changeset 86161:3408ab8b4152

* xterm.h (struct scroll_bar): Only use Lisp_Object for lisp data. Turn integer fields into `int'. Merge x_window_low and x_window_high. (SCROLL_BAR_PACK, SCROLL_BAR_UNPACK, SCROLL_BAR_X_WINDOW) (SET_SCROLL_BAR_X_WINDOW): Remove. (SCROLL_BAR_X_WIDGET, SET_SCROLL_BAR_X_WIDGET): Access the new x_window field directly. * xterm.c (x_scroll_bar_create): Use a pseudovector. Don't wrap/unwrap integers into Lisp_Objects. (XTset_vertical_scroll_bar, x_scroll_bar_handle_click) (x_scroll_bar_report_motion): Don't wrap/unwrap integers into Lisp_Objects. (x_term_init): Use SDATA. (x_window_to_scroll_bar, x_create_toolkit_scroll_bar) (x_scroll_bar_set_handle, x_scroll_bar_remove) (XTset_vertical_scroll_bar, x_scroll_bar_expose) (x_scroll_bar_report_motion, x_scroll_bar_clear): * xfns.c (x_set_background_color): * gtkutil.c (xg_create_scroll_bar, xg_set_toolkit_scroll_bar_thumb): Access the new x_window field directly.
author Stefan Monnier <monnier@iro.umontreal.ca>
date Fri, 16 Nov 2007 21:04:30 +0000
parents 1ede747999c6
children e7cf3055e000
files src/ChangeLog src/gtkutil.c src/xfns.c src/xterm.c src/xterm.h
diffstat 5 files changed, 96 insertions(+), 97 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Nov 16 20:36:34 2007 +0000
+++ b/src/ChangeLog	Fri Nov 16 21:04:30 2007 +0000
@@ -1,5 +1,25 @@
 2007-11-16  Stefan Monnier  <monnier@iro.umontreal.ca>
 
+	* xterm.h (struct scroll_bar): Only use Lisp_Object for lisp data.
+	Turn integer fields into `int'.  Merge x_window_low and x_window_high.
+	(SCROLL_BAR_PACK, SCROLL_BAR_UNPACK, SCROLL_BAR_X_WINDOW)
+	(SET_SCROLL_BAR_X_WINDOW): Remove.
+	(SCROLL_BAR_X_WIDGET, SET_SCROLL_BAR_X_WIDGET):
+	Access the new x_window field directly.
+	* xterm.c (x_scroll_bar_create): Use a pseudovector.
+	Don't wrap/unwrap integers into Lisp_Objects.
+	(XTset_vertical_scroll_bar, x_scroll_bar_handle_click)
+	(x_scroll_bar_report_motion):
+	Don't wrap/unwrap integers into Lisp_Objects.
+	(x_term_init): Use SDATA.
+	(x_window_to_scroll_bar, x_create_toolkit_scroll_bar)
+	(x_scroll_bar_set_handle, x_scroll_bar_remove)
+	(XTset_vertical_scroll_bar, x_scroll_bar_expose)
+	(x_scroll_bar_report_motion, x_scroll_bar_clear):
+	* xfns.c (x_set_background_color):
+	* gtkutil.c (xg_create_scroll_bar, xg_set_toolkit_scroll_bar_thumb):
+	Access the new x_window field directly.
+
 	* alloc.c (ALLOCATE_PSEUDOVECTOR): Move to lisp.h.
 	(allocate_pseudovector): Make non-static.
 	* lisp.h (enum pvec_type): New tag PVEC_OTHER.
--- a/src/gtkutil.c	Fri Nov 16 20:36:34 2007 +0000
+++ b/src/gtkutil.c	Fri Nov 16 21:04:30 2007 +0000
@@ -2970,10 +2970,9 @@
 
 int xg_ignore_gtk_scrollbar;
 
