x11: Implement xdg-screensaver uninhibition
This commit is contained in:
parent
e563bd5512
commit
a061b4a801
|
@ -40,6 +40,9 @@ static DBusConnection* dbus_connection = NULL;
|
||||||
static unsigned int dbus_screensaver_cookie = 0;
|
static unsigned int dbus_screensaver_cookie = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
static bool xdg_screensaver_available = true;
|
||||||
|
static bool xdg_screensaver_running = false;
|
||||||
|
|
||||||
Colormap g_x11_cmap;
|
Colormap g_x11_cmap;
|
||||||
Window g_x11_win;
|
Window g_x11_win;
|
||||||
Display *g_x11_dpy;
|
Display *g_x11_dpy;
|
||||||
|
@ -275,33 +278,70 @@ void x11_set_window_attr(Display *dpy, Window win)
|
||||||
x11_set_window_class(dpy, 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;
|
int ret;
|
||||||
char cmd[64] = {0};
|
char cmd[64] = {0};
|
||||||
static bool screensaver_na = false;
|
|
||||||
|
|
||||||
if (!enable)
|
if (!xdg_screensaver_available)
|
||||||
return;
|
|
||||||
|
|
||||||
if (screensaver_na)
|
|
||||||
return;
|
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);
|
snprintf(cmd, sizeof(cmd), "xdg-screensaver suspend 0x%x", (int)wnd);
|
||||||
|
|
||||||
ret = system(cmd);
|
ret = system(cmd);
|
||||||
if (ret == -1)
|
if (ret == -1)
|
||||||
{
|
{
|
||||||
screensaver_na = true;
|
xdg_screensaver_available = false;
|
||||||
RARCH_WARN("Failed to launch xdg-screensaver.\n");
|
RARCH_WARN("Failed to launch xdg-screensaver.\n");
|
||||||
}
|
}
|
||||||
else if (WEXITSTATUS(ret))
|
else if (WEXITSTATUS(ret))
|
||||||
{
|
{
|
||||||
screensaver_na = true;
|
xdg_screensaver_available = false;
|
||||||
RARCH_WARN("Could not suspend screen saver.\n");
|
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)
|
void x11_suspend_screensaver(Window wnd, bool enable)
|
||||||
|
|
Loading…
Reference in New Issue