1 /* X Communication module for terminals which understand the X protocol.
2 Copyright (C) 1989, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
3 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
22 /* Xt features made by Fred Pierresteguy. */
26 /* On 4.3 these lose if they come after xterm.h. */
27 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
54 #include <sys/ioctl.h>
55 #endif /* ! defined (BSD_SYSTEM) */
59 #ifndef INCLUDED_FCNTL
66 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
67 /* #include <sys/param.h> */
70 #include "character.h"
73 #include "dispextern.h"
75 #include "termhooks.h"
78 #include "emacs-icon.h"
83 #include "intervals.h"
89 #include "sysselect.h"
92 #include <X11/Shell.h>
95 #ifdef HAVE_SYS_TIME_H
107 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
108 extern void xlwmenu_redisplay
P_ ((Widget
));
111 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
113 extern void free_frame_menubar
P_ ((struct frame
*));
117 #if !defined(NO_EDITRES)
119 extern void _XEditResCheckMessages ();
120 #endif /* not NO_EDITRES */
122 /* Include toolkit specific headers for the scroll bar widget. */
124 #ifdef USE_TOOLKIT_SCROLL_BARS
125 #if defined USE_MOTIF
126 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
127 #include <Xm/ScrollBar.h>
128 #else /* !USE_MOTIF i.e. use Xaw */
131 #include <X11/Xaw3d/Simple.h>
132 #include <X11/Xaw3d/Scrollbar.h>
133 #include <X11/Xaw3d/ThreeD.h>
134 #else /* !HAVE_XAW3D */
135 #include <X11/Xaw/Simple.h>
136 #include <X11/Xaw/Scrollbar.h>
137 #endif /* !HAVE_XAW3D */
139 #define XtNpickTop "pickTop"
140 #endif /* !XtNpickTop */
141 #endif /* !USE_MOTIF */
142 #endif /* USE_TOOLKIT_SCROLL_BARS */
144 #endif /* USE_X_TOOLKIT */
148 #ifndef XtNinitialState
149 #define XtNinitialState "initialState"
153 /* Default to using XIM if available. */
157 int use_xim
= 0; /* configure --without-xim */
162 /* Non-nil means Emacs uses toolkit scroll bars. */
164 Lisp_Object Vx_toolkit_scroll_bars
;
166 /* Non-zero means that a HELP_EVENT has been generated since Emacs
169 static int any_help_event_p
;
171 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
172 static Lisp_Object last_window
;
174 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
176 int x_use_underline_position_properties
;
178 /* Non-zero means to draw the underline at the same place as the descent line. */
180 int x_underline_at_descent_line
;
182 /* This is a chain of structures for all the X displays currently in
185 struct x_display_info
*x_display_list
;
187 /* This is a list of cons cells, each of the form (NAME
188 . FONT-LIST-CACHE), one for each element of x_display_list and in
189 the same order. NAME is the name of the frame. FONT-LIST-CACHE
190 records previous values returned by x-list-fonts. */
192 Lisp_Object x_display_name_list
;
194 /* Frame being updated by update_frame. This is declared in term.c.
195 This is set by update_begin and looked at by all the XT functions.
196 It is zero while not inside an update. In that case, the XT
197 functions assume that `selected_frame' is the frame to apply to. */
199 extern struct frame
*updating_frame
;
201 /* This is a frame waiting to be auto-raised, within XTread_socket. */
203 static struct frame
*pending_autoraise_frame
;
205 /* This is a frame waiting for an event matching mask, within XTread_socket. */
210 } pending_event_wait
;
213 /* The application context for Xt use. */
214 XtAppContext Xt_app_con
;
215 static String Xt_default_resources
[] = {0};
216 #endif /* USE_X_TOOLKIT */
218 /* Non-zero means user is interacting with a toolkit scroll bar. */
220 static int toolkit_scroll_bar_interaction
;
222 /* Non-zero means to not move point as a result of clicking on a
223 frame to focus it (when focus-follows-mouse is nil). */
225 int x_mouse_click_focus_ignore_position
;
227 /* Non-zero timeout value means ignore next mouse click if it arrives
228 before that timeout elapses (i.e. as part of the same sequence of
229 events resulting from clicking on a frame to select it). */
231 static unsigned long ignore_next_mouse_click_timeout
;
235 Formerly, we used PointerMotionHintMask (in standard_event_mask)
236 so that we would have to call XQueryPointer after each MotionNotify
237 event to ask for another such event. However, this made mouse tracking
238 slow, and there was a bug that made it eventually stop.
240 Simply asking for MotionNotify all the time seems to work better.
242 In order to avoid asking for motion events and then throwing most
243 of them away or busy-polling the server for mouse positions, we ask
244 the server for pointer motion hints. This means that we get only
245 one event per group of mouse movements. "Groups" are delimited by
246 other kinds of events (focus changes and button clicks, for
247 example), or by XQueryPointer calls; when one of these happens, we
248 get another MotionNotify event the next time the mouse moves. This
249 is at least as efficient as getting motion events when mouse
250 tracking is on, and I suspect only negligibly worse when tracking
253 /* Where the mouse was last time we reported a mouse event. */
255 static XRectangle last_mouse_glyph
;
256 static FRAME_PTR last_mouse_glyph_frame
;
257 static Lisp_Object last_mouse_press_frame
;
259 /* The scroll bar in which the last X motion event occurred.
261 If the last X motion event occurred in a scroll bar, we set this so
262 XTmouse_position can know whether to report a scroll bar motion or
265 If the last X motion event didn't occur in a scroll bar, we set
266 this to Qnil, to tell XTmouse_position to return an ordinary motion
269 static Lisp_Object last_mouse_scroll_bar
;
271 /* This is a hack. We would really prefer that XTmouse_position would
272 return the time associated with the position it returns, but there
273 doesn't seem to be any way to wrest the time-stamp from the server
274 along with the position query. So, we just keep track of the time
275 of the last movement we received, and return that in hopes that
276 it's somewhat accurate. */
278 static Time last_mouse_movement_time
;
280 /* Time for last user interaction as returned in X events. */
282 static Time last_user_time
;
284 /* Incremented by XTread_socket whenever it really tries to read
288 static int volatile input_signal_count
;
290 static int input_signal_count
;
293 /* Used locally within XTread_socket. */
295 static int x_noop_count
;
297 /* Initial values of argv and argc. */
299 extern char **initial_argv
;
300 extern int initial_argc
;
302 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
304 /* Tells if a window manager is present or not. */
306 extern Lisp_Object Vx_no_window_manager
;
308 extern Lisp_Object Qeql
;
312 /* A mask of extra modifier bits to put into every keyboard char. */
314 extern EMACS_INT extra_keyboard_modifiers
;
316 /* The keysyms to use for the various modifiers. */
318 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
319 Lisp_Object Vx_keysym_table
;
320 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
322 static Lisp_Object Qvendor_specific_keysyms
;
323 static Lisp_Object Qlatin_1
;
326 /* The name of the Emacs icon file. */
327 static Lisp_Object xg_default_icon_file
;
329 /* Used in gtkutil.c. */
330 Lisp_Object Qx_gtk_map_stock
;
333 /* Used in x_flush. */
335 extern Lisp_Object Vinhibit_redisplay
;
337 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
338 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
340 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
341 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
342 static const XColor
*x_color_cells
P_ ((Display
*, int *));
343 static void x_update_window_end
P_ ((struct window
*, int, int));
345 static int x_io_error_quitter
P_ ((Display
*));
346 static struct terminal
*x_create_terminal
P_ ((struct x_display_info
*));
347 void x_delete_terminal
P_ ((struct terminal
*));
348 static void x_update_end
P_ ((struct frame
*));
349 static void XTframe_up_to_date
P_ ((struct frame
*));
350 static void XTset_terminal_modes
P_ ((struct terminal
*));
351 static void XTreset_terminal_modes
P_ ((struct terminal
*));
352 static void x_clear_frame
P_ ((struct frame
*));
353 static void frame_highlight
P_ ((struct frame
*));
354 static void frame_unhighlight
P_ ((struct frame
*));
355 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
356 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
357 struct frame
*, struct input_event
*));
358 static void x_detect_focus_change
P_ ((struct x_display_info
*,
359 XEvent
*, struct input_event
*));
360 static void XTframe_rehighlight
P_ ((struct frame
*));
361 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
362 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
363 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
364 enum text_cursor_kinds
));
366 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
367 static void x_flush
P_ ((struct frame
*f
));
368 static void x_update_begin
P_ ((struct frame
*));
369 static void x_update_window_begin
P_ ((struct window
*));
370 static void x_after_update_window_line
P_ ((struct glyph_row
*));
371 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
372 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
373 enum scroll_bar_part
*,
374 Lisp_Object
*, Lisp_Object
*,
376 static void x_handle_net_wm_state
P_ ((struct frame
*, XPropertyEvent
*));
377 static void x_check_fullscreen
P_ ((struct frame
*));
378 static void x_check_expected_move
P_ ((struct frame
*, int, int));
379 static void x_sync_with_move
P_ ((struct frame
*, int, int, int));
380 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
381 int *, struct input_event
*));
382 /* Don't declare this NO_RETURN because we want no
383 interference with debugging failing X calls. */
384 static SIGTYPE x_connection_closed
P_ ((Display
*, char *));
387 /* Flush display of frame F, or of all frames if F is null. */
393 /* Don't call XFlush when it is not safe to redisplay; the X
394 connection may be broken. */
395 if (!NILP (Vinhibit_redisplay
))
401 Lisp_Object rest
, frame
;
402 FOR_EACH_FRAME (rest
, frame
)
403 if (FRAME_X_P (XFRAME (frame
)))
404 x_flush (XFRAME (frame
));
406 else if (FRAME_X_P (f
))
407 XFlush (FRAME_X_DISPLAY (f
));
412 /* Remove calls to XFlush by defining XFlush to an empty replacement.
413 Calls to XFlush should be unnecessary because the X output buffer
414 is flushed automatically as needed by calls to XPending,
415 XNextEvent, or XWindowEvent according to the XFlush man page.
416 XTread_socket calls XPending. Removing XFlush improves
419 #define XFlush(DISPLAY) (void) 0
422 /***********************************************************************
424 ***********************************************************************/
428 /* This is a function useful for recording debugging information about
429 the sequence of occurrences in this file. */
437 struct record event_record
[100];
439 int event_record_index
;
441 record_event (locus
, type
)
445 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
446 event_record_index
= 0;
448 event_record
[event_record_index
].locus
= locus
;
449 event_record
[event_record_index
].type
= type
;
450 event_record_index
++;
457 /* Return the struct x_display_info corresponding to DPY. */
459 struct x_display_info
*
460 x_display_info_for_display (dpy
)
463 struct x_display_info
*dpyinfo
;
465 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
466 if (dpyinfo
->display
== dpy
)
472 #define OPAQUE 0xffffffff
473 #define OPACITY "_NET_WM_WINDOW_OPACITY"
476 x_set_frame_alpha (f
)
479 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
480 Display
*dpy
= FRAME_X_DISPLAY (f
);
481 Window win
= FRAME_OUTER_WINDOW (f
);
483 double alpha_min
= 1.0;
486 if (FRAME_X_DISPLAY_INFO (f
)->root_window
!= FRAME_X_OUTPUT (f
)->parent_desc
)
487 /* Since the WM decoration lies under the FRAME_OUTER_WINDOW,
488 we must treat the former instead of the latter. */
489 win
= FRAME_X_OUTPUT(f
)->parent_desc
;
491 if (dpyinfo
->x_highlight_frame
== f
)
496 if (FLOATP (Vframe_alpha_lower_limit
))
497 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
498 else if (INTEGERP (Vframe_alpha_lower_limit
))
499 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
503 else if (alpha
> 1.0)
505 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
508 opac
= alpha
* OPAQUE
;
510 /* return unless necessary */
515 unsigned long n
, left
;
517 x_catch_errors (dpy
);
518 rc
= XGetWindowProperty(dpy
, win
, XInternAtom(dpy
, OPACITY
, False
),
519 0L, 1L, False
, XA_CARDINAL
,
520 &actual
, &format
, &n
, &left
,
523 if (rc
== Success
&& actual
!= None
)
524 if (*(unsigned long *)data
== opac
)
526 XFree ((void *) data
);
531 XFree ((void *) data
);
535 x_catch_errors (dpy
);
536 XChangeProperty (dpy
, win
, XInternAtom (dpy
, OPACITY
, False
),
537 XA_CARDINAL
, 32, PropModeReplace
,
538 (unsigned char *) &opac
, 1L);
543 x_display_pixel_height (dpyinfo
)
544 struct x_display_info
*dpyinfo
;
546 return HeightOfScreen (dpyinfo
->screen
);
550 x_display_pixel_width (dpyinfo
)
551 struct x_display_info
*dpyinfo
;
553 return WidthOfScreen (dpyinfo
->screen
);
557 /***********************************************************************
558 Starting and ending an update
559 ***********************************************************************/
561 /* Start an update of frame F. This function is installed as a hook
562 for update_begin, i.e. it is called when update_begin is called.
563 This function is called prior to calls to x_update_window_begin for
564 each window being updated. Currently, there is nothing to do here
565 because all interesting stuff is done on a window basis. */
575 /* Start update of window W. Set the global variable updated_window
576 to the window being updated and set output_cursor to the cursor
580 x_update_window_begin (w
)
583 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
584 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
587 set_output_cursor (&w
->cursor
);
591 if (f
== display_info
->mouse_face_mouse_frame
)
593 /* Don't do highlighting for mouse motion during the update. */
594 display_info
->mouse_face_defer
= 1;
596 /* If F needs to be redrawn, simply forget about any prior mouse
598 if (FRAME_GARBAGED_P (f
))
599 display_info
->mouse_face_window
= Qnil
;
606 /* Draw a vertical window border from (x,y0) to (x,y1) */
609 x_draw_vertical_window_border (w
, x
, y0
, y1
)
613 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
616 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
618 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
621 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
622 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
625 /* End update of window W (which is equal to updated_window).
627 Draw vertical borders between horizontally adjacent windows, and
628 display W's cursor if CURSOR_ON_P is non-zero.
630 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
631 glyphs in mouse-face were overwritten. In that case we have to
632 make sure that the mouse-highlight is properly redrawn.
634 W may be a menu bar pseudo-window in case we don't have X toolkit
635 support. Such windows don't have a cursor, so don't display it
639 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
641 int cursor_on_p
, mouse_face_overwritten_p
;
643 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
645 if (!w
->pseudo_window_p
)
650 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
652 output_cursor
.x
, output_cursor
.y
);
654 if (draw_window_fringes (w
, 1))
655 x_draw_vertical_border (w
);
660 /* If a row with mouse-face was overwritten, arrange for
661 XTframe_up_to_date to redisplay the mouse highlight. */
662 if (mouse_face_overwritten_p
)
664 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
665 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
666 dpyinfo
->mouse_face_window
= Qnil
;
669 updated_window
= NULL
;
673 /* End update of frame F. This function is installed as a hook in
680 /* Mouse highlight may be displayed again. */
681 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
685 XFlush (FRAME_X_DISPLAY (f
));
691 /* This function is called from various places in xdisp.c whenever a
692 complete update has been performed. The global variable
693 updated_window is not available here. */
696 XTframe_up_to_date (f
)
701 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
703 if (dpyinfo
->mouse_face_deferred_gc
704 || f
== dpyinfo
->mouse_face_mouse_frame
)
707 if (dpyinfo
->mouse_face_mouse_frame
)
708 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
709 dpyinfo
->mouse_face_mouse_x
,
710 dpyinfo
->mouse_face_mouse_y
);
711 dpyinfo
->mouse_face_deferred_gc
= 0;
718 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
719 arrow bitmaps, or clear the fringes if no bitmaps are required
720 before DESIRED_ROW is made current. The window being updated is
721 found in updated_window. This function It is called from
722 update_window_line only if it is known that there are differences
723 between bitmaps to be drawn between current row and DESIRED_ROW. */
726 x_after_update_window_line (desired_row
)
727 struct glyph_row
*desired_row
;
729 struct window
*w
= updated_window
;
735 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
736 desired_row
->redraw_fringe_bitmaps_p
= 1;
738 /* When a window has disappeared, make sure that no rest of
739 full-width rows stays visible in the internal border. Could
740 check here if updated_window is the leftmost/rightmost window,
741 but I guess it's not worth doing since vertically split windows
742 are almost never used, internal border is rarely set, and the
743 overhead is very small. */
744 if (windows_or_buffers_changed
745 && desired_row
->full_width_p
746 && (f
= XFRAME (w
->frame
),
747 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
749 && (height
= desired_row
->visible_height
,
752 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
754 /* Internal border is drawn below the tool bar. */
755 if (WINDOWP (f
->tool_bar_window
)
756 && w
== XWINDOW (f
->tool_bar_window
))
760 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
761 0, y
, width
, height
, False
);
762 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
763 FRAME_PIXEL_WIDTH (f
) - width
,
764 y
, width
, height
, False
);
770 x_draw_fringe_bitmap (w
, row
, p
)
772 struct glyph_row
*row
;
773 struct draw_fringe_bitmap_params
*p
;
775 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
776 Display
*display
= FRAME_X_DISPLAY (f
);
777 Window window
= FRAME_X_WINDOW (f
);
778 GC gc
= f
->output_data
.x
->normal_gc
;
779 struct face
*face
= p
->face
;
782 /* Must clip because of partially visible lines. */
783 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
786 /* Adjust position of "bottom aligned" bitmap on partially
789 int oldVH
= row
->visible_height
;
790 row
->visible_height
= p
->h
;
791 row
->y
-= rowY
- p
->y
;
792 x_clip_to_row (w
, row
, -1, gc
);
794 row
->visible_height
= oldVH
;
797 x_clip_to_row (w
, row
, -1, gc
);
801 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
803 /* In case the same realized face is used for fringes and
804 for something displayed in the text (e.g. face `region' on
805 mono-displays, the fill style may have been changed to
806 FillSolid in x_draw_glyph_string_background. */
808 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
810 XSetForeground (display
, face
->gc
, face
->background
);
812 #ifdef USE_TOOLKIT_SCROLL_BARS
813 /* If the fringe is adjacent to the left (right) scroll bar of a
814 leftmost (rightmost, respectively) window, then extend its
815 background to the gap between the fringe and the bar. */
816 if ((WINDOW_LEFTMOST_P (w
)
817 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
818 || (WINDOW_RIGHTMOST_P (w
)
819 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
821 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
825 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
826 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
827 * FRAME_COLUMN_WIDTH (f
));
831 /* Bitmap fills the fringe. */
832 if (left
+ width
== p
->x
)
833 bx
= left
+ sb_width
;
834 else if (p
->x
+ p
->wd
== left
)
838 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
840 nx
= width
- sb_width
;
841 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
843 ny
= row
->visible_height
;
848 if (left
+ width
== bx
)
850 bx
= left
+ sb_width
;
851 nx
+= width
- sb_width
;
853 else if (bx
+ nx
== left
)
854 nx
+= width
- sb_width
;
859 if (bx
>= 0 && nx
> 0)
860 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
863 XSetForeground (display
, face
->gc
, face
->foreground
);
869 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
870 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
874 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
876 bits
= (unsigned char *)p
->bits
+ p
->dh
;
878 /* Draw the bitmap. I believe these small pixmaps can be cached
880 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
882 ? (p
->overlay_p
? face
->background
883 : f
->output_data
.x
->cursor_pixel
)
885 face
->background
, depth
);
889 clipmask
= XCreatePixmapFromBitmapData (display
,
890 FRAME_X_DISPLAY_INFO (f
)->root_window
,
893 gcv
.clip_mask
= clipmask
;
894 gcv
.clip_x_origin
= p
->x
;
895 gcv
.clip_y_origin
= p
->y
;
896 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
899 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
900 p
->wd
, p
->h
, p
->x
, p
->y
);
901 XFreePixmap (display
, pixmap
);
905 gcv
.clip_mask
= (Pixmap
) 0;
906 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
907 XFreePixmap (display
, clipmask
);
911 XSetClipMask (display
, gc
, None
);
916 /* This is called when starting Emacs and when restarting after
917 suspend. When starting Emacs, no X window is mapped. And nothing
918 must be done to Emacs's own window if it is suspended (though that
922 XTset_terminal_modes (struct terminal
*terminal
)
926 /* This is called when exiting or suspending Emacs. Exiting will make
927 the X-windows go away, and suspending requires no action. */
930 XTreset_terminal_modes (struct terminal
*terminal
)
935 /***********************************************************************
937 ***********************************************************************/
941 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
942 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
943 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
945 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
946 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
947 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
948 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
949 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
950 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
951 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
952 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
953 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
954 unsigned long *, double, int));
955 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
956 double, int, unsigned long));
957 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
958 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
959 static void x_draw_image_relief
P_ ((struct glyph_string
*));
960 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
961 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
962 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
964 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
965 int, int, int, int, int, int,
967 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
968 int, int, int, XRectangle
*));
971 static void x_check_font
P_ ((struct frame
*, struct font
*));
975 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
980 struct glyph_string
*s
;
982 if (s
->font
== FRAME_FONT (s
->f
)
983 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
984 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
986 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
989 /* Cursor on non-default face: must merge. */
993 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
994 xgcv
.foreground
= s
->face
->background
;
996 /* If the glyph would be invisible, try a different foreground. */
997 if (xgcv
.foreground
== xgcv
.background
)
998 xgcv
.foreground
= s
->face
->foreground
;
999 if (xgcv
.foreground
== xgcv
.background
)
1000 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1001 if (xgcv
.foreground
== xgcv
.background
)
1002 xgcv
.foreground
= s
->face
->foreground
;
1004 /* Make sure the cursor is distinct from text in this face. */
1005 if (xgcv
.background
== s
->face
->background
1006 && xgcv
.foreground
== s
->face
->foreground
)
1008 xgcv
.background
= s
->face
->foreground
;
1009 xgcv
.foreground
= s
->face
->background
;
1012 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1013 xgcv
.graphics_exposures
= False
;
1014 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1016 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1017 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1020 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1021 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1023 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1028 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1031 x_set_mouse_face_gc (s
)
1032 struct glyph_string
*s
;
1037 /* What face has to be used last for the mouse face? */
1038 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1039 face
= FACE_FROM_ID (s
->f
, face_id
);
1041 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1043 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1044 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1046 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1047 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1048 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1050 if (s
->font
== s
->face
->font
)
1051 s
->gc
= s
->face
->gc
;
1054 /* Otherwise construct scratch_cursor_gc with values from FACE
1059 xgcv
.background
= s
->face
->background
;
1060 xgcv
.foreground
= s
->face
->foreground
;
1061 xgcv
.graphics_exposures
= False
;
1062 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1064 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1065 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1068 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1069 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1071 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1074 xassert (s
->gc
!= 0);
1078 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1079 Faces to use in the mode line have already been computed when the
1080 matrix was built, so there isn't much to do, here. */
1083 x_set_mode_line_face_gc (s
)
1084 struct glyph_string
*s
;
1086 s
->gc
= s
->face
->gc
;
1090 /* Set S->gc of glyph string S for drawing that glyph string. Set
1091 S->stippled_p to a non-zero value if the face of S has a stipple
1095 x_set_glyph_string_gc (s
)
1096 struct glyph_string
*s
;
1098 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1100 if (s
->hl
== DRAW_NORMAL_TEXT
)
1102 s
->gc
= s
->face
->gc
;
1103 s
->stippled_p
= s
->face
->stipple
!= 0;
1105 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1107 x_set_mode_line_face_gc (s
);
1108 s
->stippled_p
= s
->face
->stipple
!= 0;
1110 else if (s
->hl
== DRAW_CURSOR
)
1112 x_set_cursor_gc (s
);
1115 else if (s
->hl
== DRAW_MOUSE_FACE
)
1117 x_set_mouse_face_gc (s
);
1118 s
->stippled_p
= s
->face
->stipple
!= 0;
1120 else if (s
->hl
== DRAW_IMAGE_RAISED
1121 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1123 s
->gc
= s
->face
->gc
;
1124 s
->stippled_p
= s
->face
->stipple
!= 0;
1128 s
->gc
= s
->face
->gc
;
1129 s
->stippled_p
= s
->face
->stipple
!= 0;
1132 /* GC must have been set. */
1133 xassert (s
->gc
!= 0);
1137 /* Set clipping for output of glyph string S. S may be part of a mode
1138 line or menu if we don't have X toolkit support. */
1141 x_set_glyph_string_clipping (s
)
1142 struct glyph_string
*s
;
1144 XRectangle
*r
= s
->clip
;
1145 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1148 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1153 /* Set SRC's clipping for output of glyph string DST. This is called
1154 when we are drawing DST's left_overhang or right_overhang only in
1158 x_set_glyph_string_clipping_exactly (src
, dst
)
1159 struct glyph_string
*src
, *dst
;
1164 r
.width
= src
->width
;
1166 r
.height
= src
->height
;
1169 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1174 Compute left and right overhang of glyph string S. */
1177 x_compute_glyph_string_overhangs (s
)
1178 struct glyph_string
*s
;
1181 && (s
->first_glyph
->type
== CHAR_GLYPH
1182 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1184 struct font_metrics metrics
;
1186 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1188 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1189 struct font
*font
= s
->font
;
1192 for (i
= 0; i
< s
->nchars
; i
++)
1193 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1194 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1198 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1200 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1202 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1203 ? metrics
.rbearing
- metrics
.width
: 0);
1204 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1208 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1209 s
->left_overhang
= - s
->cmp
->lbearing
;
1214 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1217 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1218 struct glyph_string
*s
;
1222 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1223 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1224 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1225 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1229 /* Draw the background of glyph_string S. If S->background_filled_p
1230 is non-zero don't draw it. FORCE_P non-zero means draw the
1231 background even if it wouldn't be drawn normally. This is used
1232 when a string preceding S draws into the background of S, or S
1233 contains the first component of a composition. */
1236 x_draw_glyph_string_background (s
, force_p
)
1237 struct glyph_string
*s
;
1240 /* Nothing to do if background has already been drawn or if it
1241 shouldn't be drawn in the first place. */
1242 if (!s
->background_filled_p
)
1244 int box_line_width
= max (s
->face
->box_line_width
, 0);
1248 /* Fill background with a stipple pattern. */
1249 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1250 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1251 s
->y
+ box_line_width
,
1252 s
->background_width
,
1253 s
->height
- 2 * box_line_width
);
1254 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1255 s
->background_filled_p
= 1;
1257 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1258 || s
->font_not_found_p
1259 || s
->extends_to_end_of_line_p
1262 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1263 s
->background_width
,
1264 s
->height
- 2 * box_line_width
);
1265 s
->background_filled_p
= 1;
1271 /* Draw the foreground of glyph string S. */
1274 x_draw_glyph_string_foreground (s
)
1275 struct glyph_string
*s
;
1279 /* If first glyph of S has a left box line, start drawing the text
1280 of S to the right of that box line. */
1281 if (s
->face
->box
!= FACE_NO_BOX
1282 && s
->first_glyph
->left_box_line_p
)
1283 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1287 /* Draw characters of S as rectangles if S's font could not be
1289 if (s
->font_not_found_p
)
1291 for (i
= 0; i
< s
->nchars
; ++i
)
1293 struct glyph
*g
= s
->first_glyph
+ i
;
1294 XDrawRectangle (s
->display
, s
->window
,
1295 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1297 x
+= g
->pixel_width
;
1302 struct font
*font
= s
->font
;
1303 int boff
= font
->baseline_offset
;
1306 if (font
->vertical_centering
)
1307 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1309 y
= s
->ybase
- boff
;
1311 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1312 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1314 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1315 if (s
->face
->overstrike
)
1316 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1320 /* Draw the foreground of composite glyph string S. */
1323 x_draw_composite_glyph_string_foreground (s
)
1324 struct glyph_string
*s
;
1327 struct font
*font
= s
->font
;
1329 /* If first glyph of S has a left box line, start drawing the text
1330 of S to the right of that box line. */
1331 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1332 && s
->first_glyph
->left_box_line_p
)
1333 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1337 /* S is a glyph string for a composition. S->cmp_from is the index
1338 of the first character drawn for glyphs of this composition.
1339 S->cmp_from == 0 means we are drawing the very first character of
1340 this composition. */
1342 /* Draw a rectangle for the composition if the font for the very
1343 first character of the composition could not be loaded. */
1344 if (s
->font_not_found_p
)
1346 if (s
->cmp_from
== 0)
1347 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1348 s
->width
- 1, s
->height
- 1);
1350 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1354 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1355 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1357 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1358 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1360 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1361 if (s
->face
->overstrike
)
1362 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1367 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1372 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1374 glyph
= LGSTRING_GLYPH (gstring
, i
);
1375 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1376 width
+= LGLYPH_WIDTH (glyph
);
1379 int xoff
, yoff
, wadjust
;
1383 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1386 xoff
= LGLYPH_XOFF (glyph
);
1387 yoff
= LGLYPH_YOFF (glyph
);
1388 wadjust
= LGLYPH_WADJUST (glyph
);
1389 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1396 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1401 #ifdef USE_X_TOOLKIT
1403 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1404 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1405 XrmValue
*, XrmValue
*, XtPointer
*));
1406 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1407 XrmValue
*, Cardinal
*));
1410 /* Return the frame on which widget WIDGET is used.. Abort if frame
1411 cannot be determined. */
1413 static struct frame
*
1414 x_frame_of_widget (widget
)
1417 struct x_display_info
*dpyinfo
;
1421 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1423 /* Find the top-level shell of the widget. Note that this function
1424 can be called when the widget is not yet realized, so XtWindow
1425 (widget) == 0. That's the reason we can't simply use
1426 x_any_window_to_frame. */
1427 while (!XtIsTopLevelShell (widget
))
1428 widget
= XtParent (widget
);
1430 /* Look for a frame with that top-level widget. Allocate the color
1431 on that frame to get the right gamma correction value. */
1432 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1433 if (FRAMEP (XCAR (tail
))
1434 && (f
= XFRAME (XCAR (tail
)),
1436 && f
->output_data
.nothing
!= 1
1437 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1438 && f
->output_data
.x
->widget
== widget
)
1445 /* Allocate the color COLOR->pixel on the screen and display of
1446 widget WIDGET in colormap CMAP. If an exact match cannot be
1447 allocated, try the nearest color available. Value is non-zero
1448 if successful. This is called from lwlib. */
1451 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1456 struct frame
*f
= x_frame_of_widget (widget
);
1457 return x_alloc_nearest_color (f
, cmap
, color
);
1461 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1462 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1463 If this produces the same color as PIXEL, try a color where all RGB
1464 values have DELTA added. Return the allocated color in *PIXEL.
1465 DISPLAY is the X display, CMAP is the colormap to operate on.
1466 Value is non-zero if successful. */
1469 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1473 unsigned long *pixel
;
1477 struct frame
*f
= x_frame_of_widget (widget
);
1478 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1482 /* Structure specifying which arguments should be passed by Xt to
1483 cvt_string_to_pixel. We want the widget's screen and colormap. */
1485 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1487 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1489 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1494 /* The address of this variable is returned by
1495 cvt_string_to_pixel. */
1497 static Pixel cvt_string_to_pixel_value
;
1500 /* Convert a color name to a pixel color.
1502 DPY is the display we are working on.
1504 ARGS is an array of *NARGS XrmValue structures holding additional
1505 information about the widget for which the conversion takes place.
1506 The contents of this array are determined by the specification
1507 in cvt_string_to_pixel_args.
1509 FROM is a pointer to an XrmValue which points to the color name to
1510 convert. TO is an XrmValue in which to return the pixel color.
1512 CLOSURE_RET is a pointer to user-data, in which we record if
1513 we allocated the color or not.
1515 Value is True if successful, False otherwise. */
1518 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1522 XrmValue
*from
, *to
;
1523 XtPointer
*closure_ret
;
1533 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1534 "wrongParameters", "cvt_string_to_pixel",
1536 "Screen and colormap args required", NULL
, NULL
);
1540 screen
= *(Screen
**) args
[0].addr
;
1541 cmap
= *(Colormap
*) args
[1].addr
;
1542 color_name
= (String
) from
->addr
;
1544 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1546 *closure_ret
= (XtPointer
) False
;
1547 pixel
= WhitePixelOfScreen (screen
);
1549 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1551 *closure_ret
= (XtPointer
) False
;
1552 pixel
= BlackPixelOfScreen (screen
);
1554 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1555 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1557 pixel
= color
.pixel
;
1558 *closure_ret
= (XtPointer
) True
;
1563 Cardinal nparams
= 1;
1565 params
[0] = color_name
;
1566 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1567 "badValue", "cvt_string_to_pixel",
1568 "XtToolkitError", "Invalid color `%s'",
1573 if (to
->addr
!= NULL
)
1575 if (to
->size
< sizeof (Pixel
))
1577 to
->size
= sizeof (Pixel
);
1581 *(Pixel
*) to
->addr
= pixel
;
1585 cvt_string_to_pixel_value
= pixel
;
1586 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1589 to
->size
= sizeof (Pixel
);
1594 /* Free a pixel color which was previously allocated via
1595 cvt_string_to_pixel. This is registered as the destructor
1596 for this type of resource via XtSetTypeConverter.
1598 APP is the application context in which we work.
1600 TO is a pointer to an XrmValue holding the color to free.
1601 CLOSURE is the value we stored in CLOSURE_RET for this color
1602 in cvt_string_to_pixel.
1604 ARGS and NARGS are like for cvt_string_to_pixel. */
1607 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1616 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1618 "Screen and colormap arguments required",
1621 else if (closure
!= NULL
)
1623 /* We did allocate the pixel, so free it. */
1624 Screen
*screen
= *(Screen
**) args
[0].addr
;
1625 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1626 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1627 (Pixel
*) to
->addr
, 1);
1632 #endif /* USE_X_TOOLKIT */
1635 /* Value is an array of XColor structures for the contents of the
1636 color map of display DPY. Set *NCELLS to the size of the array.
1637 Note that this probably shouldn't be called for large color maps,
1638 say a 24-bit TrueColor map. */
1640 static const XColor
*
1641 x_color_cells (dpy
, ncells
)
1645 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1647 if (dpyinfo
->color_cells
== NULL
)
1649 Screen
*screen
= dpyinfo
->screen
;
1652 dpyinfo
->ncolor_cells
1653 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1654 dpyinfo
->color_cells
1655 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1656 * sizeof *dpyinfo
->color_cells
);
1658 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1659 dpyinfo
->color_cells
[i
].pixel
= i
;
1661 XQueryColors (dpy
, dpyinfo
->cmap
,
1662 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1665 *ncells
= dpyinfo
->ncolor_cells
;
1666 return dpyinfo
->color_cells
;
1670 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1671 colors in COLORS. Use cached information, if available. */
1674 x_query_colors (f
, colors
, ncolors
)
1679 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1681 if (dpyinfo
->color_cells
)
1684 for (i
= 0; i
< ncolors
; ++i
)
1686 unsigned long pixel
= colors
[i
].pixel
;
1687 xassert (pixel
< dpyinfo
->ncolor_cells
);
1688 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1689 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1693 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1697 /* On frame F, translate pixel color to RGB values for the color in
1698 COLOR. Use cached information, if available. */
1701 x_query_color (f
, color
)
1705 x_query_colors (f
, color
, 1);
1709 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1710 exact match can't be allocated, try the nearest color available.
1711 Value is non-zero if successful. Set *COLOR to the color
1715 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1722 rc
= XAllocColor (dpy
, cmap
, color
);
1725 /* If we got to this point, the colormap is full, so we're going
1726 to try to get the next closest color. The algorithm used is
1727 a least-squares matching, which is what X uses for closest
1728 color matching with StaticColor visuals. */
1730 unsigned long nearest_delta
= ~0;
1732 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1734 for (nearest
= i
= 0; i
< ncells
; ++i
)
1736 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1737 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1738 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1739 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1741 if (delta
< nearest_delta
)
1744 nearest_delta
= delta
;
1748 color
->red
= cells
[nearest
].red
;
1749 color
->green
= cells
[nearest
].green
;
1750 color
->blue
= cells
[nearest
].blue
;
1751 rc
= XAllocColor (dpy
, cmap
, color
);
1755 /* If allocation succeeded, and the allocated pixel color is not
1756 equal to a cached pixel color recorded earlier, there was a
1757 change in the colormap, so clear the color cache. */
1758 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1759 XColor
*cached_color
;
1761 if (dpyinfo
->color_cells
1762 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1763 (cached_color
->red
!= color
->red
1764 || cached_color
->blue
!= color
->blue
1765 || cached_color
->green
!= color
->green
)))
1767 xfree (dpyinfo
->color_cells
);
1768 dpyinfo
->color_cells
= NULL
;
1769 dpyinfo
->ncolor_cells
= 0;
1773 #ifdef DEBUG_X_COLORS
1775 register_color (color
->pixel
);
1776 #endif /* DEBUG_X_COLORS */
1782 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1783 exact match can't be allocated, try the nearest color available.
1784 Value is non-zero if successful. Set *COLOR to the color
1788 x_alloc_nearest_color (f
, cmap
, color
)
1793 gamma_correct (f
, color
);
1794 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1798 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1799 It's necessary to do this instead of just using PIXEL directly to
1800 get color reference counts right. */
1803 x_copy_color (f
, pixel
)
1805 unsigned long pixel
;
1809 color
.pixel
= pixel
;
1811 x_query_color (f
, &color
);
1812 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1814 #ifdef DEBUG_X_COLORS
1815 register_color (pixel
);
1821 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1822 It's necessary to do this instead of just using PIXEL directly to
1823 get color reference counts right. */
1826 x_copy_dpy_color (dpy
, cmap
, pixel
)
1829 unsigned long pixel
;
1833 color
.pixel
= pixel
;
1835 XQueryColor (dpy
, cmap
, &color
);
1836 XAllocColor (dpy
, cmap
, &color
);
1838 #ifdef DEBUG_X_COLORS
1839 register_color (pixel
);
1845 /* Brightness beyond which a color won't have its highlight brightness
1848 Nominally, highlight colors for `3d' faces are calculated by
1849 brightening an object's color by a constant scale factor, but this
1850 doesn't yield good results for dark colors, so for colors who's
1851 brightness is less than this value (on a scale of 0-65535) have an
1852 use an additional additive factor.
1854 The value here is set so that the default menu-bar/mode-line color
1855 (grey75) will not have its highlights changed at all. */
1856 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1859 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1860 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1861 If this produces the same color as PIXEL, try a color where all RGB
1862 values have DELTA added. Return the allocated color in *PIXEL.
1863 DISPLAY is the X display, CMAP is the colormap to operate on.
1864 Value is non-zero if successful. */
1867 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1871 unsigned long *pixel
;
1879 /* Get RGB color values. */
1880 color
.pixel
= *pixel
;
1881 x_query_color (f
, &color
);
1883 /* Change RGB values by specified FACTOR. Avoid overflow! */
1884 xassert (factor
>= 0);
1885 new.red
= min (0xffff, factor
* color
.red
);
1886 new.green
= min (0xffff, factor
* color
.green
);
1887 new.blue
= min (0xffff, factor
* color
.blue
);
1889 /* Calculate brightness of COLOR. */
1890 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1892 /* We only boost colors that are darker than
1893 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1894 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1895 /* Make an additive adjustment to NEW, because it's dark enough so
1896 that scaling by FACTOR alone isn't enough. */
1898 /* How far below the limit this color is (0 - 1, 1 being darker). */
1899 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1900 /* The additive adjustment. */
1901 int min_delta
= delta
* dimness
* factor
/ 2;
1905 new.red
= max (0, new.red
- min_delta
);
1906 new.green
= max (0, new.green
- min_delta
);
1907 new.blue
= max (0, new.blue
- min_delta
);
1911 new.red
= min (0xffff, min_delta
+ new.red
);
1912 new.green
= min (0xffff, min_delta
+ new.green
);
1913 new.blue
= min (0xffff, min_delta
+ new.blue
);
1917 /* Try to allocate the color. */
1918 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1921 if (new.pixel
== *pixel
)
1923 /* If we end up with the same color as before, try adding
1924 delta to the RGB values. */
1925 x_free_colors (f
, &new.pixel
, 1);
1927 new.red
= min (0xffff, delta
+ color
.red
);
1928 new.green
= min (0xffff, delta
+ color
.green
);
1929 new.blue
= min (0xffff, delta
+ color
.blue
);
1930 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1941 /* Set up the foreground color for drawing relief lines of glyph
1942 string S. RELIEF is a pointer to a struct relief containing the GC
1943 with which lines will be drawn. Use a color that is FACTOR or
1944 DELTA lighter or darker than the relief's background which is found
1945 in S->f->output_data.x->relief_background. If such a color cannot
1946 be allocated, use DEFAULT_PIXEL, instead. */
1949 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1951 struct relief
*relief
;
1954 unsigned long default_pixel
;
1957 struct x_output
*di
= f
->output_data
.x
;
1958 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1959 unsigned long pixel
;
1960 unsigned long background
= di
->relief_background
;
1961 Colormap cmap
= FRAME_X_COLORMAP (f
);
1962 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1963 Display
*dpy
= FRAME_X_DISPLAY (f
);
1965 xgcv
.graphics_exposures
= False
;
1966 xgcv
.line_width
= 1;
1968 /* Free previously allocated color. The color cell will be reused
1969 when it has been freed as many times as it was allocated, so this
1970 doesn't affect faces using the same colors. */
1972 && relief
->allocated_p
)
1974 x_free_colors (f
, &relief
->pixel
, 1);
1975 relief
->allocated_p
= 0;
1978 /* Allocate new color. */
1979 xgcv
.foreground
= default_pixel
;
1981 if (dpyinfo
->n_planes
!= 1
1982 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1984 relief
->allocated_p
= 1;
1985 xgcv
.foreground
= relief
->pixel
= pixel
;
1988 if (relief
->gc
== 0)
1990 xgcv
.stipple
= dpyinfo
->gray
;
1992 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1995 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1999 /* Set up colors for the relief lines around glyph string S. */
2002 x_setup_relief_colors (s
)
2003 struct glyph_string
*s
;
2005 struct x_output
*di
= s
->f
->output_data
.x
;
2006 unsigned long color
;
2008 if (s
->face
->use_box_color_for_shadows_p
)
2009 color
= s
->face
->box_color
;
2010 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2012 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2013 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2018 /* Get the background color of the face. */
2019 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2020 color
= xgcv
.background
;
2023 if (di
->white_relief
.gc
== 0
2024 || color
!= di
->relief_background
)
2026 di
->relief_background
= color
;
2027 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2028 WHITE_PIX_DEFAULT (s
->f
));
2029 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2030 BLACK_PIX_DEFAULT (s
->f
));
2035 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2036 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2037 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2038 relief. LEFT_P non-zero means draw a relief on the left side of
2039 the rectangle. RIGHT_P non-zero means draw a relief on the right
2040 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2044 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2045 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2047 int left_x
, top_y
, right_x
, bottom_y
, width
;
2048 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2049 XRectangle
*clip_rect
;
2051 Display
*dpy
= FRAME_X_DISPLAY (f
);
2052 Window window
= FRAME_X_WINDOW (f
);
2057 gc
= f
->output_data
.x
->white_relief
.gc
;
2059 gc
= f
->output_data
.x
->black_relief
.gc
;
2060 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2064 for (i
= 0; i
< width
; ++i
)
2065 XDrawLine (dpy
, window
, gc
,
2066 left_x
+ i
* left_p
, top_y
+ i
,
2067 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2071 for (i
= 0; i
< width
; ++i
)
2072 XDrawLine (dpy
, window
, gc
,
2073 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2075 XSetClipMask (dpy
, gc
, None
);
2077 gc
= f
->output_data
.x
->black_relief
.gc
;
2079 gc
= f
->output_data
.x
->white_relief
.gc
;
2080 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2084 for (i
= 0; i
< width
; ++i
)
2085 XDrawLine (dpy
, window
, gc
,
2086 left_x
+ i
* left_p
, bottom_y
- i
,
2087 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2091 for (i
= 0; i
< width
; ++i
)
2092 XDrawLine (dpy
, window
, gc
,
2093 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2095 XSetClipMask (dpy
, gc
, None
);
2099 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2100 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2101 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2102 left side of the rectangle. RIGHT_P non-zero means draw a line
2103 on the right side of the rectangle. CLIP_RECT is the clipping
2104 rectangle to use when drawing. */
2107 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2108 left_p
, right_p
, clip_rect
)
2109 struct glyph_string
*s
;
2110 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2111 XRectangle
*clip_rect
;
2115 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2116 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2117 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2120 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2121 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2125 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2126 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2129 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2130 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2134 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2135 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2137 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2138 XSetClipMask (s
->display
, s
->gc
, None
);
2142 /* Draw a box around glyph string S. */
2145 x_draw_glyph_string_box (s
)
2146 struct glyph_string
*s
;
2148 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2149 int left_p
, right_p
;
2150 struct glyph
*last_glyph
;
2151 XRectangle clip_rect
;
2153 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2154 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2155 : window_box_right (s
->w
, s
->area
));
2157 /* The glyph that may have a right box line. */
2158 last_glyph
= (s
->cmp
|| s
->img
2160 : s
->first_glyph
+ s
->nchars
- 1);
2162 width
= eabs (s
->face
->box_line_width
);
2163 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2165 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2167 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2169 bottom_y
= top_y
+ s
->height
- 1;
2171 left_p
= (s
->first_glyph
->left_box_line_p
2172 || (s
->hl
== DRAW_MOUSE_FACE
2174 || s
->prev
->hl
!= s
->hl
)));
2175 right_p
= (last_glyph
->right_box_line_p
2176 || (s
->hl
== DRAW_MOUSE_FACE
2178 || s
->next
->hl
!= s
->hl
)));
2180 get_glyph_string_clip_rect (s
, &clip_rect
);
2182 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2183 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2184 left_p
, right_p
, &clip_rect
);
2187 x_setup_relief_colors (s
);
2188 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2189 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2194 /* Draw foreground of image glyph string S. */
2197 x_draw_image_foreground (s
)
2198 struct glyph_string
*s
;
2201 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2203 /* If first glyph of S has a left box line, start drawing it to the
2204 right of that line. */
2205 if (s
->face
->box
!= FACE_NO_BOX
2206 && s
->first_glyph
->left_box_line_p
2208 x
+= eabs (s
->face
->box_line_width
);
2210 /* If there is a margin around the image, adjust x- and y-position
2212 if (s
->slice
.x
== 0)
2213 x
+= s
->img
->hmargin
;
2214 if (s
->slice
.y
== 0)
2215 y
+= s
->img
->vmargin
;
2221 /* We can't set both a clip mask and use XSetClipRectangles
2222 because the latter also sets a clip mask. We also can't
2223 trust on the shape extension to be available
2224 (XShapeCombineRegion). So, compute the rectangle to draw
2226 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2229 XRectangle clip_rect
, image_rect
, r
;
2231 xgcv
.clip_mask
= s
->img
->mask
;
2232 xgcv
.clip_x_origin
= x
;
2233 xgcv
.clip_y_origin
= y
;
2234 xgcv
.function
= GXcopy
;
2235 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2237 get_glyph_string_clip_rect (s
, &clip_rect
);
2240 image_rect
.width
= s
->slice
.width
;
2241 image_rect
.height
= s
->slice
.height
;
2242 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2243 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2244 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2245 r
.width
, r
.height
, r
.x
, r
.y
);
2249 XRectangle clip_rect
, image_rect
, r
;
2251 get_glyph_string_clip_rect (s
, &clip_rect
);
2254 image_rect
.width
= s
->slice
.width
;
2255 image_rect
.height
= s
->slice
.height
;
2256 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2257 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2258 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2259 r
.width
, r
.height
, r
.x
, r
.y
);
2261 /* When the image has a mask, we can expect that at
2262 least part of a mouse highlight or a block cursor will
2263 be visible. If the image doesn't have a mask, make
2264 a block cursor visible by drawing a rectangle around
2265 the image. I believe it's looking better if we do
2266 nothing here for mouse-face. */
2267 if (s
->hl
== DRAW_CURSOR
)
2269 int r
= s
->img
->relief
;
2271 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2273 s
->slice
.width
+ r
*2 - 1,
2274 s
->slice
.height
+ r
*2 - 1);
2279 /* Draw a rectangle if image could not be loaded. */
2280 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2281 s
->slice
.width
- 1, s
->slice
.height
- 1);
2285 /* Draw a relief around the image glyph string S. */
2288 x_draw_image_relief (s
)
2289 struct glyph_string
*s
;
2291 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2294 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2296 /* If first glyph of S has a left box line, start drawing it to the
2297 right of that line. */
2298 if (s
->face
->box
!= FACE_NO_BOX
2299 && s
->first_glyph
->left_box_line_p
2301 x
+= eabs (s
->face
->box_line_width
);
2303 /* If there is a margin around the image, adjust x- and y-position
2305 if (s
->slice
.x
== 0)
2306 x
+= s
->img
->hmargin
;
2307 if (s
->slice
.y
== 0)
2308 y
+= s
->img
->vmargin
;
2310 if (s
->hl
== DRAW_IMAGE_SUNKEN
2311 || s
->hl
== DRAW_IMAGE_RAISED
)
2313 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2314 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2318 thick
= eabs (s
->img
->relief
);
2319 raised_p
= s
->img
->relief
> 0;
2324 x1
= x
+ s
->slice
.width
+ thick
- 1;
2325 y1
= y
+ s
->slice
.height
+ thick
- 1;
2327 x_setup_relief_colors (s
);
2328 get_glyph_string_clip_rect (s
, &r
);
2329 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2331 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2333 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2338 /* Draw the foreground of image glyph string S to PIXMAP. */
2341 x_draw_image_foreground_1 (s
, pixmap
)
2342 struct glyph_string
*s
;
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 (s
, x
, y
, w
, h
)
2420 struct glyph_string
*s
;
2425 /* Fill background with a stipple pattern. */
2426 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2427 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2428 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2431 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2435 /* Draw image glyph string S.
2438 s->x +-------------------------
2441 | +-------------------------
2444 | | +-------------------
2450 x_draw_image_glyph_string (s
)
2451 struct glyph_string
*s
;
2453 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2454 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2456 Pixmap pixmap
= None
;
2459 if (s
->slice
.y
== 0)
2460 height
-= box_line_vwidth
;
2461 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2462 height
-= box_line_vwidth
;
2464 /* Fill background with face under the image. Do it only if row is
2465 taller than image or if image has a clip mask to reduce
2467 s
->stippled_p
= s
->face
->stipple
!= 0;
2468 if (height
> s
->slice
.height
2472 || s
->img
->pixmap
== 0
2473 || s
->width
!= s
->background_width
)
2477 /* Create a pixmap as large as the glyph string. Fill it
2478 with the background color. Copy the image to it, using
2479 its mask. Copy the temporary pixmap to the display. */
2480 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2481 int depth
= DefaultDepthOfScreen (screen
);
2483 /* Create a pixmap as large as the glyph string. */
2484 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2485 s
->background_width
,
2488 /* Don't clip in the following because we're working on the
2490 XSetClipMask (s
->display
, s
->gc
, None
);
2492 /* Fill the pixmap with the background color/stipple. */
2495 /* Fill background with a stipple pattern. */
2496 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2497 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2498 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2499 0, 0, s
->background_width
, s
->height
);
2500 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2501 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2506 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2508 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2509 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2510 0, 0, s
->background_width
, s
->height
);
2511 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2519 if (s
->first_glyph
->left_box_line_p
2521 x
+= box_line_hwidth
;
2523 if (s
->slice
.y
== 0)
2524 y
+= box_line_vwidth
;
2526 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2529 s
->background_filled_p
= 1;
2532 /* Draw the foreground. */
2535 x_draw_image_foreground_1 (s
, pixmap
);
2536 x_set_glyph_string_clipping (s
);
2537 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2538 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2539 XFreePixmap (s
->display
, pixmap
);
2542 x_draw_image_foreground (s
);
2544 /* If we must draw a relief around the image, do it. */
2546 || s
->hl
== DRAW_IMAGE_RAISED
2547 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2548 x_draw_image_relief (s
);
2552 /* Draw stretch glyph string S. */
2555 x_draw_stretch_glyph_string (s
)
2556 struct glyph_string
*s
;
2558 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2560 if (s
->hl
== DRAW_CURSOR
2561 && !x_stretch_cursor_p
)
2563 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2564 as wide as the stretch glyph. */
2565 int width
, background_width
= s
->background_width
;
2566 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2570 background_width
-= left_x
- x
;
2573 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2576 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2578 /* Clear rest using the GC of the original non-cursor face. */
2579 if (width
< background_width
)
2582 int w
= background_width
- width
, h
= s
->height
;
2587 if (s
->row
->mouse_face_p
2588 && cursor_in_mouse_face_p (s
->w
))
2590 x_set_mouse_face_gc (s
);
2596 get_glyph_string_clip_rect (s
, &r
);
2597 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2599 if (s
->face
->stipple
)
2601 /* Fill background with a stipple pattern. */
2602 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2603 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2604 XSetFillStyle (s
->display
, gc
, FillSolid
);
2609 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2610 XSetForeground (s
->display
, gc
, xgcv
.background
);
2611 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2612 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2616 else if (!s
->background_filled_p
)
2618 int background_width
= s
->background_width
;
2619 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2621 /* Don't draw into left margin, fringe or scrollbar area
2622 except for header line and mode line. */
2623 if (x
< left_x
&& !s
->row
->mode_line_p
)
2625 background_width
-= left_x
- x
;
2628 if (background_width
> 0)
2629 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2632 s
->background_filled_p
= 1;
2636 /* Draw glyph string S. */
2639 x_draw_glyph_string (s
)
2640 struct glyph_string
*s
;
2642 int relief_drawn_p
= 0;
2644 /* If S draws into the background of its successors, draw the
2645 background of the successors first so that S can draw into it.
2646 This makes S->next use XDrawString instead of XDrawImageString. */
2647 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2650 struct glyph_string
*next
;
2652 for (width
= 0, next
= s
->next
;
2653 next
&& width
< s
->right_overhang
;
2654 width
+= next
->width
, next
= next
->next
)
2655 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2657 x_set_glyph_string_gc (next
);
2658 x_set_glyph_string_clipping (next
);
2659 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2660 x_draw_stretch_glyph_string (next
);
2662 x_draw_glyph_string_background (next
, 1);
2663 next
->num_clips
= 0;
2667 /* Set up S->gc, set clipping and draw S. */
2668 x_set_glyph_string_gc (s
);
2670 /* Draw relief (if any) in advance for char/composition so that the
2671 glyph string can be drawn over it. */
2672 if (!s
->for_overlaps
2673 && s
->face
->box
!= FACE_NO_BOX
2674 && (s
->first_glyph
->type
== CHAR_GLYPH
2675 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2678 x_set_glyph_string_clipping (s
);
2679 x_draw_glyph_string_background (s
, 1);
2680 x_draw_glyph_string_box (s
);
2681 x_set_glyph_string_clipping (s
);
2684 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2686 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2687 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2688 /* We must clip just this glyph. left_overhang part has already
2689 drawn when s->prev was drawn, and right_overhang part will be
2690 drawn later when s->next is drawn. */
2691 x_set_glyph_string_clipping_exactly (s
, s
);
2693 x_set_glyph_string_clipping (s
);
2695 switch (s
->first_glyph
->type
)
2698 x_draw_image_glyph_string (s
);
2702 x_draw_stretch_glyph_string (s
);
2706 if (s
->for_overlaps
)
2707 s
->background_filled_p
= 1;
2709 x_draw_glyph_string_background (s
, 0);
2710 x_draw_glyph_string_foreground (s
);
2713 case COMPOSITE_GLYPH
:
2714 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2715 && ! s
->first_glyph
->u
.cmp
.automatic
))
2716 s
->background_filled_p
= 1;
2718 x_draw_glyph_string_background (s
, 1);
2719 x_draw_composite_glyph_string_foreground (s
);
2726 if (!s
->for_overlaps
)
2728 /* Draw underline. */
2729 if (s
->face
->underline_p
)
2731 unsigned long thickness
, position
;
2734 if (s
->prev
&& s
->prev
->face
->underline_p
)
2736 /* We use the same underline style as the previous one. */
2737 thickness
= s
->prev
->underline_thickness
;
2738 position
= s
->prev
->underline_position
;
2742 /* Get the underline thickness. Default is 1 pixel. */
2743 if (s
->font
&& s
->font
->underline_thickness
> 0)
2744 thickness
= s
->font
->underline_thickness
;
2747 if (x_underline_at_descent_line
)
2748 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2751 /* Get the underline position. This is the recommended
2752 vertical offset in pixels from the baseline to the top of
2753 the underline. This is a signed value according to the
2754 specs, and its default is
2756 ROUND ((maximum descent) / 2), with
2757 ROUND(x) = floor (x + 0.5) */
2759 if (x_use_underline_position_properties
2760 && s
->font
&& s
->font
->underline_position
>= 0)
2761 position
= s
->font
->underline_position
;
2763 position
= (s
->font
->descent
+ 1) / 2;
2765 position
= underline_minimum_offset
;
2767 position
= max (position
, underline_minimum_offset
);
2769 /* Check the sanity of thickness and position. We should
2770 avoid drawing underline out of the current line area. */
2771 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2772 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2773 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2774 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2775 s
->underline_thickness
= thickness
;
2776 s
->underline_position
= position
;
2777 y
= s
->ybase
+ position
;
2778 if (s
->face
->underline_defaulted_p
)
2779 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2780 s
->x
, y
, s
->width
, thickness
);
2784 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2785 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2786 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2787 s
->x
, y
, s
->width
, thickness
);
2788 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2792 /* Draw overline. */
2793 if (s
->face
->overline_p
)
2795 unsigned long dy
= 0, h
= 1;
2797 if (s
->face
->overline_color_defaulted_p
)
2798 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2803 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2804 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2805 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2807 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2811 /* Draw strike-through. */
2812 if (s
->face
->strike_through_p
)
2814 unsigned long h
= 1;
2815 unsigned long dy
= (s
->height
- h
) / 2;
2817 if (s
->face
->strike_through_color_defaulted_p
)
2818 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2823 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2824 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2825 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2827 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2831 /* Draw relief if not yet drawn. */
2832 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2833 x_draw_glyph_string_box (s
);
2837 struct glyph_string
*prev
;
2839 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2840 if (prev
->hl
!= s
->hl
2841 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2843 /* As prev was drawn while clipped to its own area, we
2844 must draw the right_overhang part using s->hl now. */
2845 enum draw_glyphs_face save
= prev
->hl
;
2848 x_set_glyph_string_gc (prev
);
2849 x_set_glyph_string_clipping_exactly (s
, prev
);
2850 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2851 x_draw_glyph_string_foreground (prev
);
2853 x_draw_composite_glyph_string_foreground (prev
);
2854 XSetClipMask (prev
->display
, prev
->gc
, None
);
2856 prev
->num_clips
= 0;
2862 struct glyph_string
*next
;
2864 for (next
= s
->next
; next
; next
= next
->next
)
2865 if (next
->hl
!= s
->hl
2866 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2868 /* As next will be drawn while clipped to its own area,
2869 we must draw the left_overhang part using s->hl now. */
2870 enum draw_glyphs_face save
= next
->hl
;
2873 x_set_glyph_string_gc (next
);
2874 x_set_glyph_string_clipping_exactly (s
, next
);
2875 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2876 x_draw_glyph_string_foreground (next
);
2878 x_draw_composite_glyph_string_foreground (next
);
2879 XSetClipMask (next
->display
, next
->gc
, None
);
2881 next
->num_clips
= 0;
2886 /* Reset clipping. */
2887 XSetClipMask (s
->display
, s
->gc
, None
);
2891 /* Shift display to make room for inserted glyphs. */
2894 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2896 int x
, y
, width
, height
, shift_by
;
2898 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2899 f
->output_data
.x
->normal_gc
,
2900 x
, y
, width
, height
,
2904 /* Delete N glyphs at the nominal cursor position. Not implemented
2908 x_delete_glyphs (f
, n
)
2916 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2917 If they are <= 0, this is probably an error. */
2920 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2927 xassert (width
> 0 && height
> 0);
2928 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2932 /* Clear an entire frame. */
2935 x_clear_frame (struct frame
*f
)
2937 /* Clearing the frame will erase any cursor, so mark them all as no
2939 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2940 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2941 output_cursor
.x
= -1;
2943 /* We don't set the output cursor here because there will always
2944 follow an explicit cursor_to. */
2946 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2948 /* We have to clear the scroll bars, too. If we have changed
2949 colors or something like that, then they should be notified. */
2950 x_scroll_bar_clear (f
);
2952 XFlush (FRAME_X_DISPLAY (f
));
2959 /* Invert the middle quarter of the frame for .15 sec. */
2961 /* We use the select system call to do the waiting, so we have to make
2962 sure it's available. If it isn't, we just won't do visual bells. */
2964 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2967 /* Subtract the `struct timeval' values X and Y, storing the result in
2968 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2971 timeval_subtract (result
, x
, y
)
2972 struct timeval
*result
, x
, y
;
2974 /* Perform the carry for the later subtraction by updating y. This
2975 is safer because on some systems the tv_sec member is unsigned. */
2976 if (x
.tv_usec
< y
.tv_usec
)
2978 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2979 y
.tv_usec
-= 1000000 * nsec
;
2983 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2985 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2986 y
.tv_usec
+= 1000000 * nsec
;
2990 /* Compute the time remaining to wait. tv_usec is certainly
2992 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2993 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2995 /* Return indication of whether the result should be considered
2997 return x
.tv_sec
< y
.tv_sec
;
3009 /* Create a GC that will use the GXxor function to flip foreground
3010 pixels into background pixels. */
3014 values
.function
= GXxor
;
3015 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3016 ^ FRAME_BACKGROUND_PIXEL (f
));
3018 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3019 GCFunction
| GCForeground
, &values
);
3023 /* Get the height not including a menu bar widget. */
3024 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3025 /* Height of each line to flash. */
3026 int flash_height
= FRAME_LINE_HEIGHT (f
);
3027 /* These will be the left and right margins of the rectangles. */
3028 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3029 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3033 /* Don't flash the area between a scroll bar and the frame
3034 edge it is next to. */
3035 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3037 case vertical_scroll_bar_left
:
3038 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3041 case vertical_scroll_bar_right
:
3042 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3049 width
= flash_right
- flash_left
;
3051 /* If window is tall, flash top and bottom line. */
3052 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3054 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3056 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3057 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3058 width
, flash_height
);
3059 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3061 (height
- flash_height
3062 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3063 width
, flash_height
);
3066 /* If it is short, flash it all. */
3067 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3068 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3069 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3074 struct timeval wakeup
;
3076 EMACS_GET_TIME (wakeup
);
3078 /* Compute time to wait until, propagating carry from usecs. */
3079 wakeup
.tv_usec
+= 150000;
3080 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3081 wakeup
.tv_usec
%= 1000000;
3083 /* Keep waiting until past the time wakeup or any input gets
3085 while (! detect_input_pending ())
3087 struct timeval current
;
3088 struct timeval timeout
;
3090 EMACS_GET_TIME (current
);
3092 /* Break if result would be negative. */
3093 if (timeval_subtract (¤t
, wakeup
, current
))
3096 /* How long `select' should wait. */
3098 timeout
.tv_usec
= 10000;
3100 /* Try to wait that long--but we might wake up sooner. */
3101 select (0, NULL
, NULL
, NULL
, &timeout
);
3105 /* If window is tall, flash top and bottom line. */
3106 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3108 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3110 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3111 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3112 width
, flash_height
);
3113 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3115 (height
- flash_height
3116 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3117 width
, flash_height
);
3120 /* If it is short, flash it all. */
3121 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3122 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3123 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3125 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3133 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3137 XTtoggle_invisible_pointer (f
, invisible
)
3144 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3145 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3146 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
);
3149 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3150 f
->output_data
.x
->current_cursor
);
3151 f
->pointer_invisible
= invisible
;
3156 /* Make audible bell. */
3161 struct frame
*f
= SELECTED_FRAME ();
3163 if (FRAME_X_DISPLAY (f
))
3165 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3172 XBell (FRAME_X_DISPLAY (f
), 0);
3173 XFlush (FRAME_X_DISPLAY (f
));
3180 /* Specify how many text lines, from the top of the window,
3181 should be affected by insert-lines and delete-lines operations.
3182 This, and those operations, are used only within an update
3183 that is bounded by calls to x_update_begin and x_update_end. */
3186 XTset_terminal_window (n
)
3189 /* This function intentionally left blank. */
3194 /***********************************************************************
3196 ***********************************************************************/
3198 /* Perform an insert-lines or delete-lines operation, inserting N
3199 lines or deleting -N lines at vertical position VPOS. */
3202 x_ins_del_lines (f
, vpos
, n
)
3210 /* Scroll part of the display as described by RUN. */
3213 x_scroll_run (w
, run
)
3217 struct frame
*f
= XFRAME (w
->frame
);
3218 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3220 /* Get frame-relative bounding box of the text display area of W,
3221 without mode lines. Include in this box the left and right
3223 window_box (w
, -1, &x
, &y
, &width
, &height
);
3225 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3226 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3227 bottom_y
= y
+ height
;
3231 /* Scrolling up. Make sure we don't copy part of the mode
3232 line at the bottom. */
3233 if (from_y
+ run
->height
> bottom_y
)
3234 height
= bottom_y
- from_y
;
3236 height
= run
->height
;
3240 /* Scolling down. Make sure we don't copy over the mode line.
3242 if (to_y
+ run
->height
> bottom_y
)
3243 height
= bottom_y
- to_y
;
3245 height
= run
->height
;
3250 /* Cursor off. Will be switched on again in x_update_window_end. */
3254 XCopyArea (FRAME_X_DISPLAY (f
),
3255 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3256 f
->output_data
.x
->normal_gc
,
3266 /***********************************************************************
3268 ***********************************************************************/
3275 /* We used to only do this if Vx_no_window_manager was non-nil, but
3276 the ICCCM (section 4.1.6) says that the window's border pixmap
3277 and border pixel are window attributes which are "private to the
3278 client", so we can always change it to whatever we want. */
3280 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3281 f
->output_data
.x
->border_pixel
);
3283 x_update_cursor (f
, 1);
3284 x_set_frame_alpha (f
);
3288 frame_unhighlight (f
)
3291 /* We used to only do this if Vx_no_window_manager was non-nil, but
3292 the ICCCM (section 4.1.6) says that the window's border pixmap
3293 and border pixel are window attributes which are "private to the
3294 client", so we can always change it to whatever we want. */
3296 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3297 f
->output_data
.x
->border_tile
);
3299 x_update_cursor (f
, 1);
3300 x_set_frame_alpha (f
);
3303 /* The focus has changed. Update the frames as necessary to reflect
3304 the new situation. Note that we can't change the selected frame
3305 here, because the Lisp code we are interrupting might become confused.
3306 Each event gets marked with the frame in which it occurred, so the
3307 Lisp code can tell when the switch took place by examining the events. */
3310 x_new_focus_frame (dpyinfo
, frame
)
3311 struct x_display_info
*dpyinfo
;
3312 struct frame
*frame
;
3314 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3316 if (frame
!= dpyinfo
->x_focus_frame
)
3318 /* Set this before calling other routines, so that they see
3319 the correct value of x_focus_frame. */
3320 dpyinfo
->x_focus_frame
= frame
;
3322 if (old_focus
&& old_focus
->auto_lower
)
3323 x_lower_frame (old_focus
);
3325 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3326 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3328 pending_autoraise_frame
= 0;
3331 x_frame_rehighlight (dpyinfo
);
3334 /* Handle FocusIn and FocusOut state changes for FRAME.
3335 If FRAME has focus and there exists more than one frame, puts
3336 a FOCUS_IN_EVENT into *BUFP. */
3339 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
3342 struct x_display_info
*dpyinfo
;
3343 struct frame
*frame
;
3344 struct input_event
*bufp
;
3346 if (type
== FocusIn
)
3348 if (dpyinfo
->x_focus_event_frame
!= frame
)
3350 x_new_focus_frame (dpyinfo
, frame
);
3351 dpyinfo
->x_focus_event_frame
= frame
;
3353 /* Don't stop displaying the initial startup message
3354 for a switch-frame event we don't need. */
3355 if (NILP (Vterminal_frame
)
3356 && CONSP (Vframe_list
)
3357 && !NILP (XCDR (Vframe_list
)))
3359 bufp
->kind
= FOCUS_IN_EVENT
;
3360 XSETFRAME (bufp
->frame_or_window
, frame
);
3364 frame
->output_data
.x
->focus_state
|= state
;
3367 if (FRAME_XIC (frame
))
3368 XSetICFocus (FRAME_XIC (frame
));
3371 else if (type
== FocusOut
)
3373 frame
->output_data
.x
->focus_state
&= ~state
;
3375 if (dpyinfo
->x_focus_event_frame
== frame
)
3377 dpyinfo
->x_focus_event_frame
= 0;
3378 x_new_focus_frame (dpyinfo
, 0);
3382 if (FRAME_XIC (frame
))
3383 XUnsetICFocus (FRAME_XIC (frame
));
3385 if (frame
->pointer_invisible
)
3386 XTtoggle_invisible_pointer (frame
, 0);
3390 /* The focus may have changed. Figure out if it is a real focus change,
3391 by checking both FocusIn/Out and Enter/LeaveNotify events.
3393 Returns FOCUS_IN_EVENT event in *BUFP. */
3396 x_detect_focus_change (dpyinfo
, event
, bufp
)
3397 struct x_display_info
*dpyinfo
;
3399 struct input_event
*bufp
;
3401 struct frame
*frame
;
3403 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3407 switch (event
->type
)
3412 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3414 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3416 if (event
->xcrossing
.detail
!= NotifyInferior
3417 && event
->xcrossing
.focus
3418 && ! (focus_state
& FOCUS_EXPLICIT
))
3419 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3421 dpyinfo
, frame
, bufp
);
3427 x_focus_changed (event
->type
,
3428 (event
->xfocus
.detail
== NotifyPointer
?
3429 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3430 dpyinfo
, frame
, bufp
);
3434 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3436 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3437 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3438 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3445 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3448 x_mouse_leave (dpyinfo
)
3449 struct x_display_info
*dpyinfo
;
3451 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3454 /* The focus has changed, or we have redirected a frame's focus to
3455 another frame (this happens when a frame uses a surrogate
3456 mini-buffer frame). Shift the highlight as appropriate.
3458 The FRAME argument doesn't necessarily have anything to do with which
3459 frame is being highlighted or un-highlighted; we only use it to find
3460 the appropriate X display info. */
3463 XTframe_rehighlight (frame
)
3464 struct frame
*frame
;
3466 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3470 x_frame_rehighlight (dpyinfo
)
3471 struct x_display_info
*dpyinfo
;
3473 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3475 if (dpyinfo
->x_focus_frame
)
3477 dpyinfo
->x_highlight_frame
3478 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3479 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3480 : dpyinfo
->x_focus_frame
);
3481 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3483 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3484 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3488 dpyinfo
->x_highlight_frame
= 0;
3490 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3493 frame_unhighlight (old_highlight
);
3494 if (dpyinfo
->x_highlight_frame
)
3495 frame_highlight (dpyinfo
->x_highlight_frame
);
3501 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3503 /* Initialize mode_switch_bit and modifier_meaning. */
3505 x_find_modifier_meanings (dpyinfo
)
3506 struct x_display_info
*dpyinfo
;
3508 int min_code
, max_code
;
3511 XModifierKeymap
*mods
;
3513 dpyinfo
->meta_mod_mask
= 0;
3514 dpyinfo
->shift_lock_mask
= 0;
3515 dpyinfo
->alt_mod_mask
= 0;
3516 dpyinfo
->super_mod_mask
= 0;
3517 dpyinfo
->hyper_mod_mask
= 0;
3519 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3521 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3522 min_code
, max_code
- min_code
+ 1,
3524 mods
= XGetModifierMapping (dpyinfo
->display
);
3526 /* Scan the modifier table to see which modifier bits the Meta and
3527 Alt keysyms are on. */
3529 int row
, col
; /* The row and column in the modifier table. */
3530 int found_alt_or_meta
;
3532 for (row
= 3; row
< 8; row
++)
3534 found_alt_or_meta
= 0;
3535 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3537 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3539 /* Zeroes are used for filler. Skip them. */
3543 /* Are any of this keycode's keysyms a meta key? */
3547 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3549 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3555 found_alt_or_meta
= 1;
3556 dpyinfo
->meta_mod_mask
|= (1 << row
);
3561 found_alt_or_meta
= 1;
3562 dpyinfo
->alt_mod_mask
|= (1 << row
);
3567 if (!found_alt_or_meta
)
3568 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3569 code_col
= syms_per_code
;
3570 col
= mods
->max_keypermod
;
3575 if (!found_alt_or_meta
)
3576 dpyinfo
->super_mod_mask
|= (1 << row
);
3577 code_col
= syms_per_code
;
3578 col
= mods
->max_keypermod
;
3582 /* Ignore this if it's not on the lock modifier. */
3583 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3584 dpyinfo
->shift_lock_mask
= LockMask
;
3585 code_col
= syms_per_code
;
3586 col
= mods
->max_keypermod
;
3595 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3596 if (! dpyinfo
->meta_mod_mask
)
3598 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3599 dpyinfo
->alt_mod_mask
= 0;
3602 /* If some keys are both alt and meta,
3603 make them just meta, not alt. */
3604 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3606 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3609 XFree ((char *) syms
);
3610 XFreeModifiermap (mods
);
3613 /* Convert between the modifier bits X uses and the modifier bits
3617 x_x_to_emacs_modifiers (dpyinfo
, state
)
3618 struct x_display_info
*dpyinfo
;
3621 EMACS_UINT mod_meta
= meta_modifier
;
3622 EMACS_UINT mod_alt
= alt_modifier
;
3623 EMACS_UINT mod_hyper
= hyper_modifier
;
3624 EMACS_UINT mod_super
= super_modifier
;
3627 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3628 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3629 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3630 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3631 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3632 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3633 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3634 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3637 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3638 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3639 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3640 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3641 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3642 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3646 x_emacs_to_x_modifiers (dpyinfo
, state
)
3647 struct x_display_info
*dpyinfo
;
3650 EMACS_UINT mod_meta
= meta_modifier
;
3651 EMACS_UINT mod_alt
= alt_modifier
;
3652 EMACS_UINT mod_hyper
= hyper_modifier
;
3653 EMACS_UINT mod_super
= super_modifier
;
3657 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3658 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3659 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3660 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3661 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3662 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3663 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3664 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3667 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3668 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3669 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3670 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3671 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3672 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3675 /* Convert a keysym to its name. */
3678 x_get_keysym_name (keysym
)
3684 value
= XKeysymToString (keysym
);
3692 /* Mouse clicks and mouse movement. Rah. */
3694 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3696 If the event is a button press, then note that we have grabbed
3700 construct_mouse_click (result
, event
, f
)
3701 struct input_event
*result
;
3702 XButtonEvent
*event
;
3705 /* Make the event type NO_EVENT; we'll change that when we decide
3707 result
->kind
= MOUSE_CLICK_EVENT
;
3708 result
->code
= event
->button
- Button1
;
3709 result
->timestamp
= event
->time
;
3710 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3712 | (event
->type
== ButtonRelease
3716 XSETINT (result
->x
, event
->x
);
3717 XSETINT (result
->y
, event
->y
);
3718 XSETFRAME (result
->frame_or_window
, f
);
3724 /* Function to report a mouse movement to the mainstream Emacs code.
3725 The input handler calls this.
3727 We have received a mouse movement event, which is given in *event.
3728 If the mouse is over a different glyph than it was last time, tell
3729 the mainstream emacs code by setting mouse_moved. If not, ask for
3730 another motion event, so we can check again the next time it moves. */
3732 static XMotionEvent last_mouse_motion_event
;
3733 static Lisp_Object last_mouse_motion_frame
;
3736 note_mouse_movement (frame
, event
)
3738 XMotionEvent
*event
;
3740 last_mouse_movement_time
= event
->time
;
3741 last_mouse_motion_event
= *event
;
3742 XSETFRAME (last_mouse_motion_frame
, frame
);
3744 if (!FRAME_X_OUTPUT (frame
))
3747 if (event
->window
!= FRAME_X_WINDOW (frame
))
3749 frame
->mouse_moved
= 1;
3750 last_mouse_scroll_bar
= Qnil
;
3751 note_mouse_highlight (frame
, -1, -1);
3752 last_mouse_glyph_frame
= 0;
3757 /* Has the mouse moved off the glyph it was on at the last sighting? */
3758 if (frame
!= last_mouse_glyph_frame
3759 || event
->x
< last_mouse_glyph
.x
3760 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3761 || event
->y
< last_mouse_glyph
.y
3762 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3764 frame
->mouse_moved
= 1;
3765 last_mouse_scroll_bar
= Qnil
;
3766 note_mouse_highlight (frame
, event
->x
, event
->y
);
3767 /* Remember which glyph we're now on. */
3768 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3769 last_mouse_glyph_frame
= frame
;
3777 /************************************************************************
3779 ************************************************************************/
3782 redo_mouse_highlight ()
3784 if (!NILP (last_mouse_motion_frame
)
3785 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3786 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3787 last_mouse_motion_event
.x
,
3788 last_mouse_motion_event
.y
);
3793 /* Return the current position of the mouse.
3794 *FP should be a frame which indicates which display to ask about.
3796 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3797 and *PART to the frame, window, and scroll bar part that the mouse
3798 is over. Set *X and *Y to the portion and whole of the mouse's
3799 position on the scroll bar.
3801 If the mouse movement started elsewhere, set *FP to the frame the
3802 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3805 Set *TIME to the server time-stamp for the time at which the mouse
3806 was at this position.
3808 Don't store anything if we don't have a valid set of values to report.
3810 This clears the mouse_moved flag, so we can wait for the next mouse
3814 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3817 Lisp_Object
*bar_window
;
3818 enum scroll_bar_part
*part
;
3820 unsigned long *time
;
3826 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3827 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3833 Window dummy_window
;
3836 Lisp_Object frame
, tail
;
3838 /* Clear the mouse-moved flag for every frame on this display. */
3839 FOR_EACH_FRAME (tail
, frame
)
3840 if (FRAME_X_P (XFRAME (frame
))
3841 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3842 XFRAME (frame
)->mouse_moved
= 0;
3844 last_mouse_scroll_bar
= Qnil
;
3846 /* Figure out which root window we're on. */
3847 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3848 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3850 /* The root window which contains the pointer. */
3853 /* Trash which we can't trust if the pointer is on
3854 a different screen. */
3857 /* The position on that root window. */
3860 /* More trash we can't trust. */
3863 /* Modifier keys and pointer buttons, about which
3865 (unsigned int *) &dummy
);
3867 /* Now we have a position on the root; find the innermost window
3868 containing the pointer. */
3872 int parent_x
= 0, parent_y
= 0;
3876 /* XTranslateCoordinates can get errors if the window
3877 structure is changing at the same time this function
3878 is running. So at least we must not crash from them. */
3880 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3882 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3883 && FRAME_LIVE_P (last_mouse_frame
))
3885 /* If mouse was grabbed on a frame, give coords for that frame
3886 even if the mouse is now outside it. */
3887 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3889 /* From-window, to-window. */
3890 root
, FRAME_X_WINDOW (last_mouse_frame
),
3892 /* From-position, to-position. */
3893 root_x
, root_y
, &win_x
, &win_y
,
3897 f1
= last_mouse_frame
;
3903 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3905 /* From-window, to-window. */
3908 /* From-position, to-position. */
3909 root_x
, root_y
, &win_x
, &win_y
,
3914 if (child
== None
|| child
== win
)
3917 /* We don't wan't to know the innermost window. We
3918 want the edit window. For non-Gtk+ the innermost
3919 window is the edit window. For Gtk+ it might not
3920 be. It might be the tool bar for example. */
3921 if (x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
))
3929 /* Now we know that:
3930 win is the innermost window containing the pointer
3931 (XTC says it has no child containing the pointer),
3932 win_x and win_y are the pointer's position in it
3933 (XTC did this the last time through), and
3934 parent_x and parent_y are the pointer's position in win's parent.
3935 (They are what win_x and win_y were when win was child.
3936 If win is the root window, it has no parent, and
3937 parent_{x,y} are invalid, but that's okay, because we'll
3938 never use them in that case.) */
3941 /* We don't wan't to know the innermost window. We
3942 want the edit window. */
3943 f1
= x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3945 /* Is win one of our frames? */
3946 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3949 #ifdef USE_X_TOOLKIT
3950 /* If we end up with the menu bar window, say it's not
3953 && f1
->output_data
.x
->menubar_widget
3954 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3956 #endif /* USE_X_TOOLKIT */
3959 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3962 x_uncatch_errors ();
3964 /* If not, is it one of our scroll bars? */
3967 struct scroll_bar
*bar
;
3969 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3973 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3979 if (f1
== 0 && insist
> 0)
3980 f1
= SELECTED_FRAME ();
3984 /* Ok, we found a frame. Store all the values.
3985 last_mouse_glyph is a rectangle used to reduce the
3986 generation of mouse events. To not miss any motion
3987 events, we must divide the frame into rectangles of the
3988 size of the smallest character that could be displayed
3989 on it, i.e. into the same rectangles that matrices on
3990 the frame are divided into. */
3992 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3993 last_mouse_glyph_frame
= f1
;
3998 XSETINT (*x
, win_x
);
3999 XSETINT (*y
, win_y
);
4000 *time
= last_mouse_movement_time
;
4010 /***********************************************************************
4012 ***********************************************************************/
4014 /* Scroll bar support. */
4016 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4018 This can be called in GC, so we have to make sure to strip off mark
4021 static struct scroll_bar
*
4022 x_window_to_scroll_bar (display
, window_id
)
4028 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4029 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4030 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4032 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4034 Lisp_Object frame
, bar
, condemned
;
4036 frame
= XCAR (tail
);
4037 /* All elements of Vframe_list should be frames. */
4038 if (! FRAMEP (frame
))
4041 if (! FRAME_X_P (XFRAME (frame
)))
4044 /* Scan this frame's scroll bar list for a scroll bar with the
4046 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4047 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4048 /* This trick allows us to search both the ordinary and
4049 condemned scroll bar lists with one loop. */
4050 ! NILP (bar
) || (bar
= condemned
,
4053 bar
= XSCROLL_BAR (bar
)->next
)
4054 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4055 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4056 return XSCROLL_BAR (bar
);
4063 #if defined USE_LUCID
4065 /* Return the Lucid menu bar WINDOW is part of. Return null
4066 if WINDOW is not part of a menu bar. */
4069 x_window_to_menu_bar (window
)
4074 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4076 if (FRAME_X_P (XFRAME (XCAR (tail
))))
4078 Lisp_Object frame
= XCAR (tail
);
4079 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4081 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4089 #endif /* USE_LUCID */
4092 /************************************************************************
4094 ************************************************************************/
4096 #ifdef USE_TOOLKIT_SCROLL_BARS
4098 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
4099 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
4100 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
4101 struct scroll_bar
*));
4102 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4106 /* Lisp window being scrolled. Set when starting to interact with
4107 a toolkit scroll bar, reset to nil when ending the interaction. */
4109 static Lisp_Object window_being_scrolled
;
4111 /* Last scroll bar part sent in xm_scroll_callback. */
4113 static int last_scroll_bar_part
;
4115 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4116 that movements of 1/20 of the screen size are mapped to up/down. */
4119 /* Id of action hook installed for scroll bars. */
4121 static XtActionHookId action_hook_id
;
4123 static Boolean xaw3d_arrow_scroll
;
4125 /* Whether the drag scrolling maintains the mouse at the top of the
4126 thumb. If not, resizing the thumb needs to be done more carefully
4127 to avoid jerkyness. */
4129 static Boolean xaw3d_pick_top
;
4131 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4132 bars are used.. The hook is responsible for detecting when
4133 the user ends an interaction with the scroll bar, and generates
4134 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4137 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
4140 XtPointer client_data
;
4144 Cardinal
*num_params
;
4150 scroll_bar_p
= XmIsScrollBar (widget
);
4151 end_action
= "Release";
4152 #else /* !USE_MOTIF i.e. use Xaw */
4153 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4154 end_action
= "EndScroll";
4155 #endif /* USE_MOTIF */
4158 && strcmp (action_name
, end_action
) == 0
4159 && WINDOWP (window_being_scrolled
))
4163 x_send_scroll_bar_event (window_being_scrolled
,
4164 scroll_bar_end_scroll
, 0, 0);
4165 w
= XWINDOW (window_being_scrolled
);
4167 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4169 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4170 /* The thumb size is incorrect while dragging: fix it. */
4171 set_vertical_scroll_bar (w
);
4173 window_being_scrolled
= Qnil
;
4174 last_scroll_bar_part
= -1;
4176 /* Xt timeouts no longer needed. */
4177 toolkit_scroll_bar_interaction
= 0;
4180 #endif /* not USE_GTK */
4182 /* A vector of windows used for communication between
4183 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4185 static struct window
**scroll_bar_windows
;
4186 static int scroll_bar_windows_size
;
4189 /* Send a client message with message type Xatom_Scrollbar for a
4190 scroll action to the frame of WINDOW. PART is a value identifying
4191 the part of the scroll bar that was clicked on. PORTION is the
4192 amount to scroll of a whole of WHOLE. */
4195 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4197 int part
, portion
, whole
;
4200 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4201 struct window
*w
= XWINDOW (window
);
4202 struct frame
*f
= XFRAME (w
->frame
);
4207 /* Construct a ClientMessage event to send to the frame. */
4208 ev
->type
= ClientMessage
;
4209 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4210 ev
->display
= FRAME_X_DISPLAY (f
);
4211 ev
->window
= FRAME_X_WINDOW (f
);
4214 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4215 not enough to store a pointer or Lisp_Object on a 64 bit system.
4216 So, store the window in scroll_bar_windows and pass the index
4217 into that array in the event. */
4218 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4219 if (scroll_bar_windows
[i
] == NULL
)
4222 if (i
== scroll_bar_windows_size
)
4224 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4225 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4226 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4228 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4230 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4231 scroll_bar_windows_size
= new_size
;
4234 scroll_bar_windows
[i
] = w
;
4235 ev
->data
.l
[0] = (long) i
;
4236 ev
->data
.l
[1] = (long) part
;
4237 ev
->data
.l
[2] = (long) 0;
4238 ev
->data
.l
[3] = (long) portion
;
4239 ev
->data
.l
[4] = (long) whole
;
4241 /* Make Xt timeouts work while the scroll bar is active. */
4242 toolkit_scroll_bar_interaction
= 1;
4243 #ifdef USE_X_TOOLKIT
4244 x_activate_timeout_atimer ();
4247 /* Setting the event mask to zero means that the message will
4248 be sent to the client that created the window, and if that
4249 window no longer exists, no event will be sent. */
4250 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4255 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4259 x_scroll_bar_to_input_event (event
, ievent
)
4261 struct input_event
*ievent
;
4263 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4268 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4269 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4271 XSETWINDOW (window
, w
);
4272 f
= XFRAME (w
->frame
);
4274 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4275 ievent
->frame_or_window
= window
;
4278 ievent
->timestamp
= CurrentTime
;
4280 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4282 ievent
->part
= ev
->data
.l
[1];
4283 ievent
->code
= ev
->data
.l
[2];
4284 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4285 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4286 ievent
->modifiers
= 0;
4292 /* Minimum and maximum values used for Motif scroll bars. */
4294 #define XM_SB_MAX 10000000
4297 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4298 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4299 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4302 xm_scroll_callback (widget
, client_data
, call_data
)
4304 XtPointer client_data
, call_data
;
4306 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4307 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4308 int part
= -1, whole
= 0, portion
= 0;
4312 case XmCR_DECREMENT
:
4313 bar
->dragging
= Qnil
;
4314 part
= scroll_bar_up_arrow
;
4317 case XmCR_INCREMENT
:
4318 bar
->dragging
= Qnil
;
4319 part
= scroll_bar_down_arrow
;
4322 case XmCR_PAGE_DECREMENT
:
4323 bar
->dragging
= Qnil
;
4324 part
= scroll_bar_above_handle
;
4327 case XmCR_PAGE_INCREMENT
:
4328 bar
->dragging
= Qnil
;
4329 part
= scroll_bar_below_handle
;
4333 bar
->dragging
= Qnil
;
4334 part
= scroll_bar_to_top
;
4337 case XmCR_TO_BOTTOM
:
4338 bar
->dragging
= Qnil
;
4339 part
= scroll_bar_to_bottom
;
4346 /* Get the slider size. */
4348 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4351 whole
= XM_SB_MAX
- slider_size
;
4352 portion
= min (cs
->value
, whole
);
4353 part
= scroll_bar_handle
;
4354 bar
->dragging
= make_number (cs
->value
);
4358 case XmCR_VALUE_CHANGED
:
4364 window_being_scrolled
= bar
->window
;
4365 last_scroll_bar_part
= part
;
4366 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4370 #elif defined USE_GTK
4372 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4373 bar widget. DATA is a pointer to the scroll_bar structure. */
4376 xg_scroll_callback (widget
, data
)
4380 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4386 int part
= -1, whole
= 0, portion
= 0;
4387 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4389 position
= gtk_adjustment_get_value (adj
);
4391 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4394 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4396 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4402 if (xg_ignore_gtk_scrollbar
) return;
4404 diff
= (int) (position
- previous
);
4406 if (diff
== (int) adj
->step_increment
)
4408 part
= scroll_bar_down_arrow
;
4409 bar
->dragging
= Qnil
;
4411 else if (-diff
== (int) adj
->step_increment
)
4413 part
= scroll_bar_up_arrow
;
4414 bar
->dragging
= Qnil
;
4416 else if (diff
== (int) adj
->page_increment
)
4418 part
= scroll_bar_below_handle
;
4419 bar
->dragging
= Qnil
;
4421 else if (-diff
== (int) adj
->page_increment
)
4423 part
= scroll_bar_above_handle
;
4424 bar
->dragging
= Qnil
;
4428 part
= scroll_bar_handle
;
4429 whole
= adj
->upper
- adj
->page_size
;
4430 portion
= min ((int)position
, whole
);
4431 bar
->dragging
= make_number ((int)portion
);
4436 window_being_scrolled
= bar
->window
;
4437 last_scroll_bar_part
= part
;
4438 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4442 #else /* not USE_GTK and not USE_MOTIF */
4444 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4445 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4446 scroll bar struct. CALL_DATA is a pointer to a float saying where
4450 xaw_jump_callback (widget
, client_data
, call_data
)
4452 XtPointer client_data
, call_data
;
4454 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4455 float top
= *(float *) call_data
;
4457 int whole
, portion
, height
;
4460 /* Get the size of the thumb, a value between 0 and 1. */
4462 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4466 portion
= shown
< 1 ? top
* whole
: 0;
4468 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4469 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4470 the bottom, so we force the scrolling whenever we see that we're
4471 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4472 we try to ensure that we always stay two pixels away from the
4474 part
= scroll_bar_down_arrow
;
4476 part
= scroll_bar_handle
;
4478 window_being_scrolled
= bar
->window
;
4479 bar
->dragging
= make_number (portion
);
4480 last_scroll_bar_part
= part
;
4481 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4485 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4486 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4487 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4488 the scroll bar. CALL_DATA is an integer specifying the action that
4489 has taken place. Its magnitude is in the range 0..height of the
4490 scroll bar. Negative values mean scroll towards buffer start.
4491 Values < height of scroll bar mean line-wise movement. */
4494 xaw_scroll_callback (widget
, client_data
, call_data
)
4496 XtPointer client_data
, call_data
;
4498 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4499 /* The position really is stored cast to a pointer. */
4500 int position
= (long) call_data
;
4504 /* Get the height of the scroll bar. */
4506 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4509 if (eabs (position
) >= height
)
4510 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4512 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4513 it maps line-movement to call_data = max(5, height/20). */
4514 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4515 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4517 part
= scroll_bar_move_ratio
;
4519 window_being_scrolled
= bar
->window
;
4520 bar
->dragging
= Qnil
;
4521 last_scroll_bar_part
= part
;
4522 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4525 #endif /* not USE_GTK and not USE_MOTIF */
4527 #define SCROLL_BAR_NAME "verticalScrollBar"
4529 /* Create the widget for scroll bar BAR on frame F. Record the widget
4530 and X window of the scroll bar in BAR. */
4534 x_create_toolkit_scroll_bar (f
, bar
)
4536 struct scroll_bar
*bar
;
4538 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4541 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4546 #else /* not USE_GTK */
4549 x_create_toolkit_scroll_bar (f
, bar
)
4551 struct scroll_bar
*bar
;
4557 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4558 unsigned long pixel
;
4563 /* Set resources. Create the widget. */
4564 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4565 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4566 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4567 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4568 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4569 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4570 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4572 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4575 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4579 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4582 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4586 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4587 scroll_bar_name
, av
, ac
);
4589 /* Add one callback for everything that can happen. */
4590 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4592 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4594 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4596 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4598 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4600 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4602 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4605 /* Realize the widget. Only after that is the X window created. */
4606 XtRealizeWidget (widget
);
4608 /* Set the cursor to an arrow. I didn't find a resource to do that.
4609 And I'm wondering why it hasn't an arrow cursor by default. */
4610 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4611 f
->output_data
.x
->nontext_cursor
);
4613 #else /* !USE_MOTIF i.e. use Xaw */
4615 /* Set resources. Create the widget. The background of the
4616 Xaw3d scroll bar widget is a little bit light for my taste.
4617 We don't alter it here to let users change it according
4618 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4619 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4620 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4621 /* For smoother scrolling with Xaw3d -sm */
4622 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4624 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4627 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4631 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4634 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4638 /* Top/bottom shadow colors. */
4640 /* Allocate them, if necessary. */
4641 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4643 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4646 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4647 FRAME_X_COLORMAP (f
),
4648 &pixel
, 1.2, 0x8000))
4650 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4653 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4655 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4658 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4659 FRAME_X_COLORMAP (f
),
4660 &pixel
, 0.6, 0x4000))
4662 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4666 #ifdef XtNbeNiceToColormap
4667 /* Tell the toolkit about them. */
4668 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4669 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4670 /* We tried to allocate a color for the top/bottom shadow, and
4671 failed, so tell Xaw3d to use dithering instead. */
4673 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4677 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4678 be more consistent with other emacs 3d colors, and since Xaw3d is
4679 not good at dealing with allocation failure. */
4681 /* This tells Xaw3d to use real colors instead of dithering for
4683 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4686 /* Specify the colors. */
4687 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4690 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4693 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4696 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4702 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4703 f
->output_data
.x
->edit_widget
, av
, ac
);
4707 char *val
= initial
;
4708 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4709 #ifdef XtNarrowScrollbars
4710 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4712 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4713 if (xaw3d_arrow_scroll
|| val
== initial
)
4714 { /* ARROW_SCROLL */
4715 xaw3d_arrow_scroll
= True
;
4716 /* Isn't that just a personal preference ? --Stef */
4717 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4721 /* Define callbacks. */
4722 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4723 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4726 /* Realize the widget. Only after that is the X window created. */
4727 XtRealizeWidget (widget
);
4729 #endif /* !USE_MOTIF */
4731 /* Install an action hook that lets us detect when the user
4732 finishes interacting with a scroll bar. */
4733 if (action_hook_id
== 0)
4734 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4736 /* Remember X window and widget in the scroll bar vector. */
4737 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4738 xwindow
= XtWindow (widget
);
4739 bar
->x_window
= xwindow
;
4743 #endif /* not USE_GTK */
4746 /* Set the thumb size and position of scroll bar BAR. We are currently
4747 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4751 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4752 struct scroll_bar
*bar
;
4753 int portion
, position
, whole
;
4755 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4758 #else /* not USE_GTK */
4760 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4761 struct scroll_bar
*bar
;
4762 int portion
, position
, whole
;
4764 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4765 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4772 /* We use an estimate of 30 chars per line rather than the real
4773 `portion' value. This has the disadvantage that the thumb size
4774 is not very representative, but it makes our life a lot easier.
4775 Otherwise, we have to constantly adjust the thumb size, which
4776 we can't always do quickly enough: while dragging, the size of
4777 the thumb might prevent the user from dragging the thumb all the
4778 way to the end. but Motif and some versions of Xaw3d don't allow
4779 updating the thumb size while dragging. Also, even if we can update
4780 its size, the update will often happen too late.
4781 If you don't believe it, check out revision 1.650 of xterm.c to see
4782 what hoops we were going through and the still poor behavior we got. */
4783 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4784 /* When the thumb is at the bottom, position == whole.
4785 So we need to increase `whole' to make space for the thumb. */
4792 top
= (float) position
/ whole
;
4793 shown
= (float) portion
/ whole
;
4796 if (NILP (bar
->dragging
))
4800 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4801 is the scroll bar's maximum and MIN is the scroll bar's minimum
4803 size
= shown
* XM_SB_MAX
;
4804 size
= min (size
, XM_SB_MAX
);
4805 size
= max (size
, 1);
4807 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4808 value
= top
* XM_SB_MAX
;
4809 value
= min (value
, XM_SB_MAX
- size
);
4811 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4813 #else /* !USE_MOTIF i.e. use Xaw */
4819 top
= (float) position
/ whole
;
4820 shown
= (float) portion
/ whole
;
4824 float old_top
, old_shown
;
4826 XtVaGetValues (widget
,
4827 XtNtopOfThumb
, &old_top
,
4828 XtNshown
, &old_shown
,
4832 /* Massage the top+shown values. */
4833 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4834 top
= max (0, min (1, top
));
4837 /* Keep two pixels available for moving the thumb down. */
4838 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4840 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4841 check that your system's configuration file contains a define
4842 for `NARROWPROTO'. See s/freebsd.h for an example. */
4843 if (top
!= old_top
|| shown
!= old_shown
)
4845 if (NILP (bar
->dragging
))
4846 XawScrollbarSetThumb (widget
, top
, shown
);
4849 /* Try to make the scrolling a tad smoother. */
4850 if (!xaw3d_pick_top
)
4851 shown
= min (shown
, old_shown
);
4853 XawScrollbarSetThumb (widget
, top
, shown
);
4857 #endif /* !USE_MOTIF */
4861 #endif /* not USE_GTK */
4863 #endif /* USE_TOOLKIT_SCROLL_BARS */
4867 /************************************************************************
4868 Scroll bars, general
4869 ************************************************************************/
4871 /* Create a scroll bar and return the scroll bar vector for it. W is
4872 the Emacs window on which to create the scroll bar. TOP, LEFT,
4873 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4876 static struct scroll_bar
*
4877 x_scroll_bar_create (w
, top
, left
, width
, height
)
4879 int top
, left
, width
, height
;
4881 struct frame
*f
= XFRAME (w
->frame
);
4882 struct scroll_bar
*bar
4883 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4887 #ifdef USE_TOOLKIT_SCROLL_BARS
4888 x_create_toolkit_scroll_bar (f
, bar
);
4889 #else /* not USE_TOOLKIT_SCROLL_BARS */
4891 XSetWindowAttributes a
;
4895 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4896 if (a
.background_pixel
== -1)
4897 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4899 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4900 | ButtonMotionMask
| PointerMotionHintMask
4902 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4904 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4906 /* Clear the area of W that will serve as a scroll bar. This is
4907 for the case that a window has been split horizontally. In
4908 this case, no clear_frame is generated to reduce flickering. */
4909 if (width
> 0 && height
> 0)
4910 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4912 window_box_height (w
), False
);
4914 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4915 /* Position and size of scroll bar. */
4916 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4918 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4920 /* Border width, depth, class, and visual. */
4927 bar
->x_window
= window
;
4929 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4931 XSETWINDOW (bar
->window
, w
);
4935 bar
->height
= height
;
4938 bar
->dragging
= Qnil
;
4939 bar
->fringe_extended_p
= 0;
4941 /* Add bar to its frame's list of scroll bars. */
4942 bar
->next
= FRAME_SCROLL_BARS (f
);
4944 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4945 if (!NILP (bar
->next
))
4946 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4948 /* Map the window/widget. */
4949 #ifdef USE_TOOLKIT_SCROLL_BARS
4952 xg_update_scrollbar_pos (f
,
4955 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4956 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4958 xg_show_scroll_bar (bar
->x_window
);
4959 #else /* not USE_GTK */
4960 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4961 XtConfigureWidget (scroll_bar
,
4962 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4964 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4965 max (height
, 1), 0);
4966 XtMapWidget (scroll_bar
);
4967 #endif /* not USE_GTK */
4969 #else /* not USE_TOOLKIT_SCROLL_BARS */
4970 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
4971 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4978 #ifndef USE_TOOLKIT_SCROLL_BARS
4980 /* Draw BAR's handle in the proper position.
4982 If the handle is already drawn from START to END, don't bother
4983 redrawing it, unless REBUILD is non-zero; in that case, always
4984 redraw it. (REBUILD is handy for drawing the handle after expose
4987 Normally, we want to constrain the start and end of the handle to
4988 fit inside its rectangle, but if the user is dragging the scroll
4989 bar handle, we want to let them drag it down all the way, so that
4990 the bar's top is as far down as it goes; otherwise, there's no way
4991 to move to the very end of the buffer. */
4994 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4995 struct scroll_bar
*bar
;
4999 int dragging
= ! NILP (bar
->dragging
);
5000 Window w
= bar
->x_window
;
5001 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5002 GC gc
= f
->output_data
.x
->normal_gc
;
5004 /* If the display is already accurate, do nothing. */
5006 && start
== bar
->start
5013 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
5014 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5015 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5017 /* Make sure the values are reasonable, and try to preserve
5018 the distance between start and end. */
5020 int length
= end
- start
;
5024 else if (start
> top_range
)
5026 end
= start
+ length
;
5030 else if (end
> top_range
&& ! dragging
)
5034 /* Store the adjusted setting in the scroll bar. */
5038 /* Clip the end position, just for display. */
5039 if (end
> top_range
)
5042 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5043 below top positions, to make sure the handle is always at least
5044 that many pixels tall. */
5045 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5047 /* Draw the empty space above the handle. Note that we can't clear
5048 zero-height areas; that means "clear to end of window." */
5050 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5051 /* x, y, width, height, and exposures. */
5052 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5053 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5054 inside_width
, start
,
5057 /* Change to proper foreground color if one is specified. */
5058 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5059 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5060 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5062 /* Draw the handle itself. */
5063 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5064 /* x, y, width, height */
5065 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5066 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5067 inside_width
, end
- start
);
5069 /* Restore the foreground color of the GC if we changed it above. */
5070 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5071 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5072 FRAME_FOREGROUND_PIXEL (f
));
5074 /* Draw the empty space below the handle. Note that we can't
5075 clear zero-height areas; that means "clear to end of window." */
5076 if (end
< inside_height
)
5077 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5078 /* x, y, width, height, and exposures. */
5079 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5080 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5081 inside_width
, inside_height
- end
,
5089 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5091 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5095 x_scroll_bar_remove (bar
)
5096 struct scroll_bar
*bar
;
5098 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5101 #ifdef USE_TOOLKIT_SCROLL_BARS
5103 xg_remove_scroll_bar (f
, bar
->x_window
);
5104 #else /* not USE_GTK */
5105 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5106 #endif /* not USE_GTK */
5108 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5111 /* Disassociate this scroll bar from its window. */
5112 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
5118 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5119 that we are displaying PORTION characters out of a total of WHOLE
5120 characters, starting at POSITION. If WINDOW has no scroll bar,
5124 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
5126 int portion
, whole
, position
;
5128 struct frame
*f
= XFRAME (w
->frame
);
5129 struct scroll_bar
*bar
;
5130 int top
, height
, left
, sb_left
, width
, sb_width
;
5131 int window_y
, window_height
;
5132 #ifdef USE_TOOLKIT_SCROLL_BARS
5133 int fringe_extended_p
;
5136 /* Get window dimensions. */
5137 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5139 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5140 height
= window_height
;
5142 /* Compute the left edge of the scroll bar area. */
5143 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5145 /* Compute the width of the scroll bar which might be less than
5146 the width of the area reserved for the scroll bar. */
5147 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5148 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5152 /* Compute the left edge of the scroll bar. */
5153 #ifdef USE_TOOLKIT_SCROLL_BARS
5154 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5155 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5157 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5159 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5160 sb_left
= left
+ width
- sb_width
;
5165 #ifdef USE_TOOLKIT_SCROLL_BARS
5166 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5167 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5168 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5169 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5170 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5172 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5173 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5174 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5175 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5178 /* Does the scroll bar exist yet? */
5179 if (NILP (w
->vertical_scroll_bar
))
5181 if (width
> 0 && height
> 0)
5184 #ifdef USE_TOOLKIT_SCROLL_BARS
5185 if (fringe_extended_p
)
5186 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5187 sb_left
, top
, sb_width
, height
, False
);
5190 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5191 left
, top
, width
, height
, False
);
5195 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5199 /* It may just need to be moved and resized. */
5200 unsigned int mask
= 0;
5202 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5206 if (sb_left
!= bar
->left
)
5208 if (top
!= bar
->top
)
5210 if (sb_width
!= bar
->width
)
5212 if (height
!= bar
->height
)
5215 #ifdef USE_TOOLKIT_SCROLL_BARS
5217 /* Move/size the scroll bar widget. */
5218 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5220 /* Since toolkit scroll bars are smaller than the space reserved
5221 for them on the frame, we have to clear "under" them. */
5222 if (width
> 0 && height
> 0)
5224 if (fringe_extended_p
)
5225 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5226 sb_left
, top
, sb_width
, height
, False
);
5228 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5229 left
, top
, width
, height
, False
);
5232 xg_update_scrollbar_pos (f
,
5235 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5236 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5238 #else /* not USE_GTK */
5239 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5240 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5242 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5243 max (height
, 1), 0);
5244 #endif /* not USE_GTK */
5246 #else /* not USE_TOOLKIT_SCROLL_BARS */
5248 /* Clear areas not covered by the scroll bar because of
5249 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5250 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5252 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5253 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5255 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5256 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5257 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5261 /* Clear areas not covered by the scroll bar because it's not as
5262 wide as the area reserved for it. This makes sure a
5263 previous mode line display is cleared after C-x 2 C-x 1, for
5266 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5267 int rest
= area_width
- sb_width
;
5268 if (rest
> 0 && height
> 0)
5270 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5271 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5272 left
+ area_width
- rest
, top
,
5273 rest
, height
, False
);
5275 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5276 left
, top
, rest
, height
, False
);
5280 /* Move/size the scroll bar window. */
5285 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5287 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5289 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5293 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5295 /* Remember new settings. */
5296 bar
->left
= sb_left
;
5298 bar
->width
= sb_width
;
5299 bar
->height
= height
;
5304 #ifdef USE_TOOLKIT_SCROLL_BARS
5305 bar
->fringe_extended_p
= fringe_extended_p
;
5307 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5308 #else /* not USE_TOOLKIT_SCROLL_BARS */
5309 /* Set the scroll bar's current state, unless we're currently being
5311 if (NILP (bar
->dragging
))
5313 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5316 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5319 int start
= ((double) position
* top_range
) / whole
;
5320 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5321 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5324 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5326 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5330 /* The following three hooks are used when we're doing a thorough
5331 redisplay of the frame. We don't explicitly know which scroll bars
5332 are going to be deleted, because keeping track of when windows go
5333 away is a real pain - "Can you say set-window-configuration, boys
5334 and girls?" Instead, we just assert at the beginning of redisplay
5335 that *all* scroll bars are to be removed, and then save a scroll bar
5336 from the fiery pit when we actually redisplay its window. */
5338 /* Arrange for all scroll bars on FRAME to be removed at the next call
5339 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5340 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5343 XTcondemn_scroll_bars (frame
)
5346 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5347 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5350 bar
= FRAME_SCROLL_BARS (frame
);
5351 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5352 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5353 XSCROLL_BAR (bar
)->prev
= Qnil
;
5354 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5355 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5356 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5361 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5362 Note that WINDOW isn't necessarily condemned at all. */
5365 XTredeem_scroll_bar (window
)
5366 struct window
*window
;
5368 struct scroll_bar
*bar
;
5371 /* We can't redeem this window's scroll bar if it doesn't have one. */
5372 if (NILP (window
->vertical_scroll_bar
))
5375 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5377 /* Unlink it from the condemned list. */
5378 f
= XFRAME (WINDOW_FRAME (window
));
5379 if (NILP (bar
->prev
))
5381 /* If the prev pointer is nil, it must be the first in one of
5383 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5384 /* It's not condemned. Everything's fine. */
5386 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5387 window
->vertical_scroll_bar
))
5388 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5390 /* If its prev pointer is nil, it must be at the front of
5391 one or the other! */
5395 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5397 if (! NILP (bar
->next
))
5398 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5400 bar
->next
= FRAME_SCROLL_BARS (f
);
5402 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5403 if (! NILP (bar
->next
))
5404 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5407 /* Remove all scroll bars on FRAME that haven't been saved since the
5408 last call to `*condemn_scroll_bars_hook'. */
5411 XTjudge_scroll_bars (f
)
5414 Lisp_Object bar
, next
;
5416 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5418 /* Clear out the condemned list now so we won't try to process any
5419 more events on the hapless scroll bars. */
5420 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5422 for (; ! NILP (bar
); bar
= next
)
5424 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5426 x_scroll_bar_remove (b
);
5429 b
->next
= b
->prev
= Qnil
;
5432 /* Now there should be no references to the condemned scroll bars,
5433 and they should get garbage-collected. */
5437 #ifndef USE_TOOLKIT_SCROLL_BARS
5438 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5439 is a no-op when using toolkit scroll bars.
5441 This may be called from a signal handler, so we have to ignore GC
5445 x_scroll_bar_expose (bar
, event
)
5446 struct scroll_bar
*bar
;
5449 Window w
= bar
->x_window
;
5450 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5451 GC gc
= f
->output_data
.x
->normal_gc
;
5452 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5456 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5458 /* Switch to scroll bar foreground color. */
5459 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5460 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5461 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5463 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5464 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5466 /* x, y, width, height */
5468 bar
->width
- 1 - width_trim
- width_trim
,
5471 /* Restore the foreground color of the GC if we changed it above. */
5472 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5473 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5474 FRAME_FOREGROUND_PIXEL (f
));
5479 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5481 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5482 is set to something other than NO_EVENT, it is enqueued.
5484 This may be called from a signal handler, so we have to ignore GC
5489 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5490 struct scroll_bar
*bar
;
5492 struct input_event
*emacs_event
;
5494 if (! WINDOWP (bar
->window
))
5497 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5498 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5499 emacs_event
->modifiers
5500 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5501 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5502 event
->xbutton
.state
)
5503 | (event
->type
== ButtonRelease
5506 emacs_event
->frame_or_window
= bar
->window
;
5507 emacs_event
->arg
= Qnil
;
5508 emacs_event
->timestamp
= event
->xbutton
.time
;
5511 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5512 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5515 if (y
> top_range
) y
= top_range
;
5518 emacs_event
->part
= scroll_bar_above_handle
;
5519 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5520 emacs_event
->part
= scroll_bar_handle
;
5522 emacs_event
->part
= scroll_bar_below_handle
;
5524 #ifndef USE_TOOLKIT_SCROLL_BARS
5525 /* If the user has released the handle, set it to its final position. */
5526 if (event
->type
== ButtonRelease
5527 && ! NILP (bar
->dragging
))
5529 int new_start
= y
- XINT (bar
->dragging
);
5530 int new_end
= new_start
+ bar
->end
- bar
->start
;
5532 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5533 bar
->dragging
= Qnil
;
5537 XSETINT (emacs_event
->x
, y
);
5538 XSETINT (emacs_event
->y
, top_range
);
5542 #ifndef USE_TOOLKIT_SCROLL_BARS
5544 /* Handle some mouse motion while someone is dragging the scroll bar.
5546 This may be called from a signal handler, so we have to ignore GC
5550 x_scroll_bar_note_movement (bar
, event
)
5551 struct scroll_bar
*bar
;
5554 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5556 last_mouse_movement_time
= event
->xmotion
.time
;
5559 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5561 /* If we're dragging the bar, display it. */
5562 if (! NILP (bar
->dragging
))
5564 /* Where should the handle be now? */
5565 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5567 if (new_start
!= bar
->start
)
5569 int new_end
= new_start
+ bar
->end
- bar
->start
;
5571 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5576 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5578 /* Return information to the user about the current position of the mouse
5579 on the scroll bar. */
5582 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5584 Lisp_Object
*bar_window
;
5585 enum scroll_bar_part
*part
;
5587 unsigned long *time
;
5589 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5590 Window w
= bar
->x_window
;
5591 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5593 Window dummy_window
;
5595 unsigned int dummy_mask
;
5599 /* Get the mouse's position relative to the scroll bar window, and
5601 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5603 /* Root, child, root x and root y. */
5604 &dummy_window
, &dummy_window
,
5605 &dummy_coord
, &dummy_coord
,
5607 /* Position relative to scroll bar. */
5610 /* Mouse buttons and modifier keys. */
5616 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5618 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5620 if (! NILP (bar
->dragging
))
5621 win_y
-= XINT (bar
->dragging
);
5625 if (win_y
> top_range
)
5629 *bar_window
= bar
->window
;
5631 if (! NILP (bar
->dragging
))
5632 *part
= scroll_bar_handle
;
5633 else if (win_y
< bar
->start
)
5634 *part
= scroll_bar_above_handle
;
5635 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5636 *part
= scroll_bar_handle
;
5638 *part
= scroll_bar_below_handle
;
5640 XSETINT (*x
, win_y
);
5641 XSETINT (*y
, top_range
);
5644 last_mouse_scroll_bar
= Qnil
;
5647 *time
= last_mouse_movement_time
;
5653 /* The screen has been cleared so we may have changed foreground or
5654 background colors, and the scroll bars may need to be redrawn.
5655 Clear out the scroll bars, and ask for expose events, so we can
5659 x_scroll_bar_clear (f
)
5662 #ifndef USE_TOOLKIT_SCROLL_BARS
5665 /* We can have scroll bars even if this is 0,
5666 if we just turned off scroll bar mode.
5667 But in that case we should not clear them. */
5668 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5669 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5670 bar
= XSCROLL_BAR (bar
)->next
)
5671 XClearArea (FRAME_X_DISPLAY (f
),
5672 XSCROLL_BAR (bar
)->x_window
,
5674 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5678 /* The main X event-reading loop - XTread_socket. */
5680 /* This holds the state XLookupString needs to implement dead keys
5681 and other tricks known as "compose processing". _X Window System_
5682 says that a portable program can't use this, but Stephen Gildea assures
5683 me that letting the compiler initialize it to zeros will work okay.
5685 This must be defined outside of XTread_socket, for the same reasons
5686 given for enter_timestamp, above. */
5688 static XComposeStatus compose_status
;
5690 /* Record the last 100 characters stored
5691 to help debug the loss-of-chars-during-GC problem. */
5693 static int temp_index
;
5694 static short temp_buffer
[100];
5696 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5697 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5699 temp_buffer[temp_index++] = (keysym)
5701 /* Set this to nonzero to fake an "X I/O error"
5702 on a particular display. */
5704 struct x_display_info
*XTread_socket_fake_io_error
;
5706 /* When we find no input here, we occasionally do a no-op command
5707 to verify that the X server is still running and we can still talk with it.
5708 We try all the open displays, one by one.
5709 This variable is used for cycling thru the displays. */
5711 static struct x_display_info
*next_noop_dpyinfo
;
5713 #define SET_SAVED_MENU_EVENT(size) \
5716 if (f->output_data.x->saved_menu_event == 0) \
5717 f->output_data.x->saved_menu_event \
5718 = (XEvent *) xmalloc (sizeof (XEvent)); \
5719 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5720 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5721 XSETFRAME (inev.ie.frame_or_window, f); \
5725 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5726 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5736 /* Filter events for the current X input method.
5737 DPYINFO is the display this event is for.
5738 EVENT is the X event to filter.
5740 Returns non-zero if the event was filtered, caller shall not process
5742 Returns zero if event is wasn't filtered. */
5746 x_filter_event (dpyinfo
, event
)
5747 struct x_display_info
*dpyinfo
;
5750 /* XFilterEvent returns non-zero if the input method has
5751 consumed the event. We pass the frame's X window to
5752 XFilterEvent because that's the one for which the IC
5755 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5756 event
->xclient
.window
);
5758 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5763 static int current_count
;
5764 static int current_finish
;
5765 static struct input_event
*current_hold_quit
;
5767 /* This is the filter function invoked by the GTK event loop.
5768 It is invoked before the XEvent is translated to a GdkEvent,
5769 so we have a chance to act on the event before GTK. */
5770 static GdkFilterReturn
5771 event_handler_gdk (gxev
, ev
, data
)
5776 XEvent
*xev
= (XEvent
*) gxev
;
5778 if (current_count
>= 0)
5780 struct x_display_info
*dpyinfo
;
5782 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5785 /* Filter events for the current X input method.
5786 GTK calls XFilterEvent but not for key press and release,
5787 so we do it here. */
5788 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5789 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5790 return GDK_FILTER_REMOVE
;
5794 current_finish
= X_EVENT_NORMAL
;
5798 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5803 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5805 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5806 return GDK_FILTER_REMOVE
;
5808 return GDK_FILTER_CONTINUE
;
5810 #endif /* USE_GTK */
5813 /* Handles the XEvent EVENT on display DPYINFO.
5815 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5816 *FINISH is zero if caller should continue reading events.
5817 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5819 We return the number of characters stored into the buffer. */
5822 handle_one_xevent (dpyinfo
, eventp
, finish
, hold_quit
)
5823 struct x_display_info
*dpyinfo
;
5826 struct input_event
*hold_quit
;
5829 struct input_event ie
;
5830 struct selection_input_event sie
;
5835 struct frame
*f
= NULL
;
5836 struct coding_system coding
;
5837 XEvent event
= *eventp
;
5839 *finish
= X_EVENT_NORMAL
;
5841 EVENT_INIT (inev
.ie
);
5842 inev
.ie
.kind
= NO_EVENT
;
5845 if (pending_event_wait
.eventtype
== event
.type
)
5846 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5852 if (event
.xclient
.message_type
5853 == dpyinfo
->Xatom_wm_protocols
5854 && event
.xclient
.format
== 32)
5856 if (event
.xclient
.data
.l
[0]
5857 == dpyinfo
->Xatom_wm_take_focus
)
5859 /* Use x_any_window_to_frame because this
5860 could be the shell widget window
5861 if the frame has no title bar. */
5862 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5864 /* Not quite sure this is needed -pd */
5865 if (f
&& FRAME_XIC (f
))
5866 XSetICFocus (FRAME_XIC (f
));
5868 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5869 instructs the WM to set the input focus automatically for
5870 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5871 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5872 it has set the focus. So, XSetInputFocus below is not
5875 The call to XSetInputFocus below has also caused trouble. In
5876 cases where the XSetInputFocus done by the WM and the one
5877 below are temporally close (on a fast machine), the call
5878 below can generate additional FocusIn events which confuse
5881 /* Since we set WM_TAKE_FOCUS, we must call
5882 XSetInputFocus explicitly. But not if f is null,
5883 since that might be an event for a deleted frame. */
5886 Display
*d
= event
.xclient
.display
;
5887 /* Catch and ignore errors, in case window has been
5888 iconified by a window manager such as GWM. */
5890 XSetInputFocus (d
, event
.xclient
.window
,
5891 /* The ICCCM says this is
5892 the only valid choice. */
5894 event
.xclient
.data
.l
[1]);
5895 /* This is needed to detect the error
5896 if there is an error. */
5898 x_uncatch_errors ();
5900 /* Not certain about handling scroll bars here */
5905 if (event
.xclient
.data
.l
[0]
5906 == dpyinfo
->Xatom_wm_save_yourself
)
5908 /* Save state modify the WM_COMMAND property to
5909 something which can reinstate us. This notifies
5910 the session manager, who's looking for such a
5911 PropertyNotify. Can restart processing when
5912 a keyboard or mouse event arrives. */
5913 /* If we have a session manager, don't set this.
5914 KDE will then start two Emacsen, one for the
5915 session manager and one for this. */
5917 if (! x_session_have_connection ())
5920 f
= x_top_window_to_frame (dpyinfo
,
5921 event
.xclient
.window
);
5922 /* This is just so we only give real data once
5923 for a single Emacs process. */
5924 if (f
== SELECTED_FRAME ())
5925 XSetCommand (FRAME_X_DISPLAY (f
),
5926 event
.xclient
.window
,
5927 initial_argv
, initial_argc
);
5929 XSetCommand (FRAME_X_DISPLAY (f
),
5930 event
.xclient
.window
,
5936 if (event
.xclient
.data
.l
[0]
5937 == dpyinfo
->Xatom_wm_delete_window
)
5939 f
= x_any_window_to_frame (dpyinfo
,
5940 event
.xclient
.window
);
5942 goto OTHER
; /* May be a dialog that is to be removed */
5944 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5945 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5952 if (event
.xclient
.message_type
5953 == dpyinfo
->Xatom_wm_configure_denied
)
5958 if (event
.xclient
.message_type
5959 == dpyinfo
->Xatom_wm_window_moved
)
5962 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5964 new_x
= event
.xclient
.data
.s
[0];
5965 new_y
= event
.xclient
.data
.s
[1];
5969 f
->left_pos
= new_x
;
5976 if (event
.xclient
.message_type
5977 == dpyinfo
->Xatom_editres
)
5979 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5981 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5985 #endif /* HACK_EDITRES */
5987 if ((event
.xclient
.message_type
5988 == dpyinfo
->Xatom_DONE
)
5989 || (event
.xclient
.message_type
5990 == dpyinfo
->Xatom_PAGE
))
5992 /* Ghostview job completed. Kill it. We could
5993 reply with "Next" if we received "Page", but we
5994 currently never do because we are interested in
5995 images, only, which should have 1 page. */
5996 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5997 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6000 x_kill_gs_process (pixmap
, f
);
6001 expose_frame (f
, 0, 0, 0, 0);
6005 #ifdef USE_TOOLKIT_SCROLL_BARS
6006 /* Scroll bar callbacks send a ClientMessage from which
6007 we construct an input_event. */
6008 if (event
.xclient
.message_type
6009 == dpyinfo
->Xatom_Scrollbar
)
6011 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
6012 *finish
= X_EVENT_GOTO_OUT
;
6015 #endif /* USE_TOOLKIT_SCROLL_BARS */
6017 /* XEmbed messages from the embedder (if any). */
6018 if (event
.xclient
.message_type
6019 == dpyinfo
->Xatom_XEMBED
)
6021 enum xembed_message msg
= event
.xclient
.data
.l
[1];
6022 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6023 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6025 *finish
= X_EVENT_GOTO_OUT
;
6029 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6032 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6033 *finish
= X_EVENT_DROP
;
6037 case SelectionNotify
:
6038 last_user_time
= event
.xselection
.time
;
6039 #ifdef USE_X_TOOLKIT
6040 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6042 #endif /* not USE_X_TOOLKIT */
6043 x_handle_selection_notify (&event
.xselection
);
6046 case SelectionClear
: /* Someone has grabbed ownership. */
6047 last_user_time
= event
.xselectionclear
.time
;
6048 #ifdef USE_X_TOOLKIT
6049 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6051 #endif /* USE_X_TOOLKIT */
6053 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
6055 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6056 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6057 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6058 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6059 inev
.ie
.frame_or_window
= Qnil
;
6063 case SelectionRequest
: /* Someone wants our selection. */
6064 last_user_time
= event
.xselectionrequest
.time
;
6065 #ifdef USE_X_TOOLKIT
6066 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6068 #endif /* USE_X_TOOLKIT */
6070 XSelectionRequestEvent
*eventp
6071 = (XSelectionRequestEvent
*) &event
;
6073 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6074 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6075 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6076 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6077 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6078 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6079 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6080 inev
.ie
.frame_or_window
= Qnil
;
6084 case PropertyNotify
:
6085 last_user_time
= event
.xproperty
.time
;
6086 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
6087 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6088 x_handle_net_wm_state (f
, &event
.xproperty
);
6090 x_handle_property_notify (&event
.xproperty
);
6093 case ReparentNotify
:
6094 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6098 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6099 x_real_positions (f
, &x
, &y
);
6103 /* Perhaps reparented due to a WM restart. Reset this. */
6104 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6105 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6110 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6114 /* This seems to be needed for GTK 2.6. */
6115 x_clear_area (event
.xexpose
.display
,
6116 event
.xexpose
.window
,
6117 event
.xexpose
.x
, event
.xexpose
.y
,
6118 event
.xexpose
.width
, event
.xexpose
.height
,
6121 if (f
->async_visible
== 0)
6123 f
->async_visible
= 1;
6124 f
->async_iconified
= 0;
6125 f
->output_data
.x
->has_been_visible
= 1;
6126 SET_FRAME_GARBAGED (f
);
6130 event
.xexpose
.x
, event
.xexpose
.y
,
6131 event
.xexpose
.width
, event
.xexpose
.height
);
6135 #ifndef USE_TOOLKIT_SCROLL_BARS
6136 struct scroll_bar
*bar
;
6138 #if defined USE_LUCID
6139 /* Submenus of the Lucid menu bar aren't widgets
6140 themselves, so there's no way to dispatch events
6141 to them. Recognize this case separately. */
6144 = x_window_to_menu_bar (event
.xexpose
.window
);
6146 xlwmenu_redisplay (widget
);
6148 #endif /* USE_LUCID */
6150 #ifdef USE_TOOLKIT_SCROLL_BARS
6151 /* Dispatch event to the widget. */
6153 #else /* not USE_TOOLKIT_SCROLL_BARS */
6154 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6155 event
.xexpose
.window
);
6158 x_scroll_bar_expose (bar
, &event
);
6159 #ifdef USE_X_TOOLKIT
6162 #endif /* USE_X_TOOLKIT */
6163 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6167 case GraphicsExpose
: /* This occurs when an XCopyArea's
6168 source area was obscured or not
6170 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6174 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6175 event
.xgraphicsexpose
.width
,
6176 event
.xgraphicsexpose
.height
);
6178 #ifdef USE_X_TOOLKIT
6181 #endif /* USE_X_TOOLKIT */
6184 case NoExpose
: /* This occurs when an XCopyArea's
6185 source area was completely
6190 /* Redo the mouse-highlight after the tooltip has gone. */
6191 if (event
.xmap
.window
== tip_window
)
6194 redo_mouse_highlight ();
6197 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6198 if (f
) /* F may no longer exist if
6199 the frame was deleted. */
6201 /* While a frame is unmapped, display generation is
6202 disabled; you don't want to spend time updating a
6203 display that won't ever be seen. */
6204 f
->async_visible
= 0;
6205 /* We can't distinguish, from the event, whether the window
6206 has become iconified or invisible. So assume, if it
6207 was previously visible, than now it is iconified.
6208 But x_make_frame_invisible clears both
6209 the visible flag and the iconified flag;
6210 and that way, we know the window is not iconified now. */
6211 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6213 f
->async_iconified
= 1;
6215 inev
.ie
.kind
= ICONIFY_EVENT
;
6216 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6222 if (event
.xmap
.window
== tip_window
)
6223 /* The tooltip has been drawn already. Avoid
6224 the SET_FRAME_GARBAGED below. */
6227 /* We use x_top_window_to_frame because map events can
6228 come for sub-windows and they don't mean that the
6229 frame is visible. */
6230 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6233 /* wait_reading_process_output will notice this and update
6234 the frame's display structures.
6235 If we where iconified, we should not set garbaged,
6236 because that stops redrawing on Expose events. This looks
6237 bad if we are called from a recursive event loop
6238 (x_dispatch_event), for example when a dialog is up. */
6239 if (! f
->async_iconified
)
6240 SET_FRAME_GARBAGED (f
);
6242 /* Check if fullscreen was specified before we where mapped the
6243 first time, i.e. from the command line. */
6244 if (!f
->output_data
.x
->has_been_visible
)
6245 x_check_fullscreen (f
);
6247 f
->async_visible
= 1;
6248 f
->async_iconified
= 0;
6249 f
->output_data
.x
->has_been_visible
= 1;
6253 inev
.ie
.kind
= DEICONIFY_EVENT
;
6254 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6256 else if (! NILP (Vframe_list
)
6257 && ! NILP (XCDR (Vframe_list
)))
6258 /* Force a redisplay sooner or later
6259 to update the frame titles
6260 in case this is the second frame. */
6261 record_asynch_buffer_change ();
6264 xg_frame_resized (f
, -1, -1);
6271 last_user_time
= event
.xkey
.time
;
6272 ignore_next_mouse_click_timeout
= 0;
6274 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6275 /* Dispatch KeyPress events when in menu. */
6276 if (popup_activated ())
6280 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6282 /* If mouse-highlight is an integer, input clears out
6283 mouse highlighting. */
6284 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6286 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6288 clear_mouse_face (dpyinfo
);
6289 dpyinfo
->mouse_face_hidden
= 1;
6292 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6295 /* Scroll bars consume key events, but we want
6296 the keys to go to the scroll bar's frame. */
6297 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6299 if (widget
&& XmIsScrollBar (widget
))
6301 widget
= XtParent (widget
);
6302 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6305 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6309 KeySym keysym
, orig_keysym
;
6310 /* al%imercury@uunet.uu.net says that making this 81
6311 instead of 80 fixed a bug whereby meta chars made
6314 It seems that some version of XmbLookupString has
6315 a bug of not returning XBufferOverflow in
6316 status_return even if the input is too long to
6317 fit in 81 bytes. So, we must prepare sufficient
6318 bytes for copy_buffer. 513 bytes (256 chars for
6319 two-byte character set) seems to be a fairly good
6320 approximation. -- 2000.8.10 handa@etl.go.jp */
6321 unsigned char copy_buffer
[513];
6322 unsigned char *copy_bufptr
= copy_buffer
;
6323 int copy_bufsiz
= sizeof (copy_buffer
);
6325 Lisp_Object coding_system
= Qlatin_1
;
6329 /* Don't pass keys to GTK. A Tab will shift focus to the
6330 tool bar in GTK 2.4. Keys will still go to menus and
6331 dialogs because in that case popup_activated is TRUE
6333 *finish
= X_EVENT_DROP
;
6337 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6338 extra_keyboard_modifiers
);
6339 modifiers
= event
.xkey
.state
;
6341 /* This will have to go some day... */
6343 /* make_lispy_event turns chars into control chars.
6344 Don't do it here because XLookupString is too eager. */
6345 event
.xkey
.state
&= ~ControlMask
;
6346 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6347 | dpyinfo
->super_mod_mask
6348 | dpyinfo
->hyper_mod_mask
6349 | dpyinfo
->alt_mod_mask
);
6351 /* In case Meta is ComposeCharacter,
6352 clear its status. According to Markus Ehrnsperger
6353 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6354 this enables ComposeCharacter to work whether or
6355 not it is combined with Meta. */
6356 if (modifiers
& dpyinfo
->meta_mod_mask
)
6357 bzero (&compose_status
, sizeof (compose_status
));
6362 Status status_return
;
6364 coding_system
= Vlocale_coding_system
;
6365 nbytes
= XmbLookupString (FRAME_XIC (f
),
6366 &event
.xkey
, copy_bufptr
,
6367 copy_bufsiz
, &keysym
,
6369 if (status_return
== XBufferOverflow
)
6371 copy_bufsiz
= nbytes
+ 1;
6372 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6373 nbytes
= XmbLookupString (FRAME_XIC (f
),
6374 &event
.xkey
, copy_bufptr
,
6375 copy_bufsiz
, &keysym
,
6378 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6379 if (status_return
== XLookupNone
)
6381 else if (status_return
== XLookupChars
)
6386 else if (status_return
!= XLookupKeySym
6387 && status_return
!= XLookupBoth
)
6391 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6392 copy_bufsiz
, &keysym
,
6395 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6396 copy_bufsiz
, &keysym
,
6400 /* If not using XIM/XIC, and a compose sequence is in progress,
6401 we break here. Otherwise, chars_matched is always 0. */
6402 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6405 bzero (&compose_status
, sizeof (compose_status
));
6406 orig_keysym
= keysym
;
6408 /* Common for all keysym input events. */
6409 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6411 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6412 inev
.ie
.timestamp
= event
.xkey
.time
;
6414 /* First deal with keysyms which have defined
6415 translations to characters. */
6416 if (keysym
>= 32 && keysym
< 128)
6417 /* Avoid explicitly decoding each ASCII character. */
6419 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6420 inev
.ie
.code
= keysym
;
6424 /* Keysyms directly mapped to Unicode characters. */
6425 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6427 if (keysym
< 0x01000080)
6428 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6430 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6431 inev
.ie
.code
= keysym
& 0xFFFFFF;
6435 /* Now non-ASCII. */
6436 if (HASH_TABLE_P (Vx_keysym_table
)
6437 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6441 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6442 ? ASCII_KEYSTROKE_EVENT
6443 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6444 inev
.ie
.code
= XFASTINT (c
);
6448 /* Random non-modifier sorts of keysyms. */
6449 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6450 || keysym
== XK_Delete
6451 #ifdef XK_ISO_Left_Tab
6452 || (keysym
>= XK_ISO_Left_Tab
6453 && keysym
<= XK_ISO_Enter
)
6455 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6456 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6458 /* This recognizes the "extended function
6459 keys". It seems there's no cleaner way.
6460 Test IsModifierKey to avoid handling
6461 mode_switch incorrectly. */
6462 || ((unsigned) (keysym
) >= XK_Select
6463 && (unsigned)(keysym
) < XK_KP_Space
)
6465 #ifdef XK_dead_circumflex
6466 || orig_keysym
== XK_dead_circumflex
6468 #ifdef XK_dead_grave
6469 || orig_keysym
== XK_dead_grave
6471 #ifdef XK_dead_tilde
6472 || orig_keysym
== XK_dead_tilde
6474 #ifdef XK_dead_diaeresis
6475 || orig_keysym
== XK_dead_diaeresis
6477 #ifdef XK_dead_macron
6478 || orig_keysym
== XK_dead_macron
6480 #ifdef XK_dead_degree
6481 || orig_keysym
== XK_dead_degree
6483 #ifdef XK_dead_acute
6484 || orig_keysym
== XK_dead_acute
6486 #ifdef XK_dead_cedilla
6487 || orig_keysym
== XK_dead_cedilla
6489 #ifdef XK_dead_breve
6490 || orig_keysym
== XK_dead_breve
6492 #ifdef XK_dead_ogonek
6493 || orig_keysym
== XK_dead_ogonek
6495 #ifdef XK_dead_caron
6496 || orig_keysym
== XK_dead_caron
6498 #ifdef XK_dead_doubleacute
6499 || orig_keysym
== XK_dead_doubleacute
6501 #ifdef XK_dead_abovedot
6502 || orig_keysym
== XK_dead_abovedot
6504 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6505 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6506 /* Any "vendor-specific" key is ok. */
6507 || (orig_keysym
& (1 << 28))
6508 || (keysym
!= NoSymbol
&& nbytes
== 0))
6509 && ! (IsModifierKey (orig_keysym
)
6510 /* The symbols from XK_ISO_Lock
6511 to XK_ISO_Last_Group_Lock
6512 don't have real modifiers but
6513 should be treated similarly to
6514 Mode_switch by Emacs. */
6515 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6516 || ((unsigned)(orig_keysym
)
6518 && (unsigned)(orig_keysym
)
6519 <= XK_ISO_Last_Group_Lock
)
6523 STORE_KEYSYM_FOR_DEBUG (keysym
);
6524 /* make_lispy_event will convert this to a symbolic
6526 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6527 inev
.ie
.code
= keysym
;
6531 { /* Raw bytes, not keysym. */
6536 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6538 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6540 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6543 if (nchars
< nbytes
)
6545 /* Decode the input data. */
6549 /* The input should be decoded with `coding_system'
6550 which depends on which X*LookupString function
6551 we used just above and the locale. */
6552 setup_coding_system (coding_system
, &coding
);
6553 coding
.src_multibyte
= 0;
6554 coding
.dst_multibyte
= 1;
6555 /* The input is converted to events, thus we can't
6556 handle composition. Anyway, there's no XIM that
6557 gives us composition information. */
6558 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6560 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6561 coding
.destination
= alloca (require
);
6562 coding
.dst_bytes
= require
;
6563 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6564 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6565 nbytes
= coding
.produced
;
6566 nchars
= coding
.produced_char
;
6567 copy_bufptr
= coding
.destination
;
6570 /* Convert the input data to a sequence of
6571 character events. */
6572 for (i
= 0; i
< nbytes
; i
+= len
)
6574 if (nchars
== nbytes
)
6575 c
= copy_bufptr
[i
], len
= 1;
6577 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6579 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6580 ? ASCII_KEYSTROKE_EVENT
6581 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6583 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6588 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6590 if (keysym
== NoSymbol
)
6596 /* Don't dispatch this event since XtDispatchEvent calls
6597 XFilterEvent, and two calls in a row may freeze the
6605 last_user_time
= event
.xkey
.time
;
6607 /* Don't dispatch this event since XtDispatchEvent calls
6608 XFilterEvent, and two calls in a row may freeze the
6616 last_user_time
= event
.xcrossing
.time
;
6617 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6619 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6621 if (f
&& x_mouse_click_focus_ignore_position
)
6622 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6624 /* EnterNotify counts as mouse movement,
6625 so update things that depend on mouse position. */
6626 if (f
&& !f
->output_data
.x
->hourglass_p
)
6627 note_mouse_movement (f
, &event
.xmotion
);
6629 /* We may get an EnterNotify on the buttons in the toolbar. In that
6630 case we moved out of any highlighted area and need to note this. */
6631 if (!f
&& last_mouse_glyph_frame
)
6632 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6637 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6641 last_user_time
= event
.xcrossing
.time
;
6642 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6644 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6647 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6649 /* If we move outside the frame, then we're
6650 certainly no longer on any text in the frame. */
6651 clear_mouse_face (dpyinfo
);
6652 dpyinfo
->mouse_face_mouse_frame
= 0;
6655 /* Generate a nil HELP_EVENT to cancel a help-echo.
6656 Do it only if there's something to cancel.
6657 Otherwise, the startup message is cleared when
6658 the mouse leaves the frame. */
6659 if (any_help_event_p
)
6663 /* See comment in EnterNotify above */
6664 else if (last_mouse_glyph_frame
)
6665 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6670 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6675 last_user_time
= event
.xmotion
.time
;
6676 previous_help_echo_string
= help_echo_string
;
6677 help_echo_string
= Qnil
;
6679 if (dpyinfo
->grabbed
&& last_mouse_frame
6680 && FRAME_LIVE_P (last_mouse_frame
))
6681 f
= last_mouse_frame
;
6683 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6685 if (dpyinfo
->mouse_face_hidden
)
6687 dpyinfo
->mouse_face_hidden
= 0;
6688 clear_mouse_face (dpyinfo
);
6692 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6698 /* Generate SELECT_WINDOW_EVENTs when needed.
6699 Don't let popup menus influence things (bug#1261). */
6700 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6704 window
= window_from_coordinates (f
,
6705 event
.xmotion
.x
, event
.xmotion
.y
,
6708 /* Window will be selected only when it is not selected now and
6709 last mouse movement event was not in it. Minibuffer window
6710 will be selected only when it is active. */
6711 if (WINDOWP (window
)
6712 && !EQ (window
, last_window
)
6713 && !EQ (window
, selected_window
)
6714 /* For click-to-focus window managers
6715 create event iff we don't leave the
6717 && (focus_follows_mouse
6718 || (EQ (XWINDOW (window
)->frame
,
6719 XWINDOW (selected_window
)->frame
))))
6721 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6722 inev
.ie
.frame_or_window
= window
;
6727 if (!note_mouse_movement (f
, &event
.xmotion
))
6728 help_echo_string
= previous_help_echo_string
;
6732 #ifndef USE_TOOLKIT_SCROLL_BARS
6733 struct scroll_bar
*bar
6734 = x_window_to_scroll_bar (event
.xmotion
.display
,
6735 event
.xmotion
.window
);
6738 x_scroll_bar_note_movement (bar
, &event
);
6739 #endif /* USE_TOOLKIT_SCROLL_BARS */
6741 /* If we move outside the frame, then we're
6742 certainly no longer on any text in the frame. */
6743 clear_mouse_face (dpyinfo
);
6746 /* If the contents of the global variable help_echo_string
6747 has changed, generate a HELP_EVENT. */
6748 if (!NILP (help_echo_string
)
6749 || !NILP (previous_help_echo_string
))
6754 case ConfigureNotify
:
6755 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6758 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6759 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6761 xg_frame_resized (f
, event
.xconfigure
.width
,
6762 event
.xconfigure
.height
);
6768 #ifndef USE_X_TOOLKIT
6770 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6771 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6773 /* In the toolkit version, change_frame_size
6774 is called by the code that handles resizing
6775 of the EmacsFrame widget. */
6777 /* Even if the number of character rows and columns has
6778 not changed, the font size may have changed, so we need
6779 to check the pixel dimensions as well. */
6780 if (columns
!= FRAME_COLS (f
)
6781 || rows
!= FRAME_LINES (f
)
6782 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6783 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6785 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6786 SET_FRAME_GARBAGED (f
);
6787 cancel_mouse_face (f
);
6790 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6791 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6792 #endif /* not USE_GTK */
6796 /* GTK creates windows but doesn't map them.
6797 Only get real positions when mapped. */
6798 if (FRAME_GTK_OUTER_WIDGET (f
)
6799 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6802 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6806 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6807 xic_set_statusarea (f
);
6816 /* If we decide we want to generate an event to be seen
6817 by the rest of Emacs, we put it here. */
6820 bzero (&compose_status
, sizeof (compose_status
));
6821 last_mouse_glyph_frame
= 0;
6822 last_user_time
= event
.xbutton
.time
;
6824 if (dpyinfo
->grabbed
6826 && FRAME_LIVE_P (last_mouse_frame
))
6827 f
= last_mouse_frame
;
6829 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6832 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6837 /* Is this in the tool-bar? */
6838 if (WINDOWP (f
->tool_bar_window
)
6839 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6842 int x
= event
.xbutton
.x
;
6843 int y
= event
.xbutton
.y
;
6845 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6846 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6848 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6850 handle_tool_bar_click (f
, x
, y
,
6851 event
.xbutton
.type
== ButtonPress
,
6852 x_x_to_emacs_modifiers (dpyinfo
,
6853 event
.xbutton
.state
));
6858 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6859 if (! popup_activated ())
6862 if (ignore_next_mouse_click_timeout
)
6864 if (event
.type
== ButtonPress
6865 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6867 ignore_next_mouse_click_timeout
= 0;
6868 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6870 if (event
.type
== ButtonRelease
)
6871 ignore_next_mouse_click_timeout
= 0;
6874 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6876 if (FRAME_X_EMBEDDED_P (f
))
6877 xembed_send_message (f
, event
.xbutton
.time
,
6878 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6882 struct scroll_bar
*bar
6883 = x_window_to_scroll_bar (event
.xbutton
.display
,
6884 event
.xbutton
.window
);
6886 #ifdef USE_TOOLKIT_SCROLL_BARS
6887 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6889 if (bar
&& event
.xbutton
.state
& ControlMask
)
6891 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6892 *finish
= X_EVENT_DROP
;
6894 #else /* not USE_TOOLKIT_SCROLL_BARS */
6896 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6897 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6900 if (event
.type
== ButtonPress
)
6902 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6903 last_mouse_frame
= f
;
6906 last_tool_bar_item
= -1;
6909 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6911 /* Ignore any mouse motion that happened before this event;
6912 any subsequent mouse-movement Emacs events should reflect
6913 only motion after the ButtonPress/Release. */
6917 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6918 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6919 /* For a down-event in the menu bar,
6920 don't pass it to Xt right now.
6921 Instead, save it away
6922 and we will pass it to Xt from kbd_buffer_get_event.
6923 That way, we can run some Lisp code first. */
6926 ! popup_activated ()
6927 /* Gtk+ menus only react to the first three buttons. */
6928 && event
.xbutton
.button
< 3
6931 f
&& event
.type
== ButtonPress
6932 /* Verify the event is really within the menu bar
6933 and not just sent to it due to grabbing. */
6934 && event
.xbutton
.x
>= 0
6935 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6936 && event
.xbutton
.y
>= 0
6937 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6938 && event
.xbutton
.same_screen
)
6940 SET_SAVED_BUTTON_EVENT
;
6941 XSETFRAME (last_mouse_press_frame
, f
);
6943 *finish
= X_EVENT_DROP
;
6946 else if (event
.type
== ButtonPress
)
6948 last_mouse_press_frame
= Qnil
;
6952 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6953 but I am trying to be cautious. */
6954 else if (event
.type
== ButtonRelease
)
6956 if (!NILP (last_mouse_press_frame
))
6958 f
= XFRAME (last_mouse_press_frame
);
6959 if (f
->output_data
.x
)
6960 SET_SAVED_BUTTON_EVENT
;
6965 #endif /* USE_MOTIF */
6968 #endif /* USE_X_TOOLKIT || USE_GTK */
6972 case CirculateNotify
:
6975 case CirculateRequest
:
6978 case VisibilityNotify
:
6982 /* Someone has changed the keyboard mapping - update the
6984 switch (event
.xmapping
.request
)
6986 case MappingModifier
:
6987 x_find_modifier_meanings (dpyinfo
);
6988 /* This is meant to fall through. */
6989 case MappingKeyboard
:
6990 XRefreshKeyboardMapping (&event
.xmapping
);
6996 #ifdef USE_X_TOOLKIT
6998 if (*finish
!= X_EVENT_DROP
)
6999 XtDispatchEvent (&event
);
7001 #endif /* USE_X_TOOLKIT */
7006 if (inev
.ie
.kind
!= NO_EVENT
)
7008 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7013 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7018 XSETFRAME (frame
, f
);
7024 any_help_event_p
= 1;
7025 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7026 help_echo_object
, help_echo_pos
);
7030 help_echo_string
= Qnil
;
7031 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7041 /* Handles the XEvent EVENT on display DISPLAY.
7042 This is used for event loops outside the normal event handling,
7043 i.e. looping while a popup menu or a dialog is posted.
7045 Returns the value handle_one_xevent sets in the finish argument. */
7047 x_dispatch_event (event
, display
)
7051 struct x_display_info
*dpyinfo
;
7052 int finish
= X_EVENT_NORMAL
;
7054 dpyinfo
= x_display_info_for_display (display
);
7057 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7063 /* Read events coming from the X server.
7064 This routine is called by the SIGIO handler.
7065 We return as soon as there are no more events to be read.
7067 We return the number of characters stored into the buffer,
7068 thus pretending to be `read' (except the characters we store
7069 in the keyboard buffer can be multibyte, so are not necessarily
7072 EXPECTED is nonzero if the caller knows input is available. */
7075 XTread_socket (terminal
, expected
, hold_quit
)
7076 struct terminal
*terminal
;
7078 struct input_event
*hold_quit
;
7082 int event_found
= 0;
7084 if (interrupt_input_blocked
)
7086 interrupt_input_pending
= 1;
7088 pending_signals
= 1;
7093 interrupt_input_pending
= 0;
7095 pending_signals
= pending_atimers
;
7099 /* So people can tell when we have read the available input. */
7100 input_signal_count
++;
7105 /* Only check session manager input for the primary display. */
7106 if (terminal
->id
== 1 && x_session_have_connection ())
7108 struct input_event inev
;
7110 /* We don't need to EVENT_INIT (inev) here, as
7111 x_session_check_input copies an entire input_event. */
7112 if (x_session_check_input (&inev
))
7114 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7121 /* For debugging, this gives a way to fake an I/O error. */
7122 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7124 XTread_socket_fake_io_error
= 0;
7125 x_io_error_quitter (terminal
->display_info
.x
->display
);
7129 while (XPending (terminal
->display_info
.x
->display
))
7133 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7136 /* Filter events for the current X input method. */
7137 if (x_filter_event (terminal
->display_info
.x
, &event
))
7142 count
+= handle_one_xevent (terminal
->display_info
.x
,
7143 &event
, &finish
, hold_quit
);
7145 if (finish
== X_EVENT_GOTO_OUT
)
7151 /* For GTK we must use the GTK event loop. But XEvents gets passed
7152 to our filter function above, and then to the big event switch.
7153 We use a bunch of globals to communicate with our filter function,
7154 that is kind of ugly, but it works.
7156 There is no way to do one display at the time, GTK just does events
7157 from all displays. */
7159 while (gtk_events_pending ())
7161 current_count
= count
;
7162 current_hold_quit
= hold_quit
;
7164 gtk_main_iteration ();
7166 count
= current_count
;
7168 current_hold_quit
= 0;
7170 if (current_finish
== X_EVENT_GOTO_OUT
)
7173 #endif /* USE_GTK */
7177 /* On some systems, an X bug causes Emacs to get no more events
7178 when the window is destroyed. Detect that. (1994.) */
7181 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7182 One XNOOP in 100 loops will make Emacs terminate.
7183 B. Bretthauer, 1994 */
7185 if (x_noop_count
>= 100)
7189 if (next_noop_dpyinfo
== 0)
7190 next_noop_dpyinfo
= x_display_list
;
7192 XNoOp (next_noop_dpyinfo
->display
);
7194 /* Each time we get here, cycle through the displays now open. */
7195 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7199 /* If the focus was just given to an auto-raising frame,
7201 /* ??? This ought to be able to handle more than one such frame. */
7202 if (pending_autoraise_frame
)
7204 x_raise_frame (pending_autoraise_frame
);
7205 pending_autoraise_frame
= 0;
7217 /***********************************************************************
7219 ***********************************************************************/
7221 /* Set clipping for output in glyph row ROW. W is the window in which
7222 we operate. GC is the graphics context to set clipping in.
7224 ROW may be a text row or, e.g., a mode line. Text rows must be
7225 clipped to the interior of the window dedicated to text display,
7226 mode lines must be clipped to the whole window. */
7229 x_clip_to_row (w
, row
, area
, gc
)
7231 struct glyph_row
*row
;
7235 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7236 XRectangle clip_rect
;
7237 int window_x
, window_y
, window_width
;
7239 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7241 clip_rect
.x
= window_x
;
7242 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7243 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7244 clip_rect
.width
= window_width
;
7245 clip_rect
.height
= row
->visible_height
;
7247 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7251 /* Draw a hollow box cursor on window W in glyph row ROW. */
7254 x_draw_hollow_cursor (w
, row
)
7256 struct glyph_row
*row
;
7258 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7259 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7260 Display
*dpy
= FRAME_X_DISPLAY (f
);
7263 struct glyph
*cursor_glyph
;
7266 /* Get the glyph the cursor is on. If we can't tell because
7267 the current matrix is invalid or such, give up. */
7268 cursor_glyph
= get_phys_cursor_glyph (w
);
7269 if (cursor_glyph
== NULL
)
7272 /* Compute frame-relative coordinates for phys cursor. */
7273 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7274 wd
= w
->phys_cursor_width
;
7276 /* The foreground of cursor_gc is typically the same as the normal
7277 background color, which can cause the cursor box to be invisible. */
7278 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7279 if (dpyinfo
->scratch_cursor_gc
)
7280 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7282 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7283 GCForeground
, &xgcv
);
7284 gc
= dpyinfo
->scratch_cursor_gc
;
7286 /* Set clipping, draw the rectangle, and reset clipping again. */
7287 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7288 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7289 XSetClipMask (dpy
, gc
, None
);
7293 /* Draw a bar cursor on window W in glyph row ROW.
7295 Implementation note: One would like to draw a bar cursor with an
7296 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7297 Unfortunately, I didn't find a font yet that has this property set.
7301 x_draw_bar_cursor (w
, row
, width
, kind
)
7303 struct glyph_row
*row
;
7305 enum text_cursor_kinds kind
;
7307 struct frame
*f
= XFRAME (w
->frame
);
7308 struct glyph
*cursor_glyph
;
7310 /* If cursor is out of bounds, don't draw garbage. This can happen
7311 in mini-buffer windows when switching between echo area glyphs
7313 cursor_glyph
= get_phys_cursor_glyph (w
);
7314 if (cursor_glyph
== NULL
)
7317 /* If on an image, draw like a normal cursor. That's usually better
7318 visible than drawing a bar, esp. if the image is large so that
7319 the bar might not be in the window. */
7320 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7322 struct glyph_row
*row
;
7323 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7324 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7328 Display
*dpy
= FRAME_X_DISPLAY (f
);
7329 Window window
= FRAME_X_WINDOW (f
);
7330 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7331 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7332 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7335 /* If the glyph's background equals the color we normally draw
7336 the bars cursor in, the bar cursor in its normal color is
7337 invisible. Use the glyph's foreground color instead in this
7338 case, on the assumption that the glyph's colors are chosen so
7339 that the glyph is legible. */
7340 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7341 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7343 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7344 xgcv
.graphics_exposures
= 0;
7347 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7350 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7351 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7354 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7356 if (kind
== BAR_CURSOR
)
7359 width
= FRAME_CURSOR_WIDTH (f
);
7360 width
= min (cursor_glyph
->pixel_width
, width
);
7362 w
->phys_cursor_width
= width
;
7364 XFillRectangle (dpy
, window
, gc
,
7365 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7366 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7367 width
, row
->height
);
7371 int dummy_x
, dummy_y
, dummy_h
;
7374 width
= row
->height
;
7376 width
= min (row
->height
, width
);
7378 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7379 &dummy_y
, &dummy_h
);
7381 XFillRectangle (dpy
, window
, gc
,
7382 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7383 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7384 row
->height
- width
),
7385 w
->phys_cursor_width
, width
);
7388 XSetClipMask (dpy
, gc
, None
);
7393 /* RIF: Define cursor CURSOR on frame F. */
7396 x_define_frame_cursor (f
, cursor
)
7400 if (!f
->pointer_invisible
7401 && f
->output_data
.x
->current_cursor
!= cursor
)
7402 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7403 f
->output_data
.x
->current_cursor
= cursor
;
7407 /* RIF: Clear area on frame F. */
7410 x_clear_frame_area (f
, x
, y
, width
, height
)
7412 int x
, y
, width
, height
;
7414 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7415 x
, y
, width
, height
, False
);
7419 /* RIF: Draw cursor on window W. */
7422 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7424 struct glyph_row
*glyph_row
;
7426 int cursor_type
, cursor_width
;
7429 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7433 w
->phys_cursor_type
= cursor_type
;
7434 w
->phys_cursor_on_p
= 1;
7436 if (glyph_row
->exact_window_width_line_p
7437 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7439 glyph_row
->cursor_in_fringe_p
= 1;
7440 draw_fringe_bitmap (w
, glyph_row
, 0);
7443 switch (cursor_type
)
7445 case HOLLOW_BOX_CURSOR
:
7446 x_draw_hollow_cursor (w
, glyph_row
);
7449 case FILLED_BOX_CURSOR
:
7450 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7454 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7458 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7462 w
->phys_cursor_width
= 0;
7470 if (w
== XWINDOW (f
->selected_window
))
7471 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7472 xic_set_preeditarea (w
, x
, y
);
7477 XFlush (FRAME_X_DISPLAY (f
));
7484 /* Make the x-window of frame F use the gnu icon bitmap. */
7487 x_bitmap_icon (f
, file
)
7493 if (FRAME_X_WINDOW (f
) == 0)
7496 /* Free up our existing icon bitmap and mask if any. */
7497 if (f
->output_data
.x
->icon_bitmap
> 0)
7498 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7499 f
->output_data
.x
->icon_bitmap
= 0;
7504 /* Use gtk_window_set_icon_from_file () if available,
7505 It's not restricted to bitmaps */
7506 if (xg_set_icon (f
, file
))
7508 #endif /* USE_GTK */
7509 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7510 x_create_bitmap_mask (f
, bitmap_id
);
7514 /* Create the GNU bitmap and mask if necessary. */
7515 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7521 if (xg_set_icon (f
, xg_default_icon_file
)
7522 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7525 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7527 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7529 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7533 /* If all else fails, use the (black and white) xbm image. */
7536 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7537 gnu_xbm_width
, gnu_xbm_height
);
7541 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7542 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7546 /* The first time we create the GNU bitmap and mask,
7547 this increments the ref-count one extra time.
7548 As a result, the GNU bitmap and mask are never freed.
7549 That way, we don't have to worry about allocating it again. */
7550 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7552 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7555 x_wm_set_icon_pixmap (f
, bitmap_id
);
7556 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7562 /* Make the x-window of frame F use a rectangle with text.
7563 Use ICON_NAME as the text. */
7566 x_text_icon (f
, icon_name
)
7570 if (FRAME_X_WINDOW (f
) == 0)
7575 text
.value
= (unsigned char *) icon_name
;
7576 text
.encoding
= XA_STRING
;
7578 text
.nitems
= strlen (icon_name
);
7579 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7582 if (f
->output_data
.x
->icon_bitmap
> 0)
7583 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7584 f
->output_data
.x
->icon_bitmap
= 0;
7585 x_wm_set_icon_pixmap (f
, 0);
7590 #define X_ERROR_MESSAGE_SIZE 200
7592 /* If non-nil, this should be a string.
7593 It means catch X errors and store the error message in this string.
7595 The reason we use a stack is that x_catch_error/x_uncatch_error can
7596 be called from a signal handler.
7599 struct x_error_message_stack
{
7600 char string
[X_ERROR_MESSAGE_SIZE
];
7602 struct x_error_message_stack
*prev
;
7604 static struct x_error_message_stack
*x_error_message
;
7606 /* An X error handler which stores the error message in
7607 *x_error_message. This is called from x_error_handler if
7608 x_catch_errors is in effect. */
7611 x_error_catcher (display
, error
)
7615 XGetErrorText (display
, error
->error_code
,
7616 x_error_message
->string
,
7617 X_ERROR_MESSAGE_SIZE
);
7620 /* Begin trapping X errors for display DPY. Actually we trap X errors
7621 for all displays, but DPY should be the display you are actually
7624 After calling this function, X protocol errors no longer cause
7625 Emacs to exit; instead, they are recorded in the string
7626 stored in *x_error_message.
7628 Calling x_check_errors signals an Emacs error if an X error has
7629 occurred since the last call to x_catch_errors or x_check_errors.
7631 Calling x_uncatch_errors resumes the normal error handling. */
7633 void x_check_errors ();
7636 x_catch_errors (dpy
)
7639 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7641 /* Make sure any errors from previous requests have been dealt with. */
7645 data
->string
[0] = 0;
7646 data
->prev
= x_error_message
;
7647 x_error_message
= data
;
7650 /* Undo the last x_catch_errors call.
7651 DPY should be the display that was passed to x_catch_errors. */
7656 struct x_error_message_stack
*tmp
;
7660 /* The display may have been closed before this function is called.
7661 Check if it is still open before calling XSync. */
7662 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7663 XSync (x_error_message
->dpy
, False
);
7665 tmp
= x_error_message
;
7666 x_error_message
= x_error_message
->prev
;
7671 /* If any X protocol errors have arrived since the last call to
7672 x_catch_errors or x_check_errors, signal an Emacs error using
7673 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7676 x_check_errors (dpy
, format
)
7680 /* Make sure to catch any errors incurred so far. */
7683 if (x_error_message
->string
[0])
7685 char string
[X_ERROR_MESSAGE_SIZE
];
7686 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7687 x_uncatch_errors ();
7688 error (format
, string
);
7692 /* Nonzero if we had any X protocol errors
7693 since we did x_catch_errors on DPY. */
7696 x_had_errors_p (dpy
)
7699 /* Make sure to catch any errors incurred so far. */
7702 return x_error_message
->string
[0] != 0;
7705 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7708 x_clear_errors (dpy
)
7711 x_error_message
->string
[0] = 0;
7714 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7715 * idea. --lorentey */
7716 /* Close off all unclosed x_catch_errors calls. */
7719 x_fully_uncatch_errors ()
7721 while (x_error_message
)
7722 x_uncatch_errors ();
7726 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7729 x_catching_errors ()
7731 return x_error_message
!= 0;
7735 static unsigned int x_wire_count
;
7738 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7743 /* Handle SIGPIPE, which can happen when the connection to a server
7744 simply goes away. SIGPIPE is handled by x_connection_signal.
7745 Don't need to do anything, because the write which caused the
7746 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7747 which will do the appropriate cleanup for us. */
7750 x_connection_signal (signalnum
) /* If we don't have an argument, */
7751 int signalnum
; /* some compilers complain in signal calls. */
7754 /* USG systems forget handlers when they are used;
7755 must reestablish each time */
7756 signal (signalnum
, x_connection_signal
);
7761 /************************************************************************
7763 ************************************************************************/
7765 /* Error message passed to x_connection_closed. */
7767 static char *error_msg
;
7769 /* Function installed as fatal_error_signal_hook in
7770 x_connection_closed. Print the X error message, and exit normally,
7771 instead of dumping core when XtCloseDisplay fails. */
7774 x_fatal_error_signal ()
7776 fprintf (stderr
, "%s\n", error_msg
);
7780 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7781 the text of an error message that lead to the connection loss. */
7784 x_connection_closed (dpy
, error_message
)
7786 char *error_message
;
7788 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7789 Lisp_Object frame
, tail
;
7790 int index
= SPECPDL_INDEX ();
7792 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7793 strcpy (error_msg
, error_message
);
7794 handling_signal
= 0;
7796 /* Prevent being called recursively because of an error condition
7797 below. Otherwise, we might end up with printing ``can't find per
7798 display information'' in the recursive call instead of printing
7799 the original message here. */
7800 x_catch_errors (dpy
);
7802 /* Inhibit redisplay while frames are being deleted. */
7803 specbind (Qinhibit_redisplay
, Qt
);
7807 /* Protect display from being closed when we delete the last
7809 dpyinfo
->reference_count
++;
7810 dpyinfo
->terminal
->reference_count
++;
7813 /* First delete frames whose mini-buffers are on frames
7814 that are on the dead display. */
7815 FOR_EACH_FRAME (tail
, frame
)
7817 Lisp_Object minibuf_frame
;
7819 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7820 if (FRAME_X_P (XFRAME (frame
))
7821 && FRAME_X_P (XFRAME (minibuf_frame
))
7822 && ! EQ (frame
, minibuf_frame
)
7823 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7824 delete_frame (frame
, Qnoelisp
);
7827 /* Now delete all remaining frames on the dead display.
7828 We are now sure none of these is used as the mini-buffer
7829 for another frame that we need to delete. */
7830 FOR_EACH_FRAME (tail
, frame
)
7831 if (FRAME_X_P (XFRAME (frame
))
7832 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7834 /* Set this to t so that delete_frame won't get confused
7835 trying to find a replacement. */
7836 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7837 delete_frame (frame
, Qnoelisp
);
7840 /* We have to close the display to inform Xt that it doesn't
7841 exist anymore. If we don't, Xt will continue to wait for
7842 events from the display. As a consequence, a sequence of
7844 M-x make-frame-on-display RET :1 RET
7845 ...kill the new frame, so that we get an IO error...
7846 M-x make-frame-on-display RET :1 RET
7848 will indefinitely wait in Xt for events for display `:1', opened
7849 in the first call to make-frame-on-display.
7851 Closing the display is reported to lead to a bus error on
7852 OpenWindows in certain situations. I suspect that is a bug
7853 in OpenWindows. I don't know how to circumvent it here. */
7857 #ifdef USE_X_TOOLKIT
7858 /* If DPYINFO is null, this means we didn't open the display
7859 in the first place, so don't try to close it. */
7861 extern void (*fatal_error_signal_hook
) P_ ((void));
7862 fatal_error_signal_hook
= x_fatal_error_signal
;
7863 XtCloseDisplay (dpy
);
7864 fatal_error_signal_hook
= NULL
;
7869 /* Due to bugs in some Gtk+ versions, just exit here if this
7870 is the last display/terminal. */
7871 if (terminal_list
->next_terminal
== NULL
)
7873 fprintf (stderr
, "%s\n", error_msg
);
7874 shut_down_emacs (0, 0, Qnil
);
7877 xg_display_close (dpyinfo
->display
);
7880 /* Indicate that this display is dead. */
7881 dpyinfo
->display
= 0;
7883 dpyinfo
->reference_count
--;
7884 dpyinfo
->terminal
->reference_count
--;
7885 if (dpyinfo
->reference_count
!= 0)
7886 /* We have just closed all frames on this display. */
7891 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7892 Fdelete_terminal (tmp
, Qnoelisp
);
7896 x_uncatch_errors ();
7898 if (terminal_list
== 0)
7900 fprintf (stderr
, "%s\n", error_msg
);
7901 shut_down_emacs (0, 0, Qnil
);
7905 /* Ordinary stack unwind doesn't deal with these. */
7907 sigunblock (sigmask (SIGIO
));
7909 sigunblock (sigmask (SIGALRM
));
7910 TOTALLY_UNBLOCK_INPUT
;
7912 unbind_to (index
, Qnil
);
7913 clear_waiting_for_input ();
7914 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7915 longjmp), because returning from this function would get us back into
7916 Xlib's code which will directly call `exit'. */
7917 error ("%s", error_msg
);
7920 /* We specifically use it before defining it, so that gcc doesn't inline it,
7921 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7922 static void x_error_quitter
P_ ((Display
*, XErrorEvent
*));
7924 /* This is the first-level handler for X protocol errors.
7925 It calls x_error_quitter or x_error_catcher. */
7928 x_error_handler (display
, error
)
7932 if (x_error_message
)
7933 x_error_catcher (display
, error
);
7935 x_error_quitter (display
, error
);
7939 /* This is the usual handler for X protocol errors.
7940 It kills all frames on the display that we got the error for.
7941 If that was the only one, it prints an error message and kills Emacs. */
7943 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7945 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
7946 #define NO_INLINE __attribute__((noinline))
7951 /* Some versions of GNU/Linux define noinline in their headers. */
7957 /* On older GCC versions, just putting x_error_quitter
7958 after x_error_handler prevents inlining into the former. */
7960 static void NO_INLINE
7961 x_error_quitter (display
, error
)
7965 char buf
[256], buf1
[356];
7967 /* Ignore BadName errors. They can happen because of fonts
7968 or colors that are not defined. */
7970 if (error
->error_code
== BadName
)
7973 /* Note that there is no real way portable across R3/R4 to get the
7974 original error handler. */
7976 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7977 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7978 buf
, error
->request_code
);
7979 x_connection_closed (display
, buf1
);
7983 /* This is the handler for X IO errors, always.
7984 It kills all frames on the display that we lost touch with.
7985 If that was the only one, it prints an error message and kills Emacs. */
7988 x_io_error_quitter (display
)
7993 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7994 x_connection_closed (display
, buf
);
7998 /* Changing the font of the frame. */
8000 /* Give frame F the font FONT-OBJECT as its default font. The return
8001 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
8002 frame. If it is negative, generate a new fontset from
8006 x_new_font (f
, font_object
, fontset
)
8008 Lisp_Object font_object
;
8011 struct font
*font
= XFONT_OBJECT (font_object
);
8014 fontset
= fontset_from_font (font_object
);
8015 FRAME_FONTSET (f
) = fontset
;
8016 if (FRAME_FONT (f
) == font
)
8017 /* This font is already set in frame F. There's nothing more to
8021 FRAME_FONT (f
) = font
;
8022 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
8023 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
8024 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
8025 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
8027 compute_fringe_widths (f
, 1);
8029 /* Compute the scroll bar width in character columns. */
8030 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8032 int wid
= FRAME_COLUMN_WIDTH (f
);
8033 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8034 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8038 int wid
= FRAME_COLUMN_WIDTH (f
);
8039 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8042 if (FRAME_X_WINDOW (f
) != 0)
8044 /* Don't change the size of a tip frame; there's no point in
8045 doing it because it's done in Fx_show_tip, and it leads to
8046 problems because the tip frame has no widget. */
8047 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8049 /* When the frame is maximized/fullscreen or running under for
8050 example Xmonad, x_set_window_size will be a no-op.
8051 In that case, the right thing to do is extend rows/cols to
8052 the current frame size. We do that first if x_set_window_size
8053 turns out to not be a no-op (there is no way to know).
8054 The size will be adjusted again if the frame gets a
8055 ConfigureNotify event as a result of x_set_window_size. */
8056 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8057 #ifdef USE_X_TOOLKIT
8058 /* The menu bar is not part of text lines. The tool bar
8060 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8062 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8063 int cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8065 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8066 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8072 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8075 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8084 /***********************************************************************
8086 ***********************************************************************/
8092 /* XIM destroy callback function, which is called whenever the
8093 connection to input method XIM dies. CLIENT_DATA contains a
8094 pointer to the x_display_info structure corresponding to XIM. */
8097 xim_destroy_callback (xim
, client_data
, call_data
)
8099 XPointer client_data
;
8102 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8103 Lisp_Object frame
, tail
;
8107 /* No need to call XDestroyIC.. */
8108 FOR_EACH_FRAME (tail
, frame
)
8110 struct frame
*f
= XFRAME (frame
);
8111 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8113 FRAME_XIC (f
) = NULL
;
8114 xic_free_xfontset (f
);
8118 /* No need to call XCloseIM. */
8119 dpyinfo
->xim
= NULL
;
8120 XFree (dpyinfo
->xim_styles
);
8124 #endif /* HAVE_X11R6 */
8127 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8128 extern char *XSetIMValues
P_ ((XIM
, ...));
8131 /* Open the connection to the XIM server on display DPYINFO.
8132 RESOURCE_NAME is the resource name Emacs uses. */
8135 xim_open_dpy (dpyinfo
, resource_name
)
8136 struct x_display_info
*dpyinfo
;
8137 char *resource_name
;
8145 XCloseIM (dpyinfo
->xim
);
8146 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8153 XIMCallback destroy
;
8156 /* Get supported styles and XIM values. */
8157 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8160 destroy
.callback
= xim_destroy_callback
;
8161 destroy
.client_data
= (XPointer
)dpyinfo
;
8162 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8168 #endif /* HAVE_XIM */
8169 dpyinfo
->xim
= NULL
;
8173 #ifdef HAVE_X11R6_XIM
8175 /* XIM instantiate callback function, which is called whenever an XIM
8176 server is available. DISPLAY is the display of the XIM.
8177 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8178 when the callback was registered. */
8181 xim_instantiate_callback (display
, client_data
, call_data
)
8183 XPointer client_data
;
8186 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8187 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8189 /* We don't support multiple XIM connections. */
8193 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8195 /* Create XIC for the existing frames on the same display, as long
8196 as they have no XIC. */
8197 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8199 Lisp_Object tail
, frame
;
8202 FOR_EACH_FRAME (tail
, frame
)
8204 struct frame
*f
= XFRAME (frame
);
8207 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8208 if (FRAME_XIC (f
) == NULL
)
8210 create_frame_xic (f
);
8211 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8212 xic_set_statusarea (f
);
8213 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8215 struct window
*w
= XWINDOW (f
->selected_window
);
8216 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8225 #endif /* HAVE_X11R6_XIM */
8228 /* Open a connection to the XIM server on display DPYINFO.
8229 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8230 connection only at the first time. On X11R6, open the connection
8231 in the XIM instantiate callback function. */
8234 xim_initialize (dpyinfo
, resource_name
)
8235 struct x_display_info
*dpyinfo
;
8236 char *resource_name
;
8238 dpyinfo
->xim
= NULL
;
8242 #ifdef HAVE_X11R6_XIM
8243 struct xim_inst_t
*xim_inst
;
8246 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8247 dpyinfo
->xim_callback_data
= xim_inst
;
8248 xim_inst
->dpyinfo
= dpyinfo
;
8249 len
= strlen (resource_name
);
8250 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8251 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8252 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8253 resource_name
, EMACS_CLASS
,
8254 xim_instantiate_callback
,
8255 /* This is XPointer in XFree86
8256 but (XPointer *) on Tru64, at
8257 least, hence the configure test. */
8258 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8259 #else /* not HAVE_X11R6_XIM */
8260 xim_open_dpy (dpyinfo
, resource_name
);
8261 #endif /* not HAVE_X11R6_XIM */
8263 #endif /* HAVE_XIM */
8267 /* Close the connection to the XIM server on display DPYINFO. */
8270 xim_close_dpy (dpyinfo
)
8271 struct x_display_info
*dpyinfo
;
8276 #ifdef HAVE_X11R6_XIM
8277 if (dpyinfo
->display
)
8278 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8280 xim_instantiate_callback
, NULL
);
8281 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8282 xfree (dpyinfo
->xim_callback_data
);
8283 #endif /* HAVE_X11R6_XIM */
8284 if (dpyinfo
->display
)
8285 XCloseIM (dpyinfo
->xim
);
8286 dpyinfo
->xim
= NULL
;
8287 XFree (dpyinfo
->xim_styles
);
8289 #endif /* HAVE_XIM */
8292 #endif /* not HAVE_X11R6_XIM */
8296 /* Calculate the absolute position in frame F
8297 from its current recorded position values and gravity. */
8300 x_calc_absolute_position (f
)
8303 int flags
= f
->size_hint_flags
;
8305 /* We have nothing to do if the current position
8306 is already for the top-left corner. */
8307 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8310 /* Treat negative positions as relative to the leftmost bottommost
8311 position that fits on the screen. */
8312 if (flags
& XNegative
)
8313 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8314 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8317 int height
= FRAME_PIXEL_HEIGHT (f
);
8319 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8320 /* Something is fishy here. When using Motif, starting Emacs with
8321 `-g -0-0', the frame appears too low by a few pixels.
8323 This seems to be so because initially, while Emacs is starting,
8324 the column widget's height and the frame's pixel height are
8325 different. The column widget's height is the right one. In
8326 later invocations, when Emacs is up, the frame's pixel height
8329 It's not obvious where the initial small difference comes from.
8330 2000-12-01, gerd. */
8332 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8335 if (flags
& YNegative
)
8336 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8337 - height
+ f
->top_pos
;
8340 /* The left_pos and top_pos
8341 are now relative to the top and left screen edges,
8342 so the flags should correspond. */
8343 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8346 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8347 to really change the position, and 0 when calling from
8348 x_make_frame_visible (in that case, XOFF and YOFF are the current
8349 position values). It is -1 when calling from x_set_frame_parameters,
8350 which means, do adjust for borders but don't change the gravity. */
8353 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8355 register int xoff
, yoff
;
8358 int modified_top
, modified_left
;
8360 if (change_gravity
> 0)
8362 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8363 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8367 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8369 f
->size_hint_flags
|= XNegative
;
8371 f
->size_hint_flags
|= YNegative
;
8372 f
->win_gravity
= NorthWestGravity
;
8374 x_calc_absolute_position (f
);
8377 x_wm_set_size_hint (f
, (long) 0, 0);
8379 modified_left
= f
->left_pos
;
8380 modified_top
= f
->top_pos
;
8382 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8384 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8385 than the WM decorations. So we use the calculated offset instead
8386 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8387 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8388 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8391 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8392 modified_left
, modified_top
);
8394 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8395 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8398 /* change_gravity is non-zero when this function is called from Lisp to
8399 programmatically move a frame. In that case, we call
8400 x_check_expected_move to discover if we have a "Type A" or "Type B"
8401 window manager, and, for a "Type A" window manager, adjust the position
8404 We call x_check_expected_move if a programmatic move occurred, and
8405 either the window manager type (A/B) is unknown or it is Type A but we
8406 need to compute the top/left offset adjustment for this frame. */
8408 if (change_gravity
!= 0 &&
8409 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8410 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8411 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8412 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8413 x_check_expected_move (f
, modified_left
, modified_top
);
8418 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8419 on the root window for frame F contains ATOMNAME.
8420 This is how a WM check shall be done according to the Window Manager
8421 Specification/Extended Window Manager Hints at
8422 http://freedesktop.org/wiki/Specifications/wm-spec. */
8425 wm_supports (f
, atomname
)
8427 const char *atomname
;
8430 unsigned long actual_size
, bytes_remaining
;
8431 int i
, rc
, actual_format
;
8433 Window wmcheck_window
;
8434 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8435 Window target_window
= dpyinfo
->root_window
;
8436 long max_len
= 65536;
8437 Display
*dpy
= FRAME_X_DISPLAY (f
);
8438 unsigned char *tmp_data
= NULL
;
8439 Atom target_type
= XA_WINDOW
;
8444 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8446 x_catch_errors (dpy
);
8447 rc
= XGetWindowProperty (dpy
, target_window
,
8448 prop_atom
, 0, max_len
, False
, target_type
,
8449 &actual_type
, &actual_format
, &actual_size
,
8450 &bytes_remaining
, &tmp_data
);
8452 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8454 if (tmp_data
) XFree (tmp_data
);
8455 x_uncatch_errors ();
8460 wmcheck_window
= *(Window
*) tmp_data
;
8463 /* Check if window exists. */
8464 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8466 if (x_had_errors_p (dpy
))
8468 x_uncatch_errors ();
8473 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8475 /* Window changed, reload atoms */
8476 if (dpyinfo
->net_supported_atoms
!= NULL
)
8477 XFree (dpyinfo
->net_supported_atoms
);
8478 dpyinfo
->net_supported_atoms
= NULL
;
8479 dpyinfo
->nr_net_supported_atoms
= 0;
8480 dpyinfo
->net_supported_window
= 0;
8482 target_type
= XA_ATOM
;
8483 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8485 rc
= XGetWindowProperty (dpy
, target_window
,
8486 prop_atom
, 0, max_len
, False
, target_type
,
8487 &actual_type
, &actual_format
, &actual_size
,
8488 &bytes_remaining
, &tmp_data
);
8490 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8492 if (tmp_data
) XFree (tmp_data
);
8493 x_uncatch_errors ();
8498 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8499 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8500 dpyinfo
->net_supported_window
= wmcheck_window
;
8504 want_atom
= XInternAtom (dpy
, atomname
, False
);
8506 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8507 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8509 x_uncatch_errors ();
8516 set_wm_state (frame
, add
, what
, what2
)
8522 const char *atom
= "_NET_WM_STATE";
8523 Fx_send_client_event (frame
, make_number (0), frame
,
8524 make_unibyte_string (atom
, strlen (atom
)),
8526 /* 1 = add, 0 = remove */
8528 (make_number (add
? 1 : 0),
8530 (make_unibyte_string (what
, strlen (what
)),
8532 ? Fcons (make_unibyte_string (what2
, strlen (what2
)),
8538 x_set_sticky (f
, new_value
, old_value
)
8540 Lisp_Object new_value
, old_value
;
8544 XSETFRAME (frame
, f
);
8545 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8546 "_NET_WM_STATE_STICKY", NULL
);
8549 /* Do fullscreen as specified in extended window manager hints */
8552 do_ewmh_fullscreen (f
)
8555 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8557 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8558 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8560 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8565 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8566 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8567 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8569 XSETFRAME (frame
, f
);
8571 set_wm_state (frame
, 0, fs
, NULL
);
8572 set_wm_state (frame
, 0, fh
, NULL
);
8573 set_wm_state (frame
, 0, fw
, NULL
);
8575 /* If there are _NET_ atoms we assume we have extended window manager
8577 switch (f
->want_fullscreen
)
8579 case FULLSCREEN_BOTH
:
8580 set_wm_state (frame
, 1, fs
, NULL
);
8582 case FULLSCREEN_WIDTH
:
8583 set_wm_state (frame
, 1, fw
, NULL
);
8585 case FULLSCREEN_HEIGHT
:
8586 set_wm_state (frame
, 1, fh
, NULL
);
8588 case FULLSCREEN_MAXIMIZED
:
8589 set_wm_state (frame
, 1, fw
, fh
);
8593 f
->want_fullscreen
= FULLSCREEN_NONE
;
8597 return have_net_atom
;
8601 XTfullscreen_hook (f
)
8604 if (f
->async_visible
)
8607 x_check_fullscreen (f
);
8615 x_handle_net_wm_state (f
, event
)
8617 XPropertyEvent
*event
;
8620 unsigned long actual_size
, bytes_remaining
;
8621 int i
, rc
, actual_format
, value
= FULLSCREEN_NONE
;
8622 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8623 long max_len
= 65536;
8624 Display
*dpy
= FRAME_X_DISPLAY (f
);
8625 unsigned char *tmp_data
= NULL
;
8626 Atom target_type
= XA_ATOM
;
8631 x_catch_errors (dpy
);
8632 rc
= XGetWindowProperty (dpy
, event
->window
,
8633 event
->atom
, 0, max_len
, False
, target_type
,
8634 &actual_type
, &actual_format
, &actual_size
,
8635 &bytes_remaining
, &tmp_data
);
8637 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8639 if (tmp_data
) XFree (tmp_data
);
8640 x_uncatch_errors ();
8645 x_uncatch_errors ();
8647 for (i
= 0; i
< actual_size
; ++i
)
8649 Atom a
= ((Atom
*)tmp_data
)[i
];
8650 if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8652 if (value
== FULLSCREEN_HEIGHT
)
8653 value
= FULLSCREEN_MAXIMIZED
;
8655 value
= FULLSCREEN_WIDTH
;
8657 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8659 if (value
== FULLSCREEN_WIDTH
)
8660 value
= FULLSCREEN_MAXIMIZED
;
8662 value
= FULLSCREEN_HEIGHT
;
8664 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen_atom
)
8665 value
= FULLSCREEN_BOTH
;
8666 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8673 case FULLSCREEN_WIDTH
:
8676 case FULLSCREEN_HEIGHT
:
8679 case FULLSCREEN_BOTH
:
8682 case FULLSCREEN_MAXIMIZED
:
8687 store_frame_param (f
, Qfullscreen
, lval
);
8688 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8690 if (tmp_data
) XFree (tmp_data
);
8694 /* Check if we need to resize the frame due to a fullscreen request.
8695 If so needed, resize the frame. */
8697 x_check_fullscreen (f
)
8700 if (do_ewmh_fullscreen (f
))
8703 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8704 return; /* Only fullscreen without WM or with EWM hints (above). */
8706 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8708 int width
= FRAME_COLS (f
), height
= FRAME_LINES (f
);
8709 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8711 switch (f
->want_fullscreen
)
8713 /* No difference between these two when there is no WM */
8714 case FULLSCREEN_BOTH
:
8715 case FULLSCREEN_MAXIMIZED
:
8716 width
= x_display_pixel_width (dpyinfo
);
8717 height
= x_display_pixel_height (dpyinfo
);
8719 case FULLSCREEN_WIDTH
:
8720 width
= x_display_pixel_width (dpyinfo
);
8722 case FULLSCREEN_HEIGHT
:
8723 height
= x_display_pixel_height (dpyinfo
);
8726 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8728 change_frame_size (f
, height
, width
, 0, 1, 0);
8729 SET_FRAME_GARBAGED (f
);
8730 cancel_mouse_face (f
);
8735 /* This function is called by x_set_offset to determine whether the window
8736 manager interfered with the positioning of the frame. Type A window
8737 managers position the surrounding window manager decorations a small
8738 amount above and left of the user-supplied position. Type B window
8739 managers position the surrounding window manager decorations at the
8740 user-specified position. If we detect a Type A window manager, we
8741 compensate by moving the window right and down by the proper amount. */
8744 x_check_expected_move (f
, expected_left
, expected_top
)
8749 int current_left
= 0, current_top
= 0;
8751 /* x_real_positions returns the left and top offsets of the outermost
8752 window manager window around the frame. */
8754 x_real_positions (f
, ¤t_left
, ¤t_top
);
8756 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8758 /* It's a "Type A" window manager. */
8763 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8764 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8765 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8767 /* Now fix the mispositioned frame's location. */
8769 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8770 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8772 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8773 adjusted_left
, adjusted_top
);
8775 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8778 /* It's a "Type B" window manager. We don't have to adjust the
8779 frame's position. */
8781 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8785 /* Wait for XGetGeometry to return up-to-date position information for a
8786 recently-moved frame. Call this immediately after calling XMoveWindow.
8787 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8788 frame has been moved to, so we use a fuzzy position comparison instead
8789 of an exact comparison. */
8792 x_sync_with_move (f
, left
, top
, fuzzy
)
8794 int left
, top
, fuzzy
;
8798 while (count
++ < 50)
8800 int current_left
= 0, current_top
= 0;
8802 /* In theory, this call to XSync only needs to happen once, but in
8803 practice, it doesn't seem to work, hence the need for the surrounding
8806 XSync (FRAME_X_DISPLAY (f
), False
);
8807 x_real_positions (f
, ¤t_left
, ¤t_top
);
8811 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8814 if (eabs (current_left
- left
) <= 10
8815 && eabs (current_top
- top
) <= 40)
8818 else if (current_left
== left
&& current_top
== top
)
8822 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8823 will then return up-to-date position info. */
8825 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8829 /* Wait for an event on frame F matching EVENTTYPE. */
8831 x_wait_for_event (f
, eventtype
)
8835 int level
= interrupt_input_blocked
;
8838 EMACS_TIME tmo
, tmo_at
, time_now
;
8839 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8841 pending_event_wait
.f
= f
;
8842 pending_event_wait
.eventtype
= eventtype
;
8844 /* Set timeout to 0.1 second. Hopefully not noticable.
8845 Maybe it should be configurable. */
8846 EMACS_SET_SECS_USECS (tmo
, 0, 100000);
8847 EMACS_GET_TIME (tmo_at
);
8848 EMACS_ADD_TIME (tmo_at
, tmo_at
, tmo
);
8850 while (pending_event_wait
.eventtype
)
8852 interrupt_input_pending
= 1;
8853 TOTALLY_UNBLOCK_INPUT
;
8854 /* XTread_socket is called after unblock. */
8856 interrupt_input_blocked
= level
;
8861 EMACS_GET_TIME (time_now
);
8862 EMACS_SUB_TIME (tmo
, tmo_at
, time_now
);
8864 if (EMACS_TIME_NEG_P (tmo
) || select (fd
+1, &fds
, NULL
, NULL
, &tmo
) == 0)
8865 break; /* Timeout */
8867 pending_event_wait
.f
= 0;
8868 pending_event_wait
.eventtype
= 0;
8872 /* Change the size of frame F's X window to COLS/ROWS in the case F
8873 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8874 top-left-corner window gravity for this size change and subsequent
8875 size changes. Otherwise we leave the window gravity unchanged. */
8878 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8883 int pixelwidth
, pixelheight
;
8885 check_frame_size (f
, &rows
, &cols
);
8886 f
->scroll_bar_actual_width
8887 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8889 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
8890 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
8891 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
8893 compute_fringe_widths (f
, 0);
8895 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8896 + 2*f
->border_width
;
8897 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8898 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
)
8899 + 2*f
->border_width
;
8901 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8902 x_wm_set_size_hint (f
, (long) 0, 0);
8903 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8904 pixelwidth
, pixelheight
);
8907 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8908 receive in the ConfigureNotify event; if we get what we asked
8909 for, then the event won't cause the screen to become garbaged, so
8910 we have to make sure to do it here. */
8911 SET_FRAME_GARBAGED (f
);
8913 /* Now, strictly speaking, we can't be sure that this is accurate,
8914 but the window manager will get around to dealing with the size
8915 change request eventually, and we'll hear how it went when the
8916 ConfigureNotify event gets here.
8918 We could just not bother storing any of this information here,
8919 and let the ConfigureNotify event set everything up, but that
8920 might be kind of confusing to the Lisp code, since size changes
8921 wouldn't be reported in the frame parameters until some random
8922 point in the future when the ConfigureNotify event arrives.
8924 We pass 1 for DELAY since we can't run Lisp code inside of
8927 /* But the ConfigureNotify may in fact never arrive, and then this is
8928 not right if the frame is visible. Instead wait (with timeout)
8929 for the ConfigureNotify. */
8930 if (f
->async_visible
)
8931 x_wait_for_event (f
, ConfigureNotify
);
8934 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8935 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8936 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8942 /* Call this to change the size of frame F's x-window.
8943 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8944 for this size change and subsequent size changes.
8945 Otherwise we leave the window gravity unchanged. */
8948 x_set_window_size (f
, change_gravity
, cols
, rows
)
8956 if (FRAME_GTK_WIDGET (f
))
8957 xg_frame_set_char_size (f
, cols
, rows
);
8959 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8960 #else /* not USE_GTK */
8962 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8964 #endif /* not USE_GTK */
8966 /* If cursor was outside the new size, mark it as off. */
8967 mark_window_cursors_off (XWINDOW (f
->root_window
));
8969 /* Clear out any recollection of where the mouse highlighting was,
8970 since it might be in a place that's outside the new frame size.
8971 Actually checking whether it is outside is a pain in the neck,
8972 so don't try--just let the highlighting be done afresh with new size. */
8973 cancel_mouse_face (f
);
8978 /* Mouse warping. */
8981 x_set_mouse_position (f
, x
, y
)
8987 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8988 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8990 if (pix_x
< 0) pix_x
= 0;
8991 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8993 if (pix_y
< 0) pix_y
= 0;
8994 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8998 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8999 0, 0, 0, 0, pix_x
, pix_y
);
9003 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
9006 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9012 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9013 0, 0, 0, 0, pix_x
, pix_y
);
9017 /* focus shifting, raising and lowering. */
9020 x_focus_on_frame (f
)
9024 /* I don't think that the ICCCM allows programs to do things like this
9025 without the interaction of the window manager. Whatever you end up
9026 doing with this code, do it to x_unfocus_frame too. */
9027 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9028 RevertToPointerRoot
, CurrentTime
);
9037 /* Look at the remarks in x_focus_on_frame. */
9038 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
9039 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
9040 RevertToPointerRoot
, CurrentTime
);
9044 /* Raise frame F. */
9051 if (f
->async_visible
)
9052 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9054 XFlush (FRAME_X_DISPLAY (f
));
9058 /* Lower frame F. */
9064 if (f
->async_visible
)
9067 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9068 XFlush (FRAME_X_DISPLAY (f
));
9073 /* Activate frame with Extended Window Manager Hints */
9076 x_ewmh_activate_frame (f
)
9079 /* See Window Manager Specification/Extended Window Manager Hints at
9080 http://freedesktop.org/wiki/Specifications/wm-spec */
9082 const char *atom
= "_NET_ACTIVE_WINDOW";
9083 if (f
->async_visible
&& wm_supports (f
, atom
))
9086 XSETFRAME (frame
, f
);
9087 Fx_send_client_event (frame
, make_number (0), frame
,
9088 make_unibyte_string (atom
, strlen (atom
)),
9090 Fcons (make_number (1),
9091 Fcons (make_number (last_user_time
),
9097 XTframe_raise_lower (f
, raise_flag
)
9107 /* XEmbed implementation. */
9110 xembed_set_info (f
, flags
)
9112 enum xembed_info flags
;
9115 unsigned long data
[2];
9117 atom
= XInternAtom (FRAME_X_DISPLAY (f
), "_XEMBED_INFO", False
);
9119 data
[0] = XEMBED_VERSION
;
9122 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), atom
, atom
,
9123 32, PropModeReplace
, (unsigned char *) data
, 2);
9127 xembed_send_message (f
, time
, message
, detail
, data1
, data2
)
9130 enum xembed_message message
;
9137 event
.xclient
.type
= ClientMessage
;
9138 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9139 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9140 event
.xclient
.format
= 32;
9141 event
.xclient
.data
.l
[0] = time
;
9142 event
.xclient
.data
.l
[1] = message
;
9143 event
.xclient
.data
.l
[2] = detail
;
9144 event
.xclient
.data
.l
[3] = data1
;
9145 event
.xclient
.data
.l
[4] = data2
;
9147 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9148 False
, NoEventMask
, &event
);
9149 XSync (FRAME_X_DISPLAY (f
), False
);
9152 /* Change of visibility. */
9154 /* This tries to wait until the frame is really visible.
9155 However, if the window manager asks the user where to position
9156 the frame, this will return before the user finishes doing that.
9157 The frame will not actually be visible at that time,
9158 but it will become visible later when the window manager
9159 finishes with it. */
9162 x_make_frame_visible (f
)
9166 int original_top
, original_left
;
9167 int retry_count
= 2;
9173 type
= x_icon_type (f
);
9175 x_bitmap_icon (f
, type
);
9177 if (! FRAME_VISIBLE_P (f
))
9179 /* We test FRAME_GARBAGED_P here to make sure we don't
9180 call x_set_offset a second time
9181 if we get to x_make_frame_visible a second time
9182 before the window gets really visible. */
9183 if (! FRAME_ICONIFIED_P (f
)
9184 && ! FRAME_X_EMBEDDED_P (f
)
9185 && ! f
->output_data
.x
->asked_for_visible
)
9186 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9188 f
->output_data
.x
->asked_for_visible
= 1;
9190 if (! EQ (Vx_no_window_manager
, Qt
))
9191 x_wm_set_window_state (f
, NormalState
);
9192 #ifdef USE_X_TOOLKIT
9193 if (FRAME_X_EMBEDDED_P (f
))
9194 xembed_set_info (f
, XEMBED_MAPPED
);
9197 /* This was XtPopup, but that did nothing for an iconified frame. */
9198 XtMapWidget (f
->output_data
.x
->widget
);
9200 #else /* not USE_X_TOOLKIT */
9202 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9203 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9205 if (FRAME_X_EMBEDDED_P (f
))
9206 xembed_set_info (f
, XEMBED_MAPPED
);
9208 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9209 #endif /* not USE_GTK */
9210 #endif /* not USE_X_TOOLKIT */
9213 XFlush (FRAME_X_DISPLAY (f
));
9215 /* Synchronize to ensure Emacs knows the frame is visible
9216 before we do anything else. We do this loop with input not blocked
9217 so that incoming events are handled. */
9221 /* This must be before UNBLOCK_INPUT
9222 since events that arrive in response to the actions above
9223 will set it when they are handled. */
9224 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9226 original_left
= f
->left_pos
;
9227 original_top
= f
->top_pos
;
9229 /* This must come after we set COUNT. */
9232 /* We unblock here so that arriving X events are processed. */
9234 /* Now move the window back to where it was "supposed to be".
9235 But don't do it if the gravity is negative.
9236 When the gravity is negative, this uses a position
9237 that is 3 pixels too low. Perhaps that's really the border width.
9239 Don't do this if the window has never been visible before,
9240 because the window manager may choose the position
9241 and we don't want to override it. */
9243 if (! FRAME_VISIBLE_P (f
)
9244 && ! FRAME_ICONIFIED_P (f
)
9245 && ! FRAME_X_EMBEDDED_P (f
)
9246 && f
->win_gravity
== NorthWestGravity
9247 && previously_visible
)
9251 unsigned int width
, height
, border
, depth
;
9255 /* On some window managers (such as FVWM) moving an existing
9256 window, even to the same place, causes the window manager
9257 to introduce an offset. This can cause the window to move
9258 to an unexpected location. Check the geometry (a little
9259 slow here) and then verify that the window is in the right
9260 place. If the window is not in the right place, move it
9261 there, and take the potential window manager hit. */
9262 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9263 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9265 if (original_left
!= x
|| original_top
!= y
)
9266 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9267 original_left
, original_top
);
9272 XSETFRAME (frame
, f
);
9274 /* Wait until the frame is visible. Process X events until a
9275 MapNotify event has been seen, or until we think we won't get a
9276 MapNotify at all.. */
9277 for (count
= input_signal_count
+ 10;
9278 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9280 /* Force processing of queued events. */
9283 /* Machines that do polling rather than SIGIO have been
9284 observed to go into a busy-wait here. So we'll fake an
9285 alarm signal to let the handler know that there's something
9286 to be read. We used to raise a real alarm, but it seems
9287 that the handler isn't always enabled here. This is
9289 if (input_polling_used ())
9291 /* It could be confusing if a real alarm arrives while
9292 processing the fake one. Turn it off and let the
9293 handler reset it. */
9294 extern void poll_for_input_1
P_ ((void));
9295 int old_poll_suppress_count
= poll_suppress_count
;
9296 poll_suppress_count
= 1;
9297 poll_for_input_1 ();
9298 poll_suppress_count
= old_poll_suppress_count
;
9301 /* See if a MapNotify event has been processed. */
9302 FRAME_SAMPLE_VISIBILITY (f
);
9307 (let ((f (selected-frame)))
9311 the frame is not raised with various window managers on
9312 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9313 unknown reason, the call to XtMapWidget is completely ignored.
9314 Mapping the widget a second time works. */
9316 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9321 /* Change from mapped state to withdrawn state. */
9323 /* Make the frame visible (mapped and not iconified). */
9326 x_make_frame_invisible (f
)
9331 /* Use the frame's outermost window, not the one we normally draw on. */
9332 window
= FRAME_OUTER_WINDOW (f
);
9334 /* Don't keep the highlight on an invisible frame. */
9335 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9336 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9340 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9341 that the current position of the window is user-specified, rather than
9342 program-specified, so that when the window is mapped again, it will be
9343 placed at the same location, without forcing the user to position it
9344 by hand again (they have already done that once for this window.) */
9345 x_wm_set_size_hint (f
, (long) 0, 1);
9348 if (FRAME_GTK_OUTER_WIDGET (f
))
9349 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9352 if (FRAME_X_EMBEDDED_P (f
))
9353 xembed_set_info (f
, 0);
9358 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9359 DefaultScreen (FRAME_X_DISPLAY (f
))))
9361 UNBLOCK_INPUT_RESIGNAL
;
9362 error ("Can't notify window manager of window withdrawal");
9366 /* We can't distinguish this from iconification
9367 just by the event that we get from the server.
9368 So we can't win using the usual strategy of letting
9369 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9370 and synchronize with the server to make sure we agree. */
9372 FRAME_ICONIFIED_P (f
) = 0;
9373 f
->async_visible
= 0;
9374 f
->async_iconified
= 0;
9381 /* Change window state from mapped to iconified. */
9390 /* Don't keep the highlight on an invisible frame. */
9391 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9392 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9394 if (f
->async_iconified
)
9399 FRAME_SAMPLE_VISIBILITY (f
);
9401 type
= x_icon_type (f
);
9403 x_bitmap_icon (f
, type
);
9406 if (FRAME_GTK_OUTER_WIDGET (f
))
9408 if (! FRAME_VISIBLE_P (f
))
9409 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9411 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9414 f
->async_iconified
= 1;
9415 f
->async_visible
= 0;
9421 #ifdef USE_X_TOOLKIT
9423 if (! FRAME_VISIBLE_P (f
))
9425 if (! EQ (Vx_no_window_manager
, Qt
))
9426 x_wm_set_window_state (f
, IconicState
);
9427 /* This was XtPopup, but that did nothing for an iconified frame. */
9428 XtMapWidget (f
->output_data
.x
->widget
);
9429 /* The server won't give us any event to indicate
9430 that an invisible frame was changed to an icon,
9431 so we have to record it here. */
9434 f
->async_iconified
= 1;
9435 f
->async_visible
= 0;
9440 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9441 XtWindow (f
->output_data
.x
->widget
),
9442 DefaultScreen (FRAME_X_DISPLAY (f
)));
9446 error ("Can't notify window manager of iconification");
9448 f
->async_iconified
= 1;
9449 f
->async_visible
= 0;
9453 XFlush (FRAME_X_DISPLAY (f
));
9455 #else /* not USE_X_TOOLKIT */
9457 /* Make sure the X server knows where the window should be positioned,
9458 in case the user deiconifies with the window manager. */
9459 if (! FRAME_VISIBLE_P (f
)
9460 && ! FRAME_ICONIFIED_P (f
)
9461 && ! FRAME_X_EMBEDDED_P (f
))
9462 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9464 /* Since we don't know which revision of X we're running, we'll use both
9465 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9467 /* X11R4: send a ClientMessage to the window manager using the
9468 WM_CHANGE_STATE type. */
9472 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9473 message
.xclient
.type
= ClientMessage
;
9474 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9475 message
.xclient
.format
= 32;
9476 message
.xclient
.data
.l
[0] = IconicState
;
9478 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9479 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9481 SubstructureRedirectMask
| SubstructureNotifyMask
,
9484 UNBLOCK_INPUT_RESIGNAL
;
9485 error ("Can't notify window manager of iconification");
9489 /* X11R3: set the initial_state field of the window manager hints to
9491 x_wm_set_window_state (f
, IconicState
);
9493 if (!FRAME_VISIBLE_P (f
))
9495 /* If the frame was withdrawn, before, we must map it. */
9496 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9499 f
->async_iconified
= 1;
9500 f
->async_visible
= 0;
9502 XFlush (FRAME_X_DISPLAY (f
));
9504 #endif /* not USE_X_TOOLKIT */
9508 /* Free X resources of frame F. */
9511 x_free_frame_resources (f
)
9514 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9516 struct scroll_bar
*b
;
9520 /* If a display connection is dead, don't try sending more
9521 commands to the X server. */
9522 if (dpyinfo
->display
)
9524 /* We must free faces before destroying windows because some
9525 font-driver (e.g. xft) access a window while finishing a
9527 if (FRAME_FACE_CACHE (f
))
9528 free_frame_faces (f
);
9530 if (f
->output_data
.x
->icon_desc
)
9531 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9533 #ifdef USE_X_TOOLKIT
9534 /* Explicitly destroy the scroll bars of the frame. Without
9535 this, we get "BadDrawable" errors from the toolkit later on,
9536 presumably from expose events generated for the disappearing
9537 toolkit scroll bars. */
9538 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9540 b
= XSCROLL_BAR (bar
);
9541 x_scroll_bar_remove (b
);
9550 #ifdef USE_X_TOOLKIT
9551 if (f
->output_data
.x
->widget
)
9553 XtDestroyWidget (f
->output_data
.x
->widget
);
9554 f
->output_data
.x
->widget
= NULL
;
9556 /* Tooltips don't have widgets, only a simple X window, even if
9557 we are using a toolkit. */
9558 else if (FRAME_X_WINDOW (f
))
9559 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9561 free_frame_menubar (f
);
9562 #else /* !USE_X_TOOLKIT */
9565 /* In the GTK version, tooltips are normal X
9566 frames. We must check and free both types. */
9567 if (FRAME_GTK_OUTER_WIDGET (f
))
9569 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9570 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9571 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9573 #endif /* USE_GTK */
9575 if (FRAME_X_WINDOW (f
))
9576 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9577 #endif /* !USE_X_TOOLKIT */
9579 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9580 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9581 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9582 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9583 unload_color (f
, f
->output_data
.x
->border_pixel
);
9584 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9586 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9587 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9588 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9589 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9590 #ifdef USE_TOOLKIT_SCROLL_BARS
9591 /* Scrollbar shadow colors. */
9592 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9593 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9594 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9595 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9596 #endif /* USE_TOOLKIT_SCROLL_BARS */
9597 if (f
->output_data
.x
->white_relief
.allocated_p
)
9598 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9599 if (f
->output_data
.x
->black_relief
.allocated_p
)
9600 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9603 XFlush (FRAME_X_DISPLAY (f
));
9606 xfree (f
->output_data
.x
->saved_menu_event
);
9607 xfree (f
->output_data
.x
);
9608 f
->output_data
.x
= NULL
;
9610 if (f
== dpyinfo
->x_focus_frame
)
9611 dpyinfo
->x_focus_frame
= 0;
9612 if (f
== dpyinfo
->x_focus_event_frame
)
9613 dpyinfo
->x_focus_event_frame
= 0;
9614 if (f
== dpyinfo
->x_highlight_frame
)
9615 dpyinfo
->x_highlight_frame
= 0;
9617 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9619 dpyinfo
->mouse_face_beg_row
9620 = dpyinfo
->mouse_face_beg_col
= -1;
9621 dpyinfo
->mouse_face_end_row
9622 = dpyinfo
->mouse_face_end_col
= -1;
9623 dpyinfo
->mouse_face_window
= Qnil
;
9624 dpyinfo
->mouse_face_deferred_gc
= 0;
9625 dpyinfo
->mouse_face_mouse_frame
= 0;
9632 /* Destroy the X window of frame F. */
9635 x_destroy_window (f
)
9638 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9640 /* If a display connection is dead, don't try sending more
9641 commands to the X server. */
9642 if (dpyinfo
->display
!= 0)
9643 x_free_frame_resources (f
);
9645 dpyinfo
->reference_count
--;
9649 /* Setting window manager hints. */
9651 /* Set the normal size hints for the window manager, for frame F.
9652 FLAGS is the flags word to use--or 0 meaning preserve the flags
9653 that the window now has.
9654 If USER_POSITION is nonzero, we set the USPosition
9655 flag (this is useful when FLAGS is 0).
9656 The GTK version is in gtkutils.c */
9660 x_wm_set_size_hint (f
, flags
, user_position
)
9665 XSizeHints size_hints
;
9666 Window window
= FRAME_OUTER_WINDOW (f
);
9668 /* Setting PMaxSize caused various problems. */
9669 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9671 size_hints
.x
= f
->left_pos
;
9672 size_hints
.y
= f
->top_pos
;
9674 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9675 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9677 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9678 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9679 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9680 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9681 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9682 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9684 /* Calculate the base and minimum sizes. */
9686 int base_width
, base_height
;
9687 int min_rows
= 0, min_cols
= 0;
9689 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9690 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9692 check_frame_size (f
, &min_rows
, &min_cols
);
9694 /* The window manager uses the base width hints to calculate the
9695 current number of rows and columns in the frame while
9696 resizing; min_width and min_height aren't useful for this
9697 purpose, since they might not give the dimensions for a
9698 zero-row, zero-column frame.
9700 We use the base_width and base_height members if we have
9701 them; otherwise, we set the min_width and min_height members
9702 to the size for a zero x zero frame. */
9704 size_hints
.flags
|= PBaseSize
;
9705 size_hints
.base_width
= base_width
;
9706 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9707 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9708 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9711 /* If we don't need the old flags, we don't need the old hint at all. */
9714 size_hints
.flags
|= flags
;
9719 XSizeHints hints
; /* Sometimes I hate X Windows... */
9720 long supplied_return
;
9723 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9727 size_hints
.flags
|= flags
;
9732 if (hints
.flags
& PSize
)
9733 size_hints
.flags
|= PSize
;
9734 if (hints
.flags
& PPosition
)
9735 size_hints
.flags
|= PPosition
;
9736 if (hints
.flags
& USPosition
)
9737 size_hints
.flags
|= USPosition
;
9738 if (hints
.flags
& USSize
)
9739 size_hints
.flags
|= USSize
;
9746 size_hints
.win_gravity
= f
->win_gravity
;
9747 size_hints
.flags
|= PWinGravity
;
9751 size_hints
.flags
&= ~ PPosition
;
9752 size_hints
.flags
|= USPosition
;
9754 #endif /* PWinGravity */
9756 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9758 #endif /* not USE_GTK */
9760 /* Used for IconicState or NormalState */
9763 x_wm_set_window_state (f
, state
)
9767 #ifdef USE_X_TOOLKIT
9770 XtSetArg (al
[0], XtNinitialState
, state
);
9771 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9772 #else /* not USE_X_TOOLKIT */
9773 Window window
= FRAME_X_WINDOW (f
);
9775 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9776 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9778 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9779 #endif /* not USE_X_TOOLKIT */
9783 x_wm_set_icon_pixmap (f
, pixmap_id
)
9787 Pixmap icon_pixmap
, icon_mask
;
9789 #ifndef USE_X_TOOLKIT
9790 Window window
= FRAME_OUTER_WINDOW (f
);
9795 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9796 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9797 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9798 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9802 /* It seems there is no way to turn off use of an icon
9810 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9814 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9818 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9819 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9820 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9821 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9824 #else /* not USE_X_TOOLKIT && not USE_GTK */
9826 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9827 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9829 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9833 x_wm_set_icon_position (f
, icon_x
, icon_y
)
9837 Window window
= FRAME_OUTER_WINDOW (f
);
9839 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9840 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9841 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9843 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9847 /***********************************************************************
9849 ***********************************************************************/
9853 /* Check that FONT is valid on frame F. It is if it can be found in F's
9857 x_check_font (f
, font
)
9863 xassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9864 if (font
->driver
->check
)
9865 xassert (font
->driver
->check (f
, font
) == 0);
9868 #endif /* GLYPH_DEBUG != 0 */
9871 /***********************************************************************
9873 ***********************************************************************/
9875 #ifdef USE_X_TOOLKIT
9876 static XrmOptionDescRec emacs_options
[] = {
9877 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9878 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9880 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9881 XrmoptionSepArg
, NULL
},
9882 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9884 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9885 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9886 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9887 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9888 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9889 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9890 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9893 /* Whether atimer for Xt timeouts is activated or not. */
9895 static int x_timeout_atimer_activated_flag
;
9897 #endif /* USE_X_TOOLKIT */
9899 static int x_initialized
;
9902 static int x_session_initialized
;
9905 /* Test whether two display-name strings agree up to the dot that separates
9906 the screen number from the server number. */
9908 same_x_server (name1
, name2
)
9909 const char *name1
, *name2
;
9912 const unsigned char *system_name
= SDATA (Vsystem_name
);
9913 int system_name_length
= strlen (system_name
);
9914 int length_until_period
= 0;
9916 while (system_name
[length_until_period
] != 0
9917 && system_name
[length_until_period
] != '.')
9918 length_until_period
++;
9920 /* Treat `unix' like an empty host name. */
9921 if (! strncmp (name1
, "unix:", 5))
9923 if (! strncmp (name2
, "unix:", 5))
9925 /* Treat this host's name like an empty host name. */
9926 if (! strncmp (name1
, system_name
, system_name_length
)
9927 && name1
[system_name_length
] == ':')
9928 name1
+= system_name_length
;
9929 if (! strncmp (name2
, system_name
, system_name_length
)
9930 && name2
[system_name_length
] == ':')
9931 name2
+= system_name_length
;
9932 /* Treat this host's domainless name like an empty host name. */
9933 if (! strncmp (name1
, system_name
, length_until_period
)
9934 && name1
[length_until_period
] == ':')
9935 name1
+= length_until_period
;
9936 if (! strncmp (name2
, system_name
, length_until_period
)
9937 && name2
[length_until_period
] == ':')
9938 name2
+= length_until_period
;
9940 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9944 if (seen_colon
&& *name1
== '.')
9948 && (*name1
== '.' || *name1
== '\0')
9949 && (*name2
== '.' || *name2
== '\0'));
9952 /* Count number of set bits in mask and number of bits to shift to
9953 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9956 get_bits_and_offset (mask
, bits
, offset
)
9980 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9981 But don't permanently open it, just test its availability. */
9984 x_display_ok (display
)
9985 const char *display
;
9990 dpy
= XOpenDisplay (display
);
9992 XCloseDisplay (dpy
);
9998 /* Open a connection to X display DISPLAY_NAME, and return
9999 the structure that describes the open display.
10000 If we cannot contact the display, return null. */
10002 struct x_display_info
*
10003 x_term_init (display_name
, xrm_option
, resource_name
)
10004 Lisp_Object display_name
;
10006 char *resource_name
;
10010 struct terminal
*terminal
;
10011 struct x_display_info
*dpyinfo
;
10016 if (!x_initialized
)
10022 if (! x_display_ok (SDATA (display_name
)))
10023 error ("Display %s can't be opened", SDATA (display_name
));
10027 #define NUM_ARGV 10
10029 char *argv
[NUM_ARGV
];
10030 char **argv2
= argv
;
10033 #ifndef HAVE_GTK_MULTIDISPLAY
10034 if (!EQ (Vinitial_window_system
, Qx
))
10035 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
10038 if (x_initialized
++ > 1)
10040 #ifdef HAVE_GTK_MULTIDISPLAY
10041 /* Opening another display. If xg_display_open returns less
10042 than zero, we are probably on GTK 2.0, which can only handle
10043 one display. GTK 2.2 or later can handle more than one. */
10044 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
10046 error ("Sorry, this version of GTK can only handle one display");
10050 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10054 argv
[argc
++] = initial_argv
[0];
10056 if (! NILP (display_name
))
10058 argv
[argc
++] = "--display";
10059 argv
[argc
++] = SDATA (display_name
);
10062 argv
[argc
++] = "--name";
10063 argv
[argc
++] = resource_name
;
10065 XSetLocaleModifiers ("");
10067 gtk_init (&argc
, &argv2
);
10069 /* gtk_init does set_locale. We must fix locale after calling it. */
10073 dpy
= GDK_DISPLAY ();
10075 /* NULL window -> events for all windows go to our function */
10076 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10078 /* Load our own gtkrc if it exists. */
10080 char *file
= "~/.emacs.d/gtkrc";
10081 Lisp_Object s
, abs_file
;
10083 s
= make_string (file
, strlen (file
));
10084 abs_file
= Fexpand_file_name (s
, Qnil
);
10086 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10087 gtk_rc_parse (SDATA (abs_file
));
10090 XSetErrorHandler (x_error_handler
);
10091 XSetIOErrorHandler (x_io_error_quitter
);
10094 #else /* not USE_GTK */
10095 #ifdef USE_X_TOOLKIT
10096 /* weiner@footloose.sps.mot.com reports that this causes
10098 X protocol error: BadAtom (invalid Atom parameter)
10099 on protocol request 18skiloaf.
10100 So let's not use it until R6. */
10101 #ifdef HAVE_X11XTR6
10102 XtSetLanguageProc (NULL
, NULL
, NULL
);
10113 argv
[argc
++] = "-xrm";
10114 argv
[argc
++] = xrm_option
;
10116 turn_on_atimers (0);
10117 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
10118 resource_name
, EMACS_CLASS
,
10119 emacs_options
, XtNumber (emacs_options
),
10121 turn_on_atimers (1);
10123 #ifdef HAVE_X11XTR6
10124 /* I think this is to compensate for XtSetLanguageProc. */
10129 #else /* not USE_X_TOOLKIT */
10130 XSetLocaleModifiers ("");
10131 dpy
= XOpenDisplay (SDATA (display_name
));
10132 #endif /* not USE_X_TOOLKIT */
10133 #endif /* not USE_GTK*/
10135 /* Detect failure. */
10142 /* We have definitely succeeded. Record the new connection. */
10144 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
10145 bzero (dpyinfo
, sizeof *dpyinfo
);
10147 terminal
= x_create_terminal (dpyinfo
);
10150 struct x_display_info
*share
;
10153 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10154 share
= share
->next
, tail
= XCDR (tail
))
10155 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
10156 SDATA (display_name
)))
10159 terminal
->kboard
= share
->terminal
->kboard
;
10162 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
10163 init_kboard (terminal
->kboard
);
10164 terminal
->kboard
->Vwindow_system
= Qx
;
10165 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10167 char *vendor
= ServerVendor (dpy
);
10168 /* Temporarily hide the partially initialized terminal */
10169 terminal_list
= terminal
->next_terminal
;
10171 terminal
->kboard
->Vsystem_key_alist
10172 = call1 (Qvendor_specific_keysyms
,
10173 vendor
? build_string (vendor
) : empty_unibyte_string
);
10175 terminal
->next_terminal
= terminal_list
;
10176 terminal_list
= terminal
;
10179 terminal
->kboard
->next_kboard
= all_kboards
;
10180 all_kboards
= terminal
->kboard
;
10181 /* Don't let the initial kboard remain current longer than necessary.
10182 That would cause problems if a file loaded on startup tries to
10183 prompt in the mini-buffer. */
10184 if (current_kboard
== initial_kboard
)
10185 current_kboard
= terminal
->kboard
;
10187 terminal
->kboard
->reference_count
++;
10190 /* Put this display on the chain. */
10191 dpyinfo
->next
= x_display_list
;
10192 x_display_list
= dpyinfo
;
10194 /* Put it on x_display_name_list as well, to keep them parallel. */
10195 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10196 x_display_name_list
);
10197 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10199 dpyinfo
->display
= dpy
;
10201 /* Set the name of the terminal. */
10202 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
10203 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
10204 terminal
->name
[SBYTES (display_name
)] = 0;
10207 XSetAfterFunction (x_current_display
, x_trace_wire
);
10211 = (char *) xmalloc (SBYTES (Vinvocation_name
)
10212 + SBYTES (Vsystem_name
)
10214 sprintf (dpyinfo
->x_id_name
, "%s@%s",
10215 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10217 /* Figure out which modifier bits mean what. */
10218 x_find_modifier_meanings (dpyinfo
);
10220 /* Get the scroll bar cursor. */
10222 /* We must create a GTK cursor, it is required for GTK widgets. */
10223 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10224 #endif /* USE_GTK */
10226 dpyinfo
->vertical_scroll_bar_cursor
10227 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10229 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10230 resource_name
, EMACS_CLASS
);
10231 #ifdef HAVE_XRMSETDATABASE
10232 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10234 dpyinfo
->display
->db
= xrdb
;
10236 /* Put the rdb where we can find it in a way that works on
10238 dpyinfo
->xrdb
= xrdb
;
10240 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10241 DefaultScreen (dpyinfo
->display
));
10242 select_visual (dpyinfo
);
10243 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10244 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10245 dpyinfo
->client_leader_window
= 0;
10246 dpyinfo
->grabbed
= 0;
10247 dpyinfo
->reference_count
= 0;
10248 dpyinfo
->icon_bitmap_id
= -1;
10249 dpyinfo
->n_fonts
= 0;
10250 dpyinfo
->bitmaps
= 0;
10251 dpyinfo
->bitmaps_size
= 0;
10252 dpyinfo
->bitmaps_last
= 0;
10253 dpyinfo
->scratch_cursor_gc
= 0;
10254 dpyinfo
->mouse_face_mouse_frame
= 0;
10255 dpyinfo
->mouse_face_deferred_gc
= 0;
10256 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10257 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10258 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10259 dpyinfo
->mouse_face_window
= Qnil
;
10260 dpyinfo
->mouse_face_overlay
= Qnil
;
10261 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10262 dpyinfo
->mouse_face_defer
= 0;
10263 dpyinfo
->mouse_face_hidden
= 0;
10264 dpyinfo
->x_focus_frame
= 0;
10265 dpyinfo
->x_focus_event_frame
= 0;
10266 dpyinfo
->x_highlight_frame
= 0;
10267 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10269 /* See if we can construct pixel values from RGB values. */
10270 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10271 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10273 if (dpyinfo
->visual
->class == TrueColor
)
10275 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10276 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10277 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10278 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10279 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10280 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10283 /* See if a private colormap is requested. */
10284 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10286 if (dpyinfo
->visual
->class == PseudoColor
)
10289 value
= display_x_get_resource (dpyinfo
,
10290 build_string ("privateColormap"),
10291 build_string ("PrivateColormap"),
10293 if (STRINGP (value
)
10294 && (!strcmp (SDATA (value
), "true")
10295 || !strcmp (SDATA (value
), "on")))
10296 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10300 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10301 dpyinfo
->visual
, AllocNone
);
10304 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10305 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10306 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10307 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10308 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10309 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10310 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10311 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10312 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10315 dpyinfo
->Xatom_wm_protocols
10316 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10317 dpyinfo
->Xatom_wm_take_focus
10318 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10319 dpyinfo
->Xatom_wm_save_yourself
10320 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10321 dpyinfo
->Xatom_wm_delete_window
10322 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10323 dpyinfo
->Xatom_wm_change_state
10324 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10325 dpyinfo
->Xatom_wm_configure_denied
10326 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10327 dpyinfo
->Xatom_wm_window_moved
10328 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10329 dpyinfo
->Xatom_wm_client_leader
10330 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10331 dpyinfo
->Xatom_editres
10332 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10333 dpyinfo
->Xatom_CLIPBOARD
10334 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10335 dpyinfo
->Xatom_TIMESTAMP
10336 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10337 dpyinfo
->Xatom_TEXT
10338 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10339 dpyinfo
->Xatom_COMPOUND_TEXT
10340 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10341 dpyinfo
->Xatom_UTF8_STRING
10342 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10343 dpyinfo
->Xatom_DELETE
10344 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10345 dpyinfo
->Xatom_MULTIPLE
10346 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10347 dpyinfo
->Xatom_INCR
10348 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10349 dpyinfo
->Xatom_EMACS_TMP
10350 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10351 dpyinfo
->Xatom_TARGETS
10352 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10353 dpyinfo
->Xatom_NULL
10354 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10355 dpyinfo
->Xatom_ATOM_PAIR
10356 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10357 /* For properties of font. */
10358 dpyinfo
->Xatom_PIXEL_SIZE
10359 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10360 dpyinfo
->Xatom_AVERAGE_WIDTH
10361 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10362 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10363 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10364 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10365 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10366 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10367 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10369 /* Ghostscript support. */
10370 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10371 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10373 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10376 dpyinfo
->Xatom_XEMBED
= XInternAtom (dpyinfo
->display
, "_XEMBED",
10379 dpyinfo
->Xatom_net_wm_state
10380 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE", False
);
10381 dpyinfo
->Xatom_net_wm_state_fullscreen_atom
10382 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_FULLSCREEN", False
);
10383 dpyinfo
->Xatom_net_wm_state_maximized_horz
10384 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_HORZ", False
);
10385 dpyinfo
->Xatom_net_wm_state_maximized_vert
10386 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_VERT", False
);
10387 dpyinfo
->Xatom_net_wm_state_sticky
10388 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_STICKY", False
);
10390 dpyinfo
->cut_buffers_initialized
= 0;
10392 dpyinfo
->x_dnd_atoms_size
= 8;
10393 dpyinfo
->x_dnd_atoms_length
= 0;
10394 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
10395 * dpyinfo
->x_dnd_atoms_size
);
10397 dpyinfo
->net_supported_atoms
= NULL
;
10398 dpyinfo
->nr_net_supported_atoms
= 0;
10399 dpyinfo
->net_supported_window
= 0;
10401 connection
= ConnectionNumber (dpyinfo
->display
);
10402 dpyinfo
->connection
= connection
;
10405 extern int gray_bitmap_width
, gray_bitmap_height
;
10406 extern char *gray_bitmap_bits
;
10408 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10410 gray_bitmap_width
, gray_bitmap_height
,
10411 (unsigned long) 1, (unsigned long) 0, 1);
10415 xim_initialize (dpyinfo
, resource_name
);
10418 #ifdef subprocesses
10419 /* This is only needed for distinguishing keyboard and process input. */
10420 if (connection
!= 0)
10421 add_keyboard_wait_descriptor (connection
);
10425 fcntl (connection
, F_SETOWN
, getpid ());
10426 #endif /* ! defined (F_SETOWN) */
10429 if (interrupt_input
)
10430 init_sigio (connection
);
10431 #endif /* ! defined (SIGIO) */
10435 Display
*dpy
= dpyinfo
->display
;
10436 XrmValue d
, fr
, to
;
10439 d
.addr
= (XPointer
)&dpy
;
10440 d
.size
= sizeof (Display
*);
10441 fr
.addr
= XtDefaultFont
;
10442 fr
.size
= sizeof (XtDefaultFont
);
10443 to
.size
= sizeof (Font
*);
10444 to
.addr
= (XPointer
)&font
;
10445 x_catch_errors (dpy
);
10446 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10448 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10449 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10450 x_uncatch_errors ();
10454 /* See if we should run in synchronous mode. This is useful
10455 for debugging X code. */
10458 value
= display_x_get_resource (dpyinfo
,
10459 build_string ("synchronous"),
10460 build_string ("Synchronous"),
10462 if (STRINGP (value
)
10463 && (!strcmp (SDATA (value
), "true")
10464 || !strcmp (SDATA (value
), "on")))
10465 XSynchronize (dpyinfo
->display
, True
);
10470 value
= display_x_get_resource (dpyinfo
,
10471 build_string ("useXIM"),
10472 build_string ("UseXIM"),
10475 if (STRINGP (value
)
10476 && (!strcmp (SDATA (value
), "false")
10477 || !strcmp (SDATA (value
), "off")))
10480 if (STRINGP (value
)
10481 && (!strcmp (SDATA (value
), "true")
10482 || !strcmp (SDATA (value
), "on")))
10488 /* Only do this for the very first display in the Emacs session.
10489 Ignore X session management when Emacs was first started on a
10491 if (terminal
->id
== 1)
10492 x_session_initialize (dpyinfo
);
10500 /* Get rid of display DPYINFO, deleting all frames on it,
10501 and without sending any more commands to the X server. */
10504 x_delete_display (dpyinfo
)
10505 struct x_display_info
*dpyinfo
;
10508 struct terminal
*t
;
10510 /* Close all frames and delete the generic struct terminal for this
10512 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10513 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10516 /* Close X session management when we close its display. */
10517 if (t
->id
== 1 && x_session_have_connection ())
10520 delete_terminal (t
);
10524 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10526 /* Discard this display from x_display_name_list and x_display_list.
10527 We can't use Fdelq because that can quit. */
10528 if (! NILP (x_display_name_list
)
10529 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10530 x_display_name_list
= XCDR (x_display_name_list
);
10535 tail
= x_display_name_list
;
10536 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10538 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10540 XSETCDR (tail
, XCDR (XCDR (tail
)));
10543 tail
= XCDR (tail
);
10547 if (next_noop_dpyinfo
== dpyinfo
)
10548 next_noop_dpyinfo
= dpyinfo
->next
;
10550 if (x_display_list
== dpyinfo
)
10551 x_display_list
= dpyinfo
->next
;
10554 struct x_display_info
*tail
;
10556 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10557 if (tail
->next
== dpyinfo
)
10558 tail
->next
= tail
->next
->next
;
10561 xfree (dpyinfo
->x_id_name
);
10562 xfree (dpyinfo
->x_dnd_atoms
);
10563 xfree (dpyinfo
->color_cells
);
10567 #ifdef USE_X_TOOLKIT
10569 /* Atimer callback function for TIMER. Called every 0.1s to process
10570 Xt timeouts, if needed. We must avoid calling XtAppPending as
10571 much as possible because that function does an implicit XFlush
10572 that slows us down. */
10575 x_process_timeouts (timer
)
10576 struct atimer
*timer
;
10579 x_timeout_atimer_activated_flag
= 0;
10580 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10582 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10583 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10584 /* Reactivate the atimer for next time. */
10585 x_activate_timeout_atimer ();
10590 /* Install an asynchronous timer that processes Xt timeout events
10591 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10592 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10593 function whenever these variables are set. This is necessary
10594 because some widget sets use timeouts internally, for example the
10595 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10596 processed, these widgets don't behave normally. */
10599 x_activate_timeout_atimer ()
10602 if (!x_timeout_atimer_activated_flag
)
10604 EMACS_TIME interval
;
10606 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10607 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10608 x_timeout_atimer_activated_flag
= 1;
10613 #endif /* USE_X_TOOLKIT */
10616 /* Set up use of X before we make the first connection. */
10618 extern frame_parm_handler x_frame_parm_handlers
[];
10620 static struct redisplay_interface x_redisplay_interface
=
10622 x_frame_parm_handlers
,
10626 x_clear_end_of_line
,
10628 x_after_update_window_line
,
10629 x_update_window_begin
,
10630 x_update_window_end
,
10636 0, /* flush_display_optional */
10638 x_clear_window_mouse_face
,
10639 x_get_glyph_overhangs
,
10640 x_fix_overlapping_area
,
10641 x_draw_fringe_bitmap
,
10642 0, /* define_fringe_bitmap */
10643 0, /* destroy_fringe_bitmap */
10644 x_compute_glyph_string_overhangs
,
10645 x_draw_glyph_string
,
10646 x_define_frame_cursor
,
10647 x_clear_frame_area
,
10648 x_draw_window_cursor
,
10649 x_draw_vertical_window_border
,
10650 x_shift_glyphs_for_insert
10654 /* This function is called when the last frame on a display is deleted. */
10656 x_delete_terminal (struct terminal
*terminal
)
10658 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10661 /* Protect against recursive calls. delete_frame in
10662 delete_terminal calls us back when it deletes our last frame. */
10663 if (!terminal
->name
)
10668 /* We must close our connection to the XIM server before closing the
10671 xim_close_dpy (dpyinfo
);
10674 /* If called from x_connection_closed, the display may already be closed
10675 and dpyinfo->display was set to 0 to indicate that. */
10676 if (dpyinfo
->display
)
10678 x_destroy_all_bitmaps (dpyinfo
);
10679 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10681 /* Whether or not XCloseDisplay destroys the associated resource
10682 database depends on the version of libX11. To avoid both
10683 crash and memory leak, we dissociate the database from the
10684 display and then destroy dpyinfo->xrdb ourselves.
10686 Unfortunately, the above strategy does not work in some
10687 situations due to a bug in newer versions of libX11: because
10688 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10689 dpy->db is NULL, XCloseDisplay destroys the associated
10690 database whereas it has not been created by XGetDefault
10691 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10692 don't destroy the database here in order to avoid the crash
10693 in the above situations for now, though that may cause memory
10694 leaks in other situations. */
10696 #ifdef HAVE_XRMSETDATABASE
10697 XrmSetDatabase (dpyinfo
->display
, NULL
);
10699 dpyinfo
->display
->db
= NULL
;
10701 /* We used to call XrmDestroyDatabase from x_delete_display, but
10702 some older versions of libX11 crash if we call it after
10703 closing all the displays. */
10704 XrmDestroyDatabase (dpyinfo
->xrdb
);
10708 xg_display_close (dpyinfo
->display
);
10710 #ifdef USE_X_TOOLKIT
10711 XtCloseDisplay (dpyinfo
->display
);
10713 XCloseDisplay (dpyinfo
->display
);
10715 #endif /* ! USE_GTK */
10718 x_delete_display (dpyinfo
);
10722 /* Create a struct terminal, initialize it with the X11 specific
10723 functions and make DISPLAY->TERMINAL point to it. */
10725 static struct terminal
*
10726 x_create_terminal (struct x_display_info
*dpyinfo
)
10728 struct terminal
*terminal
;
10730 terminal
= create_terminal ();
10732 terminal
->type
= output_x_window
;
10733 terminal
->display_info
.x
= dpyinfo
;
10734 dpyinfo
->terminal
= terminal
;
10736 /* kboard is initialized in x_term_init. */
10738 terminal
->clear_frame_hook
= x_clear_frame
;
10739 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10740 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10741 terminal
->ring_bell_hook
= XTring_bell
;
10742 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10743 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10744 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
10745 terminal
->update_begin_hook
= x_update_begin
;
10746 terminal
->update_end_hook
= x_update_end
;
10747 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
10748 terminal
->read_socket_hook
= XTread_socket
;
10749 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10750 terminal
->mouse_position_hook
= XTmouse_position
;
10751 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10752 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10753 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10754 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10755 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10756 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10757 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10759 terminal
->delete_frame_hook
= x_destroy_window
;
10760 terminal
->delete_terminal_hook
= x_delete_terminal
;
10762 terminal
->rif
= &x_redisplay_interface
;
10763 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10764 terminal
->char_ins_del_ok
= 1;
10765 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10766 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10767 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10779 last_tool_bar_item
= -1;
10780 any_help_event_p
= 0;
10781 ignore_next_mouse_click_timeout
= 0;
10783 x_session_initialized
= 0;
10787 current_count
= -1;
10790 /* Try to use interrupt input; if we can't, then start polling. */
10791 Fset_input_interrupt_mode (Qt
);
10793 #ifdef USE_X_TOOLKIT
10794 XtToolkitInitialize ();
10796 Xt_app_con
= XtCreateApplicationContext ();
10798 /* Register a converter from strings to pixels, which uses
10799 Emacs' color allocation infrastructure. */
10800 XtAppSetTypeConverter (Xt_app_con
,
10801 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10802 cvt_string_to_pixel_args
,
10803 XtNumber (cvt_string_to_pixel_args
),
10804 XtCacheByDisplay
, cvt_pixel_dtor
);
10806 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10809 #ifdef USE_TOOLKIT_SCROLL_BARS
10811 xaw3d_arrow_scroll
= False
;
10812 xaw3d_pick_top
= True
;
10816 pending_autoraise_frame
= 0;
10817 pending_event_wait
.f
= 0;
10818 pending_event_wait
.eventtype
= 0;
10820 /* Note that there is no real way portable across R3/R4 to get the
10821 original error handler. */
10822 XSetErrorHandler (x_error_handler
);
10823 XSetIOErrorHandler (x_io_error_quitter
);
10825 signal (SIGPIPE
, x_connection_signal
);
10832 x_error_message
= NULL
;
10834 staticpro (&x_display_name_list
);
10835 x_display_name_list
= Qnil
;
10837 staticpro (&last_mouse_scroll_bar
);
10838 last_mouse_scroll_bar
= Qnil
;
10840 staticpro (&Qvendor_specific_keysyms
);
10841 Qvendor_specific_keysyms
= intern_c_string ("vendor-specific-keysyms");
10843 staticpro (&Qlatin_1
);
10844 Qlatin_1
= intern_c_string ("latin-1");
10846 staticpro (&last_mouse_press_frame
);
10847 last_mouse_press_frame
= Qnil
;
10850 xg_default_icon_file
= build_string ("icons/hicolor/scalable/apps/emacs.svg");
10851 staticpro (&xg_default_icon_file
);
10853 Qx_gtk_map_stock
= intern_c_string ("x-gtk-map-stock");
10854 staticpro (&Qx_gtk_map_stock
);
10857 DEFVAR_BOOL ("x-use-underline-position-properties",
10858 &x_use_underline_position_properties
,
10859 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10860 A value of nil means ignore them. If you encounter fonts with bogus
10861 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10862 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10863 to override the font's UNDERLINE_POSITION for small font display
10865 x_use_underline_position_properties
= 1;
10867 DEFVAR_BOOL ("x-underline-at-descent-line",
10868 &x_underline_at_descent_line
,
10869 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
10870 A value of nil means to draw the underline according to the value of the
10871 variable `x-use-underline-position-properties', which is usually at the
10872 baseline level. The default value is nil. */);
10873 x_underline_at_descent_line
= 0;
10875 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10876 &x_mouse_click_focus_ignore_position
,
10877 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10878 This variable is only used when the window manager requires that you
10879 click on a frame to select it (give it focus). In that case, a value
10880 of nil, means that the selected window and cursor position changes to
10881 reflect the mouse click position, while a non-nil value means that the
10882 selected window or cursor position is preserved. */);
10883 x_mouse_click_focus_ignore_position
= 0;
10885 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10886 doc
: /* What X toolkit scroll bars Emacs uses.
10887 A value of nil means Emacs doesn't use X toolkit scroll bars.
10888 Otherwise, value is a symbol describing the X toolkit. */);
10889 #ifdef USE_TOOLKIT_SCROLL_BARS
10891 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10892 #elif defined HAVE_XAW3D
10893 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10895 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10897 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10900 Vx_toolkit_scroll_bars
= Qnil
;
10903 staticpro (&last_mouse_motion_frame
);
10904 last_mouse_motion_frame
= Qnil
;
10906 Qmodifier_value
= intern_c_string ("modifier-value");
10907 Qalt
= intern_c_string ("alt");
10908 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10909 Qhyper
= intern_c_string ("hyper");
10910 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10911 Qmeta
= intern_c_string ("meta");
10912 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10913 Qsuper
= intern_c_string ("super");
10914 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10916 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10917 doc
: /* Which keys Emacs uses for the alt modifier.
10918 This should be one of the symbols `alt', `hyper', `meta', `super'.
10919 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10920 is nil, which is the same as `alt'. */);
10921 Vx_alt_keysym
= Qnil
;
10923 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10924 doc
: /* Which keys Emacs uses for the hyper modifier.
10925 This should be one of the symbols `alt', `hyper', `meta', `super'.
10926 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10927 default is nil, which is the same as `hyper'. */);
10928 Vx_hyper_keysym
= Qnil
;
10930 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10931 doc
: /* Which keys Emacs uses for the meta modifier.
10932 This should be one of the symbols `alt', `hyper', `meta', `super'.
10933 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10934 default is nil, which is the same as `meta'. */);
10935 Vx_meta_keysym
= Qnil
;
10937 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10938 doc
: /* Which keys Emacs uses for the super modifier.
10939 This should be one of the symbols `alt', `hyper', `meta', `super'.
10940 For example, `super' means use the Super_L and Super_R keysyms. The
10941 default is nil, which is the same as `super'. */);
10942 Vx_super_keysym
= Qnil
;
10944 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10945 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10946 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10947 make_float (DEFAULT_REHASH_SIZE
),
10948 make_float (DEFAULT_REHASH_THRESHOLD
),
10952 #endif /* HAVE_X_WINDOWS */
10954 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
10955 (do not change this comment) */