1 /* X Communication module for terminals which understand the X protocol.
3 Copyright (C) 1989, 1993-2016 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
10 (at 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. */
30 #include "blockinput.h"
32 /* This may include sys/types.h, and that somehow loses
33 if this is not done before the other system files. */
35 #include <X11/cursorfont.h>
37 /* If we have Xfixes extension, use it for pointer blanking. */
39 #include <X11/extensions/Xfixes.h>
42 /* Using Xft implies that XRender is available. */
44 #include <X11/extensions/Xrender.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
53 #include <sys/ioctl.h>
60 #include "character.h"
62 #include "composite.h"
64 #include "dispextern.h"
69 #include "termhooks.h"
72 #include "emacs-icon.h"
78 #include "xsettings.h"
79 #include "sysselect.h"
83 #include <X11/Shell.h>
91 #include <X11/Xproto.h>
95 #if defined (USE_LUCID) || defined (USE_MOTIF)
96 #include "../lwlib/xlwmenu.h"
100 #if !defined (NO_EDITRES)
102 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
103 #endif /* not NO_EDITRES */
105 /* Include toolkit specific headers for the scroll bar widget. */
107 #ifdef USE_TOOLKIT_SCROLL_BARS
108 #if defined USE_MOTIF
109 #include <Xm/Xm.h> /* For LESSTIF_VERSION */
110 #include <Xm/ScrollBar.h>
111 #else /* !USE_MOTIF i.e. use Xaw */
114 #include <X11/Xaw3d/Simple.h>
115 #include <X11/Xaw3d/Scrollbar.h>
116 #include <X11/Xaw3d/ThreeD.h>
117 #else /* !HAVE_XAW3D */
118 #include <X11/Xaw/Simple.h>
119 #include <X11/Xaw/Scrollbar.h>
120 #endif /* !HAVE_XAW3D */
122 #define XtNpickTop "pickTop"
123 #endif /* !XtNpickTop */
124 #endif /* !USE_MOTIF */
125 #endif /* USE_TOOLKIT_SCROLL_BARS */
127 #endif /* USE_X_TOOLKIT */
131 #ifndef XtNinitialState
132 #define XtNinitialState "initialState"
136 #include "bitmaps/gray.xbm"
139 #include <X11/XKBlib.h>
142 /* Default to using XIM if available. */
146 bool use_xim
= false; /* configure --without-xim */
149 /* Non-zero means that a HELP_EVENT has been generated since Emacs
152 static bool any_help_event_p
;
154 /* This is a chain of structures for all the X displays currently in
157 struct x_display_info
*x_display_list
;
161 /* The application context for Xt use. */
162 XtAppContext Xt_app_con
;
163 static String Xt_default_resources
[] = {0};
165 /* Non-zero means user is interacting with a toolkit scroll bar. */
166 static bool toolkit_scroll_bar_interaction
;
168 #endif /* USE_X_TOOLKIT */
170 /* Non-zero timeout value means ignore next mouse click if it arrives
171 before that timeout elapses (i.e. as part of the same sequence of
172 events resulting from clicking on a frame to select it). */
174 static Time ignore_next_mouse_click_timeout
;
176 /* Used locally within XTread_socket. */
178 static int x_noop_count
;
181 /* The name of the Emacs icon file. */
182 static Lisp_Object xg_default_icon_file
;
185 /* Some functions take this as char *, not const char *. */
186 static char emacs_class
[] = EMACS_CLASS
;
190 XEMBED_MAPPED
= 1 << 0
195 XEMBED_EMBEDDED_NOTIFY
= 0,
196 XEMBED_WINDOW_ACTIVATE
= 1,
197 XEMBED_WINDOW_DEACTIVATE
= 2,
198 XEMBED_REQUEST_FOCUS
= 3,
200 XEMBED_FOCUS_OUT
= 5,
201 XEMBED_FOCUS_NEXT
= 6,
202 XEMBED_FOCUS_PREV
= 7,
204 XEMBED_MODALITY_ON
= 10,
205 XEMBED_MODALITY_OFF
= 11,
206 XEMBED_REGISTER_ACCELERATOR
= 12,
207 XEMBED_UNREGISTER_ACCELERATOR
= 13,
208 XEMBED_ACTIVATE_ACCELERATOR
= 14
211 static void x_free_cr_resources (struct frame
*);
212 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
213 static void x_raise_frame (struct frame
*);
214 static void x_lower_frame (struct frame
*);
215 static int x_io_error_quitter (Display
*);
216 static struct terminal
*x_create_terminal (struct x_display_info
*);
217 static void x_frame_rehighlight (struct x_display_info
*);
219 static void x_clip_to_row (struct window
*, struct glyph_row
*,
220 enum glyph_row_area
, GC
);
221 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
, int);
222 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
223 enum scroll_bar_part
*,
224 Lisp_Object
*, Lisp_Object
*,
226 static void x_horizontal_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
227 enum scroll_bar_part
*,
228 Lisp_Object
*, Lisp_Object
*,
230 static bool x_handle_net_wm_state (struct frame
*, const XPropertyEvent
*);
231 static void x_check_fullscreen (struct frame
*);
232 static void x_check_expected_move (struct frame
*, int, int);
233 static void x_sync_with_move (struct frame
*, int, int, bool);
234 static int handle_one_xevent (struct x_display_info
*,
235 const XEvent
*, int *,
236 struct input_event
*);
237 #if ! (defined USE_X_TOOLKIT || defined USE_MOTIF)
238 static int x_dispatch_event (XEvent
*, Display
*);
240 static void x_wm_set_window_state (struct frame
*, int);
241 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
242 static void x_initialize (void);
244 static bool get_current_wm_state (struct frame
*, Window
, int *, bool *);
246 /* Flush display of frame F. */
249 x_flush (struct frame
*f
)
251 eassert (f
&& FRAME_X_P (f
));
252 /* Don't call XFlush when it is not safe to redisplay; the X
253 connection may be broken. */
254 if (!NILP (Vinhibit_redisplay
))
258 XFlush (FRAME_X_DISPLAY (f
));
263 /* Remove calls to XFlush by defining XFlush to an empty replacement.
264 Calls to XFlush should be unnecessary because the X output buffer
265 is flushed automatically as needed by calls to XPending,
266 XNextEvent, or XWindowEvent according to the XFlush man page.
267 XTread_socket calls XPending. Removing XFlush improves
270 #define XFlush(DISPLAY) (void) 0
273 /***********************************************************************
275 ***********************************************************************/
279 /* This is a function useful for recording debugging information about
280 the sequence of occurrences in this file. */
288 struct record event_record
[100];
290 int event_record_index
;
293 record_event (char *locus
, int type
)
295 if (event_record_index
== ARRAYELTS (event_record
))
296 event_record_index
= 0;
298 event_record
[event_record_index
].locus
= locus
;
299 event_record
[event_record_index
].type
= type
;
300 event_record_index
++;
307 #define FRAME_CR_CONTEXT(f) ((f)->output_data.x->cr_context)
308 #define FRAME_CR_SURFACE(f) ((f)->output_data.x->cr_surface)
310 static struct x_gc_ext_data
*
311 x_gc_get_ext_data (struct frame
*f
, GC gc
, int create_if_not_found_p
)
313 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
315 XExtData
**head
, *ext_data
;
318 head
= XEHeadOfExtensionList (object
);
319 ext_data
= XFindOnExtensionList (head
, dpyinfo
->ext_codes
->extension
);
320 if (ext_data
== NULL
)
322 if (!create_if_not_found_p
)
326 ext_data
= xzalloc (sizeof (*ext_data
));
327 ext_data
->number
= dpyinfo
->ext_codes
->extension
;
328 ext_data
->private_data
= xzalloc (sizeof (struct x_gc_ext_data
));
329 XAddToExtensionList (head
, ext_data
);
332 return (struct x_gc_ext_data
*) ext_data
->private_data
;
336 x_extension_initialize (struct x_display_info
*dpyinfo
)
338 XExtCodes
*ext_codes
= XAddExtension (dpyinfo
->display
);
340 dpyinfo
->ext_codes
= ext_codes
;
344 x_cr_destroy_surface (struct frame
*f
)
346 if (FRAME_CR_SURFACE (f
))
348 cairo_t
*cr
= FRAME_CR_CONTEXT (f
);
349 cairo_surface_destroy (FRAME_CR_SURFACE (f
));
350 FRAME_CR_SURFACE (f
) = 0;
351 if (cr
) cairo_destroy (cr
);
352 FRAME_CR_CONTEXT (f
) = NULL
;
357 x_begin_cr_clip (struct frame
*f
, GC gc
)
359 cairo_t
*cr
= FRAME_CR_CONTEXT (f
);
364 if (! FRAME_CR_SURFACE (f
))
366 cairo_surface_t
*surface
;
367 surface
= cairo_xlib_surface_create (FRAME_X_DISPLAY (f
),
369 FRAME_DISPLAY_INFO (f
)->visual
,
370 FRAME_PIXEL_WIDTH (f
),
371 FRAME_PIXEL_HEIGHT (f
));
372 cr
= cairo_create (surface
);
373 cairo_surface_destroy (surface
);
376 cr
= cairo_create (FRAME_CR_SURFACE (f
));
377 FRAME_CR_CONTEXT (f
) = cr
;
383 struct x_gc_ext_data
*gc_ext
= x_gc_get_ext_data (f
, gc
, 0);
385 if (gc_ext
&& gc_ext
->n_clip_rects
)
389 for (i
= 0; i
< gc_ext
->n_clip_rects
; i
++)
390 cairo_rectangle (cr
, gc_ext
->clip_rects
[i
].x
,
391 gc_ext
->clip_rects
[i
].y
,
392 gc_ext
->clip_rects
[i
].width
,
393 gc_ext
->clip_rects
[i
].height
);
402 x_end_cr_clip (struct frame
*f
)
404 cairo_restore (FRAME_CR_CONTEXT (f
));
408 x_set_cr_source_with_gc_foreground (struct frame
*f
, GC gc
)
413 XGetGCValues (FRAME_X_DISPLAY (f
), gc
, GCForeground
, &xgcv
);
414 color
.pixel
= xgcv
.foreground
;
415 x_query_color (f
, &color
);
416 cairo_set_source_rgb (FRAME_CR_CONTEXT (f
), color
.red
/ 65535.0,
417 color
.green
/ 65535.0, color
.blue
/ 65535.0);
421 x_set_cr_source_with_gc_background (struct frame
*f
, GC gc
)
426 XGetGCValues (FRAME_X_DISPLAY (f
), gc
, GCBackground
, &xgcv
);
427 color
.pixel
= xgcv
.background
;
428 x_query_color (f
, &color
);
429 cairo_set_source_rgb (FRAME_CR_CONTEXT (f
), color
.red
/ 65535.0,
430 color
.green
/ 65535.0, color
.blue
/ 65535.0);
433 /* Fringe bitmaps. */
435 static int max_fringe_bmp
= 0;
436 static cairo_pattern_t
**fringe_bmp
= 0;
439 x_cr_define_fringe_bitmap (int which
, unsigned short *bits
, int h
, int wd
)
442 cairo_surface_t
*surface
;
444 cairo_pattern_t
*pattern
;
446 if (which
>= max_fringe_bmp
)
449 max_fringe_bmp
= which
+ 20;
450 fringe_bmp
= (cairo_pattern_t
**) xrealloc (fringe_bmp
, max_fringe_bmp
* sizeof (cairo_pattern_t
*));
451 while (i
< max_fringe_bmp
)
457 surface
= cairo_image_surface_create (CAIRO_FORMAT_A1
, wd
, h
);
458 stride
= cairo_image_surface_get_stride (surface
);
459 data
= cairo_image_surface_get_data (surface
);
461 for (i
= 0; i
< h
; i
++)
463 *((unsigned short *) data
) = bits
[i
];
467 cairo_surface_mark_dirty (surface
);
468 pattern
= cairo_pattern_create_for_surface (surface
);
469 cairo_surface_destroy (surface
);
473 fringe_bmp
[which
] = pattern
;
477 x_cr_destroy_fringe_bitmap (int which
)
479 if (which
>= max_fringe_bmp
)
482 if (fringe_bmp
[which
])
485 cairo_pattern_destroy (fringe_bmp
[which
]);
488 fringe_bmp
[which
] = 0;
492 x_cr_draw_image (struct frame
*f
, GC gc
, cairo_pattern_t
*image
,
493 int src_x
, int src_y
, int width
, int height
,
494 int dest_x
, int dest_y
, bool overlay_p
)
497 cairo_matrix_t matrix
;
498 cairo_surface_t
*surface
;
499 cairo_format_t format
;
501 cr
= x_begin_cr_clip (f
, gc
);
503 cairo_rectangle (cr
, dest_x
, dest_y
, width
, height
);
506 x_set_cr_source_with_gc_background (f
, gc
);
507 cairo_rectangle (cr
, dest_x
, dest_y
, width
, height
);
508 cairo_fill_preserve (cr
);
511 cairo_matrix_init_translate (&matrix
, src_x
- dest_x
, src_y
- dest_y
);
512 cairo_pattern_set_matrix (image
, &matrix
);
513 cairo_pattern_get_surface (image
, &surface
);
514 format
= cairo_image_surface_get_format (surface
);
515 if (format
!= CAIRO_FORMAT_A8
&& format
!= CAIRO_FORMAT_A1
)
517 cairo_set_source (cr
, image
);
522 x_set_cr_source_with_gc_foreground (f
, gc
);
523 cairo_mask (cr
, image
);
529 x_cr_draw_frame (cairo_t
*cr
, struct frame
*f
)
533 width
= FRAME_PIXEL_WIDTH (f
);
534 height
= FRAME_PIXEL_HEIGHT (f
);
536 x_free_cr_resources (f
);
537 FRAME_CR_CONTEXT (f
) = cr
;
538 x_clear_area (f
, 0, 0, width
, height
);
539 expose_frame (f
, 0, 0, width
, height
);
540 FRAME_CR_CONTEXT (f
) = NULL
;
543 static cairo_status_t
544 x_cr_accumulate_data (void *closure
, const unsigned char *data
,
547 Lisp_Object
*acc
= (Lisp_Object
*) closure
;
549 *acc
= Fcons (make_unibyte_string ((char const *) data
, length
), *acc
);
551 return CAIRO_STATUS_SUCCESS
;
555 x_cr_destroy (Lisp_Object arg
)
557 cairo_t
*cr
= (cairo_t
*) XSAVE_POINTER (arg
, 0);
565 x_cr_export_frames (Lisp_Object frames
, cairo_surface_type_t surface_type
)
568 cairo_surface_t
*surface
;
571 void (*surface_set_size_func
) (cairo_surface_t
*, double, double) = NULL
;
572 Lisp_Object acc
= Qnil
;
573 int count
= SPECPDL_INDEX ();
575 specbind (Qredisplay_dont_pause
, Qt
);
576 redisplay_preserve_echo_area (31);
578 f
= XFRAME (XCAR (frames
));
579 frames
= XCDR (frames
);
580 width
= FRAME_PIXEL_WIDTH (f
);
581 height
= FRAME_PIXEL_HEIGHT (f
);
584 #ifdef CAIRO_HAS_PDF_SURFACE
585 if (surface_type
== CAIRO_SURFACE_TYPE_PDF
)
587 surface
= cairo_pdf_surface_create_for_stream (x_cr_accumulate_data
, &acc
,
589 surface_set_size_func
= cairo_pdf_surface_set_size
;
593 #ifdef CAIRO_HAS_PNG_FUNCTIONS
594 if (surface_type
== CAIRO_SURFACE_TYPE_IMAGE
)
595 surface
= cairo_image_surface_create (CAIRO_FORMAT_RGB24
, width
, height
);
598 #ifdef CAIRO_HAS_PS_SURFACE
599 if (surface_type
== CAIRO_SURFACE_TYPE_PS
)
601 surface
= cairo_ps_surface_create_for_stream (x_cr_accumulate_data
, &acc
,
603 surface_set_size_func
= cairo_ps_surface_set_size
;
607 #ifdef CAIRO_HAS_SVG_SURFACE
608 if (surface_type
== CAIRO_SURFACE_TYPE_SVG
)
609 surface
= cairo_svg_surface_create_for_stream (x_cr_accumulate_data
, &acc
,
615 cr
= cairo_create (surface
);
616 cairo_surface_destroy (surface
);
617 record_unwind_protect (x_cr_destroy
, make_save_ptr (cr
));
621 x_free_cr_resources (f
);
622 FRAME_CR_CONTEXT (f
) = cr
;
623 x_clear_area (f
, 0, 0, width
, height
);
624 expose_frame (f
, 0, 0, width
, height
);
625 FRAME_CR_CONTEXT (f
) = NULL
;
630 cairo_surface_show_page (surface
);
631 f
= XFRAME (XCAR (frames
));
632 frames
= XCDR (frames
);
633 width
= FRAME_PIXEL_WIDTH (f
);
634 height
= FRAME_PIXEL_HEIGHT (f
);
635 if (surface_set_size_func
)
636 (*surface_set_size_func
) (surface
, width
, height
);
643 #ifdef CAIRO_HAS_PNG_FUNCTIONS
644 if (surface_type
== CAIRO_SURFACE_TYPE_IMAGE
)
646 cairo_surface_flush (surface
);
647 cairo_surface_write_to_png_stream (surface
, x_cr_accumulate_data
, &acc
);
652 unbind_to (count
, Qnil
);
654 return CALLN (Fapply
, intern ("concat"), Fnreverse (acc
));
657 #endif /* USE_CAIRO */
660 x_free_cr_resources (struct frame
*f
)
665 Lisp_Object rest
, frame
;
666 FOR_EACH_FRAME (rest
, frame
)
667 if (FRAME_X_P (XFRAME (frame
)))
668 x_free_cr_resources (XFRAME (frame
));
672 cairo_t
*cr
= FRAME_CR_CONTEXT (f
);
676 cairo_surface_t
*surface
= cairo_get_target (cr
);
678 if (cairo_surface_get_type (surface
) == CAIRO_SURFACE_TYPE_XLIB
)
681 FRAME_CR_CONTEXT (f
) = NULL
;
689 x_set_clip_rectangles (struct frame
*f
, GC gc
, XRectangle
*rectangles
, int n
)
691 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, rectangles
, n
, Unsorted
);
693 eassert (n
>= 0 && n
<= MAX_CLIP_RECTS
);
696 struct x_gc_ext_data
*gc_ext
= x_gc_get_ext_data (f
, gc
, 1);
698 gc_ext
->n_clip_rects
= n
;
699 memcpy (gc_ext
->clip_rects
, rectangles
, sizeof (XRectangle
) * n
);
705 x_reset_clip_rectangles (struct frame
*f
, GC gc
)
707 XSetClipMask (FRAME_X_DISPLAY (f
), gc
, None
);
710 struct x_gc_ext_data
*gc_ext
= x_gc_get_ext_data (f
, gc
, 0);
713 gc_ext
->n_clip_rects
= 0;
719 x_fill_rectangle (struct frame
*f
, GC gc
, int x
, int y
, int width
, int height
)
724 cr
= x_begin_cr_clip (f
, gc
);
725 x_set_cr_source_with_gc_foreground (f
, gc
);
726 cairo_rectangle (cr
, x
, y
, width
, height
);
730 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
731 gc
, x
, y
, width
, height
);
736 x_draw_rectangle (struct frame
*f
, GC gc
, int x
, int y
, int width
, int height
)
741 cr
= x_begin_cr_clip (f
, gc
);
742 x_set_cr_source_with_gc_foreground (f
, gc
);
743 cairo_rectangle (cr
, x
+ 0.5, y
+ 0.5, width
, height
);
744 cairo_set_line_width (cr
, 1);
748 XDrawRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
749 gc
, x
, y
, width
, height
);
754 x_clear_window (struct frame
*f
)
759 cr
= x_begin_cr_clip (f
, NULL
);
760 x_set_cr_source_with_gc_background (f
, f
->output_data
.x
->normal_gc
);
764 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
770 x_fill_trapezoid_for_relief (struct frame
*f
, GC gc
, int x
, int y
,
771 int width
, int height
, int top_p
)
775 cr
= x_begin_cr_clip (f
, gc
);
776 x_set_cr_source_with_gc_foreground (f
, gc
);
777 cairo_move_to (cr
, top_p
? x
: x
+ height
, y
);
778 cairo_line_to (cr
, x
, y
+ height
);
779 cairo_line_to (cr
, top_p
? x
+ width
- height
: x
+ width
, y
+ height
);
780 cairo_line_to (cr
, x
+ width
, y
);
787 CORNER_BOTTOM_RIGHT
, /* 0 -> pi/2 */
788 CORNER_BOTTOM_LEFT
, /* pi/2 -> pi */
789 CORNER_TOP_LEFT
, /* pi -> 3pi/2 */
790 CORNER_TOP_RIGHT
, /* 3pi/2 -> 2pi */
795 x_erase_corners_for_relief (struct frame
*f
, GC gc
, int x
, int y
,
796 int width
, int height
,
797 double radius
, double margin
, int corners
)
802 cr
= x_begin_cr_clip (f
, gc
);
803 x_set_cr_source_with_gc_background (f
, gc
);
804 for (i
= 0; i
< CORNER_LAST
; i
++)
805 if (corners
& (1 << i
))
807 double xm
, ym
, xc
, yc
;
809 if (i
== CORNER_TOP_LEFT
|| i
== CORNER_BOTTOM_LEFT
)
810 xm
= x
- margin
, xc
= xm
+ radius
;
812 xm
= x
+ width
+ margin
, xc
= xm
- radius
;
813 if (i
== CORNER_TOP_LEFT
|| i
== CORNER_TOP_RIGHT
)
814 ym
= y
- margin
, yc
= ym
+ radius
;
816 ym
= y
+ height
+ margin
, yc
= ym
- radius
;
818 cairo_move_to (cr
, xm
, ym
);
819 cairo_arc (cr
, xc
, yc
, radius
, i
* M_PI_2
, (i
+ 1) * M_PI_2
);
822 cairo_rectangle (cr
, x
, y
, width
, height
);
828 x_draw_horizontal_wave (struct frame
*f
, GC gc
, int x
, int y
,
829 int width
, int height
, int wave_length
)
832 double dx
= wave_length
, dy
= height
- 1;
835 cr
= x_begin_cr_clip (f
, gc
);
836 x_set_cr_source_with_gc_foreground (f
, gc
);
837 cairo_rectangle (cr
, x
, y
, width
, height
);
842 xoffset
= x
% (wave_length
* 2);
844 xoffset
= wave_length
* 2;
847 xoffset
= x
% (wave_length
* 2) + wave_length
* 2;
848 n
= (width
+ xoffset
) / wave_length
+ 1;
849 if (xoffset
> wave_length
)
851 xoffset
-= wave_length
;
857 cairo_move_to (cr
, x
- xoffset
+ 0.5, y
+ 0.5);
860 cairo_rel_line_to (cr
, dx
, dy
);
863 cairo_set_line_width (cr
, 1);
870 /* Return the struct x_display_info corresponding to DPY. */
872 struct x_display_info
*
873 x_display_info_for_display (Display
*dpy
)
875 struct x_display_info
*dpyinfo
;
877 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
878 if (dpyinfo
->display
== dpy
)
885 x_find_topmost_parent (struct frame
*f
)
887 struct x_output
*x
= f
->output_data
.x
;
888 Window win
= None
, wi
= x
->parent_desc
;
889 Display
*dpy
= FRAME_X_DISPLAY (f
);
891 while (wi
!= FRAME_DISPLAY_INFO (f
)->root_window
)
895 unsigned int nchildren
;
898 if (XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
))
907 #define OPAQUE 0xffffffff
910 x_set_frame_alpha (struct frame
*f
)
912 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
913 Display
*dpy
= FRAME_X_DISPLAY (f
);
914 Window win
= FRAME_OUTER_WINDOW (f
);
916 double alpha_min
= 1.0;
920 if (dpyinfo
->x_highlight_frame
== f
)
925 if (FLOATP (Vframe_alpha_lower_limit
))
926 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
927 else if (INTEGERP (Vframe_alpha_lower_limit
))
928 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
932 else if (alpha
> 1.0)
934 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
937 opac
= alpha
* OPAQUE
;
939 x_catch_errors (dpy
);
941 /* If there is a parent from the window manager, put the property there
942 also, to work around broken window managers that fail to do that.
943 Do this unconditionally as this function is called on reparent when
944 alpha has not changed on the frame. */
946 parent
= x_find_topmost_parent (f
);
948 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
949 XA_CARDINAL
, 32, PropModeReplace
,
950 (unsigned char *) &opac
, 1);
952 /* return unless necessary */
957 unsigned long n
, left
;
959 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
960 0, 1, False
, XA_CARDINAL
,
961 &actual
, &format
, &n
, &left
,
964 if (rc
== Success
&& actual
!= None
)
966 unsigned long value
= *(unsigned long *)data
;
976 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
977 XA_CARDINAL
, 32, PropModeReplace
,
978 (unsigned char *) &opac
, 1);
982 /***********************************************************************
983 Starting and ending an update
984 ***********************************************************************/
986 /* Start an update of frame F. This function is installed as a hook
987 for update_begin, i.e. it is called when update_begin is called.
988 This function is called prior to calls to x_update_window_begin for
989 each window being updated. Currently, there is nothing to do here
990 because all interesting stuff is done on a window basis. */
993 x_update_begin (struct frame
*f
)
996 if (! NILP (tip_frame
) && XFRAME (tip_frame
) == f
997 && ! FRAME_VISIBLE_P (f
))
1000 if (! FRAME_CR_SURFACE (f
))
1004 if (FRAME_GTK_WIDGET (f
))
1006 GdkWindow
*w
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
1007 width
= gdk_window_get_width (w
);
1008 height
= gdk_window_get_height (w
);
1013 width
= FRAME_PIXEL_WIDTH (f
);
1014 height
= FRAME_PIXEL_HEIGHT (f
);
1015 if (! FRAME_EXTERNAL_TOOL_BAR (f
))
1016 height
+= FRAME_TOOL_BAR_HEIGHT (f
);
1017 if (! FRAME_EXTERNAL_MENU_BAR (f
))
1018 height
+= FRAME_MENU_BAR_HEIGHT (f
);
1021 if (width
> 0 && height
> 0)
1024 FRAME_CR_SURFACE (f
) = cairo_image_surface_create
1025 (CAIRO_FORMAT_ARGB32
, width
, height
);
1029 #endif /* USE_CAIRO */
1032 /* Start update of window W. */
1035 x_update_window_begin (struct window
*w
)
1037 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1038 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
1040 w
->output_cursor
= w
->cursor
;
1044 if (f
== hlinfo
->mouse_face_mouse_frame
)
1046 /* Don't do highlighting for mouse motion during the update. */
1047 hlinfo
->mouse_face_defer
= true;
1049 /* If F needs to be redrawn, simply forget about any prior mouse
1051 if (FRAME_GARBAGED_P (f
))
1052 hlinfo
->mouse_face_window
= Qnil
;
1059 /* Draw a vertical window border from (x,y0) to (x,y1) */
1062 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
1064 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1067 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
1069 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
1073 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
, x
, y0
, 1, y1
- y0
);
1075 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
1076 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
1080 /* Draw a window divider from (x0,y0) to (x1,y1) */
1083 x_draw_window_divider (struct window
*w
, int x0
, int x1
, int y0
, int y1
)
1085 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1086 struct face
*face
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FACE_ID
);
1087 struct face
*face_first
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
1088 struct face
*face_last
= FACE_FROM_ID (f
, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
1089 unsigned long color
= face
? face
->foreground
: FRAME_FOREGROUND_PIXEL (f
);
1090 unsigned long color_first
= (face_first
1091 ? face_first
->foreground
1092 : FRAME_FOREGROUND_PIXEL (f
));
1093 unsigned long color_last
= (face_last
1094 ? face_last
->foreground
1095 : FRAME_FOREGROUND_PIXEL (f
));
1096 Display
*display
= FRAME_X_DISPLAY (f
);
1098 if (y1
- y0
> x1
- x0
&& x1
- x0
> 2)
1101 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_first
);
1102 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1103 x0
, y0
, 1, y1
- y0
);
1104 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
1105 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1106 x0
+ 1, y0
, x1
- x0
- 2, y1
- y0
);
1107 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_last
);
1108 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1109 x1
- 1, y0
, 1, y1
- y0
);
1111 else if (x1
- x0
> y1
- y0
&& y1
- y0
> 3)
1114 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_first
);
1115 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1116 x0
, y0
, x1
- x0
, 1);
1117 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
1118 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1119 x0
, y0
+ 1, x1
- x0
, y1
- y0
- 2);
1120 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_last
);
1121 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1122 x0
, y1
- 1, x1
- x0
, 1);
1126 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
1127 x_fill_rectangle (f
, f
->output_data
.x
->normal_gc
,
1128 x0
, y0
, x1
- x0
, y1
- y0
);
1132 /* End update of window W.
1134 Draw vertical borders between horizontally adjacent windows, and
1135 display W's cursor if CURSOR_ON_P is non-zero.
1137 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
1138 glyphs in mouse-face were overwritten. In that case we have to
1139 make sure that the mouse-highlight is properly redrawn.
1141 W may be a menu bar pseudo-window in case we don't have X toolkit
1142 support. Such windows don't have a cursor, so don't display it
1146 x_update_window_end (struct window
*w
, bool cursor_on_p
,
1147 bool mouse_face_overwritten_p
)
1149 if (!w
->pseudo_window_p
)
1154 display_and_set_cursor (w
, true,
1155 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
1156 w
->output_cursor
.x
, w
->output_cursor
.y
);
1158 if (draw_window_fringes (w
, true))
1160 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
1161 x_draw_right_divider (w
);
1163 x_draw_vertical_border (w
);
1169 /* If a row with mouse-face was overwritten, arrange for
1170 XTframe_up_to_date to redisplay the mouse highlight. */
1171 if (mouse_face_overwritten_p
)
1173 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
1175 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
1176 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
1177 hlinfo
->mouse_face_window
= Qnil
;
1182 /* End update of frame F. This function is installed as a hook in
1186 x_update_end (struct frame
*f
)
1188 /* Mouse highlight may be displayed again. */
1189 MOUSE_HL_INFO (f
)->mouse_face_defer
= false;
1192 if (FRAME_CR_SURFACE (f
))
1196 #if defined (USE_GTK) && defined (HAVE_GTK3)
1197 if (FRAME_GTK_WIDGET (f
))
1199 GdkWindow
*w
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
1200 cr
= gdk_cairo_create (w
);
1205 cairo_surface_t
*surface
;
1206 int width
= FRAME_PIXEL_WIDTH (f
);
1207 int height
= FRAME_PIXEL_HEIGHT (f
);
1208 if (! FRAME_EXTERNAL_TOOL_BAR (f
))
1209 height
+= FRAME_TOOL_BAR_HEIGHT (f
);
1210 if (! FRAME_EXTERNAL_MENU_BAR (f
))
1211 height
+= FRAME_MENU_BAR_HEIGHT (f
);
1212 surface
= cairo_xlib_surface_create (FRAME_X_DISPLAY (f
),
1214 FRAME_DISPLAY_INFO (f
)->visual
,
1217 cr
= cairo_create (surface
);
1218 cairo_surface_destroy (surface
);
1221 cairo_set_source_surface (cr
, FRAME_CR_SURFACE (f
), 0, 0);
1226 #endif /* USE_CAIRO */
1230 XFlush (FRAME_X_DISPLAY (f
));
1236 /* This function is called from various places in xdisp.c
1237 whenever a complete update has been performed. */
1240 XTframe_up_to_date (struct frame
*f
)
1243 FRAME_MOUSE_UPDATE (f
);
1247 /* Clear under internal border if any (GTK has its own version). */
1250 x_clear_under_internal_border (struct frame
*f
)
1252 if (FRAME_INTERNAL_BORDER_WIDTH (f
) > 0)
1254 int border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
1255 int width
= FRAME_PIXEL_WIDTH (f
);
1256 int height
= FRAME_PIXEL_HEIGHT (f
);
1257 int margin
= FRAME_TOP_MARGIN_HEIGHT (f
);
1260 x_clear_area (f
, 0, 0, border
, height
);
1261 x_clear_area (f
, 0, margin
, width
, border
);
1262 x_clear_area (f
, width
- border
, 0, border
, height
);
1263 x_clear_area (f
, 0, height
- border
, width
, border
);
1269 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
1270 arrow bitmaps, or clear the fringes if no bitmaps are required
1271 before DESIRED_ROW is made current. This function is called from
1272 update_window_line only if it is known that there are differences
1273 between bitmaps to be drawn between current row and DESIRED_ROW. */
1276 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
1280 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
1281 desired_row
->redraw_fringe_bitmaps_p
= true;
1283 #ifdef USE_X_TOOLKIT
1284 /* When a window has disappeared, make sure that no rest of
1285 full-width rows stays visible in the internal border. Could
1286 check here if updated window is the leftmost/rightmost window,
1287 but I guess it's not worth doing since vertically split windows
1288 are almost never used, internal border is rarely set, and the
1289 overhead is very small. */
1294 if (windows_or_buffers_changed
1295 && desired_row
->full_width_p
1296 && (f
= XFRAME (w
->frame
),
1297 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
1299 && (height
= desired_row
->visible_height
,
1302 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
1305 x_clear_area (f
, 0, y
, width
, height
);
1306 x_clear_area (f
, FRAME_PIXEL_WIDTH (f
) - width
, y
, width
, height
);
1314 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
1316 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
1317 Display
*display
= FRAME_X_DISPLAY (f
);
1318 Window window
= FRAME_X_WINDOW (f
);
1319 GC gc
= f
->output_data
.x
->normal_gc
;
1320 struct face
*face
= p
->face
;
1322 /* Must clip because of partially visible lines. */
1323 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
1325 if (p
->bx
>= 0 && !p
->overlay_p
)
1327 /* In case the same realized face is used for fringes and
1328 for something displayed in the text (e.g. face `region' on
1329 mono-displays, the fill style may have been changed to
1330 FillSolid in x_draw_glyph_string_background. */
1332 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
1334 XSetForeground (display
, face
->gc
, face
->background
);
1336 x_fill_rectangle (f
, face
->gc
, p
->bx
, p
->by
, p
->nx
, p
->ny
);
1339 XSetForeground (display
, face
->gc
, face
->foreground
);
1343 if (p
->which
&& p
->which
< max_fringe_bmp
)
1347 XGetGCValues (display
, gc
, GCForeground
| GCBackground
, &gcv
);
1348 XSetForeground (display
, gc
, (p
->cursor_p
1349 ? (p
->overlay_p
? face
->background
1350 : f
->output_data
.x
->cursor_pixel
)
1351 : face
->foreground
));
1352 XSetBackground (display
, gc
, face
->background
);
1353 x_cr_draw_image (f
, gc
, fringe_bmp
[p
->which
], 0, p
->dh
,
1354 p
->wd
, p
->h
, p
->x
, p
->y
, p
->overlay_p
);
1355 XSetForeground (display
, gc
, gcv
.foreground
);
1356 XSetBackground (display
, gc
, gcv
.background
);
1358 #else /* not USE_CAIRO */
1362 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
1363 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
1367 bits
= (char *) (p
->bits
+ p
->dh
);
1369 bits
= (char *) p
->bits
+ p
->dh
;
1371 /* Draw the bitmap. I believe these small pixmaps can be cached
1373 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
1375 ? (p
->overlay_p
? face
->background
1376 : f
->output_data
.x
->cursor_pixel
)
1377 : face
->foreground
),
1378 face
->background
, depth
);
1382 clipmask
= XCreatePixmapFromBitmapData (display
,
1383 FRAME_DISPLAY_INFO (f
)->root_window
,
1386 gcv
.clip_mask
= clipmask
;
1387 gcv
.clip_x_origin
= p
->x
;
1388 gcv
.clip_y_origin
= p
->y
;
1389 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
1392 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
1393 p
->wd
, p
->h
, p
->x
, p
->y
);
1394 XFreePixmap (display
, pixmap
);
1398 gcv
.clip_mask
= (Pixmap
) 0;
1399 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
1400 XFreePixmap (display
, clipmask
);
1403 #endif /* not USE_CAIRO */
1405 x_reset_clip_rectangles (f
, gc
);
1408 /***********************************************************************
1410 ***********************************************************************/
1414 static void x_set_glyph_string_clipping (struct glyph_string
*);
1415 static void x_set_glyph_string_gc (struct glyph_string
*);
1416 static void x_draw_glyph_string_foreground (struct glyph_string
*);
1417 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
1418 static void x_draw_glyph_string_box (struct glyph_string
*);
1419 static void x_draw_glyph_string (struct glyph_string
*);
1420 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
1421 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
1422 static void x_set_cursor_gc (struct glyph_string
*);
1423 static void x_set_mode_line_face_gc (struct glyph_string
*);
1424 static void x_set_mouse_face_gc (struct glyph_string
*);
1425 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
1426 unsigned long *, double, int);
1427 static void x_setup_relief_color (struct frame
*, struct relief
*,
1428 double, int, unsigned long);
1429 static void x_setup_relief_colors (struct glyph_string
*);
1430 static void x_draw_image_glyph_string (struct glyph_string
*);
1431 static void x_draw_image_relief (struct glyph_string
*);
1432 static void x_draw_image_foreground (struct glyph_string
*);
1433 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
1434 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
1436 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
1437 int, bool, bool, bool, bool, bool,
1439 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
1440 int, bool, bool, XRectangle
*);
1441 static void x_scroll_bar_clear (struct frame
*);
1444 static void x_check_font (struct frame
*, struct font
*);
1448 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
1452 x_set_cursor_gc (struct glyph_string
*s
)
1454 if (s
->font
== FRAME_FONT (s
->f
)
1455 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1456 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1458 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1461 /* Cursor on non-default face: must merge. */
1465 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1466 xgcv
.foreground
= s
->face
->background
;
1468 /* If the glyph would be invisible, try a different foreground. */
1469 if (xgcv
.foreground
== xgcv
.background
)
1470 xgcv
.foreground
= s
->face
->foreground
;
1471 if (xgcv
.foreground
== xgcv
.background
)
1472 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1473 if (xgcv
.foreground
== xgcv
.background
)
1474 xgcv
.foreground
= s
->face
->foreground
;
1476 /* Make sure the cursor is distinct from text in this face. */
1477 if (xgcv
.background
== s
->face
->background
1478 && xgcv
.foreground
== s
->face
->foreground
)
1480 xgcv
.background
= s
->face
->foreground
;
1481 xgcv
.foreground
= s
->face
->background
;
1484 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1485 xgcv
.graphics_exposures
= False
;
1486 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1488 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1489 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1492 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1493 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1495 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1500 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1503 x_set_mouse_face_gc (struct glyph_string
*s
)
1508 /* What face has to be used last for the mouse face? */
1509 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
1510 face
= FACE_FROM_ID (s
->f
, face_id
);
1512 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1514 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1515 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1517 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1518 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1519 prepare_face_for_display (s
->f
, s
->face
);
1521 if (s
->font
== s
->face
->font
)
1522 s
->gc
= s
->face
->gc
;
1525 /* Otherwise construct scratch_cursor_gc with values from FACE
1530 xgcv
.background
= s
->face
->background
;
1531 xgcv
.foreground
= s
->face
->foreground
;
1532 xgcv
.graphics_exposures
= False
;
1533 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1535 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1536 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1539 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1540 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1542 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1545 eassert (s
->gc
!= 0);
1549 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1550 Faces to use in the mode line have already been computed when the
1551 matrix was built, so there isn't much to do, here. */
1554 x_set_mode_line_face_gc (struct glyph_string
*s
)
1556 s
->gc
= s
->face
->gc
;
1560 /* Set S->gc of glyph string S for drawing that glyph string. Set
1561 S->stippled_p to a non-zero value if the face of S has a stipple
1565 x_set_glyph_string_gc (struct glyph_string
*s
)
1567 prepare_face_for_display (s
->f
, s
->face
);
1569 if (s
->hl
== DRAW_NORMAL_TEXT
)
1571 s
->gc
= s
->face
->gc
;
1572 s
->stippled_p
= s
->face
->stipple
!= 0;
1574 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1576 x_set_mode_line_face_gc (s
);
1577 s
->stippled_p
= s
->face
->stipple
!= 0;
1579 else if (s
->hl
== DRAW_CURSOR
)
1581 x_set_cursor_gc (s
);
1582 s
->stippled_p
= false;
1584 else if (s
->hl
== DRAW_MOUSE_FACE
)
1586 x_set_mouse_face_gc (s
);
1587 s
->stippled_p
= s
->face
->stipple
!= 0;
1589 else if (s
->hl
== DRAW_IMAGE_RAISED
1590 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1592 s
->gc
= s
->face
->gc
;
1593 s
->stippled_p
= s
->face
->stipple
!= 0;
1598 /* GC must have been set. */
1599 eassert (s
->gc
!= 0);
1603 /* Set clipping for output of glyph string S. S may be part of a mode
1604 line or menu if we don't have X toolkit support. */
1607 x_set_glyph_string_clipping (struct glyph_string
*s
)
1609 XRectangle
*r
= s
->clip
;
1610 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1613 x_set_clip_rectangles (s
->f
, s
->gc
, r
, n
);
1618 /* Set SRC's clipping for output of glyph string DST. This is called
1619 when we are drawing DST's left_overhang or right_overhang only in
1623 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1628 r
.width
= src
->width
;
1630 r
.height
= src
->height
;
1633 x_set_clip_rectangles (dst
->f
, dst
->gc
, &r
, 1);
1638 Compute left and right overhang of glyph string S. */
1641 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1644 && (s
->first_glyph
->type
== CHAR_GLYPH
1645 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1647 struct font_metrics metrics
;
1649 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1651 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1652 struct font
*font
= s
->font
;
1655 for (i
= 0; i
< s
->nchars
; i
++)
1656 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1657 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1661 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1663 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1665 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1666 ? metrics
.rbearing
- metrics
.width
: 0);
1667 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1671 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1672 s
->left_overhang
= - s
->cmp
->lbearing
;
1677 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1680 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1683 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1684 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1685 x_fill_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
1686 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1690 /* Draw the background of glyph_string S. If S->background_filled_p
1691 is non-zero don't draw it. FORCE_P non-zero means draw the
1692 background even if it wouldn't be drawn normally. This is used
1693 when a string preceding S draws into the background of S, or S
1694 contains the first component of a composition. */
1697 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1699 /* Nothing to do if background has already been drawn or if it
1700 shouldn't be drawn in the first place. */
1701 if (!s
->background_filled_p
)
1703 int box_line_width
= max (s
->face
->box_line_width
, 0);
1707 /* Fill background with a stipple pattern. */
1708 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1709 x_fill_rectangle (s
->f
, s
->gc
, s
->x
,
1710 s
->y
+ box_line_width
,
1711 s
->background_width
,
1712 s
->height
- 2 * box_line_width
);
1713 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1714 s
->background_filled_p
= true;
1716 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1717 /* When xdisp.c ignores FONT_HEIGHT, we cannot trust
1718 font dimensions, since the actual glyphs might be
1719 much smaller. So in that case we always clear the
1720 rectangle with background color. */
1721 || FONT_TOO_HIGH (s
->font
)
1722 || s
->font_not_found_p
1723 || s
->extends_to_end_of_line_p
1726 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1727 s
->background_width
,
1728 s
->height
- 2 * box_line_width
);
1729 s
->background_filled_p
= true;
1735 /* Draw the foreground of glyph string S. */
1738 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1742 /* If first glyph of S has a left box line, start drawing the text
1743 of S to the right of that box line. */
1744 if (s
->face
->box
!= FACE_NO_BOX
1745 && s
->first_glyph
->left_box_line_p
)
1746 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1750 /* Draw characters of S as rectangles if S's font could not be
1752 if (s
->font_not_found_p
)
1754 for (i
= 0; i
< s
->nchars
; ++i
)
1756 struct glyph
*g
= s
->first_glyph
+ i
;
1757 x_draw_rectangle (s
->f
,
1758 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1760 x
+= g
->pixel_width
;
1765 struct font
*font
= s
->font
;
1766 int boff
= font
->baseline_offset
;
1769 if (font
->vertical_centering
)
1770 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1772 y
= s
->ybase
- boff
;
1774 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1775 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, false);
1777 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, true);
1778 if (s
->face
->overstrike
)
1779 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, false);
1783 /* Draw the foreground of composite glyph string S. */
1786 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1789 struct font
*font
= s
->font
;
1791 /* If first glyph of S has a left box line, start drawing the text
1792 of S to the right of that box line. */
1793 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1794 && s
->first_glyph
->left_box_line_p
)
1795 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1799 /* S is a glyph string for a composition. S->cmp_from is the index
1800 of the first character drawn for glyphs of this composition.
1801 S->cmp_from == 0 means we are drawing the very first character of
1802 this composition. */
1804 /* Draw a rectangle for the composition if the font for the very
1805 first character of the composition could not be loaded. */
1806 if (s
->font_not_found_p
)
1808 if (s
->cmp_from
== 0)
1809 x_draw_rectangle (s
->f
, s
->gc
, x
, s
->y
,
1810 s
->width
- 1, s
->height
- 1);
1812 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1816 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1817 /* TAB in a composition means display glyphs with padding
1818 space on the left or right. */
1819 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1821 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1822 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1824 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, false);
1825 if (s
->face
->overstrike
)
1826 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, false);
1831 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1836 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1838 glyph
= LGSTRING_GLYPH (gstring
, i
);
1839 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1840 width
+= LGLYPH_WIDTH (glyph
);
1843 int xoff
, yoff
, wadjust
;
1847 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1848 if (s
->face
->overstrike
)
1849 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, false);
1852 xoff
= LGLYPH_XOFF (glyph
);
1853 yoff
= LGLYPH_YOFF (glyph
);
1854 wadjust
= LGLYPH_WADJUST (glyph
);
1855 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, false);
1856 if (s
->face
->overstrike
)
1857 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
,
1866 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1867 if (s
->face
->overstrike
)
1868 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, false);
1874 /* Draw the foreground of glyph string S for glyphless characters. */
1877 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1879 struct glyph
*glyph
= s
->first_glyph
;
1883 /* If first glyph of S has a left box line, start drawing the text
1884 of S to the right of that box line. */
1885 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1886 && s
->first_glyph
->left_box_line_p
)
1887 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1893 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1895 char buf
[7], *str
= NULL
;
1896 int len
= glyph
->u
.glyphless
.len
;
1898 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1901 && CHAR_TABLE_P (Vglyphless_char_display
)
1902 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1906 = (! glyph
->u
.glyphless
.for_no_font
1907 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1908 glyph
->u
.glyphless
.ch
)
1909 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1910 if (STRINGP (acronym
))
1911 str
= SSDATA (acronym
);
1914 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1916 sprintf (buf
, "%0*X",
1917 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1918 glyph
->u
.glyphless
.ch
+ 0u);
1924 int upper_len
= (len
+ 1) / 2;
1927 /* It is assured that all LEN characters in STR is ASCII. */
1928 for (j
= 0; j
< len
; j
++)
1930 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1931 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1933 s
->font
->driver
->draw (s
, 0, upper_len
,
1934 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1935 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1937 s
->font
->driver
->draw (s
, upper_len
, len
,
1938 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1939 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1942 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1943 x_draw_rectangle (s
->f
, s
->gc
,
1944 x
, s
->ybase
- glyph
->ascent
,
1945 glyph
->pixel_width
- 1,
1946 glyph
->ascent
+ glyph
->descent
- 1);
1947 x
+= glyph
->pixel_width
;
1951 #ifdef USE_X_TOOLKIT
1955 /* Return the frame on which widget WIDGET is used.. Abort if frame
1956 cannot be determined. */
1958 static struct frame
*
1959 x_frame_of_widget (Widget widget
)
1961 struct x_display_info
*dpyinfo
;
1962 Lisp_Object tail
, frame
;
1965 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1967 /* Find the top-level shell of the widget. Note that this function
1968 can be called when the widget is not yet realized, so XtWindow
1969 (widget) == 0. That's the reason we can't simply use
1970 x_any_window_to_frame. */
1971 while (!XtIsTopLevelShell (widget
))
1972 widget
= XtParent (widget
);
1974 /* Look for a frame with that top-level widget. Allocate the color
1975 on that frame to get the right gamma correction value. */
1976 FOR_EACH_FRAME (tail
, frame
)
1980 && f
->output_data
.nothing
!= 1
1981 && FRAME_DISPLAY_INFO (f
) == dpyinfo
1982 && f
->output_data
.x
->widget
== widget
)
1988 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1989 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1990 If this produces the same color as PIXEL, try a color where all RGB
1991 values have DELTA added. Return the allocated color in *PIXEL.
1992 DISPLAY is the X display, CMAP is the colormap to operate on.
1993 Value is true if successful. */
1996 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1997 unsigned long *pixel
, double factor
, int delta
)
1999 struct frame
*f
= x_frame_of_widget (widget
);
2000 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
2003 #endif /* USE_LUCID */
2006 /* Structure specifying which arguments should be passed by Xt to
2007 cvt_string_to_pixel. We want the widget's screen and colormap. */
2009 static XtConvertArgRec cvt_string_to_pixel_args
[] =
2011 {XtWidgetBaseOffset
, (XtPointer
) offsetof (WidgetRec
, core
.screen
),
2013 {XtWidgetBaseOffset
, (XtPointer
) offsetof (WidgetRec
, core
.colormap
),
2018 /* The address of this variable is returned by
2019 cvt_string_to_pixel. */
2021 static Pixel cvt_string_to_pixel_value
;
2024 /* Convert a color name to a pixel color.
2026 DPY is the display we are working on.
2028 ARGS is an array of *NARGS XrmValue structures holding additional
2029 information about the widget for which the conversion takes place.
2030 The contents of this array are determined by the specification
2031 in cvt_string_to_pixel_args.
2033 FROM is a pointer to an XrmValue which points to the color name to
2034 convert. TO is an XrmValue in which to return the pixel color.
2036 CLOSURE_RET is a pointer to user-data, in which we record if
2037 we allocated the color or not.
2039 Value is True if successful, False otherwise. */
2042 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
2043 XrmValue
*from
, XrmValue
*to
,
2044 XtPointer
*closure_ret
)
2054 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
2055 "wrongParameters", "cvt_string_to_pixel",
2057 "Screen and colormap args required", NULL
, NULL
);
2061 screen
= *(Screen
**) args
[0].addr
;
2062 cmap
= *(Colormap
*) args
[1].addr
;
2063 color_name
= (String
) from
->addr
;
2065 if (strcmp (color_name
, XtDefaultBackground
) == 0)
2067 *closure_ret
= (XtPointer
) False
;
2068 pixel
= WhitePixelOfScreen (screen
);
2070 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
2072 *closure_ret
= (XtPointer
) False
;
2073 pixel
= BlackPixelOfScreen (screen
);
2075 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
2076 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
2078 pixel
= color
.pixel
;
2079 *closure_ret
= (XtPointer
) True
;
2084 Cardinal nparams
= 1;
2086 params
[0] = color_name
;
2087 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
2088 "badValue", "cvt_string_to_pixel",
2089 "XtToolkitError", "Invalid color '%s'",
2094 if (to
->addr
!= NULL
)
2096 if (to
->size
< sizeof (Pixel
))
2098 to
->size
= sizeof (Pixel
);
2102 *(Pixel
*) to
->addr
= pixel
;
2106 cvt_string_to_pixel_value
= pixel
;
2107 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
2110 to
->size
= sizeof (Pixel
);
2115 /* Free a pixel color which was previously allocated via
2116 cvt_string_to_pixel. This is registered as the destructor
2117 for this type of resource via XtSetTypeConverter.
2119 APP is the application context in which we work.
2121 TO is a pointer to an XrmValue holding the color to free.
2122 CLOSURE is the value we stored in CLOSURE_RET for this color
2123 in cvt_string_to_pixel.
2125 ARGS and NARGS are like for cvt_string_to_pixel. */
2128 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
2133 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
2135 "Screen and colormap arguments required",
2138 else if (closure
!= NULL
)
2140 /* We did allocate the pixel, so free it. */
2141 Screen
*screen
= *(Screen
**) args
[0].addr
;
2142 Colormap cmap
= *(Colormap
*) args
[1].addr
;
2143 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
2144 (Pixel
*) to
->addr
, 1);
2149 #endif /* USE_X_TOOLKIT */
2152 /* Value is an array of XColor structures for the contents of the
2153 color map of display DPY. Set *NCELLS to the size of the array.
2154 Note that this probably shouldn't be called for large color maps,
2155 say a 24-bit TrueColor map. */
2157 static const XColor
*
2158 x_color_cells (Display
*dpy
, int *ncells
)
2160 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
2162 if (dpyinfo
->color_cells
== NULL
)
2164 Screen
*screen
= dpyinfo
->screen
;
2165 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
2168 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
2169 sizeof *dpyinfo
->color_cells
);
2170 dpyinfo
->ncolor_cells
= ncolor_cells
;
2172 for (i
= 0; i
< ncolor_cells
; ++i
)
2173 dpyinfo
->color_cells
[i
].pixel
= i
;
2175 XQueryColors (dpy
, dpyinfo
->cmap
,
2176 dpyinfo
->color_cells
, ncolor_cells
);
2179 *ncells
= dpyinfo
->ncolor_cells
;
2180 return dpyinfo
->color_cells
;
2184 /* On frame F, translate pixel colors to RGB values for the NCOLORS
2185 colors in COLORS. Use cached information, if available. */
2188 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
2190 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2192 if (dpyinfo
->red_bits
> 0)
2194 /* For TrueColor displays, we can decompose the RGB value
2197 unsigned int rmult
, gmult
, bmult
;
2198 unsigned int rmask
, gmask
, bmask
;
2200 rmask
= (1 << dpyinfo
->red_bits
) - 1;
2201 gmask
= (1 << dpyinfo
->green_bits
) - 1;
2202 bmask
= (1 << dpyinfo
->blue_bits
) - 1;
2203 /* If we're widening, for example, 8 bits in the pixel value to
2204 16 bits for the separate-color representation, we want to
2205 extrapolate the lower bits based on those bits available --
2206 in other words, we'd like 0xff to become 0xffff instead of
2207 the 0xff00 we'd get by just zero-filling the lower bits.
2209 We generate a 32-bit scaled-up value and shift it, in case
2210 the bit count doesn't divide 16 evenly (e.g., when dealing
2211 with a 3-3-2 bit RGB display), to get more of the lower bits
2214 Should we cache the multipliers in dpyinfo? Maybe
2215 special-case the 8-8-8 common case? */
2216 rmult
= 0xffffffff / rmask
;
2217 gmult
= 0xffffffff / gmask
;
2218 bmult
= 0xffffffff / bmask
;
2220 for (i
= 0; i
< ncolors
; ++i
)
2222 unsigned int r
, g
, b
;
2223 unsigned long pixel
= colors
[i
].pixel
;
2225 r
= (pixel
>> dpyinfo
->red_offset
) & rmask
;
2226 g
= (pixel
>> dpyinfo
->green_offset
) & gmask
;
2227 b
= (pixel
>> dpyinfo
->blue_offset
) & bmask
;
2229 colors
[i
].red
= (r
* rmult
) >> 16;
2230 colors
[i
].green
= (g
* gmult
) >> 16;
2231 colors
[i
].blue
= (b
* bmult
) >> 16;
2236 if (dpyinfo
->color_cells
)
2239 for (i
= 0; i
< ncolors
; ++i
)
2241 unsigned long pixel
= colors
[i
].pixel
;
2242 eassert (pixel
< dpyinfo
->ncolor_cells
);
2243 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
2244 colors
[i
] = dpyinfo
->color_cells
[pixel
];
2249 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
2253 /* On frame F, translate pixel color to RGB values for the color in
2254 COLOR. Use cached information, if available. */
2257 x_query_color (struct frame
*f
, XColor
*color
)
2259 x_query_colors (f
, color
, 1);
2263 /* On frame F, translate the color name to RGB values. Use cached
2264 information, if possible.
2266 Note that there is currently no way to clean old entries out of the
2267 cache. However, it is limited to names in the server's database,
2268 and names we've actually looked up; list-colors-display is probably
2269 the most color-intensive case we're likely to hit. */
2271 Status
x_parse_color (struct frame
*f
, const char *color_name
,
2274 Display
*dpy
= FRAME_X_DISPLAY (f
);
2275 Colormap cmap
= FRAME_X_COLORMAP (f
);
2276 struct color_name_cache_entry
*cache_entry
;
2278 if (color_name
[0] == '#')
2280 /* The hex form is parsed directly by XParseColor without
2281 talking to the X server. No need for caching. */
2282 return XParseColor (dpy
, cmap
, color_name
, color
);
2285 for (cache_entry
= FRAME_DISPLAY_INFO (f
)->color_names
; cache_entry
;
2286 cache_entry
= cache_entry
->next
)
2288 if (!xstrcasecmp(cache_entry
->name
, color_name
))
2290 *color
= cache_entry
->rgb
;
2295 if (XParseColor (dpy
, cmap
, color_name
, color
) == 0)
2296 /* No caching of negative results, currently. */
2299 cache_entry
= xzalloc (sizeof *cache_entry
);
2300 cache_entry
->rgb
= *color
;
2301 cache_entry
->name
= xstrdup (color_name
);
2302 cache_entry
->next
= FRAME_DISPLAY_INFO (f
)->color_names
;
2303 FRAME_DISPLAY_INFO (f
)->color_names
= cache_entry
;
2308 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
2309 exact match can't be allocated, try the nearest color available.
2310 Value is true if successful. Set *COLOR to the color
2314 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
2318 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
2321 /* If we got to this point, the colormap is full, so we're going
2322 to try to get the next closest color. The algorithm used is
2323 a least-squares matching, which is what X uses for closest
2324 color matching with StaticColor visuals. */
2326 int max_color_delta
= 255;
2327 int max_delta
= 3 * max_color_delta
;
2328 int nearest_delta
= max_delta
+ 1;
2330 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
2332 for (nearest
= i
= 0; i
< ncells
; ++i
)
2334 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
2335 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
2336 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
2337 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
2339 if (delta
< nearest_delta
)
2342 nearest_delta
= delta
;
2346 color
->red
= cells
[nearest
].red
;
2347 color
->green
= cells
[nearest
].green
;
2348 color
->blue
= cells
[nearest
].blue
;
2349 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
2353 /* If allocation succeeded, and the allocated pixel color is not
2354 equal to a cached pixel color recorded earlier, there was a
2355 change in the colormap, so clear the color cache. */
2356 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
2357 XColor
*cached_color
;
2359 if (dpyinfo
->color_cells
2360 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
2361 (cached_color
->red
!= color
->red
2362 || cached_color
->blue
!= color
->blue
2363 || cached_color
->green
!= color
->green
)))
2365 xfree (dpyinfo
->color_cells
);
2366 dpyinfo
->color_cells
= NULL
;
2367 dpyinfo
->ncolor_cells
= 0;
2371 #ifdef DEBUG_X_COLORS
2373 register_color (color
->pixel
);
2374 #endif /* DEBUG_X_COLORS */
2380 /* Allocate the color COLOR->pixel on frame F, colormap CMAP, after
2381 gamma correction. If an exact match can't be allocated, try the
2382 nearest color available. Value is true if successful. Set *COLOR
2383 to the color allocated. */
2386 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
2388 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2390 gamma_correct (f
, color
);
2392 if (dpyinfo
->red_bits
> 0)
2394 color
->pixel
= x_make_truecolor_pixel (dpyinfo
,
2401 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
2405 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
2406 It's necessary to do this instead of just using PIXEL directly to
2407 get color reference counts right. */
2410 x_copy_color (struct frame
*f
, unsigned long pixel
)
2414 /* If display has an immutable color map, freeing colors is not
2415 necessary and some servers don't allow it. Since we won't free a
2416 color once we've allocated it, we don't need to re-allocate it to
2417 maintain the server's reference count. */
2418 if (!x_mutable_colormap (FRAME_X_VISUAL (f
)))
2421 color
.pixel
= pixel
;
2423 /* The color could still be found in the color_cells array. */
2424 x_query_color (f
, &color
);
2425 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
2427 #ifdef DEBUG_X_COLORS
2428 register_color (pixel
);
2434 /* Brightness beyond which a color won't have its highlight brightness
2437 Nominally, highlight colors for `3d' faces are calculated by
2438 brightening an object's color by a constant scale factor, but this
2439 doesn't yield good results for dark colors, so for colors who's
2440 brightness is less than this value (on a scale of 0-65535) have an
2441 use an additional additive factor.
2443 The value here is set so that the default menu-bar/mode-line color
2444 (grey75) will not have its highlights changed at all. */
2445 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
2448 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
2449 or DELTA. Try a color with RGB values multiplied by FACTOR first.
2450 If this produces the same color as PIXEL, try a color where all RGB
2451 values have DELTA added. Return the allocated color in *PIXEL.
2452 DISPLAY is the X display, CMAP is the colormap to operate on.
2453 Value is non-zero if successful. */
2456 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
,
2457 unsigned long *pixel
, double factor
, int delta
)
2463 /* Get RGB color values. */
2464 color
.pixel
= *pixel
;
2465 x_query_color (f
, &color
);
2467 /* Change RGB values by specified FACTOR. Avoid overflow! */
2468 eassert (factor
>= 0);
2469 new.red
= min (0xffff, factor
* color
.red
);
2470 new.green
= min (0xffff, factor
* color
.green
);
2471 new.blue
= min (0xffff, factor
* color
.blue
);
2473 /* Calculate brightness of COLOR. */
2474 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
2476 /* We only boost colors that are darker than
2477 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
2478 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
2479 /* Make an additive adjustment to NEW, because it's dark enough so
2480 that scaling by FACTOR alone isn't enough. */
2482 /* How far below the limit this color is (0 - 1, 1 being darker). */
2483 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
2484 /* The additive adjustment. */
2485 int min_delta
= delta
* dimness
* factor
/ 2;
2489 new.red
= max (0, new.red
- min_delta
);
2490 new.green
= max (0, new.green
- min_delta
);
2491 new.blue
= max (0, new.blue
- min_delta
);
2495 new.red
= min (0xffff, min_delta
+ new.red
);
2496 new.green
= min (0xffff, min_delta
+ new.green
);
2497 new.blue
= min (0xffff, min_delta
+ new.blue
);
2501 /* Try to allocate the color. */
2502 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2505 if (new.pixel
== *pixel
)
2507 /* If we end up with the same color as before, try adding
2508 delta to the RGB values. */
2509 x_free_colors (f
, &new.pixel
, 1);
2511 new.red
= min (0xffff, delta
+ color
.red
);
2512 new.green
= min (0xffff, delta
+ color
.green
);
2513 new.blue
= min (0xffff, delta
+ color
.blue
);
2514 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
2525 /* Set up the foreground color for drawing relief lines of glyph
2526 string S. RELIEF is a pointer to a struct relief containing the GC
2527 with which lines will be drawn. Use a color that is FACTOR or
2528 DELTA lighter or darker than the relief's background which is found
2529 in S->f->output_data.x->relief_background. If such a color cannot
2530 be allocated, use DEFAULT_PIXEL, instead. */
2533 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
,
2534 int delta
, unsigned long default_pixel
)
2537 struct x_output
*di
= f
->output_data
.x
;
2538 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
2539 unsigned long pixel
;
2540 unsigned long background
= di
->relief_background
;
2541 Colormap cmap
= FRAME_X_COLORMAP (f
);
2542 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
2543 Display
*dpy
= FRAME_X_DISPLAY (f
);
2545 xgcv
.graphics_exposures
= False
;
2546 xgcv
.line_width
= 1;
2548 /* Free previously allocated color. The color cell will be reused
2549 when it has been freed as many times as it was allocated, so this
2550 doesn't affect faces using the same colors. */
2551 if (relief
->gc
&& relief
->pixel
!= -1)
2553 x_free_colors (f
, &relief
->pixel
, 1);
2557 /* Allocate new color. */
2558 xgcv
.foreground
= default_pixel
;
2560 if (dpyinfo
->n_planes
!= 1
2561 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
2562 xgcv
.foreground
= relief
->pixel
= pixel
;
2564 if (relief
->gc
== 0)
2566 xgcv
.stipple
= dpyinfo
->gray
;
2568 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
2571 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
2575 /* Set up colors for the relief lines around glyph string S. */
2578 x_setup_relief_colors (struct glyph_string
*s
)
2580 struct x_output
*di
= s
->f
->output_data
.x
;
2581 unsigned long color
;
2583 if (s
->face
->use_box_color_for_shadows_p
)
2584 color
= s
->face
->box_color
;
2585 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2587 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2588 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2593 /* Get the background color of the face. */
2594 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2595 color
= xgcv
.background
;
2598 if (di
->white_relief
.gc
== 0
2599 || color
!= di
->relief_background
)
2601 di
->relief_background
= color
;
2602 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2603 WHITE_PIX_DEFAULT (s
->f
));
2604 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2605 BLACK_PIX_DEFAULT (s
->f
));
2610 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2611 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2612 to draw, it must be >= 0. RAISED_P means draw a raised
2613 relief. LEFT_P means draw a relief on the left side of
2614 the rectangle. RIGHT_P means draw a relief on the right
2615 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2619 x_draw_relief_rect (struct frame
*f
,
2620 int left_x
, int top_y
, int right_x
, int bottom_y
,
2621 int width
, bool raised_p
, bool top_p
, bool bot_p
,
2622 bool left_p
, bool right_p
,
2623 XRectangle
*clip_rect
)
2626 GC top_left_gc
, bottom_right_gc
;
2631 top_left_gc
= f
->output_data
.x
->white_relief
.gc
;
2632 bottom_right_gc
= f
->output_data
.x
->black_relief
.gc
;
2636 top_left_gc
= f
->output_data
.x
->black_relief
.gc
;
2637 bottom_right_gc
= f
->output_data
.x
->white_relief
.gc
;
2640 x_set_clip_rectangles (f
, top_left_gc
, clip_rect
, 1);
2641 x_set_clip_rectangles (f
, bottom_right_gc
, clip_rect
, 1);
2645 x_fill_rectangle (f
, top_left_gc
, left_x
, top_y
,
2646 width
, bottom_y
+ 1 - top_y
);
2648 corners
|= 1 << CORNER_TOP_LEFT
;
2650 corners
|= 1 << CORNER_BOTTOM_LEFT
;
2654 x_fill_rectangle (f
, bottom_right_gc
, right_x
+ 1 - width
, top_y
,
2655 width
, bottom_y
+ 1 - top_y
);
2657 corners
|= 1 << CORNER_TOP_RIGHT
;
2659 corners
|= 1 << CORNER_BOTTOM_RIGHT
;
2664 x_fill_rectangle (f
, top_left_gc
, left_x
, top_y
,
2665 right_x
+ 1 - left_x
, width
);
2667 x_fill_trapezoid_for_relief (f
, top_left_gc
, left_x
, top_y
,
2668 right_x
+ 1 - left_x
, width
, 1);
2673 x_fill_rectangle (f
, bottom_right_gc
, left_x
, bottom_y
+ 1 - width
,
2674 right_x
+ 1 - left_x
, width
);
2676 x_fill_trapezoid_for_relief (f
, bottom_right_gc
,
2677 left_x
, bottom_y
+ 1 - width
,
2678 right_x
+ 1 - left_x
, width
, 0);
2680 if (left_p
&& width
!= 1)
2681 x_fill_rectangle (f
, bottom_right_gc
, left_x
, top_y
,
2682 1, bottom_y
+ 1 - top_y
);
2683 if (top_p
&& width
!= 1)
2684 x_fill_rectangle (f
, bottom_right_gc
, left_x
, top_y
,
2685 right_x
+ 1 - left_x
, 1);
2688 XSetBackground (FRAME_X_DISPLAY (f
), top_left_gc
,
2689 FRAME_BACKGROUND_PIXEL (f
));
2690 x_erase_corners_for_relief (f
, top_left_gc
, left_x
, top_y
,
2691 right_x
- left_x
+ 1, bottom_y
- top_y
+ 1,
2695 x_reset_clip_rectangles (f
, top_left_gc
);
2696 x_reset_clip_rectangles (f
, bottom_right_gc
);
2698 Display
*dpy
= FRAME_X_DISPLAY (f
);
2699 Window window
= FRAME_X_WINDOW (f
);
2704 gc
= f
->output_data
.x
->white_relief
.gc
;
2706 gc
= f
->output_data
.x
->black_relief
.gc
;
2707 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2709 /* This code is more complicated than it has to be, because of two
2710 minor hacks to make the boxes look nicer: (i) if width > 1, draw
2711 the outermost line using the black relief. (ii) Omit the four
2718 XDrawLine (dpy
, window
, gc
,
2719 left_x
+ left_p
, top_y
,
2720 right_x
+ !right_p
, top_y
);
2722 for (i
= 1; i
< width
; ++i
)
2723 XDrawLine (dpy
, window
, gc
,
2724 left_x
+ i
* left_p
, top_y
+ i
,
2725 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2732 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
2734 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
2735 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
2737 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
2738 XDrawLine (dpy
, window
, gc
,
2739 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
2740 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
2743 XSetClipMask (dpy
, gc
, None
);
2745 gc
= f
->output_data
.x
->black_relief
.gc
;
2747 gc
= f
->output_data
.x
->white_relief
.gc
;
2748 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2752 /* Outermost top line. */
2754 XDrawLine (dpy
, window
, gc
,
2755 left_x
+ left_p
, top_y
,
2756 right_x
+ !right_p
, top_y
);
2758 /* Outermost left line. */
2760 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
2766 XDrawLine (dpy
, window
, gc
,
2767 left_x
+ left_p
, bottom_y
,
2768 right_x
+ !right_p
, bottom_y
);
2769 for (i
= 1; i
< width
; ++i
)
2770 XDrawLine (dpy
, window
, gc
,
2771 left_x
+ i
* left_p
, bottom_y
- i
,
2772 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2778 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
2779 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
2780 for (i
= 0; i
< width
; ++i
)
2781 XDrawLine (dpy
, window
, gc
,
2782 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
2783 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
2786 x_reset_clip_rectangles (f
, gc
);
2792 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2793 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2794 draw, it must be >= 0. LEFT_P means draw a line on the
2795 left side of the rectangle. RIGHT_P means draw a line
2796 on the right side of the rectangle. CLIP_RECT is the clipping
2797 rectangle to use when drawing. */
2800 x_draw_box_rect (struct glyph_string
*s
,
2801 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2802 bool left_p
, bool right_p
, XRectangle
*clip_rect
)
2806 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2807 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2808 x_set_clip_rectangles (s
->f
, s
->gc
, clip_rect
, 1);
2811 x_fill_rectangle (s
->f
, s
->gc
,
2812 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2816 x_fill_rectangle (s
->f
, s
->gc
,
2817 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2820 x_fill_rectangle (s
->f
, s
->gc
,
2821 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2825 x_fill_rectangle (s
->f
, s
->gc
,
2826 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2828 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2829 x_reset_clip_rectangles (s
->f
, s
->gc
);
2833 /* Draw a box around glyph string S. */
2836 x_draw_glyph_string_box (struct glyph_string
*s
)
2838 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
;
2839 bool raised_p
, left_p
, right_p
;
2840 struct glyph
*last_glyph
;
2841 XRectangle clip_rect
;
2843 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2844 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2845 : window_box_right (s
->w
, s
->area
));
2847 /* The glyph that may have a right box line. */
2848 last_glyph
= (s
->cmp
|| s
->img
2850 : s
->first_glyph
+ s
->nchars
- 1);
2852 width
= eabs (s
->face
->box_line_width
);
2853 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2855 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2857 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2859 bottom_y
= top_y
+ s
->height
- 1;
2861 left_p
= (s
->first_glyph
->left_box_line_p
2862 || (s
->hl
== DRAW_MOUSE_FACE
2864 || s
->prev
->hl
!= s
->hl
)));
2865 right_p
= (last_glyph
->right_box_line_p
2866 || (s
->hl
== DRAW_MOUSE_FACE
2868 || s
->next
->hl
!= s
->hl
)));
2870 get_glyph_string_clip_rect (s
, &clip_rect
);
2872 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2873 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2874 left_p
, right_p
, &clip_rect
);
2877 x_setup_relief_colors (s
);
2878 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2879 width
, raised_p
, true, true, left_p
, right_p
,
2885 /* Draw foreground of image glyph string S. */
2888 x_draw_image_foreground (struct glyph_string
*s
)
2891 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2893 /* If first glyph of S has a left box line, start drawing it to the
2894 right of that line. */
2895 if (s
->face
->box
!= FACE_NO_BOX
2896 && s
->first_glyph
->left_box_line_p
2898 x
+= eabs (s
->face
->box_line_width
);
2900 /* If there is a margin around the image, adjust x- and y-position
2902 if (s
->slice
.x
== 0)
2903 x
+= s
->img
->hmargin
;
2904 if (s
->slice
.y
== 0)
2905 y
+= s
->img
->vmargin
;
2911 /* We can't set both a clip mask and use XSetClipRectangles
2912 because the latter also sets a clip mask. We also can't
2913 trust on the shape extension to be available
2914 (XShapeCombineRegion). So, compute the rectangle to draw
2916 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2919 XRectangle clip_rect
, image_rect
, r
;
2921 xgcv
.clip_mask
= s
->img
->mask
;
2922 xgcv
.clip_x_origin
= x
;
2923 xgcv
.clip_y_origin
= y
;
2924 xgcv
.function
= GXcopy
;
2925 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2927 get_glyph_string_clip_rect (s
, &clip_rect
);
2930 image_rect
.width
= s
->slice
.width
;
2931 image_rect
.height
= s
->slice
.height
;
2932 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2933 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2934 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2935 r
.width
, r
.height
, r
.x
, r
.y
);
2939 XRectangle clip_rect
, image_rect
, r
;
2941 get_glyph_string_clip_rect (s
, &clip_rect
);
2944 image_rect
.width
= s
->slice
.width
;
2945 image_rect
.height
= s
->slice
.height
;
2946 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2947 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2948 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2949 r
.width
, r
.height
, r
.x
, r
.y
);
2951 /* When the image has a mask, we can expect that at
2952 least part of a mouse highlight or a block cursor will
2953 be visible. If the image doesn't have a mask, make
2954 a block cursor visible by drawing a rectangle around
2955 the image. I believe it's looking better if we do
2956 nothing here for mouse-face. */
2957 if (s
->hl
== DRAW_CURSOR
)
2959 int relief
= eabs (s
->img
->relief
);
2960 x_draw_rectangle (s
->f
, s
->gc
,
2961 x
- relief
, y
- relief
,
2962 s
->slice
.width
+ relief
*2 - 1,
2963 s
->slice
.height
+ relief
*2 - 1);
2968 /* Draw a rectangle if image could not be loaded. */
2969 x_draw_rectangle (s
->f
, s
->gc
, x
, y
,
2970 s
->slice
.width
- 1, s
->slice
.height
- 1);
2974 /* Draw a relief around the image glyph string S. */
2977 x_draw_image_relief (struct glyph_string
*s
)
2980 bool raised_p
, top_p
, bot_p
, left_p
, right_p
;
2981 int extra_x
, extra_y
;
2984 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2986 /* If first glyph of S has a left box line, start drawing it to the
2987 right of that line. */
2988 if (s
->face
->box
!= FACE_NO_BOX
2989 && s
->first_glyph
->left_box_line_p
2991 x
+= eabs (s
->face
->box_line_width
);
2993 /* If there is a margin around the image, adjust x- and y-position
2995 if (s
->slice
.x
== 0)
2996 x
+= s
->img
->hmargin
;
2997 if (s
->slice
.y
== 0)
2998 y
+= s
->img
->vmargin
;
3000 if (s
->hl
== DRAW_IMAGE_SUNKEN
3001 || s
->hl
== DRAW_IMAGE_RAISED
)
3003 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
3004 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
3008 thick
= eabs (s
->img
->relief
);
3009 raised_p
= s
->img
->relief
> 0;
3012 x1
= x
+ s
->slice
.width
- 1;
3013 y1
= y
+ s
->slice
.height
- 1;
3015 extra_x
= extra_y
= 0;
3016 if (s
->face
->id
== TOOL_BAR_FACE_ID
)
3018 if (CONSP (Vtool_bar_button_margin
)
3019 && INTEGERP (XCAR (Vtool_bar_button_margin
))
3020 && INTEGERP (XCDR (Vtool_bar_button_margin
)))
3022 extra_x
= XINT (XCAR (Vtool_bar_button_margin
));
3023 extra_y
= XINT (XCDR (Vtool_bar_button_margin
));
3025 else if (INTEGERP (Vtool_bar_button_margin
))
3026 extra_x
= extra_y
= XINT (Vtool_bar_button_margin
);
3029 top_p
= bot_p
= left_p
= right_p
= false;
3031 if (s
->slice
.x
== 0)
3032 x
-= thick
+ extra_x
, left_p
= true;
3033 if (s
->slice
.y
== 0)
3034 y
-= thick
+ extra_y
, top_p
= true;
3035 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
3036 x1
+= thick
+ extra_x
, right_p
= true;
3037 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
3038 y1
+= thick
+ extra_y
, bot_p
= true;
3040 x_setup_relief_colors (s
);
3041 get_glyph_string_clip_rect (s
, &r
);
3042 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
3043 top_p
, bot_p
, left_p
, right_p
, &r
);
3047 /* Draw the foreground of image glyph string S to PIXMAP. */
3050 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
3053 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
3055 /* If first glyph of S has a left box line, start drawing it to the
3056 right of that line. */
3057 if (s
->face
->box
!= FACE_NO_BOX
3058 && s
->first_glyph
->left_box_line_p
3060 x
+= eabs (s
->face
->box_line_width
);
3062 /* If there is a margin around the image, adjust x- and y-position
3064 if (s
->slice
.x
== 0)
3065 x
+= s
->img
->hmargin
;
3066 if (s
->slice
.y
== 0)
3067 y
+= s
->img
->vmargin
;
3073 /* We can't set both a clip mask and use XSetClipRectangles
3074 because the latter also sets a clip mask. We also can't
3075 trust on the shape extension to be available
3076 (XShapeCombineRegion). So, compute the rectangle to draw
3078 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
3082 xgcv
.clip_mask
= s
->img
->mask
;
3083 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
3084 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
3085 xgcv
.function
= GXcopy
;
3086 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
3088 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3089 s
->slice
.x
, s
->slice
.y
,
3090 s
->slice
.width
, s
->slice
.height
, x
, y
);
3091 XSetClipMask (s
->display
, s
->gc
, None
);
3095 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
3096 s
->slice
.x
, s
->slice
.y
,
3097 s
->slice
.width
, s
->slice
.height
, x
, y
);
3099 /* When the image has a mask, we can expect that at
3100 least part of a mouse highlight or a block cursor will
3101 be visible. If the image doesn't have a mask, make
3102 a block cursor visible by drawing a rectangle around
3103 the image. I believe it's looking better if we do
3104 nothing here for mouse-face. */
3105 if (s
->hl
== DRAW_CURSOR
)
3107 int r
= eabs (s
->img
->relief
);
3108 x_draw_rectangle (s
->f
, s
->gc
, x
- r
, y
- r
,
3109 s
->slice
.width
+ r
*2 - 1,
3110 s
->slice
.height
+ r
*2 - 1);
3115 /* Draw a rectangle if image could not be loaded. */
3116 x_draw_rectangle (s
->f
, s
->gc
, x
, y
,
3117 s
->slice
.width
- 1, s
->slice
.height
- 1);
3121 /* Draw part of the background of glyph string S. X, Y, W, and H
3122 give the rectangle to draw. */
3125 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
3129 /* Fill background with a stipple pattern. */
3130 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3131 x_fill_rectangle (s
->f
, s
->gc
, x
, y
, w
, h
);
3132 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3135 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
3139 /* Draw image glyph string S.
3142 s->x +-------------------------
3145 | +-------------------------
3148 | | +-------------------
3154 x_draw_image_glyph_string (struct glyph_string
*s
)
3156 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
3157 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
3159 Pixmap pixmap
= None
;
3162 if (s
->slice
.y
== 0)
3163 height
-= box_line_vwidth
;
3164 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
3165 height
-= box_line_vwidth
;
3167 /* Fill background with face under the image. Do it only if row is
3168 taller than image or if image has a clip mask to reduce
3170 s
->stippled_p
= s
->face
->stipple
!= 0;
3171 if (height
> s
->slice
.height
3175 || s
->img
->pixmap
== 0
3176 || s
->width
!= s
->background_width
)
3180 /* Create a pixmap as large as the glyph string. Fill it
3181 with the background color. Copy the image to it, using
3182 its mask. Copy the temporary pixmap to the display. */
3183 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
3184 int depth
= DefaultDepthOfScreen (screen
);
3186 /* Create a pixmap as large as the glyph string. */
3187 pixmap
= XCreatePixmap (s
->display
, s
->window
,
3188 s
->background_width
,
3191 /* Don't clip in the following because we're working on the
3193 XSetClipMask (s
->display
, s
->gc
, None
);
3195 /* Fill the pixmap with the background color/stipple. */
3198 /* Fill background with a stipple pattern. */
3199 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
3200 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
3201 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3202 0, 0, s
->background_width
, s
->height
);
3203 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
3204 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
3209 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
3211 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
3212 XFillRectangle (s
->display
, pixmap
, s
->gc
,
3213 0, 0, s
->background_width
, s
->height
);
3214 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3221 int width
= s
->background_width
;
3223 if (s
->first_glyph
->left_box_line_p
3226 x
+= box_line_hwidth
;
3227 width
-= box_line_hwidth
;
3230 if (s
->slice
.y
== 0)
3231 y
+= box_line_vwidth
;
3233 x_draw_glyph_string_bg_rect (s
, x
, y
, width
, height
);
3236 s
->background_filled_p
= true;
3239 /* Draw the foreground. */
3241 if (s
->img
->cr_data
)
3243 cairo_t
*cr
= x_begin_cr_clip (s
->f
, s
->gc
);
3245 int x
= s
->x
+ s
->img
->hmargin
;
3246 int y
= s
->y
+ s
->img
->vmargin
;
3247 int width
= s
->background_width
;
3249 cairo_set_source_surface (cr
, s
->img
->cr_data
,
3252 cairo_rectangle (cr
, x
, y
, width
, height
);
3254 x_end_cr_clip (s
->f
);
3260 x_draw_image_foreground_1 (s
, pixmap
);
3261 x_set_glyph_string_clipping (s
);
3262 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
3263 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
3264 XFreePixmap (s
->display
, pixmap
);
3267 x_draw_image_foreground (s
);
3269 /* If we must draw a relief around the image, do it. */
3271 || s
->hl
== DRAW_IMAGE_RAISED
3272 || s
->hl
== DRAW_IMAGE_SUNKEN
)
3273 x_draw_image_relief (s
);
3277 /* Draw stretch glyph string S. */
3280 x_draw_stretch_glyph_string (struct glyph_string
*s
)
3282 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
3284 if (s
->hl
== DRAW_CURSOR
3285 && !x_stretch_cursor_p
)
3287 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
3288 wide as the stretch glyph. */
3289 int width
, background_width
= s
->background_width
;
3292 if (!s
->row
->reversed_p
)
3294 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3298 background_width
-= left_x
- x
;
3304 /* In R2L rows, draw the cursor on the right edge of the
3306 int right_x
= window_box_right (s
->w
, TEXT_AREA
);
3308 if (x
+ background_width
> right_x
)
3309 background_width
-= x
- right_x
;
3310 x
+= background_width
;
3312 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
3313 if (s
->row
->reversed_p
)
3317 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
3319 /* Clear rest using the GC of the original non-cursor face. */
3320 if (width
< background_width
)
3323 int w
= background_width
- width
, h
= s
->height
;
3327 if (!s
->row
->reversed_p
)
3331 if (s
->row
->mouse_face_p
3332 && cursor_in_mouse_face_p (s
->w
))
3334 x_set_mouse_face_gc (s
);
3340 get_glyph_string_clip_rect (s
, &r
);
3341 x_set_clip_rectangles (s
->f
, gc
, &r
, 1);
3343 if (s
->face
->stipple
)
3345 /* Fill background with a stipple pattern. */
3346 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
3347 x_fill_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3348 XSetFillStyle (s
->display
, gc
, FillSolid
);
3353 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
3354 XSetForeground (s
->display
, gc
, xgcv
.background
);
3355 x_fill_rectangle (s
->f
, gc
, x
, y
, w
, h
);
3356 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
3359 x_reset_clip_rectangles (s
->f
, gc
);
3362 else if (!s
->background_filled_p
)
3364 int background_width
= s
->background_width
;
3365 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
3367 /* Don't draw into left margin, fringe or scrollbar area
3368 except for header line and mode line. */
3369 if (x
< left_x
&& !s
->row
->mode_line_p
)
3371 background_width
-= left_x
- x
;
3374 if (background_width
> 0)
3375 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
3378 s
->background_filled_p
= true;
3382 Draw a wavy line under S. The wave fills wave_height pixels from y0.
3388 wave_height = 3 | * * * *
3393 x_draw_underwave (struct glyph_string
*s
)
3395 int wave_height
= 3, wave_length
= 2;
3397 x_draw_horizontal_wave (s
->f
, s
->gc
, s
->x
, s
->ybase
- wave_height
+ 3,
3398 s
->width
, wave_height
, wave_length
);
3399 #else /* not USE_CAIRO */
3400 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, xmax
;
3402 XRectangle wave_clip
, string_clip
, final_clip
;
3405 dy
= wave_height
- 1;
3407 y0
= s
->ybase
- wave_height
+ 3;
3411 /* Find and set clipping rectangle */
3415 wave_clip
.width
= width
;
3416 wave_clip
.height
= wave_height
;
3417 get_glyph_string_clip_rect (s
, &string_clip
);
3419 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
3422 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
3424 /* Draw the waves */
3426 x1
= x0
- (x0
% dx
);
3428 odd
= (x1
/ dx
) & 1;
3436 if (INT_MAX
- dx
< xmax
)
3441 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
3443 x2
+= dx
, y2
= y0
+ odd
*dy
;
3447 /* Restore previous clipping rectangle(s) */
3448 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
3449 #endif /* not USE_CAIRO */
3453 /* Draw glyph string S. */
3456 x_draw_glyph_string (struct glyph_string
*s
)
3458 bool relief_drawn_p
= false;
3460 /* If S draws into the background of its successors, draw the
3461 background of the successors first so that S can draw into it.
3462 This makes S->next use XDrawString instead of XDrawImageString. */
3463 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
3466 struct glyph_string
*next
;
3468 for (width
= 0, next
= s
->next
;
3469 next
&& width
< s
->right_overhang
;
3470 width
+= next
->width
, next
= next
->next
)
3471 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
3473 x_set_glyph_string_gc (next
);
3474 x_set_glyph_string_clipping (next
);
3475 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
3476 x_draw_stretch_glyph_string (next
);
3478 x_draw_glyph_string_background (next
, true);
3479 next
->num_clips
= 0;
3483 /* Set up S->gc, set clipping and draw S. */
3484 x_set_glyph_string_gc (s
);
3486 /* Draw relief (if any) in advance for char/composition so that the
3487 glyph string can be drawn over it. */
3488 if (!s
->for_overlaps
3489 && s
->face
->box
!= FACE_NO_BOX
3490 && (s
->first_glyph
->type
== CHAR_GLYPH
3491 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
3494 x_set_glyph_string_clipping (s
);
3495 x_draw_glyph_string_background (s
, true);
3496 x_draw_glyph_string_box (s
);
3497 x_set_glyph_string_clipping (s
);
3498 relief_drawn_p
= true;
3500 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
3502 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
3503 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
3504 /* We must clip just this glyph. left_overhang part has already
3505 drawn when s->prev was drawn, and right_overhang part will be
3506 drawn later when s->next is drawn. */
3507 x_set_glyph_string_clipping_exactly (s
, s
);
3509 x_set_glyph_string_clipping (s
);
3511 switch (s
->first_glyph
->type
)
3514 x_draw_image_glyph_string (s
);
3517 #ifdef HAVE_XWIDGETS
3519 x_draw_xwidget_glyph_string (s
);
3524 x_draw_stretch_glyph_string (s
);
3528 if (s
->for_overlaps
)
3529 s
->background_filled_p
= true;
3531 x_draw_glyph_string_background (s
, false);
3532 x_draw_glyph_string_foreground (s
);
3535 case COMPOSITE_GLYPH
:
3536 if (s
->for_overlaps
|| (s
->cmp_from
> 0
3537 && ! s
->first_glyph
->u
.cmp
.automatic
))
3538 s
->background_filled_p
= true;
3540 x_draw_glyph_string_background (s
, true);
3541 x_draw_composite_glyph_string_foreground (s
);
3544 case GLYPHLESS_GLYPH
:
3545 if (s
->for_overlaps
)
3546 s
->background_filled_p
= true;
3548 x_draw_glyph_string_background (s
, true);
3549 x_draw_glyphless_glyph_string_foreground (s
);
3556 if (!s
->for_overlaps
)
3558 /* Draw underline. */
3559 if (s
->face
->underline_p
)
3561 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
3563 if (s
->face
->underline_defaulted_p
)
3564 x_draw_underwave (s
);
3568 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3569 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3570 x_draw_underwave (s
);
3571 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3574 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
3576 unsigned long thickness
, position
;
3579 if (s
->prev
&& s
->prev
->face
->underline_p
3580 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
3582 /* We use the same underline style as the previous one. */
3583 thickness
= s
->prev
->underline_thickness
;
3584 position
= s
->prev
->underline_position
;
3588 /* Get the underline thickness. Default is 1 pixel. */
3589 if (s
->font
&& s
->font
->underline_thickness
> 0)
3590 thickness
= s
->font
->underline_thickness
;
3593 if (x_underline_at_descent_line
)
3594 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
3597 /* Get the underline position. This is the recommended
3598 vertical offset in pixels from the baseline to the top of
3599 the underline. This is a signed value according to the
3600 specs, and its default is
3602 ROUND ((maximum descent) / 2), with
3603 ROUND(x) = floor (x + 0.5) */
3605 if (x_use_underline_position_properties
3606 && s
->font
&& s
->font
->underline_position
>= 0)
3607 position
= s
->font
->underline_position
;
3609 position
= (s
->font
->descent
+ 1) / 2;
3611 position
= underline_minimum_offset
;
3613 position
= max (position
, underline_minimum_offset
);
3615 /* Check the sanity of thickness and position. We should
3616 avoid drawing underline out of the current line area. */
3617 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
3618 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
3619 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
3620 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
3621 s
->underline_thickness
= thickness
;
3622 s
->underline_position
= position
;
3623 y
= s
->ybase
+ position
;
3624 if (s
->face
->underline_defaulted_p
)
3625 x_fill_rectangle (s
->f
, s
->gc
,
3626 s
->x
, y
, s
->width
, thickness
);
3630 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3631 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
3632 x_fill_rectangle (s
->f
, s
->gc
,
3633 s
->x
, y
, s
->width
, thickness
);
3634 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3638 /* Draw overline. */
3639 if (s
->face
->overline_p
)
3641 unsigned long dy
= 0, h
= 1;
3643 if (s
->face
->overline_color_defaulted_p
)
3644 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3649 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3650 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
3651 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3653 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3657 /* Draw strike-through. */
3658 if (s
->face
->strike_through_p
)
3660 unsigned long h
= 1;
3661 unsigned long dy
= (s
->height
- h
) / 2;
3663 if (s
->face
->strike_through_color_defaulted_p
)
3664 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3669 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
3670 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
3671 x_fill_rectangle (s
->f
, s
->gc
, s
->x
, s
->y
+ dy
,
3673 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
3677 /* Draw relief if not yet drawn. */
3678 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
3679 x_draw_glyph_string_box (s
);
3683 struct glyph_string
*prev
;
3685 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
3686 if (prev
->hl
!= s
->hl
3687 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
3689 /* As prev was drawn while clipped to its own area, we
3690 must draw the right_overhang part using s->hl now. */
3691 enum draw_glyphs_face save
= prev
->hl
;
3694 x_set_glyph_string_gc (prev
);
3695 x_set_glyph_string_clipping_exactly (s
, prev
);
3696 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
3697 x_draw_glyph_string_foreground (prev
);
3699 x_draw_composite_glyph_string_foreground (prev
);
3700 x_reset_clip_rectangles (prev
->f
, prev
->gc
);
3702 prev
->num_clips
= 0;
3708 struct glyph_string
*next
;
3710 for (next
= s
->next
; next
; next
= next
->next
)
3711 if (next
->hl
!= s
->hl
3712 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
3714 /* As next will be drawn while clipped to its own area,
3715 we must draw the left_overhang part using s->hl now. */
3716 enum draw_glyphs_face save
= next
->hl
;
3719 x_set_glyph_string_gc (next
);
3720 x_set_glyph_string_clipping_exactly (s
, next
);
3721 if (next
->first_glyph
->type
== CHAR_GLYPH
)
3722 x_draw_glyph_string_foreground (next
);
3724 x_draw_composite_glyph_string_foreground (next
);
3725 x_reset_clip_rectangles (next
->f
, next
->gc
);
3727 next
->num_clips
= 0;
3728 next
->clip_head
= s
->next
;
3733 /* Reset clipping. */
3734 x_reset_clip_rectangles (s
->f
, s
->gc
);
3738 /* Shift display to make room for inserted glyphs. */
3741 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
3743 /* Never called on a GUI frame, see
3744 http://lists.gnu.org/archive/html/emacs-devel/2015-05/msg00456.html
3746 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3747 f
->output_data
.x
->normal_gc
,
3748 x
, y
, width
, height
,
3752 /* Delete N glyphs at the nominal cursor position. Not implemented
3756 x_delete_glyphs (struct frame
*f
, register int n
)
3762 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
3763 If they are <= 0, this is probably an error. */
3766 x_clear_area1 (Display
*dpy
, Window window
,
3767 int x
, int y
, int width
, int height
, int exposures
)
3769 eassert (width
> 0 && height
> 0);
3770 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
3775 x_clear_area (struct frame
*f
, int x
, int y
, int width
, int height
)
3780 eassert (width
> 0 && height
> 0);
3782 cr
= x_begin_cr_clip (f
, NULL
);
3783 x_set_cr_source_with_gc_background (f
, f
->output_data
.x
->normal_gc
);
3784 cairo_rectangle (cr
, x
, y
, width
, height
);
3788 x_clear_area1 (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3789 x
, y
, width
, height
, False
);
3794 /* Clear an entire frame. */
3797 x_clear_frame (struct frame
*f
)
3799 /* Clearing the frame will erase any cursor, so mark them all as no
3801 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3807 /* We have to clear the scroll bars. If we have changed colors or
3808 something like that, then they should be notified. */
3809 x_scroll_bar_clear (f
);
3811 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3812 /* Make sure scroll bars are redrawn. As they aren't redrawn by
3813 redisplay, do it here. */
3814 if (FRAME_GTK_WIDGET (f
))
3815 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
3818 XFlush (FRAME_X_DISPLAY (f
));
3823 /* RIF: Show hourglass cursor on frame F. */
3826 x_show_hourglass (struct frame
*f
)
3828 Display
*dpy
= FRAME_X_DISPLAY (f
);
3832 struct x_output
*x
= FRAME_X_OUTPUT (f
);
3833 #ifdef USE_X_TOOLKIT
3836 if (FRAME_OUTER_WINDOW (f
))
3839 x
->hourglass_p
= true;
3841 if (!x
->hourglass_window
)
3843 unsigned long mask
= CWCursor
;
3844 XSetWindowAttributes attrs
;
3846 Window parent
= FRAME_X_WINDOW (f
);
3848 Window parent
= FRAME_OUTER_WINDOW (f
);
3850 attrs
.cursor
= x
->hourglass_cursor
;
3852 x
->hourglass_window
= XCreateWindow
3853 (dpy
, parent
, 0, 0, 32000, 32000, 0, 0,
3854 InputOnly
, CopyFromParent
, mask
, &attrs
);
3857 XMapRaised (dpy
, x
->hourglass_window
);
3863 /* RIF: Cancel hourglass cursor on frame F. */
3866 x_hide_hourglass (struct frame
*f
)
3868 struct x_output
*x
= FRAME_X_OUTPUT (f
);
3870 /* Watch out for newly created frames. */
3871 if (x
->hourglass_window
)
3873 XUnmapWindow (FRAME_X_DISPLAY (f
), x
->hourglass_window
);
3874 /* Sync here because XTread_socket looks at the
3875 hourglass_p flag that is reset to zero below. */
3876 XSync (FRAME_X_DISPLAY (f
), False
);
3877 x
->hourglass_p
= false;
3881 /* Invert the middle quarter of the frame for .15 sec. */
3884 XTflash (struct frame
*f
)
3890 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
3891 when the scroll bars and the edit widget share the same X window. */
3892 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
3894 cairo_t
*cr
= gdk_cairo_create (window
);
3895 cairo_set_source_rgb (cr
, 1, 1, 1);
3896 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
3897 #define XFillRectangle(d, win, gc, x, y, w, h) \
3899 cairo_rectangle (cr, x, y, w, h); \
3903 #else /* ! HAVE_GTK3 */
3906 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
3907 ^ FRAME_BACKGROUND_PIXEL (f
));
3908 vals
.function
= GDK_XOR
;
3909 gc
= gdk_gc_new_with_values (window
,
3910 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
3911 #define XFillRectangle(d, win, gc, x, y, w, h) \
3912 gdk_draw_rectangle (window, gc, true, x, y, w, h)
3913 #endif /* ! HAVE_GTK3 */
3914 #else /* ! USE_GTK */
3917 /* Create a GC that will use the GXxor function to flip foreground
3918 pixels into background pixels. */
3922 values
.function
= GXxor
;
3923 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3924 ^ FRAME_BACKGROUND_PIXEL (f
));
3926 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3927 GCFunction
| GCForeground
, &values
);
3931 /* Get the height not including a menu bar widget. */
3932 int height
= FRAME_PIXEL_HEIGHT (f
);
3933 /* Height of each line to flash. */
3934 int flash_height
= FRAME_LINE_HEIGHT (f
);
3935 /* These will be the left and right margins of the rectangles. */
3936 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3937 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3938 int width
= flash_right
- flash_left
;
3940 /* If window is tall, flash top and bottom line. */
3941 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3943 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3945 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3946 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3947 width
, flash_height
);
3948 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3950 (height
- flash_height
3951 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3952 width
, flash_height
);
3956 /* If it is short, flash it all. */
3957 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3958 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3959 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3964 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
3965 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
3967 /* Keep waiting until past the time wakeup or any input gets
3969 while (! detect_input_pending ())
3971 struct timespec current
= current_timespec ();
3972 struct timespec timeout
;
3974 /* Break if result would not be positive. */
3975 if (timespec_cmp (wakeup
, current
) <= 0)
3978 /* How long `select' should wait. */
3979 timeout
= make_timespec (0, 10 * 1000 * 1000);
3981 /* Try to wait that long--but we might wake up sooner. */
3982 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3986 /* If window is tall, flash top and bottom line. */
3987 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3989 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3991 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3992 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3993 width
, flash_height
);
3994 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3996 (height
- flash_height
3997 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3998 width
, flash_height
);
4001 /* If it is short, flash it all. */
4002 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
4003 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
4004 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
4010 g_object_unref (G_OBJECT (gc
));
4012 #undef XFillRectangle
4014 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
4025 XTtoggle_invisible_pointer (struct frame
*f
, bool invisible
)
4028 FRAME_DISPLAY_INFO (f
)->toggle_visible_pointer (f
, invisible
);
4033 /* Make audible bell. */
4036 XTring_bell (struct frame
*f
)
4038 if (FRAME_X_DISPLAY (f
))
4046 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
4048 XBell (FRAME_X_DISPLAY (f
), 0);
4050 XFlush (FRAME_X_DISPLAY (f
));
4056 /***********************************************************************
4058 ***********************************************************************/
4060 /* Perform an insert-lines or delete-lines operation, inserting N
4061 lines or deleting -N lines at vertical position VPOS. */
4064 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
4070 /* Scroll part of the display as described by RUN. */
4073 x_scroll_run (struct window
*w
, struct run
*run
)
4075 struct frame
*f
= XFRAME (w
->frame
);
4076 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
4078 /* Get frame-relative bounding box of the text display area of W,
4079 without mode lines. Include in this box the left and right
4081 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
4083 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
4084 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
4085 bottom_y
= y
+ height
;
4089 /* Scrolling up. Make sure we don't copy part of the mode
4090 line at the bottom. */
4091 if (from_y
+ run
->height
> bottom_y
)
4092 height
= bottom_y
- from_y
;
4094 height
= run
->height
;
4098 /* Scrolling down. Make sure we don't copy over the mode line.
4100 if (to_y
+ run
->height
> bottom_y
)
4101 height
= bottom_y
- to_y
;
4103 height
= run
->height
;
4108 /* Cursor off. Will be switched on again in x_update_window_end. */
4112 SET_FRAME_GARBAGED (f
);
4114 XCopyArea (FRAME_X_DISPLAY (f
),
4115 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
4116 f
->output_data
.x
->normal_gc
,
4127 /***********************************************************************
4129 ***********************************************************************/
4133 frame_highlight (struct frame
*f
)
4135 /* We used to only do this if Vx_no_window_manager was non-nil, but
4136 the ICCCM (section 4.1.6) says that the window's border pixmap
4137 and border pixel are window attributes which are "private to the
4138 client", so we can always change it to whatever we want. */
4140 /* I recently started to get errors in this XSetWindowBorder, depending on
4141 the window-manager in use, tho something more is at play since I've been
4142 using that same window-manager binary for ever. Let's not crash just
4143 because of this (bug#9310). */
4144 x_catch_errors (FRAME_X_DISPLAY (f
));
4145 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4146 f
->output_data
.x
->border_pixel
);
4147 x_uncatch_errors ();
4149 x_update_cursor (f
, true);
4150 x_set_frame_alpha (f
);
4154 frame_unhighlight (struct frame
*f
)
4156 /* We used to only do this if Vx_no_window_manager was non-nil, but
4157 the ICCCM (section 4.1.6) says that the window's border pixmap
4158 and border pixel are window attributes which are "private to the
4159 client", so we can always change it to whatever we want. */
4161 /* Same as above for XSetWindowBorder (bug#9310). */
4162 x_catch_errors (FRAME_X_DISPLAY (f
));
4163 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4164 f
->output_data
.x
->border_tile
);
4165 x_uncatch_errors ();
4167 x_update_cursor (f
, true);
4168 x_set_frame_alpha (f
);
4171 /* The focus has changed. Update the frames as necessary to reflect
4172 the new situation. Note that we can't change the selected frame
4173 here, because the Lisp code we are interrupting might become confused.
4174 Each event gets marked with the frame in which it occurred, so the
4175 Lisp code can tell when the switch took place by examining the events. */
4178 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
4180 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
4182 if (frame
!= dpyinfo
->x_focus_frame
)
4184 /* Set this before calling other routines, so that they see
4185 the correct value of x_focus_frame. */
4186 dpyinfo
->x_focus_frame
= frame
;
4188 if (old_focus
&& old_focus
->auto_lower
)
4189 x_lower_frame (old_focus
);
4191 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
4192 dpyinfo
->x_pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
4194 dpyinfo
->x_pending_autoraise_frame
= NULL
;
4197 x_frame_rehighlight (dpyinfo
);
4200 /* Handle FocusIn and FocusOut state changes for FRAME.
4201 If FRAME has focus and there exists more than one frame, puts
4202 a FOCUS_IN_EVENT into *BUFP. */
4205 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
4207 if (type
== FocusIn
)
4209 if (dpyinfo
->x_focus_event_frame
!= frame
)
4211 x_new_focus_frame (dpyinfo
, frame
);
4212 dpyinfo
->x_focus_event_frame
= frame
;
4214 /* Don't stop displaying the initial startup message
4215 for a switch-frame event we don't need. */
4216 /* When run as a daemon, Vterminal_frame is always NIL. */
4217 bufp
->arg
= (((NILP (Vterminal_frame
)
4218 || ! FRAME_X_P (XFRAME (Vterminal_frame
))
4219 || EQ (Fdaemonp (), Qt
))
4220 && CONSP (Vframe_list
)
4221 && !NILP (XCDR (Vframe_list
)))
4223 bufp
->kind
= FOCUS_IN_EVENT
;
4224 XSETFRAME (bufp
->frame_or_window
, frame
);
4227 frame
->output_data
.x
->focus_state
|= state
;
4230 if (FRAME_XIC (frame
))
4231 XSetICFocus (FRAME_XIC (frame
));
4234 else if (type
== FocusOut
)
4236 frame
->output_data
.x
->focus_state
&= ~state
;
4238 if (dpyinfo
->x_focus_event_frame
== frame
)
4240 dpyinfo
->x_focus_event_frame
= 0;
4241 x_new_focus_frame (dpyinfo
, 0);
4243 bufp
->kind
= FOCUS_OUT_EVENT
;
4244 XSETFRAME (bufp
->frame_or_window
, frame
);
4248 if (FRAME_XIC (frame
))
4249 XUnsetICFocus (FRAME_XIC (frame
));
4251 if (frame
->pointer_invisible
)
4252 XTtoggle_invisible_pointer (frame
, false);
4256 /* Return the Emacs frame-object corresponding to an X window.
4257 It could be the frame's main window or an icon window. */
4259 static struct frame
*
4260 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
4262 Lisp_Object tail
, frame
;
4268 FOR_EACH_FRAME (tail
, frame
)
4271 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
4273 if (f
->output_data
.x
->hourglass_window
== wdesc
)
4275 #ifdef USE_X_TOOLKIT
4276 if ((f
->output_data
.x
->edit_widget
4277 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
4278 /* A tooltip frame? */
4279 || (!f
->output_data
.x
->edit_widget
4280 && FRAME_X_WINDOW (f
) == wdesc
)
4281 || f
->output_data
.x
->icon_desc
== wdesc
)
4283 #else /* not USE_X_TOOLKIT */
4285 if (f
->output_data
.x
->edit_widget
)
4287 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
4288 struct x_output
*x
= f
->output_data
.x
;
4289 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
4292 #endif /* USE_GTK */
4293 if (FRAME_X_WINDOW (f
) == wdesc
4294 || f
->output_data
.x
->icon_desc
== wdesc
)
4296 #endif /* not USE_X_TOOLKIT */
4301 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
4303 /* Like x_window_to_frame but also compares the window with the widget's
4306 static struct frame
*
4307 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
4309 Lisp_Object tail
, frame
;
4310 struct frame
*f
, *found
= NULL
;
4316 FOR_EACH_FRAME (tail
, frame
)
4321 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
4323 /* This frame matches if the window is any of its widgets. */
4324 x
= f
->output_data
.x
;
4325 if (x
->hourglass_window
== wdesc
)
4330 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
4332 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
4335 if (wdesc
== XtWindow (x
->widget
)
4336 || wdesc
== XtWindow (x
->column_widget
)
4337 || wdesc
== XtWindow (x
->edit_widget
))
4339 /* Match if the window is this frame's menubar. */
4340 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
4344 else if (FRAME_X_WINDOW (f
) == wdesc
)
4345 /* A tooltip frame. */
4353 /* Likewise, but consider only the menu bar widget. */
4355 static struct frame
*
4356 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
,
4357 const XEvent
*event
)
4359 Window wdesc
= event
->xany
.window
;
4360 Lisp_Object tail
, frame
;
4367 FOR_EACH_FRAME (tail
, frame
)
4370 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
4372 x
= f
->output_data
.x
;
4374 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
4377 /* Match if the window is this frame's menubar. */
4378 if (x
->menubar_widget
4379 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
4386 /* Return the frame whose principal (outermost) window is WDESC.
4387 If WDESC is some other (smaller) window, we return 0. */
4390 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
4392 Lisp_Object tail
, frame
;
4399 FOR_EACH_FRAME (tail
, frame
)
4402 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
4404 x
= f
->output_data
.x
;
4408 /* This frame matches if the window is its topmost widget. */
4410 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
4411 if (gwdesc
== x
->widget
)
4414 if (wdesc
== XtWindow (x
->widget
))
4418 else if (FRAME_X_WINDOW (f
) == wdesc
)
4419 /* Tooltip frame. */
4425 #else /* !USE_X_TOOLKIT && !USE_GTK */
4427 #define x_any_window_to_frame(d, i) x_window_to_frame (d, i)
4428 #define x_top_window_to_frame(d, i) x_window_to_frame (d, i)
4430 #endif /* USE_X_TOOLKIT || USE_GTK */
4432 /* The focus may have changed. Figure out if it is a real focus change,
4433 by checking both FocusIn/Out and Enter/LeaveNotify events.
4435 Returns FOCUS_IN_EVENT event in *BUFP. */
4438 x_detect_focus_change (struct x_display_info
*dpyinfo
, struct frame
*frame
,
4439 const XEvent
*event
, struct input_event
*bufp
)
4444 switch (event
->type
)
4449 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
4451 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
4453 if (event
->xcrossing
.detail
!= NotifyInferior
4454 && event
->xcrossing
.focus
4455 && ! (focus_state
& FOCUS_EXPLICIT
))
4456 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
4458 dpyinfo
, frame
, bufp
);
4464 x_focus_changed (event
->type
,
4465 (event
->xfocus
.detail
== NotifyPointer
?
4466 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
4467 dpyinfo
, frame
, bufp
);
4471 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
4473 enum xembed_message msg
= event
->xclient
.data
.l
[1];
4474 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
4475 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
4482 #if !defined USE_X_TOOLKIT && !defined USE_GTK
4483 /* Handle an event saying the mouse has moved out of an Emacs frame. */
4486 x_mouse_leave (struct x_display_info
*dpyinfo
)
4488 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
4492 /* The focus has changed, or we have redirected a frame's focus to
4493 another frame (this happens when a frame uses a surrogate
4494 mini-buffer frame). Shift the highlight as appropriate.
4496 The FRAME argument doesn't necessarily have anything to do with which
4497 frame is being highlighted or un-highlighted; we only use it to find
4498 the appropriate X display info. */
4501 XTframe_rehighlight (struct frame
*frame
)
4503 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
4507 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
4509 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
4511 if (dpyinfo
->x_focus_frame
)
4513 dpyinfo
->x_highlight_frame
4514 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
4515 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
4516 : dpyinfo
->x_focus_frame
);
4517 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
4519 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
4520 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
4524 dpyinfo
->x_highlight_frame
= 0;
4526 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
4529 frame_unhighlight (old_highlight
);
4530 if (dpyinfo
->x_highlight_frame
)
4531 frame_highlight (dpyinfo
->x_highlight_frame
);
4537 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
4539 /* Initialize mode_switch_bit and modifier_meaning. */
4541 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
4543 int min_code
, max_code
;
4546 XModifierKeymap
*mods
;
4548 dpyinfo
->meta_mod_mask
= 0;
4549 dpyinfo
->shift_lock_mask
= 0;
4550 dpyinfo
->alt_mod_mask
= 0;
4551 dpyinfo
->super_mod_mask
= 0;
4552 dpyinfo
->hyper_mod_mask
= 0;
4554 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
4556 syms
= XGetKeyboardMapping (dpyinfo
->display
,
4557 min_code
, max_code
- min_code
+ 1,
4559 mods
= XGetModifierMapping (dpyinfo
->display
);
4561 /* Scan the modifier table to see which modifier bits the Meta and
4562 Alt keysyms are on. */
4564 int row
, col
; /* The row and column in the modifier table. */
4565 bool found_alt_or_meta
;
4567 for (row
= 3; row
< 8; row
++)
4569 found_alt_or_meta
= false;
4570 for (col
= 0; col
< mods
->max_keypermod
; col
++)
4572 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
4574 /* Zeroes are used for filler. Skip them. */
4578 /* Are any of this keycode's keysyms a meta key? */
4582 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
4584 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
4590 found_alt_or_meta
= true;
4591 dpyinfo
->meta_mod_mask
|= (1 << row
);
4596 found_alt_or_meta
= true;
4597 dpyinfo
->alt_mod_mask
|= (1 << row
);
4602 if (!found_alt_or_meta
)
4603 dpyinfo
->hyper_mod_mask
|= (1 << row
);
4604 code_col
= syms_per_code
;
4605 col
= mods
->max_keypermod
;
4610 if (!found_alt_or_meta
)
4611 dpyinfo
->super_mod_mask
|= (1 << row
);
4612 code_col
= syms_per_code
;
4613 col
= mods
->max_keypermod
;
4617 /* Ignore this if it's not on the lock modifier. */
4618 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
4619 dpyinfo
->shift_lock_mask
= LockMask
;
4620 code_col
= syms_per_code
;
4621 col
= mods
->max_keypermod
;
4630 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
4631 if (! dpyinfo
->meta_mod_mask
)
4633 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
4634 dpyinfo
->alt_mod_mask
= 0;
4637 /* If some keys are both alt and meta,
4638 make them just meta, not alt. */
4639 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
4641 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
4645 XFreeModifiermap (mods
);
4648 /* Convert between the modifier bits X uses and the modifier bits
4652 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
4654 int mod_meta
= meta_modifier
;
4655 int mod_alt
= alt_modifier
;
4656 int mod_hyper
= hyper_modifier
;
4657 int mod_super
= super_modifier
;
4660 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
4661 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
4662 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
4663 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
4664 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
4665 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
4666 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
4667 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
4669 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
4670 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
4671 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
4672 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
4673 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
4674 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
4678 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
4680 EMACS_INT mod_meta
= meta_modifier
;
4681 EMACS_INT mod_alt
= alt_modifier
;
4682 EMACS_INT mod_hyper
= hyper_modifier
;
4683 EMACS_INT mod_super
= super_modifier
;
4687 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
4688 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
4689 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
4690 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
4691 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
4692 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
4693 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
4694 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
4697 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
4698 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
4699 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
4700 | ((state
& shift_modifier
) ? ShiftMask
: 0)
4701 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
4702 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
4705 /* Convert a keysym to its name. */
4708 x_get_keysym_name (int keysym
)
4713 value
= XKeysymToString (keysym
);
4719 /* Mouse clicks and mouse movement. Rah.
4721 Formerly, we used PointerMotionHintMask (in standard_event_mask)
4722 so that we would have to call XQueryPointer after each MotionNotify
4723 event to ask for another such event. However, this made mouse tracking
4724 slow, and there was a bug that made it eventually stop.
4726 Simply asking for MotionNotify all the time seems to work better.
4728 In order to avoid asking for motion events and then throwing most
4729 of them away or busy-polling the server for mouse positions, we ask
4730 the server for pointer motion hints. This means that we get only
4731 one event per group of mouse movements. "Groups" are delimited by
4732 other kinds of events (focus changes and button clicks, for
4733 example), or by XQueryPointer calls; when one of these happens, we
4734 get another MotionNotify event the next time the mouse moves. This
4735 is at least as efficient as getting motion events when mouse
4736 tracking is on, and I suspect only negligibly worse when tracking
4739 /* Prepare a mouse-event in *RESULT for placement in the input queue.
4741 If the event is a button press, then note that we have grabbed
4745 construct_mouse_click (struct input_event
*result
,
4746 const XButtonEvent
*event
,
4749 /* Make the event type NO_EVENT; we'll change that when we decide
4751 result
->kind
= MOUSE_CLICK_EVENT
;
4752 result
->code
= event
->button
- Button1
;
4753 result
->timestamp
= event
->time
;
4754 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
),
4756 | (event
->type
== ButtonRelease
4760 XSETINT (result
->x
, event
->x
);
4761 XSETINT (result
->y
, event
->y
);
4762 XSETFRAME (result
->frame_or_window
, f
);
4767 /* Function to report a mouse movement to the mainstream Emacs code.
4768 The input handler calls this.
4770 We have received a mouse movement event, which is given in *event.
4771 If the mouse is over a different glyph than it was last time, tell
4772 the mainstream emacs code by setting mouse_moved. If not, ask for
4773 another motion event, so we can check again the next time it moves. */
4776 note_mouse_movement (struct frame
*frame
, const XMotionEvent
*event
)
4779 struct x_display_info
*dpyinfo
;
4781 if (!FRAME_X_OUTPUT (frame
))
4784 dpyinfo
= FRAME_DISPLAY_INFO (frame
);
4785 dpyinfo
->last_mouse_movement_time
= event
->time
;
4786 dpyinfo
->last_mouse_motion_frame
= frame
;
4787 dpyinfo
->last_mouse_motion_x
= event
->x
;
4788 dpyinfo
->last_mouse_motion_y
= event
->y
;
4790 if (event
->window
!= FRAME_X_WINDOW (frame
))
4792 frame
->mouse_moved
= true;
4793 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4794 note_mouse_highlight (frame
, -1, -1);
4795 dpyinfo
->last_mouse_glyph_frame
= NULL
;
4800 /* Has the mouse moved off the glyph it was on at the last sighting? */
4801 r
= &dpyinfo
->last_mouse_glyph
;
4802 if (frame
!= dpyinfo
->last_mouse_glyph_frame
4803 || event
->x
< r
->x
|| event
->x
>= r
->x
+ r
->width
4804 || event
->y
< r
->y
|| event
->y
>= r
->y
+ r
->height
)
4806 frame
->mouse_moved
= true;
4807 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4808 note_mouse_highlight (frame
, event
->x
, event
->y
);
4809 /* Remember which glyph we're now on. */
4810 remember_mouse_glyph (frame
, event
->x
, event
->y
, r
);
4811 dpyinfo
->last_mouse_glyph_frame
= frame
;
4818 /* Return the current position of the mouse.
4819 *FP should be a frame which indicates which display to ask about.
4821 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
4822 and *PART to the frame, window, and scroll bar part that the mouse
4823 is over. Set *X and *Y to the portion and whole of the mouse's
4824 position on the scroll bar.
4826 If the mouse movement started elsewhere, set *FP to the frame the
4827 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
4830 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
4831 was at this position.
4833 Don't store anything if we don't have a valid set of values to report.
4835 This clears the mouse_moved flag, so we can wait for the next mouse
4839 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
4840 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
4844 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
4848 if (dpyinfo
->last_mouse_scroll_bar
&& insist
== 0)
4850 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
4852 if (bar
->horizontal
)
4853 x_horizontal_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
4855 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
4862 Window dummy_window
;
4865 Lisp_Object frame
, tail
;
4867 /* Clear the mouse-moved flag for every frame on this display. */
4868 FOR_EACH_FRAME (tail
, frame
)
4869 if (FRAME_X_P (XFRAME (frame
))
4870 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
4871 XFRAME (frame
)->mouse_moved
= false;
4873 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4875 /* Figure out which root window we're on. */
4876 XQueryPointer (FRAME_X_DISPLAY (*fp
),
4877 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
4879 /* The root window which contains the pointer. */
4882 /* Trash which we can't trust if the pointer is on
4883 a different screen. */
4886 /* The position on that root window. */
4889 /* More trash we can't trust. */
4892 /* Modifier keys and pointer buttons, about which
4894 (unsigned int *) &dummy
);
4896 /* Now we have a position on the root; find the innermost window
4897 containing the pointer. */
4901 int parent_x
= 0, parent_y
= 0;
4905 /* XTranslateCoordinates can get errors if the window
4906 structure is changing at the same time this function
4907 is running. So at least we must not crash from them. */
4909 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4911 if (x_mouse_grabbed (dpyinfo
))
4913 /* If mouse was grabbed on a frame, give coords for that frame
4914 even if the mouse is now outside it. */
4915 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4921 FRAME_X_WINDOW (dpyinfo
->last_mouse_frame
),
4923 /* From-position, to-position. */
4924 root_x
, root_y
, &win_x
, &win_y
,
4928 f1
= dpyinfo
->last_mouse_frame
;
4934 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4936 /* From-window, to-window. */
4939 /* From-position, to-position. */
4940 root_x
, root_y
, &win_x
, &win_y
,
4945 if (child
== None
|| child
== win
)
4948 /* We don't wan't to know the innermost window. We
4949 want the edit window. For non-Gtk+ the innermost
4950 window is the edit window. For Gtk+ it might not
4951 be. It might be the tool bar for example. */
4952 if (x_window_to_frame (dpyinfo
, win
))
4960 /* Now we know that:
4961 win is the innermost window containing the pointer
4962 (XTC says it has no child containing the pointer),
4963 win_x and win_y are the pointer's position in it
4964 (XTC did this the last time through), and
4965 parent_x and parent_y are the pointer's position in win's parent.
4966 (They are what win_x and win_y were when win was child.
4967 If win is the root window, it has no parent, and
4968 parent_{x,y} are invalid, but that's okay, because we'll
4969 never use them in that case.) */
4972 /* We don't wan't to know the innermost window. We
4973 want the edit window. */
4974 f1
= x_window_to_frame (dpyinfo
, win
);
4976 /* Is win one of our frames? */
4977 f1
= x_any_window_to_frame (dpyinfo
, win
);
4980 #ifdef USE_X_TOOLKIT
4981 /* If we end up with the menu bar window, say it's not
4984 && f1
->output_data
.x
->menubar_widget
4985 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4987 #endif /* USE_X_TOOLKIT */
4990 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4993 x_uncatch_errors_after_check ();
4995 /* If not, is it one of our scroll bars? */
4998 struct scroll_bar
*bar
;
5000 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
, 2);
5004 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5010 if (f1
== 0 && insist
> 0)
5011 f1
= SELECTED_FRAME ();
5015 /* Ok, we found a frame. Store all the values.
5016 last_mouse_glyph is a rectangle used to reduce the
5017 generation of mouse events. To not miss any motion
5018 events, we must divide the frame into rectangles of the
5019 size of the smallest character that could be displayed
5020 on it, i.e. into the same rectangles that matrices on
5021 the frame are divided into. */
5023 /* FIXME: what if F1 is not an X frame? */
5024 dpyinfo
= FRAME_DISPLAY_INFO (f1
);
5025 remember_mouse_glyph (f1
, win_x
, win_y
, &dpyinfo
->last_mouse_glyph
);
5026 dpyinfo
->last_mouse_glyph_frame
= f1
;
5031 XSETINT (*x
, win_x
);
5032 XSETINT (*y
, win_y
);
5033 *timestamp
= dpyinfo
->last_mouse_movement_time
;
5043 /***********************************************************************
5045 ***********************************************************************/
5047 /* Scroll bar support. */
5049 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
5051 This can be called in GC, so we have to make sure to strip off mark
5054 static struct scroll_bar
*
5055 x_window_to_scroll_bar (Display
*display
, Window window_id
, int type
)
5057 Lisp_Object tail
, frame
;
5059 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
5060 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
5061 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
5063 FOR_EACH_FRAME (tail
, frame
)
5065 Lisp_Object bar
, condemned
;
5067 if (! FRAME_X_P (XFRAME (frame
)))
5070 /* Scan this frame's scroll bar list for a scroll bar with the
5072 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
5073 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
5074 /* This trick allows us to search both the ordinary and
5075 condemned scroll bar lists with one loop. */
5076 ! NILP (bar
) || (bar
= condemned
,
5079 bar
= XSCROLL_BAR (bar
)->next
)
5080 if (XSCROLL_BAR (bar
)->x_window
== window_id
5081 && FRAME_X_DISPLAY (XFRAME (frame
)) == display
5083 || (type
== 1 && XSCROLL_BAR (bar
)->horizontal
)
5084 || (type
== 0 && !XSCROLL_BAR (bar
)->horizontal
)))
5085 return XSCROLL_BAR (bar
);
5092 #if defined USE_LUCID
5094 /* Return the Lucid menu bar WINDOW is part of. Return null
5095 if WINDOW is not part of a menu bar. */
5098 x_window_to_menu_bar (Window window
)
5100 Lisp_Object tail
, frame
;
5102 FOR_EACH_FRAME (tail
, frame
)
5103 if (FRAME_X_P (XFRAME (frame
)))
5105 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
5107 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
5113 #endif /* USE_LUCID */
5116 /************************************************************************
5118 ************************************************************************/
5120 #ifdef USE_TOOLKIT_SCROLL_BARS
5122 static void x_send_scroll_bar_event (Lisp_Object
, enum scroll_bar_part
,
5125 /* Lisp window being scrolled. Set when starting to interact with
5126 a toolkit scroll bar, reset to nil when ending the interaction. */
5128 static Lisp_Object window_being_scrolled
;
5130 /* Whether this is an Xaw with arrow-scrollbars. This should imply
5131 that movements of 1/20 of the screen size are mapped to up/down. */
5134 /* Id of action hook installed for scroll bars. */
5136 static XtActionHookId action_hook_id
;
5137 static XtActionHookId horizontal_action_hook_id
;
5139 static Boolean xaw3d_arrow_scroll
;
5141 /* Whether the drag scrolling maintains the mouse at the top of the
5142 thumb. If not, resizing the thumb needs to be done more carefully
5143 to avoid jerkiness. */
5145 static Boolean xaw3d_pick_top
;
5147 /* Action hook installed via XtAppAddActionHook when toolkit scroll
5148 bars are used.. The hook is responsible for detecting when
5149 the user ends an interaction with the scroll bar, and generates
5150 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
5153 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
5154 XEvent
*event
, String
*params
, Cardinal
*num_params
)
5157 const char *end_action
;
5160 scroll_bar_p
= XmIsScrollBar (widget
);
5161 end_action
= "Release";
5162 #else /* !USE_MOTIF i.e. use Xaw */
5163 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
5164 end_action
= "EndScroll";
5165 #endif /* USE_MOTIF */
5168 && strcmp (action_name
, end_action
) == 0
5169 && WINDOWP (window_being_scrolled
))
5172 struct scroll_bar
*bar
;
5174 x_send_scroll_bar_event (window_being_scrolled
,
5175 scroll_bar_end_scroll
, 0, 0, false);
5176 w
= XWINDOW (window_being_scrolled
);
5177 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5179 if (bar
->dragging
!= -1)
5182 /* The thumb size is incorrect while dragging: fix it. */
5183 set_vertical_scroll_bar (w
);
5185 window_being_scrolled
= Qnil
;
5186 #if defined (USE_LUCID)
5187 bar
->last_seen_part
= scroll_bar_nowhere
;
5189 /* Xt timeouts no longer needed. */
5190 toolkit_scroll_bar_interaction
= false;
5196 xt_horizontal_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
5197 XEvent
*event
, String
*params
, Cardinal
*num_params
)
5200 const char *end_action
;
5203 scroll_bar_p
= XmIsScrollBar (widget
);
5204 end_action
= "Release";
5205 #else /* !USE_MOTIF i.e. use Xaw */
5206 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
5207 end_action
= "EndScroll";
5208 #endif /* USE_MOTIF */
5211 && strcmp (action_name
, end_action
) == 0
5212 && WINDOWP (window_being_scrolled
))
5215 struct scroll_bar
*bar
;
5217 x_send_scroll_bar_event (window_being_scrolled
,
5218 scroll_bar_end_scroll
, 0, 0, true);
5219 w
= XWINDOW (window_being_scrolled
);
5220 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
5222 if (bar
->dragging
!= -1)
5225 /* The thumb size is incorrect while dragging: fix it. */
5226 set_horizontal_scroll_bar (w
);
5228 window_being_scrolled
= Qnil
;
5229 #if defined (USE_LUCID)
5230 bar
->last_seen_part
= scroll_bar_nowhere
;
5232 /* Xt timeouts no longer needed. */
5233 toolkit_scroll_bar_interaction
= false;
5236 #endif /* not USE_GTK */
5238 /* Send a client message with message type Xatom_Scrollbar for a
5239 scroll action to the frame of WINDOW. PART is a value identifying
5240 the part of the scroll bar that was clicked on. PORTION is the
5241 amount to scroll of a whole of WHOLE. */
5244 x_send_scroll_bar_event (Lisp_Object window
, enum scroll_bar_part part
,
5245 int portion
, int whole
, bool horizontal
)
5248 XClientMessageEvent
*ev
= &event
.xclient
;
5249 struct window
*w
= XWINDOW (window
);
5250 struct frame
*f
= XFRAME (w
->frame
);
5251 intptr_t iw
= (intptr_t) w
;
5252 enum { BITS_PER_INTPTR
= CHAR_BIT
* sizeof iw
};
5253 verify (BITS_PER_INTPTR
<= 64);
5254 int sign_shift
= BITS_PER_INTPTR
- 32;
5258 /* Construct a ClientMessage event to send to the frame. */
5259 ev
->type
= ClientMessage
;
5260 ev
->message_type
= (horizontal
5261 ? FRAME_DISPLAY_INFO (f
)->Xatom_Horizontal_Scrollbar
5262 : FRAME_DISPLAY_INFO (f
)->Xatom_Scrollbar
);
5263 ev
->display
= FRAME_X_DISPLAY (f
);
5264 ev
->window
= FRAME_X_WINDOW (f
);
5267 /* A 32-bit X client on a 64-bit X server can pass a window pointer
5268 as-is. A 64-bit client on a 32-bit X server is in trouble
5269 because a pointer does not fit and would be truncated while
5270 passing through the server. So use two slots and hope that X12
5271 will resolve such issues someday. */
5272 ev
->data
.l
[0] = iw
>> 31 >> 1;
5273 ev
->data
.l
[1] = sign_shift
<= 0 ? iw
: iw
<< sign_shift
>> sign_shift
;
5274 ev
->data
.l
[2] = part
;
5275 ev
->data
.l
[3] = portion
;
5276 ev
->data
.l
[4] = whole
;
5278 /* Make Xt timeouts work while the scroll bar is active. */
5279 #ifdef USE_X_TOOLKIT
5280 toolkit_scroll_bar_interaction
= true;
5281 x_activate_timeout_atimer ();
5284 /* Setting the event mask to zero means that the message will
5285 be sent to the client that created the window, and if that
5286 window no longer exists, no event will be sent. */
5287 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
5292 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
5296 x_scroll_bar_to_input_event (const XEvent
*event
,
5297 struct input_event
*ievent
)
5299 const XClientMessageEvent
*ev
= &event
->xclient
;
5303 /* See the comment in the function above. */
5304 intptr_t iw0
= ev
->data
.l
[0];
5305 intptr_t iw1
= ev
->data
.l
[1];
5306 intptr_t iw
= (iw0
<< 31 << 1) + (iw1
& 0xffffffffu
);
5307 w
= (struct window
*) iw
;
5309 XSETWINDOW (window
, w
);
5311 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
5312 ievent
->frame_or_window
= window
;
5315 ievent
->timestamp
= CurrentTime
;
5318 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
5321 ievent
->part
= ev
->data
.l
[2];
5322 ievent
->x
= make_number (ev
->data
.l
[3]);
5323 ievent
->y
= make_number (ev
->data
.l
[4]);
5324 ievent
->modifiers
= 0;
5327 /* Transform a horizontal scroll bar ClientMessage EVENT to an Emacs
5328 input event in *IEVENT. */
5331 x_horizontal_scroll_bar_to_input_event (const XEvent
*event
,
5332 struct input_event
*ievent
)
5334 const XClientMessageEvent
*ev
= &event
->xclient
;
5338 /* See the comment in the function above. */
5339 intptr_t iw0
= ev
->data
.l
[0];
5340 intptr_t iw1
= ev
->data
.l
[1];
5341 intptr_t iw
= (iw0
<< 31 << 1) + (iw1
& 0xffffffffu
);
5342 w
= (struct window
*) iw
;
5344 XSETWINDOW (window
, w
);
5346 ievent
->kind
= HORIZONTAL_SCROLL_BAR_CLICK_EVENT
;
5347 ievent
->frame_or_window
= window
;
5350 ievent
->timestamp
= CurrentTime
;
5353 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
5356 ievent
->part
= ev
->data
.l
[2];
5357 ievent
->x
= make_number (ev
->data
.l
[3]);
5358 ievent
->y
= make_number (ev
->data
.l
[4]);
5359 ievent
->modifiers
= 0;
5365 /* Minimum and maximum values used for Motif scroll bars. */
5367 #define XM_SB_MAX 10000000
5369 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
5370 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
5371 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
5374 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5376 struct scroll_bar
*bar
= client_data
;
5377 XmScrollBarCallbackStruct
*cs
= call_data
;
5378 enum scroll_bar_part part
= scroll_bar_nowhere
;
5379 bool horizontal
= bar
->horizontal
;
5380 int whole
= 0, portion
= 0;
5384 case XmCR_DECREMENT
:
5386 part
= horizontal
? scroll_bar_left_arrow
: scroll_bar_up_arrow
;
5389 case XmCR_INCREMENT
:
5391 part
= horizontal
? scroll_bar_right_arrow
: scroll_bar_down_arrow
;
5394 case XmCR_PAGE_DECREMENT
:
5396 part
= horizontal
? scroll_bar_before_handle
: scroll_bar_above_handle
;
5399 case XmCR_PAGE_INCREMENT
:
5401 part
= horizontal
? scroll_bar_after_handle
: scroll_bar_below_handle
;
5406 part
= horizontal
? scroll_bar_to_leftmost
: scroll_bar_to_top
;
5409 case XmCR_TO_BOTTOM
:
5411 part
= horizontal
? scroll_bar_to_rightmost
: scroll_bar_to_bottom
;
5419 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
5424 portion
= bar
->whole
* ((float)cs
->value
/ XM_SB_MAX
);
5425 whole
= bar
->whole
* ((float)(XM_SB_MAX
- slider_size
) / XM_SB_MAX
);
5426 portion
= min (portion
, whole
);
5427 part
= scroll_bar_horizontal_handle
;
5431 whole
= XM_SB_MAX
- slider_size
;
5432 portion
= min (cs
->value
, whole
);
5433 part
= scroll_bar_handle
;
5436 bar
->dragging
= cs
->value
;
5440 case XmCR_VALUE_CHANGED
:
5444 if (part
!= scroll_bar_nowhere
)
5446 window_being_scrolled
= bar
->window
;
5447 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
,
5452 #elif defined USE_GTK
5454 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
5455 bar widget. DATA is a pointer to the scroll_bar structure. */
5458 xg_scroll_callback (GtkRange
*range
,
5459 GtkScrollType scroll
,
5463 int whole
= 0, portion
= 0;
5464 struct scroll_bar
*bar
= user_data
;
5465 enum scroll_bar_part part
= scroll_bar_nowhere
;
5466 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
5467 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
5469 if (xg_ignore_gtk_scrollbar
) return false;
5473 case GTK_SCROLL_JUMP
:
5474 /* Buttons 1 2 or 3 must be grabbed. */
5475 if (FRAME_DISPLAY_INFO (f
)->grabbed
!= 0
5476 && FRAME_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
5478 if (bar
->horizontal
)
5480 part
= scroll_bar_horizontal_handle
;
5481 whole
= (int)(gtk_adjustment_get_upper (adj
) -
5482 gtk_adjustment_get_page_size (adj
));
5483 portion
= min ((int)value
, whole
);
5484 bar
->dragging
= portion
;
5488 part
= scroll_bar_handle
;
5489 whole
= gtk_adjustment_get_upper (adj
) -
5490 gtk_adjustment_get_page_size (adj
);
5491 portion
= min ((int)value
, whole
);
5492 bar
->dragging
= portion
;
5496 case GTK_SCROLL_STEP_BACKWARD
:
5497 part
= (bar
->horizontal
5498 ? scroll_bar_left_arrow
: scroll_bar_up_arrow
);
5501 case GTK_SCROLL_STEP_FORWARD
:
5502 part
= (bar
->horizontal
5503 ? scroll_bar_right_arrow
: scroll_bar_down_arrow
);
5506 case GTK_SCROLL_PAGE_BACKWARD
:
5507 part
= (bar
->horizontal
5508 ? scroll_bar_before_handle
: scroll_bar_above_handle
);
5511 case GTK_SCROLL_PAGE_FORWARD
:
5512 part
= (bar
->horizontal
5513 ? scroll_bar_after_handle
: scroll_bar_below_handle
);
5520 if (part
!= scroll_bar_nowhere
)
5522 window_being_scrolled
= bar
->window
;
5523 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
,
5530 /* Callback for button release. Sets dragging to -1 when dragging is done. */
5533 xg_end_scroll_callback (GtkWidget
*widget
,
5534 GdkEventButton
*event
,
5537 struct scroll_bar
*bar
= user_data
;
5539 if (WINDOWP (window_being_scrolled
))
5541 x_send_scroll_bar_event (window_being_scrolled
,
5542 scroll_bar_end_scroll
, 0, 0, bar
->horizontal
);
5543 window_being_scrolled
= Qnil
;
5550 #else /* not USE_GTK and not USE_MOTIF */
5552 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
5553 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
5554 scroll bar struct. CALL_DATA is a pointer to a float saying where
5558 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5560 struct scroll_bar
*bar
= client_data
;
5561 float *top_addr
= call_data
;
5562 float top
= *top_addr
;
5564 int whole
, portion
, height
, width
;
5565 enum scroll_bar_part part
;
5566 bool horizontal
= bar
->horizontal
;
5571 /* Get the size of the thumb, a value between 0 and 1. */
5573 XtVaGetValues (widget
, XtNshown
, &shown
, XtNwidth
, &width
, NULL
);
5578 whole
= bar
->whole
- (shown
* bar
->whole
);
5579 portion
= min (top
* bar
->whole
, whole
);
5587 part
= scroll_bar_horizontal_handle
;
5591 /* Get the size of the thumb, a value between 0 and 1. */
5593 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
5597 portion
= shown
< 1 ? top
* whole
: 0;
5599 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
5600 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
5601 the bottom, so we force the scrolling whenever we see that we're
5602 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
5603 we try to ensure that we always stay two pixels away from the
5605 part
= scroll_bar_down_arrow
;
5607 part
= scroll_bar_handle
;
5610 window_being_scrolled
= bar
->window
;
5611 bar
->dragging
= portion
;
5612 bar
->last_seen_part
= part
;
5613 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
, bar
->horizontal
);
5617 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
5618 i.e. line or page up or down. WIDGET is the Xaw scroll bar
5619 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
5620 the scroll bar. CALL_DATA is an integer specifying the action that
5621 has taken place. Its magnitude is in the range 0..height of the
5622 scroll bar. Negative values mean scroll towards buffer start.
5623 Values < height of scroll bar mean line-wise movement. */
5626 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
5628 struct scroll_bar
*bar
= client_data
;
5629 /* The position really is stored cast to a pointer. */
5630 int position
= (intptr_t) call_data
;
5631 Dimension height
, width
;
5632 enum scroll_bar_part part
;
5634 if (bar
->horizontal
)
5636 /* Get the width of the scroll bar. */
5638 XtVaGetValues (widget
, XtNwidth
, &width
, NULL
);
5641 if (eabs (position
) >= width
)
5642 part
= (position
< 0) ? scroll_bar_before_handle
: scroll_bar_after_handle
;
5644 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
5645 it maps line-movement to call_data = max(5, height/20). */
5646 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, width
/ 20))
5647 part
= (position
< 0) ? scroll_bar_left_arrow
: scroll_bar_right_arrow
;
5649 part
= scroll_bar_move_ratio
;
5651 window_being_scrolled
= bar
->window
;
5653 bar
->last_seen_part
= part
;
5654 x_send_scroll_bar_event (bar
->window
, part
, position
, width
,
5660 /* Get the height of the scroll bar. */
5662 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
5665 if (eabs (position
) >= height
)
5666 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
5668 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
5669 it maps line-movement to call_data = max(5, height/20). */
5670 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
5671 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
5673 part
= scroll_bar_move_ratio
;
5675 window_being_scrolled
= bar
->window
;
5677 bar
->last_seen_part
= part
;
5678 x_send_scroll_bar_event (bar
->window
, part
, position
, height
,
5683 #endif /* not USE_GTK and not USE_MOTIF */
5685 #define SCROLL_BAR_NAME "verticalScrollBar"
5686 #define SCROLL_BAR_HORIZONTAL_NAME "horizontalScrollBar"
5688 /* Create the widget for scroll bar BAR on frame F. Record the widget
5689 and X window of the scroll bar in BAR. */
5693 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5695 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
5698 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
5699 G_CALLBACK (xg_end_scroll_callback
),
5705 x_create_horizontal_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5707 const char *scroll_bar_name
= SCROLL_BAR_HORIZONTAL_NAME
;
5710 xg_create_horizontal_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
5711 G_CALLBACK (xg_end_scroll_callback
),
5716 #else /* not USE_GTK */
5719 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5725 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
5726 unsigned long pixel
;
5731 /* Set resources. Create the widget. */
5732 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5733 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
5734 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
5735 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
5736 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
5737 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
5738 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
5740 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5743 XtSetArg (av
[ac
], XmNforeground
, pixel
);
5747 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5750 XtSetArg (av
[ac
], XmNbackground
, pixel
);
5754 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
5755 (char *) scroll_bar_name
, av
, ac
);
5757 /* Add one callback for everything that can happen. */
5758 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
5760 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
5762 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
5764 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
5766 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
5768 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
5770 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
5773 /* Realize the widget. Only after that is the X window created. */
5774 XtRealizeWidget (widget
);
5776 /* Set the cursor to an arrow. I didn't find a resource to do that.
5777 And I'm wondering why it hasn't an arrow cursor by default. */
5778 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
5779 f
->output_data
.x
->nontext_cursor
);
5781 #else /* !USE_MOTIF i.e. use Xaw */
5783 /* Set resources. Create the widget. The background of the
5784 Xaw3d scroll bar widget is a little bit light for my taste.
5785 We don't alter it here to let users change it according
5786 to their taste with `emacs*verticalScrollBar.background: xxx'. */
5787 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5788 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
5789 /* For smoother scrolling with Xaw3d -sm */
5790 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
5792 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5795 XtSetArg (av
[ac
], XtNforeground
, pixel
);
5799 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5802 XtSetArg (av
[ac
], XtNbackground
, pixel
);
5806 /* Top/bottom shadow colors. */
5808 /* Allocate them, if necessary. */
5809 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
5811 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5814 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
5815 FRAME_X_COLORMAP (f
),
5816 &pixel
, 1.2, 0x8000))
5818 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
5821 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
5823 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5826 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
5827 FRAME_X_COLORMAP (f
),
5828 &pixel
, 0.6, 0x4000))
5830 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
5834 #ifdef XtNbeNiceToColormap
5835 /* Tell the toolkit about them. */
5836 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
5837 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
5838 /* We tried to allocate a color for the top/bottom shadow, and
5839 failed, so tell Xaw3d to use dithering instead. */
5840 /* But only if we have a small colormap. Xaw3d can allocate nice
5843 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
5844 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
5848 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
5849 be more consistent with other emacs 3d colors, and since Xaw3d is
5850 not good at dealing with allocation failure. */
5852 /* This tells Xaw3d to use real colors instead of dithering for
5854 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
5857 /* Specify the colors. */
5858 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
5861 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
5864 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
5867 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
5873 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
5874 f
->output_data
.x
->edit_widget
, av
, ac
);
5877 char const *initial
= "";
5878 char const *val
= initial
;
5879 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
5880 #ifdef XtNarrowScrollbars
5881 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
5883 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
5884 if (xaw3d_arrow_scroll
|| val
== initial
)
5885 { /* ARROW_SCROLL */
5886 xaw3d_arrow_scroll
= True
;
5887 /* Isn't that just a personal preference ? --Stef */
5888 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
5892 /* Define callbacks. */
5893 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
5894 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
5897 /* Realize the widget. Only after that is the X window created. */
5898 XtRealizeWidget (widget
);
5900 #endif /* !USE_MOTIF */
5902 /* Install an action hook that lets us detect when the user
5903 finishes interacting with a scroll bar. */
5904 if (action_hook_id
== 0)
5905 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
5907 /* Remember X window and widget in the scroll bar vector. */
5908 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
5909 xwindow
= XtWindow (widget
);
5910 bar
->x_window
= xwindow
;
5912 bar
->horizontal
= false;
5918 x_create_horizontal_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5924 const char *scroll_bar_name
= SCROLL_BAR_HORIZONTAL_NAME
;
5925 unsigned long pixel
;
5930 /* Set resources. Create the widget. */
5931 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5932 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
5933 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
5934 XtSetArg (av
[ac
], XmNorientation
, XmHORIZONTAL
); ++ac
;
5935 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_RIGHT
), ++ac
;
5936 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
5937 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
5939 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5942 XtSetArg (av
[ac
], XmNforeground
, pixel
);
5946 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5949 XtSetArg (av
[ac
], XmNbackground
, pixel
);
5953 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
5954 (char *) scroll_bar_name
, av
, ac
);
5956 /* Add one callback for everything that can happen. */
5957 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
5959 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
5961 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
5963 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
5965 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
5967 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
5969 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
5972 /* Realize the widget. Only after that is the X window created. */
5973 XtRealizeWidget (widget
);
5975 /* Set the cursor to an arrow. I didn't find a resource to do that.
5976 And I'm wondering why it hasn't an arrow cursor by default. */
5977 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
5978 f
->output_data
.x
->nontext_cursor
);
5980 #else /* !USE_MOTIF i.e. use Xaw */
5982 /* Set resources. Create the widget. The background of the
5983 Xaw3d scroll bar widget is a little bit light for my taste.
5984 We don't alter it here to let users change it according
5985 to their taste with `emacs*verticalScrollBar.background: xxx'. */
5986 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5987 XtSetArg (av
[ac
], XtNorientation
, XtorientHorizontal
); ++ac
;
5988 /* For smoother scrolling with Xaw3d -sm */
5989 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
5991 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5994 XtSetArg (av
[ac
], XtNforeground
, pixel
);
5998 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6001 XtSetArg (av
[ac
], XtNbackground
, pixel
);
6005 /* Top/bottom shadow colors. */
6007 /* Allocate them, if necessary. */
6008 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
6010 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6013 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
6014 FRAME_X_COLORMAP (f
),
6015 &pixel
, 1.2, 0x8000))
6017 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
6020 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
6022 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6025 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
6026 FRAME_X_COLORMAP (f
),
6027 &pixel
, 0.6, 0x4000))
6029 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
6033 #ifdef XtNbeNiceToColormap
6034 /* Tell the toolkit about them. */
6035 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
6036 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
6037 /* We tried to allocate a color for the top/bottom shadow, and
6038 failed, so tell Xaw3d to use dithering instead. */
6039 /* But only if we have a small colormap. Xaw3d can allocate nice
6042 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
6043 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
6047 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
6048 be more consistent with other emacs 3d colors, and since Xaw3d is
6049 not good at dealing with allocation failure. */
6051 /* This tells Xaw3d to use real colors instead of dithering for
6053 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
6056 /* Specify the colors. */
6057 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
6060 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
6063 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
6066 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
6072 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
6073 f
->output_data
.x
->edit_widget
, av
, ac
);
6076 char const *initial
= "";
6077 char const *val
= initial
;
6078 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
6079 #ifdef XtNarrowScrollbars
6080 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
6082 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
6083 if (xaw3d_arrow_scroll
|| val
== initial
)
6084 { /* ARROW_SCROLL */
6085 xaw3d_arrow_scroll
= True
;
6086 /* Isn't that just a personal preference ? --Stef */
6087 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
6091 /* Define callbacks. */
6092 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
6093 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
6096 /* Realize the widget. Only after that is the X window created. */
6097 XtRealizeWidget (widget
);
6099 #endif /* !USE_MOTIF */
6101 /* Install an action hook that lets us detect when the user
6102 finishes interacting with a scroll bar. */
6103 if (horizontal_action_hook_id
== 0)
6104 horizontal_action_hook_id
6105 = XtAppAddActionHook (Xt_app_con
, xt_horizontal_action_hook
, 0);
6107 /* Remember X window and widget in the scroll bar vector. */
6108 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
6109 xwindow
= XtWindow (widget
);
6110 bar
->x_window
= xwindow
;
6112 bar
->horizontal
= true;
6116 #endif /* not USE_GTK */
6119 /* Set the thumb size and position of scroll bar BAR. We are currently
6120 displaying PORTION out of a whole WHOLE, and our position POSITION. */
6124 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
6126 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
6130 x_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
6132 xg_set_toolkit_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
6135 #else /* not USE_GTK */
6137 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
6140 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6141 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6148 if (scroll_bar_adjust_thumb_portion_p
)
6150 /* We use an estimate of 30 chars per line rather than the real
6151 `portion' value. This has the disadvantage that the thumb size
6152 is not very representative, but it makes our life a lot easier.
6153 Otherwise, we have to constantly adjust the thumb size, which
6154 we can't always do quickly enough: while dragging, the size of
6155 the thumb might prevent the user from dragging the thumb all the
6156 way to the end. but Motif and some versions of Xaw3d don't allow
6157 updating the thumb size while dragging. Also, even if we can update
6158 its size, the update will often happen too late.
6159 If you don't believe it, check out revision 1.650 of xterm.c to see
6160 what hoops we were going through and the still poor behavior we got. */
6161 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
6162 /* When the thumb is at the bottom, position == whole.
6163 So we need to increase `whole' to make space for the thumb. */
6171 top
= (float) position
/ whole
;
6172 shown
= (float) portion
/ whole
;
6175 if (bar
->dragging
== -1)
6179 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
6180 is the scroll bar's maximum and MIN is the scroll bar's minimum
6182 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
6184 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
6185 value
= top
* XM_SB_MAX
;
6186 value
= min (value
, XM_SB_MAX
- size
);
6188 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
6190 #else /* !USE_MOTIF i.e. use Xaw */
6196 top
= (float) position
/ whole
;
6197 shown
= (float) portion
/ whole
;
6201 float old_top
, old_shown
;
6203 XtVaGetValues (widget
,
6204 XtNtopOfThumb
, &old_top
,
6205 XtNshown
, &old_shown
,
6209 /* Massage the top+shown values. */
6210 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
6211 top
= max (0, min (1, top
));
6214 #if ! defined (HAVE_XAW3D)
6215 /* With Xaw, 'top' values too closer to 1.0 may
6216 cause the thumb to disappear. Fix that. */
6217 top
= min (top
, 0.99f
);
6219 /* Keep two pixels available for moving the thumb down. */
6220 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
6221 #if ! defined (HAVE_XAW3D)
6222 /* Likewise with too small 'shown'. */
6223 shown
= max (shown
, 0.01f
);
6226 /* If the call to XawScrollbarSetThumb below doesn't seem to
6227 work, check that 'NARROWPROTO' is defined in src/config.h.
6228 If this is not so, most likely you need to fix configure. */
6229 if (top
!= old_top
|| shown
!= old_shown
)
6231 if (bar
->dragging
== -1)
6232 XawScrollbarSetThumb (widget
, top
, shown
);
6235 /* Try to make the scrolling a tad smoother. */
6236 if (!xaw3d_pick_top
)
6237 shown
= min (shown
, old_shown
);
6239 XawScrollbarSetThumb (widget
, top
, shown
);
6243 #endif /* !USE_MOTIF */
6249 x_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
6252 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6253 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6260 shown
= (float) portion
/ whole
;
6261 top
= (float) position
/ (whole
- portion
);
6263 int size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
6264 int value
= clip_to_bounds (0, top
* (XM_SB_MAX
- size
), XM_SB_MAX
- size
);
6266 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
6268 #else /* !USE_MOTIF i.e. use Xaw */
6274 top
= (float) position
/ whole
;
6275 shown
= (float) portion
/ whole
;
6279 float old_top
, old_shown
;
6281 XtVaGetValues (widget
,
6282 XtNtopOfThumb
, &old_top
,
6283 XtNshown
, &old_shown
,
6288 /* Massage the top+shown values. */
6289 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
6290 top
= max (0, min (1, top
));
6293 #if ! defined (HAVE_XAW3D)
6294 /* With Xaw, 'top' values too closer to 1.0 may
6295 cause the thumb to disappear. Fix that. */
6296 top
= min (top
, 0.99f
);
6298 /* Keep two pixels available for moving the thumb down. */
6299 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
6300 #if ! defined (HAVE_XAW3D)
6301 /* Likewise with too small 'shown'. */
6302 shown
= max (shown
, 0.01f
);
6306 /* If the call to XawScrollbarSetThumb below doesn't seem to
6307 work, check that 'NARROWPROTO' is defined in src/config.h.
6308 If this is not so, most likely you need to fix configure. */
6309 XawScrollbarSetThumb (widget
, top
, shown
);
6311 if (top
!= old_top
|| shown
!= old_shown
)
6313 if (bar
->dragging
== -1)
6314 XawScrollbarSetThumb (widget
, top
, shown
);
6317 /* Try to make the scrolling a tad smoother. */
6318 if (!xaw3d_pick_top
)
6319 shown
= min (shown
, old_shown
);
6321 XawScrollbarSetThumb (widget
, top
, shown
);
6326 #endif /* !USE_MOTIF */
6330 #endif /* not USE_GTK */
6332 #endif /* USE_TOOLKIT_SCROLL_BARS */
6336 /************************************************************************
6337 Scroll bars, general
6338 ************************************************************************/
6340 /* Create a scroll bar and return the scroll bar vector for it. W is
6341 the Emacs window on which to create the scroll bar. TOP, LEFT,
6342 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
6345 static struct scroll_bar
*
6346 x_scroll_bar_create (struct window
*w
, int top
, int left
,
6347 int width
, int height
, bool horizontal
)
6349 struct frame
*f
= XFRAME (w
->frame
);
6350 struct scroll_bar
*bar
6351 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
6356 #ifdef USE_TOOLKIT_SCROLL_BARS
6358 x_create_horizontal_toolkit_scroll_bar (f
, bar
);
6360 x_create_toolkit_scroll_bar (f
, bar
);
6361 #else /* not USE_TOOLKIT_SCROLL_BARS */
6363 XSetWindowAttributes a
;
6367 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
6368 if (a
.background_pixel
== -1)
6369 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
6371 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
6372 | ButtonMotionMask
| PointerMotionHintMask
6374 a
.cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
6376 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
6378 /* Clear the area of W that will serve as a scroll bar. This is
6379 for the case that a window has been split horizontally. In
6380 this case, no clear_frame is generated to reduce flickering. */
6381 if (width
> 0 && window_box_height (w
) > 0)
6382 x_clear_area (f
, left
, top
, width
, window_box_height (w
));
6384 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
6385 /* Position and size of scroll bar. */
6386 left
, top
, width
, height
,
6387 /* Border width, depth, class, and visual. */
6394 bar
->x_window
= window
;
6396 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6398 XSETWINDOW (bar
->window
, w
);
6402 bar
->height
= height
;
6406 bar
->horizontal
= horizontal
;
6407 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
6408 bar
->last_seen_part
= scroll_bar_nowhere
;
6411 /* Add bar to its frame's list of scroll bars. */
6412 bar
->next
= FRAME_SCROLL_BARS (f
);
6414 XSETVECTOR (barobj
, bar
);
6415 fset_scroll_bars (f
, barobj
);
6416 if (!NILP (bar
->next
))
6417 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6419 /* Map the window/widget. */
6420 #ifdef USE_TOOLKIT_SCROLL_BARS
6424 xg_update_horizontal_scrollbar_pos (f
, bar
->x_window
, top
,
6425 left
, width
, max (height
, 1));
6427 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
6428 left
, width
, max (height
, 1));
6429 #else /* not USE_GTK */
6430 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
6431 XtConfigureWidget (scroll_bar
, left
, top
, width
, max (height
, 1), 0);
6432 XtMapWidget (scroll_bar
);
6433 #endif /* not USE_GTK */
6435 #else /* not USE_TOOLKIT_SCROLL_BARS */
6436 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
6437 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6444 #ifndef USE_TOOLKIT_SCROLL_BARS
6446 /* Draw BAR's handle in the proper position.
6448 If the handle is already drawn from START to END, don't bother
6449 redrawing it, unless REBUILD; in that case, always
6450 redraw it. (REBUILD is handy for drawing the handle after expose
6453 Normally, we want to constrain the start and end of the handle to
6454 fit inside its rectangle, but if the user is dragging the scroll
6455 bar handle, we want to let them drag it down all the way, so that
6456 the bar's top is as far down as it goes; otherwise, there's no way
6457 to move to the very end of the buffer. */
6460 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
,
6463 bool dragging
= bar
->dragging
!= -1;
6464 Window w
= bar
->x_window
;
6465 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6466 GC gc
= f
->output_data
.x
->normal_gc
;
6468 /* If the display is already accurate, do nothing. */
6470 && start
== bar
->start
6477 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
6478 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
6479 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
6481 /* Make sure the values are reasonable, and try to preserve
6482 the distance between start and end. */
6484 int length
= end
- start
;
6488 else if (start
> top_range
)
6490 end
= start
+ length
;
6494 else if (end
> top_range
&& ! dragging
)
6498 /* Store the adjusted setting in the scroll bar. */
6502 /* Clip the end position, just for display. */
6503 if (end
> top_range
)
6506 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
6507 below top positions, to make sure the handle is always at least
6508 that many pixels tall. */
6509 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
6511 /* Draw the empty space above the handle. Note that we can't clear
6512 zero-height areas; that means "clear to end of window." */
6513 if ((inside_width
> 0) && (start
> 0))
6514 x_clear_area1 (FRAME_X_DISPLAY (f
), w
,
6515 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
6516 VERTICAL_SCROLL_BAR_TOP_BORDER
,
6517 inside_width
, start
, False
);
6519 /* Change to proper foreground color if one is specified. */
6520 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
6521 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
6522 f
->output_data
.x
->scroll_bar_foreground_pixel
);
6524 /* Draw the handle itself. */
6525 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
6526 /* x, y, width, height */
6527 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
6528 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
6529 inside_width
, end
- start
);
6531 /* Restore the foreground color of the GC if we changed it above. */
6532 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
6533 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
6534 FRAME_FOREGROUND_PIXEL (f
));
6536 /* Draw the empty space below the handle. Note that we can't
6537 clear zero-height areas; that means "clear to end of window." */
6538 if ((inside_width
> 0) && (end
< inside_height
))
6539 x_clear_area1 (FRAME_X_DISPLAY (f
), w
,
6540 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
6541 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
6542 inside_width
, inside_height
- end
, False
);
6548 #endif /* !USE_TOOLKIT_SCROLL_BARS */
6550 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
6554 x_scroll_bar_remove (struct scroll_bar
*bar
)
6556 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6559 #ifdef USE_TOOLKIT_SCROLL_BARS
6561 xg_remove_scroll_bar (f
, bar
->x_window
);
6562 #else /* not USE_GTK */
6563 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
6564 #endif /* not USE_GTK */
6566 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
6569 /* Dissociate this scroll bar from its window. */
6570 if (bar
->horizontal
)
6571 wset_horizontal_scroll_bar (XWINDOW (bar
->window
), Qnil
);
6573 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
6579 /* Set the handle of the vertical scroll bar for WINDOW to indicate
6580 that we are displaying PORTION characters out of a total of WHOLE
6581 characters, starting at POSITION. If WINDOW has no scroll bar,
6585 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
6587 struct frame
*f
= XFRAME (w
->frame
);
6589 struct scroll_bar
*bar
;
6590 int top
, height
, left
, width
;
6591 int window_y
, window_height
;
6593 /* Get window dimensions. */
6594 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
6596 height
= window_height
;
6597 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
6598 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
6600 /* Does the scroll bar exist yet? */
6601 if (NILP (w
->vertical_scroll_bar
))
6603 if (width
> 0 && height
> 0)
6606 x_clear_area (f
, left
, top
, width
, height
);
6610 bar
= x_scroll_bar_create (w
, top
, left
, width
, max (height
, 1), false);
6614 /* It may just need to be moved and resized. */
6615 unsigned int mask
= 0;
6617 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
6621 if (left
!= bar
->left
)
6623 if (top
!= bar
->top
)
6625 if (width
!= bar
->width
)
6627 if (height
!= bar
->height
)
6630 #ifdef USE_TOOLKIT_SCROLL_BARS
6632 /* Move/size the scroll bar widget. */
6635 /* Since toolkit scroll bars are smaller than the space reserved
6636 for them on the frame, we have to clear "under" them. */
6637 if (width
> 0 && height
> 0)
6638 x_clear_area (f
, left
, top
, width
, height
);
6640 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
6641 left
, width
, max (height
, 1));
6642 #else /* not USE_GTK */
6643 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
6644 left
, top
, width
, max (height
, 1), 0);
6645 #endif /* not USE_GTK */
6647 #else /* not USE_TOOLKIT_SCROLL_BARS */
6649 /* Move/size the scroll bar window. */
6658 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
6662 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6664 /* Remember new settings. */
6668 bar
->height
= height
;
6673 #ifdef USE_TOOLKIT_SCROLL_BARS
6674 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
6675 #else /* not USE_TOOLKIT_SCROLL_BARS */
6676 /* Set the scroll bar's current state, unless we're currently being
6678 if (bar
->dragging
== -1)
6680 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
6683 x_scroll_bar_set_handle (bar
, 0, top_range
, false);
6686 int start
= ((double) position
* top_range
) / whole
;
6687 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
6688 x_scroll_bar_set_handle (bar
, start
, end
, false);
6691 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6693 XSETVECTOR (barobj
, bar
);
6694 wset_vertical_scroll_bar (w
, barobj
);
6699 XTset_horizontal_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
6701 struct frame
*f
= XFRAME (w
->frame
);
6703 struct scroll_bar
*bar
;
6704 int top
, height
, left
, width
;
6705 int window_x
, window_width
;
6706 int pixel_width
= WINDOW_PIXEL_WIDTH (w
);
6708 /* Get window dimensions. */
6709 window_box (w
, ANY_AREA
, &window_x
, 0, &window_width
, 0);
6711 width
= window_width
;
6712 top
= WINDOW_SCROLL_BAR_AREA_Y (w
);
6713 height
= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
6715 /* Does the scroll bar exist yet? */
6716 if (NILP (w
->horizontal_scroll_bar
))
6718 if (width
> 0 && height
> 0)
6722 /* Clear also part between window_width and
6723 WINDOW_PIXEL_WIDTH. */
6724 x_clear_area (f
, left
, top
, pixel_width
, height
);
6728 bar
= x_scroll_bar_create (w
, top
, left
, width
, height
, true);
6732 /* It may just need to be moved and resized. */
6733 unsigned int mask
= 0;
6735 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
6739 if (left
!= bar
->left
)
6741 if (top
!= bar
->top
)
6743 if (width
!= bar
->width
)
6745 if (height
!= bar
->height
)
6748 #ifdef USE_TOOLKIT_SCROLL_BARS
6749 /* Move/size the scroll bar widget. */
6752 /* Since toolkit scroll bars are smaller than the space reserved
6753 for them on the frame, we have to clear "under" them. */
6754 if (width
> 0 && height
> 0)
6756 WINDOW_LEFT_EDGE_X (w
), top
,
6757 pixel_width
- WINDOW_RIGHT_DIVIDER_WIDTH (w
), height
);
6759 xg_update_horizontal_scrollbar_pos (f
, bar
->x_window
, top
, left
,
6761 #else /* not USE_GTK */
6762 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
6763 left
, top
, width
, height
, 0);
6764 #endif /* not USE_GTK */
6766 #else /* not USE_TOOLKIT_SCROLL_BARS */
6768 /* Clear areas not covered by the scroll bar because it's not as
6769 wide as the area reserved for it. This makes sure a
6770 previous mode line display is cleared after C-x 2 C-x 1, for
6773 int area_height
= WINDOW_CONFIG_SCROLL_BAR_HEIGHT (w
);
6774 int rest
= area_height
- height
;
6775 if (rest
> 0 && width
> 0)
6776 x_clear_area (f
, left
, top
, width
, rest
);
6779 /* Move/size the scroll bar window. */
6788 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
6792 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6794 /* Remember new settings. */
6798 bar
->height
= height
;
6803 #ifdef USE_TOOLKIT_SCROLL_BARS
6804 x_set_toolkit_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
6805 #else /* not USE_TOOLKIT_SCROLL_BARS */
6806 /* Set the scroll bar's current state, unless we're currently being
6808 if (bar
->dragging
== -1)
6810 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, width
);
6813 x_scroll_bar_set_handle (bar
, 0, left_range
, false);
6816 int start
= ((double) position
* left_range
) / whole
;
6817 int end
= ((double) (position
+ portion
) * left_range
) / whole
;
6818 x_scroll_bar_set_handle (bar
, start
, end
, false);
6821 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6823 XSETVECTOR (barobj
, bar
);
6824 wset_horizontal_scroll_bar (w
, barobj
);
6828 /* The following three hooks are used when we're doing a thorough
6829 redisplay of the frame. We don't explicitly know which scroll bars
6830 are going to be deleted, because keeping track of when windows go
6831 away is a real pain - "Can you say set-window-configuration, boys
6832 and girls?" Instead, we just assert at the beginning of redisplay
6833 that *all* scroll bars are to be removed, and then save a scroll bar
6834 from the fiery pit when we actually redisplay its window. */
6836 /* Arrange for all scroll bars on FRAME to be removed at the next call
6837 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
6838 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
6841 XTcondemn_scroll_bars (struct frame
*frame
)
6843 if (!NILP (FRAME_SCROLL_BARS (frame
)))
6845 if (!NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
6847 /* Prepend scrollbars to already condemned ones. */
6848 Lisp_Object last
= FRAME_SCROLL_BARS (frame
);
6850 while (!NILP (XSCROLL_BAR (last
)->next
))
6851 last
= XSCROLL_BAR (last
)->next
;
6853 XSCROLL_BAR (last
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
6854 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= last
;
6857 fset_condemned_scroll_bars (frame
, FRAME_SCROLL_BARS (frame
));
6858 fset_scroll_bars (frame
, Qnil
);
6863 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
6864 Note that WINDOW isn't necessarily condemned at all. */
6867 XTredeem_scroll_bar (struct window
*w
)
6869 struct scroll_bar
*bar
;
6873 /* We can't redeem this window's scroll bar if it doesn't have one. */
6874 if (NILP (w
->vertical_scroll_bar
) && NILP (w
->horizontal_scroll_bar
))
6877 if (!NILP (w
->vertical_scroll_bar
) && WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
6879 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
6880 /* Unlink it from the condemned list. */
6881 f
= XFRAME (WINDOW_FRAME (w
));
6882 if (NILP (bar
->prev
))
6884 /* If the prev pointer is nil, it must be the first in one of
6886 if (EQ (FRAME_SCROLL_BARS (f
), w
->vertical_scroll_bar
))
6887 /* It's not condemned. Everything's fine. */
6889 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
6890 w
->vertical_scroll_bar
))
6891 fset_condemned_scroll_bars (f
, bar
->next
);
6893 /* If its prev pointer is nil, it must be at the front of
6894 one or the other! */
6898 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
6900 if (! NILP (bar
->next
))
6901 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
6903 bar
->next
= FRAME_SCROLL_BARS (f
);
6905 XSETVECTOR (barobj
, bar
);
6906 fset_scroll_bars (f
, barobj
);
6907 if (! NILP (bar
->next
))
6908 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6912 if (!NILP (w
->horizontal_scroll_bar
) && WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
6914 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
6915 /* Unlink it from the condemned list. */
6916 f
= XFRAME (WINDOW_FRAME (w
));
6917 if (NILP (bar
->prev
))
6919 /* If the prev pointer is nil, it must be the first in one of
6921 if (EQ (FRAME_SCROLL_BARS (f
), w
->horizontal_scroll_bar
))
6922 /* It's not condemned. Everything's fine. */
6924 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
6925 w
->horizontal_scroll_bar
))
6926 fset_condemned_scroll_bars (f
, bar
->next
);
6928 /* If its prev pointer is nil, it must be at the front of
6929 one or the other! */
6933 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
6935 if (! NILP (bar
->next
))
6936 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
6938 bar
->next
= FRAME_SCROLL_BARS (f
);
6940 XSETVECTOR (barobj
, bar
);
6941 fset_scroll_bars (f
, barobj
);
6942 if (! NILP (bar
->next
))
6943 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6947 /* Remove all scroll bars on FRAME that haven't been saved since the
6948 last call to `*condemn_scroll_bars_hook'. */
6951 XTjudge_scroll_bars (struct frame
*f
)
6953 Lisp_Object bar
, next
;
6955 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
6957 /* Clear out the condemned list now so we won't try to process any
6958 more events on the hapless scroll bars. */
6959 fset_condemned_scroll_bars (f
, Qnil
);
6961 for (; ! NILP (bar
); bar
= next
)
6963 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
6965 x_scroll_bar_remove (b
);
6968 b
->next
= b
->prev
= Qnil
;
6971 /* Now there should be no references to the condemned scroll bars,
6972 and they should get garbage-collected. */
6976 #ifndef USE_TOOLKIT_SCROLL_BARS
6977 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
6978 is a no-op when using toolkit scroll bars.
6980 This may be called from a signal handler, so we have to ignore GC
6984 x_scroll_bar_expose (struct scroll_bar
*bar
, const XEvent
*event
)
6986 Window w
= bar
->x_window
;
6987 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6988 GC gc
= f
->output_data
.x
->normal_gc
;
6992 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, true);
6994 /* Switch to scroll bar foreground color. */
6995 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
6996 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
6997 f
->output_data
.x
->scroll_bar_foreground_pixel
);
6999 /* Draw a one-pixel border just inside the edges of the scroll bar. */
7000 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
7001 /* x, y, width, height */
7002 0, 0, bar
->width
- 1, bar
->height
- 1);
7004 /* Restore the foreground color of the GC if we changed it above. */
7005 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
7006 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
7007 FRAME_FOREGROUND_PIXEL (f
));
7012 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7014 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
7015 is set to something other than NO_EVENT, it is enqueued.
7017 This may be called from a signal handler, so we have to ignore GC
7022 x_scroll_bar_handle_click (struct scroll_bar
*bar
,
7023 const XEvent
*event
,
7024 struct input_event
*emacs_event
)
7026 if (! WINDOWP (bar
->window
))
7029 emacs_event
->kind
= (bar
->horizontal
7030 ? HORIZONTAL_SCROLL_BAR_CLICK_EVENT
7031 : SCROLL_BAR_CLICK_EVENT
);
7032 emacs_event
->code
= event
->xbutton
.button
- Button1
;
7033 emacs_event
->modifiers
7034 = (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO
7035 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
7036 event
->xbutton
.state
)
7037 | (event
->type
== ButtonRelease
7040 emacs_event
->frame_or_window
= bar
->window
;
7041 emacs_event
->arg
= Qnil
;
7042 emacs_event
->timestamp
= event
->xbutton
.time
;
7043 if (bar
->horizontal
)
7046 = HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
7047 int x
= event
->xbutton
.x
- HORIZONTAL_SCROLL_BAR_LEFT_BORDER
;
7050 if (x
> left_range
) x
= left_range
;
7053 emacs_event
->part
= scroll_bar_before_handle
;
7054 else if (x
< bar
->end
+ HORIZONTAL_SCROLL_BAR_MIN_HANDLE
)
7055 emacs_event
->part
= scroll_bar_horizontal_handle
;
7057 emacs_event
->part
= scroll_bar_after_handle
;
7059 #ifndef USE_TOOLKIT_SCROLL_BARS
7060 /* If the user has released the handle, set it to its final position. */
7061 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
7063 int new_start
= - bar
->dragging
;
7064 int new_end
= new_start
+ bar
->end
- bar
->start
;
7066 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
7071 XSETINT (emacs_event
->x
, left_range
);
7072 XSETINT (emacs_event
->y
, x
);
7077 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
7078 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
7081 if (y
> top_range
) y
= top_range
;
7084 emacs_event
->part
= scroll_bar_above_handle
;
7085 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
7086 emacs_event
->part
= scroll_bar_handle
;
7088 emacs_event
->part
= scroll_bar_below_handle
;
7090 #ifndef USE_TOOLKIT_SCROLL_BARS
7091 /* If the user has released the handle, set it to its final position. */
7092 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
7094 int new_start
= y
- bar
->dragging
;
7095 int new_end
= new_start
+ bar
->end
- bar
->start
;
7097 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
7102 XSETINT (emacs_event
->x
, y
);
7103 XSETINT (emacs_event
->y
, top_range
);
7107 #ifndef USE_TOOLKIT_SCROLL_BARS
7109 /* Handle some mouse motion while someone is dragging the scroll bar.
7111 This may be called from a signal handler, so we have to ignore GC
7115 x_scroll_bar_note_movement (struct scroll_bar
*bar
,
7116 const XMotionEvent
*event
)
7118 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
7119 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
7121 dpyinfo
->last_mouse_movement_time
= event
->time
;
7122 dpyinfo
->last_mouse_scroll_bar
= bar
;
7123 f
->mouse_moved
= true;
7125 /* If we're dragging the bar, display it. */
7126 if (bar
->dragging
!= -1)
7128 /* Where should the handle be now? */
7129 int new_start
= event
->y
- bar
->dragging
;
7131 if (new_start
!= bar
->start
)
7133 int new_end
= new_start
+ bar
->end
- bar
->start
;
7135 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
7140 #endif /* !USE_TOOLKIT_SCROLL_BARS */
7142 /* Return information to the user about the current position of the mouse
7143 on the scroll bar. */
7146 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
7147 enum scroll_bar_part
*part
, Lisp_Object
*x
,
7148 Lisp_Object
*y
, Time
*timestamp
)
7150 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
7151 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
7152 Window w
= bar
->x_window
;
7153 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7155 Window dummy_window
;
7157 unsigned int dummy_mask
;
7161 /* Get the mouse's position relative to the scroll bar window, and
7163 if (XQueryPointer (FRAME_X_DISPLAY (f
), w
,
7165 /* Root, child, root x and root y. */
7166 &dummy_window
, &dummy_window
,
7167 &dummy_coord
, &dummy_coord
,
7169 /* Position relative to scroll bar. */
7172 /* Mouse buttons and modifier keys. */
7175 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
7177 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
7179 if (bar
->dragging
!= -1)
7180 win_y
-= bar
->dragging
;
7184 if (win_y
> top_range
)
7188 *bar_window
= bar
->window
;
7190 if (bar
->dragging
!= -1)
7191 *part
= scroll_bar_handle
;
7192 else if (win_y
< bar
->start
)
7193 *part
= scroll_bar_above_handle
;
7194 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
7195 *part
= scroll_bar_handle
;
7197 *part
= scroll_bar_below_handle
;
7199 XSETINT (*x
, win_y
);
7200 XSETINT (*y
, top_range
);
7202 f
->mouse_moved
= false;
7203 dpyinfo
->last_mouse_scroll_bar
= NULL
;
7204 *timestamp
= dpyinfo
->last_mouse_movement_time
;
7211 /* Return information to the user about the current position of the mouse
7212 on the scroll bar. */
7215 x_horizontal_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
7216 enum scroll_bar_part
*part
, Lisp_Object
*x
,
7217 Lisp_Object
*y
, Time
*timestamp
)
7219 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
7220 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
7221 Window w
= bar
->x_window
;
7222 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
7224 Window dummy_window
;
7226 unsigned int dummy_mask
;
7230 /* Get the mouse's position relative to the scroll bar window, and
7232 if (XQueryPointer (FRAME_X_DISPLAY (f
), w
,
7234 /* Root, child, root x and root y. */
7235 &dummy_window
, &dummy_window
,
7236 &dummy_coord
, &dummy_coord
,
7238 /* Position relative to scroll bar. */
7241 /* Mouse buttons and modifier keys. */
7244 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
7246 win_x
-= HORIZONTAL_SCROLL_BAR_LEFT_BORDER
;
7248 if (bar
->dragging
!= -1)
7249 win_x
-= bar
->dragging
;
7253 if (win_x
> left_range
)
7257 *bar_window
= bar
->window
;
7259 if (bar
->dragging
!= -1)
7260 *part
= scroll_bar_horizontal_handle
;
7261 else if (win_x
< bar
->start
)
7262 *part
= scroll_bar_before_handle
;
7263 else if (win_x
< bar
->end
+ HORIZONTAL_SCROLL_BAR_MIN_HANDLE
)
7264 *part
= scroll_bar_handle
;
7266 *part
= scroll_bar_after_handle
;
7268 XSETINT (*y
, win_x
);
7269 XSETINT (*x
, left_range
);
7271 f
->mouse_moved
= false;
7272 dpyinfo
->last_mouse_scroll_bar
= NULL
;
7273 *timestamp
= dpyinfo
->last_mouse_movement_time
;
7280 /* The screen has been cleared so we may have changed foreground or
7281 background colors, and the scroll bars may need to be redrawn.
7282 Clear out the scroll bars, and ask for expose events, so we can
7286 x_scroll_bar_clear (struct frame
*f
)
7288 #ifndef USE_TOOLKIT_SCROLL_BARS
7291 /* We can have scroll bars even if this is 0,
7292 if we just turned off scroll bar mode.
7293 But in that case we should not clear them. */
7294 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
7295 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
7296 bar
= XSCROLL_BAR (bar
)->next
)
7297 XClearArea (FRAME_X_DISPLAY (f
),
7298 XSCROLL_BAR (bar
)->x_window
,
7300 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7303 #ifdef ENABLE_CHECKING
7305 /* Record the last 100 characters stored
7306 to help debug the loss-of-chars-during-GC problem. */
7308 static int temp_index
;
7309 static short temp_buffer
[100];
7311 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
7312 if (temp_index == ARRAYELTS (temp_buffer)) \
7314 temp_buffer[temp_index++] = (keysym)
7316 #else /* not ENABLE_CHECKING */
7318 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
7320 #endif /* ENABLE_CHECKING */
7322 /* Set this to nonzero to fake an "X I/O error"
7323 on a particular display. */
7325 static struct x_display_info
*XTread_socket_fake_io_error
;
7327 /* When we find no input here, we occasionally do a no-op command
7328 to verify that the X server is still running and we can still talk with it.
7329 We try all the open displays, one by one.
7330 This variable is used for cycling thru the displays. */
7332 static struct x_display_info
*next_noop_dpyinfo
;
7341 /* Filter events for the current X input method.
7342 DPYINFO is the display this event is for.
7343 EVENT is the X event to filter.
7345 Returns non-zero if the event was filtered, caller shall not process
7347 Returns zero if event is wasn't filtered. */
7351 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
7353 /* XFilterEvent returns non-zero if the input method has
7354 consumed the event. We pass the frame's X window to
7355 XFilterEvent because that's the one for which the IC
7358 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
7359 event
->xclient
.window
);
7361 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
7366 static int current_count
;
7367 static int current_finish
;
7368 static struct input_event
*current_hold_quit
;
7370 /* This is the filter function invoked by the GTK event loop.
7371 It is invoked before the XEvent is translated to a GdkEvent,
7372 so we have a chance to act on the event before GTK. */
7373 static GdkFilterReturn
7374 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
7376 XEvent
*xev
= (XEvent
*) gxev
;
7379 if (current_count
>= 0)
7381 struct x_display_info
*dpyinfo
;
7383 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
7386 /* Filter events for the current X input method.
7387 GTK calls XFilterEvent but not for key press and release,
7388 so we do it here. */
7389 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
7391 && x_filter_event (dpyinfo
, xev
))
7394 return GDK_FILTER_REMOVE
;
7399 current_finish
= X_EVENT_NORMAL
;
7402 += handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
7406 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
7410 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
7411 return GDK_FILTER_REMOVE
;
7413 return GDK_FILTER_CONTINUE
;
7415 #endif /* USE_GTK */
7418 static void xembed_send_message (struct frame
*f
, Time
,
7419 enum xembed_message
,
7420 long detail
, long data1
, long data2
);
7423 x_net_wm_state (struct frame
*f
, Window window
)
7425 int value
= FULLSCREEN_NONE
;
7426 Lisp_Object lval
= Qnil
;
7427 bool sticky
= false;
7429 get_current_wm_state (f
, window
, &value
, &sticky
);
7433 case FULLSCREEN_WIDTH
:
7436 case FULLSCREEN_HEIGHT
:
7439 case FULLSCREEN_BOTH
:
7442 case FULLSCREEN_MAXIMIZED
:
7447 frame_size_history_add
7448 (f
, Qx_net_wm_state
, 0, 0,
7449 list2 (get_frame_param (f
, Qfullscreen
), lval
));
7451 store_frame_param (f
, Qfullscreen
, lval
);
7452 /** store_frame_param (f, Qsticky, sticky ? Qt : Qnil); **/
7455 /* Handles the XEvent EVENT on display DPYINFO.
7457 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
7458 *FINISH is zero if caller should continue reading events.
7459 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
7460 *EVENT is unchanged unless we're processing KeyPress event.
7462 We return the number of characters stored into the buffer. */
7465 handle_one_xevent (struct x_display_info
*dpyinfo
,
7466 const XEvent
*event
,
7467 int *finish
, struct input_event
*hold_quit
)
7469 union buffered_input_event inev
;
7472 ptrdiff_t nbytes
= 0;
7473 struct frame
*any
, *f
= NULL
;
7474 struct coding_system coding
;
7475 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
7476 /* This holds the state XLookupString needs to implement dead keys
7477 and other tricks known as "compose processing". _X Window System_
7478 says that a portable program can't use this, but Stephen Gildea assures
7479 me that letting the compiler initialize it to zeros will work okay. */
7480 static XComposeStatus compose_status
;
7481 XEvent configureEvent
;
7486 *finish
= X_EVENT_NORMAL
;
7488 EVENT_INIT (inev
.ie
);
7489 inev
.ie
.kind
= NO_EVENT
;
7492 any
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
7494 if (any
&& any
->wait_event_type
== event
->type
)
7495 any
->wait_event_type
= 0; /* Indicates we got it. */
7497 switch (event
->type
)
7501 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_protocols
7502 && event
->xclient
.format
== 32)
7504 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_take_focus
)
7506 /* Use the value returned by x_any_window_to_frame
7507 because this could be the shell widget window
7508 if the frame has no title bar. */
7511 /* Not quite sure this is needed -pd */
7512 if (f
&& FRAME_XIC (f
))
7513 XSetICFocus (FRAME_XIC (f
));
7516 /* Emacs sets WM hints whose `input' field is `true'. This
7517 instructs the WM to set the input focus automatically for
7518 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
7519 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
7520 it has set the focus. So, XSetInputFocus below is not
7523 The call to XSetInputFocus below has also caused trouble. In
7524 cases where the XSetInputFocus done by the WM and the one
7525 below are temporally close (on a fast machine), the call
7526 below can generate additional FocusIn events which confuse
7529 /* Since we set WM_TAKE_FOCUS, we must call
7530 XSetInputFocus explicitly. But not if f is null,
7531 since that might be an event for a deleted frame. */
7534 Display
*d
= event
->xclient
.display
;
7535 /* Catch and ignore errors, in case window has been
7536 iconified by a window manager such as GWM. */
7538 XSetInputFocus (d
, event
->xclient
.window
,
7539 /* The ICCCM says this is
7540 the only valid choice. */
7542 event
->xclient
.data
.l
[1]);
7543 x_uncatch_errors ();
7545 /* Not certain about handling scroll bars here */
7550 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_save_yourself
)
7552 /* Save state modify the WM_COMMAND property to
7553 something which can reinstate us. This notifies
7554 the session manager, who's looking for such a
7555 PropertyNotify. Can restart processing when
7556 a keyboard or mouse event arrives. */
7557 /* If we have a session manager, don't set this.
7558 KDE will then start two Emacsen, one for the
7559 session manager and one for this. */
7561 if (! x_session_have_connection ())
7564 f
= x_top_window_to_frame (dpyinfo
,
7565 event
->xclient
.window
);
7566 /* This is just so we only give real data once
7567 for a single Emacs process. */
7568 if (f
== SELECTED_FRAME ())
7569 XSetCommand (FRAME_X_DISPLAY (f
),
7570 event
->xclient
.window
,
7571 initial_argv
, initial_argc
);
7573 XSetCommand (FRAME_X_DISPLAY (f
),
7574 event
->xclient
.window
,
7580 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_delete_window
)
7584 goto OTHER
; /* May be a dialog that is to be removed */
7586 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
7587 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7594 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_configure_denied
)
7597 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_window_moved
)
7600 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
7602 new_x
= event
->xclient
.data
.s
[0];
7603 new_y
= event
->xclient
.data
.s
[1];
7607 f
->left_pos
= new_x
;
7614 if (event
->xclient
.message_type
== dpyinfo
->Xatom_editres
)
7618 _XEditResCheckMessages (f
->output_data
.x
->widget
,
7619 NULL
, (XEvent
*) event
, NULL
);
7622 #endif /* HACK_EDITRES */
7624 if (event
->xclient
.message_type
== dpyinfo
->Xatom_DONE
7625 || event
->xclient
.message_type
== dpyinfo
->Xatom_PAGE
)
7627 /* Ghostview job completed. Kill it. We could
7628 reply with "Next" if we received "Page", but we
7629 currently never do because we are interested in
7630 images, only, which should have 1 page. */
7631 Pixmap pixmap
= (Pixmap
) event
->xclient
.data
.l
[1];
7632 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
7635 x_kill_gs_process (pixmap
, f
);
7636 expose_frame (f
, 0, 0, 0, 0);
7640 #ifdef USE_TOOLKIT_SCROLL_BARS
7641 /* Scroll bar callbacks send a ClientMessage from which
7642 we construct an input_event. */
7643 if (event
->xclient
.message_type
== dpyinfo
->Xatom_Scrollbar
)
7645 x_scroll_bar_to_input_event (event
, &inev
.ie
);
7646 *finish
= X_EVENT_GOTO_OUT
;
7649 else if (event
->xclient
.message_type
== dpyinfo
->Xatom_Horizontal_Scrollbar
)
7651 x_horizontal_scroll_bar_to_input_event (event
, &inev
.ie
);
7652 *finish
= X_EVENT_GOTO_OUT
;
7655 #endif /* USE_TOOLKIT_SCROLL_BARS */
7657 /* XEmbed messages from the embedder (if any). */
7658 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
7660 enum xembed_message msg
= event
->xclient
.data
.l
[1];
7661 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
7662 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
7664 *finish
= X_EVENT_GOTO_OUT
;
7668 xft_settings_event (dpyinfo
, event
);
7673 if (x_handle_dnd_message (f
, &event
->xclient
, dpyinfo
, &inev
.ie
))
7674 *finish
= X_EVENT_DROP
;
7678 case SelectionNotify
:
7679 x_display_set_last_user_time (dpyinfo
, event
->xselection
.time
);
7680 #ifdef USE_X_TOOLKIT
7681 if (! x_window_to_frame (dpyinfo
, event
->xselection
.requestor
))
7683 #endif /* not USE_X_TOOLKIT */
7684 x_handle_selection_notify (&event
->xselection
);
7687 case SelectionClear
: /* Someone has grabbed ownership. */
7688 x_display_set_last_user_time (dpyinfo
, event
->xselectionclear
.time
);
7689 #ifdef USE_X_TOOLKIT
7690 if (! x_window_to_frame (dpyinfo
, event
->xselectionclear
.window
))
7692 #endif /* USE_X_TOOLKIT */
7694 const XSelectionClearEvent
*eventp
= &event
->xselectionclear
;
7696 inev
.sie
.kind
= SELECTION_CLEAR_EVENT
;
7697 SELECTION_EVENT_DPYINFO (&inev
.sie
) = dpyinfo
;
7698 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
7699 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
7703 case SelectionRequest
: /* Someone wants our selection. */
7704 x_display_set_last_user_time (dpyinfo
, event
->xselectionrequest
.time
);
7705 #ifdef USE_X_TOOLKIT
7706 if (!x_window_to_frame (dpyinfo
, event
->xselectionrequest
.owner
))
7708 #endif /* USE_X_TOOLKIT */
7710 const XSelectionRequestEvent
*eventp
= &event
->xselectionrequest
;
7712 inev
.sie
.kind
= SELECTION_REQUEST_EVENT
;
7713 SELECTION_EVENT_DPYINFO (&inev
.sie
) = dpyinfo
;
7714 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
7715 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
7716 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
7717 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
7718 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
7722 case PropertyNotify
:
7723 x_display_set_last_user_time (dpyinfo
, event
->xproperty
.time
);
7724 f
= x_top_window_to_frame (dpyinfo
, event
->xproperty
.window
);
7725 if (f
&& event
->xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
7727 bool not_hidden
= x_handle_net_wm_state (f
, &event
->xproperty
);
7728 if (not_hidden
&& FRAME_ICONIFIED_P (f
))
7730 /* Gnome shell does not iconify us when C-z is pressed.
7731 It hides the frame. So if our state says we aren't
7732 hidden anymore, treat it as deiconified. */
7733 SET_FRAME_VISIBLE (f
, 1);
7734 SET_FRAME_ICONIFIED (f
, false);
7735 f
->output_data
.x
->has_been_visible
= true;
7736 inev
.ie
.kind
= DEICONIFY_EVENT
;
7737 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7739 else if (! not_hidden
&& ! FRAME_ICONIFIED_P (f
))
7741 SET_FRAME_VISIBLE (f
, 0);
7742 SET_FRAME_ICONIFIED (f
, true);
7743 inev
.ie
.kind
= ICONIFY_EVENT
;
7744 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7748 x_handle_property_notify (&event
->xproperty
);
7749 xft_settings_event (dpyinfo
, event
);
7752 case ReparentNotify
:
7753 f
= x_top_window_to_frame (dpyinfo
, event
->xreparent
.window
);
7756 f
->output_data
.x
->parent_desc
= event
->xreparent
.parent
;
7757 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
7759 /* Perhaps reparented due to a WM restart. Reset this. */
7760 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
7761 FRAME_DISPLAY_INFO (f
)->net_supported_window
= 0;
7763 x_set_frame_alpha (f
);
7768 f
= x_window_to_frame (dpyinfo
, event
->xexpose
.window
);
7771 if (!FRAME_VISIBLE_P (f
))
7773 SET_FRAME_VISIBLE (f
, 1);
7774 SET_FRAME_ICONIFIED (f
, false);
7775 f
->output_data
.x
->has_been_visible
= true;
7776 SET_FRAME_GARBAGED (f
);
7781 /* This seems to be needed for GTK 2.6 and later, see
7782 http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15398. */
7784 event
->xexpose
.x
, event
->xexpose
.y
,
7785 event
->xexpose
.width
, event
->xexpose
.height
);
7787 expose_frame (f
, event
->xexpose
.x
, event
->xexpose
.y
,
7788 event
->xexpose
.width
, event
->xexpose
.height
);
7793 #ifndef USE_TOOLKIT_SCROLL_BARS
7794 struct scroll_bar
*bar
;
7796 #if defined USE_LUCID
7797 /* Submenus of the Lucid menu bar aren't widgets
7798 themselves, so there's no way to dispatch events
7799 to them. Recognize this case separately. */
7801 Widget widget
= x_window_to_menu_bar (event
->xexpose
.window
);
7803 xlwmenu_redisplay (widget
);
7805 #endif /* USE_LUCID */
7807 #ifdef USE_TOOLKIT_SCROLL_BARS
7808 /* Dispatch event to the widget. */
7810 #else /* not USE_TOOLKIT_SCROLL_BARS */
7811 bar
= x_window_to_scroll_bar (event
->xexpose
.display
,
7812 event
->xexpose
.window
, 2);
7815 x_scroll_bar_expose (bar
, event
);
7816 #ifdef USE_X_TOOLKIT
7819 #endif /* USE_X_TOOLKIT */
7820 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7824 case GraphicsExpose
: /* This occurs when an XCopyArea's
7825 source area was obscured or not
7827 f
= x_window_to_frame (dpyinfo
, event
->xgraphicsexpose
.drawable
);
7829 expose_frame (f
, event
->xgraphicsexpose
.x
,
7830 event
->xgraphicsexpose
.y
,
7831 event
->xgraphicsexpose
.width
,
7832 event
->xgraphicsexpose
.height
);
7833 #ifdef USE_X_TOOLKIT
7836 #endif /* USE_X_TOOLKIT */
7839 case NoExpose
: /* This occurs when an XCopyArea's
7840 source area was completely
7845 /* Redo the mouse-highlight after the tooltip has gone. */
7846 if (event
->xunmap
.window
== tip_window
)
7849 x_redo_mouse_highlight (dpyinfo
);
7852 f
= x_top_window_to_frame (dpyinfo
, event
->xunmap
.window
);
7853 if (f
) /* F may no longer exist if
7854 the frame was deleted. */
7856 bool visible
= FRAME_VISIBLE_P (f
);
7857 /* While a frame is unmapped, display generation is
7858 disabled; you don't want to spend time updating a
7859 display that won't ever be seen. */
7860 SET_FRAME_VISIBLE (f
, 0);
7861 /* We can't distinguish, from the event, whether the window
7862 has become iconified or invisible. So assume, if it
7863 was previously visible, than now it is iconified.
7864 But x_make_frame_invisible clears both
7865 the visible flag and the iconified flag;
7866 and that way, we know the window is not iconified now. */
7867 if (visible
|| FRAME_ICONIFIED_P (f
))
7869 SET_FRAME_ICONIFIED (f
, true);
7870 inev
.ie
.kind
= ICONIFY_EVENT
;
7871 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7877 /* We use x_top_window_to_frame because map events can
7878 come for sub-windows and they don't mean that the
7879 frame is visible. */
7880 f
= x_top_window_to_frame (dpyinfo
, event
->xmap
.window
);
7883 bool iconified
= FRAME_ICONIFIED_P (f
);
7885 /* Check if fullscreen was specified before we where mapped the
7886 first time, i.e. from the command line. */
7887 if (!f
->output_data
.x
->has_been_visible
)
7888 x_check_fullscreen (f
);
7890 SET_FRAME_VISIBLE (f
, 1);
7891 SET_FRAME_ICONIFIED (f
, false);
7892 f
->output_data
.x
->has_been_visible
= true;
7896 inev
.ie
.kind
= DEICONIFY_EVENT
;
7897 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7899 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
7900 /* Force a redisplay sooner or later to update the
7901 frame titles in case this is the second frame. */
7902 record_asynch_buffer_change ();
7905 xg_frame_resized (f
, -1, -1);
7912 x_display_set_last_user_time (dpyinfo
, event
->xkey
.time
);
7913 ignore_next_mouse_click_timeout
= 0;
7915 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7916 /* Dispatch KeyPress events when in menu. */
7917 if (popup_activated ())
7923 /* If mouse-highlight is an integer, input clears out
7924 mouse highlighting. */
7925 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
7926 #if ! defined (USE_GTK)
7928 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
))
7932 clear_mouse_face (hlinfo
);
7933 hlinfo
->mouse_face_hidden
= true;
7936 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
7939 /* Scroll bars consume key events, but we want
7940 the keys to go to the scroll bar's frame. */
7941 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
7942 event
->xkey
.window
);
7943 if (widget
&& XmIsScrollBar (widget
))
7945 widget
= XtParent (widget
);
7946 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
7949 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
7953 KeySym keysym
, orig_keysym
;
7954 /* al%imercury@uunet.uu.net says that making this 81
7955 instead of 80 fixed a bug whereby meta chars made
7958 It seems that some version of XmbLookupString has
7959 a bug of not returning XBufferOverflow in
7960 status_return even if the input is too long to
7961 fit in 81 bytes. So, we must prepare sufficient
7962 bytes for copy_buffer. 513 bytes (256 chars for
7963 two-byte character set) seems to be a fairly good
7964 approximation. -- 2000.8.10 handa@etl.go.jp */
7965 unsigned char copy_buffer
[513];
7966 unsigned char *copy_bufptr
= copy_buffer
;
7967 int copy_bufsiz
= sizeof (copy_buffer
);
7969 Lisp_Object coding_system
= Qlatin_1
;
7971 /* Event will be modified. */
7972 XKeyEvent xkey
= event
->xkey
;
7975 /* Don't pass keys to GTK. A Tab will shift focus to the
7976 tool bar in GTK 2.4. Keys will still go to menus and
7977 dialogs because in that case popup_activated is nonzero
7979 *finish
= X_EVENT_DROP
;
7982 xkey
.state
|= x_emacs_to_x_modifiers (FRAME_DISPLAY_INFO (f
),
7983 extra_keyboard_modifiers
);
7984 modifiers
= xkey
.state
;
7986 /* This will have to go some day... */
7988 /* make_lispy_event turns chars into control chars.
7989 Don't do it here because XLookupString is too eager. */
7990 xkey
.state
&= ~ControlMask
;
7991 xkey
.state
&= ~(dpyinfo
->meta_mod_mask
7992 | dpyinfo
->super_mod_mask
7993 | dpyinfo
->hyper_mod_mask
7994 | dpyinfo
->alt_mod_mask
);
7996 /* In case Meta is ComposeCharacter,
7997 clear its status. According to Markus Ehrnsperger
7998 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
7999 this enables ComposeCharacter to work whether or
8000 not it is combined with Meta. */
8001 if (modifiers
& dpyinfo
->meta_mod_mask
)
8002 memset (&compose_status
, 0, sizeof (compose_status
));
8007 Status status_return
;
8009 coding_system
= Vlocale_coding_system
;
8010 nbytes
= XmbLookupString (FRAME_XIC (f
),
8011 &xkey
, (char *) copy_bufptr
,
8012 copy_bufsiz
, &keysym
,
8014 if (status_return
== XBufferOverflow
)
8016 copy_bufsiz
= nbytes
+ 1;
8017 copy_bufptr
= alloca (copy_bufsiz
);
8018 nbytes
= XmbLookupString (FRAME_XIC (f
),
8019 &xkey
, (char *) copy_bufptr
,
8020 copy_bufsiz
, &keysym
,
8023 /* Xutf8LookupString is a new but already deprecated interface. -stef */
8024 if (status_return
== XLookupNone
)
8026 else if (status_return
== XLookupChars
)
8031 else if (status_return
!= XLookupKeySym
8032 && status_return
!= XLookupBoth
)
8036 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
8037 copy_bufsiz
, &keysym
,
8040 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
8041 copy_bufsiz
, &keysym
,
8045 /* If not using XIM/XIC, and a compose sequence is in progress,
8046 we break here. Otherwise, chars_matched is always 0. */
8047 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
8050 memset (&compose_status
, 0, sizeof (compose_status
));
8051 orig_keysym
= keysym
;
8053 /* Common for all keysym input events. */
8054 XSETFRAME (inev
.ie
.frame_or_window
, f
);
8056 = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
), modifiers
);
8057 inev
.ie
.timestamp
= xkey
.time
;
8059 /* First deal with keysyms which have defined
8060 translations to characters. */
8061 if (keysym
>= 32 && keysym
< 128)
8062 /* Avoid explicitly decoding each ASCII character. */
8064 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
8065 inev
.ie
.code
= keysym
;
8069 /* Keysyms directly mapped to Unicode characters. */
8070 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
8072 if (keysym
< 0x01000080)
8073 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
8075 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
8076 inev
.ie
.code
= keysym
& 0xFFFFFF;
8080 /* Now non-ASCII. */
8081 if (HASH_TABLE_P (Vx_keysym_table
)
8082 && (c
= Fgethash (make_number (keysym
),
8087 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
8088 ? ASCII_KEYSTROKE_EVENT
8089 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
8090 inev
.ie
.code
= XFASTINT (c
);
8094 /* Random non-modifier sorts of keysyms. */
8095 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
8096 || keysym
== XK_Delete
8097 #ifdef XK_ISO_Left_Tab
8098 || (keysym
>= XK_ISO_Left_Tab
8099 && keysym
<= XK_ISO_Enter
)
8101 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
8102 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
8104 /* This recognizes the "extended function
8105 keys". It seems there's no cleaner way.
8106 Test IsModifierKey to avoid handling
8107 mode_switch incorrectly. */
8108 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
8110 #ifdef XK_dead_circumflex
8111 || orig_keysym
== XK_dead_circumflex
8113 #ifdef XK_dead_grave
8114 || orig_keysym
== XK_dead_grave
8116 #ifdef XK_dead_tilde
8117 || orig_keysym
== XK_dead_tilde
8119 #ifdef XK_dead_diaeresis
8120 || orig_keysym
== XK_dead_diaeresis
8122 #ifdef XK_dead_macron
8123 || orig_keysym
== XK_dead_macron
8125 #ifdef XK_dead_degree
8126 || orig_keysym
== XK_dead_degree
8128 #ifdef XK_dead_acute
8129 || orig_keysym
== XK_dead_acute
8131 #ifdef XK_dead_cedilla
8132 || orig_keysym
== XK_dead_cedilla
8134 #ifdef XK_dead_breve
8135 || orig_keysym
== XK_dead_breve
8137 #ifdef XK_dead_ogonek
8138 || orig_keysym
== XK_dead_ogonek
8140 #ifdef XK_dead_caron
8141 || orig_keysym
== XK_dead_caron
8143 #ifdef XK_dead_doubleacute
8144 || orig_keysym
== XK_dead_doubleacute
8146 #ifdef XK_dead_abovedot
8147 || orig_keysym
== XK_dead_abovedot
8149 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
8150 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
8151 /* Any "vendor-specific" key is ok. */
8152 || (orig_keysym
& (1 << 28))
8153 || (keysym
!= NoSymbol
&& nbytes
== 0))
8154 && ! (IsModifierKey (orig_keysym
)
8155 /* The symbols from XK_ISO_Lock
8156 to XK_ISO_Last_Group_Lock
8157 don't have real modifiers but
8158 should be treated similarly to
8159 Mode_switch by Emacs. */
8160 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
8161 || (XK_ISO_Lock
<= orig_keysym
8162 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
8166 STORE_KEYSYM_FOR_DEBUG (keysym
);
8167 /* make_lispy_event will convert this to a symbolic
8169 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
8170 inev
.ie
.code
= keysym
;
8174 { /* Raw bytes, not keysym. */
8178 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
8180 if (ASCII_CHAR_P (copy_bufptr
[i
]))
8182 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
8185 if (nchars
< nbytes
)
8187 /* Decode the input data. */
8189 /* The input should be decoded with `coding_system'
8190 which depends on which X*LookupString function
8191 we used just above and the locale. */
8192 setup_coding_system (coding_system
, &coding
);
8193 coding
.src_multibyte
= false;
8194 coding
.dst_multibyte
= true;
8195 /* The input is converted to events, thus we can't
8196 handle composition. Anyway, there's no XIM that
8197 gives us composition information. */
8198 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
8200 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
8202 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
8203 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
8204 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
8205 nbytes
= coding
.produced
;
8206 nchars
= coding
.produced_char
;
8207 copy_bufptr
= coding
.destination
;
8210 /* Convert the input data to a sequence of
8211 character events. */
8212 for (i
= 0; i
< nbytes
; i
+= len
)
8215 if (nchars
== nbytes
)
8216 ch
= copy_bufptr
[i
], len
= 1;
8218 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
8219 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
8220 ? ASCII_KEYSTROKE_EVENT
8221 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
8223 kbd_buffer_store_buffered_event (&inev
, hold_quit
);
8228 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
8230 if (keysym
== NoSymbol
)
8233 /* FIXME: check side effects and remove this. */
8234 ((XEvent
*) event
)->xkey
= xkey
;
8238 /* Don't dispatch this event since XtDispatchEvent calls
8239 XFilterEvent, and two calls in a row may freeze the
8247 x_display_set_last_user_time (dpyinfo
, event
->xkey
.time
);
8249 /* Don't dispatch this event since XtDispatchEvent calls
8250 XFilterEvent, and two calls in a row may freeze the
8258 x_display_set_last_user_time (dpyinfo
, event
->xcrossing
.time
);
8259 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8263 if (f
&& x_mouse_click_focus_ignore_position
)
8264 ignore_next_mouse_click_timeout
= event
->xmotion
.time
+ 200;
8266 /* EnterNotify counts as mouse movement,
8267 so update things that depend on mouse position. */
8268 if (f
&& !f
->output_data
.x
->hourglass_p
)
8269 note_mouse_movement (f
, &event
->xmotion
);
8271 /* We may get an EnterNotify on the buttons in the toolbar. In that
8272 case we moved out of any highlighted area and need to note this. */
8273 if (!f
&& dpyinfo
->last_mouse_glyph_frame
)
8274 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
8279 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8283 x_display_set_last_user_time (dpyinfo
, event
->xcrossing
.time
);
8284 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8286 f
= x_top_window_to_frame (dpyinfo
, event
->xcrossing
.window
);
8289 if (f
== hlinfo
->mouse_face_mouse_frame
)
8291 /* If we move outside the frame, then we're
8292 certainly no longer on any text in the frame. */
8293 clear_mouse_face (hlinfo
);
8294 hlinfo
->mouse_face_mouse_frame
= 0;
8297 /* Generate a nil HELP_EVENT to cancel a help-echo.
8298 Do it only if there's something to cancel.
8299 Otherwise, the startup message is cleared when
8300 the mouse leaves the frame. */
8301 if (any_help_event_p
)
8305 /* See comment in EnterNotify above */
8306 else if (dpyinfo
->last_mouse_glyph_frame
)
8307 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
8312 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
8317 x_display_set_last_user_time (dpyinfo
, event
->xmotion
.time
);
8318 previous_help_echo_string
= help_echo_string
;
8319 help_echo_string
= Qnil
;
8321 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
8322 : x_window_to_frame (dpyinfo
, event
->xmotion
.window
));
8324 if (hlinfo
->mouse_face_hidden
)
8326 hlinfo
->mouse_face_hidden
= false;
8327 clear_mouse_face (hlinfo
);
8331 if (f
&& xg_event_is_for_scrollbar (f
, event
))
8337 /* Generate SELECT_WINDOW_EVENTs when needed.
8338 Don't let popup menus influence things (bug#1261). */
8339 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
8341 static Lisp_Object last_mouse_window
;
8342 Lisp_Object window
= window_from_coordinates
8343 (f
, event
->xmotion
.x
, event
->xmotion
.y
, 0, false);
8345 /* Window will be selected only when it is not selected now and
8346 last mouse movement event was not in it. Minibuffer window
8347 will be selected only when it is active. */
8348 if (WINDOWP (window
)
8349 && !EQ (window
, last_mouse_window
)
8350 && !EQ (window
, selected_window
)
8351 /* For click-to-focus window managers
8352 create event iff we don't leave the
8354 && (focus_follows_mouse
8355 || (EQ (XWINDOW (window
)->frame
,
8356 XWINDOW (selected_window
)->frame
))))
8358 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
8359 inev
.ie
.frame_or_window
= window
;
8361 /* Remember the last window where we saw the mouse. */
8362 last_mouse_window
= window
;
8364 if (!note_mouse_movement (f
, &event
->xmotion
))
8365 help_echo_string
= previous_help_echo_string
;
8369 #ifndef USE_TOOLKIT_SCROLL_BARS
8370 struct scroll_bar
*bar
8371 = x_window_to_scroll_bar (event
->xmotion
.display
,
8372 event
->xmotion
.window
, 2);
8375 x_scroll_bar_note_movement (bar
, &event
->xmotion
);
8376 #endif /* USE_TOOLKIT_SCROLL_BARS */
8378 /* If we move outside the frame, then we're
8379 certainly no longer on any text in the frame. */
8380 clear_mouse_face (hlinfo
);
8383 /* If the contents of the global variable help_echo_string
8384 has changed, generate a HELP_EVENT. */
8385 if (!NILP (help_echo_string
)
8386 || !NILP (previous_help_echo_string
))
8391 case ConfigureNotify
:
8392 /* An opaque move can generate a stream of events as the window
8393 is dragged around. If the connection round trip time isn't
8394 really short, they may come faster than we can respond to
8395 them, given the multiple queries we can do to check window
8396 manager state, translate coordinates, etc.
8398 So if this ConfigureNotify is immediately followed by another
8399 for the same window, use the info from the latest update, and
8400 consider the events all handled. */
8401 /* Opaque resize may be trickier; ConfigureNotify events are
8402 mixed with Expose events for multiple windows. */
8403 configureEvent
= *event
;
8404 while (XPending (dpyinfo
->display
))
8406 XNextEvent (dpyinfo
->display
, &next_event
);
8407 if (next_event
.type
!= ConfigureNotify
8408 || next_event
.xconfigure
.window
!= event
->xconfigure
.window
8409 /* Skipping events with different sizes can lead to a
8410 mispositioned mode line at initial window creation.
8411 Only drop window motion events for now. */
8412 || next_event
.xconfigure
.width
!= event
->xconfigure
.width
8413 || next_event
.xconfigure
.height
!= event
->xconfigure
.height
)
8415 XPutBackEvent (dpyinfo
->display
, &next_event
);
8419 configureEvent
= next_event
;
8421 f
= x_top_window_to_frame (dpyinfo
, configureEvent
.xconfigure
.window
);
8423 if (f
) x_cr_destroy_surface (f
);
8428 && configureEvent
.xconfigure
.window
== FRAME_X_WINDOW (f
))
8430 xg_frame_resized (f
, configureEvent
.xconfigure
.width
,
8431 configureEvent
.xconfigure
.height
);
8433 x_cr_destroy_surface (f
);
8440 x_net_wm_state (f
, configureEvent
.xconfigure
.window
);
8442 #ifdef USE_X_TOOLKIT
8443 /* Tip frames are pure X window, set size for them. */
8444 if (! NILP (tip_frame
) && XFRAME (tip_frame
) == f
)
8446 if (FRAME_PIXEL_HEIGHT (f
) != configureEvent
.xconfigure
.height
8447 || FRAME_PIXEL_WIDTH (f
) != configureEvent
.xconfigure
.width
)
8448 SET_FRAME_GARBAGED (f
);
8449 FRAME_PIXEL_HEIGHT (f
) = configureEvent
.xconfigure
.height
;
8450 FRAME_PIXEL_WIDTH (f
) = configureEvent
.xconfigure
.width
;
8454 #ifndef USE_X_TOOLKIT
8457 FRAME_PIXEL_TO_TEXT_WIDTH (f
, configureEvent
.xconfigure
.width
);
8459 FRAME_PIXEL_TO_TEXT_HEIGHT (f
, configureEvent
.xconfigure
.height
);
8461 /* In the toolkit version, change_frame_size
8462 is called by the code that handles resizing
8463 of the EmacsFrame widget. */
8465 /* Even if the number of character rows and columns has
8466 not changed, the font size may have changed, so we need
8467 to check the pixel dimensions as well. */
8468 if (width
!= FRAME_TEXT_WIDTH (f
)
8469 || height
!= FRAME_TEXT_HEIGHT (f
)
8470 || configureEvent
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
8471 || configureEvent
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
8473 change_frame_size (f
, width
, height
, false, true, false, true);
8474 x_clear_under_internal_border (f
);
8475 SET_FRAME_GARBAGED (f
);
8476 cancel_mouse_face (f
);
8478 #endif /* not USE_GTK */
8482 /* GTK creates windows but doesn't map them.
8483 Only get real positions when mapped. */
8484 if (FRAME_GTK_OUTER_WIDGET (f
)
8485 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
8487 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8490 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
8491 xic_set_statusarea (f
);
8500 /* If we decide we want to generate an event to be seen
8501 by the rest of Emacs, we put it here. */
8502 bool tool_bar_p
= false;
8504 memset (&compose_status
, 0, sizeof (compose_status
));
8505 dpyinfo
->last_mouse_glyph_frame
= NULL
;
8506 x_display_set_last_user_time (dpyinfo
, event
->xbutton
.time
);
8508 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
8509 : x_window_to_frame (dpyinfo
, event
->xbutton
.window
));
8512 if (f
&& xg_event_is_for_scrollbar (f
, event
))
8517 #if ! defined (USE_GTK)
8518 /* Is this in the tool-bar? */
8519 if (WINDOWP (f
->tool_bar_window
)
8520 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
8523 int x
= event
->xbutton
.x
;
8524 int y
= event
->xbutton
.y
;
8526 window
= window_from_coordinates (f
, x
, y
, 0, true);
8527 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
8529 if (tool_bar_p
&& event
->xbutton
.button
< 4)
8530 handle_tool_bar_click
8531 (f
, x
, y
, event
->xbutton
.type
== ButtonPress
,
8532 x_x_to_emacs_modifiers (dpyinfo
, event
->xbutton
.state
));
8534 #endif /* !USE_GTK */
8537 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8538 if (! popup_activated ())
8541 if (ignore_next_mouse_click_timeout
)
8543 if (event
->type
== ButtonPress
8544 && event
->xbutton
.time
> ignore_next_mouse_click_timeout
)
8546 ignore_next_mouse_click_timeout
= 0;
8547 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
8549 if (event
->type
== ButtonRelease
)
8550 ignore_next_mouse_click_timeout
= 0;
8553 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
8555 if (FRAME_X_EMBEDDED_P (f
))
8556 xembed_send_message (f
, event
->xbutton
.time
,
8557 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
8561 struct scroll_bar
*bar
8562 = x_window_to_scroll_bar (event
->xbutton
.display
,
8563 event
->xbutton
.window
, 2);
8565 #ifdef USE_TOOLKIT_SCROLL_BARS
8566 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
8568 if (bar
&& event
->xbutton
.state
& ControlMask
)
8570 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
8571 *finish
= X_EVENT_DROP
;
8573 #else /* not USE_TOOLKIT_SCROLL_BARS */
8575 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
8576 #endif /* not USE_TOOLKIT_SCROLL_BARS */
8579 if (event
->type
== ButtonPress
)
8581 dpyinfo
->grabbed
|= (1 << event
->xbutton
.button
);
8582 dpyinfo
->last_mouse_frame
= f
;
8583 #if ! defined (USE_GTK)
8584 if (f
&& !tool_bar_p
)
8585 f
->last_tool_bar_item
= -1;
8586 #endif /* not USE_GTK */
8589 dpyinfo
->grabbed
&= ~(1 << event
->xbutton
.button
);
8591 /* Ignore any mouse motion that happened before this event;
8592 any subsequent mouse-movement Emacs events should reflect
8593 only motion after the ButtonPress/Release. */
8595 f
->mouse_moved
= false;
8597 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
8598 f
= x_menubar_window_to_frame (dpyinfo
, event
);
8599 /* For a down-event in the menu bar,
8600 don't pass it to Xt right now.
8601 Instead, save it away
8602 and we will pass it to Xt from kbd_buffer_get_event.
8603 That way, we can run some Lisp code first. */
8604 if (! popup_activated ()
8606 /* Gtk+ menus only react to the first three buttons. */
8607 && event
->xbutton
.button
< 3
8609 && f
&& event
->type
== ButtonPress
8610 /* Verify the event is really within the menu bar
8611 and not just sent to it due to grabbing. */
8612 && event
->xbutton
.x
>= 0
8613 && event
->xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
8614 && event
->xbutton
.y
>= 0
8615 && event
->xbutton
.y
< FRAME_MENUBAR_HEIGHT (f
)
8616 && event
->xbutton
.same_screen
)
8618 if (!f
->output_data
.x
->saved_menu_event
)
8619 f
->output_data
.x
->saved_menu_event
= xmalloc (sizeof *event
);
8620 *f
->output_data
.x
->saved_menu_event
= *event
;
8621 inev
.ie
.kind
= MENU_BAR_ACTIVATE_EVENT
;
8622 XSETFRAME (inev
.ie
.frame_or_window
, f
);
8623 *finish
= X_EVENT_DROP
;
8627 #endif /* USE_X_TOOLKIT || USE_GTK */
8631 case CirculateNotify
:
8634 case CirculateRequest
:
8637 case VisibilityNotify
:
8641 /* Someone has changed the keyboard mapping - update the
8643 switch (event
->xmapping
.request
)
8645 case MappingModifier
:
8646 x_find_modifier_meanings (dpyinfo
);
8647 /* This is meant to fall through. */
8648 case MappingKeyboard
:
8649 XRefreshKeyboardMapping ((XMappingEvent
*) &event
->xmapping
);
8654 xft_settings_event (dpyinfo
, event
);
8659 #ifdef USE_X_TOOLKIT
8661 if (*finish
!= X_EVENT_DROP
)
8662 XtDispatchEvent ((XEvent
*) event
);
8664 #endif /* USE_X_TOOLKIT */
8669 if (inev
.ie
.kind
!= NO_EVENT
)
8671 kbd_buffer_store_buffered_event (&inev
, hold_quit
);
8676 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
8681 XSETFRAME (frame
, f
);
8687 any_help_event_p
= true;
8688 gen_help_event (help_echo_string
, frame
, help_echo_window
,
8689 help_echo_object
, help_echo_pos
);
8693 help_echo_string
= Qnil
;
8694 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
8703 /* Handles the XEvent EVENT on display DISPLAY.
8704 This is used for event loops outside the normal event handling,
8705 i.e. looping while a popup menu or a dialog is posted.
8707 Returns the value handle_one_xevent sets in the finish argument. */
8709 x_dispatch_event (XEvent
*event
, Display
*display
)
8711 struct x_display_info
*dpyinfo
;
8712 int finish
= X_EVENT_NORMAL
;
8714 dpyinfo
= x_display_info_for_display (display
);
8717 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
8722 /* Read events coming from the X server.
8723 Return as soon as there are no more events to be read.
8725 Return the number of characters stored into the buffer,
8726 thus pretending to be `read' (except the characters we store
8727 in the keyboard buffer can be multibyte, so are not necessarily
8731 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
8734 bool event_found
= false;
8735 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
8739 /* For debugging, this gives a way to fake an I/O error. */
8740 if (dpyinfo
== XTread_socket_fake_io_error
)
8742 XTread_socket_fake_io_error
= 0;
8743 x_io_error_quitter (dpyinfo
->display
);
8747 while (XPending (dpyinfo
->display
))
8752 XNextEvent (dpyinfo
->display
, &event
);
8755 /* Filter events for the current X input method. */
8756 if (x_filter_event (dpyinfo
, &event
))
8761 count
+= handle_one_xevent (dpyinfo
, &event
, &finish
, hold_quit
);
8763 if (finish
== X_EVENT_GOTO_OUT
)
8769 /* For GTK we must use the GTK event loop. But XEvents gets passed
8770 to our filter function above, and then to the big event switch.
8771 We use a bunch of globals to communicate with our filter function,
8772 that is kind of ugly, but it works.
8774 There is no way to do one display at the time, GTK just does events
8775 from all displays. */
8777 while (gtk_events_pending ())
8779 current_count
= count
;
8780 current_hold_quit
= hold_quit
;
8782 gtk_main_iteration ();
8784 count
= current_count
;
8786 current_hold_quit
= 0;
8788 if (current_finish
== X_EVENT_GOTO_OUT
)
8791 #endif /* USE_GTK */
8793 /* On some systems, an X bug causes Emacs to get no more events
8794 when the window is destroyed. Detect that. (1994.) */
8797 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
8798 One XNOOP in 100 loops will make Emacs terminate.
8799 B. Bretthauer, 1994 */
8801 if (x_noop_count
>= 100)
8805 if (next_noop_dpyinfo
== 0)
8806 next_noop_dpyinfo
= x_display_list
;
8808 XNoOp (next_noop_dpyinfo
->display
);
8810 /* Each time we get here, cycle through the displays now open. */
8811 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
8815 /* If the focus was just given to an auto-raising frame,
8816 raise it now. FIXME: handle more than one such frame. */
8817 if (dpyinfo
->x_pending_autoraise_frame
)
8819 x_raise_frame (dpyinfo
->x_pending_autoraise_frame
);
8820 dpyinfo
->x_pending_autoraise_frame
= NULL
;
8831 /***********************************************************************
8833 ***********************************************************************/
8835 /* Set clipping for output in glyph row ROW. W is the window in which
8836 we operate. GC is the graphics context to set clipping in.
8838 ROW may be a text row or, e.g., a mode line. Text rows must be
8839 clipped to the interior of the window dedicated to text display,
8840 mode lines must be clipped to the whole window. */
8843 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
8844 enum glyph_row_area area
, GC gc
)
8846 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8847 XRectangle clip_rect
;
8848 int window_x
, window_y
, window_width
;
8850 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
8852 clip_rect
.x
= window_x
;
8853 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
8854 clip_rect
.y
= max (clip_rect
.y
, window_y
);
8855 clip_rect
.width
= window_width
;
8856 clip_rect
.height
= row
->visible_height
;
8858 x_set_clip_rectangles (f
, gc
, &clip_rect
, 1);
8862 /* Draw a hollow box cursor on window W in glyph row ROW. */
8865 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
8867 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8868 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8869 Display
*dpy
= FRAME_X_DISPLAY (f
);
8872 struct glyph
*cursor_glyph
;
8875 /* Get the glyph the cursor is on. If we can't tell because
8876 the current matrix is invalid or such, give up. */
8877 cursor_glyph
= get_phys_cursor_glyph (w
);
8878 if (cursor_glyph
== NULL
)
8881 /* Compute frame-relative coordinates for phys cursor. */
8882 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
8883 wd
= w
->phys_cursor_width
- 1;
8885 /* The foreground of cursor_gc is typically the same as the normal
8886 background color, which can cause the cursor box to be invisible. */
8887 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
8888 if (dpyinfo
->scratch_cursor_gc
)
8889 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
8891 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
8892 GCForeground
, &xgcv
);
8893 gc
= dpyinfo
->scratch_cursor_gc
;
8895 /* When on R2L character, show cursor at the right edge of the
8896 glyph, unless the cursor box is as wide as the glyph or wider
8897 (the latter happens when x-stretch-cursor is non-nil). */
8898 if ((cursor_glyph
->resolved_level
& 1) != 0
8899 && cursor_glyph
->pixel_width
> wd
)
8901 x
+= cursor_glyph
->pixel_width
- wd
;
8905 /* Set clipping, draw the rectangle, and reset clipping again. */
8906 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
8907 x_draw_rectangle (f
, gc
, x
, y
, wd
, h
- 1);
8908 x_reset_clip_rectangles (f
, gc
);
8912 /* Draw a bar cursor on window W in glyph row ROW.
8914 Implementation note: One would like to draw a bar cursor with an
8915 angle equal to the one given by the font property XA_ITALIC_ANGLE.
8916 Unfortunately, I didn't find a font yet that has this property set.
8920 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
8922 struct frame
*f
= XFRAME (w
->frame
);
8923 struct glyph
*cursor_glyph
;
8925 /* If cursor is out of bounds, don't draw garbage. This can happen
8926 in mini-buffer windows when switching between echo area glyphs
8928 cursor_glyph
= get_phys_cursor_glyph (w
);
8929 if (cursor_glyph
== NULL
)
8932 #ifdef HAVE_XWIDGETS
8933 if (cursor_glyph
->type
== XWIDGET_GLYPH
)
8934 return; // Experimental avoidance of cursor on xwidget.
8937 /* If on an image, draw like a normal cursor. That's usually better
8938 visible than drawing a bar, esp. if the image is large so that
8939 the bar might not be in the window. */
8940 if (cursor_glyph
->type
== IMAGE_GLYPH
)
8942 struct glyph_row
*r
;
8943 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
8944 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
8948 Display
*dpy
= FRAME_X_DISPLAY (f
);
8949 Window window
= FRAME_X_WINDOW (f
);
8950 GC gc
= FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
;
8951 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
8952 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
8955 /* If the glyph's background equals the color we normally draw
8956 the bars cursor in, the bar cursor in its normal color is
8957 invisible. Use the glyph's foreground color instead in this
8958 case, on the assumption that the glyph's colors are chosen so
8959 that the glyph is legible. */
8960 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
8961 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
8963 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
8964 xgcv
.graphics_exposures
= False
;
8967 XChangeGC (dpy
, gc
, mask
, &xgcv
);
8970 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
8971 FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
8974 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
8976 if (kind
== BAR_CURSOR
)
8978 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8981 width
= FRAME_CURSOR_WIDTH (f
);
8982 width
= min (cursor_glyph
->pixel_width
, width
);
8984 w
->phys_cursor_width
= width
;
8986 /* If the character under cursor is R2L, draw the bar cursor
8987 on the right of its glyph, rather than on the left. */
8988 if ((cursor_glyph
->resolved_level
& 1) != 0)
8989 x
+= cursor_glyph
->pixel_width
- width
;
8991 x_fill_rectangle (f
, gc
, x
,
8992 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
8993 width
, row
->height
);
8995 else /* HBAR_CURSOR */
8997 int dummy_x
, dummy_y
, dummy_h
;
8998 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
9001 width
= row
->height
;
9003 width
= min (row
->height
, width
);
9005 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
9006 &dummy_y
, &dummy_h
);
9008 if ((cursor_glyph
->resolved_level
& 1) != 0
9009 && cursor_glyph
->pixel_width
> w
->phys_cursor_width
- 1)
9010 x
+= cursor_glyph
->pixel_width
- w
->phys_cursor_width
+ 1;
9011 x_fill_rectangle (f
, gc
, x
,
9012 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
9013 row
->height
- width
),
9014 w
->phys_cursor_width
- 1, width
);
9017 x_reset_clip_rectangles (f
, gc
);
9022 /* RIF: Define cursor CURSOR on frame F. */
9025 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
9027 if (!f
->pointer_invisible
9028 && f
->output_data
.x
->current_cursor
!= cursor
)
9029 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
9030 f
->output_data
.x
->current_cursor
= cursor
;
9034 /* RIF: Clear area on frame F. */
9037 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
9039 x_clear_area (f
, x
, y
, width
, height
);
9041 /* Must queue a redraw, because scroll bars might have been cleared. */
9042 if (FRAME_GTK_WIDGET (f
))
9043 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
9048 /* RIF: Draw cursor on window W. */
9051 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
9052 int y
, enum text_cursor_kinds cursor_type
,
9053 int cursor_width
, bool on_p
, bool active_p
)
9055 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
9059 w
->phys_cursor_type
= cursor_type
;
9060 w
->phys_cursor_on_p
= true;
9062 if (glyph_row
->exact_window_width_line_p
9063 && (glyph_row
->reversed_p
9064 ? (w
->phys_cursor
.hpos
< 0)
9065 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
9067 glyph_row
->cursor_in_fringe_p
= true;
9068 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
9072 switch (cursor_type
)
9074 case HOLLOW_BOX_CURSOR
:
9075 x_draw_hollow_cursor (w
, glyph_row
);
9078 case FILLED_BOX_CURSOR
:
9079 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
9083 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
9087 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
9091 w
->phys_cursor_width
= 0;
9100 if (w
== XWINDOW (f
->selected_window
))
9101 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
9102 xic_set_preeditarea (w
, x
, y
);
9106 XFlush (FRAME_X_DISPLAY (f
));
9112 /* Make the x-window of frame F use the gnu icon bitmap. */
9115 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
9117 ptrdiff_t bitmap_id
;
9119 if (FRAME_X_WINDOW (f
) == 0)
9122 /* Free up our existing icon bitmap and mask if any. */
9123 if (f
->output_data
.x
->icon_bitmap
> 0)
9124 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
9125 f
->output_data
.x
->icon_bitmap
= 0;
9130 /* Use gtk_window_set_icon_from_file () if available,
9131 It's not restricted to bitmaps */
9132 if (xg_set_icon (f
, file
))
9134 #endif /* USE_GTK */
9135 bitmap_id
= x_create_bitmap_from_file (f
, file
);
9136 x_create_bitmap_mask (f
, bitmap_id
);
9140 /* Create the GNU bitmap and mask if necessary. */
9141 if (FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
9147 if (xg_set_icon (f
, xg_default_icon_file
)
9148 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
9150 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= -2;
9154 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
9156 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
9158 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
9162 /* If all else fails, use the (black and white) xbm image. */
9165 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
9166 gnu_xbm_width
, gnu_xbm_height
);
9170 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
9171 x_create_bitmap_mask (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
9175 /* The first time we create the GNU bitmap and mask,
9176 this increments the ref-count one extra time.
9177 As a result, the GNU bitmap and mask are never freed.
9178 That way, we don't have to worry about allocating it again. */
9179 x_reference_bitmap (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
9181 bitmap_id
= FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
;
9184 x_wm_set_icon_pixmap (f
, bitmap_id
);
9185 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
9191 /* Make the x-window of frame F use a rectangle with text.
9192 Use ICON_NAME as the text. */
9195 x_text_icon (struct frame
*f
, const char *icon_name
)
9197 if (FRAME_X_WINDOW (f
) == 0)
9202 text
.value
= (unsigned char *) icon_name
;
9203 text
.encoding
= XA_STRING
;
9205 text
.nitems
= strlen (icon_name
);
9206 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
9209 if (f
->output_data
.x
->icon_bitmap
> 0)
9210 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
9211 f
->output_data
.x
->icon_bitmap
= 0;
9212 x_wm_set_icon_pixmap (f
, 0);
9217 #define X_ERROR_MESSAGE_SIZE 200
9219 /* If non-nil, this should be a string.
9220 It means catch X errors and store the error message in this string.
9222 The reason we use a stack is that x_catch_error/x_uncatch_error can
9223 be called from a signal handler.
9226 struct x_error_message_stack
{
9227 char string
[X_ERROR_MESSAGE_SIZE
];
9229 x_special_error_handler handler
;
9231 struct x_error_message_stack
*prev
;
9233 static struct x_error_message_stack
*x_error_message
;
9235 /* An X error handler which stores the error message in
9236 *x_error_message. This is called from x_error_handler if
9237 x_catch_errors is in effect. */
9240 x_error_catcher (Display
*display
, XErrorEvent
*event
)
9242 XGetErrorText (display
, event
->error_code
,
9243 x_error_message
->string
,
9244 X_ERROR_MESSAGE_SIZE
);
9245 if (x_error_message
->handler
)
9246 x_error_message
->handler (display
, event
, x_error_message
->string
,
9247 x_error_message
->handler_data
);
9250 /* Begin trapping X errors for display DPY. Actually we trap X errors
9251 for all displays, but DPY should be the display you are actually
9254 After calling this function, X protocol errors no longer cause
9255 Emacs to exit; instead, they are recorded in the string
9256 stored in *x_error_message.
9258 Calling x_check_errors signals an Emacs error if an X error has
9259 occurred since the last call to x_catch_errors or x_check_errors.
9261 Calling x_uncatch_errors resumes the normal error handling.
9262 Calling x_uncatch_errors_after_check is similar, but skips an XSync
9263 to the server, and should be used only immediately after
9264 x_had_errors_p or x_check_errors. */
9267 x_catch_errors_with_handler (Display
*dpy
, x_special_error_handler handler
,
9270 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
9272 /* Make sure any errors from previous requests have been dealt with. */
9276 data
->string
[0] = 0;
9277 data
->handler
= handler
;
9278 data
->handler_data
= handler_data
;
9279 data
->prev
= x_error_message
;
9280 x_error_message
= data
;
9284 x_catch_errors (Display
*dpy
)
9286 x_catch_errors_with_handler (dpy
, NULL
, NULL
);
9289 /* Undo the last x_catch_errors call.
9290 DPY should be the display that was passed to x_catch_errors.
9292 This version should be used only if the immediately preceding
9293 X-protocol-related thing was x_check_errors or x_had_error_p, both
9294 of which issue XSync calls, so we don't need to re-sync here. */
9297 x_uncatch_errors_after_check (void)
9299 struct x_error_message_stack
*tmp
;
9302 tmp
= x_error_message
;
9303 x_error_message
= x_error_message
->prev
;
9308 /* Undo the last x_catch_errors call.
9309 DPY should be the display that was passed to x_catch_errors. */
9312 x_uncatch_errors (void)
9314 struct x_error_message_stack
*tmp
;
9318 /* The display may have been closed before this function is called.
9319 Check if it is still open before calling XSync. */
9320 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
9321 XSync (x_error_message
->dpy
, False
);
9323 tmp
= x_error_message
;
9324 x_error_message
= x_error_message
->prev
;
9329 /* If any X protocol errors have arrived since the last call to
9330 x_catch_errors or x_check_errors, signal an Emacs error using
9331 sprintf (a buffer, FORMAT, the x error message text) as the text. */
9334 x_check_errors (Display
*dpy
, const char *format
)
9336 /* Make sure to catch any errors incurred so far. */
9339 if (x_error_message
->string
[0])
9341 char string
[X_ERROR_MESSAGE_SIZE
];
9342 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
9343 x_uncatch_errors ();
9344 error (format
, string
);
9348 /* Nonzero if we had any X protocol errors
9349 since we did x_catch_errors on DPY. */
9352 x_had_errors_p (Display
*dpy
)
9354 /* Make sure to catch any errors incurred so far. */
9357 return x_error_message
->string
[0] != 0;
9360 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
9363 x_clear_errors (Display
*dpy
)
9365 x_error_message
->string
[0] = 0;
9369 /* See comment in unwind_to_catch why calling this is a bad
9370 * idea. --lorentey */
9371 /* Close off all unclosed x_catch_errors calls. */
9374 x_fully_uncatch_errors (void)
9376 while (x_error_message
)
9377 x_uncatch_errors ();
9382 static unsigned int x_wire_count
;
9385 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
9390 /************************************************************************
9392 ************************************************************************/
9394 /* Error message passed to x_connection_closed. */
9396 static char *error_msg
;
9398 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
9399 the text of an error message that lead to the connection loss. */
9402 x_connection_closed (Display
*dpy
, const char *error_message
, bool ioerror
)
9404 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
9405 Lisp_Object frame
, tail
;
9406 ptrdiff_t idx
= SPECPDL_INDEX ();
9408 error_msg
= alloca (strlen (error_message
) + 1);
9409 strcpy (error_msg
, error_message
);
9411 /* Inhibit redisplay while frames are being deleted. */
9412 specbind (Qinhibit_redisplay
, Qt
);
9416 /* Protect display from being closed when we delete the last
9418 dpyinfo
->reference_count
++;
9419 dpyinfo
->terminal
->reference_count
++;
9421 if (ioerror
) dpyinfo
->display
= 0;
9423 /* First delete frames whose mini-buffers are on frames
9424 that are on the dead display. */
9425 FOR_EACH_FRAME (tail
, frame
)
9427 Lisp_Object minibuf_frame
;
9429 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
9430 if (FRAME_X_P (XFRAME (frame
))
9431 && FRAME_X_P (XFRAME (minibuf_frame
))
9432 && ! EQ (frame
, minibuf_frame
)
9433 && FRAME_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
9434 delete_frame (frame
, Qnoelisp
);
9437 /* Now delete all remaining frames on the dead display.
9438 We are now sure none of these is used as the mini-buffer
9439 for another frame that we need to delete. */
9440 FOR_EACH_FRAME (tail
, frame
)
9441 if (FRAME_X_P (XFRAME (frame
))
9442 && FRAME_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
9444 /* Set this to t so that delete_frame won't get confused
9445 trying to find a replacement. */
9446 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
9447 delete_frame (frame
, Qnoelisp
);
9450 /* If DPYINFO is null, this means we didn't open the display in the
9451 first place, so don't try to close it. */
9454 /* We can not call XtCloseDisplay here because it calls XSync.
9455 XSync inside the error handler apparently hangs Emacs. On
9456 current Xt versions, this isn't needed either. */
9458 /* A long-standing GTK bug prevents proper disconnect handling
9459 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
9460 the resulting Glib error message loop filled a user's disk.
9461 To avoid this, kill Emacs unconditionally on disconnect. */
9462 shut_down_emacs (0, Qnil
);
9463 fprintf (stderr
, "%s\n\
9464 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
9465 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
9466 For details, see etc/PROBLEMS.\n",
9469 #endif /* USE_GTK */
9471 /* Indicate that this display is dead. */
9472 dpyinfo
->display
= 0;
9474 dpyinfo
->reference_count
--;
9475 dpyinfo
->terminal
->reference_count
--;
9476 if (dpyinfo
->reference_count
!= 0)
9477 /* We have just closed all frames on this display. */
9482 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
9483 Fdelete_terminal (tmp
, Qnoelisp
);
9487 if (terminal_list
== 0)
9489 fprintf (stderr
, "%s\n", error_msg
);
9490 Fkill_emacs (make_number (70));
9494 totally_unblock_input ();
9496 unbind_to (idx
, Qnil
);
9497 clear_waiting_for_input ();
9499 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
9500 IF_LINT (if (! terminal_list
) return; )
9502 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
9503 longjmp), because returning from this function would get us back into
9504 Xlib's code which will directly call `exit'. */
9505 error ("%s", error_msg
);
9508 /* We specifically use it before defining it, so that gcc doesn't inline it,
9509 otherwise gdb doesn't know how to properly put a breakpoint on it. */
9510 static void x_error_quitter (Display
*, XErrorEvent
*);
9512 /* This is the first-level handler for X protocol errors.
9513 It calls x_error_quitter or x_error_catcher. */
9516 x_error_handler (Display
*display
, XErrorEvent
*event
)
9518 #if defined USE_GTK && defined HAVE_GTK3
9519 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
9520 && event
->request_code
== X_SetInputFocus
)
9526 if (x_error_message
)
9527 x_error_catcher (display
, event
);
9529 x_error_quitter (display
, event
);
9533 /* This is the usual handler for X protocol errors.
9534 It kills all frames on the display that we got the error for.
9535 If that was the only one, it prints an error message and kills Emacs. */
9537 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
9539 /* On older GCC versions, just putting x_error_quitter
9540 after x_error_handler prevents inlining into the former. */
9542 static void NO_INLINE
9543 x_error_quitter (Display
*display
, XErrorEvent
*event
)
9545 char buf
[256], buf1
[356];
9547 /* Ignore BadName errors. They can happen because of fonts
9548 or colors that are not defined. */
9550 if (event
->error_code
== BadName
)
9553 /* Note that there is no real way portable across R3/R4 to get the
9554 original error handler. */
9556 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
9557 sprintf (buf1
, "X protocol error: %s on protocol request %d",
9558 buf
, event
->request_code
);
9559 x_connection_closed (display
, buf1
, false);
9563 /* This is the handler for X IO errors, always.
9564 It kills all frames on the display that we lost touch with.
9565 If that was the only one, it prints an error message and kills Emacs. */
9568 x_io_error_quitter (Display
*display
)
9572 snprintf (buf
, sizeof buf
, "Connection lost to X server '%s'",
9573 DisplayString (display
));
9574 x_connection_closed (display
, buf
, true);
9578 /* Changing the font of the frame. */
9580 /* Give frame F the font FONT-OBJECT as its default font. The return
9581 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
9582 frame. If it is negative, generate a new fontset from
9586 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
9588 struct font
*font
= XFONT_OBJECT (font_object
);
9589 int unit
, font_ascent
, font_descent
;
9590 #ifndef USE_X_TOOLKIT
9591 int old_menu_bar_height
= FRAME_MENU_BAR_HEIGHT (f
);
9592 Lisp_Object fullscreen
;
9596 fontset
= fontset_from_font (font_object
);
9597 FRAME_FONTSET (f
) = fontset
;
9598 if (FRAME_FONT (f
) == font
)
9599 /* This font is already set in frame F. There's nothing more to
9603 FRAME_FONT (f
) = font
;
9604 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
9605 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
9606 get_font_ascent_descent (font
, &font_ascent
, &font_descent
);
9607 FRAME_LINE_HEIGHT (f
) = font_ascent
+ font_descent
;
9609 #ifndef USE_X_TOOLKIT
9610 FRAME_MENU_BAR_HEIGHT (f
) = FRAME_MENU_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
);
9613 /* Compute character columns occupied by scrollbar.
9615 Don't do things differently for non-toolkit scrollbars
9617 unit
= FRAME_COLUMN_WIDTH (f
);
9618 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
9619 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
9620 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
9622 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
9624 if (FRAME_X_WINDOW (f
) != 0)
9626 /* Don't change the size of a tip frame; there's no point in
9627 doing it because it's done in Fx_show_tip, and it leads to
9628 problems because the tip frame has no widget. */
9629 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9631 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
9632 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 3,
9634 #ifndef USE_X_TOOLKIT
9635 if (FRAME_MENU_BAR_HEIGHT (f
) != old_menu_bar_height
9636 && !f
->after_make_frame
9637 && (EQ (frame_inhibit_implied_resize
, Qt
)
9638 || (CONSP (frame_inhibit_implied_resize
)
9639 && NILP (Fmemq (Qfont
, frame_inhibit_implied_resize
))))
9640 && (NILP (fullscreen
= get_frame_param (f
, Qfullscreen
))
9641 || EQ (fullscreen
, Qfullwidth
)))
9642 /* If the menu bar height changes, try to keep text height
9645 (f
, -1, FRAME_TEXT_HEIGHT (f
) + FRAME_MENU_BAR_HEIGHT (f
)
9646 - old_menu_bar_height
, 1, false, Qfont
);
9647 #endif /* USE_X_TOOLKIT */
9653 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
9656 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
9665 /***********************************************************************
9667 ***********************************************************************/
9673 /* XIM destroy callback function, which is called whenever the
9674 connection to input method XIM dies. CLIENT_DATA contains a
9675 pointer to the x_display_info structure corresponding to XIM. */
9678 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
9680 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
9681 Lisp_Object frame
, tail
;
9685 /* No need to call XDestroyIC.. */
9686 FOR_EACH_FRAME (tail
, frame
)
9688 struct frame
*f
= XFRAME (frame
);
9689 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
9691 FRAME_XIC (f
) = NULL
;
9692 xic_free_xfontset (f
);
9696 /* No need to call XCloseIM. */
9697 dpyinfo
->xim
= NULL
;
9698 XFree (dpyinfo
->xim_styles
);
9702 #endif /* HAVE_X11R6 */
9704 /* Open the connection to the XIM server on display DPYINFO.
9705 RESOURCE_NAME is the resource name Emacs uses. */
9708 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
9716 XCloseIM (dpyinfo
->xim
);
9717 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
9724 XIMCallback destroy
;
9727 /* Get supported styles and XIM values. */
9728 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
9731 destroy
.callback
= xim_destroy_callback
;
9732 destroy
.client_data
= (XPointer
)dpyinfo
;
9733 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
9739 #endif /* HAVE_XIM */
9740 dpyinfo
->xim
= NULL
;
9744 #ifdef HAVE_X11R6_XIM
9746 /* XIM instantiate callback function, which is called whenever an XIM
9747 server is available. DISPLAY is the display of the XIM.
9748 CLIENT_DATA contains a pointer to an xim_inst_t structure created
9749 when the callback was registered. */
9752 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
9754 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
9755 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
9757 /* We don't support multiple XIM connections. */
9761 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
9763 /* Create XIC for the existing frames on the same display, as long
9764 as they have no XIC. */
9765 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
9767 Lisp_Object tail
, frame
;
9770 FOR_EACH_FRAME (tail
, frame
)
9772 struct frame
*f
= XFRAME (frame
);
9775 && FRAME_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
9776 if (FRAME_XIC (f
) == NULL
)
9778 create_frame_xic (f
);
9779 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
9780 xic_set_statusarea (f
);
9781 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
9783 struct window
*w
= XWINDOW (f
->selected_window
);
9784 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
9793 #endif /* HAVE_X11R6_XIM */
9796 /* Open a connection to the XIM server on display DPYINFO.
9797 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
9798 connection only at the first time. On X11R6, open the connection
9799 in the XIM instantiate callback function. */
9802 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
9804 dpyinfo
->xim
= NULL
;
9808 #ifdef HAVE_X11R6_XIM
9809 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
9812 dpyinfo
->xim_callback_data
= xim_inst
;
9813 xim_inst
->dpyinfo
= dpyinfo
;
9814 xim_inst
->resource_name
= xstrdup (resource_name
);
9815 ret
= XRegisterIMInstantiateCallback
9816 (dpyinfo
->display
, dpyinfo
->xrdb
, xim_inst
->resource_name
,
9817 emacs_class
, xim_instantiate_callback
,
9818 /* This is XPointer in XFree86 but (XPointer *)
9819 on Tru64, at least, hence the configure test. */
9820 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
9821 eassert (ret
== True
);
9822 #else /* not HAVE_X11R6_XIM */
9823 xim_open_dpy (dpyinfo
, resource_name
);
9824 #endif /* not HAVE_X11R6_XIM */
9826 #endif /* HAVE_XIM */
9830 /* Close the connection to the XIM server on display DPYINFO. */
9833 xim_close_dpy (struct x_display_info
*dpyinfo
)
9838 #ifdef HAVE_X11R6_XIM
9839 struct xim_inst_t
*xim_inst
= dpyinfo
->xim_callback_data
;
9841 if (dpyinfo
->display
)
9843 Bool ret
= XUnregisterIMInstantiateCallback
9844 (dpyinfo
->display
, dpyinfo
->xrdb
, xim_inst
->resource_name
,
9845 emacs_class
, xim_instantiate_callback
,
9846 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
9847 eassert (ret
== True
);
9849 xfree (xim_inst
->resource_name
);
9851 #endif /* HAVE_X11R6_XIM */
9852 if (dpyinfo
->display
)
9853 XCloseIM (dpyinfo
->xim
);
9854 dpyinfo
->xim
= NULL
;
9855 XFree (dpyinfo
->xim_styles
);
9857 #endif /* HAVE_XIM */
9860 #endif /* not HAVE_X11R6_XIM */
9864 /* Calculate the absolute position in frame F
9865 from its current recorded position values and gravity. */
9868 x_calc_absolute_position (struct frame
*f
)
9870 int flags
= f
->size_hint_flags
;
9872 /* We have nothing to do if the current position
9873 is already for the top-left corner. */
9874 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
9877 /* Treat negative positions as relative to the leftmost bottommost
9878 position that fits on the screen. */
9879 if (flags
& XNegative
)
9880 f
->left_pos
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
9881 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
9884 int height
= FRAME_PIXEL_HEIGHT (f
);
9886 #if defined USE_X_TOOLKIT && defined USE_MOTIF
9887 /* Something is fishy here. When using Motif, starting Emacs with
9888 `-g -0-0', the frame appears too low by a few pixels.
9890 This seems to be so because initially, while Emacs is starting,
9891 the column widget's height and the frame's pixel height are
9892 different. The column widget's height is the right one. In
9893 later invocations, when Emacs is up, the frame's pixel height
9896 It's not obvious where the initial small difference comes from.
9897 2000-12-01, gerd. */
9899 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
9902 if (flags
& YNegative
)
9903 f
->top_pos
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
9904 - height
+ f
->top_pos
;
9907 /* The left_pos and top_pos
9908 are now relative to the top and left screen edges,
9909 so the flags should correspond. */
9910 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9913 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
9914 to really change the position, and 0 when calling from
9915 x_make_frame_visible (in that case, XOFF and YOFF are the current
9916 position values). It is -1 when calling from x_set_frame_parameters,
9917 which means, do adjust for borders but don't change the gravity. */
9920 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
9922 int modified_top
, modified_left
;
9924 if (change_gravity
> 0)
9928 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
9930 f
->size_hint_flags
|= XNegative
;
9932 f
->size_hint_flags
|= YNegative
;
9933 f
->win_gravity
= NorthWestGravity
;
9935 x_calc_absolute_position (f
);
9938 x_wm_set_size_hint (f
, 0, false);
9940 modified_left
= f
->left_pos
;
9941 modified_top
= f
->top_pos
;
9943 if (change_gravity
!= 0 && FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
9945 /* Some WMs (twm, wmaker at least) has an offset that is smaller
9946 than the WM decorations. So we use the calculated offset instead
9947 of the WM decoration sizes here (x/y_pixels_outer_diff). */
9948 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
9949 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
9952 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9953 modified_left
, modified_top
);
9955 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
9956 FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
);
9958 /* change_gravity is non-zero when this function is called from Lisp to
9959 programmatically move a frame. In that case, we call
9960 x_check_expected_move to discover if we have a "Type A" or "Type B"
9961 window manager, and, for a "Type A" window manager, adjust the position
9964 We call x_check_expected_move if a programmatic move occurred, and
9965 either the window manager type (A/B) is unknown or it is Type A but we
9966 need to compute the top/left offset adjustment for this frame. */
9968 if (change_gravity
!= 0
9969 && (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
9970 || (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
9971 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
9972 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
9973 x_check_expected_move (f
, modified_left
, modified_top
);
9978 /* Return true if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
9979 on the root window for frame F contains ATOMNAME.
9980 This is how a WM check shall be done according to the Window Manager
9981 Specification/Extended Window Manager Hints at
9982 http://freedesktop.org/wiki/Specifications/wm-spec. */
9985 x_wm_supports (struct frame
*f
, Atom want_atom
)
9988 unsigned long actual_size
, bytes_remaining
;
9989 int i
, rc
, actual_format
;
9991 Window wmcheck_window
;
9992 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9993 Window target_window
= dpyinfo
->root_window
;
9994 int max_len
= 65536;
9995 Display
*dpy
= FRAME_X_DISPLAY (f
);
9996 unsigned char *tmp_data
= NULL
;
9997 Atom target_type
= XA_WINDOW
;
10001 x_catch_errors (dpy
);
10002 rc
= XGetWindowProperty (dpy
, target_window
,
10003 dpyinfo
->Xatom_net_supporting_wm_check
,
10004 0, max_len
, False
, target_type
,
10005 &actual_type
, &actual_format
, &actual_size
,
10006 &bytes_remaining
, &tmp_data
);
10008 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
10010 if (tmp_data
) XFree (tmp_data
);
10011 x_uncatch_errors ();
10016 wmcheck_window
= *(Window
*) tmp_data
;
10019 /* Check if window exists. */
10020 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
10021 if (x_had_errors_p (dpy
))
10023 x_uncatch_errors_after_check ();
10028 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
10030 /* Window changed, reload atoms */
10031 if (dpyinfo
->net_supported_atoms
!= NULL
)
10032 XFree (dpyinfo
->net_supported_atoms
);
10033 dpyinfo
->net_supported_atoms
= NULL
;
10034 dpyinfo
->nr_net_supported_atoms
= 0;
10035 dpyinfo
->net_supported_window
= 0;
10037 target_type
= XA_ATOM
;
10039 rc
= XGetWindowProperty (dpy
, target_window
,
10040 dpyinfo
->Xatom_net_supported
,
10041 0, max_len
, False
, target_type
,
10042 &actual_type
, &actual_format
, &actual_size
,
10043 &bytes_remaining
, &tmp_data
);
10045 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
10047 if (tmp_data
) XFree (tmp_data
);
10048 x_uncatch_errors ();
10053 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
10054 dpyinfo
->nr_net_supported_atoms
= actual_size
;
10055 dpyinfo
->net_supported_window
= wmcheck_window
;
10060 for (i
= 0; !ret
&& i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
10061 ret
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
10063 x_uncatch_errors ();
10070 set_wm_state (Lisp_Object frame
, bool add
, Atom atom
, Atom value
)
10072 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (XFRAME (frame
));
10074 x_send_client_event (frame
, make_number (0), frame
,
10075 dpyinfo
->Xatom_net_wm_state
,
10077 /* 1 = add, 0 = remove */
10079 (make_number (add
),
10081 (make_fixnum_or_float (atom
),
10083 ? list1 (make_fixnum_or_float (value
))
10088 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
10091 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10093 XSETFRAME (frame
, f
);
10095 set_wm_state (frame
, !NILP (new_value
),
10096 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
10099 /* Return the current _NET_WM_STATE.
10100 SIZE_STATE is set to one of the FULLSCREEN_* values.
10101 Set *STICKY to the sticky state.
10103 Return true iff we are not hidden. */
10106 get_current_wm_state (struct frame
*f
,
10111 unsigned long actual_size
;
10113 bool is_hidden
= false;
10114 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10115 long max_len
= 65536;
10116 Atom target_type
= XA_ATOM
;
10117 /* If XCB is available, we can avoid three XSync calls. */
10119 xcb_get_property_cookie_t prop_cookie
;
10120 xcb_get_property_reply_t
*prop
;
10121 xcb_atom_t
*reply_data
;
10123 Display
*dpy
= FRAME_X_DISPLAY (f
);
10124 unsigned long bytes_remaining
;
10125 int rc
, actual_format
;
10127 unsigned char *tmp_data
= NULL
;
10132 *size_state
= FULLSCREEN_NONE
;
10137 prop_cookie
= xcb_get_property (dpyinfo
->xcb_connection
, 0, window
,
10138 dpyinfo
->Xatom_net_wm_state
,
10139 target_type
, 0, max_len
);
10140 prop
= xcb_get_property_reply (dpyinfo
->xcb_connection
, prop_cookie
, NULL
);
10141 if (prop
&& prop
->type
== target_type
)
10143 int actual_bytes
= xcb_get_property_value_length (prop
);
10144 eassume (0 <= actual_bytes
);
10145 actual_size
= actual_bytes
/ sizeof *reply_data
;
10146 reply_data
= xcb_get_property_value (prop
);
10151 is_hidden
= FRAME_ICONIFIED_P (f
);
10154 x_catch_errors (dpy
);
10155 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
10156 0, max_len
, False
, target_type
,
10157 &actual_type
, &actual_format
, &actual_size
,
10158 &bytes_remaining
, &tmp_data
);
10160 if (rc
== Success
&& actual_type
== target_type
&& ! x_had_errors_p (dpy
))
10161 reply_data
= (Atom
*) tmp_data
;
10165 is_hidden
= FRAME_ICONIFIED_P (f
);
10168 x_uncatch_errors ();
10171 for (i
= 0; i
< actual_size
; ++i
)
10173 Atom a
= reply_data
[i
];
10174 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
10176 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
10178 if (*size_state
== FULLSCREEN_HEIGHT
)
10179 *size_state
= FULLSCREEN_MAXIMIZED
;
10181 *size_state
= FULLSCREEN_WIDTH
;
10183 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
10185 if (*size_state
== FULLSCREEN_WIDTH
)
10186 *size_state
= FULLSCREEN_MAXIMIZED
;
10188 *size_state
= FULLSCREEN_HEIGHT
;
10190 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
10191 *size_state
= FULLSCREEN_BOTH
;
10192 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
10199 if (tmp_data
) XFree (tmp_data
);
10203 return ! is_hidden
;
10206 /* Do fullscreen as specified in extended window manager hints */
10209 do_ewmh_fullscreen (struct frame
*f
)
10211 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10212 bool have_net_atom
= x_wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
10216 get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
10218 /* Some window managers don't say they support _NET_WM_STATE, but they do say
10219 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
10220 if (!have_net_atom
)
10221 have_net_atom
= x_wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
10223 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
10227 XSETFRAME (frame
, f
);
10229 /* Keep number of calls to set_wm_state as low as possible.
10230 Some window managers, or possible Gtk+, hangs when too many
10231 are sent at once. */
10232 switch (f
->want_fullscreen
)
10234 case FULLSCREEN_BOTH
:
10235 if (cur
!= FULLSCREEN_BOTH
)
10236 set_wm_state (frame
, true, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10239 case FULLSCREEN_WIDTH
:
10240 if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_MAXIMIZED
)
10242 set_wm_state (frame
, false,
10243 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10244 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10245 set_wm_state (frame
, true,
10246 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10250 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
10251 || cur
== FULLSCREEN_MAXIMIZED
)
10252 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10253 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10254 if (cur
!= FULLSCREEN_MAXIMIZED
|| x_frame_normalize_before_maximize
)
10255 set_wm_state (frame
, true,
10256 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10259 case FULLSCREEN_HEIGHT
:
10260 if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_MAXIMIZED
)
10262 set_wm_state (frame
, false,
10263 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10264 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10265 set_wm_state (frame
, true,
10266 dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
10270 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
10271 || cur
== FULLSCREEN_MAXIMIZED
)
10272 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10273 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
10274 if (cur
!= FULLSCREEN_MAXIMIZED
|| x_frame_normalize_before_maximize
)
10275 set_wm_state (frame
, true,
10276 dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
10279 case FULLSCREEN_MAXIMIZED
:
10280 if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_BOTH
)
10282 set_wm_state (frame
, false,
10283 dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
10284 set_wm_state (frame
, true,
10285 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10286 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10288 else if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_WIDTH
)
10290 set_wm_state (frame
, false,
10291 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10292 set_wm_state (frame
, true,
10293 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10294 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10296 else if (x_frame_normalize_before_maximize
&& cur
== FULLSCREEN_HEIGHT
)
10298 set_wm_state (frame
, false,
10299 dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
10300 set_wm_state (frame
, true,
10301 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10302 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10306 if (cur
== FULLSCREEN_BOTH
)
10307 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10309 else if (cur
== FULLSCREEN_HEIGHT
)
10310 set_wm_state (frame
, true,
10311 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
10312 else if (cur
== FULLSCREEN_WIDTH
)
10313 set_wm_state (frame
, true, None
,
10314 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10316 set_wm_state (frame
, true,
10317 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10318 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10321 case FULLSCREEN_NONE
:
10322 if (cur
== FULLSCREEN_BOTH
)
10323 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
10326 set_wm_state (frame
, false,
10327 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
10328 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
10331 f
->want_fullscreen
= FULLSCREEN_NONE
;
10335 return have_net_atom
;
10339 XTfullscreen_hook (struct frame
*f
)
10341 if (FRAME_VISIBLE_P (f
))
10344 x_check_fullscreen (f
);
10352 x_handle_net_wm_state (struct frame
*f
, const XPropertyEvent
*event
)
10354 int value
= FULLSCREEN_NONE
;
10356 bool sticky
= false;
10357 bool not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
10362 case FULLSCREEN_WIDTH
:
10365 case FULLSCREEN_HEIGHT
:
10366 lval
= Qfullheight
;
10368 case FULLSCREEN_BOTH
:
10371 case FULLSCREEN_MAXIMIZED
:
10376 frame_size_history_add
10377 (f
, Qx_handle_net_wm_state
, 0, 0,
10378 list2 (get_frame_param (f
, Qfullscreen
), lval
));
10380 store_frame_param (f
, Qfullscreen
, lval
);
10381 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
10386 /* Check if we need to resize the frame due to a fullscreen request.
10387 If so needed, resize the frame. */
10389 x_check_fullscreen (struct frame
*f
)
10391 Lisp_Object lval
= Qnil
;
10393 if (do_ewmh_fullscreen (f
))
10396 if (f
->output_data
.x
->parent_desc
!= FRAME_DISPLAY_INFO (f
)->root_window
)
10397 return; /* Only fullscreen without WM or with EWM hints (above). */
10399 /* Setting fullscreen to nil doesn't do anything. We could save the
10400 last non-fullscreen size and restore it, but it seems like a
10401 lot of work for this unusual case (no window manager running). */
10403 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
10405 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
10406 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10408 switch (f
->want_fullscreen
)
10410 /* No difference between these two when there is no WM */
10411 case FULLSCREEN_MAXIMIZED
:
10413 width
= x_display_pixel_width (dpyinfo
);
10414 height
= x_display_pixel_height (dpyinfo
);
10416 case FULLSCREEN_BOTH
:
10418 width
= x_display_pixel_width (dpyinfo
);
10419 height
= x_display_pixel_height (dpyinfo
);
10421 case FULLSCREEN_WIDTH
:
10423 width
= x_display_pixel_width (dpyinfo
);
10424 height
= height
+ FRAME_MENUBAR_HEIGHT (f
);
10426 case FULLSCREEN_HEIGHT
:
10427 lval
= Qfullheight
;
10428 height
= x_display_pixel_height (dpyinfo
);
10434 frame_size_history_add
10435 (f
, Qx_check_fullscreen
, width
, height
, Qnil
);
10437 x_wm_set_size_hint (f
, 0, false);
10439 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10442 if (FRAME_VISIBLE_P (f
))
10443 x_wait_for_event (f
, ConfigureNotify
);
10446 change_frame_size (f
, width
, height
- FRAME_MENUBAR_HEIGHT (f
),
10447 false, true, false, true);
10452 /* `x_net_wm_state' might have reset the fullscreen frame parameter,
10454 store_frame_param (f
, Qfullscreen
, lval
);
10457 /* This function is called by x_set_offset to determine whether the window
10458 manager interfered with the positioning of the frame. Type A window
10459 managers position the surrounding window manager decorations a small
10460 amount above and left of the user-supplied position. Type B window
10461 managers position the surrounding window manager decorations at the
10462 user-specified position. If we detect a Type A window manager, we
10463 compensate by moving the window right and down by the proper amount. */
10466 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
10468 int current_left
= 0, current_top
= 0;
10470 /* x_real_positions returns the left and top offsets of the outermost
10471 window manager window around the frame. */
10473 x_real_positions (f
, ¤t_left
, ¤t_top
);
10475 if (current_left
!= expected_left
|| current_top
!= expected_top
)
10477 /* It's a "Type A" window manager. */
10482 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
10483 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
10484 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
10486 /* Now fix the mispositioned frame's location. */
10488 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
10489 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
10491 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10492 adjusted_left
, adjusted_top
);
10494 x_sync_with_move (f
, expected_left
, expected_top
, false);
10497 /* It's a "Type B" window manager. We don't have to adjust the
10498 frame's position. */
10500 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
10504 /* Wait for XGetGeometry to return up-to-date position information for a
10505 recently-moved frame. Call this immediately after calling XMoveWindow.
10506 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
10507 frame has been moved to, so we use a fuzzy position comparison instead
10508 of an exact comparison. */
10511 x_sync_with_move (struct frame
*f
, int left
, int top
, bool fuzzy
)
10515 while (count
++ < 50)
10517 int current_left
= 0, current_top
= 0;
10519 /* In theory, this call to XSync only needs to happen once, but in
10520 practice, it doesn't seem to work, hence the need for the surrounding
10523 XSync (FRAME_X_DISPLAY (f
), False
);
10524 x_real_positions (f
, ¤t_left
, ¤t_top
);
10528 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
10531 if (eabs (current_left
- left
) <= 10
10532 && eabs (current_top
- top
) <= 40)
10535 else if (current_left
== left
&& current_top
== top
)
10539 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
10540 will then return up-to-date position info. */
10542 wait_reading_process_output (0, 500000000, 0, false, Qnil
, NULL
, 0);
10546 /* Wait for an event on frame F matching EVENTTYPE. */
10548 x_wait_for_event (struct frame
*f
, int eventtype
)
10550 int level
= interrupt_input_blocked
;
10553 struct timespec tmo
, tmo_at
, time_now
;
10554 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
10556 f
->wait_event_type
= eventtype
;
10558 /* Set timeout to 0.1 second. Hopefully not noticeable.
10559 Maybe it should be configurable. */
10560 tmo
= make_timespec (0, 100 * 1000 * 1000);
10561 tmo_at
= timespec_add (current_timespec (), tmo
);
10563 while (f
->wait_event_type
)
10565 pending_signals
= true;
10566 totally_unblock_input ();
10567 /* XTread_socket is called after unblock. */
10569 interrupt_input_blocked
= level
;
10574 time_now
= current_timespec ();
10575 if (timespec_cmp (tmo_at
, time_now
) < 0)
10578 tmo
= timespec_sub (tmo_at
, time_now
);
10579 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
10580 break; /* Timeout */
10583 f
->wait_event_type
= 0;
10587 /* Change the size of frame F's X window to WIDTH/HEIGHT in the case F
10588 doesn't have a widget. If CHANGE_GRAVITY, change to
10589 top-left-corner window gravity for this size change and subsequent
10590 size changes. Otherwise leave the window gravity unchanged. */
10593 x_set_window_size_1 (struct frame
*f
, bool change_gravity
,
10594 int width
, int height
)
10596 int pixelwidth
= FRAME_TEXT_TO_PIXEL_WIDTH (f
, width
);
10597 int pixelheight
= FRAME_TEXT_TO_PIXEL_HEIGHT (f
, height
);
10598 int old_width
= FRAME_PIXEL_WIDTH (f
);
10599 int old_height
= FRAME_PIXEL_HEIGHT (f
);
10600 Lisp_Object fullscreen
= get_frame_param (f
, Qfullscreen
);
10602 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
10603 x_wm_set_size_hint (f
, 0, false);
10605 /* When the frame is fullheight and we only want to change the width
10606 or it is fullwidth and we only want to change the height we should
10607 be able to preserve the fullscreen property. However, due to the
10608 fact that we have to send a resize request anyway, the window
10609 manager will abolish it. At least the respective size should
10610 remain unchanged but giving the frame back its normal size will
10612 if (EQ (fullscreen
, Qfullwidth
) && width
== FRAME_TEXT_WIDTH (f
))
10614 frame_size_history_add
10615 (f
, Qx_set_window_size_1
, width
, height
,
10616 list2 (make_number (old_height
),
10617 make_number (pixelheight
+ FRAME_MENUBAR_HEIGHT (f
))));
10619 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10620 old_width
, pixelheight
+ FRAME_MENUBAR_HEIGHT (f
));
10622 else if (EQ (fullscreen
, Qfullheight
) && height
== FRAME_TEXT_HEIGHT (f
))
10624 frame_size_history_add
10625 (f
, Qx_set_window_size_2
, width
, height
,
10626 list2 (make_number (old_width
), make_number (pixelwidth
)));
10628 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10629 pixelwidth
, old_height
);
10634 frame_size_history_add
10635 (f
, Qx_set_window_size_3
, width
, height
,
10636 list3 (make_number (pixelwidth
+ FRAME_TOOLBAR_WIDTH (f
)),
10637 make_number (pixelheight
+ FRAME_TOOLBAR_HEIGHT (f
)
10638 + FRAME_MENUBAR_HEIGHT (f
)),
10639 make_number (FRAME_MENUBAR_HEIGHT (f
))));
10641 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10642 pixelwidth
, pixelheight
+ FRAME_MENUBAR_HEIGHT (f
));
10648 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
10649 receive in the ConfigureNotify event; if we get what we asked
10650 for, then the event won't cause the screen to become garbaged, so
10651 we have to make sure to do it here. */
10652 SET_FRAME_GARBAGED (f
);
10654 /* Now, strictly speaking, we can't be sure that this is accurate,
10655 but the window manager will get around to dealing with the size
10656 change request eventually, and we'll hear how it went when the
10657 ConfigureNotify event gets here.
10659 We could just not bother storing any of this information here,
10660 and let the ConfigureNotify event set everything up, but that
10661 might be kind of confusing to the Lisp code, since size changes
10662 wouldn't be reported in the frame parameters until some random
10663 point in the future when the ConfigureNotify event arrives.
10665 Pass true for DELAY since we can't run Lisp code inside of
10668 /* But the ConfigureNotify may in fact never arrive, and then this is
10669 not right if the frame is visible. Instead wait (with timeout)
10670 for the ConfigureNotify. */
10671 if (FRAME_VISIBLE_P (f
))
10673 x_wait_for_event (f
, ConfigureNotify
);
10675 if (!NILP (fullscreen
))
10676 /* Try to restore fullscreen state. */
10678 store_frame_param (f
, Qfullscreen
, fullscreen
);
10679 x_set_fullscreen (f
, fullscreen
, fullscreen
);
10684 change_frame_size (f
, width
, height
, false, true, false, true);
10690 /* Call this to change the size of frame F's x-window.
10691 If CHANGE_GRAVITY, change to top-left-corner window gravity
10692 for this size change and subsequent size changes.
10693 Otherwise we leave the window gravity unchanged. */
10696 x_set_window_size (struct frame
*f
, bool change_gravity
,
10697 int width
, int height
, bool pixelwise
)
10701 /* The following breaks our calculations. If it's really needed,
10702 think of something else. */
10704 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
10706 int text_width
, text_height
;
10708 /* When the frame is maximized/fullscreen or running under for
10709 example Xmonad, x_set_window_size_1 will be a no-op.
10710 In that case, the right thing to do is extend rows/width to
10711 the current frame size. We do that first if x_set_window_size_1
10712 turns out to not be a no-op (there is no way to know).
10713 The size will be adjusted again if the frame gets a
10714 ConfigureNotify event as a result of x_set_window_size. */
10715 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
10716 #ifdef USE_X_TOOLKIT
10717 /* The menu bar is not part of text lines. The tool bar
10719 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
10721 text_width
= FRAME_PIXEL_TO_TEXT_WIDTH (f
, FRAME_PIXEL_WIDTH (f
));
10722 text_height
= FRAME_PIXEL_TO_TEXT_HEIGHT (f
, pixelh
);
10724 change_frame_size (f
, text_width
, text_height
, false, true, false, true);
10728 /* Pixelize width and height, if necessary. */
10731 width
= width
* FRAME_COLUMN_WIDTH (f
);
10732 height
= height
* FRAME_LINE_HEIGHT (f
);
10736 if (FRAME_GTK_WIDGET (f
))
10737 xg_frame_set_char_size (f
, width
, height
);
10739 x_set_window_size_1 (f
, change_gravity
, width
, height
);
10740 #else /* not USE_GTK */
10741 x_set_window_size_1 (f
, change_gravity
, width
, height
);
10742 x_clear_under_internal_border (f
);
10743 #endif /* not USE_GTK */
10745 /* If cursor was outside the new size, mark it as off. */
10746 mark_window_cursors_off (XWINDOW (f
->root_window
));
10748 /* Clear out any recollection of where the mouse highlighting was,
10749 since it might be in a place that's outside the new frame size.
10750 Actually checking whether it is outside is a pain in the neck,
10751 so don't try--just let the highlighting be done afresh with new size. */
10752 cancel_mouse_face (f
);
10757 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
10760 frame_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
10764 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
10765 0, 0, 0, 0, pix_x
, pix_y
);
10769 /* Raise frame F. */
10772 x_raise_frame (struct frame
*f
)
10775 if (FRAME_VISIBLE_P (f
))
10776 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
10777 XFlush (FRAME_X_DISPLAY (f
));
10781 /* Lower frame F. */
10784 x_lower_frame (struct frame
*f
)
10786 if (FRAME_VISIBLE_P (f
))
10789 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
10790 XFlush (FRAME_X_DISPLAY (f
));
10795 /* Request focus with XEmbed */
10798 xembed_request_focus (struct frame
*f
)
10800 /* See XEmbed Protocol Specification at
10801 http://freedesktop.org/wiki/Specifications/xembed-spec */
10802 if (FRAME_VISIBLE_P (f
))
10803 xembed_send_message (f
, CurrentTime
,
10804 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
10807 /* Activate frame with Extended Window Manager Hints */
10810 x_ewmh_activate_frame (struct frame
*f
)
10812 /* See Window Manager Specification/Extended Window Manager Hints at
10813 http://freedesktop.org/wiki/Specifications/wm-spec */
10815 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10817 if (FRAME_VISIBLE_P (f
) && x_wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
10820 XSETFRAME (frame
, f
);
10821 x_send_client_event (frame
, make_number (0), frame
,
10822 dpyinfo
->Xatom_net_active_window
,
10824 list2i (1, dpyinfo
->last_user_time
));
10829 XTframe_raise_lower (struct frame
*f
, bool raise_flag
)
10837 /* XEmbed implementation. */
10839 #if defined USE_X_TOOLKIT || ! defined USE_GTK
10841 /* XEmbed implementation. */
10843 #define XEMBED_VERSION 0
10846 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
10848 unsigned long data
[2];
10849 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10851 data
[0] = XEMBED_VERSION
;
10854 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10855 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
10856 32, PropModeReplace
, (unsigned char *) data
, 2);
10858 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
10861 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
10862 long int detail
, long int data1
, long int data2
)
10866 event
.xclient
.type
= ClientMessage
;
10867 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
10868 event
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_XEMBED
;
10869 event
.xclient
.format
= 32;
10870 event
.xclient
.data
.l
[0] = t
;
10871 event
.xclient
.data
.l
[1] = msg
;
10872 event
.xclient
.data
.l
[2] = detail
;
10873 event
.xclient
.data
.l
[3] = data1
;
10874 event
.xclient
.data
.l
[4] = data2
;
10876 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
10877 False
, NoEventMask
, &event
);
10878 XSync (FRAME_X_DISPLAY (f
), False
);
10881 /* Change of visibility. */
10883 /* This tries to wait until the frame is really visible.
10884 However, if the window manager asks the user where to position
10885 the frame, this will return before the user finishes doing that.
10886 The frame will not actually be visible at that time,
10887 but it will become visible later when the window manager
10888 finishes with it. */
10891 x_make_frame_visible (struct frame
*f
)
10893 int original_top
, original_left
;
10898 x_set_bitmap_icon (f
);
10900 if (! FRAME_VISIBLE_P (f
))
10902 /* We test FRAME_GARBAGED_P here to make sure we don't
10903 call x_set_offset a second time
10904 if we get to x_make_frame_visible a second time
10905 before the window gets really visible. */
10906 if (! FRAME_ICONIFIED_P (f
)
10907 && ! FRAME_X_EMBEDDED_P (f
)
10908 && ! f
->output_data
.x
->asked_for_visible
)
10909 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
10911 f
->output_data
.x
->asked_for_visible
= true;
10913 if (! EQ (Vx_no_window_manager
, Qt
))
10914 x_wm_set_window_state (f
, NormalState
);
10915 #ifdef USE_X_TOOLKIT
10916 if (FRAME_X_EMBEDDED_P (f
))
10917 xembed_set_info (f
, XEMBED_MAPPED
);
10920 /* This was XtPopup, but that did nothing for an iconified frame. */
10921 XtMapWidget (f
->output_data
.x
->widget
);
10923 #else /* not USE_X_TOOLKIT */
10925 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
10926 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
10928 if (FRAME_X_EMBEDDED_P (f
))
10929 xembed_set_info (f
, XEMBED_MAPPED
);
10931 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10932 #endif /* not USE_GTK */
10933 #endif /* not USE_X_TOOLKIT */
10936 XFlush (FRAME_X_DISPLAY (f
));
10938 /* Synchronize to ensure Emacs knows the frame is visible
10939 before we do anything else. We do this loop with input not blocked
10940 so that incoming events are handled. */
10943 /* This must be before UNBLOCK_INPUT
10944 since events that arrive in response to the actions above
10945 will set it when they are handled. */
10946 bool previously_visible
= f
->output_data
.x
->has_been_visible
;
10948 original_left
= f
->left_pos
;
10949 original_top
= f
->top_pos
;
10951 /* This must come after we set COUNT. */
10954 /* We unblock here so that arriving X events are processed. */
10956 /* Now move the window back to where it was "supposed to be".
10957 But don't do it if the gravity is negative.
10958 When the gravity is negative, this uses a position
10959 that is 3 pixels too low. Perhaps that's really the border width.
10961 Don't do this if the window has never been visible before,
10962 because the window manager may choose the position
10963 and we don't want to override it. */
10965 if (! FRAME_VISIBLE_P (f
)
10966 && ! FRAME_ICONIFIED_P (f
)
10967 && ! FRAME_X_EMBEDDED_P (f
)
10968 && f
->win_gravity
== NorthWestGravity
10969 && previously_visible
)
10973 unsigned int width
, height
, border
, depth
;
10977 /* On some window managers (such as FVWM) moving an existing
10978 window, even to the same place, causes the window manager
10979 to introduce an offset. This can cause the window to move
10980 to an unexpected location. Check the geometry (a little
10981 slow here) and then verify that the window is in the right
10982 place. If the window is not in the right place, move it
10983 there, and take the potential window manager hit. */
10984 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10985 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
10987 if (original_left
!= x
|| original_top
!= y
)
10988 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
10989 original_left
, original_top
);
10994 XSETFRAME (frame
, f
);
10996 /* Process X events until a MapNotify event has been seen. */
10997 while (!FRAME_VISIBLE_P (f
))
10999 /* Force processing of queued events. */
11002 /* If on another desktop, the deiconify/map may be ignored and the
11003 frame never becomes visible. XMonad does this.
11004 Prevent an endless loop. */
11005 if (FRAME_ICONIFIED_P (f
) && ++tries
> 100)
11008 /* This hack is still in use at least for Cygwin. See
11009 http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00351.html.
11011 Machines that do polling rather than SIGIO have been
11012 observed to go into a busy-wait here. So we'll fake an
11013 alarm signal to let the handler know that there's something
11014 to be read. We used to raise a real alarm, but it seems
11015 that the handler isn't always enabled here. This is
11017 if (input_polling_used ())
11019 /* It could be confusing if a real alarm arrives while
11020 processing the fake one. Turn it off and let the
11021 handler reset it. */
11022 int old_poll_suppress_count
= poll_suppress_count
;
11023 poll_suppress_count
= 1;
11024 poll_for_input_1 ();
11025 poll_suppress_count
= old_poll_suppress_count
;
11028 if (XPending (FRAME_X_DISPLAY (f
)))
11031 XNextEvent (FRAME_X_DISPLAY (f
), &xev
);
11032 x_dispatch_event (&xev
, FRAME_X_DISPLAY (f
));
11038 /* Change from mapped state to withdrawn state. */
11040 /* Make the frame visible (mapped and not iconified). */
11043 x_make_frame_invisible (struct frame
*f
)
11047 /* Use the frame's outermost window, not the one we normally draw on. */
11048 window
= FRAME_OUTER_WINDOW (f
);
11050 /* Don't keep the highlight on an invisible frame. */
11051 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11052 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11056 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
11057 that the current position of the window is user-specified, rather than
11058 program-specified, so that when the window is mapped again, it will be
11059 placed at the same location, without forcing the user to position it
11060 by hand again (they have already done that once for this window.) */
11061 x_wm_set_size_hint (f
, 0, true);
11064 if (FRAME_GTK_OUTER_WIDGET (f
))
11065 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
11068 if (FRAME_X_EMBEDDED_P (f
))
11069 xembed_set_info (f
, 0);
11074 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
11075 DefaultScreen (FRAME_X_DISPLAY (f
))))
11078 error ("Can't notify window manager of window withdrawal");
11082 /* We can't distinguish this from iconification
11083 just by the event that we get from the server.
11084 So we can't win using the usual strategy of letting
11085 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
11086 and synchronize with the server to make sure we agree. */
11087 SET_FRAME_VISIBLE (f
, 0);
11088 SET_FRAME_ICONIFIED (f
, false);
11095 /* Change window state from mapped to iconified. */
11098 x_iconify_frame (struct frame
*f
)
11100 #ifdef USE_X_TOOLKIT
11104 /* Don't keep the highlight on an invisible frame. */
11105 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
11106 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
11108 if (FRAME_ICONIFIED_P (f
))
11113 x_set_bitmap_icon (f
);
11115 #if defined (USE_GTK)
11116 if (FRAME_GTK_OUTER_WIDGET (f
))
11118 if (! FRAME_VISIBLE_P (f
))
11119 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
11121 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
11122 SET_FRAME_VISIBLE (f
, 0);
11123 SET_FRAME_ICONIFIED (f
, true);
11129 #ifdef USE_X_TOOLKIT
11131 if (! FRAME_VISIBLE_P (f
))
11133 if (! EQ (Vx_no_window_manager
, Qt
))
11134 x_wm_set_window_state (f
, IconicState
);
11135 /* This was XtPopup, but that did nothing for an iconified frame. */
11136 XtMapWidget (f
->output_data
.x
->widget
);
11137 /* The server won't give us any event to indicate
11138 that an invisible frame was changed to an icon,
11139 so we have to record it here. */
11140 SET_FRAME_VISIBLE (f
, 0);
11141 SET_FRAME_ICONIFIED (f
, true);
11146 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
11147 XtWindow (f
->output_data
.x
->widget
),
11148 DefaultScreen (FRAME_X_DISPLAY (f
)));
11152 error ("Can't notify window manager of iconification");
11154 SET_FRAME_ICONIFIED (f
, true);
11155 SET_FRAME_VISIBLE (f
, 0);
11158 XFlush (FRAME_X_DISPLAY (f
));
11160 #else /* not USE_X_TOOLKIT */
11162 /* Make sure the X server knows where the window should be positioned,
11163 in case the user deiconifies with the window manager. */
11164 if (! FRAME_VISIBLE_P (f
)
11165 && ! FRAME_ICONIFIED_P (f
)
11166 && ! FRAME_X_EMBEDDED_P (f
))
11167 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
11169 /* Since we don't know which revision of X we're running, we'll use both
11170 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
11172 /* X11R4: send a ClientMessage to the window manager using the
11173 WM_CHANGE_STATE type. */
11177 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
11178 msg
.xclient
.type
= ClientMessage
;
11179 msg
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
11180 msg
.xclient
.format
= 32;
11181 msg
.xclient
.data
.l
[0] = IconicState
;
11183 if (! XSendEvent (FRAME_X_DISPLAY (f
),
11184 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
11186 SubstructureRedirectMask
| SubstructureNotifyMask
,
11190 error ("Can't notify window manager of iconification");
11194 /* X11R3: set the initial_state field of the window manager hints to
11196 x_wm_set_window_state (f
, IconicState
);
11198 if (!FRAME_VISIBLE_P (f
))
11200 /* If the frame was withdrawn, before, we must map it. */
11201 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11204 SET_FRAME_ICONIFIED (f
, true);
11205 SET_FRAME_VISIBLE (f
, 0);
11207 XFlush (FRAME_X_DISPLAY (f
));
11209 #endif /* not USE_X_TOOLKIT */
11213 /* Free X resources of frame F. */
11216 x_free_frame_resources (struct frame
*f
)
11218 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
11219 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
11220 #ifdef USE_X_TOOLKIT
11222 struct scroll_bar
*b
;
11227 /* If a display connection is dead, don't try sending more
11228 commands to the X server. */
11229 if (dpyinfo
->display
)
11231 /* Always exit with visible pointer to avoid weird issue
11232 with Xfixes (Bug#17609). */
11233 if (f
->pointer_invisible
)
11234 FRAME_DISPLAY_INFO (f
)->toggle_visible_pointer (f
, 0);
11236 /* We must free faces before destroying windows because some
11237 font-driver (e.g. xft) access a window while finishing a
11239 free_frame_faces (f
);
11241 if (f
->output_data
.x
->icon_desc
)
11242 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
11244 #ifdef USE_X_TOOLKIT
11245 /* Explicitly destroy the scroll bars of the frame. Without
11246 this, we get "BadDrawable" errors from the toolkit later on,
11247 presumably from expose events generated for the disappearing
11248 toolkit scroll bars. */
11249 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
11251 b
= XSCROLL_BAR (bar
);
11252 x_scroll_bar_remove (b
);
11258 free_frame_xic (f
);
11261 x_free_cr_resources (f
);
11262 #ifdef USE_X_TOOLKIT
11263 if (f
->output_data
.x
->widget
)
11265 XtDestroyWidget (f
->output_data
.x
->widget
);
11266 f
->output_data
.x
->widget
= NULL
;
11268 /* Tooltips don't have widgets, only a simple X window, even if
11269 we are using a toolkit. */
11270 else if (FRAME_X_WINDOW (f
))
11271 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11273 free_frame_menubar (f
);
11275 if (f
->shell_position
)
11276 xfree (f
->shell_position
);
11277 #else /* !USE_X_TOOLKIT */
11280 xg_free_frame_widgets (f
);
11281 #endif /* USE_GTK */
11283 if (FRAME_X_WINDOW (f
))
11284 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11285 #endif /* !USE_X_TOOLKIT */
11287 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
11288 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
11289 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
11290 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
11291 unload_color (f
, f
->output_data
.x
->border_pixel
);
11292 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
11294 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
11295 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
11296 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
11297 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
11298 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
11299 /* Scrollbar shadow colors. */
11300 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
11301 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
11302 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
11303 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
11304 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
11305 if (f
->output_data
.x
->white_relief
.pixel
!= -1)
11306 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
11307 if (f
->output_data
.x
->black_relief
.pixel
!= -1)
11308 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
11312 /* Free extra GCs allocated by x_setup_relief_colors. */
11313 if (f
->output_data
.x
->white_relief
.gc
)
11315 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
11316 f
->output_data
.x
->white_relief
.gc
= 0;
11318 if (f
->output_data
.x
->black_relief
.gc
)
11320 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
11321 f
->output_data
.x
->black_relief
.gc
= 0;
11324 /* Free cursors. */
11325 if (f
->output_data
.x
->text_cursor
!= 0)
11326 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->text_cursor
);
11327 if (f
->output_data
.x
->nontext_cursor
!= 0)
11328 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->nontext_cursor
);
11329 if (f
->output_data
.x
->modeline_cursor
!= 0)
11330 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->modeline_cursor
);
11331 if (f
->output_data
.x
->hand_cursor
!= 0)
11332 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->hand_cursor
);
11333 if (f
->output_data
.x
->hourglass_cursor
!= 0)
11334 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->hourglass_cursor
);
11335 if (f
->output_data
.x
->horizontal_drag_cursor
!= 0)
11336 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->horizontal_drag_cursor
);
11337 if (f
->output_data
.x
->vertical_drag_cursor
!= 0)
11338 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->vertical_drag_cursor
);
11340 XFlush (FRAME_X_DISPLAY (f
));
11343 xfree (f
->output_data
.x
->saved_menu_event
);
11344 xfree (f
->output_data
.x
);
11345 f
->output_data
.x
= NULL
;
11347 if (f
== dpyinfo
->x_focus_frame
)
11348 dpyinfo
->x_focus_frame
= 0;
11349 if (f
== dpyinfo
->x_focus_event_frame
)
11350 dpyinfo
->x_focus_event_frame
= 0;
11351 if (f
== dpyinfo
->x_highlight_frame
)
11352 dpyinfo
->x_highlight_frame
= 0;
11353 if (f
== hlinfo
->mouse_face_mouse_frame
)
11354 reset_mouse_highlight (hlinfo
);
11360 /* Destroy the X window of frame F. */
11363 x_destroy_window (struct frame
*f
)
11365 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
11367 /* If a display connection is dead, don't try sending more
11368 commands to the X server. */
11369 if (dpyinfo
->display
!= 0)
11370 x_free_frame_resources (f
);
11372 dpyinfo
->reference_count
--;
11376 /* Setting window manager hints. */
11378 /* Set the normal size hints for the window manager, for frame F.
11379 FLAGS is the flags word to use--or 0 meaning preserve the flags
11380 that the window now has.
11381 If USER_POSITION, set the USPosition
11382 flag (this is useful when FLAGS is 0).
11383 The GTK version is in gtkutils.c. */
11387 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
11389 XSizeHints size_hints
;
11390 Window window
= FRAME_OUTER_WINDOW (f
);
11395 #ifdef USE_X_TOOLKIT
11396 if (f
->output_data
.x
->widget
)
11398 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
11403 /* Setting PMaxSize caused various problems. */
11404 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
11406 size_hints
.x
= f
->left_pos
;
11407 size_hints
.y
= f
->top_pos
;
11409 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
11410 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
11412 size_hints
.width_inc
= frame_resize_pixelwise
? 1 : FRAME_COLUMN_WIDTH (f
);
11413 size_hints
.height_inc
= frame_resize_pixelwise
? 1 : FRAME_LINE_HEIGHT (f
);
11415 size_hints
.max_width
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
11416 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
11417 size_hints
.max_height
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
11418 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
11420 /* Calculate the base and minimum sizes. */
11422 int base_width
, base_height
;
11424 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
11425 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
11427 /* The window manager uses the base width hints to calculate the
11428 current number of rows and columns in the frame while
11429 resizing; min_width and min_height aren't useful for this
11430 purpose, since they might not give the dimensions for a
11431 zero-row, zero-column frame. */
11433 size_hints
.flags
|= PBaseSize
;
11434 size_hints
.base_width
= base_width
;
11435 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
11436 size_hints
.min_width
= base_width
;
11437 size_hints
.min_height
= base_height
;
11440 /* If we don't need the old flags, we don't need the old hint at all. */
11443 size_hints
.flags
|= flags
;
11448 XSizeHints hints
; /* Sometimes I hate X Windows... */
11449 long supplied_return
;
11452 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
11456 size_hints
.flags
|= flags
;
11461 if (hints
.flags
& PSize
)
11462 size_hints
.flags
|= PSize
;
11463 if (hints
.flags
& PPosition
)
11464 size_hints
.flags
|= PPosition
;
11465 if (hints
.flags
& USPosition
)
11466 size_hints
.flags
|= USPosition
;
11467 if (hints
.flags
& USSize
)
11468 size_hints
.flags
|= USSize
;
11475 size_hints
.win_gravity
= f
->win_gravity
;
11476 size_hints
.flags
|= PWinGravity
;
11480 size_hints
.flags
&= ~ PPosition
;
11481 size_hints
.flags
|= USPosition
;
11483 #endif /* PWinGravity */
11485 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
11487 #endif /* not USE_GTK */
11489 /* Used for IconicState or NormalState */
11492 x_wm_set_window_state (struct frame
*f
, int state
)
11494 #ifdef USE_X_TOOLKIT
11497 XtSetArg (al
[0], XtNinitialState
, state
);
11498 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11499 #else /* not USE_X_TOOLKIT */
11500 Window window
= FRAME_X_WINDOW (f
);
11502 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
11503 f
->output_data
.x
->wm_hints
.initial_state
= state
;
11505 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11506 #endif /* not USE_X_TOOLKIT */
11510 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
11512 Pixmap icon_pixmap
, icon_mask
;
11514 #if !defined USE_X_TOOLKIT && !defined USE_GTK
11515 Window window
= FRAME_OUTER_WINDOW (f
);
11520 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
11521 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
11522 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
11523 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
11527 /* It seems there is no way to turn off use of an icon
11535 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
11539 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
11543 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
11544 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11545 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
11546 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
11549 #else /* not USE_X_TOOLKIT && not USE_GTK */
11551 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
11552 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11554 #endif /* not USE_X_TOOLKIT && not USE_GTK */
11558 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
11560 Window window
= FRAME_OUTER_WINDOW (f
);
11562 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
11563 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
11564 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
11566 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
11570 /***********************************************************************
11572 ***********************************************************************/
11576 /* Check that FONT is valid on frame F. It is if it can be found in F's
11580 x_check_font (struct frame
*f
, struct font
*font
)
11582 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
11583 if (font
->driver
->check
)
11584 eassert (font
->driver
->check (f
, font
) == 0);
11587 #endif /* GLYPH_DEBUG */
11590 /***********************************************************************
11592 ***********************************************************************/
11594 #ifdef USE_X_TOOLKIT
11595 static XrmOptionDescRec emacs_options
[] = {
11596 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
11597 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
11599 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
11600 XrmoptionSepArg
, NULL
},
11601 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
11603 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11604 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11605 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
11606 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
11607 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
11608 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
11609 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
11612 /* Whether atimer for Xt timeouts is activated or not. */
11614 static bool x_timeout_atimer_activated_flag
;
11616 #endif /* USE_X_TOOLKIT */
11618 static int x_initialized
;
11620 /* Test whether two display-name strings agree up to the dot that separates
11621 the screen number from the server number. */
11623 same_x_server (const char *name1
, const char *name2
)
11625 bool seen_colon
= false;
11626 Lisp_Object sysname
= Fsystem_name ();
11627 const char *system_name
= SSDATA (sysname
);
11628 ptrdiff_t system_name_length
= SBYTES (sysname
);
11629 ptrdiff_t length_until_period
= 0;
11631 while (system_name
[length_until_period
] != 0
11632 && system_name
[length_until_period
] != '.')
11633 length_until_period
++;
11635 /* Treat `unix' like an empty host name. */
11636 if (! strncmp (name1
, "unix:", 5))
11638 if (! strncmp (name2
, "unix:", 5))
11640 /* Treat this host's name like an empty host name. */
11641 if (! strncmp (name1
, system_name
, system_name_length
)
11642 && name1
[system_name_length
] == ':')
11643 name1
+= system_name_length
;
11644 if (! strncmp (name2
, system_name
, system_name_length
)
11645 && name2
[system_name_length
] == ':')
11646 name2
+= system_name_length
;
11647 /* Treat this host's domainless name like an empty host name. */
11648 if (! strncmp (name1
, system_name
, length_until_period
)
11649 && name1
[length_until_period
] == ':')
11650 name1
+= length_until_period
;
11651 if (! strncmp (name2
, system_name
, length_until_period
)
11652 && name2
[length_until_period
] == ':')
11653 name2
+= length_until_period
;
11655 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
11659 if (seen_colon
&& *name1
== '.')
11663 && (*name1
== '.' || *name1
== '\0')
11664 && (*name2
== '.' || *name2
== '\0'));
11667 /* Count number of set bits in mask and number of bits to shift to
11668 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
11671 get_bits_and_offset (unsigned long mask
, int *bits
, int *offset
)
11676 while (!(mask
& 1))
11692 /* Return true iff display DISPLAY is available for use.
11693 But don't permanently open it, just test its availability. */
11696 x_display_ok (const char *display
)
11698 /* XOpenDisplay fails if it gets a signal. Block SIGIO which may arrive. */
11699 unrequest_sigio ();
11700 Display
*dpy
= XOpenDisplay (display
);
11704 XCloseDisplay (dpy
);
11710 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
11711 const gchar
*msg
, gpointer user_data
)
11713 if (!strstr (msg
, "g_set_prgname"))
11714 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
11718 /* Create invisible cursor on X display referred by DPYINFO. */
11721 make_invisible_cursor (struct x_display_info
*dpyinfo
)
11723 Display
*dpy
= dpyinfo
->display
;
11724 static char const no_data
[] = { 0 };
11729 x_catch_errors (dpy
);
11730 pix
= XCreateBitmapFromData (dpy
, dpyinfo
->root_window
, no_data
, 1, 1);
11731 if (! x_had_errors_p (dpy
) && pix
!= None
)
11735 col
.red
= col
.green
= col
.blue
= 0;
11736 col
.flags
= DoRed
| DoGreen
| DoBlue
;
11737 pixc
= XCreatePixmapCursor (dpy
, pix
, pix
, &col
, &col
, 0, 0);
11738 if (! x_had_errors_p (dpy
) && pixc
!= None
)
11740 XFreePixmap (dpy
, pix
);
11743 x_uncatch_errors ();
11748 /* True if DPY supports Xfixes extension >= 4. */
11751 x_probe_xfixes_extension (Display
*dpy
)
11755 return XFixesQueryVersion (dpy
, &major
, &minor
) && major
>= 4;
11758 #endif /* HAVE_XFIXES */
11761 /* Toggle mouse pointer visibility on frame F by using Xfixes functions. */
11764 xfixes_toggle_visible_pointer (struct frame
*f
, bool invisible
)
11768 XFixesHideCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11770 XFixesShowCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
11771 f
->pointer_invisible
= invisible
;
11774 #endif /* HAVE_XFIXES */
11777 /* Toggle mouse pointer visibility on frame F by using invisible cursor. */
11780 x_toggle_visible_pointer (struct frame
*f
, bool invisible
)
11782 eassert (FRAME_DISPLAY_INFO (f
)->invisible_cursor
!= 0);
11784 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11785 FRAME_DISPLAY_INFO (f
)->invisible_cursor
);
11787 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
11788 f
->output_data
.x
->current_cursor
);
11789 f
->pointer_invisible
= invisible
;
11792 /* Setup pointer blanking, prefer Xfixes if available. */
11795 x_setup_pointer_blanking (struct x_display_info
*dpyinfo
)
11797 /* FIXME: the brave tester should set EMACS_XFIXES because we're suspecting
11798 X server bug, see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17609. */
11799 if (egetenv ("EMACS_XFIXES") && x_probe_xfixes_extension (dpyinfo
->display
))
11800 dpyinfo
->toggle_visible_pointer
= xfixes_toggle_visible_pointer
;
11803 dpyinfo
->toggle_visible_pointer
= x_toggle_visible_pointer
;
11804 dpyinfo
->invisible_cursor
= make_invisible_cursor (dpyinfo
);
11808 /* Current X display connection identifier. Incremented for each next
11809 connection established. */
11810 static unsigned x_display_id
;
11812 /* Open a connection to X display DISPLAY_NAME, and return
11813 the structure that describes the open display.
11814 If we cannot contact the display, return null. */
11816 struct x_display_info
*
11817 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
11820 struct terminal
*terminal
;
11821 struct x_display_info
*dpyinfo
;
11824 xcb_connection_t
*xcb_conn
;
11829 if (!x_initialized
)
11835 if (! x_display_ok (SSDATA (display_name
)))
11836 error ("Display %s can't be opened", SSDATA (display_name
));
11840 #define NUM_ARGV 10
11842 char *argv
[NUM_ARGV
];
11843 char **argv2
= argv
;
11846 if (x_initialized
++ > 1)
11848 xg_display_open (SSDATA (display_name
), &dpy
);
11852 static char display_opt
[] = "--display";
11853 static char name_opt
[] = "--name";
11855 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
11859 argv
[argc
++] = initial_argv
[0];
11861 if (! NILP (display_name
))
11863 argv
[argc
++] = display_opt
;
11864 argv
[argc
++] = SSDATA (display_name
);
11867 argv
[argc
++] = name_opt
;
11868 argv
[argc
++] = resource_name
;
11870 XSetLocaleModifiers ("");
11872 /* Work around GLib bug that outputs a faulty warning. See
11873 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
11874 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
11875 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
11877 /* NULL window -> events for all windows go to our function.
11878 Call before gtk_init so Gtk+ event filters comes after our. */
11879 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
11881 /* gtk_init does set_locale. Fix locale before and after. */
11883 unrequest_sigio (); /* See comment in x_display_ok. */
11884 gtk_init (&argc
, &argv2
);
11888 g_log_remove_handler ("GLib", id
);
11892 dpy
= DEFAULT_GDK_DISPLAY ();
11894 #if ! GTK_CHECK_VERSION (2, 90, 0)
11895 /* Load our own gtkrc if it exists. */
11897 const char *file
= "~/.emacs.d/gtkrc";
11898 Lisp_Object s
, abs_file
;
11900 s
= build_string (file
);
11901 abs_file
= Fexpand_file_name (s
, Qnil
);
11903 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
11904 gtk_rc_parse (SSDATA (abs_file
));
11908 XSetErrorHandler (x_error_handler
);
11909 XSetIOErrorHandler (x_io_error_quitter
);
11912 #else /* not USE_GTK */
11913 #ifdef USE_X_TOOLKIT
11914 /* weiner@footloose.sps.mot.com reports that this causes
11916 X protocol error: BadAtom (invalid Atom parameter)
11917 on protocol request 18skiloaf.
11918 So let's not use it until R6. */
11919 #ifdef HAVE_X11XTR6
11920 XtSetLanguageProc (NULL
, NULL
, NULL
);
11931 argv
[argc
++] = "-xrm";
11932 argv
[argc
++] = xrm_option
;
11934 turn_on_atimers (false);
11935 unrequest_sigio (); /* See comment in x_display_ok. */
11936 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
11937 resource_name
, EMACS_CLASS
,
11938 emacs_options
, XtNumber (emacs_options
),
11941 turn_on_atimers (true);
11943 #ifdef HAVE_X11XTR6
11944 /* I think this is to compensate for XtSetLanguageProc. */
11949 #else /* not USE_X_TOOLKIT */
11950 XSetLocaleModifiers ("");
11951 unrequest_sigio (); // See comment in x_display_ok.
11952 dpy
= XOpenDisplay (SSDATA (display_name
));
11954 #endif /* not USE_X_TOOLKIT */
11955 #endif /* not USE_GTK*/
11957 /* Detect failure. */
11965 xcb_conn
= XGetXCBConnection (dpy
);
11969 xg_display_close (dpy
);
11971 #ifdef USE_X_TOOLKIT
11972 XtCloseDisplay (dpy
);
11974 XCloseDisplay (dpy
);
11976 #endif /* ! USE_GTK */
11983 /* We have definitely succeeded. Record the new connection. */
11985 dpyinfo
= xzalloc (sizeof *dpyinfo
);
11986 terminal
= x_create_terminal (dpyinfo
);
11989 struct x_display_info
*share
;
11991 for (share
= x_display_list
; share
; share
= share
->next
)
11992 if (same_x_server (SSDATA (XCAR (share
->name_list_element
)),
11993 SSDATA (display_name
)))
11996 terminal
->kboard
= share
->terminal
->kboard
;
11999 terminal
->kboard
= allocate_kboard (Qx
);
12001 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
12003 char *vendor
= ServerVendor (dpy
);
12005 /* Temporarily hide the partially initialized terminal. */
12006 terminal_list
= terminal
->next_terminal
;
12008 kset_system_key_alist
12010 call1 (Qvendor_specific_keysyms
,
12011 vendor
? build_string (vendor
) : empty_unibyte_string
));
12013 terminal
->next_terminal
= terminal_list
;
12014 terminal_list
= terminal
;
12017 /* Don't let the initial kboard remain current longer than necessary.
12018 That would cause problems if a file loaded on startup tries to
12019 prompt in the mini-buffer. */
12020 if (current_kboard
== initial_kboard
)
12021 current_kboard
= terminal
->kboard
;
12023 terminal
->kboard
->reference_count
++;
12026 /* Put this display on the chain. */
12027 dpyinfo
->next
= x_display_list
;
12028 x_display_list
= dpyinfo
;
12030 dpyinfo
->name_list_element
= Fcons (display_name
, Qnil
);
12031 dpyinfo
->display
= dpy
;
12032 dpyinfo
->connection
= ConnectionNumber (dpyinfo
->display
);
12034 dpyinfo
->xcb_connection
= xcb_conn
;
12037 /* http://lists.gnu.org/archive/html/emacs-devel/2015-11/msg00194.html */
12038 dpyinfo
->smallest_font_height
= 1;
12039 dpyinfo
->smallest_char_width
= 1;
12041 /* Set the name of the terminal. */
12042 terminal
->name
= xlispstrdup (display_name
);
12045 XSetAfterFunction (x_current_display
, x_trace_wire
);
12048 Lisp_Object system_name
= Fsystem_name ();
12050 if (INT_ADD_WRAPV (SBYTES (Vinvocation_name
), SBYTES (system_name
) + 2,
12052 memory_full (SIZE_MAX
);
12053 dpyinfo
->x_id
= ++x_display_id
;
12054 dpyinfo
->x_id_name
= xmalloc (nbytes
);
12055 char *nametail
= lispstpcpy (dpyinfo
->x_id_name
, Vinvocation_name
);
12057 lispstpcpy (nametail
, system_name
);
12059 /* Figure out which modifier bits mean what. */
12060 x_find_modifier_meanings (dpyinfo
);
12062 /* Get the scroll bar cursor. */
12064 /* We must create a GTK cursor, it is required for GTK widgets. */
12065 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
12066 #endif /* USE_GTK */
12068 dpyinfo
->vertical_scroll_bar_cursor
12069 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
12071 dpyinfo
->horizontal_scroll_bar_cursor
12072 = XCreateFontCursor (dpyinfo
->display
, XC_sb_h_double_arrow
);
12074 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
12075 resource_name
, EMACS_CLASS
);
12076 #ifdef HAVE_XRMSETDATABASE
12077 XrmSetDatabase (dpyinfo
->display
, xrdb
);
12079 dpyinfo
->display
->db
= xrdb
;
12081 /* Put the rdb where we can find it in a way that works on
12083 dpyinfo
->xrdb
= xrdb
;
12085 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
12086 DefaultScreen (dpyinfo
->display
));
12087 select_visual (dpyinfo
);
12088 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
12089 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
12090 dpyinfo
->icon_bitmap_id
= -1;
12091 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
12093 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
12095 /* See if we can construct pixel values from RGB values. */
12096 if (dpyinfo
->visual
->class == TrueColor
)
12098 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
12099 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
12100 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
12101 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
12102 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
12103 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
12106 /* See if a private colormap is requested. */
12107 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
12109 if (dpyinfo
->visual
->class == PseudoColor
)
12111 AUTO_STRING (privateColormap
, "privateColormap");
12112 AUTO_STRING (PrivateColormap
, "PrivateColormap");
12114 = display_x_get_resource (dpyinfo
, privateColormap
,
12115 PrivateColormap
, Qnil
, Qnil
);
12116 if (STRINGP (value
)
12117 && (!strcmp (SSDATA (value
), "true")
12118 || !strcmp (SSDATA (value
), "on")))
12119 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
12123 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
12124 dpyinfo
->visual
, AllocNone
);
12128 /* If we are using Xft, the following precautions should be made:
12130 1. Make sure that the Xrender extension is added before the Xft one.
12131 Otherwise, the close-display hook set by Xft is called after the one
12132 for Xrender, and the former tries to re-add the latter. This results
12133 in inconsistency of internal states and leads to X protocol error when
12134 one reconnects to the same X server (Bug#1696).
12136 2. Check dpi value in X resources. It is better we use it as well,
12137 since Xft will use it, as will all Gnome applications. If our real DPI
12138 is smaller or larger than the one Xft uses, our font will look smaller
12139 or larger than other for other applications, even if it is the same
12140 font name (monospace-10 for example). */
12142 int event_base
, error_base
;
12146 XRenderQueryExtension (dpyinfo
->display
, &event_base
, &error_base
);
12148 v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
12149 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
12150 dpyinfo
->resy
= dpyinfo
->resx
= d
;
12154 if (dpyinfo
->resy
< 1)
12156 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
12157 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
12158 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
12159 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
12160 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
12161 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
12162 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
12163 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
12164 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
12168 static const struct
12173 #define ATOM_REFS_INIT(string, member) \
12174 { string, offsetof (struct x_display_info, member) },
12175 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
12176 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
12177 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
12178 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
12179 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
12180 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
12181 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
12182 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
12183 ATOM_REFS_INIT ("Editres", Xatom_editres
)
12184 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
12185 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
12186 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
12187 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
12188 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
12189 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
12190 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
12191 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
12192 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
12193 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
12194 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
12195 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
12196 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
12197 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
12198 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
12199 /* For properties of font. */
12200 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
12201 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
12202 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
12203 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
12204 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
12205 /* Ghostscript support. */
12206 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
12207 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
12208 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
12209 ATOM_REFS_INIT ("HORIZONTAL_SCROLLBAR", Xatom_Horizontal_Scrollbar
)
12210 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
12212 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
12213 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
12214 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
12215 Xatom_net_wm_state_maximized_horz
)
12216 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
12217 Xatom_net_wm_state_maximized_vert
)
12218 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
12219 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
12220 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
12221 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
12222 Xatom_net_window_type_tooltip
)
12223 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
12224 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
12225 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
12226 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
12227 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
12228 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
12229 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
12230 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
12231 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
12232 /* Session management */
12233 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
12234 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
12235 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
12239 enum { atom_count
= ARRAYELTS (atom_refs
) };
12240 /* 1 for _XSETTINGS_SN. */
12241 enum { total_atom_count
= 1 + atom_count
};
12242 Atom atoms_return
[total_atom_count
];
12243 char *atom_names
[total_atom_count
];
12244 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
12245 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
12246 + INT_STRLEN_BOUND (int)];
12248 for (i
= 0; i
< atom_count
; i
++)
12249 atom_names
[i
] = (char *) atom_refs
[i
].name
;
12251 /* Build _XSETTINGS_SN atom name. */
12252 sprintf (xsettings_atom_name
, xsettings_fmt
,
12253 XScreenNumberOfScreen (dpyinfo
->screen
));
12254 atom_names
[i
] = xsettings_atom_name
;
12256 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
12257 False
, atoms_return
);
12259 for (i
= 0; i
< atom_count
; i
++)
12260 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
12262 /* Manually copy last atom. */
12263 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
12266 dpyinfo
->x_dnd_atoms_size
= 8;
12267 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
12268 * dpyinfo
->x_dnd_atoms_size
);
12270 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
12271 gray_bits
, gray_width
, gray_height
,
12274 x_setup_pointer_blanking (dpyinfo
);
12277 xim_initialize (dpyinfo
, resource_name
);
12280 xsettings_initialize (dpyinfo
);
12282 /* This is only needed for distinguishing keyboard and process input. */
12283 if (dpyinfo
->connection
!= 0)
12284 add_keyboard_wait_descriptor (dpyinfo
->connection
);
12287 fcntl (dpyinfo
->connection
, F_SETOWN
, getpid ());
12288 #endif /* ! defined (F_SETOWN) */
12290 if (interrupt_input
)
12291 init_sigio (dpyinfo
->connection
);
12295 XrmValue d
, fr
, to
;
12298 dpy
= dpyinfo
->display
;
12299 d
.addr
= (XPointer
)&dpy
;
12300 d
.size
= sizeof (Display
*);
12301 fr
.addr
= XtDefaultFont
;
12302 fr
.size
= sizeof (XtDefaultFont
);
12303 to
.size
= sizeof (Font
*);
12304 to
.addr
= (XPointer
)&font
;
12305 x_catch_errors (dpy
);
12306 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
12308 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
12309 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
12310 /* Do not free XFontStruct returned by the above call to XQueryFont.
12311 This leads to X protocol errors at XtCloseDisplay (Bug#18403). */
12312 x_uncatch_errors ();
12316 /* See if we should run in synchronous mode. This is useful
12317 for debugging X code. */
12319 AUTO_STRING (synchronous
, "synchronous");
12320 AUTO_STRING (Synchronous
, "Synchronous");
12321 Lisp_Object value
= display_x_get_resource (dpyinfo
, synchronous
,
12322 Synchronous
, Qnil
, Qnil
);
12323 if (STRINGP (value
)
12324 && (!strcmp (SSDATA (value
), "true")
12325 || !strcmp (SSDATA (value
), "on")))
12326 XSynchronize (dpyinfo
->display
, True
);
12330 AUTO_STRING (useXIM
, "useXIM");
12331 AUTO_STRING (UseXIM
, "UseXIM");
12332 Lisp_Object value
= display_x_get_resource (dpyinfo
, useXIM
, UseXIM
,
12335 if (STRINGP (value
)
12336 && (!strcmp (SSDATA (value
), "false")
12337 || !strcmp (SSDATA (value
), "off")))
12340 if (STRINGP (value
)
12341 && (!strcmp (SSDATA (value
), "true")
12342 || !strcmp (SSDATA (value
), "on")))
12348 /* Only do this for the very first display in the Emacs session.
12349 Ignore X session management when Emacs was first started on a
12350 tty or started as a daemon. */
12351 if (terminal
->id
== 1 && ! IS_DAEMON
)
12352 x_session_initialize (dpyinfo
);
12356 x_extension_initialize (dpyinfo
);
12364 /* Get rid of display DPYINFO, deleting all frames on it,
12365 and without sending any more commands to the X server. */
12368 x_delete_display (struct x_display_info
*dpyinfo
)
12370 struct terminal
*t
;
12371 struct color_name_cache_entry
*color_entry
, *next_color_entry
;
12373 /* Close all frames and delete the generic struct terminal for this
12375 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
12376 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
12379 /* Close X session management when we close its display. */
12380 if (t
->id
== 1 && x_session_have_connection ())
12381 x_session_close ();
12383 delete_terminal (t
);
12387 if (next_noop_dpyinfo
== dpyinfo
)
12388 next_noop_dpyinfo
= dpyinfo
->next
;
12390 if (x_display_list
== dpyinfo
)
12391 x_display_list
= dpyinfo
->next
;
12394 struct x_display_info
*tail
;
12396 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
12397 if (tail
->next
== dpyinfo
)
12398 tail
->next
= tail
->next
->next
;
12401 for (color_entry
= dpyinfo
->color_names
;
12403 color_entry
= next_color_entry
)
12405 next_color_entry
= color_entry
->next
;
12406 xfree (color_entry
->name
);
12407 xfree (color_entry
);
12410 xfree (dpyinfo
->x_id_name
);
12411 xfree (dpyinfo
->x_dnd_atoms
);
12412 xfree (dpyinfo
->color_cells
);
12416 #ifdef USE_X_TOOLKIT
12418 /* Atimer callback function for TIMER. Called every 0.1s to process
12419 Xt timeouts, if needed. We must avoid calling XtAppPending as
12420 much as possible because that function does an implicit XFlush
12421 that slows us down. */
12424 x_process_timeouts (struct atimer
*timer
)
12427 x_timeout_atimer_activated_flag
= false;
12428 if (toolkit_scroll_bar_interaction
|| popup_activated ())
12430 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
12431 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
12432 /* Reactivate the atimer for next time. */
12433 x_activate_timeout_atimer ();
12438 /* Install an asynchronous timer that processes Xt timeout events
12439 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
12440 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
12441 function whenever these variables are set. This is necessary
12442 because some widget sets use timeouts internally, for example the
12443 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
12444 processed, these widgets don't behave normally. */
12447 x_activate_timeout_atimer (void)
12450 if (!x_timeout_atimer_activated_flag
)
12452 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
12453 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
12454 x_timeout_atimer_activated_flag
= true;
12459 #endif /* USE_X_TOOLKIT */
12462 /* Set up use of X before we make the first connection. */
12464 static struct redisplay_interface x_redisplay_interface
=
12466 x_frame_parm_handlers
,
12470 x_clear_end_of_line
,
12472 x_after_update_window_line
,
12473 x_update_window_begin
,
12474 x_update_window_end
,
12476 x_clear_window_mouse_face
,
12477 x_get_glyph_overhangs
,
12478 x_fix_overlapping_area
,
12479 x_draw_fringe_bitmap
,
12481 x_cr_define_fringe_bitmap
,
12482 x_cr_destroy_fringe_bitmap
,
12484 0, /* define_fringe_bitmap */
12485 0, /* destroy_fringe_bitmap */
12487 x_compute_glyph_string_overhangs
,
12488 x_draw_glyph_string
,
12489 x_define_frame_cursor
,
12490 x_clear_frame_area
,
12491 x_draw_window_cursor
,
12492 x_draw_vertical_window_border
,
12493 x_draw_window_divider
,
12494 x_shift_glyphs_for_insert
, /* Never called; see comment in function. */
12500 /* This function is called when the last frame on a display is deleted. */
12502 x_delete_terminal (struct terminal
*terminal
)
12504 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
12506 /* Protect against recursive calls. delete_frame in
12507 delete_terminal calls us back when it deletes our last frame. */
12508 if (!terminal
->name
)
12513 /* We must close our connection to the XIM server before closing the
12516 xim_close_dpy (dpyinfo
);
12519 /* Normally, the display is available... */
12520 if (dpyinfo
->display
)
12522 x_destroy_all_bitmaps (dpyinfo
);
12523 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
12525 /* Whether or not XCloseDisplay destroys the associated resource
12526 database depends on the version of libX11. To avoid both
12527 crash and memory leak, we dissociate the database from the
12528 display and then destroy dpyinfo->xrdb ourselves.
12530 Unfortunately, the above strategy does not work in some
12531 situations due to a bug in newer versions of libX11: because
12532 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
12533 dpy->db is NULL, XCloseDisplay destroys the associated
12534 database whereas it has not been created by XGetDefault
12535 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
12536 don't destroy the database here in order to avoid the crash
12537 in the above situations for now, though that may cause memory
12538 leaks in other situations. */
12540 #ifdef HAVE_XRMSETDATABASE
12541 XrmSetDatabase (dpyinfo
->display
, NULL
);
12543 dpyinfo
->display
->db
= NULL
;
12545 /* We used to call XrmDestroyDatabase from x_delete_display, but
12546 some older versions of libX11 crash if we call it after
12547 closing all the displays. */
12548 XrmDestroyDatabase (dpyinfo
->xrdb
);
12552 xg_display_close (dpyinfo
->display
);
12554 #ifdef USE_X_TOOLKIT
12555 XtCloseDisplay (dpyinfo
->display
);
12557 XCloseDisplay (dpyinfo
->display
);
12559 #endif /* ! USE_GTK */
12560 /* Do not close the connection here because it's already closed
12561 by X(t)CloseDisplay (Bug#18403). */
12562 dpyinfo
->display
= NULL
;
12565 /* ...but if called from x_connection_closed, the display may already
12566 be closed and dpyinfo->display was set to 0 to indicate that. Since
12567 X server is most likely gone, explicit close is the only reliable
12568 way to continue and avoid Bug#19147. */
12569 else if (dpyinfo
->connection
>= 0)
12570 emacs_close (dpyinfo
->connection
);
12572 /* No more input on this descriptor. */
12573 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
12574 /* Mark as dead. */
12575 dpyinfo
->connection
= -1;
12577 x_delete_display (dpyinfo
);
12581 /* Create a struct terminal, initialize it with the X11 specific
12582 functions and make DISPLAY->TERMINAL point to it. */
12584 static struct terminal
*
12585 x_create_terminal (struct x_display_info
*dpyinfo
)
12587 struct terminal
*terminal
;
12589 terminal
= create_terminal (output_x_window
, &x_redisplay_interface
);
12591 terminal
->display_info
.x
= dpyinfo
;
12592 dpyinfo
->terminal
= terminal
;
12594 /* kboard is initialized in x_term_init. */
12596 terminal
->clear_frame_hook
= x_clear_frame
;
12597 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
12598 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
12599 terminal
->ring_bell_hook
= XTring_bell
;
12600 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
12601 terminal
->update_begin_hook
= x_update_begin
;
12602 terminal
->update_end_hook
= x_update_end
;
12603 terminal
->read_socket_hook
= XTread_socket
;
12604 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
12605 terminal
->mouse_position_hook
= XTmouse_position
;
12606 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
12607 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
12608 terminal
->fullscreen_hook
= XTfullscreen_hook
;
12609 terminal
->menu_show_hook
= x_menu_show
;
12610 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
12611 terminal
->popup_dialog_hook
= xw_popup_dialog
;
12613 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
12614 terminal
->set_horizontal_scroll_bar_hook
= XTset_horizontal_scroll_bar
;
12615 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
12616 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
12617 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
12618 terminal
->delete_frame_hook
= x_destroy_window
;
12619 terminal
->delete_terminal_hook
= x_delete_terminal
;
12620 /* Other hooks are NULL by default. */
12626 x_initialize (void)
12631 any_help_event_p
= false;
12632 ignore_next_mouse_click_timeout
= 0;
12635 current_count
= -1;
12638 /* Try to use interrupt input; if we can't, then start polling. */
12639 Fset_input_interrupt_mode (Qt
);
12641 #ifdef USE_X_TOOLKIT
12642 XtToolkitInitialize ();
12644 Xt_app_con
= XtCreateApplicationContext ();
12646 /* Register a converter from strings to pixels, which uses
12647 Emacs' color allocation infrastructure. */
12648 XtAppSetTypeConverter (Xt_app_con
,
12649 XtRString
, XtRPixel
, cvt_string_to_pixel
,
12650 cvt_string_to_pixel_args
,
12651 XtNumber (cvt_string_to_pixel_args
),
12652 XtCacheByDisplay
, cvt_pixel_dtor
);
12654 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
12657 #ifdef USE_TOOLKIT_SCROLL_BARS
12659 xaw3d_arrow_scroll
= False
;
12660 xaw3d_pick_top
= True
;
12665 x_cr_init_fringe (&x_redisplay_interface
);
12668 /* Note that there is no real way portable across R3/R4 to get the
12669 original error handler. */
12670 XSetErrorHandler (x_error_handler
);
12671 XSetIOErrorHandler (x_io_error_quitter
);
12678 /* Emacs can handle only core input events, so make sure
12679 Gtk doesn't use Xinput or Xinput2 extensions. */
12680 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
12685 syms_of_xterm (void)
12687 x_error_message
= NULL
;
12689 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
12690 DEFSYM (Qlatin_1
, "latin-1");
12693 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
12694 staticpro (&xg_default_icon_file
);
12696 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
12699 DEFVAR_BOOL ("x-use-underline-position-properties",
12700 x_use_underline_position_properties
,
12701 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
12702 A value of nil means ignore them. If you encounter fonts with bogus
12703 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
12704 to 4.1, set this to nil. You can also use `underline-minimum-offset'
12705 to override the font's UNDERLINE_POSITION for small font display
12707 x_use_underline_position_properties
= true;
12709 DEFVAR_BOOL ("x-underline-at-descent-line",
12710 x_underline_at_descent_line
,
12711 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
12712 A value of nil means to draw the underline according to the value of the
12713 variable `x-use-underline-position-properties', which is usually at the
12714 baseline level. The default value is nil. */);
12715 x_underline_at_descent_line
= false;
12717 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
12718 x_mouse_click_focus_ignore_position
,
12719 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
12720 This variable is only used when the window manager requires that you
12721 click on a frame to select it (give it focus). In that case, a value
12722 of nil, means that the selected window and cursor position changes to
12723 reflect the mouse click position, while a non-nil value means that the
12724 selected window or cursor position is preserved. */);
12725 x_mouse_click_focus_ignore_position
= false;
12727 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
12728 doc
: /* Which toolkit scroll bars Emacs uses, if any.
12729 A value of nil means Emacs doesn't use toolkit scroll bars.
12730 With the X Window system, the value is a symbol describing the
12731 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
12732 With MS Windows or Nextstep, the value is t. */);
12733 #ifdef USE_TOOLKIT_SCROLL_BARS
12735 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
12736 #elif defined HAVE_XAW3D
12737 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
12739 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
12741 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
12744 Vx_toolkit_scroll_bars
= Qnil
;
12747 DEFSYM (Qmodifier_value
, "modifier-value");
12748 DEFSYM (Qalt
, "alt");
12749 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
12750 DEFSYM (Qhyper
, "hyper");
12751 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
12752 DEFSYM (Qmeta
, "meta");
12753 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
12754 DEFSYM (Qsuper
, "super");
12755 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
12757 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
12758 doc
: /* Which keys Emacs uses for the alt modifier.
12759 This should be one of the symbols `alt', `hyper', `meta', `super'.
12760 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
12761 is nil, which is the same as `alt'. */);
12762 Vx_alt_keysym
= Qnil
;
12764 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
12765 doc
: /* Which keys Emacs uses for the hyper modifier.
12766 This should be one of the symbols `alt', `hyper', `meta', `super'.
12767 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
12768 default is nil, which is the same as `hyper'. */);
12769 Vx_hyper_keysym
= Qnil
;
12771 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
12772 doc
: /* Which keys Emacs uses for the meta modifier.
12773 This should be one of the symbols `alt', `hyper', `meta', `super'.
12774 For example, `meta' means use the Meta_L and Meta_R keysyms. The
12775 default is nil, which is the same as `meta'. */);
12776 Vx_meta_keysym
= Qnil
;
12778 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
12779 doc
: /* Which keys Emacs uses for the super modifier.
12780 This should be one of the symbols `alt', `hyper', `meta', `super'.
12781 For example, `super' means use the Super_L and Super_R keysyms. The
12782 default is nil, which is the same as `super'. */);
12783 Vx_super_keysym
= Qnil
;
12785 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
12786 doc
: /* Hash table of character codes indexed by X keysym codes. */);
12787 Vx_keysym_table
= make_hash_table (hashtest_eql
, make_number (900),
12788 make_float (DEFAULT_REHASH_SIZE
),
12789 make_float (DEFAULT_REHASH_THRESHOLD
),
12792 DEFVAR_BOOL ("x-frame-normalize-before-maximize",
12793 x_frame_normalize_before_maximize
,
12794 doc
: /* Non-nil means normalize frame before maximizing.
12795 If this variable is t, Emacs first asks the window manager to give the
12796 frame its normal size, and only then the final state, whenever changing
12797 from a full-height, full-width or full-both state to the maximized one
12798 or when changing from the maximized to the full-height or full-width
12801 Set this variable only if your window manager cannot handle the
12802 transition between the various maximization states. */);
12803 x_frame_normalize_before_maximize
= false;