[mutter] xrandr: Rewrite to be based on the X11 display connection



commit 6c743dad8867eb4fafb664a783d26ec875e72957
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Wed Apr 23 09:57:16 2014 -0400

    xrandr: Rewrite to be based on the X11 display connection

 src/backends/meta-backend.c                    |   11 +----
 src/backends/x11/meta-backend-x11.c            |    9 +++
 src/backends/x11/meta-backend-x11.h            |    3 +-
 src/backends/x11/meta-monitor-manager-xrandr.c |   63 +++++++++---------------
 src/meta/atomnames.h                           |    3 -
 5 files changed, 34 insertions(+), 55 deletions(-)
---
diff --git a/src/backends/meta-backend.c b/src/backends/meta-backend.c
index e6aaa13..20a830b 100644
--- a/src/backends/meta-backend.c
+++ b/src/backends/meta-backend.c
@@ -50,15 +50,6 @@ typedef struct _MetaBackendPrivate MetaBackendPrivate;
 G_DEFINE_ABSTRACT_TYPE_WITH_PRIVATE (MetaBackend, meta_backend, G_TYPE_OBJECT);
 
 static void
-meta_backend_constructed (GObject *object)
-{
-  MetaBackend *backend = META_BACKEND (object);
-  MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
-
-  priv->monitor_manager = META_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend);
-}
-
-static void
 meta_backend_finalize (GObject *object)
 {
   MetaBackend *backend = META_BACKEND (object);
@@ -88,6 +79,7 @@ meta_backend_real_post_init (MetaBackend *backend)
   MetaBackendPrivate *priv = meta_backend_get_instance_private (backend);
 
   priv->cursor_renderer = meta_backend_create_cursor_renderer (backend);
+  priv->monitor_manager = META_BACKEND_GET_CLASS (backend)->create_monitor_manager (backend);
 }
 
 static MetaCursorRenderer *
@@ -101,7 +93,6 @@ meta_backend_class_init (MetaBackendClass *klass)
 {
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
-  object_class->constructed = meta_backend_constructed;
   object_class->finalize = meta_backend_finalize;
 
   klass->post_init = meta_backend_real_post_init;
diff --git a/src/backends/x11/meta-backend-x11.c b/src/backends/x11/meta-backend-x11.c
index a2cf9b2..cda2caf 100644
--- a/src/backends/x11/meta-backend-x11.c
+++ b/src/backends/x11/meta-backend-x11.c
@@ -205,3 +205,12 @@ meta_backend_x11_init (MetaBackendX11 *x11)
   /* We do X11 event retrieval ourselves */
   clutter_x11_disable_event_retrieval ();
 }
+
+Display *
+meta_backend_x11_get_xdisplay (MetaBackendX11 *x11)
+{
+  MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
+
+  return priv->xdisplay;
+}
+
diff --git a/src/backends/x11/meta-backend-x11.h b/src/backends/x11/meta-backend-x11.h
index f670bde..204654e 100644
--- a/src/backends/x11/meta-backend-x11.h
+++ b/src/backends/x11/meta-backend-x11.h
@@ -51,7 +51,6 @@ struct _MetaBackendX11Class
 
 GType meta_backend_x11_get_type (void) G_GNUC_CONST;
 
-void meta_backend_x11_handle_alarm_notify (MetaBackend *backend,
-                                           XEvent      *event);
+Display * meta_backend_x11_get_xdisplay (MetaBackendX11 *backend);
 
 #endif /* META_BACKEND_X11_H */
diff --git a/src/backends/x11/meta-monitor-manager-xrandr.c b/src/backends/x11/meta-monitor-manager-xrandr.c
index 5fbddd4..8044c6d 100644
--- a/src/backends/x11/meta-monitor-manager-xrandr.c
+++ b/src/backends/x11/meta-monitor-manager-xrandr.c
@@ -36,6 +36,7 @@
 #include <X11/extensions/Xrandr.h>
 #include <X11/extensions/dpms.h>
 
+#include "meta-backend-x11.h"
 #include <meta/main.h>
 #include <meta/errors.h>
 #include "edid.h"
