emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] /srv/bzr/emacs/trunk r112733: Factor out common code for m


From: Jan D.
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r112733: Factor out common code for multimonitors, for Gtk+, non-Gtk+ X11 and NS.
Date: Sat, 25 May 2013 13:14:38 +0200
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 112733
committer: Jan D. <address@hidden>
branch nick: trunk
timestamp: Sat 2013-05-25 13:14:38 +0200
message:
  Factor out common code for multimonitors, for Gtk+, non-Gtk+ X11 and NS.
  
  * frame.c (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): New
  Lisp_Object:s.
  (free_monitors, make_monitor_attribute_list): New functions.
  (syms_of_frame): DEFSYM Qgeometry, Qworkarea, Qmm_size, Qframes,
  Qsource.
  
  * frame.h (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): Declare.
  (struct MonitorInfo): New struct.
  (free_monitors, make_monitor_attribute_list): Declare.
  
  * nsfns.m (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): Remove.
  (struct MonitorInfo, free_monitors): Remove.
  (ns_screen_name): Make static.
  (ns_make_monitor_attribute_list): Call make_monitor_attribute_list.
  (syms_of_nsfns): Remove DEFSYM for Qgeometry, Qworkarea, Qmm_size,
  Qframes, Qsource.
  
  * xfns.c (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): Remove.
  (struct MonitorInfo, free_monitors): Remove.
  (x_make_monitor_attribute_list): Call make_monitor_attribute_list.
  (Fx_display_monitor_attributes_list): Call make_monitor_attribute_list.
  (syms_of_xfns): Remove DEFSYM for Qgeometry, Qworkarea, Qmm_size,
  Qframes, Qsource.
modified:
  src/ChangeLog
  src/frame.c
  src/frame.h
  src/nsfns.m
  src/xfns.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2013-05-25 01:55:00 +0000
+++ b/src/ChangeLog     2013-05-25 11:14:38 +0000
@@ -1,3 +1,29 @@
+2013-05-25  Jan Djärv  <address@hidden>
+
+       * xfns.c (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): Remove.
+       (struct MonitorInfo, free_monitors): Remove.
+       (x_make_monitor_attribute_list): Call make_monitor_attribute_list.
+       (Fx_display_monitor_attributes_list): Call make_monitor_attribute_list.
+       (syms_of_xfns): Remove DEFSYM for Qgeometry, Qworkarea, Qmm_size,
+       Qframes, Qsource.
+
+       * nsfns.m (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): Remove.
+       (struct MonitorInfo, free_monitors): Remove.
+       (ns_screen_name): Make static.
+       (ns_make_monitor_attribute_list): Call make_monitor_attribute_list.
+       (syms_of_nsfns): Remove DEFSYM for Qgeometry, Qworkarea, Qmm_size,
+       Qframes, Qsource.
+
+       * frame.h (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): Declare.
+       (struct MonitorInfo): New struct.
+       (free_monitors, make_monitor_attribute_list): Declare.
+
+       * frame.c (Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource): New
+       Lisp_Object:s.
+       (free_monitors, make_monitor_attribute_list): New functions.
+       (syms_of_frame): DEFSYM Qgeometry, Qworkarea, Qmm_size, Qframes,
+       Qsource.
+
 2013-05-25  Xue Fuqiao  <address@hidden>
 
        * callproc.c (call_process): Refine the doc string.  (Bug#14045)

=== modified file 'src/frame.c'
--- a/src/frame.c       2013-04-10 15:38:20 +0000
+++ b/src/frame.c       2013-05-25 11:14:38 +0000
@@ -76,7 +76,6 @@
 Lisp_Object Qauto_raise, Qauto_lower;
 Lisp_Object Qborder_color, Qborder_width;
 Lisp_Object Qcursor_color, Qcursor_type;
-static Lisp_Object Qgeometry;  /* Not used */
 Lisp_Object Qheight, Qwidth;
 Lisp_Object Qleft, Qright;
 Lisp_Object Qicon_left, Qicon_top, Qicon_type, Qicon_name;
@@ -115,6 +114,8 @@
 
 static Lisp_Object Qdelete_frame_functions;
 
+Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
+
 #ifdef HAVE_WINDOW_SYSTEM
 static void x_report_frame_params (struct frame *, Lisp_Object *);
 #endif
@@ -4129,6 +4130,73 @@
   return decode_any_frame (frame)->pointer_invisible ? Qnil : Qt;
 }
 
