From 056ce1959724bce0b79983a2b88d193def718adb Mon Sep 17 00:00:00 2001 From: Stefan Monnier Date: Fri, 16 Nov 2007 21:04:30 +0000 Subject: [PATCH] * 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. --- src/ChangeLog | 20 +++++++++ src/gtkutil.c | 11 +++-- src/xfns.c | 2 +- src/xterm.c | 120 +++++++++++++++++++++++++------------------------- src/xterm.h | 38 +++++----------- 5 files changed, 95 insertions(+), 96 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index bdc58ad4639..85f9736da7b 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,5 +1,25 @@ 2007-11-16 Stefan Monnier + * 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. diff --git a/src/gtkutil.c b/src/gtkutil.c index e36e192c65e..77d5fd65649 100644 --- a/src/gtkutil.c +++ b/src/gtkutil.c @@ -2970,10 +2970,9 @@ free_frame_menubar (f) 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 @@ xg_create_scroll_bar (f, bar, scroll_callback, scroll_bar_name) /* 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 @@ xg_set_toolkit_scroll_bar_thumb (bar, portion, position, whole) 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))); diff --git a/src/xfns.c b/src/xfns.c index a35f9dd5068..96631d98f55 100644 --- a/src/xfns.c +++ b/src/xfns.c @@ -931,7 +931,7 @@ x_set_background_color (f, arg, oldval) !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); } } diff --git a/src/xterm.c b/src/xterm.c index f3b84a73cb0..b0897c16838 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -3962,7 +3962,7 @@ x_window_to_scroll_bar (display, window_id) 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 @@ xm_scroll_callback (widget, client_data, call_data) } } +#elif defined USE_GTK -#else /* !USE_MOTIF, i.e. Xaw or GTK */ -#ifdef 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 @@ xg_scroll_callback (widget, data) } } -#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 @@ xaw_scroll_callback (widget, client_data, call_data) 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 @@ x_create_toolkit_scroll_bar (f, bar) /* 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 @@ x_scroll_bar_create (w, top, left, width, height) { 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 @@ x_scroll_bar_create (w, top, left, width, height) 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 @@ x_scroll_bar_create (w, top, left, width, height) { #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 @@ x_scroll_bar_create (w, top, left, width, height) #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 @@ x_scroll_bar_create (w, top, left, width, height) } +#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 @@ x_scroll_bar_create (w, top, left, width, height) 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 @@ x_scroll_bar_set_handle (bar, start, end, rebuild) 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 @@ x_scroll_bar_remove (bar) #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 @@ XTset_vertical_scroll_bar (w, portion, whole, position) 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 @@ XTset_vertical_scroll_bar (w, portion, whole, position) } #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 @@ XTset_vertical_scroll_bar (w, portion, whole, position) 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 @@ x_scroll_bar_expose (bar, event) 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 @@ x_scroll_bar_handle_click (bar, event, emacs_event) #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 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) 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 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) { #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 @@ x_scroll_bar_report_motion (fp, bar_window, part, x, y, time) 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 @@ x_scroll_bar_clear (f) 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 @@ handle_one_xevent (dpyinfo, eventp, finish, hold_quit) 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 @@ x_connection_closed (dpy, error_message) 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 @@ x_connection_closed (dpy, error_message) 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 @@ x_term_init (display_name, xrm_option, resource_name) /* 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); - /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */ mm = DisplayWidthMM (dpyinfo->display, screen_number); + /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */ dpyinfo->resx = (mm < 1) ? 100 : pixels * 25.4 / mm; } @@ -11038,13 +11036,13 @@ x_term_init (display_name, xrm_option, resource_name) 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 } diff --git a/src/xterm.h b/src/xterm.h index 741dec13e75..d9b5c327858 100644 --- a/src/xterm.h +++ b/src/xterm.h @@ -746,13 +746,14 @@ struct scroll_bar /* 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 @@ struct scroll_bar 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 @@ struct scroll_bar 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 @@ struct scroll_bar #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) -- 2.39.2