[gnome-panel/wip/geiger/geometry: 3/5] panel-multiscreen: remove obsolete code
- From: Sebastian Geiger <segeiger src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-panel/wip/geiger/geometry: 3/5] panel-multiscreen: remove obsolete code
- Date: Sat, 17 Feb 2018 13:47:58 +0000 (UTC)
commit 8ee45ca2cf2d234e54e88858eaf3f1011a8f5fcc
Author: Sebastian Geiger <sbastig gmx net>
Date: Fri Feb 16 23:37:24 2018 +0100
panel-multiscreen: remove obsolete code
gnome-panel/panel-multiscreen.c | 633 +++------------------------------------
gnome-panel/panel-multiscreen.h | 27 +--
gnome-panel/panel-struts.c | 11 +-
gnome-panel/panel-toplevel.c | 121 ++++----
4 files changed, 113 insertions(+), 679 deletions(-)
---
diff --git a/gnome-panel/panel-multiscreen.c b/gnome-panel/panel-multiscreen.c
index ca6fd68..b365187 100644
--- a/gnome-panel/panel-multiscreen.c
+++ b/gnome-panel/panel-multiscreen.c
@@ -23,354 +23,13 @@
* Mark McLoughlin <mark skynet ie>
*/
-#include <config.h>
-
-#include <X11/Xatom.h>
-#include <X11/Xlib.h>
-#include <X11/extensions/Xrandr.h>
-#include <gdk/gdkx.h>
-
+#include "config.h"
#include "panel-multiscreen.h"
+#include "panel-monitor.h"
-#include <string.h>
-
-static int screens = 0;
-static int *monitors = NULL;
-static GdkRectangle **geometries = NULL;
-static gboolean initialized = FALSE;
-static gboolean have_randr = FALSE;
-static gboolean have_randr_1_3 = FALSE;
-static guint reinit_id = 0;
-
-static gboolean
-_panel_multiscreen_output_should_be_first (Display *xdisplay,
- RROutput output,
- XRROutputInfo *info,
- RROutput primary)
-{
- if (primary)
- return output == primary;
-
- if (have_randr_1_3) {
- Atom connector_type_atom;
- Atom actual_type;
- int actual_format;
- unsigned long nitems;
- unsigned long bytes_after;
- unsigned char *prop;
- char *connector_type;
- gboolean retval;
-
- connector_type_atom = XInternAtom (xdisplay, "ConnectorType", False);
-
- if (XRRGetOutputProperty (xdisplay, output, connector_type_atom,
- 0, 100, False, False, None,
- &actual_type, &actual_format,
- &nitems, &bytes_after, &prop) == Success) {
- if (actual_type == XA_ATOM && nitems == 1 && actual_format == 32) {
- connector_type = XGetAtomName (xdisplay, prop[0]);
- retval = g_strcmp0 (connector_type, "Panel") == 0;
- XFree (connector_type);
- return retval;
- }
- }
- }
-
- /* Pre-1.3 fallback:
- * "LVDS" is the oh-so-intuitive name that X gives to laptop LCDs.
- * It can actually be LVDS0, LVDS-0, Lvds, etc.
- */
- return (g_ascii_strncasecmp (info->name, "LVDS", strlen ("LVDS")) == 0);
-}
-
-static gboolean
-panel_multiscreen_get_randr_monitors_for_screen (GdkScreen *screen,
- int *monitors_ret,
- GdkRectangle **geometries_ret)
-{
- Display *xdisplay;
- Window xroot;
- XRRScreenResources *resources;
- RROutput primary;
- GArray *geometries;
- int i;
- gboolean driver_is_pre_randr_1_2;
-
- if (!have_randr)
- return FALSE;
-
- /* GTK+ 2.14.x uses the Xinerama API, instead of RANDR, to get the
- * monitor geometries. It does this to avoid calling
- * XRRGetScreenResources(), which is slow as it re-detects all the
- * monitors --- note that XRRGetScreenResourcesCurrent() had not been
- * introduced yet. Using Xinerama in GTK+ has the bad side effect that
- * gdk_screen_get_monitor_plug_name() will return NULL, as Xinerama
- * does not provide that information, unlike RANDR.
- *
- * Here we need to identify the output names, so that we can put the
- * built-in LCD in a laptop *before* all other outputs. This is so
- * that gnome-panel will normally prefer to appear on the "native"
- * display rather than on an external monitor.
- *
- * To get the output names and geometries, we will not use
- * gdk_screen_get_n_monitors() and friends, but rather we will call
- * XRR*() directly.
- *
- * See https://bugzilla.novell.com/show_bug.cgi?id=479684 for this
- * particular bug, and and
- * http://bugzilla.gnome.org/show_bug.cgi?id=562944 for a more
- * long-term solution.
- */
-
- xdisplay = GDK_SCREEN_XDISPLAY (screen);
- xroot = GDK_WINDOW_XID (gdk_screen_get_root_window (screen));
-
- if (have_randr_1_3) {
- resources = XRRGetScreenResourcesCurrent (xdisplay, xroot);
- if (resources->noutput == 0) {
- /* This might happen if nothing tried to get randr
- * resources from the server before, so we need an
- * active probe. See comment #27 in
- * https://bugzilla.gnome.org/show_bug.cgi?id=597101 */
- XRRFreeScreenResources (resources);
- resources = XRRGetScreenResources (xdisplay, xroot);
- }
- } else
- resources = XRRGetScreenResources (xdisplay, xroot);
-
- if (!resources)
- return FALSE;
-
- primary = None;
- if (have_randr_1_3)
- primary = XRRGetOutputPrimary (xdisplay, xroot);
-
- geometries = g_array_sized_new (FALSE, FALSE,
- sizeof (GdkRectangle),
- resources->noutput);
-
- driver_is_pre_randr_1_2 = FALSE;
-
- for (i = 0; i < resources->noutput; i++) {
- XRROutputInfo *output;
-
- output = XRRGetOutputInfo (xdisplay, resources,
- resources->outputs[i]);
-
- /* Drivers before RANDR 1.2 return "default" for the output
- * name */
- if (g_strcmp0 (output->name, "default") == 0)
- driver_is_pre_randr_1_2 = TRUE;
-
- if (output->connection != RR_Disconnected &&
- output->crtc != 0) {
- XRRCrtcInfo *crtc;
- GdkRectangle rect;
-
- crtc = XRRGetCrtcInfo (xdisplay, resources,
- output->crtc);
-
- rect.x = crtc->x;
- rect.y = crtc->y;
- rect.width = crtc->width;
- rect.height = crtc->height;
-
- XRRFreeCrtcInfo (crtc);
-
- if (_panel_multiscreen_output_should_be_first (xdisplay,
- resources->outputs[i],
- output, primary))
- g_array_prepend_vals (geometries, &rect, 1);
- else
- g_array_append_vals (geometries, &rect, 1);
- }
-
- XRRFreeOutputInfo (output);
- }
-
- XRRFreeScreenResources (resources);
-
- if (driver_is_pre_randr_1_2) {
- /* Drivers before RANDR 1.2 don't provide useful info about
- * outputs */
- g_array_free (geometries, TRUE);
- return FALSE;
- }
-
- if (geometries->len == 0) {
- /* This can happen in at least one case:
- * https://bugzilla.novell.com/show_bug.cgi?id=543876 where all
- * monitors appear disconnected (possibly because the screen
- * is behing a KVM switch) -- see comment #8.
- * There might be other cases too, so we stay on the safe side.
- */
- g_array_free (geometries, TRUE);
- return FALSE;
- }
-
- *monitors_ret = geometries->len;
- *geometries_ret = (GdkRectangle *) g_array_free (geometries, FALSE);
+static guint reinit_id = 0;
- return TRUE;
-}
-
-static void
-panel_multiscreen_get_gdk_monitors_for_screen (GdkScreen *screen,
- int *monitors_ret,
- GdkRectangle **geometries_ret)
-{
- int num_monitors;
- GdkRectangle *geometries;
- int i;
-
- num_monitors = gdk_screen_get_n_monitors (screen);
- geometries = g_new (GdkRectangle, num_monitors);
-
- for (i = 0; i < num_monitors; i++)
- gdk_screen_get_monitor_geometry (screen, i, &(geometries[i]));
-
- *monitors_ret = num_monitors;
- *geometries_ret = geometries;
-}
-
-static void
-panel_multiscreen_get_raw_monitors_for_screen (GdkScreen *screen,
- int *monitors_ret,
- GdkRectangle **geometries_ret)
-{
- gboolean res;
-
- *monitors_ret = 0;
- *geometries_ret = NULL;
-
- res = panel_multiscreen_get_randr_monitors_for_screen (screen,
- monitors_ret,
- geometries_ret);
- if (res && *monitors_ret > 0)
- return;
-
- panel_multiscreen_get_gdk_monitors_for_screen (screen,
- monitors_ret,
- geometries_ret);
-}
-
-static inline gboolean
-rectangle_overlaps (GdkRectangle *a,
- GdkRectangle *b)
-{
- return gdk_rectangle_intersect (a, b, NULL);
-}
-
-static long
-pixels_in_rectangle (GdkRectangle *r)
-{
- return (long) (r->width * r->height);
-}
-
-static void
-panel_multiscreen_compress_overlapping_monitors (int *num_monitors_inout,
- GdkRectangle **geometries_inout)
-{
- int num_monitors;
- GdkRectangle *geometries;
- int i;
-
- num_monitors = *num_monitors_inout;
- geometries = *geometries_inout;
-
- /* http://bugzilla.gnome.org/show_bug.cgi?id=530969
- * https://bugzilla.novell.com/show_bug.cgi?id=310208
- * and many other such bugs...
- *
- * RANDR sometimes gives us monitors that overlap (i.e. outputs whose
- * bounding rectangles overlap). This is sometimes right and sometimes
- * wrong:
- *
- * * Right - two 1024x768 outputs at the same offset (0, 0) that show
- * the same thing. Think "laptop plus projector with the same
- * resolution".
- *
- * * Wrong - one 1280x1024 output ("laptop internal LCD") and another
- * 1024x768 output ("external monitor"), both at offset (0, 0).
- * There is no way for the monitor with the small resolution to
- * show the complete image from the laptop's LCD, unless one uses
- * panning (but nobody wants panning, right!?).
- *
- * With overlapping monitors, we may end up placing the panel with
- * respect to the "wrong" one. This is always wrong, as the panel
- * appears "in the middle of the screen" of the monitor with the
- * smaller resolution, instead of at the edge.
- *
- * Our strategy is to find the subsets of overlapping monitors, and
- * "compress" each such set to being like if there were a single
- * monitor with the biggest resolution of each of that set's monitors.
- * Say we have four monitors
- *
- * A, B, C, D
- *
- * where B and D overlap. In that case, we'll generate a new list that
- * looks like
- *
- * A, MAX(B, D), C
- *
- * with three monitors.
- *
- * NOTE FOR THE FUTURE: We could avoid most of this mess if we had a
- * concept of a "primary monitor". Also, we could look at each
- * output's name or properties to see if it is the built-in LCD in a
- * laptop. However, with GTK+ 2.14.x we don't get output names, since
- * it gets the list outputs from Xinerama, not RANDR (and Xinerama
- * doesn't provide output names).
- */
-
- for (i = 0; i < num_monitors; i++) {
- long max_pixels;
- int j;
-
- max_pixels = pixels_in_rectangle (&geometries[i]);
-
- j = i + 1;
-
- while (j < num_monitors) {
- if (rectangle_overlaps (&geometries[i],
- &geometries[j])) {
- long pixels;
-
- pixels = pixels_in_rectangle (&geometries[j]);
- if (pixels > max_pixels) {
- max_pixels = pixels;
- /* keep the maximum */
- geometries[i] = geometries[j];
- }
-
- /* Shift the remaining monitors to the left */
- if (num_monitors - j - 1 > 0)
- memmove (&geometries[j],
- &geometries[j + 1],
- sizeof (geometries[0]) * (num_monitors - j - 1));
-
- num_monitors--;
- g_assert (num_monitors > 0);
- } else
- j++;
- }
- }
-
- *num_monitors_inout = num_monitors;
- *geometries_inout = geometries;
-}
-
-static void
-panel_multiscreen_get_monitors_for_screen (GdkScreen *screen,
- int *monitors_ret,
- GdkRectangle **geometries_ret)
-{
- panel_multiscreen_get_raw_monitors_for_screen (screen,
- monitors_ret,
- geometries_ret);
- panel_multiscreen_compress_overlapping_monitors (monitors_ret,
- geometries_ret);
-}
+static void panel_multiscreen_reinit (void);
static gboolean
panel_multiscreen_reinit_idle (gpointer data)
@@ -390,95 +49,28 @@ panel_multiscreen_queue_reinit (void)
reinit_id = g_idle_add (panel_multiscreen_reinit_idle, NULL);
}
-static void
-panel_multiscreen_init_randr (GdkDisplay *display)
-{
- Display *xdisplay;
- int event_base, error_base;
-
- have_randr = FALSE;
- have_randr_1_3 = FALSE;
-
- xdisplay = GDK_DISPLAY_XDISPLAY (display);
-
- /* We don't remember the event/error bases, as we expect to get "screen
- * changed" events from GdkScreen instead.
- */
-
- if (XRRQueryExtension (xdisplay, &event_base, &error_base)) {
- int major, minor;
-
- XRRQueryVersion (xdisplay, &major, &minor);
- if ((major == 1 && minor >= 2) || major > 1)
- have_randr = TRUE;
-
- if ((major == 1 && minor >= 3) || major > 1)
- have_randr_1_3 = TRUE;
- }
-}
-
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);
-
- panel_multiscreen_get_monitors_for_screen (screen,
- &(monitors[i]),
- &(geometries[i]));
- }
-
- initialized = TRUE;
+ /* 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);
}
-void
+static void
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);
- }
-
- screen = gdk_screen_get_default ();
- g_signal_handlers_disconnect_by_func (screen, panel_multiscreen_queue_reinit, NULL);
-
- initialized = FALSE;
- panel_multiscreen_init ();
-
toplevels = gtk_window_list_toplevels ();
for (l = toplevels; l; l = l->next)
@@ -486,153 +78,6 @@ 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 (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;
-}
-
-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);
-
- return geometries [n_screen][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 (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;
-}
-
-int
-panel_multiscreen_height (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);
-
- return geometries [n_screen][monitor].height;
-}
-
-int
-panel_multiscreen_locate_widget_monitor (GtkWidget *widget)
-{
- GtkWidget *toplevel;
- int retval = -1;
-
- toplevel = gtk_widget_get_toplevel (widget);
- if (!toplevel)
- return -1;
-
- g_object_get (toplevel, "monitor", &retval, NULL);
-
- return retval;
-}
-
-static int
-axis_distance (int p, int axis_start, int axis_size)
-{
- if (p >= axis_start && p < axis_start + axis_size)
- return 0;
- else if (p < axis_start)
- return (axis_start - p);
- else
- return (p - (axis_start + axis_size - 1));
-}
-
-/* The panel can't use gdk_screen_get_monitor_at_point() since it has its own
- * 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,
- 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++) {
- 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);
-
- if (dist_x == 0 && dist_y == 0)
- return i;
-
- dist_squared = dist_x * dist_x + dist_y * dist_y;
-
- if (dist_squared < min_dist_squared) {
- min_dist_squared = dist_squared;
- closest_monitor = i;
- }
- }
-
- return closest_monitor;
-}
typedef struct {
int x0;
@@ -642,56 +87,56 @@ typedef struct {
} MonitorBounds;
static inline void
-get_monitor_bounds (int n_screen,
- int n_monitor,
- MonitorBounds *bounds)
+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 (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;
+ int x, y, height, width;
+
+ panel_monitor_get_geometry (n_monitor,
+ &x, &y, &height, &width);
+
+ bounds->x0 = x;
+ bounds->y0 = y;
+ bounds->x1 = bounds->x0 + width;
+ bounds->y1 = bounds->y0 + 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,
- gboolean *leftmost,
- gboolean *rightmost,
- gboolean *topmost,
- gboolean *bottommost)
+panel_multiscreen_is_at_visible_extreme (int monitor_index,
+ gboolean *leftmost,
+ gboolean *rightmost,
+ gboolean *topmost,
+ gboolean *bottommost)
{
MonitorBounds monitor;
- int n_screen, i;
+ int i, n_monitors;
- n_screen = gdk_screen_get_number (screen);
+ n_monitors = gdk_display_get_n_monitors (gdk_display_get_default ());
*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 (monitor_index >= 0 && monitor_index < n_monitors);
+
+ get_monitor_bounds (monitor_index, &monitor);
- get_monitor_bounds (n_screen, 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 < n_monitors; i++) {
MonitorBounds iter;
- if (i == n_monitor) continue;
+ if (i == monitor_index) 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 2e4934c..f9467db 100644
--- a/gnome-panel/panel-multiscreen.h
+++ b/gnome-panel/panel-multiscreen.h
@@ -29,28 +29,11 @@
#include <gtk/gtk.h>
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,
- int monitor);
-int panel_multiscreen_width (GdkScreen *screen,
- int monitor);
-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 y);
-void panel_multiscreen_is_at_visible_extreme (GdkScreen *screen,
- int monitor,
- gboolean *leftmost,
- gboolean *rightmost,
- gboolean *topmost,
- gboolean *bottommost);
+void panel_multiscreen_is_at_visible_extreme (int monitor_index,
+ gboolean *leftmost,
+ gboolean *rightmost,
+ gboolean *topmost,
+ gboolean *bottommost);
#endif /* __PANEL_MULTISCREEN_H__ */
diff --git a/gnome-panel/panel-struts.c b/gnome-panel/panel-struts.c
index 2ac3b04..6a5d590 100644
--- a/gnome-panel/panel-struts.c
+++ b/gnome-panel/panel-struts.c
@@ -260,12 +260,11 @@ panel_struts_set_window_hint (PanelToplevel *toplevel)
&monitor_x, &monitor_y,
&monitor_height, &monitor_width);
- panel_multiscreen_is_at_visible_extreme (strut->screen,
- strut->monitor,
- &leftmost,
- &rightmost,
- &topmost,
- &bottommost);
+ panel_multiscreen_is_at_visible_extreme (strut->monitor,
+ &leftmost,
+ &rightmost,
+ &topmost,
+ &bottommost);
switch (strut->orientation) {
case PANEL_ORIENTATION_TOP:
diff --git a/gnome-panel/panel-toplevel.c b/gnome-panel/panel-toplevel.c
index dc95cdf..8f8224e 100644
--- a/gnome-panel/panel-toplevel.c
+++ b/gnome-panel/panel-toplevel.c
@@ -46,6 +46,7 @@
#include "panel-struts.h"
#include "panel-lockdown.h"
#include "panel-schemas.h"
+#include "panel-monitor.h"
G_DEFINE_TYPE (PanelToplevel, panel_toplevel, GTK_TYPE_WINDOW)
@@ -414,27 +415,16 @@ panel_toplevel_get_screen_geometry (PanelToplevel *toplevel,
return screen;
}
-static GdkScreen *
+static void
panel_toplevel_get_monitor_geometry (PanelToplevel *toplevel,
- int *x,
- int *y,
- int *width,
- int *height)
+ int *x,
+ int *y,
+ int *width,
+ int *height)
{
- GdkScreen *screen;
+ int monitor_index = toplevel->priv->monitor;
- g_return_val_if_fail (PANEL_IS_TOPLEVEL (toplevel), NULL);
- g_return_val_if_fail (width != NULL && height != NULL, NULL);
-
- screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
-
- if (x) *x = panel_multiscreen_x (screen, toplevel->priv->monitor);
- if (y) *y = panel_multiscreen_y (screen, toplevel->priv->monitor);
-
- if (width) *width = panel_multiscreen_width (screen, toplevel->priv->monitor);
- if (height) *height = panel_multiscreen_height (screen, toplevel->priv->monitor);
-
- return screen;
+ panel_monitor_get_geometry (monitor_index, x, y, height, width);
}
static GdkCursorType
@@ -749,25 +739,26 @@ panel_toplevel_calc_new_orientation (PanelToplevel *toplevel,
int pointer_y)
{
PanelOrientation new_orientation;
- GdkScreen *screen;
+ GdkRectangle geometry;
+
int hborder, vborder;
- int monitor;
int monitor_width, monitor_height;
int new_x, new_y;
- screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
+ GdkMonitor *monitor = gdk_display_get_monitor_at_point(gdk_display_get_default(),
+ pointer_x, pointer_y);
- monitor = panel_multiscreen_get_monitor_at_point (screen, pointer_x, pointer_y);
+ gdk_monitor_get_geometry(monitor, &geometry);
if (toplevel->priv->geometry.height < toplevel->priv->geometry.width)
vborder = hborder = (3 * toplevel->priv->geometry.height) >> 1;
else
vborder = hborder = (3 * toplevel->priv->geometry.width) >> 1;
- new_x = pointer_x - panel_multiscreen_x (screen, monitor);
- new_y = pointer_y - panel_multiscreen_y (screen, monitor);
- monitor_width = panel_multiscreen_width (screen, monitor);
- monitor_height = panel_multiscreen_height (screen, monitor);
+ new_x = pointer_x - geometry.x;
+ new_y = pointer_y - geometry.y;
+ monitor_width = geometry.width;
+ monitor_height = geometry.height;
new_orientation = toplevel->priv->orientation;
@@ -821,7 +812,19 @@ panel_toplevel_calc_new_orientation (PanelToplevel *toplevel,
break;
}
- panel_toplevel_set_monitor (toplevel, monitor);
+ // this is a temporary hack until we can port all panel_toplevel_* functions
+ // to make use of GdkMonitor instead of the monitor index.
+ int monitor_index = 0;
+
+ for (int i=0; i < gdk_display_get_n_monitors (gdk_display_get_default ()); i++)
+ {
+ if (monitor == gdk_display_get_monitor (gdk_display_get_default (), i))
+ {
+ monitor_index = i;
+ }
+ }
+
+ panel_toplevel_set_monitor (toplevel, monitor_index);
panel_toplevel_set_orientation (toplevel, new_orientation);
}
@@ -834,6 +837,7 @@ panel_toplevel_move_to (PanelToplevel *toplevel,
PanelOrientation new_orientation;
gboolean x_centered, y_centered;
int screen_width, screen_height;
+ int new_monitor_x, new_monitor_y;
int monitor_width, monitor_height;
int width, height;
int new_monitor;
@@ -869,16 +873,20 @@ 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 = gdk_screen_get_monitor_at_point (screen, new_x, new_y);
panel_toplevel_get_monitor_geometry (
toplevel, NULL, NULL, &monitor_width, &monitor_height);
+ panel_monitor_get_geometry (new_monitor,
+ &new_monitor_x, &new_monitor_y,
+ NULL, NULL);
+
x_centered = toplevel->priv->x_centered;
y_centered = toplevel->priv->y_centered;
- x = new_x - panel_multiscreen_x (screen, new_monitor);
- y = new_y - panel_multiscreen_y (screen, new_monitor);
+ x = new_x - new_monitor_x;
+ y = new_y - new_monitor_y;
if (toplevel->priv->orientation & PANEL_HORIZONTAL_MASK) {
y_centered = FALSE;
@@ -1442,7 +1450,6 @@ static gboolean
panel_toplevel_update_struts (PanelToplevel *toplevel, gboolean end_of_animation)
{
PanelOrientation orientation;
- GdkScreen *screen;
gboolean geometry_changed = FALSE;
int strut, strut_start, strut_end;
int x, y, width, height;
@@ -1466,17 +1473,17 @@ panel_toplevel_update_struts (PanelToplevel *toplevel, gboolean end_of_animation
panel_toplevel_calculate_animation_end_geometry (toplevel);
}
- screen = panel_toplevel_get_monitor_geometry (toplevel,
- &monitor_x,
- &monitor_y,
- &monitor_width,
- &monitor_height);
+ panel_toplevel_get_monitor_geometry (toplevel,
+ &monitor_x,
+ &monitor_y,
+ &monitor_width,
+ &monitor_height);
if (end_of_animation) {
x = toplevel->priv->animation_end_x;
y = toplevel->priv->animation_end_y;
- x += panel_multiscreen_x (screen, toplevel->priv->monitor);
- y += panel_multiscreen_y (screen, toplevel->priv->monitor);
+ x += monitor_x;
+ y += monitor_y;
if (toplevel->priv->animation_end_width != -1)
width = toplevel->priv->animation_end_width;
else
@@ -1534,7 +1541,7 @@ panel_toplevel_update_struts (PanelToplevel *toplevel, gboolean end_of_animation
if (strut > 0)
geometry_changed = panel_struts_register_strut (toplevel,
- screen,
+ gdk_screen_get_default(),
toplevel->priv->monitor,
orientation,
strut,
@@ -1870,17 +1877,15 @@ get_delta (int src,
static void
panel_toplevel_update_animating_position (PanelToplevel *toplevel)
{
- GdkScreen *screen;
GTimeVal time_val;
int deltax, deltay, deltaw = 0, deltah = 0;
int monitor_offset_x, monitor_offset_y;
g_get_current_time (&time_val);
- screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
-
- monitor_offset_x = panel_multiscreen_x (screen, toplevel->priv->monitor);
- monitor_offset_y = panel_multiscreen_y (screen, toplevel->priv->monitor);
+ panel_toplevel_get_monitor_geometry (toplevel,
+ &monitor_offset_x, &monitor_offset_y,
+ NULL, NULL);
if (toplevel->priv->animation_end_width != -1)
deltaw = get_delta (toplevel->priv->geometry.width,
@@ -1984,12 +1989,12 @@ panel_toplevel_update_expanded_position (PanelToplevel *toplevel)
break;
}
- monitor = panel_multiscreen_get_monitor_at_point (screen, x, y);
+ monitor = gdk_screen_get_monitor_at_point (screen, x, y);
panel_toplevel_set_monitor_internal (toplevel, monitor, TRUE);
- x -= panel_multiscreen_x (screen, monitor);
- y -= panel_multiscreen_y (screen, monitor);
+ x -= monitor_x;
+ y -= monitor_y;
g_object_freeze_notify (G_OBJECT (toplevel));
@@ -2021,11 +2026,12 @@ panel_toplevel_update_position (PanelToplevel *toplevel)
{
int x, y;
int w, h;
+ int monitor_x, monitor_y;
int monitor_width, monitor_height;
- GdkScreen *screen;
- panel_toplevel_get_monitor_geometry (
- toplevel, NULL, NULL, &monitor_width, &monitor_height);
+ panel_toplevel_get_monitor_geometry (toplevel,
+ &monitor_x, &monitor_y,
+ &monitor_width, &monitor_height);
if (toplevel->priv->animating) {
panel_toplevel_update_animating_position (toplevel);
@@ -2109,9 +2115,8 @@ panel_toplevel_update_position (PanelToplevel *toplevel)
if (h != -1)
toplevel->priv->geometry.height = h;
- screen = gtk_window_get_screen (GTK_WINDOW (toplevel));
- x += panel_multiscreen_x (screen, toplevel->priv->monitor);
- y += panel_multiscreen_y (screen, toplevel->priv->monitor);
+ x += monitor_x;
+ y += monitor_y;
toplevel->priv->geometry.x = x;
toplevel->priv->geometry.y = y;
@@ -2940,10 +2945,10 @@ panel_toplevel_calculate_animation_end_geometry (PanelToplevel *toplevel)
static void
panel_toplevel_start_animation (PanelToplevel *toplevel)
{
- GdkScreen *screen;
GtkRequisition requisition;
int deltax, deltay, deltaw = 0, deltah = 0;
int cur_x = -1, cur_y = -1;
+ int monitor_x, monitor_y;
long t;
panel_toplevel_calculate_animation_end_geometry (toplevel);
@@ -2960,10 +2965,12 @@ panel_toplevel_start_animation (PanelToplevel *toplevel)
gdk_window_get_origin (gtk_widget_get_window (GTK_WIDGET (toplevel)), &cur_x, &cur_y);
- screen = gtk_widget_get_screen (GTK_WIDGET (toplevel));
+ panel_toplevel_get_monitor_geometry (toplevel,
+ &monitor_x, &monitor_y,
+ NULL, NULL);
- cur_x -= panel_multiscreen_x (screen, toplevel->priv->monitor);
- cur_y -= panel_multiscreen_y (screen, toplevel->priv->monitor);
+ cur_x -= monitor_x;
+ cur_y -= monitor_y;
deltax = toplevel->priv->animation_end_x - cur_x;
deltay = toplevel->priv->animation_end_y - cur_y;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]