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>
87 #if defined (USE_LUCID) || defined (USE_MOTIF)
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
;
153 /* The application context for Xt use. */
154 XtAppContext Xt_app_con
;
155 static String Xt_default_resources
[] = {0};
157 /* Non-zero means user is interacting with a toolkit scroll bar. */
158 static bool toolkit_scroll_bar_interaction
;
160 #endif /* USE_X_TOOLKIT */
162 /* Non-zero timeout value means ignore next mouse click if it arrives
163 before that timeout elapses (i.e. as part of the same sequence of
164 events resulting from clicking on a frame to select it). */
166 static Time ignore_next_mouse_click_timeout
;
168 /* Incremented by XTread_socket whenever it really tries to read
171 static int volatile input_signal_count
;
173 /* Used locally within XTread_socket. */
175 static int x_noop_count
;
177 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
179 static Lisp_Object Qvendor_specific_keysyms
;
180 static Lisp_Object Qlatin_1
;
183 /* The name of the Emacs icon file. */
184 static Lisp_Object xg_default_icon_file
;
186 /* Used in gtkutil.c. */
187 Lisp_Object Qx_gtk_map_stock
;
190 /* Some functions take this as char *, not const char *. */
191 static char emacs_class
[] = EMACS_CLASS
;
195 XEMBED_MAPPED
= 1 << 0
200 XEMBED_EMBEDDED_NOTIFY
= 0,
201 XEMBED_WINDOW_ACTIVATE
= 1,
202 XEMBED_WINDOW_DEACTIVATE
= 2,
203 XEMBED_REQUEST_FOCUS
= 3,
205 XEMBED_FOCUS_OUT
= 5,
206 XEMBED_FOCUS_NEXT
= 6,
207 XEMBED_FOCUS_PREV
= 7,
209 XEMBED_MODALITY_ON
= 10,
210 XEMBED_MODALITY_OFF
= 11,
211 XEMBED_REGISTER_ACCELERATOR
= 12,
212 XEMBED_UNREGISTER_ACCELERATOR
= 13,
213 XEMBED_ACTIVATE_ACCELERATOR
= 14
216 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
217 static void x_set_window_size_1 (struct frame
*, int, int, int);
218 static void x_raise_frame (struct frame
*);
219 static void x_lower_frame (struct frame
*);
220 static const XColor
*x_color_cells (Display
*, int *);
221 static int x_io_error_quitter (Display
*);
222 static struct terminal
*x_create_terminal (struct x_display_info
*);
223 void x_delete_terminal (struct terminal
*);
224 static void x_update_end (struct frame
*);
225 static void XTframe_up_to_date (struct frame
*);
226 static void x_clear_frame (struct frame
*);
227 static _Noreturn
void x_ins_del_lines (struct frame
*, int, int);
228 static void frame_highlight (struct frame
*);
229 static void frame_unhighlight (struct frame
*);
230 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
231 static void x_focus_changed (int, int, struct x_display_info
*,
232 struct frame
*, struct input_event
*);
233 static void XTframe_rehighlight (struct frame
*);
234 static void x_frame_rehighlight (struct x_display_info
*);
235 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
236 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
237 enum text_cursor_kinds
);
239 static void x_clip_to_row (struct window
*, struct glyph_row
*,
240 enum glyph_row_area
, GC
);
241 static void x_flush (struct frame
*f
);
242 static void x_update_begin (struct frame
*);
243 static void x_update_window_begin (struct window
*);
244 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
245 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
246 enum scroll_bar_part
*,
247 Lisp_Object
*, Lisp_Object
*,
249 static int x_handle_net_wm_state (struct frame
*, const XPropertyEvent
*);
250 static void x_check_fullscreen (struct frame
*);
251 static void x_check_expected_move (struct frame
*, int, int);
252 static void x_sync_with_move (struct frame
*, int, int, int);
253 static int handle_one_xevent (struct x_display_info
*,
254 const XEvent
*, int *,
255 struct input_event
*);
257 static int x_dispatch_event (XEvent
*, Display
*);
259 /* Don't declare this _Noreturn because we want no
260 interference with debugging failing X calls. */
261 static void x_connection_closed (Display
*, const char *);
262 static void x_wm_set_window_state (struct frame
*, int);
263 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
264 static void x_initialize (void);
267 /* Flush display of frame F. */
270 x_flush (struct frame
*f
)
272 eassert (f
&& FRAME_X_P (f
));
273 /* Don't call XFlush when it is not safe to redisplay; the X
274 connection may be broken. */
275 if (!NILP (Vinhibit_redisplay
))
279 XFlush (FRAME_X_DISPLAY (f
));
284 /* Remove calls to XFlush by defining XFlush to an empty replacement.
285 Calls to XFlush should be unnecessary because the X output buffer
286 is flushed automatically as needed by calls to XPending,
287 XNextEvent, or XWindowEvent according to the XFlush man page.
288 XTread_socket calls XPending. Removing XFlush improves
291 #define XFlush(DISPLAY) (void) 0
294 /***********************************************************************
296 ***********************************************************************/
300 /* This is a function useful for recording debugging information about
301 the sequence of occurrences in this file. */
309 struct record event_record
[100];
311 int event_record_index
;
314 record_event (char *locus
, int type
)
316 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
317 event_record_index
= 0;
319 event_record
[event_record_index
].locus
= locus
;
320 event_record
[event_record_index
].type
= type
;
321 event_record_index
++;
328 /* Return the struct x_display_info corresponding to DPY. */
330 struct x_display_info
*
331 x_display_info_for_display (Display
*dpy
)
333 struct x_display_info
*dpyinfo
;
335 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
336 if (dpyinfo
->display
== dpy
)
343 x_find_topmost_parent (struct frame
*f
)
345 struct x_output
*x
= f
->output_data
.x
;
346 Window win
= None
, wi
= x
->parent_desc
;
347 Display
*dpy
= FRAME_X_DISPLAY (f
);
349 while (wi
!= FRAME_DISPLAY_INFO (f
)->root_window
)
353 unsigned int nchildren
;
356 XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
);
363 #define OPAQUE 0xffffffff
366 x_set_frame_alpha (struct frame
*f
)
368 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
369 Display
*dpy
= FRAME_X_DISPLAY (f
);
370 Window win
= FRAME_OUTER_WINDOW (f
);
372 double alpha_min
= 1.0;
376 if (dpyinfo
->x_highlight_frame
== f
)
381 if (FLOATP (Vframe_alpha_lower_limit
))
382 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
383 else if (INTEGERP (Vframe_alpha_lower_limit
))
384 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
388 else if (alpha
> 1.0)
390 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
393 opac
= alpha
* OPAQUE
;
395 x_catch_errors (dpy
);
397 /* If there is a parent from the window manager, put the property there
398 also, to work around broken window managers that fail to do that.
399 Do this unconditionally as this function is called on reparent when
400 alpha has not changed on the frame. */
402 parent
= x_find_topmost_parent (f
);
404 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
405 XA_CARDINAL
, 32, PropModeReplace
,
406 (unsigned char *) &opac
, 1L);
408 /* return unless necessary */
413 unsigned long n
, left
;
415 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
416 0L, 1L, False
, XA_CARDINAL
,
417 &actual
, &format
, &n
, &left
,
420 if (rc
== Success
&& actual
!= None
)
422 unsigned long value
= *(unsigned long *)data
;
432 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
433 XA_CARDINAL
, 32, PropModeReplace
,
434 (unsigned char *) &opac
, 1L);
439 x_display_pixel_height (struct x_display_info
*dpyinfo
)
441 return HeightOfScreen (dpyinfo
->screen
);
445 x_display_pixel_width (struct x_display_info
*dpyinfo
)
447 return WidthOfScreen (dpyinfo
->screen
);
451 /***********************************************************************
452 Starting and ending an update
453 ***********************************************************************/
455 /* Start an update of frame F. This function is installed as a hook
456 for update_begin, i.e. it is called when update_begin is called.
457 This function is called prior to calls to x_update_window_begin for
458 each window being updated. Currently, there is nothing to do here
459 because all interesting stuff is done on a window basis. */
462 x_update_begin (struct frame
*f
)
468 /* Start update of window W. */
471 x_update_window_begin (struct window
*w
)
473 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
474 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
476 w
->output_cursor
= w
->cursor
;
480 if (f
== hlinfo
->mouse_face_mouse_frame
)
482 /* Don't do highlighting for mouse motion during the update. */
483 hlinfo
->mouse_face_defer
= 1;
485 /* If F needs to be redrawn, simply forget about any prior mouse
487 if (FRAME_GARBAGED_P (f
))
488 hlinfo
->mouse_face_window
= Qnil
;
495 /* Draw a vertical window border from (x,y0) to (x,y1) */
498 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
500 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
503 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
505 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
508 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
509 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
512 /* End update of window W.
514 Draw vertical borders between horizontally adjacent windows, and
515 display W's cursor if CURSOR_ON_P is non-zero.
517 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
518 glyphs in mouse-face were overwritten. In that case we have to
519 make sure that the mouse-highlight is properly redrawn.
521 W may be a menu bar pseudo-window in case we don't have X toolkit
522 support. Such windows don't have a cursor, so don't display it
526 x_update_window_end (struct window
*w
, bool cursor_on_p
,
527 bool mouse_face_overwritten_p
)
529 if (!w
->pseudo_window_p
)
534 display_and_set_cursor (w
, 1,
535 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
536 w
->output_cursor
.x
, w
->output_cursor
.y
);
538 if (draw_window_fringes (w
, 1))
539 x_draw_vertical_border (w
);
544 /* If a row with mouse-face was overwritten, arrange for
545 XTframe_up_to_date to redisplay the mouse highlight. */
546 if (mouse_face_overwritten_p
)
547 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w
->frame
)));
551 /* End update of frame F. This function is installed as a hook in
555 x_update_end (struct frame
*f
)
557 /* Mouse highlight may be displayed again. */
558 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
562 XFlush (FRAME_X_DISPLAY (f
));
568 /* This function is called from various places in xdisp.c
569 whenever a complete update has been performed. */
572 XTframe_up_to_date (struct frame
*f
)
575 FRAME_MOUSE_UPDATE (f
);
579 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
580 arrow bitmaps, or clear the fringes if no bitmaps are required
581 before DESIRED_ROW is made current. This function is called from
582 update_window_line only if it is known that there are differences
583 between bitmaps to be drawn between current row and DESIRED_ROW. */
586 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
593 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
594 desired_row
->redraw_fringe_bitmaps_p
= 1;
596 /* When a window has disappeared, make sure that no rest of
597 full-width rows stays visible in the internal border. Could
598 check here if updated window is the leftmost/rightmost window,
599 but I guess it's not worth doing since vertically split windows
600 are almost never used, internal border is rarely set, and the
601 overhead is very small. */
602 if (windows_or_buffers_changed
603 && desired_row
->full_width_p
604 && (f
= XFRAME (w
->frame
),
605 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
607 && (height
= desired_row
->visible_height
,
610 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
613 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
614 0, y
, width
, height
);
615 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
616 FRAME_PIXEL_WIDTH (f
) - width
,
623 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
625 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
626 Display
*display
= FRAME_X_DISPLAY (f
);
627 Window window
= FRAME_X_WINDOW (f
);
628 GC gc
= f
->output_data
.x
->normal_gc
;
629 struct face
*face
= p
->face
;
631 /* Must clip because of partially visible lines. */
632 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
636 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
638 /* In case the same realized face is used for fringes and
639 for something displayed in the text (e.g. face `region' on
640 mono-displays, the fill style may have been changed to
641 FillSolid in x_draw_glyph_string_background. */
643 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
645 XSetForeground (display
, face
->gc
, face
->background
);
647 #ifdef USE_TOOLKIT_SCROLL_BARS
648 /* If the fringe is adjacent to the left (right) scroll bar of a
649 leftmost (rightmost, respectively) window, then extend its
650 background to the gap between the fringe and the bar. */
651 if ((WINDOW_LEFTMOST_P (w
)
652 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
653 || (WINDOW_RIGHTMOST_P (w
)
654 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
656 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
660 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
661 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
662 * FRAME_COLUMN_WIDTH (f
));
666 /* Bitmap fills the fringe. */
667 if (bar_area_x
+ bar_area_width
== p
->x
)
668 bx
= bar_area_x
+ sb_width
;
669 else if (p
->x
+ p
->wd
== bar_area_x
)
673 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
675 nx
= bar_area_width
- sb_width
;
676 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
678 ny
= row
->visible_height
;
683 if (bar_area_x
+ bar_area_width
== bx
)
685 bx
= bar_area_x
+ sb_width
;
686 nx
+= bar_area_width
- sb_width
;
688 else if (bx
+ nx
== bar_area_x
)
689 nx
+= bar_area_width
- sb_width
;
694 if (bx
>= 0 && nx
> 0)
695 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
698 XSetForeground (display
, face
->gc
, face
->foreground
);
704 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
705 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
709 bits
= (char *) (p
->bits
+ p
->dh
);
711 bits
= (char *) p
->bits
+ p
->dh
;
713 /* Draw the bitmap. I believe these small pixmaps can be cached
715 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
717 ? (p
->overlay_p
? face
->background
718 : f
->output_data
.x
->cursor_pixel
)
720 face
->background
, depth
);
724 clipmask
= XCreatePixmapFromBitmapData (display
,
725 FRAME_DISPLAY_INFO (f
)->root_window
,
728 gcv
.clip_mask
= clipmask
;
729 gcv
.clip_x_origin
= p
->x
;
730 gcv
.clip_y_origin
= p
->y
;
731 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
734 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
735 p
->wd
, p
->h
, p
->x
, p
->y
);
736 XFreePixmap (display
, pixmap
);
740 gcv
.clip_mask
= (Pixmap
) 0;
741 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
742 XFreePixmap (display
, clipmask
);
746 XSetClipMask (display
, gc
, None
);
749 /***********************************************************************
751 ***********************************************************************/
755 static void x_set_glyph_string_clipping (struct glyph_string
*);
756 static void x_set_glyph_string_gc (struct glyph_string
*);
757 static void x_draw_glyph_string_foreground (struct glyph_string
*);
758 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
759 static void x_draw_glyph_string_box (struct glyph_string
*);
760 static void x_draw_glyph_string (struct glyph_string
*);
761 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
762 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
763 static void x_set_cursor_gc (struct glyph_string
*);
764 static void x_set_mode_line_face_gc (struct glyph_string
*);
765 static void x_set_mouse_face_gc (struct glyph_string
*);
766 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
767 unsigned long *, double, int);
768 static void x_setup_relief_color (struct frame
*, struct relief
*,
769 double, int, unsigned long);
770 static void x_setup_relief_colors (struct glyph_string
*);
771 static void x_draw_image_glyph_string (struct glyph_string
*);
772 static void x_draw_image_relief (struct glyph_string
*);
773 static void x_draw_image_foreground (struct glyph_string
*);
774 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
775 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
777 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
778 int, int, int, int, int, int,
780 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
781 int, int, int, XRectangle
*);
782 static void x_scroll_bar_clear (struct frame
*);
785 static void x_check_font (struct frame
*, struct font
*);
789 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
793 x_set_cursor_gc (struct glyph_string
*s
)
795 if (s
->font
== FRAME_FONT (s
->f
)
796 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
797 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
799 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
802 /* Cursor on non-default face: must merge. */
806 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
807 xgcv
.foreground
= s
->face
->background
;
809 /* If the glyph would be invisible, try a different foreground. */
810 if (xgcv
.foreground
== xgcv
.background
)
811 xgcv
.foreground
= s
->face
->foreground
;
812 if (xgcv
.foreground
== xgcv
.background
)
813 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
814 if (xgcv
.foreground
== xgcv
.background
)
815 xgcv
.foreground
= s
->face
->foreground
;
817 /* Make sure the cursor is distinct from text in this face. */
818 if (xgcv
.background
== s
->face
->background
819 && xgcv
.foreground
== s
->face
->foreground
)
821 xgcv
.background
= s
->face
->foreground
;
822 xgcv
.foreground
= s
->face
->background
;
825 IF_DEBUG (x_check_font (s
->f
, s
->font
));
826 xgcv
.graphics_exposures
= False
;
827 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
829 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
830 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
833 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
834 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
836 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
841 /* Set up S->gc of glyph string S for drawing text in mouse face. */
844 x_set_mouse_face_gc (struct glyph_string
*s
)
849 /* What face has to be used last for the mouse face? */
850 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
851 face
= FACE_FROM_ID (s
->f
, face_id
);
853 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
855 if (s
->first_glyph
->type
== CHAR_GLYPH
)
856 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
858 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
859 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
860 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
862 if (s
->font
== s
->face
->font
)
866 /* Otherwise construct scratch_cursor_gc with values from FACE
871 xgcv
.background
= s
->face
->background
;
872 xgcv
.foreground
= s
->face
->foreground
;
873 xgcv
.graphics_exposures
= False
;
874 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
876 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
877 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
880 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
881 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
883 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
886 eassert (s
->gc
!= 0);
890 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
891 Faces to use in the mode line have already been computed when the
892 matrix was built, so there isn't much to do, here. */
895 x_set_mode_line_face_gc (struct glyph_string
*s
)
901 /* Set S->gc of glyph string S for drawing that glyph string. Set
902 S->stippled_p to a non-zero value if the face of S has a stipple
906 x_set_glyph_string_gc (struct glyph_string
*s
)
908 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
910 if (s
->hl
== DRAW_NORMAL_TEXT
)
913 s
->stippled_p
= s
->face
->stipple
!= 0;
915 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
917 x_set_mode_line_face_gc (s
);
918 s
->stippled_p
= s
->face
->stipple
!= 0;
920 else if (s
->hl
== DRAW_CURSOR
)
925 else if (s
->hl
== DRAW_MOUSE_FACE
)
927 x_set_mouse_face_gc (s
);
928 s
->stippled_p
= s
->face
->stipple
!= 0;
930 else if (s
->hl
== DRAW_IMAGE_RAISED
931 || s
->hl
== DRAW_IMAGE_SUNKEN
)
934 s
->stippled_p
= s
->face
->stipple
!= 0;
939 s
->stippled_p
= s
->face
->stipple
!= 0;
942 /* GC must have been set. */
943 eassert (s
->gc
!= 0);
947 /* Set clipping for output of glyph string S. S may be part of a mode
948 line or menu if we don't have X toolkit support. */
951 x_set_glyph_string_clipping (struct glyph_string
*s
)
953 XRectangle
*r
= s
->clip
;
954 int n
= get_glyph_string_clip_rects (s
, r
, 2);
957 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
962 /* Set SRC's clipping for output of glyph string DST. This is called
963 when we are drawing DST's left_overhang or right_overhang only in
967 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
972 r
.width
= src
->width
;
974 r
.height
= src
->height
;
977 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
982 Compute left and right overhang of glyph string S. */
985 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
988 && (s
->first_glyph
->type
== CHAR_GLYPH
989 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
991 struct font_metrics metrics
;
993 if (s
->first_glyph
->type
== CHAR_GLYPH
)
995 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
996 struct font
*font
= s
->font
;
999 for (i
= 0; i
< s
->nchars
; i
++)
1000 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1001 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1005 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1007 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1009 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1010 ? metrics
.rbearing
- metrics
.width
: 0);
1011 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1015 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1016 s
->left_overhang
= - s
->cmp
->lbearing
;
1021 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1024 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1027 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1028 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1029 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1030 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1034 /* Draw the background of glyph_string S. If S->background_filled_p
1035 is non-zero don't draw it. FORCE_P non-zero means draw the
1036 background even if it wouldn't be drawn normally. This is used
1037 when a string preceding S draws into the background of S, or S
1038 contains the first component of a composition. */
1041 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1043 /* Nothing to do if background has already been drawn or if it
1044 shouldn't be drawn in the first place. */
1045 if (!s
->background_filled_p
)
1047 int box_line_width
= max (s
->face
->box_line_width
, 0);
1051 /* Fill background with a stipple pattern. */
1052 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1053 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1054 s
->y
+ box_line_width
,
1055 s
->background_width
,
1056 s
->height
- 2 * box_line_width
);
1057 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1058 s
->background_filled_p
= 1;
1060 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1061 || s
->font_not_found_p
1062 || s
->extends_to_end_of_line_p
1065 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1066 s
->background_width
,
1067 s
->height
- 2 * box_line_width
);
1068 s
->background_filled_p
= 1;
1074 /* Draw the foreground of glyph string S. */
1077 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1081 /* If first glyph of S has a left box line, start drawing the text
1082 of S to the right of that box line. */
1083 if (s
->face
->box
!= FACE_NO_BOX
1084 && s
->first_glyph
->left_box_line_p
)
1085 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1089 /* Draw characters of S as rectangles if S's font could not be
1091 if (s
->font_not_found_p
)
1093 for (i
= 0; i
< s
->nchars
; ++i
)
1095 struct glyph
*g
= s
->first_glyph
+ i
;
1096 XDrawRectangle (s
->display
, s
->window
,
1097 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1099 x
+= g
->pixel_width
;
1104 struct font
*font
= s
->font
;
1105 int boff
= font
->baseline_offset
;
1108 if (font
->vertical_centering
)
1109 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1111 y
= s
->ybase
- boff
;
1113 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1114 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1116 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1117 if (s
->face
->overstrike
)
1118 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1122 /* Draw the foreground of composite glyph string S. */
1125 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1128 struct font
*font
= s
->font
;
1130 /* If first glyph of S has a left box line, start drawing the text
1131 of S to the right of that box line. */
1132 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1133 && s
->first_glyph
->left_box_line_p
)
1134 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1138 /* S is a glyph string for a composition. S->cmp_from is the index
1139 of the first character drawn for glyphs of this composition.
1140 S->cmp_from == 0 means we are drawing the very first character of
1141 this composition. */
1143 /* Draw a rectangle for the composition if the font for the very
1144 first character of the composition could not be loaded. */
1145 if (s
->font_not_found_p
)
1147 if (s
->cmp_from
== 0)
1148 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1149 s
->width
- 1, s
->height
- 1);
1151 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1155 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1156 /* TAB in a composition means display glyphs with padding
1157 space on the left or right. */
1158 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1160 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1161 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1163 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1164 if (s
->face
->overstrike
)
1165 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1170 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1175 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1177 glyph
= LGSTRING_GLYPH (gstring
, i
);
1178 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1179 width
+= LGLYPH_WIDTH (glyph
);
1182 int xoff
, yoff
, wadjust
;
1186 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1187 if (s
->face
->overstrike
)
1188 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1191 xoff
= LGLYPH_XOFF (glyph
);
1192 yoff
= LGLYPH_YOFF (glyph
);
1193 wadjust
= LGLYPH_WADJUST (glyph
);
1194 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1195 if (s
->face
->overstrike
)
1196 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1204 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1205 if (s
->face
->overstrike
)
1206 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1212 /* Draw the foreground of glyph string S for glyphless characters. */
1215 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1217 struct glyph
*glyph
= s
->first_glyph
;
1221 /* If first glyph of S has a left box line, start drawing the text
1222 of S to the right of that box line. */
1223 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1224 && s
->first_glyph
->left_box_line_p
)
1225 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1231 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1233 char buf
[7], *str
= NULL
;
1234 int len
= glyph
->u
.glyphless
.len
;
1236 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1239 && CHAR_TABLE_P (Vglyphless_char_display
)
1240 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1244 = (! glyph
->u
.glyphless
.for_no_font
1245 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1246 glyph
->u
.glyphless
.ch
)
1247 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1248 if (STRINGP (acronym
))
1249 str
= SSDATA (acronym
);
1252 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1254 sprintf (buf
, "%0*X",
1255 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1256 glyph
->u
.glyphless
.ch
);
1262 int upper_len
= (len
+ 1) / 2;
1265 /* It is assured that all LEN characters in STR is ASCII. */
1266 for (j
= 0; j
< len
; j
++)
1268 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1269 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1271 s
->font
->driver
->draw (s
, 0, upper_len
,
1272 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1273 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1275 s
->font
->driver
->draw (s
, upper_len
, len
,
1276 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1277 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1280 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1281 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
1282 x
, s
->ybase
- glyph
->ascent
,
1283 glyph
->pixel_width
- 1,
1284 glyph
->ascent
+ glyph
->descent
- 1);
1285 x
+= glyph
->pixel_width
;
1289 #ifdef USE_X_TOOLKIT
1293 /* Return the frame on which widget WIDGET is used.. Abort if frame
1294 cannot be determined. */
1296 static struct frame
*
1297 x_frame_of_widget (Widget widget
)
1299 struct x_display_info
*dpyinfo
;
1300 Lisp_Object tail
, frame
;
1303 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1305 /* Find the top-level shell of the widget. Note that this function
1306 can be called when the widget is not yet realized, so XtWindow
1307 (widget) == 0. That's the reason we can't simply use
1308 x_any_window_to_frame. */
1309 while (!XtIsTopLevelShell (widget
))
1310 widget
= XtParent (widget
);
1312 /* Look for a frame with that top-level widget. Allocate the color
1313 on that frame to get the right gamma correction value. */
1314 FOR_EACH_FRAME (tail
, frame
)
1318 && f
->output_data
.nothing
!= 1
1319 && FRAME_DISPLAY_INFO (f
) == dpyinfo
1320 && f
->output_data
.x
->widget
== widget
)
1326 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1327 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1328 If this produces the same color as PIXEL, try a color where all RGB
1329 values have DELTA added. Return the allocated color in *PIXEL.
1330 DISPLAY is the X display, CMAP is the colormap to operate on.
1331 Value is true if successful. */
1334 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1335 unsigned long *pixel
, double factor
, int delta
)
1337 struct frame
*f
= x_frame_of_widget (widget
);
1338 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1341 #endif /* USE_LUCID */
1344 /* Structure specifying which arguments should be passed by Xt to
1345 cvt_string_to_pixel. We want the widget's screen and colormap. */
1347 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1349 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1351 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1356 /* The address of this variable is returned by
1357 cvt_string_to_pixel. */
1359 static Pixel cvt_string_to_pixel_value
;
1362 /* Convert a color name to a pixel color.
1364 DPY is the display we are working on.
1366 ARGS is an array of *NARGS XrmValue structures holding additional
1367 information about the widget for which the conversion takes place.
1368 The contents of this array are determined by the specification
1369 in cvt_string_to_pixel_args.
1371 FROM is a pointer to an XrmValue which points to the color name to
1372 convert. TO is an XrmValue in which to return the pixel color.
1374 CLOSURE_RET is a pointer to user-data, in which we record if
1375 we allocated the color or not.
1377 Value is True if successful, False otherwise. */
1380 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1381 XrmValue
*from
, XrmValue
*to
,
1382 XtPointer
*closure_ret
)
1392 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1393 "wrongParameters", "cvt_string_to_pixel",
1395 "Screen and colormap args required", NULL
, NULL
);
1399 screen
= *(Screen
**) args
[0].addr
;
1400 cmap
= *(Colormap
*) args
[1].addr
;
1401 color_name
= (String
) from
->addr
;
1403 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1405 *closure_ret
= (XtPointer
) False
;
1406 pixel
= WhitePixelOfScreen (screen
);
1408 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1410 *closure_ret
= (XtPointer
) False
;
1411 pixel
= BlackPixelOfScreen (screen
);
1413 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1414 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1416 pixel
= color
.pixel
;
1417 *closure_ret
= (XtPointer
) True
;
1422 Cardinal nparams
= 1;
1424 params
[0] = color_name
;
1425 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1426 "badValue", "cvt_string_to_pixel",
1427 "XtToolkitError", "Invalid color `%s'",
1432 if (to
->addr
!= NULL
)
1434 if (to
->size
< sizeof (Pixel
))
1436 to
->size
= sizeof (Pixel
);
1440 *(Pixel
*) to
->addr
= pixel
;
1444 cvt_string_to_pixel_value
= pixel
;
1445 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1448 to
->size
= sizeof (Pixel
);
1453 /* Free a pixel color which was previously allocated via
1454 cvt_string_to_pixel. This is registered as the destructor
1455 for this type of resource via XtSetTypeConverter.
1457 APP is the application context in which we work.
1459 TO is a pointer to an XrmValue holding the color to free.
1460 CLOSURE is the value we stored in CLOSURE_RET for this color
1461 in cvt_string_to_pixel.
1463 ARGS and NARGS are like for cvt_string_to_pixel. */
1466 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1471 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1473 "Screen and colormap arguments required",
1476 else if (closure
!= NULL
)
1478 /* We did allocate the pixel, so free it. */
1479 Screen
*screen
= *(Screen
**) args
[0].addr
;
1480 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1481 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1482 (Pixel
*) to
->addr
, 1);
1487 #endif /* USE_X_TOOLKIT */
1490 /* Value is an array of XColor structures for the contents of the
1491 color map of display DPY. Set *NCELLS to the size of the array.
1492 Note that this probably shouldn't be called for large color maps,
1493 say a 24-bit TrueColor map. */
1495 static const XColor
*
1496 x_color_cells (Display
*dpy
, int *ncells
)
1498 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1500 if (dpyinfo
->color_cells
== NULL
)
1502 Screen
*screen
= dpyinfo
->screen
;
1503 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1506 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
1507 sizeof *dpyinfo
->color_cells
);
1508 dpyinfo
->ncolor_cells
= ncolor_cells
;
1510 for (i
= 0; i
< ncolor_cells
; ++i
)
1511 dpyinfo
->color_cells
[i
].pixel
= i
;
1513 XQueryColors (dpy
, dpyinfo
->cmap
,
1514 dpyinfo
->color_cells
, ncolor_cells
);
1517 *ncells
= dpyinfo
->ncolor_cells
;
1518 return dpyinfo
->color_cells
;
1522 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1523 colors in COLORS. Use cached information, if available. */
1526 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1528 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1530 if (dpyinfo
->color_cells
)
1533 for (i
= 0; i
< ncolors
; ++i
)
1535 unsigned long pixel
= colors
[i
].pixel
;
1536 eassert (pixel
< dpyinfo
->ncolor_cells
);
1537 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1538 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1542 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1546 /* On frame F, translate pixel color to RGB values for the color in
1547 COLOR. Use cached information, if available. */
1550 x_query_color (struct frame
*f
, XColor
*color
)
1552 x_query_colors (f
, color
, 1);
1556 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1557 exact match can't be allocated, try the nearest color available.
1558 Value is true if successful. Set *COLOR to the color
1562 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1566 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1569 /* If we got to this point, the colormap is full, so we're going
1570 to try to get the next closest color. The algorithm used is
1571 a least-squares matching, which is what X uses for closest
1572 color matching with StaticColor visuals. */
1574 int max_color_delta
= 255;
1575 int max_delta
= 3 * max_color_delta
;
1576 int nearest_delta
= max_delta
+ 1;
1578 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1580 for (nearest
= i
= 0; i
< ncells
; ++i
)
1582 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1583 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1584 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1585 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1587 if (delta
< nearest_delta
)
1590 nearest_delta
= delta
;
1594 color
->red
= cells
[nearest
].red
;
1595 color
->green
= cells
[nearest
].green
;
1596 color
->blue
= cells
[nearest
].blue
;
1597 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1601 /* If allocation succeeded, and the allocated pixel color is not
1602 equal to a cached pixel color recorded earlier, there was a
1603 change in the colormap, so clear the color cache. */
1604 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1605 XColor
*cached_color
;
1607 if (dpyinfo
->color_cells
1608 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1609 (cached_color
->red
!= color
->red
1610 || cached_color
->blue
!= color
->blue
1611 || cached_color
->green
!= color
->green
)))
1613 xfree (dpyinfo
->color_cells
);
1614 dpyinfo
->color_cells
= NULL
;
1615 dpyinfo
->ncolor_cells
= 0;
1619 #ifdef DEBUG_X_COLORS
1621 register_color (color
->pixel
);
1622 #endif /* DEBUG_X_COLORS */
1628 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1629 exact match can't be allocated, try the nearest color available.
1630 Value is true if successful. Set *COLOR to the color
1634 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1636 gamma_correct (f
, color
);
1637 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1641 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1642 It's necessary to do this instead of just using PIXEL directly to
1643 get color reference counts right. */
1646 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1650 color
.pixel
= pixel
;
1652 x_query_color (f
, &color
);
1653 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1655 #ifdef DEBUG_X_COLORS
1656 register_color (pixel
);
1662 /* Brightness beyond which a color won't have its highlight brightness
1665 Nominally, highlight colors for `3d' faces are calculated by
1666 brightening an object's color by a constant scale factor, but this
1667 doesn't yield good results for dark colors, so for colors who's
1668 brightness is less than this value (on a scale of 0-65535) have an
1669 use an additional additive factor.
1671 The value here is set so that the default menu-bar/mode-line color
1672 (grey75) will not have its highlights changed at all. */
1673 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1676 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1677 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1678 If this produces the same color as PIXEL, try a color where all RGB
1679 values have DELTA added. Return the allocated color in *PIXEL.
1680 DISPLAY is the X display, CMAP is the colormap to operate on.
1681 Value is non-zero if successful. */
1684 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1690 /* Get RGB color values. */
1691 color
.pixel
= *pixel
;
1692 x_query_color (f
, &color
);
1694 /* Change RGB values by specified FACTOR. Avoid overflow! */
1695 eassert (factor
>= 0);
1696 new.red
= min (0xffff, factor
* color
.red
);
1697 new.green
= min (0xffff, factor
* color
.green
);
1698 new.blue
= min (0xffff, factor
* color
.blue
);
1700 /* Calculate brightness of COLOR. */
1701 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1703 /* We only boost colors that are darker than
1704 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1705 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1706 /* Make an additive adjustment to NEW, because it's dark enough so
1707 that scaling by FACTOR alone isn't enough. */
1709 /* How far below the limit this color is (0 - 1, 1 being darker). */
1710 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1711 /* The additive adjustment. */
1712 int min_delta
= delta
* dimness
* factor
/ 2;
1716 new.red
= max (0, new.red
- min_delta
);
1717 new.green
= max (0, new.green
- min_delta
);
1718 new.blue
= max (0, new.blue
- min_delta
);
1722 new.red
= min (0xffff, min_delta
+ new.red
);
1723 new.green
= min (0xffff, min_delta
+ new.green
);
1724 new.blue
= min (0xffff, min_delta
+ new.blue
);
1728 /* Try to allocate the color. */
1729 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1732 if (new.pixel
== *pixel
)
1734 /* If we end up with the same color as before, try adding
1735 delta to the RGB values. */
1736 x_free_colors (f
, &new.pixel
, 1);
1738 new.red
= min (0xffff, delta
+ color
.red
);
1739 new.green
= min (0xffff, delta
+ color
.green
);
1740 new.blue
= min (0xffff, delta
+ color
.blue
);
1741 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1752 /* Set up the foreground color for drawing relief lines of glyph
1753 string S. RELIEF is a pointer to a struct relief containing the GC
1754 with which lines will be drawn. Use a color that is FACTOR or
1755 DELTA lighter or darker than the relief's background which is found
1756 in S->f->output_data.x->relief_background. If such a color cannot
1757 be allocated, use DEFAULT_PIXEL, instead. */
1760 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1763 struct x_output
*di
= f
->output_data
.x
;
1764 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1765 unsigned long pixel
;
1766 unsigned long background
= di
->relief_background
;
1767 Colormap cmap
= FRAME_X_COLORMAP (f
);
1768 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1769 Display
*dpy
= FRAME_X_DISPLAY (f
);
1771 xgcv
.graphics_exposures
= False
;
1772 xgcv
.line_width
= 1;
1774 /* Free previously allocated color. The color cell will be reused
1775 when it has been freed as many times as it was allocated, so this
1776 doesn't affect faces using the same colors. */
1778 && relief
->allocated_p
)
1780 x_free_colors (f
, &relief
->pixel
, 1);
1781 relief
->allocated_p
= 0;
1784 /* Allocate new color. */
1785 xgcv
.foreground
= default_pixel
;
1787 if (dpyinfo
->n_planes
!= 1
1788 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1790 relief
->allocated_p
= 1;
1791 xgcv
.foreground
= relief
->pixel
= pixel
;
1794 if (relief
->gc
== 0)
1796 xgcv
.stipple
= dpyinfo
->gray
;
1798 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1801 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1805 /* Set up colors for the relief lines around glyph string S. */
1808 x_setup_relief_colors (struct glyph_string
*s
)
1810 struct x_output
*di
= s
->f
->output_data
.x
;
1811 unsigned long color
;
1813 if (s
->face
->use_box_color_for_shadows_p
)
1814 color
= s
->face
->box_color
;
1815 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1817 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1818 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1823 /* Get the background color of the face. */
1824 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1825 color
= xgcv
.background
;
1828 if (di
->white_relief
.gc
== 0
1829 || color
!= di
->relief_background
)
1831 di
->relief_background
= color
;
1832 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1833 WHITE_PIX_DEFAULT (s
->f
));
1834 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1835 BLACK_PIX_DEFAULT (s
->f
));
1840 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1841 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1842 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1843 relief. LEFT_P non-zero means draw a relief on the left side of
1844 the rectangle. RIGHT_P non-zero means draw a relief on the right
1845 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1849 x_draw_relief_rect (struct frame
*f
,
1850 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1851 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1852 XRectangle
*clip_rect
)
1854 Display
*dpy
= FRAME_X_DISPLAY (f
);
1855 Window window
= FRAME_X_WINDOW (f
);
1860 gc
= f
->output_data
.x
->white_relief
.gc
;
1862 gc
= f
->output_data
.x
->black_relief
.gc
;
1863 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1865 /* This code is more complicated than it has to be, because of two
1866 minor hacks to make the boxes look nicer: (i) if width > 1, draw
1867 the outermost line using the black relief. (ii) Omit the four
1874 XDrawLine (dpy
, window
, gc
,
1875 left_x
+ (left_p
? 1 : 0), top_y
,
1876 right_x
+ (right_p
? 0 : 1), top_y
);
1878 for (i
= 1; i
< width
; ++i
)
1879 XDrawLine (dpy
, window
, gc
,
1880 left_x
+ i
* left_p
, top_y
+ i
,
1881 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1888 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1890 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
1891 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
1893 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
1894 XDrawLine (dpy
, window
, gc
,
1895 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
1896 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1899 XSetClipMask (dpy
, gc
, None
);
1901 gc
= f
->output_data
.x
->black_relief
.gc
;
1903 gc
= f
->output_data
.x
->white_relief
.gc
;
1904 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1908 /* Outermost top line. */
1910 XDrawLine (dpy
, window
, gc
,
1911 left_x
+ (left_p
? 1 : 0), top_y
,
1912 right_x
+ (right_p
? 0 : 1), top_y
);
1914 /* Outermost left line. */
1916 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1922 XDrawLine (dpy
, window
, gc
,
1923 left_x
+ (left_p
? 1 : 0), bottom_y
,
1924 right_x
+ (right_p
? 0 : 1), bottom_y
);
1925 for (i
= 1; i
< width
; ++i
)
1926 XDrawLine (dpy
, window
, gc
,
1927 left_x
+ i
* left_p
, bottom_y
- i
,
1928 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
1934 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
1935 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
1936 for (i
= 0; i
< width
; ++i
)
1937 XDrawLine (dpy
, window
, gc
,
1938 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
1939 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1942 XSetClipMask (dpy
, gc
, None
);
1946 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1947 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1948 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
1949 left side of the rectangle. RIGHT_P non-zero means draw a line
1950 on the right side of the rectangle. CLIP_RECT is the clipping
1951 rectangle to use when drawing. */
1954 x_draw_box_rect (struct glyph_string
*s
,
1955 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1956 int left_p
, int right_p
, XRectangle
*clip_rect
)
1960 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
1961 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
1962 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
1965 XFillRectangle (s
->display
, s
->window
, s
->gc
,
1966 left_x
, top_y
, right_x
- left_x
+ 1, width
);
1970 XFillRectangle (s
->display
, s
->window
, s
->gc
,
1971 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
1974 XFillRectangle (s
->display
, s
->window
, s
->gc
,
1975 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
1979 XFillRectangle (s
->display
, s
->window
, s
->gc
,
1980 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
1982 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1983 XSetClipMask (s
->display
, s
->gc
, None
);
1987 /* Draw a box around glyph string S. */
1990 x_draw_glyph_string_box (struct glyph_string
*s
)
1992 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
1993 int left_p
, right_p
;
1994 struct glyph
*last_glyph
;
1995 XRectangle clip_rect
;
1997 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
1998 ? WINDOW_RIGHT_EDGE_X (s
->w
)
1999 : window_box_right (s
->w
, s
->area
));
2001 /* The glyph that may have a right box line. */
2002 last_glyph
= (s
->cmp
|| s
->img
2004 : s
->first_glyph
+ s
->nchars
- 1);
2006 width
= eabs (s
->face
->box_line_width
);
2007 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2009 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2011 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2013 bottom_y
= top_y
+ s
->height
- 1;
2015 left_p
= (s
->first_glyph
->left_box_line_p
2016 || (s
->hl
== DRAW_MOUSE_FACE
2018 || s
->prev
->hl
!= s
->hl
)));
2019 right_p
= (last_glyph
->right_box_line_p
2020 || (s
->hl
== DRAW_MOUSE_FACE
2022 || s
->next
->hl
!= s
->hl
)));
2024 get_glyph_string_clip_rect (s
, &clip_rect
);
2026 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2027 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2028 left_p
, right_p
, &clip_rect
);
2031 x_setup_relief_colors (s
);
2032 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2033 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2038 /* Draw foreground of image glyph string S. */
2041 x_draw_image_foreground (struct glyph_string
*s
)
2044 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2046 /* If first glyph of S has a left box line, start drawing it to the
2047 right of that line. */
2048 if (s
->face
->box
!= FACE_NO_BOX
2049 && s
->first_glyph
->left_box_line_p
2051 x
+= eabs (s
->face
->box_line_width
);
2053 /* If there is a margin around the image, adjust x- and y-position
2055 if (s
->slice
.x
== 0)
2056 x
+= s
->img
->hmargin
;
2057 if (s
->slice
.y
== 0)
2058 y
+= s
->img
->vmargin
;
2064 /* We can't set both a clip mask and use XSetClipRectangles
2065 because the latter also sets a clip mask. We also can't
2066 trust on the shape extension to be available
2067 (XShapeCombineRegion). So, compute the rectangle to draw
2069 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2072 XRectangle clip_rect
, image_rect
, r
;
2074 xgcv
.clip_mask
= s
->img
->mask
;
2075 xgcv
.clip_x_origin
= x
;
2076 xgcv
.clip_y_origin
= y
;
2077 xgcv
.function
= GXcopy
;
2078 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2080 get_glyph_string_clip_rect (s
, &clip_rect
);
2083 image_rect
.width
= s
->slice
.width
;
2084 image_rect
.height
= s
->slice
.height
;
2085 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2086 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2087 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2088 r
.width
, r
.height
, r
.x
, r
.y
);
2092 XRectangle clip_rect
, image_rect
, r
;
2094 get_glyph_string_clip_rect (s
, &clip_rect
);
2097 image_rect
.width
= s
->slice
.width
;
2098 image_rect
.height
= s
->slice
.height
;
2099 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2100 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2101 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2102 r
.width
, r
.height
, r
.x
, r
.y
);
2104 /* When the image has a mask, we can expect that at
2105 least part of a mouse highlight or a block cursor will
2106 be visible. If the image doesn't have a mask, make
2107 a block cursor visible by drawing a rectangle around
2108 the image. I believe it's looking better if we do
2109 nothing here for mouse-face. */
2110 if (s
->hl
== DRAW_CURSOR
)
2112 int relief
= eabs (s
->img
->relief
);
2113 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2114 x
- relief
, y
- relief
,
2115 s
->slice
.width
+ relief
*2 - 1,
2116 s
->slice
.height
+ relief
*2 - 1);
2121 /* Draw a rectangle if image could not be loaded. */
2122 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2123 s
->slice
.width
- 1, s
->slice
.height
- 1);
2127 /* Draw a relief around the image glyph string S. */
2130 x_draw_image_relief (struct glyph_string
*s
)
2132 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
2135 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2137 /* If first glyph of S has a left box line, start drawing it to the
2138 right of that line. */
2139 if (s
->face
->box
!= FACE_NO_BOX
2140 && s
->first_glyph
->left_box_line_p
2142 x
+= eabs (s
->face
->box_line_width
);
2144 /* If there is a margin around the image, adjust x- and y-position
2146 if (s
->slice
.x
== 0)
2147 x
+= s
->img
->hmargin
;
2148 if (s
->slice
.y
== 0)
2149 y
+= s
->img
->vmargin
;
2151 if (s
->hl
== DRAW_IMAGE_SUNKEN
2152 || s
->hl
== DRAW_IMAGE_RAISED
)
2154 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2155 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2159 thick
= eabs (s
->img
->relief
);
2160 raised_p
= s
->img
->relief
> 0;
2163 x1
= x
+ s
->slice
.width
- 1;
2164 y1
= y
+ s
->slice
.height
- 1;
2165 top_p
= bot_p
= left_p
= right_p
= 0;
2167 if (s
->slice
.x
== 0)
2168 x
-= thick
, left_p
= 1;
2169 if (s
->slice
.y
== 0)
2170 y
-= thick
, top_p
= 1;
2171 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
2172 x1
+= thick
, right_p
= 1;
2173 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
2174 y1
+= thick
, bot_p
= 1;
2176 x_setup_relief_colors (s
);
2177 get_glyph_string_clip_rect (s
, &r
);
2178 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
2179 top_p
, bot_p
, left_p
, right_p
, &r
);
2183 /* Draw the foreground of image glyph string S to PIXMAP. */
2186 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2189 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2191 /* If first glyph of S has a left box line, start drawing it to the
2192 right of that line. */
2193 if (s
->face
->box
!= FACE_NO_BOX
2194 && s
->first_glyph
->left_box_line_p
2196 x
+= eabs (s
->face
->box_line_width
);
2198 /* If there is a margin around the image, adjust x- and y-position
2200 if (s
->slice
.x
== 0)
2201 x
+= s
->img
->hmargin
;
2202 if (s
->slice
.y
== 0)
2203 y
+= s
->img
->vmargin
;
2209 /* We can't set both a clip mask and use XSetClipRectangles
2210 because the latter also sets a clip mask. We also can't
2211 trust on the shape extension to be available
2212 (XShapeCombineRegion). So, compute the rectangle to draw
2214 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2218 xgcv
.clip_mask
= s
->img
->mask
;
2219 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2220 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2221 xgcv
.function
= GXcopy
;
2222 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2224 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2225 s
->slice
.x
, s
->slice
.y
,
2226 s
->slice
.width
, s
->slice
.height
, x
, y
);
2227 XSetClipMask (s
->display
, s
->gc
, None
);
2231 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2232 s
->slice
.x
, s
->slice
.y
,
2233 s
->slice
.width
, s
->slice
.height
, x
, y
);
2235 /* When the image has a mask, we can expect that at
2236 least part of a mouse highlight or a block cursor will
2237 be visible. If the image doesn't have a mask, make
2238 a block cursor visible by drawing a rectangle around
2239 the image. I believe it's looking better if we do
2240 nothing here for mouse-face. */
2241 if (s
->hl
== DRAW_CURSOR
)
2243 int r
= eabs (s
->img
->relief
);
2244 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2245 s
->slice
.width
+ r
*2 - 1,
2246 s
->slice
.height
+ r
*2 - 1);
2251 /* Draw a rectangle if image could not be loaded. */
2252 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2253 s
->slice
.width
- 1, s
->slice
.height
- 1);
2257 /* Draw part of the background of glyph string S. X, Y, W, and H
2258 give the rectangle to draw. */
2261 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2265 /* Fill background with a stipple pattern. */
2266 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2267 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2268 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2271 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2275 /* Draw image glyph string S.
2278 s->x +-------------------------
2281 | +-------------------------
2284 | | +-------------------
2290 x_draw_image_glyph_string (struct glyph_string
*s
)
2292 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2293 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2295 Pixmap pixmap
= None
;
2298 if (s
->slice
.y
== 0)
2299 height
-= box_line_vwidth
;
2300 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2301 height
-= box_line_vwidth
;
2303 /* Fill background with face under the image. Do it only if row is
2304 taller than image or if image has a clip mask to reduce
2306 s
->stippled_p
= s
->face
->stipple
!= 0;
2307 if (height
> s
->slice
.height
2311 || s
->img
->pixmap
== 0
2312 || s
->width
!= s
->background_width
)
2316 /* Create a pixmap as large as the glyph string. Fill it
2317 with the background color. Copy the image to it, using
2318 its mask. Copy the temporary pixmap to the display. */
2319 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2320 int depth
= DefaultDepthOfScreen (screen
);
2322 /* Create a pixmap as large as the glyph string. */
2323 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2324 s
->background_width
,
2327 /* Don't clip in the following because we're working on the
2329 XSetClipMask (s
->display
, s
->gc
, None
);
2331 /* Fill the pixmap with the background color/stipple. */
2334 /* Fill background with a stipple pattern. */
2335 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2336 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2337 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2338 0, 0, s
->background_width
, s
->height
);
2339 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2340 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2345 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2347 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2348 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2349 0, 0, s
->background_width
, s
->height
);
2350 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2358 if (s
->first_glyph
->left_box_line_p
2360 x
+= box_line_hwidth
;
2362 if (s
->slice
.y
== 0)
2363 y
+= box_line_vwidth
;
2365 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2368 s
->background_filled_p
= 1;
2371 /* Draw the foreground. */
2374 x_draw_image_foreground_1 (s
, pixmap
);
2375 x_set_glyph_string_clipping (s
);
2376 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2377 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2378 XFreePixmap (s
->display
, pixmap
);
2381 x_draw_image_foreground (s
);
2383 /* If we must draw a relief around the image, do it. */
2385 || s
->hl
== DRAW_IMAGE_RAISED
2386 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2387 x_draw_image_relief (s
);
2391 /* Draw stretch glyph string S. */
2394 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2396 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2398 if (s
->hl
== DRAW_CURSOR
2399 && !x_stretch_cursor_p
)
2401 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2402 wide as the stretch glyph. */
2403 int width
, background_width
= s
->background_width
;
2406 if (!s
->row
->reversed_p
)
2408 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2412 background_width
-= left_x
- x
;
2418 /* In R2L rows, draw the cursor on the right edge of the
2420 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2422 if (x
+ background_width
> right_x
)
2423 background_width
-= x
- right_x
;
2424 x
+= background_width
;
2426 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2427 if (s
->row
->reversed_p
)
2431 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2433 /* Clear rest using the GC of the original non-cursor face. */
2434 if (width
< background_width
)
2437 int w
= background_width
- width
, h
= s
->height
;
2441 if (!s
->row
->reversed_p
)
2445 if (s
->row
->mouse_face_p
2446 && cursor_in_mouse_face_p (s
->w
))
2448 x_set_mouse_face_gc (s
);
2454 get_glyph_string_clip_rect (s
, &r
);
2455 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2457 if (s
->face
->stipple
)
2459 /* Fill background with a stipple pattern. */
2460 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2461 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2462 XSetFillStyle (s
->display
, gc
, FillSolid
);
2467 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2468 XSetForeground (s
->display
, gc
, xgcv
.background
);
2469 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2470 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2474 else if (!s
->background_filled_p
)
2476 int background_width
= s
->background_width
;
2477 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2479 /* Don't draw into left margin, fringe or scrollbar area
2480 except for header line and mode line. */
2481 if (x
< left_x
&& !s
->row
->mode_line_p
)
2483 background_width
-= left_x
- x
;
2486 if (background_width
> 0)
2487 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2490 s
->background_filled_p
= 1;
2494 Draw a wavy line under S. The wave fills wave_height pixels from y0.
2500 wave_height = 3 | * * * *
2505 x_draw_underwave (struct glyph_string
*s
)
2507 int wave_height
= 3, wave_length
= 2;
2508 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
2509 XRectangle wave_clip
, string_clip
, final_clip
;
2512 dy
= wave_height
- 1;
2514 y0
= s
->ybase
- wave_height
+ 3;
2518 /* Find and set clipping rectangle */
2522 wave_clip
.width
= width
;
2523 wave_clip
.height
= wave_height
;
2524 get_glyph_string_clip_rect (s
, &string_clip
);
2526 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
2529 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
2531 /* Draw the waves */
2533 x1
= x0
- (x0
% dx
);
2543 if (INT_MAX
- dx
< xmax
)
2548 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
2550 x2
+= dx
, y2
= y0
+ odd
*dy
;
2554 /* Restore previous clipping rectangle(s) */
2555 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
2559 /* Draw glyph string S. */
2562 x_draw_glyph_string (struct glyph_string
*s
)
2564 bool relief_drawn_p
= 0;
2566 /* If S draws into the background of its successors, draw the
2567 background of the successors first so that S can draw into it.
2568 This makes S->next use XDrawString instead of XDrawImageString. */
2569 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2572 struct glyph_string
*next
;
2574 for (width
= 0, next
= s
->next
;
2575 next
&& width
< s
->right_overhang
;
2576 width
+= next
->width
, next
= next
->next
)
2577 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2579 x_set_glyph_string_gc (next
);
2580 x_set_glyph_string_clipping (next
);
2581 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2582 x_draw_stretch_glyph_string (next
);
2584 x_draw_glyph_string_background (next
, 1);
2585 next
->num_clips
= 0;
2589 /* Set up S->gc, set clipping and draw S. */
2590 x_set_glyph_string_gc (s
);
2592 /* Draw relief (if any) in advance for char/composition so that the
2593 glyph string can be drawn over it. */
2594 if (!s
->for_overlaps
2595 && s
->face
->box
!= FACE_NO_BOX
2596 && (s
->first_glyph
->type
== CHAR_GLYPH
2597 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2600 x_set_glyph_string_clipping (s
);
2601 x_draw_glyph_string_background (s
, 1);
2602 x_draw_glyph_string_box (s
);
2603 x_set_glyph_string_clipping (s
);
2606 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2608 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2609 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2610 /* We must clip just this glyph. left_overhang part has already
2611 drawn when s->prev was drawn, and right_overhang part will be
2612 drawn later when s->next is drawn. */
2613 x_set_glyph_string_clipping_exactly (s
, s
);
2615 x_set_glyph_string_clipping (s
);
2617 switch (s
->first_glyph
->type
)
2620 x_draw_image_glyph_string (s
);
2624 x_draw_stretch_glyph_string (s
);
2628 if (s
->for_overlaps
)
2629 s
->background_filled_p
= 1;
2631 x_draw_glyph_string_background (s
, 0);
2632 x_draw_glyph_string_foreground (s
);
2635 case COMPOSITE_GLYPH
:
2636 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2637 && ! s
->first_glyph
->u
.cmp
.automatic
))
2638 s
->background_filled_p
= 1;
2640 x_draw_glyph_string_background (s
, 1);
2641 x_draw_composite_glyph_string_foreground (s
);
2644 case GLYPHLESS_GLYPH
:
2645 if (s
->for_overlaps
)
2646 s
->background_filled_p
= 1;
2648 x_draw_glyph_string_background (s
, 1);
2649 x_draw_glyphless_glyph_string_foreground (s
);
2656 if (!s
->for_overlaps
)
2658 /* Draw underline. */
2659 if (s
->face
->underline_p
)
2661 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2663 if (s
->face
->underline_defaulted_p
)
2664 x_draw_underwave (s
);
2668 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2669 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2670 x_draw_underwave (s
);
2671 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2674 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2676 unsigned long thickness
, position
;
2679 if (s
->prev
&& s
->prev
->face
->underline_p
2680 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2682 /* We use the same underline style as the previous one. */
2683 thickness
= s
->prev
->underline_thickness
;
2684 position
= s
->prev
->underline_position
;
2688 /* Get the underline thickness. Default is 1 pixel. */
2689 if (s
->font
&& s
->font
->underline_thickness
> 0)
2690 thickness
= s
->font
->underline_thickness
;
2693 if (x_underline_at_descent_line
)
2694 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2697 /* Get the underline position. This is the recommended
2698 vertical offset in pixels from the baseline to the top of
2699 the underline. This is a signed value according to the
2700 specs, and its default is
2702 ROUND ((maximum descent) / 2), with
2703 ROUND(x) = floor (x + 0.5) */
2705 if (x_use_underline_position_properties
2706 && s
->font
&& s
->font
->underline_position
>= 0)
2707 position
= s
->font
->underline_position
;
2709 position
= (s
->font
->descent
+ 1) / 2;
2711 position
= underline_minimum_offset
;
2713 position
= max (position
, underline_minimum_offset
);
2715 /* Check the sanity of thickness and position. We should
2716 avoid drawing underline out of the current line area. */
2717 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2718 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2719 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2720 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2721 s
->underline_thickness
= thickness
;
2722 s
->underline_position
= position
;
2723 y
= s
->ybase
+ position
;
2724 if (s
->face
->underline_defaulted_p
)
2725 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2726 s
->x
, y
, s
->width
, thickness
);
2730 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2731 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2732 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2733 s
->x
, y
, s
->width
, thickness
);
2734 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2738 /* Draw overline. */
2739 if (s
->face
->overline_p
)
2741 unsigned long dy
= 0, h
= 1;
2743 if (s
->face
->overline_color_defaulted_p
)
2744 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2749 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2750 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2751 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2753 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2757 /* Draw strike-through. */
2758 if (s
->face
->strike_through_p
)
2760 unsigned long h
= 1;
2761 unsigned long dy
= (s
->height
- h
) / 2;
2763 if (s
->face
->strike_through_color_defaulted_p
)
2764 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2769 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2770 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2771 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2773 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2777 /* Draw relief if not yet drawn. */
2778 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2779 x_draw_glyph_string_box (s
);
2783 struct glyph_string
*prev
;
2785 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2786 if (prev
->hl
!= s
->hl
2787 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2789 /* As prev was drawn while clipped to its own area, we
2790 must draw the right_overhang part using s->hl now. */
2791 enum draw_glyphs_face save
= prev
->hl
;
2794 x_set_glyph_string_gc (prev
);
2795 x_set_glyph_string_clipping_exactly (s
, prev
);
2796 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2797 x_draw_glyph_string_foreground (prev
);
2799 x_draw_composite_glyph_string_foreground (prev
);
2800 XSetClipMask (prev
->display
, prev
->gc
, None
);
2802 prev
->num_clips
= 0;
2808 struct glyph_string
*next
;
2810 for (next
= s
->next
; next
; next
= next
->next
)
2811 if (next
->hl
!= s
->hl
2812 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2814 /* As next will be drawn while clipped to its own area,
2815 we must draw the left_overhang part using s->hl now. */
2816 enum draw_glyphs_face save
= next
->hl
;
2819 x_set_glyph_string_gc (next
);
2820 x_set_glyph_string_clipping_exactly (s
, next
);
2821 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2822 x_draw_glyph_string_foreground (next
);
2824 x_draw_composite_glyph_string_foreground (next
);
2825 XSetClipMask (next
->display
, next
->gc
, None
);
2827 next
->num_clips
= 0;
2828 next
->clip_head
= s
->next
;
2833 /* Reset clipping. */
2834 XSetClipMask (s
->display
, s
->gc
, None
);
2838 /* Shift display to make room for inserted glyphs. */
2841 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2843 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2844 f
->output_data
.x
->normal_gc
,
2845 x
, y
, width
, height
,
2849 /* Delete N glyphs at the nominal cursor position. Not implemented
2853 x_delete_glyphs (struct frame
*f
, register int n
)
2859 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2860 If they are <= 0, this is probably an error. */
2863 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
)
2865 eassert (width
> 0 && height
> 0);
2866 XClearArea (dpy
, window
, x
, y
, width
, height
, False
);
2870 /* Clear an entire frame. */
2873 x_clear_frame (struct frame
*f
)
2875 /* Clearing the frame will erase any cursor, so mark them all as no
2877 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2881 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2883 /* We have to clear the scroll bars. If we have changed colors or
2884 something like that, then they should be notified. */
2885 x_scroll_bar_clear (f
);
2887 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2888 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2889 redisplay, do it here. */
2890 if (FRAME_GTK_WIDGET (f
))
2891 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2894 XFlush (FRAME_X_DISPLAY (f
));
2901 /* Invert the middle quarter of the frame for .15 sec. */
2904 XTflash (struct frame
*f
)
2910 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
2911 when the scroll bars and the edit widget share the same X window. */
2912 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
2914 cairo_t
*cr
= gdk_cairo_create (window
);
2915 cairo_set_source_rgb (cr
, 1, 1, 1);
2916 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
2917 #define XFillRectangle(d, win, gc, x, y, w, h) \
2919 cairo_rectangle (cr, x, y, w, h); \
2923 #else /* ! HAVE_GTK3 */
2926 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
2927 ^ FRAME_BACKGROUND_PIXEL (f
));
2928 vals
.function
= GDK_XOR
;
2929 gc
= gdk_gc_new_with_values (window
,
2930 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
2931 #define XFillRectangle(d, win, gc, x, y, w, h) \
2932 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
2933 #endif /* ! HAVE_GTK3 */
2934 #else /* ! USE_GTK */
2937 /* Create a GC that will use the GXxor function to flip foreground
2938 pixels into background pixels. */
2942 values
.function
= GXxor
;
2943 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
2944 ^ FRAME_BACKGROUND_PIXEL (f
));
2946 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2947 GCFunction
| GCForeground
, &values
);
2951 /* Get the height not including a menu bar widget. */
2952 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
2953 /* Height of each line to flash. */
2954 int flash_height
= FRAME_LINE_HEIGHT (f
);
2955 /* These will be the left and right margins of the rectangles. */
2956 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2957 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2958 int width
= flash_right
- flash_left
;
2960 /* If window is tall, flash top and bottom line. */
2961 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2963 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2965 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2966 + FRAME_TOP_MARGIN_HEIGHT (f
)),
2967 width
, flash_height
);
2968 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2970 (height
- flash_height
2971 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2972 width
, flash_height
);
2976 /* If it is short, flash it all. */
2977 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2978 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2979 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2984 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
2985 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
2987 /* Keep waiting until past the time wakeup or any input gets
2989 while (! detect_input_pending ())
2991 struct timespec current
= current_timespec ();
2992 struct timespec timeout
;
2994 /* Break if result would not be positive. */
2995 if (timespec_cmp (wakeup
, current
) <= 0)
2998 /* How long `select' should wait. */
2999 timeout
= make_timespec (0, 10 * 1000 * 1000);
3001 /* Try to wait that long--but we might wake up sooner. */
3002 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3006 /* If window is tall, flash top and bottom line. */
3007 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3009 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3011 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3012 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3013 width
, flash_height
);
3014 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3016 (height
- flash_height
3017 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3018 width
, flash_height
);
3021 /* If it is short, flash it all. */
3022 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3023 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3024 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3030 g_object_unref (G_OBJECT (gc
));
3032 #undef XFillRectangle
3034 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3045 XTtoggle_invisible_pointer (struct frame
*f
, int invisible
)
3050 if (FRAME_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3051 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3052 FRAME_DISPLAY_INFO (f
)->invisible_cursor
);
3055 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3056 f
->output_data
.x
->current_cursor
);
3057 f
->pointer_invisible
= invisible
;
3062 /* Make audible bell. */
3065 XTring_bell (struct frame
*f
)
3067 if (FRAME_X_DISPLAY (f
))
3075 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
3077 XBell (FRAME_X_DISPLAY (f
), 0);
3079 XFlush (FRAME_X_DISPLAY (f
));
3085 /***********************************************************************
3087 ***********************************************************************/
3089 /* Perform an insert-lines or delete-lines operation, inserting N
3090 lines or deleting -N lines at vertical position VPOS. */
3093 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3099 /* Scroll part of the display as described by RUN. */
3102 x_scroll_run (struct window
*w
, struct run
*run
)
3104 struct frame
*f
= XFRAME (w
->frame
);
3105 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3107 /* Get frame-relative bounding box of the text display area of W,
3108 without mode lines. Include in this box the left and right
3110 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
3112 #ifdef USE_TOOLKIT_SCROLL_BARS
3113 /* If the fringe is adjacent to the left (right) scroll bar of a
3114 leftmost (rightmost, respectively) window, then extend its
3115 background to the gap between the fringe and the bar. */
3116 if ((WINDOW_LEFTMOST_P (w
)
3117 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
3118 || (WINDOW_RIGHTMOST_P (w
)
3119 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
3121 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3125 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
3126 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
3127 * FRAME_COLUMN_WIDTH (f
));
3129 if (bar_area_x
+ bar_area_width
== x
)
3131 x
= bar_area_x
+ sb_width
;
3132 width
+= bar_area_width
- sb_width
;
3134 else if (x
+ width
== bar_area_x
)
3135 width
+= bar_area_width
- sb_width
;
3140 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3141 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3142 bottom_y
= y
+ height
;
3146 /* Scrolling up. Make sure we don't copy part of the mode
3147 line at the bottom. */
3148 if (from_y
+ run
->height
> bottom_y
)
3149 height
= bottom_y
- from_y
;
3151 height
= run
->height
;
3155 /* Scrolling down. Make sure we don't copy over the mode line.
3157 if (to_y
+ run
->height
> bottom_y
)
3158 height
= bottom_y
- to_y
;
3160 height
= run
->height
;
3165 /* Cursor off. Will be switched on again in x_update_window_end. */
3168 XCopyArea (FRAME_X_DISPLAY (f
),
3169 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3170 f
->output_data
.x
->normal_gc
,
3180 /***********************************************************************
3182 ***********************************************************************/
3186 frame_highlight (struct frame
*f
)
3188 /* We used to only do this if Vx_no_window_manager was non-nil, but
3189 the ICCCM (section 4.1.6) says that the window's border pixmap
3190 and border pixel are window attributes which are "private to the
3191 client", so we can always change it to whatever we want. */
3193 /* I recently started to get errors in this XSetWindowBorder, depending on
3194 the window-manager in use, tho something more is at play since I've been
3195 using that same window-manager binary for ever. Let's not crash just
3196 because of this (bug#9310). */
3197 x_catch_errors (FRAME_X_DISPLAY (f
));
3198 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3199 f
->output_data
.x
->border_pixel
);
3200 x_uncatch_errors ();
3202 x_update_cursor (f
, 1);
3203 x_set_frame_alpha (f
);
3207 frame_unhighlight (struct frame
*f
)
3209 /* We used to only do this if Vx_no_window_manager was non-nil, but
3210 the ICCCM (section 4.1.6) says that the window's border pixmap
3211 and border pixel are window attributes which are "private to the
3212 client", so we can always change it to whatever we want. */
3214 /* Same as above for XSetWindowBorder (bug#9310). */
3215 x_catch_errors (FRAME_X_DISPLAY (f
));
3216 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3217 f
->output_data
.x
->border_tile
);
3218 x_uncatch_errors ();
3220 x_update_cursor (f
, 1);
3221 x_set_frame_alpha (f
);
3224 /* The focus has changed. Update the frames as necessary to reflect
3225 the new situation. Note that we can't change the selected frame
3226 here, because the Lisp code we are interrupting might become confused.
3227 Each event gets marked with the frame in which it occurred, so the
3228 Lisp code can tell when the switch took place by examining the events. */
3231 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3233 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3235 if (frame
!= dpyinfo
->x_focus_frame
)
3237 /* Set this before calling other routines, so that they see
3238 the correct value of x_focus_frame. */
3239 dpyinfo
->x_focus_frame
= frame
;
3241 if (old_focus
&& old_focus
->auto_lower
)
3242 x_lower_frame (old_focus
);
3244 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3245 dpyinfo
->x_pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3247 dpyinfo
->x_pending_autoraise_frame
= NULL
;
3250 x_frame_rehighlight (dpyinfo
);
3253 /* Handle FocusIn and FocusOut state changes for FRAME.
3254 If FRAME has focus and there exists more than one frame, puts
3255 a FOCUS_IN_EVENT into *BUFP. */
3258 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3260 if (type
== FocusIn
)
3262 if (dpyinfo
->x_focus_event_frame
!= frame
)
3264 x_new_focus_frame (dpyinfo
, frame
);
3265 dpyinfo
->x_focus_event_frame
= frame
;
3267 /* Don't stop displaying the initial startup message
3268 for a switch-frame event we don't need. */
3269 /* When run as a daemon, Vterminal_frame is always NIL. */
3270 bufp
->arg
= (((NILP (Vterminal_frame
) || EQ (Fdaemonp (), Qt
))
3271 && CONSP (Vframe_list
)
3272 && !NILP (XCDR (Vframe_list
)))
3274 bufp
->kind
= FOCUS_IN_EVENT
;
3275 XSETFRAME (bufp
->frame_or_window
, frame
);
3278 frame
->output_data
.x
->focus_state
|= state
;
3281 if (FRAME_XIC (frame
))
3282 XSetICFocus (FRAME_XIC (frame
));
3285 else if (type
== FocusOut
)
3287 frame
->output_data
.x
->focus_state
&= ~state
;
3289 if (dpyinfo
->x_focus_event_frame
== frame
)
3291 dpyinfo
->x_focus_event_frame
= 0;
3292 x_new_focus_frame (dpyinfo
, 0);
3294 bufp
->kind
= FOCUS_OUT_EVENT
;
3295 XSETFRAME (bufp
->frame_or_window
, frame
);
3299 if (FRAME_XIC (frame
))
3300 XUnsetICFocus (FRAME_XIC (frame
));
3302 if (frame
->pointer_invisible
)
3303 XTtoggle_invisible_pointer (frame
, 0);
3307 /* Return the Emacs frame-object corresponding to an X window.
3308 It could be the frame's main window or an icon window. */
3310 static struct frame
*
3311 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3313 Lisp_Object tail
, frame
;
3319 FOR_EACH_FRAME (tail
, frame
)
3322 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3324 if (f
->output_data
.x
->hourglass_window
== wdesc
)
3326 #ifdef USE_X_TOOLKIT
3327 if ((f
->output_data
.x
->edit_widget
3328 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
3329 /* A tooltip frame? */
3330 || (!f
->output_data
.x
->edit_widget
3331 && FRAME_X_WINDOW (f
) == wdesc
)
3332 || f
->output_data
.x
->icon_desc
== wdesc
)
3334 #else /* not USE_X_TOOLKIT */
3336 if (f
->output_data
.x
->edit_widget
)
3338 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3339 struct x_output
*x
= f
->output_data
.x
;
3340 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
3343 #endif /* USE_GTK */
3344 if (FRAME_X_WINDOW (f
) == wdesc
3345 || f
->output_data
.x
->icon_desc
== wdesc
)
3347 #endif /* not USE_X_TOOLKIT */
3352 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3354 /* Like x_window_to_frame but also compares the window with the widget's
3357 static struct frame
*
3358 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3360 Lisp_Object tail
, frame
;
3361 struct frame
*f
, *found
= NULL
;
3367 FOR_EACH_FRAME (tail
, frame
)
3372 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
3374 /* This frame matches if the window is any of its widgets. */
3375 x
= f
->output_data
.x
;
3376 if (x
->hourglass_window
== wdesc
)
3381 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3383 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
3386 if (wdesc
== XtWindow (x
->widget
)
3387 || wdesc
== XtWindow (x
->column_widget
)
3388 || wdesc
== XtWindow (x
->edit_widget
))
3390 /* Match if the window is this frame's menubar. */
3391 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3395 else if (FRAME_X_WINDOW (f
) == wdesc
)
3396 /* A tooltip frame. */
3404 /* Likewise, but consider only the menu bar widget. */
3406 static struct frame
*
3407 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
,
3408 const XEvent
*event
)
3410 Window wdesc
= event
->xany
.window
;
3411 Lisp_Object tail
, frame
;
3418 FOR_EACH_FRAME (tail
, frame
)
3421 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3423 x
= f
->output_data
.x
;
3425 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
3428 /* Match if the window is this frame's menubar. */
3429 if (x
->menubar_widget
3430 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3437 /* Return the frame whose principal (outermost) window is WDESC.
3438 If WDESC is some other (smaller) window, we return 0. */
3441 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3443 Lisp_Object tail
, frame
;
3450 FOR_EACH_FRAME (tail
, frame
)
3453 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3455 x
= f
->output_data
.x
;
3459 /* This frame matches if the window is its topmost widget. */
3461 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3462 if (gwdesc
== x
->widget
)
3465 if (wdesc
== XtWindow (x
->widget
))
3469 else if (FRAME_X_WINDOW (f
) == wdesc
)
3470 /* Tooltip frame. */
3476 #else /* !USE_X_TOOLKIT && !USE_GTK */
3478 #define x_any_window_to_frame(d, i) x_window_to_frame (d, i)
3479 #define x_top_window_to_frame(d, i) x_window_to_frame (d, i)
3481 #endif /* USE_X_TOOLKIT || USE_GTK */
3483 /* The focus may have changed. Figure out if it is a real focus change,
3484 by checking both FocusIn/Out and Enter/LeaveNotify events.
3486 Returns FOCUS_IN_EVENT event in *BUFP. */
3489 x_detect_focus_change (struct x_display_info
*dpyinfo
, struct frame
*frame
,
3490 const XEvent
*event
, struct input_event
*bufp
)
3495 switch (event
->type
)
3500 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3502 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3504 if (event
->xcrossing
.detail
!= NotifyInferior
3505 && event
->xcrossing
.focus
3506 && ! (focus_state
& FOCUS_EXPLICIT
))
3507 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3509 dpyinfo
, frame
, bufp
);
3515 x_focus_changed (event
->type
,
3516 (event
->xfocus
.detail
== NotifyPointer
?
3517 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3518 dpyinfo
, frame
, bufp
);
3522 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3524 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3525 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3526 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3533 #if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
3534 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3537 x_mouse_leave (struct x_display_info
*dpyinfo
)
3539 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3543 /* The focus has changed, or we have redirected a frame's focus to
3544 another frame (this happens when a frame uses a surrogate
3545 mini-buffer frame). Shift the highlight as appropriate.
3547 The FRAME argument doesn't necessarily have anything to do with which
3548 frame is being highlighted or un-highlighted; we only use it to find
3549 the appropriate X display info. */
3552 XTframe_rehighlight (struct frame
*frame
)
3554 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
3558 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3560 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3562 if (dpyinfo
->x_focus_frame
)
3564 dpyinfo
->x_highlight_frame
3565 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3566 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3567 : dpyinfo
->x_focus_frame
);
3568 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3570 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
3571 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3575 dpyinfo
->x_highlight_frame
= 0;
3577 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3580 frame_unhighlight (old_highlight
);
3581 if (dpyinfo
->x_highlight_frame
)
3582 frame_highlight (dpyinfo
->x_highlight_frame
);
3588 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3590 /* Initialize mode_switch_bit and modifier_meaning. */
3592 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3594 int min_code
, max_code
;
3597 XModifierKeymap
*mods
;
3599 dpyinfo
->meta_mod_mask
= 0;
3600 dpyinfo
->shift_lock_mask
= 0;
3601 dpyinfo
->alt_mod_mask
= 0;
3602 dpyinfo
->super_mod_mask
= 0;
3603 dpyinfo
->hyper_mod_mask
= 0;
3605 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3607 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3608 min_code
, max_code
- min_code
+ 1,
3610 mods
= XGetModifierMapping (dpyinfo
->display
);
3612 /* Scan the modifier table to see which modifier bits the Meta and
3613 Alt keysyms are on. */
3615 int row
, col
; /* The row and column in the modifier table. */
3616 int found_alt_or_meta
;
3618 for (row
= 3; row
< 8; row
++)
3620 found_alt_or_meta
= 0;
3621 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3623 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3625 /* Zeroes are used for filler. Skip them. */
3629 /* Are any of this keycode's keysyms a meta key? */
3633 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3635 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3641 found_alt_or_meta
= 1;
3642 dpyinfo
->meta_mod_mask
|= (1 << row
);
3647 found_alt_or_meta
= 1;
3648 dpyinfo
->alt_mod_mask
|= (1 << row
);
3653 if (!found_alt_or_meta
)
3654 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3655 code_col
= syms_per_code
;
3656 col
= mods
->max_keypermod
;
3661 if (!found_alt_or_meta
)
3662 dpyinfo
->super_mod_mask
|= (1 << row
);
3663 code_col
= syms_per_code
;
3664 col
= mods
->max_keypermod
;
3668 /* Ignore this if it's not on the lock modifier. */
3669 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3670 dpyinfo
->shift_lock_mask
= LockMask
;
3671 code_col
= syms_per_code
;
3672 col
= mods
->max_keypermod
;
3681 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3682 if (! dpyinfo
->meta_mod_mask
)
3684 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3685 dpyinfo
->alt_mod_mask
= 0;
3688 /* If some keys are both alt and meta,
3689 make them just meta, not alt. */
3690 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3692 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3696 XFreeModifiermap (mods
);
3699 /* Convert between the modifier bits X uses and the modifier bits
3703 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
3705 int mod_meta
= meta_modifier
;
3706 int mod_alt
= alt_modifier
;
3707 int mod_hyper
= hyper_modifier
;
3708 int mod_super
= super_modifier
;
3711 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3712 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
3713 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3714 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
3715 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3716 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
3717 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3718 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
3720 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3721 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3722 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3723 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3724 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3725 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3729 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
3731 EMACS_INT mod_meta
= meta_modifier
;
3732 EMACS_INT mod_alt
= alt_modifier
;
3733 EMACS_INT mod_hyper
= hyper_modifier
;
3734 EMACS_INT mod_super
= super_modifier
;
3738 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3739 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
3740 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3741 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
3742 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3743 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
3744 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3745 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
3748 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3749 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3750 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3751 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3752 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3753 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3756 /* Convert a keysym to its name. */
3759 x_get_keysym_name (int keysym
)
3764 value
= XKeysymToString (keysym
);
3770 /* Mouse clicks and mouse movement. Rah.
3772 Formerly, we used PointerMotionHintMask (in standard_event_mask)
3773 so that we would have to call XQueryPointer after each MotionNotify
3774 event to ask for another such event. However, this made mouse tracking
3775 slow, and there was a bug that made it eventually stop.
3777 Simply asking for MotionNotify all the time seems to work better.
3779 In order to avoid asking for motion events and then throwing most
3780 of them away or busy-polling the server for mouse positions, we ask
3781 the server for pointer motion hints. This means that we get only
3782 one event per group of mouse movements. "Groups" are delimited by
3783 other kinds of events (focus changes and button clicks, for
3784 example), or by XQueryPointer calls; when one of these happens, we
3785 get another MotionNotify event the next time the mouse moves. This
3786 is at least as efficient as getting motion events when mouse
3787 tracking is on, and I suspect only negligibly worse when tracking
3790 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3792 If the event is a button press, then note that we have grabbed
3796 construct_mouse_click (struct input_event
*result
,
3797 const XButtonEvent
*event
,
3800 /* Make the event type NO_EVENT; we'll change that when we decide
3802 result
->kind
= MOUSE_CLICK_EVENT
;
3803 result
->code
= event
->button
- Button1
;
3804 result
->timestamp
= event
->time
;
3805 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
),
3807 | (event
->type
== ButtonRelease
3811 XSETINT (result
->x
, event
->x
);
3812 XSETINT (result
->y
, event
->y
);
3813 XSETFRAME (result
->frame_or_window
, f
);
3818 /* Function to report a mouse movement to the mainstream Emacs code.
3819 The input handler calls this.
3821 We have received a mouse movement event, which is given in *event.
3822 If the mouse is over a different glyph than it was last time, tell
3823 the mainstream emacs code by setting mouse_moved. If not, ask for
3824 another motion event, so we can check again the next time it moves. */
3827 note_mouse_movement (struct frame
*frame
, const XMotionEvent
*event
)
3830 struct x_display_info
*dpyinfo
;
3832 if (!FRAME_X_OUTPUT (frame
))
3835 dpyinfo
= FRAME_DISPLAY_INFO (frame
);
3836 dpyinfo
->last_mouse_movement_time
= event
->time
;
3837 dpyinfo
->last_mouse_motion_frame
= frame
;
3838 dpyinfo
->last_mouse_motion_x
= event
->x
;
3839 dpyinfo
->last_mouse_motion_y
= event
->y
;
3841 if (event
->window
!= FRAME_X_WINDOW (frame
))
3843 frame
->mouse_moved
= 1;
3844 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3845 note_mouse_highlight (frame
, -1, -1);
3846 dpyinfo
->last_mouse_glyph_frame
= NULL
;
3851 /* Has the mouse moved off the glyph it was on at the last sighting? */
3852 r
= &dpyinfo
->last_mouse_glyph
;
3853 if (frame
!= dpyinfo
->last_mouse_glyph_frame
3854 || event
->x
< r
->x
|| event
->x
>= r
->x
+ r
->width
3855 || event
->y
< r
->y
|| event
->y
>= r
->y
+ r
->height
)
3857 frame
->mouse_moved
= 1;
3858 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3859 note_mouse_highlight (frame
, event
->x
, event
->y
);
3860 /* Remember which glyph we're now on. */
3861 remember_mouse_glyph (frame
, event
->x
, event
->y
, r
);
3862 dpyinfo
->last_mouse_glyph_frame
= frame
;
3869 /* Return the current position of the mouse.
3870 *FP should be a frame which indicates which display to ask about.
3872 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3873 and *PART to the frame, window, and scroll bar part that the mouse
3874 is over. Set *X and *Y to the portion and whole of the mouse's
3875 position on the scroll bar.
3877 If the mouse movement started elsewhere, set *FP to the frame the
3878 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3881 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
3882 was at this position.
3884 Don't store anything if we don't have a valid set of values to report.
3886 This clears the mouse_moved flag, so we can wait for the next mouse
3890 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3891 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3895 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
3899 if (dpyinfo
->last_mouse_scroll_bar
&& insist
== 0)
3900 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
3906 Window dummy_window
;
3909 Lisp_Object frame
, tail
;
3911 /* Clear the mouse-moved flag for every frame on this display. */
3912 FOR_EACH_FRAME (tail
, frame
)
3913 if (FRAME_X_P (XFRAME (frame
))
3914 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3915 XFRAME (frame
)->mouse_moved
= 0;
3917 dpyinfo
->last_mouse_scroll_bar
= NULL
;
3919 /* Figure out which root window we're on. */
3920 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3921 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3923 /* The root window which contains the pointer. */
3926 /* Trash which we can't trust if the pointer is on
3927 a different screen. */
3930 /* The position on that root window. */
3933 /* More trash we can't trust. */
3936 /* Modifier keys and pointer buttons, about which
3938 (unsigned int *) &dummy
);
3940 /* Now we have a position on the root; find the innermost window
3941 containing the pointer. */
3945 int parent_x
= 0, parent_y
= 0;
3949 /* XTranslateCoordinates can get errors if the window
3950 structure is changing at the same time this function
3951 is running. So at least we must not crash from them. */
3953 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3955 if (x_mouse_grabbed (dpyinfo
))
3957 /* If mouse was grabbed on a frame, give coords for that frame
3958 even if the mouse is now outside it. */
3959 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3965 FRAME_X_WINDOW (dpyinfo
->last_mouse_frame
),
3967 /* From-position, to-position. */
3968 root_x
, root_y
, &win_x
, &win_y
,
3972 f1
= dpyinfo
->last_mouse_frame
;
3978 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3980 /* From-window, to-window. */
3983 /* From-position, to-position. */
3984 root_x
, root_y
, &win_x
, &win_y
,
3989 if (child
== None
|| child
== win
)
3992 /* We don't wan't to know the innermost window. We
3993 want the edit window. For non-Gtk+ the innermost
3994 window is the edit window. For Gtk+ it might not
3995 be. It might be the tool bar for example. */
3996 if (x_window_to_frame (dpyinfo
, win
))
4004 /* Now we know that:
4005 win is the innermost window containing the pointer
4006 (XTC says it has no child containing the pointer),
4007 win_x and win_y are the pointer's position in it
4008 (XTC did this the last time through), and
4009 parent_x and parent_y are the pointer's position in win's parent.
4010 (They are what win_x and win_y were when win was child.
4011 If win is the root window, it has no parent, and
4012 parent_{x,y} are invalid, but that's okay, because we'll
4013 never use them in that case.) */
4016 /* We don't wan't to know the innermost window. We
4017 want the edit window. */
4018 f1
= x_window_to_frame (dpyinfo
, win
);
4020 /* Is win one of our frames? */
4021 f1
= x_any_window_to_frame (dpyinfo
, win
);
4024 #ifdef USE_X_TOOLKIT
4025 /* If we end up with the menu bar window, say it's not
4028 && f1
->output_data
.x
->menubar_widget
4029 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4031 #endif /* USE_X_TOOLKIT */
4034 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4037 x_uncatch_errors ();
4039 /* If not, is it one of our scroll bars? */
4042 struct scroll_bar
*bar
;
4044 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4048 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4054 if (f1
== 0 && insist
> 0)
4055 f1
= SELECTED_FRAME ();
4059 /* Ok, we found a frame. Store all the values.
4060 last_mouse_glyph is a rectangle used to reduce the
4061 generation of mouse events. To not miss any motion
4062 events, we must divide the frame into rectangles of the
4063 size of the smallest character that could be displayed
4064 on it, i.e. into the same rectangles that matrices on
4065 the frame are divided into. */
4067 /* FIXME: what if F1 is not an X frame? */
4068 dpyinfo
= FRAME_DISPLAY_INFO (f1
);
4069 remember_mouse_glyph (f1
, win_x
, win_y
, &dpyinfo
->last_mouse_glyph
);
4070 dpyinfo
->last_mouse_glyph_frame
= f1
;
4075 XSETINT (*x
, win_x
);
4076 XSETINT (*y
, win_y
);
4077 *timestamp
= dpyinfo
->last_mouse_movement_time
;
4087 /***********************************************************************
4089 ***********************************************************************/
4091 /* Scroll bar support. */
4093 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4095 This can be called in GC, so we have to make sure to strip off mark
4098 static struct scroll_bar
*
4099 x_window_to_scroll_bar (Display
*display
, Window window_id
)
4101 Lisp_Object tail
, frame
;
4103 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4104 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4105 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4107 FOR_EACH_FRAME (tail
, frame
)
4109 Lisp_Object bar
, condemned
;
4111 if (! FRAME_X_P (XFRAME (frame
)))
4114 /* Scan this frame's scroll bar list for a scroll bar with the
4116 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4117 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4118 /* This trick allows us to search both the ordinary and
4119 condemned scroll bar lists with one loop. */
4120 ! NILP (bar
) || (bar
= condemned
,
4123 bar
= XSCROLL_BAR (bar
)->next
)
4124 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4125 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4126 return XSCROLL_BAR (bar
);
4133 #if defined USE_LUCID
4135 /* Return the Lucid menu bar WINDOW is part of. Return null
4136 if WINDOW is not part of a menu bar. */
4139 x_window_to_menu_bar (Window window
)
4141 Lisp_Object tail
, frame
;
4143 FOR_EACH_FRAME (tail
, frame
)
4144 if (FRAME_X_P (XFRAME (frame
)))
4146 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4148 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4154 #endif /* USE_LUCID */
4157 /************************************************************************
4159 ************************************************************************/
4161 #ifdef USE_TOOLKIT_SCROLL_BARS
4163 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
4165 /* Lisp window being scrolled. Set when starting to interact with
4166 a toolkit scroll bar, reset to nil when ending the interaction. */
4168 static Lisp_Object window_being_scrolled
;
4170 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4171 that movements of 1/20 of the screen size are mapped to up/down. */
4174 /* Id of action hook installed for scroll bars. */
4176 static XtActionHookId action_hook_id
;
4178 static Boolean xaw3d_arrow_scroll
;
4180 /* Whether the drag scrolling maintains the mouse at the top of the
4181 thumb. If not, resizing the thumb needs to be done more carefully
4182 to avoid jerkiness. */
4184 static Boolean xaw3d_pick_top
;
4186 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4187 bars are used.. The hook is responsible for detecting when
4188 the user ends an interaction with the scroll bar, and generates
4189 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4192 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4193 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4196 const char *end_action
;
4199 scroll_bar_p
= XmIsScrollBar (widget
);
4200 end_action
= "Release";
4201 #else /* !USE_MOTIF i.e. use Xaw */
4202 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4203 end_action
= "EndScroll";
4204 #endif /* USE_MOTIF */
4207 && strcmp (action_name
, end_action
) == 0
4208 && WINDOWP (window_being_scrolled
))
4211 struct scroll_bar
*bar
;
4213 x_send_scroll_bar_event (window_being_scrolled
,
4214 scroll_bar_end_scroll
, 0, 0);
4215 w
= XWINDOW (window_being_scrolled
);
4216 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4218 if (bar
->dragging
!= -1)
4221 /* The thumb size is incorrect while dragging: fix it. */
4222 set_vertical_scroll_bar (w
);
4224 window_being_scrolled
= Qnil
;
4225 #if defined (USE_LUCID)
4226 bar
->last_seen_part
= scroll_bar_nowhere
;
4228 /* Xt timeouts no longer needed. */
4229 toolkit_scroll_bar_interaction
= 0;
4232 #endif /* not USE_GTK */
4234 /* Send a client message with message type Xatom_Scrollbar for a
4235 scroll action to the frame of WINDOW. PART is a value identifying
4236 the part of the scroll bar that was clicked on. PORTION is the
4237 amount to scroll of a whole of WHOLE. */
4240 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4243 XClientMessageEvent
*ev
= &event
.xclient
;
4244 struct window
*w
= XWINDOW (window
);
4245 struct frame
*f
= XFRAME (w
->frame
);
4246 intptr_t iw
= (intptr_t) w
;
4247 enum { BITS_PER_INTPTR
= CHAR_BIT
* sizeof iw
};
4248 verify (BITS_PER_INTPTR
<= 64);
4249 int sign_shift
= BITS_PER_INTPTR
- 32;
4253 /* Construct a ClientMessage event to send to the frame. */
4254 ev
->type
= ClientMessage
;
4255 ev
->message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4256 ev
->display
= FRAME_X_DISPLAY (f
);
4257 ev
->window
= FRAME_X_WINDOW (f
);
4260 /* A 32-bit X client on a 64-bit X server can pass a window pointer
4261 as-is. A 64-bit client on a 32-bit X server is in trouble
4262 because a pointer does not fit and would be truncated while
4263 passing through the server. So use two slots and hope that X12
4264 will resolve such issues someday. */
4265 ev
->data
.l
[0] = iw
>> 31 >> 1;
4266 ev
->data
.l
[1] = sign_shift
<= 0 ? iw
: iw
<< sign_shift
>> sign_shift
;
4267 ev
->data
.l
[2] = part
;
4268 ev
->data
.l
[3] = portion
;
4269 ev
->data
.l
[4] = whole
;
4271 /* Make Xt timeouts work while the scroll bar is active. */
4272 #ifdef USE_X_TOOLKIT
4273 toolkit_scroll_bar_interaction
= 1;
4274 x_activate_timeout_atimer ();
4277 /* Setting the event mask to zero means that the message will
4278 be sent to the client that created the window, and if that
4279 window no longer exists, no event will be sent. */
4280 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4285 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4289 x_scroll_bar_to_input_event (const XEvent
*event
,
4290 struct input_event
*ievent
)
4292 const XClientMessageEvent
*ev
= &event
->xclient
;
4296 /* See the comment in the function above. */
4297 intptr_t iw0
= ev
->data
.l
[0];
4298 intptr_t iw1
= ev
->data
.l
[1];
4299 intptr_t iw
= (iw0
<< 31 << 1) + (iw1
& 0xffffffffu
);
4300 w
= (struct window
*) iw
;
4302 XSETWINDOW (window
, w
);
4304 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4305 ievent
->frame_or_window
= window
;
4308 ievent
->timestamp
= CurrentTime
;
4311 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4314 ievent
->part
= ev
->data
.l
[2];
4315 ievent
->x
= make_number (ev
->data
.l
[3]);
4316 ievent
->y
= make_number (ev
->data
.l
[4]);
4317 ievent
->modifiers
= 0;
4323 /* Minimum and maximum values used for Motif scroll bars. */
4325 #define XM_SB_MAX 10000000
4328 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4329 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4330 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4333 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4335 struct scroll_bar
*bar
= client_data
;
4336 XmScrollBarCallbackStruct
*cs
= call_data
;
4337 int part
= -1, whole
= 0, portion
= 0;
4341 case XmCR_DECREMENT
:
4343 part
= scroll_bar_up_arrow
;
4346 case XmCR_INCREMENT
:
4348 part
= scroll_bar_down_arrow
;
4351 case XmCR_PAGE_DECREMENT
:
4353 part
= scroll_bar_above_handle
;
4356 case XmCR_PAGE_INCREMENT
:
4358 part
= scroll_bar_below_handle
;
4363 part
= scroll_bar_to_top
;
4366 case XmCR_TO_BOTTOM
:
4368 part
= scroll_bar_to_bottom
;
4375 /* Get the slider size. */
4377 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4380 whole
= XM_SB_MAX
- slider_size
;
4381 portion
= min (cs
->value
, whole
);
4382 part
= scroll_bar_handle
;
4383 bar
->dragging
= cs
->value
;
4387 case XmCR_VALUE_CHANGED
:
4393 window_being_scrolled
= bar
->window
;
4394 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4398 #elif defined USE_GTK
4400 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4401 bar widget. DATA is a pointer to the scroll_bar structure. */
4404 xg_scroll_callback (GtkRange
*range
,
4405 GtkScrollType scroll
,
4409 struct scroll_bar
*bar
= user_data
;
4411 int part
= -1, whole
= 0, portion
= 0;
4412 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4413 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4415 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4416 position
= gtk_adjustment_get_value (adj
);
4421 case GTK_SCROLL_JUMP
:
4422 /* Buttons 1 2 or 3 must be grabbed. */
4423 if (FRAME_DISPLAY_INFO (f
)->grabbed
!= 0
4424 && FRAME_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4426 part
= scroll_bar_handle
;
4427 whole
= gtk_adjustment_get_upper (adj
) -
4428 gtk_adjustment_get_page_size (adj
);
4429 portion
= min ((int)position
, whole
);
4430 bar
->dragging
= portion
;
4433 case GTK_SCROLL_STEP_BACKWARD
:
4434 part
= scroll_bar_up_arrow
;
4437 case GTK_SCROLL_STEP_FORWARD
:
4438 part
= scroll_bar_down_arrow
;
4441 case GTK_SCROLL_PAGE_BACKWARD
:
4442 part
= scroll_bar_above_handle
;
4445 case GTK_SCROLL_PAGE_FORWARD
:
4446 part
= scroll_bar_below_handle
;
4453 window_being_scrolled
= bar
->window
;
4454 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4460 /* Callback for button release. Sets dragging to -1 when dragging is done. */
4463 xg_end_scroll_callback (GtkWidget
*widget
,
4464 GdkEventButton
*event
,
4467 struct scroll_bar
*bar
= user_data
;
4469 if (WINDOWP (window_being_scrolled
))
4471 x_send_scroll_bar_event (window_being_scrolled
,
4472 scroll_bar_end_scroll
, 0, 0);
4473 window_being_scrolled
= Qnil
;
4480 #else /* not USE_GTK and not USE_MOTIF */
4482 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4483 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4484 scroll bar struct. CALL_DATA is a pointer to a float saying where
4488 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4490 struct scroll_bar
*bar
= client_data
;
4491 float *top_addr
= call_data
;
4492 float top
= *top_addr
;
4494 int whole
, portion
, height
;
4495 enum scroll_bar_part part
;
4497 /* Get the size of the thumb, a value between 0 and 1. */
4499 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4503 portion
= shown
< 1 ? top
* whole
: 0;
4505 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
4506 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4507 the bottom, so we force the scrolling whenever we see that we're
4508 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4509 we try to ensure that we always stay two pixels away from the
4511 part
= scroll_bar_down_arrow
;
4513 part
= scroll_bar_handle
;
4515 window_being_scrolled
= bar
->window
;
4516 bar
->dragging
= portion
;
4517 bar
->last_seen_part
= part
;
4518 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4522 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4523 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4524 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4525 the scroll bar. CALL_DATA is an integer specifying the action that
4526 has taken place. Its magnitude is in the range 0..height of the
4527 scroll bar. Negative values mean scroll towards buffer start.
4528 Values < height of scroll bar mean line-wise movement. */
4531 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4533 struct scroll_bar
*bar
= client_data
;
4534 /* The position really is stored cast to a pointer. */
4535 int position
= (intptr_t) call_data
;
4537 enum scroll_bar_part part
;
4539 /* Get the height of the scroll bar. */
4541 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4544 if (eabs (position
) >= height
)
4545 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4547 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4548 it maps line-movement to call_data = max(5, height/20). */
4549 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4550 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4552 part
= scroll_bar_move_ratio
;
4554 window_being_scrolled
= bar
->window
;
4556 bar
->last_seen_part
= part
;
4557 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4560 #endif /* not USE_GTK and not USE_MOTIF */
4562 #define SCROLL_BAR_NAME "verticalScrollBar"
4564 /* Create the widget for scroll bar BAR on frame F. Record the widget
4565 and X window of the scroll bar in BAR. */
4569 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4571 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4574 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4575 G_CALLBACK (xg_end_scroll_callback
),
4580 #else /* not USE_GTK */
4583 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4589 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4590 unsigned long pixel
;
4595 /* Set resources. Create the widget. */
4596 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4597 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4598 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4599 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4600 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4601 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4602 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4604 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4607 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4611 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4614 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4618 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4619 (char *) scroll_bar_name
, av
, ac
);
4621 /* Add one callback for everything that can happen. */
4622 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4624 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4626 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4628 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4630 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4632 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4634 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4637 /* Realize the widget. Only after that is the X window created. */
4638 XtRealizeWidget (widget
);
4640 /* Set the cursor to an arrow. I didn't find a resource to do that.
4641 And I'm wondering why it hasn't an arrow cursor by default. */
4642 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4643 f
->output_data
.x
->nontext_cursor
);
4645 #else /* !USE_MOTIF i.e. use Xaw */
4647 /* Set resources. Create the widget. The background of the
4648 Xaw3d scroll bar widget is a little bit light for my taste.
4649 We don't alter it here to let users change it according
4650 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4651 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4652 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4653 /* For smoother scrolling with Xaw3d -sm */
4654 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4656 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4659 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4663 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4666 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4670 /* Top/bottom shadow colors. */
4672 /* Allocate them, if necessary. */
4673 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4675 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4678 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4679 FRAME_X_COLORMAP (f
),
4680 &pixel
, 1.2, 0x8000))
4682 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4685 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4687 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4690 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4691 FRAME_X_COLORMAP (f
),
4692 &pixel
, 0.6, 0x4000))
4694 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4698 #ifdef XtNbeNiceToColormap
4699 /* Tell the toolkit about them. */
4700 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4701 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4702 /* We tried to allocate a color for the top/bottom shadow, and
4703 failed, so tell Xaw3d to use dithering instead. */
4704 /* But only if we have a small colormap. Xaw3d can allocate nice
4707 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4708 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4712 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4713 be more consistent with other emacs 3d colors, and since Xaw3d is
4714 not good at dealing with allocation failure. */
4716 /* This tells Xaw3d to use real colors instead of dithering for
4718 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4721 /* Specify the colors. */
4722 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4725 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4728 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4731 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4737 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4738 f
->output_data
.x
->edit_widget
, av
, ac
);
4741 char const *initial
= "";
4742 char const *val
= initial
;
4743 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4744 #ifdef XtNarrowScrollbars
4745 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4747 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4748 if (xaw3d_arrow_scroll
|| val
== initial
)
4749 { /* ARROW_SCROLL */
4750 xaw3d_arrow_scroll
= True
;
4751 /* Isn't that just a personal preference ? --Stef */
4752 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4756 /* Define callbacks. */
4757 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4758 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4761 /* Realize the widget. Only after that is the X window created. */
4762 XtRealizeWidget (widget
);
4764 #endif /* !USE_MOTIF */
4766 /* Install an action hook that lets us detect when the user
4767 finishes interacting with a scroll bar. */
4768 if (action_hook_id
== 0)
4769 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4771 /* Remember X window and widget in the scroll bar vector. */
4772 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4773 xwindow
= XtWindow (widget
);
4774 bar
->x_window
= xwindow
;
4778 #endif /* not USE_GTK */
4781 /* Set the thumb size and position of scroll bar BAR. We are currently
4782 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4786 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4788 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4791 #else /* not USE_GTK */
4793 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4796 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4797 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4804 if (scroll_bar_adjust_thumb_portion_p
)
4806 /* We use an estimate of 30 chars per line rather than the real
4807 `portion' value. This has the disadvantage that the thumb size
4808 is not very representative, but it makes our life a lot easier.
4809 Otherwise, we have to constantly adjust the thumb size, which
4810 we can't always do quickly enough: while dragging, the size of
4811 the thumb might prevent the user from dragging the thumb all the
4812 way to the end. but Motif and some versions of Xaw3d don't allow
4813 updating the thumb size while dragging. Also, even if we can update
4814 its size, the update will often happen too late.
4815 If you don't believe it, check out revision 1.650 of xterm.c to see
4816 what hoops we were going through and the still poor behavior we got. */
4817 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4818 /* When the thumb is at the bottom, position == whole.
4819 So we need to increase `whole' to make space for the thumb. */
4827 top
= (float) position
/ whole
;
4828 shown
= (float) portion
/ whole
;
4831 if (bar
->dragging
== -1)
4835 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4836 is the scroll bar's maximum and MIN is the scroll bar's minimum
4838 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
4840 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4841 value
= top
* XM_SB_MAX
;
4842 value
= min (value
, XM_SB_MAX
- size
);
4844 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4846 #else /* !USE_MOTIF i.e. use Xaw */
4852 top
= (float) position
/ whole
;
4853 shown
= (float) portion
/ whole
;
4857 float old_top
, old_shown
;
4859 XtVaGetValues (widget
,
4860 XtNtopOfThumb
, &old_top
,
4861 XtNshown
, &old_shown
,
4865 /* Massage the top+shown values. */
4866 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
4867 top
= max (0, min (1, top
));
4870 #if ! defined (HAVE_XAW3D)
4871 /* With Xaw, 'top' values too closer to 1.0 may
4872 cause the thumb to disappear. Fix that. */
4873 top
= min (top
, 0.99f
);
4875 /* Keep two pixels available for moving the thumb down. */
4876 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
4877 #if ! defined (HAVE_XAW3D)
4878 /* Likewise with too small 'shown'. */
4879 shown
= max (shown
, 0.01f
);
4882 /* If the call to XawScrollbarSetThumb below doesn't seem to
4883 work, check that 'NARROWPROTO' is defined in src/config.h.
4884 If this is not so, most likely you need to fix configure. */
4885 if (top
!= old_top
|| shown
!= old_shown
)
4887 if (bar
->dragging
== -1)
4888 XawScrollbarSetThumb (widget
, top
, shown
);
4891 /* Try to make the scrolling a tad smoother. */
4892 if (!xaw3d_pick_top
)
4893 shown
= min (shown
, old_shown
);
4895 XawScrollbarSetThumb (widget
, top
, shown
);
4899 #endif /* !USE_MOTIF */
4903 #endif /* not USE_GTK */
4905 #endif /* USE_TOOLKIT_SCROLL_BARS */
4909 /************************************************************************
4910 Scroll bars, general
4911 ************************************************************************/
4913 /* Create a scroll bar and return the scroll bar vector for it. W is
4914 the Emacs window on which to create the scroll bar. TOP, LEFT,
4915 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4918 static struct scroll_bar
*
4919 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
4921 struct frame
*f
= XFRAME (w
->frame
);
4922 struct scroll_bar
*bar
4923 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4928 #ifdef USE_TOOLKIT_SCROLL_BARS
4929 x_create_toolkit_scroll_bar (f
, bar
);
4930 #else /* not USE_TOOLKIT_SCROLL_BARS */
4932 XSetWindowAttributes a
;
4936 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4937 if (a
.background_pixel
== -1)
4938 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4940 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4941 | ButtonMotionMask
| PointerMotionHintMask
4943 a
.cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4945 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4947 /* Clear the area of W that will serve as a scroll bar. This is
4948 for the case that a window has been split horizontally. In
4949 this case, no clear_frame is generated to reduce flickering. */
4950 if (width
> 0 && height
> 0)
4951 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4952 left
, top
, width
, window_box_height (w
));
4954 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4955 /* Position and size of scroll bar. */
4956 left
, top
, width
, height
,
4957 /* Border width, depth, class, and visual. */
4964 bar
->x_window
= window
;
4966 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4968 XSETWINDOW (bar
->window
, w
);
4972 bar
->height
= height
;
4976 bar
->fringe_extended_p
= 0;
4977 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
4978 bar
->last_seen_part
= scroll_bar_nowhere
;
4981 /* Add bar to its frame's list of scroll bars. */
4982 bar
->next
= FRAME_SCROLL_BARS (f
);
4984 XSETVECTOR (barobj
, bar
);
4985 fset_scroll_bars (f
, barobj
);
4986 if (!NILP (bar
->next
))
4987 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4989 /* Map the window/widget. */
4990 #ifdef USE_TOOLKIT_SCROLL_BARS
4993 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
4994 left
,width
, max (height
, 1));
4995 #else /* not USE_GTK */
4996 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4997 XtConfigureWidget (scroll_bar
, left
, top
, width
, max (height
, 1), 0);
4998 XtMapWidget (scroll_bar
);
4999 #endif /* not USE_GTK */
5001 #else /* not USE_TOOLKIT_SCROLL_BARS */
5002 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5003 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5010 #ifndef USE_TOOLKIT_SCROLL_BARS
5012 /* Draw BAR's handle in the proper position.
5014 If the handle is already drawn from START to END, don't bother
5015 redrawing it, unless REBUILD is non-zero; in that case, always
5016 redraw it. (REBUILD is handy for drawing the handle after expose
5019 Normally, we want to constrain the start and end of the handle to
5020 fit inside its rectangle, but if the user is dragging the scroll
5021 bar handle, we want to let them drag it down all the way, so that
5022 the bar's top is as far down as it goes; otherwise, there's no way
5023 to move to the very end of the buffer. */
5026 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
5028 bool dragging
= bar
->dragging
!= -1;
5029 Window w
= bar
->x_window
;
5030 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5031 GC gc
= f
->output_data
.x
->normal_gc
;
5033 /* If the display is already accurate, do nothing. */
5035 && start
== bar
->start
5042 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5043 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5044 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5046 /* Make sure the values are reasonable, and try to preserve
5047 the distance between start and end. */
5049 int length
= end
- start
;
5053 else if (start
> top_range
)
5055 end
= start
+ length
;
5059 else if (end
> top_range
&& ! dragging
)
5063 /* Store the adjusted setting in the scroll bar. */
5067 /* Clip the end position, just for display. */
5068 if (end
> top_range
)
5071 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5072 below top positions, to make sure the handle is always at least
5073 that many pixels tall. */
5074 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5076 /* Draw the empty space above the handle. Note that we can't clear
5077 zero-height areas; that means "clear to end of window." */
5079 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5080 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5081 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5082 inside_width
, start
);
5084 /* Change to proper foreground color if one is specified. */
5085 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5086 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5087 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5089 /* Draw the handle itself. */
5090 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5091 /* x, y, width, height */
5092 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5093 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5094 inside_width
, end
- start
);
5096 /* Restore the foreground color of the GC if we changed it above. */
5097 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5098 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5099 FRAME_FOREGROUND_PIXEL (f
));
5101 /* Draw the empty space below the handle. Note that we can't
5102 clear zero-height areas; that means "clear to end of window." */
5103 if (end
< inside_height
)
5104 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5105 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5106 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5107 inside_width
, inside_height
- end
);
5113 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5115 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5119 x_scroll_bar_remove (struct scroll_bar
*bar
)
5121 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5124 #ifdef USE_TOOLKIT_SCROLL_BARS
5126 xg_remove_scroll_bar (f
, bar
->x_window
);
5127 #else /* not USE_GTK */
5128 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5129 #endif /* not USE_GTK */
5131 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5134 /* Dissociate this scroll bar from its window. */
5135 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5141 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5142 that we are displaying PORTION characters out of a total of WHOLE
5143 characters, starting at POSITION. If WINDOW has no scroll bar,
5147 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5149 struct frame
*f
= XFRAME (w
->frame
);
5151 struct scroll_bar
*bar
;
5152 int top
, height
, left
, sb_left
, width
, sb_width
;
5153 int window_y
, window_height
;
5154 #ifdef USE_TOOLKIT_SCROLL_BARS
5155 bool fringe_extended_p
;
5158 /* Get window dimensions. */
5159 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
5161 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5162 height
= window_height
;
5164 /* Compute the left edge of the scroll bar area. */
5165 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5167 /* Compute the width of the scroll bar which might be less than
5168 the width of the area reserved for the scroll bar. */
5169 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5170 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5174 /* Compute the left edge of the scroll bar. */
5175 #ifdef USE_TOOLKIT_SCROLL_BARS
5176 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5177 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5179 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5181 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5182 sb_left
= left
+ width
- sb_width
;
5187 #ifdef USE_TOOLKIT_SCROLL_BARS
5188 fringe_extended_p
= WINDOW_FRINGE_EXTENDED_P (w
);
5191 /* Does the scroll bar exist yet? */
5192 if (NILP (w
->vertical_scroll_bar
))
5194 if (width
> 0 && height
> 0)
5197 #ifdef USE_TOOLKIT_SCROLL_BARS
5198 if (fringe_extended_p
)
5199 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5200 sb_left
, top
, sb_width
, height
);
5203 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5204 left
, top
, width
, height
);
5208 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5212 /* It may just need to be moved and resized. */
5213 unsigned int mask
= 0;
5215 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5219 if (sb_left
!= bar
->left
)
5221 if (top
!= bar
->top
)
5223 if (sb_width
!= bar
->width
)
5225 if (height
!= bar
->height
)
5228 #ifdef USE_TOOLKIT_SCROLL_BARS
5230 /* Move/size the scroll bar widget. */
5231 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5233 /* Since toolkit scroll bars are smaller than the space reserved
5234 for them on the frame, we have to clear "under" them. */
5235 if (width
> 0 && height
> 0)
5237 if (fringe_extended_p
)
5238 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5239 sb_left
, top
, sb_width
, height
);
5241 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5242 left
, top
, width
, height
);
5245 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
5246 sb_left
, sb_width
, max (height
, 1));
5247 #else /* not USE_GTK */
5248 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5249 sb_left
, top
, sb_width
, max (height
, 1), 0);
5250 #endif /* not USE_GTK */
5252 #else /* not USE_TOOLKIT_SCROLL_BARS */
5254 /* Clear areas not covered by the scroll bar because it's not as
5255 wide as the area reserved for it. This makes sure a
5256 previous mode line display is cleared after C-x 2 C-x 1, for
5259 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5260 int rest
= area_width
- sb_width
;
5261 if (rest
> 0 && height
> 0)
5263 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5264 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5265 left
+ area_width
- rest
, top
, rest
, height
);
5267 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5268 left
, top
, rest
, height
);
5272 /* Move/size the scroll bar window. */
5279 wc
.width
= sb_width
;
5281 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5285 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5287 /* Remember new settings. */
5288 bar
->left
= sb_left
;
5290 bar
->width
= sb_width
;
5291 bar
->height
= height
;
5296 #ifdef USE_TOOLKIT_SCROLL_BARS
5297 bar
->fringe_extended_p
= fringe_extended_p
;
5299 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5300 #else /* not USE_TOOLKIT_SCROLL_BARS */
5301 /* Set the scroll bar's current state, unless we're currently being
5303 if (bar
->dragging
== -1)
5305 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5308 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5311 int start
= ((double) position
* top_range
) / whole
;
5312 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5313 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5316 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5318 XSETVECTOR (barobj
, bar
);
5319 wset_vertical_scroll_bar (w
, barobj
);
5323 /* The following three hooks are used when we're doing a thorough
5324 redisplay of the frame. We don't explicitly know which scroll bars
5325 are going to be deleted, because keeping track of when windows go
5326 away is a real pain - "Can you say set-window-configuration, boys
5327 and girls?" Instead, we just assert at the beginning of redisplay
5328 that *all* scroll bars are to be removed, and then save a scroll bar
5329 from the fiery pit when we actually redisplay its window. */
5331 /* Arrange for all scroll bars on FRAME to be removed at the next call
5332 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5333 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5336 XTcondemn_scroll_bars (struct frame
*frame
)
5338 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5339 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5342 bar
= FRAME_SCROLL_BARS (frame
);
5343 fset_scroll_bars (frame
, XSCROLL_BAR (bar
)->next
);
5344 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5345 XSCROLL_BAR (bar
)->prev
= Qnil
;
5346 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5347 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5348 fset_condemned_scroll_bars (frame
, bar
);
5353 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5354 Note that WINDOW isn't necessarily condemned at all. */
5357 XTredeem_scroll_bar (struct window
*window
)
5359 struct scroll_bar
*bar
;
5363 /* We can't redeem this window's scroll bar if it doesn't have one. */
5364 if (NILP (window
->vertical_scroll_bar
))
5367 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5369 /* Unlink it from the condemned list. */
5370 f
= XFRAME (WINDOW_FRAME (window
));
5371 if (NILP (bar
->prev
))
5373 /* If the prev pointer is nil, it must be the first in one of
5375 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5376 /* It's not condemned. Everything's fine. */
5378 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5379 window
->vertical_scroll_bar
))
5380 fset_condemned_scroll_bars (f
, bar
->next
);
5382 /* If its prev pointer is nil, it must be at the front of
5383 one or the other! */
5387 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5389 if (! NILP (bar
->next
))
5390 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5392 bar
->next
= FRAME_SCROLL_BARS (f
);
5394 XSETVECTOR (barobj
, bar
);
5395 fset_scroll_bars (f
, barobj
);
5396 if (! NILP (bar
->next
))
5397 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5400 /* Remove all scroll bars on FRAME that haven't been saved since the
5401 last call to `*condemn_scroll_bars_hook'. */
5404 XTjudge_scroll_bars (struct frame
*f
)
5406 Lisp_Object bar
, next
;
5408 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5410 /* Clear out the condemned list now so we won't try to process any
5411 more events on the hapless scroll bars. */
5412 fset_condemned_scroll_bars (f
, Qnil
);
5414 for (; ! NILP (bar
); bar
= next
)
5416 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5418 x_scroll_bar_remove (b
);
5421 b
->next
= b
->prev
= Qnil
;
5424 /* Now there should be no references to the condemned scroll bars,
5425 and they should get garbage-collected. */
5429 #ifndef USE_TOOLKIT_SCROLL_BARS
5430 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5431 is a no-op when using toolkit scroll bars.
5433 This may be called from a signal handler, so we have to ignore GC
5437 x_scroll_bar_expose (struct scroll_bar
*bar
, const XEvent
*event
)
5439 Window w
= bar
->x_window
;
5440 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5441 GC gc
= f
->output_data
.x
->normal_gc
;
5445 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5447 /* Switch to scroll bar foreground color. */
5448 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5449 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5450 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5452 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5453 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5454 /* x, y, width, height */
5455 0, 0, bar
->width
- 1, bar
->height
- 1);
5457 /* Restore the foreground color of the GC if we changed it above. */
5458 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5459 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5460 FRAME_FOREGROUND_PIXEL (f
));
5465 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5467 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5468 is set to something other than NO_EVENT, it is enqueued.
5470 This may be called from a signal handler, so we have to ignore GC
5475 x_scroll_bar_handle_click (struct scroll_bar
*bar
,
5476 const XEvent
*event
,
5477 struct input_event
*emacs_event
)
5479 if (! WINDOWP (bar
->window
))
5482 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5483 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5484 emacs_event
->modifiers
5485 = (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO
5486 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5487 event
->xbutton
.state
)
5488 | (event
->type
== ButtonRelease
5491 emacs_event
->frame_or_window
= bar
->window
;
5492 emacs_event
->arg
= Qnil
;
5493 emacs_event
->timestamp
= event
->xbutton
.time
;
5496 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5497 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5500 if (y
> top_range
) y
= top_range
;
5503 emacs_event
->part
= scroll_bar_above_handle
;
5504 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5505 emacs_event
->part
= scroll_bar_handle
;
5507 emacs_event
->part
= scroll_bar_below_handle
;
5509 #ifndef USE_TOOLKIT_SCROLL_BARS
5510 /* If the user has released the handle, set it to its final position. */
5511 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
5513 int new_start
= y
- bar
->dragging
;
5514 int new_end
= new_start
+ bar
->end
- bar
->start
;
5516 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5521 XSETINT (emacs_event
->x
, y
);
5522 XSETINT (emacs_event
->y
, top_range
);
5526 #ifndef USE_TOOLKIT_SCROLL_BARS
5528 /* Handle some mouse motion while someone is dragging the scroll bar.
5530 This may be called from a signal handler, so we have to ignore GC
5534 x_scroll_bar_note_movement (struct scroll_bar
*bar
,
5535 const XMotionEvent
*event
)
5537 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5538 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
5540 dpyinfo
->last_mouse_movement_time
= event
->time
;
5541 dpyinfo
->last_mouse_scroll_bar
= bar
;
5544 /* If we're dragging the bar, display it. */
5545 if (bar
->dragging
!= -1)
5547 /* Where should the handle be now? */
5548 int new_start
= event
->y
- bar
->dragging
;
5550 if (new_start
!= bar
->start
)
5552 int new_end
= new_start
+ bar
->end
- bar
->start
;
5554 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5559 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5561 /* Return information to the user about the current position of the mouse
5562 on the scroll bar. */
5565 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
5566 enum scroll_bar_part
*part
, Lisp_Object
*x
,
5567 Lisp_Object
*y
, Time
*timestamp
)
5569 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (*fp
);
5570 struct scroll_bar
*bar
= dpyinfo
->last_mouse_scroll_bar
;
5571 Window w
= bar
->x_window
;
5572 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5574 Window dummy_window
;
5576 unsigned int dummy_mask
;
5580 /* Get the mouse's position relative to the scroll bar window, and
5582 if (XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5584 /* Root, child, root x and root y. */
5585 &dummy_window
, &dummy_window
,
5586 &dummy_coord
, &dummy_coord
,
5588 /* Position relative to scroll bar. */
5591 /* Mouse buttons and modifier keys. */
5594 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5596 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5598 if (bar
->dragging
!= -1)
5599 win_y
-= bar
->dragging
;
5603 if (win_y
> top_range
)
5607 *bar_window
= bar
->window
;
5609 if (bar
->dragging
!= -1)
5610 *part
= scroll_bar_handle
;
5611 else if (win_y
< bar
->start
)
5612 *part
= scroll_bar_above_handle
;
5613 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5614 *part
= scroll_bar_handle
;
5616 *part
= scroll_bar_below_handle
;
5618 XSETINT (*x
, win_y
);
5619 XSETINT (*y
, top_range
);
5622 dpyinfo
->last_mouse_scroll_bar
= NULL
;
5623 *timestamp
= dpyinfo
->last_mouse_movement_time
;
5630 /* The screen has been cleared so we may have changed foreground or
5631 background colors, and the scroll bars may need to be redrawn.
5632 Clear out the scroll bars, and ask for expose events, so we can
5636 x_scroll_bar_clear (struct frame
*f
)
5638 #ifndef USE_TOOLKIT_SCROLL_BARS
5641 /* We can have scroll bars even if this is 0,
5642 if we just turned off scroll bar mode.
5643 But in that case we should not clear them. */
5644 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5645 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5646 bar
= XSCROLL_BAR (bar
)->next
)
5647 XClearArea (FRAME_X_DISPLAY (f
),
5648 XSCROLL_BAR (bar
)->x_window
,
5650 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5653 #ifdef ENABLE_CHECKING
5655 /* Record the last 100 characters stored
5656 to help debug the loss-of-chars-during-GC problem. */
5658 static int temp_index
;
5659 static short temp_buffer
[100];
5661 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5662 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5664 temp_buffer[temp_index++] = (keysym)
5666 #else /* not ENABLE_CHECKING */
5668 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
5670 #endif /* ENABLE_CHECKING */
5672 /* Set this to nonzero to fake an "X I/O error"
5673 on a particular display. */
5675 static struct x_display_info
*XTread_socket_fake_io_error
;
5677 /* When we find no input here, we occasionally do a no-op command
5678 to verify that the X server is still running and we can still talk with it.
5679 We try all the open displays, one by one.
5680 This variable is used for cycling thru the displays. */
5682 static struct x_display_info
*next_noop_dpyinfo
;
5691 /* Filter events for the current X input method.
5692 DPYINFO is the display this event is for.
5693 EVENT is the X event to filter.
5695 Returns non-zero if the event was filtered, caller shall not process
5697 Returns zero if event is wasn't filtered. */
5701 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5703 /* XFilterEvent returns non-zero if the input method has
5704 consumed the event. We pass the frame's X window to
5705 XFilterEvent because that's the one for which the IC
5708 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5709 event
->xclient
.window
);
5711 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5716 static int current_count
;
5717 static int current_finish
;
5718 static struct input_event
*current_hold_quit
;
5720 /* This is the filter function invoked by the GTK event loop.
5721 It is invoked before the XEvent is translated to a GdkEvent,
5722 so we have a chance to act on the event before GTK. */
5723 static GdkFilterReturn
5724 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5726 XEvent
*xev
= (XEvent
*) gxev
;
5729 if (current_count
>= 0)
5731 struct x_display_info
*dpyinfo
;
5733 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5736 /* Filter events for the current X input method.
5737 GTK calls XFilterEvent but not for key press and release,
5738 so we do it here. */
5739 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5741 && x_filter_event (dpyinfo
, xev
))
5744 return GDK_FILTER_REMOVE
;
5749 current_finish
= X_EVENT_NORMAL
;
5752 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5756 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5760 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5761 return GDK_FILTER_REMOVE
;
5763 return GDK_FILTER_CONTINUE
;
5765 #endif /* USE_GTK */
5768 static void xembed_send_message (struct frame
*f
, Time
,
5769 enum xembed_message
,
5770 long detail
, long data1
, long data2
);
5772 /* Handles the XEvent EVENT on display DPYINFO.
5774 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5775 *FINISH is zero if caller should continue reading events.
5776 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5777 *EVENT is unchanged unless we're processing KeyPress event.
5779 We return the number of characters stored into the buffer. */
5782 handle_one_xevent (struct x_display_info
*dpyinfo
,
5783 const XEvent
*event
,
5784 int *finish
, struct input_event
*hold_quit
)
5787 struct input_event ie
;
5788 struct selection_input_event sie
;
5792 ptrdiff_t nbytes
= 0;
5793 struct frame
*any
, *f
= NULL
;
5794 struct coding_system coding
;
5795 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
5796 /* This holds the state XLookupString needs to implement dead keys
5797 and other tricks known as "compose processing". _X Window System_
5798 says that a portable program can't use this, but Stephen Gildea assures
5799 me that letting the compiler initialize it to zeros will work okay. */
5800 static XComposeStatus compose_status
;
5804 *finish
= X_EVENT_NORMAL
;
5806 EVENT_INIT (inev
.ie
);
5807 inev
.ie
.kind
= NO_EVENT
;
5810 any
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
5812 if (any
&& any
->wait_event_type
== event
->type
)
5813 any
->wait_event_type
= 0; /* Indicates we got it. */
5815 switch (event
->type
)
5819 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_protocols
5820 && event
->xclient
.format
== 32)
5822 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_take_focus
)
5824 /* Use the value returned by x_any_window_to_frame
5825 because this could be the shell widget window
5826 if the frame has no title bar. */
5829 /* Not quite sure this is needed -pd */
5830 if (f
&& FRAME_XIC (f
))
5831 XSetICFocus (FRAME_XIC (f
));
5833 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5834 instructs the WM to set the input focus automatically for
5835 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5836 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5837 it has set the focus. So, XSetInputFocus below is not
5840 The call to XSetInputFocus below has also caused trouble. In
5841 cases where the XSetInputFocus done by the WM and the one
5842 below are temporally close (on a fast machine), the call
5843 below can generate additional FocusIn events which confuse
5846 /* Since we set WM_TAKE_FOCUS, we must call
5847 XSetInputFocus explicitly. But not if f is null,
5848 since that might be an event for a deleted frame. */
5851 Display
*d
= event
->xclient
.display
;
5852 /* Catch and ignore errors, in case window has been
5853 iconified by a window manager such as GWM. */
5855 XSetInputFocus (d
, event
->xclient
.window
,
5856 /* The ICCCM says this is
5857 the only valid choice. */
5859 event
->xclient
.data
.l
[1]);
5860 /* This is needed to detect the error
5861 if there is an error. */
5863 x_uncatch_errors ();
5865 /* Not certain about handling scroll bars here */
5870 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_save_yourself
)
5872 /* Save state modify the WM_COMMAND property to
5873 something which can reinstate us. This notifies
5874 the session manager, who's looking for such a
5875 PropertyNotify. Can restart processing when
5876 a keyboard or mouse event arrives. */
5877 /* If we have a session manager, don't set this.
5878 KDE will then start two Emacsen, one for the
5879 session manager and one for this. */
5881 if (! x_session_have_connection ())
5884 f
= x_top_window_to_frame (dpyinfo
,
5885 event
->xclient
.window
);
5886 /* This is just so we only give real data once
5887 for a single Emacs process. */
5888 if (f
== SELECTED_FRAME ())
5889 XSetCommand (FRAME_X_DISPLAY (f
),
5890 event
->xclient
.window
,
5891 initial_argv
, initial_argc
);
5893 XSetCommand (FRAME_X_DISPLAY (f
),
5894 event
->xclient
.window
,
5900 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_delete_window
)
5904 goto OTHER
; /* May be a dialog that is to be removed */
5906 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5907 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5914 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_configure_denied
)
5917 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_window_moved
)
5920 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
5922 new_x
= event
->xclient
.data
.s
[0];
5923 new_y
= event
->xclient
.data
.s
[1];
5927 f
->left_pos
= new_x
;
5934 if (event
->xclient
.message_type
== dpyinfo
->Xatom_editres
)
5938 _XEditResCheckMessages (f
->output_data
.x
->widget
,
5939 NULL
, (XEvent
*) event
, NULL
);
5942 #endif /* HACK_EDITRES */
5944 if (event
->xclient
.message_type
== dpyinfo
->Xatom_DONE
5945 || event
->xclient
.message_type
== dpyinfo
->Xatom_PAGE
)
5947 /* Ghostview job completed. Kill it. We could
5948 reply with "Next" if we received "Page", but we
5949 currently never do because we are interested in
5950 images, only, which should have 1 page. */
5951 Pixmap pixmap
= (Pixmap
) event
->xclient
.data
.l
[1];
5952 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
5955 x_kill_gs_process (pixmap
, f
);
5956 expose_frame (f
, 0, 0, 0, 0);
5960 #ifdef USE_TOOLKIT_SCROLL_BARS
5961 /* Scroll bar callbacks send a ClientMessage from which
5962 we construct an input_event. */
5963 if (event
->xclient
.message_type
== dpyinfo
->Xatom_Scrollbar
)
5965 x_scroll_bar_to_input_event (event
, &inev
.ie
);
5966 *finish
= X_EVENT_GOTO_OUT
;
5969 #endif /* USE_TOOLKIT_SCROLL_BARS */
5971 /* XEmbed messages from the embedder (if any). */
5972 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
5974 enum xembed_message msg
= event
->xclient
.data
.l
[1];
5975 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
5976 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
5978 *finish
= X_EVENT_GOTO_OUT
;
5982 xft_settings_event (dpyinfo
, event
);
5987 if (x_handle_dnd_message (f
, &event
->xclient
, dpyinfo
, &inev
.ie
))
5988 *finish
= X_EVENT_DROP
;
5992 case SelectionNotify
:
5993 dpyinfo
->last_user_time
= event
->xselection
.time
;
5994 #ifdef USE_X_TOOLKIT
5995 if (! x_window_to_frame (dpyinfo
, event
->xselection
.requestor
))
5997 #endif /* not USE_X_TOOLKIT */
5998 x_handle_selection_notify (&event
->xselection
);
6001 case SelectionClear
: /* Someone has grabbed ownership. */
6002 dpyinfo
->last_user_time
= event
->xselectionclear
.time
;
6003 #ifdef USE_X_TOOLKIT
6004 if (! x_window_to_frame (dpyinfo
, event
->xselectionclear
.window
))
6006 #endif /* USE_X_TOOLKIT */
6008 const XSelectionClearEvent
*eventp
= &event
->xselectionclear
;
6010 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6011 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6012 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6013 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6017 case SelectionRequest
: /* Someone wants our selection. */
6018 dpyinfo
->last_user_time
= event
->xselectionrequest
.time
;
6019 #ifdef USE_X_TOOLKIT
6020 if (!x_window_to_frame (dpyinfo
, event
->xselectionrequest
.owner
))
6022 #endif /* USE_X_TOOLKIT */
6024 const XSelectionRequestEvent
*eventp
= &event
->xselectionrequest
;
6026 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6027 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6028 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6029 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6030 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6031 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6032 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6036 case PropertyNotify
:
6037 dpyinfo
->last_user_time
= event
->xproperty
.time
;
6038 f
= x_top_window_to_frame (dpyinfo
, event
->xproperty
.window
);
6039 if (f
&& event
->xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6040 if (x_handle_net_wm_state (f
, &event
->xproperty
)
6041 && FRAME_ICONIFIED_P (f
)
6042 && f
->output_data
.x
->net_wm_state_hidden_seen
)
6044 /* Gnome shell does not iconify us when C-z is pressed.
6045 It hides the frame. So if our state says we aren't
6046 hidden anymore, treat it as deiconified. */
6047 SET_FRAME_VISIBLE (f
, 1);
6048 SET_FRAME_ICONIFIED (f
, 0);
6049 f
->output_data
.x
->has_been_visible
= 1;
6050 f
->output_data
.x
->net_wm_state_hidden_seen
= 0;
6051 inev
.ie
.kind
= DEICONIFY_EVENT
;
6052 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6055 x_handle_property_notify (&event
->xproperty
);
6056 xft_settings_event (dpyinfo
, event
);
6059 case ReparentNotify
:
6060 f
= x_top_window_to_frame (dpyinfo
, event
->xreparent
.window
);
6063 f
->output_data
.x
->parent_desc
= event
->xreparent
.parent
;
6064 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6066 /* Perhaps reparented due to a WM restart. Reset this. */
6067 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6068 FRAME_DISPLAY_INFO (f
)->net_supported_window
= 0;
6070 x_set_frame_alpha (f
);
6075 f
= x_window_to_frame (dpyinfo
, event
->xexpose
.window
);
6078 if (!FRAME_VISIBLE_P (f
))
6080 SET_FRAME_VISIBLE (f
, 1);
6081 SET_FRAME_ICONIFIED (f
, 0);
6082 f
->output_data
.x
->has_been_visible
= 1;
6083 SET_FRAME_GARBAGED (f
);
6088 /* This seems to be needed for GTK 2.6 and later, see
6089 http://debbugs.gnu.org/cgi/bugreport.cgi?bug=15398. */
6090 x_clear_area (event
->xexpose
.display
,
6091 event
->xexpose
.window
,
6092 event
->xexpose
.x
, event
->xexpose
.y
,
6093 event
->xexpose
.width
, event
->xexpose
.height
);
6095 expose_frame (f
, event
->xexpose
.x
, event
->xexpose
.y
,
6096 event
->xexpose
.width
, event
->xexpose
.height
);
6101 #ifndef USE_TOOLKIT_SCROLL_BARS
6102 struct scroll_bar
*bar
;
6104 #if defined USE_LUCID
6105 /* Submenus of the Lucid menu bar aren't widgets
6106 themselves, so there's no way to dispatch events
6107 to them. Recognize this case separately. */
6109 Widget widget
= x_window_to_menu_bar (event
->xexpose
.window
);
6111 xlwmenu_redisplay (widget
);
6113 #endif /* USE_LUCID */
6115 #ifdef USE_TOOLKIT_SCROLL_BARS
6116 /* Dispatch event to the widget. */
6118 #else /* not USE_TOOLKIT_SCROLL_BARS */
6119 bar
= x_window_to_scroll_bar (event
->xexpose
.display
,
6120 event
->xexpose
.window
);
6123 x_scroll_bar_expose (bar
, event
);
6124 #ifdef USE_X_TOOLKIT
6127 #endif /* USE_X_TOOLKIT */
6128 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6132 case GraphicsExpose
: /* This occurs when an XCopyArea's
6133 source area was obscured or not
6135 f
= x_window_to_frame (dpyinfo
, event
->xgraphicsexpose
.drawable
);
6137 expose_frame (f
, event
->xgraphicsexpose
.x
,
6138 event
->xgraphicsexpose
.y
,
6139 event
->xgraphicsexpose
.width
,
6140 event
->xgraphicsexpose
.height
);
6141 #ifdef USE_X_TOOLKIT
6144 #endif /* USE_X_TOOLKIT */
6147 case NoExpose
: /* This occurs when an XCopyArea's
6148 source area was completely
6153 /* Redo the mouse-highlight after the tooltip has gone. */
6154 if (event
->xunmap
.window
== tip_window
)
6157 x_redo_mouse_highlight (dpyinfo
);
6160 f
= x_top_window_to_frame (dpyinfo
, event
->xunmap
.window
);
6161 if (f
) /* F may no longer exist if
6162 the frame was deleted. */
6164 bool visible
= FRAME_VISIBLE_P (f
);
6165 /* While a frame is unmapped, display generation is
6166 disabled; you don't want to spend time updating a
6167 display that won't ever be seen. */
6168 SET_FRAME_VISIBLE (f
, 0);
6169 /* We can't distinguish, from the event, whether the window
6170 has become iconified or invisible. So assume, if it
6171 was previously visible, than now it is iconified.
6172 But x_make_frame_invisible clears both
6173 the visible flag and the iconified flag;
6174 and that way, we know the window is not iconified now. */
6175 if (visible
|| FRAME_ICONIFIED_P (f
))
6177 SET_FRAME_ICONIFIED (f
, 1);
6178 inev
.ie
.kind
= ICONIFY_EVENT
;
6179 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6185 if (event
->xmap
.window
== tip_window
)
6186 /* The tooltip has been drawn already. Avoid
6187 the SET_FRAME_GARBAGED below. */
6190 /* We use x_top_window_to_frame because map events can
6191 come for sub-windows and they don't mean that the
6192 frame is visible. */
6193 f
= x_top_window_to_frame (dpyinfo
, event
->xmap
.window
);
6196 bool iconified
= FRAME_ICONIFIED_P (f
);
6197 /* wait_reading_process_output will notice this and update
6198 the frame's display structures.
6199 If we where iconified, we should not set garbaged,
6200 because that stops redrawing on Expose events. This looks
6201 bad if we are called from a recursive event loop
6202 (x_dispatch_event), for example when a dialog is up. */
6204 SET_FRAME_GARBAGED (f
);
6206 /* Check if fullscreen was specified before we where mapped the
6207 first time, i.e. from the command line. */
6208 if (!f
->output_data
.x
->has_been_visible
)
6209 x_check_fullscreen (f
);
6211 SET_FRAME_VISIBLE (f
, 1);
6212 SET_FRAME_ICONIFIED (f
, 0);
6213 f
->output_data
.x
->has_been_visible
= 1;
6217 inev
.ie
.kind
= DEICONIFY_EVENT
;
6218 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6220 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
6221 /* Force a redisplay sooner or later to update the
6222 frame titles in case this is the second frame. */
6223 record_asynch_buffer_change ();
6226 xg_frame_resized (f
, -1, -1);
6233 dpyinfo
->last_user_time
= event
->xkey
.time
;
6234 ignore_next_mouse_click_timeout
= 0;
6236 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6237 /* Dispatch KeyPress events when in menu. */
6238 if (popup_activated ())
6244 #if ! defined (USE_GTK)
6245 /* If mouse-highlight is an integer, input clears out
6246 mouse highlighting. */
6247 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6249 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)))
6251 clear_mouse_face (hlinfo
);
6252 hlinfo
->mouse_face_hidden
= 1;
6256 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6259 /* Scroll bars consume key events, but we want
6260 the keys to go to the scroll bar's frame. */
6261 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6262 event
->xkey
.window
);
6263 if (widget
&& XmIsScrollBar (widget
))
6265 widget
= XtParent (widget
);
6266 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6269 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6273 KeySym keysym
, orig_keysym
;
6274 /* al%imercury@uunet.uu.net says that making this 81
6275 instead of 80 fixed a bug whereby meta chars made
6278 It seems that some version of XmbLookupString has
6279 a bug of not returning XBufferOverflow in
6280 status_return even if the input is too long to
6281 fit in 81 bytes. So, we must prepare sufficient
6282 bytes for copy_buffer. 513 bytes (256 chars for
6283 two-byte character set) seems to be a fairly good
6284 approximation. -- 2000.8.10 handa@etl.go.jp */
6285 unsigned char copy_buffer
[513];
6286 unsigned char *copy_bufptr
= copy_buffer
;
6287 int copy_bufsiz
= sizeof (copy_buffer
);
6289 Lisp_Object coding_system
= Qlatin_1
;
6291 /* Event will be modified. */
6292 XKeyEvent xkey
= event
->xkey
;
6295 /* Don't pass keys to GTK. A Tab will shift focus to the
6296 tool bar in GTK 2.4. Keys will still go to menus and
6297 dialogs because in that case popup_activated is TRUE
6299 *finish
= X_EVENT_DROP
;
6302 xkey
.state
|= x_emacs_to_x_modifiers (FRAME_DISPLAY_INFO (f
),
6303 extra_keyboard_modifiers
);
6304 modifiers
= xkey
.state
;
6306 /* This will have to go some day... */
6308 /* make_lispy_event turns chars into control chars.
6309 Don't do it here because XLookupString is too eager. */
6310 xkey
.state
&= ~ControlMask
;
6311 xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6312 | dpyinfo
->super_mod_mask
6313 | dpyinfo
->hyper_mod_mask
6314 | dpyinfo
->alt_mod_mask
);
6316 /* In case Meta is ComposeCharacter,
6317 clear its status. According to Markus Ehrnsperger
6318 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6319 this enables ComposeCharacter to work whether or
6320 not it is combined with Meta. */
6321 if (modifiers
& dpyinfo
->meta_mod_mask
)
6322 memset (&compose_status
, 0, sizeof (compose_status
));
6327 Status status_return
;
6329 coding_system
= Vlocale_coding_system
;
6330 nbytes
= XmbLookupString (FRAME_XIC (f
),
6331 &xkey
, (char *) copy_bufptr
,
6332 copy_bufsiz
, &keysym
,
6334 if (status_return
== XBufferOverflow
)
6336 copy_bufsiz
= nbytes
+ 1;
6337 copy_bufptr
= alloca (copy_bufsiz
);
6338 nbytes
= XmbLookupString (FRAME_XIC (f
),
6339 &xkey
, (char *) copy_bufptr
,
6340 copy_bufsiz
, &keysym
,
6343 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6344 if (status_return
== XLookupNone
)
6346 else if (status_return
== XLookupChars
)
6351 else if (status_return
!= XLookupKeySym
6352 && status_return
!= XLookupBoth
)
6356 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
6357 copy_bufsiz
, &keysym
,
6360 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
6361 copy_bufsiz
, &keysym
,
6365 /* If not using XIM/XIC, and a compose sequence is in progress,
6366 we break here. Otherwise, chars_matched is always 0. */
6367 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6370 memset (&compose_status
, 0, sizeof (compose_status
));
6371 orig_keysym
= keysym
;
6373 /* Common for all keysym input events. */
6374 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6376 = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
), modifiers
);
6377 inev
.ie
.timestamp
= xkey
.time
;
6379 /* First deal with keysyms which have defined
6380 translations to characters. */
6381 if (keysym
>= 32 && keysym
< 128)
6382 /* Avoid explicitly decoding each ASCII character. */
6384 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6385 inev
.ie
.code
= keysym
;
6389 /* Keysyms directly mapped to Unicode characters. */
6390 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6392 if (keysym
< 0x01000080)
6393 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6395 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6396 inev
.ie
.code
= keysym
& 0xFFFFFF;
6400 /* Now non-ASCII. */
6401 if (HASH_TABLE_P (Vx_keysym_table
)
6402 && (c
= Fgethash (make_number (keysym
),
6407 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6408 ? ASCII_KEYSTROKE_EVENT
6409 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6410 inev
.ie
.code
= XFASTINT (c
);
6414 /* Random non-modifier sorts of keysyms. */
6415 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6416 || keysym
== XK_Delete
6417 #ifdef XK_ISO_Left_Tab
6418 || (keysym
>= XK_ISO_Left_Tab
6419 && keysym
<= XK_ISO_Enter
)
6421 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6422 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6424 /* This recognizes the "extended function
6425 keys". It seems there's no cleaner way.
6426 Test IsModifierKey to avoid handling
6427 mode_switch incorrectly. */
6428 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
6430 #ifdef XK_dead_circumflex
6431 || orig_keysym
== XK_dead_circumflex
6433 #ifdef XK_dead_grave
6434 || orig_keysym
== XK_dead_grave
6436 #ifdef XK_dead_tilde
6437 || orig_keysym
== XK_dead_tilde
6439 #ifdef XK_dead_diaeresis
6440 || orig_keysym
== XK_dead_diaeresis
6442 #ifdef XK_dead_macron
6443 || orig_keysym
== XK_dead_macron
6445 #ifdef XK_dead_degree
6446 || orig_keysym
== XK_dead_degree
6448 #ifdef XK_dead_acute
6449 || orig_keysym
== XK_dead_acute
6451 #ifdef XK_dead_cedilla
6452 || orig_keysym
== XK_dead_cedilla
6454 #ifdef XK_dead_breve
6455 || orig_keysym
== XK_dead_breve
6457 #ifdef XK_dead_ogonek
6458 || orig_keysym
== XK_dead_ogonek
6460 #ifdef XK_dead_caron
6461 || orig_keysym
== XK_dead_caron
6463 #ifdef XK_dead_doubleacute
6464 || orig_keysym
== XK_dead_doubleacute
6466 #ifdef XK_dead_abovedot
6467 || orig_keysym
== XK_dead_abovedot
6469 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6470 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6471 /* Any "vendor-specific" key is ok. */
6472 || (orig_keysym
& (1 << 28))
6473 || (keysym
!= NoSymbol
&& nbytes
== 0))
6474 && ! (IsModifierKey (orig_keysym
)
6475 /* The symbols from XK_ISO_Lock
6476 to XK_ISO_Last_Group_Lock
6477 don't have real modifiers but
6478 should be treated similarly to
6479 Mode_switch by Emacs. */
6480 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6481 || (XK_ISO_Lock
<= orig_keysym
6482 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
6486 STORE_KEYSYM_FOR_DEBUG (keysym
);
6487 /* make_lispy_event will convert this to a symbolic
6489 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6490 inev
.ie
.code
= keysym
;
6494 { /* Raw bytes, not keysym. */
6498 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6500 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6502 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6505 if (nchars
< nbytes
)
6507 /* Decode the input data. */
6509 /* The input should be decoded with `coding_system'
6510 which depends on which X*LookupString function
6511 we used just above and the locale. */
6512 setup_coding_system (coding_system
, &coding
);
6513 coding
.src_multibyte
= 0;
6514 coding
.dst_multibyte
= 1;
6515 /* The input is converted to events, thus we can't
6516 handle composition. Anyway, there's no XIM that
6517 gives us composition information. */
6518 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6520 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
6522 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6523 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6524 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6525 nbytes
= coding
.produced
;
6526 nchars
= coding
.produced_char
;
6527 copy_bufptr
= coding
.destination
;
6530 /* Convert the input data to a sequence of
6531 character events. */
6532 for (i
= 0; i
< nbytes
; i
+= len
)
6535 if (nchars
== nbytes
)
6536 ch
= copy_bufptr
[i
], len
= 1;
6538 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6539 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
6540 ? ASCII_KEYSTROKE_EVENT
6541 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6543 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6548 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6550 if (keysym
== NoSymbol
)
6553 /* FIXME: check side effects and remove this. */
6554 ((XEvent
*) event
)->xkey
= xkey
;
6558 /* Don't dispatch this event since XtDispatchEvent calls
6559 XFilterEvent, and two calls in a row may freeze the
6567 dpyinfo
->last_user_time
= event
->xkey
.time
;
6569 /* Don't dispatch this event since XtDispatchEvent calls
6570 XFilterEvent, and two calls in a row may freeze the
6578 dpyinfo
->last_user_time
= event
->xcrossing
.time
;
6579 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6583 if (f
&& x_mouse_click_focus_ignore_position
)
6584 ignore_next_mouse_click_timeout
= event
->xmotion
.time
+ 200;
6586 /* EnterNotify counts as mouse movement,
6587 so update things that depend on mouse position. */
6588 if (f
&& !f
->output_data
.x
->hourglass_p
)
6589 note_mouse_movement (f
, &event
->xmotion
);
6591 /* We may get an EnterNotify on the buttons in the toolbar. In that
6592 case we moved out of any highlighted area and need to note this. */
6593 if (!f
&& dpyinfo
->last_mouse_glyph_frame
)
6594 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
6599 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6603 dpyinfo
->last_user_time
= event
->xcrossing
.time
;
6604 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6606 f
= x_top_window_to_frame (dpyinfo
, event
->xcrossing
.window
);
6609 if (f
== hlinfo
->mouse_face_mouse_frame
)
6611 /* If we move outside the frame, then we're
6612 certainly no longer on any text in the frame. */
6613 clear_mouse_face (hlinfo
);
6614 hlinfo
->mouse_face_mouse_frame
= 0;
6617 /* Generate a nil HELP_EVENT to cancel a help-echo.
6618 Do it only if there's something to cancel.
6619 Otherwise, the startup message is cleared when
6620 the mouse leaves the frame. */
6621 if (any_help_event_p
)
6625 /* See comment in EnterNotify above */
6626 else if (dpyinfo
->last_mouse_glyph_frame
)
6627 note_mouse_movement (dpyinfo
->last_mouse_glyph_frame
, &event
->xmotion
);
6632 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6637 dpyinfo
->last_user_time
= event
->xmotion
.time
;
6638 previous_help_echo_string
= help_echo_string
;
6639 help_echo_string
= Qnil
;
6641 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
6642 : x_window_to_frame (dpyinfo
, event
->xmotion
.window
));
6644 if (hlinfo
->mouse_face_hidden
)
6646 hlinfo
->mouse_face_hidden
= 0;
6647 clear_mouse_face (hlinfo
);
6651 if (f
&& xg_event_is_for_scrollbar (f
, event
))
6657 /* Generate SELECT_WINDOW_EVENTs when needed.
6658 Don't let popup menus influence things (bug#1261). */
6659 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6661 static Lisp_Object last_mouse_window
;
6662 Lisp_Object window
= window_from_coordinates
6663 (f
, event
->xmotion
.x
, event
->xmotion
.y
, 0, 0);
6665 /* Window will be selected only when it is not selected now and
6666 last mouse movement event was not in it. Minibuffer window
6667 will be selected only when it is active. */
6668 if (WINDOWP (window
)
6669 && !EQ (window
, last_mouse_window
)
6670 && !EQ (window
, selected_window
)
6671 /* For click-to-focus window managers
6672 create event iff we don't leave the
6674 && (focus_follows_mouse
6675 || (EQ (XWINDOW (window
)->frame
,
6676 XWINDOW (selected_window
)->frame
))))
6678 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6679 inev
.ie
.frame_or_window
= window
;
6681 /* Remember the last window where we saw the mouse. */
6682 last_mouse_window
= window
;
6684 if (!note_mouse_movement (f
, &event
->xmotion
))
6685 help_echo_string
= previous_help_echo_string
;
6689 #ifndef USE_TOOLKIT_SCROLL_BARS
6690 struct scroll_bar
*bar
6691 = x_window_to_scroll_bar (event
->xmotion
.display
,
6692 event
->xmotion
.window
);
6695 x_scroll_bar_note_movement (bar
, &event
->xmotion
);
6696 #endif /* USE_TOOLKIT_SCROLL_BARS */
6698 /* If we move outside the frame, then we're
6699 certainly no longer on any text in the frame. */
6700 clear_mouse_face (hlinfo
);
6703 /* If the contents of the global variable help_echo_string
6704 has changed, generate a HELP_EVENT. */
6705 if (!NILP (help_echo_string
)
6706 || !NILP (previous_help_echo_string
))
6711 case ConfigureNotify
:
6712 f
= x_top_window_to_frame (dpyinfo
, event
->xconfigure
.window
);
6716 && event
->xconfigure
.window
== FRAME_X_WINDOW (f
))
6718 xg_frame_resized (f
, event
->xconfigure
.width
,
6719 event
->xconfigure
.height
);
6725 #ifndef USE_X_TOOLKIT
6727 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
->xconfigure
.height
);
6728 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
->xconfigure
.width
);
6730 /* In the toolkit version, change_frame_size
6731 is called by the code that handles resizing
6732 of the EmacsFrame widget. */
6734 /* Even if the number of character rows and columns has
6735 not changed, the font size may have changed, so we need
6736 to check the pixel dimensions as well. */
6737 if (columns
!= FRAME_COLS (f
)
6738 || rows
!= FRAME_LINES (f
)
6739 || event
->xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6740 || event
->xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6742 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6743 SET_FRAME_GARBAGED (f
);
6744 cancel_mouse_face (f
);
6747 FRAME_PIXEL_WIDTH (f
) = event
->xconfigure
.width
;
6748 FRAME_PIXEL_HEIGHT (f
) = event
->xconfigure
.height
;
6749 #endif /* not USE_GTK */
6753 /* GTK creates windows but doesn't map them.
6754 Only get real positions when mapped. */
6755 if (FRAME_GTK_OUTER_WIDGET (f
)
6756 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6758 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6761 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6762 xic_set_statusarea (f
);
6771 /* If we decide we want to generate an event to be seen
6772 by the rest of Emacs, we put it here. */
6773 bool tool_bar_p
= 0;
6775 memset (&compose_status
, 0, sizeof (compose_status
));
6776 dpyinfo
->last_mouse_glyph_frame
= NULL
;
6777 dpyinfo
->last_user_time
= event
->xbutton
.time
;
6779 f
= (x_mouse_grabbed (dpyinfo
) ? dpyinfo
->last_mouse_frame
6780 : x_window_to_frame (dpyinfo
, event
->xbutton
.window
));
6783 if (f
&& xg_event_is_for_scrollbar (f
, event
))
6788 #if ! defined (USE_GTK)
6789 /* Is this in the tool-bar? */
6790 if (WINDOWP (f
->tool_bar_window
)
6791 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6794 int x
= event
->xbutton
.x
;
6795 int y
= event
->xbutton
.y
;
6797 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6798 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6800 if (tool_bar_p
&& event
->xbutton
.button
< 4)
6801 handle_tool_bar_click
6802 (f
, x
, y
, event
->xbutton
.type
== ButtonPress
,
6803 x_x_to_emacs_modifiers (dpyinfo
, event
->xbutton
.state
));
6805 #endif /* !USE_GTK */
6808 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6809 if (! popup_activated ())
6812 if (ignore_next_mouse_click_timeout
)
6814 if (event
->type
== ButtonPress
6815 && event
->xbutton
.time
> ignore_next_mouse_click_timeout
)
6817 ignore_next_mouse_click_timeout
= 0;
6818 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
6820 if (event
->type
== ButtonRelease
)
6821 ignore_next_mouse_click_timeout
= 0;
6824 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
6826 if (FRAME_X_EMBEDDED_P (f
))
6827 xembed_send_message (f
, event
->xbutton
.time
,
6828 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6832 struct scroll_bar
*bar
6833 = x_window_to_scroll_bar (event
->xbutton
.display
,
6834 event
->xbutton
.window
);
6836 #ifdef USE_TOOLKIT_SCROLL_BARS
6837 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6839 if (bar
&& event
->xbutton
.state
& ControlMask
)
6841 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
6842 *finish
= X_EVENT_DROP
;
6844 #else /* not USE_TOOLKIT_SCROLL_BARS */
6846 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
6847 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6850 if (event
->type
== ButtonPress
)
6852 dpyinfo
->grabbed
|= (1 << event
->xbutton
.button
);
6853 dpyinfo
->last_mouse_frame
= f
;
6856 last_tool_bar_item
= -1;
6859 dpyinfo
->grabbed
&= ~(1 << event
->xbutton
.button
);
6861 /* Ignore any mouse motion that happened before this event;
6862 any subsequent mouse-movement Emacs events should reflect
6863 only motion after the ButtonPress/Release. */
6867 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6868 f
= x_menubar_window_to_frame (dpyinfo
, event
);
6869 /* For a down-event in the menu bar,
6870 don't pass it to Xt right now.
6871 Instead, save it away
6872 and we will pass it to Xt from kbd_buffer_get_event.
6873 That way, we can run some Lisp code first. */
6874 if (! popup_activated ()
6876 /* Gtk+ menus only react to the first three buttons. */
6877 && event
->xbutton
.button
< 3
6879 && f
&& event
->type
== ButtonPress
6880 /* Verify the event is really within the menu bar
6881 and not just sent to it due to grabbing. */
6882 && event
->xbutton
.x
>= 0
6883 && event
->xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6884 && event
->xbutton
.y
>= 0
6885 && event
->xbutton
.y
< f
->output_data
.x
->menubar_height
6886 && event
->xbutton
.same_screen
)
6888 if (!f
->output_data
.x
->saved_menu_event
)
6889 f
->output_data
.x
->saved_menu_event
= xmalloc (sizeof *event
);
6890 *f
->output_data
.x
->saved_menu_event
= *event
;
6891 inev
.ie
.kind
= MENU_BAR_ACTIVATE_EVENT
;
6892 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6893 *finish
= X_EVENT_DROP
;
6897 #endif /* USE_X_TOOLKIT || USE_GTK */
6901 case CirculateNotify
:
6904 case CirculateRequest
:
6907 case VisibilityNotify
:
6911 /* Someone has changed the keyboard mapping - update the
6913 switch (event
->xmapping
.request
)
6915 case MappingModifier
:
6916 x_find_modifier_meanings (dpyinfo
);
6917 /* This is meant to fall through. */
6918 case MappingKeyboard
:
6919 XRefreshKeyboardMapping ((XMappingEvent
*) &event
->xmapping
);
6924 xft_settings_event (dpyinfo
, event
);
6929 #ifdef USE_X_TOOLKIT
6931 if (*finish
!= X_EVENT_DROP
)
6932 XtDispatchEvent ((XEvent
*) event
);
6934 #endif /* USE_X_TOOLKIT */
6939 if (inev
.ie
.kind
!= NO_EVENT
)
6941 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6946 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6951 XSETFRAME (frame
, f
);
6957 any_help_event_p
= 1;
6958 gen_help_event (help_echo_string
, frame
, help_echo_window
,
6959 help_echo_object
, help_echo_pos
);
6963 help_echo_string
= Qnil
;
6964 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
6973 #if defined USE_GTK || defined USE_X_TOOLKIT
6975 /* Handles the XEvent EVENT on display DISPLAY.
6976 This is used for event loops outside the normal event handling,
6977 i.e. looping while a popup menu or a dialog is posted.
6979 Returns the value handle_one_xevent sets in the finish argument. */
6981 x_dispatch_event (XEvent
*event
, Display
*display
)
6983 struct x_display_info
*dpyinfo
;
6984 int finish
= X_EVENT_NORMAL
;
6986 dpyinfo
= x_display_info_for_display (display
);
6989 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
6996 /* Read events coming from the X server.
6997 Return as soon as there are no more events to be read.
6999 Return the number of characters stored into the buffer,
7000 thus pretending to be `read' (except the characters we store
7001 in the keyboard buffer can be multibyte, so are not necessarily
7005 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
7008 int event_found
= 0;
7009 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
7013 /* So people can tell when we have read the available input. */
7014 input_signal_count
++;
7016 /* For debugging, this gives a way to fake an I/O error. */
7017 if (dpyinfo
== XTread_socket_fake_io_error
)
7019 XTread_socket_fake_io_error
= 0;
7020 x_io_error_quitter (dpyinfo
->display
);
7024 while (XPending (dpyinfo
->display
))
7029 XNextEvent (dpyinfo
->display
, &event
);
7032 /* Filter events for the current X input method. */
7033 if (x_filter_event (dpyinfo
, &event
))
7038 count
+= handle_one_xevent (dpyinfo
, &event
, &finish
, hold_quit
);
7040 if (finish
== X_EVENT_GOTO_OUT
)
7046 /* For GTK we must use the GTK event loop. But XEvents gets passed
7047 to our filter function above, and then to the big event switch.
7048 We use a bunch of globals to communicate with our filter function,
7049 that is kind of ugly, but it works.
7051 There is no way to do one display at the time, GTK just does events
7052 from all displays. */
7054 while (gtk_events_pending ())
7056 current_count
= count
;
7057 current_hold_quit
= hold_quit
;
7059 gtk_main_iteration ();
7061 count
= current_count
;
7063 current_hold_quit
= 0;
7065 if (current_finish
== X_EVENT_GOTO_OUT
)
7068 #endif /* USE_GTK */
7070 /* On some systems, an X bug causes Emacs to get no more events
7071 when the window is destroyed. Detect that. (1994.) */
7074 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7075 One XNOOP in 100 loops will make Emacs terminate.
7076 B. Bretthauer, 1994 */
7078 if (x_noop_count
>= 100)
7082 if (next_noop_dpyinfo
== 0)
7083 next_noop_dpyinfo
= x_display_list
;
7085 XNoOp (next_noop_dpyinfo
->display
);
7087 /* Each time we get here, cycle through the displays now open. */
7088 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7092 /* If the focus was just given to an auto-raising frame,
7093 raise it now. FIXME: handle more than one such frame. */
7094 if (dpyinfo
->x_pending_autoraise_frame
)
7096 x_raise_frame (dpyinfo
->x_pending_autoraise_frame
);
7097 dpyinfo
->x_pending_autoraise_frame
= NULL
;
7108 /***********************************************************************
7110 ***********************************************************************/
7112 /* Set clipping for output in glyph row ROW. W is the window in which
7113 we operate. GC is the graphics context to set clipping in.
7115 ROW may be a text row or, e.g., a mode line. Text rows must be
7116 clipped to the interior of the window dedicated to text display,
7117 mode lines must be clipped to the whole window. */
7120 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
7121 enum glyph_row_area area
, GC gc
)
7123 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7124 XRectangle clip_rect
;
7125 int window_x
, window_y
, window_width
;
7127 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7129 clip_rect
.x
= window_x
;
7130 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7131 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7132 clip_rect
.width
= window_width
;
7133 clip_rect
.height
= row
->visible_height
;
7135 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7139 /* Draw a hollow box cursor on window W in glyph row ROW. */
7142 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7144 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7145 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
7146 Display
*dpy
= FRAME_X_DISPLAY (f
);
7149 struct glyph
*cursor_glyph
;
7152 /* Get the glyph the cursor is on. If we can't tell because
7153 the current matrix is invalid or such, give up. */
7154 cursor_glyph
= get_phys_cursor_glyph (w
);
7155 if (cursor_glyph
== NULL
)
7158 /* Compute frame-relative coordinates for phys cursor. */
7159 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7160 wd
= w
->phys_cursor_width
;
7162 /* The foreground of cursor_gc is typically the same as the normal
7163 background color, which can cause the cursor box to be invisible. */
7164 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7165 if (dpyinfo
->scratch_cursor_gc
)
7166 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7168 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7169 GCForeground
, &xgcv
);
7170 gc
= dpyinfo
->scratch_cursor_gc
;
7172 /* Set clipping, draw the rectangle, and reset clipping again. */
7173 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7174 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7175 XSetClipMask (dpy
, gc
, None
);
7179 /* Draw a bar cursor on window W in glyph row ROW.
7181 Implementation note: One would like to draw a bar cursor with an
7182 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7183 Unfortunately, I didn't find a font yet that has this property set.
7187 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7189 struct frame
*f
= XFRAME (w
->frame
);
7190 struct glyph
*cursor_glyph
;
7192 /* If cursor is out of bounds, don't draw garbage. This can happen
7193 in mini-buffer windows when switching between echo area glyphs
7195 cursor_glyph
= get_phys_cursor_glyph (w
);
7196 if (cursor_glyph
== NULL
)
7199 /* If on an image, draw like a normal cursor. That's usually better
7200 visible than drawing a bar, esp. if the image is large so that
7201 the bar might not be in the window. */
7202 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7204 struct glyph_row
*r
;
7205 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7206 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
7210 Display
*dpy
= FRAME_X_DISPLAY (f
);
7211 Window window
= FRAME_X_WINDOW (f
);
7212 GC gc
= FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7213 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7214 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7217 /* If the glyph's background equals the color we normally draw
7218 the bars cursor in, the bar cursor in its normal color is
7219 invisible. Use the glyph's foreground color instead in this
7220 case, on the assumption that the glyph's colors are chosen so
7221 that the glyph is legible. */
7222 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7223 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7225 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7226 xgcv
.graphics_exposures
= 0;
7229 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7232 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7233 FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7236 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7238 if (kind
== BAR_CURSOR
)
7240 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7243 width
= FRAME_CURSOR_WIDTH (f
);
7244 width
= min (cursor_glyph
->pixel_width
, width
);
7246 w
->phys_cursor_width
= width
;
7248 /* If the character under cursor is R2L, draw the bar cursor
7249 on the right of its glyph, rather than on the left. */
7250 if ((cursor_glyph
->resolved_level
& 1) != 0)
7251 x
+= cursor_glyph
->pixel_width
- width
;
7253 XFillRectangle (dpy
, window
, gc
, x
,
7254 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7255 width
, row
->height
);
7259 int dummy_x
, dummy_y
, dummy_h
;
7262 width
= row
->height
;
7264 width
= min (row
->height
, width
);
7266 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7267 &dummy_y
, &dummy_h
);
7269 XFillRectangle (dpy
, window
, gc
,
7270 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7271 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7272 row
->height
- width
),
7273 w
->phys_cursor_width
, width
);
7276 XSetClipMask (dpy
, gc
, None
);
7281 /* RIF: Define cursor CURSOR on frame F. */
7284 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7286 if (!f
->pointer_invisible
7287 && f
->output_data
.x
->current_cursor
!= cursor
)
7288 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7289 f
->output_data
.x
->current_cursor
= cursor
;
7293 /* RIF: Clear area on frame F. */
7296 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7298 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), x
, y
, width
, height
);
7300 /* Must queue a redraw, because scroll bars might have been cleared. */
7301 if (FRAME_GTK_WIDGET (f
))
7302 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7307 /* RIF: Draw cursor on window W. */
7310 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
7311 int y
, enum text_cursor_kinds cursor_type
,
7312 int cursor_width
, bool on_p
, bool active_p
)
7314 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7318 w
->phys_cursor_type
= cursor_type
;
7319 w
->phys_cursor_on_p
= 1;
7321 if (glyph_row
->exact_window_width_line_p
7322 && (glyph_row
->reversed_p
7323 ? (w
->phys_cursor
.hpos
< 0)
7324 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7326 glyph_row
->cursor_in_fringe_p
= 1;
7327 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7331 switch (cursor_type
)
7333 case HOLLOW_BOX_CURSOR
:
7334 x_draw_hollow_cursor (w
, glyph_row
);
7337 case FILLED_BOX_CURSOR
:
7338 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7342 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7346 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7350 w
->phys_cursor_width
= 0;
7359 if (w
== XWINDOW (f
->selected_window
))
7360 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7361 xic_set_preeditarea (w
, x
, y
);
7365 XFlush (FRAME_X_DISPLAY (f
));
7371 /* Make the x-window of frame F use the gnu icon bitmap. */
7374 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7376 ptrdiff_t bitmap_id
;
7378 if (FRAME_X_WINDOW (f
) == 0)
7381 /* Free up our existing icon bitmap and mask if any. */
7382 if (f
->output_data
.x
->icon_bitmap
> 0)
7383 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7384 f
->output_data
.x
->icon_bitmap
= 0;
7389 /* Use gtk_window_set_icon_from_file () if available,
7390 It's not restricted to bitmaps */
7391 if (xg_set_icon (f
, file
))
7393 #endif /* USE_GTK */
7394 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7395 x_create_bitmap_mask (f
, bitmap_id
);
7399 /* Create the GNU bitmap and mask if necessary. */
7400 if (FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7406 if (xg_set_icon (f
, xg_default_icon_file
)
7407 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7410 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7412 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7414 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7418 /* If all else fails, use the (black and white) xbm image. */
7421 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
7422 gnu_xbm_width
, gnu_xbm_height
);
7426 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7427 x_create_bitmap_mask (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7431 /* The first time we create the GNU bitmap and mask,
7432 this increments the ref-count one extra time.
7433 As a result, the GNU bitmap and mask are never freed.
7434 That way, we don't have to worry about allocating it again. */
7435 x_reference_bitmap (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7437 bitmap_id
= FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
;
7440 x_wm_set_icon_pixmap (f
, bitmap_id
);
7441 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7447 /* Make the x-window of frame F use a rectangle with text.
7448 Use ICON_NAME as the text. */
7451 x_text_icon (struct frame
*f
, const char *icon_name
)
7453 if (FRAME_X_WINDOW (f
) == 0)
7458 text
.value
= (unsigned char *) icon_name
;
7459 text
.encoding
= XA_STRING
;
7461 text
.nitems
= strlen (icon_name
);
7462 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7465 if (f
->output_data
.x
->icon_bitmap
> 0)
7466 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7467 f
->output_data
.x
->icon_bitmap
= 0;
7468 x_wm_set_icon_pixmap (f
, 0);
7473 #define X_ERROR_MESSAGE_SIZE 200
7475 /* If non-nil, this should be a string.
7476 It means catch X errors and store the error message in this string.
7478 The reason we use a stack is that x_catch_error/x_uncatch_error can
7479 be called from a signal handler.
7482 struct x_error_message_stack
{
7483 char string
[X_ERROR_MESSAGE_SIZE
];
7485 struct x_error_message_stack
*prev
;
7487 static struct x_error_message_stack
*x_error_message
;
7489 /* An X error handler which stores the error message in
7490 *x_error_message. This is called from x_error_handler if
7491 x_catch_errors is in effect. */
7494 x_error_catcher (Display
*display
, XErrorEvent
*event
)
7496 XGetErrorText (display
, event
->error_code
,
7497 x_error_message
->string
,
7498 X_ERROR_MESSAGE_SIZE
);
7501 /* Begin trapping X errors for display DPY. Actually we trap X errors
7502 for all displays, but DPY should be the display you are actually
7505 After calling this function, X protocol errors no longer cause
7506 Emacs to exit; instead, they are recorded in the string
7507 stored in *x_error_message.
7509 Calling x_check_errors signals an Emacs error if an X error has
7510 occurred since the last call to x_catch_errors or x_check_errors.
7512 Calling x_uncatch_errors resumes the normal error handling. */
7515 x_catch_errors (Display
*dpy
)
7517 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
7519 /* Make sure any errors from previous requests have been dealt with. */
7523 data
->string
[0] = 0;
7524 data
->prev
= x_error_message
;
7525 x_error_message
= data
;
7528 /* Undo the last x_catch_errors call.
7529 DPY should be the display that was passed to x_catch_errors. */
7532 x_uncatch_errors (void)
7534 struct x_error_message_stack
*tmp
;
7538 /* The display may have been closed before this function is called.
7539 Check if it is still open before calling XSync. */
7540 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7541 XSync (x_error_message
->dpy
, False
);
7543 tmp
= x_error_message
;
7544 x_error_message
= x_error_message
->prev
;
7549 /* If any X protocol errors have arrived since the last call to
7550 x_catch_errors or x_check_errors, signal an Emacs error using
7551 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7554 x_check_errors (Display
*dpy
, const char *format
)
7556 /* Make sure to catch any errors incurred so far. */
7559 if (x_error_message
->string
[0])
7561 char string
[X_ERROR_MESSAGE_SIZE
];
7562 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7563 x_uncatch_errors ();
7564 error (format
, string
);
7568 /* Nonzero if we had any X protocol errors
7569 since we did x_catch_errors on DPY. */
7572 x_had_errors_p (Display
*dpy
)
7574 /* Make sure to catch any errors incurred so far. */
7577 return x_error_message
->string
[0] != 0;
7580 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7583 x_clear_errors (Display
*dpy
)
7585 x_error_message
->string
[0] = 0;
7588 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7589 * idea. --lorentey */
7590 /* Close off all unclosed x_catch_errors calls. */
7593 x_fully_uncatch_errors (void)
7595 while (x_error_message
)
7596 x_uncatch_errors ();
7601 static unsigned int x_wire_count
;
7604 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7609 /************************************************************************
7611 ************************************************************************/
7613 /* Error message passed to x_connection_closed. */
7615 static char *error_msg
;
7617 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7618 the text of an error message that lead to the connection loss. */
7621 x_connection_closed (Display
*dpy
, const char *error_message
)
7623 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7624 Lisp_Object frame
, tail
;
7625 ptrdiff_t idx
= SPECPDL_INDEX ();
7627 error_msg
= alloca (strlen (error_message
) + 1);
7628 strcpy (error_msg
, error_message
);
7630 /* Inhibit redisplay while frames are being deleted. */
7631 specbind (Qinhibit_redisplay
, Qt
);
7635 /* Protect display from being closed when we delete the last
7637 dpyinfo
->reference_count
++;
7638 dpyinfo
->terminal
->reference_count
++;
7641 /* First delete frames whose mini-buffers are on frames
7642 that are on the dead display. */
7643 FOR_EACH_FRAME (tail
, frame
)
7645 Lisp_Object minibuf_frame
;
7647 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7648 if (FRAME_X_P (XFRAME (frame
))
7649 && FRAME_X_P (XFRAME (minibuf_frame
))
7650 && ! EQ (frame
, minibuf_frame
)
7651 && FRAME_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7652 delete_frame (frame
, Qnoelisp
);
7655 /* Now delete all remaining frames on the dead display.
7656 We are now sure none of these is used as the mini-buffer
7657 for another frame that we need to delete. */
7658 FOR_EACH_FRAME (tail
, frame
)
7659 if (FRAME_X_P (XFRAME (frame
))
7660 && FRAME_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7662 /* Set this to t so that delete_frame won't get confused
7663 trying to find a replacement. */
7664 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
7665 delete_frame (frame
, Qnoelisp
);
7668 /* If DPYINFO is null, this means we didn't open the display in the
7669 first place, so don't try to close it. */
7672 /* We can not call XtCloseDisplay here because it calls XSync.
7673 XSync inside the error handler apparently hangs Emacs. On
7674 current Xt versions, this isn't needed either. */
7676 /* A long-standing GTK bug prevents proper disconnect handling
7677 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
7678 the resulting Glib error message loop filled a user's disk.
7679 To avoid this, kill Emacs unconditionally on disconnect. */
7680 shut_down_emacs (0, Qnil
);
7681 fprintf (stderr
, "%s\n\
7682 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
7683 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
7684 For details, see etc/PROBLEMS.\n",
7687 #endif /* USE_GTK */
7689 /* Indicate that this display is dead. */
7690 dpyinfo
->display
= 0;
7692 dpyinfo
->reference_count
--;
7693 dpyinfo
->terminal
->reference_count
--;
7694 if (dpyinfo
->reference_count
!= 0)
7695 /* We have just closed all frames on this display. */
7700 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7701 Fdelete_terminal (tmp
, Qnoelisp
);
7705 if (terminal_list
== 0)
7707 fprintf (stderr
, "%s\n", error_msg
);
7708 Fkill_emacs (make_number (70));
7712 totally_unblock_input ();
7714 unbind_to (idx
, Qnil
);
7715 clear_waiting_for_input ();
7717 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
7718 IF_LINT (if (! terminal_list
) return; )
7720 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7721 longjmp), because returning from this function would get us back into
7722 Xlib's code which will directly call `exit'. */
7723 error ("%s", error_msg
);
7726 /* We specifically use it before defining it, so that gcc doesn't inline it,
7727 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7728 static void x_error_quitter (Display
*, XErrorEvent
*);
7730 /* This is the first-level handler for X protocol errors.
7731 It calls x_error_quitter or x_error_catcher. */
7734 x_error_handler (Display
*display
, XErrorEvent
*event
)
7736 #if defined USE_GTK && defined HAVE_GTK3
7737 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
7738 && event
->request_code
== X_SetInputFocus
)
7744 if (x_error_message
)
7745 x_error_catcher (display
, event
);
7747 x_error_quitter (display
, event
);
7751 /* This is the usual handler for X protocol errors.
7752 It kills all frames on the display that we got the error for.
7753 If that was the only one, it prints an error message and kills Emacs. */
7755 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7757 /* On older GCC versions, just putting x_error_quitter
7758 after x_error_handler prevents inlining into the former. */
7760 static void NO_INLINE
7761 x_error_quitter (Display
*display
, XErrorEvent
*event
)
7763 char buf
[256], buf1
[356];
7765 /* Ignore BadName errors. They can happen because of fonts
7766 or colors that are not defined. */
7768 if (event
->error_code
== BadName
)
7771 /* Note that there is no real way portable across R3/R4 to get the
7772 original error handler. */
7774 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
7775 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7776 buf
, event
->request_code
);
7777 x_connection_closed (display
, buf1
);
7781 /* This is the handler for X IO errors, always.
7782 It kills all frames on the display that we lost touch with.
7783 If that was the only one, it prints an error message and kills Emacs. */
7786 x_io_error_quitter (Display
*display
)
7790 snprintf (buf
, sizeof buf
, "Connection lost to X server `%s'",
7791 DisplayString (display
));
7792 x_connection_closed (display
, buf
);
7796 /* Changing the font of the frame. */
7798 /* Give frame F the font FONT-OBJECT as its default font. The return
7799 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7800 frame. If it is negative, generate a new fontset from
7804 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7806 struct font
*font
= XFONT_OBJECT (font_object
);
7809 fontset
= fontset_from_font (font_object
);
7810 FRAME_FONTSET (f
) = fontset
;
7811 if (FRAME_FONT (f
) == font
)
7812 /* This font is already set in frame F. There's nothing more to
7816 FRAME_FONT (f
) = font
;
7817 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7818 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7819 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7821 compute_fringe_widths (f
, 1);
7823 /* Compute the scroll bar width in character columns. */
7824 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7826 int wid
= FRAME_COLUMN_WIDTH (f
);
7827 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7828 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7832 int wid
= FRAME_COLUMN_WIDTH (f
);
7833 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7836 if (FRAME_X_WINDOW (f
) != 0)
7838 /* Don't change the size of a tip frame; there's no point in
7839 doing it because it's done in Fx_show_tip, and it leads to
7840 problems because the tip frame has no widget. */
7841 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7842 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7847 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7850 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
7859 /***********************************************************************
7861 ***********************************************************************/
7867 /* XIM destroy callback function, which is called whenever the
7868 connection to input method XIM dies. CLIENT_DATA contains a
7869 pointer to the x_display_info structure corresponding to XIM. */
7872 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
7874 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7875 Lisp_Object frame
, tail
;
7879 /* No need to call XDestroyIC.. */
7880 FOR_EACH_FRAME (tail
, frame
)
7882 struct frame
*f
= XFRAME (frame
);
7883 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
7885 FRAME_XIC (f
) = NULL
;
7886 xic_free_xfontset (f
);
7890 /* No need to call XCloseIM. */
7891 dpyinfo
->xim
= NULL
;
7892 XFree (dpyinfo
->xim_styles
);
7896 #endif /* HAVE_X11R6 */
7899 /* This isn't prototyped in OSF 5.0 or 5.1a. */
7900 extern char *XSetIMValues (XIM
, ...);
7903 /* Open the connection to the XIM server on display DPYINFO.
7904 RESOURCE_NAME is the resource name Emacs uses. */
7907 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
7915 XCloseIM (dpyinfo
->xim
);
7916 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
7923 XIMCallback destroy
;
7926 /* Get supported styles and XIM values. */
7927 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
7930 destroy
.callback
= xim_destroy_callback
;
7931 destroy
.client_data
= (XPointer
)dpyinfo
;
7932 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
7938 #endif /* HAVE_XIM */
7939 dpyinfo
->xim
= NULL
;
7943 #ifdef HAVE_X11R6_XIM
7945 /* XIM instantiate callback function, which is called whenever an XIM
7946 server is available. DISPLAY is the display of the XIM.
7947 CLIENT_DATA contains a pointer to an xim_inst_t structure created
7948 when the callback was registered. */
7951 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
7953 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
7954 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
7956 /* We don't support multiple XIM connections. */
7960 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
7962 /* Create XIC for the existing frames on the same display, as long
7963 as they have no XIC. */
7964 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
7966 Lisp_Object tail
, frame
;
7969 FOR_EACH_FRAME (tail
, frame
)
7971 struct frame
*f
= XFRAME (frame
);
7974 && FRAME_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
7975 if (FRAME_XIC (f
) == NULL
)
7977 create_frame_xic (f
);
7978 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
7979 xic_set_statusarea (f
);
7980 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
7982 struct window
*w
= XWINDOW (f
->selected_window
);
7983 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
7992 #endif /* HAVE_X11R6_XIM */
7995 /* Open a connection to the XIM server on display DPYINFO.
7996 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
7997 connection only at the first time. On X11R6, open the connection
7998 in the XIM instantiate callback function. */
8001 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
8003 dpyinfo
->xim
= NULL
;
8007 #ifdef HAVE_X11R6_XIM
8008 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
8010 dpyinfo
->xim_callback_data
= xim_inst
;
8011 xim_inst
->dpyinfo
= dpyinfo
;
8012 xim_inst
->resource_name
= xstrdup (resource_name
);
8013 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8014 resource_name
, emacs_class
,
8015 xim_instantiate_callback
,
8016 /* This is XPointer in XFree86
8017 but (XPointer *) on Tru64, at
8018 least, hence the configure test. */
8019 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8020 #else /* not HAVE_X11R6_XIM */
8021 xim_open_dpy (dpyinfo
, resource_name
);
8022 #endif /* not HAVE_X11R6_XIM */
8024 #endif /* HAVE_XIM */
8028 /* Close the connection to the XIM server on display DPYINFO. */
8031 xim_close_dpy (struct x_display_info
*dpyinfo
)
8036 #ifdef HAVE_X11R6_XIM
8037 if (dpyinfo
->display
)
8038 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8040 xim_instantiate_callback
, NULL
);
8041 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8042 xfree (dpyinfo
->xim_callback_data
);
8043 #endif /* HAVE_X11R6_XIM */
8044 if (dpyinfo
->display
)
8045 XCloseIM (dpyinfo
->xim
);
8046 dpyinfo
->xim
= NULL
;
8047 XFree (dpyinfo
->xim_styles
);
8049 #endif /* HAVE_XIM */
8052 #endif /* not HAVE_X11R6_XIM */
8056 /* Calculate the absolute position in frame F
8057 from its current recorded position values and gravity. */
8060 x_calc_absolute_position (struct frame
*f
)
8062 int flags
= f
->size_hint_flags
;
8064 /* We have nothing to do if the current position
8065 is already for the top-left corner. */
8066 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8069 /* Treat negative positions as relative to the leftmost bottommost
8070 position that fits on the screen. */
8071 if (flags
& XNegative
)
8072 f
->left_pos
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
8073 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8076 int height
= FRAME_PIXEL_HEIGHT (f
);
8078 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8079 /* Something is fishy here. When using Motif, starting Emacs with
8080 `-g -0-0', the frame appears too low by a few pixels.
8082 This seems to be so because initially, while Emacs is starting,
8083 the column widget's height and the frame's pixel height are
8084 different. The column widget's height is the right one. In
8085 later invocations, when Emacs is up, the frame's pixel height
8088 It's not obvious where the initial small difference comes from.
8089 2000-12-01, gerd. */
8091 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8094 if (flags
& YNegative
)
8095 f
->top_pos
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
8096 - height
+ f
->top_pos
;
8099 /* The left_pos and top_pos
8100 are now relative to the top and left screen edges,
8101 so the flags should correspond. */
8102 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8105 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8106 to really change the position, and 0 when calling from
8107 x_make_frame_visible (in that case, XOFF and YOFF are the current
8108 position values). It is -1 when calling from x_set_frame_parameters,
8109 which means, do adjust for borders but don't change the gravity. */
8112 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8114 int modified_top
, modified_left
;
8116 if (change_gravity
> 0)
8120 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8122 f
->size_hint_flags
|= XNegative
;
8124 f
->size_hint_flags
|= YNegative
;
8125 f
->win_gravity
= NorthWestGravity
;
8127 x_calc_absolute_position (f
);
8130 x_wm_set_size_hint (f
, (long) 0, 0);
8132 modified_left
= f
->left_pos
;
8133 modified_top
= f
->top_pos
;
8135 if (change_gravity
!= 0 && FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8137 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8138 than the WM decorations. So we use the calculated offset instead
8139 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8140 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8141 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8144 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8145 modified_left
, modified_top
);
8147 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8148 FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8151 /* change_gravity is non-zero when this function is called from Lisp to
8152 programmatically move a frame. In that case, we call
8153 x_check_expected_move to discover if we have a "Type A" or "Type B"
8154 window manager, and, for a "Type A" window manager, adjust the position
8157 We call x_check_expected_move if a programmatic move occurred, and
8158 either the window manager type (A/B) is unknown or it is Type A but we
8159 need to compute the top/left offset adjustment for this frame. */
8161 if (change_gravity
!= 0 &&
8162 (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8163 || (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8164 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8165 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8166 x_check_expected_move (f
, modified_left
, modified_top
);
8171 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8172 on the root window for frame F contains ATOMNAME.
8173 This is how a WM check shall be done according to the Window Manager
8174 Specification/Extended Window Manager Hints at
8175 http://freedesktop.org/wiki/Specifications/wm-spec. */
8178 wm_supports (struct frame
*f
, Atom want_atom
)
8181 unsigned long actual_size
, bytes_remaining
;
8182 int i
, rc
, actual_format
;
8183 Window wmcheck_window
;
8184 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8185 Window target_window
= dpyinfo
->root_window
;
8186 long max_len
= 65536;
8187 Display
*dpy
= FRAME_X_DISPLAY (f
);
8188 unsigned char *tmp_data
= NULL
;
8189 Atom target_type
= XA_WINDOW
;
8193 x_catch_errors (dpy
);
8194 rc
= XGetWindowProperty (dpy
, target_window
,
8195 dpyinfo
->Xatom_net_supporting_wm_check
,
8196 0, max_len
, False
, target_type
,
8197 &actual_type
, &actual_format
, &actual_size
,
8198 &bytes_remaining
, &tmp_data
);
8200 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8202 if (tmp_data
) XFree (tmp_data
);
8203 x_uncatch_errors ();
8208 wmcheck_window
= *(Window
*) tmp_data
;
8211 /* Check if window exists. */
8212 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8214 if (x_had_errors_p (dpy
))
8216 x_uncatch_errors ();
8221 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8223 /* Window changed, reload atoms */
8224 if (dpyinfo
->net_supported_atoms
!= NULL
)
8225 XFree (dpyinfo
->net_supported_atoms
);
8226 dpyinfo
->net_supported_atoms
= NULL
;
8227 dpyinfo
->nr_net_supported_atoms
= 0;
8228 dpyinfo
->net_supported_window
= 0;
8230 target_type
= XA_ATOM
;
8232 rc
= XGetWindowProperty (dpy
, target_window
,
8233 dpyinfo
->Xatom_net_supported
,
8234 0, max_len
, False
, target_type
,
8235 &actual_type
, &actual_format
, &actual_size
,
8236 &bytes_remaining
, &tmp_data
);
8238 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8240 if (tmp_data
) XFree (tmp_data
);
8241 x_uncatch_errors ();
8246 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8247 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8248 dpyinfo
->net_supported_window
= wmcheck_window
;
8253 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8254 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8256 x_uncatch_errors ();
8263 set_wm_state (Lisp_Object frame
, int add
, Atom atom
, Atom value
)
8265 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (XFRAME (frame
));
8267 x_send_client_event (frame
, make_number (0), frame
,
8268 dpyinfo
->Xatom_net_wm_state
,
8270 /* 1 = add, 0 = remove */
8272 (make_number (add
? 1 : 0),
8274 (make_fixnum_or_float (atom
),
8276 ? list1 (make_fixnum_or_float (value
))
8281 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8284 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8286 XSETFRAME (frame
, f
);
8288 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8289 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
8292 /* Return the current _NET_WM_STATE.
8293 SIZE_STATE is set to one of the FULLSCREEN_* values.
8294 STICKY is set to 1 if the sticky state is set, 0 if not.
8296 Return non-zero if we are not hidden, zero if we are. */
8299 get_current_wm_state (struct frame
*f
,
8305 unsigned long actual_size
, bytes_remaining
;
8306 int i
, rc
, actual_format
, is_hidden
= 0;
8307 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8308 long max_len
= 65536;
8309 Display
*dpy
= FRAME_X_DISPLAY (f
);
8310 unsigned char *tmp_data
= NULL
;
8311 Atom target_type
= XA_ATOM
;
8314 *size_state
= FULLSCREEN_NONE
;
8317 x_catch_errors (dpy
);
8318 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
8319 0, max_len
, False
, target_type
,
8320 &actual_type
, &actual_format
, &actual_size
,
8321 &bytes_remaining
, &tmp_data
);
8323 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8325 if (tmp_data
) XFree (tmp_data
);
8326 x_uncatch_errors ();
8328 return !FRAME_ICONIFIED_P (f
);
8331 x_uncatch_errors ();
8333 for (i
= 0; i
< actual_size
; ++i
)
8335 Atom a
= ((Atom
*)tmp_data
)[i
];
8336 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
8339 f
->output_data
.x
->net_wm_state_hidden_seen
= 1;
8341 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8343 if (*size_state
== FULLSCREEN_HEIGHT
)
8344 *size_state
= FULLSCREEN_MAXIMIZED
;
8346 *size_state
= FULLSCREEN_WIDTH
;
8348 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8350 if (*size_state
== FULLSCREEN_WIDTH
)
8351 *size_state
= FULLSCREEN_MAXIMIZED
;
8353 *size_state
= FULLSCREEN_HEIGHT
;
8355 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
8356 *size_state
= FULLSCREEN_BOTH
;
8357 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8361 if (tmp_data
) XFree (tmp_data
);
8366 /* Do fullscreen as specified in extended window manager hints */
8369 do_ewmh_fullscreen (struct frame
*f
)
8371 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8372 int have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
8375 (void)get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
8377 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8378 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8380 have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
8382 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
8386 XSETFRAME (frame
, f
);
8388 /* Keep number of calls to set_wm_state as low as possible.
8389 Some window managers, or possible Gtk+, hangs when too many
8390 are sent at once. */
8391 switch (f
->want_fullscreen
)
8393 case FULLSCREEN_BOTH
:
8394 if (cur
== FULLSCREEN_WIDTH
|| cur
== FULLSCREEN_MAXIMIZED
8395 || cur
== FULLSCREEN_HEIGHT
)
8396 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8397 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8398 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8400 case FULLSCREEN_WIDTH
:
8401 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
8402 || cur
== FULLSCREEN_MAXIMIZED
)
8403 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8404 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8405 if (cur
!= FULLSCREEN_MAXIMIZED
)
8406 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
8408 case FULLSCREEN_HEIGHT
:
8409 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
8410 || cur
== FULLSCREEN_MAXIMIZED
)
8411 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8412 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
8413 if (cur
!= FULLSCREEN_MAXIMIZED
)
8414 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
8416 case FULLSCREEN_MAXIMIZED
:
8417 if (cur
== FULLSCREEN_BOTH
)
8418 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8419 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8420 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8422 case FULLSCREEN_NONE
:
8423 if (cur
== FULLSCREEN_BOTH
)
8424 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8426 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8427 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8430 f
->want_fullscreen
= FULLSCREEN_NONE
;
8434 return have_net_atom
;
8438 XTfullscreen_hook (struct frame
*f
)
8440 if (FRAME_VISIBLE_P (f
))
8443 x_check_fullscreen (f
);
8451 x_handle_net_wm_state (struct frame
*f
, const XPropertyEvent
*event
)
8453 int value
= FULLSCREEN_NONE
;
8456 int not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
8461 case FULLSCREEN_WIDTH
:
8464 case FULLSCREEN_HEIGHT
:
8467 case FULLSCREEN_BOTH
:
8470 case FULLSCREEN_MAXIMIZED
:
8475 store_frame_param (f
, Qfullscreen
, lval
);
8476 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8481 /* Check if we need to resize the frame due to a fullscreen request.
8482 If so needed, resize the frame. */
8484 x_check_fullscreen (struct frame
*f
)
8486 if (do_ewmh_fullscreen (f
))
8489 if (f
->output_data
.x
->parent_desc
!= FRAME_DISPLAY_INFO (f
)->root_window
)
8490 return; /* Only fullscreen without WM or with EWM hints (above). */
8492 /* Setting fullscreen to nil doesn't do anything. We could save the
8493 last non-fullscreen size and restore it, but it seems like a
8494 lot of work for this unusual case (no window manager running). */
8496 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8498 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
8499 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8501 switch (f
->want_fullscreen
)
8503 /* No difference between these two when there is no WM */
8504 case FULLSCREEN_BOTH
:
8505 case FULLSCREEN_MAXIMIZED
:
8506 width
= x_display_pixel_width (dpyinfo
);
8507 height
= x_display_pixel_height (dpyinfo
);
8509 case FULLSCREEN_WIDTH
:
8510 width
= x_display_pixel_width (dpyinfo
);
8512 case FULLSCREEN_HEIGHT
:
8513 height
= x_display_pixel_height (dpyinfo
);
8516 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8521 /* This function is called by x_set_offset to determine whether the window
8522 manager interfered with the positioning of the frame. Type A window
8523 managers position the surrounding window manager decorations a small
8524 amount above and left of the user-supplied position. Type B window
8525 managers position the surrounding window manager decorations at the
8526 user-specified position. If we detect a Type A window manager, we
8527 compensate by moving the window right and down by the proper amount. */
8530 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8532 int current_left
= 0, current_top
= 0;
8534 /* x_real_positions returns the left and top offsets of the outermost
8535 window manager window around the frame. */
8537 x_real_positions (f
, ¤t_left
, ¤t_top
);
8539 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8541 /* It's a "Type A" window manager. */
8546 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8547 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8548 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8550 /* Now fix the mispositioned frame's location. */
8552 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8553 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8555 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8556 adjusted_left
, adjusted_top
);
8558 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8561 /* It's a "Type B" window manager. We don't have to adjust the
8562 frame's position. */
8564 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8568 /* Wait for XGetGeometry to return up-to-date position information for a
8569 recently-moved frame. Call this immediately after calling XMoveWindow.
8570 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8571 frame has been moved to, so we use a fuzzy position comparison instead
8572 of an exact comparison. */
8575 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8579 while (count
++ < 50)
8581 int current_left
= 0, current_top
= 0;
8583 /* In theory, this call to XSync only needs to happen once, but in
8584 practice, it doesn't seem to work, hence the need for the surrounding
8587 XSync (FRAME_X_DISPLAY (f
), False
);
8588 x_real_positions (f
, ¤t_left
, ¤t_top
);
8592 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8595 if (eabs (current_left
- left
) <= 10
8596 && eabs (current_top
- top
) <= 40)
8599 else if (current_left
== left
&& current_top
== top
)
8603 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8604 will then return up-to-date position info. */
8606 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8610 /* Wait for an event on frame F matching EVENTTYPE. */
8612 x_wait_for_event (struct frame
*f
, int eventtype
)
8614 int level
= interrupt_input_blocked
;
8617 struct timespec tmo
, tmo_at
, time_now
;
8618 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8620 f
->wait_event_type
= eventtype
;
8622 /* Set timeout to 0.1 second. Hopefully not noticeable.
8623 Maybe it should be configurable. */
8624 tmo
= make_timespec (0, 100 * 1000 * 1000);
8625 tmo_at
= timespec_add (current_timespec (), tmo
);
8627 while (f
->wait_event_type
)
8629 pending_signals
= 1;
8630 totally_unblock_input ();
8631 /* XTread_socket is called after unblock. */
8633 interrupt_input_blocked
= level
;
8638 time_now
= current_timespec ();
8639 if (timespec_cmp (tmo_at
, time_now
) < 0)
8642 tmo
= timespec_sub (tmo_at
, time_now
);
8643 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
8644 break; /* Timeout */
8647 f
->wait_event_type
= 0;
8651 /* Change the size of frame F's X window to COLS/ROWS in the case F
8652 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8653 top-left-corner window gravity for this size change and subsequent
8654 size changes. Otherwise we leave the window gravity unchanged. */
8657 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8659 int pixelwidth
, pixelheight
;
8661 check_frame_size (f
, &rows
, &cols
);
8662 f
->scroll_bar_actual_width
8663 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8665 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8667 compute_fringe_widths (f
, 0);
8669 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8670 + FRAME_TOOLBAR_WIDTH (f
);
8671 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8672 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8674 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8675 x_wm_set_size_hint (f
, (long) 0, 0);
8676 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8677 pixelwidth
, pixelheight
);
8680 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8681 receive in the ConfigureNotify event; if we get what we asked
8682 for, then the event won't cause the screen to become garbaged, so
8683 we have to make sure to do it here. */
8684 SET_FRAME_GARBAGED (f
);
8686 /* Now, strictly speaking, we can't be sure that this is accurate,
8687 but the window manager will get around to dealing with the size
8688 change request eventually, and we'll hear how it went when the
8689 ConfigureNotify event gets here.
8691 We could just not bother storing any of this information here,
8692 and let the ConfigureNotify event set everything up, but that
8693 might be kind of confusing to the Lisp code, since size changes
8694 wouldn't be reported in the frame parameters until some random
8695 point in the future when the ConfigureNotify event arrives.
8697 We pass 1 for DELAY since we can't run Lisp code inside of
8700 /* But the ConfigureNotify may in fact never arrive, and then this is
8701 not right if the frame is visible. Instead wait (with timeout)
8702 for the ConfigureNotify. */
8703 if (FRAME_VISIBLE_P (f
))
8704 x_wait_for_event (f
, ConfigureNotify
);
8707 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8708 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8709 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8715 /* Call this to change the size of frame F's x-window.
8716 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8717 for this size change and subsequent size changes.
8718 Otherwise we leave the window gravity unchanged. */
8721 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8725 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8729 /* When the frame is maximized/fullscreen or running under for
8730 example Xmonad, x_set_window_size_1 will be a no-op.
8731 In that case, the right thing to do is extend rows/cols to
8732 the current frame size. We do that first if x_set_window_size_1
8733 turns out to not be a no-op (there is no way to know).
8734 The size will be adjusted again if the frame gets a
8735 ConfigureNotify event as a result of x_set_window_size. */
8736 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8737 #ifdef USE_X_TOOLKIT
8738 /* The menu bar is not part of text lines. The tool bar
8740 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8742 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8743 /* Update f->scroll_bar_actual_width because it is used in
8744 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8745 f
->scroll_bar_actual_width
8746 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8747 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8748 change_frame_size (f
, r
, c
, 0, 1, 0);
8752 if (FRAME_GTK_WIDGET (f
))
8753 xg_frame_set_char_size (f
, cols
, rows
);
8755 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8756 #else /* not USE_GTK */
8758 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8760 #endif /* not USE_GTK */
8762 /* If cursor was outside the new size, mark it as off. */
8763 mark_window_cursors_off (XWINDOW (f
->root_window
));
8765 /* Clear out any recollection of where the mouse highlighting was,
8766 since it might be in a place that's outside the new frame size.
8767 Actually checking whether it is outside is a pain in the neck,
8768 so don't try--just let the highlighting be done afresh with new size. */
8769 cancel_mouse_face (f
);
8774 /* Mouse warping. */
8777 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8781 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8782 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8784 if (pix_x
< 0) pix_x
= 0;
8785 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8787 if (pix_y
< 0) pix_y
= 0;
8788 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8792 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8793 0, 0, 0, 0, pix_x
, pix_y
);
8797 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8800 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8804 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8805 0, 0, 0, 0, pix_x
, pix_y
);
8809 /* Raise frame F. */
8812 x_raise_frame (struct frame
*f
)
8815 if (FRAME_VISIBLE_P (f
))
8816 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8817 XFlush (FRAME_X_DISPLAY (f
));
8821 /* Lower frame F. */
8824 x_lower_frame (struct frame
*f
)
8826 if (FRAME_VISIBLE_P (f
))
8829 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8830 XFlush (FRAME_X_DISPLAY (f
));
8835 /* Request focus with XEmbed */
8838 xembed_request_focus (struct frame
*f
)
8840 /* See XEmbed Protocol Specification at
8841 http://freedesktop.org/wiki/Specifications/xembed-spec */
8842 if (FRAME_VISIBLE_P (f
))
8843 xembed_send_message (f
, CurrentTime
,
8844 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
8847 /* Activate frame with Extended Window Manager Hints */
8850 x_ewmh_activate_frame (struct frame
*f
)
8852 /* See Window Manager Specification/Extended Window Manager Hints at
8853 http://freedesktop.org/wiki/Specifications/wm-spec */
8855 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8857 if (FRAME_VISIBLE_P (f
) && wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
8860 XSETFRAME (frame
, f
);
8861 x_send_client_event (frame
, make_number (0), frame
,
8862 dpyinfo
->Xatom_net_active_window
,
8864 list2i (1, dpyinfo
->last_user_time
));
8869 XTframe_raise_lower (struct frame
*f
, int raise_flag
)
8877 /* XEmbed implementation. */
8879 #if defined USE_X_TOOLKIT || ! defined USE_GTK
8881 /* XEmbed implementation. */
8883 #define XEMBED_VERSION 0
8886 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
8888 unsigned long data
[2];
8889 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8891 data
[0] = XEMBED_VERSION
;
8894 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8895 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
8896 32, PropModeReplace
, (unsigned char *) data
, 2);
8898 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
8901 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
8902 long int detail
, long int data1
, long int data2
)
8906 event
.xclient
.type
= ClientMessage
;
8907 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
8908 event
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_XEMBED
;
8909 event
.xclient
.format
= 32;
8910 event
.xclient
.data
.l
[0] = t
;
8911 event
.xclient
.data
.l
[1] = msg
;
8912 event
.xclient
.data
.l
[2] = detail
;
8913 event
.xclient
.data
.l
[3] = data1
;
8914 event
.xclient
.data
.l
[4] = data2
;
8916 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
8917 False
, NoEventMask
, &event
);
8918 XSync (FRAME_X_DISPLAY (f
), False
);
8921 /* Change of visibility. */
8923 /* This tries to wait until the frame is really visible.
8924 However, if the window manager asks the user where to position
8925 the frame, this will return before the user finishes doing that.
8926 The frame will not actually be visible at that time,
8927 but it will become visible later when the window manager
8928 finishes with it. */
8931 x_make_frame_visible (struct frame
*f
)
8933 int original_top
, original_left
;
8934 int retry_count
= 2;
8940 x_set_bitmap_icon (f
);
8942 if (! FRAME_VISIBLE_P (f
))
8944 /* We test FRAME_GARBAGED_P here to make sure we don't
8945 call x_set_offset a second time
8946 if we get to x_make_frame_visible a second time
8947 before the window gets really visible. */
8948 if (! FRAME_ICONIFIED_P (f
)
8949 && ! FRAME_X_EMBEDDED_P (f
)
8950 && ! f
->output_data
.x
->asked_for_visible
)
8951 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8953 f
->output_data
.x
->asked_for_visible
= 1;
8955 if (! EQ (Vx_no_window_manager
, Qt
))
8956 x_wm_set_window_state (f
, NormalState
);
8957 #ifdef USE_X_TOOLKIT
8958 if (FRAME_X_EMBEDDED_P (f
))
8959 xembed_set_info (f
, XEMBED_MAPPED
);
8962 /* This was XtPopup, but that did nothing for an iconified frame. */
8963 XtMapWidget (f
->output_data
.x
->widget
);
8965 #else /* not USE_X_TOOLKIT */
8967 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8968 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8970 if (FRAME_X_EMBEDDED_P (f
))
8971 xembed_set_info (f
, XEMBED_MAPPED
);
8973 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8974 #endif /* not USE_GTK */
8975 #endif /* not USE_X_TOOLKIT */
8978 XFlush (FRAME_X_DISPLAY (f
));
8980 /* Synchronize to ensure Emacs knows the frame is visible
8981 before we do anything else. We do this loop with input not blocked
8982 so that incoming events are handled. */
8986 /* This must be before UNBLOCK_INPUT
8987 since events that arrive in response to the actions above
8988 will set it when they are handled. */
8989 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8991 original_left
= f
->left_pos
;
8992 original_top
= f
->top_pos
;
8994 /* This must come after we set COUNT. */
8997 /* We unblock here so that arriving X events are processed. */
8999 /* Now move the window back to where it was "supposed to be".
9000 But don't do it if the gravity is negative.
9001 When the gravity is negative, this uses a position
9002 that is 3 pixels too low. Perhaps that's really the border width.
9004 Don't do this if the window has never been visible before,
9005 because the window manager may choose the position
9006 and we don't want to override it. */
9008 if (! FRAME_VISIBLE_P (f
)
9009 && ! FRAME_ICONIFIED_P (f
)
9010 && ! FRAME_X_EMBEDDED_P (f
)
9011 && f
->win_gravity
== NorthWestGravity
9012 && previously_visible
)
9016 unsigned int width
, height
, border
, depth
;
9020 /* On some window managers (such as FVWM) moving an existing
9021 window, even to the same place, causes the window manager
9022 to introduce an offset. This can cause the window to move
9023 to an unexpected location. Check the geometry (a little
9024 slow here) and then verify that the window is in the right
9025 place. If the window is not in the right place, move it
9026 there, and take the potential window manager hit. */
9027 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9028 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9030 if (original_left
!= x
|| original_top
!= y
)
9031 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9032 original_left
, original_top
);
9037 XSETFRAME (frame
, f
);
9039 /* Wait until the frame is visible. Process X events until a
9040 MapNotify event has been seen, or until we think we won't get a
9041 MapNotify at all.. */
9042 for (count
= input_signal_count
+ 10;
9043 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9045 /* Force processing of queued events. */
9048 /* Machines that do polling rather than SIGIO have been
9049 observed to go into a busy-wait here. So we'll fake an
9050 alarm signal to let the handler know that there's something
9051 to be read. We used to raise a real alarm, but it seems
9052 that the handler isn't always enabled here. This is
9054 if (input_polling_used ())
9056 /* It could be confusing if a real alarm arrives while
9057 processing the fake one. Turn it off and let the
9058 handler reset it. */
9059 int old_poll_suppress_count
= poll_suppress_count
;
9060 poll_suppress_count
= 1;
9061 poll_for_input_1 ();
9062 poll_suppress_count
= old_poll_suppress_count
;
9068 (let ((f (selected-frame)))
9072 the frame is not raised with various window managers on
9073 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9074 unknown reason, the call to XtMapWidget is completely ignored.
9075 Mapping the widget a second time works. */
9077 if (!FRAME_VISIBLE_P (f
) && --retry_count
!= 0)
9082 /* Change from mapped state to withdrawn state. */
9084 /* Make the frame visible (mapped and not iconified). */
9087 x_make_frame_invisible (struct frame
*f
)
9091 /* Use the frame's outermost window, not the one we normally draw on. */
9092 window
= FRAME_OUTER_WINDOW (f
);
9094 /* Don't keep the highlight on an invisible frame. */
9095 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9096 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9100 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9101 that the current position of the window is user-specified, rather than
9102 program-specified, so that when the window is mapped again, it will be
9103 placed at the same location, without forcing the user to position it
9104 by hand again (they have already done that once for this window.) */
9105 x_wm_set_size_hint (f
, (long) 0, 1);
9108 if (FRAME_GTK_OUTER_WIDGET (f
))
9109 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9112 if (FRAME_X_EMBEDDED_P (f
))
9113 xembed_set_info (f
, 0);
9118 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9119 DefaultScreen (FRAME_X_DISPLAY (f
))))
9122 error ("Can't notify window manager of window withdrawal");
9126 /* We can't distinguish this from iconification
9127 just by the event that we get from the server.
9128 So we can't win using the usual strategy of letting
9129 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9130 and synchronize with the server to make sure we agree. */
9131 SET_FRAME_VISIBLE (f
, 0);
9132 SET_FRAME_ICONIFIED (f
, 0);
9139 /* Change window state from mapped to iconified. */
9142 x_iconify_frame (struct frame
*f
)
9144 #ifdef USE_X_TOOLKIT
9148 /* Don't keep the highlight on an invisible frame. */
9149 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9150 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9152 if (FRAME_ICONIFIED_P (f
))
9157 x_set_bitmap_icon (f
);
9159 #if defined (USE_GTK)
9160 if (FRAME_GTK_OUTER_WIDGET (f
))
9162 if (! FRAME_VISIBLE_P (f
))
9163 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9165 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9166 SET_FRAME_VISIBLE (f
, 0);
9167 SET_FRAME_ICONIFIED (f
, 1);
9173 #ifdef USE_X_TOOLKIT
9175 if (! FRAME_VISIBLE_P (f
))
9177 if (! EQ (Vx_no_window_manager
, Qt
))
9178 x_wm_set_window_state (f
, IconicState
);
9179 /* This was XtPopup, but that did nothing for an iconified frame. */
9180 XtMapWidget (f
->output_data
.x
->widget
);
9181 /* The server won't give us any event to indicate
9182 that an invisible frame was changed to an icon,
9183 so we have to record it here. */
9184 SET_FRAME_VISIBLE (f
, 0);
9185 SET_FRAME_ICONIFIED (f
, 1);
9190 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9191 XtWindow (f
->output_data
.x
->widget
),
9192 DefaultScreen (FRAME_X_DISPLAY (f
)));
9196 error ("Can't notify window manager of iconification");
9198 SET_FRAME_ICONIFIED (f
, 1);
9199 SET_FRAME_VISIBLE (f
, 0);
9202 XFlush (FRAME_X_DISPLAY (f
));
9204 #else /* not USE_X_TOOLKIT */
9206 /* Make sure the X server knows where the window should be positioned,
9207 in case the user deiconifies with the window manager. */
9208 if (! FRAME_VISIBLE_P (f
)
9209 && ! FRAME_ICONIFIED_P (f
)
9210 && ! FRAME_X_EMBEDDED_P (f
))
9211 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9213 /* Since we don't know which revision of X we're running, we'll use both
9214 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9216 /* X11R4: send a ClientMessage to the window manager using the
9217 WM_CHANGE_STATE type. */
9221 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
9222 msg
.xclient
.type
= ClientMessage
;
9223 msg
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9224 msg
.xclient
.format
= 32;
9225 msg
.xclient
.data
.l
[0] = IconicState
;
9227 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9228 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9230 SubstructureRedirectMask
| SubstructureNotifyMask
,
9234 error ("Can't notify window manager of iconification");
9238 /* X11R3: set the initial_state field of the window manager hints to
9240 x_wm_set_window_state (f
, IconicState
);
9242 if (!FRAME_VISIBLE_P (f
))
9244 /* If the frame was withdrawn, before, we must map it. */
9245 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9248 SET_FRAME_ICONIFIED (f
, 1);
9249 SET_FRAME_VISIBLE (f
, 0);
9251 XFlush (FRAME_X_DISPLAY (f
));
9253 #endif /* not USE_X_TOOLKIT */
9257 /* Free X resources of frame F. */
9260 x_free_frame_resources (struct frame
*f
)
9262 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9263 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
9264 #ifdef USE_X_TOOLKIT
9266 struct scroll_bar
*b
;
9271 /* If a display connection is dead, don't try sending more
9272 commands to the X server. */
9273 if (dpyinfo
->display
)
9275 /* We must free faces before destroying windows because some
9276 font-driver (e.g. xft) access a window while finishing a
9278 if (FRAME_FACE_CACHE (f
))
9279 free_frame_faces (f
);
9281 if (f
->output_data
.x
->icon_desc
)
9282 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9284 #ifdef USE_X_TOOLKIT
9285 /* Explicitly destroy the scroll bars of the frame. Without
9286 this, we get "BadDrawable" errors from the toolkit later on,
9287 presumably from expose events generated for the disappearing
9288 toolkit scroll bars. */
9289 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9291 b
= XSCROLL_BAR (bar
);
9292 x_scroll_bar_remove (b
);
9301 #ifdef USE_X_TOOLKIT
9302 if (f
->output_data
.x
->widget
)
9304 XtDestroyWidget (f
->output_data
.x
->widget
);
9305 f
->output_data
.x
->widget
= NULL
;
9307 /* Tooltips don't have widgets, only a simple X window, even if
9308 we are using a toolkit. */
9309 else if (FRAME_X_WINDOW (f
))
9310 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9312 free_frame_menubar (f
);
9313 #else /* !USE_X_TOOLKIT */
9316 xg_free_frame_widgets (f
);
9317 #endif /* USE_GTK */
9319 if (FRAME_X_WINDOW (f
))
9320 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9321 #endif /* !USE_X_TOOLKIT */
9323 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9324 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9325 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9326 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9327 unload_color (f
, f
->output_data
.x
->border_pixel
);
9328 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9330 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9331 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9332 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9333 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9334 #ifdef USE_TOOLKIT_SCROLL_BARS
9335 /* Scrollbar shadow colors. */
9336 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9337 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9338 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9339 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9340 #endif /* USE_TOOLKIT_SCROLL_BARS */
9341 if (f
->output_data
.x
->white_relief
.allocated_p
)
9342 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9343 if (f
->output_data
.x
->black_relief
.allocated_p
)
9344 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9348 /* Free extra GCs allocated by x_setup_relief_colors. */
9349 if (f
->output_data
.x
->white_relief
.gc
)
9351 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
9352 f
->output_data
.x
->white_relief
.gc
= 0;
9354 if (f
->output_data
.x
->black_relief
.gc
)
9356 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
9357 f
->output_data
.x
->black_relief
.gc
= 0;
9360 XFlush (FRAME_X_DISPLAY (f
));
9363 xfree (f
->output_data
.x
->saved_menu_event
);
9364 xfree (f
->output_data
.x
);
9365 f
->output_data
.x
= NULL
;
9367 if (f
== dpyinfo
->x_focus_frame
)
9368 dpyinfo
->x_focus_frame
= 0;
9369 if (f
== dpyinfo
->x_focus_event_frame
)
9370 dpyinfo
->x_focus_event_frame
= 0;
9371 if (f
== dpyinfo
->x_highlight_frame
)
9372 dpyinfo
->x_highlight_frame
= 0;
9373 if (f
== hlinfo
->mouse_face_mouse_frame
)
9374 reset_mouse_highlight (hlinfo
);
9380 /* Destroy the X window of frame F. */
9383 x_destroy_window (struct frame
*f
)
9385 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9387 /* If a display connection is dead, don't try sending more
9388 commands to the X server. */
9389 if (dpyinfo
->display
!= 0)
9390 x_free_frame_resources (f
);
9392 dpyinfo
->reference_count
--;
9396 /* Setting window manager hints. */
9398 /* Set the normal size hints for the window manager, for frame F.
9399 FLAGS is the flags word to use--or 0 meaning preserve the flags
9400 that the window now has.
9401 If USER_POSITION, set the USPosition
9402 flag (this is useful when FLAGS is 0).
9403 The GTK version is in gtkutils.c. */
9407 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
9409 XSizeHints size_hints
;
9410 Window window
= FRAME_OUTER_WINDOW (f
);
9412 #ifdef USE_X_TOOLKIT
9413 if (f
->output_data
.x
->widget
)
9415 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
9420 /* Setting PMaxSize caused various problems. */
9421 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9423 size_hints
.x
= f
->left_pos
;
9424 size_hints
.y
= f
->top_pos
;
9426 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9427 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9429 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9430 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9431 size_hints
.max_width
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
9432 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9433 size_hints
.max_height
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
9434 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9436 /* Calculate the base and minimum sizes. */
9438 int base_width
, base_height
;
9439 int min_rows
= 0, min_cols
= 0;
9441 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9442 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9444 check_frame_size (f
, &min_rows
, &min_cols
);
9446 /* The window manager uses the base width hints to calculate the
9447 current number of rows and columns in the frame while
9448 resizing; min_width and min_height aren't useful for this
9449 purpose, since they might not give the dimensions for a
9450 zero-row, zero-column frame.
9452 We use the base_width and base_height members if we have
9453 them; otherwise, we set the min_width and min_height members
9454 to the size for a zero x zero frame. */
9456 size_hints
.flags
|= PBaseSize
;
9457 size_hints
.base_width
= base_width
;
9458 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9459 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9460 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9463 /* If we don't need the old flags, we don't need the old hint at all. */
9466 size_hints
.flags
|= flags
;
9471 XSizeHints hints
; /* Sometimes I hate X Windows... */
9472 long supplied_return
;
9475 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9479 size_hints
.flags
|= flags
;
9484 if (hints
.flags
& PSize
)
9485 size_hints
.flags
|= PSize
;
9486 if (hints
.flags
& PPosition
)
9487 size_hints
.flags
|= PPosition
;
9488 if (hints
.flags
& USPosition
)
9489 size_hints
.flags
|= USPosition
;
9490 if (hints
.flags
& USSize
)
9491 size_hints
.flags
|= USSize
;
9498 size_hints
.win_gravity
= f
->win_gravity
;
9499 size_hints
.flags
|= PWinGravity
;
9503 size_hints
.flags
&= ~ PPosition
;
9504 size_hints
.flags
|= USPosition
;
9506 #endif /* PWinGravity */
9508 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9510 #endif /* not USE_GTK */
9512 /* Used for IconicState or NormalState */
9515 x_wm_set_window_state (struct frame
*f
, int state
)
9517 #ifdef USE_X_TOOLKIT
9520 XtSetArg (al
[0], XtNinitialState
, state
);
9521 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9522 #else /* not USE_X_TOOLKIT */
9523 Window window
= FRAME_X_WINDOW (f
);
9525 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9526 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9528 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9529 #endif /* not USE_X_TOOLKIT */
9533 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
9535 Pixmap icon_pixmap
, icon_mask
;
9537 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9538 Window window
= FRAME_OUTER_WINDOW (f
);
9543 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9544 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9545 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9546 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9550 /* It seems there is no way to turn off use of an icon
9558 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9562 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9566 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9567 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9568 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9569 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9572 #else /* not USE_X_TOOLKIT && not USE_GTK */
9574 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9575 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9577 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9581 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9583 Window window
= FRAME_OUTER_WINDOW (f
);
9585 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9586 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9587 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9589 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9593 /***********************************************************************
9595 ***********************************************************************/
9599 /* Check that FONT is valid on frame F. It is if it can be found in F's
9603 x_check_font (struct frame
*f
, struct font
*font
)
9605 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9606 if (font
->driver
->check
)
9607 eassert (font
->driver
->check (f
, font
) == 0);
9610 #endif /* GLYPH_DEBUG */
9613 /***********************************************************************
9615 ***********************************************************************/
9617 #ifdef USE_X_TOOLKIT
9618 static XrmOptionDescRec emacs_options
[] = {
9619 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9620 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9622 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9623 XrmoptionSepArg
, NULL
},
9624 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9626 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9627 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9628 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9629 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9630 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9631 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9632 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9635 /* Whether atimer for Xt timeouts is activated or not. */
9637 static int x_timeout_atimer_activated_flag
;
9639 #endif /* USE_X_TOOLKIT */
9641 static int x_initialized
;
9643 /* Test whether two display-name strings agree up to the dot that separates
9644 the screen number from the server number. */
9646 same_x_server (const char *name1
, const char *name2
)
9649 const char *system_name
= SSDATA (Vsystem_name
);
9650 ptrdiff_t system_name_length
= SBYTES (Vsystem_name
);
9651 ptrdiff_t length_until_period
= 0;
9653 while (system_name
[length_until_period
] != 0
9654 && system_name
[length_until_period
] != '.')
9655 length_until_period
++;
9657 /* Treat `unix' like an empty host name. */
9658 if (! strncmp (name1
, "unix:", 5))
9660 if (! strncmp (name2
, "unix:", 5))
9662 /* Treat this host's name like an empty host name. */
9663 if (! strncmp (name1
, system_name
, system_name_length
)
9664 && name1
[system_name_length
] == ':')
9665 name1
+= system_name_length
;
9666 if (! strncmp (name2
, system_name
, system_name_length
)
9667 && name2
[system_name_length
] == ':')
9668 name2
+= system_name_length
;
9669 /* Treat this host's domainless name like an empty host name. */
9670 if (! strncmp (name1
, system_name
, length_until_period
)
9671 && name1
[length_until_period
] == ':')
9672 name1
+= length_until_period
;
9673 if (! strncmp (name2
, system_name
, length_until_period
)
9674 && name2
[length_until_period
] == ':')
9675 name2
+= length_until_period
;
9677 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9681 if (seen_colon
&& *name1
== '.')
9685 && (*name1
== '.' || *name1
== '\0')
9686 && (*name2
== '.' || *name2
== '\0'));
9689 /* Count number of set bits in mask and number of bits to shift to
9690 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9693 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9714 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9715 But don't permanently open it, just test its availability. */
9718 x_display_ok (const char *display
)
9720 Display
*dpy
= XOpenDisplay (display
);
9721 return dpy
? (XCloseDisplay (dpy
), 1) : 0;
9726 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
9727 const gchar
*msg
, gpointer user_data
)
9729 if (!strstr (msg
, "g_set_prgname"))
9730 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
9734 /* Open a connection to X display DISPLAY_NAME, and return
9735 the structure that describes the open display.
9736 If we cannot contact the display, return null. */
9738 struct x_display_info
*
9739 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9743 struct terminal
*terminal
;
9744 struct x_display_info
*dpyinfo
;
9756 if (! x_display_ok (SSDATA (display_name
)))
9757 error ("Display %s can't be opened", SSDATA (display_name
));
9763 char *argv
[NUM_ARGV
];
9764 char **argv2
= argv
;
9767 if (x_initialized
++ > 1)
9769 xg_display_open (SSDATA (display_name
), &dpy
);
9773 static char display_opt
[] = "--display";
9774 static char name_opt
[] = "--name";
9776 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9780 argv
[argc
++] = initial_argv
[0];
9782 if (! NILP (display_name
))
9784 argv
[argc
++] = display_opt
;
9785 argv
[argc
++] = SSDATA (display_name
);
9788 argv
[argc
++] = name_opt
;
9789 argv
[argc
++] = resource_name
;
9791 XSetLocaleModifiers ("");
9793 /* Emacs can only handle core input events, so make sure
9794 Gtk doesn't use Xinput or Xinput2 extensions. */
9795 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
9797 /* Work around GLib bug that outputs a faulty warning. See
9798 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9799 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9800 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9802 /* NULL window -> events for all windows go to our function.
9803 Call before gtk_init so Gtk+ event filters comes after our. */
9804 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9806 /* gtk_init does set_locale. Fix locale before and after. */
9808 gtk_init (&argc
, &argv2
);
9811 g_log_remove_handler ("GLib", id
);
9815 dpy
= DEFAULT_GDK_DISPLAY ();
9817 #if ! GTK_CHECK_VERSION (2, 90, 0)
9818 /* Load our own gtkrc if it exists. */
9820 const char *file
= "~/.emacs.d/gtkrc";
9821 Lisp_Object s
, abs_file
;
9823 s
= build_string (file
);
9824 abs_file
= Fexpand_file_name (s
, Qnil
);
9826 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
9827 gtk_rc_parse (SSDATA (abs_file
));
9831 XSetErrorHandler (x_error_handler
);
9832 XSetIOErrorHandler (x_io_error_quitter
);
9835 #else /* not USE_GTK */
9836 #ifdef USE_X_TOOLKIT
9837 /* weiner@footloose.sps.mot.com reports that this causes
9839 X protocol error: BadAtom (invalid Atom parameter)
9840 on protocol request 18skiloaf.
9841 So let's not use it until R6. */
9843 XtSetLanguageProc (NULL
, NULL
, NULL
);
9854 argv
[argc
++] = "-xrm";
9855 argv
[argc
++] = xrm_option
;
9857 turn_on_atimers (0);
9858 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
9859 resource_name
, EMACS_CLASS
,
9860 emacs_options
, XtNumber (emacs_options
),
9862 turn_on_atimers (1);
9865 /* I think this is to compensate for XtSetLanguageProc. */
9870 #else /* not USE_X_TOOLKIT */
9871 XSetLocaleModifiers ("");
9872 dpy
= XOpenDisplay (SSDATA (display_name
));
9873 #endif /* not USE_X_TOOLKIT */
9874 #endif /* not USE_GTK*/
9876 /* Detect failure. */
9883 /* We have definitely succeeded. Record the new connection. */
9885 dpyinfo
= xzalloc (sizeof *dpyinfo
);
9886 terminal
= x_create_terminal (dpyinfo
);
9889 struct x_display_info
*share
;
9891 for (share
= x_display_list
; share
; share
= share
->next
)
9892 if (same_x_server (SSDATA (XCAR (share
->name_list_element
)),
9893 SSDATA (display_name
)))
9896 terminal
->kboard
= share
->terminal
->kboard
;
9899 terminal
->kboard
= allocate_kboard (Qx
);
9901 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
9903 char *vendor
= ServerVendor (dpy
);
9905 /* Protect terminal from GC before removing it from the
9906 list of terminals. */
9907 struct gcpro gcpro1
;
9908 Lisp_Object gcpro_term
;
9909 XSETTERMINAL (gcpro_term
, terminal
);
9910 GCPRO1 (gcpro_term
);
9912 /* Temporarily hide the partially initialized terminal. */
9913 terminal_list
= terminal
->next_terminal
;
9915 kset_system_key_alist
9917 call1 (Qvendor_specific_keysyms
,
9918 vendor
? build_string (vendor
) : empty_unibyte_string
));
9920 terminal
->next_terminal
= terminal_list
;
9921 terminal_list
= terminal
;
9925 /* Don't let the initial kboard remain current longer than necessary.
9926 That would cause problems if a file loaded on startup tries to
9927 prompt in the mini-buffer. */
9928 if (current_kboard
== initial_kboard
)
9929 current_kboard
= terminal
->kboard
;
9931 terminal
->kboard
->reference_count
++;
9934 /* Put this display on the chain. */
9935 dpyinfo
->next
= x_display_list
;
9936 x_display_list
= dpyinfo
;
9938 dpyinfo
->name_list_element
= Fcons (display_name
, Qnil
);
9939 dpyinfo
->display
= dpy
;
9941 /* Set the name of the terminal. */
9942 terminal
->name
= xlispstrdup (display_name
);
9945 XSetAfterFunction (x_current_display
, x_trace_wire
);
9948 lim
= min (PTRDIFF_MAX
, SIZE_MAX
) - sizeof "@";
9949 if (lim
- SBYTES (Vinvocation_name
) < SBYTES (Vsystem_name
))
9950 memory_full (SIZE_MAX
);
9951 dpyinfo
->x_id_name
= xmalloc (SBYTES (Vinvocation_name
)
9952 + SBYTES (Vsystem_name
) + 2);
9953 strcat (strcat (strcpy (dpyinfo
->x_id_name
, SSDATA (Vinvocation_name
)), "@"),
9954 SSDATA (Vsystem_name
));
9956 /* Figure out which modifier bits mean what. */
9957 x_find_modifier_meanings (dpyinfo
);
9959 /* Get the scroll bar cursor. */
9961 /* We must create a GTK cursor, it is required for GTK widgets. */
9962 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
9963 #endif /* USE_GTK */
9965 dpyinfo
->vertical_scroll_bar_cursor
9966 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
9968 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
9969 resource_name
, EMACS_CLASS
);
9970 #ifdef HAVE_XRMSETDATABASE
9971 XrmSetDatabase (dpyinfo
->display
, xrdb
);
9973 dpyinfo
->display
->db
= xrdb
;
9975 /* Put the rdb where we can find it in a way that works on
9977 dpyinfo
->xrdb
= xrdb
;
9979 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
9980 DefaultScreen (dpyinfo
->display
));
9981 select_visual (dpyinfo
);
9982 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
9983 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
9984 dpyinfo
->icon_bitmap_id
= -1;
9985 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
9987 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
9989 /* See if we can construct pixel values from RGB values. */
9990 if (dpyinfo
->visual
->class == TrueColor
)
9992 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
9993 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
9994 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
9995 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
9996 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
9997 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10000 /* See if a private colormap is requested. */
10001 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10003 if (dpyinfo
->visual
->class == PseudoColor
)
10006 value
= display_x_get_resource (dpyinfo
,
10007 build_string ("privateColormap"),
10008 build_string ("PrivateColormap"),
10010 if (STRINGP (value
)
10011 && (!strcmp (SSDATA (value
), "true")
10012 || !strcmp (SSDATA (value
), "on")))
10013 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10017 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10018 dpyinfo
->visual
, AllocNone
);
10022 /* If we are using Xft, check dpi value in X resources.
10023 It is better we use it as well, since Xft will use it, as will all
10024 Gnome applications. If our real DPI is smaller or larger than the
10025 one Xft uses, our font will look smaller or larger than other
10026 for other applications, even if it is the same font name (monospace-10
10028 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10030 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10031 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10035 if (dpyinfo
->resy
< 1)
10037 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10038 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10039 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10040 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10041 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10042 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10043 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10044 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10045 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10049 static const struct
10054 #define ATOM_REFS_INIT(string, member) \
10055 { string, offsetof (struct x_display_info, member) },
10056 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
10057 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
10058 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
10059 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
10060 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
10061 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
10062 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
10063 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
10064 ATOM_REFS_INIT ("Editres", Xatom_editres
)
10065 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
10066 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
10067 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
10068 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
10069 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
10070 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
10071 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
10072 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
10073 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
10074 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
10075 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
10076 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
10077 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
10078 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
10079 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
10080 /* For properties of font. */
10081 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
10082 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
10083 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
10084 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
10085 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
10086 /* Ghostscript support. */
10087 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
10088 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
10089 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
10090 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
10092 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
10093 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
10094 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
10095 Xatom_net_wm_state_maximized_horz
)
10096 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
10097 Xatom_net_wm_state_maximized_vert
)
10098 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
10099 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
10100 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
10101 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
10102 Xatom_net_window_type_tooltip
)
10103 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
10104 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
10105 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
10106 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
10107 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
10108 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
10109 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
10110 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
10111 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
10112 /* Session management */
10113 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
10114 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
10115 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
10119 const int atom_count
= sizeof (atom_refs
) / sizeof (atom_refs
[0]);
10120 /* 1 for _XSETTINGS_SN */
10121 const int total_atom_count
= 1 + atom_count
;
10122 Atom
*atoms_return
= xmalloc (total_atom_count
* sizeof *atoms_return
);
10123 char **atom_names
= xmalloc (total_atom_count
* sizeof *atom_names
);
10124 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
10125 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
10126 + INT_STRLEN_BOUND (int)];
10128 for (i
= 0; i
< atom_count
; i
++)
10129 atom_names
[i
] = (char *) atom_refs
[i
].name
;
10131 /* Build _XSETTINGS_SN atom name */
10132 sprintf (xsettings_atom_name
, xsettings_fmt
,
10133 XScreenNumberOfScreen (dpyinfo
->screen
));
10134 atom_names
[i
] = xsettings_atom_name
;
10136 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
10137 False
, atoms_return
);
10139 for (i
= 0; i
< atom_count
; i
++)
10140 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
10142 /* Manual copy of last atom */
10143 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
10145 xfree (atom_names
);
10146 xfree (atoms_return
);
10149 dpyinfo
->x_dnd_atoms_size
= 8;
10150 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
10151 * dpyinfo
->x_dnd_atoms_size
);
10153 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10154 gray_bits
, gray_width
, gray_height
,
10158 xim_initialize (dpyinfo
, resource_name
);
10161 xsettings_initialize (dpyinfo
);
10163 connection
= ConnectionNumber (dpyinfo
->display
);
10165 /* This is only needed for distinguishing keyboard and process input. */
10166 if (connection
!= 0)
10167 add_keyboard_wait_descriptor (connection
);
10170 fcntl (connection
, F_SETOWN
, getpid ());
10171 #endif /* ! defined (F_SETOWN) */
10173 if (interrupt_input
)
10174 init_sigio (connection
);
10178 XrmValue d
, fr
, to
;
10181 dpy
= dpyinfo
->display
;
10182 d
.addr
= (XPointer
)&dpy
;
10183 d
.size
= sizeof (Display
*);
10184 fr
.addr
= XtDefaultFont
;
10185 fr
.size
= sizeof (XtDefaultFont
);
10186 to
.size
= sizeof (Font
*);
10187 to
.addr
= (XPointer
)&font
;
10188 x_catch_errors (dpy
);
10189 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10191 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10192 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10193 x_uncatch_errors ();
10197 /* See if we should run in synchronous mode. This is useful
10198 for debugging X code. */
10201 value
= display_x_get_resource (dpyinfo
,
10202 build_string ("synchronous"),
10203 build_string ("Synchronous"),
10205 if (STRINGP (value
)
10206 && (!strcmp (SSDATA (value
), "true")
10207 || !strcmp (SSDATA (value
), "on")))
10208 XSynchronize (dpyinfo
->display
, True
);
10213 value
= display_x_get_resource (dpyinfo
,
10214 build_string ("useXIM"),
10215 build_string ("UseXIM"),
10218 if (STRINGP (value
)
10219 && (!strcmp (SSDATA (value
), "false")
10220 || !strcmp (SSDATA (value
), "off")))
10223 if (STRINGP (value
)
10224 && (!strcmp (SSDATA (value
), "true")
10225 || !strcmp (SSDATA (value
), "on")))
10231 /* Only do this for the very first display in the Emacs session.
10232 Ignore X session management when Emacs was first started on a
10234 if (terminal
->id
== 1)
10235 x_session_initialize (dpyinfo
);
10243 /* Get rid of display DPYINFO, deleting all frames on it,
10244 and without sending any more commands to the X server. */
10247 x_delete_display (struct x_display_info
*dpyinfo
)
10249 struct terminal
*t
;
10251 /* Close all frames and delete the generic struct terminal for this
10253 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10254 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10257 /* Close X session management when we close its display. */
10258 if (t
->id
== 1 && x_session_have_connection ())
10259 x_session_close ();
10261 delete_terminal (t
);
10265 if (next_noop_dpyinfo
== dpyinfo
)
10266 next_noop_dpyinfo
= dpyinfo
->next
;
10268 if (x_display_list
== dpyinfo
)
10269 x_display_list
= dpyinfo
->next
;
10272 struct x_display_info
*tail
;
10274 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10275 if (tail
->next
== dpyinfo
)
10276 tail
->next
= tail
->next
->next
;
10279 xfree (dpyinfo
->x_id_name
);
10280 xfree (dpyinfo
->x_dnd_atoms
);
10281 xfree (dpyinfo
->color_cells
);
10285 #ifdef USE_X_TOOLKIT
10287 /* Atimer callback function for TIMER. Called every 0.1s to process
10288 Xt timeouts, if needed. We must avoid calling XtAppPending as
10289 much as possible because that function does an implicit XFlush
10290 that slows us down. */
10293 x_process_timeouts (struct atimer
*timer
)
10296 x_timeout_atimer_activated_flag
= 0;
10297 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10299 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10300 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10301 /* Reactivate the atimer for next time. */
10302 x_activate_timeout_atimer ();
10307 /* Install an asynchronous timer that processes Xt timeout events
10308 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10309 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10310 function whenever these variables are set. This is necessary
10311 because some widget sets use timeouts internally, for example the
10312 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10313 processed, these widgets don't behave normally. */
10316 x_activate_timeout_atimer (void)
10319 if (!x_timeout_atimer_activated_flag
)
10321 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
10322 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10323 x_timeout_atimer_activated_flag
= 1;
10328 #endif /* USE_X_TOOLKIT */
10331 /* Set up use of X before we make the first connection. */
10333 static struct redisplay_interface x_redisplay_interface
=
10335 x_frame_parm_handlers
,
10339 x_clear_end_of_line
,
10341 x_after_update_window_line
,
10342 x_update_window_begin
,
10343 x_update_window_end
,
10345 x_clear_window_mouse_face
,
10346 x_get_glyph_overhangs
,
10347 x_fix_overlapping_area
,
10348 x_draw_fringe_bitmap
,
10349 0, /* define_fringe_bitmap */
10350 0, /* destroy_fringe_bitmap */
10351 x_compute_glyph_string_overhangs
,
10352 x_draw_glyph_string
,
10353 x_define_frame_cursor
,
10354 x_clear_frame_area
,
10355 x_draw_window_cursor
,
10356 x_draw_vertical_window_border
,
10357 x_shift_glyphs_for_insert
10361 /* This function is called when the last frame on a display is deleted. */
10363 x_delete_terminal (struct terminal
*terminal
)
10365 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10366 int connection
= -1;
10368 /* Protect against recursive calls. delete_frame in
10369 delete_terminal calls us back when it deletes our last frame. */
10370 if (!terminal
->name
)
10375 /* We must close our connection to the XIM server before closing the
10378 xim_close_dpy (dpyinfo
);
10381 /* If called from x_connection_closed, the display may already be closed
10382 and dpyinfo->display was set to 0 to indicate that. */
10383 if (dpyinfo
->display
)
10385 connection
= ConnectionNumber (dpyinfo
->display
);
10387 x_destroy_all_bitmaps (dpyinfo
);
10388 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10390 /* Whether or not XCloseDisplay destroys the associated resource
10391 database depends on the version of libX11. To avoid both
10392 crash and memory leak, we dissociate the database from the
10393 display and then destroy dpyinfo->xrdb ourselves.
10395 Unfortunately, the above strategy does not work in some
10396 situations due to a bug in newer versions of libX11: because
10397 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10398 dpy->db is NULL, XCloseDisplay destroys the associated
10399 database whereas it has not been created by XGetDefault
10400 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10401 don't destroy the database here in order to avoid the crash
10402 in the above situations for now, though that may cause memory
10403 leaks in other situations. */
10405 #ifdef HAVE_XRMSETDATABASE
10406 XrmSetDatabase (dpyinfo
->display
, NULL
);
10408 dpyinfo
->display
->db
= NULL
;
10410 /* We used to call XrmDestroyDatabase from x_delete_display, but
10411 some older versions of libX11 crash if we call it after
10412 closing all the displays. */
10413 XrmDestroyDatabase (dpyinfo
->xrdb
);
10417 xg_display_close (dpyinfo
->display
);
10419 #ifdef USE_X_TOOLKIT
10420 XtCloseDisplay (dpyinfo
->display
);
10422 XCloseDisplay (dpyinfo
->display
);
10424 #endif /* ! USE_GTK */
10427 /* No more input on this descriptor. */
10428 if (connection
!= -1)
10429 delete_keyboard_wait_descriptor (connection
);
10431 /* Mark as dead. */
10432 dpyinfo
->display
= NULL
;
10433 x_delete_display (dpyinfo
);
10437 /* Create a struct terminal, initialize it with the X11 specific
10438 functions and make DISPLAY->TERMINAL point to it. */
10440 static struct terminal
*
10441 x_create_terminal (struct x_display_info
*dpyinfo
)
10443 struct terminal
*terminal
;
10445 terminal
= create_terminal ();
10447 terminal
->type
= output_x_window
;
10448 terminal
->display_info
.x
= dpyinfo
;
10449 dpyinfo
->terminal
= terminal
;
10451 /* kboard is initialized in x_term_init. */
10453 terminal
->clear_frame_hook
= x_clear_frame
;
10454 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10455 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10456 terminal
->ring_bell_hook
= XTring_bell
;
10457 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10458 terminal
->reset_terminal_modes_hook
= NULL
;
10459 terminal
->set_terminal_modes_hook
= NULL
;
10460 terminal
->update_begin_hook
= x_update_begin
;
10461 terminal
->update_end_hook
= x_update_end
;
10462 terminal
->set_terminal_window_hook
= NULL
;
10463 terminal
->read_socket_hook
= XTread_socket
;
10464 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10465 terminal
->mouse_position_hook
= XTmouse_position
;
10466 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10467 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10468 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10469 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10470 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10471 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10472 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10474 terminal
->delete_frame_hook
= x_destroy_window
;
10475 terminal
->delete_terminal_hook
= x_delete_terminal
;
10477 terminal
->rif
= &x_redisplay_interface
;
10483 x_initialize (void)
10488 last_tool_bar_item
= -1;
10489 any_help_event_p
= 0;
10490 ignore_next_mouse_click_timeout
= 0;
10493 current_count
= -1;
10496 /* Try to use interrupt input; if we can't, then start polling. */
10497 Fset_input_interrupt_mode (Qt
);
10499 #ifdef USE_X_TOOLKIT
10500 XtToolkitInitialize ();
10502 Xt_app_con
= XtCreateApplicationContext ();
10504 /* Register a converter from strings to pixels, which uses
10505 Emacs' color allocation infrastructure. */
10506 XtAppSetTypeConverter (Xt_app_con
,
10507 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10508 cvt_string_to_pixel_args
,
10509 XtNumber (cvt_string_to_pixel_args
),
10510 XtCacheByDisplay
, cvt_pixel_dtor
);
10512 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10515 #ifdef USE_TOOLKIT_SCROLL_BARS
10517 xaw3d_arrow_scroll
= False
;
10518 xaw3d_pick_top
= True
;
10522 /* Note that there is no real way portable across R3/R4 to get the
10523 original error handler. */
10524 XSetErrorHandler (x_error_handler
);
10525 XSetIOErrorHandler (x_io_error_quitter
);
10530 syms_of_xterm (void)
10532 x_error_message
= NULL
;
10534 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
10535 DEFSYM (Qlatin_1
, "latin-1");
10538 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10539 staticpro (&xg_default_icon_file
);
10541 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
10544 DEFVAR_BOOL ("x-use-underline-position-properties",
10545 x_use_underline_position_properties
,
10546 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
10547 A value of nil means ignore them. If you encounter fonts with bogus
10548 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10549 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10550 to override the font's UNDERLINE_POSITION for small font display
10552 x_use_underline_position_properties
= 1;
10554 DEFVAR_BOOL ("x-underline-at-descent-line",
10555 x_underline_at_descent_line
,
10556 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
10557 A value of nil means to draw the underline according to the value of the
10558 variable `x-use-underline-position-properties', which is usually at the
10559 baseline level. The default value is nil. */);
10560 x_underline_at_descent_line
= 0;
10562 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10563 x_mouse_click_focus_ignore_position
,
10564 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10565 This variable is only used when the window manager requires that you
10566 click on a frame to select it (give it focus). In that case, a value
10567 of nil, means that the selected window and cursor position changes to
10568 reflect the mouse click position, while a non-nil value means that the
10569 selected window or cursor position is preserved. */);
10570 x_mouse_click_focus_ignore_position
= 0;
10572 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
10573 doc
: /* Which toolkit scroll bars Emacs uses, if any.
10574 A value of nil means Emacs doesn't use toolkit scroll bars.
10575 With the X Window system, the value is a symbol describing the
10576 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
10577 With MS Windows or Nextstep, the value is t. */);
10578 #ifdef USE_TOOLKIT_SCROLL_BARS
10580 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10581 #elif defined HAVE_XAW3D
10582 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10584 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10586 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10589 Vx_toolkit_scroll_bars
= Qnil
;
10592 Qmodifier_value
= intern_c_string ("modifier-value");
10593 Qalt
= intern_c_string ("alt");
10594 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10595 Qhyper
= intern_c_string ("hyper");
10596 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10597 Qmeta
= intern_c_string ("meta");
10598 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10599 Qsuper
= intern_c_string ("super");
10600 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10602 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
10603 doc
: /* Which keys Emacs uses for the alt modifier.
10604 This should be one of the symbols `alt', `hyper', `meta', `super'.
10605 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10606 is nil, which is the same as `alt'. */);
10607 Vx_alt_keysym
= Qnil
;
10609 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
10610 doc
: /* Which keys Emacs uses for the hyper modifier.
10611 This should be one of the symbols `alt', `hyper', `meta', `super'.
10612 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10613 default is nil, which is the same as `hyper'. */);
10614 Vx_hyper_keysym
= Qnil
;
10616 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
10617 doc
: /* Which keys Emacs uses for the meta modifier.
10618 This should be one of the symbols `alt', `hyper', `meta', `super'.
10619 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10620 default is nil, which is the same as `meta'. */);
10621 Vx_meta_keysym
= Qnil
;
10623 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
10624 doc
: /* Which keys Emacs uses for the super modifier.
10625 This should be one of the symbols `alt', `hyper', `meta', `super'.
10626 For example, `super' means use the Super_L and Super_R keysyms. The
10627 default is nil, which is the same as `super'. */);
10628 Vx_super_keysym
= Qnil
;
10630 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
10631 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10632 Vx_keysym_table
= make_hash_table (hashtest_eql
, make_number (900),
10633 make_float (DEFAULT_REHASH_SIZE
),
10634 make_float (DEFAULT_REHASH_THRESHOLD
),