-/* SET_SCROLL_BAR_X_WINDOW assumes the second argument fits in
-   32 bits.  But we want to store pointers, and they may be larger
-   than 32 bits.  Keep a mapping from integer index to widget pointers
-   to get around the 32 bit limitation.  */
+/* Xlib's `Window' fits in 32 bits.  But we want to store pointers, and they
+   may be larger than 32 bits.  Keep a mapping from integer index to widget
+   pointers to get around the 32 bit limitation.  */
 
 static struct
 {
@@ -3183,7 +3182,7 @@
   /* Set the cursor to an arrow.  */
   xg_set_cursor (webox, FRAME_X_DISPLAY_INFO (f)->xg_cursor);
 
-  SET_SCROLL_BAR_X_WINDOW (bar, scroll_id);
+  bar->x_window = scroll_id;
 }
 
 /* Make the scroll bar represented by SCROLLBAR_ID visible.  */
@@ -3258,7 +3257,7 @@
      struct scroll_bar *bar;
      int portion, position, whole;
 {
-  GtkWidget *wscroll = xg_get_widget_from_map (SCROLL_BAR_X_WINDOW (bar));
+  GtkWidget *wscroll = xg_get_widget_from_map (bar->x_window);
 
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
 
--- a/src/xfns.c	Fri Nov 16 20:36:34 2007 +0000
+++ b/src/xfns.c	Fri Nov 16 21:04:30 2007 +0000
@@ -931,7 +931,7 @@
 	     !NILP (bar);
 	     bar = XSCROLL_BAR (bar)->next)
 	  {
-	    Window window = SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar));
+	    Window window = XSCROLL_BAR (bar)->x_window;
 	    XSetWindowBackground (dpy, window, bg);
 	  }
       }
--- a/src/xterm.c	Fri Nov 16 20:36:34 2007 +0000
+++ b/src/xterm.c	Fri Nov 16 21:04:30 2007 +0000
@@ -3962,7 +3962,7 @@
 			       condemned = Qnil,
 			       ! GC_NILP (bar));
 	   bar = XSCROLL_BAR (bar)->next)
-	if (SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)) == window_id &&
+	if (XSCROLL_BAR (bar)->x_window == window_id &&
             FRAME_X_DISPLAY (XFRAME (frame)) == display)
 	  return XSCROLL_BAR (bar);
     }
@@ -4280,9 +4280,8 @@
     }
 }
 
-
-#else /* !USE_MOTIF, i.e. Xaw or GTK */
-#ifdef USE_GTK
+#elif defined USE_GTK
+
 /* Scroll bar callback for GTK scroll bars.  WIDGET is the scroll
    bar widget.  DATA is a pointer to the scroll_bar structure. */
 
@@ -4353,7 +4352,7 @@
     }
 }
 
-#else /* not USE_GTK */
+#else /* not USE_GTK and not USE_MOTIF */
 
 /* Xaw scroll bar callback.  Invoked when the thumb is dragged.
    WIDGET is the scroll bar widget.  CLIENT_DATA is a pointer to the
@@ -4436,8 +4435,7 @@
   x_send_scroll_bar_event (bar->window, part, position, height);
 }
 
-#endif /* not USE_GTK */
-#endif /* not USE_MOTIF */
+#endif /* not USE_GTK and not USE_MOTIF */
 
 #define SCROLL_BAR_NAME "verticalScrollBar"
 
@@ -4643,7 +4641,7 @@
   /* Remember X window and widget in the scroll bar vector.  */
   SET_SCROLL_BAR_X_WIDGET (bar, widget);
   xwindow = XtWindow (widget);
-  SET_SCROLL_BAR_X_WINDOW (bar, xwindow);
+  bar->x_window = xwindow;
 
   UNBLOCK_INPUT;
 }
