[gnome-panel/wip-warnings: 1/2] multiscreen: remove GdkScreen
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip-warnings: 1/2] multiscreen: remove GdkScreen
- Date: Tue, 25 Feb 2020 17:21:29 +0000 (UTC)
commit 38e4050759e38d9916a65658d0a97fb0d6c0f567
Author: Sebastian Geiger <sbastig gmx net>
Date: Tue Feb 25 16:01:16 2020 +0100
multiscreen: remove GdkScreen
Since there is only one GdkScreen object it is not
necessary to pass the 'screen' pointer around
between functions.
Also the global 'screens' variable is obsolete
since it can only ever contain a single screen
object.
gnome-panel/panel-multiscreen.c | 169 ++++++++++++++--------------------------
gnome-panel/panel-multiscreen.h | 6 +-
gnome-panel/panel-struts.c | 3 +-
gnome-panel/panel-toplevel.c | 6 +-
4 files changed, 63 insertions(+), 121 deletions(-)
---
diff --git a/gnome-panel/panel-multiscreen.c b/gnome-panel/panel-multiscreen.c
index caf4ae398..1fe252e17 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 = 0;
+static GdkRectangle *monitor_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,31 @@ 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]));
+ for (i = 0; i < num_monitors; 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 +247,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 +363,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 +421,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, &monitor_geometries);
initialized = TRUE;
}
@@ -462,15 +452,8 @@ 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);
+ if (monitor_geometries) {
+ g_free (monitor_geometries);
}
screen = gdk_screen_get_default ();
@@ -491,56 +474,36 @@ 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 monitor_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 (n_screen >= 0 && n_screen < screens, 0);
- g_return_val_if_fail (monitor >= 0 && monitor < monitors [n_screen], 0);
+ g_return_val_if_fail (monitor >= 0 && monitor < monitors, 0);
- return geometries [n_screen][monitor].y;
+ return monitor_geometries [monitor].y;
}
int
panel_multiscreen_width (GdkScreen *screen,
int monitor)
{
- int n_screen;
+ g_return_val_if_fail (monitor >= 0 && monitor < monitors, 0);
- n_screen = gdk_screen_get_number (screen);
-
- 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 monitor_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 monitor_geometries [monitor].height;
}
int
@@ -573,34 +536,22 @@ 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, monitor_geometries[i].x, monitor_geometries[i].width);
+ dist_y = axis_distance (y, monitor_geometries[i].y, monitor_geometries[i].height);
if (dist_x == 0 && dist_y == 0)
return i;
@@ -624,56 +575,50 @@ 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 = monitor_geometries [n_monitor].x;
+ bounds->y0 = monitor_geometries [n_monitor].y;
+ bounds->x1 = bounds->x0 + monitor_geometries [n_monitor].width;
+ bounds->y1 = bounds->y0 + monitor_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);
+ int i;
*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 c55fcdde9..9876cdbfd 100644
--- a/gnome-panel/panel-multiscreen.h
+++ b/gnome-panel/panel-multiscreen.h
@@ -40,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]