[gnome-session] all: Drop GTK_DISPLAY () calls



commit fa73f94f992cde97ea1fe84e04fd896c0085855d
Author: Vincent Untz <vuntz gnome org>
Date:   Tue Sep 21 14:28:37 2010 -0400

    all: Drop GTK_DISPLAY () calls
    
    This is another round of GTK+ 3 fixes.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=630277

 gnome-session/gs-idle-monitor.c    |   43 ++++++++++++++++++---------------
 gnome-session/gsm-inhibit-dialog.c |   46 +++++++++++++++++++++++------------
 2 files changed, 54 insertions(+), 35 deletions(-)
---
diff --git a/gnome-session/gs-idle-monitor.c b/gnome-session/gs-idle-monitor.c
index 05dbb02..cd38dcb 100644
--- a/gnome-session/gs-idle-monitor.c
+++ b/gnome-session/gs-idle-monitor.c
@@ -47,6 +47,8 @@ static void gs_idle_monitor_finalize   (GObject             *object);
 
 struct GSIdleMonitorPrivate
 {
+        Display     *display;
+
         GHashTable  *watches;
         int          sync_event_base;
         XSyncCounter counter;
@@ -60,6 +62,7 @@ struct GSIdleMonitorPrivate
 
 typedef struct
 {
+        Display               *display;
         guint                  id;
         XSyncValue             interval;
         GSIdleMonitorWatchFunc callback;
@@ -141,16 +144,16 @@ send_fake_event (GSIdleMonitor *monitor)
 
         g_debug ("GSIdleMonitor: sending fake key");
 
-        XLockDisplay (GDK_DISPLAY());
-        XTestFakeKeyEvent (GDK_DISPLAY(),
+        XLockDisplay (monitor->priv->display);
+        XTestFakeKeyEvent (monitor->priv->display,
                            *monitor->priv->keycode,
                            True,
                            CurrentTime);
-        XTestFakeKeyEvent (GDK_DISPLAY(),
+        XTestFakeKeyEvent (monitor->priv->display,
                            *monitor->priv->keycode,
                            False,
                            CurrentTime);
-        XUnlockDisplay (GDK_DISPLAY());
+        XUnlockDisplay (monitor->priv->display);
 
         /* Swap the keycode */
         if (monitor->priv->keycode == &monitor->priv->keycode1) {
@@ -249,7 +252,7 @@ init_xsync (GSIdleMonitor *monitor)
         int                 ncounters;
         XSyncSystemCounter *counters;
 
-        res = XSyncQueryExtension (GDK_DISPLAY (),
+        res = XSyncQueryExtension (monitor->priv->display,
                                    &monitor->priv->sync_event_base,
                                    &sync_error_base);
         if (! res) {
@@ -257,13 +260,13 @@ init_xsync (GSIdleMonitor *monitor)
                 return FALSE;
         }
 
-        res = XSyncInitialize (GDK_DISPLAY (), &major, &minor);
+        res = XSyncInitialize (monitor->priv->display, &major, &minor);
         if (! res) {
                 g_warning ("GSIdleMonitor: Unable to initialize Sync extension");
                 return FALSE;
         }
 
-        counters = XSyncListSystemCounters (GDK_DISPLAY (), &ncounters);
+        counters = XSyncListSystemCounters (monitor->priv->display, &ncounters);
         for (i = 0; i < ncounters; i++) {
                 if (counters[i].name != NULL
                     && strcmp (counters[i].name, "IDLETIME") == 0) {
@@ -289,23 +292,23 @@ _init_xtest (GSIdleMonitor *monitor)
 #ifdef HAVE_XTEST
         int a, b, c, d;
 
-        XLockDisplay (GDK_DISPLAY());
-        monitor->priv->have_xtest = (XTestQueryExtension (GDK_DISPLAY(), &a, &b, &c, &d) == True);
+        XLockDisplay (monitor->priv->display);
+        monitor->priv->have_xtest = (XTestQueryExtension (monitor->priv->display, &a, &b, &c, &d) == True);
         if (monitor->priv->have_xtest) {
-                monitor->priv->keycode1 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L);
+                monitor->priv->keycode1 = XKeysymToKeycode (monitor->priv->display, XK_Alt_L);
                 if (monitor->priv->keycode1 == 0) {
                         g_warning ("keycode1 not existant");
                 }
-                monitor->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_R);
+                monitor->priv->keycode2 = XKeysymToKeycode (monitor->priv->display, XK_Alt_R);
                 if (monitor->priv->keycode2 == 0) {
-                        monitor->priv->keycode2 = XKeysymToKeycode (GDK_DISPLAY(), XK_Alt_L);
+                        monitor->priv->keycode2 = XKeysymToKeycode (monitor->priv->display, XK_Alt_L);
                         if (monitor->priv->keycode2 == 0) {
                                 g_warning ("keycode2 not existant");
                         }
                 }
                 monitor->priv->keycode = &monitor->priv->keycode1;
         }
-        XUnlockDisplay (GDK_DISPLAY());
+        XUnlockDisplay (monitor->priv->display);
 #endif /* HAVE_XTEST */
 }
 
@@ -320,6 +323,7 @@ gs_idle_monitor_constructor (GType                  type,
                                                                                                n_construct_properties,
                                                                                                construct_properties));
 
+        monitor->priv->display = GDK_DISPLAY_XDISPLAY (gdk_display_get_default ());
         _init_xtest (monitor);
 
         if (! init_xsync (monitor)) {
@@ -379,10 +383,10 @@ idle_monitor_watch_free (GSIdleMonitorWatch *watch)
                 return;
         }
         if (watch->xalarm_positive != None) {
-                XSyncDestroyAlarm (GDK_DISPLAY (), watch->xalarm_positive);
+                XSyncDestroyAlarm (watch->display, watch->xalarm_positive);
         }
         if (watch->xalarm_negative != None) {
-                XSyncDestroyAlarm (GDK_DISPLAY (), watch->xalarm_negative);
+                XSyncDestroyAlarm (watch->display, watch->xalarm_negative);
         }
         g_slice_free (GSIdleMonitorWatch, watch);
 }
@@ -452,22 +456,22 @@ _xsync_alarm_set (GSIdleMonitor      *monitor,
         if (watch->xalarm_positive != None) {
                 g_debug ("GSIdleMonitor: updating alarm for positive transition wait=%lld",
                          _xsyncvalue_to_int64 (attr.trigger.wait_value));
-                XSyncChangeAlarm (GDK_DISPLAY (), watch->xalarm_positive, flags, &attr);
+                XSyncChangeAlarm (monitor->priv->display, watch->xalarm_positive, flags, &attr);
         } else {
                 g_debug ("GSIdleMonitor: creating new alarm for positive transition wait=%lld",
                          _xsyncvalue_to_int64 (attr.trigger.wait_value));
-                watch->xalarm_positive = XSyncCreateAlarm (GDK_DISPLAY (), flags, &attr);
+                watch->xalarm_positive = XSyncCreateAlarm (monitor->priv->display, flags, &attr);
         }
 
         attr.trigger.test_type = XSyncNegativeTransition;
         if (watch->xalarm_negative != None) {
                 g_debug ("GSIdleMonitor: updating alarm for negative transition wait=%lld",
                          _xsyncvalue_to_int64 (attr.trigger.wait_value));
-                XSyncChangeAlarm (GDK_DISPLAY (), watch->xalarm_negative, flags, &attr);
+                XSyncChangeAlarm (monitor->priv->display, watch->xalarm_negative, flags, &attr);
         } else {
                 g_debug ("GSIdleMonitor: creating new alarm for negative transition wait=%lld",
                          _xsyncvalue_to_int64 (attr.trigger.wait_value));
-                watch->xalarm_negative = XSyncCreateAlarm (GDK_DISPLAY (), flags, &attr);
+                watch->xalarm_negative = XSyncCreateAlarm (monitor->priv->display, flags, &attr);
         }
 
         return TRUE;
@@ -485,6 +489,7 @@ gs_idle_monitor_add_watch (GSIdleMonitor         *monitor,
         g_return_val_if_fail (callback != NULL, 0);
 
         watch = idle_monitor_watch_new (interval);
+        watch->display = monitor->priv->display;
         watch->callback = callback;
         watch->user_data = user_data;
 
diff --git a/gnome-session/gsm-inhibit-dialog.c b/gnome-session/gsm-inhibit-dialog.c
index 4e76e6f..077d8eb 100644
--- a/gnome-session/gsm-inhibit-dialog.c
+++ b/gnome-session/gsm-inhibit-dialog.c
@@ -389,7 +389,8 @@ pixbuf_get_from_pixmap (Pixmap xpixmap)
 }
 
 static Pixmap
-get_pixmap_for_window (Window window)
+get_pixmap_for_window (Display *display,
+                       Window   window)
 {
         XWindowAttributes        attr;
         XRenderPictureAttributes pa;
@@ -403,9 +404,9 @@ get_pixmap_for_window (Window window)
         int                      width;
         int                      height;
 
-        XGetWindowAttributes (GDK_DISPLAY (), window, &attr);
+        XGetWindowAttributes (display, window, &attr);
 
-        format = XRenderFindVisualFormat (GDK_DISPLAY (), attr.visual);
+        format = XRenderFindVisualFormat (display, attr.visual);
         has_alpha = (format->type == PictTypeDirect && format->direct.alphaMask);
         x = attr.x;
         y = attr.y;
@@ -414,15 +415,15 @@ get_pixmap_for_window (Window window)
 
         pa.subwindow_mode = IncludeInferiors; /* Don't clip child widgets */
 
-        src_picture = XRenderCreatePicture (GDK_DISPLAY (), window, format, CPSubwindowMode, &pa);
+        src_picture = XRenderCreatePicture (display, window, format, CPSubwindowMode, &pa);
 
-        pixmap = XCreatePixmap (GDK_DISPLAY (),
+        pixmap = XCreatePixmap (display,
                                 window,
                                 width, height,
                                 attr.depth);
 
-        dst_picture = XRenderCreatePicture (GDK_DISPLAY (), pixmap, format, 0, 0);
-        XRenderComposite (GDK_DISPLAY (),
+        dst_picture = XRenderCreatePicture (display, pixmap, format, 0, 0);
+        XRenderComposite (display,
                           has_alpha ? PictOpOver : PictOpSrc,
                           src_picture,
                           None,
@@ -438,17 +439,22 @@ get_pixmap_for_window (Window window)
 #endif /* HAVE_COMPOSITE */
 
 static GdkPixbuf *
-get_pixbuf_for_window (guint xid,
-                       int   width,
-                       int   height)
+get_pixbuf_for_window (GdkDisplay *gdkdisplay,
+                       guint       xid,
+                       int         width,
+                       int         height)
 {
         GdkPixbuf *pixbuf = NULL;
 #ifdef HAVE_XRENDER
+        Display   *display;
         Window     xwindow;
         Pixmap     xpixmap;
 
+        display = GDK_DISPLAY_XDISPLAY (gdkdisplay);
         xwindow = (Window) xid;
-        xpixmap = get_pixmap_for_window (xwindow);
+
+        xpixmap = get_pixmap_for_window (display, xwindow);
+
         if (xpixmap == None) {
                 g_debug ("GsmInhibitDialog: Unable to get window snapshot for %u", xid);
                 return NULL;
@@ -460,8 +466,8 @@ get_pixbuf_for_window (guint xid,
 
         if (xpixmap != None) {
                 gdk_error_trap_push ();
-                XFreePixmap (GDK_DISPLAY (), xpixmap);
-                gdk_display_sync (gdk_display_get_default ());
+                XFreePixmap (display, xpixmap);
+                gdk_display_sync (gdkdisplay);
                 gdk_error_trap_pop ();
         }
 
@@ -482,6 +488,7 @@ static void
 add_inhibitor (GsmInhibitDialog *dialog,
                GsmInhibitor     *inhibitor)
 {
+        GdkDisplay     *gdkdisplay;
         const char     *name;
         const char     *icon_name;
         const char     *app_id;
@@ -493,6 +500,8 @@ add_inhibitor (GsmInhibitDialog *dialog,
         guint           xid;
         char           *freeme;
 
+        gdkdisplay = gtk_widget_get_display (GTK_WIDGET (dialog));
+
         /* FIXME: get info from xid */
 
         desktop_file = NULL;
@@ -513,7 +522,7 @@ add_inhibitor (GsmInhibitDialog *dialog,
         xid = gsm_inhibitor_peek_toplevel_xid (inhibitor);
         g_debug ("GsmInhibitDialog: inhibitor has XID %u", xid);
         if (xid > 0 && dialog->priv->have_xrender) {
-                pixbuf = get_pixbuf_for_window (xid, DEFAULT_SNAPSHOT_SIZE, DEFAULT_SNAPSHOT_SIZE);
+                pixbuf = get_pixbuf_for_window (gdkdisplay, xid, DEFAULT_SNAPSHOT_SIZE, DEFAULT_SNAPSHOT_SIZE);
                 if (pixbuf == NULL) {
                         g_debug ("GsmInhibitDialog: unable to read pixbuf from %u", xid);
                 }
@@ -982,21 +991,26 @@ gsm_inhibit_dialog_constructor (GType                  type,
                                 GObjectConstructParam *construct_properties)
 {
         GsmInhibitDialog *dialog;
+#ifdef HAVE_XRENDER
+        GdkDisplay *gdkdisplay;
+#endif /* HAVE_XRENDER */
 
         dialog = GSM_INHIBIT_DIALOG (G_OBJECT_CLASS (gsm_inhibit_dialog_parent_class)->constructor (type,
                                                                                                                   n_construct_properties,
                                                                                                                   construct_properties));
 
 #ifdef HAVE_XRENDER
+        gdkdisplay = gdk_display_get_default ();
+
         gdk_error_trap_push ();
-        if (XRenderQueryExtension (GDK_DISPLAY (), &dialog->priv->xrender_event_base, &dialog->priv->xrender_error_base)) {
+        if (XRenderQueryExtension (GDK_DISPLAY_XDISPLAY (gdkdisplay), &dialog->priv->xrender_event_base, &dialog->priv->xrender_error_base)) {
                 g_debug ("GsmInhibitDialog: Initialized XRender extension");
                 dialog->priv->have_xrender = TRUE;
         } else {
                 g_debug ("GsmInhibitDialog: Unable to initialize XRender extension");
                 dialog->priv->have_xrender = FALSE;
         }
-        gdk_display_sync (gdk_display_get_default ());
+        gdk_display_sync (gdkdisplay);
         gdk_error_trap_pop ();
 #endif /* HAVE_XRENDER */
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]