1
0
Fork 0
mirror of https://github.com/bjornbytes/lovr.git synced 2024-07-03 04:53:35 +00:00

lovr.focus;

This may not work in all cases involving e.g. overlays.
This commit is contained in:
bjorn 2017-03-11 19:01:01 -08:00
parent f9f0773b92
commit 0c6da83332
4 changed files with 27 additions and 0 deletions

View file

@ -19,6 +19,12 @@ static int nextEvent(lua_State* L) {
return 2; return 2;
} }
case EVENT_FOCUS: {
lua_pushstring(L, "focus");
lua_pushboolean(L, event->data.focus.isFocused);
return 2;
};
case EVENT_CONTROLLER_ADDED: { case EVENT_CONTROLLER_ADDED: {
lua_pushstring(L, "controlleradded"); lua_pushstring(L, "controlleradded");
luax_pushtype(L, Controller, event->data.controlleradded.controller); luax_pushtype(L, Controller, event->data.controlleradded.controller);
@ -90,6 +96,10 @@ int l_lovrEventPush(lua_State* L) {
data.quit.exitCode = luaL_optint(L, 2, 0); data.quit.exitCode = luaL_optint(L, 2, 0);
break; break;
case EVENT_FOCUS:
data.focus.isFocused = lua_toboolean(L, 2);
break;
case EVENT_CONTROLLER_ADDED: case EVENT_CONTROLLER_ADDED:
data.controlleradded.controller = luax_checktype(L, 2, Controller); data.controlleradded.controller = luax_checktype(L, 2, Controller);
break; break;

View file

@ -5,6 +5,7 @@
typedef enum { typedef enum {
EVENT_QUIT, EVENT_QUIT,
EVENT_FOCUS,
EVENT_CONTROLLER_ADDED, EVENT_CONTROLLER_ADDED,
EVENT_CONTROLLER_REMOVED, EVENT_CONTROLLER_REMOVED,
EVENT_CONTROLLER_PRESSED, EVENT_CONTROLLER_PRESSED,
@ -15,6 +16,10 @@ typedef struct {
int exitCode; int exitCode;
} QuitEvent; } QuitEvent;
typedef struct {
int isFocused;
} FocusEvent;
typedef struct { typedef struct {
Controller* controller; Controller* controller;
} ControllerAddedEvent; } ControllerAddedEvent;
@ -35,6 +40,7 @@ typedef struct {
typedef union { typedef union {
QuitEvent quit; QuitEvent quit;
FocusEvent focus;
ControllerAddedEvent controlleradded; ControllerAddedEvent controlleradded;
ControllerRemovedEvent controllerremoved; ControllerRemovedEvent controllerremoved;
ControllerPressedEvent controllerpressed; ControllerPressedEvent controllerpressed;

View file

@ -154,6 +154,14 @@ void lovrHeadsetPoll() {
} }
break; break;
} }
case EVREventType_VREvent_InputFocusCaptured:
case EVREventType_VREvent_InputFocusReleased:
int isFocused = vrEvent.eventType == EVREventType_VREvent_InputFocusReleased;
EventData data = { .focus = { isFocused } };
Event event = { .type = EVENT_FOCUS, .data = data };
lovrEventPush(event);
break;
} }
} }
} }

View file

@ -113,6 +113,9 @@ void lovrInit(lua_State* L, int argc, char** argv) {
"lovr.handlers = setmetatable({ " "lovr.handlers = setmetatable({ "
" quit = function() end, " " quit = function() end, "
" focus = function(f) "
" if lovr.focus then lovr.focus(f) end "
" end, "
" controlleradded = function(c) " " controlleradded = function(c) "
" if lovr.controlleradded then lovr.controlleradded(c) end " " if lovr.controlleradded then lovr.controlleradded(c) end "
" end, " " end, "