static void deactivate_dbus_based_screensaver(const char *d_service, const char *d_path, const char *d_interface) { if (!connection) screensaver_connect(); if (!connection) return; if (is_dbus_based_screensaver_active(d_service, d_path, d_interface)) { // screen saver is active already, deactivating timer makes no sense return; } GDBusMessage *msg = g_dbus_message_new_method_call(d_service, d_path, d_interface, "SimulateUserActivity"); if (!msg) return; GError *error = NULL; g_dbus_connection_send_message(connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error); if (error != NULL) { trace_error("%s, can't send message, %s\n", __func__, error->message); g_clear_error(&error); goto err; } // workaround Plasma 5 issue by calling GetSessionIdleTime after SimulateUserActivity if (config.quirks.plasma5_screensaver) { msg = g_dbus_message_new_method_call(d_service, d_path, d_interface, "GetSessionIdleTime"); error = NULL; g_dbus_connection_send_message(connection, msg, G_DBUS_SEND_MESSAGE_FLAGS_NONE, NULL, &error); if (error != NULL) { trace_error("%s, can't send message, %s\n", __func__, error->message); g_clear_error(&error); goto err; } } g_dbus_connection_flush_sync(connection, NULL, &error); if (error != NULL) { trace_error("%s, can't flush dbus connection, %s\n", __func__, error->message); g_clear_error(&error); goto err; } err: g_object_unref(msg); }
uint32_t screensaver_type_detect(Display *dpy) { #if HAVE_GLIB_DBUS if (!connection) screensaver_connect(); if (!connection) return 0; #endif // HAVE_GLIB_DBUS uint32_t flags = 0; if (find_xscreensaver_window(dpy) != 0) flags |= SST_XSCREENSAVER; #if HAVE_GLIB_DBUS flags |= detect_dbus_based_screensavers(); #endif // HAVE_GLIB_DBUS return flags; }
int tables_open_display(void) { int retval = 0; int major, minor; pthread_mutex_init(&display.lock, NULL); pthread_mutex_lock(&display.lock); display.x = XOpenDisplay(NULL); if (!display.x) { trace_error("%s, can't open X Display\n", __func__); retval = 1; goto quit; } if (config.quirks.x_synchronize) XSynchronize(display.x, True); #if HAVE_HWDEC display.va = vaGetDisplay(display.x); VAStatus status = vaInitialize(display.va, &major, &minor); if (status == VA_STATUS_SUCCESS) { trace_info_f("libva version %d.%d\n", major, minor); display.va_available = 1; } else { // TODO: remember? trace_info_f("no libva\n"); display.va_available = 0; } #endif // HAVE_HWDEC if (!glXQueryVersion(display.x, &major, &minor)) { trace_error("%s, glXQueryVersion returned False\n", __func__); } else { trace_info_f("GLX version %d.%d\n", major, minor); } check_glx_extensions(); // initialize screensaver inhibition library screensaver_connect(); display.screensaver_types = screensaver_type_detect(display.x); gchar *s = g_strdup_printf("screensavers found:%s%s%s%s%s", (display.screensaver_types & SST_XSCREENSAVER) ? " XScreenSaver" : "", (display.screensaver_types & SST_FDO_SCREENSAVER) ? " fd.o-screensaver" : "", (display.screensaver_types & SST_CINNAMON_SCREENSAVER) ? " cinnamon-screensaver" : "", (display.screensaver_types & SST_GNOME_SCREENSAVER) ? " gnome-screensaver" : "", (display.screensaver_types & SST_KDE_SCREENSAVER) ? " kscreensaver" : ""); trace_info_f("%s\n", s); g_free(s); // create transparent cursor const char t_pixmap_data = 0; XColor t_color = {}; Pixmap t_pixmap = XCreateBitmapFromData(display.x, DefaultRootWindow(display.x), &t_pixmap_data, 1, 1); display.transparent_cursor = XCreatePixmapCursor(display.x, t_pixmap, t_pixmap, &t_color, &t_color, 0, 0); XFreePixmap(display.x, t_pixmap); // determine minimal size across all screens display.min_width = (uint32_t)-1; display.min_height = (uint32_t)-1; XRRScreenResources *sr = XRRGetScreenResources(display.x, DefaultRootWindow(display.x)); if (sr) { for (int k = 0; k < sr->ncrtc; k ++) { XRRCrtcInfo *ci = XRRGetCrtcInfo(display.x, sr, sr->crtcs[k]); if (ci && ci->width > 0 && ci->height > 0) { display.min_width = MIN(display.min_width, ci->width); display.min_height = MIN(display.min_height, ci->height); } if (ci) XRRFreeCrtcInfo(ci); } XRRFreeScreenResources(sr); } if (display.min_width == (uint32_t)-1 || display.min_height == (uint32_t)-1) { display.min_width = 300; display.min_height = 300; } // apply size override from the configuration file if (config.fullscreen_width > 0) display.min_width = config.fullscreen_width; if (config.fullscreen_height > 0) display.min_height = config.fullscreen_height; display.pictfmt_rgb24 = XRenderFindStandardFormat(display.x, PictStandardRGB24); display.pictfmt_argb32 = XRenderFindStandardFormat(display.x, PictStandardARGB32); quit: pthread_mutex_unlock(&display.lock); return retval; }