1 /* X Communication module for terminals which understand the X protocol.
3 Copyright (C) 1989, 1993-2012 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. */
31 #include "blockinput.h"
33 /* Need syssignal.h for various externs and definitions that may be required
34 by some configurations for calls to signal later in this source file. */
35 #include "syssignal.h"
37 /* This may include sys/types.h, and that somehow loses
38 if this is not done before the other system files. */
40 #include <X11/cursorfont.h>
42 /* Load sys/types.h if not already loaded.
43 In some systems loading it twice is suicidal. */
45 #include <sys/types.h>
48 #include <sys/ioctl.h>
56 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
57 /* #include <sys/param.h> */
60 #include "character.h"
63 #include "dispextern.h"
65 #include "termhooks.h"
68 #include "emacs-icon.h"
73 #include "intervals.h"
79 #include "xsettings.h"
81 #include "sysselect.h"
84 #include <X11/Shell.h>
92 #include <X11/Xproto.h>
97 #include "../lwlib/xlwmenu.h"
101 #if !defined (NO_EDITRES)
103 extern void _XEditResCheckMessages (Widget
, XtPointer
, XEvent
*, Boolean
*);
104 #endif /* not NO_EDITRES */
106 /* Include toolkit specific headers for the scroll bar widget. */
108 #ifdef USE_TOOLKIT_SCROLL_BARS
109 #if defined USE_MOTIF
110 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
111 #include <Xm/ScrollBar.h>
112 #else /* !USE_MOTIF i.e. use Xaw */
115 #include <X11/Xaw3d/Simple.h>
116 #include <X11/Xaw3d/Scrollbar.h>
117 #include <X11/Xaw3d/ThreeD.h>
118 #else /* !HAVE_XAW3D */
119 #include <X11/Xaw/Simple.h>
120 #include <X11/Xaw/Scrollbar.h>
121 #endif /* !HAVE_XAW3D */
123 #define XtNpickTop "pickTop"
124 #endif /* !XtNpickTop */
125 #endif /* !USE_MOTIF */
126 #endif /* USE_TOOLKIT_SCROLL_BARS */
128 #endif /* USE_X_TOOLKIT */
132 #ifndef XtNinitialState
133 #define XtNinitialState "initialState"
137 #include "bitmaps/gray.xbm"
139 /* Default to using XIM if available. */
143 int use_xim
= 0; /* configure --without-xim */
148 /* Non-zero means that a HELP_EVENT has been generated since Emacs
151 static int any_help_event_p
;
153 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
154 static Lisp_Object last_window
;
156 /* This is a chain of structures for all the X displays currently in
159 struct x_display_info
*x_display_list
;
161 /* This is a list of cons cells, each of the form (NAME
162 . FONT-LIST-CACHE), one for each element of x_display_list and in
163 the same order. NAME is the name of the frame. FONT-LIST-CACHE
164 records previous values returned by x-list-fonts. */
166 Lisp_Object x_display_name_list
;
168 /* This is a frame waiting to be auto-raised, within XTread_socket. */
170 static struct frame
*pending_autoraise_frame
;
172 /* This is a frame waiting for an event matching mask, within XTread_socket. */
177 } pending_event_wait
;
180 /* The application context for Xt use. */
181 XtAppContext Xt_app_con
;
182 static String Xt_default_resources
[] = {0};
184 /* Non-zero means user is interacting with a toolkit scroll bar. */
186 static int toolkit_scroll_bar_interaction
;
187 #endif /* USE_X_TOOLKIT */
189 /* Non-zero timeout value means ignore next mouse click if it arrives
190 before that timeout elapses (i.e. as part of the same sequence of
191 events resulting from clicking on a frame to select it). */
193 static unsigned long ignore_next_mouse_click_timeout
;
197 Formerly, we used PointerMotionHintMask (in standard_event_mask)
198 so that we would have to call XQueryPointer after each MotionNotify
199 event to ask for another such event. However, this made mouse tracking
200 slow, and there was a bug that made it eventually stop.
202 Simply asking for MotionNotify all the time seems to work better.
204 In order to avoid asking for motion events and then throwing most
205 of them away or busy-polling the server for mouse positions, we ask
206 the server for pointer motion hints. This means that we get only
207 one event per group of mouse movements. "Groups" are delimited by
208 other kinds of events (focus changes and button clicks, for
209 example), or by XQueryPointer calls; when one of these happens, we
210 get another MotionNotify event the next time the mouse moves. This
211 is at least as efficient as getting motion events when mouse
212 tracking is on, and I suspect only negligibly worse when tracking
215 /* Where the mouse was last time we reported a mouse event. */
217 static XRectangle last_mouse_glyph
;
218 static FRAME_PTR last_mouse_glyph_frame
;
219 static Lisp_Object last_mouse_press_frame
;
221 /* The scroll bar in which the last X motion event occurred.
223 If the last X motion event occurred in a scroll bar, we set this so
224 XTmouse_position can know whether to report a scroll bar motion or
227 If the last X motion event didn't occur in a scroll bar, we set
228 this to Qnil, to tell XTmouse_position to return an ordinary motion
231 static Lisp_Object last_mouse_scroll_bar
;
233 /* This is a hack. We would really prefer that XTmouse_position would
234 return the time associated with the position it returns, but there
235 doesn't seem to be any way to wrest the time-stamp from the server
236 along with the position query. So, we just keep track of the time
237 of the last movement we received, and return that in hopes that
238 it's somewhat accurate. */
240 static Time last_mouse_movement_time
;
242 /* Time for last user interaction as returned in X events. */
244 static Time last_user_time
;
246 /* Incremented by XTread_socket whenever it really tries to read
249 static int volatile input_signal_count
;
251 /* Used locally within XTread_socket. */
253 static int x_noop_count
;
255 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
257 static Lisp_Object Qvendor_specific_keysyms
;
258 static Lisp_Object Qlatin_1
;
261 /* The name of the Emacs icon file. */
262 static Lisp_Object xg_default_icon_file
;
264 /* Used in gtkutil.c. */
265 Lisp_Object Qx_gtk_map_stock
;
268 /* Some functions take this as char *, not const char *. */
269 static char emacs_class
[] = EMACS_CLASS
;
273 XEMBED_MAPPED
= 1 << 0
278 XEMBED_EMBEDDED_NOTIFY
= 0,
279 XEMBED_WINDOW_ACTIVATE
= 1,
280 XEMBED_WINDOW_DEACTIVATE
= 2,
281 XEMBED_REQUEST_FOCUS
= 3,
283 XEMBED_FOCUS_OUT
= 5,
284 XEMBED_FOCUS_NEXT
= 6,
285 XEMBED_FOCUS_PREV
= 7,
287 XEMBED_MODALITY_ON
= 10,
288 XEMBED_MODALITY_OFF
= 11,
289 XEMBED_REGISTER_ACCELERATOR
= 12,
290 XEMBED_UNREGISTER_ACCELERATOR
= 13,
291 XEMBED_ACTIVATE_ACCELERATOR
= 14
294 /* Used in x_flush. */
296 static int x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
297 static void x_set_window_size_1 (struct frame
*, int, int, int);
298 static void x_raise_frame (struct frame
*);
299 static void x_lower_frame (struct frame
*);
300 static const XColor
*x_color_cells (Display
*, int *);
301 static void x_update_window_end (struct window
*, int, int);
303 static int x_io_error_quitter (Display
*);
304 static struct terminal
*x_create_terminal (struct x_display_info
*);
305 void x_delete_terminal (struct terminal
*);
306 static void x_update_end (struct frame
*);
307 static void XTframe_up_to_date (struct frame
*);
308 static void XTset_terminal_modes (struct terminal
*);
309 static void XTreset_terminal_modes (struct terminal
*);
310 static void x_clear_frame (struct frame
*);
311 static _Noreturn
void x_ins_del_lines (struct frame
*, int, int);
312 static void frame_highlight (struct frame
*);
313 static void frame_unhighlight (struct frame
*);
314 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
315 static void x_focus_changed (int, int, struct x_display_info
*,
316 struct frame
*, struct input_event
*);
317 static void x_detect_focus_change (struct x_display_info
*,
318 XEvent
*, struct input_event
*);
319 static void XTframe_rehighlight (struct frame
*);
320 static void x_frame_rehighlight (struct x_display_info
*);
321 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
322 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
323 enum text_cursor_kinds
);
325 static void x_clip_to_row (struct window
*, struct glyph_row
*, int, GC
);
326 static void x_flush (struct frame
*f
);
327 static void x_update_begin (struct frame
*);
328 static void x_update_window_begin (struct window
*);
329 static void x_after_update_window_line (struct glyph_row
*);
330 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
331 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
332 enum scroll_bar_part
*,
333 Lisp_Object
*, Lisp_Object
*,
335 static int x_handle_net_wm_state (struct frame
*, XPropertyEvent
*);
336 static void x_check_fullscreen (struct frame
*);
337 static void x_check_expected_move (struct frame
*, int, int);
338 static void x_sync_with_move (struct frame
*, int, int, int);
339 static int handle_one_xevent (struct x_display_info
*, XEvent
*,
340 int *, struct input_event
*);
342 static int x_dispatch_event (XEvent
*, Display
*);
344 /* Don't declare this _Noreturn because we want no
345 interference with debugging failing X calls. */
346 static void x_connection_closed (Display
*, const char *);
347 static void x_wm_set_window_state (struct frame
*, int);
348 static void x_wm_set_icon_pixmap (struct frame
*, ptrdiff_t);
349 static void x_initialize (void);
352 /* Flush display of frame F, or of all frames if F is null. */
355 x_flush (struct frame
*f
)
357 /* Don't call XFlush when it is not safe to redisplay; the X
358 connection may be broken. */
359 if (!NILP (Vinhibit_redisplay
))
365 Lisp_Object rest
, frame
;
366 FOR_EACH_FRAME (rest
, frame
)
367 if (FRAME_X_P (XFRAME (frame
)))
368 x_flush (XFRAME (frame
));
370 else if (FRAME_X_P (f
))
371 XFlush (FRAME_X_DISPLAY (f
));
376 /* Remove calls to XFlush by defining XFlush to an empty replacement.
377 Calls to XFlush should be unnecessary because the X output buffer
378 is flushed automatically as needed by calls to XPending,
379 XNextEvent, or XWindowEvent according to the XFlush man page.
380 XTread_socket calls XPending. Removing XFlush improves
383 #define XFlush(DISPLAY) (void) 0
386 /***********************************************************************
388 ***********************************************************************/
392 /* This is a function useful for recording debugging information about
393 the sequence of occurrences in this file. */
401 struct record event_record
[100];
403 int event_record_index
;
406 record_event (char *locus
, int type
)
408 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
409 event_record_index
= 0;
411 event_record
[event_record_index
].locus
= locus
;
412 event_record
[event_record_index
].type
= type
;
413 event_record_index
++;
420 /* Return the struct x_display_info corresponding to DPY. */
422 struct x_display_info
*
423 x_display_info_for_display (Display
*dpy
)
425 struct x_display_info
*dpyinfo
;
427 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
428 if (dpyinfo
->display
== dpy
)
435 x_find_topmost_parent (struct frame
*f
)
437 struct x_output
*x
= f
->output_data
.x
;
438 Window win
= None
, wi
= x
->parent_desc
;
439 Display
*dpy
= FRAME_X_DISPLAY (f
);
441 while (wi
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
445 unsigned int nchildren
;
448 XQueryTree (dpy
, win
, &root
, &wi
, &children
, &nchildren
);
455 #define OPAQUE 0xffffffff
458 x_set_frame_alpha (struct frame
*f
)
460 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
461 Display
*dpy
= FRAME_X_DISPLAY (f
);
462 Window win
= FRAME_OUTER_WINDOW (f
);
464 double alpha_min
= 1.0;
468 if (dpyinfo
->x_highlight_frame
== f
)
473 if (FLOATP (Vframe_alpha_lower_limit
))
474 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
475 else if (INTEGERP (Vframe_alpha_lower_limit
))
476 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
480 else if (alpha
> 1.0)
482 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
485 opac
= alpha
* OPAQUE
;
487 x_catch_errors (dpy
);
489 /* If there is a parent from the window manager, put the property there
490 also, to work around broken window managers that fail to do that.
491 Do this unconditionally as this function is called on reparent when
492 alpha has not changed on the frame. */
494 parent
= x_find_topmost_parent (f
);
496 XChangeProperty (dpy
, parent
, dpyinfo
->Xatom_net_wm_window_opacity
,
497 XA_CARDINAL
, 32, PropModeReplace
,
498 (unsigned char *) &opac
, 1L);
500 /* return unless necessary */
505 unsigned long n
, left
;
507 rc
= XGetWindowProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
508 0L, 1L, False
, XA_CARDINAL
,
509 &actual
, &format
, &n
, &left
,
512 if (rc
== Success
&& actual
!= None
)
514 unsigned long value
= *(unsigned long *)data
;
524 XChangeProperty (dpy
, win
, dpyinfo
->Xatom_net_wm_window_opacity
,
525 XA_CARDINAL
, 32, PropModeReplace
,
526 (unsigned char *) &opac
, 1L);
531 x_display_pixel_height (struct x_display_info
*dpyinfo
)
533 return HeightOfScreen (dpyinfo
->screen
);
537 x_display_pixel_width (struct x_display_info
*dpyinfo
)
539 return WidthOfScreen (dpyinfo
->screen
);
543 /***********************************************************************
544 Starting and ending an update
545 ***********************************************************************/
547 /* Start an update of frame F. This function is installed as a hook
548 for update_begin, i.e. it is called when update_begin is called.
549 This function is called prior to calls to x_update_window_begin for
550 each window being updated. Currently, there is nothing to do here
551 because all interesting stuff is done on a window basis. */
554 x_update_begin (struct frame
*f
)
560 /* Start update of window W. Set the global variable updated_window
561 to the window being updated and set output_cursor to the cursor
565 x_update_window_begin (struct window
*w
)
567 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
568 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
571 set_output_cursor (&w
->cursor
);
575 if (f
== hlinfo
->mouse_face_mouse_frame
)
577 /* Don't do highlighting for mouse motion during the update. */
578 hlinfo
->mouse_face_defer
= 1;
580 /* If F needs to be redrawn, simply forget about any prior mouse
582 if (FRAME_GARBAGED_P (f
))
583 hlinfo
->mouse_face_window
= Qnil
;
590 /* Draw a vertical window border from (x,y0) to (x,y1) */
593 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
595 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
598 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
600 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
603 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
604 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
607 /* End update of window W (which is equal to updated_window).
609 Draw vertical borders between horizontally adjacent windows, and
610 display W's cursor if CURSOR_ON_P is non-zero.
612 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
613 glyphs in mouse-face were overwritten. In that case we have to
614 make sure that the mouse-highlight is properly redrawn.
616 W may be a menu bar pseudo-window in case we don't have X toolkit
617 support. Such windows don't have a cursor, so don't display it
621 x_update_window_end (struct window
*w
, int cursor_on_p
, int mouse_face_overwritten_p
)
623 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (XFRAME (w
->frame
));
625 if (!w
->pseudo_window_p
)
630 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
632 output_cursor
.x
, output_cursor
.y
);
634 if (draw_window_fringes (w
, 1))
635 x_draw_vertical_border (w
);
640 /* If a row with mouse-face was overwritten, arrange for
641 XTframe_up_to_date to redisplay the mouse highlight. */
642 if (mouse_face_overwritten_p
)
644 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
645 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
646 hlinfo
->mouse_face_window
= Qnil
;
649 updated_window
= NULL
;
653 /* End update of frame F. This function is installed as a hook in
657 x_update_end (struct frame
*f
)
659 /* Mouse highlight may be displayed again. */
660 MOUSE_HL_INFO (f
)->mouse_face_defer
= 0;
664 XFlush (FRAME_X_DISPLAY (f
));
670 /* This function is called from various places in xdisp.c whenever a
671 complete update has been performed. The global variable
672 updated_window is not available here. */
675 XTframe_up_to_date (struct frame
*f
)
679 Mouse_HLInfo
*hlinfo
= MOUSE_HL_INFO (f
);
681 if (hlinfo
->mouse_face_deferred_gc
682 || f
== hlinfo
->mouse_face_mouse_frame
)
685 if (hlinfo
->mouse_face_mouse_frame
)
686 note_mouse_highlight (hlinfo
->mouse_face_mouse_frame
,
687 hlinfo
->mouse_face_mouse_x
,
688 hlinfo
->mouse_face_mouse_y
);
689 hlinfo
->mouse_face_deferred_gc
= 0;
696 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
697 arrow bitmaps, or clear the fringes if no bitmaps are required
698 before DESIRED_ROW is made current. The window being updated is
699 found in updated_window. This function It is called from
700 update_window_line only if it is known that there are differences
701 between bitmaps to be drawn between current row and DESIRED_ROW. */
704 x_after_update_window_line (struct glyph_row
*desired_row
)
706 struct window
*w
= updated_window
;
712 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
713 desired_row
->redraw_fringe_bitmaps_p
= 1;
715 /* When a window has disappeared, make sure that no rest of
716 full-width rows stays visible in the internal border. Could
717 check here if updated_window is the leftmost/rightmost window,
718 but I guess it's not worth doing since vertically split windows
719 are almost never used, internal border is rarely set, and the
720 overhead is very small. */
721 if (windows_or_buffers_changed
722 && desired_row
->full_width_p
723 && (f
= XFRAME (w
->frame
),
724 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
726 && (height
= desired_row
->visible_height
,
729 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
732 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
733 0, y
, width
, height
, False
);
734 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
735 FRAME_PIXEL_WIDTH (f
) - width
,
736 y
, width
, height
, False
);
742 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
744 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
745 Display
*display
= FRAME_X_DISPLAY (f
);
746 Window window
= FRAME_X_WINDOW (f
);
747 GC gc
= f
->output_data
.x
->normal_gc
;
748 struct face
*face
= p
->face
;
750 /* Must clip because of partially visible lines. */
751 x_clip_to_row (w
, row
, -1, gc
);
755 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
757 /* In case the same realized face is used for fringes and
758 for something displayed in the text (e.g. face `region' on
759 mono-displays, the fill style may have been changed to
760 FillSolid in x_draw_glyph_string_background. */
762 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
764 XSetForeground (display
, face
->gc
, face
->background
);
766 #ifdef USE_TOOLKIT_SCROLL_BARS
767 /* If the fringe is adjacent to the left (right) scroll bar of a
768 leftmost (rightmost, respectively) window, then extend its
769 background to the gap between the fringe and the bar. */
770 if ((WINDOW_LEFTMOST_P (w
)
771 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
772 || (WINDOW_RIGHTMOST_P (w
)
773 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
775 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
779 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
780 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
781 * FRAME_COLUMN_WIDTH (f
));
785 /* Bitmap fills the fringe. */
786 if (bar_area_x
+ bar_area_width
== p
->x
)
787 bx
= bar_area_x
+ sb_width
;
788 else if (p
->x
+ p
->wd
== bar_area_x
)
792 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
794 nx
= bar_area_width
- sb_width
;
795 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
797 ny
= row
->visible_height
;
802 if (bar_area_x
+ bar_area_width
== bx
)
804 bx
= bar_area_x
+ sb_width
;
805 nx
+= bar_area_width
- sb_width
;
807 else if (bx
+ nx
== bar_area_x
)
808 nx
+= bar_area_width
- sb_width
;
813 if (bx
>= 0 && nx
> 0)
814 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
817 XSetForeground (display
, face
->gc
, face
->foreground
);
823 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
824 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
828 bits
= (char *) (p
->bits
+ p
->dh
);
830 bits
= (char *) p
->bits
+ p
->dh
;
832 /* Draw the bitmap. I believe these small pixmaps can be cached
834 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
836 ? (p
->overlay_p
? face
->background
837 : f
->output_data
.x
->cursor_pixel
)
839 face
->background
, depth
);
843 clipmask
= XCreatePixmapFromBitmapData (display
,
844 FRAME_X_DISPLAY_INFO (f
)->root_window
,
847 gcv
.clip_mask
= clipmask
;
848 gcv
.clip_x_origin
= p
->x
;
849 gcv
.clip_y_origin
= p
->y
;
850 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
853 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
854 p
->wd
, p
->h
, p
->x
, p
->y
);
855 XFreePixmap (display
, pixmap
);
859 gcv
.clip_mask
= (Pixmap
) 0;
860 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
861 XFreePixmap (display
, clipmask
);
865 XSetClipMask (display
, gc
, None
);
870 /* This is called when starting Emacs and when restarting after
871 suspend. When starting Emacs, no X window is mapped. And nothing
872 must be done to Emacs's own window if it is suspended (though that
876 XTset_terminal_modes (struct terminal
*terminal
)
880 /* This is called when exiting or suspending Emacs. Exiting will make
881 the X-windows go away, and suspending requires no action. */
884 XTreset_terminal_modes (struct terminal
*terminal
)
889 /***********************************************************************
891 ***********************************************************************/
895 static void x_set_glyph_string_clipping (struct glyph_string
*);
896 static void x_set_glyph_string_gc (struct glyph_string
*);
897 static void x_draw_glyph_string_background (struct glyph_string
*,
899 static void x_draw_glyph_string_foreground (struct glyph_string
*);
900 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
901 static void x_draw_glyph_string_box (struct glyph_string
*);
902 static void x_draw_glyph_string (struct glyph_string
*);
903 static _Noreturn
void x_delete_glyphs (struct frame
*, int);
904 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
905 static void x_set_cursor_gc (struct glyph_string
*);
906 static void x_set_mode_line_face_gc (struct glyph_string
*);
907 static void x_set_mouse_face_gc (struct glyph_string
*);
908 static int x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
909 unsigned long *, double, int);
910 static void x_setup_relief_color (struct frame
*, struct relief
*,
911 double, int, unsigned long);
912 static void x_setup_relief_colors (struct glyph_string
*);
913 static void x_draw_image_glyph_string (struct glyph_string
*);
914 static void x_draw_image_relief (struct glyph_string
*);
915 static void x_draw_image_foreground (struct glyph_string
*);
916 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
917 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
919 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
920 int, int, int, int, int, int,
922 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
923 int, int, int, XRectangle
*);
924 static void x_scroll_bar_clear (struct frame
*);
927 static void x_check_font (struct frame
*, struct font
*);
931 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
935 x_set_cursor_gc (struct glyph_string
*s
)
937 if (s
->font
== FRAME_FONT (s
->f
)
938 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
939 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
941 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
944 /* Cursor on non-default face: must merge. */
948 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
949 xgcv
.foreground
= s
->face
->background
;
951 /* If the glyph would be invisible, try a different foreground. */
952 if (xgcv
.foreground
== xgcv
.background
)
953 xgcv
.foreground
= s
->face
->foreground
;
954 if (xgcv
.foreground
== xgcv
.background
)
955 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
956 if (xgcv
.foreground
== xgcv
.background
)
957 xgcv
.foreground
= s
->face
->foreground
;
959 /* Make sure the cursor is distinct from text in this face. */
960 if (xgcv
.background
== s
->face
->background
961 && xgcv
.foreground
== s
->face
->foreground
)
963 xgcv
.background
= s
->face
->foreground
;
964 xgcv
.foreground
= s
->face
->background
;
967 IF_DEBUG (x_check_font (s
->f
, s
->font
));
968 xgcv
.graphics_exposures
= False
;
969 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
971 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
972 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
975 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
976 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
978 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
983 /* Set up S->gc of glyph string S for drawing text in mouse face. */
986 x_set_mouse_face_gc (struct glyph_string
*s
)
991 /* What face has to be used last for the mouse face? */
992 face_id
= MOUSE_HL_INFO (s
->f
)->mouse_face_face_id
;
993 face
= FACE_FROM_ID (s
->f
, face_id
);
995 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
997 if (s
->first_glyph
->type
== CHAR_GLYPH
)
998 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1000 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1001 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1002 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1004 if (s
->font
== s
->face
->font
)
1005 s
->gc
= s
->face
->gc
;
1008 /* Otherwise construct scratch_cursor_gc with values from FACE
1013 xgcv
.background
= s
->face
->background
;
1014 xgcv
.foreground
= s
->face
->foreground
;
1015 xgcv
.graphics_exposures
= False
;
1016 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1018 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1019 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1022 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1023 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1025 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1028 eassert (s
->gc
!= 0);
1032 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1033 Faces to use in the mode line have already been computed when the
1034 matrix was built, so there isn't much to do, here. */
1037 x_set_mode_line_face_gc (struct glyph_string
*s
)
1039 s
->gc
= s
->face
->gc
;
1043 /* Set S->gc of glyph string S for drawing that glyph string. Set
1044 S->stippled_p to a non-zero value if the face of S has a stipple
1048 x_set_glyph_string_gc (struct glyph_string
*s
)
1050 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1052 if (s
->hl
== DRAW_NORMAL_TEXT
)
1054 s
->gc
= s
->face
->gc
;
1055 s
->stippled_p
= s
->face
->stipple
!= 0;
1057 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1059 x_set_mode_line_face_gc (s
);
1060 s
->stippled_p
= s
->face
->stipple
!= 0;
1062 else if (s
->hl
== DRAW_CURSOR
)
1064 x_set_cursor_gc (s
);
1067 else if (s
->hl
== DRAW_MOUSE_FACE
)
1069 x_set_mouse_face_gc (s
);
1070 s
->stippled_p
= s
->face
->stipple
!= 0;
1072 else if (s
->hl
== DRAW_IMAGE_RAISED
1073 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1075 s
->gc
= s
->face
->gc
;
1076 s
->stippled_p
= s
->face
->stipple
!= 0;
1080 s
->gc
= s
->face
->gc
;
1081 s
->stippled_p
= s
->face
->stipple
!= 0;
1084 /* GC must have been set. */
1085 eassert (s
->gc
!= 0);
1089 /* Set clipping for output of glyph string S. S may be part of a mode
1090 line or menu if we don't have X toolkit support. */
1093 x_set_glyph_string_clipping (struct glyph_string
*s
)
1095 XRectangle
*r
= s
->clip
;
1096 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1099 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1104 /* Set SRC's clipping for output of glyph string DST. This is called
1105 when we are drawing DST's left_overhang or right_overhang only in
1109 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1114 r
.width
= src
->width
;
1116 r
.height
= src
->height
;
1119 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1124 Compute left and right overhang of glyph string S. */
1127 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1130 && (s
->first_glyph
->type
== CHAR_GLYPH
1131 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1133 struct font_metrics metrics
;
1135 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1137 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1138 struct font
*font
= s
->font
;
1141 for (i
= 0; i
< s
->nchars
; i
++)
1142 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1143 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1147 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1149 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1151 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1152 ? metrics
.rbearing
- metrics
.width
: 0);
1153 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1157 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1158 s
->left_overhang
= - s
->cmp
->lbearing
;
1163 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1166 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1169 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1170 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1171 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1172 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1176 /* Draw the background of glyph_string S. If S->background_filled_p
1177 is non-zero don't draw it. FORCE_P non-zero means draw the
1178 background even if it wouldn't be drawn normally. This is used
1179 when a string preceding S draws into the background of S, or S
1180 contains the first component of a composition. */
1183 x_draw_glyph_string_background (struct glyph_string
*s
, int force_p
)
1185 /* Nothing to do if background has already been drawn or if it
1186 shouldn't be drawn in the first place. */
1187 if (!s
->background_filled_p
)
1189 int box_line_width
= max (s
->face
->box_line_width
, 0);
1193 /* Fill background with a stipple pattern. */
1194 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1195 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1196 s
->y
+ box_line_width
,
1197 s
->background_width
,
1198 s
->height
- 2 * box_line_width
);
1199 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1200 s
->background_filled_p
= 1;
1202 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1203 || s
->font_not_found_p
1204 || s
->extends_to_end_of_line_p
1207 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1208 s
->background_width
,
1209 s
->height
- 2 * box_line_width
);
1210 s
->background_filled_p
= 1;
1216 /* Draw the foreground of glyph string S. */
1219 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1223 /* If first glyph of S has a left box line, start drawing the text
1224 of S to the right of that box line. */
1225 if (s
->face
->box
!= FACE_NO_BOX
1226 && s
->first_glyph
->left_box_line_p
)
1227 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1231 /* Draw characters of S as rectangles if S's font could not be
1233 if (s
->font_not_found_p
)
1235 for (i
= 0; i
< s
->nchars
; ++i
)
1237 struct glyph
*g
= s
->first_glyph
+ i
;
1238 XDrawRectangle (s
->display
, s
->window
,
1239 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1241 x
+= g
->pixel_width
;
1246 struct font
*font
= s
->font
;
1247 int boff
= font
->baseline_offset
;
1250 if (font
->vertical_centering
)
1251 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1253 y
= s
->ybase
- boff
;
1255 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1256 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1258 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1259 if (s
->face
->overstrike
)
1260 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1264 /* Draw the foreground of composite glyph string S. */
1267 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1270 struct font
*font
= s
->font
;
1272 /* If first glyph of S has a left box line, start drawing the text
1273 of S to the right of that box line. */
1274 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1275 && s
->first_glyph
->left_box_line_p
)
1276 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1280 /* S is a glyph string for a composition. S->cmp_from is the index
1281 of the first character drawn for glyphs of this composition.
1282 S->cmp_from == 0 means we are drawing the very first character of
1283 this composition. */
1285 /* Draw a rectangle for the composition if the font for the very
1286 first character of the composition could not be loaded. */
1287 if (s
->font_not_found_p
)
1289 if (s
->cmp_from
== 0)
1290 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1291 s
->width
- 1, s
->height
- 1);
1293 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1297 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1298 /* TAB in a composition means display glyphs with padding
1299 space on the left or right. */
1300 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1302 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1303 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1305 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1306 if (s
->face
->overstrike
)
1307 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1312 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1317 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1319 glyph
= LGSTRING_GLYPH (gstring
, i
);
1320 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1321 width
+= LGLYPH_WIDTH (glyph
);
1324 int xoff
, yoff
, wadjust
;
1328 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1329 if (s
->face
->overstrike
)
1330 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1333 xoff
= LGLYPH_XOFF (glyph
);
1334 yoff
= LGLYPH_YOFF (glyph
);
1335 wadjust
= LGLYPH_WADJUST (glyph
);
1336 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1337 if (s
->face
->overstrike
)
1338 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1346 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1347 if (s
->face
->overstrike
)
1348 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1354 /* Draw the foreground of glyph string S for glyphless characters. */
1357 x_draw_glyphless_glyph_string_foreground (struct glyph_string
*s
)
1359 struct glyph
*glyph
= s
->first_glyph
;
1363 /* If first glyph of S has a left box line, start drawing the text
1364 of S to the right of that box line. */
1365 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1366 && s
->first_glyph
->left_box_line_p
)
1367 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1373 for (i
= 0; i
< s
->nchars
; i
++, glyph
++)
1375 char buf
[7], *str
= NULL
;
1376 int len
= glyph
->u
.glyphless
.len
;
1378 if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_ACRONYM
)
1381 && CHAR_TABLE_P (Vglyphless_char_display
)
1382 && (CHAR_TABLE_EXTRA_SLOTS (XCHAR_TABLE (Vglyphless_char_display
))
1386 = (! glyph
->u
.glyphless
.for_no_font
1387 ? CHAR_TABLE_REF (Vglyphless_char_display
,
1388 glyph
->u
.glyphless
.ch
)
1389 : XCHAR_TABLE (Vglyphless_char_display
)->extras
[0]);
1390 if (STRINGP (acronym
))
1391 str
= SSDATA (acronym
);
1394 else if (glyph
->u
.glyphless
.method
== GLYPHLESS_DISPLAY_HEX_CODE
)
1396 sprintf ((char *) buf
, "%0*X",
1397 glyph
->u
.glyphless
.ch
< 0x10000 ? 4 : 6,
1398 glyph
->u
.glyphless
.ch
);
1404 int upper_len
= (len
+ 1) / 2;
1407 /* It is assured that all LEN characters in STR is ASCII. */
1408 for (j
= 0; j
< len
; j
++)
1410 code
= s
->font
->driver
->encode_char (s
->font
, str
[j
]);
1411 STORE_XCHAR2B (char2b
+ j
, code
>> 8, code
& 0xFF);
1413 s
->font
->driver
->draw (s
, 0, upper_len
,
1414 x
+ glyph
->slice
.glyphless
.upper_xoff
,
1415 s
->ybase
+ glyph
->slice
.glyphless
.upper_yoff
,
1417 s
->font
->driver
->draw (s
, upper_len
, len
,
1418 x
+ glyph
->slice
.glyphless
.lower_xoff
,
1419 s
->ybase
+ glyph
->slice
.glyphless
.lower_yoff
,
1422 if (glyph
->u
.glyphless
.method
!= GLYPHLESS_DISPLAY_THIN_SPACE
)
1423 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
1424 x
, s
->ybase
- glyph
->ascent
,
1425 glyph
->pixel_width
- 1,
1426 glyph
->ascent
+ glyph
->descent
- 1);
1427 x
+= glyph
->pixel_width
;
1431 #ifdef USE_X_TOOLKIT
1433 static Boolean
cvt_string_to_pixel (Display
*, XrmValue
*, Cardinal
*,
1434 XrmValue
*, XrmValue
*, XtPointer
*);
1435 static void cvt_pixel_dtor (XtAppContext
, XrmValue
*, XtPointer
,
1436 XrmValue
*, Cardinal
*);
1440 /* Return the frame on which widget WIDGET is used.. Abort if frame
1441 cannot be determined. */
1443 static struct frame
*
1444 x_frame_of_widget (Widget widget
)
1446 struct x_display_info
*dpyinfo
;
1450 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1452 /* Find the top-level shell of the widget. Note that this function
1453 can be called when the widget is not yet realized, so XtWindow
1454 (widget) == 0. That's the reason we can't simply use
1455 x_any_window_to_frame. */
1456 while (!XtIsTopLevelShell (widget
))
1457 widget
= XtParent (widget
);
1459 /* Look for a frame with that top-level widget. Allocate the color
1460 on that frame to get the right gamma correction value. */
1461 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1462 if (FRAMEP (XCAR (tail
))
1463 && (f
= XFRAME (XCAR (tail
)),
1465 && f
->output_data
.nothing
!= 1
1466 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1467 && f
->output_data
.x
->widget
== widget
)
1473 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1474 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1475 If this produces the same color as PIXEL, try a color where all RGB
1476 values have DELTA added. Return the allocated color in *PIXEL.
1477 DISPLAY is the X display, CMAP is the colormap to operate on.
1478 Value is non-zero if successful. */
1481 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1482 unsigned long *pixel
, double factor
, int delta
)
1484 struct frame
*f
= x_frame_of_widget (widget
);
1485 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1488 #endif /* USE_LUCID */
1491 /* Structure specifying which arguments should be passed by Xt to
1492 cvt_string_to_pixel. We want the widget's screen and colormap. */
1494 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1496 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1498 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1503 /* The address of this variable is returned by
1504 cvt_string_to_pixel. */
1506 static Pixel cvt_string_to_pixel_value
;
1509 /* Convert a color name to a pixel color.
1511 DPY is the display we are working on.
1513 ARGS is an array of *NARGS XrmValue structures holding additional
1514 information about the widget for which the conversion takes place.
1515 The contents of this array are determined by the specification
1516 in cvt_string_to_pixel_args.
1518 FROM is a pointer to an XrmValue which points to the color name to
1519 convert. TO is an XrmValue in which to return the pixel color.
1521 CLOSURE_RET is a pointer to user-data, in which we record if
1522 we allocated the color or not.
1524 Value is True if successful, False otherwise. */
1527 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1528 XrmValue
*from
, XrmValue
*to
,
1529 XtPointer
*closure_ret
)
1539 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1540 "wrongParameters", "cvt_string_to_pixel",
1542 "Screen and colormap args required", NULL
, NULL
);
1546 screen
= *(Screen
**) args
[0].addr
;
1547 cmap
= *(Colormap
*) args
[1].addr
;
1548 color_name
= (String
) from
->addr
;
1550 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1552 *closure_ret
= (XtPointer
) False
;
1553 pixel
= WhitePixelOfScreen (screen
);
1555 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1557 *closure_ret
= (XtPointer
) False
;
1558 pixel
= BlackPixelOfScreen (screen
);
1560 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1561 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1563 pixel
= color
.pixel
;
1564 *closure_ret
= (XtPointer
) True
;
1569 Cardinal nparams
= 1;
1571 params
[0] = color_name
;
1572 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1573 "badValue", "cvt_string_to_pixel",
1574 "XtToolkitError", "Invalid color `%s'",
1579 if (to
->addr
!= NULL
)
1581 if (to
->size
< sizeof (Pixel
))
1583 to
->size
= sizeof (Pixel
);
1587 *(Pixel
*) to
->addr
= pixel
;
1591 cvt_string_to_pixel_value
= pixel
;
1592 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1595 to
->size
= sizeof (Pixel
);
1600 /* Free a pixel color which was previously allocated via
1601 cvt_string_to_pixel. This is registered as the destructor
1602 for this type of resource via XtSetTypeConverter.
1604 APP is the application context in which we work.
1606 TO is a pointer to an XrmValue holding the color to free.
1607 CLOSURE is the value we stored in CLOSURE_RET for this color
1608 in cvt_string_to_pixel.
1610 ARGS and NARGS are like for cvt_string_to_pixel. */
1613 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1618 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1620 "Screen and colormap arguments required",
1623 else if (closure
!= NULL
)
1625 /* We did allocate the pixel, so free it. */
1626 Screen
*screen
= *(Screen
**) args
[0].addr
;
1627 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1628 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1629 (Pixel
*) to
->addr
, 1);
1634 #endif /* USE_X_TOOLKIT */
1637 /* Value is an array of XColor structures for the contents of the
1638 color map of display DPY. Set *NCELLS to the size of the array.
1639 Note that this probably shouldn't be called for large color maps,
1640 say a 24-bit TrueColor map. */
1642 static const XColor
*
1643 x_color_cells (Display
*dpy
, int *ncells
)
1645 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1647 if (dpyinfo
->color_cells
== NULL
)
1649 Screen
*screen
= dpyinfo
->screen
;
1650 int ncolor_cells
= XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1653 dpyinfo
->color_cells
= xnmalloc (ncolor_cells
,
1654 sizeof *dpyinfo
->color_cells
);
1655 dpyinfo
->ncolor_cells
= ncolor_cells
;
1657 for (i
= 0; i
< ncolor_cells
; ++i
)
1658 dpyinfo
->color_cells
[i
].pixel
= i
;
1660 XQueryColors (dpy
, dpyinfo
->cmap
,
1661 dpyinfo
->color_cells
, ncolor_cells
);
1664 *ncells
= dpyinfo
->ncolor_cells
;
1665 return dpyinfo
->color_cells
;
1669 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1670 colors in COLORS. Use cached information, if available. */
1673 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1675 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1677 if (dpyinfo
->color_cells
)
1680 for (i
= 0; i
< ncolors
; ++i
)
1682 unsigned long pixel
= colors
[i
].pixel
;
1683 eassert (pixel
< dpyinfo
->ncolor_cells
);
1684 eassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1685 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1689 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1693 /* On frame F, translate pixel color to RGB values for the color in
1694 COLOR. Use cached information, if available. */
1697 x_query_color (struct frame
*f
, XColor
*color
)
1699 x_query_colors (f
, color
, 1);
1703 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1704 exact match can't be allocated, try the nearest color available.
1705 Value is non-zero if successful. Set *COLOR to the color
1709 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1713 rc
= XAllocColor (dpy
, cmap
, color
);
1716 /* If we got to this point, the colormap is full, so we're going
1717 to try to get the next closest color. The algorithm used is
1718 a least-squares matching, which is what X uses for closest
1719 color matching with StaticColor visuals. */
1721 int max_color_delta
= 255;
1722 int max_delta
= 3 * max_color_delta
;
1723 int nearest_delta
= max_delta
+ 1;
1725 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1727 for (nearest
= i
= 0; i
< ncells
; ++i
)
1729 int dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1730 int dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1731 int dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1732 int delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1734 if (delta
< nearest_delta
)
1737 nearest_delta
= delta
;
1741 color
->red
= cells
[nearest
].red
;
1742 color
->green
= cells
[nearest
].green
;
1743 color
->blue
= cells
[nearest
].blue
;
1744 rc
= XAllocColor (dpy
, cmap
, color
);
1748 /* If allocation succeeded, and the allocated pixel color is not
1749 equal to a cached pixel color recorded earlier, there was a
1750 change in the colormap, so clear the color cache. */
1751 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1752 XColor
*cached_color
;
1754 if (dpyinfo
->color_cells
1755 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1756 (cached_color
->red
!= color
->red
1757 || cached_color
->blue
!= color
->blue
1758 || cached_color
->green
!= color
->green
)))
1760 xfree (dpyinfo
->color_cells
);
1761 dpyinfo
->color_cells
= NULL
;
1762 dpyinfo
->ncolor_cells
= 0;
1766 #ifdef DEBUG_X_COLORS
1768 register_color (color
->pixel
);
1769 #endif /* DEBUG_X_COLORS */
1775 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1776 exact match can't be allocated, try the nearest color available.
1777 Value is non-zero if successful. Set *COLOR to the color
1781 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1783 gamma_correct (f
, color
);
1784 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1788 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1789 It's necessary to do this instead of just using PIXEL directly to
1790 get color reference counts right. */
1793 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1797 color
.pixel
= pixel
;
1799 x_query_color (f
, &color
);
1800 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1802 #ifdef DEBUG_X_COLORS
1803 register_color (pixel
);
1809 /* Brightness beyond which a color won't have its highlight brightness
1812 Nominally, highlight colors for `3d' faces are calculated by
1813 brightening an object's color by a constant scale factor, but this
1814 doesn't yield good results for dark colors, so for colors who's
1815 brightness is less than this value (on a scale of 0-65535) have an
1816 use an additional additive factor.
1818 The value here is set so that the default menu-bar/mode-line color
1819 (grey75) will not have its highlights changed at all. */
1820 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1823 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1824 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1825 If this produces the same color as PIXEL, try a color where all RGB
1826 values have DELTA added. Return the allocated color in *PIXEL.
1827 DISPLAY is the X display, CMAP is the colormap to operate on.
1828 Value is non-zero if successful. */
1831 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1837 /* Get RGB color values. */
1838 color
.pixel
= *pixel
;
1839 x_query_color (f
, &color
);
1841 /* Change RGB values by specified FACTOR. Avoid overflow! */
1842 eassert (factor
>= 0);
1843 new.red
= min (0xffff, factor
* color
.red
);
1844 new.green
= min (0xffff, factor
* color
.green
);
1845 new.blue
= min (0xffff, factor
* color
.blue
);
1847 /* Calculate brightness of COLOR. */
1848 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1850 /* We only boost colors that are darker than
1851 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1852 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1853 /* Make an additive adjustment to NEW, because it's dark enough so
1854 that scaling by FACTOR alone isn't enough. */
1856 /* How far below the limit this color is (0 - 1, 1 being darker). */
1857 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1858 /* The additive adjustment. */
1859 int min_delta
= delta
* dimness
* factor
/ 2;
1863 new.red
= max (0, new.red
- min_delta
);
1864 new.green
= max (0, new.green
- min_delta
);
1865 new.blue
= max (0, new.blue
- min_delta
);
1869 new.red
= min (0xffff, min_delta
+ new.red
);
1870 new.green
= min (0xffff, min_delta
+ new.green
);
1871 new.blue
= min (0xffff, min_delta
+ new.blue
);
1875 /* Try to allocate the color. */
1876 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1879 if (new.pixel
== *pixel
)
1881 /* If we end up with the same color as before, try adding
1882 delta to the RGB values. */
1883 x_free_colors (f
, &new.pixel
, 1);
1885 new.red
= min (0xffff, delta
+ color
.red
);
1886 new.green
= min (0xffff, delta
+ color
.green
);
1887 new.blue
= min (0xffff, delta
+ color
.blue
);
1888 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1899 /* Set up the foreground color for drawing relief lines of glyph
1900 string S. RELIEF is a pointer to a struct relief containing the GC
1901 with which lines will be drawn. Use a color that is FACTOR or
1902 DELTA lighter or darker than the relief's background which is found
1903 in S->f->output_data.x->relief_background. If such a color cannot
1904 be allocated, use DEFAULT_PIXEL, instead. */
1907 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1910 struct x_output
*di
= f
->output_data
.x
;
1911 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1912 unsigned long pixel
;
1913 unsigned long background
= di
->relief_background
;
1914 Colormap cmap
= FRAME_X_COLORMAP (f
);
1915 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1916 Display
*dpy
= FRAME_X_DISPLAY (f
);
1918 xgcv
.graphics_exposures
= False
;
1919 xgcv
.line_width
= 1;
1921 /* Free previously allocated color. The color cell will be reused
1922 when it has been freed as many times as it was allocated, so this
1923 doesn't affect faces using the same colors. */
1925 && relief
->allocated_p
)
1927 x_free_colors (f
, &relief
->pixel
, 1);
1928 relief
->allocated_p
= 0;
1931 /* Allocate new color. */
1932 xgcv
.foreground
= default_pixel
;
1934 if (dpyinfo
->n_planes
!= 1
1935 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1937 relief
->allocated_p
= 1;
1938 xgcv
.foreground
= relief
->pixel
= pixel
;
1941 if (relief
->gc
== 0)
1943 xgcv
.stipple
= dpyinfo
->gray
;
1945 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1948 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1952 /* Set up colors for the relief lines around glyph string S. */
1955 x_setup_relief_colors (struct glyph_string
*s
)
1957 struct x_output
*di
= s
->f
->output_data
.x
;
1958 unsigned long color
;
1960 if (s
->face
->use_box_color_for_shadows_p
)
1961 color
= s
->face
->box_color
;
1962 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1964 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1965 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1970 /* Get the background color of the face. */
1971 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1972 color
= xgcv
.background
;
1975 if (di
->white_relief
.gc
== 0
1976 || color
!= di
->relief_background
)
1978 di
->relief_background
= color
;
1979 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1980 WHITE_PIX_DEFAULT (s
->f
));
1981 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1982 BLACK_PIX_DEFAULT (s
->f
));
1987 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1988 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1989 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1990 relief. LEFT_P non-zero means draw a relief on the left side of
1991 the rectangle. RIGHT_P non-zero means draw a relief on the right
1992 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1996 x_draw_relief_rect (struct frame
*f
,
1997 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1998 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1999 XRectangle
*clip_rect
)
2001 Display
*dpy
= FRAME_X_DISPLAY (f
);
2002 Window window
= FRAME_X_WINDOW (f
);
2007 gc
= f
->output_data
.x
->white_relief
.gc
;
2009 gc
= f
->output_data
.x
->black_relief
.gc
;
2010 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2012 /* This code is more complicated than it has to be, because of two
2013 minor hacks to make the boxes look nicer: (i) if width > 1, draw
2014 the outermost line using the black relief. (ii) Omit the four
2021 XDrawLine (dpy
, window
, gc
,
2022 left_x
+ (left_p
? 1 : 0), top_y
,
2023 right_x
+ (right_p
? 0 : 1), top_y
);
2025 for (i
= 1; i
< width
; ++i
)
2026 XDrawLine (dpy
, window
, gc
,
2027 left_x
+ i
* left_p
, top_y
+ i
,
2028 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2035 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
2037 XClearArea (dpy
, window
, left_x
, top_y
, 1, 1, False
);
2038 XClearArea (dpy
, window
, left_x
, bottom_y
, 1, 1, False
);
2040 for (i
= (width
> 1 ? 1 : 0); i
< width
; ++i
)
2041 XDrawLine (dpy
, window
, gc
,
2042 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2045 XSetClipMask (dpy
, gc
, None
);
2047 gc
= f
->output_data
.x
->black_relief
.gc
;
2049 gc
= f
->output_data
.x
->white_relief
.gc
;
2050 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2054 /* Outermost top line. */
2056 XDrawLine (dpy
, window
, gc
,
2057 left_x
+ (left_p
? 1 : 0), top_y
,
2058 right_x
+ (right_p
? 0 : 1), top_y
);
2060 /* Outermost left line. */
2062 XDrawLine (dpy
, window
, gc
, left_x
, top_y
+ 1, left_x
, bottom_y
);
2068 XDrawLine (dpy
, window
, gc
,
2069 left_x
+ (left_p
? 1 : 0), bottom_y
,
2070 right_x
+ (right_p
? 0 : 1), bottom_y
);
2071 for (i
= 1; i
< width
; ++i
)
2072 XDrawLine (dpy
, window
, gc
,
2073 left_x
+ i
* left_p
, bottom_y
- i
,
2074 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2080 XClearArea (dpy
, window
, right_x
, top_y
, 1, 1, False
);
2081 XClearArea (dpy
, window
, right_x
, bottom_y
, 1, 1, False
);
2082 for (i
= 0; i
< width
; ++i
)
2083 XDrawLine (dpy
, window
, gc
,
2084 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2087 XSetClipMask (dpy
, gc
, None
);
2091 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2092 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2093 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2094 left side of the rectangle. RIGHT_P non-zero means draw a line
2095 on the right side of the rectangle. CLIP_RECT is the clipping
2096 rectangle to use when drawing. */
2099 x_draw_box_rect (struct glyph_string
*s
,
2100 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2101 int left_p
, int right_p
, XRectangle
*clip_rect
)
2105 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2106 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2107 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2110 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2111 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2115 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2116 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2119 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2120 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2124 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2125 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2127 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2128 XSetClipMask (s
->display
, s
->gc
, None
);
2132 /* Draw a box around glyph string S. */
2135 x_draw_glyph_string_box (struct glyph_string
*s
)
2137 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2138 int left_p
, right_p
;
2139 struct glyph
*last_glyph
;
2140 XRectangle clip_rect
;
2142 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2143 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2144 : window_box_right (s
->w
, s
->area
));
2146 /* The glyph that may have a right box line. */
2147 last_glyph
= (s
->cmp
|| s
->img
2149 : s
->first_glyph
+ s
->nchars
- 1);
2151 width
= eabs (s
->face
->box_line_width
);
2152 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2154 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2156 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2158 bottom_y
= top_y
+ s
->height
- 1;
2160 left_p
= (s
->first_glyph
->left_box_line_p
2161 || (s
->hl
== DRAW_MOUSE_FACE
2163 || s
->prev
->hl
!= s
->hl
)));
2164 right_p
= (last_glyph
->right_box_line_p
2165 || (s
->hl
== DRAW_MOUSE_FACE
2167 || s
->next
->hl
!= s
->hl
)));
2169 get_glyph_string_clip_rect (s
, &clip_rect
);
2171 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2172 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2173 left_p
, right_p
, &clip_rect
);
2176 x_setup_relief_colors (s
);
2177 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2178 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2183 /* Draw foreground of image glyph string S. */
2186 x_draw_image_foreground (struct glyph_string
*s
)
2189 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2191 /* If first glyph of S has a left box line, start drawing it to the
2192 right of that line. */
2193 if (s
->face
->box
!= FACE_NO_BOX
2194 && s
->first_glyph
->left_box_line_p
2196 x
+= eabs (s
->face
->box_line_width
);
2198 /* If there is a margin around the image, adjust x- and y-position
2200 if (s
->slice
.x
== 0)
2201 x
+= s
->img
->hmargin
;
2202 if (s
->slice
.y
== 0)
2203 y
+= s
->img
->vmargin
;
2209 /* We can't set both a clip mask and use XSetClipRectangles
2210 because the latter also sets a clip mask. We also can't
2211 trust on the shape extension to be available
2212 (XShapeCombineRegion). So, compute the rectangle to draw
2214 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2217 XRectangle clip_rect
, image_rect
, r
;
2219 xgcv
.clip_mask
= s
->img
->mask
;
2220 xgcv
.clip_x_origin
= x
;
2221 xgcv
.clip_y_origin
= y
;
2222 xgcv
.function
= GXcopy
;
2223 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2225 get_glyph_string_clip_rect (s
, &clip_rect
);
2228 image_rect
.width
= s
->slice
.width
;
2229 image_rect
.height
= s
->slice
.height
;
2230 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2231 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2232 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2233 r
.width
, r
.height
, r
.x
, r
.y
);
2237 XRectangle clip_rect
, image_rect
, r
;
2239 get_glyph_string_clip_rect (s
, &clip_rect
);
2242 image_rect
.width
= s
->slice
.width
;
2243 image_rect
.height
= s
->slice
.height
;
2244 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2245 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2246 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2247 r
.width
, r
.height
, r
.x
, r
.y
);
2249 /* When the image has a mask, we can expect that at
2250 least part of a mouse highlight or a block cursor will
2251 be visible. If the image doesn't have a mask, make
2252 a block cursor visible by drawing a rectangle around
2253 the image. I believe it's looking better if we do
2254 nothing here for mouse-face. */
2255 if (s
->hl
== DRAW_CURSOR
)
2257 int relief
= s
->img
->relief
;
2258 if (relief
< 0) relief
= -relief
;
2259 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2260 x
- relief
, y
- relief
,
2261 s
->slice
.width
+ relief
*2 - 1,
2262 s
->slice
.height
+ relief
*2 - 1);
2267 /* Draw a rectangle if image could not be loaded. */
2268 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2269 s
->slice
.width
- 1, s
->slice
.height
- 1);
2273 /* Draw a relief around the image glyph string S. */
2276 x_draw_image_relief (struct glyph_string
*s
)
2278 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2279 int extra_x
, extra_y
;
2282 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2284 /* If first glyph of S has a left box line, start drawing it to the
2285 right of that line. */
2286 if (s
->face
->box
!= FACE_NO_BOX
2287 && s
->first_glyph
->left_box_line_p
2289 x
+= eabs (s
->face
->box_line_width
);
2291 /* If there is a margin around the image, adjust x- and y-position
2293 if (s
->slice
.x
== 0)
2294 x
+= s
->img
->hmargin
;
2295 if (s
->slice
.y
== 0)
2296 y
+= s
->img
->vmargin
;
2298 if (s
->hl
== DRAW_IMAGE_SUNKEN
2299 || s
->hl
== DRAW_IMAGE_RAISED
)
2301 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2302 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2306 thick
= eabs (s
->img
->relief
);
2307 raised_p
= s
->img
->relief
> 0;
2310 extra_x
= extra_y
= 0;
2311 if (s
->face
->id
== TOOL_BAR_FACE_ID
)
2313 if (CONSP (Vtool_bar_button_margin
)
2314 && INTEGERP (XCAR (Vtool_bar_button_margin
))
2315 && INTEGERP (XCDR (Vtool_bar_button_margin
)))
2317 extra_x
= XINT (XCAR (Vtool_bar_button_margin
));
2318 extra_y
= XINT (XCDR (Vtool_bar_button_margin
));
2320 else if (INTEGERP (Vtool_bar_button_margin
))
2321 extra_x
= extra_y
= XINT (Vtool_bar_button_margin
);
2324 x0
= x
- thick
- extra_x
;
2325 y0
= y
- thick
- extra_y
;
2326 x1
= x
+ s
->slice
.width
+ thick
- 1 + extra_x
;
2327 y1
= y
+ s
->slice
.height
+ thick
- 1 + extra_y
;
2329 x_setup_relief_colors (s
);
2330 get_glyph_string_clip_rect (s
, &r
);
2331 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2333 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2335 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2340 /* Draw the foreground of image glyph string S to PIXMAP. */
2343 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2346 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2348 /* If first glyph of S has a left box line, start drawing it to the
2349 right of that line. */
2350 if (s
->face
->box
!= FACE_NO_BOX
2351 && s
->first_glyph
->left_box_line_p
2353 x
+= eabs (s
->face
->box_line_width
);
2355 /* If there is a margin around the image, adjust x- and y-position
2357 if (s
->slice
.x
== 0)
2358 x
+= s
->img
->hmargin
;
2359 if (s
->slice
.y
== 0)
2360 y
+= s
->img
->vmargin
;
2366 /* We can't set both a clip mask and use XSetClipRectangles
2367 because the latter also sets a clip mask. We also can't
2368 trust on the shape extension to be available
2369 (XShapeCombineRegion). So, compute the rectangle to draw
2371 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2375 xgcv
.clip_mask
= s
->img
->mask
;
2376 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2377 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2378 xgcv
.function
= GXcopy
;
2379 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2381 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2382 s
->slice
.x
, s
->slice
.y
,
2383 s
->slice
.width
, s
->slice
.height
, x
, y
);
2384 XSetClipMask (s
->display
, s
->gc
, None
);
2388 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2389 s
->slice
.x
, s
->slice
.y
,
2390 s
->slice
.width
, s
->slice
.height
, x
, y
);
2392 /* When the image has a mask, we can expect that at
2393 least part of a mouse highlight or a block cursor will
2394 be visible. If the image doesn't have a mask, make
2395 a block cursor visible by drawing a rectangle around
2396 the image. I believe it's looking better if we do
2397 nothing here for mouse-face. */
2398 if (s
->hl
== DRAW_CURSOR
)
2400 int r
= s
->img
->relief
;
2402 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2403 s
->slice
.width
+ r
*2 - 1,
2404 s
->slice
.height
+ r
*2 - 1);
2409 /* Draw a rectangle if image could not be loaded. */
2410 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2411 s
->slice
.width
- 1, s
->slice
.height
- 1);
2415 /* Draw part of the background of glyph string S. X, Y, W, and H
2416 give the rectangle to draw. */
2419 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2423 /* Fill background with a stipple pattern. */
2424 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2425 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2426 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2429 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2433 /* Draw image glyph string S.
2436 s->x +-------------------------
2439 | +-------------------------
2442 | | +-------------------
2448 x_draw_image_glyph_string (struct glyph_string
*s
)
2450 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2451 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2453 Pixmap pixmap
= None
;
2456 if (s
->slice
.y
== 0)
2457 height
-= box_line_vwidth
;
2458 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2459 height
-= box_line_vwidth
;
2461 /* Fill background with face under the image. Do it only if row is
2462 taller than image or if image has a clip mask to reduce
2464 s
->stippled_p
= s
->face
->stipple
!= 0;
2465 if (height
> s
->slice
.height
2469 || s
->img
->pixmap
== 0
2470 || s
->width
!= s
->background_width
)
2474 /* Create a pixmap as large as the glyph string. Fill it
2475 with the background color. Copy the image to it, using
2476 its mask. Copy the temporary pixmap to the display. */
2477 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2478 int depth
= DefaultDepthOfScreen (screen
);
2480 /* Create a pixmap as large as the glyph string. */
2481 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2482 s
->background_width
,
2485 /* Don't clip in the following because we're working on the
2487 XSetClipMask (s
->display
, s
->gc
, None
);
2489 /* Fill the pixmap with the background color/stipple. */
2492 /* Fill background with a stipple pattern. */
2493 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2494 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2495 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2496 0, 0, s
->background_width
, s
->height
);
2497 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2498 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2503 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2505 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2506 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2507 0, 0, s
->background_width
, s
->height
);
2508 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2516 if (s
->first_glyph
->left_box_line_p
2518 x
+= box_line_hwidth
;
2520 if (s
->slice
.y
== 0)
2521 y
+= box_line_vwidth
;
2523 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2526 s
->background_filled_p
= 1;
2529 /* Draw the foreground. */
2532 x_draw_image_foreground_1 (s
, pixmap
);
2533 x_set_glyph_string_clipping (s
);
2534 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2535 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2536 XFreePixmap (s
->display
, pixmap
);
2539 x_draw_image_foreground (s
);
2541 /* If we must draw a relief around the image, do it. */
2543 || s
->hl
== DRAW_IMAGE_RAISED
2544 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2545 x_draw_image_relief (s
);
2549 /* Draw stretch glyph string S. */
2552 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2554 eassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2556 if (s
->hl
== DRAW_CURSOR
2557 && !x_stretch_cursor_p
)
2559 /* If `x-stretch-cursor' is nil, don't draw a block cursor as
2560 wide as the stretch glyph. */
2561 int width
, background_width
= s
->background_width
;
2564 if (!s
->row
->reversed_p
)
2566 int left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2570 background_width
-= left_x
- x
;
2576 /* In R2L rows, draw the cursor on the right edge of the
2578 int right_x
= window_box_right_offset (s
->w
, TEXT_AREA
);
2580 if (x
+ background_width
> right_x
)
2581 background_width
-= x
- right_x
;
2582 x
+= background_width
;
2584 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2585 if (s
->row
->reversed_p
)
2589 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2591 /* Clear rest using the GC of the original non-cursor face. */
2592 if (width
< background_width
)
2595 int w
= background_width
- width
, h
= s
->height
;
2599 if (!s
->row
->reversed_p
)
2603 if (s
->row
->mouse_face_p
2604 && cursor_in_mouse_face_p (s
->w
))
2606 x_set_mouse_face_gc (s
);
2612 get_glyph_string_clip_rect (s
, &r
);
2613 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2615 if (s
->face
->stipple
)
2617 /* Fill background with a stipple pattern. */
2618 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2619 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2620 XSetFillStyle (s
->display
, gc
, FillSolid
);
2625 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2626 XSetForeground (s
->display
, gc
, xgcv
.background
);
2627 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2628 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2632 else if (!s
->background_filled_p
)
2634 int background_width
= s
->background_width
;
2635 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2637 /* Don't draw into left margin, fringe or scrollbar area
2638 except for header line and mode line. */
2639 if (x
< left_x
&& !s
->row
->mode_line_p
)
2641 background_width
-= left_x
- x
;
2644 if (background_width
> 0)
2645 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2648 s
->background_filled_p
= 1;
2652 Draw a wavy line under S. The wave fills wave_height pixels from y0.
2658 wave_height = 3 | * * * *
2663 x_draw_underwave (struct glyph_string
*s
)
2665 int wave_height
= 2, wave_length
= 3;
2666 int dx
, dy
, x0
, y0
, width
, x1
, y1
, x2
, y2
, odd
, xmax
;
2667 XRectangle wave_clip
, string_clip
, final_clip
;
2670 dy
= wave_height
- 1;
2676 /* Find and set clipping rectangle */
2678 wave_clip
= (XRectangle
){ x0
, y0
, width
, wave_height
};
2679 get_glyph_string_clip_rect (s
, &string_clip
);
2681 if (!x_intersect_rectangles (&wave_clip
, &string_clip
, &final_clip
))
2684 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, &final_clip
, 1, Unsorted
);
2686 /* Draw the waves */
2688 x1
= x0
- (x0
% dx
);
2698 if (INT_MAX
- dx
< xmax
)
2703 XDrawLine (s
->display
, s
->window
, s
->gc
, x1
, y1
, x2
, y2
);
2705 x2
+= dx
, y2
= y0
+ odd
*dy
;
2709 /* Restore previous clipping rectangle(s) */
2710 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, s
->clip
, s
->num_clips
, Unsorted
);
2714 /* Draw glyph string S. */
2717 x_draw_glyph_string (struct glyph_string
*s
)
2719 int relief_drawn_p
= 0;
2721 /* If S draws into the background of its successors, draw the
2722 background of the successors first so that S can draw into it.
2723 This makes S->next use XDrawString instead of XDrawImageString. */
2724 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2727 struct glyph_string
*next
;
2729 for (width
= 0, next
= s
->next
;
2730 next
&& width
< s
->right_overhang
;
2731 width
+= next
->width
, next
= next
->next
)
2732 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2734 x_set_glyph_string_gc (next
);
2735 x_set_glyph_string_clipping (next
);
2736 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2737 x_draw_stretch_glyph_string (next
);
2739 x_draw_glyph_string_background (next
, 1);
2740 next
->num_clips
= 0;
2744 /* Set up S->gc, set clipping and draw S. */
2745 x_set_glyph_string_gc (s
);
2747 /* Draw relief (if any) in advance for char/composition so that the
2748 glyph string can be drawn over it. */
2749 if (!s
->for_overlaps
2750 && s
->face
->box
!= FACE_NO_BOX
2751 && (s
->first_glyph
->type
== CHAR_GLYPH
2752 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2755 x_set_glyph_string_clipping (s
);
2756 x_draw_glyph_string_background (s
, 1);
2757 x_draw_glyph_string_box (s
);
2758 x_set_glyph_string_clipping (s
);
2761 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2763 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2764 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2765 /* We must clip just this glyph. left_overhang part has already
2766 drawn when s->prev was drawn, and right_overhang part will be
2767 drawn later when s->next is drawn. */
2768 x_set_glyph_string_clipping_exactly (s
, s
);
2770 x_set_glyph_string_clipping (s
);
2772 switch (s
->first_glyph
->type
)
2775 x_draw_image_glyph_string (s
);
2779 x_draw_stretch_glyph_string (s
);
2783 if (s
->for_overlaps
)
2784 s
->background_filled_p
= 1;
2786 x_draw_glyph_string_background (s
, 0);
2787 x_draw_glyph_string_foreground (s
);
2790 case COMPOSITE_GLYPH
:
2791 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2792 && ! s
->first_glyph
->u
.cmp
.automatic
))
2793 s
->background_filled_p
= 1;
2795 x_draw_glyph_string_background (s
, 1);
2796 x_draw_composite_glyph_string_foreground (s
);
2799 case GLYPHLESS_GLYPH
:
2800 if (s
->for_overlaps
)
2801 s
->background_filled_p
= 1;
2803 x_draw_glyph_string_background (s
, 1);
2804 x_draw_glyphless_glyph_string_foreground (s
);
2811 if (!s
->for_overlaps
)
2813 /* Draw underline. */
2814 if (s
->face
->underline_p
)
2816 if (s
->face
->underline_type
== FACE_UNDER_WAVE
)
2818 if (s
->face
->underline_defaulted_p
)
2819 x_draw_underwave (s
);
2823 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2824 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2825 x_draw_underwave (s
);
2826 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2829 else if (s
->face
->underline_type
== FACE_UNDER_LINE
)
2831 unsigned long thickness
, position
;
2834 if (s
->prev
&& s
->prev
->face
->underline_p
)
2836 /* We use the same underline style as the previous one. */
2837 thickness
= s
->prev
->underline_thickness
;
2838 position
= s
->prev
->underline_position
;
2842 /* Get the underline thickness. Default is 1 pixel. */
2843 if (s
->font
&& s
->font
->underline_thickness
> 0)
2844 thickness
= s
->font
->underline_thickness
;
2847 if (x_underline_at_descent_line
)
2848 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2851 /* Get the underline position. This is the recommended
2852 vertical offset in pixels from the baseline to the top of
2853 the underline. This is a signed value according to the
2854 specs, and its default is
2856 ROUND ((maximum descent) / 2), with
2857 ROUND(x) = floor (x + 0.5) */
2859 if (x_use_underline_position_properties
2860 && s
->font
&& s
->font
->underline_position
>= 0)
2861 position
= s
->font
->underline_position
;
2863 position
= (s
->font
->descent
+ 1) / 2;
2865 position
= underline_minimum_offset
;
2867 position
= max (position
, underline_minimum_offset
);
2869 /* Check the sanity of thickness and position. We should
2870 avoid drawing underline out of the current line area. */
2871 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2872 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2873 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2874 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2875 s
->underline_thickness
= thickness
;
2876 s
->underline_position
= position
;
2877 y
= s
->ybase
+ position
;
2878 if (s
->face
->underline_defaulted_p
)
2879 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2880 s
->x
, y
, s
->width
, thickness
);
2884 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2885 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2886 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2887 s
->x
, y
, s
->width
, thickness
);
2888 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2892 /* Draw overline. */
2893 if (s
->face
->overline_p
)
2895 unsigned long dy
= 0, h
= 1;
2897 if (s
->face
->overline_color_defaulted_p
)
2898 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2903 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2904 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2905 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2907 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2911 /* Draw strike-through. */
2912 if (s
->face
->strike_through_p
)
2914 unsigned long h
= 1;
2915 unsigned long dy
= (s
->height
- h
) / 2;
2917 if (s
->face
->strike_through_color_defaulted_p
)
2918 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2923 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2924 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2925 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2927 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2931 /* Draw relief if not yet drawn. */
2932 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2933 x_draw_glyph_string_box (s
);
2937 struct glyph_string
*prev
;
2939 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2940 if (prev
->hl
!= s
->hl
2941 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2943 /* As prev was drawn while clipped to its own area, we
2944 must draw the right_overhang part using s->hl now. */
2945 enum draw_glyphs_face save
= prev
->hl
;
2948 x_set_glyph_string_gc (prev
);
2949 x_set_glyph_string_clipping_exactly (s
, prev
);
2950 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2951 x_draw_glyph_string_foreground (prev
);
2953 x_draw_composite_glyph_string_foreground (prev
);
2954 XSetClipMask (prev
->display
, prev
->gc
, None
);
2956 prev
->num_clips
= 0;
2962 struct glyph_string
*next
;
2964 for (next
= s
->next
; next
; next
= next
->next
)
2965 if (next
->hl
!= s
->hl
2966 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2968 /* As next will be drawn while clipped to its own area,
2969 we must draw the left_overhang part using s->hl now. */
2970 enum draw_glyphs_face save
= next
->hl
;
2973 x_set_glyph_string_gc (next
);
2974 x_set_glyph_string_clipping_exactly (s
, next
);
2975 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2976 x_draw_glyph_string_foreground (next
);
2978 x_draw_composite_glyph_string_foreground (next
);
2979 XSetClipMask (next
->display
, next
->gc
, None
);
2981 next
->num_clips
= 0;
2986 /* Reset clipping. */
2987 XSetClipMask (s
->display
, s
->gc
, None
);
2991 /* Shift display to make room for inserted glyphs. */
2994 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2996 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2997 f
->output_data
.x
->normal_gc
,
2998 x
, y
, width
, height
,
3002 /* Delete N glyphs at the nominal cursor position. Not implemented
3006 x_delete_glyphs (struct frame
*f
, register int n
)
3012 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
3013 If they are <= 0, this is probably an error. */
3016 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
, int exposures
)
3018 eassert (width
> 0 && height
> 0);
3019 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
3023 /* Clear an entire frame. */
3026 x_clear_frame (struct frame
*f
)
3028 /* Clearing the frame will erase any cursor, so mark them all as no
3030 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
3031 output_cursor
.hpos
= output_cursor
.vpos
= 0;
3032 output_cursor
.x
= -1;
3034 /* We don't set the output cursor here because there will always
3035 follow an explicit cursor_to. */
3038 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
3040 /* We have to clear the scroll bars. If we have changed colors or
3041 something like that, then they should be notified. */
3042 x_scroll_bar_clear (f
);
3044 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3045 /* Make sure scroll bars are redrawn. As they aren't redrawn by
3046 redisplay, do it here. */
3047 if (FRAME_GTK_WIDGET (f
))
3048 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
3051 XFlush (FRAME_X_DISPLAY (f
));
3058 /* Invert the middle quarter of the frame for .15 sec. */
3061 XTflash (struct frame
*f
)
3067 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
3068 when the scroll bars and the edit widget share the same X window. */
3069 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
3071 cairo_t
*cr
= gdk_cairo_create (window
);
3072 cairo_set_source_rgb (cr
, 1, 1, 1);
3073 cairo_set_operator (cr
, CAIRO_OPERATOR_DIFFERENCE
);
3074 #define XFillRectangle(d, win, gc, x, y, w, h) \
3076 cairo_rectangle (cr, x, y, w, h); \
3080 #else /* ! HAVE_GTK3 */
3083 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
3084 ^ FRAME_BACKGROUND_PIXEL (f
));
3085 vals
.function
= GDK_XOR
;
3086 gc
= gdk_gc_new_with_values (window
,
3087 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
3088 #define XFillRectangle(d, win, gc, x, y, w, h) \
3089 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
3090 #endif /* ! HAVE_GTK3 */
3091 #else /* ! USE_GTK */
3094 /* Create a GC that will use the GXxor function to flip foreground
3095 pixels into background pixels. */
3099 values
.function
= GXxor
;
3100 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3101 ^ FRAME_BACKGROUND_PIXEL (f
));
3103 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3104 GCFunction
| GCForeground
, &values
);
3108 /* Get the height not including a menu bar widget. */
3109 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3110 /* Height of each line to flash. */
3111 int flash_height
= FRAME_LINE_HEIGHT (f
);
3112 /* These will be the left and right margins of the rectangles. */
3113 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3114 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3118 /* Don't flash the area between a scroll bar and the frame
3119 edge it is next to. */
3120 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3122 case vertical_scroll_bar_left
:
3123 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3126 case vertical_scroll_bar_right
:
3127 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3134 width
= flash_right
- flash_left
;
3136 /* If window is tall, flash top and bottom line. */
3137 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3139 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3141 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3142 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3143 width
, flash_height
);
3144 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3146 (height
- flash_height
3147 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3148 width
, flash_height
);
3152 /* If it is short, flash it all. */
3153 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3154 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3155 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3160 EMACS_TIME delay
= make_emacs_time (0, 150 * 1000 * 1000);
3161 EMACS_TIME wakeup
= add_emacs_time (current_emacs_time (), delay
);
3163 /* Keep waiting until past the time wakeup or any input gets
3165 while (! detect_input_pending ())
3167 EMACS_TIME current
= current_emacs_time ();
3170 /* Break if result would not be positive. */
3171 if (EMACS_TIME_LE (wakeup
, current
))
3174 /* How long `select' should wait. */
3175 timeout
= make_emacs_time (0, 10 * 1000 * 1000);
3177 /* Try to wait that long--but we might wake up sooner. */
3178 pselect (0, NULL
, NULL
, NULL
, &timeout
, NULL
);
3182 /* If window is tall, flash top and bottom line. */
3183 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3185 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3187 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3188 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3189 width
, flash_height
);
3190 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3192 (height
- flash_height
3193 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3194 width
, flash_height
);
3197 /* If it is short, flash it all. */
3198 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3199 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3200 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3206 g_object_unref (G_OBJECT (gc
));
3208 #undef XFillRectangle
3210 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3221 XTtoggle_invisible_pointer (FRAME_PTR f
, int invisible
)
3226 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3227 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3228 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
);
3231 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3232 f
->output_data
.x
->current_cursor
);
3233 f
->pointer_invisible
= invisible
;
3238 /* Make audible bell. */
3241 XTring_bell (struct frame
*f
)
3243 if (FRAME_X_DISPLAY (f
))
3250 XBell (FRAME_X_DISPLAY (f
), 0);
3251 XFlush (FRAME_X_DISPLAY (f
));
3258 /* Specify how many text lines, from the top of the window,
3259 should be affected by insert-lines and delete-lines operations.
3260 This, and those operations, are used only within an update
3261 that is bounded by calls to x_update_begin and x_update_end. */
3264 XTset_terminal_window (struct frame
*f
, int n
)
3266 /* This function intentionally left blank. */
3271 /***********************************************************************
3273 ***********************************************************************/
3275 /* Perform an insert-lines or delete-lines operation, inserting N
3276 lines or deleting -N lines at vertical position VPOS. */
3279 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3285 /* Scroll part of the display as described by RUN. */
3288 x_scroll_run (struct window
*w
, struct run
*run
)
3290 struct frame
*f
= XFRAME (w
->frame
);
3291 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3293 /* Get frame-relative bounding box of the text display area of W,
3294 without mode lines. Include in this box the left and right
3296 window_box (w
, -1, &x
, &y
, &width
, &height
);
3298 #ifdef USE_TOOLKIT_SCROLL_BARS
3299 /* If the fringe is adjacent to the left (right) scroll bar of a
3300 leftmost (rightmost, respectively) window, then extend its
3301 background to the gap between the fringe and the bar. */
3302 if ((WINDOW_LEFTMOST_P (w
)
3303 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
3304 || (WINDOW_RIGHTMOST_P (w
)
3305 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
3307 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
3311 int bar_area_x
= WINDOW_SCROLL_BAR_AREA_X (w
);
3312 int bar_area_width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
3313 * FRAME_COLUMN_WIDTH (f
));
3315 if (bar_area_x
+ bar_area_width
== x
)
3317 x
= bar_area_x
+ sb_width
;
3318 width
+= bar_area_width
- sb_width
;
3320 else if (x
+ width
== bar_area_x
)
3321 width
+= bar_area_width
- sb_width
;
3326 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3327 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3328 bottom_y
= y
+ height
;
3332 /* Scrolling up. Make sure we don't copy part of the mode
3333 line at the bottom. */
3334 if (from_y
+ run
->height
> bottom_y
)
3335 height
= bottom_y
- from_y
;
3337 height
= run
->height
;
3341 /* Scrolling down. Make sure we don't copy over the mode line.
3343 if (to_y
+ run
->height
> bottom_y
)
3344 height
= bottom_y
- to_y
;
3346 height
= run
->height
;
3351 /* Cursor off. Will be switched on again in x_update_window_end. */
3355 XCopyArea (FRAME_X_DISPLAY (f
),
3356 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3357 f
->output_data
.x
->normal_gc
,
3367 /***********************************************************************
3369 ***********************************************************************/
3373 frame_highlight (struct frame
*f
)
3375 /* We used to only do this if Vx_no_window_manager was non-nil, but
3376 the ICCCM (section 4.1.6) says that the window's border pixmap
3377 and border pixel are window attributes which are "private to the
3378 client", so we can always change it to whatever we want. */
3380 /* I recently started to get errors in this XSetWindowBorder, depending on
3381 the window-manager in use, tho something more is at play since I've been
3382 using that same window-manager binary for ever. Let's not crash just
3383 because of this (bug#9310). */
3384 x_catch_errors (FRAME_X_DISPLAY (f
));
3385 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3386 f
->output_data
.x
->border_pixel
);
3387 x_uncatch_errors ();
3389 x_update_cursor (f
, 1);
3390 x_set_frame_alpha (f
);
3394 frame_unhighlight (struct frame
*f
)
3396 /* We used to only do this if Vx_no_window_manager was non-nil, but
3397 the ICCCM (section 4.1.6) says that the window's border pixmap
3398 and border pixel are window attributes which are "private to the
3399 client", so we can always change it to whatever we want. */
3401 /* Same as above for XSetWindowBorder (bug#9310). */
3402 x_catch_errors (FRAME_X_DISPLAY (f
));
3403 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3404 f
->output_data
.x
->border_tile
);
3405 x_uncatch_errors ();
3407 x_update_cursor (f
, 1);
3408 x_set_frame_alpha (f
);
3411 /* The focus has changed. Update the frames as necessary to reflect
3412 the new situation. Note that we can't change the selected frame
3413 here, because the Lisp code we are interrupting might become confused.
3414 Each event gets marked with the frame in which it occurred, so the
3415 Lisp code can tell when the switch took place by examining the events. */
3418 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3420 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3422 if (frame
!= dpyinfo
->x_focus_frame
)
3424 /* Set this before calling other routines, so that they see
3425 the correct value of x_focus_frame. */
3426 dpyinfo
->x_focus_frame
= frame
;
3428 if (old_focus
&& old_focus
->auto_lower
)
3429 x_lower_frame (old_focus
);
3431 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3432 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3434 pending_autoraise_frame
= 0;
3437 x_frame_rehighlight (dpyinfo
);
3440 /* Handle FocusIn and FocusOut state changes for FRAME.
3441 If FRAME has focus and there exists more than one frame, puts
3442 a FOCUS_IN_EVENT into *BUFP. */
3445 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3447 if (type
== FocusIn
)
3449 if (dpyinfo
->x_focus_event_frame
!= frame
)
3451 x_new_focus_frame (dpyinfo
, frame
);
3452 dpyinfo
->x_focus_event_frame
= frame
;
3454 /* Don't stop displaying the initial startup message
3455 for a switch-frame event we don't need. */
3456 if (NILP (Vterminal_frame
)
3457 && CONSP (Vframe_list
)
3458 && !NILP (XCDR (Vframe_list
)))
3460 bufp
->kind
= FOCUS_IN_EVENT
;
3461 XSETFRAME (bufp
->frame_or_window
, frame
);
3465 frame
->output_data
.x
->focus_state
|= state
;
3468 if (FRAME_XIC (frame
))
3469 XSetICFocus (FRAME_XIC (frame
));
3472 else if (type
== FocusOut
)
3474 frame
->output_data
.x
->focus_state
&= ~state
;
3476 if (dpyinfo
->x_focus_event_frame
== frame
)
3478 dpyinfo
->x_focus_event_frame
= 0;
3479 x_new_focus_frame (dpyinfo
, 0);
3483 if (FRAME_XIC (frame
))
3484 XUnsetICFocus (FRAME_XIC (frame
));
3486 if (frame
->pointer_invisible
)
3487 XTtoggle_invisible_pointer (frame
, 0);
3491 /* The focus may have changed. Figure out if it is a real focus change,
3492 by checking both FocusIn/Out and Enter/LeaveNotify events.
3494 Returns FOCUS_IN_EVENT event in *BUFP. */
3497 x_detect_focus_change (struct x_display_info
*dpyinfo
, XEvent
*event
, struct input_event
*bufp
)
3499 struct frame
*frame
;
3501 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3505 switch (event
->type
)
3510 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3512 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3514 if (event
->xcrossing
.detail
!= NotifyInferior
3515 && event
->xcrossing
.focus
3516 && ! (focus_state
& FOCUS_EXPLICIT
))
3517 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3519 dpyinfo
, frame
, bufp
);
3525 x_focus_changed (event
->type
,
3526 (event
->xfocus
.detail
== NotifyPointer
?
3527 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3528 dpyinfo
, frame
, bufp
);
3532 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3534 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3535 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3536 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3543 #if defined HAVE_MENUS && !defined USE_X_TOOLKIT && !defined USE_GTK
3544 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3547 x_mouse_leave (struct x_display_info
*dpyinfo
)
3549 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3553 /* The focus has changed, or we have redirected a frame's focus to
3554 another frame (this happens when a frame uses a surrogate
3555 mini-buffer frame). Shift the highlight as appropriate.
3557 The FRAME argument doesn't necessarily have anything to do with which
3558 frame is being highlighted or un-highlighted; we only use it to find
3559 the appropriate X display info. */
3562 XTframe_rehighlight (struct frame
*frame
)
3564 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3568 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3570 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3572 if (dpyinfo
->x_focus_frame
)
3574 dpyinfo
->x_highlight_frame
3575 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3576 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3577 : dpyinfo
->x_focus_frame
);
3578 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3580 fset_focus_frame (dpyinfo
->x_focus_frame
, Qnil
);
3581 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3585 dpyinfo
->x_highlight_frame
= 0;
3587 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3590 frame_unhighlight (old_highlight
);
3591 if (dpyinfo
->x_highlight_frame
)
3592 frame_highlight (dpyinfo
->x_highlight_frame
);
3598 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3600 /* Initialize mode_switch_bit and modifier_meaning. */
3602 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3604 int min_code
, max_code
;
3607 XModifierKeymap
*mods
;
3609 dpyinfo
->meta_mod_mask
= 0;
3610 dpyinfo
->shift_lock_mask
= 0;
3611 dpyinfo
->alt_mod_mask
= 0;
3612 dpyinfo
->super_mod_mask
= 0;
3613 dpyinfo
->hyper_mod_mask
= 0;
3615 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3617 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3618 min_code
, max_code
- min_code
+ 1,
3620 mods
= XGetModifierMapping (dpyinfo
->display
);
3622 /* Scan the modifier table to see which modifier bits the Meta and
3623 Alt keysyms are on. */
3625 int row
, col
; /* The row and column in the modifier table. */
3626 int found_alt_or_meta
;
3628 for (row
= 3; row
< 8; row
++)
3630 found_alt_or_meta
= 0;
3631 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3633 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3635 /* Zeroes are used for filler. Skip them. */
3639 /* Are any of this keycode's keysyms a meta key? */
3643 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3645 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3651 found_alt_or_meta
= 1;
3652 dpyinfo
->meta_mod_mask
|= (1 << row
);
3657 found_alt_or_meta
= 1;
3658 dpyinfo
->alt_mod_mask
|= (1 << row
);
3663 if (!found_alt_or_meta
)
3664 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3665 code_col
= syms_per_code
;
3666 col
= mods
->max_keypermod
;
3671 if (!found_alt_or_meta
)
3672 dpyinfo
->super_mod_mask
|= (1 << row
);
3673 code_col
= syms_per_code
;
3674 col
= mods
->max_keypermod
;
3678 /* Ignore this if it's not on the lock modifier. */
3679 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3680 dpyinfo
->shift_lock_mask
= LockMask
;
3681 code_col
= syms_per_code
;
3682 col
= mods
->max_keypermod
;
3691 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3692 if (! dpyinfo
->meta_mod_mask
)
3694 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3695 dpyinfo
->alt_mod_mask
= 0;
3698 /* If some keys are both alt and meta,
3699 make them just meta, not alt. */
3700 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3702 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3706 XFreeModifiermap (mods
);
3709 /* Convert between the modifier bits X uses and the modifier bits
3713 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, int state
)
3715 int mod_meta
= meta_modifier
;
3716 int mod_alt
= alt_modifier
;
3717 int mod_hyper
= hyper_modifier
;
3718 int mod_super
= super_modifier
;
3721 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3722 if (INTEGERP (tem
)) mod_alt
= XINT (tem
) & INT_MAX
;
3723 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3724 if (INTEGERP (tem
)) mod_meta
= XINT (tem
) & INT_MAX
;
3725 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3726 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
) & INT_MAX
;
3727 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3728 if (INTEGERP (tem
)) mod_super
= XINT (tem
) & INT_MAX
;
3730 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3731 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3732 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3733 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3734 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3735 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3739 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, EMACS_INT state
)
3741 EMACS_INT mod_meta
= meta_modifier
;
3742 EMACS_INT mod_alt
= alt_modifier
;
3743 EMACS_INT mod_hyper
= hyper_modifier
;
3744 EMACS_INT mod_super
= super_modifier
;
3748 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3749 if (INTEGERP (tem
)) mod_alt
= XINT (tem
);
3750 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3751 if (INTEGERP (tem
)) mod_meta
= XINT (tem
);
3752 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3753 if (INTEGERP (tem
)) mod_hyper
= XINT (tem
);
3754 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3755 if (INTEGERP (tem
)) mod_super
= XINT (tem
);
3758 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3759 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3760 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3761 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3762 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3763 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3766 /* Convert a keysym to its name. */
3769 x_get_keysym_name (int keysym
)
3774 value
= XKeysymToString (keysym
);
3782 /* Mouse clicks and mouse movement. Rah. */
3784 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3786 If the event is a button press, then note that we have grabbed
3790 construct_mouse_click (struct input_event
*result
, XButtonEvent
*event
, struct frame
*f
)
3792 /* Make the event type NO_EVENT; we'll change that when we decide
3794 result
->kind
= MOUSE_CLICK_EVENT
;
3795 result
->code
= event
->button
- Button1
;
3796 result
->timestamp
= event
->time
;
3797 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3799 | (event
->type
== ButtonRelease
3803 XSETINT (result
->x
, event
->x
);
3804 XSETINT (result
->y
, event
->y
);
3805 XSETFRAME (result
->frame_or_window
, f
);
3811 /* Function to report a mouse movement to the mainstream Emacs code.
3812 The input handler calls this.
3814 We have received a mouse movement event, which is given in *event.
3815 If the mouse is over a different glyph than it was last time, tell
3816 the mainstream emacs code by setting mouse_moved. If not, ask for
3817 another motion event, so we can check again the next time it moves. */
3819 static XMotionEvent last_mouse_motion_event
;
3820 static Lisp_Object last_mouse_motion_frame
;
3823 note_mouse_movement (FRAME_PTR frame
, XMotionEvent
*event
)
3825 last_mouse_movement_time
= event
->time
;
3826 last_mouse_motion_event
= *event
;
3827 XSETFRAME (last_mouse_motion_frame
, frame
);
3829 if (!FRAME_X_OUTPUT (frame
))
3832 if (event
->window
!= FRAME_X_WINDOW (frame
))
3834 frame
->mouse_moved
= 1;
3835 last_mouse_scroll_bar
= Qnil
;
3836 note_mouse_highlight (frame
, -1, -1);
3837 last_mouse_glyph_frame
= 0;
3842 /* Has the mouse moved off the glyph it was on at the last sighting? */
3843 if (frame
!= last_mouse_glyph_frame
3844 || event
->x
< last_mouse_glyph
.x
3845 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3846 || event
->y
< last_mouse_glyph
.y
3847 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3849 frame
->mouse_moved
= 1;
3850 last_mouse_scroll_bar
= Qnil
;
3851 note_mouse_highlight (frame
, event
->x
, event
->y
);
3852 /* Remember which glyph we're now on. */
3853 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3854 last_mouse_glyph_frame
= frame
;
3862 /************************************************************************
3864 ************************************************************************/
3867 redo_mouse_highlight (void)
3869 if (!NILP (last_mouse_motion_frame
)
3870 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3871 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3872 last_mouse_motion_event
.x
,
3873 last_mouse_motion_event
.y
);
3878 /* Return the current position of the mouse.
3879 *FP should be a frame which indicates which display to ask about.
3881 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3882 and *PART to the frame, window, and scroll bar part that the mouse
3883 is over. Set *X and *Y to the portion and whole of the mouse's
3884 position on the scroll bar.
3886 If the mouse movement started elsewhere, set *FP to the frame the
3887 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3890 Set *TIMESTAMP to the server time-stamp for the time at which the mouse
3891 was at this position.
3893 Don't store anything if we don't have a valid set of values to report.
3895 This clears the mouse_moved flag, so we can wait for the next mouse
3899 XTmouse_position (FRAME_PTR
*fp
, int insist
, Lisp_Object
*bar_window
,
3900 enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
,
3907 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3908 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, timestamp
);
3914 Window dummy_window
;
3917 Lisp_Object frame
, tail
;
3919 /* Clear the mouse-moved flag for every frame on this display. */
3920 FOR_EACH_FRAME (tail
, frame
)
3921 if (FRAME_X_P (XFRAME (frame
))
3922 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3923 XFRAME (frame
)->mouse_moved
= 0;
3925 last_mouse_scroll_bar
= Qnil
;
3927 /* Figure out which root window we're on. */
3928 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3929 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3931 /* The root window which contains the pointer. */
3934 /* Trash which we can't trust if the pointer is on
3935 a different screen. */
3938 /* The position on that root window. */
3941 /* More trash we can't trust. */
3944 /* Modifier keys and pointer buttons, about which
3946 (unsigned int *) &dummy
);
3948 /* Now we have a position on the root; find the innermost window
3949 containing the pointer. */
3953 int parent_x
= 0, parent_y
= 0;
3957 /* XTranslateCoordinates can get errors if the window
3958 structure is changing at the same time this function
3959 is running. So at least we must not crash from them. */
3961 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3963 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3964 && FRAME_LIVE_P (last_mouse_frame
))
3966 /* If mouse was grabbed on a frame, give coords for that frame
3967 even if the mouse is now outside it. */
3968 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3970 /* From-window, to-window. */
3971 root
, FRAME_X_WINDOW (last_mouse_frame
),
3973 /* From-position, to-position. */
3974 root_x
, root_y
, &win_x
, &win_y
,
3978 f1
= last_mouse_frame
;
3984 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3986 /* From-window, to-window. */
3989 /* From-position, to-position. */
3990 root_x
, root_y
, &win_x
, &win_y
,
3995 if (child
== None
|| child
== win
)
3998 /* We don't wan't to know the innermost window. We
3999 want the edit window. For non-Gtk+ the innermost
4000 window is the edit window. For Gtk+ it might not
4001 be. It might be the tool bar for example. */
4002 if (x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
))
4010 /* Now we know that:
4011 win is the innermost window containing the pointer
4012 (XTC says it has no child containing the pointer),
4013 win_x and win_y are the pointer's position in it
4014 (XTC did this the last time through), and
4015 parent_x and parent_y are the pointer's position in win's parent.
4016 (They are what win_x and win_y were when win was child.
4017 If win is the root window, it has no parent, and
4018 parent_{x,y} are invalid, but that's okay, because we'll
4019 never use them in that case.) */
4022 /* We don't wan't to know the innermost window. We
4023 want the edit window. */
4024 f1
= x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
4026 /* Is win one of our frames? */
4027 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
4030 #ifdef USE_X_TOOLKIT
4031 /* If we end up with the menu bar window, say it's not
4034 && f1
->output_data
.x
->menubar_widget
4035 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
4037 #endif /* USE_X_TOOLKIT */
4040 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
4043 x_uncatch_errors ();
4045 /* If not, is it one of our scroll bars? */
4048 struct scroll_bar
*bar
;
4050 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
4054 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4060 if (f1
== 0 && insist
> 0)
4061 f1
= SELECTED_FRAME ();
4065 /* Ok, we found a frame. Store all the values.
4066 last_mouse_glyph is a rectangle used to reduce the
4067 generation of mouse events. To not miss any motion
4068 events, we must divide the frame into rectangles of the
4069 size of the smallest character that could be displayed
4070 on it, i.e. into the same rectangles that matrices on
4071 the frame are divided into. */
4073 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
4074 last_mouse_glyph_frame
= f1
;
4079 XSETINT (*x
, win_x
);
4080 XSETINT (*y
, win_y
);
4081 *timestamp
= last_mouse_movement_time
;
4091 /***********************************************************************
4093 ***********************************************************************/
4095 /* Scroll bar support. */
4097 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4099 This can be called in GC, so we have to make sure to strip off mark
4102 static struct scroll_bar
*
4103 x_window_to_scroll_bar (Display
*display
, Window window_id
)
4107 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4108 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4109 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4111 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4113 Lisp_Object frame
, bar
, condemned
;
4115 frame
= XCAR (tail
);
4116 /* All elements of Vframe_list should be frames. */
4117 if (! FRAMEP (frame
))
4120 if (! FRAME_X_P (XFRAME (frame
)))
4123 /* Scan this frame's scroll bar list for a scroll bar with the
4125 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4126 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4127 /* This trick allows us to search both the ordinary and
4128 condemned scroll bar lists with one loop. */
4129 ! NILP (bar
) || (bar
= condemned
,
4132 bar
= XSCROLL_BAR (bar
)->next
)
4133 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4134 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4135 return XSCROLL_BAR (bar
);
4142 #if defined USE_LUCID
4144 /* Return the Lucid menu bar WINDOW is part of. Return null
4145 if WINDOW is not part of a menu bar. */
4148 x_window_to_menu_bar (Window window
)
4152 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4154 if (FRAME_X_P (XFRAME (XCAR (tail
))))
4156 Lisp_Object frame
= XCAR (tail
);
4157 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4159 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4167 #endif /* USE_LUCID */
4170 /************************************************************************
4172 ************************************************************************/
4174 #ifdef USE_TOOLKIT_SCROLL_BARS
4176 static void x_scroll_bar_to_input_event (XEvent
*, struct input_event
*);
4177 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
4178 static void x_create_toolkit_scroll_bar (struct frame
*,
4179 struct scroll_bar
*);
4180 static void x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*,
4184 /* Lisp window being scrolled. Set when starting to interact with
4185 a toolkit scroll bar, reset to nil when ending the interaction. */
4187 static Lisp_Object window_being_scrolled
;
4189 /* Last scroll bar part sent in xm_scroll_callback. */
4191 static int last_scroll_bar_part
;
4193 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4194 that movements of 1/20 of the screen size are mapped to up/down. */
4197 /* Id of action hook installed for scroll bars. */
4199 static XtActionHookId action_hook_id
;
4201 static Boolean xaw3d_arrow_scroll
;
4203 /* Whether the drag scrolling maintains the mouse at the top of the
4204 thumb. If not, resizing the thumb needs to be done more carefully
4205 to avoid jerkiness. */
4207 static Boolean xaw3d_pick_top
;
4209 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4210 bars are used.. The hook is responsible for detecting when
4211 the user ends an interaction with the scroll bar, and generates
4212 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4215 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4216 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4219 const char *end_action
;
4222 scroll_bar_p
= XmIsScrollBar (widget
);
4223 end_action
= "Release";
4224 #else /* !USE_MOTIF i.e. use Xaw */
4225 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4226 end_action
= "EndScroll";
4227 #endif /* USE_MOTIF */
4230 && strcmp (action_name
, end_action
) == 0
4231 && WINDOWP (window_being_scrolled
))
4235 x_send_scroll_bar_event (window_being_scrolled
,
4236 scroll_bar_end_scroll
, 0, 0);
4237 w
= XWINDOW (window_being_scrolled
);
4239 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4241 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4242 /* The thumb size is incorrect while dragging: fix it. */
4243 set_vertical_scroll_bar (w
);
4245 window_being_scrolled
= Qnil
;
4246 last_scroll_bar_part
= -1;
4248 /* Xt timeouts no longer needed. */
4249 toolkit_scroll_bar_interaction
= 0;
4252 #endif /* not USE_GTK */
4254 /* A vector of windows used for communication between
4255 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4257 static struct window
**scroll_bar_windows
;
4258 static ptrdiff_t scroll_bar_windows_size
;
4261 /* Send a client message with message type Xatom_Scrollbar for a
4262 scroll action to the frame of WINDOW. PART is a value identifying
4263 the part of the scroll bar that was clicked on. PORTION is the
4264 amount to scroll of a whole of WHOLE. */
4267 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4270 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4271 struct window
*w
= XWINDOW (window
);
4272 struct frame
*f
= XFRAME (w
->frame
);
4277 /* Construct a ClientMessage event to send to the frame. */
4278 ev
->type
= ClientMessage
;
4279 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4280 ev
->display
= FRAME_X_DISPLAY (f
);
4281 ev
->window
= FRAME_X_WINDOW (f
);
4284 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4285 not enough to store a pointer or Lisp_Object on a 64 bit system.
4286 So, store the window in scroll_bar_windows and pass the index
4287 into that array in the event. */
4288 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4289 if (scroll_bar_windows
[i
] == NULL
)
4292 if (i
== scroll_bar_windows_size
)
4294 ptrdiff_t old_nbytes
=
4295 scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4297 enum { XClientMessageEvent_MAX
= 0x7fffffff };
4298 scroll_bar_windows
=
4299 xpalloc (scroll_bar_windows
, &scroll_bar_windows_size
, 1,
4300 XClientMessageEvent_MAX
, sizeof *scroll_bar_windows
);
4301 nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4302 memset (&scroll_bar_windows
[i
], 0, nbytes
- old_nbytes
);
4305 scroll_bar_windows
[i
] = w
;
4306 ev
->data
.l
[0] = (long) i
;
4307 ev
->data
.l
[1] = (long) part
;
4308 ev
->data
.l
[2] = (long) 0;
4309 ev
->data
.l
[3] = (long) portion
;
4310 ev
->data
.l
[4] = (long) whole
;
4312 /* Make Xt timeouts work while the scroll bar is active. */
4313 #ifdef USE_X_TOOLKIT
4314 toolkit_scroll_bar_interaction
= 1;
4315 x_activate_timeout_atimer ();
4318 /* Setting the event mask to zero means that the message will
4319 be sent to the client that created the window, and if that
4320 window no longer exists, no event will be sent. */
4321 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4326 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4330 x_scroll_bar_to_input_event (XEvent
*event
, struct input_event
*ievent
)
4332 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4336 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4337 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4339 XSETWINDOW (window
, w
);
4341 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4342 ievent
->frame_or_window
= window
;
4345 ievent
->timestamp
= CurrentTime
;
4348 XtLastTimestampProcessed (FRAME_X_DISPLAY (XFRAME (w
->frame
)));
4350 ievent
->part
= ev
->data
.l
[1];
4351 ievent
->code
= ev
->data
.l
[2];
4352 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4353 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4354 ievent
->modifiers
= 0;
4360 /* Minimum and maximum values used for Motif scroll bars. */
4362 #define XM_SB_MAX 10000000
4365 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4366 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4367 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4370 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4372 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4373 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4374 int part
= -1, whole
= 0, portion
= 0;
4378 case XmCR_DECREMENT
:
4379 bar
->dragging
= Qnil
;
4380 part
= scroll_bar_up_arrow
;
4383 case XmCR_INCREMENT
:
4384 bar
->dragging
= Qnil
;
4385 part
= scroll_bar_down_arrow
;
4388 case XmCR_PAGE_DECREMENT
:
4389 bar
->dragging
= Qnil
;
4390 part
= scroll_bar_above_handle
;
4393 case XmCR_PAGE_INCREMENT
:
4394 bar
->dragging
= Qnil
;
4395 part
= scroll_bar_below_handle
;
4399 bar
->dragging
= Qnil
;
4400 part
= scroll_bar_to_top
;
4403 case XmCR_TO_BOTTOM
:
4404 bar
->dragging
= Qnil
;
4405 part
= scroll_bar_to_bottom
;
4412 /* Get the slider size. */
4414 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4417 whole
= XM_SB_MAX
- slider_size
;
4418 portion
= min (cs
->value
, whole
);
4419 part
= scroll_bar_handle
;
4420 bar
->dragging
= make_number (cs
->value
);
4424 case XmCR_VALUE_CHANGED
:
4430 window_being_scrolled
= bar
->window
;
4431 last_scroll_bar_part
= part
;
4432 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4436 #elif defined USE_GTK
4438 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4439 bar widget. DATA is a pointer to the scroll_bar structure. */
4442 xg_scroll_callback (GtkRange
*range
,
4443 GtkScrollType scroll
,
4447 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4449 int part
= -1, whole
= 0, portion
= 0;
4450 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4451 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4453 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4454 position
= gtk_adjustment_get_value (adj
);
4459 case GTK_SCROLL_JUMP
:
4460 /* Buttons 1 2 or 3 must be grabbed. */
4461 if (FRAME_X_DISPLAY_INFO (f
)->grabbed
!= 0
4462 && FRAME_X_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4464 part
= scroll_bar_handle
;
4465 whole
= gtk_adjustment_get_upper (adj
) -
4466 gtk_adjustment_get_page_size (adj
);
4467 portion
= min ((int)position
, whole
);
4468 bar
->dragging
= make_number ((int)portion
);
4471 case GTK_SCROLL_STEP_BACKWARD
:
4472 part
= scroll_bar_up_arrow
;
4473 bar
->dragging
= Qnil
;
4475 case GTK_SCROLL_STEP_FORWARD
:
4476 part
= scroll_bar_down_arrow
;
4477 bar
->dragging
= Qnil
;
4479 case GTK_SCROLL_PAGE_BACKWARD
:
4480 part
= scroll_bar_above_handle
;
4481 bar
->dragging
= Qnil
;
4483 case GTK_SCROLL_PAGE_FORWARD
:
4484 part
= scroll_bar_below_handle
;
4485 bar
->dragging
= Qnil
;
4491 window_being_scrolled
= bar
->window
;
4492 last_scroll_bar_part
= part
;
4493 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4499 /* Callback for button release. Sets dragging to Qnil when dragging is done. */
4502 xg_end_scroll_callback (GtkWidget
*widget
,
4503 GdkEventButton
*event
,
4506 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4507 bar
->dragging
= Qnil
;
4508 if (WINDOWP (window_being_scrolled
))
4510 x_send_scroll_bar_event (window_being_scrolled
,
4511 scroll_bar_end_scroll
, 0, 0);
4512 window_being_scrolled
= Qnil
;
4519 #else /* not USE_GTK and not USE_MOTIF */
4521 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4522 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4523 scroll bar struct. CALL_DATA is a pointer to a float saying where
4527 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4529 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4530 float top
= *(float *) call_data
;
4532 int whole
, portion
, height
;
4535 /* Get the size of the thumb, a value between 0 and 1. */
4537 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4541 portion
= shown
< 1 ? top
* whole
: 0;
4543 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0f
/ height
))
4544 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4545 the bottom, so we force the scrolling whenever we see that we're
4546 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4547 we try to ensure that we always stay two pixels away from the
4549 part
= scroll_bar_down_arrow
;
4551 part
= scroll_bar_handle
;
4553 window_being_scrolled
= bar
->window
;
4554 bar
->dragging
= make_number (portion
);
4555 last_scroll_bar_part
= part
;
4556 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4560 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4561 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4562 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4563 the scroll bar. CALL_DATA is an integer specifying the action that
4564 has taken place. Its magnitude is in the range 0..height of the
4565 scroll bar. Negative values mean scroll towards buffer start.
4566 Values < height of scroll bar mean line-wise movement. */
4569 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4571 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4572 /* The position really is stored cast to a pointer. */
4573 int position
= (long) call_data
;
4577 /* Get the height of the scroll bar. */
4579 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4582 if (eabs (position
) >= height
)
4583 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4585 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4586 it maps line-movement to call_data = max(5, height/20). */
4587 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4588 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4590 part
= scroll_bar_move_ratio
;
4592 window_being_scrolled
= bar
->window
;
4593 bar
->dragging
= Qnil
;
4594 last_scroll_bar_part
= part
;
4595 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4598 #endif /* not USE_GTK and not USE_MOTIF */
4600 #define SCROLL_BAR_NAME "verticalScrollBar"
4602 /* Create the widget for scroll bar BAR on frame F. Record the widget
4603 and X window of the scroll bar in BAR. */
4607 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4609 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4612 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4613 G_CALLBACK (xg_end_scroll_callback
),
4618 #else /* not USE_GTK */
4621 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4627 const char *scroll_bar_name
= SCROLL_BAR_NAME
;
4628 unsigned long pixel
;
4633 /* Set resources. Create the widget. */
4634 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4635 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4636 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4637 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4638 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4639 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4640 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4642 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4645 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4649 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4652 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4656 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4657 (char *) scroll_bar_name
, av
, ac
);
4659 /* Add one callback for everything that can happen. */
4660 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4662 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4664 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4666 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4668 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4670 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4672 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4675 /* Realize the widget. Only after that is the X window created. */
4676 XtRealizeWidget (widget
);
4678 /* Set the cursor to an arrow. I didn't find a resource to do that.
4679 And I'm wondering why it hasn't an arrow cursor by default. */
4680 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4681 f
->output_data
.x
->nontext_cursor
);
4683 #else /* !USE_MOTIF i.e. use Xaw */
4685 /* Set resources. Create the widget. The background of the
4686 Xaw3d scroll bar widget is a little bit light for my taste.
4687 We don't alter it here to let users change it according
4688 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4689 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4690 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4691 /* For smoother scrolling with Xaw3d -sm */
4692 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4694 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4697 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4701 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4704 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4708 /* Top/bottom shadow colors. */
4710 /* Allocate them, if necessary. */
4711 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4713 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4716 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4717 FRAME_X_COLORMAP (f
),
4718 &pixel
, 1.2, 0x8000))
4720 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4723 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4725 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4728 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4729 FRAME_X_COLORMAP (f
),
4730 &pixel
, 0.6, 0x4000))
4732 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4736 #ifdef XtNbeNiceToColormap
4737 /* Tell the toolkit about them. */
4738 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4739 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4740 /* We tried to allocate a color for the top/bottom shadow, and
4741 failed, so tell Xaw3d to use dithering instead. */
4742 /* But only if we have a small colormap. Xaw3d can allocate nice
4745 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4746 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4750 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4751 be more consistent with other emacs 3d colors, and since Xaw3d is
4752 not good at dealing with allocation failure. */
4754 /* This tells Xaw3d to use real colors instead of dithering for
4756 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4759 /* Specify the colors. */
4760 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4763 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4766 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4769 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4775 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4776 f
->output_data
.x
->edit_widget
, av
, ac
);
4779 char const *initial
= "";
4780 char const *val
= initial
;
4781 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4782 #ifdef XtNarrowScrollbars
4783 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4785 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4786 if (xaw3d_arrow_scroll
|| val
== initial
)
4787 { /* ARROW_SCROLL */
4788 xaw3d_arrow_scroll
= True
;
4789 /* Isn't that just a personal preference ? --Stef */
4790 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4794 /* Define callbacks. */
4795 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4796 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4799 /* Realize the widget. Only after that is the X window created. */
4800 XtRealizeWidget (widget
);
4802 #endif /* !USE_MOTIF */
4804 /* Install an action hook that lets us detect when the user
4805 finishes interacting with a scroll bar. */
4806 if (action_hook_id
== 0)
4807 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4809 /* Remember X window and widget in the scroll bar vector. */
4810 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4811 xwindow
= XtWindow (widget
);
4812 bar
->x_window
= xwindow
;
4816 #endif /* not USE_GTK */
4819 /* Set the thumb size and position of scroll bar BAR. We are currently
4820 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4824 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4826 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4829 #else /* not USE_GTK */
4831 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4834 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4835 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4842 /* We use an estimate of 30 chars per line rather than the real
4843 `portion' value. This has the disadvantage that the thumb size
4844 is not very representative, but it makes our life a lot easier.
4845 Otherwise, we have to constantly adjust the thumb size, which
4846 we can't always do quickly enough: while dragging, the size of
4847 the thumb might prevent the user from dragging the thumb all the
4848 way to the end. but Motif and some versions of Xaw3d don't allow
4849 updating the thumb size while dragging. Also, even if we can update
4850 its size, the update will often happen too late.
4851 If you don't believe it, check out revision 1.650 of xterm.c to see
4852 what hoops we were going through and the still poor behavior we got. */
4853 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4854 /* When the thumb is at the bottom, position == whole.
4855 So we need to increase `whole' to make space for the thumb. */
4862 top
= (float) position
/ whole
;
4863 shown
= (float) portion
/ whole
;
4866 if (NILP (bar
->dragging
))
4870 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4871 is the scroll bar's maximum and MIN is the scroll bar's minimum
4873 size
= shown
* XM_SB_MAX
;
4874 size
= min (size
, XM_SB_MAX
);
4875 size
= max (size
, 1);
4877 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4878 value
= top
* XM_SB_MAX
;
4879 value
= min (value
, XM_SB_MAX
- size
);
4881 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4883 #else /* !USE_MOTIF i.e. use Xaw */
4889 top
= (float) position
/ whole
;
4890 shown
= (float) portion
/ whole
;
4894 float old_top
, old_shown
;
4896 XtVaGetValues (widget
,
4897 XtNtopOfThumb
, &old_top
,
4898 XtNshown
, &old_shown
,
4902 /* Massage the top+shown values. */
4903 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4904 top
= max (0, min (1, top
));
4907 /* Keep two pixels available for moving the thumb down. */
4908 shown
= max (0, min (1 - top
- (2.0f
/ height
), shown
));
4910 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4911 check that your system's configuration file contains a define
4912 for `NARROWPROTO'. See s/freebsd.h for an example. */
4913 if (top
!= old_top
|| shown
!= old_shown
)
4915 if (NILP (bar
->dragging
))
4916 XawScrollbarSetThumb (widget
, top
, shown
);
4919 /* Try to make the scrolling a tad smoother. */
4920 if (!xaw3d_pick_top
)
4921 shown
= min (shown
, old_shown
);
4923 XawScrollbarSetThumb (widget
, top
, shown
);
4927 #endif /* !USE_MOTIF */
4931 #endif /* not USE_GTK */
4933 #endif /* USE_TOOLKIT_SCROLL_BARS */
4937 /************************************************************************
4938 Scroll bars, general
4939 ************************************************************************/
4941 /* Create a scroll bar and return the scroll bar vector for it. W is
4942 the Emacs window on which to create the scroll bar. TOP, LEFT,
4943 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4946 static struct scroll_bar
*
4947 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
4949 struct frame
*f
= XFRAME (w
->frame
);
4950 struct scroll_bar
*bar
4951 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4956 #ifdef USE_TOOLKIT_SCROLL_BARS
4957 x_create_toolkit_scroll_bar (f
, bar
);
4958 #else /* not USE_TOOLKIT_SCROLL_BARS */
4960 XSetWindowAttributes a
;
4964 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4965 if (a
.background_pixel
== -1)
4966 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4968 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4969 | ButtonMotionMask
| PointerMotionHintMask
4971 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4973 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4975 /* Clear the area of W that will serve as a scroll bar. This is
4976 for the case that a window has been split horizontally. In
4977 this case, no clear_frame is generated to reduce flickering. */
4978 if (width
> 0 && height
> 0)
4979 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4981 window_box_height (w
), False
);
4983 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4984 /* Position and size of scroll bar. */
4985 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4987 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4989 /* Border width, depth, class, and visual. */
4996 bar
->x_window
= window
;
4998 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5000 XSETWINDOW (bar
->window
, w
);
5004 bar
->height
= height
;
5007 bar
->dragging
= Qnil
;
5008 bar
->fringe_extended_p
= 0;
5010 /* Add bar to its frame's list of scroll bars. */
5011 bar
->next
= FRAME_SCROLL_BARS (f
);
5013 XSETVECTOR (barobj
, bar
);
5014 fset_scroll_bars (f
, barobj
);
5015 if (!NILP (bar
->next
))
5016 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5018 /* Map the window/widget. */
5019 #ifdef USE_TOOLKIT_SCROLL_BARS
5022 xg_update_scrollbar_pos (f
,
5025 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5026 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5028 #else /* not USE_GTK */
5029 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
5030 XtConfigureWidget (scroll_bar
,
5031 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5033 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5034 max (height
, 1), 0);
5035 XtMapWidget (scroll_bar
);
5036 #endif /* not USE_GTK */
5038 #else /* not USE_TOOLKIT_SCROLL_BARS */
5039 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
5040 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5047 #ifndef USE_TOOLKIT_SCROLL_BARS
5049 /* Draw BAR's handle in the proper position.
5051 If the handle is already drawn from START to END, don't bother
5052 redrawing it, unless REBUILD is non-zero; in that case, always
5053 redraw it. (REBUILD is handy for drawing the handle after expose
5056 Normally, we want to constrain the start and end of the handle to
5057 fit inside its rectangle, but if the user is dragging the scroll
5058 bar handle, we want to let them drag it down all the way, so that
5059 the bar's top is as far down as it goes; otherwise, there's no way
5060 to move to the very end of the buffer. */
5063 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
5065 int dragging
= ! NILP (bar
->dragging
);
5066 Window w
= bar
->x_window
;
5067 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5068 GC gc
= f
->output_data
.x
->normal_gc
;
5070 /* If the display is already accurate, do nothing. */
5072 && start
== bar
->start
5079 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5080 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5081 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5083 /* Make sure the values are reasonable, and try to preserve
5084 the distance between start and end. */
5086 int length
= end
- start
;
5090 else if (start
> top_range
)
5092 end
= start
+ length
;
5096 else if (end
> top_range
&& ! dragging
)
5100 /* Store the adjusted setting in the scroll bar. */
5104 /* Clip the end position, just for display. */
5105 if (end
> top_range
)
5108 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5109 below top positions, to make sure the handle is always at least
5110 that many pixels tall. */
5111 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5113 /* Draw the empty space above the handle. Note that we can't clear
5114 zero-height areas; that means "clear to end of window." */
5116 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5117 /* x, y, width, height, and exposures. */
5118 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5119 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5120 inside_width
, start
,
5123 /* Change to proper foreground color if one is specified. */
5124 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5125 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5126 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5128 /* Draw the handle itself. */
5129 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5130 /* x, y, width, height */
5131 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5132 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5133 inside_width
, end
- start
);
5135 /* Restore the foreground color of the GC if we changed it above. */
5136 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5137 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5138 FRAME_FOREGROUND_PIXEL (f
));
5140 /* Draw the empty space below the handle. Note that we can't
5141 clear zero-height areas; that means "clear to end of window." */
5142 if (end
< inside_height
)
5143 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5144 /* x, y, width, height, and exposures. */
5145 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5146 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5147 inside_width
, inside_height
- end
,
5155 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5157 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5161 x_scroll_bar_remove (struct scroll_bar
*bar
)
5163 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5166 #ifdef USE_TOOLKIT_SCROLL_BARS
5168 xg_remove_scroll_bar (f
, bar
->x_window
);
5169 #else /* not USE_GTK */
5170 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5171 #endif /* not USE_GTK */
5173 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5176 /* Dissociate this scroll bar from its window. */
5177 wset_vertical_scroll_bar (XWINDOW (bar
->window
), Qnil
);
5183 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5184 that we are displaying PORTION characters out of a total of WHOLE
5185 characters, starting at POSITION. If WINDOW has no scroll bar,
5189 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
5191 struct frame
*f
= XFRAME (w
->frame
);
5193 struct scroll_bar
*bar
;
5194 int top
, height
, left
, sb_left
, width
, sb_width
;
5195 int window_y
, window_height
;
5196 #ifdef USE_TOOLKIT_SCROLL_BARS
5197 int fringe_extended_p
;
5200 /* Get window dimensions. */
5201 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5203 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5204 height
= window_height
;
5206 /* Compute the left edge of the scroll bar area. */
5207 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5209 /* Compute the width of the scroll bar which might be less than
5210 the width of the area reserved for the scroll bar. */
5211 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5212 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5216 /* Compute the left edge of the scroll bar. */
5217 #ifdef USE_TOOLKIT_SCROLL_BARS
5218 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5219 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5221 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5223 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5224 sb_left
= left
+ width
- sb_width
;
5229 #ifdef USE_TOOLKIT_SCROLL_BARS
5230 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5231 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5232 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5233 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5234 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5236 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5237 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5238 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5239 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5242 /* Does the scroll bar exist yet? */
5243 if (NILP (w
->vertical_scroll_bar
))
5245 if (width
> 0 && height
> 0)
5248 #ifdef USE_TOOLKIT_SCROLL_BARS
5249 if (fringe_extended_p
)
5250 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5251 sb_left
, top
, sb_width
, height
, False
);
5254 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5255 left
, top
, width
, height
, False
);
5259 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5263 /* It may just need to be moved and resized. */
5264 unsigned int mask
= 0;
5266 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5270 if (sb_left
!= bar
->left
)
5272 if (top
!= bar
->top
)
5274 if (sb_width
!= bar
->width
)
5276 if (height
!= bar
->height
)
5279 #ifdef USE_TOOLKIT_SCROLL_BARS
5281 /* Move/size the scroll bar widget. */
5282 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5284 /* Since toolkit scroll bars are smaller than the space reserved
5285 for them on the frame, we have to clear "under" them. */
5286 if (width
> 0 && height
> 0)
5288 if (fringe_extended_p
)
5289 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5290 sb_left
, top
, sb_width
, height
, False
);
5292 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5293 left
, top
, width
, height
, False
);
5296 xg_update_scrollbar_pos (f
,
5299 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5300 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5302 #else /* not USE_GTK */
5303 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5304 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5306 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5307 max (height
, 1), 0);
5308 #endif /* not USE_GTK */
5310 #else /* not USE_TOOLKIT_SCROLL_BARS */
5312 /* Clear areas not covered by the scroll bar because of
5313 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5314 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5316 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5317 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5319 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5320 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5321 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5325 /* Clear areas not covered by the scroll bar because it's not as
5326 wide as the area reserved for it. This makes sure a
5327 previous mode line display is cleared after C-x 2 C-x 1, for
5330 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5331 int rest
= area_width
- sb_width
;
5332 if (rest
> 0 && height
> 0)
5334 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5335 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5336 left
+ area_width
- rest
, top
,
5337 rest
, height
, False
);
5339 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5340 left
, top
, rest
, height
, False
);
5344 /* Move/size the scroll bar window. */
5349 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5351 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5353 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5357 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5359 /* Remember new settings. */
5360 bar
->left
= sb_left
;
5362 bar
->width
= sb_width
;
5363 bar
->height
= height
;
5368 #ifdef USE_TOOLKIT_SCROLL_BARS
5369 bar
->fringe_extended_p
= fringe_extended_p
;
5371 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5372 #else /* not USE_TOOLKIT_SCROLL_BARS */
5373 /* Set the scroll bar's current state, unless we're currently being
5375 if (NILP (bar
->dragging
))
5377 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5380 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5383 int start
= ((double) position
* top_range
) / whole
;
5384 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5385 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5388 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5390 XSETVECTOR (barobj
, bar
);
5391 wset_vertical_scroll_bar (w
, barobj
);
5395 /* The following three hooks are used when we're doing a thorough
5396 redisplay of the frame. We don't explicitly know which scroll bars
5397 are going to be deleted, because keeping track of when windows go
5398 away is a real pain - "Can you say set-window-configuration, boys
5399 and girls?" Instead, we just assert at the beginning of redisplay
5400 that *all* scroll bars are to be removed, and then save a scroll bar
5401 from the fiery pit when we actually redisplay its window. */
5403 /* Arrange for all scroll bars on FRAME to be removed at the next call
5404 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5405 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5408 XTcondemn_scroll_bars (FRAME_PTR frame
)
5410 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5411 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5414 bar
= FRAME_SCROLL_BARS (frame
);
5415 fset_scroll_bars (frame
, XSCROLL_BAR (bar
)->next
);
5416 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5417 XSCROLL_BAR (bar
)->prev
= Qnil
;
5418 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5419 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5420 fset_condemned_scroll_bars (frame
, bar
);
5425 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5426 Note that WINDOW isn't necessarily condemned at all. */
5429 XTredeem_scroll_bar (struct window
*window
)
5431 struct scroll_bar
*bar
;
5435 /* We can't redeem this window's scroll bar if it doesn't have one. */
5436 if (NILP (window
->vertical_scroll_bar
))
5439 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5441 /* Unlink it from the condemned list. */
5442 f
= XFRAME (WINDOW_FRAME (window
));
5443 if (NILP (bar
->prev
))
5445 /* If the prev pointer is nil, it must be the first in one of
5447 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5448 /* It's not condemned. Everything's fine. */
5450 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5451 window
->vertical_scroll_bar
))
5452 fset_condemned_scroll_bars (f
, bar
->next
);
5454 /* If its prev pointer is nil, it must be at the front of
5455 one or the other! */
5459 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5461 if (! NILP (bar
->next
))
5462 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5464 bar
->next
= FRAME_SCROLL_BARS (f
);
5466 XSETVECTOR (barobj
, bar
);
5467 fset_scroll_bars (f
, barobj
);
5468 if (! NILP (bar
->next
))
5469 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5472 /* Remove all scroll bars on FRAME that haven't been saved since the
5473 last call to `*condemn_scroll_bars_hook'. */
5476 XTjudge_scroll_bars (FRAME_PTR f
)
5478 Lisp_Object bar
, next
;
5480 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5482 /* Clear out the condemned list now so we won't try to process any
5483 more events on the hapless scroll bars. */
5484 fset_condemned_scroll_bars (f
, Qnil
);
5486 for (; ! NILP (bar
); bar
= next
)
5488 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5490 x_scroll_bar_remove (b
);
5493 b
->next
= b
->prev
= Qnil
;
5496 /* Now there should be no references to the condemned scroll bars,
5497 and they should get garbage-collected. */
5501 #ifndef USE_TOOLKIT_SCROLL_BARS
5502 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5503 is a no-op when using toolkit scroll bars.
5505 This may be called from a signal handler, so we have to ignore GC
5509 x_scroll_bar_expose (struct scroll_bar
*bar
, XEvent
*event
)
5511 Window w
= bar
->x_window
;
5512 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5513 GC gc
= f
->output_data
.x
->normal_gc
;
5514 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5518 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5520 /* Switch to scroll bar foreground color. */
5521 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5522 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5523 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5525 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5526 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5528 /* x, y, width, height */
5530 bar
->width
- 1 - width_trim
- width_trim
,
5533 /* Restore the foreground color of the GC if we changed it above. */
5534 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5535 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5536 FRAME_FOREGROUND_PIXEL (f
));
5541 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5543 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5544 is set to something other than NO_EVENT, it is enqueued.
5546 This may be called from a signal handler, so we have to ignore GC
5551 x_scroll_bar_handle_click (struct scroll_bar
*bar
, XEvent
*event
, struct input_event
*emacs_event
)
5553 if (! WINDOWP (bar
->window
))
5556 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5557 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5558 emacs_event
->modifiers
5559 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5560 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5561 event
->xbutton
.state
)
5562 | (event
->type
== ButtonRelease
5565 emacs_event
->frame_or_window
= bar
->window
;
5566 emacs_event
->arg
= Qnil
;
5567 emacs_event
->timestamp
= event
->xbutton
.time
;
5570 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5571 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5574 if (y
> top_range
) y
= top_range
;
5577 emacs_event
->part
= scroll_bar_above_handle
;
5578 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5579 emacs_event
->part
= scroll_bar_handle
;
5581 emacs_event
->part
= scroll_bar_below_handle
;
5583 #ifndef USE_TOOLKIT_SCROLL_BARS
5584 /* If the user has released the handle, set it to its final position. */
5585 if (event
->type
== ButtonRelease
5586 && ! NILP (bar
->dragging
))
5588 int new_start
= y
- XINT (bar
->dragging
);
5589 int new_end
= new_start
+ bar
->end
- bar
->start
;
5591 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5592 bar
->dragging
= Qnil
;
5596 XSETINT (emacs_event
->x
, y
);
5597 XSETINT (emacs_event
->y
, top_range
);
5601 #ifndef USE_TOOLKIT_SCROLL_BARS
5603 /* Handle some mouse motion while someone is dragging the scroll bar.
5605 This may be called from a signal handler, so we have to ignore GC
5609 x_scroll_bar_note_movement (struct scroll_bar
*bar
, XEvent
*event
)
5611 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5613 last_mouse_movement_time
= event
->xmotion
.time
;
5616 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5618 /* If we're dragging the bar, display it. */
5619 if (! NILP (bar
->dragging
))
5621 /* Where should the handle be now? */
5622 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5624 if (new_start
!= bar
->start
)
5626 int new_end
= new_start
+ bar
->end
- bar
->start
;
5628 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5633 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5635 /* Return information to the user about the current position of the mouse
5636 on the scroll bar. */
5639 x_scroll_bar_report_motion (FRAME_PTR
*fp
, Lisp_Object
*bar_window
,
5640 enum scroll_bar_part
*part
, Lisp_Object
*x
,
5641 Lisp_Object
*y
, Time
*timestamp
)
5643 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5644 Window w
= bar
->x_window
;
5645 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5647 Window dummy_window
;
5649 unsigned int dummy_mask
;
5653 /* Get the mouse's position relative to the scroll bar window, and
5655 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5657 /* Root, child, root x and root y. */
5658 &dummy_window
, &dummy_window
,
5659 &dummy_coord
, &dummy_coord
,
5661 /* Position relative to scroll bar. */
5664 /* Mouse buttons and modifier keys. */
5670 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5672 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5674 if (! NILP (bar
->dragging
))
5675 win_y
-= XINT (bar
->dragging
);
5679 if (win_y
> top_range
)
5683 *bar_window
= bar
->window
;
5685 if (! NILP (bar
->dragging
))
5686 *part
= scroll_bar_handle
;
5687 else if (win_y
< bar
->start
)
5688 *part
= scroll_bar_above_handle
;
5689 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5690 *part
= scroll_bar_handle
;
5692 *part
= scroll_bar_below_handle
;
5694 XSETINT (*x
, win_y
);
5695 XSETINT (*y
, top_range
);
5698 last_mouse_scroll_bar
= Qnil
;
5701 *timestamp
= last_mouse_movement_time
;
5707 /* The screen has been cleared so we may have changed foreground or
5708 background colors, and the scroll bars may need to be redrawn.
5709 Clear out the scroll bars, and ask for expose events, so we can
5713 x_scroll_bar_clear (FRAME_PTR f
)
5715 #ifndef USE_TOOLKIT_SCROLL_BARS
5718 /* We can have scroll bars even if this is 0,
5719 if we just turned off scroll bar mode.
5720 But in that case we should not clear them. */
5721 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5722 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5723 bar
= XSCROLL_BAR (bar
)->next
)
5724 XClearArea (FRAME_X_DISPLAY (f
),
5725 XSCROLL_BAR (bar
)->x_window
,
5727 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5731 /* The main X event-reading loop - XTread_socket. */
5733 /* This holds the state XLookupString needs to implement dead keys
5734 and other tricks known as "compose processing". _X Window System_
5735 says that a portable program can't use this, but Stephen Gildea assures
5736 me that letting the compiler initialize it to zeros will work okay.
5738 This must be defined outside of XTread_socket, for the same reasons
5739 given for enter_timestamp, above. */
5741 static XComposeStatus compose_status
;
5743 /* Record the last 100 characters stored
5744 to help debug the loss-of-chars-during-GC problem. */
5746 static int temp_index
;
5747 static short temp_buffer
[100];
5749 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5750 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5752 temp_buffer[temp_index++] = (keysym)
5754 /* Set this to nonzero to fake an "X I/O error"
5755 on a particular display. */
5757 static struct x_display_info
*XTread_socket_fake_io_error
;
5759 /* When we find no input here, we occasionally do a no-op command
5760 to verify that the X server is still running and we can still talk with it.
5761 We try all the open displays, one by one.
5762 This variable is used for cycling thru the displays. */
5764 static struct x_display_info
*next_noop_dpyinfo
;
5766 #if defined USE_X_TOOLKIT || defined USE_GTK
5767 #define SET_SAVED_BUTTON_EVENT \
5770 if (f->output_data.x->saved_menu_event == 0) \
5771 f->output_data.x->saved_menu_event = \
5772 xmalloc (sizeof (XEvent)); \
5773 *f->output_data.x->saved_menu_event = event; \
5774 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5775 XSETFRAME (inev.ie.frame_or_window, f); \
5787 /* Filter events for the current X input method.
5788 DPYINFO is the display this event is for.
5789 EVENT is the X event to filter.
5791 Returns non-zero if the event was filtered, caller shall not process
5793 Returns zero if event is wasn't filtered. */
5797 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5799 /* XFilterEvent returns non-zero if the input method has
5800 consumed the event. We pass the frame's X window to
5801 XFilterEvent because that's the one for which the IC
5804 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5805 event
->xclient
.window
);
5807 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5812 static int current_count
;
5813 static int current_finish
;
5814 static struct input_event
*current_hold_quit
;
5816 /* This is the filter function invoked by the GTK event loop.
5817 It is invoked before the XEvent is translated to a GdkEvent,
5818 so we have a chance to act on the event before GTK. */
5819 static GdkFilterReturn
5820 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5822 XEvent
*xev
= (XEvent
*) gxev
;
5825 if (current_count
>= 0)
5827 struct x_display_info
*dpyinfo
;
5829 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5832 /* Filter events for the current X input method.
5833 GTK calls XFilterEvent but not for key press and release,
5834 so we do it here. */
5835 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5837 && x_filter_event (dpyinfo
, xev
))
5840 return GDK_FILTER_REMOVE
;
5845 current_finish
= X_EVENT_NORMAL
;
5848 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5852 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5856 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5857 return GDK_FILTER_REMOVE
;
5859 return GDK_FILTER_CONTINUE
;
5861 #endif /* USE_GTK */
5864 static void xembed_send_message (struct frame
*f
, Time
,
5865 enum xembed_message
,
5866 long detail
, long data1
, long data2
);
5868 /* Handles the XEvent EVENT on display DPYINFO.
5870 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5871 *FINISH is zero if caller should continue reading events.
5872 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5874 We return the number of characters stored into the buffer. */
5877 handle_one_xevent (struct x_display_info
*dpyinfo
, XEvent
*eventptr
,
5878 int *finish
, struct input_event
*hold_quit
)
5881 struct input_event ie
;
5882 struct selection_input_event sie
;
5886 ptrdiff_t nbytes
= 0;
5887 struct frame
*f
= NULL
;
5888 struct coding_system coding
;
5889 XEvent event
= *eventptr
;
5890 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
5893 *finish
= X_EVENT_NORMAL
;
5895 EVENT_INIT (inev
.ie
);
5896 inev
.ie
.kind
= NO_EVENT
;
5899 if (pending_event_wait
.eventtype
== event
.type
)
5900 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5906 if (event
.xclient
.message_type
5907 == dpyinfo
->Xatom_wm_protocols
5908 && event
.xclient
.format
== 32)
5910 if (event
.xclient
.data
.l
[0]
5911 == dpyinfo
->Xatom_wm_take_focus
)
5913 /* Use x_any_window_to_frame because this
5914 could be the shell widget window
5915 if the frame has no title bar. */
5916 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5918 /* Not quite sure this is needed -pd */
5919 if (f
&& FRAME_XIC (f
))
5920 XSetICFocus (FRAME_XIC (f
));
5922 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5923 instructs the WM to set the input focus automatically for
5924 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5925 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5926 it has set the focus. So, XSetInputFocus below is not
5929 The call to XSetInputFocus below has also caused trouble. In
5930 cases where the XSetInputFocus done by the WM and the one
5931 below are temporally close (on a fast machine), the call
5932 below can generate additional FocusIn events which confuse
5935 /* Since we set WM_TAKE_FOCUS, we must call
5936 XSetInputFocus explicitly. But not if f is null,
5937 since that might be an event for a deleted frame. */
5940 Display
*d
= event
.xclient
.display
;
5941 /* Catch and ignore errors, in case window has been
5942 iconified by a window manager such as GWM. */
5944 XSetInputFocus (d
, event
.xclient
.window
,
5945 /* The ICCCM says this is
5946 the only valid choice. */
5948 event
.xclient
.data
.l
[1]);
5949 /* This is needed to detect the error
5950 if there is an error. */
5952 x_uncatch_errors ();
5954 /* Not certain about handling scroll bars here */
5959 if (event
.xclient
.data
.l
[0]
5960 == dpyinfo
->Xatom_wm_save_yourself
)
5962 /* Save state modify the WM_COMMAND property to
5963 something which can reinstate us. This notifies
5964 the session manager, who's looking for such a
5965 PropertyNotify. Can restart processing when
5966 a keyboard or mouse event arrives. */
5967 /* If we have a session manager, don't set this.
5968 KDE will then start two Emacsen, one for the
5969 session manager and one for this. */
5971 if (! x_session_have_connection ())
5974 f
= x_top_window_to_frame (dpyinfo
,
5975 event
.xclient
.window
);
5976 /* This is just so we only give real data once
5977 for a single Emacs process. */
5978 if (f
== SELECTED_FRAME ())
5979 XSetCommand (FRAME_X_DISPLAY (f
),
5980 event
.xclient
.window
,
5981 initial_argv
, initial_argc
);
5983 XSetCommand (FRAME_X_DISPLAY (f
),
5984 event
.xclient
.window
,
5990 if (event
.xclient
.data
.l
[0]
5991 == dpyinfo
->Xatom_wm_delete_window
)
5993 f
= x_any_window_to_frame (dpyinfo
,
5994 event
.xclient
.window
);
5996 goto OTHER
; /* May be a dialog that is to be removed */
5998 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5999 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6006 if (event
.xclient
.message_type
6007 == dpyinfo
->Xatom_wm_configure_denied
)
6012 if (event
.xclient
.message_type
6013 == dpyinfo
->Xatom_wm_window_moved
)
6016 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6018 new_x
= event
.xclient
.data
.s
[0];
6019 new_y
= event
.xclient
.data
.s
[1];
6023 f
->left_pos
= new_x
;
6030 if (event
.xclient
.message_type
6031 == dpyinfo
->Xatom_editres
)
6033 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6035 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
6039 #endif /* HACK_EDITRES */
6041 if ((event
.xclient
.message_type
6042 == dpyinfo
->Xatom_DONE
)
6043 || (event
.xclient
.message_type
6044 == dpyinfo
->Xatom_PAGE
))
6046 /* Ghostview job completed. Kill it. We could
6047 reply with "Next" if we received "Page", but we
6048 currently never do because we are interested in
6049 images, only, which should have 1 page. */
6050 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
6051 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6054 x_kill_gs_process (pixmap
, f
);
6055 expose_frame (f
, 0, 0, 0, 0);
6059 #ifdef USE_TOOLKIT_SCROLL_BARS
6060 /* Scroll bar callbacks send a ClientMessage from which
6061 we construct an input_event. */
6062 if (event
.xclient
.message_type
6063 == dpyinfo
->Xatom_Scrollbar
)
6065 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
6066 *finish
= X_EVENT_GOTO_OUT
;
6069 #endif /* USE_TOOLKIT_SCROLL_BARS */
6071 /* XEmbed messages from the embedder (if any). */
6072 if (event
.xclient
.message_type
6073 == dpyinfo
->Xatom_XEMBED
)
6075 enum xembed_message msg
= event
.xclient
.data
.l
[1];
6076 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6077 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6079 *finish
= X_EVENT_GOTO_OUT
;
6083 xft_settings_event (dpyinfo
, &event
);
6085 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6088 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6089 *finish
= X_EVENT_DROP
;
6093 case SelectionNotify
:
6094 last_user_time
= event
.xselection
.time
;
6095 #ifdef USE_X_TOOLKIT
6096 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6098 #endif /* not USE_X_TOOLKIT */
6099 x_handle_selection_notify (&event
.xselection
);
6102 case SelectionClear
: /* Someone has grabbed ownership. */
6103 last_user_time
= event
.xselectionclear
.time
;
6104 #ifdef USE_X_TOOLKIT
6105 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6107 #endif /* USE_X_TOOLKIT */
6109 XSelectionClearEvent
*eventp
= &(event
.xselectionclear
);
6111 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6112 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6113 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6114 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6115 inev
.ie
.frame_or_window
= Qnil
;
6119 case SelectionRequest
: /* Someone wants our selection. */
6120 last_user_time
= event
.xselectionrequest
.time
;
6121 #ifdef USE_X_TOOLKIT
6122 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6124 #endif /* USE_X_TOOLKIT */
6126 XSelectionRequestEvent
*eventp
= &(event
.xselectionrequest
);
6128 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6129 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6130 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6131 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6132 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6133 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6134 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6135 inev
.ie
.frame_or_window
= Qnil
;
6139 case PropertyNotify
:
6140 last_user_time
= event
.xproperty
.time
;
6141 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
6142 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6143 if (x_handle_net_wm_state (f
, &event
.xproperty
) && f
->iconified
6144 && f
->output_data
.x
->net_wm_state_hidden_seen
)
6146 /* Gnome shell does not iconify us when C-z is pressed. It hides
6147 the frame. So if our state says we aren't hidden anymore,
6148 treat it as deiconified. */
6149 if (! f
->async_iconified
)
6150 SET_FRAME_GARBAGED (f
);
6151 f
->async_visible
= 1;
6152 f
->async_iconified
= 0;
6153 f
->output_data
.x
->has_been_visible
= 1;
6154 f
->output_data
.x
->net_wm_state_hidden_seen
= 0;
6155 inev
.ie
.kind
= DEICONIFY_EVENT
;
6156 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6159 x_handle_property_notify (&event
.xproperty
);
6160 xft_settings_event (dpyinfo
, &event
);
6163 case ReparentNotify
:
6164 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6168 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6169 x_real_positions (f
, &x
, &y
);
6173 /* Perhaps reparented due to a WM restart. Reset this. */
6174 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6175 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6177 x_set_frame_alpha (f
);
6182 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6186 /* This seems to be needed for GTK 2.6. */
6187 x_clear_area (event
.xexpose
.display
,
6188 event
.xexpose
.window
,
6189 event
.xexpose
.x
, event
.xexpose
.y
,
6190 event
.xexpose
.width
, event
.xexpose
.height
,
6193 if (f
->async_visible
== 0)
6195 f
->async_visible
= 1;
6196 f
->async_iconified
= 0;
6197 f
->output_data
.x
->has_been_visible
= 1;
6198 SET_FRAME_GARBAGED (f
);
6202 event
.xexpose
.x
, event
.xexpose
.y
,
6203 event
.xexpose
.width
, event
.xexpose
.height
);
6207 #ifndef USE_TOOLKIT_SCROLL_BARS
6208 struct scroll_bar
*bar
;
6210 #if defined USE_LUCID
6211 /* Submenus of the Lucid menu bar aren't widgets
6212 themselves, so there's no way to dispatch events
6213 to them. Recognize this case separately. */
6216 = x_window_to_menu_bar (event
.xexpose
.window
);
6218 xlwmenu_redisplay (widget
);
6220 #endif /* USE_LUCID */
6222 #ifdef USE_TOOLKIT_SCROLL_BARS
6223 /* Dispatch event to the widget. */
6225 #else /* not USE_TOOLKIT_SCROLL_BARS */
6226 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6227 event
.xexpose
.window
);
6230 x_scroll_bar_expose (bar
, &event
);
6231 #ifdef USE_X_TOOLKIT
6234 #endif /* USE_X_TOOLKIT */
6235 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6239 case GraphicsExpose
: /* This occurs when an XCopyArea's
6240 source area was obscured or not
6242 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6246 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6247 event
.xgraphicsexpose
.width
,
6248 event
.xgraphicsexpose
.height
);
6250 #ifdef USE_X_TOOLKIT
6253 #endif /* USE_X_TOOLKIT */
6256 case NoExpose
: /* This occurs when an XCopyArea's
6257 source area was completely
6262 /* Redo the mouse-highlight after the tooltip has gone. */
6263 if (event
.xmap
.window
== tip_window
)
6266 redo_mouse_highlight ();
6269 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6270 if (f
) /* F may no longer exist if
6271 the frame was deleted. */
6273 /* While a frame is unmapped, display generation is
6274 disabled; you don't want to spend time updating a
6275 display that won't ever be seen. */
6276 f
->async_visible
= 0;
6277 /* We can't distinguish, from the event, whether the window
6278 has become iconified or invisible. So assume, if it
6279 was previously visible, than now it is iconified.
6280 But x_make_frame_invisible clears both
6281 the visible flag and the iconified flag;
6282 and that way, we know the window is not iconified now. */
6283 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6285 f
->async_iconified
= 1;
6287 inev
.ie
.kind
= ICONIFY_EVENT
;
6288 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6294 if (event
.xmap
.window
== tip_window
)
6295 /* The tooltip has been drawn already. Avoid
6296 the SET_FRAME_GARBAGED below. */
6299 /* We use x_top_window_to_frame because map events can
6300 come for sub-windows and they don't mean that the
6301 frame is visible. */
6302 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6305 /* wait_reading_process_output will notice this and update
6306 the frame's display structures.
6307 If we where iconified, we should not set garbaged,
6308 because that stops redrawing on Expose events. This looks
6309 bad if we are called from a recursive event loop
6310 (x_dispatch_event), for example when a dialog is up. */
6311 if (! f
->async_iconified
)
6312 SET_FRAME_GARBAGED (f
);
6314 /* Check if fullscreen was specified before we where mapped the
6315 first time, i.e. from the command line. */
6316 if (!f
->output_data
.x
->has_been_visible
)
6317 x_check_fullscreen (f
);
6319 f
->async_visible
= 1;
6320 f
->async_iconified
= 0;
6321 f
->output_data
.x
->has_been_visible
= 1;
6325 inev
.ie
.kind
= DEICONIFY_EVENT
;
6326 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6328 else if (! NILP (Vframe_list
)
6329 && ! NILP (XCDR (Vframe_list
)))
6330 /* Force a redisplay sooner or later
6331 to update the frame titles
6332 in case this is the second frame. */
6333 record_asynch_buffer_change ();
6336 xg_frame_resized (f
, -1, -1);
6343 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 mouse-highlight is an integer, input clears out
6355 mouse highlighting. */
6356 if (!hlinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6358 || !EQ (f
->tool_bar_window
, hlinfo
->mouse_face_window
)))
6360 clear_mouse_face (hlinfo
);
6361 hlinfo
->mouse_face_hidden
= 1;
6364 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6367 /* Scroll bars consume key events, but we want
6368 the keys to go to the scroll bar's frame. */
6369 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6371 if (widget
&& XmIsScrollBar (widget
))
6373 widget
= XtParent (widget
);
6374 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6377 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6381 KeySym keysym
, orig_keysym
;
6382 /* al%imercury@uunet.uu.net says that making this 81
6383 instead of 80 fixed a bug whereby meta chars made
6386 It seems that some version of XmbLookupString has
6387 a bug of not returning XBufferOverflow in
6388 status_return even if the input is too long to
6389 fit in 81 bytes. So, we must prepare sufficient
6390 bytes for copy_buffer. 513 bytes (256 chars for
6391 two-byte character set) seems to be a fairly good
6392 approximation. -- 2000.8.10 handa@etl.go.jp */
6393 unsigned char copy_buffer
[513];
6394 unsigned char *copy_bufptr
= copy_buffer
;
6395 int copy_bufsiz
= sizeof (copy_buffer
);
6397 Lisp_Object coding_system
= Qlatin_1
;
6401 /* Don't pass keys to GTK. A Tab will shift focus to the
6402 tool bar in GTK 2.4. Keys will still go to menus and
6403 dialogs because in that case popup_activated is TRUE
6405 *finish
= X_EVENT_DROP
;
6409 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6410 extra_keyboard_modifiers
);
6411 modifiers
= event
.xkey
.state
;
6413 /* This will have to go some day... */
6415 /* make_lispy_event turns chars into control chars.
6416 Don't do it here because XLookupString is too eager. */
6417 event
.xkey
.state
&= ~ControlMask
;
6418 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6419 | dpyinfo
->super_mod_mask
6420 | dpyinfo
->hyper_mod_mask
6421 | dpyinfo
->alt_mod_mask
);
6423 /* In case Meta is ComposeCharacter,
6424 clear its status. According to Markus Ehrnsperger
6425 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6426 this enables ComposeCharacter to work whether or
6427 not it is combined with Meta. */
6428 if (modifiers
& dpyinfo
->meta_mod_mask
)
6429 memset (&compose_status
, 0, sizeof (compose_status
));
6434 Status status_return
;
6436 coding_system
= Vlocale_coding_system
;
6437 nbytes
= XmbLookupString (FRAME_XIC (f
),
6438 &event
.xkey
, (char *) copy_bufptr
,
6439 copy_bufsiz
, &keysym
,
6441 if (status_return
== XBufferOverflow
)
6443 copy_bufsiz
= nbytes
+ 1;
6444 copy_bufptr
= alloca (copy_bufsiz
);
6445 nbytes
= XmbLookupString (FRAME_XIC (f
),
6446 &event
.xkey
, (char *) copy_bufptr
,
6447 copy_bufsiz
, &keysym
,
6450 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6451 if (status_return
== XLookupNone
)
6453 else if (status_return
== XLookupChars
)
6458 else if (status_return
!= XLookupKeySym
6459 && status_return
!= XLookupBoth
)
6463 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6464 copy_bufsiz
, &keysym
,
6467 nbytes
= XLookupString (&event
.xkey
, (char *) copy_bufptr
,
6468 copy_bufsiz
, &keysym
,
6472 /* If not using XIM/XIC, and a compose sequence is in progress,
6473 we break here. Otherwise, chars_matched is always 0. */
6474 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6477 memset (&compose_status
, 0, sizeof (compose_status
));
6478 orig_keysym
= keysym
;
6480 /* Common for all keysym input events. */
6481 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6483 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6484 inev
.ie
.timestamp
= event
.xkey
.time
;
6486 /* First deal with keysyms which have defined
6487 translations to characters. */
6488 if (keysym
>= 32 && keysym
< 128)
6489 /* Avoid explicitly decoding each ASCII character. */
6491 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6492 inev
.ie
.code
= keysym
;
6496 /* Keysyms directly mapped to Unicode characters. */
6497 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6499 if (keysym
< 0x01000080)
6500 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6502 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6503 inev
.ie
.code
= keysym
& 0xFFFFFF;
6507 /* Now non-ASCII. */
6508 if (HASH_TABLE_P (Vx_keysym_table
)
6509 && (c
= Fgethash (make_number (keysym
),
6514 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6515 ? ASCII_KEYSTROKE_EVENT
6516 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6517 inev
.ie
.code
= XFASTINT (c
);
6521 /* Random non-modifier sorts of keysyms. */
6522 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6523 || keysym
== XK_Delete
6524 #ifdef XK_ISO_Left_Tab
6525 || (keysym
>= XK_ISO_Left_Tab
6526 && keysym
<= XK_ISO_Enter
)
6528 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6529 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6531 /* This recognizes the "extended function
6532 keys". It seems there's no cleaner way.
6533 Test IsModifierKey to avoid handling
6534 mode_switch incorrectly. */
6535 || (XK_Select
<= keysym
&& keysym
< XK_KP_Space
)
6537 #ifdef XK_dead_circumflex
6538 || orig_keysym
== XK_dead_circumflex
6540 #ifdef XK_dead_grave
6541 || orig_keysym
== XK_dead_grave
6543 #ifdef XK_dead_tilde
6544 || orig_keysym
== XK_dead_tilde
6546 #ifdef XK_dead_diaeresis
6547 || orig_keysym
== XK_dead_diaeresis
6549 #ifdef XK_dead_macron
6550 || orig_keysym
== XK_dead_macron
6552 #ifdef XK_dead_degree
6553 || orig_keysym
== XK_dead_degree
6555 #ifdef XK_dead_acute
6556 || orig_keysym
== XK_dead_acute
6558 #ifdef XK_dead_cedilla
6559 || orig_keysym
== XK_dead_cedilla
6561 #ifdef XK_dead_breve
6562 || orig_keysym
== XK_dead_breve
6564 #ifdef XK_dead_ogonek
6565 || orig_keysym
== XK_dead_ogonek
6567 #ifdef XK_dead_caron
6568 || orig_keysym
== XK_dead_caron
6570 #ifdef XK_dead_doubleacute
6571 || orig_keysym
== XK_dead_doubleacute
6573 #ifdef XK_dead_abovedot
6574 || orig_keysym
== XK_dead_abovedot
6576 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6577 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6578 /* Any "vendor-specific" key is ok. */
6579 || (orig_keysym
& (1 << 28))
6580 || (keysym
!= NoSymbol
&& nbytes
== 0))
6581 && ! (IsModifierKey (orig_keysym
)
6582 /* The symbols from XK_ISO_Lock
6583 to XK_ISO_Last_Group_Lock
6584 don't have real modifiers but
6585 should be treated similarly to
6586 Mode_switch by Emacs. */
6587 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6588 || (XK_ISO_Lock
<= orig_keysym
6589 && orig_keysym
<= XK_ISO_Last_Group_Lock
)
6593 STORE_KEYSYM_FOR_DEBUG (keysym
);
6594 /* make_lispy_event will convert this to a symbolic
6596 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6597 inev
.ie
.code
= keysym
;
6601 { /* Raw bytes, not keysym. */
6605 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6607 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6609 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6612 if (nchars
< nbytes
)
6614 /* Decode the input data. */
6616 /* The input should be decoded with `coding_system'
6617 which depends on which X*LookupString function
6618 we used just above and the locale. */
6619 setup_coding_system (coding_system
, &coding
);
6620 coding
.src_multibyte
= 0;
6621 coding
.dst_multibyte
= 1;
6622 /* The input is converted to events, thus we can't
6623 handle composition. Anyway, there's no XIM that
6624 gives us composition information. */
6625 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6627 SAFE_NALLOCA (coding
.destination
, MAX_MULTIBYTE_LENGTH
,
6629 coding
.dst_bytes
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6630 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6631 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6632 nbytes
= coding
.produced
;
6633 nchars
= coding
.produced_char
;
6634 copy_bufptr
= coding
.destination
;
6637 /* Convert the input data to a sequence of
6638 character events. */
6639 for (i
= 0; i
< nbytes
; i
+= len
)
6642 if (nchars
== nbytes
)
6643 ch
= copy_bufptr
[i
], len
= 1;
6645 ch
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6646 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (ch
)
6647 ? ASCII_KEYSTROKE_EVENT
6648 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6650 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6655 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6657 if (keysym
== NoSymbol
)
6663 /* Don't dispatch this event since XtDispatchEvent calls
6664 XFilterEvent, and two calls in a row may freeze the
6672 last_user_time
= event
.xkey
.time
;
6674 /* Don't dispatch this event since XtDispatchEvent calls
6675 XFilterEvent, and two calls in a row may freeze the
6683 last_user_time
= event
.xcrossing
.time
;
6684 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6686 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6688 if (f
&& x_mouse_click_focus_ignore_position
)
6689 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6691 /* EnterNotify counts as mouse movement,
6692 so update things that depend on mouse position. */
6693 if (f
&& !f
->output_data
.x
->hourglass_p
)
6694 note_mouse_movement (f
, &event
.xmotion
);
6696 /* We may get an EnterNotify on the buttons in the toolbar. In that
6697 case we moved out of any highlighted area and need to note this. */
6698 if (!f
&& last_mouse_glyph_frame
)
6699 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6704 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6708 last_user_time
= event
.xcrossing
.time
;
6709 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6711 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6714 if (f
== hlinfo
->mouse_face_mouse_frame
)
6716 /* If we move outside the frame, then we're
6717 certainly no longer on any text in the frame. */
6718 clear_mouse_face (hlinfo
);
6719 hlinfo
->mouse_face_mouse_frame
= 0;
6722 /* Generate a nil HELP_EVENT to cancel a help-echo.
6723 Do it only if there's something to cancel.
6724 Otherwise, the startup message is cleared when
6725 the mouse leaves the frame. */
6726 if (any_help_event_p
)
6730 /* See comment in EnterNotify above */
6731 else if (last_mouse_glyph_frame
)
6732 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6737 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6742 last_user_time
= event
.xmotion
.time
;
6743 previous_help_echo_string
= help_echo_string
;
6744 help_echo_string
= Qnil
;
6746 if (dpyinfo
->grabbed
&& last_mouse_frame
6747 && FRAME_LIVE_P (last_mouse_frame
))
6748 f
= last_mouse_frame
;
6750 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6752 if (hlinfo
->mouse_face_hidden
)
6754 hlinfo
->mouse_face_hidden
= 0;
6755 clear_mouse_face (hlinfo
);
6759 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6765 /* Generate SELECT_WINDOW_EVENTs when needed.
6766 Don't let popup menus influence things (bug#1261). */
6767 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6771 window
= window_from_coordinates (f
,
6772 event
.xmotion
.x
, event
.xmotion
.y
,
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_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
;
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
);
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. */
6887 memset (&compose_status
, 0, sizeof (compose_status
));
6888 last_mouse_glyph_frame
= 0;
6889 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 /* Is this in the tool-bar? */
6905 if (WINDOWP (f
->tool_bar_window
)
6906 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6909 int x
= event
.xbutton
.x
;
6910 int y
= event
.xbutton
.y
;
6912 window
= window_from_coordinates (f
, x
, y
, 0, 1);
6913 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6915 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6917 handle_tool_bar_click (f
, x
, y
,
6918 event
.xbutton
.type
== ButtonPress
,
6919 x_x_to_emacs_modifiers (dpyinfo
,
6920 event
.xbutton
.state
));
6925 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6926 if (! popup_activated ())
6929 if (ignore_next_mouse_click_timeout
)
6931 if (event
.type
== ButtonPress
6932 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6934 ignore_next_mouse_click_timeout
= 0;
6935 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6937 if (event
.type
== ButtonRelease
)
6938 ignore_next_mouse_click_timeout
= 0;
6941 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6943 if (FRAME_X_EMBEDDED_P (f
))
6944 xembed_send_message (f
, event
.xbutton
.time
,
6945 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6949 struct scroll_bar
*bar
6950 = x_window_to_scroll_bar (event
.xbutton
.display
,
6951 event
.xbutton
.window
);
6953 #ifdef USE_TOOLKIT_SCROLL_BARS
6954 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6956 if (bar
&& event
.xbutton
.state
& ControlMask
)
6958 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6959 *finish
= X_EVENT_DROP
;
6961 #else /* not USE_TOOLKIT_SCROLL_BARS */
6963 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6964 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6967 if (event
.type
== ButtonPress
)
6969 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6970 last_mouse_frame
= f
;
6973 last_tool_bar_item
= -1;
6976 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6978 /* Ignore any mouse motion that happened before this event;
6979 any subsequent mouse-movement Emacs events should reflect
6980 only motion after the ButtonPress/Release. */
6984 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6985 f
= x_menubar_window_to_frame (dpyinfo
, &event
);
6986 /* For a down-event in the menu bar,
6987 don't pass it to Xt right now.
6988 Instead, save it away
6989 and we will pass it to Xt from kbd_buffer_get_event.
6990 That way, we can run some Lisp code first. */
6991 if (! popup_activated ()
6993 /* Gtk+ menus only react to the first three buttons. */
6994 && event
.xbutton
.button
< 3
6996 && f
&& event
.type
== ButtonPress
6997 /* Verify the event is really within the menu bar
6998 and not just sent to it due to grabbing. */
6999 && event
.xbutton
.x
>= 0
7000 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
7001 && event
.xbutton
.y
>= 0
7002 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
7003 && event
.xbutton
.same_screen
)
7005 SET_SAVED_BUTTON_EVENT
;
7006 XSETFRAME (last_mouse_press_frame
, f
);
7007 *finish
= X_EVENT_DROP
;
7009 else if (event
.type
== ButtonPress
)
7011 last_mouse_press_frame
= Qnil
;
7016 #endif /* USE_X_TOOLKIT || USE_GTK */
7020 case CirculateNotify
:
7023 case CirculateRequest
:
7026 case VisibilityNotify
:
7030 /* Someone has changed the keyboard mapping - update the
7032 switch (event
.xmapping
.request
)
7034 case MappingModifier
:
7035 x_find_modifier_meanings (dpyinfo
);
7036 /* This is meant to fall through. */
7037 case MappingKeyboard
:
7038 XRefreshKeyboardMapping (&event
.xmapping
);
7043 xft_settings_event (dpyinfo
, &event
);
7048 #ifdef USE_X_TOOLKIT
7050 if (*finish
!= X_EVENT_DROP
)
7051 XtDispatchEvent (&event
);
7053 #endif /* USE_X_TOOLKIT */
7058 if (inev
.ie
.kind
!= NO_EVENT
)
7060 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7065 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7070 XSETFRAME (frame
, f
);
7076 any_help_event_p
= 1;
7077 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7078 help_echo_object
, help_echo_pos
);
7082 help_echo_string
= Qnil
;
7083 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7093 #if defined USE_GTK || defined USE_X_TOOLKIT
7095 /* Handles the XEvent EVENT on display DISPLAY.
7096 This is used for event loops outside the normal event handling,
7097 i.e. looping while a popup menu or a dialog is posted.
7099 Returns the value handle_one_xevent sets in the finish argument. */
7101 x_dispatch_event (XEvent
*event
, Display
*display
)
7103 struct x_display_info
*dpyinfo
;
7104 int finish
= X_EVENT_NORMAL
;
7106 dpyinfo
= x_display_info_for_display (display
);
7109 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7116 /* Read events coming from the X server.
7117 This routine is called by the SIGIO handler only if SYNC_INPUT is
7119 We return as soon as there are no more events to be read.
7121 We return the number of characters stored into the buffer,
7122 thus pretending to be `read' (except the characters we store
7123 in the keyboard buffer can be multibyte, so are not necessarily
7126 EXPECTED is nonzero if the caller knows input is available. */
7129 XTread_socket (struct terminal
*terminal
, int expected
, struct input_event
*hold_quit
)
7132 int event_found
= 0;
7134 if (interrupt_input_blocked
)
7136 interrupt_input_pending
= 1;
7138 pending_signals
= 1;
7143 interrupt_input_pending
= 0;
7145 pending_signals
= pending_atimers
;
7149 /* So people can tell when we have read the available input. */
7150 input_signal_count
++;
7156 /* For debugging, this gives a way to fake an I/O error. */
7157 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7159 XTread_socket_fake_io_error
= 0;
7160 x_io_error_quitter (terminal
->display_info
.x
->display
);
7164 while (XPending (terminal
->display_info
.x
->display
))
7169 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7172 /* Filter events for the current X input method. */
7173 if (x_filter_event (terminal
->display_info
.x
, &event
))
7178 count
+= handle_one_xevent (terminal
->display_info
.x
,
7179 &event
, &finish
, hold_quit
);
7181 if (finish
== X_EVENT_GOTO_OUT
)
7189 /* For GTK we must use the GTK event loop. But XEvents gets passed
7190 to our filter function above, and then to the big event switch.
7191 We use a bunch of globals to communicate with our filter function,
7192 that is kind of ugly, but it works.
7194 There is no way to do one display at the time, GTK just does events
7195 from all displays. */
7197 while (gtk_events_pending ())
7199 current_count
= count
;
7200 current_hold_quit
= hold_quit
;
7202 gtk_main_iteration ();
7204 count
= current_count
;
7206 current_hold_quit
= 0;
7208 if (current_finish
== X_EVENT_GOTO_OUT
)
7211 #endif /* USE_GTK */
7213 /* On some systems, an X bug causes Emacs to get no more events
7214 when the window is destroyed. Detect that. (1994.) */
7217 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7218 One XNOOP in 100 loops will make Emacs terminate.
7219 B. Bretthauer, 1994 */
7221 if (x_noop_count
>= 100)
7225 if (next_noop_dpyinfo
== 0)
7226 next_noop_dpyinfo
= x_display_list
;
7228 XNoOp (next_noop_dpyinfo
->display
);
7230 /* Each time we get here, cycle through the displays now open. */
7231 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7235 /* If the focus was just given to an auto-raising frame,
7237 /* ??? This ought to be able to handle more than one such frame. */
7238 if (pending_autoraise_frame
)
7240 x_raise_frame (pending_autoraise_frame
);
7241 pending_autoraise_frame
= 0;
7255 /***********************************************************************
7257 ***********************************************************************/
7259 /* Set clipping for output in glyph row ROW. W is the window in which
7260 we operate. GC is the graphics context to set clipping in.
7262 ROW may be a text row or, e.g., a mode line. Text rows must be
7263 clipped to the interior of the window dedicated to text display,
7264 mode lines must be clipped to the whole window. */
7267 x_clip_to_row (struct window
*w
, struct glyph_row
*row
, int area
, GC gc
)
7269 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7270 XRectangle clip_rect
;
7271 int window_x
, window_y
, window_width
;
7273 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7275 clip_rect
.x
= window_x
;
7276 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7277 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7278 clip_rect
.width
= window_width
;
7279 clip_rect
.height
= row
->visible_height
;
7281 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7285 /* Draw a hollow box cursor on window W in glyph row ROW. */
7288 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7290 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7291 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7292 Display
*dpy
= FRAME_X_DISPLAY (f
);
7295 struct glyph
*cursor_glyph
;
7298 /* Get the glyph the cursor is on. If we can't tell because
7299 the current matrix is invalid or such, give up. */
7300 cursor_glyph
= get_phys_cursor_glyph (w
);
7301 if (cursor_glyph
== NULL
)
7304 /* Compute frame-relative coordinates for phys cursor. */
7305 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7306 wd
= w
->phys_cursor_width
;
7308 /* The foreground of cursor_gc is typically the same as the normal
7309 background color, which can cause the cursor box to be invisible. */
7310 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7311 if (dpyinfo
->scratch_cursor_gc
)
7312 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7314 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7315 GCForeground
, &xgcv
);
7316 gc
= dpyinfo
->scratch_cursor_gc
;
7318 /* Set clipping, draw the rectangle, and reset clipping again. */
7319 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7320 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7321 XSetClipMask (dpy
, gc
, None
);
7325 /* Draw a bar cursor on window W in glyph row ROW.
7327 Implementation note: One would like to draw a bar cursor with an
7328 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7329 Unfortunately, I didn't find a font yet that has this property set.
7333 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7335 struct frame
*f
= XFRAME (w
->frame
);
7336 struct glyph
*cursor_glyph
;
7338 /* If cursor is out of bounds, don't draw garbage. This can happen
7339 in mini-buffer windows when switching between echo area glyphs
7341 cursor_glyph
= get_phys_cursor_glyph (w
);
7342 if (cursor_glyph
== NULL
)
7345 /* If on an image, draw like a normal cursor. That's usually better
7346 visible than drawing a bar, esp. if the image is large so that
7347 the bar might not be in the window. */
7348 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7350 struct glyph_row
*r
;
7351 r
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7352 draw_phys_cursor_glyph (w
, r
, DRAW_CURSOR
);
7356 Display
*dpy
= FRAME_X_DISPLAY (f
);
7357 Window window
= FRAME_X_WINDOW (f
);
7358 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7359 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7360 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7363 /* If the glyph's background equals the color we normally draw
7364 the bars cursor in, the bar cursor in its normal color is
7365 invisible. Use the glyph's foreground color instead in this
7366 case, on the assumption that the glyph's colors are chosen so
7367 that the glyph is legible. */
7368 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7369 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7371 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7372 xgcv
.graphics_exposures
= 0;
7375 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7378 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7379 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7382 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7384 if (kind
== BAR_CURSOR
)
7386 int x
= WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
);
7389 width
= FRAME_CURSOR_WIDTH (f
);
7390 width
= min (cursor_glyph
->pixel_width
, width
);
7392 w
->phys_cursor_width
= width
;
7394 /* If the character under cursor is R2L, draw the bar cursor
7395 on the right of its glyph, rather than on the left. */
7396 if ((cursor_glyph
->resolved_level
& 1) != 0)
7397 x
+= cursor_glyph
->pixel_width
- width
;
7399 XFillRectangle (dpy
, window
, gc
, x
,
7400 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7401 width
, row
->height
);
7405 int dummy_x
, dummy_y
, dummy_h
;
7408 width
= row
->height
;
7410 width
= min (row
->height
, width
);
7412 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7413 &dummy_y
, &dummy_h
);
7415 XFillRectangle (dpy
, window
, gc
,
7416 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7417 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7418 row
->height
- width
),
7419 w
->phys_cursor_width
, width
);
7422 XSetClipMask (dpy
, gc
, None
);
7427 /* RIF: Define cursor CURSOR on frame F. */
7430 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7432 if (!f
->pointer_invisible
7433 && f
->output_data
.x
->current_cursor
!= cursor
)
7434 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7435 f
->output_data
.x
->current_cursor
= cursor
;
7439 /* RIF: Clear area on frame F. */
7442 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7444 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7445 x
, y
, width
, height
, False
);
7447 /* Must queue a redraw, because scroll bars might have been cleared. */
7448 if (FRAME_GTK_WIDGET (f
))
7449 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7454 /* RIF: Draw cursor on window W. */
7457 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
, int y
, int cursor_type
, int cursor_width
, int on_p
, int active_p
)
7459 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7463 w
->phys_cursor_type
= cursor_type
;
7464 w
->phys_cursor_on_p
= 1;
7466 if (glyph_row
->exact_window_width_line_p
7467 && (glyph_row
->reversed_p
7468 ? (w
->phys_cursor
.hpos
< 0)
7469 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7471 glyph_row
->cursor_in_fringe_p
= 1;
7472 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7476 switch (cursor_type
)
7478 case HOLLOW_BOX_CURSOR
:
7479 x_draw_hollow_cursor (w
, glyph_row
);
7482 case FILLED_BOX_CURSOR
:
7483 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7487 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7491 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7495 w
->phys_cursor_width
= 0;
7504 if (w
== XWINDOW (f
->selected_window
))
7505 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7506 xic_set_preeditarea (w
, x
, y
);
7511 XFlush (FRAME_X_DISPLAY (f
));
7518 /* Make the x-window of frame F use the gnu icon bitmap. */
7521 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7523 ptrdiff_t bitmap_id
;
7525 if (FRAME_X_WINDOW (f
) == 0)
7528 /* Free up our existing icon bitmap and mask if any. */
7529 if (f
->output_data
.x
->icon_bitmap
> 0)
7530 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7531 f
->output_data
.x
->icon_bitmap
= 0;
7536 /* Use gtk_window_set_icon_from_file () if available,
7537 It's not restricted to bitmaps */
7538 if (xg_set_icon (f
, file
))
7540 #endif /* USE_GTK */
7541 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7542 x_create_bitmap_mask (f
, bitmap_id
);
7546 /* Create the GNU bitmap and mask if necessary. */
7547 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7553 if (xg_set_icon (f
, xg_default_icon_file
)
7554 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7557 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7559 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7561 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7565 /* If all else fails, use the (black and white) xbm image. */
7568 rc
= x_create_bitmap_from_data (f
, (char *) gnu_xbm_bits
,
7569 gnu_xbm_width
, gnu_xbm_height
);
7573 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7574 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7578 /* The first time we create the GNU bitmap and mask,
7579 this increments the ref-count one extra time.
7580 As a result, the GNU bitmap and mask are never freed.
7581 That way, we don't have to worry about allocating it again. */
7582 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7584 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7587 x_wm_set_icon_pixmap (f
, bitmap_id
);
7588 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7594 /* Make the x-window of frame F use a rectangle with text.
7595 Use ICON_NAME as the text. */
7598 x_text_icon (struct frame
*f
, const char *icon_name
)
7600 if (FRAME_X_WINDOW (f
) == 0)
7605 text
.value
= (unsigned char *) icon_name
;
7606 text
.encoding
= XA_STRING
;
7608 text
.nitems
= strlen (icon_name
);
7609 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7612 if (f
->output_data
.x
->icon_bitmap
> 0)
7613 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7614 f
->output_data
.x
->icon_bitmap
= 0;
7615 x_wm_set_icon_pixmap (f
, 0);
7620 #define X_ERROR_MESSAGE_SIZE 200
7622 /* If non-nil, this should be a string.
7623 It means catch X errors and store the error message in this string.
7625 The reason we use a stack is that x_catch_error/x_uncatch_error can
7626 be called from a signal handler.
7629 struct x_error_message_stack
{
7630 char string
[X_ERROR_MESSAGE_SIZE
];
7632 struct x_error_message_stack
*prev
;
7634 static struct x_error_message_stack
*x_error_message
;
7636 /* An X error handler which stores the error message in
7637 *x_error_message. This is called from x_error_handler if
7638 x_catch_errors is in effect. */
7641 x_error_catcher (Display
*display
, XErrorEvent
*event
)
7643 XGetErrorText (display
, event
->error_code
,
7644 x_error_message
->string
,
7645 X_ERROR_MESSAGE_SIZE
);
7648 /* Begin trapping X errors for display DPY. Actually we trap X errors
7649 for all displays, but DPY should be the display you are actually
7652 After calling this function, X protocol errors no longer cause
7653 Emacs to exit; instead, they are recorded in the string
7654 stored in *x_error_message.
7656 Calling x_check_errors signals an Emacs error if an X error has
7657 occurred since the last call to x_catch_errors or x_check_errors.
7659 Calling x_uncatch_errors resumes the normal error handling. */
7662 x_catch_errors (Display
*dpy
)
7664 struct x_error_message_stack
*data
= xmalloc (sizeof *data
);
7666 /* Make sure any errors from previous requests have been dealt with. */
7670 data
->string
[0] = 0;
7671 data
->prev
= x_error_message
;
7672 x_error_message
= data
;
7675 /* Undo the last x_catch_errors call.
7676 DPY should be the display that was passed to x_catch_errors. */
7679 x_uncatch_errors (void)
7681 struct x_error_message_stack
*tmp
;
7685 /* The display may have been closed before this function is called.
7686 Check if it is still open before calling XSync. */
7687 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7688 XSync (x_error_message
->dpy
, False
);
7690 tmp
= x_error_message
;
7691 x_error_message
= x_error_message
->prev
;
7696 /* If any X protocol errors have arrived since the last call to
7697 x_catch_errors or x_check_errors, signal an Emacs error using
7698 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7701 x_check_errors (Display
*dpy
, const char *format
)
7703 /* Make sure to catch any errors incurred so far. */
7706 if (x_error_message
->string
[0])
7708 char string
[X_ERROR_MESSAGE_SIZE
];
7709 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7710 x_uncatch_errors ();
7711 error (format
, string
);
7715 /* Nonzero if we had any X protocol errors
7716 since we did x_catch_errors on DPY. */
7719 x_had_errors_p (Display
*dpy
)
7721 /* Make sure to catch any errors incurred so far. */
7724 return x_error_message
->string
[0] != 0;
7727 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7730 x_clear_errors (Display
*dpy
)
7732 x_error_message
->string
[0] = 0;
7735 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7736 * idea. --lorentey */
7737 /* Close off all unclosed x_catch_errors calls. */
7740 x_fully_uncatch_errors (void)
7742 while (x_error_message
)
7743 x_uncatch_errors ();
7748 static unsigned int x_wire_count
;
7751 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7756 /* Handle SIGPIPE, which can happen when the connection to a server
7757 simply goes away. SIGPIPE is handled by x_connection_signal.
7758 Don't need to do anything, because the write which caused the
7759 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7760 which will do the appropriate cleanup for us. */
7763 x_connection_signal (int signalnum
) /* If we don't have an argument, */
7764 /* some compilers complain in signal calls. */
7767 /* USG systems forget handlers when they are used;
7768 must reestablish each time */
7769 signal (signalnum
, x_connection_signal
);
7774 /************************************************************************
7776 ************************************************************************/
7778 /* Error message passed to x_connection_closed. */
7780 static char *error_msg
;
7782 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7783 the text of an error message that lead to the connection loss. */
7786 x_connection_closed (Display
*dpy
, const char *error_message
)
7788 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7789 Lisp_Object frame
, tail
;
7790 ptrdiff_t idx
= SPECPDL_INDEX ();
7792 error_msg
= alloca (strlen (error_message
) + 1);
7793 strcpy (error_msg
, error_message
);
7794 handling_signal
= 0;
7796 /* Inhibit redisplay while frames are being deleted. */
7797 specbind (Qinhibit_redisplay
, Qt
);
7801 /* Protect display from being closed when we delete the last
7803 dpyinfo
->reference_count
++;
7804 dpyinfo
->terminal
->reference_count
++;
7807 /* First delete frames whose mini-buffers are on frames
7808 that are on the dead display. */
7809 FOR_EACH_FRAME (tail
, frame
)
7811 Lisp_Object minibuf_frame
;
7813 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7814 if (FRAME_X_P (XFRAME (frame
))
7815 && FRAME_X_P (XFRAME (minibuf_frame
))
7816 && ! EQ (frame
, minibuf_frame
)
7817 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7818 delete_frame (frame
, Qnoelisp
);
7821 /* Now delete all remaining frames on the dead display.
7822 We are now sure none of these is used as the mini-buffer
7823 for another frame that we need to delete. */
7824 FOR_EACH_FRAME (tail
, frame
)
7825 if (FRAME_X_P (XFRAME (frame
))
7826 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7828 /* Set this to t so that delete_frame won't get confused
7829 trying to find a replacement. */
7830 kset_default_minibuffer_frame (FRAME_KBOARD (XFRAME (frame
)), Qt
);
7831 delete_frame (frame
, Qnoelisp
);
7834 /* If DPYINFO is null, this means we didn't open the display in the
7835 first place, so don't try to close it. */
7838 /* We can not call XtCloseDisplay here because it calls XSync.
7839 XSync inside the error handler apparently hangs Emacs. On
7840 current Xt versions, this isn't needed either. */
7842 /* A long-standing GTK bug prevents proper disconnect handling
7843 (https://bugzilla.gnome.org/show_bug.cgi?id=85715). Once,
7844 the resulting Glib error message loop filled a user's disk.
7845 To avoid this, kill Emacs unconditionally on disconnect. */
7846 shut_down_emacs (0, Qnil
);
7847 fprintf (stderr
, "%s\n\
7848 When compiled with GTK, Emacs cannot recover from X disconnects.\n\
7849 This is a GTK bug: https://bugzilla.gnome.org/show_bug.cgi?id=85715\n\
7850 For details, see etc/PROBLEMS.\n",
7853 #endif /* USE_GTK */
7855 /* Indicate that this display is dead. */
7856 dpyinfo
->display
= 0;
7858 dpyinfo
->reference_count
--;
7859 dpyinfo
->terminal
->reference_count
--;
7860 if (dpyinfo
->reference_count
!= 0)
7861 /* We have just closed all frames on this display. */
7866 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7867 Fdelete_terminal (tmp
, Qnoelisp
);
7871 if (terminal_list
== 0)
7873 fprintf (stderr
, "%s\n", error_msg
);
7874 Fkill_emacs (make_number (70));
7878 /* Ordinary stack unwind doesn't deal with these. */
7880 sigunblock (sigmask (SIGIO
));
7882 sigunblock (sigmask (SIGALRM
));
7883 TOTALLY_UNBLOCK_INPUT
;
7885 unbind_to (idx
, Qnil
);
7886 clear_waiting_for_input ();
7888 /* Tell GCC not to suggest attribute 'noreturn' for this function. */
7889 IF_LINT (if (! terminal_list
) return; )
7891 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7892 longjmp), because returning from this function would get us back into
7893 Xlib's code which will directly call `exit'. */
7894 error ("%s", error_msg
);
7897 /* We specifically use it before defining it, so that gcc doesn't inline it,
7898 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7899 static void x_error_quitter (Display
*, XErrorEvent
*);
7901 /* This is the first-level handler for X protocol errors.
7902 It calls x_error_quitter or x_error_catcher. */
7905 x_error_handler (Display
*display
, XErrorEvent
*event
)
7908 if (event
->error_code
== BadMatch
7909 && event
->request_code
== X_SetInputFocus
7910 && event
->minor_code
== 0)
7916 if (x_error_message
)
7917 x_error_catcher (display
, event
);
7919 x_error_quitter (display
, event
);
7923 /* This is the usual handler for X protocol errors.
7924 It kills all frames on the display that we got the error for.
7925 If that was the only one, it prints an error message and kills Emacs. */
7927 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7929 /* On older GCC versions, just putting x_error_quitter
7930 after x_error_handler prevents inlining into the former. */
7932 static void NO_INLINE
7933 x_error_quitter (Display
*display
, XErrorEvent
*event
)
7935 char buf
[256], buf1
[356];
7937 /* Ignore BadName errors. They can happen because of fonts
7938 or colors that are not defined. */
7940 if (event
->error_code
== BadName
)
7943 /* Note that there is no real way portable across R3/R4 to get the
7944 original error handler. */
7946 XGetErrorText (display
, event
->error_code
, buf
, sizeof (buf
));
7947 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7948 buf
, event
->request_code
);
7949 x_connection_closed (display
, buf1
);
7953 /* This is the handler for X IO errors, always.
7954 It kills all frames on the display that we lost touch with.
7955 If that was the only one, it prints an error message and kills Emacs. */
7958 x_io_error_quitter (Display
*display
)
7962 snprintf (buf
, sizeof buf
, "Connection lost to X server `%s'",
7963 DisplayString (display
));
7964 x_connection_closed (display
, buf
);
7968 /* Changing the font of the frame. */
7970 /* Give frame F the font FONT-OBJECT as its default font. The return
7971 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7972 frame. If it is negative, generate a new fontset from
7976 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7978 struct font
*font
= XFONT_OBJECT (font_object
);
7981 fontset
= fontset_from_font (font_object
);
7982 FRAME_FONTSET (f
) = fontset
;
7983 if (FRAME_FONT (f
) == font
)
7984 /* This font is already set in frame F. There's nothing more to
7988 FRAME_FONT (f
) = font
;
7989 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7990 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7991 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
7992 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7994 compute_fringe_widths (f
, 1);
7996 /* Compute the scroll bar width in character columns. */
7997 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7999 int wid
= FRAME_COLUMN_WIDTH (f
);
8000 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8001 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8005 int wid
= FRAME_COLUMN_WIDTH (f
);
8006 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8009 if (FRAME_X_WINDOW (f
) != 0)
8011 /* Don't change the size of a tip frame; there's no point in
8012 doing it because it's done in Fx_show_tip, and it leads to
8013 problems because the tip frame has no widget. */
8014 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8015 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8020 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8023 xic_set_xfontset (f
, SSDATA (fontset_ascii (fontset
)));
8032 /***********************************************************************
8034 ***********************************************************************/
8040 /* XIM destroy callback function, which is called whenever the
8041 connection to input method XIM dies. CLIENT_DATA contains a
8042 pointer to the x_display_info structure corresponding to XIM. */
8045 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
8047 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8048 Lisp_Object frame
, tail
;
8052 /* No need to call XDestroyIC.. */
8053 FOR_EACH_FRAME (tail
, frame
)
8055 struct frame
*f
= XFRAME (frame
);
8056 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8058 FRAME_XIC (f
) = NULL
;
8059 xic_free_xfontset (f
);
8063 /* No need to call XCloseIM. */
8064 dpyinfo
->xim
= NULL
;
8065 XFree (dpyinfo
->xim_styles
);
8069 #endif /* HAVE_X11R6 */
8072 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8073 extern char *XSetIMValues (XIM
, ...);
8076 /* Open the connection to the XIM server on display DPYINFO.
8077 RESOURCE_NAME is the resource name Emacs uses. */
8080 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
8088 XCloseIM (dpyinfo
->xim
);
8089 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8096 XIMCallback destroy
;
8099 /* Get supported styles and XIM values. */
8100 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8103 destroy
.callback
= xim_destroy_callback
;
8104 destroy
.client_data
= (XPointer
)dpyinfo
;
8105 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8111 #endif /* HAVE_XIM */
8112 dpyinfo
->xim
= NULL
;
8116 #ifdef HAVE_X11R6_XIM
8118 /* XIM instantiate callback function, which is called whenever an XIM
8119 server is available. DISPLAY is the display of the XIM.
8120 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8121 when the callback was registered. */
8124 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
8126 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8127 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8129 /* We don't support multiple XIM connections. */
8133 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8135 /* Create XIC for the existing frames on the same display, as long
8136 as they have no XIC. */
8137 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8139 Lisp_Object tail
, frame
;
8142 FOR_EACH_FRAME (tail
, frame
)
8144 struct frame
*f
= XFRAME (frame
);
8147 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8148 if (FRAME_XIC (f
) == NULL
)
8150 create_frame_xic (f
);
8151 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8152 xic_set_statusarea (f
);
8153 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8155 struct window
*w
= XWINDOW (f
->selected_window
);
8156 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8165 #endif /* HAVE_X11R6_XIM */
8168 /* Open a connection to the XIM server on display DPYINFO.
8169 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8170 connection only at the first time. On X11R6, open the connection
8171 in the XIM instantiate callback function. */
8174 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
8176 dpyinfo
->xim
= NULL
;
8180 #ifdef HAVE_X11R6_XIM
8181 struct xim_inst_t
*xim_inst
= xmalloc (sizeof *xim_inst
);
8184 dpyinfo
->xim_callback_data
= xim_inst
;
8185 xim_inst
->dpyinfo
= dpyinfo
;
8186 len
= strlen (resource_name
);
8187 xim_inst
->resource_name
= xmalloc (len
+ 1);
8188 memcpy (xim_inst
->resource_name
, resource_name
, len
+ 1);
8189 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8190 resource_name
, emacs_class
,
8191 xim_instantiate_callback
,
8192 /* This is XPointer in XFree86
8193 but (XPointer *) on Tru64, at
8194 least, hence the configure test. */
8195 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8196 #else /* not HAVE_X11R6_XIM */
8197 xim_open_dpy (dpyinfo
, resource_name
);
8198 #endif /* not HAVE_X11R6_XIM */
8200 #endif /* HAVE_XIM */
8204 /* Close the connection to the XIM server on display DPYINFO. */
8207 xim_close_dpy (struct x_display_info
*dpyinfo
)
8212 #ifdef HAVE_X11R6_XIM
8213 if (dpyinfo
->display
)
8214 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8216 xim_instantiate_callback
, NULL
);
8217 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8218 xfree (dpyinfo
->xim_callback_data
);
8219 #endif /* HAVE_X11R6_XIM */
8220 if (dpyinfo
->display
)
8221 XCloseIM (dpyinfo
->xim
);
8222 dpyinfo
->xim
= NULL
;
8223 XFree (dpyinfo
->xim_styles
);
8225 #endif /* HAVE_XIM */
8228 #endif /* not HAVE_X11R6_XIM */
8232 /* Calculate the absolute position in frame F
8233 from its current recorded position values and gravity. */
8236 x_calc_absolute_position (struct frame
*f
)
8238 int flags
= f
->size_hint_flags
;
8240 /* We have nothing to do if the current position
8241 is already for the top-left corner. */
8242 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8245 /* Treat negative positions as relative to the leftmost bottommost
8246 position that fits on the screen. */
8247 if (flags
& XNegative
)
8248 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8249 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8252 int height
= FRAME_PIXEL_HEIGHT (f
);
8254 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8255 /* Something is fishy here. When using Motif, starting Emacs with
8256 `-g -0-0', the frame appears too low by a few pixels.
8258 This seems to be so because initially, while Emacs is starting,
8259 the column widget's height and the frame's pixel height are
8260 different. The column widget's height is the right one. In
8261 later invocations, when Emacs is up, the frame's pixel height
8264 It's not obvious where the initial small difference comes from.
8265 2000-12-01, gerd. */
8267 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8270 if (flags
& YNegative
)
8271 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8272 - height
+ f
->top_pos
;
8275 /* The left_pos and top_pos
8276 are now relative to the top and left screen edges,
8277 so the flags should correspond. */
8278 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8281 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8282 to really change the position, and 0 when calling from
8283 x_make_frame_visible (in that case, XOFF and YOFF are the current
8284 position values). It is -1 when calling from x_set_frame_parameters,
8285 which means, do adjust for borders but don't change the gravity. */
8288 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8290 int modified_top
, modified_left
;
8292 if (change_gravity
> 0)
8294 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8295 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8299 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8301 f
->size_hint_flags
|= XNegative
;
8303 f
->size_hint_flags
|= YNegative
;
8304 f
->win_gravity
= NorthWestGravity
;
8306 x_calc_absolute_position (f
);
8309 x_wm_set_size_hint (f
, (long) 0, 0);
8311 modified_left
= f
->left_pos
;
8312 modified_top
= f
->top_pos
;
8314 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8316 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8317 than the WM decorations. So we use the calculated offset instead
8318 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8319 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8320 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8323 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8324 modified_left
, modified_top
);
8326 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8327 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8330 /* change_gravity is non-zero when this function is called from Lisp to
8331 programmatically move a frame. In that case, we call
8332 x_check_expected_move to discover if we have a "Type A" or "Type B"
8333 window manager, and, for a "Type A" window manager, adjust the position
8336 We call x_check_expected_move if a programmatic move occurred, and
8337 either the window manager type (A/B) is unknown or it is Type A but we
8338 need to compute the top/left offset adjustment for this frame. */
8340 if (change_gravity
!= 0 &&
8341 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8342 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8343 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8344 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8345 x_check_expected_move (f
, modified_left
, modified_top
);
8350 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8351 on the root window for frame F contains ATOMNAME.
8352 This is how a WM check shall be done according to the Window Manager
8353 Specification/Extended Window Manager Hints at
8354 http://freedesktop.org/wiki/Specifications/wm-spec. */
8357 wm_supports (struct frame
*f
, Atom want_atom
)
8360 unsigned long actual_size
, bytes_remaining
;
8361 int i
, rc
, actual_format
;
8362 Window wmcheck_window
;
8363 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8364 Window target_window
= dpyinfo
->root_window
;
8365 long max_len
= 65536;
8366 Display
*dpy
= FRAME_X_DISPLAY (f
);
8367 unsigned char *tmp_data
= NULL
;
8368 Atom target_type
= XA_WINDOW
;
8372 x_catch_errors (dpy
);
8373 rc
= XGetWindowProperty (dpy
, target_window
,
8374 dpyinfo
->Xatom_net_supporting_wm_check
,
8375 0, max_len
, False
, target_type
,
8376 &actual_type
, &actual_format
, &actual_size
,
8377 &bytes_remaining
, &tmp_data
);
8379 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8381 if (tmp_data
) XFree (tmp_data
);
8382 x_uncatch_errors ();
8387 wmcheck_window
= *(Window
*) tmp_data
;
8390 /* Check if window exists. */
8391 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8393 if (x_had_errors_p (dpy
))
8395 x_uncatch_errors ();
8400 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8402 /* Window changed, reload atoms */
8403 if (dpyinfo
->net_supported_atoms
!= NULL
)
8404 XFree (dpyinfo
->net_supported_atoms
);
8405 dpyinfo
->net_supported_atoms
= NULL
;
8406 dpyinfo
->nr_net_supported_atoms
= 0;
8407 dpyinfo
->net_supported_window
= 0;
8409 target_type
= XA_ATOM
;
8411 rc
= XGetWindowProperty (dpy
, target_window
,
8412 dpyinfo
->Xatom_net_supported
,
8413 0, max_len
, False
, target_type
,
8414 &actual_type
, &actual_format
, &actual_size
,
8415 &bytes_remaining
, &tmp_data
);
8417 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8419 if (tmp_data
) XFree (tmp_data
);
8420 x_uncatch_errors ();
8425 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8426 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8427 dpyinfo
->net_supported_window
= wmcheck_window
;
8432 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8433 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8435 x_uncatch_errors ();
8442 set_wm_state (Lisp_Object frame
, int add
, Atom atom
, Atom value
)
8444 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (frame
));
8446 x_send_client_event (frame
, make_number (0), frame
,
8447 dpyinfo
->Xatom_net_wm_state
,
8449 /* 1 = add, 0 = remove */
8451 (make_number (add
? 1 : 0),
8453 (make_fixnum_or_float (atom
),
8455 ? Fcons (make_fixnum_or_float (value
), Qnil
)
8460 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8463 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8465 XSETFRAME (frame
, f
);
8467 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8468 dpyinfo
->Xatom_net_wm_state_sticky
, None
);
8471 /* Return the current _NET_WM_STATE.
8472 SIZE_STATE is set to one of the FULLSCREEN_* values.
8473 STICKY is set to 1 if the sticky state is set, 0 if not.
8475 Return non-zero if we are not hidden, zero if we are. */
8478 get_current_wm_state (struct frame
*f
,
8484 unsigned long actual_size
, bytes_remaining
;
8485 int i
, rc
, actual_format
, is_hidden
= 0;
8486 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8487 long max_len
= 65536;
8488 Display
*dpy
= FRAME_X_DISPLAY (f
);
8489 unsigned char *tmp_data
= NULL
;
8490 Atom target_type
= XA_ATOM
;
8493 *size_state
= FULLSCREEN_NONE
;
8496 x_catch_errors (dpy
);
8497 rc
= XGetWindowProperty (dpy
, window
, dpyinfo
->Xatom_net_wm_state
,
8498 0, max_len
, False
, target_type
,
8499 &actual_type
, &actual_format
, &actual_size
,
8500 &bytes_remaining
, &tmp_data
);
8502 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8504 if (tmp_data
) XFree (tmp_data
);
8505 x_uncatch_errors ();
8507 return ! f
->iconified
;
8510 x_uncatch_errors ();
8512 for (i
= 0; i
< actual_size
; ++i
)
8514 Atom a
= ((Atom
*)tmp_data
)[i
];
8515 if (a
== dpyinfo
->Xatom_net_wm_state_hidden
)
8518 f
->output_data
.x
->net_wm_state_hidden_seen
= 1;
8520 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8522 if (*size_state
== FULLSCREEN_HEIGHT
)
8523 *size_state
= FULLSCREEN_MAXIMIZED
;
8525 *size_state
= FULLSCREEN_WIDTH
;
8527 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8529 if (*size_state
== FULLSCREEN_WIDTH
)
8530 *size_state
= FULLSCREEN_MAXIMIZED
;
8532 *size_state
= FULLSCREEN_HEIGHT
;
8534 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen
)
8535 *size_state
= FULLSCREEN_BOTH
;
8536 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8540 if (tmp_data
) XFree (tmp_data
);
8545 /* Do fullscreen as specified in extended window manager hints */
8548 do_ewmh_fullscreen (struct frame
*f
)
8550 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8551 int have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state
);
8554 (void)get_current_wm_state (f
, FRAME_OUTER_WINDOW (f
), &cur
, &dummy
);
8556 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8557 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8559 have_net_atom
= wm_supports (f
, dpyinfo
->Xatom_net_wm_state_fullscreen
);
8561 if (have_net_atom
&& cur
!= f
->want_fullscreen
)
8565 XSETFRAME (frame
, f
);
8567 /* Keep number of calls to set_wm_state as low as possible.
8568 Some window managers, or possible Gtk+, hangs when too many
8569 are sent at once. */
8570 switch (f
->want_fullscreen
)
8572 case FULLSCREEN_BOTH
:
8573 if (cur
== FULLSCREEN_WIDTH
|| cur
== FULLSCREEN_MAXIMIZED
8574 || cur
== FULLSCREEN_HEIGHT
)
8575 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8576 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8577 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8579 case FULLSCREEN_WIDTH
:
8580 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_HEIGHT
8581 || cur
== FULLSCREEN_MAXIMIZED
)
8582 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8583 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8584 if (cur
!= FULLSCREEN_MAXIMIZED
)
8585 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
, None
);
8587 case FULLSCREEN_HEIGHT
:
8588 if (cur
== FULLSCREEN_BOTH
|| cur
== FULLSCREEN_WIDTH
8589 || cur
== FULLSCREEN_MAXIMIZED
)
8590 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
,
8591 dpyinfo
->Xatom_net_wm_state_maximized_horz
);
8592 if (cur
!= FULLSCREEN_MAXIMIZED
)
8593 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_vert
, None
);
8595 case FULLSCREEN_MAXIMIZED
:
8596 if (cur
== FULLSCREEN_BOTH
)
8597 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8598 set_wm_state (frame
, 1, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8599 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8601 case FULLSCREEN_NONE
:
8602 if (cur
== FULLSCREEN_BOTH
)
8603 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_fullscreen
, None
);
8605 set_wm_state (frame
, 0, dpyinfo
->Xatom_net_wm_state_maximized_horz
,
8606 dpyinfo
->Xatom_net_wm_state_maximized_vert
);
8609 f
->want_fullscreen
= FULLSCREEN_NONE
;
8613 return have_net_atom
;
8617 XTfullscreen_hook (FRAME_PTR f
)
8619 if (f
->async_visible
)
8622 x_check_fullscreen (f
);
8630 x_handle_net_wm_state (struct frame
*f
, XPropertyEvent
*event
)
8632 int value
= FULLSCREEN_NONE
;
8635 int not_hidden
= get_current_wm_state (f
, event
->window
, &value
, &sticky
);
8640 case FULLSCREEN_WIDTH
:
8643 case FULLSCREEN_HEIGHT
:
8646 case FULLSCREEN_BOTH
:
8649 case FULLSCREEN_MAXIMIZED
:
8654 store_frame_param (f
, Qfullscreen
, lval
);
8655 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8660 /* Check if we need to resize the frame due to a fullscreen request.
8661 If so needed, resize the frame. */
8663 x_check_fullscreen (struct frame
*f
)
8665 if (do_ewmh_fullscreen (f
))
8668 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8669 return; /* Only fullscreen without WM or with EWM hints (above). */
8671 /* Setting fullscreen to nil doesn't do anything. We could save the
8672 last non-fullscreen size and restore it, but it seems like a
8673 lot of work for this unusual case (no window manager running). */
8675 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8677 int width
= FRAME_PIXEL_WIDTH (f
), height
= FRAME_PIXEL_HEIGHT (f
);
8678 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8680 switch (f
->want_fullscreen
)
8682 /* No difference between these two when there is no WM */
8683 case FULLSCREEN_BOTH
:
8684 case FULLSCREEN_MAXIMIZED
:
8685 width
= x_display_pixel_width (dpyinfo
);
8686 height
= x_display_pixel_height (dpyinfo
);
8688 case FULLSCREEN_WIDTH
:
8689 width
= x_display_pixel_width (dpyinfo
);
8691 case FULLSCREEN_HEIGHT
:
8692 height
= x_display_pixel_height (dpyinfo
);
8695 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8700 /* This function is called by x_set_offset to determine whether the window
8701 manager interfered with the positioning of the frame. Type A window
8702 managers position the surrounding window manager decorations a small
8703 amount above and left of the user-supplied position. Type B window
8704 managers position the surrounding window manager decorations at the
8705 user-specified position. If we detect a Type A window manager, we
8706 compensate by moving the window right and down by the proper amount. */
8709 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8711 int current_left
= 0, current_top
= 0;
8713 /* x_real_positions returns the left and top offsets of the outermost
8714 window manager window around the frame. */
8716 x_real_positions (f
, ¤t_left
, ¤t_top
);
8718 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8720 /* It's a "Type A" window manager. */
8725 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8726 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8727 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8729 /* Now fix the mispositioned frame's location. */
8731 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8732 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8734 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8735 adjusted_left
, adjusted_top
);
8737 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8740 /* It's a "Type B" window manager. We don't have to adjust the
8741 frame's position. */
8743 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8747 /* Wait for XGetGeometry to return up-to-date position information for a
8748 recently-moved frame. Call this immediately after calling XMoveWindow.
8749 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8750 frame has been moved to, so we use a fuzzy position comparison instead
8751 of an exact comparison. */
8754 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8758 while (count
++ < 50)
8760 int current_left
= 0, current_top
= 0;
8762 /* In theory, this call to XSync only needs to happen once, but in
8763 practice, it doesn't seem to work, hence the need for the surrounding
8766 XSync (FRAME_X_DISPLAY (f
), False
);
8767 x_real_positions (f
, ¤t_left
, ¤t_top
);
8771 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8774 if (eabs (current_left
- left
) <= 10
8775 && eabs (current_top
- top
) <= 40)
8778 else if (current_left
== left
&& current_top
== top
)
8782 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8783 will then return up-to-date position info. */
8785 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8789 /* Wait for an event on frame F matching EVENTTYPE. */
8791 x_wait_for_event (struct frame
*f
, int eventtype
)
8793 int level
= interrupt_input_blocked
;
8796 EMACS_TIME tmo
, tmo_at
, time_now
;
8797 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8799 pending_event_wait
.f
= f
;
8800 pending_event_wait
.eventtype
= eventtype
;
8802 /* Set timeout to 0.1 second. Hopefully not noticeable.
8803 Maybe it should be configurable. */
8804 tmo
= make_emacs_time (0, 100 * 1000 * 1000);
8805 tmo_at
= add_emacs_time (current_emacs_time (), tmo
);
8807 while (pending_event_wait
.eventtype
)
8809 interrupt_input_pending
= 1;
8810 TOTALLY_UNBLOCK_INPUT
;
8811 /* XTread_socket is called after unblock. */
8813 interrupt_input_blocked
= level
;
8818 time_now
= current_emacs_time ();
8819 if (EMACS_TIME_LT (tmo_at
, time_now
))
8822 tmo
= sub_emacs_time (tmo_at
, time_now
);
8823 if (pselect (fd
+ 1, &fds
, NULL
, NULL
, &tmo
, NULL
) == 0)
8824 break; /* Timeout */
8826 pending_event_wait
.f
= 0;
8827 pending_event_wait
.eventtype
= 0;
8831 /* Change the size of frame F's X window to COLS/ROWS in the case F
8832 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8833 top-left-corner window gravity for this size change and subsequent
8834 size changes. Otherwise we leave the window gravity unchanged. */
8837 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8839 int pixelwidth
, pixelheight
;
8841 check_frame_size (f
, &rows
, &cols
);
8842 f
->scroll_bar_actual_width
8843 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8845 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8847 compute_fringe_widths (f
, 0);
8849 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8850 + FRAME_TOOLBAR_WIDTH (f
);
8851 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8852 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8854 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8855 x_wm_set_size_hint (f
, (long) 0, 0);
8856 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8857 pixelwidth
, pixelheight
);
8860 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8861 receive in the ConfigureNotify event; if we get what we asked
8862 for, then the event won't cause the screen to become garbaged, so
8863 we have to make sure to do it here. */
8864 SET_FRAME_GARBAGED (f
);
8866 /* Now, strictly speaking, we can't be sure that this is accurate,
8867 but the window manager will get around to dealing with the size
8868 change request eventually, and we'll hear how it went when the
8869 ConfigureNotify event gets here.
8871 We could just not bother storing any of this information here,
8872 and let the ConfigureNotify event set everything up, but that
8873 might be kind of confusing to the Lisp code, since size changes
8874 wouldn't be reported in the frame parameters until some random
8875 point in the future when the ConfigureNotify event arrives.
8877 We pass 1 for DELAY since we can't run Lisp code inside of
8880 /* But the ConfigureNotify may in fact never arrive, and then this is
8881 not right if the frame is visible. Instead wait (with timeout)
8882 for the ConfigureNotify. */
8883 if (f
->async_visible
)
8884 x_wait_for_event (f
, ConfigureNotify
);
8887 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8888 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8889 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8895 /* Call this to change the size of frame F's x-window.
8896 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8897 for this size change and subsequent size changes.
8898 Otherwise we leave the window gravity unchanged. */
8901 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8905 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8909 /* When the frame is maximized/fullscreen or running under for
8910 example Xmonad, x_set_window_size_1 will be a no-op.
8911 In that case, the right thing to do is extend rows/cols to
8912 the current frame size. We do that first if x_set_window_size_1
8913 turns out to not be a no-op (there is no way to know).
8914 The size will be adjusted again if the frame gets a
8915 ConfigureNotify event as a result of x_set_window_size. */
8916 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8917 #ifdef USE_X_TOOLKIT
8918 /* The menu bar is not part of text lines. The tool bar
8920 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8922 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8923 /* Update f->scroll_bar_actual_width because it is used in
8924 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8925 f
->scroll_bar_actual_width
8926 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8927 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8928 change_frame_size (f
, r
, c
, 0, 1, 0);
8932 if (FRAME_GTK_WIDGET (f
))
8933 xg_frame_set_char_size (f
, cols
, rows
);
8935 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8936 #else /* not USE_GTK */
8938 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8940 #endif /* not USE_GTK */
8942 /* If cursor was outside the new size, mark it as off. */
8943 mark_window_cursors_off (XWINDOW (f
->root_window
));
8945 /* Clear out any recollection of where the mouse highlighting was,
8946 since it might be in a place that's outside the new frame size.
8947 Actually checking whether it is outside is a pain in the neck,
8948 so don't try--just let the highlighting be done afresh with new size. */
8949 cancel_mouse_face (f
);
8954 /* Mouse warping. */
8957 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8961 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8962 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8964 if (pix_x
< 0) pix_x
= 0;
8965 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8967 if (pix_y
< 0) pix_y
= 0;
8968 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8972 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8973 0, 0, 0, 0, pix_x
, pix_y
);
8977 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8980 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8984 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8985 0, 0, 0, 0, pix_x
, pix_y
);
8989 /* Raise frame F. */
8992 x_raise_frame (struct frame
*f
)
8995 if (f
->async_visible
)
8996 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8998 XFlush (FRAME_X_DISPLAY (f
));
9002 /* Lower frame F. */
9005 x_lower_frame (struct frame
*f
)
9007 if (f
->async_visible
)
9010 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9011 XFlush (FRAME_X_DISPLAY (f
));
9016 /* Request focus with XEmbed */
9019 xembed_request_focus (FRAME_PTR f
)
9021 /* See XEmbed Protocol Specification at
9022 http://freedesktop.org/wiki/Specifications/xembed-spec */
9023 if (f
->async_visible
)
9024 xembed_send_message (f
, CurrentTime
,
9025 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
9028 /* Activate frame with Extended Window Manager Hints */
9031 x_ewmh_activate_frame (FRAME_PTR f
)
9033 /* See Window Manager Specification/Extended Window Manager Hints at
9034 http://freedesktop.org/wiki/Specifications/wm-spec */
9036 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9037 if (f
->async_visible
&& wm_supports (f
, dpyinfo
->Xatom_net_active_window
))
9040 XSETFRAME (frame
, f
);
9041 x_send_client_event (frame
, make_number (0), frame
,
9042 dpyinfo
->Xatom_net_active_window
,
9044 Fcons (make_number (1),
9045 Fcons (make_number (last_user_time
),
9051 XTframe_raise_lower (FRAME_PTR f
, int raise_flag
)
9059 /* XEmbed implementation. */
9061 #if defined USE_X_TOOLKIT || ! defined USE_GTK
9063 /* XEmbed implementation. */
9065 #define XEMBED_VERSION 0
9068 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
9070 unsigned long data
[2];
9071 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9073 data
[0] = XEMBED_VERSION
;
9076 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9077 dpyinfo
->Xatom_XEMBED_INFO
, dpyinfo
->Xatom_XEMBED_INFO
,
9078 32, PropModeReplace
, (unsigned char *) data
, 2);
9080 #endif /* defined USE_X_TOOLKIT || ! defined USE_GTK */
9083 xembed_send_message (struct frame
*f
, Time t
, enum xembed_message msg
,
9084 long int detail
, long int data1
, long int data2
)
9088 event
.xclient
.type
= ClientMessage
;
9089 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9090 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9091 event
.xclient
.format
= 32;
9092 event
.xclient
.data
.l
[0] = t
;
9093 event
.xclient
.data
.l
[1] = msg
;
9094 event
.xclient
.data
.l
[2] = detail
;
9095 event
.xclient
.data
.l
[3] = data1
;
9096 event
.xclient
.data
.l
[4] = data2
;
9098 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9099 False
, NoEventMask
, &event
);
9100 XSync (FRAME_X_DISPLAY (f
), False
);
9103 /* Change of visibility. */
9105 /* This tries to wait until the frame is really visible.
9106 However, if the window manager asks the user where to position
9107 the frame, this will return before the user finishes doing that.
9108 The frame will not actually be visible at that time,
9109 but it will become visible later when the window manager
9110 finishes with it. */
9113 x_make_frame_visible (struct frame
*f
)
9116 int original_top
, original_left
;
9117 int retry_count
= 2;
9123 type
= x_icon_type (f
);
9125 x_bitmap_icon (f
, type
);
9127 if (! FRAME_VISIBLE_P (f
))
9129 /* We test FRAME_GARBAGED_P here to make sure we don't
9130 call x_set_offset a second time
9131 if we get to x_make_frame_visible a second time
9132 before the window gets really visible. */
9133 if (! FRAME_ICONIFIED_P (f
)
9134 && ! FRAME_X_EMBEDDED_P (f
)
9135 && ! f
->output_data
.x
->asked_for_visible
)
9136 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9138 f
->output_data
.x
->asked_for_visible
= 1;
9140 if (! EQ (Vx_no_window_manager
, Qt
))
9141 x_wm_set_window_state (f
, NormalState
);
9142 #ifdef USE_X_TOOLKIT
9143 if (FRAME_X_EMBEDDED_P (f
))
9144 xembed_set_info (f
, XEMBED_MAPPED
);
9147 /* This was XtPopup, but that did nothing for an iconified frame. */
9148 XtMapWidget (f
->output_data
.x
->widget
);
9150 #else /* not USE_X_TOOLKIT */
9152 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9153 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9155 if (FRAME_X_EMBEDDED_P (f
))
9156 xembed_set_info (f
, XEMBED_MAPPED
);
9158 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9159 #endif /* not USE_GTK */
9160 #endif /* not USE_X_TOOLKIT */
9163 XFlush (FRAME_X_DISPLAY (f
));
9165 /* Synchronize to ensure Emacs knows the frame is visible
9166 before we do anything else. We do this loop with input not blocked
9167 so that incoming events are handled. */
9171 /* This must be before UNBLOCK_INPUT
9172 since events that arrive in response to the actions above
9173 will set it when they are handled. */
9174 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9176 original_left
= f
->left_pos
;
9177 original_top
= f
->top_pos
;
9179 /* This must come after we set COUNT. */
9182 /* We unblock here so that arriving X events are processed. */
9184 /* Now move the window back to where it was "supposed to be".
9185 But don't do it if the gravity is negative.
9186 When the gravity is negative, this uses a position
9187 that is 3 pixels too low. Perhaps that's really the border width.
9189 Don't do this if the window has never been visible before,
9190 because the window manager may choose the position
9191 and we don't want to override it. */
9193 if (! FRAME_VISIBLE_P (f
)
9194 && ! FRAME_ICONIFIED_P (f
)
9195 && ! FRAME_X_EMBEDDED_P (f
)
9196 && f
->win_gravity
== NorthWestGravity
9197 && previously_visible
)
9201 unsigned int width
, height
, border
, depth
;
9205 /* On some window managers (such as FVWM) moving an existing
9206 window, even to the same place, causes the window manager
9207 to introduce an offset. This can cause the window to move
9208 to an unexpected location. Check the geometry (a little
9209 slow here) and then verify that the window is in the right
9210 place. If the window is not in the right place, move it
9211 there, and take the potential window manager hit. */
9212 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9213 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9215 if (original_left
!= x
|| original_top
!= y
)
9216 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9217 original_left
, original_top
);
9222 XSETFRAME (frame
, f
);
9224 /* Wait until the frame is visible. Process X events until a
9225 MapNotify event has been seen, or until we think we won't get a
9226 MapNotify at all.. */
9227 for (count
= input_signal_count
+ 10;
9228 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9230 /* Force processing of queued events. */
9233 /* Machines that do polling rather than SIGIO have been
9234 observed to go into a busy-wait here. So we'll fake an
9235 alarm signal to let the handler know that there's something
9236 to be read. We used to raise a real alarm, but it seems
9237 that the handler isn't always enabled here. This is
9239 if (input_polling_used ())
9241 /* It could be confusing if a real alarm arrives while
9242 processing the fake one. Turn it off and let the
9243 handler reset it. */
9244 int old_poll_suppress_count
= poll_suppress_count
;
9245 poll_suppress_count
= 1;
9246 poll_for_input_1 ();
9247 poll_suppress_count
= old_poll_suppress_count
;
9250 /* See if a MapNotify event has been processed. */
9251 FRAME_SAMPLE_VISIBILITY (f
);
9256 (let ((f (selected-frame)))
9260 the frame is not raised with various window managers on
9261 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9262 unknown reason, the call to XtMapWidget is completely ignored.
9263 Mapping the widget a second time works. */
9265 if (!FRAME_VISIBLE_P (f
) && --retry_count
!= 0)
9270 /* Change from mapped state to withdrawn state. */
9272 /* Make the frame visible (mapped and not iconified). */
9275 x_make_frame_invisible (struct frame
*f
)
9279 /* Use the frame's outermost window, not the one we normally draw on. */
9280 window
= FRAME_OUTER_WINDOW (f
);
9282 /* Don't keep the highlight on an invisible frame. */
9283 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9284 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9288 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9289 that the current position of the window is user-specified, rather than
9290 program-specified, so that when the window is mapped again, it will be
9291 placed at the same location, without forcing the user to position it
9292 by hand again (they have already done that once for this window.) */
9293 x_wm_set_size_hint (f
, (long) 0, 1);
9296 if (FRAME_GTK_OUTER_WIDGET (f
))
9297 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9300 if (FRAME_X_EMBEDDED_P (f
))
9301 xembed_set_info (f
, 0);
9306 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9307 DefaultScreen (FRAME_X_DISPLAY (f
))))
9309 UNBLOCK_INPUT_RESIGNAL
;
9310 error ("Can't notify window manager of window withdrawal");
9314 /* We can't distinguish this from iconification
9315 just by the event that we get from the server.
9316 So we can't win using the usual strategy of letting
9317 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9318 and synchronize with the server to make sure we agree. */
9320 FRAME_ICONIFIED_P (f
) = 0;
9321 f
->async_visible
= 0;
9322 f
->async_iconified
= 0;
9329 /* Change window state from mapped to iconified. */
9332 x_iconify_frame (struct frame
*f
)
9334 #ifdef USE_X_TOOLKIT
9339 /* Don't keep the highlight on an invisible frame. */
9340 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9341 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9343 if (f
->async_iconified
)
9348 FRAME_SAMPLE_VISIBILITY (f
);
9350 type
= x_icon_type (f
);
9352 x_bitmap_icon (f
, type
);
9354 #if defined (USE_GTK)
9355 if (FRAME_GTK_OUTER_WIDGET (f
))
9357 if (! FRAME_VISIBLE_P (f
))
9358 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9360 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9363 f
->async_iconified
= 1;
9364 f
->async_visible
= 0;
9370 #ifdef USE_X_TOOLKIT
9372 if (! FRAME_VISIBLE_P (f
))
9374 if (! EQ (Vx_no_window_manager
, Qt
))
9375 x_wm_set_window_state (f
, IconicState
);
9376 /* This was XtPopup, but that did nothing for an iconified frame. */
9377 XtMapWidget (f
->output_data
.x
->widget
);
9378 /* The server won't give us any event to indicate
9379 that an invisible frame was changed to an icon,
9380 so we have to record it here. */
9383 f
->async_iconified
= 1;
9384 f
->async_visible
= 0;
9389 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9390 XtWindow (f
->output_data
.x
->widget
),
9391 DefaultScreen (FRAME_X_DISPLAY (f
)));
9395 error ("Can't notify window manager of iconification");
9397 f
->async_iconified
= 1;
9398 f
->async_visible
= 0;
9402 XFlush (FRAME_X_DISPLAY (f
));
9404 #else /* not USE_X_TOOLKIT */
9406 /* Make sure the X server knows where the window should be positioned,
9407 in case the user deiconifies with the window manager. */
9408 if (! FRAME_VISIBLE_P (f
)
9409 && ! FRAME_ICONIFIED_P (f
)
9410 && ! FRAME_X_EMBEDDED_P (f
))
9411 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9413 /* Since we don't know which revision of X we're running, we'll use both
9414 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9416 /* X11R4: send a ClientMessage to the window manager using the
9417 WM_CHANGE_STATE type. */
9421 msg
.xclient
.window
= FRAME_X_WINDOW (f
);
9422 msg
.xclient
.type
= ClientMessage
;
9423 msg
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9424 msg
.xclient
.format
= 32;
9425 msg
.xclient
.data
.l
[0] = IconicState
;
9427 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9428 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9430 SubstructureRedirectMask
| SubstructureNotifyMask
,
9433 UNBLOCK_INPUT_RESIGNAL
;
9434 error ("Can't notify window manager of iconification");
9438 /* X11R3: set the initial_state field of the window manager hints to
9440 x_wm_set_window_state (f
, IconicState
);
9442 if (!FRAME_VISIBLE_P (f
))
9444 /* If the frame was withdrawn, before, we must map it. */
9445 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9448 f
->async_iconified
= 1;
9449 f
->async_visible
= 0;
9451 XFlush (FRAME_X_DISPLAY (f
));
9453 #endif /* not USE_X_TOOLKIT */
9457 /* Free X resources of frame F. */
9460 x_free_frame_resources (struct frame
*f
)
9462 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9463 Mouse_HLInfo
*hlinfo
= &dpyinfo
->mouse_highlight
;
9464 #ifdef USE_X_TOOLKIT
9466 struct scroll_bar
*b
;
9471 /* If a display connection is dead, don't try sending more
9472 commands to the X server. */
9473 if (dpyinfo
->display
)
9475 /* We must free faces before destroying windows because some
9476 font-driver (e.g. xft) access a window while finishing a
9478 if (FRAME_FACE_CACHE (f
))
9479 free_frame_faces (f
);
9481 if (f
->output_data
.x
->icon_desc
)
9482 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9484 #ifdef USE_X_TOOLKIT
9485 /* Explicitly destroy the scroll bars of the frame. Without
9486 this, we get "BadDrawable" errors from the toolkit later on,
9487 presumably from expose events generated for the disappearing
9488 toolkit scroll bars. */
9489 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9491 b
= XSCROLL_BAR (bar
);
9492 x_scroll_bar_remove (b
);
9501 #ifdef USE_X_TOOLKIT
9502 if (f
->output_data
.x
->widget
)
9504 XtDestroyWidget (f
->output_data
.x
->widget
);
9505 f
->output_data
.x
->widget
= NULL
;
9507 /* Tooltips don't have widgets, only a simple X window, even if
9508 we are using a toolkit. */
9509 else if (FRAME_X_WINDOW (f
))
9510 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9512 free_frame_menubar (f
);
9513 #else /* !USE_X_TOOLKIT */
9516 xg_free_frame_widgets (f
);
9517 #endif /* USE_GTK */
9519 if (FRAME_X_WINDOW (f
))
9520 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9521 #endif /* !USE_X_TOOLKIT */
9523 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9524 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9525 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9526 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9527 unload_color (f
, f
->output_data
.x
->border_pixel
);
9528 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9530 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9531 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9532 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9533 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9534 #ifdef USE_TOOLKIT_SCROLL_BARS
9535 /* Scrollbar shadow colors. */
9536 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9537 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9538 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9539 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9540 #endif /* USE_TOOLKIT_SCROLL_BARS */
9541 if (f
->output_data
.x
->white_relief
.allocated_p
)
9542 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9543 if (f
->output_data
.x
->black_relief
.allocated_p
)
9544 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9547 XFlush (FRAME_X_DISPLAY (f
));
9550 xfree (f
->output_data
.x
->saved_menu_event
);
9551 xfree (f
->output_data
.x
);
9552 f
->output_data
.x
= NULL
;
9554 if (f
== dpyinfo
->x_focus_frame
)
9555 dpyinfo
->x_focus_frame
= 0;
9556 if (f
== dpyinfo
->x_focus_event_frame
)
9557 dpyinfo
->x_focus_event_frame
= 0;
9558 if (f
== dpyinfo
->x_highlight_frame
)
9559 dpyinfo
->x_highlight_frame
= 0;
9561 if (f
== hlinfo
->mouse_face_mouse_frame
)
9563 hlinfo
->mouse_face_beg_row
9564 = hlinfo
->mouse_face_beg_col
= -1;
9565 hlinfo
->mouse_face_end_row
9566 = hlinfo
->mouse_face_end_col
= -1;
9567 hlinfo
->mouse_face_window
= Qnil
;
9568 hlinfo
->mouse_face_deferred_gc
= 0;
9569 hlinfo
->mouse_face_mouse_frame
= 0;
9576 /* Destroy the X window of frame F. */
9579 x_destroy_window (struct frame
*f
)
9581 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9583 /* If a display connection is dead, don't try sending more
9584 commands to the X server. */
9585 if (dpyinfo
->display
!= 0)
9586 x_free_frame_resources (f
);
9588 dpyinfo
->reference_count
--;
9592 /* Setting window manager hints. */
9594 /* Set the normal size hints for the window manager, for frame F.
9595 FLAGS is the flags word to use--or 0 meaning preserve the flags
9596 that the window now has.
9597 If USER_POSITION is nonzero, we set the USPosition
9598 flag (this is useful when FLAGS is 0).
9599 The GTK version is in gtkutils.c */
9603 x_wm_set_size_hint (struct frame
*f
, long flags
, int user_position
)
9605 XSizeHints size_hints
;
9606 Window window
= FRAME_OUTER_WINDOW (f
);
9608 #ifdef USE_X_TOOLKIT
9609 if (f
->output_data
.x
->widget
)
9611 widget_update_wm_size_hints (f
->output_data
.x
->widget
);
9616 /* Setting PMaxSize caused various problems. */
9617 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9619 size_hints
.x
= f
->left_pos
;
9620 size_hints
.y
= f
->top_pos
;
9622 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9623 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9625 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9626 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9627 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9628 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9629 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9630 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9632 /* Calculate the base and minimum sizes. */
9634 int base_width
, base_height
;
9635 int min_rows
= 0, min_cols
= 0;
9637 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9638 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9640 check_frame_size (f
, &min_rows
, &min_cols
);
9642 /* The window manager uses the base width hints to calculate the
9643 current number of rows and columns in the frame while
9644 resizing; min_width and min_height aren't useful for this
9645 purpose, since they might not give the dimensions for a
9646 zero-row, zero-column frame.
9648 We use the base_width and base_height members if we have
9649 them; otherwise, we set the min_width and min_height members
9650 to the size for a zero x zero frame. */
9652 size_hints
.flags
|= PBaseSize
;
9653 size_hints
.base_width
= base_width
;
9654 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9655 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9656 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9659 /* If we don't need the old flags, we don't need the old hint at all. */
9662 size_hints
.flags
|= flags
;
9667 XSizeHints hints
; /* Sometimes I hate X Windows... */
9668 long supplied_return
;
9671 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9675 size_hints
.flags
|= flags
;
9680 if (hints
.flags
& PSize
)
9681 size_hints
.flags
|= PSize
;
9682 if (hints
.flags
& PPosition
)
9683 size_hints
.flags
|= PPosition
;
9684 if (hints
.flags
& USPosition
)
9685 size_hints
.flags
|= USPosition
;
9686 if (hints
.flags
& USSize
)
9687 size_hints
.flags
|= USSize
;
9694 size_hints
.win_gravity
= f
->win_gravity
;
9695 size_hints
.flags
|= PWinGravity
;
9699 size_hints
.flags
&= ~ PPosition
;
9700 size_hints
.flags
|= USPosition
;
9702 #endif /* PWinGravity */
9704 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9706 #endif /* not USE_GTK */
9708 /* Used for IconicState or NormalState */
9711 x_wm_set_window_state (struct frame
*f
, int state
)
9713 #ifdef USE_X_TOOLKIT
9716 XtSetArg (al
[0], XtNinitialState
, state
);
9717 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9718 #else /* not USE_X_TOOLKIT */
9719 Window window
= FRAME_X_WINDOW (f
);
9721 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9722 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9724 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9725 #endif /* not USE_X_TOOLKIT */
9729 x_wm_set_icon_pixmap (struct frame
*f
, ptrdiff_t pixmap_id
)
9731 Pixmap icon_pixmap
, icon_mask
;
9733 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9734 Window window
= FRAME_OUTER_WINDOW (f
);
9739 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9740 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9741 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9742 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9746 /* It seems there is no way to turn off use of an icon
9754 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9758 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9762 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9763 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9764 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9765 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9768 #else /* not USE_X_TOOLKIT && not USE_GTK */
9770 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9771 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9773 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9777 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9779 Window window
= FRAME_OUTER_WINDOW (f
);
9781 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9782 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9783 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9785 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9789 /***********************************************************************
9791 ***********************************************************************/
9795 /* Check that FONT is valid on frame F. It is if it can be found in F's
9799 x_check_font (struct frame
*f
, struct font
*font
)
9801 eassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9802 if (font
->driver
->check
)
9803 eassert (font
->driver
->check (f
, font
) == 0);
9806 #endif /* GLYPH_DEBUG */
9809 /***********************************************************************
9811 ***********************************************************************/
9813 #ifdef USE_X_TOOLKIT
9814 static XrmOptionDescRec emacs_options
[] = {
9815 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9816 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9818 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9819 XrmoptionSepArg
, NULL
},
9820 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9822 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9823 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9824 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9825 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9826 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9827 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9828 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9831 /* Whether atimer for Xt timeouts is activated or not. */
9833 static int x_timeout_atimer_activated_flag
;
9835 #endif /* USE_X_TOOLKIT */
9837 static int x_initialized
;
9839 /* Test whether two display-name strings agree up to the dot that separates
9840 the screen number from the server number. */
9842 same_x_server (const char *name1
, const char *name2
)
9845 const char *system_name
= SSDATA (Vsystem_name
);
9846 ptrdiff_t system_name_length
= SBYTES (Vsystem_name
);
9847 ptrdiff_t length_until_period
= 0;
9849 while (system_name
[length_until_period
] != 0
9850 && system_name
[length_until_period
] != '.')
9851 length_until_period
++;
9853 /* Treat `unix' like an empty host name. */
9854 if (! strncmp (name1
, "unix:", 5))
9856 if (! strncmp (name2
, "unix:", 5))
9858 /* Treat this host's name like an empty host name. */
9859 if (! strncmp (name1
, system_name
, system_name_length
)
9860 && name1
[system_name_length
] == ':')
9861 name1
+= system_name_length
;
9862 if (! strncmp (name2
, system_name
, system_name_length
)
9863 && name2
[system_name_length
] == ':')
9864 name2
+= system_name_length
;
9865 /* Treat this host's domainless name like an empty host name. */
9866 if (! strncmp (name1
, system_name
, length_until_period
)
9867 && name1
[length_until_period
] == ':')
9868 name1
+= length_until_period
;
9869 if (! strncmp (name2
, system_name
, length_until_period
)
9870 && name2
[length_until_period
] == ':')
9871 name2
+= length_until_period
;
9873 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9877 if (seen_colon
&& *name1
== '.')
9881 && (*name1
== '.' || *name1
== '\0')
9882 && (*name2
== '.' || *name2
== '\0'));
9885 /* Count number of set bits in mask and number of bits to shift to
9886 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9889 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9910 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9911 But don't permanently open it, just test its availability. */
9914 x_display_ok (const char *display
)
9919 dpy
= XOpenDisplay (display
);
9921 XCloseDisplay (dpy
);
9929 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
,
9930 const gchar
*msg
, gpointer user_data
)
9932 if (!strstr (msg
, "g_set_prgname"))
9933 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, msg
);
9937 /* Open a connection to X display DISPLAY_NAME, and return
9938 the structure that describes the open display.
9939 If we cannot contact the display, return null. */
9941 struct x_display_info
*
9942 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9946 struct terminal
*terminal
;
9947 struct x_display_info
*dpyinfo
;
9949 Mouse_HLInfo
*hlinfo
;
9960 if (! x_display_ok (SSDATA (display_name
)))
9961 error ("Display %s can't be opened", SSDATA (display_name
));
9967 char *argv
[NUM_ARGV
];
9968 char **argv2
= argv
;
9971 if (x_initialized
++ > 1)
9973 xg_display_open (SSDATA (display_name
), &dpy
);
9977 static char display_opt
[] = "--display";
9978 static char name_opt
[] = "--name";
9980 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9984 argv
[argc
++] = initial_argv
[0];
9986 if (! NILP (display_name
))
9988 argv
[argc
++] = display_opt
;
9989 argv
[argc
++] = SSDATA (display_name
);
9992 argv
[argc
++] = name_opt
;
9993 argv
[argc
++] = resource_name
;
9995 XSetLocaleModifiers ("");
9997 /* Emacs can only handle core input events, so make sure
9998 Gtk doesn't use Xinput or Xinput2 extensions. */
10000 static char fix_events
[] = "GDK_CORE_DEVICE_EVENTS=1";
10001 putenv (fix_events
);
10004 /* Work around GLib bug that outputs a faulty warning. See
10005 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
10006 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
10007 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
10009 /* NULL window -> events for all windows go to our function.
10010 Call before gtk_init so Gtk+ event filters comes after our. */
10011 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10013 gtk_init (&argc
, &argv2
);
10014 g_log_remove_handler ("GLib", id
);
10016 /* gtk_init does set_locale. We must fix locale after calling it. */
10020 dpy
= DEFAULT_GDK_DISPLAY ();
10022 #if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION <= 90
10023 /* Load our own gtkrc if it exists. */
10025 const char *file
= "~/.emacs.d/gtkrc";
10026 Lisp_Object s
, abs_file
;
10028 s
= build_string (file
);
10029 abs_file
= Fexpand_file_name (s
, Qnil
);
10031 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10032 gtk_rc_parse (SSDATA (abs_file
));
10036 XSetErrorHandler (x_error_handler
);
10037 XSetIOErrorHandler (x_io_error_quitter
);
10040 #else /* not USE_GTK */
10041 #ifdef USE_X_TOOLKIT
10042 /* weiner@footloose.sps.mot.com reports that this causes
10044 X protocol error: BadAtom (invalid Atom parameter)
10045 on protocol request 18skiloaf.
10046 So let's not use it until R6. */
10047 #ifdef HAVE_X11XTR6
10048 XtSetLanguageProc (NULL
, NULL
, NULL
);
10059 argv
[argc
++] = "-xrm";
10060 argv
[argc
++] = xrm_option
;
10062 turn_on_atimers (0);
10063 dpy
= XtOpenDisplay (Xt_app_con
, SSDATA (display_name
),
10064 resource_name
, EMACS_CLASS
,
10065 emacs_options
, XtNumber (emacs_options
),
10067 turn_on_atimers (1);
10069 #ifdef HAVE_X11XTR6
10070 /* I think this is to compensate for XtSetLanguageProc. */
10075 #else /* not USE_X_TOOLKIT */
10076 XSetLocaleModifiers ("");
10077 dpy
= XOpenDisplay (SSDATA (display_name
));
10078 #endif /* not USE_X_TOOLKIT */
10079 #endif /* not USE_GTK*/
10081 /* Detect failure. */
10088 /* We have definitely succeeded. Record the new connection. */
10090 dpyinfo
= xzalloc (sizeof *dpyinfo
);
10091 hlinfo
= &dpyinfo
->mouse_highlight
;
10093 terminal
= x_create_terminal (dpyinfo
);
10096 struct x_display_info
*share
;
10099 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10100 share
= share
->next
, tail
= XCDR (tail
))
10101 if (same_x_server (SSDATA (XCAR (XCAR (tail
))),
10102 SSDATA (display_name
)))
10105 terminal
->kboard
= share
->terminal
->kboard
;
10108 terminal
->kboard
= xmalloc (sizeof *terminal
->kboard
);
10109 init_kboard (terminal
->kboard
);
10110 kset_window_system (terminal
->kboard
, Qx
);
10112 /* Add the keyboard to the list before running Lisp code (via
10113 Qvendor_specific_keysyms below), since these are not traced
10114 via terminals but only through all_kboards. */
10115 terminal
->kboard
->next_kboard
= all_kboards
;
10116 all_kboards
= terminal
->kboard
;
10118 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10120 char *vendor
= ServerVendor (dpy
);
10122 /* Protect terminal from GC before removing it from the
10123 list of terminals. */
10124 struct gcpro gcpro1
;
10125 Lisp_Object gcpro_term
;
10126 XSETTERMINAL (gcpro_term
, terminal
);
10127 GCPRO1 (gcpro_term
);
10129 /* Temporarily hide the partially initialized terminal. */
10130 terminal_list
= terminal
->next_terminal
;
10132 kset_system_key_alist
10134 call1 (Qvendor_specific_keysyms
,
10135 vendor
? build_string (vendor
) : empty_unibyte_string
));
10137 terminal
->next_terminal
= terminal_list
;
10138 terminal_list
= terminal
;
10142 /* Don't let the initial kboard remain current longer than necessary.
10143 That would cause problems if a file loaded on startup tries to
10144 prompt in the mini-buffer. */
10145 if (current_kboard
== initial_kboard
)
10146 current_kboard
= terminal
->kboard
;
10148 terminal
->kboard
->reference_count
++;
10151 /* Put this display on the chain. */
10152 dpyinfo
->next
= x_display_list
;
10153 x_display_list
= dpyinfo
;
10155 /* Put it on x_display_name_list as well, to keep them parallel. */
10156 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10157 x_display_name_list
);
10158 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10160 dpyinfo
->display
= dpy
;
10162 /* Set the name of the terminal. */
10163 terminal
->name
= xmalloc (SBYTES (display_name
) + 1);
10164 memcpy (terminal
->name
, SSDATA (display_name
), SBYTES (display_name
));
10165 terminal
->name
[SBYTES (display_name
)] = 0;
10168 XSetAfterFunction (x_current_display
, x_trace_wire
);
10171 lim
= min (PTRDIFF_MAX
, SIZE_MAX
) - sizeof "@";
10172 if (lim
- SBYTES (Vinvocation_name
) < SBYTES (Vsystem_name
))
10173 memory_full (SIZE_MAX
);
10174 dpyinfo
->x_id_name
= xmalloc (SBYTES (Vinvocation_name
)
10175 + SBYTES (Vsystem_name
) + 2);
10176 strcat (strcat (strcpy (dpyinfo
->x_id_name
, SSDATA (Vinvocation_name
)), "@"),
10177 SSDATA (Vsystem_name
));
10179 /* Figure out which modifier bits mean what. */
10180 x_find_modifier_meanings (dpyinfo
);
10182 /* Get the scroll bar cursor. */
10184 /* We must create a GTK cursor, it is required for GTK widgets. */
10185 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10186 #endif /* USE_GTK */
10188 dpyinfo
->vertical_scroll_bar_cursor
10189 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10191 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10192 resource_name
, EMACS_CLASS
);
10193 #ifdef HAVE_XRMSETDATABASE
10194 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10196 dpyinfo
->display
->db
= xrdb
;
10198 /* Put the rdb where we can find it in a way that works on
10200 dpyinfo
->xrdb
= xrdb
;
10202 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10203 DefaultScreen (dpyinfo
->display
));
10204 select_visual (dpyinfo
);
10205 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10206 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10207 dpyinfo
->client_leader_window
= 0;
10208 dpyinfo
->grabbed
= 0;
10209 dpyinfo
->reference_count
= 0;
10210 dpyinfo
->icon_bitmap_id
= -1;
10211 dpyinfo
->n_fonts
= 0;
10212 dpyinfo
->bitmaps
= 0;
10213 dpyinfo
->bitmaps_size
= 0;
10214 dpyinfo
->bitmaps_last
= 0;
10215 dpyinfo
->scratch_cursor_gc
= 0;
10216 hlinfo
->mouse_face_mouse_frame
= 0;
10217 hlinfo
->mouse_face_deferred_gc
= 0;
10218 hlinfo
->mouse_face_beg_row
= hlinfo
->mouse_face_beg_col
= -1;
10219 hlinfo
->mouse_face_end_row
= hlinfo
->mouse_face_end_col
= -1;
10220 hlinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10221 hlinfo
->mouse_face_window
= Qnil
;
10222 hlinfo
->mouse_face_overlay
= Qnil
;
10223 hlinfo
->mouse_face_mouse_x
= hlinfo
->mouse_face_mouse_y
= 0;
10224 hlinfo
->mouse_face_defer
= 0;
10225 hlinfo
->mouse_face_hidden
= 0;
10226 dpyinfo
->x_focus_frame
= 0;
10227 dpyinfo
->x_focus_event_frame
= 0;
10228 dpyinfo
->x_highlight_frame
= 0;
10229 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10231 /* See if we can construct pixel values from RGB values. */
10232 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10233 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10235 if (dpyinfo
->visual
->class == TrueColor
)
10237 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10238 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10239 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10240 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10241 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10242 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10245 /* See if a private colormap is requested. */
10246 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10248 if (dpyinfo
->visual
->class == PseudoColor
)
10251 value
= display_x_get_resource (dpyinfo
,
10252 build_string ("privateColormap"),
10253 build_string ("PrivateColormap"),
10255 if (STRINGP (value
)
10256 && (!strcmp (SSDATA (value
), "true")
10257 || !strcmp (SSDATA (value
), "on")))
10258 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10262 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10263 dpyinfo
->visual
, AllocNone
);
10267 /* If we are using Xft, check dpi value in X resources.
10268 It is better we use it as well, since Xft will use it, as will all
10269 Gnome applications. If our real DPI is smaller or larger than the
10270 one Xft uses, our font will look smaller or larger than other
10271 for other applications, even if it is the same font name (monospace-10
10273 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10275 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10276 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10280 if (dpyinfo
->resy
< 1)
10282 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10283 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10284 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10285 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10286 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10287 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10288 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10289 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10290 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10299 { "WM_PROTOCOLS", &dpyinfo
->Xatom_wm_protocols
},
10300 { "WM_TAKE_FOCUS", &dpyinfo
->Xatom_wm_take_focus
},
10301 { "WM_SAVE_YOURSELF", &dpyinfo
->Xatom_wm_save_yourself
},
10302 { "WM_DELETE_WINDOW", &dpyinfo
->Xatom_wm_delete_window
},
10303 { "WM_CHANGE_STATE", &dpyinfo
->Xatom_wm_change_state
},
10304 { "WM_CONFIGURE_DENIED", &dpyinfo
->Xatom_wm_configure_denied
},
10305 { "WM_MOVED", &dpyinfo
->Xatom_wm_window_moved
},
10306 { "WM_CLIENT_LEADER", &dpyinfo
->Xatom_wm_client_leader
},
10307 { "Editres", &dpyinfo
->Xatom_editres
},
10308 { "CLIPBOARD", &dpyinfo
->Xatom_CLIPBOARD
},
10309 { "TIMESTAMP", &dpyinfo
->Xatom_TIMESTAMP
},
10310 { "TEXT", &dpyinfo
->Xatom_TEXT
},
10311 { "COMPOUND_TEXT", &dpyinfo
->Xatom_COMPOUND_TEXT
},
10312 { "UTF8_STRING", &dpyinfo
->Xatom_UTF8_STRING
},
10313 { "DELETE", &dpyinfo
->Xatom_DELETE
},
10314 { "MULTIPLE", &dpyinfo
->Xatom_MULTIPLE
},
10315 { "INCR", &dpyinfo
->Xatom_INCR
},
10316 { "_EMACS_TMP_", &dpyinfo
->Xatom_EMACS_TMP
},
10317 { "TARGETS", &dpyinfo
->Xatom_TARGETS
},
10318 { "NULL", &dpyinfo
->Xatom_NULL
},
10319 { "ATOM", &dpyinfo
->Xatom_ATOM
},
10320 { "ATOM_PAIR", &dpyinfo
->Xatom_ATOM_PAIR
},
10321 { "CLIPBOARD_MANAGER", &dpyinfo
->Xatom_CLIPBOARD_MANAGER
},
10322 { "_XEMBED_INFO", &dpyinfo
->Xatom_XEMBED_INFO
},
10323 /* For properties of font. */
10324 { "PIXEL_SIZE", &dpyinfo
->Xatom_PIXEL_SIZE
},
10325 { "AVERAGE_WIDTH", &dpyinfo
->Xatom_AVERAGE_WIDTH
},
10326 { "_MULE_BASELINE_OFFSET", &dpyinfo
->Xatom_MULE_BASELINE_OFFSET
},
10327 { "_MULE_RELATIVE_COMPOSE", &dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
},
10328 { "_MULE_DEFAULT_ASCENT", &dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
},
10329 /* Ghostscript support. */
10330 { "DONE", &dpyinfo
->Xatom_DONE
},
10331 { "PAGE", &dpyinfo
->Xatom_PAGE
},
10332 { "SCROLLBAR", &dpyinfo
->Xatom_Scrollbar
},
10333 { "_XEMBED", &dpyinfo
->Xatom_XEMBED
},
10335 { "_NET_WM_STATE", &dpyinfo
->Xatom_net_wm_state
},
10336 { "_NET_WM_STATE_FULLSCREEN", &dpyinfo
->Xatom_net_wm_state_fullscreen
},
10337 { "_NET_WM_STATE_MAXIMIZED_HORZ",
10338 &dpyinfo
->Xatom_net_wm_state_maximized_horz
},
10339 { "_NET_WM_STATE_MAXIMIZED_VERT",
10340 &dpyinfo
->Xatom_net_wm_state_maximized_vert
},
10341 { "_NET_WM_STATE_STICKY", &dpyinfo
->Xatom_net_wm_state_sticky
},
10342 { "_NET_WM_STATE_HIDDEN", &dpyinfo
->Xatom_net_wm_state_hidden
},
10343 { "_NET_WM_WINDOW_TYPE", &dpyinfo
->Xatom_net_window_type
},
10344 { "_NET_WM_WINDOW_TYPE_TOOLTIP",
10345 &dpyinfo
->Xatom_net_window_type_tooltip
},
10346 { "_NET_WM_ICON_NAME", &dpyinfo
->Xatom_net_wm_icon_name
},
10347 { "_NET_WM_NAME", &dpyinfo
->Xatom_net_wm_name
},
10348 { "_NET_SUPPORTED", &dpyinfo
->Xatom_net_supported
},
10349 { "_NET_SUPPORTING_WM_CHECK", &dpyinfo
->Xatom_net_supporting_wm_check
},
10350 { "_NET_WM_WINDOW_OPACITY", &dpyinfo
->Xatom_net_wm_window_opacity
},
10351 { "_NET_ACTIVE_WINDOW", &dpyinfo
->Xatom_net_active_window
},
10352 { "_NET_FRAME_EXTENTS", &dpyinfo
->Xatom_net_frame_extents
},
10353 /* Session management */
10354 { "SM_CLIENT_ID", &dpyinfo
->Xatom_SM_CLIENT_ID
},
10355 { "_XSETTINGS_SETTINGS", &dpyinfo
->Xatom_xsettings_prop
},
10356 { "MANAGER", &dpyinfo
->Xatom_xsettings_mgr
},
10360 const int atom_count
= sizeof (atom_refs
) / sizeof (atom_refs
[0]);
10361 /* 1 for _XSETTINGS_SN */
10362 const int total_atom_count
= 1 + atom_count
;
10363 Atom
*atoms_return
= xmalloc (total_atom_count
* sizeof *atoms_return
);
10364 char **atom_names
= xmalloc (total_atom_count
* sizeof *atom_names
);
10365 static char const xsettings_fmt
[] = "_XSETTINGS_S%d";
10366 char xsettings_atom_name
[sizeof xsettings_fmt
- 2
10367 + INT_STRLEN_BOUND (int)];
10369 for (i
= 0; i
< atom_count
; i
++)
10370 atom_names
[i
] = (char *) atom_refs
[i
].name
;
10372 /* Build _XSETTINGS_SN atom name */
10373 sprintf (xsettings_atom_name
, xsettings_fmt
,
10374 XScreenNumberOfScreen (dpyinfo
->screen
));
10375 atom_names
[i
] = xsettings_atom_name
;
10377 XInternAtoms (dpyinfo
->display
, atom_names
, total_atom_count
,
10378 False
, atoms_return
);
10380 for (i
= 0; i
< atom_count
; i
++)
10381 *atom_refs
[i
].atom
= atoms_return
[i
];
10383 /* Manual copy of last atom */
10384 dpyinfo
->Xatom_xsettings_sel
= atoms_return
[i
];
10386 xfree (atom_names
);
10387 xfree (atoms_return
);
10390 dpyinfo
->x_dnd_atoms_size
= 8;
10391 dpyinfo
->x_dnd_atoms_length
= 0;
10392 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof *dpyinfo
->x_dnd_atoms
10393 * dpyinfo
->x_dnd_atoms_size
);
10395 dpyinfo
->net_supported_atoms
= NULL
;
10396 dpyinfo
->nr_net_supported_atoms
= 0;
10397 dpyinfo
->net_supported_window
= 0;
10399 connection
= ConnectionNumber (dpyinfo
->display
);
10400 dpyinfo
->connection
= connection
;
10402 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10403 gray_bits
, gray_width
, gray_height
,
10407 xim_initialize (dpyinfo
, resource_name
);
10410 xsettings_initialize (dpyinfo
);
10412 /* This is only needed for distinguishing keyboard and process input. */
10413 if (connection
!= 0)
10414 add_keyboard_wait_descriptor (connection
);
10417 fcntl (connection
, F_SETOWN
, getpid ());
10418 #endif /* ! defined (F_SETOWN) */
10421 if (interrupt_input
)
10422 init_sigio (connection
);
10423 #endif /* ! defined (SIGIO) */
10427 XrmValue d
, fr
, to
;
10430 dpy
= dpyinfo
->display
;
10431 d
.addr
= (XPointer
)&dpy
;
10432 d
.size
= sizeof (Display
*);
10433 fr
.addr
= XtDefaultFont
;
10434 fr
.size
= sizeof (XtDefaultFont
);
10435 to
.size
= sizeof (Font
*);
10436 to
.addr
= (XPointer
)&font
;
10437 x_catch_errors (dpy
);
10438 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10440 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10441 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10442 x_uncatch_errors ();
10446 /* See if we should run in synchronous mode. This is useful
10447 for debugging X code. */
10450 value
= display_x_get_resource (dpyinfo
,
10451 build_string ("synchronous"),
10452 build_string ("Synchronous"),
10454 if (STRINGP (value
)
10455 && (!strcmp (SSDATA (value
), "true")
10456 || !strcmp (SSDATA (value
), "on")))
10457 XSynchronize (dpyinfo
->display
, True
);
10462 value
= display_x_get_resource (dpyinfo
,
10463 build_string ("useXIM"),
10464 build_string ("UseXIM"),
10467 if (STRINGP (value
)
10468 && (!strcmp (SSDATA (value
), "false")
10469 || !strcmp (SSDATA (value
), "off")))
10472 if (STRINGP (value
)
10473 && (!strcmp (SSDATA (value
), "true")
10474 || !strcmp (SSDATA (value
), "on")))
10480 /* Only do this for the very first display in the Emacs session.
10481 Ignore X session management when Emacs was first started on a
10483 if (terminal
->id
== 1)
10484 x_session_initialize (dpyinfo
);
10492 /* Get rid of display DPYINFO, deleting all frames on it,
10493 and without sending any more commands to the X server. */
10496 x_delete_display (struct x_display_info
*dpyinfo
)
10498 struct terminal
*t
;
10500 /* Close all frames and delete the generic struct terminal for this
10502 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10503 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10506 /* Close X session management when we close its display. */
10507 if (t
->id
== 1 && x_session_have_connection ())
10508 x_session_close ();
10510 delete_terminal (t
);
10514 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10516 /* Discard this display from x_display_name_list and x_display_list.
10517 We can't use Fdelq because that can quit. */
10518 if (! NILP (x_display_name_list
)
10519 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10520 x_display_name_list
= XCDR (x_display_name_list
);
10525 tail
= x_display_name_list
;
10526 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10528 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10530 XSETCDR (tail
, XCDR (XCDR (tail
)));
10533 tail
= XCDR (tail
);
10537 if (next_noop_dpyinfo
== dpyinfo
)
10538 next_noop_dpyinfo
= dpyinfo
->next
;
10540 if (x_display_list
== dpyinfo
)
10541 x_display_list
= dpyinfo
->next
;
10544 struct x_display_info
*tail
;
10546 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10547 if (tail
->next
== dpyinfo
)
10548 tail
->next
= tail
->next
->next
;
10551 xfree (dpyinfo
->x_id_name
);
10552 xfree (dpyinfo
->x_dnd_atoms
);
10553 xfree (dpyinfo
->color_cells
);
10557 #ifdef USE_X_TOOLKIT
10559 /* Atimer callback function for TIMER. Called every 0.1s to process
10560 Xt timeouts, if needed. We must avoid calling XtAppPending as
10561 much as possible because that function does an implicit XFlush
10562 that slows us down. */
10565 x_process_timeouts (struct atimer
*timer
)
10568 x_timeout_atimer_activated_flag
= 0;
10569 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10571 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10572 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10573 /* Reactivate the atimer for next time. */
10574 x_activate_timeout_atimer ();
10579 /* Install an asynchronous timer that processes Xt timeout events
10580 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10581 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10582 function whenever these variables are set. This is necessary
10583 because some widget sets use timeouts internally, for example the
10584 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10585 processed, these widgets don't behave normally. */
10588 x_activate_timeout_atimer (void)
10591 if (!x_timeout_atimer_activated_flag
)
10593 EMACS_TIME interval
= make_emacs_time (0, 100 * 1000 * 1000);
10594 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10595 x_timeout_atimer_activated_flag
= 1;
10600 #endif /* USE_X_TOOLKIT */
10603 /* Set up use of X before we make the first connection. */
10605 static struct redisplay_interface x_redisplay_interface
=
10607 x_frame_parm_handlers
,
10611 x_clear_end_of_line
,
10613 x_after_update_window_line
,
10614 x_update_window_begin
,
10615 x_update_window_end
,
10621 0, /* flush_display_optional */
10623 x_clear_window_mouse_face
,
10624 x_get_glyph_overhangs
,
10625 x_fix_overlapping_area
,
10626 x_draw_fringe_bitmap
,
10627 0, /* define_fringe_bitmap */
10628 0, /* destroy_fringe_bitmap */
10629 x_compute_glyph_string_overhangs
,
10630 x_draw_glyph_string
,
10631 x_define_frame_cursor
,
10632 x_clear_frame_area
,
10633 x_draw_window_cursor
,
10634 x_draw_vertical_window_border
,
10635 x_shift_glyphs_for_insert
10639 /* This function is called when the last frame on a display is deleted. */
10641 x_delete_terminal (struct terminal
*terminal
)
10643 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10645 /* Protect against recursive calls. delete_frame in
10646 delete_terminal calls us back when it deletes our last frame. */
10647 if (!terminal
->name
)
10652 /* We must close our connection to the XIM server before closing the
10655 xim_close_dpy (dpyinfo
);
10658 /* If called from x_connection_closed, the display may already be closed
10659 and dpyinfo->display was set to 0 to indicate that. */
10660 if (dpyinfo
->display
)
10662 x_destroy_all_bitmaps (dpyinfo
);
10663 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10665 /* Whether or not XCloseDisplay destroys the associated resource
10666 database depends on the version of libX11. To avoid both
10667 crash and memory leak, we dissociate the database from the
10668 display and then destroy dpyinfo->xrdb ourselves.
10670 Unfortunately, the above strategy does not work in some
10671 situations due to a bug in newer versions of libX11: because
10672 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10673 dpy->db is NULL, XCloseDisplay destroys the associated
10674 database whereas it has not been created by XGetDefault
10675 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10676 don't destroy the database here in order to avoid the crash
10677 in the above situations for now, though that may cause memory
10678 leaks in other situations. */
10680 #ifdef HAVE_XRMSETDATABASE
10681 XrmSetDatabase (dpyinfo
->display
, NULL
);
10683 dpyinfo
->display
->db
= NULL
;
10685 /* We used to call XrmDestroyDatabase from x_delete_display, but
10686 some older versions of libX11 crash if we call it after
10687 closing all the displays. */
10688 XrmDestroyDatabase (dpyinfo
->xrdb
);
10692 xg_display_close (dpyinfo
->display
);
10694 #ifdef USE_X_TOOLKIT
10695 XtCloseDisplay (dpyinfo
->display
);
10697 XCloseDisplay (dpyinfo
->display
);
10699 #endif /* ! USE_GTK */
10702 /* Mark as dead. */
10703 dpyinfo
->display
= NULL
;
10704 x_delete_display (dpyinfo
);
10708 /* Create a struct terminal, initialize it with the X11 specific
10709 functions and make DISPLAY->TERMINAL point to it. */
10711 static struct terminal
*
10712 x_create_terminal (struct x_display_info
*dpyinfo
)
10714 struct terminal
*terminal
;
10716 terminal
= create_terminal ();
10718 terminal
->type
= output_x_window
;
10719 terminal
->display_info
.x
= dpyinfo
;
10720 dpyinfo
->terminal
= terminal
;
10722 /* kboard is initialized in x_term_init. */
10724 terminal
->clear_frame_hook
= x_clear_frame
;
10725 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10726 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10727 terminal
->ring_bell_hook
= XTring_bell
;
10728 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10729 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10730 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
10731 terminal
->update_begin_hook
= x_update_begin
;
10732 terminal
->update_end_hook
= x_update_end
;
10733 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
10734 terminal
->read_socket_hook
= XTread_socket
;
10735 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10736 terminal
->mouse_position_hook
= XTmouse_position
;
10737 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10738 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10739 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10740 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10741 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10742 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10743 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10745 terminal
->delete_frame_hook
= x_destroy_window
;
10746 terminal
->delete_terminal_hook
= x_delete_terminal
;
10748 terminal
->rif
= &x_redisplay_interface
;
10749 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10750 terminal
->char_ins_del_ok
= 1;
10751 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10752 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10753 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10760 x_initialize (void)
10765 last_tool_bar_item
= -1;
10766 any_help_event_p
= 0;
10767 ignore_next_mouse_click_timeout
= 0;
10770 current_count
= -1;
10773 /* Try to use interrupt input; if we can't, then start polling. */
10774 Fset_input_interrupt_mode (Qt
);
10776 #ifdef USE_X_TOOLKIT
10777 XtToolkitInitialize ();
10779 Xt_app_con
= XtCreateApplicationContext ();
10781 /* Register a converter from strings to pixels, which uses
10782 Emacs' color allocation infrastructure. */
10783 XtAppSetTypeConverter (Xt_app_con
,
10784 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10785 cvt_string_to_pixel_args
,
10786 XtNumber (cvt_string_to_pixel_args
),
10787 XtCacheByDisplay
, cvt_pixel_dtor
);
10789 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10792 #ifdef USE_TOOLKIT_SCROLL_BARS
10794 xaw3d_arrow_scroll
= False
;
10795 xaw3d_pick_top
= True
;
10799 pending_autoraise_frame
= 0;
10800 pending_event_wait
.f
= 0;
10801 pending_event_wait
.eventtype
= 0;
10803 /* Note that there is no real way portable across R3/R4 to get the
10804 original error handler. */
10805 XSetErrorHandler (x_error_handler
);
10806 XSetIOErrorHandler (x_io_error_quitter
);
10808 signal (SIGPIPE
, x_connection_signal
);
10813 syms_of_xterm (void)
10815 x_error_message
= NULL
;
10817 staticpro (&x_display_name_list
);
10818 x_display_name_list
= Qnil
;
10820 staticpro (&last_mouse_scroll_bar
);
10821 last_mouse_scroll_bar
= Qnil
;
10823 DEFSYM (Qvendor_specific_keysyms
, "vendor-specific-keysyms");
10824 DEFSYM (Qlatin_1
, "latin-1");
10826 staticpro (&last_mouse_press_frame
);
10827 last_mouse_press_frame
= Qnil
;
10830 xg_default_icon_file
= build_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10831 staticpro (&xg_default_icon_file
);
10833 DEFSYM (Qx_gtk_map_stock
, "x-gtk-map-stock");
10836 DEFVAR_BOOL ("x-use-underline-position-properties",
10837 x_use_underline_position_properties
,
10838 doc
: /* Non-nil means make use of UNDERLINE_POSITION font properties.
10839 A value of nil means ignore them. If you encounter fonts with bogus
10840 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10841 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10842 to override the font's UNDERLINE_POSITION for small font display
10844 x_use_underline_position_properties
= 1;
10846 DEFVAR_BOOL ("x-underline-at-descent-line",
10847 x_underline_at_descent_line
,
10848 doc
: /* Non-nil means to draw the underline at the same place as the descent line.
10849 A value of nil means to draw the underline according to the value of the
10850 variable `x-use-underline-position-properties', which is usually at the
10851 baseline level. The default value is nil. */);
10852 x_underline_at_descent_line
= 0;
10854 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10855 x_mouse_click_focus_ignore_position
,
10856 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10857 This variable is only used when the window manager requires that you
10858 click on a frame to select it (give it focus). In that case, a value
10859 of nil, means that the selected window and cursor position changes to
10860 reflect the mouse click position, while a non-nil value means that the
10861 selected window or cursor position is preserved. */);
10862 x_mouse_click_focus_ignore_position
= 0;
10864 DEFVAR_LISP ("x-toolkit-scroll-bars", Vx_toolkit_scroll_bars
,
10865 doc
: /* Which toolkit scroll bars Emacs uses, if any.
10866 A value of nil means Emacs doesn't use toolkit scroll bars.
10867 With the X Window system, the value is a symbol describing the
10868 X toolkit. Possible values are: gtk, motif, xaw, or xaw3d.
10869 With MS Windows or Nextstep, the value is t. */);
10870 #ifdef USE_TOOLKIT_SCROLL_BARS
10872 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10873 #elif defined HAVE_XAW3D
10874 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10876 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10878 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10881 Vx_toolkit_scroll_bars
= Qnil
;
10884 staticpro (&last_mouse_motion_frame
);
10885 last_mouse_motion_frame
= Qnil
;
10887 Qmodifier_value
= intern_c_string ("modifier-value");
10888 Qalt
= intern_c_string ("alt");
10889 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10890 Qhyper
= intern_c_string ("hyper");
10891 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10892 Qmeta
= intern_c_string ("meta");
10893 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10894 Qsuper
= intern_c_string ("super");
10895 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10897 DEFVAR_LISP ("x-alt-keysym", Vx_alt_keysym
,
10898 doc
: /* Which keys Emacs uses for the alt modifier.
10899 This should be one of the symbols `alt', `hyper', `meta', `super'.
10900 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10901 is nil, which is the same as `alt'. */);
10902 Vx_alt_keysym
= Qnil
;
10904 DEFVAR_LISP ("x-hyper-keysym", Vx_hyper_keysym
,
10905 doc
: /* Which keys Emacs uses for the hyper modifier.
10906 This should be one of the symbols `alt', `hyper', `meta', `super'.
10907 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10908 default is nil, which is the same as `hyper'. */);
10909 Vx_hyper_keysym
= Qnil
;
10911 DEFVAR_LISP ("x-meta-keysym", Vx_meta_keysym
,
10912 doc
: /* Which keys Emacs uses for the meta modifier.
10913 This should be one of the symbols `alt', `hyper', `meta', `super'.
10914 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10915 default is nil, which is the same as `meta'. */);
10916 Vx_meta_keysym
= Qnil
;
10918 DEFVAR_LISP ("x-super-keysym", Vx_super_keysym
,
10919 doc
: /* Which keys Emacs uses for the super modifier.
10920 This should be one of the symbols `alt', `hyper', `meta', `super'.
10921 For example, `super' means use the Super_L and Super_R keysyms. The
10922 default is nil, which is the same as `super'. */);
10923 Vx_super_keysym
= Qnil
;
10925 DEFVAR_LISP ("x-keysym-table", Vx_keysym_table
,
10926 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10927 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10928 make_float (DEFAULT_REHASH_SIZE
),
10929 make_float (DEFAULT_REHASH_THRESHOLD
),
10933 #endif /* HAVE_X_WINDOWS */