@@ -141,16 +142,16 @@ static gboolean
 output_get_presentation_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
                                 MetaOutput               *output)
 {
-  MetaDisplay *display = meta_get_display ();
   gboolean value;
-  Atom actual_type;
+  Atom atom, actual_type;
   int actual_format;
   unsigned long nitems, bytes_after;
   unsigned char *buffer;
 
+  atom = XInternAtom (manager_xrandr->xdisplay, "_MUTTER_PRESENTATION_OUTPUT", False);
   XRRGetOutputProperty (manager_xrandr->xdisplay,
                         (XID)output->output_id,
-                        display->atom__MUTTER_PRESENTATION_OUTPUT,
+                        atom,
                         0, G_MAXLONG, False, False, XA_CARDINAL,
                         &actual_type, &actual_format,
                         &nitems, &bytes_after, &buffer);
@@ -177,16 +178,16 @@ static int
 output_get_backlight_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
                              MetaOutput               *output)
 {
-  MetaDisplay *display = meta_get_display ();
   gboolean value;
-  Atom actual_type;
+  Atom atom, actual_type;
   int actual_format;
   unsigned long nitems, bytes_after;
   unsigned char *buffer;
 
+  atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
   XRRGetOutputProperty (manager_xrandr->xdisplay,
                         (XID)output->output_id,
-                        display->atom_Backlight,
+                        atom,
                         0, G_MAXLONG, False, False, XA_INTEGER,
                         &actual_type, &actual_format,
                         &nitems, &bytes_after, &buffer);
@@ -205,14 +206,13 @@ static void
 output_get_backlight_limits_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
                                     MetaOutput               *output)
 {
-  MetaDisplay *display = meta_get_display ();
+  Atom atom;
   XRRPropertyInfo *info;
 
-  meta_error_trap_push (display);
+  atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
   info = XRRQueryOutputProperty (manager_xrandr->xdisplay,
                                  (XID)output->output_id,
-                                 display->atom_Backlight);
-  meta_error_trap_pop (display);
+                                 atom);
 
   if (info == NULL)
     {
@@ -314,14 +314,13 @@ static gboolean
 output_get_hotplug_mode_update (MetaMonitorManagerXrandr *manager_xrandr,
                                 XID                       output_id)
 {
-  MetaDisplay *display = meta_get_display ();
+  Atom atom;
   XRRPropertyInfo *info;
   gboolean result = FALSE;
 
-  meta_error_trap_push (display);
+  atom = XInternAtom (manager_xrandr->xdisplay, "hotplug_mode_update", False);
   info = XRRQueryOutputProperty (manager_xrandr->xdisplay, output_id,
-                                 display->atom_hotplug_mode_update);
-  meta_error_trap_pop (display);
+                                 atom);
 
   if (info)
     {
@@ -350,9 +349,7 @@ meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager)
     XRRFreeScreenResources (manager_xrandr->resources);
   manager_xrandr->resources = NULL;
 
-  meta_error_trap_push (meta_get_display ());
   dpms_capable = DPMSCapable (manager_xrandr->xdisplay);
-  meta_error_trap_pop (meta_get_display ());
 
   if (dpms_capable &&
       DPMSInfo (manager_xrandr->xdisplay, &dpms_state, &dpms_enabled) &&
@@ -452,10 +449,8 @@ meta_monitor_manager_xrandr_read_current (MetaMonitorManager *manager)
       XRRFreeCrtcInfo (crtc);
     }
 
-  meta_error_trap_push (meta_get_display ());
   primary_output = XRRGetOutputPrimary (manager_xrandr->xdisplay,
                                        DefaultRootWindow (manager_xrandr->xdisplay));
-  meta_error_trap_pop (meta_get_display ());
 
   n_actual_outputs = 0;
   for (i = 0; i < (unsigned)resources->noutput; i++)
@@ -637,10 +632,8 @@ meta_monitor_manager_xrandr_set_power_save_mode (MetaMonitorManager *manager,
     return;
   }
 
-  meta_error_trap_push (meta_get_display ());
   DPMSForceLevel (manager_xrandr->xdisplay, state);
   DPMSSetTimeouts (manager_xrandr->xdisplay, 0, 0, 0);
-  meta_error_trap_pop (meta_get_display ());
 }
 
 static Rotation
@@ -674,16 +667,15 @@ output_set_presentation_xrandr (MetaMonitorManagerXrandr *manager_xrandr,
                                 MetaOutput               *output,
                                 gboolean                  presentation)
 {
-  MetaDisplay *display = meta_get_display ();
+  Atom atom;
   int value = presentation;
 
-  meta_error_trap_push (display);
+  atom = XInternAtom (manager_xrandr->xdisplay, "_MUTTER_PRESENTATION_OUTPUT", False);
   XRRChangeOutputProperty (manager_xrandr->xdisplay,
                            (XID)output->output_id,
-                           display->atom__MUTTER_PRESENTATION_OUTPUT,
+                           atom,
                            XA_CARDINAL, 32, PropModeReplace,
                            (unsigned char*) &value, 1);
-  meta_error_trap_pop (display);
 }
 
 static void
