x11: Implement xdg-screensaver uninhibition

This commit is contained in:
Bastien Nocera 2016-09-16 13:00:43 +02:00
parent e563bd5512
commit a061b4a801

View File

@ -40,6 +40,9 @@ static DBusConnection* dbus_connection = NULL;
static unsigned int dbus_screensaver_cookie = 0;
#endif
static bool xdg_screensaver_available = true;
static bool xdg_screensaver_running = false;
Colormap g_x11_cmap;
Window g_x11_win;
Display *g_x11_dpy;
@ -275,33 +278,70 @@ void x11_set_window_attr(Display *dpy, Window win)
x11_set_window_class(dpy, win);
}
static void x11_suspend_screensaver_xdg_screensaver(Window wnd, bool enable)
static void xdg_screensaver_inhibit(Window wnd)
{
int ret;
char cmd[64] = {0};
static bool screensaver_na = false;
if (!enable)
return;
if (screensaver_na)
if (!xdg_screensaver_available)
return;
RARCH_LOG("Suspending screensaver (X11).\n");
if (xdg_screensaver_running)
return;
RARCH_LOG("Suspending screensaver (X11, xdg-screensaver).\n");
snprintf(cmd, sizeof(cmd), "xdg-screensaver suspend 0x%x", (int)wnd);
ret = system(cmd);
if (ret == -1)
{
screensaver_na = true;
xdg_screensaver_available = false;
RARCH_WARN("Failed to launch xdg-screensaver.\n");
}
else if (WEXITSTATUS(ret))
{
screensaver_na = true;
xdg_screensaver_available = false;
RARCH_WARN("Could not suspend screen saver.\n");
}
else
{
xdg_screensaver_running = true;
}
}
static void xdg_screensaver_uninhibit(Window wnd)
{
int ret;
char cmd[64] = {0};
if (!xdg_screensaver_available)
return;
if (!xdg_screensaver_running)
return;
RARCH_LOG("Resuming screensaver (X11, xdg-screensaver).\n");
snprintf(cmd, sizeof(cmd), "xdg-screensaver resume 0x%x", (int)wnd);
ret = system(cmd);
if (ret == -1)
{
xdg_screensaver_available = false;
RARCH_WARN("Failed to launch xdg-screensaver.\n");
}
else if (WEXITSTATUS(ret))
{
xdg_screensaver_available = false;
RARCH_WARN("Could not suspend screen saver.\n");
}
}
void x11_suspend_screensaver_xdg_screensaver(Window wnd, bool enable)
{
if (enable) xdg_screensaver_inhibit(wnd);
xdg_screensaver_uninhibit(wnd);
}
void x11_suspend_screensaver(Window wnd, bool enable)