[client] displayserver: move screensaver handling into displayservers

This also makes Wayland idle inhibition respect noScreensaver setting.
This commit is contained in:
Quantum 2021-01-18 16:08:38 -05:00 committed by Geoffrey McRae
parent 44a949f5c6
commit 2f11024db8
5 changed files with 33 additions and 8 deletions

View file

@ -222,6 +222,16 @@ static void sdlRealignPointer(void)
app_handleMouseNormal(0, 0); app_handleMouseNormal(0, 0);
} }
static void sdlInhibitIdle(void)
{
SDL_DisableScreenSaver();
}
static void sdlUninhibitIdle(void)
{
SDL_EnableScreenSaver();
}
struct LG_DisplayServerOps LGDS_SDL = struct LG_DisplayServerOps LGDS_SDL =
{ {
.subsystem = SDL_SYSWM_UNKNOWN, .subsystem = SDL_SYSWM_UNKNOWN,
@ -238,6 +248,8 @@ struct LG_DisplayServerOps LGDS_SDL =
.ungrabKeyboard = sdlUngrabKeyboard, .ungrabKeyboard = sdlUngrabKeyboard,
.warpPointer = sdlWarpPointer, .warpPointer = sdlWarpPointer,
.realignPointer = sdlRealignPointer, .realignPointer = sdlRealignPointer,
.inhibitIdle = sdlInhibitIdle,
.uninhibitIdle = sdlUninhibitIdle,
/* SDL does not have clipboard support */ /* SDL does not have clipboard support */
.cbInit = NULL, .cbInit = NULL,

View file

@ -206,14 +206,14 @@ static const struct wl_pointer_listener pointerListener = {
.axis = pointerAxisHandler, .axis = pointerAxisHandler,
}; };
static void inhibitIdle(void) static void waylandInhibitIdle(void)
{ {
if (wm.idleInhibitManager && !wm.idleInhibitor) if (wm.idleInhibitManager && !wm.idleInhibitor)
wm.idleInhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor( wm.idleInhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor(
wm.idleInhibitManager, wm.surface); wm.idleInhibitManager, wm.surface);
} }
static void uninhibitIdle(void) static void waylandUninhibitIdle(void)
{ {
if (wm.idleInhibitor) if (wm.idleInhibitor)
{ {
@ -238,14 +238,12 @@ static void keyboardEnterHandler(void * data, struct wl_keyboard * keyboard,
uint32_t * key; uint32_t * key;
wl_array_for_each(key, keys) wl_array_for_each(key, keys)
app_handleKeyPress(*key); app_handleKeyPress(*key);
inhibitIdle();
} }
static void keyboardLeaveHandler(void * data, struct wl_keyboard * keyboard, static void keyboardLeaveHandler(void * data, struct wl_keyboard * keyboard,
uint32_t serial, struct wl_surface * surface) uint32_t serial, struct wl_surface * surface)
{ {
uninhibitIdle(); // Do nothing.
} }
static void keyboardKeyHandler(void * data, struct wl_keyboard * keyboard, static void keyboardKeyHandler(void * data, struct wl_keyboard * keyboard,
@ -473,7 +471,7 @@ static void waylandFree(void)
if (wm.idleInhibitManager) if (wm.idleInhibitManager)
{ {
uninhibitIdle(); waylandUninhibitIdle();
zwp_idle_inhibit_manager_v1_destroy(wm.idleInhibitManager); zwp_idle_inhibit_manager_v1_destroy(wm.idleInhibitManager);
} }
@ -862,6 +860,8 @@ struct LG_DisplayServerOps LGDS_Wayland =
.ungrabKeyboard = waylandUngrabKeyboard, .ungrabKeyboard = waylandUngrabKeyboard,
.warpPointer = waylandWarpPointer, .warpPointer = waylandWarpPointer,
.realignPointer = waylandRealignPointer, .realignPointer = waylandRealignPointer,
.inhibitIdle = waylandInhibitIdle,
.uninhibitIdle = waylandUninhibitIdle,
.cbInit = waylandCBInit, .cbInit = waylandCBInit,
.cbNotice = waylandCBNotice, .cbNotice = waylandCBNotice,

View file

@ -850,6 +850,10 @@ struct LG_DisplayServerOps LGDS_X11 =
.ungrabKeyboard = x11UngrabKeyboard, .ungrabKeyboard = x11UngrabKeyboard,
.warpPointer = x11WarpPointer, .warpPointer = x11WarpPointer,
/* Use SDL implementation for now */
.inhibitIdle = NULL,
.uninhibitIdle = NULL,
.cbInit = x11CBInit, .cbInit = x11CBInit,
.cbNotice = x11CBNotice, .cbNotice = x11CBNotice,
.cbRelease = x11CBRelease, .cbRelease = x11CBRelease,

View file

@ -100,6 +100,10 @@ struct LG_DisplayServerOps
* deltas */ * deltas */
void (*realignPointer)(); void (*realignPointer)();
/* called to disable/enable the screensaver */
void (*inhibitIdle)();
void (*uninhibitIdle)();
/* clipboard support */ /* clipboard support */
bool (* cbInit)(void); bool (* cbInit)(void);
void (* cbNotice)(LG_ClipboardData type); void (* cbNotice)(LG_ClipboardData type);

View file

@ -1816,6 +1816,8 @@ static int lg_run(void)
SET_FALLBACK(ungrabKeyboard); SET_FALLBACK(ungrabKeyboard);
SET_FALLBACK(warpPointer); SET_FALLBACK(warpPointer);
SET_FALLBACK(realignPointer); SET_FALLBACK(realignPointer);
SET_FALLBACK(inhibitIdle);
SET_FALLBACK(uninhibitIdle);
SET_FALLBACK(cbInit); SET_FALLBACK(cbInit);
SET_FALLBACK(cbNotice); SET_FALLBACK(cbNotice);
SET_FALLBACK(cbRelease); SET_FALLBACK(cbRelease);
@ -1829,7 +1831,7 @@ static int lg_run(void)
return -1; return -1;
} }
if (!params.noScreensaver) // Allow screensavers for now: we will enable and disable as needed.
SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"); SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1");
if (SDL_Init(SDL_INIT_VIDEO) < 0) if (SDL_Init(SDL_INIT_VIDEO) < 0)
@ -1961,6 +1963,9 @@ static int lg_run(void)
if (!params.center) if (!params.center)
SDL_SetWindowPosition(g_state.window, params.x, params.y); SDL_SetWindowPosition(g_state.window, params.x, params.y);
if (!params.noScreensaver)
g_state.ds->inhibitIdle();
// ensure the initial window size is stored in the state // ensure the initial window size is stored in the state
SDL_GetWindowSize(g_state.window, &g_state.windowW, &g_state.windowH); SDL_GetWindowSize(g_state.window, &g_state.windowW, &g_state.windowH);