emacs-diffs
[Top][All Lists]
Advanced

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

[Emacs-diffs] trunk r117932: * termhooks.h (enum scroll_bar_part): Begin


From: Dmitry Antipov
Subject: [Emacs-diffs] trunk r117932: * termhooks.h (enum scroll_bar_part): Begin from 0 to allow...
Date: Wed, 24 Sep 2014 07:18:03 +0000
User-agent: Bazaar (2.6b2)

------------------------------------------------------------
revno: 117932
revision-id: address@hidden
parent: address@hidden
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Wed 2014-09-24 11:17:51 +0400
message:
  * 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.
modified:
  src/ChangeLog                  changelog-20091113204419-o5vbwnq5f7feedwu-1438
  src/keyboard.c                 keyboard.c-20091113204419-o5vbwnq5f7feedwu-449
  src/nsterm.h                   nsterm.h-20091113204419-o5vbwnq5f7feedwu-8746
  src/nsterm.m                   nsterm.m-20091113204419-o5vbwnq5f7feedwu-8747
  src/term.c                     term.c-20091113204419-o5vbwnq5f7feedwu-220
  src/termhooks.h                termhooks.h-20091113204419-o5vbwnq5f7feedwu-249
  src/w32inevt.c                 w32inevt.c-20091113204419-o5vbwnq5f7feedwu-813
  src/w32term.c                  w32term.c-20091113204419-o5vbwnq5f7feedwu-950
  src/xterm.c                    xterm.c-20091113204419-o5vbwnq5f7feedwu-244
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2014-09-24 04:12:37 +0000
+++ b/src/ChangeLog     2014-09-24 07:17:51 +0000
@@ -1,3 +1,23 @@
+2014-09-24  Dmitry Antipov  <address@hidden>
+
+       * 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  <address@hidden>
 
        Fix some slow uses and misuses of strcat.

=== modified file 'src/keyboard.c'
--- a/src/keyboard.c    2014-09-16 08:20:08 +0000
+++ b/src/keyboard.c    2014-09-24 07:17:51 +0000
@@ -3747,14 +3747,12 @@
 {
   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 @@
   event.arg = Qnil;
   event.x = Qnil;
   event.y = help;
-  event.code = 0;
+  event.timestamp = 0;
   kbd_buffer_store_event (&event);
 }
 
@@ -4086,7 +4084,7 @@
 
          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 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 @@
 #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 @@
          }
 #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 @@
 
     case 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];
-
-       position = list5 (window, Qvertical_scroll_bar, portion_whole,
-                         make_number (event->timestamp), part);
+       Lisp_Object position, head;
+
+       position = make_scroll_bar_position (event, Qvertical_scroll_bar);
 
        /* Always treat scroll bar events as clicks.  */
        event->modifiers |= click_modifier;
@@ -5987,14 +5980,9 @@
 
     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];
-
-       position = list5 (window, Qhorizontal_scroll_bar, portion_whole,
-                         make_number (event->timestamp), part);
+       Lisp_Object position, head;
+
+       position = make_scroll_bar_position (event, Qhorizontal_scroll_bar);
 
        /* Always treat scroll bar events as clicks.  */
        event->modifiers |= click_modifier;

=== modified file 'src/nsterm.h'
--- a/src/nsterm.h      2014-07-27 13:21:30 +0000
+++ b/src/nsterm.h      2014-09-24 07:17:51 +0000
@@ -401,7 +401,7 @@
    CGFloat last_mouse_offset;
    float min_portion;
    int pixel_height;
-   int last_hit_part;
+   enum scroll_bar_part last_hit_part;
 
    BOOL condemned;
 

=== modified file 'src/nsterm.m'
--- a/src/nsterm.m      2014-09-15 00:20:21 +0000
+++ b/src/nsterm.m      2014-09-24 07:17:51 +0000
@@ -1930,10 +1930,9 @@
           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 @@
       [scroll_repeat_entry release];
       scroll_repeat_entry = nil;
     }
-  last_hit_part = 0;
+  last_hit_part = scroll_bar_above_handle;
 }
 
 

=== modified file 'src/term.c'
--- a/src/term.c        2014-09-07 07:04:01 +0000
+++ b/src/term.c        2014-09-24 07:17:51 +0000
@@ -2540,7 +2540,7 @@
   (*fp)->mouse_moved = 0;
 
   *bar_window = Qnil;
-  *part = 0;
+  *part = scroll_bar_above_handle;
 
   XSETINT (*x, last_mouse_x);
   XSETINT (*y, last_mouse_y);

=== modified file 'src/termhooks.h'
--- a/src/termhooks.h   2014-07-27 13:21:30 +0000
+++ b/src/termhooks.h   2014-09-24 07:17:51 +0000
@@ -28,7 +28,7 @@
 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 @@
 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;
-
-  int modifiers;               /* See enum below for interpretation.  */
-
+     For a mouse event, this is the button number.  */
+  unsigned code;
+
+  /* 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.

=== modified file 'src/w32inevt.c'
--- a/src/w32inevt.c    2014-07-27 13:21:30 +0000
+++ b/src/w32inevt.c    2014-09-24 07:17:51 +0000
@@ -411,7 +411,7 @@
 
   *f = get_frame ();
   *bar_window = Qnil;
-  *part = 0;
+  *part = scroll_bar_above_handle;
   SELECTED_FRAME ()->mouse_moved = 0;
 
   XSETINT (*x, movement_pos.X);

=== modified file 'src/w32term.c'
--- a/src/w32term.c     2014-09-22 19:20:45 +0000
+++ b/src/w32term.c     2014-09-24 07:17:51 +0000
@@ -3448,7 +3448,7 @@
            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);

=== modified file 'src/xterm.c'
--- a/src/xterm.c       2014-09-23 17:03:48 +0000
+++ b/src/xterm.c       2014-09-24 07:17:51 +0000
@@ -4157,7 +4157,7 @@
            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 @@
 
 #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 @@
    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 @@
 {
   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 @@
       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 @@
                     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 @@
       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);


reply via email to

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