@@ -4787,7 +4785,7 @@
 {
   struct frame *f = XFRAME (w->frame);
   struct scroll_bar *bar
-    = XSCROLL_BAR (Fmake_vector (make_number (SCROLL_BAR_VEC_SIZE), Qnil));
+    = ALLOCATE_PSEUDOVECTOR (struct scroll_bar, x_window, PVEC_OTHER);
 
   BLOCK_INPUT;
 
@@ -4831,21 +4829,19 @@
 			    CopyFromParent,
 			     /* Attributes.  */
 			    mask, &a);
-    SET_SCROLL_BAR_X_WINDOW (bar, window);
+    bar->x_window = window;
   }
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 
   XSETWINDOW (bar->window, w);
-  XSETINT (bar->top, top);
-  XSETINT (bar->left, left);
-  XSETINT (bar->width, width);
-  XSETINT (bar->height, height);
-  XSETINT (bar->start, 0);
-  XSETINT (bar->end, 0);
+  bar->top = top;
+  bar->left = left;
+  bar->width = width;
+  bar->height = height;
+  bar->start = 0;
+  bar->end = 0;
   bar->dragging = Qnil;
-#ifdef USE_TOOLKIT_SCROLL_BARS
-  bar->fringe_extended_p = Qnil;
-#endif
+  bar->fringe_extended_p = 0;
 
   /* Add bar to its frame's list of scroll bars.  */
   bar->next = FRAME_SCROLL_BARS (f);
@@ -4859,12 +4855,12 @@
   {
 #ifdef USE_GTK
     xg_update_scrollbar_pos (f,
-                             SCROLL_BAR_X_WINDOW (bar),
+                             bar->x_window,
                              top,
                              left + VERTICAL_SCROLL_BAR_WIDTH_TRIM,
                              width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2,
                              max (height, 1));
-    xg_show_scroll_bar (SCROLL_BAR_X_WINDOW (bar));
+    xg_show_scroll_bar (bar->x_window);
 #else /* not USE_GTK */
     Widget scroll_bar = SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar);
     XtConfigureWidget (scroll_bar,
@@ -4876,7 +4872,7 @@
 #endif /* not USE_GTK */
     }
 #else /* not USE_TOOLKIT_SCROLL_BARS */
-  XMapRaised (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
+  XMapRaised (FRAME_X_DISPLAY (f), bar->x_window);
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 
   UNBLOCK_INPUT;
@@ -4884,6 +4880,8 @@
 }
 
 
+#ifndef USE_TOOLKIT_SCROLL_BARS
+
 /* Draw BAR's handle in the proper position.
 
    If the handle is already drawn from START to END, don't bother
@@ -4897,8 +4895,6 @@
    the bar's top is as far down as it goes; otherwise, there's no way
    to move to the very end of the buffer.  */
 
-#ifndef USE_TOOLKIT_SCROLL_BARS
-
 static void
 x_scroll_bar_set_handle (bar, start, end, rebuild)
      struct scroll_bar *bar;
@@ -4906,7 +4902,7 @@
      int rebuild;
 {
   int dragging = ! NILP (bar->dragging);
-  Window w = SCROLL_BAR_X_WINDOW (bar);
+  Window w = bar->x_window;
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   GC gc = f->output_data.x->normal_gc;
 
@@ -5009,12 +5005,12 @@
 
 #ifdef USE_TOOLKIT_SCROLL_BARS
 #ifdef USE_GTK
-  xg_remove_scroll_bar (f, SCROLL_BAR_X_WINDOW (bar));
+  xg_remove_scroll_bar (f, bar->x_window);
 #else /* not USE_GTK */
   XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f), bar));
 #endif /* not USE_GTK */
 #else
-  XDestroyWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar));
+  XDestroyWindow (FRAME_X_DISPLAY (f), bar->x_window);
 #endif
 
   /* Disassociate this scroll bar from its window.  */
@@ -5112,19 +5108,19 @@
 
       BLOCK_INPUT;
 
-      if (sb_left != XINT (bar->left))
+      if (sb_left != bar->left)
 	mask |= CWX;
-      if (top != XINT (bar->top))
+      if (top != bar->top)
 	mask |= CWY;