+
+
+/***********************************************************************
+                       Multimonitor data
+ ***********************************************************************/
+
+#ifdef HAVE_WINDOW_SYSTEM
+
+void
+free_monitors (struct MonitorInfo *monitors, int n_monitors)
+{
+  int i;
+  for (i = 0; i < n_monitors; ++i)
+    xfree (monitors[i].name);
+  xfree (monitors);
+}
+
+Lisp_Object
+make_monitor_attribute_list (struct MonitorInfo *monitors,
+                             int n_monitors,
+                             int primary_monitor,
+                             Lisp_Object monitor_frames,
+                             const char *source)
+{
+  Lisp_Object attributes_list = Qnil;
+  Lisp_Object primary_monitor_attributes = Qnil;
+  int i;
+
+  for (i = 0; i < n_monitors; ++i)
+    {
+      Lisp_Object geometry, workarea, attributes = Qnil;
+      struct MonitorInfo *mi = &monitors[i];
+
+      if (mi->geom.width == 0) continue;
+
+      workarea = list4i (mi->work.x, mi->work.y,
+                        mi->work.width, mi->work.height);
+      geometry = list4i (mi->geom.x, mi->geom.y,
+                        mi->geom.width, mi->geom.height);
+      attributes = Fcons (Fcons (Qsource,
+                                 make_string (source, strlen (source))),
+                          attributes);
+      attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
+                         attributes);
+      attributes = Fcons (Fcons (Qmm_size,
+                                 list2i (mi->mm_width, mi->mm_height)),
+                          attributes);
+      attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
+      attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
+      if (mi->name)
+        attributes = Fcons (Fcons (Qname, make_string (mi->name,
+                                                       strlen (mi->name))),
+                            attributes);
+
+      if (i == primary_monitor)
+        primary_monitor_attributes = attributes;
+      else
+        attributes_list = Fcons (attributes, attributes_list);
+    }
+
+  if (!NILP (primary_monitor_attributes))
+    attributes_list = Fcons (primary_monitor_attributes, attributes_list);
+  return attributes_list;
+}
+
+#endif /* HAVE_WINDOW_SYSTEM */
+
 
 /***********************************************************************
                                Initialization
@@ -4187,6 +4255,12 @@
   DEFSYM (Qterminal, "terminal");
   DEFSYM (Qterminal_live_p, "terminal-live-p");
 
+  DEFSYM (Qgeometry, "geometry");
+  DEFSYM (Qworkarea, "workarea");
+  DEFSYM (Qmm_size, "mm-size");
+  DEFSYM (Qframes, "frames");
+  DEFSYM (Qsource, "source");
+
 #ifdef HAVE_NS
   DEFSYM (Qns_parse_geometry, "ns-parse-geometry");
 #endif

=== modified file 'src/frame.h'
--- a/src/frame.h       2013-04-15 07:27:56 +0000
+++ b/src/frame.h       2013-05-25 11:14:38 +0000
@@ -1198,6 +1198,8 @@
 
 extern Lisp_Object Qrun_hook_with_args;
 
+extern Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
+
 #ifdef HAVE_WINDOW_SYSTEM
 
 /* The class of this X application.  */
@@ -1288,6 +1290,28 @@
 extern void x_query_color (struct frame *f, XColor *);
 
 #endif /* HAVE_WINDOW_SYSTEM */
+
+/***********************************************************************
+                       Multimonitor data
+ ***********************************************************************/
+
+#ifdef HAVE_WINDOW_SYSTEM
+
+struct MonitorInfo {
+  XRectangle geom, work;
+  int mm_width, mm_height;
+  char *name;
+};
+
+extern void free_monitors (struct MonitorInfo *monitors, int n_monitors);
+extern Lisp_Object make_monitor_attribute_list (struct MonitorInfo *monitors,
+                                                int n_monitors,
+                                                int primary_monitor,
+                                                Lisp_Object monitor_frames,
+                                                const char *source);
+
+#endif /* HAVE_WINDOW_SYSTEM */
+
 
 INLINE_HEADER_END
 

