[gnome-panel] clock: stop using deprecated API from GdkScreen



commit 14694981d1ff8877fee4f6da069a090371949014
Author: Alberts Muktupāvels <alberts muktupavels gmail com>
Date:   Sun Oct 30 21:38:17 2016 +0200

    clock: stop using deprecated API from GdkScreen

 applets/clock/calendar-window.c |   22 +++++++++++++++++--
 applets/clock/clock.c           |   42 +++++++++++++++++---------------------
 configure.ac                    |    2 +-
 3 files changed, 39 insertions(+), 27 deletions(-)
---
diff --git a/applets/clock/calendar-window.c b/applets/clock/calendar-window.c
index df0e6f5..ac0a3b8 100644
--- a/applets/clock/calendar-window.c
+++ b/applets/clock/calendar-window.c
@@ -1236,6 +1236,21 @@ typedef struct
 } ConstraintData;
 
 static void
+get_monitor_geometry (GtkWidget    *widget,
+                      GdkRectangle *geometry)
+{
+       GdkDisplay *display;
+       GdkWindow *window;
+       GdkMonitor *monitor;
+
+       display = gdk_display_get_default ();
+       window = gtk_widget_get_window (widget);
+       monitor = gdk_display_get_monitor_at_window (display, window);
+
+       gdk_monitor_get_geometry (monitor, geometry);
+}
+
+static void
 constrain_list_size (GtkWidget      *widget,
                      GtkAllocation  *allocation,
                      ConstraintData *constraint)
@@ -1244,7 +1259,7 @@ constrain_list_size (GtkWidget      *widget,
        GtkStyleContext *context;
        GtkStateFlags    state;
        GtkBorder        padding;
-        int              screen_h;
+        GdkRectangle     monitor;
         int              width;
         int              height;
         int              max_height;
@@ -1253,9 +1268,10 @@ constrain_list_size (GtkWidget      *widget,
         gtk_widget_get_preferred_size (constraint->calendar, &req, NULL);
         width = MIN (allocation->width, req.width);
 
-       screen_h = gdk_screen_get_height (gtk_widget_get_screen (widget));
+        get_monitor_geometry (widget, &monitor);
+
         /* constrain height to be the tree height up to a max */
-        max_height = (screen_h - req.height) / 3;
+        max_height = (monitor.height - req.height) / 3;
         gtk_widget_get_preferred_size (constraint->tree, &req, NULL);
 
        state = gtk_widget_get_state_flags (widget);
diff --git a/applets/clock/clock.c b/applets/clock/clock.c
index 8759644..64dae68 100644
--- a/applets/clock/clock.c
+++ b/applets/clock/clock.c
@@ -407,18 +407,30 @@ create_calendar (ClockData *cd)
 }
 
 static void
+get_monitor_geometry (ClockData    *cd,
+                      GdkRectangle *geometry)
+{
+       GdkDisplay *display;
+       GdkWindow *window;
+       GdkMonitor *monitor;
+
+       display = gdk_display_get_default ();
+       window = gtk_widget_get_window (cd->panel_button);
+       monitor = gdk_display_get_monitor_at_window (display, window);
+
+       gdk_monitor_get_geometry (monitor, geometry);
+}
+
+static void
 position_calendar_popup (ClockData *cd)
 {
        GtkRequisition  req;
        GtkAllocation   allocation;
-       GdkScreen      *screen;
        GdkRectangle    monitor;
        GdkGravity      gravity = GDK_GRAVITY_NORTH_WEST;
        int             button_w, button_h;
        int             x, y;
        int             w, h;
-       int             i, n;
-       gboolean        found_monitor = FALSE;
 
        /* Get root origin of the toggle button, and position above that. */
        gdk_window_get_origin (gtk_widget_get_window (cd->panel_button),
@@ -433,26 +445,7 @@ position_calendar_popup (ClockData *cd)
        button_w = allocation.width;
        button_h = allocation.height;
 
-       screen = gtk_window_get_screen (GTK_WINDOW (cd->calendar_popup));
-
-       n = gdk_screen_get_n_monitors (screen);
-       for (i = 0; i < n; i++) {
-               gdk_screen_get_monitor_geometry (screen, i, &monitor);
-               if (x >= monitor.x && x <= monitor.x + monitor.width &&
-                   y >= monitor.y && y <= monitor.y + monitor.height) {
-                       found_monitor = TRUE;
-                       break;
-               }
-       }
-
-       if (!found_monitor) {
-               /* eek, we should be on one of those xinerama
-                  monitors */
-               monitor.x = 0;
-               monitor.y = 0;
-               monitor.width = gdk_screen_get_width (screen);
-               monitor.height = gdk_screen_get_height (screen);
-       }
+       get_monitor_geometry (cd, &monitor);
 
        /* Based on panel orientation, position the popup.
         * Ignore window gravity since the window is undecorated.
@@ -498,6 +491,9 @@ position_calendar_popup (ClockData *cd)
                gravity = GDK_GRAVITY_SOUTH_WEST;
 
                break;
+       default:
+               g_assert_not_reached ();
+               break;
        }
 
        gtk_window_move (GTK_WINDOW (cd->calendar_popup), x, y);
diff --git a/configure.ac b/configure.ac
index fe0bd3f..aac6b2f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -94,7 +94,7 @@ LIBGNOME_DESKTOP_REQUIRED=2.91.0
 GDK_PIXBUF_REQUIRED=2.25.2
 PANGO_REQUIRED=1.15.4
 GLIB_REQUIRED=2.45.3
-GTK_REQUIRED=3.19.6
+GTK_REQUIRED=3.22.0
 LIBWNCK_REQUIRED=3.4.6
 LIBGNOME_MENU_REQUIRED=3.7.90
 LIBECAL_REQUIRED=3.5.3


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