-      if (sb_width != XINT (bar->width))
+      if (sb_width != bar->width)
 	mask |= CWWidth;
-      if (height != XINT (bar->height))
+      if (height != bar->height)
 	mask |= CWHeight;
 
 #ifdef USE_TOOLKIT_SCROLL_BARS
 
       /* Move/size the scroll bar widget.  */
-      if (mask || !NILP (bar->fringe_extended_p) != fringe_extended_p)
+      if (mask || bar->fringe_extended_p != fringe_extended_p)
 	{
 	  /* Since toolkit scroll bars are smaller than the space reserved
 	     for them on the frame, we have to clear "under" them.  */
@@ -5139,7 +5135,7 @@
 	    }
 #ifdef USE_GTK
           xg_update_scrollbar_pos (f,
-                                   SCROLL_BAR_X_WINDOW (bar),
+                                   bar->x_window,
                                    top,
                                    sb_left + VERTICAL_SCROLL_BAR_WIDTH_TRIM,
                                    sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM *2,
@@ -5195,23 +5191,23 @@
 	  wc.y = top;
 	  wc.width = sb_width - VERTICAL_SCROLL_BAR_WIDTH_TRIM * 2;
 	  wc.height = height;
-	  XConfigureWindow (FRAME_X_DISPLAY (f), SCROLL_BAR_X_WINDOW (bar),
+	  XConfigureWindow (FRAME_X_DISPLAY (f), bar->x_window,
 			    mask, &wc);
 	}
 
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 
       /* Remember new settings.  */
-      XSETINT (bar->left, sb_left);
-      XSETINT (bar->top, top);
-      XSETINT (bar->width, sb_width);
-      XSETINT (bar->height, height);
+      bar->left = sb_left;
+      bar->top = top;
+      bar->width = sb_width;
+      bar->height = height;
 
       UNBLOCK_INPUT;
     }
 
 #ifdef USE_TOOLKIT_SCROLL_BARS
-  bar->fringe_extended_p = fringe_extended_p ? Qt : Qnil;
+  bar->fringe_extended_p = fringe_extended_p;
 
   x_set_toolkit_scroll_bar_thumb (bar, portion, position, whole);
 #else /* not USE_TOOLKIT_SCROLL_BARS */
@@ -5355,7 +5351,7 @@
      struct scroll_bar *bar;
      XEvent *event;
 {
-  Window w = SCROLL_BAR_X_WINDOW (bar);
+  Window w = bar->x_window;
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   GC gc = f->output_data.x->normal_gc;
   int width_trim = VERTICAL_SCROLL_BAR_WIDTH_TRIM;
@@ -5419,18 +5415,18 @@
 #if 0
     FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
     int internal_height
-      = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height));
+      = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, bar->height);
 #endif
     int top_range
-      = VERTICAL_SCROLL_BAR_TOP_RANGE (f, XINT (bar->height));
+      = VERTICAL_SCROLL_BAR_TOP_RANGE (f, bar->height);
     int y = event->xbutton.y - VERTICAL_SCROLL_BAR_TOP_BORDER;
 
     if (y < 0) y = 0;
     if (y > top_range) y = top_range;
 
-    if (y < XINT (bar->start))
+    if (y < bar->start)
       emacs_event->part = scroll_bar_above_handle;
-    else if (y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE)
+    else if (y < bar->end + VERTICAL_SCROLL_BAR_MIN_HANDLE)
       emacs_event->part = scroll_bar_handle;
     else
       emacs_event->part = scroll_bar_below_handle;
@@ -5523,7 +5519,7 @@
      unsigned long *time;
 {
   struct scroll_bar *bar = XSCROLL_BAR (last_mouse_scroll_bar);
-  Window w = SCROLL_BAR_X_WINDOW (bar);
+  Window w = bar->x_window;
   FRAME_PTR f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
   int win_x, win_y;
   Window dummy_window;
@@ -5550,10 +5546,10 @@
     {
 #if 0
       int inside_height
-	= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, XINT (bar->height));
+	= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, bar->height);
 #endif
       int top_range
