mirror of https://github.com/bjornbytes/lovr.git
lovr.focus;
This may not work in all cases involving e.g. overlays.
This commit is contained in:
parent
f9f0773b92
commit
0c6da83332
|
@ -19,6 +19,12 @@ static int nextEvent(lua_State* L) {
|
|||
return 2;
|
||||
}
|
||||
|
||||
case EVENT_FOCUS: {
|
||||
lua_pushstring(L, "focus");
|
||||
lua_pushboolean(L, event->data.focus.isFocused);
|
||||
return 2;
|
||||
};
|
||||
|
||||
case EVENT_CONTROLLER_ADDED: {
|
||||
lua_pushstring(L, "controlleradded");
|
||||
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);
|
||||
break;
|
||||
|
||||
case EVENT_FOCUS:
|
||||
data.focus.isFocused = lua_toboolean(L, 2);
|
||||
break;
|
||||
|
||||
case EVENT_CONTROLLER_ADDED:
|
||||
data.controlleradded.controller = luax_checktype(L, 2, Controller);
|
||||
break;
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
typedef enum {
|
||||
EVENT_QUIT,
|
||||
EVENT_FOCUS,
|
||||
EVENT_CONTROLLER_ADDED,
|
||||
EVENT_CONTROLLER_REMOVED,
|
||||
EVENT_CONTROLLER_PRESSED,
|
||||
|
@ -15,6 +16,10 @@ typedef struct {
|
|||
int exitCode;
|
||||
} QuitEvent;
|
||||
|
||||
typedef struct {
|
||||
int isFocused;
|
||||
} FocusEvent;
|
||||
|
||||
typedef struct {
|
||||
Controller* controller;
|
||||
} ControllerAddedEvent;
|
||||
|
@ -35,6 +40,7 @@ typedef struct {
|
|||
|
||||
typedef union {
|
||||
QuitEvent quit;
|
||||
FocusEvent focus;
|
||||
ControllerAddedEvent controlleradded;
|
||||
ControllerRemovedEvent controllerremoved;
|
||||
ControllerPressedEvent controllerpressed;
|
||||
|
|
|
@ -154,6 +154,14 @@ void lovrHeadsetPoll() {
|
|||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -113,6 +113,9 @@ void lovrInit(lua_State* L, int argc, char** argv) {
|
|||
|
||||
"lovr.handlers = setmetatable({ "
|
||||
" quit = function() end, "
|
||||
" focus = function(f) "
|
||||
" if lovr.focus then lovr.focus(f) end "
|
||||
" end, "
|
||||
" controlleradded = function(c) "
|
||||
" if lovr.controlleradded then lovr.controlleradded(c) end "
|
||||
" end, "
|
||||
|
|
Loading…
Reference in New Issue