1 /* X Communication module for terminals which understand the X protocol.
3 Copyright (C) 1989, 1993-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
21 /* Xt features made by Fred Pierresteguy. */
27 #include "blockinput.h"
28 #include "syssignal.h"
30 /* This may include sys/types.h, and that somehow loses
31 if this is not done before the other system files. */
33 #include <X11/cursorfont.h>
35 /* Load sys/types.h if not already loaded.
36 In some systems loading it twice is suicidal. */
38 #include <sys/types.h>
41 #include <sys/ioctl.h>
48 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
49 /* #include <sys/param.h> */
52 #include "character.h"
55 #include "dispextern.h"
57 #include "termhooks.h"
60 #include "emacs-icon.h"
65 #include "intervals.h"
70 #include "xsettings.h"
72 #include "sysselect.h"
75 #include <X11/Shell.h>
83 #include <X11/Xproto.h>
88 #include "../lwlib/xlwmenu.h"
92 #if !defined (NO_EDITRES)
94 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
95 #endif /* not NO_EDITRES */
97 /* Include toolkit specific headers for the scroll bar widget. */
99 #ifdef USE_TOOLKIT_SCROLL_BARS
100 #if defined USE_MOTIF
101 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
102 #include <Xm/ScrollBar.h>
103 #else /* !USE_MOTIF i.e. use Xaw */
106 #include <X11/Xaw3d/Simple.h>
107 #include <X11/Xaw3d/Scrollbar.h>
108 #include <X11/Xaw3d/ThreeD.h>
109 #else /* !HAVE_XAW3D */
110 #include <X11/Xaw/Simple.h>
111 #include <X11/Xaw/Scrollbar.h>
112 #endif /* !HAVE_XAW3D */
114 #define XtNpickTop "pickTop"
115 #endif /* !XtNpickTop */
116 #endif /* !USE_MOTIF */
117 #endif /* USE_TOOLKIT_SCROLL_BARS */
119 #endif /* USE_X_TOOLKIT */
123 #ifndef XtNinitialState
124 #define XtNinitialState "initialState"
128 #include "bitmaps/gray.xbm"
131 #include <X11/XKBlib.h>
134 /* Default to using XIM if available. */
138 int use_xim
= 0; /* configure --without-xim */
141 /* Non-zero means that a HELP_EVENT has been generated since Emacs
144 static bool any_help_event_p
;
146 /* This is a chain of structures for all the X displays currently in
149 struct x_display_info
*x_display_list
;
151 /* This is a list of cons cells, each of the form (NAME
152 . FONT-LIST-CACHE), one for each element of x_display_list and in
153 the same order. NAME is the name of the frame. FONT-LIST-CACHE
154 records previous values returned by x-list-fonts. */
156 Lisp_Object x_display_name_list
;
158 /* This is a frame waiting to be auto-raised, within XTread_socket. */
160 static struct frame
*pending_autoraise_frame
;
164 /* The application context for Xt use. */
165 XtAppContext Xt_app_con
;
166 static String Xt_default_resources
[] = {0};
168 /* Non-zero means user is interacting with a toolkit scroll bar. */
169 static bool toolkit_scroll_bar_interaction
;
171 #endif /* USE_X_TOOLKIT */
173 /* Non-zero timeout value means ignore next mouse click if it arrives
174 before that timeout elapses (i.e. as part of the same sequence of
175 events resulting from clicking on a frame to select it). */
177 static Time ignore_next_mouse_click_timeout
;
181 Formerly, we used PointerMotionHintMask (in standard_event_mask)
182 so that we would have to call XQueryPointer after each MotionNotify
183 event to ask for another such event. However, this made mouse tracking
184 slow, and there was a bug that made it eventually stop.
186 Simply asking for MotionNotify all the time seems to work better.
188 In order to avoid asking for motion events and then throwing most
189 of them away or busy-polling the server for mouse positions, we ask
190 the server for pointer motion hints. This means that we get only
191 one event per group of mouse movements. "Groups" are delimited by
192 other kinds of events (focus changes and button clicks, for
193 example), or by XQueryPointer calls; when one of these happens, we
194 get another MotionNotify event the next time the mouse moves. This
195 is at least as efficient as getting motion events when mouse
196 tracking is on, and I suspect only negligibly worse when tracking
199 /* Where the mouse was last time we reported a mouse event. */
201 static XRectangle last_mouse_glyph
;
202 static struct frame
*last_mouse_glyph_frame
;
204 /* The scroll bar in which the last X motion event occurred.
206 If the last X motion event occurred in a scroll bar, we set this so
207 XTmouse_position can know whether to report a scroll bar motion or
210 If the last X motion event didn't occur in a scroll bar, we set
211 this to Qnil, to tell XTmouse_position to return an ordinary motion
214 static Lisp_Object last_mouse_scroll_bar
;
216 /* This is a hack. We would really prefer that XTmouse_position would
217 return the time associated with the position it returns, but there
218 doesn't seem to be any way to wrest the time-stamp from the server
219 along with the position query. So, we just keep track of the time
220 of the last movement we received, and return that in hopes that
221 it's somewhat accurate. */
223 static Time last_mouse_movement_time
;
225 /* Incremented by XTread_socket whenever it really tries to read
228 static int volatile input_signal_count
;
230 /* Used locally within XTread_socket. */
232 static int x_noop_count
;
234 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
236 static Lisp_Object Qvendor_specific_keysyms
;
237 static Lisp_Object Qlatin_1
;
240 /* The name of the Emacs icon file. */
241 static Lisp_Object xg_default_icon_file
;
243 /* Used in gtkutil.c. */
244 Lisp_Object Qx_gtk_map_stock
;
247 /* Some functions take this as char *, not const char *. */
248 static char emacs_class
[] = EMACS_CLASS
;
252 XEMBED_MAPPED
= 1 << 0
257 XEMBED_EMBEDDED_NOTIFY
= 0,
258 XEMBED_WINDOW_ACTIVATE
= 1,
259 XEMBED_WINDOW_DEACTIVATE
= 2,
260 XEMBED_REQUEST_FOCUS
= 3,
262 XEMBED_FOCUS_OUT
= 5,
263 XEMBED_FOCUS_NEXT
= 6,
264 XEMBED_FOCUS_PREV
= 7,
266 XEMBED_MODALITY_ON
= 10,
267 XEMBED_MODALITY_OFF
= 11,
268 XEMBED_REGISTER_ACCELERATOR
= 12,
269 XEMBED_UNREGISTER_ACCELERATOR
= 13,
270 XEMBED_ACTIVATE_ACCELERATOR
= 14
273 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
274 static void x_set_window_size_1 (struct frame
*, int, int, int);
275 static void x_raise_frame (struct frame
*);
276 static void x_lower_frame (struct frame
*);
277 static const XColor
*x_color_cells (Display
*, int *);
278 static int x_io_error_quitter (Display
*);
279 static struct terminal
*x_create_terminal (struct x_display_info
*);
280 void x_delete_terminal (struct terminal
*);
281 static void x_update_end (struct frame
*);
282 static void XTframe_up_to_date (struct frame
*);
283 static void x_clear_frame (struct frame
*);
284 static _Noreturn
void x_ins_del_lines (struct frame
*, int, int);
285 static void frame_highlight (struct frame
*);
286 static void frame_unhighlight (struct frame
*);
287 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
288 static void x_focus_changed (int, int, struct x_display_info
*,
289 struct frame
*, struct input_event
*);
290 static void XTframe_rehighlight (struct frame
*);
291 static void x_frame_rehighlight (struct x_display_info
*);
292 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
293 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
294 enum text_cursor_kinds
);
296 static void x_clip_to_row (struct window
*, struct glyph_row
*,
297 enum glyph_row_area
, GC
);
298 static void x_flush (struct frame
*f
);
299 static void x_update_begin (struct frame
*);
300 static void x_update_window_begin (struct window
*);
301 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
302 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
303 enum scroll_bar_part
*,
304 Lisp_Object
*, Lisp_Object
*,
306 static int x_handle_net_wm_state (struct frame
*, const XPropertyEvent
*);
307 static void x_check_fullscreen (struct frame
*);
308 static void x_check_expected_move (struct frame
*, int, int);
309 static void x_sync_with_move (struct frame
*, int, int, int);
310 static int handle_one_xevent (struct x_display_info
*,
311 const XEvent
*, int *,
312 struct input_event
*);
314 static int x_dispatch_event (XEvent
*, Display
*);
316 /* Don't declare this _Noreturn because we want no
317 interference with debugging failing X calls. */
318 static void x_connection_closed (Display
*, const char *);
319 static void x_wm_set_window_state (struct frame
*, int);
320 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
321 static void x_initialize (void);
324 /* Flush display of frame F. */
327 x_flush (struct frame
*f
)
329 eassert (f
&& FRAME_X_P (f
));
330 /* Don't call XFlush when it is not safe to redisplay; the X
331 connection may be broken. */
332 if (!NILP (Vinhibit_redisplay
))
336 XFlush (FRAME_X_DISPLAY (f
));
341 /* Remove calls to XFlush by defining XFlush to an empty replacement.
342 Calls to XFlush should be unnecessary because the X output buffer
343 is flushed automatically as needed by calls to XPending,
344 XNextEvent, or XWindowEvent according to the XFlush man page.
345 XTread_socket calls XPending. Removing XFlush improves
348 #define XFlush(DISPLAY) (void) 0
351 /***********************************************************************
353 ***********************************************************************/
357 /* This is a function useful for recording debugging information about
358 the sequence of occurrences in this file. */
366 struct record event_record
[100];
368 int event_record_index
;
371 record_event (char *locus
, int type
)
373 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
374 event_record_index
= 0;
376 event_record
[event_record_index
].locus
= locus
;
377 event_record
[event_record_index
].type
= type
;
378 event_record_index
++;
385 /* Return the struct x_display_info corresponding to DPY. */
387 struct x_display_info
*
388 x_display_info_for_display (Display
*dpy
)
390 struct x_display_info
*dpyinfo
;
392 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
393 if (dpyinfo
->display
== dpy
)
400 x_find_topmost_parent (struct frame
*f
)
402 struct x_output
*x
= f
->output_data
.x
;
403 Window win
= None
, wi
= x
->parent_desc
;
404 Display
*dpy
= FRAME_X_DISPLAY (f
);
406 while (wi
!= FRAME_DISPLAY_INFO (f
)->root_window
)
410 unsigned int nchildren
;
413 XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
);
420 #define OPAQUE 0xffffffff
423 x_set_frame_alpha (struct frame
*f
)
425 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
426 Display
*dpy
= FRAME_X_DISPLAY (f
);
427 Window win
= FRAME_OUTER_WINDOW (f
);
429 double alpha_min
= 1.0;
433 if (dpyinfo
->x_highlight_frame
== f
)
438 if (FLOATP (Vframe_alpha_lower_limit
))
439 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
440 else if (INTEGERP (Vframe_alpha_lower_limit
))
441 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
445 else if (alpha
> 1.0)
447 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
450 opac
= alpha
* OPAQUE
;
452 x_catch_errors (dpy
);
454 /* If there is a parent from the window manager, put the property there
455 also, to work around broken window managers that fail to do that.
456 Do this unconditionally as this function is called on reparent when
457 alpha has not changed on the frame. */
459 parent
= x_find_topmost_parent (f
);
461 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
462 XA_CARDINAL
, 32, PropModeReplace
,
463 (unsigned char *) &opac
, 1L);
465 /* return unless necessary */
470 unsigned long n
, left
;
472 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
473 0L, 1L, False
, XA_CARDINAL
,
474 &actual
, &format
, &n
, &left
,
477 if (rc
== Success
&& actual
!= None
)
479 unsigned long value
= *(unsigned long *)data
;
489 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
490 XA_CARDINAL
, 32, PropModeReplace
,
491 (unsigned char *) &opac
, 1L);
496 x_display_pixel_height (struct x_display_info
*dpyinfo
)
498 return HeightOfScreen (dpyinfo
->screen
);
502 x_display_pixel_width (struct x_display_info
*dpyinfo
)
504 return WidthOfScreen (dpyinfo
->screen
);
508 /***********************************************************************
509 Starting and ending an update
510 ***********************************************************************/
512 /* Start an update of frame F. This function is installed as a hook
513 for update_begin, i.e. it is called when update_begin is called.
514 This function is called prior to calls to x_update_window_begin for
515 each window being updated. Currently, there is nothing to do here
516 because all interesting stuff is done on a window basis. */
519 x_update_begin (struct frame
*f
)
525 /* Start update of window W. */
528 x_update_window_begin (struct window
*w
)
530 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
531 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
533 w
->output_cursor
= w
->cursor
;
537 if (f
== hlinfo
->mouse_face_mouse_frame
)
539 /* Don't do highlighting for mouse motion during the update. */
540 hlinfo
->mouse_face_defer
= 1;
542 /* If F needs to be redrawn, simply forget about any prior mouse
544 if (FRAME_GARBAGED_P (f
))
545 hlinfo
->mouse_face_window
= Qnil
;
552 /* Draw a vertical window border from (x,y0) to (x,y1) */
555 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
557 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
560 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
562 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
565 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
566 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
569 /* End update of window W.
571 Draw vertical borders between horizontally adjacent windows, and
572 display W's cursor if CURSOR_ON_P is non-zero.
574 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
575 glyphs in mouse-face were overwritten. In that case we have to
576 make sure that the mouse-highlight is properly redrawn.
578 W may be a menu bar pseudo-window in case we don't have X toolkit
579 support. Such windows don't have a cursor, so don't display it
583 x_update_window_end (struct window
*w
, bool cursor_on_p
,
584 bool mouse_face_overwritten_p
)
586 if (!w
->pseudo_window_p
)
591 display_and_set_cursor (w
, 1,
592 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
593 w
->output_cursor
.x
, w
->output_cursor
.y
);
595 if (draw_window_fringes (w
, 1))
596 x_draw_vertical_border (w
);
601 /* If a row with mouse-face was overwritten, arrange for
602 XTframe_up_to_date to redisplay the mouse highlight. */
603 if (mouse_face_overwritten_p
)
604 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w
->frame
)));
608 /* End update of frame F. This function is installed as a hook in
612 x_update_end (struct frame
*f
)
614 /* Mouse highlight may be displayed again. */
615 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
619 XFlush (FRAME_X_DISPLAY (f
));
625 /* This function is called from various places in xdisp.c
626 whenever a complete update has been performed. */
629 XTframe_up_to_date (struct frame
*f
)
632 FRAME_MOUSE_UPDATE (f
);
636 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
637 arrow bitmaps, or clear the fringes if no bitmaps are required
638 before DESIRED_ROW is made current. This function is called from
639 update_window_line only if it is known that there are differences
640 between bitmaps to be drawn between current row and DESIRED_ROW. */
643 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
650 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
651 desired_row
->redraw_fringe_bitmaps_p
= 1;
653 /* When a window has disappeared, make sure that no rest of
654 full-width rows stays visible in the internal border. Could
655 check here if updated window is the leftmost/rightmost window,
656 but I guess it's not worth doing since vertically split windows
657 are almost never used, internal border is rarely set, and the
658 overhead is very small. */
659 if (windows_or_buffers_changed
660 && desired_row
->full_width_p
661 && (f
= XFRAME (w
->frame
),
662 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
664 && (height
= desired_row
->visible_height
,
667 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
670 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
671 0, y
, width
, height
);
672 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
673 FRAME_PIXEL_WIDTH (f
) - width
,
680 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
682 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
683 Display
*display
= FRAME_X_DISPLAY (f
);
684 Window window
= FRAME_X_WINDOW (f
);
685 GC gc
= f
->output_data
.x
->normal_gc
;
686 struct face
*face
= p
->face
;
688 /* Must clip because of partially visible lines. */
689 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
693 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
695 /* In case the same realized face is used for fringes and
696 for something displayed in the text (e.g. face `region' on
697 mono-displays, the fill style may have been changed to
698 FillSolid in x_draw_glyph_string_background. */
700 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
702 XSetForeground (display
, face
->gc
, face
->background
);
704 #ifdef USE_TOOLKIT_SCROLL_BARS
705 /* If the fringe is adjacent to the left (right) scroll bar of a
706 leftmost (rightmost, respectively) window, then extend its
707 background to the gap between the fringe and the bar. */
708 if ((WINDOW_LEFTMOST_P (w
)
709 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
710 || (WINDOW_RIGHTMOST_P (w
)
711 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
713 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
717 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
718 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
719 * FRAME_COLUMN_WIDTH (f
));
723 /* Bitmap fills the fringe. */
724 if (bar_area_x
+ bar_area_width
== p
->x
)
725 bx
= bar_area_x
+ sb_width
;
726 else if (p
->x
+ p
->wd
== bar_area_x
)
730 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
732 nx
= bar_area_width
- sb_width
;
733 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
735 ny
= row
->visible_height
;
740 if (bar_area_x
+ bar_area_width
== bx
)
742 bx
= bar_area_x
+ sb_width
;
743 nx
+= bar_area_width
- sb_width
;
745 else if (bx
+ nx
== bar_area_x
)
746 nx
+= bar_area_width
- sb_width
;
751 if (bx
>= 0 && nx
> 0)
752 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
755 XSetForeground (display
, face
->gc
, face
->foreground
);
761 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
762 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
766 bits
= (char *) (p
->bits
+ p
->dh
);
768 bits
= (char *) p
->bits
+ p
->dh
;
770 /* Draw the bitmap. I believe these small pixmaps can be cached
772 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
774 ? (p
->overlay_p
? face
->background
775 : f
->output_data
.x
->cursor_pixel
)
777 face
->background
, depth
);
781 clipmask
= XCreatePixmapFromBitmapData (display
,
782 FRAME_DISPLAY_INFO (f
)->root_window
,
785 gcv
.clip_mask
= clipmask
;
786 gcv
.clip_x_origin
= p
->x
;
787 gcv
.clip_y_origin
= p
->y
;
788 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
791 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
792 p
->wd
, p
->h
, p
->x
, p
->y
);
793 XFreePixmap (display
, pixmap
);
797 gcv
.clip_mask
= (Pixmap
) 0;
798 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
799 XFreePixmap (display
, clipmask
);
803 XSetClipMask (display
, gc
, None
);
806 /***********************************************************************
808 ***********************************************************************/
812 static void x_set_glyph_string_clipping (struct glyph_string
*);
813 static void x_set_glyph_string_gc (struct glyph_string
*);
814 static void x_draw_glyph_string_foreground (struct glyph_string
*);
815 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
816 static void x_draw_glyph_string_box (struct glyph_string
*);
817 static void x_draw_glyph_string (struct glyph_string
*);
818 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
819 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
820 static void x_set_cursor_gc (struct glyph_string
*);
821 static void x_set_mode_line_face_gc (struct glyph_string
*);
822 static void x_set_mouse_face_gc (struct glyph_string
*);
823 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
824 unsigned long *, double, int);
825 static void x_setup_relief_color (struct frame
*, struct relief
*,
826 double, int, unsigned long);
827 static void x_setup_relief_colors (struct glyph_string
*);
828 static void x_draw_image_glyph_string (struct glyph_string
*);
829 static void x_draw_image_relief (struct glyph_string
*);
830 static void x_draw_image_foreground (struct glyph_string
*);
831 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
832 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
834 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
835 int, int, int, int, int, int,
837 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
838 int, int, int, XRectangle
*);
839 static void x_scroll_bar_clear (struct frame
*);
842 static void x_check_font (struct frame
*, struct font
*);
846 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
850 x_set_cursor_gc (struct glyph_string
*s
)
852 if (s
->font
== FRAME_FONT (s
->f
)
853 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
854 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
856 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
859 /* Cursor on non-default face: must merge. */
863 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
864 xgcv
.foreground
= s
->face
->background
;
866 /* If the glyph would be invisible, try a different foreground. */
867 if (xgcv
.foreground
== xgcv
.background
)
868 xgcv
.foreground
= s
->face
->foreground
;
869 if (xgcv
.foreground
== xgcv
.background
)
870 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
871 if (xgcv
.foreground
== xgcv
.background
)
872 xgcv
.foreground
= s
->face
->foreground
;
874 /* Make sure the cursor is distinct from text in this face. */
875 if (xgcv
.background
== s
->face
->background
876 && xgcv
.foreground
== s
->face
->foreground
)
878 xgcv
.background
= s
->face
->foreground
;
879 xgcv
.foreground
= s
->face
->background
;
882 IF_DEBUG (x_check_font (s
->f
, s
->font
));
883 xgcv
.graphics_exposures
= False
;
884 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
886 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
887 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
890 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
891 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
893 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
898 /* Set up S->gc of glyph string S for drawing text in mouse face. */
901 x_set_mouse_face_gc (struct glyph_string
*s
)
906 /* What face has to be used last for the mouse face? */
907 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
908 face
= FACE_FROM_ID (s
->f
, face_id
);
910 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
912 if (s
->first_glyph
->type
== CHAR_GLYPH
)
913 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
915 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
916 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
917 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
919 if (s
->font
== s
->face
->font
)
923 /* Otherwise construct scratch_cursor_gc with values from FACE
928 xgcv
.background
= s
->face
->background
;
929 xgcv
.foreground
= s
->face
->foreground
;
930 xgcv
.graphics_exposures
= False
;
931 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
933 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
934 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
937 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
938 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
940 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
943 eassert (s
->gc
!= 0);
947 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
948 Faces to use in the mode line have already been computed when the
949 matrix was built, so there isn't much to do, here. */
952 x_set_mode_line_face_gc (struct glyph_string
*s
)
958 /* Set S->gc of glyph string S for drawing that glyph string. Set
959 S->stippled_p to a non-zero value if the face of S has a stipple
963 x_set_glyph_string_gc (struct glyph_string
*s
)
965 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
967 if (s
->hl
== DRAW_NORMAL_TEXT
)
970 s
->stippled_p
= s
->face
->stipple
!= 0;
972 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
974 x_set_mode_line_face_gc (s
);
975 s
->stippled_p
= s
->face
->stipple
!= 0;
977 else if (s
->hl
== DRAW_CURSOR
)
982 else if (s
->hl
== DRAW_MOUSE_FACE
)
984 x_set_mouse_face_gc (s
);
985 s
->stippled_p
= s
->face
->stipple
!= 0;
987 else if (s
->hl
== DRAW_IMAGE_RAISED
988 || s
->hl
== DRAW_IMAGE_SUNKEN
)
991 s
->stippled_p
= s
->face
->stipple
!= 0;
996 s
->stippled_p
= s
->face
->stipple
!= 0;
999 /* GC must have been set. */
1000 eassert (s
->gc
!= 0);
1004 /* Set clipping for output of glyph string S. S may be part of a mode
1005 line or menu if we don't have X toolkit support. */
1008 x_set_glyph_string_clipping (struct glyph_string
*s
)
1010 XRectangle
*r
= s
->clip
;
1011 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1014 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1019 /* Set SRC's clipping for output of glyph string DST. This is called
1020 when we are drawing DST's left_overhang or right_overhang only in
1024 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1029 r
.width
= src
->width
;
1031 r
.height
= src
->height
;
1034 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1039 Compute left and right overhang of glyph string S. */
1042 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1045 && (s
->first_glyph
->type
== CHAR_GLYPH
1046 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1048 struct font_metrics metrics
;
1050 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1052 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1053 struct font
*font
= s
->font
;
1056 for (i
= 0; i
< s
->nchars
; i
++)
1057 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1058 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1062 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1064 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1066 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1067 ? metrics
.rbearing
- metrics
.width
: 0);
1068 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1072 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1073 s
->left_overhang
= - s
->cmp
->lbearing
;
1078 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1081 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1084 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1085 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1086 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1087 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1091 /* Draw the background of glyph_string S. If S->background_filled_p
1092 is non-zero don't draw it. FORCE_P non-zero means draw the
1093 background even if it wouldn't be drawn normally. This is used
1094 when a string preceding S draws into the background of S, or S
1095 contains the first component of a composition. */
1098 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1100 /* Nothing to do if background has already been drawn or if it
1101 shouldn't be drawn in the first place. */
1102 if (!s
->background_filled_p
)
1104 int box_line_width
= max (s
->face
->box_line_width
, 0);
1108 /* Fill background with a stipple pattern. */
1109 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1110 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1111 s
->y
+ box_line_width
,
1112 s
->background_width
,
1113 s
->height
- 2 * box_line_width
);
1114 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1115 s
->background_filled_p
= 1;
1117 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1118 || s
->font_not_found_p
1119 || s
->extends_to_end_of_line_p
1122 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1123 s
->background_width
,
1124 s
->height
- 2 * box_line_width
);
1125 s
->background_filled_p
= 1;
1131 /* Draw the foreground of glyph string S. */
1134 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1138 /* If first glyph of S has a left box line, start drawing the text
1139 of S to the right of that box line. */
1140 if (s
->face
->box
!= FACE_NO_BOX
1141 && s
->first_glyph
->left_box_line_p
)
1142 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1146 /* Draw characters of S as rectangles if S's font could not be
1148 if (s
->font_not_found_p
)
1150 for (i
= 0; i
< s
->nchars
; ++i
)
1152 struct glyph
*g
= s
->first_glyph
+ i
;
1153 XDrawRectangle (s
->display
, s
->window
,
1154 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1156 x
+= g
->pixel_width
;
1161 struct font
*font
= s
->font
;
1162 int boff
= font
->baseline_offset
;
1165 if (font
->vertical_centering
)
1166 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1168 y
= s
->ybase
- boff
;
1170 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1171 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1173 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1174 if (s
->face
->overstrike
)
1175 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1179 /* Draw the foreground of composite glyph string S. */
1182 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1185 struct font
*font
= s
->font
;
1187 /* If first glyph of S has a left box line, start drawing the text
1188 of S to the right of that box line. */
1189 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1190 && s
->first_glyph
->left_box_line_p
)
1191 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1195 /* S is a glyph string for a composition. S->cmp_from is the index
1196 of the first character drawn for glyphs of this composition.
1197 S->cmp_from == 0 means we are drawing the very first character of
1198 this composition. */
1200 /* Draw a rectangle for the composition if the font for the very
1201 first character of the composition could not be loaded. */
1202 if (s
->font_not_found_p
)
1204 if (s
->cmp_from
== 0)
1205 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1206 s
->width
- 1, s
->height
- 1);
1208 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1212 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1213 /* TAB in a composition means display glyphs with padding
1214 space on the left or right. */
1215 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1217 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1218 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1220 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1221 if (s
->face
->overstrike
)
1222 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1227 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1232 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1234 glyph
= LGSTRING_GLYPH (gstring
, i
);
1235 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1236 width
+= LGLYPH_WIDTH (glyph
);
1239 int xoff
, yoff
, wadjust
;
1243 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1244 if (s
->face
->overstrike
)
1245 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1248 xoff
= LGLYPH_XOFF (glyph
);
1249 yoff
= LGLYPH_YOFF (glyph
);
1250 wadjust
= LGLYPH_WADJUST (glyph
);
1251 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1252 if (s
->face
->overstrike
)
1253 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1261 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1262 if (s
->face
->overstrike
)
1263 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1269 /* Draw the foreground of glyph string S for glyphless characters. */
1272 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1274 struct glyph
*glyph
= s
->first_glyph
;
1278 /* If first glyph of S has a left box line, start drawing the text
1279 of S to the right of that box line. */
1280 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1281 && s
->first_glyph
->left_box_line_p
)
1282 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1288 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1290 char buf
[7], *str
= NULL
;
1291 int len
= glyph
->u
.glyphless
.len
;
1293 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1296 && CHAR_TABLE_P (Vglyphless_char_display
)
1297 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1301 = (! glyph
->u
.glyphless
.for_no_font
1302 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1303 glyph
->u
.glyphless
.ch
)
1304 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1305 if (STRINGP (acronym
))
1306 str
= SSDATA (acronym
);
1309 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1311 sprintf (buf
, "%0*X",
1312 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1313 glyph
->u
.glyphless
.ch
);
1319 int upper_len
= (len
+ 1) / 2;
1322 /* It is assured that all LEN characters in STR is ASCII. */
1323 for (j
= 0; j
< len
; j
++)
1325 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1326 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1328 s
->font
->driver
->draw (s
, 0, upper_len
,
1329 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1330 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1332 s
->font
->driver
->draw (s
, upper_len
, len
,
1333 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1334 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1337 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1338 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
1339 x
, s
->ybase
- glyph
->ascent
,
1340 glyph
->pixel_width
- 1,
1341 glyph
->ascent
+ glyph
->descent
- 1);
1342 x
+= glyph
->pixel_width
;
1346 #ifdef USE_X_TOOLKIT
1350 /* Return the frame on which widget WIDGET is used.. Abort if frame
1351 cannot be determined. */
1353 static struct frame
*
1354 x_frame_of_widget (Widget widget
)
1356 struct x_display_info
*dpyinfo
;
1357 Lisp_Object tail
, frame
;
1360 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1362 /* Find the top-level shell of the widget. Note that this function
1363 can be called when the widget is not yet realized, so XtWindow
1364 (widget) == 0. That's the reason we can't simply use
1365 x_any_window_to_frame. */
1366 while (!XtIsTopLevelShell (widget
))
1367 widget
= XtParent (widget
);
1369 /* Look for a frame with that top-level widget. Allocate the color
1370 on that frame to get the right gamma correction value. */
1371 FOR_EACH_FRAME (tail
, frame
)
1375 && f
->output_data
.nothing
!= 1
1376 && FRAME_DISPLAY_INFO (f
) == dpyinfo
1377 && f
->output_data
.x
->widget
== widget
)
1383 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1384 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1385 If this produces the same color as PIXEL, try a color where all RGB
1386 values have DELTA added. Return the allocated color in *PIXEL.
1387 DISPLAY is the X display, CMAP is the colormap to operate on.
1388 Value is true if successful. */
1391 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1392 unsigned long *pixel
, double factor
, int delta
)
1394 struct frame
*f
= x_frame_of_widget (widget
);
1395 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1398 #endif /* USE_LUCID */
1401 /* Structure specifying which arguments should be passed by Xt to
1402 cvt_string_to_pixel. We want the widget's screen and colormap. */
1404 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1406 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1408 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1413 /* The address of this variable is returned by
1414 cvt_string_to_pixel. */
1416 static Pixel cvt_string_to_pixel_value
;
1419 /* Convert a color name to a pixel color.
1421 DPY is the display we are working on.
1423 ARGS is an array of *NARGS XrmValue structures holding additional
1424 information about the widget for which the conversion takes place.
1425 The contents of this array are determined by the specification
1426 in cvt_string_to_pixel_args.
1428 FROM is a pointer to an XrmValue which points to the color name to
1429 convert. TO is an XrmValue in which to return the pixel color.
1431 CLOSURE_RET is a pointer to user-data, in which we record if
1432 we allocated the color or not.
1434 Value is True if successful, False otherwise. */
1437 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1438 XrmValue
*from
, XrmValue
*to
,
1439 XtPointer
*closure_ret
)
1449 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1450 "wrongParameters", "cvt_string_to_pixel",
1452 "Screen and colormap args required", NULL
, NULL
);
1456 screen
= *(Screen
**) args
[0].addr
;
1457 cmap
= *(Colormap
*) args
[1].addr
;
1458 color_name
= (String
) from
->addr
;
1460 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1462 *closure_ret
= (XtPointer
) False
;
1463 pixel
= WhitePixelOfScreen (screen
);
1465 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1467 *closure_ret
= (XtPointer
) False
;
1468 pixel
= BlackPixelOfScreen (screen
);
1470 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1471 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1473 pixel
= color
.pixel
;
1474 *closure_ret
= (XtPointer
) True
;
1479 Cardinal nparams
= 1;
1481 params
[0] = color_name
;
1482 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1483 "badValue", "cvt_string_to_pixel",
1484 "XtToolkitError", "Invalid color `%s'",
1489 if (to
->addr
!= NULL
)
1491 if (to
->size
< sizeof (Pixel
))
1493 to
->size
= sizeof (Pixel
);
1497 *(Pixel
*) to
->addr
= pixel
;
1501 cvt_string_to_pixel_value
= pixel
;
1502 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1505 to
->size
= sizeof (Pixel
);
1510 /* Free a pixel color which was previously allocated via
1511 cvt_string_to_pixel. This is registered as the destructor
1512 for this type of resource via XtSetTypeConverter.
1514 APP is the application context in which we work.
1516 TO is a pointer to an XrmValue holding the color to free.
1517 CLOSURE is the value we stored in CLOSURE_RET for this color
1518 in cvt_string_to_pixel.
1520 ARGS and NARGS are like for cvt_string_to_pixel. */
1523 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1528 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1530 "Screen and colormap arguments required",
1533 else if (closure
!= NULL
)
1535 /* We did allocate the pixel, so free it. */
1536 Screen
*screen
= *(Screen
**) args
[0].addr
;
1537 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1538 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1539 (Pixel
*) to
->addr
, 1);
1544 #endif /* USE_X_TOOLKIT */
1547 /* Value is an array of XColor structures for the contents of the
1548 color map of display DPY. Set *NCELLS to the size of the array.
1549 Note that this probably shouldn't be called for large color maps,
1550 say a 24-bit TrueColor map. */
1552 static const XColor
*
1553 x_color_cells (Display
*dpy
, int *ncells
)
1555 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1557 if (dpyinfo
->color_cells
== NULL
)
1559 Screen
*screen
= dpyinfo
->screen
;
1560 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1563 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
1564 sizeof *dpyinfo
->color_cells
);
1565 dpyinfo
->ncolor_cells
= ncolor_cells
;
1567 for (i
= 0; i
< ncolor_cells
; ++i
)
1568 dpyinfo
->color_cells
[i
].pixel
= i
;
1570 XQueryColors (dpy
, dpyinfo
->cmap
,
1571 dpyinfo
->color_cells
, ncolor_cells
);
1574 *ncells
= dpyinfo
->ncolor_cells
;
1575 return dpyinfo
->color_cells
;
1579 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1580 colors in COLORS. Use cached information, if available. */
1583 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1585 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1587 if (dpyinfo
->color_cells
)
1590 for (i
= 0; i
< ncolors
; ++i
)
1592 unsigned long pixel
= colors
[i
].pixel
;
1593 eassert (pixel
< dpyinfo
->ncolor_cells
);
1594 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1595 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1599 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1603 /* On frame F, translate pixel color to RGB values for the color in
1604 COLOR. Use cached information, if available. */
1607 x_query_color (struct frame
*f
, XColor
*color
)
1609 x_query_colors (f
, color
, 1);
1613 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1614 exact match can't be allocated, try the nearest color available.
1615 Value is true if successful. Set *COLOR to the color
1619 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1623 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1626 /* If we got to this point, the colormap is full, so we're going
1627 to try to get the next closest color. The algorithm used is
1628 a least-squares matching, which is what X uses for closest
1629 color matching with StaticColor visuals. */
1631 int max_color_delta
= 255;
1632 int max_delta
= 3 * max_color_delta
;
1633 int nearest_delta
= max_delta
+ 1;
1635 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1637 for (nearest
= i
= 0; i
< ncells
; ++i
)
1639 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1640 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1641 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1642 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1644 if (delta
< nearest_delta
)
1647 nearest_delta
= delta
;
1651 color
->red
= cells
[nearest
].red
;
1652 color
->green
= cells
[nearest
].green
;
1653 color
->blue
= cells
[nearest
].blue
;
1654 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1658 /* If allocation succeeded, and the allocated pixel color is not
1659 equal to a cached pixel color recorded earlier, there was a
1660 change in the colormap, so clear the color cache. */
1661 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1662 XColor
*cached_color
;
1664 if (dpyinfo
->color_cells
1665 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1666 (cached_color
->red
!= color
->red
1667 || cached_color
->blue
!= color
->blue
1668 || cached_color
->green
!= color
->green
)))
1670 xfree (dpyinfo
->color_cells
);
1671 dpyinfo
->color_cells
= NULL
;
1672 dpyinfo
->ncolor_cells
= 0;
1676 #ifdef DEBUG_X_COLORS
1678 register_color (color
->pixel
);
1679 #endif /* DEBUG_X_COLORS */
1685 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1686 exact match can't be allocated, try the nearest color available.
1687 Value is true if successful. Set *COLOR to the color
1691 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1693 gamma_correct (f
, color
);
1694 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1698 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1699 It's necessary to do this instead of just using PIXEL directly to
1700 get color reference counts right. */
1703 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1707 color
.pixel
= pixel
;
1709 x_query_color (f
, &color
);
1710 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1712 #ifdef DEBUG_X_COLORS
1713 register_color (pixel
);
1719 /* Brightness beyond which a color won't have its highlight brightness
1722 Nominally, highlight colors for `3d' faces are calculated by
1723 brightening an object's color by a constant scale factor, but this
1724 doesn't yield good results for dark colors, so for colors who's
1725 brightness is less than this value (on a scale of 0-65535) have an
1726 use an additional additive factor.
1728 The value here is set so that the default menu-bar/mode-line color
1729 (grey75) will not have its highlights changed at all. */
1730 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1733 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1734 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1735 If this produces the same color as PIXEL, try a color where all RGB
1736 values have DELTA added. Return the allocated color in *PIXEL.
1737 DISPLAY is the X display, CMAP is the colormap to operate on.
1738 Value is non-zero if successful. */
1741 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1747 /* Get RGB color values. */
1748 color
.pixel
= *pixel
;
1749 x_query_color (f
, &color
);
1751 /* Change RGB values by specified FACTOR. Avoid overflow! */
1752 eassert (factor
>= 0);
1753 new.red
= min (0xffff, factor
* color
.red
);
1754 new.green
= min (0xffff, factor
* color
.green
);
1755 new.blue
= min (0xffff, factor
* color
.blue
);
1757 /* Calculate brightness of COLOR. */
1758 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1760 /* We only boost colors that are darker than
1761 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1762 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1763 /* Make an additive adjustment to NEW, because it's dark enough so
1764 that scaling by FACTOR alone isn't enough. */
1766 /* How far below the limit this color is (0 - 1, 1 being darker). */
1767 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1768 /* The additive adjustment. */
1769 int min_delta
= delta
* dimness
* factor
/ 2;
1773 new.red
= max (0, new.red
- min_delta
);
1774 new.green
= max (0, new.green
- min_delta
);
1775 new.blue
= max (0, new.blue
- min_delta
);
1779 new.red
= min (0xffff, min_delta
+ new.red
);
1780 new.green
= min (0xffff, min_delta
+ new.green
);
1781 new.blue
= min (0xffff, min_delta
+ new.blue
);
1785 /* Try to allocate the color. */
1786 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1789 if (new.pixel
== *pixel
)
1791 /* If we end up with the same color as before, try adding
1792 delta to the RGB values. */
1793 x_free_colors (f
, &new.pixel
, 1);
1795 new.red
= min (0xffff, delta
+ color
.red
);
1796 new.green
= min (0xffff, delta
+ color
.green
);
1797 new.blue
= min (0xffff, delta
+ color
.blue
);
1798 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1809 /* Set up the foreground color for drawing relief lines of glyph
1810 string S. RELIEF is a pointer to a struct relief containing the GC
1811 with which lines will be drawn. Use a color that is FACTOR or
1812 DELTA lighter or darker than the relief's background which is found
1813 in S->f->output_data.x->relief_background. If such a color cannot
1814 be allocated, use DEFAULT_PIXEL, instead. */
1817 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1820 struct x_output
*di
= f
->output_data
.x
;
1821 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1822 unsigned long pixel
;
1823 unsigned long background
= di
->relief_background
;
1824 Colormap cmap
= FRAME_X_COLORMAP (f
);
1825 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1826 Display
*dpy
= FRAME_X_DISPLAY (f
);
1828 xgcv
.graphics_exposures
= False
;
1829 xgcv
.line_width
= 1;
1831 /* Free previously allocated color. The color cell will be reused
1832 when it has been freed as many times as it was allocated, so this
1833 doesn't affect faces using the same colors. */
1835 && relief
->allocated_p
)
1837 x_free_colors (f
, &relief
->pixel
, 1);
1838 relief
->allocated_p
= 0;
1841 /* Allocate new color. */
1842 xgcv
.foreground
= default_pixel
;
1844 if (dpyinfo
->n_planes
!= 1
1845 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1847 relief
->allocated_p
= 1;
1848 xgcv
.foreground
= relief
->pixel
= pixel
;
1851 if (relief
->gc
== 0)
1853 xgcv
.stipple
= dpyinfo
->gray
;
1855 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1858 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1862 /* Set up colors for the relief lines around glyph string S. */
1865 x_setup_relief_colors (struct glyph_string
*s
)
1867 struct x_output
*di
= s
->f
->output_data
.x
;
1868 unsigned long color
;
1870 if (s
->face
->use_box_color_for_shadows_p
)
1871 color
= s
->face
->box_color
;
1872 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1874 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1875 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1880 /* Get the background color of the face. */
1881 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1882 color
= xgcv
.background
;
1885 if (di
->white_relief
.gc
== 0
1886 || color
!= di
->relief_background
)
1888 di
->relief_background
= color
;
1889 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1890 WHITE_PIX_DEFAULT (s
->f
));
1891 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1892 BLACK_PIX_DEFAULT (s
->f
));
1897 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1898 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1899 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1900 relief. LEFT_P non-zero means draw a relief on the left side of
1901 the rectangle. RIGHT_P non-zero means draw a relief on the right
1902 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1906 x_draw_relief_rect (struct frame
*f
,
1907 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1908 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1909 XRectangle
*clip_rect
)
1911 Display
*dpy
= FRAME_X_DISPLAY (f
);
1912 Window window
= FRAME_X_WINDOW (f
);
1917 gc
= f
->output_data
.x
->white_relief
.gc
;
1919 gc
= f
->output_data
.x
->black_relief
.gc
;
1920 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1922 /* This code is more complicated than it has to be, because of two
1923 minor hacks to make the boxes look nicer: (i) if width > 1, draw
1924 the outermost line using the black relief. (ii) Omit the four
1931 XDrawLine (dpy
, window
, gc
,
1932 left_x
+ (left_p
? 1 : 0), top_y
,
1933 right_x
+ (right_p
? 0 : 1), top_y
);
1935 for (i
= 1; i
< width
; ++i
)
1936 XDrawLine (dpy
, window
, gc
,
1937 left_x
+ i
* left_p
, top_y
+ i
,
1938 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1945 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1947 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
1948 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
1950 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
1951 XDrawLine (dpy
, window
, gc
,
1952 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
1953 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1956 XSetClipMask (dpy
, gc
, None
);
1958 gc
= f
->output_data
.x
->black_relief
.gc
;
1960 gc
= f
->output_data
.x
->white_relief
.gc
;
1961 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1965 /* Outermost top line. */
1967 XDrawLine (dpy
, window
, gc
,
1968 left_x
+ (left_p
? 1 : 0), top_y
,
1969 right_x
+ (right_p
? 0 : 1), top_y
);
1971 /* Outermost left line. */
1973 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1979 XDrawLine (dpy
, window
, gc
,
1980 left_x
+ (left_p
? 1 : 0), bottom_y
,
1981 right_x
+ (right_p
? 0 : 1), bottom_y
);
1982 for (i
= 1; i
< width
; ++i
)
1983 XDrawLine (dpy
, window
, gc
,
1984 left_x
+ i
* left_p
, bottom_y
- i
,
1985 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
1991 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
1992 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
1993 for (i
= 0; i
< width
; ++i
)
1994 XDrawLine (dpy
, window
, gc
,
1995 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
1996 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1999 XSetClipMask (dpy
, gc
, None
);
2003 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2004 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2005 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2006 left side of the rectangle. RIGHT_P non-zero means draw a line
2007 on the right side of the rectangle. CLIP_RECT is the clipping
2008 rectangle to use when drawing. */
2011 x_draw_box_rect (struct glyph_string
*s
,
2012 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2013 int left_p
, int right_p
, XRectangle
*clip_rect
)
2017 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2018 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2019 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2022 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2023 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2027 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2028 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2031 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2032 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2036 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2037 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2039 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2040 XSetClipMask (s
->display
, s
->gc
, None
);
2044 /* Draw a box around glyph string S. */
2047 x_draw_glyph_string_box (struct glyph_string
*s
)
2049 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2050 int left_p
, right_p
;
2051 struct glyph
*last_glyph
;
2052 XRectangle clip_rect
;
2054 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2055 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2056 : window_box_right (s
->w
, s
->area
));
2058 /* The glyph that may have a right box line. */
2059 last_glyph
= (s
->cmp
|| s
->img
2061 : s
->first_glyph
+ s
->nchars
- 1);
2063 width
= eabs (s
->face
->box_line_width
);
2064 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2066 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2068 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2070 bottom_y
= top_y
+ s
->height
- 1;
2072 left_p
= (s
->first_glyph
->left_box_line_p
2073 || (s
->hl
== DRAW_MOUSE_FACE
2075 || s
->prev
->hl
!= s
->hl
)));
2076 right_p
= (last_glyph
->right_box_line_p
2077 || (s
->hl
== DRAW_MOUSE_FACE
2079 || s
->next
->hl
!= s
->hl
)));
2081 get_glyph_string_clip_rect (s
, &clip_rect
);
2083 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2084 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2085 left_p
, right_p
, &clip_rect
);
2088 x_setup_relief_colors (s
);
2089 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2090 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2095 /* Draw foreground of image glyph string S. */
2098 x_draw_image_foreground (struct glyph_string
*s
)
2101 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2103 /* If first glyph of S has a left box line, start drawing it to the
2104 right of that line. */
2105 if (s
->face
->box
!= FACE_NO_BOX
2106 && s
->first_glyph
->left_box_line_p
2108 x
+= eabs (s
->face
->box_line_width
);
2110 /* If there is a margin around the image, adjust x- and y-position
2112 if (s
->slice
.x
== 0)
2113 x
+= s
->img
->hmargin
;
2114 if (s
->slice
.y
== 0)
2115 y
+= s
->img
->vmargin
;
2121 /* We can't set both a clip mask and use XSetClipRectangles
2122 because the latter also sets a clip mask. We also can't
2123 trust on the shape extension to be available
2124 (XShapeCombineRegion). So, compute the rectangle to draw
2126 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2129 XRectangle clip_rect
, image_rect
, r
;
2131 xgcv
.clip_mask
= s
->img
->mask
;
2132 xgcv
.clip_x_origin
= x
;
2133 xgcv
.clip_y_origin
= y
;
2134 xgcv
.function
= GXcopy
;
2135 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2137 get_glyph_string_clip_rect (s
, &clip_rect
);
2140 image_rect
.width
= s
->slice
.width
;
2141 image_rect
.height
= s
->slice
.height
;
2142 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2143 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2144 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2145 r
.width
, r
.height
, r
.x
, r
.y
);
2149 XRectangle clip_rect
, image_rect
, r
;
2151 get_glyph_string_clip_rect (s
, &clip_rect
);
2154 image_rect
.width
= s
->slice
.width
;
2155 image_rect
.height
= s
->slice
.height
;
2156 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2157 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2158 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2159 r
.width
, r
.height
, r
.x
, r
.y
);
2161 /* When the image has a mask, we can expect that at
2162 least part of a mouse highlight or a block cursor will
2163 be visible. If the image doesn't have a mask, make
2164 a block cursor visible by drawing a rectangle around
2165 the image. I believe it's looking better if we do
2166 nothing here for mouse-face. */
2167 if (s
->hl
== DRAW_CURSOR
)
2169 int relief
= eabs (s
->img
->relief
);
2170 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2171 x
- relief
, y
- relief
,
2172 s
->slice
.width
+ relief
*2 - 1,
2173 s
->slice
.height
+ relief
*2 - 1);
2178 /* Draw a rectangle if image could not be loaded. */
2179 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2180 s
->slice
.width
- 1, s
->slice
.height
- 1);
2184 /* Draw a relief around the image glyph string S. */
2187 x_draw_image_relief (struct glyph_string
*s
)
2189 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
2192 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2194 /* If first glyph of S has a left box line, start drawing it to the
2195 right of that line. */
2196 if (s
->face
->box
!= FACE_NO_BOX
2197 && s
->first_glyph
->left_box_line_p
2199 x
+= eabs (s
->face
->box_line_width
);
2201 /* If there is a margin around the image, adjust x- and y-position
2203 if (s
->slice
.x
== 0)
2204 x
+= s
->img
->hmargin
;
2205 if (s
->slice
.y
== 0)
2206 y
+= s
->img
->vmargin
;
2208 if (s
->hl
== DRAW_IMAGE_SUNKEN
2209 || s
->hl
== DRAW_IMAGE_RAISED
)
2211 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2212 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2216 thick
= eabs (s
->img
->relief
);
2217 raised_p
= s
->img
->relief
> 0;
2220 x1
= x
+ s
->slice
.width
- 1;
2221 y1
= y
+ s
->slice
.height
- 1;
2222 top_p
= bot_p
= left_p
= right_p
= 0;
2224 if (s
->slice
.x
== 0)
2225 x
-= thick
, left_p
= 1;
2226 if (s
->slice
.y
== 0)
2227 y
-= thick
, top_p
= 1;
2228 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
2229 x1
+= thick
, right_p
= 1;
2230 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
2231 y1
+= thick
, bot_p
= 1;
2233 x_setup_relief_colors (s
);
2234 get_glyph_string_clip_rect (s
, &r
);
2235 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
2236 top_p
, bot_p
, left_p
, right_p
, &r
);
2240 /* Draw the foreground of image glyph string S to PIXMAP. */
2243 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2246 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2248 /* If first glyph of S has a left box line, start drawing it to the
2249 right of that line. */
2250 if (s
->face
->box
!= FACE_NO_BOX
2251 && s
->first_glyph
->left_box_line_p
2253 x
+= eabs (s
->face
->box_line_width
);
2255 /* If there is a margin around the image, adjust x- and y-position
2257 if (s
->slice
.x
== 0)
2258 x
+= s
->img
->hmargin
;
2259 if (s
->slice
.y
== 0)
2260 y
+= s
->img
->vmargin
;
2266 /* We can't set both a clip mask and use XSetClipRectangles
2267 because the latter also sets a clip mask. We also can't
2268 trust on the shape extension to be available
2269 (XShapeCombineRegion). So, compute the rectangle to draw
2271 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2275 xgcv
.clip_mask
= s
->img
->mask
;
2276 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2277 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2278 xgcv
.function
= GXcopy
;
2279 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2281 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2282 s
->slice
.x
, s
->slice
.y
,
2283 s
->slice
.width
, s
->slice
.height
, x
, y
);
2284 XSetClipMask (s
->display
, s
->gc
, None
);
2288 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2289 s
->slice
.x
, s
->slice
.y
,
2290 s
->slice
.width
, s
->slice
.height
, x
, y
);
2292 /* When the image has a mask, we can expect that at
2293 least part of a mouse highlight or a block cursor will
2294 be visible. If the image doesn't have a mask, make
2295 a block cursor visible by drawing a rectangle around
2296 the image. I believe it's looking better if we do
2297 nothing here for mouse-face. */
2298 if (s
->hl
== DRAW_CURSOR
)
2300 int r
= eabs (s
->img
->relief
);
2301 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2302 s
->slice
.width
+ r
*2 - 1,
2303 s
->slice
.height
+ r
*2 - 1);
2308 /* Draw a rectangle if image could not be loaded. */
2309 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2310 s
->slice
.width
- 1, s
->slice
.height
- 1);
2314 /* Draw part of the background of glyph string S. X, Y, W, and H
2315 give the rectangle to draw. */
2318 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2322 /* Fill background with a stipple pattern. */
2323 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2324 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2325 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2328 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2332 /* Draw image glyph string S.
2335 s->x +-------------------------
2338 | +-------------------------
2341 | | +-------------------
2347 x_draw_image_glyph_string (struct glyph_string
*s
)
2349 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2350 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2352 Pixmap pixmap
= None
;
2355 if (s
->slice
.y
== 0)
2356 height
-= box_line_vwidth
;
2357 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2358 height
-= box_line_vwidth
;
2360 /* Fill background with face under the image. Do it only if row is
2361 taller than image or if image has a clip mask to reduce
2363 s
->stippled_p
= s
->face
->stipple
!= 0;
2364 if (height
> s
->slice
.height
2368 || s
->img
->pixmap
== 0
2369 || s
->width
!= s
->background_width
)
2373 /* Create a pixmap as large as the glyph string. Fill it
2374 with the background color. Copy the image to it, using
2375 its mask. Copy the temporary pixmap to the display. */
2376 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2377 int depth
= DefaultDepthOfScreen (screen
);
2379 /* Create a pixmap as large as the glyph string. */
2380 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2381 s
->background_width
,
2384 /* Don't clip in the following because we're working on the
2386 XSetClipMask (s
->display
, s
->gc
, None
);
2388 /* Fill the pixmap with the background color/stipple. */
2391 /* Fill background with a stipple pattern. */
2392 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2393 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2394 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2395 0, 0, s
->background_width
, s
->height
);
2396 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2397 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2402 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2404 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2405 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2406 0, 0, s
->background_width
, s
->height
);
2407 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2415 if (s
->first_glyph
->left_box_line_p
2417 x
+= box_line_hwidth
;
2419 if (s
->slice
.y
== 0)
2420 y
+= box_line_vwidth
;
2422 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2425 s
->background_filled_p
= 1;
2428 /* Draw the foreground. */
2431 x_draw_image_foreground_1 (s
, pixmap
);
2432 x_set_glyph_string_clipping (s
);
2433 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2434 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2435 XFreePixmap (s
->display
, pixmap
);
2438 x_draw_image_foreground (s
);
2440 /* If we must draw a relief around the image, do it. */
2442 || s
->hl
== DRAW_IMAGE_RAISED
2443 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2444 x_draw_image_relief (s
);
2448 /* Draw stretch glyph string S. */
2451 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2453 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2455 if (s
->hl
== DRAW_CURSOR
2456 && !x_stretch_cursor_p
)
2458 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2459 wide as the stretch glyph. */
2460 int width
, background_width
= s
->background_width
;
2463 if (!s
->row
->reversed_p
)
2465 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2469 background_width
-= left_x
- x
;
2475 /* In R2L rows, draw the cursor on the right edge of the
2477 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2479 if (x
+ background_width
> right_x
)
2480 background_width
-= x
- right_x
;
2481 x
+= background_width
;
2483 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2484 if (s
->row
->reversed_p
)
2488 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2490 /* Clear rest using the GC of the original non-cursor face. */
2491 if (width
< background_width
)
2494 int w
= background_width
- width
, h
= s
->height
;
2498 if (!s
->row
->reversed_p
)
2502 if (s
->row
->mouse_face_p
2503 && cursor_in_mouse_face_p (s
->w
))
2505 x_set_mouse_face_gc (s
);
2511 get_glyph_string_clip_rect (s
, &r
);
2512 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2514 if (s
->face
->stipple
)
2516 /* Fill background with a stipple pattern. */
2517 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2518 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2519 XSetFillStyle (s
->display
, gc
, FillSolid
);
2524 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2525 XSetForeground (s
->display
, gc
, xgcv
.background
);
2526 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2527 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2531 else if (!s
->background_filled_p
)
2533 int background_width
= s
->background_width
;
2534 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2536 /* Don't draw into left margin, fringe or scrollbar area
2537 except for header line and mode line. */
2538 if (x
< left_x
&& !s
->row
->mode_line_p
)
2540 background_width
-= left_x
- x
;
2543 if (background_width
> 0)
2544 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2547 s
->background_filled_p
= 1;
2551 Draw a wavy line under S. The wave fills wave_height pixels from y0.
2557 wave_height = 3 | * * * *
2562 x_draw_underwave (struct glyph_string
*s
)
2564 int wave_height
= 3, wave_length
= 2;
2565 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
2566 XRectangle wave_clip
, string_clip
, final_clip
;
2569 dy
= wave_height
- 1;
2571 y0
= s
->ybase
- wave_height
+ 3;
2575 /* Find and set clipping rectangle */
2579 wave_clip
.width
= width
;
2580 wave_clip
.height
= wave_height
;
2581 get_glyph_string_clip_rect (s
, &string_clip
);
2583 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
2586 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
2588 /* Draw the waves */
2590 x1
= x0
- (x0
% dx
);
2600 if (INT_MAX
- dx
< xmax
)
2605 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
2607 x2
+= dx
, y2
= y0
+ odd
*dy
;
2611 /* Restore previous clipping rectangle(s) */
2612 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
2616 /* Draw glyph string S. */
2619 x_draw_glyph_string (struct glyph_string
*s
)
2621 bool relief_drawn_p
= 0;
2623 /* If S draws into the background of its successors, draw the
2624 background of the successors first so that S can draw into it.
2625 This makes S->next use XDrawString instead of XDrawImageString. */
2626 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2629 struct glyph_string
*next
;
2631 for (width
= 0, next
= s
->next
;
2632 next
&& width
< s
->right_overhang
;
2633 width
+= next
->width
, next
= next
->next
)
2634 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2636 x_set_glyph_string_gc (next
);
2637 x_set_glyph_string_clipping (next
);
2638 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2639 x_draw_stretch_glyph_string (next
);
2641 x_draw_glyph_string_background (next
, 1);
2642 next
->num_clips
= 0;
2646 /* Set up S->gc, set clipping and draw S. */
2647 x_set_glyph_string_gc (s
);
2649 /* Draw relief (if any) in advance for char/composition so that the
2650 glyph string can be drawn over it. */
2651 if (!s
->for_overlaps
2652 && s
->face
->box
!= FACE_NO_BOX
2653 && (s
->first_glyph
->type
== CHAR_GLYPH
2654 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2657 x_set_glyph_string_clipping (s
);
2658 x_draw_glyph_string_background (s
, 1);
2659 x_draw_glyph_string_box (s
);
2660 x_set_glyph_string_clipping (s
);
2663 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2665 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2666 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2667 /* We must clip just this glyph. left_overhang part has already
2668 drawn when s->prev was drawn, and right_overhang part will be
2669 drawn later when s->next is drawn. */
2670 x_set_glyph_string_clipping_exactly (s
, s
);
2672 x_set_glyph_string_clipping (s
);
2674 switch (s
->first_glyph
->type
)
2677 x_draw_image_glyph_string (s
);
2681 x_draw_stretch_glyph_string (s
);
2685 if (s
->for_overlaps
)
2686 s
->background_filled_p
= 1;
2688 x_draw_glyph_string_background (s
, 0);
2689 x_draw_glyph_string_foreground (s
);
2692 case COMPOSITE_GLYPH
:
2693 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2694 && ! s
->first_glyph
->u
.cmp
.automatic
))
2695 s
->background_filled_p
= 1;
2697 x_draw_glyph_string_background (s
, 1);
2698 x_draw_composite_glyph_string_foreground (s
);
2701 case GLYPHLESS_GLYPH
:
2702 if (s
->for_overlaps
)
2703 s
->background_filled_p
= 1;
2705 x_draw_glyph_string_background (s
, 1);
2706 x_draw_glyphless_glyph_string_foreground (s
);
2713 if (!s
->for_overlaps
)
2715 /* Draw underline. */
2716 if (s
->face
->underline_p
)
2718 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2720 if (s
->face
->underline_defaulted_p
)
2721 x_draw_underwave (s
);
2725 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2726 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2727 x_draw_underwave (s
);
2728 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2731 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2733 unsigned long thickness
, position
;
2736 if (s
->prev
&& s
->prev
->face
->underline_p
2737 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2739 /* We use the same underline style as the previous one. */
2740 thickness
= s
->prev
->underline_thickness
;
2741 position
= s
->prev
->underline_position
;
2745 /* Get the underline thickness. Default is 1 pixel. */
2746 if (s
->font
&& s
->font
->underline_thickness
> 0)
2747 thickness
= s
->font
->underline_thickness
;
2750 if (x_underline_at_descent_line
)
2751 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2754 /* Get the underline position. This is the recommended
2755 vertical offset in pixels from the baseline to the top of
2756 the underline. This is a signed value according to the
2757 specs, and its default is
2759 ROUND ((maximum descent) / 2), with
2760 ROUND(x) = floor (x + 0.5) */
2762 if (x_use_underline_position_properties
2763 && s
->font
&& s
->font
->underline_position
>= 0)
2764 position
= s
->font
->underline_position
;
2766 position
= (s
->font
->descent
+ 1) / 2;
2768 position
= underline_minimum_offset
;
2770 position
= max (position
, underline_minimum_offset
);
2772 /* Check the sanity of thickness and position. We should
2773 avoid drawing underline out of the current line area. */
2774 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2775 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2776 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2777 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2778 s
->underline_thickness
= thickness
;
2779 s
->underline_position
= position
;
2780 y
= s
->ybase
+ position
;
2781 if (s
->face
->underline_defaulted_p
)
2782 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2783 s
->x
, y
, s
->width
, thickness
);
2787 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2788 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2789 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2790 s
->x
, y
, s
->width
, thickness
);
2791 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2795 /* Draw overline. */
2796 if (s
->face
->overline_p
)
2798 unsigned long dy
= 0, h
= 1;
2800 if (s
->face
->overline_color_defaulted_p
)
2801 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2806 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2807 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2808 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2810 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2814 /* Draw strike-through. */
2815 if (s
->face
->strike_through_p
)
2817 unsigned long h
= 1;
2818 unsigned long dy
= (s
->height
- h
) / 2;
2820 if (s
->face
->strike_through_color_defaulted_p
)
2821 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2826 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2827 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2828 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2830 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2834 /* Draw relief if not yet drawn. */
2835 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2836 x_draw_glyph_string_box (s
);
2840 struct glyph_string
*prev
;
2842 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2843 if (prev
->hl
!= s
->hl
2844 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2846 /* As prev was drawn while clipped to its own area, we
2847 must draw the right_overhang part using s->hl now. */
2848 enum draw_glyphs_face save
= prev
->hl
;
2851 x_set_glyph_string_gc (prev
);
2852 x_set_glyph_string_clipping_exactly (s
, prev
);
2853 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2854 x_draw_glyph_string_foreground (prev
);
2856 x_draw_composite_glyph_string_foreground (prev
);
2857 XSetClipMask (prev
->display
, prev
->gc
, None
);
2859 prev
->num_clips
= 0;
2865 struct glyph_string
*next
;
2867 for (next
= s
->next
; next
; next
= next
->next
)
2868 if (next
->hl
!= s
->hl
2869 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2871 /* As next will be drawn while clipped to its own area,
2872 we must draw the left_overhang part using s->hl now. */
2873 enum draw_glyphs_face save
= next
->hl
;
2876 x_set_glyph_string_gc (next
);
2877 x_set_glyph_string_clipping_exactly (s
, next
);
2878 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2879 x_draw_glyph_string_foreground (next
);
2881 x_draw_composite_glyph_string_foreground (next
);
2882 XSetClipMask (next
->display
, next
->gc
, None
);
2884 next
->num_clips
= 0;
2885 next
->clip_head
= s
->next
;
2890 /* Reset clipping. */
2891 XSetClipMask (s
->display
, s
->gc
, None
);
2895 /* Shift display to make room for inserted glyphs. */
2898 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2900 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2901 f
->output_data
.x
->normal_gc
,
2902 x
, y
, width
, height
,
2906 /* Delete N glyphs at the nominal cursor position. Not implemented
2910 x_delete_glyphs (struct frame
*f
, register int n
)
2916 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2917 If they are <= 0, this is probably an error. */
2920 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
)
2922 eassert (width
> 0 && height
> 0);
2923 XClearArea (dpy
, window
, x
, y
, width
, height
, False
);
2927 /* Clear an entire frame. */
2930 x_clear_frame (struct frame
*f
)
2932 /* Clearing the frame will erase any cursor, so mark them all as no
2934 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2938 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2940 /* We have to clear the scroll bars. If we have changed colors or
2941 something like that, then they should be notified. */
2942 x_scroll_bar_clear (f
);
2944 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2945 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2946 redisplay, do it here. */
2947 if (FRAME_GTK_WIDGET (f
))
2948 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2951 XFlush (FRAME_X_DISPLAY (f
));
2958 /* Invert the middle quarter of the frame for .15 sec. */
2961 XTflash (struct frame
*f
)
2967 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
2968 when the scroll bars and the edit widget share the same X window. */
2969 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
2971 cairo_t
*cr
= gdk_cairo_create (window
);
2972 cairo_set_source_rgb (cr
, 1, 1, 1);
2973 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
2974 #define XFillRectangle(d, win, gc, x, y, w, h) \
2976 cairo_rectangle (cr, x, y, w, h); \
2980 #else /* ! HAVE_GTK3 */
2983 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
2984 ^ FRAME_BACKGROUND_PIXEL (f
));
2985 vals
.function
= GDK_XOR
;
2986 gc
= gdk_gc_new_with_values (window
,
2987 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
2988 #define XFillRectangle(d, win, gc, x, y, w, h) \
2989 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
2990 #endif /* ! HAVE_GTK3 */
2991 #else /* ! USE_GTK */
2994 /* Create a GC that will use the GXxor function to flip foreground
2995 pixels into background pixels. */
2999 values
.function
= GXxor
;
3000 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3001 ^ FRAME_BACKGROUND_PIXEL (f
));
3003 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3004 GCFunction
| GCForeground
, &values
);
3008 /* Get the height not including a menu bar widget. */
3009 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3010 /* Height of each line to flash. */
3011 int flash_height
= FRAME_LINE_HEIGHT (f
);
3012 /* These will be the left and right margins of the rectangles. */
3013 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3014 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3015 int width
= flash_right
- flash_left
;
3017 /* If window is tall, flash top and bottom line. */
3018 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3020 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3022 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3023 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3024 width
, flash_height
);
3025 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3027 (height
- flash_height
3028 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3029 width
, flash_height
);
3033 /* If it is short, flash it all. */
3034 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3035 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3036 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3041 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
3042 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
3044 /* Keep waiting until past the time wakeup or any input gets
3046 while (! detect_input_pending ())
3048 struct timespec current
= current_timespec ();
3049 struct timespec timeout
;
3051 /* Break if result would not be positive. */
3052 if (timespec_cmp (wakeup
, current
) <= 0)
3055 /* How long `select' should wait. */
3056 timeout
= make_timespec (0, 10 * 1000 * 1000);
3058 /* Try to wait that long--but we might wake up sooner. */
3059 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3063 /* If window is tall, flash top and bottom line. */
3064 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3066 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3068 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3069 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3070 width
, flash_height
);
3071 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3073 (height
- flash_height
3074 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3075 width
, flash_height
);
3078 /* If it is short, flash it all. */
3079 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3080 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3081 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3087 g_object_unref (G_OBJECT (gc
));
3089 #undef XFillRectangle
3091 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3102 XTtoggle_invisible_pointer (struct frame
*f
, int invisible
)
3107 if (FRAME_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3108 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3109 FRAME_DISPLAY_INFO (f
)->invisible_cursor
);
3112 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3113 f
->output_data
.x
->current_cursor
);
3114 f
->pointer_invisible
= invisible
;
3119 /* Make audible bell. */
3122 XTring_bell (struct frame
*f
)
3124 if (FRAME_X_DISPLAY (f
))
3132 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
3134 XBell (FRAME_X_DISPLAY (f
), 0);
3136 XFlush (FRAME_X_DISPLAY (f
));
3142 /***********************************************************************
3144 ***********************************************************************/
3146 /* Perform an insert-lines or delete-lines operation, inserting N
3147 lines or deleting -N lines at vertical position VPOS. */
3150 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3156 /* Scroll part of the display as described by RUN. */
3159 x_scroll_run (struct window
*w
, struct run
*run
)
3161 struct frame
*f
= XFRAME (w
->frame
);
3162 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3164 /* Get frame-relative bounding box of the text display area of W,
3165 without mode lines. Include in this box the left and right
3167 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
3169 #ifdef USE_TOOLKIT_SCROLL_BARS
3170 /* If the fringe is adjacent to the left (right) scroll bar of a
3171 leftmost (rightmost, respectively) window, then extend its
3172 background to the gap between the fringe and the bar. */
3173 if ((WINDOW_LEFTMOST_P (w
)
3174 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
3175 || (WINDOW_RIGHTMOST_P (w
)
3176 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
3178 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3182 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
3183 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
3184 * FRAME_COLUMN_WIDTH (f
));
3186 if (bar_area_x
+ bar_area_width
== x
)
3188 x
= bar_area_x
+ sb_width
;
3189 width
+= bar_area_width
- sb_width
;
3191 else if (x
+ width
== bar_area_x
)
3192 width
+= bar_area_width
- sb_width
;
3197 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3198 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3199 bottom_y
= y
+ height
;
3203 /* Scrolling up. Make sure we don't copy part of the mode
3204 line at the bottom. */
3205 if (from_y
+ run
->height
> bottom_y
)
3206 height
= bottom_y
- from_y
;
3208 height
= run
->height
;
3212 /* Scrolling down. Make sure we don't copy over the mode line.
3214 if (to_y
+ run
->height
> bottom_y
)
3215 height
= bottom_y
- to_y
;
3217 height
= run
->height
;
3222 /* Cursor off. Will be switched on again in x_update_window_end. */
3225 XCopyArea (FRAME_X_DISPLAY (f
),
3226 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3227 f
->output_data
.x
->normal_gc
,
3237 /***********************************************************************
3239 ***********************************************************************/
3243 frame_highlight (struct frame
*f
)
3245 /* We used to only do this if Vx_no_window_manager was non-nil, but
3246 the ICCCM (section 4.1.6) says that the window's border pixmap
3247 and border pixel are window attributes which are "private to the
3248 client", so we can always change it to whatever we want. */
3250 /* I recently started to get errors in this XSetWindowBorder, depending on
3251 the window-manager in use, tho something more is at play since I've been
3252 using that same window-manager binary for ever. Let's not crash just
3253 because of this (bug#9310). */
3254 x_catch_errors (FRAME_X_DISPLAY (f
));
3255 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3256 f
->output_data
.x
->border_pixel
);
3257 x_uncatch_errors ();
3259 x_update_cursor (f
, 1);
3260 x_set_frame_alpha (f
);
3264 frame_unhighlight (struct frame
*f
)
3266 /* We used to only do this if Vx_no_window_manager was non-nil, but
3267 the ICCCM (section 4.1.6) says that the window's border pixmap
3268 and border pixel are window attributes which are "private to the
3269 client", so we can always change it to whatever we want. */
3271 /* Same as above for XSetWindowBorder (bug#9310). */
3272 x_catch_errors (FRAME_X_DISPLAY (f
));
3273 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3274 f
->output_data
.x
->border_tile
);
3275 x_uncatch_errors ();
3277 x_update_cursor (f
, 1);
3278 x_set_frame_alpha (f
);
3281 /* The focus has changed. Update the frames as necessary to reflect
3282 the new situation. Note that we can't change the selected frame
3283 here, because the Lisp code we are interrupting might become confused.
3284 Each event gets marked with the frame in which it occurred, so the
3285 Lisp code can tell when the switch took place by examining the events. */
3288 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3290 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3292 if (frame
!= dpyinfo
->x_focus_frame
)
3294 /* Set this before calling other routines, so that they see
3295 the correct value of x_focus_frame. */
3296 dpyinfo
->x_focus_frame
= frame
;
3298 if (old_focus
&& old_focus
->auto_lower
)
3299 x_lower_frame (old_focus
);
3301 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3302 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3304 pending_autoraise_frame
= 0;
3307 x_frame_rehighlight (dpyinfo
);
3310 /* Handle FocusIn and FocusOut state changes for FRAME.
3311 If FRAME has focus and there exists more than one frame, puts
3312 a FOCUS_IN_EVENT into *BUFP. */
3315 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3317 if (type
== FocusIn
)
3319 if (dpyinfo
->x_focus_event_frame
!= frame
)
3321 x_new_focus_frame (dpyinfo
, frame
);
3322 dpyinfo
->x_focus_event_frame
= frame
;
3324 /* Don't stop displaying the initial startup message
3325 for a switch-frame event we don't need. */
3326 /* When run as a daemon, Vterminal_frame is always NIL. */
3327 bufp
->arg
= (((NILP (Vterminal_frame
) || EQ (Fdaemonp (), Qt
))
3328 && CONSP (Vframe_list
)
3329 && !NILP (XCDR (Vframe_list
)))
3331 bufp
->kind
= FOCUS_IN_EVENT
;
3332 XSETFRAME (bufp
->frame_or_window
, frame
);
3335 frame
->output_data
.x
->focus_state
|= state
;
3338 if (FRAME_XIC (frame
))
3339 XSetICFocus (FRAME_XIC (frame
));
3342 else if (type
== FocusOut
)
3344 frame
->output_data
.x
->focus_state
&= ~state
;
3346 if (dpyinfo
->x_focus_event_frame
== frame
)
3348 dpyinfo
->x_focus_event_frame
= 0;
3349 x_new_focus_frame (dpyinfo
, 0);
3351 bufp
->kind
= FOCUS_OUT_EVENT
;
3352 XSETFRAME (bufp
->frame_or_window
, frame
);
3356 if (FRAME_XIC (frame
))
3357 XUnsetICFocus (FRAME_XIC (frame
));
3359 if (frame
->pointer_invisible
)
3360 XTtoggle_invisible_pointer (frame
, 0);
3364 /* Return the Emacs frame-object corresponding to an X window.
3365 It could be the frame's main window or an icon window. */
3367 static struct frame
*
3368 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3370 Lisp_Object tail
, frame
;
3376 FOR_EACH_FRAME (tail
, frame
)
3379 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3381 if (f
->output_data
.x
->hourglass_window
== wdesc
)
3383 #ifdef USE_X_TOOLKIT
3384 if ((f
->output_data
.x
->edit_widget
3385 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
3386 /* A tooltip frame? */
3387 || (!f
->output_data
.x
->edit_widget
3388 && FRAME_X_WINDOW (f
) == wdesc
)
3389 || f
->output_data
.x
->icon_desc
== wdesc
)
3391 #else /* not USE_X_TOOLKIT */
3393 if (f
->output_data
.x
->edit_widget
)
3395 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3396 struct x_output
*x
= f
->output_data
.x
;
3397 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
3400 #endif /* USE_GTK */
3401 if (FRAME_X_WINDOW (f
) == wdesc
3402 || f
->output_data
.x
->icon_desc
== wdesc
)
3404 #endif /* not USE_X_TOOLKIT */
3409 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3411 /* Like x_window_to_frame but also compares the window with the widget's
3414 static struct frame
*
3415 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3417 Lisp_Object tail
, frame
;
3418 struct frame
*f
, *found
= NULL
;
3424 FOR_EACH_FRAME (tail
, frame
)
3429 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
3431 /* This frame matches if the window is any of its widgets. */
3432 x
= f
->output_data
.x
;
3433 if (x
->hourglass_window
== wdesc
)
3438 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3440 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
3443 if (wdesc
== XtWindow (x
->widget
)
3444 || wdesc
== XtWindow (x
->column_widget
)
3445 || wdesc
== XtWindow (x
->edit_widget
))
3447 /* Match if the window is this frame's menubar. */
3448 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3452 else if (FRAME_X_WINDOW (f
) == wdesc
)
3453 /* A tooltip frame. */
3461 /* Likewise, but consider only the menu bar widget. */
3463 static struct frame
*
3464 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
,
3465 const XEvent
*event
)
3467 Window wdesc
= event
->xany
.window
;
3468 Lisp_Object tail
, frame
;
3475 FOR_EACH_FRAME (tail
, frame
)
3478 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3480 x
= f
->output_data
.x
;
3482 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
3485 /* Match if the window is this frame's menubar. */
3486 if (x
->menubar_widget
3487 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3494 /* Return the frame whose principal (outermost) window is WDESC.
3495 If WDESC is some other (smaller) window, we return 0. */
3498 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3500 Lisp_Object tail
, frame
;
3507 FOR_EACH_FRAME (tail
, frame
)
3510 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3512 x
= f
->output_data
.x
;
3516 /* This frame matches if the window is its topmost widget. */
3518 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3519 if (gwdesc
== x
->widget
)
3522 if (wdesc
== XtWindow (x
->widget
))
3526 else if (FRAME_X_WINDOW (f
) == wdesc
)
3527 /* Tooltip frame. */
3533 #else /* !USE_X_TOOLKIT && !USE_GTK */
3535 #define x_any_window_to_frame(d, i) x_window_to_frame (d, i)
3536 #define x_top_window_to_frame(d, i) x_window_to_frame (d, i)
3538 #endif /* USE_X_TOOLKIT || USE_GTK */
3540 /* The focus may have changed. Figure out if it is a real focus change,
3541 by checking both FocusIn/Out and Enter/LeaveNotify events.
3543 Returns FOCUS_IN_EVENT event in *BUFP. */
3546 x_detect_focus_change (struct x_display_info
*dpyinfo
, struct frame
*frame
,
3547 const XEvent
*event
, struct input_event
*bufp
)
3552 switch (event
->type
)
3557 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3559 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3561 if (event
->xcrossing
.detail
!= NotifyInferior
3562 && event
->xcrossing
.focus
3563 && ! (focus_state
& FOCUS_EXPLICIT
))
3564 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3566 dpyinfo
, frame
, bufp
);
3572 x_focus_changed (event
->type
,
3573 (event
->xfocus
.detail
== NotifyPointer
?
3574 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3575 dpyinfo
, frame
, bufp
);
3579 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3581 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3582 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3583 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3590 #if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
3591 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3594 x_mouse_leave (struct x_display_info
*dpyinfo
)
3596 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3600 /* The focus has changed, or we have redirected a frame's focus to
3601 another frame (this happens when a frame uses a surrogate
3602 mini-buffer frame). Shift the highlight as appropriate.
3604 The FRAME argument doesn't necessarily have anything to do with which
3605 frame is being highlighted or un-highlighted; we only use it to find
3606 the appropriate X display info. */
3609 XTframe_rehighlight (struct frame
*frame
)
3611 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
3615 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3617 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3619 if (dpyinfo
->x_focus_frame
)
3621 dpyinfo
->x_highlight_frame
3622 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3623 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3624 : dpyinfo
->x_focus_frame
);
3625 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3627 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
3628 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3632 dpyinfo
->x_highlight_frame
= 0;
3634 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3637 frame_unhighlight (old_highlight
);
3638 if (dpyinfo
->x_highlight_frame
)
3639 frame_highlight (dpyinfo
->x_highlight_frame
);
3645 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3647 /* Initialize mode_switch_bit and modifier_meaning. */
3649 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3651 int min_code
, max_code
;
3654 XModifierKeymap
*mods
;
3656 dpyinfo
->meta_mod_mask
= 0;
3657 dpyinfo
->shift_lock_mask
= 0;
3658 dpyinfo
->alt_mod_mask
= 0;
3659 dpyinfo
->super_mod_mask
= 0;
3660 dpyinfo
->hyper_mod_mask
= 0;
3662 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3664 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3665 min_code
, max_code
- min_code
+ 1,
3667 mods
= XGetModifierMapping (dpyinfo
->display
);
3669 /* Scan the modifier table to see which modifier bits the Meta and
3670 Alt keysyms are on. */
3672 int row
, col
; /* The row and column in the modifier table. */
3673 int found_alt_or_meta
;
3675 for (row
= 3; row
< 8; row
++)
3677 found_alt_or_meta
= 0;
3678 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3680 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3682 /* Zeroes are used for filler. Skip them. */
3686 /* Are any of this keycode's keysyms a meta key? */
3690 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3692 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3698 found_alt_or_meta
= 1;
3699 dpyinfo
->meta_mod_mask
|= (1 << row
);
3704 found_alt_or_meta
= 1;
3705 dpyinfo
->alt_mod_mask
|= (1 << row
);
3710 if (!found_alt_or_meta
)
3711 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3712 code_col
= syms_per_code
;
3713 col
= mods
->max_keypermod
;
3718 if (!found_alt_or_meta
)
3719 dpyinfo
->super_mod_mask
|= (1 << row
);
3720 code_col
= syms_per_code
;
3721 col
= mods
->max_keypermod
;
3725 /* Ignore this if it's not on the lock modifier. */
3726 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3727 dpyinfo
->shift_lock_mask
= LockMask
;
3728 code_col
= syms_per_code
;
3729 col
= mods
->max_keypermod
;
3738 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3739 if (! dpyinfo
->meta_mod_mask
)
3741 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3742 dpyinfo
->alt_mod_mask
= 0;
3745 /* If some keys are both alt and meta,
3746 make them just meta, not alt. */
3747 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3749 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3753 XFreeModifiermap (mods
);
3756 /* Convert between the modifier bits X uses and the modifier bits
3760 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
3762 int mod_meta
= meta_modifier
;
3763 int mod_alt
= alt_modifier
;
3764 int mod_hyper
= hyper_modifier
;
3765 int mod_super
= super_modifier
;
3768 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3769 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
3770 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3771 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
3772 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3773 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
3774 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3775 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
3777 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3778 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3779 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3780 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3781 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3782 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3786 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
3788 EMACS_INT mod_meta
= meta_modifier
;
3789 EMACS_INT mod_alt
= alt_modifier
;
3790 EMACS_INT mod_hyper
= hyper_modifier
;
3791 EMACS_INT mod_super
= super_modifier
;
3795 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3796 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
3797 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3798 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
3799 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3800 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
3801 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3802 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
3805 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3806 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3807 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3808 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3809 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3810 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3813 /* Convert a keysym to its name. */
3816 x_get_keysym_name (int keysym
)
3821 value
= XKeysymToString (keysym
);
3829 /* Mouse clicks and mouse movement. Rah. */
3831 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3833 If the event is a button press, then note that we have grabbed
3837 construct_mouse_click (struct input_event
*result
,
3838 const XButtonEvent
*event
,
3841 /* Make the event type NO_EVENT; we'll change that when we decide
3843 result
->kind
= MOUSE_CLICK_EVENT
;
3844 result
->code
= event
->button
- Button1
;
3845 result
->timestamp
= event
->time
;
3846 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
),
3848 | (event
->type
== ButtonRelease
3852 XSETINT (result
->x
, event
->x
);
3853 XSETINT (result
->y
, event
->y
);
3854 XSETFRAME (result
->frame_or_window
, f
);
3859 /* Function to report a mouse movement to the mainstream Emacs code.
3860 The input handler calls this.
3862 We have received a mouse movement event, which is given in *event.
3863 If the mouse is over a different glyph than it was last time, tell
3864 the mainstream emacs code by setting mouse_moved. If not, ask for
3865 another motion event, so we can check again the next time it moves. */
3867 static XMotionEvent last_mouse_motion_event
;
3868 static Lisp_Object last_mouse_motion_frame
;
3871 note_mouse_movement (struct frame
*frame
, const XMotionEvent
*event
)
3873 last_mouse_movement_time
= event
->time
;
3874 last_mouse_motion_event
= *event
;
3875 XSETFRAME (last_mouse_motion_frame
, frame
);
3877 if (!FRAME_X_OUTPUT (frame
))
3880 if (event
->window
!= FRAME_X_WINDOW (frame
))
3882 frame
->mouse_moved
= 1;
3883 last_mouse_scroll_bar
= Qnil
;
3884 note_mouse_highlight (frame
, -1, -1);
3885 last_mouse_glyph_frame
= 0;
3890 /* Has the mouse moved off the glyph it was on at the last sighting? */
3891 if (frame
!= last_mouse_glyph_frame
3892 || event
->x
< last_mouse_glyph
.x
3893 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3894 || event
->y
< last_mouse_glyph
.y
3895 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3897 frame
->mouse_moved
= 1;
3898 last_mouse_scroll_bar
= Qnil
;
3899 note_mouse_highlight (frame
, event
->x
, event
->y
);
3900 /* Remember which glyph we're now on. */
3901 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3902 last_mouse_glyph_frame
= frame
;
3910 /************************************************************************
3912 ************************************************************************/
3915 redo_mouse_highlight (void)
3917 if (!NILP (last_mouse_motion_frame
)
3918 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3919 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3920 last_mouse_motion_event
.x
,
3921 last_mouse_motion_event
.y
);
3926 /* Return the current position of the mouse.
3927 *FP should be a frame which indicates which display to ask about.
3929 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3930 and *PART to the frame, window, and scroll bar part that the mouse
3931 is over. Set *X and *Y to the portion and whole of the mouse's
3932 position on the scroll bar.
3934 If the mouse movement started elsewhere, set *FP to the frame the
3935 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3938 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
3939 was at this position.
3941 Don't store anything if we don't have a valid set of values to report.
3943 This clears the mouse_moved flag, so we can wait for the next mouse
3947 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3948 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3955 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3956 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
3962 Window dummy_window
;
3965 Lisp_Object frame
, tail
;
3967 /* Clear the mouse-moved flag for every frame on this display. */
3968 FOR_EACH_FRAME (tail
, frame
)
3969 if (FRAME_X_P (XFRAME (frame
))
3970 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3971 XFRAME (frame
)->mouse_moved
= 0;
3973 last_mouse_scroll_bar
= Qnil
;
3975 /* Figure out which root window we're on. */
3976 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3977 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3979 /* The root window which contains the pointer. */
3982 /* Trash which we can't trust if the pointer is on
3983 a different screen. */
3986 /* The position on that root window. */
3989 /* More trash we can't trust. */
3992 /* Modifier keys and pointer buttons, about which
3994 (unsigned int *) &dummy
);
3996 /* Now we have a position on the root; find the innermost window
3997 containing the pointer. */
4001 int parent_x
= 0, parent_y
= 0;
4005 /* XTranslateCoordinates can get errors if the window
4006 structure is changing at the same time this function
4007 is running. So at least we must not crash from them. */
4009 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4011 if (FRAME_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4012 && FRAME_LIVE_P (last_mouse_frame
))
4014 /* If mouse was grabbed on a frame, give coords for that frame
4015 even if the mouse is now outside it. */
4016 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4018 /* From-window, to-window. */
4019 root
, FRAME_X_WINDOW (last_mouse_frame
),
4021 /* From-position, to-position. */
4022 root_x
, root_y
, &win_x
, &win_y
,
4026 f1
= last_mouse_frame
;
4032 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4034 /* From-window, to-window. */
4037 /* From-position, to-position. */
4038 root_x
, root_y
, &win_x
, &win_y
,
4043 if (child
== None
|| child
== win
)
4046 /* We don't wan't to know the innermost window. We
4047 want the edit window. For non-Gtk+ the innermost
4048 window is the edit window. For Gtk+ it might not
4049 be. It might be the tool bar for example. */
4050 if (x_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
))
4058 /* Now we know that:
4059 win is the innermost window containing the pointer
4060 (XTC says it has no child containing the pointer),
4061 win_x and win_y are the pointer's position in it
4062 (XTC did this the last time through), and
4063 parent_x and parent_y are the pointer's position in win's parent.
4064 (They are what win_x and win_y were when win was child.
4065 If win is the root window, it has no parent, and
4066 parent_{x,y} are invalid, but that's okay, because we'll
4067 never use them in that case.) */
4070 /* We don't wan't to know the innermost window. We
4071 want the edit window. */
4072 f1
= x_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
);
4074 /* Is win one of our frames? */
4075 f1
= x_any_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
);
4078 #ifdef USE_X_TOOLKIT
4079 /* If we end up with the menu bar window, say it's not
4082 && f1
->output_data
.x
->menubar_widget
4083 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4085 #endif /* USE_X_TOOLKIT */
4088 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4091 x_uncatch_errors ();
4093 /* If not, is it one of our scroll bars? */
4096 struct scroll_bar
*bar
;
4098 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4102 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4108 if (f1
== 0 && insist
> 0)
4109 f1
= SELECTED_FRAME ();
4113 /* Ok, we found a frame. Store all the values.
4114 last_mouse_glyph is a rectangle used to reduce the
4115 generation of mouse events. To not miss any motion
4116 events, we must divide the frame into rectangles of the
4117 size of the smallest character that could be displayed
4118 on it, i.e. into the same rectangles that matrices on
4119 the frame are divided into. */
4121 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
4122 last_mouse_glyph_frame
= f1
;
4127 XSETINT (*x
, win_x
);
4128 XSETINT (*y
, win_y
);
4129 *timestamp
= last_mouse_movement_time
;
4139 /***********************************************************************
4141 ***********************************************************************/
4143 /* Scroll bar support. */
4145 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4147 This can be called in GC, so we have to make sure to strip off mark
4150 static struct scroll_bar
*
4151 x_window_to_scroll_bar (Display
*display
, Window window_id
)
4153 Lisp_Object tail
, frame
;
4155 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4156 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4157 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4159 FOR_EACH_FRAME (tail
, frame
)
4161 Lisp_Object bar
, condemned
;
4163 if (! FRAME_X_P (XFRAME (frame
)))
4166 /* Scan this frame's scroll bar list for a scroll bar with the
4168 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4169 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4170 /* This trick allows us to search both the ordinary and
4171 condemned scroll bar lists with one loop. */
4172 ! NILP (bar
) || (bar
= condemned
,
4175 bar
= XSCROLL_BAR (bar
)->next
)
4176 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4177 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4178 return XSCROLL_BAR (bar
);
4185 #if defined USE_LUCID
4187 /* Return the Lucid menu bar WINDOW is part of. Return null
4188 if WINDOW is not part of a menu bar. */
4191 x_window_to_menu_bar (Window window
)
4193 Lisp_Object tail
, frame
;
4195 FOR_EACH_FRAME (tail
, frame
)
4196 if (FRAME_X_P (XFRAME (frame
)))
4198 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4200 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4206 #endif /* USE_LUCID */
4209 /************************************************************************
4211 ************************************************************************/
4213 #ifdef USE_TOOLKIT_SCROLL_BARS
4215 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
4217 /* Lisp window being scrolled. Set when starting to interact with
4218 a toolkit scroll bar, reset to nil when ending the interaction. */
4220 static Lisp_Object window_being_scrolled
;
4222 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4223 that movements of 1/20 of the screen size are mapped to up/down. */
4226 /* Id of action hook installed for scroll bars. */
4228 static XtActionHookId action_hook_id
;
4230 static Boolean xaw3d_arrow_scroll
;
4232 /* Whether the drag scrolling maintains the mouse at the top of the
4233 thumb. If not, resizing the thumb needs to be done more carefully
4234 to avoid jerkiness. */
4236 static Boolean xaw3d_pick_top
;
4238 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4239 bars are used.. The hook is responsible for detecting when
4240 the user ends an interaction with the scroll bar, and generates
4241 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4244 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4245 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4248 const char *end_action
;
4251 scroll_bar_p
= XmIsScrollBar (widget
);
4252 end_action
= "Release";
4253 #else /* !USE_MOTIF i.e. use Xaw */
4254 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4255 end_action
= "EndScroll";
4256 #endif /* USE_MOTIF */
4259 && strcmp (action_name
, end_action
) == 0
4260 && WINDOWP (window_being_scrolled
))
4263 struct scroll_bar
*bar
;
4265 x_send_scroll_bar_event (window_being_scrolled
,
4266 scroll_bar_end_scroll
, 0, 0);
4267 w
= XWINDOW (window_being_scrolled
);
4268 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4270 if (bar
->dragging
!= -1)
4273 /* The thumb size is incorrect while dragging: fix it. */
4274 set_vertical_scroll_bar (w
);
4276 window_being_scrolled
= Qnil
;
4277 #if defined (USE_LUCID)
4278 bar
->last_seen_part
= scroll_bar_nowhere
;
4280 /* Xt timeouts no longer needed. */
4281 toolkit_scroll_bar_interaction
= 0;
4284 #endif /* not USE_GTK */
4286 /* A vector of windows used for communication between
4287 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4289 static struct window
**scroll_bar_windows
;
4290 static ptrdiff_t scroll_bar_windows_size
;
4293 /* Send a client message with message type Xatom_Scrollbar for a
4294 scroll action to the frame of WINDOW. PART is a value identifying
4295 the part of the scroll bar that was clicked on. PORTION is the
4296 amount to scroll of a whole of WHOLE. */
4299 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4302 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4303 struct window
*w
= XWINDOW (window
);
4304 struct frame
*f
= XFRAME (w
->frame
);
4309 /* Construct a ClientMessage event to send to the frame. */
4310 ev
->type
= ClientMessage
;
4311 ev
->message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4312 ev
->display
= FRAME_X_DISPLAY (f
);
4313 ev
->window
= FRAME_X_WINDOW (f
);
4316 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4317 not enough to store a pointer or Lisp_Object on a 64 bit system.
4318 So, store the window in scroll_bar_windows and pass the index
4319 into that array in the event. */
4320 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4321 if (scroll_bar_windows
[i
] == NULL
)
4324 if (i
== scroll_bar_windows_size
)
4326 ptrdiff_t old_nbytes
=
4327 scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4329 enum { XClientMessageEvent_MAX
= 0x7fffffff };
4330 scroll_bar_windows
=
4331 xpalloc (scroll_bar_windows
, &scroll_bar_windows_size
, 1,
4332 XClientMessageEvent_MAX
, sizeof *scroll_bar_windows
);
4333 nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4334 memset (&scroll_bar_windows
[i
], 0, nbytes
- old_nbytes
);
4337 scroll_bar_windows
[i
] = w
;
4338 ev
->data
.l
[0] = (long) i
;
4339 ev
->data
.l
[1] = (long) part
;
4340 ev
->data
.l
[2] = (long) 0;
4341 ev
->data
.l
[3] = (long) portion
;
4342 ev
->data
.l
[4] = (long) whole
;
4344 /* Make Xt timeouts work while the scroll bar is active. */
4345 #ifdef USE_X_TOOLKIT
4346 toolkit_scroll_bar_interaction
= 1;
4347 x_activate_timeout_atimer ();
4350 /* Setting the event mask to zero means that the message will
4351 be sent to the client that created the window, and if that
4352 window no longer exists, no event will be sent. */
4353 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4358 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4362 x_scroll_bar_to_input_event (const XEvent
*event
,
4363 struct input_event
*ievent
)
4365 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4369 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4370 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4372 XSETWINDOW (window
, w
);
4374 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4375 ievent
->frame_or_window
= window
;
4378 ievent
->timestamp
= CurrentTime
;
4381 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4383 ievent
->part
= ev
->data
.l
[1];
4384 ievent
->code
= ev
->data
.l
[2];
4385 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4386 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4387 ievent
->modifiers
= 0;
4393 /* Minimum and maximum values used for Motif scroll bars. */
4395 #define XM_SB_MAX 10000000
4398 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4399 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4400 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4403 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4405 struct scroll_bar
*bar
= client_data
;
4406 XmScrollBarCallbackStruct
*cs
= call_data
;
4407 int part
= -1, whole
= 0, portion
= 0;
4411 case XmCR_DECREMENT
:
4413 part
= scroll_bar_up_arrow
;
4416 case XmCR_INCREMENT
:
4418 part
= scroll_bar_down_arrow
;
4421 case XmCR_PAGE_DECREMENT
:
4423 part
= scroll_bar_above_handle
;
4426 case XmCR_PAGE_INCREMENT
:
4428 part
= scroll_bar_below_handle
;
4433 part
= scroll_bar_to_top
;
4436 case XmCR_TO_BOTTOM
:
4438 part
= scroll_bar_to_bottom
;
4445 /* Get the slider size. */
4447 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4450 whole
= XM_SB_MAX
- slider_size
;
4451 portion
= min (cs
->value
, whole
);
4452 part
= scroll_bar_handle
;
4453 bar
->dragging
= cs
->value
;
4457 case XmCR_VALUE_CHANGED
:
4463 window_being_scrolled
= bar
->window
;
4464 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4468 #elif defined USE_GTK
4470 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4471 bar widget. DATA is a pointer to the scroll_bar structure. */
4474 xg_scroll_callback (GtkRange
*range
,
4475 GtkScrollType scroll
,
4479 struct scroll_bar
*bar
= user_data
;
4481 int part
= -1, whole
= 0, portion
= 0;
4482 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4483 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4485 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4486 position
= gtk_adjustment_get_value (adj
);
4491 case GTK_SCROLL_JUMP
:
4492 /* Buttons 1 2 or 3 must be grabbed. */
4493 if (FRAME_DISPLAY_INFO (f
)->grabbed
!= 0
4494 && FRAME_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4496 part
= scroll_bar_handle
;
4497 whole
= gtk_adjustment_get_upper (adj
) -
4498 gtk_adjustment_get_page_size (adj
);
4499 portion
= min ((int)position
, whole
);
4500 bar
->dragging
= portion
;
4503 case GTK_SCROLL_STEP_BACKWARD
:
4504 part
= scroll_bar_up_arrow
;
4507 case GTK_SCROLL_STEP_FORWARD
:
4508 part
= scroll_bar_down_arrow
;
4511 case GTK_SCROLL_PAGE_BACKWARD
:
4512 part
= scroll_bar_above_handle
;
4515 case GTK_SCROLL_PAGE_FORWARD
:
4516 part
= scroll_bar_below_handle
;
4523 window_being_scrolled
= bar
->window
;
4524 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4530 /* Callback for button release. Sets dragging to -1 when dragging is done. */
4533 xg_end_scroll_callback (GtkWidget
*widget
,
4534 GdkEventButton
*event
,
4537 struct scroll_bar
*bar
= user_data
;
4539 if (WINDOWP (window_being_scrolled
))
4541 x_send_scroll_bar_event (window_being_scrolled
,
4542 scroll_bar_end_scroll
, 0, 0);
4543 window_being_scrolled
= Qnil
;
4550 #else /* not USE_GTK and not USE_MOTIF */
4552 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4553 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4554 scroll bar struct. CALL_DATA is a pointer to a float saying where
4558 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4560 struct scroll_bar
*bar
= client_data
;
4561 float *top_addr
= call_data
;
4562 float top
= *top_addr
;
4564 int whole
, portion
, height
;
4565 enum scroll_bar_part part
;
4567 /* Get the size of the thumb, a value between 0 and 1. */
4569 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4573 portion
= shown
< 1 ? top
* whole
: 0;
4575 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
4576 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4577 the bottom, so we force the scrolling whenever we see that we're
4578 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4579 we try to ensure that we always stay two pixels away from the
4581 part
= scroll_bar_down_arrow
;
4583 part
= scroll_bar_handle
;
4585 window_being_scrolled
= bar
->window
;
4586 bar
->dragging
= portion
;
4587 bar
->last_seen_part
= part
;
4588 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4592 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4593 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4594 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4595 the scroll bar. CALL_DATA is an integer specifying the action that
4596 has taken place. Its magnitude is in the range 0..height of the
4597 scroll bar. Negative values mean scroll towards buffer start.
4598 Values < height of scroll bar mean line-wise movement. */
4601 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4603 struct scroll_bar
*bar
= client_data
;
4604 /* The position really is stored cast to a pointer. */
4605 int position
= (intptr_t) call_data
;
4607 enum scroll_bar_part part
;
4609 /* Get the height of the scroll bar. */
4611 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4614 if (eabs (position
) >= height
)
4615 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4617 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4618 it maps line-movement to call_data = max(5, height/20). */
4619 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4620 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4622 part
= scroll_bar_move_ratio
;
4624 window_being_scrolled
= bar
->window
;
4626 bar
->last_seen_part
= part
;
4627 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4630 #endif /* not USE_GTK and not USE_MOTIF */
4632 #define SCROLL_BAR_NAME "verticalScrollBar"
4634 /* Create the widget for scroll bar BAR on frame F. Record the widget
4635 and X window of the scroll bar in BAR. */
4639 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4641 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4644 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4645 G_CALLBACK (xg_end_scroll_callback
),
4650 #else /* not USE_GTK */
4653 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4659 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4660 unsigned long pixel
;
4665 /* Set resources. Create the widget. */
4666 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4667 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4668 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4669 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4670 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4671 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4672 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4674 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4677 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4681 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4684 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4688 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4689 (char *) scroll_bar_name
, av
, ac
);
4691 /* Add one callback for everything that can happen. */
4692 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4694 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4696 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4698 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4700 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4702 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4704 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4707 /* Realize the widget. Only after that is the X window created. */
4708 XtRealizeWidget (widget
);
4710 /* Set the cursor to an arrow. I didn't find a resource to do that.
4711 And I'm wondering why it hasn't an arrow cursor by default. */
4712 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4713 f
->output_data
.x
->nontext_cursor
);
4715 #else /* !USE_MOTIF i.e. use Xaw */
4717 /* Set resources. Create the widget. The background of the
4718 Xaw3d scroll bar widget is a little bit light for my taste.
4719 We don't alter it here to let users change it according
4720 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4721 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4722 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4723 /* For smoother scrolling with Xaw3d -sm */
4724 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4726 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4729 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4733 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4736 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4740 /* Top/bottom shadow colors. */
4742 /* Allocate them, if necessary. */
4743 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4745 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4748 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4749 FRAME_X_COLORMAP (f
),
4750 &pixel
, 1.2, 0x8000))
4752 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4755 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4757 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4760 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4761 FRAME_X_COLORMAP (f
),
4762 &pixel
, 0.6, 0x4000))
4764 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4768 #ifdef XtNbeNiceToColormap
4769 /* Tell the toolkit about them. */
4770 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4771 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4772 /* We tried to allocate a color for the top/bottom shadow, and
4773 failed, so tell Xaw3d to use dithering instead. */
4774 /* But only if we have a small colormap. Xaw3d can allocate nice
4777 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4778 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4782 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4783 be more consistent with other emacs 3d colors, and since Xaw3d is
4784 not good at dealing with allocation failure. */
4786 /* This tells Xaw3d to use real colors instead of dithering for
4788 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4791 /* Specify the colors. */
4792 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4795 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4798 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4801 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4807 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4808 f
->output_data
.x
->edit_widget
, av
, ac
);
4811 char const *initial
= "";
4812 char const *val
= initial
;
4813 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4814 #ifdef XtNarrowScrollbars
4815 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4817 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4818 if (xaw3d_arrow_scroll
|| val
== initial
)
4819 { /* ARROW_SCROLL */
4820 xaw3d_arrow_scroll
= True
;
4821 /* Isn't that just a personal preference ? --Stef */
4822 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4826 /* Define callbacks. */
4827 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4828 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4831 /* Realize the widget. Only after that is the X window created. */
4832 XtRealizeWidget (widget
);
4834 #endif /* !USE_MOTIF */
4836 /* Install an action hook that lets us detect when the user
4837 finishes interacting with a scroll bar. */
4838 if (action_hook_id
== 0)
4839 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4841 /* Remember X window and widget in the scroll bar vector. */
4842 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4843 xwindow
= XtWindow (widget
);
4844 bar
->x_window
= xwindow
;
4848 #endif /* not USE_GTK */
4851 /* Set the thumb size and position of scroll bar BAR. We are currently
4852 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4856 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4858 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4861 #else /* not USE_GTK */
4863 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4866 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4867 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4874 if (scroll_bar_adjust_thumb_portion_p
)
4876 /* We use an estimate of 30 chars per line rather than the real
4877 `portion' value. This has the disadvantage that the thumb size
4878 is not very representative, but it makes our life a lot easier.
4879 Otherwise, we have to constantly adjust the thumb size, which
4880 we can't always do quickly enough: while dragging, the size of
4881 the thumb might prevent the user from dragging the thumb all the
4882 way to the end. but Motif and some versions of Xaw3d don't allow
4883 updating the thumb size while dragging. Also, even if we can update
4884 its size, the update will often happen too late.
4885 If you don't believe it, check out revision 1.650 of xterm.c to see
4886 what hoops we were going through and the still poor behavior we got. */
4887 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4888 /* When the thumb is at the bottom, position == whole.
4889 So we need to increase `whole' to make space for the thumb. */
4897 top
= (float) position
/ whole
;
4898 shown
= (float) portion
/ whole
;
4901 if (bar
->dragging
== -1)
4905 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4906 is the scroll bar's maximum and MIN is the scroll bar's minimum
4908 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
4910 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4911 value
= top
* XM_SB_MAX
;
4912 value
= min (value
, XM_SB_MAX
- size
);
4914 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4916 #else /* !USE_MOTIF i.e. use Xaw */
4922 top
= (float) position
/ whole
;
4923 shown
= (float) portion
/ whole
;
4927 float old_top
, old_shown
;
4929 XtVaGetValues (widget
,
4930 XtNtopOfThumb
, &old_top
,
4931 XtNshown
, &old_shown
,
4935 /* Massage the top+shown values. */
4936 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
4937 top
= max (0, min (1, top
));
4940 #if ! defined (HAVE_XAW3D)
4941 /* With Xaw, 'top' values too closer to 1.0 may
4942 cause the thumb to disappear. Fix that. */
4943 top
= min (top
, 0.99f
);
4945 /* Keep two pixels available for moving the thumb down. */
4946 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
4947 #if ! defined (HAVE_XAW3D)
4948 /* Likewise with too small 'shown'. */
4949 shown
= max (shown
, 0.01f
);
4952 /* If the call to XawScrollbarSetThumb below doesn't seem to
4953 work, check that 'NARROWPROTO' is defined in src/config.h.
4954 If this is not so, most likely you need to fix configure. */
4955 if (top
!= old_top
|| shown
!= old_shown
)
4957 if (bar
->dragging
== -1)
4958 XawScrollbarSetThumb (widget
, top
, shown
);
4961 /* Try to make the scrolling a tad smoother. */
4962 if (!xaw3d_pick_top
)
4963 shown
= min (shown
, old_shown
);
4965 XawScrollbarSetThumb (widget
, top
, shown
);
4969 #endif /* !USE_MOTIF */
4973 #endif /* not USE_GTK */
4975 #endif /* USE_TOOLKIT_SCROLL_BARS */
4979 /************************************************************************
4980 Scroll bars, general
4981 ************************************************************************/
4983 /* Create a scroll bar and return the scroll bar vector for it. W is
4984 the Emacs window on which to create the scroll bar. TOP, LEFT,
4985 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4988 static struct scroll_bar
*
4989 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
4991 struct frame
*f
= XFRAME (w
->frame
);
4992 struct scroll_bar
*bar
4993 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4998 #ifdef USE_TOOLKIT_SCROLL_BARS
4999 x_create_toolkit_scroll_bar (f
, bar
);
5000 #else /* not USE_TOOLKIT_SCROLL_BARS */
5002 XSetWindowAttributes a
;
5006 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5007 if (a
.background_pixel
== -1)
5008 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5010 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
5011 | ButtonMotionMask
| PointerMotionHintMask
5013 a
.cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
5015 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
5017 /* Clear the area of W that will serve as a scroll bar. This is
5018 for the case that a window has been split horizontally. In
5019 this case, no clear_frame is generated to reduce flickering. */
5020 if (width
> 0 && height
> 0)
5021 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5022 left
, top
, width
, window_box_height (w
));
5024 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5025 /* Position and size of scroll bar. */
5026 left
, top
, width
, height
,
5027 /* Border width, depth, class, and visual. */
5034 bar
->x_window
= window
;
5036 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5038 XSETWINDOW (bar
->window
, w
);
5042 bar
->height
= height
;
5046 bar
->fringe_extended_p
= 0;
5047 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
5048 bar
->last_seen_part
= scroll_bar_nowhere
;
5051 /* Add bar to its frame's list of scroll bars. */
5052 bar
->next
= FRAME_SCROLL_BARS (f
);
5054 XSETVECTOR (barobj
, bar
);
5055 fset_scroll_bars (f
, barobj
);
5056 if (!NILP (bar
->next
))
5057 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5059 /* Map the window/widget. */
5060 #ifdef USE_TOOLKIT_SCROLL_BARS
5063 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
5064 left
,width
, max (height
, 1));
5065 #else /* not USE_GTK */
5066 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5067 XtConfigureWidget (scroll_bar
, left
, top
, width
, max (height
, 1), 0);
5068 XtMapWidget (scroll_bar
);
5069 #endif /* not USE_GTK */
5071 #else /* not USE_TOOLKIT_SCROLL_BARS */
5072 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5073 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5080 #ifndef USE_TOOLKIT_SCROLL_BARS
5082 /* Draw BAR's handle in the proper position.
5084 If the handle is already drawn from START to END, don't bother
5085 redrawing it, unless REBUILD is non-zero; in that case, always
5086 redraw it. (REBUILD is handy for drawing the handle after expose
5089 Normally, we want to constrain the start and end of the handle to
5090 fit inside its rectangle, but if the user is dragging the scroll
5091 bar handle, we want to let them drag it down all the way, so that
5092 the bar's top is as far down as it goes; otherwise, there's no way
5093 to move to the very end of the buffer. */
5096 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
5098 bool dragging
= bar
->dragging
!= -1;
5099 Window w
= bar
->x_window
;
5100 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5101 GC gc
= f
->output_data
.x
->normal_gc
;
5103 /* If the display is already accurate, do nothing. */
5105 && start
== bar
->start
5112 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5113 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5114 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5116 /* Make sure the values are reasonable, and try to preserve
5117 the distance between start and end. */
5119 int length
= end
- start
;
5123 else if (start
> top_range
)
5125 end
= start
+ length
;
5129 else if (end
> top_range
&& ! dragging
)
5133 /* Store the adjusted setting in the scroll bar. */
5137 /* Clip the end position, just for display. */
5138 if (end
> top_range
)
5141 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5142 below top positions, to make sure the handle is always at least
5143 that many pixels tall. */
5144 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5146 /* Draw the empty space above the handle. Note that we can't clear
5147 zero-height areas; that means "clear to end of window." */
5149 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5150 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5151 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5152 inside_width
, start
);
5154 /* Change to proper foreground color if one is specified. */
5155 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5156 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5157 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5159 /* Draw the handle itself. */
5160 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5161 /* x, y, width, height */
5162 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5163 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5164 inside_width
, end
- start
);
5166 /* Restore the foreground color of the GC if we changed it above. */
5167 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5168 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5169 FRAME_FOREGROUND_PIXEL (f
));
5171 /* Draw the empty space below the handle. Note that we can't
5172 clear zero-height areas; that means "clear to end of window." */
5173 if (end
< inside_height
)
5174 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5175 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5176 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5177 inside_width
, inside_height
- end
);
5183 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5185 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5189 x_scroll_bar_remove (struct scroll_bar
*bar
)
5191 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5194 #ifdef USE_TOOLKIT_SCROLL_BARS
5196 xg_remove_scroll_bar (f
, bar
->x_window
);
5197 #else /* not USE_GTK */
5198 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5199 #endif /* not USE_GTK */
5201 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5204 /* Dissociate this scroll bar from its window. */
5205 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5211 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5212 that we are displaying PORTION characters out of a total of WHOLE
5213 characters, starting at POSITION. If WINDOW has no scroll bar,
5217 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5219 struct frame
*f
= XFRAME (w
->frame
);
5221 struct scroll_bar
*bar
;
5222 int top
, height
, left
, sb_left
, width
, sb_width
;
5223 int window_y
, window_height
;
5224 #ifdef USE_TOOLKIT_SCROLL_BARS
5225 bool fringe_extended_p
;
5228 /* Get window dimensions. */
5229 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
5231 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5232 height
= window_height
;
5234 /* Compute the left edge of the scroll bar area. */
5235 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5237 /* Compute the width of the scroll bar which might be less than
5238 the width of the area reserved for the scroll bar. */
5239 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5240 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5244 /* Compute the left edge of the scroll bar. */
5245 #ifdef USE_TOOLKIT_SCROLL_BARS
5246 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5247 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5249 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5251 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5252 sb_left
= left
+ width
- sb_width
;
5257 #ifdef USE_TOOLKIT_SCROLL_BARS
5258 fringe_extended_p
= WINDOW_FRINGE_EXTENDED_P (w
);
5261 /* Does the scroll bar exist yet? */
5262 if (NILP (w
->vertical_scroll_bar
))
5264 if (width
> 0 && height
> 0)
5267 #ifdef USE_TOOLKIT_SCROLL_BARS
5268 if (fringe_extended_p
)
5269 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5270 sb_left
, top
, sb_width
, height
);
5273 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5274 left
, top
, width
, height
);
5278 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5282 /* It may just need to be moved and resized. */
5283 unsigned int mask
= 0;
5285 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5289 if (sb_left
!= bar
->left
)
5291 if (top
!= bar
->top
)
5293 if (sb_width
!= bar
->width
)
5295 if (height
!= bar
->height
)
5298 #ifdef USE_TOOLKIT_SCROLL_BARS
5300 /* Move/size the scroll bar widget. */
5301 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5303 /* Since toolkit scroll bars are smaller than the space reserved
5304 for them on the frame, we have to clear "under" them. */
5305 if (width
> 0 && height
> 0)
5307 if (fringe_extended_p
)
5308 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5309 sb_left
, top
, sb_width
, height
);
5311 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5312 left
, top
, width
, height
);
5315 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
5316 sb_left
, sb_width
, max (height
, 1));
5317 #else /* not USE_GTK */
5318 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5319 sb_left
, top
, sb_width
, max (height
, 1), 0);
5320 #endif /* not USE_GTK */
5322 #else /* not USE_TOOLKIT_SCROLL_BARS */
5324 /* Clear areas not covered by the scroll bar because it's not as
5325 wide as the area reserved for it. This makes sure a
5326 previous mode line display is cleared after C-x 2 C-x 1, for
5329 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5330 int rest
= area_width
- sb_width
;
5331 if (rest
> 0 && height
> 0)
5333 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5334 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5335 left
+ area_width
- rest
, top
, rest
, height
);
5337 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5338 left
, top
, rest
, height
);
5342 /* Move/size the scroll bar window. */
5349 wc
.width
= sb_width
;
5351 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5355 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5357 /* Remember new settings. */
5358 bar
->left
= sb_left
;
5360 bar
->width
= sb_width
;
5361 bar
->height
= height
;
5366 #ifdef USE_TOOLKIT_SCROLL_BARS
5367 bar
->fringe_extended_p
= fringe_extended_p
;
5369 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5370 #else /* not USE_TOOLKIT_SCROLL_BARS */
5371 /* Set the scroll bar's current state, unless we're currently being
5373 if (bar
->dragging
== -1)
5375 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5378 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5381 int start
= ((double) position
* top_range
) / whole
;
5382 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5383 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5386 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5388 XSETVECTOR (barobj
, bar
);
5389 wset_vertical_scroll_bar (w
, barobj
);
5393 /* The following three hooks are used when we're doing a thorough
5394 redisplay of the frame. We don't explicitly know which scroll bars
5395 are going to be deleted, because keeping track of when windows go
5396 away is a real pain - "Can you say set-window-configuration, boys
5397 and girls?" Instead, we just assert at the beginning of redisplay
5398 that *all* scroll bars are to be removed, and then save a scroll bar
5399 from the fiery pit when we actually redisplay its window. */
5401 /* Arrange for all scroll bars on FRAME to be removed at the next call
5402 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5403 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5406 XTcondemn_scroll_bars (struct frame
*frame
)
5408 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5409 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5412 bar
= FRAME_SCROLL_BARS (frame
);
5413 fset_scroll_bars (frame
, XSCROLL_BAR (bar
)->next
);
5414 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5415 XSCROLL_BAR (bar
)->prev
= Qnil
;
5416 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5417 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5418 fset_condemned_scroll_bars (frame
, bar
);
5423 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5424 Note that WINDOW isn't necessarily condemned at all. */
5427 XTredeem_scroll_bar (struct window
*window
)
5429 struct scroll_bar
*bar
;
5433 /* We can't redeem this window's scroll bar if it doesn't have one. */
5434 if (NILP (window
->vertical_scroll_bar
))
5437 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5439 /* Unlink it from the condemned list. */
5440 f
= XFRAME (WINDOW_FRAME (window
));
5441 if (NILP (bar
->prev
))
5443 /* If the prev pointer is nil, it must be the first in one of
5445 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5446 /* It's not condemned. Everything's fine. */
5448 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5449 window
->vertical_scroll_bar
))
5450 fset_condemned_scroll_bars (f
, bar
->next
);
5452 /* If its prev pointer is nil, it must be at the front of
5453 one or the other! */
5457 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5459 if (! NILP (bar
->next
))
5460 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5462 bar
->next
= FRAME_SCROLL_BARS (f
);
5464 XSETVECTOR (barobj
, bar
);
5465 fset_scroll_bars (f
, barobj
);
5466 if (! NILP (bar
->next
))
5467 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5470 /* Remove all scroll bars on FRAME that haven't been saved since the
5471 last call to `*condemn_scroll_bars_hook'. */
5474 XTjudge_scroll_bars (struct frame
*f
)
5476 Lisp_Object bar
, next
;
5478 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5480 /* Clear out the condemned list now so we won't try to process any
5481 more events on the hapless scroll bars. */
5482 fset_condemned_scroll_bars (f
, Qnil
);
5484 for (; ! NILP (bar
); bar
= next
)
5486 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5488 x_scroll_bar_remove (b
);
5491 b
->next
= b
->prev
= Qnil
;
5494 /* Now there should be no references to the condemned scroll bars,
5495 and they should get garbage-collected. */
5499 #ifndef USE_TOOLKIT_SCROLL_BARS
5500 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5501 is a no-op when using toolkit scroll bars.
5503 This may be called from a signal handler, so we have to ignore GC
5507 x_scroll_bar_expose (struct scroll_bar
*bar
, const XEvent
*event
)
5509 Window w
= bar
->x_window
;
5510 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5511 GC gc
= f
->output_data
.x
->normal_gc
;
5515 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5517 /* Switch to scroll bar foreground color. */
5518 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5519 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5520 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5522 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5523 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5524 /* x, y, width, height */
5525 0, 0, bar
->width
- 1, bar
->height
- 1);
5527 /* Restore the foreground color of the GC if we changed it above. */
5528 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5529 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5530 FRAME_FOREGROUND_PIXEL (f
));
5535 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5537 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5538 is set to something other than NO_EVENT, it is enqueued.
5540 This may be called from a signal handler, so we have to ignore GC
5545 x_scroll_bar_handle_click (struct scroll_bar
*bar
,
5546 const XEvent
*event
,
5547 struct input_event
*emacs_event
)
5549 if (! WINDOWP (bar
->window
))
5552 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5553 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5554 emacs_event
->modifiers
5555 = (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO
5556 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5557 event
->xbutton
.state
)
5558 | (event
->type
== ButtonRelease
5561 emacs_event
->frame_or_window
= bar
->window
;
5562 emacs_event
->arg
= Qnil
;
5563 emacs_event
->timestamp
= event
->xbutton
.time
;
5566 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5567 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5570 if (y
> top_range
) y
= top_range
;
5573 emacs_event
->part
= scroll_bar_above_handle
;
5574 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5575 emacs_event
->part
= scroll_bar_handle
;
5577 emacs_event
->part
= scroll_bar_below_handle
;
5579 #ifndef USE_TOOLKIT_SCROLL_BARS
5580 /* If the user has released the handle, set it to its final position. */
5581 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
5583 int new_start
= y
- bar
->dragging
;
5584 int new_end
= new_start
+ bar
->end
- bar
->start
;
5586 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5591 XSETINT (emacs_event
->x
, y
);
5592 XSETINT (emacs_event
->y
, top_range
);
5596 #ifndef USE_TOOLKIT_SCROLL_BARS
5598 /* Handle some mouse motion while someone is dragging the scroll bar.
5600 This may be called from a signal handler, so we have to ignore GC
5604 x_scroll_bar_note_movement (struct scroll_bar
*bar
,
5605 const XMotionEvent
*event
)
5607 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5609 last_mouse_movement_time
= event
->time
;
5612 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5614 /* If we're dragging the bar, display it. */
5615 if (bar
->dragging
!= -1)
5617 /* Where should the handle be now? */
5618 int new_start
= event
->y
- bar
->dragging
;
5620 if (new_start
!= bar
->start
)
5622 int new_end
= new_start
+ bar
->end
- bar
->start
;
5624 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5629 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5631 /* Return information to the user about the current position of the mouse
5632 on the scroll bar. */
5635 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
5636 enum scroll_bar_part
*part
, Lisp_Object
*x
,
5637 Lisp_Object
*y
, Time
*timestamp
)
5639 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5640 Window w
= bar
->x_window
;
5641 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5643 Window dummy_window
;
5645 unsigned int dummy_mask
;
5649 /* Get the mouse's position relative to the scroll bar window, and
5651 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5653 /* Root, child, root x and root y. */
5654 &dummy_window
, &dummy_window
,
5655 &dummy_coord
, &dummy_coord
,
5657 /* Position relative to scroll bar. */
5660 /* Mouse buttons and modifier keys. */
5666 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5668 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5670 if (bar
->dragging
!= -1)
5671 win_y
-= bar
->dragging
;
5675 if (win_y
> top_range
)
5679 *bar_window
= bar
->window
;
5681 if (bar
->dragging
!= -1)
5682 *part
= scroll_bar_handle
;
5683 else if (win_y
< bar
->start
)
5684 *part
= scroll_bar_above_handle
;
5685 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5686 *part
= scroll_bar_handle
;
5688 *part
= scroll_bar_below_handle
;
5690 XSETINT (*x
, win_y
);
5691 XSETINT (*y
, top_range
);
5694 last_mouse_scroll_bar
= Qnil
;
5697 *timestamp
= last_mouse_movement_time
;
5703 /* The screen has been cleared so we may have changed foreground or
5704 background colors, and the scroll bars may need to be redrawn.
5705 Clear out the scroll bars, and ask for expose events, so we can
5709 x_scroll_bar_clear (struct frame
*f
)
5711 #ifndef USE_TOOLKIT_SCROLL_BARS
5714 /* We can have scroll bars even if this is 0,
5715 if we just turned off scroll bar mode.
5716 But in that case we should not clear them. */
5717 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5718 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5719 bar
= XSCROLL_BAR (bar
)->next
)
5720 XClearArea (FRAME_X_DISPLAY (f
),
5721 XSCROLL_BAR (bar
)->x_window
,
5723 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5726 #ifdef ENABLE_CHECKING
5728 /* Record the last 100 characters stored
5729 to help debug the loss-of-chars-during-GC problem. */
5731 static int temp_index
;
5732 static short temp_buffer
[100];
5734 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5735 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5737 temp_buffer[temp_index++] = (keysym)
5739 #else /* not ENABLE_CHECKING */
5741 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
5743 #endif /* ENABLE_CHECKING */
5745 /* Set this to nonzero to fake an "X I/O error"
5746 on a particular display. */
5748 static struct x_display_info
*XTread_socket_fake_io_error
;
5750 /* When we find no input here, we occasionally do a no-op command
5751 to verify that the X server is still running and we can still talk with it.
5752 We try all the open displays, one by one.
5753 This variable is used for cycling thru the displays. */
5755 static struct x_display_info
*next_noop_dpyinfo
;
5764 /* Filter events for the current X input method.
5765 DPYINFO is the display this event is for.
5766 EVENT is the X event to filter.
5768 Returns non-zero if the event was filtered, caller shall not process
5770 Returns zero if event is wasn't filtered. */
5774 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5776 /* XFilterEvent returns non-zero if the input method has
5777 consumed the event. We pass the frame's X window to
5778 XFilterEvent because that's the one for which the IC
5781 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5782 event
->xclient
.window
);
5784 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5789 static int current_count
;
5790 static int current_finish
;
5791 static struct input_event
*current_hold_quit
;
5793 /* This is the filter function invoked by the GTK event loop.
5794 It is invoked before the XEvent is translated to a GdkEvent,
5795 so we have a chance to act on the event before GTK. */
5796 static GdkFilterReturn
5797 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5799 XEvent
*xev
= (XEvent
*) gxev
;
5802 if (current_count
>= 0)
5804 struct x_display_info
*dpyinfo
;
5806 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5809 /* Filter events for the current X input method.
5810 GTK calls XFilterEvent but not for key press and release,
5811 so we do it here. */
5812 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5814 && x_filter_event (dpyinfo
, xev
))
5817 return GDK_FILTER_REMOVE
;
5822 current_finish
= X_EVENT_NORMAL
;
5825 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5829 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5833 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5834 return GDK_FILTER_REMOVE
;
5836 return GDK_FILTER_CONTINUE
;
5838 #endif /* USE_GTK */
5841 static void xembed_send_message (struct frame
*f
, Time
,
5842 enum xembed_message
,
5843 long detail
, long data1
, long data2
);
5845 /* Handles the XEvent EVENT on display DPYINFO.
5847 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5848 *FINISH is zero if caller should continue reading events.
5849 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5850 *EVENT is unchanged unless we're processing KeyPress event.
5852 We return the number of characters stored into the buffer. */
5855 handle_one_xevent (struct x_display_info
*dpyinfo
,
5856 const XEvent
*event
,
5857 int *finish
, struct input_event
*hold_quit
)
5860 struct input_event ie
;
5861 struct selection_input_event sie
;
5865 ptrdiff_t nbytes
= 0;
5866 struct frame
*any
, *f
= NULL
;
5867 struct coding_system coding
;
5868 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
5869 /* This holds the state XLookupString needs to implement dead keys
5870 and other tricks known as "compose processing". _X Window System_
5871 says that a portable program can't use this, but Stephen Gildea assures
5872 me that letting the compiler initialize it to zeros will work okay. */
5873 static XComposeStatus compose_status
;
5877 *finish
= X_EVENT_NORMAL
;
5879 EVENT_INIT (inev
.ie
);
5880 inev
.ie
.kind
= NO_EVENT
;
5883 any
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
5885 if (any
&& any
->wait_event_type
== event
->type
)
5886 any
->wait_event_type
= 0; /* Indicates we got it. */
5888 switch (event
->type
)
5892 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_protocols
5893 && event
->xclient
.format
== 32)
5895 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_take_focus
)
5897 /* Use the value returned by x_any_window_to_frame
5898 because this could be the shell widget window
5899 if the frame has no title bar. */
5902 /* Not quite sure this is needed -pd */
5903 if (f
&& FRAME_XIC (f
))
5904 XSetICFocus (FRAME_XIC (f
));
5906 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5907 instructs the WM to set the input focus automatically for
5908 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5909 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5910 it has set the focus. So, XSetInputFocus below is not
5913 The call to XSetInputFocus below has also caused trouble. In
5914 cases where the XSetInputFocus done by the WM and the one
5915 below are temporally close (on a fast machine), the call
5916 below can generate additional FocusIn events which confuse
5919 /* Since we set WM_TAKE_FOCUS, we must call
5920 XSetInputFocus explicitly. But not if f is null,
5921 since that might be an event for a deleted frame. */
5924 Display
*d
= event
->xclient
.display
;
5925 /* Catch and ignore errors, in case window has been
5926 iconified by a window manager such as GWM. */
5928 XSetInputFocus (d
, event
->xclient
.window
,
5929 /* The ICCCM says this is
5930 the only valid choice. */
5932 event
->xclient
.data
.l
[1]);
5933 /* This is needed to detect the error
5934 if there is an error. */
5936 x_uncatch_errors ();
5938 /* Not certain about handling scroll bars here */
5943 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_save_yourself
)
5945 /* Save state modify the WM_COMMAND property to
5946 something which can reinstate us. This notifies
5947 the session manager, who's looking for such a
5948 PropertyNotify. Can restart processing when
5949 a keyboard or mouse event arrives. */
5950 /* If we have a session manager, don't set this.
5951 KDE will then start two Emacsen, one for the
5952 session manager and one for this. */
5954 if (! x_session_have_connection ())
5957 f
= x_top_window_to_frame (dpyinfo
,
5958 event
->xclient
.window
);
5959 /* This is just so we only give real data once
5960 for a single Emacs process. */
5961 if (f
== SELECTED_FRAME ())
5962 XSetCommand (FRAME_X_DISPLAY (f
),
5963 event
->xclient
.window
,
5964 initial_argv
, initial_argc
);
5966 XSetCommand (FRAME_X_DISPLAY (f
),
5967 event
->xclient
.window
,
5973 if (event
->xclient
.data
.l
[0] == dpyinfo
->Xatom_wm_delete_window
)
5977 goto OTHER
; /* May be a dialog that is to be removed */
5979 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5980 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5987 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_configure_denied
)
5990 if (event
->xclient
.message_type
== dpyinfo
->Xatom_wm_window_moved
)
5993 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
5995 new_x
= event
->xclient
.data
.s
[0];
5996 new_y
= event
->xclient
.data
.s
[1];
6000 f
->left_pos
= new_x
;
6007 if (event
->xclient
.message_type
== dpyinfo
->Xatom_editres
)
6011 _XEditResCheckMessages (f
->output_data
.x
->widget
,
6012 NULL
, (XEvent
*) event
, NULL
);
6015 #endif /* HACK_EDITRES */
6017 if (event
->xclient
.message_type
== dpyinfo
->Xatom_DONE
6018 || event
->xclient
.message_type
== dpyinfo
->Xatom_PAGE
)
6020 /* Ghostview job completed. Kill it. We could
6021 reply with "Next" if we received "Page", but we
6022 currently never do because we are interested in
6023 images, only, which should have 1 page. */
6024 Pixmap pixmap
= (Pixmap
) event
->xclient
.data
.l
[1];
6025 f
= x_window_to_frame (dpyinfo
, event
->xclient
.window
);
6028 x_kill_gs_process (pixmap
, f
);
6029 expose_frame (f
, 0, 0, 0, 0);
6033 #ifdef USE_TOOLKIT_SCROLL_BARS
6034 /* Scroll bar callbacks send a ClientMessage from which
6035 we construct an input_event. */
6036 if (event
->xclient
.message_type
== dpyinfo
->Xatom_Scrollbar
)
6038 x_scroll_bar_to_input_event (event
, &inev
.ie
);
6039 *finish
= X_EVENT_GOTO_OUT
;
6042 #endif /* USE_TOOLKIT_SCROLL_BARS */
6044 /* XEmbed messages from the embedder (if any). */
6045 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
6047 enum xembed_message msg
= event
->xclient
.data
.l
[1];
6048 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6049 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6051 *finish
= X_EVENT_GOTO_OUT
;
6055 xft_settings_event (dpyinfo
, event
);
6060 if (x_handle_dnd_message (f
, &event
->xclient
, dpyinfo
, &inev
.ie
))
6061 *finish
= X_EVENT_DROP
;
6065 case SelectionNotify
:
6066 dpyinfo
->last_user_time
= event
->xselection
.time
;
6067 #ifdef USE_X_TOOLKIT
6068 if (! x_window_to_frame (dpyinfo
, event
->xselection
.requestor
))
6070 #endif /* not USE_X_TOOLKIT */
6071 x_handle_selection_notify (&event
->xselection
);
6074 case SelectionClear
: /* Someone has grabbed ownership. */
6075 dpyinfo
->last_user_time
= event
->xselectionclear
.time
;
6076 #ifdef USE_X_TOOLKIT
6077 if (! x_window_to_frame (dpyinfo
, event
->xselectionclear
.window
))
6079 #endif /* USE_X_TOOLKIT */
6081 const XSelectionClearEvent
*eventp
= &event
->xselectionclear
;
6083 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6084 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6085 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6086 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6090 case SelectionRequest
: /* Someone wants our selection. */
6091 dpyinfo
->last_user_time
= event
->xselectionrequest
.time
;
6092 #ifdef USE_X_TOOLKIT
6093 if (!x_window_to_frame (dpyinfo
, event
->xselectionrequest
.owner
))
6095 #endif /* USE_X_TOOLKIT */
6097 const XSelectionRequestEvent
*eventp
= &event
->xselectionrequest
;
6099 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6100 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6101 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6102 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6103 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6104 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6105 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6109 case PropertyNotify
:
6110 dpyinfo
->last_user_time
= event
->xproperty
.time
;
6111 f
= x_top_window_to_frame (dpyinfo
, event
->xproperty
.window
);
6112 if (f
&& event
->xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6113 if (x_handle_net_wm_state (f
, &event
->xproperty
)
6114 && FRAME_ICONIFIED_P (f
)
6115 && f
->output_data
.x
->net_wm_state_hidden_seen
)
6117 /* Gnome shell does not iconify us when C-z is pressed.
6118 It hides the frame. So if our state says we aren't
6119 hidden anymore, treat it as deiconified. */
6120 SET_FRAME_VISIBLE (f
, 1);
6121 SET_FRAME_ICONIFIED (f
, 0);
6122 f
->output_data
.x
->has_been_visible
= 1;
6123 f
->output_data
.x
->net_wm_state_hidden_seen
= 0;
6124 inev
.ie
.kind
= DEICONIFY_EVENT
;
6125 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6128 x_handle_property_notify (&event
->xproperty
);
6129 xft_settings_event (dpyinfo
, event
);
6132 case ReparentNotify
:
6133 f
= x_top_window_to_frame (dpyinfo
, event
->xreparent
.window
);
6137 f
->output_data
.x
->parent_desc
= event
->xreparent
.parent
;
6138 x_real_positions (f
, &x
, &y
);
6142 /* Perhaps reparented due to a WM restart. Reset this. */
6143 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6144 FRAME_DISPLAY_INFO (f
)->net_supported_window
= 0;
6146 x_set_frame_alpha (f
);
6151 f
= x_window_to_frame (dpyinfo
, event
->xexpose
.window
);
6154 #if ! GTK_CHECK_VERSION (2, 7, 0)
6155 /* This seems to be needed for GTK 2.6. */
6156 x_clear_area (event
->xexpose
.display
,
6157 event
->xexpose
.window
,
6158 event
->xexpose
.x
, event
->xexpose
.y
,
6159 event
->xexpose
.width
, event
->xexpose
.height
);
6161 if (!FRAME_VISIBLE_P (f
))
6163 SET_FRAME_VISIBLE (f
, 1);
6164 SET_FRAME_ICONIFIED (f
, 0);
6165 f
->output_data
.x
->has_been_visible
= 1;
6166 SET_FRAME_GARBAGED (f
);
6169 expose_frame (f
, event
->xexpose
.x
, event
->xexpose
.y
,
6170 event
->xexpose
.width
, event
->xexpose
.height
);
6174 #ifndef USE_TOOLKIT_SCROLL_BARS
6175 struct scroll_bar
*bar
;
6177 #if defined USE_LUCID
6178 /* Submenus of the Lucid menu bar aren't widgets
6179 themselves, so there's no way to dispatch events
6180 to them. Recognize this case separately. */
6182 Widget widget
= x_window_to_menu_bar (event
->xexpose
.window
);
6184 xlwmenu_redisplay (widget
);
6186 #endif /* USE_LUCID */
6188 #ifdef USE_TOOLKIT_SCROLL_BARS
6189 /* Dispatch event to the widget. */
6191 #else /* not USE_TOOLKIT_SCROLL_BARS */
6192 bar
= x_window_to_scroll_bar (event
->xexpose
.display
,
6193 event
->xexpose
.window
);
6196 x_scroll_bar_expose (bar
, event
);
6197 #ifdef USE_X_TOOLKIT
6200 #endif /* USE_X_TOOLKIT */
6201 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6205 case GraphicsExpose
: /* This occurs when an XCopyArea's
6206 source area was obscured or not
6208 f
= x_window_to_frame (dpyinfo
, event
->xgraphicsexpose
.drawable
);
6210 expose_frame (f
, event
->xgraphicsexpose
.x
,
6211 event
->xgraphicsexpose
.y
,
6212 event
->xgraphicsexpose
.width
,
6213 event
->xgraphicsexpose
.height
);
6214 #ifdef USE_X_TOOLKIT
6217 #endif /* USE_X_TOOLKIT */
6220 case NoExpose
: /* This occurs when an XCopyArea's
6221 source area was completely
6226 /* Redo the mouse-highlight after the tooltip has gone. */
6227 if (event
->xunmap
.window
== tip_window
)
6230 redo_mouse_highlight ();
6233 f
= x_top_window_to_frame (dpyinfo
, event
->xunmap
.window
);
6234 if (f
) /* F may no longer exist if
6235 the frame was deleted. */
6237 bool visible
= FRAME_VISIBLE_P (f
);
6238 /* While a frame is unmapped, display generation is
6239 disabled; you don't want to spend time updating a
6240 display that won't ever be seen. */
6241 SET_FRAME_VISIBLE (f
, 0);
6242 /* We can't distinguish, from the event, whether the window
6243 has become iconified or invisible. So assume, if it
6244 was previously visible, than now it is iconified.
6245 But x_make_frame_invisible clears both
6246 the visible flag and the iconified flag;
6247 and that way, we know the window is not iconified now. */
6248 if (visible
|| FRAME_ICONIFIED_P (f
))
6250 SET_FRAME_ICONIFIED (f
, 1);
6251 inev
.ie
.kind
= ICONIFY_EVENT
;
6252 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6258 if (event
->xmap
.window
== tip_window
)
6259 /* The tooltip has been drawn already. Avoid
6260 the SET_FRAME_GARBAGED below. */
6263 /* We use x_top_window_to_frame because map events can
6264 come for sub-windows and they don't mean that the
6265 frame is visible. */
6266 f
= x_top_window_to_frame (dpyinfo
, event
->xmap
.window
);
6269 bool iconified
= FRAME_ICONIFIED_P (f
);
6270 /* wait_reading_process_output will notice this and update
6271 the frame's display structures.
6272 If we where iconified, we should not set garbaged,
6273 because that stops redrawing on Expose events. This looks
6274 bad if we are called from a recursive event loop
6275 (x_dispatch_event), for example when a dialog is up. */
6277 SET_FRAME_GARBAGED (f
);
6279 /* Check if fullscreen was specified before we where mapped the
6280 first time, i.e. from the command line. */
6281 if (!f
->output_data
.x
->has_been_visible
)
6282 x_check_fullscreen (f
);
6284 SET_FRAME_VISIBLE (f
, 1);
6285 SET_FRAME_ICONIFIED (f
, 0);
6286 f
->output_data
.x
->has_been_visible
= 1;
6290 inev
.ie
.kind
= DEICONIFY_EVENT
;
6291 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6293 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
6294 /* Force a redisplay sooner or later to update the
6295 frame titles in case this is the second frame. */
6296 record_asynch_buffer_change ();
6299 xg_frame_resized (f
, -1, -1);
6306 dpyinfo
->last_user_time
= event
->xkey
.time
;
6307 ignore_next_mouse_click_timeout
= 0;
6309 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6310 /* Dispatch KeyPress events when in menu. */
6311 if (popup_activated ())
6317 #if ! defined (USE_GTK)
6318 /* If mouse-highlight is an integer, input clears out
6319 mouse highlighting. */
6320 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6322 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)))
6324 clear_mouse_face (hlinfo
);
6325 hlinfo
->mouse_face_hidden
= 1;
6329 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6332 /* Scroll bars consume key events, but we want
6333 the keys to go to the scroll bar's frame. */
6334 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6335 event
->xkey
.window
);
6336 if (widget
&& XmIsScrollBar (widget
))
6338 widget
= XtParent (widget
);
6339 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6342 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6346 KeySym keysym
, orig_keysym
;
6347 /* al%imercury@uunet.uu.net says that making this 81
6348 instead of 80 fixed a bug whereby meta chars made
6351 It seems that some version of XmbLookupString has
6352 a bug of not returning XBufferOverflow in
6353 status_return even if the input is too long to
6354 fit in 81 bytes. So, we must prepare sufficient
6355 bytes for copy_buffer. 513 bytes (256 chars for
6356 two-byte character set) seems to be a fairly good
6357 approximation. -- 2000.8.10 handa@etl.go.jp */
6358 unsigned char copy_buffer
[513];
6359 unsigned char *copy_bufptr
= copy_buffer
;
6360 int copy_bufsiz
= sizeof (copy_buffer
);
6362 Lisp_Object coding_system
= Qlatin_1
;
6364 /* Event will be modified. */
6365 XKeyEvent xkey
= event
->xkey
;
6368 /* Don't pass keys to GTK. A Tab will shift focus to the
6369 tool bar in GTK 2.4. Keys will still go to menus and
6370 dialogs because in that case popup_activated is TRUE
6372 *finish
= X_EVENT_DROP
;
6375 xkey
.state
|= x_emacs_to_x_modifiers (FRAME_DISPLAY_INFO (f
),
6376 extra_keyboard_modifiers
);
6377 modifiers
= xkey
.state
;
6379 /* This will have to go some day... */
6381 /* make_lispy_event turns chars into control chars.
6382 Don't do it here because XLookupString is too eager. */
6383 xkey
.state
&= ~ControlMask
;
6384 xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6385 | dpyinfo
->super_mod_mask
6386 | dpyinfo
->hyper_mod_mask
6387 | dpyinfo
->alt_mod_mask
);
6389 /* In case Meta is ComposeCharacter,
6390 clear its status. According to Markus Ehrnsperger
6391 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6392 this enables ComposeCharacter to work whether or
6393 not it is combined with Meta. */
6394 if (modifiers
& dpyinfo
->meta_mod_mask
)
6395 memset (&compose_status
, 0, sizeof (compose_status
));
6400 Status status_return
;
6402 coding_system
= Vlocale_coding_system
;
6403 nbytes
= XmbLookupString (FRAME_XIC (f
),
6404 &xkey
, (char *) copy_bufptr
,
6405 copy_bufsiz
, &keysym
,
6407 if (status_return
== XBufferOverflow
)
6409 copy_bufsiz
= nbytes
+ 1;
6410 copy_bufptr
= alloca (copy_bufsiz
);
6411 nbytes
= XmbLookupString (FRAME_XIC (f
),
6412 &xkey
, (char *) copy_bufptr
,
6413 copy_bufsiz
, &keysym
,
6416 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6417 if (status_return
== XLookupNone
)
6419 else if (status_return
== XLookupChars
)
6424 else if (status_return
!= XLookupKeySym
6425 && status_return
!= XLookupBoth
)
6429 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
6430 copy_bufsiz
, &keysym
,
6433 nbytes
= XLookupString (&xkey
, (char *) copy_bufptr
,
6434 copy_bufsiz
, &keysym
,
6438 /* If not using XIM/XIC, and a compose sequence is in progress,
6439 we break here. Otherwise, chars_matched is always 0. */
6440 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6443 memset (&compose_status
, 0, sizeof (compose_status
));
6444 orig_keysym
= keysym
;
6446 /* Common for all keysym input events. */
6447 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6449 = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
), modifiers
);
6450 inev
.ie
.timestamp
= xkey
.time
;
6452 /* First deal with keysyms which have defined
6453 translations to characters. */
6454 if (keysym
>= 32 && keysym
< 128)
6455 /* Avoid explicitly decoding each ASCII character. */
6457 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6458 inev
.ie
.code
= keysym
;
6462 /* Keysyms directly mapped to Unicode characters. */
6463 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6465 if (keysym
< 0x01000080)
6466 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6468 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6469 inev
.ie
.code
= keysym
& 0xFFFFFF;
6473 /* Now non-ASCII. */
6474 if (HASH_TABLE_P (Vx_keysym_table
)
6475 && (c
= Fgethash (make_number (keysym
),
6480 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6481 ? ASCII_KEYSTROKE_EVENT
6482 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6483 inev
.ie
.code
= XFASTINT (c
);
6487 /* Random non-modifier sorts of keysyms. */
6488 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6489 || keysym
== XK_Delete
6490 #ifdef XK_ISO_Left_Tab
6491 || (keysym
>= XK_ISO_Left_Tab
6492 && keysym
<= XK_ISO_Enter
)
6494 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6495 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6497 /* This recognizes the "extended function
6498 keys". It seems there's no cleaner way.
6499 Test IsModifierKey to avoid handling
6500 mode_switch incorrectly. */
6501 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
6503 #ifdef XK_dead_circumflex
6504 || orig_keysym
== XK_dead_circumflex
6506 #ifdef XK_dead_grave
6507 || orig_keysym
== XK_dead_grave
6509 #ifdef XK_dead_tilde
6510 || orig_keysym
== XK_dead_tilde
6512 #ifdef XK_dead_diaeresis
6513 || orig_keysym
== XK_dead_diaeresis
6515 #ifdef XK_dead_macron
6516 || orig_keysym
== XK_dead_macron
6518 #ifdef XK_dead_degree
6519 || orig_keysym
== XK_dead_degree
6521 #ifdef XK_dead_acute
6522 || orig_keysym
== XK_dead_acute
6524 #ifdef XK_dead_cedilla
6525 || orig_keysym
== XK_dead_cedilla
6527 #ifdef XK_dead_breve
6528 || orig_keysym
== XK_dead_breve
6530 #ifdef XK_dead_ogonek
6531 || orig_keysym
== XK_dead_ogonek
6533 #ifdef XK_dead_caron
6534 || orig_keysym
== XK_dead_caron
6536 #ifdef XK_dead_doubleacute
6537 || orig_keysym
== XK_dead_doubleacute
6539 #ifdef XK_dead_abovedot
6540 || orig_keysym
== XK_dead_abovedot
6542 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6543 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6544 /* Any "vendor-specific" key is ok. */
6545 || (orig_keysym
& (1 << 28))
6546 || (keysym
!= NoSymbol
&& nbytes
== 0))
6547 && ! (IsModifierKey (orig_keysym
)
6548 /* The symbols from XK_ISO_Lock
6549 to XK_ISO_Last_Group_Lock
6550 don't have real modifiers but
6551 should be treated similarly to
6552 Mode_switch by Emacs. */
6553 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6554 || (XK_ISO_Lock
<= orig_keysym
6555 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
6559 STORE_KEYSYM_FOR_DEBUG (keysym
);
6560 /* make_lispy_event will convert this to a symbolic
6562 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6563 inev
.ie
.code
= keysym
;
6567 { /* Raw bytes, not keysym. */
6571 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6573 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6575 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6578 if (nchars
< nbytes
)
6580 /* Decode the input data. */
6582 /* The input should be decoded with `coding_system'
6583 which depends on which X*LookupString function
6584 we used just above and the locale. */
6585 setup_coding_system (coding_system
, &coding
);
6586 coding
.src_multibyte
= 0;
6587 coding
.dst_multibyte
= 1;
6588 /* The input is converted to events, thus we can't
6589 handle composition. Anyway, there's no XIM that
6590 gives us composition information. */
6591 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6593 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
6595 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6596 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6597 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6598 nbytes
= coding
.produced
;
6599 nchars
= coding
.produced_char
;
6600 copy_bufptr
= coding
.destination
;
6603 /* Convert the input data to a sequence of
6604 character events. */
6605 for (i
= 0; i
< nbytes
; i
+= len
)
6608 if (nchars
== nbytes
)
6609 ch
= copy_bufptr
[i
], len
= 1;
6611 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6612 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
6613 ? ASCII_KEYSTROKE_EVENT
6614 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6616 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6621 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6623 if (keysym
== NoSymbol
)
6626 /* FIXME: check side effects and remove this. */
6627 ((XEvent
*) event
)->xkey
= xkey
;
6631 /* Don't dispatch this event since XtDispatchEvent calls
6632 XFilterEvent, and two calls in a row may freeze the
6640 dpyinfo
->last_user_time
= event
->xkey
.time
;
6642 /* Don't dispatch this event since XtDispatchEvent calls
6643 XFilterEvent, and two calls in a row may freeze the
6651 dpyinfo
->last_user_time
= event
->xcrossing
.time
;
6652 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6656 if (f
&& x_mouse_click_focus_ignore_position
)
6657 ignore_next_mouse_click_timeout
= event
->xmotion
.time
+ 200;
6659 /* EnterNotify counts as mouse movement,
6660 so update things that depend on mouse position. */
6661 if (f
&& !f
->output_data
.x
->hourglass_p
)
6662 note_mouse_movement (f
, &event
->xmotion
);
6664 /* We may get an EnterNotify on the buttons in the toolbar. In that
6665 case we moved out of any highlighted area and need to note this. */
6666 if (!f
&& last_mouse_glyph_frame
)
6667 note_mouse_movement (last_mouse_glyph_frame
, &event
->xmotion
);
6672 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6676 dpyinfo
->last_user_time
= event
->xcrossing
.time
;
6677 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6679 f
= x_top_window_to_frame (dpyinfo
, event
->xcrossing
.window
);
6682 if (f
== hlinfo
->mouse_face_mouse_frame
)
6684 /* If we move outside the frame, then we're
6685 certainly no longer on any text in the frame. */
6686 clear_mouse_face (hlinfo
);
6687 hlinfo
->mouse_face_mouse_frame
= 0;
6690 /* Generate a nil HELP_EVENT to cancel a help-echo.
6691 Do it only if there's something to cancel.
6692 Otherwise, the startup message is cleared when
6693 the mouse leaves the frame. */
6694 if (any_help_event_p
)
6698 /* See comment in EnterNotify above */
6699 else if (last_mouse_glyph_frame
)
6700 note_mouse_movement (last_mouse_glyph_frame
, &event
->xmotion
);
6705 x_detect_focus_change (dpyinfo
, any
, event
, &inev
.ie
);
6710 dpyinfo
->last_user_time
= event
->xmotion
.time
;
6711 previous_help_echo_string
= help_echo_string
;
6712 help_echo_string
= Qnil
;
6714 if (dpyinfo
->grabbed
&& last_mouse_frame
6715 && FRAME_LIVE_P (last_mouse_frame
))
6716 f
= last_mouse_frame
;
6718 f
= x_window_to_frame (dpyinfo
, event
->xmotion
.window
);
6720 if (hlinfo
->mouse_face_hidden
)
6722 hlinfo
->mouse_face_hidden
= 0;
6723 clear_mouse_face (hlinfo
);
6727 if (f
&& xg_event_is_for_scrollbar (f
, event
))
6733 /* Generate SELECT_WINDOW_EVENTs when needed.
6734 Don't let popup menus influence things (bug#1261). */
6735 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6737 static Lisp_Object last_mouse_window
;
6738 Lisp_Object window
= window_from_coordinates
6739 (f
, event
->xmotion
.x
, event
->xmotion
.y
, 0, 0);
6741 /* Window will be selected only when it is not selected now and
6742 last mouse movement event was not in it. Minibuffer window
6743 will be selected only when it is active. */
6744 if (WINDOWP (window
)
6745 && !EQ (window
, last_mouse_window
)
6746 && !EQ (window
, selected_window
)
6747 /* For click-to-focus window managers
6748 create event iff we don't leave the
6750 && (focus_follows_mouse
6751 || (EQ (XWINDOW (window
)->frame
,
6752 XWINDOW (selected_window
)->frame
))))
6754 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6755 inev
.ie
.frame_or_window
= window
;
6757 /* Remember the last window where we saw the mouse. */
6758 last_mouse_window
= window
;
6760 if (!note_mouse_movement (f
, &event
->xmotion
))
6761 help_echo_string
= previous_help_echo_string
;
6765 #ifndef USE_TOOLKIT_SCROLL_BARS
6766 struct scroll_bar
*bar
6767 = x_window_to_scroll_bar (event
->xmotion
.display
,
6768 event
->xmotion
.window
);
6771 x_scroll_bar_note_movement (bar
, &event
->xmotion
);
6772 #endif /* USE_TOOLKIT_SCROLL_BARS */
6774 /* If we move outside the frame, then we're
6775 certainly no longer on any text in the frame. */
6776 clear_mouse_face (hlinfo
);
6779 /* If the contents of the global variable help_echo_string
6780 has changed, generate a HELP_EVENT. */
6781 if (!NILP (help_echo_string
)
6782 || !NILP (previous_help_echo_string
))
6787 case ConfigureNotify
:
6788 f
= x_top_window_to_frame (dpyinfo
, event
->xconfigure
.window
);
6792 && event
->xconfigure
.window
== FRAME_X_WINDOW (f
))
6794 xg_frame_resized (f
, event
->xconfigure
.width
,
6795 event
->xconfigure
.height
);
6801 #ifndef USE_X_TOOLKIT
6803 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
->xconfigure
.height
);
6804 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
->xconfigure
.width
);
6806 /* In the toolkit version, change_frame_size
6807 is called by the code that handles resizing
6808 of the EmacsFrame widget. */
6810 /* Even if the number of character rows and columns has
6811 not changed, the font size may have changed, so we need
6812 to check the pixel dimensions as well. */
6813 if (columns
!= FRAME_COLS (f
)
6814 || rows
!= FRAME_LINES (f
)
6815 || event
->xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6816 || event
->xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6818 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6819 SET_FRAME_GARBAGED (f
);
6820 cancel_mouse_face (f
);
6823 FRAME_PIXEL_WIDTH (f
) = event
->xconfigure
.width
;
6824 FRAME_PIXEL_HEIGHT (f
) = event
->xconfigure
.height
;
6825 #endif /* not USE_GTK */
6829 /* GTK creates windows but doesn't map them.
6830 Only get real positions when mapped. */
6831 if (FRAME_GTK_OUTER_WIDGET (f
)
6832 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6835 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6839 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6840 xic_set_statusarea (f
);
6849 /* If we decide we want to generate an event to be seen
6850 by the rest of Emacs, we put it here. */
6851 bool tool_bar_p
= 0;
6853 memset (&compose_status
, 0, sizeof (compose_status
));
6854 last_mouse_glyph_frame
= 0;
6855 dpyinfo
->last_user_time
= event
->xbutton
.time
;
6857 if (dpyinfo
->grabbed
6859 && FRAME_LIVE_P (last_mouse_frame
))
6860 f
= last_mouse_frame
;
6862 f
= x_window_to_frame (dpyinfo
, event
->xbutton
.window
);
6865 if (f
&& xg_event_is_for_scrollbar (f
, event
))
6870 #if ! defined (USE_GTK)
6871 /* Is this in the tool-bar? */
6872 if (WINDOWP (f
->tool_bar_window
)
6873 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6876 int x
= event
->xbutton
.x
;
6877 int y
= event
->xbutton
.y
;
6879 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6880 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6882 if (tool_bar_p
&& event
->xbutton
.button
< 4)
6883 handle_tool_bar_click
6884 (f
, x
, y
, event
->xbutton
.type
== ButtonPress
,
6885 x_x_to_emacs_modifiers (dpyinfo
, event
->xbutton
.state
));
6887 #endif /* !USE_GTK */
6890 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6891 if (! popup_activated ())
6894 if (ignore_next_mouse_click_timeout
)
6896 if (event
->type
== ButtonPress
6897 && event
->xbutton
.time
> ignore_next_mouse_click_timeout
)
6899 ignore_next_mouse_click_timeout
= 0;
6900 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
6902 if (event
->type
== ButtonRelease
)
6903 ignore_next_mouse_click_timeout
= 0;
6906 construct_mouse_click (&inev
.ie
, &event
->xbutton
, f
);
6908 if (FRAME_X_EMBEDDED_P (f
))
6909 xembed_send_message (f
, event
->xbutton
.time
,
6910 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6914 struct scroll_bar
*bar
6915 = x_window_to_scroll_bar (event
->xbutton
.display
,
6916 event
->xbutton
.window
);
6918 #ifdef USE_TOOLKIT_SCROLL_BARS
6919 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6921 if (bar
&& event
->xbutton
.state
& ControlMask
)
6923 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
6924 *finish
= X_EVENT_DROP
;
6926 #else /* not USE_TOOLKIT_SCROLL_BARS */
6928 x_scroll_bar_handle_click (bar
, event
, &inev
.ie
);
6929 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6932 if (event
->type
== ButtonPress
)
6934 dpyinfo
->grabbed
|= (1 << event
->xbutton
.button
);
6935 last_mouse_frame
= f
;
6938 last_tool_bar_item
= -1;
6941 dpyinfo
->grabbed
&= ~(1 << event
->xbutton
.button
);
6943 /* Ignore any mouse motion that happened before this event;
6944 any subsequent mouse-movement Emacs events should reflect
6945 only motion after the ButtonPress/Release. */
6949 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6950 f
= x_menubar_window_to_frame (dpyinfo
, event
);
6951 /* For a down-event in the menu bar,
6952 don't pass it to Xt right now.
6953 Instead, save it away
6954 and we will pass it to Xt from kbd_buffer_get_event.
6955 That way, we can run some Lisp code first. */
6956 if (! popup_activated ()
6958 /* Gtk+ menus only react to the first three buttons. */
6959 && event
->xbutton
.button
< 3
6961 && f
&& event
->type
== ButtonPress
6962 /* Verify the event is really within the menu bar
6963 and not just sent to it due to grabbing. */
6964 && event
->xbutton
.x
>= 0
6965 && event
->xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6966 && event
->xbutton
.y
>= 0
6967 && event
->xbutton
.y
< f
->output_data
.x
->menubar_height
6968 && event
->xbutton
.same_screen
)
6970 if (!f
->output_data
.x
->saved_menu_event
)
6971 f
->output_data
.x
->saved_menu_event
= xmalloc (sizeof *event
);
6972 *f
->output_data
.x
->saved_menu_event
= *event
;
6973 inev
.ie
.kind
= MENU_BAR_ACTIVATE_EVENT
;
6974 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6975 *finish
= X_EVENT_DROP
;
6979 #endif /* USE_X_TOOLKIT || USE_GTK */
6983 case CirculateNotify
:
6986 case CirculateRequest
:
6989 case VisibilityNotify
:
6993 /* Someone has changed the keyboard mapping - update the
6995 switch (event
->xmapping
.request
)
6997 case MappingModifier
:
6998 x_find_modifier_meanings (dpyinfo
);
6999 /* This is meant to fall through. */
7000 case MappingKeyboard
:
7001 XRefreshKeyboardMapping ((XMappingEvent
*) &event
->xmapping
);
7006 xft_settings_event (dpyinfo
, event
);
7011 #ifdef USE_X_TOOLKIT
7013 if (*finish
!= X_EVENT_DROP
)
7014 XtDispatchEvent ((XEvent
*) event
);
7016 #endif /* USE_X_TOOLKIT */
7021 if (inev
.ie
.kind
!= NO_EVENT
)
7023 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7028 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7033 XSETFRAME (frame
, f
);
7039 any_help_event_p
= 1;
7040 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7041 help_echo_object
, help_echo_pos
);
7045 help_echo_string
= Qnil
;
7046 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7055 #if defined USE_GTK || defined USE_X_TOOLKIT
7057 /* Handles the XEvent EVENT on display DISPLAY.
7058 This is used for event loops outside the normal event handling,
7059 i.e. looping while a popup menu or a dialog is posted.
7061 Returns the value handle_one_xevent sets in the finish argument. */
7063 x_dispatch_event (XEvent
*event
, Display
*display
)
7065 struct x_display_info
*dpyinfo
;
7066 int finish
= X_EVENT_NORMAL
;
7068 dpyinfo
= x_display_info_for_display (display
);
7071 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7078 /* Read events coming from the X server.
7079 Return as soon as there are no more events to be read.
7081 Return the number of characters stored into the buffer,
7082 thus pretending to be `read' (except the characters we store
7083 in the keyboard buffer can be multibyte, so are not necessarily
7087 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
7090 int event_found
= 0;
7094 /* So people can tell when we have read the available input. */
7095 input_signal_count
++;
7097 /* For debugging, this gives a way to fake an I/O error. */
7098 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7100 XTread_socket_fake_io_error
= 0;
7101 x_io_error_quitter (terminal
->display_info
.x
->display
);
7105 while (XPending (terminal
->display_info
.x
->display
))
7110 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7113 /* Filter events for the current X input method. */
7114 if (x_filter_event (terminal
->display_info
.x
, &event
))
7119 count
+= handle_one_xevent (terminal
->display_info
.x
,
7120 &event
, &finish
, hold_quit
);
7122 if (finish
== X_EVENT_GOTO_OUT
)
7130 /* For GTK we must use the GTK event loop. But XEvents gets passed
7131 to our filter function above, and then to the big event switch.
7132 We use a bunch of globals to communicate with our filter function,
7133 that is kind of ugly, but it works.
7135 There is no way to do one display at the time, GTK just does events
7136 from all displays. */
7138 while (gtk_events_pending ())
7140 current_count
= count
;
7141 current_hold_quit
= hold_quit
;
7143 gtk_main_iteration ();
7145 count
= current_count
;
7147 current_hold_quit
= 0;
7149 if (current_finish
== X_EVENT_GOTO_OUT
)
7152 #endif /* USE_GTK */
7154 /* On some systems, an X bug causes Emacs to get no more events
7155 when the window is destroyed. Detect that. (1994.) */
7158 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7159 One XNOOP in 100 loops will make Emacs terminate.
7160 B. Bretthauer, 1994 */
7162 if (x_noop_count
>= 100)
7166 if (next_noop_dpyinfo
== 0)
7167 next_noop_dpyinfo
= x_display_list
;
7169 XNoOp (next_noop_dpyinfo
->display
);
7171 /* Each time we get here, cycle through the displays now open. */
7172 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7176 /* If the focus was just given to an auto-raising frame,
7178 /* ??? This ought to be able to handle more than one such frame. */
7179 if (pending_autoraise_frame
)
7181 x_raise_frame (pending_autoraise_frame
);
7182 pending_autoraise_frame
= 0;
7193 /***********************************************************************
7195 ***********************************************************************/
7197 /* Set clipping for output in glyph row ROW. W is the window in which
7198 we operate. GC is the graphics context to set clipping in.
7200 ROW may be a text row or, e.g., a mode line. Text rows must be
7201 clipped to the interior of the window dedicated to text display,
7202 mode lines must be clipped to the whole window. */
7205 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
7206 enum glyph_row_area area
, GC gc
)
7208 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7209 XRectangle clip_rect
;
7210 int window_x
, window_y
, window_width
;
7212 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7214 clip_rect
.x
= window_x
;
7215 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7216 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7217 clip_rect
.width
= window_width
;
7218 clip_rect
.height
= row
->visible_height
;
7220 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7224 /* Draw a hollow box cursor on window W in glyph row ROW. */
7227 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7229 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7230 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
7231 Display
*dpy
= FRAME_X_DISPLAY (f
);
7234 struct glyph
*cursor_glyph
;
7237 /* Get the glyph the cursor is on. If we can't tell because
7238 the current matrix is invalid or such, give up. */
7239 cursor_glyph
= get_phys_cursor_glyph (w
);
7240 if (cursor_glyph
== NULL
)
7243 /* Compute frame-relative coordinates for phys cursor. */
7244 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7245 wd
= w
->phys_cursor_width
;
7247 /* The foreground of cursor_gc is typically the same as the normal
7248 background color, which can cause the cursor box to be invisible. */
7249 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7250 if (dpyinfo
->scratch_cursor_gc
)
7251 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7253 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7254 GCForeground
, &xgcv
);
7255 gc
= dpyinfo
->scratch_cursor_gc
;
7257 /* Set clipping, draw the rectangle, and reset clipping again. */
7258 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7259 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7260 XSetClipMask (dpy
, gc
, None
);
7264 /* Draw a bar cursor on window W in glyph row ROW.
7266 Implementation note: One would like to draw a bar cursor with an
7267 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7268 Unfortunately, I didn't find a font yet that has this property set.
7272 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7274 struct frame
*f
= XFRAME (w
->frame
);
7275 struct glyph
*cursor_glyph
;
7277 /* If cursor is out of bounds, don't draw garbage. This can happen
7278 in mini-buffer windows when switching between echo area glyphs
7280 cursor_glyph
= get_phys_cursor_glyph (w
);
7281 if (cursor_glyph
== NULL
)
7284 /* If on an image, draw like a normal cursor. That's usually better
7285 visible than drawing a bar, esp. if the image is large so that
7286 the bar might not be in the window. */
7287 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7289 struct glyph_row
*r
;
7290 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7291 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
7295 Display
*dpy
= FRAME_X_DISPLAY (f
);
7296 Window window
= FRAME_X_WINDOW (f
);
7297 GC gc
= FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7298 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7299 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7302 /* If the glyph's background equals the color we normally draw
7303 the bars cursor in, the bar cursor in its normal color is
7304 invisible. Use the glyph's foreground color instead in this
7305 case, on the assumption that the glyph's colors are chosen so
7306 that the glyph is legible. */
7307 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7308 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7310 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7311 xgcv
.graphics_exposures
= 0;
7314 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7317 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7318 FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7321 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7323 if (kind
== BAR_CURSOR
)
7325 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7328 width
= FRAME_CURSOR_WIDTH (f
);
7329 width
= min (cursor_glyph
->pixel_width
, width
);
7331 w
->phys_cursor_width
= width
;
7333 /* If the character under cursor is R2L, draw the bar cursor
7334 on the right of its glyph, rather than on the left. */
7335 if ((cursor_glyph
->resolved_level
& 1) != 0)
7336 x
+= cursor_glyph
->pixel_width
- width
;
7338 XFillRectangle (dpy
, window
, gc
, x
,
7339 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7340 width
, row
->height
);
7344 int dummy_x
, dummy_y
, dummy_h
;
7347 width
= row
->height
;
7349 width
= min (row
->height
, width
);
7351 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7352 &dummy_y
, &dummy_h
);
7354 XFillRectangle (dpy
, window
, gc
,
7355 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7356 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7357 row
->height
- width
),
7358 w
->phys_cursor_width
, width
);
7361 XSetClipMask (dpy
, gc
, None
);
7366 /* RIF: Define cursor CURSOR on frame F. */
7369 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7371 if (!f
->pointer_invisible
7372 && f
->output_data
.x
->current_cursor
!= cursor
)
7373 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7374 f
->output_data
.x
->current_cursor
= cursor
;
7378 /* RIF: Clear area on frame F. */
7381 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7383 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), x
, y
, width
, height
);
7385 /* Must queue a redraw, because scroll bars might have been cleared. */
7386 if (FRAME_GTK_WIDGET (f
))
7387 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7392 /* RIF: Draw cursor on window W. */
7395 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
7396 int y
, enum text_cursor_kinds cursor_type
,
7397 int cursor_width
, bool on_p
, bool active_p
)
7399 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7403 w
->phys_cursor_type
= cursor_type
;
7404 w
->phys_cursor_on_p
= 1;
7406 if (glyph_row
->exact_window_width_line_p
7407 && (glyph_row
->reversed_p
7408 ? (w
->phys_cursor
.hpos
< 0)
7409 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7411 glyph_row
->cursor_in_fringe_p
= 1;
7412 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7416 switch (cursor_type
)
7418 case HOLLOW_BOX_CURSOR
:
7419 x_draw_hollow_cursor (w
, glyph_row
);
7422 case FILLED_BOX_CURSOR
:
7423 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7427 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7431 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7435 w
->phys_cursor_width
= 0;
7444 if (w
== XWINDOW (f
->selected_window
))
7445 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7446 xic_set_preeditarea (w
, x
, y
);
7450 XFlush (FRAME_X_DISPLAY (f
));
7456 /* Make the x-window of frame F use the gnu icon bitmap. */
7459 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7461 ptrdiff_t bitmap_id
;
7463 if (FRAME_X_WINDOW (f
) == 0)
7466 /* Free up our existing icon bitmap and mask if any. */
7467 if (f
->output_data
.x
->icon_bitmap
> 0)
7468 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7469 f
->output_data
.x
->icon_bitmap
= 0;
7474 /* Use gtk_window_set_icon_from_file () if available,
7475 It's not restricted to bitmaps */
7476 if (xg_set_icon (f
, file
))
7478 #endif /* USE_GTK */
7479 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7480 x_create_bitmap_mask (f
, bitmap_id
);
7484 /* Create the GNU bitmap and mask if necessary. */
7485 if (FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7491 if (xg_set_icon (f
, xg_default_icon_file
)
7492 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7495 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7497 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7499 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7503 /* If all else fails, use the (black and white) xbm image. */
7506 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
7507 gnu_xbm_width
, gnu_xbm_height
);
7511 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7512 x_create_bitmap_mask (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7516 /* The first time we create the GNU bitmap and mask,
7517 this increments the ref-count one extra time.
7518 As a result, the GNU bitmap and mask are never freed.
7519 That way, we don't have to worry about allocating it again. */
7520 x_reference_bitmap (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7522 bitmap_id
= FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
;
7525 x_wm_set_icon_pixmap (f
, bitmap_id
);
7526 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7532 /* Make the x-window of frame F use a rectangle with text.
7533 Use ICON_NAME as the text. */
7536 x_text_icon (struct frame
*f
, const char *icon_name
)
7538 if (FRAME_X_WINDOW (f
) == 0)
7543 text
.value
= (unsigned char *) icon_name
;
7544 text
.encoding
= XA_STRING
;
7546 text
.nitems
= strlen (icon_name
);
7547 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7550 if (f
->output_data
.x
->icon_bitmap
> 0)
7551 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7552 f
->output_data
.x
->icon_bitmap
= 0;
7553 x_wm_set_icon_pixmap (f
, 0);
7558 #define X_ERROR_MESSAGE_SIZE 200
7560 /* If non-nil, this should be a string.
7561 It means catch X errors and store the error message in this string.
7563 The reason we use a stack is that x_catch_error/x_uncatch_error can
7564 be called from a signal handler.
7567 struct x_error_message_stack
{
7568 char string
[X_ERROR_MESSAGE_SIZE
];
7570 struct x_error_message_stack
*prev
;
7572 static struct x_error_message_stack
*x_error_message
;
7574 /* An X error handler which stores the error message in
7575 *x_error_message. This is called from x_error_handler if
7576 x_catch_errors is in effect. */
7579 x_error_catcher (Display
*display
, XErrorEvent
*event
)
7581 XGetErrorText (display
, event
->error_code
,
7582 x_error_message
->string
,
7583 X_ERROR_MESSAGE_SIZE
);
7586 /* Begin trapping X errors for display DPY. Actually we trap X errors
7587 for all displays, but DPY should be the display you are actually
7590 After calling this function, X protocol errors no longer cause
7591 Emacs to exit; instead, they are recorded in the string
7592 stored in *x_error_message.
7594 Calling x_check_errors signals an Emacs error if an X error has
7595 occurred since the last call to x_catch_errors or x_check_errors.
7597 Calling x_uncatch_errors resumes the normal error handling. */
7600 x_catch_errors (Display
*dpy
)
7602 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
7604 /* Make sure any errors from previous requests have been dealt with. */
7608 data
->string
[0] = 0;
7609 data
->prev
= x_error_message
;
7610 x_error_message
= data
;
7613 /* Undo the last x_catch_errors call.
7614 DPY should be the display that was passed to x_catch_errors. */
7617 x_uncatch_errors (void)
7619 struct x_error_message_stack
*tmp
;
7623 /* The display may have been closed before this function is called.
7624 Check if it is still open before calling XSync. */
7625 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7626 XSync (x_error_message
->dpy
, False
);
7628 tmp
= x_error_message
;
7629 x_error_message
= x_error_message
->prev
;
7634 /* If any X protocol errors have arrived since the last call to
7635 x_catch_errors or x_check_errors, signal an Emacs error using
7636 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7639 x_check_errors (Display
*dpy
, const char *format
)
7641 /* Make sure to catch any errors incurred so far. */
7644 if (x_error_message
->string
[0])
7646 char string
[X_ERROR_MESSAGE_SIZE
];
7647 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7648 x_uncatch_errors ();
7649 error (format
, string
);
7653 /* Nonzero if we had any X protocol errors
7654 since we did x_catch_errors on DPY. */
7657 x_had_errors_p (Display
*dpy
)
7659 /* Make sure to catch any errors incurred so far. */
7662 return x_error_message
->string
[0] != 0;
7665 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7668 x_clear_errors (Display
*dpy
)
7670 x_error_message
->string
[0] = 0;
7673 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7674 * idea. --lorentey */
7675 /* Close off all unclosed x_catch_errors calls. */
7678 x_fully_uncatch_errors (void)
7680 while (x_error_message
)
7681 x_uncatch_errors ();
7686 static unsigned int x_wire_count
;
7689 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7694 /************************************************************************
7696 ************************************************************************/
7698 /* Error message passed to x_connection_closed. */
7700 static char *error_msg
;
7702 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7703 the text of an error message that lead to the connection loss. */
7706 x_connection_closed (Display
*dpy
, const char *error_message
)
7708 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7709 Lisp_Object frame
, tail
;
7710 ptrdiff_t idx
= SPECPDL_INDEX ();
7712 error_msg
= alloca (strlen (error_message
) + 1);
7713 strcpy (error_msg
, error_message
);
7715 /* Inhibit redisplay while frames are being deleted. */
7716 specbind (Qinhibit_redisplay
, Qt
);
7720 /* Protect display from being closed when we delete the last
7722 dpyinfo
->reference_count
++;
7723 dpyinfo
->terminal
->reference_count
++;
7726 /* First delete frames whose mini-buffers are on frames
7727 that are on the dead display. */
7728 FOR_EACH_FRAME (tail
, frame
)
7730 Lisp_Object minibuf_frame
;
7732 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7733 if (FRAME_X_P (XFRAME (frame
))
7734 && FRAME_X_P (XFRAME (minibuf_frame
))
7735 && ! EQ (frame
, minibuf_frame
)
7736 && FRAME_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7737 delete_frame (frame
, Qnoelisp
);
7740 /* Now delete all remaining frames on the dead display.
7741 We are now sure none of these is used as the mini-buffer
7742 for another frame that we need to delete. */
7743 FOR_EACH_FRAME (tail
, frame
)
7744 if (FRAME_X_P (XFRAME (frame
))
7745 && FRAME_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7747 /* Set this to t so that delete_frame won't get confused
7748 trying to find a replacement. */
7749 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
7750 delete_frame (frame
, Qnoelisp
);
7753 /* If DPYINFO is null, this means we didn't open the display in the
7754 first place, so don't try to close it. */
7757 /* We can not call XtCloseDisplay here because it calls XSync.
7758 XSync inside the error handler apparently hangs Emacs. On
7759 current Xt versions, this isn't needed either. */
7761 /* A long-standing GTK bug prevents proper disconnect handling
7762 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
7763 the resulting Glib error message loop filled a user's disk.
7764 To avoid this, kill Emacs unconditionally on disconnect. */
7765 shut_down_emacs (0, Qnil
);
7766 fprintf (stderr
, "%s\n\
7767 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
7768 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
7769 For details, see etc/PROBLEMS.\n",
7772 #endif /* USE_GTK */
7774 /* Indicate that this display is dead. */
7775 dpyinfo
->display
= 0;
7777 dpyinfo
->reference_count
--;
7778 dpyinfo
->terminal
->reference_count
--;
7779 if (dpyinfo
->reference_count
!= 0)
7780 /* We have just closed all frames on this display. */
7785 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7786 Fdelete_terminal (tmp
, Qnoelisp
);
7790 if (terminal_list
== 0)
7792 fprintf (stderr
, "%s\n", error_msg
);
7793 Fkill_emacs (make_number (70));
7797 totally_unblock_input ();
7799 unbind_to (idx
, Qnil
);
7800 clear_waiting_for_input ();
7802 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
7803 IF_LINT (if (! terminal_list
) return; )
7805 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7806 longjmp), because returning from this function would get us back into
7807 Xlib's code which will directly call `exit'. */
7808 error ("%s", error_msg
);
7811 /* We specifically use it before defining it, so that gcc doesn't inline it,
7812 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7813 static void x_error_quitter (Display
*, XErrorEvent
*);
7815 /* This is the first-level handler for X protocol errors.
7816 It calls x_error_quitter or x_error_catcher. */
7819 x_error_handler (Display
*display
, XErrorEvent
*event
)
7821 #if defined USE_GTK && defined HAVE_GTK3
7822 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
7823 && event
->request_code
== X_SetInputFocus
)
7829 if (x_error_message
)
7830 x_error_catcher (display
, event
);
7832 x_error_quitter (display
, event
);
7836 /* This is the usual handler for X protocol errors.
7837 It kills all frames on the display that we got the error for.
7838 If that was the only one, it prints an error message and kills Emacs. */
7840 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7842 /* On older GCC versions, just putting x_error_quitter
7843 after x_error_handler prevents inlining into the former. */
7845 static void NO_INLINE
7846 x_error_quitter (Display
*display
, XErrorEvent
*event
)
7848 char buf
[256], buf1
[356];
7850 /* Ignore BadName errors. They can happen because of fonts
7851 or colors that are not defined. */
7853 if (event
->error_code
== BadName
)
7856 /* Note that there is no real way portable across R3/R4 to get the
7857 original error handler. */
7859 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
7860 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7861 buf
, event
->request_code
);
7862 x_connection_closed (display
, buf1
);
7866 /* This is the handler for X IO errors, always.
7867 It kills all frames on the display that we lost touch with.
7868 If that was the only one, it prints an error message and kills Emacs. */
7871 x_io_error_quitter (Display
*display
)
7875 snprintf (buf
, sizeof buf
, "Connection lost to X server `%s'",
7876 DisplayString (display
));
7877 x_connection_closed (display
, buf
);
7881 /* Changing the font of the frame. */
7883 /* Give frame F the font FONT-OBJECT as its default font. The return
7884 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7885 frame. If it is negative, generate a new fontset from
7889 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7891 struct font
*font
= XFONT_OBJECT (font_object
);
7894 fontset
= fontset_from_font (font_object
);
7895 FRAME_FONTSET (f
) = fontset
;
7896 if (FRAME_FONT (f
) == font
)
7897 /* This font is already set in frame F. There's nothing more to
7901 FRAME_FONT (f
) = font
;
7902 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7903 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7904 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7906 compute_fringe_widths (f
, 1);
7908 /* Compute the scroll bar width in character columns. */
7909 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7911 int wid
= FRAME_COLUMN_WIDTH (f
);
7912 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7913 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7917 int wid
= FRAME_COLUMN_WIDTH (f
);
7918 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7921 if (FRAME_X_WINDOW (f
) != 0)
7923 /* Don't change the size of a tip frame; there's no point in
7924 doing it because it's done in Fx_show_tip, and it leads to
7925 problems because the tip frame has no widget. */
7926 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7927 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7932 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7935 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
7944 /***********************************************************************
7946 ***********************************************************************/
7952 /* XIM destroy callback function, which is called whenever the
7953 connection to input method XIM dies. CLIENT_DATA contains a
7954 pointer to the x_display_info structure corresponding to XIM. */
7957 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
7959 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7960 Lisp_Object frame
, tail
;
7964 /* No need to call XDestroyIC.. */
7965 FOR_EACH_FRAME (tail
, frame
)
7967 struct frame
*f
= XFRAME (frame
);
7968 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
7970 FRAME_XIC (f
) = NULL
;
7971 xic_free_xfontset (f
);
7975 /* No need to call XCloseIM. */
7976 dpyinfo
->xim
= NULL
;
7977 XFree (dpyinfo
->xim_styles
);
7981 #endif /* HAVE_X11R6 */
7984 /* This isn't prototyped in OSF 5.0 or 5.1a. */
7985 extern char *XSetIMValues (XIM
, ...);
7988 /* Open the connection to the XIM server on display DPYINFO.
7989 RESOURCE_NAME is the resource name Emacs uses. */
7992 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
8000 XCloseIM (dpyinfo
->xim
);
8001 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8008 XIMCallback destroy
;
8011 /* Get supported styles and XIM values. */
8012 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8015 destroy
.callback
= xim_destroy_callback
;
8016 destroy
.client_data
= (XPointer
)dpyinfo
;
8017 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8023 #endif /* HAVE_XIM */
8024 dpyinfo
->xim
= NULL
;
8028 #ifdef HAVE_X11R6_XIM
8030 /* XIM instantiate callback function, which is called whenever an XIM
8031 server is available. DISPLAY is the display of the XIM.
8032 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8033 when the callback was registered. */
8036 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
8038 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8039 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8041 /* We don't support multiple XIM connections. */
8045 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8047 /* Create XIC for the existing frames on the same display, as long
8048 as they have no XIC. */
8049 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8051 Lisp_Object tail
, frame
;
8054 FOR_EACH_FRAME (tail
, frame
)
8056 struct frame
*f
= XFRAME (frame
);
8059 && FRAME_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8060 if (FRAME_XIC (f
) == NULL
)
8062 create_frame_xic (f
);
8063 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8064 xic_set_statusarea (f
);
8065 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8067 struct window
*w
= XWINDOW (f
->selected_window
);
8068 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8077 #endif /* HAVE_X11R6_XIM */
8080 /* Open a connection to the XIM server on display DPYINFO.
8081 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8082 connection only at the first time. On X11R6, open the connection
8083 in the XIM instantiate callback function. */
8086 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
8088 dpyinfo
->xim
= NULL
;
8092 #ifdef HAVE_X11R6_XIM
8093 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
8095 dpyinfo
->xim_callback_data
= xim_inst
;
8096 xim_inst
->dpyinfo
= dpyinfo
;
8097 xim_inst
->resource_name
= xstrdup (resource_name
);
8098 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8099 resource_name
, emacs_class
,
8100 xim_instantiate_callback
,
8101 /* This is XPointer in XFree86
8102 but (XPointer *) on Tru64, at
8103 least, hence the configure test. */
8104 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8105 #else /* not HAVE_X11R6_XIM */
8106 xim_open_dpy (dpyinfo
, resource_name
);
8107 #endif /* not HAVE_X11R6_XIM */
8109 #endif /* HAVE_XIM */
8113 /* Close the connection to the XIM server on display DPYINFO. */
8116 xim_close_dpy (struct x_display_info
*dpyinfo
)
8121 #ifdef HAVE_X11R6_XIM
8122 if (dpyinfo
->display
)
8123 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8125 xim_instantiate_callback
, NULL
);
8126 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8127 xfree (dpyinfo
->xim_callback_data
);
8128 #endif /* HAVE_X11R6_XIM */
8129 if (dpyinfo
->display
)
8130 XCloseIM (dpyinfo
->xim
);
8131 dpyinfo
->xim
= NULL
;
8132 XFree (dpyinfo
->xim_styles
);
8134 #endif /* HAVE_XIM */
8137 #endif /* not HAVE_X11R6_XIM */
8141 /* Calculate the absolute position in frame F
8142 from its current recorded position values and gravity. */
8145 x_calc_absolute_position (struct frame
*f
)
8147 int flags
= f
->size_hint_flags
;
8149 /* We have nothing to do if the current position
8150 is already for the top-left corner. */
8151 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8154 /* Treat negative positions as relative to the leftmost bottommost
8155 position that fits on the screen. */
8156 if (flags
& XNegative
)
8157 f
->left_pos
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
8158 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8161 int height
= FRAME_PIXEL_HEIGHT (f
);
8163 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8164 /* Something is fishy here. When using Motif, starting Emacs with
8165 `-g -0-0', the frame appears too low by a few pixels.
8167 This seems to be so because initially, while Emacs is starting,
8168 the column widget's height and the frame's pixel height are
8169 different. The column widget's height is the right one. In
8170 later invocations, when Emacs is up, the frame's pixel height
8173 It's not obvious where the initial small difference comes from.
8174 2000-12-01, gerd. */
8176 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8179 if (flags
& YNegative
)
8180 f
->top_pos
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
8181 - height
+ f
->top_pos
;
8184 /* The left_pos and top_pos
8185 are now relative to the top and left screen edges,
8186 so the flags should correspond. */
8187 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8190 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8191 to really change the position, and 0 when calling from
8192 x_make_frame_visible (in that case, XOFF and YOFF are the current
8193 position values). It is -1 when calling from x_set_frame_parameters,
8194 which means, do adjust for borders but don't change the gravity. */
8197 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8199 int modified_top
, modified_left
;
8201 if (change_gravity
> 0)
8205 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8207 f
->size_hint_flags
|= XNegative
;
8209 f
->size_hint_flags
|= YNegative
;
8210 f
->win_gravity
= NorthWestGravity
;
8212 x_calc_absolute_position (f
);
8215 x_wm_set_size_hint (f
, (long) 0, 0);
8217 modified_left
= f
->left_pos
;
8218 modified_top
= f
->top_pos
;
8220 if (change_gravity
!= 0 && FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8222 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8223 than the WM decorations. So we use the calculated offset instead
8224 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8225 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8226 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8229 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8230 modified_left
, modified_top
);
8232 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8233 FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8236 /* change_gravity is non-zero when this function is called from Lisp to
8237 programmatically move a frame. In that case, we call
8238 x_check_expected_move to discover if we have a "Type A" or "Type B"
8239 window manager, and, for a "Type A" window manager, adjust the position
8242 We call x_check_expected_move if a programmatic move occurred, and
8243 either the window manager type (A/B) is unknown or it is Type A but we
8244 need to compute the top/left offset adjustment for this frame. */
8246 if (change_gravity
!= 0 &&
8247 (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8248 || (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8249 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8250 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8251 x_check_expected_move (f
, modified_left
, modified_top
);
8256 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8257 on the root window for frame F contains ATOMNAME.
8258 This is how a WM check shall be done according to the Window Manager
8259 Specification/Extended Window Manager Hints at
8260 http://freedesktop.org/wiki/Specifications/wm-spec. */
8263 wm_supports (struct frame
*f
, Atom want_atom
)
8266 unsigned long actual_size
, bytes_remaining
;
8267 int i
, rc
, actual_format
;
8268 Window wmcheck_window
;
8269 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8270 Window target_window
= dpyinfo
->root_window
;
8271 long max_len
= 65536;
8272 Display
*dpy
= FRAME_X_DISPLAY (f
);
8273 unsigned char *tmp_data
= NULL
;
8274 Atom target_type
= XA_WINDOW
;
8278 x_catch_errors (dpy
);
8279 rc
= XGetWindowProperty (dpy
, target_window
,
8280 dpyinfo
->Xatom_net_supporting_wm_check
,
8281 0, max_len
, False
, target_type
,
8282 &actual_type
, &actual_format
, &actual_size
,
8283 &bytes_remaining
, &tmp_data
);
8285 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8287 if (tmp_data
) XFree (tmp_data
);
8288 x_uncatch_errors ();
8293 wmcheck_window
= *(Window
*) tmp_data
;
8296 /* Check if window exists. */
8297 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8299 if (x_had_errors_p (dpy
))
8301 x_uncatch_errors ();
8306 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8308 /* Window changed, reload atoms */
8309 if (dpyinfo
->net_supported_atoms
!= NULL
)
8310 XFree (dpyinfo
->net_supported_atoms
);
8311 dpyinfo
->net_supported_atoms
= NULL
;
8312 dpyinfo
->nr_net_supported_atoms
= 0;
8313 dpyinfo
->net_supported_window
= 0;
8315 target_type
= XA_ATOM
;
8317 rc
= XGetWindowProperty (dpy
, target_window
,
8318 dpyinfo
->Xatom_net_supported
,
8319 0, max_len
, False
, target_type
,
8320 &actual_type
, &actual_format
, &actual_size
,
8321 &bytes_remaining
, &tmp_data
);
8323 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8325 if (tmp_data
) XFree (tmp_data
);
8326 x_uncatch_errors ();
8331 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8332 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8333 dpyinfo
->net_supported_window
= wmcheck_window
;
8338 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8339 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8341 x_uncatch_errors ();
8348 set_wm_state (Lisp_Object frame
, int add
, Atom atom
, Atom value
)
8350 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (XFRAME (frame
));
8352 x_send_client_event (frame
, make_number (0), frame
,
8353 dpyinfo
->Xatom_net_wm_state
,
8355 /* 1 = add, 0 = remove */
8357 (make_number (add
? 1 : 0),
8359 (make_fixnum_or_float (atom
),
8361 ? list1 (make_fixnum_or_float (value
))
8366 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8369 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8371 XSETFRAME (frame
, f
);
8373 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8374 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
8377 /* Return the current _NET_WM_STATE.
8378 SIZE_STATE is set to one of the FULLSCREEN_* values.
8379 STICKY is set to 1 if the sticky state is set, 0 if not.
8381 Return non-zero if we are not hidden, zero if we are. */
8384 get_current_wm_state (struct frame
*f
,
8390 unsigned long actual_size
, bytes_remaining
;
8391 int i
, rc
, actual_format
, is_hidden
= 0;
8392 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8393 long max_len
= 65536;
8394 Display
*dpy
= FRAME_X_DISPLAY (f
);
8395 unsigned char *tmp_data
= NULL
;
8396 Atom target_type
= XA_ATOM
;
8399 *size_state
= FULLSCREEN_NONE
;
8402 x_catch_errors (dpy
);
8403 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
8404 0, max_len
, False
, target_type
,
8405 &actual_type
, &actual_format
, &actual_size
,
8406 &bytes_remaining
, &tmp_data
);
8408 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8410 if (tmp_data
) XFree (tmp_data
);
8411 x_uncatch_errors ();
8413 return !FRAME_ICONIFIED_P (f
);
8416 x_uncatch_errors ();
8418 for (i
= 0; i
< actual_size
; ++i
)
8420 Atom a
= ((Atom
*)tmp_data
)[i
];
8421 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
8424 f
->output_data
.x
->net_wm_state_hidden_seen
= 1;
8426 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8428 if (*size_state
== FULLSCREEN_HEIGHT
)
8429 *size_state
= FULLSCREEN_MAXIMIZED
;
8431 *size_state
= FULLSCREEN_WIDTH
;
8433 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8435 if (*size_state
== FULLSCREEN_WIDTH
)
8436 *size_state
= FULLSCREEN_MAXIMIZED
;
8438 *size_state
= FULLSCREEN_HEIGHT
;
8440 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
8441 *size_state
= FULLSCREEN_BOTH
;
8442 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8446 if (tmp_data
) XFree (tmp_data
);
8451 /* Do fullscreen as specified in extended window manager hints */
8454 do_ewmh_fullscreen (struct frame
*f
)
8456 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8457 int have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
8460 (void)get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
8462 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8463 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8465 have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
8467 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
8471 XSETFRAME (frame
, f
);
8473 /* Keep number of calls to set_wm_state as low as possible.
8474 Some window managers, or possible Gtk+, hangs when too many
8475 are sent at once. */
8476 switch (f
->want_fullscreen
)
8478 case FULLSCREEN_BOTH
:
8479 if (cur
== FULLSCREEN_WIDTH
|| cur
== FULLSCREEN_MAXIMIZED
8480 || cur
== FULLSCREEN_HEIGHT
)
8481 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8482 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8483 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8485 case FULLSCREEN_WIDTH
:
8486 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
8487 || cur
== FULLSCREEN_MAXIMIZED
)
8488 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8489 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8490 if (cur
!= FULLSCREEN_MAXIMIZED
)
8491 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
8493 case FULLSCREEN_HEIGHT
:
8494 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
8495 || cur
== FULLSCREEN_MAXIMIZED
)
8496 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8497 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
8498 if (cur
!= FULLSCREEN_MAXIMIZED
)
8499 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
8501 case FULLSCREEN_MAXIMIZED
:
8502 if (cur
== FULLSCREEN_BOTH
)
8503 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8504 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8505 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8507 case FULLSCREEN_NONE
:
8508 if (cur
== FULLSCREEN_BOTH
)
8509 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8511 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8512 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8515 f
->want_fullscreen
= FULLSCREEN_NONE
;
8519 return have_net_atom
;
8523 XTfullscreen_hook (struct frame
*f
)
8525 if (FRAME_VISIBLE_P (f
))
8528 x_check_fullscreen (f
);
8536 x_handle_net_wm_state (struct frame
*f
, const XPropertyEvent
*event
)
8538 int value
= FULLSCREEN_NONE
;
8541 int not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
8546 case FULLSCREEN_WIDTH
:
8549 case FULLSCREEN_HEIGHT
:
8552 case FULLSCREEN_BOTH
:
8555 case FULLSCREEN_MAXIMIZED
:
8560 store_frame_param (f
, Qfullscreen
, lval
);
8561 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8566 /* Check if we need to resize the frame due to a fullscreen request.
8567 If so needed, resize the frame. */
8569 x_check_fullscreen (struct frame
*f
)
8571 if (do_ewmh_fullscreen (f
))
8574 if (f
->output_data
.x
->parent_desc
!= FRAME_DISPLAY_INFO (f
)->root_window
)
8575 return; /* Only fullscreen without WM or with EWM hints (above). */
8577 /* Setting fullscreen to nil doesn't do anything. We could save the
8578 last non-fullscreen size and restore it, but it seems like a
8579 lot of work for this unusual case (no window manager running). */
8581 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8583 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
8584 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8586 switch (f
->want_fullscreen
)
8588 /* No difference between these two when there is no WM */
8589 case FULLSCREEN_BOTH
:
8590 case FULLSCREEN_MAXIMIZED
:
8591 width
= x_display_pixel_width (dpyinfo
);
8592 height
= x_display_pixel_height (dpyinfo
);
8594 case FULLSCREEN_WIDTH
:
8595 width
= x_display_pixel_width (dpyinfo
);
8597 case FULLSCREEN_HEIGHT
:
8598 height
= x_display_pixel_height (dpyinfo
);
8601 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8606 /* This function is called by x_set_offset to determine whether the window
8607 manager interfered with the positioning of the frame. Type A window
8608 managers position the surrounding window manager decorations a small
8609 amount above and left of the user-supplied position. Type B window
8610 managers position the surrounding window manager decorations at the
8611 user-specified position. If we detect a Type A window manager, we
8612 compensate by moving the window right and down by the proper amount. */
8615 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8617 int current_left
= 0, current_top
= 0;
8619 /* x_real_positions returns the left and top offsets of the outermost
8620 window manager window around the frame. */
8622 x_real_positions (f
, ¤t_left
, ¤t_top
);
8624 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8626 /* It's a "Type A" window manager. */
8631 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8632 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8633 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8635 /* Now fix the mispositioned frame's location. */
8637 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8638 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8640 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8641 adjusted_left
, adjusted_top
);
8643 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8646 /* It's a "Type B" window manager. We don't have to adjust the
8647 frame's position. */
8649 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8653 /* Wait for XGetGeometry to return up-to-date position information for a
8654 recently-moved frame. Call this immediately after calling XMoveWindow.
8655 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8656 frame has been moved to, so we use a fuzzy position comparison instead
8657 of an exact comparison. */
8660 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8664 while (count
++ < 50)
8666 int current_left
= 0, current_top
= 0;
8668 /* In theory, this call to XSync only needs to happen once, but in
8669 practice, it doesn't seem to work, hence the need for the surrounding
8672 XSync (FRAME_X_DISPLAY (f
), False
);
8673 x_real_positions (f
, ¤t_left
, ¤t_top
);
8677 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8680 if (eabs (current_left
- left
) <= 10
8681 && eabs (current_top
- top
) <= 40)
8684 else if (current_left
== left
&& current_top
== top
)
8688 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8689 will then return up-to-date position info. */
8691 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8695 /* Wait for an event on frame F matching EVENTTYPE. */
8697 x_wait_for_event (struct frame
*f
, int eventtype
)
8699 int level
= interrupt_input_blocked
;
8702 struct timespec tmo
, tmo_at
, time_now
;
8703 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8705 f
->wait_event_type
= eventtype
;
8707 /* Set timeout to 0.1 second. Hopefully not noticeable.
8708 Maybe it should be configurable. */
8709 tmo
= make_timespec (0, 100 * 1000 * 1000);
8710 tmo_at
= timespec_add (current_timespec (), tmo
);
8712 while (f
->wait_event_type
)
8714 pending_signals
= 1;
8715 totally_unblock_input ();
8716 /* XTread_socket is called after unblock. */
8718 interrupt_input_blocked
= level
;
8723 time_now
= current_timespec ();
8724 if (timespec_cmp (tmo_at
, time_now
) < 0)
8727 tmo
= timespec_sub (tmo_at
, time_now
);
8728 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
8729 break; /* Timeout */
8732 f
->wait_event_type
= 0;
8736 /* Change the size of frame F's X window to COLS/ROWS in the case F
8737 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8738 top-left-corner window gravity for this size change and subsequent
8739 size changes. Otherwise we leave the window gravity unchanged. */
8742 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8744 int pixelwidth
, pixelheight
;
8746 check_frame_size (f
, &rows
, &cols
);
8747 f
->scroll_bar_actual_width
8748 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8750 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8752 compute_fringe_widths (f
, 0);
8754 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8755 + FRAME_TOOLBAR_WIDTH (f
);
8756 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8757 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8759 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8760 x_wm_set_size_hint (f
, (long) 0, 0);
8761 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8762 pixelwidth
, pixelheight
);
8765 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8766 receive in the ConfigureNotify event; if we get what we asked
8767 for, then the event won't cause the screen to become garbaged, so
8768 we have to make sure to do it here. */
8769 SET_FRAME_GARBAGED (f
);
8771 /* Now, strictly speaking, we can't be sure that this is accurate,
8772 but the window manager will get around to dealing with the size
8773 change request eventually, and we'll hear how it went when the
8774 ConfigureNotify event gets here.
8776 We could just not bother storing any of this information here,
8777 and let the ConfigureNotify event set everything up, but that
8778 might be kind of confusing to the Lisp code, since size changes
8779 wouldn't be reported in the frame parameters until some random
8780 point in the future when the ConfigureNotify event arrives.
8782 We pass 1 for DELAY since we can't run Lisp code inside of
8785 /* But the ConfigureNotify may in fact never arrive, and then this is
8786 not right if the frame is visible. Instead wait (with timeout)
8787 for the ConfigureNotify. */
8788 if (FRAME_VISIBLE_P (f
))
8789 x_wait_for_event (f
, ConfigureNotify
);
8792 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8793 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8794 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8800 /* Call this to change the size of frame F's x-window.
8801 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8802 for this size change and subsequent size changes.
8803 Otherwise we leave the window gravity unchanged. */
8806 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8810 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8814 /* When the frame is maximized/fullscreen or running under for
8815 example Xmonad, x_set_window_size_1 will be a no-op.
8816 In that case, the right thing to do is extend rows/cols to
8817 the current frame size. We do that first if x_set_window_size_1
8818 turns out to not be a no-op (there is no way to know).
8819 The size will be adjusted again if the frame gets a
8820 ConfigureNotify event as a result of x_set_window_size. */
8821 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8822 #ifdef USE_X_TOOLKIT
8823 /* The menu bar is not part of text lines. The tool bar
8825 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8827 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8828 /* Update f->scroll_bar_actual_width because it is used in
8829 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8830 f
->scroll_bar_actual_width
8831 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8832 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8833 change_frame_size (f
, r
, c
, 0, 1, 0);
8837 if (FRAME_GTK_WIDGET (f
))
8838 xg_frame_set_char_size (f
, cols
, rows
);
8840 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8841 #else /* not USE_GTK */
8843 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8845 #endif /* not USE_GTK */
8847 /* If cursor was outside the new size, mark it as off. */
8848 mark_window_cursors_off (XWINDOW (f
->root_window
));
8850 /* Clear out any recollection of where the mouse highlighting was,
8851 since it might be in a place that's outside the new frame size.
8852 Actually checking whether it is outside is a pain in the neck,
8853 so don't try--just let the highlighting be done afresh with new size. */
8854 cancel_mouse_face (f
);
8859 /* Mouse warping. */
8862 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8866 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8867 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8869 if (pix_x
< 0) pix_x
= 0;
8870 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8872 if (pix_y
< 0) pix_y
= 0;
8873 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8877 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8878 0, 0, 0, 0, pix_x
, pix_y
);
8882 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8885 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8889 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8890 0, 0, 0, 0, pix_x
, pix_y
);
8894 /* Raise frame F. */
8897 x_raise_frame (struct frame
*f
)
8900 if (FRAME_VISIBLE_P (f
))
8901 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8902 XFlush (FRAME_X_DISPLAY (f
));
8906 /* Lower frame F. */
8909 x_lower_frame (struct frame
*f
)
8911 if (FRAME_VISIBLE_P (f
))
8914 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8915 XFlush (FRAME_X_DISPLAY (f
));
8920 /* Request focus with XEmbed */
8923 xembed_request_focus (struct frame
*f
)
8925 /* See XEmbed Protocol Specification at
8926 http://freedesktop.org/wiki/Specifications/xembed-spec */
8927 if (FRAME_VISIBLE_P (f
))
8928 xembed_send_message (f
, CurrentTime
,
8929 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
8932 /* Activate frame with Extended Window Manager Hints */
8935 x_ewmh_activate_frame (struct frame
*f
)
8937 /* See Window Manager Specification/Extended Window Manager Hints at
8938 http://freedesktop.org/wiki/Specifications/wm-spec */
8940 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8942 if (FRAME_VISIBLE_P (f
) && wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
8945 XSETFRAME (frame
, f
);
8946 x_send_client_event (frame
, make_number (0), frame
,
8947 dpyinfo
->Xatom_net_active_window
,
8949 list2i (1, dpyinfo
->last_user_time
));
8954 XTframe_raise_lower (struct frame
*f
, int raise_flag
)
8962 /* XEmbed implementation. */
8964 #if defined USE_X_TOOLKIT || ! defined USE_GTK
8966 /* XEmbed implementation. */
8968 #define XEMBED_VERSION 0
8971 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
8973 unsigned long data
[2];
8974 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8976 data
[0] = XEMBED_VERSION
;
8979 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8980 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
8981 32, PropModeReplace
, (unsigned char *) data
, 2);
8983 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
8986 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
8987 long int detail
, long int data1
, long int data2
)
8991 event
.xclient
.type
= ClientMessage
;
8992 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
8993 event
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_XEMBED
;
8994 event
.xclient
.format
= 32;
8995 event
.xclient
.data
.l
[0] = t
;
8996 event
.xclient
.data
.l
[1] = msg
;
8997 event
.xclient
.data
.l
[2] = detail
;
8998 event
.xclient
.data
.l
[3] = data1
;
8999 event
.xclient
.data
.l
[4] = data2
;
9001 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9002 False
, NoEventMask
, &event
);
9003 XSync (FRAME_X_DISPLAY (f
), False
);
9006 /* Change of visibility. */
9008 /* This tries to wait until the frame is really visible.
9009 However, if the window manager asks the user where to position
9010 the frame, this will return before the user finishes doing that.
9011 The frame will not actually be visible at that time,
9012 but it will become visible later when the window manager
9013 finishes with it. */
9016 x_make_frame_visible (struct frame
*f
)
9019 int original_top
, original_left
;
9020 int retry_count
= 2;
9026 type
= x_icon_type (f
);
9028 x_bitmap_icon (f
, type
);
9030 if (! FRAME_VISIBLE_P (f
))
9032 /* We test FRAME_GARBAGED_P here to make sure we don't
9033 call x_set_offset a second time
9034 if we get to x_make_frame_visible a second time
9035 before the window gets really visible. */
9036 if (! FRAME_ICONIFIED_P (f
)
9037 && ! FRAME_X_EMBEDDED_P (f
)
9038 && ! f
->output_data
.x
->asked_for_visible
)
9039 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9041 f
->output_data
.x
->asked_for_visible
= 1;
9043 if (! EQ (Vx_no_window_manager
, Qt
))
9044 x_wm_set_window_state (f
, NormalState
);
9045 #ifdef USE_X_TOOLKIT
9046 if (FRAME_X_EMBEDDED_P (f
))
9047 xembed_set_info (f
, XEMBED_MAPPED
);
9050 /* This was XtPopup, but that did nothing for an iconified frame. */
9051 XtMapWidget (f
->output_data
.x
->widget
);
9053 #else /* not USE_X_TOOLKIT */
9055 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9056 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9058 if (FRAME_X_EMBEDDED_P (f
))
9059 xembed_set_info (f
, XEMBED_MAPPED
);
9061 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9062 #endif /* not USE_GTK */
9063 #endif /* not USE_X_TOOLKIT */
9066 XFlush (FRAME_X_DISPLAY (f
));
9068 /* Synchronize to ensure Emacs knows the frame is visible
9069 before we do anything else. We do this loop with input not blocked
9070 so that incoming events are handled. */
9074 /* This must be before UNBLOCK_INPUT
9075 since events that arrive in response to the actions above
9076 will set it when they are handled. */
9077 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9079 original_left
= f
->left_pos
;
9080 original_top
= f
->top_pos
;
9082 /* This must come after we set COUNT. */
9085 /* We unblock here so that arriving X events are processed. */
9087 /* Now move the window back to where it was "supposed to be".
9088 But don't do it if the gravity is negative.
9089 When the gravity is negative, this uses a position
9090 that is 3 pixels too low. Perhaps that's really the border width.
9092 Don't do this if the window has never been visible before,
9093 because the window manager may choose the position
9094 and we don't want to override it. */
9096 if (! FRAME_VISIBLE_P (f
)
9097 && ! FRAME_ICONIFIED_P (f
)
9098 && ! FRAME_X_EMBEDDED_P (f
)
9099 && f
->win_gravity
== NorthWestGravity
9100 && previously_visible
)
9104 unsigned int width
, height
, border
, depth
;
9108 /* On some window managers (such as FVWM) moving an existing
9109 window, even to the same place, causes the window manager
9110 to introduce an offset. This can cause the window to move
9111 to an unexpected location. Check the geometry (a little
9112 slow here) and then verify that the window is in the right
9113 place. If the window is not in the right place, move it
9114 there, and take the potential window manager hit. */
9115 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9116 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9118 if (original_left
!= x
|| original_top
!= y
)
9119 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9120 original_left
, original_top
);
9125 XSETFRAME (frame
, f
);
9127 /* Wait until the frame is visible. Process X events until a
9128 MapNotify event has been seen, or until we think we won't get a
9129 MapNotify at all.. */
9130 for (count
= input_signal_count
+ 10;
9131 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9133 /* Force processing of queued events. */
9136 /* Machines that do polling rather than SIGIO have been
9137 observed to go into a busy-wait here. So we'll fake an
9138 alarm signal to let the handler know that there's something
9139 to be read. We used to raise a real alarm, but it seems
9140 that the handler isn't always enabled here. This is
9142 if (input_polling_used ())
9144 /* It could be confusing if a real alarm arrives while
9145 processing the fake one. Turn it off and let the
9146 handler reset it. */
9147 int old_poll_suppress_count
= poll_suppress_count
;
9148 poll_suppress_count
= 1;
9149 poll_for_input_1 ();
9150 poll_suppress_count
= old_poll_suppress_count
;
9156 (let ((f (selected-frame)))
9160 the frame is not raised with various window managers on
9161 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9162 unknown reason, the call to XtMapWidget is completely ignored.
9163 Mapping the widget a second time works. */
9165 if (!FRAME_VISIBLE_P (f
) && --retry_count
!= 0)
9170 /* Change from mapped state to withdrawn state. */
9172 /* Make the frame visible (mapped and not iconified). */
9175 x_make_frame_invisible (struct frame
*f
)
9179 /* Use the frame's outermost window, not the one we normally draw on. */
9180 window
= FRAME_OUTER_WINDOW (f
);
9182 /* Don't keep the highlight on an invisible frame. */
9183 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9184 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9188 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9189 that the current position of the window is user-specified, rather than
9190 program-specified, so that when the window is mapped again, it will be
9191 placed at the same location, without forcing the user to position it
9192 by hand again (they have already done that once for this window.) */
9193 x_wm_set_size_hint (f
, (long) 0, 1);
9196 if (FRAME_GTK_OUTER_WIDGET (f
))
9197 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9200 if (FRAME_X_EMBEDDED_P (f
))
9201 xembed_set_info (f
, 0);
9206 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9207 DefaultScreen (FRAME_X_DISPLAY (f
))))
9210 error ("Can't notify window manager of window withdrawal");
9214 /* We can't distinguish this from iconification
9215 just by the event that we get from the server.
9216 So we can't win using the usual strategy of letting
9217 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9218 and synchronize with the server to make sure we agree. */
9219 SET_FRAME_VISIBLE (f
, 0);
9220 SET_FRAME_ICONIFIED (f
, 0);
9227 /* Change window state from mapped to iconified. */
9230 x_iconify_frame (struct frame
*f
)
9232 #ifdef USE_X_TOOLKIT
9237 /* Don't keep the highlight on an invisible frame. */
9238 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9239 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9241 if (FRAME_ICONIFIED_P (f
))
9246 type
= x_icon_type (f
);
9248 x_bitmap_icon (f
, type
);
9250 #if defined (USE_GTK)
9251 if (FRAME_GTK_OUTER_WIDGET (f
))
9253 if (! FRAME_VISIBLE_P (f
))
9254 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9256 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9257 SET_FRAME_VISIBLE (f
, 0);
9258 SET_FRAME_ICONIFIED (f
, 1);
9264 #ifdef USE_X_TOOLKIT
9266 if (! FRAME_VISIBLE_P (f
))
9268 if (! EQ (Vx_no_window_manager
, Qt
))
9269 x_wm_set_window_state (f
, IconicState
);
9270 /* This was XtPopup, but that did nothing for an iconified frame. */
9271 XtMapWidget (f
->output_data
.x
->widget
);
9272 /* The server won't give us any event to indicate
9273 that an invisible frame was changed to an icon,
9274 so we have to record it here. */
9275 SET_FRAME_VISIBLE (f
, 0);
9276 SET_FRAME_ICONIFIED (f
, 1);
9281 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9282 XtWindow (f
->output_data
.x
->widget
),
9283 DefaultScreen (FRAME_X_DISPLAY (f
)));
9287 error ("Can't notify window manager of iconification");
9289 SET_FRAME_ICONIFIED (f
, 1);
9290 SET_FRAME_VISIBLE (f
, 0);
9293 XFlush (FRAME_X_DISPLAY (f
));
9295 #else /* not USE_X_TOOLKIT */
9297 /* Make sure the X server knows where the window should be positioned,
9298 in case the user deiconifies with the window manager. */
9299 if (! FRAME_VISIBLE_P (f
)
9300 && ! FRAME_ICONIFIED_P (f
)
9301 && ! FRAME_X_EMBEDDED_P (f
))
9302 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9304 /* Since we don't know which revision of X we're running, we'll use both
9305 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9307 /* X11R4: send a ClientMessage to the window manager using the
9308 WM_CHANGE_STATE type. */
9312 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
9313 msg
.xclient
.type
= ClientMessage
;
9314 msg
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9315 msg
.xclient
.format
= 32;
9316 msg
.xclient
.data
.l
[0] = IconicState
;
9318 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9319 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9321 SubstructureRedirectMask
| SubstructureNotifyMask
,
9325 error ("Can't notify window manager of iconification");
9329 /* X11R3: set the initial_state field of the window manager hints to
9331 x_wm_set_window_state (f
, IconicState
);
9333 if (!FRAME_VISIBLE_P (f
))
9335 /* If the frame was withdrawn, before, we must map it. */
9336 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9339 SET_FRAME_ICONIFIED (f
, 1);
9340 SET_FRAME_VISIBLE (f
, 0);
9342 XFlush (FRAME_X_DISPLAY (f
));
9344 #endif /* not USE_X_TOOLKIT */
9348 /* Free X resources of frame F. */
9351 x_free_frame_resources (struct frame
*f
)
9353 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9354 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
9355 #ifdef USE_X_TOOLKIT
9357 struct scroll_bar
*b
;
9362 /* If a display connection is dead, don't try sending more
9363 commands to the X server. */
9364 if (dpyinfo
->display
)
9366 /* We must free faces before destroying windows because some
9367 font-driver (e.g. xft) access a window while finishing a
9369 if (FRAME_FACE_CACHE (f
))
9370 free_frame_faces (f
);
9372 if (f
->output_data
.x
->icon_desc
)
9373 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9375 #ifdef USE_X_TOOLKIT
9376 /* Explicitly destroy the scroll bars of the frame. Without
9377 this, we get "BadDrawable" errors from the toolkit later on,
9378 presumably from expose events generated for the disappearing
9379 toolkit scroll bars. */
9380 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9382 b
= XSCROLL_BAR (bar
);
9383 x_scroll_bar_remove (b
);
9392 #ifdef USE_X_TOOLKIT
9393 if (f
->output_data
.x
->widget
)
9395 XtDestroyWidget (f
->output_data
.x
->widget
);
9396 f
->output_data
.x
->widget
= NULL
;
9398 /* Tooltips don't have widgets, only a simple X window, even if
9399 we are using a toolkit. */
9400 else if (FRAME_X_WINDOW (f
))
9401 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9403 free_frame_menubar (f
);
9404 #else /* !USE_X_TOOLKIT */
9407 xg_free_frame_widgets (f
);
9408 #endif /* USE_GTK */
9410 if (FRAME_X_WINDOW (f
))
9411 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9412 #endif /* !USE_X_TOOLKIT */
9414 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9415 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9416 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9417 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9418 unload_color (f
, f
->output_data
.x
->border_pixel
);
9419 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9421 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9422 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9423 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9424 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9425 #ifdef USE_TOOLKIT_SCROLL_BARS
9426 /* Scrollbar shadow colors. */
9427 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9428 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9429 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9430 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9431 #endif /* USE_TOOLKIT_SCROLL_BARS */
9432 if (f
->output_data
.x
->white_relief
.allocated_p
)
9433 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9434 if (f
->output_data
.x
->black_relief
.allocated_p
)
9435 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9439 /* Free extra GCs allocated by x_setup_relief_colors. */
9440 if (f
->output_data
.x
->white_relief
.gc
)
9442 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
9443 f
->output_data
.x
->white_relief
.gc
= 0;
9445 if (f
->output_data
.x
->black_relief
.gc
)
9447 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
9448 f
->output_data
.x
->black_relief
.gc
= 0;
9451 XFlush (FRAME_X_DISPLAY (f
));
9454 xfree (f
->output_data
.x
->saved_menu_event
);
9455 xfree (f
->output_data
.x
);
9456 f
->output_data
.x
= NULL
;
9458 if (f
== dpyinfo
->x_focus_frame
)
9459 dpyinfo
->x_focus_frame
= 0;
9460 if (f
== dpyinfo
->x_focus_event_frame
)
9461 dpyinfo
->x_focus_event_frame
= 0;
9462 if (f
== dpyinfo
->x_highlight_frame
)
9463 dpyinfo
->x_highlight_frame
= 0;
9464 if (f
== hlinfo
->mouse_face_mouse_frame
)
9465 reset_mouse_highlight (hlinfo
);
9471 /* Destroy the X window of frame F. */
9474 x_destroy_window (struct frame
*f
)
9476 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9478 /* If a display connection is dead, don't try sending more
9479 commands to the X server. */
9480 if (dpyinfo
->display
!= 0)
9481 x_free_frame_resources (f
);
9483 dpyinfo
->reference_count
--;
9487 /* Setting window manager hints. */
9489 /* Set the normal size hints for the window manager, for frame F.
9490 FLAGS is the flags word to use--or 0 meaning preserve the flags
9491 that the window now has.
9492 If USER_POSITION, set the USPosition
9493 flag (this is useful when FLAGS is 0).
9494 The GTK version is in gtkutils.c. */
9498 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
9500 XSizeHints size_hints
;
9501 Window window
= FRAME_OUTER_WINDOW (f
);
9503 #ifdef USE_X_TOOLKIT
9504 if (f
->output_data
.x
->widget
)
9506 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
9511 /* Setting PMaxSize caused various problems. */
9512 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9514 size_hints
.x
= f
->left_pos
;
9515 size_hints
.y
= f
->top_pos
;
9517 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9518 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9520 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9521 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9522 size_hints
.max_width
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
9523 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9524 size_hints
.max_height
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
9525 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9527 /* Calculate the base and minimum sizes. */
9529 int base_width
, base_height
;
9530 int min_rows
= 0, min_cols
= 0;
9532 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9533 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9535 check_frame_size (f
, &min_rows
, &min_cols
);
9537 /* The window manager uses the base width hints to calculate the
9538 current number of rows and columns in the frame while
9539 resizing; min_width and min_height aren't useful for this
9540 purpose, since they might not give the dimensions for a
9541 zero-row, zero-column frame.
9543 We use the base_width and base_height members if we have
9544 them; otherwise, we set the min_width and min_height members
9545 to the size for a zero x zero frame. */
9547 size_hints
.flags
|= PBaseSize
;
9548 size_hints
.base_width
= base_width
;
9549 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9550 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9551 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9554 /* If we don't need the old flags, we don't need the old hint at all. */
9557 size_hints
.flags
|= flags
;
9562 XSizeHints hints
; /* Sometimes I hate X Windows... */
9563 long supplied_return
;
9566 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9570 size_hints
.flags
|= flags
;
9575 if (hints
.flags
& PSize
)
9576 size_hints
.flags
|= PSize
;
9577 if (hints
.flags
& PPosition
)
9578 size_hints
.flags
|= PPosition
;
9579 if (hints
.flags
& USPosition
)
9580 size_hints
.flags
|= USPosition
;
9581 if (hints
.flags
& USSize
)
9582 size_hints
.flags
|= USSize
;
9589 size_hints
.win_gravity
= f
->win_gravity
;
9590 size_hints
.flags
|= PWinGravity
;
9594 size_hints
.flags
&= ~ PPosition
;
9595 size_hints
.flags
|= USPosition
;
9597 #endif /* PWinGravity */
9599 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9601 #endif /* not USE_GTK */
9603 /* Used for IconicState or NormalState */
9606 x_wm_set_window_state (struct frame
*f
, int state
)
9608 #ifdef USE_X_TOOLKIT
9611 XtSetArg (al
[0], XtNinitialState
, state
);
9612 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9613 #else /* not USE_X_TOOLKIT */
9614 Window window
= FRAME_X_WINDOW (f
);
9616 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9617 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9619 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9620 #endif /* not USE_X_TOOLKIT */
9624 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
9626 Pixmap icon_pixmap
, icon_mask
;
9628 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9629 Window window
= FRAME_OUTER_WINDOW (f
);
9634 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9635 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9636 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9637 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9641 /* It seems there is no way to turn off use of an icon
9649 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9653 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9657 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9658 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9659 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9660 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9663 #else /* not USE_X_TOOLKIT && not USE_GTK */
9665 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9666 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9668 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9672 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9674 Window window
= FRAME_OUTER_WINDOW (f
);
9676 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9677 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9678 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9680 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9684 /***********************************************************************
9686 ***********************************************************************/
9690 /* Check that FONT is valid on frame F. It is if it can be found in F's
9694 x_check_font (struct frame
*f
, struct font
*font
)
9696 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9697 if (font
->driver
->check
)
9698 eassert (font
->driver
->check (f
, font
) == 0);
9701 #endif /* GLYPH_DEBUG */
9704 /***********************************************************************
9706 ***********************************************************************/
9708 #ifdef USE_X_TOOLKIT
9709 static XrmOptionDescRec emacs_options
[] = {
9710 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9711 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9713 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9714 XrmoptionSepArg
, NULL
},
9715 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9717 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9718 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9719 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9720 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9721 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9722 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9723 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9726 /* Whether atimer for Xt timeouts is activated or not. */
9728 static int x_timeout_atimer_activated_flag
;
9730 #endif /* USE_X_TOOLKIT */
9732 static int x_initialized
;
9734 /* Test whether two display-name strings agree up to the dot that separates
9735 the screen number from the server number. */
9737 same_x_server (const char *name1
, const char *name2
)
9740 const char *system_name
= SSDATA (Vsystem_name
);
9741 ptrdiff_t system_name_length
= SBYTES (Vsystem_name
);
9742 ptrdiff_t length_until_period
= 0;
9744 while (system_name
[length_until_period
] != 0
9745 && system_name
[length_until_period
] != '.')
9746 length_until_period
++;
9748 /* Treat `unix' like an empty host name. */
9749 if (! strncmp (name1
, "unix:", 5))
9751 if (! strncmp (name2
, "unix:", 5))
9753 /* Treat this host's name like an empty host name. */
9754 if (! strncmp (name1
, system_name
, system_name_length
)
9755 && name1
[system_name_length
] == ':')
9756 name1
+= system_name_length
;
9757 if (! strncmp (name2
, system_name
, system_name_length
)
9758 && name2
[system_name_length
] == ':')
9759 name2
+= system_name_length
;
9760 /* Treat this host's domainless name like an empty host name. */
9761 if (! strncmp (name1
, system_name
, length_until_period
)
9762 && name1
[length_until_period
] == ':')
9763 name1
+= length_until_period
;
9764 if (! strncmp (name2
, system_name
, length_until_period
)
9765 && name2
[length_until_period
] == ':')
9766 name2
+= length_until_period
;
9768 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9772 if (seen_colon
&& *name1
== '.')
9776 && (*name1
== '.' || *name1
== '\0')
9777 && (*name2
== '.' || *name2
== '\0'));
9780 /* Count number of set bits in mask and number of bits to shift to
9781 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9784 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9805 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9806 But don't permanently open it, just test its availability. */
9809 x_display_ok (const char *display
)
9811 Display
*dpy
= XOpenDisplay (display
);
9812 return dpy
? (XCloseDisplay (dpy
), 1) : 0;
9817 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
9818 const gchar
*msg
, gpointer user_data
)
9820 if (!strstr (msg
, "g_set_prgname"))
9821 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
9825 /* Open a connection to X display DISPLAY_NAME, and return
9826 the structure that describes the open display.
9827 If we cannot contact the display, return null. */
9829 struct x_display_info
*
9830 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9834 struct terminal
*terminal
;
9835 struct x_display_info
*dpyinfo
;
9847 if (! x_display_ok (SSDATA (display_name
)))
9848 error ("Display %s can't be opened", SSDATA (display_name
));
9854 char *argv
[NUM_ARGV
];
9855 char **argv2
= argv
;
9858 if (x_initialized
++ > 1)
9860 xg_display_open (SSDATA (display_name
), &dpy
);
9864 static char display_opt
[] = "--display";
9865 static char name_opt
[] = "--name";
9867 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9871 argv
[argc
++] = initial_argv
[0];
9873 if (! NILP (display_name
))
9875 argv
[argc
++] = display_opt
;
9876 argv
[argc
++] = SSDATA (display_name
);
9879 argv
[argc
++] = name_opt
;
9880 argv
[argc
++] = resource_name
;
9882 XSetLocaleModifiers ("");
9884 /* Emacs can only handle core input events, so make sure
9885 Gtk doesn't use Xinput or Xinput2 extensions. */
9886 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
9888 /* Work around GLib bug that outputs a faulty warning. See
9889 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9890 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9891 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9893 /* NULL window -> events for all windows go to our function.
9894 Call before gtk_init so Gtk+ event filters comes after our. */
9895 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9897 /* gtk_init does set_locale. Fix locale before and after. */
9899 gtk_init (&argc
, &argv2
);
9902 g_log_remove_handler ("GLib", id
);
9906 dpy
= DEFAULT_GDK_DISPLAY ();
9908 #if ! GTK_CHECK_VERSION (2, 90, 0)
9909 /* Load our own gtkrc if it exists. */
9911 const char *file
= "~/.emacs.d/gtkrc";
9912 Lisp_Object s
, abs_file
;
9914 s
= build_string (file
);
9915 abs_file
= Fexpand_file_name (s
, Qnil
);
9917 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
9918 gtk_rc_parse (SSDATA (abs_file
));
9922 XSetErrorHandler (x_error_handler
);
9923 XSetIOErrorHandler (x_io_error_quitter
);
9926 #else /* not USE_GTK */
9927 #ifdef USE_X_TOOLKIT
9928 /* weiner@footloose.sps.mot.com reports that this causes
9930 X protocol error: BadAtom (invalid Atom parameter)
9931 on protocol request 18skiloaf.
9932 So let's not use it until R6. */
9934 XtSetLanguageProc (NULL
, NULL
, NULL
);
9945 argv
[argc
++] = "-xrm";
9946 argv
[argc
++] = xrm_option
;
9948 turn_on_atimers (0);
9949 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
9950 resource_name
, EMACS_CLASS
,
9951 emacs_options
, XtNumber (emacs_options
),
9953 turn_on_atimers (1);
9956 /* I think this is to compensate for XtSetLanguageProc. */
9961 #else /* not USE_X_TOOLKIT */
9962 XSetLocaleModifiers ("");
9963 dpy
= XOpenDisplay (SSDATA (display_name
));
9964 #endif /* not USE_X_TOOLKIT */
9965 #endif /* not USE_GTK*/
9967 /* Detect failure. */
9974 /* We have definitely succeeded. Record the new connection. */
9976 dpyinfo
= xzalloc (sizeof *dpyinfo
);
9977 terminal
= x_create_terminal (dpyinfo
);
9980 struct x_display_info
*share
;
9983 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
9984 share
= share
->next
, tail
= XCDR (tail
))
9985 if (same_x_server (SSDATA (XCAR (XCAR (tail
))),
9986 SSDATA (display_name
)))
9989 terminal
->kboard
= share
->terminal
->kboard
;
9992 terminal
->kboard
= xmalloc (sizeof *terminal
->kboard
);
9993 init_kboard (terminal
->kboard
);
9994 kset_window_system (terminal
->kboard
, Qx
);
9996 /* Add the keyboard to the list before running Lisp code (via
9997 Qvendor_specific_keysyms below), since these are not traced
9998 via terminals but only through all_kboards. */
9999 terminal
->kboard
->next_kboard
= all_kboards
;
10000 all_kboards
= terminal
->kboard
;
10002 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10004 char *vendor
= ServerVendor (dpy
);
10006 /* Protect terminal from GC before removing it from the
10007 list of terminals. */
10008 struct gcpro gcpro1
;
10009 Lisp_Object gcpro_term
;
10010 XSETTERMINAL (gcpro_term
, terminal
);
10011 GCPRO1 (gcpro_term
);
10013 /* Temporarily hide the partially initialized terminal. */
10014 terminal_list
= terminal
->next_terminal
;
10016 kset_system_key_alist
10018 call1 (Qvendor_specific_keysyms
,
10019 vendor
? build_string (vendor
) : empty_unibyte_string
));
10021 terminal
->next_terminal
= terminal_list
;
10022 terminal_list
= terminal
;
10026 /* Don't let the initial kboard remain current longer than necessary.
10027 That would cause problems if a file loaded on startup tries to
10028 prompt in the mini-buffer. */
10029 if (current_kboard
== initial_kboard
)
10030 current_kboard
= terminal
->kboard
;
10032 terminal
->kboard
->reference_count
++;
10035 /* Put this display on the chain. */
10036 dpyinfo
->next
= x_display_list
;
10037 x_display_list
= dpyinfo
;
10039 /* Put it on x_display_name_list as well, to keep them parallel. */
10040 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10041 x_display_name_list
);
10042 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10044 dpyinfo
->display
= dpy
;
10046 /* Set the name of the terminal. */
10047 terminal
->name
= xlispstrdup (display_name
);
10050 XSetAfterFunction (x_current_display
, x_trace_wire
);
10053 lim
= min (PTRDIFF_MAX
, SIZE_MAX
) - sizeof "@";
10054 if (lim
- SBYTES (Vinvocation_name
) < SBYTES (Vsystem_name
))
10055 memory_full (SIZE_MAX
);
10056 dpyinfo
->x_id_name
= xmalloc (SBYTES (Vinvocation_name
)
10057 + SBYTES (Vsystem_name
) + 2);
10058 strcat (strcat (strcpy (dpyinfo
->x_id_name
, SSDATA (Vinvocation_name
)), "@"),
10059 SSDATA (Vsystem_name
));
10061 /* Figure out which modifier bits mean what. */
10062 x_find_modifier_meanings (dpyinfo
);
10064 /* Get the scroll bar cursor. */
10066 /* We must create a GTK cursor, it is required for GTK widgets. */
10067 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10068 #endif /* USE_GTK */
10070 dpyinfo
->vertical_scroll_bar_cursor
10071 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10073 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10074 resource_name
, EMACS_CLASS
);
10075 #ifdef HAVE_XRMSETDATABASE
10076 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10078 dpyinfo
->display
->db
= xrdb
;
10080 /* Put the rdb where we can find it in a way that works on
10082 dpyinfo
->xrdb
= xrdb
;
10084 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10085 DefaultScreen (dpyinfo
->display
));
10086 select_visual (dpyinfo
);
10087 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10088 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10089 dpyinfo
->icon_bitmap_id
= -1;
10090 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10092 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
10094 /* See if we can construct pixel values from RGB values. */
10095 if (dpyinfo
->visual
->class == TrueColor
)
10097 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10098 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10099 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10100 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10101 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10102 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10105 /* See if a private colormap is requested. */
10106 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10108 if (dpyinfo
->visual
->class == PseudoColor
)
10111 value
= display_x_get_resource (dpyinfo
,
10112 build_string ("privateColormap"),
10113 build_string ("PrivateColormap"),
10115 if (STRINGP (value
)
10116 && (!strcmp (SSDATA (value
), "true")
10117 || !strcmp (SSDATA (value
), "on")))
10118 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10122 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10123 dpyinfo
->visual
, AllocNone
);
10127 /* If we are using Xft, check dpi value in X resources.
10128 It is better we use it as well, since Xft will use it, as will all
10129 Gnome applications. If our real DPI is smaller or larger than the
10130 one Xft uses, our font will look smaller or larger than other
10131 for other applications, even if it is the same font name (monospace-10
10133 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10135 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10136 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10140 if (dpyinfo
->resy
< 1)
10142 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10143 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10144 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10145 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10146 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10147 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10148 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10149 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10150 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10154 static const struct
10159 #define ATOM_REFS_INIT(string, member) \
10160 { string, offsetof (struct x_display_info, member) },
10161 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
10162 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
10163 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
10164 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
10165 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
10166 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
10167 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
10168 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
10169 ATOM_REFS_INIT ("Editres", Xatom_editres
)
10170 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
10171 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
10172 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
10173 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
10174 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
10175 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
10176 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
10177 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
10178 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
10179 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
10180 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
10181 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
10182 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
10183 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
10184 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
10185 /* For properties of font. */
10186 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
10187 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
10188 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
10189 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
10190 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
10191 /* Ghostscript support. */
10192 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
10193 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
10194 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
10195 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
10197 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
10198 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
10199 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
10200 Xatom_net_wm_state_maximized_horz
)
10201 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
10202 Xatom_net_wm_state_maximized_vert
)
10203 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
10204 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
10205 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
10206 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
10207 Xatom_net_window_type_tooltip
)
10208 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
10209 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
10210 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
10211 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
10212 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
10213 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
10214 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
10215 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
10216 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
10217 /* Session management */
10218 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
10219 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
10220 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
10224 const int atom_count
= sizeof (atom_refs
) / sizeof (atom_refs
[0]);
10225 /* 1 for _XSETTINGS_SN */
10226 const int total_atom_count
= 1 + atom_count
;
10227 Atom
*atoms_return
= xmalloc (total_atom_count
* sizeof *atoms_return
);
10228 char **atom_names
= xmalloc (total_atom_count
* sizeof *atom_names
);
10229 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
10230 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
10231 + INT_STRLEN_BOUND (int)];
10233 for (i
= 0; i
< atom_count
; i
++)
10234 atom_names
[i
] = (char *) atom_refs
[i
].name
;
10236 /* Build _XSETTINGS_SN atom name */
10237 sprintf (xsettings_atom_name
, xsettings_fmt
,
10238 XScreenNumberOfScreen (dpyinfo
->screen
));
10239 atom_names
[i
] = xsettings_atom_name
;
10241 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
10242 False
, atoms_return
);
10244 for (i
= 0; i
< atom_count
; i
++)
10245 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
10247 /* Manual copy of last atom */
10248 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
10250 xfree (atom_names
);
10251 xfree (atoms_return
);
10254 dpyinfo
->x_dnd_atoms_size
= 8;
10255 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
10256 * dpyinfo
->x_dnd_atoms_size
);
10258 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10259 gray_bits
, gray_width
, gray_height
,
10263 xim_initialize (dpyinfo
, resource_name
);
10266 xsettings_initialize (dpyinfo
);
10268 connection
= ConnectionNumber (dpyinfo
->display
);
10270 /* This is only needed for distinguishing keyboard and process input. */
10271 if (connection
!= 0)
10272 add_keyboard_wait_descriptor (connection
);
10275 fcntl (connection
, F_SETOWN
, getpid ());
10276 #endif /* ! defined (F_SETOWN) */
10278 if (interrupt_input
)
10279 init_sigio (connection
);
10283 XrmValue d
, fr
, to
;
10286 dpy
= dpyinfo
->display
;
10287 d
.addr
= (XPointer
)&dpy
;
10288 d
.size
= sizeof (Display
*);
10289 fr
.addr
= XtDefaultFont
;
10290 fr
.size
= sizeof (XtDefaultFont
);
10291 to
.size
= sizeof (Font
*);
10292 to
.addr
= (XPointer
)&font
;
10293 x_catch_errors (dpy
);
10294 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10296 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10297 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10298 x_uncatch_errors ();
10302 /* See if we should run in synchronous mode. This is useful
10303 for debugging X code. */
10306 value
= display_x_get_resource (dpyinfo
,
10307 build_string ("synchronous"),
10308 build_string ("Synchronous"),
10310 if (STRINGP (value
)
10311 && (!strcmp (SSDATA (value
), "true")
10312 || !strcmp (SSDATA (value
), "on")))
10313 XSynchronize (dpyinfo
->display
, True
);
10318 value
= display_x_get_resource (dpyinfo
,
10319 build_string ("useXIM"),
10320 build_string ("UseXIM"),
10323 if (STRINGP (value
)
10324 && (!strcmp (SSDATA (value
), "false")
10325 || !strcmp (SSDATA (value
), "off")))
10328 if (STRINGP (value
)
10329 && (!strcmp (SSDATA (value
), "true")
10330 || !strcmp (SSDATA (value
), "on")))
10336 /* Only do this for the very first display in the Emacs session.
10337 Ignore X session management when Emacs was first started on a
10339 if (terminal
->id
== 1)
10340 x_session_initialize (dpyinfo
);
10348 /* Get rid of display DPYINFO, deleting all frames on it,
10349 and without sending any more commands to the X server. */
10352 x_delete_display (struct x_display_info
*dpyinfo
)
10354 struct terminal
*t
;
10356 /* Close all frames and delete the generic struct terminal for this
10358 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10359 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10362 /* Close X session management when we close its display. */
10363 if (t
->id
== 1 && x_session_have_connection ())
10364 x_session_close ();
10366 delete_terminal (t
);
10370 /* Discard this display from x_display_name_list and x_display_list.
10371 We can't use Fdelq because that can quit. */
10372 if (! NILP (x_display_name_list
)
10373 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10374 x_display_name_list
= XCDR (x_display_name_list
);
10379 tail
= x_display_name_list
;
10380 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10382 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10384 XSETCDR (tail
, XCDR (XCDR (tail
)));
10387 tail
= XCDR (tail
);
10391 if (next_noop_dpyinfo
== dpyinfo
)
10392 next_noop_dpyinfo
= dpyinfo
->next
;
10394 if (x_display_list
== dpyinfo
)
10395 x_display_list
= dpyinfo
->next
;
10398 struct x_display_info
*tail
;
10400 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10401 if (tail
->next
== dpyinfo
)
10402 tail
->next
= tail
->next
->next
;
10405 xfree (dpyinfo
->x_id_name
);
10406 xfree (dpyinfo
->x_dnd_atoms
);
10407 xfree (dpyinfo
->color_cells
);
10411 #ifdef USE_X_TOOLKIT
10413 /* Atimer callback function for TIMER. Called every 0.1s to process
10414 Xt timeouts, if needed. We must avoid calling XtAppPending as
10415 much as possible because that function does an implicit XFlush
10416 that slows us down. */
10419 x_process_timeouts (struct atimer
*timer
)
10422 x_timeout_atimer_activated_flag
= 0;
10423 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10425 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10426 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10427 /* Reactivate the atimer for next time. */
10428 x_activate_timeout_atimer ();
10433 /* Install an asynchronous timer that processes Xt timeout events
10434 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10435 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10436 function whenever these variables are set. This is necessary
10437 because some widget sets use timeouts internally, for example the
10438 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10439 processed, these widgets don't behave normally. */
10442 x_activate_timeout_atimer (void)
10445 if (!x_timeout_atimer_activated_flag
)
10447 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
10448 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10449 x_timeout_atimer_activated_flag
= 1;
10454 #endif /* USE_X_TOOLKIT */
10457 /* Set up use of X before we make the first connection. */
10459 static struct redisplay_interface x_redisplay_interface
=
10461 x_frame_parm_handlers
,
10465 x_clear_end_of_line
,
10467 x_after_update_window_line
,
10468 x_update_window_begin
,
10469 x_update_window_end
,
10471 x_clear_window_mouse_face
,
10472 x_get_glyph_overhangs
,
10473 x_fix_overlapping_area
,
10474 x_draw_fringe_bitmap
,
10475 0, /* define_fringe_bitmap */
10476 0, /* destroy_fringe_bitmap */
10477 x_compute_glyph_string_overhangs
,
10478 x_draw_glyph_string
,
10479 x_define_frame_cursor
,
10480 x_clear_frame_area
,
10481 x_draw_window_cursor
,
10482 x_draw_vertical_window_border
,
10483 x_shift_glyphs_for_insert
10487 /* This function is called when the last frame on a display is deleted. */
10489 x_delete_terminal (struct terminal
*terminal
)
10491 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10492 int connection
= -1;
10494 /* Protect against recursive calls. delete_frame in
10495 delete_terminal calls us back when it deletes our last frame. */
10496 if (!terminal
->name
)
10501 /* We must close our connection to the XIM server before closing the
10504 xim_close_dpy (dpyinfo
);
10507 /* If called from x_connection_closed, the display may already be closed
10508 and dpyinfo->display was set to 0 to indicate that. */
10509 if (dpyinfo
->display
)
10511 connection
= ConnectionNumber (dpyinfo
->display
);
10513 x_destroy_all_bitmaps (dpyinfo
);
10514 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10516 /* Whether or not XCloseDisplay destroys the associated resource
10517 database depends on the version of libX11. To avoid both
10518 crash and memory leak, we dissociate the database from the
10519 display and then destroy dpyinfo->xrdb ourselves.
10521 Unfortunately, the above strategy does not work in some
10522 situations due to a bug in newer versions of libX11: because
10523 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10524 dpy->db is NULL, XCloseDisplay destroys the associated
10525 database whereas it has not been created by XGetDefault
10526 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10527 don't destroy the database here in order to avoid the crash
10528 in the above situations for now, though that may cause memory
10529 leaks in other situations. */
10531 #ifdef HAVE_XRMSETDATABASE
10532 XrmSetDatabase (dpyinfo
->display
, NULL
);
10534 dpyinfo
->display
->db
= NULL
;
10536 /* We used to call XrmDestroyDatabase from x_delete_display, but
10537 some older versions of libX11 crash if we call it after
10538 closing all the displays. */
10539 XrmDestroyDatabase (dpyinfo
->xrdb
);
10543 xg_display_close (dpyinfo
->display
);
10545 #ifdef USE_X_TOOLKIT
10546 XtCloseDisplay (dpyinfo
->display
);
10548 XCloseDisplay (dpyinfo
->display
);
10550 #endif /* ! USE_GTK */
10553 /* No more input on this descriptor. */
10554 if (connection
!= -1)
10555 delete_keyboard_wait_descriptor (connection
);
10557 /* Mark as dead. */
10558 dpyinfo
->display
= NULL
;
10559 x_delete_display (dpyinfo
);
10563 /* Create a struct terminal, initialize it with the X11 specific
10564 functions and make DISPLAY->TERMINAL point to it. */
10566 static struct terminal
*
10567 x_create_terminal (struct x_display_info
*dpyinfo
)
10569 struct terminal
*terminal
;
10571 terminal
= create_terminal ();
10573 terminal
->type
= output_x_window
;
10574 terminal
->display_info
.x
= dpyinfo
;
10575 dpyinfo
->terminal
= terminal
;
10577 /* kboard is initialized in x_term_init. */
10579 terminal
->clear_frame_hook
= x_clear_frame
;
10580 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10581 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10582 terminal
->ring_bell_hook
= XTring_bell
;
10583 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10584 terminal
->reset_terminal_modes_hook
= NULL
;
10585 terminal
->set_terminal_modes_hook
= NULL
;
10586 terminal
->update_begin_hook
= x_update_begin
;
10587 terminal
->update_end_hook
= x_update_end
;
10588 terminal
->set_terminal_window_hook
= NULL
;
10589 terminal
->read_socket_hook
= XTread_socket
;
10590 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10591 terminal
->mouse_position_hook
= XTmouse_position
;
10592 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10593 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10594 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10595 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10596 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10597 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10598 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10600 terminal
->delete_frame_hook
= x_destroy_window
;
10601 terminal
->delete_terminal_hook
= x_delete_terminal
;
10603 terminal
->rif
= &x_redisplay_interface
;
10604 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10605 terminal
->char_ins_del_ok
= 1;
10606 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10607 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10608 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10615 x_initialize (void)
10620 last_tool_bar_item
= -1;
10621 any_help_event_p
= 0;
10622 ignore_next_mouse_click_timeout
= 0;
10625 current_count
= -1;
10628 /* Try to use interrupt input; if we can't, then start polling. */
10629 Fset_input_interrupt_mode (Qt
);
10631 #ifdef USE_X_TOOLKIT
10632 XtToolkitInitialize ();
10634 Xt_app_con
= XtCreateApplicationContext ();
10636 /* Register a converter from strings to pixels, which uses
10637 Emacs' color allocation infrastructure. */
10638 XtAppSetTypeConverter (Xt_app_con
,
10639 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10640 cvt_string_to_pixel_args
,
10641 XtNumber (cvt_string_to_pixel_args
),
10642 XtCacheByDisplay
, cvt_pixel_dtor
);
10644 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10647 #ifdef USE_TOOLKIT_SCROLL_BARS
10649 xaw3d_arrow_scroll
= False
;
10650 xaw3d_pick_top
= True
;
10654 pending_autoraise_frame
= 0;
10656 /* Note that there is no real way portable across R3/R4 to get the
10657 original error handler. */
10658 XSetErrorHandler (x_error_handler
);
10659 XSetIOErrorHandler (x_io_error_quitter
);
10664 syms_of_xterm (void)
10666 x_error_message
= NULL
;
10668 staticpro (&x_display_name_list
);
10669 x_display_name_list
= Qnil
;
10671 staticpro (&last_mouse_scroll_bar
);
10672 last_mouse_scroll_bar
= Qnil
;
10674 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
10675 DEFSYM (Qlatin_1
, "latin-1");
10678 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10679 staticpro (&xg_default_icon_file
);
10681 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
10684 DEFVAR_BOOL ("x-use-underline-position-properties",
10685 x_use_underline_position_properties
,
10686 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
10687 A value of nil means ignore them. If you encounter fonts with bogus
10688 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10689 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10690 to override the font's UNDERLINE_POSITION for small font display
10692 x_use_underline_position_properties
= 1;
10694 DEFVAR_BOOL ("x-underline-at-descent-line",
10695 x_underline_at_descent_line
,
10696 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
10697 A value of nil means to draw the underline according to the value of the
10698 variable `x-use-underline-position-properties', which is usually at the
10699 baseline level. The default value is nil. */);
10700 x_underline_at_descent_line
= 0;
10702 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10703 x_mouse_click_focus_ignore_position
,
10704 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10705 This variable is only used when the window manager requires that you
10706 click on a frame to select it (give it focus). In that case, a value
10707 of nil, means that the selected window and cursor position changes to
10708 reflect the mouse click position, while a non-nil value means that the
10709 selected window or cursor position is preserved. */);
10710 x_mouse_click_focus_ignore_position
= 0;
10712 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
10713 doc
: /* Which toolkit scroll bars Emacs uses, if any.
10714 A value of nil means Emacs doesn't use toolkit scroll bars.
10715 With the X Window system, the value is a symbol describing the
10716 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
10717 With MS Windows or Nextstep, the value is t. */);
10718 #ifdef USE_TOOLKIT_SCROLL_BARS
10720 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10721 #elif defined HAVE_XAW3D
10722 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10724 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10726 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10729 Vx_toolkit_scroll_bars
= Qnil
;
10732 staticpro (&last_mouse_motion_frame
);
10733 last_mouse_motion_frame
= Qnil
;
10735 Qmodifier_value
= intern_c_string ("modifier-value");
10736 Qalt
= intern_c_string ("alt");
10737 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10738 Qhyper
= intern_c_string ("hyper");
10739 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10740 Qmeta
= intern_c_string ("meta");
10741 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10742 Qsuper
= intern_c_string ("super");
10743 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10745 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
10746 doc
: /* Which keys Emacs uses for the alt modifier.
10747 This should be one of the symbols `alt', `hyper', `meta', `super'.
10748 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10749 is nil, which is the same as `alt'. */);
10750 Vx_alt_keysym
= Qnil
;
10752 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
10753 doc
: /* Which keys Emacs uses for the hyper modifier.
10754 This should be one of the symbols `alt', `hyper', `meta', `super'.
10755 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10756 default is nil, which is the same as `hyper'. */);
10757 Vx_hyper_keysym
= Qnil
;
10759 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
10760 doc
: /* Which keys Emacs uses for the meta modifier.
10761 This should be one of the symbols `alt', `hyper', `meta', `super'.
10762 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10763 default is nil, which is the same as `meta'. */);
10764 Vx_meta_keysym
= Qnil
;
10766 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
10767 doc
: /* Which keys Emacs uses for the super modifier.
10768 This should be one of the symbols `alt', `hyper', `meta', `super'.
10769 For example, `super' means use the Super_L and Super_R keysyms. The
10770 default is nil, which is the same as `super'. */);
10771 Vx_super_keysym
= Qnil
;
10773 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
10774 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10775 Vx_keysym_table
= make_hash_table (hashtest_eql
, make_number (900),
10776 make_float (DEFAULT_REHASH_SIZE
),
10777 make_float (DEFAULT_REHASH_THRESHOLD
),