aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorDmitry Antipov2014-09-24 11:17:51 +0400
committerDmitry Antipov2014-09-24 11:17:51 +0400
commit4b930ccbb4fc4b848f318e09eddd172c2acf9b9b (patch)
tree349f033caa6278c11cae123b8d2f949ec7e3df10 /src
parent4620e6bccd98625208d8be4d960d24119a20594f (diff)
downloademacs-4b930ccbb4fc4b848f318e09eddd172c2acf9b9b.tar.gz
emacs-4b930ccbb4fc4b848f318e09eddd172c2acf9b9b.zip
* 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.
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog20
-rw-r--r--src/keyboard.c58
-rw-r--r--src/nsterm.h2
-rw-r--r--src/nsterm.m5
-rw-r--r--src/term.c2
-rw-r--r--src/termhooks.h31
-rw-r--r--src/w32inevt.c2
-rw-r--r--src/w32term.c2
-rw-r--r--src/xterm.c19
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 @@
12014-09-24 Dmitry Antipov <dmantipov@yandex.ru>
2
3 * termhooks.h (enum scroll_bar_part): Begin from 0 to allow...
4 (struct input_event): ...unsigned bitfields. Likewise for
5 `event_kind' member. Prefer unsigned for `code' and 'modifiers'.
6 Use `timestamp' for HELP_EVENT position. Add compile-time assert.
7 * keyboard.c (gen_help_event, kbd_buffer_store_help_event)
8 (kbd_buffer_get_event): Adjust users.
9 (scroll_bar_parts): Add Qnil to match scroll_bar_nowhere.
10 (make_scroll_bar_position): New function, refactored out of...
11 (make_lispy_event): ...adjusted user.
12 * nsterm.h (EmacsScroller): Use enum for `last_hit_part' member.
13 * nsterm.m (ns_mouse_position, mouseUp):
14 * term.c (term_mouse_position):
15 * w32inevt.c (w32_console_mouse_position):
16 * w32term.c (w32_mouse_position):
17 * xterm.c (XTmouse_position): Use scroll_bar_above_handle.
18 (x_send_scroll_bar_event, xm_scroll_callback, xg_scroll_callback):
19 Prefer enum and explicit enum members to integers and numeric values.
20
12014-09-24 Paul Eggert <eggert@cs.ucla.edu> 212014-09-24 Paul Eggert <eggert@cs.ucla.edu>
2 22
3 Fix some slow uses and misuses of strcat. 23 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,
3747{ 3747{
3748 struct input_event event; 3748 struct input_event event;
3749 3749
3750 EVENT_INIT (event);
3751
3752 event.kind = HELP_EVENT; 3750 event.kind = HELP_EVENT;
3753 event.frame_or_window = frame; 3751 event.frame_or_window = frame;
3754 event.arg = object; 3752 event.arg = object;
3755 event.x = WINDOWP (window) ? window : frame; 3753 event.x = WINDOWP (window) ? window : frame;
3756 event.y = help; 3754 event.y = help;
3757 event.code = pos; 3755 event.timestamp = pos;
3758 kbd_buffer_store_event (&event); 3756 kbd_buffer_store_event (&event);
3759} 3757}
3760 3758
@@ -3771,7 +3769,7 @@ kbd_buffer_store_help_event (Lisp_Object frame, Lisp_Object help)
3771 event.arg = Qnil; 3769 event.arg = Qnil;
3772 event.x = Qnil; 3770 event.x = Qnil;
3773 event.y = help; 3771 event.y = help;
3774 event.code = 0; 3772 event.timestamp = 0;
3775 kbd_buffer_store_event (&event); 3773 kbd_buffer_store_event (&event);
3776} 3774}
3777 3775
@@ -4086,7 +4084,7 @@ kbd_buffer_get_event (KBOARD **kbp,
4086 4084
4087 frame = event->frame_or_window; 4085 frame = event->frame_or_window;
4088 object = event->arg; 4086 object = event->arg;
4089 position = make_number (event->code); 4087 position = make_number (event->timestamp);
4090 window = event->x; 4088 window = event->x;
4091 help = event->y; 4089 help = event->y;
4092 clear_event (event); 4090 clear_event (event);
@@ -5201,9 +5199,11 @@ static Lisp_Object Qleftmost, Qrightmost;
5201static Lisp_Object Qend_scroll; 5199static Lisp_Object Qend_scroll;
5202static Lisp_Object Qratio; 5200static Lisp_Object Qratio;
5203 5201
5204/* An array of scroll bar parts, indexed by an enum scroll_bar_part value. */ 5202/* An array of scroll bar parts, indexed by an enum scroll_bar_part value.
5203 Note that Qnil corresponds to scroll_bar_nowhere and should not appear
5204 in Lisp events. */
5205static Lisp_Object *const scroll_bar_parts[] = { 5205static Lisp_Object *const scroll_bar_parts[] = {
5206 &Qabove_handle, &Qhandle, &Qbelow_handle, 5206 &Qnil, &Qabove_handle, &Qhandle, &Qbelow_handle,
5207 &Qup, &Qdown, &Qtop, &Qbottom, &Qend_scroll, &Qratio, 5207 &Qup, &Qdown, &Qtop, &Qbottom, &Qend_scroll, &Qratio,
5208 &Qbefore_handle, &Qhorizontal_handle, &Qafter_handle, 5208 &Qbefore_handle, &Qhorizontal_handle, &Qafter_handle,
5209 &Qleft, &Qright, &Qleftmost, &Qrightmost, &Qend_scroll, &Qratio 5209 &Qleft, &Qright, &Qleftmost, &Qrightmost, &Qend_scroll, &Qratio
@@ -5450,6 +5450,16 @@ toolkit_menubar_in_use (struct frame *f)
5450#endif 5450#endif
5451} 5451}
5452 5452
5453/* Build the part of Lisp event which represents scroll bar state from
5454 EV. TYPE is one of Qvertical_scroll_bar or Qhorizontal_scroll_bar. */
5455
5456static Lisp_Object
5457make_scroll_bar_position (struct input_event *ev, Lisp_Object type)
5458{
5459 return list5 (ev->frame_or_window, type, Fcons (ev->x, ev->y),
5460 make_number (ev->timestamp), *scroll_bar_parts[ev->part]);
5461}
5462
5453/* Given a struct input_event, build the lisp event which represents 5463/* Given a struct input_event, build the lisp event which represents
5454 it. If EVENT is 0, build a mouse movement event from the mouse 5464 it. If EVENT is 0, build a mouse movement event from the mouse
5455 movement buffer, which should have a movement event in it. 5465 movement buffer, which should have a movement event in it.
@@ -5667,20 +5677,8 @@ make_lispy_event (struct input_event *event)
5667 } 5677 }
5668#ifndef USE_TOOLKIT_SCROLL_BARS 5678#ifndef USE_TOOLKIT_SCROLL_BARS
5669 else 5679 else
5670 { 5680 /* It's a scrollbar click. */
5671 /* It's a scrollbar click. */ 5681 position = make_scroll_bar_position (event, Qvertical_scroll_bar);
5672 Lisp_Object window;
5673 Lisp_Object portion_whole;
5674 Lisp_Object part;
5675
5676 window = event->frame_or_window;
5677 portion_whole = Fcons (event->x, event->y);
5678 part = *scroll_bar_parts[(int) event->part];
5679
5680 position = list5 (window, Qvertical_scroll_bar,
5681 portion_whole, make_number (event->timestamp),
5682 part);
5683 }
5684#endif /* not USE_TOOLKIT_SCROLL_BARS */ 5682#endif /* not USE_TOOLKIT_SCROLL_BARS */
5685 5683
5686 if (button >= ASIZE (button_down_location)) 5684 if (button >= ASIZE (button_down_location))
@@ -5957,14 +5955,9 @@ make_lispy_event (struct input_event *event)
5957 5955
5958 case SCROLL_BAR_CLICK_EVENT: 5956 case SCROLL_BAR_CLICK_EVENT:
5959 { 5957 {
5960 Lisp_Object position, head, window, portion_whole, part; 5958 Lisp_Object position, head;
5961 5959
5962 window = event->frame_or_window; 5960 position = make_scroll_bar_position (event, Qvertical_scroll_bar);
5963 portion_whole = Fcons (event->x, event->y);
5964 part = *scroll_bar_parts[(int) event->part];
5965
5966 position = list5 (window, Qvertical_scroll_bar, portion_whole,
5967 make_number (event->timestamp), part);
5968 5961
5969 /* Always treat scroll bar events as clicks. */ 5962 /* Always treat scroll bar events as clicks. */
5970 event->modifiers |= click_modifier; 5963 event->modifiers |= click_modifier;
@@ -5987,14 +5980,9 @@ make_lispy_event (struct input_event *event)
5987 5980
5988 case HORIZONTAL_SCROLL_BAR_CLICK_EVENT: 5981 case HORIZONTAL_SCROLL_BAR_CLICK_EVENT:
5989 { 5982 {
5990 Lisp_Object position, head, window, portion_whole, part; 5983 Lisp_Object position, head;
5991
5992 window = event->frame_or_window;
5993 portion_whole = Fcons (event->x, event->y);
5994 part = *scroll_bar_parts[(int) event->part];
5995 5984
5996 position = list5 (window, Qhorizontal_scroll_bar, portion_whole, 5985 position = make_scroll_bar_position (event, Qhorizontal_scroll_bar);
5997 make_number (event->timestamp), part);
5998 5986
5999 /* Always treat scroll bar events as clicks. */ 5987 /* Always treat scroll bar events as clicks. */
6000 event->modifiers |= click_modifier; 5988 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;
401 CGFloat last_mouse_offset; 401 CGFloat last_mouse_offset;
402 float min_portion; 402 float min_portion;
403 int pixel_height; 403 int pixel_height;
404 int last_hit_part; 404 enum scroll_bar_part last_hit_part;
405 405
406 BOOL condemned; 406 BOOL condemned;
407 407
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,
1930 position = [view convertPoint: position fromView: nil]; 1930 position = [view convertPoint: position fromView: nil];
1931 remember_mouse_glyph (f, position.x, position.y, 1931 remember_mouse_glyph (f, position.x, position.y,
1932 &dpyinfo->last_mouse_glyph); 1932 &dpyinfo->last_mouse_glyph);
1933/*fprintf (stderr, "ns_mouse_position: %.0f, %.0f\n", position.x, position.y); */
1934 1933
1935 if (bar_window) *bar_window = Qnil; 1934 if (bar_window) *bar_window = Qnil;
1936 if (part) *part = 0; /*scroll_bar_handle; */ 1935 if (part) *part = scroll_bar_above_handle;
1937 1936
1938 if (x) XSETINT (*x, lrint (position.x)); 1937 if (x) XSETINT (*x, lrint (position.x));
1939 if (y) XSETINT (*y, lrint (position.y)); 1938 if (y) XSETINT (*y, lrint (position.y));
@@ -7505,7 +7504,7 @@ if (cols > 0 && rows > 0)
7505 [scroll_repeat_entry release]; 7504 [scroll_repeat_entry release];
7506 scroll_repeat_entry = nil; 7505 scroll_repeat_entry = nil;
7507 } 7506 }
7508 last_hit_part = 0; 7507 last_hit_part = scroll_bar_above_handle;
7509} 7508}
7510 7509
7511 7510
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,
2540 (*fp)->mouse_moved = 0; 2540 (*fp)->mouse_moved = 0;
2541 2541
2542 *bar_window = Qnil; 2542 *bar_window = Qnil;
2543 *part = 0; 2543 *part = scroll_bar_above_handle;
2544 2544
2545 XSETINT (*x, last_mouse_x); 2545 XSETINT (*x, last_mouse_x);
2546 XSETINT (*y, last_mouse_y); 2546 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 <http://www.gnu.org/licenses/>. */
28INLINE_HEADER_BEGIN 28INLINE_HEADER_BEGIN
29 29
30enum scroll_bar_part { 30enum scroll_bar_part {
31 scroll_bar_nowhere = -1, 31 scroll_bar_nowhere,
32 scroll_bar_above_handle, 32 scroll_bar_above_handle,
33 scroll_bar_handle, 33 scroll_bar_handle,
34 scroll_bar_below_handle, 34 scroll_bar_below_handle,
@@ -255,31 +255,42 @@ enum event_kind
255struct input_event 255struct input_event
256{ 256{
257 /* What kind of event was this? */ 257 /* What kind of event was this? */
258 enum event_kind kind; 258 ENUM_BF (event_kind) kind : 16;
259
260 /* Used in scroll back click events. */
261 ENUM_BF (scroll_bar_part) part : 16;
259 262
260 /* For an ASCII_KEYSTROKE_EVENT and MULTIBYTE_CHAR_KEYSTROKE_EVENT, 263 /* For an ASCII_KEYSTROKE_EVENT and MULTIBYTE_CHAR_KEYSTROKE_EVENT,
261 this is the character. 264 this is the character.
262 For a NON_ASCII_KEYSTROKE_EVENT, this is the keysym code. 265 For a NON_ASCII_KEYSTROKE_EVENT, this is the keysym code.
263 For a mouse event, this is the button number. 266 For a mouse event, this is the button number. */
264 For a HELP_EVENT, this is the position within the object 267 unsigned code;
265 (stored in ARG below) where the help was found. */
266 ptrdiff_t code;
267 enum scroll_bar_part part;
268 268
269 int modifiers; /* See enum below for interpretation. */ 269 /* See enum below for interpretation. */
270 unsigned modifiers;
270 271
272 /* One would prefer C integers, but HELP_EVENT uses these to
273 record frame or window object and a help form, respectively. */
271 Lisp_Object x, y; 274 Lisp_Object x, y;
275
276 /* Usually a time as reported by window system-specific event loop.
277 For a HELP_EVENT, this is the position within the object (stored
278 in ARG below) where the help was found. */
272 Time timestamp; 279 Time timestamp;
273 280
274 /* This field is copied into a vector while the event is in 281 /* This field is copied into a vector while the event is in
275 the queue, so that garbage collections won't kill it. */ 282 the queue, so that garbage collections won't kill it. */
276 Lisp_Object frame_or_window; 283 Lisp_Object frame_or_window;
277 284
278 /* Additional event argument. This is used for TOOL_BAR_EVENTs and 285 /* This additional argument is used in attempt to avoid extra consing
279 HELP_EVENTs and avoids calling Fcons during signal handling. */ 286 when building events. Unfortunately some events have to pass much
287 more data than it's reasonable to pack directly into this structure. */
280 Lisp_Object arg; 288 Lisp_Object arg;
281}; 289};
282 290
291/* To make sure we don't break HELP_EVENT. */
292verify (sizeof (Time) == sizeof (ptrdiff_t));
293
283#define EVENT_INIT(event) memset (&(event), 0, sizeof (struct input_event)) 294#define EVENT_INIT(event) memset (&(event), 0, sizeof (struct input_event))
284 295
285/* Bits in the modifiers member of the input_event structure. 296/* 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,
411 411
412 *f = get_frame (); 412 *f = get_frame ();
413 *bar_window = Qnil; 413 *bar_window = Qnil;
414 *part = 0; 414 *part = scroll_bar_above_handle;
415 SELECTED_FRAME ()->mouse_moved = 0; 415 SELECTED_FRAME ()->mouse_moved = 0;
416 416
417 XSETINT (*x, movement_pos.X); 417 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,
3448 dpyinfo->last_mouse_glyph_frame = f1; 3448 dpyinfo->last_mouse_glyph_frame = f1;
3449 3449
3450 *bar_window = Qnil; 3450 *bar_window = Qnil;
3451 *part = 0; 3451 *part = scroll_bar_above_handle;
3452 *fp = f1; 3452 *fp = f1;
3453 XSETINT (*x, pt.x); 3453 XSETINT (*x, pt.x);
3454 XSETINT (*y, pt.y); 3454 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,
4157 dpyinfo->last_mouse_glyph_frame = f1; 4157 dpyinfo->last_mouse_glyph_frame = f1;
4158 4158
4159 *bar_window = Qnil; 4159 *bar_window = Qnil;
4160 *part = 0; 4160 *part = scroll_bar_above_handle;
4161 *fp = f1; 4161 *fp = f1;
4162 XSETINT (*x, win_x); 4162 XSETINT (*x, win_x);
4163 XSETINT (*y, win_y); 4163 XSETINT (*y, win_y);
@@ -4250,7 +4250,8 @@ x_window_to_menu_bar (Window window)
4250 4250
4251#ifdef USE_TOOLKIT_SCROLL_BARS 4251#ifdef USE_TOOLKIT_SCROLL_BARS
4252 4252
4253static void x_send_scroll_bar_event (Lisp_Object, int, int, int, bool); 4253static void x_send_scroll_bar_event (Lisp_Object, enum scroll_bar_part,
4254 int, int, bool);
4254 4255
4255/* Lisp window being scrolled. Set when starting to interact with 4256/* Lisp window being scrolled. Set when starting to interact with
4256 a toolkit scroll bar, reset to nil when ending the interaction. */ 4257 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
4371 amount to scroll of a whole of WHOLE. */ 4372 amount to scroll of a whole of WHOLE. */
4372 4373
4373static void 4374static void
4374x_send_scroll_bar_event (Lisp_Object window, int part, int portion, int whole, bool horizontal) 4375x_send_scroll_bar_event (Lisp_Object window, enum scroll_bar_part part,
4376 int portion, int whole, bool horizontal)
4375{ 4377{
4376 XEvent event; 4378 XEvent event;
4377 XClientMessageEvent *ev = &event.xclient; 4379 XClientMessageEvent *ev = &event.xclient;
@@ -4504,8 +4506,8 @@ xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4504{ 4506{
4505 struct scroll_bar *bar = client_data; 4507 struct scroll_bar *bar = client_data;
4506 XmScrollBarCallbackStruct *cs = call_data; 4508 XmScrollBarCallbackStruct *cs = call_data;
4507 int part = -1, whole = 0, portion = 0; 4509 enum scroll_bar_part part = scroll_bar_nowhere;
4508 int horizontal = bar->horizontal; 4510 int horizontal = bar->horizontal, whole = 0, portion = 0;
4509 4511
4510 switch (cs->reason) 4512 switch (cs->reason)
4511 { 4513 {
@@ -4569,7 +4571,7 @@ xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4569 break; 4571 break;
4570 }; 4572 };
4571 4573
4572 if (part >= 0) 4574 if (part != scroll_bar_nowhere)
4573 { 4575 {
4574 window_being_scrolled = bar->window; 4576 window_being_scrolled = bar->window;
4575 x_send_scroll_bar_event (bar->window, part, portion, whole, bar->horizontal); 4577 x_send_scroll_bar_event (bar->window, part, portion, whole, bar->horizontal);
@@ -4587,8 +4589,9 @@ xg_scroll_callback (GtkRange *range,
4587 gdouble value, 4589 gdouble value,
4588 gpointer user_data) 4590 gpointer user_data)
4589{ 4591{
4592 int whole = 0, portion = 0;
4590 struct scroll_bar *bar = user_data; 4593 struct scroll_bar *bar = user_data;
4591 int part = -1, whole = 0, portion = 0; 4594 enum scroll_bar_part part = scroll_bar_nowhere;
4592 GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range)); 4595 GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range));
4593 struct frame *f = g_object_get_data (G_OBJECT (range), XG_FRAME_DATA); 4596 struct frame *f = g_object_get_data (G_OBJECT (range), XG_FRAME_DATA);
4594 4597
@@ -4641,7 +4644,7 @@ xg_scroll_callback (GtkRange *range,
4641 break; 4644 break;
4642 } 4645 }
4643 4646
4644 if (part >= 0) 4647 if (part != scroll_bar_nowhere)
4645 { 4648 {
4646 window_being_scrolled = bar->window; 4649 window_being_scrolled = bar->window;
4647 x_send_scroll_bar_event (bar->window, part, portion, whole, bar->horizontal); 4650 x_send_scroll_bar_event (bar->window, part, portion, whole, bar->horizontal);