[mutter/wip/display-no-wayland: 1/24] Rework and consolidate monitor handling in MetaScreen
- From: Giovanni Campagna <gcampagna src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [mutter/wip/display-no-wayland: 1/24] Rework and consolidate monitor handling in MetaScreen
- Date: Thu, 8 Aug 2013 13:13:33 +0000 (UTC)
commit 5adbe16263abf975021e02d8da3f9af3c3997980
Author: Giovanni Campagna <gcampagn redhat com>
Date: Thu Jul 18 13:09:16 2013 +0200
Rework and consolidate monitor handling in MetaScreen
Consolidate all places that deal with output configuration in
MetaScreen, which gets it either from XRandR or from a dummy static configuration.
We still need to read the Xinerama config, even when running xwayland,
because we need the indices for _NET_WM_FULLSCREEN_MONITORS, but
now we do it only when needed.
https://bugzilla.gnome.org/show_bug.cgi?id=705670
src/core/screen-private.h | 34 ++++-
src/core/screen.c | 368 ++++++++++++++++++++++-----------------------
src/core/window-private.h | 2 +-
src/core/window.c | 27 +++-
4 files changed, 231 insertions(+), 200 deletions(-)
---
diff --git a/src/core/screen-private.h b/src/core/screen-private.h
index 83adb83..dfefaa2 100644
--- a/src/core/screen-private.h
+++ b/src/core/screen-private.h
@@ -39,15 +39,32 @@
#include "stack-tracker.h"
#include "ui.h"
+#include <cogl/cogl.h>
+
+typedef struct _MetaOutput MetaOutput;
typedef struct _MetaMonitorInfo MetaMonitorInfo;
+struct _MetaOutput
+{
+ MetaMonitorInfo *monitor;
+ char *name;
+ int width_mm;
+ int height_mm;
+ CoglSubpixelOrder subpixel_order;
+};
+
struct _MetaMonitorInfo
{
int number;
+ int xinerama_index;
MetaRectangle rect;
gboolean is_primary;
gboolean in_fullscreen;
- XID output; /* The primary or first output for this crtc, None if no xrandr */
+ float refresh_rate;
+
+ /* The primary or first output for this crtc, 0 if we can't figure out.
+ This is a XID when using XRandR, otherwise a KMS id (not implemented) */
+ glong output_id;
};
typedef void (* MetaScreenWindowFunc) (MetaScreen *screen, MetaWindow *window,
@@ -100,10 +117,18 @@ struct _MetaScreen
Window wm_sn_selection_window;
Atom wm_sn_atom;
guint32 wm_sn_timestamp;
-
+
+ /* Outputs refers to physical screens,
+ while monitor_infos refer to logical ones (aka CRTC)
+ They can be different if two outputs are
+ in clone mode
+ */
+ MetaOutput *outputs;
MetaMonitorInfo *monitor_infos;
int primary_monitor_index;
+ int n_outputs;
int n_monitor_infos;
+ gboolean has_xinerama_indices;
/* Cache the current monitor */
int last_monitor_index;
@@ -257,4 +282,9 @@ void meta_screen_workspace_switched (MetaScreen *screen,
void meta_screen_set_active_workspace_hint (MetaScreen *screen);
+int meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen,
+ int index);
+int meta_screen_monitor_index_to_xinerama_index (MetaScreen *screen,
+ int index);
+
#endif
diff --git a/src/core/screen.c b/src/core/screen.c
index 6db3ea3..94b2f19 100644
--- a/src/core/screen.c
+++ b/src/core/screen.c
@@ -350,250 +350,238 @@ set_wm_icon_size_hint (MetaScreen *screen)
#undef N_VALS
}
-/* The list of monitors reported by the windowing system might include
- * mirrored monitors with identical bounds. Since mirrored monitors
- * shouldn't be treated as separate monitors for most purposes, we
- * filter them out here. (We ignore the possibility of partially
- * overlapping monitors because they are rare and it's hard to come
- * up with any sensible interpretation.)
- */
+static gboolean
+has_dummy_output (void)
+{
+ return FALSE;
+}
+
+static void
+make_dummy_monitor_config (MetaScreen *screen)
+{
+ screen->outputs = g_new0 (MetaOutput, 1);
+ screen->n_outputs = 1;
+
+ screen->outputs[0].name = g_strdup ("LVDS");
+ screen->outputs[0].width_mm = 222;
+ screen->outputs[0].height_mm = 125;
+ screen->outputs[0].subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
+
+ screen->monitor_infos = g_new0 (MetaMonitorInfo, 1);
+ screen->n_monitor_infos = 1;
+
+ screen->monitor_infos[0].number = 0;
+ screen->monitor_infos[0].xinerama_index = 0;
+ screen->monitor_infos[0].rect.x = 0;
+ screen->monitor_infos[0].rect.y = 0;
+ screen->monitor_infos[0].rect.width = screen->rect.width;
+ screen->monitor_infos[0].rect.height = screen->rect.height;
+ screen->monitor_infos[0].refresh_rate = 60.0f;
+ screen->monitor_infos[0].is_primary = TRUE;
+ screen->monitor_infos[0].in_fullscreen = -1;
+ screen->monitor_infos[0].output_id = 1;
+
+ screen->has_xinerama_indices = TRUE;
+}
+
static void
-filter_mirrored_monitors (MetaScreen *screen)
+meta_screen_ensure_xinerama_indices (MetaScreen *screen)
{
- int i, j;
+ XineramaScreenInfo *infos;
+ int n_infos, i, j;
+
+ if (screen->has_xinerama_indices)
+ return;
- /* Currently always true and simplifies things */
- g_assert (screen->primary_monitor_index == 0);
+ screen->has_xinerama_indices = TRUE;
- for (i = 1; i < screen->n_monitor_infos; i++)
+ if (!XineramaIsActive (screen->display->xdisplay))
+ return;
+
+ infos = XineramaQueryScreens (screen->display->xdisplay, &n_infos);
+ if (n_infos <= 0 || infos == NULL)
{
- /* In case we've filtered previous monitors */
- screen->monitor_infos[i].number = i;
+ meta_XFree (infos);
+ return;
+ }
- for (j = 0; j < i; j++)
+ for (i = 0; i < screen->n_monitor_infos; ++i)
+ {
+ for (j = 0; j < n_infos; ++j)
{
- if (meta_rectangle_equal (&screen->monitor_infos[i].rect,
- &screen->monitor_infos[j].rect))
- {
- memmove (&screen->monitor_infos[i],
- &screen->monitor_infos[i + 1],
- (screen->n_monitor_infos - i - 1) * sizeof (MetaMonitorInfo));
- screen->n_monitor_infos--;
- i--;
-
- continue;
- }
+ if (screen->monitor_infos[i].rect.x == infos[j].x_org &&
+ screen->monitor_infos[i].rect.y == infos[j].y_org &&
+ screen->monitor_infos[i].rect.width == infos[j].width &&
+ screen->monitor_infos[i].rect.height == infos[j].height)
+ screen->monitor_infos[i].xinerama_index = j;
}
}
+
+ meta_XFree (infos);
}
-#ifdef HAVE_RANDR
-static MetaMonitorInfo *
-find_monitor_with_rect (MetaScreen *screen, int x, int y, int w, int h)
+int
+meta_screen_monitor_index_to_xinerama_index (MetaScreen *screen,
+ int index)
+{
+ meta_screen_ensure_xinerama_indices (screen);
+
+ return screen->monitor_infos[index].xinerama_index;
+}
+
+int
+meta_screen_xinerama_index_to_monitor_index (MetaScreen *screen,
+ int index)
{
- MetaMonitorInfo *info;
int i;
+ meta_screen_ensure_xinerama_indices (screen);
+
for (i = 0; i < screen->n_monitor_infos; i++)
- {
- info = &screen->monitor_infos[i];
- if (x == info->rect.x &&
- y == info->rect.y &&
- w == info->rect.width &&
- h == info->rect.height)
- return info;
- }
- return NULL;
+ if (screen->monitor_infos[i].xinerama_index == index)
+ return i;
+
+ return -1;
}
+#ifdef HAVE_RANDR
+
/* In the case of multiple outputs of a single crtc (mirroring), we consider one of the
* outputs the "main". This is the one we consider "owning" the windows, so if
* the mirroring is changed to a dual monitor setup then the windows are moved to the
* crtc that now has that main output. If one of the outputs is the primary that is
* always the main, otherwise we just use the first.
*/
-static XID
-find_main_output_for_crtc (MetaScreen *screen, XRRScreenResources *resources, XRRCrtcInfo *crtc)
+static void
+find_main_output_for_crtc (MetaScreen *screen,
+ XRRScreenResources *resources,
+ XRRCrtcInfo *crtc,
+ MetaMonitorInfo *info,
+ GArray *outputs)
{
XRROutputInfo *output;
RROutput primary_output;
int i;
- XID res;
primary_output = XRRGetOutputPrimary (screen->display->xdisplay, screen->xroot);
- res = None;
for (i = 0; i < crtc->noutput; i++)
{
output = XRRGetOutputInfo (screen->display->xdisplay, resources, crtc->outputs[i]);
- if (output->connection != RR_Disconnected &&
- (res == None || crtc->outputs[i] == primary_output))
- res = crtc->outputs[i];
+
+ if (output->connection != RR_Disconnected)
+ {
+ MetaOutput meta_output;
+
+ meta_output.name = g_strdup (output->name);
+ meta_output.width_mm = output->mm_width;
+ meta_output.height_mm = output->mm_height;
+ meta_output.subpixel_order = COGL_SUBPIXEL_ORDER_UNKNOWN;
+
+ g_array_append_val (outputs, meta_output);
+
+ if (crtc->outputs[i] == primary_output)
+ {
+ info->output_id = crtc->outputs[i];
+ info->is_primary = TRUE;
+ screen->primary_monitor_index = info->number;
+ }
+ else if (info->output_id == 0)
+ {
+ info->output_id = crtc->outputs[i];
+ }
+ }
+
XRRFreeOutputInfo (output);
}
-
- return res;
}
-#endif
-
static void
-reload_monitor_infos (MetaScreen *screen)
+read_monitor_infos_from_xrandr (MetaScreen *screen)
{
- MetaDisplay *display;
+ XRRScreenResources *resources;
+ GArray *outputs;
+ int i, j;
- {
- GList *tmp;
+ resources = XRRGetScreenResourcesCurrent (screen->display->xdisplay, screen->xroot);
+ if (!resources)
+ return make_dummy_monitor_config (screen);
- tmp = screen->workspaces;
- while (tmp != NULL)
- {
- MetaWorkspace *space = tmp->data;
+ outputs = g_array_new (FALSE, TRUE, sizeof (MetaOutput));
- meta_workspace_invalidate_work_area (space);
-
- tmp = tmp->next;
- }
- }
+ screen->n_outputs = 0;
+ screen->n_monitor_infos = resources->ncrtc;
- display = screen->display;
+ screen->monitor_infos = g_new0 (MetaMonitorInfo, screen->n_monitor_infos);
- /* Any previous screen->monitor_infos is freed by the caller */
-
- screen->monitor_infos = NULL;
- screen->n_monitor_infos = 0;
- screen->last_monitor_index = 0;
+ for (i = 0; i < resources->ncrtc; i++)
+ {
+ XRRCrtcInfo *crtc;
+ MetaMonitorInfo *info;
- /* Xinerama doesn't have a concept of primary monitor, however XRandR
- * does. However, the XRandR xinerama compat code always sorts the
- * primary output first, so we rely on that here. We could use the
- * native XRandR calls instead of xinerama, but that would be
- * slightly problematic for _NET_WM_FULLSCREEN_MONITORS support, as
- * that is defined in terms of xinerama monitor indexes.
- * So, since we don't need anything in xrandr except the primary
- * we can keep using xinerama and use the first monitor as the
- * primary.
- */
- screen->primary_monitor_index = 0;
+ crtc = XRRGetCrtcInfo (screen->display->xdisplay, resources, resources->crtcs[i]);
- screen->display->monitor_cache_invalidated = TRUE;
+ info = &screen->monitor_infos[i];
- if (g_getenv ("MUTTER_DEBUG_XINERAMA"))
- {
- meta_topic (META_DEBUG_XINERAMA,
- "Pretending a single monitor has two Xinerama screens\n");
+ info->number = i;
+ info->rect.x = crtc->x;
+ info->rect.y = crtc->y;
+ info->rect.width = crtc->width;
+ info->rect.height = crtc->height;
+ info->in_fullscreen = -1;
- screen->monitor_infos = g_new0 (MetaMonitorInfo, 2);
- screen->n_monitor_infos = 2;
+ for (j = 0; j < resources->nmode; j++)
+ {
+ if (resources->modes[j].id == crtc->mode)
+ info->refresh_rate = (resources->modes[j].dotClock /
+ ((float)resources->modes[j].hTotal *
+ resources->modes[j].vTotal));
+ }
- screen->monitor_infos[0].number = 0;
- screen->monitor_infos[0].rect = screen->rect;
- screen->monitor_infos[0].rect.width = screen->rect.width / 2;
- screen->monitor_infos[0].in_fullscreen = -1;
+ find_main_output_for_crtc (screen, resources, crtc, info, outputs);
- screen->monitor_infos[1].number = 1;
- screen->monitor_infos[1].rect = screen->rect;
- screen->monitor_infos[1].rect.x = screen->rect.width / 2;
- screen->monitor_infos[1].rect.width = screen->rect.width / 2;
- screen->monitor_infos[0].in_fullscreen = -1;
- }
+ XRRFreeCrtcInfo (crtc);
+ }
- if (screen->n_monitor_infos == 0 &&
- XineramaIsActive (display->xdisplay))
- {
- XineramaScreenInfo *infos;
- int n_infos;
- int i;
-
- n_infos = 0;
- infos = XineramaQueryScreens (display->xdisplay, &n_infos);
+ screen->n_outputs = outputs->len;
+ screen->outputs = (void*)g_array_free (outputs, FALSE);
- meta_topic (META_DEBUG_XINERAMA,
- "Found %d Xinerama screens on display %s\n",
- n_infos, display->name);
+ XRRFreeScreenResources (resources);
+}
- if (n_infos > 0)
- {
- screen->monitor_infos = g_new0 (MetaMonitorInfo, n_infos);
- screen->n_monitor_infos = n_infos;
-
- i = 0;
- while (i < n_infos)
- {
- screen->monitor_infos[i].number = infos[i].screen_number;
- screen->monitor_infos[i].rect.x = infos[i].x_org;
- screen->monitor_infos[i].rect.y = infos[i].y_org;
- screen->monitor_infos[i].rect.width = infos[i].width;
- screen->monitor_infos[i].rect.height = infos[i].height;
- screen->monitor_infos[i].in_fullscreen = -1;
-
- meta_topic (META_DEBUG_XINERAMA,
- "Monitor %d is %d,%d %d x %d\n",
- screen->monitor_infos[i].number,
- screen->monitor_infos[i].rect.x,
- screen->monitor_infos[i].rect.y,
- screen->monitor_infos[i].rect.width,
- screen->monitor_infos[i].rect.height);
-
- ++i;
- }
- }
-
- meta_XFree (infos);
+#endif
-#ifdef HAVE_RANDR
- {
- XRRScreenResources *resources;
+static void
+reload_monitor_infos (MetaScreen *screen)
+{
+ GList *tmp;
- resources = XRRGetScreenResourcesCurrent (display->xdisplay, screen->xroot);
- if (resources)
- {
- for (i = 0; i < resources->ncrtc; i++)
- {
- XRRCrtcInfo *crtc;
- MetaMonitorInfo *info;
-
- crtc = XRRGetCrtcInfo (display->xdisplay, resources, resources->crtcs[i]);
- info = find_monitor_with_rect (screen, crtc->x, crtc->y, (int)crtc->width,
(int)crtc->height);
- if (info)
- info->output = find_main_output_for_crtc (screen, resources, crtc);
-
- XRRFreeCrtcInfo (crtc);
- }
- XRRFreeScreenResources (resources);
- }
- }
-#endif
- }
- else if (screen->n_monitor_infos > 0)
+ tmp = screen->workspaces;
+ while (tmp != NULL)
{
- meta_topic (META_DEBUG_XINERAMA,
- "No Xinerama extension or Xinerama inactive on display %s\n",
- display->name);
- }
+ MetaWorkspace *space = tmp->data;
- /* If no Xinerama, fill in the single screen info so
- * we can use the field unconditionally
- */
- if (screen->n_monitor_infos == 0)
- {
- meta_topic (META_DEBUG_XINERAMA,
- "No Xinerama screens, using default screen info\n");
-
- screen->monitor_infos = g_new0 (MetaMonitorInfo, 1);
- screen->n_monitor_infos = 1;
-
- screen->monitor_infos[0].number = 0;
- screen->monitor_infos[0].rect = screen->rect;
- screen->monitor_infos[0].in_fullscreen = -1;
+ meta_workspace_invalidate_work_area (space);
+
+ tmp = tmp->next;
}
- filter_mirrored_monitors (screen);
+ /* Any previous screen->monitor_infos or screen->outputs is freed by the caller */
+
+ screen->outputs = NULL;
+ screen->n_outputs = 0;
+ screen->monitor_infos = NULL;
+ screen->n_monitor_infos = 0;
+ screen->last_monitor_index = 0;
+ screen->has_xinerama_indices = FALSE;
+ screen->display->monitor_cache_invalidated = TRUE;
- screen->monitor_infos[screen->primary_monitor_index].is_primary = TRUE;
+ if (has_dummy_output ())
+ return make_dummy_monitor_config (screen);
- g_assert (screen->n_monitor_infos > 0);
- g_assert (screen->monitor_infos != NULL);
+#ifdef HAVE_RANDR
+ return read_monitor_infos_from_xrandr (screen);
+#endif
}
/* The guard window allows us to leave minimized windows mapped so
@@ -852,10 +840,6 @@ meta_screen_new (MetaDisplay *display,
screen->compositor_data = NULL;
screen->guard_window = None;
- screen->monitor_infos = NULL;
- screen->n_monitor_infos = 0;
- screen->last_monitor_index = 0;
-
reload_monitor_infos (screen);
meta_screen_set_cursor (screen, META_CURSOR_DEFAULT);
@@ -941,7 +925,7 @@ meta_screen_new (MetaDisplay *display,
meta_verbose ("Added screen %d ('%s') root 0x%lx\n",
screen->number, screen->screen_name, screen->xroot);
-
+
return screen;
}
@@ -3003,12 +2987,16 @@ meta_screen_resize (MetaScreen *screen,
int height)
{
GSList *windows, *tmp;
+ MetaOutput *old_outputs;
MetaMonitorInfo *old_monitor_infos;
+ int n_old_outputs, i;
screen->rect.width = width;
screen->rect.height = height;
/* Save the old monitor infos, so they stay valid during the update */
+ old_outputs = screen->outputs;
+ n_old_outputs = screen->n_outputs;
old_monitor_infos = screen->monitor_infos;
reload_monitor_infos (screen);
@@ -3054,6 +3042,10 @@ meta_screen_resize (MetaScreen *screen,
meta_screen_queue_check_fullscreen (screen);
g_signal_emit (screen, screen_signals[MONITORS_CHANGED], 0);
+
+ for (i = 0; i < n_old_outputs; i++)
+ g_free (old_outputs[i].name);
+ g_free (old_outputs);
}
void
diff --git a/src/core/window-private.h b/src/core/window-private.h
index ec94cca..657a6eb 100644
--- a/src/core/window-private.h
+++ b/src/core/window-private.h
@@ -165,7 +165,7 @@ struct _MetaWindow
* been overridden (via a client message), the window will cover the union of
* these monitors. If not, this is the single monitor which the window's
* origin is on. */
- long fullscreen_monitors[4];
+ gint fullscreen_monitors[4];
/* Whether we're trying to constrain the window to be fully onscreen */
guint require_fully_onscreen : 1;
diff --git a/src/core/window.c b/src/core/window.c
index 9252ab2..1373aaa 100644
--- a/src/core/window.c
+++ b/src/core/window.c
@@ -2108,10 +2108,14 @@ set_net_wm_state (MetaWindow *window)
if (window->fullscreen)
{
- data[0] = window->fullscreen_monitors[0];
- data[1] = window->fullscreen_monitors[1];
- data[2] = window->fullscreen_monitors[2];
- data[3] = window->fullscreen_monitors[3];
+ data[0] = meta_screen_monitor_index_to_xinerama_index (window->screen,
+ window->fullscreen_monitors[0]);
+ data[1] = meta_screen_monitor_index_to_xinerama_index (window->screen,
+ window->fullscreen_monitors[1]);
+ data[2] = meta_screen_monitor_index_to_xinerama_index (window->screen,
+ window->fullscreen_monitors[2]);
+ data[3] = meta_screen_monitor_index_to_xinerama_index (window->screen,
+ window->fullscreen_monitors[3]);
meta_verbose ("Setting _NET_WM_FULLSCREEN_MONITORS\n");
meta_error_trap_push (window->display);
@@ -4785,7 +4789,8 @@ meta_window_update_for_monitors_changed (MetaWindow *window)
{
MetaMonitorInfo *info = &window->screen->monitor_infos[i];
- if (info->output == old->output)
+ if (info->output_id != 0 &&
+ info->output_id == old->output_id)
{
new = info;
break;
@@ -7119,10 +7124,14 @@ meta_window_client_message (MetaWindow *window,
meta_verbose ("_NET_WM_FULLSCREEN_MONITORS request for window '%s'\n",
window->desc);
- top = event->xclient.data.l[0];
- bottom = event->xclient.data.l[1];
- left = event->xclient.data.l[2];
- right = event->xclient.data.l[3];
+ top = meta_screen_xinerama_index_to_monitor_index (window->screen,
+ event->xclient.data.l[0]);
+ bottom = meta_screen_xinerama_index_to_monitor_index (window->screen,
+ event->xclient.data.l[1]);
+ left = meta_screen_xinerama_index_to_monitor_index (window->screen,
+ event->xclient.data.l[2]);
+ right = meta_screen_xinerama_index_to_monitor_index (window->screen,
+ event->xclient.data.l[3]);
/* source_indication = event->xclient.data.l[4]; */
meta_window_update_fullscreen_monitors (window, top, bottom, left, right);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]