aboutsummaryrefslogtreecommitdiffstats
path: root/src/xterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xterm.c')
-rw-r--r--src/xterm.c421
1 files changed, 146 insertions, 275 deletions
diff --git a/src/xterm.c b/src/xterm.c
index a486242b8c3..bd990014cea 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -140,16 +140,11 @@ int use_xim = 1;
140int use_xim = 0; /* configure --without-xim */ 140int use_xim = 0; /* configure --without-xim */
141#endif 141#endif
142 142
143
144
145/* Non-zero means that a HELP_EVENT has been generated since Emacs 143/* Non-zero means that a HELP_EVENT has been generated since Emacs
146 start. */ 144 start. */
147 145
148static bool any_help_event_p; 146static bool any_help_event_p;
149 147
150/* Last window where we saw the mouse. Used by mouse-autoselect-window. */
151static Lisp_Object last_window;
152
153/* This is a chain of structures for all the X displays currently in 148/* This is a chain of structures for all the X displays currently in
154 use. */ 149 use. */
155 150
@@ -292,15 +287,11 @@ static void x_set_window_size_1 (struct frame *, int, int, int);
292static void x_raise_frame (struct frame *); 287static void x_raise_frame (struct frame *);
293static void x_lower_frame (struct frame *); 288static void x_lower_frame (struct frame *);
294static const XColor *x_color_cells (Display *, int *); 289static const XColor *x_color_cells (Display *, int *);
295static void x_update_window_end (struct window *, int, int);
296
297static int x_io_error_quitter (Display *); 290static int x_io_error_quitter (Display *);
298static struct terminal *x_create_terminal (struct x_display_info *); 291static struct terminal *x_create_terminal (struct x_display_info *);
299void x_delete_terminal (struct terminal *); 292void x_delete_terminal (struct terminal *);
300static void x_update_end (struct frame *); 293static void x_update_end (struct frame *);
301static void XTframe_up_to_date (struct frame *); 294static void XTframe_up_to_date (struct frame *);
302static void XTset_terminal_modes (struct terminal *);
303static void XTreset_terminal_modes (struct terminal *);
304static void x_clear_frame (struct frame *); 295static void x_clear_frame (struct frame *);
305static _Noreturn void x_ins_del_lines (struct frame *, int, int); 296static _Noreturn void x_ins_del_lines (struct frame *, int, int);
306static void frame_highlight (struct frame *); 297static void frame_highlight (struct frame *);
@@ -316,11 +307,11 @@ static void x_draw_hollow_cursor (struct window *, struct glyph_row *);
316static void x_draw_bar_cursor (struct window *, struct glyph_row *, int, 307static void x_draw_bar_cursor (struct window *, struct glyph_row *, int,
317 enum text_cursor_kinds); 308 enum text_cursor_kinds);
318 309
319static void x_clip_to_row (struct window *, struct glyph_row *, int, GC); 310static void x_clip_to_row (struct window *, struct glyph_row *,
311 enum glyph_row_area, GC);
320static void x_flush (struct frame *f); 312static void x_flush (struct frame *f);
321static void x_update_begin (struct frame *); 313static void x_update_begin (struct frame *);
322static void x_update_window_begin (struct window *); 314static void x_update_window_begin (struct window *);
323static void x_after_update_window_line (struct glyph_row *);
324static struct scroll_bar *x_window_to_scroll_bar (Display *, Window); 315static struct scroll_bar *x_window_to_scroll_bar (Display *, Window);
325static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *, 316static void x_scroll_bar_report_motion (struct frame **, Lisp_Object *,
326 enum scroll_bar_part *, 317 enum scroll_bar_part *,
@@ -554,9 +545,7 @@ x_update_begin (struct frame *f)
554} 545}
555 546
556 547
557/* Start update of window W. Set the global variable updated_window 548/* Start update of window W. */
558 to the window being updated and set output_cursor to the cursor
559 position of W. */
560 549
561static void 550static void
562x_update_window_begin (struct window *w) 551x_update_window_begin (struct window *w)
@@ -564,8 +553,7 @@ x_update_window_begin (struct window *w)
564 struct frame *f = XFRAME (WINDOW_FRAME (w)); 553 struct frame *f = XFRAME (WINDOW_FRAME (w));
565 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f); 554 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
566 555
567 updated_window = w; 556 w->output_cursor = w->cursor;
568 set_output_cursor (&w->cursor);
569 557
570 block_input (); 558 block_input ();
571 559
@@ -601,7 +589,7 @@ x_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
601 f->output_data.x->normal_gc, x, y0, x, y1); 589 f->output_data.x->normal_gc, x, y0, x, y1);
602} 590}
603 591
604/* End update of window W (which is equal to updated_window). 592/* End update of window W.
605 593
606 Draw vertical borders between horizontally adjacent windows, and 594 Draw vertical borders between horizontally adjacent windows, and
607 display W's cursor if CURSOR_ON_P is non-zero. 595 display W's cursor if CURSOR_ON_P is non-zero.
@@ -615,18 +603,17 @@ x_draw_vertical_window_border (struct window *w, int x, int y0, int y1)
615 here. */ 603 here. */
616 604
617static void 605static void
618x_update_window_end (struct window *w, int cursor_on_p, int mouse_face_overwritten_p) 606x_update_window_end (struct window *w, bool cursor_on_p,
607 bool mouse_face_overwritten_p)
619{ 608{
620 Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame));
621
622 if (!w->pseudo_window_p) 609 if (!w->pseudo_window_p)
623 { 610 {
624 block_input (); 611 block_input ();
625 612
626 if (cursor_on_p) 613 if (cursor_on_p)
627 display_and_set_cursor (w, 1, output_cursor.hpos, 614 display_and_set_cursor (w, 1,
628 output_cursor.vpos, 615 w->output_cursor.hpos, w->output_cursor.vpos,
629 output_cursor.x, output_cursor.y); 616 w->output_cursor.x, w->output_cursor.y);
630 617
631 if (draw_window_fringes (w, 1)) 618 if (draw_window_fringes (w, 1))
632 x_draw_vertical_border (w); 619 x_draw_vertical_border (w);
@@ -637,13 +624,7 @@ x_update_window_end (struct window *w, int cursor_on_p, int mouse_face_overwritt
637 /* If a row with mouse-face was overwritten, arrange for 624 /* If a row with mouse-face was overwritten, arrange for
638 XTframe_up_to_date to redisplay the mouse highlight. */ 625 XTframe_up_to_date to redisplay the mouse highlight. */
639 if (mouse_face_overwritten_p) 626 if (mouse_face_overwritten_p)
640 { 627 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w->frame)));
641 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
642 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
643 hlinfo->mouse_face_window = Qnil;
644 }
645
646 updated_window = NULL;
647} 628}
648 629
649 630
@@ -664,9 +645,8 @@ x_update_end (struct frame *f)
664} 645}
665 646
666 647
667/* This function is called from various places in xdisp.c whenever a 648/* This function is called from various places in xdisp.c
668 complete update has been performed. The global variable 649 whenever a complete update has been performed. */
669 updated_window is not available here. */
670 650
671static void 651static void
672XTframe_up_to_date (struct frame *f) 652XTframe_up_to_date (struct frame *f)
@@ -678,15 +658,13 @@ XTframe_up_to_date (struct frame *f)
678 658
679/* Draw truncation mark bitmaps, continuation mark bitmaps, overlay 659/* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
680 arrow bitmaps, or clear the fringes if no bitmaps are required 660 arrow bitmaps, or clear the fringes if no bitmaps are required
681 before DESIRED_ROW is made current. The window being updated is 661 before DESIRED_ROW is made current. This function is called from
682 found in updated_window. This function It is called from
683 update_window_line only if it is known that there are differences 662 update_window_line only if it is known that there are differences
684 between bitmaps to be drawn between current row and DESIRED_ROW. */ 663 between bitmaps to be drawn between current row and DESIRED_ROW. */
685 664
686static void 665static void
687x_after_update_window_line (struct glyph_row *desired_row) 666x_after_update_window_line (struct window *w, struct glyph_row *desired_row)
688{ 667{
689 struct window *w = updated_window;
690 struct frame *f; 668 struct frame *f;
691 int width, height; 669 int width, height;
692 670
@@ -697,7 +675,7 @@ x_after_update_window_line (struct glyph_row *desired_row)
697 675
698 /* When a window has disappeared, make sure that no rest of 676 /* When a window has disappeared, make sure that no rest of
699 full-width rows stays visible in the internal border. Could 677 full-width rows stays visible in the internal border. Could
700 check here if updated_window is the leftmost/rightmost window, 678 check here if updated window is the leftmost/rightmost window,
701 but I guess it's not worth doing since vertically split windows 679 but I guess it's not worth doing since vertically split windows
702 are almost never used, internal border is rarely set, and the 680 are almost never used, internal border is rarely set, and the
703 overhead is very small. */ 681 overhead is very small. */
@@ -713,10 +691,10 @@ x_after_update_window_line (struct glyph_row *desired_row)
713 691
714 block_input (); 692 block_input ();
715 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 693 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
716 0, y, width, height, False); 694 0, y, width, height);
717 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 695 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
718 FRAME_PIXEL_WIDTH (f) - width, 696 FRAME_PIXEL_WIDTH (f) - width,
719 y, width, height, False); 697 y, width, height);
720 unblock_input (); 698 unblock_input ();
721 } 699 }
722} 700}
@@ -731,7 +709,7 @@ x_draw_fringe_bitmap (struct window *w, struct glyph_row *row, struct draw_fring
731 struct face *face = p->face; 709 struct face *face = p->face;
732 710
733 /* Must clip because of partially visible lines. */ 711 /* Must clip because of partially visible lines. */
734 x_clip_to_row (w, row, -1, gc); 712 x_clip_to_row (w, row, ANY_AREA, gc);
735 713
736 if (!p->overlay_p) 714 if (!p->overlay_p)
737 { 715 {
@@ -848,27 +826,6 @@ x_draw_fringe_bitmap (struct window *w, struct glyph_row *row, struct draw_fring
848 XSetClipMask (display, gc, None); 826 XSetClipMask (display, gc, None);
849} 827}
850 828
851
852
853/* This is called when starting Emacs and when restarting after
854 suspend. When starting Emacs, no X window is mapped. And nothing
855 must be done to Emacs's own window if it is suspended (though that
856 rarely happens). */
857
858static void
859XTset_terminal_modes (struct terminal *terminal)
860{
861}
862
863/* This is called when exiting or suspending Emacs. Exiting will make
864 the X-windows go away, and suspending requires no action. */
865
866static void
867XTreset_terminal_modes (struct terminal *terminal)
868{
869}
870
871
872/*********************************************************************** 829/***********************************************************************
873 Glyph display 830 Glyph display
874 ***********************************************************************/ 831 ***********************************************************************/
@@ -1374,7 +1331,7 @@ x_draw_glyphless_glyph_string_foreground (struct glyph_string *s)
1374 } 1331 }
1375 else if (glyph->u.glyphless.method == GLYPHLESS_DISPLAY_HEX_CODE) 1332 else if (glyph->u.glyphless.method == GLYPHLESS_DISPLAY_HEX_CODE)
1376 { 1333 {
1377 sprintf ((char *) buf, "%0*X", 1334 sprintf (buf, "%0*X",
1378 glyph->u.glyphless.ch < 0x10000 ? 4 : 6, 1335 glyph->u.glyphless.ch < 0x10000 ? 4 : 6,
1379 glyph->u.glyphless.ch); 1336 glyph->u.glyphless.ch);
1380 str = buf; 1337 str = buf;
@@ -2983,10 +2940,10 @@ x_delete_glyphs (struct frame *f, register int n)
2983 If they are <= 0, this is probably an error. */ 2940 If they are <= 0, this is probably an error. */
2984 2941
2985void 2942void
2986x_clear_area (Display *dpy, Window window, int x, int y, int width, int height, int exposures) 2943x_clear_area (Display *dpy, Window window, int x, int y, int width, int height)
2987{ 2944{
2988 eassert (width > 0 && height > 0); 2945 eassert (width > 0 && height > 0);
2989 XClearArea (dpy, window, x, y, width, height, exposures); 2946 XClearArea (dpy, window, x, y, width, height, False);
2990} 2947}
2991 2948
2992 2949
@@ -2998,11 +2955,7 @@ x_clear_frame (struct frame *f)
2998 /* Clearing the frame will erase any cursor, so mark them all as no 2955 /* Clearing the frame will erase any cursor, so mark them all as no
2999 longer visible. */ 2956 longer visible. */
3000 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f))); 2957 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f)));
3001 output_cursor.hpos = output_cursor.vpos = 0;
3002 output_cursor.x = -1;
3003 2958
3004 /* We don't set the output cursor here because there will always
3005 follow an explicit cursor_to. */
3006 block_input (); 2959 block_input ();
3007 2960
3008 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); 2961 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
@@ -3127,22 +3080,22 @@ XTflash (struct frame *f)
3127 x_flush (f); 3080 x_flush (f);
3128 3081
3129 { 3082 {
3130 EMACS_TIME delay = make_emacs_time (0, 150 * 1000 * 1000); 3083 struct timespec delay = make_timespec (0, 150 * 1000 * 1000);
3131 EMACS_TIME wakeup = add_emacs_time (current_emacs_time (), delay); 3084 struct timespec wakeup = timespec_add (current_timespec (), delay);
3132 3085
3133 /* Keep waiting until past the time wakeup or any input gets 3086 /* Keep waiting until past the time wakeup or any input gets
3134 available. */ 3087 available. */
3135 while (! detect_input_pending ()) 3088 while (! detect_input_pending ())
3136 { 3089 {
3137 EMACS_TIME current = current_emacs_time (); 3090 struct timespec current = current_timespec ();
3138 EMACS_TIME timeout; 3091 struct timespec timeout;
3139 3092
3140 /* Break if result would not be positive. */ 3093 /* Break if result would not be positive. */
3141 if (EMACS_TIME_LE (wakeup, current)) 3094 if (timespec_cmp (wakeup, current) <= 0)
3142 break; 3095 break;
3143 3096
3144 /* How long `select' should wait. */ 3097 /* How long `select' should wait. */
3145 timeout = make_emacs_time (0, 10 * 1000 * 1000); 3098 timeout = make_timespec (0, 10 * 1000 * 1000);
3146 3099
3147 /* Try to wait that long--but we might wake up sooner. */ 3100 /* Try to wait that long--but we might wake up sooner. */
3148 pselect (0, NULL, NULL, NULL, &timeout, NULL); 3101 pselect (0, NULL, NULL, NULL, &timeout, NULL);
@@ -3228,20 +3181,6 @@ XTring_bell (struct frame *f)
3228 } 3181 }
3229} 3182}
3230 3183
3231
3232/* Specify how many text lines, from the top of the window,
3233 should be affected by insert-lines and delete-lines operations.
3234 This, and those operations, are used only within an update
3235 that is bounded by calls to x_update_begin and x_update_end. */
3236
3237static void
3238XTset_terminal_window (struct frame *f, int n)
3239{
3240 /* This function intentionally left blank. */
3241}
3242
3243
3244
3245/*********************************************************************** 3184/***********************************************************************
3246 Line Dance 3185 Line Dance
3247 ***********************************************************************/ 3186 ***********************************************************************/
@@ -3267,7 +3206,7 @@ x_scroll_run (struct window *w, struct run *run)
3267 /* Get frame-relative bounding box of the text display area of W, 3206 /* Get frame-relative bounding box of the text display area of W,
3268 without mode lines. Include in this box the left and right 3207 without mode lines. Include in this box the left and right
3269 fringe of W. */ 3208 fringe of W. */
3270 window_box (w, -1, &x, &y, &width, &height); 3209 window_box (w, ANY_AREA, &x, &y, &width, &height);
3271 3210
3272#ifdef USE_TOOLKIT_SCROLL_BARS 3211#ifdef USE_TOOLKIT_SCROLL_BARS
3273 /* If the fringe is adjacent to the left (right) scroll bar of a 3212 /* If the fringe is adjacent to the left (right) scroll bar of a
@@ -3323,7 +3262,6 @@ x_scroll_run (struct window *w, struct run *run)
3323 block_input (); 3262 block_input ();
3324 3263
3325 /* Cursor off. Will be switched on again in x_update_window_end. */ 3264 /* Cursor off. Will be switched on again in x_update_window_end. */
3326 updated_window = w;
3327 x_clear_cursor (w); 3265 x_clear_cursor (w);
3328 3266
3329 XCopyArea (FRAME_X_DISPLAY (f), 3267 XCopyArea (FRAME_X_DISPLAY (f),
@@ -3784,7 +3722,6 @@ construct_mouse_click (struct input_event *result, XButtonEvent *event, struct f
3784 return Qnil; 3722 return Qnil;
3785} 3723}
3786 3724
3787
3788/* Function to report a mouse movement to the mainstream Emacs code. 3725/* Function to report a mouse movement to the mainstream Emacs code.
3789 The input handler calls this. 3726 The input handler calls this.
3790 3727
@@ -4204,9 +4141,9 @@ xt_action_hook (Widget widget, XtPointer client_data, String action_name,
4204 scroll_bar_end_scroll, 0, 0); 4141 scroll_bar_end_scroll, 0, 0);
4205 w = XWINDOW (window_being_scrolled); 4142 w = XWINDOW (window_being_scrolled);
4206 4143
4207 if (!NILP (XSCROLL_BAR (w->vertical_scroll_bar)->dragging)) 4144 if (XSCROLL_BAR (w->vertical_scroll_bar)->dragging != -1)
4208 { 4145 {
4209 XSCROLL_BAR (w->vertical_scroll_bar)->dragging = Qnil; 4146 XSCROLL_BAR (w->vertical_scroll_bar)->dragging = -1;
4210 /* The thumb size is incorrect while dragging: fix it. */ 4147 /* The thumb size is incorrect while dragging: fix it. */
4211 set_vertical_scroll_bar (w); 4148 set_vertical_scroll_bar (w);
4212 } 4149 }
@@ -4337,39 +4274,39 @@ x_scroll_bar_to_input_event (XEvent *event, struct input_event *ievent)
4337static void 4274static void
4338xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data) 4275xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4339{ 4276{
4340 struct scroll_bar *bar = (struct scroll_bar *) client_data; 4277 struct scroll_bar *bar = client_data;
4341 XmScrollBarCallbackStruct *cs = (XmScrollBarCallbackStruct *) call_data; 4278 XmScrollBarCallbackStruct *cs = call_data;
4342 int part = -1, whole = 0, portion = 0; 4279 int part = -1, whole = 0, portion = 0;
4343 4280
4344 switch (cs->reason) 4281 switch (cs->reason)
4345 { 4282 {
4346 case XmCR_DECREMENT: 4283 case XmCR_DECREMENT:
4347 bar->dragging = Qnil; 4284 bar->dragging = -1;
4348 part = scroll_bar_up_arrow; 4285 part = scroll_bar_up_arrow;
4349 break; 4286 break;
4350 4287
4351 case XmCR_INCREMENT: 4288 case XmCR_INCREMENT:
4352 bar->dragging = Qnil; 4289 bar->dragging = -1;
4353 part = scroll_bar_down_arrow; 4290 part = scroll_bar_down_arrow;
4354 break; 4291 break;
4355 4292
4356 case XmCR_PAGE_DECREMENT: 4293 case XmCR_PAGE_DECREMENT:
4357 bar->dragging = Qnil; 4294 bar->dragging = -1;
4358 part = scroll_bar_above_handle; 4295 part = scroll_bar_above_handle;
4359 break; 4296 break;
4360 4297
4361 case XmCR_PAGE_INCREMENT: 4298 case XmCR_PAGE_INCREMENT:
4362 bar->dragging = Qnil; 4299 bar->dragging = -1;
4363 part = scroll_bar_below_handle; 4300 part = scroll_bar_below_handle;
4364 break; 4301 break;
4365 4302
4366 case XmCR_TO_TOP: 4303 case XmCR_TO_TOP:
4367 bar->dragging = Qnil; 4304 bar->dragging = -1;
4368 part = scroll_bar_to_top; 4305 part = scroll_bar_to_top;
4369 break; 4306 break;
4370 4307
4371 case XmCR_TO_BOTTOM: 4308 case XmCR_TO_BOTTOM:
4372 bar->dragging = Qnil; 4309 bar->dragging = -1;
4373 part = scroll_bar_to_bottom; 4310 part = scroll_bar_to_bottom;
4374 break; 4311 break;
4375 4312
@@ -4385,7 +4322,7 @@ xm_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4385 whole = XM_SB_MAX - slider_size; 4322 whole = XM_SB_MAX - slider_size;
4386 portion = min (cs->value, whole); 4323 portion = min (cs->value, whole);
4387 part = scroll_bar_handle; 4324 part = scroll_bar_handle;
4388 bar->dragging = make_number (cs->value); 4325 bar->dragging = cs->value;
4389 } 4326 }
4390 break; 4327 break;
4391 4328
@@ -4412,12 +4349,11 @@ xg_scroll_callback (GtkRange *range,
4412 gdouble value, 4349 gdouble value,
4413 gpointer user_data) 4350 gpointer user_data)
4414{ 4351{
4415 struct scroll_bar *bar = (struct scroll_bar *) user_data; 4352 struct scroll_bar *bar = user_data;
4416 gdouble position; 4353 gdouble position;
4417 int part = -1, whole = 0, portion = 0; 4354 int part = -1, whole = 0, portion = 0;
4418 GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range)); 4355 GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range));
4419 struct frame *f = (struct frame *) g_object_get_data (G_OBJECT (range), 4356 struct frame *f = g_object_get_data (G_OBJECT (range), XG_FRAME_DATA);
4420 XG_FRAME_DATA);
4421 4357
4422 if (xg_ignore_gtk_scrollbar) return FALSE; 4358 if (xg_ignore_gtk_scrollbar) return FALSE;
4423 position = gtk_adjustment_get_value (adj); 4359 position = gtk_adjustment_get_value (adj);
@@ -4434,24 +4370,24 @@ xg_scroll_callback (GtkRange *range,
4434 whole = gtk_adjustment_get_upper (adj) - 4370 whole = gtk_adjustment_get_upper (adj) -
4435 gtk_adjustment_get_page_size (adj); 4371 gtk_adjustment_get_page_size (adj);
4436 portion = min ((int)position, whole); 4372 portion = min ((int)position, whole);
4437 bar->dragging = make_number ((int)portion); 4373 bar->dragging = portion;
4438 } 4374 }
4439 break; 4375 break;
4440 case GTK_SCROLL_STEP_BACKWARD: 4376 case GTK_SCROLL_STEP_BACKWARD:
4441 part = scroll_bar_up_arrow; 4377 part = scroll_bar_up_arrow;
4442 bar->dragging = Qnil; 4378 bar->dragging = -1;
4443 break; 4379 break;
4444 case GTK_SCROLL_STEP_FORWARD: 4380 case GTK_SCROLL_STEP_FORWARD:
4445 part = scroll_bar_down_arrow; 4381 part = scroll_bar_down_arrow;
4446 bar->dragging = Qnil; 4382 bar->dragging = -1;
4447 break; 4383 break;
4448 case GTK_SCROLL_PAGE_BACKWARD: 4384 case GTK_SCROLL_PAGE_BACKWARD:
4449 part = scroll_bar_above_handle; 4385 part = scroll_bar_above_handle;
4450 bar->dragging = Qnil; 4386 bar->dragging = -1;
4451 break; 4387 break;
4452 case GTK_SCROLL_PAGE_FORWARD: 4388 case GTK_SCROLL_PAGE_FORWARD:
4453 part = scroll_bar_below_handle; 4389 part = scroll_bar_below_handle;
4454 bar->dragging = Qnil; 4390 bar->dragging = -1;
4455 break; 4391 break;
4456 } 4392 }
4457 4393
@@ -4465,15 +4401,15 @@ xg_scroll_callback (GtkRange *range,
4465 return FALSE; 4401 return FALSE;
4466} 4402}
4467 4403
4468/* Callback for button release. Sets dragging to Qnil when dragging is done. */ 4404/* Callback for button release. Sets dragging to -1 when dragging is done. */
4469 4405
4470static gboolean 4406static gboolean
4471xg_end_scroll_callback (GtkWidget *widget, 4407xg_end_scroll_callback (GtkWidget *widget,
4472 GdkEventButton *event, 4408 GdkEventButton *event,
4473 gpointer user_data) 4409 gpointer user_data)
4474{ 4410{
4475 struct scroll_bar *bar = (struct scroll_bar *) user_data; 4411 struct scroll_bar *bar = user_data;
4476 bar->dragging = Qnil; 4412 bar->dragging = -1;
4477 if (WINDOWP (window_being_scrolled)) 4413 if (WINDOWP (window_being_scrolled))
4478 { 4414 {
4479 x_send_scroll_bar_event (window_being_scrolled, 4415 x_send_scroll_bar_event (window_being_scrolled,
@@ -4495,8 +4431,9 @@ xg_end_scroll_callback (GtkWidget *widget,
4495static void 4431static void
4496xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data) 4432xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4497{ 4433{
4498 struct scroll_bar *bar = (struct scroll_bar *) client_data; 4434 struct scroll_bar *bar = client_data;
4499 float top = *(float *) call_data; 4435 float *top_addr = call_data;
4436 float top = *top_addr;
4500 float shown; 4437 float shown;
4501 int whole, portion, height; 4438 int whole, portion, height;
4502 int part; 4439 int part;
@@ -4520,7 +4457,7 @@ xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4520 part = scroll_bar_handle; 4457 part = scroll_bar_handle;
4521 4458
4522 window_being_scrolled = bar->window; 4459 window_being_scrolled = bar->window;
4523 bar->dragging = make_number (portion); 4460 bar->dragging = portion;
4524 last_scroll_bar_part = part; 4461 last_scroll_bar_part = part;
4525 x_send_scroll_bar_event (bar->window, part, portion, whole); 4462 x_send_scroll_bar_event (bar->window, part, portion, whole);
4526} 4463}
@@ -4537,9 +4474,9 @@ xaw_jump_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4537static void 4474static void
4538xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data) 4475xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4539{ 4476{
4540 struct scroll_bar *bar = (struct scroll_bar *) client_data; 4477 struct scroll_bar *bar = client_data;
4541 /* The position really is stored cast to a pointer. */ 4478 /* The position really is stored cast to a pointer. */
4542 int position = (long) call_data; 4479 int position = (intptr_t) call_data;
4543 Dimension height; 4480 Dimension height;
4544 int part; 4481 int part;
4545 4482
@@ -4559,7 +4496,7 @@ xaw_scroll_callback (Widget widget, XtPointer client_data, XtPointer call_data)
4559 part = scroll_bar_move_ratio; 4496 part = scroll_bar_move_ratio;
4560 4497
4561 window_being_scrolled = bar->window; 4498 window_being_scrolled = bar->window;
4562 bar->dragging = Qnil; 4499 bar->dragging = -1;
4563 last_scroll_bar_part = part; 4500 last_scroll_bar_part = part;
4564 x_send_scroll_bar_event (bar->window, part, position, height); 4501 x_send_scroll_bar_event (bar->window, part, position, height);
4565} 4502}
@@ -4835,7 +4772,7 @@ x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int positio
4835 shown = (float) portion / whole; 4772 shown = (float) portion / whole;
4836 } 4773 }
4837 4774
4838 if (NILP (bar->dragging)) 4775 if (bar->dragging == -1)
4839 { 4776 {
4840 int size, value; 4777 int size, value;
4841 4778
@@ -4870,7 +4807,7 @@ x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int positio
4870 NULL); 4807 NULL);
4871 4808
4872 /* Massage the top+shown values. */ 4809 /* Massage the top+shown values. */
4873 if (NILP (bar->dragging) || last_scroll_bar_part == scroll_bar_down_arrow) 4810 if (bar->dragging == -1 || last_scroll_bar_part == scroll_bar_down_arrow)
4874 top = max (0, min (1, top)); 4811 top = max (0, min (1, top));
4875 else 4812 else
4876 top = old_top; 4813 top = old_top;
@@ -4882,7 +4819,7 @@ x_set_toolkit_scroll_bar_thumb (struct scroll_bar *bar, int portion, int positio
4882 for `NARROWPROTO'. See s/freebsd.h for an example. */ 4819 for `NARROWPROTO'. See s/freebsd.h for an example. */
4883 if (top != old_top || shown != old_shown) 4820 if (top != old_top || shown != old_shown)
4884 { 4821 {
4885 if (NILP (bar->dragging)) 4822 if (bar->dragging == -1)
4886 XawScrollbarSetThumb (widget, top, shown); 4823 XawScrollbarSetThumb (widget, top, shown);
4887 else 4824 else
4888 { 4825 {
@@ -4947,8 +4884,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
4947 this case, no clear_frame is generated to reduce flickering. */ 4884 this case, no clear_frame is generated to reduce flickering. */
4948 if (width > 0 && height > 0) 4885 if (width > 0 && height > 0)
4949 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 4886 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4950 left, top, width, 4887 left, top, width, window_box_height (w));
4951 window_box_height (w), False);
4952 4888
4953 window = XCreateWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 4889 window = XCreateWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4954 /* Position and size of scroll bar. */ 4890 /* Position and size of scroll bar. */
@@ -4974,7 +4910,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
4974 bar->height = height; 4910 bar->height = height;
4975 bar->start = 0; 4911 bar->start = 0;
4976 bar->end = 0; 4912 bar->end = 0;
4977 bar->dragging = Qnil; 4913 bar->dragging = -1;
4978 bar->fringe_extended_p = 0; 4914 bar->fringe_extended_p = 0;
4979 4915
4980 /* Add bar to its frame's list of scroll bars. */ 4916 /* Add bar to its frame's list of scroll bars. */
@@ -5032,7 +4968,7 @@ x_scroll_bar_create (struct window *w, int top, int left, int width, int height)
5032static void 4968static void
5033x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild) 4969x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild)
5034{ 4970{
5035 int dragging = ! NILP (bar->dragging); 4971 bool dragging = bar->dragging != -1;
5036 Window w = bar->x_window; 4972 Window w = bar->x_window;
5037 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window))); 4973 struct frame *f = XFRAME (WINDOW_FRAME (XWINDOW (bar->window)));
5038 GC gc = f->output_data.x->normal_gc; 4974 GC gc = f->output_data.x->normal_gc;
@@ -5084,11 +5020,9 @@ x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild
5084 zero-height areas; that means "clear to end of window." */ 5020 zero-height areas; that means "clear to end of window." */
5085 if (start > 0) 5021 if (start > 0)
5086 x_clear_area (FRAME_X_DISPLAY (f), w, 5022 x_clear_area (FRAME_X_DISPLAY (f), w,
5087 /* x, y, width, height, and exposures. */
5088 VERTICAL_SCROLL_BAR_LEFT_BORDER, 5023 VERTICAL_SCROLL_BAR_LEFT_BORDER,
5089 VERTICAL_SCROLL_BAR_TOP_BORDER, 5024 VERTICAL_SCROLL_BAR_TOP_BORDER,
5090 inside_width, start, 5025 inside_width, start);
5091 False);
5092 5026
5093 /* Change to proper foreground color if one is specified. */ 5027 /* Change to proper foreground color if one is specified. */
5094 if (f->output_data.x->scroll_bar_foreground_pixel != -1) 5028 if (f->output_data.x->scroll_bar_foreground_pixel != -1)
@@ -5111,12 +5045,9 @@ x_scroll_bar_set_handle (struct scroll_bar *bar, int start, int end, int rebuild
5111 clear zero-height areas; that means "clear to end of window." */ 5045 clear zero-height areas; that means "clear to end of window." */
5112 if (end < inside_height) 5046 if (end < inside_height)
5113 x_clear_area (FRAME_X_DISPLAY (f), w, 5047 x_clear_area (FRAME_X_DISPLAY (f), w,
5114 /* x, y, width, height, and exposures. */
5115 VERTICAL_SCROLL_BAR_LEFT_BORDER, 5048 VERTICAL_SCROLL_BAR_LEFT_BORDER,
5116 VERTICAL_SCROLL_BAR_TOP_BORDER + end, 5049 VERTICAL_SCROLL_BAR_TOP_BORDER + end,
5117 inside_width, inside_height - end, 5050 inside_width, inside_height - end);
5118 False);
5119
5120 } 5051 }
5121 5052
5122 unblock_input (); 5053 unblock_input ();
@@ -5164,11 +5095,11 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5164 int top, height, left, sb_left, width, sb_width; 5095 int top, height, left, sb_left, width, sb_width;
5165 int window_y, window_height; 5096 int window_y, window_height;
5166#ifdef USE_TOOLKIT_SCROLL_BARS 5097#ifdef USE_TOOLKIT_SCROLL_BARS
5167 int fringe_extended_p; 5098 bool fringe_extended_p;
5168#endif 5099#endif
5169 5100
5170 /* Get window dimensions. */ 5101 /* Get window dimensions. */
5171 window_box (w, -1, 0, &window_y, 0, &window_height); 5102 window_box (w, ANY_AREA, 0, &window_y, 0, &window_height);
5172 top = window_y; 5103 top = window_y;
5173 width = WINDOW_CONFIG_SCROLL_BAR_COLS (w) * FRAME_COLUMN_WIDTH (f); 5104 width = WINDOW_CONFIG_SCROLL_BAR_COLS (w) * FRAME_COLUMN_WIDTH (f);
5174 height = window_height; 5105 height = window_height;
@@ -5197,16 +5128,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5197#endif 5128#endif
5198 5129
5199#ifdef USE_TOOLKIT_SCROLL_BARS 5130#ifdef USE_TOOLKIT_SCROLL_BARS
5200 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) 5131 fringe_extended_p = WINDOW_FRINGE_EXTENDED_P (w);
5201 fringe_extended_p = (WINDOW_LEFTMOST_P (w)
5202 && WINDOW_LEFT_FRINGE_WIDTH (w)
5203 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
5204 || WINDOW_LEFT_MARGIN_COLS (w) == 0));
5205 else
5206 fringe_extended_p = (WINDOW_RIGHTMOST_P (w)
5207 && WINDOW_RIGHT_FRINGE_WIDTH (w)
5208 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w)
5209 || WINDOW_RIGHT_MARGIN_COLS (w) == 0));
5210#endif 5132#endif
5211 5133
5212 /* Does the scroll bar exist yet? */ 5134 /* Does the scroll bar exist yet? */
@@ -5218,11 +5140,11 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5218#ifdef USE_TOOLKIT_SCROLL_BARS 5140#ifdef USE_TOOLKIT_SCROLL_BARS
5219 if (fringe_extended_p) 5141 if (fringe_extended_p)
5220 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5142 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5221 sb_left, top, sb_width, height, False); 5143 sb_left, top, sb_width, height);
5222 else 5144 else
5223#endif 5145#endif
5224 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5146 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5225 left, top, width, height, False); 5147 left, top, width, height);
5226 unblock_input (); 5148 unblock_input ();
5227 } 5149 }
5228 5150
@@ -5257,10 +5179,10 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5257 { 5179 {
5258 if (fringe_extended_p) 5180 if (fringe_extended_p)
5259 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5181 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5260 sb_left, top, sb_width, height, False); 5182 sb_left, top, sb_width, height);
5261 else 5183 else
5262 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5184 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5263 left, top, width, height, False); 5185 left, top, width, height);
5264 } 5186 }
5265#ifdef USE_GTK 5187#ifdef USE_GTK
5266 xg_update_scrollbar_pos (f, 5188 xg_update_scrollbar_pos (f,
@@ -5284,12 +5206,10 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5284 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM) 5206 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM)
5285 { 5207 {
5286 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5208 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5287 left, top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, 5209 left, top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, height);
5288 height, False);
5289 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5210 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5290 left + width - VERTICAL_SCROLL_BAR_WIDTH_TRIM, 5211 left + width - VERTICAL_SCROLL_BAR_WIDTH_TRIM,
5291 top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, 5212 top, VERTICAL_SCROLL_BAR_WIDTH_TRIM, height);
5292 height, False);
5293 } 5213 }
5294 5214
5295 /* Clear areas not covered by the scroll bar because it's not as 5215 /* Clear areas not covered by the scroll bar because it's not as
@@ -5303,11 +5223,10 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5303 { 5223 {
5304 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w)) 5224 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w))
5305 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5225 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5306 left + area_width - rest, top, 5226 left + area_width - rest, top, rest, height);
5307 rest, height, False);
5308 else 5227 else
5309 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 5228 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
5310 left, top, rest, height, False); 5229 left, top, rest, height);
5311 } 5230 }
5312 } 5231 }
5313 5232
@@ -5342,7 +5261,7 @@ XTset_vertical_scroll_bar (struct window *w, int portion, int whole, int positio
5342#else /* not USE_TOOLKIT_SCROLL_BARS */ 5261#else /* not USE_TOOLKIT_SCROLL_BARS */
5343 /* Set the scroll bar's current state, unless we're currently being 5262 /* Set the scroll bar's current state, unless we're currently being
5344 dragged. */ 5263 dragged. */
5345 if (NILP (bar->dragging)) 5264 if (bar->dragging == -1)
5346 { 5265 {
5347 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height); 5266 int top_range = VERTICAL_SCROLL_BAR_TOP_RANGE (f, height);
5348 5267
@@ -5552,14 +5471,13 @@ x_scroll_bar_handle_click (struct scroll_bar *bar, XEvent *event, struct input_e
5552 5471
5553#ifndef USE_TOOLKIT_SCROLL_BARS 5472#ifndef USE_TOOLKIT_SCROLL_BARS
5554 /* If the user has released the handle, set it to its final position. */ 5473 /* If the user has released the handle, set it to its final position. */
5555 if (event->type == ButtonRelease 5474 if (event->type == ButtonRelease && bar->dragging != -1)
5556 && ! NILP (bar->dragging))
5557 { 5475 {
5558 int new_start = y - XINT (bar->dragging); 5476 int new_start = y - XINT (bar->dragging);
5559 int new_end = new_start + bar->end - bar->start; 5477 int new_end = new_start + bar->end - bar->start;
5560 5478
5561 x_scroll_bar_set_handle (bar, new_start, new_end, 0); 5479 x_scroll_bar_set_handle (bar, new_start, new_end, 0);
5562 bar->dragging = Qnil; 5480 bar->dragging = -1;
5563 } 5481 }
5564#endif 5482#endif
5565 5483
@@ -5576,20 +5494,20 @@ x_scroll_bar_handle_click (struct scroll_bar *bar, XEvent *event, struct input_e
5576 mark bits. */ 5494 mark bits. */
5577 5495
5578static void 5496static void
5579x_scroll_bar_note_movement (struct scroll_bar *bar, XEvent *event) 5497x_scroll_bar_note_movement (struct scroll_bar *bar, XMotionEvent *event)
5580{ 5498{
5581 struct frame *f = XFRAME (XWINDOW (bar->window)->frame); 5499 struct frame *f = XFRAME (XWINDOW (bar->window)->frame);
5582 5500
5583 last_mouse_movement_time = event->xmotion.time; 5501 last_mouse_movement_time = event->time;
5584 5502
5585 f->mouse_moved = 1; 5503 f->mouse_moved = 1;
5586 XSETVECTOR (last_mouse_scroll_bar, bar); 5504 XSETVECTOR (last_mouse_scroll_bar, bar);
5587 5505
5588 /* If we're dragging the bar, display it. */ 5506 /* If we're dragging the bar, display it. */
5589 if (! NILP (bar->dragging)) 5507 if (bar->dragging != -1)
5590 { 5508 {
5591 /* Where should the handle be now? */ 5509 /* Where should the handle be now? */
5592 int new_start = event->xmotion.y - XINT (bar->dragging); 5510 int new_start = event->y - bar->dragging;
5593 5511
5594 if (new_start != bar->start) 5512 if (new_start != bar->start)
5595 { 5513 {
@@ -5641,8 +5559,8 @@ x_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
5641 5559
5642 win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER; 5560 win_y -= VERTICAL_SCROLL_BAR_TOP_BORDER;
5643 5561
5644 if (! NILP (bar->dragging)) 5562 if (bar->dragging != -1)
5645 win_y -= XINT (bar->dragging); 5563 win_y -= bar->dragging;
5646 5564
5647 if (win_y < 0) 5565 if (win_y < 0)
5648 win_y = 0; 5566 win_y = 0;
@@ -5652,7 +5570,7 @@ x_scroll_bar_report_motion (struct frame **fp, Lisp_Object *bar_window,
5652 *fp = f; 5570 *fp = f;
5653 *bar_window = bar->window; 5571 *bar_window = bar->window;
5654 5572
5655 if (! NILP (bar->dragging)) 5573 if (bar->dragging != -1)
5656 *part = scroll_bar_handle; 5574 *part = scroll_bar_handle;
5657 else if (win_y < bar->start) 5575 else if (win_y < bar->start)
5658 *part = scroll_bar_above_handle; 5576 *part = scroll_bar_above_handle;
@@ -5697,18 +5615,7 @@ x_scroll_bar_clear (struct frame *f)
5697#endif /* not USE_TOOLKIT_SCROLL_BARS */ 5615#endif /* not USE_TOOLKIT_SCROLL_BARS */
5698} 5616}
5699 5617
5700 5618#ifdef ENABLE_CHECKING
5701/* The main X event-reading loop - XTread_socket. */
5702
5703/* This holds the state XLookupString needs to implement dead keys
5704 and other tricks known as "compose processing". _X Window System_
5705 says that a portable program can't use this, but Stephen Gildea assures
5706 me that letting the compiler initialize it to zeros will work okay.
5707
5708 This must be defined outside of XTread_socket, for the same reasons
5709 given for enter_timestamp, above. */
5710
5711static XComposeStatus compose_status;
5712 5619
5713/* Record the last 100 characters stored 5620/* Record the last 100 characters stored
5714 to help debug the loss-of-chars-during-GC problem. */ 5621 to help debug the loss-of-chars-during-GC problem. */
@@ -5721,6 +5628,12 @@ static short temp_buffer[100];
5721 temp_index = 0; \ 5628 temp_index = 0; \
5722 temp_buffer[temp_index++] = (keysym) 5629 temp_buffer[temp_index++] = (keysym)
5723 5630
5631#else /* not ENABLE_CHECKING */
5632
5633#define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
5634
5635#endif /* ENABLE_CHECKING */
5636
5724/* Set this to nonzero to fake an "X I/O error" 5637/* Set this to nonzero to fake an "X I/O error"
5725 on a particular display. */ 5638 on a particular display. */
5726 5639
@@ -5858,6 +5771,12 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
5858 struct coding_system coding; 5771 struct coding_system coding;
5859 XEvent event = *eventptr; 5772 XEvent event = *eventptr;
5860 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight; 5773 Mouse_HLInfo *hlinfo = &dpyinfo->mouse_highlight;
5774 /* This holds the state XLookupString needs to implement dead keys
5775 and other tricks known as "compose processing". _X Window System_
5776 says that a portable program can't use this, but Stephen Gildea assures
5777 me that letting the compiler initialize it to zeros will work okay. */
5778 static XComposeStatus compose_status;
5779
5861 USE_SAFE_ALLOCA; 5780 USE_SAFE_ALLOCA;
5862 5781
5863 *finish = X_EVENT_NORMAL; 5782 *finish = X_EVENT_NORMAL;
@@ -6151,11 +6070,10 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6151 { 6070 {
6152#ifdef USE_GTK 6071#ifdef USE_GTK
6153 /* This seems to be needed for GTK 2.6. */ 6072 /* This seems to be needed for GTK 2.6. */
6154 x_clear_area (event.xexpose.display, 6073 x_clear_area (event.xexpose.display,
6155 event.xexpose.window, 6074 event.xexpose.window,
6156 event.xexpose.x, event.xexpose.y, 6075 event.xexpose.x, event.xexpose.y,
6157 event.xexpose.width, event.xexpose.height, 6076 event.xexpose.width, event.xexpose.height);
6158 FALSE);
6159#endif 6077#endif
6160 if (!FRAME_VISIBLE_P (f)) 6078 if (!FRAME_VISIBLE_P (f))
6161 { 6079 {
@@ -6227,7 +6145,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6227 6145
6228 case UnmapNotify: 6146 case UnmapNotify:
6229 /* Redo the mouse-highlight after the tooltip has gone. */ 6147 /* Redo the mouse-highlight after the tooltip has gone. */
6230 if (event.xmap.window == tip_window) 6148 if (event.xunmap.window == tip_window)
6231 { 6149 {
6232 tip_window = 0; 6150 tip_window = 0;
6233 redo_mouse_highlight (); 6151 redo_mouse_highlight ();
@@ -6731,18 +6649,16 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6731 /* Generate SELECT_WINDOW_EVENTs when needed. 6649 /* Generate SELECT_WINDOW_EVENTs when needed.
6732 Don't let popup menus influence things (bug#1261). */ 6650 Don't let popup menus influence things (bug#1261). */
6733 if (!NILP (Vmouse_autoselect_window) && !popup_activated ()) 6651 if (!NILP (Vmouse_autoselect_window) && !popup_activated ())
6734 { 6652 {
6735 Lisp_Object window; 6653 static Lisp_Object last_mouse_window;
6736 6654 Lisp_Object window = window_from_coordinates
6737 window = window_from_coordinates (f, 6655 (f, event.xmotion.x, event.xmotion.y, 0, 0);
6738 event.xmotion.x, event.xmotion.y, 6656
6739 0, 0); 6657 /* Window will be selected only when it is not selected now and
6740 6658 last mouse movement event was not in it. Minibuffer window
6741 /* Window will be selected only when it is not selected now and 6659 will be selected only when it is active. */
6742 last mouse movement event was not in it. Minibuffer window 6660 if (WINDOWP (window)
6743 will be selected only when it is active. */ 6661 && !EQ (window, last_mouse_window)
6744 if (WINDOWP (window)
6745 && !EQ (window, last_window)
6746 && !EQ (window, selected_window) 6662 && !EQ (window, selected_window)
6747 /* For click-to-focus window managers 6663 /* For click-to-focus window managers
6748 create event iff we don't leave the 6664 create event iff we don't leave the
@@ -6750,13 +6666,13 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6750 && (focus_follows_mouse 6666 && (focus_follows_mouse
6751 || (EQ (XWINDOW (window)->frame, 6667 || (EQ (XWINDOW (window)->frame,
6752 XWINDOW (selected_window)->frame)))) 6668 XWINDOW (selected_window)->frame))))
6753 { 6669 {
6754 inev.ie.kind = SELECT_WINDOW_EVENT; 6670 inev.ie.kind = SELECT_WINDOW_EVENT;
6755 inev.ie.frame_or_window = window; 6671 inev.ie.frame_or_window = window;
6756 } 6672 }
6757 6673 /* Remember the last window where we saw the mouse. */
6758 last_window=window; 6674 last_mouse_window = window;
6759 } 6675 }
6760 if (!note_mouse_movement (f, &event.xmotion)) 6676 if (!note_mouse_movement (f, &event.xmotion))
6761 help_echo_string = previous_help_echo_string; 6677 help_echo_string = previous_help_echo_string;
6762 } 6678 }
@@ -6768,7 +6684,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, XEvent *eventptr,
6768 event.xmotion.window); 6684 event.xmotion.window);
6769 6685
6770 if (bar) 6686 if (bar)
6771 x_scroll_bar_note_movement (bar, &event); 6687 x_scroll_bar_note_movement (bar, &event.xmotion);
6772#endif /* USE_TOOLKIT_SCROLL_BARS */ 6688#endif /* USE_TOOLKIT_SCROLL_BARS */
6773 6689
6774 /* If we move outside the frame, then we're 6690 /* If we move outside the frame, then we're
@@ -7200,7 +7116,8 @@ XTread_socket (struct terminal *terminal, struct input_event *hold_quit)
7200 mode lines must be clipped to the whole window. */ 7116 mode lines must be clipped to the whole window. */
7201 7117
7202static void 7118static void
7203x_clip_to_row (struct window *w, struct glyph_row *row, int area, GC gc) 7119x_clip_to_row (struct window *w, struct glyph_row *row,
7120 enum glyph_row_area area, GC gc)
7204{ 7121{
7205 struct frame *f = XFRAME (WINDOW_FRAME (w)); 7122 struct frame *f = XFRAME (WINDOW_FRAME (w));
7206 XRectangle clip_rect; 7123 XRectangle clip_rect;
@@ -7377,8 +7294,7 @@ x_define_frame_cursor (struct frame *f, Cursor cursor)
7377static void 7294static void
7378x_clear_frame_area (struct frame *f, int x, int y, int width, int height) 7295x_clear_frame_area (struct frame *f, int x, int y, int width, int height)
7379{ 7296{
7380 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 7297 x_clear_area (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), x, y, width, height);
7381 x, y, width, height, False);
7382#ifdef USE_GTK 7298#ifdef USE_GTK
7383 /* Must queue a redraw, because scroll bars might have been cleared. */ 7299 /* Must queue a redraw, because scroll bars might have been cleared. */
7384 if (FRAME_GTK_WIDGET (f)) 7300 if (FRAME_GTK_WIDGET (f))
@@ -7390,7 +7306,9 @@ x_clear_frame_area (struct frame *f, int x, int y, int width, int height)
7390/* RIF: Draw cursor on window W. */ 7306/* RIF: Draw cursor on window W. */
7391 7307
7392static void 7308static void
7393x_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x, int y, int cursor_type, int cursor_width, int on_p, int active_p) 7309x_draw_window_cursor (struct window *w, struct glyph_row *glyph_row, int x,
7310 int y, enum text_cursor_kinds cursor_type,
7311 int cursor_width, bool on_p, bool active_p)
7394{ 7312{
7395 struct frame *f = XFRAME (WINDOW_FRAME (w)); 7313 struct frame *f = XFRAME (WINDOW_FRAME (w));
7396 7314
@@ -7817,9 +7735,8 @@ static int
7817x_error_handler (Display *display, XErrorEvent *event) 7735x_error_handler (Display *display, XErrorEvent *event)
7818{ 7736{
7819#if defined USE_GTK && defined HAVE_GTK3 7737#if defined USE_GTK && defined HAVE_GTK3
7820 if (event->error_code == BadMatch 7738 if ((event->error_code == BadMatch || event->error_code == BadWindow)
7821 && event->request_code == X_SetInputFocus 7739 && event->request_code == X_SetInputFocus)
7822 && event->minor_code == 0)
7823 { 7740 {
7824 return 0; 7741 return 0;
7825 } 7742 }
@@ -8090,13 +8007,10 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name)
8090 { 8007 {
8091#ifdef HAVE_X11R6_XIM 8008#ifdef HAVE_X11R6_XIM
8092 struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst); 8009 struct xim_inst_t *xim_inst = xmalloc (sizeof *xim_inst);
8093 ptrdiff_t len;
8094 8010
8095 dpyinfo->xim_callback_data = xim_inst; 8011 dpyinfo->xim_callback_data = xim_inst;
8096 xim_inst->dpyinfo = dpyinfo; 8012 xim_inst->dpyinfo = dpyinfo;
8097 len = strlen (resource_name); 8013 xim_inst->resource_name = xstrdup (resource_name);
8098 xim_inst->resource_name = xmalloc (len + 1);
8099 memcpy (xim_inst->resource_name, resource_name, len + 1);
8100 XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb, 8014 XRegisterIMInstantiateCallback (dpyinfo->display, dpyinfo->xrdb,
8101 resource_name, emacs_class, 8015 resource_name, emacs_class,
8102 xim_instantiate_callback, 8016 xim_instantiate_callback,
@@ -8202,9 +8116,6 @@ x_set_offset (struct frame *f, register int xoff, register int yoff, int change_
8202 8116
8203 if (change_gravity > 0) 8117 if (change_gravity > 0)
8204 { 8118 {
8205 FRAME_X_OUTPUT (f)->left_before_move = f->left_pos;
8206 FRAME_X_OUTPUT (f)->top_before_move = f->top_pos;
8207
8208 f->top_pos = yoff; 8119 f->top_pos = yoff;
8209 f->left_pos = xoff; 8120 f->left_pos = xoff;
8210 f->size_hint_flags &= ~ (XNegative | YNegative); 8121 f->size_hint_flags &= ~ (XNegative | YNegative);
@@ -8703,8 +8614,8 @@ x_wait_for_event (struct frame *f, int eventtype)
8703{ 8614{
8704 int level = interrupt_input_blocked; 8615 int level = interrupt_input_blocked;
8705 8616
8706 SELECT_TYPE fds; 8617 fd_set fds;
8707 EMACS_TIME tmo, tmo_at, time_now; 8618 struct timespec tmo, tmo_at, time_now;
8708 int fd = ConnectionNumber (FRAME_X_DISPLAY (f)); 8619 int fd = ConnectionNumber (FRAME_X_DISPLAY (f));
8709 8620
8710 pending_event_wait.f = f; 8621 pending_event_wait.f = f;
@@ -8712,8 +8623,8 @@ x_wait_for_event (struct frame *f, int eventtype)
8712 8623
8713 /* Set timeout to 0.1 second. Hopefully not noticeable. 8624 /* Set timeout to 0.1 second. Hopefully not noticeable.
8714 Maybe it should be configurable. */ 8625 Maybe it should be configurable. */
8715 tmo = make_emacs_time (0, 100 * 1000 * 1000); 8626 tmo = make_timespec (0, 100 * 1000 * 1000);
8716 tmo_at = add_emacs_time (current_emacs_time (), tmo); 8627 tmo_at = timespec_add (current_timespec (), tmo);
8717 8628
8718 while (pending_event_wait.eventtype) 8629 while (pending_event_wait.eventtype)
8719 { 8630 {
@@ -8726,11 +8637,11 @@ x_wait_for_event (struct frame *f, int eventtype)
8726 FD_ZERO (&fds); 8637 FD_ZERO (&fds);
8727 FD_SET (fd, &fds); 8638 FD_SET (fd, &fds);
8728 8639
8729 time_now = current_emacs_time (); 8640 time_now = current_timespec ();
8730 if (EMACS_TIME_LT (tmo_at, time_now)) 8641 if (timespec_cmp (tmo_at, time_now) < 0)
8731 break; 8642 break;
8732 8643
8733 tmo = sub_emacs_time (tmo_at, time_now); 8644 tmo = timespec_sub (tmo_at, time_now);
8734 if (pselect (fd + 1, &fds, NULL, NULL, &tmo, NULL) == 0) 8645 if (pselect (fd + 1, &fds, NULL, NULL, &tmo, NULL) == 0)
8735 break; /* Timeout */ 8646 break; /* Timeout */
8736 } 8647 }
@@ -9466,16 +9377,8 @@ x_free_frame_resources (struct frame *f)
9466 dpyinfo->x_focus_event_frame = 0; 9377 dpyinfo->x_focus_event_frame = 0;
9467 if (f == dpyinfo->x_highlight_frame) 9378 if (f == dpyinfo->x_highlight_frame)
9468 dpyinfo->x_highlight_frame = 0; 9379 dpyinfo->x_highlight_frame = 0;
9469
9470 if (f == hlinfo->mouse_face_mouse_frame) 9380 if (f == hlinfo->mouse_face_mouse_frame)
9471 { 9381 reset_mouse_highlight (hlinfo);
9472 hlinfo->mouse_face_beg_row
9473 = hlinfo->mouse_face_beg_col = -1;
9474 hlinfo->mouse_face_end_row
9475 = hlinfo->mouse_face_end_col = -1;
9476 hlinfo->mouse_face_window = Qnil;
9477 hlinfo->mouse_face_mouse_frame = 0;
9478 }
9479 9382
9480 unblock_input (); 9383 unblock_input ();
9481} 9384}
@@ -9847,7 +9750,6 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
9847 struct terminal *terminal; 9750 struct terminal *terminal;
9848 struct x_display_info *dpyinfo; 9751 struct x_display_info *dpyinfo;
9849 XrmDatabase xrdb; 9752 XrmDatabase xrdb;
9850 Mouse_HLInfo *hlinfo;
9851 ptrdiff_t lim; 9753 ptrdiff_t lim;
9852 9754
9853 block_input (); 9755 block_input ();
@@ -9988,8 +9890,6 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
9988 /* We have definitely succeeded. Record the new connection. */ 9890 /* We have definitely succeeded. Record the new connection. */
9989 9891
9990 dpyinfo = xzalloc (sizeof *dpyinfo); 9892 dpyinfo = xzalloc (sizeof *dpyinfo);
9991 hlinfo = &dpyinfo->mouse_highlight;
9992
9993 terminal = x_create_terminal (dpyinfo); 9893 terminal = x_create_terminal (dpyinfo);
9994 9894
9995 { 9895 {
@@ -10060,9 +9960,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10060 dpyinfo->display = dpy; 9960 dpyinfo->display = dpy;
10061 9961
10062 /* Set the name of the terminal. */ 9962 /* Set the name of the terminal. */
10063 terminal->name = xmalloc (SBYTES (display_name) + 1); 9963 terminal->name = xlispstrdup (display_name);
10064 memcpy (terminal->name, SSDATA (display_name), SBYTES (display_name));
10065 terminal->name[SBYTES (display_name)] = 0;
10066 9964
10067#if 0 9965#if 0
10068 XSetAfterFunction (x_current_display, x_trace_wire); 9966 XSetAfterFunction (x_current_display, x_trace_wire);
@@ -10104,33 +10002,12 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10104 select_visual (dpyinfo); 10002 select_visual (dpyinfo);
10105 dpyinfo->cmap = DefaultColormapOfScreen (dpyinfo->screen); 10003 dpyinfo->cmap = DefaultColormapOfScreen (dpyinfo->screen);
10106 dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen); 10004 dpyinfo->root_window = RootWindowOfScreen (dpyinfo->screen);
10107 dpyinfo->client_leader_window = 0;
10108 dpyinfo->grabbed = 0;
10109 dpyinfo->reference_count = 0;
10110 dpyinfo->icon_bitmap_id = -1; 10005 dpyinfo->icon_bitmap_id = -1;
10111 dpyinfo->n_fonts = 0;
10112 dpyinfo->bitmaps = 0;
10113 dpyinfo->bitmaps_size = 0;
10114 dpyinfo->bitmaps_last = 0;
10115 dpyinfo->scratch_cursor_gc = 0;
10116 hlinfo->mouse_face_mouse_frame = 0;
10117 hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1;
10118 hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1;
10119 hlinfo->mouse_face_face_id = DEFAULT_FACE_ID;
10120 hlinfo->mouse_face_window = Qnil;
10121 hlinfo->mouse_face_overlay = Qnil;
10122 hlinfo->mouse_face_mouse_x = hlinfo->mouse_face_mouse_y = 0;
10123 hlinfo->mouse_face_defer = 0;
10124 hlinfo->mouse_face_hidden = 0;
10125 dpyinfo->x_focus_frame = 0;
10126 dpyinfo->x_focus_event_frame = 0;
10127 dpyinfo->x_highlight_frame = 0;
10128 dpyinfo->wm_type = X_WMTYPE_UNKNOWN; 10006 dpyinfo->wm_type = X_WMTYPE_UNKNOWN;
10129 10007
10130 /* See if we can construct pixel values from RGB values. */ 10008 reset_mouse_highlight (&dpyinfo->mouse_highlight);
10131 dpyinfo->red_bits = dpyinfo->blue_bits = dpyinfo->green_bits = 0;
10132 dpyinfo->red_offset = dpyinfo->blue_offset = dpyinfo->green_offset = 0;
10133 10009
10010 /* See if we can construct pixel values from RGB values. */
10134 if (dpyinfo->visual->class == TrueColor) 10011 if (dpyinfo->visual->class == TrueColor)
10135 { 10012 {
10136 get_bits_and_offset (dpyinfo->visual->red_mask, 10013 get_bits_and_offset (dpyinfo->visual->red_mask,
@@ -10291,14 +10168,9 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
10291 } 10168 }
10292 10169
10293 dpyinfo->x_dnd_atoms_size = 8; 10170 dpyinfo->x_dnd_atoms_size = 8;
10294 dpyinfo->x_dnd_atoms_length = 0;
10295 dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms 10171 dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms
10296 * dpyinfo->x_dnd_atoms_size); 10172 * dpyinfo->x_dnd_atoms_size);
10297 10173
10298 dpyinfo->net_supported_atoms = NULL;
10299 dpyinfo->nr_net_supported_atoms = 0;
10300 dpyinfo->net_supported_window = 0;
10301
10302 connection = ConnectionNumber (dpyinfo->display); 10174 connection = ConnectionNumber (dpyinfo->display);
10303 dpyinfo->connection = connection; 10175 dpyinfo->connection = connection;
10304 dpyinfo->gray 10176 dpyinfo->gray
@@ -10491,7 +10363,7 @@ x_activate_timeout_atimer (void)
10491 block_input (); 10363 block_input ();
10492 if (!x_timeout_atimer_activated_flag) 10364 if (!x_timeout_atimer_activated_flag)
10493 { 10365 {
10494 EMACS_TIME interval = make_emacs_time (0, 100 * 1000 * 1000); 10366 struct timespec interval = make_timespec (0, 100 * 1000 * 1000);
10495 start_atimer (ATIMER_RELATIVE, interval, x_process_timeouts, 0); 10367 start_atimer (ATIMER_RELATIVE, interval, x_process_timeouts, 0);
10496 x_timeout_atimer_activated_flag = 1; 10368 x_timeout_atimer_activated_flag = 1;
10497 } 10369 }
@@ -10514,7 +10386,6 @@ static struct redisplay_interface x_redisplay_interface =
10514 x_after_update_window_line, 10386 x_after_update_window_line,
10515 x_update_window_begin, 10387 x_update_window_begin,
10516 x_update_window_end, 10388 x_update_window_end,
10517 x_cursor_to,
10518 x_flush, 10389 x_flush,
10519#ifdef XFlush 10390#ifdef XFlush
10520 x_flush, 10391 x_flush,
@@ -10627,11 +10498,11 @@ x_create_terminal (struct x_display_info *dpyinfo)
10627 terminal->delete_glyphs_hook = x_delete_glyphs; 10498 terminal->delete_glyphs_hook = x_delete_glyphs;
10628 terminal->ring_bell_hook = XTring_bell; 10499 terminal->ring_bell_hook = XTring_bell;
10629 terminal->toggle_invisible_pointer_hook = XTtoggle_invisible_pointer; 10500 terminal->toggle_invisible_pointer_hook = XTtoggle_invisible_pointer;
10630 terminal->reset_terminal_modes_hook = XTreset_terminal_modes; 10501 terminal->reset_terminal_modes_hook = NULL;
10631 terminal->set_terminal_modes_hook = XTset_terminal_modes; 10502 terminal->set_terminal_modes_hook = NULL;
10632 terminal->update_begin_hook = x_update_begin; 10503 terminal->update_begin_hook = x_update_begin;
10633 terminal->update_end_hook = x_update_end; 10504 terminal->update_end_hook = x_update_end;
10634 terminal->set_terminal_window_hook = XTset_terminal_window; 10505 terminal->set_terminal_window_hook = NULL;
10635 terminal->read_socket_hook = XTread_socket; 10506 terminal->read_socket_hook = XTread_socket;
10636 terminal->frame_up_to_date_hook = XTframe_up_to_date; 10507 terminal->frame_up_to_date_hook = XTframe_up_to_date;
10637 terminal->mouse_position_hook = XTmouse_position; 10508 terminal->mouse_position_hook = XTmouse_position;