From 4b930ccbb4fc4b848f318e09eddd172c2acf9b9b Mon Sep 17 00:00:00 2001 From: Dmitry Antipov Date: Wed, 24 Sep 2014 11:17:51 +0400 Subject: [PATCH] * termhooks.h (enum scroll_bar_part): Begin from 0 to allow... (struct input_event): ...unsigned bitfields. Likewise for `event_kind' member. Prefer unsigned for `code' and 'modifiers'. Use `timestamp' for HELP_EVENT position. Add compile-time assert. * keyboard.c (gen_help_event, kbd_buffer_store_help_event) (kbd_buffer_get_event): Adjust users. (scroll_bar_parts): Add Qnil to match scroll_bar_nowhere. (make_scroll_bar_position): New function, refactored out of... (make_lispy_event): ...adjusted user. * nsterm.h (EmacsScroller): Use enum for `last_hit_part' member. * nsterm.m (ns_mouse_position, mouseUp): * term.c (term_mouse_position): * w32inevt.c (w32_console_mouse_position): * w32term.c (w32_mouse_position): * xterm.c (XTmouse_position): Use scroll_bar_above_handle. (x_send_scroll_bar_event, xm_scroll_callback, xg_scroll_callback): Prefer enum and explicit enum members to integers and numeric values. --- src/ChangeLog | 20 +++++++++++++++++ src/keyboard.c | 58 ++++++++++++++++++++----------------------------- src/nsterm.h | 2 +- src/nsterm.m | 5 ++--- src/term.c | 2 +- src/termhooks.h | 31 +++++++++++++++++--------- src/w32inevt.c | 2 +- src/w32term.c | 2 +- src/xterm.c | 19 +++++++++------- 9 files changed, 81 insertions(+), 60 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 0fc4c2b1599..8f312a3ab3e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2014-09-24 Dmitry Antipov + + * termhooks.h (enum scroll_bar_part): Begin from 0 to allow... + (struct input_event): ...unsigned bitfields. Likewise for + `event_kind' member. Prefer unsigned for `code' and 'modifiers'. + Use `timestamp' for HELP_EVENT position. Add compile-time assert. + * keyboard.c (gen_help_event, kbd_buffer_store_help_event) + (kbd_buffer_get_event): Adjust users. + (scroll_bar_parts): Add Qnil to match scroll_bar_nowhere. + (make_scroll_bar_position): New function, refactored out of... + (make_lispy_event): ...adjusted user. + * nsterm.h (EmacsScroller): Use enum for `last_hit_part' member. + * nsterm.m (ns_mouse_position, mouseUp): + * term.c (term_mouse_position): + * w32inevt.c (w32_console_mouse_position): + * w32term.c (w32_mouse_position): + * xterm.c (XTmouse_position): Use scroll_bar_above_handle. + (x_send_scroll_bar_event, xm_scroll_callback, xg_scroll_callback): + Prefer enum and explicit enum members to integers and numeric values. + 2014-09-24 Paul Eggert Fix some slow uses and misuses of strcat. diff --git a/src/keyboard.c b/src/keyboard.c index f79c1c94167..7625586650f 100644 --- a/src/keyboard.c +++ b/src/keyboard.c @@ -3747,14 +3747,12 @@ gen_help_event (Lisp_Object help, Lisp_Object frame, Lisp_Object window, { struct input_event event; - EVENT_INIT (event); - event.kind = HELP_EVENT; event.frame_or_window = frame; event.arg = object; event.x = WINDOWP (window) ? window : frame; event.y = help; - event.code = pos; + event.timestamp = pos; kbd_buffer_store_event (&event); } @@ -3771,7 +3769,7 @@ kbd_buffer_store_help_event (Lisp_Object frame, Lisp_Object help) event.arg = Qnil; event.x = Qnil; event.y = help; - event.code = 0; + event.timestamp = 0; kbd_buffer_store_event (&event); } @@ -4086,7 +4084,7 @@ kbd_buffer_get_event (KBOARD **kbp, frame = event->frame_or_window; object = event->arg; - position = make_number (event->code); + position = make_number (event->timestamp); window = event->x; help = event->y; clear_event (event); @@ -5201,9 +5199,11 @@ static Lisp_Object Qleftmost, Qrightmost; static Lisp_Object Qend_scroll; static Lisp_Object Qratio; -/* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */ +/* An array of scroll bar parts, indexed by an enum scroll_bar_part value. + Note that Qnil corresponds to scroll_bar_nowhere and should not appear + in Lisp events. */ static Lisp_Object *const scroll_bar_parts[] = { - &Qabove_handle, &Qhandle, &Qbelow_handle, + &Qnil, &Qabove_handle, &Qhandle, &Qbelow_handle, &Qup, &Qdown, &Qtop, &Qbottom, &Qend_scroll, &Qratio, &Qbefore_handle, &Qhorizontal_handle, &Qafter_handle, &Qleft, &Qright, &Qleftmost, &Qrightmost, &Qend_scroll, &Qratio @@ -5450,6 +5450,16 @@ toolkit_menubar_in_use (struct frame *f) #endif } +/* Build the part of Lisp event which represents scroll bar state from + EV. TYPE is one of Qvertical_scroll_bar or Qhorizontal_scroll_bar. */ + +static Lisp_Object +make_scroll_bar_position (struct input_event *ev, Lisp_Object type) +{ + return list5 (ev->frame_or_window, type, Fcons (ev->x, ev->y), + make_number (ev->timestamp), *scroll_bar_parts[ev->part]); +} + /* Given a struct input_event, build the lisp event which represents it. If EVENT is 0, build a mouse movement event from the mouse movement buffer, which should have a movement event in it. @@ -5667,20 +5677,8 @@ make_lispy_event (struct input_event *event) } #ifndef USE_TOOLKIT_SCROLL_BARS else - { - /* It's a scrollbar click. */ - Lisp_Object window; - Lisp_Object portion_whole; - Lisp_Object part; - - window = event->frame_or_window; - portion_whole = Fcons (event->x, event->y); - part = *scroll_bar_parts[(int) event->part]; - - position = list5 (window, Qvertical_scroll_bar, - portion_whole, make_number (event->timestamp), - part); - } + /* It's a scrollbar click. */ + position = make_scroll_bar_position (event, Qvertical_scroll_bar); #endif /* not USE_TOOLKIT_SCROLL_BARS */ if (button >= ASIZE (button_down_location)) @@ -5957,14 +5955,9 @@ make_lispy_event (struct input_event *event) case SCROLL_BAR_CLICK_EVENT: { - Lisp_Object position, head, window, portion_whole, part; + Lisp_Object position, head; - window = event->frame_or_window; - portion_whole = Fcons (event->x, event->y); - part = *scroll_bar_parts[(int) event->part]; - - position = list5 (window, Qvertical_scroll_bar, portion_whole, - make_number (event->timestamp), part); + position = make_scroll_bar_position (event, Qvertical_scroll_bar); /* Always treat scroll bar events as clicks. */ event->modifiers |= click_modifier; @@ -5987,14 +5980,9 @@ make_lispy_event (struct input_event *event) case HORIZONTAL_SCROLL_BAR_CLICK_EVENT: { - Lisp_Object position, head, window, portion_whole, part; - - window = event->frame_or_window; - portion_whole = Fcons (event->x, event->y); - part = *scroll_bar_parts[(int) event->part]; + Lisp_Object position, head; - position = list5 (window, Qhorizontal_scroll_bar, portion_whole, - make_number (event->timestamp), part); + position = make_scroll_bar_position (event, Qhorizontal_scroll_bar); /* Always treat scroll bar events as clicks. */ event->modifiers |= click_modifier; diff --git a/src/nsterm.h b/src/nsterm.h index 00a0b54add9..e223281de28 100644 --- a/src/nsterm.h +++ b/src/nsterm.h @@ -401,7 +401,7 @@ typedef float EmacsCGFloat; CGFloat last_mouse_offset; float min_portion; int pixel_height; - int last_hit_part; + enum scroll_bar_part last_hit_part; BOOL condemned; diff --git a/src/nsterm.m b/src/nsterm.m index 5f86369a8c4..d40541f5125 100644 --- a/src/nsterm.m +++ b/src/nsterm.m @@ -1930,10 +1930,9 @@ ns_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, position = [view convertPoint: position fromView: nil]; remember_mouse_glyph (f, position.x, position.y, &dpyinfo->last_mouse_glyph); -/*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */ if (bar_window) *bar_window = Qnil; - if (part) *part = 0; /*scroll_bar_handle; */ + if (part) *part = scroll_bar_above_handle; if (x) XSETINT (*x, lrint (position.x)); if (y) XSETINT (*y, lrint (position.y)); @@ -7505,7 +7504,7 @@ if (cols > 0 && rows > 0) [scroll_repeat_entry release]; scroll_repeat_entry = nil; } - last_hit_part = 0; + last_hit_part = scroll_bar_above_handle; } diff --git a/src/term.c b/src/term.c index 0a1b3dd13e2..572435bdd1a 100644 --- a/src/term.c +++ b/src/term.c @@ -2540,7 +2540,7 @@ term_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, (*fp)->mouse_moved = 0; *bar_window = Qnil; - *part = 0; + *part = scroll_bar_above_handle; XSETINT (*x, last_mouse_x); XSETINT (*y, last_mouse_y); diff --git a/src/termhooks.h b/src/termhooks.h index 04104eb41e9..6412f0da6ca 100644 --- a/src/termhooks.h +++ b/src/termhooks.h @@ -28,7 +28,7 @@ along with GNU Emacs. If not, see . */ INLINE_HEADER_BEGIN enum scroll_bar_part { - scroll_bar_nowhere = -1, + scroll_bar_nowhere, scroll_bar_above_handle, scroll_bar_handle, scroll_bar_below_handle, @@ -255,31 +255,42 @@ enum event_kind struct input_event { /* What kind of event was this? */ - enum event_kind kind; + ENUM_BF (event_kind) kind : 16; + + /* Used in scroll back click events. */ + ENUM_BF (scroll_bar_part) part : 16; /* For an ASCII_KEYSTROKE_EVENT and MULTIBYTE_CHAR_KEYSTROKE_EVENT, this is the character. For a NON_ASCII_KEYSTROKE_EVENT, this is the keysym code. - For a mouse event, this is the button number. - For a HELP_EVENT, this is the position within the object - (stored in ARG below) where the help was found. */ - ptrdiff_t code; - enum scroll_bar_part part; + For a mouse event, this is the button number. */ + unsigned code; - int modifiers; /* See enum below for interpretation. */ + /* See enum below for interpretation. */ + unsigned modifiers; + /* One would prefer C integers, but HELP_EVENT uses these to + record frame or window object and a help form, respectively. */ Lisp_Object x, y; + + /* Usually a time as reported by window system-specific event loop. + For a HELP_EVENT, this is the position within the object (stored + in ARG below) where the help was found. */ Time timestamp; /* This field is copied into a vector while the event is in the queue, so that garbage collections won't kill it. */ Lisp_Object frame_or_window; - /* Additional event argument. This is used for TOOL_BAR_EVENTs and - HELP_EVENTs and avoids calling Fcons during signal handling. */ + /* This additional argument is used in attempt to avoid extra consing + when building events. Unfortunately some events have to pass much + more data than it's reasonable to pack directly into this structure. */ Lisp_Object arg; }; +/* To make sure we don't break HELP_EVENT. */ +verify (sizeof (Time) == sizeof (ptrdiff_t)); + #define EVENT_INIT(event) memset (&(event), 0, sizeof (struct input_event)) /* Bits in the modifiers member of the input_event structure. diff --git a/src/w32inevt.c b/src/w32inevt.c index ccb5a900a16..3dcae11cc48 100644 --- a/src/w32inevt.c +++ b/src/w32inevt.c @@ -411,7 +411,7 @@ w32_console_mouse_position (struct frame **f, *f = get_frame (); *bar_window = Qnil; - *part = 0; + *part = scroll_bar_above_handle; SELECTED_FRAME ()->mouse_moved = 0; XSETINT (*x, movement_pos.X); diff --git a/src/w32term.c b/src/w32term.c index 443f5ece8f0..0e10738e6f9 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -3448,7 +3448,7 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, dpyinfo->last_mouse_glyph_frame = f1; *bar_window = Qnil; - *part = 0; + *part = scroll_bar_above_handle; *fp = f1; XSETINT (*x, pt.x); XSETINT (*y, pt.y); diff --git a/src/xterm.c b/src/xterm.c index e24e86ce412..89a7453b953 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -4157,7 +4157,7 @@ XTmouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, dpyinfo->last_mouse_glyph_frame = f1; *bar_window = Qnil; - *part = 0; + *part = scroll_bar_above_handle; *fp = f1; XSETINT (*x, win_x); XSETINT (*y, win_y); @@ -4250,7 +4250,8 @@ x_window_to_menu_bar (Window window) #ifdef USE_TOOLKIT_SCROLL_BARS -static void x_send_scroll_bar_event (Lisp_Object, int, int, int, bool); +static void x_send_scroll_bar_event (Lisp_Object, enum scroll_bar_part, + int, int, bool); /* Lisp window being scrolled. Set when starting to interact with a toolkit scroll bar, reset to nil when ending the interaction. */ @@ -4371,7 +4372,8 @@ xt_horizontal_action_hook (Widget widget, XtPointer client_data, String action_n amount to scroll of a whole of WHOLE. */ static void -x_send_scroll_bar_event (Lisp_Object window, int part, int portion, int whole, bool horizontal) +x_send_scroll_bar_event (Lisp_Object window, enum scroll_bar_part part, + int portion, int whole, bool horizontal) { XEvent event; XClientMessageEvent *ev = &event.xclient; @@ -4504,8 +4506,8 @@ xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data) { struct scroll_bar *bar = client_data; XmScrollBarCallbackStruct *cs = call_data; - int part = -1, whole = 0, portion = 0; - int horizontal = bar->horizontal; + enum scroll_bar_part part = scroll_bar_nowhere; + int horizontal = bar->horizontal, whole = 0, portion = 0; switch (cs->reason) { @@ -4569,7 +4571,7 @@ xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data) break; }; - if (part >= 0) + if (part != scroll_bar_nowhere) { window_being_scrolled = bar->window; x_send_scroll_bar_event (bar->window, part, portion, whole, bar->horizontal); @@ -4587,8 +4589,9 @@ xg_scroll_callback (GtkRange *range, gdouble value, gpointer user_data) { + int whole = 0, portion = 0; struct scroll_bar *bar = user_data; - int part = -1, whole = 0, portion = 0; + enum scroll_bar_part part = scroll_bar_nowhere; GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range)); struct frame *f = g_object_get_data (G_OBJECT (range), XG_FRAME_DATA); @@ -4641,7 +4644,7 @@ xg_scroll_callback (GtkRange *range, break; } - if (part >= 0) + if (part != scroll_bar_nowhere) { window_being_scrolled = bar->window; x_send_scroll_bar_event (bar->window, part, portion, whole, bar->horizontal); -- 2.39.5