1 /* X Communication module for terminals which understand the X protocol.
3 Copyright (C) 1989, 1993-2013 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 /* Load sys/types.h if not already loaded.
36 In some systems loading it twice is suicidal. */
38 #include <sys/types.h>
41 #include <sys/ioctl.h>
48 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
49 /* #include <sys/param.h> */
52 #include "character.h"
55 #include "dispextern.h"
57 #include "termhooks.h"
60 #include "emacs-icon.h"
65 #include "intervals.h"
70 #include "xsettings.h"
72 #include "sysselect.h"
75 #include <X11/Shell.h>
83 #include <X11/Xproto.h>
88 #include "../lwlib/xlwmenu.h"
92 #if !defined (NO_EDITRES)
94 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
95 #endif /* not NO_EDITRES */
97 /* Include toolkit specific headers for the scroll bar widget. */
99 #ifdef USE_TOOLKIT_SCROLL_BARS
100 #if defined USE_MOTIF
101 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
102 #include <Xm/ScrollBar.h>
103 #else /* !USE_MOTIF i.e. use Xaw */
106 #include <X11/Xaw3d/Simple.h>
107 #include <X11/Xaw3d/Scrollbar.h>
108 #include <X11/Xaw3d/ThreeD.h>
109 #else /* !HAVE_XAW3D */
110 #include <X11/Xaw/Simple.h>
111 #include <X11/Xaw/Scrollbar.h>
112 #endif /* !HAVE_XAW3D */
114 #define XtNpickTop "pickTop"
115 #endif /* !XtNpickTop */
116 #endif /* !USE_MOTIF */
117 #endif /* USE_TOOLKIT_SCROLL_BARS */
119 #endif /* USE_X_TOOLKIT */
123 #ifndef XtNinitialState
124 #define XtNinitialState "initialState"
128 #include "bitmaps/gray.xbm"
131 #include <X11/XKBlib.h>
134 /* Default to using XIM if available. */
138 int use_xim
= 0; /* configure --without-xim */
141 /* Non-zero means that a HELP_EVENT has been generated since Emacs
144 static bool any_help_event_p
;
146 /* This is a chain of structures for all the X displays currently in
149 struct x_display_info
*x_display_list
;
151 /* This is a list of cons cells, each of the form (NAME
152 . FONT-LIST-CACHE), one for each element of x_display_list and in
153 the same order. NAME is the name of the frame. FONT-LIST-CACHE
154 records previous values returned by x-list-fonts. */
156 Lisp_Object x_display_name_list
;
158 /* This is a frame waiting to be auto-raised, within XTread_socket. */
160 static struct frame
*pending_autoraise_frame
;
162 /* This is a frame waiting for an event matching mask, within XTread_socket. */
167 } pending_event_wait
;
170 /* The application context for Xt use. */
171 XtAppContext Xt_app_con
;
172 static String Xt_default_resources
[] = {0};
174 /* Non-zero means user is interacting with a toolkit scroll bar. */
176 static int toolkit_scroll_bar_interaction
;
177 #endif /* USE_X_TOOLKIT */
179 /* Non-zero timeout value means ignore next mouse click if it arrives
180 before that timeout elapses (i.e. as part of the same sequence of
181 events resulting from clicking on a frame to select it). */
183 static unsigned long ignore_next_mouse_click_timeout
;
187 Formerly, we used PointerMotionHintMask (in standard_event_mask)
188 so that we would have to call XQueryPointer after each MotionNotify
189 event to ask for another such event. However, this made mouse tracking
190 slow, and there was a bug that made it eventually stop.
192 Simply asking for MotionNotify all the time seems to work better.
194 In order to avoid asking for motion events and then throwing most
195 of them away or busy-polling the server for mouse positions, we ask
196 the server for pointer motion hints. This means that we get only
197 one event per group of mouse movements. "Groups" are delimited by
198 other kinds of events (focus changes and button clicks, for
199 example), or by XQueryPointer calls; when one of these happens, we
200 get another MotionNotify event the next time the mouse moves. This
201 is at least as efficient as getting motion events when mouse
202 tracking is on, and I suspect only negligibly worse when tracking
205 /* Where the mouse was last time we reported a mouse event. */
207 static XRectangle last_mouse_glyph
;
208 static struct frame
*last_mouse_glyph_frame
;
210 /* The scroll bar in which the last X motion event occurred.
212 If the last X motion event occurred in a scroll bar, we set this so
213 XTmouse_position can know whether to report a scroll bar motion or
216 If the last X motion event didn't occur in a scroll bar, we set
217 this to Qnil, to tell XTmouse_position to return an ordinary motion
220 static Lisp_Object last_mouse_scroll_bar
;
222 /* This is a hack. We would really prefer that XTmouse_position would
223 return the time associated with the position it returns, but there
224 doesn't seem to be any way to wrest the time-stamp from the server
225 along with the position query. So, we just keep track of the time
226 of the last movement we received, and return that in hopes that
227 it's somewhat accurate. */
229 static Time last_mouse_movement_time
;
231 /* Incremented by XTread_socket whenever it really tries to read
234 static int volatile input_signal_count
;
236 /* Used locally within XTread_socket. */
238 static int x_noop_count
;
240 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
242 static Lisp_Object Qvendor_specific_keysyms
;
243 static Lisp_Object Qlatin_1
;
246 /* The name of the Emacs icon file. */
247 static Lisp_Object xg_default_icon_file
;
249 /* Used in gtkutil.c. */
250 Lisp_Object Qx_gtk_map_stock
;
253 /* Some functions take this as char *, not const char *. */
254 static char emacs_class
[] = EMACS_CLASS
;
258 XEMBED_MAPPED
= 1 << 0
263 XEMBED_EMBEDDED_NOTIFY
= 0,
264 XEMBED_WINDOW_ACTIVATE
= 1,
265 XEMBED_WINDOW_DEACTIVATE
= 2,
266 XEMBED_REQUEST_FOCUS
= 3,
268 XEMBED_FOCUS_OUT
= 5,
269 XEMBED_FOCUS_NEXT
= 6,
270 XEMBED_FOCUS_PREV
= 7,
272 XEMBED_MODALITY_ON
= 10,
273 XEMBED_MODALITY_OFF
= 11,
274 XEMBED_REGISTER_ACCELERATOR
= 12,
275 XEMBED_UNREGISTER_ACCELERATOR
= 13,
276 XEMBED_ACTIVATE_ACCELERATOR
= 14
279 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
280 static void x_set_window_size_1 (struct frame
*, int, int, int);
281 static void x_raise_frame (struct frame
*);
282 static void x_lower_frame (struct frame
*);
283 static const XColor
*x_color_cells (Display
*, int *);
284 static int x_io_error_quitter (Display
*);
285 static struct terminal
*x_create_terminal (struct x_display_info
*);
286 void x_delete_terminal (struct terminal
*);
287 static void x_update_end (struct frame
*);
288 static void XTframe_up_to_date (struct frame
*);
289 static void x_clear_frame (struct frame
*);
290 static _Noreturn
void x_ins_del_lines (struct frame
*, int, int);
291 static void frame_highlight (struct frame
*);
292 static void frame_unhighlight (struct frame
*);
293 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
294 static void x_focus_changed (int, int, struct x_display_info
*,
295 struct frame
*, struct input_event
*);
296 static void x_detect_focus_change (struct x_display_info
*,
297 XEvent
*, struct input_event
*);
298 static void XTframe_rehighlight (struct frame
*);
299 static void x_frame_rehighlight (struct x_display_info
*);
300 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
301 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
302 enum text_cursor_kinds
);
304 static void x_clip_to_row (struct window
*, struct glyph_row
*,
305 enum glyph_row_area
, GC
);
306 static void x_flush (struct frame
*f
);
307 static void x_update_begin (struct frame
*);
308 static void x_update_window_begin (struct window
*);
309 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
310 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
311 enum scroll_bar_part
*,
312 Lisp_Object
*, Lisp_Object
*,
314 static int x_handle_net_wm_state (struct frame
*, XPropertyEvent
*);
315 static void x_check_fullscreen (struct frame
*);
316 static void x_check_expected_move (struct frame
*, int, int);
317 static void x_sync_with_move (struct frame
*, int, int, int);
318 static int handle_one_xevent (struct x_display_info
*, XEvent
*,
319 int *, struct input_event
*);
321 static int x_dispatch_event (XEvent
*, Display
*);
323 /* Don't declare this _Noreturn because we want no
324 interference with debugging failing X calls. */
325 static void x_connection_closed (Display
*, const char *);
326 static void x_wm_set_window_state (struct frame
*, int);
327 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
328 static void x_initialize (void);
331 /* Flush display of frame F. */
334 x_flush (struct frame
*f
)
336 eassert (f
&& FRAME_X_P (f
));
337 /* Don't call XFlush when it is not safe to redisplay; the X
338 connection may be broken. */
339 if (!NILP (Vinhibit_redisplay
))
343 XFlush (FRAME_X_DISPLAY (f
));
348 /* Remove calls to XFlush by defining XFlush to an empty replacement.
349 Calls to XFlush should be unnecessary because the X output buffer
350 is flushed automatically as needed by calls to XPending,
351 XNextEvent, or XWindowEvent according to the XFlush man page.
352 XTread_socket calls XPending. Removing XFlush improves
355 #define XFlush(DISPLAY) (void) 0
358 /***********************************************************************
360 ***********************************************************************/
364 /* This is a function useful for recording debugging information about
365 the sequence of occurrences in this file. */
373 struct record event_record
[100];
375 int event_record_index
;
378 record_event (char *locus
, int type
)
380 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
381 event_record_index
= 0;
383 event_record
[event_record_index
].locus
= locus
;
384 event_record
[event_record_index
].type
= type
;
385 event_record_index
++;
392 /* Return the struct x_display_info corresponding to DPY. */
394 struct x_display_info
*
395 x_display_info_for_display (Display
*dpy
)
397 struct x_display_info
*dpyinfo
;
399 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
400 if (dpyinfo
->display
== dpy
)
407 x_find_topmost_parent (struct frame
*f
)
409 struct x_output
*x
= f
->output_data
.x
;
410 Window win
= None
, wi
= x
->parent_desc
;
411 Display
*dpy
= FRAME_X_DISPLAY (f
);
413 while (wi
!= FRAME_DISPLAY_INFO (f
)->root_window
)
417 unsigned int nchildren
;
420 XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
);
427 #define OPAQUE 0xffffffff
430 x_set_frame_alpha (struct frame
*f
)
432 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
433 Display
*dpy
= FRAME_X_DISPLAY (f
);
434 Window win
= FRAME_OUTER_WINDOW (f
);
436 double alpha_min
= 1.0;
440 if (dpyinfo
->x_highlight_frame
== f
)
445 if (FLOATP (Vframe_alpha_lower_limit
))
446 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
447 else if (INTEGERP (Vframe_alpha_lower_limit
))
448 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
452 else if (alpha
> 1.0)
454 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
457 opac
= alpha
* OPAQUE
;
459 x_catch_errors (dpy
);
461 /* If there is a parent from the window manager, put the property there
462 also, to work around broken window managers that fail to do that.
463 Do this unconditionally as this function is called on reparent when
464 alpha has not changed on the frame. */
466 parent
= x_find_topmost_parent (f
);
468 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
469 XA_CARDINAL
, 32, PropModeReplace
,
470 (unsigned char *) &opac
, 1L);
472 /* return unless necessary */
477 unsigned long n
, left
;
479 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
480 0L, 1L, False
, XA_CARDINAL
,
481 &actual
, &format
, &n
, &left
,
484 if (rc
== Success
&& actual
!= None
)
486 unsigned long value
= *(unsigned long *)data
;
496 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
497 XA_CARDINAL
, 32, PropModeReplace
,
498 (unsigned char *) &opac
, 1L);
503 x_display_pixel_height (struct x_display_info
*dpyinfo
)
505 return HeightOfScreen (dpyinfo
->screen
);
509 x_display_pixel_width (struct x_display_info
*dpyinfo
)
511 return WidthOfScreen (dpyinfo
->screen
);
515 /***********************************************************************
516 Starting and ending an update
517 ***********************************************************************/
519 /* Start an update of frame F. This function is installed as a hook
520 for update_begin, i.e. it is called when update_begin is called.
521 This function is called prior to calls to x_update_window_begin for
522 each window being updated. Currently, there is nothing to do here
523 because all interesting stuff is done on a window basis. */
526 x_update_begin (struct frame
*f
)
532 /* Start update of window W. */
535 x_update_window_begin (struct window
*w
)
537 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
538 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
540 w
->output_cursor
= w
->cursor
;
544 if (f
== hlinfo
->mouse_face_mouse_frame
)
546 /* Don't do highlighting for mouse motion during the update. */
547 hlinfo
->mouse_face_defer
= 1;
549 /* If F needs to be redrawn, simply forget about any prior mouse
551 if (FRAME_GARBAGED_P (f
))
552 hlinfo
->mouse_face_window
= Qnil
;
559 /* Draw a vertical window border from (x,y0) to (x,y1) */
562 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
564 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
567 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
569 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
572 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
573 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
576 /* End update of window W.
578 Draw vertical borders between horizontally adjacent windows, and
579 display W's cursor if CURSOR_ON_P is non-zero.
581 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
582 glyphs in mouse-face were overwritten. In that case we have to
583 make sure that the mouse-highlight is properly redrawn.
585 W may be a menu bar pseudo-window in case we don't have X toolkit
586 support. Such windows don't have a cursor, so don't display it
590 x_update_window_end (struct window
*w
, bool cursor_on_p
,
591 bool mouse_face_overwritten_p
)
593 if (!w
->pseudo_window_p
)
598 display_and_set_cursor (w
, 1,
599 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
600 w
->output_cursor
.x
, w
->output_cursor
.y
);
602 if (draw_window_fringes (w
, 1))
603 x_draw_vertical_border (w
);
608 /* If a row with mouse-face was overwritten, arrange for
609 XTframe_up_to_date to redisplay the mouse highlight. */
610 if (mouse_face_overwritten_p
)
611 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w
->frame
)));
615 /* End update of frame F. This function is installed as a hook in
619 x_update_end (struct frame
*f
)
621 /* Mouse highlight may be displayed again. */
622 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
626 XFlush (FRAME_X_DISPLAY (f
));
632 /* This function is called from various places in xdisp.c
633 whenever a complete update has been performed. */
636 XTframe_up_to_date (struct frame
*f
)
639 FRAME_MOUSE_UPDATE (f
);
643 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
644 arrow bitmaps, or clear the fringes if no bitmaps are required
645 before DESIRED_ROW is made current. This function is called from
646 update_window_line only if it is known that there are differences
647 between bitmaps to be drawn between current row and DESIRED_ROW. */
650 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
657 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
658 desired_row
->redraw_fringe_bitmaps_p
= 1;
660 /* When a window has disappeared, make sure that no rest of
661 full-width rows stays visible in the internal border. Could
662 check here if updated window is the leftmost/rightmost window,
663 but I guess it's not worth doing since vertically split windows
664 are almost never used, internal border is rarely set, and the
665 overhead is very small. */
666 if (windows_or_buffers_changed
667 && desired_row
->full_width_p
668 && (f
= XFRAME (w
->frame
),
669 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
671 && (height
= desired_row
->visible_height
,
674 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
677 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
678 0, y
, width
, height
);
679 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
680 FRAME_PIXEL_WIDTH (f
) - width
,
687 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
689 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
690 Display
*display
= FRAME_X_DISPLAY (f
);
691 Window window
= FRAME_X_WINDOW (f
);
692 GC gc
= f
->output_data
.x
->normal_gc
;
693 struct face
*face
= p
->face
;
695 /* Must clip because of partially visible lines. */
696 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
700 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
702 /* In case the same realized face is used for fringes and
703 for something displayed in the text (e.g. face `region' on
704 mono-displays, the fill style may have been changed to
705 FillSolid in x_draw_glyph_string_background. */
707 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
709 XSetForeground (display
, face
->gc
, face
->background
);
711 #ifdef USE_TOOLKIT_SCROLL_BARS
712 /* If the fringe is adjacent to the left (right) scroll bar of a
713 leftmost (rightmost, respectively) window, then extend its
714 background to the gap between the fringe and the bar. */
715 if ((WINDOW_LEFTMOST_P (w
)
716 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
717 || (WINDOW_RIGHTMOST_P (w
)
718 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
720 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
724 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
725 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
726 * FRAME_COLUMN_WIDTH (f
));
730 /* Bitmap fills the fringe. */
731 if (bar_area_x
+ bar_area_width
== p
->x
)
732 bx
= bar_area_x
+ sb_width
;
733 else if (p
->x
+ p
->wd
== bar_area_x
)
737 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
739 nx
= bar_area_width
- sb_width
;
740 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
742 ny
= row
->visible_height
;
747 if (bar_area_x
+ bar_area_width
== bx
)
749 bx
= bar_area_x
+ sb_width
;
750 nx
+= bar_area_width
- sb_width
;
752 else if (bx
+ nx
== bar_area_x
)
753 nx
+= bar_area_width
- sb_width
;
758 if (bx
>= 0 && nx
> 0)
759 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
762 XSetForeground (display
, face
->gc
, face
->foreground
);
768 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
769 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
773 bits
= (char *) (p
->bits
+ p
->dh
);
775 bits
= (char *) p
->bits
+ p
->dh
;
777 /* Draw the bitmap. I believe these small pixmaps can be cached
779 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
781 ? (p
->overlay_p
? face
->background
782 : f
->output_data
.x
->cursor_pixel
)
784 face
->background
, depth
);
788 clipmask
= XCreatePixmapFromBitmapData (display
,
789 FRAME_DISPLAY_INFO (f
)->root_window
,
792 gcv
.clip_mask
= clipmask
;
793 gcv
.clip_x_origin
= p
->x
;
794 gcv
.clip_y_origin
= p
->y
;
795 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
798 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
799 p
->wd
, p
->h
, p
->x
, p
->y
);
800 XFreePixmap (display
, pixmap
);
804 gcv
.clip_mask
= (Pixmap
) 0;
805 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
806 XFreePixmap (display
, clipmask
);
810 XSetClipMask (display
, gc
, None
);
813 /***********************************************************************
815 ***********************************************************************/
819 static void x_set_glyph_string_clipping (struct glyph_string
*);
820 static void x_set_glyph_string_gc (struct glyph_string
*);
821 static void x_draw_glyph_string_foreground (struct glyph_string
*);
822 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
823 static void x_draw_glyph_string_box (struct glyph_string
*);
824 static void x_draw_glyph_string (struct glyph_string
*);
825 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
826 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
827 static void x_set_cursor_gc (struct glyph_string
*);
828 static void x_set_mode_line_face_gc (struct glyph_string
*);
829 static void x_set_mouse_face_gc (struct glyph_string
*);
830 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
831 unsigned long *, double, int);
832 static void x_setup_relief_color (struct frame
*, struct relief
*,
833 double, int, unsigned long);
834 static void x_setup_relief_colors (struct glyph_string
*);
835 static void x_draw_image_glyph_string (struct glyph_string
*);
836 static void x_draw_image_relief (struct glyph_string
*);
837 static void x_draw_image_foreground (struct glyph_string
*);
838 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
839 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
841 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
842 int, int, int, int, int, int,
844 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
845 int, int, int, XRectangle
*);
846 static void x_scroll_bar_clear (struct frame
*);
849 static void x_check_font (struct frame
*, struct font
*);
853 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
857 x_set_cursor_gc (struct glyph_string
*s
)
859 if (s
->font
== FRAME_FONT (s
->f
)
860 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
861 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
863 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
866 /* Cursor on non-default face: must merge. */
870 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
871 xgcv
.foreground
= s
->face
->background
;
873 /* If the glyph would be invisible, try a different foreground. */
874 if (xgcv
.foreground
== xgcv
.background
)
875 xgcv
.foreground
= s
->face
->foreground
;
876 if (xgcv
.foreground
== xgcv
.background
)
877 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
878 if (xgcv
.foreground
== xgcv
.background
)
879 xgcv
.foreground
= s
->face
->foreground
;
881 /* Make sure the cursor is distinct from text in this face. */
882 if (xgcv
.background
== s
->face
->background
883 && xgcv
.foreground
== s
->face
->foreground
)
885 xgcv
.background
= s
->face
->foreground
;
886 xgcv
.foreground
= s
->face
->background
;
889 IF_DEBUG (x_check_font (s
->f
, s
->font
));
890 xgcv
.graphics_exposures
= False
;
891 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
893 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
894 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
897 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
898 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
900 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
905 /* Set up S->gc of glyph string S for drawing text in mouse face. */
908 x_set_mouse_face_gc (struct glyph_string
*s
)
913 /* What face has to be used last for the mouse face? */
914 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
915 face
= FACE_FROM_ID (s
->f
, face_id
);
917 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
919 if (s
->first_glyph
->type
== CHAR_GLYPH
)
920 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
922 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
923 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
924 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
926 if (s
->font
== s
->face
->font
)
930 /* Otherwise construct scratch_cursor_gc with values from FACE
935 xgcv
.background
= s
->face
->background
;
936 xgcv
.foreground
= s
->face
->foreground
;
937 xgcv
.graphics_exposures
= False
;
938 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
940 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
941 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
944 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
945 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
947 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
950 eassert (s
->gc
!= 0);
954 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
955 Faces to use in the mode line have already been computed when the
956 matrix was built, so there isn't much to do, here. */
959 x_set_mode_line_face_gc (struct glyph_string
*s
)
965 /* Set S->gc of glyph string S for drawing that glyph string. Set
966 S->stippled_p to a non-zero value if the face of S has a stipple
970 x_set_glyph_string_gc (struct glyph_string
*s
)
972 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
974 if (s
->hl
== DRAW_NORMAL_TEXT
)
977 s
->stippled_p
= s
->face
->stipple
!= 0;
979 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
981 x_set_mode_line_face_gc (s
);
982 s
->stippled_p
= s
->face
->stipple
!= 0;
984 else if (s
->hl
== DRAW_CURSOR
)
989 else if (s
->hl
== DRAW_MOUSE_FACE
)
991 x_set_mouse_face_gc (s
);
992 s
->stippled_p
= s
->face
->stipple
!= 0;
994 else if (s
->hl
== DRAW_IMAGE_RAISED
995 || s
->hl
== DRAW_IMAGE_SUNKEN
)
998 s
->stippled_p
= s
->face
->stipple
!= 0;
1002 s
->gc
= s
->face
->gc
;
1003 s
->stippled_p
= s
->face
->stipple
!= 0;
1006 /* GC must have been set. */
1007 eassert (s
->gc
!= 0);
1011 /* Set clipping for output of glyph string S. S may be part of a mode
1012 line or menu if we don't have X toolkit support. */
1015 x_set_glyph_string_clipping (struct glyph_string
*s
)
1017 XRectangle
*r
= s
->clip
;
1018 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1021 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1026 /* Set SRC's clipping for output of glyph string DST. This is called
1027 when we are drawing DST's left_overhang or right_overhang only in
1031 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1036 r
.width
= src
->width
;
1038 r
.height
= src
->height
;
1041 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1046 Compute left and right overhang of glyph string S. */
1049 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1052 && (s
->first_glyph
->type
== CHAR_GLYPH
1053 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1055 struct font_metrics metrics
;
1057 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1059 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1060 struct font
*font
= s
->font
;
1063 for (i
= 0; i
< s
->nchars
; i
++)
1064 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1065 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1069 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1071 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1073 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1074 ? metrics
.rbearing
- metrics
.width
: 0);
1075 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1079 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1080 s
->left_overhang
= - s
->cmp
->lbearing
;
1085 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1088 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1091 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1092 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1093 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1094 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1098 /* Draw the background of glyph_string S. If S->background_filled_p
1099 is non-zero don't draw it. FORCE_P non-zero means draw the
1100 background even if it wouldn't be drawn normally. This is used
1101 when a string preceding S draws into the background of S, or S
1102 contains the first component of a composition. */
1105 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1107 /* Nothing to do if background has already been drawn or if it
1108 shouldn't be drawn in the first place. */
1109 if (!s
->background_filled_p
)
1111 int box_line_width
= max (s
->face
->box_line_width
, 0);
1115 /* Fill background with a stipple pattern. */
1116 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1117 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1118 s
->y
+ box_line_width
,
1119 s
->background_width
,
1120 s
->height
- 2 * box_line_width
);
1121 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1122 s
->background_filled_p
= 1;
1124 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1125 || s
->font_not_found_p
1126 || s
->extends_to_end_of_line_p
1129 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1130 s
->background_width
,
1131 s
->height
- 2 * box_line_width
);
1132 s
->background_filled_p
= 1;
1138 /* Draw the foreground of glyph string S. */
1141 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1145 /* If first glyph of S has a left box line, start drawing the text
1146 of S to the right of that box line. */
1147 if (s
->face
->box
!= FACE_NO_BOX
1148 && s
->first_glyph
->left_box_line_p
)
1149 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1153 /* Draw characters of S as rectangles if S's font could not be
1155 if (s
->font_not_found_p
)
1157 for (i
= 0; i
< s
->nchars
; ++i
)
1159 struct glyph
*g
= s
->first_glyph
+ i
;
1160 XDrawRectangle (s
->display
, s
->window
,
1161 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1163 x
+= g
->pixel_width
;
1168 struct font
*font
= s
->font
;
1169 int boff
= font
->baseline_offset
;
1172 if (font
->vertical_centering
)
1173 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1175 y
= s
->ybase
- boff
;
1177 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1178 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1180 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1181 if (s
->face
->overstrike
)
1182 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1186 /* Draw the foreground of composite glyph string S. */
1189 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1192 struct font
*font
= s
->font
;
1194 /* If first glyph of S has a left box line, start drawing the text
1195 of S to the right of that box line. */
1196 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1197 && s
->first_glyph
->left_box_line_p
)
1198 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1202 /* S is a glyph string for a composition. S->cmp_from is the index
1203 of the first character drawn for glyphs of this composition.
1204 S->cmp_from == 0 means we are drawing the very first character of
1205 this composition. */
1207 /* Draw a rectangle for the composition if the font for the very
1208 first character of the composition could not be loaded. */
1209 if (s
->font_not_found_p
)
1211 if (s
->cmp_from
== 0)
1212 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1213 s
->width
- 1, s
->height
- 1);
1215 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1219 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1220 /* TAB in a composition means display glyphs with padding
1221 space on the left or right. */
1222 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1224 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1225 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1227 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1228 if (s
->face
->overstrike
)
1229 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1234 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1239 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1241 glyph
= LGSTRING_GLYPH (gstring
, i
);
1242 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1243 width
+= LGLYPH_WIDTH (glyph
);
1246 int xoff
, yoff
, wadjust
;
1250 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1251 if (s
->face
->overstrike
)
1252 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1255 xoff
= LGLYPH_XOFF (glyph
);
1256 yoff
= LGLYPH_YOFF (glyph
);
1257 wadjust
= LGLYPH_WADJUST (glyph
);
1258 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1259 if (s
->face
->overstrike
)
1260 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1268 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1269 if (s
->face
->overstrike
)
1270 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1276 /* Draw the foreground of glyph string S for glyphless characters. */
1279 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1281 struct glyph
*glyph
= s
->first_glyph
;
1285 /* If first glyph of S has a left box line, start drawing the text
1286 of S to the right of that box line. */
1287 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1288 && s
->first_glyph
->left_box_line_p
)
1289 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1295 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1297 char buf
[7], *str
= NULL
;
1298 int len
= glyph
->u
.glyphless
.len
;
1300 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1303 && CHAR_TABLE_P (Vglyphless_char_display
)
1304 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1308 = (! glyph
->u
.glyphless
.for_no_font
1309 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1310 glyph
->u
.glyphless
.ch
)
1311 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1312 if (STRINGP (acronym
))
1313 str
= SSDATA (acronym
);
1316 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1318 sprintf (buf
, "%0*X",
1319 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1320 glyph
->u
.glyphless
.ch
);
1326 int upper_len
= (len
+ 1) / 2;
1329 /* It is assured that all LEN characters in STR is ASCII. */
1330 for (j
= 0; j
< len
; j
++)
1332 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1333 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1335 s
->font
->driver
->draw (s
, 0, upper_len
,
1336 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1337 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1339 s
->font
->driver
->draw (s
, upper_len
, len
,
1340 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1341 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1344 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1345 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
1346 x
, s
->ybase
- glyph
->ascent
,
1347 glyph
->pixel_width
- 1,
1348 glyph
->ascent
+ glyph
->descent
- 1);
1349 x
+= glyph
->pixel_width
;
1353 #ifdef USE_X_TOOLKIT
1357 /* Return the frame on which widget WIDGET is used.. Abort if frame
1358 cannot be determined. */
1360 static struct frame
*
1361 x_frame_of_widget (Widget widget
)
1363 struct x_display_info
*dpyinfo
;
1364 Lisp_Object tail
, frame
;
1367 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1369 /* Find the top-level shell of the widget. Note that this function
1370 can be called when the widget is not yet realized, so XtWindow
1371 (widget) == 0. That's the reason we can't simply use
1372 x_any_window_to_frame. */
1373 while (!XtIsTopLevelShell (widget
))
1374 widget
= XtParent (widget
);
1376 /* Look for a frame with that top-level widget. Allocate the color
1377 on that frame to get the right gamma correction value. */
1378 FOR_EACH_FRAME (tail
, frame
)
1382 && f
->output_data
.nothing
!= 1
1383 && FRAME_DISPLAY_INFO (f
) == dpyinfo
1384 && f
->output_data
.x
->widget
== widget
)
1390 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1391 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1392 If this produces the same color as PIXEL, try a color where all RGB
1393 values have DELTA added. Return the allocated color in *PIXEL.
1394 DISPLAY is the X display, CMAP is the colormap to operate on.
1395 Value is true if successful. */
1398 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1399 unsigned long *pixel
, double factor
, int delta
)
1401 struct frame
*f
= x_frame_of_widget (widget
);
1402 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1405 #endif /* USE_LUCID */
1408 /* Structure specifying which arguments should be passed by Xt to
1409 cvt_string_to_pixel. We want the widget's screen and colormap. */
1411 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1413 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1415 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1420 /* The address of this variable is returned by
1421 cvt_string_to_pixel. */
1423 static Pixel cvt_string_to_pixel_value
;
1426 /* Convert a color name to a pixel color.
1428 DPY is the display we are working on.
1430 ARGS is an array of *NARGS XrmValue structures holding additional
1431 information about the widget for which the conversion takes place.
1432 The contents of this array are determined by the specification
1433 in cvt_string_to_pixel_args.
1435 FROM is a pointer to an XrmValue which points to the color name to
1436 convert. TO is an XrmValue in which to return the pixel color.
1438 CLOSURE_RET is a pointer to user-data, in which we record if
1439 we allocated the color or not.
1441 Value is True if successful, False otherwise. */
1444 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1445 XrmValue
*from
, XrmValue
*to
,
1446 XtPointer
*closure_ret
)
1456 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1457 "wrongParameters", "cvt_string_to_pixel",
1459 "Screen and colormap args required", NULL
, NULL
);
1463 screen
= *(Screen
**) args
[0].addr
;
1464 cmap
= *(Colormap
*) args
[1].addr
;
1465 color_name
= (String
) from
->addr
;
1467 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1469 *closure_ret
= (XtPointer
) False
;
1470 pixel
= WhitePixelOfScreen (screen
);
1472 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1474 *closure_ret
= (XtPointer
) False
;
1475 pixel
= BlackPixelOfScreen (screen
);
1477 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1478 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1480 pixel
= color
.pixel
;
1481 *closure_ret
= (XtPointer
) True
;
1486 Cardinal nparams
= 1;
1488 params
[0] = color_name
;
1489 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1490 "badValue", "cvt_string_to_pixel",
1491 "XtToolkitError", "Invalid color `%s'",
1496 if (to
->addr
!= NULL
)
1498 if (to
->size
< sizeof (Pixel
))
1500 to
->size
= sizeof (Pixel
);
1504 *(Pixel
*) to
->addr
= pixel
;
1508 cvt_string_to_pixel_value
= pixel
;
1509 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1512 to
->size
= sizeof (Pixel
);
1517 /* Free a pixel color which was previously allocated via
1518 cvt_string_to_pixel. This is registered as the destructor
1519 for this type of resource via XtSetTypeConverter.
1521 APP is the application context in which we work.
1523 TO is a pointer to an XrmValue holding the color to free.
1524 CLOSURE is the value we stored in CLOSURE_RET for this color
1525 in cvt_string_to_pixel.
1527 ARGS and NARGS are like for cvt_string_to_pixel. */
1530 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1535 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1537 "Screen and colormap arguments required",
1540 else if (closure
!= NULL
)
1542 /* We did allocate the pixel, so free it. */
1543 Screen
*screen
= *(Screen
**) args
[0].addr
;
1544 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1545 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1546 (Pixel
*) to
->addr
, 1);
1551 #endif /* USE_X_TOOLKIT */
1554 /* Value is an array of XColor structures for the contents of the
1555 color map of display DPY. Set *NCELLS to the size of the array.
1556 Note that this probably shouldn't be called for large color maps,
1557 say a 24-bit TrueColor map. */
1559 static const XColor
*
1560 x_color_cells (Display
*dpy
, int *ncells
)
1562 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1564 if (dpyinfo
->color_cells
== NULL
)
1566 Screen
*screen
= dpyinfo
->screen
;
1567 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1570 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
1571 sizeof *dpyinfo
->color_cells
);
1572 dpyinfo
->ncolor_cells
= ncolor_cells
;
1574 for (i
= 0; i
< ncolor_cells
; ++i
)
1575 dpyinfo
->color_cells
[i
].pixel
= i
;
1577 XQueryColors (dpy
, dpyinfo
->cmap
,
1578 dpyinfo
->color_cells
, ncolor_cells
);
1581 *ncells
= dpyinfo
->ncolor_cells
;
1582 return dpyinfo
->color_cells
;
1586 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1587 colors in COLORS. Use cached information, if available. */
1590 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1592 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1594 if (dpyinfo
->color_cells
)
1597 for (i
= 0; i
< ncolors
; ++i
)
1599 unsigned long pixel
= colors
[i
].pixel
;
1600 eassert (pixel
< dpyinfo
->ncolor_cells
);
1601 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1602 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1606 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1610 /* On frame F, translate pixel color to RGB values for the color in
1611 COLOR. Use cached information, if available. */
1614 x_query_color (struct frame
*f
, XColor
*color
)
1616 x_query_colors (f
, color
, 1);
1620 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1621 exact match can't be allocated, try the nearest color available.
1622 Value is true if successful. Set *COLOR to the color
1626 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1630 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1633 /* If we got to this point, the colormap is full, so we're going
1634 to try to get the next closest color. The algorithm used is
1635 a least-squares matching, which is what X uses for closest
1636 color matching with StaticColor visuals. */
1638 int max_color_delta
= 255;
1639 int max_delta
= 3 * max_color_delta
;
1640 int nearest_delta
= max_delta
+ 1;
1642 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1644 for (nearest
= i
= 0; i
< ncells
; ++i
)
1646 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1647 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1648 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1649 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1651 if (delta
< nearest_delta
)
1654 nearest_delta
= delta
;
1658 color
->red
= cells
[nearest
].red
;
1659 color
->green
= cells
[nearest
].green
;
1660 color
->blue
= cells
[nearest
].blue
;
1661 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1665 /* If allocation succeeded, and the allocated pixel color is not
1666 equal to a cached pixel color recorded earlier, there was a
1667 change in the colormap, so clear the color cache. */
1668 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1669 XColor
*cached_color
;
1671 if (dpyinfo
->color_cells
1672 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1673 (cached_color
->red
!= color
->red
1674 || cached_color
->blue
!= color
->blue
1675 || cached_color
->green
!= color
->green
)))
1677 xfree (dpyinfo
->color_cells
);
1678 dpyinfo
->color_cells
= NULL
;
1679 dpyinfo
->ncolor_cells
= 0;
1683 #ifdef DEBUG_X_COLORS
1685 register_color (color
->pixel
);
1686 #endif /* DEBUG_X_COLORS */
1692 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1693 exact match can't be allocated, try the nearest color available.
1694 Value is true if successful. Set *COLOR to the color
1698 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1700 gamma_correct (f
, color
);
1701 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1705 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1706 It's necessary to do this instead of just using PIXEL directly to
1707 get color reference counts right. */
1710 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1714 color
.pixel
= pixel
;
1716 x_query_color (f
, &color
);
1717 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1719 #ifdef DEBUG_X_COLORS
1720 register_color (pixel
);
1726 /* Brightness beyond which a color won't have its highlight brightness
1729 Nominally, highlight colors for `3d' faces are calculated by
1730 brightening an object's color by a constant scale factor, but this
1731 doesn't yield good results for dark colors, so for colors who's
1732 brightness is less than this value (on a scale of 0-65535) have an
1733 use an additional additive factor.
1735 The value here is set so that the default menu-bar/mode-line color
1736 (grey75) will not have its highlights changed at all. */
1737 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1740 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1741 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1742 If this produces the same color as PIXEL, try a color where all RGB
1743 values have DELTA added. Return the allocated color in *PIXEL.
1744 DISPLAY is the X display, CMAP is the colormap to operate on.
1745 Value is non-zero if successful. */
1748 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1754 /* Get RGB color values. */
1755 color
.pixel
= *pixel
;
1756 x_query_color (f
, &color
);
1758 /* Change RGB values by specified FACTOR. Avoid overflow! */
1759 eassert (factor
>= 0);
1760 new.red
= min (0xffff, factor
* color
.red
);
1761 new.green
= min (0xffff, factor
* color
.green
);
1762 new.blue
= min (0xffff, factor
* color
.blue
);
1764 /* Calculate brightness of COLOR. */
1765 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1767 /* We only boost colors that are darker than
1768 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1769 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1770 /* Make an additive adjustment to NEW, because it's dark enough so
1771 that scaling by FACTOR alone isn't enough. */
1773 /* How far below the limit this color is (0 - 1, 1 being darker). */
1774 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1775 /* The additive adjustment. */
1776 int min_delta
= delta
* dimness
* factor
/ 2;
1780 new.red
= max (0, new.red
- min_delta
);
1781 new.green
= max (0, new.green
- min_delta
);
1782 new.blue
= max (0, new.blue
- min_delta
);
1786 new.red
= min (0xffff, min_delta
+ new.red
);
1787 new.green
= min (0xffff, min_delta
+ new.green
);
1788 new.blue
= min (0xffff, min_delta
+ new.blue
);
1792 /* Try to allocate the color. */
1793 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1796 if (new.pixel
== *pixel
)
1798 /* If we end up with the same color as before, try adding
1799 delta to the RGB values. */
1800 x_free_colors (f
, &new.pixel
, 1);
1802 new.red
= min (0xffff, delta
+ color
.red
);
1803 new.green
= min (0xffff, delta
+ color
.green
);
1804 new.blue
= min (0xffff, delta
+ color
.blue
);
1805 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1816 /* Set up the foreground color for drawing relief lines of glyph
1817 string S. RELIEF is a pointer to a struct relief containing the GC
1818 with which lines will be drawn. Use a color that is FACTOR or
1819 DELTA lighter or darker than the relief's background which is found
1820 in S->f->output_data.x->relief_background. If such a color cannot
1821 be allocated, use DEFAULT_PIXEL, instead. */
1824 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1827 struct x_output
*di
= f
->output_data
.x
;
1828 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1829 unsigned long pixel
;
1830 unsigned long background
= di
->relief_background
;
1831 Colormap cmap
= FRAME_X_COLORMAP (f
);
1832 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1833 Display
*dpy
= FRAME_X_DISPLAY (f
);
1835 xgcv
.graphics_exposures
= False
;
1836 xgcv
.line_width
= 1;
1838 /* Free previously allocated color. The color cell will be reused
1839 when it has been freed as many times as it was allocated, so this
1840 doesn't affect faces using the same colors. */
1842 && relief
->allocated_p
)
1844 x_free_colors (f
, &relief
->pixel
, 1);
1845 relief
->allocated_p
= 0;
1848 /* Allocate new color. */
1849 xgcv
.foreground
= default_pixel
;
1851 if (dpyinfo
->n_planes
!= 1
1852 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1854 relief
->allocated_p
= 1;
1855 xgcv
.foreground
= relief
->pixel
= pixel
;
1858 if (relief
->gc
== 0)
1860 xgcv
.stipple
= dpyinfo
->gray
;
1862 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1865 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1869 /* Set up colors for the relief lines around glyph string S. */
1872 x_setup_relief_colors (struct glyph_string
*s
)
1874 struct x_output
*di
= s
->f
->output_data
.x
;
1875 unsigned long color
;
1877 if (s
->face
->use_box_color_for_shadows_p
)
1878 color
= s
->face
->box_color
;
1879 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1881 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1882 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1887 /* Get the background color of the face. */
1888 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1889 color
= xgcv
.background
;
1892 if (di
->white_relief
.gc
== 0
1893 || color
!= di
->relief_background
)
1895 di
->relief_background
= color
;
1896 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1897 WHITE_PIX_DEFAULT (s
->f
));
1898 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1899 BLACK_PIX_DEFAULT (s
->f
));
1904 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1905 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1906 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1907 relief. LEFT_P non-zero means draw a relief on the left side of
1908 the rectangle. RIGHT_P non-zero means draw a relief on the right
1909 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1913 x_draw_relief_rect (struct frame
*f
,
1914 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1915 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1916 XRectangle
*clip_rect
)
1918 Display
*dpy
= FRAME_X_DISPLAY (f
);
1919 Window window
= FRAME_X_WINDOW (f
);
1924 gc
= f
->output_data
.x
->white_relief
.gc
;
1926 gc
= f
->output_data
.x
->black_relief
.gc
;
1927 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1929 /* This code is more complicated than it has to be, because of two
1930 minor hacks to make the boxes look nicer: (i) if width > 1, draw
1931 the outermost line using the black relief. (ii) Omit the four
1938 XDrawLine (dpy
, window
, gc
,
1939 left_x
+ (left_p
? 1 : 0), top_y
,
1940 right_x
+ (right_p
? 0 : 1), top_y
);
1942 for (i
= 1; i
< width
; ++i
)
1943 XDrawLine (dpy
, window
, gc
,
1944 left_x
+ i
* left_p
, top_y
+ i
,
1945 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1952 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1954 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
1955 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
1957 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
1958 XDrawLine (dpy
, window
, gc
,
1959 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
1960 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1963 XSetClipMask (dpy
, gc
, None
);
1965 gc
= f
->output_data
.x
->black_relief
.gc
;
1967 gc
= f
->output_data
.x
->white_relief
.gc
;
1968 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1972 /* Outermost top line. */
1974 XDrawLine (dpy
, window
, gc
,
1975 left_x
+ (left_p
? 1 : 0), top_y
,
1976 right_x
+ (right_p
? 0 : 1), top_y
);
1978 /* Outermost left line. */
1980 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1986 XDrawLine (dpy
, window
, gc
,
1987 left_x
+ (left_p
? 1 : 0), bottom_y
,
1988 right_x
+ (right_p
? 0 : 1), bottom_y
);
1989 for (i
= 1; i
< width
; ++i
)
1990 XDrawLine (dpy
, window
, gc
,
1991 left_x
+ i
* left_p
, bottom_y
- i
,
1992 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
1998 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
1999 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
2000 for (i
= 0; i
< width
; ++i
)
2001 XDrawLine (dpy
, window
, gc
,
2002 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
2003 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
2006 XSetClipMask (dpy
, gc
, None
);
2010 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2011 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2012 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2013 left side of the rectangle. RIGHT_P non-zero means draw a line
2014 on the right side of the rectangle. CLIP_RECT is the clipping
2015 rectangle to use when drawing. */
2018 x_draw_box_rect (struct glyph_string
*s
,
2019 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2020 int left_p
, int right_p
, XRectangle
*clip_rect
)
2024 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2025 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2026 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2029 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2030 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2034 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2035 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2038 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2039 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2043 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2044 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2046 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2047 XSetClipMask (s
->display
, s
->gc
, None
);
2051 /* Draw a box around glyph string S. */
2054 x_draw_glyph_string_box (struct glyph_string
*s
)
2056 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2057 int left_p
, right_p
;
2058 struct glyph
*last_glyph
;
2059 XRectangle clip_rect
;
2061 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2062 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2063 : window_box_right (s
->w
, s
->area
));
2065 /* The glyph that may have a right box line. */
2066 last_glyph
= (s
->cmp
|| s
->img
2068 : s
->first_glyph
+ s
->nchars
- 1);
2070 width
= eabs (s
->face
->box_line_width
);
2071 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2073 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2075 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2077 bottom_y
= top_y
+ s
->height
- 1;
2079 left_p
= (s
->first_glyph
->left_box_line_p
2080 || (s
->hl
== DRAW_MOUSE_FACE
2082 || s
->prev
->hl
!= s
->hl
)));
2083 right_p
= (last_glyph
->right_box_line_p
2084 || (s
->hl
== DRAW_MOUSE_FACE
2086 || s
->next
->hl
!= s
->hl
)));
2088 get_glyph_string_clip_rect (s
, &clip_rect
);
2090 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2091 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2092 left_p
, right_p
, &clip_rect
);
2095 x_setup_relief_colors (s
);
2096 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2097 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2102 /* Draw foreground of image glyph string S. */
2105 x_draw_image_foreground (struct glyph_string
*s
)
2108 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2110 /* If first glyph of S has a left box line, start drawing it to the
2111 right of that line. */
2112 if (s
->face
->box
!= FACE_NO_BOX
2113 && s
->first_glyph
->left_box_line_p
2115 x
+= eabs (s
->face
->box_line_width
);
2117 /* If there is a margin around the image, adjust x- and y-position
2119 if (s
->slice
.x
== 0)
2120 x
+= s
->img
->hmargin
;
2121 if (s
->slice
.y
== 0)
2122 y
+= s
->img
->vmargin
;
2128 /* We can't set both a clip mask and use XSetClipRectangles
2129 because the latter also sets a clip mask. We also can't
2130 trust on the shape extension to be available
2131 (XShapeCombineRegion). So, compute the rectangle to draw
2133 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2136 XRectangle clip_rect
, image_rect
, r
;
2138 xgcv
.clip_mask
= s
->img
->mask
;
2139 xgcv
.clip_x_origin
= x
;
2140 xgcv
.clip_y_origin
= y
;
2141 xgcv
.function
= GXcopy
;
2142 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2144 get_glyph_string_clip_rect (s
, &clip_rect
);
2147 image_rect
.width
= s
->slice
.width
;
2148 image_rect
.height
= s
->slice
.height
;
2149 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2150 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2151 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2152 r
.width
, r
.height
, r
.x
, r
.y
);
2156 XRectangle clip_rect
, image_rect
, r
;
2158 get_glyph_string_clip_rect (s
, &clip_rect
);
2161 image_rect
.width
= s
->slice
.width
;
2162 image_rect
.height
= s
->slice
.height
;
2163 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2164 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2165 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2166 r
.width
, r
.height
, r
.x
, r
.y
);
2168 /* When the image has a mask, we can expect that at
2169 least part of a mouse highlight or a block cursor will
2170 be visible. If the image doesn't have a mask, make
2171 a block cursor visible by drawing a rectangle around
2172 the image. I believe it's looking better if we do
2173 nothing here for mouse-face. */
2174 if (s
->hl
== DRAW_CURSOR
)
2176 int relief
= eabs (s
->img
->relief
);
2177 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2178 x
- relief
, y
- relief
,
2179 s
->slice
.width
+ relief
*2 - 1,
2180 s
->slice
.height
+ relief
*2 - 1);
2185 /* Draw a rectangle if image could not be loaded. */
2186 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2187 s
->slice
.width
- 1, s
->slice
.height
- 1);
2191 /* Draw a relief around the image glyph string S. */
2194 x_draw_image_relief (struct glyph_string
*s
)
2196 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
2199 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2201 /* If first glyph of S has a left box line, start drawing it to the
2202 right of that line. */
2203 if (s
->face
->box
!= FACE_NO_BOX
2204 && s
->first_glyph
->left_box_line_p
2206 x
+= eabs (s
->face
->box_line_width
);
2208 /* If there is a margin around the image, adjust x- and y-position
2210 if (s
->slice
.x
== 0)
2211 x
+= s
->img
->hmargin
;
2212 if (s
->slice
.y
== 0)
2213 y
+= s
->img
->vmargin
;
2215 if (s
->hl
== DRAW_IMAGE_SUNKEN
2216 || s
->hl
== DRAW_IMAGE_RAISED
)
2218 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2219 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2223 thick
= eabs (s
->img
->relief
);
2224 raised_p
= s
->img
->relief
> 0;
2227 x1
= x
+ s
->slice
.width
- 1;
2228 y1
= y
+ s
->slice
.height
- 1;
2229 top_p
= bot_p
= left_p
= right_p
= 0;
2231 if (s
->slice
.x
== 0)
2232 x
-= thick
, left_p
= 1;
2233 if (s
->slice
.y
== 0)
2234 y
-= thick
, top_p
= 1;
2235 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
2236 x1
+= thick
, right_p
= 1;
2237 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
2238 y1
+= thick
, bot_p
= 1;
2240 x_setup_relief_colors (s
);
2241 get_glyph_string_clip_rect (s
, &r
);
2242 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
2243 top_p
, bot_p
, left_p
, right_p
, &r
);
2247 /* Draw the foreground of image glyph string S to PIXMAP. */
2250 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2253 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2255 /* If first glyph of S has a left box line, start drawing it to the
2256 right of that line. */
2257 if (s
->face
->box
!= FACE_NO_BOX
2258 && s
->first_glyph
->left_box_line_p
2260 x
+= eabs (s
->face
->box_line_width
);
2262 /* If there is a margin around the image, adjust x- and y-position
2264 if (s
->slice
.x
== 0)
2265 x
+= s
->img
->hmargin
;
2266 if (s
->slice
.y
== 0)
2267 y
+= s
->img
->vmargin
;
2273 /* We can't set both a clip mask and use XSetClipRectangles
2274 because the latter also sets a clip mask. We also can't
2275 trust on the shape extension to be available
2276 (XShapeCombineRegion). So, compute the rectangle to draw
2278 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2282 xgcv
.clip_mask
= s
->img
->mask
;
2283 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2284 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2285 xgcv
.function
= GXcopy
;
2286 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2288 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2289 s
->slice
.x
, s
->slice
.y
,
2290 s
->slice
.width
, s
->slice
.height
, x
, y
);
2291 XSetClipMask (s
->display
, s
->gc
, None
);
2295 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2296 s
->slice
.x
, s
->slice
.y
,
2297 s
->slice
.width
, s
->slice
.height
, x
, y
);
2299 /* When the image has a mask, we can expect that at
2300 least part of a mouse highlight or a block cursor will
2301 be visible. If the image doesn't have a mask, make
2302 a block cursor visible by drawing a rectangle around
2303 the image. I believe it's looking better if we do
2304 nothing here for mouse-face. */
2305 if (s
->hl
== DRAW_CURSOR
)
2307 int r
= eabs (s
->img
->relief
);
2308 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2309 s
->slice
.width
+ r
*2 - 1,
2310 s
->slice
.height
+ r
*2 - 1);
2315 /* Draw a rectangle if image could not be loaded. */
2316 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2317 s
->slice
.width
- 1, s
->slice
.height
- 1);
2321 /* Draw part of the background of glyph string S. X, Y, W, and H
2322 give the rectangle to draw. */
2325 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2329 /* Fill background with a stipple pattern. */
2330 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2331 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2332 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2335 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2339 /* Draw image glyph string S.
2342 s->x +-------------------------
2345 | +-------------------------
2348 | | +-------------------
2354 x_draw_image_glyph_string (struct glyph_string
*s
)
2356 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2357 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2359 Pixmap pixmap
= None
;
2362 if (s
->slice
.y
== 0)
2363 height
-= box_line_vwidth
;
2364 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2365 height
-= box_line_vwidth
;
2367 /* Fill background with face under the image. Do it only if row is
2368 taller than image or if image has a clip mask to reduce
2370 s
->stippled_p
= s
->face
->stipple
!= 0;
2371 if (height
> s
->slice
.height
2375 || s
->img
->pixmap
== 0
2376 || s
->width
!= s
->background_width
)
2380 /* Create a pixmap as large as the glyph string. Fill it
2381 with the background color. Copy the image to it, using
2382 its mask. Copy the temporary pixmap to the display. */
2383 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2384 int depth
= DefaultDepthOfScreen (screen
);
2386 /* Create a pixmap as large as the glyph string. */
2387 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2388 s
->background_width
,
2391 /* Don't clip in the following because we're working on the
2393 XSetClipMask (s
->display
, s
->gc
, None
);
2395 /* Fill the pixmap with the background color/stipple. */
2398 /* Fill background with a stipple pattern. */
2399 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2400 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2401 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2402 0, 0, s
->background_width
, s
->height
);
2403 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2404 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2409 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2411 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2412 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2413 0, 0, s
->background_width
, s
->height
);
2414 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2422 if (s
->first_glyph
->left_box_line_p
2424 x
+= box_line_hwidth
;
2426 if (s
->slice
.y
== 0)
2427 y
+= box_line_vwidth
;
2429 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2432 s
->background_filled_p
= 1;
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_offset (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
);
2538 else if (!s
->background_filled_p
)
2540 int background_width
= s
->background_width
;
2541 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2543 /* Don't draw into left margin, fringe or scrollbar area
2544 except for header line and mode line. */
2545 if (x
< left_x
&& !s
->row
->mode_line_p
)
2547 background_width
-= left_x
- x
;
2550 if (background_width
> 0)
2551 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2554 s
->background_filled_p
= 1;
2558 Draw a wavy line under S. The wave fills wave_height pixels from y0.
2564 wave_height = 3 | * * * *
2569 x_draw_underwave (struct glyph_string
*s
)
2571 int wave_height
= 3, wave_length
= 2;
2572 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
2573 XRectangle wave_clip
, string_clip
, final_clip
;
2576 dy
= wave_height
- 1;
2578 y0
= s
->ybase
- wave_height
+ 3;
2582 /* Find and set clipping rectangle */
2586 wave_clip
.width
= width
;
2587 wave_clip
.height
= wave_height
;
2588 get_glyph_string_clip_rect (s
, &string_clip
);
2590 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
2593 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
2595 /* Draw the waves */
2597 x1
= x0
- (x0
% dx
);
2607 if (INT_MAX
- dx
< xmax
)
2612 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
2614 x2
+= dx
, y2
= y0
+ odd
*dy
;
2618 /* Restore previous clipping rectangle(s) */
2619 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
2623 /* Draw glyph string S. */
2626 x_draw_glyph_string (struct glyph_string
*s
)
2628 bool relief_drawn_p
= 0;
2630 /* If S draws into the background of its successors, draw the
2631 background of the successors first so that S can draw into it.
2632 This makes S->next use XDrawString instead of XDrawImageString. */
2633 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2636 struct glyph_string
*next
;
2638 for (width
= 0, next
= s
->next
;
2639 next
&& width
< s
->right_overhang
;
2640 width
+= next
->width
, next
= next
->next
)
2641 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2643 x_set_glyph_string_gc (next
);
2644 x_set_glyph_string_clipping (next
);
2645 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2646 x_draw_stretch_glyph_string (next
);
2648 x_draw_glyph_string_background (next
, 1);
2649 next
->num_clips
= 0;
2653 /* Set up S->gc, set clipping and draw S. */
2654 x_set_glyph_string_gc (s
);
2656 /* Draw relief (if any) in advance for char/composition so that the
2657 glyph string can be drawn over it. */
2658 if (!s
->for_overlaps
2659 && s
->face
->box
!= FACE_NO_BOX
2660 && (s
->first_glyph
->type
== CHAR_GLYPH
2661 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2664 x_set_glyph_string_clipping (s
);
2665 x_draw_glyph_string_background (s
, 1);
2666 x_draw_glyph_string_box (s
);
2667 x_set_glyph_string_clipping (s
);
2670 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2672 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2673 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2674 /* We must clip just this glyph. left_overhang part has already
2675 drawn when s->prev was drawn, and right_overhang part will be
2676 drawn later when s->next is drawn. */
2677 x_set_glyph_string_clipping_exactly (s
, s
);
2679 x_set_glyph_string_clipping (s
);
2681 switch (s
->first_glyph
->type
)
2684 x_draw_image_glyph_string (s
);
2688 x_draw_stretch_glyph_string (s
);
2692 if (s
->for_overlaps
)
2693 s
->background_filled_p
= 1;
2695 x_draw_glyph_string_background (s
, 0);
2696 x_draw_glyph_string_foreground (s
);
2699 case COMPOSITE_GLYPH
:
2700 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2701 && ! s
->first_glyph
->u
.cmp
.automatic
))
2702 s
->background_filled_p
= 1;
2704 x_draw_glyph_string_background (s
, 1);
2705 x_draw_composite_glyph_string_foreground (s
);
2708 case GLYPHLESS_GLYPH
:
2709 if (s
->for_overlaps
)
2710 s
->background_filled_p
= 1;
2712 x_draw_glyph_string_background (s
, 1);
2713 x_draw_glyphless_glyph_string_foreground (s
);
2720 if (!s
->for_overlaps
)
2722 /* Draw underline. */
2723 if (s
->face
->underline_p
)
2725 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2727 if (s
->face
->underline_defaulted_p
)
2728 x_draw_underwave (s
);
2732 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2733 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2734 x_draw_underwave (s
);
2735 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2738 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2740 unsigned long thickness
, position
;
2743 if (s
->prev
&& s
->prev
->face
->underline_p
2744 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2746 /* We use the same underline style as the previous one. */
2747 thickness
= s
->prev
->underline_thickness
;
2748 position
= s
->prev
->underline_position
;
2752 /* Get the underline thickness. Default is 1 pixel. */
2753 if (s
->font
&& s
->font
->underline_thickness
> 0)
2754 thickness
= s
->font
->underline_thickness
;
2757 if (x_underline_at_descent_line
)
2758 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2761 /* Get the underline position. This is the recommended
2762 vertical offset in pixels from the baseline to the top of
2763 the underline. This is a signed value according to the
2764 specs, and its default is
2766 ROUND ((maximum descent) / 2), with
2767 ROUND(x) = floor (x + 0.5) */
2769 if (x_use_underline_position_properties
2770 && s
->font
&& s
->font
->underline_position
>= 0)
2771 position
= s
->font
->underline_position
;
2773 position
= (s
->font
->descent
+ 1) / 2;
2775 position
= underline_minimum_offset
;
2777 position
= max (position
, underline_minimum_offset
);
2779 /* Check the sanity of thickness and position. We should
2780 avoid drawing underline out of the current line area. */
2781 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2782 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2783 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2784 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2785 s
->underline_thickness
= thickness
;
2786 s
->underline_position
= position
;
2787 y
= s
->ybase
+ position
;
2788 if (s
->face
->underline_defaulted_p
)
2789 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2790 s
->x
, y
, s
->width
, thickness
);
2794 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2795 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2796 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2797 s
->x
, y
, s
->width
, thickness
);
2798 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2802 /* Draw overline. */
2803 if (s
->face
->overline_p
)
2805 unsigned long dy
= 0, h
= 1;
2807 if (s
->face
->overline_color_defaulted_p
)
2808 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2813 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2814 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2815 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2817 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2821 /* Draw strike-through. */
2822 if (s
->face
->strike_through_p
)
2824 unsigned long h
= 1;
2825 unsigned long dy
= (s
->height
- h
) / 2;
2827 if (s
->face
->strike_through_color_defaulted_p
)
2828 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2833 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2834 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2835 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2837 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2841 /* Draw relief if not yet drawn. */
2842 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2843 x_draw_glyph_string_box (s
);
2847 struct glyph_string
*prev
;
2849 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2850 if (prev
->hl
!= s
->hl
2851 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2853 /* As prev was drawn while clipped to its own area, we
2854 must draw the right_overhang part using s->hl now. */
2855 enum draw_glyphs_face save
= prev
->hl
;
2858 x_set_glyph_string_gc (prev
);
2859 x_set_glyph_string_clipping_exactly (s
, prev
);
2860 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2861 x_draw_glyph_string_foreground (prev
);
2863 x_draw_composite_glyph_string_foreground (prev
);
2864 XSetClipMask (prev
->display
, prev
->gc
, None
);
2866 prev
->num_clips
= 0;
2872 struct glyph_string
*next
;
2874 for (next
= s
->next
; next
; next
= next
->next
)
2875 if (next
->hl
!= s
->hl
2876 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2878 /* As next will be drawn while clipped to its own area,
2879 we must draw the left_overhang part using s->hl now. */
2880 enum draw_glyphs_face save
= next
->hl
;
2883 x_set_glyph_string_gc (next
);
2884 x_set_glyph_string_clipping_exactly (s
, next
);
2885 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2886 x_draw_glyph_string_foreground (next
);
2888 x_draw_composite_glyph_string_foreground (next
);
2889 XSetClipMask (next
->display
, next
->gc
, None
);
2891 next
->num_clips
= 0;
2892 next
->clip_head
= s
->next
;
2897 /* Reset clipping. */
2898 XSetClipMask (s
->display
, s
->gc
, None
);
2902 /* Shift display to make room for inserted glyphs. */
2905 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2907 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2908 f
->output_data
.x
->normal_gc
,
2909 x
, y
, width
, height
,
2913 /* Delete N glyphs at the nominal cursor position. Not implemented
2917 x_delete_glyphs (struct frame
*f
, register int n
)
2923 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2924 If they are <= 0, this is probably an error. */
2927 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
)
2929 eassert (width
> 0 && height
> 0);
2930 XClearArea (dpy
, window
, x
, y
, width
, height
, False
);
2934 /* Clear an entire frame. */
2937 x_clear_frame (struct frame
*f
)
2939 /* Clearing the frame will erase any cursor, so mark them all as no
2941 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2945 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2947 /* We have to clear the scroll bars. If we have changed colors or
2948 something like that, then they should be notified. */
2949 x_scroll_bar_clear (f
);
2951 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2952 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2953 redisplay, do it here. */
2954 if (FRAME_GTK_WIDGET (f
))
2955 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2958 XFlush (FRAME_X_DISPLAY (f
));
2965 /* Invert the middle quarter of the frame for .15 sec. */
2968 XTflash (struct frame
*f
)
2974 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
2975 when the scroll bars and the edit widget share the same X window. */
2976 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
2978 cairo_t
*cr
= gdk_cairo_create (window
);
2979 cairo_set_source_rgb (cr
, 1, 1, 1);
2980 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
2981 #define XFillRectangle(d, win, gc, x, y, w, h) \
2983 cairo_rectangle (cr, x, y, w, h); \
2987 #else /* ! HAVE_GTK3 */
2990 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
2991 ^ FRAME_BACKGROUND_PIXEL (f
));
2992 vals
.function
= GDK_XOR
;
2993 gc
= gdk_gc_new_with_values (window
,
2994 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
2995 #define XFillRectangle(d, win, gc, x, y, w, h) \
2996 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
2997 #endif /* ! HAVE_GTK3 */
2998 #else /* ! USE_GTK */
3001 /* Create a GC that will use the GXxor function to flip foreground
3002 pixels into background pixels. */
3006 values
.function
= GXxor
;
3007 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3008 ^ FRAME_BACKGROUND_PIXEL (f
));
3010 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3011 GCFunction
| GCForeground
, &values
);
3015 /* Get the height not including a menu bar widget. */
3016 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3017 /* Height of each line to flash. */
3018 int flash_height
= FRAME_LINE_HEIGHT (f
);
3019 /* These will be the left and right margins of the rectangles. */
3020 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3021 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3025 /* Don't flash the area between a scroll bar and the frame
3026 edge it is next to. */
3027 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3029 case vertical_scroll_bar_left
:
3030 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3033 case vertical_scroll_bar_right
:
3034 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3041 width
= flash_right
- flash_left
;
3043 /* If window is tall, flash top and bottom line. */
3044 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3046 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3048 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3049 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3050 width
, flash_height
);
3051 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3053 (height
- flash_height
3054 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3055 width
, flash_height
);
3059 /* If it is short, flash it all. */
3060 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3061 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3062 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3067 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
3068 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
3070 /* Keep waiting until past the time wakeup or any input gets
3072 while (! detect_input_pending ())
3074 struct timespec current
= current_timespec ();
3075 struct timespec timeout
;
3077 /* Break if result would not be positive. */
3078 if (timespec_cmp (wakeup
, current
) <= 0)
3081 /* How long `select' should wait. */
3082 timeout
= make_timespec (0, 10 * 1000 * 1000);
3084 /* Try to wait that long--but we might wake up sooner. */
3085 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3089 /* If window is tall, flash top and bottom line. */
3090 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3092 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3094 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3095 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3096 width
, flash_height
);
3097 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3099 (height
- flash_height
3100 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3101 width
, flash_height
);
3104 /* If it is short, flash it all. */
3105 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3106 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3107 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3113 g_object_unref (G_OBJECT (gc
));
3115 #undef XFillRectangle
3117 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3128 XTtoggle_invisible_pointer (struct frame
*f
, int invisible
)
3133 if (FRAME_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3134 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3135 FRAME_DISPLAY_INFO (f
)->invisible_cursor
);
3138 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3139 f
->output_data
.x
->current_cursor
);
3140 f
->pointer_invisible
= invisible
;
3145 /* Make audible bell. */
3148 XTring_bell (struct frame
*f
)
3150 if (FRAME_X_DISPLAY (f
))
3158 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
3160 XBell (FRAME_X_DISPLAY (f
), 0);
3162 XFlush (FRAME_X_DISPLAY (f
));
3168 /***********************************************************************
3170 ***********************************************************************/
3172 /* Perform an insert-lines or delete-lines operation, inserting N
3173 lines or deleting -N lines at vertical position VPOS. */
3176 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3182 /* Scroll part of the display as described by RUN. */
3185 x_scroll_run (struct window
*w
, struct run
*run
)
3187 struct frame
*f
= XFRAME (w
->frame
);
3188 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3190 /* Get frame-relative bounding box of the text display area of W,
3191 without mode lines. Include in this box the left and right
3193 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
3195 #ifdef USE_TOOLKIT_SCROLL_BARS
3196 /* If the fringe is adjacent to the left (right) scroll bar of a
3197 leftmost (rightmost, respectively) window, then extend its
3198 background to the gap between the fringe and the bar. */
3199 if ((WINDOW_LEFTMOST_P (w
)
3200 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
3201 || (WINDOW_RIGHTMOST_P (w
)
3202 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
3204 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3208 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
3209 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
3210 * FRAME_COLUMN_WIDTH (f
));
3212 if (bar_area_x
+ bar_area_width
== x
)
3214 x
= bar_area_x
+ sb_width
;
3215 width
+= bar_area_width
- sb_width
;
3217 else if (x
+ width
== bar_area_x
)
3218 width
+= bar_area_width
- sb_width
;
3223 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3224 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3225 bottom_y
= y
+ height
;
3229 /* Scrolling up. Make sure we don't copy part of the mode
3230 line at the bottom. */
3231 if (from_y
+ run
->height
> bottom_y
)
3232 height
= bottom_y
- from_y
;
3234 height
= run
->height
;
3238 /* Scrolling down. Make sure we don't copy over the mode line.
3240 if (to_y
+ run
->height
> bottom_y
)
3241 height
= bottom_y
- to_y
;
3243 height
= run
->height
;
3248 /* Cursor off. Will be switched on again in x_update_window_end. */
3251 XCopyArea (FRAME_X_DISPLAY (f
),
3252 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3253 f
->output_data
.x
->normal_gc
,
3263 /***********************************************************************
3265 ***********************************************************************/
3269 frame_highlight (struct frame
*f
)
3271 /* We used to only do this if Vx_no_window_manager was non-nil, but
3272 the ICCCM (section 4.1.6) says that the window's border pixmap
3273 and border pixel are window attributes which are "private to the
3274 client", so we can always change it to whatever we want. */
3276 /* I recently started to get errors in this XSetWindowBorder, depending on
3277 the window-manager in use, tho something more is at play since I've been
3278 using that same window-manager binary for ever. Let's not crash just
3279 because of this (bug#9310). */
3280 x_catch_errors (FRAME_X_DISPLAY (f
));
3281 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3282 f
->output_data
.x
->border_pixel
);
3283 x_uncatch_errors ();
3285 x_update_cursor (f
, 1);
3286 x_set_frame_alpha (f
);
3290 frame_unhighlight (struct frame
*f
)
3292 /* We used to only do this if Vx_no_window_manager was non-nil, but
3293 the ICCCM (section 4.1.6) says that the window's border pixmap
3294 and border pixel are window attributes which are "private to the
3295 client", so we can always change it to whatever we want. */
3297 /* Same as above for XSetWindowBorder (bug#9310). */
3298 x_catch_errors (FRAME_X_DISPLAY (f
));
3299 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3300 f
->output_data
.x
->border_tile
);
3301 x_uncatch_errors ();
3303 x_update_cursor (f
, 1);
3304 x_set_frame_alpha (f
);
3307 /* The focus has changed. Update the frames as necessary to reflect
3308 the new situation. Note that we can't change the selected frame
3309 here, because the Lisp code we are interrupting might become confused.
3310 Each event gets marked with the frame in which it occurred, so the
3311 Lisp code can tell when the switch took place by examining the events. */
3314 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3316 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3318 if (frame
!= dpyinfo
->x_focus_frame
)
3320 /* Set this before calling other routines, so that they see
3321 the correct value of x_focus_frame. */
3322 dpyinfo
->x_focus_frame
= frame
;
3324 if (old_focus
&& old_focus
->auto_lower
)
3325 x_lower_frame (old_focus
);
3327 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3328 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3330 pending_autoraise_frame
= 0;
3333 x_frame_rehighlight (dpyinfo
);
3336 /* Handle FocusIn and FocusOut state changes for FRAME.
3337 If FRAME has focus and there exists more than one frame, puts
3338 a FOCUS_IN_EVENT into *BUFP. */
3341 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3343 if (type
== FocusIn
)
3345 if (dpyinfo
->x_focus_event_frame
!= frame
)
3347 x_new_focus_frame (dpyinfo
, frame
);
3348 dpyinfo
->x_focus_event_frame
= frame
;
3350 /* Don't stop displaying the initial startup message
3351 for a switch-frame event we don't need. */
3352 /* When run as a daemon, Vterminal_frame is always NIL. */
3353 bufp
->arg
= (((NILP (Vterminal_frame
) || EQ (Fdaemonp (), Qt
))
3354 && CONSP (Vframe_list
)
3355 && !NILP (XCDR (Vframe_list
)))
3357 bufp
->kind
= FOCUS_IN_EVENT
;
3358 XSETFRAME (bufp
->frame_or_window
, frame
);
3361 frame
->output_data
.x
->focus_state
|= state
;
3364 if (FRAME_XIC (frame
))
3365 XSetICFocus (FRAME_XIC (frame
));
3368 else if (type
== FocusOut
)
3370 frame
->output_data
.x
->focus_state
&= ~state
;
3372 if (dpyinfo
->x_focus_event_frame
== frame
)
3374 dpyinfo
->x_focus_event_frame
= 0;
3375 x_new_focus_frame (dpyinfo
, 0);
3377 bufp
->kind
= FOCUS_OUT_EVENT
;
3378 XSETFRAME (bufp
->frame_or_window
, frame
);
3382 if (FRAME_XIC (frame
))
3383 XUnsetICFocus (FRAME_XIC (frame
));
3385 if (frame
->pointer_invisible
)
3386 XTtoggle_invisible_pointer (frame
, 0);
3390 /* Return the Emacs frame-object corresponding to an X window.
3391 It could be the frame's main window or an icon window. */
3393 static struct frame
*
3394 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3396 Lisp_Object tail
, frame
;
3402 FOR_EACH_FRAME (tail
, frame
)
3405 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3407 if (f
->output_data
.x
->hourglass_window
== wdesc
)
3409 #ifdef USE_X_TOOLKIT
3410 if ((f
->output_data
.x
->edit_widget
3411 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
3412 /* A tooltip frame? */
3413 || (!f
->output_data
.x
->edit_widget
3414 && FRAME_X_WINDOW (f
) == wdesc
)
3415 || f
->output_data
.x
->icon_desc
== wdesc
)
3417 #else /* not USE_X_TOOLKIT */
3419 if (f
->output_data
.x
->edit_widget
)
3421 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3422 struct x_output
*x
= f
->output_data
.x
;
3423 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
3426 #endif /* USE_GTK */
3427 if (FRAME_X_WINDOW (f
) == wdesc
3428 || f
->output_data
.x
->icon_desc
== wdesc
)
3430 #endif /* not USE_X_TOOLKIT */
3435 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3437 /* Like x_window_to_frame but also compares the window with the widget's
3440 static struct frame
*
3441 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3443 Lisp_Object tail
, frame
;
3444 struct frame
*f
, *found
= NULL
;
3450 FOR_EACH_FRAME (tail
, frame
)
3455 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
3457 /* This frame matches if the window is any of its widgets. */
3458 x
= f
->output_data
.x
;
3459 if (x
->hourglass_window
== wdesc
)
3464 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3466 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
3469 if (wdesc
== XtWindow (x
->widget
)
3470 || wdesc
== XtWindow (x
->column_widget
)
3471 || wdesc
== XtWindow (x
->edit_widget
))
3473 /* Match if the window is this frame's menubar. */
3474 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3478 else if (FRAME_X_WINDOW (f
) == wdesc
)
3479 /* A tooltip frame. */
3487 /* Likewise, but consider only the menu bar widget. */
3489 static struct frame
*
3490 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
, XEvent
*event
)
3492 Window wdesc
= event
->xany
.window
;
3493 Lisp_Object tail
, frame
;
3500 FOR_EACH_FRAME (tail
, frame
)
3503 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3505 x
= f
->output_data
.x
;
3507 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
3510 /* Match if the window is this frame's menubar. */
3511 if (x
->menubar_widget
3512 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3519 /* Return the frame whose principal (outermost) window is WDESC.
3520 If WDESC is some other (smaller) window, we return 0. */
3523 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3525 Lisp_Object tail
, frame
;
3532 FOR_EACH_FRAME (tail
, frame
)
3535 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3537 x
= f
->output_data
.x
;
3541 /* This frame matches if the window is its topmost widget. */
3543 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3544 if (gwdesc
== x
->widget
)
3547 if (wdesc
== XtWindow (x
->widget
))
3551 else if (FRAME_X_WINDOW (f
) == wdesc
)
3552 /* Tooltip frame. */
3558 #else /* !USE_X_TOOLKIT && !USE_GTK */
3560 #define x_any_window_to_frame(d, i) x_window_to_frame (d, i)
3561 #define x_top_window_to_frame(d, i) x_window_to_frame (d, i)
3563 #endif /* USE_X_TOOLKIT || USE_GTK */
3565 /* The focus may have changed. Figure out if it is a real focus change,
3566 by checking both FocusIn/Out and Enter/LeaveNotify events.
3568 Returns FOCUS_IN_EVENT event in *BUFP. */
3571 x_detect_focus_change (struct x_display_info
*dpyinfo
, XEvent
*event
, struct input_event
*bufp
)
3573 struct frame
*frame
;
3575 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3579 switch (event
->type
)
3584 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3586 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3588 if (event
->xcrossing
.detail
!= NotifyInferior
3589 && event
->xcrossing
.focus
3590 && ! (focus_state
& FOCUS_EXPLICIT
))
3591 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3593 dpyinfo
, frame
, bufp
);
3599 x_focus_changed (event
->type
,
3600 (event
->xfocus
.detail
== NotifyPointer
?
3601 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3602 dpyinfo
, frame
, bufp
);
3606 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3608 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3609 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3610 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3617 #if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
3618 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3621 x_mouse_leave (struct x_display_info
*dpyinfo
)
3623 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3627 /* The focus has changed, or we have redirected a frame's focus to
3628 another frame (this happens when a frame uses a surrogate
3629 mini-buffer frame). Shift the highlight as appropriate.
3631 The FRAME argument doesn't necessarily have anything to do with which
3632 frame is being highlighted or un-highlighted; we only use it to find
3633 the appropriate X display info. */
3636 XTframe_rehighlight (struct frame
*frame
)
3638 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
3642 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3644 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3646 if (dpyinfo
->x_focus_frame
)
3648 dpyinfo
->x_highlight_frame
3649 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3650 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3651 : dpyinfo
->x_focus_frame
);
3652 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3654 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
3655 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3659 dpyinfo
->x_highlight_frame
= 0;
3661 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3664 frame_unhighlight (old_highlight
);
3665 if (dpyinfo
->x_highlight_frame
)
3666 frame_highlight (dpyinfo
->x_highlight_frame
);
3672 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3674 /* Initialize mode_switch_bit and modifier_meaning. */
3676 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3678 int min_code
, max_code
;
3681 XModifierKeymap
*mods
;
3683 dpyinfo
->meta_mod_mask
= 0;
3684 dpyinfo
->shift_lock_mask
= 0;
3685 dpyinfo
->alt_mod_mask
= 0;
3686 dpyinfo
->super_mod_mask
= 0;
3687 dpyinfo
->hyper_mod_mask
= 0;
3689 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3691 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3692 min_code
, max_code
- min_code
+ 1,
3694 mods
= XGetModifierMapping (dpyinfo
->display
);
3696 /* Scan the modifier table to see which modifier bits the Meta and
3697 Alt keysyms are on. */
3699 int row
, col
; /* The row and column in the modifier table. */
3700 int found_alt_or_meta
;
3702 for (row
= 3; row
< 8; row
++)
3704 found_alt_or_meta
= 0;
3705 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3707 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3709 /* Zeroes are used for filler. Skip them. */
3713 /* Are any of this keycode's keysyms a meta key? */
3717 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3719 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3725 found_alt_or_meta
= 1;
3726 dpyinfo
->meta_mod_mask
|= (1 << row
);
3731 found_alt_or_meta
= 1;
3732 dpyinfo
->alt_mod_mask
|= (1 << row
);
3737 if (!found_alt_or_meta
)
3738 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3739 code_col
= syms_per_code
;
3740 col
= mods
->max_keypermod
;
3745 if (!found_alt_or_meta
)
3746 dpyinfo
->super_mod_mask
|= (1 << row
);
3747 code_col
= syms_per_code
;
3748 col
= mods
->max_keypermod
;
3752 /* Ignore this if it's not on the lock modifier. */
3753 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3754 dpyinfo
->shift_lock_mask
= LockMask
;
3755 code_col
= syms_per_code
;
3756 col
= mods
->max_keypermod
;
3765 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3766 if (! dpyinfo
->meta_mod_mask
)
3768 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3769 dpyinfo
->alt_mod_mask
= 0;
3772 /* If some keys are both alt and meta,
3773 make them just meta, not alt. */
3774 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3776 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3780 XFreeModifiermap (mods
);
3783 /* Convert between the modifier bits X uses and the modifier bits
3787 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
3789 int mod_meta
= meta_modifier
;
3790 int mod_alt
= alt_modifier
;
3791 int mod_hyper
= hyper_modifier
;
3792 int mod_super
= super_modifier
;
3795 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3796 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
3797 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3798 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
3799 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3800 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
3801 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3802 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
3804 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3805 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3806 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3807 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3808 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3809 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3813 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
3815 EMACS_INT mod_meta
= meta_modifier
;
3816 EMACS_INT mod_alt
= alt_modifier
;
3817 EMACS_INT mod_hyper
= hyper_modifier
;
3818 EMACS_INT mod_super
= super_modifier
;
3822 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3823 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
3824 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3825 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
3826 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3827 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
3828 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3829 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
3832 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3833 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3834 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3835 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3836 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3837 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3840 /* Convert a keysym to its name. */
3843 x_get_keysym_name (int keysym
)
3848 value
= XKeysymToString (keysym
);
3856 /* Mouse clicks and mouse movement. Rah. */
3858 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3860 If the event is a button press, then note that we have grabbed
3864 construct_mouse_click (struct input_event
*result
, XButtonEvent
*event
, struct frame
*f
)
3866 /* Make the event type NO_EVENT; we'll change that when we decide
3868 result
->kind
= MOUSE_CLICK_EVENT
;
3869 result
->code
= event
->button
- Button1
;
3870 result
->timestamp
= event
->time
;
3871 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
),
3873 | (event
->type
== ButtonRelease
3877 XSETINT (result
->x
, event
->x
);
3878 XSETINT (result
->y
, event
->y
);
3879 XSETFRAME (result
->frame_or_window
, f
);
3884 /* Function to report a mouse movement to the mainstream Emacs code.
3885 The input handler calls this.
3887 We have received a mouse movement event, which is given in *event.
3888 If the mouse is over a different glyph than it was last time, tell
3889 the mainstream emacs code by setting mouse_moved. If not, ask for
3890 another motion event, so we can check again the next time it moves. */
3892 static XMotionEvent last_mouse_motion_event
;
3893 static Lisp_Object last_mouse_motion_frame
;
3896 note_mouse_movement (struct frame
*frame
, XMotionEvent
*event
)
3898 last_mouse_movement_time
= event
->time
;
3899 last_mouse_motion_event
= *event
;
3900 XSETFRAME (last_mouse_motion_frame
, frame
);
3902 if (!FRAME_X_OUTPUT (frame
))
3905 if (event
->window
!= FRAME_X_WINDOW (frame
))
3907 frame
->mouse_moved
= 1;
3908 last_mouse_scroll_bar
= Qnil
;
3909 note_mouse_highlight (frame
, -1, -1);
3910 last_mouse_glyph_frame
= 0;
3915 /* Has the mouse moved off the glyph it was on at the last sighting? */
3916 if (frame
!= last_mouse_glyph_frame
3917 || event
->x
< last_mouse_glyph
.x
3918 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3919 || event
->y
< last_mouse_glyph
.y
3920 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3922 frame
->mouse_moved
= 1;
3923 last_mouse_scroll_bar
= Qnil
;
3924 note_mouse_highlight (frame
, event
->x
, event
->y
);
3925 /* Remember which glyph we're now on. */
3926 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3927 last_mouse_glyph_frame
= frame
;
3935 /************************************************************************
3937 ************************************************************************/
3940 redo_mouse_highlight (void)
3942 if (!NILP (last_mouse_motion_frame
)
3943 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3944 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3945 last_mouse_motion_event
.x
,
3946 last_mouse_motion_event
.y
);
3951 /* Return the current position of the mouse.
3952 *FP should be a frame which indicates which display to ask about.
3954 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3955 and *PART to the frame, window, and scroll bar part that the mouse
3956 is over. Set *X and *Y to the portion and whole of the mouse's
3957 position on the scroll bar.
3959 If the mouse movement started elsewhere, set *FP to the frame the
3960 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3963 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
3964 was at this position.
3966 Don't store anything if we don't have a valid set of values to report.
3968 This clears the mouse_moved flag, so we can wait for the next mouse
3972 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3973 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3980 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3981 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
3987 Window dummy_window
;
3990 Lisp_Object frame
, tail
;
3992 /* Clear the mouse-moved flag for every frame on this display. */
3993 FOR_EACH_FRAME (tail
, frame
)
3994 if (FRAME_X_P (XFRAME (frame
))
3995 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3996 XFRAME (frame
)->mouse_moved
= 0;
3998 last_mouse_scroll_bar
= Qnil
;
4000 /* Figure out which root window we're on. */
4001 XQueryPointer (FRAME_X_DISPLAY (*fp
),
4002 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
4004 /* The root window which contains the pointer. */
4007 /* Trash which we can't trust if the pointer is on
4008 a different screen. */
4011 /* The position on that root window. */
4014 /* More trash we can't trust. */
4017 /* Modifier keys and pointer buttons, about which
4019 (unsigned int *) &dummy
);
4021 /* Now we have a position on the root; find the innermost window
4022 containing the pointer. */
4026 int parent_x
= 0, parent_y
= 0;
4030 /* XTranslateCoordinates can get errors if the window
4031 structure is changing at the same time this function
4032 is running. So at least we must not crash from them. */
4034 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4036 if (FRAME_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4037 && FRAME_LIVE_P (last_mouse_frame
))
4039 /* If mouse was grabbed on a frame, give coords for that frame
4040 even if the mouse is now outside it. */
4041 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4043 /* From-window, to-window. */
4044 root
, FRAME_X_WINDOW (last_mouse_frame
),
4046 /* From-position, to-position. */
4047 root_x
, root_y
, &win_x
, &win_y
,
4051 f1
= last_mouse_frame
;
4057 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4059 /* From-window, to-window. */
4062 /* From-position, to-position. */
4063 root_x
, root_y
, &win_x
, &win_y
,
4068 if (child
== None
|| child
== win
)
4071 /* We don't wan't to know the innermost window. We
4072 want the edit window. For non-Gtk+ the innermost
4073 window is the edit window. For Gtk+ it might not
4074 be. It might be the tool bar for example. */
4075 if (x_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
))
4083 /* Now we know that:
4084 win is the innermost window containing the pointer
4085 (XTC says it has no child containing the pointer),
4086 win_x and win_y are the pointer's position in it
4087 (XTC did this the last time through), and
4088 parent_x and parent_y are the pointer's position in win's parent.
4089 (They are what win_x and win_y were when win was child.
4090 If win is the root window, it has no parent, and
4091 parent_{x,y} are invalid, but that's okay, because we'll
4092 never use them in that case.) */
4095 /* We don't wan't to know the innermost window. We
4096 want the edit window. */
4097 f1
= x_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
);
4099 /* Is win one of our frames? */
4100 f1
= x_any_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
);
4103 #ifdef USE_X_TOOLKIT
4104 /* If we end up with the menu bar window, say it's not
4107 && f1
->output_data
.x
->menubar_widget
4108 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4110 #endif /* USE_X_TOOLKIT */
4113 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4116 x_uncatch_errors ();
4118 /* If not, is it one of our scroll bars? */
4121 struct scroll_bar
*bar
;
4123 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4127 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4133 if (f1
== 0 && insist
> 0)
4134 f1
= SELECTED_FRAME ();
4138 /* Ok, we found a frame. Store all the values.
4139 last_mouse_glyph is a rectangle used to reduce the
4140 generation of mouse events. To not miss any motion
4141 events, we must divide the frame into rectangles of the
4142 size of the smallest character that could be displayed
4143 on it, i.e. into the same rectangles that matrices on
4144 the frame are divided into. */
4146 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
4147 last_mouse_glyph_frame
= f1
;
4152 XSETINT (*x
, win_x
);
4153 XSETINT (*y
, win_y
);
4154 *timestamp
= last_mouse_movement_time
;
4164 /***********************************************************************
4166 ***********************************************************************/
4168 /* Scroll bar support. */
4170 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4172 This can be called in GC, so we have to make sure to strip off mark
4175 static struct scroll_bar
*
4176 x_window_to_scroll_bar (Display
*display
, Window window_id
)
4178 Lisp_Object tail
, frame
;
4180 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4181 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4182 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4184 FOR_EACH_FRAME (tail
, frame
)
4186 Lisp_Object bar
, condemned
;
4188 if (! FRAME_X_P (XFRAME (frame
)))
4191 /* Scan this frame's scroll bar list for a scroll bar with the
4193 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4194 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4195 /* This trick allows us to search both the ordinary and
4196 condemned scroll bar lists with one loop. */
4197 ! NILP (bar
) || (bar
= condemned
,
4200 bar
= XSCROLL_BAR (bar
)->next
)
4201 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4202 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4203 return XSCROLL_BAR (bar
);
4210 #if defined USE_LUCID
4212 /* Return the Lucid menu bar WINDOW is part of. Return null
4213 if WINDOW is not part of a menu bar. */
4216 x_window_to_menu_bar (Window window
)
4218 Lisp_Object tail
, frame
;
4220 FOR_EACH_FRAME (tail
, frame
)
4221 if (FRAME_X_P (XFRAME (frame
)))
4223 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4225 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4231 #endif /* USE_LUCID */
4234 /************************************************************************
4236 ************************************************************************/
4238 #ifdef USE_TOOLKIT_SCROLL_BARS
4240 static void x_scroll_bar_to_input_event (XEvent
*, struct input_event
*);
4241 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
4242 static void x_create_toolkit_scroll_bar (struct frame
*,
4243 struct scroll_bar
*);
4244 static void x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*,
4248 /* Lisp window being scrolled. Set when starting to interact with
4249 a toolkit scroll bar, reset to nil when ending the interaction. */
4251 static Lisp_Object window_being_scrolled
;
4253 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4254 that movements of 1/20 of the screen size are mapped to up/down. */
4257 /* Id of action hook installed for scroll bars. */
4259 static XtActionHookId action_hook_id
;
4261 static Boolean xaw3d_arrow_scroll
;
4263 /* Whether the drag scrolling maintains the mouse at the top of the
4264 thumb. If not, resizing the thumb needs to be done more carefully
4265 to avoid jerkiness. */
4267 static Boolean xaw3d_pick_top
;
4269 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4270 bars are used.. The hook is responsible for detecting when
4271 the user ends an interaction with the scroll bar, and generates
4272 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4275 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4276 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4279 const char *end_action
;
4282 scroll_bar_p
= XmIsScrollBar (widget
);
4283 end_action
= "Release";
4284 #else /* !USE_MOTIF i.e. use Xaw */
4285 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4286 end_action
= "EndScroll";
4287 #endif /* USE_MOTIF */
4290 && strcmp (action_name
, end_action
) == 0
4291 && WINDOWP (window_being_scrolled
))
4294 struct scroll_bar
*bar
;
4296 x_send_scroll_bar_event (window_being_scrolled
,
4297 scroll_bar_end_scroll
, 0, 0);
4298 w
= XWINDOW (window_being_scrolled
);
4299 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4301 if (bar
->dragging
!= -1)
4304 /* The thumb size is incorrect while dragging: fix it. */
4305 set_vertical_scroll_bar (w
);
4307 window_being_scrolled
= Qnil
;
4308 #if defined (USE_LUCID)
4309 bar
->last_seen_part
= scroll_bar_nowhere
;
4311 /* Xt timeouts no longer needed. */
4312 toolkit_scroll_bar_interaction
= 0;
4315 #endif /* not USE_GTK */
4317 /* A vector of windows used for communication between
4318 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4320 static struct window
**scroll_bar_windows
;
4321 static ptrdiff_t scroll_bar_windows_size
;
4324 /* Send a client message with message type Xatom_Scrollbar for a
4325 scroll action to the frame of WINDOW. PART is a value identifying
4326 the part of the scroll bar that was clicked on. PORTION is the
4327 amount to scroll of a whole of WHOLE. */
4330 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4333 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4334 struct window
*w
= XWINDOW (window
);
4335 struct frame
*f
= XFRAME (w
->frame
);
4340 /* Construct a ClientMessage event to send to the frame. */
4341 ev
->type
= ClientMessage
;
4342 ev
->message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4343 ev
->display
= FRAME_X_DISPLAY (f
);
4344 ev
->window
= FRAME_X_WINDOW (f
);
4347 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4348 not enough to store a pointer or Lisp_Object on a 64 bit system.
4349 So, store the window in scroll_bar_windows and pass the index
4350 into that array in the event. */
4351 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4352 if (scroll_bar_windows
[i
] == NULL
)
4355 if (i
== scroll_bar_windows_size
)
4357 ptrdiff_t old_nbytes
=
4358 scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4360 enum { XClientMessageEvent_MAX
= 0x7fffffff };
4361 scroll_bar_windows
=
4362 xpalloc (scroll_bar_windows
, &scroll_bar_windows_size
, 1,
4363 XClientMessageEvent_MAX
, sizeof *scroll_bar_windows
);
4364 nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4365 memset (&scroll_bar_windows
[i
], 0, nbytes
- old_nbytes
);
4368 scroll_bar_windows
[i
] = w
;
4369 ev
->data
.l
[0] = (long) i
;
4370 ev
->data
.l
[1] = (long) part
;
4371 ev
->data
.l
[2] = (long) 0;
4372 ev
->data
.l
[3] = (long) portion
;
4373 ev
->data
.l
[4] = (long) whole
;
4375 /* Make Xt timeouts work while the scroll bar is active. */
4376 #ifdef USE_X_TOOLKIT
4377 toolkit_scroll_bar_interaction
= 1;
4378 x_activate_timeout_atimer ();
4381 /* Setting the event mask to zero means that the message will
4382 be sent to the client that created the window, and if that
4383 window no longer exists, no event will be sent. */
4384 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4389 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4393 x_scroll_bar_to_input_event (XEvent
*event
, struct input_event
*ievent
)
4395 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4399 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4400 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4402 XSETWINDOW (window
, w
);
4404 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4405 ievent
->frame_or_window
= window
;
4408 ievent
->timestamp
= CurrentTime
;
4411 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4413 ievent
->part
= ev
->data
.l
[1];
4414 ievent
->code
= ev
->data
.l
[2];
4415 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4416 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4417 ievent
->modifiers
= 0;
4423 /* Minimum and maximum values used for Motif scroll bars. */
4425 #define XM_SB_MAX 10000000
4428 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4429 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4430 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4433 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4435 struct scroll_bar
*bar
= client_data
;
4436 XmScrollBarCallbackStruct
*cs
= call_data
;
4437 int part
= -1, whole
= 0, portion
= 0;
4441 case XmCR_DECREMENT
:
4443 part
= scroll_bar_up_arrow
;
4446 case XmCR_INCREMENT
:
4448 part
= scroll_bar_down_arrow
;
4451 case XmCR_PAGE_DECREMENT
:
4453 part
= scroll_bar_above_handle
;
4456 case XmCR_PAGE_INCREMENT
:
4458 part
= scroll_bar_below_handle
;
4463 part
= scroll_bar_to_top
;
4466 case XmCR_TO_BOTTOM
:
4468 part
= scroll_bar_to_bottom
;
4475 /* Get the slider size. */
4477 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4480 whole
= XM_SB_MAX
- slider_size
;
4481 portion
= min (cs
->value
, whole
);
4482 part
= scroll_bar_handle
;
4483 bar
->dragging
= cs
->value
;
4487 case XmCR_VALUE_CHANGED
:
4493 window_being_scrolled
= bar
->window
;
4494 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4498 #elif defined USE_GTK
4500 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4501 bar widget. DATA is a pointer to the scroll_bar structure. */
4504 xg_scroll_callback (GtkRange
*range
,
4505 GtkScrollType scroll
,
4509 struct scroll_bar
*bar
= user_data
;
4511 int part
= -1, whole
= 0, portion
= 0;
4512 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4513 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4515 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4516 position
= gtk_adjustment_get_value (adj
);
4521 case GTK_SCROLL_JUMP
:
4522 /* Buttons 1 2 or 3 must be grabbed. */
4523 if (FRAME_DISPLAY_INFO (f
)->grabbed
!= 0
4524 && FRAME_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4526 part
= scroll_bar_handle
;
4527 whole
= gtk_adjustment_get_upper (adj
) -
4528 gtk_adjustment_get_page_size (adj
);
4529 portion
= min ((int)position
, whole
);
4530 bar
->dragging
= portion
;
4533 case GTK_SCROLL_STEP_BACKWARD
:
4534 part
= scroll_bar_up_arrow
;
4537 case GTK_SCROLL_STEP_FORWARD
:
4538 part
= scroll_bar_down_arrow
;
4541 case GTK_SCROLL_PAGE_BACKWARD
:
4542 part
= scroll_bar_above_handle
;
4545 case GTK_SCROLL_PAGE_FORWARD
:
4546 part
= scroll_bar_below_handle
;
4553 window_being_scrolled
= bar
->window
;
4554 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4560 /* Callback for button release. Sets dragging to -1 when dragging is done. */
4563 xg_end_scroll_callback (GtkWidget
*widget
,
4564 GdkEventButton
*event
,
4567 struct scroll_bar
*bar
= user_data
;
4569 if (WINDOWP (window_being_scrolled
))
4571 x_send_scroll_bar_event (window_being_scrolled
,
4572 scroll_bar_end_scroll
, 0, 0);
4573 window_being_scrolled
= Qnil
;
4580 #else /* not USE_GTK and not USE_MOTIF */
4582 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4583 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4584 scroll bar struct. CALL_DATA is a pointer to a float saying where
4588 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4590 struct scroll_bar
*bar
= client_data
;
4591 float *top_addr
= call_data
;
4592 float top
= *top_addr
;
4594 int whole
, portion
, height
;
4595 enum scroll_bar_part part
;
4597 /* Get the size of the thumb, a value between 0 and 1. */
4599 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4603 portion
= shown
< 1 ? top
* whole
: 0;
4605 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
4606 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4607 the bottom, so we force the scrolling whenever we see that we're
4608 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4609 we try to ensure that we always stay two pixels away from the
4611 part
= scroll_bar_down_arrow
;
4613 part
= scroll_bar_handle
;
4615 window_being_scrolled
= bar
->window
;
4616 bar
->dragging
= portion
;
4617 bar
->last_seen_part
= part
;
4618 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4622 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4623 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4624 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4625 the scroll bar. CALL_DATA is an integer specifying the action that
4626 has taken place. Its magnitude is in the range 0..height of the
4627 scroll bar. Negative values mean scroll towards buffer start.
4628 Values < height of scroll bar mean line-wise movement. */
4631 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4633 struct scroll_bar
*bar
= client_data
;
4634 /* The position really is stored cast to a pointer. */
4635 int position
= (intptr_t) call_data
;
4637 enum scroll_bar_part part
;
4639 /* Get the height of the scroll bar. */
4641 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4644 if (eabs (position
) >= height
)
4645 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4647 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4648 it maps line-movement to call_data = max(5, height/20). */
4649 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4650 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4652 part
= scroll_bar_move_ratio
;
4654 window_being_scrolled
= bar
->window
;
4656 bar
->last_seen_part
= part
;
4657 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4660 #endif /* not USE_GTK and not USE_MOTIF */
4662 #define SCROLL_BAR_NAME "verticalScrollBar"
4664 /* Create the widget for scroll bar BAR on frame F. Record the widget
4665 and X window of the scroll bar in BAR. */
4669 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4671 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4674 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4675 G_CALLBACK (xg_end_scroll_callback
),
4680 #else /* not USE_GTK */
4683 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4689 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4690 unsigned long pixel
;
4695 /* Set resources. Create the widget. */
4696 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4697 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4698 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4699 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4700 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4701 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4702 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4704 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4707 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4711 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4714 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4718 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4719 (char *) scroll_bar_name
, av
, ac
);
4721 /* Add one callback for everything that can happen. */
4722 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4724 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4726 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4728 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4730 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4732 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4734 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4737 /* Realize the widget. Only after that is the X window created. */
4738 XtRealizeWidget (widget
);
4740 /* Set the cursor to an arrow. I didn't find a resource to do that.
4741 And I'm wondering why it hasn't an arrow cursor by default. */
4742 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4743 f
->output_data
.x
->nontext_cursor
);
4745 #else /* !USE_MOTIF i.e. use Xaw */
4747 /* Set resources. Create the widget. The background of the
4748 Xaw3d scroll bar widget is a little bit light for my taste.
4749 We don't alter it here to let users change it according
4750 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4751 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4752 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4753 /* For smoother scrolling with Xaw3d -sm */
4754 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4756 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4759 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4763 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4766 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4770 /* Top/bottom shadow colors. */
4772 /* Allocate them, if necessary. */
4773 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4775 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4778 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4779 FRAME_X_COLORMAP (f
),
4780 &pixel
, 1.2, 0x8000))
4782 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4785 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4787 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4790 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4791 FRAME_X_COLORMAP (f
),
4792 &pixel
, 0.6, 0x4000))
4794 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4798 #ifdef XtNbeNiceToColormap
4799 /* Tell the toolkit about them. */
4800 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4801 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4802 /* We tried to allocate a color for the top/bottom shadow, and
4803 failed, so tell Xaw3d to use dithering instead. */
4804 /* But only if we have a small colormap. Xaw3d can allocate nice
4807 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4808 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4812 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4813 be more consistent with other emacs 3d colors, and since Xaw3d is
4814 not good at dealing with allocation failure. */
4816 /* This tells Xaw3d to use real colors instead of dithering for
4818 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4821 /* Specify the colors. */
4822 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4825 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4828 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4831 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4837 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4838 f
->output_data
.x
->edit_widget
, av
, ac
);
4841 char const *initial
= "";
4842 char const *val
= initial
;
4843 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4844 #ifdef XtNarrowScrollbars
4845 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4847 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4848 if (xaw3d_arrow_scroll
|| val
== initial
)
4849 { /* ARROW_SCROLL */
4850 xaw3d_arrow_scroll
= True
;
4851 /* Isn't that just a personal preference ? --Stef */
4852 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4856 /* Define callbacks. */
4857 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4858 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4861 /* Realize the widget. Only after that is the X window created. */
4862 XtRealizeWidget (widget
);
4864 #endif /* !USE_MOTIF */
4866 /* Install an action hook that lets us detect when the user
4867 finishes interacting with a scroll bar. */
4868 if (action_hook_id
== 0)
4869 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4871 /* Remember X window and widget in the scroll bar vector. */
4872 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4873 xwindow
= XtWindow (widget
);
4874 bar
->x_window
= xwindow
;
4878 #endif /* not USE_GTK */
4881 /* Set the thumb size and position of scroll bar BAR. We are currently
4882 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4886 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4888 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4891 #else /* not USE_GTK */
4893 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4896 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4897 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4904 if (scroll_bar_adjust_thumb_portion_p
)
4906 /* We use an estimate of 30 chars per line rather than the real
4907 `portion' value. This has the disadvantage that the thumb size
4908 is not very representative, but it makes our life a lot easier.
4909 Otherwise, we have to constantly adjust the thumb size, which
4910 we can't always do quickly enough: while dragging, the size of
4911 the thumb might prevent the user from dragging the thumb all the
4912 way to the end. but Motif and some versions of Xaw3d don't allow
4913 updating the thumb size while dragging. Also, even if we can update
4914 its size, the update will often happen too late.
4915 If you don't believe it, check out revision 1.650 of xterm.c to see
4916 what hoops we were going through and the still poor behavior we got. */
4917 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4918 /* When the thumb is at the bottom, position == whole.
4919 So we need to increase `whole' to make space for the thumb. */
4927 top
= (float) position
/ whole
;
4928 shown
= (float) portion
/ whole
;
4931 if (bar
->dragging
== -1)
4935 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4936 is the scroll bar's maximum and MIN is the scroll bar's minimum
4938 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
4940 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4941 value
= top
* XM_SB_MAX
;
4942 value
= min (value
, XM_SB_MAX
- size
);
4944 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4946 #else /* !USE_MOTIF i.e. use Xaw */
4952 top
= (float) position
/ whole
;
4953 shown
= (float) portion
/ whole
;
4957 float old_top
, old_shown
;
4959 XtVaGetValues (widget
,
4960 XtNtopOfThumb
, &old_top
,
4961 XtNshown
, &old_shown
,
4965 /* Massage the top+shown values. */
4966 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
4967 top
= max (0, min (1, top
));
4970 #if ! defined (HAVE_XAW3D)
4971 /* With Xaw, 'top' values too closer to 1.0 may
4972 cause the thumb to disappear. Fix that. */
4973 top
= min (top
, 0.99f
);
4975 /* Keep two pixels available for moving the thumb down. */
4976 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
4977 #if ! defined (HAVE_XAW3D)
4978 /* Likewise with too small 'shown'. */
4979 shown
= max (shown
, 0.01f
);
4982 /* If the call to XawScrollbarSetThumb below doesn't seem to
4983 work, check that 'NARROWPROTO' is defined in src/config.h.
4984 If this is not so, most likely you need to fix configure. */
4985 if (top
!= old_top
|| shown
!= old_shown
)
4987 if (bar
->dragging
== -1)
4988 XawScrollbarSetThumb (widget
, top
, shown
);
4991 /* Try to make the scrolling a tad smoother. */
4992 if (!xaw3d_pick_top
)
4993 shown
= min (shown
, old_shown
);
4995 XawScrollbarSetThumb (widget
, top
, shown
);
4999 #endif /* !USE_MOTIF */
5003 #endif /* not USE_GTK */
5005 #endif /* USE_TOOLKIT_SCROLL_BARS */
5009 /************************************************************************
5010 Scroll bars, general
5011 ************************************************************************/
5013 /* Create a scroll bar and return the scroll bar vector for it. W is
5014 the Emacs window on which to create the scroll bar. TOP, LEFT,
5015 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
5018 static struct scroll_bar
*
5019 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
5021 struct frame
*f
= XFRAME (w
->frame
);
5022 struct scroll_bar
*bar
5023 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
5028 #ifdef USE_TOOLKIT_SCROLL_BARS
5029 x_create_toolkit_scroll_bar (f
, bar
);
5030 #else /* not USE_TOOLKIT_SCROLL_BARS */
5032 XSetWindowAttributes a
;
5036 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5037 if (a
.background_pixel
== -1)
5038 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5040 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
5041 | ButtonMotionMask
| PointerMotionHintMask
5043 a
.cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
5045 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
5047 /* Clear the area of W that will serve as a scroll bar. This is
5048 for the case that a window has been split horizontally. In
5049 this case, no clear_frame is generated to reduce flickering. */
5050 if (width
> 0 && height
> 0)
5051 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5052 left
, top
, width
, window_box_height (w
));
5054 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5055 /* Position and size of scroll bar. */
5056 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5058 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5060 /* Border width, depth, class, and visual. */
5067 bar
->x_window
= window
;
5069 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5071 XSETWINDOW (bar
->window
, w
);
5075 bar
->height
= height
;
5079 bar
->fringe_extended_p
= 0;
5080 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
5081 bar
->last_seen_part
= scroll_bar_nowhere
;
5084 /* Add bar to its frame's list of scroll bars. */
5085 bar
->next
= FRAME_SCROLL_BARS (f
);
5087 XSETVECTOR (barobj
, bar
);
5088 fset_scroll_bars (f
, barobj
);
5089 if (!NILP (bar
->next
))
5090 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5092 /* Map the window/widget. */
5093 #ifdef USE_TOOLKIT_SCROLL_BARS
5096 xg_update_scrollbar_pos (f
,
5099 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5100 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5102 #else /* not USE_GTK */
5103 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5104 XtConfigureWidget (scroll_bar
,
5105 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5107 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5108 max (height
, 1), 0);
5109 XtMapWidget (scroll_bar
);
5110 #endif /* not USE_GTK */
5112 #else /* not USE_TOOLKIT_SCROLL_BARS */
5113 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5114 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5121 #ifndef USE_TOOLKIT_SCROLL_BARS
5123 /* Draw BAR's handle in the proper position.
5125 If the handle is already drawn from START to END, don't bother
5126 redrawing it, unless REBUILD is non-zero; in that case, always
5127 redraw it. (REBUILD is handy for drawing the handle after expose
5130 Normally, we want to constrain the start and end of the handle to
5131 fit inside its rectangle, but if the user is dragging the scroll
5132 bar handle, we want to let them drag it down all the way, so that
5133 the bar's top is as far down as it goes; otherwise, there's no way
5134 to move to the very end of the buffer. */
5137 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
5139 bool dragging
= bar
->dragging
!= -1;
5140 Window w
= bar
->x_window
;
5141 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5142 GC gc
= f
->output_data
.x
->normal_gc
;
5144 /* If the display is already accurate, do nothing. */
5146 && start
== bar
->start
5153 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5154 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5155 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5157 /* Make sure the values are reasonable, and try to preserve
5158 the distance between start and end. */
5160 int length
= end
- start
;
5164 else if (start
> top_range
)
5166 end
= start
+ length
;
5170 else if (end
> top_range
&& ! dragging
)
5174 /* Store the adjusted setting in the scroll bar. */
5178 /* Clip the end position, just for display. */
5179 if (end
> top_range
)
5182 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5183 below top positions, to make sure the handle is always at least
5184 that many pixels tall. */
5185 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5187 /* Draw the empty space above the handle. Note that we can't clear
5188 zero-height areas; that means "clear to end of window." */
5190 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5191 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5192 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5193 inside_width
, start
);
5195 /* Change to proper foreground color if one is specified. */
5196 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5197 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5198 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5200 /* Draw the handle itself. */
5201 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5202 /* x, y, width, height */
5203 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5204 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5205 inside_width
, end
- start
);
5207 /* Restore the foreground color of the GC if we changed it above. */
5208 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5209 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5210 FRAME_FOREGROUND_PIXEL (f
));
5212 /* Draw the empty space below the handle. Note that we can't
5213 clear zero-height areas; that means "clear to end of window." */
5214 if (end
< inside_height
)
5215 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5216 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5217 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5218 inside_width
, inside_height
- end
);
5224 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5226 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5230 x_scroll_bar_remove (struct scroll_bar
*bar
)
5232 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5235 #ifdef USE_TOOLKIT_SCROLL_BARS
5237 xg_remove_scroll_bar (f
, bar
->x_window
);
5238 #else /* not USE_GTK */
5239 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5240 #endif /* not USE_GTK */
5242 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5245 /* Dissociate this scroll bar from its window. */
5246 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5252 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5253 that we are displaying PORTION characters out of a total of WHOLE
5254 characters, starting at POSITION. If WINDOW has no scroll bar,
5258 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5260 struct frame
*f
= XFRAME (w
->frame
);
5262 struct scroll_bar
*bar
;
5263 int top
, height
, left
, sb_left
, width
, sb_width
;
5264 int window_y
, window_height
;
5265 #ifdef USE_TOOLKIT_SCROLL_BARS
5266 bool fringe_extended_p
;
5269 /* Get window dimensions. */
5270 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
5272 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5273 height
= window_height
;
5275 /* Compute the left edge of the scroll bar area. */
5276 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5278 /* Compute the width of the scroll bar which might be less than
5279 the width of the area reserved for the scroll bar. */
5280 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5281 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5285 /* Compute the left edge of the scroll bar. */
5286 #ifdef USE_TOOLKIT_SCROLL_BARS
5287 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5288 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5290 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5292 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5293 sb_left
= left
+ width
- sb_width
;
5298 #ifdef USE_TOOLKIT_SCROLL_BARS
5299 fringe_extended_p
= WINDOW_FRINGE_EXTENDED_P (w
);
5302 /* Does the scroll bar exist yet? */
5303 if (NILP (w
->vertical_scroll_bar
))
5305 if (width
> 0 && height
> 0)
5308 #ifdef USE_TOOLKIT_SCROLL_BARS
5309 if (fringe_extended_p
)
5310 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5311 sb_left
, top
, sb_width
, height
);
5314 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5315 left
, top
, width
, height
);
5319 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5323 /* It may just need to be moved and resized. */
5324 unsigned int mask
= 0;
5326 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5330 if (sb_left
!= bar
->left
)
5332 if (top
!= bar
->top
)
5334 if (sb_width
!= bar
->width
)
5336 if (height
!= bar
->height
)
5339 #ifdef USE_TOOLKIT_SCROLL_BARS
5341 /* Move/size the scroll bar widget. */
5342 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5344 /* Since toolkit scroll bars are smaller than the space reserved
5345 for them on the frame, we have to clear "under" them. */
5346 if (width
> 0 && height
> 0)
5348 if (fringe_extended_p
)
5349 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5350 sb_left
, top
, sb_width
, height
);
5352 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5353 left
, top
, width
, height
);
5356 xg_update_scrollbar_pos (f
,
5359 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5360 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5362 #else /* not USE_GTK */
5363 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5364 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5366 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5367 max (height
, 1), 0);
5368 #endif /* not USE_GTK */
5370 #else /* not USE_TOOLKIT_SCROLL_BARS */
5372 /* Clear areas not covered by the scroll bar because of
5373 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5374 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5376 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5377 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
, height
);
5378 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5379 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5380 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
, height
);
5383 /* Clear areas not covered by the scroll bar because it's not as
5384 wide as the area reserved for it. This makes sure a
5385 previous mode line display is cleared after C-x 2 C-x 1, for
5388 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5389 int rest
= area_width
- sb_width
;
5390 if (rest
> 0 && height
> 0)
5392 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5393 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5394 left
+ area_width
- rest
, top
, rest
, height
);
5396 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5397 left
, top
, rest
, height
);
5401 /* Move/size the scroll bar window. */
5406 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5408 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5410 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5414 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5416 /* Remember new settings. */
5417 bar
->left
= sb_left
;
5419 bar
->width
= sb_width
;
5420 bar
->height
= height
;
5425 #ifdef USE_TOOLKIT_SCROLL_BARS
5426 bar
->fringe_extended_p
= fringe_extended_p
;
5428 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5429 #else /* not USE_TOOLKIT_SCROLL_BARS */
5430 /* Set the scroll bar's current state, unless we're currently being
5432 if (bar
->dragging
== -1)
5434 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5437 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5440 int start
= ((double) position
* top_range
) / whole
;
5441 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5442 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5445 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5447 XSETVECTOR (barobj
, bar
);
5448 wset_vertical_scroll_bar (w
, barobj
);
5452 /* The following three hooks are used when we're doing a thorough
5453 redisplay of the frame. We don't explicitly know which scroll bars
5454 are going to be deleted, because keeping track of when windows go
5455 away is a real pain - "Can you say set-window-configuration, boys
5456 and girls?" Instead, we just assert at the beginning of redisplay
5457 that *all* scroll bars are to be removed, and then save a scroll bar
5458 from the fiery pit when we actually redisplay its window. */
5460 /* Arrange for all scroll bars on FRAME to be removed at the next call
5461 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5462 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5465 XTcondemn_scroll_bars (struct frame
*frame
)
5467 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5468 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5471 bar
= FRAME_SCROLL_BARS (frame
);
5472 fset_scroll_bars (frame
, XSCROLL_BAR (bar
)->next
);
5473 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5474 XSCROLL_BAR (bar
)->prev
= Qnil
;
5475 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5476 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5477 fset_condemned_scroll_bars (frame
, bar
);
5482 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5483 Note that WINDOW isn't necessarily condemned at all. */
5486 XTredeem_scroll_bar (struct window
*window
)
5488 struct scroll_bar
*bar
;
5492 /* We can't redeem this window's scroll bar if it doesn't have one. */
5493 if (NILP (window
->vertical_scroll_bar
))
5496 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5498 /* Unlink it from the condemned list. */
5499 f
= XFRAME (WINDOW_FRAME (window
));
5500 if (NILP (bar
->prev
))
5502 /* If the prev pointer is nil, it must be the first in one of
5504 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5505 /* It's not condemned. Everything's fine. */
5507 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5508 window
->vertical_scroll_bar
))
5509 fset_condemned_scroll_bars (f
, bar
->next
);
5511 /* If its prev pointer is nil, it must be at the front of
5512 one or the other! */
5516 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5518 if (! NILP (bar
->next
))
5519 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5521 bar
->next
= FRAME_SCROLL_BARS (f
);
5523 XSETVECTOR (barobj
, bar
);
5524 fset_scroll_bars (f
, barobj
);
5525 if (! NILP (bar
->next
))
5526 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5529 /* Remove all scroll bars on FRAME that haven't been saved since the
5530 last call to `*condemn_scroll_bars_hook'. */
5533 XTjudge_scroll_bars (struct frame
*f
)
5535 Lisp_Object bar
, next
;
5537 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5539 /* Clear out the condemned list now so we won't try to process any
5540 more events on the hapless scroll bars. */
5541 fset_condemned_scroll_bars (f
, Qnil
);
5543 for (; ! NILP (bar
); bar
= next
)
5545 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5547 x_scroll_bar_remove (b
);
5550 b
->next
= b
->prev
= Qnil
;
5553 /* Now there should be no references to the condemned scroll bars,
5554 and they should get garbage-collected. */
5558 #ifndef USE_TOOLKIT_SCROLL_BARS
5559 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5560 is a no-op when using toolkit scroll bars.
5562 This may be called from a signal handler, so we have to ignore GC
5566 x_scroll_bar_expose (struct scroll_bar
*bar
, XEvent
*event
)
5568 Window w
= bar
->x_window
;
5569 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5570 GC gc
= f
->output_data
.x
->normal_gc
;
5571 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5575 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5577 /* Switch to scroll bar foreground color. */
5578 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5579 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5580 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5582 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5583 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5585 /* x, y, width, height */
5587 bar
->width
- 1 - width_trim
- width_trim
,
5590 /* Restore the foreground color of the GC if we changed it above. */
5591 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5592 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5593 FRAME_FOREGROUND_PIXEL (f
));
5598 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5600 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5601 is set to something other than NO_EVENT, it is enqueued.
5603 This may be called from a signal handler, so we have to ignore GC
5608 x_scroll_bar_handle_click (struct scroll_bar
*bar
, XEvent
*event
, struct input_event
*emacs_event
)
5610 if (! WINDOWP (bar
->window
))
5613 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5614 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5615 emacs_event
->modifiers
5616 = (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO
5617 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5618 event
->xbutton
.state
)
5619 | (event
->type
== ButtonRelease
5622 emacs_event
->frame_or_window
= bar
->window
;
5623 emacs_event
->arg
= Qnil
;
5624 emacs_event
->timestamp
= event
->xbutton
.time
;
5627 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5628 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5631 if (y
> top_range
) y
= top_range
;
5634 emacs_event
->part
= scroll_bar_above_handle
;
5635 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5636 emacs_event
->part
= scroll_bar_handle
;
5638 emacs_event
->part
= scroll_bar_below_handle
;
5640 #ifndef USE_TOOLKIT_SCROLL_BARS
5641 /* If the user has released the handle, set it to its final position. */
5642 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
5644 int new_start
= y
- bar
->dragging
;
5645 int new_end
= new_start
+ bar
->end
- bar
->start
;
5647 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5652 XSETINT (emacs_event
->x
, y
);
5653 XSETINT (emacs_event
->y
, top_range
);
5657 #ifndef USE_TOOLKIT_SCROLL_BARS
5659 /* Handle some mouse motion while someone is dragging the scroll bar.
5661 This may be called from a signal handler, so we have to ignore GC
5665 x_scroll_bar_note_movement (struct scroll_bar
*bar
, XMotionEvent
*event
)
5667 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5669 last_mouse_movement_time
= event
->time
;
5672 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5674 /* If we're dragging the bar, display it. */
5675 if (bar
->dragging
!= -1)
5677 /* Where should the handle be now? */
5678 int new_start
= event
->y
- bar
->dragging
;
5680 if (new_start
!= bar
->start
)
5682 int new_end
= new_start
+ bar
->end
- bar
->start
;
5684 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5689 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5691 /* Return information to the user about the current position of the mouse
5692 on the scroll bar. */
5695 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
5696 enum scroll_bar_part
*part
, Lisp_Object
*x
,
5697 Lisp_Object
*y
, Time
*timestamp
)
5699 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5700 Window w
= bar
->x_window
;
5701 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5703 Window dummy_window
;
5705 unsigned int dummy_mask
;
5709 /* Get the mouse's position relative to the scroll bar window, and
5711 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5713 /* Root, child, root x and root y. */
5714 &dummy_window
, &dummy_window
,
5715 &dummy_coord
, &dummy_coord
,
5717 /* Position relative to scroll bar. */
5720 /* Mouse buttons and modifier keys. */
5726 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5728 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5730 if (bar
->dragging
!= -1)
5731 win_y
-= bar
->dragging
;
5735 if (win_y
> top_range
)
5739 *bar_window
= bar
->window
;
5741 if (bar
->dragging
!= -1)
5742 *part
= scroll_bar_handle
;
5743 else if (win_y
< bar
->start
)
5744 *part
= scroll_bar_above_handle
;
5745 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5746 *part
= scroll_bar_handle
;
5748 *part
= scroll_bar_below_handle
;
5750 XSETINT (*x
, win_y
);
5751 XSETINT (*y
, top_range
);
5754 last_mouse_scroll_bar
= Qnil
;
5757 *timestamp
= last_mouse_movement_time
;
5763 /* The screen has been cleared so we may have changed foreground or
5764 background colors, and the scroll bars may need to be redrawn.
5765 Clear out the scroll bars, and ask for expose events, so we can
5769 x_scroll_bar_clear (struct frame
*f
)
5771 #ifndef USE_TOOLKIT_SCROLL_BARS
5774 /* We can have scroll bars even if this is 0,
5775 if we just turned off scroll bar mode.
5776 But in that case we should not clear them. */
5777 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5778 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5779 bar
= XSCROLL_BAR (bar
)->next
)
5780 XClearArea (FRAME_X_DISPLAY (f
),
5781 XSCROLL_BAR (bar
)->x_window
,
5783 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5786 #ifdef ENABLE_CHECKING
5788 /* Record the last 100 characters stored
5789 to help debug the loss-of-chars-during-GC problem. */
5791 static int temp_index
;
5792 static short temp_buffer
[100];
5794 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5795 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5797 temp_buffer[temp_index++] = (keysym)
5799 #else /* not ENABLE_CHECKING */
5801 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
5803 #endif /* ENABLE_CHECKING */
5805 /* Set this to nonzero to fake an "X I/O error"
5806 on a particular display. */
5808 static struct x_display_info
*XTread_socket_fake_io_error
;
5810 /* When we find no input here, we occasionally do a no-op command
5811 to verify that the X server is still running and we can still talk with it.
5812 We try all the open displays, one by one.
5813 This variable is used for cycling thru the displays. */
5815 static struct x_display_info
*next_noop_dpyinfo
;
5817 #if defined USE_X_TOOLKIT || defined USE_GTK
5818 #define SET_SAVED_BUTTON_EVENT \
5821 if (f->output_data.x->saved_menu_event == 0) \
5822 f->output_data.x->saved_menu_event = \
5823 xmalloc (sizeof (XEvent)); \
5824 *f->output_data.x->saved_menu_event = event; \
5825 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5826 XSETFRAME (inev.ie.frame_or_window, f); \
5838 /* Filter events for the current X input method.
5839 DPYINFO is the display this event is for.
5840 EVENT is the X event to filter.
5842 Returns non-zero if the event was filtered, caller shall not process
5844 Returns zero if event is wasn't filtered. */
5848 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5850 /* XFilterEvent returns non-zero if the input method has
5851 consumed the event. We pass the frame's X window to
5852 XFilterEvent because that's the one for which the IC
5855 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5856 event
->xclient
.window
);
5858 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5863 static int current_count
;
5864 static int current_finish
;
5865 static struct input_event
*current_hold_quit
;
5867 /* This is the filter function invoked by the GTK event loop.
5868 It is invoked before the XEvent is translated to a GdkEvent,
5869 so we have a chance to act on the event before GTK. */
5870 static GdkFilterReturn
5871 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5873 XEvent
*xev
= (XEvent
*) gxev
;
5876 if (current_count
>= 0)
5878 struct x_display_info
*dpyinfo
;
5880 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5883 /* Filter events for the current X input method.
5884 GTK calls XFilterEvent but not for key press and release,
5885 so we do it here. */
5886 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5888 && x_filter_event (dpyinfo
, xev
))
5891 return GDK_FILTER_REMOVE
;
5896 current_finish
= X_EVENT_NORMAL
;
5899 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5903 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5907 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5908 return GDK_FILTER_REMOVE
;
5910 return GDK_FILTER_CONTINUE
;
5912 #endif /* USE_GTK */
5915 static void xembed_send_message (struct frame
*f
, Time
,
5916 enum xembed_message
,
5917 long detail
, long data1
, long data2
);
5919 /* Handles the XEvent EVENT on display DPYINFO.
5921 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5922 *FINISH is zero if caller should continue reading events.
5923 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5925 We return the number of characters stored into the buffer. */
5928 handle_one_xevent (struct x_display_info
*dpyinfo
, XEvent
*eventptr
,
5929 int *finish
, struct input_event
*hold_quit
)
5932 struct input_event ie
;
5933 struct selection_input_event sie
;
5937 ptrdiff_t nbytes
= 0;
5938 struct frame
*f
= NULL
;
5939 struct coding_system coding
;
5940 XEvent event
= *eventptr
;
5941 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
5942 /* This holds the state XLookupString needs to implement dead keys
5943 and other tricks known as "compose processing". _X Window System_
5944 says that a portable program can't use this, but Stephen Gildea assures
5945 me that letting the compiler initialize it to zeros will work okay. */
5946 static XComposeStatus compose_status
;
5950 *finish
= X_EVENT_NORMAL
;
5952 EVENT_INIT (inev
.ie
);
5953 inev
.ie
.kind
= NO_EVENT
;
5956 if (pending_event_wait
.eventtype
== event
.type
)
5957 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5963 if (event
.xclient
.message_type
5964 == dpyinfo
->Xatom_wm_protocols
5965 && event
.xclient
.format
== 32)
5967 if (event
.xclient
.data
.l
[0]
5968 == dpyinfo
->Xatom_wm_take_focus
)
5970 /* Use x_any_window_to_frame because this
5971 could be the shell widget window
5972 if the frame has no title bar. */
5973 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5975 /* Not quite sure this is needed -pd */
5976 if (f
&& FRAME_XIC (f
))
5977 XSetICFocus (FRAME_XIC (f
));
5979 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5980 instructs the WM to set the input focus automatically for
5981 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5982 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5983 it has set the focus. So, XSetInputFocus below is not
5986 The call to XSetInputFocus below has also caused trouble. In
5987 cases where the XSetInputFocus done by the WM and the one
5988 below are temporally close (on a fast machine), the call
5989 below can generate additional FocusIn events which confuse
5992 /* Since we set WM_TAKE_FOCUS, we must call
5993 XSetInputFocus explicitly. But not if f is null,
5994 since that might be an event for a deleted frame. */
5997 Display
*d
= event
.xclient
.display
;
5998 /* Catch and ignore errors, in case window has been
5999 iconified by a window manager such as GWM. */
6001 XSetInputFocus (d
, event
.xclient
.window
,
6002 /* The ICCCM says this is
6003 the only valid choice. */
6005 event
.xclient
.data
.l
[1]);
6006 /* This is needed to detect the error
6007 if there is an error. */
6009 x_uncatch_errors ();
6011 /* Not certain about handling scroll bars here */
6016 if (event
.xclient
.data
.l
[0]
6017 == dpyinfo
->Xatom_wm_save_yourself
)
6019 /* Save state modify the WM_COMMAND property to
6020 something which can reinstate us. This notifies
6021 the session manager, who's looking for such a
6022 PropertyNotify. Can restart processing when
6023 a keyboard or mouse event arrives. */
6024 /* If we have a session manager, don't set this.
6025 KDE will then start two Emacsen, one for the
6026 session manager and one for this. */
6028 if (! x_session_have_connection ())
6031 f
= x_top_window_to_frame (dpyinfo
,
6032 event
.xclient
.window
);
6033 /* This is just so we only give real data once
6034 for a single Emacs process. */
6035 if (f
== SELECTED_FRAME ())
6036 XSetCommand (FRAME_X_DISPLAY (f
),
6037 event
.xclient
.window
,
6038 initial_argv
, initial_argc
);
6040 XSetCommand (FRAME_X_DISPLAY (f
),
6041 event
.xclient
.window
,
6047 if (event
.xclient
.data
.l
[0]
6048 == dpyinfo
->Xatom_wm_delete_window
)
6050 f
= x_any_window_to_frame (dpyinfo
,
6051 event
.xclient
.window
);
6053 goto OTHER
; /* May be a dialog that is to be removed */
6055 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
6056 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6063 if (event
.xclient
.message_type
6064 == dpyinfo
->Xatom_wm_configure_denied
)
6069 if (event
.xclient
.message_type
6070 == dpyinfo
->Xatom_wm_window_moved
)
6073 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6075 new_x
= event
.xclient
.data
.s
[0];
6076 new_y
= event
.xclient
.data
.s
[1];
6080 f
->left_pos
= new_x
;
6087 if (event
.xclient
.message_type
6088 == dpyinfo
->Xatom_editres
)
6090 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6092 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
6096 #endif /* HACK_EDITRES */
6098 if ((event
.xclient
.message_type
6099 == dpyinfo
->Xatom_DONE
)
6100 || (event
.xclient
.message_type
6101 == dpyinfo
->Xatom_PAGE
))
6103 /* Ghostview job completed. Kill it. We could
6104 reply with "Next" if we received "Page", but we
6105 currently never do because we are interested in
6106 images, only, which should have 1 page. */
6107 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
6108 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6111 x_kill_gs_process (pixmap
, f
);
6112 expose_frame (f
, 0, 0, 0, 0);
6116 #ifdef USE_TOOLKIT_SCROLL_BARS
6117 /* Scroll bar callbacks send a ClientMessage from which
6118 we construct an input_event. */
6119 if (event
.xclient
.message_type
6120 == dpyinfo
->Xatom_Scrollbar
)
6122 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
6123 *finish
= X_EVENT_GOTO_OUT
;
6126 #endif /* USE_TOOLKIT_SCROLL_BARS */
6128 /* XEmbed messages from the embedder (if any). */
6129 if (event
.xclient
.message_type
6130 == dpyinfo
->Xatom_XEMBED
)
6132 enum xembed_message msg
= event
.xclient
.data
.l
[1];
6133 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6134 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6136 *finish
= X_EVENT_GOTO_OUT
;
6140 xft_settings_event (dpyinfo
, &event
);
6142 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6145 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6146 *finish
= X_EVENT_DROP
;
6150 case SelectionNotify
:
6151 dpyinfo
->last_user_time
= event
.xselection
.time
;
6152 #ifdef USE_X_TOOLKIT
6153 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6155 #endif /* not USE_X_TOOLKIT */
6156 x_handle_selection_notify (&event
.xselection
);
6159 case SelectionClear
: /* Someone has grabbed ownership. */
6160 dpyinfo
->last_user_time
= event
.xselectionclear
.time
;
6161 #ifdef USE_X_TOOLKIT
6162 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6164 #endif /* USE_X_TOOLKIT */
6166 XSelectionClearEvent
*eventp
= &(event
.xselectionclear
);
6168 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6169 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6170 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6171 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6175 case SelectionRequest
: /* Someone wants our selection. */
6176 dpyinfo
->last_user_time
= event
.xselectionrequest
.time
;
6177 #ifdef USE_X_TOOLKIT
6178 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6180 #endif /* USE_X_TOOLKIT */
6182 XSelectionRequestEvent
*eventp
= &(event
.xselectionrequest
);
6184 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6185 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6186 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6187 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6188 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6189 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6190 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6194 case PropertyNotify
:
6195 dpyinfo
->last_user_time
= event
.xproperty
.time
;
6196 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
6197 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6198 if (x_handle_net_wm_state (f
, &event
.xproperty
)
6199 && FRAME_ICONIFIED_P (f
)
6200 && f
->output_data
.x
->net_wm_state_hidden_seen
)
6202 /* Gnome shell does not iconify us when C-z is pressed.
6203 It hides the frame. So if our state says we aren't
6204 hidden anymore, treat it as deiconified. */
6205 SET_FRAME_VISIBLE (f
, 1);
6206 SET_FRAME_ICONIFIED (f
, 0);
6207 f
->output_data
.x
->has_been_visible
= 1;
6208 f
->output_data
.x
->net_wm_state_hidden_seen
= 0;
6209 inev
.ie
.kind
= DEICONIFY_EVENT
;
6210 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6213 x_handle_property_notify (&event
.xproperty
);
6214 xft_settings_event (dpyinfo
, &event
);
6217 case ReparentNotify
:
6218 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6222 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6223 x_real_positions (f
, &x
, &y
);
6227 /* Perhaps reparented due to a WM restart. Reset this. */
6228 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6229 FRAME_DISPLAY_INFO (f
)->net_supported_window
= 0;
6231 x_set_frame_alpha (f
);
6236 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6240 /* This seems to be needed for GTK 2.6. */
6241 x_clear_area (event
.xexpose
.display
,
6242 event
.xexpose
.window
,
6243 event
.xexpose
.x
, event
.xexpose
.y
,
6244 event
.xexpose
.width
, event
.xexpose
.height
);
6246 if (!FRAME_VISIBLE_P (f
))
6248 SET_FRAME_VISIBLE (f
, 1);
6249 SET_FRAME_ICONIFIED (f
, 0);
6250 f
->output_data
.x
->has_been_visible
= 1;
6251 SET_FRAME_GARBAGED (f
);
6255 event
.xexpose
.x
, event
.xexpose
.y
,
6256 event
.xexpose
.width
, event
.xexpose
.height
);
6260 #ifndef USE_TOOLKIT_SCROLL_BARS
6261 struct scroll_bar
*bar
;
6263 #if defined USE_LUCID
6264 /* Submenus of the Lucid menu bar aren't widgets
6265 themselves, so there's no way to dispatch events
6266 to them. Recognize this case separately. */
6269 = x_window_to_menu_bar (event
.xexpose
.window
);
6271 xlwmenu_redisplay (widget
);
6273 #endif /* USE_LUCID */
6275 #ifdef USE_TOOLKIT_SCROLL_BARS
6276 /* Dispatch event to the widget. */
6278 #else /* not USE_TOOLKIT_SCROLL_BARS */
6279 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6280 event
.xexpose
.window
);
6283 x_scroll_bar_expose (bar
, &event
);
6284 #ifdef USE_X_TOOLKIT
6287 #endif /* USE_X_TOOLKIT */
6288 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6292 case GraphicsExpose
: /* This occurs when an XCopyArea's
6293 source area was obscured or not
6295 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6299 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6300 event
.xgraphicsexpose
.width
,
6301 event
.xgraphicsexpose
.height
);
6303 #ifdef USE_X_TOOLKIT
6306 #endif /* USE_X_TOOLKIT */
6309 case NoExpose
: /* This occurs when an XCopyArea's
6310 source area was completely
6315 /* Redo the mouse-highlight after the tooltip has gone. */
6316 if (event
.xunmap
.window
== tip_window
)
6319 redo_mouse_highlight ();
6322 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6323 if (f
) /* F may no longer exist if
6324 the frame was deleted. */
6326 bool visible
= FRAME_VISIBLE_P (f
);
6327 /* While a frame is unmapped, display generation is
6328 disabled; you don't want to spend time updating a
6329 display that won't ever be seen. */
6330 SET_FRAME_VISIBLE (f
, 0);
6331 /* We can't distinguish, from the event, whether the window
6332 has become iconified or invisible. So assume, if it
6333 was previously visible, than now it is iconified.
6334 But x_make_frame_invisible clears both
6335 the visible flag and the iconified flag;
6336 and that way, we know the window is not iconified now. */
6337 if (visible
|| FRAME_ICONIFIED_P (f
))
6339 SET_FRAME_ICONIFIED (f
, 1);
6340 inev
.ie
.kind
= ICONIFY_EVENT
;
6341 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6347 if (event
.xmap
.window
== tip_window
)
6348 /* The tooltip has been drawn already. Avoid
6349 the SET_FRAME_GARBAGED below. */
6352 /* We use x_top_window_to_frame because map events can
6353 come for sub-windows and they don't mean that the
6354 frame is visible. */
6355 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6358 bool iconified
= FRAME_ICONIFIED_P (f
);
6359 /* wait_reading_process_output will notice this and update
6360 the frame's display structures.
6361 If we where iconified, we should not set garbaged,
6362 because that stops redrawing on Expose events. This looks
6363 bad if we are called from a recursive event loop
6364 (x_dispatch_event), for example when a dialog is up. */
6366 SET_FRAME_GARBAGED (f
);
6368 /* Check if fullscreen was specified before we where mapped the
6369 first time, i.e. from the command line. */
6370 if (!f
->output_data
.x
->has_been_visible
)
6371 x_check_fullscreen (f
);
6373 SET_FRAME_VISIBLE (f
, 1);
6374 SET_FRAME_ICONIFIED (f
, 0);
6375 f
->output_data
.x
->has_been_visible
= 1;
6379 inev
.ie
.kind
= DEICONIFY_EVENT
;
6380 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6382 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
6383 /* Force a redisplay sooner or later to update the
6384 frame titles in case this is the second frame. */
6385 record_asynch_buffer_change ();
6388 xg_frame_resized (f
, -1, -1);
6395 dpyinfo
->last_user_time
= event
.xkey
.time
;
6396 ignore_next_mouse_click_timeout
= 0;
6398 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6399 /* Dispatch KeyPress events when in menu. */
6400 if (popup_activated ())
6404 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6406 #if ! defined (USE_GTK)
6407 /* If mouse-highlight is an integer, input clears out
6408 mouse highlighting. */
6409 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6411 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)))
6413 clear_mouse_face (hlinfo
);
6414 hlinfo
->mouse_face_hidden
= 1;
6418 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6421 /* Scroll bars consume key events, but we want
6422 the keys to go to the scroll bar's frame. */
6423 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6425 if (widget
&& XmIsScrollBar (widget
))
6427 widget
= XtParent (widget
);
6428 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6431 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6435 KeySym keysym
, orig_keysym
;
6436 /* al%imercury@uunet.uu.net says that making this 81
6437 instead of 80 fixed a bug whereby meta chars made
6440 It seems that some version of XmbLookupString has
6441 a bug of not returning XBufferOverflow in
6442 status_return even if the input is too long to
6443 fit in 81 bytes. So, we must prepare sufficient
6444 bytes for copy_buffer. 513 bytes (256 chars for
6445 two-byte character set) seems to be a fairly good
6446 approximation. -- 2000.8.10 handa@etl.go.jp */
6447 unsigned char copy_buffer
[513];
6448 unsigned char *copy_bufptr
= copy_buffer
;
6449 int copy_bufsiz
= sizeof (copy_buffer
);
6451 Lisp_Object coding_system
= Qlatin_1
;
6455 /* Don't pass keys to GTK. A Tab will shift focus to the
6456 tool bar in GTK 2.4. Keys will still go to menus and
6457 dialogs because in that case popup_activated is TRUE
6459 *finish
= X_EVENT_DROP
;
6463 |= x_emacs_to_x_modifiers (FRAME_DISPLAY_INFO (f
),
6464 extra_keyboard_modifiers
);
6465 modifiers
= event
.xkey
.state
;
6467 /* This will have to go some day... */
6469 /* make_lispy_event turns chars into control chars.
6470 Don't do it here because XLookupString is too eager. */
6471 event
.xkey
.state
&= ~ControlMask
;
6472 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6473 | dpyinfo
->super_mod_mask
6474 | dpyinfo
->hyper_mod_mask
6475 | dpyinfo
->alt_mod_mask
);
6477 /* In case Meta is ComposeCharacter,
6478 clear its status. According to Markus Ehrnsperger
6479 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6480 this enables ComposeCharacter to work whether or
6481 not it is combined with Meta. */
6482 if (modifiers
& dpyinfo
->meta_mod_mask
)
6483 memset (&compose_status
, 0, sizeof (compose_status
));
6488 Status status_return
;
6490 coding_system
= Vlocale_coding_system
;
6491 nbytes
= XmbLookupString (FRAME_XIC (f
),
6492 &event
.xkey
, (char *) copy_bufptr
,
6493 copy_bufsiz
, &keysym
,
6495 if (status_return
== XBufferOverflow
)
6497 copy_bufsiz
= nbytes
+ 1;
6498 copy_bufptr
= alloca (copy_bufsiz
);
6499 nbytes
= XmbLookupString (FRAME_XIC (f
),
6500 &event
.xkey
, (char *) copy_bufptr
,
6501 copy_bufsiz
, &keysym
,
6504 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6505 if (status_return
== XLookupNone
)
6507 else if (status_return
== XLookupChars
)
6512 else if (status_return
!= XLookupKeySym
6513 && status_return
!= XLookupBoth
)
6517 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6518 copy_bufsiz
, &keysym
,
6521 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6522 copy_bufsiz
, &keysym
,
6526 /* If not using XIM/XIC, and a compose sequence is in progress,
6527 we break here. Otherwise, chars_matched is always 0. */
6528 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6531 memset (&compose_status
, 0, sizeof (compose_status
));
6532 orig_keysym
= keysym
;
6534 /* Common for all keysym input events. */
6535 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6537 = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
), modifiers
);
6538 inev
.ie
.timestamp
= event
.xkey
.time
;
6540 /* First deal with keysyms which have defined
6541 translations to characters. */
6542 if (keysym
>= 32 && keysym
< 128)
6543 /* Avoid explicitly decoding each ASCII character. */
6545 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6546 inev
.ie
.code
= keysym
;
6550 /* Keysyms directly mapped to Unicode characters. */
6551 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6553 if (keysym
< 0x01000080)
6554 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6556 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6557 inev
.ie
.code
= keysym
& 0xFFFFFF;
6561 /* Now non-ASCII. */
6562 if (HASH_TABLE_P (Vx_keysym_table
)
6563 && (c
= Fgethash (make_number (keysym
),
6568 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6569 ? ASCII_KEYSTROKE_EVENT
6570 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6571 inev
.ie
.code
= XFASTINT (c
);
6575 /* Random non-modifier sorts of keysyms. */
6576 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6577 || keysym
== XK_Delete
6578 #ifdef XK_ISO_Left_Tab
6579 || (keysym
>= XK_ISO_Left_Tab
6580 && keysym
<= XK_ISO_Enter
)
6582 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6583 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6585 /* This recognizes the "extended function
6586 keys". It seems there's no cleaner way.
6587 Test IsModifierKey to avoid handling
6588 mode_switch incorrectly. */
6589 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
6591 #ifdef XK_dead_circumflex
6592 || orig_keysym
== XK_dead_circumflex
6594 #ifdef XK_dead_grave
6595 || orig_keysym
== XK_dead_grave
6597 #ifdef XK_dead_tilde
6598 || orig_keysym
== XK_dead_tilde
6600 #ifdef XK_dead_diaeresis
6601 || orig_keysym
== XK_dead_diaeresis
6603 #ifdef XK_dead_macron
6604 || orig_keysym
== XK_dead_macron
6606 #ifdef XK_dead_degree
6607 || orig_keysym
== XK_dead_degree
6609 #ifdef XK_dead_acute
6610 || orig_keysym
== XK_dead_acute
6612 #ifdef XK_dead_cedilla
6613 || orig_keysym
== XK_dead_cedilla
6615 #ifdef XK_dead_breve
6616 || orig_keysym
== XK_dead_breve
6618 #ifdef XK_dead_ogonek
6619 || orig_keysym
== XK_dead_ogonek
6621 #ifdef XK_dead_caron
6622 || orig_keysym
== XK_dead_caron
6624 #ifdef XK_dead_doubleacute
6625 || orig_keysym
== XK_dead_doubleacute
6627 #ifdef XK_dead_abovedot
6628 || orig_keysym
== XK_dead_abovedot
6630 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6631 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6632 /* Any "vendor-specific" key is ok. */
6633 || (orig_keysym
& (1 << 28))
6634 || (keysym
!= NoSymbol
&& nbytes
== 0))
6635 && ! (IsModifierKey (orig_keysym
)
6636 /* The symbols from XK_ISO_Lock
6637 to XK_ISO_Last_Group_Lock
6638 don't have real modifiers but
6639 should be treated similarly to
6640 Mode_switch by Emacs. */
6641 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6642 || (XK_ISO_Lock
<= orig_keysym
6643 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
6647 STORE_KEYSYM_FOR_DEBUG (keysym
);
6648 /* make_lispy_event will convert this to a symbolic
6650 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6651 inev
.ie
.code
= keysym
;
6655 { /* Raw bytes, not keysym. */
6659 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6661 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6663 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6666 if (nchars
< nbytes
)
6668 /* Decode the input data. */
6670 /* The input should be decoded with `coding_system'
6671 which depends on which X*LookupString function
6672 we used just above and the locale. */
6673 setup_coding_system (coding_system
, &coding
);
6674 coding
.src_multibyte
= 0;
6675 coding
.dst_multibyte
= 1;
6676 /* The input is converted to events, thus we can't
6677 handle composition. Anyway, there's no XIM that
6678 gives us composition information. */
6679 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6681 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
6683 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6684 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6685 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6686 nbytes
= coding
.produced
;
6687 nchars
= coding
.produced_char
;
6688 copy_bufptr
= coding
.destination
;
6691 /* Convert the input data to a sequence of
6692 character events. */
6693 for (i
= 0; i
< nbytes
; i
+= len
)
6696 if (nchars
== nbytes
)
6697 ch
= copy_bufptr
[i
], len
= 1;
6699 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6700 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
6701 ? ASCII_KEYSTROKE_EVENT
6702 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6704 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6709 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6711 if (keysym
== NoSymbol
)
6717 /* Don't dispatch this event since XtDispatchEvent calls
6718 XFilterEvent, and two calls in a row may freeze the
6726 dpyinfo
->last_user_time
= event
.xkey
.time
;
6728 /* Don't dispatch this event since XtDispatchEvent calls
6729 XFilterEvent, and two calls in a row may freeze the
6737 dpyinfo
->last_user_time
= event
.xcrossing
.time
;
6738 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6740 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6742 if (f
&& x_mouse_click_focus_ignore_position
)
6743 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6745 /* EnterNotify counts as mouse movement,
6746 so update things that depend on mouse position. */
6747 if (f
&& !f
->output_data
.x
->hourglass_p
)
6748 note_mouse_movement (f
, &event
.xmotion
);
6750 /* We may get an EnterNotify on the buttons in the toolbar. In that
6751 case we moved out of any highlighted area and need to note this. */
6752 if (!f
&& last_mouse_glyph_frame
)
6753 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6758 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6762 dpyinfo
->last_user_time
= event
.xcrossing
.time
;
6763 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6765 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6768 if (f
== hlinfo
->mouse_face_mouse_frame
)
6770 /* If we move outside the frame, then we're
6771 certainly no longer on any text in the frame. */
6772 clear_mouse_face (hlinfo
);
6773 hlinfo
->mouse_face_mouse_frame
= 0;
6776 /* Generate a nil HELP_EVENT to cancel a help-echo.
6777 Do it only if there's something to cancel.
6778 Otherwise, the startup message is cleared when
6779 the mouse leaves the frame. */
6780 if (any_help_event_p
)
6784 /* See comment in EnterNotify above */
6785 else if (last_mouse_glyph_frame
)
6786 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6791 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6796 dpyinfo
->last_user_time
= event
.xmotion
.time
;
6797 previous_help_echo_string
= help_echo_string
;
6798 help_echo_string
= Qnil
;
6800 if (dpyinfo
->grabbed
&& last_mouse_frame
6801 && FRAME_LIVE_P (last_mouse_frame
))
6802 f
= last_mouse_frame
;
6804 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6806 if (hlinfo
->mouse_face_hidden
)
6808 hlinfo
->mouse_face_hidden
= 0;
6809 clear_mouse_face (hlinfo
);
6813 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6819 /* Generate SELECT_WINDOW_EVENTs when needed.
6820 Don't let popup menus influence things (bug#1261). */
6821 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6823 static Lisp_Object last_mouse_window
;
6824 Lisp_Object window
= window_from_coordinates
6825 (f
, event
.xmotion
.x
, event
.xmotion
.y
, 0, 0);
6827 /* Window will be selected only when it is not selected now and
6828 last mouse movement event was not in it. Minibuffer window
6829 will be selected only when it is active. */
6830 if (WINDOWP (window
)
6831 && !EQ (window
, last_mouse_window
)
6832 && !EQ (window
, selected_window
)
6833 /* For click-to-focus window managers
6834 create event iff we don't leave the
6836 && (focus_follows_mouse
6837 || (EQ (XWINDOW (window
)->frame
,
6838 XWINDOW (selected_window
)->frame
))))
6840 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6841 inev
.ie
.frame_or_window
= window
;
6843 /* Remember the last window where we saw the mouse. */
6844 last_mouse_window
= window
;
6846 if (!note_mouse_movement (f
, &event
.xmotion
))
6847 help_echo_string
= previous_help_echo_string
;
6851 #ifndef USE_TOOLKIT_SCROLL_BARS
6852 struct scroll_bar
*bar
6853 = x_window_to_scroll_bar (event
.xmotion
.display
,
6854 event
.xmotion
.window
);
6857 x_scroll_bar_note_movement (bar
, &event
.xmotion
);
6858 #endif /* USE_TOOLKIT_SCROLL_BARS */
6860 /* If we move outside the frame, then we're
6861 certainly no longer on any text in the frame. */
6862 clear_mouse_face (hlinfo
);
6865 /* If the contents of the global variable help_echo_string
6866 has changed, generate a HELP_EVENT. */
6867 if (!NILP (help_echo_string
)
6868 || !NILP (previous_help_echo_string
))
6873 case ConfigureNotify
:
6874 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6877 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6878 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6880 xg_frame_resized (f
, event
.xconfigure
.width
,
6881 event
.xconfigure
.height
);
6887 #ifndef USE_X_TOOLKIT
6889 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6890 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6892 /* In the toolkit version, change_frame_size
6893 is called by the code that handles resizing
6894 of the EmacsFrame widget. */
6896 /* Even if the number of character rows and columns has
6897 not changed, the font size may have changed, so we need
6898 to check the pixel dimensions as well. */
6899 if (columns
!= FRAME_COLS (f
)
6900 || rows
!= FRAME_LINES (f
)
6901 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6902 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6904 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6905 SET_FRAME_GARBAGED (f
);
6906 cancel_mouse_face (f
);
6909 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6910 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6911 #endif /* not USE_GTK */
6915 /* GTK creates windows but doesn't map them.
6916 Only get real positions when mapped. */
6917 if (FRAME_GTK_OUTER_WIDGET (f
)
6918 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6921 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6925 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6926 xic_set_statusarea (f
);
6935 /* If we decide we want to generate an event to be seen
6936 by the rest of Emacs, we put it here. */
6937 bool tool_bar_p
= 0;
6939 memset (&compose_status
, 0, sizeof (compose_status
));
6940 last_mouse_glyph_frame
= 0;
6941 dpyinfo
->last_user_time
= event
.xbutton
.time
;
6943 if (dpyinfo
->grabbed
6945 && FRAME_LIVE_P (last_mouse_frame
))
6946 f
= last_mouse_frame
;
6948 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6951 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6956 #if ! defined (USE_GTK)
6957 /* Is this in the tool-bar? */
6958 if (WINDOWP (f
->tool_bar_window
)
6959 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6962 int x
= event
.xbutton
.x
;
6963 int y
= event
.xbutton
.y
;
6965 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6966 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6968 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6969 handle_tool_bar_click
6970 (f
, x
, y
, event
.xbutton
.type
== ButtonPress
,
6971 x_x_to_emacs_modifiers (dpyinfo
, event
.xbutton
.state
));
6973 #endif /* !USE_GTK */
6976 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6977 if (! popup_activated ())
6980 if (ignore_next_mouse_click_timeout
)
6982 if (event
.type
== ButtonPress
6983 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6985 ignore_next_mouse_click_timeout
= 0;
6986 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6988 if (event
.type
== ButtonRelease
)
6989 ignore_next_mouse_click_timeout
= 0;
6992 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6994 if (FRAME_X_EMBEDDED_P (f
))
6995 xembed_send_message (f
, event
.xbutton
.time
,
6996 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
7000 struct scroll_bar
*bar
7001 = x_window_to_scroll_bar (event
.xbutton
.display
,
7002 event
.xbutton
.window
);
7004 #ifdef USE_TOOLKIT_SCROLL_BARS
7005 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
7007 if (bar
&& event
.xbutton
.state
& ControlMask
)
7009 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7010 *finish
= X_EVENT_DROP
;
7012 #else /* not USE_TOOLKIT_SCROLL_BARS */
7014 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
7015 #endif /* not USE_TOOLKIT_SCROLL_BARS */
7018 if (event
.type
== ButtonPress
)
7020 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
7021 last_mouse_frame
= f
;
7024 last_tool_bar_item
= -1;
7027 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
7029 /* Ignore any mouse motion that happened before this event;
7030 any subsequent mouse-movement Emacs events should reflect
7031 only motion after the ButtonPress/Release. */
7035 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
7036 f
= x_menubar_window_to_frame (dpyinfo
, &event
);
7037 /* For a down-event in the menu bar,
7038 don't pass it to Xt right now.
7039 Instead, save it away
7040 and we will pass it to Xt from kbd_buffer_get_event.
7041 That way, we can run some Lisp code first. */
7042 if (! popup_activated ()
7044 /* Gtk+ menus only react to the first three buttons. */
7045 && event
.xbutton
.button
< 3
7047 && f
&& event
.type
== ButtonPress
7048 /* Verify the event is really within the menu bar
7049 and not just sent to it due to grabbing. */
7050 && event
.xbutton
.x
>= 0
7051 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
7052 && event
.xbutton
.y
>= 0
7053 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
7054 && event
.xbutton
.same_screen
)
7056 SET_SAVED_BUTTON_EVENT
;
7057 *finish
= X_EVENT_DROP
;
7061 #endif /* USE_X_TOOLKIT || USE_GTK */
7065 case CirculateNotify
:
7068 case CirculateRequest
:
7071 case VisibilityNotify
:
7075 /* Someone has changed the keyboard mapping - update the
7077 switch (event
.xmapping
.request
)
7079 case MappingModifier
:
7080 x_find_modifier_meanings (dpyinfo
);
7081 /* This is meant to fall through. */
7082 case MappingKeyboard
:
7083 XRefreshKeyboardMapping (&event
.xmapping
);
7088 xft_settings_event (dpyinfo
, &event
);
7093 #ifdef USE_X_TOOLKIT
7095 if (*finish
!= X_EVENT_DROP
)
7096 XtDispatchEvent (&event
);
7098 #endif /* USE_X_TOOLKIT */
7103 if (inev
.ie
.kind
!= NO_EVENT
)
7105 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7110 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7115 XSETFRAME (frame
, f
);
7121 any_help_event_p
= 1;
7122 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7123 help_echo_object
, help_echo_pos
);
7127 help_echo_string
= Qnil
;
7128 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7138 #if defined USE_GTK || defined USE_X_TOOLKIT
7140 /* Handles the XEvent EVENT on display DISPLAY.
7141 This is used for event loops outside the normal event handling,
7142 i.e. looping while a popup menu or a dialog is posted.
7144 Returns the value handle_one_xevent sets in the finish argument. */
7146 x_dispatch_event (XEvent
*event
, Display
*display
)
7148 struct x_display_info
*dpyinfo
;
7149 int finish
= X_EVENT_NORMAL
;
7151 dpyinfo
= x_display_info_for_display (display
);
7154 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7161 /* Read events coming from the X server.
7162 Return as soon as there are no more events to be read.
7164 Return the number of characters stored into the buffer,
7165 thus pretending to be `read' (except the characters we store
7166 in the keyboard buffer can be multibyte, so are not necessarily
7170 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
7173 int event_found
= 0;
7177 /* So people can tell when we have read the available input. */
7178 input_signal_count
++;
7180 /* For debugging, this gives a way to fake an I/O error. */
7181 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7183 XTread_socket_fake_io_error
= 0;
7184 x_io_error_quitter (terminal
->display_info
.x
->display
);
7188 while (XPending (terminal
->display_info
.x
->display
))
7193 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7196 /* Filter events for the current X input method. */
7197 if (x_filter_event (terminal
->display_info
.x
, &event
))
7202 count
+= handle_one_xevent (terminal
->display_info
.x
,
7203 &event
, &finish
, hold_quit
);
7205 if (finish
== X_EVENT_GOTO_OUT
)
7213 /* For GTK we must use the GTK event loop. But XEvents gets passed
7214 to our filter function above, and then to the big event switch.
7215 We use a bunch of globals to communicate with our filter function,
7216 that is kind of ugly, but it works.
7218 There is no way to do one display at the time, GTK just does events
7219 from all displays. */
7221 while (gtk_events_pending ())
7223 current_count
= count
;
7224 current_hold_quit
= hold_quit
;
7226 gtk_main_iteration ();
7228 count
= current_count
;
7230 current_hold_quit
= 0;
7232 if (current_finish
== X_EVENT_GOTO_OUT
)
7235 #endif /* USE_GTK */
7237 /* On some systems, an X bug causes Emacs to get no more events
7238 when the window is destroyed. Detect that. (1994.) */
7241 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7242 One XNOOP in 100 loops will make Emacs terminate.
7243 B. Bretthauer, 1994 */
7245 if (x_noop_count
>= 100)
7249 if (next_noop_dpyinfo
== 0)
7250 next_noop_dpyinfo
= x_display_list
;
7252 XNoOp (next_noop_dpyinfo
->display
);
7254 /* Each time we get here, cycle through the displays now open. */
7255 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7259 /* If the focus was just given to an auto-raising frame,
7261 /* ??? This ought to be able to handle more than one such frame. */
7262 if (pending_autoraise_frame
)
7264 x_raise_frame (pending_autoraise_frame
);
7265 pending_autoraise_frame
= 0;
7276 /***********************************************************************
7278 ***********************************************************************/
7280 /* Set clipping for output in glyph row ROW. W is the window in which
7281 we operate. GC is the graphics context to set clipping in.
7283 ROW may be a text row or, e.g., a mode line. Text rows must be
7284 clipped to the interior of the window dedicated to text display,
7285 mode lines must be clipped to the whole window. */
7288 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
7289 enum glyph_row_area area
, GC gc
)
7291 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7292 XRectangle clip_rect
;
7293 int window_x
, window_y
, window_width
;
7295 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7297 clip_rect
.x
= window_x
;
7298 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7299 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7300 clip_rect
.width
= window_width
;
7301 clip_rect
.height
= row
->visible_height
;
7303 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7307 /* Draw a hollow box cursor on window W in glyph row ROW. */
7310 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7312 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7313 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
7314 Display
*dpy
= FRAME_X_DISPLAY (f
);
7317 struct glyph
*cursor_glyph
;
7320 /* Get the glyph the cursor is on. If we can't tell because
7321 the current matrix is invalid or such, give up. */
7322 cursor_glyph
= get_phys_cursor_glyph (w
);
7323 if (cursor_glyph
== NULL
)
7326 /* Compute frame-relative coordinates for phys cursor. */
7327 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7328 wd
= w
->phys_cursor_width
;
7330 /* The foreground of cursor_gc is typically the same as the normal
7331 background color, which can cause the cursor box to be invisible. */
7332 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7333 if (dpyinfo
->scratch_cursor_gc
)
7334 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7336 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7337 GCForeground
, &xgcv
);
7338 gc
= dpyinfo
->scratch_cursor_gc
;
7340 /* Set clipping, draw the rectangle, and reset clipping again. */
7341 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7342 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7343 XSetClipMask (dpy
, gc
, None
);
7347 /* Draw a bar cursor on window W in glyph row ROW.
7349 Implementation note: One would like to draw a bar cursor with an
7350 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7351 Unfortunately, I didn't find a font yet that has this property set.
7355 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7357 struct frame
*f
= XFRAME (w
->frame
);
7358 struct glyph
*cursor_glyph
;
7360 /* If cursor is out of bounds, don't draw garbage. This can happen
7361 in mini-buffer windows when switching between echo area glyphs
7363 cursor_glyph
= get_phys_cursor_glyph (w
);
7364 if (cursor_glyph
== NULL
)
7367 /* If on an image, draw like a normal cursor. That's usually better
7368 visible than drawing a bar, esp. if the image is large so that
7369 the bar might not be in the window. */
7370 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7372 struct glyph_row
*r
;
7373 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7374 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
7378 Display
*dpy
= FRAME_X_DISPLAY (f
);
7379 Window window
= FRAME_X_WINDOW (f
);
7380 GC gc
= FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7381 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7382 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7385 /* If the glyph's background equals the color we normally draw
7386 the bars cursor in, the bar cursor in its normal color is
7387 invisible. Use the glyph's foreground color instead in this
7388 case, on the assumption that the glyph's colors are chosen so
7389 that the glyph is legible. */
7390 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7391 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7393 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7394 xgcv
.graphics_exposures
= 0;
7397 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7400 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7401 FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7404 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7406 if (kind
== BAR_CURSOR
)
7408 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7411 width
= FRAME_CURSOR_WIDTH (f
);
7412 width
= min (cursor_glyph
->pixel_width
, width
);
7414 w
->phys_cursor_width
= width
;
7416 /* If the character under cursor is R2L, draw the bar cursor
7417 on the right of its glyph, rather than on the left. */
7418 if ((cursor_glyph
->resolved_level
& 1) != 0)
7419 x
+= cursor_glyph
->pixel_width
- width
;
7421 XFillRectangle (dpy
, window
, gc
, x
,
7422 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7423 width
, row
->height
);
7427 int dummy_x
, dummy_y
, dummy_h
;
7430 width
= row
->height
;
7432 width
= min (row
->height
, width
);
7434 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7435 &dummy_y
, &dummy_h
);
7437 XFillRectangle (dpy
, window
, gc
,
7438 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7439 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7440 row
->height
- width
),
7441 w
->phys_cursor_width
, width
);
7444 XSetClipMask (dpy
, gc
, None
);
7449 /* RIF: Define cursor CURSOR on frame F. */
7452 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7454 if (!f
->pointer_invisible
7455 && f
->output_data
.x
->current_cursor
!= cursor
)
7456 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7457 f
->output_data
.x
->current_cursor
= cursor
;
7461 /* RIF: Clear area on frame F. */
7464 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7466 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), x
, y
, width
, height
);
7468 /* Must queue a redraw, because scroll bars might have been cleared. */
7469 if (FRAME_GTK_WIDGET (f
))
7470 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7475 /* RIF: Draw cursor on window W. */
7478 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
7479 int y
, enum text_cursor_kinds cursor_type
,
7480 int cursor_width
, bool on_p
, bool active_p
)
7482 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7486 w
->phys_cursor_type
= cursor_type
;
7487 w
->phys_cursor_on_p
= 1;
7489 if (glyph_row
->exact_window_width_line_p
7490 && (glyph_row
->reversed_p
7491 ? (w
->phys_cursor
.hpos
< 0)
7492 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7494 glyph_row
->cursor_in_fringe_p
= 1;
7495 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7499 switch (cursor_type
)
7501 case HOLLOW_BOX_CURSOR
:
7502 x_draw_hollow_cursor (w
, glyph_row
);
7505 case FILLED_BOX_CURSOR
:
7506 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7510 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7514 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7518 w
->phys_cursor_width
= 0;
7527 if (w
== XWINDOW (f
->selected_window
))
7528 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7529 xic_set_preeditarea (w
, x
, y
);
7533 XFlush (FRAME_X_DISPLAY (f
));
7539 /* Make the x-window of frame F use the gnu icon bitmap. */
7542 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7544 ptrdiff_t bitmap_id
;
7546 if (FRAME_X_WINDOW (f
) == 0)
7549 /* Free up our existing icon bitmap and mask if any. */
7550 if (f
->output_data
.x
->icon_bitmap
> 0)
7551 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7552 f
->output_data
.x
->icon_bitmap
= 0;
7557 /* Use gtk_window_set_icon_from_file () if available,
7558 It's not restricted to bitmaps */
7559 if (xg_set_icon (f
, file
))
7561 #endif /* USE_GTK */
7562 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7563 x_create_bitmap_mask (f
, bitmap_id
);
7567 /* Create the GNU bitmap and mask if necessary. */
7568 if (FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7574 if (xg_set_icon (f
, xg_default_icon_file
)
7575 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7578 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7580 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7582 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7586 /* If all else fails, use the (black and white) xbm image. */
7589 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
7590 gnu_xbm_width
, gnu_xbm_height
);
7594 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7595 x_create_bitmap_mask (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7599 /* The first time we create the GNU bitmap and mask,
7600 this increments the ref-count one extra time.
7601 As a result, the GNU bitmap and mask are never freed.
7602 That way, we don't have to worry about allocating it again. */
7603 x_reference_bitmap (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7605 bitmap_id
= FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
;
7608 x_wm_set_icon_pixmap (f
, bitmap_id
);
7609 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7615 /* Make the x-window of frame F use a rectangle with text.
7616 Use ICON_NAME as the text. */
7619 x_text_icon (struct frame
*f
, const char *icon_name
)
7621 if (FRAME_X_WINDOW (f
) == 0)
7626 text
.value
= (unsigned char *) icon_name
;
7627 text
.encoding
= XA_STRING
;
7629 text
.nitems
= strlen (icon_name
);
7630 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7633 if (f
->output_data
.x
->icon_bitmap
> 0)
7634 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7635 f
->output_data
.x
->icon_bitmap
= 0;
7636 x_wm_set_icon_pixmap (f
, 0);
7641 #define X_ERROR_MESSAGE_SIZE 200
7643 /* If non-nil, this should be a string.
7644 It means catch X errors and store the error message in this string.
7646 The reason we use a stack is that x_catch_error/x_uncatch_error can
7647 be called from a signal handler.
7650 struct x_error_message_stack
{
7651 char string
[X_ERROR_MESSAGE_SIZE
];
7653 struct x_error_message_stack
*prev
;
7655 static struct x_error_message_stack
*x_error_message
;
7657 /* An X error handler which stores the error message in
7658 *x_error_message. This is called from x_error_handler if
7659 x_catch_errors is in effect. */
7662 x_error_catcher (Display
*display
, XErrorEvent
*event
)
7664 XGetErrorText (display
, event
->error_code
,
7665 x_error_message
->string
,
7666 X_ERROR_MESSAGE_SIZE
);
7669 /* Begin trapping X errors for display DPY. Actually we trap X errors
7670 for all displays, but DPY should be the display you are actually
7673 After calling this function, X protocol errors no longer cause
7674 Emacs to exit; instead, they are recorded in the string
7675 stored in *x_error_message.
7677 Calling x_check_errors signals an Emacs error if an X error has
7678 occurred since the last call to x_catch_errors or x_check_errors.
7680 Calling x_uncatch_errors resumes the normal error handling. */
7683 x_catch_errors (Display
*dpy
)
7685 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
7687 /* Make sure any errors from previous requests have been dealt with. */
7691 data
->string
[0] = 0;
7692 data
->prev
= x_error_message
;
7693 x_error_message
= data
;
7696 /* Undo the last x_catch_errors call.
7697 DPY should be the display that was passed to x_catch_errors. */
7700 x_uncatch_errors (void)
7702 struct x_error_message_stack
*tmp
;
7706 /* The display may have been closed before this function is called.
7707 Check if it is still open before calling XSync. */
7708 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7709 XSync (x_error_message
->dpy
, False
);
7711 tmp
= x_error_message
;
7712 x_error_message
= x_error_message
->prev
;
7717 /* If any X protocol errors have arrived since the last call to
7718 x_catch_errors or x_check_errors, signal an Emacs error using
7719 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7722 x_check_errors (Display
*dpy
, const char *format
)
7724 /* Make sure to catch any errors incurred so far. */
7727 if (x_error_message
->string
[0])
7729 char string
[X_ERROR_MESSAGE_SIZE
];
7730 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7731 x_uncatch_errors ();
7732 error (format
, string
);
7736 /* Nonzero if we had any X protocol errors
7737 since we did x_catch_errors on DPY. */
7740 x_had_errors_p (Display
*dpy
)
7742 /* Make sure to catch any errors incurred so far. */
7745 return x_error_message
->string
[0] != 0;
7748 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7751 x_clear_errors (Display
*dpy
)
7753 x_error_message
->string
[0] = 0;
7756 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7757 * idea. --lorentey */
7758 /* Close off all unclosed x_catch_errors calls. */
7761 x_fully_uncatch_errors (void)
7763 while (x_error_message
)
7764 x_uncatch_errors ();
7769 static unsigned int x_wire_count
;
7772 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7777 /************************************************************************
7779 ************************************************************************/
7781 /* Error message passed to x_connection_closed. */
7783 static char *error_msg
;
7785 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7786 the text of an error message that lead to the connection loss. */
7789 x_connection_closed (Display
*dpy
, const char *error_message
)
7791 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7792 Lisp_Object frame
, tail
;
7793 ptrdiff_t idx
= SPECPDL_INDEX ();
7795 error_msg
= alloca (strlen (error_message
) + 1);
7796 strcpy (error_msg
, error_message
);
7798 /* Inhibit redisplay while frames are being deleted. */
7799 specbind (Qinhibit_redisplay
, Qt
);
7803 /* Protect display from being closed when we delete the last
7805 dpyinfo
->reference_count
++;
7806 dpyinfo
->terminal
->reference_count
++;
7809 /* First delete frames whose mini-buffers are on frames
7810 that are on the dead display. */
7811 FOR_EACH_FRAME (tail
, frame
)
7813 Lisp_Object minibuf_frame
;
7815 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7816 if (FRAME_X_P (XFRAME (frame
))
7817 && FRAME_X_P (XFRAME (minibuf_frame
))
7818 && ! EQ (frame
, minibuf_frame
)
7819 && FRAME_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7820 delete_frame (frame
, Qnoelisp
);
7823 /* Now delete all remaining frames on the dead display.
7824 We are now sure none of these is used as the mini-buffer
7825 for another frame that we need to delete. */
7826 FOR_EACH_FRAME (tail
, frame
)
7827 if (FRAME_X_P (XFRAME (frame
))
7828 && FRAME_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7830 /* Set this to t so that delete_frame won't get confused
7831 trying to find a replacement. */
7832 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
7833 delete_frame (frame
, Qnoelisp
);
7836 /* If DPYINFO is null, this means we didn't open the display in the
7837 first place, so don't try to close it. */
7840 /* We can not call XtCloseDisplay here because it calls XSync.
7841 XSync inside the error handler apparently hangs Emacs. On
7842 current Xt versions, this isn't needed either. */
7844 /* A long-standing GTK bug prevents proper disconnect handling
7845 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
7846 the resulting Glib error message loop filled a user's disk.
7847 To avoid this, kill Emacs unconditionally on disconnect. */
7848 shut_down_emacs (0, Qnil
);
7849 fprintf (stderr
, "%s\n\
7850 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
7851 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
7852 For details, see etc/PROBLEMS.\n",
7855 #endif /* USE_GTK */
7857 /* Indicate that this display is dead. */
7858 dpyinfo
->display
= 0;
7860 dpyinfo
->reference_count
--;
7861 dpyinfo
->terminal
->reference_count
--;
7862 if (dpyinfo
->reference_count
!= 0)
7863 /* We have just closed all frames on this display. */
7868 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7869 Fdelete_terminal (tmp
, Qnoelisp
);
7873 if (terminal_list
== 0)
7875 fprintf (stderr
, "%s\n", error_msg
);
7876 Fkill_emacs (make_number (70));
7880 totally_unblock_input ();
7882 unbind_to (idx
, Qnil
);
7883 clear_waiting_for_input ();
7885 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
7886 IF_LINT (if (! terminal_list
) return; )
7888 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7889 longjmp), because returning from this function would get us back into
7890 Xlib's code which will directly call `exit'. */
7891 error ("%s", error_msg
);
7894 /* We specifically use it before defining it, so that gcc doesn't inline it,
7895 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7896 static void x_error_quitter (Display
*, XErrorEvent
*);
7898 /* This is the first-level handler for X protocol errors.
7899 It calls x_error_quitter or x_error_catcher. */
7902 x_error_handler (Display
*display
, XErrorEvent
*event
)
7904 #if defined USE_GTK && defined HAVE_GTK3
7905 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
7906 && event
->request_code
== X_SetInputFocus
)
7912 if (x_error_message
)
7913 x_error_catcher (display
, event
);
7915 x_error_quitter (display
, event
);
7919 /* This is the usual handler for X protocol errors.
7920 It kills all frames on the display that we got the error for.
7921 If that was the only one, it prints an error message and kills Emacs. */
7923 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7925 /* On older GCC versions, just putting x_error_quitter
7926 after x_error_handler prevents inlining into the former. */
7928 static void NO_INLINE
7929 x_error_quitter (Display
*display
, XErrorEvent
*event
)
7931 char buf
[256], buf1
[356];
7933 /* Ignore BadName errors. They can happen because of fonts
7934 or colors that are not defined. */
7936 if (event
->error_code
== BadName
)
7939 /* Note that there is no real way portable across R3/R4 to get the
7940 original error handler. */
7942 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
7943 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7944 buf
, event
->request_code
);
7945 x_connection_closed (display
, buf1
);
7949 /* This is the handler for X IO errors, always.
7950 It kills all frames on the display that we lost touch with.
7951 If that was the only one, it prints an error message and kills Emacs. */
7954 x_io_error_quitter (Display
*display
)
7958 snprintf (buf
, sizeof buf
, "Connection lost to X server `%s'",
7959 DisplayString (display
));
7960 x_connection_closed (display
, buf
);
7964 /* Changing the font of the frame. */
7966 /* Give frame F the font FONT-OBJECT as its default font. The return
7967 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7968 frame. If it is negative, generate a new fontset from
7972 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7974 struct font
*font
= XFONT_OBJECT (font_object
);
7977 fontset
= fontset_from_font (font_object
);
7978 FRAME_FONTSET (f
) = fontset
;
7979 if (FRAME_FONT (f
) == font
)
7980 /* This font is already set in frame F. There's nothing more to
7984 FRAME_FONT (f
) = font
;
7985 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7986 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7987 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7989 compute_fringe_widths (f
, 1);
7991 /* Compute the scroll bar width in character columns. */
7992 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7994 int wid
= FRAME_COLUMN_WIDTH (f
);
7995 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7996 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8000 int wid
= FRAME_COLUMN_WIDTH (f
);
8001 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8004 if (FRAME_X_WINDOW (f
) != 0)
8006 /* Don't change the size of a tip frame; there's no point in
8007 doing it because it's done in Fx_show_tip, and it leads to
8008 problems because the tip frame has no widget. */
8009 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8010 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8015 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8018 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
8027 /***********************************************************************
8029 ***********************************************************************/
8035 /* XIM destroy callback function, which is called whenever the
8036 connection to input method XIM dies. CLIENT_DATA contains a
8037 pointer to the x_display_info structure corresponding to XIM. */
8040 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
8042 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8043 Lisp_Object frame
, tail
;
8047 /* No need to call XDestroyIC.. */
8048 FOR_EACH_FRAME (tail
, frame
)
8050 struct frame
*f
= XFRAME (frame
);
8051 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
8053 FRAME_XIC (f
) = NULL
;
8054 xic_free_xfontset (f
);
8058 /* No need to call XCloseIM. */
8059 dpyinfo
->xim
= NULL
;
8060 XFree (dpyinfo
->xim_styles
);
8064 #endif /* HAVE_X11R6 */
8067 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8068 extern char *XSetIMValues (XIM
, ...);
8071 /* Open the connection to the XIM server on display DPYINFO.
8072 RESOURCE_NAME is the resource name Emacs uses. */
8075 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
8083 XCloseIM (dpyinfo
->xim
);
8084 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8091 XIMCallback destroy
;
8094 /* Get supported styles and XIM values. */
8095 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8098 destroy
.callback
= xim_destroy_callback
;
8099 destroy
.client_data
= (XPointer
)dpyinfo
;
8100 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8106 #endif /* HAVE_XIM */
8107 dpyinfo
->xim
= NULL
;
8111 #ifdef HAVE_X11R6_XIM
8113 /* XIM instantiate callback function, which is called whenever an XIM
8114 server is available. DISPLAY is the display of the XIM.
8115 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8116 when the callback was registered. */
8119 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
8121 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8122 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8124 /* We don't support multiple XIM connections. */
8128 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8130 /* Create XIC for the existing frames on the same display, as long
8131 as they have no XIC. */
8132 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8134 Lisp_Object tail
, frame
;
8137 FOR_EACH_FRAME (tail
, frame
)
8139 struct frame
*f
= XFRAME (frame
);
8142 && FRAME_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8143 if (FRAME_XIC (f
) == NULL
)
8145 create_frame_xic (f
);
8146 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8147 xic_set_statusarea (f
);
8148 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8150 struct window
*w
= XWINDOW (f
->selected_window
);
8151 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8160 #endif /* HAVE_X11R6_XIM */
8163 /* Open a connection to the XIM server on display DPYINFO.
8164 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8165 connection only at the first time. On X11R6, open the connection
8166 in the XIM instantiate callback function. */
8169 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
8171 dpyinfo
->xim
= NULL
;
8175 #ifdef HAVE_X11R6_XIM
8176 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
8178 dpyinfo
->xim_callback_data
= xim_inst
;
8179 xim_inst
->dpyinfo
= dpyinfo
;
8180 xim_inst
->resource_name
= xstrdup (resource_name
);
8181 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8182 resource_name
, emacs_class
,
8183 xim_instantiate_callback
,
8184 /* This is XPointer in XFree86
8185 but (XPointer *) on Tru64, at
8186 least, hence the configure test. */
8187 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8188 #else /* not HAVE_X11R6_XIM */
8189 xim_open_dpy (dpyinfo
, resource_name
);
8190 #endif /* not HAVE_X11R6_XIM */
8192 #endif /* HAVE_XIM */
8196 /* Close the connection to the XIM server on display DPYINFO. */
8199 xim_close_dpy (struct x_display_info
*dpyinfo
)
8204 #ifdef HAVE_X11R6_XIM
8205 if (dpyinfo
->display
)
8206 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8208 xim_instantiate_callback
, NULL
);
8209 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8210 xfree (dpyinfo
->xim_callback_data
);
8211 #endif /* HAVE_X11R6_XIM */
8212 if (dpyinfo
->display
)
8213 XCloseIM (dpyinfo
->xim
);
8214 dpyinfo
->xim
= NULL
;
8215 XFree (dpyinfo
->xim_styles
);
8217 #endif /* HAVE_XIM */
8220 #endif /* not HAVE_X11R6_XIM */
8224 /* Calculate the absolute position in frame F
8225 from its current recorded position values and gravity. */
8228 x_calc_absolute_position (struct frame
*f
)
8230 int flags
= f
->size_hint_flags
;
8232 /* We have nothing to do if the current position
8233 is already for the top-left corner. */
8234 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8237 /* Treat negative positions as relative to the leftmost bottommost
8238 position that fits on the screen. */
8239 if (flags
& XNegative
)
8240 f
->left_pos
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
8241 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8244 int height
= FRAME_PIXEL_HEIGHT (f
);
8246 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8247 /* Something is fishy here. When using Motif, starting Emacs with
8248 `-g -0-0', the frame appears too low by a few pixels.
8250 This seems to be so because initially, while Emacs is starting,
8251 the column widget's height and the frame's pixel height are
8252 different. The column widget's height is the right one. In
8253 later invocations, when Emacs is up, the frame's pixel height
8256 It's not obvious where the initial small difference comes from.
8257 2000-12-01, gerd. */
8259 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8262 if (flags
& YNegative
)
8263 f
->top_pos
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
8264 - height
+ f
->top_pos
;
8267 /* The left_pos and top_pos
8268 are now relative to the top and left screen edges,
8269 so the flags should correspond. */
8270 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8273 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8274 to really change the position, and 0 when calling from
8275 x_make_frame_visible (in that case, XOFF and YOFF are the current
8276 position values). It is -1 when calling from x_set_frame_parameters,
8277 which means, do adjust for borders but don't change the gravity. */
8280 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8282 int modified_top
, modified_left
;
8284 if (change_gravity
> 0)
8288 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8290 f
->size_hint_flags
|= XNegative
;
8292 f
->size_hint_flags
|= YNegative
;
8293 f
->win_gravity
= NorthWestGravity
;
8295 x_calc_absolute_position (f
);
8298 x_wm_set_size_hint (f
, (long) 0, 0);
8300 modified_left
= f
->left_pos
;
8301 modified_top
= f
->top_pos
;
8303 if (change_gravity
!= 0 && FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8305 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8306 than the WM decorations. So we use the calculated offset instead
8307 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8308 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8309 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8312 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8313 modified_left
, modified_top
);
8315 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8316 FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8319 /* change_gravity is non-zero when this function is called from Lisp to
8320 programmatically move a frame. In that case, we call
8321 x_check_expected_move to discover if we have a "Type A" or "Type B"
8322 window manager, and, for a "Type A" window manager, adjust the position
8325 We call x_check_expected_move if a programmatic move occurred, and
8326 either the window manager type (A/B) is unknown or it is Type A but we
8327 need to compute the top/left offset adjustment for this frame. */
8329 if (change_gravity
!= 0 &&
8330 (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8331 || (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8332 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8333 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8334 x_check_expected_move (f
, modified_left
, modified_top
);
8339 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8340 on the root window for frame F contains ATOMNAME.
8341 This is how a WM check shall be done according to the Window Manager
8342 Specification/Extended Window Manager Hints at
8343 http://freedesktop.org/wiki/Specifications/wm-spec. */
8346 wm_supports (struct frame
*f
, Atom want_atom
)
8349 unsigned long actual_size
, bytes_remaining
;
8350 int i
, rc
, actual_format
;
8351 Window wmcheck_window
;
8352 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8353 Window target_window
= dpyinfo
->root_window
;
8354 long max_len
= 65536;
8355 Display
*dpy
= FRAME_X_DISPLAY (f
);
8356 unsigned char *tmp_data
= NULL
;
8357 Atom target_type
= XA_WINDOW
;
8361 x_catch_errors (dpy
);
8362 rc
= XGetWindowProperty (dpy
, target_window
,
8363 dpyinfo
->Xatom_net_supporting_wm_check
,
8364 0, max_len
, False
, target_type
,
8365 &actual_type
, &actual_format
, &actual_size
,
8366 &bytes_remaining
, &tmp_data
);
8368 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8370 if (tmp_data
) XFree (tmp_data
);
8371 x_uncatch_errors ();
8376 wmcheck_window
= *(Window
*) tmp_data
;
8379 /* Check if window exists. */
8380 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8382 if (x_had_errors_p (dpy
))
8384 x_uncatch_errors ();
8389 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8391 /* Window changed, reload atoms */
8392 if (dpyinfo
->net_supported_atoms
!= NULL
)
8393 XFree (dpyinfo
->net_supported_atoms
);
8394 dpyinfo
->net_supported_atoms
= NULL
;
8395 dpyinfo
->nr_net_supported_atoms
= 0;
8396 dpyinfo
->net_supported_window
= 0;
8398 target_type
= XA_ATOM
;
8400 rc
= XGetWindowProperty (dpy
, target_window
,
8401 dpyinfo
->Xatom_net_supported
,
8402 0, max_len
, False
, target_type
,
8403 &actual_type
, &actual_format
, &actual_size
,
8404 &bytes_remaining
, &tmp_data
);
8406 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8408 if (tmp_data
) XFree (tmp_data
);
8409 x_uncatch_errors ();
8414 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8415 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8416 dpyinfo
->net_supported_window
= wmcheck_window
;
8421 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8422 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8424 x_uncatch_errors ();
8431 set_wm_state (Lisp_Object frame
, int add
, Atom atom
, Atom value
)
8433 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (XFRAME (frame
));
8435 x_send_client_event (frame
, make_number (0), frame
,
8436 dpyinfo
->Xatom_net_wm_state
,
8438 /* 1 = add, 0 = remove */
8440 (make_number (add
? 1 : 0),
8442 (make_fixnum_or_float (atom
),
8444 ? list1 (make_fixnum_or_float (value
))
8449 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8452 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8454 XSETFRAME (frame
, f
);
8456 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8457 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
8460 /* Return the current _NET_WM_STATE.
8461 SIZE_STATE is set to one of the FULLSCREEN_* values.
8462 STICKY is set to 1 if the sticky state is set, 0 if not.
8464 Return non-zero if we are not hidden, zero if we are. */
8467 get_current_wm_state (struct frame
*f
,
8473 unsigned long actual_size
, bytes_remaining
;
8474 int i
, rc
, actual_format
, is_hidden
= 0;
8475 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8476 long max_len
= 65536;
8477 Display
*dpy
= FRAME_X_DISPLAY (f
);
8478 unsigned char *tmp_data
= NULL
;
8479 Atom target_type
= XA_ATOM
;
8482 *size_state
= FULLSCREEN_NONE
;
8485 x_catch_errors (dpy
);
8486 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
8487 0, max_len
, False
, target_type
,
8488 &actual_type
, &actual_format
, &actual_size
,
8489 &bytes_remaining
, &tmp_data
);
8491 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8493 if (tmp_data
) XFree (tmp_data
);
8494 x_uncatch_errors ();
8496 return !FRAME_ICONIFIED_P (f
);
8499 x_uncatch_errors ();
8501 for (i
= 0; i
< actual_size
; ++i
)
8503 Atom a
= ((Atom
*)tmp_data
)[i
];
8504 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
8507 f
->output_data
.x
->net_wm_state_hidden_seen
= 1;
8509 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8511 if (*size_state
== FULLSCREEN_HEIGHT
)
8512 *size_state
= FULLSCREEN_MAXIMIZED
;
8514 *size_state
= FULLSCREEN_WIDTH
;
8516 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8518 if (*size_state
== FULLSCREEN_WIDTH
)
8519 *size_state
= FULLSCREEN_MAXIMIZED
;
8521 *size_state
= FULLSCREEN_HEIGHT
;
8523 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
8524 *size_state
= FULLSCREEN_BOTH
;
8525 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8529 if (tmp_data
) XFree (tmp_data
);
8534 /* Do fullscreen as specified in extended window manager hints */
8537 do_ewmh_fullscreen (struct frame
*f
)
8539 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8540 int have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
8543 (void)get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
8545 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8546 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8548 have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
8550 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
8554 XSETFRAME (frame
, f
);
8556 /* Keep number of calls to set_wm_state as low as possible.
8557 Some window managers, or possible Gtk+, hangs when too many
8558 are sent at once. */
8559 switch (f
->want_fullscreen
)
8561 case FULLSCREEN_BOTH
:
8562 if (cur
== FULLSCREEN_WIDTH
|| cur
== FULLSCREEN_MAXIMIZED
8563 || cur
== FULLSCREEN_HEIGHT
)
8564 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8565 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8566 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8568 case FULLSCREEN_WIDTH
:
8569 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
8570 || cur
== FULLSCREEN_MAXIMIZED
)
8571 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8572 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8573 if (cur
!= FULLSCREEN_MAXIMIZED
)
8574 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
8576 case FULLSCREEN_HEIGHT
:
8577 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
8578 || cur
== FULLSCREEN_MAXIMIZED
)
8579 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8580 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
8581 if (cur
!= FULLSCREEN_MAXIMIZED
)
8582 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
8584 case FULLSCREEN_MAXIMIZED
:
8585 if (cur
== FULLSCREEN_BOTH
)
8586 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8587 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8588 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8590 case FULLSCREEN_NONE
:
8591 if (cur
== FULLSCREEN_BOTH
)
8592 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8594 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8595 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8598 f
->want_fullscreen
= FULLSCREEN_NONE
;
8602 return have_net_atom
;
8606 XTfullscreen_hook (struct frame
*f
)
8608 if (FRAME_VISIBLE_P (f
))
8611 x_check_fullscreen (f
);
8619 x_handle_net_wm_state (struct frame
*f
, XPropertyEvent
*event
)
8621 int value
= FULLSCREEN_NONE
;
8624 int not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
8629 case FULLSCREEN_WIDTH
:
8632 case FULLSCREEN_HEIGHT
:
8635 case FULLSCREEN_BOTH
:
8638 case FULLSCREEN_MAXIMIZED
:
8643 store_frame_param (f
, Qfullscreen
, lval
);
8644 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8649 /* Check if we need to resize the frame due to a fullscreen request.
8650 If so needed, resize the frame. */
8652 x_check_fullscreen (struct frame
*f
)
8654 if (do_ewmh_fullscreen (f
))
8657 if (f
->output_data
.x
->parent_desc
!= FRAME_DISPLAY_INFO (f
)->root_window
)
8658 return; /* Only fullscreen without WM or with EWM hints (above). */
8660 /* Setting fullscreen to nil doesn't do anything. We could save the
8661 last non-fullscreen size and restore it, but it seems like a
8662 lot of work for this unusual case (no window manager running). */
8664 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8666 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
8667 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8669 switch (f
->want_fullscreen
)
8671 /* No difference between these two when there is no WM */
8672 case FULLSCREEN_BOTH
:
8673 case FULLSCREEN_MAXIMIZED
:
8674 width
= x_display_pixel_width (dpyinfo
);
8675 height
= x_display_pixel_height (dpyinfo
);
8677 case FULLSCREEN_WIDTH
:
8678 width
= x_display_pixel_width (dpyinfo
);
8680 case FULLSCREEN_HEIGHT
:
8681 height
= x_display_pixel_height (dpyinfo
);
8684 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8689 /* This function is called by x_set_offset to determine whether the window
8690 manager interfered with the positioning of the frame. Type A window
8691 managers position the surrounding window manager decorations a small
8692 amount above and left of the user-supplied position. Type B window
8693 managers position the surrounding window manager decorations at the
8694 user-specified position. If we detect a Type A window manager, we
8695 compensate by moving the window right and down by the proper amount. */
8698 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8700 int current_left
= 0, current_top
= 0;
8702 /* x_real_positions returns the left and top offsets of the outermost
8703 window manager window around the frame. */
8705 x_real_positions (f
, ¤t_left
, ¤t_top
);
8707 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8709 /* It's a "Type A" window manager. */
8714 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8715 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8716 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8718 /* Now fix the mispositioned frame's location. */
8720 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8721 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8723 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8724 adjusted_left
, adjusted_top
);
8726 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8729 /* It's a "Type B" window manager. We don't have to adjust the
8730 frame's position. */
8732 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8736 /* Wait for XGetGeometry to return up-to-date position information for a
8737 recently-moved frame. Call this immediately after calling XMoveWindow.
8738 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8739 frame has been moved to, so we use a fuzzy position comparison instead
8740 of an exact comparison. */
8743 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8747 while (count
++ < 50)
8749 int current_left
= 0, current_top
= 0;
8751 /* In theory, this call to XSync only needs to happen once, but in
8752 practice, it doesn't seem to work, hence the need for the surrounding
8755 XSync (FRAME_X_DISPLAY (f
), False
);
8756 x_real_positions (f
, ¤t_left
, ¤t_top
);
8760 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8763 if (eabs (current_left
- left
) <= 10
8764 && eabs (current_top
- top
) <= 40)
8767 else if (current_left
== left
&& current_top
== top
)
8771 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8772 will then return up-to-date position info. */
8774 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8778 /* Wait for an event on frame F matching EVENTTYPE. */
8780 x_wait_for_event (struct frame
*f
, int eventtype
)
8782 int level
= interrupt_input_blocked
;
8785 struct timespec tmo
, tmo_at
, time_now
;
8786 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8788 pending_event_wait
.f
= f
;
8789 pending_event_wait
.eventtype
= eventtype
;
8791 /* Set timeout to 0.1 second. Hopefully not noticeable.
8792 Maybe it should be configurable. */
8793 tmo
= make_timespec (0, 100 * 1000 * 1000);
8794 tmo_at
= timespec_add (current_timespec (), tmo
);
8796 while (pending_event_wait
.eventtype
)
8798 pending_signals
= 1;
8799 totally_unblock_input ();
8800 /* XTread_socket is called after unblock. */
8802 interrupt_input_blocked
= level
;
8807 time_now
= current_timespec ();
8808 if (timespec_cmp (tmo_at
, time_now
) < 0)
8811 tmo
= timespec_sub (tmo_at
, time_now
);
8812 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
8813 break; /* Timeout */
8815 pending_event_wait
.f
= 0;
8816 pending_event_wait
.eventtype
= 0;
8820 /* Change the size of frame F's X window to COLS/ROWS in the case F
8821 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8822 top-left-corner window gravity for this size change and subsequent
8823 size changes. Otherwise we leave the window gravity unchanged. */
8826 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8828 int pixelwidth
, pixelheight
;
8830 check_frame_size (f
, &rows
, &cols
);
8831 f
->scroll_bar_actual_width
8832 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8834 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8836 compute_fringe_widths (f
, 0);
8838 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8839 + FRAME_TOOLBAR_WIDTH (f
);
8840 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8841 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8843 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8844 x_wm_set_size_hint (f
, (long) 0, 0);
8845 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8846 pixelwidth
, pixelheight
);
8849 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8850 receive in the ConfigureNotify event; if we get what we asked
8851 for, then the event won't cause the screen to become garbaged, so
8852 we have to make sure to do it here. */
8853 SET_FRAME_GARBAGED (f
);
8855 /* Now, strictly speaking, we can't be sure that this is accurate,
8856 but the window manager will get around to dealing with the size
8857 change request eventually, and we'll hear how it went when the
8858 ConfigureNotify event gets here.
8860 We could just not bother storing any of this information here,
8861 and let the ConfigureNotify event set everything up, but that
8862 might be kind of confusing to the Lisp code, since size changes
8863 wouldn't be reported in the frame parameters until some random
8864 point in the future when the ConfigureNotify event arrives.
8866 We pass 1 for DELAY since we can't run Lisp code inside of
8869 /* But the ConfigureNotify may in fact never arrive, and then this is
8870 not right if the frame is visible. Instead wait (with timeout)
8871 for the ConfigureNotify. */
8872 if (FRAME_VISIBLE_P (f
))
8873 x_wait_for_event (f
, ConfigureNotify
);
8876 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8877 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8878 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8884 /* Call this to change the size of frame F's x-window.
8885 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8886 for this size change and subsequent size changes.
8887 Otherwise we leave the window gravity unchanged. */
8890 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8894 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8898 /* When the frame is maximized/fullscreen or running under for
8899 example Xmonad, x_set_window_size_1 will be a no-op.
8900 In that case, the right thing to do is extend rows/cols to
8901 the current frame size. We do that first if x_set_window_size_1
8902 turns out to not be a no-op (there is no way to know).
8903 The size will be adjusted again if the frame gets a
8904 ConfigureNotify event as a result of x_set_window_size. */
8905 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8906 #ifdef USE_X_TOOLKIT
8907 /* The menu bar is not part of text lines. The tool bar
8909 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8911 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8912 /* Update f->scroll_bar_actual_width because it is used in
8913 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8914 f
->scroll_bar_actual_width
8915 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8916 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8917 change_frame_size (f
, r
, c
, 0, 1, 0);
8921 if (FRAME_GTK_WIDGET (f
))
8922 xg_frame_set_char_size (f
, cols
, rows
);
8924 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8925 #else /* not USE_GTK */
8927 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8929 #endif /* not USE_GTK */
8931 /* If cursor was outside the new size, mark it as off. */
8932 mark_window_cursors_off (XWINDOW (f
->root_window
));
8934 /* Clear out any recollection of where the mouse highlighting was,
8935 since it might be in a place that's outside the new frame size.
8936 Actually checking whether it is outside is a pain in the neck,
8937 so don't try--just let the highlighting be done afresh with new size. */
8938 cancel_mouse_face (f
);
8943 /* Mouse warping. */
8946 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8950 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8951 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8953 if (pix_x
< 0) pix_x
= 0;
8954 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8956 if (pix_y
< 0) pix_y
= 0;
8957 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8961 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8962 0, 0, 0, 0, pix_x
, pix_y
);
8966 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8969 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8973 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8974 0, 0, 0, 0, pix_x
, pix_y
);
8978 /* Raise frame F. */
8981 x_raise_frame (struct frame
*f
)
8984 if (FRAME_VISIBLE_P (f
))
8985 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8986 XFlush (FRAME_X_DISPLAY (f
));
8990 /* Lower frame F. */
8993 x_lower_frame (struct frame
*f
)
8995 if (FRAME_VISIBLE_P (f
))
8998 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8999 XFlush (FRAME_X_DISPLAY (f
));
9004 /* Request focus with XEmbed */
9007 xembed_request_focus (struct frame
*f
)
9009 /* See XEmbed Protocol Specification at
9010 http://freedesktop.org/wiki/Specifications/xembed-spec */
9011 if (FRAME_VISIBLE_P (f
))
9012 xembed_send_message (f
, CurrentTime
,
9013 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
9016 /* Activate frame with Extended Window Manager Hints */
9019 x_ewmh_activate_frame (struct frame
*f
)
9021 /* See Window Manager Specification/Extended Window Manager Hints at
9022 http://freedesktop.org/wiki/Specifications/wm-spec */
9024 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9026 if (FRAME_VISIBLE_P (f
) && wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
9029 XSETFRAME (frame
, f
);
9030 x_send_client_event (frame
, make_number (0), frame
,
9031 dpyinfo
->Xatom_net_active_window
,
9033 list2i (1, dpyinfo
->last_user_time
));
9038 XTframe_raise_lower (struct frame
*f
, int raise_flag
)
9046 /* XEmbed implementation. */
9048 #if defined USE_X_TOOLKIT || ! defined USE_GTK
9050 /* XEmbed implementation. */
9052 #define XEMBED_VERSION 0
9055 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
9057 unsigned long data
[2];
9058 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9060 data
[0] = XEMBED_VERSION
;
9063 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9064 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
9065 32, PropModeReplace
, (unsigned char *) data
, 2);
9067 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
9070 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
9071 long int detail
, long int data1
, long int data2
)
9075 event
.xclient
.type
= ClientMessage
;
9076 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9077 event
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9078 event
.xclient
.format
= 32;
9079 event
.xclient
.data
.l
[0] = t
;
9080 event
.xclient
.data
.l
[1] = msg
;
9081 event
.xclient
.data
.l
[2] = detail
;
9082 event
.xclient
.data
.l
[3] = data1
;
9083 event
.xclient
.data
.l
[4] = data2
;
9085 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9086 False
, NoEventMask
, &event
);
9087 XSync (FRAME_X_DISPLAY (f
), False
);
9090 /* Change of visibility. */
9092 /* This tries to wait until the frame is really visible.
9093 However, if the window manager asks the user where to position
9094 the frame, this will return before the user finishes doing that.
9095 The frame will not actually be visible at that time,
9096 but it will become visible later when the window manager
9097 finishes with it. */
9100 x_make_frame_visible (struct frame
*f
)
9103 int original_top
, original_left
;
9104 int retry_count
= 2;
9110 type
= x_icon_type (f
);
9112 x_bitmap_icon (f
, type
);
9114 if (! FRAME_VISIBLE_P (f
))
9116 /* We test FRAME_GARBAGED_P here to make sure we don't
9117 call x_set_offset a second time
9118 if we get to x_make_frame_visible a second time
9119 before the window gets really visible. */
9120 if (! FRAME_ICONIFIED_P (f
)
9121 && ! FRAME_X_EMBEDDED_P (f
)
9122 && ! f
->output_data
.x
->asked_for_visible
)
9123 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9125 f
->output_data
.x
->asked_for_visible
= 1;
9127 if (! EQ (Vx_no_window_manager
, Qt
))
9128 x_wm_set_window_state (f
, NormalState
);
9129 #ifdef USE_X_TOOLKIT
9130 if (FRAME_X_EMBEDDED_P (f
))
9131 xembed_set_info (f
, XEMBED_MAPPED
);
9134 /* This was XtPopup, but that did nothing for an iconified frame. */
9135 XtMapWidget (f
->output_data
.x
->widget
);
9137 #else /* not USE_X_TOOLKIT */
9139 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9140 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9142 if (FRAME_X_EMBEDDED_P (f
))
9143 xembed_set_info (f
, XEMBED_MAPPED
);
9145 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9146 #endif /* not USE_GTK */
9147 #endif /* not USE_X_TOOLKIT */
9150 XFlush (FRAME_X_DISPLAY (f
));
9152 /* Synchronize to ensure Emacs knows the frame is visible
9153 before we do anything else. We do this loop with input not blocked
9154 so that incoming events are handled. */
9158 /* This must be before UNBLOCK_INPUT
9159 since events that arrive in response to the actions above
9160 will set it when they are handled. */
9161 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9163 original_left
= f
->left_pos
;
9164 original_top
= f
->top_pos
;
9166 /* This must come after we set COUNT. */
9169 /* We unblock here so that arriving X events are processed. */
9171 /* Now move the window back to where it was "supposed to be".
9172 But don't do it if the gravity is negative.
9173 When the gravity is negative, this uses a position
9174 that is 3 pixels too low. Perhaps that's really the border width.
9176 Don't do this if the window has never been visible before,
9177 because the window manager may choose the position
9178 and we don't want to override it. */
9180 if (! FRAME_VISIBLE_P (f
)
9181 && ! FRAME_ICONIFIED_P (f
)
9182 && ! FRAME_X_EMBEDDED_P (f
)
9183 && f
->win_gravity
== NorthWestGravity
9184 && previously_visible
)
9188 unsigned int width
, height
, border
, depth
;
9192 /* On some window managers (such as FVWM) moving an existing
9193 window, even to the same place, causes the window manager
9194 to introduce an offset. This can cause the window to move
9195 to an unexpected location. Check the geometry (a little
9196 slow here) and then verify that the window is in the right
9197 place. If the window is not in the right place, move it
9198 there, and take the potential window manager hit. */
9199 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9200 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9202 if (original_left
!= x
|| original_top
!= y
)
9203 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9204 original_left
, original_top
);
9209 XSETFRAME (frame
, f
);
9211 /* Wait until the frame is visible. Process X events until a
9212 MapNotify event has been seen, or until we think we won't get a
9213 MapNotify at all.. */
9214 for (count
= input_signal_count
+ 10;
9215 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9217 /* Force processing of queued events. */
9220 /* Machines that do polling rather than SIGIO have been
9221 observed to go into a busy-wait here. So we'll fake an
9222 alarm signal to let the handler know that there's something
9223 to be read. We used to raise a real alarm, but it seems
9224 that the handler isn't always enabled here. This is
9226 if (input_polling_used ())
9228 /* It could be confusing if a real alarm arrives while
9229 processing the fake one. Turn it off and let the
9230 handler reset it. */
9231 int old_poll_suppress_count
= poll_suppress_count
;
9232 poll_suppress_count
= 1;
9233 poll_for_input_1 ();
9234 poll_suppress_count
= old_poll_suppress_count
;
9240 (let ((f (selected-frame)))
9244 the frame is not raised with various window managers on
9245 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9246 unknown reason, the call to XtMapWidget is completely ignored.
9247 Mapping the widget a second time works. */
9249 if (!FRAME_VISIBLE_P (f
) && --retry_count
!= 0)
9254 /* Change from mapped state to withdrawn state. */
9256 /* Make the frame visible (mapped and not iconified). */
9259 x_make_frame_invisible (struct frame
*f
)
9263 /* Use the frame's outermost window, not the one we normally draw on. */
9264 window
= FRAME_OUTER_WINDOW (f
);
9266 /* Don't keep the highlight on an invisible frame. */
9267 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9268 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9272 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9273 that the current position of the window is user-specified, rather than
9274 program-specified, so that when the window is mapped again, it will be
9275 placed at the same location, without forcing the user to position it
9276 by hand again (they have already done that once for this window.) */
9277 x_wm_set_size_hint (f
, (long) 0, 1);
9280 if (FRAME_GTK_OUTER_WIDGET (f
))
9281 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9284 if (FRAME_X_EMBEDDED_P (f
))
9285 xembed_set_info (f
, 0);
9290 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9291 DefaultScreen (FRAME_X_DISPLAY (f
))))
9294 error ("Can't notify window manager of window withdrawal");
9298 /* We can't distinguish this from iconification
9299 just by the event that we get from the server.
9300 So we can't win using the usual strategy of letting
9301 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9302 and synchronize with the server to make sure we agree. */
9303 SET_FRAME_VISIBLE (f
, 0);
9304 SET_FRAME_ICONIFIED (f
, 0);
9311 /* Change window state from mapped to iconified. */
9314 x_iconify_frame (struct frame
*f
)
9316 #ifdef USE_X_TOOLKIT
9321 /* Don't keep the highlight on an invisible frame. */
9322 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9323 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9325 if (FRAME_ICONIFIED_P (f
))
9330 type
= x_icon_type (f
);
9332 x_bitmap_icon (f
, type
);
9334 #if defined (USE_GTK)
9335 if (FRAME_GTK_OUTER_WIDGET (f
))
9337 if (! FRAME_VISIBLE_P (f
))
9338 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9340 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9341 SET_FRAME_VISIBLE (f
, 0);
9342 SET_FRAME_ICONIFIED (f
, 1);
9348 #ifdef USE_X_TOOLKIT
9350 if (! FRAME_VISIBLE_P (f
))
9352 if (! EQ (Vx_no_window_manager
, Qt
))
9353 x_wm_set_window_state (f
, IconicState
);
9354 /* This was XtPopup, but that did nothing for an iconified frame. */
9355 XtMapWidget (f
->output_data
.x
->widget
);
9356 /* The server won't give us any event to indicate
9357 that an invisible frame was changed to an icon,
9358 so we have to record it here. */
9359 SET_FRAME_VISIBLE (f
, 0);
9360 SET_FRAME_ICONIFIED (f
, 1);
9365 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9366 XtWindow (f
->output_data
.x
->widget
),
9367 DefaultScreen (FRAME_X_DISPLAY (f
)));
9371 error ("Can't notify window manager of iconification");
9373 SET_FRAME_ICONIFIED (f
, 1);
9374 SET_FRAME_VISIBLE (f
, 0);
9377 XFlush (FRAME_X_DISPLAY (f
));
9379 #else /* not USE_X_TOOLKIT */
9381 /* Make sure the X server knows where the window should be positioned,
9382 in case the user deiconifies with the window manager. */
9383 if (! FRAME_VISIBLE_P (f
)
9384 && ! FRAME_ICONIFIED_P (f
)
9385 && ! FRAME_X_EMBEDDED_P (f
))
9386 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9388 /* Since we don't know which revision of X we're running, we'll use both
9389 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9391 /* X11R4: send a ClientMessage to the window manager using the
9392 WM_CHANGE_STATE type. */
9396 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
9397 msg
.xclient
.type
= ClientMessage
;
9398 msg
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9399 msg
.xclient
.format
= 32;
9400 msg
.xclient
.data
.l
[0] = IconicState
;
9402 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9403 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9405 SubstructureRedirectMask
| SubstructureNotifyMask
,
9409 error ("Can't notify window manager of iconification");
9413 /* X11R3: set the initial_state field of the window manager hints to
9415 x_wm_set_window_state (f
, IconicState
);
9417 if (!FRAME_VISIBLE_P (f
))
9419 /* If the frame was withdrawn, before, we must map it. */
9420 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9423 SET_FRAME_ICONIFIED (f
, 1);
9424 SET_FRAME_VISIBLE (f
, 0);
9426 XFlush (FRAME_X_DISPLAY (f
));
9428 #endif /* not USE_X_TOOLKIT */
9432 /* Free X resources of frame F. */
9435 x_free_frame_resources (struct frame
*f
)
9437 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9438 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
9439 #ifdef USE_X_TOOLKIT
9441 struct scroll_bar
*b
;
9446 /* If a display connection is dead, don't try sending more
9447 commands to the X server. */
9448 if (dpyinfo
->display
)
9450 /* We must free faces before destroying windows because some
9451 font-driver (e.g. xft) access a window while finishing a
9453 if (FRAME_FACE_CACHE (f
))
9454 free_frame_faces (f
);
9456 if (f
->output_data
.x
->icon_desc
)
9457 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9459 #ifdef USE_X_TOOLKIT
9460 /* Explicitly destroy the scroll bars of the frame. Without
9461 this, we get "BadDrawable" errors from the toolkit later on,
9462 presumably from expose events generated for the disappearing
9463 toolkit scroll bars. */
9464 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9466 b
= XSCROLL_BAR (bar
);
9467 x_scroll_bar_remove (b
);
9476 #ifdef USE_X_TOOLKIT
9477 if (f
->output_data
.x
->widget
)
9479 XtDestroyWidget (f
->output_data
.x
->widget
);
9480 f
->output_data
.x
->widget
= NULL
;
9482 /* Tooltips don't have widgets, only a simple X window, even if
9483 we are using a toolkit. */
9484 else if (FRAME_X_WINDOW (f
))
9485 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9487 free_frame_menubar (f
);
9488 #else /* !USE_X_TOOLKIT */
9491 xg_free_frame_widgets (f
);
9492 #endif /* USE_GTK */
9494 if (FRAME_X_WINDOW (f
))
9495 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9496 #endif /* !USE_X_TOOLKIT */
9498 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9499 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9500 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9501 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9502 unload_color (f
, f
->output_data
.x
->border_pixel
);
9503 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9505 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9506 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9507 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9508 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9509 #ifdef USE_TOOLKIT_SCROLL_BARS
9510 /* Scrollbar shadow colors. */
9511 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9512 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9513 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9514 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9515 #endif /* USE_TOOLKIT_SCROLL_BARS */
9516 if (f
->output_data
.x
->white_relief
.allocated_p
)
9517 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9518 if (f
->output_data
.x
->black_relief
.allocated_p
)
9519 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9523 /* Free extra GCs allocated by x_setup_relief_colors. */
9524 if (f
->output_data
.x
->white_relief
.gc
)
9526 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
9527 f
->output_data
.x
->white_relief
.gc
= 0;
9529 if (f
->output_data
.x
->black_relief
.gc
)
9531 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
9532 f
->output_data
.x
->black_relief
.gc
= 0;
9535 XFlush (FRAME_X_DISPLAY (f
));
9538 xfree (f
->output_data
.x
->saved_menu_event
);
9539 xfree (f
->output_data
.x
);
9540 f
->output_data
.x
= NULL
;
9542 if (f
== dpyinfo
->x_focus_frame
)
9543 dpyinfo
->x_focus_frame
= 0;
9544 if (f
== dpyinfo
->x_focus_event_frame
)
9545 dpyinfo
->x_focus_event_frame
= 0;
9546 if (f
== dpyinfo
->x_highlight_frame
)
9547 dpyinfo
->x_highlight_frame
= 0;
9548 if (f
== hlinfo
->mouse_face_mouse_frame
)
9549 reset_mouse_highlight (hlinfo
);
9555 /* Destroy the X window of frame F. */
9558 x_destroy_window (struct frame
*f
)
9560 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9562 /* If a display connection is dead, don't try sending more
9563 commands to the X server. */
9564 if (dpyinfo
->display
!= 0)
9565 x_free_frame_resources (f
);
9567 dpyinfo
->reference_count
--;
9571 /* Setting window manager hints. */
9573 /* Set the normal size hints for the window manager, for frame F.
9574 FLAGS is the flags word to use--or 0 meaning preserve the flags
9575 that the window now has.
9576 If USER_POSITION, set the USPosition
9577 flag (this is useful when FLAGS is 0).
9578 The GTK version is in gtkutils.c. */
9582 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
9584 XSizeHints size_hints
;
9585 Window window
= FRAME_OUTER_WINDOW (f
);
9587 #ifdef USE_X_TOOLKIT
9588 if (f
->output_data
.x
->widget
)
9590 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
9595 /* Setting PMaxSize caused various problems. */
9596 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9598 size_hints
.x
= f
->left_pos
;
9599 size_hints
.y
= f
->top_pos
;
9601 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9602 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9604 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9605 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9606 size_hints
.max_width
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
9607 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9608 size_hints
.max_height
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
9609 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9611 /* Calculate the base and minimum sizes. */
9613 int base_width
, base_height
;
9614 int min_rows
= 0, min_cols
= 0;
9616 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9617 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9619 check_frame_size (f
, &min_rows
, &min_cols
);
9621 /* The window manager uses the base width hints to calculate the
9622 current number of rows and columns in the frame while
9623 resizing; min_width and min_height aren't useful for this
9624 purpose, since they might not give the dimensions for a
9625 zero-row, zero-column frame.
9627 We use the base_width and base_height members if we have
9628 them; otherwise, we set the min_width and min_height members
9629 to the size for a zero x zero frame. */
9631 size_hints
.flags
|= PBaseSize
;
9632 size_hints
.base_width
= base_width
;
9633 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9634 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9635 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9638 /* If we don't need the old flags, we don't need the old hint at all. */
9641 size_hints
.flags
|= flags
;
9646 XSizeHints hints
; /* Sometimes I hate X Windows... */
9647 long supplied_return
;
9650 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9654 size_hints
.flags
|= flags
;
9659 if (hints
.flags
& PSize
)
9660 size_hints
.flags
|= PSize
;
9661 if (hints
.flags
& PPosition
)
9662 size_hints
.flags
|= PPosition
;
9663 if (hints
.flags
& USPosition
)
9664 size_hints
.flags
|= USPosition
;
9665 if (hints
.flags
& USSize
)
9666 size_hints
.flags
|= USSize
;
9673 size_hints
.win_gravity
= f
->win_gravity
;
9674 size_hints
.flags
|= PWinGravity
;
9678 size_hints
.flags
&= ~ PPosition
;
9679 size_hints
.flags
|= USPosition
;
9681 #endif /* PWinGravity */
9683 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9685 #endif /* not USE_GTK */
9687 /* Used for IconicState or NormalState */
9690 x_wm_set_window_state (struct frame
*f
, int state
)
9692 #ifdef USE_X_TOOLKIT
9695 XtSetArg (al
[0], XtNinitialState
, state
);
9696 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9697 #else /* not USE_X_TOOLKIT */
9698 Window window
= FRAME_X_WINDOW (f
);
9700 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9701 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9703 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9704 #endif /* not USE_X_TOOLKIT */
9708 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
9710 Pixmap icon_pixmap
, icon_mask
;
9712 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9713 Window window
= FRAME_OUTER_WINDOW (f
);
9718 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9719 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9720 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9721 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9725 /* It seems there is no way to turn off use of an icon
9733 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9737 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9741 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9742 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9743 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9744 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9747 #else /* not USE_X_TOOLKIT && not USE_GTK */
9749 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9750 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9752 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9756 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9758 Window window
= FRAME_OUTER_WINDOW (f
);
9760 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9761 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9762 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9764 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9768 /***********************************************************************
9770 ***********************************************************************/
9774 /* Check that FONT is valid on frame F. It is if it can be found in F's
9778 x_check_font (struct frame
*f
, struct font
*font
)
9780 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9781 if (font
->driver
->check
)
9782 eassert (font
->driver
->check (f
, font
) == 0);
9785 #endif /* GLYPH_DEBUG */
9788 /***********************************************************************
9790 ***********************************************************************/
9792 #ifdef USE_X_TOOLKIT
9793 static XrmOptionDescRec emacs_options
[] = {
9794 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9795 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9797 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9798 XrmoptionSepArg
, NULL
},
9799 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9801 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9802 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9803 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9804 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9805 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9806 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9807 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9810 /* Whether atimer for Xt timeouts is activated or not. */
9812 static int x_timeout_atimer_activated_flag
;
9814 #endif /* USE_X_TOOLKIT */
9816 static int x_initialized
;
9818 /* Test whether two display-name strings agree up to the dot that separates
9819 the screen number from the server number. */
9821 same_x_server (const char *name1
, const char *name2
)
9824 const char *system_name
= SSDATA (Vsystem_name
);
9825 ptrdiff_t system_name_length
= SBYTES (Vsystem_name
);
9826 ptrdiff_t length_until_period
= 0;
9828 while (system_name
[length_until_period
] != 0
9829 && system_name
[length_until_period
] != '.')
9830 length_until_period
++;
9832 /* Treat `unix' like an empty host name. */
9833 if (! strncmp (name1
, "unix:", 5))
9835 if (! strncmp (name2
, "unix:", 5))
9837 /* Treat this host's name like an empty host name. */
9838 if (! strncmp (name1
, system_name
, system_name_length
)
9839 && name1
[system_name_length
] == ':')
9840 name1
+= system_name_length
;
9841 if (! strncmp (name2
, system_name
, system_name_length
)
9842 && name2
[system_name_length
] == ':')
9843 name2
+= system_name_length
;
9844 /* Treat this host's domainless name like an empty host name. */
9845 if (! strncmp (name1
, system_name
, length_until_period
)
9846 && name1
[length_until_period
] == ':')
9847 name1
+= length_until_period
;
9848 if (! strncmp (name2
, system_name
, length_until_period
)
9849 && name2
[length_until_period
] == ':')
9850 name2
+= length_until_period
;
9852 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9856 if (seen_colon
&& *name1
== '.')
9860 && (*name1
== '.' || *name1
== '\0')
9861 && (*name2
== '.' || *name2
== '\0'));
9864 /* Count number of set bits in mask and number of bits to shift to
9865 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9868 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9889 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9890 But don't permanently open it, just test its availability. */
9893 x_display_ok (const char *display
)
9895 Display
*dpy
= XOpenDisplay (display
);
9896 return dpy
? (XCloseDisplay (dpy
), 1) : 0;
9901 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
9902 const gchar
*msg
, gpointer user_data
)
9904 if (!strstr (msg
, "g_set_prgname"))
9905 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
9909 /* Open a connection to X display DISPLAY_NAME, and return
9910 the structure that describes the open display.
9911 If we cannot contact the display, return null. */
9913 struct x_display_info
*
9914 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9918 struct terminal
*terminal
;
9919 struct x_display_info
*dpyinfo
;
9931 if (! x_display_ok (SSDATA (display_name
)))
9932 error ("Display %s can't be opened", SSDATA (display_name
));
9938 char *argv
[NUM_ARGV
];
9939 char **argv2
= argv
;
9942 if (x_initialized
++ > 1)
9944 xg_display_open (SSDATA (display_name
), &dpy
);
9948 static char display_opt
[] = "--display";
9949 static char name_opt
[] = "--name";
9951 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9955 argv
[argc
++] = initial_argv
[0];
9957 if (! NILP (display_name
))
9959 argv
[argc
++] = display_opt
;
9960 argv
[argc
++] = SSDATA (display_name
);
9963 argv
[argc
++] = name_opt
;
9964 argv
[argc
++] = resource_name
;
9966 XSetLocaleModifiers ("");
9968 /* Emacs can only handle core input events, so make sure
9969 Gtk doesn't use Xinput or Xinput2 extensions. */
9970 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
9972 /* Work around GLib bug that outputs a faulty warning. See
9973 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9974 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9975 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9977 /* NULL window -> events for all windows go to our function.
9978 Call before gtk_init so Gtk+ event filters comes after our. */
9979 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9981 /* gtk_init does set_locale. Fix locale before and after. */
9983 gtk_init (&argc
, &argv2
);
9986 g_log_remove_handler ("GLib", id
);
9990 dpy
= DEFAULT_GDK_DISPLAY ();
9992 #if ! GTK_CHECK_VERSION (2, 90, 0)
9993 /* Load our own gtkrc if it exists. */
9995 const char *file
= "~/.emacs.d/gtkrc";
9996 Lisp_Object s
, abs_file
;
9998 s
= build_string (file
);
9999 abs_file
= Fexpand_file_name (s
, Qnil
);
10001 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10002 gtk_rc_parse (SSDATA (abs_file
));
10006 XSetErrorHandler (x_error_handler
);
10007 XSetIOErrorHandler (x_io_error_quitter
);
10010 #else /* not USE_GTK */
10011 #ifdef USE_X_TOOLKIT
10012 /* weiner@footloose.sps.mot.com reports that this causes
10014 X protocol error: BadAtom (invalid Atom parameter)
10015 on protocol request 18skiloaf.
10016 So let's not use it until R6. */
10017 #ifdef HAVE_X11XTR6
10018 XtSetLanguageProc (NULL
, NULL
, NULL
);
10029 argv
[argc
++] = "-xrm";
10030 argv
[argc
++] = xrm_option
;
10032 turn_on_atimers (0);
10033 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
10034 resource_name
, EMACS_CLASS
,
10035 emacs_options
, XtNumber (emacs_options
),
10037 turn_on_atimers (1);
10039 #ifdef HAVE_X11XTR6
10040 /* I think this is to compensate for XtSetLanguageProc. */
10045 #else /* not USE_X_TOOLKIT */
10046 XSetLocaleModifiers ("");
10047 dpy
= XOpenDisplay (SSDATA (display_name
));
10048 #endif /* not USE_X_TOOLKIT */
10049 #endif /* not USE_GTK*/
10051 /* Detect failure. */
10058 /* We have definitely succeeded. Record the new connection. */
10060 dpyinfo
= xzalloc (sizeof *dpyinfo
);
10061 terminal
= x_create_terminal (dpyinfo
);
10064 struct x_display_info
*share
;
10067 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10068 share
= share
->next
, tail
= XCDR (tail
))
10069 if (same_x_server (SSDATA (XCAR (XCAR (tail
))),
10070 SSDATA (display_name
)))
10073 terminal
->kboard
= share
->terminal
->kboard
;
10076 terminal
->kboard
= xmalloc (sizeof *terminal
->kboard
);
10077 init_kboard (terminal
->kboard
);
10078 kset_window_system (terminal
->kboard
, Qx
);
10080 /* Add the keyboard to the list before running Lisp code (via
10081 Qvendor_specific_keysyms below), since these are not traced
10082 via terminals but only through all_kboards. */
10083 terminal
->kboard
->next_kboard
= all_kboards
;
10084 all_kboards
= terminal
->kboard
;
10086 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10088 char *vendor
= ServerVendor (dpy
);
10090 /* Protect terminal from GC before removing it from the
10091 list of terminals. */
10092 struct gcpro gcpro1
;
10093 Lisp_Object gcpro_term
;
10094 XSETTERMINAL (gcpro_term
, terminal
);
10095 GCPRO1 (gcpro_term
);
10097 /* Temporarily hide the partially initialized terminal. */
10098 terminal_list
= terminal
->next_terminal
;
10100 kset_system_key_alist
10102 call1 (Qvendor_specific_keysyms
,
10103 vendor
? build_string (vendor
) : empty_unibyte_string
));
10105 terminal
->next_terminal
= terminal_list
;
10106 terminal_list
= terminal
;
10110 /* Don't let the initial kboard remain current longer than necessary.
10111 That would cause problems if a file loaded on startup tries to
10112 prompt in the mini-buffer. */
10113 if (current_kboard
== initial_kboard
)
10114 current_kboard
= terminal
->kboard
;
10116 terminal
->kboard
->reference_count
++;
10119 /* Put this display on the chain. */
10120 dpyinfo
->next
= x_display_list
;
10121 x_display_list
= dpyinfo
;
10123 /* Put it on x_display_name_list as well, to keep them parallel. */
10124 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10125 x_display_name_list
);
10126 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10128 dpyinfo
->display
= dpy
;
10130 /* Set the name of the terminal. */
10131 terminal
->name
= xlispstrdup (display_name
);
10134 XSetAfterFunction (x_current_display
, x_trace_wire
);
10137 lim
= min (PTRDIFF_MAX
, SIZE_MAX
) - sizeof "@";
10138 if (lim
- SBYTES (Vinvocation_name
) < SBYTES (Vsystem_name
))
10139 memory_full (SIZE_MAX
);
10140 dpyinfo
->x_id_name
= xmalloc (SBYTES (Vinvocation_name
)
10141 + SBYTES (Vsystem_name
) + 2);
10142 strcat (strcat (strcpy (dpyinfo
->x_id_name
, SSDATA (Vinvocation_name
)), "@"),
10143 SSDATA (Vsystem_name
));
10145 /* Figure out which modifier bits mean what. */
10146 x_find_modifier_meanings (dpyinfo
);
10148 /* Get the scroll bar cursor. */
10150 /* We must create a GTK cursor, it is required for GTK widgets. */
10151 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10152 #endif /* USE_GTK */
10154 dpyinfo
->vertical_scroll_bar_cursor
10155 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10157 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10158 resource_name
, EMACS_CLASS
);
10159 #ifdef HAVE_XRMSETDATABASE
10160 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10162 dpyinfo
->display
->db
= xrdb
;
10164 /* Put the rdb where we can find it in a way that works on
10166 dpyinfo
->xrdb
= xrdb
;
10168 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10169 DefaultScreen (dpyinfo
->display
));
10170 select_visual (dpyinfo
);
10171 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10172 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10173 dpyinfo
->icon_bitmap_id
= -1;
10174 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10176 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
10178 /* See if we can construct pixel values from RGB values. */
10179 if (dpyinfo
->visual
->class == TrueColor
)
10181 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10182 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10183 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10184 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10185 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10186 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10189 /* See if a private colormap is requested. */
10190 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10192 if (dpyinfo
->visual
->class == PseudoColor
)
10195 value
= display_x_get_resource (dpyinfo
,
10196 build_string ("privateColormap"),
10197 build_string ("PrivateColormap"),
10199 if (STRINGP (value
)
10200 && (!strcmp (SSDATA (value
), "true")
10201 || !strcmp (SSDATA (value
), "on")))
10202 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10206 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10207 dpyinfo
->visual
, AllocNone
);
10211 /* If we are using Xft, check dpi value in X resources.
10212 It is better we use it as well, since Xft will use it, as will all
10213 Gnome applications. If our real DPI is smaller or larger than the
10214 one Xft uses, our font will look smaller or larger than other
10215 for other applications, even if it is the same font name (monospace-10
10217 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10219 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10220 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10224 if (dpyinfo
->resy
< 1)
10226 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10227 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10228 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10229 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10230 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10231 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10232 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10233 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10234 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10238 static const struct
10243 #define ATOM_REFS_INIT(string, member) \
10244 { string, offsetof (struct x_display_info, member) },
10245 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
10246 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
10247 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
10248 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
10249 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
10250 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
10251 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
10252 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
10253 ATOM_REFS_INIT ("Editres", Xatom_editres
)
10254 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
10255 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
10256 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
10257 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
10258 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
10259 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
10260 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
10261 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
10262 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
10263 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
10264 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
10265 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
10266 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
10267 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
10268 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
10269 /* For properties of font. */
10270 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
10271 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
10272 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
10273 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
10274 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
10275 /* Ghostscript support. */
10276 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
10277 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
10278 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
10279 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
10281 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
10282 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
10283 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
10284 Xatom_net_wm_state_maximized_horz
)
10285 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
10286 Xatom_net_wm_state_maximized_vert
)
10287 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
10288 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
10289 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
10290 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
10291 Xatom_net_window_type_tooltip
)
10292 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
10293 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
10294 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
10295 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
10296 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
10297 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
10298 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
10299 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
10300 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
10301 /* Session management */
10302 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
10303 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
10304 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
10308 const int atom_count
= sizeof (atom_refs
) / sizeof (atom_refs
[0]);
10309 /* 1 for _XSETTINGS_SN */
10310 const int total_atom_count
= 1 + atom_count
;
10311 Atom
*atoms_return
= xmalloc (total_atom_count
* sizeof *atoms_return
);
10312 char **atom_names
= xmalloc (total_atom_count
* sizeof *atom_names
);
10313 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
10314 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
10315 + INT_STRLEN_BOUND (int)];
10317 for (i
= 0; i
< atom_count
; i
++)
10318 atom_names
[i
] = (char *) atom_refs
[i
].name
;
10320 /* Build _XSETTINGS_SN atom name */
10321 sprintf (xsettings_atom_name
, xsettings_fmt
,
10322 XScreenNumberOfScreen (dpyinfo
->screen
));
10323 atom_names
[i
] = xsettings_atom_name
;
10325 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
10326 False
, atoms_return
);
10328 for (i
= 0; i
< atom_count
; i
++)
10329 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
10331 /* Manual copy of last atom */
10332 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
10334 xfree (atom_names
);
10335 xfree (atoms_return
);
10338 dpyinfo
->x_dnd_atoms_size
= 8;
10339 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
10340 * dpyinfo
->x_dnd_atoms_size
);
10342 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10343 gray_bits
, gray_width
, gray_height
,
10347 xim_initialize (dpyinfo
, resource_name
);
10350 xsettings_initialize (dpyinfo
);
10352 connection
= ConnectionNumber (dpyinfo
->display
);
10354 /* This is only needed for distinguishing keyboard and process input. */
10355 if (connection
!= 0)
10356 add_keyboard_wait_descriptor (connection
);
10359 fcntl (connection
, F_SETOWN
, getpid ());
10360 #endif /* ! defined (F_SETOWN) */
10362 if (interrupt_input
)
10363 init_sigio (connection
);
10367 XrmValue d
, fr
, to
;
10370 dpy
= dpyinfo
->display
;
10371 d
.addr
= (XPointer
)&dpy
;
10372 d
.size
= sizeof (Display
*);
10373 fr
.addr
= XtDefaultFont
;
10374 fr
.size
= sizeof (XtDefaultFont
);
10375 to
.size
= sizeof (Font
*);
10376 to
.addr
= (XPointer
)&font
;
10377 x_catch_errors (dpy
);
10378 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10380 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10381 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10382 x_uncatch_errors ();
10386 /* See if we should run in synchronous mode. This is useful
10387 for debugging X code. */
10390 value
= display_x_get_resource (dpyinfo
,
10391 build_string ("synchronous"),
10392 build_string ("Synchronous"),
10394 if (STRINGP (value
)
10395 && (!strcmp (SSDATA (value
), "true")
10396 || !strcmp (SSDATA (value
), "on")))
10397 XSynchronize (dpyinfo
->display
, True
);
10402 value
= display_x_get_resource (dpyinfo
,
10403 build_string ("useXIM"),
10404 build_string ("UseXIM"),
10407 if (STRINGP (value
)
10408 && (!strcmp (SSDATA (value
), "false")
10409 || !strcmp (SSDATA (value
), "off")))
10412 if (STRINGP (value
)
10413 && (!strcmp (SSDATA (value
), "true")
10414 || !strcmp (SSDATA (value
), "on")))
10420 /* Only do this for the very first display in the Emacs session.
10421 Ignore X session management when Emacs was first started on a
10423 if (terminal
->id
== 1)
10424 x_session_initialize (dpyinfo
);
10432 /* Get rid of display DPYINFO, deleting all frames on it,
10433 and without sending any more commands to the X server. */
10436 x_delete_display (struct x_display_info
*dpyinfo
)
10438 struct terminal
*t
;
10440 /* Close all frames and delete the generic struct terminal for this
10442 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10443 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10446 /* Close X session management when we close its display. */
10447 if (t
->id
== 1 && x_session_have_connection ())
10448 x_session_close ();
10450 delete_terminal (t
);
10454 /* Discard this display from x_display_name_list and x_display_list.
10455 We can't use Fdelq because that can quit. */
10456 if (! NILP (x_display_name_list
)
10457 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10458 x_display_name_list
= XCDR (x_display_name_list
);
10463 tail
= x_display_name_list
;
10464 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10466 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10468 XSETCDR (tail
, XCDR (XCDR (tail
)));
10471 tail
= XCDR (tail
);
10475 if (next_noop_dpyinfo
== dpyinfo
)
10476 next_noop_dpyinfo
= dpyinfo
->next
;
10478 if (x_display_list
== dpyinfo
)
10479 x_display_list
= dpyinfo
->next
;
10482 struct x_display_info
*tail
;
10484 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10485 if (tail
->next
== dpyinfo
)
10486 tail
->next
= tail
->next
->next
;
10489 xfree (dpyinfo
->x_id_name
);
10490 xfree (dpyinfo
->x_dnd_atoms
);
10491 xfree (dpyinfo
->color_cells
);
10495 #ifdef USE_X_TOOLKIT
10497 /* Atimer callback function for TIMER. Called every 0.1s to process
10498 Xt timeouts, if needed. We must avoid calling XtAppPending as
10499 much as possible because that function does an implicit XFlush
10500 that slows us down. */
10503 x_process_timeouts (struct atimer
*timer
)
10506 x_timeout_atimer_activated_flag
= 0;
10507 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10509 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10510 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10511 /* Reactivate the atimer for next time. */
10512 x_activate_timeout_atimer ();
10517 /* Install an asynchronous timer that processes Xt timeout events
10518 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10519 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10520 function whenever these variables are set. This is necessary
10521 because some widget sets use timeouts internally, for example the
10522 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10523 processed, these widgets don't behave normally. */
10526 x_activate_timeout_atimer (void)
10529 if (!x_timeout_atimer_activated_flag
)
10531 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
10532 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10533 x_timeout_atimer_activated_flag
= 1;
10538 #endif /* USE_X_TOOLKIT */
10541 /* Set up use of X before we make the first connection. */
10543 static struct redisplay_interface x_redisplay_interface
=
10545 x_frame_parm_handlers
,
10549 x_clear_end_of_line
,
10551 x_after_update_window_line
,
10552 x_update_window_begin
,
10553 x_update_window_end
,
10555 x_clear_window_mouse_face
,
10556 x_get_glyph_overhangs
,
10557 x_fix_overlapping_area
,
10558 x_draw_fringe_bitmap
,
10559 0, /* define_fringe_bitmap */
10560 0, /* destroy_fringe_bitmap */
10561 x_compute_glyph_string_overhangs
,
10562 x_draw_glyph_string
,
10563 x_define_frame_cursor
,
10564 x_clear_frame_area
,
10565 x_draw_window_cursor
,
10566 x_draw_vertical_window_border
,
10567 x_shift_glyphs_for_insert
10571 /* This function is called when the last frame on a display is deleted. */
10573 x_delete_terminal (struct terminal
*terminal
)
10575 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10576 int connection
= -1;
10578 /* Protect against recursive calls. delete_frame in
10579 delete_terminal calls us back when it deletes our last frame. */
10580 if (!terminal
->name
)
10585 /* We must close our connection to the XIM server before closing the
10588 xim_close_dpy (dpyinfo
);
10591 /* If called from x_connection_closed, the display may already be closed
10592 and dpyinfo->display was set to 0 to indicate that. */
10593 if (dpyinfo
->display
)
10595 connection
= ConnectionNumber (dpyinfo
->display
);
10597 x_destroy_all_bitmaps (dpyinfo
);
10598 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10600 /* Whether or not XCloseDisplay destroys the associated resource
10601 database depends on the version of libX11. To avoid both
10602 crash and memory leak, we dissociate the database from the
10603 display and then destroy dpyinfo->xrdb ourselves.
10605 Unfortunately, the above strategy does not work in some
10606 situations due to a bug in newer versions of libX11: because
10607 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10608 dpy->db is NULL, XCloseDisplay destroys the associated
10609 database whereas it has not been created by XGetDefault
10610 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10611 don't destroy the database here in order to avoid the crash
10612 in the above situations for now, though that may cause memory
10613 leaks in other situations. */
10615 #ifdef HAVE_XRMSETDATABASE
10616 XrmSetDatabase (dpyinfo
->display
, NULL
);
10618 dpyinfo
->display
->db
= NULL
;
10620 /* We used to call XrmDestroyDatabase from x_delete_display, but
10621 some older versions of libX11 crash if we call it after
10622 closing all the displays. */
10623 XrmDestroyDatabase (dpyinfo
->xrdb
);
10627 xg_display_close (dpyinfo
->display
);
10629 #ifdef USE_X_TOOLKIT
10630 XtCloseDisplay (dpyinfo
->display
);
10632 XCloseDisplay (dpyinfo
->display
);
10634 #endif /* ! USE_GTK */
10637 /* No more input on this descriptor. */
10638 if (connection
!= -1)
10639 delete_keyboard_wait_descriptor (connection
);
10641 /* Mark as dead. */
10642 dpyinfo
->display
= NULL
;
10643 x_delete_display (dpyinfo
);
10647 /* Create a struct terminal, initialize it with the X11 specific
10648 functions and make DISPLAY->TERMINAL point to it. */
10650 static struct terminal
*
10651 x_create_terminal (struct x_display_info
*dpyinfo
)
10653 struct terminal
*terminal
;
10655 terminal
= create_terminal ();
10657 terminal
->type
= output_x_window
;
10658 terminal
->display_info
.x
= dpyinfo
;
10659 dpyinfo
->terminal
= terminal
;
10661 /* kboard is initialized in x_term_init. */
10663 terminal
->clear_frame_hook
= x_clear_frame
;
10664 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10665 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10666 terminal
->ring_bell_hook
= XTring_bell
;
10667 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10668 terminal
->reset_terminal_modes_hook
= NULL
;
10669 terminal
->set_terminal_modes_hook
= NULL
;
10670 terminal
->update_begin_hook
= x_update_begin
;
10671 terminal
->update_end_hook
= x_update_end
;
10672 terminal
->set_terminal_window_hook
= NULL
;
10673 terminal
->read_socket_hook
= XTread_socket
;
10674 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10675 terminal
->mouse_position_hook
= XTmouse_position
;
10676 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10677 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10678 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10679 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10680 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10681 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10682 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10684 terminal
->delete_frame_hook
= x_destroy_window
;
10685 terminal
->delete_terminal_hook
= x_delete_terminal
;
10687 terminal
->rif
= &x_redisplay_interface
;
10688 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10689 terminal
->char_ins_del_ok
= 1;
10690 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10691 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10692 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10699 x_initialize (void)
10704 last_tool_bar_item
= -1;
10705 any_help_event_p
= 0;
10706 ignore_next_mouse_click_timeout
= 0;
10709 current_count
= -1;
10712 /* Try to use interrupt input; if we can't, then start polling. */
10713 Fset_input_interrupt_mode (Qt
);
10715 #ifdef USE_X_TOOLKIT
10716 XtToolkitInitialize ();
10718 Xt_app_con
= XtCreateApplicationContext ();
10720 /* Register a converter from strings to pixels, which uses
10721 Emacs' color allocation infrastructure. */
10722 XtAppSetTypeConverter (Xt_app_con
,
10723 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10724 cvt_string_to_pixel_args
,
10725 XtNumber (cvt_string_to_pixel_args
),
10726 XtCacheByDisplay
, cvt_pixel_dtor
);
10728 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10731 #ifdef USE_TOOLKIT_SCROLL_BARS
10733 xaw3d_arrow_scroll
= False
;
10734 xaw3d_pick_top
= True
;
10738 pending_autoraise_frame
= 0;
10739 pending_event_wait
.f
= 0;
10740 pending_event_wait
.eventtype
= 0;
10742 /* Note that there is no real way portable across R3/R4 to get the
10743 original error handler. */
10744 XSetErrorHandler (x_error_handler
);
10745 XSetIOErrorHandler (x_io_error_quitter
);
10750 syms_of_xterm (void)
10752 x_error_message
= NULL
;
10754 staticpro (&x_display_name_list
);
10755 x_display_name_list
= Qnil
;
10757 staticpro (&last_mouse_scroll_bar
);
10758 last_mouse_scroll_bar
= Qnil
;
10760 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
10761 DEFSYM (Qlatin_1
, "latin-1");
10764 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10765 staticpro (&xg_default_icon_file
);
10767 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
10770 DEFVAR_BOOL ("x-use-underline-position-properties",
10771 x_use_underline_position_properties
,
10772 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
10773 A value of nil means ignore them. If you encounter fonts with bogus
10774 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10775 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10776 to override the font's UNDERLINE_POSITION for small font display
10778 x_use_underline_position_properties
= 1;
10780 DEFVAR_BOOL ("x-underline-at-descent-line",
10781 x_underline_at_descent_line
,
10782 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
10783 A value of nil means to draw the underline according to the value of the
10784 variable `x-use-underline-position-properties', which is usually at the
10785 baseline level. The default value is nil. */);
10786 x_underline_at_descent_line
= 0;
10788 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10789 x_mouse_click_focus_ignore_position
,
10790 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10791 This variable is only used when the window manager requires that you
10792 click on a frame to select it (give it focus). In that case, a value
10793 of nil, means that the selected window and cursor position changes to
10794 reflect the mouse click position, while a non-nil value means that the
10795 selected window or cursor position is preserved. */);
10796 x_mouse_click_focus_ignore_position
= 0;
10798 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
10799 doc
: /* Which toolkit scroll bars Emacs uses, if any.
10800 A value of nil means Emacs doesn't use toolkit scroll bars.
10801 With the X Window system, the value is a symbol describing the
10802 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
10803 With MS Windows or Nextstep, the value is t. */);
10804 #ifdef USE_TOOLKIT_SCROLL_BARS
10806 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10807 #elif defined HAVE_XAW3D
10808 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10810 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10812 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10815 Vx_toolkit_scroll_bars
= Qnil
;
10818 staticpro (&last_mouse_motion_frame
);
10819 last_mouse_motion_frame
= Qnil
;
10821 Qmodifier_value
= intern_c_string ("modifier-value");
10822 Qalt
= intern_c_string ("alt");
10823 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10824 Qhyper
= intern_c_string ("hyper");
10825 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10826 Qmeta
= intern_c_string ("meta");
10827 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10828 Qsuper
= intern_c_string ("super");
10829 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10831 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
10832 doc
: /* Which keys Emacs uses for the alt modifier.
10833 This should be one of the symbols `alt', `hyper', `meta', `super'.
10834 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10835 is nil, which is the same as `alt'. */);
10836 Vx_alt_keysym
= Qnil
;
10838 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
10839 doc
: /* Which keys Emacs uses for the hyper modifier.
10840 This should be one of the symbols `alt', `hyper', `meta', `super'.
10841 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10842 default is nil, which is the same as `hyper'. */);
10843 Vx_hyper_keysym
= Qnil
;
10845 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
10846 doc
: /* Which keys Emacs uses for the meta modifier.
10847 This should be one of the symbols `alt', `hyper', `meta', `super'.
10848 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10849 default is nil, which is the same as `meta'. */);
10850 Vx_meta_keysym
= Qnil
;
10852 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
10853 doc
: /* Which keys Emacs uses for the super modifier.
10854 This should be one of the symbols `alt', `hyper', `meta', `super'.
10855 For example, `super' means use the Super_L and Super_R keysyms. The
10856 default is nil, which is the same as `super'. */);
10857 Vx_super_keysym
= Qnil
;
10859 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
10860 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10861 Vx_keysym_table
= make_hash_table (hashtest_eql
, make_number (900),
10862 make_float (DEFAULT_REHASH_SIZE
),
10863 make_float (DEFAULT_REHASH_THRESHOLD
),