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. */
29 #include "blockinput.h"
30 #include "syssignal.h"
32 /* This may include sys/types.h, and that somehow loses
33 if this is not done before the other system files. */
35 #include <X11/cursorfont.h>
37 /* Load sys/types.h if not already loaded.
38 In some systems loading it twice is suicidal. */
40 #include <sys/types.h>
43 #include <sys/ioctl.h>
50 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
51 /* #include <sys/param.h> */
54 #include "character.h"
57 #include "dispextern.h"
59 #include "termhooks.h"
62 #include "emacs-icon.h"
67 #include "intervals.h"
72 #include "xsettings.h"
74 #include "sysselect.h"
77 #include <X11/Shell.h>
85 #include <X11/Xproto.h>
90 #include "../lwlib/xlwmenu.h"
94 #if !defined (NO_EDITRES)
96 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
97 #endif /* not NO_EDITRES */
99 /* Include toolkit specific headers for the scroll bar widget. */
101 #ifdef USE_TOOLKIT_SCROLL_BARS
102 #if defined USE_MOTIF
103 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
104 #include <Xm/ScrollBar.h>
105 #else /* !USE_MOTIF i.e. use Xaw */
108 #include <X11/Xaw3d/Simple.h>
109 #include <X11/Xaw3d/Scrollbar.h>
110 #include <X11/Xaw3d/ThreeD.h>
111 #else /* !HAVE_XAW3D */
112 #include <X11/Xaw/Simple.h>
113 #include <X11/Xaw/Scrollbar.h>
114 #endif /* !HAVE_XAW3D */
116 #define XtNpickTop "pickTop"
117 #endif /* !XtNpickTop */
118 #endif /* !USE_MOTIF */
119 #endif /* USE_TOOLKIT_SCROLL_BARS */
121 #endif /* USE_X_TOOLKIT */
125 #ifndef XtNinitialState
126 #define XtNinitialState "initialState"
130 #include "bitmaps/gray.xbm"
133 #include <X11/XKBlib.h>
136 /* Default to using XIM if available. */
140 int use_xim
= 0; /* configure --without-xim */
143 /* Non-zero means that a HELP_EVENT has been generated since Emacs
146 static bool any_help_event_p
;
148 /* This is a chain of structures for all the X displays currently in
151 struct x_display_info
*x_display_list
;
153 /* This is a list of cons cells, each of the form (NAME
154 . FONT-LIST-CACHE), one for each element of x_display_list and in
155 the same order. NAME is the name of the frame. FONT-LIST-CACHE
156 records previous values returned by x-list-fonts. */
158 Lisp_Object x_display_name_list
;
160 /* This is a frame waiting to be auto-raised, within XTread_socket. */
162 static struct frame
*pending_autoraise_frame
;
164 /* This is a frame waiting for an event matching mask, within XTread_socket. */
169 } pending_event_wait
;
172 /* The application context for Xt use. */
173 XtAppContext Xt_app_con
;
174 static String Xt_default_resources
[] = {0};
176 /* Non-zero means user is interacting with a toolkit scroll bar. */
178 static int toolkit_scroll_bar_interaction
;
179 #endif /* USE_X_TOOLKIT */
181 /* Non-zero timeout value means ignore next mouse click if it arrives
182 before that timeout elapses (i.e. as part of the same sequence of
183 events resulting from clicking on a frame to select it). */
185 static unsigned long ignore_next_mouse_click_timeout
;
189 Formerly, we used PointerMotionHintMask (in standard_event_mask)
190 so that we would have to call XQueryPointer after each MotionNotify
191 event to ask for another such event. However, this made mouse tracking
192 slow, and there was a bug that made it eventually stop.
194 Simply asking for MotionNotify all the time seems to work better.
196 In order to avoid asking for motion events and then throwing most
197 of them away or busy-polling the server for mouse positions, we ask
198 the server for pointer motion hints. This means that we get only
199 one event per group of mouse movements. "Groups" are delimited by
200 other kinds of events (focus changes and button clicks, for
201 example), or by XQueryPointer calls; when one of these happens, we
202 get another MotionNotify event the next time the mouse moves. This
203 is at least as efficient as getting motion events when mouse
204 tracking is on, and I suspect only negligibly worse when tracking
207 /* Where the mouse was last time we reported a mouse event. */
209 static XRectangle last_mouse_glyph
;
210 static struct frame
*last_mouse_glyph_frame
;
212 /* The scroll bar in which the last X motion event occurred.
214 If the last X motion event occurred in a scroll bar, we set this so
215 XTmouse_position can know whether to report a scroll bar motion or
218 If the last X motion event didn't occur in a scroll bar, we set
219 this to Qnil, to tell XTmouse_position to return an ordinary motion
222 static Lisp_Object last_mouse_scroll_bar
;
224 /* This is a hack. We would really prefer that XTmouse_position would
225 return the time associated with the position it returns, but there
226 doesn't seem to be any way to wrest the time-stamp from the server
227 along with the position query. So, we just keep track of the time
228 of the last movement we received, and return that in hopes that
229 it's somewhat accurate. */
231 static Time last_mouse_movement_time
;
233 /* Incremented by XTread_socket whenever it really tries to read
236 static int volatile input_signal_count
;
238 /* Used locally within XTread_socket. */
240 static int x_noop_count
;
242 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
244 static Lisp_Object Qvendor_specific_keysyms
;
245 static Lisp_Object Qlatin_1
;
248 /* The name of the Emacs icon file. */
249 static Lisp_Object xg_default_icon_file
;
251 /* Used in gtkutil.c. */
252 Lisp_Object Qx_gtk_map_stock
;
255 /* Some functions take this as char *, not const char *. */
256 static char emacs_class
[] = EMACS_CLASS
;
260 XEMBED_MAPPED
= 1 << 0
265 XEMBED_EMBEDDED_NOTIFY
= 0,
266 XEMBED_WINDOW_ACTIVATE
= 1,
267 XEMBED_WINDOW_DEACTIVATE
= 2,
268 XEMBED_REQUEST_FOCUS
= 3,
270 XEMBED_FOCUS_OUT
= 5,
271 XEMBED_FOCUS_NEXT
= 6,
272 XEMBED_FOCUS_PREV
= 7,
274 XEMBED_MODALITY_ON
= 10,
275 XEMBED_MODALITY_OFF
= 11,
276 XEMBED_REGISTER_ACCELERATOR
= 12,
277 XEMBED_UNREGISTER_ACCELERATOR
= 13,
278 XEMBED_ACTIVATE_ACCELERATOR
= 14
281 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
282 static void x_set_window_size_1 (struct frame
*, int, int, int);
283 static void x_raise_frame (struct frame
*);
284 static void x_lower_frame (struct frame
*);
285 static const XColor
*x_color_cells (Display
*, int *);
286 static int x_io_error_quitter (Display
*);
287 static struct terminal
*x_create_terminal (struct x_display_info
*);
288 void x_delete_terminal (struct terminal
*);
289 static void x_update_end (struct frame
*);
290 static void XTframe_up_to_date (struct frame
*);
291 static void x_clear_frame (struct frame
*);
292 static _Noreturn
void x_ins_del_lines (struct frame
*, int, int);
293 static void frame_highlight (struct frame
*);
294 static void frame_unhighlight (struct frame
*);
295 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
296 static void x_focus_changed (int, int, struct x_display_info
*,
297 struct frame
*, struct input_event
*);
298 static void x_detect_focus_change (struct x_display_info
*,
299 XEvent
*, struct input_event
*);
300 static void XTframe_rehighlight (struct frame
*);
301 static void x_frame_rehighlight (struct x_display_info
*);
302 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
303 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
304 enum text_cursor_kinds
);
306 static void x_clip_to_row (struct window
*, struct glyph_row
*,
307 enum glyph_row_area
, GC
);
308 static void x_flush (struct frame
*f
);
309 static void x_update_begin (struct frame
*);
310 static void x_update_window_begin (struct window
*);
311 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
312 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
313 enum scroll_bar_part
*,
314 Lisp_Object
*, Lisp_Object
*,
316 static int x_handle_net_wm_state (struct frame
*, XPropertyEvent
*);
317 static void x_check_fullscreen (struct frame
*);
318 static void x_check_expected_move (struct frame
*, int, int);
319 static void x_sync_with_move (struct frame
*, int, int, int);
320 static int handle_one_xevent (struct x_display_info
*, XEvent
*,
321 int *, struct input_event
*);
323 static int x_dispatch_event (XEvent
*, Display
*);
325 /* Don't declare this _Noreturn because we want no
326 interference with debugging failing X calls. */
327 static void x_connection_closed (Display
*, const char *);
328 static void x_wm_set_window_state (struct frame
*, int);
329 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
330 static void x_initialize (void);
333 /* Flush display of frame F. */
336 x_flush (struct frame
*f
)
338 eassert (f
&& FRAME_X_P (f
));
339 /* Don't call XFlush when it is not safe to redisplay; the X
340 connection may be broken. */
341 if (!NILP (Vinhibit_redisplay
))
345 XFlush (FRAME_X_DISPLAY (f
));
350 /* Remove calls to XFlush by defining XFlush to an empty replacement.
351 Calls to XFlush should be unnecessary because the X output buffer
352 is flushed automatically as needed by calls to XPending,
353 XNextEvent, or XWindowEvent according to the XFlush man page.
354 XTread_socket calls XPending. Removing XFlush improves
357 #define XFlush(DISPLAY) (void) 0
360 /***********************************************************************
362 ***********************************************************************/
366 /* This is a function useful for recording debugging information about
367 the sequence of occurrences in this file. */
375 struct record event_record
[100];
377 int event_record_index
;
380 record_event (char *locus
, int type
)
382 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
383 event_record_index
= 0;
385 event_record
[event_record_index
].locus
= locus
;
386 event_record
[event_record_index
].type
= type
;
387 event_record_index
++;
394 /* Return the struct x_display_info corresponding to DPY. */
396 struct x_display_info
*
397 x_display_info_for_display (Display
*dpy
)
399 struct x_display_info
*dpyinfo
;
401 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
402 if (dpyinfo
->display
== dpy
)
409 x_find_topmost_parent (struct frame
*f
)
411 struct x_output
*x
= f
->output_data
.x
;
412 Window win
= None
, wi
= x
->parent_desc
;
413 Display
*dpy
= FRAME_X_DISPLAY (f
);
415 while (wi
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
419 unsigned int nchildren
;
422 XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
);
429 #define OPAQUE 0xffffffff
432 x_set_frame_alpha (struct frame
*f
)
434 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
435 Display
*dpy
= FRAME_X_DISPLAY (f
);
436 Window win
= FRAME_OUTER_WINDOW (f
);
438 double alpha_min
= 1.0;
442 if (dpyinfo
->x_highlight_frame
== f
)
447 if (FLOATP (Vframe_alpha_lower_limit
))
448 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
449 else if (INTEGERP (Vframe_alpha_lower_limit
))
450 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
454 else if (alpha
> 1.0)
456 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
459 opac
= alpha
* OPAQUE
;
461 x_catch_errors (dpy
);
463 /* If there is a parent from the window manager, put the property there
464 also, to work around broken window managers that fail to do that.
465 Do this unconditionally as this function is called on reparent when
466 alpha has not changed on the frame. */
468 parent
= x_find_topmost_parent (f
);
470 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
471 XA_CARDINAL
, 32, PropModeReplace
,
472 (unsigned char *) &opac
, 1L);
474 /* return unless necessary */
479 unsigned long n
, left
;
481 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
482 0L, 1L, False
, XA_CARDINAL
,
483 &actual
, &format
, &n
, &left
,
486 if (rc
== Success
&& actual
!= None
)
488 unsigned long value
= *(unsigned long *)data
;
498 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
499 XA_CARDINAL
, 32, PropModeReplace
,
500 (unsigned char *) &opac
, 1L);
505 x_display_pixel_height (struct x_display_info
*dpyinfo
)
507 return HeightOfScreen (dpyinfo
->screen
);
511 x_display_pixel_width (struct x_display_info
*dpyinfo
)
513 return WidthOfScreen (dpyinfo
->screen
);
517 /***********************************************************************
518 Starting and ending an update
519 ***********************************************************************/
521 /* Start an update of frame F. This function is installed as a hook
522 for update_begin, i.e. it is called when update_begin is called.
523 This function is called prior to calls to x_update_window_begin for
524 each window being updated. Currently, there is nothing to do here
525 because all interesting stuff is done on a window basis. */
528 x_update_begin (struct frame
*f
)
534 /* Start update of window W. */
537 x_update_window_begin (struct window
*w
)
539 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
540 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
542 w
->output_cursor
= w
->cursor
;
546 if (f
== hlinfo
->mouse_face_mouse_frame
)
548 /* Don't do highlighting for mouse motion during the update. */
549 hlinfo
->mouse_face_defer
= 1;
551 /* If F needs to be redrawn, simply forget about any prior mouse
553 if (FRAME_GARBAGED_P (f
))
554 hlinfo
->mouse_face_window
= Qnil
;
561 /* Draw a vertical window border from (x,y0) to (x,y1) */
564 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
566 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
569 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
571 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
574 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
575 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
578 /* End update of window W.
580 Draw vertical borders between horizontally adjacent windows, and
581 display W's cursor if CURSOR_ON_P is non-zero.
583 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
584 glyphs in mouse-face were overwritten. In that case we have to
585 make sure that the mouse-highlight is properly redrawn.
587 W may be a menu bar pseudo-window in case we don't have X toolkit
588 support. Such windows don't have a cursor, so don't display it
592 x_update_window_end (struct window
*w
, bool cursor_on_p
,
593 bool mouse_face_overwritten_p
)
595 if (!w
->pseudo_window_p
)
600 display_and_set_cursor (w
, 1,
601 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
602 w
->output_cursor
.x
, w
->output_cursor
.y
);
604 if (draw_window_fringes (w
, 1))
605 x_draw_vertical_border (w
);
610 /* If a row with mouse-face was overwritten, arrange for
611 XTframe_up_to_date to redisplay the mouse highlight. */
612 if (mouse_face_overwritten_p
)
613 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w
->frame
)));
617 /* End update of frame F. This function is installed as a hook in
621 x_update_end (struct frame
*f
)
623 /* Mouse highlight may be displayed again. */
624 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
628 XFlush (FRAME_X_DISPLAY (f
));
634 /* This function is called from various places in xdisp.c
635 whenever a complete update has been performed. */
638 XTframe_up_to_date (struct frame
*f
)
641 FRAME_MOUSE_UPDATE (f
);
645 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
646 arrow bitmaps, or clear the fringes if no bitmaps are required
647 before DESIRED_ROW is made current. This function is called from
648 update_window_line only if it is known that there are differences
649 between bitmaps to be drawn between current row and DESIRED_ROW. */
652 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
659 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
660 desired_row
->redraw_fringe_bitmaps_p
= 1;
662 /* When a window has disappeared, make sure that no rest of
663 full-width rows stays visible in the internal border. Could
664 check here if updated window is the leftmost/rightmost window,
665 but I guess it's not worth doing since vertically split windows
666 are almost never used, internal border is rarely set, and the
667 overhead is very small. */
668 if (windows_or_buffers_changed
669 && desired_row
->full_width_p
670 && (f
= XFRAME (w
->frame
),
671 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
673 && (height
= desired_row
->visible_height
,
676 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
679 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
680 0, y
, width
, height
);
681 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
682 FRAME_PIXEL_WIDTH (f
) - width
,
689 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
691 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
692 Display
*display
= FRAME_X_DISPLAY (f
);
693 Window window
= FRAME_X_WINDOW (f
);
694 GC gc
= f
->output_data
.x
->normal_gc
;
695 struct face
*face
= p
->face
;
697 /* Must clip because of partially visible lines. */
698 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
702 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
704 /* In case the same realized face is used for fringes and
705 for something displayed in the text (e.g. face `region' on
706 mono-displays, the fill style may have been changed to
707 FillSolid in x_draw_glyph_string_background. */
709 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
711 XSetForeground (display
, face
->gc
, face
->background
);
713 #ifdef USE_TOOLKIT_SCROLL_BARS
714 /* If the fringe is adjacent to the left (right) scroll bar of a
715 leftmost (rightmost, respectively) window, then extend its
716 background to the gap between the fringe and the bar. */
717 if ((WINDOW_LEFTMOST_P (w
)
718 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
719 || (WINDOW_RIGHTMOST_P (w
)
720 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
722 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
726 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
727 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
728 * FRAME_COLUMN_WIDTH (f
));
732 /* Bitmap fills the fringe. */
733 if (bar_area_x
+ bar_area_width
== p
->x
)
734 bx
= bar_area_x
+ sb_width
;
735 else if (p
->x
+ p
->wd
== bar_area_x
)
739 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
741 nx
= bar_area_width
- sb_width
;
742 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
744 ny
= row
->visible_height
;
749 if (bar_area_x
+ bar_area_width
== bx
)
751 bx
= bar_area_x
+ sb_width
;
752 nx
+= bar_area_width
- sb_width
;
754 else if (bx
+ nx
== bar_area_x
)
755 nx
+= bar_area_width
- sb_width
;
760 if (bx
>= 0 && nx
> 0)
761 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
764 XSetForeground (display
, face
->gc
, face
->foreground
);
770 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
771 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
775 bits
= (char *) (p
->bits
+ p
->dh
);
777 bits
= (char *) p
->bits
+ p
->dh
;
779 /* Draw the bitmap. I believe these small pixmaps can be cached
781 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
783 ? (p
->overlay_p
? face
->background
784 : f
->output_data
.x
->cursor_pixel
)
786 face
->background
, depth
);
790 clipmask
= XCreatePixmapFromBitmapData (display
,
791 FRAME_X_DISPLAY_INFO (f
)->root_window
,
794 gcv
.clip_mask
= clipmask
;
795 gcv
.clip_x_origin
= p
->x
;
796 gcv
.clip_y_origin
= p
->y
;
797 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
800 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
801 p
->wd
, p
->h
, p
->x
, p
->y
);
802 XFreePixmap (display
, pixmap
);
806 gcv
.clip_mask
= (Pixmap
) 0;
807 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
808 XFreePixmap (display
, clipmask
);
812 XSetClipMask (display
, gc
, None
);
815 /***********************************************************************
817 ***********************************************************************/
821 static void x_set_glyph_string_clipping (struct glyph_string
*);
822 static void x_set_glyph_string_gc (struct glyph_string
*);
823 static void x_draw_glyph_string_foreground (struct glyph_string
*);
824 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
825 static void x_draw_glyph_string_box (struct glyph_string
*);
826 static void x_draw_glyph_string (struct glyph_string
*);
827 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
828 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
829 static void x_set_cursor_gc (struct glyph_string
*);
830 static void x_set_mode_line_face_gc (struct glyph_string
*);
831 static void x_set_mouse_face_gc (struct glyph_string
*);
832 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
833 unsigned long *, double, int);
834 static void x_setup_relief_color (struct frame
*, struct relief
*,
835 double, int, unsigned long);
836 static void x_setup_relief_colors (struct glyph_string
*);
837 static void x_draw_image_glyph_string (struct glyph_string
*);
838 static void x_draw_image_relief (struct glyph_string
*);
839 static void x_draw_image_foreground (struct glyph_string
*);
840 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
841 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
843 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
844 int, int, int, int, int, int,
846 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
847 int, int, int, XRectangle
*);
848 static void x_scroll_bar_clear (struct frame
*);
851 static void x_check_font (struct frame
*, struct font
*);
855 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
859 x_set_cursor_gc (struct glyph_string
*s
)
861 if (s
->font
== FRAME_FONT (s
->f
)
862 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
863 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
865 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
868 /* Cursor on non-default face: must merge. */
872 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
873 xgcv
.foreground
= s
->face
->background
;
875 /* If the glyph would be invisible, try a different foreground. */
876 if (xgcv
.foreground
== xgcv
.background
)
877 xgcv
.foreground
= s
->face
->foreground
;
878 if (xgcv
.foreground
== xgcv
.background
)
879 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
880 if (xgcv
.foreground
== xgcv
.background
)
881 xgcv
.foreground
= s
->face
->foreground
;
883 /* Make sure the cursor is distinct from text in this face. */
884 if (xgcv
.background
== s
->face
->background
885 && xgcv
.foreground
== s
->face
->foreground
)
887 xgcv
.background
= s
->face
->foreground
;
888 xgcv
.foreground
= s
->face
->background
;
891 IF_DEBUG (x_check_font (s
->f
, s
->font
));
892 xgcv
.graphics_exposures
= False
;
893 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
895 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
896 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
899 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
900 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
902 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
907 /* Set up S->gc of glyph string S for drawing text in mouse face. */
910 x_set_mouse_face_gc (struct glyph_string
*s
)
915 /* What face has to be used last for the mouse face? */
916 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
917 face
= FACE_FROM_ID (s
->f
, face_id
);
919 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
921 if (s
->first_glyph
->type
== CHAR_GLYPH
)
922 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
924 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
925 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
926 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
928 if (s
->font
== s
->face
->font
)
932 /* Otherwise construct scratch_cursor_gc with values from FACE
937 xgcv
.background
= s
->face
->background
;
938 xgcv
.foreground
= s
->face
->foreground
;
939 xgcv
.graphics_exposures
= False
;
940 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
942 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
943 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
946 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
947 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
949 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
952 eassert (s
->gc
!= 0);
956 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
957 Faces to use in the mode line have already been computed when the
958 matrix was built, so there isn't much to do, here. */
961 x_set_mode_line_face_gc (struct glyph_string
*s
)
967 /* Set S->gc of glyph string S for drawing that glyph string. Set
968 S->stippled_p to a non-zero value if the face of S has a stipple
972 x_set_glyph_string_gc (struct glyph_string
*s
)
974 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
976 if (s
->hl
== DRAW_NORMAL_TEXT
)
979 s
->stippled_p
= s
->face
->stipple
!= 0;
981 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
983 x_set_mode_line_face_gc (s
);
984 s
->stippled_p
= s
->face
->stipple
!= 0;
986 else if (s
->hl
== DRAW_CURSOR
)
991 else if (s
->hl
== DRAW_MOUSE_FACE
)
993 x_set_mouse_face_gc (s
);
994 s
->stippled_p
= s
->face
->stipple
!= 0;
996 else if (s
->hl
== DRAW_IMAGE_RAISED
997 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1000 s
->stippled_p
= s
->face
->stipple
!= 0;
1004 s
->gc
= s
->face
->gc
;
1005 s
->stippled_p
= s
->face
->stipple
!= 0;
1008 /* GC must have been set. */
1009 eassert (s
->gc
!= 0);
1013 /* Set clipping for output of glyph string S. S may be part of a mode
1014 line or menu if we don't have X toolkit support. */
1017 x_set_glyph_string_clipping (struct glyph_string
*s
)
1019 XRectangle
*r
= s
->clip
;
1020 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1023 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1028 /* Set SRC's clipping for output of glyph string DST. This is called
1029 when we are drawing DST's left_overhang or right_overhang only in
1033 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1038 r
.width
= src
->width
;
1040 r
.height
= src
->height
;
1043 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1048 Compute left and right overhang of glyph string S. */
1051 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1054 && (s
->first_glyph
->type
== CHAR_GLYPH
1055 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1057 struct font_metrics metrics
;
1059 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1061 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1062 struct font
*font
= s
->font
;
1065 for (i
= 0; i
< s
->nchars
; i
++)
1066 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1067 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1071 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1073 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1075 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1076 ? metrics
.rbearing
- metrics
.width
: 0);
1077 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1081 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1082 s
->left_overhang
= - s
->cmp
->lbearing
;
1087 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1090 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1093 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1094 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1095 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1096 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1100 /* Draw the background of glyph_string S. If S->background_filled_p
1101 is non-zero don't draw it. FORCE_P non-zero means draw the
1102 background even if it wouldn't be drawn normally. This is used
1103 when a string preceding S draws into the background of S, or S
1104 contains the first component of a composition. */
1107 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1109 /* Nothing to do if background has already been drawn or if it
1110 shouldn't be drawn in the first place. */
1111 if (!s
->background_filled_p
)
1113 int box_line_width
= max (s
->face
->box_line_width
, 0);
1117 /* Fill background with a stipple pattern. */
1118 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1119 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1120 s
->y
+ box_line_width
,
1121 s
->background_width
,
1122 s
->height
- 2 * box_line_width
);
1123 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1124 s
->background_filled_p
= 1;
1126 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1127 || s
->font_not_found_p
1128 || s
->extends_to_end_of_line_p
1131 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1132 s
->background_width
,
1133 s
->height
- 2 * box_line_width
);
1134 s
->background_filled_p
= 1;
1140 /* Draw the foreground of glyph string S. */
1143 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1147 /* If first glyph of S has a left box line, start drawing the text
1148 of S to the right of that box line. */
1149 if (s
->face
->box
!= FACE_NO_BOX
1150 && s
->first_glyph
->left_box_line_p
)
1151 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1155 /* Draw characters of S as rectangles if S's font could not be
1157 if (s
->font_not_found_p
)
1159 for (i
= 0; i
< s
->nchars
; ++i
)
1161 struct glyph
*g
= s
->first_glyph
+ i
;
1162 XDrawRectangle (s
->display
, s
->window
,
1163 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1165 x
+= g
->pixel_width
;
1170 struct font
*font
= s
->font
;
1171 int boff
= font
->baseline_offset
;
1174 if (font
->vertical_centering
)
1175 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1177 y
= s
->ybase
- boff
;
1179 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1180 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1182 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1183 if (s
->face
->overstrike
)
1184 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1188 /* Draw the foreground of composite glyph string S. */
1191 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1194 struct font
*font
= s
->font
;
1196 /* If first glyph of S has a left box line, start drawing the text
1197 of S to the right of that box line. */
1198 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1199 && s
->first_glyph
->left_box_line_p
)
1200 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1204 /* S is a glyph string for a composition. S->cmp_from is the index
1205 of the first character drawn for glyphs of this composition.
1206 S->cmp_from == 0 means we are drawing the very first character of
1207 this composition. */
1209 /* Draw a rectangle for the composition if the font for the very
1210 first character of the composition could not be loaded. */
1211 if (s
->font_not_found_p
)
1213 if (s
->cmp_from
== 0)
1214 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1215 s
->width
- 1, s
->height
- 1);
1217 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1221 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1222 /* TAB in a composition means display glyphs with padding
1223 space on the left or right. */
1224 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1226 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1227 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1229 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1230 if (s
->face
->overstrike
)
1231 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1236 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1241 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1243 glyph
= LGSTRING_GLYPH (gstring
, i
);
1244 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1245 width
+= LGLYPH_WIDTH (glyph
);
1248 int xoff
, yoff
, wadjust
;
1252 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1253 if (s
->face
->overstrike
)
1254 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1257 xoff
= LGLYPH_XOFF (glyph
);
1258 yoff
= LGLYPH_YOFF (glyph
);
1259 wadjust
= LGLYPH_WADJUST (glyph
);
1260 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1261 if (s
->face
->overstrike
)
1262 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1270 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1271 if (s
->face
->overstrike
)
1272 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1278 /* Draw the foreground of glyph string S for glyphless characters. */
1281 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1283 struct glyph
*glyph
= s
->first_glyph
;
1287 /* If first glyph of S has a left box line, start drawing the text
1288 of S to the right of that box line. */
1289 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1290 && s
->first_glyph
->left_box_line_p
)
1291 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1297 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1299 char buf
[7], *str
= NULL
;
1300 int len
= glyph
->u
.glyphless
.len
;
1302 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1305 && CHAR_TABLE_P (Vglyphless_char_display
)
1306 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1310 = (! glyph
->u
.glyphless
.for_no_font
1311 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1312 glyph
->u
.glyphless
.ch
)
1313 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1314 if (STRINGP (acronym
))
1315 str
= SSDATA (acronym
);
1318 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1320 sprintf (buf
, "%0*X",
1321 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1322 glyph
->u
.glyphless
.ch
);
1328 int upper_len
= (len
+ 1) / 2;
1331 /* It is assured that all LEN characters in STR is ASCII. */
1332 for (j
= 0; j
< len
; j
++)
1334 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1335 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1337 s
->font
->driver
->draw (s
, 0, upper_len
,
1338 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1339 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1341 s
->font
->driver
->draw (s
, upper_len
, len
,
1342 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1343 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1346 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1347 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
1348 x
, s
->ybase
- glyph
->ascent
,
1349 glyph
->pixel_width
- 1,
1350 glyph
->ascent
+ glyph
->descent
- 1);
1351 x
+= glyph
->pixel_width
;
1355 #ifdef USE_X_TOOLKIT
1359 /* Return the frame on which widget WIDGET is used.. Abort if frame
1360 cannot be determined. */
1362 static struct frame
*
1363 x_frame_of_widget (Widget widget
)
1365 struct x_display_info
*dpyinfo
;
1366 Lisp_Object tail
, frame
;
1369 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1371 /* Find the top-level shell of the widget. Note that this function
1372 can be called when the widget is not yet realized, so XtWindow
1373 (widget) == 0. That's the reason we can't simply use
1374 x_any_window_to_frame. */
1375 while (!XtIsTopLevelShell (widget
))
1376 widget
= XtParent (widget
);
1378 /* Look for a frame with that top-level widget. Allocate the color
1379 on that frame to get the right gamma correction value. */
1380 FOR_EACH_FRAME (tail
, frame
)
1384 && f
->output_data
.nothing
!= 1
1385 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
1386 && f
->output_data
.x
->widget
== widget
)
1392 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1393 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1394 If this produces the same color as PIXEL, try a color where all RGB
1395 values have DELTA added. Return the allocated color in *PIXEL.
1396 DISPLAY is the X display, CMAP is the colormap to operate on.
1397 Value is true if successful. */
1400 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1401 unsigned long *pixel
, double factor
, int delta
)
1403 struct frame
*f
= x_frame_of_widget (widget
);
1404 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1407 #endif /* USE_LUCID */
1410 /* Structure specifying which arguments should be passed by Xt to
1411 cvt_string_to_pixel. We want the widget's screen and colormap. */
1413 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1415 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1417 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1422 /* The address of this variable is returned by
1423 cvt_string_to_pixel. */
1425 static Pixel cvt_string_to_pixel_value
;
1428 /* Convert a color name to a pixel color.
1430 DPY is the display we are working on.
1432 ARGS is an array of *NARGS XrmValue structures holding additional
1433 information about the widget for which the conversion takes place.
1434 The contents of this array are determined by the specification
1435 in cvt_string_to_pixel_args.
1437 FROM is a pointer to an XrmValue which points to the color name to
1438 convert. TO is an XrmValue in which to return the pixel color.
1440 CLOSURE_RET is a pointer to user-data, in which we record if
1441 we allocated the color or not.
1443 Value is True if successful, False otherwise. */
1446 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1447 XrmValue
*from
, XrmValue
*to
,
1448 XtPointer
*closure_ret
)
1458 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1459 "wrongParameters", "cvt_string_to_pixel",
1461 "Screen and colormap args required", NULL
, NULL
);
1465 screen
= *(Screen
**) args
[0].addr
;
1466 cmap
= *(Colormap
*) args
[1].addr
;
1467 color_name
= (String
) from
->addr
;
1469 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1471 *closure_ret
= (XtPointer
) False
;
1472 pixel
= WhitePixelOfScreen (screen
);
1474 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1476 *closure_ret
= (XtPointer
) False
;
1477 pixel
= BlackPixelOfScreen (screen
);
1479 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1480 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1482 pixel
= color
.pixel
;
1483 *closure_ret
= (XtPointer
) True
;
1488 Cardinal nparams
= 1;
1490 params
[0] = color_name
;
1491 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1492 "badValue", "cvt_string_to_pixel",
1493 "XtToolkitError", "Invalid color `%s'",
1498 if (to
->addr
!= NULL
)
1500 if (to
->size
< sizeof (Pixel
))
1502 to
->size
= sizeof (Pixel
);
1506 *(Pixel
*) to
->addr
= pixel
;
1510 cvt_string_to_pixel_value
= pixel
;
1511 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1514 to
->size
= sizeof (Pixel
);
1519 /* Free a pixel color which was previously allocated via
1520 cvt_string_to_pixel. This is registered as the destructor
1521 for this type of resource via XtSetTypeConverter.
1523 APP is the application context in which we work.
1525 TO is a pointer to an XrmValue holding the color to free.
1526 CLOSURE is the value we stored in CLOSURE_RET for this color
1527 in cvt_string_to_pixel.
1529 ARGS and NARGS are like for cvt_string_to_pixel. */
1532 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1537 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1539 "Screen and colormap arguments required",
1542 else if (closure
!= NULL
)
1544 /* We did allocate the pixel, so free it. */
1545 Screen
*screen
= *(Screen
**) args
[0].addr
;
1546 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1547 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1548 (Pixel
*) to
->addr
, 1);
1553 #endif /* USE_X_TOOLKIT */
1556 /* Value is an array of XColor structures for the contents of the
1557 color map of display DPY. Set *NCELLS to the size of the array.
1558 Note that this probably shouldn't be called for large color maps,
1559 say a 24-bit TrueColor map. */
1561 static const XColor
*
1562 x_color_cells (Display
*dpy
, int *ncells
)
1564 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1566 if (dpyinfo
->color_cells
== NULL
)
1568 Screen
*screen
= dpyinfo
->screen
;
1569 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1572 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
1573 sizeof *dpyinfo
->color_cells
);
1574 dpyinfo
->ncolor_cells
= ncolor_cells
;
1576 for (i
= 0; i
< ncolor_cells
; ++i
)
1577 dpyinfo
->color_cells
[i
].pixel
= i
;
1579 XQueryColors (dpy
, dpyinfo
->cmap
,
1580 dpyinfo
->color_cells
, ncolor_cells
);
1583 *ncells
= dpyinfo
->ncolor_cells
;
1584 return dpyinfo
->color_cells
;
1588 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1589 colors in COLORS. Use cached information, if available. */
1592 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1594 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1596 if (dpyinfo
->color_cells
)
1599 for (i
= 0; i
< ncolors
; ++i
)
1601 unsigned long pixel
= colors
[i
].pixel
;
1602 eassert (pixel
< dpyinfo
->ncolor_cells
);
1603 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1604 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1608 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1612 /* On frame F, translate pixel color to RGB values for the color in
1613 COLOR. Use cached information, if available. */
1616 x_query_color (struct frame
*f
, XColor
*color
)
1618 x_query_colors (f
, color
, 1);
1622 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1623 exact match can't be allocated, try the nearest color available.
1624 Value is true if successful. Set *COLOR to the color
1628 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1632 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1635 /* If we got to this point, the colormap is full, so we're going
1636 to try to get the next closest color. The algorithm used is
1637 a least-squares matching, which is what X uses for closest
1638 color matching with StaticColor visuals. */
1640 int max_color_delta
= 255;
1641 int max_delta
= 3 * max_color_delta
;
1642 int nearest_delta
= max_delta
+ 1;
1644 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1646 for (nearest
= i
= 0; i
< ncells
; ++i
)
1648 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1649 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1650 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1651 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1653 if (delta
< nearest_delta
)
1656 nearest_delta
= delta
;
1660 color
->red
= cells
[nearest
].red
;
1661 color
->green
= cells
[nearest
].green
;
1662 color
->blue
= cells
[nearest
].blue
;
1663 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1667 /* If allocation succeeded, and the allocated pixel color is not
1668 equal to a cached pixel color recorded earlier, there was a
1669 change in the colormap, so clear the color cache. */
1670 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1671 XColor
*cached_color
;
1673 if (dpyinfo
->color_cells
1674 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1675 (cached_color
->red
!= color
->red
1676 || cached_color
->blue
!= color
->blue
1677 || cached_color
->green
!= color
->green
)))
1679 xfree (dpyinfo
->color_cells
);
1680 dpyinfo
->color_cells
= NULL
;
1681 dpyinfo
->ncolor_cells
= 0;
1685 #ifdef DEBUG_X_COLORS
1687 register_color (color
->pixel
);
1688 #endif /* DEBUG_X_COLORS */
1694 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1695 exact match can't be allocated, try the nearest color available.
1696 Value is true if successful. Set *COLOR to the color
1700 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1702 gamma_correct (f
, color
);
1703 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1707 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1708 It's necessary to do this instead of just using PIXEL directly to
1709 get color reference counts right. */
1712 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1716 color
.pixel
= pixel
;
1718 x_query_color (f
, &color
);
1719 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1721 #ifdef DEBUG_X_COLORS
1722 register_color (pixel
);
1728 /* Brightness beyond which a color won't have its highlight brightness
1731 Nominally, highlight colors for `3d' faces are calculated by
1732 brightening an object's color by a constant scale factor, but this
1733 doesn't yield good results for dark colors, so for colors who's
1734 brightness is less than this value (on a scale of 0-65535) have an
1735 use an additional additive factor.
1737 The value here is set so that the default menu-bar/mode-line color
1738 (grey75) will not have its highlights changed at all. */
1739 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1742 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1743 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1744 If this produces the same color as PIXEL, try a color where all RGB
1745 values have DELTA added. Return the allocated color in *PIXEL.
1746 DISPLAY is the X display, CMAP is the colormap to operate on.
1747 Value is non-zero if successful. */
1750 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1756 /* Get RGB color values. */
1757 color
.pixel
= *pixel
;
1758 x_query_color (f
, &color
);
1760 /* Change RGB values by specified FACTOR. Avoid overflow! */
1761 eassert (factor
>= 0);
1762 new.red
= min (0xffff, factor
* color
.red
);
1763 new.green
= min (0xffff, factor
* color
.green
);
1764 new.blue
= min (0xffff, factor
* color
.blue
);
1766 /* Calculate brightness of COLOR. */
1767 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1769 /* We only boost colors that are darker than
1770 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1771 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1772 /* Make an additive adjustment to NEW, because it's dark enough so
1773 that scaling by FACTOR alone isn't enough. */
1775 /* How far below the limit this color is (0 - 1, 1 being darker). */
1776 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1777 /* The additive adjustment. */
1778 int min_delta
= delta
* dimness
* factor
/ 2;
1782 new.red
= max (0, new.red
- min_delta
);
1783 new.green
= max (0, new.green
- min_delta
);
1784 new.blue
= max (0, new.blue
- min_delta
);
1788 new.red
= min (0xffff, min_delta
+ new.red
);
1789 new.green
= min (0xffff, min_delta
+ new.green
);
1790 new.blue
= min (0xffff, min_delta
+ new.blue
);
1794 /* Try to allocate the color. */
1795 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1798 if (new.pixel
== *pixel
)
1800 /* If we end up with the same color as before, try adding
1801 delta to the RGB values. */
1802 x_free_colors (f
, &new.pixel
, 1);
1804 new.red
= min (0xffff, delta
+ color
.red
);
1805 new.green
= min (0xffff, delta
+ color
.green
);
1806 new.blue
= min (0xffff, delta
+ color
.blue
);
1807 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1818 /* Set up the foreground color for drawing relief lines of glyph
1819 string S. RELIEF is a pointer to a struct relief containing the GC
1820 with which lines will be drawn. Use a color that is FACTOR or
1821 DELTA lighter or darker than the relief's background which is found
1822 in S->f->output_data.x->relief_background. If such a color cannot
1823 be allocated, use DEFAULT_PIXEL, instead. */
1826 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1829 struct x_output
*di
= f
->output_data
.x
;
1830 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1831 unsigned long pixel
;
1832 unsigned long background
= di
->relief_background
;
1833 Colormap cmap
= FRAME_X_COLORMAP (f
);
1834 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1835 Display
*dpy
= FRAME_X_DISPLAY (f
);
1837 xgcv
.graphics_exposures
= False
;
1838 xgcv
.line_width
= 1;
1840 /* Free previously allocated color. The color cell will be reused
1841 when it has been freed as many times as it was allocated, so this
1842 doesn't affect faces using the same colors. */
1844 && relief
->allocated_p
)
1846 x_free_colors (f
, &relief
->pixel
, 1);
1847 relief
->allocated_p
= 0;
1850 /* Allocate new color. */
1851 xgcv
.foreground
= default_pixel
;
1853 if (dpyinfo
->n_planes
!= 1
1854 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1856 relief
->allocated_p
= 1;
1857 xgcv
.foreground
= relief
->pixel
= pixel
;
1860 if (relief
->gc
== 0)
1862 xgcv
.stipple
= dpyinfo
->gray
;
1864 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1867 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1871 /* Set up colors for the relief lines around glyph string S. */
1874 x_setup_relief_colors (struct glyph_string
*s
)
1876 struct x_output
*di
= s
->f
->output_data
.x
;
1877 unsigned long color
;
1879 if (s
->face
->use_box_color_for_shadows_p
)
1880 color
= s
->face
->box_color
;
1881 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1883 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1884 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1889 /* Get the background color of the face. */
1890 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1891 color
= xgcv
.background
;
1894 if (di
->white_relief
.gc
== 0
1895 || color
!= di
->relief_background
)
1897 di
->relief_background
= color
;
1898 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1899 WHITE_PIX_DEFAULT (s
->f
));
1900 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1901 BLACK_PIX_DEFAULT (s
->f
));
1906 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1907 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1908 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1909 relief. LEFT_P non-zero means draw a relief on the left side of
1910 the rectangle. RIGHT_P non-zero means draw a relief on the right
1911 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1915 x_draw_relief_rect (struct frame
*f
,
1916 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1917 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1918 XRectangle
*clip_rect
)
1920 Display
*dpy
= FRAME_X_DISPLAY (f
);
1921 Window window
= FRAME_X_WINDOW (f
);
1926 gc
= f
->output_data
.x
->white_relief
.gc
;
1928 gc
= f
->output_data
.x
->black_relief
.gc
;
1929 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1931 /* This code is more complicated than it has to be, because of two
1932 minor hacks to make the boxes look nicer: (i) if width > 1, draw
1933 the outermost line using the black relief. (ii) Omit the four
1940 XDrawLine (dpy
, window
, gc
,
1941 left_x
+ (left_p
? 1 : 0), top_y
,
1942 right_x
+ (right_p
? 0 : 1), top_y
);
1944 for (i
= 1; i
< width
; ++i
)
1945 XDrawLine (dpy
, window
, gc
,
1946 left_x
+ i
* left_p
, top_y
+ i
,
1947 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1954 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1956 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
1957 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
1959 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
1960 XDrawLine (dpy
, window
, gc
,
1961 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
1962 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1965 XSetClipMask (dpy
, gc
, None
);
1967 gc
= f
->output_data
.x
->black_relief
.gc
;
1969 gc
= f
->output_data
.x
->white_relief
.gc
;
1970 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1974 /* Outermost top line. */
1976 XDrawLine (dpy
, window
, gc
,
1977 left_x
+ (left_p
? 1 : 0), top_y
,
1978 right_x
+ (right_p
? 0 : 1), top_y
);
1980 /* Outermost left line. */
1982 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1988 XDrawLine (dpy
, window
, gc
,
1989 left_x
+ (left_p
? 1 : 0), bottom_y
,
1990 right_x
+ (right_p
? 0 : 1), bottom_y
);
1991 for (i
= 1; i
< width
; ++i
)
1992 XDrawLine (dpy
, window
, gc
,
1993 left_x
+ i
* left_p
, bottom_y
- i
,
1994 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2000 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
2001 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
2002 for (i
= 0; i
< width
; ++i
)
2003 XDrawLine (dpy
, window
, gc
,
2004 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
2005 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
2008 XSetClipMask (dpy
, gc
, None
);
2012 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2013 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2014 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2015 left side of the rectangle. RIGHT_P non-zero means draw a line
2016 on the right side of the rectangle. CLIP_RECT is the clipping
2017 rectangle to use when drawing. */
2020 x_draw_box_rect (struct glyph_string
*s
,
2021 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2022 int left_p
, int right_p
, XRectangle
*clip_rect
)
2026 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2027 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2028 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2031 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2032 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2036 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2037 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2040 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2041 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2045 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2046 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2048 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2049 XSetClipMask (s
->display
, s
->gc
, None
);
2053 /* Draw a box around glyph string S. */
2056 x_draw_glyph_string_box (struct glyph_string
*s
)
2058 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2059 int left_p
, right_p
;
2060 struct glyph
*last_glyph
;
2061 XRectangle clip_rect
;
2063 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2064 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2065 : window_box_right (s
->w
, s
->area
));
2067 /* The glyph that may have a right box line. */
2068 last_glyph
= (s
->cmp
|| s
->img
2070 : s
->first_glyph
+ s
->nchars
- 1);
2072 width
= eabs (s
->face
->box_line_width
);
2073 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2075 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2077 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2079 bottom_y
= top_y
+ s
->height
- 1;
2081 left_p
= (s
->first_glyph
->left_box_line_p
2082 || (s
->hl
== DRAW_MOUSE_FACE
2084 || s
->prev
->hl
!= s
->hl
)));
2085 right_p
= (last_glyph
->right_box_line_p
2086 || (s
->hl
== DRAW_MOUSE_FACE
2088 || s
->next
->hl
!= s
->hl
)));
2090 get_glyph_string_clip_rect (s
, &clip_rect
);
2092 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2093 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2094 left_p
, right_p
, &clip_rect
);
2097 x_setup_relief_colors (s
);
2098 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2099 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2104 /* Draw foreground of image glyph string S. */
2107 x_draw_image_foreground (struct glyph_string
*s
)
2110 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2112 /* If first glyph of S has a left box line, start drawing it to the
2113 right of that line. */
2114 if (s
->face
->box
!= FACE_NO_BOX
2115 && s
->first_glyph
->left_box_line_p
2117 x
+= eabs (s
->face
->box_line_width
);
2119 /* If there is a margin around the image, adjust x- and y-position
2121 if (s
->slice
.x
== 0)
2122 x
+= s
->img
->hmargin
;
2123 if (s
->slice
.y
== 0)
2124 y
+= s
->img
->vmargin
;
2130 /* We can't set both a clip mask and use XSetClipRectangles
2131 because the latter also sets a clip mask. We also can't
2132 trust on the shape extension to be available
2133 (XShapeCombineRegion). So, compute the rectangle to draw
2135 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2138 XRectangle clip_rect
, image_rect
, r
;
2140 xgcv
.clip_mask
= s
->img
->mask
;
2141 xgcv
.clip_x_origin
= x
;
2142 xgcv
.clip_y_origin
= y
;
2143 xgcv
.function
= GXcopy
;
2144 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2146 get_glyph_string_clip_rect (s
, &clip_rect
);
2149 image_rect
.width
= s
->slice
.width
;
2150 image_rect
.height
= s
->slice
.height
;
2151 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2152 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2153 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2154 r
.width
, r
.height
, r
.x
, r
.y
);
2158 XRectangle clip_rect
, image_rect
, r
;
2160 get_glyph_string_clip_rect (s
, &clip_rect
);
2163 image_rect
.width
= s
->slice
.width
;
2164 image_rect
.height
= s
->slice
.height
;
2165 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2166 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2167 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2168 r
.width
, r
.height
, r
.x
, r
.y
);
2170 /* When the image has a mask, we can expect that at
2171 least part of a mouse highlight or a block cursor will
2172 be visible. If the image doesn't have a mask, make
2173 a block cursor visible by drawing a rectangle around
2174 the image. I believe it's looking better if we do
2175 nothing here for mouse-face. */
2176 if (s
->hl
== DRAW_CURSOR
)
2178 int relief
= eabs (s
->img
->relief
);
2179 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2180 x
- relief
, y
- relief
,
2181 s
->slice
.width
+ relief
*2 - 1,
2182 s
->slice
.height
+ relief
*2 - 1);
2187 /* Draw a rectangle if image could not be loaded. */
2188 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2189 s
->slice
.width
- 1, s
->slice
.height
- 1);
2193 /* Draw a relief around the image glyph string S. */
2196 x_draw_image_relief (struct glyph_string
*s
)
2198 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
2201 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2203 /* If first glyph of S has a left box line, start drawing it to the
2204 right of that line. */
2205 if (s
->face
->box
!= FACE_NO_BOX
2206 && s
->first_glyph
->left_box_line_p
2208 x
+= eabs (s
->face
->box_line_width
);
2210 /* If there is a margin around the image, adjust x- and y-position
2212 if (s
->slice
.x
== 0)
2213 x
+= s
->img
->hmargin
;
2214 if (s
->slice
.y
== 0)
2215 y
+= s
->img
->vmargin
;
2217 if (s
->hl
== DRAW_IMAGE_SUNKEN
2218 || s
->hl
== DRAW_IMAGE_RAISED
)
2220 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2221 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2225 thick
= eabs (s
->img
->relief
);
2226 raised_p
= s
->img
->relief
> 0;
2229 x1
= x
+ s
->slice
.width
- 1;
2230 y1
= y
+ s
->slice
.height
- 1;
2231 top_p
= bot_p
= left_p
= right_p
= 0;
2233 if (s
->slice
.x
== 0)
2234 x
-= thick
, left_p
= 1;
2235 if (s
->slice
.y
== 0)
2236 y
-= thick
, top_p
= 1;
2237 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
2238 x1
+= thick
, right_p
= 1;
2239 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
2240 y1
+= thick
, bot_p
= 1;
2242 x_setup_relief_colors (s
);
2243 get_glyph_string_clip_rect (s
, &r
);
2244 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
2245 top_p
, bot_p
, left_p
, right_p
, &r
);
2249 /* Draw the foreground of image glyph string S to PIXMAP. */
2252 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2255 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2257 /* If first glyph of S has a left box line, start drawing it to the
2258 right of that line. */
2259 if (s
->face
->box
!= FACE_NO_BOX
2260 && s
->first_glyph
->left_box_line_p
2262 x
+= eabs (s
->face
->box_line_width
);
2264 /* If there is a margin around the image, adjust x- and y-position
2266 if (s
->slice
.x
== 0)
2267 x
+= s
->img
->hmargin
;
2268 if (s
->slice
.y
== 0)
2269 y
+= s
->img
->vmargin
;
2275 /* We can't set both a clip mask and use XSetClipRectangles
2276 because the latter also sets a clip mask. We also can't
2277 trust on the shape extension to be available
2278 (XShapeCombineRegion). So, compute the rectangle to draw
2280 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2284 xgcv
.clip_mask
= s
->img
->mask
;
2285 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2286 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2287 xgcv
.function
= GXcopy
;
2288 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2290 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2291 s
->slice
.x
, s
->slice
.y
,
2292 s
->slice
.width
, s
->slice
.height
, x
, y
);
2293 XSetClipMask (s
->display
, s
->gc
, None
);
2297 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2298 s
->slice
.x
, s
->slice
.y
,
2299 s
->slice
.width
, s
->slice
.height
, x
, y
);
2301 /* When the image has a mask, we can expect that at
2302 least part of a mouse highlight or a block cursor will
2303 be visible. If the image doesn't have a mask, make
2304 a block cursor visible by drawing a rectangle around
2305 the image. I believe it's looking better if we do
2306 nothing here for mouse-face. */
2307 if (s
->hl
== DRAW_CURSOR
)
2309 int r
= eabs (s
->img
->relief
);
2310 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2311 s
->slice
.width
+ r
*2 - 1,
2312 s
->slice
.height
+ r
*2 - 1);
2317 /* Draw a rectangle if image could not be loaded. */
2318 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2319 s
->slice
.width
- 1, s
->slice
.height
- 1);
2323 /* Draw part of the background of glyph string S. X, Y, W, and H
2324 give the rectangle to draw. */
2327 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2331 /* Fill background with a stipple pattern. */
2332 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2333 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2334 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2337 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2341 /* Draw image glyph string S.
2344 s->x +-------------------------
2347 | +-------------------------
2350 | | +-------------------
2356 x_draw_image_glyph_string (struct glyph_string
*s
)
2358 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2359 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2361 Pixmap pixmap
= None
;
2364 if (s
->slice
.y
== 0)
2365 height
-= box_line_vwidth
;
2366 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2367 height
-= box_line_vwidth
;
2369 /* Fill background with face under the image. Do it only if row is
2370 taller than image or if image has a clip mask to reduce
2372 s
->stippled_p
= s
->face
->stipple
!= 0;
2373 if (height
> s
->slice
.height
2377 || s
->img
->pixmap
== 0
2378 || s
->width
!= s
->background_width
)
2382 /* Create a pixmap as large as the glyph string. Fill it
2383 with the background color. Copy the image to it, using
2384 its mask. Copy the temporary pixmap to the display. */
2385 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2386 int depth
= DefaultDepthOfScreen (screen
);
2388 /* Create a pixmap as large as the glyph string. */
2389 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2390 s
->background_width
,
2393 /* Don't clip in the following because we're working on the
2395 XSetClipMask (s
->display
, s
->gc
, None
);
2397 /* Fill the pixmap with the background color/stipple. */
2400 /* Fill background with a stipple pattern. */
2401 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2402 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2403 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2404 0, 0, s
->background_width
, s
->height
);
2405 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2406 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2411 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2413 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2414 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2415 0, 0, s
->background_width
, s
->height
);
2416 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2424 if (s
->first_glyph
->left_box_line_p
2426 x
+= box_line_hwidth
;
2428 if (s
->slice
.y
== 0)
2429 y
+= box_line_vwidth
;
2431 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2434 s
->background_filled_p
= 1;
2437 /* Draw the foreground. */
2440 x_draw_image_foreground_1 (s
, pixmap
);
2441 x_set_glyph_string_clipping (s
);
2442 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2443 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2444 XFreePixmap (s
->display
, pixmap
);
2447 x_draw_image_foreground (s
);
2449 /* If we must draw a relief around the image, do it. */
2451 || s
->hl
== DRAW_IMAGE_RAISED
2452 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2453 x_draw_image_relief (s
);
2457 /* Draw stretch glyph string S. */
2460 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2462 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2464 if (s
->hl
== DRAW_CURSOR
2465 && !x_stretch_cursor_p
)
2467 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2468 wide as the stretch glyph. */
2469 int width
, background_width
= s
->background_width
;
2472 if (!s
->row
->reversed_p
)
2474 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2478 background_width
-= left_x
- x
;
2484 /* In R2L rows, draw the cursor on the right edge of the
2486 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2488 if (x
+ background_width
> right_x
)
2489 background_width
-= x
- right_x
;
2490 x
+= background_width
;
2492 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2493 if (s
->row
->reversed_p
)
2497 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2499 /* Clear rest using the GC of the original non-cursor face. */
2500 if (width
< background_width
)
2503 int w
= background_width
- width
, h
= s
->height
;
2507 if (!s
->row
->reversed_p
)
2511 if (s
->row
->mouse_face_p
2512 && cursor_in_mouse_face_p (s
->w
))
2514 x_set_mouse_face_gc (s
);
2520 get_glyph_string_clip_rect (s
, &r
);
2521 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2523 if (s
->face
->stipple
)
2525 /* Fill background with a stipple pattern. */
2526 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2527 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2528 XSetFillStyle (s
->display
, gc
, FillSolid
);
2533 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2534 XSetForeground (s
->display
, gc
, xgcv
.background
);
2535 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2536 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2540 else if (!s
->background_filled_p
)
2542 int background_width
= s
->background_width
;
2543 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2545 /* Don't draw into left margin, fringe or scrollbar area
2546 except for header line and mode line. */
2547 if (x
< left_x
&& !s
->row
->mode_line_p
)
2549 background_width
-= left_x
- x
;
2552 if (background_width
> 0)
2553 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2556 s
->background_filled_p
= 1;
2560 Draw a wavy line under S. The wave fills wave_height pixels from y0.
2566 wave_height = 3 | * * * *
2571 x_draw_underwave (struct glyph_string
*s
)
2573 int wave_height
= 3, wave_length
= 2;
2574 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
2575 XRectangle wave_clip
, string_clip
, final_clip
;
2578 dy
= wave_height
- 1;
2580 y0
= s
->ybase
- wave_height
+ 3;
2584 /* Find and set clipping rectangle */
2588 wave_clip
.width
= width
;
2589 wave_clip
.height
= wave_height
;
2590 get_glyph_string_clip_rect (s
, &string_clip
);
2592 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
2595 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
2597 /* Draw the waves */
2599 x1
= x0
- (x0
% dx
);
2609 if (INT_MAX
- dx
< xmax
)
2614 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
2616 x2
+= dx
, y2
= y0
+ odd
*dy
;
2620 /* Restore previous clipping rectangle(s) */
2621 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
2625 /* Draw glyph string S. */
2628 x_draw_glyph_string (struct glyph_string
*s
)
2630 bool relief_drawn_p
= 0;
2632 /* If S draws into the background of its successors, draw the
2633 background of the successors first so that S can draw into it.
2634 This makes S->next use XDrawString instead of XDrawImageString. */
2635 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2638 struct glyph_string
*next
;
2640 for (width
= 0, next
= s
->next
;
2641 next
&& width
< s
->right_overhang
;
2642 width
+= next
->width
, next
= next
->next
)
2643 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2645 x_set_glyph_string_gc (next
);
2646 x_set_glyph_string_clipping (next
);
2647 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2648 x_draw_stretch_glyph_string (next
);
2650 x_draw_glyph_string_background (next
, 1);
2651 next
->num_clips
= 0;
2655 /* Set up S->gc, set clipping and draw S. */
2656 x_set_glyph_string_gc (s
);
2658 /* Draw relief (if any) in advance for char/composition so that the
2659 glyph string can be drawn over it. */
2660 if (!s
->for_overlaps
2661 && s
->face
->box
!= FACE_NO_BOX
2662 && (s
->first_glyph
->type
== CHAR_GLYPH
2663 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2666 x_set_glyph_string_clipping (s
);
2667 x_draw_glyph_string_background (s
, 1);
2668 x_draw_glyph_string_box (s
);
2669 x_set_glyph_string_clipping (s
);
2672 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2674 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2675 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2676 /* We must clip just this glyph. left_overhang part has already
2677 drawn when s->prev was drawn, and right_overhang part will be
2678 drawn later when s->next is drawn. */
2679 x_set_glyph_string_clipping_exactly (s
, s
);
2681 x_set_glyph_string_clipping (s
);
2683 switch (s
->first_glyph
->type
)
2686 x_draw_image_glyph_string (s
);
2690 x_draw_stretch_glyph_string (s
);
2694 if (s
->for_overlaps
)
2695 s
->background_filled_p
= 1;
2697 x_draw_glyph_string_background (s
, 0);
2698 x_draw_glyph_string_foreground (s
);
2701 case COMPOSITE_GLYPH
:
2702 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2703 && ! s
->first_glyph
->u
.cmp
.automatic
))
2704 s
->background_filled_p
= 1;
2706 x_draw_glyph_string_background (s
, 1);
2707 x_draw_composite_glyph_string_foreground (s
);
2710 case GLYPHLESS_GLYPH
:
2711 if (s
->for_overlaps
)
2712 s
->background_filled_p
= 1;
2714 x_draw_glyph_string_background (s
, 1);
2715 x_draw_glyphless_glyph_string_foreground (s
);
2722 if (!s
->for_overlaps
)
2724 /* Draw underline. */
2725 if (s
->face
->underline_p
)
2727 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2729 if (s
->face
->underline_defaulted_p
)
2730 x_draw_underwave (s
);
2734 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2735 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2736 x_draw_underwave (s
);
2737 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2740 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2742 unsigned long thickness
, position
;
2745 if (s
->prev
&& s
->prev
->face
->underline_p
2746 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2748 /* We use the same underline style as the previous one. */
2749 thickness
= s
->prev
->underline_thickness
;
2750 position
= s
->prev
->underline_position
;
2754 /* Get the underline thickness. Default is 1 pixel. */
2755 if (s
->font
&& s
->font
->underline_thickness
> 0)
2756 thickness
= s
->font
->underline_thickness
;
2759 if (x_underline_at_descent_line
)
2760 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2763 /* Get the underline position. This is the recommended
2764 vertical offset in pixels from the baseline to the top of
2765 the underline. This is a signed value according to the
2766 specs, and its default is
2768 ROUND ((maximum descent) / 2), with
2769 ROUND(x) = floor (x + 0.5) */
2771 if (x_use_underline_position_properties
2772 && s
->font
&& s
->font
->underline_position
>= 0)
2773 position
= s
->font
->underline_position
;
2775 position
= (s
->font
->descent
+ 1) / 2;
2777 position
= underline_minimum_offset
;
2779 position
= max (position
, underline_minimum_offset
);
2781 /* Check the sanity of thickness and position. We should
2782 avoid drawing underline out of the current line area. */
2783 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2784 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2785 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2786 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2787 s
->underline_thickness
= thickness
;
2788 s
->underline_position
= position
;
2789 y
= s
->ybase
+ position
;
2790 if (s
->face
->underline_defaulted_p
)
2791 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2792 s
->x
, y
, s
->width
, thickness
);
2796 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2797 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2798 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2799 s
->x
, y
, s
->width
, thickness
);
2800 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2804 /* Draw overline. */
2805 if (s
->face
->overline_p
)
2807 unsigned long dy
= 0, h
= 1;
2809 if (s
->face
->overline_color_defaulted_p
)
2810 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2815 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2816 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2817 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2819 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2823 /* Draw strike-through. */
2824 if (s
->face
->strike_through_p
)
2826 unsigned long h
= 1;
2827 unsigned long dy
= (s
->height
- h
) / 2;
2829 if (s
->face
->strike_through_color_defaulted_p
)
2830 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2835 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2836 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2837 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2839 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2843 /* Draw relief if not yet drawn. */
2844 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2845 x_draw_glyph_string_box (s
);
2849 struct glyph_string
*prev
;
2851 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2852 if (prev
->hl
!= s
->hl
2853 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2855 /* As prev was drawn while clipped to its own area, we
2856 must draw the right_overhang part using s->hl now. */
2857 enum draw_glyphs_face save
= prev
->hl
;
2860 x_set_glyph_string_gc (prev
);
2861 x_set_glyph_string_clipping_exactly (s
, prev
);
2862 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2863 x_draw_glyph_string_foreground (prev
);
2865 x_draw_composite_glyph_string_foreground (prev
);
2866 XSetClipMask (prev
->display
, prev
->gc
, None
);
2868 prev
->num_clips
= 0;
2874 struct glyph_string
*next
;
2876 for (next
= s
->next
; next
; next
= next
->next
)
2877 if (next
->hl
!= s
->hl
2878 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2880 /* As next will be drawn while clipped to its own area,
2881 we must draw the left_overhang part using s->hl now. */
2882 enum draw_glyphs_face save
= next
->hl
;
2885 x_set_glyph_string_gc (next
);
2886 x_set_glyph_string_clipping_exactly (s
, next
);
2887 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2888 x_draw_glyph_string_foreground (next
);
2890 x_draw_composite_glyph_string_foreground (next
);
2891 XSetClipMask (next
->display
, next
->gc
, None
);
2893 next
->num_clips
= 0;
2894 next
->clip_head
= s
->next
;
2899 /* Reset clipping. */
2900 XSetClipMask (s
->display
, s
->gc
, None
);
2904 /* Shift display to make room for inserted glyphs. */
2907 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2909 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2910 f
->output_data
.x
->normal_gc
,
2911 x
, y
, width
, height
,
2915 /* Delete N glyphs at the nominal cursor position. Not implemented
2919 x_delete_glyphs (struct frame
*f
, register int n
)
2925 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2926 If they are <= 0, this is probably an error. */
2929 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
)
2931 eassert (width
> 0 && height
> 0);
2932 XClearArea (dpy
, window
, x
, y
, width
, height
, False
);
2936 /* Clear an entire frame. */
2939 x_clear_frame (struct frame
*f
)
2941 /* Clearing the frame will erase any cursor, so mark them all as no
2943 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2947 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2949 /* We have to clear the scroll bars. If we have changed colors or
2950 something like that, then they should be notified. */
2951 x_scroll_bar_clear (f
);
2953 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2954 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2955 redisplay, do it here. */
2956 if (FRAME_GTK_WIDGET (f
))
2957 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2960 XFlush (FRAME_X_DISPLAY (f
));
2967 /* Invert the middle quarter of the frame for .15 sec. */
2970 XTflash (struct frame
*f
)
2976 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
2977 when the scroll bars and the edit widget share the same X window. */
2978 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
2980 cairo_t
*cr
= gdk_cairo_create (window
);
2981 cairo_set_source_rgb (cr
, 1, 1, 1);
2982 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
2983 #define XFillRectangle(d, win, gc, x, y, w, h) \
2985 cairo_rectangle (cr, x, y, w, h); \
2989 #else /* ! HAVE_GTK3 */
2992 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
2993 ^ FRAME_BACKGROUND_PIXEL (f
));
2994 vals
.function
= GDK_XOR
;
2995 gc
= gdk_gc_new_with_values (window
,
2996 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
2997 #define XFillRectangle(d, win, gc, x, y, w, h) \
2998 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
2999 #endif /* ! HAVE_GTK3 */
3000 #else /* ! USE_GTK */
3003 /* Create a GC that will use the GXxor function to flip foreground
3004 pixels into background pixels. */
3008 values
.function
= GXxor
;
3009 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3010 ^ FRAME_BACKGROUND_PIXEL (f
));
3012 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3013 GCFunction
| GCForeground
, &values
);
3017 /* Get the height not including a menu bar widget. */
3018 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3019 /* Height of each line to flash. */
3020 int flash_height
= FRAME_LINE_HEIGHT (f
);
3021 /* These will be the left and right margins of the rectangles. */
3022 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3023 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3027 /* Don't flash the area between a scroll bar and the frame
3028 edge it is next to. */
3029 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3031 case vertical_scroll_bar_left
:
3032 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3035 case vertical_scroll_bar_right
:
3036 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3043 width
= flash_right
- flash_left
;
3045 /* If window is tall, flash top and bottom line. */
3046 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3048 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3050 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3051 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3052 width
, flash_height
);
3053 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3055 (height
- flash_height
3056 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3057 width
, flash_height
);
3061 /* If it is short, flash it all. */
3062 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3063 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3064 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3069 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
3070 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
3072 /* Keep waiting until past the time wakeup or any input gets
3074 while (! detect_input_pending ())
3076 struct timespec current
= current_timespec ();
3077 struct timespec timeout
;
3079 /* Break if result would not be positive. */
3080 if (timespec_cmp (wakeup
, current
) <= 0)
3083 /* How long `select' should wait. */
3084 timeout
= make_timespec (0, 10 * 1000 * 1000);
3086 /* Try to wait that long--but we might wake up sooner. */
3087 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3091 /* If window is tall, flash top and bottom line. */
3092 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3094 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3096 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3097 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3098 width
, flash_height
);
3099 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3101 (height
- flash_height
3102 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3103 width
, flash_height
);
3106 /* If it is short, flash it all. */
3107 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3108 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3109 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3115 g_object_unref (G_OBJECT (gc
));
3117 #undef XFillRectangle
3119 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3130 XTtoggle_invisible_pointer (struct frame
*f
, int invisible
)
3135 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3136 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3137 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
);
3140 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3141 f
->output_data
.x
->current_cursor
);
3142 f
->pointer_invisible
= invisible
;
3147 /* Make audible bell. */
3150 XTring_bell (struct frame
*f
)
3152 if (FRAME_X_DISPLAY (f
))
3160 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
3162 XBell (FRAME_X_DISPLAY (f
), 0);
3164 XFlush (FRAME_X_DISPLAY (f
));
3170 /***********************************************************************
3172 ***********************************************************************/
3174 /* Perform an insert-lines or delete-lines operation, inserting N
3175 lines or deleting -N lines at vertical position VPOS. */
3178 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3184 /* Scroll part of the display as described by RUN. */
3187 x_scroll_run (struct window
*w
, struct run
*run
)
3189 struct frame
*f
= XFRAME (w
->frame
);
3190 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3192 /* Get frame-relative bounding box of the text display area of W,
3193 without mode lines. Include in this box the left and right
3195 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
3197 #ifdef USE_TOOLKIT_SCROLL_BARS
3198 /* If the fringe is adjacent to the left (right) scroll bar of a
3199 leftmost (rightmost, respectively) window, then extend its
3200 background to the gap between the fringe and the bar. */
3201 if ((WINDOW_LEFTMOST_P (w
)
3202 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
3203 || (WINDOW_RIGHTMOST_P (w
)
3204 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
3206 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3210 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
3211 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
3212 * FRAME_COLUMN_WIDTH (f
));
3214 if (bar_area_x
+ bar_area_width
== x
)
3216 x
= bar_area_x
+ sb_width
;
3217 width
+= bar_area_width
- sb_width
;
3219 else if (x
+ width
== bar_area_x
)
3220 width
+= bar_area_width
- sb_width
;
3225 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3226 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3227 bottom_y
= y
+ height
;
3231 /* Scrolling up. Make sure we don't copy part of the mode
3232 line at the bottom. */
3233 if (from_y
+ run
->height
> bottom_y
)
3234 height
= bottom_y
- from_y
;
3236 height
= run
->height
;
3240 /* Scrolling down. Make sure we don't copy over the mode line.
3242 if (to_y
+ run
->height
> bottom_y
)
3243 height
= bottom_y
- to_y
;
3245 height
= run
->height
;
3250 /* Cursor off. Will be switched on again in x_update_window_end. */
3253 XCopyArea (FRAME_X_DISPLAY (f
),
3254 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3255 f
->output_data
.x
->normal_gc
,
3265 /***********************************************************************
3267 ***********************************************************************/
3271 frame_highlight (struct frame
*f
)
3273 /* We used to only do this if Vx_no_window_manager was non-nil, but
3274 the ICCCM (section 4.1.6) says that the window's border pixmap
3275 and border pixel are window attributes which are "private to the
3276 client", so we can always change it to whatever we want. */
3278 /* I recently started to get errors in this XSetWindowBorder, depending on
3279 the window-manager in use, tho something more is at play since I've been
3280 using that same window-manager binary for ever. Let's not crash just
3281 because of this (bug#9310). */
3282 x_catch_errors (FRAME_X_DISPLAY (f
));
3283 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3284 f
->output_data
.x
->border_pixel
);
3285 x_uncatch_errors ();
3287 x_update_cursor (f
, 1);
3288 x_set_frame_alpha (f
);
3292 frame_unhighlight (struct frame
*f
)
3294 /* We used to only do this if Vx_no_window_manager was non-nil, but
3295 the ICCCM (section 4.1.6) says that the window's border pixmap
3296 and border pixel are window attributes which are "private to the
3297 client", so we can always change it to whatever we want. */
3299 /* Same as above for XSetWindowBorder (bug#9310). */
3300 x_catch_errors (FRAME_X_DISPLAY (f
));
3301 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3302 f
->output_data
.x
->border_tile
);
3303 x_uncatch_errors ();
3305 x_update_cursor (f
, 1);
3306 x_set_frame_alpha (f
);
3309 /* The focus has changed. Update the frames as necessary to reflect
3310 the new situation. Note that we can't change the selected frame
3311 here, because the Lisp code we are interrupting might become confused.
3312 Each event gets marked with the frame in which it occurred, so the
3313 Lisp code can tell when the switch took place by examining the events. */
3316 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3318 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3320 if (frame
!= dpyinfo
->x_focus_frame
)
3322 /* Set this before calling other routines, so that they see
3323 the correct value of x_focus_frame. */
3324 dpyinfo
->x_focus_frame
= frame
;
3326 if (old_focus
&& old_focus
->auto_lower
)
3327 x_lower_frame (old_focus
);
3329 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3330 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3332 pending_autoraise_frame
= 0;
3335 x_frame_rehighlight (dpyinfo
);
3338 /* Handle FocusIn and FocusOut state changes for FRAME.
3339 If FRAME has focus and there exists more than one frame, puts
3340 a FOCUS_IN_EVENT into *BUFP. */
3343 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3345 if (type
== FocusIn
)
3347 if (dpyinfo
->x_focus_event_frame
!= frame
)
3349 x_new_focus_frame (dpyinfo
, frame
);
3350 dpyinfo
->x_focus_event_frame
= frame
;
3352 /* Don't stop displaying the initial startup message
3353 for a switch-frame event we don't need. */
3354 /* When run as a daemon, Vterminal_frame is always NIL. */
3355 bufp
->arg
= (((NILP (Vterminal_frame
) || EQ (Fdaemonp (), Qt
))
3356 && CONSP (Vframe_list
)
3357 && !NILP (XCDR (Vframe_list
)))
3359 bufp
->kind
= FOCUS_IN_EVENT
;
3360 XSETFRAME (bufp
->frame_or_window
, frame
);
3363 frame
->output_data
.x
->focus_state
|= state
;
3366 if (FRAME_XIC (frame
))
3367 XSetICFocus (FRAME_XIC (frame
));
3370 else if (type
== FocusOut
)
3372 frame
->output_data
.x
->focus_state
&= ~state
;
3374 if (dpyinfo
->x_focus_event_frame
== frame
)
3376 dpyinfo
->x_focus_event_frame
= 0;
3377 x_new_focus_frame (dpyinfo
, 0);
3379 bufp
->kind
= FOCUS_OUT_EVENT
;
3380 XSETFRAME (bufp
->frame_or_window
, frame
);
3384 if (FRAME_XIC (frame
))
3385 XUnsetICFocus (FRAME_XIC (frame
));
3387 if (frame
->pointer_invisible
)
3388 XTtoggle_invisible_pointer (frame
, 0);
3392 /* The focus may have changed. Figure out if it is a real focus change,
3393 by checking both FocusIn/Out and Enter/LeaveNotify events.
3395 Returns FOCUS_IN_EVENT event in *BUFP. */
3398 x_detect_focus_change (struct x_display_info
*dpyinfo
, XEvent
*event
, struct input_event
*bufp
)
3400 struct frame
*frame
;
3402 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3406 switch (event
->type
)
3411 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3413 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3415 if (event
->xcrossing
.detail
!= NotifyInferior
3416 && event
->xcrossing
.focus
3417 && ! (focus_state
& FOCUS_EXPLICIT
))
3418 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3420 dpyinfo
, frame
, bufp
);
3426 x_focus_changed (event
->type
,
3427 (event
->xfocus
.detail
== NotifyPointer
?
3428 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3429 dpyinfo
, frame
, bufp
);
3433 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3435 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3436 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3437 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3444 #if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
3445 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3448 x_mouse_leave (struct x_display_info
*dpyinfo
)
3450 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3454 /* The focus has changed, or we have redirected a frame's focus to
3455 another frame (this happens when a frame uses a surrogate
3456 mini-buffer frame). Shift the highlight as appropriate.
3458 The FRAME argument doesn't necessarily have anything to do with which
3459 frame is being highlighted or un-highlighted; we only use it to find
3460 the appropriate X display info. */
3463 XTframe_rehighlight (struct frame
*frame
)
3465 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3469 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3471 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3473 if (dpyinfo
->x_focus_frame
)
3475 dpyinfo
->x_highlight_frame
3476 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3477 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3478 : dpyinfo
->x_focus_frame
);
3479 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3481 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
3482 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3486 dpyinfo
->x_highlight_frame
= 0;
3488 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3491 frame_unhighlight (old_highlight
);
3492 if (dpyinfo
->x_highlight_frame
)
3493 frame_highlight (dpyinfo
->x_highlight_frame
);
3499 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3501 /* Initialize mode_switch_bit and modifier_meaning. */
3503 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3505 int min_code
, max_code
;
3508 XModifierKeymap
*mods
;
3510 dpyinfo
->meta_mod_mask
= 0;
3511 dpyinfo
->shift_lock_mask
= 0;
3512 dpyinfo
->alt_mod_mask
= 0;
3513 dpyinfo
->super_mod_mask
= 0;
3514 dpyinfo
->hyper_mod_mask
= 0;
3516 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3518 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3519 min_code
, max_code
- min_code
+ 1,
3521 mods
= XGetModifierMapping (dpyinfo
->display
);
3523 /* Scan the modifier table to see which modifier bits the Meta and
3524 Alt keysyms are on. */
3526 int row
, col
; /* The row and column in the modifier table. */
3527 int found_alt_or_meta
;
3529 for (row
= 3; row
< 8; row
++)
3531 found_alt_or_meta
= 0;
3532 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3534 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3536 /* Zeroes are used for filler. Skip them. */
3540 /* Are any of this keycode's keysyms a meta key? */
3544 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3546 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3552 found_alt_or_meta
= 1;
3553 dpyinfo
->meta_mod_mask
|= (1 << row
);
3558 found_alt_or_meta
= 1;
3559 dpyinfo
->alt_mod_mask
|= (1 << row
);
3564 if (!found_alt_or_meta
)
3565 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3566 code_col
= syms_per_code
;
3567 col
= mods
->max_keypermod
;
3572 if (!found_alt_or_meta
)
3573 dpyinfo
->super_mod_mask
|= (1 << row
);
3574 code_col
= syms_per_code
;
3575 col
= mods
->max_keypermod
;
3579 /* Ignore this if it's not on the lock modifier. */
3580 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3581 dpyinfo
->shift_lock_mask
= LockMask
;
3582 code_col
= syms_per_code
;
3583 col
= mods
->max_keypermod
;
3592 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3593 if (! dpyinfo
->meta_mod_mask
)
3595 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3596 dpyinfo
->alt_mod_mask
= 0;
3599 /* If some keys are both alt and meta,
3600 make them just meta, not alt. */
3601 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3603 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3607 XFreeModifiermap (mods
);
3610 /* Convert between the modifier bits X uses and the modifier bits
3614 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
3616 int mod_meta
= meta_modifier
;
3617 int mod_alt
= alt_modifier
;
3618 int mod_hyper
= hyper_modifier
;
3619 int mod_super
= super_modifier
;
3622 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3623 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
3624 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3625 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
3626 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3627 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
3628 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3629 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
3631 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3632 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3633 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3634 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3635 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3636 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3640 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
3642 EMACS_INT mod_meta
= meta_modifier
;
3643 EMACS_INT mod_alt
= alt_modifier
;
3644 EMACS_INT mod_hyper
= hyper_modifier
;
3645 EMACS_INT mod_super
= super_modifier
;
3649 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3650 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
3651 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3652 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
3653 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3654 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
3655 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3656 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
3659 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3660 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3661 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3662 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3663 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3664 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3667 /* Convert a keysym to its name. */
3670 x_get_keysym_name (int keysym
)
3675 value
= XKeysymToString (keysym
);
3683 /* Mouse clicks and mouse movement. Rah. */
3685 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3687 If the event is a button press, then note that we have grabbed
3691 construct_mouse_click (struct input_event
*result
, XButtonEvent
*event
, struct frame
*f
)
3693 /* Make the event type NO_EVENT; we'll change that when we decide
3695 result
->kind
= MOUSE_CLICK_EVENT
;
3696 result
->code
= event
->button
- Button1
;
3697 result
->timestamp
= event
->time
;
3698 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3700 | (event
->type
== ButtonRelease
3704 XSETINT (result
->x
, event
->x
);
3705 XSETINT (result
->y
, event
->y
);
3706 XSETFRAME (result
->frame_or_window
, f
);
3711 /* Function to report a mouse movement to the mainstream Emacs code.
3712 The input handler calls this.
3714 We have received a mouse movement event, which is given in *event.
3715 If the mouse is over a different glyph than it was last time, tell
3716 the mainstream emacs code by setting mouse_moved. If not, ask for
3717 another motion event, so we can check again the next time it moves. */
3719 static XMotionEvent last_mouse_motion_event
;
3720 static Lisp_Object last_mouse_motion_frame
;
3723 note_mouse_movement (struct frame
*frame
, XMotionEvent
*event
)
3725 last_mouse_movement_time
= event
->time
;
3726 last_mouse_motion_event
= *event
;
3727 XSETFRAME (last_mouse_motion_frame
, frame
);
3729 if (!FRAME_X_OUTPUT (frame
))
3732 if (event
->window
!= FRAME_X_WINDOW (frame
))
3734 frame
->mouse_moved
= 1;
3735 last_mouse_scroll_bar
= Qnil
;
3736 note_mouse_highlight (frame
, -1, -1);
3737 last_mouse_glyph_frame
= 0;
3742 /* Has the mouse moved off the glyph it was on at the last sighting? */
3743 if (frame
!= last_mouse_glyph_frame
3744 || event
->x
< last_mouse_glyph
.x
3745 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3746 || event
->y
< last_mouse_glyph
.y
3747 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3749 frame
->mouse_moved
= 1;
3750 last_mouse_scroll_bar
= Qnil
;
3751 note_mouse_highlight (frame
, event
->x
, event
->y
);
3752 /* Remember which glyph we're now on. */
3753 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3754 last_mouse_glyph_frame
= frame
;
3762 /************************************************************************
3764 ************************************************************************/
3767 redo_mouse_highlight (void)
3769 if (!NILP (last_mouse_motion_frame
)
3770 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3771 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3772 last_mouse_motion_event
.x
,
3773 last_mouse_motion_event
.y
);
3778 /* Return the current position of the mouse.
3779 *FP should be a frame which indicates which display to ask about.
3781 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3782 and *PART to the frame, window, and scroll bar part that the mouse
3783 is over. Set *X and *Y to the portion and whole of the mouse's
3784 position on the scroll bar.
3786 If the mouse movement started elsewhere, set *FP to the frame the
3787 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3790 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
3791 was at this position.
3793 Don't store anything if we don't have a valid set of values to report.
3795 This clears the mouse_moved flag, so we can wait for the next mouse
3799 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3800 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3807 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3808 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
3814 Window dummy_window
;
3817 Lisp_Object frame
, tail
;
3819 /* Clear the mouse-moved flag for every frame on this display. */
3820 FOR_EACH_FRAME (tail
, frame
)
3821 if (FRAME_X_P (XFRAME (frame
))
3822 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3823 XFRAME (frame
)->mouse_moved
= 0;
3825 last_mouse_scroll_bar
= Qnil
;
3827 /* Figure out which root window we're on. */
3828 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3829 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3831 /* The root window which contains the pointer. */
3834 /* Trash which we can't trust if the pointer is on
3835 a different screen. */
3838 /* The position on that root window. */
3841 /* More trash we can't trust. */
3844 /* Modifier keys and pointer buttons, about which
3846 (unsigned int *) &dummy
);
3848 /* Now we have a position on the root; find the innermost window
3849 containing the pointer. */
3853 int parent_x
= 0, parent_y
= 0;
3857 /* XTranslateCoordinates can get errors if the window
3858 structure is changing at the same time this function
3859 is running. So at least we must not crash from them. */
3861 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3863 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3864 && FRAME_LIVE_P (last_mouse_frame
))
3866 /* If mouse was grabbed on a frame, give coords for that frame
3867 even if the mouse is now outside it. */
3868 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3870 /* From-window, to-window. */
3871 root
, FRAME_X_WINDOW (last_mouse_frame
),
3873 /* From-position, to-position. */
3874 root_x
, root_y
, &win_x
, &win_y
,
3878 f1
= last_mouse_frame
;
3884 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3886 /* From-window, to-window. */
3889 /* From-position, to-position. */
3890 root_x
, root_y
, &win_x
, &win_y
,
3895 if (child
== None
|| child
== win
)
3898 /* We don't wan't to know the innermost window. We
3899 want the edit window. For non-Gtk+ the innermost
3900 window is the edit window. For Gtk+ it might not
3901 be. It might be the tool bar for example. */
3902 if (x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
))
3910 /* Now we know that:
3911 win is the innermost window containing the pointer
3912 (XTC says it has no child containing the pointer),
3913 win_x and win_y are the pointer's position in it
3914 (XTC did this the last time through), and
3915 parent_x and parent_y are the pointer's position in win's parent.
3916 (They are what win_x and win_y were when win was child.
3917 If win is the root window, it has no parent, and
3918 parent_{x,y} are invalid, but that's okay, because we'll
3919 never use them in that case.) */
3922 /* We don't wan't to know the innermost window. We
3923 want the edit window. */
3924 f1
= x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3926 /* Is win one of our frames? */
3927 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3930 #ifdef USE_X_TOOLKIT
3931 /* If we end up with the menu bar window, say it's not
3934 && f1
->output_data
.x
->menubar_widget
3935 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3937 #endif /* USE_X_TOOLKIT */
3940 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3943 x_uncatch_errors ();
3945 /* If not, is it one of our scroll bars? */
3948 struct scroll_bar
*bar
;
3950 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3954 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3960 if (f1
== 0 && insist
> 0)
3961 f1
= SELECTED_FRAME ();
3965 /* Ok, we found a frame. Store all the values.
3966 last_mouse_glyph is a rectangle used to reduce the
3967 generation of mouse events. To not miss any motion
3968 events, we must divide the frame into rectangles of the
3969 size of the smallest character that could be displayed
3970 on it, i.e. into the same rectangles that matrices on
3971 the frame are divided into. */
3973 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3974 last_mouse_glyph_frame
= f1
;
3979 XSETINT (*x
, win_x
);
3980 XSETINT (*y
, win_y
);
3981 *timestamp
= last_mouse_movement_time
;
3991 /***********************************************************************
3993 ***********************************************************************/
3995 /* Scroll bar support. */
3997 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3999 This can be called in GC, so we have to make sure to strip off mark
4002 static struct scroll_bar
*
4003 x_window_to_scroll_bar (Display
*display
, Window window_id
)
4005 Lisp_Object tail
, frame
;
4007 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4008 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4009 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4011 FOR_EACH_FRAME (tail
, frame
)
4013 Lisp_Object bar
, condemned
;
4015 if (! FRAME_X_P (XFRAME (frame
)))
4018 /* Scan this frame's scroll bar list for a scroll bar with the
4020 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4021 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4022 /* This trick allows us to search both the ordinary and
4023 condemned scroll bar lists with one loop. */
4024 ! NILP (bar
) || (bar
= condemned
,
4027 bar
= XSCROLL_BAR (bar
)->next
)
4028 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4029 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4030 return XSCROLL_BAR (bar
);
4037 #if defined USE_LUCID
4039 /* Return the Lucid menu bar WINDOW is part of. Return null
4040 if WINDOW is not part of a menu bar. */
4043 x_window_to_menu_bar (Window window
)
4045 Lisp_Object tail
, frame
;
4047 FOR_EACH_FRAME (tail
, frame
)
4048 if (FRAME_X_P (XFRAME (frame
)))
4050 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4052 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4058 #endif /* USE_LUCID */
4061 /************************************************************************
4063 ************************************************************************/
4065 #ifdef USE_TOOLKIT_SCROLL_BARS
4067 static void x_scroll_bar_to_input_event (XEvent
*, struct input_event
*);
4068 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
4069 static void x_create_toolkit_scroll_bar (struct frame
*,
4070 struct scroll_bar
*);
4071 static void x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*,
4075 /* Lisp window being scrolled. Set when starting to interact with
4076 a toolkit scroll bar, reset to nil when ending the interaction. */
4078 static Lisp_Object window_being_scrolled
;
4080 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4081 that movements of 1/20 of the screen size are mapped to up/down. */
4084 /* Id of action hook installed for scroll bars. */
4086 static XtActionHookId action_hook_id
;
4088 static Boolean xaw3d_arrow_scroll
;
4090 /* Whether the drag scrolling maintains the mouse at the top of the
4091 thumb. If not, resizing the thumb needs to be done more carefully
4092 to avoid jerkiness. */
4094 static Boolean xaw3d_pick_top
;
4096 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4097 bars are used.. The hook is responsible for detecting when
4098 the user ends an interaction with the scroll bar, and generates
4099 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4102 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4103 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4106 const char *end_action
;
4109 scroll_bar_p
= XmIsScrollBar (widget
);
4110 end_action
= "Release";
4111 #else /* !USE_MOTIF i.e. use Xaw */
4112 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4113 end_action
= "EndScroll";
4114 #endif /* USE_MOTIF */
4117 && strcmp (action_name
, end_action
) == 0
4118 && WINDOWP (window_being_scrolled
))
4121 struct scroll_bar
*bar
;
4123 x_send_scroll_bar_event (window_being_scrolled
,
4124 scroll_bar_end_scroll
, 0, 0);
4125 w
= XWINDOW (window_being_scrolled
);
4126 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4128 if (bar
->dragging
!= -1)
4131 /* The thumb size is incorrect while dragging: fix it. */
4132 set_vertical_scroll_bar (w
);
4134 window_being_scrolled
= Qnil
;
4135 #if defined (USE_LUCID)
4136 bar
->last_seen_part
= scroll_bar_nowhere
;
4138 /* Xt timeouts no longer needed. */
4139 toolkit_scroll_bar_interaction
= 0;
4142 #endif /* not USE_GTK */
4144 /* A vector of windows used for communication between
4145 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4147 static struct window
**scroll_bar_windows
;
4148 static ptrdiff_t scroll_bar_windows_size
;
4151 /* Send a client message with message type Xatom_Scrollbar for a
4152 scroll action to the frame of WINDOW. PART is a value identifying
4153 the part of the scroll bar that was clicked on. PORTION is the
4154 amount to scroll of a whole of WHOLE. */
4157 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4160 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4161 struct window
*w
= XWINDOW (window
);
4162 struct frame
*f
= XFRAME (w
->frame
);
4167 /* Construct a ClientMessage event to send to the frame. */
4168 ev
->type
= ClientMessage
;
4169 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4170 ev
->display
= FRAME_X_DISPLAY (f
);
4171 ev
->window
= FRAME_X_WINDOW (f
);
4174 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4175 not enough to store a pointer or Lisp_Object on a 64 bit system.
4176 So, store the window in scroll_bar_windows and pass the index
4177 into that array in the event. */
4178 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4179 if (scroll_bar_windows
[i
] == NULL
)
4182 if (i
== scroll_bar_windows_size
)
4184 ptrdiff_t old_nbytes
=
4185 scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4187 enum { XClientMessageEvent_MAX
= 0x7fffffff };
4188 scroll_bar_windows
=
4189 xpalloc (scroll_bar_windows
, &scroll_bar_windows_size
, 1,
4190 XClientMessageEvent_MAX
, sizeof *scroll_bar_windows
);
4191 nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4192 memset (&scroll_bar_windows
[i
], 0, nbytes
- old_nbytes
);
4195 scroll_bar_windows
[i
] = w
;
4196 ev
->data
.l
[0] = (long) i
;
4197 ev
->data
.l
[1] = (long) part
;
4198 ev
->data
.l
[2] = (long) 0;
4199 ev
->data
.l
[3] = (long) portion
;
4200 ev
->data
.l
[4] = (long) whole
;
4202 /* Make Xt timeouts work while the scroll bar is active. */
4203 #ifdef USE_X_TOOLKIT
4204 toolkit_scroll_bar_interaction
= 1;
4205 x_activate_timeout_atimer ();
4208 /* Setting the event mask to zero means that the message will
4209 be sent to the client that created the window, and if that
4210 window no longer exists, no event will be sent. */
4211 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4216 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4220 x_scroll_bar_to_input_event (XEvent
*event
, struct input_event
*ievent
)
4222 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4226 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4227 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4229 XSETWINDOW (window
, w
);
4231 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4232 ievent
->frame_or_window
= window
;
4235 ievent
->timestamp
= CurrentTime
;
4238 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4240 ievent
->part
= ev
->data
.l
[1];
4241 ievent
->code
= ev
->data
.l
[2];
4242 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4243 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4244 ievent
->modifiers
= 0;
4250 /* Minimum and maximum values used for Motif scroll bars. */
4252 #define XM_SB_MAX 10000000
4255 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4256 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4257 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4260 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4262 struct scroll_bar
*bar
= client_data
;
4263 XmScrollBarCallbackStruct
*cs
= call_data
;
4264 int part
= -1, whole
= 0, portion
= 0;
4268 case XmCR_DECREMENT
:
4270 part
= scroll_bar_up_arrow
;
4273 case XmCR_INCREMENT
:
4275 part
= scroll_bar_down_arrow
;
4278 case XmCR_PAGE_DECREMENT
:
4280 part
= scroll_bar_above_handle
;
4283 case XmCR_PAGE_INCREMENT
:
4285 part
= scroll_bar_below_handle
;
4290 part
= scroll_bar_to_top
;
4293 case XmCR_TO_BOTTOM
:
4295 part
= scroll_bar_to_bottom
;
4302 /* Get the slider size. */
4304 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4307 whole
= XM_SB_MAX
- slider_size
;
4308 portion
= min (cs
->value
, whole
);
4309 part
= scroll_bar_handle
;
4310 bar
->dragging
= cs
->value
;
4314 case XmCR_VALUE_CHANGED
:
4320 window_being_scrolled
= bar
->window
;
4321 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4325 #elif defined USE_GTK
4327 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4328 bar widget. DATA is a pointer to the scroll_bar structure. */
4331 xg_scroll_callback (GtkRange
*range
,
4332 GtkScrollType scroll
,
4336 struct scroll_bar
*bar
= user_data
;
4338 int part
= -1, whole
= 0, portion
= 0;
4339 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4340 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4342 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4343 position
= gtk_adjustment_get_value (adj
);
4348 case GTK_SCROLL_JUMP
:
4349 /* Buttons 1 2 or 3 must be grabbed. */
4350 if (FRAME_X_DISPLAY_INFO (f
)->grabbed
!= 0
4351 && FRAME_X_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4353 part
= scroll_bar_handle
;
4354 whole
= gtk_adjustment_get_upper (adj
) -
4355 gtk_adjustment_get_page_size (adj
);
4356 portion
= min ((int)position
, whole
);
4357 bar
->dragging
= portion
;
4360 case GTK_SCROLL_STEP_BACKWARD
:
4361 part
= scroll_bar_up_arrow
;
4364 case GTK_SCROLL_STEP_FORWARD
:
4365 part
= scroll_bar_down_arrow
;
4368 case GTK_SCROLL_PAGE_BACKWARD
:
4369 part
= scroll_bar_above_handle
;
4372 case GTK_SCROLL_PAGE_FORWARD
:
4373 part
= scroll_bar_below_handle
;
4380 window_being_scrolled
= bar
->window
;
4381 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4387 /* Callback for button release. Sets dragging to -1 when dragging is done. */
4390 xg_end_scroll_callback (GtkWidget
*widget
,
4391 GdkEventButton
*event
,
4394 struct scroll_bar
*bar
= user_data
;
4396 if (WINDOWP (window_being_scrolled
))
4398 x_send_scroll_bar_event (window_being_scrolled
,
4399 scroll_bar_end_scroll
, 0, 0);
4400 window_being_scrolled
= Qnil
;
4407 #else /* not USE_GTK and not USE_MOTIF */
4409 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4410 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4411 scroll bar struct. CALL_DATA is a pointer to a float saying where
4415 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4417 struct scroll_bar
*bar
= client_data
;
4418 float *top_addr
= call_data
;
4419 float top
= *top_addr
;
4421 int whole
, portion
, height
;
4422 enum scroll_bar_part part
;
4424 /* Get the size of the thumb, a value between 0 and 1. */
4426 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4430 portion
= shown
< 1 ? top
* whole
: 0;
4432 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
4433 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4434 the bottom, so we force the scrolling whenever we see that we're
4435 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4436 we try to ensure that we always stay two pixels away from the
4438 part
= scroll_bar_down_arrow
;
4440 part
= scroll_bar_handle
;
4442 window_being_scrolled
= bar
->window
;
4443 bar
->dragging
= portion
;
4444 bar
->last_seen_part
= part
;
4445 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4449 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4450 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4451 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4452 the scroll bar. CALL_DATA is an integer specifying the action that
4453 has taken place. Its magnitude is in the range 0..height of the
4454 scroll bar. Negative values mean scroll towards buffer start.
4455 Values < height of scroll bar mean line-wise movement. */
4458 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4460 struct scroll_bar
*bar
= client_data
;
4461 /* The position really is stored cast to a pointer. */
4462 int position
= (intptr_t) call_data
;
4464 enum scroll_bar_part part
;
4466 /* Get the height of the scroll bar. */
4468 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4471 if (eabs (position
) >= height
)
4472 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4474 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4475 it maps line-movement to call_data = max(5, height/20). */
4476 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4477 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4479 part
= scroll_bar_move_ratio
;
4481 window_being_scrolled
= bar
->window
;
4483 bar
->last_seen_part
= part
;
4484 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4487 #endif /* not USE_GTK and not USE_MOTIF */
4489 #define SCROLL_BAR_NAME "verticalScrollBar"
4491 /* Create the widget for scroll bar BAR on frame F. Record the widget
4492 and X window of the scroll bar in BAR. */
4496 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4498 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4501 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4502 G_CALLBACK (xg_end_scroll_callback
),
4507 #else /* not USE_GTK */
4510 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4516 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4517 unsigned long pixel
;
4522 /* Set resources. Create the widget. */
4523 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4524 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4525 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4526 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4527 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4528 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4529 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4531 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4534 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4538 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4541 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4545 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4546 (char *) scroll_bar_name
, av
, ac
);
4548 /* Add one callback for everything that can happen. */
4549 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4551 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4553 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4555 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4557 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4559 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4561 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4564 /* Realize the widget. Only after that is the X window created. */
4565 XtRealizeWidget (widget
);
4567 /* Set the cursor to an arrow. I didn't find a resource to do that.
4568 And I'm wondering why it hasn't an arrow cursor by default. */
4569 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4570 f
->output_data
.x
->nontext_cursor
);
4572 #else /* !USE_MOTIF i.e. use Xaw */
4574 /* Set resources. Create the widget. The background of the
4575 Xaw3d scroll bar widget is a little bit light for my taste.
4576 We don't alter it here to let users change it according
4577 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4578 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4579 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4580 /* For smoother scrolling with Xaw3d -sm */
4581 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4583 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4586 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4590 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4593 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4597 /* Top/bottom shadow colors. */
4599 /* Allocate them, if necessary. */
4600 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4602 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4605 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4606 FRAME_X_COLORMAP (f
),
4607 &pixel
, 1.2, 0x8000))
4609 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4612 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4614 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4617 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4618 FRAME_X_COLORMAP (f
),
4619 &pixel
, 0.6, 0x4000))
4621 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4625 #ifdef XtNbeNiceToColormap
4626 /* Tell the toolkit about them. */
4627 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4628 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4629 /* We tried to allocate a color for the top/bottom shadow, and
4630 failed, so tell Xaw3d to use dithering instead. */
4631 /* But only if we have a small colormap. Xaw3d can allocate nice
4634 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4635 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4639 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4640 be more consistent with other emacs 3d colors, and since Xaw3d is
4641 not good at dealing with allocation failure. */
4643 /* This tells Xaw3d to use real colors instead of dithering for
4645 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4648 /* Specify the colors. */
4649 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4652 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4655 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4658 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4664 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4665 f
->output_data
.x
->edit_widget
, av
, ac
);
4668 char const *initial
= "";
4669 char const *val
= initial
;
4670 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4671 #ifdef XtNarrowScrollbars
4672 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4674 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4675 if (xaw3d_arrow_scroll
|| val
== initial
)
4676 { /* ARROW_SCROLL */
4677 xaw3d_arrow_scroll
= True
;
4678 /* Isn't that just a personal preference ? --Stef */
4679 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4683 /* Define callbacks. */
4684 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4685 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4688 /* Realize the widget. Only after that is the X window created. */
4689 XtRealizeWidget (widget
);
4691 #endif /* !USE_MOTIF */
4693 /* Install an action hook that lets us detect when the user
4694 finishes interacting with a scroll bar. */
4695 if (action_hook_id
== 0)
4696 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4698 /* Remember X window and widget in the scroll bar vector. */
4699 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4700 xwindow
= XtWindow (widget
);
4701 bar
->x_window
= xwindow
;
4705 #endif /* not USE_GTK */
4708 /* Set the thumb size and position of scroll bar BAR. We are currently
4709 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4713 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4715 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4718 #else /* not USE_GTK */
4720 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4723 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4724 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4731 if (scroll_bar_adjust_thumb_portion_p
)
4733 /* We use an estimate of 30 chars per line rather than the real
4734 `portion' value. This has the disadvantage that the thumb size
4735 is not very representative, but it makes our life a lot easier.
4736 Otherwise, we have to constantly adjust the thumb size, which
4737 we can't always do quickly enough: while dragging, the size of
4738 the thumb might prevent the user from dragging the thumb all the
4739 way to the end. but Motif and some versions of Xaw3d don't allow
4740 updating the thumb size while dragging. Also, even if we can update
4741 its size, the update will often happen too late.
4742 If you don't believe it, check out revision 1.650 of xterm.c to see
4743 what hoops we were going through and the still poor behavior we got. */
4744 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4745 /* When the thumb is at the bottom, position == whole.
4746 So we need to increase `whole' to make space for the thumb. */
4754 top
= (float) position
/ whole
;
4755 shown
= (float) portion
/ whole
;
4758 if (bar
->dragging
== -1)
4762 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4763 is the scroll bar's maximum and MIN is the scroll bar's minimum
4765 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
4767 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4768 value
= top
* XM_SB_MAX
;
4769 value
= min (value
, XM_SB_MAX
- size
);
4771 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4773 #else /* !USE_MOTIF i.e. use Xaw */
4779 top
= (float) position
/ whole
;
4780 shown
= (float) portion
/ whole
;
4784 float old_top
, old_shown
;
4786 XtVaGetValues (widget
,
4787 XtNtopOfThumb
, &old_top
,
4788 XtNshown
, &old_shown
,
4792 /* Massage the top+shown values. */
4793 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
4794 top
= max (0, min (1, top
));
4797 #if ! defined (HAVE_XAW3D)
4798 /* With Xaw, 'top' values too closer to 1.0 may
4799 cause the thumb to disappear. Fix that. */
4800 top
= min (top
, 0.99f
);
4802 /* Keep two pixels available for moving the thumb down. */
4803 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
4804 #if ! defined (HAVE_XAW3D)
4805 /* Likewise with too small 'shown'. */
4806 shown
= max (shown
, 0.01f
);
4809 /* If the call to XawScrollbarSetThumb below doesn't seem to
4810 work, check that 'NARROWPROTO' is defined in src/config.h.
4811 If this is not so, most likely you need to fix configure. */
4812 if (top
!= old_top
|| shown
!= old_shown
)
4814 if (bar
->dragging
== -1)
4815 XawScrollbarSetThumb (widget
, top
, shown
);
4818 /* Try to make the scrolling a tad smoother. */
4819 if (!xaw3d_pick_top
)
4820 shown
= min (shown
, old_shown
);
4822 XawScrollbarSetThumb (widget
, top
, shown
);
4826 #endif /* !USE_MOTIF */
4830 #endif /* not USE_GTK */
4832 #endif /* USE_TOOLKIT_SCROLL_BARS */
4836 /************************************************************************
4837 Scroll bars, general
4838 ************************************************************************/
4840 /* Create a scroll bar and return the scroll bar vector for it. W is
4841 the Emacs window on which to create the scroll bar. TOP, LEFT,
4842 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4845 static struct scroll_bar
*
4846 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
4848 struct frame
*f
= XFRAME (w
->frame
);
4849 struct scroll_bar
*bar
4850 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4855 #ifdef USE_TOOLKIT_SCROLL_BARS
4856 x_create_toolkit_scroll_bar (f
, bar
);
4857 #else /* not USE_TOOLKIT_SCROLL_BARS */
4859 XSetWindowAttributes a
;
4863 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4864 if (a
.background_pixel
== -1)
4865 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4867 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4868 | ButtonMotionMask
| PointerMotionHintMask
4870 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4872 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4874 /* Clear the area of W that will serve as a scroll bar. This is
4875 for the case that a window has been split horizontally. In
4876 this case, no clear_frame is generated to reduce flickering. */
4877 if (width
> 0 && height
> 0)
4878 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4879 left
, top
, width
, window_box_height (w
));
4881 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4882 /* Position and size of scroll bar. */
4883 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4885 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4887 /* Border width, depth, class, and visual. */
4894 bar
->x_window
= window
;
4896 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4898 XSETWINDOW (bar
->window
, w
);
4902 bar
->height
= height
;
4906 bar
->fringe_extended_p
= 0;
4907 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
4908 bar
->last_seen_part
= scroll_bar_nowhere
;
4911 /* Add bar to its frame's list of scroll bars. */
4912 bar
->next
= FRAME_SCROLL_BARS (f
);
4914 XSETVECTOR (barobj
, bar
);
4915 fset_scroll_bars (f
, barobj
);
4916 if (!NILP (bar
->next
))
4917 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4919 /* Map the window/widget. */
4920 #ifdef USE_TOOLKIT_SCROLL_BARS
4923 xg_update_scrollbar_pos (f
,
4926 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4927 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4929 #else /* not USE_GTK */
4930 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4931 XtConfigureWidget (scroll_bar
,
4932 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4934 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4935 max (height
, 1), 0);
4936 XtMapWidget (scroll_bar
);
4937 #endif /* not USE_GTK */
4939 #else /* not USE_TOOLKIT_SCROLL_BARS */
4940 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
4941 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4948 #ifndef USE_TOOLKIT_SCROLL_BARS
4950 /* Draw BAR's handle in the proper position.
4952 If the handle is already drawn from START to END, don't bother
4953 redrawing it, unless REBUILD is non-zero; in that case, always
4954 redraw it. (REBUILD is handy for drawing the handle after expose
4957 Normally, we want to constrain the start and end of the handle to
4958 fit inside its rectangle, but if the user is dragging the scroll
4959 bar handle, we want to let them drag it down all the way, so that
4960 the bar's top is as far down as it goes; otherwise, there's no way
4961 to move to the very end of the buffer. */
4964 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
4966 bool dragging
= bar
->dragging
!= -1;
4967 Window w
= bar
->x_window
;
4968 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4969 GC gc
= f
->output_data
.x
->normal_gc
;
4971 /* If the display is already accurate, do nothing. */
4973 && start
== bar
->start
4980 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
4981 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
4982 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4984 /* Make sure the values are reasonable, and try to preserve
4985 the distance between start and end. */
4987 int length
= end
- start
;
4991 else if (start
> top_range
)
4993 end
= start
+ length
;
4997 else if (end
> top_range
&& ! dragging
)
5001 /* Store the adjusted setting in the scroll bar. */
5005 /* Clip the end position, just for display. */
5006 if (end
> top_range
)
5009 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5010 below top positions, to make sure the handle is always at least
5011 that many pixels tall. */
5012 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5014 /* Draw the empty space above the handle. Note that we can't clear
5015 zero-height areas; that means "clear to end of window." */
5017 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5018 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5019 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5020 inside_width
, start
);
5022 /* Change to proper foreground color if one is specified. */
5023 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5024 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5025 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5027 /* Draw the handle itself. */
5028 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5029 /* x, y, width, height */
5030 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5031 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5032 inside_width
, end
- start
);
5034 /* Restore the foreground color of the GC if we changed it above. */
5035 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5036 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5037 FRAME_FOREGROUND_PIXEL (f
));
5039 /* Draw the empty space below the handle. Note that we can't
5040 clear zero-height areas; that means "clear to end of window." */
5041 if (end
< inside_height
)
5042 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5043 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5044 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5045 inside_width
, inside_height
- end
);
5051 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5053 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5057 x_scroll_bar_remove (struct scroll_bar
*bar
)
5059 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5062 #ifdef USE_TOOLKIT_SCROLL_BARS
5064 xg_remove_scroll_bar (f
, bar
->x_window
);
5065 #else /* not USE_GTK */
5066 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5067 #endif /* not USE_GTK */
5069 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5072 /* Dissociate this scroll bar from its window. */
5073 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5079 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5080 that we are displaying PORTION characters out of a total of WHOLE
5081 characters, starting at POSITION. If WINDOW has no scroll bar,
5085 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5087 struct frame
*f
= XFRAME (w
->frame
);
5089 struct scroll_bar
*bar
;
5090 int top
, height
, left
, sb_left
, width
, sb_width
;
5091 int window_y
, window_height
;
5092 #ifdef USE_TOOLKIT_SCROLL_BARS
5093 bool fringe_extended_p
;
5096 /* Get window dimensions. */
5097 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
5099 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5100 height
= window_height
;
5102 /* Compute the left edge of the scroll bar area. */
5103 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5105 /* Compute the width of the scroll bar which might be less than
5106 the width of the area reserved for the scroll bar. */
5107 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5108 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5112 /* Compute the left edge of the scroll bar. */
5113 #ifdef USE_TOOLKIT_SCROLL_BARS
5114 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5115 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5117 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5119 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5120 sb_left
= left
+ width
- sb_width
;
5125 #ifdef USE_TOOLKIT_SCROLL_BARS
5126 fringe_extended_p
= WINDOW_FRINGE_EXTENDED_P (w
);
5129 /* Does the scroll bar exist yet? */
5130 if (NILP (w
->vertical_scroll_bar
))
5132 if (width
> 0 && height
> 0)
5135 #ifdef USE_TOOLKIT_SCROLL_BARS
5136 if (fringe_extended_p
)
5137 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5138 sb_left
, top
, sb_width
, height
);
5141 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5142 left
, top
, width
, height
);
5146 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5150 /* It may just need to be moved and resized. */
5151 unsigned int mask
= 0;
5153 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5157 if (sb_left
!= bar
->left
)
5159 if (top
!= bar
->top
)
5161 if (sb_width
!= bar
->width
)
5163 if (height
!= bar
->height
)
5166 #ifdef USE_TOOLKIT_SCROLL_BARS
5168 /* Move/size the scroll bar widget. */
5169 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5171 /* Since toolkit scroll bars are smaller than the space reserved
5172 for them on the frame, we have to clear "under" them. */
5173 if (width
> 0 && height
> 0)
5175 if (fringe_extended_p
)
5176 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5177 sb_left
, top
, sb_width
, height
);
5179 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5180 left
, top
, width
, height
);
5183 xg_update_scrollbar_pos (f
,
5186 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5187 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5189 #else /* not USE_GTK */
5190 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5191 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5193 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5194 max (height
, 1), 0);
5195 #endif /* not USE_GTK */
5197 #else /* not USE_TOOLKIT_SCROLL_BARS */
5199 /* Clear areas not covered by the scroll bar because of
5200 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5201 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5203 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5204 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
, height
);
5205 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5206 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5207 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
, height
);
5210 /* Clear areas not covered by the scroll bar because it's not as
5211 wide as the area reserved for it. This makes sure a
5212 previous mode line display is cleared after C-x 2 C-x 1, for
5215 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5216 int rest
= area_width
- sb_width
;
5217 if (rest
> 0 && height
> 0)
5219 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5220 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5221 left
+ area_width
- rest
, top
, rest
, height
);
5223 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5224 left
, top
, rest
, height
);
5228 /* Move/size the scroll bar window. */
5233 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5235 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5237 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5241 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5243 /* Remember new settings. */
5244 bar
->left
= sb_left
;
5246 bar
->width
= sb_width
;
5247 bar
->height
= height
;
5252 #ifdef USE_TOOLKIT_SCROLL_BARS
5253 bar
->fringe_extended_p
= fringe_extended_p
;
5255 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5256 #else /* not USE_TOOLKIT_SCROLL_BARS */
5257 /* Set the scroll bar's current state, unless we're currently being
5259 if (bar
->dragging
== -1)
5261 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5264 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5267 int start
= ((double) position
* top_range
) / whole
;
5268 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5269 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5272 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5274 XSETVECTOR (barobj
, bar
);
5275 wset_vertical_scroll_bar (w
, barobj
);
5279 /* The following three hooks are used when we're doing a thorough
5280 redisplay of the frame. We don't explicitly know which scroll bars
5281 are going to be deleted, because keeping track of when windows go
5282 away is a real pain - "Can you say set-window-configuration, boys
5283 and girls?" Instead, we just assert at the beginning of redisplay
5284 that *all* scroll bars are to be removed, and then save a scroll bar
5285 from the fiery pit when we actually redisplay its window. */
5287 /* Arrange for all scroll bars on FRAME to be removed at the next call
5288 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5289 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5292 XTcondemn_scroll_bars (struct frame
*frame
)
5294 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5295 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5298 bar
= FRAME_SCROLL_BARS (frame
);
5299 fset_scroll_bars (frame
, XSCROLL_BAR (bar
)->next
);
5300 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5301 XSCROLL_BAR (bar
)->prev
= Qnil
;
5302 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5303 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5304 fset_condemned_scroll_bars (frame
, bar
);
5309 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5310 Note that WINDOW isn't necessarily condemned at all. */
5313 XTredeem_scroll_bar (struct window
*window
)
5315 struct scroll_bar
*bar
;
5319 /* We can't redeem this window's scroll bar if it doesn't have one. */
5320 if (NILP (window
->vertical_scroll_bar
))
5323 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5325 /* Unlink it from the condemned list. */
5326 f
= XFRAME (WINDOW_FRAME (window
));
5327 if (NILP (bar
->prev
))
5329 /* If the prev pointer is nil, it must be the first in one of
5331 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5332 /* It's not condemned. Everything's fine. */
5334 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5335 window
->vertical_scroll_bar
))
5336 fset_condemned_scroll_bars (f
, bar
->next
);
5338 /* If its prev pointer is nil, it must be at the front of
5339 one or the other! */
5343 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5345 if (! NILP (bar
->next
))
5346 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5348 bar
->next
= FRAME_SCROLL_BARS (f
);
5350 XSETVECTOR (barobj
, bar
);
5351 fset_scroll_bars (f
, barobj
);
5352 if (! NILP (bar
->next
))
5353 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5356 /* Remove all scroll bars on FRAME that haven't been saved since the
5357 last call to `*condemn_scroll_bars_hook'. */
5360 XTjudge_scroll_bars (struct frame
*f
)
5362 Lisp_Object bar
, next
;
5364 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5366 /* Clear out the condemned list now so we won't try to process any
5367 more events on the hapless scroll bars. */
5368 fset_condemned_scroll_bars (f
, Qnil
);
5370 for (; ! NILP (bar
); bar
= next
)
5372 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5374 x_scroll_bar_remove (b
);
5377 b
->next
= b
->prev
= Qnil
;
5380 /* Now there should be no references to the condemned scroll bars,
5381 and they should get garbage-collected. */
5385 #ifndef USE_TOOLKIT_SCROLL_BARS
5386 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5387 is a no-op when using toolkit scroll bars.
5389 This may be called from a signal handler, so we have to ignore GC
5393 x_scroll_bar_expose (struct scroll_bar
*bar
, XEvent
*event
)
5395 Window w
= bar
->x_window
;
5396 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5397 GC gc
= f
->output_data
.x
->normal_gc
;
5398 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5402 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5404 /* Switch to scroll bar foreground color. */
5405 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5406 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5407 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5409 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5410 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5412 /* x, y, width, height */
5414 bar
->width
- 1 - width_trim
- width_trim
,
5417 /* Restore the foreground color of the GC if we changed it above. */
5418 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5419 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5420 FRAME_FOREGROUND_PIXEL (f
));
5425 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5427 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5428 is set to something other than NO_EVENT, it is enqueued.
5430 This may be called from a signal handler, so we have to ignore GC
5435 x_scroll_bar_handle_click (struct scroll_bar
*bar
, XEvent
*event
, struct input_event
*emacs_event
)
5437 if (! WINDOWP (bar
->window
))
5440 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5441 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5442 emacs_event
->modifiers
5443 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5444 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5445 event
->xbutton
.state
)
5446 | (event
->type
== ButtonRelease
5449 emacs_event
->frame_or_window
= bar
->window
;
5450 emacs_event
->arg
= Qnil
;
5451 emacs_event
->timestamp
= event
->xbutton
.time
;
5454 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5455 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5458 if (y
> top_range
) y
= top_range
;
5461 emacs_event
->part
= scroll_bar_above_handle
;
5462 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5463 emacs_event
->part
= scroll_bar_handle
;
5465 emacs_event
->part
= scroll_bar_below_handle
;
5467 #ifndef USE_TOOLKIT_SCROLL_BARS
5468 /* If the user has released the handle, set it to its final position. */
5469 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
5471 int new_start
= y
- bar
->dragging
;
5472 int new_end
= new_start
+ bar
->end
- bar
->start
;
5474 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5479 XSETINT (emacs_event
->x
, y
);
5480 XSETINT (emacs_event
->y
, top_range
);
5484 #ifndef USE_TOOLKIT_SCROLL_BARS
5486 /* Handle some mouse motion while someone is dragging the scroll bar.
5488 This may be called from a signal handler, so we have to ignore GC
5492 x_scroll_bar_note_movement (struct scroll_bar
*bar
, XMotionEvent
*event
)
5494 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5496 last_mouse_movement_time
= event
->time
;
5499 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5501 /* If we're dragging the bar, display it. */
5502 if (bar
->dragging
!= -1)
5504 /* Where should the handle be now? */
5505 int new_start
= event
->y
- bar
->dragging
;
5507 if (new_start
!= bar
->start
)
5509 int new_end
= new_start
+ bar
->end
- bar
->start
;
5511 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5516 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5518 /* Return information to the user about the current position of the mouse
5519 on the scroll bar. */
5522 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
5523 enum scroll_bar_part
*part
, Lisp_Object
*x
,
5524 Lisp_Object
*y
, Time
*timestamp
)
5526 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5527 Window w
= bar
->x_window
;
5528 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5530 Window dummy_window
;
5532 unsigned int dummy_mask
;
5536 /* Get the mouse's position relative to the scroll bar window, and
5538 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5540 /* Root, child, root x and root y. */
5541 &dummy_window
, &dummy_window
,
5542 &dummy_coord
, &dummy_coord
,
5544 /* Position relative to scroll bar. */
5547 /* Mouse buttons and modifier keys. */
5553 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5555 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5557 if (bar
->dragging
!= -1)
5558 win_y
-= bar
->dragging
;
5562 if (win_y
> top_range
)
5566 *bar_window
= bar
->window
;
5568 if (bar
->dragging
!= -1)
5569 *part
= scroll_bar_handle
;
5570 else if (win_y
< bar
->start
)
5571 *part
= scroll_bar_above_handle
;
5572 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5573 *part
= scroll_bar_handle
;
5575 *part
= scroll_bar_below_handle
;
5577 XSETINT (*x
, win_y
);
5578 XSETINT (*y
, top_range
);
5581 last_mouse_scroll_bar
= Qnil
;
5584 *timestamp
= last_mouse_movement_time
;
5590 /* The screen has been cleared so we may have changed foreground or
5591 background colors, and the scroll bars may need to be redrawn.
5592 Clear out the scroll bars, and ask for expose events, so we can
5596 x_scroll_bar_clear (struct frame
*f
)
5598 #ifndef USE_TOOLKIT_SCROLL_BARS
5601 /* We can have scroll bars even if this is 0,
5602 if we just turned off scroll bar mode.
5603 But in that case we should not clear them. */
5604 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5605 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5606 bar
= XSCROLL_BAR (bar
)->next
)
5607 XClearArea (FRAME_X_DISPLAY (f
),
5608 XSCROLL_BAR (bar
)->x_window
,
5610 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5613 #ifdef ENABLE_CHECKING
5615 /* Record the last 100 characters stored
5616 to help debug the loss-of-chars-during-GC problem. */
5618 static int temp_index
;
5619 static short temp_buffer
[100];
5621 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5622 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5624 temp_buffer[temp_index++] = (keysym)
5626 #else /* not ENABLE_CHECKING */
5628 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
5630 #endif /* ENABLE_CHECKING */
5632 /* Set this to nonzero to fake an "X I/O error"
5633 on a particular display. */
5635 static struct x_display_info
*XTread_socket_fake_io_error
;
5637 /* When we find no input here, we occasionally do a no-op command
5638 to verify that the X server is still running and we can still talk with it.
5639 We try all the open displays, one by one.
5640 This variable is used for cycling thru the displays. */
5642 static struct x_display_info
*next_noop_dpyinfo
;
5644 #if defined USE_X_TOOLKIT || defined USE_GTK
5645 #define SET_SAVED_BUTTON_EVENT \
5648 if (f->output_data.x->saved_menu_event == 0) \
5649 f->output_data.x->saved_menu_event = \
5650 xmalloc (sizeof (XEvent)); \
5651 *f->output_data.x->saved_menu_event = event; \
5652 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5653 XSETFRAME (inev.ie.frame_or_window, f); \
5665 /* Filter events for the current X input method.
5666 DPYINFO is the display this event is for.
5667 EVENT is the X event to filter.
5669 Returns non-zero if the event was filtered, caller shall not process
5671 Returns zero if event is wasn't filtered. */
5675 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5677 /* XFilterEvent returns non-zero if the input method has
5678 consumed the event. We pass the frame's X window to
5679 XFilterEvent because that's the one for which the IC
5682 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5683 event
->xclient
.window
);
5685 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5690 static int current_count
;
5691 static int current_finish
;
5692 static struct input_event
*current_hold_quit
;
5694 /* This is the filter function invoked by the GTK event loop.
5695 It is invoked before the XEvent is translated to a GdkEvent,
5696 so we have a chance to act on the event before GTK. */
5697 static GdkFilterReturn
5698 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5700 XEvent
*xev
= (XEvent
*) gxev
;
5703 if (current_count
>= 0)
5705 struct x_display_info
*dpyinfo
;
5707 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5710 /* Filter events for the current X input method.
5711 GTK calls XFilterEvent but not for key press and release,
5712 so we do it here. */
5713 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5715 && x_filter_event (dpyinfo
, xev
))
5718 return GDK_FILTER_REMOVE
;
5723 current_finish
= X_EVENT_NORMAL
;
5726 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5730 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5734 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5735 return GDK_FILTER_REMOVE
;
5737 return GDK_FILTER_CONTINUE
;
5739 #endif /* USE_GTK */
5742 static void xembed_send_message (struct frame
*f
, Time
,
5743 enum xembed_message
,
5744 long detail
, long data1
, long data2
);
5746 /* Handles the XEvent EVENT on display DPYINFO.
5748 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5749 *FINISH is zero if caller should continue reading events.
5750 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5752 We return the number of characters stored into the buffer. */
5755 handle_one_xevent (struct x_display_info
*dpyinfo
, XEvent
*eventptr
,
5756 int *finish
, struct input_event
*hold_quit
)
5759 struct input_event ie
;
5760 struct selection_input_event sie
;
5764 ptrdiff_t nbytes
= 0;
5765 struct frame
*f
= NULL
;
5766 struct coding_system coding
;
5767 XEvent event
= *eventptr
;
5768 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
5769 /* This holds the state XLookupString needs to implement dead keys
5770 and other tricks known as "compose processing". _X Window System_
5771 says that a portable program can't use this, but Stephen Gildea assures
5772 me that letting the compiler initialize it to zeros will work okay. */
5773 static XComposeStatus compose_status
;
5777 *finish
= X_EVENT_NORMAL
;
5779 EVENT_INIT (inev
.ie
);
5780 inev
.ie
.kind
= NO_EVENT
;
5783 if (pending_event_wait
.eventtype
== event
.type
)
5784 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5790 if (event
.xclient
.message_type
5791 == dpyinfo
->Xatom_wm_protocols
5792 && event
.xclient
.format
== 32)
5794 if (event
.xclient
.data
.l
[0]
5795 == dpyinfo
->Xatom_wm_take_focus
)
5797 /* Use x_any_window_to_frame because this
5798 could be the shell widget window
5799 if the frame has no title bar. */
5800 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5802 /* Not quite sure this is needed -pd */
5803 if (f
&& FRAME_XIC (f
))
5804 XSetICFocus (FRAME_XIC (f
));
5806 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5807 instructs the WM to set the input focus automatically for
5808 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5809 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5810 it has set the focus. So, XSetInputFocus below is not
5813 The call to XSetInputFocus below has also caused trouble. In
5814 cases where the XSetInputFocus done by the WM and the one
5815 below are temporally close (on a fast machine), the call
5816 below can generate additional FocusIn events which confuse
5819 /* Since we set WM_TAKE_FOCUS, we must call
5820 XSetInputFocus explicitly. But not if f is null,
5821 since that might be an event for a deleted frame. */
5824 Display
*d
= event
.xclient
.display
;
5825 /* Catch and ignore errors, in case window has been
5826 iconified by a window manager such as GWM. */
5828 XSetInputFocus (d
, event
.xclient
.window
,
5829 /* The ICCCM says this is
5830 the only valid choice. */
5832 event
.xclient
.data
.l
[1]);
5833 /* This is needed to detect the error
5834 if there is an error. */
5836 x_uncatch_errors ();
5838 /* Not certain about handling scroll bars here */
5843 if (event
.xclient
.data
.l
[0]
5844 == dpyinfo
->Xatom_wm_save_yourself
)
5846 /* Save state modify the WM_COMMAND property to
5847 something which can reinstate us. This notifies
5848 the session manager, who's looking for such a
5849 PropertyNotify. Can restart processing when
5850 a keyboard or mouse event arrives. */
5851 /* If we have a session manager, don't set this.
5852 KDE will then start two Emacsen, one for the
5853 session manager and one for this. */
5855 if (! x_session_have_connection ())
5858 f
= x_top_window_to_frame (dpyinfo
,
5859 event
.xclient
.window
);
5860 /* This is just so we only give real data once
5861 for a single Emacs process. */
5862 if (f
== SELECTED_FRAME ())
5863 XSetCommand (FRAME_X_DISPLAY (f
),
5864 event
.xclient
.window
,
5865 initial_argv
, initial_argc
);
5867 XSetCommand (FRAME_X_DISPLAY (f
),
5868 event
.xclient
.window
,
5874 if (event
.xclient
.data
.l
[0]
5875 == dpyinfo
->Xatom_wm_delete_window
)
5877 f
= x_any_window_to_frame (dpyinfo
,
5878 event
.xclient
.window
);
5880 goto OTHER
; /* May be a dialog that is to be removed */
5882 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5883 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5890 if (event
.xclient
.message_type
5891 == dpyinfo
->Xatom_wm_configure_denied
)
5896 if (event
.xclient
.message_type
5897 == dpyinfo
->Xatom_wm_window_moved
)
5900 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5902 new_x
= event
.xclient
.data
.s
[0];
5903 new_y
= event
.xclient
.data
.s
[1];
5907 f
->left_pos
= new_x
;
5914 if (event
.xclient
.message_type
5915 == dpyinfo
->Xatom_editres
)
5917 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5919 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5923 #endif /* HACK_EDITRES */
5925 if ((event
.xclient
.message_type
5926 == dpyinfo
->Xatom_DONE
)
5927 || (event
.xclient
.message_type
5928 == dpyinfo
->Xatom_PAGE
))
5930 /* Ghostview job completed. Kill it. We could
5931 reply with "Next" if we received "Page", but we
5932 currently never do because we are interested in
5933 images, only, which should have 1 page. */
5934 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5935 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5938 x_kill_gs_process (pixmap
, f
);
5939 expose_frame (f
, 0, 0, 0, 0);
5943 #ifdef USE_TOOLKIT_SCROLL_BARS
5944 /* Scroll bar callbacks send a ClientMessage from which
5945 we construct an input_event. */
5946 if (event
.xclient
.message_type
5947 == dpyinfo
->Xatom_Scrollbar
)
5949 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
5950 *finish
= X_EVENT_GOTO_OUT
;
5953 #endif /* USE_TOOLKIT_SCROLL_BARS */
5955 /* XEmbed messages from the embedder (if any). */
5956 if (event
.xclient
.message_type
5957 == dpyinfo
->Xatom_XEMBED
)
5959 enum xembed_message msg
= event
.xclient
.data
.l
[1];
5960 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
5961 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
5963 *finish
= X_EVENT_GOTO_OUT
;
5967 xft_settings_event (dpyinfo
, &event
);
5969 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5972 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
5973 *finish
= X_EVENT_DROP
;
5977 case SelectionNotify
:
5978 dpyinfo
->last_user_time
= event
.xselection
.time
;
5979 #ifdef USE_X_TOOLKIT
5980 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5982 #endif /* not USE_X_TOOLKIT */
5983 x_handle_selection_notify (&event
.xselection
);
5986 case SelectionClear
: /* Someone has grabbed ownership. */
5987 dpyinfo
->last_user_time
= event
.xselectionclear
.time
;
5988 #ifdef USE_X_TOOLKIT
5989 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5991 #endif /* USE_X_TOOLKIT */
5993 XSelectionClearEvent
*eventp
= &(event
.xselectionclear
);
5995 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
5996 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5997 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5998 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6002 case SelectionRequest
: /* Someone wants our selection. */
6003 dpyinfo
->last_user_time
= event
.xselectionrequest
.time
;
6004 #ifdef USE_X_TOOLKIT
6005 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6007 #endif /* USE_X_TOOLKIT */
6009 XSelectionRequestEvent
*eventp
= &(event
.xselectionrequest
);
6011 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6012 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6013 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6014 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6015 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6016 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6017 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6021 case PropertyNotify
:
6022 dpyinfo
->last_user_time
= event
.xproperty
.time
;
6023 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
6024 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6025 if (x_handle_net_wm_state (f
, &event
.xproperty
)
6026 && FRAME_ICONIFIED_P (f
)
6027 && f
->output_data
.x
->net_wm_state_hidden_seen
)
6029 /* Gnome shell does not iconify us when C-z is pressed.
6030 It hides the frame. So if our state says we aren't
6031 hidden anymore, treat it as deiconified. */
6032 SET_FRAME_VISIBLE (f
, 1);
6033 SET_FRAME_ICONIFIED (f
, 0);
6034 f
->output_data
.x
->has_been_visible
= 1;
6035 f
->output_data
.x
->net_wm_state_hidden_seen
= 0;
6036 inev
.ie
.kind
= DEICONIFY_EVENT
;
6037 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6040 x_handle_property_notify (&event
.xproperty
);
6041 xft_settings_event (dpyinfo
, &event
);
6044 case ReparentNotify
:
6045 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6049 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6050 x_real_positions (f
, &x
, &y
);
6054 /* Perhaps reparented due to a WM restart. Reset this. */
6055 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6056 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6058 x_set_frame_alpha (f
);
6063 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6067 /* This seems to be needed for GTK 2.6. */
6068 x_clear_area (event
.xexpose
.display
,
6069 event
.xexpose
.window
,
6070 event
.xexpose
.x
, event
.xexpose
.y
,
6071 event
.xexpose
.width
, event
.xexpose
.height
);
6073 if (!FRAME_VISIBLE_P (f
))
6075 SET_FRAME_VISIBLE (f
, 1);
6076 SET_FRAME_ICONIFIED (f
, 0);
6077 f
->output_data
.x
->has_been_visible
= 1;
6078 SET_FRAME_GARBAGED (f
);
6082 event
.xexpose
.x
, event
.xexpose
.y
,
6083 event
.xexpose
.width
, event
.xexpose
.height
);
6087 #ifndef USE_TOOLKIT_SCROLL_BARS
6088 struct scroll_bar
*bar
;
6090 #if defined USE_LUCID
6091 /* Submenus of the Lucid menu bar aren't widgets
6092 themselves, so there's no way to dispatch events
6093 to them. Recognize this case separately. */
6096 = x_window_to_menu_bar (event
.xexpose
.window
);
6098 xlwmenu_redisplay (widget
);
6100 #endif /* USE_LUCID */
6102 #ifdef USE_TOOLKIT_SCROLL_BARS
6103 /* Dispatch event to the widget. */
6105 #else /* not USE_TOOLKIT_SCROLL_BARS */
6106 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6107 event
.xexpose
.window
);
6110 x_scroll_bar_expose (bar
, &event
);
6111 #ifdef USE_X_TOOLKIT
6114 #endif /* USE_X_TOOLKIT */
6115 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6119 case GraphicsExpose
: /* This occurs when an XCopyArea's
6120 source area was obscured or not
6122 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6126 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6127 event
.xgraphicsexpose
.width
,
6128 event
.xgraphicsexpose
.height
);
6130 #ifdef USE_X_TOOLKIT
6133 #endif /* USE_X_TOOLKIT */
6136 case NoExpose
: /* This occurs when an XCopyArea's
6137 source area was completely
6142 /* Redo the mouse-highlight after the tooltip has gone. */
6143 if (event
.xunmap
.window
== tip_window
)
6146 redo_mouse_highlight ();
6149 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6150 if (f
) /* F may no longer exist if
6151 the frame was deleted. */
6153 bool visible
= FRAME_VISIBLE_P (f
);
6154 /* While a frame is unmapped, display generation is
6155 disabled; you don't want to spend time updating a
6156 display that won't ever be seen. */
6157 SET_FRAME_VISIBLE (f
, 0);
6158 /* We can't distinguish, from the event, whether the window
6159 has become iconified or invisible. So assume, if it
6160 was previously visible, than now it is iconified.
6161 But x_make_frame_invisible clears both
6162 the visible flag and the iconified flag;
6163 and that way, we know the window is not iconified now. */
6164 if (visible
|| FRAME_ICONIFIED_P (f
))
6166 SET_FRAME_ICONIFIED (f
, 1);
6167 inev
.ie
.kind
= ICONIFY_EVENT
;
6168 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6174 if (event
.xmap
.window
== tip_window
)
6175 /* The tooltip has been drawn already. Avoid
6176 the SET_FRAME_GARBAGED below. */
6179 /* We use x_top_window_to_frame because map events can
6180 come for sub-windows and they don't mean that the
6181 frame is visible. */
6182 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6185 bool iconified
= FRAME_ICONIFIED_P (f
);
6186 /* wait_reading_process_output will notice this and update
6187 the frame's display structures.
6188 If we where iconified, we should not set garbaged,
6189 because that stops redrawing on Expose events. This looks
6190 bad if we are called from a recursive event loop
6191 (x_dispatch_event), for example when a dialog is up. */
6193 SET_FRAME_GARBAGED (f
);
6195 /* Check if fullscreen was specified before we where mapped the
6196 first time, i.e. from the command line. */
6197 if (!f
->output_data
.x
->has_been_visible
)
6198 x_check_fullscreen (f
);
6200 SET_FRAME_VISIBLE (f
, 1);
6201 SET_FRAME_ICONIFIED (f
, 0);
6202 f
->output_data
.x
->has_been_visible
= 1;
6206 inev
.ie
.kind
= DEICONIFY_EVENT
;
6207 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6209 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
6210 /* Force a redisplay sooner or later to update the
6211 frame titles in case this is the second frame. */
6212 record_asynch_buffer_change ();
6215 xg_frame_resized (f
, -1, -1);
6222 dpyinfo
->last_user_time
= event
.xkey
.time
;
6223 ignore_next_mouse_click_timeout
= 0;
6225 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6226 /* Dispatch KeyPress events when in menu. */
6227 if (popup_activated ())
6231 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6233 #if ! defined (USE_GTK)
6234 /* If mouse-highlight is an integer, input clears out
6235 mouse highlighting. */
6236 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6238 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)))
6240 clear_mouse_face (hlinfo
);
6241 hlinfo
->mouse_face_hidden
= 1;
6245 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6248 /* Scroll bars consume key events, but we want
6249 the keys to go to the scroll bar's frame. */
6250 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6252 if (widget
&& XmIsScrollBar (widget
))
6254 widget
= XtParent (widget
);
6255 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6258 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6262 KeySym keysym
, orig_keysym
;
6263 /* al%imercury@uunet.uu.net says that making this 81
6264 instead of 80 fixed a bug whereby meta chars made
6267 It seems that some version of XmbLookupString has
6268 a bug of not returning XBufferOverflow in
6269 status_return even if the input is too long to
6270 fit in 81 bytes. So, we must prepare sufficient
6271 bytes for copy_buffer. 513 bytes (256 chars for
6272 two-byte character set) seems to be a fairly good
6273 approximation. -- 2000.8.10 handa@etl.go.jp */
6274 unsigned char copy_buffer
[513];
6275 unsigned char *copy_bufptr
= copy_buffer
;
6276 int copy_bufsiz
= sizeof (copy_buffer
);
6278 Lisp_Object coding_system
= Qlatin_1
;
6282 /* Don't pass keys to GTK. A Tab will shift focus to the
6283 tool bar in GTK 2.4. Keys will still go to menus and
6284 dialogs because in that case popup_activated is TRUE
6286 *finish
= X_EVENT_DROP
;
6290 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6291 extra_keyboard_modifiers
);
6292 modifiers
= event
.xkey
.state
;
6294 /* This will have to go some day... */
6296 /* make_lispy_event turns chars into control chars.
6297 Don't do it here because XLookupString is too eager. */
6298 event
.xkey
.state
&= ~ControlMask
;
6299 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6300 | dpyinfo
->super_mod_mask
6301 | dpyinfo
->hyper_mod_mask
6302 | dpyinfo
->alt_mod_mask
);
6304 /* In case Meta is ComposeCharacter,
6305 clear its status. According to Markus Ehrnsperger
6306 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6307 this enables ComposeCharacter to work whether or
6308 not it is combined with Meta. */
6309 if (modifiers
& dpyinfo
->meta_mod_mask
)
6310 memset (&compose_status
, 0, sizeof (compose_status
));
6315 Status status_return
;
6317 coding_system
= Vlocale_coding_system
;
6318 nbytes
= XmbLookupString (FRAME_XIC (f
),
6319 &event
.xkey
, (char *) copy_bufptr
,
6320 copy_bufsiz
, &keysym
,
6322 if (status_return
== XBufferOverflow
)
6324 copy_bufsiz
= nbytes
+ 1;
6325 copy_bufptr
= alloca (copy_bufsiz
);
6326 nbytes
= XmbLookupString (FRAME_XIC (f
),
6327 &event
.xkey
, (char *) copy_bufptr
,
6328 copy_bufsiz
, &keysym
,
6331 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6332 if (status_return
== XLookupNone
)
6334 else if (status_return
== XLookupChars
)
6339 else if (status_return
!= XLookupKeySym
6340 && status_return
!= XLookupBoth
)
6344 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6345 copy_bufsiz
, &keysym
,
6348 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6349 copy_bufsiz
, &keysym
,
6353 /* If not using XIM/XIC, and a compose sequence is in progress,
6354 we break here. Otherwise, chars_matched is always 0. */
6355 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6358 memset (&compose_status
, 0, sizeof (compose_status
));
6359 orig_keysym
= keysym
;
6361 /* Common for all keysym input events. */
6362 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6364 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6365 inev
.ie
.timestamp
= event
.xkey
.time
;
6367 /* First deal with keysyms which have defined
6368 translations to characters. */
6369 if (keysym
>= 32 && keysym
< 128)
6370 /* Avoid explicitly decoding each ASCII character. */
6372 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6373 inev
.ie
.code
= keysym
;
6377 /* Keysyms directly mapped to Unicode characters. */
6378 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6380 if (keysym
< 0x01000080)
6381 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6383 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6384 inev
.ie
.code
= keysym
& 0xFFFFFF;
6388 /* Now non-ASCII. */
6389 if (HASH_TABLE_P (Vx_keysym_table
)
6390 && (c
= Fgethash (make_number (keysym
),
6395 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6396 ? ASCII_KEYSTROKE_EVENT
6397 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6398 inev
.ie
.code
= XFASTINT (c
);
6402 /* Random non-modifier sorts of keysyms. */
6403 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6404 || keysym
== XK_Delete
6405 #ifdef XK_ISO_Left_Tab
6406 || (keysym
>= XK_ISO_Left_Tab
6407 && keysym
<= XK_ISO_Enter
)
6409 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6410 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6412 /* This recognizes the "extended function
6413 keys". It seems there's no cleaner way.
6414 Test IsModifierKey to avoid handling
6415 mode_switch incorrectly. */
6416 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
6418 #ifdef XK_dead_circumflex
6419 || orig_keysym
== XK_dead_circumflex
6421 #ifdef XK_dead_grave
6422 || orig_keysym
== XK_dead_grave
6424 #ifdef XK_dead_tilde
6425 || orig_keysym
== XK_dead_tilde
6427 #ifdef XK_dead_diaeresis
6428 || orig_keysym
== XK_dead_diaeresis
6430 #ifdef XK_dead_macron
6431 || orig_keysym
== XK_dead_macron
6433 #ifdef XK_dead_degree
6434 || orig_keysym
== XK_dead_degree
6436 #ifdef XK_dead_acute
6437 || orig_keysym
== XK_dead_acute
6439 #ifdef XK_dead_cedilla
6440 || orig_keysym
== XK_dead_cedilla
6442 #ifdef XK_dead_breve
6443 || orig_keysym
== XK_dead_breve
6445 #ifdef XK_dead_ogonek
6446 || orig_keysym
== XK_dead_ogonek
6448 #ifdef XK_dead_caron
6449 || orig_keysym
== XK_dead_caron
6451 #ifdef XK_dead_doubleacute
6452 || orig_keysym
== XK_dead_doubleacute
6454 #ifdef XK_dead_abovedot
6455 || orig_keysym
== XK_dead_abovedot
6457 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6458 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6459 /* Any "vendor-specific" key is ok. */
6460 || (orig_keysym
& (1 << 28))
6461 || (keysym
!= NoSymbol
&& nbytes
== 0))
6462 && ! (IsModifierKey (orig_keysym
)
6463 /* The symbols from XK_ISO_Lock
6464 to XK_ISO_Last_Group_Lock
6465 don't have real modifiers but
6466 should be treated similarly to
6467 Mode_switch by Emacs. */
6468 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6469 || (XK_ISO_Lock
<= orig_keysym
6470 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
6474 STORE_KEYSYM_FOR_DEBUG (keysym
);
6475 /* make_lispy_event will convert this to a symbolic
6477 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6478 inev
.ie
.code
= keysym
;
6482 { /* Raw bytes, not keysym. */
6486 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6488 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6490 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6493 if (nchars
< nbytes
)
6495 /* Decode the input data. */
6497 /* The input should be decoded with `coding_system'
6498 which depends on which X*LookupString function
6499 we used just above and the locale. */
6500 setup_coding_system (coding_system
, &coding
);
6501 coding
.src_multibyte
= 0;
6502 coding
.dst_multibyte
= 1;
6503 /* The input is converted to events, thus we can't
6504 handle composition. Anyway, there's no XIM that
6505 gives us composition information. */
6506 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6508 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
6510 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6511 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6512 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6513 nbytes
= coding
.produced
;
6514 nchars
= coding
.produced_char
;
6515 copy_bufptr
= coding
.destination
;
6518 /* Convert the input data to a sequence of
6519 character events. */
6520 for (i
= 0; i
< nbytes
; i
+= len
)
6523 if (nchars
== nbytes
)
6524 ch
= copy_bufptr
[i
], len
= 1;
6526 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6527 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
6528 ? ASCII_KEYSTROKE_EVENT
6529 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6531 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6536 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6538 if (keysym
== NoSymbol
)
6544 /* Don't dispatch this event since XtDispatchEvent calls
6545 XFilterEvent, and two calls in a row may freeze the
6553 dpyinfo
->last_user_time
= event
.xkey
.time
;
6555 /* Don't dispatch this event since XtDispatchEvent calls
6556 XFilterEvent, and two calls in a row may freeze the
6564 dpyinfo
->last_user_time
= event
.xcrossing
.time
;
6565 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6567 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6569 if (f
&& x_mouse_click_focus_ignore_position
)
6570 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6572 /* EnterNotify counts as mouse movement,
6573 so update things that depend on mouse position. */
6574 if (f
&& !f
->output_data
.x
->hourglass_p
)
6575 note_mouse_movement (f
, &event
.xmotion
);
6577 /* We may get an EnterNotify on the buttons in the toolbar. In that
6578 case we moved out of any highlighted area and need to note this. */
6579 if (!f
&& last_mouse_glyph_frame
)
6580 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6585 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6589 dpyinfo
->last_user_time
= event
.xcrossing
.time
;
6590 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6592 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6595 if (f
== hlinfo
->mouse_face_mouse_frame
)
6597 /* If we move outside the frame, then we're
6598 certainly no longer on any text in the frame. */
6599 clear_mouse_face (hlinfo
);
6600 hlinfo
->mouse_face_mouse_frame
= 0;
6603 /* Generate a nil HELP_EVENT to cancel a help-echo.
6604 Do it only if there's something to cancel.
6605 Otherwise, the startup message is cleared when
6606 the mouse leaves the frame. */
6607 if (any_help_event_p
)
6611 /* See comment in EnterNotify above */
6612 else if (last_mouse_glyph_frame
)
6613 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6618 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6623 dpyinfo
->last_user_time
= event
.xmotion
.time
;
6624 previous_help_echo_string
= help_echo_string
;
6625 help_echo_string
= Qnil
;
6627 if (dpyinfo
->grabbed
&& last_mouse_frame
6628 && FRAME_LIVE_P (last_mouse_frame
))
6629 f
= last_mouse_frame
;
6631 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6633 if (hlinfo
->mouse_face_hidden
)
6635 hlinfo
->mouse_face_hidden
= 0;
6636 clear_mouse_face (hlinfo
);
6640 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6646 /* Generate SELECT_WINDOW_EVENTs when needed.
6647 Don't let popup menus influence things (bug#1261). */
6648 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6650 static Lisp_Object last_mouse_window
;
6651 Lisp_Object window
= window_from_coordinates
6652 (f
, event
.xmotion
.x
, event
.xmotion
.y
, 0, 0);
6654 /* Window will be selected only when it is not selected now and
6655 last mouse movement event was not in it. Minibuffer window
6656 will be selected only when it is active. */
6657 if (WINDOWP (window
)
6658 && !EQ (window
, last_mouse_window
)
6659 && !EQ (window
, selected_window
)
6660 /* For click-to-focus window managers
6661 create event iff we don't leave the
6663 && (focus_follows_mouse
6664 || (EQ (XWINDOW (window
)->frame
,
6665 XWINDOW (selected_window
)->frame
))))
6667 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6668 inev
.ie
.frame_or_window
= window
;
6670 /* Remember the last window where we saw the mouse. */
6671 last_mouse_window
= window
;
6673 if (!note_mouse_movement (f
, &event
.xmotion
))
6674 help_echo_string
= previous_help_echo_string
;
6678 #ifndef USE_TOOLKIT_SCROLL_BARS
6679 struct scroll_bar
*bar
6680 = x_window_to_scroll_bar (event
.xmotion
.display
,
6681 event
.xmotion
.window
);
6684 x_scroll_bar_note_movement (bar
, &event
.xmotion
);
6685 #endif /* USE_TOOLKIT_SCROLL_BARS */
6687 /* If we move outside the frame, then we're
6688 certainly no longer on any text in the frame. */
6689 clear_mouse_face (hlinfo
);
6692 /* If the contents of the global variable help_echo_string
6693 has changed, generate a HELP_EVENT. */
6694 if (!NILP (help_echo_string
)
6695 || !NILP (previous_help_echo_string
))
6700 case ConfigureNotify
:
6701 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6704 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6705 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6707 xg_frame_resized (f
, event
.xconfigure
.width
,
6708 event
.xconfigure
.height
);
6714 #ifndef USE_X_TOOLKIT
6716 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6717 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6719 /* In the toolkit version, change_frame_size
6720 is called by the code that handles resizing
6721 of the EmacsFrame widget. */
6723 /* Even if the number of character rows and columns has
6724 not changed, the font size may have changed, so we need
6725 to check the pixel dimensions as well. */
6726 if (columns
!= FRAME_COLS (f
)
6727 || rows
!= FRAME_LINES (f
)
6728 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6729 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6731 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6732 SET_FRAME_GARBAGED (f
);
6733 cancel_mouse_face (f
);
6736 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6737 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6738 #endif /* not USE_GTK */
6742 /* GTK creates windows but doesn't map them.
6743 Only get real positions when mapped. */
6744 if (FRAME_GTK_OUTER_WIDGET (f
)
6745 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6748 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6752 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6753 xic_set_statusarea (f
);
6762 /* If we decide we want to generate an event to be seen
6763 by the rest of Emacs, we put it here. */
6764 bool tool_bar_p
= 0;
6766 memset (&compose_status
, 0, sizeof (compose_status
));
6767 last_mouse_glyph_frame
= 0;
6768 dpyinfo
->last_user_time
= event
.xbutton
.time
;
6770 if (dpyinfo
->grabbed
6772 && FRAME_LIVE_P (last_mouse_frame
))
6773 f
= last_mouse_frame
;
6775 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6778 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6783 #if ! defined (USE_GTK)
6784 /* Is this in the tool-bar? */
6785 if (WINDOWP (f
->tool_bar_window
)
6786 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6789 int x
= event
.xbutton
.x
;
6790 int y
= event
.xbutton
.y
;
6792 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6793 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6795 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6796 handle_tool_bar_click
6797 (f
, x
, y
, event
.xbutton
.type
== ButtonPress
,
6798 x_x_to_emacs_modifiers (dpyinfo
, event
.xbutton
.state
));
6800 #endif /* !USE_GTK */
6803 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6804 if (! popup_activated ())
6807 if (ignore_next_mouse_click_timeout
)
6809 if (event
.type
== ButtonPress
6810 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6812 ignore_next_mouse_click_timeout
= 0;
6813 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6815 if (event
.type
== ButtonRelease
)
6816 ignore_next_mouse_click_timeout
= 0;
6819 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6821 if (FRAME_X_EMBEDDED_P (f
))
6822 xembed_send_message (f
, event
.xbutton
.time
,
6823 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6827 struct scroll_bar
*bar
6828 = x_window_to_scroll_bar (event
.xbutton
.display
,
6829 event
.xbutton
.window
);
6831 #ifdef USE_TOOLKIT_SCROLL_BARS
6832 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6834 if (bar
&& event
.xbutton
.state
& ControlMask
)
6836 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6837 *finish
= X_EVENT_DROP
;
6839 #else /* not USE_TOOLKIT_SCROLL_BARS */
6841 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6842 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6845 if (event
.type
== ButtonPress
)
6847 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6848 last_mouse_frame
= f
;
6851 last_tool_bar_item
= -1;
6854 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6856 /* Ignore any mouse motion that happened before this event;
6857 any subsequent mouse-movement Emacs events should reflect
6858 only motion after the ButtonPress/Release. */
6862 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6863 f
= x_menubar_window_to_frame (dpyinfo
, &event
);
6864 /* For a down-event in the menu bar,
6865 don't pass it to Xt right now.
6866 Instead, save it away
6867 and we will pass it to Xt from kbd_buffer_get_event.
6868 That way, we can run some Lisp code first. */
6869 if (! popup_activated ()
6871 /* Gtk+ menus only react to the first three buttons. */
6872 && event
.xbutton
.button
< 3
6874 && f
&& event
.type
== ButtonPress
6875 /* Verify the event is really within the menu bar
6876 and not just sent to it due to grabbing. */
6877 && event
.xbutton
.x
>= 0
6878 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6879 && event
.xbutton
.y
>= 0
6880 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6881 && event
.xbutton
.same_screen
)
6883 SET_SAVED_BUTTON_EVENT
;
6884 *finish
= X_EVENT_DROP
;
6888 #endif /* USE_X_TOOLKIT || USE_GTK */
6892 case CirculateNotify
:
6895 case CirculateRequest
:
6898 case VisibilityNotify
:
6902 /* Someone has changed the keyboard mapping - update the
6904 switch (event
.xmapping
.request
)
6906 case MappingModifier
:
6907 x_find_modifier_meanings (dpyinfo
);
6908 /* This is meant to fall through. */
6909 case MappingKeyboard
:
6910 XRefreshKeyboardMapping (&event
.xmapping
);
6915 xft_settings_event (dpyinfo
, &event
);
6920 #ifdef USE_X_TOOLKIT
6922 if (*finish
!= X_EVENT_DROP
)
6923 XtDispatchEvent (&event
);
6925 #endif /* USE_X_TOOLKIT */
6930 if (inev
.ie
.kind
!= NO_EVENT
)
6932 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6937 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6942 XSETFRAME (frame
, f
);
6948 any_help_event_p
= 1;
6949 gen_help_event (help_echo_string
, frame
, help_echo_window
,
6950 help_echo_object
, help_echo_pos
);
6954 help_echo_string
= Qnil
;
6955 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
6965 #if defined USE_GTK || defined USE_X_TOOLKIT
6967 /* Handles the XEvent EVENT on display DISPLAY.
6968 This is used for event loops outside the normal event handling,
6969 i.e. looping while a popup menu or a dialog is posted.
6971 Returns the value handle_one_xevent sets in the finish argument. */
6973 x_dispatch_event (XEvent
*event
, Display
*display
)
6975 struct x_display_info
*dpyinfo
;
6976 int finish
= X_EVENT_NORMAL
;
6978 dpyinfo
= x_display_info_for_display (display
);
6981 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
6988 /* Read events coming from the X server.
6989 Return as soon as there are no more events to be read.
6991 Return the number of characters stored into the buffer,
6992 thus pretending to be `read' (except the characters we store
6993 in the keyboard buffer can be multibyte, so are not necessarily
6997 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
7000 int event_found
= 0;
7004 /* So people can tell when we have read the available input. */
7005 input_signal_count
++;
7007 /* For debugging, this gives a way to fake an I/O error. */
7008 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7010 XTread_socket_fake_io_error
= 0;
7011 x_io_error_quitter (terminal
->display_info
.x
->display
);
7015 while (XPending (terminal
->display_info
.x
->display
))
7020 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7023 /* Filter events for the current X input method. */
7024 if (x_filter_event (terminal
->display_info
.x
, &event
))
7029 count
+= handle_one_xevent (terminal
->display_info
.x
,
7030 &event
, &finish
, hold_quit
);
7032 if (finish
== X_EVENT_GOTO_OUT
)
7040 /* For GTK we must use the GTK event loop. But XEvents gets passed
7041 to our filter function above, and then to the big event switch.
7042 We use a bunch of globals to communicate with our filter function,
7043 that is kind of ugly, but it works.
7045 There is no way to do one display at the time, GTK just does events
7046 from all displays. */
7048 while (gtk_events_pending ())
7050 current_count
= count
;
7051 current_hold_quit
= hold_quit
;
7053 gtk_main_iteration ();
7055 count
= current_count
;
7057 current_hold_quit
= 0;
7059 if (current_finish
== X_EVENT_GOTO_OUT
)
7062 #endif /* USE_GTK */
7064 /* On some systems, an X bug causes Emacs to get no more events
7065 when the window is destroyed. Detect that. (1994.) */
7068 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7069 One XNOOP in 100 loops will make Emacs terminate.
7070 B. Bretthauer, 1994 */
7072 if (x_noop_count
>= 100)
7076 if (next_noop_dpyinfo
== 0)
7077 next_noop_dpyinfo
= x_display_list
;
7079 XNoOp (next_noop_dpyinfo
->display
);
7081 /* Each time we get here, cycle through the displays now open. */
7082 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7086 /* If the focus was just given to an auto-raising frame,
7088 /* ??? This ought to be able to handle more than one such frame. */
7089 if (pending_autoraise_frame
)
7091 x_raise_frame (pending_autoraise_frame
);
7092 pending_autoraise_frame
= 0;
7103 /***********************************************************************
7105 ***********************************************************************/
7107 /* Set clipping for output in glyph row ROW. W is the window in which
7108 we operate. GC is the graphics context to set clipping in.
7110 ROW may be a text row or, e.g., a mode line. Text rows must be
7111 clipped to the interior of the window dedicated to text display,
7112 mode lines must be clipped to the whole window. */
7115 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
7116 enum glyph_row_area area
, GC gc
)
7118 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7119 XRectangle clip_rect
;
7120 int window_x
, window_y
, window_width
;
7122 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7124 clip_rect
.x
= window_x
;
7125 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7126 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7127 clip_rect
.width
= window_width
;
7128 clip_rect
.height
= row
->visible_height
;
7130 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7134 /* Draw a hollow box cursor on window W in glyph row ROW. */
7137 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7139 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7140 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7141 Display
*dpy
= FRAME_X_DISPLAY (f
);
7144 struct glyph
*cursor_glyph
;
7147 /* Get the glyph the cursor is on. If we can't tell because
7148 the current matrix is invalid or such, give up. */
7149 cursor_glyph
= get_phys_cursor_glyph (w
);
7150 if (cursor_glyph
== NULL
)
7153 /* Compute frame-relative coordinates for phys cursor. */
7154 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7155 wd
= w
->phys_cursor_width
;
7157 /* The foreground of cursor_gc is typically the same as the normal
7158 background color, which can cause the cursor box to be invisible. */
7159 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7160 if (dpyinfo
->scratch_cursor_gc
)
7161 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7163 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7164 GCForeground
, &xgcv
);
7165 gc
= dpyinfo
->scratch_cursor_gc
;
7167 /* Set clipping, draw the rectangle, and reset clipping again. */
7168 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7169 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7170 XSetClipMask (dpy
, gc
, None
);
7174 /* Draw a bar cursor on window W in glyph row ROW.
7176 Implementation note: One would like to draw a bar cursor with an
7177 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7178 Unfortunately, I didn't find a font yet that has this property set.
7182 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7184 struct frame
*f
= XFRAME (w
->frame
);
7185 struct glyph
*cursor_glyph
;
7187 /* If cursor is out of bounds, don't draw garbage. This can happen
7188 in mini-buffer windows when switching between echo area glyphs
7190 cursor_glyph
= get_phys_cursor_glyph (w
);
7191 if (cursor_glyph
== NULL
)
7194 /* If on an image, draw like a normal cursor. That's usually better
7195 visible than drawing a bar, esp. if the image is large so that
7196 the bar might not be in the window. */
7197 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7199 struct glyph_row
*r
;
7200 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7201 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
7205 Display
*dpy
= FRAME_X_DISPLAY (f
);
7206 Window window
= FRAME_X_WINDOW (f
);
7207 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7208 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7209 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7212 /* If the glyph's background equals the color we normally draw
7213 the bars cursor in, the bar cursor in its normal color is
7214 invisible. Use the glyph's foreground color instead in this
7215 case, on the assumption that the glyph's colors are chosen so
7216 that the glyph is legible. */
7217 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7218 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7220 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7221 xgcv
.graphics_exposures
= 0;
7224 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7227 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7228 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7231 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7233 if (kind
== BAR_CURSOR
)
7235 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7238 width
= FRAME_CURSOR_WIDTH (f
);
7239 width
= min (cursor_glyph
->pixel_width
, width
);
7241 w
->phys_cursor_width
= width
;
7243 /* If the character under cursor is R2L, draw the bar cursor
7244 on the right of its glyph, rather than on the left. */
7245 if ((cursor_glyph
->resolved_level
& 1) != 0)
7246 x
+= cursor_glyph
->pixel_width
- width
;
7248 XFillRectangle (dpy
, window
, gc
, x
,
7249 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7250 width
, row
->height
);
7254 int dummy_x
, dummy_y
, dummy_h
;
7257 width
= row
->height
;
7259 width
= min (row
->height
, width
);
7261 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7262 &dummy_y
, &dummy_h
);
7264 XFillRectangle (dpy
, window
, gc
,
7265 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7266 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7267 row
->height
- width
),
7268 w
->phys_cursor_width
, width
);
7271 XSetClipMask (dpy
, gc
, None
);
7276 /* RIF: Define cursor CURSOR on frame F. */
7279 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7281 if (!f
->pointer_invisible
7282 && f
->output_data
.x
->current_cursor
!= cursor
)
7283 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7284 f
->output_data
.x
->current_cursor
= cursor
;
7288 /* RIF: Clear area on frame F. */
7291 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7293 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), x
, y
, width
, height
);
7295 /* Must queue a redraw, because scroll bars might have been cleared. */
7296 if (FRAME_GTK_WIDGET (f
))
7297 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7302 /* RIF: Draw cursor on window W. */
7305 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
7306 int y
, enum text_cursor_kinds cursor_type
,
7307 int cursor_width
, bool on_p
, bool active_p
)
7309 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7313 w
->phys_cursor_type
= cursor_type
;
7314 w
->phys_cursor_on_p
= 1;
7316 if (glyph_row
->exact_window_width_line_p
7317 && (glyph_row
->reversed_p
7318 ? (w
->phys_cursor
.hpos
< 0)
7319 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7321 glyph_row
->cursor_in_fringe_p
= 1;
7322 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7326 switch (cursor_type
)
7328 case HOLLOW_BOX_CURSOR
:
7329 x_draw_hollow_cursor (w
, glyph_row
);
7332 case FILLED_BOX_CURSOR
:
7333 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7337 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7341 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7345 w
->phys_cursor_width
= 0;
7354 if (w
== XWINDOW (f
->selected_window
))
7355 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7356 xic_set_preeditarea (w
, x
, y
);
7360 XFlush (FRAME_X_DISPLAY (f
));
7366 /* Make the x-window of frame F use the gnu icon bitmap. */
7369 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7371 ptrdiff_t bitmap_id
;
7373 if (FRAME_X_WINDOW (f
) == 0)
7376 /* Free up our existing icon bitmap and mask if any. */
7377 if (f
->output_data
.x
->icon_bitmap
> 0)
7378 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7379 f
->output_data
.x
->icon_bitmap
= 0;
7384 /* Use gtk_window_set_icon_from_file () if available,
7385 It's not restricted to bitmaps */
7386 if (xg_set_icon (f
, file
))
7388 #endif /* USE_GTK */
7389 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7390 x_create_bitmap_mask (f
, bitmap_id
);
7394 /* Create the GNU bitmap and mask if necessary. */
7395 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7401 if (xg_set_icon (f
, xg_default_icon_file
)
7402 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7405 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7407 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7409 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7413 /* If all else fails, use the (black and white) xbm image. */
7416 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
7417 gnu_xbm_width
, gnu_xbm_height
);
7421 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7422 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7426 /* The first time we create the GNU bitmap and mask,
7427 this increments the ref-count one extra time.
7428 As a result, the GNU bitmap and mask are never freed.
7429 That way, we don't have to worry about allocating it again. */
7430 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7432 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7435 x_wm_set_icon_pixmap (f
, bitmap_id
);
7436 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7442 /* Make the x-window of frame F use a rectangle with text.
7443 Use ICON_NAME as the text. */
7446 x_text_icon (struct frame
*f
, const char *icon_name
)
7448 if (FRAME_X_WINDOW (f
) == 0)
7453 text
.value
= (unsigned char *) icon_name
;
7454 text
.encoding
= XA_STRING
;
7456 text
.nitems
= strlen (icon_name
);
7457 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7460 if (f
->output_data
.x
->icon_bitmap
> 0)
7461 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7462 f
->output_data
.x
->icon_bitmap
= 0;
7463 x_wm_set_icon_pixmap (f
, 0);
7468 #define X_ERROR_MESSAGE_SIZE 200
7470 /* If non-nil, this should be a string.
7471 It means catch X errors and store the error message in this string.
7473 The reason we use a stack is that x_catch_error/x_uncatch_error can
7474 be called from a signal handler.
7477 struct x_error_message_stack
{
7478 char string
[X_ERROR_MESSAGE_SIZE
];
7480 struct x_error_message_stack
*prev
;
7482 static struct x_error_message_stack
*x_error_message
;
7484 /* An X error handler which stores the error message in
7485 *x_error_message. This is called from x_error_handler if
7486 x_catch_errors is in effect. */
7489 x_error_catcher (Display
*display
, XErrorEvent
*event
)
7491 XGetErrorText (display
, event
->error_code
,
7492 x_error_message
->string
,
7493 X_ERROR_MESSAGE_SIZE
);
7496 /* Begin trapping X errors for display DPY. Actually we trap X errors
7497 for all displays, but DPY should be the display you are actually
7500 After calling this function, X protocol errors no longer cause
7501 Emacs to exit; instead, they are recorded in the string
7502 stored in *x_error_message.
7504 Calling x_check_errors signals an Emacs error if an X error has
7505 occurred since the last call to x_catch_errors or x_check_errors.
7507 Calling x_uncatch_errors resumes the normal error handling. */
7510 x_catch_errors (Display
*dpy
)
7512 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
7514 /* Make sure any errors from previous requests have been dealt with. */
7518 data
->string
[0] = 0;
7519 data
->prev
= x_error_message
;
7520 x_error_message
= data
;
7523 /* Undo the last x_catch_errors call.
7524 DPY should be the display that was passed to x_catch_errors. */
7527 x_uncatch_errors (void)
7529 struct x_error_message_stack
*tmp
;
7533 /* The display may have been closed before this function is called.
7534 Check if it is still open before calling XSync. */
7535 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7536 XSync (x_error_message
->dpy
, False
);
7538 tmp
= x_error_message
;
7539 x_error_message
= x_error_message
->prev
;
7544 /* If any X protocol errors have arrived since the last call to
7545 x_catch_errors or x_check_errors, signal an Emacs error using
7546 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7549 x_check_errors (Display
*dpy
, const char *format
)
7551 /* Make sure to catch any errors incurred so far. */
7554 if (x_error_message
->string
[0])
7556 char string
[X_ERROR_MESSAGE_SIZE
];
7557 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7558 x_uncatch_errors ();
7559 error (format
, string
);
7563 /* Nonzero if we had any X protocol errors
7564 since we did x_catch_errors on DPY. */
7567 x_had_errors_p (Display
*dpy
)
7569 /* Make sure to catch any errors incurred so far. */
7572 return x_error_message
->string
[0] != 0;
7575 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7578 x_clear_errors (Display
*dpy
)
7580 x_error_message
->string
[0] = 0;
7583 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7584 * idea. --lorentey */
7585 /* Close off all unclosed x_catch_errors calls. */
7588 x_fully_uncatch_errors (void)
7590 while (x_error_message
)
7591 x_uncatch_errors ();
7596 static unsigned int x_wire_count
;
7599 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7604 /************************************************************************
7606 ************************************************************************/
7608 /* Error message passed to x_connection_closed. */
7610 static char *error_msg
;
7612 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7613 the text of an error message that lead to the connection loss. */
7616 x_connection_closed (Display
*dpy
, const char *error_message
)
7618 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7619 Lisp_Object frame
, tail
;
7620 ptrdiff_t idx
= SPECPDL_INDEX ();
7622 error_msg
= alloca (strlen (error_message
) + 1);
7623 strcpy (error_msg
, error_message
);
7625 /* Inhibit redisplay while frames are being deleted. */
7626 specbind (Qinhibit_redisplay
, Qt
);
7630 /* Protect display from being closed when we delete the last
7632 dpyinfo
->reference_count
++;
7633 dpyinfo
->terminal
->reference_count
++;
7636 /* First delete frames whose mini-buffers are on frames
7637 that are on the dead display. */
7638 FOR_EACH_FRAME (tail
, frame
)
7640 Lisp_Object minibuf_frame
;
7642 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7643 if (FRAME_X_P (XFRAME (frame
))
7644 && FRAME_X_P (XFRAME (minibuf_frame
))
7645 && ! EQ (frame
, minibuf_frame
)
7646 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7647 delete_frame (frame
, Qnoelisp
);
7650 /* Now delete all remaining frames on the dead display.
7651 We are now sure none of these is used as the mini-buffer
7652 for another frame that we need to delete. */
7653 FOR_EACH_FRAME (tail
, frame
)
7654 if (FRAME_X_P (XFRAME (frame
))
7655 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7657 /* Set this to t so that delete_frame won't get confused
7658 trying to find a replacement. */
7659 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
7660 delete_frame (frame
, Qnoelisp
);
7663 /* If DPYINFO is null, this means we didn't open the display in the
7664 first place, so don't try to close it. */
7667 /* We can not call XtCloseDisplay here because it calls XSync.
7668 XSync inside the error handler apparently hangs Emacs. On
7669 current Xt versions, this isn't needed either. */
7671 /* A long-standing GTK bug prevents proper disconnect handling
7672 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
7673 the resulting Glib error message loop filled a user's disk.
7674 To avoid this, kill Emacs unconditionally on disconnect. */
7675 shut_down_emacs (0, Qnil
);
7676 fprintf (stderr
, "%s\n\
7677 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
7678 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
7679 For details, see etc/PROBLEMS.\n",
7682 #endif /* USE_GTK */
7684 /* Indicate that this display is dead. */
7685 dpyinfo
->display
= 0;
7687 dpyinfo
->reference_count
--;
7688 dpyinfo
->terminal
->reference_count
--;
7689 if (dpyinfo
->reference_count
!= 0)
7690 /* We have just closed all frames on this display. */
7695 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7696 Fdelete_terminal (tmp
, Qnoelisp
);
7700 if (terminal_list
== 0)
7702 fprintf (stderr
, "%s\n", error_msg
);
7703 Fkill_emacs (make_number (70));
7707 totally_unblock_input ();
7709 unbind_to (idx
, Qnil
);
7710 clear_waiting_for_input ();
7712 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
7713 IF_LINT (if (! terminal_list
) return; )
7715 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7716 longjmp), because returning from this function would get us back into
7717 Xlib's code which will directly call `exit'. */
7718 error ("%s", error_msg
);
7721 /* We specifically use it before defining it, so that gcc doesn't inline it,
7722 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7723 static void x_error_quitter (Display
*, XErrorEvent
*);
7725 /* This is the first-level handler for X protocol errors.
7726 It calls x_error_quitter or x_error_catcher. */
7729 x_error_handler (Display
*display
, XErrorEvent
*event
)
7731 #if defined USE_GTK && defined HAVE_GTK3
7732 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
7733 && event
->request_code
== X_SetInputFocus
)
7739 if (x_error_message
)
7740 x_error_catcher (display
, event
);
7742 x_error_quitter (display
, event
);
7746 /* This is the usual handler for X protocol errors.
7747 It kills all frames on the display that we got the error for.
7748 If that was the only one, it prints an error message and kills Emacs. */
7750 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7752 /* On older GCC versions, just putting x_error_quitter
7753 after x_error_handler prevents inlining into the former. */
7755 static void NO_INLINE
7756 x_error_quitter (Display
*display
, XErrorEvent
*event
)
7758 char buf
[256], buf1
[356];
7760 /* Ignore BadName errors. They can happen because of fonts
7761 or colors that are not defined. */
7763 if (event
->error_code
== BadName
)
7766 /* Note that there is no real way portable across R3/R4 to get the
7767 original error handler. */
7769 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
7770 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7771 buf
, event
->request_code
);
7772 x_connection_closed (display
, buf1
);
7776 /* This is the handler for X IO errors, always.
7777 It kills all frames on the display that we lost touch with.
7778 If that was the only one, it prints an error message and kills Emacs. */
7781 x_io_error_quitter (Display
*display
)
7785 snprintf (buf
, sizeof buf
, "Connection lost to X server `%s'",
7786 DisplayString (display
));
7787 x_connection_closed (display
, buf
);
7791 /* Changing the font of the frame. */
7793 /* Give frame F the font FONT-OBJECT as its default font. The return
7794 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7795 frame. If it is negative, generate a new fontset from
7799 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7801 struct font
*font
= XFONT_OBJECT (font_object
);
7804 fontset
= fontset_from_font (font_object
);
7805 FRAME_FONTSET (f
) = fontset
;
7806 if (FRAME_FONT (f
) == font
)
7807 /* This font is already set in frame F. There's nothing more to
7811 FRAME_FONT (f
) = font
;
7812 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7813 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7814 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7816 compute_fringe_widths (f
, 1);
7818 /* Compute the scroll bar width in character columns. */
7819 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7821 int wid
= FRAME_COLUMN_WIDTH (f
);
7822 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7823 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7827 int wid
= FRAME_COLUMN_WIDTH (f
);
7828 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7831 if (FRAME_X_WINDOW (f
) != 0)
7833 /* Don't change the size of a tip frame; there's no point in
7834 doing it because it's done in Fx_show_tip, and it leads to
7835 problems because the tip frame has no widget. */
7836 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7837 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7842 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7845 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
7854 /***********************************************************************
7856 ***********************************************************************/
7862 /* XIM destroy callback function, which is called whenever the
7863 connection to input method XIM dies. CLIENT_DATA contains a
7864 pointer to the x_display_info structure corresponding to XIM. */
7867 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
7869 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7870 Lisp_Object frame
, tail
;
7874 /* No need to call XDestroyIC.. */
7875 FOR_EACH_FRAME (tail
, frame
)
7877 struct frame
*f
= XFRAME (frame
);
7878 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
7880 FRAME_XIC (f
) = NULL
;
7881 xic_free_xfontset (f
);
7885 /* No need to call XCloseIM. */
7886 dpyinfo
->xim
= NULL
;
7887 XFree (dpyinfo
->xim_styles
);
7891 #endif /* HAVE_X11R6 */
7894 /* This isn't prototyped in OSF 5.0 or 5.1a. */
7895 extern char *XSetIMValues (XIM
, ...);
7898 /* Open the connection to the XIM server on display DPYINFO.
7899 RESOURCE_NAME is the resource name Emacs uses. */
7902 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
7910 XCloseIM (dpyinfo
->xim
);
7911 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
7918 XIMCallback destroy
;
7921 /* Get supported styles and XIM values. */
7922 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
7925 destroy
.callback
= xim_destroy_callback
;
7926 destroy
.client_data
= (XPointer
)dpyinfo
;
7927 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
7933 #endif /* HAVE_XIM */
7934 dpyinfo
->xim
= NULL
;
7938 #ifdef HAVE_X11R6_XIM
7940 /* XIM instantiate callback function, which is called whenever an XIM
7941 server is available. DISPLAY is the display of the XIM.
7942 CLIENT_DATA contains a pointer to an xim_inst_t structure created
7943 when the callback was registered. */
7946 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
7948 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
7949 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
7951 /* We don't support multiple XIM connections. */
7955 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
7957 /* Create XIC for the existing frames on the same display, as long
7958 as they have no XIC. */
7959 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
7961 Lisp_Object tail
, frame
;
7964 FOR_EACH_FRAME (tail
, frame
)
7966 struct frame
*f
= XFRAME (frame
);
7969 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
7970 if (FRAME_XIC (f
) == NULL
)
7972 create_frame_xic (f
);
7973 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
7974 xic_set_statusarea (f
);
7975 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
7977 struct window
*w
= XWINDOW (f
->selected_window
);
7978 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
7987 #endif /* HAVE_X11R6_XIM */
7990 /* Open a connection to the XIM server on display DPYINFO.
7991 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
7992 connection only at the first time. On X11R6, open the connection
7993 in the XIM instantiate callback function. */
7996 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
7998 dpyinfo
->xim
= NULL
;
8002 #ifdef HAVE_X11R6_XIM
8003 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
8005 dpyinfo
->xim_callback_data
= xim_inst
;
8006 xim_inst
->dpyinfo
= dpyinfo
;
8007 xim_inst
->resource_name
= xstrdup (resource_name
);
8008 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8009 resource_name
, emacs_class
,
8010 xim_instantiate_callback
,
8011 /* This is XPointer in XFree86
8012 but (XPointer *) on Tru64, at
8013 least, hence the configure test. */
8014 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8015 #else /* not HAVE_X11R6_XIM */
8016 xim_open_dpy (dpyinfo
, resource_name
);
8017 #endif /* not HAVE_X11R6_XIM */
8019 #endif /* HAVE_XIM */
8023 /* Close the connection to the XIM server on display DPYINFO. */
8026 xim_close_dpy (struct x_display_info
*dpyinfo
)
8031 #ifdef HAVE_X11R6_XIM
8032 if (dpyinfo
->display
)
8033 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8035 xim_instantiate_callback
, NULL
);
8036 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8037 xfree (dpyinfo
->xim_callback_data
);
8038 #endif /* HAVE_X11R6_XIM */
8039 if (dpyinfo
->display
)
8040 XCloseIM (dpyinfo
->xim
);
8041 dpyinfo
->xim
= NULL
;
8042 XFree (dpyinfo
->xim_styles
);
8044 #endif /* HAVE_XIM */
8047 #endif /* not HAVE_X11R6_XIM */
8051 /* Calculate the absolute position in frame F
8052 from its current recorded position values and gravity. */
8055 x_calc_absolute_position (struct frame
*f
)
8057 int flags
= f
->size_hint_flags
;
8059 /* We have nothing to do if the current position
8060 is already for the top-left corner. */
8061 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8064 /* Treat negative positions as relative to the leftmost bottommost
8065 position that fits on the screen. */
8066 if (flags
& XNegative
)
8067 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8068 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8071 int height
= FRAME_PIXEL_HEIGHT (f
);
8073 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8074 /* Something is fishy here. When using Motif, starting Emacs with
8075 `-g -0-0', the frame appears too low by a few pixels.
8077 This seems to be so because initially, while Emacs is starting,
8078 the column widget's height and the frame's pixel height are
8079 different. The column widget's height is the right one. In
8080 later invocations, when Emacs is up, the frame's pixel height
8083 It's not obvious where the initial small difference comes from.
8084 2000-12-01, gerd. */
8086 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8089 if (flags
& YNegative
)
8090 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8091 - height
+ f
->top_pos
;
8094 /* The left_pos and top_pos
8095 are now relative to the top and left screen edges,
8096 so the flags should correspond. */
8097 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8100 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8101 to really change the position, and 0 when calling from
8102 x_make_frame_visible (in that case, XOFF and YOFF are the current
8103 position values). It is -1 when calling from x_set_frame_parameters,
8104 which means, do adjust for borders but don't change the gravity. */
8107 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8109 int modified_top
, modified_left
;
8111 if (change_gravity
> 0)
8115 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8117 f
->size_hint_flags
|= XNegative
;
8119 f
->size_hint_flags
|= YNegative
;
8120 f
->win_gravity
= NorthWestGravity
;
8122 x_calc_absolute_position (f
);
8125 x_wm_set_size_hint (f
, (long) 0, 0);
8127 modified_left
= f
->left_pos
;
8128 modified_top
= f
->top_pos
;
8130 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8132 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8133 than the WM decorations. So we use the calculated offset instead
8134 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8135 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8136 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8139 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8140 modified_left
, modified_top
);
8142 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8143 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8146 /* change_gravity is non-zero when this function is called from Lisp to
8147 programmatically move a frame. In that case, we call
8148 x_check_expected_move to discover if we have a "Type A" or "Type B"
8149 window manager, and, for a "Type A" window manager, adjust the position
8152 We call x_check_expected_move if a programmatic move occurred, and
8153 either the window manager type (A/B) is unknown or it is Type A but we
8154 need to compute the top/left offset adjustment for this frame. */
8156 if (change_gravity
!= 0 &&
8157 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8158 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8159 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8160 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8161 x_check_expected_move (f
, modified_left
, modified_top
);
8166 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8167 on the root window for frame F contains ATOMNAME.
8168 This is how a WM check shall be done according to the Window Manager
8169 Specification/Extended Window Manager Hints at
8170 http://freedesktop.org/wiki/Specifications/wm-spec. */
8173 wm_supports (struct frame
*f
, Atom want_atom
)
8176 unsigned long actual_size
, bytes_remaining
;
8177 int i
, rc
, actual_format
;
8178 Window wmcheck_window
;
8179 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8180 Window target_window
= dpyinfo
->root_window
;
8181 long max_len
= 65536;
8182 Display
*dpy
= FRAME_X_DISPLAY (f
);
8183 unsigned char *tmp_data
= NULL
;
8184 Atom target_type
= XA_WINDOW
;
8188 x_catch_errors (dpy
);
8189 rc
= XGetWindowProperty (dpy
, target_window
,
8190 dpyinfo
->Xatom_net_supporting_wm_check
,
8191 0, max_len
, False
, target_type
,
8192 &actual_type
, &actual_format
, &actual_size
,
8193 &bytes_remaining
, &tmp_data
);
8195 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8197 if (tmp_data
) XFree (tmp_data
);
8198 x_uncatch_errors ();
8203 wmcheck_window
= *(Window
*) tmp_data
;
8206 /* Check if window exists. */
8207 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8209 if (x_had_errors_p (dpy
))
8211 x_uncatch_errors ();
8216 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8218 /* Window changed, reload atoms */
8219 if (dpyinfo
->net_supported_atoms
!= NULL
)
8220 XFree (dpyinfo
->net_supported_atoms
);
8221 dpyinfo
->net_supported_atoms
= NULL
;
8222 dpyinfo
->nr_net_supported_atoms
= 0;
8223 dpyinfo
->net_supported_window
= 0;
8225 target_type
= XA_ATOM
;
8227 rc
= XGetWindowProperty (dpy
, target_window
,
8228 dpyinfo
->Xatom_net_supported
,
8229 0, max_len
, False
, target_type
,
8230 &actual_type
, &actual_format
, &actual_size
,
8231 &bytes_remaining
, &tmp_data
);
8233 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8235 if (tmp_data
) XFree (tmp_data
);
8236 x_uncatch_errors ();
8241 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8242 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8243 dpyinfo
->net_supported_window
= wmcheck_window
;
8248 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8249 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8251 x_uncatch_errors ();
8258 set_wm_state (Lisp_Object frame
, int add
, Atom atom
, Atom value
)
8260 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (frame
));
8262 x_send_client_event (frame
, make_number (0), frame
,
8263 dpyinfo
->Xatom_net_wm_state
,
8265 /* 1 = add, 0 = remove */
8267 (make_number (add
? 1 : 0),
8269 (make_fixnum_or_float (atom
),
8271 ? list1 (make_fixnum_or_float (value
))
8276 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8279 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8281 XSETFRAME (frame
, f
);
8283 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8284 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
8287 /* Return the current _NET_WM_STATE.
8288 SIZE_STATE is set to one of the FULLSCREEN_* values.
8289 STICKY is set to 1 if the sticky state is set, 0 if not.
8291 Return non-zero if we are not hidden, zero if we are. */
8294 get_current_wm_state (struct frame
*f
,
8300 unsigned long actual_size
, bytes_remaining
;
8301 int i
, rc
, actual_format
, is_hidden
= 0;
8302 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8303 long max_len
= 65536;
8304 Display
*dpy
= FRAME_X_DISPLAY (f
);
8305 unsigned char *tmp_data
= NULL
;
8306 Atom target_type
= XA_ATOM
;
8309 *size_state
= FULLSCREEN_NONE
;
8312 x_catch_errors (dpy
);
8313 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
8314 0, max_len
, False
, target_type
,
8315 &actual_type
, &actual_format
, &actual_size
,
8316 &bytes_remaining
, &tmp_data
);
8318 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8320 if (tmp_data
) XFree (tmp_data
);
8321 x_uncatch_errors ();
8323 return !FRAME_ICONIFIED_P (f
);
8326 x_uncatch_errors ();
8328 for (i
= 0; i
< actual_size
; ++i
)
8330 Atom a
= ((Atom
*)tmp_data
)[i
];
8331 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
8334 f
->output_data
.x
->net_wm_state_hidden_seen
= 1;
8336 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8338 if (*size_state
== FULLSCREEN_HEIGHT
)
8339 *size_state
= FULLSCREEN_MAXIMIZED
;
8341 *size_state
= FULLSCREEN_WIDTH
;
8343 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8345 if (*size_state
== FULLSCREEN_WIDTH
)
8346 *size_state
= FULLSCREEN_MAXIMIZED
;
8348 *size_state
= FULLSCREEN_HEIGHT
;
8350 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
8351 *size_state
= FULLSCREEN_BOTH
;
8352 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8356 if (tmp_data
) XFree (tmp_data
);
8361 /* Do fullscreen as specified in extended window manager hints */
8364 do_ewmh_fullscreen (struct frame
*f
)
8366 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8367 int have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
8370 (void)get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
8372 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8373 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8375 have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
8377 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
8381 XSETFRAME (frame
, f
);
8383 /* Keep number of calls to set_wm_state as low as possible.
8384 Some window managers, or possible Gtk+, hangs when too many
8385 are sent at once. */
8386 switch (f
->want_fullscreen
)
8388 case FULLSCREEN_BOTH
:
8389 if (cur
== FULLSCREEN_WIDTH
|| cur
== FULLSCREEN_MAXIMIZED
8390 || cur
== FULLSCREEN_HEIGHT
)
8391 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8392 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8393 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8395 case FULLSCREEN_WIDTH
:
8396 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
8397 || cur
== FULLSCREEN_MAXIMIZED
)
8398 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8399 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8400 if (cur
!= FULLSCREEN_MAXIMIZED
)
8401 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
8403 case FULLSCREEN_HEIGHT
:
8404 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
8405 || cur
== FULLSCREEN_MAXIMIZED
)
8406 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8407 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
8408 if (cur
!= FULLSCREEN_MAXIMIZED
)
8409 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
8411 case FULLSCREEN_MAXIMIZED
:
8412 if (cur
== FULLSCREEN_BOTH
)
8413 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8414 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8415 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8417 case FULLSCREEN_NONE
:
8418 if (cur
== FULLSCREEN_BOTH
)
8419 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8421 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8422 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8425 f
->want_fullscreen
= FULLSCREEN_NONE
;
8429 return have_net_atom
;
8433 XTfullscreen_hook (struct frame
*f
)
8435 if (FRAME_VISIBLE_P (f
))
8438 x_check_fullscreen (f
);
8446 x_handle_net_wm_state (struct frame
*f
, XPropertyEvent
*event
)
8448 int value
= FULLSCREEN_NONE
;
8451 int not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
8456 case FULLSCREEN_WIDTH
:
8459 case FULLSCREEN_HEIGHT
:
8462 case FULLSCREEN_BOTH
:
8465 case FULLSCREEN_MAXIMIZED
:
8470 store_frame_param (f
, Qfullscreen
, lval
);
8471 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8476 /* Check if we need to resize the frame due to a fullscreen request.
8477 If so needed, resize the frame. */
8479 x_check_fullscreen (struct frame
*f
)
8481 if (do_ewmh_fullscreen (f
))
8484 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8485 return; /* Only fullscreen without WM or with EWM hints (above). */
8487 /* Setting fullscreen to nil doesn't do anything. We could save the
8488 last non-fullscreen size and restore it, but it seems like a
8489 lot of work for this unusual case (no window manager running). */
8491 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8493 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
8494 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8496 switch (f
->want_fullscreen
)
8498 /* No difference between these two when there is no WM */
8499 case FULLSCREEN_BOTH
:
8500 case FULLSCREEN_MAXIMIZED
:
8501 width
= x_display_pixel_width (dpyinfo
);
8502 height
= x_display_pixel_height (dpyinfo
);
8504 case FULLSCREEN_WIDTH
:
8505 width
= x_display_pixel_width (dpyinfo
);
8507 case FULLSCREEN_HEIGHT
:
8508 height
= x_display_pixel_height (dpyinfo
);
8511 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8516 /* This function is called by x_set_offset to determine whether the window
8517 manager interfered with the positioning of the frame. Type A window
8518 managers position the surrounding window manager decorations a small
8519 amount above and left of the user-supplied position. Type B window
8520 managers position the surrounding window manager decorations at the
8521 user-specified position. If we detect a Type A window manager, we
8522 compensate by moving the window right and down by the proper amount. */
8525 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8527 int current_left
= 0, current_top
= 0;
8529 /* x_real_positions returns the left and top offsets of the outermost
8530 window manager window around the frame. */
8532 x_real_positions (f
, ¤t_left
, ¤t_top
);
8534 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8536 /* It's a "Type A" window manager. */
8541 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8542 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8543 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8545 /* Now fix the mispositioned frame's location. */
8547 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8548 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8550 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8551 adjusted_left
, adjusted_top
);
8553 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8556 /* It's a "Type B" window manager. We don't have to adjust the
8557 frame's position. */
8559 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8563 /* Wait for XGetGeometry to return up-to-date position information for a
8564 recently-moved frame. Call this immediately after calling XMoveWindow.
8565 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8566 frame has been moved to, so we use a fuzzy position comparison instead
8567 of an exact comparison. */
8570 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8574 while (count
++ < 50)
8576 int current_left
= 0, current_top
= 0;
8578 /* In theory, this call to XSync only needs to happen once, but in
8579 practice, it doesn't seem to work, hence the need for the surrounding
8582 XSync (FRAME_X_DISPLAY (f
), False
);
8583 x_real_positions (f
, ¤t_left
, ¤t_top
);
8587 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8590 if (eabs (current_left
- left
) <= 10
8591 && eabs (current_top
- top
) <= 40)
8594 else if (current_left
== left
&& current_top
== top
)
8598 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8599 will then return up-to-date position info. */
8601 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8605 /* Wait for an event on frame F matching EVENTTYPE. */
8607 x_wait_for_event (struct frame
*f
, int eventtype
)
8609 int level
= interrupt_input_blocked
;
8612 struct timespec tmo
, tmo_at
, time_now
;
8613 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8615 pending_event_wait
.f
= f
;
8616 pending_event_wait
.eventtype
= eventtype
;
8618 /* Set timeout to 0.1 second. Hopefully not noticeable.
8619 Maybe it should be configurable. */
8620 tmo
= make_timespec (0, 100 * 1000 * 1000);
8621 tmo_at
= timespec_add (current_timespec (), tmo
);
8623 while (pending_event_wait
.eventtype
)
8625 pending_signals
= 1;
8626 totally_unblock_input ();
8627 /* XTread_socket is called after unblock. */
8629 interrupt_input_blocked
= level
;
8634 time_now
= current_timespec ();
8635 if (timespec_cmp (tmo_at
, time_now
) < 0)
8638 tmo
= timespec_sub (tmo_at
, time_now
);
8639 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
8640 break; /* Timeout */
8642 pending_event_wait
.f
= 0;
8643 pending_event_wait
.eventtype
= 0;
8647 /* Change the size of frame F's X window to COLS/ROWS in the case F
8648 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8649 top-left-corner window gravity for this size change and subsequent
8650 size changes. Otherwise we leave the window gravity unchanged. */
8653 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8655 int pixelwidth
, pixelheight
;
8657 check_frame_size (f
, &rows
, &cols
);
8658 f
->scroll_bar_actual_width
8659 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8661 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8663 compute_fringe_widths (f
, 0);
8665 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8666 + FRAME_TOOLBAR_WIDTH (f
);
8667 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8668 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8670 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8671 x_wm_set_size_hint (f
, (long) 0, 0);
8672 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8673 pixelwidth
, pixelheight
);
8676 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8677 receive in the ConfigureNotify event; if we get what we asked
8678 for, then the event won't cause the screen to become garbaged, so
8679 we have to make sure to do it here. */
8680 SET_FRAME_GARBAGED (f
);
8682 /* Now, strictly speaking, we can't be sure that this is accurate,
8683 but the window manager will get around to dealing with the size
8684 change request eventually, and we'll hear how it went when the
8685 ConfigureNotify event gets here.
8687 We could just not bother storing any of this information here,
8688 and let the ConfigureNotify event set everything up, but that
8689 might be kind of confusing to the Lisp code, since size changes
8690 wouldn't be reported in the frame parameters until some random
8691 point in the future when the ConfigureNotify event arrives.
8693 We pass 1 for DELAY since we can't run Lisp code inside of
8696 /* But the ConfigureNotify may in fact never arrive, and then this is
8697 not right if the frame is visible. Instead wait (with timeout)
8698 for the ConfigureNotify. */
8699 if (FRAME_VISIBLE_P (f
))
8700 x_wait_for_event (f
, ConfigureNotify
);
8703 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8704 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8705 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8711 /* Call this to change the size of frame F's x-window.
8712 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8713 for this size change and subsequent size changes.
8714 Otherwise we leave the window gravity unchanged. */
8717 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8721 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8725 /* When the frame is maximized/fullscreen or running under for
8726 example Xmonad, x_set_window_size_1 will be a no-op.
8727 In that case, the right thing to do is extend rows/cols to
8728 the current frame size. We do that first if x_set_window_size_1
8729 turns out to not be a no-op (there is no way to know).
8730 The size will be adjusted again if the frame gets a
8731 ConfigureNotify event as a result of x_set_window_size. */
8732 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8733 #ifdef USE_X_TOOLKIT
8734 /* The menu bar is not part of text lines. The tool bar
8736 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8738 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8739 /* Update f->scroll_bar_actual_width because it is used in
8740 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8741 f
->scroll_bar_actual_width
8742 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8743 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8744 change_frame_size (f
, r
, c
, 0, 1, 0);
8748 if (FRAME_GTK_WIDGET (f
))
8749 xg_frame_set_char_size (f
, cols
, rows
);
8751 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8752 #else /* not USE_GTK */
8754 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8756 #endif /* not USE_GTK */
8758 /* If cursor was outside the new size, mark it as off. */
8759 mark_window_cursors_off (XWINDOW (f
->root_window
));
8761 /* Clear out any recollection of where the mouse highlighting was,
8762 since it might be in a place that's outside the new frame size.
8763 Actually checking whether it is outside is a pain in the neck,
8764 so don't try--just let the highlighting be done afresh with new size. */
8765 cancel_mouse_face (f
);
8770 /* Mouse warping. */
8773 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8777 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8778 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8780 if (pix_x
< 0) pix_x
= 0;
8781 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8783 if (pix_y
< 0) pix_y
= 0;
8784 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8788 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8789 0, 0, 0, 0, pix_x
, pix_y
);
8793 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8796 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8800 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8801 0, 0, 0, 0, pix_x
, pix_y
);
8805 /* Raise frame F. */
8808 x_raise_frame (struct frame
*f
)
8811 if (FRAME_VISIBLE_P (f
))
8812 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8813 XFlush (FRAME_X_DISPLAY (f
));
8817 /* Lower frame F. */
8820 x_lower_frame (struct frame
*f
)
8822 if (FRAME_VISIBLE_P (f
))
8825 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8826 XFlush (FRAME_X_DISPLAY (f
));
8831 /* Request focus with XEmbed */
8834 xembed_request_focus (struct frame
*f
)
8836 /* See XEmbed Protocol Specification at
8837 http://freedesktop.org/wiki/Specifications/xembed-spec */
8838 if (FRAME_VISIBLE_P (f
))
8839 xembed_send_message (f
, CurrentTime
,
8840 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
8843 /* Activate frame with Extended Window Manager Hints */
8846 x_ewmh_activate_frame (struct frame
*f
)
8848 /* See Window Manager Specification/Extended Window Manager Hints at
8849 http://freedesktop.org/wiki/Specifications/wm-spec */
8851 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8853 if (FRAME_VISIBLE_P (f
) && wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
8856 XSETFRAME (frame
, f
);
8857 x_send_client_event (frame
, make_number (0), frame
,
8858 dpyinfo
->Xatom_net_active_window
,
8860 list2i (1, dpyinfo
->last_user_time
));
8865 XTframe_raise_lower (struct frame
*f
, int raise_flag
)
8873 /* XEmbed implementation. */
8875 #if defined USE_X_TOOLKIT || ! defined USE_GTK
8877 /* XEmbed implementation. */
8879 #define XEMBED_VERSION 0
8882 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
8884 unsigned long data
[2];
8885 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8887 data
[0] = XEMBED_VERSION
;
8890 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8891 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
8892 32, PropModeReplace
, (unsigned char *) data
, 2);
8894 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
8897 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
8898 long int detail
, long int data1
, long int data2
)
8902 event
.xclient
.type
= ClientMessage
;
8903 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
8904 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
8905 event
.xclient
.format
= 32;
8906 event
.xclient
.data
.l
[0] = t
;
8907 event
.xclient
.data
.l
[1] = msg
;
8908 event
.xclient
.data
.l
[2] = detail
;
8909 event
.xclient
.data
.l
[3] = data1
;
8910 event
.xclient
.data
.l
[4] = data2
;
8912 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
8913 False
, NoEventMask
, &event
);
8914 XSync (FRAME_X_DISPLAY (f
), False
);
8917 /* Change of visibility. */
8919 /* This tries to wait until the frame is really visible.
8920 However, if the window manager asks the user where to position
8921 the frame, this will return before the user finishes doing that.
8922 The frame will not actually be visible at that time,
8923 but it will become visible later when the window manager
8924 finishes with it. */
8927 x_make_frame_visible (struct frame
*f
)
8930 int original_top
, original_left
;
8931 int retry_count
= 2;
8937 type
= x_icon_type (f
);
8939 x_bitmap_icon (f
, type
);
8941 if (! FRAME_VISIBLE_P (f
))
8943 /* We test FRAME_GARBAGED_P here to make sure we don't
8944 call x_set_offset a second time
8945 if we get to x_make_frame_visible a second time
8946 before the window gets really visible. */
8947 if (! FRAME_ICONIFIED_P (f
)
8948 && ! FRAME_X_EMBEDDED_P (f
)
8949 && ! f
->output_data
.x
->asked_for_visible
)
8950 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8952 f
->output_data
.x
->asked_for_visible
= 1;
8954 if (! EQ (Vx_no_window_manager
, Qt
))
8955 x_wm_set_window_state (f
, NormalState
);
8956 #ifdef USE_X_TOOLKIT
8957 if (FRAME_X_EMBEDDED_P (f
))
8958 xembed_set_info (f
, XEMBED_MAPPED
);
8961 /* This was XtPopup, but that did nothing for an iconified frame. */
8962 XtMapWidget (f
->output_data
.x
->widget
);
8964 #else /* not USE_X_TOOLKIT */
8966 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8967 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8969 if (FRAME_X_EMBEDDED_P (f
))
8970 xembed_set_info (f
, XEMBED_MAPPED
);
8972 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8973 #endif /* not USE_GTK */
8974 #endif /* not USE_X_TOOLKIT */
8977 XFlush (FRAME_X_DISPLAY (f
));
8979 /* Synchronize to ensure Emacs knows the frame is visible
8980 before we do anything else. We do this loop with input not blocked
8981 so that incoming events are handled. */
8985 /* This must be before UNBLOCK_INPUT
8986 since events that arrive in response to the actions above
8987 will set it when they are handled. */
8988 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8990 original_left
= f
->left_pos
;
8991 original_top
= f
->top_pos
;
8993 /* This must come after we set COUNT. */
8996 /* We unblock here so that arriving X events are processed. */
8998 /* Now move the window back to where it was "supposed to be".
8999 But don't do it if the gravity is negative.
9000 When the gravity is negative, this uses a position
9001 that is 3 pixels too low. Perhaps that's really the border width.
9003 Don't do this if the window has never been visible before,
9004 because the window manager may choose the position
9005 and we don't want to override it. */
9007 if (! FRAME_VISIBLE_P (f
)
9008 && ! FRAME_ICONIFIED_P (f
)
9009 && ! FRAME_X_EMBEDDED_P (f
)
9010 && f
->win_gravity
== NorthWestGravity
9011 && previously_visible
)
9015 unsigned int width
, height
, border
, depth
;
9019 /* On some window managers (such as FVWM) moving an existing
9020 window, even to the same place, causes the window manager
9021 to introduce an offset. This can cause the window to move
9022 to an unexpected location. Check the geometry (a little
9023 slow here) and then verify that the window is in the right
9024 place. If the window is not in the right place, move it
9025 there, and take the potential window manager hit. */
9026 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9027 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9029 if (original_left
!= x
|| original_top
!= y
)
9030 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9031 original_left
, original_top
);
9036 XSETFRAME (frame
, f
);
9038 /* Wait until the frame is visible. Process X events until a
9039 MapNotify event has been seen, or until we think we won't get a
9040 MapNotify at all.. */
9041 for (count
= input_signal_count
+ 10;
9042 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9044 /* Force processing of queued events. */
9047 /* Machines that do polling rather than SIGIO have been
9048 observed to go into a busy-wait here. So we'll fake an
9049 alarm signal to let the handler know that there's something
9050 to be read. We used to raise a real alarm, but it seems
9051 that the handler isn't always enabled here. This is
9053 if (input_polling_used ())
9055 /* It could be confusing if a real alarm arrives while
9056 processing the fake one. Turn it off and let the
9057 handler reset it. */
9058 int old_poll_suppress_count
= poll_suppress_count
;
9059 poll_suppress_count
= 1;
9060 poll_for_input_1 ();
9061 poll_suppress_count
= old_poll_suppress_count
;
9067 (let ((f (selected-frame)))
9071 the frame is not raised with various window managers on
9072 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9073 unknown reason, the call to XtMapWidget is completely ignored.
9074 Mapping the widget a second time works. */
9076 if (!FRAME_VISIBLE_P (f
) && --retry_count
!= 0)
9081 /* Change from mapped state to withdrawn state. */
9083 /* Make the frame visible (mapped and not iconified). */
9086 x_make_frame_invisible (struct frame
*f
)
9090 /* Use the frame's outermost window, not the one we normally draw on. */
9091 window
= FRAME_OUTER_WINDOW (f
);
9093 /* Don't keep the highlight on an invisible frame. */
9094 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9095 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9099 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9100 that the current position of the window is user-specified, rather than
9101 program-specified, so that when the window is mapped again, it will be
9102 placed at the same location, without forcing the user to position it
9103 by hand again (they have already done that once for this window.) */
9104 x_wm_set_size_hint (f
, (long) 0, 1);
9107 if (FRAME_GTK_OUTER_WIDGET (f
))
9108 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9111 if (FRAME_X_EMBEDDED_P (f
))
9112 xembed_set_info (f
, 0);
9117 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9118 DefaultScreen (FRAME_X_DISPLAY (f
))))
9121 error ("Can't notify window manager of window withdrawal");
9125 /* We can't distinguish this from iconification
9126 just by the event that we get from the server.
9127 So we can't win using the usual strategy of letting
9128 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9129 and synchronize with the server to make sure we agree. */
9130 SET_FRAME_VISIBLE (f
, 0);
9131 SET_FRAME_ICONIFIED (f
, 0);
9138 /* Change window state from mapped to iconified. */
9141 x_iconify_frame (struct frame
*f
)
9143 #ifdef USE_X_TOOLKIT
9148 /* Don't keep the highlight on an invisible frame. */
9149 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9150 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9152 if (FRAME_ICONIFIED_P (f
))
9157 type
= x_icon_type (f
);
9159 x_bitmap_icon (f
, type
);
9161 #if defined (USE_GTK)
9162 if (FRAME_GTK_OUTER_WIDGET (f
))
9164 if (! FRAME_VISIBLE_P (f
))
9165 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9167 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9168 SET_FRAME_VISIBLE (f
, 0);
9169 SET_FRAME_ICONIFIED (f
, 1);
9175 #ifdef USE_X_TOOLKIT
9177 if (! FRAME_VISIBLE_P (f
))
9179 if (! EQ (Vx_no_window_manager
, Qt
))
9180 x_wm_set_window_state (f
, IconicState
);
9181 /* This was XtPopup, but that did nothing for an iconified frame. */
9182 XtMapWidget (f
->output_data
.x
->widget
);
9183 /* The server won't give us any event to indicate
9184 that an invisible frame was changed to an icon,
9185 so we have to record it here. */
9186 SET_FRAME_VISIBLE (f
, 0);
9187 SET_FRAME_ICONIFIED (f
, 1);
9192 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9193 XtWindow (f
->output_data
.x
->widget
),
9194 DefaultScreen (FRAME_X_DISPLAY (f
)));
9198 error ("Can't notify window manager of iconification");
9200 SET_FRAME_ICONIFIED (f
, 1);
9201 SET_FRAME_VISIBLE (f
, 0);
9204 XFlush (FRAME_X_DISPLAY (f
));
9206 #else /* not USE_X_TOOLKIT */
9208 /* Make sure the X server knows where the window should be positioned,
9209 in case the user deiconifies with the window manager. */
9210 if (! FRAME_VISIBLE_P (f
)
9211 && ! FRAME_ICONIFIED_P (f
)
9212 && ! FRAME_X_EMBEDDED_P (f
))
9213 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9215 /* Since we don't know which revision of X we're running, we'll use both
9216 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9218 /* X11R4: send a ClientMessage to the window manager using the
9219 WM_CHANGE_STATE type. */
9223 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
9224 msg
.xclient
.type
= ClientMessage
;
9225 msg
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9226 msg
.xclient
.format
= 32;
9227 msg
.xclient
.data
.l
[0] = IconicState
;
9229 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9230 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9232 SubstructureRedirectMask
| SubstructureNotifyMask
,
9236 error ("Can't notify window manager of iconification");
9240 /* X11R3: set the initial_state field of the window manager hints to
9242 x_wm_set_window_state (f
, IconicState
);
9244 if (!FRAME_VISIBLE_P (f
))
9246 /* If the frame was withdrawn, before, we must map it. */
9247 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9250 SET_FRAME_ICONIFIED (f
, 1);
9251 SET_FRAME_VISIBLE (f
, 0);
9253 XFlush (FRAME_X_DISPLAY (f
));
9255 #endif /* not USE_X_TOOLKIT */
9259 /* Free X resources of frame F. */
9262 x_free_frame_resources (struct frame
*f
)
9264 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9265 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
9266 #ifdef USE_X_TOOLKIT
9268 struct scroll_bar
*b
;
9273 /* If a display connection is dead, don't try sending more
9274 commands to the X server. */
9275 if (dpyinfo
->display
)
9277 /* We must free faces before destroying windows because some
9278 font-driver (e.g. xft) access a window while finishing a
9280 if (FRAME_FACE_CACHE (f
))
9281 free_frame_faces (f
);
9283 if (f
->output_data
.x
->icon_desc
)
9284 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9286 #ifdef USE_X_TOOLKIT
9287 /* Explicitly destroy the scroll bars of the frame. Without
9288 this, we get "BadDrawable" errors from the toolkit later on,
9289 presumably from expose events generated for the disappearing
9290 toolkit scroll bars. */
9291 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9293 b
= XSCROLL_BAR (bar
);
9294 x_scroll_bar_remove (b
);
9303 #ifdef USE_X_TOOLKIT
9304 if (f
->output_data
.x
->widget
)
9306 XtDestroyWidget (f
->output_data
.x
->widget
);
9307 f
->output_data
.x
->widget
= NULL
;
9309 /* Tooltips don't have widgets, only a simple X window, even if
9310 we are using a toolkit. */
9311 else if (FRAME_X_WINDOW (f
))
9312 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9314 free_frame_menubar (f
);
9315 #else /* !USE_X_TOOLKIT */
9318 xg_free_frame_widgets (f
);
9319 #endif /* USE_GTK */
9321 if (FRAME_X_WINDOW (f
))
9322 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9323 #endif /* !USE_X_TOOLKIT */
9325 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9326 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9327 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9328 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9329 unload_color (f
, f
->output_data
.x
->border_pixel
);
9330 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9332 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9333 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9334 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9335 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9336 #ifdef USE_TOOLKIT_SCROLL_BARS
9337 /* Scrollbar shadow colors. */
9338 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9339 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9340 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9341 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9342 #endif /* USE_TOOLKIT_SCROLL_BARS */
9343 if (f
->output_data
.x
->white_relief
.allocated_p
)
9344 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9345 if (f
->output_data
.x
->black_relief
.allocated_p
)
9346 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9350 /* Free extra GCs allocated by x_setup_relief_colors. */
9351 if (f
->output_data
.x
->white_relief
.gc
)
9353 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
9354 f
->output_data
.x
->white_relief
.gc
= 0;
9356 if (f
->output_data
.x
->black_relief
.gc
)
9358 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
9359 f
->output_data
.x
->black_relief
.gc
= 0;
9362 XFlush (FRAME_X_DISPLAY (f
));
9365 xfree (f
->output_data
.x
->saved_menu_event
);
9366 xfree (f
->output_data
.x
);
9367 f
->output_data
.x
= NULL
;
9369 if (f
== dpyinfo
->x_focus_frame
)
9370 dpyinfo
->x_focus_frame
= 0;
9371 if (f
== dpyinfo
->x_focus_event_frame
)
9372 dpyinfo
->x_focus_event_frame
= 0;
9373 if (f
== dpyinfo
->x_highlight_frame
)
9374 dpyinfo
->x_highlight_frame
= 0;
9375 if (f
== hlinfo
->mouse_face_mouse_frame
)
9376 reset_mouse_highlight (hlinfo
);
9382 /* Destroy the X window of frame F. */
9385 x_destroy_window (struct frame
*f
)
9387 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9389 /* If a display connection is dead, don't try sending more
9390 commands to the X server. */
9391 if (dpyinfo
->display
!= 0)
9392 x_free_frame_resources (f
);
9394 dpyinfo
->reference_count
--;
9398 /* Setting window manager hints. */
9400 /* Set the normal size hints for the window manager, for frame F.
9401 FLAGS is the flags word to use--or 0 meaning preserve the flags
9402 that the window now has.
9403 If USER_POSITION, set the USPosition
9404 flag (this is useful when FLAGS is 0).
9405 The GTK version is in gtkutils.c. */
9409 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
9411 XSizeHints size_hints
;
9412 Window window
= FRAME_OUTER_WINDOW (f
);
9414 #ifdef USE_X_TOOLKIT
9415 if (f
->output_data
.x
->widget
)
9417 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
9422 /* Setting PMaxSize caused various problems. */
9423 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9425 size_hints
.x
= f
->left_pos
;
9426 size_hints
.y
= f
->top_pos
;
9428 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9429 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9431 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9432 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9433 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9434 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9435 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9436 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9438 /* Calculate the base and minimum sizes. */
9440 int base_width
, base_height
;
9441 int min_rows
= 0, min_cols
= 0;
9443 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9444 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9446 check_frame_size (f
, &min_rows
, &min_cols
);
9448 /* The window manager uses the base width hints to calculate the
9449 current number of rows and columns in the frame while
9450 resizing; min_width and min_height aren't useful for this
9451 purpose, since they might not give the dimensions for a
9452 zero-row, zero-column frame.
9454 We use the base_width and base_height members if we have
9455 them; otherwise, we set the min_width and min_height members
9456 to the size for a zero x zero frame. */
9458 size_hints
.flags
|= PBaseSize
;
9459 size_hints
.base_width
= base_width
;
9460 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9461 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9462 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9465 /* If we don't need the old flags, we don't need the old hint at all. */
9468 size_hints
.flags
|= flags
;
9473 XSizeHints hints
; /* Sometimes I hate X Windows... */
9474 long supplied_return
;
9477 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9481 size_hints
.flags
|= flags
;
9486 if (hints
.flags
& PSize
)
9487 size_hints
.flags
|= PSize
;
9488 if (hints
.flags
& PPosition
)
9489 size_hints
.flags
|= PPosition
;
9490 if (hints
.flags
& USPosition
)
9491 size_hints
.flags
|= USPosition
;
9492 if (hints
.flags
& USSize
)
9493 size_hints
.flags
|= USSize
;
9500 size_hints
.win_gravity
= f
->win_gravity
;
9501 size_hints
.flags
|= PWinGravity
;
9505 size_hints
.flags
&= ~ PPosition
;
9506 size_hints
.flags
|= USPosition
;
9508 #endif /* PWinGravity */
9510 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9512 #endif /* not USE_GTK */
9514 /* Used for IconicState or NormalState */
9517 x_wm_set_window_state (struct frame
*f
, int state
)
9519 #ifdef USE_X_TOOLKIT
9522 XtSetArg (al
[0], XtNinitialState
, state
);
9523 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9524 #else /* not USE_X_TOOLKIT */
9525 Window window
= FRAME_X_WINDOW (f
);
9527 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9528 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9530 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9531 #endif /* not USE_X_TOOLKIT */
9535 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
9537 Pixmap icon_pixmap
, icon_mask
;
9539 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9540 Window window
= FRAME_OUTER_WINDOW (f
);
9545 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9546 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9547 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9548 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9552 /* It seems there is no way to turn off use of an icon
9560 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9564 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9568 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9569 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9570 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9571 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9574 #else /* not USE_X_TOOLKIT && not USE_GTK */
9576 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9577 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9579 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9583 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9585 Window window
= FRAME_OUTER_WINDOW (f
);
9587 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9588 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9589 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9591 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9595 /***********************************************************************
9597 ***********************************************************************/
9601 /* Check that FONT is valid on frame F. It is if it can be found in F's
9605 x_check_font (struct frame
*f
, struct font
*font
)
9607 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9608 if (font
->driver
->check
)
9609 eassert (font
->driver
->check (f
, font
) == 0);
9612 #endif /* GLYPH_DEBUG */
9615 /***********************************************************************
9617 ***********************************************************************/
9619 #ifdef USE_X_TOOLKIT
9620 static XrmOptionDescRec emacs_options
[] = {
9621 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9622 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9624 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9625 XrmoptionSepArg
, NULL
},
9626 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9628 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9629 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9630 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9631 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9632 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9633 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9634 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9637 /* Whether atimer for Xt timeouts is activated or not. */
9639 static int x_timeout_atimer_activated_flag
;
9641 #endif /* USE_X_TOOLKIT */
9643 static int x_initialized
;
9645 /* Test whether two display-name strings agree up to the dot that separates
9646 the screen number from the server number. */
9648 same_x_server (const char *name1
, const char *name2
)
9651 const char *system_name
= SSDATA (Vsystem_name
);
9652 ptrdiff_t system_name_length
= SBYTES (Vsystem_name
);
9653 ptrdiff_t length_until_period
= 0;
9655 while (system_name
[length_until_period
] != 0
9656 && system_name
[length_until_period
] != '.')
9657 length_until_period
++;
9659 /* Treat `unix' like an empty host name. */
9660 if (! strncmp (name1
, "unix:", 5))
9662 if (! strncmp (name2
, "unix:", 5))
9664 /* Treat this host's name like an empty host name. */
9665 if (! strncmp (name1
, system_name
, system_name_length
)
9666 && name1
[system_name_length
] == ':')
9667 name1
+= system_name_length
;
9668 if (! strncmp (name2
, system_name
, system_name_length
)
9669 && name2
[system_name_length
] == ':')
9670 name2
+= system_name_length
;
9671 /* Treat this host's domainless name like an empty host name. */
9672 if (! strncmp (name1
, system_name
, length_until_period
)
9673 && name1
[length_until_period
] == ':')
9674 name1
+= length_until_period
;
9675 if (! strncmp (name2
, system_name
, length_until_period
)
9676 && name2
[length_until_period
] == ':')
9677 name2
+= length_until_period
;
9679 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9683 if (seen_colon
&& *name1
== '.')
9687 && (*name1
== '.' || *name1
== '\0')
9688 && (*name2
== '.' || *name2
== '\0'));
9691 /* Count number of set bits in mask and number of bits to shift to
9692 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9695 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9716 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9717 But don't permanently open it, just test its availability. */
9720 x_display_ok (const char *display
)
9722 Display
*dpy
= XOpenDisplay (display
);
9723 return dpy
? (XCloseDisplay (dpy
), 1) : 0;
9728 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
9729 const gchar
*msg
, gpointer user_data
)
9731 if (!strstr (msg
, "g_set_prgname"))
9732 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
9736 /* Open a connection to X display DISPLAY_NAME, and return
9737 the structure that describes the open display.
9738 If we cannot contact the display, return null. */
9740 struct x_display_info
*
9741 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9745 struct terminal
*terminal
;
9746 struct x_display_info
*dpyinfo
;
9758 if (! x_display_ok (SSDATA (display_name
)))
9759 error ("Display %s can't be opened", SSDATA (display_name
));
9765 char *argv
[NUM_ARGV
];
9766 char **argv2
= argv
;
9769 if (x_initialized
++ > 1)
9771 xg_display_open (SSDATA (display_name
), &dpy
);
9775 static char display_opt
[] = "--display";
9776 static char name_opt
[] = "--name";
9778 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9782 argv
[argc
++] = initial_argv
[0];
9784 if (! NILP (display_name
))
9786 argv
[argc
++] = display_opt
;
9787 argv
[argc
++] = SSDATA (display_name
);
9790 argv
[argc
++] = name_opt
;
9791 argv
[argc
++] = resource_name
;
9793 XSetLocaleModifiers ("");
9795 /* Emacs can only handle core input events, so make sure
9796 Gtk doesn't use Xinput or Xinput2 extensions. */
9797 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
9799 /* Work around GLib bug that outputs a faulty warning. See
9800 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9801 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9802 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9804 /* NULL window -> events for all windows go to our function.
9805 Call before gtk_init so Gtk+ event filters comes after our. */
9806 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9808 /* gtk_init does set_locale. Fix locale before and after. */
9810 gtk_init (&argc
, &argv2
);
9813 g_log_remove_handler ("GLib", id
);
9817 dpy
= DEFAULT_GDK_DISPLAY ();
9819 #if ! GTK_CHECK_VERSION (2, 90, 0)
9820 /* Load our own gtkrc if it exists. */
9822 const char *file
= "~/.emacs.d/gtkrc";
9823 Lisp_Object s
, abs_file
;
9825 s
= build_string (file
);
9826 abs_file
= Fexpand_file_name (s
, Qnil
);
9828 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
9829 gtk_rc_parse (SSDATA (abs_file
));
9833 XSetErrorHandler (x_error_handler
);
9834 XSetIOErrorHandler (x_io_error_quitter
);
9837 #else /* not USE_GTK */
9838 #ifdef USE_X_TOOLKIT
9839 /* weiner@footloose.sps.mot.com reports that this causes
9841 X protocol error: BadAtom (invalid Atom parameter)
9842 on protocol request 18skiloaf.
9843 So let's not use it until R6. */
9845 XtSetLanguageProc (NULL
, NULL
, NULL
);
9856 argv
[argc
++] = "-xrm";
9857 argv
[argc
++] = xrm_option
;
9859 turn_on_atimers (0);
9860 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
9861 resource_name
, EMACS_CLASS
,
9862 emacs_options
, XtNumber (emacs_options
),
9864 turn_on_atimers (1);
9867 /* I think this is to compensate for XtSetLanguageProc. */
9872 #else /* not USE_X_TOOLKIT */
9873 XSetLocaleModifiers ("");
9874 dpy
= XOpenDisplay (SSDATA (display_name
));
9875 #endif /* not USE_X_TOOLKIT */
9876 #endif /* not USE_GTK*/
9878 /* Detect failure. */
9885 /* We have definitely succeeded. Record the new connection. */
9887 dpyinfo
= xzalloc (sizeof *dpyinfo
);
9888 terminal
= x_create_terminal (dpyinfo
);
9891 struct x_display_info
*share
;
9894 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
9895 share
= share
->next
, tail
= XCDR (tail
))
9896 if (same_x_server (SSDATA (XCAR (XCAR (tail
))),
9897 SSDATA (display_name
)))
9900 terminal
->kboard
= share
->terminal
->kboard
;
9903 terminal
->kboard
= xmalloc (sizeof *terminal
->kboard
);
9904 init_kboard (terminal
->kboard
);
9905 kset_window_system (terminal
->kboard
, Qx
);
9907 /* Add the keyboard to the list before running Lisp code (via
9908 Qvendor_specific_keysyms below), since these are not traced
9909 via terminals but only through all_kboards. */
9910 terminal
->kboard
->next_kboard
= all_kboards
;
9911 all_kboards
= terminal
->kboard
;
9913 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
9915 char *vendor
= ServerVendor (dpy
);
9917 /* Protect terminal from GC before removing it from the
9918 list of terminals. */
9919 struct gcpro gcpro1
;
9920 Lisp_Object gcpro_term
;
9921 XSETTERMINAL (gcpro_term
, terminal
);
9922 GCPRO1 (gcpro_term
);
9924 /* Temporarily hide the partially initialized terminal. */
9925 terminal_list
= terminal
->next_terminal
;
9927 kset_system_key_alist
9929 call1 (Qvendor_specific_keysyms
,
9930 vendor
? build_string (vendor
) : empty_unibyte_string
));
9932 terminal
->next_terminal
= terminal_list
;
9933 terminal_list
= terminal
;
9937 /* Don't let the initial kboard remain current longer than necessary.
9938 That would cause problems if a file loaded on startup tries to
9939 prompt in the mini-buffer. */
9940 if (current_kboard
== initial_kboard
)
9941 current_kboard
= terminal
->kboard
;
9943 terminal
->kboard
->reference_count
++;
9946 /* Put this display on the chain. */
9947 dpyinfo
->next
= x_display_list
;
9948 x_display_list
= dpyinfo
;
9950 /* Put it on x_display_name_list as well, to keep them parallel. */
9951 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
9952 x_display_name_list
);
9953 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
9955 dpyinfo
->display
= dpy
;
9957 /* Set the name of the terminal. */
9958 terminal
->name
= xlispstrdup (display_name
);
9961 XSetAfterFunction (x_current_display
, x_trace_wire
);
9964 lim
= min (PTRDIFF_MAX
, SIZE_MAX
) - sizeof "@";
9965 if (lim
- SBYTES (Vinvocation_name
) < SBYTES (Vsystem_name
))
9966 memory_full (SIZE_MAX
);
9967 dpyinfo
->x_id_name
= xmalloc (SBYTES (Vinvocation_name
)
9968 + SBYTES (Vsystem_name
) + 2);
9969 strcat (strcat (strcpy (dpyinfo
->x_id_name
, SSDATA (Vinvocation_name
)), "@"),
9970 SSDATA (Vsystem_name
));
9972 /* Figure out which modifier bits mean what. */
9973 x_find_modifier_meanings (dpyinfo
);
9975 /* Get the scroll bar cursor. */
9977 /* We must create a GTK cursor, it is required for GTK widgets. */
9978 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
9979 #endif /* USE_GTK */
9981 dpyinfo
->vertical_scroll_bar_cursor
9982 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
9984 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
9985 resource_name
, EMACS_CLASS
);
9986 #ifdef HAVE_XRMSETDATABASE
9987 XrmSetDatabase (dpyinfo
->display
, xrdb
);
9989 dpyinfo
->display
->db
= xrdb
;
9991 /* Put the rdb where we can find it in a way that works on
9993 dpyinfo
->xrdb
= xrdb
;
9995 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
9996 DefaultScreen (dpyinfo
->display
));
9997 select_visual (dpyinfo
);
9998 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
9999 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10000 dpyinfo
->icon_bitmap_id
= -1;
10001 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10003 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
10005 /* See if we can construct pixel values from RGB values. */
10006 if (dpyinfo
->visual
->class == TrueColor
)
10008 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10009 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10010 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10011 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10012 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10013 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10016 /* See if a private colormap is requested. */
10017 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10019 if (dpyinfo
->visual
->class == PseudoColor
)
10022 value
= display_x_get_resource (dpyinfo
,
10023 build_string ("privateColormap"),
10024 build_string ("PrivateColormap"),
10026 if (STRINGP (value
)
10027 && (!strcmp (SSDATA (value
), "true")
10028 || !strcmp (SSDATA (value
), "on")))
10029 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10033 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10034 dpyinfo
->visual
, AllocNone
);
10038 /* If we are using Xft, check dpi value in X resources.
10039 It is better we use it as well, since Xft will use it, as will all
10040 Gnome applications. If our real DPI is smaller or larger than the
10041 one Xft uses, our font will look smaller or larger than other
10042 for other applications, even if it is the same font name (monospace-10
10044 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10046 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10047 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10051 if (dpyinfo
->resy
< 1)
10053 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10054 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10055 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10056 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10057 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10058 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10059 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10060 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10061 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10065 static const struct
10070 #define ATOM_REFS_INIT(string, member) \
10071 { string, offsetof (struct x_display_info, member) },
10072 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
10073 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
10074 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
10075 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
10076 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
10077 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
10078 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
10079 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
10080 ATOM_REFS_INIT ("Editres", Xatom_editres
)
10081 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
10082 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
10083 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
10084 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
10085 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
10086 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
10087 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
10088 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
10089 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
10090 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
10091 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
10092 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
10093 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
10094 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
10095 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
10096 /* For properties of font. */
10097 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
10098 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
10099 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
10100 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
10101 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
10102 /* Ghostscript support. */
10103 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
10104 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
10105 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
10106 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
10108 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
10109 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
10110 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
10111 Xatom_net_wm_state_maximized_horz
)
10112 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
10113 Xatom_net_wm_state_maximized_vert
)
10114 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
10115 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
10116 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
10117 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
10118 Xatom_net_window_type_tooltip
)
10119 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
10120 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
10121 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
10122 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
10123 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
10124 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
10125 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
10126 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
10127 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
10128 /* Session management */
10129 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
10130 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
10131 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
10135 const int atom_count
= sizeof (atom_refs
) / sizeof (atom_refs
[0]);
10136 /* 1 for _XSETTINGS_SN */
10137 const int total_atom_count
= 1 + atom_count
;
10138 Atom
*atoms_return
= xmalloc (total_atom_count
* sizeof *atoms_return
);
10139 char **atom_names
= xmalloc (total_atom_count
* sizeof *atom_names
);
10140 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
10141 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
10142 + INT_STRLEN_BOUND (int)];
10144 for (i
= 0; i
< atom_count
; i
++)
10145 atom_names
[i
] = (char *) atom_refs
[i
].name
;
10147 /* Build _XSETTINGS_SN atom name */
10148 sprintf (xsettings_atom_name
, xsettings_fmt
,
10149 XScreenNumberOfScreen (dpyinfo
->screen
));
10150 atom_names
[i
] = xsettings_atom_name
;
10152 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
10153 False
, atoms_return
);
10155 for (i
= 0; i
< atom_count
; i
++)
10156 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
10158 /* Manual copy of last atom */
10159 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
10161 xfree (atom_names
);
10162 xfree (atoms_return
);
10165 dpyinfo
->x_dnd_atoms_size
= 8;
10166 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
10167 * dpyinfo
->x_dnd_atoms_size
);
10169 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10170 gray_bits
, gray_width
, gray_height
,
10174 xim_initialize (dpyinfo
, resource_name
);
10177 xsettings_initialize (dpyinfo
);
10179 connection
= ConnectionNumber (dpyinfo
->display
);
10181 /* This is only needed for distinguishing keyboard and process input. */
10182 if (connection
!= 0)
10183 add_keyboard_wait_descriptor (connection
);
10186 fcntl (connection
, F_SETOWN
, getpid ());
10187 #endif /* ! defined (F_SETOWN) */
10189 if (interrupt_input
)
10190 init_sigio (connection
);
10194 XrmValue d
, fr
, to
;
10197 dpy
= dpyinfo
->display
;
10198 d
.addr
= (XPointer
)&dpy
;
10199 d
.size
= sizeof (Display
*);
10200 fr
.addr
= XtDefaultFont
;
10201 fr
.size
= sizeof (XtDefaultFont
);
10202 to
.size
= sizeof (Font
*);
10203 to
.addr
= (XPointer
)&font
;
10204 x_catch_errors (dpy
);
10205 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10207 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10208 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10209 x_uncatch_errors ();
10213 /* See if we should run in synchronous mode. This is useful
10214 for debugging X code. */
10217 value
= display_x_get_resource (dpyinfo
,
10218 build_string ("synchronous"),
10219 build_string ("Synchronous"),
10221 if (STRINGP (value
)
10222 && (!strcmp (SSDATA (value
), "true")
10223 || !strcmp (SSDATA (value
), "on")))
10224 XSynchronize (dpyinfo
->display
, True
);
10229 value
= display_x_get_resource (dpyinfo
,
10230 build_string ("useXIM"),
10231 build_string ("UseXIM"),
10234 if (STRINGP (value
)
10235 && (!strcmp (SSDATA (value
), "false")
10236 || !strcmp (SSDATA (value
), "off")))
10239 if (STRINGP (value
)
10240 && (!strcmp (SSDATA (value
), "true")
10241 || !strcmp (SSDATA (value
), "on")))
10247 /* Only do this for the very first display in the Emacs session.
10248 Ignore X session management when Emacs was first started on a
10250 if (terminal
->id
== 1)
10251 x_session_initialize (dpyinfo
);
10259 /* Get rid of display DPYINFO, deleting all frames on it,
10260 and without sending any more commands to the X server. */
10263 x_delete_display (struct x_display_info
*dpyinfo
)
10265 struct terminal
*t
;
10267 /* Close all frames and delete the generic struct terminal for this
10269 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10270 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10273 /* Close X session management when we close its display. */
10274 if (t
->id
== 1 && x_session_have_connection ())
10275 x_session_close ();
10277 delete_terminal (t
);
10281 /* Discard this display from x_display_name_list and x_display_list.
10282 We can't use Fdelq because that can quit. */
10283 if (! NILP (x_display_name_list
)
10284 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10285 x_display_name_list
= XCDR (x_display_name_list
);
10290 tail
= x_display_name_list
;
10291 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10293 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10295 XSETCDR (tail
, XCDR (XCDR (tail
)));
10298 tail
= XCDR (tail
);
10302 if (next_noop_dpyinfo
== dpyinfo
)
10303 next_noop_dpyinfo
= dpyinfo
->next
;
10305 if (x_display_list
== dpyinfo
)
10306 x_display_list
= dpyinfo
->next
;
10309 struct x_display_info
*tail
;
10311 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10312 if (tail
->next
== dpyinfo
)
10313 tail
->next
= tail
->next
->next
;
10316 xfree (dpyinfo
->x_id_name
);
10317 xfree (dpyinfo
->x_dnd_atoms
);
10318 xfree (dpyinfo
->color_cells
);
10322 #ifdef USE_X_TOOLKIT
10324 /* Atimer callback function for TIMER. Called every 0.1s to process
10325 Xt timeouts, if needed. We must avoid calling XtAppPending as
10326 much as possible because that function does an implicit XFlush
10327 that slows us down. */
10330 x_process_timeouts (struct atimer
*timer
)
10333 x_timeout_atimer_activated_flag
= 0;
10334 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10336 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10337 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10338 /* Reactivate the atimer for next time. */
10339 x_activate_timeout_atimer ();
10344 /* Install an asynchronous timer that processes Xt timeout events
10345 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10346 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10347 function whenever these variables are set. This is necessary
10348 because some widget sets use timeouts internally, for example the
10349 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10350 processed, these widgets don't behave normally. */
10353 x_activate_timeout_atimer (void)
10356 if (!x_timeout_atimer_activated_flag
)
10358 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
10359 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10360 x_timeout_atimer_activated_flag
= 1;
10365 #endif /* USE_X_TOOLKIT */
10368 /* Set up use of X before we make the first connection. */
10370 static struct redisplay_interface x_redisplay_interface
=
10372 x_frame_parm_handlers
,
10376 x_clear_end_of_line
,
10378 x_after_update_window_line
,
10379 x_update_window_begin
,
10380 x_update_window_end
,
10382 x_clear_window_mouse_face
,
10383 x_get_glyph_overhangs
,
10384 x_fix_overlapping_area
,
10385 x_draw_fringe_bitmap
,
10386 0, /* define_fringe_bitmap */
10387 0, /* destroy_fringe_bitmap */
10388 x_compute_glyph_string_overhangs
,
10389 x_draw_glyph_string
,
10390 x_define_frame_cursor
,
10391 x_clear_frame_area
,
10392 x_draw_window_cursor
,
10393 x_draw_vertical_window_border
,
10394 x_shift_glyphs_for_insert
10398 /* This function is called when the last frame on a display is deleted. */
10400 x_delete_terminal (struct terminal
*terminal
)
10402 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10403 int connection
= -1;
10405 /* Protect against recursive calls. delete_frame in
10406 delete_terminal calls us back when it deletes our last frame. */
10407 if (!terminal
->name
)
10412 /* We must close our connection to the XIM server before closing the
10415 xim_close_dpy (dpyinfo
);
10418 /* If called from x_connection_closed, the display may already be closed
10419 and dpyinfo->display was set to 0 to indicate that. */
10420 if (dpyinfo
->display
)
10422 connection
= ConnectionNumber (dpyinfo
->display
);
10424 x_destroy_all_bitmaps (dpyinfo
);
10425 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10427 /* Whether or not XCloseDisplay destroys the associated resource
10428 database depends on the version of libX11. To avoid both
10429 crash and memory leak, we dissociate the database from the
10430 display and then destroy dpyinfo->xrdb ourselves.
10432 Unfortunately, the above strategy does not work in some
10433 situations due to a bug in newer versions of libX11: because
10434 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10435 dpy->db is NULL, XCloseDisplay destroys the associated
10436 database whereas it has not been created by XGetDefault
10437 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10438 don't destroy the database here in order to avoid the crash
10439 in the above situations for now, though that may cause memory
10440 leaks in other situations. */
10442 #ifdef HAVE_XRMSETDATABASE
10443 XrmSetDatabase (dpyinfo
->display
, NULL
);
10445 dpyinfo
->display
->db
= NULL
;
10447 /* We used to call XrmDestroyDatabase from x_delete_display, but
10448 some older versions of libX11 crash if we call it after
10449 closing all the displays. */
10450 XrmDestroyDatabase (dpyinfo
->xrdb
);
10454 xg_display_close (dpyinfo
->display
);
10456 #ifdef USE_X_TOOLKIT
10457 XtCloseDisplay (dpyinfo
->display
);
10459 XCloseDisplay (dpyinfo
->display
);
10461 #endif /* ! USE_GTK */
10464 /* No more input on this descriptor. */
10465 if (connection
!= -1)
10466 delete_keyboard_wait_descriptor (connection
);
10468 /* Mark as dead. */
10469 dpyinfo
->display
= NULL
;
10470 x_delete_display (dpyinfo
);
10474 /* Create a struct terminal, initialize it with the X11 specific
10475 functions and make DISPLAY->TERMINAL point to it. */
10477 static struct terminal
*
10478 x_create_terminal (struct x_display_info
*dpyinfo
)
10480 struct terminal
*terminal
;
10482 terminal
= create_terminal ();
10484 terminal
->type
= output_x_window
;
10485 terminal
->display_info
.x
= dpyinfo
;
10486 dpyinfo
->terminal
= terminal
;
10488 /* kboard is initialized in x_term_init. */
10490 terminal
->clear_frame_hook
= x_clear_frame
;
10491 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10492 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10493 terminal
->ring_bell_hook
= XTring_bell
;
10494 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10495 terminal
->reset_terminal_modes_hook
= NULL
;
10496 terminal
->set_terminal_modes_hook
= NULL
;
10497 terminal
->update_begin_hook
= x_update_begin
;
10498 terminal
->update_end_hook
= x_update_end
;
10499 terminal
->set_terminal_window_hook
= NULL
;
10500 terminal
->read_socket_hook
= XTread_socket
;
10501 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10502 terminal
->mouse_position_hook
= XTmouse_position
;
10503 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10504 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10505 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10506 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10507 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10508 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10509 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10511 terminal
->delete_frame_hook
= x_destroy_window
;
10512 terminal
->delete_terminal_hook
= x_delete_terminal
;
10514 terminal
->rif
= &x_redisplay_interface
;
10515 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10516 terminal
->char_ins_del_ok
= 1;
10517 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10518 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10519 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10526 x_initialize (void)
10531 last_tool_bar_item
= -1;
10532 any_help_event_p
= 0;
10533 ignore_next_mouse_click_timeout
= 0;
10536 current_count
= -1;
10539 /* Try to use interrupt input; if we can't, then start polling. */
10540 Fset_input_interrupt_mode (Qt
);
10542 #ifdef USE_X_TOOLKIT
10543 XtToolkitInitialize ();
10545 Xt_app_con
= XtCreateApplicationContext ();
10547 /* Register a converter from strings to pixels, which uses
10548 Emacs' color allocation infrastructure. */
10549 XtAppSetTypeConverter (Xt_app_con
,
10550 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10551 cvt_string_to_pixel_args
,
10552 XtNumber (cvt_string_to_pixel_args
),
10553 XtCacheByDisplay
, cvt_pixel_dtor
);
10555 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10558 #ifdef USE_TOOLKIT_SCROLL_BARS
10560 xaw3d_arrow_scroll
= False
;
10561 xaw3d_pick_top
= True
;
10565 pending_autoraise_frame
= 0;
10566 pending_event_wait
.f
= 0;
10567 pending_event_wait
.eventtype
= 0;
10569 /* Note that there is no real way portable across R3/R4 to get the
10570 original error handler. */
10571 XSetErrorHandler (x_error_handler
);
10572 XSetIOErrorHandler (x_io_error_quitter
);
10577 syms_of_xterm (void)
10579 x_error_message
= NULL
;
10581 staticpro (&x_display_name_list
);
10582 x_display_name_list
= Qnil
;
10584 staticpro (&last_mouse_scroll_bar
);
10585 last_mouse_scroll_bar
= Qnil
;
10587 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
10588 DEFSYM (Qlatin_1
, "latin-1");
10591 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10592 staticpro (&xg_default_icon_file
);
10594 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
10597 DEFVAR_BOOL ("x-use-underline-position-properties",
10598 x_use_underline_position_properties
,
10599 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
10600 A value of nil means ignore them. If you encounter fonts with bogus
10601 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10602 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10603 to override the font's UNDERLINE_POSITION for small font display
10605 x_use_underline_position_properties
= 1;
10607 DEFVAR_BOOL ("x-underline-at-descent-line",
10608 x_underline_at_descent_line
,
10609 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
10610 A value of nil means to draw the underline according to the value of the
10611 variable `x-use-underline-position-properties', which is usually at the
10612 baseline level. The default value is nil. */);
10613 x_underline_at_descent_line
= 0;
10615 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10616 x_mouse_click_focus_ignore_position
,
10617 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10618 This variable is only used when the window manager requires that you
10619 click on a frame to select it (give it focus). In that case, a value
10620 of nil, means that the selected window and cursor position changes to
10621 reflect the mouse click position, while a non-nil value means that the
10622 selected window or cursor position is preserved. */);
10623 x_mouse_click_focus_ignore_position
= 0;
10625 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
10626 doc
: /* Which toolkit scroll bars Emacs uses, if any.
10627 A value of nil means Emacs doesn't use toolkit scroll bars.
10628 With the X Window system, the value is a symbol describing the
10629 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
10630 With MS Windows or Nextstep, the value is t. */);
10631 #ifdef USE_TOOLKIT_SCROLL_BARS
10633 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10634 #elif defined HAVE_XAW3D
10635 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10637 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10639 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10642 Vx_toolkit_scroll_bars
= Qnil
;
10645 staticpro (&last_mouse_motion_frame
);
10646 last_mouse_motion_frame
= Qnil
;
10648 Qmodifier_value
= intern_c_string ("modifier-value");
10649 Qalt
= intern_c_string ("alt");
10650 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10651 Qhyper
= intern_c_string ("hyper");
10652 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10653 Qmeta
= intern_c_string ("meta");
10654 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10655 Qsuper
= intern_c_string ("super");
10656 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10658 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
10659 doc
: /* Which keys Emacs uses for the alt modifier.
10660 This should be one of the symbols `alt', `hyper', `meta', `super'.
10661 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10662 is nil, which is the same as `alt'. */);
10663 Vx_alt_keysym
= Qnil
;
10665 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
10666 doc
: /* Which keys Emacs uses for the hyper modifier.
10667 This should be one of the symbols `alt', `hyper', `meta', `super'.
10668 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10669 default is nil, which is the same as `hyper'. */);
10670 Vx_hyper_keysym
= Qnil
;
10672 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
10673 doc
: /* Which keys Emacs uses for the meta modifier.
10674 This should be one of the symbols `alt', `hyper', `meta', `super'.
10675 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10676 default is nil, which is the same as `meta'. */);
10677 Vx_meta_keysym
= Qnil
;
10679 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
10680 doc
: /* Which keys Emacs uses for the super modifier.
10681 This should be one of the symbols `alt', `hyper', `meta', `super'.
10682 For example, `super' means use the Super_L and Super_R keysyms. The
10683 default is nil, which is the same as `super'. */);
10684 Vx_super_keysym
= Qnil
;
10686 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
10687 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10688 Vx_keysym_table
= make_hash_table (hashtest_eql
, make_number (900),
10689 make_float (DEFAULT_REHASH_SIZE
),
10690 make_float (DEFAULT_REHASH_THRESHOLD
),
10694 #endif /* HAVE_X_WINDOWS */