[gnome-panel/wip-warnings-next] multiscreen: remove GdkScreen



commit b2dde0a3996d7b556f3038a0bf00b97e338a9ec3
Author: Sebastian Geiger <sbastig gmx net>
Date:   Mon Feb 24 23:44:00 2020 +0100

    multiscreen: remove GdkScreen

 gnome-panel/panel-multiscreen.c | 176 ++++++++++++----------------------------
 gnome-panel/panel-multiscreen.h |   9 +-
 gnome-panel/panel-struts.c      |   3 +-
 gnome-panel/panel-toplevel.c    |   6 +-
 4 files changed, 58 insertions(+), 136 deletions(-)
---
diff --git a/gnome-panel/panel-multiscreen.c b/gnome-panel/panel-multiscreen.c
index ca6fd6869..7ea454bd5 100644
--- a/gnome-panel/panel-multiscreen.c
+++ b/gnome-panel/panel-multiscreen.c
@@ -34,9 +34,8 @@
 
 #include <string.h>
 
-static int            screens     = 0;
-static int           *monitors    = NULL;
-static GdkRectangle **geometries  = NULL;
+static int            monitors    = 1;
+static GdkRectangle  *geometries  = NULL;
 static gboolean       initialized = FALSE;
 static gboolean       have_randr  = FALSE;
 static gboolean       have_randr_1_3 = FALSE;
@@ -84,10 +83,10 @@ _panel_multiscreen_output_should_be_first (Display       *xdisplay,
 }
 
 static gboolean
