1 /* X Communication module for terminals which understand the X protocol.
3 Copyright (C) 1989, 1993-2013 Free Software Foundation, Inc.
5 This file is part of GNU Emacs.
7 GNU Emacs is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU Emacs is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
20 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
21 /* Xt features made by Fred Pierresteguy. */
27 #include "blockinput.h"
28 #include "syssignal.h"
30 /* This may include sys/types.h, and that somehow loses
31 if this is not done before the other system files. */
33 #include <X11/cursorfont.h>
35 /* Load sys/types.h if not already loaded.
36 In some systems loading it twice is suicidal. */
38 #include <sys/types.h>
41 #include <sys/ioctl.h>
48 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
49 /* #include <sys/param.h> */
52 #include "character.h"
55 #include "dispextern.h"
57 #include "termhooks.h"
60 #include "emacs-icon.h"
65 #include "intervals.h"
70 #include "xsettings.h"
72 #include "sysselect.h"
75 #include <X11/Shell.h>
83 #include <X11/Xproto.h>
88 #include "../lwlib/xlwmenu.h"
92 #if !defined (NO_EDITRES)
94 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
95 #endif /* not NO_EDITRES */
97 /* Include toolkit specific headers for the scroll bar widget. */
99 #ifdef USE_TOOLKIT_SCROLL_BARS
100 #if defined USE_MOTIF
101 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
102 #include <Xm/ScrollBar.h>
103 #else /* !USE_MOTIF i.e. use Xaw */
106 #include <X11/Xaw3d/Simple.h>
107 #include <X11/Xaw3d/Scrollbar.h>
108 #include <X11/Xaw3d/ThreeD.h>
109 #else /* !HAVE_XAW3D */
110 #include <X11/Xaw/Simple.h>
111 #include <X11/Xaw/Scrollbar.h>
112 #endif /* !HAVE_XAW3D */
114 #define XtNpickTop "pickTop"
115 #endif /* !XtNpickTop */
116 #endif /* !USE_MOTIF */
117 #endif /* USE_TOOLKIT_SCROLL_BARS */
119 #endif /* USE_X_TOOLKIT */
123 #ifndef XtNinitialState
124 #define XtNinitialState "initialState"
128 #include "bitmaps/gray.xbm"
131 #include <X11/XKBlib.h>
134 /* Default to using XIM if available. */
138 int use_xim
= 0; /* configure --without-xim */
141 /* Non-zero means that a HELP_EVENT has been generated since Emacs
144 static bool any_help_event_p
;
146 /* This is a chain of structures for all the X displays currently in
149 struct x_display_info
*x_display_list
;
151 /* This is a list of cons cells, each of the form (NAME
152 . FONT-LIST-CACHE), one for each element of x_display_list and in
153 the same order. NAME is the name of the frame. FONT-LIST-CACHE
154 records previous values returned by x-list-fonts. */
156 Lisp_Object x_display_name_list
;
158 /* This is a frame waiting to be auto-raised, within XTread_socket. */
160 static struct frame
*pending_autoraise_frame
;
162 /* This is a frame waiting for an event matching mask, within XTread_socket. */
167 } pending_event_wait
;
170 /* The application context for Xt use. */
171 XtAppContext Xt_app_con
;
172 static String Xt_default_resources
[] = {0};
174 /* Non-zero means user is interacting with a toolkit scroll bar. */
176 static int toolkit_scroll_bar_interaction
;
177 #endif /* USE_X_TOOLKIT */
179 /* Non-zero timeout value means ignore next mouse click if it arrives
180 before that timeout elapses (i.e. as part of the same sequence of
181 events resulting from clicking on a frame to select it). */
183 static unsigned long ignore_next_mouse_click_timeout
;
187 Formerly, we used PointerMotionHintMask (in standard_event_mask)
188 so that we would have to call XQueryPointer after each MotionNotify
189 event to ask for another such event. However, this made mouse tracking
190 slow, and there was a bug that made it eventually stop.
192 Simply asking for MotionNotify all the time seems to work better.
194 In order to avoid asking for motion events and then throwing most
195 of them away or busy-polling the server for mouse positions, we ask
196 the server for pointer motion hints. This means that we get only
197 one event per group of mouse movements. "Groups" are delimited by
198 other kinds of events (focus changes and button clicks, for
199 example), or by XQueryPointer calls; when one of these happens, we
200 get another MotionNotify event the next time the mouse moves. This
201 is at least as efficient as getting motion events when mouse
202 tracking is on, and I suspect only negligibly worse when tracking
205 /* Where the mouse was last time we reported a mouse event. */
207 static XRectangle last_mouse_glyph
;
208 static struct frame
*last_mouse_glyph_frame
;
210 /* The scroll bar in which the last X motion event occurred.
212 If the last X motion event occurred in a scroll bar, we set this so
213 XTmouse_position can know whether to report a scroll bar motion or
216 If the last X motion event didn't occur in a scroll bar, we set
217 this to Qnil, to tell XTmouse_position to return an ordinary motion
220 static Lisp_Object last_mouse_scroll_bar
;
222 /* This is a hack. We would really prefer that XTmouse_position would
223 return the time associated with the position it returns, but there
224 doesn't seem to be any way to wrest the time-stamp from the server
225 along with the position query. So, we just keep track of the time
226 of the last movement we received, and return that in hopes that
227 it's somewhat accurate. */
229 static Time last_mouse_movement_time
;
231 /* Incremented by XTread_socket whenever it really tries to read
234 static int volatile input_signal_count
;
236 /* Used locally within XTread_socket. */
238 static int x_noop_count
;
240 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
242 static Lisp_Object Qvendor_specific_keysyms
;
243 static Lisp_Object Qlatin_1
;
246 /* The name of the Emacs icon file. */
247 static Lisp_Object xg_default_icon_file
;
249 /* Used in gtkutil.c. */
250 Lisp_Object Qx_gtk_map_stock
;
253 /* Some functions take this as char *, not const char *. */
254 static char emacs_class
[] = EMACS_CLASS
;
258 XEMBED_MAPPED
= 1 << 0
263 XEMBED_EMBEDDED_NOTIFY
= 0,
264 XEMBED_WINDOW_ACTIVATE
= 1,
265 XEMBED_WINDOW_DEACTIVATE
= 2,
266 XEMBED_REQUEST_FOCUS
= 3,
268 XEMBED_FOCUS_OUT
= 5,
269 XEMBED_FOCUS_NEXT
= 6,
270 XEMBED_FOCUS_PREV
= 7,
272 XEMBED_MODALITY_ON
= 10,
273 XEMBED_MODALITY_OFF
= 11,
274 XEMBED_REGISTER_ACCELERATOR
= 12,
275 XEMBED_UNREGISTER_ACCELERATOR
= 13,
276 XEMBED_ACTIVATE_ACCELERATOR
= 14
279 static bool x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
280 static void x_set_window_size_1 (struct frame
*, int, int, int);
281 static void x_raise_frame (struct frame
*);
282 static void x_lower_frame (struct frame
*);
283 static const XColor
*x_color_cells (Display
*, int *);
284 static int x_io_error_quitter (Display
*);
285 static struct terminal
*x_create_terminal (struct x_display_info
*);
286 void x_delete_terminal (struct terminal
*);
287 static void x_update_end (struct frame
*);
288 static void XTframe_up_to_date (struct frame
*);
289 static void x_clear_frame (struct frame
*);
290 static _Noreturn
void x_ins_del_lines (struct frame
*, int, int);
291 static void frame_highlight (struct frame
*);
292 static void frame_unhighlight (struct frame
*);
293 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
294 static void x_focus_changed (int, int, struct x_display_info
*,
295 struct frame
*, struct input_event
*);
296 static void x_detect_focus_change (struct x_display_info
*,
297 XEvent
*, struct input_event
*);
298 static void XTframe_rehighlight (struct frame
*);
299 static void x_frame_rehighlight (struct x_display_info
*);
300 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
301 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
302 enum text_cursor_kinds
);
304 static void x_clip_to_row (struct window
*, struct glyph_row
*,
305 enum glyph_row_area
, GC
);
306 static void x_flush (struct frame
*f
);
307 static void x_update_begin (struct frame
*);
308 static void x_update_window_begin (struct window
*);
309 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
310 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
311 enum scroll_bar_part
*,
312 Lisp_Object
*, Lisp_Object
*,
314 static int x_handle_net_wm_state (struct frame
*, XPropertyEvent
*);
315 static void x_check_fullscreen (struct frame
*);
316 static void x_check_expected_move (struct frame
*, int, int);
317 static void x_sync_with_move (struct frame
*, int, int, int);
318 static int handle_one_xevent (struct x_display_info
*, XEvent
*,
319 int *, struct input_event
*);
321 static int x_dispatch_event (XEvent
*, Display
*);
323 /* Don't declare this _Noreturn because we want no
324 interference with debugging failing X calls. */
325 static void x_connection_closed (Display
*, const char *);
326 static void x_wm_set_window_state (struct frame
*, int);
327 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
328 static void x_initialize (void);
331 /* Flush display of frame F. */
334 x_flush (struct frame
*f
)
336 eassert (f
&& FRAME_X_P (f
));
337 /* Don't call XFlush when it is not safe to redisplay; the X
338 connection may be broken. */
339 if (!NILP (Vinhibit_redisplay
))
343 XFlush (FRAME_X_DISPLAY (f
));
348 /* Remove calls to XFlush by defining XFlush to an empty replacement.
349 Calls to XFlush should be unnecessary because the X output buffer
350 is flushed automatically as needed by calls to XPending,
351 XNextEvent, or XWindowEvent according to the XFlush man page.
352 XTread_socket calls XPending. Removing XFlush improves
355 #define XFlush(DISPLAY) (void) 0
358 /***********************************************************************
360 ***********************************************************************/
364 /* This is a function useful for recording debugging information about
365 the sequence of occurrences in this file. */
373 struct record event_record
[100];
375 int event_record_index
;
378 record_event (char *locus
, int type
)
380 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
381 event_record_index
= 0;
383 event_record
[event_record_index
].locus
= locus
;
384 event_record
[event_record_index
].type
= type
;
385 event_record_index
++;
392 /* Return the struct x_display_info corresponding to DPY. */
394 struct x_display_info
*
395 x_display_info_for_display (Display
*dpy
)
397 struct x_display_info
*dpyinfo
;
399 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
400 if (dpyinfo
->display
== dpy
)
407 x_find_topmost_parent (struct frame
*f
)
409 struct x_output
*x
= f
->output_data
.x
;
410 Window win
= None
, wi
= x
->parent_desc
;
411 Display
*dpy
= FRAME_X_DISPLAY (f
);
413 while (wi
!= FRAME_DISPLAY_INFO (f
)->root_window
)
417 unsigned int nchildren
;
420 XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
);
427 #define OPAQUE 0xffffffff
430 x_set_frame_alpha (struct frame
*f
)
432 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
433 Display
*dpy
= FRAME_X_DISPLAY (f
);
434 Window win
= FRAME_OUTER_WINDOW (f
);
436 double alpha_min
= 1.0;
440 if (dpyinfo
->x_highlight_frame
== f
)
445 if (FLOATP (Vframe_alpha_lower_limit
))
446 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
447 else if (INTEGERP (Vframe_alpha_lower_limit
))
448 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
452 else if (alpha
> 1.0)
454 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
457 opac
= alpha
* OPAQUE
;
459 x_catch_errors (dpy
);
461 /* If there is a parent from the window manager, put the property there
462 also, to work around broken window managers that fail to do that.
463 Do this unconditionally as this function is called on reparent when
464 alpha has not changed on the frame. */
466 parent
= x_find_topmost_parent (f
);
468 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
469 XA_CARDINAL
, 32, PropModeReplace
,
470 (unsigned char *) &opac
, 1L);
472 /* return unless necessary */
477 unsigned long n
, left
;
479 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
480 0L, 1L, False
, XA_CARDINAL
,
481 &actual
, &format
, &n
, &left
,
484 if (rc
== Success
&& actual
!= None
)
486 unsigned long value
= *(unsigned long *)data
;
496 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
497 XA_CARDINAL
, 32, PropModeReplace
,
498 (unsigned char *) &opac
, 1L);
503 x_display_pixel_height (struct x_display_info
*dpyinfo
)
505 return HeightOfScreen (dpyinfo
->screen
);
509 x_display_pixel_width (struct x_display_info
*dpyinfo
)
511 return WidthOfScreen (dpyinfo
->screen
);
515 /***********************************************************************
516 Starting and ending an update
517 ***********************************************************************/
519 /* Start an update of frame F. This function is installed as a hook
520 for update_begin, i.e. it is called when update_begin is called.
521 This function is called prior to calls to x_update_window_begin for
522 each window being updated. Currently, there is nothing to do here
523 because all interesting stuff is done on a window basis. */
526 x_update_begin (struct frame
*f
)
532 /* Start update of window W. */
535 x_update_window_begin (struct window
*w
)
537 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
538 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
540 w
->output_cursor
= w
->cursor
;
544 if (f
== hlinfo
->mouse_face_mouse_frame
)
546 /* Don't do highlighting for mouse motion during the update. */
547 hlinfo
->mouse_face_defer
= 1;
549 /* If F needs to be redrawn, simply forget about any prior mouse
551 if (FRAME_GARBAGED_P (f
))
552 hlinfo
->mouse_face_window
= Qnil
;
559 /* Draw a vertical window border from (x,y0) to (x,y1) */
562 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
564 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
567 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
569 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
572 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
573 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
576 /* End update of window W.
578 Draw vertical borders between horizontally adjacent windows, and
579 display W's cursor if CURSOR_ON_P is non-zero.
581 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
582 glyphs in mouse-face were overwritten. In that case we have to
583 make sure that the mouse-highlight is properly redrawn.
585 W may be a menu bar pseudo-window in case we don't have X toolkit
586 support. Such windows don't have a cursor, so don't display it
590 x_update_window_end (struct window
*w
, bool cursor_on_p
,
591 bool mouse_face_overwritten_p
)
593 if (!w
->pseudo_window_p
)
598 display_and_set_cursor (w
, 1,
599 w
->output_cursor
.hpos
, w
->output_cursor
.vpos
,
600 w
->output_cursor
.x
, w
->output_cursor
.y
);
602 if (draw_window_fringes (w
, 1))
603 x_draw_vertical_border (w
);
608 /* If a row with mouse-face was overwritten, arrange for
609 XTframe_up_to_date to redisplay the mouse highlight. */
610 if (mouse_face_overwritten_p
)
611 reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w
->frame
)));
615 /* End update of frame F. This function is installed as a hook in
619 x_update_end (struct frame
*f
)
621 /* Mouse highlight may be displayed again. */
622 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
626 XFlush (FRAME_X_DISPLAY (f
));
632 /* This function is called from various places in xdisp.c
633 whenever a complete update has been performed. */
636 XTframe_up_to_date (struct frame
*f
)
639 FRAME_MOUSE_UPDATE (f
);
643 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
644 arrow bitmaps, or clear the fringes if no bitmaps are required
645 before DESIRED_ROW is made current. This function is called from
646 update_window_line only if it is known that there are differences
647 between bitmaps to be drawn between current row and DESIRED_ROW. */
650 x_after_update_window_line (struct window
*w
, struct glyph_row
*desired_row
)
657 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
658 desired_row
->redraw_fringe_bitmaps_p
= 1;
660 /* When a window has disappeared, make sure that no rest of
661 full-width rows stays visible in the internal border. Could
662 check here if updated window is the leftmost/rightmost window,
663 but I guess it's not worth doing since vertically split windows
664 are almost never used, internal border is rarely set, and the
665 overhead is very small. */
666 if (windows_or_buffers_changed
667 && desired_row
->full_width_p
668 && (f
= XFRAME (w
->frame
),
669 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
671 && (height
= desired_row
->visible_height
,
674 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
677 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
678 0, y
, width
, height
);
679 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
680 FRAME_PIXEL_WIDTH (f
) - width
,
687 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
689 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
690 Display
*display
= FRAME_X_DISPLAY (f
);
691 Window window
= FRAME_X_WINDOW (f
);
692 GC gc
= f
->output_data
.x
->normal_gc
;
693 struct face
*face
= p
->face
;
695 /* Must clip because of partially visible lines. */
696 x_clip_to_row (w
, row
, ANY_AREA
, gc
);
700 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
702 /* In case the same realized face is used for fringes and
703 for something displayed in the text (e.g. face `region' on
704 mono-displays, the fill style may have been changed to
705 FillSolid in x_draw_glyph_string_background. */
707 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
709 XSetForeground (display
, face
->gc
, face
->background
);
711 #ifdef USE_TOOLKIT_SCROLL_BARS
712 /* If the fringe is adjacent to the left (right) scroll bar of a
713 leftmost (rightmost, respectively) window, then extend its
714 background to the gap between the fringe and the bar. */
715 if ((WINDOW_LEFTMOST_P (w
)
716 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
717 || (WINDOW_RIGHTMOST_P (w
)
718 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
720 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
724 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
725 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
726 * FRAME_COLUMN_WIDTH (f
));
730 /* Bitmap fills the fringe. */
731 if (bar_area_x
+ bar_area_width
== p
->x
)
732 bx
= bar_area_x
+ sb_width
;
733 else if (p
->x
+ p
->wd
== bar_area_x
)
737 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
739 nx
= bar_area_width
- sb_width
;
740 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
742 ny
= row
->visible_height
;
747 if (bar_area_x
+ bar_area_width
== bx
)
749 bx
= bar_area_x
+ sb_width
;
750 nx
+= bar_area_width
- sb_width
;
752 else if (bx
+ nx
== bar_area_x
)
753 nx
+= bar_area_width
- sb_width
;
758 if (bx
>= 0 && nx
> 0)
759 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
762 XSetForeground (display
, face
->gc
, face
->foreground
);
768 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
769 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
773 bits
= (char *) (p
->bits
+ p
->dh
);
775 bits
= (char *) p
->bits
+ p
->dh
;
777 /* Draw the bitmap. I believe these small pixmaps can be cached
779 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
781 ? (p
->overlay_p
? face
->background
782 : f
->output_data
.x
->cursor_pixel
)
784 face
->background
, depth
);
788 clipmask
= XCreatePixmapFromBitmapData (display
,
789 FRAME_DISPLAY_INFO (f
)->root_window
,
792 gcv
.clip_mask
= clipmask
;
793 gcv
.clip_x_origin
= p
->x
;
794 gcv
.clip_y_origin
= p
->y
;
795 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
798 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
799 p
->wd
, p
->h
, p
->x
, p
->y
);
800 XFreePixmap (display
, pixmap
);
804 gcv
.clip_mask
= (Pixmap
) 0;
805 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
806 XFreePixmap (display
, clipmask
);
810 XSetClipMask (display
, gc
, None
);
813 /***********************************************************************
815 ***********************************************************************/
819 static void x_set_glyph_string_clipping (struct glyph_string
*);
820 static void x_set_glyph_string_gc (struct glyph_string
*);
821 static void x_draw_glyph_string_foreground (struct glyph_string
*);
822 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
823 static void x_draw_glyph_string_box (struct glyph_string
*);
824 static void x_draw_glyph_string (struct glyph_string
*);
825 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
826 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
827 static void x_set_cursor_gc (struct glyph_string
*);
828 static void x_set_mode_line_face_gc (struct glyph_string
*);
829 static void x_set_mouse_face_gc (struct glyph_string
*);
830 static bool x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
831 unsigned long *, double, int);
832 static void x_setup_relief_color (struct frame
*, struct relief
*,
833 double, int, unsigned long);
834 static void x_setup_relief_colors (struct glyph_string
*);
835 static void x_draw_image_glyph_string (struct glyph_string
*);
836 static void x_draw_image_relief (struct glyph_string
*);
837 static void x_draw_image_foreground (struct glyph_string
*);
838 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
839 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
841 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
842 int, int, int, int, int, int,
844 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
845 int, int, int, XRectangle
*);
846 static void x_scroll_bar_clear (struct frame
*);
849 static void x_check_font (struct frame
*, struct font
*);
853 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
857 x_set_cursor_gc (struct glyph_string
*s
)
859 if (s
->font
== FRAME_FONT (s
->f
)
860 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
861 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
863 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
866 /* Cursor on non-default face: must merge. */
870 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
871 xgcv
.foreground
= s
->face
->background
;
873 /* If the glyph would be invisible, try a different foreground. */
874 if (xgcv
.foreground
== xgcv
.background
)
875 xgcv
.foreground
= s
->face
->foreground
;
876 if (xgcv
.foreground
== xgcv
.background
)
877 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
878 if (xgcv
.foreground
== xgcv
.background
)
879 xgcv
.foreground
= s
->face
->foreground
;
881 /* Make sure the cursor is distinct from text in this face. */
882 if (xgcv
.background
== s
->face
->background
883 && xgcv
.foreground
== s
->face
->foreground
)
885 xgcv
.background
= s
->face
->foreground
;
886 xgcv
.foreground
= s
->face
->background
;
889 IF_DEBUG (x_check_font (s
->f
, s
->font
));
890 xgcv
.graphics_exposures
= False
;
891 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
893 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
894 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
897 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
898 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
900 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
905 /* Set up S->gc of glyph string S for drawing text in mouse face. */
908 x_set_mouse_face_gc (struct glyph_string
*s
)
913 /* What face has to be used last for the mouse face? */
914 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
915 face
= FACE_FROM_ID (s
->f
, face_id
);
917 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
919 if (s
->first_glyph
->type
== CHAR_GLYPH
)
920 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
922 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
923 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
924 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
926 if (s
->font
== s
->face
->font
)
930 /* Otherwise construct scratch_cursor_gc with values from FACE
935 xgcv
.background
= s
->face
->background
;
936 xgcv
.foreground
= s
->face
->foreground
;
937 xgcv
.graphics_exposures
= False
;
938 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
940 if (FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
941 XChangeGC (s
->display
, FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
944 FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
945 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
947 s
->gc
= FRAME_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
950 eassert (s
->gc
!= 0);
954 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
955 Faces to use in the mode line have already been computed when the
956 matrix was built, so there isn't much to do, here. */
959 x_set_mode_line_face_gc (struct glyph_string
*s
)
965 /* Set S->gc of glyph string S for drawing that glyph string. Set
966 S->stippled_p to a non-zero value if the face of S has a stipple
970 x_set_glyph_string_gc (struct glyph_string
*s
)
972 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
974 if (s
->hl
== DRAW_NORMAL_TEXT
)
977 s
->stippled_p
= s
->face
->stipple
!= 0;
979 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
981 x_set_mode_line_face_gc (s
);
982 s
->stippled_p
= s
->face
->stipple
!= 0;
984 else if (s
->hl
== DRAW_CURSOR
)
989 else if (s
->hl
== DRAW_MOUSE_FACE
)
991 x_set_mouse_face_gc (s
);
992 s
->stippled_p
= s
->face
->stipple
!= 0;
994 else if (s
->hl
== DRAW_IMAGE_RAISED
995 || s
->hl
== DRAW_IMAGE_SUNKEN
)
998 s
->stippled_p
= s
->face
->stipple
!= 0;
1002 s
->gc
= s
->face
->gc
;
1003 s
->stippled_p
= s
->face
->stipple
!= 0;
1006 /* GC must have been set. */
1007 eassert (s
->gc
!= 0);
1011 /* Set clipping for output of glyph string S. S may be part of a mode
1012 line or menu if we don't have X toolkit support. */
1015 x_set_glyph_string_clipping (struct glyph_string
*s
)
1017 XRectangle
*r
= s
->clip
;
1018 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1021 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1026 /* Set SRC's clipping for output of glyph string DST. This is called
1027 when we are drawing DST's left_overhang or right_overhang only in
1031 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1036 r
.width
= src
->width
;
1038 r
.height
= src
->height
;
1041 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1046 Compute left and right overhang of glyph string S. */
1049 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1052 && (s
->first_glyph
->type
== CHAR_GLYPH
1053 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1055 struct font_metrics metrics
;
1057 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1059 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1060 struct font
*font
= s
->font
;
1063 for (i
= 0; i
< s
->nchars
; i
++)
1064 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1065 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1069 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1071 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1073 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1074 ? metrics
.rbearing
- metrics
.width
: 0);
1075 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1079 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1080 s
->left_overhang
= - s
->cmp
->lbearing
;
1085 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1088 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1091 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1092 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1093 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1094 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1098 /* Draw the background of glyph_string S. If S->background_filled_p
1099 is non-zero don't draw it. FORCE_P non-zero means draw the
1100 background even if it wouldn't be drawn normally. This is used
1101 when a string preceding S draws into the background of S, or S
1102 contains the first component of a composition. */
1105 x_draw_glyph_string_background (struct glyph_string
*s
, bool force_p
)
1107 /* Nothing to do if background has already been drawn or if it
1108 shouldn't be drawn in the first place. */
1109 if (!s
->background_filled_p
)
1111 int box_line_width
= max (s
->face
->box_line_width
, 0);
1115 /* Fill background with a stipple pattern. */
1116 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1117 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1118 s
->y
+ box_line_width
,
1119 s
->background_width
,
1120 s
->height
- 2 * box_line_width
);
1121 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1122 s
->background_filled_p
= 1;
1124 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1125 || s
->font_not_found_p
1126 || s
->extends_to_end_of_line_p
1129 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1130 s
->background_width
,
1131 s
->height
- 2 * box_line_width
);
1132 s
->background_filled_p
= 1;
1138 /* Draw the foreground of glyph string S. */
1141 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1145 /* If first glyph of S has a left box line, start drawing the text
1146 of S to the right of that box line. */
1147 if (s
->face
->box
!= FACE_NO_BOX
1148 && s
->first_glyph
->left_box_line_p
)
1149 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1153 /* Draw characters of S as rectangles if S's font could not be
1155 if (s
->font_not_found_p
)
1157 for (i
= 0; i
< s
->nchars
; ++i
)
1159 struct glyph
*g
= s
->first_glyph
+ i
;
1160 XDrawRectangle (s
->display
, s
->window
,
1161 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1163 x
+= g
->pixel_width
;
1168 struct font
*font
= s
->font
;
1169 int boff
= font
->baseline_offset
;
1172 if (font
->vertical_centering
)
1173 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1175 y
= s
->ybase
- boff
;
1177 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1178 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1180 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1181 if (s
->face
->overstrike
)
1182 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1186 /* Draw the foreground of composite glyph string S. */
1189 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1192 struct font
*font
= s
->font
;
1194 /* If first glyph of S has a left box line, start drawing the text
1195 of S to the right of that box line. */
1196 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1197 && s
->first_glyph
->left_box_line_p
)
1198 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1202 /* S is a glyph string for a composition. S->cmp_from is the index
1203 of the first character drawn for glyphs of this composition.
1204 S->cmp_from == 0 means we are drawing the very first character of
1205 this composition. */
1207 /* Draw a rectangle for the composition if the font for the very
1208 first character of the composition could not be loaded. */
1209 if (s
->font_not_found_p
)
1211 if (s
->cmp_from
== 0)
1212 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1213 s
->width
- 1, s
->height
- 1);
1215 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1219 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1220 /* TAB in a composition means display glyphs with padding
1221 space on the left or right. */
1222 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1224 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1225 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1227 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1228 if (s
->face
->overstrike
)
1229 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1234 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1239 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1241 glyph
= LGSTRING_GLYPH (gstring
, i
);
1242 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1243 width
+= LGLYPH_WIDTH (glyph
);
1246 int xoff
, yoff
, wadjust
;
1250 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1251 if (s
->face
->overstrike
)
1252 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1255 xoff
= LGLYPH_XOFF (glyph
);
1256 yoff
= LGLYPH_YOFF (glyph
);
1257 wadjust
= LGLYPH_WADJUST (glyph
);
1258 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1259 if (s
->face
->overstrike
)
1260 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1268 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1269 if (s
->face
->overstrike
)
1270 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1276 /* Draw the foreground of glyph string S for glyphless characters. */
1279 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1281 struct glyph
*glyph
= s
->first_glyph
;
1285 /* If first glyph of S has a left box line, start drawing the text
1286 of S to the right of that box line. */
1287 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1288 && s
->first_glyph
->left_box_line_p
)
1289 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1295 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1297 char buf
[7], *str
= NULL
;
1298 int len
= glyph
->u
.glyphless
.len
;
1300 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1303 && CHAR_TABLE_P (Vglyphless_char_display
)
1304 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1308 = (! glyph
->u
.glyphless
.for_no_font
1309 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1310 glyph
->u
.glyphless
.ch
)
1311 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1312 if (STRINGP (acronym
))
1313 str
= SSDATA (acronym
);
1316 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1318 sprintf (buf
, "%0*X",
1319 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1320 glyph
->u
.glyphless
.ch
);
1326 int upper_len
= (len
+ 1) / 2;
1329 /* It is assured that all LEN characters in STR is ASCII. */
1330 for (j
= 0; j
< len
; j
++)
1332 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1333 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1335 s
->font
->driver
->draw (s
, 0, upper_len
,
1336 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1337 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1339 s
->font
->driver
->draw (s
, upper_len
, len
,
1340 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1341 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1344 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1345 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
1346 x
, s
->ybase
- glyph
->ascent
,
1347 glyph
->pixel_width
- 1,
1348 glyph
->ascent
+ glyph
->descent
- 1);
1349 x
+= glyph
->pixel_width
;
1353 #ifdef USE_X_TOOLKIT
1357 /* Return the frame on which widget WIDGET is used.. Abort if frame
1358 cannot be determined. */
1360 static struct frame
*
1361 x_frame_of_widget (Widget widget
)
1363 struct x_display_info
*dpyinfo
;
1364 Lisp_Object tail
, frame
;
1367 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1369 /* Find the top-level shell of the widget. Note that this function
1370 can be called when the widget is not yet realized, so XtWindow
1371 (widget) == 0. That's the reason we can't simply use
1372 x_any_window_to_frame. */
1373 while (!XtIsTopLevelShell (widget
))
1374 widget
= XtParent (widget
);
1376 /* Look for a frame with that top-level widget. Allocate the color
1377 on that frame to get the right gamma correction value. */
1378 FOR_EACH_FRAME (tail
, frame
)
1382 && f
->output_data
.nothing
!= 1
1383 && FRAME_DISPLAY_INFO (f
) == dpyinfo
1384 && f
->output_data
.x
->widget
== widget
)
1390 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1391 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1392 If this produces the same color as PIXEL, try a color where all RGB
1393 values have DELTA added. Return the allocated color in *PIXEL.
1394 DISPLAY is the X display, CMAP is the colormap to operate on.
1395 Value is true if successful. */
1398 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1399 unsigned long *pixel
, double factor
, int delta
)
1401 struct frame
*f
= x_frame_of_widget (widget
);
1402 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1405 #endif /* USE_LUCID */
1408 /* Structure specifying which arguments should be passed by Xt to
1409 cvt_string_to_pixel. We want the widget's screen and colormap. */
1411 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1413 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1415 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1420 /* The address of this variable is returned by
1421 cvt_string_to_pixel. */
1423 static Pixel cvt_string_to_pixel_value
;
1426 /* Convert a color name to a pixel color.
1428 DPY is the display we are working on.
1430 ARGS is an array of *NARGS XrmValue structures holding additional
1431 information about the widget for which the conversion takes place.
1432 The contents of this array are determined by the specification
1433 in cvt_string_to_pixel_args.
1435 FROM is a pointer to an XrmValue which points to the color name to
1436 convert. TO is an XrmValue in which to return the pixel color.
1438 CLOSURE_RET is a pointer to user-data, in which we record if
1439 we allocated the color or not.
1441 Value is True if successful, False otherwise. */
1444 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1445 XrmValue
*from
, XrmValue
*to
,
1446 XtPointer
*closure_ret
)
1456 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1457 "wrongParameters", "cvt_string_to_pixel",
1459 "Screen and colormap args required", NULL
, NULL
);
1463 screen
= *(Screen
**) args
[0].addr
;
1464 cmap
= *(Colormap
*) args
[1].addr
;
1465 color_name
= (String
) from
->addr
;
1467 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1469 *closure_ret
= (XtPointer
) False
;
1470 pixel
= WhitePixelOfScreen (screen
);
1472 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1474 *closure_ret
= (XtPointer
) False
;
1475 pixel
= BlackPixelOfScreen (screen
);
1477 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1478 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1480 pixel
= color
.pixel
;
1481 *closure_ret
= (XtPointer
) True
;
1486 Cardinal nparams
= 1;
1488 params
[0] = color_name
;
1489 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1490 "badValue", "cvt_string_to_pixel",
1491 "XtToolkitError", "Invalid color `%s'",
1496 if (to
->addr
!= NULL
)
1498 if (to
->size
< sizeof (Pixel
))
1500 to
->size
= sizeof (Pixel
);
1504 *(Pixel
*) to
->addr
= pixel
;
1508 cvt_string_to_pixel_value
= pixel
;
1509 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1512 to
->size
= sizeof (Pixel
);
1517 /* Free a pixel color which was previously allocated via
1518 cvt_string_to_pixel. This is registered as the destructor
1519 for this type of resource via XtSetTypeConverter.
1521 APP is the application context in which we work.
1523 TO is a pointer to an XrmValue holding the color to free.
1524 CLOSURE is the value we stored in CLOSURE_RET for this color
1525 in cvt_string_to_pixel.
1527 ARGS and NARGS are like for cvt_string_to_pixel. */
1530 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1535 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1537 "Screen and colormap arguments required",
1540 else if (closure
!= NULL
)
1542 /* We did allocate the pixel, so free it. */
1543 Screen
*screen
= *(Screen
**) args
[0].addr
;
1544 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1545 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1546 (Pixel
*) to
->addr
, 1);
1551 #endif /* USE_X_TOOLKIT */
1554 /* Value is an array of XColor structures for the contents of the
1555 color map of display DPY. Set *NCELLS to the size of the array.
1556 Note that this probably shouldn't be called for large color maps,
1557 say a 24-bit TrueColor map. */
1559 static const XColor
*
1560 x_color_cells (Display
*dpy
, int *ncells
)
1562 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1564 if (dpyinfo
->color_cells
== NULL
)
1566 Screen
*screen
= dpyinfo
->screen
;
1567 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1570 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
1571 sizeof *dpyinfo
->color_cells
);
1572 dpyinfo
->ncolor_cells
= ncolor_cells
;
1574 for (i
= 0; i
< ncolor_cells
; ++i
)
1575 dpyinfo
->color_cells
[i
].pixel
= i
;
1577 XQueryColors (dpy
, dpyinfo
->cmap
,
1578 dpyinfo
->color_cells
, ncolor_cells
);
1581 *ncells
= dpyinfo
->ncolor_cells
;
1582 return dpyinfo
->color_cells
;
1586 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1587 colors in COLORS. Use cached information, if available. */
1590 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1592 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1594 if (dpyinfo
->color_cells
)
1597 for (i
= 0; i
< ncolors
; ++i
)
1599 unsigned long pixel
= colors
[i
].pixel
;
1600 eassert (pixel
< dpyinfo
->ncolor_cells
);
1601 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1602 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1606 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1610 /* On frame F, translate pixel color to RGB values for the color in
1611 COLOR. Use cached information, if available. */
1614 x_query_color (struct frame
*f
, XColor
*color
)
1616 x_query_colors (f
, color
, 1);
1620 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1621 exact match can't be allocated, try the nearest color available.
1622 Value is true if successful. Set *COLOR to the color
1626 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1630 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1633 /* If we got to this point, the colormap is full, so we're going
1634 to try to get the next closest color. The algorithm used is
1635 a least-squares matching, which is what X uses for closest
1636 color matching with StaticColor visuals. */
1638 int max_color_delta
= 255;
1639 int max_delta
= 3 * max_color_delta
;
1640 int nearest_delta
= max_delta
+ 1;
1642 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1644 for (nearest
= i
= 0; i
< ncells
; ++i
)
1646 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1647 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1648 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1649 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1651 if (delta
< nearest_delta
)
1654 nearest_delta
= delta
;
1658 color
->red
= cells
[nearest
].red
;
1659 color
->green
= cells
[nearest
].green
;
1660 color
->blue
= cells
[nearest
].blue
;
1661 rc
= XAllocColor (dpy
, cmap
, color
) != 0;
1665 /* If allocation succeeded, and the allocated pixel color is not
1666 equal to a cached pixel color recorded earlier, there was a
1667 change in the colormap, so clear the color cache. */
1668 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1669 XColor
*cached_color
;
1671 if (dpyinfo
->color_cells
1672 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1673 (cached_color
->red
!= color
->red
1674 || cached_color
->blue
!= color
->blue
1675 || cached_color
->green
!= color
->green
)))
1677 xfree (dpyinfo
->color_cells
);
1678 dpyinfo
->color_cells
= NULL
;
1679 dpyinfo
->ncolor_cells
= 0;
1683 #ifdef DEBUG_X_COLORS
1685 register_color (color
->pixel
);
1686 #endif /* DEBUG_X_COLORS */
1692 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1693 exact match can't be allocated, try the nearest color available.
1694 Value is true if successful. Set *COLOR to the color
1698 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1700 gamma_correct (f
, color
);
1701 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1705 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1706 It's necessary to do this instead of just using PIXEL directly to
1707 get color reference counts right. */
1710 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1714 color
.pixel
= pixel
;
1716 x_query_color (f
, &color
);
1717 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1719 #ifdef DEBUG_X_COLORS
1720 register_color (pixel
);
1726 /* Brightness beyond which a color won't have its highlight brightness
1729 Nominally, highlight colors for `3d' faces are calculated by
1730 brightening an object's color by a constant scale factor, but this
1731 doesn't yield good results for dark colors, so for colors who's
1732 brightness is less than this value (on a scale of 0-65535) have an
1733 use an additional additive factor.
1735 The value here is set so that the default menu-bar/mode-line color
1736 (grey75) will not have its highlights changed at all. */
1737 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1740 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1741 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1742 If this produces the same color as PIXEL, try a color where all RGB
1743 values have DELTA added. Return the allocated color in *PIXEL.
1744 DISPLAY is the X display, CMAP is the colormap to operate on.
1745 Value is non-zero if successful. */
1748 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1754 /* Get RGB color values. */
1755 color
.pixel
= *pixel
;
1756 x_query_color (f
, &color
);
1758 /* Change RGB values by specified FACTOR. Avoid overflow! */
1759 eassert (factor
>= 0);
1760 new.red
= min (0xffff, factor
* color
.red
);
1761 new.green
= min (0xffff, factor
* color
.green
);
1762 new.blue
= min (0xffff, factor
* color
.blue
);
1764 /* Calculate brightness of COLOR. */
1765 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1767 /* We only boost colors that are darker than
1768 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1769 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1770 /* Make an additive adjustment to NEW, because it's dark enough so
1771 that scaling by FACTOR alone isn't enough. */
1773 /* How far below the limit this color is (0 - 1, 1 being darker). */
1774 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1775 /* The additive adjustment. */
1776 int min_delta
= delta
* dimness
* factor
/ 2;
1780 new.red
= max (0, new.red
- min_delta
);
1781 new.green
= max (0, new.green
- min_delta
);
1782 new.blue
= max (0, new.blue
- min_delta
);
1786 new.red
= min (0xffff, min_delta
+ new.red
);
1787 new.green
= min (0xffff, min_delta
+ new.green
);
1788 new.blue
= min (0xffff, min_delta
+ new.blue
);
1792 /* Try to allocate the color. */
1793 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1796 if (new.pixel
== *pixel
)
1798 /* If we end up with the same color as before, try adding
1799 delta to the RGB values. */
1800 x_free_colors (f
, &new.pixel
, 1);
1802 new.red
= min (0xffff, delta
+ color
.red
);
1803 new.green
= min (0xffff, delta
+ color
.green
);
1804 new.blue
= min (0xffff, delta
+ color
.blue
);
1805 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1816 /* Set up the foreground color for drawing relief lines of glyph
1817 string S. RELIEF is a pointer to a struct relief containing the GC
1818 with which lines will be drawn. Use a color that is FACTOR or
1819 DELTA lighter or darker than the relief's background which is found
1820 in S->f->output_data.x->relief_background. If such a color cannot
1821 be allocated, use DEFAULT_PIXEL, instead. */
1824 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1827 struct x_output
*di
= f
->output_data
.x
;
1828 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1829 unsigned long pixel
;
1830 unsigned long background
= di
->relief_background
;
1831 Colormap cmap
= FRAME_X_COLORMAP (f
);
1832 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
1833 Display
*dpy
= FRAME_X_DISPLAY (f
);
1835 xgcv
.graphics_exposures
= False
;
1836 xgcv
.line_width
= 1;
1838 /* Free previously allocated color. The color cell will be reused
1839 when it has been freed as many times as it was allocated, so this
1840 doesn't affect faces using the same colors. */
1842 && relief
->allocated_p
)
1844 x_free_colors (f
, &relief
->pixel
, 1);
1845 relief
->allocated_p
= 0;
1848 /* Allocate new color. */
1849 xgcv
.foreground
= default_pixel
;
1851 if (dpyinfo
->n_planes
!= 1
1852 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1854 relief
->allocated_p
= 1;
1855 xgcv
.foreground
= relief
->pixel
= pixel
;
1858 if (relief
->gc
== 0)
1860 xgcv
.stipple
= dpyinfo
->gray
;
1862 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1865 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1869 /* Set up colors for the relief lines around glyph string S. */
1872 x_setup_relief_colors (struct glyph_string
*s
)
1874 struct x_output
*di
= s
->f
->output_data
.x
;
1875 unsigned long color
;
1877 if (s
->face
->use_box_color_for_shadows_p
)
1878 color
= s
->face
->box_color
;
1879 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1881 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1882 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1887 /* Get the background color of the face. */
1888 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1889 color
= xgcv
.background
;
1892 if (di
->white_relief
.gc
== 0
1893 || color
!= di
->relief_background
)
1895 di
->relief_background
= color
;
1896 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1897 WHITE_PIX_DEFAULT (s
->f
));
1898 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1899 BLACK_PIX_DEFAULT (s
->f
));
1904 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1905 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1906 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1907 relief. LEFT_P non-zero means draw a relief on the left side of
1908 the rectangle. RIGHT_P non-zero means draw a relief on the right
1909 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1913 x_draw_relief_rect (struct frame
*f
,
1914 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1915 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1916 XRectangle
*clip_rect
)
1918 Display
*dpy
= FRAME_X_DISPLAY (f
);
1919 Window window
= FRAME_X_WINDOW (f
);
1924 gc
= f
->output_data
.x
->white_relief
.gc
;
1926 gc
= f
->output_data
.x
->black_relief
.gc
;
1927 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1929 /* This code is more complicated than it has to be, because of two
1930 minor hacks to make the boxes look nicer: (i) if width > 1, draw
1931 the outermost line using the black relief. (ii) Omit the four
1938 XDrawLine (dpy
, window
, gc
,
1939 left_x
+ (left_p
? 1 : 0), top_y
,
1940 right_x
+ (right_p
? 0 : 1), top_y
);
1942 for (i
= 1; i
< width
; ++i
)
1943 XDrawLine (dpy
, window
, gc
,
1944 left_x
+ i
* left_p
, top_y
+ i
,
1945 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1952 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1954 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
1955 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
1957 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
1958 XDrawLine (dpy
, window
, gc
,
1959 left_x
+ i
, top_y
+ (i
+ 1) * top_p
,
1960 left_x
+ i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
1963 XSetClipMask (dpy
, gc
, None
);
1965 gc
= f
->output_data
.x
->black_relief
.gc
;
1967 gc
= f
->output_data
.x
->white_relief
.gc
;
1968 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1972 /* Outermost top line. */
1974 XDrawLine (dpy
, window
, gc
,
1975 left_x
+ (left_p
? 1 : 0), top_y
,
1976 right_x
+ (right_p
? 0 : 1), top_y
);
1978 /* Outermost left line. */
1980 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
1986 XDrawLine (dpy
, window
, gc
,
1987 left_x
+ (left_p
? 1 : 0), bottom_y
,
1988 right_x
+ (right_p
? 0 : 1), bottom_y
);
1989 for (i
= 1; i
< width
; ++i
)
1990 XDrawLine (dpy
, window
, gc
,
1991 left_x
+ i
* left_p
, bottom_y
- i
,
1992 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
1998 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
1999 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
2000 for (i
= 0; i
< width
; ++i
)
2001 XDrawLine (dpy
, window
, gc
,
2002 right_x
- i
, top_y
+ (i
+ 1) * top_p
,
2003 right_x
- i
, bottom_y
+ 1 - (i
+ 1) * bot_p
);
2006 XSetClipMask (dpy
, gc
, None
);
2010 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2011 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2012 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2013 left side of the rectangle. RIGHT_P non-zero means draw a line
2014 on the right side of the rectangle. CLIP_RECT is the clipping
2015 rectangle to use when drawing. */
2018 x_draw_box_rect (struct glyph_string
*s
,
2019 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2020 int left_p
, int right_p
, XRectangle
*clip_rect
)
2024 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2025 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2026 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2029 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2030 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2034 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2035 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2038 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2039 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2043 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2044 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2046 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2047 XSetClipMask (s
->display
, s
->gc
, None
);
2051 /* Draw a box around glyph string S. */
2054 x_draw_glyph_string_box (struct glyph_string
*s
)
2056 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2057 int left_p
, right_p
;
2058 struct glyph
*last_glyph
;
2059 XRectangle clip_rect
;
2061 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2062 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2063 : window_box_right (s
->w
, s
->area
));
2065 /* The glyph that may have a right box line. */
2066 last_glyph
= (s
->cmp
|| s
->img
2068 : s
->first_glyph
+ s
->nchars
- 1);
2070 width
= eabs (s
->face
->box_line_width
);
2071 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2073 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2075 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2077 bottom_y
= top_y
+ s
->height
- 1;
2079 left_p
= (s
->first_glyph
->left_box_line_p
2080 || (s
->hl
== DRAW_MOUSE_FACE
2082 || s
->prev
->hl
!= s
->hl
)));
2083 right_p
= (last_glyph
->right_box_line_p
2084 || (s
->hl
== DRAW_MOUSE_FACE
2086 || s
->next
->hl
!= s
->hl
)));
2088 get_glyph_string_clip_rect (s
, &clip_rect
);
2090 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2091 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2092 left_p
, right_p
, &clip_rect
);
2095 x_setup_relief_colors (s
);
2096 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2097 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2102 /* Draw foreground of image glyph string S. */
2105 x_draw_image_foreground (struct glyph_string
*s
)
2108 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2110 /* If first glyph of S has a left box line, start drawing it to the
2111 right of that line. */
2112 if (s
->face
->box
!= FACE_NO_BOX
2113 && s
->first_glyph
->left_box_line_p
2115 x
+= eabs (s
->face
->box_line_width
);
2117 /* If there is a margin around the image, adjust x- and y-position
2119 if (s
->slice
.x
== 0)
2120 x
+= s
->img
->hmargin
;
2121 if (s
->slice
.y
== 0)
2122 y
+= s
->img
->vmargin
;
2128 /* We can't set both a clip mask and use XSetClipRectangles
2129 because the latter also sets a clip mask. We also can't
2130 trust on the shape extension to be available
2131 (XShapeCombineRegion). So, compute the rectangle to draw
2133 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2136 XRectangle clip_rect
, image_rect
, r
;
2138 xgcv
.clip_mask
= s
->img
->mask
;
2139 xgcv
.clip_x_origin
= x
;
2140 xgcv
.clip_y_origin
= y
;
2141 xgcv
.function
= GXcopy
;
2142 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2144 get_glyph_string_clip_rect (s
, &clip_rect
);
2147 image_rect
.width
= s
->slice
.width
;
2148 image_rect
.height
= s
->slice
.height
;
2149 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2150 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2151 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2152 r
.width
, r
.height
, r
.x
, r
.y
);
2156 XRectangle clip_rect
, image_rect
, r
;
2158 get_glyph_string_clip_rect (s
, &clip_rect
);
2161 image_rect
.width
= s
->slice
.width
;
2162 image_rect
.height
= s
->slice
.height
;
2163 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2164 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2165 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2166 r
.width
, r
.height
, r
.x
, r
.y
);
2168 /* When the image has a mask, we can expect that at
2169 least part of a mouse highlight or a block cursor will
2170 be visible. If the image doesn't have a mask, make
2171 a block cursor visible by drawing a rectangle around
2172 the image. I believe it's looking better if we do
2173 nothing here for mouse-face. */
2174 if (s
->hl
== DRAW_CURSOR
)
2176 int relief
= eabs (s
->img
->relief
);
2177 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2178 x
- relief
, y
- relief
,
2179 s
->slice
.width
+ relief
*2 - 1,
2180 s
->slice
.height
+ relief
*2 - 1);
2185 /* Draw a rectangle if image could not be loaded. */
2186 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2187 s
->slice
.width
- 1, s
->slice
.height
- 1);
2191 /* Draw a relief around the image glyph string S. */
2194 x_draw_image_relief (struct glyph_string
*s
)
2196 int x1
, y1
, thick
, raised_p
, top_p
, bot_p
, left_p
, right_p
;
2199 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2201 /* If first glyph of S has a left box line, start drawing it to the
2202 right of that line. */
2203 if (s
->face
->box
!= FACE_NO_BOX
2204 && s
->first_glyph
->left_box_line_p
2206 x
+= eabs (s
->face
->box_line_width
);
2208 /* If there is a margin around the image, adjust x- and y-position
2210 if (s
->slice
.x
== 0)
2211 x
+= s
->img
->hmargin
;
2212 if (s
->slice
.y
== 0)
2213 y
+= s
->img
->vmargin
;
2215 if (s
->hl
== DRAW_IMAGE_SUNKEN
2216 || s
->hl
== DRAW_IMAGE_RAISED
)
2218 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2219 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2223 thick
= eabs (s
->img
->relief
);
2224 raised_p
= s
->img
->relief
> 0;
2227 x1
= x
+ s
->slice
.width
- 1;
2228 y1
= y
+ s
->slice
.height
- 1;
2229 top_p
= bot_p
= left_p
= right_p
= 0;
2231 if (s
->slice
.x
== 0)
2232 x
-= thick
, left_p
= 1;
2233 if (s
->slice
.y
== 0)
2234 y
-= thick
, top_p
= 1;
2235 if (s
->slice
.x
+ s
->slice
.width
== s
->img
->width
)
2236 x1
+= thick
, right_p
= 1;
2237 if (s
->slice
.y
+ s
->slice
.height
== s
->img
->height
)
2238 y1
+= thick
, bot_p
= 1;
2240 x_setup_relief_colors (s
);
2241 get_glyph_string_clip_rect (s
, &r
);
2242 x_draw_relief_rect (s
->f
, x
, y
, x1
, y1
, thick
, raised_p
,
2243 top_p
, bot_p
, left_p
, right_p
, &r
);
2247 /* Draw the foreground of image glyph string S to PIXMAP. */
2250 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2253 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2255 /* If first glyph of S has a left box line, start drawing it to the
2256 right of that line. */
2257 if (s
->face
->box
!= FACE_NO_BOX
2258 && s
->first_glyph
->left_box_line_p
2260 x
+= eabs (s
->face
->box_line_width
);
2262 /* If there is a margin around the image, adjust x- and y-position
2264 if (s
->slice
.x
== 0)
2265 x
+= s
->img
->hmargin
;
2266 if (s
->slice
.y
== 0)
2267 y
+= s
->img
->vmargin
;
2273 /* We can't set both a clip mask and use XSetClipRectangles
2274 because the latter also sets a clip mask. We also can't
2275 trust on the shape extension to be available
2276 (XShapeCombineRegion). So, compute the rectangle to draw
2278 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2282 xgcv
.clip_mask
= s
->img
->mask
;
2283 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2284 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2285 xgcv
.function
= GXcopy
;
2286 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2288 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2289 s
->slice
.x
, s
->slice
.y
,
2290 s
->slice
.width
, s
->slice
.height
, x
, y
);
2291 XSetClipMask (s
->display
, s
->gc
, None
);
2295 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2296 s
->slice
.x
, s
->slice
.y
,
2297 s
->slice
.width
, s
->slice
.height
, x
, y
);
2299 /* When the image has a mask, we can expect that at
2300 least part of a mouse highlight or a block cursor will
2301 be visible. If the image doesn't have a mask, make
2302 a block cursor visible by drawing a rectangle around
2303 the image. I believe it's looking better if we do
2304 nothing here for mouse-face. */
2305 if (s
->hl
== DRAW_CURSOR
)
2307 int r
= eabs (s
->img
->relief
);
2308 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2309 s
->slice
.width
+ r
*2 - 1,
2310 s
->slice
.height
+ r
*2 - 1);
2315 /* Draw a rectangle if image could not be loaded. */
2316 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2317 s
->slice
.width
- 1, s
->slice
.height
- 1);
2321 /* Draw part of the background of glyph string S. X, Y, W, and H
2322 give the rectangle to draw. */
2325 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2329 /* Fill background with a stipple pattern. */
2330 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2331 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2332 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2335 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2339 /* Draw image glyph string S.
2342 s->x +-------------------------
2345 | +-------------------------
2348 | | +-------------------
2354 x_draw_image_glyph_string (struct glyph_string
*s
)
2356 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2357 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2359 Pixmap pixmap
= None
;
2362 if (s
->slice
.y
== 0)
2363 height
-= box_line_vwidth
;
2364 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2365 height
-= box_line_vwidth
;
2367 /* Fill background with face under the image. Do it only if row is
2368 taller than image or if image has a clip mask to reduce
2370 s
->stippled_p
= s
->face
->stipple
!= 0;
2371 if (height
> s
->slice
.height
2375 || s
->img
->pixmap
== 0
2376 || s
->width
!= s
->background_width
)
2380 /* Create a pixmap as large as the glyph string. Fill it
2381 with the background color. Copy the image to it, using
2382 its mask. Copy the temporary pixmap to the display. */
2383 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2384 int depth
= DefaultDepthOfScreen (screen
);
2386 /* Create a pixmap as large as the glyph string. */
2387 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2388 s
->background_width
,
2391 /* Don't clip in the following because we're working on the
2393 XSetClipMask (s
->display
, s
->gc
, None
);
2395 /* Fill the pixmap with the background color/stipple. */
2398 /* Fill background with a stipple pattern. */
2399 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2400 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2401 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2402 0, 0, s
->background_width
, s
->height
);
2403 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2404 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2409 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2411 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2412 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2413 0, 0, s
->background_width
, s
->height
);
2414 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2422 if (s
->first_glyph
->left_box_line_p
2424 x
+= box_line_hwidth
;
2426 if (s
->slice
.y
== 0)
2427 y
+= box_line_vwidth
;
2429 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2432 s
->background_filled_p
= 1;
2435 /* Draw the foreground. */
2438 x_draw_image_foreground_1 (s
, pixmap
);
2439 x_set_glyph_string_clipping (s
);
2440 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2441 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2442 XFreePixmap (s
->display
, pixmap
);
2445 x_draw_image_foreground (s
);
2447 /* If we must draw a relief around the image, do it. */
2449 || s
->hl
== DRAW_IMAGE_RAISED
2450 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2451 x_draw_image_relief (s
);
2455 /* Draw stretch glyph string S. */
2458 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2460 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2462 if (s
->hl
== DRAW_CURSOR
2463 && !x_stretch_cursor_p
)
2465 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2466 wide as the stretch glyph. */
2467 int width
, background_width
= s
->background_width
;
2470 if (!s
->row
->reversed_p
)
2472 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2476 background_width
-= left_x
- x
;
2482 /* In R2L rows, draw the cursor on the right edge of the
2484 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2486 if (x
+ background_width
> right_x
)
2487 background_width
-= x
- right_x
;
2488 x
+= background_width
;
2490 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2491 if (s
->row
->reversed_p
)
2495 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2497 /* Clear rest using the GC of the original non-cursor face. */
2498 if (width
< background_width
)
2501 int w
= background_width
- width
, h
= s
->height
;
2505 if (!s
->row
->reversed_p
)
2509 if (s
->row
->mouse_face_p
2510 && cursor_in_mouse_face_p (s
->w
))
2512 x_set_mouse_face_gc (s
);
2518 get_glyph_string_clip_rect (s
, &r
);
2519 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2521 if (s
->face
->stipple
)
2523 /* Fill background with a stipple pattern. */
2524 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2525 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2526 XSetFillStyle (s
->display
, gc
, FillSolid
);
2531 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2532 XSetForeground (s
->display
, gc
, xgcv
.background
);
2533 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2534 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2538 else if (!s
->background_filled_p
)
2540 int background_width
= s
->background_width
;
2541 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2543 /* Don't draw into left margin, fringe or scrollbar area
2544 except for header line and mode line. */
2545 if (x
< left_x
&& !s
->row
->mode_line_p
)
2547 background_width
-= left_x
- x
;
2550 if (background_width
> 0)
2551 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2554 s
->background_filled_p
= 1;
2558 Draw a wavy line under S. The wave fills wave_height pixels from y0.
2564 wave_height = 3 | * * * *
2569 x_draw_underwave (struct glyph_string
*s
)
2571 int wave_height
= 3, wave_length
= 2;
2572 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
2573 XRectangle wave_clip
, string_clip
, final_clip
;
2576 dy
= wave_height
- 1;
2578 y0
= s
->ybase
- wave_height
+ 3;
2582 /* Find and set clipping rectangle */
2586 wave_clip
.width
= width
;
2587 wave_clip
.height
= wave_height
;
2588 get_glyph_string_clip_rect (s
, &string_clip
);
2590 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
2593 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
2595 /* Draw the waves */
2597 x1
= x0
- (x0
% dx
);
2607 if (INT_MAX
- dx
< xmax
)
2612 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
2614 x2
+= dx
, y2
= y0
+ odd
*dy
;
2618 /* Restore previous clipping rectangle(s) */
2619 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
2623 /* Draw glyph string S. */
2626 x_draw_glyph_string (struct glyph_string
*s
)
2628 bool relief_drawn_p
= 0;
2630 /* If S draws into the background of its successors, draw the
2631 background of the successors first so that S can draw into it.
2632 This makes S->next use XDrawString instead of XDrawImageString. */
2633 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2636 struct glyph_string
*next
;
2638 for (width
= 0, next
= s
->next
;
2639 next
&& width
< s
->right_overhang
;
2640 width
+= next
->width
, next
= next
->next
)
2641 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2643 x_set_glyph_string_gc (next
);
2644 x_set_glyph_string_clipping (next
);
2645 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2646 x_draw_stretch_glyph_string (next
);
2648 x_draw_glyph_string_background (next
, 1);
2649 next
->num_clips
= 0;
2653 /* Set up S->gc, set clipping and draw S. */
2654 x_set_glyph_string_gc (s
);
2656 /* Draw relief (if any) in advance for char/composition so that the
2657 glyph string can be drawn over it. */
2658 if (!s
->for_overlaps
2659 && s
->face
->box
!= FACE_NO_BOX
2660 && (s
->first_glyph
->type
== CHAR_GLYPH
2661 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2664 x_set_glyph_string_clipping (s
);
2665 x_draw_glyph_string_background (s
, 1);
2666 x_draw_glyph_string_box (s
);
2667 x_set_glyph_string_clipping (s
);
2670 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2672 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2673 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2674 /* We must clip just this glyph. left_overhang part has already
2675 drawn when s->prev was drawn, and right_overhang part will be
2676 drawn later when s->next is drawn. */
2677 x_set_glyph_string_clipping_exactly (s
, s
);
2679 x_set_glyph_string_clipping (s
);
2681 switch (s
->first_glyph
->type
)
2684 x_draw_image_glyph_string (s
);
2688 x_draw_stretch_glyph_string (s
);
2692 if (s
->for_overlaps
)
2693 s
->background_filled_p
= 1;
2695 x_draw_glyph_string_background (s
, 0);
2696 x_draw_glyph_string_foreground (s
);
2699 case COMPOSITE_GLYPH
:
2700 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2701 && ! s
->first_glyph
->u
.cmp
.automatic
))
2702 s
->background_filled_p
= 1;
2704 x_draw_glyph_string_background (s
, 1);
2705 x_draw_composite_glyph_string_foreground (s
);
2708 case GLYPHLESS_GLYPH
:
2709 if (s
->for_overlaps
)
2710 s
->background_filled_p
= 1;
2712 x_draw_glyph_string_background (s
, 1);
2713 x_draw_glyphless_glyph_string_foreground (s
);
2720 if (!s
->for_overlaps
)
2722 /* Draw underline. */
2723 if (s
->face
->underline_p
)
2725 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2727 if (s
->face
->underline_defaulted_p
)
2728 x_draw_underwave (s
);
2732 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2733 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2734 x_draw_underwave (s
);
2735 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2738 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2740 unsigned long thickness
, position
;
2743 if (s
->prev
&& s
->prev
->face
->underline_p
2744 && s
->prev
->face
->underline_type
== FACE_UNDER_LINE
)
2746 /* We use the same underline style as the previous one. */
2747 thickness
= s
->prev
->underline_thickness
;
2748 position
= s
->prev
->underline_position
;
2752 /* Get the underline thickness. Default is 1 pixel. */
2753 if (s
->font
&& s
->font
->underline_thickness
> 0)
2754 thickness
= s
->font
->underline_thickness
;
2757 if (x_underline_at_descent_line
)
2758 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2761 /* Get the underline position. This is the recommended
2762 vertical offset in pixels from the baseline to the top of
2763 the underline. This is a signed value according to the
2764 specs, and its default is
2766 ROUND ((maximum descent) / 2), with
2767 ROUND(x) = floor (x + 0.5) */
2769 if (x_use_underline_position_properties
2770 && s
->font
&& s
->font
->underline_position
>= 0)
2771 position
= s
->font
->underline_position
;
2773 position
= (s
->font
->descent
+ 1) / 2;
2775 position
= underline_minimum_offset
;
2777 position
= max (position
, underline_minimum_offset
);
2779 /* Check the sanity of thickness and position. We should
2780 avoid drawing underline out of the current line area. */
2781 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2782 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2783 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2784 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2785 s
->underline_thickness
= thickness
;
2786 s
->underline_position
= position
;
2787 y
= s
->ybase
+ position
;
2788 if (s
->face
->underline_defaulted_p
)
2789 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2790 s
->x
, y
, s
->width
, thickness
);
2794 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2795 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2796 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2797 s
->x
, y
, s
->width
, thickness
);
2798 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2802 /* Draw overline. */
2803 if (s
->face
->overline_p
)
2805 unsigned long dy
= 0, h
= 1;
2807 if (s
->face
->overline_color_defaulted_p
)
2808 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2813 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2814 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2815 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2817 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2821 /* Draw strike-through. */
2822 if (s
->face
->strike_through_p
)
2824 unsigned long h
= 1;
2825 unsigned long dy
= (s
->height
- h
) / 2;
2827 if (s
->face
->strike_through_color_defaulted_p
)
2828 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2833 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2834 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2835 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2837 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2841 /* Draw relief if not yet drawn. */
2842 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2843 x_draw_glyph_string_box (s
);
2847 struct glyph_string
*prev
;
2849 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2850 if (prev
->hl
!= s
->hl
2851 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2853 /* As prev was drawn while clipped to its own area, we
2854 must draw the right_overhang part using s->hl now. */
2855 enum draw_glyphs_face save
= prev
->hl
;
2858 x_set_glyph_string_gc (prev
);
2859 x_set_glyph_string_clipping_exactly (s
, prev
);
2860 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2861 x_draw_glyph_string_foreground (prev
);
2863 x_draw_composite_glyph_string_foreground (prev
);
2864 XSetClipMask (prev
->display
, prev
->gc
, None
);
2866 prev
->num_clips
= 0;
2872 struct glyph_string
*next
;
2874 for (next
= s
->next
; next
; next
= next
->next
)
2875 if (next
->hl
!= s
->hl
2876 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2878 /* As next will be drawn while clipped to its own area,
2879 we must draw the left_overhang part using s->hl now. */
2880 enum draw_glyphs_face save
= next
->hl
;
2883 x_set_glyph_string_gc (next
);
2884 x_set_glyph_string_clipping_exactly (s
, next
);
2885 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2886 x_draw_glyph_string_foreground (next
);
2888 x_draw_composite_glyph_string_foreground (next
);
2889 XSetClipMask (next
->display
, next
->gc
, None
);
2891 next
->num_clips
= 0;
2892 next
->clip_head
= s
->next
;
2897 /* Reset clipping. */
2898 XSetClipMask (s
->display
, s
->gc
, None
);
2902 /* Shift display to make room for inserted glyphs. */
2905 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2907 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2908 f
->output_data
.x
->normal_gc
,
2909 x
, y
, width
, height
,
2913 /* Delete N glyphs at the nominal cursor position. Not implemented
2917 x_delete_glyphs (struct frame
*f
, register int n
)
2923 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2924 If they are <= 0, this is probably an error. */
2927 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
)
2929 eassert (width
> 0 && height
> 0);
2930 XClearArea (dpy
, window
, x
, y
, width
, height
, False
);
2934 /* Clear an entire frame. */
2937 x_clear_frame (struct frame
*f
)
2939 /* Clearing the frame will erase any cursor, so mark them all as no
2941 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2945 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2947 /* We have to clear the scroll bars. If we have changed colors or
2948 something like that, then they should be notified. */
2949 x_scroll_bar_clear (f
);
2951 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2952 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2953 redisplay, do it here. */
2954 if (FRAME_GTK_WIDGET (f
))
2955 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2958 XFlush (FRAME_X_DISPLAY (f
));
2965 /* Invert the middle quarter of the frame for .15 sec. */
2968 XTflash (struct frame
*f
)
2974 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
2975 when the scroll bars and the edit widget share the same X window. */
2976 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
2978 cairo_t
*cr
= gdk_cairo_create (window
);
2979 cairo_set_source_rgb (cr
, 1, 1, 1);
2980 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
2981 #define XFillRectangle(d, win, gc, x, y, w, h) \
2983 cairo_rectangle (cr, x, y, w, h); \
2987 #else /* ! HAVE_GTK3 */
2990 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
2991 ^ FRAME_BACKGROUND_PIXEL (f
));
2992 vals
.function
= GDK_XOR
;
2993 gc
= gdk_gc_new_with_values (window
,
2994 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
2995 #define XFillRectangle(d, win, gc, x, y, w, h) \
2996 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
2997 #endif /* ! HAVE_GTK3 */
2998 #else /* ! USE_GTK */
3001 /* Create a GC that will use the GXxor function to flip foreground
3002 pixels into background pixels. */
3006 values
.function
= GXxor
;
3007 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3008 ^ FRAME_BACKGROUND_PIXEL (f
));
3010 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3011 GCFunction
| GCForeground
, &values
);
3015 /* Get the height not including a menu bar widget. */
3016 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3017 /* Height of each line to flash. */
3018 int flash_height
= FRAME_LINE_HEIGHT (f
);
3019 /* These will be the left and right margins of the rectangles. */
3020 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3021 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3022 int width
= flash_right
- flash_left
;
3024 /* If window is tall, flash top and bottom line. */
3025 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3027 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3029 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3030 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3031 width
, flash_height
);
3032 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3034 (height
- flash_height
3035 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3036 width
, flash_height
);
3040 /* If it is short, flash it all. */
3041 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3042 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3043 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3048 struct timespec delay
= make_timespec (0, 150 * 1000 * 1000);
3049 struct timespec wakeup
= timespec_add (current_timespec (), delay
);
3051 /* Keep waiting until past the time wakeup or any input gets
3053 while (! detect_input_pending ())
3055 struct timespec current
= current_timespec ();
3056 struct timespec timeout
;
3058 /* Break if result would not be positive. */
3059 if (timespec_cmp (wakeup
, current
) <= 0)
3062 /* How long `select' should wait. */
3063 timeout
= make_timespec (0, 10 * 1000 * 1000);
3065 /* Try to wait that long--but we might wake up sooner. */
3066 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3070 /* If window is tall, flash top and bottom line. */
3071 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3073 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3075 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3076 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3077 width
, flash_height
);
3078 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3080 (height
- flash_height
3081 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3082 width
, flash_height
);
3085 /* If it is short, flash it all. */
3086 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3087 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3088 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3094 g_object_unref (G_OBJECT (gc
));
3096 #undef XFillRectangle
3098 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3109 XTtoggle_invisible_pointer (struct frame
*f
, int invisible
)
3114 if (FRAME_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3115 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3116 FRAME_DISPLAY_INFO (f
)->invisible_cursor
);
3119 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3120 f
->output_data
.x
->current_cursor
);
3121 f
->pointer_invisible
= invisible
;
3126 /* Make audible bell. */
3129 XTring_bell (struct frame
*f
)
3131 if (FRAME_X_DISPLAY (f
))
3139 XkbBell (FRAME_X_DISPLAY (f
), None
, 0, None
);
3141 XBell (FRAME_X_DISPLAY (f
), 0);
3143 XFlush (FRAME_X_DISPLAY (f
));
3149 /***********************************************************************
3151 ***********************************************************************/
3153 /* Perform an insert-lines or delete-lines operation, inserting N
3154 lines or deleting -N lines at vertical position VPOS. */
3157 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3163 /* Scroll part of the display as described by RUN. */
3166 x_scroll_run (struct window
*w
, struct run
*run
)
3168 struct frame
*f
= XFRAME (w
->frame
);
3169 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3171 /* Get frame-relative bounding box of the text display area of W,
3172 without mode lines. Include in this box the left and right
3174 window_box (w
, ANY_AREA
, &x
, &y
, &width
, &height
);
3176 #ifdef USE_TOOLKIT_SCROLL_BARS
3177 /* If the fringe is adjacent to the left (right) scroll bar of a
3178 leftmost (rightmost, respectively) window, then extend its
3179 background to the gap between the fringe and the bar. */
3180 if ((WINDOW_LEFTMOST_P (w
)
3181 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
3182 || (WINDOW_RIGHTMOST_P (w
)
3183 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
3185 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3189 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
3190 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
3191 * FRAME_COLUMN_WIDTH (f
));
3193 if (bar_area_x
+ bar_area_width
== x
)
3195 x
= bar_area_x
+ sb_width
;
3196 width
+= bar_area_width
- sb_width
;
3198 else if (x
+ width
== bar_area_x
)
3199 width
+= bar_area_width
- sb_width
;
3204 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3205 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3206 bottom_y
= y
+ height
;
3210 /* Scrolling up. Make sure we don't copy part of the mode
3211 line at the bottom. */
3212 if (from_y
+ run
->height
> bottom_y
)
3213 height
= bottom_y
- from_y
;
3215 height
= run
->height
;
3219 /* Scrolling down. Make sure we don't copy over the mode line.
3221 if (to_y
+ run
->height
> bottom_y
)
3222 height
= bottom_y
- to_y
;
3224 height
= run
->height
;
3229 /* Cursor off. Will be switched on again in x_update_window_end. */
3232 XCopyArea (FRAME_X_DISPLAY (f
),
3233 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3234 f
->output_data
.x
->normal_gc
,
3244 /***********************************************************************
3246 ***********************************************************************/
3250 frame_highlight (struct frame
*f
)
3252 /* We used to only do this if Vx_no_window_manager was non-nil, but
3253 the ICCCM (section 4.1.6) says that the window's border pixmap
3254 and border pixel are window attributes which are "private to the
3255 client", so we can always change it to whatever we want. */
3257 /* I recently started to get errors in this XSetWindowBorder, depending on
3258 the window-manager in use, tho something more is at play since I've been
3259 using that same window-manager binary for ever. Let's not crash just
3260 because of this (bug#9310). */
3261 x_catch_errors (FRAME_X_DISPLAY (f
));
3262 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3263 f
->output_data
.x
->border_pixel
);
3264 x_uncatch_errors ();
3266 x_update_cursor (f
, 1);
3267 x_set_frame_alpha (f
);
3271 frame_unhighlight (struct frame
*f
)
3273 /* We used to only do this if Vx_no_window_manager was non-nil, but
3274 the ICCCM (section 4.1.6) says that the window's border pixmap
3275 and border pixel are window attributes which are "private to the
3276 client", so we can always change it to whatever we want. */
3278 /* Same as above for XSetWindowBorder (bug#9310). */
3279 x_catch_errors (FRAME_X_DISPLAY (f
));
3280 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3281 f
->output_data
.x
->border_tile
);
3282 x_uncatch_errors ();
3284 x_update_cursor (f
, 1);
3285 x_set_frame_alpha (f
);
3288 /* The focus has changed. Update the frames as necessary to reflect
3289 the new situation. Note that we can't change the selected frame
3290 here, because the Lisp code we are interrupting might become confused.
3291 Each event gets marked with the frame in which it occurred, so the
3292 Lisp code can tell when the switch took place by examining the events. */
3295 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3297 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3299 if (frame
!= dpyinfo
->x_focus_frame
)
3301 /* Set this before calling other routines, so that they see
3302 the correct value of x_focus_frame. */
3303 dpyinfo
->x_focus_frame
= frame
;
3305 if (old_focus
&& old_focus
->auto_lower
)
3306 x_lower_frame (old_focus
);
3308 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3309 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3311 pending_autoraise_frame
= 0;
3314 x_frame_rehighlight (dpyinfo
);
3317 /* Handle FocusIn and FocusOut state changes for FRAME.
3318 If FRAME has focus and there exists more than one frame, puts
3319 a FOCUS_IN_EVENT into *BUFP. */
3322 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3324 if (type
== FocusIn
)
3326 if (dpyinfo
->x_focus_event_frame
!= frame
)
3328 x_new_focus_frame (dpyinfo
, frame
);
3329 dpyinfo
->x_focus_event_frame
= frame
;
3331 /* Don't stop displaying the initial startup message
3332 for a switch-frame event we don't need. */
3333 /* When run as a daemon, Vterminal_frame is always NIL. */
3334 bufp
->arg
= (((NILP (Vterminal_frame
) || EQ (Fdaemonp (), Qt
))
3335 && CONSP (Vframe_list
)
3336 && !NILP (XCDR (Vframe_list
)))
3338 bufp
->kind
= FOCUS_IN_EVENT
;
3339 XSETFRAME (bufp
->frame_or_window
, frame
);
3342 frame
->output_data
.x
->focus_state
|= state
;
3345 if (FRAME_XIC (frame
))
3346 XSetICFocus (FRAME_XIC (frame
));
3349 else if (type
== FocusOut
)
3351 frame
->output_data
.x
->focus_state
&= ~state
;
3353 if (dpyinfo
->x_focus_event_frame
== frame
)
3355 dpyinfo
->x_focus_event_frame
= 0;
3356 x_new_focus_frame (dpyinfo
, 0);
3358 bufp
->kind
= FOCUS_OUT_EVENT
;
3359 XSETFRAME (bufp
->frame_or_window
, frame
);
3363 if (FRAME_XIC (frame
))
3364 XUnsetICFocus (FRAME_XIC (frame
));
3366 if (frame
->pointer_invisible
)
3367 XTtoggle_invisible_pointer (frame
, 0);
3371 /* Return the Emacs frame-object corresponding to an X window.
3372 It could be the frame's main window or an icon window. */
3374 static struct frame
*
3375 x_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3377 Lisp_Object tail
, frame
;
3383 FOR_EACH_FRAME (tail
, frame
)
3386 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3388 if (f
->output_data
.x
->hourglass_window
== wdesc
)
3390 #ifdef USE_X_TOOLKIT
3391 if ((f
->output_data
.x
->edit_widget
3392 && XtWindow (f
->output_data
.x
->edit_widget
) == wdesc
)
3393 /* A tooltip frame? */
3394 || (!f
->output_data
.x
->edit_widget
3395 && FRAME_X_WINDOW (f
) == wdesc
)
3396 || f
->output_data
.x
->icon_desc
== wdesc
)
3398 #else /* not USE_X_TOOLKIT */
3400 if (f
->output_data
.x
->edit_widget
)
3402 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3403 struct x_output
*x
= f
->output_data
.x
;
3404 if (gwdesc
!= 0 && gwdesc
== x
->edit_widget
)
3407 #endif /* USE_GTK */
3408 if (FRAME_X_WINDOW (f
) == wdesc
3409 || f
->output_data
.x
->icon_desc
== wdesc
)
3411 #endif /* not USE_X_TOOLKIT */
3416 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
3418 /* Like x_window_to_frame but also compares the window with the widget's
3421 static struct frame
*
3422 x_any_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3424 Lisp_Object tail
, frame
;
3425 struct frame
*f
, *found
= NULL
;
3431 FOR_EACH_FRAME (tail
, frame
)
3436 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
3438 /* This frame matches if the window is any of its widgets. */
3439 x
= f
->output_data
.x
;
3440 if (x
->hourglass_window
== wdesc
)
3445 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3447 && gtk_widget_get_toplevel (gwdesc
) == x
->widget
)
3450 if (wdesc
== XtWindow (x
->widget
)
3451 || wdesc
== XtWindow (x
->column_widget
)
3452 || wdesc
== XtWindow (x
->edit_widget
))
3454 /* Match if the window is this frame's menubar. */
3455 else if (lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3459 else if (FRAME_X_WINDOW (f
) == wdesc
)
3460 /* A tooltip frame. */
3468 /* Likewise, but consider only the menu bar widget. */
3470 static struct frame
*
3471 x_menubar_window_to_frame (struct x_display_info
*dpyinfo
, XEvent
*event
)
3473 Window wdesc
= event
->xany
.window
;
3474 Lisp_Object tail
, frame
;
3481 FOR_EACH_FRAME (tail
, frame
)
3484 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3486 x
= f
->output_data
.x
;
3488 if (x
->menubar_widget
&& xg_event_is_for_menubar (f
, event
))
3491 /* Match if the window is this frame's menubar. */
3492 if (x
->menubar_widget
3493 && lw_window_is_in_menubar (wdesc
, x
->menubar_widget
))
3500 /* Return the frame whose principal (outermost) window is WDESC.
3501 If WDESC is some other (smaller) window, we return 0. */
3504 x_top_window_to_frame (struct x_display_info
*dpyinfo
, int wdesc
)
3506 Lisp_Object tail
, frame
;
3513 FOR_EACH_FRAME (tail
, frame
)
3516 if (!FRAME_X_P (f
) || FRAME_DISPLAY_INFO (f
) != dpyinfo
)
3518 x
= f
->output_data
.x
;
3522 /* This frame matches if the window is its topmost widget. */
3524 GtkWidget
*gwdesc
= xg_win_to_widget (dpyinfo
->display
, wdesc
);
3525 if (gwdesc
== x
->widget
)
3528 if (wdesc
== XtWindow (x
->widget
))
3532 else if (FRAME_X_WINDOW (f
) == wdesc
)
3533 /* Tooltip frame. */
3539 #else /* !USE_X_TOOLKIT && !USE_GTK */
3541 #define x_any_window_to_frame(d, i) x_window_to_frame (d, i)
3542 #define x_top_window_to_frame(d, i) x_window_to_frame (d, i)
3544 #endif /* USE_X_TOOLKIT || USE_GTK */
3546 /* The focus may have changed. Figure out if it is a real focus change,
3547 by checking both FocusIn/Out and Enter/LeaveNotify events.
3549 Returns FOCUS_IN_EVENT event in *BUFP. */
3552 x_detect_focus_change (struct x_display_info
*dpyinfo
, XEvent
*event
, struct input_event
*bufp
)
3554 struct frame
*frame
;
3556 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3560 switch (event
->type
)
3565 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3567 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3569 if (event
->xcrossing
.detail
!= NotifyInferior
3570 && event
->xcrossing
.focus
3571 && ! (focus_state
& FOCUS_EXPLICIT
))
3572 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3574 dpyinfo
, frame
, bufp
);
3580 x_focus_changed (event
->type
,
3581 (event
->xfocus
.detail
== NotifyPointer
?
3582 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3583 dpyinfo
, frame
, bufp
);
3587 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3589 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3590 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3591 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3598 #if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
3599 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3602 x_mouse_leave (struct x_display_info
*dpyinfo
)
3604 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3608 /* The focus has changed, or we have redirected a frame's focus to
3609 another frame (this happens when a frame uses a surrogate
3610 mini-buffer frame). Shift the highlight as appropriate.
3612 The FRAME argument doesn't necessarily have anything to do with which
3613 frame is being highlighted or un-highlighted; we only use it to find
3614 the appropriate X display info. */
3617 XTframe_rehighlight (struct frame
*frame
)
3619 x_frame_rehighlight (FRAME_DISPLAY_INFO (frame
));
3623 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3625 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3627 if (dpyinfo
->x_focus_frame
)
3629 dpyinfo
->x_highlight_frame
3630 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3631 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3632 : dpyinfo
->x_focus_frame
);
3633 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3635 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
3636 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3640 dpyinfo
->x_highlight_frame
= 0;
3642 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3645 frame_unhighlight (old_highlight
);
3646 if (dpyinfo
->x_highlight_frame
)
3647 frame_highlight (dpyinfo
->x_highlight_frame
);
3653 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3655 /* Initialize mode_switch_bit and modifier_meaning. */
3657 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3659 int min_code
, max_code
;
3662 XModifierKeymap
*mods
;
3664 dpyinfo
->meta_mod_mask
= 0;
3665 dpyinfo
->shift_lock_mask
= 0;
3666 dpyinfo
->alt_mod_mask
= 0;
3667 dpyinfo
->super_mod_mask
= 0;
3668 dpyinfo
->hyper_mod_mask
= 0;
3670 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3672 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3673 min_code
, max_code
- min_code
+ 1,
3675 mods
= XGetModifierMapping (dpyinfo
->display
);
3677 /* Scan the modifier table to see which modifier bits the Meta and
3678 Alt keysyms are on. */
3680 int row
, col
; /* The row and column in the modifier table. */
3681 int found_alt_or_meta
;
3683 for (row
= 3; row
< 8; row
++)
3685 found_alt_or_meta
= 0;
3686 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3688 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3690 /* Zeroes are used for filler. Skip them. */
3694 /* Are any of this keycode's keysyms a meta key? */
3698 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3700 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3706 found_alt_or_meta
= 1;
3707 dpyinfo
->meta_mod_mask
|= (1 << row
);
3712 found_alt_or_meta
= 1;
3713 dpyinfo
->alt_mod_mask
|= (1 << row
);
3718 if (!found_alt_or_meta
)
3719 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3720 code_col
= syms_per_code
;
3721 col
= mods
->max_keypermod
;
3726 if (!found_alt_or_meta
)
3727 dpyinfo
->super_mod_mask
|= (1 << row
);
3728 code_col
= syms_per_code
;
3729 col
= mods
->max_keypermod
;
3733 /* Ignore this if it's not on the lock modifier. */
3734 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3735 dpyinfo
->shift_lock_mask
= LockMask
;
3736 code_col
= syms_per_code
;
3737 col
= mods
->max_keypermod
;
3746 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3747 if (! dpyinfo
->meta_mod_mask
)
3749 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3750 dpyinfo
->alt_mod_mask
= 0;
3753 /* If some keys are both alt and meta,
3754 make them just meta, not alt. */
3755 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3757 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3761 XFreeModifiermap (mods
);
3764 /* Convert between the modifier bits X uses and the modifier bits
3768 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
3770 int mod_meta
= meta_modifier
;
3771 int mod_alt
= alt_modifier
;
3772 int mod_hyper
= hyper_modifier
;
3773 int mod_super
= super_modifier
;
3776 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3777 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
3778 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3779 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
3780 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3781 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
3782 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3783 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
3785 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3786 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3787 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3788 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3789 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3790 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3794 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
3796 EMACS_INT mod_meta
= meta_modifier
;
3797 EMACS_INT mod_alt
= alt_modifier
;
3798 EMACS_INT mod_hyper
= hyper_modifier
;
3799 EMACS_INT mod_super
= super_modifier
;
3803 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3804 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
3805 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3806 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
3807 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3808 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
3809 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3810 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
3813 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3814 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3815 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3816 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3817 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3818 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3821 /* Convert a keysym to its name. */
3824 x_get_keysym_name (int keysym
)
3829 value
= XKeysymToString (keysym
);
3837 /* Mouse clicks and mouse movement. Rah. */
3839 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3841 If the event is a button press, then note that we have grabbed
3845 construct_mouse_click (struct input_event
*result
, XButtonEvent
*event
, struct frame
*f
)
3847 /* Make the event type NO_EVENT; we'll change that when we decide
3849 result
->kind
= MOUSE_CLICK_EVENT
;
3850 result
->code
= event
->button
- Button1
;
3851 result
->timestamp
= event
->time
;
3852 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
),
3854 | (event
->type
== ButtonRelease
3858 XSETINT (result
->x
, event
->x
);
3859 XSETINT (result
->y
, event
->y
);
3860 XSETFRAME (result
->frame_or_window
, f
);
3865 /* Function to report a mouse movement to the mainstream Emacs code.
3866 The input handler calls this.
3868 We have received a mouse movement event, which is given in *event.
3869 If the mouse is over a different glyph than it was last time, tell
3870 the mainstream emacs code by setting mouse_moved. If not, ask for
3871 another motion event, so we can check again the next time it moves. */
3873 static XMotionEvent last_mouse_motion_event
;
3874 static Lisp_Object last_mouse_motion_frame
;
3877 note_mouse_movement (struct frame
*frame
, XMotionEvent
*event
)
3879 last_mouse_movement_time
= event
->time
;
3880 last_mouse_motion_event
= *event
;
3881 XSETFRAME (last_mouse_motion_frame
, frame
);
3883 if (!FRAME_X_OUTPUT (frame
))
3886 if (event
->window
!= FRAME_X_WINDOW (frame
))
3888 frame
->mouse_moved
= 1;
3889 last_mouse_scroll_bar
= Qnil
;
3890 note_mouse_highlight (frame
, -1, -1);
3891 last_mouse_glyph_frame
= 0;
3896 /* Has the mouse moved off the glyph it was on at the last sighting? */
3897 if (frame
!= last_mouse_glyph_frame
3898 || event
->x
< last_mouse_glyph
.x
3899 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3900 || event
->y
< last_mouse_glyph
.y
3901 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3903 frame
->mouse_moved
= 1;
3904 last_mouse_scroll_bar
= Qnil
;
3905 note_mouse_highlight (frame
, event
->x
, event
->y
);
3906 /* Remember which glyph we're now on. */
3907 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3908 last_mouse_glyph_frame
= frame
;
3916 /************************************************************************
3918 ************************************************************************/
3921 redo_mouse_highlight (void)
3923 if (!NILP (last_mouse_motion_frame
)
3924 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3925 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3926 last_mouse_motion_event
.x
,
3927 last_mouse_motion_event
.y
);
3932 /* Return the current position of the mouse.
3933 *FP should be a frame which indicates which display to ask about.
3935 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3936 and *PART to the frame, window, and scroll bar part that the mouse
3937 is over. Set *X and *Y to the portion and whole of the mouse's
3938 position on the scroll bar.
3940 If the mouse movement started elsewhere, set *FP to the frame the
3941 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3944 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
3945 was at this position.
3947 Don't store anything if we don't have a valid set of values to report.
3949 This clears the mouse_moved flag, so we can wait for the next mouse
3953 XTmouse_position (struct frame
**fp
, int insist
, Lisp_Object
*bar_window
,
3954 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3961 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3962 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
3968 Window dummy_window
;
3971 Lisp_Object frame
, tail
;
3973 /* Clear the mouse-moved flag for every frame on this display. */
3974 FOR_EACH_FRAME (tail
, frame
)
3975 if (FRAME_X_P (XFRAME (frame
))
3976 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3977 XFRAME (frame
)->mouse_moved
= 0;
3979 last_mouse_scroll_bar
= Qnil
;
3981 /* Figure out which root window we're on. */
3982 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3983 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3985 /* The root window which contains the pointer. */
3988 /* Trash which we can't trust if the pointer is on
3989 a different screen. */
3992 /* The position on that root window. */
3995 /* More trash we can't trust. */
3998 /* Modifier keys and pointer buttons, about which
4000 (unsigned int *) &dummy
);
4002 /* Now we have a position on the root; find the innermost window
4003 containing the pointer. */
4007 int parent_x
= 0, parent_y
= 0;
4011 /* XTranslateCoordinates can get errors if the window
4012 structure is changing at the same time this function
4013 is running. So at least we must not crash from them. */
4015 x_catch_errors (FRAME_X_DISPLAY (*fp
));
4017 if (FRAME_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
4018 && FRAME_LIVE_P (last_mouse_frame
))
4020 /* If mouse was grabbed on a frame, give coords for that frame
4021 even if the mouse is now outside it. */
4022 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4024 /* From-window, to-window. */
4025 root
, FRAME_X_WINDOW (last_mouse_frame
),
4027 /* From-position, to-position. */
4028 root_x
, root_y
, &win_x
, &win_y
,
4032 f1
= last_mouse_frame
;
4038 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
4040 /* From-window, to-window. */
4043 /* From-position, to-position. */
4044 root_x
, root_y
, &win_x
, &win_y
,
4049 if (child
== None
|| child
== win
)
4052 /* We don't wan't to know the innermost window. We
4053 want the edit window. For non-Gtk+ the innermost
4054 window is the edit window. For Gtk+ it might not
4055 be. It might be the tool bar for example. */
4056 if (x_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
))
4064 /* Now we know that:
4065 win is the innermost window containing the pointer
4066 (XTC says it has no child containing the pointer),
4067 win_x and win_y are the pointer's position in it
4068 (XTC did this the last time through), and
4069 parent_x and parent_y are the pointer's position in win's parent.
4070 (They are what win_x and win_y were when win was child.
4071 If win is the root window, it has no parent, and
4072 parent_{x,y} are invalid, but that's okay, because we'll
4073 never use them in that case.) */
4076 /* We don't wan't to know the innermost window. We
4077 want the edit window. */
4078 f1
= x_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
);
4080 /* Is win one of our frames? */
4081 f1
= x_any_window_to_frame (FRAME_DISPLAY_INFO (*fp
), win
);
4084 #ifdef USE_X_TOOLKIT
4085 /* If we end up with the menu bar window, say it's not
4088 && f1
->output_data
.x
->menubar_widget
4089 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4091 #endif /* USE_X_TOOLKIT */
4094 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4097 x_uncatch_errors ();
4099 /* If not, is it one of our scroll bars? */
4102 struct scroll_bar
*bar
;
4104 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4108 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4114 if (f1
== 0 && insist
> 0)
4115 f1
= SELECTED_FRAME ();
4119 /* Ok, we found a frame. Store all the values.
4120 last_mouse_glyph is a rectangle used to reduce the
4121 generation of mouse events. To not miss any motion
4122 events, we must divide the frame into rectangles of the
4123 size of the smallest character that could be displayed
4124 on it, i.e. into the same rectangles that matrices on
4125 the frame are divided into. */
4127 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
4128 last_mouse_glyph_frame
= f1
;
4133 XSETINT (*x
, win_x
);
4134 XSETINT (*y
, win_y
);
4135 *timestamp
= last_mouse_movement_time
;
4145 /***********************************************************************
4147 ***********************************************************************/
4149 /* Scroll bar support. */
4151 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4153 This can be called in GC, so we have to make sure to strip off mark
4156 static struct scroll_bar
*
4157 x_window_to_scroll_bar (Display
*display
, Window window_id
)
4159 Lisp_Object tail
, frame
;
4161 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4162 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4163 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4165 FOR_EACH_FRAME (tail
, frame
)
4167 Lisp_Object bar
, condemned
;
4169 if (! FRAME_X_P (XFRAME (frame
)))
4172 /* Scan this frame's scroll bar list for a scroll bar with the
4174 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4175 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4176 /* This trick allows us to search both the ordinary and
4177 condemned scroll bar lists with one loop. */
4178 ! NILP (bar
) || (bar
= condemned
,
4181 bar
= XSCROLL_BAR (bar
)->next
)
4182 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4183 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4184 return XSCROLL_BAR (bar
);
4191 #if defined USE_LUCID
4193 /* Return the Lucid menu bar WINDOW is part of. Return null
4194 if WINDOW is not part of a menu bar. */
4197 x_window_to_menu_bar (Window window
)
4199 Lisp_Object tail
, frame
;
4201 FOR_EACH_FRAME (tail
, frame
)
4202 if (FRAME_X_P (XFRAME (frame
)))
4204 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4206 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4212 #endif /* USE_LUCID */
4215 /************************************************************************
4217 ************************************************************************/
4219 #ifdef USE_TOOLKIT_SCROLL_BARS
4221 static void x_scroll_bar_to_input_event (XEvent
*, struct input_event
*);
4222 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
4223 static void x_create_toolkit_scroll_bar (struct frame
*,
4224 struct scroll_bar
*);
4225 static void x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*,
4229 /* Lisp window being scrolled. Set when starting to interact with
4230 a toolkit scroll bar, reset to nil when ending the interaction. */
4232 static Lisp_Object window_being_scrolled
;
4234 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4235 that movements of 1/20 of the screen size are mapped to up/down. */
4238 /* Id of action hook installed for scroll bars. */
4240 static XtActionHookId action_hook_id
;
4242 static Boolean xaw3d_arrow_scroll
;
4244 /* Whether the drag scrolling maintains the mouse at the top of the
4245 thumb. If not, resizing the thumb needs to be done more carefully
4246 to avoid jerkiness. */
4248 static Boolean xaw3d_pick_top
;
4250 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4251 bars are used.. The hook is responsible for detecting when
4252 the user ends an interaction with the scroll bar, and generates
4253 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4256 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4257 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4260 const char *end_action
;
4263 scroll_bar_p
= XmIsScrollBar (widget
);
4264 end_action
= "Release";
4265 #else /* !USE_MOTIF i.e. use Xaw */
4266 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4267 end_action
= "EndScroll";
4268 #endif /* USE_MOTIF */
4271 && strcmp (action_name
, end_action
) == 0
4272 && WINDOWP (window_being_scrolled
))
4275 struct scroll_bar
*bar
;
4277 x_send_scroll_bar_event (window_being_scrolled
,
4278 scroll_bar_end_scroll
, 0, 0);
4279 w
= XWINDOW (window_being_scrolled
);
4280 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
4282 if (bar
->dragging
!= -1)
4285 /* The thumb size is incorrect while dragging: fix it. */
4286 set_vertical_scroll_bar (w
);
4288 window_being_scrolled
= Qnil
;
4289 #if defined (USE_LUCID)
4290 bar
->last_seen_part
= scroll_bar_nowhere
;
4292 /* Xt timeouts no longer needed. */
4293 toolkit_scroll_bar_interaction
= 0;
4296 #endif /* not USE_GTK */
4298 /* A vector of windows used for communication between
4299 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4301 static struct window
**scroll_bar_windows
;
4302 static ptrdiff_t scroll_bar_windows_size
;
4305 /* Send a client message with message type Xatom_Scrollbar for a
4306 scroll action to the frame of WINDOW. PART is a value identifying
4307 the part of the scroll bar that was clicked on. PORTION is the
4308 amount to scroll of a whole of WHOLE. */
4311 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4314 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4315 struct window
*w
= XWINDOW (window
);
4316 struct frame
*f
= XFRAME (w
->frame
);
4321 /* Construct a ClientMessage event to send to the frame. */
4322 ev
->type
= ClientMessage
;
4323 ev
->message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4324 ev
->display
= FRAME_X_DISPLAY (f
);
4325 ev
->window
= FRAME_X_WINDOW (f
);
4328 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4329 not enough to store a pointer or Lisp_Object on a 64 bit system.
4330 So, store the window in scroll_bar_windows and pass the index
4331 into that array in the event. */
4332 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4333 if (scroll_bar_windows
[i
] == NULL
)
4336 if (i
== scroll_bar_windows_size
)
4338 ptrdiff_t old_nbytes
=
4339 scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4341 enum { XClientMessageEvent_MAX
= 0x7fffffff };
4342 scroll_bar_windows
=
4343 xpalloc (scroll_bar_windows
, &scroll_bar_windows_size
, 1,
4344 XClientMessageEvent_MAX
, sizeof *scroll_bar_windows
);
4345 nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4346 memset (&scroll_bar_windows
[i
], 0, nbytes
- old_nbytes
);
4349 scroll_bar_windows
[i
] = w
;
4350 ev
->data
.l
[0] = (long) i
;
4351 ev
->data
.l
[1] = (long) part
;
4352 ev
->data
.l
[2] = (long) 0;
4353 ev
->data
.l
[3] = (long) portion
;
4354 ev
->data
.l
[4] = (long) whole
;
4356 /* Make Xt timeouts work while the scroll bar is active. */
4357 #ifdef USE_X_TOOLKIT
4358 toolkit_scroll_bar_interaction
= 1;
4359 x_activate_timeout_atimer ();
4362 /* Setting the event mask to zero means that the message will
4363 be sent to the client that created the window, and if that
4364 window no longer exists, no event will be sent. */
4365 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4370 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4374 x_scroll_bar_to_input_event (XEvent
*event
, struct input_event
*ievent
)
4376 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4380 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4381 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4383 XSETWINDOW (window
, w
);
4385 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4386 ievent
->frame_or_window
= window
;
4389 ievent
->timestamp
= CurrentTime
;
4392 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4394 ievent
->part
= ev
->data
.l
[1];
4395 ievent
->code
= ev
->data
.l
[2];
4396 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4397 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4398 ievent
->modifiers
= 0;
4404 /* Minimum and maximum values used for Motif scroll bars. */
4406 #define XM_SB_MAX 10000000
4409 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4410 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4411 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4414 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4416 struct scroll_bar
*bar
= client_data
;
4417 XmScrollBarCallbackStruct
*cs
= call_data
;
4418 int part
= -1, whole
= 0, portion
= 0;
4422 case XmCR_DECREMENT
:
4424 part
= scroll_bar_up_arrow
;
4427 case XmCR_INCREMENT
:
4429 part
= scroll_bar_down_arrow
;
4432 case XmCR_PAGE_DECREMENT
:
4434 part
= scroll_bar_above_handle
;
4437 case XmCR_PAGE_INCREMENT
:
4439 part
= scroll_bar_below_handle
;
4444 part
= scroll_bar_to_top
;
4447 case XmCR_TO_BOTTOM
:
4449 part
= scroll_bar_to_bottom
;
4456 /* Get the slider size. */
4458 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4461 whole
= XM_SB_MAX
- slider_size
;
4462 portion
= min (cs
->value
, whole
);
4463 part
= scroll_bar_handle
;
4464 bar
->dragging
= cs
->value
;
4468 case XmCR_VALUE_CHANGED
:
4474 window_being_scrolled
= bar
->window
;
4475 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4479 #elif defined USE_GTK
4481 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4482 bar widget. DATA is a pointer to the scroll_bar structure. */
4485 xg_scroll_callback (GtkRange
*range
,
4486 GtkScrollType scroll
,
4490 struct scroll_bar
*bar
= user_data
;
4492 int part
= -1, whole
= 0, portion
= 0;
4493 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4494 struct frame
*f
= g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4496 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4497 position
= gtk_adjustment_get_value (adj
);
4502 case GTK_SCROLL_JUMP
:
4503 /* Buttons 1 2 or 3 must be grabbed. */
4504 if (FRAME_DISPLAY_INFO (f
)->grabbed
!= 0
4505 && FRAME_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4507 part
= scroll_bar_handle
;
4508 whole
= gtk_adjustment_get_upper (adj
) -
4509 gtk_adjustment_get_page_size (adj
);
4510 portion
= min ((int)position
, whole
);
4511 bar
->dragging
= portion
;
4514 case GTK_SCROLL_STEP_BACKWARD
:
4515 part
= scroll_bar_up_arrow
;
4518 case GTK_SCROLL_STEP_FORWARD
:
4519 part
= scroll_bar_down_arrow
;
4522 case GTK_SCROLL_PAGE_BACKWARD
:
4523 part
= scroll_bar_above_handle
;
4526 case GTK_SCROLL_PAGE_FORWARD
:
4527 part
= scroll_bar_below_handle
;
4534 window_being_scrolled
= bar
->window
;
4535 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4541 /* Callback for button release. Sets dragging to -1 when dragging is done. */
4544 xg_end_scroll_callback (GtkWidget
*widget
,
4545 GdkEventButton
*event
,
4548 struct scroll_bar
*bar
= user_data
;
4550 if (WINDOWP (window_being_scrolled
))
4552 x_send_scroll_bar_event (window_being_scrolled
,
4553 scroll_bar_end_scroll
, 0, 0);
4554 window_being_scrolled
= Qnil
;
4561 #else /* not USE_GTK and not USE_MOTIF */
4563 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4564 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4565 scroll bar struct. CALL_DATA is a pointer to a float saying where
4569 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4571 struct scroll_bar
*bar
= client_data
;
4572 float *top_addr
= call_data
;
4573 float top
= *top_addr
;
4575 int whole
, portion
, height
;
4576 enum scroll_bar_part part
;
4578 /* Get the size of the thumb, a value between 0 and 1. */
4580 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4584 portion
= shown
< 1 ? top
* whole
: 0;
4586 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
4587 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4588 the bottom, so we force the scrolling whenever we see that we're
4589 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4590 we try to ensure that we always stay two pixels away from the
4592 part
= scroll_bar_down_arrow
;
4594 part
= scroll_bar_handle
;
4596 window_being_scrolled
= bar
->window
;
4597 bar
->dragging
= portion
;
4598 bar
->last_seen_part
= part
;
4599 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4603 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4604 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4605 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4606 the scroll bar. CALL_DATA is an integer specifying the action that
4607 has taken place. Its magnitude is in the range 0..height of the
4608 scroll bar. Negative values mean scroll towards buffer start.
4609 Values < height of scroll bar mean line-wise movement. */
4612 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4614 struct scroll_bar
*bar
= client_data
;
4615 /* The position really is stored cast to a pointer. */
4616 int position
= (intptr_t) call_data
;
4618 enum scroll_bar_part part
;
4620 /* Get the height of the scroll bar. */
4622 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4625 if (eabs (position
) >= height
)
4626 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4628 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4629 it maps line-movement to call_data = max(5, height/20). */
4630 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4631 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4633 part
= scroll_bar_move_ratio
;
4635 window_being_scrolled
= bar
->window
;
4637 bar
->last_seen_part
= part
;
4638 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4641 #endif /* not USE_GTK and not USE_MOTIF */
4643 #define SCROLL_BAR_NAME "verticalScrollBar"
4645 /* Create the widget for scroll bar BAR on frame F. Record the widget
4646 and X window of the scroll bar in BAR. */
4650 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4652 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4655 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4656 G_CALLBACK (xg_end_scroll_callback
),
4661 #else /* not USE_GTK */
4664 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4670 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4671 unsigned long pixel
;
4676 /* Set resources. Create the widget. */
4677 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4678 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4679 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4680 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4681 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4682 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4683 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4685 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4688 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4692 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4695 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4699 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4700 (char *) scroll_bar_name
, av
, ac
);
4702 /* Add one callback for everything that can happen. */
4703 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4705 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4707 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4709 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4711 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4713 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4715 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4718 /* Realize the widget. Only after that is the X window created. */
4719 XtRealizeWidget (widget
);
4721 /* Set the cursor to an arrow. I didn't find a resource to do that.
4722 And I'm wondering why it hasn't an arrow cursor by default. */
4723 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4724 f
->output_data
.x
->nontext_cursor
);
4726 #else /* !USE_MOTIF i.e. use Xaw */
4728 /* Set resources. Create the widget. The background of the
4729 Xaw3d scroll bar widget is a little bit light for my taste.
4730 We don't alter it here to let users change it according
4731 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4732 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4733 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4734 /* For smoother scrolling with Xaw3d -sm */
4735 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4737 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4740 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4744 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4747 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4751 /* Top/bottom shadow colors. */
4753 /* Allocate them, if necessary. */
4754 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4756 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4759 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4760 FRAME_X_COLORMAP (f
),
4761 &pixel
, 1.2, 0x8000))
4763 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4766 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4768 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4771 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4772 FRAME_X_COLORMAP (f
),
4773 &pixel
, 0.6, 0x4000))
4775 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4779 #ifdef XtNbeNiceToColormap
4780 /* Tell the toolkit about them. */
4781 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4782 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4783 /* We tried to allocate a color for the top/bottom shadow, and
4784 failed, so tell Xaw3d to use dithering instead. */
4785 /* But only if we have a small colormap. Xaw3d can allocate nice
4788 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4789 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4793 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4794 be more consistent with other emacs 3d colors, and since Xaw3d is
4795 not good at dealing with allocation failure. */
4797 /* This tells Xaw3d to use real colors instead of dithering for
4799 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4802 /* Specify the colors. */
4803 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4806 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4809 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4812 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4818 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4819 f
->output_data
.x
->edit_widget
, av
, ac
);
4822 char const *initial
= "";
4823 char const *val
= initial
;
4824 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4825 #ifdef XtNarrowScrollbars
4826 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4828 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4829 if (xaw3d_arrow_scroll
|| val
== initial
)
4830 { /* ARROW_SCROLL */
4831 xaw3d_arrow_scroll
= True
;
4832 /* Isn't that just a personal preference ? --Stef */
4833 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4837 /* Define callbacks. */
4838 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4839 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4842 /* Realize the widget. Only after that is the X window created. */
4843 XtRealizeWidget (widget
);
4845 #endif /* !USE_MOTIF */
4847 /* Install an action hook that lets us detect when the user
4848 finishes interacting with a scroll bar. */
4849 if (action_hook_id
== 0)
4850 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4852 /* Remember X window and widget in the scroll bar vector. */
4853 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4854 xwindow
= XtWindow (widget
);
4855 bar
->x_window
= xwindow
;
4859 #endif /* not USE_GTK */
4862 /* Set the thumb size and position of scroll bar BAR. We are currently
4863 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4867 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4869 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4872 #else /* not USE_GTK */
4874 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4877 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4878 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4885 if (scroll_bar_adjust_thumb_portion_p
)
4887 /* We use an estimate of 30 chars per line rather than the real
4888 `portion' value. This has the disadvantage that the thumb size
4889 is not very representative, but it makes our life a lot easier.
4890 Otherwise, we have to constantly adjust the thumb size, which
4891 we can't always do quickly enough: while dragging, the size of
4892 the thumb might prevent the user from dragging the thumb all the
4893 way to the end. but Motif and some versions of Xaw3d don't allow
4894 updating the thumb size while dragging. Also, even if we can update
4895 its size, the update will often happen too late.
4896 If you don't believe it, check out revision 1.650 of xterm.c to see
4897 what hoops we were going through and the still poor behavior we got. */
4898 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4899 /* When the thumb is at the bottom, position == whole.
4900 So we need to increase `whole' to make space for the thumb. */
4908 top
= (float) position
/ whole
;
4909 shown
= (float) portion
/ whole
;
4912 if (bar
->dragging
== -1)
4916 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4917 is the scroll bar's maximum and MIN is the scroll bar's minimum
4919 size
= clip_to_bounds (1, shown
* XM_SB_MAX
, XM_SB_MAX
);
4921 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4922 value
= top
* XM_SB_MAX
;
4923 value
= min (value
, XM_SB_MAX
- size
);
4925 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4927 #else /* !USE_MOTIF i.e. use Xaw */
4933 top
= (float) position
/ whole
;
4934 shown
= (float) portion
/ whole
;
4938 float old_top
, old_shown
;
4940 XtVaGetValues (widget
,
4941 XtNtopOfThumb
, &old_top
,
4942 XtNshown
, &old_shown
,
4946 /* Massage the top+shown values. */
4947 if (bar
->dragging
== -1 || bar
->last_seen_part
== scroll_bar_down_arrow
)
4948 top
= max (0, min (1, top
));
4951 #if ! defined (HAVE_XAW3D)
4952 /* With Xaw, 'top' values too closer to 1.0 may
4953 cause the thumb to disappear. Fix that. */
4954 top
= min (top
, 0.99f
);
4956 /* Keep two pixels available for moving the thumb down. */
4957 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
4958 #if ! defined (HAVE_XAW3D)
4959 /* Likewise with too small 'shown'. */
4960 shown
= max (shown
, 0.01f
);
4963 /* If the call to XawScrollbarSetThumb below doesn't seem to
4964 work, check that 'NARROWPROTO' is defined in src/config.h.
4965 If this is not so, most likely you need to fix configure. */
4966 if (top
!= old_top
|| shown
!= old_shown
)
4968 if (bar
->dragging
== -1)
4969 XawScrollbarSetThumb (widget
, top
, shown
);
4972 /* Try to make the scrolling a tad smoother. */
4973 if (!xaw3d_pick_top
)
4974 shown
= min (shown
, old_shown
);
4976 XawScrollbarSetThumb (widget
, top
, shown
);
4980 #endif /* !USE_MOTIF */
4984 #endif /* not USE_GTK */
4986 #endif /* USE_TOOLKIT_SCROLL_BARS */
4990 /************************************************************************
4991 Scroll bars, general
4992 ************************************************************************/
4994 /* Create a scroll bar and return the scroll bar vector for it. W is
4995 the Emacs window on which to create the scroll bar. TOP, LEFT,
4996 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4999 static struct scroll_bar
*
5000 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
5002 struct frame
*f
= XFRAME (w
->frame
);
5003 struct scroll_bar
*bar
5004 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
5009 #ifdef USE_TOOLKIT_SCROLL_BARS
5010 x_create_toolkit_scroll_bar (f
, bar
);
5011 #else /* not USE_TOOLKIT_SCROLL_BARS */
5013 XSetWindowAttributes a
;
5017 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
5018 if (a
.background_pixel
== -1)
5019 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
5021 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
5022 | ButtonMotionMask
| PointerMotionHintMask
5024 a
.cursor
= FRAME_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
5026 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
5028 /* Clear the area of W that will serve as a scroll bar. This is
5029 for the case that a window has been split horizontally. In
5030 this case, no clear_frame is generated to reduce flickering. */
5031 if (width
> 0 && height
> 0)
5032 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5033 left
, top
, width
, window_box_height (w
));
5035 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5036 /* Position and size of scroll bar. */
5037 left
, top
, width
, height
,
5038 /* Border width, depth, class, and visual. */
5045 bar
->x_window
= window
;
5047 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5049 XSETWINDOW (bar
->window
, w
);
5053 bar
->height
= height
;
5057 bar
->fringe_extended_p
= 0;
5058 #if defined (USE_TOOLKIT_SCROLL_BARS) && defined (USE_LUCID)
5059 bar
->last_seen_part
= scroll_bar_nowhere
;
5062 /* Add bar to its frame's list of scroll bars. */
5063 bar
->next
= FRAME_SCROLL_BARS (f
);
5065 XSETVECTOR (barobj
, bar
);
5066 fset_scroll_bars (f
, barobj
);
5067 if (!NILP (bar
->next
))
5068 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5070 /* Map the window/widget. */
5071 #ifdef USE_TOOLKIT_SCROLL_BARS
5074 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
5075 left
,width
, max (height
, 1));
5076 #else /* not USE_GTK */
5077 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5078 XtConfigureWidget (scroll_bar
, left
, top
, width
, max (height
, 1), 0);
5079 XtMapWidget (scroll_bar
);
5080 #endif /* not USE_GTK */
5082 #else /* not USE_TOOLKIT_SCROLL_BARS */
5083 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5084 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5091 #ifndef USE_TOOLKIT_SCROLL_BARS
5093 /* Draw BAR's handle in the proper position.
5095 If the handle is already drawn from START to END, don't bother
5096 redrawing it, unless REBUILD is non-zero; in that case, always
5097 redraw it. (REBUILD is handy for drawing the handle after expose
5100 Normally, we want to constrain the start and end of the handle to
5101 fit inside its rectangle, but if the user is dragging the scroll
5102 bar handle, we want to let them drag it down all the way, so that
5103 the bar's top is as far down as it goes; otherwise, there's no way
5104 to move to the very end of the buffer. */
5107 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
5109 bool dragging
= bar
->dragging
!= -1;
5110 Window w
= bar
->x_window
;
5111 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5112 GC gc
= f
->output_data
.x
->normal_gc
;
5114 /* If the display is already accurate, do nothing. */
5116 && start
== bar
->start
5123 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5124 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5125 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5127 /* Make sure the values are reasonable, and try to preserve
5128 the distance between start and end. */
5130 int length
= end
- start
;
5134 else if (start
> top_range
)
5136 end
= start
+ length
;
5140 else if (end
> top_range
&& ! dragging
)
5144 /* Store the adjusted setting in the scroll bar. */
5148 /* Clip the end position, just for display. */
5149 if (end
> top_range
)
5152 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5153 below top positions, to make sure the handle is always at least
5154 that many pixels tall. */
5155 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5157 /* Draw the empty space above the handle. Note that we can't clear
5158 zero-height areas; that means "clear to end of window." */
5160 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5161 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5162 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5163 inside_width
, start
);
5165 /* Change to proper foreground color if one is specified. */
5166 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5167 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5168 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5170 /* Draw the handle itself. */
5171 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5172 /* x, y, width, height */
5173 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5174 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5175 inside_width
, end
- start
);
5177 /* Restore the foreground color of the GC if we changed it above. */
5178 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5179 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5180 FRAME_FOREGROUND_PIXEL (f
));
5182 /* Draw the empty space below the handle. Note that we can't
5183 clear zero-height areas; that means "clear to end of window." */
5184 if (end
< inside_height
)
5185 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5186 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5187 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5188 inside_width
, inside_height
- end
);
5194 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5196 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5200 x_scroll_bar_remove (struct scroll_bar
*bar
)
5202 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5205 #ifdef USE_TOOLKIT_SCROLL_BARS
5207 xg_remove_scroll_bar (f
, bar
->x_window
);
5208 #else /* not USE_GTK */
5209 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5210 #endif /* not USE_GTK */
5212 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5215 /* Dissociate this scroll bar from its window. */
5216 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5222 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5223 that we are displaying PORTION characters out of a total of WHOLE
5224 characters, starting at POSITION. If WINDOW has no scroll bar,
5228 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5230 struct frame
*f
= XFRAME (w
->frame
);
5232 struct scroll_bar
*bar
;
5233 int top
, height
, left
, sb_left
, width
, sb_width
;
5234 int window_y
, window_height
;
5235 #ifdef USE_TOOLKIT_SCROLL_BARS
5236 bool fringe_extended_p
;
5239 /* Get window dimensions. */
5240 window_box (w
, ANY_AREA
, 0, &window_y
, 0, &window_height
);
5242 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5243 height
= window_height
;
5245 /* Compute the left edge of the scroll bar area. */
5246 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5248 /* Compute the width of the scroll bar which might be less than
5249 the width of the area reserved for the scroll bar. */
5250 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5251 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5255 /* Compute the left edge of the scroll bar. */
5256 #ifdef USE_TOOLKIT_SCROLL_BARS
5257 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5258 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5260 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5262 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5263 sb_left
= left
+ width
- sb_width
;
5268 #ifdef USE_TOOLKIT_SCROLL_BARS
5269 fringe_extended_p
= WINDOW_FRINGE_EXTENDED_P (w
);
5272 /* Does the scroll bar exist yet? */
5273 if (NILP (w
->vertical_scroll_bar
))
5275 if (width
> 0 && height
> 0)
5278 #ifdef USE_TOOLKIT_SCROLL_BARS
5279 if (fringe_extended_p
)
5280 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5281 sb_left
, top
, sb_width
, height
);
5284 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5285 left
, top
, width
, height
);
5289 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5293 /* It may just need to be moved and resized. */
5294 unsigned int mask
= 0;
5296 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5300 if (sb_left
!= bar
->left
)
5302 if (top
!= bar
->top
)
5304 if (sb_width
!= bar
->width
)
5306 if (height
!= bar
->height
)
5309 #ifdef USE_TOOLKIT_SCROLL_BARS
5311 /* Move/size the scroll bar widget. */
5312 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5314 /* Since toolkit scroll bars are smaller than the space reserved
5315 for them on the frame, we have to clear "under" them. */
5316 if (width
> 0 && height
> 0)
5318 if (fringe_extended_p
)
5319 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5320 sb_left
, top
, sb_width
, height
);
5322 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5323 left
, top
, width
, height
);
5326 xg_update_scrollbar_pos (f
, bar
->x_window
, top
,
5327 sb_left
, sb_width
, max (height
, 1));
5328 #else /* not USE_GTK */
5329 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5330 sb_left
, top
, sb_width
, max (height
, 1), 0);
5331 #endif /* not USE_GTK */
5333 #else /* not USE_TOOLKIT_SCROLL_BARS */
5335 /* Clear areas not covered by the scroll bar because it's not as
5336 wide as the area reserved for it. This makes sure a
5337 previous mode line display is cleared after C-x 2 C-x 1, for
5340 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5341 int rest
= area_width
- sb_width
;
5342 if (rest
> 0 && height
> 0)
5344 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5345 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5346 left
+ area_width
- rest
, top
, rest
, height
);
5348 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5349 left
, top
, rest
, height
);
5353 /* Move/size the scroll bar window. */
5360 wc
.width
= sb_width
;
5362 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5366 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5368 /* Remember new settings. */
5369 bar
->left
= sb_left
;
5371 bar
->width
= sb_width
;
5372 bar
->height
= height
;
5377 #ifdef USE_TOOLKIT_SCROLL_BARS
5378 bar
->fringe_extended_p
= fringe_extended_p
;
5380 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5381 #else /* not USE_TOOLKIT_SCROLL_BARS */
5382 /* Set the scroll bar's current state, unless we're currently being
5384 if (bar
->dragging
== -1)
5386 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5389 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5392 int start
= ((double) position
* top_range
) / whole
;
5393 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5394 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5397 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5399 XSETVECTOR (barobj
, bar
);
5400 wset_vertical_scroll_bar (w
, barobj
);
5404 /* The following three hooks are used when we're doing a thorough
5405 redisplay of the frame. We don't explicitly know which scroll bars
5406 are going to be deleted, because keeping track of when windows go
5407 away is a real pain - "Can you say set-window-configuration, boys
5408 and girls?" Instead, we just assert at the beginning of redisplay
5409 that *all* scroll bars are to be removed, and then save a scroll bar
5410 from the fiery pit when we actually redisplay its window. */
5412 /* Arrange for all scroll bars on FRAME to be removed at the next call
5413 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5414 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5417 XTcondemn_scroll_bars (struct frame
*frame
)
5419 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5420 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5423 bar
= FRAME_SCROLL_BARS (frame
);
5424 fset_scroll_bars (frame
, XSCROLL_BAR (bar
)->next
);
5425 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5426 XSCROLL_BAR (bar
)->prev
= Qnil
;
5427 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5428 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5429 fset_condemned_scroll_bars (frame
, bar
);
5434 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5435 Note that WINDOW isn't necessarily condemned at all. */
5438 XTredeem_scroll_bar (struct window
*window
)
5440 struct scroll_bar
*bar
;
5444 /* We can't redeem this window's scroll bar if it doesn't have one. */
5445 if (NILP (window
->vertical_scroll_bar
))
5448 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5450 /* Unlink it from the condemned list. */
5451 f
= XFRAME (WINDOW_FRAME (window
));
5452 if (NILP (bar
->prev
))
5454 /* If the prev pointer is nil, it must be the first in one of
5456 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5457 /* It's not condemned. Everything's fine. */
5459 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5460 window
->vertical_scroll_bar
))
5461 fset_condemned_scroll_bars (f
, bar
->next
);
5463 /* If its prev pointer is nil, it must be at the front of
5464 one or the other! */
5468 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5470 if (! NILP (bar
->next
))
5471 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5473 bar
->next
= FRAME_SCROLL_BARS (f
);
5475 XSETVECTOR (barobj
, bar
);
5476 fset_scroll_bars (f
, barobj
);
5477 if (! NILP (bar
->next
))
5478 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5481 /* Remove all scroll bars on FRAME that haven't been saved since the
5482 last call to `*condemn_scroll_bars_hook'. */
5485 XTjudge_scroll_bars (struct frame
*f
)
5487 Lisp_Object bar
, next
;
5489 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5491 /* Clear out the condemned list now so we won't try to process any
5492 more events on the hapless scroll bars. */
5493 fset_condemned_scroll_bars (f
, Qnil
);
5495 for (; ! NILP (bar
); bar
= next
)
5497 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5499 x_scroll_bar_remove (b
);
5502 b
->next
= b
->prev
= Qnil
;
5505 /* Now there should be no references to the condemned scroll bars,
5506 and they should get garbage-collected. */
5510 #ifndef USE_TOOLKIT_SCROLL_BARS
5511 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5512 is a no-op when using toolkit scroll bars.
5514 This may be called from a signal handler, so we have to ignore GC
5518 x_scroll_bar_expose (struct scroll_bar
*bar
, XEvent
*event
)
5520 Window w
= bar
->x_window
;
5521 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5522 GC gc
= f
->output_data
.x
->normal_gc
;
5526 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5528 /* Switch to scroll bar foreground color. */
5529 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5530 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5531 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5533 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5534 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5535 /* x, y, width, height */
5536 0, 0, bar
->width
- 1, bar
->height
- 1);
5538 /* Restore the foreground color of the GC if we changed it above. */
5539 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5540 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5541 FRAME_FOREGROUND_PIXEL (f
));
5546 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5548 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5549 is set to something other than NO_EVENT, it is enqueued.
5551 This may be called from a signal handler, so we have to ignore GC
5556 x_scroll_bar_handle_click (struct scroll_bar
*bar
, XEvent
*event
, struct input_event
*emacs_event
)
5558 if (! WINDOWP (bar
->window
))
5561 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5562 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5563 emacs_event
->modifiers
5564 = (x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO
5565 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5566 event
->xbutton
.state
)
5567 | (event
->type
== ButtonRelease
5570 emacs_event
->frame_or_window
= bar
->window
;
5571 emacs_event
->arg
= Qnil
;
5572 emacs_event
->timestamp
= event
->xbutton
.time
;
5575 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5576 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5579 if (y
> top_range
) y
= top_range
;
5582 emacs_event
->part
= scroll_bar_above_handle
;
5583 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5584 emacs_event
->part
= scroll_bar_handle
;
5586 emacs_event
->part
= scroll_bar_below_handle
;
5588 #ifndef USE_TOOLKIT_SCROLL_BARS
5589 /* If the user has released the handle, set it to its final position. */
5590 if (event
->type
== ButtonRelease
&& bar
->dragging
!= -1)
5592 int new_start
= y
- bar
->dragging
;
5593 int new_end
= new_start
+ bar
->end
- bar
->start
;
5595 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5600 XSETINT (emacs_event
->x
, y
);
5601 XSETINT (emacs_event
->y
, top_range
);
5605 #ifndef USE_TOOLKIT_SCROLL_BARS
5607 /* Handle some mouse motion while someone is dragging the scroll bar.
5609 This may be called from a signal handler, so we have to ignore GC
5613 x_scroll_bar_note_movement (struct scroll_bar
*bar
, XMotionEvent
*event
)
5615 struct frame
*f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5617 last_mouse_movement_time
= event
->time
;
5620 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5622 /* If we're dragging the bar, display it. */
5623 if (bar
->dragging
!= -1)
5625 /* Where should the handle be now? */
5626 int new_start
= event
->y
- bar
->dragging
;
5628 if (new_start
!= bar
->start
)
5630 int new_end
= new_start
+ bar
->end
- bar
->start
;
5632 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5637 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5639 /* Return information to the user about the current position of the mouse
5640 on the scroll bar. */
5643 x_scroll_bar_report_motion (struct frame
**fp
, Lisp_Object
*bar_window
,
5644 enum scroll_bar_part
*part
, Lisp_Object
*x
,
5645 Lisp_Object
*y
, Time
*timestamp
)
5647 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5648 Window w
= bar
->x_window
;
5649 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5651 Window dummy_window
;
5653 unsigned int dummy_mask
;
5657 /* Get the mouse's position relative to the scroll bar window, and
5659 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5661 /* Root, child, root x and root y. */
5662 &dummy_window
, &dummy_window
,
5663 &dummy_coord
, &dummy_coord
,
5665 /* Position relative to scroll bar. */
5668 /* Mouse buttons and modifier keys. */
5674 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5676 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5678 if (bar
->dragging
!= -1)
5679 win_y
-= bar
->dragging
;
5683 if (win_y
> top_range
)
5687 *bar_window
= bar
->window
;
5689 if (bar
->dragging
!= -1)
5690 *part
= scroll_bar_handle
;
5691 else if (win_y
< bar
->start
)
5692 *part
= scroll_bar_above_handle
;
5693 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5694 *part
= scroll_bar_handle
;
5696 *part
= scroll_bar_below_handle
;
5698 XSETINT (*x
, win_y
);
5699 XSETINT (*y
, top_range
);
5702 last_mouse_scroll_bar
= Qnil
;
5705 *timestamp
= last_mouse_movement_time
;
5711 /* The screen has been cleared so we may have changed foreground or
5712 background colors, and the scroll bars may need to be redrawn.
5713 Clear out the scroll bars, and ask for expose events, so we can
5717 x_scroll_bar_clear (struct frame
*f
)
5719 #ifndef USE_TOOLKIT_SCROLL_BARS
5722 /* We can have scroll bars even if this is 0,
5723 if we just turned off scroll bar mode.
5724 But in that case we should not clear them. */
5725 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5726 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5727 bar
= XSCROLL_BAR (bar
)->next
)
5728 XClearArea (FRAME_X_DISPLAY (f
),
5729 XSCROLL_BAR (bar
)->x_window
,
5731 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5734 #ifdef ENABLE_CHECKING
5736 /* Record the last 100 characters stored
5737 to help debug the loss-of-chars-during-GC problem. */
5739 static int temp_index
;
5740 static short temp_buffer
[100];
5742 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5743 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5745 temp_buffer[temp_index++] = (keysym)
5747 #else /* not ENABLE_CHECKING */
5749 #define STORE_KEYSYM_FOR_DEBUG(keysym) ((void)0)
5751 #endif /* ENABLE_CHECKING */
5753 /* Set this to nonzero to fake an "X I/O error"
5754 on a particular display. */
5756 static struct x_display_info
*XTread_socket_fake_io_error
;
5758 /* When we find no input here, we occasionally do a no-op command
5759 to verify that the X server is still running and we can still talk with it.
5760 We try all the open displays, one by one.
5761 This variable is used for cycling thru the displays. */
5763 static struct x_display_info
*next_noop_dpyinfo
;
5765 #if defined USE_X_TOOLKIT || defined USE_GTK
5766 #define SET_SAVED_BUTTON_EVENT \
5769 if (f->output_data.x->saved_menu_event == 0) \
5770 f->output_data.x->saved_menu_event = \
5771 xmalloc (sizeof (XEvent)); \
5772 *f->output_data.x->saved_menu_event = event; \
5773 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5774 XSETFRAME (inev.ie.frame_or_window, f); \
5786 /* Filter events for the current X input method.
5787 DPYINFO is the display this event is for.
5788 EVENT is the X event to filter.
5790 Returns non-zero if the event was filtered, caller shall not process
5792 Returns zero if event is wasn't filtered. */
5796 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5798 /* XFilterEvent returns non-zero if the input method has
5799 consumed the event. We pass the frame's X window to
5800 XFilterEvent because that's the one for which the IC
5803 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5804 event
->xclient
.window
);
5806 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5811 static int current_count
;
5812 static int current_finish
;
5813 static struct input_event
*current_hold_quit
;
5815 /* This is the filter function invoked by the GTK event loop.
5816 It is invoked before the XEvent is translated to a GdkEvent,
5817 so we have a chance to act on the event before GTK. */
5818 static GdkFilterReturn
5819 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5821 XEvent
*xev
= (XEvent
*) gxev
;
5824 if (current_count
>= 0)
5826 struct x_display_info
*dpyinfo
;
5828 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5831 /* Filter events for the current X input method.
5832 GTK calls XFilterEvent but not for key press and release,
5833 so we do it here. */
5834 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5836 && x_filter_event (dpyinfo
, xev
))
5839 return GDK_FILTER_REMOVE
;
5844 current_finish
= X_EVENT_NORMAL
;
5847 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5851 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5855 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5856 return GDK_FILTER_REMOVE
;
5858 return GDK_FILTER_CONTINUE
;
5860 #endif /* USE_GTK */
5863 static void xembed_send_message (struct frame
*f
, Time
,
5864 enum xembed_message
,
5865 long detail
, long data1
, long data2
);
5867 /* Handles the XEvent EVENT on display DPYINFO.
5869 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5870 *FINISH is zero if caller should continue reading events.
5871 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5873 We return the number of characters stored into the buffer. */
5876 handle_one_xevent (struct x_display_info
*dpyinfo
, XEvent
*eventptr
,
5877 int *finish
, struct input_event
*hold_quit
)
5880 struct input_event ie
;
5881 struct selection_input_event sie
;
5885 ptrdiff_t nbytes
= 0;
5886 struct frame
*f
= NULL
;
5887 struct coding_system coding
;
5888 XEvent event
= *eventptr
;
5889 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
5890 /* This holds the state XLookupString needs to implement dead keys
5891 and other tricks known as "compose processing". _X Window System_
5892 says that a portable program can't use this, but Stephen Gildea assures
5893 me that letting the compiler initialize it to zeros will work okay. */
5894 static XComposeStatus compose_status
;
5898 *finish
= X_EVENT_NORMAL
;
5900 EVENT_INIT (inev
.ie
);
5901 inev
.ie
.kind
= NO_EVENT
;
5904 if (pending_event_wait
.eventtype
== event
.type
)
5905 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5911 if (event
.xclient
.message_type
5912 == dpyinfo
->Xatom_wm_protocols
5913 && event
.xclient
.format
== 32)
5915 if (event
.xclient
.data
.l
[0]
5916 == dpyinfo
->Xatom_wm_take_focus
)
5918 /* Use x_any_window_to_frame because this
5919 could be the shell widget window
5920 if the frame has no title bar. */
5921 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5923 /* Not quite sure this is needed -pd */
5924 if (f
&& FRAME_XIC (f
))
5925 XSetICFocus (FRAME_XIC (f
));
5927 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5928 instructs the WM to set the input focus automatically for
5929 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5930 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5931 it has set the focus. So, XSetInputFocus below is not
5934 The call to XSetInputFocus below has also caused trouble. In
5935 cases where the XSetInputFocus done by the WM and the one
5936 below are temporally close (on a fast machine), the call
5937 below can generate additional FocusIn events which confuse
5940 /* Since we set WM_TAKE_FOCUS, we must call
5941 XSetInputFocus explicitly. But not if f is null,
5942 since that might be an event for a deleted frame. */
5945 Display
*d
= event
.xclient
.display
;
5946 /* Catch and ignore errors, in case window has been
5947 iconified by a window manager such as GWM. */
5949 XSetInputFocus (d
, event
.xclient
.window
,
5950 /* The ICCCM says this is
5951 the only valid choice. */
5953 event
.xclient
.data
.l
[1]);
5954 /* This is needed to detect the error
5955 if there is an error. */
5957 x_uncatch_errors ();
5959 /* Not certain about handling scroll bars here */
5964 if (event
.xclient
.data
.l
[0]
5965 == dpyinfo
->Xatom_wm_save_yourself
)
5967 /* Save state modify the WM_COMMAND property to
5968 something which can reinstate us. This notifies
5969 the session manager, who's looking for such a
5970 PropertyNotify. Can restart processing when
5971 a keyboard or mouse event arrives. */
5972 /* If we have a session manager, don't set this.
5973 KDE will then start two Emacsen, one for the
5974 session manager and one for this. */
5976 if (! x_session_have_connection ())
5979 f
= x_top_window_to_frame (dpyinfo
,
5980 event
.xclient
.window
);
5981 /* This is just so we only give real data once
5982 for a single Emacs process. */
5983 if (f
== SELECTED_FRAME ())
5984 XSetCommand (FRAME_X_DISPLAY (f
),
5985 event
.xclient
.window
,
5986 initial_argv
, initial_argc
);
5988 XSetCommand (FRAME_X_DISPLAY (f
),
5989 event
.xclient
.window
,
5995 if (event
.xclient
.data
.l
[0]
5996 == dpyinfo
->Xatom_wm_delete_window
)
5998 f
= x_any_window_to_frame (dpyinfo
,
5999 event
.xclient
.window
);
6001 goto OTHER
; /* May be a dialog that is to be removed */
6003 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
6004 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6011 if (event
.xclient
.message_type
6012 == dpyinfo
->Xatom_wm_configure_denied
)
6017 if (event
.xclient
.message_type
6018 == dpyinfo
->Xatom_wm_window_moved
)
6021 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6023 new_x
= event
.xclient
.data
.s
[0];
6024 new_y
= event
.xclient
.data
.s
[1];
6028 f
->left_pos
= new_x
;
6035 if (event
.xclient
.message_type
6036 == dpyinfo
->Xatom_editres
)
6038 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6040 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
6044 #endif /* HACK_EDITRES */
6046 if ((event
.xclient
.message_type
6047 == dpyinfo
->Xatom_DONE
)
6048 || (event
.xclient
.message_type
6049 == dpyinfo
->Xatom_PAGE
))
6051 /* Ghostview job completed. Kill it. We could
6052 reply with "Next" if we received "Page", but we
6053 currently never do because we are interested in
6054 images, only, which should have 1 page. */
6055 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
6056 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6059 x_kill_gs_process (pixmap
, f
);
6060 expose_frame (f
, 0, 0, 0, 0);
6064 #ifdef USE_TOOLKIT_SCROLL_BARS
6065 /* Scroll bar callbacks send a ClientMessage from which
6066 we construct an input_event. */
6067 if (event
.xclient
.message_type
6068 == dpyinfo
->Xatom_Scrollbar
)
6070 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
6071 *finish
= X_EVENT_GOTO_OUT
;
6074 #endif /* USE_TOOLKIT_SCROLL_BARS */
6076 /* XEmbed messages from the embedder (if any). */
6077 if (event
.xclient
.message_type
6078 == dpyinfo
->Xatom_XEMBED
)
6080 enum xembed_message msg
= event
.xclient
.data
.l
[1];
6081 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6082 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6084 *finish
= X_EVENT_GOTO_OUT
;
6088 xft_settings_event (dpyinfo
, &event
);
6090 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6093 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6094 *finish
= X_EVENT_DROP
;
6098 case SelectionNotify
:
6099 dpyinfo
->last_user_time
= event
.xselection
.time
;
6100 #ifdef USE_X_TOOLKIT
6101 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6103 #endif /* not USE_X_TOOLKIT */
6104 x_handle_selection_notify (&event
.xselection
);
6107 case SelectionClear
: /* Someone has grabbed ownership. */
6108 dpyinfo
->last_user_time
= event
.xselectionclear
.time
;
6109 #ifdef USE_X_TOOLKIT
6110 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6112 #endif /* USE_X_TOOLKIT */
6114 XSelectionClearEvent
*eventp
= &(event
.xselectionclear
);
6116 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6117 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6118 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6119 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6123 case SelectionRequest
: /* Someone wants our selection. */
6124 dpyinfo
->last_user_time
= event
.xselectionrequest
.time
;
6125 #ifdef USE_X_TOOLKIT
6126 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6128 #endif /* USE_X_TOOLKIT */
6130 XSelectionRequestEvent
*eventp
= &(event
.xselectionrequest
);
6132 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6133 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6134 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6135 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6136 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6137 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6138 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6142 case PropertyNotify
:
6143 dpyinfo
->last_user_time
= event
.xproperty
.time
;
6144 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
6145 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6146 if (x_handle_net_wm_state (f
, &event
.xproperty
)
6147 && FRAME_ICONIFIED_P (f
)
6148 && f
->output_data
.x
->net_wm_state_hidden_seen
)
6150 /* Gnome shell does not iconify us when C-z is pressed.
6151 It hides the frame. So if our state says we aren't
6152 hidden anymore, treat it as deiconified. */
6153 SET_FRAME_VISIBLE (f
, 1);
6154 SET_FRAME_ICONIFIED (f
, 0);
6155 f
->output_data
.x
->has_been_visible
= 1;
6156 f
->output_data
.x
->net_wm_state_hidden_seen
= 0;
6157 inev
.ie
.kind
= DEICONIFY_EVENT
;
6158 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6161 x_handle_property_notify (&event
.xproperty
);
6162 xft_settings_event (dpyinfo
, &event
);
6165 case ReparentNotify
:
6166 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6170 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6171 x_real_positions (f
, &x
, &y
);
6175 /* Perhaps reparented due to a WM restart. Reset this. */
6176 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6177 FRAME_DISPLAY_INFO (f
)->net_supported_window
= 0;
6179 x_set_frame_alpha (f
);
6184 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6188 /* This seems to be needed for GTK 2.6. */
6189 x_clear_area (event
.xexpose
.display
,
6190 event
.xexpose
.window
,
6191 event
.xexpose
.x
, event
.xexpose
.y
,
6192 event
.xexpose
.width
, event
.xexpose
.height
);
6194 if (!FRAME_VISIBLE_P (f
))
6196 SET_FRAME_VISIBLE (f
, 1);
6197 SET_FRAME_ICONIFIED (f
, 0);
6198 f
->output_data
.x
->has_been_visible
= 1;
6199 SET_FRAME_GARBAGED (f
);
6203 event
.xexpose
.x
, event
.xexpose
.y
,
6204 event
.xexpose
.width
, event
.xexpose
.height
);
6208 #ifndef USE_TOOLKIT_SCROLL_BARS
6209 struct scroll_bar
*bar
;
6211 #if defined USE_LUCID
6212 /* Submenus of the Lucid menu bar aren't widgets
6213 themselves, so there's no way to dispatch events
6214 to them. Recognize this case separately. */
6217 = x_window_to_menu_bar (event
.xexpose
.window
);
6219 xlwmenu_redisplay (widget
);
6221 #endif /* USE_LUCID */
6223 #ifdef USE_TOOLKIT_SCROLL_BARS
6224 /* Dispatch event to the widget. */
6226 #else /* not USE_TOOLKIT_SCROLL_BARS */
6227 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6228 event
.xexpose
.window
);
6231 x_scroll_bar_expose (bar
, &event
);
6232 #ifdef USE_X_TOOLKIT
6235 #endif /* USE_X_TOOLKIT */
6236 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6240 case GraphicsExpose
: /* This occurs when an XCopyArea's
6241 source area was obscured or not
6243 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6247 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6248 event
.xgraphicsexpose
.width
,
6249 event
.xgraphicsexpose
.height
);
6251 #ifdef USE_X_TOOLKIT
6254 #endif /* USE_X_TOOLKIT */
6257 case NoExpose
: /* This occurs when an XCopyArea's
6258 source area was completely
6263 /* Redo the mouse-highlight after the tooltip has gone. */
6264 if (event
.xunmap
.window
== tip_window
)
6267 redo_mouse_highlight ();
6270 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6271 if (f
) /* F may no longer exist if
6272 the frame was deleted. */
6274 bool visible
= FRAME_VISIBLE_P (f
);
6275 /* While a frame is unmapped, display generation is
6276 disabled; you don't want to spend time updating a
6277 display that won't ever be seen. */
6278 SET_FRAME_VISIBLE (f
, 0);
6279 /* We can't distinguish, from the event, whether the window
6280 has become iconified or invisible. So assume, if it
6281 was previously visible, than now it is iconified.
6282 But x_make_frame_invisible clears both
6283 the visible flag and the iconified flag;
6284 and that way, we know the window is not iconified now. */
6285 if (visible
|| FRAME_ICONIFIED_P (f
))
6287 SET_FRAME_ICONIFIED (f
, 1);
6288 inev
.ie
.kind
= ICONIFY_EVENT
;
6289 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6295 if (event
.xmap
.window
== tip_window
)
6296 /* The tooltip has been drawn already. Avoid
6297 the SET_FRAME_GARBAGED below. */
6300 /* We use x_top_window_to_frame because map events can
6301 come for sub-windows and they don't mean that the
6302 frame is visible. */
6303 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6306 bool iconified
= FRAME_ICONIFIED_P (f
);
6307 /* wait_reading_process_output will notice this and update
6308 the frame's display structures.
6309 If we where iconified, we should not set garbaged,
6310 because that stops redrawing on Expose events. This looks
6311 bad if we are called from a recursive event loop
6312 (x_dispatch_event), for example when a dialog is up. */
6314 SET_FRAME_GARBAGED (f
);
6316 /* Check if fullscreen was specified before we where mapped the
6317 first time, i.e. from the command line. */
6318 if (!f
->output_data
.x
->has_been_visible
)
6319 x_check_fullscreen (f
);
6321 SET_FRAME_VISIBLE (f
, 1);
6322 SET_FRAME_ICONIFIED (f
, 0);
6323 f
->output_data
.x
->has_been_visible
= 1;
6327 inev
.ie
.kind
= DEICONIFY_EVENT
;
6328 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6330 else if (! NILP (Vframe_list
) && ! NILP (XCDR (Vframe_list
)))
6331 /* Force a redisplay sooner or later to update the
6332 frame titles in case this is the second frame. */
6333 record_asynch_buffer_change ();
6336 xg_frame_resized (f
, -1, -1);
6343 dpyinfo
->last_user_time
= event
.xkey
.time
;
6344 ignore_next_mouse_click_timeout
= 0;
6346 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6347 /* Dispatch KeyPress events when in menu. */
6348 if (popup_activated ())
6352 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6354 #if ! defined (USE_GTK)
6355 /* If mouse-highlight is an integer, input clears out
6356 mouse highlighting. */
6357 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6359 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)))
6361 clear_mouse_face (hlinfo
);
6362 hlinfo
->mouse_face_hidden
= 1;
6366 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6369 /* Scroll bars consume key events, but we want
6370 the keys to go to the scroll bar's frame. */
6371 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6373 if (widget
&& XmIsScrollBar (widget
))
6375 widget
= XtParent (widget
);
6376 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6379 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6383 KeySym keysym
, orig_keysym
;
6384 /* al%imercury@uunet.uu.net says that making this 81
6385 instead of 80 fixed a bug whereby meta chars made
6388 It seems that some version of XmbLookupString has
6389 a bug of not returning XBufferOverflow in
6390 status_return even if the input is too long to
6391 fit in 81 bytes. So, we must prepare sufficient
6392 bytes for copy_buffer. 513 bytes (256 chars for
6393 two-byte character set) seems to be a fairly good
6394 approximation. -- 2000.8.10 handa@etl.go.jp */
6395 unsigned char copy_buffer
[513];
6396 unsigned char *copy_bufptr
= copy_buffer
;
6397 int copy_bufsiz
= sizeof (copy_buffer
);
6399 Lisp_Object coding_system
= Qlatin_1
;
6403 /* Don't pass keys to GTK. A Tab will shift focus to the
6404 tool bar in GTK 2.4. Keys will still go to menus and
6405 dialogs because in that case popup_activated is TRUE
6407 *finish
= X_EVENT_DROP
;
6411 |= x_emacs_to_x_modifiers (FRAME_DISPLAY_INFO (f
),
6412 extra_keyboard_modifiers
);
6413 modifiers
= event
.xkey
.state
;
6415 /* This will have to go some day... */
6417 /* make_lispy_event turns chars into control chars.
6418 Don't do it here because XLookupString is too eager. */
6419 event
.xkey
.state
&= ~ControlMask
;
6420 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6421 | dpyinfo
->super_mod_mask
6422 | dpyinfo
->hyper_mod_mask
6423 | dpyinfo
->alt_mod_mask
);
6425 /* In case Meta is ComposeCharacter,
6426 clear its status. According to Markus Ehrnsperger
6427 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6428 this enables ComposeCharacter to work whether or
6429 not it is combined with Meta. */
6430 if (modifiers
& dpyinfo
->meta_mod_mask
)
6431 memset (&compose_status
, 0, sizeof (compose_status
));
6436 Status status_return
;
6438 coding_system
= Vlocale_coding_system
;
6439 nbytes
= XmbLookupString (FRAME_XIC (f
),
6440 &event
.xkey
, (char *) copy_bufptr
,
6441 copy_bufsiz
, &keysym
,
6443 if (status_return
== XBufferOverflow
)
6445 copy_bufsiz
= nbytes
+ 1;
6446 copy_bufptr
= alloca (copy_bufsiz
);
6447 nbytes
= XmbLookupString (FRAME_XIC (f
),
6448 &event
.xkey
, (char *) copy_bufptr
,
6449 copy_bufsiz
, &keysym
,
6452 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6453 if (status_return
== XLookupNone
)
6455 else if (status_return
== XLookupChars
)
6460 else if (status_return
!= XLookupKeySym
6461 && status_return
!= XLookupBoth
)
6465 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6466 copy_bufsiz
, &keysym
,
6469 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6470 copy_bufsiz
, &keysym
,
6474 /* If not using XIM/XIC, and a compose sequence is in progress,
6475 we break here. Otherwise, chars_matched is always 0. */
6476 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6479 memset (&compose_status
, 0, sizeof (compose_status
));
6480 orig_keysym
= keysym
;
6482 /* Common for all keysym input events. */
6483 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6485 = x_x_to_emacs_modifiers (FRAME_DISPLAY_INFO (f
), modifiers
);
6486 inev
.ie
.timestamp
= event
.xkey
.time
;
6488 /* First deal with keysyms which have defined
6489 translations to characters. */
6490 if (keysym
>= 32 && keysym
< 128)
6491 /* Avoid explicitly decoding each ASCII character. */
6493 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6494 inev
.ie
.code
= keysym
;
6498 /* Keysyms directly mapped to Unicode characters. */
6499 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6501 if (keysym
< 0x01000080)
6502 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6504 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6505 inev
.ie
.code
= keysym
& 0xFFFFFF;
6509 /* Now non-ASCII. */
6510 if (HASH_TABLE_P (Vx_keysym_table
)
6511 && (c
= Fgethash (make_number (keysym
),
6516 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6517 ? ASCII_KEYSTROKE_EVENT
6518 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6519 inev
.ie
.code
= XFASTINT (c
);
6523 /* Random non-modifier sorts of keysyms. */
6524 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6525 || keysym
== XK_Delete
6526 #ifdef XK_ISO_Left_Tab
6527 || (keysym
>= XK_ISO_Left_Tab
6528 && keysym
<= XK_ISO_Enter
)
6530 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6531 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6533 /* This recognizes the "extended function
6534 keys". It seems there's no cleaner way.
6535 Test IsModifierKey to avoid handling
6536 mode_switch incorrectly. */
6537 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
6539 #ifdef XK_dead_circumflex
6540 || orig_keysym
== XK_dead_circumflex
6542 #ifdef XK_dead_grave
6543 || orig_keysym
== XK_dead_grave
6545 #ifdef XK_dead_tilde
6546 || orig_keysym
== XK_dead_tilde
6548 #ifdef XK_dead_diaeresis
6549 || orig_keysym
== XK_dead_diaeresis
6551 #ifdef XK_dead_macron
6552 || orig_keysym
== XK_dead_macron
6554 #ifdef XK_dead_degree
6555 || orig_keysym
== XK_dead_degree
6557 #ifdef XK_dead_acute
6558 || orig_keysym
== XK_dead_acute
6560 #ifdef XK_dead_cedilla
6561 || orig_keysym
== XK_dead_cedilla
6563 #ifdef XK_dead_breve
6564 || orig_keysym
== XK_dead_breve
6566 #ifdef XK_dead_ogonek
6567 || orig_keysym
== XK_dead_ogonek
6569 #ifdef XK_dead_caron
6570 || orig_keysym
== XK_dead_caron
6572 #ifdef XK_dead_doubleacute
6573 || orig_keysym
== XK_dead_doubleacute
6575 #ifdef XK_dead_abovedot
6576 || orig_keysym
== XK_dead_abovedot
6578 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6579 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6580 /* Any "vendor-specific" key is ok. */
6581 || (orig_keysym
& (1 << 28))
6582 || (keysym
!= NoSymbol
&& nbytes
== 0))
6583 && ! (IsModifierKey (orig_keysym
)
6584 /* The symbols from XK_ISO_Lock
6585 to XK_ISO_Last_Group_Lock
6586 don't have real modifiers but
6587 should be treated similarly to
6588 Mode_switch by Emacs. */
6589 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6590 || (XK_ISO_Lock
<= orig_keysym
6591 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
6595 STORE_KEYSYM_FOR_DEBUG (keysym
);
6596 /* make_lispy_event will convert this to a symbolic
6598 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6599 inev
.ie
.code
= keysym
;
6603 { /* Raw bytes, not keysym. */
6607 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6609 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6611 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6614 if (nchars
< nbytes
)
6616 /* Decode the input data. */
6618 /* The input should be decoded with `coding_system'
6619 which depends on which X*LookupString function
6620 we used just above and the locale. */
6621 setup_coding_system (coding_system
, &coding
);
6622 coding
.src_multibyte
= 0;
6623 coding
.dst_multibyte
= 1;
6624 /* The input is converted to events, thus we can't
6625 handle composition. Anyway, there's no XIM that
6626 gives us composition information. */
6627 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6629 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
6631 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6632 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6633 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6634 nbytes
= coding
.produced
;
6635 nchars
= coding
.produced_char
;
6636 copy_bufptr
= coding
.destination
;
6639 /* Convert the input data to a sequence of
6640 character events. */
6641 for (i
= 0; i
< nbytes
; i
+= len
)
6644 if (nchars
== nbytes
)
6645 ch
= copy_bufptr
[i
], len
= 1;
6647 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6648 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
6649 ? ASCII_KEYSTROKE_EVENT
6650 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6652 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6657 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6659 if (keysym
== NoSymbol
)
6665 /* Don't dispatch this event since XtDispatchEvent calls
6666 XFilterEvent, and two calls in a row may freeze the
6674 dpyinfo
->last_user_time
= event
.xkey
.time
;
6676 /* Don't dispatch this event since XtDispatchEvent calls
6677 XFilterEvent, and two calls in a row may freeze the
6685 dpyinfo
->last_user_time
= event
.xcrossing
.time
;
6686 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6688 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6690 if (f
&& x_mouse_click_focus_ignore_position
)
6691 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6693 /* EnterNotify counts as mouse movement,
6694 so update things that depend on mouse position. */
6695 if (f
&& !f
->output_data
.x
->hourglass_p
)
6696 note_mouse_movement (f
, &event
.xmotion
);
6698 /* We may get an EnterNotify on the buttons in the toolbar. In that
6699 case we moved out of any highlighted area and need to note this. */
6700 if (!f
&& last_mouse_glyph_frame
)
6701 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6706 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6710 dpyinfo
->last_user_time
= event
.xcrossing
.time
;
6711 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6713 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6716 if (f
== hlinfo
->mouse_face_mouse_frame
)
6718 /* If we move outside the frame, then we're
6719 certainly no longer on any text in the frame. */
6720 clear_mouse_face (hlinfo
);
6721 hlinfo
->mouse_face_mouse_frame
= 0;
6724 /* Generate a nil HELP_EVENT to cancel a help-echo.
6725 Do it only if there's something to cancel.
6726 Otherwise, the startup message is cleared when
6727 the mouse leaves the frame. */
6728 if (any_help_event_p
)
6732 /* See comment in EnterNotify above */
6733 else if (last_mouse_glyph_frame
)
6734 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6739 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6744 dpyinfo
->last_user_time
= event
.xmotion
.time
;
6745 previous_help_echo_string
= help_echo_string
;
6746 help_echo_string
= Qnil
;
6748 if (dpyinfo
->grabbed
&& last_mouse_frame
6749 && FRAME_LIVE_P (last_mouse_frame
))
6750 f
= last_mouse_frame
;
6752 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6754 if (hlinfo
->mouse_face_hidden
)
6756 hlinfo
->mouse_face_hidden
= 0;
6757 clear_mouse_face (hlinfo
);
6761 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6767 /* Generate SELECT_WINDOW_EVENTs when needed.
6768 Don't let popup menus influence things (bug#1261). */
6769 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6771 static Lisp_Object last_mouse_window
;
6772 Lisp_Object window
= window_from_coordinates
6773 (f
, event
.xmotion
.x
, event
.xmotion
.y
, 0, 0);
6775 /* Window will be selected only when it is not selected now and
6776 last mouse movement event was not in it. Minibuffer window
6777 will be selected only when it is active. */
6778 if (WINDOWP (window
)
6779 && !EQ (window
, last_mouse_window
)
6780 && !EQ (window
, selected_window
)
6781 /* For click-to-focus window managers
6782 create event iff we don't leave the
6784 && (focus_follows_mouse
6785 || (EQ (XWINDOW (window
)->frame
,
6786 XWINDOW (selected_window
)->frame
))))
6788 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6789 inev
.ie
.frame_or_window
= window
;
6791 /* Remember the last window where we saw the mouse. */
6792 last_mouse_window
= window
;
6794 if (!note_mouse_movement (f
, &event
.xmotion
))
6795 help_echo_string
= previous_help_echo_string
;
6799 #ifndef USE_TOOLKIT_SCROLL_BARS
6800 struct scroll_bar
*bar
6801 = x_window_to_scroll_bar (event
.xmotion
.display
,
6802 event
.xmotion
.window
);
6805 x_scroll_bar_note_movement (bar
, &event
.xmotion
);
6806 #endif /* USE_TOOLKIT_SCROLL_BARS */
6808 /* If we move outside the frame, then we're
6809 certainly no longer on any text in the frame. */
6810 clear_mouse_face (hlinfo
);
6813 /* If the contents of the global variable help_echo_string
6814 has changed, generate a HELP_EVENT. */
6815 if (!NILP (help_echo_string
)
6816 || !NILP (previous_help_echo_string
))
6821 case ConfigureNotify
:
6822 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6825 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6826 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6828 xg_frame_resized (f
, event
.xconfigure
.width
,
6829 event
.xconfigure
.height
);
6835 #ifndef USE_X_TOOLKIT
6837 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6838 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6840 /* In the toolkit version, change_frame_size
6841 is called by the code that handles resizing
6842 of the EmacsFrame widget. */
6844 /* Even if the number of character rows and columns has
6845 not changed, the font size may have changed, so we need
6846 to check the pixel dimensions as well. */
6847 if (columns
!= FRAME_COLS (f
)
6848 || rows
!= FRAME_LINES (f
)
6849 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6850 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6852 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6853 SET_FRAME_GARBAGED (f
);
6854 cancel_mouse_face (f
);
6857 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6858 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6859 #endif /* not USE_GTK */
6863 /* GTK creates windows but doesn't map them.
6864 Only get real positions when mapped. */
6865 if (FRAME_GTK_OUTER_WIDGET (f
)
6866 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6869 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6873 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6874 xic_set_statusarea (f
);
6883 /* If we decide we want to generate an event to be seen
6884 by the rest of Emacs, we put it here. */
6885 bool tool_bar_p
= 0;
6887 memset (&compose_status
, 0, sizeof (compose_status
));
6888 last_mouse_glyph_frame
= 0;
6889 dpyinfo
->last_user_time
= event
.xbutton
.time
;
6891 if (dpyinfo
->grabbed
6893 && FRAME_LIVE_P (last_mouse_frame
))
6894 f
= last_mouse_frame
;
6896 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6899 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6904 #if ! defined (USE_GTK)
6905 /* Is this in the tool-bar? */
6906 if (WINDOWP (f
->tool_bar_window
)
6907 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6910 int x
= event
.xbutton
.x
;
6911 int y
= event
.xbutton
.y
;
6913 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6914 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6916 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6917 handle_tool_bar_click
6918 (f
, x
, y
, event
.xbutton
.type
== ButtonPress
,
6919 x_x_to_emacs_modifiers (dpyinfo
, event
.xbutton
.state
));
6921 #endif /* !USE_GTK */
6924 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6925 if (! popup_activated ())
6928 if (ignore_next_mouse_click_timeout
)
6930 if (event
.type
== ButtonPress
6931 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6933 ignore_next_mouse_click_timeout
= 0;
6934 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6936 if (event
.type
== ButtonRelease
)
6937 ignore_next_mouse_click_timeout
= 0;
6940 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6942 if (FRAME_X_EMBEDDED_P (f
))
6943 xembed_send_message (f
, event
.xbutton
.time
,
6944 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6948 struct scroll_bar
*bar
6949 = x_window_to_scroll_bar (event
.xbutton
.display
,
6950 event
.xbutton
.window
);
6952 #ifdef USE_TOOLKIT_SCROLL_BARS
6953 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6955 if (bar
&& event
.xbutton
.state
& ControlMask
)
6957 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6958 *finish
= X_EVENT_DROP
;
6960 #else /* not USE_TOOLKIT_SCROLL_BARS */
6962 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6963 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6966 if (event
.type
== ButtonPress
)
6968 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6969 last_mouse_frame
= f
;
6972 last_tool_bar_item
= -1;
6975 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6977 /* Ignore any mouse motion that happened before this event;
6978 any subsequent mouse-movement Emacs events should reflect
6979 only motion after the ButtonPress/Release. */
6983 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6984 f
= x_menubar_window_to_frame (dpyinfo
, &event
);
6985 /* For a down-event in the menu bar,
6986 don't pass it to Xt right now.
6987 Instead, save it away
6988 and we will pass it to Xt from kbd_buffer_get_event.
6989 That way, we can run some Lisp code first. */
6990 if (! popup_activated ()
6992 /* Gtk+ menus only react to the first three buttons. */
6993 && event
.xbutton
.button
< 3
6995 && f
&& event
.type
== ButtonPress
6996 /* Verify the event is really within the menu bar
6997 and not just sent to it due to grabbing. */
6998 && event
.xbutton
.x
>= 0
6999 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
7000 && event
.xbutton
.y
>= 0
7001 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
7002 && event
.xbutton
.same_screen
)
7004 SET_SAVED_BUTTON_EVENT
;
7005 *finish
= X_EVENT_DROP
;
7009 #endif /* USE_X_TOOLKIT || USE_GTK */
7013 case CirculateNotify
:
7016 case CirculateRequest
:
7019 case VisibilityNotify
:
7023 /* Someone has changed the keyboard mapping - update the
7025 switch (event
.xmapping
.request
)
7027 case MappingModifier
:
7028 x_find_modifier_meanings (dpyinfo
);
7029 /* This is meant to fall through. */
7030 case MappingKeyboard
:
7031 XRefreshKeyboardMapping (&event
.xmapping
);
7036 xft_settings_event (dpyinfo
, &event
);
7041 #ifdef USE_X_TOOLKIT
7043 if (*finish
!= X_EVENT_DROP
)
7044 XtDispatchEvent (&event
);
7046 #endif /* USE_X_TOOLKIT */
7051 if (inev
.ie
.kind
!= NO_EVENT
)
7053 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7058 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7063 XSETFRAME (frame
, f
);
7069 any_help_event_p
= 1;
7070 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7071 help_echo_object
, help_echo_pos
);
7075 help_echo_string
= Qnil
;
7076 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7086 #if defined USE_GTK || defined USE_X_TOOLKIT
7088 /* Handles the XEvent EVENT on display DISPLAY.
7089 This is used for event loops outside the normal event handling,
7090 i.e. looping while a popup menu or a dialog is posted.
7092 Returns the value handle_one_xevent sets in the finish argument. */
7094 x_dispatch_event (XEvent
*event
, Display
*display
)
7096 struct x_display_info
*dpyinfo
;
7097 int finish
= X_EVENT_NORMAL
;
7099 dpyinfo
= x_display_info_for_display (display
);
7102 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7109 /* Read events coming from the X server.
7110 Return as soon as there are no more events to be read.
7112 Return the number of characters stored into the buffer,
7113 thus pretending to be `read' (except the characters we store
7114 in the keyboard buffer can be multibyte, so are not necessarily
7118 XTread_socket (struct terminal
*terminal
, struct input_event
*hold_quit
)
7121 int event_found
= 0;
7125 /* So people can tell when we have read the available input. */
7126 input_signal_count
++;
7128 /* For debugging, this gives a way to fake an I/O error. */
7129 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7131 XTread_socket_fake_io_error
= 0;
7132 x_io_error_quitter (terminal
->display_info
.x
->display
);
7136 while (XPending (terminal
->display_info
.x
->display
))
7141 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7144 /* Filter events for the current X input method. */
7145 if (x_filter_event (terminal
->display_info
.x
, &event
))
7150 count
+= handle_one_xevent (terminal
->display_info
.x
,
7151 &event
, &finish
, hold_quit
);
7153 if (finish
== X_EVENT_GOTO_OUT
)
7161 /* For GTK we must use the GTK event loop. But XEvents gets passed
7162 to our filter function above, and then to the big event switch.
7163 We use a bunch of globals to communicate with our filter function,
7164 that is kind of ugly, but it works.
7166 There is no way to do one display at the time, GTK just does events
7167 from all displays. */
7169 while (gtk_events_pending ())
7171 current_count
= count
;
7172 current_hold_quit
= hold_quit
;
7174 gtk_main_iteration ();
7176 count
= current_count
;
7178 current_hold_quit
= 0;
7180 if (current_finish
== X_EVENT_GOTO_OUT
)
7183 #endif /* USE_GTK */
7185 /* On some systems, an X bug causes Emacs to get no more events
7186 when the window is destroyed. Detect that. (1994.) */
7189 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7190 One XNOOP in 100 loops will make Emacs terminate.
7191 B. Bretthauer, 1994 */
7193 if (x_noop_count
>= 100)
7197 if (next_noop_dpyinfo
== 0)
7198 next_noop_dpyinfo
= x_display_list
;
7200 XNoOp (next_noop_dpyinfo
->display
);
7202 /* Each time we get here, cycle through the displays now open. */
7203 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7207 /* If the focus was just given to an auto-raising frame,
7209 /* ??? This ought to be able to handle more than one such frame. */
7210 if (pending_autoraise_frame
)
7212 x_raise_frame (pending_autoraise_frame
);
7213 pending_autoraise_frame
= 0;
7224 /***********************************************************************
7226 ***********************************************************************/
7228 /* Set clipping for output in glyph row ROW. W is the window in which
7229 we operate. GC is the graphics context to set clipping in.
7231 ROW may be a text row or, e.g., a mode line. Text rows must be
7232 clipped to the interior of the window dedicated to text display,
7233 mode lines must be clipped to the whole window. */
7236 x_clip_to_row (struct window
*w
, struct glyph_row
*row
,
7237 enum glyph_row_area area
, GC gc
)
7239 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7240 XRectangle clip_rect
;
7241 int window_x
, window_y
, window_width
;
7243 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7245 clip_rect
.x
= window_x
;
7246 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7247 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7248 clip_rect
.width
= window_width
;
7249 clip_rect
.height
= row
->visible_height
;
7251 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7255 /* Draw a hollow box cursor on window W in glyph row ROW. */
7258 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7260 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7261 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
7262 Display
*dpy
= FRAME_X_DISPLAY (f
);
7265 struct glyph
*cursor_glyph
;
7268 /* Get the glyph the cursor is on. If we can't tell because
7269 the current matrix is invalid or such, give up. */
7270 cursor_glyph
= get_phys_cursor_glyph (w
);
7271 if (cursor_glyph
== NULL
)
7274 /* Compute frame-relative coordinates for phys cursor. */
7275 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7276 wd
= w
->phys_cursor_width
;
7278 /* The foreground of cursor_gc is typically the same as the normal
7279 background color, which can cause the cursor box to be invisible. */
7280 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7281 if (dpyinfo
->scratch_cursor_gc
)
7282 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7284 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7285 GCForeground
, &xgcv
);
7286 gc
= dpyinfo
->scratch_cursor_gc
;
7288 /* Set clipping, draw the rectangle, and reset clipping again. */
7289 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7290 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7291 XSetClipMask (dpy
, gc
, None
);
7295 /* Draw a bar cursor on window W in glyph row ROW.
7297 Implementation note: One would like to draw a bar cursor with an
7298 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7299 Unfortunately, I didn't find a font yet that has this property set.
7303 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7305 struct frame
*f
= XFRAME (w
->frame
);
7306 struct glyph
*cursor_glyph
;
7308 /* If cursor is out of bounds, don't draw garbage. This can happen
7309 in mini-buffer windows when switching between echo area glyphs
7311 cursor_glyph
= get_phys_cursor_glyph (w
);
7312 if (cursor_glyph
== NULL
)
7315 /* If on an image, draw like a normal cursor. That's usually better
7316 visible than drawing a bar, esp. if the image is large so that
7317 the bar might not be in the window. */
7318 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7320 struct glyph_row
*r
;
7321 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7322 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
7326 Display
*dpy
= FRAME_X_DISPLAY (f
);
7327 Window window
= FRAME_X_WINDOW (f
);
7328 GC gc
= FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7329 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7330 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7333 /* If the glyph's background equals the color we normally draw
7334 the bars cursor in, the bar cursor in its normal color is
7335 invisible. Use the glyph's foreground color instead in this
7336 case, on the assumption that the glyph's colors are chosen so
7337 that the glyph is legible. */
7338 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7339 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7341 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7342 xgcv
.graphics_exposures
= 0;
7345 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7348 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7349 FRAME_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7352 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7354 if (kind
== BAR_CURSOR
)
7356 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7359 width
= FRAME_CURSOR_WIDTH (f
);
7360 width
= min (cursor_glyph
->pixel_width
, width
);
7362 w
->phys_cursor_width
= width
;
7364 /* If the character under cursor is R2L, draw the bar cursor
7365 on the right of its glyph, rather than on the left. */
7366 if ((cursor_glyph
->resolved_level
& 1) != 0)
7367 x
+= cursor_glyph
->pixel_width
- width
;
7369 XFillRectangle (dpy
, window
, gc
, x
,
7370 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7371 width
, row
->height
);
7375 int dummy_x
, dummy_y
, dummy_h
;
7378 width
= row
->height
;
7380 width
= min (row
->height
, width
);
7382 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7383 &dummy_y
, &dummy_h
);
7385 XFillRectangle (dpy
, window
, gc
,
7386 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7387 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7388 row
->height
- width
),
7389 w
->phys_cursor_width
, width
);
7392 XSetClipMask (dpy
, gc
, None
);
7397 /* RIF: Define cursor CURSOR on frame F. */
7400 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7402 if (!f
->pointer_invisible
7403 && f
->output_data
.x
->current_cursor
!= cursor
)
7404 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7405 f
->output_data
.x
->current_cursor
= cursor
;
7409 /* RIF: Clear area on frame F. */
7412 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7414 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), x
, y
, width
, height
);
7416 /* Must queue a redraw, because scroll bars might have been cleared. */
7417 if (FRAME_GTK_WIDGET (f
))
7418 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7423 /* RIF: Draw cursor on window W. */
7426 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
,
7427 int y
, enum text_cursor_kinds cursor_type
,
7428 int cursor_width
, bool on_p
, bool active_p
)
7430 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7434 w
->phys_cursor_type
= cursor_type
;
7435 w
->phys_cursor_on_p
= 1;
7437 if (glyph_row
->exact_window_width_line_p
7438 && (glyph_row
->reversed_p
7439 ? (w
->phys_cursor
.hpos
< 0)
7440 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7442 glyph_row
->cursor_in_fringe_p
= 1;
7443 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7447 switch (cursor_type
)
7449 case HOLLOW_BOX_CURSOR
:
7450 x_draw_hollow_cursor (w
, glyph_row
);
7453 case FILLED_BOX_CURSOR
:
7454 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7458 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7462 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7466 w
->phys_cursor_width
= 0;
7475 if (w
== XWINDOW (f
->selected_window
))
7476 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7477 xic_set_preeditarea (w
, x
, y
);
7481 XFlush (FRAME_X_DISPLAY (f
));
7487 /* Make the x-window of frame F use the gnu icon bitmap. */
7490 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7492 ptrdiff_t bitmap_id
;
7494 if (FRAME_X_WINDOW (f
) == 0)
7497 /* Free up our existing icon bitmap and mask if any. */
7498 if (f
->output_data
.x
->icon_bitmap
> 0)
7499 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7500 f
->output_data
.x
->icon_bitmap
= 0;
7505 /* Use gtk_window_set_icon_from_file () if available,
7506 It's not restricted to bitmaps */
7507 if (xg_set_icon (f
, file
))
7509 #endif /* USE_GTK */
7510 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7511 x_create_bitmap_mask (f
, bitmap_id
);
7515 /* Create the GNU bitmap and mask if necessary. */
7516 if (FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7522 if (xg_set_icon (f
, xg_default_icon_file
)
7523 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7526 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7528 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7530 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7534 /* If all else fails, use the (black and white) xbm image. */
7537 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
7538 gnu_xbm_width
, gnu_xbm_height
);
7542 FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7543 x_create_bitmap_mask (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7547 /* The first time we create the GNU bitmap and mask,
7548 this increments the ref-count one extra time.
7549 As a result, the GNU bitmap and mask are never freed.
7550 That way, we don't have to worry about allocating it again. */
7551 x_reference_bitmap (f
, FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
);
7553 bitmap_id
= FRAME_DISPLAY_INFO (f
)->icon_bitmap_id
;
7556 x_wm_set_icon_pixmap (f
, bitmap_id
);
7557 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7563 /* Make the x-window of frame F use a rectangle with text.
7564 Use ICON_NAME as the text. */
7567 x_text_icon (struct frame
*f
, const char *icon_name
)
7569 if (FRAME_X_WINDOW (f
) == 0)
7574 text
.value
= (unsigned char *) icon_name
;
7575 text
.encoding
= XA_STRING
;
7577 text
.nitems
= strlen (icon_name
);
7578 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7581 if (f
->output_data
.x
->icon_bitmap
> 0)
7582 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7583 f
->output_data
.x
->icon_bitmap
= 0;
7584 x_wm_set_icon_pixmap (f
, 0);
7589 #define X_ERROR_MESSAGE_SIZE 200
7591 /* If non-nil, this should be a string.
7592 It means catch X errors and store the error message in this string.
7594 The reason we use a stack is that x_catch_error/x_uncatch_error can
7595 be called from a signal handler.
7598 struct x_error_message_stack
{
7599 char string
[X_ERROR_MESSAGE_SIZE
];
7601 struct x_error_message_stack
*prev
;
7603 static struct x_error_message_stack
*x_error_message
;
7605 /* An X error handler which stores the error message in
7606 *x_error_message. This is called from x_error_handler if
7607 x_catch_errors is in effect. */
7610 x_error_catcher (Display
*display
, XErrorEvent
*event
)
7612 XGetErrorText (display
, event
->error_code
,
7613 x_error_message
->string
,
7614 X_ERROR_MESSAGE_SIZE
);
7617 /* Begin trapping X errors for display DPY. Actually we trap X errors
7618 for all displays, but DPY should be the display you are actually
7621 After calling this function, X protocol errors no longer cause
7622 Emacs to exit; instead, they are recorded in the string
7623 stored in *x_error_message.
7625 Calling x_check_errors signals an Emacs error if an X error has
7626 occurred since the last call to x_catch_errors or x_check_errors.
7628 Calling x_uncatch_errors resumes the normal error handling. */
7631 x_catch_errors (Display
*dpy
)
7633 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
7635 /* Make sure any errors from previous requests have been dealt with. */
7639 data
->string
[0] = 0;
7640 data
->prev
= x_error_message
;
7641 x_error_message
= data
;
7644 /* Undo the last x_catch_errors call.
7645 DPY should be the display that was passed to x_catch_errors. */
7648 x_uncatch_errors (void)
7650 struct x_error_message_stack
*tmp
;
7654 /* The display may have been closed before this function is called.
7655 Check if it is still open before calling XSync. */
7656 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7657 XSync (x_error_message
->dpy
, False
);
7659 tmp
= x_error_message
;
7660 x_error_message
= x_error_message
->prev
;
7665 /* If any X protocol errors have arrived since the last call to
7666 x_catch_errors or x_check_errors, signal an Emacs error using
7667 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7670 x_check_errors (Display
*dpy
, const char *format
)
7672 /* Make sure to catch any errors incurred so far. */
7675 if (x_error_message
->string
[0])
7677 char string
[X_ERROR_MESSAGE_SIZE
];
7678 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7679 x_uncatch_errors ();
7680 error (format
, string
);
7684 /* Nonzero if we had any X protocol errors
7685 since we did x_catch_errors on DPY. */
7688 x_had_errors_p (Display
*dpy
)
7690 /* Make sure to catch any errors incurred so far. */
7693 return x_error_message
->string
[0] != 0;
7696 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7699 x_clear_errors (Display
*dpy
)
7701 x_error_message
->string
[0] = 0;
7704 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7705 * idea. --lorentey */
7706 /* Close off all unclosed x_catch_errors calls. */
7709 x_fully_uncatch_errors (void)
7711 while (x_error_message
)
7712 x_uncatch_errors ();
7717 static unsigned int x_wire_count
;
7720 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7725 /************************************************************************
7727 ************************************************************************/
7729 /* Error message passed to x_connection_closed. */
7731 static char *error_msg
;
7733 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7734 the text of an error message that lead to the connection loss. */
7737 x_connection_closed (Display
*dpy
, const char *error_message
)
7739 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7740 Lisp_Object frame
, tail
;
7741 ptrdiff_t idx
= SPECPDL_INDEX ();
7743 error_msg
= alloca (strlen (error_message
) + 1);
7744 strcpy (error_msg
, error_message
);
7746 /* Inhibit redisplay while frames are being deleted. */
7747 specbind (Qinhibit_redisplay
, Qt
);
7751 /* Protect display from being closed when we delete the last
7753 dpyinfo
->reference_count
++;
7754 dpyinfo
->terminal
->reference_count
++;
7757 /* First delete frames whose mini-buffers are on frames
7758 that are on the dead display. */
7759 FOR_EACH_FRAME (tail
, frame
)
7761 Lisp_Object minibuf_frame
;
7763 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7764 if (FRAME_X_P (XFRAME (frame
))
7765 && FRAME_X_P (XFRAME (minibuf_frame
))
7766 && ! EQ (frame
, minibuf_frame
)
7767 && FRAME_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7768 delete_frame (frame
, Qnoelisp
);
7771 /* Now delete all remaining frames on the dead display.
7772 We are now sure none of these is used as the mini-buffer
7773 for another frame that we need to delete. */
7774 FOR_EACH_FRAME (tail
, frame
)
7775 if (FRAME_X_P (XFRAME (frame
))
7776 && FRAME_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7778 /* Set this to t so that delete_frame won't get confused
7779 trying to find a replacement. */
7780 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
7781 delete_frame (frame
, Qnoelisp
);
7784 /* If DPYINFO is null, this means we didn't open the display in the
7785 first place, so don't try to close it. */
7788 /* We can not call XtCloseDisplay here because it calls XSync.
7789 XSync inside the error handler apparently hangs Emacs. On
7790 current Xt versions, this isn't needed either. */
7792 /* A long-standing GTK bug prevents proper disconnect handling
7793 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
7794 the resulting Glib error message loop filled a user's disk.
7795 To avoid this, kill Emacs unconditionally on disconnect. */
7796 shut_down_emacs (0, Qnil
);
7797 fprintf (stderr
, "%s\n\
7798 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
7799 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
7800 For details, see etc/PROBLEMS.\n",
7803 #endif /* USE_GTK */
7805 /* Indicate that this display is dead. */
7806 dpyinfo
->display
= 0;
7808 dpyinfo
->reference_count
--;
7809 dpyinfo
->terminal
->reference_count
--;
7810 if (dpyinfo
->reference_count
!= 0)
7811 /* We have just closed all frames on this display. */
7816 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7817 Fdelete_terminal (tmp
, Qnoelisp
);
7821 if (terminal_list
== 0)
7823 fprintf (stderr
, "%s\n", error_msg
);
7824 Fkill_emacs (make_number (70));
7828 totally_unblock_input ();
7830 unbind_to (idx
, Qnil
);
7831 clear_waiting_for_input ();
7833 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
7834 IF_LINT (if (! terminal_list
) return; )
7836 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7837 longjmp), because returning from this function would get us back into
7838 Xlib's code which will directly call `exit'. */
7839 error ("%s", error_msg
);
7842 /* We specifically use it before defining it, so that gcc doesn't inline it,
7843 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7844 static void x_error_quitter (Display
*, XErrorEvent
*);
7846 /* This is the first-level handler for X protocol errors.
7847 It calls x_error_quitter or x_error_catcher. */
7850 x_error_handler (Display
*display
, XErrorEvent
*event
)
7852 #if defined USE_GTK && defined HAVE_GTK3
7853 if ((event
->error_code
== BadMatch
|| event
->error_code
== BadWindow
)
7854 && event
->request_code
== X_SetInputFocus
)
7860 if (x_error_message
)
7861 x_error_catcher (display
, event
);
7863 x_error_quitter (display
, event
);
7867 /* This is the usual handler for X protocol errors.
7868 It kills all frames on the display that we got the error for.
7869 If that was the only one, it prints an error message and kills Emacs. */
7871 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7873 /* On older GCC versions, just putting x_error_quitter
7874 after x_error_handler prevents inlining into the former. */
7876 static void NO_INLINE
7877 x_error_quitter (Display
*display
, XErrorEvent
*event
)
7879 char buf
[256], buf1
[356];
7881 /* Ignore BadName errors. They can happen because of fonts
7882 or colors that are not defined. */
7884 if (event
->error_code
== BadName
)
7887 /* Note that there is no real way portable across R3/R4 to get the
7888 original error handler. */
7890 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
7891 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7892 buf
, event
->request_code
);
7893 x_connection_closed (display
, buf1
);
7897 /* This is the handler for X IO errors, always.
7898 It kills all frames on the display that we lost touch with.
7899 If that was the only one, it prints an error message and kills Emacs. */
7902 x_io_error_quitter (Display
*display
)
7906 snprintf (buf
, sizeof buf
, "Connection lost to X server `%s'",
7907 DisplayString (display
));
7908 x_connection_closed (display
, buf
);
7912 /* Changing the font of the frame. */
7914 /* Give frame F the font FONT-OBJECT as its default font. The return
7915 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7916 frame. If it is negative, generate a new fontset from
7920 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7922 struct font
*font
= XFONT_OBJECT (font_object
);
7925 fontset
= fontset_from_font (font_object
);
7926 FRAME_FONTSET (f
) = fontset
;
7927 if (FRAME_FONT (f
) == font
)
7928 /* This font is already set in frame F. There's nothing more to
7932 FRAME_FONT (f
) = font
;
7933 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7934 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7935 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7937 compute_fringe_widths (f
, 1);
7939 /* Compute the scroll bar width in character columns. */
7940 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7942 int wid
= FRAME_COLUMN_WIDTH (f
);
7943 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7944 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7948 int wid
= FRAME_COLUMN_WIDTH (f
);
7949 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7952 if (FRAME_X_WINDOW (f
) != 0)
7954 /* Don't change the size of a tip frame; there's no point in
7955 doing it because it's done in Fx_show_tip, and it leads to
7956 problems because the tip frame has no widget. */
7957 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7958 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7963 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7966 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
7975 /***********************************************************************
7977 ***********************************************************************/
7983 /* XIM destroy callback function, which is called whenever the
7984 connection to input method XIM dies. CLIENT_DATA contains a
7985 pointer to the x_display_info structure corresponding to XIM. */
7988 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
7990 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7991 Lisp_Object frame
, tail
;
7995 /* No need to call XDestroyIC.. */
7996 FOR_EACH_FRAME (tail
, frame
)
7998 struct frame
*f
= XFRAME (frame
);
7999 if (FRAME_X_P (f
) && FRAME_DISPLAY_INFO (f
) == dpyinfo
)
8001 FRAME_XIC (f
) = NULL
;
8002 xic_free_xfontset (f
);
8006 /* No need to call XCloseIM. */
8007 dpyinfo
->xim
= NULL
;
8008 XFree (dpyinfo
->xim_styles
);
8012 #endif /* HAVE_X11R6 */
8015 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8016 extern char *XSetIMValues (XIM
, ...);
8019 /* Open the connection to the XIM server on display DPYINFO.
8020 RESOURCE_NAME is the resource name Emacs uses. */
8023 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
8031 XCloseIM (dpyinfo
->xim
);
8032 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8039 XIMCallback destroy
;
8042 /* Get supported styles and XIM values. */
8043 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8046 destroy
.callback
= xim_destroy_callback
;
8047 destroy
.client_data
= (XPointer
)dpyinfo
;
8048 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8054 #endif /* HAVE_XIM */
8055 dpyinfo
->xim
= NULL
;
8059 #ifdef HAVE_X11R6_XIM
8061 /* XIM instantiate callback function, which is called whenever an XIM
8062 server is available. DISPLAY is the display of the XIM.
8063 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8064 when the callback was registered. */
8067 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
8069 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8070 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8072 /* We don't support multiple XIM connections. */
8076 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8078 /* Create XIC for the existing frames on the same display, as long
8079 as they have no XIC. */
8080 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8082 Lisp_Object tail
, frame
;
8085 FOR_EACH_FRAME (tail
, frame
)
8087 struct frame
*f
= XFRAME (frame
);
8090 && FRAME_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8091 if (FRAME_XIC (f
) == NULL
)
8093 create_frame_xic (f
);
8094 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8095 xic_set_statusarea (f
);
8096 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8098 struct window
*w
= XWINDOW (f
->selected_window
);
8099 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8108 #endif /* HAVE_X11R6_XIM */
8111 /* Open a connection to the XIM server on display DPYINFO.
8112 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8113 connection only at the first time. On X11R6, open the connection
8114 in the XIM instantiate callback function. */
8117 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
8119 dpyinfo
->xim
= NULL
;
8123 #ifdef HAVE_X11R6_XIM
8124 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
8126 dpyinfo
->xim_callback_data
= xim_inst
;
8127 xim_inst
->dpyinfo
= dpyinfo
;
8128 xim_inst
->resource_name
= xstrdup (resource_name
);
8129 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8130 resource_name
, emacs_class
,
8131 xim_instantiate_callback
,
8132 /* This is XPointer in XFree86
8133 but (XPointer *) on Tru64, at
8134 least, hence the configure test. */
8135 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8136 #else /* not HAVE_X11R6_XIM */
8137 xim_open_dpy (dpyinfo
, resource_name
);
8138 #endif /* not HAVE_X11R6_XIM */
8140 #endif /* HAVE_XIM */
8144 /* Close the connection to the XIM server on display DPYINFO. */
8147 xim_close_dpy (struct x_display_info
*dpyinfo
)
8152 #ifdef HAVE_X11R6_XIM
8153 if (dpyinfo
->display
)
8154 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8156 xim_instantiate_callback
, NULL
);
8157 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8158 xfree (dpyinfo
->xim_callback_data
);
8159 #endif /* HAVE_X11R6_XIM */
8160 if (dpyinfo
->display
)
8161 XCloseIM (dpyinfo
->xim
);
8162 dpyinfo
->xim
= NULL
;
8163 XFree (dpyinfo
->xim_styles
);
8165 #endif /* HAVE_XIM */
8168 #endif /* not HAVE_X11R6_XIM */
8172 /* Calculate the absolute position in frame F
8173 from its current recorded position values and gravity. */
8176 x_calc_absolute_position (struct frame
*f
)
8178 int flags
= f
->size_hint_flags
;
8180 /* We have nothing to do if the current position
8181 is already for the top-left corner. */
8182 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8185 /* Treat negative positions as relative to the leftmost bottommost
8186 position that fits on the screen. */
8187 if (flags
& XNegative
)
8188 f
->left_pos
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
8189 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8192 int height
= FRAME_PIXEL_HEIGHT (f
);
8194 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8195 /* Something is fishy here. When using Motif, starting Emacs with
8196 `-g -0-0', the frame appears too low by a few pixels.
8198 This seems to be so because initially, while Emacs is starting,
8199 the column widget's height and the frame's pixel height are
8200 different. The column widget's height is the right one. In
8201 later invocations, when Emacs is up, the frame's pixel height
8204 It's not obvious where the initial small difference comes from.
8205 2000-12-01, gerd. */
8207 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8210 if (flags
& YNegative
)
8211 f
->top_pos
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
8212 - height
+ f
->top_pos
;
8215 /* The left_pos and top_pos
8216 are now relative to the top and left screen edges,
8217 so the flags should correspond. */
8218 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8221 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8222 to really change the position, and 0 when calling from
8223 x_make_frame_visible (in that case, XOFF and YOFF are the current
8224 position values). It is -1 when calling from x_set_frame_parameters,
8225 which means, do adjust for borders but don't change the gravity. */
8228 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8230 int modified_top
, modified_left
;
8232 if (change_gravity
> 0)
8236 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8238 f
->size_hint_flags
|= XNegative
;
8240 f
->size_hint_flags
|= YNegative
;
8241 f
->win_gravity
= NorthWestGravity
;
8243 x_calc_absolute_position (f
);
8246 x_wm_set_size_hint (f
, (long) 0, 0);
8248 modified_left
= f
->left_pos
;
8249 modified_top
= f
->top_pos
;
8251 if (change_gravity
!= 0 && FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8253 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8254 than the WM decorations. So we use the calculated offset instead
8255 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8256 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8257 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8260 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8261 modified_left
, modified_top
);
8263 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8264 FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8267 /* change_gravity is non-zero when this function is called from Lisp to
8268 programmatically move a frame. In that case, we call
8269 x_check_expected_move to discover if we have a "Type A" or "Type B"
8270 window manager, and, for a "Type A" window manager, adjust the position
8273 We call x_check_expected_move if a programmatic move occurred, and
8274 either the window manager type (A/B) is unknown or it is Type A but we
8275 need to compute the top/left offset adjustment for this frame. */
8277 if (change_gravity
!= 0 &&
8278 (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8279 || (FRAME_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8280 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8281 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8282 x_check_expected_move (f
, modified_left
, modified_top
);
8287 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8288 on the root window for frame F contains ATOMNAME.
8289 This is how a WM check shall be done according to the Window Manager
8290 Specification/Extended Window Manager Hints at
8291 http://freedesktop.org/wiki/Specifications/wm-spec. */
8294 wm_supports (struct frame
*f
, Atom want_atom
)
8297 unsigned long actual_size
, bytes_remaining
;
8298 int i
, rc
, actual_format
;
8299 Window wmcheck_window
;
8300 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8301 Window target_window
= dpyinfo
->root_window
;
8302 long max_len
= 65536;
8303 Display
*dpy
= FRAME_X_DISPLAY (f
);
8304 unsigned char *tmp_data
= NULL
;
8305 Atom target_type
= XA_WINDOW
;
8309 x_catch_errors (dpy
);
8310 rc
= XGetWindowProperty (dpy
, target_window
,
8311 dpyinfo
->Xatom_net_supporting_wm_check
,
8312 0, max_len
, False
, target_type
,
8313 &actual_type
, &actual_format
, &actual_size
,
8314 &bytes_remaining
, &tmp_data
);
8316 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8318 if (tmp_data
) XFree (tmp_data
);
8319 x_uncatch_errors ();
8324 wmcheck_window
= *(Window
*) tmp_data
;
8327 /* Check if window exists. */
8328 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8330 if (x_had_errors_p (dpy
))
8332 x_uncatch_errors ();
8337 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8339 /* Window changed, reload atoms */
8340 if (dpyinfo
->net_supported_atoms
!= NULL
)
8341 XFree (dpyinfo
->net_supported_atoms
);
8342 dpyinfo
->net_supported_atoms
= NULL
;
8343 dpyinfo
->nr_net_supported_atoms
= 0;
8344 dpyinfo
->net_supported_window
= 0;
8346 target_type
= XA_ATOM
;
8348 rc
= XGetWindowProperty (dpy
, target_window
,
8349 dpyinfo
->Xatom_net_supported
,
8350 0, max_len
, False
, target_type
,
8351 &actual_type
, &actual_format
, &actual_size
,
8352 &bytes_remaining
, &tmp_data
);
8354 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8356 if (tmp_data
) XFree (tmp_data
);
8357 x_uncatch_errors ();
8362 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8363 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8364 dpyinfo
->net_supported_window
= wmcheck_window
;
8369 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8370 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8372 x_uncatch_errors ();
8379 set_wm_state (Lisp_Object frame
, int add
, Atom atom
, Atom value
)
8381 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (XFRAME (frame
));
8383 x_send_client_event (frame
, make_number (0), frame
,
8384 dpyinfo
->Xatom_net_wm_state
,
8386 /* 1 = add, 0 = remove */
8388 (make_number (add
? 1 : 0),
8390 (make_fixnum_or_float (atom
),
8392 ? list1 (make_fixnum_or_float (value
))
8397 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8400 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8402 XSETFRAME (frame
, f
);
8404 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8405 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
8408 /* Return the current _NET_WM_STATE.
8409 SIZE_STATE is set to one of the FULLSCREEN_* values.
8410 STICKY is set to 1 if the sticky state is set, 0 if not.
8412 Return non-zero if we are not hidden, zero if we are. */
8415 get_current_wm_state (struct frame
*f
,
8421 unsigned long actual_size
, bytes_remaining
;
8422 int i
, rc
, actual_format
, is_hidden
= 0;
8423 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8424 long max_len
= 65536;
8425 Display
*dpy
= FRAME_X_DISPLAY (f
);
8426 unsigned char *tmp_data
= NULL
;
8427 Atom target_type
= XA_ATOM
;
8430 *size_state
= FULLSCREEN_NONE
;
8433 x_catch_errors (dpy
);
8434 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
8435 0, max_len
, False
, target_type
,
8436 &actual_type
, &actual_format
, &actual_size
,
8437 &bytes_remaining
, &tmp_data
);
8439 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8441 if (tmp_data
) XFree (tmp_data
);
8442 x_uncatch_errors ();
8444 return !FRAME_ICONIFIED_P (f
);
8447 x_uncatch_errors ();
8449 for (i
= 0; i
< actual_size
; ++i
)
8451 Atom a
= ((Atom
*)tmp_data
)[i
];
8452 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
8455 f
->output_data
.x
->net_wm_state_hidden_seen
= 1;
8457 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8459 if (*size_state
== FULLSCREEN_HEIGHT
)
8460 *size_state
= FULLSCREEN_MAXIMIZED
;
8462 *size_state
= FULLSCREEN_WIDTH
;
8464 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8466 if (*size_state
== FULLSCREEN_WIDTH
)
8467 *size_state
= FULLSCREEN_MAXIMIZED
;
8469 *size_state
= FULLSCREEN_HEIGHT
;
8471 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
8472 *size_state
= FULLSCREEN_BOTH
;
8473 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8477 if (tmp_data
) XFree (tmp_data
);
8482 /* Do fullscreen as specified in extended window manager hints */
8485 do_ewmh_fullscreen (struct frame
*f
)
8487 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8488 int have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
8491 (void)get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
8493 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8494 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8496 have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
8498 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
8502 XSETFRAME (frame
, f
);
8504 /* Keep number of calls to set_wm_state as low as possible.
8505 Some window managers, or possible Gtk+, hangs when too many
8506 are sent at once. */
8507 switch (f
->want_fullscreen
)
8509 case FULLSCREEN_BOTH
:
8510 if (cur
== FULLSCREEN_WIDTH
|| cur
== FULLSCREEN_MAXIMIZED
8511 || cur
== FULLSCREEN_HEIGHT
)
8512 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8513 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8514 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8516 case FULLSCREEN_WIDTH
:
8517 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
8518 || cur
== FULLSCREEN_MAXIMIZED
)
8519 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8520 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8521 if (cur
!= FULLSCREEN_MAXIMIZED
)
8522 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
8524 case FULLSCREEN_HEIGHT
:
8525 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
8526 || cur
== FULLSCREEN_MAXIMIZED
)
8527 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8528 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
8529 if (cur
!= FULLSCREEN_MAXIMIZED
)
8530 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
8532 case FULLSCREEN_MAXIMIZED
:
8533 if (cur
== FULLSCREEN_BOTH
)
8534 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8535 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8536 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8538 case FULLSCREEN_NONE
:
8539 if (cur
== FULLSCREEN_BOTH
)
8540 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8542 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8543 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8546 f
->want_fullscreen
= FULLSCREEN_NONE
;
8550 return have_net_atom
;
8554 XTfullscreen_hook (struct frame
*f
)
8556 if (FRAME_VISIBLE_P (f
))
8559 x_check_fullscreen (f
);
8567 x_handle_net_wm_state (struct frame
*f
, XPropertyEvent
*event
)
8569 int value
= FULLSCREEN_NONE
;
8572 int not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
8577 case FULLSCREEN_WIDTH
:
8580 case FULLSCREEN_HEIGHT
:
8583 case FULLSCREEN_BOTH
:
8586 case FULLSCREEN_MAXIMIZED
:
8591 store_frame_param (f
, Qfullscreen
, lval
);
8592 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8597 /* Check if we need to resize the frame due to a fullscreen request.
8598 If so needed, resize the frame. */
8600 x_check_fullscreen (struct frame
*f
)
8602 if (do_ewmh_fullscreen (f
))
8605 if (f
->output_data
.x
->parent_desc
!= FRAME_DISPLAY_INFO (f
)->root_window
)
8606 return; /* Only fullscreen without WM or with EWM hints (above). */
8608 /* Setting fullscreen to nil doesn't do anything. We could save the
8609 last non-fullscreen size and restore it, but it seems like a
8610 lot of work for this unusual case (no window manager running). */
8612 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8614 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
8615 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8617 switch (f
->want_fullscreen
)
8619 /* No difference between these two when there is no WM */
8620 case FULLSCREEN_BOTH
:
8621 case FULLSCREEN_MAXIMIZED
:
8622 width
= x_display_pixel_width (dpyinfo
);
8623 height
= x_display_pixel_height (dpyinfo
);
8625 case FULLSCREEN_WIDTH
:
8626 width
= x_display_pixel_width (dpyinfo
);
8628 case FULLSCREEN_HEIGHT
:
8629 height
= x_display_pixel_height (dpyinfo
);
8632 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8637 /* This function is called by x_set_offset to determine whether the window
8638 manager interfered with the positioning of the frame. Type A window
8639 managers position the surrounding window manager decorations a small
8640 amount above and left of the user-supplied position. Type B window
8641 managers position the surrounding window manager decorations at the
8642 user-specified position. If we detect a Type A window manager, we
8643 compensate by moving the window right and down by the proper amount. */
8646 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8648 int current_left
= 0, current_top
= 0;
8650 /* x_real_positions returns the left and top offsets of the outermost
8651 window manager window around the frame. */
8653 x_real_positions (f
, ¤t_left
, ¤t_top
);
8655 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8657 /* It's a "Type A" window manager. */
8662 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8663 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8664 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8666 /* Now fix the mispositioned frame's location. */
8668 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8669 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8671 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8672 adjusted_left
, adjusted_top
);
8674 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8677 /* It's a "Type B" window manager. We don't have to adjust the
8678 frame's position. */
8680 FRAME_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8684 /* Wait for XGetGeometry to return up-to-date position information for a
8685 recently-moved frame. Call this immediately after calling XMoveWindow.
8686 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8687 frame has been moved to, so we use a fuzzy position comparison instead
8688 of an exact comparison. */
8691 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8695 while (count
++ < 50)
8697 int current_left
= 0, current_top
= 0;
8699 /* In theory, this call to XSync only needs to happen once, but in
8700 practice, it doesn't seem to work, hence the need for the surrounding
8703 XSync (FRAME_X_DISPLAY (f
), False
);
8704 x_real_positions (f
, ¤t_left
, ¤t_top
);
8708 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8711 if (eabs (current_left
- left
) <= 10
8712 && eabs (current_top
- top
) <= 40)
8715 else if (current_left
== left
&& current_top
== top
)
8719 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8720 will then return up-to-date position info. */
8722 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8726 /* Wait for an event on frame F matching EVENTTYPE. */
8728 x_wait_for_event (struct frame
*f
, int eventtype
)
8730 int level
= interrupt_input_blocked
;
8733 struct timespec tmo
, tmo_at
, time_now
;
8734 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8736 pending_event_wait
.f
= f
;
8737 pending_event_wait
.eventtype
= eventtype
;
8739 /* Set timeout to 0.1 second. Hopefully not noticeable.
8740 Maybe it should be configurable. */
8741 tmo
= make_timespec (0, 100 * 1000 * 1000);
8742 tmo_at
= timespec_add (current_timespec (), tmo
);
8744 while (pending_event_wait
.eventtype
)
8746 pending_signals
= 1;
8747 totally_unblock_input ();
8748 /* XTread_socket is called after unblock. */
8750 interrupt_input_blocked
= level
;
8755 time_now
= current_timespec ();
8756 if (timespec_cmp (tmo_at
, time_now
) < 0)
8759 tmo
= timespec_sub (tmo_at
, time_now
);
8760 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
8761 break; /* Timeout */
8763 pending_event_wait
.f
= 0;
8764 pending_event_wait
.eventtype
= 0;
8768 /* Change the size of frame F's X window to COLS/ROWS in the case F
8769 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8770 top-left-corner window gravity for this size change and subsequent
8771 size changes. Otherwise we leave the window gravity unchanged. */
8774 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8776 int pixelwidth
, pixelheight
;
8778 check_frame_size (f
, &rows
, &cols
);
8779 f
->scroll_bar_actual_width
8780 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8782 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8784 compute_fringe_widths (f
, 0);
8786 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8787 + FRAME_TOOLBAR_WIDTH (f
);
8788 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8789 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8791 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8792 x_wm_set_size_hint (f
, (long) 0, 0);
8793 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8794 pixelwidth
, pixelheight
);
8797 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8798 receive in the ConfigureNotify event; if we get what we asked
8799 for, then the event won't cause the screen to become garbaged, so
8800 we have to make sure to do it here. */
8801 SET_FRAME_GARBAGED (f
);
8803 /* Now, strictly speaking, we can't be sure that this is accurate,
8804 but the window manager will get around to dealing with the size
8805 change request eventually, and we'll hear how it went when the
8806 ConfigureNotify event gets here.
8808 We could just not bother storing any of this information here,
8809 and let the ConfigureNotify event set everything up, but that
8810 might be kind of confusing to the Lisp code, since size changes
8811 wouldn't be reported in the frame parameters until some random
8812 point in the future when the ConfigureNotify event arrives.
8814 We pass 1 for DELAY since we can't run Lisp code inside of
8817 /* But the ConfigureNotify may in fact never arrive, and then this is
8818 not right if the frame is visible. Instead wait (with timeout)
8819 for the ConfigureNotify. */
8820 if (FRAME_VISIBLE_P (f
))
8821 x_wait_for_event (f
, ConfigureNotify
);
8824 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8825 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8826 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8832 /* Call this to change the size of frame F's x-window.
8833 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8834 for this size change and subsequent size changes.
8835 Otherwise we leave the window gravity unchanged. */
8838 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8842 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8846 /* When the frame is maximized/fullscreen or running under for
8847 example Xmonad, x_set_window_size_1 will be a no-op.
8848 In that case, the right thing to do is extend rows/cols to
8849 the current frame size. We do that first if x_set_window_size_1
8850 turns out to not be a no-op (there is no way to know).
8851 The size will be adjusted again if the frame gets a
8852 ConfigureNotify event as a result of x_set_window_size. */
8853 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8854 #ifdef USE_X_TOOLKIT
8855 /* The menu bar is not part of text lines. The tool bar
8857 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8859 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8860 /* Update f->scroll_bar_actual_width because it is used in
8861 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8862 f
->scroll_bar_actual_width
8863 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8864 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8865 change_frame_size (f
, r
, c
, 0, 1, 0);
8869 if (FRAME_GTK_WIDGET (f
))
8870 xg_frame_set_char_size (f
, cols
, rows
);
8872 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8873 #else /* not USE_GTK */
8875 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8877 #endif /* not USE_GTK */
8879 /* If cursor was outside the new size, mark it as off. */
8880 mark_window_cursors_off (XWINDOW (f
->root_window
));
8882 /* Clear out any recollection of where the mouse highlighting was,
8883 since it might be in a place that's outside the new frame size.
8884 Actually checking whether it is outside is a pain in the neck,
8885 so don't try--just let the highlighting be done afresh with new size. */
8886 cancel_mouse_face (f
);
8891 /* Mouse warping. */
8894 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8898 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8899 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8901 if (pix_x
< 0) pix_x
= 0;
8902 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8904 if (pix_y
< 0) pix_y
= 0;
8905 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8909 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8910 0, 0, 0, 0, pix_x
, pix_y
);
8914 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8917 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8921 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8922 0, 0, 0, 0, pix_x
, pix_y
);
8926 /* Raise frame F. */
8929 x_raise_frame (struct frame
*f
)
8932 if (FRAME_VISIBLE_P (f
))
8933 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8934 XFlush (FRAME_X_DISPLAY (f
));
8938 /* Lower frame F. */
8941 x_lower_frame (struct frame
*f
)
8943 if (FRAME_VISIBLE_P (f
))
8946 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8947 XFlush (FRAME_X_DISPLAY (f
));
8952 /* Request focus with XEmbed */
8955 xembed_request_focus (struct frame
*f
)
8957 /* See XEmbed Protocol Specification at
8958 http://freedesktop.org/wiki/Specifications/xembed-spec */
8959 if (FRAME_VISIBLE_P (f
))
8960 xembed_send_message (f
, CurrentTime
,
8961 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
8964 /* Activate frame with Extended Window Manager Hints */
8967 x_ewmh_activate_frame (struct frame
*f
)
8969 /* See Window Manager Specification/Extended Window Manager Hints at
8970 http://freedesktop.org/wiki/Specifications/wm-spec */
8972 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
8974 if (FRAME_VISIBLE_P (f
) && wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
8977 XSETFRAME (frame
, f
);
8978 x_send_client_event (frame
, make_number (0), frame
,
8979 dpyinfo
->Xatom_net_active_window
,
8981 list2i (1, dpyinfo
->last_user_time
));
8986 XTframe_raise_lower (struct frame
*f
, int raise_flag
)
8994 /* XEmbed implementation. */
8996 #if defined USE_X_TOOLKIT || ! defined USE_GTK
8998 /* XEmbed implementation. */
9000 #define XEMBED_VERSION 0
9003 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
9005 unsigned long data
[2];
9006 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9008 data
[0] = XEMBED_VERSION
;
9011 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9012 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
9013 32, PropModeReplace
, (unsigned char *) data
, 2);
9015 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
9018 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
9019 long int detail
, long int data1
, long int data2
)
9023 event
.xclient
.type
= ClientMessage
;
9024 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9025 event
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9026 event
.xclient
.format
= 32;
9027 event
.xclient
.data
.l
[0] = t
;
9028 event
.xclient
.data
.l
[1] = msg
;
9029 event
.xclient
.data
.l
[2] = detail
;
9030 event
.xclient
.data
.l
[3] = data1
;
9031 event
.xclient
.data
.l
[4] = data2
;
9033 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9034 False
, NoEventMask
, &event
);
9035 XSync (FRAME_X_DISPLAY (f
), False
);
9038 /* Change of visibility. */
9040 /* This tries to wait until the frame is really visible.
9041 However, if the window manager asks the user where to position
9042 the frame, this will return before the user finishes doing that.
9043 The frame will not actually be visible at that time,
9044 but it will become visible later when the window manager
9045 finishes with it. */
9048 x_make_frame_visible (struct frame
*f
)
9051 int original_top
, original_left
;
9052 int retry_count
= 2;
9058 type
= x_icon_type (f
);
9060 x_bitmap_icon (f
, type
);
9062 if (! FRAME_VISIBLE_P (f
))
9064 /* We test FRAME_GARBAGED_P here to make sure we don't
9065 call x_set_offset a second time
9066 if we get to x_make_frame_visible a second time
9067 before the window gets really visible. */
9068 if (! FRAME_ICONIFIED_P (f
)
9069 && ! FRAME_X_EMBEDDED_P (f
)
9070 && ! f
->output_data
.x
->asked_for_visible
)
9071 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9073 f
->output_data
.x
->asked_for_visible
= 1;
9075 if (! EQ (Vx_no_window_manager
, Qt
))
9076 x_wm_set_window_state (f
, NormalState
);
9077 #ifdef USE_X_TOOLKIT
9078 if (FRAME_X_EMBEDDED_P (f
))
9079 xembed_set_info (f
, XEMBED_MAPPED
);
9082 /* This was XtPopup, but that did nothing for an iconified frame. */
9083 XtMapWidget (f
->output_data
.x
->widget
);
9085 #else /* not USE_X_TOOLKIT */
9087 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9088 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9090 if (FRAME_X_EMBEDDED_P (f
))
9091 xembed_set_info (f
, XEMBED_MAPPED
);
9093 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9094 #endif /* not USE_GTK */
9095 #endif /* not USE_X_TOOLKIT */
9098 XFlush (FRAME_X_DISPLAY (f
));
9100 /* Synchronize to ensure Emacs knows the frame is visible
9101 before we do anything else. We do this loop with input not blocked
9102 so that incoming events are handled. */
9106 /* This must be before UNBLOCK_INPUT
9107 since events that arrive in response to the actions above
9108 will set it when they are handled. */
9109 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9111 original_left
= f
->left_pos
;
9112 original_top
= f
->top_pos
;
9114 /* This must come after we set COUNT. */
9117 /* We unblock here so that arriving X events are processed. */
9119 /* Now move the window back to where it was "supposed to be".
9120 But don't do it if the gravity is negative.
9121 When the gravity is negative, this uses a position
9122 that is 3 pixels too low. Perhaps that's really the border width.
9124 Don't do this if the window has never been visible before,
9125 because the window manager may choose the position
9126 and we don't want to override it. */
9128 if (! FRAME_VISIBLE_P (f
)
9129 && ! FRAME_ICONIFIED_P (f
)
9130 && ! FRAME_X_EMBEDDED_P (f
)
9131 && f
->win_gravity
== NorthWestGravity
9132 && previously_visible
)
9136 unsigned int width
, height
, border
, depth
;
9140 /* On some window managers (such as FVWM) moving an existing
9141 window, even to the same place, causes the window manager
9142 to introduce an offset. This can cause the window to move
9143 to an unexpected location. Check the geometry (a little
9144 slow here) and then verify that the window is in the right
9145 place. If the window is not in the right place, move it
9146 there, and take the potential window manager hit. */
9147 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9148 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9150 if (original_left
!= x
|| original_top
!= y
)
9151 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9152 original_left
, original_top
);
9157 XSETFRAME (frame
, f
);
9159 /* Wait until the frame is visible. Process X events until a
9160 MapNotify event has been seen, or until we think we won't get a
9161 MapNotify at all.. */
9162 for (count
= input_signal_count
+ 10;
9163 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9165 /* Force processing of queued events. */
9168 /* Machines that do polling rather than SIGIO have been
9169 observed to go into a busy-wait here. So we'll fake an
9170 alarm signal to let the handler know that there's something
9171 to be read. We used to raise a real alarm, but it seems
9172 that the handler isn't always enabled here. This is
9174 if (input_polling_used ())
9176 /* It could be confusing if a real alarm arrives while
9177 processing the fake one. Turn it off and let the
9178 handler reset it. */
9179 int old_poll_suppress_count
= poll_suppress_count
;
9180 poll_suppress_count
= 1;
9181 poll_for_input_1 ();
9182 poll_suppress_count
= old_poll_suppress_count
;
9188 (let ((f (selected-frame)))
9192 the frame is not raised with various window managers on
9193 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9194 unknown reason, the call to XtMapWidget is completely ignored.
9195 Mapping the widget a second time works. */
9197 if (!FRAME_VISIBLE_P (f
) && --retry_count
!= 0)
9202 /* Change from mapped state to withdrawn state. */
9204 /* Make the frame visible (mapped and not iconified). */
9207 x_make_frame_invisible (struct frame
*f
)
9211 /* Use the frame's outermost window, not the one we normally draw on. */
9212 window
= FRAME_OUTER_WINDOW (f
);
9214 /* Don't keep the highlight on an invisible frame. */
9215 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9216 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9220 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9221 that the current position of the window is user-specified, rather than
9222 program-specified, so that when the window is mapped again, it will be
9223 placed at the same location, without forcing the user to position it
9224 by hand again (they have already done that once for this window.) */
9225 x_wm_set_size_hint (f
, (long) 0, 1);
9228 if (FRAME_GTK_OUTER_WIDGET (f
))
9229 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9232 if (FRAME_X_EMBEDDED_P (f
))
9233 xembed_set_info (f
, 0);
9238 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9239 DefaultScreen (FRAME_X_DISPLAY (f
))))
9242 error ("Can't notify window manager of window withdrawal");
9246 /* We can't distinguish this from iconification
9247 just by the event that we get from the server.
9248 So we can't win using the usual strategy of letting
9249 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9250 and synchronize with the server to make sure we agree. */
9251 SET_FRAME_VISIBLE (f
, 0);
9252 SET_FRAME_ICONIFIED (f
, 0);
9259 /* Change window state from mapped to iconified. */
9262 x_iconify_frame (struct frame
*f
)
9264 #ifdef USE_X_TOOLKIT
9269 /* Don't keep the highlight on an invisible frame. */
9270 if (FRAME_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9271 FRAME_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9273 if (FRAME_ICONIFIED_P (f
))
9278 type
= x_icon_type (f
);
9280 x_bitmap_icon (f
, type
);
9282 #if defined (USE_GTK)
9283 if (FRAME_GTK_OUTER_WIDGET (f
))
9285 if (! FRAME_VISIBLE_P (f
))
9286 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9288 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9289 SET_FRAME_VISIBLE (f
, 0);
9290 SET_FRAME_ICONIFIED (f
, 1);
9296 #ifdef USE_X_TOOLKIT
9298 if (! FRAME_VISIBLE_P (f
))
9300 if (! EQ (Vx_no_window_manager
, Qt
))
9301 x_wm_set_window_state (f
, IconicState
);
9302 /* This was XtPopup, but that did nothing for an iconified frame. */
9303 XtMapWidget (f
->output_data
.x
->widget
);
9304 /* The server won't give us any event to indicate
9305 that an invisible frame was changed to an icon,
9306 so we have to record it here. */
9307 SET_FRAME_VISIBLE (f
, 0);
9308 SET_FRAME_ICONIFIED (f
, 1);
9313 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9314 XtWindow (f
->output_data
.x
->widget
),
9315 DefaultScreen (FRAME_X_DISPLAY (f
)));
9319 error ("Can't notify window manager of iconification");
9321 SET_FRAME_ICONIFIED (f
, 1);
9322 SET_FRAME_VISIBLE (f
, 0);
9325 XFlush (FRAME_X_DISPLAY (f
));
9327 #else /* not USE_X_TOOLKIT */
9329 /* Make sure the X server knows where the window should be positioned,
9330 in case the user deiconifies with the window manager. */
9331 if (! FRAME_VISIBLE_P (f
)
9332 && ! FRAME_ICONIFIED_P (f
)
9333 && ! FRAME_X_EMBEDDED_P (f
))
9334 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9336 /* Since we don't know which revision of X we're running, we'll use both
9337 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9339 /* X11R4: send a ClientMessage to the window manager using the
9340 WM_CHANGE_STATE type. */
9344 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
9345 msg
.xclient
.type
= ClientMessage
;
9346 msg
.xclient
.message_type
= FRAME_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9347 msg
.xclient
.format
= 32;
9348 msg
.xclient
.data
.l
[0] = IconicState
;
9350 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9351 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9353 SubstructureRedirectMask
| SubstructureNotifyMask
,
9357 error ("Can't notify window manager of iconification");
9361 /* X11R3: set the initial_state field of the window manager hints to
9363 x_wm_set_window_state (f
, IconicState
);
9365 if (!FRAME_VISIBLE_P (f
))
9367 /* If the frame was withdrawn, before, we must map it. */
9368 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9371 SET_FRAME_ICONIFIED (f
, 1);
9372 SET_FRAME_VISIBLE (f
, 0);
9374 XFlush (FRAME_X_DISPLAY (f
));
9376 #endif /* not USE_X_TOOLKIT */
9380 /* Free X resources of frame F. */
9383 x_free_frame_resources (struct frame
*f
)
9385 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9386 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
9387 #ifdef USE_X_TOOLKIT
9389 struct scroll_bar
*b
;
9394 /* If a display connection is dead, don't try sending more
9395 commands to the X server. */
9396 if (dpyinfo
->display
)
9398 /* We must free faces before destroying windows because some
9399 font-driver (e.g. xft) access a window while finishing a
9401 if (FRAME_FACE_CACHE (f
))
9402 free_frame_faces (f
);
9404 if (f
->output_data
.x
->icon_desc
)
9405 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9407 #ifdef USE_X_TOOLKIT
9408 /* Explicitly destroy the scroll bars of the frame. Without
9409 this, we get "BadDrawable" errors from the toolkit later on,
9410 presumably from expose events generated for the disappearing
9411 toolkit scroll bars. */
9412 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9414 b
= XSCROLL_BAR (bar
);
9415 x_scroll_bar_remove (b
);
9424 #ifdef USE_X_TOOLKIT
9425 if (f
->output_data
.x
->widget
)
9427 XtDestroyWidget (f
->output_data
.x
->widget
);
9428 f
->output_data
.x
->widget
= NULL
;
9430 /* Tooltips don't have widgets, only a simple X window, even if
9431 we are using a toolkit. */
9432 else if (FRAME_X_WINDOW (f
))
9433 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9435 free_frame_menubar (f
);
9436 #else /* !USE_X_TOOLKIT */
9439 xg_free_frame_widgets (f
);
9440 #endif /* USE_GTK */
9442 if (FRAME_X_WINDOW (f
))
9443 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9444 #endif /* !USE_X_TOOLKIT */
9446 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9447 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9448 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9449 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9450 unload_color (f
, f
->output_data
.x
->border_pixel
);
9451 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9453 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9454 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9455 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9456 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9457 #ifdef USE_TOOLKIT_SCROLL_BARS
9458 /* Scrollbar shadow colors. */
9459 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9460 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9461 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9462 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9463 #endif /* USE_TOOLKIT_SCROLL_BARS */
9464 if (f
->output_data
.x
->white_relief
.allocated_p
)
9465 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9466 if (f
->output_data
.x
->black_relief
.allocated_p
)
9467 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9471 /* Free extra GCs allocated by x_setup_relief_colors. */
9472 if (f
->output_data
.x
->white_relief
.gc
)
9474 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->white_relief
.gc
);
9475 f
->output_data
.x
->white_relief
.gc
= 0;
9477 if (f
->output_data
.x
->black_relief
.gc
)
9479 XFreeGC (dpyinfo
->display
, f
->output_data
.x
->black_relief
.gc
);
9480 f
->output_data
.x
->black_relief
.gc
= 0;
9483 XFlush (FRAME_X_DISPLAY (f
));
9486 xfree (f
->output_data
.x
->saved_menu_event
);
9487 xfree (f
->output_data
.x
);
9488 f
->output_data
.x
= NULL
;
9490 if (f
== dpyinfo
->x_focus_frame
)
9491 dpyinfo
->x_focus_frame
= 0;
9492 if (f
== dpyinfo
->x_focus_event_frame
)
9493 dpyinfo
->x_focus_event_frame
= 0;
9494 if (f
== dpyinfo
->x_highlight_frame
)
9495 dpyinfo
->x_highlight_frame
= 0;
9496 if (f
== hlinfo
->mouse_face_mouse_frame
)
9497 reset_mouse_highlight (hlinfo
);
9503 /* Destroy the X window of frame F. */
9506 x_destroy_window (struct frame
*f
)
9508 struct x_display_info
*dpyinfo
= FRAME_DISPLAY_INFO (f
);
9510 /* If a display connection is dead, don't try sending more
9511 commands to the X server. */
9512 if (dpyinfo
->display
!= 0)
9513 x_free_frame_resources (f
);
9515 dpyinfo
->reference_count
--;
9519 /* Setting window manager hints. */
9521 /* Set the normal size hints for the window manager, for frame F.
9522 FLAGS is the flags word to use--or 0 meaning preserve the flags
9523 that the window now has.
9524 If USER_POSITION, set the USPosition
9525 flag (this is useful when FLAGS is 0).
9526 The GTK version is in gtkutils.c. */
9530 x_wm_set_size_hint (struct frame
*f
, long flags
, bool user_position
)
9532 XSizeHints size_hints
;
9533 Window window
= FRAME_OUTER_WINDOW (f
);
9535 #ifdef USE_X_TOOLKIT
9536 if (f
->output_data
.x
->widget
)
9538 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
9543 /* Setting PMaxSize caused various problems. */
9544 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9546 size_hints
.x
= f
->left_pos
;
9547 size_hints
.y
= f
->top_pos
;
9549 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9550 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9552 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9553 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9554 size_hints
.max_width
= x_display_pixel_width (FRAME_DISPLAY_INFO (f
))
9555 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9556 size_hints
.max_height
= x_display_pixel_height (FRAME_DISPLAY_INFO (f
))
9557 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9559 /* Calculate the base and minimum sizes. */
9561 int base_width
, base_height
;
9562 int min_rows
= 0, min_cols
= 0;
9564 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9565 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9567 check_frame_size (f
, &min_rows
, &min_cols
);
9569 /* The window manager uses the base width hints to calculate the
9570 current number of rows and columns in the frame while
9571 resizing; min_width and min_height aren't useful for this
9572 purpose, since they might not give the dimensions for a
9573 zero-row, zero-column frame.
9575 We use the base_width and base_height members if we have
9576 them; otherwise, we set the min_width and min_height members
9577 to the size for a zero x zero frame. */
9579 size_hints
.flags
|= PBaseSize
;
9580 size_hints
.base_width
= base_width
;
9581 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9582 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9583 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9586 /* If we don't need the old flags, we don't need the old hint at all. */
9589 size_hints
.flags
|= flags
;
9594 XSizeHints hints
; /* Sometimes I hate X Windows... */
9595 long supplied_return
;
9598 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9602 size_hints
.flags
|= flags
;
9607 if (hints
.flags
& PSize
)
9608 size_hints
.flags
|= PSize
;
9609 if (hints
.flags
& PPosition
)
9610 size_hints
.flags
|= PPosition
;
9611 if (hints
.flags
& USPosition
)
9612 size_hints
.flags
|= USPosition
;
9613 if (hints
.flags
& USSize
)
9614 size_hints
.flags
|= USSize
;
9621 size_hints
.win_gravity
= f
->win_gravity
;
9622 size_hints
.flags
|= PWinGravity
;
9626 size_hints
.flags
&= ~ PPosition
;
9627 size_hints
.flags
|= USPosition
;
9629 #endif /* PWinGravity */
9631 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9633 #endif /* not USE_GTK */
9635 /* Used for IconicState or NormalState */
9638 x_wm_set_window_state (struct frame
*f
, int state
)
9640 #ifdef USE_X_TOOLKIT
9643 XtSetArg (al
[0], XtNinitialState
, state
);
9644 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9645 #else /* not USE_X_TOOLKIT */
9646 Window window
= FRAME_X_WINDOW (f
);
9648 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9649 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9651 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9652 #endif /* not USE_X_TOOLKIT */
9656 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
9658 Pixmap icon_pixmap
, icon_mask
;
9660 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9661 Window window
= FRAME_OUTER_WINDOW (f
);
9666 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9667 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9668 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9669 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9673 /* It seems there is no way to turn off use of an icon
9681 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9685 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9689 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9690 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9691 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9692 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9695 #else /* not USE_X_TOOLKIT && not USE_GTK */
9697 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9698 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9700 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9704 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9706 Window window
= FRAME_OUTER_WINDOW (f
);
9708 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9709 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9710 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9712 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9716 /***********************************************************************
9718 ***********************************************************************/
9722 /* Check that FONT is valid on frame F. It is if it can be found in F's
9726 x_check_font (struct frame
*f
, struct font
*font
)
9728 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9729 if (font
->driver
->check
)
9730 eassert (font
->driver
->check (f
, font
) == 0);
9733 #endif /* GLYPH_DEBUG */
9736 /***********************************************************************
9738 ***********************************************************************/
9740 #ifdef USE_X_TOOLKIT
9741 static XrmOptionDescRec emacs_options
[] = {
9742 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9743 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9745 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9746 XrmoptionSepArg
, NULL
},
9747 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9749 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9750 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9751 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9752 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9753 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9754 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9755 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9758 /* Whether atimer for Xt timeouts is activated or not. */
9760 static int x_timeout_atimer_activated_flag
;
9762 #endif /* USE_X_TOOLKIT */
9764 static int x_initialized
;
9766 /* Test whether two display-name strings agree up to the dot that separates
9767 the screen number from the server number. */
9769 same_x_server (const char *name1
, const char *name2
)
9772 const char *system_name
= SSDATA (Vsystem_name
);
9773 ptrdiff_t system_name_length
= SBYTES (Vsystem_name
);
9774 ptrdiff_t length_until_period
= 0;
9776 while (system_name
[length_until_period
] != 0
9777 && system_name
[length_until_period
] != '.')
9778 length_until_period
++;
9780 /* Treat `unix' like an empty host name. */
9781 if (! strncmp (name1
, "unix:", 5))
9783 if (! strncmp (name2
, "unix:", 5))
9785 /* Treat this host's name like an empty host name. */
9786 if (! strncmp (name1
, system_name
, system_name_length
)
9787 && name1
[system_name_length
] == ':')
9788 name1
+= system_name_length
;
9789 if (! strncmp (name2
, system_name
, system_name_length
)
9790 && name2
[system_name_length
] == ':')
9791 name2
+= system_name_length
;
9792 /* Treat this host's domainless name like an empty host name. */
9793 if (! strncmp (name1
, system_name
, length_until_period
)
9794 && name1
[length_until_period
] == ':')
9795 name1
+= length_until_period
;
9796 if (! strncmp (name2
, system_name
, length_until_period
)
9797 && name2
[length_until_period
] == ':')
9798 name2
+= length_until_period
;
9800 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9804 if (seen_colon
&& *name1
== '.')
9808 && (*name1
== '.' || *name1
== '\0')
9809 && (*name2
== '.' || *name2
== '\0'));
9812 /* Count number of set bits in mask and number of bits to shift to
9813 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9816 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9837 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9838 But don't permanently open it, just test its availability. */
9841 x_display_ok (const char *display
)
9843 Display
*dpy
= XOpenDisplay (display
);
9844 return dpy
? (XCloseDisplay (dpy
), 1) : 0;
9849 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
9850 const gchar
*msg
, gpointer user_data
)
9852 if (!strstr (msg
, "g_set_prgname"))
9853 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
9857 /* Open a connection to X display DISPLAY_NAME, and return
9858 the structure that describes the open display.
9859 If we cannot contact the display, return null. */
9861 struct x_display_info
*
9862 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9866 struct terminal
*terminal
;
9867 struct x_display_info
*dpyinfo
;
9879 if (! x_display_ok (SSDATA (display_name
)))
9880 error ("Display %s can't be opened", SSDATA (display_name
));
9886 char *argv
[NUM_ARGV
];
9887 char **argv2
= argv
;
9890 if (x_initialized
++ > 1)
9892 xg_display_open (SSDATA (display_name
), &dpy
);
9896 static char display_opt
[] = "--display";
9897 static char name_opt
[] = "--name";
9899 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9903 argv
[argc
++] = initial_argv
[0];
9905 if (! NILP (display_name
))
9907 argv
[argc
++] = display_opt
;
9908 argv
[argc
++] = SSDATA (display_name
);
9911 argv
[argc
++] = name_opt
;
9912 argv
[argc
++] = resource_name
;
9914 XSetLocaleModifiers ("");
9916 /* Emacs can only handle core input events, so make sure
9917 Gtk doesn't use Xinput or Xinput2 extensions. */
9918 xputenv ("GDK_CORE_DEVICE_EVENTS=1");
9920 /* Work around GLib bug that outputs a faulty warning. See
9921 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9922 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9923 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9925 /* NULL window -> events for all windows go to our function.
9926 Call before gtk_init so Gtk+ event filters comes after our. */
9927 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9929 /* gtk_init does set_locale. Fix locale before and after. */
9931 gtk_init (&argc
, &argv2
);
9934 g_log_remove_handler ("GLib", id
);
9938 dpy
= DEFAULT_GDK_DISPLAY ();
9940 #if ! GTK_CHECK_VERSION (2, 90, 0)
9941 /* Load our own gtkrc if it exists. */
9943 const char *file
= "~/.emacs.d/gtkrc";
9944 Lisp_Object s
, abs_file
;
9946 s
= build_string (file
);
9947 abs_file
= Fexpand_file_name (s
, Qnil
);
9949 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
9950 gtk_rc_parse (SSDATA (abs_file
));
9954 XSetErrorHandler (x_error_handler
);
9955 XSetIOErrorHandler (x_io_error_quitter
);
9958 #else /* not USE_GTK */
9959 #ifdef USE_X_TOOLKIT
9960 /* weiner@footloose.sps.mot.com reports that this causes
9962 X protocol error: BadAtom (invalid Atom parameter)
9963 on protocol request 18skiloaf.
9964 So let's not use it until R6. */
9966 XtSetLanguageProc (NULL
, NULL
, NULL
);
9977 argv
[argc
++] = "-xrm";
9978 argv
[argc
++] = xrm_option
;
9980 turn_on_atimers (0);
9981 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
9982 resource_name
, EMACS_CLASS
,
9983 emacs_options
, XtNumber (emacs_options
),
9985 turn_on_atimers (1);
9988 /* I think this is to compensate for XtSetLanguageProc. */
9993 #else /* not USE_X_TOOLKIT */
9994 XSetLocaleModifiers ("");
9995 dpy
= XOpenDisplay (SSDATA (display_name
));
9996 #endif /* not USE_X_TOOLKIT */
9997 #endif /* not USE_GTK*/
9999 /* Detect failure. */
10006 /* We have definitely succeeded. Record the new connection. */
10008 dpyinfo
= xzalloc (sizeof *dpyinfo
);
10009 terminal
= x_create_terminal (dpyinfo
);
10012 struct x_display_info
*share
;
10015 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10016 share
= share
->next
, tail
= XCDR (tail
))
10017 if (same_x_server (SSDATA (XCAR (XCAR (tail
))),
10018 SSDATA (display_name
)))
10021 terminal
->kboard
= share
->terminal
->kboard
;
10024 terminal
->kboard
= xmalloc (sizeof *terminal
->kboard
);
10025 init_kboard (terminal
->kboard
);
10026 kset_window_system (terminal
->kboard
, Qx
);
10028 /* Add the keyboard to the list before running Lisp code (via
10029 Qvendor_specific_keysyms below), since these are not traced
10030 via terminals but only through all_kboards. */
10031 terminal
->kboard
->next_kboard
= all_kboards
;
10032 all_kboards
= terminal
->kboard
;
10034 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10036 char *vendor
= ServerVendor (dpy
);
10038 /* Protect terminal from GC before removing it from the
10039 list of terminals. */
10040 struct gcpro gcpro1
;
10041 Lisp_Object gcpro_term
;
10042 XSETTERMINAL (gcpro_term
, terminal
);
10043 GCPRO1 (gcpro_term
);
10045 /* Temporarily hide the partially initialized terminal. */
10046 terminal_list
= terminal
->next_terminal
;
10048 kset_system_key_alist
10050 call1 (Qvendor_specific_keysyms
,
10051 vendor
? build_string (vendor
) : empty_unibyte_string
));
10053 terminal
->next_terminal
= terminal_list
;
10054 terminal_list
= terminal
;
10058 /* Don't let the initial kboard remain current longer than necessary.
10059 That would cause problems if a file loaded on startup tries to
10060 prompt in the mini-buffer. */
10061 if (current_kboard
== initial_kboard
)
10062 current_kboard
= terminal
->kboard
;
10064 terminal
->kboard
->reference_count
++;
10067 /* Put this display on the chain. */
10068 dpyinfo
->next
= x_display_list
;
10069 x_display_list
= dpyinfo
;
10071 /* Put it on x_display_name_list as well, to keep them parallel. */
10072 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10073 x_display_name_list
);
10074 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10076 dpyinfo
->display
= dpy
;
10078 /* Set the name of the terminal. */
10079 terminal
->name
= xlispstrdup (display_name
);
10082 XSetAfterFunction (x_current_display
, x_trace_wire
);
10085 lim
= min (PTRDIFF_MAX
, SIZE_MAX
) - sizeof "@";
10086 if (lim
- SBYTES (Vinvocation_name
) < SBYTES (Vsystem_name
))
10087 memory_full (SIZE_MAX
);
10088 dpyinfo
->x_id_name
= xmalloc (SBYTES (Vinvocation_name
)
10089 + SBYTES (Vsystem_name
) + 2);
10090 strcat (strcat (strcpy (dpyinfo
->x_id_name
, SSDATA (Vinvocation_name
)), "@"),
10091 SSDATA (Vsystem_name
));
10093 /* Figure out which modifier bits mean what. */
10094 x_find_modifier_meanings (dpyinfo
);
10096 /* Get the scroll bar cursor. */
10098 /* We must create a GTK cursor, it is required for GTK widgets. */
10099 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10100 #endif /* USE_GTK */
10102 dpyinfo
->vertical_scroll_bar_cursor
10103 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10105 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10106 resource_name
, EMACS_CLASS
);
10107 #ifdef HAVE_XRMSETDATABASE
10108 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10110 dpyinfo
->display
->db
= xrdb
;
10112 /* Put the rdb where we can find it in a way that works on
10114 dpyinfo
->xrdb
= xrdb
;
10116 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10117 DefaultScreen (dpyinfo
->display
));
10118 select_visual (dpyinfo
);
10119 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10120 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10121 dpyinfo
->icon_bitmap_id
= -1;
10122 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10124 reset_mouse_highlight (&dpyinfo
->mouse_highlight
);
10126 /* See if we can construct pixel values from RGB values. */
10127 if (dpyinfo
->visual
->class == TrueColor
)
10129 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10130 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10131 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10132 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10133 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10134 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10137 /* See if a private colormap is requested. */
10138 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10140 if (dpyinfo
->visual
->class == PseudoColor
)
10143 value
= display_x_get_resource (dpyinfo
,
10144 build_string ("privateColormap"),
10145 build_string ("PrivateColormap"),
10147 if (STRINGP (value
)
10148 && (!strcmp (SSDATA (value
), "true")
10149 || !strcmp (SSDATA (value
), "on")))
10150 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10154 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10155 dpyinfo
->visual
, AllocNone
);
10159 /* If we are using Xft, check dpi value in X resources.
10160 It is better we use it as well, since Xft will use it, as will all
10161 Gnome applications. If our real DPI is smaller or larger than the
10162 one Xft uses, our font will look smaller or larger than other
10163 for other applications, even if it is the same font name (monospace-10
10165 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10167 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10168 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10172 if (dpyinfo
->resy
< 1)
10174 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10175 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10176 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10177 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10178 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10179 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10180 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10181 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10182 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10186 static const struct
10191 #define ATOM_REFS_INIT(string, member) \
10192 { string, offsetof (struct x_display_info, member) },
10193 ATOM_REFS_INIT ("WM_PROTOCOLS", Xatom_wm_protocols
)
10194 ATOM_REFS_INIT ("WM_TAKE_FOCUS", Xatom_wm_take_focus
)
10195 ATOM_REFS_INIT ("WM_SAVE_YOURSELF", Xatom_wm_save_yourself
)
10196 ATOM_REFS_INIT ("WM_DELETE_WINDOW", Xatom_wm_delete_window
)
10197 ATOM_REFS_INIT ("WM_CHANGE_STATE", Xatom_wm_change_state
)
10198 ATOM_REFS_INIT ("WM_CONFIGURE_DENIED", Xatom_wm_configure_denied
)
10199 ATOM_REFS_INIT ("WM_MOVED", Xatom_wm_window_moved
)
10200 ATOM_REFS_INIT ("WM_CLIENT_LEADER", Xatom_wm_client_leader
)
10201 ATOM_REFS_INIT ("Editres", Xatom_editres
)
10202 ATOM_REFS_INIT ("CLIPBOARD", Xatom_CLIPBOARD
)
10203 ATOM_REFS_INIT ("TIMESTAMP", Xatom_TIMESTAMP
)
10204 ATOM_REFS_INIT ("TEXT", Xatom_TEXT
)
10205 ATOM_REFS_INIT ("COMPOUND_TEXT", Xatom_COMPOUND_TEXT
)
10206 ATOM_REFS_INIT ("UTF8_STRING", Xatom_UTF8_STRING
)
10207 ATOM_REFS_INIT ("DELETE", Xatom_DELETE
)
10208 ATOM_REFS_INIT ("MULTIPLE", Xatom_MULTIPLE
)
10209 ATOM_REFS_INIT ("INCR", Xatom_INCR
)
10210 ATOM_REFS_INIT ("_EMACS_TMP_", Xatom_EMACS_TMP
)
10211 ATOM_REFS_INIT ("TARGETS", Xatom_TARGETS
)
10212 ATOM_REFS_INIT ("NULL", Xatom_NULL
)
10213 ATOM_REFS_INIT ("ATOM", Xatom_ATOM
)
10214 ATOM_REFS_INIT ("ATOM_PAIR", Xatom_ATOM_PAIR
)
10215 ATOM_REFS_INIT ("CLIPBOARD_MANAGER", Xatom_CLIPBOARD_MANAGER
)
10216 ATOM_REFS_INIT ("_XEMBED_INFO", Xatom_XEMBED_INFO
)
10217 /* For properties of font. */
10218 ATOM_REFS_INIT ("PIXEL_SIZE", Xatom_PIXEL_SIZE
)
10219 ATOM_REFS_INIT ("AVERAGE_WIDTH", Xatom_AVERAGE_WIDTH
)
10220 ATOM_REFS_INIT ("_MULE_BASELINE_OFFSET", Xatom_MULE_BASELINE_OFFSET
)
10221 ATOM_REFS_INIT ("_MULE_RELATIVE_COMPOSE", Xatom_MULE_RELATIVE_COMPOSE
)
10222 ATOM_REFS_INIT ("_MULE_DEFAULT_ASCENT", Xatom_MULE_DEFAULT_ASCENT
)
10223 /* Ghostscript support. */
10224 ATOM_REFS_INIT ("DONE", Xatom_DONE
)
10225 ATOM_REFS_INIT ("PAGE", Xatom_PAGE
)
10226 ATOM_REFS_INIT ("SCROLLBAR", Xatom_Scrollbar
)
10227 ATOM_REFS_INIT ("_XEMBED", Xatom_XEMBED
)
10229 ATOM_REFS_INIT ("_NET_WM_STATE", Xatom_net_wm_state
)
10230 ATOM_REFS_INIT ("_NET_WM_STATE_FULLSCREEN", Xatom_net_wm_state_fullscreen
)
10231 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_HORZ",
10232 Xatom_net_wm_state_maximized_horz
)
10233 ATOM_REFS_INIT ("_NET_WM_STATE_MAXIMIZED_VERT",
10234 Xatom_net_wm_state_maximized_vert
)
10235 ATOM_REFS_INIT ("_NET_WM_STATE_STICKY", Xatom_net_wm_state_sticky
)
10236 ATOM_REFS_INIT ("_NET_WM_STATE_HIDDEN", Xatom_net_wm_state_hidden
)
10237 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE", Xatom_net_window_type
)
10238 ATOM_REFS_INIT ("_NET_WM_WINDOW_TYPE_TOOLTIP",
10239 Xatom_net_window_type_tooltip
)
10240 ATOM_REFS_INIT ("_NET_WM_ICON_NAME", Xatom_net_wm_icon_name
)
10241 ATOM_REFS_INIT ("_NET_WM_NAME", Xatom_net_wm_name
)
10242 ATOM_REFS_INIT ("_NET_SUPPORTED", Xatom_net_supported
)
10243 ATOM_REFS_INIT ("_NET_SUPPORTING_WM_CHECK", Xatom_net_supporting_wm_check
)
10244 ATOM_REFS_INIT ("_NET_WM_WINDOW_OPACITY", Xatom_net_wm_window_opacity
)
10245 ATOM_REFS_INIT ("_NET_ACTIVE_WINDOW", Xatom_net_active_window
)
10246 ATOM_REFS_INIT ("_NET_FRAME_EXTENTS", Xatom_net_frame_extents
)
10247 ATOM_REFS_INIT ("_NET_CURRENT_DESKTOP", Xatom_net_current_desktop
)
10248 ATOM_REFS_INIT ("_NET_WORKAREA", Xatom_net_workarea
)
10249 /* Session management */
10250 ATOM_REFS_INIT ("SM_CLIENT_ID", Xatom_SM_CLIENT_ID
)
10251 ATOM_REFS_INIT ("_XSETTINGS_SETTINGS", Xatom_xsettings_prop
)
10252 ATOM_REFS_INIT ("MANAGER", Xatom_xsettings_mgr
)
10256 const int atom_count
= sizeof (atom_refs
) / sizeof (atom_refs
[0]);
10257 /* 1 for _XSETTINGS_SN */
10258 const int total_atom_count
= 1 + atom_count
;
10259 Atom
*atoms_return
= xmalloc (total_atom_count
* sizeof *atoms_return
);
10260 char **atom_names
= xmalloc (total_atom_count
* sizeof *atom_names
);
10261 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
10262 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
10263 + INT_STRLEN_BOUND (int)];
10265 for (i
= 0; i
< atom_count
; i
++)
10266 atom_names
[i
] = (char *) atom_refs
[i
].name
;
10268 /* Build _XSETTINGS_SN atom name */
10269 sprintf (xsettings_atom_name
, xsettings_fmt
,
10270 XScreenNumberOfScreen (dpyinfo
->screen
));
10271 atom_names
[i
] = xsettings_atom_name
;
10273 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
10274 False
, atoms_return
);
10276 for (i
= 0; i
< atom_count
; i
++)
10277 *(Atom
*) ((char *) dpyinfo
+ atom_refs
[i
].offset
) = atoms_return
[i
];
10279 /* Manual copy of last atom */
10280 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
10282 xfree (atom_names
);
10283 xfree (atoms_return
);
10286 dpyinfo
->x_dnd_atoms_size
= 8;
10287 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
10288 * dpyinfo
->x_dnd_atoms_size
);
10290 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10291 gray_bits
, gray_width
, gray_height
,
10295 xim_initialize (dpyinfo
, resource_name
);
10298 xsettings_initialize (dpyinfo
);
10300 connection
= ConnectionNumber (dpyinfo
->display
);
10302 /* This is only needed for distinguishing keyboard and process input. */
10303 if (connection
!= 0)
10304 add_keyboard_wait_descriptor (connection
);
10307 fcntl (connection
, F_SETOWN
, getpid ());
10308 #endif /* ! defined (F_SETOWN) */
10310 if (interrupt_input
)
10311 init_sigio (connection
);
10315 XrmValue d
, fr
, to
;
10318 dpy
= dpyinfo
->display
;
10319 d
.addr
= (XPointer
)&dpy
;
10320 d
.size
= sizeof (Display
*);
10321 fr
.addr
= XtDefaultFont
;
10322 fr
.size
= sizeof (XtDefaultFont
);
10323 to
.size
= sizeof (Font
*);
10324 to
.addr
= (XPointer
)&font
;
10325 x_catch_errors (dpy
);
10326 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10328 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10329 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10330 x_uncatch_errors ();
10334 /* See if we should run in synchronous mode. This is useful
10335 for debugging X code. */
10338 value
= display_x_get_resource (dpyinfo
,
10339 build_string ("synchronous"),
10340 build_string ("Synchronous"),
10342 if (STRINGP (value
)
10343 && (!strcmp (SSDATA (value
), "true")
10344 || !strcmp (SSDATA (value
), "on")))
10345 XSynchronize (dpyinfo
->display
, True
);
10350 value
= display_x_get_resource (dpyinfo
,
10351 build_string ("useXIM"),
10352 build_string ("UseXIM"),
10355 if (STRINGP (value
)
10356 && (!strcmp (SSDATA (value
), "false")
10357 || !strcmp (SSDATA (value
), "off")))
10360 if (STRINGP (value
)
10361 && (!strcmp (SSDATA (value
), "true")
10362 || !strcmp (SSDATA (value
), "on")))
10368 /* Only do this for the very first display in the Emacs session.
10369 Ignore X session management when Emacs was first started on a
10371 if (terminal
->id
== 1)
10372 x_session_initialize (dpyinfo
);
10380 /* Get rid of display DPYINFO, deleting all frames on it,
10381 and without sending any more commands to the X server. */
10384 x_delete_display (struct x_display_info
*dpyinfo
)
10386 struct terminal
*t
;
10388 /* Close all frames and delete the generic struct terminal for this
10390 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10391 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10394 /* Close X session management when we close its display. */
10395 if (t
->id
== 1 && x_session_have_connection ())
10396 x_session_close ();
10398 delete_terminal (t
);
10402 /* Discard this display from x_display_name_list and x_display_list.
10403 We can't use Fdelq because that can quit. */
10404 if (! NILP (x_display_name_list
)
10405 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10406 x_display_name_list
= XCDR (x_display_name_list
);
10411 tail
= x_display_name_list
;
10412 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10414 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10416 XSETCDR (tail
, XCDR (XCDR (tail
)));
10419 tail
= XCDR (tail
);
10423 if (next_noop_dpyinfo
== dpyinfo
)
10424 next_noop_dpyinfo
= dpyinfo
->next
;
10426 if (x_display_list
== dpyinfo
)
10427 x_display_list
= dpyinfo
->next
;
10430 struct x_display_info
*tail
;
10432 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10433 if (tail
->next
== dpyinfo
)
10434 tail
->next
= tail
->next
->next
;
10437 xfree (dpyinfo
->x_id_name
);
10438 xfree (dpyinfo
->x_dnd_atoms
);
10439 xfree (dpyinfo
->color_cells
);
10443 #ifdef USE_X_TOOLKIT
10445 /* Atimer callback function for TIMER. Called every 0.1s to process
10446 Xt timeouts, if needed. We must avoid calling XtAppPending as
10447 much as possible because that function does an implicit XFlush
10448 that slows us down. */
10451 x_process_timeouts (struct atimer
*timer
)
10454 x_timeout_atimer_activated_flag
= 0;
10455 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10457 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10458 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10459 /* Reactivate the atimer for next time. */
10460 x_activate_timeout_atimer ();
10465 /* Install an asynchronous timer that processes Xt timeout events
10466 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10467 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10468 function whenever these variables are set. This is necessary
10469 because some widget sets use timeouts internally, for example the
10470 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10471 processed, these widgets don't behave normally. */
10474 x_activate_timeout_atimer (void)
10477 if (!x_timeout_atimer_activated_flag
)
10479 struct timespec interval
= make_timespec (0, 100 * 1000 * 1000);
10480 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10481 x_timeout_atimer_activated_flag
= 1;
10486 #endif /* USE_X_TOOLKIT */
10489 /* Set up use of X before we make the first connection. */
10491 static struct redisplay_interface x_redisplay_interface
=
10493 x_frame_parm_handlers
,
10497 x_clear_end_of_line
,
10499 x_after_update_window_line
,
10500 x_update_window_begin
,
10501 x_update_window_end
,
10503 x_clear_window_mouse_face
,
10504 x_get_glyph_overhangs
,
10505 x_fix_overlapping_area
,
10506 x_draw_fringe_bitmap
,
10507 0, /* define_fringe_bitmap */
10508 0, /* destroy_fringe_bitmap */
10509 x_compute_glyph_string_overhangs
,
10510 x_draw_glyph_string
,
10511 x_define_frame_cursor
,
10512 x_clear_frame_area
,
10513 x_draw_window_cursor
,
10514 x_draw_vertical_window_border
,
10515 x_shift_glyphs_for_insert
10519 /* This function is called when the last frame on a display is deleted. */
10521 x_delete_terminal (struct terminal
*terminal
)
10523 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10524 int connection
= -1;
10526 /* Protect against recursive calls. delete_frame in
10527 delete_terminal calls us back when it deletes our last frame. */
10528 if (!terminal
->name
)
10533 /* We must close our connection to the XIM server before closing the
10536 xim_close_dpy (dpyinfo
);
10539 /* If called from x_connection_closed, the display may already be closed
10540 and dpyinfo->display was set to 0 to indicate that. */
10541 if (dpyinfo
->display
)
10543 connection
= ConnectionNumber (dpyinfo
->display
);
10545 x_destroy_all_bitmaps (dpyinfo
);
10546 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10548 /* Whether or not XCloseDisplay destroys the associated resource
10549 database depends on the version of libX11. To avoid both
10550 crash and memory leak, we dissociate the database from the
10551 display and then destroy dpyinfo->xrdb ourselves.
10553 Unfortunately, the above strategy does not work in some
10554 situations due to a bug in newer versions of libX11: because
10555 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10556 dpy->db is NULL, XCloseDisplay destroys the associated
10557 database whereas it has not been created by XGetDefault
10558 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10559 don't destroy the database here in order to avoid the crash
10560 in the above situations for now, though that may cause memory
10561 leaks in other situations. */
10563 #ifdef HAVE_XRMSETDATABASE
10564 XrmSetDatabase (dpyinfo
->display
, NULL
);
10566 dpyinfo
->display
->db
= NULL
;
10568 /* We used to call XrmDestroyDatabase from x_delete_display, but
10569 some older versions of libX11 crash if we call it after
10570 closing all the displays. */
10571 XrmDestroyDatabase (dpyinfo
->xrdb
);
10575 xg_display_close (dpyinfo
->display
);
10577 #ifdef USE_X_TOOLKIT
10578 XtCloseDisplay (dpyinfo
->display
);
10580 XCloseDisplay (dpyinfo
->display
);
10582 #endif /* ! USE_GTK */
10585 /* No more input on this descriptor. */
10586 if (connection
!= -1)
10587 delete_keyboard_wait_descriptor (connection
);
10589 /* Mark as dead. */
10590 dpyinfo
->display
= NULL
;
10591 x_delete_display (dpyinfo
);
10595 /* Create a struct terminal, initialize it with the X11 specific
10596 functions and make DISPLAY->TERMINAL point to it. */
10598 static struct terminal
*
10599 x_create_terminal (struct x_display_info
*dpyinfo
)
10601 struct terminal
*terminal
;
10603 terminal
= create_terminal ();
10605 terminal
->type
= output_x_window
;
10606 terminal
->display_info
.x
= dpyinfo
;
10607 dpyinfo
->terminal
= terminal
;
10609 /* kboard is initialized in x_term_init. */
10611 terminal
->clear_frame_hook
= x_clear_frame
;
10612 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10613 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10614 terminal
->ring_bell_hook
= XTring_bell
;
10615 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10616 terminal
->reset_terminal_modes_hook
= NULL
;
10617 terminal
->set_terminal_modes_hook
= NULL
;
10618 terminal
->update_begin_hook
= x_update_begin
;
10619 terminal
->update_end_hook
= x_update_end
;
10620 terminal
->set_terminal_window_hook
= NULL
;
10621 terminal
->read_socket_hook
= XTread_socket
;
10622 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10623 terminal
->mouse_position_hook
= XTmouse_position
;
10624 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10625 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10626 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10627 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10628 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10629 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10630 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10632 terminal
->delete_frame_hook
= x_destroy_window
;
10633 terminal
->delete_terminal_hook
= x_delete_terminal
;
10635 terminal
->rif
= &x_redisplay_interface
;
10636 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10637 terminal
->char_ins_del_ok
= 1;
10638 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10639 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10640 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10647 x_initialize (void)
10652 last_tool_bar_item
= -1;
10653 any_help_event_p
= 0;
10654 ignore_next_mouse_click_timeout
= 0;
10657 current_count
= -1;
10660 /* Try to use interrupt input; if we can't, then start polling. */
10661 Fset_input_interrupt_mode (Qt
);
10663 #ifdef USE_X_TOOLKIT
10664 XtToolkitInitialize ();
10666 Xt_app_con
= XtCreateApplicationContext ();
10668 /* Register a converter from strings to pixels, which uses
10669 Emacs' color allocation infrastructure. */
10670 XtAppSetTypeConverter (Xt_app_con
,
10671 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10672 cvt_string_to_pixel_args
,
10673 XtNumber (cvt_string_to_pixel_args
),
10674 XtCacheByDisplay
, cvt_pixel_dtor
);
10676 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10679 #ifdef USE_TOOLKIT_SCROLL_BARS
10681 xaw3d_arrow_scroll
= False
;
10682 xaw3d_pick_top
= True
;
10686 pending_autoraise_frame
= 0;
10687 pending_event_wait
.f
= 0;
10688 pending_event_wait
.eventtype
= 0;
10690 /* Note that there is no real way portable across R3/R4 to get the
10691 original error handler. */
10692 XSetErrorHandler (x_error_handler
);
10693 XSetIOErrorHandler (x_io_error_quitter
);
10698 syms_of_xterm (void)
10700 x_error_message
= NULL
;
10702 staticpro (&x_display_name_list
);
10703 x_display_name_list
= Qnil
;
10705 staticpro (&last_mouse_scroll_bar
);
10706 last_mouse_scroll_bar
= Qnil
;
10708 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
10709 DEFSYM (Qlatin_1
, "latin-1");
10712 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10713 staticpro (&xg_default_icon_file
);
10715 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
10718 DEFVAR_BOOL ("x-use-underline-position-properties",
10719 x_use_underline_position_properties
,
10720 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
10721 A value of nil means ignore them. If you encounter fonts with bogus
10722 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10723 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10724 to override the font's UNDERLINE_POSITION for small font display
10726 x_use_underline_position_properties
= 1;
10728 DEFVAR_BOOL ("x-underline-at-descent-line",
10729 x_underline_at_descent_line
,
10730 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
10731 A value of nil means to draw the underline according to the value of the
10732 variable `x-use-underline-position-properties', which is usually at the
10733 baseline level. The default value is nil. */);
10734 x_underline_at_descent_line
= 0;
10736 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10737 x_mouse_click_focus_ignore_position
,
10738 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10739 This variable is only used when the window manager requires that you
10740 click on a frame to select it (give it focus). In that case, a value
10741 of nil, means that the selected window and cursor position changes to
10742 reflect the mouse click position, while a non-nil value means that the
10743 selected window or cursor position is preserved. */);
10744 x_mouse_click_focus_ignore_position
= 0;
10746 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
10747 doc
: /* Which toolkit scroll bars Emacs uses, if any.
10748 A value of nil means Emacs doesn't use toolkit scroll bars.
10749 With the X Window system, the value is a symbol describing the
10750 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
10751 With MS Windows or Nextstep, the value is t. */);
10752 #ifdef USE_TOOLKIT_SCROLL_BARS
10754 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10755 #elif defined HAVE_XAW3D
10756 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10758 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10760 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10763 Vx_toolkit_scroll_bars
= Qnil
;
10766 staticpro (&last_mouse_motion_frame
);
10767 last_mouse_motion_frame
= Qnil
;
10769 Qmodifier_value
= intern_c_string ("modifier-value");
10770 Qalt
= intern_c_string ("alt");
10771 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10772 Qhyper
= intern_c_string ("hyper");
10773 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10774 Qmeta
= intern_c_string ("meta");
10775 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10776 Qsuper
= intern_c_string ("super");
10777 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10779 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
10780 doc
: /* Which keys Emacs uses for the alt modifier.
10781 This should be one of the symbols `alt', `hyper', `meta', `super'.
10782 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10783 is nil, which is the same as `alt'. */);
10784 Vx_alt_keysym
= Qnil
;
10786 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
10787 doc
: /* Which keys Emacs uses for the hyper modifier.
10788 This should be one of the symbols `alt', `hyper', `meta', `super'.
10789 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10790 default is nil, which is the same as `hyper'. */);
10791 Vx_hyper_keysym
= Qnil
;
10793 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
10794 doc
: /* Which keys Emacs uses for the meta modifier.
10795 This should be one of the symbols `alt', `hyper', `meta', `super'.
10796 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10797 default is nil, which is the same as `meta'. */);
10798 Vx_meta_keysym
= Qnil
;
10800 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
10801 doc
: /* Which keys Emacs uses for the super modifier.
10802 This should be one of the symbols `alt', `hyper', `meta', `super'.
10803 For example, `super' means use the Super_L and Super_R keysyms. The
10804 default is nil, which is the same as `super'. */);
10805 Vx_super_keysym
= Qnil
;
10807 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
10808 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10809 Vx_keysym_table
= make_hash_table (hashtest_eql
, make_number (900),
10810 make_float (DEFAULT_REHASH_SIZE
),
10811 make_float (DEFAULT_REHASH_THRESHOLD
),