X-Git-Url: https://www.fi.muni.cz/~kas/git//home/kas/public_html/git/?a=blobdiff_plain;ds=sidebyside;f=cut-n-paste%2Ftotem-screensaver%2Ftotem-scrsaver.c;h=36d314ef20b615ab29ef2afc4bd44300fa7669e7;hb=212d9a536bc60e711b779feb5e8aa33db654997d;hp=3a0332a18a2e035d276c6febdb306167808813a2;hpb=93211dfbee19004044aea60d461e6f7dcb4ff3ce;p=evince.git diff --git a/cut-n-paste/totem-screensaver/totem-scrsaver.c b/cut-n-paste/totem-screensaver/totem-scrsaver.c index 3a0332a1..36d314ef 100644 --- a/cut-n-paste/totem-screensaver/totem-scrsaver.c +++ b/cut-n-paste/totem-screensaver/totem-scrsaver.c @@ -60,7 +60,6 @@ struct TotemScrsaverPrivate { GDBusProxy *gs_proxy; gboolean have_screensaver_dbus; - guint watch_id; guint32 cookie; gboolean old_dbus_api; @@ -211,71 +210,76 @@ screensaver_disable_dbus (TotemScrsaver *scr) } static void -screensaver_dbus_appeared_cb (GDBusConnection *connection, - const gchar *name, - const gchar *name_owner, - GDBusProxy *proxy, - gpointer user_data) +screensaver_update_dbus_presence (TotemScrsaver *scr) { - TotemScrsaver *scr = TOTEM_SCRSAVER (user_data); TotemScrsaverPrivate *priv = scr->priv; + gchar *name_owner; - priv->gs_proxy = g_object_ref (proxy); - - priv->have_screensaver_dbus = TRUE; + name_owner = g_dbus_proxy_get_name_owner (priv->gs_proxy); + if (name_owner) { + priv->have_screensaver_dbus = TRUE; + g_free (name_owner); + } else { + priv->have_screensaver_dbus = FALSE; + } } static void -screensaver_dbus_disappeared_cb (GDBusConnection *connection, - const gchar *name, - gpointer user_data) +screensaver_dbus_owner_changed_cb (GObject *object, + GParamSpec *pspec, + gpointer user_data) { TotemScrsaver *scr = TOTEM_SCRSAVER (user_data); - TotemScrsaverPrivate *priv = scr->priv; - - if (priv->gs_proxy) { - g_object_unref (priv->gs_proxy); - priv->gs_proxy = NULL; - } - priv->have_screensaver_dbus = FALSE; + screensaver_update_dbus_presence (scr); } static void -screensaver_init_dbus (TotemScrsaver *scr) +screensaver_dbus_proxy_new_cb (GObject *source, + GAsyncResult *result, + gpointer user_data) { + TotemScrsaver *scr = TOTEM_SCRSAVER (user_data); TotemScrsaverPrivate *priv = scr->priv; - priv->watch_id = g_bus_watch_proxy (G_BUS_TYPE_SESSION, - GS_SERVICE, - G_BUS_NAME_WATCHER_FLAGS_NONE, - GS_PATH, - GS_INTERFACE, - G_TYPE_DBUS_PROXY, - G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | - G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS, - screensaver_dbus_appeared_cb, - screensaver_dbus_disappeared_cb, - scr, NULL); + priv->gs_proxy = g_dbus_proxy_new_for_bus_finish (result, NULL); + if (!priv->gs_proxy) + return; + + screensaver_update_dbus_presence (scr); + + g_signal_connect (priv->gs_proxy, "notify::g-name-owner", + G_CALLBACK (screensaver_dbus_owner_changed_cb), + scr); } static void -screensaver_finalize_dbus (TotemScrsaver *scr) +screensaver_init_dbus (TotemScrsaver *scr) { - TotemScrsaverPrivate *priv = scr->priv; + g_dbus_proxy_new_for_bus (G_BUS_TYPE_SESSION, + G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES, + NULL, + GS_SERVICE, + GS_PATH, + GS_INTERFACE, + NULL, + screensaver_dbus_proxy_new_cb, + scr); +} +static void +screensaver_finalize_dbus (TotemScrsaver *scr) +{ if (scr->priv->gs_proxy) { g_object_unref (scr->priv->gs_proxy); } - - if (priv->watch_id > 0) - g_bus_unwatch_proxy (priv->watch_id); } #ifdef GDK_WINDOWING_X11 static void screensaver_enable_x11 (TotemScrsaver *scr) { + Display *xdisplay; #ifdef HAVE_XTEST if (scr->priv->have_xtest != FALSE) @@ -285,13 +289,14 @@ screensaver_enable_x11 (TotemScrsaver *scr) } #endif /* HAVE_XTEST */ - XLockDisplay (GDK_DISPLAY()); - XSetScreenSaver (GDK_DISPLAY(), + xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + XLockDisplay (xdisplay); + XSetScreenSaver (xdisplay, scr->priv->timeout, scr->priv->interval, scr->priv->prefer_blanking, scr->priv->allow_exposures); - XUnlockDisplay (GDK_DISPLAY()); + XUnlockDisplay (xdisplay); } #ifdef HAVE_XTEST @@ -300,12 +305,15 @@ fake_event (TotemScrsaver *scr) { if (scr->priv->disabled) { - XLockDisplay (GDK_DISPLAY()); - XTestFakeKeyEvent (GDK_DISPLAY(), *scr->priv->keycode, + Display *display; + + xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); + XLockDisplay (xdisplay); + XTestFakeKeyEvent (xdisplay, *scr->priv->keycode, True, CurrentTime); - XTestFakeKeyEvent (GDK_DISPLAY(), *scr->priv->keycode, + XTestFakeKeyEvent (xdisplay, *scr->priv->keycode, False, CurrentTime); - XUnlockDisplay (GDK_DISPLAY()); + XUnlockDisplay (xdisplay); /* Swap the keycode */ if (scr->priv->keycode == &scr->priv->keycode1) scr->priv->keycode = &scr->priv->keycode2; @@ -320,16 +328,19 @@ fake_event (TotemScrsaver *scr) static void screensaver_disable_x11 (TotemScrsaver *scr) { + Display *xdisplay; + + xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); #ifdef HAVE_XTEST if (scr->priv->have_xtest != FALSE) { - XLockDisplay (GDK_DISPLAY()); - XGetScreenSaver(GDK_DISPLAY(), &scr->priv->timeout, + XLockDisplay (xdisplay); + XGetScreenSaver(xdisplay, &scr->priv->timeout, &scr->priv->interval, &scr->priv->prefer_blanking, &scr->priv->allow_exposures); - XUnlockDisplay (GDK_DISPLAY()); + XUnlockDisplay (xdisplay); if (scr->priv->timeout != 0) { g_timeout_add_seconds (scr->priv->timeout / 2, @@ -343,14 +354,14 @@ screensaver_disable_x11 (TotemScrsaver *scr) } #endif /* HAVE_XTEST */ - XLockDisplay (GDK_DISPLAY()); - XGetScreenSaver(GDK_DISPLAY(), &scr->priv->timeout, + XLockDisplay (xdisplay); + XGetScreenSaver(xdisplay, &scr->priv->timeout, &scr->priv->interval, &scr->priv->prefer_blanking, &scr->priv->allow_exposures); - XSetScreenSaver(GDK_DISPLAY(), 0, 0, + XSetScreenSaver(xdisplay, 0, 0, DontPreferBlanking, DontAllowExposures); - XUnlockDisplay (GDK_DISPLAY()); + XUnlockDisplay (xdisplay); } static void @@ -358,25 +369,28 @@ screensaver_init_x11 (TotemScrsaver *scr) { #ifdef HAVE_XTEST int a, b, c, d; + Display *display; + + xdisplay = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()); - XLockDisplay (GDK_DISPLAY()); - scr->priv->have_xtest = (XTestQueryExtension (GDK_DISPLAY(), &a, &b, &c, &d) == True); + XLockDisplay (xdisplay); + scr->priv->have_xtest = (XTestQueryExtension (xdisplay, &a, &b, &c, &d) == True); if (scr->priv->have_xtest != FALSE) { - scr->priv->keycode1 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L); + scr->priv->keycode1 = XKeysymToKeycode (xdisplay, XK_Alt_L); if (scr->priv->keycode1 == 0) { g_warning ("scr->priv->keycode1 not existant"); } - scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_R); + scr->priv->keycode2 = XKeysymToKeycode (xdisplay, XK_Alt_R); if (scr->priv->keycode2 == 0) { - scr->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L); + scr->priv->keycode2 = XKeysymToKeycode (xdisplay, XK_Alt_L); if (scr->priv->keycode2 == 0) { g_warning ("scr->priv->keycode2 not existant"); } } scr->priv->keycode = &scr->priv->keycode1; } - XUnlockDisplay (GDK_DISPLAY()); + XUnlockDisplay (xdisplay); #endif /* HAVE_XTEST */ }