From 2f11024db89d1f5991c5fda2a94309973a3ee6aa Mon Sep 17 00:00:00 2001 From: Quantum Date: Mon, 18 Jan 2021 16:08:38 -0500 Subject: [PATCH] [client] displayserver: move screensaver handling into displayservers This also makes Wayland idle inhibition respect noScreensaver setting. --- client/displayservers/SDL/sdl.c | 12 ++++++++++++ client/displayservers/Wayland/wayland.c | 12 ++++++------ client/displayservers/X11/x11.c | 4 ++++ client/include/interface/displayserver.h | 4 ++++ client/src/main.c | 9 +++++++-- 5 files changed, 33 insertions(+), 8 deletions(-) diff --git a/client/displayservers/SDL/sdl.c b/client/displayservers/SDL/sdl.c index 130ad33c..67816966 100644 --- a/client/displayservers/SDL/sdl.c +++ b/client/displayservers/SDL/sdl.c @@ -222,6 +222,16 @@ static void sdlRealignPointer(void) app_handleMouseNormal(0, 0); } +static void sdlInhibitIdle(void) +{ + SDL_DisableScreenSaver(); +} + +static void sdlUninhibitIdle(void) +{ + SDL_EnableScreenSaver(); +} + struct LG_DisplayServerOps LGDS_SDL = { .subsystem = SDL_SYSWM_UNKNOWN, @@ -238,6 +248,8 @@ struct LG_DisplayServerOps LGDS_SDL = .ungrabKeyboard = sdlUngrabKeyboard, .warpPointer = sdlWarpPointer, .realignPointer = sdlRealignPointer, + .inhibitIdle = sdlInhibitIdle, + .uninhibitIdle = sdlUninhibitIdle, /* SDL does not have clipboard support */ .cbInit = NULL, diff --git a/client/displayservers/Wayland/wayland.c b/client/displayservers/Wayland/wayland.c index de60456d..72b30bc6 100644 --- a/client/displayservers/Wayland/wayland.c +++ b/client/displayservers/Wayland/wayland.c @@ -206,14 +206,14 @@ static const struct wl_pointer_listener pointerListener = { .axis = pointerAxisHandler, }; -static void inhibitIdle(void) +static void waylandInhibitIdle(void) { if (wm.idleInhibitManager && !wm.idleInhibitor) wm.idleInhibitor = zwp_idle_inhibit_manager_v1_create_inhibitor( wm.idleInhibitManager, wm.surface); } -static void uninhibitIdle(void) +static void waylandUninhibitIdle(void) { if (wm.idleInhibitor) { @@ -238,14 +238,12 @@ static void keyboardEnterHandler(void * data, struct wl_keyboard * keyboard, uint32_t * key; wl_array_for_each(key, keys) app_handleKeyPress(*key); - - inhibitIdle(); } static void keyboardLeaveHandler(void * data, struct wl_keyboard * keyboard, uint32_t serial, struct wl_surface * surface) { - uninhibitIdle(); + // Do nothing. } static void keyboardKeyHandler(void * data, struct wl_keyboard * keyboard, @@ -473,7 +471,7 @@ static void waylandFree(void) if (wm.idleInhibitManager) { - uninhibitIdle(); + waylandUninhibitIdle(); zwp_idle_inhibit_manager_v1_destroy(wm.idleInhibitManager); } @@ -862,6 +860,8 @@ struct LG_DisplayServerOps LGDS_Wayland = .ungrabKeyboard = waylandUngrabKeyboard, .warpPointer = waylandWarpPointer, .realignPointer = waylandRealignPointer, + .inhibitIdle = waylandInhibitIdle, + .uninhibitIdle = waylandUninhibitIdle, .cbInit = waylandCBInit, .cbNotice = waylandCBNotice, diff --git a/client/displayservers/X11/x11.c b/client/displayservers/X11/x11.c index 9f9e3649..2d94ee91 100644 --- a/client/displayservers/X11/x11.c +++ b/client/displayservers/X11/x11.c @@ -850,6 +850,10 @@ struct LG_DisplayServerOps LGDS_X11 = .ungrabKeyboard = x11UngrabKeyboard, .warpPointer = x11WarpPointer, + /* Use SDL implementation for now */ + .inhibitIdle = NULL, + .uninhibitIdle = NULL, + .cbInit = x11CBInit, .cbNotice = x11CBNotice, .cbRelease = x11CBRelease, diff --git a/client/include/interface/displayserver.h b/client/include/interface/displayserver.h index 6d4346f5..abb9ccf7 100644 --- a/client/include/interface/displayserver.h +++ b/client/include/interface/displayserver.h @@ -100,6 +100,10 @@ struct LG_DisplayServerOps * deltas */ void (*realignPointer)(); + /* called to disable/enable the screensaver */ + void (*inhibitIdle)(); + void (*uninhibitIdle)(); + /* clipboard support */ bool (* cbInit)(void); void (* cbNotice)(LG_ClipboardData type); diff --git a/client/src/main.c b/client/src/main.c index 23924d2c..a2d3595c 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -1816,6 +1816,8 @@ static int lg_run(void) SET_FALLBACK(ungrabKeyboard); SET_FALLBACK(warpPointer); SET_FALLBACK(realignPointer); + SET_FALLBACK(inhibitIdle); + SET_FALLBACK(uninhibitIdle); SET_FALLBACK(cbInit); SET_FALLBACK(cbNotice); SET_FALLBACK(cbRelease); @@ -1829,8 +1831,8 @@ static int lg_run(void) return -1; } - if (!params.noScreensaver) - SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"); + // Allow screensavers for now: we will enable and disable as needed. + SDL_SetHint(SDL_HINT_VIDEO_ALLOW_SCREENSAVER, "1"); if (SDL_Init(SDL_INIT_VIDEO) < 0) { @@ -1961,6 +1963,9 @@ static int lg_run(void) if (!params.center) 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 SDL_GetWindowSize(g_state.window, &g_state.windowW, &g_state.windowH);