-panel_multiscreen_get_randr_monitors_for_screen (GdkScreen     *screen,
-                                                int           *monitors_ret,
+panel_multiscreen_get_randr_monitors_for_screen (int           *monitors_ret,
                                                 GdkRectangle **geometries_ret)
 {
+       GdkScreen          *screen;
        Display            *xdisplay;
        Window              xroot;
        XRRScreenResources *resources;
@@ -122,6 +121,7 @@ panel_multiscreen_get_randr_monitors_for_screen (GdkScreen     *screen,
         * long-term solution.
         */
 
+       screen = gdk_screen_get_default ();
        xdisplay = GDK_SCREEN_XDISPLAY (screen);
        xroot = GDK_WINDOW_XID (gdk_screen_get_root_window (screen));
 
@@ -215,27 +215,30 @@ panel_multiscreen_get_randr_monitors_for_screen (GdkScreen     *screen,
 }
 
 static void
-panel_multiscreen_get_gdk_monitors_for_screen (GdkScreen     *screen,
-                                              int           *monitors_ret,
+panel_multiscreen_get_gdk_monitors_for_screen (int           *monitors_ret,
                                               GdkRectangle **geometries_ret)
 {
+       GdkDisplay   *display;
        int           num_monitors;
        GdkRectangle *geometries;
        int           i;
 
-       num_monitors = gdk_screen_get_n_monitors (screen);
+       display = gdk_display_get_default ();
+       num_monitors = gdk_display_get_n_monitors (display);
        geometries = g_new (GdkRectangle, num_monitors);
 
        for (i = 0; i < num_monitors; i++)
-               gdk_screen_get_monitor_geometry (screen, i, &(geometries[i]));
+         GdkMonitor * monitor;
+
+         monitor = gdk_display_get_monitor (display, i);
+         gdk_monitor_get_geometry (monitor, &(geometries[i]));
 
        *monitors_ret = num_monitors;
        *geometries_ret = geometries;
 }
 
 static void
-panel_multiscreen_get_raw_monitors_for_screen (GdkScreen     *screen,
-                                              int           *monitors_ret,
+panel_multiscreen_get_raw_monitors_for_screen (int           *monitors_ret,
                                               GdkRectangle **geometries_ret)
 {
        gboolean res;
@@ -243,14 +246,12 @@ panel_multiscreen_get_raw_monitors_for_screen (GdkScreen     *screen,
        *monitors_ret = 0;
        *geometries_ret = NULL;
 
-       res = panel_multiscreen_get_randr_monitors_for_screen (screen,
-                                                              monitors_ret,
+       res = panel_multiscreen_get_randr_monitors_for_screen (monitors_ret,
                                                               geometries_ret);
        if (res && *monitors_ret > 0)
                return;
 
-       panel_multiscreen_get_gdk_monitors_for_screen (screen,
-                                                      monitors_ret,
+       panel_multiscreen_get_gdk_monitors_for_screen (monitors_ret,
                                                       geometries_ret);
 }
 
@@ -361,12 +362,10 @@ panel_multiscreen_compress_overlapping_monitors (int           *num_monitors_ino
 }
 
 static void
-panel_multiscreen_get_monitors_for_screen (GdkScreen     *screen,
-                                          int           *monitors_ret,
+panel_multiscreen_get_monitors_for_screen (int           *monitors_ret,
                                           GdkRectangle **geometries_ret)
 {
-       panel_multiscreen_get_raw_monitors_for_screen (screen,
-                                                      monitors_ret,
+       panel_multiscreen_get_raw_monitors_for_screen (monitors_ret,
                                                       geometries_ret);
        panel_multiscreen_compress_overlapping_monitors (monitors_ret,
                                                         geometries_ret);
@@ -421,37 +420,27 @@ void
 panel_multiscreen_init (void)
 {
        GdkDisplay *display;
-       int         i;
+       GdkScreen *screen;
 
        if (initialized)
                return;
 
        display = gdk_display_get_default ();
-       screens = 1;
 
        panel_multiscreen_init_randr (display);
 
-       monitors   = g_new0 (int, screens);
-       geometries = g_new0 (GdkRectangle *, screens);
-
-       for (i = 0; i < screens; i++) {
-               GdkScreen *screen;
-
-               screen = gdk_display_get_screen (display, i);
+       screen = gdk_screen_get_default ();
 
-               /* We connect to both signals to be on the safe side, but in
-                * theory, it should be enough to only connect to
-                * monitors-changed. Since we'll likely get two signals, we do
-                * the real callback in the idle loop. */
-               g_signal_connect (screen, "size-changed",
-                                 G_CALLBACK (panel_multiscreen_queue_reinit), NULL);
-               g_signal_connect (screen, "monitors-changed",
-                                 G_CALLBACK (panel_multiscreen_queue_reinit), NULL);
+       /* We connect to both signals to be on the safe side, but in
+        * theory, it should be enough to only connect to
+        * monitors-changed. Since we'll likely get two signals, we do
+        * the real callback in the idle loop. */
+       g_signal_connect (screen, "size-changed",
+                         G_CALLBACK (panel_multiscreen_queue_reinit), NULL);
+       g_signal_connect (screen, "monitors-changed",
+                         G_CALLBACK (panel_multiscreen_queue_reinit), NULL);
 
-               panel_multiscreen_get_monitors_for_screen (screen,
-                                                          &(monitors[i]),
-                                                          &(geometries[i]));
-       }
+       panel_multiscreen_get_monitors_for_screen (&monitors), &geometries);
 
        initialized = TRUE;
 }
@@ -462,14 +451,7 @@ panel_multiscreen_reinit (void)
        GdkScreen *screen;
        GList     *toplevels, *l;
 
-       if (monitors)
-               g_free (monitors);
-
        if (geometries) {
-               int j;
-
-               for (j = 0; j < screens; j++)
-                       g_free (geometries[j]);
                g_free (geometries);
        }
 
@@ -486,79 +468,41 @@ panel_multiscreen_reinit (void)
 
        g_list_free (toplevels);
 }
-       
-int
-panel_multiscreen_screens (void)
-{
-       return screens;
-}
-
-int
-panel_multiscreen_monitors (GdkScreen *screen)
-{
-       int n_screen;
-
-       n_screen = gdk_screen_get_number (screen);
-
-       g_return_val_if_fail (n_screen >= 0 && n_screen < screens, 1);
-
-       return monitors [n_screen];
-}
 
 int
 panel_multiscreen_x (GdkScreen *screen,
                     int        monitor)
 {
-       int n_screen;
-
-       n_screen = gdk_screen_get_number (screen);
+       g_return_val_if_fail (monitor >= 0 && monitor < monitors, 0);
 
-       g_return_val_if_fail (n_screen >= 0 && n_screen < screens, 0);
-       g_return_val_if_fail (monitor >= 0 && monitor < monitors [n_screen], 0);
-
-       return geometries [n_screen][monitor].x;
+       return geometries [monitor].x;
 }
 
 int
 panel_multiscreen_y (GdkScreen *screen,
                     int        monitor)
 {
-       int n_screen;
-
-       n_screen = gdk_screen_get_number (screen);
+       g_return_val_if_fail (monitor >= 0 && monitor < monitors, 0);
 
-       g_return_val_if_fail (n_screen >= 0 && n_screen < screens, 0);
-       g_return_val_if_fail (monitor >= 0 && monitor < monitors [n_screen], 0);
-
-       return geometries [n_screen][monitor].y;
+       return geometries [monitor].y;
 }
 
 int
 panel_multiscreen_width (GdkScreen *screen,
                         int        monitor)
 {
-       int n_screen;
-
-       n_screen = gdk_screen_get_number (screen);
+       g_return_val_if_fail (monitor >= 0 && monitor < monitors, 0);
 
-       g_return_val_if_fail (n_screen >= 0 && n_screen < screens, 0);
-       g_return_val_if_fail (monitor >= 0 && monitor < monitors [n_screen], 0);
-
-       return geometries [n_screen][monitor].width;
+       return geometries [monitor].width;
 }
 
 int
 panel_multiscreen_height (GdkScreen *screen,
                          int        monitor)
 {
-       int n_screen;
-
-       n_screen = gdk_screen_get_number (screen);
+       g_return_val_if_fail (monitor >= 0 && monitor < monitors, 0);
 
-       g_return_val_if_fail (n_screen >= 0 && n_screen < screens, 0);
-       g_return_val_if_fail (monitor >= 0 && monitor < monitors [n_screen], 0);
-
-       return geometries [n_screen][monitor].height;
+       return geometries [monitor].height;
 }
 
 int
@@ -591,34 +535,25 @@ axis_distance (int p, int axis_start, int axis_size)
  * view of which monitors are present. Look at get_monitors_for_screen() above
  * to see why. */
 int
-panel_multiscreen_get_monitor_at_point (GdkScreen *screen,
-                                       int        x,
+panel_multiscreen_get_monitor_at_point (int        x,
                                        int        y)
 {
-       int n_screen;
        int i;
-       int n_monitors;
-       GdkRectangle *geoms;
        int min_dist_squared;
        int closest_monitor;
 
        /* not -1 as callers expect a real monitor */
        g_return_val_if_fail (GDK_IS_SCREEN (screen), 0);
 
-       n_screen = gdk_screen_get_number (screen);
-
-       n_monitors = monitors[n_screen];
-       geoms = geometries[n_screen];
-
        min_dist_squared = G_MAXINT32;
        closest_monitor = 0;
 
-       for (i = 0; i < n_monitors; i++) {
+       for (i = 0; i < monitors; i++) {
                int dist_x, dist_y;
                int dist_squared;
 
-               dist_x = axis_distance (x, geoms[i].x, geoms[i].width);
-               dist_y = axis_distance (y, geoms[i].y, geoms[i].height);
+               dist_x = axis_distance (x, geometries[i].x, geometries[i].width);
+               dist_y = axis_distance (y, geometries[i].y, geometries[i].height);
 
                if (dist_x == 0 && dist_y == 0)
                        return i;
@@ -642,56 +577,49 @@ typedef struct {
 } MonitorBounds;
 
 static inline void
-get_monitor_bounds (int            n_screen,
-                   int            n_monitor,
+get_monitor_bounds (int            n_monitor,
                    MonitorBounds *bounds)
 {
-       g_assert (n_screen >= 0 && n_screen < screens);
-       g_assert (n_monitor >= 0 || n_monitor < monitors [n_screen]);
+       g_assert (n_monitor >= 0 || n_monitor < monitors);
        g_assert (bounds != NULL);
 
-       bounds->x0 = geometries [n_screen][n_monitor].x;
-       bounds->y0 = geometries [n_screen][n_monitor].y;
-       bounds->x1 = bounds->x0 + geometries [n_screen][n_monitor].width;
-       bounds->y1 = bounds->y0 + geometries [n_screen][n_monitor].height;
+       bounds->x0 = geometries [n_monitor].x;
+       bounds->y0 = geometries [n_monitor].y;
+       bounds->x1 = bounds->x0 + geometries [n_monitor].width;
+       bounds->y1 = bounds->y0 + geometries [n_monitor].height;
 }
 
 /* determines whether a given monitor is along the visible
  * edge of the logical screen.
  */
 void
-panel_multiscreen_is_at_visible_extreme (GdkScreen *screen,
-                                        int        n_monitor,
+panel_multiscreen_is_at_visible_extreme (int        n_monitor,
                                         gboolean  *leftmost,
                                         gboolean  *rightmost,
                                         gboolean  *topmost,
                                         gboolean  *bottommost)
 {
        MonitorBounds monitor;
-       int           n_screen, i;
-
-       n_screen = gdk_screen_get_number (screen);
 
        *leftmost   = TRUE;
        *rightmost  = TRUE;
        *topmost    = TRUE;
        *bottommost = TRUE;
 
-       g_return_if_fail (n_screen >= 0 && n_screen < screens);
-       g_return_if_fail (n_monitor >= 0 && n_monitor < monitors [n_screen]);
+       g_return_if_fail (n_monitor >= 0 && n_monitor < monitors);
 
-       get_monitor_bounds (n_screen, n_monitor, &monitor);
+       get_monitor_bounds (n_monitor, &monitor);
        
        /* go through each monitor and try to find one either right,
         * below, above, or left of the specified monitor
         */
 
-       for (i = 0; i < monitors [n_screen]; i++) {
+       for (i = 0; i < monitors; i++) {
                MonitorBounds iter;
 
                if (i == n_monitor) continue;
 
-               get_monitor_bounds (n_screen, i, &iter);
+               get_monitor_bounds (i, &iter);
 
                if ((iter.y0 >= monitor.y0 && iter.y0 <  monitor.y1) ||
                    (iter.y1 >  monitor.y0 && iter.y1 <= monitor.y1)) {
diff --git a/gnome-panel/panel-multiscreen.h b/gnome-panel/panel-multiscreen.h
index 2e4934ccb..9876cdbfd 100644
--- a/gnome-panel/panel-multiscreen.h
+++ b/gnome-panel/panel-multiscreen.h
@@ -31,9 +31,6 @@
 void   panel_multiscreen_init                  (void);
 void   panel_multiscreen_reinit                (void);
 
-int    panel_multiscreen_screens               (void);
-int    panel_multiscreen_monitors              (GdkScreen *screen);
-
 int    panel_multiscreen_x                     (GdkScreen *screen,
                                                 int        monitor);
 int    panel_multiscreen_y                     (GdkScreen *screen,
@@ -43,11 +40,9 @@ int  panel_multiscreen_width                 (GdkScreen *screen,
 int    panel_multiscreen_height                (GdkScreen *screen,
                                                 int        monitor);
 int    panel_multiscreen_locate_widget_monitor (GtkWidget *widget);
-int     panel_multiscreen_get_monitor_at_point  (GdkScreen *screen,
-                                                int        x,
+int     panel_multiscreen_get_monitor_at_point  (int        x,
                                                 int        y);
-void    panel_multiscreen_is_at_visible_extreme (GdkScreen *screen,
-                                                int        monitor,
+void    panel_multiscreen_is_at_visible_extreme (int        monitor,
                                                 gboolean  *leftmost,
                                                 gboolean  *rightmost,
                                                 gboolean  *topmost,
diff --git a/gnome-panel/panel-struts.c b/gnome-panel/panel-struts.c
index 5bdba495c..2c583b9de 100644
--- a/gnome-panel/panel-struts.c
+++ b/gnome-panel/panel-struts.c
@@ -281,8 +281,7 @@ panel_struts_set_window_hint (PanelToplevel *toplevel)
                                           &monitor_width,
                                           &monitor_height);
 
-        panel_multiscreen_is_at_visible_extreme (screen,
-                                                 strut->monitor,
+        panel_multiscreen_is_at_visible_extreme (strut->monitor,
                                                  &leftmost,
                                                  &rightmost,
                                                  &topmost,
diff --git a/gnome-panel/panel-toplevel.c b/gnome-panel/panel-toplevel.c
index c3395a0a2..880c8e676 100644
--- a/gnome-panel/panel-toplevel.c
+++ b/gnome-panel/panel-toplevel.c
@@ -753,7 +753,7 @@ panel_toplevel_calc_new_orientation (PanelToplevel *toplevel,
 
        screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
 
-       monitor = panel_multiscreen_get_monitor_at_point (screen, pointer_x, pointer_y);
+       monitor = panel_multiscreen_get_monitor_at_point (pointer_x, pointer_y);
 
        if (toplevel->priv->geometry.height < toplevel->priv->geometry.width)
                vborder = hborder = (3 * toplevel->priv->geometry.height) >> 1;
@@ -865,7 +865,7 @@ panel_toplevel_move_to (PanelToplevel *toplevel,
                 toplevel->priv->orientation & PANEL_HORIZONTAL_MASK)
                new_orientation = PANEL_ORIENTATION_BOTTOM;
 
-       new_monitor = panel_multiscreen_get_monitor_at_point (screen, new_x, new_y);
+       new_monitor = panel_multiscreen_get_monitor_at_point (new_x, new_y);
 
        panel_toplevel_get_monitor_geometry (
                        toplevel, NULL, NULL, &monitor_width, &monitor_height);
@@ -1944,7 +1944,7 @@ panel_toplevel_update_expanded_position (PanelToplevel *toplevel)
                break;
        }
 
-       monitor = panel_multiscreen_get_monitor_at_point (screen, x, y);
+       monitor = panel_multiscreen_get_monitor_at_point (x, y);
 
        panel_toplevel_set_monitor_internal (toplevel, monitor, TRUE);
 


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