-	= VERTICAL_SCROLL_BAR_TOP_RANGE     (f, XINT (bar->height));
+	= VERTICAL_SCROLL_BAR_TOP_RANGE     (f, bar->height);
 
       win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER;
 
@@ -5570,9 +5566,9 @@
 
       if (! NILP (bar->dragging))
 	*part = scroll_bar_handle;
-      else if (win_y < XINT (bar->start))
+      else if (win_y < bar->start)
 	*part = scroll_bar_above_handle;
-      else if (win_y < XINT (bar->end) + VERTICAL_SCROLL_BAR_MIN_HANDLE)
+      else if (win_y < bar->end + VERTICAL_SCROLL_BAR_MIN_HANDLE)
 	*part = scroll_bar_handle;
       else
 	*part = scroll_bar_below_handle;
@@ -5609,7 +5605,7 @@
     for (bar = FRAME_SCROLL_BARS (f); VECTORP (bar);
 	 bar = XSCROLL_BAR (bar)->next)
       XClearArea (FRAME_X_DISPLAY (f),
-		  SCROLL_BAR_X_WINDOW (XSCROLL_BAR (bar)),
+		  XSCROLL_BAR (bar)->x_window,
 		  0, 0, 0, 0, True);
 #endif /* not USE_TOOLKIT_SCROLL_BARS */
 }
@@ -6847,12 +6843,10 @@
 
                 if (tool_bar_p && event.xbutton.button < 4)
                   {
-                    if (event.xbutton.type == ButtonPress)
-                      handle_tool_bar_click (f, x, y, 1, 0);
-                    else
-                      handle_tool_bar_click (f, x, y, 0,
-                                             x_x_to_emacs_modifiers (dpyinfo,
-								     event.xbutton.state));
+		    handle_tool_bar_click (f, x, y,
+					   event.xbutton.type == ButtonPress,
+					   x_x_to_emacs_modifiers (dpyinfo,
+								   event.xbutton.state));
                   }
               }
 
@@ -7854,7 +7848,7 @@
 
      Closing the display is reported to lead to a bus error on
      OpenWindows in certain situations.  I suspect that is a bug
-     in OpenWindows.  I don't know how to cicumvent it here.  */
+     in OpenWindows.  I don't know how to circumvent it here.  */
 
 #ifdef USE_X_TOOLKIT
   /* If DPYINFO is null, this means we didn't open the display
@@ -7905,6 +7899,10 @@
 
   unbind_to (index, Qnil);
   clear_waiting_for_input ();
+  /* FIXME: This is an asynchronous interrupt w.r.t elisp, so signalling an
+     error might not be the best thing to do.  I'd vote for creating an
+     elisp event and stuffing it in the queue so people can bind to it via
+     the global map.  --Stef  */
   error ("%s", error_msg);
 }
 
@@ -10868,8 +10866,8 @@
     /* Mac OS X 10.3's Xserver sometimes reports 0.0mm.  */
     dpyinfo->resy = (mm < 1) ? 100 : pixels * 25.4 / mm;
     pixels = DisplayWidth (dpyinfo->display, screen_number);
+    mm = DisplayWidthMM (dpyinfo->display, screen_number);
     /* Mac OS X 10.3's Xserver sometimes reports 0.0mm.  */
-    mm = DisplayWidthMM (dpyinfo->display, screen_number);
     dpyinfo->resx = (mm < 1) ? 100 : pixels * 25.4 / mm;
   }
 