@@ -694,11 +686,10 @@ meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager,
                                                 unsigned int         n_outputs)
 {
   MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
-  MetaDisplay *display = meta_get_display ();
   unsigned i;
   int width, height, width_mm, height_mm;
 
-  meta_display_grab (display);
+  XGrabServer (manager_xrandr->xdisplay);
 
   /* First compute the new size of the screen (framebuffer) */
   width = 0; height = 0;
@@ -792,10 +783,8 @@ meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager,
    */
   width_mm = (width / DPI_FALLBACK) * 25.4 + 0.5;
   height_mm = (height / DPI_FALLBACK) * 25.4 + 0.5;
-  meta_error_trap_push (display);
   XRRSetScreenSize (manager_xrandr->xdisplay, DefaultRootWindow (manager_xrandr->xdisplay),
                     width, height, width_mm, height_mm);
-  meta_error_trap_pop (display);
 
   for (i = 0; i < n_crtcs; i++)
     {
@@ -852,7 +841,6 @@ meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager,
               goto next;
             }
 
-          meta_error_trap_push (display);
           ok = XRRSetCrtcConfig (manager_xrandr->xdisplay,
                                  manager_xrandr->resources,
                                  (XID)crtc->crtc_id,
@@ -861,7 +849,6 @@ meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager,
                                  (XID)mode->mode_id,
                                  wl_transform_to_xrandr (crtc_info->transform),
                                  outputs, n_outputs);
-          meta_error_trap_pop (display);
 
           if (ok != Success)
             {
@@ -902,11 +889,9 @@ meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager,
 
       if (output_info->is_primary)
         {
-          meta_error_trap_push (display);
           XRRSetOutputPrimary (manager_xrandr->xdisplay,
                                DefaultRootWindow (manager_xrandr->xdisplay),
                                (XID)output_info->output->output_id);
-          meta_error_trap_pop (display);
         }
 
       output_set_presentation_xrandr (manager_xrandr,
@@ -932,7 +917,7 @@ meta_monitor_manager_xrandr_apply_configuration (MetaMonitorManager *manager,
       output->is_primary = FALSE;
     }
 
-  meta_display_ungrab (display);
+  XUngrabServer (manager_xrandr->xdisplay);
 }
 
 static void
@@ -941,18 +926,17 @@ meta_monitor_manager_xrandr_change_backlight (MetaMonitorManager *manager,
                                              gint                value)
 {
   MetaMonitorManagerXrandr *manager_xrandr = META_MONITOR_MANAGER_XRANDR (manager);
-  MetaDisplay *display = meta_get_display ();
+  Atom atom;
   int hw_value;
 
   hw_value = round ((double)value / 100.0 * output->backlight_max + output->backlight_min);
 
-  meta_error_trap_push (display);
+  atom = XInternAtom (manager_xrandr->xdisplay, "Backlight", False);
   XRRChangeOutputProperty (manager_xrandr->xdisplay,
                            (XID)output->output_id,
-                           display->atom_Backlight,
+                           atom,
                            XA_INTEGER, 32, PropModeReplace,
                            (unsigned char *) &hw_value, 1);
-  meta_error_trap_pop (display);
 
   /* We're not selecting for property notifies, so update the value immediately */
   output->backlight = normalize_backlight (output, hw_value);
@@ -1079,9 +1063,9 @@ meta_monitor_manager_xrandr_handle_xevent (MetaMonitorManager *manager,
 static void
 meta_monitor_manager_xrandr_init (MetaMonitorManagerXrandr *manager_xrandr)
 {
-  MetaDisplay *display = meta_get_display ();
+  MetaBackendX11 *backend = META_BACKEND_X11 (meta_get_backend ());
 
-  manager_xrandr->xdisplay = display->xdisplay;
+  manager_xrandr->xdisplay = meta_backend_x11_get_xdisplay (backend);
 
   if (!XRRQueryExtension (manager_xrandr->xdisplay,
                          &manager_xrandr->rr_event_base,
@@ -1130,4 +1114,3 @@ meta_monitor_manager_xrandr_class_init (MetaMonitorManagerXrandrClass *klass)
   manager_class->set_crtc_gamma = meta_monitor_manager_xrandr_set_crtc_gamma;
   manager_class->handle_xevent = meta_monitor_manager_xrandr_handle_xevent;
 }
-
diff --git a/src/meta/atomnames.h b/src/meta/atomnames.h
index 24b6304..29b8be9 100644
--- a/src/meta/atomnames.h
+++ b/src/meta/atomnames.h
@@ -70,7 +70,6 @@ item(_MUTTER_TIMESTAMP_PING)
 item(_MUTTER_FOCUS_SET)
 item(_MUTTER_SENTINEL)
 item(_MUTTER_VERSION)
-item(_MUTTER_PRESENTATION_OUTPUT)
 item(WM_CLIENT_MACHINE)
 item(MANAGER)
 item(TARGETS)
@@ -78,9 +77,7 @@ item(MULTIPLE)
 item(TIMESTAMP)
 item(VERSION)
 item(ATOM_PAIR)
-item(Backlight)
 item(_XKB_RULES_NAMES)
-item(hotplug_mode_update)
 item(WL_SURFACE_ID)
 
 /* Oddities: These are used, and we need atoms for them,


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