1 /* X Communication module for terminals which understand the X protocol.
3 Copyright (C) 1989, 1993-2015 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. */
27 #include "blockinput.h"
28 #include "syssignal.h"
30 /* This may include sys/types.h, and that somehow loses
31 if this is not done before the other system files. */
33 #include <X11/cursorfont.h>
35 /* If we have Xfixes extension, use it for pointer blanking. */
37 #include <X11/extensions/Xfixes.h>
40 /* Using Xft implies that XRender is available. */
42 #include <X11/extensions/Xrender.h>
45 /* Load sys/types.h if not already loaded.
46 In some systems loading it twice is suicidal. */
48 #include <sys/types.h>
51 #include <sys/ioctl.h>
58 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
59 /* #include <sys/param.h> */
62 #include "character.h"
65 #include "dispextern.h"
70 #include "termhooks.h"
73 #include "emacs-icon.h"
78 #include "intervals.h"
83 #include "xsettings.h"
85 #include "sysselect.h"
89 #include <X11/Shell.h>
97 #include <X11/Xproto.h>
101 #if defined (USE_LUCID) || defined (USE_MOTIF)
102 #include "../lwlib/xlwmenu.h"
106 #if !defined (NO_EDITRES)
108 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
109 #endif /* not NO_EDITRES */
111 /* Include toolkit specific headers for the scroll bar widget. */
113 #ifdef USE_TOOLKIT_SCROLL_BARS
114 #if defined USE_MOTIF
115 #include <Xm/Xm.h> /* For LESSTIF_VERSION */
116 #include <Xm/ScrollBar.h>
117 #else /* !USE_MOTIF i.e. use Xaw */
120 #include <X11/Xaw3d/Simple.h>
121 #include <X11/Xaw3d/Scrollbar.h>
122 #include <X11/Xaw3d/ThreeD.h>
123 #else /* !HAVE_XAW3D */
124 #include <X11/Xaw/Simple.h>
125 #include <X11/Xaw/Scrollbar.h>
126 #endif /* !HAVE_XAW3D */
128 #define XtNpickTop "pickTop"
129 #endif /* !XtNpickTop */
130 #endif /* !USE_MOTIF */
131 #endif /* USE_TOOLKIT_SCROLL_BARS */
133 #endif /* USE_X_TOOLKIT */
137 #ifndef XtNinitialState
138 #define XtNinitialState "initialState"
142 #include "bitmaps/gray.xbm"
145 #include <X11/XKBlib.h>
148 /* Default to using XIM if available. */
152 bool use_xim
= false; /* configure --without-xim */
155 /* Non-zero means that a HELP_EVENT has been generated since Emacs
158 static bool any_help_event_p
;
160 /* This is a chain of structures for all the X displays currently in
163 struct x_display_info
*x_display_list
;
167 /* The application context for Xt use. */
168 XtAppContext Xt_app_con
;
169 static String Xt_default_resources
[] = {0};
171 /* Non-zero means user is interacting with a toolkit scroll bar. */
172 static bool toolkit_scroll_bar_interaction
;
174 #endif /* USE_X_TOOLKIT */
176 /* Non-zero timeout value means ignore next mouse click if it arrives
177 before that timeout elapses (i.e. as part of the same sequence of
178 events resulting from clicking on a frame to select it). */
180 static Time ignore_next_mouse_click_timeout
;
182 /* Used locally within XTread_socket. */
184 static int x_noop_count
;
186 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
188 static Lisp_Object Qvendor_specific_keysyms
;
189 static Lisp_Object Qlatin_1
;
192 /* The name of the Emacs icon file. */
193 static Lisp_Object xg_default_icon_file
;
195 /* Used in gtkutil.c. */
196 Lisp_Object Qx_gtk_map_stock
;
199 /* Some functions take this as char *, not const char *. */
200 static char emacs_class
[] = EMACS_CLASS
;
204 XEMBED_MAPPED
= 1 << 0
209 XEMBED_EMBEDDED_NOTIFY
= 0,
210 XEMBED_WINDOW_ACTIVATE
= 1,
211 XEMBED_WINDOW_DEACTIVATE
= 2,
212 XEMBED_REQUEST_FOCUS
= 3,
214 XEMBED_FOCUS_OUT
= 5,
215 XEMBED_FOCUS_NEXT
= 6,
216 XEMBED_FOCUS_PREV
= 7,
218 XEMBED_MODALITY_ON
= 10,
219 XEMBED_MODALITY_OFF
= 11,
220 XEMBED_REGISTER_ACCELERATOR
= 12,
221 XEMBED_UNREGISTER_ACCELERATOR
= 13,
222 XEMBED_ACTIVATE_ACCELERATOR
= 14
225 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
226 static void x_set_window_size_1 (struct frame
*, bool, int, int, bool);
227 static void x_raise_frame (struct frame
*);
228 static void x_lower_frame (struct frame
*);
229 static const XColor
*x_color_cells (Display
*, int *);
230 static int x_io_error_quitter (Display
*);
231 static struct terminal
*x_create_terminal (struct x_display_info
*);
232 static void x_update_end (struct frame
*);
233 static void XTframe_up_to_date (struct frame
*);
234 static void x_clear_frame (struct frame
*);
235 static _Noreturn
void x_ins_del_lines (struct frame
*, int, int);
236 static void frame_highlight (struct frame
*);
237 static void frame_unhighlight (struct frame
*);
238 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
239 static void x_focus_changed (int, int, struct x_display_info
*,
240 struct frame
*, struct input_event
*);
241 static void XTframe_rehighlight (struct frame
*);
242 static void x_frame_rehighlight (struct x_display_info
*);
243 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
244 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
245 enum text_cursor_kinds
);
247 static void x_clip_to_row (struct window
*, struct glyph_row
*,
248 enum glyph_row_area
, GC
);
249 static void x_flush (struct frame
*f
);
250 static void x_update_begin (struct frame
*);
251 static void x_update_window_begin (struct window
*);
252 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
, int);
253 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
254 enum scroll_bar_part
*,
255 Lisp_Object
*, Lisp_Object
*,
257 static void x_horizontal_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
258 enum scroll_bar_part
*,
259 Lisp_Object
*, Lisp_Object
*,
261 static bool x_handle_net_wm_state (struct frame
*, const XPropertyEvent
*);
262 static void x_check_fullscreen (struct frame
*);
263 static void x_check_expected_move (struct frame
*, int, int);
264 static void x_sync_with_move (struct frame
*, int, int, bool);
265 static int handle_one_xevent (struct x_display_info
*,
266 const XEvent
*, int *,
267 struct input_event
*);
268 #if ! (defined USE_X_TOOLKIT || defined USE_MOTIF)
269 static int x_dispatch_event (XEvent
*, Display
*);
271 /* Don't declare this _Noreturn because we want no
272 interference with debugging failing X calls. */
273 static void x_connection_closed (Display
*, const char *);
274 static void x_wm_set_window_state (struct frame
*, int);
275 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
276 static void x_initialize (void);
278 static bool get_current_wm_state (struct frame
*, Window
, int *, bool *);
280 /* Flush display of frame F. */
283 x_flush (struct frame
*f
)
285 eassert (f
&& FRAME_X_P (f
));
286 /* Don't call XFlush when it is not safe to redisplay; the X
287 connection may be broken. */
288 if (!NILP (Vinhibit_redisplay
))
292 XFlush (FRAME_X_DISPLAY (f
));
297 /* Remove calls to XFlush by defining XFlush to an empty replacement.
298 Calls to XFlush should be unnecessary because the X output buffer
299 is flushed automatically as needed by calls to XPending,
300 XNextEvent, or XWindowEvent according to the XFlush man page.
301 XTread_socket calls XPending. Removing XFlush improves
304 #define XFlush(DISPLAY) (void) 0
307 /***********************************************************************
309 ***********************************************************************/
313 /* This is a function useful for recording debugging information about
314 the sequence of occurrences in this file. */
322 struct record event_record
[100];
324 int event_record_index
;
327 record_event (char *locus
, int type
)
329 if (event_record_index
== ARRAYELTS (event_record
))
330 event_record_index
= 0;
332 event_record
[event_record_index
].locus
= locus
;
333 event_record
[event_record_index
].type
= type
;
334 event_record_index
++;
341 /* Return the struct x_display_info corresponding to DPY. */
343 struct x_display_info
*
344 x_display_info_for_display (Display
*dpy
)
346 struct x_display_info
*dpyinfo
;
348 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
349 if (dpyinfo
->display
== dpy
)
356 x_find_topmost_parent (struct frame
*f
)
358 struct x_output
*x
= f
->output_data
.x
;
359 Window win
= None
, wi
= x
->parent_desc
;
360 Display
*dpy
= FRAME_X_DISPLAY (f
);
362 while (wi
!= FRAME_DISPLAY_INFO (f
)->root_window
)
366 unsigned int nchildren
;
369 if (XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
))
378 #define OPAQUE 0xffffffff
381 x_set_frame_alpha (struct frame
*f
)
383 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
384 Display
*dpy
= FRAME_X_DISPLAY (f
);
385 Window win
= FRAME_OUTER_WINDOW (f
);
387 double alpha_min
= 1.0;
391 if (dpyinfo
->x_highlight_frame
== f
)
396 if (FLOATP (Vframe_alpha_lower_limit
))
397 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
398 else if (INTEGERP (Vframe_alpha_lower_limit
))
399 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
403 else if (alpha
> 1.0)
405 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
408 opac
= alpha
* OPAQUE
;
410 x_catch_errors (dpy
);
412 /* If there is a parent from the window manager, put the property there
413 also, to work around broken window managers that fail to do that.
414 Do this unconditionally as this function is called on reparent when
415 alpha has not changed on the frame. */
417 parent
= x_find_topmost_parent (f
);
419 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
420 XA_CARDINAL
, 32, PropModeReplace
,
421 (unsigned char *) &opac
, 1);
423 /* return unless necessary */
428 unsigned long n
, left
;
430 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
431 0, 1, False
, XA_CARDINAL
,
432 &actual
, &format
, &n
, &left
,
435 if (rc
== Success
&& actual
!= None
)
437 unsigned long value
= *(unsigned long *)data
;
447 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
448 XA_CARDINAL
, 32, PropModeReplace
,
449 (unsigned char *) &opac
, 1);
453 /***********************************************************************
454 Starting and ending an update
455 ***********************************************************************/
457 /* Start an update of frame F. This function is installed as a hook
458 for update_begin, i.e. it is called when update_begin is called.
459 This function is called prior to calls to x_update_window_begin for
460 each window being updated. Currently, there is nothing to do here
461 because all interesting stuff is done on a window basis. */
464 x_update_begin (struct frame
*f
)
470 /* Start update of window W. */
473 x_update_window_begin (struct window
*w
)
475 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
476 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
478 w
->output_cursor
= w
->cursor
;
482 if (f
== hlinfo
->mouse_face_mouse_frame
)
484 /* Don't do highlighting for mouse motion during the update. */
485 hlinfo
->mouse_face_defer
= true;
487 /* If F needs to be redrawn, simply forget about any prior mouse
489 if (FRAME_GARBAGED_P (f
))
490 hlinfo
->mouse_face_window
= Qnil
;
497 /* Draw a vertical window border from (x,y0) to (x,y1) */
500 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
502 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
505 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
507 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
510 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
511 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
514 /* Draw a window divider from (x0,y0) to (x1,y1) */
517 x_draw_window_divider (struct window
*w
, int x0
, int x1
, int y0
, int y1
)
519 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
520 struct face
*face
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FACE_ID
);
521 struct face
*face_first
= FACE_FROM_ID (f
, WINDOW_DIVIDER_FIRST_PIXEL_FACE_ID
);
522 struct face
*face_last
= FACE_FROM_ID (f
, WINDOW_DIVIDER_LAST_PIXEL_FACE_ID
);
523 unsigned long color
= face
? face
->foreground
: FRAME_FOREGROUND_PIXEL (f
);
524 unsigned long color_first
= (face_first
525 ? face_first
->foreground
526 : FRAME_FOREGROUND_PIXEL (f
));
527 unsigned long color_last
= (face_last
528 ? face_last
->foreground
529 : FRAME_FOREGROUND_PIXEL (f
));
530 Display
*display
= FRAME_X_DISPLAY (f
);
531 Window window
= FRAME_X_WINDOW (f
);
533 if (y1
- y0
> x1
- x0
&& x1
- x0
> 2)
536 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_first
);
537 XFillRectangle (display
, window
, f
->output_data
.x
->normal_gc
,
539 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
540 XFillRectangle (display
, window
, f
->output_data
.x
->normal_gc
,
541 x0
+ 1, y0
, x1
- x0
- 2, y1
- y0
);
542 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_last
);
543 XFillRectangle (display
, window
, f
->output_data
.x
->normal_gc
,
544 x1
- 1, y0
, 1, y1
- y0
);
546 else if (x1
- x0
> y1
- y0
&& y1
- y0
> 3)
549 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_first
);
550 XFillRectangle (display
, window
, f
->output_data
.x
->normal_gc
,
552 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
553 XFillRectangle (display
, window
, f
->output_data
.x
->normal_gc
,
554 x0
, y0
+ 1, x1
- x0
, y1
- y0
- 2);
555 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color_last
);
556 XFillRectangle (display
, window
, f
->output_data
.x
->normal_gc
,
557 x0
, y1
- 1, x1
- x0
, 1);
561 XSetForeground (display
, f
->output_data
.x
->normal_gc
, color
);
562 XFillRectangle (display
, window
, f
->output_data
.x
->normal_gc
,
563 x0
, y0
, x1
- x0
, y1
- y0
);
567 /* End update of window W.
569 Draw vertical borders between horizontally adjacent windows, and
570 display W's cursor if CURSOR_ON_P is non-zero.
572 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
573 glyphs in mouse-face were overwritten. In that case we have to
574 make sure that the mouse-highlight is properly redrawn.
576 W may be a menu bar pseudo-window in case we don't have X toolkit
577 support. Such windows don't have a cursor, so don't display it
581 x_update_window_end (struct window
*w
, bool cursor_on_p
,
582 bool mouse_face_overwritten_p
)
584 if (!w
->pseudo_window_p
)
589 display_and_set_cursor (w
, true,
590 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
591 w
->output_cursor
.x
, w
->output_cursor
.y
);
593 if (draw_window_fringes (w
, true))
595 if (WINDOW_RIGHT_DIVIDER_WIDTH (w
))
596 x_draw_right_divider (w
);
598 x_draw_vertical_border (w
);
604 /* If a row with mouse-face was overwritten, arrange for
605 XTframe_up_to_date to redisplay the mouse highlight. */
606 if (mouse_face_overwritten_p
)
608 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
610 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
611 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
612 hlinfo
->mouse_face_window
= Qnil
;
617 /* End update of frame F. This function is installed as a hook in
621 x_update_end (struct frame
*f
)
623 /* Mouse highlight may be displayed again. */
624 MOUSE_HL_INFO (f
)->mouse_face_defer
= false;
628 XFlush (FRAME_X_DISPLAY (f
));
634 /* This function is called from various places in xdisp.c
635 whenever a complete update has been performed. */
638 XTframe_up_to_date (struct frame
*f
)
641 FRAME_MOUSE_UPDATE (f
);
645 /* Clear under internal border if any (GTK has its own version). */
648 x_clear_under_internal_border (struct frame
*f
)
650 if (FRAME_INTERNAL_BORDER_WIDTH (f
) > 0)
652 Display
*display
= FRAME_X_DISPLAY (f
);
653 Window window
= FRAME_X_WINDOW (f
);
654 int border
= FRAME_INTERNAL_BORDER_WIDTH (f
);
655 int width
= FRAME_PIXEL_WIDTH (f
);
656 int height
= FRAME_PIXEL_HEIGHT (f
);
657 int margin
= FRAME_TOP_MARGIN_HEIGHT (f
);
660 x_clear_area (display
, window
, 0, 0, border
, height
);
661 x_clear_area (display
, window
, 0, margin
, width
, border
);
662 x_clear_area (display
, window
, width
- border
, 0, border
, height
);
663 x_clear_area (display
, window
, 0, height
- border
, width
, border
);
669 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
670 arrow bitmaps, or clear the fringes if no bitmaps are required
671 before DESIRED_ROW is made current. This function is called from
672 update_window_line only if it is known that there are differences
673 between bitmaps to be drawn between current row and DESIRED_ROW. */
676 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
680 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
681 desired_row
->redraw_fringe_bitmaps_p
= true;
684 /* When a window has disappeared, make sure that no rest of
685 full-width rows stays visible in the internal border. Could
686 check here if updated window is the leftmost/rightmost window,
687 but I guess it's not worth doing since vertically split windows
688 are almost never used, internal border is rarely set, and the
689 overhead is very small. */
694 if (windows_or_buffers_changed
695 && desired_row
->full_width_p
696 && (f
= XFRAME (w
->frame
),
697 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
699 && (height
= desired_row
->visible_height
,
702 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
705 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
706 0, y
, width
, height
);
707 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
708 FRAME_PIXEL_WIDTH (f
) - width
,
717 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
719 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
720 Display
*display
= FRAME_X_DISPLAY (f
);
721 Window window
= FRAME_X_WINDOW (f
);
722 GC gc
= f
->output_data
.x
->normal_gc
;
723 struct face
*face
= p
->face
;
725 /* Must clip because of partially visible lines. */
726 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
728 if (p
->bx
>= 0 && !p
->overlay_p
)
730 /* In case the same realized face is used for fringes and
731 for something displayed in the text (e.g. face `region' on
732 mono-displays, the fill style may have been changed to
733 FillSolid in x_draw_glyph_string_background. */
735 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
737 XSetForeground (display
, face
->gc
, face
->background
);
739 XFillRectangle (display
, window
, face
->gc
,
740 p
->bx
, p
->by
, p
->nx
, p
->ny
);
743 XSetForeground (display
, face
->gc
, face
->foreground
);
749 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
750 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
754 bits
= (char *) (p
->bits
+ p
->dh
);
756 bits
= (char *) p
->bits
+ p
->dh
;
758 /* Draw the bitmap. I believe these small pixmaps can be cached
760 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
762 ? (p
->overlay_p
? face
->background
763 : f
->output_data
.x
->cursor_pixel
)
765 face
->background
, depth
);
769 clipmask
= XCreatePixmapFromBitmapData (display
,
770 FRAME_DISPLAY_INFO (f
)->root_window
,
773 gcv
.clip_mask
= clipmask
;
774 gcv
.clip_x_origin
= p
->x
;
775 gcv
.clip_y_origin
= p
->y
;
776 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
779 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
780 p
->wd
, p
->h
, p
->x
, p
->y
);
781 XFreePixmap (display
, pixmap
);
785 gcv
.clip_mask
= (Pixmap
) 0;
786 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
787 XFreePixmap (display
, clipmask
);
791 XSetClipMask (display
, gc
, None
);
794 /***********************************************************************
796 ***********************************************************************/
800 static void x_set_glyph_string_clipping (struct glyph_string
*);
801 static void x_set_glyph_string_gc (struct glyph_string
*);
802 static void x_draw_glyph_string_foreground (struct glyph_string
*);
803 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
804 static void x_draw_glyph_string_box (struct glyph_string
*);
805 static void x_draw_glyph_string (struct glyph_string
*);
806 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
807 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
808 static void x_set_cursor_gc (struct glyph_string
*);
809 static void x_set_mode_line_face_gc (struct glyph_string
*);
810 static void x_set_mouse_face_gc (struct glyph_string
*);
811 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
812 unsigned long *, double, int);
813 static void x_setup_relief_color (struct frame
*, struct relief
*,
814 double, int, unsigned long);
815 static void x_setup_relief_colors (struct glyph_string
*);
816 static void x_draw_image_glyph_string (struct glyph_string
*);
817 static void x_draw_image_relief (struct glyph_string
*);
818 static void x_draw_image_foreground (struct glyph_string
*);
819 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
820 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
822 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
823 int, bool, bool, bool, bool, bool,
825 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
826 int, bool, bool, XRectangle
*);
827 static void x_scroll_bar_clear (struct frame
*);
830 static void x_check_font (struct frame
*, struct font
*);
834 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
838 x_set_cursor_gc (struct glyph_string
*s
)
840 if (s
->font
== FRAME_FONT (s
->f
)
841 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
842 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
844 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
847 /* Cursor on non-default face: must merge. */
851 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
852 xgcv
.foreground
= s
->face
->background
;
854 /* If the glyph would be invisible, try a different foreground. */
855 if (xgcv
.foreground
== xgcv
.background
)
856 xgcv
.foreground
= s
->face
->foreground
;
857 if (xgcv
.foreground
== xgcv
.background
)
858 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
859 if (xgcv
.foreground
== xgcv
.background
)
860 xgcv
.foreground
= s
->face
->foreground
;
862 /* Make sure the cursor is distinct from text in this face. */
863 if (xgcv
.background
== s
->face
->background
864 && xgcv
.foreground
== s
->face
->foreground
)
866 xgcv
.background
= s
->face
->foreground
;
867 xgcv
.foreground
= s
->face
->background
;
870 IF_DEBUG (x_check_font (s
->f
, s
->font
));
871 xgcv
.graphics_exposures
= False
;
872 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
874 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
875 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
878 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
879 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
881 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
886 /* Set up S->gc of glyph string S for drawing text in mouse face. */
889 x_set_mouse_face_gc (struct glyph_string
*s
)
894 /* What face has to be used last for the mouse face? */
895 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
896 face
= FACE_FROM_ID (s
->f
, face_id
);
898 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
900 if (s
->first_glyph
->type
== CHAR_GLYPH
)
901 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
903 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
904 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
905 prepare_face_for_display (s
->f
, s
->face
);
907 if (s
->font
== s
->face
->font
)
911 /* Otherwise construct scratch_cursor_gc with values from FACE
916 xgcv
.background
= s
->face
->background
;
917 xgcv
.foreground
= s
->face
->foreground
;
918 xgcv
.graphics_exposures
= False
;
919 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
921 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
922 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
925 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
926 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
928 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
931 eassert (s
->gc
!= 0);
935 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
936 Faces to use in the mode line have already been computed when the
937 matrix was built, so there isn't much to do, here. */
940 x_set_mode_line_face_gc (struct glyph_string
*s
)
946 /* Set S->gc of glyph string S for drawing that glyph string. Set
947 S->stippled_p to a non-zero value if the face of S has a stipple
951 x_set_glyph_string_gc (struct glyph_string
*s
)
953 prepare_face_for_display (s
->f
, s
->face
);
955 if (s
->hl
== DRAW_NORMAL_TEXT
)
958 s
->stippled_p
= s
->face
->stipple
!= 0;
960 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
962 x_set_mode_line_face_gc (s
);
963 s
->stippled_p
= s
->face
->stipple
!= 0;
965 else if (s
->hl
== DRAW_CURSOR
)
968 s
->stippled_p
= false;
970 else if (s
->hl
== DRAW_MOUSE_FACE
)
972 x_set_mouse_face_gc (s
);
973 s
->stippled_p
= s
->face
->stipple
!= 0;
975 else if (s
->hl
== DRAW_IMAGE_RAISED
976 || s
->hl
== DRAW_IMAGE_SUNKEN
)
979 s
->stippled_p
= s
->face
->stipple
!= 0;
984 /* GC must have been set. */
985 eassert (s
->gc
!= 0);
989 /* Set clipping for output of glyph string S. S may be part of a mode
990 line or menu if we don't have X toolkit support. */
993 x_set_glyph_string_clipping (struct glyph_string
*s
)
995 XRectangle
*r
= s
->clip
;
996 int n
= get_glyph_string_clip_rects (s
, r
, 2);
999 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1004 /* Set SRC's clipping for output of glyph string DST. This is called
1005 when we are drawing DST's left_overhang or right_overhang only in
1009 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1014 r
.width
= src
->width
;
1016 r
.height
= src
->height
;
1019 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1024 Compute left and right overhang of glyph string S. */
1027 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1030 && (s
->first_glyph
->type
== CHAR_GLYPH
1031 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1033 struct font_metrics metrics
;
1035 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1037 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1038 struct font
*font
= s
->font
;
1041 for (i
= 0; i
< s
->nchars
; i
++)
1042 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1043 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1047 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1049 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1051 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1052 ? metrics
.rbearing
- metrics
.width
: 0);
1053 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1057 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1058 s
->left_overhang
= - s
->cmp
->lbearing
;
1063 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1066 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1069 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1070 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1071 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1072 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1076 /* Draw the background of glyph_string S. If S->background_filled_p
1077 is non-zero don't draw it. FORCE_P non-zero means draw the
1078 background even if it wouldn't be drawn normally. This is used
1079 when a string preceding S draws into the background of S, or S
1080 contains the first component of a composition. */
1083 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1085 /* Nothing to do if background has already been drawn or if it
1086 shouldn't be drawn in the first place. */
1087 if (!s
->background_filled_p
)
1089 int box_line_width
= max (s
->face
->box_line_width
, 0);
1093 /* Fill background with a stipple pattern. */
1094 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1095 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1096 s
->y
+ box_line_width
,
1097 s
->background_width
,
1098 s
->height
- 2 * box_line_width
);
1099 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1100 s
->background_filled_p
= true;
1102 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1103 || s
->font_not_found_p
1104 || s
->extends_to_end_of_line_p
1107 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1108 s
->background_width
,
1109 s
->height
- 2 * box_line_width
);
1110 s
->background_filled_p
= true;
1116 /* Draw the foreground of glyph string S. */
1119 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1123 /* If first glyph of S has a left box line, start drawing the text
1124 of S to the right of that box line. */
1125 if (s
->face
->box
!= FACE_NO_BOX
1126 && s
->first_glyph
->left_box_line_p
)
1127 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1131 /* Draw characters of S as rectangles if S's font could not be
1133 if (s
->font_not_found_p
)
1135 for (i
= 0; i
< s
->nchars
; ++i
)
1137 struct glyph
*g
= s
->first_glyph
+ i
;
1138 XDrawRectangle (s
->display
, s
->window
,
1139 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1141 x
+= g
->pixel_width
;
1146 struct font
*font
= s
->font
;
1147 int boff
= font
->baseline_offset
;
1150 if (font
->vertical_centering
)
1151 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1153 y
= s
->ybase
- boff
;
1155 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1156 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, false);
1158 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, true);
1159 if (s
->face
->overstrike
)
1160 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, false);
1164 /* Draw the foreground of composite glyph string S. */
1167 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1170 struct font
*font
= s
->font
;
1172 /* If first glyph of S has a left box line, start drawing the text
1173 of S to the right of that box line. */
1174 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1175 && s
->first_glyph
->left_box_line_p
)
1176 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1180 /* S is a glyph string for a composition. S->cmp_from is the index
1181 of the first character drawn for glyphs of this composition.
1182 S->cmp_from == 0 means we are drawing the very first character of
1183 this composition. */
1185 /* Draw a rectangle for the composition if the font for the very
1186 first character of the composition could not be loaded. */
1187 if (s
->font_not_found_p
)
1189 if (s
->cmp_from
== 0)
1190 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1191 s
->width
- 1, s
->height
- 1);
1193 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1197 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1198 /* TAB in a composition means display glyphs with padding
1199 space on the left or right. */
1200 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1202 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1203 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1205 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, false);
1206 if (s
->face
->overstrike
)
1207 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, false);
1212 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1217 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1219 glyph
= LGSTRING_GLYPH (gstring
, i
);
1220 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1221 width
+= LGLYPH_WIDTH (glyph
);
1224 int xoff
, yoff
, wadjust
;
1228 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1229 if (s
->face
->overstrike
)
1230 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, false);
1233 xoff
= LGLYPH_XOFF (glyph
);
1234 yoff
= LGLYPH_YOFF (glyph
);
1235 wadjust
= LGLYPH_WADJUST (glyph
);
1236 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, false);
1237 if (s
->face
->overstrike
)
1238 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
,
1247 font
->driver
->draw (s
, j
, i
, x
, y
, false);
1248 if (s
->face
->overstrike
)
1249 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, false);
1255 /* Draw the foreground of glyph string S for glyphless characters. */
1258 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1260 struct glyph
*glyph
= s
->first_glyph
;
1264 /* If first glyph of S has a left box line, start drawing the text
1265 of S to the right of that box line. */
1266 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1267 && s
->first_glyph
->left_box_line_p
)
1268 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1274 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1276 char buf
[7], *str
= NULL
;
1277 int len
= glyph
->u
.glyphless
.len
;
1279 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1282 && CHAR_TABLE_P (Vglyphless_char_display
)
1283 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1287 = (! glyph
->u
.glyphless
.for_no_font
1288 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1289 glyph
->u
.glyphless
.ch
)
1290 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1291 if (STRINGP (acronym
))
1292 str
= SSDATA (acronym
);
1295 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1297 sprintf (buf
, "%0*X",
1298 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1299 glyph
->u
.glyphless
.ch
);
1305 int upper_len
= (len
+ 1) / 2;
1308 /* It is assured that all LEN characters in STR is ASCII. */
1309 for (j
= 0; j
< len
; j
++)
1311 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1312 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1314 s
->font
->driver
->draw (s
, 0, upper_len
,
1315 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1316 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1318 s
->font
->driver
->draw (s
, upper_len
, len
,
1319 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1320 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1323 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1324 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
1325 x
, s
->ybase
- glyph
->ascent
,
1326 glyph
->pixel_width
- 1,
1327 glyph
->ascent
+ glyph
->descent
- 1);
1328 x
+= glyph
->pixel_width
;
1332 #ifdef USE_X_TOOLKIT
1336 /* Return the frame on which widget WIDGET is used.. Abort if frame
1337 cannot be determined. */
1339 static struct frame
*
1340 x_frame_of_widget (Widget widget
)
1342 struct x_display_info
*dpyinfo
;
1343 Lisp_Object tail
, frame
;
1346 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1348 /* Find the top-level shell of the widget. Note that this function
1349 can be called when the widget is not yet realized, so XtWindow
1350 (widget) == 0. That's the reason we can't simply use
1351 x_any_window_to_frame. */
1352 while (!XtIsTopLevelShell (widget
))
1353 widget
= XtParent (widget
);
1355 /* Look for a frame with that top-level widget. Allocate the color
1356 on that frame to get the right gamma correction value. */
1357 FOR_EACH_FRAME (tail
, frame
)
1361 && f
->output_data
.nothing
!= 1
1362 && FRAME_DISPLAY_INFO (f
) == dpyinfo
1363 && f
->output_data
.x
->widget
== widget
)
1369 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1370 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1371 If this produces the same color as PIXEL, try a color where all RGB
1372 values have DELTA added. Return the allocated color in *PIXEL.
1373 DISPLAY is the X display, CMAP is the colormap to operate on.
1374 Value is true if successful. */
1377 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1378 unsigned long *pixel
, double factor
, int delta
)
1380 struct frame
*f
= x_frame_of_widget (widget
);
1381 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1384 #endif /* USE_LUCID */
1387 /* Structure specifying which arguments should be passed by Xt to
1388 cvt_string_to_pixel. We want the widget's screen and colormap. */
1390 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1392 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1394 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1399 /* The address of this variable is returned by
1400 cvt_string_to_pixel. */
1402 static Pixel cvt_string_to_pixel_value
;
1405 /* Convert a color name to a pixel color.
1407 DPY is the display we are working on.
1409 ARGS is an array of *NARGS XrmValue structures holding additional
1410 information about the widget for which the conversion takes place.
1411 The contents of this array are determined by the specification
1412 in cvt_string_to_pixel_args.
1414 FROM is a pointer to an XrmValue which points to the color name to
1415 convert. TO is an XrmValue in which to return the pixel color.
1417 CLOSURE_RET is a pointer to user-data, in which we record if
1418 we allocated the color or not.
1420 Value is True if successful, False otherwise. */
1423 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1424 XrmValue
*from
, XrmValue
*to
,
1425 XtPointer
*closure_ret
)
1435 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1436 "wrongParameters", "cvt_string_to_pixel",
1438 "Screen and colormap args required", NULL
, NULL
);
1442 screen
= *(Screen
**) args
[0].addr
;
1443 cmap
= *(Colormap
*) args
[1].addr
;
1444 color_name
= (String
) from
->addr
;
1446 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1448 *closure_ret
= (XtPointer
) False
;
1449 pixel
= WhitePixelOfScreen (screen
);
1451 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1453 *closure_ret
= (XtPointer
) False
;
1454 pixel
= BlackPixelOfScreen (screen
);
1456 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1457 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1459 pixel
= color
.pixel
;
1460 *closure_ret
= (XtPointer
) True
;
1465 Cardinal nparams
= 1;
1467 params
[0] = color_name
;
1468 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1469 "badValue", "cvt_string_to_pixel",
1470 "XtToolkitError", "Invalid color `%s'",
1475 if (to
->addr
!= NULL
)
1477 if (to
->size
< sizeof (Pixel
))
1479 to
->size
= sizeof (Pixel
);
1483 *(Pixel
*) to
->addr
= pixel
;
1487 cvt_string_to_pixel_value
= pixel
;
1488 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1491 to
->size
= sizeof (Pixel
);
1496 /* Free a pixel color which was previously allocated via
1497 cvt_string_to_pixel. This is registered as the destructor
1498 for this type of resource via XtSetTypeConverter.
1500 APP is the application context in which we work.
1502 TO is a pointer to an XrmValue holding the color to free.
1503 CLOSURE is the value we stored in CLOSURE_RET for this color
1504 in cvt_string_to_pixel.
1506 ARGS and NARGS are like for cvt_string_to_pixel. */
1509 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1514 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1516 "Screen and colormap arguments required",
1519 else if (closure
!= NULL
)
1521 /* We did allocate the pixel, so free it. */
1522 Screen
*screen
= *(Screen
**) args
[0].addr
;
1523 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1524 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1525 (Pixel
*) to
->addr
, 1);
1530 #endif /* USE_X_TOOLKIT */
1533 /* Value is an array of XColor structures for the contents of the
1534 color map of display DPY. Set *NCELLS to the size of the array.
1535 Note that this probably shouldn't be called for large color maps,
1536 say a 24-bit TrueColor map. */
1538 static const XColor
*
1539 x_color_cells (Display
*dpy
, int *ncells
)
1541 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1543 if (dpyinfo
->color_cells
== NULL
)
1545 Screen
*screen
= dpyinfo
->screen
;
1546 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1549 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
1550 sizeof *dpyinfo
->color_cells
);
1551 dpyinfo
->ncolor_cells
= ncolor_cells
;
1553 for (i
= 0; i
< ncolor_cells
; ++i
)
1554 dpyinfo
->color_cells
[i
].pixel
= i
;
1556 XQueryColors (dpy
, dpyinfo
->cmap
,
1557 dpyinfo
->color_cells
, ncolor_cells
);
1560 *ncells
= dpyinfo
->ncolor_cells
;
1561 return dpyinfo
->color_cells
;
1565 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1566 colors in COLORS. Use cached information, if available. */
1569 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1571 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1573 if (dpyinfo
->color_cells
)
1576 for (i
= 0; i
< ncolors
; ++i
)
1578 unsigned long pixel
= colors
[i
].pixel
;
1579 eassert (pixel
< dpyinfo
->ncolor_cells
);
1580 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1581 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1585 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1589 /* On frame F, translate pixel color to RGB values for the color in
1590 COLOR. Use cached information, if available. */
1593 x_query_color (struct frame
*f
, XColor
*color
)
1595 x_query_colors (f
, color
, 1);
1599 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1600 exact match can't be allocated, try the nearest color available.
1601 Value is true if successful. Set *COLOR to the color
1605 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1609 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1612 /* If we got to this point, the colormap is full, so we're going
1613 to try to get the next closest color. The algorithm used is
1614 a least-squares matching, which is what X uses for closest
1615 color matching with StaticColor visuals. */
1617 int max_color_delta
= 255;
1618 int max_delta
= 3 * max_color_delta
;
1619 int nearest_delta
= max_delta
+ 1;
1621 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1623 for (nearest
= i
= 0; i
< ncells
; ++i
)
1625 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1626 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1627 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1628 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1630 if (delta
< nearest_delta
)
1633 nearest_delta
= delta
;
1637 color
->red
= cells
[nearest
].red
;
1638 color
->green
= cells
[nearest
].green
;
1639 color
->blue
= cells
[nearest
].blue
;
1640 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1644 /* If allocation succeeded, and the allocated pixel color is not
1645 equal to a cached pixel color recorded earlier, there was a
1646 change in the colormap, so clear the color cache. */
1647 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1648 XColor
*cached_color
;
1650 if (dpyinfo
->color_cells
1651 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1652 (cached_color
->red
!= color
->red
1653 || cached_color
->blue
!= color
->blue
1654 || cached_color
->green
!= color
->green
)))
1656 xfree (dpyinfo
->color_cells
);
1657 dpyinfo
->color_cells
= NULL
;
1658 dpyinfo
->ncolor_cells
= 0;
1662 #ifdef DEBUG_X_COLORS
1664 register_color (color
->pixel
);
1665 #endif /* DEBUG_X_COLORS */
1671 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1672 exact match can't be allocated, try the nearest color available.
1673 Value is true if successful. Set *COLOR to the color
1677 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1679 gamma_correct (f
, color
);
1680 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1684 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1685 It's necessary to do this instead of just using PIXEL directly to
1686 get color reference counts right. */
1689 x_copy_color (struct frame
*f
, unsigned long pixel
)
1693 color
.pixel
= pixel
;
1695 x_query_color (f
, &color
);
1696 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1698 #ifdef DEBUG_X_COLORS
1699 register_color (pixel
);
1705 /* Brightness beyond which a color won't have its highlight brightness
1708 Nominally, highlight colors for `3d' faces are calculated by
1709 brightening an object's color by a constant scale factor, but this
1710 doesn't yield good results for dark colors, so for colors who's
1711 brightness is less than this value (on a scale of 0-65535) have an
1712 use an additional additive factor.
1714 The value here is set so that the default menu-bar/mode-line color
1715 (grey75) will not have its highlights changed at all. */
1716 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1719 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1720 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1721 If this produces the same color as PIXEL, try a color where all RGB
1722 values have DELTA added. Return the allocated color in *PIXEL.
1723 DISPLAY is the X display, CMAP is the colormap to operate on.
1724 Value is non-zero if successful. */
1727 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
,
1728 unsigned long *pixel
, double factor
, int delta
)
1734 /* Get RGB color values. */
1735 color
.pixel
= *pixel
;
1736 x_query_color (f
, &color
);
1738 /* Change RGB values by specified FACTOR. Avoid overflow! */
1739 eassert (factor
>= 0);
1740 new.red
= min (0xffff, factor
* color
.red
);
1741 new.green
= min (0xffff, factor
* color
.green
);
1742 new.blue
= min (0xffff, factor
* color
.blue
);
1744 /* Calculate brightness of COLOR. */
1745 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1747 /* We only boost colors that are darker than
1748 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1749 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1750 /* Make an additive adjustment to NEW, because it's dark enough so
1751 that scaling by FACTOR alone isn't enough. */
1753 /* How far below the limit this color is (0 - 1, 1 being darker). */
1754 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1755 /* The additive adjustment. */
1756 int min_delta
= delta
* dimness
* factor
/ 2;
1760 new.red
= max (0, new.red
- min_delta
);
1761 new.green
= max (0, new.green
- min_delta
);
1762 new.blue
= max (0, new.blue
- min_delta
);
1766 new.red
= min (0xffff, min_delta
+ new.red
);
1767 new.green
= min (0xffff, min_delta
+ new.green
);
1768 new.blue
= min (0xffff, min_delta
+ new.blue
);
1772 /* Try to allocate the color. */
1773 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1776 if (new.pixel
== *pixel
)
1778 /* If we end up with the same color as before, try adding
1779 delta to the RGB values. */
1780 x_free_colors (f
, &new.pixel
, 1);
1782 new.red
= min (0xffff, delta
+ color
.red
);
1783 new.green
= min (0xffff, delta
+ color
.green
);
1784 new.blue
= min (0xffff, delta
+ color
.blue
);
1785 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1796 /* Set up the foreground color for drawing relief lines of glyph
1797 string S. RELIEF is a pointer to a struct relief containing the GC
1798 with which lines will be drawn. Use a color that is FACTOR or
1799 DELTA lighter or darker than the relief's background which is found
1800 in S->f->output_data.x->relief_background. If such a color cannot
1801 be allocated, use DEFAULT_PIXEL, instead. */
1804 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
,
1805 int delta
, unsigned long default_pixel
)
1808 struct x_output
*di
= f
->output_data
.x
;
1809 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1810 unsigned long pixel
;
1811 unsigned long background
= di
->relief_background
;
1812 Colormap cmap
= FRAME_X_COLORMAP (f
);
1813 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1814 Display
*dpy
= FRAME_X_DISPLAY (f
);
1816 xgcv
.graphics_exposures
= False
;
1817 xgcv
.line_width
= 1;
1819 /* Free previously allocated color. The color cell will be reused
1820 when it has been freed as many times as it was allocated, so this
1821 doesn't affect faces using the same colors. */
1822 if (relief
->gc
&& relief
->pixel
!= -1)
1824 x_free_colors (f
, &relief
->pixel
, 1);
1828 /* Allocate new color. */
1829 xgcv
.foreground
= default_pixel
;
1831 if (dpyinfo
->n_planes
!= 1
1832 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1833 xgcv
.foreground
= relief
->pixel
= pixel
;
1835 if (relief
->gc
== 0)
1837 xgcv
.stipple
= dpyinfo
->gray
;
1839 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1842 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1846 /* Set up colors for the relief lines around glyph string S. */
1849 x_setup_relief_colors (struct glyph_string
*s
)
1851 struct x_output
*di
= s
->f
->output_data
.x
;
1852 unsigned long color
;
1854 if (s
->face
->use_box_color_for_shadows_p
)
1855 color
= s
->face
->box_color
;
1856 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1858 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1859 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1864 /* Get the background color of the face. */
1865 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1866 color
= xgcv
.background
;
1869 if (di
->white_relief
.gc
== 0
1870 || color
!= di
->relief_background
)
1872 di
->relief_background
= color
;
1873 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1874 WHITE_PIX_DEFAULT (s
->f
));
1875 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1876 BLACK_PIX_DEFAULT (s
->f
));
1881 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1882 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1883 to draw, it must be >= 0. RAISED_P means draw a raised
1884 relief. LEFT_P means draw a relief on the left side of
1885 the rectangle. RIGHT_P means draw a relief on the right
1886 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1890 x_draw_relief_rect (struct frame
*f
,
1891 int left_x
, int top_y
, int right_x
, int bottom_y
,
1892 int width
, bool raised_p
, bool top_p
, bool bot_p
,
1893 bool left_p
, bool right_p
,
1894 XRectangle
*clip_rect
)
1896 Display
*dpy
= FRAME_X_DISPLAY (f
);
1897 Window window
= FRAME_X_WINDOW (f
);
1902 gc
= f
->output_data
.x
->white_relief
.gc
;
1904 gc
= f
->output_data
.x
->black_relief
.gc
;
1905 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1907 /* This code is more complicated than it has to be, because of two
1908 minor hacks to make the boxes look nicer: (i) if width > 1, draw
1909 the outermost line using the black relief. (ii) Omit the four
1916 XDrawLine (dpy
, window
, gc
,
1917 left_x
+ left_p
, top_y
,
1918 right_x
+ !right_p
, top_y
);
1920 for (i
= 1; i
< width
; ++i
)
1921 XDrawLine (dpy
, window
, gc
,
1922 left_x
+ i
* left_p
, top_y
+ i
,
1923 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1930 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1932 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
1933 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
1935 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
1936 XDrawLine (dpy
, window
, gc
,
1937 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
1938 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1941 XSetClipMask (dpy
, gc
, None
);
1943 gc
= f
->output_data
.x
->black_relief
.gc
;
1945 gc
= f
->output_data
.x
->white_relief
.gc
;
1946 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1950 /* Outermost top line. */
1952 XDrawLine (dpy
, window
, gc
,
1953 left_x
+ left_p
, top_y
,
1954 right_x
+ !right_p
, top_y
);
1956 /* Outermost left line. */
1958 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1964 XDrawLine (dpy
, window
, gc
,
1965 left_x
+ left_p
, bottom_y
,
1966 right_x
+ !right_p
, bottom_y
);
1967 for (i
= 1; i
< width
; ++i
)
1968 XDrawLine (dpy
, window
, gc
,
1969 left_x
+ i
* left_p
, bottom_y
- i
,
1970 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
1976 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
1977 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
1978 for (i
= 0; i
< width
; ++i
)
1979 XDrawLine (dpy
, window
, gc
,
1980 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
1981 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1984 XSetClipMask (dpy
, gc
, None
);
1988 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1989 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1990 draw, it must be >= 0. LEFT_P means draw a line on the
1991 left side of the rectangle. RIGHT_P means draw a line
1992 on the right side of the rectangle. CLIP_RECT is the clipping
1993 rectangle to use when drawing. */
1996 x_draw_box_rect (struct glyph_string
*s
,
1997 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1998 bool left_p
, bool right_p
, XRectangle
*clip_rect
)
2002 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2003 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2004 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2007 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2008 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2012 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2013 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2016 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2017 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2021 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2022 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2024 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2025 XSetClipMask (s
->display
, s
->gc
, None
);
2029 /* Draw a box around glyph string S. */
2032 x_draw_glyph_string_box (struct glyph_string
*s
)
2034 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
;
2035 bool raised_p
, left_p
, right_p
;
2036 struct glyph
*last_glyph
;
2037 XRectangle clip_rect
;
2039 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2040 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2041 : window_box_right (s
->w
, s
->area
));
2043 /* The glyph that may have a right box line. */
2044 last_glyph
= (s
->cmp
|| s
->img
2046 : s
->first_glyph
+ s
->nchars
- 1);
2048 width
= eabs (s
->face
->box_line_width
);
2049 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2051 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2053 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2055 bottom_y
= top_y
+ s
->height
- 1;
2057 left_p
= (s
->first_glyph
->left_box_line_p
2058 || (s
->hl
== DRAW_MOUSE_FACE
2060 || s
->prev
->hl
!= s
->hl
)));
2061 right_p
= (last_glyph
->right_box_line_p
2062 || (s
->hl
== DRAW_MOUSE_FACE
2064 || s
->next
->hl
!= s
->hl
)));
2066 get_glyph_string_clip_rect (s
, &clip_rect
);
2068 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2069 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2070 left_p
, right_p
, &clip_rect
);
2073 x_setup_relief_colors (s
);
2074 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2075 width
, raised_p
, true, true, left_p
, right_p
,
2081 /* Draw foreground of image glyph string S. */
2084 x_draw_image_foreground (struct glyph_string
*s
)
2087 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2089 /* If first glyph of S has a left box line, start drawing it to the
2090 right of that line. */
2091 if (s
->face
->box
!= FACE_NO_BOX
2092 && s
->first_glyph
->left_box_line_p
2094 x
+= eabs (s
->face
->box_line_width
);
2096 /* If there is a margin around the image, adjust x- and y-position
2098 if (s
->slice
.x
== 0)
2099 x
+= s
->img
->hmargin
;
2100 if (s
->slice
.y
== 0)
2101 y
+= s
->img
->vmargin
;
2107 /* We can't set both a clip mask and use XSetClipRectangles
2108 because the latter also sets a clip mask. We also can't
2109 trust on the shape extension to be available
2110 (XShapeCombineRegion). So, compute the rectangle to draw
2112 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2115 XRectangle clip_rect
, image_rect
, r
;
2117 xgcv
.clip_mask
= s
->img
->mask
;
2118 xgcv
.clip_x_origin
= x
;
2119 xgcv
.clip_y_origin
= y
;
2120 xgcv
.function
= GXcopy
;
2121 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2123 get_glyph_string_clip_rect (s
, &clip_rect
);
2126 image_rect
.width
= s
->slice
.width
;
2127 image_rect
.height
= s
->slice
.height
;
2128 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2129 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2130 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2131 r
.width
, r
.height
, r
.x
, r
.y
);
2135 XRectangle clip_rect
, image_rect
, r
;
2137 get_glyph_string_clip_rect (s
, &clip_rect
);
2140 image_rect
.width
= s
->slice
.width
;
2141 image_rect
.height
= s
->slice
.height
;
2142 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2143 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2144 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2145 r
.width
, r
.height
, r
.x
, r
.y
);
2147 /* When the image has a mask, we can expect that at
2148 least part of a mouse highlight or a block cursor will
2149 be visible. If the image doesn't have a mask, make
2150 a block cursor visible by drawing a rectangle around
2151 the image. I believe it's looking better if we do
2152 nothing here for mouse-face. */
2153 if (s
->hl
== DRAW_CURSOR
)
2155 int relief
= eabs (s
->img
->relief
);
2156 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2157 x
- relief
, y
- relief
,
2158 s
->slice
.width
+ relief
*2 - 1,
2159 s
->slice
.height
+ relief
*2 - 1);
2164 /* Draw a rectangle if image could not be loaded. */
2165 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2166 s
->slice
.width
- 1, s
->slice
.height
- 1);
2170 /* Draw a relief around the image glyph string S. */
2173 x_draw_image_relief (struct glyph_string
*s
)
2176 bool raised_p
, top_p
, bot_p
, left_p
, right_p
;
2177 int extra_x
, extra_y
;
2180 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2182 /* If first glyph of S has a left box line, start drawing it to the
2183 right of that line. */
2184 if (s
->face
->box
!= FACE_NO_BOX
2185 && s
->first_glyph
->left_box_line_p
2187 x
+= eabs (s
->face
->box_line_width
);
2189 /* If there is a margin around the image, adjust x- and y-position
2191 if (s
->slice
.x
== 0)
2192 x
+= s
->img
->hmargin
;
2193 if (s
->slice
.y
== 0)
2194 y
+= s
->img
->vmargin
;
2196 if (s
->hl
== DRAW_IMAGE_SUNKEN
2197 || s
->hl
== DRAW_IMAGE_RAISED
)
2199 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2200 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2204 thick
= eabs (s
->img
->relief
);
2205 raised_p
= s
->img
->relief
> 0;
2208 x1
= x
+ s
->slice
.width
- 1;
2209 y1
= y
+ s
->slice
.height
- 1;
2211 extra_x
= extra_y
= 0;
2212 if (s
->face
->id
== TOOL_BAR_FACE_ID
)
2214 if (CONSP (Vtool_bar_button_margin
)
2215 && INTEGERP (XCAR (Vtool_bar_button_margin
))
2216 && INTEGERP (XCDR (Vtool_bar_button_margin
)))
2218 extra_x
= XINT (XCAR (Vtool_bar_button_margin
));
2219 extra_y
= XINT (XCDR (Vtool_bar_button_margin
));
2221 else if (INTEGERP (Vtool_bar_button_margin
))
2222 extra_x
= extra_y
= XINT (Vtool_bar_button_margin
);
2225 top_p
= bot_p
= left_p
= right_p
= false;
2227 if (s
->slice
.x
== 0)
2228 x
-= thick
+ extra_x
, left_p
= true;
2229 if (s
->slice
.y
== 0)
2230 y
-= thick
+ extra_y
, top_p
= true;
2231 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
2232 x1
+= thick
+ extra_x
, right_p
= true;
2233 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
2234 y1
+= thick
+ extra_y
, bot_p
= true;
2236 x_setup_relief_colors (s
);
2237 get_glyph_string_clip_rect (s
, &r
);
2238 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
2239 top_p
, bot_p
, left_p
, right_p
, &r
);
2243 /* Draw the foreground of image glyph string S to PIXMAP. */
2246 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2249 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2251 /* If first glyph of S has a left box line, start drawing it to the
2252 right of that line. */
2253 if (s
->face
->box
!= FACE_NO_BOX
2254 && s
->first_glyph
->left_box_line_p
2256 x
+= eabs (s
->face
->box_line_width
);
2258 /* If there is a margin around the image, adjust x- and y-position
2260 if (s
->slice
.x
== 0)
2261 x
+= s
->img
->hmargin
;
2262 if (s
->slice
.y
== 0)
2263 y
+= s
->img
->vmargin
;
2269 /* We can't set both a clip mask and use XSetClipRectangles
2270 because the latter also sets a clip mask. We also can't
2271 trust on the shape extension to be available
2272 (XShapeCombineRegion). So, compute the rectangle to draw
2274 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2278 xgcv
.clip_mask
= s
->img
->mask
;
2279 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2280 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2281 xgcv
.function
= GXcopy
;
2282 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2284 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2285 s
->slice
.x
, s
->slice
.y
,
2286 s
->slice
.width
, s
->slice
.height
, x
, y
);
2287 XSetClipMask (s
->display
, s
->gc
, None
);
2291 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2292 s
->slice
.x
, s
->slice
.y
,
2293 s
->slice
.width
, s
->slice
.height
, x
, y
);
2295 /* When the image has a mask, we can expect that at
2296 least part of a mouse highlight or a block cursor will
2297 be visible. If the image doesn't have a mask, make
2298 a block cursor visible by drawing a rectangle around
2299 the image. I believe it's looking better if we do
2300 nothing here for mouse-face. */
2301 if (s
->hl
== DRAW_CURSOR
)
2303 int r
= eabs (s
->img
->relief
);
2304 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2305 s
->slice
.width
+ r
*2 - 1,
2306 s
->slice
.height
+ r
*2 - 1);
2311 /* Draw a rectangle if image could not be loaded. */
2312 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2313 s
->slice
.width
- 1, s
->slice
.height
- 1);
2317 /* Draw part of the background of glyph string S. X, Y, W, and H
2318 give the rectangle to draw. */
2321 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2325 /* Fill background with a stipple pattern. */
2326 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2327 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2328 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2331 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2335 /* Draw image glyph string S.
2338 s->x +-------------------------
2341 | +-------------------------
2344 | | +-------------------
2350 x_draw_image_glyph_string (struct glyph_string
*s
)
2352 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2353 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2355 Pixmap pixmap
= None
;
2358 if (s
->slice
.y
== 0)
2359 height
-= box_line_vwidth
;
2360 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2361 height
-= box_line_vwidth
;
2363 /* Fill background with face under the image. Do it only if row is
2364 taller than image or if image has a clip mask to reduce
2366 s
->stippled_p
= s
->face
->stipple
!= 0;
2367 if (height
> s
->slice
.height
2371 || s
->img
->pixmap
== 0
2372 || s
->width
!= s
->background_width
)
2376 /* Create a pixmap as large as the glyph string. Fill it
2377 with the background color. Copy the image to it, using
2378 its mask. Copy the temporary pixmap to the display. */
2379 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2380 int depth
= DefaultDepthOfScreen (screen
);
2382 /* Create a pixmap as large as the glyph string. */
2383 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2384 s
->background_width
,
2387 /* Don't clip in the following because we're working on the
2389 XSetClipMask (s
->display
, s
->gc
, None
);
2391 /* Fill the pixmap with the background color/stipple. */
2394 /* Fill background with a stipple pattern. */
2395 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2396 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2397 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2398 0, 0, s
->background_width
, s
->height
);
2399 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2400 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2405 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2407 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2408 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2409 0, 0, s
->background_width
, s
->height
);
2410 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2417 int width
= s
->background_width
;
2419 if (s
->first_glyph
->left_box_line_p
2422 x
+= box_line_hwidth
;
2423 width
-= box_line_hwidth
;
2426 if (s
->slice
.y
== 0)
2427 y
+= box_line_vwidth
;
2429 x_draw_glyph_string_bg_rect (s
, x
, y
, width
, height
);
2432 s
->background_filled_p
= true;
2435 /* Draw the foreground. */
2438 x_draw_image_foreground_1 (s
, pixmap
);
2439 x_set_glyph_string_clipping (s
);
2440 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2441 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2442 XFreePixmap (s
->display
, pixmap
);
2445 x_draw_image_foreground (s
);
2447 /* If we must draw a relief around the image, do it. */
2449 || s
->hl
== DRAW_IMAGE_RAISED
2450 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2451 x_draw_image_relief (s
);
2455 /* Draw stretch glyph string S. */
2458 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2460 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2462 if (s
->hl
== DRAW_CURSOR
2463 && !x_stretch_cursor_p
)
2465 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2466 wide as the stretch glyph. */
2467 int width
, background_width
= s
->background_width
;
2470 if (!s
->row
->reversed_p
)
2472 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2476 background_width
-= left_x
- x
;
2482 /* In R2L rows, draw the cursor on the right edge of the
2484 int right_x
= window_box_right (s
->w
, TEXT_AREA
);
2486 if (x
+ background_width
> right_x
)
2487 background_width
-= x
- right_x
;
2488 x
+= background_width
;
2490 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2491 if (s
->row
->reversed_p
)
2495 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2497 /* Clear rest using the GC of the original non-cursor face. */
2498 if (width
< background_width
)
2501 int w
= background_width
- width
, h
= s
->height
;
2505 if (!s
->row
->reversed_p
)
2509 if (s
->row
->mouse_face_p
2510 && cursor_in_mouse_face_p (s
->w
))
2512 x_set_mouse_face_gc (s
);
2518 get_glyph_string_clip_rect (s
, &r
);
2519 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2521 if (s
->face
->stipple
)
2523 /* Fill background with a stipple pattern. */
2524 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2525 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2526 XSetFillStyle (s
->display
, gc
, FillSolid
);
2531 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2532 XSetForeground (s
->display
, gc
, xgcv
.background
);
2533 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2534 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2537 XSetClipMask (s
->display
, gc
, None
);
2540 else if (!s
->background_filled_p
)
2542 int background_width
= s
->background_width
;
2543 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2545 /* Don't draw into left margin, fringe or scrollbar area
2546 except for header line and mode line. */
2547 if (x
< left_x
&& !s
->row
->mode_line_p
)
2549 background_width
-= left_x
- x
;
2552 if (background_width
> 0)
2553 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2556 s
->background_filled_p
= true;
2560 Draw a wavy line under S. The wave fills wave_height pixels from y0.
2566 wave_height = 3 | * * * *
2571 x_draw_underwave (struct glyph_string
*s
)
2573 int wave_height
= 3, wave_length
= 2;
2574 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, xmax
;
2576 XRectangle wave_clip
, string_clip
, final_clip
;
2579 dy
= wave_height
- 1;
2581 y0
= s
->ybase
- wave_height
+ 3;
2585 /* Find and set clipping rectangle */
2589 wave_clip
.width
= width
;
2590 wave_clip
.height
= wave_height
;
2591 get_glyph_string_clip_rect (s
, &string_clip
);
2593 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
2596 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
2598 /* Draw the waves */
2600 x1
= x0
- (x0
% dx
);
2602 odd
= (x1
/ dx
) & 1;
2610 if (INT_MAX
- dx
< xmax
)
2615 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
2617 x2
+= dx
, y2
= y0
+ odd
*dy
;
2621 /* Restore previous clipping rectangle(s) */
2622 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
2626 /* Draw glyph string S. */
2629 x_draw_glyph_string (struct glyph_string
*s
)
2631 bool relief_drawn_p
= false;
2633 /* If S draws into the background of its successors, draw the
2634 background of the successors first so that S can draw into it.
2635 This makes S->next use XDrawString instead of XDrawImageString. */
2636 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2639 struct glyph_string
*next
;
2641 for (width
= 0, next
= s
->next
;
2642 next
&& width
< s
->right_overhang
;
2643 width
+= next
->width
, next
= next
->next
)
2644 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2646 x_set_glyph_string_gc (next
);
2647 x_set_glyph_string_clipping (next
);
2648 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2649 x_draw_stretch_glyph_string (next
);
2651 x_draw_glyph_string_background (next
, true);
2652 next
->num_clips
= 0;
2656 /* Set up S->gc, set clipping and draw S. */
2657 x_set_glyph_string_gc (s
);
2659 /* Draw relief (if any) in advance for char/composition so that the
2660 glyph string can be drawn over it. */
2661 if (!s
->for_overlaps
2662 && s
->face
->box
!= FACE_NO_BOX
2663 && (s
->first_glyph
->type
== CHAR_GLYPH
2664 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2667 x_set_glyph_string_clipping (s
);
2668 x_draw_glyph_string_background (s
, true);
2669 x_draw_glyph_string_box (s
);
2670 x_set_glyph_string_clipping (s
);
2671 relief_drawn_p
= true;
2673 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2675 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2676 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2677 /* We must clip just this glyph. left_overhang part has already
2678 drawn when s->prev was drawn, and right_overhang part will be
2679 drawn later when s->next is drawn. */
2680 x_set_glyph_string_clipping_exactly (s
, s
);
2682 x_set_glyph_string_clipping (s
);
2684 switch (s
->first_glyph
->type
)
2687 x_draw_image_glyph_string (s
);
2690 #ifdef HAVE_XWIDGETS
2692 //erase xwidget background
2693 //x_draw_glyph_string_background (s, 0);
2694 x_draw_xwidget_glyph_string (s
);
2698 x_draw_stretch_glyph_string (s
);
2702 if (s
->for_overlaps
)
2703 s
->background_filled_p
= true;
2705 x_draw_glyph_string_background (s
, false);
2706 x_draw_glyph_string_foreground (s
);
2709 case COMPOSITE_GLYPH
:
2710 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2711 && ! s
->first_glyph
->u
.cmp
.automatic
))
2712 s
->background_filled_p
= true;
2714 x_draw_glyph_string_background (s
, true);
2715 x_draw_composite_glyph_string_foreground (s
);
2718 case GLYPHLESS_GLYPH
:
2719 if (s
->for_overlaps
)
2720 s
->background_filled_p
= true;
2722 x_draw_glyph_string_background (s
, true);
2723 x_draw_glyphless_glyph_string_foreground (s
);
2730 if (!s
->for_overlaps
)
2732 /* Draw underline. */
2733 if (s
->face
->underline_p
)
2735 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2737 if (s
->face
->underline_defaulted_p
)
2738 x_draw_underwave (s
);
2742 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2743 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2744 x_draw_underwave (s
);
2745 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2748 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2750 unsigned long thickness
, position
;
2753 if (s
->prev
&& s
->prev
->face
->underline_p
2754 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2756 /* We use the same underline style as the previous one. */
2757 thickness
= s
->prev
->underline_thickness
;
2758 position
= s
->prev
->underline_position
;
2762 /* Get the underline thickness. Default is 1 pixel. */
2763 if (s
->font
&& s
->font
->underline_thickness
> 0)
2764 thickness
= s
->font
->underline_thickness
;
2767 if (x_underline_at_descent_line
)
2768 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2771 /* Get the underline position. This is the recommended
2772 vertical offset in pixels from the baseline to the top of
2773 the underline. This is a signed value according to the
2774 specs, and its default is
2776 ROUND ((maximum descent) / 2), with
2777 ROUND(x) = floor (x + 0.5) */
2779 if (x_use_underline_position_properties
2780 && s
->font
&& s
->font
->underline_position
>= 0)
2781 position
= s
->font
->underline_position
;
2783 position
= (s
->font
->descent
+ 1) / 2;
2785 position
= underline_minimum_offset
;
2787 position
= max (position
, underline_minimum_offset
);
2789 /* Check the sanity of thickness and position. We should
2790 avoid drawing underline out of the current line area. */
2791 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2792 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2793 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2794 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2795 s
->underline_thickness
= thickness
;
2796 s
->underline_position
= position
;
2797 y
= s
->ybase
+ position
;
2798 if (s
->face
->underline_defaulted_p
)
2799 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2800 s
->x
, y
, s
->width
, thickness
);
2804 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2805 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2806 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2807 s
->x
, y
, s
->width
, thickness
);
2808 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2812 /* Draw overline. */
2813 if (s
->face
->overline_p
)
2815 unsigned long dy
= 0, h
= 1;
2817 if (s
->face
->overline_color_defaulted_p
)
2818 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2823 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2824 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2825 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2827 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2831 /* Draw strike-through. */
2832 if (s
->face
->strike_through_p
)
2834 unsigned long h
= 1;
2835 unsigned long dy
= (s
->height
- h
) / 2;
2837 if (s
->face
->strike_through_color_defaulted_p
)
2838 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2843 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2844 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2845 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2847 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2851 /* Draw relief if not yet drawn. */
2852 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2853 x_draw_glyph_string_box (s
);
2857 struct glyph_string
*prev
;
2859 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2860 if (prev
->hl
!= s
->hl
2861 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2863 /* As prev was drawn while clipped to its own area, we
2864 must draw the right_overhang part using s->hl now. */
2865 enum draw_glyphs_face save
= prev
->hl
;
2868 x_set_glyph_string_gc (prev
);
2869 x_set_glyph_string_clipping_exactly (s
, prev
);
2870 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2871 x_draw_glyph_string_foreground (prev
);
2873 x_draw_composite_glyph_string_foreground (prev
);
2874 XSetClipMask (prev
->display
, prev
->gc
, None
);
2876 prev
->num_clips
= 0;
2882 struct glyph_string
*next
;
2884 for (next
= s
->next
; next
; next
= next
->next
)
2885 if (next
->hl
!= s
->hl
2886 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2888 /* As next will be drawn while clipped to its own area,
2889 we must draw the left_overhang part using s->hl now. */
2890 enum draw_glyphs_face save
= next
->hl
;
2893 x_set_glyph_string_gc (next
);
2894 x_set_glyph_string_clipping_exactly (s
, next
);
2895 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2896 x_draw_glyph_string_foreground (next
);
2898 x_draw_composite_glyph_string_foreground (next
);
2899 XSetClipMask (next
->display
, next
->gc
, None
);
2901 next
->num_clips
= 0;
2902 next
->clip_head
= s
->next
;
2907 /* Reset clipping. */
2908 XSetClipMask (s
->display
, s
->gc
, None
);
2912 /* Shift display to make room for inserted glyphs. */
2915 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2917 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2918 f
->output_data
.x
->normal_gc
,
2919 x
, y
, width
, height
,
2923 /* Delete N glyphs at the nominal cursor position. Not implemented
2927 x_delete_glyphs (struct frame
*f
, register int n
)
2933 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2934 If they are <= 0, this is probably an error. */
2937 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
)
2939 eassert (width
> 0 && height
> 0);
2940 XClearArea (dpy
, window
, x
, y
, width
, height
, False
);
2944 /* Clear an entire frame. */
2947 x_clear_frame (struct frame
*f
)
2949 /* Clearing the frame will erase any cursor, so mark them all as no
2951 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2955 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2957 /* We have to clear the scroll bars. If we have changed colors or
2958 something like that, then they should be notified. */
2959 x_scroll_bar_clear (f
);
2961 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2962 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2963 redisplay, do it here. */
2964 if (FRAME_GTK_WIDGET (f
))
2965 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2968 XFlush (FRAME_X_DISPLAY (f
));
2973 /* RIF: Show hourglass cursor on frame F. */
2976 x_show_hourglass (struct frame
*f
)
2978 Display
*dpy
= FRAME_X_DISPLAY (f
);
2982 struct x_output
*x
= FRAME_X_OUTPUT (f
);
2983 #ifdef USE_X_TOOLKIT
2986 if (FRAME_OUTER_WINDOW (f
))
2989 x
->hourglass_p
= true;
2991 if (!x
->hourglass_window
)
2993 unsigned long mask
= CWCursor
;
2994 XSetWindowAttributes attrs
;
2996 Window parent
= FRAME_X_WINDOW (f
);
2998 Window parent
= FRAME_OUTER_WINDOW (f
);
3000 attrs
.cursor
= x
->hourglass_cursor
;
3002 x
->hourglass_window
= XCreateWindow
3003 (dpy
, parent
, 0, 0, 32000, 32000, 0, 0,
3004 InputOnly
, CopyFromParent
, mask
, &attrs
);
3007 XMapRaised (dpy
, x
->hourglass_window
);
3013 /* RIF: Cancel hourglass cursor on frame F. */
3016 x_hide_hourglass (struct frame
*f
)
3018 struct x_output
*x
= FRAME_X_OUTPUT (f
);
3020 /* Watch out for newly created frames. */
3021 if (x
->hourglass_window
)
3023 XUnmapWindow (FRAME_X_DISPLAY (f
), x
->hourglass_window
);
3024 /* Sync here because XTread_socket looks at the
3025 hourglass_p flag that is reset to zero below. */
3026 XSync (FRAME_X_DISPLAY (f
), False
);
3027 x
->hourglass_p
= false;
3031 /* Invert the middle quarter of the frame for .15 sec. */
3034 XTflash (struct frame
*f
)
3040 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
3041 when the scroll bars and the edit widget share the same X window. */
3042 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
3044 cairo_t
*cr
= gdk_cairo_create (window
);
3045 cairo_set_source_rgb (cr
, 1, 1, 1);
3046 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
3047 #define XFillRectangle(d, win, gc, x, y, w, h) \
3049 cairo_rectangle (cr, x, y, w, h); \
3053 #else /* ! HAVE_GTK3 */
3056 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
3057 ^ FRAME_BACKGROUND_PIXEL (f
));
3058 vals
.function
= GDK_XOR
;
3059 gc
= gdk_gc_new_with_values (window
,
3060 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
3061 #define XFillRectangle(d, win, gc, x, y, w, h) \
3062 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
3063 #endif /* ! HAVE_GTK3 */
3064 #else /* ! USE_GTK */
3067 /* Create a GC that will use the GXxor function to flip foreground
3068 pixels into background pixels. */
3072 values
.function
= GXxor
;
3073 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3074 ^ FRAME_BACKGROUND_PIXEL (f
));
3076 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3077 GCFunction
| GCForeground
, &values
);
3081 /* Get the height not including a menu bar widget. */
3082 int height
= FRAME_PIXEL_HEIGHT (f
);
3083 /* Height of each line to flash. */
3084 int flash_height
= FRAME_LINE_HEIGHT (f
);
3085 /* These will be the left and right margins of the rectangles. */
3086 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3087 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3088 int width
= flash_right
- flash_left
;
3090 /* If window is tall, flash top and bottom line. */
3091 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3093 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3095 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3096 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3097 width
, flash_height
);
3098 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3100 (height
- flash_height
3101 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3102 width
, flash_height
);
3106 /* If it is short, flash it all. */
3107 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3108 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3109 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3114 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
3115 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
3117 /* Keep waiting until past the time wakeup or any input gets
3119 while (! detect_input_pending ())
3121 struct timespec current
= current_timespec ();
3122 struct timespec timeout
;
3124 /* Break if result would not be positive. */
3125 if (timespec_cmp (wakeup
, current
) <= 0)
3128 /* How long `select' should wait. */
3129 timeout
= make_timespec (0, 10 * 1000 * 1000);
3131 /* Try to wait that long--but we might wake up sooner. */
3132 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3136 /* If window is tall, flash top and bottom line. */
3137 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3139 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3141 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3142 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3143 width
, flash_height
);
3144 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3146 (height
- flash_height
3147 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3148 width
, flash_height
);
3151 /* If it is short, flash it all. */
3152 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3153 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3154 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3160 g_object_unref (G_OBJECT (gc
));
3162 #undef XFillRectangle
3164 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3175 XTtoggle_invisible_pointer (struct frame
*f
, bool invisible
)
3178 FRAME_DISPLAY_INFO (f
)->toggle_visible_pointer (f
, invisible
);
3183 /* Make audible bell. */
3186 XTring_bell (struct frame
*f
)
3188 if (FRAME_X_DISPLAY (f
))
3196 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
3198 XBell (FRAME_X_DISPLAY (f
), 0);
3200 XFlush (FRAME_X_DISPLAY (f
));
3206 /***********************************************************************
3208 ***********************************************************************/
3210 /* Perform an insert-lines or delete-lines operation, inserting N
3211 lines or deleting -N lines at vertical position VPOS. */
3214 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3220 /* Scroll part of the display as described by RUN. */
3223 x_scroll_run (struct window
*w
, struct run
*run
)
3225 struct frame
*f
= XFRAME (w
->frame
);
3226 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3228 /* Get frame-relative bounding box of the text display area of W,
3229 without mode lines. Include in this box the left and right
3231 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
3233 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3234 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3235 bottom_y
= y
+ height
;
3239 /* Scrolling up. Make sure we don't copy part of the mode
3240 line at the bottom. */
3241 if (from_y
+ run
->height
> bottom_y
)
3242 height
= bottom_y
- from_y
;
3244 height
= run
->height
;
3248 /* Scrolling down. Make sure we don't copy over the mode line.
3250 if (to_y
+ run
->height
> bottom_y
)
3251 height
= bottom_y
- to_y
;
3253 height
= run
->height
;
3258 /* Cursor off. Will be switched on again in x_update_window_end. */
3261 XCopyArea (FRAME_X_DISPLAY (f
),
3262 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3263 f
->output_data
.x
->normal_gc
,
3273 /***********************************************************************
3275 ***********************************************************************/
3279 frame_highlight (struct frame
*f
)
3281 /* We used to only do this if Vx_no_window_manager was non-nil, but
3282 the ICCCM (section 4.1.6) says that the window's border pixmap
3283 and border pixel are window attributes which are "private to the
3284 client", so we can always change it to whatever we want. */
3286 /* I recently started to get errors in this XSetWindowBorder, depending on
3287 the window-manager in use, tho something more is at play since I've been
3288 using that same window-manager binary for ever. Let's not crash just
3289 because of this (bug#9310). */
3290 x_catch_errors (FRAME_X_DISPLAY (f
));
3291 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3292 f
->output_data
.x
->border_pixel
);
3293 x_uncatch_errors ();
3295 x_update_cursor (f
, true);
3296 x_set_frame_alpha (f
);
3300 frame_unhighlight (struct frame
*f
)
3302 /* We used to only do this if Vx_no_window_manager was non-nil, but
3303 the ICCCM (section 4.1.6) says that the window's border pixmap
3304 and border pixel are window attributes which are "private to the
3305 client", so we can always change it to whatever we want. */
3307 /* Same as above for XSetWindowBorder (bug#9310). */
3308 x_catch_errors (FRAME_X_DISPLAY (f
));
3309 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3310 f
->output_data
.x
->border_tile
);
3311 x_uncatch_errors ();
3313 x_update_cursor (f
, true);
3314 x_set_frame_alpha (f
);
3317 /* The focus has changed. Update the frames as necessary to reflect
3318 the new situation. Note that we can't change the selected frame
3319 here, because the Lisp code we are interrupting might become confused.
3320 Each event gets marked with the frame in which it occurred, so the
3321 Lisp code can tell when the switch took place by examining the events. */
3324 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3326 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3328 if (frame
!= dpyinfo
->x_focus_frame
)
3330 /* Set this before calling other routines, so that they see
3331 the correct value of x_focus_frame. */
3332 dpyinfo
->x_focus_frame
= frame
;
3334 if (old_focus
&& old_focus
->auto_lower
)
3335 x_lower_frame (old_focus
);
3337 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3338 dpyinfo
->x_pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3340 dpyinfo
->x_pending_autoraise_frame
= NULL
;
3343 x_frame_rehighlight (dpyinfo
);
3346 /* Handle FocusIn and FocusOut state changes for FRAME.
3347 If FRAME has focus and there exists more than one frame, puts
3348 a FOCUS_IN_EVENT into *BUFP. */
3351 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3353 if (type
== FocusIn
)
3355 if (dpyinfo
->x_focus_event_frame
!= frame
)
3357 x_new_focus_frame (dpyinfo
, frame
);
3358 dpyinfo
->x_focus_event_frame
= frame
;
3360 /* Don't stop displaying the initial startup message
3361 for a switch-frame event we don't need. */
3362 /* When run as a daemon, Vterminal_frame is always NIL. */
3363 bufp
->arg
= (((NILP (Vterminal_frame
)
3364 || ! FRAME_X_P (XFRAME (Vterminal_frame
))
3365 || EQ (Fdaemonp (), Qt
))
3366 && CONSP (Vframe_list
)
3367 && !NILP (XCDR (Vframe_list
)))
3369 bufp
->kind
= FOCUS_IN_EVENT
;
3370 XSETFRAME (bufp
->frame_or_window
, frame
);
3373 frame
->output_data
.x
->focus_state
|= state
;
3376 if (FRAME_XIC (frame
))
3377 XSetICFocus (FRAME_XIC (frame
));
3380 else if (type
== FocusOut
)
3382 frame
->output_data
.x
->focus_state
&= ~state
;
3384 if (dpyinfo
->x_focus_event_frame
== frame
)
3386 dpyinfo
->x_focus_event_frame
= 0;
3387 x_new_focus_frame (dpyinfo
, 0);
3389 bufp
->kind
= FOCUS_OUT_EVENT
;
3390 XSETFRAME (bufp
->frame_or_window
, frame
);
3394 if (FRAME_XIC (frame
))
3395 XUnsetICFocus (FRAME_XIC (frame
));
3397 if (frame
->pointer_invisible
)
3398 XTtoggle_invisible_pointer (frame
, false);
3402 /* Return the Emacs frame-object corresponding to an X window.
3403 It could be the frame's main window or an icon window. */
3405 static struct frame
*
3406 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3408 Lisp_Object tail
, frame
;
3414 FOR_EACH_FRAME (tail
, frame
)
3417 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3419 if (f
->output_data
.x
->hourglass_window
== wdesc
)
3421 #ifdef USE_X_TOOLKIT
3422 if ((f
->output_data
.x
->edit_widget
3423 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
3424 /* A tooltip frame? */
3425 || (!f
->output_data
.x
->edit_widget
3426 && FRAME_X_WINDOW (f
) == wdesc
)
3427 || f
->output_data
.x
->icon_desc
== wdesc
)
3429 #else /* not USE_X_TOOLKIT */
3431 if (f
->output_data
.x
->edit_widget
)
3433 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3434 struct x_output
*x
= f
->output_data
.x
;
3435 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
3438 #endif /* USE_GTK */
3439 if (FRAME_X_WINDOW (f
) == wdesc
3440 || f
->output_data
.x
->icon_desc
== wdesc
)
3442 #endif /* not USE_X_TOOLKIT */
3447 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3449 /* Like x_window_to_frame but also compares the window with the widget's
3452 static struct frame
*
3453 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3455 Lisp_Object tail
, frame
;
3456 struct frame
*f
, *found
= NULL
;
3462 FOR_EACH_FRAME (tail
, frame
)
3467 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
3469 /* This frame matches if the window is any of its widgets. */
3470 x
= f
->output_data
.x
;
3471 if (x
->hourglass_window
== wdesc
)
3476 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3478 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
3481 if (wdesc
== XtWindow (x
->widget
)
3482 || wdesc
== XtWindow (x
->column_widget
)
3483 || wdesc
== XtWindow (x
->edit_widget
))
3485 /* Match if the window is this frame's menubar. */
3486 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3490 else if (FRAME_X_WINDOW (f
) == wdesc
)
3491 /* A tooltip frame. */
3499 /* Likewise, but consider only the menu bar widget. */
3501 static struct frame
*
3502 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
,
3503 const XEvent
*event
)
3505 Window wdesc
= event
->xany
.window
;
3506 Lisp_Object tail
, frame
;
3513 FOR_EACH_FRAME (tail
, frame
)
3516 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3518 x
= f
->output_data
.x
;
3520 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
3523 /* Match if the window is this frame's menubar. */
3524 if (x
->menubar_widget
3525 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3532 /* Return the frame whose principal (outermost) window is WDESC.
3533 If WDESC is some other (smaller) window, we return 0. */
3536 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3538 Lisp_Object tail
, frame
;
3545 FOR_EACH_FRAME (tail
, frame
)
3548 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3550 x
= f
->output_data
.x
;
3554 /* This frame matches if the window is its topmost widget. */
3556 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3557 if (gwdesc
== x
->widget
)
3560 if (wdesc
== XtWindow (x
->widget
))
3564 else if (FRAME_X_WINDOW (f
) == wdesc
)
3565 /* Tooltip frame. */
3571 #else /* !USE_X_TOOLKIT && !USE_GTK */
3573 #define x_any_window_to_frame(d, i) x_window_to_frame (d, i)
3574 #define x_top_window_to_frame(d, i) x_window_to_frame (d, i)
3576 #endif /* USE_X_TOOLKIT || USE_GTK */
3578 /* The focus may have changed. Figure out if it is a real focus change,
3579 by checking both FocusIn/Out and Enter/LeaveNotify events.
3581 Returns FOCUS_IN_EVENT event in *BUFP. */
3584 x_detect_focus_change (struct x_display_info
*dpyinfo
, struct frame
*frame
,
3585 const XEvent
*event
, struct input_event
*bufp
)
3590 switch (event
->type
)
3595 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3597 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3599 if (event
->xcrossing
.detail
!= NotifyInferior
3600 && event
->xcrossing
.focus
3601 && ! (focus_state
& FOCUS_EXPLICIT
))
3602 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3604 dpyinfo
, frame
, bufp
);
3610 x_focus_changed (event
->type
,
3611 (event
->xfocus
.detail
== NotifyPointer
?
3612 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3613 dpyinfo
, frame
, bufp
);
3617 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3619 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3620 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3621 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3628 #if !defined USE_X_TOOLKIT && !defined USE_GTK
3629 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3632 x_mouse_leave (struct x_display_info
*dpyinfo
)
3634 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3638 /* The focus has changed, or we have redirected a frame's focus to
3639 another frame (this happens when a frame uses a surrogate
3640 mini-buffer frame). Shift the highlight as appropriate.
3642 The FRAME argument doesn't necessarily have anything to do with which
3643 frame is being highlighted or un-highlighted; we only use it to find
3644 the appropriate X display info. */
3647 XTframe_rehighlight (struct frame
*frame
)
3649 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
3653 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3655 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3657 if (dpyinfo
->x_focus_frame
)
3659 dpyinfo
->x_highlight_frame
3660 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3661 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3662 : dpyinfo
->x_focus_frame
);
3663 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3665 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
3666 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3670 dpyinfo
->x_highlight_frame
= 0;
3672 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3675 frame_unhighlight (old_highlight
);
3676 if (dpyinfo
->x_highlight_frame
)
3677 frame_highlight (dpyinfo
->x_highlight_frame
);
3683 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3685 /* Initialize mode_switch_bit and modifier_meaning. */
3687 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3689 int min_code
, max_code
;
3692 XModifierKeymap
*mods
;
3694 dpyinfo
->meta_mod_mask
= 0;
3695 dpyinfo
->shift_lock_mask
= 0;
3696 dpyinfo
->alt_mod_mask
= 0;
3697 dpyinfo
->super_mod_mask
= 0;
3698 dpyinfo
->hyper_mod_mask
= 0;
3700 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3702 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3703 min_code
, max_code
- min_code
+ 1,
3705 mods
= XGetModifierMapping (dpyinfo
->display
);
3707 /* Scan the modifier table to see which modifier bits the Meta and
3708 Alt keysyms are on. */
3710 int row
, col
; /* The row and column in the modifier table. */
3711 bool found_alt_or_meta
;
3713 for (row
= 3; row
< 8; row
++)
3715 found_alt_or_meta
= false;
3716 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3718 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3720 /* Zeroes are used for filler. Skip them. */
3724 /* Are any of this keycode's keysyms a meta key? */
3728 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3730 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3736 found_alt_or_meta
= true;
3737 dpyinfo
->meta_mod_mask
|= (1 << row
);
3742 found_alt_or_meta
= true;
3743 dpyinfo
->alt_mod_mask
|= (1 << row
);
3748 if (!found_alt_or_meta
)
3749 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3750 code_col
= syms_per_code
;
3751 col
= mods
->max_keypermod
;
3756 if (!found_alt_or_meta
)
3757 dpyinfo
->super_mod_mask
|= (1 << row
);
3758 code_col
= syms_per_code
;
3759 col
= mods
->max_keypermod
;
3763 /* Ignore this if it's not on the lock modifier. */
3764 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3765 dpyinfo
->shift_lock_mask
= LockMask
;
3766 code_col
= syms_per_code
;
3767 col
= mods
->max_keypermod
;
3776 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3777 if (! dpyinfo
->meta_mod_mask
)
3779 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3780 dpyinfo
->alt_mod_mask
= 0;
3783 /* If some keys are both alt and meta,
3784 make them just meta, not alt. */
3785 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3787 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3791 XFreeModifiermap (mods
);
3794 /* Convert between the modifier bits X uses and the modifier bits
3798 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
3800 int mod_meta
= meta_modifier
;
3801 int mod_alt
= alt_modifier
;
3802 int mod_hyper
= hyper_modifier
;
3803 int mod_super
= super_modifier
;
3806 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3807 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
3808 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3809 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
3810 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3811 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
3812 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3813 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
3815 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3816 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3817 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3818 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3819 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3820 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3824 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
3826 EMACS_INT mod_meta
= meta_modifier
;
3827 EMACS_INT mod_alt
= alt_modifier
;
3828 EMACS_INT mod_hyper
= hyper_modifier
;
3829 EMACS_INT mod_super
= super_modifier
;
3833 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3834 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
3835 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3836 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
3837 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3838 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
3839 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3840 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
3843 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3844 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3845 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3846 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3847 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3848 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3851 /* Convert a keysym to its name. */
3854 x_get_keysym_name (int keysym
)
3859 value
= XKeysymToString (keysym
);
3865 /* Mouse clicks and mouse movement. Rah.
3867 Formerly, we used PointerMotionHintMask (in standard_event_mask)
3868 so that we would have to call XQueryPointer after each MotionNotify
3869 event to ask for another such event. However, this made mouse tracking
3870 slow, and there was a bug that made it eventually stop.
3872 Simply asking for MotionNotify all the time seems to work better.
3874 In order to avoid asking for motion events and then throwing most
3875 of them away or busy-polling the server for mouse positions, we ask
3876 the server for pointer motion hints. This means that we get only
3877 one event per group of mouse movements. "Groups" are delimited by
3878 other kinds of events (focus changes and button clicks, for
3879 example), or by XQueryPointer calls; when one of these happens, we
3880 get another MotionNotify event the next time the mouse moves. This
3881 is at least as efficient as getting motion events when mouse
3882 tracking is on, and I suspect only negligibly worse when tracking
3885 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3887 If the event is a button press, then note that we have grabbed
3891 construct_mouse_click (struct input_event
*result
,
3892 const XButtonEvent
*event
,
3895 /* Make the event type NO_EVENT; we'll change that when we decide
3897 result
->kind
= MOUSE_CLICK_EVENT
;
3898 result
->code
= event
->button
- Button1
;
3899 result
->timestamp
= event
->time
;
3900 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
),
3902 | (event
->type
== ButtonRelease
3906 XSETINT (result
->x
, event
->x
);
3907 XSETINT (result
->y
, event
->y
);
3908 XSETFRAME (result
->frame_or_window
, f
);
3913 /* Function to report a mouse movement to the mainstream Emacs code.
3914 The input handler calls this.
3916 We have received a mouse movement event, which is given in *event.
3917 If the mouse is over a different glyph than it was last time, tell
3918 the mainstream emacs code by setting mouse_moved. If not, ask for
3919 another motion event, so we can check again the next time it moves. */
3922 note_mouse_movement (struct frame
*frame
, const XMotionEvent
*event
)
3925 struct x_display_info
*dpyinfo
;
3927 if (!FRAME_X_OUTPUT (frame
))
3930 dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3931 dpyinfo
->last_mouse_movement_time
= event
->time
;
3932 dpyinfo
->last_mouse_motion_frame
= frame
;
3933 dpyinfo
->last_mouse_motion_x
= event
->x
;
3934 dpyinfo
->last_mouse_motion_y
= event
->y
;
3936 if (event
->window
!= FRAME_X_WINDOW (frame
))
3938 frame
->mouse_moved
= true;
3939 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3940 note_mouse_highlight (frame
, -1, -1);
3941 dpyinfo
->last_mouse_glyph_frame
= NULL
;
3946 /* Has the mouse moved off the glyph it was on at the last sighting? */
3947 r
= &dpyinfo
->last_mouse_glyph
;
3948 if (frame
!= dpyinfo
->last_mouse_glyph_frame
3949 || event
->x
< r
->x
|| event
->x
>= r
->x
+ r
->width
3950 || event
->y
< r
->y
|| event
->y
>= r
->y
+ r
->height
)
3952 frame
->mouse_moved
= true;
3953 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3954 note_mouse_highlight (frame
, event
->x
, event
->y
);
3955 /* Remember which glyph we're now on. */
3956 remember_mouse_glyph (frame
, event
->x
, event
->y
, r
);
3957 dpyinfo
->last_mouse_glyph_frame
= frame
;
3964 /* Return the current position of the mouse.
3965 *FP should be a frame which indicates which display to ask about.
3967 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3968 and *PART to the frame, window, and scroll bar part that the mouse
3969 is over. Set *X and *Y to the portion and whole of the mouse's
3970 position on the scroll bar.
3972 If the mouse movement started elsewhere, set *FP to the frame the
3973 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3976 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
3977 was at this position.
3979 Don't store anything if we don't have a valid set of values to report.
3981 This clears the mouse_moved flag, so we can wait for the next mouse
3985 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3986 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3990 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
3994 if (dpyinfo
->last_mouse_scroll_bar
&& insist
== 0)
3996 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
3998 if (bar
->horizontal
)
3999 x_horizontal_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
4001 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
4008 Window dummy_window
;
4011 Lisp_Object frame
, tail
;
4013 /* Clear the mouse-moved flag for every frame on this display. */
4014 FOR_EACH_FRAME (tail
, frame
)
4015 if (FRAME_X_P (XFRAME (frame
))
4016 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
4017 XFRAME (frame
)->mouse_moved
= false;
4019 dpyinfo
->last_mouse_scroll_bar
= NULL
;
4021 /* Figure out which root window we're on. */
4022 XQueryPointer (FRAME_X_DISPLAY (*fp
),
4023 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
4025 /* The root window which contains the pointer. */
4028 /* Trash which we can't trust if the pointer is on
4029 a different screen. */
4032 /* The position on that root window. */
4035 /* More trash we can't trust. */
4038 /* Modifier keys and pointer buttons, about which
4040 (unsigned int *) &dummy
);
4042 /* Now we have a position on the root; find the innermost window
4043 containing the pointer. */
4047 int parent_x
= 0, parent_y
= 0;
4051 /* XTranslateCoordinates can get errors if the window
4052 structure is changing at the same time this function
4053 is running. So at least we must not crash from them. */
4055 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4057 if (x_mouse_grabbed (dpyinfo
))
4059 /* If mouse was grabbed on a frame, give coords for that frame
4060 even if the mouse is now outside it. */
4061 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4067 FRAME_X_WINDOW (dpyinfo
->last_mouse_frame
),
4069 /* From-position, to-position. */
4070 root_x
, root_y
, &win_x
, &win_y
,
4074 f1
= dpyinfo
->last_mouse_frame
;
4080 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4082 /* From-window, to-window. */
4085 /* From-position, to-position. */
4086 root_x
, root_y
, &win_x
, &win_y
,
4091 if (child
== None
|| child
== win
)
4094 /* We don't wan't to know the innermost window. We
4095 want the edit window. For non-Gtk+ the innermost
4096 window is the edit window. For Gtk+ it might not
4097 be. It might be the tool bar for example. */
4098 if (x_window_to_frame (dpyinfo
, win
))
4106 /* Now we know that:
4107 win is the innermost window containing the pointer
4108 (XTC says it has no child containing the pointer),
4109 win_x and win_y are the pointer's position in it
4110 (XTC did this the last time through), and
4111 parent_x and parent_y are the pointer's position in win's parent.
4112 (They are what win_x and win_y were when win was child.
4113 If win is the root window, it has no parent, and
4114 parent_{x,y} are invalid, but that's okay, because we'll
4115 never use them in that case.) */
4118 /* We don't wan't to know the innermost window. We
4119 want the edit window. */
4120 f1
= x_window_to_frame (dpyinfo
, win
);
4122 /* Is win one of our frames? */
4123 f1
= x_any_window_to_frame (dpyinfo
, win
);
4126 #ifdef USE_X_TOOLKIT
4127 /* If we end up with the menu bar window, say it's not
4130 && f1
->output_data
.x
->menubar_widget
4131 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4133 #endif /* USE_X_TOOLKIT */
4136 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4139 x_uncatch_errors ();
4141 /* If not, is it one of our scroll bars? */
4144 struct scroll_bar
*bar
;
4146 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
, 2);
4150 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4156 if (f1
== 0 && insist
> 0)
4157 f1
= SELECTED_FRAME ();
4161 /* Ok, we found a frame. Store all the values.
4162 last_mouse_glyph is a rectangle used to reduce the
4163 generation of mouse events. To not miss any motion
4164 events, we must divide the frame into rectangles of the
4165 size of the smallest character that could be displayed
4166 on it, i.e. into the same rectangles that matrices on
4167 the frame are divided into. */
4169 /* FIXME: what if F1 is not an X frame? */
4170 dpyinfo
= FRAME_DISPLAY_INFO (f1
);
4171 remember_mouse_glyph (f1
, win_x
, win_y
, &dpyinfo
->last_mouse_glyph
);
4172 dpyinfo
->last_mouse_glyph_frame
= f1
;
4175 *part
= scroll_bar_above_handle
;
4177 XSETINT (*x
, win_x
);
4178 XSETINT (*y
, win_y
);
4179 *timestamp
= dpyinfo
->last_mouse_movement_time
;
4189 /***********************************************************************
4191 ***********************************************************************/
4193 /* Scroll bar support. */
4195 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4197 This can be called in GC, so we have to make sure to strip off mark
4200 static struct scroll_bar
*
4201 x_window_to_scroll_bar (Display
*display
, Window window_id
, int type
)
4203 Lisp_Object tail
, frame
;
4205 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4206 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4207 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4209 FOR_EACH_FRAME (tail
, frame
)
4211 Lisp_Object bar
, condemned
;
4213 if (! FRAME_X_P (XFRAME (frame
)))
4216 /* Scan this frame's scroll bar list for a scroll bar with the
4218 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4219 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4220 /* This trick allows us to search both the ordinary and
4221 condemned scroll bar lists with one loop. */
4222 ! NILP (bar
) || (bar
= condemned
,
4225 bar
= XSCROLL_BAR (bar
)->next
)
4226 if (XSCROLL_BAR (bar
)->x_window
== window_id
4227 && FRAME_X_DISPLAY (XFRAME (frame
)) == display
4229 || (type
== 1 && XSCROLL_BAR (bar
)->horizontal
)
4230 || (type
== 0 && !XSCROLL_BAR (bar
)->horizontal
)))
4231 return XSCROLL_BAR (bar
);
4238 #if defined USE_LUCID
4240 /* Return the Lucid menu bar WINDOW is part of. Return null
4241 if WINDOW is not part of a menu bar. */
4244 x_window_to_menu_bar (Window window
)
4246 Lisp_Object tail
, frame
;
4248 FOR_EACH_FRAME (tail
, frame
)
4249 if (FRAME_X_P (XFRAME (frame
)))
4251 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4253 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4259 #endif /* USE_LUCID */
4262 /************************************************************************
4264 ************************************************************************/
4266 #ifdef USE_TOOLKIT_SCROLL_BARS
4268 static void x_send_scroll_bar_event (Lisp_Object
, enum scroll_bar_part
,
4271 /* Lisp window being scrolled. Set when starting to interact with
4272 a toolkit scroll bar, reset to nil when ending the interaction. */
4274 static Lisp_Object window_being_scrolled
;
4276 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4277 that movements of 1/20 of the screen size are mapped to up/down. */
4280 /* Id of action hook installed for scroll bars. */
4282 static XtActionHookId action_hook_id
;
4283 static XtActionHookId horizontal_action_hook_id
;
4285 static Boolean xaw3d_arrow_scroll
;
4287 /* Whether the drag scrolling maintains the mouse at the top of the
4288 thumb. If not, resizing the thumb needs to be done more carefully
4289 to avoid jerkiness. */
4291 static Boolean xaw3d_pick_top
;
4293 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4294 bars are used.. The hook is responsible for detecting when
4295 the user ends an interaction with the scroll bar, and generates
4296 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4299 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4300 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4303 const char *end_action
;
4306 scroll_bar_p
= XmIsScrollBar (widget
);
4307 end_action
= "Release";
4308 #else /* !USE_MOTIF i.e. use Xaw */
4309 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4310 end_action
= "EndScroll";
4311 #endif /* USE_MOTIF */
4314 && strcmp (action_name
, end_action
) == 0
4315 && WINDOWP (window_being_scrolled
))
4318 struct scroll_bar
*bar
;
4320 x_send_scroll_bar_event (window_being_scrolled
,
4321 scroll_bar_end_scroll
, 0, 0, false);
4322 w
= XWINDOW (window_being_scrolled
);
4323 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4325 if (bar
->dragging
!= -1)
4328 /* The thumb size is incorrect while dragging: fix it. */
4329 set_vertical_scroll_bar (w
);
4331 window_being_scrolled
= Qnil
;
4332 #if defined (USE_LUCID)
4333 bar
->last_seen_part
= scroll_bar_nowhere
;
4335 /* Xt timeouts no longer needed. */
4336 toolkit_scroll_bar_interaction
= false;
4342 xt_horizontal_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4343 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4346 const char *end_action
;
4349 scroll_bar_p
= XmIsScrollBar (widget
);
4350 end_action
= "Release";
4351 #else /* !USE_MOTIF i.e. use Xaw */
4352 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4353 end_action
= "EndScroll";
4354 #endif /* USE_MOTIF */
4357 && strcmp (action_name
, end_action
) == 0
4358 && WINDOWP (window_being_scrolled
))
4361 struct scroll_bar
*bar
;
4363 x_send_scroll_bar_event (window_being_scrolled
,
4364 scroll_bar_end_scroll
, 0, 0, true);
4365 w
= XWINDOW (window_being_scrolled
);
4366 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
4368 if (bar
->dragging
!= -1)
4371 /* The thumb size is incorrect while dragging: fix it. */
4372 set_horizontal_scroll_bar (w
);
4374 window_being_scrolled
= Qnil
;
4375 #if defined (USE_LUCID)
4376 bar
->last_seen_part
= scroll_bar_nowhere
;
4378 /* Xt timeouts no longer needed. */
4379 toolkit_scroll_bar_interaction
= false;
4382 #endif /* not USE_GTK */
4384 /* Send a client message with message type Xatom_Scrollbar for a
4385 scroll action to the frame of WINDOW. PART is a value identifying
4386 the part of the scroll bar that was clicked on. PORTION is the
4387 amount to scroll of a whole of WHOLE. */
4390 x_send_scroll_bar_event (Lisp_Object window
, enum scroll_bar_part part
,
4391 int portion
, int whole
, bool horizontal
)
4394 XClientMessageEvent
*ev
= &event
.xclient
;
4395 struct window
*w
= XWINDOW (window
);
4396 struct frame
*f
= XFRAME (w
->frame
);
4397 intptr_t iw
= (intptr_t) w
;
4398 enum { BITS_PER_INTPTR
= CHAR_BIT
* sizeof iw
};
4399 verify (BITS_PER_INTPTR
<= 64);
4400 int sign_shift
= BITS_PER_INTPTR
- 32;
4404 /* Construct a ClientMessage event to send to the frame. */
4405 ev
->type
= ClientMessage
;
4406 ev
->message_type
= (horizontal
4407 ? FRAME_DISPLAY_INFO (f
)->Xatom_Horizontal_Scrollbar
4408 : FRAME_DISPLAY_INFO (f
)->Xatom_Scrollbar
);
4409 ev
->display
= FRAME_X_DISPLAY (f
);
4410 ev
->window
= FRAME_X_WINDOW (f
);
4413 /* A 32-bit X client on a 64-bit X server can pass a window pointer
4414 as-is. A 64-bit client on a 32-bit X server is in trouble
4415 because a pointer does not fit and would be truncated while
4416 passing through the server. So use two slots and hope that X12
4417 will resolve such issues someday. */
4418 ev
->data
.l
[0] = iw
>> 31 >> 1;
4419 ev
->data
.l
[1] = sign_shift
<= 0 ? iw
: iw
<< sign_shift
>> sign_shift
;
4420 ev
->data
.l
[2] = part
;
4421 ev
->data
.l
[3] = portion
;
4422 ev
->data
.l
[4] = whole
;
4424 /* Make Xt timeouts work while the scroll bar is active. */
4425 #ifdef USE_X_TOOLKIT
4426 toolkit_scroll_bar_interaction
= true;
4427 x_activate_timeout_atimer ();
4430 /* Setting the event mask to zero means that the message will
4431 be sent to the client that created the window, and if that
4432 window no longer exists, no event will be sent. */
4433 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4438 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4442 x_scroll_bar_to_input_event (const XEvent
*event
,
4443 struct input_event
*ievent
)
4445 const XClientMessageEvent
*ev
= &event
->xclient
;
4449 /* See the comment in the function above. */
4450 intptr_t iw0
= ev
->data
.l
[0];
4451 intptr_t iw1
= ev
->data
.l
[1];
4452 intptr_t iw
= (iw0
<< 31 << 1) + (iw1
& 0xffffffffu
);
4453 w
= (struct window
*) iw
;
4455 XSETWINDOW (window
, w
);
4457 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4458 ievent
->frame_or_window
= window
;
4461 ievent
->timestamp
= CurrentTime
;
4464 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4467 ievent
->part
= ev
->data
.l
[2];
4468 ievent
->x
= make_number (ev
->data
.l
[3]);
4469 ievent
->y
= make_number (ev
->data
.l
[4]);
4470 ievent
->modifiers
= 0;
4473 /* Transform a horizontal scroll bar ClientMessage EVENT to an Emacs
4474 input event in *IEVENT. */
4477 x_horizontal_scroll_bar_to_input_event (const XEvent
*event
,
4478 struct input_event
*ievent
)
4480 const XClientMessageEvent
*ev
= &event
->xclient
;
4484 /* See the comment in the function above. */
4485 intptr_t iw0
= ev
->data
.l
[0];
4486 intptr_t iw1
= ev
->data
.l
[1];
4487 intptr_t iw
= (iw0
<< 31 << 1) + (iw1
& 0xffffffffu
);
4488 w
= (struct window
*) iw
;
4490 XSETWINDOW (window
, w
);
4492 ievent
->kind
= HORIZONTAL_SCROLL_BAR_CLICK_EVENT
;
4493 ievent
->frame_or_window
= window
;
4496 ievent
->timestamp
= CurrentTime
;
4499 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4502 ievent
->part
= ev
->data
.l
[2];
4503 ievent
->x
= make_number (ev
->data
.l
[3]);
4504 ievent
->y
= make_number (ev
->data
.l
[4]);
4505 ievent
->modifiers
= 0;
4511 /* Minimum and maximum values used for Motif scroll bars. */
4513 #define XM_SB_MAX 10000000
4515 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4516 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4517 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4520 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4522 struct scroll_bar
*bar
= client_data
;
4523 XmScrollBarCallbackStruct
*cs
= call_data
;
4524 enum scroll_bar_part part
= scroll_bar_nowhere
;
4525 bool horizontal
= bar
->horizontal
;
4526 int whole
= 0, portion
= 0;
4530 case XmCR_DECREMENT
:
4532 part
= horizontal
? scroll_bar_left_arrow
: scroll_bar_up_arrow
;
4535 case XmCR_INCREMENT
:
4537 part
= horizontal
? scroll_bar_right_arrow
: scroll_bar_down_arrow
;
4540 case XmCR_PAGE_DECREMENT
:
4542 part
= horizontal
? scroll_bar_before_handle
: scroll_bar_above_handle
;
4545 case XmCR_PAGE_INCREMENT
:
4547 part
= horizontal
? scroll_bar_after_handle
: scroll_bar_below_handle
;
4552 part
= horizontal
? scroll_bar_to_leftmost
: scroll_bar_to_top
;
4555 case XmCR_TO_BOTTOM
:
4557 part
= horizontal
? scroll_bar_to_rightmost
: scroll_bar_to_bottom
;
4565 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4570 portion
= bar
->whole
* ((float)cs
->value
/ XM_SB_MAX
);
4571 whole
= bar
->whole
* ((float)(XM_SB_MAX
- slider_size
) / XM_SB_MAX
);
4572 portion
= min (portion
, whole
);
4573 part
= scroll_bar_horizontal_handle
;
4577 whole
= XM_SB_MAX
- slider_size
;
4578 portion
= min (cs
->value
, whole
);
4579 part
= scroll_bar_handle
;
4582 bar
->dragging
= cs
->value
;
4586 case XmCR_VALUE_CHANGED
:
4590 if (part
!= scroll_bar_nowhere
)
4592 window_being_scrolled
= bar
->window
;
4593 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
,
4598 #elif defined USE_GTK
4600 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4601 bar widget. DATA is a pointer to the scroll_bar structure. */
4604 xg_scroll_callback (GtkRange
*range
,
4605 GtkScrollType scroll
,
4609 int whole
= 0, portion
= 0;
4610 struct scroll_bar
*bar
= user_data
;
4611 enum scroll_bar_part part
= scroll_bar_nowhere
;
4612 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4613 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4615 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4619 case GTK_SCROLL_JUMP
:
4620 /* Buttons 1 2 or 3 must be grabbed. */
4621 if (FRAME_DISPLAY_INFO (f
)->grabbed
!= 0
4622 && FRAME_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4624 if (bar
->horizontal
)
4626 part
= scroll_bar_horizontal_handle
;
4627 whole
= (int)(gtk_adjustment_get_upper (adj
) -
4628 gtk_adjustment_get_page_size (adj
));
4629 portion
= min ((int)value
, whole
);
4630 bar
->dragging
= portion
;
4634 part
= scroll_bar_handle
;
4635 whole
= gtk_adjustment_get_upper (adj
) -
4636 gtk_adjustment_get_page_size (adj
);
4637 portion
= min ((int)value
, whole
);
4638 bar
->dragging
= portion
;
4642 case GTK_SCROLL_STEP_BACKWARD
:
4643 part
= (bar
->horizontal
4644 ? scroll_bar_left_arrow
: scroll_bar_up_arrow
);
4647 case GTK_SCROLL_STEP_FORWARD
:
4648 part
= (bar
->horizontal
4649 ? scroll_bar_right_arrow
: scroll_bar_down_arrow
);
4652 case GTK_SCROLL_PAGE_BACKWARD
:
4653 part
= (bar
->horizontal
4654 ? scroll_bar_before_handle
: scroll_bar_above_handle
);
4657 case GTK_SCROLL_PAGE_FORWARD
:
4658 part
= (bar
->horizontal
4659 ? scroll_bar_after_handle
: scroll_bar_below_handle
);
4664 if (part
!= scroll_bar_nowhere
)
4666 window_being_scrolled
= bar
->window
;
4667 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
,
4674 /* Callback for button release. Sets dragging to -1 when dragging is done. */
4677 xg_end_scroll_callback (GtkWidget
*widget
,
4678 GdkEventButton
*event
,
4681 struct scroll_bar
*bar
= user_data
;
4683 if (WINDOWP (window_being_scrolled
))
4685 x_send_scroll_bar_event (window_being_scrolled
,
4686 scroll_bar_end_scroll
, 0, 0, bar
->horizontal
);
4687 window_being_scrolled
= Qnil
;
4694 #else /* not USE_GTK and not USE_MOTIF */
4696 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4697 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4698 scroll bar struct. CALL_DATA is a pointer to a float saying where
4702 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4704 struct scroll_bar
*bar
= client_data
;
4705 float *top_addr
= call_data
;
4706 float top
= *top_addr
;
4708 int whole
, portion
, height
, width
;
4709 enum scroll_bar_part part
;
4710 bool horizontal
= bar
->horizontal
;
4715 /* Get the size of the thumb, a value between 0 and 1. */
4717 XtVaGetValues (widget
, XtNshown
, &shown
, XtNwidth
, &width
, NULL
);
4722 whole
= bar
->whole
- (shown
* bar
->whole
);
4723 portion
= min (top
* bar
->whole
, whole
);
4731 part
= scroll_bar_horizontal_handle
;
4735 /* Get the size of the thumb, a value between 0 and 1. */
4737 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4741 portion
= shown
< 1 ? top
* whole
: 0;
4743 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
4744 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4745 the bottom, so we force the scrolling whenever we see that we're
4746 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4747 we try to ensure that we always stay two pixels away from the
4749 part
= scroll_bar_down_arrow
;
4751 part
= scroll_bar_handle
;
4754 window_being_scrolled
= bar
->window
;
4755 bar
->dragging
= portion
;
4756 bar
->last_seen_part
= part
;
4757 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
, bar
->horizontal
);
4761 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4762 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4763 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4764 the scroll bar. CALL_DATA is an integer specifying the action that
4765 has taken place. Its magnitude is in the range 0..height of the
4766 scroll bar. Negative values mean scroll towards buffer start.
4767 Values < height of scroll bar mean line-wise movement. */
4770 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4772 struct scroll_bar
*bar
= client_data
;
4773 /* The position really is stored cast to a pointer. */
4774 int position
= (intptr_t) call_data
;
4775 Dimension height
, width
;
4776 enum scroll_bar_part part
;
4778 if (bar
->horizontal
)
4780 /* Get the width of the scroll bar. */
4782 XtVaGetValues (widget
, XtNwidth
, &width
, NULL
);
4785 if (eabs (position
) >= width
)
4786 part
= (position
< 0) ? scroll_bar_before_handle
: scroll_bar_after_handle
;
4788 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4789 it maps line-movement to call_data = max(5, height/20). */
4790 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, width
/ 20))
4791 part
= (position
< 0) ? scroll_bar_left_arrow
: scroll_bar_right_arrow
;
4793 part
= scroll_bar_move_ratio
;
4795 window_being_scrolled
= bar
->window
;
4797 bar
->last_seen_part
= part
;
4798 x_send_scroll_bar_event (bar
->window
, part
, position
, width
,
4804 /* Get the height of the scroll bar. */
4806 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4809 if (eabs (position
) >= height
)
4810 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4812 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4813 it maps line-movement to call_data = max(5, height/20). */
4814 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4815 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4817 part
= scroll_bar_move_ratio
;
4819 window_being_scrolled
= bar
->window
;
4821 bar
->last_seen_part
= part
;
4822 x_send_scroll_bar_event (bar
->window
, part
, position
, height
,
4827 #endif /* not USE_GTK and not USE_MOTIF */
4829 #define SCROLL_BAR_NAME "verticalScrollBar"
4830 #define SCROLL_BAR_HORIZONTAL_NAME "horizontalScrollBar"
4832 /* Create the widget for scroll bar BAR on frame F. Record the widget
4833 and X window of the scroll bar in BAR. */
4837 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4839 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4842 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4843 G_CALLBACK (xg_end_scroll_callback
),
4849 x_create_horizontal_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4851 const char *scroll_bar_name
= SCROLL_BAR_HORIZONTAL_NAME
;
4854 xg_create_horizontal_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4855 G_CALLBACK (xg_end_scroll_callback
),
4860 #else /* not USE_GTK */
4863 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4869 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4870 unsigned long pixel
;
4875 /* Set resources. Create the widget. */
4876 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4877 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4878 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4879 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4880 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4881 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4882 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4884 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4887 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4891 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4894 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4898 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4899 (char *) scroll_bar_name
, av
, ac
);
4901 /* Add one callback for everything that can happen. */
4902 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4904 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4906 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4908 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4910 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4912 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4914 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4917 /* Realize the widget. Only after that is the X window created. */
4918 XtRealizeWidget (widget
);
4920 /* Set the cursor to an arrow. I didn't find a resource to do that.
4921 And I'm wondering why it hasn't an arrow cursor by default. */
4922 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4923 f
->output_data
.x
->nontext_cursor
);
4925 #else /* !USE_MOTIF i.e. use Xaw */
4927 /* Set resources. Create the widget. The background of the
4928 Xaw3d scroll bar widget is a little bit light for my taste.
4929 We don't alter it here to let users change it according
4930 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4931 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4932 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4933 /* For smoother scrolling with Xaw3d -sm */
4934 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4936 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4939 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4943 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4946 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4950 /* Top/bottom shadow colors. */
4952 /* Allocate them, if necessary. */
4953 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4955 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4958 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4959 FRAME_X_COLORMAP (f
),
4960 &pixel
, 1.2, 0x8000))
4962 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4965 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4967 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4970 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4971 FRAME_X_COLORMAP (f
),
4972 &pixel
, 0.6, 0x4000))
4974 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4978 #ifdef XtNbeNiceToColormap
4979 /* Tell the toolkit about them. */
4980 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4981 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4982 /* We tried to allocate a color for the top/bottom shadow, and
4983 failed, so tell Xaw3d to use dithering instead. */
4984 /* But only if we have a small colormap. Xaw3d can allocate nice
4987 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4988 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4992 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4993 be more consistent with other emacs 3d colors, and since Xaw3d is
4994 not good at dealing with allocation failure. */
4996 /* This tells Xaw3d to use real colors instead of dithering for
4998 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
5001 /* Specify the colors. */
5002 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
5005 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
5008 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
5011 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
5017 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
5018 f
->output_data
.x
->edit_widget
, av
, ac
);
5021 char const *initial
= "";
5022 char const *val
= initial
;
5023 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
5024 #ifdef XtNarrowScrollbars
5025 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
5027 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
5028 if (xaw3d_arrow_scroll
|| val
== initial
)
5029 { /* ARROW_SCROLL */
5030 xaw3d_arrow_scroll
= True
;
5031 /* Isn't that just a personal preference ? --Stef */
5032 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
5036 /* Define callbacks. */
5037 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
5038 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
5041 /* Realize the widget. Only after that is the X window created. */
5042 XtRealizeWidget (widget
);
5044 #endif /* !USE_MOTIF */
5046 /* Install an action hook that lets us detect when the user
5047 finishes interacting with a scroll bar. */
5048 if (action_hook_id
== 0)
5049 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
5051 /* Remember X window and widget in the scroll bar vector. */
5052 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
5053 xwindow
= XtWindow (widget
);
5054 bar
->x_window
= xwindow
;
5056 bar
->horizontal
= false;
5062 x_create_horizontal_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
5068 const char *scroll_bar_name
= SCROLL_BAR_HORIZONTAL_NAME
;
5069 unsigned long pixel
;
5074 /* Set resources. Create the widget. */
5075 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5076 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
5077 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
5078 XtSetArg (av
[ac
], XmNorientation
, XmHORIZONTAL
); ++ac
;
5079 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_RIGHT
), ++ac
;
5080 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
5081 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
5083 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5086 XtSetArg (av
[ac
], XmNforeground
, pixel
);
5090 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5093 XtSetArg (av
[ac
], XmNbackground
, pixel
);
5097 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
5098 (char *) scroll_bar_name
, av
, ac
);
5100 /* Add one callback for everything that can happen. */
5101 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
5103 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
5105 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
5107 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
5109 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
5111 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
5113 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
5116 /* Realize the widget. Only after that is the X window created. */
5117 XtRealizeWidget (widget
);
5119 /* Set the cursor to an arrow. I didn't find a resource to do that.
5120 And I'm wondering why it hasn't an arrow cursor by default. */
5121 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
5122 f
->output_data
.x
->nontext_cursor
);
5124 #else /* !USE_MOTIF i.e. use Xaw */
5126 /* Set resources. Create the widget. The background of the
5127 Xaw3d scroll bar widget is a little bit light for my taste.
5128 We don't alter it here to let users change it according
5129 to their taste with `emacs*verticalScrollBar.background: xxx'. */
5130 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
5131 XtSetArg (av
[ac
], XtNorientation
, XtorientHorizontal
); ++ac
;
5132 /* For smoother scrolling with Xaw3d -sm */
5133 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
5135 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
5138 XtSetArg (av
[ac
], XtNforeground
, pixel
);
5142 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5145 XtSetArg (av
[ac
], XtNbackground
, pixel
);
5149 /* Top/bottom shadow colors. */
5151 /* Allocate them, if necessary. */
5152 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
5154 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5157 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
5158 FRAME_X_COLORMAP (f
),
5159 &pixel
, 1.2, 0x8000))
5161 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
5164 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
5166 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5169 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
5170 FRAME_X_COLORMAP (f
),
5171 &pixel
, 0.6, 0x4000))
5173 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
5177 #ifdef XtNbeNiceToColormap
5178 /* Tell the toolkit about them. */
5179 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
5180 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
5181 /* We tried to allocate a color for the top/bottom shadow, and
5182 failed, so tell Xaw3d to use dithering instead. */
5183 /* But only if we have a small colormap. Xaw3d can allocate nice
5186 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
5187 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
5191 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
5192 be more consistent with other emacs 3d colors, and since Xaw3d is
5193 not good at dealing with allocation failure. */
5195 /* This tells Xaw3d to use real colors instead of dithering for
5197 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
5200 /* Specify the colors. */
5201 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
5204 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
5207 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
5210 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
5216 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
5217 f
->output_data
.x
->edit_widget
, av
, ac
);
5220 char const *initial
= "";
5221 char const *val
= initial
;
5222 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
5223 #ifdef XtNarrowScrollbars
5224 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
5226 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
5227 if (xaw3d_arrow_scroll
|| val
== initial
)
5228 { /* ARROW_SCROLL */
5229 xaw3d_arrow_scroll
= True
;
5230 /* Isn't that just a personal preference ? --Stef */
5231 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
5235 /* Define callbacks. */
5236 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
5237 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
5240 /* Realize the widget. Only after that is the X window created. */
5241 XtRealizeWidget (widget
);
5243 #endif /* !USE_MOTIF */
5245 /* Install an action hook that lets us detect when the user
5246 finishes interacting with a scroll bar. */
5247 if (horizontal_action_hook_id
== 0)
5248 horizontal_action_hook_id
5249 = XtAppAddActionHook (Xt_app_con
, xt_horizontal_action_hook
, 0);
5251 /* Remember X window and widget in the scroll bar vector. */
5252 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
5253 xwindow
= XtWindow (widget
);
5254 bar
->x_window
= xwindow
;
5256 bar
->horizontal
= true;
5260 #endif /* not USE_GTK */
5263 /* Set the thumb size and position of scroll bar BAR. We are currently
5264 displaying PORTION out of a whole WHOLE, and our position POSITION. */
5268 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
5270 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5274 x_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
5276 xg_set_toolkit_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
5279 #else /* not USE_GTK */
5281 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
5284 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5285 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5292 if (scroll_bar_adjust_thumb_portion_p
)
5294 /* We use an estimate of 30 chars per line rather than the real
5295 `portion' value. This has the disadvantage that the thumb size
5296 is not very representative, but it makes our life a lot easier.
5297 Otherwise, we have to constantly adjust the thumb size, which
5298 we can't always do quickly enough: while dragging, the size of
5299 the thumb might prevent the user from dragging the thumb all the
5300 way to the end. but Motif and some versions of Xaw3d don't allow
5301 updating the thumb size while dragging. Also, even if we can update
5302 its size, the update will often happen too late.
5303 If you don't believe it, check out revision 1.650 of xterm.c to see
5304 what hoops we were going through and the still poor behavior we got. */
5305 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
5306 /* When the thumb is at the bottom, position == whole.
5307 So we need to increase `whole' to make space for the thumb. */
5315 top
= (float) position
/ whole
;
5316 shown
= (float) portion
/ whole
;
5319 if (bar
->dragging
== -1)
5323 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
5324 is the scroll bar's maximum and MIN is the scroll bar's minimum
5326 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
5328 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
5329 value
= top
* XM_SB_MAX
;
5330 value
= min (value
, XM_SB_MAX
- size
);
5332 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
5334 #else /* !USE_MOTIF i.e. use Xaw */
5340 top
= (float) position
/ whole
;
5341 shown
= (float) portion
/ whole
;
5345 float old_top
, old_shown
;
5347 XtVaGetValues (widget
,
5348 XtNtopOfThumb
, &old_top
,
5349 XtNshown
, &old_shown
,
5353 /* Massage the top+shown values. */
5354 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
5355 top
= max (0, min (1, top
));
5358 #if ! defined (HAVE_XAW3D)
5359 /* With Xaw, 'top' values too closer to 1.0 may
5360 cause the thumb to disappear. Fix that. */
5361 top
= min (top
, 0.99f
);
5363 /* Keep two pixels available for moving the thumb down. */
5364 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
5365 #if ! defined (HAVE_XAW3D)
5366 /* Likewise with too small 'shown'. */
5367 shown
= max (shown
, 0.01f
);
5370 /* If the call to XawScrollbarSetThumb below doesn't seem to
5371 work, check that 'NARROWPROTO' is defined in src/config.h.
5372 If this is not so, most likely you need to fix configure. */
5373 if (top
!= old_top
|| shown
!= old_shown
)
5375 if (bar
->dragging
== -1)
5376 XawScrollbarSetThumb (widget
, top
, shown
);
5379 /* Try to make the scrolling a tad smoother. */
5380 if (!xaw3d_pick_top
)
5381 shown
= min (shown
, old_shown
);
5383 XawScrollbarSetThumb (widget
, top
, shown
);
5387 #endif /* !USE_MOTIF */
5393 x_set_toolkit_horizontal_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
5396 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5397 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5404 shown
= (float) portion
/ whole
;
5405 top
= (float) position
/ (whole
- portion
);
5407 int size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
5408 int value
= clip_to_bounds (0, top
* (XM_SB_MAX
- size
), XM_SB_MAX
- size
);
5410 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
5412 #else /* !USE_MOTIF i.e. use Xaw */
5418 top
= (float) position
/ whole
;
5419 shown
= (float) portion
/ whole
;
5423 float old_top
, old_shown
;
5425 XtVaGetValues (widget
,
5426 XtNtopOfThumb
, &old_top
,
5427 XtNshown
, &old_shown
,
5432 /* Massage the top+shown values. */
5433 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
5434 top
= max (0, min (1, top
));
5437 #if ! defined (HAVE_XAW3D)
5438 /* With Xaw, 'top' values too closer to 1.0 may
5439 cause the thumb to disappear. Fix that. */
5440 top
= min (top
, 0.99f
);
5442 /* Keep two pixels available for moving the thumb down. */
5443 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
5444 #if ! defined (HAVE_XAW3D)
5445 /* Likewise with too small 'shown'. */
5446 shown
= max (shown
, 0.01f
);
5450 /* If the call to XawScrollbarSetThumb below doesn't seem to
5451 work, check that 'NARROWPROTO' is defined in src/config.h.
5452 If this is not so, most likely you need to fix configure. */
5453 XawScrollbarSetThumb (widget
, top
, shown
);
5455 if (top
!= old_top
|| shown
!= old_shown
)
5457 if (bar
->dragging
== -1)
5458 XawScrollbarSetThumb (widget
, top
, shown
);
5461 /* Try to make the scrolling a tad smoother. */
5462 if (!xaw3d_pick_top
)
5463 shown
= min (shown
, old_shown
);
5465 XawScrollbarSetThumb (widget
, top
, shown
);
5470 #endif /* !USE_MOTIF */
5474 #endif /* not USE_GTK */
5476 #endif /* USE_TOOLKIT_SCROLL_BARS */
5480 /************************************************************************
5481 Scroll bars, general
5482 ************************************************************************/
5484 /* Create a scroll bar and return the scroll bar vector for it. W is
5485 the Emacs window on which to create the scroll bar. TOP, LEFT,
5486 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
5489 static struct scroll_bar
*
5490 x_scroll_bar_create (struct window
*w
, int top
, int left
,
5491 int width
, int height
, bool horizontal
)
5493 struct frame
*f
= XFRAME (w
->frame
);
5494 struct scroll_bar
*bar
5495 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
5500 #ifdef USE_TOOLKIT_SCROLL_BARS
5502 x_create_horizontal_toolkit_scroll_bar (f
, bar
);
5504 x_create_toolkit_scroll_bar (f
, bar
);
5505 #else /* not USE_TOOLKIT_SCROLL_BARS */
5507 XSetWindowAttributes a
;
5511 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5512 if (a
.background_pixel
== -1)
5513 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5515 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
5516 | ButtonMotionMask
| PointerMotionHintMask
5518 a
.cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
5520 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
5522 /* Clear the area of W that will serve as a scroll bar. This is
5523 for the case that a window has been split horizontally. In
5524 this case, no clear_frame is generated to reduce flickering. */
5525 if (width
> 0 && window_box_height (w
) > 0)
5526 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5527 left
, top
, width
, window_box_height (w
));
5529 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5530 /* Position and size of scroll bar. */
5531 left
, top
, width
, height
,
5532 /* Border width, depth, class, and visual. */
5539 bar
->x_window
= window
;
5541 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5543 XSETWINDOW (bar
->window
, w
);
5547 bar
->height
= height
;
5551 bar
->horizontal
= horizontal
;
5552 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
5553 bar
->last_seen_part
= scroll_bar_nowhere
;
5556 /* Add bar to its frame's list of scroll bars. */
5557 bar
->next
= FRAME_SCROLL_BARS (f
);
5559 XSETVECTOR (barobj
, bar
);
5560 fset_scroll_bars (f
, barobj
);
5561 if (!NILP (bar
->next
))
5562 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5564 /* Map the window/widget. */
5565 #ifdef USE_TOOLKIT_SCROLL_BARS
5569 xg_update_horizontal_scrollbar_pos (f
, bar
->x_window
, top
,
5570 left
, width
, max (height
, 1));
5572 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
5573 left
, width
, max (height
, 1));
5574 #else /* not USE_GTK */
5575 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5576 XtConfigureWidget (scroll_bar
, left
, top
, width
, max (height
, 1), 0);
5577 XtMapWidget (scroll_bar
);
5578 #endif /* not USE_GTK */
5580 #else /* not USE_TOOLKIT_SCROLL_BARS */
5581 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5582 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5589 #ifndef USE_TOOLKIT_SCROLL_BARS
5591 /* Draw BAR's handle in the proper position.
5593 If the handle is already drawn from START to END, don't bother
5594 redrawing it, unless REBUILD; in that case, always
5595 redraw it. (REBUILD is handy for drawing the handle after expose
5598 Normally, we want to constrain the start and end of the handle to
5599 fit inside its rectangle, but if the user is dragging the scroll
5600 bar handle, we want to let them drag it down all the way, so that
5601 the bar's top is as far down as it goes; otherwise, there's no way
5602 to move to the very end of the buffer. */
5605 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
,
5608 bool dragging
= bar
->dragging
!= -1;
5609 Window w
= bar
->x_window
;
5610 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5611 GC gc
= f
->output_data
.x
->normal_gc
;
5613 /* If the display is already accurate, do nothing. */
5615 && start
== bar
->start
5622 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5623 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5624 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5626 /* Make sure the values are reasonable, and try to preserve
5627 the distance between start and end. */
5629 int length
= end
- start
;
5633 else if (start
> top_range
)
5635 end
= start
+ length
;
5639 else if (end
> top_range
&& ! dragging
)
5643 /* Store the adjusted setting in the scroll bar. */
5647 /* Clip the end position, just for display. */
5648 if (end
> top_range
)
5651 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5652 below top positions, to make sure the handle is always at least
5653 that many pixels tall. */
5654 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5656 /* Draw the empty space above the handle. Note that we can't clear
5657 zero-height areas; that means "clear to end of window." */
5658 if ((inside_width
> 0) && (start
> 0))
5659 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5660 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5661 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5662 inside_width
, start
);
5664 /* Change to proper foreground color if one is specified. */
5665 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5666 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5667 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5669 /* Draw the handle itself. */
5670 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5671 /* x, y, width, height */
5672 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5673 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5674 inside_width
, end
- start
);
5676 /* Restore the foreground color of the GC if we changed it above. */
5677 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5678 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5679 FRAME_FOREGROUND_PIXEL (f
));
5681 /* Draw the empty space below the handle. Note that we can't
5682 clear zero-height areas; that means "clear to end of window." */
5683 if ((inside_width
> 0) && (end
< inside_height
))
5684 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5685 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5686 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5687 inside_width
, inside_height
- end
);
5693 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5695 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5699 x_scroll_bar_remove (struct scroll_bar
*bar
)
5701 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5704 #ifdef USE_TOOLKIT_SCROLL_BARS
5706 xg_remove_scroll_bar (f
, bar
->x_window
);
5707 #else /* not USE_GTK */
5708 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5709 #endif /* not USE_GTK */
5711 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5714 /* Dissociate this scroll bar from its window. */
5715 if (bar
->horizontal
)
5716 wset_horizontal_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5718 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5724 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5725 that we are displaying PORTION characters out of a total of WHOLE
5726 characters, starting at POSITION. If WINDOW has no scroll bar,
5730 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5732 struct frame
*f
= XFRAME (w
->frame
);
5734 struct scroll_bar
*bar
;
5735 int top
, height
, left
, width
;
5736 int window_y
, window_height
;
5738 /* Get window dimensions. */
5739 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
5741 height
= window_height
;
5742 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5743 width
= WINDOW_SCROLL_BAR_AREA_WIDTH (w
);
5745 /* Does the scroll bar exist yet? */
5746 if (NILP (w
->vertical_scroll_bar
))
5748 if (width
> 0 && height
> 0)
5751 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5752 left
, top
, width
, height
);
5756 bar
= x_scroll_bar_create (w
, top
, left
, width
, max (height
, 1), false);
5760 /* It may just need to be moved and resized. */
5761 unsigned int mask
= 0;
5763 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5767 if (left
!= bar
->left
)
5769 if (top
!= bar
->top
)
5771 if (width
!= bar
->width
)
5773 if (height
!= bar
->height
)
5776 #ifdef USE_TOOLKIT_SCROLL_BARS
5778 /* Move/size the scroll bar widget. */
5781 /* Since toolkit scroll bars are smaller than the space reserved
5782 for them on the frame, we have to clear "under" them. */
5783 if (width
> 0 && height
> 0)
5784 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5785 left
, top
, width
, height
);
5787 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
5788 left
, width
, max (height
, 1));
5789 #else /* not USE_GTK */
5790 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5791 left
, top
, width
, max (height
, 1), 0);
5792 #endif /* not USE_GTK */
5794 #else /* not USE_TOOLKIT_SCROLL_BARS */
5796 /* Move/size the scroll bar window. */
5805 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5809 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5811 /* Remember new settings. */
5815 bar
->height
= height
;
5820 #ifdef USE_TOOLKIT_SCROLL_BARS
5821 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5822 #else /* not USE_TOOLKIT_SCROLL_BARS */
5823 /* Set the scroll bar's current state, unless we're currently being
5825 if (bar
->dragging
== -1)
5827 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5830 x_scroll_bar_set_handle (bar
, 0, top_range
, false);
5833 int start
= ((double) position
* top_range
) / whole
;
5834 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5835 x_scroll_bar_set_handle (bar
, start
, end
, false);
5838 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5840 XSETVECTOR (barobj
, bar
);
5841 wset_vertical_scroll_bar (w
, barobj
);
5846 XTset_horizontal_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5848 struct frame
*f
= XFRAME (w
->frame
);
5850 struct scroll_bar
*bar
;
5851 int top
, height
, left
, width
;
5852 int window_x
, window_width
;
5853 int pixel_width
= WINDOW_PIXEL_WIDTH (w
);
5855 /* Get window dimensions. */
5856 window_box (w
, ANY_AREA
, &window_x
, 0, &window_width
, 0);
5858 width
= window_width
;
5859 top
= WINDOW_SCROLL_BAR_AREA_Y (w
);
5860 height
= WINDOW_SCROLL_BAR_AREA_HEIGHT (w
);
5862 /* Does the scroll bar exist yet? */
5863 if (NILP (w
->horizontal_scroll_bar
))
5865 if (width
> 0 && height
> 0)
5869 /* Clear also part between window_width and
5870 WINDOW_PIXEL_WIDTH. */
5871 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5872 left
, top
, pixel_width
, height
);
5876 bar
= x_scroll_bar_create (w
, top
, left
, width
, height
, true);
5880 /* It may just need to be moved and resized. */
5881 unsigned int mask
= 0;
5883 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
5887 if (left
!= bar
->left
)
5889 if (top
!= bar
->top
)
5891 if (width
!= bar
->width
)
5893 if (height
!= bar
->height
)
5896 #ifdef USE_TOOLKIT_SCROLL_BARS
5897 /* Move/size the scroll bar widget. */
5900 /* Since toolkit scroll bars are smaller than the space reserved
5901 for them on the frame, we have to clear "under" them. */
5902 if (width
> 0 && height
> 0)
5903 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5904 WINDOW_LEFT_EDGE_X (w
), top
,
5905 pixel_width
- WINDOW_RIGHT_DIVIDER_WIDTH (w
), height
);
5907 xg_update_horizontal_scrollbar_pos (f
, bar
->x_window
, top
, left
,
5909 #else /* not USE_GTK */
5910 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5911 left
, top
, width
, height
, 0);
5912 #endif /* not USE_GTK */
5914 #else /* not USE_TOOLKIT_SCROLL_BARS */
5916 /* Clear areas not covered by the scroll bar because it's not as
5917 wide as the area reserved for it. This makes sure a
5918 previous mode line display is cleared after C-x 2 C-x 1, for
5921 int area_height
= WINDOW_CONFIG_SCROLL_BAR_HEIGHT (w
);
5922 int rest
= area_height
- height
;
5923 if (rest
> 0 && width
> 0)
5924 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5925 left
, top
, width
, rest
);
5928 /* Move/size the scroll bar window. */
5937 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5941 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5943 /* Remember new settings. */
5947 bar
->height
= height
;
5952 #ifdef USE_TOOLKIT_SCROLL_BARS
5953 x_set_toolkit_horizontal_scroll_bar_thumb (bar
, portion
, position
, whole
);
5954 #else /* not USE_TOOLKIT_SCROLL_BARS */
5955 /* Set the scroll bar's current state, unless we're currently being
5957 if (bar
->dragging
== -1)
5959 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, width
);
5962 x_scroll_bar_set_handle (bar
, 0, left_range
, false);
5965 int start
= ((double) position
* left_range
) / whole
;
5966 int end
= ((double) (position
+ portion
) * left_range
) / whole
;
5967 x_scroll_bar_set_handle (bar
, start
, end
, false);
5970 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5972 XSETVECTOR (barobj
, bar
);
5973 wset_horizontal_scroll_bar (w
, barobj
);
5977 /* The following three hooks are used when we're doing a thorough
5978 redisplay of the frame. We don't explicitly know which scroll bars
5979 are going to be deleted, because keeping track of when windows go
5980 away is a real pain - "Can you say set-window-configuration, boys
5981 and girls?" Instead, we just assert at the beginning of redisplay
5982 that *all* scroll bars are to be removed, and then save a scroll bar
5983 from the fiery pit when we actually redisplay its window. */
5985 /* Arrange for all scroll bars on FRAME to be removed at the next call
5986 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5987 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5990 XTcondemn_scroll_bars (struct frame
*frame
)
5992 if (!NILP (FRAME_SCROLL_BARS (frame
)))
5994 if (!NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5996 /* Prepend scrollbars to already condemned ones. */
5997 Lisp_Object last
= FRAME_SCROLL_BARS (frame
);
5999 while (!NILP (XSCROLL_BAR (last
)->next
))
6000 last
= XSCROLL_BAR (last
)->next
;
6002 XSCROLL_BAR (last
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
6003 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= last
;
6006 fset_condemned_scroll_bars (frame
, FRAME_SCROLL_BARS (frame
));
6007 fset_scroll_bars (frame
, Qnil
);
6012 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
6013 Note that WINDOW isn't necessarily condemned at all. */
6016 XTredeem_scroll_bar (struct window
*w
)
6018 struct scroll_bar
*bar
;
6022 /* We can't redeem this window's scroll bar if it doesn't have one. */
6023 if (NILP (w
->vertical_scroll_bar
) && NILP (w
->horizontal_scroll_bar
))
6026 if (!NILP (w
->vertical_scroll_bar
) && WINDOW_HAS_VERTICAL_SCROLL_BAR (w
))
6028 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
6029 /* Unlink it from the condemned list. */
6030 f
= XFRAME (WINDOW_FRAME (w
));
6031 if (NILP (bar
->prev
))
6033 /* If the prev pointer is nil, it must be the first in one of
6035 if (EQ (FRAME_SCROLL_BARS (f
), w
->vertical_scroll_bar
))
6036 /* It's not condemned. Everything's fine. */
6038 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
6039 w
->vertical_scroll_bar
))
6040 fset_condemned_scroll_bars (f
, bar
->next
);
6042 /* If its prev pointer is nil, it must be at the front of
6043 one or the other! */
6047 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
6049 if (! NILP (bar
->next
))
6050 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
6052 bar
->next
= FRAME_SCROLL_BARS (f
);
6054 XSETVECTOR (barobj
, bar
);
6055 fset_scroll_bars (f
, barobj
);
6056 if (! NILP (bar
->next
))
6057 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6061 if (!NILP (w
->horizontal_scroll_bar
) && WINDOW_HAS_HORIZONTAL_SCROLL_BAR (w
))
6063 bar
= XSCROLL_BAR (w
->horizontal_scroll_bar
);
6064 /* Unlink it from the condemned list. */
6065 f
= XFRAME (WINDOW_FRAME (w
));
6066 if (NILP (bar
->prev
))
6068 /* If the prev pointer is nil, it must be the first in one of
6070 if (EQ (FRAME_SCROLL_BARS (f
), w
->horizontal_scroll_bar
))
6071 /* It's not condemned. Everything's fine. */
6073 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
6074 w
->horizontal_scroll_bar
))
6075 fset_condemned_scroll_bars (f
, bar
->next
);
6077 /* If its prev pointer is nil, it must be at the front of
6078 one or the other! */
6082 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
6084 if (! NILP (bar
->next
))
6085 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
6087 bar
->next
= FRAME_SCROLL_BARS (f
);
6089 XSETVECTOR (barobj
, bar
);
6090 fset_scroll_bars (f
, barobj
);
6091 if (! NILP (bar
->next
))
6092 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
6096 /* Remove all scroll bars on FRAME that haven't been saved since the
6097 last call to `*condemn_scroll_bars_hook'. */
6100 XTjudge_scroll_bars (struct frame
*f
)
6102 Lisp_Object bar
, next
;
6104 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
6106 /* Clear out the condemned list now so we won't try to process any
6107 more events on the hapless scroll bars. */
6108 fset_condemned_scroll_bars (f
, Qnil
);
6110 for (; ! NILP (bar
); bar
= next
)
6112 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
6114 x_scroll_bar_remove (b
);
6117 b
->next
= b
->prev
= Qnil
;
6120 /* Now there should be no references to the condemned scroll bars,
6121 and they should get garbage-collected. */
6125 #ifndef USE_TOOLKIT_SCROLL_BARS
6126 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
6127 is a no-op when using toolkit scroll bars.
6129 This may be called from a signal handler, so we have to ignore GC
6133 x_scroll_bar_expose (struct scroll_bar
*bar
, const XEvent
*event
)
6135 Window w
= bar
->x_window
;
6136 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6137 GC gc
= f
->output_data
.x
->normal_gc
;
6141 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, true);
6143 /* Switch to scroll bar foreground color. */
6144 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
6145 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
6146 f
->output_data
.x
->scroll_bar_foreground_pixel
);
6148 /* Draw a one-pixel border just inside the edges of the scroll bar. */
6149 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
6150 /* x, y, width, height */
6151 0, 0, bar
->width
- 1, bar
->height
- 1);
6153 /* Restore the foreground color of the GC if we changed it above. */
6154 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
6155 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
6156 FRAME_FOREGROUND_PIXEL (f
));
6161 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6163 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
6164 is set to something other than NO_EVENT, it is enqueued.
6166 This may be called from a signal handler, so we have to ignore GC
6171 x_scroll_bar_handle_click (struct scroll_bar
*bar
,
6172 const XEvent
*event
,
6173 struct input_event
*emacs_event
)
6175 if (! WINDOWP (bar
->window
))
6178 emacs_event
->kind
= (bar
->horizontal
6179 ? HORIZONTAL_SCROLL_BAR_CLICK_EVENT
6180 : SCROLL_BAR_CLICK_EVENT
);
6181 emacs_event
->code
= event
->xbutton
.button
- Button1
;
6182 emacs_event
->modifiers
6183 = (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO
6184 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
6185 event
->xbutton
.state
)
6186 | (event
->type
== ButtonRelease
6189 emacs_event
->frame_or_window
= bar
->window
;
6190 emacs_event
->arg
= Qnil
;
6191 emacs_event
->timestamp
= event
->xbutton
.time
;
6192 if (bar
->horizontal
)
6195 = HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
6196 int x
= event
->xbutton
.x
- HORIZONTAL_SCROLL_BAR_LEFT_BORDER
;
6199 if (x
> left_range
) x
= left_range
;
6202 emacs_event
->part
= scroll_bar_before_handle
;
6203 else if (x
< bar
->end
+ HORIZONTAL_SCROLL_BAR_MIN_HANDLE
)
6204 emacs_event
->part
= scroll_bar_horizontal_handle
;
6206 emacs_event
->part
= scroll_bar_after_handle
;
6208 #ifndef USE_TOOLKIT_SCROLL_BARS
6209 /* If the user has released the handle, set it to its final position. */
6210 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
6212 int new_start
= - bar
->dragging
;
6213 int new_end
= new_start
+ bar
->end
- bar
->start
;
6215 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
6220 XSETINT (emacs_event
->x
, left_range
);
6221 XSETINT (emacs_event
->y
, x
);
6226 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
6227 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
6230 if (y
> top_range
) y
= top_range
;
6233 emacs_event
->part
= scroll_bar_above_handle
;
6234 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
6235 emacs_event
->part
= scroll_bar_handle
;
6237 emacs_event
->part
= scroll_bar_below_handle
;
6239 #ifndef USE_TOOLKIT_SCROLL_BARS
6240 /* If the user has released the handle, set it to its final position. */
6241 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
6243 int new_start
= y
- bar
->dragging
;
6244 int new_end
= new_start
+ bar
->end
- bar
->start
;
6246 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
6251 XSETINT (emacs_event
->x
, y
);
6252 XSETINT (emacs_event
->y
, top_range
);
6256 #ifndef USE_TOOLKIT_SCROLL_BARS
6258 /* Handle some mouse motion while someone is dragging the scroll bar.
6260 This may be called from a signal handler, so we have to ignore GC
6264 x_scroll_bar_note_movement (struct scroll_bar
*bar
,
6265 const XMotionEvent
*event
)
6267 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
6268 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
6270 dpyinfo
->last_mouse_movement_time
= event
->time
;
6271 dpyinfo
->last_mouse_scroll_bar
= bar
;
6272 f
->mouse_moved
= true;
6274 /* If we're dragging the bar, display it. */
6275 if (bar
->dragging
!= -1)
6277 /* Where should the handle be now? */
6278 int new_start
= event
->y
- bar
->dragging
;
6280 if (new_start
!= bar
->start
)
6282 int new_end
= new_start
+ bar
->end
- bar
->start
;
6284 x_scroll_bar_set_handle (bar
, new_start
, new_end
, false);
6289 #endif /* !USE_TOOLKIT_SCROLL_BARS */
6291 /* Return information to the user about the current position of the mouse
6292 on the scroll bar. */
6295 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
6296 enum scroll_bar_part
*part
, Lisp_Object
*x
,
6297 Lisp_Object
*y
, Time
*timestamp
)
6299 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
6300 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
6301 Window w
= bar
->x_window
;
6302 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6304 Window dummy_window
;
6306 unsigned int dummy_mask
;
6310 /* Get the mouse's position relative to the scroll bar window, and
6312 if (XQueryPointer (FRAME_X_DISPLAY (f
), w
,
6314 /* Root, child, root x and root y. */
6315 &dummy_window
, &dummy_window
,
6316 &dummy_coord
, &dummy_coord
,
6318 /* Position relative to scroll bar. */
6321 /* Mouse buttons and modifier keys. */
6324 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
6326 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
6328 if (bar
->dragging
!= -1)
6329 win_y
-= bar
->dragging
;
6333 if (win_y
> top_range
)
6337 *bar_window
= bar
->window
;
6339 if (bar
->dragging
!= -1)
6340 *part
= scroll_bar_handle
;
6341 else if (win_y
< bar
->start
)
6342 *part
= scroll_bar_above_handle
;
6343 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
6344 *part
= scroll_bar_handle
;
6346 *part
= scroll_bar_below_handle
;
6348 XSETINT (*x
, win_y
);
6349 XSETINT (*y
, top_range
);
6351 f
->mouse_moved
= false;
6352 dpyinfo
->last_mouse_scroll_bar
= NULL
;
6353 *timestamp
= dpyinfo
->last_mouse_movement_time
;
6360 /* Return information to the user about the current position of the mouse
6361 on the scroll bar. */
6364 x_horizontal_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
6365 enum scroll_bar_part
*part
, Lisp_Object
*x
,
6366 Lisp_Object
*y
, Time
*timestamp
)
6368 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
6369 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
6370 Window w
= bar
->x_window
;
6371 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
6373 Window dummy_window
;
6375 unsigned int dummy_mask
;
6379 /* Get the mouse's position relative to the scroll bar window, and
6381 if (XQueryPointer (FRAME_X_DISPLAY (f
), w
,
6383 /* Root, child, root x and root y. */
6384 &dummy_window
, &dummy_window
,
6385 &dummy_coord
, &dummy_coord
,
6387 /* Position relative to scroll bar. */
6390 /* Mouse buttons and modifier keys. */
6393 int left_range
= HORIZONTAL_SCROLL_BAR_LEFT_RANGE (f
, bar
->width
);
6395 win_x
-= HORIZONTAL_SCROLL_BAR_LEFT_BORDER
;
6397 if (bar
->dragging
!= -1)
6398 win_x
-= bar
->dragging
;
6402 if (win_x
> left_range
)
6406 *bar_window
= bar
->window
;
6408 if (bar
->dragging
!= -1)
6409 *part
= scroll_bar_horizontal_handle
;
6410 else if (win_x
< bar
->start
)
6411 *part
= scroll_bar_before_handle
;
6412 else if (win_x
< bar
->end
+ HORIZONTAL_SCROLL_BAR_MIN_HANDLE
)
6413 *part
= scroll_bar_handle
;
6415 *part
= scroll_bar_after_handle
;
6417 XSETINT (*y
, win_x
);
6418 XSETINT (*x
, left_range
);
6420 f
->mouse_moved
= false;
6421 dpyinfo
->last_mouse_scroll_bar
= NULL
;
6422 *timestamp
= dpyinfo
->last_mouse_movement_time
;
6429 /* The screen has been cleared so we may have changed foreground or
6430 background colors, and the scroll bars may need to be redrawn.
6431 Clear out the scroll bars, and ask for expose events, so we can
6435 x_scroll_bar_clear (struct frame
*f
)
6437 #ifndef USE_TOOLKIT_SCROLL_BARS
6440 /* We can have scroll bars even if this is 0,
6441 if we just turned off scroll bar mode.
6442 But in that case we should not clear them. */
6443 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
6444 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
6445 bar
= XSCROLL_BAR (bar
)->next
)
6446 XClearArea (FRAME_X_DISPLAY (f
),
6447 XSCROLL_BAR (bar
)->x_window
,
6449 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6452 #ifdef ENABLE_CHECKING
6454 /* Record the last 100 characters stored
6455 to help debug the loss-of-chars-during-GC problem. */
6457 static int temp_index
;
6458 static short temp_buffer
[100];
6460 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
6461 if (temp_index == ARRAYELTS (temp_buffer)) \
6463 temp_buffer[temp_index++] = (keysym)
6465 #else /* not ENABLE_CHECKING */
6467 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
6469 #endif /* ENABLE_CHECKING */
6471 /* Set this to nonzero to fake an "X I/O error"
6472 on a particular display. */
6474 static struct x_display_info
*XTread_socket_fake_io_error
;
6476 /* When we find no input here, we occasionally do a no-op command
6477 to verify that the X server is still running and we can still talk with it.
6478 We try all the open displays, one by one.
6479 This variable is used for cycling thru the displays. */
6481 static struct x_display_info
*next_noop_dpyinfo
;
6490 /* Filter events for the current X input method.
6491 DPYINFO is the display this event is for.
6492 EVENT is the X event to filter.
6494 Returns non-zero if the event was filtered, caller shall not process
6496 Returns zero if event is wasn't filtered. */
6500 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
6502 /* XFilterEvent returns non-zero if the input method has
6503 consumed the event. We pass the frame's X window to
6504 XFilterEvent because that's the one for which the IC
6507 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
6508 event
->xclient
.window
);
6510 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
6515 static int current_count
;
6516 static int current_finish
;
6517 static struct input_event
*current_hold_quit
;
6519 /* This is the filter function invoked by the GTK event loop.
6520 It is invoked before the XEvent is translated to a GdkEvent,
6521 so we have a chance to act on the event before GTK. */
6522 static GdkFilterReturn
6523 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
6525 XEvent
*xev
= (XEvent
*) gxev
;
6528 if (current_count
>= 0)
6530 struct x_display_info
*dpyinfo
;
6532 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
6535 /* Filter events for the current X input method.
6536 GTK calls XFilterEvent but not for key press and release,
6537 so we do it here. */
6538 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
6540 && x_filter_event (dpyinfo
, xev
))
6543 return GDK_FILTER_REMOVE
;
6548 current_finish
= X_EVENT_NORMAL
;
6551 += handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
6555 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
6559 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
6560 return GDK_FILTER_REMOVE
;
6562 return GDK_FILTER_CONTINUE
;
6564 #endif /* USE_GTK */
6567 static void xembed_send_message (struct frame
*f
, Time
,
6568 enum xembed_message
,
6569 long detail
, long data1
, long data2
);
6572 x_net_wm_state (struct frame
*f
, Window window
)
6574 int value
= FULLSCREEN_NONE
;
6575 Lisp_Object lval
= Qnil
;
6576 bool sticky
= false;
6578 get_current_wm_state (f
, window
, &value
, &sticky
);
6582 case FULLSCREEN_WIDTH
:
6585 case FULLSCREEN_HEIGHT
:
6588 case FULLSCREEN_BOTH
:
6591 case FULLSCREEN_MAXIMIZED
:
6596 store_frame_param (f
, Qfullscreen
, lval
);
6597 /** store_frame_param (f, Qsticky, sticky ? Qt : Qnil); **/
6600 /* Handles the XEvent EVENT on display DPYINFO.
6602 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
6603 *FINISH is zero if caller should continue reading events.
6604 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
6605 *EVENT is unchanged unless we're processing KeyPress event.
6607 We return the number of characters stored into the buffer. */
6610 handle_one_xevent (struct x_display_info
*dpyinfo
,
6611 const XEvent
*event
,
6612 int *finish
, struct input_event
*hold_quit
)
6615 struct input_event ie
;
6616 struct selection_input_event sie
;
6620 ptrdiff_t nbytes
= 0;
6621 struct frame
*any
, *f
= NULL
;
6622 struct coding_system coding
;
6623 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
6624 /* This holds the state XLookupString needs to implement dead keys
6625 and other tricks known as "compose processing". _X Window System_
6626 says that a portable program can't use this, but Stephen Gildea assures
6627 me that letting the compiler initialize it to zeros will work okay. */
6628 static XComposeStatus compose_status
;
6632 *finish
= X_EVENT_NORMAL
;
6634 EVENT_INIT (inev
.ie
);
6635 inev
.ie
.kind
= NO_EVENT
;
6638 any
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
6640 if (any
&& any
->wait_event_type
== event
->type
)
6641 any
->wait_event_type
= 0; /* Indicates we got it. */
6643 switch (event
->type
)
6647 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_protocols
6648 && event
->xclient
.format
== 32)
6650 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_take_focus
)
6652 /* Use the value returned by x_any_window_to_frame
6653 because this could be the shell widget window
6654 if the frame has no title bar. */
6657 /* Not quite sure this is needed -pd */
6658 if (f
&& FRAME_XIC (f
))
6659 XSetICFocus (FRAME_XIC (f
));
6662 /* Emacs sets WM hints whose `input' field is `true'. This
6663 instructs the WM to set the input focus automatically for
6664 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
6665 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
6666 it has set the focus. So, XSetInputFocus below is not
6669 The call to XSetInputFocus below has also caused trouble. In
6670 cases where the XSetInputFocus done by the WM and the one
6671 below are temporally close (on a fast machine), the call
6672 below can generate additional FocusIn events which confuse
6675 /* Since we set WM_TAKE_FOCUS, we must call
6676 XSetInputFocus explicitly. But not if f is null,
6677 since that might be an event for a deleted frame. */
6680 Display
*d
= event
->xclient
.display
;
6681 /* Catch and ignore errors, in case window has been
6682 iconified by a window manager such as GWM. */
6684 XSetInputFocus (d
, event
->xclient
.window
,
6685 /* The ICCCM says this is
6686 the only valid choice. */
6688 event
->xclient
.data
.l
[1]);
6689 /* This is needed to detect the error
6690 if there is an error. */
6692 x_uncatch_errors ();
6694 /* Not certain about handling scroll bars here */
6699 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_save_yourself
)
6701 /* Save state modify the WM_COMMAND property to
6702 something which can reinstate us. This notifies
6703 the session manager, who's looking for such a
6704 PropertyNotify. Can restart processing when
6705 a keyboard or mouse event arrives. */
6706 /* If we have a session manager, don't set this.
6707 KDE will then start two Emacsen, one for the
6708 session manager and one for this. */
6710 if (! x_session_have_connection ())
6713 f
= x_top_window_to_frame (dpyinfo
,
6714 event
->xclient
.window
);
6715 /* This is just so we only give real data once
6716 for a single Emacs process. */
6717 if (f
== SELECTED_FRAME ())
6718 XSetCommand (FRAME_X_DISPLAY (f
),
6719 event
->xclient
.window
,
6720 initial_argv
, initial_argc
);
6722 XSetCommand (FRAME_X_DISPLAY (f
),
6723 event
->xclient
.window
,
6729 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_delete_window
)
6733 goto OTHER
; /* May be a dialog that is to be removed */
6735 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
6736 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6743 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_configure_denied
)
6746 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_window_moved
)
6749 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
6751 new_x
= event
->xclient
.data
.s
[0];
6752 new_y
= event
->xclient
.data
.s
[1];
6756 f
->left_pos
= new_x
;
6763 if (event
->xclient
.message_type
== dpyinfo
->Xatom_editres
)
6767 _XEditResCheckMessages (f
->output_data
.x
->widget
,
6768 NULL
, (XEvent
*) event
, NULL
);
6771 #endif /* HACK_EDITRES */
6773 if (event
->xclient
.message_type
== dpyinfo
->Xatom_DONE
6774 || event
->xclient
.message_type
== dpyinfo
->Xatom_PAGE
)
6776 /* Ghostview job completed. Kill it. We could
6777 reply with "Next" if we received "Page", but we
6778 currently never do because we are interested in
6779 images, only, which should have 1 page. */
6780 Pixmap pixmap
= (Pixmap
) event
->xclient
.data
.l
[1];
6781 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
6784 x_kill_gs_process (pixmap
, f
);
6785 expose_frame (f
, 0, 0, 0, 0);
6789 #ifdef USE_TOOLKIT_SCROLL_BARS
6790 /* Scroll bar callbacks send a ClientMessage from which
6791 we construct an input_event. */
6792 if (event
->xclient
.message_type
== dpyinfo
->Xatom_Scrollbar
)
6794 x_scroll_bar_to_input_event (event
, &inev
.ie
);
6795 *finish
= X_EVENT_GOTO_OUT
;
6798 else if (event
->xclient
.message_type
== dpyinfo
->Xatom_Horizontal_Scrollbar
)
6800 x_horizontal_scroll_bar_to_input_event (event
, &inev
.ie
);
6801 *finish
= X_EVENT_GOTO_OUT
;
6804 #endif /* USE_TOOLKIT_SCROLL_BARS */
6806 /* XEmbed messages from the embedder (if any). */
6807 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
6809 enum xembed_message msg
= event
->xclient
.data
.l
[1];
6810 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6811 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6813 *finish
= X_EVENT_GOTO_OUT
;
6817 xft_settings_event (dpyinfo
, event
);
6822 if (x_handle_dnd_message (f
, &event
->xclient
, dpyinfo
, &inev
.ie
))
6823 *finish
= X_EVENT_DROP
;
6827 case SelectionNotify
:
6828 x_display_set_last_user_time (dpyinfo
, event
->xselection
.time
);
6829 #ifdef USE_X_TOOLKIT
6830 if (! x_window_to_frame (dpyinfo
, event
->xselection
.requestor
))
6832 #endif /* not USE_X_TOOLKIT */
6833 x_handle_selection_notify (&event
->xselection
);
6836 case SelectionClear
: /* Someone has grabbed ownership. */
6837 x_display_set_last_user_time (dpyinfo
, event
->xselectionclear
.time
);
6838 #ifdef USE_X_TOOLKIT
6839 if (! x_window_to_frame (dpyinfo
, event
->xselectionclear
.window
))
6841 #endif /* USE_X_TOOLKIT */
6843 const XSelectionClearEvent
*eventp
= &event
->xselectionclear
;
6845 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6846 SELECTION_EVENT_DPYINFO (&inev
.sie
) = dpyinfo
;
6847 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6848 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6852 case SelectionRequest
: /* Someone wants our selection. */
6853 x_display_set_last_user_time (dpyinfo
, event
->xselectionrequest
.time
);
6854 #ifdef USE_X_TOOLKIT
6855 if (!x_window_to_frame (dpyinfo
, event
->xselectionrequest
.owner
))
6857 #endif /* USE_X_TOOLKIT */
6859 const XSelectionRequestEvent
*eventp
= &event
->xselectionrequest
;
6861 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6862 SELECTION_EVENT_DPYINFO (&inev
.sie
) = dpyinfo
;
6863 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6864 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6865 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6866 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6867 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6871 case PropertyNotify
:
6872 x_display_set_last_user_time (dpyinfo
, event
->xproperty
.time
);
6873 f
= x_top_window_to_frame (dpyinfo
, event
->xproperty
.window
);
6874 if (f
&& event
->xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6876 bool not_hidden
= x_handle_net_wm_state (f
, &event
->xproperty
);
6877 if (not_hidden
&& FRAME_ICONIFIED_P (f
))
6879 /* Gnome shell does not iconify us when C-z is pressed.
6880 It hides the frame. So if our state says we aren't
6881 hidden anymore, treat it as deiconified. */
6882 SET_FRAME_VISIBLE (f
, 1);
6883 SET_FRAME_ICONIFIED (f
, false);
6884 f
->output_data
.x
->has_been_visible
= true;
6885 inev
.ie
.kind
= DEICONIFY_EVENT
;
6886 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6888 else if (! not_hidden
&& ! FRAME_ICONIFIED_P (f
))
6890 SET_FRAME_VISIBLE (f
, 0);
6891 SET_FRAME_ICONIFIED (f
, true);
6892 inev
.ie
.kind
= ICONIFY_EVENT
;
6893 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6897 x_handle_property_notify (&event
->xproperty
);
6898 xft_settings_event (dpyinfo
, event
);
6901 case ReparentNotify
:
6902 f
= x_top_window_to_frame (dpyinfo
, event
->xreparent
.window
);
6905 f
->output_data
.x
->parent_desc
= event
->xreparent
.parent
;
6906 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6908 /* Perhaps reparented due to a WM restart. Reset this. */
6909 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6910 FRAME_DISPLAY_INFO (f
)->net_supported_window
= 0;
6912 x_set_frame_alpha (f
);
6917 f
= x_window_to_frame (dpyinfo
, event
->xexpose
.window
);
6920 if (!FRAME_VISIBLE_P (f
))
6922 SET_FRAME_VISIBLE (f
, 1);
6923 SET_FRAME_ICONIFIED (f
, false);
6924 f
->output_data
.x
->has_been_visible
= true;
6925 SET_FRAME_GARBAGED (f
);
6930 /* This seems to be needed for GTK 2.6 and later, see
6931 http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15398. */
6932 x_clear_area (event
->xexpose
.display
,
6933 event
->xexpose
.window
,
6934 event
->xexpose
.x
, event
->xexpose
.y
,
6935 event
->xexpose
.width
, event
->xexpose
.height
);
6937 expose_frame (f
, event
->xexpose
.x
, event
->xexpose
.y
,
6938 event
->xexpose
.width
, event
->xexpose
.height
);
6943 #ifndef USE_TOOLKIT_SCROLL_BARS
6944 struct scroll_bar
*bar
;
6946 #if defined USE_LUCID
6947 /* Submenus of the Lucid menu bar aren't widgets
6948 themselves, so there's no way to dispatch events
6949 to them. Recognize this case separately. */
6951 Widget widget
= x_window_to_menu_bar (event
->xexpose
.window
);
6953 xlwmenu_redisplay (widget
);
6955 #endif /* USE_LUCID */
6957 #ifdef USE_TOOLKIT_SCROLL_BARS
6958 /* Dispatch event to the widget. */
6960 #else /* not USE_TOOLKIT_SCROLL_BARS */
6961 bar
= x_window_to_scroll_bar (event
->xexpose
.display
,
6962 event
->xexpose
.window
, 2);
6965 x_scroll_bar_expose (bar
, event
);
6966 #ifdef USE_X_TOOLKIT
6969 #endif /* USE_X_TOOLKIT */
6970 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6974 case GraphicsExpose
: /* This occurs when an XCopyArea's
6975 source area was obscured or not
6977 f
= x_window_to_frame (dpyinfo
, event
->xgraphicsexpose
.drawable
);
6979 expose_frame (f
, event
->xgraphicsexpose
.x
,
6980 event
->xgraphicsexpose
.y
,
6981 event
->xgraphicsexpose
.width
,
6982 event
->xgraphicsexpose
.height
);
6983 #ifdef USE_X_TOOLKIT
6986 #endif /* USE_X_TOOLKIT */
6989 case NoExpose
: /* This occurs when an XCopyArea's
6990 source area was completely
6995 /* Redo the mouse-highlight after the tooltip has gone. */
6996 if (event
->xunmap
.window
== tip_window
)
6999 x_redo_mouse_highlight (dpyinfo
);
7002 f
= x_top_window_to_frame (dpyinfo
, event
->xunmap
.window
);
7003 if (f
) /* F may no longer exist if
7004 the frame was deleted. */
7006 bool visible
= FRAME_VISIBLE_P (f
);
7007 /* While a frame is unmapped, display generation is
7008 disabled; you don't want to spend time updating a
7009 display that won't ever be seen. */
7010 SET_FRAME_VISIBLE (f
, 0);
7011 /* We can't distinguish, from the event, whether the window
7012 has become iconified or invisible. So assume, if it
7013 was previously visible, than now it is iconified.
7014 But x_make_frame_invisible clears both
7015 the visible flag and the iconified flag;
7016 and that way, we know the window is not iconified now. */
7017 if (visible
|| FRAME_ICONIFIED_P (f
))
7019 SET_FRAME_ICONIFIED (f
, true);
7020 inev
.ie
.kind
= ICONIFY_EVENT
;
7021 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7027 if (event
->xmap
.window
== tip_window
)
7028 /* The tooltip has been drawn already. Avoid
7029 the SET_FRAME_GARBAGED below. */
7032 /* We use x_top_window_to_frame because map events can
7033 come for sub-windows and they don't mean that the
7034 frame is visible. */
7035 f
= x_top_window_to_frame (dpyinfo
, event
->xmap
.window
);
7038 bool iconified
= FRAME_ICONIFIED_P (f
);
7040 /* Check if fullscreen was specified before we where mapped the
7041 first time, i.e. from the command line. */
7042 if (!f
->output_data
.x
->has_been_visible
)
7043 x_check_fullscreen (f
);
7045 SET_FRAME_VISIBLE (f
, 1);
7046 SET_FRAME_ICONIFIED (f
, false);
7047 f
->output_data
.x
->has_been_visible
= true;
7051 inev
.ie
.kind
= DEICONIFY_EVENT
;
7052 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7054 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
7055 /* Force a redisplay sooner or later to update the
7056 frame titles in case this is the second frame. */
7057 record_asynch_buffer_change ();
7060 xg_frame_resized (f
, -1, -1);
7067 x_display_set_last_user_time (dpyinfo
, event
->xkey
.time
);
7068 ignore_next_mouse_click_timeout
= 0;
7070 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7071 /* Dispatch KeyPress events when in menu. */
7072 if (popup_activated ())
7078 #if ! defined (USE_GTK)
7079 /* If mouse-highlight is an integer, input clears out
7080 mouse highlighting. */
7081 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
7083 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)))
7085 clear_mouse_face (hlinfo
);
7086 hlinfo
->mouse_face_hidden
= true;
7090 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
7093 /* Scroll bars consume key events, but we want
7094 the keys to go to the scroll bar's frame. */
7095 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
7096 event
->xkey
.window
);
7097 if (widget
&& XmIsScrollBar (widget
))
7099 widget
= XtParent (widget
);
7100 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
7103 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
7107 KeySym keysym
, orig_keysym
;
7108 /* al%imercury@uunet.uu.net says that making this 81
7109 instead of 80 fixed a bug whereby meta chars made
7112 It seems that some version of XmbLookupString has
7113 a bug of not returning XBufferOverflow in
7114 status_return even if the input is too long to
7115 fit in 81 bytes. So, we must prepare sufficient
7116 bytes for copy_buffer. 513 bytes (256 chars for
7117 two-byte character set) seems to be a fairly good
7118 approximation. -- 2000.8.10 handa@etl.go.jp */
7119 unsigned char copy_buffer
[513];
7120 unsigned char *copy_bufptr
= copy_buffer
;
7121 int copy_bufsiz
= sizeof (copy_buffer
);
7123 Lisp_Object coding_system
= Qlatin_1
;
7125 /* Event will be modified. */
7126 XKeyEvent xkey
= event
->xkey
;
7129 /* Don't pass keys to GTK. A Tab will shift focus to the
7130 tool bar in GTK 2.4. Keys will still go to menus and
7131 dialogs because in that case popup_activated is nonzero
7133 *finish
= X_EVENT_DROP
;
7136 xkey
.state
|= x_emacs_to_x_modifiers (FRAME_DISPLAY_INFO (f
),
7137 extra_keyboard_modifiers
);
7138 modifiers
= xkey
.state
;
7140 /* This will have to go some day... */
7142 /* make_lispy_event turns chars into control chars.
7143 Don't do it here because XLookupString is too eager. */
7144 xkey
.state
&= ~ControlMask
;
7145 xkey
.state
&= ~(dpyinfo
->meta_mod_mask
7146 | dpyinfo
->super_mod_mask
7147 | dpyinfo
->hyper_mod_mask
7148 | dpyinfo
->alt_mod_mask
);
7150 /* In case Meta is ComposeCharacter,
7151 clear its status. According to Markus Ehrnsperger
7152 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
7153 this enables ComposeCharacter to work whether or
7154 not it is combined with Meta. */
7155 if (modifiers
& dpyinfo
->meta_mod_mask
)
7156 memset (&compose_status
, 0, sizeof (compose_status
));
7161 Status status_return
;
7163 coding_system
= Vlocale_coding_system
;
7164 nbytes
= XmbLookupString (FRAME_XIC (f
),
7165 &xkey
, (char *) copy_bufptr
,
7166 copy_bufsiz
, &keysym
,
7168 if (status_return
== XBufferOverflow
)
7170 copy_bufsiz
= nbytes
+ 1;
7171 copy_bufptr
= alloca (copy_bufsiz
);
7172 nbytes
= XmbLookupString (FRAME_XIC (f
),
7173 &xkey
, (char *) copy_bufptr
,
7174 copy_bufsiz
, &keysym
,
7177 /* Xutf8LookupString is a new but already deprecated interface. -stef */
7178 if (status_return
== XLookupNone
)
7180 else if (status_return
== XLookupChars
)
7185 else if (status_return
!= XLookupKeySym
7186 && status_return
!= XLookupBoth
)
7190 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
7191 copy_bufsiz
, &keysym
,
7194 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
7195 copy_bufsiz
, &keysym
,
7199 /* If not using XIM/XIC, and a compose sequence is in progress,
7200 we break here. Otherwise, chars_matched is always 0. */
7201 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
7204 memset (&compose_status
, 0, sizeof (compose_status
));
7205 orig_keysym
= keysym
;
7207 /* Common for all keysym input events. */
7208 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7210 = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
), modifiers
);
7211 inev
.ie
.timestamp
= xkey
.time
;
7213 /* First deal with keysyms which have defined
7214 translations to characters. */
7215 if (keysym
>= 32 && keysym
< 128)
7216 /* Avoid explicitly decoding each ASCII character. */
7218 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
7219 inev
.ie
.code
= keysym
;
7223 /* Keysyms directly mapped to Unicode characters. */
7224 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
7226 if (keysym
< 0x01000080)
7227 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
7229 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
7230 inev
.ie
.code
= keysym
& 0xFFFFFF;
7234 /* Now non-ASCII. */
7235 if (HASH_TABLE_P (Vx_keysym_table
)
7236 && (c
= Fgethash (make_number (keysym
),
7241 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
7242 ? ASCII_KEYSTROKE_EVENT
7243 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
7244 inev
.ie
.code
= XFASTINT (c
);
7248 /* Random non-modifier sorts of keysyms. */
7249 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
7250 || keysym
== XK_Delete
7251 #ifdef XK_ISO_Left_Tab
7252 || (keysym
>= XK_ISO_Left_Tab
7253 && keysym
<= XK_ISO_Enter
)
7255 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
7256 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
7258 /* This recognizes the "extended function
7259 keys". It seems there's no cleaner way.
7260 Test IsModifierKey to avoid handling
7261 mode_switch incorrectly. */
7262 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
7264 #ifdef XK_dead_circumflex
7265 || orig_keysym
== XK_dead_circumflex
7267 #ifdef XK_dead_grave
7268 || orig_keysym
== XK_dead_grave
7270 #ifdef XK_dead_tilde
7271 || orig_keysym
== XK_dead_tilde
7273 #ifdef XK_dead_diaeresis
7274 || orig_keysym
== XK_dead_diaeresis
7276 #ifdef XK_dead_macron
7277 || orig_keysym
== XK_dead_macron
7279 #ifdef XK_dead_degree
7280 || orig_keysym
== XK_dead_degree
7282 #ifdef XK_dead_acute
7283 || orig_keysym
== XK_dead_acute
7285 #ifdef XK_dead_cedilla
7286 || orig_keysym
== XK_dead_cedilla
7288 #ifdef XK_dead_breve
7289 || orig_keysym
== XK_dead_breve
7291 #ifdef XK_dead_ogonek
7292 || orig_keysym
== XK_dead_ogonek
7294 #ifdef XK_dead_caron
7295 || orig_keysym
== XK_dead_caron
7297 #ifdef XK_dead_doubleacute
7298 || orig_keysym
== XK_dead_doubleacute
7300 #ifdef XK_dead_abovedot
7301 || orig_keysym
== XK_dead_abovedot
7303 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
7304 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
7305 /* Any "vendor-specific" key is ok. */
7306 || (orig_keysym
& (1 << 28))
7307 || (keysym
!= NoSymbol
&& nbytes
== 0))
7308 && ! (IsModifierKey (orig_keysym
)
7309 /* The symbols from XK_ISO_Lock
7310 to XK_ISO_Last_Group_Lock
7311 don't have real modifiers but
7312 should be treated similarly to
7313 Mode_switch by Emacs. */
7314 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
7315 || (XK_ISO_Lock
<= orig_keysym
7316 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
7320 STORE_KEYSYM_FOR_DEBUG (keysym
);
7321 /* make_lispy_event will convert this to a symbolic
7323 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
7324 inev
.ie
.code
= keysym
;
7328 { /* Raw bytes, not keysym. */
7332 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
7334 if (ASCII_CHAR_P (copy_bufptr
[i
]))
7336 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
7339 if (nchars
< nbytes
)
7341 /* Decode the input data. */
7343 /* The input should be decoded with `coding_system'
7344 which depends on which X*LookupString function
7345 we used just above and the locale. */
7346 setup_coding_system (coding_system
, &coding
);
7347 coding
.src_multibyte
= false;
7348 coding
.dst_multibyte
= true;
7349 /* The input is converted to events, thus we can't
7350 handle composition. Anyway, there's no XIM that
7351 gives us composition information. */
7352 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
7354 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
7356 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
7357 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
7358 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
7359 nbytes
= coding
.produced
;
7360 nchars
= coding
.produced_char
;
7361 copy_bufptr
= coding
.destination
;
7364 /* Convert the input data to a sequence of
7365 character events. */
7366 for (i
= 0; i
< nbytes
; i
+= len
)
7369 if (nchars
== nbytes
)
7370 ch
= copy_bufptr
[i
], len
= 1;
7372 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
7373 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
7374 ? ASCII_KEYSTROKE_EVENT
7375 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
7377 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7382 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
7384 if (keysym
== NoSymbol
)
7387 /* FIXME: check side effects and remove this. */
7388 ((XEvent
*) event
)->xkey
= xkey
;
7392 /* Don't dispatch this event since XtDispatchEvent calls
7393 XFilterEvent, and two calls in a row may freeze the
7401 x_display_set_last_user_time (dpyinfo
, event
->xkey
.time
);
7403 /* Don't dispatch this event since XtDispatchEvent calls
7404 XFilterEvent, and two calls in a row may freeze the
7412 x_display_set_last_user_time (dpyinfo
, event
->xcrossing
.time
);
7413 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
7417 if (f
&& x_mouse_click_focus_ignore_position
)
7418 ignore_next_mouse_click_timeout
= event
->xmotion
.time
+ 200;
7420 /* EnterNotify counts as mouse movement,
7421 so update things that depend on mouse position. */
7422 if (f
&& !f
->output_data
.x
->hourglass_p
)
7423 note_mouse_movement (f
, &event
->xmotion
);
7425 /* We may get an EnterNotify on the buttons in the toolbar. In that
7426 case we moved out of any highlighted area and need to note this. */
7427 if (!f
&& dpyinfo
->last_mouse_glyph_frame
)
7428 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
7433 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
7437 x_display_set_last_user_time (dpyinfo
, event
->xcrossing
.time
);
7438 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
7440 f
= x_top_window_to_frame (dpyinfo
, event
->xcrossing
.window
);
7443 if (f
== hlinfo
->mouse_face_mouse_frame
)
7445 /* If we move outside the frame, then we're
7446 certainly no longer on any text in the frame. */
7447 clear_mouse_face (hlinfo
);
7448 hlinfo
->mouse_face_mouse_frame
= 0;
7451 /* Generate a nil HELP_EVENT to cancel a help-echo.
7452 Do it only if there's something to cancel.
7453 Otherwise, the startup message is cleared when
7454 the mouse leaves the frame. */
7455 if (any_help_event_p
)
7459 /* See comment in EnterNotify above */
7460 else if (dpyinfo
->last_mouse_glyph_frame
)
7461 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
7466 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
7471 x_display_set_last_user_time (dpyinfo
, event
->xmotion
.time
);
7472 previous_help_echo_string
= help_echo_string
;
7473 help_echo_string
= Qnil
;
7475 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
7476 : x_window_to_frame (dpyinfo
, event
->xmotion
.window
));
7478 if (hlinfo
->mouse_face_hidden
)
7480 hlinfo
->mouse_face_hidden
= false;
7481 clear_mouse_face (hlinfo
);
7485 if (f
&& xg_event_is_for_scrollbar (f
, event
))
7491 /* Generate SELECT_WINDOW_EVENTs when needed.
7492 Don't let popup menus influence things (bug#1261). */
7493 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
7495 static Lisp_Object last_mouse_window
;
7496 Lisp_Object window
= window_from_coordinates
7497 (f
, event
->xmotion
.x
, event
->xmotion
.y
, 0, false);
7499 /* Window will be selected only when it is not selected now and
7500 last mouse movement event was not in it. Minibuffer window
7501 will be selected only when it is active. */
7502 if (WINDOWP (window
)
7503 && !EQ (window
, last_mouse_window
)
7504 && !EQ (window
, selected_window
)
7505 /* For click-to-focus window managers
7506 create event iff we don't leave the
7508 && (focus_follows_mouse
7509 || (EQ (XWINDOW (window
)->frame
,
7510 XWINDOW (selected_window
)->frame
))))
7512 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
7513 inev
.ie
.frame_or_window
= window
;
7515 /* Remember the last window where we saw the mouse. */
7516 last_mouse_window
= window
;
7518 if (!note_mouse_movement (f
, &event
->xmotion
))
7519 help_echo_string
= previous_help_echo_string
;
7523 #ifndef USE_TOOLKIT_SCROLL_BARS
7524 struct scroll_bar
*bar
7525 = x_window_to_scroll_bar (event
->xmotion
.display
,
7526 event
->xmotion
.window
, 2);
7529 x_scroll_bar_note_movement (bar
, &event
->xmotion
);
7530 #endif /* USE_TOOLKIT_SCROLL_BARS */
7532 /* If we move outside the frame, then we're
7533 certainly no longer on any text in the frame. */
7534 clear_mouse_face (hlinfo
);
7537 /* If the contents of the global variable help_echo_string
7538 has changed, generate a HELP_EVENT. */
7539 if (!NILP (help_echo_string
)
7540 || !NILP (previous_help_echo_string
))
7545 case ConfigureNotify
:
7546 f
= x_top_window_to_frame (dpyinfo
, event
->xconfigure
.window
);
7550 && event
->xconfigure
.window
== FRAME_X_WINDOW (f
))
7552 xg_frame_resized (f
, event
->xconfigure
.width
,
7553 event
->xconfigure
.height
);
7559 x_net_wm_state (f
, event
->xconfigure
.window
);
7561 #ifndef USE_X_TOOLKIT
7563 int width
= FRAME_PIXEL_TO_TEXT_WIDTH (f
, event
->xconfigure
.width
);
7564 int height
= FRAME_PIXEL_TO_TEXT_HEIGHT (f
, event
->xconfigure
.height
);
7566 /* In the toolkit version, change_frame_size
7567 is called by the code that handles resizing
7568 of the EmacsFrame widget. */
7570 /* Even if the number of character rows and columns has
7571 not changed, the font size may have changed, so we need
7572 to check the pixel dimensions as well. */
7573 if (width
!= FRAME_TEXT_WIDTH (f
)
7574 || height
!= FRAME_TEXT_HEIGHT (f
)
7575 || event
->xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
7576 || event
->xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
7578 change_frame_size (f
, width
, height
, false, true, false, true);
7579 x_clear_under_internal_border (f
);
7580 SET_FRAME_GARBAGED (f
);
7581 cancel_mouse_face (f
);
7583 #endif /* not USE_GTK */
7587 /* GTK creates windows but doesn't map them.
7588 Only get real positions when mapped. */
7589 if (FRAME_GTK_OUTER_WIDGET (f
)
7590 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
7592 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
7595 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
7596 xic_set_statusarea (f
);
7605 /* If we decide we want to generate an event to be seen
7606 by the rest of Emacs, we put it here. */
7607 bool tool_bar_p
= false;
7609 memset (&compose_status
, 0, sizeof (compose_status
));
7610 dpyinfo
->last_mouse_glyph_frame
= NULL
;
7611 x_display_set_last_user_time (dpyinfo
, event
->xbutton
.time
);
7613 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
7614 : x_window_to_frame (dpyinfo
, event
->xbutton
.window
));
7617 if (f
&& xg_event_is_for_scrollbar (f
, event
))
7622 #if ! defined (USE_GTK)
7623 /* Is this in the tool-bar? */
7624 if (WINDOWP (f
->tool_bar_window
)
7625 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
7628 int x
= event
->xbutton
.x
;
7629 int y
= event
->xbutton
.y
;
7631 window
= window_from_coordinates (f
, x
, y
, 0, true);
7632 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
7634 if (tool_bar_p
&& event
->xbutton
.button
< 4)
7635 handle_tool_bar_click
7636 (f
, x
, y
, event
->xbutton
.type
== ButtonPress
,
7637 x_x_to_emacs_modifiers (dpyinfo
, event
->xbutton
.state
));
7639 #endif /* !USE_GTK */
7642 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7643 if (! popup_activated ())
7646 if (ignore_next_mouse_click_timeout
)
7648 if (event
->type
== ButtonPress
7649 && event
->xbutton
.time
> ignore_next_mouse_click_timeout
)
7651 ignore_next_mouse_click_timeout
= 0;
7652 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
7654 if (event
->type
== ButtonRelease
)
7655 ignore_next_mouse_click_timeout
= 0;
7658 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
7660 if (FRAME_X_EMBEDDED_P (f
))
7661 xembed_send_message (f
, event
->xbutton
.time
,
7662 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
7666 struct scroll_bar
*bar
7667 = x_window_to_scroll_bar (event
->xbutton
.display
,
7668 event
->xbutton
.window
, 2);
7670 #ifdef USE_TOOLKIT_SCROLL_BARS
7671 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
7673 if (bar
&& event
->xbutton
.state
& ControlMask
)
7675 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
7676 *finish
= X_EVENT_DROP
;
7678 #else /* not USE_TOOLKIT_SCROLL_BARS */
7680 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
7681 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7684 if (event
->type
== ButtonPress
)
7686 dpyinfo
->grabbed
|= (1 << event
->xbutton
.button
);
7687 dpyinfo
->last_mouse_frame
= f
;
7688 #if ! defined (USE_GTK)
7689 if (f
&& !tool_bar_p
)
7690 f
->last_tool_bar_item
= -1;
7691 #endif /* not USE_GTK */
7694 dpyinfo
->grabbed
&= ~(1 << event
->xbutton
.button
);
7696 /* Ignore any mouse motion that happened before this event;
7697 any subsequent mouse-movement Emacs events should reflect
7698 only motion after the ButtonPress/Release. */
7700 f
->mouse_moved
= false;
7702 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7703 f
= x_menubar_window_to_frame (dpyinfo
, event
);
7704 /* For a down-event in the menu bar,
7705 don't pass it to Xt right now.
7706 Instead, save it away
7707 and we will pass it to Xt from kbd_buffer_get_event.
7708 That way, we can run some Lisp code first. */
7709 if (! popup_activated ()
7711 /* Gtk+ menus only react to the first three buttons. */
7712 && event
->xbutton
.button
< 3
7714 && f
&& event
->type
== ButtonPress
7715 /* Verify the event is really within the menu bar
7716 and not just sent to it due to grabbing. */
7717 && event
->xbutton
.x
>= 0
7718 && event
->xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
7719 && event
->xbutton
.y
>= 0
7720 && event
->xbutton
.y
< FRAME_MENUBAR_HEIGHT (f
)
7721 && event
->xbutton
.same_screen
)
7723 if (!f
->output_data
.x
->saved_menu_event
)
7724 f
->output_data
.x
->saved_menu_event
= xmalloc (sizeof *event
);
7725 *f
->output_data
.x
->saved_menu_event
= *event
;
7726 inev
.ie
.kind
= MENU_BAR_ACTIVATE_EVENT
;
7727 XSETFRAME (inev
.ie
.frame_or_window
, f
);
7728 *finish
= X_EVENT_DROP
;
7732 #endif /* USE_X_TOOLKIT || USE_GTK */
7736 case CirculateNotify
:
7739 case CirculateRequest
:
7742 case VisibilityNotify
:
7746 /* Someone has changed the keyboard mapping - update the
7748 switch (event
->xmapping
.request
)
7750 case MappingModifier
:
7751 x_find_modifier_meanings (dpyinfo
);
7752 /* This is meant to fall through. */
7753 case MappingKeyboard
:
7754 XRefreshKeyboardMapping ((XMappingEvent
*) &event
->xmapping
);
7759 xft_settings_event (dpyinfo
, event
);
7764 #ifdef USE_X_TOOLKIT
7766 if (*finish
!= X_EVENT_DROP
)
7767 XtDispatchEvent ((XEvent
*) event
);
7769 #endif /* USE_X_TOOLKIT */
7774 if (inev
.ie
.kind
!= NO_EVENT
)
7776 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7781 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7786 XSETFRAME (frame
, f
);
7792 any_help_event_p
= true;
7793 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7794 help_echo_object
, help_echo_pos
);
7798 help_echo_string
= Qnil
;
7799 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7808 /* Handles the XEvent EVENT on display DISPLAY.
7809 This is used for event loops outside the normal event handling,
7810 i.e. looping while a popup menu or a dialog is posted.
7812 Returns the value handle_one_xevent sets in the finish argument. */
7814 x_dispatch_event (XEvent
*event
, Display
*display
)
7816 struct x_display_info
*dpyinfo
;
7817 int finish
= X_EVENT_NORMAL
;
7819 dpyinfo
= x_display_info_for_display (display
);
7822 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7827 /* Read events coming from the X server.
7828 Return as soon as there are no more events to be read.
7830 Return the number of characters stored into the buffer,
7831 thus pretending to be `read' (except the characters we store
7832 in the keyboard buffer can be multibyte, so are not necessarily
7836 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
7839 bool event_found
= false;
7840 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
7844 /* For debugging, this gives a way to fake an I/O error. */
7845 if (dpyinfo
== XTread_socket_fake_io_error
)
7847 XTread_socket_fake_io_error
= 0;
7848 x_io_error_quitter (dpyinfo
->display
);
7852 while (XPending (dpyinfo
->display
))
7857 XNextEvent (dpyinfo
->display
, &event
);
7860 /* Filter events for the current X input method. */
7861 if (x_filter_event (dpyinfo
, &event
))
7866 count
+= handle_one_xevent (dpyinfo
, &event
, &finish
, hold_quit
);
7868 if (finish
== X_EVENT_GOTO_OUT
)
7874 /* For GTK we must use the GTK event loop. But XEvents gets passed
7875 to our filter function above, and then to the big event switch.
7876 We use a bunch of globals to communicate with our filter function,
7877 that is kind of ugly, but it works.
7879 There is no way to do one display at the time, GTK just does events
7880 from all displays. */
7882 while (gtk_events_pending ())
7884 current_count
= count
;
7885 current_hold_quit
= hold_quit
;
7887 gtk_main_iteration ();
7889 count
= current_count
;
7891 current_hold_quit
= 0;
7893 if (current_finish
== X_EVENT_GOTO_OUT
)
7896 #endif /* USE_GTK */
7898 /* On some systems, an X bug causes Emacs to get no more events
7899 when the window is destroyed. Detect that. (1994.) */
7902 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7903 One XNOOP in 100 loops will make Emacs terminate.
7904 B. Bretthauer, 1994 */
7906 if (x_noop_count
>= 100)
7910 if (next_noop_dpyinfo
== 0)
7911 next_noop_dpyinfo
= x_display_list
;
7913 XNoOp (next_noop_dpyinfo
->display
);
7915 /* Each time we get here, cycle through the displays now open. */
7916 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7920 /* If the focus was just given to an auto-raising frame,
7921 raise it now. FIXME: handle more than one such frame. */
7922 if (dpyinfo
->x_pending_autoraise_frame
)
7924 x_raise_frame (dpyinfo
->x_pending_autoraise_frame
);
7925 dpyinfo
->x_pending_autoraise_frame
= NULL
;
7936 /***********************************************************************
7938 ***********************************************************************/
7940 /* Set clipping for output in glyph row ROW. W is the window in which
7941 we operate. GC is the graphics context to set clipping in.
7943 ROW may be a text row or, e.g., a mode line. Text rows must be
7944 clipped to the interior of the window dedicated to text display,
7945 mode lines must be clipped to the whole window. */
7948 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
7949 enum glyph_row_area area
, GC gc
)
7951 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7952 XRectangle clip_rect
;
7953 int window_x
, window_y
, window_width
;
7955 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7957 clip_rect
.x
= window_x
;
7958 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7959 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7960 clip_rect
.width
= window_width
;
7961 clip_rect
.height
= row
->visible_height
;
7963 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7967 /* Draw a hollow box cursor on window W in glyph row ROW. */
7970 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7972 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7973 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
7974 Display
*dpy
= FRAME_X_DISPLAY (f
);
7977 struct glyph
*cursor_glyph
;
7980 /* Get the glyph the cursor is on. If we can't tell because
7981 the current matrix is invalid or such, give up. */
7982 cursor_glyph
= get_phys_cursor_glyph (w
);
7983 if (cursor_glyph
== NULL
)
7986 /* Compute frame-relative coordinates for phys cursor. */
7987 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7988 wd
= w
->phys_cursor_width
- 1;
7990 /* The foreground of cursor_gc is typically the same as the normal
7991 background color, which can cause the cursor box to be invisible. */
7992 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7993 if (dpyinfo
->scratch_cursor_gc
)
7994 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7996 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7997 GCForeground
, &xgcv
);
7998 gc
= dpyinfo
->scratch_cursor_gc
;
8000 /* When on R2L character, show cursor at the right edge of the
8001 glyph, unless the cursor box is as wide as the glyph or wider
8002 (the latter happens when x-stretch-cursor is non-nil). */
8003 if ((cursor_glyph
->resolved_level
& 1) != 0
8004 && cursor_glyph
->pixel_width
> wd
)
8006 x
+= cursor_glyph
->pixel_width
- wd
;
8010 /* Set clipping, draw the rectangle, and reset clipping again. */
8011 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
8012 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
8013 XSetClipMask (dpy
, gc
, None
);
8017 /* Draw a bar cursor on window W in glyph row ROW.
8019 Implementation note: One would like to draw a bar cursor with an
8020 angle equal to the one given by the font property XA_ITALIC_ANGLE.
8021 Unfortunately, I didn't find a font yet that has this property set.
8025 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
8027 struct frame
*f
= XFRAME (w
->frame
);
8028 struct glyph
*cursor_glyph
;
8030 /* If cursor is out of bounds, don't draw garbage. This can happen
8031 in mini-buffer windows when switching between echo area glyphs
8033 cursor_glyph
= get_phys_cursor_glyph (w
);
8034 if (cursor_glyph
== NULL
)
8036 #ifdef HAVE_XWIDGETS
8037 if (cursor_glyph
->type
== XWIDGET_GLYPH
){
8038 printf("tried avoiding xwidget cursor\n");
8039 return; //experimental avoidance of cursor on xwidget
8042 /* If on an image, draw like a normal cursor. That's usually better
8043 visible than drawing a bar, esp. if the image is large so that
8044 the bar might not be in the window. */
8045 if (cursor_glyph
->type
== IMAGE_GLYPH
)
8047 struct glyph_row
*r
;
8048 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
8049 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
8053 Display
*dpy
= FRAME_X_DISPLAY (f
);
8054 Window window
= FRAME_X_WINDOW (f
);
8055 GC gc
= FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
;
8056 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
8057 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
8060 /* If the glyph's background equals the color we normally draw
8061 the bars cursor in, the bar cursor in its normal color is
8062 invisible. Use the glyph's foreground color instead in this
8063 case, on the assumption that the glyph's colors are chosen so
8064 that the glyph is legible. */
8065 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
8066 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
8068 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
8069 xgcv
.graphics_exposures
= False
;
8072 XChangeGC (dpy
, gc
, mask
, &xgcv
);
8075 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
8076 FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
8079 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
8081 if (kind
== BAR_CURSOR
)
8083 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8086 width
= FRAME_CURSOR_WIDTH (f
);
8087 width
= min (cursor_glyph
->pixel_width
, width
);
8089 w
->phys_cursor_width
= width
;
8091 /* If the character under cursor is R2L, draw the bar cursor
8092 on the right of its glyph, rather than on the left. */
8093 if ((cursor_glyph
->resolved_level
& 1) != 0)
8094 x
+= cursor_glyph
->pixel_width
- width
;
8096 XFillRectangle (dpy
, window
, gc
, x
,
8097 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
8098 width
, row
->height
);
8100 else /* HBAR_CURSOR */
8102 int dummy_x
, dummy_y
, dummy_h
;
8103 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
8106 width
= row
->height
;
8108 width
= min (row
->height
, width
);
8110 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
8111 &dummy_y
, &dummy_h
);
8113 if ((cursor_glyph
->resolved_level
& 1) != 0
8114 && cursor_glyph
->pixel_width
> w
->phys_cursor_width
- 1)
8115 x
+= cursor_glyph
->pixel_width
- w
->phys_cursor_width
+ 1;
8116 XFillRectangle (dpy
, window
, gc
, x
,
8117 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
8118 row
->height
- width
),
8119 w
->phys_cursor_width
- 1, width
);
8122 XSetClipMask (dpy
, gc
, None
);
8127 /* RIF: Define cursor CURSOR on frame F. */
8130 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
8132 if (!f
->pointer_invisible
8133 && f
->output_data
.x
->current_cursor
!= cursor
)
8134 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
8135 f
->output_data
.x
->current_cursor
= cursor
;
8139 /* RIF: Clear area on frame F. */
8142 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
8144 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), x
, y
, width
, height
);
8146 /* Must queue a redraw, because scroll bars might have been cleared. */
8147 if (FRAME_GTK_WIDGET (f
))
8148 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
8153 /* RIF: Draw cursor on window W. */
8156 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
8157 int y
, enum text_cursor_kinds cursor_type
,
8158 int cursor_width
, bool on_p
, bool active_p
)
8160 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
8164 w
->phys_cursor_type
= cursor_type
;
8165 w
->phys_cursor_on_p
= true;
8167 if (glyph_row
->exact_window_width_line_p
8168 && (glyph_row
->reversed_p
8169 ? (w
->phys_cursor
.hpos
< 0)
8170 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
8172 glyph_row
->cursor_in_fringe_p
= true;
8173 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
8177 switch (cursor_type
)
8179 case HOLLOW_BOX_CURSOR
:
8180 x_draw_hollow_cursor (w
, glyph_row
);
8183 case FILLED_BOX_CURSOR
:
8184 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
8188 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
8192 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
8196 w
->phys_cursor_width
= 0;
8205 if (w
== XWINDOW (f
->selected_window
))
8206 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
8207 xic_set_preeditarea (w
, x
, y
);
8211 XFlush (FRAME_X_DISPLAY (f
));
8217 /* Make the x-window of frame F use the gnu icon bitmap. */
8220 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
8222 ptrdiff_t bitmap_id
;
8224 if (FRAME_X_WINDOW (f
) == 0)
8227 /* Free up our existing icon bitmap and mask if any. */
8228 if (f
->output_data
.x
->icon_bitmap
> 0)
8229 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
8230 f
->output_data
.x
->icon_bitmap
= 0;
8235 /* Use gtk_window_set_icon_from_file () if available,
8236 It's not restricted to bitmaps */
8237 if (xg_set_icon (f
, file
))
8239 #endif /* USE_GTK */
8240 bitmap_id
= x_create_bitmap_from_file (f
, file
);
8241 x_create_bitmap_mask (f
, bitmap_id
);
8245 /* Create the GNU bitmap and mask if necessary. */
8246 if (FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
8252 if (xg_set_icon (f
, xg_default_icon_file
)
8253 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
8255 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= -2;
8259 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
8261 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
8263 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
8267 /* If all else fails, use the (black and white) xbm image. */
8270 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
8271 gnu_xbm_width
, gnu_xbm_height
);
8275 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
8276 x_create_bitmap_mask (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
8280 /* The first time we create the GNU bitmap and mask,
8281 this increments the ref-count one extra time.
8282 As a result, the GNU bitmap and mask are never freed.
8283 That way, we don't have to worry about allocating it again. */
8284 x_reference_bitmap (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
8286 bitmap_id
= FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
;
8289 x_wm_set_icon_pixmap (f
, bitmap_id
);
8290 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
8296 /* Make the x-window of frame F use a rectangle with text.
8297 Use ICON_NAME as the text. */
8300 x_text_icon (struct frame
*f
, const char *icon_name
)
8302 if (FRAME_X_WINDOW (f
) == 0)
8307 text
.value
= (unsigned char *) icon_name
;
8308 text
.encoding
= XA_STRING
;
8310 text
.nitems
= strlen (icon_name
);
8311 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
8314 if (f
->output_data
.x
->icon_bitmap
> 0)
8315 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
8316 f
->output_data
.x
->icon_bitmap
= 0;
8317 x_wm_set_icon_pixmap (f
, 0);
8322 #define X_ERROR_MESSAGE_SIZE 200
8324 /* If non-nil, this should be a string.
8325 It means catch X errors and store the error message in this string.
8327 The reason we use a stack is that x_catch_error/x_uncatch_error can
8328 be called from a signal handler.
8331 struct x_error_message_stack
{
8332 char string
[X_ERROR_MESSAGE_SIZE
];
8334 struct x_error_message_stack
*prev
;
8336 static struct x_error_message_stack
*x_error_message
;
8338 /* An X error handler which stores the error message in
8339 *x_error_message. This is called from x_error_handler if
8340 x_catch_errors is in effect. */
8343 x_error_catcher (Display
*display
, XErrorEvent
*event
)
8345 XGetErrorText (display
, event
->error_code
,
8346 x_error_message
->string
,
8347 X_ERROR_MESSAGE_SIZE
);
8350 /* Begin trapping X errors for display DPY. Actually we trap X errors
8351 for all displays, but DPY should be the display you are actually
8354 After calling this function, X protocol errors no longer cause
8355 Emacs to exit; instead, they are recorded in the string
8356 stored in *x_error_message.
8358 Calling x_check_errors signals an Emacs error if an X error has
8359 occurred since the last call to x_catch_errors or x_check_errors.
8361 Calling x_uncatch_errors resumes the normal error handling. */
8364 x_catch_errors (Display
*dpy
)
8366 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
8368 /* Make sure any errors from previous requests have been dealt with. */
8372 data
->string
[0] = 0;
8373 data
->prev
= x_error_message
;
8374 x_error_message
= data
;
8377 /* Undo the last x_catch_errors call.
8378 DPY should be the display that was passed to x_catch_errors. */
8381 x_uncatch_errors (void)
8383 struct x_error_message_stack
*tmp
;
8387 /* The display may have been closed before this function is called.
8388 Check if it is still open before calling XSync. */
8389 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
8390 XSync (x_error_message
->dpy
, False
);
8392 tmp
= x_error_message
;
8393 x_error_message
= x_error_message
->prev
;
8398 /* If any X protocol errors have arrived since the last call to
8399 x_catch_errors or x_check_errors, signal an Emacs error using
8400 sprintf (a buffer, FORMAT, the x error message text) as the text. */
8403 x_check_errors (Display
*dpy
, const char *format
)
8405 /* Make sure to catch any errors incurred so far. */
8408 if (x_error_message
->string
[0])
8410 char string
[X_ERROR_MESSAGE_SIZE
];
8411 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
8412 x_uncatch_errors ();
8413 error (format
, string
);
8417 /* Nonzero if we had any X protocol errors
8418 since we did x_catch_errors on DPY. */
8421 x_had_errors_p (Display
*dpy
)
8423 /* Make sure to catch any errors incurred so far. */
8426 return x_error_message
->string
[0] != 0;
8429 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
8432 x_clear_errors (Display
*dpy
)
8434 x_error_message
->string
[0] = 0;
8438 /* See comment in unwind_to_catch why calling this is a bad
8439 * idea. --lorentey */
8440 /* Close off all unclosed x_catch_errors calls. */
8443 x_fully_uncatch_errors (void)
8445 while (x_error_message
)
8446 x_uncatch_errors ();
8451 static unsigned int x_wire_count
;
8454 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
8459 /************************************************************************
8461 ************************************************************************/
8463 /* Error message passed to x_connection_closed. */
8465 static char *error_msg
;
8467 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
8468 the text of an error message that lead to the connection loss. */
8471 x_connection_closed (Display
*dpy
, const char *error_message
)
8473 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
8474 Lisp_Object frame
, tail
;
8475 ptrdiff_t idx
= SPECPDL_INDEX ();
8477 error_msg
= alloca (strlen (error_message
) + 1);
8478 strcpy (error_msg
, error_message
);
8480 /* Inhibit redisplay while frames are being deleted. */
8481 specbind (Qinhibit_redisplay
, Qt
);
8485 /* Protect display from being closed when we delete the last
8487 dpyinfo
->reference_count
++;
8488 dpyinfo
->terminal
->reference_count
++;
8491 /* First delete frames whose mini-buffers are on frames
8492 that are on the dead display. */
8493 FOR_EACH_FRAME (tail
, frame
)
8495 Lisp_Object minibuf_frame
;
8497 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
8498 if (FRAME_X_P (XFRAME (frame
))
8499 && FRAME_X_P (XFRAME (minibuf_frame
))
8500 && ! EQ (frame
, minibuf_frame
)
8501 && FRAME_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
8502 delete_frame (frame
, Qnoelisp
);
8505 /* Now delete all remaining frames on the dead display.
8506 We are now sure none of these is used as the mini-buffer
8507 for another frame that we need to delete. */
8508 FOR_EACH_FRAME (tail
, frame
)
8509 if (FRAME_X_P (XFRAME (frame
))
8510 && FRAME_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
8512 /* Set this to t so that delete_frame won't get confused
8513 trying to find a replacement. */
8514 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
8515 delete_frame (frame
, Qnoelisp
);
8518 /* If DPYINFO is null, this means we didn't open the display in the
8519 first place, so don't try to close it. */
8522 /* We can not call XtCloseDisplay here because it calls XSync.
8523 XSync inside the error handler apparently hangs Emacs. On
8524 current Xt versions, this isn't needed either. */
8526 /* A long-standing GTK bug prevents proper disconnect handling
8527 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
8528 the resulting Glib error message loop filled a user's disk.
8529 To avoid this, kill Emacs unconditionally on disconnect. */
8530 shut_down_emacs (0, Qnil
);
8531 fprintf (stderr
, "%s\n\
8532 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
8533 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
8534 For details, see etc/PROBLEMS.\n",
8537 #endif /* USE_GTK */
8539 /* Indicate that this display is dead. */
8540 dpyinfo
->display
= 0;
8542 dpyinfo
->reference_count
--;
8543 dpyinfo
->terminal
->reference_count
--;
8544 if (dpyinfo
->reference_count
!= 0)
8545 /* We have just closed all frames on this display. */
8550 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
8551 Fdelete_terminal (tmp
, Qnoelisp
);
8555 if (terminal_list
== 0)
8557 fprintf (stderr
, "%s\n", error_msg
);
8558 Fkill_emacs (make_number (70));
8562 totally_unblock_input ();
8564 unbind_to (idx
, Qnil
);
8565 clear_waiting_for_input ();
8567 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
8568 IF_LINT (if (! terminal_list
) return; )
8570 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
8571 longjmp), because returning from this function would get us back into
8572 Xlib's code which will directly call `exit'. */
8573 error ("%s", error_msg
);
8576 /* We specifically use it before defining it, so that gcc doesn't inline it,
8577 otherwise gdb doesn't know how to properly put a breakpoint on it. */
8578 static void x_error_quitter (Display
*, XErrorEvent
*);
8580 /* This is the first-level handler for X protocol errors.
8581 It calls x_error_quitter or x_error_catcher. */
8584 x_error_handler (Display
*display
, XErrorEvent
*event
)
8586 #if defined USE_GTK && defined HAVE_GTK3
8587 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
8588 && event
->request_code
== X_SetInputFocus
)
8594 if (x_error_message
)
8595 x_error_catcher (display
, event
);
8597 x_error_quitter (display
, event
);
8601 /* This is the usual handler for X protocol errors.
8602 It kills all frames on the display that we got the error for.
8603 If that was the only one, it prints an error message and kills Emacs. */
8605 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
8607 /* On older GCC versions, just putting x_error_quitter
8608 after x_error_handler prevents inlining into the former. */
8610 static void NO_INLINE
8611 x_error_quitter (Display
*display
, XErrorEvent
*event
)
8613 char buf
[256], buf1
[356];
8615 /* Ignore BadName errors. They can happen because of fonts
8616 or colors that are not defined. */
8618 if (event
->error_code
== BadName
)
8621 /* Note that there is no real way portable across R3/R4 to get the
8622 original error handler. */
8624 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
8625 sprintf (buf1
, "X protocol error: %s on protocol request %d",
8626 buf
, event
->request_code
);
8627 x_connection_closed (display
, buf1
);
8631 /* This is the handler for X IO errors, always.
8632 It kills all frames on the display that we lost touch with.
8633 If that was the only one, it prints an error message and kills Emacs. */
8636 x_io_error_quitter (Display
*display
)
8640 snprintf (buf
, sizeof buf
, "Connection lost to X server `%s'",
8641 DisplayString (display
));
8642 x_connection_closed (display
, buf
);
8646 /* Changing the font of the frame. */
8648 /* Give frame F the font FONT-OBJECT as its default font. The return
8649 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
8650 frame. If it is negative, generate a new fontset from
8654 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
8656 struct font
*font
= XFONT_OBJECT (font_object
);
8660 fontset
= fontset_from_font (font_object
);
8661 FRAME_FONTSET (f
) = fontset
;
8662 if (FRAME_FONT (f
) == font
)
8663 /* This font is already set in frame F. There's nothing more to
8667 FRAME_FONT (f
) = font
;
8668 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
8669 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
8670 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
8672 #ifndef USE_X_TOOLKIT
8673 FRAME_MENU_BAR_HEIGHT (f
) = FRAME_MENU_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
);
8676 /* Compute character columns occupied by scrollbar.
8678 Don't do things differently for non-toolkit scrollbars
8680 unit
= FRAME_COLUMN_WIDTH (f
);
8681 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8682 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8683 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + unit
- 1) / unit
;
8685 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + unit
- 1) / unit
;
8687 if (FRAME_X_WINDOW (f
) != 0)
8689 /* Don't change the size of a tip frame; there's no point in
8690 doing it because it's done in Fx_show_tip, and it leads to
8691 problems because the tip frame has no widget. */
8692 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8693 adjust_frame_size (f
, FRAME_COLS (f
) * FRAME_COLUMN_WIDTH (f
),
8694 FRAME_LINES (f
) * FRAME_LINE_HEIGHT (f
), 3,
8700 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8703 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
8712 /***********************************************************************
8714 ***********************************************************************/
8720 /* XIM destroy callback function, which is called whenever the
8721 connection to input method XIM dies. CLIENT_DATA contains a
8722 pointer to the x_display_info structure corresponding to XIM. */
8725 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
8727 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8728 Lisp_Object frame
, tail
;
8732 /* No need to call XDestroyIC.. */
8733 FOR_EACH_FRAME (tail
, frame
)
8735 struct frame
*f
= XFRAME (frame
);
8736 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
8738 FRAME_XIC (f
) = NULL
;
8739 xic_free_xfontset (f
);
8743 /* No need to call XCloseIM. */
8744 dpyinfo
->xim
= NULL
;
8745 XFree (dpyinfo
->xim_styles
);
8749 #endif /* HAVE_X11R6 */
8751 /* Open the connection to the XIM server on display DPYINFO.
8752 RESOURCE_NAME is the resource name Emacs uses. */
8755 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
8763 XCloseIM (dpyinfo
->xim
);
8764 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8771 XIMCallback destroy
;
8774 /* Get supported styles and XIM values. */
8775 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8778 destroy
.callback
= xim_destroy_callback
;
8779 destroy
.client_data
= (XPointer
)dpyinfo
;
8780 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8786 #endif /* HAVE_XIM */
8787 dpyinfo
->xim
= NULL
;
8791 #ifdef HAVE_X11R6_XIM
8793 /* XIM instantiate callback function, which is called whenever an XIM
8794 server is available. DISPLAY is the display of the XIM.
8795 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8796 when the callback was registered. */
8799 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
8801 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8802 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8804 /* We don't support multiple XIM connections. */
8808 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8810 /* Create XIC for the existing frames on the same display, as long
8811 as they have no XIC. */
8812 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8814 Lisp_Object tail
, frame
;
8817 FOR_EACH_FRAME (tail
, frame
)
8819 struct frame
*f
= XFRAME (frame
);
8822 && FRAME_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8823 if (FRAME_XIC (f
) == NULL
)
8825 create_frame_xic (f
);
8826 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8827 xic_set_statusarea (f
);
8828 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8830 struct window
*w
= XWINDOW (f
->selected_window
);
8831 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8840 #endif /* HAVE_X11R6_XIM */
8843 /* Open a connection to the XIM server on display DPYINFO.
8844 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8845 connection only at the first time. On X11R6, open the connection
8846 in the XIM instantiate callback function. */
8849 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
8851 dpyinfo
->xim
= NULL
;
8855 #ifdef HAVE_X11R6_XIM
8856 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
8859 dpyinfo
->xim_callback_data
= xim_inst
;
8860 xim_inst
->dpyinfo
= dpyinfo
;
8861 xim_inst
->resource_name
= xstrdup (resource_name
);
8862 ret
= XRegisterIMInstantiateCallback
8863 (dpyinfo
->display
, dpyinfo
->xrdb
, xim_inst
->resource_name
,
8864 emacs_class
, xim_instantiate_callback
,
8865 /* This is XPointer in XFree86 but (XPointer *)
8866 on Tru64, at least, hence the configure test. */
8867 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8868 eassert (ret
== True
);
8869 #else /* not HAVE_X11R6_XIM */
8870 xim_open_dpy (dpyinfo
, resource_name
);
8871 #endif /* not HAVE_X11R6_XIM */
8873 #endif /* HAVE_XIM */
8877 /* Close the connection to the XIM server on display DPYINFO. */
8880 xim_close_dpy (struct x_display_info
*dpyinfo
)
8885 #ifdef HAVE_X11R6_XIM
8886 struct xim_inst_t
*xim_inst
= dpyinfo
->xim_callback_data
;
8888 if (dpyinfo
->display
)
8890 Bool ret
= XUnregisterIMInstantiateCallback
8891 (dpyinfo
->display
, dpyinfo
->xrdb
, xim_inst
->resource_name
,
8892 emacs_class
, xim_instantiate_callback
,
8893 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8894 eassert (ret
== True
);
8896 xfree (xim_inst
->resource_name
);
8898 #endif /* HAVE_X11R6_XIM */
8899 if (dpyinfo
->display
)
8900 XCloseIM (dpyinfo
->xim
);
8901 dpyinfo
->xim
= NULL
;
8902 XFree (dpyinfo
->xim_styles
);
8904 #endif /* HAVE_XIM */
8907 #endif /* not HAVE_X11R6_XIM */
8911 /* Calculate the absolute position in frame F
8912 from its current recorded position values and gravity. */
8915 x_calc_absolute_position (struct frame
*f
)
8917 int flags
= f
->size_hint_flags
;
8919 /* We have nothing to do if the current position
8920 is already for the top-left corner. */
8921 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8924 /* Treat negative positions as relative to the leftmost bottommost
8925 position that fits on the screen. */
8926 if (flags
& XNegative
)
8927 f
->left_pos
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
8928 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8931 int height
= FRAME_PIXEL_HEIGHT (f
);
8933 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8934 /* Something is fishy here. When using Motif, starting Emacs with
8935 `-g -0-0', the frame appears too low by a few pixels.
8937 This seems to be so because initially, while Emacs is starting,
8938 the column widget's height and the frame's pixel height are
8939 different. The column widget's height is the right one. In
8940 later invocations, when Emacs is up, the frame's pixel height
8943 It's not obvious where the initial small difference comes from.
8944 2000-12-01, gerd. */
8946 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8949 if (flags
& YNegative
)
8950 f
->top_pos
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
8951 - height
+ f
->top_pos
;
8954 /* The left_pos and top_pos
8955 are now relative to the top and left screen edges,
8956 so the flags should correspond. */
8957 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8960 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8961 to really change the position, and 0 when calling from
8962 x_make_frame_visible (in that case, XOFF and YOFF are the current
8963 position values). It is -1 when calling from x_set_frame_parameters,
8964 which means, do adjust for borders but don't change the gravity. */
8967 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8969 int modified_top
, modified_left
;
8971 if (change_gravity
> 0)
8975 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8977 f
->size_hint_flags
|= XNegative
;
8979 f
->size_hint_flags
|= YNegative
;
8980 f
->win_gravity
= NorthWestGravity
;
8982 x_calc_absolute_position (f
);
8985 x_wm_set_size_hint (f
, 0, false);
8987 modified_left
= f
->left_pos
;
8988 modified_top
= f
->top_pos
;
8990 if (change_gravity
!= 0 && FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8992 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8993 than the WM decorations. So we use the calculated offset instead
8994 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8995 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8996 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8999 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9000 modified_left
, modified_top
);
9002 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
9003 FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
);
9005 /* change_gravity is non-zero when this function is called from Lisp to
9006 programmatically move a frame. In that case, we call
9007 x_check_expected_move to discover if we have a "Type A" or "Type B"
9008 window manager, and, for a "Type A" window manager, adjust the position
9011 We call x_check_expected_move if a programmatic move occurred, and
9012 either the window manager type (A/B) is unknown or it is Type A but we
9013 need to compute the top/left offset adjustment for this frame. */
9015 if (change_gravity
!= 0
9016 && (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
9017 || (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
9018 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
9019 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
9020 x_check_expected_move (f
, modified_left
, modified_top
);
9025 /* Return true if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
9026 on the root window for frame F contains ATOMNAME.
9027 This is how a WM check shall be done according to the Window Manager
9028 Specification/Extended Window Manager Hints at
9029 http://freedesktop.org/wiki/Specifications/wm-spec. */
9032 wm_supports (struct frame
*f
, Atom want_atom
)
9035 unsigned long actual_size
, bytes_remaining
;
9036 int i
, rc
, actual_format
;
9038 Window wmcheck_window
;
9039 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9040 Window target_window
= dpyinfo
->root_window
;
9041 int max_len
= 65536;
9042 Display
*dpy
= FRAME_X_DISPLAY (f
);
9043 unsigned char *tmp_data
= NULL
;
9044 Atom target_type
= XA_WINDOW
;
9048 x_catch_errors (dpy
);
9049 rc
= XGetWindowProperty (dpy
, target_window
,
9050 dpyinfo
->Xatom_net_supporting_wm_check
,
9051 0, max_len
, False
, target_type
,
9052 &actual_type
, &actual_format
, &actual_size
,
9053 &bytes_remaining
, &tmp_data
);
9055 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
9057 if (tmp_data
) XFree (tmp_data
);
9058 x_uncatch_errors ();
9063 wmcheck_window
= *(Window
*) tmp_data
;
9066 /* Check if window exists. */
9067 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
9069 if (x_had_errors_p (dpy
))
9071 x_uncatch_errors ();
9076 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
9078 /* Window changed, reload atoms */
9079 if (dpyinfo
->net_supported_atoms
!= NULL
)
9080 XFree (dpyinfo
->net_supported_atoms
);
9081 dpyinfo
->net_supported_atoms
= NULL
;
9082 dpyinfo
->nr_net_supported_atoms
= 0;
9083 dpyinfo
->net_supported_window
= 0;
9085 target_type
= XA_ATOM
;
9087 rc
= XGetWindowProperty (dpy
, target_window
,
9088 dpyinfo
->Xatom_net_supported
,
9089 0, max_len
, False
, target_type
,
9090 &actual_type
, &actual_format
, &actual_size
,
9091 &bytes_remaining
, &tmp_data
);
9093 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
9095 if (tmp_data
) XFree (tmp_data
);
9096 x_uncatch_errors ();
9101 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
9102 dpyinfo
->nr_net_supported_atoms
= actual_size
;
9103 dpyinfo
->net_supported_window
= wmcheck_window
;
9108 for (i
= 0; !ret
&& i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
9109 ret
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
9111 x_uncatch_errors ();
9118 set_wm_state (Lisp_Object frame
, bool add
, Atom atom
, Atom value
)
9120 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (XFRAME (frame
));
9122 x_send_client_event (frame
, make_number (0), frame
,
9123 dpyinfo
->Xatom_net_wm_state
,
9125 /* 1 = add, 0 = remove */
9129 (make_fixnum_or_float (atom
),
9131 ? list1 (make_fixnum_or_float (value
))
9136 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
9139 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9141 XSETFRAME (frame
, f
);
9143 set_wm_state (frame
, !NILP (new_value
),
9144 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
9147 /* Return the current _NET_WM_STATE.
9148 SIZE_STATE is set to one of the FULLSCREEN_* values.
9149 Set *STICKY to the sticky state.
9151 Return true iff we are not hidden. */
9154 get_current_wm_state (struct frame
*f
,
9160 unsigned long actual_size
, bytes_remaining
;
9161 int i
, rc
, actual_format
;
9162 bool is_hidden
= false;
9163 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9164 long max_len
= 65536;
9165 Display
*dpy
= FRAME_X_DISPLAY (f
);
9166 unsigned char *tmp_data
= NULL
;
9167 Atom target_type
= XA_ATOM
;
9170 *size_state
= FULLSCREEN_NONE
;
9173 x_catch_errors (dpy
);
9174 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
9175 0, max_len
, False
, target_type
,
9176 &actual_type
, &actual_format
, &actual_size
,
9177 &bytes_remaining
, &tmp_data
);
9179 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
9181 if (tmp_data
) XFree (tmp_data
);
9182 x_uncatch_errors ();
9184 return !FRAME_ICONIFIED_P (f
);
9187 x_uncatch_errors ();
9189 for (i
= 0; i
< actual_size
; ++i
)
9191 Atom a
= ((Atom
*)tmp_data
)[i
];
9192 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
9194 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
9196 if (*size_state
== FULLSCREEN_HEIGHT
)
9197 *size_state
= FULLSCREEN_MAXIMIZED
;
9199 *size_state
= FULLSCREEN_WIDTH
;
9201 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
9203 if (*size_state
== FULLSCREEN_WIDTH
)
9204 *size_state
= FULLSCREEN_MAXIMIZED
;
9206 *size_state
= FULLSCREEN_HEIGHT
;
9208 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
9209 *size_state
= FULLSCREEN_BOTH
;
9210 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
9214 if (tmp_data
) XFree (tmp_data
);
9219 /* Do fullscreen as specified in extended window manager hints */
9222 do_ewmh_fullscreen (struct frame
*f
)
9224 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9225 bool have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
9229 get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
9231 /* Some window managers don't say they support _NET_WM_STATE, but they do say
9232 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
9234 have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
9236 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
9240 XSETFRAME (frame
, f
);
9242 /* Keep number of calls to set_wm_state as low as possible.
9243 Some window managers, or possible Gtk+, hangs when too many
9244 are sent at once. */
9245 switch (f
->want_fullscreen
)
9247 case FULLSCREEN_BOTH
:
9248 if (cur
!= FULLSCREEN_BOTH
)
9249 set_wm_state (frame
, true, dpyinfo
->Xatom_net_wm_state_fullscreen
,
9252 case FULLSCREEN_WIDTH
:
9253 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
9254 || cur
== FULLSCREEN_MAXIMIZED
)
9255 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
9256 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
9257 if (cur
!= FULLSCREEN_MAXIMIZED
)
9258 set_wm_state (frame
, true,
9259 dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
9261 case FULLSCREEN_HEIGHT
:
9262 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
9263 || cur
== FULLSCREEN_MAXIMIZED
)
9264 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
9265 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
9266 if (cur
!= FULLSCREEN_MAXIMIZED
)
9267 set_wm_state (frame
, true,
9268 dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
9270 case FULLSCREEN_MAXIMIZED
:
9271 if (cur
== FULLSCREEN_BOTH
)
9272 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
9274 set_wm_state (frame
, true,
9275 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
9276 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
9278 case FULLSCREEN_NONE
:
9279 if (cur
== FULLSCREEN_BOTH
)
9280 set_wm_state (frame
, false, dpyinfo
->Xatom_net_wm_state_fullscreen
,
9283 set_wm_state (frame
, false,
9284 dpyinfo
->Xatom_net_wm_state_maximized_horz
,
9285 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
9288 f
->want_fullscreen
= FULLSCREEN_NONE
;
9292 return have_net_atom
;
9296 XTfullscreen_hook (struct frame
*f
)
9298 if (FRAME_VISIBLE_P (f
))
9301 x_check_fullscreen (f
);
9309 x_handle_net_wm_state (struct frame
*f
, const XPropertyEvent
*event
)
9311 int value
= FULLSCREEN_NONE
;
9313 bool sticky
= false;
9314 bool not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
9319 case FULLSCREEN_WIDTH
:
9322 case FULLSCREEN_HEIGHT
:
9325 case FULLSCREEN_BOTH
:
9328 case FULLSCREEN_MAXIMIZED
:
9333 store_frame_param (f
, Qfullscreen
, lval
);
9334 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
9339 /* Check if we need to resize the frame due to a fullscreen request.
9340 If so needed, resize the frame. */
9342 x_check_fullscreen (struct frame
*f
)
9344 if (do_ewmh_fullscreen (f
))
9347 if (f
->output_data
.x
->parent_desc
!= FRAME_DISPLAY_INFO (f
)->root_window
)
9348 return; /* Only fullscreen without WM or with EWM hints (above). */
9350 /* Setting fullscreen to nil doesn't do anything. We could save the
9351 last non-fullscreen size and restore it, but it seems like a
9352 lot of work for this unusual case (no window manager running). */
9354 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
9356 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
9357 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9359 switch (f
->want_fullscreen
)
9361 /* No difference between these two when there is no WM */
9362 case FULLSCREEN_BOTH
:
9363 case FULLSCREEN_MAXIMIZED
:
9364 width
= x_display_pixel_width (dpyinfo
);
9365 height
= x_display_pixel_height (dpyinfo
);
9367 case FULLSCREEN_WIDTH
:
9368 width
= x_display_pixel_width (dpyinfo
);
9370 case FULLSCREEN_HEIGHT
:
9371 height
= x_display_pixel_height (dpyinfo
);
9374 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9379 /* This function is called by x_set_offset to determine whether the window
9380 manager interfered with the positioning of the frame. Type A window
9381 managers position the surrounding window manager decorations a small
9382 amount above and left of the user-supplied position. Type B window
9383 managers position the surrounding window manager decorations at the
9384 user-specified position. If we detect a Type A window manager, we
9385 compensate by moving the window right and down by the proper amount. */
9388 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
9390 int current_left
= 0, current_top
= 0;
9392 /* x_real_positions returns the left and top offsets of the outermost
9393 window manager window around the frame. */
9395 x_real_positions (f
, ¤t_left
, ¤t_top
);
9397 if (current_left
!= expected_left
|| current_top
!= expected_top
)
9399 /* It's a "Type A" window manager. */
9404 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
9405 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
9406 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
9408 /* Now fix the mispositioned frame's location. */
9410 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
9411 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
9413 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9414 adjusted_left
, adjusted_top
);
9416 x_sync_with_move (f
, expected_left
, expected_top
, false);
9419 /* It's a "Type B" window manager. We don't have to adjust the
9420 frame's position. */
9422 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
9426 /* Wait for XGetGeometry to return up-to-date position information for a
9427 recently-moved frame. Call this immediately after calling XMoveWindow.
9428 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
9429 frame has been moved to, so we use a fuzzy position comparison instead
9430 of an exact comparison. */
9433 x_sync_with_move (struct frame
*f
, int left
, int top
, bool fuzzy
)
9437 while (count
++ < 50)
9439 int current_left
= 0, current_top
= 0;
9441 /* In theory, this call to XSync only needs to happen once, but in
9442 practice, it doesn't seem to work, hence the need for the surrounding
9445 XSync (FRAME_X_DISPLAY (f
), False
);
9446 x_real_positions (f
, ¤t_left
, ¤t_top
);
9450 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
9453 if (eabs (current_left
- left
) <= 10
9454 && eabs (current_top
- top
) <= 40)
9457 else if (current_left
== left
&& current_top
== top
)
9461 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
9462 will then return up-to-date position info. */
9464 wait_reading_process_output (0, 500000000, 0, false, Qnil
, NULL
, 0);
9468 /* Wait for an event on frame F matching EVENTTYPE. */
9470 x_wait_for_event (struct frame
*f
, int eventtype
)
9472 int level
= interrupt_input_blocked
;
9475 struct timespec tmo
, tmo_at
, time_now
;
9476 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
9478 f
->wait_event_type
= eventtype
;
9480 /* Set timeout to 0.1 second. Hopefully not noticeable.
9481 Maybe it should be configurable. */
9482 tmo
= make_timespec (0, 100 * 1000 * 1000);
9483 tmo_at
= timespec_add (current_timespec (), tmo
);
9485 while (f
->wait_event_type
)
9487 pending_signals
= true;
9488 totally_unblock_input ();
9489 /* XTread_socket is called after unblock. */
9491 interrupt_input_blocked
= level
;
9496 time_now
= current_timespec ();
9497 if (timespec_cmp (tmo_at
, time_now
) < 0)
9500 tmo
= timespec_sub (tmo_at
, time_now
);
9501 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
9502 break; /* Timeout */
9505 f
->wait_event_type
= 0;
9509 /* Change the size of frame F's X window to WIDTH/HEIGHT in the case F
9510 doesn't have a widget. If CHANGE_GRAVITY, change to
9511 top-left-corner window gravity for this size change and subsequent
9512 size changes. Otherwise leave the window gravity unchanged. */
9515 x_set_window_size_1 (struct frame
*f
, bool change_gravity
,
9516 int width
, int height
, bool pixelwise
)
9518 int pixelwidth
, pixelheight
;
9520 pixelwidth
= (pixelwise
9521 ? FRAME_TEXT_TO_PIXEL_WIDTH (f
, width
)
9522 : FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, width
));
9523 pixelheight
= ((pixelwise
9524 ? FRAME_TEXT_TO_PIXEL_HEIGHT (f
, height
)
9525 : FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, height
)));
9527 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
9528 x_wm_set_size_hint (f
, 0, false);
9529 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9530 pixelwidth
, pixelheight
+ FRAME_MENUBAR_HEIGHT (f
));
9533 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
9534 receive in the ConfigureNotify event; if we get what we asked
9535 for, then the event won't cause the screen to become garbaged, so
9536 we have to make sure to do it here. */
9537 SET_FRAME_GARBAGED (f
);
9539 /* Now, strictly speaking, we can't be sure that this is accurate,
9540 but the window manager will get around to dealing with the size
9541 change request eventually, and we'll hear how it went when the
9542 ConfigureNotify event gets here.
9544 We could just not bother storing any of this information here,
9545 and let the ConfigureNotify event set everything up, but that
9546 might be kind of confusing to the Lisp code, since size changes
9547 wouldn't be reported in the frame parameters until some random
9548 point in the future when the ConfigureNotify event arrives.
9550 Pass true for DELAY since we can't run Lisp code inside of
9553 /* But the ConfigureNotify may in fact never arrive, and then this is
9554 not right if the frame is visible. Instead wait (with timeout)
9555 for the ConfigureNotify. */
9556 if (FRAME_VISIBLE_P (f
))
9557 x_wait_for_event (f
, ConfigureNotify
);
9560 change_frame_size (f
, pixelwidth
, pixelheight
, false, true, false, true);
9566 /* Call this to change the size of frame F's x-window.
9567 If CHANGE_GRAVITY, change to top-left-corner window gravity
9568 for this size change and subsequent size changes.
9569 Otherwise we leave the window gravity unchanged. */
9572 x_set_window_size (struct frame
*f
, bool change_gravity
,
9573 int width
, int height
, bool pixelwise
)
9577 /* The following breaks our calculations. If it's really needed,
9578 think of something else. */
9580 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
9582 int text_width
, text_height
;
9584 /* When the frame is maximized/fullscreen or running under for
9585 example Xmonad, x_set_window_size_1 will be a no-op.
9586 In that case, the right thing to do is extend rows/width to
9587 the current frame size. We do that first if x_set_window_size_1
9588 turns out to not be a no-op (there is no way to know).
9589 The size will be adjusted again if the frame gets a
9590 ConfigureNotify event as a result of x_set_window_size. */
9591 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
9592 #ifdef USE_X_TOOLKIT
9593 /* The menu bar is not part of text lines. The tool bar
9595 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
9597 text_width
= FRAME_PIXEL_TO_TEXT_WIDTH (f
, FRAME_PIXEL_WIDTH (f
));
9598 text_height
= FRAME_PIXEL_TO_TEXT_HEIGHT (f
, pixelh
);
9600 change_frame_size (f
, text_width
, text_height
, false, true, false, true);
9605 if (FRAME_GTK_WIDGET (f
))
9607 xg_frame_set_char_size (f
, width
* FRAME_COLUMN_WIDTH (f
),
9608 height
* FRAME_LINE_HEIGHT (f
));
9610 xg_frame_set_char_size (f
, width
, height
);
9612 x_set_window_size_1 (f
, change_gravity
, width
, height
, pixelwise
);
9613 #else /* not USE_GTK */
9615 x_set_window_size_1 (f
, change_gravity
, width
, height
, pixelwise
);
9616 x_clear_under_internal_border (f
);
9618 #endif /* not USE_GTK */
9620 /* If cursor was outside the new size, mark it as off. */
9621 mark_window_cursors_off (XWINDOW (f
->root_window
));
9623 /* Clear out any recollection of where the mouse highlighting was,
9624 since it might be in a place that's outside the new frame size.
9625 Actually checking whether it is outside is a pain in the neck,
9626 so don't try--just let the highlighting be done afresh with new size. */
9627 cancel_mouse_face (f
);
9631 do_pending_window_change (false);
9634 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
9637 frame_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
9641 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9642 0, 0, 0, 0, pix_x
, pix_y
);
9646 /* Raise frame F. */
9649 x_raise_frame (struct frame
*f
)
9652 if (FRAME_VISIBLE_P (f
))
9653 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9654 XFlush (FRAME_X_DISPLAY (f
));
9658 /* Lower frame F. */
9661 x_lower_frame (struct frame
*f
)
9663 if (FRAME_VISIBLE_P (f
))
9666 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9667 XFlush (FRAME_X_DISPLAY (f
));
9672 /* Request focus with XEmbed */
9675 xembed_request_focus (struct frame
*f
)
9677 /* See XEmbed Protocol Specification at
9678 http://freedesktop.org/wiki/Specifications/xembed-spec */
9679 if (FRAME_VISIBLE_P (f
))
9680 xembed_send_message (f
, CurrentTime
,
9681 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
9684 /* Activate frame with Extended Window Manager Hints */
9687 x_ewmh_activate_frame (struct frame
*f
)
9689 /* See Window Manager Specification/Extended Window Manager Hints at
9690 http://freedesktop.org/wiki/Specifications/wm-spec */
9692 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9694 if (FRAME_VISIBLE_P (f
) && wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
9697 XSETFRAME (frame
, f
);
9698 x_send_client_event (frame
, make_number (0), frame
,
9699 dpyinfo
->Xatom_net_active_window
,
9701 list2i (1, dpyinfo
->last_user_time
));
9706 XTframe_raise_lower (struct frame
*f
, bool raise_flag
)
9714 /* XEmbed implementation. */
9716 #if defined USE_X_TOOLKIT || ! defined USE_GTK
9718 /* XEmbed implementation. */
9720 #define XEMBED_VERSION 0
9723 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
9725 unsigned long data
[2];
9726 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9728 data
[0] = XEMBED_VERSION
;
9731 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9732 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
9733 32, PropModeReplace
, (unsigned char *) data
, 2);
9735 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
9738 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
9739 long int detail
, long int data1
, long int data2
)
9743 event
.xclient
.type
= ClientMessage
;
9744 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9745 event
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9746 event
.xclient
.format
= 32;
9747 event
.xclient
.data
.l
[0] = t
;
9748 event
.xclient
.data
.l
[1] = msg
;
9749 event
.xclient
.data
.l
[2] = detail
;
9750 event
.xclient
.data
.l
[3] = data1
;
9751 event
.xclient
.data
.l
[4] = data2
;
9753 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9754 False
, NoEventMask
, &event
);
9755 XSync (FRAME_X_DISPLAY (f
), False
);
9758 /* Change of visibility. */
9760 /* This tries to wait until the frame is really visible.
9761 However, if the window manager asks the user where to position
9762 the frame, this will return before the user finishes doing that.
9763 The frame will not actually be visible at that time,
9764 but it will become visible later when the window manager
9765 finishes with it. */
9768 x_make_frame_visible (struct frame
*f
)
9770 int original_top
, original_left
;
9775 x_set_bitmap_icon (f
);
9777 if (! FRAME_VISIBLE_P (f
))
9779 /* We test FRAME_GARBAGED_P here to make sure we don't
9780 call x_set_offset a second time
9781 if we get to x_make_frame_visible a second time
9782 before the window gets really visible. */
9783 if (! FRAME_ICONIFIED_P (f
)
9784 && ! FRAME_X_EMBEDDED_P (f
)
9785 && ! f
->output_data
.x
->asked_for_visible
)
9786 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9788 f
->output_data
.x
->asked_for_visible
= true;
9790 if (! EQ (Vx_no_window_manager
, Qt
))
9791 x_wm_set_window_state (f
, NormalState
);
9792 #ifdef USE_X_TOOLKIT
9793 if (FRAME_X_EMBEDDED_P (f
))
9794 xembed_set_info (f
, XEMBED_MAPPED
);
9797 /* This was XtPopup, but that did nothing for an iconified frame. */
9798 XtMapWidget (f
->output_data
.x
->widget
);
9800 #else /* not USE_X_TOOLKIT */
9802 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9803 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9805 if (FRAME_X_EMBEDDED_P (f
))
9806 xembed_set_info (f
, XEMBED_MAPPED
);
9808 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9809 #endif /* not USE_GTK */
9810 #endif /* not USE_X_TOOLKIT */
9813 XFlush (FRAME_X_DISPLAY (f
));
9815 /* Synchronize to ensure Emacs knows the frame is visible
9816 before we do anything else. We do this loop with input not blocked
9817 so that incoming events are handled. */
9820 /* This must be before UNBLOCK_INPUT
9821 since events that arrive in response to the actions above
9822 will set it when they are handled. */
9823 bool previously_visible
= f
->output_data
.x
->has_been_visible
;
9825 original_left
= f
->left_pos
;
9826 original_top
= f
->top_pos
;
9828 /* This must come after we set COUNT. */
9831 /* We unblock here so that arriving X events are processed. */
9833 /* Now move the window back to where it was "supposed to be".
9834 But don't do it if the gravity is negative.
9835 When the gravity is negative, this uses a position
9836 that is 3 pixels too low. Perhaps that's really the border width.
9838 Don't do this if the window has never been visible before,
9839 because the window manager may choose the position
9840 and we don't want to override it. */
9842 if (! FRAME_VISIBLE_P (f
)
9843 && ! FRAME_ICONIFIED_P (f
)
9844 && ! FRAME_X_EMBEDDED_P (f
)
9845 && f
->win_gravity
== NorthWestGravity
9846 && previously_visible
)
9850 unsigned int width
, height
, border
, depth
;
9854 /* On some window managers (such as FVWM) moving an existing
9855 window, even to the same place, causes the window manager
9856 to introduce an offset. This can cause the window to move
9857 to an unexpected location. Check the geometry (a little
9858 slow here) and then verify that the window is in the right
9859 place. If the window is not in the right place, move it
9860 there, and take the potential window manager hit. */
9861 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9862 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9864 if (original_left
!= x
|| original_top
!= y
)
9865 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9866 original_left
, original_top
);
9871 XSETFRAME (frame
, f
);
9873 /* Process X events until a MapNotify event has been seen. */
9874 while (!FRAME_VISIBLE_P (f
))
9876 /* Force processing of queued events. */
9879 /* If on another desktop, the deiconify/map may be ignored and the
9880 frame never becomes visible. XMonad does this.
9881 Prevent an endless loop. */
9882 if (FRAME_ICONIFIED_P (f
) && ++tries
> 100)
9885 /* This hack is still in use at least for Cygwin. See
9886 http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00351.html.
9888 Machines that do polling rather than SIGIO have been
9889 observed to go into a busy-wait here. So we'll fake an
9890 alarm signal to let the handler know that there's something
9891 to be read. We used to raise a real alarm, but it seems
9892 that the handler isn't always enabled here. This is
9894 if (input_polling_used ())
9896 /* It could be confusing if a real alarm arrives while
9897 processing the fake one. Turn it off and let the
9898 handler reset it. */
9899 int old_poll_suppress_count
= poll_suppress_count
;
9900 poll_suppress_count
= 1;
9901 poll_for_input_1 ();
9902 poll_suppress_count
= old_poll_suppress_count
;
9905 if (XPending (FRAME_X_DISPLAY (f
)))
9908 XNextEvent (FRAME_X_DISPLAY (f
), &xev
);
9909 x_dispatch_event (&xev
, FRAME_X_DISPLAY (f
));
9915 /* Change from mapped state to withdrawn state. */
9917 /* Make the frame visible (mapped and not iconified). */
9920 x_make_frame_invisible (struct frame
*f
)
9924 /* Use the frame's outermost window, not the one we normally draw on. */
9925 window
= FRAME_OUTER_WINDOW (f
);
9927 /* Don't keep the highlight on an invisible frame. */
9928 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9929 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9933 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9934 that the current position of the window is user-specified, rather than
9935 program-specified, so that when the window is mapped again, it will be
9936 placed at the same location, without forcing the user to position it
9937 by hand again (they have already done that once for this window.) */
9938 x_wm_set_size_hint (f
, 0, true);
9941 if (FRAME_GTK_OUTER_WIDGET (f
))
9942 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9945 if (FRAME_X_EMBEDDED_P (f
))
9946 xembed_set_info (f
, 0);
9951 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9952 DefaultScreen (FRAME_X_DISPLAY (f
))))
9955 error ("Can't notify window manager of window withdrawal");
9959 /* We can't distinguish this from iconification
9960 just by the event that we get from the server.
9961 So we can't win using the usual strategy of letting
9962 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9963 and synchronize with the server to make sure we agree. */
9964 SET_FRAME_VISIBLE (f
, 0);
9965 SET_FRAME_ICONIFIED (f
, false);
9972 /* Change window state from mapped to iconified. */
9975 x_iconify_frame (struct frame
*f
)
9977 #ifdef USE_X_TOOLKIT
9981 /* Don't keep the highlight on an invisible frame. */
9982 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9983 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9985 if (FRAME_ICONIFIED_P (f
))
9990 x_set_bitmap_icon (f
);
9992 #if defined (USE_GTK)
9993 if (FRAME_GTK_OUTER_WIDGET (f
))
9995 if (! FRAME_VISIBLE_P (f
))
9996 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9998 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9999 SET_FRAME_VISIBLE (f
, 0);
10000 SET_FRAME_ICONIFIED (f
, true);
10006 #ifdef USE_X_TOOLKIT
10008 if (! FRAME_VISIBLE_P (f
))
10010 if (! EQ (Vx_no_window_manager
, Qt
))
10011 x_wm_set_window_state (f
, IconicState
);
10012 /* This was XtPopup, but that did nothing for an iconified frame. */
10013 XtMapWidget (f
->output_data
.x
->widget
);
10014 /* The server won't give us any event to indicate
10015 that an invisible frame was changed to an icon,
10016 so we have to record it here. */
10017 SET_FRAME_VISIBLE (f
, 0);
10018 SET_FRAME_ICONIFIED (f
, true);
10023 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
10024 XtWindow (f
->output_data
.x
->widget
),
10025 DefaultScreen (FRAME_X_DISPLAY (f
)));
10029 error ("Can't notify window manager of iconification");
10031 SET_FRAME_ICONIFIED (f
, true);
10032 SET_FRAME_VISIBLE (f
, 0);
10035 XFlush (FRAME_X_DISPLAY (f
));
10037 #else /* not USE_X_TOOLKIT */
10039 /* Make sure the X server knows where the window should be positioned,
10040 in case the user deiconifies with the window manager. */
10041 if (! FRAME_VISIBLE_P (f
)
10042 && ! FRAME_ICONIFIED_P (f
)
10043 && ! FRAME_X_EMBEDDED_P (f
))
10044 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
10046 /* Since we don't know which revision of X we're running, we'll use both
10047 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
10049 /* X11R4: send a ClientMessage to the window manager using the
10050 WM_CHANGE_STATE type. */
10054 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
10055 msg
.xclient
.type
= ClientMessage
;
10056 msg
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
10057 msg
.xclient
.format
= 32;
10058 msg
.xclient
.data
.l
[0] = IconicState
;
10060 if (! XSendEvent (FRAME_X_DISPLAY (f
),
10061 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
10063 SubstructureRedirectMask
| SubstructureNotifyMask
,
10067 error ("Can't notify window manager of iconification");
10071 /* X11R3: set the initial_state field of the window manager hints to
10073 x_wm_set_window_state (f
, IconicState
);
10075 if (!FRAME_VISIBLE_P (f
))
10077 /* If the frame was withdrawn, before, we must map it. */
10078 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10081 SET_FRAME_ICONIFIED (f
, true);
10082 SET_FRAME_VISIBLE (f
, 0);
10084 XFlush (FRAME_X_DISPLAY (f
));
10086 #endif /* not USE_X_TOOLKIT */
10090 /* Free X resources of frame F. */
10093 x_free_frame_resources (struct frame
*f
)
10095 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10096 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
10097 #ifdef USE_X_TOOLKIT
10099 struct scroll_bar
*b
;
10104 /* If a display connection is dead, don't try sending more
10105 commands to the X server. */
10106 if (dpyinfo
->display
)
10108 /* Always exit with visible pointer to avoid weird issue
10109 with Xfixes (Bug#17609). */
10110 if (f
->pointer_invisible
)
10111 FRAME_DISPLAY_INFO (f
)->toggle_visible_pointer (f
, 0);
10113 /* We must free faces before destroying windows because some
10114 font-driver (e.g. xft) access a window while finishing a
10116 free_frame_faces (f
);
10118 if (f
->output_data
.x
->icon_desc
)
10119 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
10121 #ifdef USE_X_TOOLKIT
10122 /* Explicitly destroy the scroll bars of the frame. Without
10123 this, we get "BadDrawable" errors from the toolkit later on,
10124 presumably from expose events generated for the disappearing
10125 toolkit scroll bars. */
10126 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
10128 b
= XSCROLL_BAR (bar
);
10129 x_scroll_bar_remove (b
);
10135 free_frame_xic (f
);
10138 #ifdef USE_X_TOOLKIT
10139 if (f
->output_data
.x
->widget
)
10141 XtDestroyWidget (f
->output_data
.x
->widget
);
10142 f
->output_data
.x
->widget
= NULL
;
10144 /* Tooltips don't have widgets, only a simple X window, even if
10145 we are using a toolkit. */
10146 else if (FRAME_X_WINDOW (f
))
10147 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10149 free_frame_menubar (f
);
10151 if (f
->shell_position
)
10152 xfree (f
->shell_position
);
10153 #else /* !USE_X_TOOLKIT */
10156 xg_free_frame_widgets (f
);
10157 #endif /* USE_GTK */
10159 if (FRAME_X_WINDOW (f
))
10160 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10161 #endif /* !USE_X_TOOLKIT */
10163 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
10164 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
10165 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
10166 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
10167 unload_color (f
, f
->output_data
.x
->border_pixel
);
10168 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
10170 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
10171 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
10172 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
10173 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
10174 #if defined (USE_LUCID) && defined (USE_TOOLKIT_SCROLL_BARS)
10175 /* Scrollbar shadow colors. */
10176 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
10177 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
10178 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
10179 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
10180 #endif /* USE_LUCID && USE_TOOLKIT_SCROLL_BARS */
10181 if (f
->output_data
.x
->white_relief
.pixel
!= -1)
10182 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
10183 if (f
->output_data
.x
->black_relief
.pixel
!= -1)
10184 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
10188 /* Free extra GCs allocated by x_setup_relief_colors. */
10189 if (f
->output_data
.x
->white_relief
.gc
)
10191 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
10192 f
->output_data
.x
->white_relief
.gc
= 0;
10194 if (f
->output_data
.x
->black_relief
.gc
)
10196 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
10197 f
->output_data
.x
->black_relief
.gc
= 0;
10200 /* Free cursors. */
10201 if (f
->output_data
.x
->text_cursor
!= 0)
10202 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->text_cursor
);
10203 if (f
->output_data
.x
->nontext_cursor
!= 0)
10204 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->nontext_cursor
);
10205 if (f
->output_data
.x
->modeline_cursor
!= 0)
10206 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->modeline_cursor
);
10207 if (f
->output_data
.x
->hand_cursor
!= 0)
10208 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->hand_cursor
);
10209 if (f
->output_data
.x
->hourglass_cursor
!= 0)
10210 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->hourglass_cursor
);
10211 if (f
->output_data
.x
->horizontal_drag_cursor
!= 0)
10212 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->horizontal_drag_cursor
);
10213 if (f
->output_data
.x
->vertical_drag_cursor
!= 0)
10214 XFreeCursor (FRAME_X_DISPLAY (f
), f
->output_data
.x
->vertical_drag_cursor
);
10216 XFlush (FRAME_X_DISPLAY (f
));
10219 xfree (f
->output_data
.x
->saved_menu_event
);
10220 xfree (f
->output_data
.x
);
10221 f
->output_data
.x
= NULL
;
10223 if (f
== dpyinfo
->x_focus_frame
)
10224 dpyinfo
->x_focus_frame
= 0;
10225 if (f
== dpyinfo
->x_focus_event_frame
)
10226 dpyinfo
->x_focus_event_frame
= 0;
10227 if (f
== dpyinfo
->x_highlight_frame
)
10228 dpyinfo
->x_highlight_frame
= 0;
10229 if (f
== hlinfo
->mouse_face_mouse_frame
)
10230 reset_mouse_highlight (hlinfo
);
10236 /* Destroy the X window of frame F. */
10239 x_destroy_window (struct frame
*f
)
10241 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
10243 /* If a display connection is dead, don't try sending more
10244 commands to the X server. */
10245 if (dpyinfo
->display
!= 0)
10246 x_free_frame_resources (f
);
10248 dpyinfo
->reference_count
--;
10252 /* Setting window manager hints. */
10254 /* Set the normal size hints for the window manager, for frame F.
10255 FLAGS is the flags word to use--or 0 meaning preserve the flags
10256 that the window now has.
10257 If USER_POSITION, set the USPosition
10258 flag (this is useful when FLAGS is 0).
10259 The GTK version is in gtkutils.c. */
10263 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
10265 XSizeHints size_hints
;
10266 Window window
= FRAME_OUTER_WINDOW (f
);
10271 #ifdef USE_X_TOOLKIT
10272 if (f
->output_data
.x
->widget
)
10274 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
10279 /* Setting PMaxSize caused various problems. */
10280 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
10282 size_hints
.x
= f
->left_pos
;
10283 size_hints
.y
= f
->top_pos
;
10285 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
10286 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
10288 size_hints
.width_inc
= frame_resize_pixelwise
? 1 : FRAME_COLUMN_WIDTH (f
);
10289 size_hints
.height_inc
= frame_resize_pixelwise
? 1 : FRAME_LINE_HEIGHT (f
);
10291 size_hints
.max_width
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
10292 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
10293 size_hints
.max_height
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
10294 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
10296 /* Calculate the base and minimum sizes. */
10298 int base_width
, base_height
;
10299 int min_rows
= 0, min_cols
= 0;
10301 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
10302 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
10304 if (frame_resize_pixelwise
)
10305 /* Needed to prevent a bad protocol error crash when making the
10306 frame size very small. */
10308 min_cols
= 2 * min_cols
;
10309 min_rows
= 2 * min_rows
;
10312 /* The window manager uses the base width hints to calculate the
10313 current number of rows and columns in the frame while
10314 resizing; min_width and min_height aren't useful for this
10315 purpose, since they might not give the dimensions for a
10316 zero-row, zero-column frame.
10318 We use the base_width and base_height members if we have
10319 them; otherwise, we set the min_width and min_height members
10320 to the size for a zero x zero frame. */
10322 size_hints
.flags
|= PBaseSize
;
10323 size_hints
.base_width
= base_width
;
10324 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
10325 size_hints
.min_width
= base_width
+ min_cols
* FRAME_COLUMN_WIDTH (f
);
10326 size_hints
.min_height
= base_height
+ min_rows
* FRAME_LINE_HEIGHT (f
);
10329 /* If we don't need the old flags, we don't need the old hint at all. */
10332 size_hints
.flags
|= flags
;
10337 XSizeHints hints
; /* Sometimes I hate X Windows... */
10338 long supplied_return
;
10341 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
10345 size_hints
.flags
|= flags
;
10350 if (hints
.flags
& PSize
)
10351 size_hints
.flags
|= PSize
;
10352 if (hints
.flags
& PPosition
)
10353 size_hints
.flags
|= PPosition
;
10354 if (hints
.flags
& USPosition
)
10355 size_hints
.flags
|= USPosition
;
10356 if (hints
.flags
& USSize
)
10357 size_hints
.flags
|= USSize
;
10364 size_hints
.win_gravity
= f
->win_gravity
;
10365 size_hints
.flags
|= PWinGravity
;
10369 size_hints
.flags
&= ~ PPosition
;
10370 size_hints
.flags
|= USPosition
;
10372 #endif /* PWinGravity */
10374 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
10376 #endif /* not USE_GTK */
10378 /* Used for IconicState or NormalState */
10381 x_wm_set_window_state (struct frame
*f
, int state
)
10383 #ifdef USE_X_TOOLKIT
10386 XtSetArg (al
[0], XtNinitialState
, state
);
10387 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10388 #else /* not USE_X_TOOLKIT */
10389 Window window
= FRAME_X_WINDOW (f
);
10391 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
10392 f
->output_data
.x
->wm_hints
.initial_state
= state
;
10394 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10395 #endif /* not USE_X_TOOLKIT */
10399 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
10401 Pixmap icon_pixmap
, icon_mask
;
10403 #if !defined USE_X_TOOLKIT && !defined USE_GTK
10404 Window window
= FRAME_OUTER_WINDOW (f
);
10409 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
10410 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
10411 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
10412 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
10416 /* It seems there is no way to turn off use of an icon
10424 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
10428 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
10432 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
10433 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10434 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
10435 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
10438 #else /* not USE_X_TOOLKIT && not USE_GTK */
10440 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
10441 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10443 #endif /* not USE_X_TOOLKIT && not USE_GTK */
10447 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
10449 Window window
= FRAME_OUTER_WINDOW (f
);
10451 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
10452 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
10453 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
10455 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
10459 /***********************************************************************
10461 ***********************************************************************/
10465 /* Check that FONT is valid on frame F. It is if it can be found in F's
10469 x_check_font (struct frame
*f
, struct font
*font
)
10471 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
10472 if (font
->driver
->check
)
10473 eassert (font
->driver
->check (f
, font
) == 0);
10476 #endif /* GLYPH_DEBUG */
10479 /***********************************************************************
10481 ***********************************************************************/
10483 #ifdef USE_X_TOOLKIT
10484 static XrmOptionDescRec emacs_options
[] = {
10485 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
10486 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
10488 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
10489 XrmoptionSepArg
, NULL
},
10490 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
10492 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10493 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10494 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
10495 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10496 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
10497 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
10498 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
10501 /* Whether atimer for Xt timeouts is activated or not. */
10503 static bool x_timeout_atimer_activated_flag
;
10505 #endif /* USE_X_TOOLKIT */
10507 static int x_initialized
;
10509 /* Test whether two display-name strings agree up to the dot that separates
10510 the screen number from the server number. */
10512 same_x_server (const char *name1
, const char *name2
)
10514 bool seen_colon
= false;
10515 Lisp_Object sysname
= Fsystem_name ();
10516 const char *system_name
= SSDATA (sysname
);
10517 ptrdiff_t system_name_length
= SBYTES (sysname
);
10518 ptrdiff_t length_until_period
= 0;
10520 while (system_name
[length_until_period
] != 0
10521 && system_name
[length_until_period
] != '.')
10522 length_until_period
++;
10524 /* Treat `unix' like an empty host name. */
10525 if (! strncmp (name1
, "unix:", 5))
10527 if (! strncmp (name2
, "unix:", 5))
10529 /* Treat this host's name like an empty host name. */
10530 if (! strncmp (name1
, system_name
, system_name_length
)
10531 && name1
[system_name_length
] == ':')
10532 name1
+= system_name_length
;
10533 if (! strncmp (name2
, system_name
, system_name_length
)
10534 && name2
[system_name_length
] == ':')
10535 name2
+= system_name_length
;
10536 /* Treat this host's domainless name like an empty host name. */
10537 if (! strncmp (name1
, system_name
, length_until_period
)
10538 && name1
[length_until_period
] == ':')
10539 name1
+= length_until_period
;
10540 if (! strncmp (name2
, system_name
, length_until_period
)
10541 && name2
[length_until_period
] == ':')
10542 name2
+= length_until_period
;
10544 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
10548 if (seen_colon
&& *name1
== '.')
10552 && (*name1
== '.' || *name1
== '\0')
10553 && (*name2
== '.' || *name2
== '\0'));
10556 /* Count number of set bits in mask and number of bits to shift to
10557 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
10560 get_bits_and_offset (unsigned long mask
, int *bits
, int *offset
)
10565 while (!(mask
& 1))
10581 /* Return true iff display DISPLAY is available for use.
10582 But don't permanently open it, just test its availability. */
10585 x_display_ok (const char *display
)
10587 Display
*dpy
= XOpenDisplay (display
);
10590 XCloseDisplay (dpy
);
10596 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
10597 const gchar
*msg
, gpointer user_data
)
10599 if (!strstr (msg
, "g_set_prgname"))
10600 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
10604 /* Create invisible cursor on X display referred by DPYINFO. */
10607 make_invisible_cursor (struct x_display_info
*dpyinfo
)
10609 Display
*dpy
= dpyinfo
->display
;
10610 static char const no_data
[] = { 0 };
10615 x_catch_errors (dpy
);
10616 pix
= XCreateBitmapFromData (dpy
, dpyinfo
->root_window
, no_data
, 1, 1);
10617 if (! x_had_errors_p (dpy
) && pix
!= None
)
10621 col
.red
= col
.green
= col
.blue
= 0;
10622 col
.flags
= DoRed
| DoGreen
| DoBlue
;
10623 pixc
= XCreatePixmapCursor (dpy
, pix
, pix
, &col
, &col
, 0, 0);
10624 if (! x_had_errors_p (dpy
) && pixc
!= None
)
10626 XFreePixmap (dpy
, pix
);
10629 x_uncatch_errors ();
10634 /* True if DPY supports Xfixes extension >= 4. */
10637 x_probe_xfixes_extension (Display
*dpy
)
10641 return XFixesQueryVersion (dpy
, &major
, &minor
) && major
>= 4;
10644 #endif /* HAVE_XFIXES */
10647 /* Toggle mouse pointer visibility on frame F by using Xfixes functions. */
10650 xfixes_toggle_visible_pointer (struct frame
*f
, bool invisible
)
10654 XFixesHideCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10656 XFixesShowCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
10657 f
->pointer_invisible
= invisible
;
10660 #endif /* HAVE_XFIXES */
10663 /* Toggle mouse pointer visibility on frame F by using invisible cursor. */
10666 x_toggle_visible_pointer (struct frame
*f
, bool invisible
)
10668 eassert (FRAME_DISPLAY_INFO (f
)->invisible_cursor
!= 0);
10670 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10671 FRAME_DISPLAY_INFO (f
)->invisible_cursor
);
10673 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
10674 f
->output_data
.x
->current_cursor
);
10675 f
->pointer_invisible
= invisible
;
10678 /* Setup pointer blanking, prefer Xfixes if available. */
10681 x_setup_pointer_blanking (struct x_display_info
*dpyinfo
)
10683 /* FIXME: the brave tester should set EMACS_XFIXES because we're suspecting
10684 X server bug, see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17609. */
10685 if (egetenv ("EMACS_XFIXES") && x_probe_xfixes_extension (dpyinfo
->display
))
10686 dpyinfo
->toggle_visible_pointer
= xfixes_toggle_visible_pointer
;
10689 dpyinfo
->toggle_visible_pointer
= x_toggle_visible_pointer
;
10690 dpyinfo
->invisible_cursor
= make_invisible_cursor (dpyinfo
);
10694 /* Current X display connection identifier. Incremented for each next
10695 connection established. */
10696 static unsigned x_display_id
;
10698 /* Open a connection to X display DISPLAY_NAME, and return
10699 the structure that describes the open display.
10700 If we cannot contact the display, return null. */
10702 struct x_display_info
*
10703 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
10706 struct terminal
*terminal
;
10707 struct x_display_info
*dpyinfo
;
10713 if (!x_initialized
)
10719 if (! x_display_ok (SSDATA (display_name
)))
10720 error ("Display %s can't be opened", SSDATA (display_name
));
10724 #define NUM_ARGV 10
10726 char *argv
[NUM_ARGV
];
10727 char **argv2
= argv
;
10730 if (x_initialized
++ > 1)
10732 xg_display_open (SSDATA (display_name
), &dpy
);
10736 static char display_opt
[] = "--display";
10737 static char name_opt
[] = "--name";
10739 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10743 argv
[argc
++] = initial_argv
[0];
10745 if (! NILP (display_name
))
10747 argv
[argc
++] = display_opt
;
10748 argv
[argc
++] = SSDATA (display_name
);
10751 argv
[argc
++] = name_opt
;
10752 argv
[argc
++] = resource_name
;
10754 XSetLocaleModifiers ("");
10756 /* Work around GLib bug that outputs a faulty warning. See
10757 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
10758 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
10759 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
10761 /* NULL window -> events for all windows go to our function.
10762 Call before gtk_init so Gtk+ event filters comes after our. */
10763 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10765 /* gtk_init does set_locale. Fix locale before and after. */
10767 gtk_init (&argc
, &argv2
);
10770 g_log_remove_handler ("GLib", id
);
10774 dpy
= DEFAULT_GDK_DISPLAY ();
10776 #if ! GTK_CHECK_VERSION (2, 90, 0)
10777 /* Load our own gtkrc if it exists. */
10779 const char *file
= "~/.emacs.d/gtkrc";
10780 Lisp_Object s
, abs_file
;
10782 s
= build_string (file
);
10783 abs_file
= Fexpand_file_name (s
, Qnil
);
10785 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10786 gtk_rc_parse (SSDATA (abs_file
));
10790 XSetErrorHandler (x_error_handler
);
10791 XSetIOErrorHandler (x_io_error_quitter
);
10794 #else /* not USE_GTK */
10795 #ifdef USE_X_TOOLKIT
10796 /* weiner@footloose.sps.mot.com reports that this causes
10798 X protocol error: BadAtom (invalid Atom parameter)
10799 on protocol request 18skiloaf.
10800 So let's not use it until R6. */
10801 #ifdef HAVE_X11XTR6
10802 XtSetLanguageProc (NULL
, NULL
, NULL
);
10813 argv
[argc
++] = "-xrm";
10814 argv
[argc
++] = xrm_option
;
10816 turn_on_atimers (false);
10817 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
10818 resource_name
, EMACS_CLASS
,
10819 emacs_options
, XtNumber (emacs_options
),
10821 turn_on_atimers (true);
10823 #ifdef HAVE_X11XTR6
10824 /* I think this is to compensate for XtSetLanguageProc. */
10829 #else /* not USE_X_TOOLKIT */
10830 XSetLocaleModifiers ("");
10831 dpy
= XOpenDisplay (SSDATA (display_name
));
10832 #endif /* not USE_X_TOOLKIT */
10833 #endif /* not USE_GTK*/
10835 /* Detect failure. */
10842 /* We have definitely succeeded. Record the new connection. */
10844 dpyinfo
= xzalloc (sizeof *dpyinfo
);
10845 terminal
= x_create_terminal (dpyinfo
);
10848 struct x_display_info
*share
;
10850 for (share
= x_display_list
; share
; share
= share
->next
)
10851 if (same_x_server (SSDATA (XCAR (share
->name_list_element
)),
10852 SSDATA (display_name
)))
10855 terminal
->kboard
= share
->terminal
->kboard
;
10858 terminal
->kboard
= allocate_kboard (Qx
);
10860 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10862 char *vendor
= ServerVendor (dpy
);
10864 /* Protect terminal from GC before removing it from the
10865 list of terminals. */
10866 struct gcpro gcpro1
;
10867 Lisp_Object gcpro_term
;
10868 XSETTERMINAL (gcpro_term
, terminal
);
10869 GCPRO1 (gcpro_term
);
10871 /* Temporarily hide the partially initialized terminal. */
10872 terminal_list
= terminal
->next_terminal
;
10874 kset_system_key_alist
10876 call1 (Qvendor_specific_keysyms
,
10877 vendor
? build_string (vendor
) : empty_unibyte_string
));
10879 terminal
->next_terminal
= terminal_list
;
10880 terminal_list
= terminal
;
10884 /* Don't let the initial kboard remain current longer than necessary.
10885 That would cause problems if a file loaded on startup tries to
10886 prompt in the mini-buffer. */
10887 if (current_kboard
== initial_kboard
)
10888 current_kboard
= terminal
->kboard
;
10890 terminal
->kboard
->reference_count
++;
10893 /* Put this display on the chain. */
10894 dpyinfo
->next
= x_display_list
;
10895 x_display_list
= dpyinfo
;
10897 dpyinfo
->name_list_element
= Fcons (display_name
, Qnil
);
10898 dpyinfo
->display
= dpy
;
10899 dpyinfo
->connection
= ConnectionNumber (dpyinfo
->display
);
10901 /* Set the name of the terminal. */
10902 terminal
->name
= xlispstrdup (display_name
);
10905 XSetAfterFunction (x_current_display
, x_trace_wire
);
10908 lim
= min (PTRDIFF_MAX
, SIZE_MAX
) - sizeof "@";
10909 Lisp_Object system_name
= Fsystem_name ();
10910 if (lim
- SBYTES (Vinvocation_name
) < SBYTES (system_name
))
10911 memory_full (SIZE_MAX
);
10912 dpyinfo
->x_id
= ++x_display_id
;
10913 dpyinfo
->x_id_name
= xmalloc (SBYTES (Vinvocation_name
)
10914 + SBYTES (system_name
) + 2);
10915 char *nametail
= lispstpcpy (dpyinfo
->x_id_name
, Vinvocation_name
);
10917 lispstpcpy (nametail
, system_name
);
10919 /* Figure out which modifier bits mean what. */
10920 x_find_modifier_meanings (dpyinfo
);
10922 /* Get the scroll bar cursor. */
10924 /* We must create a GTK cursor, it is required for GTK widgets. */
10925 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10926 #endif /* USE_GTK */
10928 dpyinfo
->vertical_scroll_bar_cursor
10929 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10931 dpyinfo
->horizontal_scroll_bar_cursor
10932 = XCreateFontCursor (dpyinfo
->display
, XC_sb_h_double_arrow
);
10934 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10935 resource_name
, EMACS_CLASS
);
10936 #ifdef HAVE_XRMSETDATABASE
10937 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10939 dpyinfo
->display
->db
= xrdb
;
10941 /* Put the rdb where we can find it in a way that works on
10943 dpyinfo
->xrdb
= xrdb
;
10945 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10946 DefaultScreen (dpyinfo
->display
));
10947 select_visual (dpyinfo
);
10948 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10949 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10950 dpyinfo
->icon_bitmap_id
= -1;
10951 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10953 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
10955 /* See if we can construct pixel values from RGB values. */
10956 if (dpyinfo
->visual
->class == TrueColor
)
10958 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10959 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10960 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10961 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10962 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10963 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10966 /* See if a private colormap is requested. */
10967 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10969 if (dpyinfo
->visual
->class == PseudoColor
)
10971 AUTO_STRING (privateColormap
, "privateColormap");
10972 AUTO_STRING (PrivateColormap
, "PrivateColormap");
10974 = display_x_get_resource (dpyinfo
, privateColormap
,
10975 PrivateColormap
, Qnil
, Qnil
);
10976 if (STRINGP (value
)
10977 && (!strcmp (SSDATA (value
), "true")
10978 || !strcmp (SSDATA (value
), "on")))
10979 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10983 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10984 dpyinfo
->visual
, AllocNone
);
10988 /* If we are using Xft, the following precautions should be made:
10990 1. Make sure that the Xrender extension is added before the Xft one.
10991 Otherwise, the close-display hook set by Xft is called after the one
10992 for Xrender, and the former tries to re-add the latter. This results
10993 in inconsistency of internal states and leads to X protocol error when
10994 one reconnects to the same X server (Bug#1696).
10996 2. Check dpi value in X resources. It is better we use it as well,
10997 since Xft will use it, as will all Gnome applications. If our real DPI
10998 is smaller or larger than the one Xft uses, our font will look smaller
10999 or larger than other for other applications, even if it is the same
11000 font name (monospace-10 for example). */
11002 int event_base
, error_base
;
11006 XRenderQueryExtension (dpyinfo
->display
, &event_base
, &error_base
);
11008 v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
11009 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
11010 dpyinfo
->resy
= dpyinfo
->resx
= d
;
11014 if (dpyinfo
->resy
< 1)
11016 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
11017 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
11018 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
11019 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11020 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11021 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
11022 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
11023 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
11024 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
11028 static const struct
11033 #define ATOM_REFS_INIT(string, member) \
11034 { string, offsetof (struct x_display_info, member) },
11035 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
11036 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
11037 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
11038 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
11039 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
11040 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
11041 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
11042 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
11043 ATOM_REFS_INIT ("Editres", Xatom_editres
)
11044 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
11045 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
11046 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
11047 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
11048 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
11049 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
11050 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
11051 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
11052 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
11053 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
11054 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
11055 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
11056 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
11057 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
11058 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
11059 /* For properties of font. */
11060 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
11061 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
11062 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
11063 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
11064 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
11065 /* Ghostscript support. */
11066 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
11067 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
11068 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
11069 ATOM_REFS_INIT ("HORIZONTAL_SCROLLBAR", Xatom_Horizontal_Scrollbar
)
11070 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
11072 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
11073 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
11074 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
11075 Xatom_net_wm_state_maximized_horz
)
11076 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
11077 Xatom_net_wm_state_maximized_vert
)
11078 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
11079 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
11080 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
11081 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
11082 Xatom_net_window_type_tooltip
)
11083 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
11084 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
11085 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
11086 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
11087 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
11088 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
11089 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
11090 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
11091 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
11092 /* Session management */
11093 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
11094 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
11095 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
11099 enum { atom_count
= ARRAYELTS (atom_refs
) };
11100 /* 1 for _XSETTINGS_SN. */
11101 enum { total_atom_count
= 1 + atom_count
};
11102 Atom atoms_return
[total_atom_count
];
11103 char *atom_names
[total_atom_count
];
11104 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
11105 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
11106 + INT_STRLEN_BOUND (int)];
11108 for (i
= 0; i
< atom_count
; i
++)
11109 atom_names
[i
] = (char *) atom_refs
[i
].name
;
11111 /* Build _XSETTINGS_SN atom name. */
11112 sprintf (xsettings_atom_name
, xsettings_fmt
,
11113 XScreenNumberOfScreen (dpyinfo
->screen
));
11114 atom_names
[i
] = xsettings_atom_name
;
11116 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
11117 False
, atoms_return
);
11119 for (i
= 0; i
< atom_count
; i
++)
11120 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
11122 /* Manually copy last atom. */
11123 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
11126 dpyinfo
->x_dnd_atoms_size
= 8;
11127 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
11128 * dpyinfo
->x_dnd_atoms_size
);
11130 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
11131 gray_bits
, gray_width
, gray_height
,
11134 x_setup_pointer_blanking (dpyinfo
);
11137 xim_initialize (dpyinfo
, resource_name
);
11140 xsettings_initialize (dpyinfo
);
11142 /* This is only needed for distinguishing keyboard and process input. */
11143 if (dpyinfo
->connection
!= 0)
11144 add_keyboard_wait_descriptor (dpyinfo
->connection
);
11147 fcntl (dpyinfo
->connection
, F_SETOWN
, getpid ());
11148 #endif /* ! defined (F_SETOWN) */
11150 if (interrupt_input
)
11151 init_sigio (dpyinfo
->connection
);
11155 XrmValue d
, fr
, to
;
11158 dpy
= dpyinfo
->display
;
11159 d
.addr
= (XPointer
)&dpy
;
11160 d
.size
= sizeof (Display
*);
11161 fr
.addr
= XtDefaultFont
;
11162 fr
.size
= sizeof (XtDefaultFont
);
11163 to
.size
= sizeof (Font
*);
11164 to
.addr
= (XPointer
)&font
;
11165 x_catch_errors (dpy
);
11166 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
11168 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
11169 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
11170 /* Do not free XFontStruct returned by the above call to XQueryFont.
11171 This leads to X protocol errors at XtCloseDisplay (Bug#18403). */
11172 x_uncatch_errors ();
11176 /* See if we should run in synchronous mode. This is useful
11177 for debugging X code. */
11179 AUTO_STRING (synchronous
, "synchronous");
11180 AUTO_STRING (Synchronous
, "Synchronous");
11181 Lisp_Object value
= display_x_get_resource (dpyinfo
, synchronous
,
11182 Synchronous
, Qnil
, Qnil
);
11183 if (STRINGP (value
)
11184 && (!strcmp (SSDATA (value
), "true")
11185 || !strcmp (SSDATA (value
), "on")))
11186 XSynchronize (dpyinfo
->display
, True
);
11190 AUTO_STRING (useXIM
, "useXIM");
11191 AUTO_STRING (UseXIM
, "UseXIM");
11192 Lisp_Object value
= display_x_get_resource (dpyinfo
, useXIM
, UseXIM
,
11195 if (STRINGP (value
)
11196 && (!strcmp (SSDATA (value
), "false")
11197 || !strcmp (SSDATA (value
), "off")))
11200 if (STRINGP (value
)
11201 && (!strcmp (SSDATA (value
), "true")
11202 || !strcmp (SSDATA (value
), "on")))
11208 /* Only do this for the very first display in the Emacs session.
11209 Ignore X session management when Emacs was first started on a
11210 tty or started as a daemon. */
11211 if (terminal
->id
== 1 && ! IS_DAEMON
)
11212 x_session_initialize (dpyinfo
);
11220 /* Get rid of display DPYINFO, deleting all frames on it,
11221 and without sending any more commands to the X server. */
11224 x_delete_display (struct x_display_info
*dpyinfo
)
11226 struct terminal
*t
;
11228 /* Close all frames and delete the generic struct terminal for this
11230 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
11231 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
11234 /* Close X session management when we close its display. */
11235 if (t
->id
== 1 && x_session_have_connection ())
11236 x_session_close ();
11238 delete_terminal (t
);
11242 if (next_noop_dpyinfo
== dpyinfo
)
11243 next_noop_dpyinfo
= dpyinfo
->next
;
11245 if (x_display_list
== dpyinfo
)
11246 x_display_list
= dpyinfo
->next
;
11249 struct x_display_info
*tail
;
11251 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
11252 if (tail
->next
== dpyinfo
)
11253 tail
->next
= tail
->next
->next
;
11256 xfree (dpyinfo
->x_id_name
);
11257 xfree (dpyinfo
->x_dnd_atoms
);
11258 xfree (dpyinfo
->color_cells
);
11262 #ifdef USE_X_TOOLKIT
11264 /* Atimer callback function for TIMER. Called every 0.1s to process
11265 Xt timeouts, if needed. We must avoid calling XtAppPending as
11266 much as possible because that function does an implicit XFlush
11267 that slows us down. */
11270 x_process_timeouts (struct atimer
*timer
)
11273 x_timeout_atimer_activated_flag
= false;
11274 if (toolkit_scroll_bar_interaction
|| popup_activated ())
11276 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
11277 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
11278 /* Reactivate the atimer for next time. */
11279 x_activate_timeout_atimer ();
11284 /* Install an asynchronous timer that processes Xt timeout events
11285 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
11286 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
11287 function whenever these variables are set. This is necessary
11288 because some widget sets use timeouts internally, for example the
11289 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
11290 processed, these widgets don't behave normally. */
11293 x_activate_timeout_atimer (void)
11296 if (!x_timeout_atimer_activated_flag
)
11298 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
11299 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
11300 x_timeout_atimer_activated_flag
= true;
11305 #endif /* USE_X_TOOLKIT */
11308 /* Set up use of X before we make the first connection. */
11310 static struct redisplay_interface x_redisplay_interface
=
11312 x_frame_parm_handlers
,
11316 x_clear_end_of_line
,
11318 x_after_update_window_line
,
11319 x_update_window_begin
,
11320 x_update_window_end
,
11322 x_clear_window_mouse_face
,
11323 x_get_glyph_overhangs
,
11324 x_fix_overlapping_area
,
11325 x_draw_fringe_bitmap
,
11326 0, /* define_fringe_bitmap */
11327 0, /* destroy_fringe_bitmap */
11328 x_compute_glyph_string_overhangs
,
11329 x_draw_glyph_string
,
11330 x_define_frame_cursor
,
11331 x_clear_frame_area
,
11332 x_draw_window_cursor
,
11333 x_draw_vertical_window_border
,
11334 x_draw_window_divider
,
11335 x_shift_glyphs_for_insert
,
11341 /* This function is called when the last frame on a display is deleted. */
11343 x_delete_terminal (struct terminal
*terminal
)
11345 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
11347 /* Protect against recursive calls. delete_frame in
11348 delete_terminal calls us back when it deletes our last frame. */
11349 if (!terminal
->name
)
11354 /* We must close our connection to the XIM server before closing the
11357 xim_close_dpy (dpyinfo
);
11360 /* Normally, the display is available... */
11361 if (dpyinfo
->display
)
11363 x_destroy_all_bitmaps (dpyinfo
);
11364 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
11366 /* Whether or not XCloseDisplay destroys the associated resource
11367 database depends on the version of libX11. To avoid both
11368 crash and memory leak, we dissociate the database from the
11369 display and then destroy dpyinfo->xrdb ourselves.
11371 Unfortunately, the above strategy does not work in some
11372 situations due to a bug in newer versions of libX11: because
11373 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
11374 dpy->db is NULL, XCloseDisplay destroys the associated
11375 database whereas it has not been created by XGetDefault
11376 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
11377 don't destroy the database here in order to avoid the crash
11378 in the above situations for now, though that may cause memory
11379 leaks in other situations. */
11381 #ifdef HAVE_XRMSETDATABASE
11382 XrmSetDatabase (dpyinfo
->display
, NULL
);
11384 dpyinfo
->display
->db
= NULL
;
11386 /* We used to call XrmDestroyDatabase from x_delete_display, but
11387 some older versions of libX11 crash if we call it after
11388 closing all the displays. */
11389 XrmDestroyDatabase (dpyinfo
->xrdb
);
11393 xg_display_close (dpyinfo
->display
);
11395 #ifdef USE_X_TOOLKIT
11396 XtCloseDisplay (dpyinfo
->display
);
11398 XCloseDisplay (dpyinfo
->display
);
11400 #endif /* ! USE_GTK */
11401 /* Do not close the connection here because it's already closed
11402 by X(t)CloseDisplay (Bug#18403). */
11403 dpyinfo
->display
= NULL
;
11406 /* ...but if called from x_connection_closed, the display may already
11407 be closed and dpyinfo->display was set to 0 to indicate that. Since
11408 X server is most likely gone, explicit close is the only reliable
11409 way to continue and avoid Bug#19147. */
11410 else if (dpyinfo
->connection
>= 0)
11411 emacs_close (dpyinfo
->connection
);
11413 /* No more input on this descriptor. */
11414 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
11415 /* Mark as dead. */
11416 dpyinfo
->connection
= -1;
11418 x_delete_display (dpyinfo
);
11422 /* Create a struct terminal, initialize it with the X11 specific
11423 functions and make DISPLAY->TERMINAL point to it. */
11425 static struct terminal
*
11426 x_create_terminal (struct x_display_info
*dpyinfo
)
11428 struct terminal
*terminal
;
11430 terminal
= create_terminal (output_x_window
, &x_redisplay_interface
);
11432 terminal
->display_info
.x
= dpyinfo
;
11433 dpyinfo
->terminal
= terminal
;
11435 /* kboard is initialized in x_term_init. */
11437 terminal
->clear_frame_hook
= x_clear_frame
;
11438 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
11439 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
11440 terminal
->ring_bell_hook
= XTring_bell
;
11441 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
11442 terminal
->update_begin_hook
= x_update_begin
;
11443 terminal
->update_end_hook
= x_update_end
;
11444 terminal
->read_socket_hook
= XTread_socket
;
11445 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
11446 terminal
->mouse_position_hook
= XTmouse_position
;
11447 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
11448 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
11449 terminal
->fullscreen_hook
= XTfullscreen_hook
;
11450 terminal
->menu_show_hook
= x_menu_show
;
11451 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
11452 terminal
->popup_dialog_hook
= xw_popup_dialog
;
11454 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
11455 terminal
->set_horizontal_scroll_bar_hook
= XTset_horizontal_scroll_bar
;
11456 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
11457 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
11458 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
11459 terminal
->delete_frame_hook
= x_destroy_window
;
11460 terminal
->delete_terminal_hook
= x_delete_terminal
;
11461 /* Other hooks are NULL by default. */
11467 x_initialize (void)
11472 any_help_event_p
= false;
11473 ignore_next_mouse_click_timeout
= 0;
11476 current_count
= -1;
11479 /* Try to use interrupt input; if we can't, then start polling. */
11480 Fset_input_interrupt_mode (Qt
);
11482 #ifdef USE_X_TOOLKIT
11483 XtToolkitInitialize ();
11485 Xt_app_con
= XtCreateApplicationContext ();
11487 /* Register a converter from strings to pixels, which uses
11488 Emacs' color allocation infrastructure. */
11489 XtAppSetTypeConverter (Xt_app_con
,
11490 XtRString
, XtRPixel
, cvt_string_to_pixel
,
11491 cvt_string_to_pixel_args
,
11492 XtNumber (cvt_string_to_pixel_args
),
11493 XtCacheByDisplay
, cvt_pixel_dtor
);
11495 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
11498 #ifdef USE_TOOLKIT_SCROLL_BARS
11500 xaw3d_arrow_scroll
= False
;
11501 xaw3d_pick_top
= True
;
11505 /* Note that there is no real way portable across R3/R4 to get the
11506 original error handler. */
11507 XSetErrorHandler (x_error_handler
);
11508 XSetIOErrorHandler (x_io_error_quitter
);
11515 /* Emacs can handle only core input events, so make sure
11516 Gtk doesn't use Xinput or Xinput2 extensions. */
11517 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
11522 syms_of_xterm (void)
11524 x_error_message
= NULL
;
11526 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
11527 DEFSYM (Qlatin_1
, "latin-1");
11530 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
11531 staticpro (&xg_default_icon_file
);
11533 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
11536 DEFVAR_BOOL ("x-use-underline-position-properties",
11537 x_use_underline_position_properties
,
11538 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
11539 A value of nil means ignore them. If you encounter fonts with bogus
11540 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11541 to 4.1, set this to nil. You can also use `underline-minimum-offset'
11542 to override the font's UNDERLINE_POSITION for small font display
11544 x_use_underline_position_properties
= true;
11546 DEFVAR_BOOL ("x-underline-at-descent-line",
11547 x_underline_at_descent_line
,
11548 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
11549 A value of nil means to draw the underline according to the value of the
11550 variable `x-use-underline-position-properties', which is usually at the
11551 baseline level. The default value is nil. */);
11552 x_underline_at_descent_line
= false;
11554 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
11555 x_mouse_click_focus_ignore_position
,
11556 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
11557 This variable is only used when the window manager requires that you
11558 click on a frame to select it (give it focus). In that case, a value
11559 of nil, means that the selected window and cursor position changes to
11560 reflect the mouse click position, while a non-nil value means that the
11561 selected window or cursor position is preserved. */);
11562 x_mouse_click_focus_ignore_position
= false;
11564 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
11565 doc
: /* Which toolkit scroll bars Emacs uses, if any.
11566 A value of nil means Emacs doesn't use toolkit scroll bars.
11567 With the X Window system, the value is a symbol describing the
11568 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
11569 With MS Windows or Nextstep, the value is t. */);
11570 #ifdef USE_TOOLKIT_SCROLL_BARS
11572 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
11573 #elif defined HAVE_XAW3D
11574 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
11576 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
11578 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
11581 Vx_toolkit_scroll_bars
= Qnil
;
11584 DEFSYM (Qmodifier_value
, "modifier-value");
11585 DEFSYM (Qalt
, "alt");
11586 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
11587 DEFSYM (Qhyper
, "hyper");
11588 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
11589 DEFSYM (Qmeta
, "meta");
11590 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
11591 DEFSYM (Qsuper
, "super");
11592 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
11594 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
11595 doc
: /* Which keys Emacs uses for the alt modifier.
11596 This should be one of the symbols `alt', `hyper', `meta', `super'.
11597 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
11598 is nil, which is the same as `alt'. */);
11599 Vx_alt_keysym
= Qnil
;
11601 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
11602 doc
: /* Which keys Emacs uses for the hyper modifier.
11603 This should be one of the symbols `alt', `hyper', `meta', `super'.
11604 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
11605 default is nil, which is the same as `hyper'. */);
11606 Vx_hyper_keysym
= Qnil
;
11608 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
11609 doc
: /* Which keys Emacs uses for the meta modifier.
11610 This should be one of the symbols `alt', `hyper', `meta', `super'.
11611 For example, `meta' means use the Meta_L and Meta_R keysyms. The
11612 default is nil, which is the same as `meta'. */);
11613 Vx_meta_keysym
= Qnil
;
11615 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
11616 doc
: /* Which keys Emacs uses for the super modifier.
11617 This should be one of the symbols `alt', `hyper', `meta', `super'.
11618 For example, `super' means use the Super_L and Super_R keysyms. The
11619 default is nil, which is the same as `super'. */);
11620 Vx_super_keysym
= Qnil
;
11622 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
11623 doc
: /* Hash table of character codes indexed by X keysym codes. */);
11624 Vx_keysym_table
= make_hash_table (hashtest_eql
, make_number (900),
11625 make_float (DEFAULT_REHASH_SIZE
),
11626 make_float (DEFAULT_REHASH_THRESHOLD
),