@@ -11038,13 +11036,13 @@
 				    Qnil, Qnil);
 #ifdef USE_XIM
     if (STRINGP (value)
-	&& (!strcmp (XSTRING (value)->data, "false")
-	    || !strcmp (XSTRING (value)->data, "off")))
+	&& (!strcmp (SDATA (value), "false")
+	    || !strcmp (SDATA (value), "off")))
       use_xim = 0;
 #else
     if (STRINGP (value)
-	&& (!strcmp (XSTRING (value)->data, "true")
-	    || !strcmp (XSTRING (value)->data, "on")))
+	&& (!strcmp (SDATA (value), "true")
+	    || !strcmp (SDATA (value), "on")))
       use_xim = 1;
 #endif
   }
--- a/src/xterm.h	Fri Nov 16 20:36:34 2007 +0000
+++ b/src/xterm.h	Fri Nov 16 21:04:30 2007 +0000
@@ -746,13 +746,14 @@
   /* The next and previous in the chain of scroll bars in this frame.  */
   Lisp_Object next, prev;
 
-  /* The X window representing this scroll bar.  Since this is a full
-     32-bit quantity, we store it split into two 32-bit values.  */
-  Lisp_Object x_window_low, x_window_high;
+  /* Fields from `x_window' down will not be traced by the GC.  */
+
+  /* The X window representing this scroll bar.  */
+  Window x_window;
 
   /* The position and size of the scroll bar in pixels, relative to the
      frame.  */
-  Lisp_Object top, left, width, height;
+  int top, left, width, height;
 
   /* The starting and ending positions of the handle, relative to the
      handle area (i.e. zero is the top position, not
@@ -765,7 +766,7 @@
      drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
      where they would be normally; the bottom and top are in a
      different co-ordinate system.  */
-  Lisp_Object start, end;
+  int start, end;
 
   /* If the scroll bar handle is currently being dragged by the user,
      this is the number of pixels from the top of the handle to the
@@ -773,11 +774,9 @@
      being dragged, this is Qnil.  */
   Lisp_Object dragging;
 
-#ifdef USE_TOOLKIT_SCROLL_BARS
-  /* t if the background of the fringe that is adjacent to a scroll
+  /* 1 if the background of the fringe that is adjacent to a scroll
      bar is extended to the gap between the fringe and the bar.  */
-  Lisp_Object fringe_extended_p;
-#endif
+  unsigned int fringe_extended_p : 1;
 };
 
 /* The number of elements a vector holding a struct scroll_bar needs.  */
@@ -790,36 +789,19 @@
 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
 
 
-/* Building a 32-bit C integer from two 16-bit lisp integers.  */
-#define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
-
-/* Setting two lisp integers to the low and high words of a 32-bit C int.  */
-#define SCROLL_BAR_UNPACK(low, high, int32) \
-  (XSETINT ((low),   (int32)        & 0xffff), \
-   XSETINT ((high), ((int32) >> 16) & 0xffff))
-
-
-/* Extract the X window id of the scroll bar from a struct scroll_bar.  */
-#define SCROLL_BAR_X_WINDOW(ptr) \
-  ((Window) SCROLL_BAR_PACK ((ptr)->x_window_low, (ptr)->x_window_high))
-
-/* Store a window id in a struct scroll_bar.  */
-#define SET_SCROLL_BAR_X_WINDOW(ptr, id) \
-  (SCROLL_BAR_UNPACK ((ptr)->x_window_low, (ptr)->x_window_high, (int) id))
-
 /* Extract the X widget of the scroll bar from a struct scroll_bar.
    XtWindowToWidget should be fast enough since Xt uses a hash table
    to map windows to widgets.  */
 
 #define SCROLL_BAR_X_WIDGET(dpy, ptr) \
-  XtWindowToWidget (dpy, SCROLL_BAR_X_WINDOW (ptr))
+  XtWindowToWidget (dpy, ptr->x_window)
 
 /* Store a widget id in a struct scroll_bar.  */
 
 #define SET_SCROLL_BAR_X_WIDGET(ptr, w)		\
   do {						\
     Window window = XtWindow (w);		\
-    SET_SCROLL_BAR_X_WINDOW (ptr, window);	\
+    ptr->x_window = window;			\
 } while (0)