1 /* X Communication module for terminals which understand the X protocol.
3 Copyright (C) 1989, 1993-2017 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or (at
10 your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
21 /* Xt features made by Fred Pierresteguy. */
31 #include "blockinput.h"
33 /* This may include sys/types.h, and that somehow loses
34 if this is not done before the other system files. */
36 #include <X11/cursorfont.h>
38 /* If we have Xfixes extension, use it for pointer blanking. */
40 #include <X11/extensions/Xfixes.h>
43 /* Using Xft implies that XRender is available. */
45 #include <X11/extensions/Xrender.h>
49 #include <X11/extensions/Xdbe.h>
52 /* Load sys/types.h if not already loaded.
53 In some systems loading it twice is suicidal. */
55 #include <sys/types.h>
58 #include <sys/ioctl.h>
65 #include "character.h"
67 #include "composite.h"
69 #include "dispextern.h"
72 #include "termhooks.h"
75 #include "emacs-icon.h"
81 #include "xsettings.h"
82 #include "sysselect.h"
86 #include <X11/Shell.h>
94 #include <X11/Xproto.h>
98 #if defined (USE_LUCID) || defined (USE_MOTIF)
99 #include "../lwlib/xlwmenu.h"
104 /* Include toolkit specific headers for the scroll bar widget. */
106 #ifdef USE_TOOLKIT_SCROLL_BARS
107 #if defined USE_MOTIF
108 #include <Xm/Xm.h> /* For LESSTIF_VERSION */
109 #include <Xm/ScrollBar.h>
110 #else /* !USE_MOTIF i.e. use Xaw */
113 #include <X11/Xaw3d/Simple.h>
114 #include <X11/Xaw3d/Scrollbar.h>
115 #include <X11/Xaw3d/ThreeD.h>
116 #else /* !HAVE_XAW3D */
117 #include <X11/Xaw/Simple.h>
118 #include <X11/Xaw/Scrollbar.h>
119 #endif /* !HAVE_XAW3D */
121 #define XtNpickTop "pickTop"
122 #endif /* !XtNpickTop */
123 #endif /* !USE_MOTIF */
124 #endif /* USE_TOOLKIT_SCROLL_BARS */
126 #endif /* USE_X_TOOLKIT */
130 #ifndef XtNinitialState
131 #define XtNinitialState "initialState"
135 #include "bitmaps/gray.xbm"
138 #include <X11/XKBlib.h>
141 /* Default to using XIM if available. */
145 bool use_xim
= false; /* configure --without-xim */
148 /* Non-zero means that a HELP_EVENT has been generated since Emacs
151 static bool any_help_event_p
;
153 /* This is a chain of structures for all the X displays currently in
156 struct x_display_info
*x_display_list
;
160 /* The application context for Xt use. */
161 XtAppContext Xt_app_con
;
162 static String Xt_default_resources
[] = {0};
164 /* Non-zero means user is interacting with a toolkit scroll bar. */
165 static bool toolkit_scroll_bar_interaction
;
167 #endif /* USE_X_TOOLKIT */
169 /* Non-zero timeout value means ignore next mouse click if it arrives
170 before that timeout elapses (i.e. as part of the same sequence of
171 events resulting from clicking on a frame to select it). */
173 static Time ignore_next_mouse_click_timeout
;
175 /* Used locally within XTread_socket. */
177 static int x_noop_count
;
180 /* The name of the Emacs icon file. */
181 static Lisp_Object xg_default_icon_file
;
184 /* Some functions take this as char *, not const char *. */
185 static char emacs_class
[] = EMACS_CLASS
;
189 XEMBED_MAPPED
= 1 << 0
194 XEMBED_EMBEDDED_NOTIFY
= 0,
195 XEMBED_WINDOW_ACTIVATE
= 1,
196 XEMBED_WINDOW_DEACTIVATE
= 2,
197 XEMBED_REQUEST_FOCUS
= 3,
199 XEMBED_FOCUS_OUT
= 5,
200 XEMBED_FOCUS_NEXT
= 6,
201 XEMBED_FOCUS_PREV
= 7,
203 XEMBED_MODALITY_ON
= 10,
204 XEMBED_MODALITY_OFF
= 11,
205 XEMBED_REGISTER_ACCELERATOR
= 12,
206 XEMBED_UNREGISTER_ACCELERATOR
= 13,
207 XEMBED_ACTIVATE_ACCELERATOR
= 14
210 static void x_free_cr_resources (struct frame
*);
211 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
212 static void x_raise_frame (struct frame
*);
213 static void x_lower_frame (struct frame
*);
214 static int x_io_error_quitter (Display
*);
215 static struct terminal
*x_create_terminal (struct x_display_info
*);
216 static void x_frame_rehighlight (struct x_display_info
*);
218 static void x_clip_to_row (struct window
*, struct glyph_row
*,
219 enum glyph_row_area
, GC
);
220 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
, int);
221 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
222 enum scroll_bar_part
*,
223 Lisp_Object
*, Lisp_Object
*,
225 static void x_horizontal_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
226 enum scroll_bar_part
*,
227 Lisp_Object
*, Lisp_Object
*,
229 static bool x_handle_net_wm_state (struct frame
*, const XPropertyEvent
*);
230 static void x_check_fullscreen (struct frame
*);
231 static void x_check_expected_move (struct frame
*, int, int);
232 static void x_sync_with_move (struct frame
*, int, int, bool);
233 static int handle_one_xevent (struct x_display_info
*,
234 const XEvent
*, int *,
235 struct input_event
*);
236 #if ! (defined USE_X_TOOLKIT || defined USE_MOTIF)
237 static int x_dispatch_event (XEvent
*, Display
*);
239 static void x_wm_set_window_state (struct frame
*, int);
240 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
241 static void x_initialize (void);
243 static bool get_current_wm_state (struct frame
*, Window
, int *, bool *);
245 /* Flush display of frame F. */
248 x_flush (struct frame
*f
)
250 eassert (f
&& FRAME_X_P (f
));
251 /* Don't call XFlush when it is not safe to redisplay; the X
252 connection may be broken. */
253 if (!NILP (Vinhibit_redisplay
))
257 XFlush (FRAME_X_DISPLAY (f
));
262 /* Remove calls to XFlush by defining XFlush to an empty replacement.
263 Calls to XFlush should be unnecessary because the X output buffer
264 is flushed automatically as needed by calls to XPending,
265 XNextEvent, or XWindowEvent according to the XFlush man page.
266 XTread_socket calls XPending. Removing XFlush improves
269 #define XFlush(DISPLAY) (void) 0
272 /***********************************************************************
274 ***********************************************************************/
278 /* This is a function useful for recording debugging information about
279 the sequence of occurrences in this file. */
287 struct record event_record
[100];
289 int event_record_index
;
292 record_event (char *locus
, int type
)
294 if (event_record_index
== ARRAYELTS (event_record
))
295 event_record_index
= 0;
297 event_record
[event_record_index
].locus
= locus
;
298 event_record
[event_record_index
].type
= type
;
299 event_record_index
++;
306 #define FRAME_CR_CONTEXT(f) ((f)->output_data.x->cr_context)
307 #define FRAME_CR_SURFACE(f) ((f)->output_data.x->cr_surface)
309 static struct x_gc_ext_data
*
310 x_gc_get_ext_data (struct frame
*f
, GC gc
, int create_if_not_found_p
)
312 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
314 XExtData
**head
, *ext_data
;
317 head
= XEHeadOfExtensionList (object
);
318 ext_data
= XFindOnExtensionList (head
, dpyinfo
->ext_codes
->extension
);
319 if (ext_data
== NULL
)
321 if (!create_if_not_found_p
)
325 ext_data
= xzalloc (sizeof (*ext_data
));
326 ext_data
->number
= dpyinfo
->ext_codes
->extension
;
327 ext_data
->private_data
= xzalloc (sizeof (struct x_gc_ext_data
));
328 XAddToExtensionList (head
, ext_data
);
331 return (struct x_gc_ext_data
*) ext_data
->private_data
;
335 x_extension_initialize (struct x_display_info
*dpyinfo
)
337 XExtCodes
*ext_codes
= XAddExtension (dpyinfo
->display
);
339 dpyinfo
->ext_codes
= ext_codes
;
343 x_cr_destroy_surface (struct frame
*f
)
345 if (FRAME_CR_SURFACE (f
))
347 cairo_t
*cr
= FRAME_CR_CONTEXT (f
);
348 cairo_surface_destroy (FRAME_CR_SURFACE (f
));
349 FRAME_CR_SURFACE (f
) = 0;
350 if (cr
) cairo_destroy (cr
);
351 FRAME_CR_CONTEXT (f
) = NULL
;
356 x_begin_cr_clip (struct frame
*f
, GC gc
)
358 cairo_t
*cr
= FRAME_CR_CONTEXT (f
);
363 if (! FRAME_CR_SURFACE (f
))
365 cairo_surface_t
*surface
;
366 surface
= cairo_xlib_surface_create (FRAME_X_DISPLAY (f
),
367 FRAME_X_DRAWABLE (f
),
368 FRAME_DISPLAY_INFO (f
)->visual
,
369 FRAME_PIXEL_WIDTH (f
),
370 FRAME_PIXEL_HEIGHT (f
));
371 cr
= cairo_create (surface
);
372 cairo_surface_destroy (surface
);
375 cr
= cairo_create (FRAME_CR_SURFACE (f
));
376 FRAME_CR_CONTEXT (f
) = cr
;
382 struct x_gc_ext_data
*gc_ext
= x_gc_get_ext_data (f
, gc
, 0);
384 if (gc_ext
&& gc_ext
->n_clip_rects
)
388 for (i
= 0; i
< gc_ext
->n_clip_rects
; i
++)
389 cairo_rectangle (cr
, gc_ext
->clip_rects
[i
].x
,
390 gc_ext
->clip_rects
[i
].y
,
391 gc_ext
->clip_rects
[i
].width
,
392 gc_ext
->clip_rects
[i
].height
);
401 x_end_cr_clip (struct frame
*f
)
403 cairo_restore (FRAME_CR_CONTEXT (f
));
407 x_set_cr_source_with_gc_foreground (struct frame
*f
, GC gc
)
412 XGetGCValues (FRAME_X_DISPLAY (f
), gc
, GCForeground
, &xgcv
);
413 color
.pixel
= xgcv
.foreground
;
414 x_query_color (f
, &color
);
415 cairo_set_source_rgb (FRAME_CR_CONTEXT (f
), color
.red
/ 65535.0,
416 color
.green
/ 65535.0, color
.blue
/ 65535.0);
420 x_set_cr_source_with_gc_background (struct frame
*f
, GC gc
)
425 XGetGCValues (FRAME_X_DISPLAY (f
), gc
, GCBackground
, &xgcv
);
426 color
.pixel
= xgcv
.background
;
427 x_query_color (f
, &color
);
428 cairo_set_source_rgb (FRAME_CR_CONTEXT (f
), color
.red
/ 65535.0,
429 color
.green
/ 65535.0, color
.blue
/ 65535.0);
432 /* Fringe bitmaps. */
434 static int max_fringe_bmp
= 0;
435 static cairo_pattern_t
**fringe_bmp
= 0;
438 x_cr_define_fringe_bitmap (int which
, unsigned short *bits
, int h
, int wd
)
441 cairo_surface_t
*surface
;
443 cairo_pattern_t
*pattern
;
445 if (which
>= max_fringe_bmp
)
448 max_fringe_bmp
= which
+ 20;
449 fringe_bmp
= (cairo_pattern_t
**) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (cairo_pattern_t
*));
450 while (i
< max_fringe_bmp
)
456 surface
= cairo_image_surface_create (CAIRO_FORMAT_A1
, wd
, h
);
457 stride
= cairo_image_surface_get_stride (surface
);
458 data
= cairo_image_surface_get_data (surface
);
460 for (i
= 0; i
< h
; i
++)
462 *((unsigned short *) data
) = bits
[i
];
466 cairo_surface_mark_dirty (surface
);
467 pattern
= cairo_pattern_create_for_surface (surface
);
468 cairo_surface_destroy (surface
);
472 fringe_bmp
[which
] = pattern
;
476 x_cr_destroy_fringe_bitmap (int which
)
478 if (which
>= max_fringe_bmp
)
481 if (fringe_bmp
[which
])
484 cairo_pattern_destroy (fringe_bmp
[which
]);
487 fringe_bmp
[which
] = 0;
491 x_cr_draw_image (struct frame
*f
, GC gc
, cairo_pattern_t
*image
,
492 int src_x
, int src_y
, int width
, int height
,
493 int dest_x
, int dest_y
, bool overlay_p
)
496 cairo_matrix_t matrix
;
497 cairo_surface_t
*surface
;
498 cairo_format_t format
;
500 cr
= x_begin_cr_clip (f
, gc
);
502 cairo_rectangle (cr
, dest_x
, dest_y
, width
, height
);
505 x_set_cr_source_with_gc_background (f
, gc
);
506 cairo_rectangle (cr
, dest_x
, dest_y
, width
, height
);
507 cairo_fill_preserve (cr
);
510 cairo_matrix_init_translate (&matrix
, src_x
- dest_x
, src_y
- dest_y
);
511 cairo_pattern_set_matrix (image
, &matrix
);
512 cairo_pattern_get_surface (image
, &surface
);
513 format
= cairo_image_surface_get_format (surface
);
514 if (format
!= CAIRO_FORMAT_A8
&& format
!= CAIRO_FORMAT_A1
)
516 cairo_set_source (cr
, image
);
521 x_set_cr_source_with_gc_foreground (f
, gc
);
522 cairo_mask (cr
, image
);
528 x_cr_draw_frame (cairo_t
*cr
, struct frame
*f
)
532 width
= FRAME_PIXEL_WIDTH (f
);
533 height
= FRAME_PIXEL_HEIGHT (f
);
535 x_free_cr_resources (f
);
536 FRAME_CR_CONTEXT (f
) = cr
;
537 x_clear_area (f
, 0, 0, width
, height
);
538 expose_frame (f
, 0, 0, width
, height
);
539 FRAME_CR_CONTEXT (f
) = NULL
;
542 static cairo_status_t
543 x_cr_accumulate_data (void *closure
, const unsigned char *data
,
546 Lisp_Object
*acc
= (Lisp_Object
*) closure
;
548 *acc
= Fcons (make_unibyte_string ((char const *) data
, length
), *acc
);
550 return CAIRO_STATUS_SUCCESS
;
554 x_cr_destroy (Lisp_Object arg
)
556 cairo_t
*cr
= (cairo_t
*) XSAVE_POINTER (arg
, 0);
564 x_cr_export_frames (Lisp_Object frames
, cairo_surface_type_t surface_type
)
567 cairo_surface_t
*surface
;
570 void (*surface_set_size_func
) (cairo_surface_t
*, double, double) = NULL
;
571 Lisp_Object acc
= Qnil
;
572 int count
= SPECPDL_INDEX ();
574 specbind (Qredisplay_dont_pause
, Qt
);
575 redisplay_preserve_echo_area (31);
577 f
= XFRAME (XCAR (frames
));
578 frames
= XCDR (frames
);
579 width
= FRAME_PIXEL_WIDTH (f
);
580 height
= FRAME_PIXEL_HEIGHT (f
);
583 #ifdef CAIRO_HAS_PDF_SURFACE
584 if (surface_type
== CAIRO_SURFACE_TYPE_PDF
)
586 surface
= cairo_pdf_surface_create_for_stream (x_cr_accumulate_data
, &acc
,
588 surface_set_size_func
= cairo_pdf_surface_set_size
;
592 #ifdef CAIRO_HAS_PNG_FUNCTIONS
593 if (surface_type
== CAIRO_SURFACE_TYPE_IMAGE
)
594 surface
= cairo_image_surface_create (CAIRO_FORMAT_RGB24
, width
, height
);
597 #ifdef CAIRO_HAS_PS_SURFACE
598 if (surface_type
== CAIRO_SURFACE_TYPE_PS
)
600 surface
= cairo_ps_surface_create_for_stream (x_cr_accumulate_data
, &acc
,
602 surface_set_size_func
= cairo_ps_surface_set_size
;
606 #ifdef CAIRO_HAS_SVG_SURFACE
607 if (surface_type
== CAIRO_SURFACE_TYPE_SVG
)
608 surface
= cairo_svg_surface_create_for_stream (x_cr_accumulate_data
, &acc
,
614 cr
= cairo_create (surface
);
615 cairo_surface_destroy (surface
);
616 record_unwind_protect (x_cr_destroy
, make_save_ptr (cr
));
620 x_free_cr_resources (f
);
621 FRAME_CR_CONTEXT (f
) = cr
;
622 x_clear_area (f
, 0, 0, width
, height
);
623 expose_frame (f
, 0, 0, width
, height
);
624 FRAME_CR_CONTEXT (f
) = NULL
;
629 cairo_surface_show_page (surface
);
630 f
= XFRAME (XCAR (frames
));
631 frames
= XCDR (frames
);
632 width
= FRAME_PIXEL_WIDTH (f
);
633 height
= FRAME_PIXEL_HEIGHT (f
);
634 if (surface_set_size_func
)
635 (*surface_set_size_func
) (surface
, width
, height
);
642 #ifdef CAIRO_HAS_PNG_FUNCTIONS
643 if (surface_type
== CAIRO_SURFACE_TYPE_IMAGE
)
645 cairo_surface_flush (surface
);
646 cairo_surface_write_to_png_stream (surface
, x_cr_accumulate_data
, &acc
);
651 unbind_to (count
, Qnil
);
653 return CALLN (Fapply
, intern ("concat"), Fnreverse (acc
));
656 #endif /* USE_CAIRO */
659 x_free_cr_resources (struct frame
*f
)
664 Lisp_Object rest
, frame
;
665 FOR_EACH_FRAME (rest
, frame
)
666 if (FRAME_X_P (XFRAME (frame
)))
667 x_free_cr_resources (XFRAME (frame
));
671 cairo_t
*cr
= FRAME_CR_CONTEXT (f
);
675 cairo_surface_t
*surface
= cairo_get_target (cr
);
677 if (cairo_surface_get_type (surface
) == CAIRO_SURFACE_TYPE_XLIB
)
680 FRAME_CR_CONTEXT (f
) = NULL
;
688 x_set_clip_rectangles (struct frame
*f
, GC gc
, XRectangle
*rectangles
, int n
)
690 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, rectangles
, n
, Unsorted
);
692 eassert (n
>= 0 && n
<= MAX_CLIP_RECTS
);
695 struct x_gc_ext_data
*gc_ext
= x_gc_get_ext_data (f
, gc
, 1);
697 gc_ext
->n_clip_rects
= n
;
698 memcpy (gc_ext
->clip_rects
, rectangles
, sizeof (XRectangle
) * n
);
704 x_reset_clip_rectangles (struct frame
*f
, GC gc
)
706 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
709 struct x_gc_ext_data
*gc_ext
= x_gc_get_ext_data (f
, gc
, 0);
712 gc_ext
->n_clip_rects
= 0;
718 x_fill_rectangle (struct frame
*f
, GC gc
, int x
, int y
, int width
, int height
)
723 cr
= x_begin_cr_clip (f
, gc
);
724 x_set_cr_source_with_gc_foreground (f
, gc
);
725 cairo_rectangle (cr
, x
, y
, width
, height
);
729 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_DRAWABLE (f
),
730 gc
, x
, y
, width
, height
);
735 x_draw_rectangle (struct frame
*f
, GC gc
, int x
, int y
, int width
, int height
)
740 cr
= x_begin_cr_clip (f
, gc
);
741 x_set_cr_source_with_gc_foreground (f
, gc
);
742 cairo_rectangle (cr
, x
+ 0.5, y
+ 0.5, width
, height
);
743 cairo_set_line_width (cr
, 1);
747 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_DRAWABLE (f
),
748 gc
, x
, y
, width
, height
);
753 x_clear_window (struct frame
*f
)
758 cr
= x_begin_cr_clip (f
, NULL
);
759 x_set_cr_source_with_gc_background (f
, f
->output_data
.x
->normal_gc
);
763 if (FRAME_X_DOUBLE_BUFFERED_P (f
))
764 x_clear_area (f
, 0, 0, FRAME_PIXEL_WIDTH (f
), FRAME_PIXEL_HEIGHT (f
));
766 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
772 x_fill_trapezoid_for_relief (struct frame
*f
, GC gc
, int x
, int y
,
773 int width
, int height
, int top_p
)
777 cr
= x_begin_cr_clip (f
, gc
);
778 x_set_cr_source_with_gc_foreground (f
, gc
);
779 cairo_move_to (cr
, top_p
? x
: x
+ height
, y
);
780 cairo_line_to (cr
, x
, y
+ height
);
781 cairo_line_to (cr
, top_p
? x
+ width
- height
: x
+ width
, y
+ height
);
782 cairo_line_to (cr
, x
+ width
, y
);
789 CORNER_BOTTOM_RIGHT
, /* 0 -> pi/2 */
790 CORNER_BOTTOM_LEFT
, /* pi/2 -> pi */
791 CORNER_TOP_LEFT
, /* pi -> 3pi/2 */
792 CORNER_TOP_RIGHT
, /* 3pi/2 -> 2pi */
797 x_erase_corners_for_relief (struct frame
*f
, GC gc
, int x
, int y
,
798 int width
, int height
,
799 double radius
, double margin
, int corners
)
804 cr
= x_begin_cr_clip (f
, gc
);
805 x_set_cr_source_with_gc_background (f
, gc
);
806 for (i
= 0; i
< CORNER_LAST
; i
++)
807 if (corners
& (1 << i
))
809 double xm
, ym
, xc
, yc
;
811 if (i
== CORNER_TOP_LEFT
|| i
== CORNER_BOTTOM_LEFT
)
812 xm
= x
- margin
, xc
= xm
+ radius
;
814 xm
= x
+ width
+ margin
, xc
= xm
- radius
;
815 if (i
== CORNER_TOP_LEFT
|| i
== CORNER_TOP_RIGHT
)
816 ym
= y
- margin
, yc
= ym
+ radius
;
818 ym
= y
+ height
+ margin
, yc
= ym
- radius
;
820 cairo_move_to (cr
, xm
, ym
);
821 cairo_arc (cr
, xc
, yc
, radius
, i
* M_PI_2
, (i
+ 1) * M_PI_2
);
824 cairo_rectangle (cr
, x
, y
, width
, height
);
830 x_draw_horizontal_wave (struct frame
*f
, GC gc
, int x
, int y
,
831 int width
, int height
, int wave_length
)
834 double dx
= wave_length
, dy
= height
- 1;
837 cr
= x_begin_cr_clip (f
, gc
);
838 x_set_cr_source_with_gc_foreground (f
, gc
);
839 cairo_rectangle (cr
, x
, y
, width
, height
);
844 xoffset
= x
% (wave_length
* 2);
846 xoffset
= wave_length
* 2;
849 xoffset
= x
% (wave_length
* 2) + wave_length
* 2;
850 n
= (width
+ xoffset
) / wave_length
+ 1;
851 if (xoffset
> wave_length
)
853 xoffset
-= wave_length
;
859 cairo_move_to (cr
, x
- xoffset
+ 0.5, y
+ 0.5);
862 cairo_rel_line_to (cr
, dx
, dy
);
865 cairo_set_line_width (cr
, 1);
872 /* Return the struct x_display_info corresponding to DPY. */
874 struct x_display_info
*
875 x_display_info_for_display (Display
*dpy
)
877 struct x_display_info
*dpyinfo
;
879 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
880 if (dpyinfo
->display
== dpy
)
887 x_find_topmost_parent (struct frame
*f
)
889 struct x_output
*x
= f
->output_data
.x
;
890 Window win
= None
, wi
= x
->parent_desc
;
891 Display
*dpy
= FRAME_X_DISPLAY (f
);
893 while (wi
!= FRAME_DISPLAY_INFO (f
)->root_window
)
897 unsigned int nchildren
;
900 if (XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
))
909 #define OPAQUE 0xffffffff
912 x_set_frame_alpha (struct frame
*f
)
914 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
915 Display
*dpy
= FRAME_X_DISPLAY (f
);
916 Window win
= FRAME_OUTER_WINDOW (f
);
918 double alpha_min
= 1.0;
922 if (dpyinfo
->x_highlight_frame
== f
)
927 if (FLOATP (Vframe_alpha_lower_limit
))
928 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
929 else if (INTEGERP (Vframe_alpha_lower_limit
))
930 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
934 else if (alpha
> 1.0)
936 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
939 opac
= alpha
* OPAQUE
;
941 x_catch_errors (dpy
);
943 /* If there is a parent from the window manager, put the property there
944 also, to work around broken window managers that fail to do that.
945 Do this unconditionally as this function is called on reparent when
946 alpha has not changed on the frame. */
948 parent
= x_find_topmost_parent (f
);
950 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
951 XA_CARDINAL
, 32, PropModeReplace
,
952 (unsigned char *) &opac
, 1);
954 /* return unless necessary */
959 unsigned long n
, left
;
961 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
962 0, 1, False
, XA_CARDINAL
,
963 &actual
, &format
, &n
, &left
,
966 if (rc
== Success
&& actual
!= None
)
968 unsigned long value
= *(unsigned long *)data
;
978 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
979 XA_CARDINAL
, 32, PropModeReplace
,
980 (unsigned char *) &opac
, 1);
984 /***********************************************************************
985 Starting and ending an update
986 ***********************************************************************/
988 /* Start an update of frame F. This function is installed as a hook
989 for update_begin, i.e. it is called when update_begin is called.
990 This function is called prior to calls to x_update_window_begin for
991 each window being updated. Currently, there is nothing to do here
992 because all interesting stuff is done on a window basis. */
995 x_update_begin (struct frame
*f
)
998 if (! NILP (tip_frame
) && XFRAME (tip_frame
) == f
999 && ! FRAME_VISIBLE_P (f
))
1002 if (! FRAME_CR_SURFACE (f
))
1006 if (FRAME_GTK_WIDGET (f
))
1008 GdkWindow
*w
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
1009 width
= gdk_window_get_width (w
);
1010 height
= gdk_window_get_height (w
);
1015 width
= FRAME_PIXEL_WIDTH (f
);
1016 height
= FRAME_PIXEL_HEIGHT (f
);
1017 if (! FRAME_EXTERNAL_TOOL_BAR (f
))
1018 height
+= FRAME_TOOL_BAR_HEIGHT (f
);
1019 if (! FRAME_EXTERNAL_MENU_BAR (f
))
1020 height
+= FRAME_MENU_BAR_HEIGHT (f
);
1023 if (width
> 0 && height
> 0)
1026 FRAME_CR_SURFACE (f
) = cairo_image_surface_create
1027 (CAIRO_FORMAT_ARGB32
, width
, height
);
1031 #endif /* USE_CAIRO */
1034 /* Start update of window W. */
1037 x_update_window_begin (struct window
*w
)
1039 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1040 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
1042 w
->output_cursor
= w
->cursor
;
1046 if (f
== hlinfo
->mouse_face_mouse_frame
)
1048 /* Don't do highlighting for mouse motion during the update. */
1049 hlinfo
->mouse_face_defer
= true;
1051 /* If F needs to be redrawn, simply forget about any prior mouse
1053 if (FRAME_GARBAGED_P (f
))
1054 hlinfo
->mouse_face_window
= Qnil
;
1061 /* Draw a vertical window border from (x,y0) to (x,y1) */
1064 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
1066 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1069 face
= FACE_FROM_ID_OR_NULL (f
, VERTICAL_BORDER_FACE_ID
);
1071 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
1075 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
, x
, y0
, 1, y1
- y0
);
1077 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_DRAWABLE (f
),
1078 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
1082 /* Draw a window divider from (x0,y0) to (x1,y1) */
1085 x_draw_window_divider (struct window
*w
, int x0
, int x1
, int y0
, int y1
)
1087 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1088 struct face
*face
= FACE_FROM_ID_OR_NULL (f
, WINDOW_DIVIDER_FACE_ID
);
1089 struct face
*face_first
1090 = FACE_FROM_ID_OR_NULL (f
, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
1091 struct face
*face_last
1092 = FACE_FROM_ID_OR_NULL (f
, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
1093 unsigned long color
= face
? face
->foreground
: FRAME_FOREGROUND_PIXEL (f
);
1094 unsigned long color_first
= (face_first
1095 ? face_first
->foreground
1096 : FRAME_FOREGROUND_PIXEL (f
));
1097 unsigned long color_last
= (face_last
1098 ? face_last
->foreground
1099 : FRAME_FOREGROUND_PIXEL (f
));
1100 Display
*display
= FRAME_X_DISPLAY (f
);
1102 if (y1
- y0
> x1
- x0
&& x1
- x0
> 2)
1105 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_first
);
1106 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1107 x0
, y0
, 1, y1
- y0
);
1108 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
1109 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1110 x0
+ 1, y0
, x1
- x0
- 2, y1
- y0
);
1111 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_last
);
1112 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1113 x1
- 1, y0
, 1, y1
- y0
);
1115 else if (x1
- x0
> y1
- y0
&& y1
- y0
> 3)
1118 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_first
);
1119 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1120 x0
, y0
, x1
- x0
, 1);
1121 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
1122 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1123 x0
, y0
+ 1, x1
- x0
, y1
- y0
- 2);
1124 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_last
);
1125 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1126 x0
, y1
- 1, x1
- x0
, 1);
1130 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
1131 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1132 x0
, y0
, x1
- x0
, y1
- y0
);
1136 /* End update of window W.
1138 Draw vertical borders between horizontally adjacent windows, and
1139 display W's cursor if CURSOR_ON_P is non-zero.
1141 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1142 glyphs in mouse-face were overwritten. In that case we have to
1143 make sure that the mouse-highlight is properly redrawn.
1145 W may be a menu bar pseudo-window in case we don't have X toolkit
1146 support. Such windows don't have a cursor, so don't display it
1150 x_update_window_end (struct window
*w
, bool cursor_on_p
,
1151 bool mouse_face_overwritten_p
)
1153 if (!w
->pseudo_window_p
)
1158 display_and_set_cursor (w
, true,
1159 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
1160 w
->output_cursor
.x
, w
->output_cursor
.y
);
1162 if (draw_window_fringes (w
, true))
1164 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
1165 x_draw_right_divider (w
);
1167 x_draw_vertical_border (w
);
1173 /* If a row with mouse-face was overwritten, arrange for
1174 XTframe_up_to_date to redisplay the mouse highlight. */
1175 if (mouse_face_overwritten_p
)
1177 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
1179 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1180 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1181 hlinfo
->mouse_face_window
= Qnil
;
1185 /* Show the frame back buffer. If frame is double-buffered,
1186 atomically publish to the user's screen graphics updates made since
1187 the last call to show_back_buffer. */
1189 show_back_buffer (struct frame
*f
)
1192 if (FRAME_X_DOUBLE_BUFFERED_P (f
))
1195 XdbeSwapInfo swap_info
;
1196 memset (&swap_info
, 0, sizeof (swap_info
));
1197 swap_info
.swap_window
= FRAME_X_WINDOW (f
);
1198 swap_info
.swap_action
= XdbeCopied
;
1199 XdbeSwapBuffers (FRAME_X_DISPLAY (f
), &swap_info
, 1);
1201 eassert (!"should have back-buffer only with XDBE");
1204 FRAME_X_NEED_BUFFER_FLIP (f
) = false;
1208 /* Updates back buffer and flushes changes to display. Called from
1209 minibuf read code. Note that we display the back buffer even if
1210 buffer flipping is blocked. */
1212 x_flip_and_flush (struct frame
*f
)
1215 if (FRAME_X_NEED_BUFFER_FLIP (f
))
1216 show_back_buffer (f
);
1221 /* End update of frame F. This function is installed as a hook in
1225 x_update_end (struct frame
*f
)
1227 /* Mouse highlight may be displayed again. */
1228 MOUSE_HL_INFO (f
)->mouse_face_defer
= false;
1231 if (FRAME_CR_SURFACE (f
))
1235 #if defined (USE_GTK) && defined (HAVE_GTK3)
1236 if (FRAME_GTK_WIDGET (f
))
1238 GdkWindow
*w
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
1239 cr
= gdk_cairo_create (w
);
1244 cairo_surface_t
*surface
;
1245 int width
= FRAME_PIXEL_WIDTH (f
);
1246 int height
= FRAME_PIXEL_HEIGHT (f
);
1247 if (! FRAME_EXTERNAL_TOOL_BAR (f
))
1248 height
+= FRAME_TOOL_BAR_HEIGHT (f
);
1249 if (! FRAME_EXTERNAL_MENU_BAR (f
))
1250 height
+= FRAME_MENU_BAR_HEIGHT (f
);
1251 surface
= cairo_xlib_surface_create (FRAME_X_DISPLAY (f
),
1252 FRAME_X_DRAWABLE (f
),
1253 FRAME_DISPLAY_INFO (f
)->visual
,
1256 cr
= cairo_create (surface
);
1257 cairo_surface_destroy (surface
);
1260 cairo_set_source_surface (cr
, FRAME_CR_SURFACE (f
), 0, 0);
1269 XFlush (FRAME_X_DISPLAY (f
));
1274 /* This function is called from various places in xdisp.c
1275 whenever a complete update has been performed. */
1278 XTframe_up_to_date (struct frame
*f
)
1280 eassert (FRAME_X_P (f
));
1282 FRAME_MOUSE_UPDATE (f
);
1283 if (!buffer_flipping_blocked_p () && FRAME_X_NEED_BUFFER_FLIP (f
))
1284 show_back_buffer (f
);
1289 XTbuffer_flipping_unblocked_hook (struct frame
*f
)
1291 if (FRAME_X_NEED_BUFFER_FLIP (f
))
1292 show_back_buffer (f
);
1295 /* Clear under internal border if any (GTK has its own version). */
1298 x_clear_under_internal_border (struct frame
*f
)
1300 if (FRAME_INTERNAL_BORDER_WIDTH (f
) > 0)
1302 int border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1303 int width
= FRAME_PIXEL_WIDTH (f
);
1304 int height
= FRAME_PIXEL_HEIGHT (f
);
1305 int margin
= FRAME_TOP_MARGIN_HEIGHT (f
);
1308 x_clear_area (f
, 0, 0, border
, height
);
1309 x_clear_area (f
, 0, margin
, width
, border
);
1310 x_clear_area (f
, width
- border
, 0, border
, height
);
1311 x_clear_area (f
, 0, height
- border
, width
, border
);
1317 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1318 arrow bitmaps, or clear the fringes if no bitmaps are required
1319 before DESIRED_ROW is made current. This function is called from
1320 update_window_line only if it is known that there are differences
1321 between bitmaps to be drawn between current row and DESIRED_ROW. */
1324 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
1328 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1329 desired_row
->redraw_fringe_bitmaps_p
= true;
1331 #ifdef USE_X_TOOLKIT
1332 /* When a window has disappeared, make sure that no rest of
1333 full-width rows stays visible in the internal border. Could
1334 check here if updated window is the leftmost/rightmost window,
1335 but I guess it's not worth doing since vertically split windows
1336 are almost never used, internal border is rarely set, and the
1337 overhead is very small. */
1342 if (windows_or_buffers_changed
1343 && desired_row
->full_width_p
1344 && (f
= XFRAME (w
->frame
),
1345 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
1347 && (height
= desired_row
->visible_height
,
1350 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
1353 x_clear_area (f
, 0, y
, width
, height
);
1354 x_clear_area (f
, FRAME_PIXEL_WIDTH (f
) - width
, y
, width
, height
);
1362 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
1364 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1365 Display
*display
= FRAME_X_DISPLAY (f
);
1366 GC gc
= f
->output_data
.x
->normal_gc
;
1367 struct face
*face
= p
->face
;
1369 /* Must clip because of partially visible lines. */
1370 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
1372 if (p
->bx
>= 0 && !p
->overlay_p
)
1374 /* In case the same realized face is used for fringes and
1375 for something displayed in the text (e.g. face `region' on
1376 mono-displays, the fill style may have been changed to
1377 FillSolid in x_draw_glyph_string_background. */
1379 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
1381 XSetForeground (display
, face
->gc
, face
->background
);
1383 x_fill_rectangle (f
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
1386 XSetForeground (display
, face
->gc
, face
->foreground
);
1390 if (p
->which
&& p
->which
< max_fringe_bmp
)
1394 XGetGCValues (display
, gc
, GCForeground
| GCBackground
, &gcv
);
1395 XSetForeground (display
, gc
, (p
->cursor_p
1396 ? (p
->overlay_p
? face
->background
1397 : f
->output_data
.x
->cursor_pixel
)
1398 : face
->foreground
));
1399 XSetBackground (display
, gc
, face
->background
);
1400 x_cr_draw_image (f
, gc
, fringe_bmp
[p
->which
], 0, p
->dh
,
1401 p
->wd
, p
->h
, p
->x
, p
->y
, p
->overlay_p
);
1402 XSetForeground (display
, gc
, gcv
.foreground
);
1403 XSetBackground (display
, gc
, gcv
.background
);
1405 #else /* not USE_CAIRO */
1408 Drawable drawable
= FRAME_X_DRAWABLE (f
);
1410 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
1411 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
1415 bits
= (char *) (p
->bits
+ p
->dh
);
1417 bits
= (char *) p
->bits
+ p
->dh
;
1419 /* Draw the bitmap. I believe these small pixmaps can be cached
1421 pixmap
= XCreatePixmapFromBitmapData (display
, drawable
, bits
, p
->wd
, p
->h
,
1423 ? (p
->overlay_p
? face
->background
1424 : f
->output_data
.x
->cursor_pixel
)
1425 : face
->foreground
),
1426 face
->background
, depth
);
1430 clipmask
= XCreatePixmapFromBitmapData (display
,
1431 FRAME_DISPLAY_INFO (f
)->root_window
,
1434 gcv
.clip_mask
= clipmask
;
1435 gcv
.clip_x_origin
= p
->x
;
1436 gcv
.clip_y_origin
= p
->y
;
1437 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
1440 XCopyArea (display
, pixmap
, drawable
, gc
, 0, 0,
1441 p
->wd
, p
->h
, p
->x
, p
->y
);
1442 XFreePixmap (display
, pixmap
);
1446 gcv
.clip_mask
= (Pixmap
) 0;
1447 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
1448 XFreePixmap (display
, clipmask
);
1451 #endif /* not USE_CAIRO */
1453 x_reset_clip_rectangles (f
, gc
);
1456 /***********************************************************************
1458 ***********************************************************************/
1462 static void x_set_glyph_string_clipping (struct glyph_string
*);
1463 static void x_set_glyph_string_gc (struct glyph_string
*);
1464 static void x_draw_glyph_string_foreground (struct glyph_string
*);
1465 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
1466 static void x_draw_glyph_string_box (struct glyph_string
*);
1467 static void x_draw_glyph_string (struct glyph_string
*);
1468 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
1469 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
1470 static void x_set_cursor_gc (struct glyph_string
*);
1471 static void x_set_mode_line_face_gc (struct glyph_string
*);
1472 static void x_set_mouse_face_gc (struct glyph_string
*);
1473 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
1474 unsigned long *, double, int);
1475 static void x_setup_relief_color (struct frame
*, struct relief
*,
1476 double, int, unsigned long);
1477 static void x_setup_relief_colors (struct glyph_string
*);
1478 static void x_draw_image_glyph_string (struct glyph_string
*);
1479 static void x_draw_image_relief (struct glyph_string
*);
1480 static void x_draw_image_foreground (struct glyph_string
*);
1481 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
1482 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
1484 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
1485 int, bool, bool, bool, bool, bool,
1487 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
1488 int, bool, bool, XRectangle
*);
1489 static void x_scroll_bar_clear (struct frame
*);
1492 static void x_check_font (struct frame
*, struct font
*);
1496 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1500 x_set_cursor_gc (struct glyph_string
*s
)
1502 if (s
->font
== FRAME_FONT (s
->f
)
1503 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1504 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1506 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1509 /* Cursor on non-default face: must merge. */
1513 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1514 xgcv
.foreground
= s
->face
->background
;
1516 /* If the glyph would be invisible, try a different foreground. */
1517 if (xgcv
.foreground
== xgcv
.background
)
1518 xgcv
.foreground
= s
->face
->foreground
;
1519 if (xgcv
.foreground
== xgcv
.background
)
1520 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1521 if (xgcv
.foreground
== xgcv
.background
)
1522 xgcv
.foreground
= s
->face
->foreground
;
1524 /* Make sure the cursor is distinct from text in this face. */
1525 if (xgcv
.background
== s
->face
->background
1526 && xgcv
.foreground
== s
->face
->foreground
)
1528 xgcv
.background
= s
->face
->foreground
;
1529 xgcv
.foreground
= s
->face
->background
;
1532 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1533 xgcv
.graphics_exposures
= False
;
1534 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1536 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1537 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1540 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1541 = XCreateGC (s
->display
, FRAME_X_DRAWABLE (s
->f
), mask
, &xgcv
);
1543 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1548 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1551 x_set_mouse_face_gc (struct glyph_string
*s
)
1556 /* What face has to be used last for the mouse face? */
1557 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
1558 face
= FACE_FROM_ID_OR_NULL (s
->f
, face_id
);
1560 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1562 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1563 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1565 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1566 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1567 prepare_face_for_display (s
->f
, s
->face
);
1569 if (s
->font
== s
->face
->font
)
1570 s
->gc
= s
->face
->gc
;
1573 /* Otherwise construct scratch_cursor_gc with values from FACE
1578 xgcv
.background
= s
->face
->background
;
1579 xgcv
.foreground
= s
->face
->foreground
;
1580 xgcv
.graphics_exposures
= False
;
1581 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1583 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1584 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1587 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1588 = XCreateGC (s
->display
, FRAME_X_DRAWABLE (s
->f
), mask
, &xgcv
);
1590 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1593 eassert (s
->gc
!= 0);
1597 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1598 Faces to use in the mode line have already been computed when the
1599 matrix was built, so there isn't much to do, here. */
1602 x_set_mode_line_face_gc (struct glyph_string
*s
)
1604 s
->gc
= s
->face
->gc
;
1608 /* Set S->gc of glyph string S for drawing that glyph string. Set
1609 S->stippled_p to a non-zero value if the face of S has a stipple
1613 x_set_glyph_string_gc (struct glyph_string
*s
)
1615 prepare_face_for_display (s
->f
, s
->face
);
1617 if (s
->hl
== DRAW_NORMAL_TEXT
)
1619 s
->gc
= s
->face
->gc
;
1620 s
->stippled_p
= s
->face
->stipple
!= 0;
1622 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1624 x_set_mode_line_face_gc (s
);
1625 s
->stippled_p
= s
->face
->stipple
!= 0;
1627 else if (s
->hl
== DRAW_CURSOR
)
1629 x_set_cursor_gc (s
);
1630 s
->stippled_p
= false;
1632 else if (s
->hl
== DRAW_MOUSE_FACE
)
1634 x_set_mouse_face_gc (s
);
1635 s
->stippled_p
= s
->face
->stipple
!= 0;
1637 else if (s
->hl
== DRAW_IMAGE_RAISED
1638 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1640 s
->gc
= s
->face
->gc
;
1641 s
->stippled_p
= s
->face
->stipple
!= 0;
1646 /* GC must have been set. */
1647 eassert (s
->gc
!= 0);
1651 /* Set clipping for output of glyph string S. S may be part of a mode
1652 line or menu if we don't have X toolkit support. */
1655 x_set_glyph_string_clipping (struct glyph_string
*s
)
1657 XRectangle
*r
= s
->clip
;
1658 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1661 x_set_clip_rectangles (s
->f
, s
->gc
, r
, n
);
1666 /* Set SRC's clipping for output of glyph string DST. This is called
1667 when we are drawing DST's left_overhang or right_overhang only in
1671 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1676 r
.width
= src
->width
;
1678 r
.height
= src
->height
;
1681 x_set_clip_rectangles (dst
->f
, dst
->gc
, &r
, 1);
1686 Compute left and right overhang of glyph string S. */
1689 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1692 && (s
->first_glyph
->type
== CHAR_GLYPH
1693 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1695 struct font_metrics metrics
;
1697 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1699 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1700 struct font
*font
= s
->font
;
1703 for (i
= 0; i
< s
->nchars
; i
++)
1704 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1705 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1709 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1711 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1713 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1714 ? metrics
.rbearing
- metrics
.width
: 0);
1715 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1719 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1720 s
->left_overhang
= - s
->cmp
->lbearing
;
1725 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1728 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1731 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1732 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1733 x_fill_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
1734 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1738 /* Draw the background of glyph_string S. If S->background_filled_p
1739 is non-zero don't draw it. FORCE_P non-zero means draw the
1740 background even if it wouldn't be drawn normally. This is used
1741 when a string preceding S draws into the background of S, or S
1742 contains the first component of a composition. */
1745 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1747 /* Nothing to do if background has already been drawn or if it
1748 shouldn't be drawn in the first place. */
1749 if (!s
->background_filled_p
)
1751 int box_line_width
= max (s
->face
->box_line_width
, 0);
1755 /* Fill background with a stipple pattern. */
1756 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1757 x_fill_rectangle (s
->f
, s
->gc
, s
->x
,
1758 s
->y
+ box_line_width
,
1759 s
->background_width
,
1760 s
->height
- 2 * box_line_width
);
1761 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1762 s
->background_filled_p
= true;
1764 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1765 /* When xdisp.c ignores FONT_HEIGHT, we cannot trust
1766 font dimensions, since the actual glyphs might be
1767 much smaller. So in that case we always clear the
1768 rectangle with background color. */
1769 || FONT_TOO_HIGH (s
->font
)
1770 || s
->font_not_found_p
1771 || s
->extends_to_end_of_line_p
1774 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1775 s
->background_width
,
1776 s
->height
- 2 * box_line_width
);
1777 s
->background_filled_p
= true;
1783 /* Draw the foreground of glyph string S. */
1786 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1790 /* If first glyph of S has a left box line, start drawing the text
1791 of S to the right of that box line. */
1792 if (s
->face
->box
!= FACE_NO_BOX
1793 && s
->first_glyph
->left_box_line_p
)
1794 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1798 /* Draw characters of S as rectangles if S's font could not be
1800 if (s
->font_not_found_p
)
1802 for (i
= 0; i
< s
->nchars
; ++i
)
1804 struct glyph
*g
= s
->first_glyph
+ i
;
1805 x_draw_rectangle (s
->f
,
1806 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1808 x
+= g
->pixel_width
;
1813 struct font
*font
= s
->font
;
1814 int boff
= font
->baseline_offset
;
1817 if (font
->vertical_centering
)
1818 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1820 y
= s
->ybase
- boff
;
1822 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1823 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, false);
1825 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, true);
1826 if (s
->face
->overstrike
)
1827 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, false);
1831 /* Draw the foreground of composite glyph string S. */
1834 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1837 struct font
*font
= s
->font
;
1839 /* If first glyph of S has a left box line, start drawing the text
1840 of S to the right of that box line. */
1841 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1842 && s
->first_glyph
->left_box_line_p
)
1843 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1847 /* S is a glyph string for a composition. S->cmp_from is the index
1848 of the first character drawn for glyphs of this composition.
1849 S->cmp_from == 0 means we are drawing the very first character of
1850 this composition. */
1852 /* Draw a rectangle for the composition if the font for the very
1853 first character of the composition could not be loaded. */
1854 if (s
->font_not_found_p
)
1856 if (s
->cmp_from
== 0)
1857 x_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
1858 s
->width
- 1, s
->height
- 1);
1860 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1864 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1865 /* TAB in a composition means display glyphs with padding
1866 space on the left or right. */
1867 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1869 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1870 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1872 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, false);
1873 if (s
->face
->overstrike
)
1874 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, false);
1879 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1884 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1886 glyph
= LGSTRING_GLYPH (gstring
, i
);
1887 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1888 width
+= LGLYPH_WIDTH (glyph
);
1891 int xoff
, yoff
, wadjust
;
1895 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1896 if (s
->face
->overstrike
)
1897 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, false);
1900 xoff
= LGLYPH_XOFF (glyph
);
1901 yoff
= LGLYPH_YOFF (glyph
);
1902 wadjust
= LGLYPH_WADJUST (glyph
);
1903 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, false);
1904 if (s
->face
->overstrike
)
1905 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
,
1914 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1915 if (s
->face
->overstrike
)
1916 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, false);
1922 /* Draw the foreground of glyph string S for glyphless characters. */
1925 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1927 struct glyph
*glyph
= s
->first_glyph
;
1931 /* If first glyph of S has a left box line, start drawing the text
1932 of S to the right of that box line. */
1933 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1934 && s
->first_glyph
->left_box_line_p
)
1935 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1941 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1943 char buf
[7], *str
= NULL
;
1944 int len
= glyph
->u
.glyphless
.len
;
1946 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1949 && CHAR_TABLE_P (Vglyphless_char_display
)
1950 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1954 = (! glyph
->u
.glyphless
.for_no_font
1955 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1956 glyph
->u
.glyphless
.ch
)
1957 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1958 if (STRINGP (acronym
))
1959 str
= SSDATA (acronym
);
1962 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1964 sprintf (buf
, "%0*X",
1965 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1966 glyph
->u
.glyphless
.ch
+ 0u);
1972 int upper_len
= (len
+ 1) / 2;
1975 /* It is assured that all LEN characters in STR is ASCII. */
1976 for (j
= 0; j
< len
; j
++)
1978 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1979 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1981 s
->font
->driver
->draw (s
, 0, upper_len
,
1982 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1983 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1985 s
->font
->driver
->draw (s
, upper_len
, len
,
1986 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1987 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1990 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1991 x_draw_rectangle (s
->f
, s
->gc
,
1992 x
, s
->ybase
- glyph
->ascent
,
1993 glyph
->pixel_width
- 1,
1994 glyph
->ascent
+ glyph
->descent
- 1);
1995 x
+= glyph
->pixel_width
;
1999 #ifdef USE_X_TOOLKIT
2003 /* Return the frame on which widget WIDGET is used.. Abort if frame
2004 cannot be determined. */
2006 static struct frame
*
2007 x_frame_of_widget (Widget widget
)
2009 struct x_display_info
*dpyinfo
;
2010 Lisp_Object tail
, frame
;
2013 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
2015 /* Find the top-level shell of the widget. Note that this function
2016 can be called when the widget is not yet realized, so XtWindow
2017 (widget) == 0. That's the reason we can't simply use
2018 x_any_window_to_frame. */
2019 while (!XtIsTopLevelShell (widget
))
2020 widget
= XtParent (widget
);
2022 /* Look for a frame with that top-level widget. Allocate the color
2023 on that frame to get the right gamma correction value. */
2024 FOR_EACH_FRAME (tail
, frame
)
2028 && f
->output_data
.nothing
!= 1
2029 && FRAME_DISPLAY_INFO (f
) == dpyinfo
2030 && f
->output_data
.x
->widget
== widget
)
2036 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2037 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2038 If this produces the same color as PIXEL, try a color where all RGB
2039 values have DELTA added. Return the allocated color in *PIXEL.
2040 DISPLAY is the X display, CMAP is the colormap to operate on.
2041 Value is true if successful. */
2044 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
2045 unsigned long *pixel
, double factor
, int delta
)
2047 struct frame
*f
= x_frame_of_widget (widget
);
2048 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
2051 #endif /* USE_LUCID */
2054 /* Structure specifying which arguments should be passed by Xt to
2055 cvt_string_to_pixel. We want the widget's screen and colormap. */
2057 static XtConvertArgRec cvt_string_to_pixel_args
[] =
2059 {XtWidgetBaseOffset
, (XtPointer
) offsetof (WidgetRec
, core
.screen
),
2061 {XtWidgetBaseOffset
, (XtPointer
) offsetof (WidgetRec
, core
.colormap
),
2066 /* The address of this variable is returned by
2067 cvt_string_to_pixel. */
2069 static Pixel cvt_string_to_pixel_value
;
2072 /* Convert a color name to a pixel color.
2074 DPY is the display we are working on.
2076 ARGS is an array of *NARGS XrmValue structures holding additional
2077 information about the widget for which the conversion takes place.
2078 The contents of this array are determined by the specification
2079 in cvt_string_to_pixel_args.
2081 FROM is a pointer to an XrmValue which points to the color name to
2082 convert. TO is an XrmValue in which to return the pixel color.
2084 CLOSURE_RET is a pointer to user-data, in which we record if
2085 we allocated the color or not.
2087 Value is True if successful, False otherwise. */
2090 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
2091 XrmValue
*from
, XrmValue
*to
,
2092 XtPointer
*closure_ret
)
2102 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
2103 "wrongParameters", "cvt_string_to_pixel",
2105 "Screen and colormap args required", NULL
, NULL
);
2109 screen
= *(Screen
**) args
[0].addr
;
2110 cmap
= *(Colormap
*) args
[1].addr
;
2111 color_name
= (String
) from
->addr
;
2113 if (strcmp (color_name
, XtDefaultBackground
) == 0)
2115 *closure_ret
= (XtPointer
) False
;
2116 pixel
= WhitePixelOfScreen (screen
);
2118 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
2120 *closure_ret
= (XtPointer
) False
;
2121 pixel
= BlackPixelOfScreen (screen
);
2123 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
2124 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
2126 pixel
= color
.pixel
;
2127 *closure_ret
= (XtPointer
) True
;
2132 Cardinal nparams
= 1;
2134 params
[0] = color_name
;
2135 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
2136 "badValue", "cvt_string_to_pixel",
2137 "XtToolkitError", "Invalid color '%s'",
2142 if (to
->addr
!= NULL
)
2144 if (to
->size
< sizeof (Pixel
))
2146 to
->size
= sizeof (Pixel
);
2150 *(Pixel
*) to
->addr
= pixel
;
2154 cvt_string_to_pixel_value
= pixel
;
2155 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
2158 to
->size
= sizeof (Pixel
);
2163 /* Free a pixel color which was previously allocated via
2164 cvt_string_to_pixel. This is registered as the destructor
2165 for this type of resource via XtSetTypeConverter.
2167 APP is the application context in which we work.
2169 TO is a pointer to an XrmValue holding the color to free.
2170 CLOSURE is the value we stored in CLOSURE_RET for this color
2171 in cvt_string_to_pixel.
2173 ARGS and NARGS are like for cvt_string_to_pixel. */
2176 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
2181 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
2183 "Screen and colormap arguments required",
2186 else if (closure
!= NULL
)
2188 /* We did allocate the pixel, so free it. */
2189 Screen
*screen
= *(Screen
**) args
[0].addr
;
2190 Colormap cmap
= *(Colormap
*) args
[1].addr
;
2191 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
2192 (Pixel
*) to
->addr
, 1);
2197 #endif /* USE_X_TOOLKIT */
2200 /* Value is an array of XColor structures for the contents of the
2201 color map of display DPY. Set *NCELLS to the size of the array.
2202 Note that this probably shouldn't be called for large color maps,
2203 say a 24-bit TrueColor map. */
2205 static const XColor
*
2206 x_color_cells (Display
*dpy
, int *ncells
)
2208 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
2211 if (dpyinfo
->color_cells
== NULL
)
2213 Screen
*screen
= dpyinfo
->screen
;
2214 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
2217 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
2218 sizeof *dpyinfo
->color_cells
);
2219 dpyinfo
->ncolor_cells
= ncolor_cells
;
2221 for (i
= 0; i
< ncolor_cells
; ++i
)
2222 dpyinfo
->color_cells
[i
].pixel
= i
;
2224 XQueryColors (dpy
, dpyinfo
->cmap
,
2225 dpyinfo
->color_cells
, ncolor_cells
);
2228 *ncells
= dpyinfo
->ncolor_cells
;
2229 return dpyinfo
->color_cells
;
2233 /* On frame F, translate pixel colors to RGB values for the NCOLORS
2234 colors in COLORS. Use cached information, if available. */
2237 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
2239 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2241 if (dpyinfo
->red_bits
> 0)
2243 /* For TrueColor displays, we can decompose the RGB value
2246 unsigned int rmult
, gmult
, bmult
;
2247 unsigned int rmask
, gmask
, bmask
;
2249 rmask
= (1 << dpyinfo
->red_bits
) - 1;
2250 gmask
= (1 << dpyinfo
->green_bits
) - 1;
2251 bmask
= (1 << dpyinfo
->blue_bits
) - 1;
2252 /* If we're widening, for example, 8 bits in the pixel value to
2253 16 bits for the separate-color representation, we want to
2254 extrapolate the lower bits based on those bits available --
2255 in other words, we'd like 0xff to become 0xffff instead of
2256 the 0xff00 we'd get by just zero-filling the lower bits.
2258 We generate a 32-bit scaled-up value and shift it, in case
2259 the bit count doesn't divide 16 evenly (e.g., when dealing
2260 with a 3-3-2 bit RGB display), to get more of the lower bits
2263 Should we cache the multipliers in dpyinfo? Maybe
2264 special-case the 8-8-8 common case? */
2265 rmult
= 0xffffffff / rmask
;
2266 gmult
= 0xffffffff / gmask
;
2267 bmult
= 0xffffffff / bmask
;
2269 for (i
= 0; i
< ncolors
; ++i
)
2271 unsigned int r
, g
, b
;
2272 unsigned long pixel
= colors
[i
].pixel
;
2274 r
= (pixel
>> dpyinfo
->red_offset
) & rmask
;
2275 g
= (pixel
>> dpyinfo
->green_offset
) & gmask
;
2276 b
= (pixel
>> dpyinfo
->blue_offset
) & bmask
;
2278 colors
[i
].red
= (r
* rmult
) >> 16;
2279 colors
[i
].green
= (g
* gmult
) >> 16;
2280 colors
[i
].blue
= (b
* bmult
) >> 16;
2285 if (dpyinfo
->color_cells
)
2288 for (i
= 0; i
< ncolors
; ++i
)
2290 unsigned long pixel
= colors
[i
].pixel
;
2291 eassert (pixel
< dpyinfo
->ncolor_cells
);
2292 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
2293 colors
[i
] = dpyinfo
->color_cells
[pixel
];
2298 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
2302 /* On frame F, translate pixel color to RGB values for the color in
2303 COLOR. Use cached information, if available. */
2306 x_query_color (struct frame
*f
, XColor
*color
)
2308 x_query_colors (f
, color
, 1);
2312 /* On frame F, translate the color name to RGB values. Use cached
2313 information, if possible.
2315 Note that there is currently no way to clean old entries out of the
2316 cache. However, it is limited to names in the server's database,
2317 and names we've actually looked up; list-colors-display is probably
2318 the most color-intensive case we're likely to hit. */
2320 Status
x_parse_color (struct frame
*f
, const char *color_name
,
2323 Display
*dpy
= FRAME_X_DISPLAY (f
);
2324 Colormap cmap
= FRAME_X_COLORMAP (f
);
2325 struct color_name_cache_entry
*cache_entry
;
2327 if (color_name
[0] == '#')
2329 /* The hex form is parsed directly by XParseColor without
2330 talking to the X server. No need for caching. */
2331 return XParseColor (dpy
, cmap
, color_name
, color
);
2334 for (cache_entry
= FRAME_DISPLAY_INFO (f
)->color_names
; cache_entry
;
2335 cache_entry
= cache_entry
->next
)
2337 if (!xstrcasecmp(cache_entry
->name
, color_name
))
2339 *color
= cache_entry
->rgb
;
2344 if (XParseColor (dpy
, cmap
, color_name
, color
) == 0)
2345 /* No caching of negative results, currently. */
2348 cache_entry
= xzalloc (sizeof *cache_entry
);
2349 cache_entry
->rgb
= *color
;
2350 cache_entry
->name
= xstrdup (color_name
);
2351 cache_entry
->next
= FRAME_DISPLAY_INFO (f
)->color_names
;
2352 FRAME_DISPLAY_INFO (f
)->color_names
= cache_entry
;
2357 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
2358 exact match can't be allocated, try the nearest color available.
2359 Value is true if successful. Set *COLOR to the color
2363 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
2367 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
2370 /* If we got to this point, the colormap is full, so we're going
2371 to try to get the next closest color. The algorithm used is
2372 a least-squares matching, which is what X uses for closest
2373 color matching with StaticColor visuals. */
2375 int max_color_delta
= 255;
2376 int max_delta
= 3 * max_color_delta
;
2377 int nearest_delta
= max_delta
+ 1;
2379 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
2381 for (nearest
= i
= 0; i
< ncells
; ++i
)
2383 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2384 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2385 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2386 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2388 if (delta
< nearest_delta
)
2391 nearest_delta
= delta
;
2395 color
->red
= cells
[nearest
].red
;
2396 color
->green
= cells
[nearest
].green
;
2397 color
->blue
= cells
[nearest
].blue
;
2398 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
2402 /* If allocation succeeded, and the allocated pixel color is not
2403 equal to a cached pixel color recorded earlier, there was a
2404 change in the colormap, so clear the color cache. */
2405 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
2408 if (dpyinfo
->color_cells
)
2410 XColor
*cached_color
= &dpyinfo
->color_cells
[color
->pixel
];
2411 if (cached_color
->red
!= color
->red
2412 || cached_color
->blue
!= color
->blue
2413 || cached_color
->green
!= color
->green
)
2415 xfree (dpyinfo
->color_cells
);
2416 dpyinfo
->color_cells
= NULL
;
2417 dpyinfo
->ncolor_cells
= 0;
2422 #ifdef DEBUG_X_COLORS
2424 register_color (color
->pixel
);
2425 #endif /* DEBUG_X_COLORS */
2431 /* Allocate the color COLOR->pixel on frame F, colormap CMAP, after
2432 gamma correction. If an exact match can't be allocated, try the
2433 nearest color available. Value is true if successful. Set *COLOR
2434 to the color allocated. */
2437 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
2439 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2441 gamma_correct (f
, color
);
2443 if (dpyinfo
->red_bits
> 0)
2445 color
->pixel
= x_make_truecolor_pixel (dpyinfo
,
2452 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
2456 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
2457 It's necessary to do this instead of just using PIXEL directly to
2458 get color reference counts right. */
2461 x_copy_color (struct frame
*f
, unsigned long pixel
)
2465 /* If display has an immutable color map, freeing colors is not
2466 necessary and some servers don't allow it. Since we won't free a
2467 color once we've allocated it, we don't need to re-allocate it to
2468 maintain the server's reference count. */
2469 if (!x_mutable_colormap (FRAME_X_VISUAL (f
)))
2472 color
.pixel
= pixel
;
2474 /* The color could still be found in the color_cells array. */
2475 x_query_color (f
, &color
);
2476 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2478 #ifdef DEBUG_X_COLORS
2479 register_color (pixel
);
2485 /* Brightness beyond which a color won't have its highlight brightness
2488 Nominally, highlight colors for `3d' faces are calculated by
2489 brightening an object's color by a constant scale factor, but this
2490 doesn't yield good results for dark colors, so for colors who's
2491 brightness is less than this value (on a scale of 0-65535) have an
2492 use an additional additive factor.
2494 The value here is set so that the default menu-bar/mode-line color
2495 (grey75) will not have its highlights changed at all. */
2496 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
2499 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2500 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2501 If this produces the same color as PIXEL, try a color where all RGB
2502 values have DELTA added. Return the allocated color in *PIXEL.
2503 DISPLAY is the X display, CMAP is the colormap to operate on.
2504 Value is non-zero if successful. */
2507 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
,
2508 unsigned long *pixel
, double factor
, int delta
)
2514 /* Get RGB color values. */
2515 color
.pixel
= *pixel
;
2516 x_query_color (f
, &color
);
2518 /* Change RGB values by specified FACTOR. Avoid overflow! */
2519 eassert (factor
>= 0);
2520 new.red
= min (0xffff, factor
* color
.red
);
2521 new.green
= min (0xffff, factor
* color
.green
);
2522 new.blue
= min (0xffff, factor
* color
.blue
);
2524 /* Calculate brightness of COLOR. */
2525 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
2527 /* We only boost colors that are darker than
2528 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2529 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2530 /* Make an additive adjustment to NEW, because it's dark enough so
2531 that scaling by FACTOR alone isn't enough. */
2533 /* How far below the limit this color is (0 - 1, 1 being darker). */
2534 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2535 /* The additive adjustment. */
2536 int min_delta
= delta
* dimness
* factor
/ 2;
2540 new.red
= max (0, new.red
- min_delta
);
2541 new.green
= max (0, new.green
- min_delta
);
2542 new.blue
= max (0, new.blue
- min_delta
);
2546 new.red
= min (0xffff, min_delta
+ new.red
);
2547 new.green
= min (0xffff, min_delta
+ new.green
);
2548 new.blue
= min (0xffff, min_delta
+ new.blue
);
2552 /* Try to allocate the color. */
2553 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2556 if (new.pixel
== *pixel
)
2558 /* If we end up with the same color as before, try adding
2559 delta to the RGB values. */
2560 x_free_colors (f
, &new.pixel
, 1);
2562 new.red
= min (0xffff, delta
+ color
.red
);
2563 new.green
= min (0xffff, delta
+ color
.green
);
2564 new.blue
= min (0xffff, delta
+ color
.blue
);
2565 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2576 /* Set up the foreground color for drawing relief lines of glyph
2577 string S. RELIEF is a pointer to a struct relief containing the GC
2578 with which lines will be drawn. Use a color that is FACTOR or
2579 DELTA lighter or darker than the relief's background which is found
2580 in S->f->output_data.x->relief_background. If such a color cannot
2581 be allocated, use DEFAULT_PIXEL, instead. */
2584 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
,
2585 int delta
, unsigned long default_pixel
)
2588 struct x_output
*di
= f
->output_data
.x
;
2589 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
2590 unsigned long pixel
;
2591 unsigned long background
= di
->relief_background
;
2592 Colormap cmap
= FRAME_X_COLORMAP (f
);
2593 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2594 Display
*dpy
= FRAME_X_DISPLAY (f
);
2596 xgcv
.graphics_exposures
= False
;
2597 xgcv
.line_width
= 1;
2599 /* Free previously allocated color. The color cell will be reused
2600 when it has been freed as many times as it was allocated, so this
2601 doesn't affect faces using the same colors. */
2602 if (relief
->gc
&& relief
->pixel
!= -1)
2604 x_free_colors (f
, &relief
->pixel
, 1);
2608 /* Allocate new color. */
2609 xgcv
.foreground
= default_pixel
;
2611 if (dpyinfo
->n_planes
!= 1
2612 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
2613 xgcv
.foreground
= relief
->pixel
= pixel
;
2615 if (relief
->gc
== 0)
2617 xgcv
.stipple
= dpyinfo
->gray
;
2619 relief
->gc
= XCreateGC (dpy
, FRAME_X_DRAWABLE (f
), mask
, &xgcv
);
2622 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
2626 /* Set up colors for the relief lines around glyph string S. */
2629 x_setup_relief_colors (struct glyph_string
*s
)
2631 struct x_output
*di
= s
->f
->output_data
.x
;
2632 unsigned long color
;
2634 if (s
->face
->use_box_color_for_shadows_p
)
2635 color
= s
->face
->box_color
;
2636 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2638 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2639 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2644 /* Get the background color of the face. */
2645 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2646 color
= xgcv
.background
;
2649 if (di
->white_relief
.gc
== 0
2650 || color
!= di
->relief_background
)
2652 di
->relief_background
= color
;
2653 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2654 WHITE_PIX_DEFAULT (s
->f
));
2655 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2656 BLACK_PIX_DEFAULT (s
->f
));
2661 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2662 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2663 to draw, it must be >= 0. RAISED_P means draw a raised
2664 relief. LEFT_P means draw a relief on the left side of
2665 the rectangle. RIGHT_P means draw a relief on the right
2666 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2670 x_draw_relief_rect (struct frame
*f
,
2671 int left_x
, int top_y
, int right_x
, int bottom_y
,
2672 int width
, bool raised_p
, bool top_p
, bool bot_p
,
2673 bool left_p
, bool right_p
,
2674 XRectangle
*clip_rect
)
2677 GC top_left_gc
, bottom_right_gc
;
2682 top_left_gc
= f
->output_data
.x
->white_relief
.gc
;
2683 bottom_right_gc
= f
->output_data
.x
->black_relief
.gc
;
2687 top_left_gc
= f
->output_data
.x
->black_relief
.gc
;
2688 bottom_right_gc
= f
->output_data
.x
->white_relief
.gc
;
2691 x_set_clip_rectangles (f
, top_left_gc
, clip_rect
, 1);
2692 x_set_clip_rectangles (f
, bottom_right_gc
, clip_rect
, 1);
2696 x_fill_rectangle (f
, top_left_gc
, left_x
, top_y
,
2697 width
, bottom_y
+ 1 - top_y
);
2699 corners
|= 1 << CORNER_TOP_LEFT
;
2701 corners
|= 1 << CORNER_BOTTOM_LEFT
;
2705 x_fill_rectangle (f
, bottom_right_gc
, right_x
+ 1 - width
, top_y
,
2706 width
, bottom_y
+ 1 - top_y
);
2708 corners
|= 1 << CORNER_TOP_RIGHT
;
2710 corners
|= 1 << CORNER_BOTTOM_RIGHT
;
2715 x_fill_rectangle (f
, top_left_gc
, left_x
, top_y
,
2716 right_x
+ 1 - left_x
, width
);
2718 x_fill_trapezoid_for_relief (f
, top_left_gc
, left_x
, top_y
,
2719 right_x
+ 1 - left_x
, width
, 1);
2724 x_fill_rectangle (f
, bottom_right_gc
, left_x
, bottom_y
+ 1 - width
,
2725 right_x
+ 1 - left_x
, width
);
2727 x_fill_trapezoid_for_relief (f
, bottom_right_gc
,
2728 left_x
, bottom_y
+ 1 - width
,
2729 right_x
+ 1 - left_x
, width
, 0);
2731 if (left_p
&& width
!= 1)
2732 x_fill_rectangle (f
, bottom_right_gc
, left_x
, top_y
,
2733 1, bottom_y
+ 1 - top_y
);
2734 if (top_p
&& width
!= 1)
2735 x_fill_rectangle (f
, bottom_right_gc
, left_x
, top_y
,
2736 right_x
+ 1 - left_x
, 1);
2739 XSetBackground (FRAME_X_DISPLAY (f
), top_left_gc
,
2740 FRAME_BACKGROUND_PIXEL (f
));
2741 x_erase_corners_for_relief (f
, top_left_gc
, left_x
, top_y
,
2742 right_x
- left_x
+ 1, bottom_y
- top_y
+ 1,
2746 x_reset_clip_rectangles (f
, top_left_gc
);
2747 x_reset_clip_rectangles (f
, bottom_right_gc
);
2749 Display
*dpy
= FRAME_X_DISPLAY (f
);
2750 Drawable drawable
= FRAME_X_DRAWABLE (f
);
2755 gc
= f
->output_data
.x
->white_relief
.gc
;
2757 gc
= f
->output_data
.x
->black_relief
.gc
;
2758 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2760 /* This code is more complicated than it has to be, because of two
2761 minor hacks to make the boxes look nicer: (i) if width > 1, draw
2762 the outermost line using the black relief. (ii) Omit the four
2769 XDrawLine (dpy
, drawable
, gc
,
2770 left_x
+ left_p
, top_y
,
2771 right_x
+ !right_p
, top_y
);
2773 for (i
= 1; i
< width
; ++i
)
2774 XDrawLine (dpy
, drawable
, gc
,
2775 left_x
+ i
* left_p
, top_y
+ i
,
2776 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2783 XDrawLine (dpy
, drawable
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
2785 x_clear_area(f
, left_x
, top_y
, 1, 1);
2786 x_clear_area(f
, left_x
, bottom_y
, 1, 1);
2788 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
2789 XDrawLine (dpy
, drawable
, gc
,
2790 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
2791 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
2794 XSetClipMask (dpy
, gc
, None
);
2796 gc
= f
->output_data
.x
->black_relief
.gc
;
2798 gc
= f
->output_data
.x
->white_relief
.gc
;
2799 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2803 /* Outermost top line. */
2805 XDrawLine (dpy
, drawable
, gc
,
2806 left_x
+ left_p
, top_y
,
2807 right_x
+ !right_p
, top_y
);
2809 /* Outermost left line. */
2811 XDrawLine (dpy
, drawable
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
2817 XDrawLine (dpy
, drawable
, gc
,
2818 left_x
+ left_p
, bottom_y
,
2819 right_x
+ !right_p
, bottom_y
);
2820 for (i
= 1; i
< width
; ++i
)
2821 XDrawLine (dpy
, drawable
, gc
,
2822 left_x
+ i
* left_p
, bottom_y
- i
,
2823 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2829 x_clear_area(f
, right_x
, top_y
, 1, 1);
2830 x_clear_area(f
, right_x
, bottom_y
, 1, 1);
2831 for (i
= 0; i
< width
; ++i
)
2832 XDrawLine (dpy
, drawable
, gc
,
2833 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
2834 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
2837 x_reset_clip_rectangles (f
, gc
);
2843 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2844 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2845 draw, it must be >= 0. LEFT_P means draw a line on the
2846 left side of the rectangle. RIGHT_P means draw a line
2847 on the right side of the rectangle. CLIP_RECT is the clipping
2848 rectangle to use when drawing. */
2851 x_draw_box_rect (struct glyph_string
*s
,
2852 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2853 bool left_p
, bool right_p
, XRectangle
*clip_rect
)
2857 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2858 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2859 x_set_clip_rectangles (s
->f
, s
->gc
, clip_rect
, 1);
2862 x_fill_rectangle (s
->f
, s
->gc
,
2863 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2867 x_fill_rectangle (s
->f
, s
->gc
,
2868 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2871 x_fill_rectangle (s
->f
, s
->gc
,
2872 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2876 x_fill_rectangle (s
->f
, s
->gc
,
2877 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2879 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2880 x_reset_clip_rectangles (s
->f
, s
->gc
);
2884 /* Draw a box around glyph string S. */
2887 x_draw_glyph_string_box (struct glyph_string
*s
)
2889 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
;
2890 bool raised_p
, left_p
, right_p
;
2891 struct glyph
*last_glyph
;
2892 XRectangle clip_rect
;
2894 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2895 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2896 : window_box_right (s
->w
, s
->area
));
2898 /* The glyph that may have a right box line. */
2899 last_glyph
= (s
->cmp
|| s
->img
2901 : s
->first_glyph
+ s
->nchars
- 1);
2903 width
= eabs (s
->face
->box_line_width
);
2904 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2906 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2908 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2910 bottom_y
= top_y
+ s
->height
- 1;
2912 left_p
= (s
->first_glyph
->left_box_line_p
2913 || (s
->hl
== DRAW_MOUSE_FACE
2915 || s
->prev
->hl
!= s
->hl
)));
2916 right_p
= (last_glyph
->right_box_line_p
2917 || (s
->hl
== DRAW_MOUSE_FACE
2919 || s
->next
->hl
!= s
->hl
)));
2921 get_glyph_string_clip_rect (s
, &clip_rect
);
2923 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2924 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2925 left_p
, right_p
, &clip_rect
);
2928 x_setup_relief_colors (s
);
2929 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2930 width
, raised_p
, true, true, left_p
, right_p
,
2936 /* Draw foreground of image glyph string S. */
2939 x_draw_image_foreground (struct glyph_string
*s
)
2942 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2944 /* If first glyph of S has a left box line, start drawing it to the
2945 right of that line. */
2946 if (s
->face
->box
!= FACE_NO_BOX
2947 && s
->first_glyph
->left_box_line_p
2949 x
+= eabs (s
->face
->box_line_width
);
2951 /* If there is a margin around the image, adjust x- and y-position
2953 if (s
->slice
.x
== 0)
2954 x
+= s
->img
->hmargin
;
2955 if (s
->slice
.y
== 0)
2956 y
+= s
->img
->vmargin
;
2962 /* We can't set both a clip mask and use XSetClipRectangles
2963 because the latter also sets a clip mask. We also can't
2964 trust on the shape extension to be available
2965 (XShapeCombineRegion). So, compute the rectangle to draw
2967 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2970 XRectangle clip_rect
, image_rect
, r
;
2972 xgcv
.clip_mask
= s
->img
->mask
;
2973 xgcv
.clip_x_origin
= x
;
2974 xgcv
.clip_y_origin
= y
;
2975 xgcv
.function
= GXcopy
;
2976 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2978 get_glyph_string_clip_rect (s
, &clip_rect
);
2981 image_rect
.width
= s
->slice
.width
;
2982 image_rect
.height
= s
->slice
.height
;
2983 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2984 XCopyArea (s
->display
, s
->img
->pixmap
,
2985 FRAME_X_DRAWABLE (s
->f
), s
->gc
,
2986 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2987 r
.width
, r
.height
, r
.x
, r
.y
);
2991 XRectangle clip_rect
, image_rect
, r
;
2993 get_glyph_string_clip_rect (s
, &clip_rect
);
2996 image_rect
.width
= s
->slice
.width
;
2997 image_rect
.height
= s
->slice
.height
;
2998 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2999 XCopyArea (s
->display
, s
->img
->pixmap
,
3000 FRAME_X_DRAWABLE (s
->f
), s
->gc
,
3001 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
3002 r
.width
, r
.height
, r
.x
, r
.y
);
3004 /* When the image has a mask, we can expect that at
3005 least part of a mouse highlight or a block cursor will
3006 be visible. If the image doesn't have a mask, make
3007 a block cursor visible by drawing a rectangle around
3008 the image. I believe it's looking better if we do
3009 nothing here for mouse-face. */
3010 if (s
->hl
== DRAW_CURSOR
)
3012 int relief
= eabs (s
->img
->relief
);
3013 x_draw_rectangle (s
->f
, s
->gc
,
3014 x
- relief
, y
- relief
,
3015 s
->slice
.width
+ relief
*2 - 1,
3016 s
->slice
.height
+ relief
*2 - 1);
3021 /* Draw a rectangle if image could not be loaded. */
3022 x_draw_rectangle (s
->f
, s
->gc
, x
, y
,
3023 s
->slice
.width
- 1, s
->slice
.height
- 1);
3027 /* Draw a relief around the image glyph string S. */
3030 x_draw_image_relief (struct glyph_string
*s
)
3033 bool raised_p
, top_p
, bot_p
, left_p
, right_p
;
3034 int extra_x
, extra_y
;
3037 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3039 /* If first glyph of S has a left box line, start drawing it to the
3040 right of that line. */
3041 if (s
->face
->box
!= FACE_NO_BOX
3042 && s
->first_glyph
->left_box_line_p
3044 x
+= eabs (s
->face
->box_line_width
);
3046 /* If there is a margin around the image, adjust x- and y-position
3048 if (s
->slice
.x
== 0)
3049 x
+= s
->img
->hmargin
;
3050 if (s
->slice
.y
== 0)
3051 y
+= s
->img
->vmargin
;
3053 if (s
->hl
== DRAW_IMAGE_SUNKEN
3054 || s
->hl
== DRAW_IMAGE_RAISED
)
3056 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3057 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3061 thick
= eabs (s
->img
->relief
);
3062 raised_p
= s
->img
->relief
> 0;
3065 x1
= x
+ s
->slice
.width
- 1;
3066 y1
= y
+ s
->slice
.height
- 1;
3068 extra_x
= extra_y
= 0;
3069 if (s
->face
->id
== TOOL_BAR_FACE_ID
)
3071 if (CONSP (Vtool_bar_button_margin
)
3072 && INTEGERP (XCAR (Vtool_bar_button_margin
))
3073 && INTEGERP (XCDR (Vtool_bar_button_margin
)))
3075 extra_x
= XINT (XCAR (Vtool_bar_button_margin
));
3076 extra_y
= XINT (XCDR (Vtool_bar_button_margin
));
3078 else if (INTEGERP (Vtool_bar_button_margin
))
3079 extra_x
= extra_y
= XINT (Vtool_bar_button_margin
);
3082 top_p
= bot_p
= left_p
= right_p
= false;
3084 if (s
->slice
.x
== 0)
3085 x
-= thick
+ extra_x
, left_p
= true;
3086 if (s
->slice
.y
== 0)
3087 y
-= thick
+ extra_y
, top_p
= true;
3088 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
3089 x1
+= thick
+ extra_x
, right_p
= true;
3090 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
3091 y1
+= thick
+ extra_y
, bot_p
= true;
3093 x_setup_relief_colors (s
);
3094 get_glyph_string_clip_rect (s
, &r
);
3095 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
3096 top_p
, bot_p
, left_p
, right_p
, &r
);
3100 /* Draw the foreground of image glyph string S to PIXMAP. */
3103 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
3106 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3108 /* If first glyph of S has a left box line, start drawing it to the
3109 right of that line. */
3110 if (s
->face
->box
!= FACE_NO_BOX
3111 && s
->first_glyph
->left_box_line_p
3113 x
+= eabs (s
->face
->box_line_width
);
3115 /* If there is a margin around the image, adjust x- and y-position
3117 if (s
->slice
.x
== 0)
3118 x
+= s
->img
->hmargin
;
3119 if (s
->slice
.y
== 0)
3120 y
+= s
->img
->vmargin
;
3126 /* We can't set both a clip mask and use XSetClipRectangles
3127 because the latter also sets a clip mask. We also can't
3128 trust on the shape extension to be available
3129 (XShapeCombineRegion). So, compute the rectangle to draw
3131 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3135 xgcv
.clip_mask
= s
->img
->mask
;
3136 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
3137 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
3138 xgcv
.function
= GXcopy
;
3139 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3141 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3142 s
->slice
.x
, s
->slice
.y
,
3143 s
->slice
.width
, s
->slice
.height
, x
, y
);
3144 XSetClipMask (s
->display
, s
->gc
, None
);
3148 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3149 s
->slice
.x
, s
->slice
.y
,
3150 s
->slice
.width
, s
->slice
.height
, x
, y
);
3152 /* When the image has a mask, we can expect that at
3153 least part of a mouse highlight or a block cursor will
3154 be visible. If the image doesn't have a mask, make
3155 a block cursor visible by drawing a rectangle around
3156 the image. I believe it's looking better if we do
3157 nothing here for mouse-face. */
3158 if (s
->hl
== DRAW_CURSOR
)
3160 int r
= eabs (s
->img
->relief
);
3161 x_draw_rectangle (s
->f
, s
->gc
, x
- r
, y
- r
,
3162 s
->slice
.width
+ r
*2 - 1,
3163 s
->slice
.height
+ r
*2 - 1);
3168 /* Draw a rectangle if image could not be loaded. */
3169 x_draw_rectangle (s
->f
, s
->gc
, x
, y
,
3170 s
->slice
.width
- 1, s
->slice
.height
- 1);
3174 /* Draw part of the background of glyph string S. X, Y, W, and H
3175 give the rectangle to draw. */
3178 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
3182 /* Fill background with a stipple pattern. */
3183 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3184 x_fill_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
3185 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3188 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3192 /* Draw image glyph string S.
3195 s->x +-------------------------
3198 | +-------------------------
3201 | | +-------------------
3207 x_draw_image_glyph_string (struct glyph_string
*s
)
3209 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
3210 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3212 Pixmap pixmap
= None
;
3215 if (s
->slice
.y
== 0)
3216 height
-= box_line_vwidth
;
3217 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
3218 height
-= box_line_vwidth
;
3220 /* Fill background with face under the image. Do it only if row is
3221 taller than image or if image has a clip mask to reduce
3223 s
->stippled_p
= s
->face
->stipple
!= 0;
3224 if (height
> s
->slice
.height
3228 || s
->img
->pixmap
== 0
3229 || s
->width
!= s
->background_width
)
3233 /* Create a pixmap as large as the glyph string. Fill it
3234 with the background color. Copy the image to it, using
3235 its mask. Copy the temporary pixmap to the display. */
3236 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3237 int depth
= DefaultDepthOfScreen (screen
);
3239 /* Create a pixmap as large as the glyph string. */
3240 pixmap
= XCreatePixmap (s
->display
, FRAME_X_DRAWABLE (s
->f
),
3241 s
->background_width
,
3244 /* Don't clip in the following because we're working on the
3246 XSetClipMask (s
->display
, s
->gc
, None
);
3248 /* Fill the pixmap with the background color/stipple. */
3251 /* Fill background with a stipple pattern. */
3252 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3253 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
3254 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3255 0, 0, s
->background_width
, s
->height
);
3256 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3257 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
3262 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3264 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3265 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3266 0, 0, s
->background_width
, s
->height
);
3267 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3274 int width
= s
->background_width
;
3276 if (s
->first_glyph
->left_box_line_p
3279 x
+= box_line_hwidth
;
3280 width
-= box_line_hwidth
;
3283 if (s
->slice
.y
== 0)
3284 y
+= box_line_vwidth
;
3286 x_draw_glyph_string_bg_rect (s
, x
, y
, width
, height
);
3289 s
->background_filled_p
= true;
3292 /* Draw the foreground. */
3294 if (s
->img
->cr_data
)
3296 cairo_t
*cr
= x_begin_cr_clip (s
->f
, s
->gc
);
3298 int x
= s
->x
+ s
->img
->hmargin
;
3299 int y
= s
->y
+ s
->img
->vmargin
;
3300 int width
= s
->background_width
;
3302 cairo_set_source_surface (cr
, s
->img
->cr_data
,
3305 cairo_rectangle (cr
, x
, y
, width
, height
);
3307 x_end_cr_clip (s
->f
);
3313 x_draw_image_foreground_1 (s
, pixmap
);
3314 x_set_glyph_string_clipping (s
);
3315 XCopyArea (s
->display
, pixmap
, FRAME_X_DRAWABLE (s
->f
), s
->gc
,
3316 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3317 XFreePixmap (s
->display
, pixmap
);
3320 x_draw_image_foreground (s
);
3322 /* If we must draw a relief around the image, do it. */
3324 || s
->hl
== DRAW_IMAGE_RAISED
3325 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3326 x_draw_image_relief (s
);
3330 /* Draw stretch glyph string S. */
3333 x_draw_stretch_glyph_string (struct glyph_string
*s
)
3335 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3337 if (s
->hl
== DRAW_CURSOR
3338 && !x_stretch_cursor_p
)
3340 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
3341 wide as the stretch glyph. */
3342 int width
, background_width
= s
->background_width
;
3345 if (!s
->row
->reversed_p
)
3347 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3351 background_width
-= left_x
- x
;
3357 /* In R2L rows, draw the cursor on the right edge of the
3359 int right_x
= window_box_right (s
->w
, TEXT_AREA
);
3361 if (x
+ background_width
> right_x
)
3362 background_width
-= x
- right_x
;
3363 x
+= background_width
;
3365 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
3366 if (s
->row
->reversed_p
)
3370 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
3372 /* Clear rest using the GC of the original non-cursor face. */
3373 if (width
< background_width
)
3376 int w
= background_width
- width
, h
= s
->height
;
3380 if (!s
->row
->reversed_p
)
3384 if (s
->row
->mouse_face_p
3385 && cursor_in_mouse_face_p (s
->w
))
3387 x_set_mouse_face_gc (s
);
3393 get_glyph_string_clip_rect (s
, &r
);
3394 x_set_clip_rectangles (s
->f
, gc
, &r
, 1);
3396 if (s
->face
->stipple
)
3398 /* Fill background with a stipple pattern. */
3399 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3400 x_fill_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3401 XSetFillStyle (s
->display
, gc
, FillSolid
);
3406 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
3407 XSetForeground (s
->display
, gc
, xgcv
.background
);
3408 x_fill_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3409 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
3412 x_reset_clip_rectangles (s
->f
, gc
);
3415 else if (!s
->background_filled_p
)
3417 int background_width
= s
->background_width
;
3418 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3420 /* Don't draw into left margin, fringe or scrollbar area
3421 except for header line and mode line. */
3422 if (x
< left_x
&& !s
->row
->mode_line_p
)
3424 background_width
-= left_x
- x
;
3427 if (background_width
> 0)
3428 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
3431 s
->background_filled_p
= true;
3435 Draw a wavy line under S. The wave fills wave_height pixels from y0.
3441 wave_height = 3 | * * * *
3446 x_draw_underwave (struct glyph_string
*s
)
3448 int wave_height
= 3, wave_length
= 2;
3450 x_draw_horizontal_wave (s
->f
, s
->gc
, s
->x
, s
->ybase
- wave_height
+ 3,
3451 s
->width
, wave_height
, wave_length
);
3452 #else /* not USE_CAIRO */
3453 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, xmax
;
3455 XRectangle wave_clip
, string_clip
, final_clip
;
3458 dy
= wave_height
- 1;
3460 y0
= s
->ybase
- wave_height
+ 3;
3464 /* Find and set clipping rectangle */
3468 wave_clip
.width
= width
;
3469 wave_clip
.height
= wave_height
;
3470 get_glyph_string_clip_rect (s
, &string_clip
);
3472 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
3475 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
3477 /* Draw the waves */
3479 x1
= x0
- (x0
% dx
);
3481 odd
= (x1
/ dx
) & 1;
3489 if (INT_MAX
- dx
< xmax
)
3494 XDrawLine (s
->display
, FRAME_X_DRAWABLE (s
->f
), s
->gc
, x1
, y1
, x2
, y2
);
3496 x2
+= dx
, y2
= y0
+ odd
*dy
;
3500 /* Restore previous clipping rectangle(s) */
3501 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
3502 #endif /* not USE_CAIRO */
3506 /* Draw glyph string S. */
3509 x_draw_glyph_string (struct glyph_string
*s
)
3511 bool relief_drawn_p
= false;
3513 /* If S draws into the background of its successors, draw the
3514 background of the successors first so that S can draw into it.
3515 This makes S->next use XDrawString instead of XDrawImageString. */
3516 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
3519 struct glyph_string
*next
;
3521 for (width
= 0, next
= s
->next
;
3522 next
&& width
< s
->right_overhang
;
3523 width
+= next
->width
, next
= next
->next
)
3524 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
3526 x_set_glyph_string_gc (next
);
3527 x_set_glyph_string_clipping (next
);
3528 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
3529 x_draw_stretch_glyph_string (next
);
3531 x_draw_glyph_string_background (next
, true);
3532 next
->num_clips
= 0;
3536 /* Set up S->gc, set clipping and draw S. */
3537 x_set_glyph_string_gc (s
);
3539 /* Draw relief (if any) in advance for char/composition so that the
3540 glyph string can be drawn over it. */
3541 if (!s
->for_overlaps
3542 && s
->face
->box
!= FACE_NO_BOX
3543 && (s
->first_glyph
->type
== CHAR_GLYPH
3544 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3547 x_set_glyph_string_clipping (s
);
3548 x_draw_glyph_string_background (s
, true);
3549 x_draw_glyph_string_box (s
);
3550 x_set_glyph_string_clipping (s
);
3551 relief_drawn_p
= true;
3553 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
3555 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
3556 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
3557 /* We must clip just this glyph. left_overhang part has already
3558 drawn when s->prev was drawn, and right_overhang part will be
3559 drawn later when s->next is drawn. */
3560 x_set_glyph_string_clipping_exactly (s
, s
);
3562 x_set_glyph_string_clipping (s
);
3564 switch (s
->first_glyph
->type
)
3567 x_draw_image_glyph_string (s
);
3571 x_draw_xwidget_glyph_string (s
);
3575 x_draw_stretch_glyph_string (s
);
3579 if (s
->for_overlaps
)
3580 s
->background_filled_p
= true;
3582 x_draw_glyph_string_background (s
, false);
3583 x_draw_glyph_string_foreground (s
);
3586 case COMPOSITE_GLYPH
:
3587 if (s
->for_overlaps
|| (s
->cmp_from
> 0
3588 && ! s
->first_glyph
->u
.cmp
.automatic
))
3589 s
->background_filled_p
= true;
3591 x_draw_glyph_string_background (s
, true);
3592 x_draw_composite_glyph_string_foreground (s
);
3595 case GLYPHLESS_GLYPH
:
3596 if (s
->for_overlaps
)
3597 s
->background_filled_p
= true;
3599 x_draw_glyph_string_background (s
, true);
3600 x_draw_glyphless_glyph_string_foreground (s
);
3607 if (!s
->for_overlaps
)
3609 /* Draw underline. */
3610 if (s
->face
->underline_p
)
3612 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
3614 if (s
->face
->underline_defaulted_p
)
3615 x_draw_underwave (s
);
3619 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3620 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3621 x_draw_underwave (s
);
3622 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3625 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
3627 unsigned long thickness
, position
;
3630 if (s
->prev
&& s
->prev
->face
->underline_p
3631 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
3633 /* We use the same underline style as the previous one. */
3634 thickness
= s
->prev
->underline_thickness
;
3635 position
= s
->prev
->underline_position
;
3639 struct font
*font
= font_for_underline_metrics (s
);
3641 /* Get the underline thickness. Default is 1 pixel. */
3642 if (font
&& font
->underline_thickness
> 0)
3643 thickness
= font
->underline_thickness
;
3646 if (x_underline_at_descent_line
)
3647 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
3650 /* Get the underline position. This is the recommended
3651 vertical offset in pixels from the baseline to the top of
3652 the underline. This is a signed value according to the
3653 specs, and its default is
3655 ROUND ((maximum descent) / 2), with
3656 ROUND(x) = floor (x + 0.5) */
3658 if (x_use_underline_position_properties
3659 && font
&& font
->underline_position
>= 0)
3660 position
= font
->underline_position
;
3662 position
= (font
->descent
+ 1) / 2;
3664 position
= underline_minimum_offset
;
3666 position
= max (position
, underline_minimum_offset
);
3668 /* Check the sanity of thickness and position. We should
3669 avoid drawing underline out of the current line area. */
3670 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
3671 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
3672 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
3673 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
3674 s
->underline_thickness
= thickness
;
3675 s
->underline_position
= position
;
3676 y
= s
->ybase
+ position
;
3677 if (s
->face
->underline_defaulted_p
)
3678 x_fill_rectangle (s
->f
, s
->gc
,
3679 s
->x
, y
, s
->width
, thickness
);
3683 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3684 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3685 x_fill_rectangle (s
->f
, s
->gc
,
3686 s
->x
, y
, s
->width
, thickness
);
3687 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3691 /* Draw overline. */
3692 if (s
->face
->overline_p
)
3694 unsigned long dy
= 0, h
= 1;
3696 if (s
->face
->overline_color_defaulted_p
)
3697 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3702 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3703 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3704 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3706 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3710 /* Draw strike-through. */
3711 if (s
->face
->strike_through_p
)
3713 /* Y-coordinate and height of the glyph string's first
3714 glyph. We cannot use s->y and s->height because those
3715 could be larger if there are taller display elements
3716 (e.g., characters displayed with a larger font) in the
3718 int glyph_y
= s
->ybase
- s
->first_glyph
->ascent
;
3719 int glyph_height
= s
->first_glyph
->ascent
+ s
->first_glyph
->descent
;
3720 /* Strike-through width and offset from the glyph string's
3722 unsigned long h
= 1;
3723 unsigned long dy
= (glyph_height
- h
) / 2;
3725 if (s
->face
->strike_through_color_defaulted_p
)
3726 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, glyph_y
+ dy
,
3731 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3732 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3733 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, glyph_y
+ dy
,
3735 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3739 /* Draw relief if not yet drawn. */
3740 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3741 x_draw_glyph_string_box (s
);
3745 struct glyph_string
*prev
;
3747 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
3748 if (prev
->hl
!= s
->hl
3749 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
3751 /* As prev was drawn while clipped to its own area, we
3752 must draw the right_overhang part using s->hl now. */
3753 enum draw_glyphs_face save
= prev
->hl
;
3756 x_set_glyph_string_gc (prev
);
3757 x_set_glyph_string_clipping_exactly (s
, prev
);
3758 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
3759 x_draw_glyph_string_foreground (prev
);
3761 x_draw_composite_glyph_string_foreground (prev
);
3762 x_reset_clip_rectangles (prev
->f
, prev
->gc
);
3764 prev
->num_clips
= 0;
3770 struct glyph_string
*next
;
3772 for (next
= s
->next
; next
; next
= next
->next
)
3773 if (next
->hl
!= s
->hl
3774 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
3776 /* As next will be drawn while clipped to its own area,
3777 we must draw the left_overhang part using s->hl now. */
3778 enum draw_glyphs_face save
= next
->hl
;
3781 x_set_glyph_string_gc (next
);
3782 x_set_glyph_string_clipping_exactly (s
, next
);
3783 if (next
->first_glyph
->type
== CHAR_GLYPH
)
3784 x_draw_glyph_string_foreground (next
);
3786 x_draw_composite_glyph_string_foreground (next
);
3787 x_reset_clip_rectangles (next
->f
, next
->gc
);
3789 next
->num_clips
= 0;
3790 next
->clip_head
= s
->next
;
3795 /* Reset clipping. */
3796 x_reset_clip_rectangles (s
->f
, s
->gc
);
3800 /* Shift display to make room for inserted glyphs. */
3803 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
3805 /* Never called on a GUI frame, see
3806 http://lists.gnu.org/archive/html/emacs-devel/2015-05/msg00456.html
3808 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_DRAWABLE (f
), FRAME_X_DRAWABLE (f
),
3809 f
->output_data
.x
->normal_gc
,
3810 x
, y
, width
, height
,
3814 /* Delete N glyphs at the nominal cursor position. Not implemented
3818 x_delete_glyphs (struct frame
*f
, register int n
)
3824 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
3825 If they are <= 0, this is probably an error. */
3827 static ATTRIBUTE_UNUSED
void
3828 x_clear_area1 (Display
*dpy
, Window window
,
3829 int x
, int y
, int width
, int height
, int exposures
)
3831 eassert (width
> 0 && height
> 0);
3832 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
3836 x_clear_area (struct frame
*f
, int x
, int y
, int width
, int height
)
3841 eassert (width
> 0 && height
> 0);
3843 cr
= x_begin_cr_clip (f
, NULL
);
3844 x_set_cr_source_with_gc_background (f
, f
->output_data
.x
->normal_gc
);
3845 cairo_rectangle (cr
, x
, y
, width
, height
);
3849 if (FRAME_X_DOUBLE_BUFFERED_P (f
))
3850 XFillRectangle (FRAME_X_DISPLAY (f
),
3851 FRAME_X_DRAWABLE (f
),
3852 f
->output_data
.x
->reverse_gc
,
3853 x
, y
, width
, height
);
3855 x_clear_area1 (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3856 x
, y
, width
, height
, False
);
3861 /* Clear an entire frame. */
3864 x_clear_frame (struct frame
*f
)
3866 /* Clearing the frame will erase any cursor, so mark them all as no
3868 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3872 font_drop_xrender_surfaces (f
);
3875 /* We have to clear the scroll bars. If we have changed colors or
3876 something like that, then they should be notified. */
3877 x_scroll_bar_clear (f
);
3879 XFlush (FRAME_X_DISPLAY (f
));
3884 /* RIF: Show hourglass cursor on frame F. */
3887 x_show_hourglass (struct frame
*f
)
3889 Display
*dpy
= FRAME_X_DISPLAY (f
);
3893 struct x_output
*x
= FRAME_X_OUTPUT (f
);
3894 #ifdef USE_X_TOOLKIT
3897 if (FRAME_OUTER_WINDOW (f
))
3900 x
->hourglass_p
= true;
3902 if (!x
->hourglass_window
)
3904 unsigned long mask
= CWCursor
;
3905 XSetWindowAttributes attrs
;
3907 Window parent
= FRAME_X_WINDOW (f
);
3909 Window parent
= FRAME_OUTER_WINDOW (f
);
3911 attrs
.cursor
= x
->hourglass_cursor
;
3913 x
->hourglass_window
= XCreateWindow
3914 (dpy
, parent
, 0, 0, 32000, 32000, 0, 0,
3915 InputOnly
, CopyFromParent
, mask
, &attrs
);
3918 XMapRaised (dpy
, x
->hourglass_window
);
3924 /* RIF: Cancel hourglass cursor on frame F. */
3927 x_hide_hourglass (struct frame
*f
)
3929 struct x_output
*x
= FRAME_X_OUTPUT (f
);
3931 /* Watch out for newly created frames. */
3932 if (x
->hourglass_window
)
3934 XUnmapWindow (FRAME_X_DISPLAY (f
), x
->hourglass_window
);
3935 /* Sync here because XTread_socket looks at the
3936 hourglass_p flag that is reset to zero below. */
3937 XSync (FRAME_X_DISPLAY (f
), False
);
3938 x
->hourglass_p
= false;
3942 /* Invert the middle quarter of the frame for .15 sec. */
3945 XTflash (struct frame
*f
)
3951 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
3952 when the scroll bars and the edit widget share the same X window. */
3953 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
3955 cairo_t
*cr
= gdk_cairo_create (window
);
3956 cairo_set_source_rgb (cr
, 1, 1, 1);
3957 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
3958 #define XFillRectangle(d, win, gc, x, y, w, h) \
3960 cairo_rectangle (cr, x, y, w, h); \
3964 #else /* ! HAVE_GTK3 */
3967 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
3968 ^ FRAME_BACKGROUND_PIXEL (f
));
3969 vals
.function
= GDK_XOR
;
3970 gc
= gdk_gc_new_with_values (window
,
3971 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
3972 #define XFillRectangle(d, win, gc, x, y, w, h) \
3973 gdk_draw_rectangle (window, gc, true, x, y, w, h)
3974 #endif /* ! HAVE_GTK3 */
3975 #else /* ! USE_GTK */
3978 /* Create a GC that will use the GXxor function to flip foreground
3979 pixels into background pixels. */
3983 values
.function
= GXxor
;
3984 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3985 ^ FRAME_BACKGROUND_PIXEL (f
));
3987 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3988 GCFunction
| GCForeground
, &values
);
3992 /* Get the height not including a menu bar widget. */
3993 int height
= FRAME_PIXEL_HEIGHT (f
);
3994 /* Height of each line to flash. */
3995 int flash_height
= FRAME_LINE_HEIGHT (f
);
3996 /* These will be the left and right margins of the rectangles. */
3997 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3998 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3999 int width
= flash_right
- flash_left
;
4001 /* If window is tall, flash top and bottom line. */
4002 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4004 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4006 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4007 + FRAME_TOP_MARGIN_HEIGHT (f
)),
4008 width
, flash_height
);
4009 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4011 (height
- flash_height
4012 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4013 width
, flash_height
);
4017 /* If it is short, flash it all. */
4018 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4019 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4020 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4025 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
4026 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
4028 /* Keep waiting until past the time wakeup or any input gets
4030 while (! detect_input_pending ())
4032 struct timespec current
= current_timespec ();
4033 struct timespec timeout
;
4035 /* Break if result would not be positive. */
4036 if (timespec_cmp (wakeup
, current
) <= 0)
4039 /* How long `select' should wait. */
4040 timeout
= make_timespec (0, 10 * 1000 * 1000);
4042 /* Try to wait that long--but we might wake up sooner. */
4043 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
4047 /* If window is tall, flash top and bottom line. */
4048 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
4050 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4052 (FRAME_INTERNAL_BORDER_WIDTH (f
)
4053 + FRAME_TOP_MARGIN_HEIGHT (f
)),
4054 width
, flash_height
);
4055 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4057 (height
- flash_height
4058 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
4059 width
, flash_height
);
4062 /* If it is short, flash it all. */
4063 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4064 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4065 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4071 g_object_unref (G_OBJECT (gc
));
4073 #undef XFillRectangle
4075 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
4086 XTtoggle_invisible_pointer (struct frame
*f
, bool invisible
)
4089 FRAME_DISPLAY_INFO (f
)->toggle_visible_pointer (f
, invisible
);
4094 /* Make audible bell. */
4097 XTring_bell (struct frame
*f
)
4099 if (FRAME_X_DISPLAY (f
))
4107 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
4109 XBell (FRAME_X_DISPLAY (f
), 0);
4111 XFlush (FRAME_X_DISPLAY (f
));
4117 /***********************************************************************
4119 ***********************************************************************/
4121 /* Perform an insert-lines or delete-lines operation, inserting N
4122 lines or deleting -N lines at vertical position VPOS. */
4125 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
4131 /* Scroll part of the display as described by RUN. */
4134 x_scroll_run (struct window
*w
, struct run
*run
)
4136 struct frame
*f
= XFRAME (w
->frame
);
4137 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
4139 /* Get frame-relative bounding box of the text display area of W,
4140 without mode lines. Include in this box the left and right
4142 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
4144 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
4145 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
4146 bottom_y
= y
+ height
;
4150 /* Scrolling up. Make sure we don't copy part of the mode
4151 line at the bottom. */
4152 if (from_y
+ run
->height
> bottom_y
)
4153 height
= bottom_y
- from_y
;
4155 height
= run
->height
;
4159 /* Scrolling down. Make sure we don't copy over the mode line.
4161 if (to_y
+ run
->height
> bottom_y
)
4162 height
= bottom_y
- to_y
;
4164 height
= run
->height
;
4169 /* Cursor off. Will be switched on again in x_update_window_end. */
4173 SET_FRAME_GARBAGED (f
);
4175 XCopyArea (FRAME_X_DISPLAY (f
),
4176 FRAME_X_DRAWABLE (f
), FRAME_X_DRAWABLE (f
),
4177 f
->output_data
.x
->normal_gc
,
4188 /***********************************************************************
4190 ***********************************************************************/
4194 frame_highlight (struct frame
*f
)
4196 /* We used to only do this if Vx_no_window_manager was non-nil, but
4197 the ICCCM (section 4.1.6) says that the window's border pixmap
4198 and border pixel are window attributes which are "private to the
4199 client", so we can always change it to whatever we want. */
4201 /* I recently started to get errors in this XSetWindowBorder, depending on
4202 the window-manager in use, tho something more is at play since I've been
4203 using that same window-manager binary for ever. Let's not crash just
4204 because of this (bug#9310). */
4205 x_catch_errors (FRAME_X_DISPLAY (f
));
4206 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4207 f
->output_data
.x
->border_pixel
);
4208 x_uncatch_errors ();
4210 x_update_cursor (f
, true);
4211 x_set_frame_alpha (f
);
4215 frame_unhighlight (struct frame
*f
)
4217 /* We used to only do this if Vx_no_window_manager was non-nil, but
4218 the ICCCM (section 4.1.6) says that the window's border pixmap
4219 and border pixel are window attributes which are "private to the
4220 client", so we can always change it to whatever we want. */
4222 /* Same as above for XSetWindowBorder (bug#9310). */
4223 x_catch_errors (FRAME_X_DISPLAY (f
));
4224 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4225 f
->output_data
.x
->border_tile
);
4226 x_uncatch_errors ();
4228 x_update_cursor (f
, true);
4229 x_set_frame_alpha (f
);
4232 /* The focus has changed. Update the frames as necessary to reflect
4233 the new situation. Note that we can't change the selected frame
4234 here, because the Lisp code we are interrupting might become confused.
4235 Each event gets marked with the frame in which it occurred, so the
4236 Lisp code can tell when the switch took place by examining the events. */
4239 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
4241 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
4243 if (frame
!= dpyinfo
->x_focus_frame
)
4245 /* Set this before calling other routines, so that they see
4246 the correct value of x_focus_frame. */
4247 dpyinfo
->x_focus_frame
= frame
;
4249 if (old_focus
&& old_focus
->auto_lower
)
4250 x_lower_frame (old_focus
);
4252 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
4253 dpyinfo
->x_pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
4255 dpyinfo
->x_pending_autoraise_frame
= NULL
;
4258 x_frame_rehighlight (dpyinfo
);
4261 /* Handle FocusIn and FocusOut state changes for FRAME.
4262 If FRAME has focus and there exists more than one frame, puts
4263 a FOCUS_IN_EVENT into *BUFP. */
4266 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
4268 if (type
== FocusIn
)
4270 if (dpyinfo
->x_focus_event_frame
!= frame
)
4272 x_new_focus_frame (dpyinfo
, frame
);
4273 dpyinfo
->x_focus_event_frame
= frame
;
4275 /* Don't stop displaying the initial startup message
4276 for a switch-frame event we don't need. */
4277 /* When run as a daemon, Vterminal_frame is always NIL. */
4278 bufp
->arg
= (((NILP (Vterminal_frame
)
4279 || ! FRAME_X_P (XFRAME (Vterminal_frame
))
4280 || EQ (Fdaemonp (), Qt
))
4281 && CONSP (Vframe_list
)
4282 && !NILP (XCDR (Vframe_list
)))
4284 bufp
->kind
= FOCUS_IN_EVENT
;
4285 XSETFRAME (bufp
->frame_or_window
, frame
);
4288 frame
->output_data
.x
->focus_state
|= state
;
4291 if (FRAME_XIC (frame
))
4292 XSetICFocus (FRAME_XIC (frame
));
4295 else if (type
== FocusOut
)
4297 frame
->output_data
.x
->focus_state
&= ~state
;
4299 if (dpyinfo
->x_focus_event_frame
== frame
)
4301 dpyinfo
->x_focus_event_frame
= 0;
4302 x_new_focus_frame (dpyinfo
, 0);
4304 bufp
->kind
= FOCUS_OUT_EVENT
;
4305 XSETFRAME (bufp
->frame_or_window
, frame
);
4309 if (FRAME_XIC (frame
))
4310 XUnsetICFocus (FRAME_XIC (frame
));
4312 if (frame
->pointer_invisible
)
4313 XTtoggle_invisible_pointer (frame
, false);
4317 /* Return the Emacs frame-object corresponding to an X window.
4318 It could be the frame's main window or an icon window. */
4320 static struct frame
*
4321 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
4323 Lisp_Object tail
, frame
;
4329 FOR_EACH_FRAME (tail
, frame
)
4332 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
4334 if (f
->output_data
.x
->hourglass_window
== wdesc
)
4336 #ifdef USE_X_TOOLKIT
4337 if ((f
->output_data
.x
->edit_widget
4338 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
4339 /* A tooltip frame? */
4340 || (!f
->output_data
.x
->edit_widget
4341 && FRAME_X_WINDOW (f
) == wdesc
)
4342 || f
->output_data
.x
->icon_desc
== wdesc
)
4344 #else /* not USE_X_TOOLKIT */
4346 if (f
->output_data
.x
->edit_widget
)
4348 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
4349 struct x_output
*x
= f
->output_data
.x
;
4350 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
4353 #endif /* USE_GTK */
4354 if (FRAME_X_WINDOW (f
) == wdesc
4355 || f
->output_data
.x
->icon_desc
== wdesc
)
4357 #endif /* not USE_X_TOOLKIT */
4362 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4364 /* Like x_window_to_frame but also compares the window with the widget's
4367 static struct frame
*
4368 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
4370 Lisp_Object tail
, frame
;
4371 struct frame
*f
, *found
= NULL
;
4377 FOR_EACH_FRAME (tail
, frame
)
4382 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
4384 /* This frame matches if the window is any of its widgets. */
4385 x
= f
->output_data
.x
;
4386 if (x
->hourglass_window
== wdesc
)
4391 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
4393 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
4396 if (wdesc
== XtWindow (x
->widget
)
4397 || wdesc
== XtWindow (x
->column_widget
)
4398 || wdesc
== XtWindow (x
->edit_widget
))
4400 /* Match if the window is this frame's menubar. */
4401 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
4405 else if (FRAME_X_WINDOW (f
) == wdesc
)
4406 /* A tooltip frame. */
4414 /* Likewise, but consider only the menu bar widget. */
4416 static struct frame
*
4417 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
,
4418 const XEvent
*event
)
4420 Window wdesc
= event
->xany
.window
;
4421 Lisp_Object tail
, frame
;
4428 FOR_EACH_FRAME (tail
, frame
)
4431 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
4433 x
= f
->output_data
.x
;
4435 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
4438 /* Match if the window is this frame's menubar. */
4439 if (x
->menubar_widget
4440 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
4447 /* Return the frame whose principal (outermost) window is WDESC.
4448 If WDESC is some other (smaller) window, we return 0. */
4451 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
4453 Lisp_Object tail
, frame
;
4460 FOR_EACH_FRAME (tail
, frame
)
4463 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
4465 x
= f
->output_data
.x
;
4469 /* This frame matches if the window is its topmost widget. */
4471 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
4472 if (gwdesc
== x
->widget
)
4475 if (wdesc
== XtWindow (x
->widget
))
4479 else if (FRAME_X_WINDOW (f
) == wdesc
)
4480 /* Tooltip frame. */
4486 #else /* !USE_X_TOOLKIT && !USE_GTK */
4488 #define x_any_window_to_frame(d, i) x_window_to_frame (d, i)
4489 #define x_top_window_to_frame(d, i) x_window_to_frame (d, i)
4491 #endif /* USE_X_TOOLKIT || USE_GTK */
4493 /* The focus may have changed. Figure out if it is a real focus change,
4494 by checking both FocusIn/Out and Enter/LeaveNotify events.
4496 Returns FOCUS_IN_EVENT event in *BUFP. */
4499 x_detect_focus_change (struct x_display_info
*dpyinfo
, struct frame
*frame
,
4500 const XEvent
*event
, struct input_event
*bufp
)
4505 switch (event
->type
)
4510 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
4512 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
4514 if (event
->xcrossing
.detail
!= NotifyInferior
4515 && event
->xcrossing
.focus
4516 && ! (focus_state
& FOCUS_EXPLICIT
))
4517 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
4519 dpyinfo
, frame
, bufp
);
4525 x_focus_changed (event
->type
,
4526 (event
->xfocus
.detail
== NotifyPointer
?
4527 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
4528 dpyinfo
, frame
, bufp
);
4532 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
4534 enum xembed_message msg
= event
->xclient
.data
.l
[1];
4535 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
4536 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
4543 #if !defined USE_X_TOOLKIT && !defined USE_GTK
4544 /* Handle an event saying the mouse has moved out of an Emacs frame. */
4547 x_mouse_leave (struct x_display_info
*dpyinfo
)
4549 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
4553 /* The focus has changed, or we have redirected a frame's focus to
4554 another frame (this happens when a frame uses a surrogate
4555 mini-buffer frame). Shift the highlight as appropriate.
4557 The FRAME argument doesn't necessarily have anything to do with which
4558 frame is being highlighted or un-highlighted; we only use it to find
4559 the appropriate X display info. */
4562 XTframe_rehighlight (struct frame
*frame
)
4564 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
4568 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
4570 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
4572 if (dpyinfo
->x_focus_frame
)
4574 dpyinfo
->x_highlight_frame
4575 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
4576 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
4577 : dpyinfo
->x_focus_frame
);
4578 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
4580 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
4581 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
4585 dpyinfo
->x_highlight_frame
= 0;
4587 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
4590 frame_unhighlight (old_highlight
);
4591 if (dpyinfo
->x_highlight_frame
)
4592 frame_highlight (dpyinfo
->x_highlight_frame
);
4598 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
4600 /* Initialize mode_switch_bit and modifier_meaning. */
4602 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
4604 int min_code
, max_code
;
4607 XModifierKeymap
*mods
;
4609 dpyinfo
->meta_mod_mask
= 0;
4610 dpyinfo
->shift_lock_mask
= 0;
4611 dpyinfo
->alt_mod_mask
= 0;
4612 dpyinfo
->super_mod_mask
= 0;
4613 dpyinfo
->hyper_mod_mask
= 0;
4615 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
4617 syms
= XGetKeyboardMapping (dpyinfo
->display
,
4618 min_code
, max_code
- min_code
+ 1,
4620 mods
= XGetModifierMapping (dpyinfo
->display
);
4622 /* Scan the modifier table to see which modifier bits the Meta and
4623 Alt keysyms are on. */
4625 int row
, col
; /* The row and column in the modifier table. */
4626 bool found_alt_or_meta
;
4628 for (row
= 3; row
< 8; row
++)
4630 found_alt_or_meta
= false;
4631 for (col
= 0; col
< mods
->max_keypermod
; col
++)
4633 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
4635 /* Zeroes are used for filler. Skip them. */
4639 /* Are any of this keycode's keysyms a meta key? */
4643 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
4645 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
4651 found_alt_or_meta
= true;
4652 dpyinfo
->meta_mod_mask
|= (1 << row
);
4657 found_alt_or_meta
= true;
4658 dpyinfo
->alt_mod_mask
|= (1 << row
);
4663 if (!found_alt_or_meta
)
4664 dpyinfo
->hyper_mod_mask
|= (1 << row
);
4665 code_col
= syms_per_code
;
4666 col
= mods
->max_keypermod
;
4671 if (!found_alt_or_meta
)
4672 dpyinfo
->super_mod_mask
|= (1 << row
);
4673 code_col
= syms_per_code
;
4674 col
= mods
->max_keypermod
;
4678 /* Ignore this if it's not on the lock modifier. */
4679 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
4680 dpyinfo
->shift_lock_mask
= LockMask
;
4681 code_col
= syms_per_code
;
4682 col
= mods
->max_keypermod
;
4691 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
4692 if (! dpyinfo
->meta_mod_mask
)
4694 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
4695 dpyinfo
->alt_mod_mask
= 0;
4698 /* If some keys are both alt and meta,
4699 make them just meta, not alt. */
4700 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
4702 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
4706 XFreeModifiermap (mods
);
4709 /* Convert between the modifier bits X uses and the modifier bits
4713 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
4715 int mod_ctrl
= ctrl_modifier
;
4716 int mod_meta
= meta_modifier
;
4717 int mod_alt
= alt_modifier
;
4718 int mod_hyper
= hyper_modifier
;
4719 int mod_super
= super_modifier
;
4722 tem
= Fget (Vx_ctrl_keysym
, Qmodifier_value
);
4723 if (INTEGERP (tem
)) mod_ctrl
= XINT (tem
) & INT_MAX
;
4724 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
4725 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
4726 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
4727 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
4728 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
4729 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
4730 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
4731 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
4733 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
4734 | ((state
& ControlMask
) ? mod_ctrl
: 0)
4735 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
4736 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
4737 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
4738 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
4742 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
4744 EMACS_INT mod_ctrl
= ctrl_modifier
;
4745 EMACS_INT mod_meta
= meta_modifier
;
4746 EMACS_INT mod_alt
= alt_modifier
;
4747 EMACS_INT mod_hyper
= hyper_modifier
;
4748 EMACS_INT mod_super
= super_modifier
;
4752 tem
= Fget (Vx_ctrl_keysym
, Qmodifier_value
);
4753 if (INTEGERP (tem
)) mod_ctrl
= XINT (tem
);
4754 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
4755 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
4756 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
4757 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
4758 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
4759 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
4760 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
4761 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
4764 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
4765 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
4766 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
4767 | ((state
& shift_modifier
) ? ShiftMask
: 0)
4768 | ((state
& mod_ctrl
) ? ControlMask
: 0)
4769 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
4772 /* Convert a keysym to its name. */
4775 x_get_keysym_name (int keysym
)
4780 value
= XKeysymToString (keysym
);
4786 /* Mouse clicks and mouse movement. Rah.
4788 Formerly, we used PointerMotionHintMask (in standard_event_mask)
4789 so that we would have to call XQueryPointer after each MotionNotify
4790 event to ask for another such event. However, this made mouse tracking
4791 slow, and there was a bug that made it eventually stop.
4793 Simply asking for MotionNotify all the time seems to work better.
4795 In order to avoid asking for motion events and then throwing most
4796 of them away or busy-polling the server for mouse positions, we ask
4797 the server for pointer motion hints. This means that we get only
4798 one event per group of mouse movements. "Groups" are delimited by
4799 other kinds of events (focus changes and button clicks, for
4800 example), or by XQueryPointer calls; when one of these happens, we
4801 get another MotionNotify event the next time the mouse moves. This
4802 is at least as efficient as getting motion events when mouse
4803 tracking is on, and I suspect only negligibly worse when tracking
4806 /* Prepare a mouse-event in *RESULT for placement in the input queue.
4808 If the event is a button press, then note that we have grabbed
4812 construct_mouse_click (struct input_event
*result
,
4813 const XButtonEvent
*event
,
4816 /* Make the event type NO_EVENT; we'll change that when we decide
4818 result
->kind
= MOUSE_CLICK_EVENT
;
4819 result
->code
= event
->button
- Button1
;
4820 result
->timestamp
= event
->time
;
4821 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
),
4823 | (event
->type
== ButtonRelease
4827 XSETINT (result
->x
, event
->x
);
4828 XSETINT (result
->y
, event
->y
);
4829 XSETFRAME (result
->frame_or_window
, f
);
4834 /* Function to report a mouse movement to the mainstream Emacs code.
4835 The input handler calls this.
4837 We have received a mouse movement event, which is given in *event.
4838 If the mouse is over a different glyph than it was last time, tell
4839 the mainstream emacs code by setting mouse_moved. If not, ask for
4840 another motion event, so we can check again the next time it moves. */
4843 note_mouse_movement (struct frame
*frame
, const XMotionEvent
*event
)
4846 struct x_display_info
*dpyinfo
;
4848 if (!FRAME_X_OUTPUT (frame
))
4851 dpyinfo
= FRAME_DISPLAY_INFO (frame
);
4852 dpyinfo
->last_mouse_movement_time
= event
->time
;
4853 dpyinfo
->last_mouse_motion_frame
= frame
;
4854 dpyinfo
->last_mouse_motion_x
= event
->x
;
4855 dpyinfo
->last_mouse_motion_y
= event
->y
;
4857 if (event
->window
!= FRAME_X_WINDOW (frame
))
4859 frame
->mouse_moved
= true;
4860 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4861 note_mouse_highlight (frame
, -1, -1);
4862 dpyinfo
->last_mouse_glyph_frame
= NULL
;
4867 /* Has the mouse moved off the glyph it was on at the last sighting? */
4868 r
= &dpyinfo
->last_mouse_glyph
;
4869 if (frame
!= dpyinfo
->last_mouse_glyph_frame
4870 || event
->x
< r
->x
|| event
->x
>= r
->x
+ r
->width
4871 || event
->y
< r
->y
|| event
->y
>= r
->y
+ r
->height
)
4873 frame
->mouse_moved
= true;
4874 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4875 note_mouse_highlight (frame
, event
->x
, event
->y
);
4876 /* Remember which glyph we're now on. */
4877 remember_mouse_glyph (frame
, event
->x
, event
->y
, r
);
4878 dpyinfo
->last_mouse_glyph_frame
= frame
;
4885 /* Return the current position of the mouse.
4886 *FP should be a frame which indicates which display to ask about.
4888 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
4889 and *PART to the frame, window, and scroll bar part that the mouse
4890 is over. Set *X and *Y to the portion and whole of the mouse's
4891 position on the scroll bar.
4893 If the mouse movement started elsewhere, set *FP to the frame the
4894 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
4897 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
4898 was at this position.
4900 Don't store anything if we don't have a valid set of values to report.
4902 This clears the mouse_moved flag, so we can wait for the next mouse
4906 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
4907 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
4911 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
4915 if (dpyinfo
->last_mouse_scroll_bar
&& insist
== 0)
4917 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
4919 if (bar
->horizontal
)
4920 x_horizontal_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
4922 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
4929 Window dummy_window
;
4932 Lisp_Object frame
, tail
;
4934 /* Clear the mouse-moved flag for every frame on this display. */
4935 FOR_EACH_FRAME (tail
, frame
)
4936 if (FRAME_X_P (XFRAME (frame
))
4937 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
4938 XFRAME (frame
)->mouse_moved
= false;
4940 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4942 /* Figure out which root window we're on. */
4943 XQueryPointer (FRAME_X_DISPLAY (*fp
),
4944 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
4946 /* The root window which contains the pointer. */
4949 /* Trash which we can't trust if the pointer is on
4950 a different screen. */
4953 /* The position on that root window. */
4956 /* More trash we can't trust. */
4959 /* Modifier keys and pointer buttons, about which
4961 (unsigned int *) &dummy
);
4963 /* Now we have a position on the root; find the innermost window
4964 containing the pointer. */
4968 int parent_x
= 0, parent_y
= 0;
4972 /* XTranslateCoordinates can get errors if the window
4973 structure is changing at the same time this function
4974 is running. So at least we must not crash from them. */
4976 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4978 if (x_mouse_grabbed (dpyinfo
))
4980 /* If mouse was grabbed on a frame, give coords for that frame
4981 even if the mouse is now outside it. */
4982 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4988 FRAME_X_WINDOW (dpyinfo
->last_mouse_frame
),
4990 /* From-position, to-position. */
4991 root_x
, root_y
, &win_x
, &win_y
,
4995 f1
= dpyinfo
->last_mouse_frame
;
5001 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
5003 /* From-window, to-window. */
5006 /* From-position, to-position. */
5007 root_x
, root_y
, &win_x
, &win_y
,
5012 if (child
== None
|| child
== win
)
5015 /* We don't wan't to know the innermost window. We
5016 want the edit window. For non-Gtk+ the innermost
5017 window is the edit window. For Gtk+ it might not
5018 be. It might be the tool bar for example. */
5019 if (x_window_to_frame (dpyinfo
, win
))
5027 /* Now we know that:
5028 win is the innermost window containing the pointer
5029 (XTC says it has no child containing the pointer),
5030 win_x and win_y are the pointer's position in it
5031 (XTC did this the last time through), and
5032 parent_x and parent_y are the pointer's position in win's parent.
5033 (They are what win_x and win_y were when win was child.
5034 If win is the root window, it has no parent, and
5035 parent_{x,y} are invalid, but that's okay, because we'll
5036 never use them in that case.) */
5039 /* We don't wan't to know the innermost window. We
5040 want the edit window. */
5041 f1
= x_window_to_frame (dpyinfo
, win
);
5043 /* Is win one of our frames? */
5044 f1
= x_any_window_to_frame (dpyinfo
, win
);
5047 #ifdef USE_X_TOOLKIT
5048 /* If we end up with the menu bar window, say it's not
5051 && f1
->output_data
.x
->menubar_widget
5052 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
5054 #endif /* USE_X_TOOLKIT */
5057 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
5060 x_uncatch_errors_after_check ();
5062 /* If not, is it one of our scroll bars? */
5065 struct scroll_bar
*bar
;
5067 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
, 2);
5071 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5077 if (f1
== 0 && insist
> 0)
5078 f1
= SELECTED_FRAME ();
5082 /* Ok, we found a frame. Store all the values.
5083 last_mouse_glyph is a rectangle used to reduce the
5084 generation of mouse events. To not miss any motion
5085 events, we must divide the frame into rectangles of the
5086 size of the smallest character that could be displayed
5087 on it, i.e. into the same rectangles that matrices on
5088 the frame are divided into. */
5090 /* FIXME: what if F1 is not an X frame? */
5091 dpyinfo
= FRAME_DISPLAY_INFO (f1
);
5092 remember_mouse_glyph (f1
, win_x
, win_y
, &dpyinfo
->last_mouse_glyph
);
5093 dpyinfo
->last_mouse_glyph_frame
= f1
;
5098 XSETINT (*x
, win_x
);
5099 XSETINT (*y
, win_y
);
5100 *timestamp
= dpyinfo
->last_mouse_movement_time
;
5110 /***********************************************************************
5112 ***********************************************************************/
5114 /* Scroll bar support. */
5116 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
5118 This can be called in GC, so we have to make sure to strip off mark
5121 static struct scroll_bar
*
5122 x_window_to_scroll_bar (Display
*display
, Window window_id
, int type
)
5124 Lisp_Object tail
, frame
;
5126 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
5127 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
5128 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
5130 FOR_EACH_FRAME (tail
, frame
)
5132 Lisp_Object bar
, condemned
;
5134 if (! FRAME_X_P (XFRAME (frame
)))
5137 /* Scan this frame's scroll bar list for a scroll bar with the
5139 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
5140 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
5141 /* This trick allows us to search both the ordinary and
5142 condemned scroll bar lists with one loop. */
5143 ! NILP (bar
) || (bar
= condemned
,
5146 bar
= XSCROLL_BAR (bar
)->next
)
5147 if (XSCROLL_BAR (bar
)->x_window
== window_id
5148 && FRAME_X_DISPLAY (XFRAME (frame
)) == display
5150 || (type
== 1 && XSCROLL_BAR (bar
)->horizontal
)
5151 || (type
== 0 && !XSCROLL_BAR (bar
)->horizontal
)))
5152 return XSCROLL_BAR (bar
);
5159 #if defined USE_LUCID
5161 /* Return the Lucid menu bar WINDOW is part of. Return null
5162 if WINDOW is not part of a menu bar. */
5165 x_window_to_menu_bar (Window window
)
5167 Lisp_Object tail
, frame
;
5169 FOR_EACH_FRAME (tail
, frame
)
5170 if (FRAME_X_P (XFRAME (frame
)))
5172 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
5174 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
5180 #endif /* USE_LUCID */
5183 /************************************************************************
5185 ************************************************************************/
5187 #ifdef USE_TOOLKIT_SCROLL_BARS
5189 static void x_send_scroll_bar_event (Lisp_Object
, enum scroll_bar_part
,
5192 /* Lisp window being scrolled. Set when starting to interact with
5193 a toolkit scroll bar, reset to nil when ending the interaction. */
5195 static Lisp_Object window_being_scrolled
;
5197 /* Whether this is an Xaw with arrow-scrollbars. This should imply
5198 that movements of 1/20 of the screen size are mapped to up/down. */
5201 /* Id of action hook installed for scroll bars. */
5203 static XtActionHookId action_hook_id
;
5204 static XtActionHookId horizontal_action_hook_id
;
5206 static Boolean xaw3d_arrow_scroll
;
5208 /* Whether the drag scrolling maintains the mouse at the top of the
5209 thumb. If not, resizing the thumb needs to be done more carefully
5210 to avoid jerkiness. */
5212 static Boolean xaw3d_pick_top
;
5214 /* Action hook installed via XtAppAddActionHook when toolkit scroll
5215 bars are used.. The hook is responsible for detecting when
5216 the user ends an interaction with the scroll bar, and generates
5217 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
5220 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
5221 XEvent
*event
, String
*params
, Cardinal
*num_params
)
5224 const char *end_action
;
5227 scroll_bar_p
= XmIsScrollBar (widget
);
5228 end_action
= "Release";
5229 #else /* !USE_MOTIF i.e. use Xaw */
5230 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
5231 end_action
= "EndScroll";
5232 #endif /* USE_MOTIF */
5235 && strcmp (action_name
, end_action
) == 0
5236 && WINDOWP (window_being_scrolled
))
5239 struct scroll_bar
*bar
;
5241 x_send_scroll_bar_event (window_being_scrolled
,
5242 scroll_bar_end_scroll
, 0, 0, false);
5243 w
= XWINDOW (window_being_scrolled
);
5244 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5246 if (bar
->dragging
!= -1)
5249 /* The thumb size is incorrect while dragging: fix it. */
5250 set_vertical_scroll_bar (w
);
5252 window_being_scrolled
= Qnil
;
5253 #if defined (USE_LUCID)
5254 bar
->last_seen_part
= scroll_bar_nowhere
;
5256 /* Xt timeouts no longer needed. */
5257 toolkit_scroll_bar_interaction
= false;
5263 xt_horizontal_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
5264 XEvent
*event
, String
*params
, Cardinal
*num_params
)
5267 const char *end_action
;
5270 scroll_bar_p
= XmIsScrollBar (widget
);
5271 end_action
= "Release";
5272 #else /* !USE_MOTIF i.e. use Xaw */
5273 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
5274 end_action
= "EndScroll";
5275 #endif /* USE_MOTIF */
5278 && strcmp (action_name
, end_action
) == 0
5279 && WINDOWP (window_being_scrolled
))
5282 struct scroll_bar
*bar
;
5284 x_send_scroll_bar_event (window_being_scrolled
,
5285 scroll_bar_end_scroll
, 0, 0, true);
5286 w
= XWINDOW (window_being_scrolled
);
5287 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
5289 if (bar
->dragging
!= -1)
5292 /* The thumb size is incorrect while dragging: fix it. */
5293 set_horizontal_scroll_bar (w
);
5295 window_being_scrolled
= Qnil
;
5296 #if defined (USE_LUCID)
5297 bar
->last_seen_part
= scroll_bar_nowhere
;
5299 /* Xt timeouts no longer needed. */
5300 toolkit_scroll_bar_interaction
= false;
5303 #endif /* not USE_GTK */
5305 /* Send a client message with message type Xatom_Scrollbar for a
5306 scroll action to the frame of WINDOW. PART is a value identifying
5307 the part of the scroll bar that was clicked on. PORTION is the
5308 amount to scroll of a whole of WHOLE. */
5311 x_send_scroll_bar_event (Lisp_Object window
, enum scroll_bar_part part
,
5312 int portion
, int whole
, bool horizontal
)
5315 XClientMessageEvent
*ev
= &event
.xclient
;
5316 struct window
*w
= XWINDOW (window
);
5317 struct frame
*f
= XFRAME (w
->frame
);
5318 intptr_t iw
= (intptr_t) w
;
5319 verify (INTPTR_WIDTH
<= 64);
5320 int sign_shift
= INTPTR_WIDTH
- 32;
5324 /* Construct a ClientMessage event to send to the frame. */
5325 ev
->type
= ClientMessage
;
5326 ev
->message_type
= (horizontal
5327 ? FRAME_DISPLAY_INFO (f
)->Xatom_Horizontal_Scrollbar
5328 : FRAME_DISPLAY_INFO (f
)->Xatom_Scrollbar
);
5329 ev
->display
= FRAME_X_DISPLAY (f
);
5330 ev
->window
= FRAME_X_WINDOW (f
);
5333 /* A 32-bit X client on a 64-bit X server can pass a window pointer
5334 as-is. A 64-bit client on a 32-bit X server is in trouble
5335 because a pointer does not fit and would be truncated while
5336 passing through the server. So use two slots and hope that X12
5337 will resolve such issues someday. */
5338 ev
->data
.l
[0] = iw
>> 31 >> 1;
5339 ev
->data
.l
[1] = sign_shift
<= 0 ? iw
: iw
<< sign_shift
>> sign_shift
;
5340 ev
->data
.l
[2] = part
;
5341 ev
->data
.l
[3] = portion
;
5342 ev
->data
.l
[4] = whole
;
5344 /* Make Xt timeouts work while the scroll bar is active. */
5345 #ifdef USE_X_TOOLKIT
5346 toolkit_scroll_bar_interaction
= true;
5347 x_activate_timeout_atimer ();
5350 /* Setting the event mask to zero means that the message will
5351 be sent to the client that created the window, and if that
5352 window no longer exists, no event will be sent. */
5353 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
5358 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
5362 x_scroll_bar_to_input_event (const XEvent
*event
,
5363 struct input_event
*ievent
)
5365 const XClientMessageEvent
*ev
= &event
->xclient
;
5369 /* See the comment in the function above. */
5370 intptr_t iw0
= ev
->data
.l
[0];
5371 intptr_t iw1
= ev
->data
.l
[1];
5372 intptr_t iw
= (iw0
<< 31 << 1) + (iw1
& 0xffffffffu
);
5373 w
= (struct window
*) iw
;
5375 XSETWINDOW (window
, w
);
5377 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
5378 ievent
->frame_or_window
= window
;
5381 ievent
->timestamp
= CurrentTime
;
5384 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
5387 ievent
->part
= ev
->data
.l
[2];
5388 ievent
->x
= make_number (ev
->data
.l
[3]);
5389 ievent
->y
= make_number (ev
->data
.l
[4]);
5390 ievent
->modifiers
= 0;
5393 /* Transform a horizontal scroll bar ClientMessage EVENT to an Emacs
5394 input event in *IEVENT. */
5397 x_horizontal_scroll_bar_to_input_event (const XEvent
*event
,
5398 struct input_event
*ievent
)
5400 const XClientMessageEvent
*ev
= &event
->xclient
;
5404 /* See the comment in the function above. */
5405 intptr_t iw0
= ev
->data
.l
[0];
5406 intptr_t iw1
= ev
->data
.l
[1];
5407 intptr_t iw
= (iw0
<< 31 << 1) + (iw1
& 0xffffffffu
);
5408 w
= (struct window
*) iw
;
5410 XSETWINDOW (window
, w
);
5412 ievent
->kind
= HORIZONTAL_SCROLL_BAR_CLICK_EVENT
;
5413 ievent
->frame_or_window
= window
;
5416 ievent
->timestamp
= CurrentTime
;
5419 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
5422 ievent
->part
= ev
->data
.l
[2];
5423 ievent
->x
= make_number (ev
->data
.l
[3]);
5424 ievent
->y
= make_number (ev
->data
.l
[4]);
5425 ievent
->modifiers
= 0;
5431 /* Minimum and maximum values used for Motif scroll bars. */
5433 #define XM_SB_MAX 10000000
5435 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
5436 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
5437 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
5440 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5442 struct scroll_bar
*bar
= client_data
;
5443 XmScrollBarCallbackStruct
*cs
= call_data
;
5444 enum scroll_bar_part part
= scroll_bar_nowhere
;
5445 bool horizontal
= bar
->horizontal
;
5446 int whole
= 0, portion
= 0;
5450 case XmCR_DECREMENT
:
5452 part
= horizontal
? scroll_bar_left_arrow
: scroll_bar_up_arrow
;
5455 case XmCR_INCREMENT
:
5457 part
= horizontal
? scroll_bar_right_arrow
: scroll_bar_down_arrow
;
5460 case XmCR_PAGE_DECREMENT
:
5462 part
= horizontal
? scroll_bar_before_handle
: scroll_bar_above_handle
;
5465 case XmCR_PAGE_INCREMENT
:
5467 part
= horizontal
? scroll_bar_after_handle
: scroll_bar_below_handle
;
5472 part
= horizontal
? scroll_bar_to_leftmost
: scroll_bar_to_top
;
5475 case XmCR_TO_BOTTOM
:
5477 part
= horizontal
? scroll_bar_to_rightmost
: scroll_bar_to_bottom
;
5485 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
5490 portion
= bar
->whole
* ((float)cs
->value
/ XM_SB_MAX
);
5491 whole
= bar
->whole
* ((float)(XM_SB_MAX
- slider_size
) / XM_SB_MAX
);
5492 portion
= min (portion
, whole
);
5493 part
= scroll_bar_horizontal_handle
;
5497 whole
= XM_SB_MAX
- slider_size
;
5498 portion
= min (cs
->value
, whole
);
5499 part
= scroll_bar_handle
;
5502 bar
->dragging
= cs
->value
;
5506 case XmCR_VALUE_CHANGED
:
5510 if (part
!= scroll_bar_nowhere
)
5512 window_being_scrolled
= bar
->window
;
5513 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
,
5518 #elif defined USE_GTK
5520 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
5521 bar widget. DATA is a pointer to the scroll_bar structure. */
5524 xg_scroll_callback (GtkRange
*range
,
5525 GtkScrollType scroll
,
5529 int whole
= 0, portion
= 0;
5530 struct scroll_bar
*bar
= user_data
;
5531 enum scroll_bar_part part
= scroll_bar_nowhere
;
5532 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
5533 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
5535 if (xg_ignore_gtk_scrollbar
) return false;
5539 case GTK_SCROLL_JUMP
:
5540 /* Buttons 1 2 or 3 must be grabbed. */
5541 if (FRAME_DISPLAY_INFO (f
)->grabbed
!= 0
5542 && FRAME_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
5544 if (bar
->horizontal
)
5546 part
= scroll_bar_horizontal_handle
;
5547 whole
= (int)(gtk_adjustment_get_upper (adj
) -
5548 gtk_adjustment_get_page_size (adj
));
5549 portion
= min ((int)value
, whole
);
5550 bar
->dragging
= portion
;
5554 part
= scroll_bar_handle
;
5555 whole
= gtk_adjustment_get_upper (adj
) -
5556 gtk_adjustment_get_page_size (adj
);
5557 portion
= min ((int)value
, whole
);
5558 bar
->dragging
= portion
;
5562 case GTK_SCROLL_STEP_BACKWARD
:
5563 part
= (bar
->horizontal
5564 ? scroll_bar_left_arrow
: scroll_bar_up_arrow
);
5567 case GTK_SCROLL_STEP_FORWARD
:
5568 part
= (bar
->horizontal
5569 ? scroll_bar_right_arrow
: scroll_bar_down_arrow
);
5572 case GTK_SCROLL_PAGE_BACKWARD
:
5573 part
= (bar
->horizontal
5574 ? scroll_bar_before_handle
: scroll_bar_above_handle
);
5577 case GTK_SCROLL_PAGE_FORWARD
:
5578 part
= (bar
->horizontal
5579 ? scroll_bar_after_handle
: scroll_bar_below_handle
);
5586 if (part
!= scroll_bar_nowhere
)
5588 window_being_scrolled
= bar
->window
;
5589 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
,
5596 /* Callback for button release. Sets dragging to -1 when dragging is done. */
5599 xg_end_scroll_callback (GtkWidget
*widget
,
5600 GdkEventButton
*event
,
5603 struct scroll_bar
*bar
= user_data
;
5605 if (WINDOWP (window_being_scrolled
))
5607 x_send_scroll_bar_event (window_being_scrolled
,
5608 scroll_bar_end_scroll
, 0, 0, bar
->horizontal
);
5609 window_being_scrolled
= Qnil
;
5616 #else /* not USE_GTK and not USE_MOTIF */
5618 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
5619 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
5620 scroll bar struct. CALL_DATA is a pointer to a float saying where
5624 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5626 struct scroll_bar
*bar
= client_data
;
5627 float *top_addr
= call_data
;
5628 float top
= *top_addr
;
5630 int whole
, portion
, height
, width
;
5631 enum scroll_bar_part part
;
5632 bool horizontal
= bar
->horizontal
;
5637 /* Get the size of the thumb, a value between 0 and 1. */
5639 XtVaGetValues (widget
, XtNshown
, &shown
, XtNwidth
, &width
, NULL
);
5644 whole
= bar
->whole
- (shown
* bar
->whole
);
5645 portion
= min (top
* bar
->whole
, whole
);
5653 part
= scroll_bar_horizontal_handle
;
5657 /* Get the size of the thumb, a value between 0 and 1. */
5659 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
5663 portion
= shown
< 1 ? top
* whole
: 0;
5665 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
5666 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
5667 the bottom, so we force the scrolling whenever we see that we're
5668 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
5669 we try to ensure that we always stay two pixels away from the
5671 part
= scroll_bar_down_arrow
;
5673 part
= scroll_bar_handle
;
5676 window_being_scrolled
= bar
->window
;
5677 bar
->dragging
= portion
;
5678 bar
->last_seen_part
= part
;
5679 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
, bar
->horizontal
);
5683 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
5684 i.e. line or page up or down. WIDGET is the Xaw scroll bar
5685 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
5686 the scroll bar. CALL_DATA is an integer specifying the action that
5687 has taken place. Its magnitude is in the range 0..height of the
5688 scroll bar. Negative values mean scroll towards buffer start.
5689 Values < height of scroll bar mean line-wise movement. */
5692 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5694 struct scroll_bar
*bar
= client_data
;
5695 /* The position really is stored cast to a pointer. */
5696 int position
= (intptr_t) call_data
;
5697 Dimension height
, width
;
5698 enum scroll_bar_part part
;
5700 if (bar
->horizontal
)
5702 /* Get the width of the scroll bar. */
5704 XtVaGetValues (widget
, XtNwidth
, &width
, NULL
);
5707 if (eabs (position
) >= width
)
5708 part
= (position
< 0) ? scroll_bar_before_handle
: scroll_bar_after_handle
;
5710 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
5711 it maps line-movement to call_data = max(5, height/20). */
5712 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, width
/ 20))
5713 part
= (position
< 0) ? scroll_bar_left_arrow
: scroll_bar_right_arrow
;
5715 part
= scroll_bar_move_ratio
;
5717 window_being_scrolled
= bar
->window
;
5719 bar
->last_seen_part
= part
;
5720 x_send_scroll_bar_event (bar
->window
, part
, position
, width
,
5726 /* Get the height of the scroll bar. */
5728 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
5731 if (eabs (position
) >= height
)
5732 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
5734 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
5735 it maps line-movement to call_data = max(5, height/20). */
5736 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
5737 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
5739 part
= scroll_bar_move_ratio
;
5741 window_being_scrolled
= bar
->window
;
5743 bar
->last_seen_part
= part
;
5744 x_send_scroll_bar_event (bar
->window
, part
, position
, height
,
5749 #endif /* not USE_GTK and not USE_MOTIF */
5751 #define SCROLL_BAR_NAME "verticalScrollBar"
5752 #define SCROLL_BAR_HORIZONTAL_NAME "horizontalScrollBar"
5754 /* Create the widget for scroll bar BAR on frame F. Record the widget
5755 and X window of the scroll bar in BAR. */
5759 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5761 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
5764 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
5765 G_CALLBACK (xg_end_scroll_callback
),
5771 x_create_horizontal_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5773 const char *scroll_bar_name
= SCROLL_BAR_HORIZONTAL_NAME
;
5776 xg_create_horizontal_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
5777 G_CALLBACK (xg_end_scroll_callback
),
5782 #else /* not USE_GTK */
5785 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5791 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
5792 unsigned long pixel
;
5797 /* Set resources. Create the widget. */
5798 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5799 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
5800 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
5801 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
5802 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
5803 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
5804 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
5806 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5809 XtSetArg (av
[ac
], XmNforeground
, pixel
);
5813 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5816 XtSetArg (av
[ac
], XmNbackground
, pixel
);
5820 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
5821 (char *) scroll_bar_name
, av
, ac
);
5823 /* Add one callback for everything that can happen. */
5824 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
5826 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
5828 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
5830 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
5832 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
5834 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
5836 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
5839 /* Realize the widget. Only after that is the X window created. */
5840 XtRealizeWidget (widget
);
5842 /* Set the cursor to an arrow. I didn't find a resource to do that.
5843 And I'm wondering why it hasn't an arrow cursor by default. */
5844 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
5845 f
->output_data
.x
->nontext_cursor
);
5847 #else /* !USE_MOTIF i.e. use Xaw */
5849 /* Set resources. Create the widget. The background of the
5850 Xaw3d scroll bar widget is a little bit light for my taste.
5851 We don't alter it here to let users change it according
5852 to their taste with `emacs*verticalScrollBar.background: xxx'. */
5853 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5854 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
5855 /* For smoother scrolling with Xaw3d -sm */
5856 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
5858 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5861 XtSetArg (av
[ac
], XtNforeground
, pixel
);
5865 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5868 XtSetArg (av
[ac
], XtNbackground
, pixel
);
5872 /* Top/bottom shadow colors. */
5874 /* Allocate them, if necessary. */
5875 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
5877 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5880 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
5881 FRAME_X_COLORMAP (f
),
5882 &pixel
, 1.2, 0x8000))
5884 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
5887 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
5889 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5892 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
5893 FRAME_X_COLORMAP (f
),
5894 &pixel
, 0.6, 0x4000))
5896 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
5900 #ifdef XtNbeNiceToColormap
5901 /* Tell the toolkit about them. */
5902 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
5903 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
5904 /* We tried to allocate a color for the top/bottom shadow, and
5905 failed, so tell Xaw3d to use dithering instead. */
5906 /* But only if we have a small colormap. Xaw3d can allocate nice
5909 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
5910 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
5914 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
5915 be more consistent with other emacs 3d colors, and since Xaw3d is
5916 not good at dealing with allocation failure. */
5918 /* This tells Xaw3d to use real colors instead of dithering for
5920 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
5923 /* Specify the colors. */
5924 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
5927 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
5930 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
5933 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
5939 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
5940 f
->output_data
.x
->edit_widget
, av
, ac
);
5943 char const *initial
= "";
5944 char const *val
= initial
;
5945 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
5946 #ifdef XtNarrowScrollbars
5947 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
5949 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
5950 if (xaw3d_arrow_scroll
|| val
== initial
)
5951 { /* ARROW_SCROLL */
5952 xaw3d_arrow_scroll
= True
;
5953 /* Isn't that just a personal preference ? --Stef */
5954 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
5958 /* Define callbacks. */
5959 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
5960 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
5963 /* Realize the widget. Only after that is the X window created. */
5964 XtRealizeWidget (widget
);
5966 #endif /* !USE_MOTIF */
5968 /* Install an action hook that lets us detect when the user
5969 finishes interacting with a scroll bar. */
5970 if (action_hook_id
== 0)
5971 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
5973 /* Remember X window and widget in the scroll bar vector. */
5974 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
5975 xwindow
= XtWindow (widget
);
5976 bar
->x_window
= xwindow
;
5978 bar
->horizontal
= false;
5984 x_create_horizontal_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5990 const char *scroll_bar_name
= SCROLL_BAR_HORIZONTAL_NAME
;
5991 unsigned long pixel
;
5996 /* Set resources. Create the widget. */
5997 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5998 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
5999 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
6000 XtSetArg (av
[ac
], XmNorientation
, XmHORIZONTAL
); ++ac
;
6001 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_RIGHT
), ++ac
;
6002 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
6003 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
6005 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
6008 XtSetArg (av
[ac
], XmNforeground
, pixel
);
6012 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6015 XtSetArg (av
[ac
], XmNbackground
, pixel
);
6019 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
6020 (char *) scroll_bar_name
, av
, ac
);
6022 /* Add one callback for everything that can happen. */
6023 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
6025 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
6027 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
6029 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
6031 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
6033 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
6035 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
6038 /* Realize the widget. Only after that is the X window created. */
6039 XtRealizeWidget (widget
);
6041 /* Set the cursor to an arrow. I didn't find a resource to do that.
6042 And I'm wondering why it hasn't an arrow cursor by default. */
6043 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
6044 f
->output_data
.x
->nontext_cursor
);
6046 #else /* !USE_MOTIF i.e. use Xaw */
6048 /* Set resources. Create the widget. The background of the
6049 Xaw3d scroll bar widget is a little bit light for my taste.
6050 We don't alter it here to let users change it according
6051 to their taste with `emacs*verticalScrollBar.background: xxx'. */
6052 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
6053 XtSetArg (av
[ac
], XtNorientation
, XtorientHorizontal
); ++ac
;
6054 /* For smoother scrolling with Xaw3d -sm */
6055 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
6057 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
6060 XtSetArg (av
[ac
], XtNforeground
, pixel
);
6064 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6067 XtSetArg (av
[ac
], XtNbackground
, pixel
);
6071 /* Top/bottom shadow colors. */
6073 /* Allocate them, if necessary. */
6074 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
6076 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6079 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
6080 FRAME_X_COLORMAP (f
),
6081 &pixel
, 1.2, 0x8000))
6083 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
6086 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
6088 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6091 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
6092 FRAME_X_COLORMAP (f
),
6093 &pixel
, 0.6, 0x4000))
6095 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
6099 #ifdef XtNbeNiceToColormap
6100 /* Tell the toolkit about them. */
6101 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
6102 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
6103 /* We tried to allocate a color for the top/bottom shadow, and
6104 failed, so tell Xaw3d to use dithering instead. */
6105 /* But only if we have a small colormap. Xaw3d can allocate nice
6108 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
6109 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
6113 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
6114 be more consistent with other emacs 3d colors, and since Xaw3d is
6115 not good at dealing with allocation failure. */
6117 /* This tells Xaw3d to use real colors instead of dithering for
6119 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
6122 /* Specify the colors. */
6123 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
6126 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
6129 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
6132 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
6138 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
6139 f
->output_data
.x
->edit_widget
, av
, ac
);
6142 char const *initial
= "";
6143 char const *val
= initial
;
6144 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
6145 #ifdef XtNarrowScrollbars
6146 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
6148 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
6149 if (xaw3d_arrow_scroll
|| val
== initial
)
6150 { /* ARROW_SCROLL */
6151 xaw3d_arrow_scroll
= True
;
6152 /* Isn't that just a personal preference ? --Stef */
6153 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
6157 /* Define callbacks. */
6158 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
6159 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
6162 /* Realize the widget. Only after that is the X window created. */
6163 XtRealizeWidget (widget
);
6165 #endif /* !USE_MOTIF */
6167 /* Install an action hook that lets us detect when the user
6168 finishes interacting with a scroll bar. */
6169 if (horizontal_action_hook_id
== 0)
6170 horizontal_action_hook_id
6171 = XtAppAddActionHook (Xt_app_con
, xt_horizontal_action_hook
, 0);
6173 /* Remember X window and widget in the scroll bar vector. */
6174 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
6175 xwindow
= XtWindow (widget
);
6176 bar
->x_window
= xwindow
;
6178 bar
->horizontal
= true;
6182 #endif /* not USE_GTK */
6185 /* Set the thumb size and position of scroll bar BAR. We are currently
6186 displaying PORTION out of a whole WHOLE, and our position POSITION. */
6190 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
6192 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
6196 x_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
6198 xg_set_toolkit_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
6201 #else /* not USE_GTK */
6203 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
6206 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6207 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6214 if (scroll_bar_adjust_thumb_portion_p
)
6216 /* We use an estimate of 30 chars per line rather than the real
6217 `portion' value. This has the disadvantage that the thumb size
6218 is not very representative, but it makes our life a lot easier.
6219 Otherwise, we have to constantly adjust the thumb size, which
6220 we can't always do quickly enough: while dragging, the size of
6221 the thumb might prevent the user from dragging the thumb all the
6222 way to the end. but Motif and some versions of Xaw3d don't allow
6223 updating the thumb size while dragging. Also, even if we can update
6224 its size, the update will often happen too late.
6225 If you don't believe it, check out revision 1.650 of xterm.c to see
6226 what hoops we were going through and the still poor behavior we got. */
6227 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
6228 /* When the thumb is at the bottom, position == whole.
6229 So we need to increase `whole' to make space for the thumb. */
6237 top
= (float) position
/ whole
;
6238 shown
= (float) portion
/ whole
;
6241 if (bar
->dragging
== -1)
6245 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
6246 is the scroll bar's maximum and MIN is the scroll bar's minimum
6248 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
6250 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
6251 value
= top
* XM_SB_MAX
;
6252 value
= min (value
, XM_SB_MAX
- size
);
6254 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
6256 #else /* !USE_MOTIF i.e. use Xaw */
6262 top
= (float) position
/ whole
;
6263 shown
= (float) portion
/ whole
;
6267 float old_top
, old_shown
;
6269 XtVaGetValues (widget
,
6270 XtNtopOfThumb
, &old_top
,
6271 XtNshown
, &old_shown
,
6275 /* Massage the top+shown values. */
6276 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
6277 top
= max (0, min (1, top
));
6280 #if ! defined (HAVE_XAW3D)
6281 /* With Xaw, 'top' values too closer to 1.0 may
6282 cause the thumb to disappear. Fix that. */
6283 top
= min (top
, 0.99f
);
6285 /* Keep two pixels available for moving the thumb down. */
6286 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
6287 #if ! defined (HAVE_XAW3D)
6288 /* Likewise with too small 'shown'. */
6289 shown
= max (shown
, 0.01f
);
6292 /* If the call to XawScrollbarSetThumb below doesn't seem to
6293 work, check that 'NARROWPROTO' is defined in src/config.h.
6294 If this is not so, most likely you need to fix configure. */
6295 if (top
!= old_top
|| shown
!= old_shown
)
6297 if (bar
->dragging
== -1)
6298 XawScrollbarSetThumb (widget
, top
, shown
);
6301 /* Try to make the scrolling a tad smoother. */
6302 if (!xaw3d_pick_top
)
6303 shown
= min (shown
, old_shown
);
6305 XawScrollbarSetThumb (widget
, top
, shown
);
6309 #endif /* !USE_MOTIF */
6315 x_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
6318 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6319 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6326 shown
= (float) portion
/ whole
;
6327 top
= (float) position
/ (whole
- portion
);
6329 int size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
6330 int value
= clip_to_bounds (0, top
* (XM_SB_MAX
- size
), XM_SB_MAX
- size
);
6332 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
6334 #else /* !USE_MOTIF i.e. use Xaw */
6340 top
= (float) position
/ whole
;
6341 shown
= (float) portion
/ whole
;
6345 float old_top
, old_shown
;
6347 XtVaGetValues (widget
,
6348 XtNtopOfThumb
, &old_top
,
6349 XtNshown
, &old_shown
,
6354 /* Massage the top+shown values. */
6355 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
6356 top
= max (0, min (1, top
));
6359 #if ! defined (HAVE_XAW3D)
6360 /* With Xaw, 'top' values too closer to 1.0 may
6361 cause the thumb to disappear. Fix that. */
6362 top
= min (top
, 0.99f
);
6364 /* Keep two pixels available for moving the thumb down. */
6365 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
6366 #if ! defined (HAVE_XAW3D)
6367 /* Likewise with too small 'shown'. */
6368 shown
= max (shown
, 0.01f
);
6372 /* If the call to XawScrollbarSetThumb below doesn't seem to
6373 work, check that 'NARROWPROTO' is defined in src/config.h.
6374 If this is not so, most likely you need to fix configure. */
6375 XawScrollbarSetThumb (widget
, top
, shown
);
6377 if (top
!= old_top
|| shown
!= old_shown
)
6379 if (bar
->dragging
== -1)
6380 XawScrollbarSetThumb (widget
, top
, shown
);
6383 /* Try to make the scrolling a tad smoother. */
6384 if (!xaw3d_pick_top
)
6385 shown
= min (shown
, old_shown
);
6387 XawScrollbarSetThumb (widget
, top
, shown
);
6392 #endif /* !USE_MOTIF */
6396 #endif /* not USE_GTK */
6398 #endif /* USE_TOOLKIT_SCROLL_BARS */
6402 /************************************************************************
6403 Scroll bars, general
6404 ************************************************************************/
6406 /* Create a scroll bar and return the scroll bar vector for it. W is
6407 the Emacs window on which to create the scroll bar. TOP, LEFT,
6408 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
6411 static struct scroll_bar
*
6412 x_scroll_bar_create (struct window
*w
, int top
, int left
,
6413 int width
, int height
, bool horizontal
)
6415 struct frame
*f
= XFRAME (w
->frame
);
6416 struct scroll_bar
*bar
6417 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
6422 #ifdef USE_TOOLKIT_SCROLL_BARS
6424 x_create_horizontal_toolkit_scroll_bar (f
, bar
);
6426 x_create_toolkit_scroll_bar (f
, bar
);
6427 #else /* not USE_TOOLKIT_SCROLL_BARS */
6429 XSetWindowAttributes a
;
6433 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6434 if (a
.background_pixel
== -1)
6435 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
6437 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
6438 | ButtonMotionMask
| PointerMotionHintMask
6440 a
.cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
6442 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
6444 /* Clear the area of W that will serve as a scroll bar. This is
6445 for the case that a window has been split horizontally. In
6446 this case, no clear_frame is generated to reduce flickering. */
6447 if (width
> 0 && window_box_height (w
) > 0)
6448 x_clear_area (f
, left
, top
, width
, window_box_height (w
));
6450 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6451 /* Position and size of scroll bar. */
6452 left
, top
, width
, height
,
6453 /* Border width, depth, class, and visual. */
6460 bar
->x_window
= window
;
6462 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6464 XSETWINDOW (bar
->window
, w
);
6468 bar
->height
= height
;
6472 bar
->horizontal
= horizontal
;
6473 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
6474 bar
->last_seen_part
= scroll_bar_nowhere
;
6477 /* Add bar to its frame's list of scroll bars. */
6478 bar
->next
= FRAME_SCROLL_BARS (f
);
6480 XSETVECTOR (barobj
, bar
);
6481 fset_scroll_bars (f
, barobj
);
6482 if (!NILP (bar
->next
))
6483 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6485 /* Map the window/widget. */
6486 #ifdef USE_TOOLKIT_SCROLL_BARS
6490 xg_update_horizontal_scrollbar_pos (f
, bar
->x_window
, top
,
6491 left
, width
, max (height
, 1));
6493 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
6494 left
, width
, max (height
, 1));
6495 #else /* not USE_GTK */
6496 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6497 XtConfigureWidget (scroll_bar
, left
, top
, width
, max (height
, 1), 0);
6498 XtMapWidget (scroll_bar
);
6499 #endif /* not USE_GTK */
6501 #else /* not USE_TOOLKIT_SCROLL_BARS */
6502 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
6503 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6510 #ifndef USE_TOOLKIT_SCROLL_BARS
6512 /* Draw BAR's handle in the proper position.
6514 If the handle is already drawn from START to END, don't bother
6515 redrawing it, unless REBUILD; in that case, always
6516 redraw it. (REBUILD is handy for drawing the handle after expose
6519 Normally, we want to constrain the start and end of the handle to
6520 fit inside its rectangle, but if the user is dragging the scroll
6521 bar handle, we want to let them drag it down all the way, so that
6522 the bar's top is as far down as it goes; otherwise, there's no way
6523 to move to the very end of the buffer. */
6526 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
,
6529 bool dragging
= bar
->dragging
!= -1;
6530 Window w
= bar
->x_window
;
6531 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6532 GC gc
= f
->output_data
.x
->normal_gc
;
6534 /* If the display is already accurate, do nothing. */
6536 && start
== bar
->start
6543 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
6544 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
6545 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
6547 /* Make sure the values are reasonable, and try to preserve
6548 the distance between start and end. */
6550 int length
= end
- start
;
6554 else if (start
> top_range
)
6556 end
= start
+ length
;
6560 else if (end
> top_range
&& ! dragging
)
6564 /* Store the adjusted setting in the scroll bar. */
6568 /* Clip the end position, just for display. */
6569 if (end
> top_range
)
6572 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
6573 below top positions, to make sure the handle is always at least
6574 that many pixels tall. */
6575 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
6577 /* Draw the empty space above the handle. Note that we can't clear
6578 zero-height areas; that means "clear to end of window." */
6579 if ((inside_width
> 0) && (start
> 0))
6580 x_clear_area1 (FRAME_X_DISPLAY (f
), w
,
6581 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
6582 VERTICAL_SCROLL_BAR_TOP_BORDER
,
6583 inside_width
, start
, False
);
6585 /* Change to proper foreground color if one is specified. */
6586 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
6587 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
6588 f
->output_data
.x
->scroll_bar_foreground_pixel
);
6590 /* Draw the handle itself. */
6591 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
6592 /* x, y, width, height */
6593 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
6594 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
6595 inside_width
, end
- start
);
6597 /* Restore the foreground color of the GC if we changed it above. */
6598 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
6599 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
6600 FRAME_FOREGROUND_PIXEL (f
));
6602 /* Draw the empty space below the handle. Note that we can't
6603 clear zero-height areas; that means "clear to end of window." */
6604 if ((inside_width
> 0) && (end
< inside_height
))
6605 x_clear_area1 (FRAME_X_DISPLAY (f
), w
,
6606 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
6607 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
6608 inside_width
, inside_height
- end
, False
);
6614 #endif /* !USE_TOOLKIT_SCROLL_BARS */
6616 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
6620 x_scroll_bar_remove (struct scroll_bar
*bar
)
6622 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6625 #ifdef USE_TOOLKIT_SCROLL_BARS
6627 xg_remove_scroll_bar (f
, bar
->x_window
);
6628 #else /* not USE_GTK */
6629 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
6630 #endif /* not USE_GTK */
6632 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
6635 /* Dissociate this scroll bar from its window. */
6636 if (bar
->horizontal
)
6637 wset_horizontal_scroll_bar (XWINDOW (bar
->window
), Qnil
);
6639 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
6645 /* Set the handle of the vertical scroll bar for WINDOW to indicate
6646 that we are displaying PORTION characters out of a total of WHOLE
6647 characters, starting at POSITION. If WINDOW has no scroll bar,
6651 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
6653 struct frame
*f
= XFRAME (w
->frame
);
6655 struct scroll_bar
*bar
;
6656 int top
, height
, left
, width
;
6657 int window_y
, window_height
;
6659 /* Get window dimensions. */
6660 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
6662 height
= window_height
;
6663 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
6664 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
6666 /* Does the scroll bar exist yet? */
6667 if (NILP (w
->vertical_scroll_bar
))
6669 if (width
> 0 && height
> 0)
6672 x_clear_area (f
, left
, top
, width
, height
);
6676 bar
= x_scroll_bar_create (w
, top
, left
, width
, max (height
, 1), false);
6680 /* It may just need to be moved and resized. */
6681 unsigned int mask
= 0;
6683 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
6687 if (left
!= bar
->left
)
6689 if (top
!= bar
->top
)
6691 if (width
!= bar
->width
)
6693 if (height
!= bar
->height
)
6696 #ifdef USE_TOOLKIT_SCROLL_BARS
6698 /* Move/size the scroll bar widget. */
6701 /* Since toolkit scroll bars are smaller than the space reserved
6702 for them on the frame, we have to clear "under" them. */
6703 if (width
> 0 && height
> 0)
6704 x_clear_area (f
, left
, top
, width
, height
);
6706 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
6707 left
, width
, max (height
, 1));
6708 #else /* not USE_GTK */
6709 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
6710 left
, top
, width
, max (height
, 1), 0);
6711 #endif /* not USE_GTK */
6713 #else /* not USE_TOOLKIT_SCROLL_BARS */
6715 /* Move/size the scroll bar window. */
6724 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
6728 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6730 /* Remember new settings. */
6734 bar
->height
= height
;
6739 #ifdef USE_TOOLKIT_SCROLL_BARS
6740 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
6741 #else /* not USE_TOOLKIT_SCROLL_BARS */
6742 /* Set the scroll bar's current state, unless we're currently being
6744 if (bar
->dragging
== -1)
6746 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
6749 x_scroll_bar_set_handle (bar
, 0, top_range
, false);
6752 int start
= ((double) position
* top_range
) / whole
;
6753 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
6754 x_scroll_bar_set_handle (bar
, start
, end
, false);
6757 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6759 XSETVECTOR (barobj
, bar
);
6760 wset_vertical_scroll_bar (w
, barobj
);
6765 XTset_horizontal_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
6767 struct frame
*f
= XFRAME (w
->frame
);
6769 struct scroll_bar
*bar
;
6770 int top
, height
, left
, width
;
6771 int window_x
, window_width
;
6772 int pixel_width
= WINDOW_PIXEL_WIDTH (w
);
6774 /* Get window dimensions. */
6775 window_box (w
, ANY_AREA
, &window_x
, 0, &window_width
, 0);
6777 width
= window_width
;
6778 top
= WINDOW_SCROLL_BAR_AREA_Y (w
);
6779 height
= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
6781 /* Does the scroll bar exist yet? */
6782 if (NILP (w
->horizontal_scroll_bar
))
6784 if (width
> 0 && height
> 0)
6788 /* Clear also part between window_width and
6789 WINDOW_PIXEL_WIDTH. */
6790 x_clear_area (f
, left
, top
, pixel_width
, height
);
6794 bar
= x_scroll_bar_create (w
, top
, left
, width
, height
, true);
6798 /* It may just need to be moved and resized. */
6799 unsigned int mask
= 0;
6801 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
6805 if (left
!= bar
->left
)
6807 if (top
!= bar
->top
)
6809 if (width
!= bar
->width
)
6811 if (height
!= bar
->height
)
6814 #ifdef USE_TOOLKIT_SCROLL_BARS
6815 /* Move/size the scroll bar widget. */
6818 /* Since toolkit scroll bars are smaller than the space reserved
6819 for them on the frame, we have to clear "under" them. */
6820 if (width
> 0 && height
> 0)
6822 WINDOW_LEFT_EDGE_X (w
), top
,
6823 pixel_width
- WINDOW_RIGHT_DIVIDER_WIDTH (w
), height
);
6825 xg_update_horizontal_scrollbar_pos (f
, bar
->x_window
, top
, left
,
6827 #else /* not USE_GTK */
6828 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
6829 left
, top
, width
, height
, 0);
6830 #endif /* not USE_GTK */
6832 #else /* not USE_TOOLKIT_SCROLL_BARS */
6834 /* Clear areas not covered by the scroll bar because it's not as
6835 wide as the area reserved for it. This makes sure a
6836 previous mode line display is cleared after C-x 2 C-x 1, for
6839 int area_height
= WINDOW_CONFIG_SCROLL_BAR_HEIGHT (w
);
6840 int rest
= area_height
- height
;
6841 if (rest
> 0 && width
> 0)
6842 x_clear_area (f
, left
, top
, width
, rest
);
6845 /* Move/size the scroll bar window. */
6854 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
6858 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6860 /* Remember new settings. */
6864 bar
->height
= height
;
6869 #ifdef USE_TOOLKIT_SCROLL_BARS
6870 x_set_toolkit_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
6871 #else /* not USE_TOOLKIT_SCROLL_BARS */
6872 /* Set the scroll bar's current state, unless we're currently being
6874 if (bar
->dragging
== -1)
6876 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, width
);
6879 x_scroll_bar_set_handle (bar
, 0, left_range
, false);
6882 int start
= ((double) position
* left_range
) / whole
;
6883 int end
= ((double) (position
+ portion
) * left_range
) / whole
;
6884 x_scroll_bar_set_handle (bar
, start
, end
, false);
6887 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6889 XSETVECTOR (barobj
, bar
);
6890 wset_horizontal_scroll_bar (w
, barobj
);
6894 /* The following three hooks are used when we're doing a thorough
6895 redisplay of the frame. We don't explicitly know which scroll bars
6896 are going to be deleted, because keeping track of when windows go
6897 away is a real pain - "Can you say set-window-configuration, boys
6898 and girls?" Instead, we just assert at the beginning of redisplay
6899 that *all* scroll bars are to be removed, and then save a scroll bar
6900 from the fiery pit when we actually redisplay its window. */
6902 /* Arrange for all scroll bars on FRAME to be removed at the next call
6903 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
6904 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
6907 XTcondemn_scroll_bars (struct frame
*frame
)
6909 if (!NILP (FRAME_SCROLL_BARS (frame
)))
6911 if (!NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
6913 /* Prepend scrollbars to already condemned ones. */
6914 Lisp_Object last
= FRAME_SCROLL_BARS (frame
);
6916 while (!NILP (XSCROLL_BAR (last
)->next
))
6917 last
= XSCROLL_BAR (last
)->next
;
6919 XSCROLL_BAR (last
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
6920 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= last
;
6923 fset_condemned_scroll_bars (frame
, FRAME_SCROLL_BARS (frame
));
6924 fset_scroll_bars (frame
, Qnil
);
6929 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
6930 Note that WINDOW isn't necessarily condemned at all. */
6933 XTredeem_scroll_bar (struct window
*w
)
6935 struct scroll_bar
*bar
;
6939 /* We can't redeem this window's scroll bar if it doesn't have one. */
6940 if (NILP (w
->vertical_scroll_bar
) && NILP (w
->horizontal_scroll_bar
))
6943 if (!NILP (w
->vertical_scroll_bar
) && WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
6945 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
6946 /* Unlink it from the condemned list. */
6947 f
= XFRAME (WINDOW_FRAME (w
));
6948 if (NILP (bar
->prev
))
6950 /* If the prev pointer is nil, it must be the first in one of
6952 if (EQ (FRAME_SCROLL_BARS (f
), w
->vertical_scroll_bar
))
6953 /* It's not condemned. Everything's fine. */
6955 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
6956 w
->vertical_scroll_bar
))
6957 fset_condemned_scroll_bars (f
, bar
->next
);
6959 /* If its prev pointer is nil, it must be at the front of
6960 one or the other! */
6964 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
6966 if (! NILP (bar
->next
))
6967 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
6969 bar
->next
= FRAME_SCROLL_BARS (f
);
6971 XSETVECTOR (barobj
, bar
);
6972 fset_scroll_bars (f
, barobj
);
6973 if (! NILP (bar
->next
))
6974 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6978 if (!NILP (w
->horizontal_scroll_bar
) && WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
6980 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
6981 /* Unlink it from the condemned list. */
6982 f
= XFRAME (WINDOW_FRAME (w
));
6983 if (NILP (bar
->prev
))
6985 /* If the prev pointer is nil, it must be the first in one of
6987 if (EQ (FRAME_SCROLL_BARS (f
), w
->horizontal_scroll_bar
))
6988 /* It's not condemned. Everything's fine. */
6990 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
6991 w
->horizontal_scroll_bar
))
6992 fset_condemned_scroll_bars (f
, bar
->next
);
6994 /* If its prev pointer is nil, it must be at the front of
6995 one or the other! */
6999 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
7001 if (! NILP (bar
->next
))
7002 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
7004 bar
->next
= FRAME_SCROLL_BARS (f
);
7006 XSETVECTOR (barobj
, bar
);
7007 fset_scroll_bars (f
, barobj
);
7008 if (! NILP (bar
->next
))
7009 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
7013 /* Remove all scroll bars on FRAME that haven't been saved since the
7014 last call to `*condemn_scroll_bars_hook'. */
7017 XTjudge_scroll_bars (struct frame
*f
)
7019 Lisp_Object bar
, next
;
7021 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
7023 /* Clear out the condemned list now so we won't try to process any
7024 more events on the hapless scroll bars. */
7025 fset_condemned_scroll_bars (f
, Qnil
);
7027 for (; ! NILP (bar
); bar
= next
)
7029 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
7031 x_scroll_bar_remove (b
);
7034 b
->next
= b
->prev
= Qnil
;
7037 /* Now there should be no references to the condemned scroll bars,
7038 and they should get garbage-collected. */
7042 #ifndef USE_TOOLKIT_SCROLL_BARS
7043 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
7044 is a no-op when using toolkit scroll bars.
7046 This may be called from a signal handler, so we have to ignore GC
7050 x_scroll_bar_expose (struct scroll_bar
*bar
, const XEvent
*event
)
7052 Window w
= bar
->x_window
;
7053 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7054 GC gc
= f
->output_data
.x
->normal_gc
;
7058 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, true);
7060 /* Switch to scroll bar foreground color. */
7061 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7062 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7063 f
->output_data
.x
->scroll_bar_foreground_pixel
);
7065 /* Draw a one-pixel border just inside the edges of the scroll bar. */
7066 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
7067 /* x, y, width, height */
7068 0, 0, bar
->width
- 1, bar
->height
- 1);
7070 /* Restore the foreground color of the GC if we changed it above. */
7071 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7072 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7073 FRAME_FOREGROUND_PIXEL (f
));
7078 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7080 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
7081 is set to something other than NO_EVENT, it is enqueued.
7083 This may be called from a signal handler, so we have to ignore GC
7088 x_scroll_bar_handle_click (struct scroll_bar
*bar
,
7089 const XEvent
*event
,
7090 struct input_event
*emacs_event
)
7092 if (! WINDOWP (bar
->window
))
7095 emacs_event
->kind
= (bar
->horizontal
7096 ? HORIZONTAL_SCROLL_BAR_CLICK_EVENT
7097 : SCROLL_BAR_CLICK_EVENT
);
7098 emacs_event
->code
= event
->xbutton
.button
- Button1
;
7099 emacs_event
->modifiers
7100 = (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO
7101 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
7102 event
->xbutton
.state
)
7103 | (event
->type
== ButtonRelease
7106 emacs_event
->frame_or_window
= bar
->window
;
7107 emacs_event
->arg
= Qnil
;
7108 emacs_event
->timestamp
= event
->xbutton
.time
;
7109 if (bar
->horizontal
)
7112 = HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
7113 int x
= event
->xbutton
.x
- HORIZONTAL_SCROLL_BAR_LEFT_BORDER
;
7116 if (x
> left_range
) x
= left_range
;
7119 emacs_event
->part
= scroll_bar_before_handle
;
7120 else if (x
< bar
->end
+ HORIZONTAL_SCROLL_BAR_MIN_HANDLE
)
7121 emacs_event
->part
= scroll_bar_horizontal_handle
;
7123 emacs_event
->part
= scroll_bar_after_handle
;
7125 #ifndef USE_TOOLKIT_SCROLL_BARS
7126 /* If the user has released the handle, set it to its final position. */
7127 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
7129 int new_start
= - bar
->dragging
;
7130 int new_end
= new_start
+ bar
->end
- bar
->start
;
7132 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
7137 XSETINT (emacs_event
->x
, left_range
);
7138 XSETINT (emacs_event
->y
, x
);
7143 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
7144 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
7147 if (y
> top_range
) y
= top_range
;
7150 emacs_event
->part
= scroll_bar_above_handle
;
7151 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
7152 emacs_event
->part
= scroll_bar_handle
;
7154 emacs_event
->part
= scroll_bar_below_handle
;
7156 #ifndef USE_TOOLKIT_SCROLL_BARS
7157 /* If the user has released the handle, set it to its final position. */
7158 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
7160 int new_start
= y
- bar
->dragging
;
7161 int new_end
= new_start
+ bar
->end
- bar
->start
;
7163 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
7168 XSETINT (emacs_event
->x
, y
);
7169 XSETINT (emacs_event
->y
, top_range
);
7173 #ifndef USE_TOOLKIT_SCROLL_BARS
7175 /* Handle some mouse motion while someone is dragging the scroll bar.
7177 This may be called from a signal handler, so we have to ignore GC
7181 x_scroll_bar_note_movement (struct scroll_bar
*bar
,
7182 const XMotionEvent
*event
)
7184 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
7185 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
7187 dpyinfo
->last_mouse_movement_time
= event
->time
;
7188 dpyinfo
->last_mouse_scroll_bar
= bar
;
7189 f
->mouse_moved
= true;
7191 /* If we're dragging the bar, display it. */
7192 if (bar
->dragging
!= -1)
7194 /* Where should the handle be now? */
7195 int new_start
= event
->y
- bar
->dragging
;
7197 if (new_start
!= bar
->start
)
7199 int new_end
= new_start
+ bar
->end
- bar
->start
;
7201 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
7206 #endif /* !USE_TOOLKIT_SCROLL_BARS */
7208 /* Return information to the user about the current position of the mouse
7209 on the scroll bar. */
7212 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
7213 enum scroll_bar_part
*part
, Lisp_Object
*x
,
7214 Lisp_Object
*y
, Time
*timestamp
)
7216 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
7217 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
7218 Window w
= bar
->x_window
;
7219 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7221 Window dummy_window
;
7223 unsigned int dummy_mask
;
7227 /* Get the mouse's position relative to the scroll bar window, and
7229 if (XQueryPointer (FRAME_X_DISPLAY (f
), w
,
7231 /* Root, child, root x and root y. */
7232 &dummy_window
, &dummy_window
,
7233 &dummy_coord
, &dummy_coord
,
7235 /* Position relative to scroll bar. */
7238 /* Mouse buttons and modifier keys. */
7241 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
7243 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
7245 if (bar
->dragging
!= -1)
7246 win_y
-= bar
->dragging
;
7250 if (win_y
> top_range
)
7254 *bar_window
= bar
->window
;
7256 if (bar
->dragging
!= -1)
7257 *part
= scroll_bar_handle
;
7258 else if (win_y
< bar
->start
)
7259 *part
= scroll_bar_above_handle
;
7260 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
7261 *part
= scroll_bar_handle
;
7263 *part
= scroll_bar_below_handle
;
7265 XSETINT (*x
, win_y
);
7266 XSETINT (*y
, top_range
);
7268 f
->mouse_moved
= false;
7269 dpyinfo
->last_mouse_scroll_bar
= NULL
;
7270 *timestamp
= dpyinfo
->last_mouse_movement_time
;
7277 /* Return information to the user about the current position of the mouse
7278 on the scroll bar. */
7281 x_horizontal_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
7282 enum scroll_bar_part
*part
, Lisp_Object
*x
,
7283 Lisp_Object
*y
, Time
*timestamp
)
7285 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
7286 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
7287 Window w
= bar
->x_window
;
7288 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7290 Window dummy_window
;
7292 unsigned int dummy_mask
;
7296 /* Get the mouse's position relative to the scroll bar window, and
7298 if (XQueryPointer (FRAME_X_DISPLAY (f
), w
,
7300 /* Root, child, root x and root y. */
7301 &dummy_window
, &dummy_window
,
7302 &dummy_coord
, &dummy_coord
,
7304 /* Position relative to scroll bar. */
7307 /* Mouse buttons and modifier keys. */
7310 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
7312 win_x
-= HORIZONTAL_SCROLL_BAR_LEFT_BORDER
;
7314 if (bar
->dragging
!= -1)
7315 win_x
-= bar
->dragging
;
7319 if (win_x
> left_range
)
7323 *bar_window
= bar
->window
;
7325 if (bar
->dragging
!= -1)
7326 *part
= scroll_bar_horizontal_handle
;
7327 else if (win_x
< bar
->start
)
7328 *part
= scroll_bar_before_handle
;
7329 else if (win_x
< bar
->end
+ HORIZONTAL_SCROLL_BAR_MIN_HANDLE
)
7330 *part
= scroll_bar_handle
;
7332 *part
= scroll_bar_after_handle
;
7334 XSETINT (*y
, win_x
);
7335 XSETINT (*x
, left_range
);
7337 f
->mouse_moved
= false;
7338 dpyinfo
->last_mouse_scroll_bar
= NULL
;
7339 *timestamp
= dpyinfo
->last_mouse_movement_time
;
7346 /* The screen has been cleared so we may have changed foreground or
7347 background colors, and the scroll bars may need to be redrawn.
7348 Clear out the scroll bars, and ask for expose events, so we can
7352 x_scroll_bar_clear (struct frame
*f
)
7354 #ifndef USE_TOOLKIT_SCROLL_BARS
7357 /* We can have scroll bars even if this is 0,
7358 if we just turned off scroll bar mode.
7359 But in that case we should not clear them. */
7360 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
7361 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
7362 bar
= XSCROLL_BAR (bar
)->next
)
7363 XClearArea (FRAME_X_DISPLAY (f
),
7364 XSCROLL_BAR (bar
)->x_window
,
7366 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7369 #ifdef ENABLE_CHECKING
7371 /* Record the last 100 characters stored
7372 to help debug the loss-of-chars-during-GC problem. */
7374 static int temp_index
;
7375 static short temp_buffer
[100];
7377 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
7378 if (temp_index == ARRAYELTS (temp_buffer)) \
7380 temp_buffer[temp_index++] = (keysym)
7382 #else /* not ENABLE_CHECKING */
7384 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
7386 #endif /* ENABLE_CHECKING */
7388 /* Set this to nonzero to fake an "X I/O error"
7389 on a particular display. */
7391 static struct x_display_info
*XTread_socket_fake_io_error
;
7393 /* When we find no input here, we occasionally do a no-op command
7394 to verify that the X server is still running and we can still talk with it.
7395 We try all the open displays, one by one.
7396 This variable is used for cycling thru the displays. */
7398 static struct x_display_info
*next_noop_dpyinfo
;
7407 /* Filter events for the current X input method.
7408 DPYINFO is the display this event is for.
7409 EVENT is the X event to filter.
7411 Returns non-zero if the event was filtered, caller shall not process
7413 Returns zero if event is wasn't filtered. */
7417 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
7419 /* XFilterEvent returns non-zero if the input method has
7420 consumed the event. We pass the frame's X window to
7421 XFilterEvent because that's the one for which the IC
7424 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
7425 event
->xclient
.window
);
7427 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
7432 static int current_count
;
7433 static int current_finish
;
7434 static struct input_event
*current_hold_quit
;
7436 /* This is the filter function invoked by the GTK event loop.
7437 It is invoked before the XEvent is translated to a GdkEvent,
7438 so we have a chance to act on the event before GTK. */
7439 static GdkFilterReturn
7440 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
7442 XEvent
*xev
= (XEvent
*) gxev
;
7445 if (current_count
>= 0)
7447 struct x_display_info
*dpyinfo
;
7449 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
7452 /* Filter events for the current X input method.
7453 GTK calls XFilterEvent but not for key press and release,
7454 so we do it here. */
7455 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
7457 && x_filter_event (dpyinfo
, xev
))
7460 return GDK_FILTER_REMOVE
;
7465 current_finish
= X_EVENT_NORMAL
;
7468 += handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
7472 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
7476 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
7477 return GDK_FILTER_REMOVE
;
7479 return GDK_FILTER_CONTINUE
;
7481 #endif /* USE_GTK */
7484 static void xembed_send_message (struct frame
*f
, Time
,
7485 enum xembed_message
,
7486 long detail
, long data1
, long data2
);
7489 x_net_wm_state (struct frame
*f
, Window window
)
7491 int value
= FULLSCREEN_NONE
;
7492 Lisp_Object lval
= Qnil
;
7493 bool sticky
= false;
7495 get_current_wm_state (f
, window
, &value
, &sticky
);
7499 case FULLSCREEN_WIDTH
:
7502 case FULLSCREEN_HEIGHT
:
7505 case FULLSCREEN_BOTH
:
7508 case FULLSCREEN_MAXIMIZED
:
7513 frame_size_history_add
7514 (f
, Qx_net_wm_state
, 0, 0,
7515 list2 (get_frame_param (f
, Qfullscreen
), lval
));
7517 store_frame_param (f
, Qfullscreen
, lval
);
7518 /** store_frame_param (f, Qsticky, sticky ? Qt : Qnil); **/
7521 /* Flip back buffers on any frames with undrawn content. */
7523 flush_dirty_back_buffers (void)
7526 Lisp_Object tail
, frame
;
7527 FOR_EACH_FRAME (tail
, frame
)
7529 struct frame
*f
= XFRAME (frame
);
7530 if (FRAME_LIVE_P (f
) &&
7532 FRAME_X_WINDOW (f
) &&
7533 !FRAME_GARBAGED_P (f
) &&
7534 !buffer_flipping_blocked_p () &&
7535 FRAME_X_NEED_BUFFER_FLIP (f
))
7536 show_back_buffer (f
);
7541 /* Handles the XEvent EVENT on display DPYINFO.
7543 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
7544 *FINISH is zero if caller should continue reading events.
7545 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
7546 *EVENT is unchanged unless we're processing KeyPress event.
7548 We return the number of characters stored into the buffer. */
7551 handle_one_xevent (struct x_display_info
*dpyinfo
,
7552 const XEvent
*event
,
7553 int *finish
, struct input_event
*hold_quit
)
7555 union buffered_input_event inev
;
7558 ptrdiff_t nbytes
= 0;
7559 struct frame
*any
, *f
= NULL
;
7560 struct coding_system coding
;
7561 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
7562 /* This holds the state XLookupString needs to implement dead keys
7563 and other tricks known as "compose processing". _X Window System_
7564 says that a portable program can't use this, but Stephen Gildea assures
7565 me that letting the compiler initialize it to zeros will work okay. */
7566 static XComposeStatus compose_status
;
7567 XEvent configureEvent
;
7572 *finish
= X_EVENT_NORMAL
;
7574 EVENT_INIT (inev
.ie
);
7575 inev
.ie
.kind
= NO_EVENT
;
7578 any
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
7580 if (any
&& any
->wait_event_type
== event
->type
)
7581 any
->wait_event_type
= 0; /* Indicates we got it. */
7583 switch (event
->type
)
7587 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_protocols
7588 && event
->xclient
.format
== 32)
7590 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_take_focus
)
7592 /* Use the value returned by x_any_window_to_frame
7593 because this could be the shell widget window
7594 if the frame has no title bar. */
7597 /* Not quite sure this is needed -pd */
7598 if (f
&& FRAME_XIC (f
))
7599 XSetICFocus (FRAME_XIC (f
));
7602 /* Emacs sets WM hints whose `input' field is `true'. This
7603 instructs the WM to set the input focus automatically for
7604 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
7605 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
7606 it has set the focus. So, XSetInputFocus below is not
7609 The call to XSetInputFocus below has also caused trouble. In
7610 cases where the XSetInputFocus done by the WM and the one
7611 below are temporally close (on a fast machine), the call
7612 below can generate additional FocusIn events which confuse
7615 /* Since we set WM_TAKE_FOCUS, we must call
7616 XSetInputFocus explicitly. But not if f is null,
7617 since that might be an event for a deleted frame. */
7620 Display
*d
= event
->xclient
.display
;
7621 /* Catch and ignore errors, in case window has been
7622 iconified by a window manager such as GWM. */
7624 XSetInputFocus (d
, event
->xclient
.window
,
7625 /* The ICCCM says this is
7626 the only valid choice. */
7628 event
->xclient
.data
.l
[1]);
7629 x_uncatch_errors ();
7631 /* Not certain about handling scroll bars here */
7636 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_save_yourself
)
7638 /* Save state modify the WM_COMMAND property to
7639 something which can reinstate us. This notifies
7640 the session manager, who's looking for such a
7641 PropertyNotify. Can restart processing when
7642 a keyboard or mouse event arrives. */
7643 /* If we have a session manager, don't set this.
7644 KDE will then start two Emacsen, one for the
7645 session manager and one for this. */
7647 if (! x_session_have_connection ())
7650 f
= x_top_window_to_frame (dpyinfo
,
7651 event
->xclient
.window
);
7652 /* This is just so we only give real data once
7653 for a single Emacs process. */
7654 if (f
== SELECTED_FRAME ())
7655 XSetCommand (FRAME_X_DISPLAY (f
),
7656 event
->xclient
.window
,
7657 initial_argv
, initial_argc
);
7659 XSetCommand (FRAME_X_DISPLAY (f
),
7660 event
->xclient
.window
,
7666 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_delete_window
)
7670 goto OTHER
; /* May be a dialog that is to be removed */
7672 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
7673 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7680 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_configure_denied
)
7683 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_window_moved
)
7686 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
7688 new_x
= event
->xclient
.data
.s
[0];
7689 new_y
= event
->xclient
.data
.s
[1];
7693 f
->left_pos
= new_x
;
7699 #ifdef X_TOOLKIT_EDITRES
7700 if (event
->xclient
.message_type
== dpyinfo
->Xatom_editres
)
7704 _XEditResCheckMessages (f
->output_data
.x
->widget
,
7705 NULL
, (XEvent
*) event
, NULL
);
7708 #endif /* X_TOOLKIT_EDITRES */
7710 if (event
->xclient
.message_type
== dpyinfo
->Xatom_DONE
7711 || event
->xclient
.message_type
== dpyinfo
->Xatom_PAGE
)
7713 /* Ghostview job completed. Kill it. We could
7714 reply with "Next" if we received "Page", but we
7715 currently never do because we are interested in
7716 images, only, which should have 1 page. */
7717 Pixmap pixmap
= (Pixmap
) event
->xclient
.data
.l
[1];
7718 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
7721 x_kill_gs_process (pixmap
, f
);
7722 expose_frame (f
, 0, 0, 0, 0);
7726 #ifdef USE_TOOLKIT_SCROLL_BARS
7727 /* Scroll bar callbacks send a ClientMessage from which
7728 we construct an input_event. */
7729 if (event
->xclient
.message_type
== dpyinfo
->Xatom_Scrollbar
)
7731 x_scroll_bar_to_input_event (event
, &inev
.ie
);
7732 *finish
= X_EVENT_GOTO_OUT
;
7735 else if (event
->xclient
.message_type
== dpyinfo
->Xatom_Horizontal_Scrollbar
)
7737 x_horizontal_scroll_bar_to_input_event (event
, &inev
.ie
);
7738 *finish
= X_EVENT_GOTO_OUT
;
7741 #endif /* USE_TOOLKIT_SCROLL_BARS */
7743 /* XEmbed messages from the embedder (if any). */
7744 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
7746 enum xembed_message msg
= event
->xclient
.data
.l
[1];
7747 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
7748 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
7750 *finish
= X_EVENT_GOTO_OUT
;
7754 xft_settings_event (dpyinfo
, event
);
7759 if (x_handle_dnd_message (f
, &event
->xclient
, dpyinfo
, &inev
.ie
))
7760 *finish
= X_EVENT_DROP
;
7764 case SelectionNotify
:
7765 x_display_set_last_user_time (dpyinfo
, event
->xselection
.time
);
7766 #ifdef USE_X_TOOLKIT
7767 if (! x_window_to_frame (dpyinfo
, event
->xselection
.requestor
))
7769 #endif /* not USE_X_TOOLKIT */
7770 x_handle_selection_notify (&event
->xselection
);
7773 case SelectionClear
: /* Someone has grabbed ownership. */
7774 x_display_set_last_user_time (dpyinfo
, event
->xselectionclear
.time
);
7775 #ifdef USE_X_TOOLKIT
7776 if (! x_window_to_frame (dpyinfo
, event
->xselectionclear
.window
))
7778 #endif /* USE_X_TOOLKIT */
7780 const XSelectionClearEvent
*eventp
= &event
->xselectionclear
;
7782 inev
.sie
.kind
= SELECTION_CLEAR_EVENT
;
7783 SELECTION_EVENT_DPYINFO (&inev
.sie
) = dpyinfo
;
7784 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
7785 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
7789 case SelectionRequest
: /* Someone wants our selection. */
7790 x_display_set_last_user_time (dpyinfo
, event
->xselectionrequest
.time
);
7791 #ifdef USE_X_TOOLKIT
7792 if (!x_window_to_frame (dpyinfo
, event
->xselectionrequest
.owner
))
7794 #endif /* USE_X_TOOLKIT */
7796 const XSelectionRequestEvent
*eventp
= &event
->xselectionrequest
;
7798 inev
.sie
.kind
= SELECTION_REQUEST_EVENT
;
7799 SELECTION_EVENT_DPYINFO (&inev
.sie
) = dpyinfo
;
7800 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
7801 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
7802 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
7803 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
7804 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
7808 case PropertyNotify
:
7809 x_display_set_last_user_time (dpyinfo
, event
->xproperty
.time
);
7810 f
= x_top_window_to_frame (dpyinfo
, event
->xproperty
.window
);
7811 if (f
&& event
->xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
7813 bool not_hidden
= x_handle_net_wm_state (f
, &event
->xproperty
);
7814 if (not_hidden
&& FRAME_ICONIFIED_P (f
))
7816 /* Gnome shell does not iconify us when C-z is pressed.
7817 It hides the frame. So if our state says we aren't
7818 hidden anymore, treat it as deiconified. */
7819 SET_FRAME_VISIBLE (f
, 1);
7820 SET_FRAME_ICONIFIED (f
, false);
7821 f
->output_data
.x
->has_been_visible
= true;
7822 inev
.ie
.kind
= DEICONIFY_EVENT
;
7823 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7825 else if (! not_hidden
&& ! FRAME_ICONIFIED_P (f
))
7827 SET_FRAME_VISIBLE (f
, 0);
7828 SET_FRAME_ICONIFIED (f
, true);
7829 inev
.ie
.kind
= ICONIFY_EVENT
;
7830 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7834 x_handle_property_notify (&event
->xproperty
);
7835 xft_settings_event (dpyinfo
, event
);
7838 case ReparentNotify
:
7839 f
= x_top_window_to_frame (dpyinfo
, event
->xreparent
.window
);
7842 f
->output_data
.x
->parent_desc
= event
->xreparent
.parent
;
7843 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
7845 /* Perhaps reparented due to a WM restart. Reset this. */
7846 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
7847 FRAME_DISPLAY_INFO (f
)->net_supported_window
= 0;
7849 x_set_frame_alpha (f
);
7854 f
= x_window_to_frame (dpyinfo
, event
->xexpose
.window
);
7857 if (!FRAME_VISIBLE_P (f
))
7860 SET_FRAME_VISIBLE (f
, 1);
7861 SET_FRAME_ICONIFIED (f
, false);
7862 if (FRAME_X_DOUBLE_BUFFERED_P (f
))
7863 font_drop_xrender_surfaces (f
);
7864 f
->output_data
.x
->has_been_visible
= true;
7865 SET_FRAME_GARBAGED (f
);
7868 else if (FRAME_GARBAGED_P (f
))
7871 /* Go around the back buffer and manually clear the
7872 window the first time we show it. This way, we avoid
7873 showing users the sanity-defying horror of whatever
7874 GtkWindow is rendering beneath us. We've garbaged
7875 the frame, so we'll redraw the whole thing on next
7876 redisplay anyway. Yuck. */
7878 FRAME_X_DISPLAY (f
),
7880 event
->xexpose
.x
, event
->xexpose
.y
,
7881 event
->xexpose
.width
, event
->xexpose
.height
,
7887 if (!FRAME_GARBAGED_P (f
))
7890 /* This seems to be needed for GTK 2.6 and later, see
7891 http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15398. */
7893 event
->xexpose
.x
, event
->xexpose
.y
,
7894 event
->xexpose
.width
, event
->xexpose
.height
);
7896 expose_frame (f
, event
->xexpose
.x
, event
->xexpose
.y
,
7897 event
->xexpose
.width
, event
->xexpose
.height
);
7900 if (!FRAME_GARBAGED_P (f
))
7901 show_back_buffer (f
);
7905 #ifndef USE_TOOLKIT_SCROLL_BARS
7906 struct scroll_bar
*bar
;
7908 #if defined USE_LUCID
7909 /* Submenus of the Lucid menu bar aren't widgets
7910 themselves, so there's no way to dispatch events
7911 to them. Recognize this case separately. */
7913 Widget widget
= x_window_to_menu_bar (event
->xexpose
.window
);
7915 xlwmenu_redisplay (widget
);
7917 #endif /* USE_LUCID */
7919 #ifdef USE_TOOLKIT_SCROLL_BARS
7920 /* Dispatch event to the widget. */
7922 #else /* not USE_TOOLKIT_SCROLL_BARS */
7923 bar
= x_window_to_scroll_bar (event
->xexpose
.display
,
7924 event
->xexpose
.window
, 2);
7927 x_scroll_bar_expose (bar
, event
);
7928 #ifdef USE_X_TOOLKIT
7931 #endif /* USE_X_TOOLKIT */
7932 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7936 case GraphicsExpose
: /* This occurs when an XCopyArea's
7937 source area was obscured or not
7939 f
= x_window_to_frame (dpyinfo
, event
->xgraphicsexpose
.drawable
);
7942 expose_frame (f
, event
->xgraphicsexpose
.x
,
7943 event
->xgraphicsexpose
.y
,
7944 event
->xgraphicsexpose
.width
,
7945 event
->xgraphicsexpose
.height
);
7946 show_back_buffer (f
);
7948 #ifdef USE_X_TOOLKIT
7951 #endif /* USE_X_TOOLKIT */
7954 case NoExpose
: /* This occurs when an XCopyArea's
7955 source area was completely
7960 /* Redo the mouse-highlight after the tooltip has gone. */
7961 if (event
->xunmap
.window
== tip_window
)
7964 x_redo_mouse_highlight (dpyinfo
);
7967 f
= x_top_window_to_frame (dpyinfo
, event
->xunmap
.window
);
7968 if (f
) /* F may no longer exist if
7969 the frame was deleted. */
7971 bool visible
= FRAME_VISIBLE_P (f
);
7972 /* While a frame is unmapped, display generation is
7973 disabled; you don't want to spend time updating a
7974 display that won't ever be seen. */
7975 SET_FRAME_VISIBLE (f
, 0);
7976 /* We can't distinguish, from the event, whether the window
7977 has become iconified or invisible. So assume, if it
7978 was previously visible, than now it is iconified.
7979 But x_make_frame_invisible clears both
7980 the visible flag and the iconified flag;
7981 and that way, we know the window is not iconified now. */
7982 if (visible
|| FRAME_ICONIFIED_P (f
))
7984 SET_FRAME_ICONIFIED (f
, true);
7985 inev
.ie
.kind
= ICONIFY_EVENT
;
7986 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7992 /* We use x_top_window_to_frame because map events can
7993 come for sub-windows and they don't mean that the
7994 frame is visible. */
7995 f
= x_top_window_to_frame (dpyinfo
, event
->xmap
.window
);
7998 bool iconified
= FRAME_ICONIFIED_P (f
);
8000 /* Check if fullscreen was specified before we where mapped the
8001 first time, i.e. from the command line. */
8002 if (!f
->output_data
.x
->has_been_visible
)
8003 x_check_fullscreen (f
);
8005 SET_FRAME_VISIBLE (f
, 1);
8006 SET_FRAME_ICONIFIED (f
, false);
8007 f
->output_data
.x
->has_been_visible
= true;
8011 inev
.ie
.kind
= DEICONIFY_EVENT
;
8012 XSETFRAME (inev
.ie
.frame_or_window
, f
);
8014 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
8015 /* Force a redisplay sooner or later to update the
8016 frame titles in case this is the second frame. */
8017 record_asynch_buffer_change ();
8023 x_display_set_last_user_time (dpyinfo
, event
->xkey
.time
);
8024 ignore_next_mouse_click_timeout
= 0;
8026 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8027 /* Dispatch KeyPress events when in menu. */
8028 if (popup_activated ())
8034 /* If mouse-highlight is an integer, input clears out
8035 mouse highlighting. */
8036 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
8037 #if ! defined (USE_GTK)
8039 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
8043 clear_mouse_face (hlinfo
);
8044 hlinfo
->mouse_face_hidden
= true;
8047 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
8050 /* Scroll bars consume key events, but we want
8051 the keys to go to the scroll bar's frame. */
8052 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
8053 event
->xkey
.window
);
8054 if (widget
&& XmIsScrollBar (widget
))
8056 widget
= XtParent (widget
);
8057 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
8060 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
8064 KeySym keysym
, orig_keysym
;
8065 /* al%imercury@uunet.uu.net says that making this 81
8066 instead of 80 fixed a bug whereby meta chars made
8069 It seems that some version of XmbLookupString has
8070 a bug of not returning XBufferOverflow in
8071 status_return even if the input is too long to
8072 fit in 81 bytes. So, we must prepare sufficient
8073 bytes for copy_buffer. 513 bytes (256 chars for
8074 two-byte character set) seems to be a fairly good
8075 approximation. -- 2000.8.10 handa@etl.go.jp */
8076 unsigned char copy_buffer
[513];
8077 unsigned char *copy_bufptr
= copy_buffer
;
8078 int copy_bufsiz
= sizeof (copy_buffer
);
8080 Lisp_Object coding_system
= Qlatin_1
;
8082 /* Event will be modified. */
8083 XKeyEvent xkey
= event
->xkey
;
8086 /* Don't pass keys to GTK. A Tab will shift focus to the
8087 tool bar in GTK 2.4. Keys will still go to menus and
8088 dialogs because in that case popup_activated is nonzero
8090 *finish
= X_EVENT_DROP
;
8093 xkey
.state
|= x_emacs_to_x_modifiers (FRAME_DISPLAY_INFO (f
),
8094 extra_keyboard_modifiers
);
8095 modifiers
= xkey
.state
;
8097 /* This will have to go some day... */
8099 /* make_lispy_event turns chars into control chars.
8100 Don't do it here because XLookupString is too eager. */
8101 xkey
.state
&= ~ControlMask
;
8102 xkey
.state
&= ~(dpyinfo
->meta_mod_mask
8103 | dpyinfo
->super_mod_mask
8104 | dpyinfo
->hyper_mod_mask
8105 | dpyinfo
->alt_mod_mask
);
8107 /* In case Meta is ComposeCharacter,
8108 clear its status. According to Markus Ehrnsperger
8109 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
8110 this enables ComposeCharacter to work whether or
8111 not it is combined with Meta. */
8112 if (modifiers
& dpyinfo
->meta_mod_mask
)
8113 memset (&compose_status
, 0, sizeof (compose_status
));
8118 Status status_return
;
8120 coding_system
= Vlocale_coding_system
;
8121 nbytes
= XmbLookupString (FRAME_XIC (f
),
8122 &xkey
, (char *) copy_bufptr
,
8123 copy_bufsiz
, &keysym
,
8125 if (status_return
== XBufferOverflow
)
8127 copy_bufsiz
= nbytes
+ 1;
8128 copy_bufptr
= alloca (copy_bufsiz
);
8129 nbytes
= XmbLookupString (FRAME_XIC (f
),
8130 &xkey
, (char *) copy_bufptr
,
8131 copy_bufsiz
, &keysym
,
8134 /* Xutf8LookupString is a new but already deprecated interface. -stef */
8135 if (status_return
== XLookupNone
)
8137 else if (status_return
== XLookupChars
)
8142 else if (status_return
!= XLookupKeySym
8143 && status_return
!= XLookupBoth
)
8147 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
8148 copy_bufsiz
, &keysym
,
8151 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
8152 copy_bufsiz
, &keysym
,
8156 /* If not using XIM/XIC, and a compose sequence is in progress,
8157 we break here. Otherwise, chars_matched is always 0. */
8158 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
8161 memset (&compose_status
, 0, sizeof (compose_status
));
8162 orig_keysym
= keysym
;
8164 /* Common for all keysym input events. */
8165 XSETFRAME (inev
.ie
.frame_or_window
, f
);
8167 = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
), modifiers
);
8168 inev
.ie
.timestamp
= xkey
.time
;
8170 /* First deal with keysyms which have defined
8171 translations to characters. */
8172 if (keysym
>= 32 && keysym
< 128)
8173 /* Avoid explicitly decoding each ASCII character. */
8175 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
8176 inev
.ie
.code
= keysym
;
8180 /* Keysyms directly mapped to Unicode characters. */
8181 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
8183 if (keysym
< 0x01000080)
8184 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
8186 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
8187 inev
.ie
.code
= keysym
& 0xFFFFFF;
8191 /* Now non-ASCII. */
8192 if (HASH_TABLE_P (Vx_keysym_table
)
8193 && (c
= Fgethash (make_number (keysym
),
8198 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
8199 ? ASCII_KEYSTROKE_EVENT
8200 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
8201 inev
.ie
.code
= XFASTINT (c
);
8205 /* Random non-modifier sorts of keysyms. */
8206 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
8207 || keysym
== XK_Delete
8208 #ifdef XK_ISO_Left_Tab
8209 || (keysym
>= XK_ISO_Left_Tab
8210 && keysym
<= XK_ISO_Enter
)
8212 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
8213 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
8215 /* This recognizes the "extended function
8216 keys". It seems there's no cleaner way.
8217 Test IsModifierKey to avoid handling
8218 mode_switch incorrectly. */
8219 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
8221 #ifdef XK_dead_circumflex
8222 || orig_keysym
== XK_dead_circumflex
8224 #ifdef XK_dead_grave
8225 || orig_keysym
== XK_dead_grave
8227 #ifdef XK_dead_tilde
8228 || orig_keysym
== XK_dead_tilde
8230 #ifdef XK_dead_diaeresis
8231 || orig_keysym
== XK_dead_diaeresis
8233 #ifdef XK_dead_macron
8234 || orig_keysym
== XK_dead_macron
8236 #ifdef XK_dead_degree
8237 || orig_keysym
== XK_dead_degree
8239 #ifdef XK_dead_acute
8240 || orig_keysym
== XK_dead_acute
8242 #ifdef XK_dead_cedilla
8243 || orig_keysym
== XK_dead_cedilla
8245 #ifdef XK_dead_breve
8246 || orig_keysym
== XK_dead_breve
8248 #ifdef XK_dead_ogonek
8249 || orig_keysym
== XK_dead_ogonek
8251 #ifdef XK_dead_caron
8252 || orig_keysym
== XK_dead_caron
8254 #ifdef XK_dead_doubleacute
8255 || orig_keysym
== XK_dead_doubleacute
8257 #ifdef XK_dead_abovedot
8258 || orig_keysym
== XK_dead_abovedot
8260 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
8261 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
8262 /* Any "vendor-specific" key is ok. */
8263 || (orig_keysym
& (1 << 28))
8264 || (keysym
!= NoSymbol
&& nbytes
== 0))
8265 && ! (IsModifierKey (orig_keysym
)
8266 /* The symbols from XK_ISO_Lock
8267 to XK_ISO_Last_Group_Lock
8268 don't have real modifiers but
8269 should be treated similarly to
8270 Mode_switch by Emacs. */
8271 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
8272 || (XK_ISO_Lock
<= orig_keysym
8273 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
8277 STORE_KEYSYM_FOR_DEBUG (keysym
);
8278 /* make_lispy_event will convert this to a symbolic
8280 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
8281 inev
.ie
.code
= keysym
;
8285 { /* Raw bytes, not keysym. */
8289 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
8291 if (ASCII_CHAR_P (copy_bufptr
[i
]))
8293 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
8296 if (nchars
< nbytes
)
8298 /* Decode the input data. */
8300 /* The input should be decoded with `coding_system'
8301 which depends on which X*LookupString function
8302 we used just above and the locale. */
8303 setup_coding_system (coding_system
, &coding
);
8304 coding
.src_multibyte
= false;
8305 coding
.dst_multibyte
= true;
8306 /* The input is converted to events, thus we can't
8307 handle composition. Anyway, there's no XIM that
8308 gives us composition information. */
8309 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
8311 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
8313 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
8314 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
8315 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
8316 nbytes
= coding
.produced
;
8317 nchars
= coding
.produced_char
;
8318 copy_bufptr
= coding
.destination
;
8321 /* Convert the input data to a sequence of
8322 character events. */
8323 for (i
= 0; i
< nbytes
; i
+= len
)
8326 if (nchars
== nbytes
)
8327 ch
= copy_bufptr
[i
], len
= 1;
8329 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
8330 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
8331 ? ASCII_KEYSTROKE_EVENT
8332 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
8334 kbd_buffer_store_buffered_event (&inev
, hold_quit
);
8339 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
8341 if (keysym
== NoSymbol
)
8344 /* FIXME: check side effects and remove this. */
8345 ((XEvent
*) event
)->xkey
= xkey
;
8349 /* Don't dispatch this event since XtDispatchEvent calls
8350 XFilterEvent, and two calls in a row may freeze the
8358 x_display_set_last_user_time (dpyinfo
, event
->xkey
.time
);
8360 /* Don't dispatch this event since XtDispatchEvent calls
8361 XFilterEvent, and two calls in a row may freeze the
8369 x_display_set_last_user_time (dpyinfo
, event
->xcrossing
.time
);
8370 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8374 if (f
&& x_mouse_click_focus_ignore_position
)
8375 ignore_next_mouse_click_timeout
= event
->xmotion
.time
+ 200;
8377 /* EnterNotify counts as mouse movement,
8378 so update things that depend on mouse position. */
8379 if (f
&& !f
->output_data
.x
->hourglass_p
)
8380 note_mouse_movement (f
, &event
->xmotion
);
8382 /* We may get an EnterNotify on the buttons in the toolbar. In that
8383 case we moved out of any highlighted area and need to note this. */
8384 if (!f
&& dpyinfo
->last_mouse_glyph_frame
)
8385 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
8390 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8394 x_display_set_last_user_time (dpyinfo
, event
->xcrossing
.time
);
8395 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8397 f
= x_top_window_to_frame (dpyinfo
, event
->xcrossing
.window
);
8400 if (f
== hlinfo
->mouse_face_mouse_frame
)
8402 /* If we move outside the frame, then we're
8403 certainly no longer on any text in the frame. */
8404 clear_mouse_face (hlinfo
);
8405 hlinfo
->mouse_face_mouse_frame
= 0;
8408 /* Generate a nil HELP_EVENT to cancel a help-echo.
8409 Do it only if there's something to cancel.
8410 Otherwise, the startup message is cleared when
8411 the mouse leaves the frame. */
8412 if (any_help_event_p
)
8416 /* See comment in EnterNotify above */
8417 else if (dpyinfo
->last_mouse_glyph_frame
)
8418 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
8423 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8428 x_display_set_last_user_time (dpyinfo
, event
->xmotion
.time
);
8429 previous_help_echo_string
= help_echo_string
;
8430 help_echo_string
= Qnil
;
8432 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
8433 : x_window_to_frame (dpyinfo
, event
->xmotion
.window
));
8435 if (hlinfo
->mouse_face_hidden
)
8437 hlinfo
->mouse_face_hidden
= false;
8438 clear_mouse_face (hlinfo
);
8442 if (f
&& xg_event_is_for_scrollbar (f
, event
))
8448 /* Generate SELECT_WINDOW_EVENTs when needed.
8449 Don't let popup menus influence things (bug#1261). */
8450 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
8452 static Lisp_Object last_mouse_window
;
8453 Lisp_Object window
= window_from_coordinates
8454 (f
, event
->xmotion
.x
, event
->xmotion
.y
, 0, false);
8456 /* Window will be selected only when it is not selected now and
8457 last mouse movement event was not in it. Minibuffer window
8458 will be selected only when it is active. */
8459 if (WINDOWP (window
)
8460 && !EQ (window
, last_mouse_window
)
8461 && !EQ (window
, selected_window
)
8462 /* For click-to-focus window managers
8463 create event iff we don't leave the
8465 && (focus_follows_mouse
8466 || (EQ (XWINDOW (window
)->frame
,
8467 XWINDOW (selected_window
)->frame
))))
8469 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
8470 inev
.ie
.frame_or_window
= window
;
8472 /* Remember the last window where we saw the mouse. */
8473 last_mouse_window
= window
;
8475 if (!note_mouse_movement (f
, &event
->xmotion
))
8476 help_echo_string
= previous_help_echo_string
;
8480 #ifndef USE_TOOLKIT_SCROLL_BARS
8481 struct scroll_bar
*bar
8482 = x_window_to_scroll_bar (event
->xmotion
.display
,
8483 event
->xmotion
.window
, 2);
8486 x_scroll_bar_note_movement (bar
, &event
->xmotion
);
8487 #endif /* USE_TOOLKIT_SCROLL_BARS */
8489 /* If we move outside the frame, then we're
8490 certainly no longer on any text in the frame. */
8491 clear_mouse_face (hlinfo
);
8494 /* If the contents of the global variable help_echo_string
8495 has changed, generate a HELP_EVENT. */
8496 if (!NILP (help_echo_string
)
8497 || !NILP (previous_help_echo_string
))
8502 case ConfigureNotify
:
8503 /* An opaque move can generate a stream of events as the window
8504 is dragged around. If the connection round trip time isn't
8505 really short, they may come faster than we can respond to
8506 them, given the multiple queries we can do to check window
8507 manager state, translate coordinates, etc.
8509 So if this ConfigureNotify is immediately followed by another
8510 for the same window, use the info from the latest update, and
8511 consider the events all handled. */
8512 /* Opaque resize may be trickier; ConfigureNotify events are
8513 mixed with Expose events for multiple windows. */
8514 configureEvent
= *event
;
8515 while (XPending (dpyinfo
->display
))
8517 XNextEvent (dpyinfo
->display
, &next_event
);
8518 if (next_event
.type
!= ConfigureNotify
8519 || next_event
.xconfigure
.window
!= event
->xconfigure
.window
8520 /* Skipping events with different sizes can lead to a
8521 mispositioned mode line at initial window creation.
8522 Only drop window motion events for now. */
8523 || next_event
.xconfigure
.width
!= event
->xconfigure
.width
8524 || next_event
.xconfigure
.height
!= event
->xconfigure
.height
)
8526 XPutBackEvent (dpyinfo
->display
, &next_event
);
8530 configureEvent
= next_event
;
8533 f
= x_top_window_to_frame (dpyinfo
, configureEvent
.xconfigure
.window
);
8534 /* Unfortunately, we need to call font_drop_xrender_surfaces for
8535 _all_ ConfigureNotify events, otherwise we miss some and
8536 flicker. Don't try to optimize these calls by looking only
8537 for size changes: that's not sufficient. We miss some
8538 surface invalidations and flicker. */
8540 if (f
&& FRAME_X_DOUBLE_BUFFERED_P (f
))
8541 font_drop_xrender_surfaces (f
);
8544 if (f
) x_cr_destroy_surface (f
);
8549 && configureEvent
.xconfigure
.window
== FRAME_X_WINDOW (f
))
8552 if (FRAME_X_DOUBLE_BUFFERED_P (f
))
8553 font_drop_xrender_surfaces (f
);
8555 xg_frame_resized (f
, configureEvent
.xconfigure
.width
,
8556 configureEvent
.xconfigure
.height
);
8558 x_cr_destroy_surface (f
);
8565 /* Don't call x_net_wm_state for the scroll bar window.
8566 (Bug#24963, Bug#25887) */
8567 if (configureEvent
.xconfigure
.window
== FRAME_X_WINDOW (f
))
8568 x_net_wm_state (f
, configureEvent
.xconfigure
.window
);
8570 #ifdef USE_X_TOOLKIT
8571 /* Tip frames are pure X window, set size for them. */
8572 if (! NILP (tip_frame
) && XFRAME (tip_frame
) == f
)
8574 if (FRAME_PIXEL_HEIGHT (f
) != configureEvent
.xconfigure
.height
8575 || FRAME_PIXEL_WIDTH (f
) != configureEvent
.xconfigure
.width
)
8577 SET_FRAME_GARBAGED (f
);
8579 FRAME_PIXEL_HEIGHT (f
) = configureEvent
.xconfigure
.height
;
8580 FRAME_PIXEL_WIDTH (f
) = configureEvent
.xconfigure
.width
;
8584 #ifndef USE_X_TOOLKIT
8587 FRAME_PIXEL_TO_TEXT_WIDTH (f
, configureEvent
.xconfigure
.width
);
8589 FRAME_PIXEL_TO_TEXT_HEIGHT (f
, configureEvent
.xconfigure
.height
);
8591 /* In the toolkit version, change_frame_size
8592 is called by the code that handles resizing
8593 of the EmacsFrame widget. */
8595 /* Even if the number of character rows and columns has
8596 not changed, the font size may have changed, so we need
8597 to check the pixel dimensions as well. */
8598 if (width
!= FRAME_TEXT_WIDTH (f
)
8599 || height
!= FRAME_TEXT_HEIGHT (f
)
8600 || configureEvent
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
8601 || configureEvent
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
8603 change_frame_size (f
, width
, height
, false, true, false, true);
8604 x_clear_under_internal_border (f
);
8605 SET_FRAME_GARBAGED (f
);
8606 cancel_mouse_face (f
);
8608 #endif /* not USE_GTK */
8612 /* GTK creates windows but doesn't map them.
8613 Only get real positions when mapped. */
8614 if (FRAME_GTK_OUTER_WIDGET (f
)
8615 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
8617 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8620 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
8621 xic_set_statusarea (f
);
8630 /* If we decide we want to generate an event to be seen
8631 by the rest of Emacs, we put it here. */
8632 bool tool_bar_p
= false;
8634 memset (&compose_status
, 0, sizeof (compose_status
));
8635 dpyinfo
->last_mouse_glyph_frame
= NULL
;
8636 x_display_set_last_user_time (dpyinfo
, event
->xbutton
.time
);
8638 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
8639 : x_window_to_frame (dpyinfo
, event
->xbutton
.window
));
8642 if (f
&& xg_event_is_for_scrollbar (f
, event
))
8647 #if ! defined (USE_GTK)
8648 /* Is this in the tool-bar? */
8649 if (WINDOWP (f
->tool_bar_window
)
8650 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
8653 int x
= event
->xbutton
.x
;
8654 int y
= event
->xbutton
.y
;
8656 window
= window_from_coordinates (f
, x
, y
, 0, true);
8657 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
8659 if (tool_bar_p
&& event
->xbutton
.button
< 4)
8660 handle_tool_bar_click
8661 (f
, x
, y
, event
->xbutton
.type
== ButtonPress
,
8662 x_x_to_emacs_modifiers (dpyinfo
, event
->xbutton
.state
));
8664 #endif /* !USE_GTK */
8667 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8668 if (! popup_activated ())
8671 if (ignore_next_mouse_click_timeout
)
8673 if (event
->type
== ButtonPress
8674 && event
->xbutton
.time
> ignore_next_mouse_click_timeout
)
8676 ignore_next_mouse_click_timeout
= 0;
8677 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
8679 if (event
->type
== ButtonRelease
)
8680 ignore_next_mouse_click_timeout
= 0;
8683 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
8685 if (FRAME_X_EMBEDDED_P (f
))
8686 xembed_send_message (f
, event
->xbutton
.time
,
8687 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
8691 struct scroll_bar
*bar
8692 = x_window_to_scroll_bar (event
->xbutton
.display
,
8693 event
->xbutton
.window
, 2);
8695 #ifdef USE_TOOLKIT_SCROLL_BARS
8696 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
8698 if (bar
&& event
->xbutton
.state
& ControlMask
)
8700 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
8701 *finish
= X_EVENT_DROP
;
8703 #else /* not USE_TOOLKIT_SCROLL_BARS */
8705 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
8706 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8709 if (event
->type
== ButtonPress
)
8711 dpyinfo
->grabbed
|= (1 << event
->xbutton
.button
);
8712 dpyinfo
->last_mouse_frame
= f
;
8713 #if ! defined (USE_GTK)
8714 if (f
&& !tool_bar_p
)
8715 f
->last_tool_bar_item
= -1;
8716 #endif /* not USE_GTK */
8719 dpyinfo
->grabbed
&= ~(1 << event
->xbutton
.button
);
8721 /* Ignore any mouse motion that happened before this event;
8722 any subsequent mouse-movement Emacs events should reflect
8723 only motion after the ButtonPress/Release. */
8725 f
->mouse_moved
= false;
8727 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8728 f
= x_menubar_window_to_frame (dpyinfo
, event
);
8729 /* For a down-event in the menu bar,
8730 don't pass it to Xt right now.
8731 Instead, save it away
8732 and we will pass it to Xt from kbd_buffer_get_event.
8733 That way, we can run some Lisp code first. */
8734 if (! popup_activated ()
8736 /* Gtk+ menus only react to the first three buttons. */
8737 && event
->xbutton
.button
< 3
8739 && f
&& event
->type
== ButtonPress
8740 /* Verify the event is really within the menu bar
8741 and not just sent to it due to grabbing. */
8742 && event
->xbutton
.x
>= 0
8743 && event
->xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
8744 && event
->xbutton
.y
>= 0
8745 && event
->xbutton
.y
< FRAME_MENUBAR_HEIGHT (f
)
8746 && event
->xbutton
.same_screen
)
8748 if (!f
->output_data
.x
->saved_menu_event
)
8749 f
->output_data
.x
->saved_menu_event
= xmalloc (sizeof *event
);
8750 *f
->output_data
.x
->saved_menu_event
= *event
;
8751 inev
.ie
.kind
= MENU_BAR_ACTIVATE_EVENT
;
8752 XSETFRAME (inev
.ie
.frame_or_window
, f
);
8753 *finish
= X_EVENT_DROP
;
8757 #endif /* USE_X_TOOLKIT || USE_GTK */
8761 case CirculateNotify
:
8764 case CirculateRequest
:
8767 case VisibilityNotify
:
8771 /* Someone has changed the keyboard mapping - update the
8773 switch (event
->xmapping
.request
)
8775 case MappingModifier
:
8776 x_find_modifier_meanings (dpyinfo
);
8777 /* This is meant to fall through. */
8778 case MappingKeyboard
:
8779 XRefreshKeyboardMapping ((XMappingEvent
*) &event
->xmapping
);
8784 xft_settings_event (dpyinfo
, event
);
8789 #ifdef USE_X_TOOLKIT
8791 if (*finish
!= X_EVENT_DROP
)
8792 XtDispatchEvent ((XEvent
*) event
);
8794 #endif /* USE_X_TOOLKIT */
8799 if (inev
.ie
.kind
!= NO_EVENT
)
8801 kbd_buffer_store_buffered_event (&inev
, hold_quit
);
8806 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
8811 XSETFRAME (frame
, f
);
8817 any_help_event_p
= true;
8818 gen_help_event (help_echo_string
, frame
, help_echo_window
,
8819 help_echo_object
, help_echo_pos
);
8823 help_echo_string
= Qnil
;
8824 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
8829 /* Sometimes event processing draws to the frame outside redisplay.
8830 To ensure that these changes become visible, draw them here. */
8831 flush_dirty_back_buffers ();
8836 /* Handles the XEvent EVENT on display DISPLAY.
8837 This is used for event loops outside the normal event handling,
8838 i.e. looping while a popup menu or a dialog is posted.
8840 Returns the value handle_one_xevent sets in the finish argument. */
8842 x_dispatch_event (XEvent
*event
, Display
*display
)
8844 struct x_display_info
*dpyinfo
;
8845 int finish
= X_EVENT_NORMAL
;
8847 dpyinfo
= x_display_info_for_display (display
);
8850 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
8855 /* Read events coming from the X server.
8856 Return as soon as there are no more events to be read.
8858 Return the number of characters stored into the buffer,
8859 thus pretending to be `read' (except the characters we store
8860 in the keyboard buffer can be multibyte, so are not necessarily
8864 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
8867 bool event_found
= false;
8868 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
8872 /* For debugging, this gives a way to fake an I/O error. */
8873 if (dpyinfo
== XTread_socket_fake_io_error
)
8875 XTread_socket_fake_io_error
= 0;
8876 x_io_error_quitter (dpyinfo
->display
);
8880 while (XPending (dpyinfo
->display
))
8885 XNextEvent (dpyinfo
->display
, &event
);
8888 /* Filter events for the current X input method. */
8889 if (x_filter_event (dpyinfo
, &event
))
8894 count
+= handle_one_xevent (dpyinfo
, &event
, &finish
, hold_quit
);
8896 if (finish
== X_EVENT_GOTO_OUT
)
8902 /* For GTK we must use the GTK event loop. But XEvents gets passed
8903 to our filter function above, and then to the big event switch.
8904 We use a bunch of globals to communicate with our filter function,
8905 that is kind of ugly, but it works.
8907 There is no way to do one display at the time, GTK just does events
8908 from all displays. */
8910 while (gtk_events_pending ())
8912 current_count
= count
;
8913 current_hold_quit
= hold_quit
;
8915 gtk_main_iteration ();
8917 count
= current_count
;
8919 current_hold_quit
= 0;
8921 if (current_finish
== X_EVENT_GOTO_OUT
)
8924 #endif /* USE_GTK */
8926 /* On some systems, an X bug causes Emacs to get no more events
8927 when the window is destroyed. Detect that. (1994.) */
8930 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
8931 One XNOOP in 100 loops will make Emacs terminate.
8932 B. Bretthauer, 1994 */
8934 if (x_noop_count
>= 100)
8938 if (next_noop_dpyinfo
== 0)
8939 next_noop_dpyinfo
= x_display_list
;
8941 XNoOp (next_noop_dpyinfo
->display
);
8943 /* Each time we get here, cycle through the displays now open. */
8944 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
8948 /* If the focus was just given to an auto-raising frame,
8949 raise it now. FIXME: handle more than one such frame. */
8950 if (dpyinfo
->x_pending_autoraise_frame
)
8952 x_raise_frame (dpyinfo
->x_pending_autoraise_frame
);
8953 dpyinfo
->x_pending_autoraise_frame
= NULL
;
8964 /***********************************************************************
8966 ***********************************************************************/
8968 /* Set clipping for output in glyph row ROW. W is the window in which
8969 we operate. GC is the graphics context to set clipping in.
8971 ROW may be a text row or, e.g., a mode line. Text rows must be
8972 clipped to the interior of the window dedicated to text display,
8973 mode lines must be clipped to the whole window. */
8976 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
8977 enum glyph_row_area area
, GC gc
)
8979 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8980 XRectangle clip_rect
;
8981 int window_x
, window_y
, window_width
;
8983 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
8985 clip_rect
.x
= window_x
;
8986 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
8987 clip_rect
.y
= max (clip_rect
.y
, window_y
);
8988 clip_rect
.width
= window_width
;
8989 clip_rect
.height
= row
->visible_height
;
8991 x_set_clip_rectangles (f
, gc
, &clip_rect
, 1);
8995 /* Draw a hollow box cursor on window W in glyph row ROW. */
8998 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
9000 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9001 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9002 Display
*dpy
= FRAME_X_DISPLAY (f
);
9005 struct glyph
*cursor_glyph
;
9008 /* Get the glyph the cursor is on. If we can't tell because
9009 the current matrix is invalid or such, give up. */
9010 cursor_glyph
= get_phys_cursor_glyph (w
);
9011 if (cursor_glyph
== NULL
)
9014 /* Compute frame-relative coordinates for phys cursor. */
9015 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
9016 wd
= w
->phys_cursor_width
- 1;
9018 /* The foreground of cursor_gc is typically the same as the normal
9019 background color, which can cause the cursor box to be invisible. */
9020 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9021 if (dpyinfo
->scratch_cursor_gc
)
9022 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
9024 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_DRAWABLE (f
),
9025 GCForeground
, &xgcv
);
9026 gc
= dpyinfo
->scratch_cursor_gc
;
9028 /* When on R2L character, show cursor at the right edge of the
9029 glyph, unless the cursor box is as wide as the glyph or wider
9030 (the latter happens when x-stretch-cursor is non-nil). */
9031 if ((cursor_glyph
->resolved_level
& 1) != 0
9032 && cursor_glyph
->pixel_width
> wd
)
9034 x
+= cursor_glyph
->pixel_width
- wd
;
9038 /* Set clipping, draw the rectangle, and reset clipping again. */
9039 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
9040 x_draw_rectangle (f
, gc
, x
, y
, wd
, h
- 1);
9041 x_reset_clip_rectangles (f
, gc
);
9045 /* Draw a bar cursor on window W in glyph row ROW.
9047 Implementation note: One would like to draw a bar cursor with an
9048 angle equal to the one given by the font property XA_ITALIC_ANGLE.
9049 Unfortunately, I didn't find a font yet that has this property set.
9053 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
9055 struct frame
*f
= XFRAME (w
->frame
);
9056 struct glyph
*cursor_glyph
;
9058 /* If cursor is out of bounds, don't draw garbage. This can happen
9059 in mini-buffer windows when switching between echo area glyphs
9061 cursor_glyph
= get_phys_cursor_glyph (w
);
9062 if (cursor_glyph
== NULL
)
9065 /* Experimental avoidance of cursor on xwidget. */
9066 if (cursor_glyph
->type
== XWIDGET_GLYPH
)
9069 /* If on an image, draw like a normal cursor. That's usually better
9070 visible than drawing a bar, esp. if the image is large so that
9071 the bar might not be in the window. */
9072 if (cursor_glyph
->type
== IMAGE_GLYPH
)
9074 struct glyph_row
*r
;
9075 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
9076 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
9080 Display
*dpy
= FRAME_X_DISPLAY (f
);
9081 Drawable drawable
= FRAME_X_DRAWABLE (f
);
9082 GC gc
= FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
;
9083 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
9084 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
9087 /* If the glyph's background equals the color we normally draw
9088 the bars cursor in, the bar cursor in its normal color is
9089 invisible. Use the glyph's foreground color instead in this
9090 case, on the assumption that the glyph's colors are chosen so
9091 that the glyph is legible. */
9092 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
9093 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
9095 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
9096 xgcv
.graphics_exposures
= False
;
9099 XChangeGC (dpy
, gc
, mask
, &xgcv
);
9102 gc
= XCreateGC (dpy
, drawable
, mask
, &xgcv
);
9103 FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
9106 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
9108 if (kind
== BAR_CURSOR
)
9110 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9113 width
= FRAME_CURSOR_WIDTH (f
);
9114 width
= min (cursor_glyph
->pixel_width
, width
);
9116 w
->phys_cursor_width
= width
;
9118 /* If the character under cursor is R2L, draw the bar cursor
9119 on the right of its glyph, rather than on the left. */
9120 if ((cursor_glyph
->resolved_level
& 1) != 0)
9121 x
+= cursor_glyph
->pixel_width
- width
;
9123 x_fill_rectangle (f
, gc
, x
,
9124 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
9125 width
, row
->height
);
9127 else /* HBAR_CURSOR */
9129 int dummy_x
, dummy_y
, dummy_h
;
9130 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9133 width
= row
->height
;
9135 width
= min (row
->height
, width
);
9137 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
9138 &dummy_y
, &dummy_h
);
9140 if ((cursor_glyph
->resolved_level
& 1) != 0
9141 && cursor_glyph
->pixel_width
> w
->phys_cursor_width
- 1)
9142 x
+= cursor_glyph
->pixel_width
- w
->phys_cursor_width
+ 1;
9143 x_fill_rectangle (f
, gc
, x
,
9144 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
9145 row
->height
- width
),
9146 w
->phys_cursor_width
- 1, width
);
9149 x_reset_clip_rectangles (f
, gc
);
9154 /* RIF: Define cursor CURSOR on frame F. */
9157 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
9159 if (!f
->pointer_invisible
9160 && f
->output_data
.x
->current_cursor
!= cursor
)
9161 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
9162 f
->output_data
.x
->current_cursor
= cursor
;
9166 /* RIF: Clear area on frame F. */
9169 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
9171 x_clear_area (f
, x
, y
, width
, height
);
9175 /* RIF: Draw cursor on window W. */
9178 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
9179 int y
, enum text_cursor_kinds cursor_type
,
9180 int cursor_width
, bool on_p
, bool active_p
)
9182 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9186 w
->phys_cursor_type
= cursor_type
;
9187 w
->phys_cursor_on_p
= true;
9189 if (glyph_row
->exact_window_width_line_p
9190 && (glyph_row
->reversed_p
9191 ? (w
->phys_cursor
.hpos
< 0)
9192 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
9194 glyph_row
->cursor_in_fringe_p
= true;
9195 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
9199 switch (cursor_type
)
9201 case HOLLOW_BOX_CURSOR
:
9202 x_draw_hollow_cursor (w
, glyph_row
);
9205 case FILLED_BOX_CURSOR
:
9206 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9210 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
9214 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
9218 w
->phys_cursor_width
= 0;
9227 if (w
== XWINDOW (f
->selected_window
))
9228 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
9229 xic_set_preeditarea (w
, x
, y
);
9233 XFlush (FRAME_X_DISPLAY (f
));
9239 /* Make the x-window of frame F use the gnu icon bitmap. */
9242 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
9244 ptrdiff_t bitmap_id
;
9246 if (FRAME_X_WINDOW (f
) == 0)
9249 /* Free up our existing icon bitmap and mask if any. */
9250 if (f
->output_data
.x
->icon_bitmap
> 0)
9251 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
9252 f
->output_data
.x
->icon_bitmap
= 0;
9257 /* Use gtk_window_set_icon_from_file () if available,
9258 It's not restricted to bitmaps */
9259 if (xg_set_icon (f
, file
))
9261 #endif /* USE_GTK */
9262 bitmap_id
= x_create_bitmap_from_file (f
, file
);
9263 x_create_bitmap_mask (f
, bitmap_id
);
9267 /* Create the GNU bitmap and mask if necessary. */
9268 if (FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
9274 if (xg_set_icon (f
, xg_default_icon_file
)
9275 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
9277 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= -2;
9281 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
9283 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
9285 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
9289 /* If all else fails, use the (black and white) xbm image. */
9292 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
9293 gnu_xbm_width
, gnu_xbm_height
);
9297 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
9298 x_create_bitmap_mask (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
9302 /* The first time we create the GNU bitmap and mask,
9303 this increments the ref-count one extra time.
9304 As a result, the GNU bitmap and mask are never freed.
9305 That way, we don't have to worry about allocating it again. */
9306 x_reference_bitmap (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
9308 bitmap_id
= FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
;
9311 x_wm_set_icon_pixmap (f
, bitmap_id
);
9312 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
9318 /* Make the x-window of frame F use a rectangle with text.
9319 Use ICON_NAME as the text. */
9322 x_text_icon (struct frame
*f
, const char *icon_name
)
9324 if (FRAME_X_WINDOW (f
) == 0)
9329 text
.value
= (unsigned char *) icon_name
;
9330 text
.encoding
= XA_STRING
;
9332 text
.nitems
= strlen (icon_name
);
9333 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
9336 if (f
->output_data
.x
->icon_bitmap
> 0)
9337 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
9338 f
->output_data
.x
->icon_bitmap
= 0;
9339 x_wm_set_icon_pixmap (f
, 0);
9344 #define X_ERROR_MESSAGE_SIZE 200
9346 /* If non-nil, this should be a string.
9347 It means catch X errors and store the error message in this string.
9349 The reason we use a stack is that x_catch_error/x_uncatch_error can
9350 be called from a signal handler.
9353 struct x_error_message_stack
{
9354 char string
[X_ERROR_MESSAGE_SIZE
];
9356 x_special_error_handler handler
;
9358 struct x_error_message_stack
*prev
;
9360 static struct x_error_message_stack
*x_error_message
;
9362 /* An X error handler which stores the error message in
9363 *x_error_message. This is called from x_error_handler if
9364 x_catch_errors is in effect. */
9367 x_error_catcher (Display
*display
, XErrorEvent
*event
)
9369 XGetErrorText (display
, event
->error_code
,
9370 x_error_message
->string
,
9371 X_ERROR_MESSAGE_SIZE
);
9372 if (x_error_message
->handler
)
9373 x_error_message
->handler (display
, event
, x_error_message
->string
,
9374 x_error_message
->handler_data
);
9377 /* Begin trapping X errors for display DPY. Actually we trap X errors
9378 for all displays, but DPY should be the display you are actually
9381 After calling this function, X protocol errors no longer cause
9382 Emacs to exit; instead, they are recorded in the string
9383 stored in *x_error_message.
9385 Calling x_check_errors signals an Emacs error if an X error has
9386 occurred since the last call to x_catch_errors or x_check_errors.
9388 Calling x_uncatch_errors resumes the normal error handling.
9389 Calling x_uncatch_errors_after_check is similar, but skips an XSync
9390 to the server, and should be used only immediately after
9391 x_had_errors_p or x_check_errors. */
9394 x_catch_errors_with_handler (Display
*dpy
, x_special_error_handler handler
,
9397 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
9399 /* Make sure any errors from previous requests have been dealt with. */
9403 data
->string
[0] = 0;
9404 data
->handler
= handler
;
9405 data
->handler_data
= handler_data
;
9406 data
->prev
= x_error_message
;
9407 x_error_message
= data
;
9411 x_catch_errors (Display
*dpy
)
9413 x_catch_errors_with_handler (dpy
, NULL
, NULL
);
9416 /* Undo the last x_catch_errors call.
9417 DPY should be the display that was passed to x_catch_errors.
9419 This version should be used only if the immediately preceding
9420 X-protocol-related thing was x_check_errors or x_had_error_p, both
9421 of which issue XSync calls, so we don't need to re-sync here. */
9424 x_uncatch_errors_after_check (void)
9426 struct x_error_message_stack
*tmp
;
9429 tmp
= x_error_message
;
9430 x_error_message
= x_error_message
->prev
;
9435 /* Undo the last x_catch_errors call.
9436 DPY should be the display that was passed to x_catch_errors. */
9439 x_uncatch_errors (void)
9441 struct x_error_message_stack
*tmp
;
9445 /* The display may have been closed before this function is called.
9446 Check if it is still open before calling XSync. */
9447 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
9448 XSync (x_error_message
->dpy
, False
);
9450 tmp
= x_error_message
;
9451 x_error_message
= x_error_message
->prev
;
9456 /* If any X protocol errors have arrived since the last call to
9457 x_catch_errors or x_check_errors, signal an Emacs error using
9458 sprintf (a buffer, FORMAT, the x error message text) as the text. */
9461 x_check_errors (Display
*dpy
, const char *format
)
9463 /* Make sure to catch any errors incurred so far. */
9466 if (x_error_message
->string
[0])
9468 char string
[X_ERROR_MESSAGE_SIZE
];
9469 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
9470 x_uncatch_errors ();
9471 error (format
, string
);
9475 /* Nonzero if we had any X protocol errors
9476 since we did x_catch_errors on DPY. */
9479 x_had_errors_p (Display
*dpy
)
9481 /* Make sure to catch any errors incurred so far. */
9484 return x_error_message
->string
[0] != 0;
9487 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
9490 x_clear_errors (Display
*dpy
)
9492 x_error_message
->string
[0] = 0;
9496 /* See comment in unwind_to_catch why calling this is a bad
9497 * idea. --lorentey */
9498 /* Close off all unclosed x_catch_errors calls. */
9501 x_fully_uncatch_errors (void)
9503 while (x_error_message
)
9504 x_uncatch_errors ();
9509 static unsigned int x_wire_count
;
9512 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
9517 /************************************************************************
9519 ************************************************************************/
9521 /* Error message passed to x_connection_closed. */
9523 static char *error_msg
;
9525 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
9526 the text of an error message that lead to the connection loss. */
9528 static _Noreturn
void
9529 x_connection_closed (Display
*dpy
, const char *error_message
, bool ioerror
)
9531 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
9532 Lisp_Object frame
, tail
;
9533 ptrdiff_t idx
= SPECPDL_INDEX ();
9535 error_msg
= alloca (strlen (error_message
) + 1);
9536 strcpy (error_msg
, error_message
);
9538 /* Inhibit redisplay while frames are being deleted. */
9539 specbind (Qinhibit_redisplay
, Qt
);
9543 /* Protect display from being closed when we delete the last
9545 dpyinfo
->reference_count
++;
9546 dpyinfo
->terminal
->reference_count
++;
9548 if (ioerror
) dpyinfo
->display
= 0;
9550 /* First delete frames whose mini-buffers are on frames
9551 that are on the dead display. */
9552 FOR_EACH_FRAME (tail
, frame
)
9554 Lisp_Object minibuf_frame
;
9556 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
9557 if (FRAME_X_P (XFRAME (frame
))
9558 && FRAME_X_P (XFRAME (minibuf_frame
))
9559 && ! EQ (frame
, minibuf_frame
)
9560 && FRAME_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
9561 delete_frame (frame
, Qnoelisp
);
9564 /* Now delete all remaining frames on the dead display.
9565 We are now sure none of these is used as the mini-buffer
9566 for another frame that we need to delete. */
9567 FOR_EACH_FRAME (tail
, frame
)
9568 if (FRAME_X_P (XFRAME (frame
))
9569 && FRAME_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
9571 /* Set this to t so that delete_frame won't get confused
9572 trying to find a replacement. */
9573 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
9574 delete_frame (frame
, Qnoelisp
);
9577 /* If DPYINFO is null, this means we didn't open the display in the
9578 first place, so don't try to close it. */
9581 /* We can not call XtCloseDisplay here because it calls XSync.
9582 XSync inside the error handler apparently hangs Emacs. On
9583 current Xt versions, this isn't needed either. */
9585 /* A long-standing GTK bug prevents proper disconnect handling
9586 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
9587 the resulting Glib error message loop filled a user's disk.
9588 To avoid this, kill Emacs unconditionally on disconnect. */
9589 shut_down_emacs (0, Qnil
);
9590 fprintf (stderr
, "%s\n\
9591 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
9592 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
9593 For details, see etc/PROBLEMS.\n",
9596 #endif /* USE_GTK */
9598 /* Indicate that this display is dead. */
9599 dpyinfo
->display
= 0;
9601 dpyinfo
->reference_count
--;
9602 dpyinfo
->terminal
->reference_count
--;
9603 if (dpyinfo
->reference_count
!= 0)
9604 /* We have just closed all frames on this display. */
9609 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
9610 Fdelete_terminal (tmp
, Qnoelisp
);
9614 if (terminal_list
== 0)
9616 fprintf (stderr
, "%s\n", error_msg
);
9617 Fkill_emacs (make_number (70));
9621 totally_unblock_input ();
9623 unbind_to (idx
, Qnil
);
9624 clear_waiting_for_input ();
9626 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
9627 longjmp), because returning from this function would get us back into
9628 Xlib's code which will directly call `exit'. */
9629 error ("%s", error_msg
);
9632 /* We specifically use it before defining it, so that gcc doesn't inline it,
9633 otherwise gdb doesn't know how to properly put a breakpoint on it. */
9634 static void x_error_quitter (Display
*, XErrorEvent
*);
9636 /* This is the first-level handler for X protocol errors.
9637 It calls x_error_quitter or x_error_catcher. */
9640 x_error_handler (Display
*display
, XErrorEvent
*event
)
9642 #if defined USE_GTK && defined HAVE_GTK3
9643 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
9644 && event
->request_code
== X_SetInputFocus
)
9650 if (x_error_message
)
9651 x_error_catcher (display
, event
);
9653 x_error_quitter (display
, event
);
9657 /* This is the usual handler for X protocol errors.
9658 It kills all frames on the display that we got the error for.
9659 If that was the only one, it prints an error message and kills Emacs. */
9661 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
9663 /* On older GCC versions, just putting x_error_quitter
9664 after x_error_handler prevents inlining into the former. */
9666 static void NO_INLINE
9667 x_error_quitter (Display
*display
, XErrorEvent
*event
)
9669 char buf
[256], buf1
[356];
9671 /* Ignore BadName errors. They can happen because of fonts
9672 or colors that are not defined. */
9674 if (event
->error_code
== BadName
)
9677 /* Note that there is no real way portable across R3/R4 to get the
9678 original error handler. */
9680 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
9681 sprintf (buf1
, "X protocol error: %s on protocol request %d",
9682 buf
, event
->request_code
);
9683 x_connection_closed (display
, buf1
, false);
9687 /* This is the handler for X IO errors, always.
9688 It kills all frames on the display that we lost touch with.
9689 If that was the only one, it prints an error message and kills Emacs. */
9691 static _Noreturn
int
9692 x_io_error_quitter (Display
*display
)
9696 snprintf (buf
, sizeof buf
, "Connection lost to X server '%s'",
9697 DisplayString (display
));
9698 x_connection_closed (display
, buf
, true);
9702 /* Changing the font of the frame. */
9704 /* Give frame F the font FONT-OBJECT as its default font. The return
9705 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
9706 frame. If it is negative, generate a new fontset from
9710 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
9712 struct font
*font
= XFONT_OBJECT (font_object
);
9713 int unit
, font_ascent
, font_descent
;
9714 #ifndef USE_X_TOOLKIT
9715 int old_menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
9716 Lisp_Object fullscreen
;
9720 fontset
= fontset_from_font (font_object
);
9721 FRAME_FONTSET (f
) = fontset
;
9722 if (FRAME_FONT (f
) == font
)
9723 /* This font is already set in frame F. There's nothing more to
9727 FRAME_FONT (f
) = font
;
9728 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
9729 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
9730 get_font_ascent_descent (font
, &font_ascent
, &font_descent
);
9731 FRAME_LINE_HEIGHT (f
) = font_ascent
+ font_descent
;
9733 #ifndef USE_X_TOOLKIT
9734 FRAME_MENU_BAR_HEIGHT (f
) = FRAME_MENU_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
);
9737 /* Compute character columns occupied by scrollbar.
9739 Don't do things differently for non-toolkit scrollbars
9741 unit
= FRAME_COLUMN_WIDTH (f
);
9742 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
9743 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
9744 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
9746 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
9748 if (FRAME_X_WINDOW (f
) != 0)
9750 /* Don't change the size of a tip frame; there's no point in
9751 doing it because it's done in Fx_show_tip, and it leads to
9752 problems because the tip frame has no widget. */
9753 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9755 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
9756 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 3,
9758 #ifndef USE_X_TOOLKIT
9759 if (FRAME_MENU_BAR_HEIGHT (f
) != old_menu_bar_height
9760 && !f
->after_make_frame
9761 && (EQ (frame_inhibit_implied_resize
, Qt
)
9762 || (CONSP (frame_inhibit_implied_resize
)
9763 && NILP (Fmemq (Qfont
, frame_inhibit_implied_resize
))))
9764 && (NILP (fullscreen
= get_frame_param (f
, Qfullscreen
))
9765 || EQ (fullscreen
, Qfullwidth
)))
9766 /* If the menu bar height changes, try to keep text height
9769 (f
, -1, FRAME_TEXT_HEIGHT (f
) + FRAME_MENU_BAR_HEIGHT (f
)
9770 - old_menu_bar_height
, 1, false, Qfont
);
9771 #endif /* USE_X_TOOLKIT */
9777 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
9780 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
9789 /***********************************************************************
9791 ***********************************************************************/
9797 /* XIM destroy callback function, which is called whenever the
9798 connection to input method XIM dies. CLIENT_DATA contains a
9799 pointer to the x_display_info structure corresponding to XIM. */
9802 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
9804 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
9805 Lisp_Object frame
, tail
;
9809 /* No need to call XDestroyIC.. */
9810 FOR_EACH_FRAME (tail
, frame
)
9812 struct frame
*f
= XFRAME (frame
);
9813 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
9815 FRAME_XIC (f
) = NULL
;
9816 xic_free_xfontset (f
);
9820 /* No need to call XCloseIM. */
9821 dpyinfo
->xim
= NULL
;
9822 XFree (dpyinfo
->xim_styles
);
9826 #endif /* HAVE_X11R6 */
9828 /* Open the connection to the XIM server on display DPYINFO.
9829 RESOURCE_NAME is the resource name Emacs uses. */
9832 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
9840 XCloseIM (dpyinfo
->xim
);
9841 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
9848 XIMCallback destroy
;
9851 /* Get supported styles and XIM values. */
9852 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
9855 destroy
.callback
= xim_destroy_callback
;
9856 destroy
.client_data
= (XPointer
)dpyinfo
;
9857 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
9863 #endif /* HAVE_XIM */
9864 dpyinfo
->xim
= NULL
;
9868 #ifdef HAVE_X11R6_XIM
9870 /* XIM instantiate callback function, which is called whenever an XIM
9871 server is available. DISPLAY is the display of the XIM.
9872 CLIENT_DATA contains a pointer to an xim_inst_t structure created
9873 when the callback was registered. */
9876 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
9878 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
9879 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
9881 /* We don't support multiple XIM connections. */
9885 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
9887 /* Create XIC for the existing frames on the same display, as long
9888 as they have no XIC. */
9889 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
9891 Lisp_Object tail
, frame
;
9894 FOR_EACH_FRAME (tail
, frame
)
9896 struct frame
*f
= XFRAME (frame
);
9899 && FRAME_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
9900 if (FRAME_XIC (f
) == NULL
)
9902 create_frame_xic (f
);
9903 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
9904 xic_set_statusarea (f
);
9905 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
9907 struct window
*w
= XWINDOW (f
->selected_window
);
9908 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
9917 #endif /* HAVE_X11R6_XIM */
9920 /* Open a connection to the XIM server on display DPYINFO.
9921 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
9922 connection only at the first time. On X11R6, open the connection
9923 in the XIM instantiate callback function. */
9926 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
9928 dpyinfo
->xim
= NULL
;
9932 #ifdef HAVE_X11R6_XIM
9933 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
9936 dpyinfo
->xim_callback_data
= xim_inst
;
9937 xim_inst
->dpyinfo
= dpyinfo
;
9938 xim_inst
->resource_name
= xstrdup (resource_name
);
9939 ret
= XRegisterIMInstantiateCallback
9940 (dpyinfo
->display
, dpyinfo
->xrdb
, xim_inst
->resource_name
,
9941 emacs_class
, xim_instantiate_callback
,
9942 /* This is XPointer in XFree86 but (XPointer *)
9943 on Tru64, at least, hence the configure test. */
9944 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
9945 eassert (ret
== True
);
9946 #else /* not HAVE_X11R6_XIM */
9947 xim_open_dpy (dpyinfo
, resource_name
);
9948 #endif /* not HAVE_X11R6_XIM */
9950 #endif /* HAVE_XIM */
9954 /* Close the connection to the XIM server on display DPYINFO. */
9957 xim_close_dpy (struct x_display_info
*dpyinfo
)
9962 #ifdef HAVE_X11R6_XIM
9963 struct xim_inst_t
*xim_inst
= dpyinfo
->xim_callback_data
;
9965 if (dpyinfo
->display
)
9967 Bool ret
= XUnregisterIMInstantiateCallback
9968 (dpyinfo
->display
, dpyinfo
->xrdb
, xim_inst
->resource_name
,
9969 emacs_class
, xim_instantiate_callback
,
9970 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
9971 eassert (ret
== True
);
9973 xfree (xim_inst
->resource_name
);
9975 #endif /* HAVE_X11R6_XIM */
9976 if (dpyinfo
->display
)
9977 XCloseIM (dpyinfo
->xim
);
9978 dpyinfo
->xim
= NULL
;
9979 XFree (dpyinfo
->xim_styles
);
9981 #endif /* HAVE_XIM */
9984 #endif /* not HAVE_X11R6_XIM */
9988 /* Calculate the absolute position in frame F
9989 from its current recorded position values and gravity. */
9992 x_calc_absolute_position (struct frame
*f
)
9994 int flags
= f
->size_hint_flags
;
9996 /* We have nothing to do if the current position
9997 is already for the top-left corner. */
9998 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
10001 /* Treat negative positions as relative to the leftmost bottommost
10002 position that fits on the screen. */
10003 if (flags
& XNegative
)
10004 f
->left_pos
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
10005 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
10008 int height
= FRAME_PIXEL_HEIGHT (f
);
10010 #if defined USE_X_TOOLKIT && defined USE_MOTIF
10011 /* Something is fishy here. When using Motif, starting Emacs with
10012 `-g -0-0', the frame appears too low by a few pixels.
10014 This seems to be so because initially, while Emacs is starting,
10015 the column widget's height and the frame's pixel height are
10016 different. The column widget's height is the right one. In
10017 later invocations, when Emacs is up, the frame's pixel height
10020 It's not obvious where the initial small difference comes from.
10021 2000-12-01, gerd. */
10023 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
10026 if (flags
& YNegative
)
10027 f
->top_pos
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
10028 - height
+ f
->top_pos
;
10031 /* The left_pos and top_pos
10032 are now relative to the top and left screen edges,
10033 so the flags should correspond. */
10034 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10037 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
10038 to really change the position, and 0 when calling from
10039 x_make_frame_visible (in that case, XOFF and YOFF are the current
10040 position values). It is -1 when calling from x_set_frame_parameters,
10041 which means, do adjust for borders but don't change the gravity. */
10044 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
10046 int modified_top
, modified_left
;
10048 if (change_gravity
> 0)
10051 f
->left_pos
= xoff
;
10052 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
10054 f
->size_hint_flags
|= XNegative
;
10056 f
->size_hint_flags
|= YNegative
;
10057 f
->win_gravity
= NorthWestGravity
;
10059 x_calc_absolute_position (f
);
10062 x_wm_set_size_hint (f
, 0, false);
10064 modified_left
= f
->left_pos
;
10065 modified_top
= f
->top_pos
;
10067 if (change_gravity
!= 0 && FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
10069 /* Some WMs (twm, wmaker at least) has an offset that is smaller
10070 than the WM decorations. So we use the calculated offset instead
10071 of the WM decoration sizes here (x/y_pixels_outer_diff). */
10072 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
10073 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
10076 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10077 modified_left
, modified_top
);
10079 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
10080 FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
);
10082 /* change_gravity is non-zero when this function is called from Lisp to
10083 programmatically move a frame. In that case, we call
10084 x_check_expected_move to discover if we have a "Type A" or "Type B"
10085 window manager, and, for a "Type A" window manager, adjust the position
10088 We call x_check_expected_move if a programmatic move occurred, and
10089 either the window manager type (A/B) is unknown or it is Type A but we
10090 need to compute the top/left offset adjustment for this frame. */
10092 if (change_gravity
!= 0
10093 && (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
10094 || (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
10095 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
10096 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
10097 x_check_expected_move (f
, modified_left
, modified_top
);
10102 /* Return true if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
10103 on the root window for frame F contains ATOMNAME.
10104 This is how a WM check shall be done according to the Window Manager
10105 Specification/Extended Window Manager Hints at
10106 http://freedesktop.org/wiki/Specifications/wm-spec. */
10109 x_wm_supports (struct frame
*f
, Atom want_atom
)
10112 unsigned long actual_size
, bytes_remaining
;
10113 int i
, rc
, actual_format
;
10115 Window wmcheck_window
;
10116 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10117 Window target_window
= dpyinfo
->root_window
;
10118 int max_len
= 65536;
10119 Display
*dpy
= FRAME_X_DISPLAY (f
);
10120 unsigned char *tmp_data
= NULL
;
10121 Atom target_type
= XA_WINDOW
;
10125 x_catch_errors (dpy
);
10126 rc
= XGetWindowProperty (dpy
, target_window
,
10127 dpyinfo
->Xatom_net_supporting_wm_check
,
10128 0, max_len
, False
, target_type
,
10129 &actual_type
, &actual_format
, &actual_size
,
10130 &bytes_remaining
, &tmp_data
);
10132 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
10134 if (tmp_data
) XFree (tmp_data
);
10135 x_uncatch_errors ();
10140 wmcheck_window
= *(Window
*) tmp_data
;
10143 /* Check if window exists. */
10144 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
10145 if (x_had_errors_p (dpy
))
10147 x_uncatch_errors_after_check ();
10152 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
10154 /* Window changed, reload atoms */
10155 if (dpyinfo
->net_supported_atoms
!= NULL
)
10156 XFree (dpyinfo
->net_supported_atoms
);
10157 dpyinfo
->net_supported_atoms
= NULL
;
10158 dpyinfo
->nr_net_supported_atoms
= 0;
10159 dpyinfo
->net_supported_window
= 0;
10161 target_type
= XA_ATOM
;
10163 rc
= XGetWindowProperty (dpy
, target_window
,
10164 dpyinfo
->Xatom_net_supported
,
10165 0, max_len
, False
, target_type
,
10166 &actual_type
, &actual_format
, &actual_size
,
10167 &bytes_remaining
, &tmp_data
);
10169 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
10171 if (tmp_data
) XFree (tmp_data
);
10172 x_uncatch_errors ();
10177 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
10178 dpyinfo
->nr_net_supported_atoms
= actual_size
;
10179 dpyinfo
->net_supported_window
= wmcheck_window
;
10184 for (i
= 0; !ret
&& i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
10185 ret
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
10187 x_uncatch_errors ();
10194 set_wm_state (Lisp_Object frame
, bool add
, Atom atom
, Atom value
)
10196 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (XFRAME (frame
));
10198 x_send_client_event (frame
, make_number (0), frame
,
10199 dpyinfo
->Xatom_net_wm_state
,
10201 /* 1 = add, 0 = remove */
10203 (make_number (add
),
10205 (make_fixnum_or_float (atom
),
10207 ? list1 (make_fixnum_or_float (value
))
10212 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
10215 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10217 XSETFRAME (frame
, f
);
10219 set_wm_state (frame
, !NILP (new_value
),
10220 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
10223 /* Return the current _NET_WM_STATE.
10224 SIZE_STATE is set to one of the FULLSCREEN_* values.
10225 Set *STICKY to the sticky state.
10227 Return true iff we are not hidden. */
10230 get_current_wm_state (struct frame
*f
,
10235 unsigned long actual_size
;
10237 bool is_hidden
= false;
10238 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10239 long max_len
= 65536;
10240 Atom target_type
= XA_ATOM
;
10241 /* If XCB is available, we can avoid three XSync calls. */
10243 xcb_get_property_cookie_t prop_cookie
;
10244 xcb_get_property_reply_t
*prop
;
10245 xcb_atom_t
*reply_data
;
10247 Display
*dpy
= FRAME_X_DISPLAY (f
);
10248 unsigned long bytes_remaining
;
10249 int rc
, actual_format
;
10251 unsigned char *tmp_data
= NULL
;
10256 *size_state
= FULLSCREEN_NONE
;
10261 prop_cookie
= xcb_get_property (dpyinfo
->xcb_connection
, 0, window
,
10262 dpyinfo
->Xatom_net_wm_state
,
10263 target_type
, 0, max_len
);
10264 prop
= xcb_get_property_reply (dpyinfo
->xcb_connection
, prop_cookie
, NULL
);
10265 if (prop
&& prop
->type
== target_type
)
10267 int actual_bytes
= xcb_get_property_value_length (prop
);
10268 eassume (0 <= actual_bytes
);
10269 actual_size
= actual_bytes
/ sizeof *reply_data
;
10270 reply_data
= xcb_get_property_value (prop
);
10275 is_hidden
= FRAME_ICONIFIED_P (f
);
10278 x_catch_errors (dpy
);
10279 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
10280 0, max_len
, False
, target_type
,
10281 &actual_type
, &actual_format
, &actual_size
,
10282 &bytes_remaining
, &tmp_data
);
10284 if (rc
== Success
&& actual_type
== target_type
&& ! x_had_errors_p (dpy
))
10285 reply_data
= (Atom
*) tmp_data
;
10289 is_hidden
= FRAME_ICONIFIED_P (f
);
10292 x_uncatch_errors ();
10295 for (i
= 0; i
< actual_size
; ++i
)
10297 Atom a
= reply_data
[i
];
10298 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
10300 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
10302 if (*size_state
== FULLSCREEN_HEIGHT
)
10303 *size_state
= FULLSCREEN_MAXIMIZED
;
10305 *size_state
= FULLSCREEN_WIDTH
;
10307 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
10309 if (*size_state
== FULLSCREEN_WIDTH
)
10310 *size_state
= FULLSCREEN_MAXIMIZED
;
10312 *size_state
= FULLSCREEN_HEIGHT
;
10314 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
10315 *size_state
= FULLSCREEN_BOTH
;
10316 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
10323 if (tmp_data
) XFree (tmp_data
);
10327 return ! is_hidden
;
10330 /* Do fullscreen as specified in extended window manager hints */
10333 do_ewmh_fullscreen (struct frame
*f
)
10335 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10336 bool have_net_atom
= x_wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
10340 get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
10342 /* Some window managers don't say they support _NET_WM_STATE, but they do say
10343 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
10344 if (!have_net_atom
)
10345 have_net_atom
= x_wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
10347 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
10351 XSETFRAME (frame
, f
);
10353 /* Keep number of calls to set_wm_state as low as possible.
10354 Some window managers, or possible Gtk+, hangs when too many
10355 are sent at once. */
10356 switch (f
->want_fullscreen
)
10358 case FULLSCREEN_BOTH
:
10359 if (cur
!= FULLSCREEN_BOTH
)
10360 set_wm_state (frame
, true, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10363 case FULLSCREEN_WIDTH
:
10364 if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_MAXIMIZED
)
10366 set_wm_state (frame
, false,
10367 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10368 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10369 set_wm_state (frame
, true,
10370 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10374 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
10375 || cur
== FULLSCREEN_MAXIMIZED
)
10376 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10377 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10378 if (cur
!= FULLSCREEN_MAXIMIZED
|| x_frame_normalize_before_maximize
)
10379 set_wm_state (frame
, true,
10380 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10383 case FULLSCREEN_HEIGHT
:
10384 if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_MAXIMIZED
)
10386 set_wm_state (frame
, false,
10387 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10388 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10389 set_wm_state (frame
, true,
10390 dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
10394 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
10395 || cur
== FULLSCREEN_MAXIMIZED
)
10396 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10397 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
10398 if (cur
!= FULLSCREEN_MAXIMIZED
|| x_frame_normalize_before_maximize
)
10399 set_wm_state (frame
, true,
10400 dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
10403 case FULLSCREEN_MAXIMIZED
:
10404 if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_BOTH
)
10406 set_wm_state (frame
, false,
10407 dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
10408 set_wm_state (frame
, true,
10409 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10410 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10412 else if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_WIDTH
)
10414 set_wm_state (frame
, false,
10415 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10416 set_wm_state (frame
, true,
10417 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10418 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10420 else if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_HEIGHT
)
10422 set_wm_state (frame
, false,
10423 dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
10424 set_wm_state (frame
, true,
10425 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10426 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10430 if (cur
== FULLSCREEN_BOTH
)
10431 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10433 else if (cur
== FULLSCREEN_HEIGHT
)
10434 set_wm_state (frame
, true,
10435 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10436 else if (cur
== FULLSCREEN_WIDTH
)
10437 set_wm_state (frame
, true, None
,
10438 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10440 set_wm_state (frame
, true,
10441 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10442 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10445 case FULLSCREEN_NONE
:
10446 if (cur
== FULLSCREEN_BOTH
)
10447 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10450 set_wm_state (frame
, false,
10451 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10452 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10455 f
->want_fullscreen
= FULLSCREEN_NONE
;
10459 return have_net_atom
;
10463 XTfullscreen_hook (struct frame
*f
)
10465 if (FRAME_VISIBLE_P (f
))
10468 x_check_fullscreen (f
);
10476 x_handle_net_wm_state (struct frame
*f
, const XPropertyEvent
*event
)
10478 int value
= FULLSCREEN_NONE
;
10480 bool sticky
= false;
10481 bool not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
10486 case FULLSCREEN_WIDTH
:
10489 case FULLSCREEN_HEIGHT
:
10490 lval
= Qfullheight
;
10492 case FULLSCREEN_BOTH
:
10495 case FULLSCREEN_MAXIMIZED
:
10500 frame_size_history_add
10501 (f
, Qx_handle_net_wm_state
, 0, 0,
10502 list2 (get_frame_param (f
, Qfullscreen
), lval
));
10504 store_frame_param (f
, Qfullscreen
, lval
);
10505 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
10510 /* Check if we need to resize the frame due to a fullscreen request.
10511 If so needed, resize the frame. */
10513 x_check_fullscreen (struct frame
*f
)
10515 Lisp_Object lval
= Qnil
;
10517 if (do_ewmh_fullscreen (f
))
10520 if (f
->output_data
.x
->parent_desc
!= FRAME_DISPLAY_INFO (f
)->root_window
)
10521 return; /* Only fullscreen without WM or with EWM hints (above). */
10523 /* Setting fullscreen to nil doesn't do anything. We could save the
10524 last non-fullscreen size and restore it, but it seems like a
10525 lot of work for this unusual case (no window manager running). */
10527 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
10529 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
10530 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10532 switch (f
->want_fullscreen
)
10534 /* No difference between these two when there is no WM */
10535 case FULLSCREEN_MAXIMIZED
:
10537 width
= x_display_pixel_width (dpyinfo
);
10538 height
= x_display_pixel_height (dpyinfo
);
10540 case FULLSCREEN_BOTH
:
10542 width
= x_display_pixel_width (dpyinfo
);
10543 height
= x_display_pixel_height (dpyinfo
);
10545 case FULLSCREEN_WIDTH
:
10547 width
= x_display_pixel_width (dpyinfo
);
10548 height
= height
+ FRAME_MENUBAR_HEIGHT (f
);
10550 case FULLSCREEN_HEIGHT
:
10551 lval
= Qfullheight
;
10552 height
= x_display_pixel_height (dpyinfo
);
10558 frame_size_history_add
10559 (f
, Qx_check_fullscreen
, width
, height
, Qnil
);
10561 x_wm_set_size_hint (f
, 0, false);
10563 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10566 if (FRAME_VISIBLE_P (f
))
10567 x_wait_for_event (f
, ConfigureNotify
);
10570 change_frame_size (f
, width
, height
- FRAME_MENUBAR_HEIGHT (f
),
10571 false, true, false, true);
10576 /* `x_net_wm_state' might have reset the fullscreen frame parameter,
10578 store_frame_param (f
, Qfullscreen
, lval
);
10581 /* This function is called by x_set_offset to determine whether the window
10582 manager interfered with the positioning of the frame. Type A window
10583 managers position the surrounding window manager decorations a small
10584 amount above and left of the user-supplied position. Type B window
10585 managers position the surrounding window manager decorations at the
10586 user-specified position. If we detect a Type A window manager, we
10587 compensate by moving the window right and down by the proper amount. */
10590 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
10592 int current_left
= 0, current_top
= 0;
10594 /* x_real_positions returns the left and top offsets of the outermost
10595 window manager window around the frame. */
10597 x_real_positions (f
, ¤t_left
, ¤t_top
);
10599 if (current_left
!= expected_left
|| current_top
!= expected_top
)
10601 /* It's a "Type A" window manager. */
10606 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
10607 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
10608 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
10610 /* Now fix the mispositioned frame's location. */
10612 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
10613 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
10615 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10616 adjusted_left
, adjusted_top
);
10618 x_sync_with_move (f
, expected_left
, expected_top
, false);
10621 /* It's a "Type B" window manager. We don't have to adjust the
10622 frame's position. */
10624 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
10628 /* Wait for XGetGeometry to return up-to-date position information for a
10629 recently-moved frame. Call this immediately after calling XMoveWindow.
10630 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
10631 frame has been moved to, so we use a fuzzy position comparison instead
10632 of an exact comparison. */
10635 x_sync_with_move (struct frame
*f
, int left
, int top
, bool fuzzy
)
10639 while (count
++ < 50)
10641 int current_left
= 0, current_top
= 0;
10643 /* In theory, this call to XSync only needs to happen once, but in
10644 practice, it doesn't seem to work, hence the need for the surrounding
10647 XSync (FRAME_X_DISPLAY (f
), False
);
10648 x_real_positions (f
, ¤t_left
, ¤t_top
);
10652 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
10655 if (eabs (current_left
- left
) <= 10
10656 && eabs (current_top
- top
) <= 40)
10659 else if (current_left
== left
&& current_top
== top
)
10663 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
10664 will then return up-to-date position info. */
10666 wait_reading_process_output (0, 500000000, 0, false, Qnil
, NULL
, 0);
10670 /* Wait for an event on frame F matching EVENTTYPE. */
10672 x_wait_for_event (struct frame
*f
, int eventtype
)
10674 int level
= interrupt_input_blocked
;
10677 struct timespec tmo
, tmo_at
, time_now
;
10678 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
10680 f
->wait_event_type
= eventtype
;
10682 /* Set timeout to 0.1 second. Hopefully not noticeable.
10683 Maybe it should be configurable. */
10684 tmo
= make_timespec (0, 100 * 1000 * 1000);
10685 tmo_at
= timespec_add (current_timespec (), tmo
);
10687 while (f
->wait_event_type
)
10689 pending_signals
= true;
10690 totally_unblock_input ();
10691 /* XTread_socket is called after unblock. */
10693 interrupt_input_blocked
= level
;
10698 time_now
= current_timespec ();
10699 if (timespec_cmp (tmo_at
, time_now
) < 0)
10702 tmo
= timespec_sub (tmo_at
, time_now
);
10703 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
10704 break; /* Timeout */
10707 f
->wait_event_type
= 0;
10711 /* Change the size of frame F's X window to WIDTH/HEIGHT in the case F
10712 doesn't have a widget. If CHANGE_GRAVITY, change to
10713 top-left-corner window gravity for this size change and subsequent
10714 size changes. Otherwise leave the window gravity unchanged. */
10717 x_set_window_size_1 (struct frame
*f
, bool change_gravity
,
10718 int width
, int height
)
10720 int pixelwidth
= FRAME_TEXT_TO_PIXEL_WIDTH (f
, width
);
10721 int pixelheight
= FRAME_TEXT_TO_PIXEL_HEIGHT (f
, height
);
10722 int old_width
= FRAME_PIXEL_WIDTH (f
);
10723 int old_height
= FRAME_PIXEL_HEIGHT (f
);
10724 Lisp_Object fullscreen
= get_frame_param (f
, Qfullscreen
);
10726 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
10727 x_wm_set_size_hint (f
, 0, false);
10729 /* When the frame is fullheight and we only want to change the width
10730 or it is fullwidth and we only want to change the height we should
10731 be able to preserve the fullscreen property. However, due to the
10732 fact that we have to send a resize request anyway, the window
10733 manager will abolish it. At least the respective size should
10734 remain unchanged but giving the frame back its normal size will
10736 if (EQ (fullscreen
, Qfullwidth
) && width
== FRAME_TEXT_WIDTH (f
))
10738 frame_size_history_add
10739 (f
, Qx_set_window_size_1
, width
, height
,
10740 list2 (make_number (old_height
),
10741 make_number (pixelheight
+ FRAME_MENUBAR_HEIGHT (f
))));
10743 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10744 old_width
, pixelheight
+ FRAME_MENUBAR_HEIGHT (f
));
10746 else if (EQ (fullscreen
, Qfullheight
) && height
== FRAME_TEXT_HEIGHT (f
))
10748 frame_size_history_add
10749 (f
, Qx_set_window_size_2
, width
, height
,
10750 list2 (make_number (old_width
), make_number (pixelwidth
)));
10752 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10753 pixelwidth
, old_height
);
10758 frame_size_history_add
10759 (f
, Qx_set_window_size_3
, width
, height
,
10760 list3 (make_number (pixelwidth
+ FRAME_TOOLBAR_WIDTH (f
)),
10761 make_number (pixelheight
+ FRAME_TOOLBAR_HEIGHT (f
)
10762 + FRAME_MENUBAR_HEIGHT (f
)),
10763 make_number (FRAME_MENUBAR_HEIGHT (f
))));
10765 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10766 pixelwidth
, pixelheight
+ FRAME_MENUBAR_HEIGHT (f
));
10772 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10773 receive in the ConfigureNotify event; if we get what we asked
10774 for, then the event won't cause the screen to become garbaged, so
10775 we have to make sure to do it here. */
10776 SET_FRAME_GARBAGED (f
);
10778 /* Now, strictly speaking, we can't be sure that this is accurate,
10779 but the window manager will get around to dealing with the size
10780 change request eventually, and we'll hear how it went when the
10781 ConfigureNotify event gets here.
10783 We could just not bother storing any of this information here,
10784 and let the ConfigureNotify event set everything up, but that
10785 might be kind of confusing to the Lisp code, since size changes
10786 wouldn't be reported in the frame parameters until some random
10787 point in the future when the ConfigureNotify event arrives.
10789 Pass true for DELAY since we can't run Lisp code inside of
10792 /* But the ConfigureNotify may in fact never arrive, and then this is
10793 not right if the frame is visible. Instead wait (with timeout)
10794 for the ConfigureNotify. */
10795 if (FRAME_VISIBLE_P (f
))
10797 x_wait_for_event (f
, ConfigureNotify
);
10799 if (!NILP (fullscreen
))
10800 /* Try to restore fullscreen state. */
10802 store_frame_param (f
, Qfullscreen
, fullscreen
);
10803 x_set_fullscreen (f
, fullscreen
, fullscreen
);
10808 change_frame_size (f
, width
, height
, false, true, false, true);
10814 /* Call this to change the size of frame F's x-window.
10815 If CHANGE_GRAVITY, change to top-left-corner window gravity
10816 for this size change and subsequent size changes.
10817 Otherwise we leave the window gravity unchanged. */
10820 x_set_window_size (struct frame
*f
, bool change_gravity
,
10821 int width
, int height
, bool pixelwise
)
10825 /* The following breaks our calculations. If it's really needed,
10826 think of something else. */
10828 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
10830 int text_width
, text_height
;
10832 /* When the frame is maximized/fullscreen or running under for
10833 example Xmonad, x_set_window_size_1 will be a no-op.
10834 In that case, the right thing to do is extend rows/width to
10835 the current frame size. We do that first if x_set_window_size_1
10836 turns out to not be a no-op (there is no way to know).
10837 The size will be adjusted again if the frame gets a
10838 ConfigureNotify event as a result of x_set_window_size. */
10839 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
10840 #ifdef USE_X_TOOLKIT
10841 /* The menu bar is not part of text lines. The tool bar
10843 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
10845 text_width
= FRAME_PIXEL_TO_TEXT_WIDTH (f
, FRAME_PIXEL_WIDTH (f
));
10846 text_height
= FRAME_PIXEL_TO_TEXT_HEIGHT (f
, pixelh
);
10848 change_frame_size (f
, text_width
, text_height
, false, true, false, true);
10852 /* Pixelize width and height, if necessary. */
10855 width
= width
* FRAME_COLUMN_WIDTH (f
);
10856 height
= height
* FRAME_LINE_HEIGHT (f
);
10860 if (FRAME_GTK_WIDGET (f
))
10861 xg_frame_set_char_size (f
, width
, height
);
10863 x_set_window_size_1 (f
, change_gravity
, width
, height
);
10864 #else /* not USE_GTK */
10865 x_set_window_size_1 (f
, change_gravity
, width
, height
);
10866 x_clear_under_internal_border (f
);
10867 #endif /* not USE_GTK */
10869 /* If cursor was outside the new size, mark it as off. */
10870 mark_window_cursors_off (XWINDOW (f
->root_window
));
10872 /* Clear out any recollection of where the mouse highlighting was,
10873 since it might be in a place that's outside the new frame size.
10874 Actually checking whether it is outside is a pain in the neck,
10875 so don't try--just let the highlighting be done afresh with new size. */
10876 cancel_mouse_face (f
);
10880 do_pending_window_change (false);
10883 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
10886 frame_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
10890 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10891 0, 0, 0, 0, pix_x
, pix_y
);
10895 /* Raise frame F. */
10898 x_raise_frame (struct frame
*f
)
10901 if (FRAME_VISIBLE_P (f
))
10902 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
10903 XFlush (FRAME_X_DISPLAY (f
));
10907 /* Lower frame F. */
10910 x_lower_frame (struct frame
*f
)
10912 if (FRAME_VISIBLE_P (f
))
10915 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
10916 XFlush (FRAME_X_DISPLAY (f
));
10921 /* Request focus with XEmbed */
10924 xembed_request_focus (struct frame
*f
)
10926 /* See XEmbed Protocol Specification at
10927 http://freedesktop.org/wiki/Specifications/xembed-spec */
10928 if (FRAME_VISIBLE_P (f
))
10929 xembed_send_message (f
, CurrentTime
,
10930 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
10933 /* Activate frame with Extended Window Manager Hints */
10936 x_ewmh_activate_frame (struct frame
*f
)
10938 /* See Window Manager Specification/Extended Window Manager Hints at
10939 http://freedesktop.org/wiki/Specifications/wm-spec */
10941 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10943 if (FRAME_VISIBLE_P (f
) && x_wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
10946 XSETFRAME (frame
, f
);
10947 x_send_client_event (frame
, make_number (0), frame
,
10948 dpyinfo
->Xatom_net_active_window
,
10950 list2i (1, dpyinfo
->last_user_time
));
10955 XTframe_raise_lower (struct frame
*f
, bool raise_flag
)
10963 /* XEmbed implementation. */
10965 #if defined USE_X_TOOLKIT || ! defined USE_GTK
10967 /* XEmbed implementation. */
10969 #define XEMBED_VERSION 0
10972 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
10974 unsigned long data
[2];
10975 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10977 data
[0] = XEMBED_VERSION
;
10980 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10981 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
10982 32, PropModeReplace
, (unsigned char *) data
, 2);
10984 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
10987 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
10988 long int detail
, long int data1
, long int data2
)
10992 event
.xclient
.type
= ClientMessage
;
10993 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
10994 event
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_XEMBED
;
10995 event
.xclient
.format
= 32;
10996 event
.xclient
.data
.l
[0] = t
;
10997 event
.xclient
.data
.l
[1] = msg
;
10998 event
.xclient
.data
.l
[2] = detail
;
10999 event
.xclient
.data
.l
[3] = data1
;
11000 event
.xclient
.data
.l
[4] = data2
;
11002 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
11003 False
, NoEventMask
, &event
);
11004 XSync (FRAME_X_DISPLAY (f
), False
);
11007 /* Change of visibility. */
11009 /* This function sends the request to make the frame visible, but may
11010 return before it the frame's visibility is changed. */
11013 x_make_frame_visible (struct frame
*f
)
11017 x_set_bitmap_icon (f
);
11019 if (! FRAME_VISIBLE_P (f
))
11021 /* We test asked_for_visible here to make sure we don't
11022 call x_set_offset a second time
11023 if we get to x_make_frame_visible a second time
11024 before the window gets really visible. */
11025 if (! FRAME_ICONIFIED_P (f
)
11026 && ! FRAME_X_EMBEDDED_P (f
)
11027 && ! f
->output_data
.x
->asked_for_visible
)
11028 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
11030 f
->output_data
.x
->asked_for_visible
= true;
11032 if (! EQ (Vx_no_window_manager
, Qt
))
11033 x_wm_set_window_state (f
, NormalState
);
11034 #ifdef USE_X_TOOLKIT
11035 if (FRAME_X_EMBEDDED_P (f
))
11036 xembed_set_info (f
, XEMBED_MAPPED
);
11039 /* This was XtPopup, but that did nothing for an iconified frame. */
11040 XtMapWidget (f
->output_data
.x
->widget
);
11042 #else /* not USE_X_TOOLKIT */
11044 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
11045 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
11047 if (FRAME_X_EMBEDDED_P (f
))
11048 xembed_set_info (f
, XEMBED_MAPPED
);
11050 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11051 #endif /* not USE_GTK */
11052 #endif /* not USE_X_TOOLKIT */
11055 XFlush (FRAME_X_DISPLAY (f
));
11057 /* Synchronize to ensure Emacs knows the frame is visible
11058 before we do anything else. We do this loop with input not blocked
11059 so that incoming events are handled. */
11061 /* This must be before UNBLOCK_INPUT
11062 since events that arrive in response to the actions above
11063 will set it when they are handled. */
11064 bool previously_visible
= f
->output_data
.x
->has_been_visible
;
11066 int original_left
= f
->left_pos
;
11067 int original_top
= f
->top_pos
;
11069 /* This must come after we set COUNT. */
11072 /* We unblock here so that arriving X events are processed. */
11074 /* Now move the window back to where it was "supposed to be".
11075 But don't do it if the gravity is negative.
11076 When the gravity is negative, this uses a position
11077 that is 3 pixels too low. Perhaps that's really the border width.
11079 Don't do this if the window has never been visible before,
11080 because the window manager may choose the position
11081 and we don't want to override it. */
11083 if (! FRAME_VISIBLE_P (f
)
11084 && ! FRAME_ICONIFIED_P (f
)
11085 && ! FRAME_X_EMBEDDED_P (f
)
11086 && f
->win_gravity
== NorthWestGravity
11087 && previously_visible
)
11091 unsigned int width
, height
, border
, depth
;
11095 /* On some window managers (such as FVWM) moving an existing
11096 window, even to the same place, causes the window manager
11097 to introduce an offset. This can cause the window to move
11098 to an unexpected location. Check the geometry (a little
11099 slow here) and then verify that the window is in the right
11100 place. If the window is not in the right place, move it
11101 there, and take the potential window manager hit. */
11102 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11103 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
11105 if (original_left
!= x
|| original_top
!= y
)
11106 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
11107 original_left
, original_top
);
11114 /* Change from mapped state to withdrawn state. */
11116 /* Make the frame visible (mapped and not iconified). */
11119 x_make_frame_invisible (struct frame
*f
)
11123 /* Use the frame's outermost window, not the one we normally draw on. */
11124 window
= FRAME_OUTER_WINDOW (f
);
11126 /* Don't keep the highlight on an invisible frame. */
11127 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11128 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11132 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11133 that the current position of the window is user-specified, rather than
11134 program-specified, so that when the window is mapped again, it will be
11135 placed at the same location, without forcing the user to position it
11136 by hand again (they have already done that once for this window.) */
11137 x_wm_set_size_hint (f
, 0, true);
11140 if (FRAME_GTK_OUTER_WIDGET (f
))
11141 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
11144 if (FRAME_X_EMBEDDED_P (f
))
11145 xembed_set_info (f
, 0);
11150 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11151 DefaultScreen (FRAME_X_DISPLAY (f
))))
11154 error ("Can't notify window manager of window withdrawal");
11158 /* We can't distinguish this from iconification
11159 just by the event that we get from the server.
11160 So we can't win using the usual strategy of letting
11161 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11162 and synchronize with the server to make sure we agree. */
11163 SET_FRAME_VISIBLE (f
, 0);
11164 SET_FRAME_ICONIFIED (f
, false);
11171 /* Change window state from mapped to iconified. */
11174 x_iconify_frame (struct frame
*f
)
11176 #ifdef USE_X_TOOLKIT
11180 /* Don't keep the highlight on an invisible frame. */
11181 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11182 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11184 if (FRAME_ICONIFIED_P (f
))
11189 x_set_bitmap_icon (f
);
11191 #if defined (USE_GTK)
11192 if (FRAME_GTK_OUTER_WIDGET (f
))
11194 if (! FRAME_VISIBLE_P (f
))
11195 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
11197 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
11198 SET_FRAME_VISIBLE (f
, 0);
11199 SET_FRAME_ICONIFIED (f
, true);
11205 #ifdef USE_X_TOOLKIT
11207 if (! FRAME_VISIBLE_P (f
))
11209 if (! EQ (Vx_no_window_manager
, Qt
))
11210 x_wm_set_window_state (f
, IconicState
);
11211 /* This was XtPopup, but that did nothing for an iconified frame. */
11212 XtMapWidget (f
->output_data
.x
->widget
);
11213 /* The server won't give us any event to indicate
11214 that an invisible frame was changed to an icon,
11215 so we have to record it here. */
11216 SET_FRAME_VISIBLE (f
, 0);
11217 SET_FRAME_ICONIFIED (f
, true);
11222 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11223 XtWindow (f
->output_data
.x
->widget
),
11224 DefaultScreen (FRAME_X_DISPLAY (f
)));
11228 error ("Can't notify window manager of iconification");
11230 SET_FRAME_ICONIFIED (f
, true);
11231 SET_FRAME_VISIBLE (f
, 0);
11234 XFlush (FRAME_X_DISPLAY (f
));
11236 #else /* not USE_X_TOOLKIT */
11238 /* Make sure the X server knows where the window should be positioned,
11239 in case the user deiconifies with the window manager. */
11240 if (! FRAME_VISIBLE_P (f
)
11241 && ! FRAME_ICONIFIED_P (f
)
11242 && ! FRAME_X_EMBEDDED_P (f
))
11243 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
11245 /* Since we don't know which revision of X we're running, we'll use both
11246 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11248 /* X11R4: send a ClientMessage to the window manager using the
11249 WM_CHANGE_STATE type. */
11253 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
11254 msg
.xclient
.type
= ClientMessage
;
11255 msg
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11256 msg
.xclient
.format
= 32;
11257 msg
.xclient
.data
.l
[0] = IconicState
;
11259 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11260 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11262 SubstructureRedirectMask
| SubstructureNotifyMask
,
11266 error ("Can't notify window manager of iconification");
11270 /* X11R3: set the initial_state field of the window manager hints to
11272 x_wm_set_window_state (f
, IconicState
);
11274 if (!FRAME_VISIBLE_P (f
))
11276 /* If the frame was withdrawn, before, we must map it. */
11277 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11280 SET_FRAME_ICONIFIED (f
, true);
11281 SET_FRAME_VISIBLE (f
, 0);
11283 XFlush (FRAME_X_DISPLAY (f
));
11285 #endif /* not USE_X_TOOLKIT */
11289 /* Free X resources of frame F. */
11292 x_free_frame_resources (struct frame
*f
)
11294 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
11295 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
11296 #ifdef USE_X_TOOLKIT
11298 struct scroll_bar
*b
;
11303 /* If a display connection is dead, don't try sending more
11304 commands to the X server. */
11305 if (dpyinfo
->display
)
11307 /* Always exit with visible pointer to avoid weird issue
11308 with Xfixes (Bug#17609). */
11309 if (f
->pointer_invisible
)
11310 FRAME_DISPLAY_INFO (f
)->toggle_visible_pointer (f
, 0);
11312 /* We must free faces before destroying windows because some
11313 font-driver (e.g. xft) access a window while finishing a
11315 free_frame_faces (f
);
11316 tear_down_x_back_buffer (f
);
11318 if (f
->output_data
.x
->icon_desc
)
11319 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11321 #ifdef USE_X_TOOLKIT
11322 /* Explicitly destroy the scroll bars of the frame. Without
11323 this, we get "BadDrawable" errors from the toolkit later on,
11324 presumably from expose events generated for the disappearing
11325 toolkit scroll bars. */
11326 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
11328 b
= XSCROLL_BAR (bar
);
11329 x_scroll_bar_remove (b
);
11335 free_frame_xic (f
);
11338 x_free_cr_resources (f
);
11339 #ifdef USE_X_TOOLKIT
11340 if (f
->output_data
.x
->widget
)
11342 XtDestroyWidget (f
->output_data
.x
->widget
);
11343 f
->output_data
.x
->widget
= NULL
;
11345 /* Tooltips don't have widgets, only a simple X window, even if
11346 we are using a toolkit. */
11347 else if (FRAME_X_WINDOW (f
))
11348 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11350 free_frame_menubar (f
);
11352 if (f
->shell_position
)
11353 xfree (f
->shell_position
);
11354 #else /* !USE_X_TOOLKIT */
11357 xg_free_frame_widgets (f
);
11358 #endif /* USE_GTK */
11360 tear_down_x_back_buffer (f
);
11361 if (FRAME_X_WINDOW (f
))
11362 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11363 #endif /* !USE_X_TOOLKIT */
11365 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
11366 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
11367 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
11368 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
11369 unload_color (f
, f
->output_data
.x
->border_pixel
);
11370 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
11372 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
11373 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
11374 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
11375 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
11376 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
11377 /* Scrollbar shadow colors. */
11378 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
11379 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
11380 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
11381 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
11382 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
11383 if (f
->output_data
.x
->white_relief
.pixel
!= -1)
11384 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
11385 if (f
->output_data
.x
->black_relief
.pixel
!= -1)
11386 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
11390 /* Free extra GCs allocated by x_setup_relief_colors. */
11391 if (f
->output_data
.x
->white_relief
.gc
)
11393 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
11394 f
->output_data
.x
->white_relief
.gc
= 0;
11396 if (f
->output_data
.x
->black_relief
.gc
)
11398 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
11399 f
->output_data
.x
->black_relief
.gc
= 0;
11402 /* Free cursors. */
11403 if (f
->output_data
.x
->text_cursor
!= 0)
11404 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->text_cursor
);
11405 if (f
->output_data
.x
->nontext_cursor
!= 0)
11406 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->nontext_cursor
);
11407 if (f
->output_data
.x
->modeline_cursor
!= 0)
11408 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->modeline_cursor
);
11409 if (f
->output_data
.x
->hand_cursor
!= 0)
11410 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->hand_cursor
);
11411 if (f
->output_data
.x
->hourglass_cursor
!= 0)
11412 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->hourglass_cursor
);
11413 if (f
->output_data
.x
->horizontal_drag_cursor
!= 0)
11414 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->horizontal_drag_cursor
);
11415 if (f
->output_data
.x
->vertical_drag_cursor
!= 0)
11416 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->vertical_drag_cursor
);
11418 XFlush (FRAME_X_DISPLAY (f
));
11421 xfree (f
->output_data
.x
->saved_menu_event
);
11422 xfree (f
->output_data
.x
);
11423 f
->output_data
.x
= NULL
;
11425 if (f
== dpyinfo
->x_focus_frame
)
11426 dpyinfo
->x_focus_frame
= 0;
11427 if (f
== dpyinfo
->x_focus_event_frame
)
11428 dpyinfo
->x_focus_event_frame
= 0;
11429 if (f
== dpyinfo
->x_highlight_frame
)
11430 dpyinfo
->x_highlight_frame
= 0;
11431 if (f
== hlinfo
->mouse_face_mouse_frame
)
11432 reset_mouse_highlight (hlinfo
);
11438 /* Destroy the X window of frame F. */
11441 x_destroy_window (struct frame
*f
)
11443 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
11445 /* If a display connection is dead, don't try sending more
11446 commands to the X server. */
11447 if (dpyinfo
->display
!= 0)
11448 x_free_frame_resources (f
);
11450 dpyinfo
->reference_count
--;
11454 /* Setting window manager hints. */
11456 /* Set the normal size hints for the window manager, for frame F.
11457 FLAGS is the flags word to use--or 0 meaning preserve the flags
11458 that the window now has.
11459 If USER_POSITION, set the USPosition
11460 flag (this is useful when FLAGS is 0).
11461 The GTK version is in gtkutils.c. */
11465 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
11467 XSizeHints size_hints
;
11468 Window window
= FRAME_OUTER_WINDOW (f
);
11473 #ifdef USE_X_TOOLKIT
11474 if (f
->output_data
.x
->widget
)
11476 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
11481 /* Setting PMaxSize caused various problems. */
11482 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
11484 size_hints
.x
= f
->left_pos
;
11485 size_hints
.y
= f
->top_pos
;
11487 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
11488 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
11490 size_hints
.width_inc
= frame_resize_pixelwise
? 1 : FRAME_COLUMN_WIDTH (f
);
11491 size_hints
.height_inc
= frame_resize_pixelwise
? 1 : FRAME_LINE_HEIGHT (f
);
11493 size_hints
.max_width
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
11494 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
11495 size_hints
.max_height
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
11496 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
11498 /* Calculate the base and minimum sizes. */
11500 int base_width
, base_height
;
11502 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
11503 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
11505 /* The window manager uses the base width hints to calculate the
11506 current number of rows and columns in the frame while
11507 resizing; min_width and min_height aren't useful for this
11508 purpose, since they might not give the dimensions for a
11509 zero-row, zero-column frame. */
11511 size_hints
.flags
|= PBaseSize
;
11512 size_hints
.base_width
= base_width
;
11513 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
11514 size_hints
.min_width
= base_width
;
11515 size_hints
.min_height
= base_height
;
11518 /* If we don't need the old flags, we don't need the old hint at all. */
11521 size_hints
.flags
|= flags
;
11526 XSizeHints hints
; /* Sometimes I hate X Windows... */
11527 long supplied_return
;
11530 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
11534 size_hints
.flags
|= flags
;
11539 if (hints
.flags
& PSize
)
11540 size_hints
.flags
|= PSize
;
11541 if (hints
.flags
& PPosition
)
11542 size_hints
.flags
|= PPosition
;
11543 if (hints
.flags
& USPosition
)
11544 size_hints
.flags
|= USPosition
;
11545 if (hints
.flags
& USSize
)
11546 size_hints
.flags
|= USSize
;
11553 size_hints
.win_gravity
= f
->win_gravity
;
11554 size_hints
.flags
|= PWinGravity
;
11558 size_hints
.flags
&= ~ PPosition
;
11559 size_hints
.flags
|= USPosition
;
11561 #endif /* PWinGravity */
11563 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11565 #endif /* not USE_GTK */
11567 /* Used for IconicState or NormalState */
11570 x_wm_set_window_state (struct frame
*f
, int state
)
11572 #ifdef USE_X_TOOLKIT
11575 XtSetArg (al
[0], XtNinitialState
, state
);
11576 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11577 #else /* not USE_X_TOOLKIT */
11578 Window window
= FRAME_X_WINDOW (f
);
11580 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
11581 f
->output_data
.x
->wm_hints
.initial_state
= state
;
11583 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11584 #endif /* not USE_X_TOOLKIT */
11588 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
11590 Pixmap icon_pixmap
, icon_mask
;
11592 #if !defined USE_X_TOOLKIT && !defined USE_GTK
11593 Window window
= FRAME_OUTER_WINDOW (f
);
11598 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
11599 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
11600 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
11601 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
11605 /* It seems there is no way to turn off use of an icon
11613 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
11617 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
11621 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
11622 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11623 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
11624 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11627 #else /* not USE_X_TOOLKIT && not USE_GTK */
11629 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
11630 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11632 #endif /* not USE_X_TOOLKIT && not USE_GTK */
11636 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
11638 Window window
= FRAME_OUTER_WINDOW (f
);
11640 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
11641 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
11642 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
11644 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11648 /***********************************************************************
11650 ***********************************************************************/
11654 /* Check that FONT is valid on frame F. It is if it can be found in F's
11658 x_check_font (struct frame
*f
, struct font
*font
)
11660 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
11661 if (font
->driver
->check
)
11662 eassert (font
->driver
->check (f
, font
) == 0);
11665 #endif /* GLYPH_DEBUG */
11668 /***********************************************************************
11670 ***********************************************************************/
11672 #ifdef USE_X_TOOLKIT
11673 static XrmOptionDescRec emacs_options
[] = {
11674 {(char *) "-geometry", (char *) ".geometry", XrmoptionSepArg
, NULL
},
11675 {(char *) "-iconic", (char *) ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
11677 {(char *) "-internal-border-width",
11678 (char *) "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
11679 {(char *) "-ib", (char *) "*EmacsScreen.internalBorderWidth",
11680 XrmoptionSepArg
, NULL
},
11681 {(char *) "-T", (char *) "*EmacsShell.title", XrmoptionSepArg
, NULL
},
11682 {(char *) "-wn", (char *) "*EmacsShell.title", XrmoptionSepArg
, NULL
},
11683 {(char *) "-title", (char *) "*EmacsShell.title", XrmoptionSepArg
, NULL
},
11684 {(char *) "-iconname", (char *) "*EmacsShell.iconName",
11685 XrmoptionSepArg
, NULL
},
11686 {(char *) "-in", (char *) "*EmacsShell.iconName", XrmoptionSepArg
, NULL
},
11687 {(char *) "-mc", (char *) "*pointerColor", XrmoptionSepArg
, NULL
},
11688 {(char *) "-cr", (char *) "*cursorColor", XrmoptionSepArg
, NULL
}
11691 /* Whether atimer for Xt timeouts is activated or not. */
11693 static bool x_timeout_atimer_activated_flag
;
11695 #endif /* USE_X_TOOLKIT */
11697 static int x_initialized
;
11699 /* Test whether two display-name strings agree up to the dot that separates
11700 the screen number from the server number. */
11702 same_x_server (const char *name1
, const char *name2
)
11704 bool seen_colon
= false;
11705 Lisp_Object sysname
= Fsystem_name ();
11706 const char *system_name
= SSDATA (sysname
);
11707 ptrdiff_t system_name_length
= SBYTES (sysname
);
11708 ptrdiff_t length_until_period
= 0;
11710 while (system_name
[length_until_period
] != 0
11711 && system_name
[length_until_period
] != '.')
11712 length_until_period
++;
11714 /* Treat `unix' like an empty host name. */
11715 if (! strncmp (name1
, "unix:", 5))
11717 if (! strncmp (name2
, "unix:", 5))
11719 /* Treat this host's name like an empty host name. */
11720 if (! strncmp (name1
, system_name
, system_name_length
)
11721 && name1
[system_name_length
] == ':')
11722 name1
+= system_name_length
;
11723 if (! strncmp (name2
, system_name
, system_name_length
)
11724 && name2
[system_name_length
] == ':')
11725 name2
+= system_name_length
;
11726 /* Treat this host's domainless name like an empty host name. */
11727 if (! strncmp (name1
, system_name
, length_until_period
)
11728 && name1
[length_until_period
] == ':')
11729 name1
+= length_until_period
;
11730 if (! strncmp (name2
, system_name
, length_until_period
)
11731 && name2
[length_until_period
] == ':')
11732 name2
+= length_until_period
;
11734 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
11738 if (seen_colon
&& *name1
== '.')
11742 && (*name1
== '.' || *name1
== '\0')
11743 && (*name2
== '.' || *name2
== '\0'));
11746 /* Count number of set bits in mask and number of bits to shift to
11747 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
11750 get_bits_and_offset (unsigned long mask
, int *bits
, int *offset
)
11755 while (!(mask
& 1))
11771 /* Return true iff display DISPLAY is available for use.
11772 But don't permanently open it, just test its availability. */
11775 x_display_ok (const char *display
)
11777 /* XOpenDisplay fails if it gets a signal. Block SIGIO which may arrive. */
11778 unrequest_sigio ();
11779 Display
*dpy
= XOpenDisplay (display
);
11783 XCloseDisplay (dpy
);
11789 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
11790 const gchar
*msg
, gpointer user_data
)
11792 if (!strstr (msg
, "g_set_prgname"))
11793 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
11797 /* Create invisible cursor on X display referred by DPYINFO. */
11800 make_invisible_cursor (struct x_display_info
*dpyinfo
)
11802 Display
*dpy
= dpyinfo
->display
;
11803 static char const no_data
[] = { 0 };
11808 x_catch_errors (dpy
);
11809 pix
= XCreateBitmapFromData (dpy
, dpyinfo
->root_window
, no_data
, 1, 1);
11810 if (! x_had_errors_p (dpy
) && pix
!= None
)
11814 col
.red
= col
.green
= col
.blue
= 0;
11815 col
.flags
= DoRed
| DoGreen
| DoBlue
;
11816 pixc
= XCreatePixmapCursor (dpy
, pix
, pix
, &col
, &col
, 0, 0);
11817 if (! x_had_errors_p (dpy
) && pixc
!= None
)
11819 XFreePixmap (dpy
, pix
);
11822 x_uncatch_errors ();
11827 /* True if DPY supports Xfixes extension >= 4. */
11830 x_probe_xfixes_extension (Display
*dpy
)
11834 return XFixesQueryVersion (dpy
, &major
, &minor
) && major
>= 4;
11837 #endif /* HAVE_XFIXES */
11840 /* Toggle mouse pointer visibility on frame F by using Xfixes functions. */
11843 xfixes_toggle_visible_pointer (struct frame
*f
, bool invisible
)
11847 XFixesHideCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11849 XFixesShowCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11850 f
->pointer_invisible
= invisible
;
11853 #endif /* HAVE_XFIXES */
11856 /* Toggle mouse pointer visibility on frame F by using invisible cursor. */
11859 x_toggle_visible_pointer (struct frame
*f
, bool invisible
)
11861 eassert (FRAME_DISPLAY_INFO (f
)->invisible_cursor
!= 0);
11863 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11864 FRAME_DISPLAY_INFO (f
)->invisible_cursor
);
11866 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11867 f
->output_data
.x
->current_cursor
);
11868 f
->pointer_invisible
= invisible
;
11871 /* Setup pointer blanking, prefer Xfixes if available. */
11874 x_setup_pointer_blanking (struct x_display_info
*dpyinfo
)
11876 /* FIXME: the brave tester should set EMACS_XFIXES because we're suspecting
11877 X server bug, see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17609. */
11878 if (egetenv ("EMACS_XFIXES") && x_probe_xfixes_extension (dpyinfo
->display
))
11879 dpyinfo
->toggle_visible_pointer
= xfixes_toggle_visible_pointer
;
11882 dpyinfo
->toggle_visible_pointer
= x_toggle_visible_pointer
;
11883 dpyinfo
->invisible_cursor
= make_invisible_cursor (dpyinfo
);
11887 /* Current X display connection identifier. Incremented for each next
11888 connection established. */
11889 static unsigned x_display_id
;
11891 /* Open a connection to X display DISPLAY_NAME, and return
11892 the structure that describes the open display.
11893 If we cannot contact the display, return null. */
11895 struct x_display_info
*
11896 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
11899 struct terminal
*terminal
;
11900 struct x_display_info
*dpyinfo
;
11903 xcb_connection_t
*xcb_conn
;
11908 if (!x_initialized
)
11914 if (! x_display_ok (SSDATA (display_name
)))
11915 error ("Display %s can't be opened", SSDATA (display_name
));
11919 #define NUM_ARGV 10
11921 char *argv
[NUM_ARGV
];
11922 char **argv2
= argv
;
11925 if (x_initialized
++ > 1)
11927 xg_display_open (SSDATA (display_name
), &dpy
);
11931 static char display_opt
[] = "--display";
11932 static char name_opt
[] = "--name";
11934 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
11938 argv
[argc
++] = initial_argv
[0];
11940 if (! NILP (display_name
))
11942 argv
[argc
++] = display_opt
;
11943 argv
[argc
++] = SSDATA (display_name
);
11946 argv
[argc
++] = name_opt
;
11947 argv
[argc
++] = resource_name
;
11949 XSetLocaleModifiers ("");
11951 /* Work around GLib bug that outputs a faulty warning. See
11952 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
11953 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
11954 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
11956 /* NULL window -> events for all windows go to our function.
11957 Call before gtk_init so Gtk+ event filters comes after our. */
11958 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
11960 /* gtk_init does set_locale. Fix locale before and after. */
11962 unrequest_sigio (); /* See comment in x_display_ok. */
11963 gtk_init (&argc
, &argv2
);
11967 g_log_remove_handler ("GLib", id
);
11971 dpy
= DEFAULT_GDK_DISPLAY ();
11973 #if ! GTK_CHECK_VERSION (2, 90, 0)
11974 /* Load our own gtkrc if it exists. */
11976 const char *file
= "~/.emacs.d/gtkrc";
11977 Lisp_Object s
, abs_file
;
11979 s
= build_string (file
);
11980 abs_file
= Fexpand_file_name (s
, Qnil
);
11982 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
11983 gtk_rc_parse (SSDATA (abs_file
));
11987 XSetErrorHandler (x_error_handler
);
11988 XSetIOErrorHandler (x_io_error_quitter
);
11991 #else /* not USE_GTK */
11992 #ifdef USE_X_TOOLKIT
11993 /* weiner@footloose.sps.mot.com reports that this causes
11995 X protocol error: BadAtom (invalid Atom parameter)
11996 on protocol request 18skiloaf.
11997 So let's not use it until R6. */
11998 #ifdef HAVE_X11XTR6
11999 XtSetLanguageProc (NULL
, NULL
, NULL
);
12006 argv
[0] = (char *) "";
12010 argv
[argc
++] = (char *) "-xrm";
12011 argv
[argc
++] = xrm_option
;
12013 turn_on_atimers (false);
12014 unrequest_sigio (); /* See comment in x_display_ok. */
12015 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
12016 resource_name
, EMACS_CLASS
,
12017 emacs_options
, XtNumber (emacs_options
),
12020 turn_on_atimers (true);
12022 #ifdef HAVE_X11XTR6
12023 /* I think this is to compensate for XtSetLanguageProc. */
12028 #else /* not USE_X_TOOLKIT */
12029 XSetLocaleModifiers ("");
12030 unrequest_sigio (); /* See comment in x_display_ok. */
12031 dpy
= XOpenDisplay (SSDATA (display_name
));
12033 #endif /* not USE_X_TOOLKIT */
12034 #endif /* not USE_GTK*/
12036 /* Detect failure. */
12044 xcb_conn
= XGetXCBConnection (dpy
);
12048 xg_display_close (dpy
);
12050 #ifdef USE_X_TOOLKIT
12051 XtCloseDisplay (dpy
);
12053 XCloseDisplay (dpy
);
12055 #endif /* ! USE_GTK */
12062 /* We have definitely succeeded. Record the new connection. */
12064 dpyinfo
= xzalloc (sizeof *dpyinfo
);
12065 terminal
= x_create_terminal (dpyinfo
);
12068 struct x_display_info
*share
;
12070 for (share
= x_display_list
; share
; share
= share
->next
)
12071 if (same_x_server (SSDATA (XCAR (share
->name_list_element
)),
12072 SSDATA (display_name
)))
12075 terminal
->kboard
= share
->terminal
->kboard
;
12078 terminal
->kboard
= allocate_kboard (Qx
);
12080 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
12082 char *vendor
= ServerVendor (dpy
);
12084 /* Temporarily hide the partially initialized terminal. */
12085 terminal_list
= terminal
->next_terminal
;
12087 kset_system_key_alist
12089 call1 (Qvendor_specific_keysyms
,
12090 vendor
? build_string (vendor
) : empty_unibyte_string
));
12092 terminal
->next_terminal
= terminal_list
;
12093 terminal_list
= terminal
;
12096 /* Don't let the initial kboard remain current longer than necessary.
12097 That would cause problems if a file loaded on startup tries to
12098 prompt in the mini-buffer. */
12099 if (current_kboard
== initial_kboard
)
12100 current_kboard
= terminal
->kboard
;
12102 terminal
->kboard
->reference_count
++;
12105 /* Put this display on the chain. */
12106 dpyinfo
->next
= x_display_list
;
12107 x_display_list
= dpyinfo
;
12109 dpyinfo
->name_list_element
= Fcons (display_name
, Qnil
);
12110 dpyinfo
->display
= dpy
;
12111 dpyinfo
->connection
= ConnectionNumber (dpyinfo
->display
);
12113 dpyinfo
->xcb_connection
= xcb_conn
;
12116 /* http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg00194.html */
12117 dpyinfo
->smallest_font_height
= 1;
12118 dpyinfo
->smallest_char_width
= 1;
12120 /* Set the name of the terminal. */
12121 terminal
->name
= xlispstrdup (display_name
);
12124 XSetAfterFunction (x_current_display
, x_trace_wire
);
12127 Lisp_Object system_name
= Fsystem_name ();
12129 if (INT_ADD_WRAPV (SBYTES (Vinvocation_name
), SBYTES (system_name
) + 2,
12131 memory_full (SIZE_MAX
);
12132 dpyinfo
->x_id
= ++x_display_id
;
12133 dpyinfo
->x_id_name
= xmalloc (nbytes
);
12134 char *nametail
= lispstpcpy (dpyinfo
->x_id_name
, Vinvocation_name
);
12136 lispstpcpy (nametail
, system_name
);
12138 /* Figure out which modifier bits mean what. */
12139 x_find_modifier_meanings (dpyinfo
);
12141 /* Get the scroll bar cursor. */
12143 /* We must create a GTK cursor, it is required for GTK widgets. */
12144 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
12145 #endif /* USE_GTK */
12147 dpyinfo
->vertical_scroll_bar_cursor
12148 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
12150 dpyinfo
->horizontal_scroll_bar_cursor
12151 = XCreateFontCursor (dpyinfo
->display
, XC_sb_h_double_arrow
);
12153 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
12154 resource_name
, EMACS_CLASS
);
12155 #ifdef HAVE_XRMSETDATABASE
12156 XrmSetDatabase (dpyinfo
->display
, xrdb
);
12158 dpyinfo
->display
->db
= xrdb
;
12160 /* Put the rdb where we can find it in a way that works on
12162 dpyinfo
->xrdb
= xrdb
;
12164 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
12165 DefaultScreen (dpyinfo
->display
));
12166 select_visual (dpyinfo
);
12167 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
12168 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
12169 dpyinfo
->icon_bitmap_id
= -1;
12170 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
12172 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
12174 /* See if we can construct pixel values from RGB values. */
12175 if (dpyinfo
->visual
->class == TrueColor
)
12177 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
12178 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
12179 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
12180 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
12181 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
12182 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
12185 /* See if a private colormap is requested. */
12186 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
12188 if (dpyinfo
->visual
->class == PseudoColor
)
12190 AUTO_STRING (privateColormap
, "privateColormap");
12191 AUTO_STRING (PrivateColormap
, "PrivateColormap");
12193 = display_x_get_resource (dpyinfo
, privateColormap
,
12194 PrivateColormap
, Qnil
, Qnil
);
12195 if (STRINGP (value
)
12196 && (!strcmp (SSDATA (value
), "true")
12197 || !strcmp (SSDATA (value
), "on")))
12198 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
12202 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
12203 dpyinfo
->visual
, AllocNone
);
12206 dpyinfo
->supports_xdbe
= false;
12209 if (XdbeQueryExtension (dpyinfo
->display
, &xdbe_major
, &xdbe_minor
))
12210 dpyinfo
->supports_xdbe
= true;
12215 /* If we are using Xft, the following precautions should be made:
12217 1. Make sure that the Xrender extension is added before the Xft one.
12218 Otherwise, the close-display hook set by Xft is called after the one
12219 for Xrender, and the former tries to re-add the latter. This results
12220 in inconsistency of internal states and leads to X protocol error when
12221 one reconnects to the same X server (Bug#1696).
12223 2. Check dpi value in X resources. It is better we use it as well,
12224 since Xft will use it, as will all Gnome applications. If our real DPI
12225 is smaller or larger than the one Xft uses, our font will look smaller
12226 or larger than other for other applications, even if it is the same
12227 font name (monospace-10 for example). */
12229 int event_base
, error_base
;
12233 XRenderQueryExtension (dpyinfo
->display
, &event_base
, &error_base
);
12235 v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
12236 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
12237 dpyinfo
->resy
= dpyinfo
->resx
= d
;
12241 if (dpyinfo
->resy
< 1)
12243 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
12244 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
12245 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
12246 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
12247 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
12248 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
12249 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
12250 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
12251 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
12255 static const struct
12260 #define ATOM_REFS_INIT(string, member) \
12261 { string, offsetof (struct x_display_info, member) },
12262 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
12263 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
12264 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
12265 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
12266 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
12267 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
12268 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
12269 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
12270 ATOM_REFS_INIT ("Editres", Xatom_editres
)
12271 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
12272 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
12273 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
12274 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
12275 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
12276 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
12277 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
12278 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
12279 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
12280 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
12281 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
12282 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
12283 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
12284 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
12285 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
12286 /* For properties of font. */
12287 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
12288 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
12289 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
12290 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
12291 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
12292 /* Ghostscript support. */
12293 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
12294 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
12295 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
12296 ATOM_REFS_INIT ("HORIZONTAL_SCROLLBAR", Xatom_Horizontal_Scrollbar
)
12297 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
12299 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
12300 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
12301 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
12302 Xatom_net_wm_state_maximized_horz
)
12303 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
12304 Xatom_net_wm_state_maximized_vert
)
12305 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
12306 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
12307 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
12308 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
12309 Xatom_net_window_type_tooltip
)
12310 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
12311 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
12312 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
12313 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
12314 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
12315 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
12316 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
12317 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
12318 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
12319 /* Session management */
12320 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
12321 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
12322 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
12326 enum { atom_count
= ARRAYELTS (atom_refs
) };
12327 /* 1 for _XSETTINGS_SN. */
12328 enum { total_atom_count
= 1 + atom_count
};
12329 Atom atoms_return
[total_atom_count
];
12330 char *atom_names
[total_atom_count
];
12331 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
12332 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
12333 + INT_STRLEN_BOUND (int)];
12335 for (i
= 0; i
< atom_count
; i
++)
12336 atom_names
[i
] = (char *) atom_refs
[i
].name
;
12338 /* Build _XSETTINGS_SN atom name. */
12339 sprintf (xsettings_atom_name
, xsettings_fmt
,
12340 XScreenNumberOfScreen (dpyinfo
->screen
));
12341 atom_names
[i
] = xsettings_atom_name
;
12343 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
12344 False
, atoms_return
);
12346 for (i
= 0; i
< atom_count
; i
++)
12347 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
12349 /* Manually copy last atom. */
12350 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
12353 dpyinfo
->x_dnd_atoms_size
= 8;
12354 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
12355 * dpyinfo
->x_dnd_atoms_size
);
12357 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12358 gray_bits
, gray_width
, gray_height
,
12361 x_setup_pointer_blanking (dpyinfo
);
12364 xim_initialize (dpyinfo
, resource_name
);
12367 xsettings_initialize (dpyinfo
);
12369 /* This is only needed for distinguishing keyboard and process input. */
12370 if (dpyinfo
->connection
!= 0)
12371 add_keyboard_wait_descriptor (dpyinfo
->connection
);
12374 fcntl (dpyinfo
->connection
, F_SETOWN
, getpid ());
12375 #endif /* ! defined (F_SETOWN) */
12377 if (interrupt_input
)
12378 init_sigio (dpyinfo
->connection
);
12382 XrmValue d
, fr
, to
;
12385 dpy
= dpyinfo
->display
;
12386 d
.addr
= (XPointer
)&dpy
;
12387 d
.size
= sizeof (Display
*);
12388 fr
.addr
= (char *) XtDefaultFont
;
12389 fr
.size
= sizeof (XtDefaultFont
);
12390 to
.size
= sizeof (Font
*);
12391 to
.addr
= (XPointer
)&font
;
12392 x_catch_errors (dpy
);
12393 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
12395 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
12396 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
12397 /* Do not free XFontStruct returned by the above call to XQueryFont.
12398 This leads to X protocol errors at XtCloseDisplay (Bug#18403). */
12399 x_uncatch_errors ();
12403 /* See if we should run in synchronous mode. This is useful
12404 for debugging X code. */
12406 AUTO_STRING (synchronous
, "synchronous");
12407 AUTO_STRING (Synchronous
, "Synchronous");
12408 Lisp_Object value
= display_x_get_resource (dpyinfo
, synchronous
,
12409 Synchronous
, Qnil
, Qnil
);
12410 if (STRINGP (value
)
12411 && (!strcmp (SSDATA (value
), "true")
12412 || !strcmp (SSDATA (value
), "on")))
12413 XSynchronize (dpyinfo
->display
, True
);
12417 AUTO_STRING (useXIM
, "useXIM");
12418 AUTO_STRING (UseXIM
, "UseXIM");
12419 Lisp_Object value
= display_x_get_resource (dpyinfo
, useXIM
, UseXIM
,
12422 if (STRINGP (value
)
12423 && (!strcmp (SSDATA (value
), "false")
12424 || !strcmp (SSDATA (value
), "off")))
12427 if (STRINGP (value
)
12428 && (!strcmp (SSDATA (value
), "true")
12429 || !strcmp (SSDATA (value
), "on")))
12435 /* Only do this for the very first display in the Emacs session.
12436 Ignore X session management when Emacs was first started on a
12437 tty or started as a daemon. */
12438 if (terminal
->id
== 1 && ! IS_DAEMON
)
12439 x_session_initialize (dpyinfo
);
12443 x_extension_initialize (dpyinfo
);
12451 /* Get rid of display DPYINFO, deleting all frames on it,
12452 and without sending any more commands to the X server. */
12455 x_delete_display (struct x_display_info
*dpyinfo
)
12457 struct terminal
*t
;
12458 struct color_name_cache_entry
*color_entry
, *next_color_entry
;
12460 /* Close all frames and delete the generic struct terminal for this
12462 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
12463 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
12466 /* Close X session management when we close its display. */
12467 if (t
->id
== 1 && x_session_have_connection ())
12468 x_session_close ();
12470 delete_terminal (t
);
12474 if (next_noop_dpyinfo
== dpyinfo
)
12475 next_noop_dpyinfo
= dpyinfo
->next
;
12477 if (x_display_list
== dpyinfo
)
12478 x_display_list
= dpyinfo
->next
;
12481 struct x_display_info
*tail
;
12483 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
12484 if (tail
->next
== dpyinfo
)
12485 tail
->next
= tail
->next
->next
;
12488 for (color_entry
= dpyinfo
->color_names
;
12490 color_entry
= next_color_entry
)
12492 next_color_entry
= color_entry
->next
;
12493 xfree (color_entry
->name
);
12494 xfree (color_entry
);
12497 xfree (dpyinfo
->x_id_name
);
12498 xfree (dpyinfo
->x_dnd_atoms
);
12499 xfree (dpyinfo
->color_cells
);
12503 #ifdef USE_X_TOOLKIT
12505 /* Atimer callback function for TIMER. Called every 0.1s to process
12506 Xt timeouts, if needed. We must avoid calling XtAppPending as
12507 much as possible because that function does an implicit XFlush
12508 that slows us down. */
12511 x_process_timeouts (struct atimer
*timer
)
12514 x_timeout_atimer_activated_flag
= false;
12515 if (toolkit_scroll_bar_interaction
|| popup_activated ())
12517 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
12518 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
12519 /* Reactivate the atimer for next time. */
12520 x_activate_timeout_atimer ();
12525 /* Install an asynchronous timer that processes Xt timeout events
12526 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
12527 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
12528 function whenever these variables are set. This is necessary
12529 because some widget sets use timeouts internally, for example the
12530 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
12531 processed, these widgets don't behave normally. */
12534 x_activate_timeout_atimer (void)
12537 if (!x_timeout_atimer_activated_flag
)
12539 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
12540 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
12541 x_timeout_atimer_activated_flag
= true;
12546 #endif /* USE_X_TOOLKIT */
12549 /* Set up use of X before we make the first connection. */
12551 static struct redisplay_interface x_redisplay_interface
=
12553 x_frame_parm_handlers
,
12557 x_clear_end_of_line
,
12559 x_after_update_window_line
,
12560 x_update_window_begin
,
12561 x_update_window_end
,
12563 x_clear_window_mouse_face
,
12564 x_get_glyph_overhangs
,
12565 x_fix_overlapping_area
,
12566 x_draw_fringe_bitmap
,
12568 x_cr_define_fringe_bitmap
,
12569 x_cr_destroy_fringe_bitmap
,
12571 0, /* define_fringe_bitmap */
12572 0, /* destroy_fringe_bitmap */
12574 x_compute_glyph_string_overhangs
,
12575 x_draw_glyph_string
,
12576 x_define_frame_cursor
,
12577 x_clear_frame_area
,
12578 x_draw_window_cursor
,
12579 x_draw_vertical_window_border
,
12580 x_draw_window_divider
,
12581 x_shift_glyphs_for_insert
, /* Never called; see comment in function. */
12587 /* This function is called when the last frame on a display is deleted. */
12589 x_delete_terminal (struct terminal
*terminal
)
12591 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
12593 /* Protect against recursive calls. delete_frame in
12594 delete_terminal calls us back when it deletes our last frame. */
12595 if (!terminal
->name
)
12600 /* We must close our connection to the XIM server before closing the
12603 xim_close_dpy (dpyinfo
);
12606 /* Normally, the display is available... */
12607 if (dpyinfo
->display
)
12609 x_destroy_all_bitmaps (dpyinfo
);
12610 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
12612 /* Whether or not XCloseDisplay destroys the associated resource
12613 database depends on the version of libX11. To avoid both
12614 crash and memory leak, we dissociate the database from the
12615 display and then destroy dpyinfo->xrdb ourselves.
12617 Unfortunately, the above strategy does not work in some
12618 situations due to a bug in newer versions of libX11: because
12619 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
12620 dpy->db is NULL, XCloseDisplay destroys the associated
12621 database whereas it has not been created by XGetDefault
12622 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
12623 don't destroy the database here in order to avoid the crash
12624 in the above situations for now, though that may cause memory
12625 leaks in other situations. */
12627 #ifdef HAVE_XRMSETDATABASE
12628 XrmSetDatabase (dpyinfo
->display
, NULL
);
12630 dpyinfo
->display
->db
= NULL
;
12632 /* We used to call XrmDestroyDatabase from x_delete_display, but
12633 some older versions of libX11 crash if we call it after
12634 closing all the displays. */
12635 XrmDestroyDatabase (dpyinfo
->xrdb
);
12639 xg_display_close (dpyinfo
->display
);
12641 #ifdef USE_X_TOOLKIT
12642 XtCloseDisplay (dpyinfo
->display
);
12644 XCloseDisplay (dpyinfo
->display
);
12646 #endif /* ! USE_GTK */
12647 /* Do not close the connection here because it's already closed
12648 by X(t)CloseDisplay (Bug#18403). */
12649 dpyinfo
->display
= NULL
;
12652 /* ...but if called from x_connection_closed, the display may already
12653 be closed and dpyinfo->display was set to 0 to indicate that. Since
12654 X server is most likely gone, explicit close is the only reliable
12655 way to continue and avoid Bug#19147. */
12656 else if (dpyinfo
->connection
>= 0)
12657 emacs_close (dpyinfo
->connection
);
12659 /* No more input on this descriptor. */
12660 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
12661 /* Mark as dead. */
12662 dpyinfo
->connection
= -1;
12664 x_delete_display (dpyinfo
);
12668 /* Create a struct terminal, initialize it with the X11 specific
12669 functions and make DISPLAY->TERMINAL point to it. */
12671 static struct terminal
*
12672 x_create_terminal (struct x_display_info
*dpyinfo
)
12674 struct terminal
*terminal
;
12676 terminal
= create_terminal (output_x_window
, &x_redisplay_interface
);
12678 terminal
->display_info
.x
= dpyinfo
;
12679 dpyinfo
->terminal
= terminal
;
12681 /* kboard is initialized in x_term_init. */
12683 terminal
->clear_frame_hook
= x_clear_frame
;
12684 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
12685 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
12686 terminal
->ring_bell_hook
= XTring_bell
;
12687 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
12688 terminal
->update_begin_hook
= x_update_begin
;
12689 terminal
->update_end_hook
= x_update_end
;
12690 terminal
->read_socket_hook
= XTread_socket
;
12691 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
12692 terminal
->buffer_flipping_unblocked_hook
= XTbuffer_flipping_unblocked_hook
;
12693 terminal
->mouse_position_hook
= XTmouse_position
;
12694 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
12695 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
12696 terminal
->fullscreen_hook
= XTfullscreen_hook
;
12697 terminal
->menu_show_hook
= x_menu_show
;
12698 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
12699 terminal
->popup_dialog_hook
= xw_popup_dialog
;
12701 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
12702 terminal
->set_horizontal_scroll_bar_hook
= XTset_horizontal_scroll_bar
;
12703 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
12704 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
12705 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
12706 terminal
->delete_frame_hook
= x_destroy_window
;
12707 terminal
->delete_terminal_hook
= x_delete_terminal
;
12708 /* Other hooks are NULL by default. */
12714 x_initialize (void)
12719 any_help_event_p
= false;
12720 ignore_next_mouse_click_timeout
= 0;
12723 current_count
= -1;
12726 /* Try to use interrupt input; if we can't, then start polling. */
12727 Fset_input_interrupt_mode (Qt
);
12729 #if THREADS_ENABLED
12730 /* This must be called before any other Xlib routines. */
12731 if (XInitThreads () == 0)
12733 "Warning: An error occurred initializing X11 thread support!\n");
12736 #ifdef USE_X_TOOLKIT
12737 XtToolkitInitialize ();
12739 Xt_app_con
= XtCreateApplicationContext ();
12741 /* Register a converter from strings to pixels, which uses
12742 Emacs' color allocation infrastructure. */
12743 XtAppSetTypeConverter (Xt_app_con
,
12744 XtRString
, XtRPixel
, cvt_string_to_pixel
,
12745 cvt_string_to_pixel_args
,
12746 XtNumber (cvt_string_to_pixel_args
),
12747 XtCacheByDisplay
, cvt_pixel_dtor
);
12749 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
12752 #ifdef USE_TOOLKIT_SCROLL_BARS
12754 xaw3d_arrow_scroll
= False
;
12755 xaw3d_pick_top
= True
;
12760 x_cr_init_fringe (&x_redisplay_interface
);
12763 /* Note that there is no real way portable across R3/R4 to get the
12764 original error handler. */
12765 XSetErrorHandler (x_error_handler
);
12766 XSetIOErrorHandler (x_io_error_quitter
);
12773 /* Emacs can handle only core input events, so make sure
12774 Gtk doesn't use Xinput or Xinput2 extensions. */
12775 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
12780 syms_of_xterm (void)
12782 x_error_message
= NULL
;
12784 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
12785 DEFSYM (Qlatin_1
, "latin-1");
12788 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
12789 staticpro (&xg_default_icon_file
);
12791 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
12794 DEFVAR_BOOL ("x-use-underline-position-properties",
12795 x_use_underline_position_properties
,
12796 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
12797 A value of nil means ignore them. If you encounter fonts with bogus
12798 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
12799 to 4.1, set this to nil. You can also use `underline-minimum-offset'
12800 to override the font's UNDERLINE_POSITION for small font display
12802 x_use_underline_position_properties
= true;
12804 DEFVAR_BOOL ("x-underline-at-descent-line",
12805 x_underline_at_descent_line
,
12806 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
12807 A value of nil means to draw the underline according to the value of the
12808 variable `x-use-underline-position-properties', which is usually at the
12809 baseline level. The default value is nil. */);
12810 x_underline_at_descent_line
= false;
12812 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
12813 x_mouse_click_focus_ignore_position
,
12814 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
12815 This variable is only used when the window manager requires that you
12816 click on a frame to select it (give it focus). In that case, a value
12817 of nil, means that the selected window and cursor position changes to
12818 reflect the mouse click position, while a non-nil value means that the
12819 selected window or cursor position is preserved. */);
12820 x_mouse_click_focus_ignore_position
= false;
12822 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
12823 doc
: /* Which toolkit scroll bars Emacs uses, if any.
12824 A value of nil means Emacs doesn't use toolkit scroll bars.
12825 With the X Window system, the value is a symbol describing the
12826 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
12827 With MS Windows or Nextstep, the value is t. */);
12828 #ifdef USE_TOOLKIT_SCROLL_BARS
12830 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
12831 #elif defined HAVE_XAW3D
12832 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
12834 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
12836 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
12839 Vx_toolkit_scroll_bars
= Qnil
;
12842 DEFSYM (Qmodifier_value
, "modifier-value");
12843 DEFSYM (Qctrl
, "ctrl");
12844 Fput (Qctrl
, Qmodifier_value
, make_number (ctrl_modifier
));
12845 DEFSYM (Qalt
, "alt");
12846 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
12847 DEFSYM (Qhyper
, "hyper");
12848 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
12849 DEFSYM (Qmeta
, "meta");
12850 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
12851 DEFSYM (Qsuper
, "super");
12852 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
12854 DEFVAR_LISP ("x-ctrl-keysym", Vx_ctrl_keysym
,
12855 doc
: /* Which keys Emacs uses for the ctrl modifier.
12856 This should be one of the symbols `ctrl', `alt', `hyper', `meta',
12857 `super'. For example, `ctrl' means use the Ctrl_L and Ctrl_R keysyms.
12858 The default is nil, which is the same as `ctrl'. */);
12859 Vx_ctrl_keysym
= Qnil
;
12861 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
12862 doc
: /* Which keys Emacs uses for the alt modifier.
12863 This should be one of the symbols `ctrl', `alt', `hyper', `meta',
12864 `super'. For example, `alt' means use the Alt_L and Alt_R keysyms.
12865 The default is nil, which is the same as `alt'. */);
12866 Vx_alt_keysym
= Qnil
;
12868 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
12869 doc
: /* Which keys Emacs uses for the hyper modifier.
12870 This should be one of the symbols `ctrl', `alt', `hyper', `meta',
12871 `super'. For example, `hyper' means use the Hyper_L and Hyper_R
12872 keysyms. The default is nil, which is the same as `hyper'. */);
12873 Vx_hyper_keysym
= Qnil
;
12875 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
12876 doc
: /* Which keys Emacs uses for the meta modifier.
12877 This should be one of the symbols `ctrl', `alt', `hyper', `meta',
12878 `super'. For example, `meta' means use the Meta_L and Meta_R keysyms.
12879 The default is nil, which is the same as `meta'. */);
12880 Vx_meta_keysym
= Qnil
;
12882 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
12883 doc
: /* Which keys Emacs uses for the super modifier.
12884 This should be one of the symbols `ctrl', `alt', `hyper', `meta',
12885 `super'. For example, `super' means use the Super_L and Super_R
12886 keysyms. The default is nil, which is the same as `super'. */);
12887 Vx_super_keysym
= Qnil
;
12889 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
12890 doc
: /* Hash table of character codes indexed by X keysym codes. */);
12891 Vx_keysym_table
= make_hash_table (hashtest_eql
, 900,
12892 DEFAULT_REHASH_SIZE
,
12893 DEFAULT_REHASH_THRESHOLD
,
12896 DEFVAR_BOOL ("x-frame-normalize-before-maximize",
12897 x_frame_normalize_before_maximize
,
12898 doc
: /* Non-nil means normalize frame before maximizing.
12899 If this variable is t, Emacs first asks the window manager to give the
12900 frame its normal size, and only then the final state, whenever changing
12901 from a full-height, full-width or full-both state to the maximized one
12902 or when changing from the maximized to the full-height or full-width
12905 Set this variable only if your window manager cannot handle the
12906 transition between the various maximization states. */);
12907 x_frame_normalize_before_maximize
= false;