=== modified file 'src/nsfns.m'
--- a/src/nsfns.m       2013-05-20 08:27:56 +0000
+++ b/src/nsfns.m       2013-05-25 11:14:38 +0000
@@ -105,7 +105,6 @@
 static ptrdiff_t image_cache_refcount;
 #endif
 
-static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
 
 /* ==========================================================================
 
@@ -2328,27 +2327,12 @@
   return make_number (x_display_pixel_height (dpyinfo));
 }
 
-struct MonitorInfo {
-  XRectangle geom, work;
-  int mm_width, mm_height;
-  char *name;
-};
-
-static void
-free_monitors (struct MonitorInfo *monitors, int n_monitors)
-{
-  int i;
-  for (i = 0; i < n_monitors; ++i)
-    xfree (monitors[i].name);
-  xfree (monitors);
-}
-
 #ifdef NS_IMPL_COCOA
 /* Returns the name for the screen that DICT came from, or NULL.
    Caller must free return value.
 */
 
-char *
+static char *
 ns_screen_name (CGDirectDisplayID did)
 {
   char *name = NULL;
@@ -2377,8 +2361,7 @@
                                 const char *source)
 {
   Lisp_Object monitor_frames = Fmake_vector (make_number (n_monitors), Qnil);
-  Lisp_Object frame, rest, attributes_list = Qnil;
-  Lisp_Object primary_monitor_attributes = Qnil;
+  Lisp_Object frame, rest;
   NSArray *screens = [NSScreen screens];
   int i;
 
@@ -2404,41 +2387,8 @@
        }
     }
 
-  for (i = 0; i < n_monitors; ++i)
-    {
-      Lisp_Object geometry, workarea, attributes = Qnil;
-      struct MonitorInfo *mi = &monitors[i];
-
-      if (mi->geom.width == 0) continue;
-
-      workarea = list4i (mi->work.x, mi->work.y,
-                        mi->work.width, mi->work.height);
-      geometry = list4i (mi->geom.x, mi->geom.y,
-                        mi->geom.width, mi->geom.height);
-      attributes = Fcons (Fcons (Qsource,
-                                 make_string (source, strlen (source))),
-                          attributes);
-      attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
-                         attributes);
-      attributes = Fcons (Fcons (Qmm_size,
-                                 list2i (mi->mm_width, mi->mm_height)),
-                          attributes);
-      attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
-      attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
-      if (mi->name)
-        attributes = Fcons (Fcons (Qname, make_string (mi->name,
-                                                       strlen (mi->name))),
-                            attributes);
-
-      if (i == primary_monitor)
-        primary_monitor_attributes = attributes;
-      else
-        attributes_list = Fcons (attributes, attributes_list);
-    }
-
-  if (!NILP (primary_monitor_attributes))
-    attributes_list = Fcons (primary_monitor_attributes, attributes_list);
-  return attributes_list;
+  return make_monitor_attribute_list (monitors, n_monitors, primary_monitor,
+                                      monitor_frames, source);
 }
 
 DEFUN ("ns-display-monitor-attributes-list",
@@ -2922,11 +2872,6 @@
 void
 syms_of_nsfns (void)
 {
-  DEFSYM (Qgeometry, "geometry");
-  DEFSYM (Qworkarea, "workarea");
-  DEFSYM (Qmm_size, "mm-size");
-  DEFSYM (Qframes, "frames");
-  DEFSYM (Qsource, "source");
   Qfontsize = intern_c_string ("fontsize");
   staticpro (&Qfontsize);
 

=== modified file 'src/xfns.c'
--- a/src/xfns.c        2013-05-20 03:15:20 +0000
+++ b/src/xfns.c        2013-05-25 11:14:38 +0000
@@ -133,7 +133,6 @@
 static Lisp_Object Qsuppress_icon;
 static Lisp_Object Qundefined_color;
 static Lisp_Object Qcompound_text, Qcancel_timer;
-static Lisp_Object Qgeometry, Qworkarea, Qmm_size, Qframes, Qsource;
 Lisp_Object Qfont_param;
 
 #ifdef GLYPH_DEBUG
@@ -3882,24 +3881,6 @@
 
 #ifndef USE_GTK
 
-struct MonitorInfo {
-  XRectangle geom, work;
-  int mm_width, mm_height;
-  char *name;
-};
-
-#if defined HAVE_XINERAMA || defined HAVE_XRANDR
-static void
-free_monitors (struct MonitorInfo *monitors, int n_monitors)
-{
-  int i;
-  for (i = 0; i < n_monitors; ++i)
-    xfree (monitors[i].name);
-  xfree (monitors);
-}
-#endif /* HAVE_XINERAMA || HAVE_XRANDR */
-
-
 /* Return monitor number where F is "most" or closest to.  */
 static int
 x_get_monitor_for_frame (struct frame *f,
@@ -3971,9 +3952,7 @@
                                const char *source)
 {
   Lisp_Object monitor_frames = Fmake_vector (make_number (n_monitors), Qnil);
-  Lisp_Object frame, rest, attributes_list = Qnil;
-  Lisp_Object primary_monitor_attributes = Qnil;
-  int i;
+  Lisp_Object frame, rest;
 
   FOR_EACH_FRAME (rest, frame)
     {
@@ -3982,46 +3961,13 @@
       if (FRAME_X_P (f) && FRAME_X_DISPLAY_INFO (f) == dpyinfo
          && !EQ (frame, tip_frame))
        {
-         i = x_get_monitor_for_frame (f, monitors, n_monitors);
+         int i = x_get_monitor_for_frame (f, monitors, n_monitors);
          ASET (monitor_frames, i, Fcons (frame, AREF (monitor_frames, i)));
        }
     }
 
-  for (i = 0; i < n_monitors; ++i)
-    {
-      Lisp_Object geometry, workarea, attributes = Qnil;
-      struct MonitorInfo *mi = &monitors[i];
-
-      if (mi->geom.width == 0) continue;
-
-      workarea = list4i (mi->work.x, mi->work.y,
-                        mi->work.width, mi->work.height);
-      geometry = list4i (mi->geom.x, mi->geom.y,
-                        mi->geom.width, mi->geom.height);
-      attributes = Fcons (Fcons (Qsource,
-                                 make_string (source, strlen (source))),
-                          attributes);
-      attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
-                         attributes);
-      attributes = Fcons (Fcons (Qmm_size,
-                                 list2i (mi->mm_width, mi->mm_height)),
-                          attributes);
-      attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
-      attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
-      if (mi->name)
-        attributes = Fcons (Fcons (Qname, make_string (mi->name,
-                                                       strlen (mi->name))),
-                            attributes);
-
-      if (i == primary_monitor)
-        primary_monitor_attributes = attributes;
-      else
-        attributes_list = Fcons (attributes, attributes_list);
-    }
-
-  if (!NILP (primary_monitor_attributes))
-    attributes_list = Fcons (primary_monitor_attributes, attributes_list);
-  return attributes_list;
+  return make_monitor_attribute_list (monitors, n_monitors, primary_monitor,
+                                      monitor_frames, source);
 }
 
 static Lisp_Object
@@ -4270,9 +4216,9 @@
   GdkDisplay *gdpy;
   GdkScreen *gscreen;
   gint primary_monitor = 0, n_monitors, i;
-  Lisp_Object primary_monitor_attributes = Qnil;
   Lisp_Object monitor_frames, rest, frame;
   static const char *source = "Gdk";
+  struct MonitorInfo *monitors;
 
   block_input ();
   mm_width_per_pixel = ((double) WidthMMOfScreen (dpyinfo->screen)
@@ -4286,6 +4232,8 @@
 #endif
   n_monitors = gdk_screen_get_n_monitors (gscreen);
   monitor_frames = Fmake_vector (make_number (n_monitors), Qnil);
+  monitors = (struct MonitorInfo *) xzalloc (n_monitors * sizeof (*monitors));
+
   FOR_EACH_FRAME (rest, frame)
     {
       struct frame *f = XFRAME (frame);
@@ -4300,21 +4248,13 @@
        }
     }
 
-  i = n_monitors;
-  while (i-- > 0)
+  for (i = 0; i < n_monitors; ++i)
     {
-      Lisp_Object geometry, workarea, attributes = Qnil;
       gint width_mm = -1, height_mm = -1;
-      GdkRectangle rec;
-
-      attributes = Fcons (Fcons (Qsource,
-                                 make_string (source, strlen (source))),
-                          attributes);
-      attributes = Fcons (Fcons (Qframes, AREF (monitor_frames, i)),
-                         attributes);
+      GdkRectangle rec, work;
+      struct MonitorInfo *mi = &monitors[i];
 
       gdk_screen_get_monitor_geometry (gscreen, i, &rec);
-      geometry = list4i (rec.x, rec.y, rec.width, rec.height);
 
 #if GTK_CHECK_VERSION (2, 14, 0)
       width_mm = gdk_screen_get_monitor_width_mm (gscreen, i);
@@ -4324,54 +4264,50 @@
        width_mm = rec.width * mm_width_per_pixel + 0.5;
       if (height_mm < 0)
        height_mm = rec.height * mm_height_per_pixel + 0.5;
-      attributes = Fcons (Fcons (Qmm_size,
-                                list2i (width_mm, height_mm)),
-                         attributes);
 
 #if GTK_CHECK_VERSION (3, 4, 0)
-      gdk_screen_get_monitor_workarea (gscreen, i, &rec);
-      workarea = list4i (rec.x, rec.y, rec.width, rec.height);
+      gdk_screen_get_monitor_workarea (gscreen, i, &work);
 #else
       /* Emulate the behavior of GTK+ 3.4.  */
       {
        XRectangle workarea_r;
 
-       workarea = Qnil;
        if (i == primary_monitor && x_get_net_workarea (dpyinfo, &workarea_r))
          {
-           GdkRectangle work;
-
            work.x = workarea_r.x;
            work.y = workarea_r.y;
            work.width = workarea_r.width;
            work.height = workarea_r.height;
-           if (gdk_rectangle_intersect (&rec, &work, &work))
-             workarea = list4i (work.x, work.y, work.width, work.height);
-         }
-       if (NILP (workarea))
-         workarea = geometry;
+           if (! gdk_rectangle_intersect (&rec, &work, &work))
+              work = rec;
+          }
+        else
+          work = rec;
       }
 #endif
-      attributes = Fcons (Fcons (Qworkarea, workarea), attributes);
-
-      attributes = Fcons (Fcons (Qgeometry, geometry), attributes);
+
+
+      mi->geom.x = rec.x;
+      mi->geom.y = rec.y;
+      mi->geom.width = rec.width;
+      mi->geom.height = rec.height;
+      mi->work.x = work.x;
+      mi->work.y = work.y;
+      mi->work.width = work.width;
+      mi->work.height = work.height;
+      mi->mm_width = width_mm;
+      mi->mm_height = height_mm;
+
 #if GTK_CHECK_VERSION (2, 14, 0)
-      {
-        char *name = gdk_screen_get_monitor_plug_name (gscreen, i);
-        if (name)
-          attributes = Fcons (Fcons (Qname, make_string (name, strlen (name))),
-                              attributes);
-      }
+      mi->name = gdk_screen_get_monitor_plug_name (gscreen, i);
 #endif
-
-      if (i == primary_monitor)
-       primary_monitor_attributes = attributes;
-      else
-       attributes_list = Fcons (attributes, attributes_list);
     }
 
-  if (!NILP (primary_monitor_attributes))
-    attributes_list = Fcons (primary_monitor_attributes, attributes_list);
+  attributes_list = make_monitor_attribute_list (monitors,
+                                                 n_monitors,
+                                                 primary_monitor,
+                                                 monitor_frames,
+                                                 source);
   unblock_input ();
 #else  /* not USE_GTK */
 
@@ -6294,11 +6230,6 @@
   DEFSYM (Qundefined_color, "undefined-color");
   DEFSYM (Qcompound_text, "compound-text");
   DEFSYM (Qcancel_timer, "cancel-timer");
-  DEFSYM (Qgeometry, "geometry");
-  DEFSYM (Qworkarea, "workarea");
-  DEFSYM (Qmm_size, "mm-size");
-  DEFSYM (Qframes, "frames");
-  DEFSYM (Qsource, "source");
   DEFSYM (Qfont_param, "font-parameter");
   /* This is the end of symbol initialization.  */
 


reply via email to

[Prev in Thread] Current Thread [Next in Thread]