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. */
35 #include "blockinput.h"
37 /* Need syssignal.h for various externs and definitions that may be required
38 by some configurations for calls to signal later in this source file. */
39 #include "syssignal.h"
41 /* This may include sys/types.h, and that somehow loses
42 if this is not done before the other system files. */
44 #include <X11/cursorfont.h>
46 /* Load sys/types.h if not already loaded.
47 In some systems loading it twice is suicidal. */
49 #include <sys/types.h>
53 #include <sys/ioctl.h>
54 #endif /* ! defined (BSD_SYSTEM) */
58 #ifndef INCLUDED_FCNTL
65 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
66 /* #include <sys/param.h> */
69 #include "character.h"
72 #include "dispextern.h"
74 #include "termhooks.h"
77 #include "emacs-icon.h"
82 #include "intervals.h"
90 #include <X11/Shell.h>
93 #ifdef HAVE_SYS_TIME_H
105 extern int xlwmenu_window_p
P_ ((Widget w
, Window window
));
106 extern void xlwmenu_redisplay
P_ ((Widget
));
109 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
111 extern void free_frame_menubar
P_ ((struct frame
*));
115 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
117 extern void _XEditResCheckMessages ();
118 #endif /* not NO_EDITRES */
120 /* Include toolkit specific headers for the scroll bar widget. */
122 #ifdef USE_TOOLKIT_SCROLL_BARS
123 #if defined USE_MOTIF
124 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
125 #include <Xm/ScrollBar.h>
126 #else /* !USE_MOTIF i.e. use Xaw */
129 #include <X11/Xaw3d/Simple.h>
130 #include <X11/Xaw3d/Scrollbar.h>
131 #include <X11/Xaw3d/ThreeD.h>
132 #else /* !HAVE_XAW3D */
133 #include <X11/Xaw/Simple.h>
134 #include <X11/Xaw/Scrollbar.h>
135 #endif /* !HAVE_XAW3D */
137 #define XtNpickTop "pickTop"
138 #endif /* !XtNpickTop */
139 #endif /* !USE_MOTIF */
140 #endif /* USE_TOOLKIT_SCROLL_BARS */
142 #endif /* USE_X_TOOLKIT */
146 #ifndef XtNinitialState
147 #define XtNinitialState "initialState"
151 /* Default to using XIM if available. */
155 int use_xim
= 0; /* configure --without-xim */
160 /* Non-nil means Emacs uses toolkit scroll bars. */
162 Lisp_Object Vx_toolkit_scroll_bars
;
164 /* Non-zero means that a HELP_EVENT has been generated since Emacs
167 static int any_help_event_p
;
169 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
170 static Lisp_Object last_window
;
172 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
174 int x_use_underline_position_properties
;
176 /* Non-zero means to draw the underline at the same place as the descent line. */
178 int x_underline_at_descent_line
;
180 /* This is a chain of structures for all the X displays currently in
183 struct x_display_info
*x_display_list
;
185 /* This is a list of cons cells, each of the form (NAME
186 . FONT-LIST-CACHE), one for each element of x_display_list and in
187 the same order. NAME is the name of the frame. FONT-LIST-CACHE
188 records previous values returned by x-list-fonts. */
190 Lisp_Object x_display_name_list
;
192 /* Frame being updated by update_frame. This is declared in term.c.
193 This is set by update_begin and looked at by all the XT functions.
194 It is zero while not inside an update. In that case, the XT
195 functions assume that `selected_frame' is the frame to apply to. */
197 extern struct frame
*updating_frame
;
199 /* This is a frame waiting to be auto-raised, within XTread_socket. */
201 struct frame
*pending_autoraise_frame
;
204 /* The application context for Xt use. */
205 XtAppContext Xt_app_con
;
206 static String Xt_default_resources
[] = {0};
207 #endif /* USE_X_TOOLKIT */
209 /* Non-zero means user is interacting with a toolkit scroll bar. */
211 static int toolkit_scroll_bar_interaction
;
213 /* Non-zero means to not move point as a result of clicking on a
214 frame to focus it (when focus-follows-mouse is nil). */
216 int x_mouse_click_focus_ignore_position
;
218 /* Non-zero timeout value means ignore next mouse click if it arrives
219 before that timeout elapses (i.e. as part of the same sequence of
220 events resulting from clicking on a frame to select it). */
222 static unsigned long ignore_next_mouse_click_timeout
;
226 Formerly, we used PointerMotionHintMask (in standard_event_mask)
227 so that we would have to call XQueryPointer after each MotionNotify
228 event to ask for another such event. However, this made mouse tracking
229 slow, and there was a bug that made it eventually stop.
231 Simply asking for MotionNotify all the time seems to work better.
233 In order to avoid asking for motion events and then throwing most
234 of them away or busy-polling the server for mouse positions, we ask
235 the server for pointer motion hints. This means that we get only
236 one event per group of mouse movements. "Groups" are delimited by
237 other kinds of events (focus changes and button clicks, for
238 example), or by XQueryPointer calls; when one of these happens, we
239 get another MotionNotify event the next time the mouse moves. This
240 is at least as efficient as getting motion events when mouse
241 tracking is on, and I suspect only negligibly worse when tracking
244 /* Where the mouse was last time we reported a mouse event. */
246 static XRectangle last_mouse_glyph
;
247 static FRAME_PTR last_mouse_glyph_frame
;
248 static Lisp_Object last_mouse_press_frame
;
250 /* The scroll bar in which the last X motion event occurred.
252 If the last X motion event occurred in a scroll bar, we set this so
253 XTmouse_position can know whether to report a scroll bar motion or
256 If the last X motion event didn't occur in a scroll bar, we set
257 this to Qnil, to tell XTmouse_position to return an ordinary motion
260 static Lisp_Object last_mouse_scroll_bar
;
262 /* This is a hack. We would really prefer that XTmouse_position would
263 return the time associated with the position it returns, but there
264 doesn't seem to be any way to wrest the time-stamp from the server
265 along with the position query. So, we just keep track of the time
266 of the last movement we received, and return that in hopes that
267 it's somewhat accurate. */
269 static Time last_mouse_movement_time
;
271 /* Time for last user interaction as returned in X events. */
273 static Time last_user_time
;
275 /* Incremented by XTread_socket whenever it really tries to read
279 static int volatile input_signal_count
;
281 static int input_signal_count
;
284 /* Used locally within XTread_socket. */
286 static int x_noop_count
;
288 /* Initial values of argv and argc. */
290 extern char **initial_argv
;
291 extern int initial_argc
;
293 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
295 /* Tells if a window manager is present or not. */
297 extern Lisp_Object Vx_no_window_manager
;
299 extern Lisp_Object Qeql
;
303 /* A mask of extra modifier bits to put into every keyboard char. */
305 extern EMACS_INT extra_keyboard_modifiers
;
307 /* The keysyms to use for the various modifiers. */
309 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
310 Lisp_Object Vx_keysym_table
;
311 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
313 static Lisp_Object Qvendor_specific_keysyms
;
314 static Lisp_Object Qlatin_1
;
317 /* The name of the Emacs icon file. */
318 static Lisp_Object xg_default_icon_file
;
320 /* Used in gtkutil.c. */
321 Lisp_Object Qx_gtk_map_stock
;
324 /* Used in x_flush. */
326 extern Lisp_Object Vinhibit_redisplay
;
328 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
329 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
331 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
332 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
333 static const XColor
*x_color_cells
P_ ((Display
*, int *));
334 static void x_update_window_end
P_ ((struct window
*, int, int));
336 static int x_io_error_quitter
P_ ((Display
*));
337 static struct terminal
*x_create_terminal
P_ ((struct x_display_info
*));
338 void x_delete_terminal
P_ ((struct terminal
*));
339 static void x_update_end
P_ ((struct frame
*));
340 static void XTframe_up_to_date
P_ ((struct frame
*));
341 static void XTset_terminal_modes
P_ ((struct terminal
*));
342 static void XTreset_terminal_modes
P_ ((struct terminal
*));
343 static void x_clear_frame
P_ ((struct frame
*));
344 static void frame_highlight
P_ ((struct frame
*));
345 static void frame_unhighlight
P_ ((struct frame
*));
346 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
347 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
348 struct frame
*, struct input_event
*));
349 static void x_detect_focus_change
P_ ((struct x_display_info
*,
350 XEvent
*, struct input_event
*));
351 static void XTframe_rehighlight
P_ ((struct frame
*));
352 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
353 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
354 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
355 enum text_cursor_kinds
));
357 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
358 static void x_flush
P_ ((struct frame
*f
));
359 static void x_update_begin
P_ ((struct frame
*));
360 static void x_update_window_begin
P_ ((struct window
*));
361 static void x_after_update_window_line
P_ ((struct glyph_row
*));
362 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
363 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
364 enum scroll_bar_part
*,
365 Lisp_Object
*, Lisp_Object
*,
367 static void x_handle_net_wm_state
P_ ((struct frame
*, XPropertyEvent
*));
368 static void x_check_fullscreen
P_ ((struct frame
*));
369 static void x_check_expected_move
P_ ((struct frame
*, int, int));
370 static void x_sync_with_move
P_ ((struct frame
*, int, int, int));
371 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
372 int *, struct input_event
*));
373 /* Don't declare this NO_RETURN because we want no
374 interference with debugging failing X calls. */
375 static SIGTYPE x_connection_closed
P_ ((Display
*, char *));
378 /* Flush display of frame F, or of all frames if F is null. */
384 /* Don't call XFlush when it is not safe to redisplay; the X
385 connection may be broken. */
386 if (!NILP (Vinhibit_redisplay
))
392 Lisp_Object rest
, frame
;
393 FOR_EACH_FRAME (rest
, frame
)
394 if (FRAME_X_P (XFRAME (frame
)))
395 x_flush (XFRAME (frame
));
397 else if (FRAME_X_P (f
))
398 XFlush (FRAME_X_DISPLAY (f
));
403 /* Remove calls to XFlush by defining XFlush to an empty replacement.
404 Calls to XFlush should be unnecessary because the X output buffer
405 is flushed automatically as needed by calls to XPending,
406 XNextEvent, or XWindowEvent according to the XFlush man page.
407 XTread_socket calls XPending. Removing XFlush improves
410 #define XFlush(DISPLAY) (void) 0
413 /***********************************************************************
415 ***********************************************************************/
419 /* This is a function useful for recording debugging information about
420 the sequence of occurrences in this file. */
428 struct record event_record
[100];
430 int event_record_index
;
432 record_event (locus
, type
)
436 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
437 event_record_index
= 0;
439 event_record
[event_record_index
].locus
= locus
;
440 event_record
[event_record_index
].type
= type
;
441 event_record_index
++;
448 /* Return the struct x_display_info corresponding to DPY. */
450 struct x_display_info
*
451 x_display_info_for_display (dpy
)
454 struct x_display_info
*dpyinfo
;
456 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
457 if (dpyinfo
->display
== dpy
)
463 #define OPAQUE 0xffffffff
464 #define OPACITY "_NET_WM_WINDOW_OPACITY"
467 x_set_frame_alpha (f
)
470 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
471 Display
*dpy
= FRAME_X_DISPLAY (f
);
472 Window win
= FRAME_OUTER_WINDOW (f
);
474 double alpha_min
= 1.0;
477 if (FRAME_X_DISPLAY_INFO (f
)->root_window
!= FRAME_X_OUTPUT (f
)->parent_desc
)
478 /* Since the WM decoration lies under the FRAME_OUTER_WINDOW,
479 we must treat the former instead of the latter. */
480 win
= FRAME_X_OUTPUT(f
)->parent_desc
;
482 if (dpyinfo
->x_highlight_frame
== f
)
487 if (FLOATP (Vframe_alpha_lower_limit
))
488 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
489 else if (INTEGERP (Vframe_alpha_lower_limit
))
490 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
494 else if (alpha
> 1.0)
496 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
499 opac
= alpha
* OPAQUE
;
501 /* return unless necessary */
506 unsigned long n
, left
;
508 x_catch_errors (dpy
);
509 rc
= XGetWindowProperty(dpy
, win
, XInternAtom(dpy
, OPACITY
, False
),
510 0L, 1L, False
, XA_CARDINAL
,
511 &actual
, &format
, &n
, &left
,
514 if (rc
== Success
&& actual
!= None
)
515 if (*(unsigned long *)data
== opac
)
517 XFree ((void *) data
);
522 XFree ((void *) data
);
526 x_catch_errors (dpy
);
527 XChangeProperty (dpy
, win
, XInternAtom (dpy
, OPACITY
, False
),
528 XA_CARDINAL
, 32, PropModeReplace
,
529 (unsigned char *) &opac
, 1L);
534 x_display_pixel_height (dpyinfo
)
535 struct x_display_info
*dpyinfo
;
537 return HeightOfScreen (dpyinfo
->screen
);
541 x_display_pixel_width (dpyinfo
)
542 struct x_display_info
*dpyinfo
;
544 return WidthOfScreen (dpyinfo
->screen
);
548 /***********************************************************************
549 Starting and ending an update
550 ***********************************************************************/
552 /* Start an update of frame F. This function is installed as a hook
553 for update_begin, i.e. it is called when update_begin is called.
554 This function is called prior to calls to x_update_window_begin for
555 each window being updated. Currently, there is nothing to do here
556 because all interesting stuff is done on a window basis. */
566 /* Start update of window W. Set the global variable updated_window
567 to the window being updated and set output_cursor to the cursor
571 x_update_window_begin (w
)
574 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
575 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
578 set_output_cursor (&w
->cursor
);
582 if (f
== display_info
->mouse_face_mouse_frame
)
584 /* Don't do highlighting for mouse motion during the update. */
585 display_info
->mouse_face_defer
= 1;
587 /* If F needs to be redrawn, simply forget about any prior mouse
589 if (FRAME_GARBAGED_P (f
))
590 display_info
->mouse_face_window
= Qnil
;
597 /* Draw a vertical window border from (x,y0) to (x,y1) */
600 x_draw_vertical_window_border (w
, x
, y0
, y1
)
604 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
607 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
609 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
612 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
613 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
616 /* End update of window W (which is equal to updated_window).
618 Draw vertical borders between horizontally adjacent windows, and
619 display W's cursor if CURSOR_ON_P is non-zero.
621 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
622 glyphs in mouse-face were overwritten. In that case we have to
623 make sure that the mouse-highlight is properly redrawn.
625 W may be a menu bar pseudo-window in case we don't have X toolkit
626 support. Such windows don't have a cursor, so don't display it
630 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
632 int cursor_on_p
, mouse_face_overwritten_p
;
634 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
636 if (!w
->pseudo_window_p
)
641 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
643 output_cursor
.x
, output_cursor
.y
);
645 if (draw_window_fringes (w
, 1))
646 x_draw_vertical_border (w
);
651 /* If a row with mouse-face was overwritten, arrange for
652 XTframe_up_to_date to redisplay the mouse highlight. */
653 if (mouse_face_overwritten_p
)
655 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
656 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
657 dpyinfo
->mouse_face_window
= Qnil
;
660 updated_window
= NULL
;
664 /* End update of frame F. This function is installed as a hook in
671 /* Mouse highlight may be displayed again. */
672 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
676 XFlush (FRAME_X_DISPLAY (f
));
682 /* This function is called from various places in xdisp.c whenever a
683 complete update has been performed. The global variable
684 updated_window is not available here. */
687 XTframe_up_to_date (f
)
692 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
694 if (dpyinfo
->mouse_face_deferred_gc
695 || f
== dpyinfo
->mouse_face_mouse_frame
)
698 if (dpyinfo
->mouse_face_mouse_frame
)
699 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
700 dpyinfo
->mouse_face_mouse_x
,
701 dpyinfo
->mouse_face_mouse_y
);
702 dpyinfo
->mouse_face_deferred_gc
= 0;
709 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
710 arrow bitmaps, or clear the fringes if no bitmaps are required
711 before DESIRED_ROW is made current. The window being updated is
712 found in updated_window. This function It is called from
713 update_window_line only if it is known that there are differences
714 between bitmaps to be drawn between current row and DESIRED_ROW. */
717 x_after_update_window_line (desired_row
)
718 struct glyph_row
*desired_row
;
720 struct window
*w
= updated_window
;
726 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
727 desired_row
->redraw_fringe_bitmaps_p
= 1;
729 /* When a window has disappeared, make sure that no rest of
730 full-width rows stays visible in the internal border. Could
731 check here if updated_window is the leftmost/rightmost window,
732 but I guess it's not worth doing since vertically split windows
733 are almost never used, internal border is rarely set, and the
734 overhead is very small. */
735 if (windows_or_buffers_changed
736 && desired_row
->full_width_p
737 && (f
= XFRAME (w
->frame
),
738 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
740 && (height
= desired_row
->visible_height
,
743 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
745 /* Internal border is drawn below the tool bar. */
746 if (WINDOWP (f
->tool_bar_window
)
747 && w
== XWINDOW (f
->tool_bar_window
))
751 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
752 0, y
, width
, height
, False
);
753 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
754 FRAME_PIXEL_WIDTH (f
) - width
,
755 y
, width
, height
, False
);
761 x_draw_fringe_bitmap (w
, row
, p
)
763 struct glyph_row
*row
;
764 struct draw_fringe_bitmap_params
*p
;
766 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
767 Display
*display
= FRAME_X_DISPLAY (f
);
768 Window window
= FRAME_X_WINDOW (f
);
769 GC gc
= f
->output_data
.x
->normal_gc
;
770 struct face
*face
= p
->face
;
773 /* Must clip because of partially visible lines. */
774 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
777 /* Adjust position of "bottom aligned" bitmap on partially
780 int oldVH
= row
->visible_height
;
781 row
->visible_height
= p
->h
;
782 row
->y
-= rowY
- p
->y
;
783 x_clip_to_row (w
, row
, -1, gc
);
785 row
->visible_height
= oldVH
;
788 x_clip_to_row (w
, row
, -1, gc
);
792 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
794 /* In case the same realized face is used for fringes and
795 for something displayed in the text (e.g. face `region' on
796 mono-displays, the fill style may have been changed to
797 FillSolid in x_draw_glyph_string_background. */
799 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
801 XSetForeground (display
, face
->gc
, face
->background
);
803 #ifdef USE_TOOLKIT_SCROLL_BARS
804 /* If the fringe is adjacent to the left (right) scroll bar of a
805 leftmost (rightmost, respectively) window, then extend its
806 background to the gap between the fringe and the bar. */
807 if ((WINDOW_LEFTMOST_P (w
)
808 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
809 || (WINDOW_RIGHTMOST_P (w
)
810 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
812 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
816 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
817 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
818 * FRAME_COLUMN_WIDTH (f
));
822 /* Bitmap fills the fringe. */
823 if (left
+ width
== p
->x
)
824 bx
= left
+ sb_width
;
825 else if (p
->x
+ p
->wd
== left
)
829 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
831 nx
= width
- sb_width
;
832 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
834 ny
= row
->visible_height
;
839 if (left
+ width
== bx
)
841 bx
= left
+ sb_width
;
842 nx
+= width
- sb_width
;
844 else if (bx
+ nx
== left
)
845 nx
+= width
- sb_width
;
850 if (bx
>= 0 && nx
> 0)
851 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
854 XSetForeground (display
, face
->gc
, face
->foreground
);
860 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
861 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
865 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
867 bits
= (unsigned char *)p
->bits
+ p
->dh
;
869 /* Draw the bitmap. I believe these small pixmaps can be cached
871 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
873 ? (p
->overlay_p
? face
->background
874 : f
->output_data
.x
->cursor_pixel
)
876 face
->background
, depth
);
880 clipmask
= XCreatePixmapFromBitmapData (display
,
881 FRAME_X_DISPLAY_INFO (f
)->root_window
,
884 gcv
.clip_mask
= clipmask
;
885 gcv
.clip_x_origin
= p
->x
;
886 gcv
.clip_y_origin
= p
->y
;
887 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
890 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
891 p
->wd
, p
->h
, p
->x
, p
->y
);
892 XFreePixmap (display
, pixmap
);
896 gcv
.clip_mask
= (Pixmap
) 0;
897 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
898 XFreePixmap (display
, clipmask
);
902 XSetClipMask (display
, gc
, None
);
907 /* This is called when starting Emacs and when restarting after
908 suspend. When starting Emacs, no X window is mapped. And nothing
909 must be done to Emacs's own window if it is suspended (though that
913 XTset_terminal_modes (struct terminal
*terminal
)
917 /* This is called when exiting or suspending Emacs. Exiting will make
918 the X-windows go away, and suspending requires no action. */
921 XTreset_terminal_modes (struct terminal
*terminal
)
926 /***********************************************************************
928 ***********************************************************************/
932 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
933 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
934 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
936 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
937 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
938 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
939 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
940 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
941 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
942 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
943 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
944 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
945 unsigned long *, double, int));
946 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
947 double, int, unsigned long));
948 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
949 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
950 static void x_draw_image_relief
P_ ((struct glyph_string
*));
951 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
952 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
953 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
955 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
956 int, int, int, int, int, int,
958 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
959 int, int, int, XRectangle
*));
962 static void x_check_font
P_ ((struct frame
*, struct font
*));
966 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
971 struct glyph_string
*s
;
973 if (s
->font
== FRAME_FONT (s
->f
)
974 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
975 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
977 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
980 /* Cursor on non-default face: must merge. */
984 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
985 xgcv
.foreground
= s
->face
->background
;
987 /* If the glyph would be invisible, try a different foreground. */
988 if (xgcv
.foreground
== xgcv
.background
)
989 xgcv
.foreground
= s
->face
->foreground
;
990 if (xgcv
.foreground
== xgcv
.background
)
991 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
992 if (xgcv
.foreground
== xgcv
.background
)
993 xgcv
.foreground
= s
->face
->foreground
;
995 /* Make sure the cursor is distinct from text in this face. */
996 if (xgcv
.background
== s
->face
->background
997 && xgcv
.foreground
== s
->face
->foreground
)
999 xgcv
.background
= s
->face
->foreground
;
1000 xgcv
.foreground
= s
->face
->background
;
1003 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1004 xgcv
.graphics_exposures
= False
;
1005 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1007 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1008 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1011 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1012 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1014 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1019 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1022 x_set_mouse_face_gc (s
)
1023 struct glyph_string
*s
;
1028 /* What face has to be used last for the mouse face? */
1029 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1030 face
= FACE_FROM_ID (s
->f
, face_id
);
1032 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1034 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1035 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1037 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1038 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1039 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1041 if (s
->font
== s
->face
->font
)
1042 s
->gc
= s
->face
->gc
;
1045 /* Otherwise construct scratch_cursor_gc with values from FACE
1050 xgcv
.background
= s
->face
->background
;
1051 xgcv
.foreground
= s
->face
->foreground
;
1052 xgcv
.graphics_exposures
= False
;
1053 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1055 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1056 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1059 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1060 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1062 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1065 xassert (s
->gc
!= 0);
1069 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1070 Faces to use in the mode line have already been computed when the
1071 matrix was built, so there isn't much to do, here. */
1074 x_set_mode_line_face_gc (s
)
1075 struct glyph_string
*s
;
1077 s
->gc
= s
->face
->gc
;
1081 /* Set S->gc of glyph string S for drawing that glyph string. Set
1082 S->stippled_p to a non-zero value if the face of S has a stipple
1086 x_set_glyph_string_gc (s
)
1087 struct glyph_string
*s
;
1089 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1091 if (s
->hl
== DRAW_NORMAL_TEXT
)
1093 s
->gc
= s
->face
->gc
;
1094 s
->stippled_p
= s
->face
->stipple
!= 0;
1096 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1098 x_set_mode_line_face_gc (s
);
1099 s
->stippled_p
= s
->face
->stipple
!= 0;
1101 else if (s
->hl
== DRAW_CURSOR
)
1103 x_set_cursor_gc (s
);
1106 else if (s
->hl
== DRAW_MOUSE_FACE
)
1108 x_set_mouse_face_gc (s
);
1109 s
->stippled_p
= s
->face
->stipple
!= 0;
1111 else if (s
->hl
== DRAW_IMAGE_RAISED
1112 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1114 s
->gc
= s
->face
->gc
;
1115 s
->stippled_p
= s
->face
->stipple
!= 0;
1119 s
->gc
= s
->face
->gc
;
1120 s
->stippled_p
= s
->face
->stipple
!= 0;
1123 /* GC must have been set. */
1124 xassert (s
->gc
!= 0);
1128 /* Set clipping for output of glyph string S. S may be part of a mode
1129 line or menu if we don't have X toolkit support. */
1132 x_set_glyph_string_clipping (s
)
1133 struct glyph_string
*s
;
1135 XRectangle
*r
= s
->clip
;
1136 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1139 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1144 /* Set SRC's clipping for output of glyph string DST. This is called
1145 when we are drawing DST's left_overhang or right_overhang only in
1149 x_set_glyph_string_clipping_exactly (src
, dst
)
1150 struct glyph_string
*src
, *dst
;
1155 r
.width
= src
->width
;
1157 r
.height
= src
->height
;
1160 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1165 Compute left and right overhang of glyph string S. */
1168 x_compute_glyph_string_overhangs (s
)
1169 struct glyph_string
*s
;
1172 && (s
->first_glyph
->type
== CHAR_GLYPH
1173 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1175 struct font_metrics metrics
;
1177 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1179 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1180 struct font
*font
= s
->font
;
1183 for (i
= 0; i
< s
->nchars
; i
++)
1184 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1185 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1189 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1191 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1193 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1194 ? metrics
.rbearing
- metrics
.width
: 0);
1195 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1199 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1200 s
->left_overhang
= - s
->cmp
->lbearing
;
1205 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1208 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1209 struct glyph_string
*s
;
1213 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1214 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1215 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1216 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1220 /* Draw the background of glyph_string S. If S->background_filled_p
1221 is non-zero don't draw it. FORCE_P non-zero means draw the
1222 background even if it wouldn't be drawn normally. This is used
1223 when a string preceding S draws into the background of S, or S
1224 contains the first component of a composition. */
1227 x_draw_glyph_string_background (s
, force_p
)
1228 struct glyph_string
*s
;
1231 /* Nothing to do if background has already been drawn or if it
1232 shouldn't be drawn in the first place. */
1233 if (!s
->background_filled_p
)
1235 int box_line_width
= max (s
->face
->box_line_width
, 0);
1239 /* Fill background with a stipple pattern. */
1240 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1241 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1242 s
->y
+ box_line_width
,
1243 s
->background_width
,
1244 s
->height
- 2 * box_line_width
);
1245 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1246 s
->background_filled_p
= 1;
1248 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1249 || s
->font_not_found_p
1250 || s
->extends_to_end_of_line_p
1253 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1254 s
->background_width
,
1255 s
->height
- 2 * box_line_width
);
1256 s
->background_filled_p
= 1;
1262 /* Draw the foreground of glyph string S. */
1265 x_draw_glyph_string_foreground (s
)
1266 struct glyph_string
*s
;
1270 /* If first glyph of S has a left box line, start drawing the text
1271 of S to the right of that box line. */
1272 if (s
->face
->box
!= FACE_NO_BOX
1273 && s
->first_glyph
->left_box_line_p
)
1274 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1278 /* Draw characters of S as rectangles if S's font could not be
1280 if (s
->font_not_found_p
)
1282 for (i
= 0; i
< s
->nchars
; ++i
)
1284 struct glyph
*g
= s
->first_glyph
+ i
;
1285 XDrawRectangle (s
->display
, s
->window
,
1286 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1288 x
+= g
->pixel_width
;
1293 struct font
*font
= s
->font
;
1294 int boff
= font
->baseline_offset
;
1297 if (font
->vertical_centering
)
1298 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1300 y
= s
->ybase
- boff
;
1302 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1303 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1305 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1306 if (s
->face
->overstrike
)
1307 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1311 /* Draw the foreground of composite glyph string S. */
1314 x_draw_composite_glyph_string_foreground (s
)
1315 struct glyph_string
*s
;
1318 struct font
*font
= s
->font
;
1320 /* If first glyph of S has a left box line, start drawing the text
1321 of S to the right of that box line. */
1322 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1323 && s
->first_glyph
->left_box_line_p
)
1324 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1328 /* S is a glyph string for a composition. S->cmp_from is the index
1329 of the first character drawn for glyphs of this composition.
1330 S->cmp_from == 0 means we are drawing the very first character of
1331 this composition. */
1333 /* Draw a rectangle for the composition if the font for the very
1334 first character of the composition could not be loaded. */
1335 if (s
->font_not_found_p
)
1337 if (s
->cmp_from
== 0)
1338 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1339 s
->width
- 1, s
->height
- 1);
1341 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1345 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1346 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1348 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1349 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1351 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1352 if (s
->face
->overstrike
)
1353 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1358 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1363 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1365 glyph
= LGSTRING_GLYPH (gstring
, i
);
1366 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1367 width
+= LGLYPH_WIDTH (glyph
);
1370 int xoff
, yoff
, wadjust
;
1374 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1377 xoff
= LGLYPH_XOFF (glyph
);
1378 yoff
= LGLYPH_YOFF (glyph
);
1379 wadjust
= LGLYPH_WADJUST (glyph
);
1380 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1387 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1392 #ifdef USE_X_TOOLKIT
1394 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1395 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1396 XrmValue
*, XrmValue
*, XtPointer
*));
1397 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1398 XrmValue
*, Cardinal
*));
1401 /* Return the frame on which widget WIDGET is used.. Abort if frame
1402 cannot be determined. */
1404 static struct frame
*
1405 x_frame_of_widget (widget
)
1408 struct x_display_info
*dpyinfo
;
1412 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1414 /* Find the top-level shell of the widget. Note that this function
1415 can be called when the widget is not yet realized, so XtWindow
1416 (widget) == 0. That's the reason we can't simply use
1417 x_any_window_to_frame. */
1418 while (!XtIsTopLevelShell (widget
))
1419 widget
= XtParent (widget
);
1421 /* Look for a frame with that top-level widget. Allocate the color
1422 on that frame to get the right gamma correction value. */
1423 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1424 if (FRAMEP (XCAR (tail
))
1425 && (f
= XFRAME (XCAR (tail
)),
1427 && f
->output_data
.nothing
!= 1
1428 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1429 && f
->output_data
.x
->widget
== widget
)
1436 /* Allocate the color COLOR->pixel on the screen and display of
1437 widget WIDGET in colormap CMAP. If an exact match cannot be
1438 allocated, try the nearest color available. Value is non-zero
1439 if successful. This is called from lwlib. */
1442 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1447 struct frame
*f
= x_frame_of_widget (widget
);
1448 return x_alloc_nearest_color (f
, cmap
, color
);
1452 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1453 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1454 If this produces the same color as PIXEL, try a color where all RGB
1455 values have DELTA added. Return the allocated color in *PIXEL.
1456 DISPLAY is the X display, CMAP is the colormap to operate on.
1457 Value is non-zero if successful. */
1460 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1464 unsigned long *pixel
;
1468 struct frame
*f
= x_frame_of_widget (widget
);
1469 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1473 /* Structure specifying which arguments should be passed by Xt to
1474 cvt_string_to_pixel. We want the widget's screen and colormap. */
1476 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1478 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1480 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1485 /* The address of this variable is returned by
1486 cvt_string_to_pixel. */
1488 static Pixel cvt_string_to_pixel_value
;
1491 /* Convert a color name to a pixel color.
1493 DPY is the display we are working on.
1495 ARGS is an array of *NARGS XrmValue structures holding additional
1496 information about the widget for which the conversion takes place.
1497 The contents of this array are determined by the specification
1498 in cvt_string_to_pixel_args.
1500 FROM is a pointer to an XrmValue which points to the color name to
1501 convert. TO is an XrmValue in which to return the pixel color.
1503 CLOSURE_RET is a pointer to user-data, in which we record if
1504 we allocated the color or not.
1506 Value is True if successful, False otherwise. */
1509 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1513 XrmValue
*from
, *to
;
1514 XtPointer
*closure_ret
;
1524 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1525 "wrongParameters", "cvt_string_to_pixel",
1527 "Screen and colormap args required", NULL
, NULL
);
1531 screen
= *(Screen
**) args
[0].addr
;
1532 cmap
= *(Colormap
*) args
[1].addr
;
1533 color_name
= (String
) from
->addr
;
1535 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1537 *closure_ret
= (XtPointer
) False
;
1538 pixel
= WhitePixelOfScreen (screen
);
1540 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1542 *closure_ret
= (XtPointer
) False
;
1543 pixel
= BlackPixelOfScreen (screen
);
1545 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1546 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1548 pixel
= color
.pixel
;
1549 *closure_ret
= (XtPointer
) True
;
1554 Cardinal nparams
= 1;
1556 params
[0] = color_name
;
1557 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1558 "badValue", "cvt_string_to_pixel",
1559 "XtToolkitError", "Invalid color `%s'",
1564 if (to
->addr
!= NULL
)
1566 if (to
->size
< sizeof (Pixel
))
1568 to
->size
= sizeof (Pixel
);
1572 *(Pixel
*) to
->addr
= pixel
;
1576 cvt_string_to_pixel_value
= pixel
;
1577 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1580 to
->size
= sizeof (Pixel
);
1585 /* Free a pixel color which was previously allocated via
1586 cvt_string_to_pixel. This is registered as the destructor
1587 for this type of resource via XtSetTypeConverter.
1589 APP is the application context in which we work.
1591 TO is a pointer to an XrmValue holding the color to free.
1592 CLOSURE is the value we stored in CLOSURE_RET for this color
1593 in cvt_string_to_pixel.
1595 ARGS and NARGS are like for cvt_string_to_pixel. */
1598 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1607 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1609 "Screen and colormap arguments required",
1612 else if (closure
!= NULL
)
1614 /* We did allocate the pixel, so free it. */
1615 Screen
*screen
= *(Screen
**) args
[0].addr
;
1616 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1617 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1618 (Pixel
*) to
->addr
, 1);
1623 #endif /* USE_X_TOOLKIT */
1626 /* Value is an array of XColor structures for the contents of the
1627 color map of display DPY. Set *NCELLS to the size of the array.
1628 Note that this probably shouldn't be called for large color maps,
1629 say a 24-bit TrueColor map. */
1631 static const XColor
*
1632 x_color_cells (dpy
, ncells
)
1636 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1638 if (dpyinfo
->color_cells
== NULL
)
1640 Screen
*screen
= dpyinfo
->screen
;
1643 dpyinfo
->ncolor_cells
1644 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1645 dpyinfo
->color_cells
1646 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1647 * sizeof *dpyinfo
->color_cells
);
1649 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1650 dpyinfo
->color_cells
[i
].pixel
= i
;
1652 XQueryColors (dpy
, dpyinfo
->cmap
,
1653 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1656 *ncells
= dpyinfo
->ncolor_cells
;
1657 return dpyinfo
->color_cells
;
1661 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1662 colors in COLORS. Use cached information, if available. */
1665 x_query_colors (f
, colors
, ncolors
)
1670 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1672 if (dpyinfo
->color_cells
)
1675 for (i
= 0; i
< ncolors
; ++i
)
1677 unsigned long pixel
= colors
[i
].pixel
;
1678 xassert (pixel
< dpyinfo
->ncolor_cells
);
1679 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1680 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1684 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1688 /* On frame F, translate pixel color to RGB values for the color in
1689 COLOR. Use cached information, if available. */
1692 x_query_color (f
, color
)
1696 x_query_colors (f
, color
, 1);
1700 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1701 exact match can't be allocated, try the nearest color available.
1702 Value is non-zero if successful. Set *COLOR to the color
1706 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1713 rc
= XAllocColor (dpy
, cmap
, color
);
1716 /* If we got to this point, the colormap is full, so we're going
1717 to try to get the next closest color. The algorithm used is
1718 a least-squares matching, which is what X uses for closest
1719 color matching with StaticColor visuals. */
1721 unsigned long nearest_delta
= ~0;
1723 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1725 for (nearest
= i
= 0; i
< ncells
; ++i
)
1727 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1728 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1729 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1730 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1732 if (delta
< nearest_delta
)
1735 nearest_delta
= delta
;
1739 color
->red
= cells
[nearest
].red
;
1740 color
->green
= cells
[nearest
].green
;
1741 color
->blue
= cells
[nearest
].blue
;
1742 rc
= XAllocColor (dpy
, cmap
, color
);
1746 /* If allocation succeeded, and the allocated pixel color is not
1747 equal to a cached pixel color recorded earlier, there was a
1748 change in the colormap, so clear the color cache. */
1749 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1750 XColor
*cached_color
;
1752 if (dpyinfo
->color_cells
1753 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1754 (cached_color
->red
!= color
->red
1755 || cached_color
->blue
!= color
->blue
1756 || cached_color
->green
!= color
->green
)))
1758 xfree (dpyinfo
->color_cells
);
1759 dpyinfo
->color_cells
= NULL
;
1760 dpyinfo
->ncolor_cells
= 0;
1764 #ifdef DEBUG_X_COLORS
1766 register_color (color
->pixel
);
1767 #endif /* DEBUG_X_COLORS */
1773 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1774 exact match can't be allocated, try the nearest color available.
1775 Value is non-zero if successful. Set *COLOR to the color
1779 x_alloc_nearest_color (f
, cmap
, color
)
1784 gamma_correct (f
, color
);
1785 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1789 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1790 It's necessary to do this instead of just using PIXEL directly to
1791 get color reference counts right. */
1794 x_copy_color (f
, pixel
)
1796 unsigned long pixel
;
1800 color
.pixel
= pixel
;
1802 x_query_color (f
, &color
);
1803 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1805 #ifdef DEBUG_X_COLORS
1806 register_color (pixel
);
1812 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1813 It's necessary to do this instead of just using PIXEL directly to
1814 get color reference counts right. */
1817 x_copy_dpy_color (dpy
, cmap
, pixel
)
1820 unsigned long pixel
;
1824 color
.pixel
= pixel
;
1826 XQueryColor (dpy
, cmap
, &color
);
1827 XAllocColor (dpy
, cmap
, &color
);
1829 #ifdef DEBUG_X_COLORS
1830 register_color (pixel
);
1836 /* Brightness beyond which a color won't have its highlight brightness
1839 Nominally, highlight colors for `3d' faces are calculated by
1840 brightening an object's color by a constant scale factor, but this
1841 doesn't yield good results for dark colors, so for colors who's
1842 brightness is less than this value (on a scale of 0-65535) have an
1843 use an additional additive factor.
1845 The value here is set so that the default menu-bar/mode-line color
1846 (grey75) will not have its highlights changed at all. */
1847 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1850 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1851 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1852 If this produces the same color as PIXEL, try a color where all RGB
1853 values have DELTA added. Return the allocated color in *PIXEL.
1854 DISPLAY is the X display, CMAP is the colormap to operate on.
1855 Value is non-zero if successful. */
1858 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1862 unsigned long *pixel
;
1870 /* Get RGB color values. */
1871 color
.pixel
= *pixel
;
1872 x_query_color (f
, &color
);
1874 /* Change RGB values by specified FACTOR. Avoid overflow! */
1875 xassert (factor
>= 0);
1876 new.red
= min (0xffff, factor
* color
.red
);
1877 new.green
= min (0xffff, factor
* color
.green
);
1878 new.blue
= min (0xffff, factor
* color
.blue
);
1880 /* Calculate brightness of COLOR. */
1881 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1883 /* We only boost colors that are darker than
1884 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1885 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1886 /* Make an additive adjustment to NEW, because it's dark enough so
1887 that scaling by FACTOR alone isn't enough. */
1889 /* How far below the limit this color is (0 - 1, 1 being darker). */
1890 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1891 /* The additive adjustment. */
1892 int min_delta
= delta
* dimness
* factor
/ 2;
1896 new.red
= max (0, new.red
- min_delta
);
1897 new.green
= max (0, new.green
- min_delta
);
1898 new.blue
= max (0, new.blue
- min_delta
);
1902 new.red
= min (0xffff, min_delta
+ new.red
);
1903 new.green
= min (0xffff, min_delta
+ new.green
);
1904 new.blue
= min (0xffff, min_delta
+ new.blue
);
1908 /* Try to allocate the color. */
1909 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1912 if (new.pixel
== *pixel
)
1914 /* If we end up with the same color as before, try adding
1915 delta to the RGB values. */
1916 x_free_colors (f
, &new.pixel
, 1);
1918 new.red
= min (0xffff, delta
+ color
.red
);
1919 new.green
= min (0xffff, delta
+ color
.green
);
1920 new.blue
= min (0xffff, delta
+ color
.blue
);
1921 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1932 /* Set up the foreground color for drawing relief lines of glyph
1933 string S. RELIEF is a pointer to a struct relief containing the GC
1934 with which lines will be drawn. Use a color that is FACTOR or
1935 DELTA lighter or darker than the relief's background which is found
1936 in S->f->output_data.x->relief_background. If such a color cannot
1937 be allocated, use DEFAULT_PIXEL, instead. */
1940 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1942 struct relief
*relief
;
1945 unsigned long default_pixel
;
1948 struct x_output
*di
= f
->output_data
.x
;
1949 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1950 unsigned long pixel
;
1951 unsigned long background
= di
->relief_background
;
1952 Colormap cmap
= FRAME_X_COLORMAP (f
);
1953 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1954 Display
*dpy
= FRAME_X_DISPLAY (f
);
1956 xgcv
.graphics_exposures
= False
;
1957 xgcv
.line_width
= 1;
1959 /* Free previously allocated color. The color cell will be reused
1960 when it has been freed as many times as it was allocated, so this
1961 doesn't affect faces using the same colors. */
1963 && relief
->allocated_p
)
1965 x_free_colors (f
, &relief
->pixel
, 1);
1966 relief
->allocated_p
= 0;
1969 /* Allocate new color. */
1970 xgcv
.foreground
= default_pixel
;
1972 if (dpyinfo
->n_planes
!= 1
1973 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1975 relief
->allocated_p
= 1;
1976 xgcv
.foreground
= relief
->pixel
= pixel
;
1979 if (relief
->gc
== 0)
1981 xgcv
.stipple
= dpyinfo
->gray
;
1983 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1986 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1990 /* Set up colors for the relief lines around glyph string S. */
1993 x_setup_relief_colors (s
)
1994 struct glyph_string
*s
;
1996 struct x_output
*di
= s
->f
->output_data
.x
;
1997 unsigned long color
;
1999 if (s
->face
->use_box_color_for_shadows_p
)
2000 color
= s
->face
->box_color
;
2001 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2003 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2004 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2009 /* Get the background color of the face. */
2010 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2011 color
= xgcv
.background
;
2014 if (di
->white_relief
.gc
== 0
2015 || color
!= di
->relief_background
)
2017 di
->relief_background
= color
;
2018 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2019 WHITE_PIX_DEFAULT (s
->f
));
2020 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2021 BLACK_PIX_DEFAULT (s
->f
));
2026 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2027 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2028 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2029 relief. LEFT_P non-zero means draw a relief on the left side of
2030 the rectangle. RIGHT_P non-zero means draw a relief on the right
2031 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2035 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2036 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2038 int left_x
, top_y
, right_x
, bottom_y
, width
;
2039 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2040 XRectangle
*clip_rect
;
2042 Display
*dpy
= FRAME_X_DISPLAY (f
);
2043 Window window
= FRAME_X_WINDOW (f
);
2048 gc
= f
->output_data
.x
->white_relief
.gc
;
2050 gc
= f
->output_data
.x
->black_relief
.gc
;
2051 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2055 for (i
= 0; i
< width
; ++i
)
2056 XDrawLine (dpy
, window
, gc
,
2057 left_x
+ i
* left_p
, top_y
+ i
,
2058 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2062 for (i
= 0; i
< width
; ++i
)
2063 XDrawLine (dpy
, window
, gc
,
2064 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2066 XSetClipMask (dpy
, gc
, None
);
2068 gc
= f
->output_data
.x
->black_relief
.gc
;
2070 gc
= f
->output_data
.x
->white_relief
.gc
;
2071 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2075 for (i
= 0; i
< width
; ++i
)
2076 XDrawLine (dpy
, window
, gc
,
2077 left_x
+ i
* left_p
, bottom_y
- i
,
2078 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2082 for (i
= 0; i
< width
; ++i
)
2083 XDrawLine (dpy
, window
, gc
,
2084 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2086 XSetClipMask (dpy
, gc
, None
);
2090 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2091 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2092 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2093 left side of the rectangle. RIGHT_P non-zero means draw a line
2094 on the right side of the rectangle. CLIP_RECT is the clipping
2095 rectangle to use when drawing. */
2098 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2099 left_p
, right_p
, clip_rect
)
2100 struct glyph_string
*s
;
2101 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2102 XRectangle
*clip_rect
;
2106 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2107 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2108 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2111 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2112 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2116 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2117 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2120 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2121 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2125 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2126 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2128 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2129 XSetClipMask (s
->display
, s
->gc
, None
);
2133 /* Draw a box around glyph string S. */
2136 x_draw_glyph_string_box (s
)
2137 struct glyph_string
*s
;
2139 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2140 int left_p
, right_p
;
2141 struct glyph
*last_glyph
;
2142 XRectangle clip_rect
;
2144 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2145 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2146 : window_box_right (s
->w
, s
->area
));
2148 /* The glyph that may have a right box line. */
2149 last_glyph
= (s
->cmp
|| s
->img
2151 : s
->first_glyph
+ s
->nchars
- 1);
2153 width
= eabs (s
->face
->box_line_width
);
2154 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2156 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2158 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2160 bottom_y
= top_y
+ s
->height
- 1;
2162 left_p
= (s
->first_glyph
->left_box_line_p
2163 || (s
->hl
== DRAW_MOUSE_FACE
2165 || s
->prev
->hl
!= s
->hl
)));
2166 right_p
= (last_glyph
->right_box_line_p
2167 || (s
->hl
== DRAW_MOUSE_FACE
2169 || s
->next
->hl
!= s
->hl
)));
2171 get_glyph_string_clip_rect (s
, &clip_rect
);
2173 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2174 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2175 left_p
, right_p
, &clip_rect
);
2178 x_setup_relief_colors (s
);
2179 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2180 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2185 /* Draw foreground of image glyph string S. */
2188 x_draw_image_foreground (s
)
2189 struct glyph_string
*s
;
2192 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2194 /* If first glyph of S has a left box line, start drawing it to the
2195 right of that line. */
2196 if (s
->face
->box
!= FACE_NO_BOX
2197 && s
->first_glyph
->left_box_line_p
2199 x
+= eabs (s
->face
->box_line_width
);
2201 /* If there is a margin around the image, adjust x- and y-position
2203 if (s
->slice
.x
== 0)
2204 x
+= s
->img
->hmargin
;
2205 if (s
->slice
.y
== 0)
2206 y
+= s
->img
->vmargin
;
2212 /* We can't set both a clip mask and use XSetClipRectangles
2213 because the latter also sets a clip mask. We also can't
2214 trust on the shape extension to be available
2215 (XShapeCombineRegion). So, compute the rectangle to draw
2217 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2220 XRectangle clip_rect
, image_rect
, r
;
2222 xgcv
.clip_mask
= s
->img
->mask
;
2223 xgcv
.clip_x_origin
= x
;
2224 xgcv
.clip_y_origin
= y
;
2225 xgcv
.function
= GXcopy
;
2226 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2228 get_glyph_string_clip_rect (s
, &clip_rect
);
2231 image_rect
.width
= s
->slice
.width
;
2232 image_rect
.height
= s
->slice
.height
;
2233 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2234 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2235 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2236 r
.width
, r
.height
, r
.x
, r
.y
);
2240 XRectangle clip_rect
, image_rect
, r
;
2242 get_glyph_string_clip_rect (s
, &clip_rect
);
2245 image_rect
.width
= s
->slice
.width
;
2246 image_rect
.height
= s
->slice
.height
;
2247 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2248 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2249 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2250 r
.width
, r
.height
, r
.x
, r
.y
);
2252 /* When the image has a mask, we can expect that at
2253 least part of a mouse highlight or a block cursor will
2254 be visible. If the image doesn't have a mask, make
2255 a block cursor visible by drawing a rectangle around
2256 the image. I believe it's looking better if we do
2257 nothing here for mouse-face. */
2258 if (s
->hl
== DRAW_CURSOR
)
2260 int r
= s
->img
->relief
;
2262 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2264 s
->slice
.width
+ r
*2 - 1,
2265 s
->slice
.height
+ r
*2 - 1);
2270 /* Draw a rectangle if image could not be loaded. */
2271 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2272 s
->slice
.width
- 1, s
->slice
.height
- 1);
2276 /* Draw a relief around the image glyph string S. */
2279 x_draw_image_relief (s
)
2280 struct glyph_string
*s
;
2282 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2285 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2287 /* If first glyph of S has a left box line, start drawing it to the
2288 right of that line. */
2289 if (s
->face
->box
!= FACE_NO_BOX
2290 && s
->first_glyph
->left_box_line_p
2292 x
+= eabs (s
->face
->box_line_width
);
2294 /* If there is a margin around the image, adjust x- and y-position
2296 if (s
->slice
.x
== 0)
2297 x
+= s
->img
->hmargin
;
2298 if (s
->slice
.y
== 0)
2299 y
+= s
->img
->vmargin
;
2301 if (s
->hl
== DRAW_IMAGE_SUNKEN
2302 || s
->hl
== DRAW_IMAGE_RAISED
)
2304 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2305 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2309 thick
= eabs (s
->img
->relief
);
2310 raised_p
= s
->img
->relief
> 0;
2315 x1
= x
+ s
->slice
.width
+ thick
- 1;
2316 y1
= y
+ s
->slice
.height
+ thick
- 1;
2318 x_setup_relief_colors (s
);
2319 get_glyph_string_clip_rect (s
, &r
);
2320 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2322 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2324 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2329 /* Draw the foreground of image glyph string S to PIXMAP. */
2332 x_draw_image_foreground_1 (s
, pixmap
)
2333 struct glyph_string
*s
;
2337 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2339 /* If first glyph of S has a left box line, start drawing it to the
2340 right of that line. */
2341 if (s
->face
->box
!= FACE_NO_BOX
2342 && s
->first_glyph
->left_box_line_p
2344 x
+= eabs (s
->face
->box_line_width
);
2346 /* If there is a margin around the image, adjust x- and y-position
2348 if (s
->slice
.x
== 0)
2349 x
+= s
->img
->hmargin
;
2350 if (s
->slice
.y
== 0)
2351 y
+= s
->img
->vmargin
;
2357 /* We can't set both a clip mask and use XSetClipRectangles
2358 because the latter also sets a clip mask. We also can't
2359 trust on the shape extension to be available
2360 (XShapeCombineRegion). So, compute the rectangle to draw
2362 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2366 xgcv
.clip_mask
= s
->img
->mask
;
2367 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2368 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2369 xgcv
.function
= GXcopy
;
2370 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2372 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2373 s
->slice
.x
, s
->slice
.y
,
2374 s
->slice
.width
, s
->slice
.height
, x
, y
);
2375 XSetClipMask (s
->display
, s
->gc
, None
);
2379 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2380 s
->slice
.x
, s
->slice
.y
,
2381 s
->slice
.width
, s
->slice
.height
, x
, y
);
2383 /* When the image has a mask, we can expect that at
2384 least part of a mouse highlight or a block cursor will
2385 be visible. If the image doesn't have a mask, make
2386 a block cursor visible by drawing a rectangle around
2387 the image. I believe it's looking better if we do
2388 nothing here for mouse-face. */
2389 if (s
->hl
== DRAW_CURSOR
)
2391 int r
= s
->img
->relief
;
2393 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2394 s
->slice
.width
+ r
*2 - 1,
2395 s
->slice
.height
+ r
*2 - 1);
2400 /* Draw a rectangle if image could not be loaded. */
2401 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2402 s
->slice
.width
- 1, s
->slice
.height
- 1);
2406 /* Draw part of the background of glyph string S. X, Y, W, and H
2407 give the rectangle to draw. */
2410 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2411 struct glyph_string
*s
;
2416 /* Fill background with a stipple pattern. */
2417 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2418 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2419 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2422 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2426 /* Draw image glyph string S.
2429 s->x +-------------------------
2432 | +-------------------------
2435 | | +-------------------
2441 x_draw_image_glyph_string (s
)
2442 struct glyph_string
*s
;
2444 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2445 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2447 Pixmap pixmap
= None
;
2450 if (s
->slice
.y
== 0)
2451 height
-= box_line_vwidth
;
2452 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2453 height
-= box_line_vwidth
;
2455 /* Fill background with face under the image. Do it only if row is
2456 taller than image or if image has a clip mask to reduce
2458 s
->stippled_p
= s
->face
->stipple
!= 0;
2459 if (height
> s
->slice
.height
2463 || s
->img
->pixmap
== 0
2464 || s
->width
!= s
->background_width
)
2468 /* Create a pixmap as large as the glyph string. Fill it
2469 with the background color. Copy the image to it, using
2470 its mask. Copy the temporary pixmap to the display. */
2471 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2472 int depth
= DefaultDepthOfScreen (screen
);
2474 /* Create a pixmap as large as the glyph string. */
2475 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2476 s
->background_width
,
2479 /* Don't clip in the following because we're working on the
2481 XSetClipMask (s
->display
, s
->gc
, None
);
2483 /* Fill the pixmap with the background color/stipple. */
2486 /* Fill background with a stipple pattern. */
2487 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2488 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2489 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2490 0, 0, s
->background_width
, s
->height
);
2491 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2492 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2497 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2499 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2500 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2501 0, 0, s
->background_width
, s
->height
);
2502 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2510 if (s
->first_glyph
->left_box_line_p
2512 x
+= box_line_hwidth
;
2514 if (s
->slice
.y
== 0)
2515 y
+= box_line_vwidth
;
2517 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2520 s
->background_filled_p
= 1;
2523 /* Draw the foreground. */
2526 x_draw_image_foreground_1 (s
, pixmap
);
2527 x_set_glyph_string_clipping (s
);
2528 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2529 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2530 XFreePixmap (s
->display
, pixmap
);
2533 x_draw_image_foreground (s
);
2535 /* If we must draw a relief around the image, do it. */
2537 || s
->hl
== DRAW_IMAGE_RAISED
2538 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2539 x_draw_image_relief (s
);
2543 /* Draw stretch glyph string S. */
2546 x_draw_stretch_glyph_string (s
)
2547 struct glyph_string
*s
;
2549 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2551 if (s
->hl
== DRAW_CURSOR
2552 && !x_stretch_cursor_p
)
2554 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2555 as wide as the stretch glyph. */
2556 int width
, background_width
= s
->background_width
;
2557 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2561 background_width
-= left_x
- x
;
2564 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2567 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2569 /* Clear rest using the GC of the original non-cursor face. */
2570 if (width
< background_width
)
2573 int w
= background_width
- width
, h
= s
->height
;
2578 if (s
->row
->mouse_face_p
2579 && cursor_in_mouse_face_p (s
->w
))
2581 x_set_mouse_face_gc (s
);
2587 get_glyph_string_clip_rect (s
, &r
);
2588 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2590 if (s
->face
->stipple
)
2592 /* Fill background with a stipple pattern. */
2593 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2594 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2595 XSetFillStyle (s
->display
, gc
, FillSolid
);
2600 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2601 XSetForeground (s
->display
, gc
, xgcv
.background
);
2602 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2603 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2607 else if (!s
->background_filled_p
)
2609 int background_width
= s
->background_width
;
2610 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2612 /* Don't draw into left margin, fringe or scrollbar area
2613 except for header line and mode line. */
2614 if (x
< left_x
&& !s
->row
->mode_line_p
)
2616 background_width
-= left_x
- x
;
2619 if (background_width
> 0)
2620 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2623 s
->background_filled_p
= 1;
2627 /* Draw glyph string S. */
2630 x_draw_glyph_string (s
)
2631 struct glyph_string
*s
;
2633 int relief_drawn_p
= 0;
2635 /* If S draws into the background of its successors, draw the
2636 background of the successors first so that S can draw into it.
2637 This makes S->next use XDrawString instead of XDrawImageString. */
2638 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2641 struct glyph_string
*next
;
2643 for (width
= 0, next
= s
->next
;
2644 next
&& width
< s
->right_overhang
;
2645 width
+= next
->width
, next
= next
->next
)
2646 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2648 x_set_glyph_string_gc (next
);
2649 x_set_glyph_string_clipping (next
);
2650 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2651 x_draw_stretch_glyph_string (next
);
2653 x_draw_glyph_string_background (next
, 1);
2654 next
->num_clips
= 0;
2658 /* Set up S->gc, set clipping and draw S. */
2659 x_set_glyph_string_gc (s
);
2661 /* Draw relief (if any) in advance for char/composition so that the
2662 glyph string can be drawn over it. */
2663 if (!s
->for_overlaps
2664 && s
->face
->box
!= FACE_NO_BOX
2665 && (s
->first_glyph
->type
== CHAR_GLYPH
2666 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2669 x_set_glyph_string_clipping (s
);
2670 x_draw_glyph_string_background (s
, 1);
2671 x_draw_glyph_string_box (s
);
2672 x_set_glyph_string_clipping (s
);
2675 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2677 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2678 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2679 /* We must clip just this glyph. left_overhang part has already
2680 drawn when s->prev was drawn, and right_overhang part will be
2681 drawn later when s->next is drawn. */
2682 x_set_glyph_string_clipping_exactly (s
, s
);
2684 x_set_glyph_string_clipping (s
);
2686 switch (s
->first_glyph
->type
)
2689 x_draw_image_glyph_string (s
);
2693 x_draw_stretch_glyph_string (s
);
2697 if (s
->for_overlaps
)
2698 s
->background_filled_p
= 1;
2700 x_draw_glyph_string_background (s
, 0);
2701 x_draw_glyph_string_foreground (s
);
2704 case COMPOSITE_GLYPH
:
2705 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2706 && ! s
->first_glyph
->u
.cmp
.automatic
))
2707 s
->background_filled_p
= 1;
2709 x_draw_glyph_string_background (s
, 1);
2710 x_draw_composite_glyph_string_foreground (s
);
2717 if (!s
->for_overlaps
)
2719 /* Draw underline. */
2720 if (s
->face
->underline_p
)
2722 unsigned long thickness
, position
;
2725 if (s
->prev
&& s
->prev
->face
->underline_p
)
2727 /* We use the same underline style as the previous one. */
2728 thickness
= s
->prev
->underline_thickness
;
2729 position
= s
->prev
->underline_position
;
2733 /* Get the underline thickness. Default is 1 pixel. */
2734 if (s
->font
&& s
->font
->underline_thickness
> 0)
2735 thickness
= s
->font
->underline_thickness
;
2738 if (x_underline_at_descent_line
)
2739 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2742 /* Get the underline position. This is the recommended
2743 vertical offset in pixels from the baseline to the top of
2744 the underline. This is a signed value according to the
2745 specs, and its default is
2747 ROUND ((maximum descent) / 2), with
2748 ROUND(x) = floor (x + 0.5) */
2750 if (x_use_underline_position_properties
2751 && s
->font
&& s
->font
->underline_position
>= 0)
2752 position
= s
->font
->underline_position
;
2754 position
= (s
->font
->descent
+ 1) / 2;
2756 position
= underline_minimum_offset
;
2758 position
= max (position
, underline_minimum_offset
);
2760 /* Check the sanity of thickness and position. We should
2761 avoid drawing underline out of the current line area. */
2762 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2763 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2764 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2765 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2766 s
->underline_thickness
= thickness
;
2767 s
->underline_position
= position
;
2768 y
= s
->ybase
+ position
;
2769 if (s
->face
->underline_defaulted_p
)
2770 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2771 s
->x
, y
, s
->width
, thickness
);
2775 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2776 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2777 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2778 s
->x
, y
, s
->width
, thickness
);
2779 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2783 /* Draw overline. */
2784 if (s
->face
->overline_p
)
2786 unsigned long dy
= 0, h
= 1;
2788 if (s
->face
->overline_color_defaulted_p
)
2789 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2794 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2795 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2796 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2798 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2802 /* Draw strike-through. */
2803 if (s
->face
->strike_through_p
)
2805 unsigned long h
= 1;
2806 unsigned long dy
= (s
->height
- h
) / 2;
2808 if (s
->face
->strike_through_color_defaulted_p
)
2809 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2814 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2815 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2816 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2818 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2822 /* Draw relief if not yet drawn. */
2823 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2824 x_draw_glyph_string_box (s
);
2828 struct glyph_string
*prev
;
2830 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2831 if (prev
->hl
!= s
->hl
2832 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2834 /* As prev was drawn while clipped to its own area, we
2835 must draw the right_overhang part using s->hl now. */
2836 enum draw_glyphs_face save
= prev
->hl
;
2839 x_set_glyph_string_gc (prev
);
2840 x_set_glyph_string_clipping_exactly (s
, prev
);
2841 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2842 x_draw_glyph_string_foreground (prev
);
2844 x_draw_composite_glyph_string_foreground (prev
);
2845 XSetClipMask (prev
->display
, prev
->gc
, None
);
2847 prev
->num_clips
= 0;
2853 struct glyph_string
*next
;
2855 for (next
= s
->next
; next
; next
= next
->next
)
2856 if (next
->hl
!= s
->hl
2857 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2859 /* As next will be drawn while clipped to its own area,
2860 we must draw the left_overhang part using s->hl now. */
2861 enum draw_glyphs_face save
= next
->hl
;
2864 x_set_glyph_string_gc (next
);
2865 x_set_glyph_string_clipping_exactly (s
, next
);
2866 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2867 x_draw_glyph_string_foreground (next
);
2869 x_draw_composite_glyph_string_foreground (next
);
2870 XSetClipMask (next
->display
, next
->gc
, None
);
2872 next
->num_clips
= 0;
2877 /* Reset clipping. */
2878 XSetClipMask (s
->display
, s
->gc
, None
);
2882 /* Shift display to make room for inserted glyphs. */
2885 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2887 int x
, y
, width
, height
, shift_by
;
2889 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2890 f
->output_data
.x
->normal_gc
,
2891 x
, y
, width
, height
,
2895 /* Delete N glyphs at the nominal cursor position. Not implemented
2899 x_delete_glyphs (f
, n
)
2907 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2908 If they are <= 0, this is probably an error. */
2911 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2918 xassert (width
> 0 && height
> 0);
2919 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2923 /* Clear an entire frame. */
2926 x_clear_frame (struct frame
*f
)
2928 /* Clearing the frame will erase any cursor, so mark them all as no
2930 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2931 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2932 output_cursor
.x
= -1;
2934 /* We don't set the output cursor here because there will always
2935 follow an explicit cursor_to. */
2937 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2939 /* We have to clear the scroll bars, too. If we have changed
2940 colors or something like that, then they should be notified. */
2941 x_scroll_bar_clear (f
);
2943 XFlush (FRAME_X_DISPLAY (f
));
2950 /* Invert the middle quarter of the frame for .15 sec. */
2952 /* We use the select system call to do the waiting, so we have to make
2953 sure it's available. If it isn't, we just won't do visual bells. */
2955 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2958 /* Subtract the `struct timeval' values X and Y, storing the result in
2959 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2962 timeval_subtract (result
, x
, y
)
2963 struct timeval
*result
, x
, y
;
2965 /* Perform the carry for the later subtraction by updating y. This
2966 is safer because on some systems the tv_sec member is unsigned. */
2967 if (x
.tv_usec
< y
.tv_usec
)
2969 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2970 y
.tv_usec
-= 1000000 * nsec
;
2974 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2976 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2977 y
.tv_usec
+= 1000000 * nsec
;
2981 /* Compute the time remaining to wait. tv_usec is certainly
2983 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2984 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2986 /* Return indication of whether the result should be considered
2988 return x
.tv_sec
< y
.tv_sec
;
3000 /* Create a GC that will use the GXxor function to flip foreground
3001 pixels into background pixels. */
3005 values
.function
= GXxor
;
3006 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3007 ^ FRAME_BACKGROUND_PIXEL (f
));
3009 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3010 GCFunction
| GCForeground
, &values
);
3014 /* Get the height not including a menu bar widget. */
3015 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3016 /* Height of each line to flash. */
3017 int flash_height
= FRAME_LINE_HEIGHT (f
);
3018 /* These will be the left and right margins of the rectangles. */
3019 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3020 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3024 /* Don't flash the area between a scroll bar and the frame
3025 edge it is next to. */
3026 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3028 case vertical_scroll_bar_left
:
3029 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3032 case vertical_scroll_bar_right
:
3033 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3040 width
= flash_right
- flash_left
;
3042 /* If window is tall, flash top and bottom line. */
3043 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3045 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3047 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3048 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3049 width
, flash_height
);
3050 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3052 (height
- flash_height
3053 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3054 width
, flash_height
);
3057 /* If it is short, flash it all. */
3058 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3059 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3060 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3065 struct timeval wakeup
;
3067 EMACS_GET_TIME (wakeup
);
3069 /* Compute time to wait until, propagating carry from usecs. */
3070 wakeup
.tv_usec
+= 150000;
3071 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3072 wakeup
.tv_usec
%= 1000000;
3074 /* Keep waiting until past the time wakeup or any input gets
3076 while (! detect_input_pending ())
3078 struct timeval current
;
3079 struct timeval timeout
;
3081 EMACS_GET_TIME (current
);
3083 /* Break if result would be negative. */
3084 if (timeval_subtract (¤t
, wakeup
, current
))
3087 /* How long `select' should wait. */
3089 timeout
.tv_usec
= 10000;
3091 /* Try to wait that long--but we might wake up sooner. */
3092 select (0, NULL
, NULL
, NULL
, &timeout
);
3096 /* If window is tall, flash top and bottom line. */
3097 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3099 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3101 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3102 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3103 width
, flash_height
);
3104 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3106 (height
- flash_height
3107 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3108 width
, flash_height
);
3111 /* If it is short, flash it all. */
3112 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3113 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3114 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3116 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3124 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3128 XTtoggle_invisible_pointer (f
, invisible
)
3135 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3136 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3137 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
);
3140 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3141 f
->output_data
.x
->current_cursor
);
3142 f
->pointer_invisible
= invisible
;
3147 /* Make audible bell. */
3152 struct frame
*f
= SELECTED_FRAME ();
3154 if (FRAME_X_DISPLAY (f
))
3156 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3163 XBell (FRAME_X_DISPLAY (f
), 0);
3164 XFlush (FRAME_X_DISPLAY (f
));
3171 /* Specify how many text lines, from the top of the window,
3172 should be affected by insert-lines and delete-lines operations.
3173 This, and those operations, are used only within an update
3174 that is bounded by calls to x_update_begin and x_update_end. */
3177 XTset_terminal_window (n
)
3180 /* This function intentionally left blank. */
3185 /***********************************************************************
3187 ***********************************************************************/
3189 /* Perform an insert-lines or delete-lines operation, inserting N
3190 lines or deleting -N lines at vertical position VPOS. */
3193 x_ins_del_lines (f
, vpos
, n
)
3201 /* Scroll part of the display as described by RUN. */
3204 x_scroll_run (w
, run
)
3208 struct frame
*f
= XFRAME (w
->frame
);
3209 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3211 /* Get frame-relative bounding box of the text display area of W,
3212 without mode lines. Include in this box the left and right
3214 window_box (w
, -1, &x
, &y
, &width
, &height
);
3216 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3217 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3218 bottom_y
= y
+ height
;
3222 /* Scrolling up. Make sure we don't copy part of the mode
3223 line at the bottom. */
3224 if (from_y
+ run
->height
> bottom_y
)
3225 height
= bottom_y
- from_y
;
3227 height
= run
->height
;
3231 /* Scolling down. Make sure we don't copy over the mode line.
3233 if (to_y
+ run
->height
> bottom_y
)
3234 height
= bottom_y
- to_y
;
3236 height
= run
->height
;
3241 /* Cursor off. Will be switched on again in x_update_window_end. */
3245 XCopyArea (FRAME_X_DISPLAY (f
),
3246 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3247 f
->output_data
.x
->normal_gc
,
3257 /***********************************************************************
3259 ***********************************************************************/
3266 /* We used to only do this if Vx_no_window_manager was non-nil, but
3267 the ICCCM (section 4.1.6) says that the window's border pixmap
3268 and border pixel are window attributes which are "private to the
3269 client", so we can always change it to whatever we want. */
3271 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3272 f
->output_data
.x
->border_pixel
);
3274 x_update_cursor (f
, 1);
3275 x_set_frame_alpha (f
);
3279 frame_unhighlight (f
)
3282 /* We used to only do this if Vx_no_window_manager was non-nil, but
3283 the ICCCM (section 4.1.6) says that the window's border pixmap
3284 and border pixel are window attributes which are "private to the
3285 client", so we can always change it to whatever we want. */
3287 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3288 f
->output_data
.x
->border_tile
);
3290 x_update_cursor (f
, 1);
3291 x_set_frame_alpha (f
);
3294 /* The focus has changed. Update the frames as necessary to reflect
3295 the new situation. Note that we can't change the selected frame
3296 here, because the Lisp code we are interrupting might become confused.
3297 Each event gets marked with the frame in which it occurred, so the
3298 Lisp code can tell when the switch took place by examining the events. */
3301 x_new_focus_frame (dpyinfo
, frame
)
3302 struct x_display_info
*dpyinfo
;
3303 struct frame
*frame
;
3305 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3307 if (frame
!= dpyinfo
->x_focus_frame
)
3309 /* Set this before calling other routines, so that they see
3310 the correct value of x_focus_frame. */
3311 dpyinfo
->x_focus_frame
= frame
;
3313 if (old_focus
&& old_focus
->auto_lower
)
3314 x_lower_frame (old_focus
);
3316 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3317 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3319 pending_autoraise_frame
= 0;
3322 x_frame_rehighlight (dpyinfo
);
3325 /* Handle FocusIn and FocusOut state changes for FRAME.
3326 If FRAME has focus and there exists more than one frame, puts
3327 a FOCUS_IN_EVENT into *BUFP. */
3330 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
3333 struct x_display_info
*dpyinfo
;
3334 struct frame
*frame
;
3335 struct input_event
*bufp
;
3337 if (type
== FocusIn
)
3339 if (dpyinfo
->x_focus_event_frame
!= frame
)
3341 x_new_focus_frame (dpyinfo
, frame
);
3342 dpyinfo
->x_focus_event_frame
= frame
;
3344 /* Don't stop displaying the initial startup message
3345 for a switch-frame event we don't need. */
3346 if (NILP (Vterminal_frame
)
3347 && CONSP (Vframe_list
)
3348 && !NILP (XCDR (Vframe_list
)))
3350 bufp
->kind
= FOCUS_IN_EVENT
;
3351 XSETFRAME (bufp
->frame_or_window
, frame
);
3355 frame
->output_data
.x
->focus_state
|= state
;
3358 if (FRAME_XIC (frame
))
3359 XSetICFocus (FRAME_XIC (frame
));
3362 else if (type
== FocusOut
)
3364 frame
->output_data
.x
->focus_state
&= ~state
;
3366 if (dpyinfo
->x_focus_event_frame
== frame
)
3368 dpyinfo
->x_focus_event_frame
= 0;
3369 x_new_focus_frame (dpyinfo
, 0);
3373 if (FRAME_XIC (frame
))
3374 XUnsetICFocus (FRAME_XIC (frame
));
3376 if (frame
->pointer_invisible
)
3377 XTtoggle_invisible_pointer (frame
, 0);
3381 /* The focus may have changed. Figure out if it is a real focus change,
3382 by checking both FocusIn/Out and Enter/LeaveNotify events.
3384 Returns FOCUS_IN_EVENT event in *BUFP. */
3387 x_detect_focus_change (dpyinfo
, event
, bufp
)
3388 struct x_display_info
*dpyinfo
;
3390 struct input_event
*bufp
;
3392 struct frame
*frame
;
3394 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3398 switch (event
->type
)
3403 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3405 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3407 if (event
->xcrossing
.detail
!= NotifyInferior
3408 && event
->xcrossing
.focus
3409 && ! (focus_state
& FOCUS_EXPLICIT
))
3410 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3412 dpyinfo
, frame
, bufp
);
3418 x_focus_changed (event
->type
,
3419 (event
->xfocus
.detail
== NotifyPointer
?
3420 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3421 dpyinfo
, frame
, bufp
);
3425 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3427 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3428 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3429 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3436 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3439 x_mouse_leave (dpyinfo
)
3440 struct x_display_info
*dpyinfo
;
3442 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3445 /* The focus has changed, or we have redirected a frame's focus to
3446 another frame (this happens when a frame uses a surrogate
3447 mini-buffer frame). Shift the highlight as appropriate.
3449 The FRAME argument doesn't necessarily have anything to do with which
3450 frame is being highlighted or un-highlighted; we only use it to find
3451 the appropriate X display info. */
3454 XTframe_rehighlight (frame
)
3455 struct frame
*frame
;
3457 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3461 x_frame_rehighlight (dpyinfo
)
3462 struct x_display_info
*dpyinfo
;
3464 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3466 if (dpyinfo
->x_focus_frame
)
3468 dpyinfo
->x_highlight_frame
3469 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3470 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3471 : dpyinfo
->x_focus_frame
);
3472 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3474 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3475 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3479 dpyinfo
->x_highlight_frame
= 0;
3481 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3484 frame_unhighlight (old_highlight
);
3485 if (dpyinfo
->x_highlight_frame
)
3486 frame_highlight (dpyinfo
->x_highlight_frame
);
3492 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3494 /* Initialize mode_switch_bit and modifier_meaning. */
3496 x_find_modifier_meanings (dpyinfo
)
3497 struct x_display_info
*dpyinfo
;
3499 int min_code
, max_code
;
3502 XModifierKeymap
*mods
;
3504 dpyinfo
->meta_mod_mask
= 0;
3505 dpyinfo
->shift_lock_mask
= 0;
3506 dpyinfo
->alt_mod_mask
= 0;
3507 dpyinfo
->super_mod_mask
= 0;
3508 dpyinfo
->hyper_mod_mask
= 0;
3510 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3512 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3513 min_code
, max_code
- min_code
+ 1,
3515 mods
= XGetModifierMapping (dpyinfo
->display
);
3517 /* Scan the modifier table to see which modifier bits the Meta and
3518 Alt keysyms are on. */
3520 int row
, col
; /* The row and column in the modifier table. */
3521 int found_alt_or_meta
;
3523 for (row
= 3; row
< 8; row
++)
3525 found_alt_or_meta
= 0;
3526 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3528 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3530 /* Zeroes are used for filler. Skip them. */
3534 /* Are any of this keycode's keysyms a meta key? */
3538 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3540 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3546 found_alt_or_meta
= 1;
3547 dpyinfo
->meta_mod_mask
|= (1 << row
);
3552 found_alt_or_meta
= 1;
3553 dpyinfo
->alt_mod_mask
|= (1 << row
);
3558 if (!found_alt_or_meta
)
3559 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3560 code_col
= syms_per_code
;
3561 col
= mods
->max_keypermod
;
3566 if (!found_alt_or_meta
)
3567 dpyinfo
->super_mod_mask
|= (1 << row
);
3568 code_col
= syms_per_code
;
3569 col
= mods
->max_keypermod
;
3573 /* Ignore this if it's not on the lock modifier. */
3574 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3575 dpyinfo
->shift_lock_mask
= LockMask
;
3576 code_col
= syms_per_code
;
3577 col
= mods
->max_keypermod
;
3586 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3587 if (! dpyinfo
->meta_mod_mask
)
3589 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3590 dpyinfo
->alt_mod_mask
= 0;
3593 /* If some keys are both alt and meta,
3594 make them just meta, not alt. */
3595 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3597 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3600 XFree ((char *) syms
);
3601 XFreeModifiermap (mods
);
3604 /* Convert between the modifier bits X uses and the modifier bits
3608 x_x_to_emacs_modifiers (dpyinfo
, state
)
3609 struct x_display_info
*dpyinfo
;
3612 EMACS_UINT mod_meta
= meta_modifier
;
3613 EMACS_UINT mod_alt
= alt_modifier
;
3614 EMACS_UINT mod_hyper
= hyper_modifier
;
3615 EMACS_UINT mod_super
= super_modifier
;
3618 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3619 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3620 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3621 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3622 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3623 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3624 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3625 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3628 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3629 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3630 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3631 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3632 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3633 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3637 x_emacs_to_x_modifiers (dpyinfo
, state
)
3638 struct x_display_info
*dpyinfo
;
3641 EMACS_UINT mod_meta
= meta_modifier
;
3642 EMACS_UINT mod_alt
= alt_modifier
;
3643 EMACS_UINT mod_hyper
= hyper_modifier
;
3644 EMACS_UINT mod_super
= super_modifier
;
3648 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3649 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3650 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3651 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3652 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3653 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3654 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3655 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3658 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3659 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3660 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3661 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3662 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3663 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3666 /* Convert a keysym to its name. */
3669 x_get_keysym_name (keysym
)
3675 value
= XKeysymToString (keysym
);
3683 /* Mouse clicks and mouse movement. Rah. */
3685 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3687 If the event is a button press, then note that we have grabbed
3691 construct_mouse_click (result
, event
, f
)
3692 struct input_event
*result
;
3693 XButtonEvent
*event
;
3696 /* Make the event type NO_EVENT; we'll change that when we decide
3698 result
->kind
= MOUSE_CLICK_EVENT
;
3699 result
->code
= event
->button
- Button1
;
3700 result
->timestamp
= event
->time
;
3701 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3703 | (event
->type
== ButtonRelease
3707 XSETINT (result
->x
, event
->x
);
3708 XSETINT (result
->y
, event
->y
);
3709 XSETFRAME (result
->frame_or_window
, f
);
3715 /* Function to report a mouse movement to the mainstream Emacs code.
3716 The input handler calls this.
3718 We have received a mouse movement event, which is given in *event.
3719 If the mouse is over a different glyph than it was last time, tell
3720 the mainstream emacs code by setting mouse_moved. If not, ask for
3721 another motion event, so we can check again the next time it moves. */
3723 static XMotionEvent last_mouse_motion_event
;
3724 static Lisp_Object last_mouse_motion_frame
;
3727 note_mouse_movement (frame
, event
)
3729 XMotionEvent
*event
;
3731 last_mouse_movement_time
= event
->time
;
3732 last_mouse_motion_event
= *event
;
3733 XSETFRAME (last_mouse_motion_frame
, frame
);
3735 if (!FRAME_X_OUTPUT (frame
))
3738 if (event
->window
!= FRAME_X_WINDOW (frame
))
3740 frame
->mouse_moved
= 1;
3741 last_mouse_scroll_bar
= Qnil
;
3742 note_mouse_highlight (frame
, -1, -1);
3743 last_mouse_glyph_frame
= 0;
3748 /* Has the mouse moved off the glyph it was on at the last sighting? */
3749 if (frame
!= last_mouse_glyph_frame
3750 || event
->x
< last_mouse_glyph
.x
3751 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3752 || event
->y
< last_mouse_glyph
.y
3753 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3755 frame
->mouse_moved
= 1;
3756 last_mouse_scroll_bar
= Qnil
;
3757 note_mouse_highlight (frame
, event
->x
, event
->y
);
3758 /* Remember which glyph we're now on. */
3759 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3760 last_mouse_glyph_frame
= frame
;
3768 /************************************************************************
3770 ************************************************************************/
3773 redo_mouse_highlight ()
3775 if (!NILP (last_mouse_motion_frame
)
3776 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3777 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3778 last_mouse_motion_event
.x
,
3779 last_mouse_motion_event
.y
);
3784 /* Return the current position of the mouse.
3785 *FP should be a frame which indicates which display to ask about.
3787 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3788 and *PART to the frame, window, and scroll bar part that the mouse
3789 is over. Set *X and *Y to the portion and whole of the mouse's
3790 position on the scroll bar.
3792 If the mouse movement started elsewhere, set *FP to the frame the
3793 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3796 Set *TIME to the server time-stamp for the time at which the mouse
3797 was at this position.
3799 Don't store anything if we don't have a valid set of values to report.
3801 This clears the mouse_moved flag, so we can wait for the next mouse
3805 XTmouse_position (fp
, insist
, bar_window
, part
, x
, y
, time
)
3808 Lisp_Object
*bar_window
;
3809 enum scroll_bar_part
*part
;
3811 unsigned long *time
;
3817 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3818 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3824 Window dummy_window
;
3827 Lisp_Object frame
, tail
;
3829 /* Clear the mouse-moved flag for every frame on this display. */
3830 FOR_EACH_FRAME (tail
, frame
)
3831 if (FRAME_X_P (XFRAME (frame
))
3832 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3833 XFRAME (frame
)->mouse_moved
= 0;
3835 last_mouse_scroll_bar
= Qnil
;
3837 /* Figure out which root window we're on. */
3838 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3839 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3841 /* The root window which contains the pointer. */
3844 /* Trash which we can't trust if the pointer is on
3845 a different screen. */
3848 /* The position on that root window. */
3851 /* More trash we can't trust. */
3854 /* Modifier keys and pointer buttons, about which
3856 (unsigned int *) &dummy
);
3858 /* Now we have a position on the root; find the innermost window
3859 containing the pointer. */
3863 int parent_x
= 0, parent_y
= 0;
3867 /* XTranslateCoordinates can get errors if the window
3868 structure is changing at the same time this function
3869 is running. So at least we must not crash from them. */
3871 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3873 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3874 && FRAME_LIVE_P (last_mouse_frame
))
3876 /* If mouse was grabbed on a frame, give coords for that frame
3877 even if the mouse is now outside it. */
3878 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3880 /* From-window, to-window. */
3881 root
, FRAME_X_WINDOW (last_mouse_frame
),
3883 /* From-position, to-position. */
3884 root_x
, root_y
, &win_x
, &win_y
,
3888 f1
= last_mouse_frame
;
3894 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3896 /* From-window, to-window. */
3899 /* From-position, to-position. */
3900 root_x
, root_y
, &win_x
, &win_y
,
3905 if (child
== None
|| child
== win
)
3908 /* We don't wan't to know the innermost window. We
3909 want the edit window. For non-Gtk+ the innermost
3910 window is the edit window. For Gtk+ it might not
3911 be. It might be the tool bar for example. */
3912 if (x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
))
3920 /* Now we know that:
3921 win is the innermost window containing the pointer
3922 (XTC says it has no child containing the pointer),
3923 win_x and win_y are the pointer's position in it
3924 (XTC did this the last time through), and
3925 parent_x and parent_y are the pointer's position in win's parent.
3926 (They are what win_x and win_y were when win was child.
3927 If win is the root window, it has no parent, and
3928 parent_{x,y} are invalid, but that's okay, because we'll
3929 never use them in that case.) */
3932 /* We don't wan't to know the innermost window. We
3933 want the edit window. */
3934 f1
= x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3936 /* Is win one of our frames? */
3937 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3940 #ifdef USE_X_TOOLKIT
3941 /* If we end up with the menu bar window, say it's not
3944 && f1
->output_data
.x
->menubar_widget
3945 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3947 #endif /* USE_X_TOOLKIT */
3950 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3953 x_uncatch_errors ();
3955 /* If not, is it one of our scroll bars? */
3958 struct scroll_bar
*bar
;
3960 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3964 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3970 if (f1
== 0 && insist
> 0)
3971 f1
= SELECTED_FRAME ();
3975 /* Ok, we found a frame. Store all the values.
3976 last_mouse_glyph is a rectangle used to reduce the
3977 generation of mouse events. To not miss any motion
3978 events, we must divide the frame into rectangles of the
3979 size of the smallest character that could be displayed
3980 on it, i.e. into the same rectangles that matrices on
3981 the frame are divided into. */
3983 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3984 last_mouse_glyph_frame
= f1
;
3989 XSETINT (*x
, win_x
);
3990 XSETINT (*y
, win_y
);
3991 *time
= last_mouse_movement_time
;
4001 /***********************************************************************
4003 ***********************************************************************/
4005 /* Scroll bar support. */
4007 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
4009 This can be called in GC, so we have to make sure to strip off mark
4012 static struct scroll_bar
*
4013 x_window_to_scroll_bar (display
, window_id
)
4019 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4020 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4021 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4023 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4025 Lisp_Object frame
, bar
, condemned
;
4027 frame
= XCAR (tail
);
4028 /* All elements of Vframe_list should be frames. */
4029 if (! FRAMEP (frame
))
4032 if (! FRAME_X_P (XFRAME (frame
)))
4035 /* Scan this frame's scroll bar list for a scroll bar with the
4037 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4038 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4039 /* This trick allows us to search both the ordinary and
4040 condemned scroll bar lists with one loop. */
4041 ! NILP (bar
) || (bar
= condemned
,
4044 bar
= XSCROLL_BAR (bar
)->next
)
4045 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4046 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4047 return XSCROLL_BAR (bar
);
4054 #if defined USE_LUCID
4056 /* Return the Lucid menu bar WINDOW is part of. Return null
4057 if WINDOW is not part of a menu bar. */
4060 x_window_to_menu_bar (window
)
4065 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4067 if (FRAME_X_P (XFRAME (XCAR (tail
))))
4069 Lisp_Object frame
= XCAR (tail
);
4070 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4072 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4080 #endif /* USE_LUCID */
4083 /************************************************************************
4085 ************************************************************************/
4087 #ifdef USE_TOOLKIT_SCROLL_BARS
4089 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
4090 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
4091 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
4092 struct scroll_bar
*));
4093 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4097 /* Lisp window being scrolled. Set when starting to interact with
4098 a toolkit scroll bar, reset to nil when ending the interaction. */
4100 static Lisp_Object window_being_scrolled
;
4102 /* Last scroll bar part sent in xm_scroll_callback. */
4104 static int last_scroll_bar_part
;
4106 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4107 that movements of 1/20 of the screen size are mapped to up/down. */
4110 /* Id of action hook installed for scroll bars. */
4112 static XtActionHookId action_hook_id
;
4114 static Boolean xaw3d_arrow_scroll
;
4116 /* Whether the drag scrolling maintains the mouse at the top of the
4117 thumb. If not, resizing the thumb needs to be done more carefully
4118 to avoid jerkyness. */
4120 static Boolean xaw3d_pick_top
;
4122 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4123 bars are used.. The hook is responsible for detecting when
4124 the user ends an interaction with the scroll bar, and generates
4125 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4128 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
4131 XtPointer client_data
;
4135 Cardinal
*num_params
;
4141 scroll_bar_p
= XmIsScrollBar (widget
);
4142 end_action
= "Release";
4143 #else /* !USE_MOTIF i.e. use Xaw */
4144 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4145 end_action
= "EndScroll";
4146 #endif /* USE_MOTIF */
4149 && strcmp (action_name
, end_action
) == 0
4150 && WINDOWP (window_being_scrolled
))
4154 x_send_scroll_bar_event (window_being_scrolled
,
4155 scroll_bar_end_scroll
, 0, 0);
4156 w
= XWINDOW (window_being_scrolled
);
4158 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4160 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4161 /* The thumb size is incorrect while dragging: fix it. */
4162 set_vertical_scroll_bar (w
);
4164 window_being_scrolled
= Qnil
;
4165 last_scroll_bar_part
= -1;
4167 /* Xt timeouts no longer needed. */
4168 toolkit_scroll_bar_interaction
= 0;
4171 #endif /* not USE_GTK */
4173 /* A vector of windows used for communication between
4174 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4176 static struct window
**scroll_bar_windows
;
4177 static int scroll_bar_windows_size
;
4180 /* Send a client message with message type Xatom_Scrollbar for a
4181 scroll action to the frame of WINDOW. PART is a value identifying
4182 the part of the scroll bar that was clicked on. PORTION is the
4183 amount to scroll of a whole of WHOLE. */
4186 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4188 int part
, portion
, whole
;
4191 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4192 struct window
*w
= XWINDOW (window
);
4193 struct frame
*f
= XFRAME (w
->frame
);
4198 /* Construct a ClientMessage event to send to the frame. */
4199 ev
->type
= ClientMessage
;
4200 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4201 ev
->display
= FRAME_X_DISPLAY (f
);
4202 ev
->window
= FRAME_X_WINDOW (f
);
4205 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4206 not enough to store a pointer or Lisp_Object on a 64 bit system.
4207 So, store the window in scroll_bar_windows and pass the index
4208 into that array in the event. */
4209 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4210 if (scroll_bar_windows
[i
] == NULL
)
4213 if (i
== scroll_bar_windows_size
)
4215 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4216 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4217 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4219 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4221 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4222 scroll_bar_windows_size
= new_size
;
4225 scroll_bar_windows
[i
] = w
;
4226 ev
->data
.l
[0] = (long) i
;
4227 ev
->data
.l
[1] = (long) part
;
4228 ev
->data
.l
[2] = (long) 0;
4229 ev
->data
.l
[3] = (long) portion
;
4230 ev
->data
.l
[4] = (long) whole
;
4232 /* Make Xt timeouts work while the scroll bar is active. */
4233 toolkit_scroll_bar_interaction
= 1;
4234 #ifdef USE_X_TOOLKIT
4235 x_activate_timeout_atimer ();
4238 /* Setting the event mask to zero means that the message will
4239 be sent to the client that created the window, and if that
4240 window no longer exists, no event will be sent. */
4241 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4246 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4250 x_scroll_bar_to_input_event (event
, ievent
)
4252 struct input_event
*ievent
;
4254 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4259 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4260 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4262 XSETWINDOW (window
, w
);
4263 f
= XFRAME (w
->frame
);
4265 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4266 ievent
->frame_or_window
= window
;
4269 ievent
->timestamp
= CurrentTime
;
4271 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4273 ievent
->part
= ev
->data
.l
[1];
4274 ievent
->code
= ev
->data
.l
[2];
4275 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4276 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4277 ievent
->modifiers
= 0;
4283 /* Minimum and maximum values used for Motif scroll bars. */
4285 #define XM_SB_MAX 10000000
4288 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4289 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4290 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4293 xm_scroll_callback (widget
, client_data
, call_data
)
4295 XtPointer client_data
, call_data
;
4297 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4298 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4299 int part
= -1, whole
= 0, portion
= 0;
4303 case XmCR_DECREMENT
:
4304 bar
->dragging
= Qnil
;
4305 part
= scroll_bar_up_arrow
;
4308 case XmCR_INCREMENT
:
4309 bar
->dragging
= Qnil
;
4310 part
= scroll_bar_down_arrow
;
4313 case XmCR_PAGE_DECREMENT
:
4314 bar
->dragging
= Qnil
;
4315 part
= scroll_bar_above_handle
;
4318 case XmCR_PAGE_INCREMENT
:
4319 bar
->dragging
= Qnil
;
4320 part
= scroll_bar_below_handle
;
4324 bar
->dragging
= Qnil
;
4325 part
= scroll_bar_to_top
;
4328 case XmCR_TO_BOTTOM
:
4329 bar
->dragging
= Qnil
;
4330 part
= scroll_bar_to_bottom
;
4337 /* Get the slider size. */
4339 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4342 whole
= XM_SB_MAX
- slider_size
;
4343 portion
= min (cs
->value
, whole
);
4344 part
= scroll_bar_handle
;
4345 bar
->dragging
= make_number (cs
->value
);
4349 case XmCR_VALUE_CHANGED
:
4355 window_being_scrolled
= bar
->window
;
4356 last_scroll_bar_part
= part
;
4357 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4361 #elif defined USE_GTK
4363 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4364 bar widget. DATA is a pointer to the scroll_bar structure. */
4367 xg_scroll_callback (widget
, data
)
4371 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4377 int part
= -1, whole
= 0, portion
= 0;
4378 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4380 position
= gtk_adjustment_get_value (adj
);
4382 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4385 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4387 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4393 if (xg_ignore_gtk_scrollbar
) return;
4395 diff
= (int) (position
- previous
);
4397 if (diff
== (int) adj
->step_increment
)
4399 part
= scroll_bar_down_arrow
;
4400 bar
->dragging
= Qnil
;
4402 else if (-diff
== (int) adj
->step_increment
)
4404 part
= scroll_bar_up_arrow
;
4405 bar
->dragging
= Qnil
;
4407 else if (diff
== (int) adj
->page_increment
)
4409 part
= scroll_bar_below_handle
;
4410 bar
->dragging
= Qnil
;
4412 else if (-diff
== (int) adj
->page_increment
)
4414 part
= scroll_bar_above_handle
;
4415 bar
->dragging
= Qnil
;
4419 part
= scroll_bar_handle
;
4420 whole
= adj
->upper
- adj
->page_size
;
4421 portion
= min ((int)position
, whole
);
4422 bar
->dragging
= make_number ((int)portion
);
4427 window_being_scrolled
= bar
->window
;
4428 last_scroll_bar_part
= part
;
4429 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4433 #else /* not USE_GTK and not USE_MOTIF */
4435 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4436 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4437 scroll bar struct. CALL_DATA is a pointer to a float saying where
4441 xaw_jump_callback (widget
, client_data
, call_data
)
4443 XtPointer client_data
, call_data
;
4445 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4446 float top
= *(float *) call_data
;
4448 int whole
, portion
, height
;
4451 /* Get the size of the thumb, a value between 0 and 1. */
4453 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4457 portion
= shown
< 1 ? top
* whole
: 0;
4459 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4460 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4461 the bottom, so we force the scrolling whenever we see that we're
4462 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4463 we try to ensure that we always stay two pixels away from the
4465 part
= scroll_bar_down_arrow
;
4467 part
= scroll_bar_handle
;
4469 window_being_scrolled
= bar
->window
;
4470 bar
->dragging
= make_number (portion
);
4471 last_scroll_bar_part
= part
;
4472 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4476 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4477 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4478 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4479 the scroll bar. CALL_DATA is an integer specifying the action that
4480 has taken place. Its magnitude is in the range 0..height of the
4481 scroll bar. Negative values mean scroll towards buffer start.
4482 Values < height of scroll bar mean line-wise movement. */
4485 xaw_scroll_callback (widget
, client_data
, call_data
)
4487 XtPointer client_data
, call_data
;
4489 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4490 /* The position really is stored cast to a pointer. */
4491 int position
= (long) call_data
;
4495 /* Get the height of the scroll bar. */
4497 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4500 if (eabs (position
) >= height
)
4501 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4503 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4504 it maps line-movement to call_data = max(5, height/20). */
4505 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4506 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4508 part
= scroll_bar_move_ratio
;
4510 window_being_scrolled
= bar
->window
;
4511 bar
->dragging
= Qnil
;
4512 last_scroll_bar_part
= part
;
4513 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4516 #endif /* not USE_GTK and not USE_MOTIF */
4518 #define SCROLL_BAR_NAME "verticalScrollBar"
4520 /* Create the widget for scroll bar BAR on frame F. Record the widget
4521 and X window of the scroll bar in BAR. */
4525 x_create_toolkit_scroll_bar (f
, bar
)
4527 struct scroll_bar
*bar
;
4529 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4532 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4537 #else /* not USE_GTK */
4540 x_create_toolkit_scroll_bar (f
, bar
)
4542 struct scroll_bar
*bar
;
4548 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4549 unsigned long pixel
;
4554 /* Set resources. Create the widget. */
4555 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4556 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4557 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4558 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4559 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4560 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4561 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4563 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4566 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4570 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4573 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4577 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4578 scroll_bar_name
, av
, ac
);
4580 /* Add one callback for everything that can happen. */
4581 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4583 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4585 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4587 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4589 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4591 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4593 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4596 /* Realize the widget. Only after that is the X window created. */
4597 XtRealizeWidget (widget
);
4599 /* Set the cursor to an arrow. I didn't find a resource to do that.
4600 And I'm wondering why it hasn't an arrow cursor by default. */
4601 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4602 f
->output_data
.x
->nontext_cursor
);
4604 #else /* !USE_MOTIF i.e. use Xaw */
4606 /* Set resources. Create the widget. The background of the
4607 Xaw3d scroll bar widget is a little bit light for my taste.
4608 We don't alter it here to let users change it according
4609 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4610 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4611 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4612 /* For smoother scrolling with Xaw3d -sm */
4613 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4615 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4618 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4622 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4625 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4629 /* Top/bottom shadow colors. */
4631 /* Allocate them, if necessary. */
4632 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4634 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4635 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4636 &pixel
, 1.2, 0x8000))
4638 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4640 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4642 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4643 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4644 &pixel
, 0.6, 0x4000))
4646 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4649 #ifdef XtNbeNiceToColormap
4650 /* Tell the toolkit about them. */
4651 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4652 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4653 /* We tried to allocate a color for the top/bottom shadow, and
4654 failed, so tell Xaw3d to use dithering instead. */
4656 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4660 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4661 be more consistent with other emacs 3d colors, and since Xaw3d is
4662 not good at dealing with allocation failure. */
4664 /* This tells Xaw3d to use real colors instead of dithering for
4666 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4669 /* Specify the colors. */
4670 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4673 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4676 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4679 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4685 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4686 f
->output_data
.x
->edit_widget
, av
, ac
);
4690 char *val
= initial
;
4691 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4692 #ifdef XtNarrowScrollbars
4693 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4695 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4696 if (xaw3d_arrow_scroll
|| val
== initial
)
4697 { /* ARROW_SCROLL */
4698 xaw3d_arrow_scroll
= True
;
4699 /* Isn't that just a personal preference ? --Stef */
4700 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4704 /* Define callbacks. */
4705 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4706 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4709 /* Realize the widget. Only after that is the X window created. */
4710 XtRealizeWidget (widget
);
4712 #endif /* !USE_MOTIF */
4714 /* Install an action hook that lets us detect when the user
4715 finishes interacting with a scroll bar. */
4716 if (action_hook_id
== 0)
4717 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4719 /* Remember X window and widget in the scroll bar vector. */
4720 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4721 xwindow
= XtWindow (widget
);
4722 bar
->x_window
= xwindow
;
4726 #endif /* not USE_GTK */
4729 /* Set the thumb size and position of scroll bar BAR. We are currently
4730 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4734 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4735 struct scroll_bar
*bar
;
4736 int portion
, position
, whole
;
4738 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4741 #else /* not USE_GTK */
4743 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4744 struct scroll_bar
*bar
;
4745 int portion
, position
, whole
;
4747 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4748 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4755 /* We use an estimate of 30 chars per line rather than the real
4756 `portion' value. This has the disadvantage that the thumb size
4757 is not very representative, but it makes our life a lot easier.
4758 Otherwise, we have to constantly adjust the thumb size, which
4759 we can't always do quickly enough: while dragging, the size of
4760 the thumb might prevent the user from dragging the thumb all the
4761 way to the end. but Motif and some versions of Xaw3d don't allow
4762 updating the thumb size while dragging. Also, even if we can update
4763 its size, the update will often happen too late.
4764 If you don't believe it, check out revision 1.650 of xterm.c to see
4765 what hoops we were going through and the still poor behavior we got. */
4766 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4767 /* When the thumb is at the bottom, position == whole.
4768 So we need to increase `whole' to make space for the thumb. */
4775 top
= (float) position
/ whole
;
4776 shown
= (float) portion
/ whole
;
4779 if (NILP (bar
->dragging
))
4783 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4784 is the scroll bar's maximum and MIN is the scroll bar's minimum
4786 size
= shown
* XM_SB_MAX
;
4787 size
= min (size
, XM_SB_MAX
);
4788 size
= max (size
, 1);
4790 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4791 value
= top
* XM_SB_MAX
;
4792 value
= min (value
, XM_SB_MAX
- size
);
4794 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4796 #else /* !USE_MOTIF i.e. use Xaw */
4802 top
= (float) position
/ whole
;
4803 shown
= (float) portion
/ whole
;
4807 float old_top
, old_shown
;
4809 XtVaGetValues (widget
,
4810 XtNtopOfThumb
, &old_top
,
4811 XtNshown
, &old_shown
,
4815 /* Massage the top+shown values. */
4816 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4817 top
= max (0, min (1, top
));
4820 /* Keep two pixels available for moving the thumb down. */
4821 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4823 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4824 check that your system's configuration file contains a define
4825 for `NARROWPROTO'. See s/freebsd.h for an example. */
4826 if (top
!= old_top
|| shown
!= old_shown
)
4828 if (NILP (bar
->dragging
))
4829 XawScrollbarSetThumb (widget
, top
, shown
);
4832 /* Try to make the scrolling a tad smoother. */
4833 if (!xaw3d_pick_top
)
4834 shown
= min (shown
, old_shown
);
4836 XawScrollbarSetThumb (widget
, top
, shown
);
4840 #endif /* !USE_MOTIF */
4844 #endif /* not USE_GTK */
4846 #endif /* USE_TOOLKIT_SCROLL_BARS */
4850 /************************************************************************
4851 Scroll bars, general
4852 ************************************************************************/
4854 /* Create a scroll bar and return the scroll bar vector for it. W is
4855 the Emacs window on which to create the scroll bar. TOP, LEFT,
4856 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4859 static struct scroll_bar
*
4860 x_scroll_bar_create (w
, top
, left
, width
, height
)
4862 int top
, left
, width
, height
;
4864 struct frame
*f
= XFRAME (w
->frame
);
4865 struct scroll_bar
*bar
4866 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4870 #ifdef USE_TOOLKIT_SCROLL_BARS
4871 x_create_toolkit_scroll_bar (f
, bar
);
4872 #else /* not USE_TOOLKIT_SCROLL_BARS */
4874 XSetWindowAttributes a
;
4878 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4879 if (a
.background_pixel
== -1)
4880 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4882 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4883 | ButtonMotionMask
| PointerMotionHintMask
4885 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4887 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4889 /* Clear the area of W that will serve as a scroll bar. This is
4890 for the case that a window has been split horizontally. In
4891 this case, no clear_frame is generated to reduce flickering. */
4892 if (width
> 0 && height
> 0)
4893 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4895 window_box_height (w
), False
);
4897 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4898 /* Position and size of scroll bar. */
4899 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4901 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4903 /* Border width, depth, class, and visual. */
4910 bar
->x_window
= window
;
4912 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4914 XSETWINDOW (bar
->window
, w
);
4918 bar
->height
= height
;
4921 bar
->dragging
= Qnil
;
4922 bar
->fringe_extended_p
= 0;
4924 /* Add bar to its frame's list of scroll bars. */
4925 bar
->next
= FRAME_SCROLL_BARS (f
);
4927 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4928 if (!NILP (bar
->next
))
4929 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4931 /* Map the window/widget. */
4932 #ifdef USE_TOOLKIT_SCROLL_BARS
4935 xg_update_scrollbar_pos (f
,
4938 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4939 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4941 xg_show_scroll_bar (bar
->x_window
);
4942 #else /* not USE_GTK */
4943 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4944 XtConfigureWidget (scroll_bar
,
4945 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4947 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4948 max (height
, 1), 0);
4949 XtMapWidget (scroll_bar
);
4950 #endif /* not USE_GTK */
4952 #else /* not USE_TOOLKIT_SCROLL_BARS */
4953 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
4954 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4961 #ifndef USE_TOOLKIT_SCROLL_BARS
4963 /* Draw BAR's handle in the proper position.
4965 If the handle is already drawn from START to END, don't bother
4966 redrawing it, unless REBUILD is non-zero; in that case, always
4967 redraw it. (REBUILD is handy for drawing the handle after expose
4970 Normally, we want to constrain the start and end of the handle to
4971 fit inside its rectangle, but if the user is dragging the scroll
4972 bar handle, we want to let them drag it down all the way, so that
4973 the bar's top is as far down as it goes; otherwise, there's no way
4974 to move to the very end of the buffer. */
4977 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4978 struct scroll_bar
*bar
;
4982 int dragging
= ! NILP (bar
->dragging
);
4983 Window w
= bar
->x_window
;
4984 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4985 GC gc
= f
->output_data
.x
->normal_gc
;
4987 /* If the display is already accurate, do nothing. */
4989 && start
== bar
->start
4996 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
4997 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
4998 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5000 /* Make sure the values are reasonable, and try to preserve
5001 the distance between start and end. */
5003 int length
= end
- start
;
5007 else if (start
> top_range
)
5009 end
= start
+ length
;
5013 else if (end
> top_range
&& ! dragging
)
5017 /* Store the adjusted setting in the scroll bar. */
5021 /* Clip the end position, just for display. */
5022 if (end
> top_range
)
5025 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5026 below top positions, to make sure the handle is always at least
5027 that many pixels tall. */
5028 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5030 /* Draw the empty space above the handle. Note that we can't clear
5031 zero-height areas; that means "clear to end of window." */
5033 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5034 /* x, y, width, height, and exposures. */
5035 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5036 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5037 inside_width
, start
,
5040 /* Change to proper foreground color if one is specified. */
5041 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5042 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5043 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5045 /* Draw the handle itself. */
5046 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5047 /* x, y, width, height */
5048 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5049 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5050 inside_width
, end
- start
);
5052 /* Restore the foreground color of the GC if we changed it above. */
5053 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5054 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5055 FRAME_FOREGROUND_PIXEL (f
));
5057 /* Draw the empty space below the handle. Note that we can't
5058 clear zero-height areas; that means "clear to end of window." */
5059 if (end
< inside_height
)
5060 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5061 /* x, y, width, height, and exposures. */
5062 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5063 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5064 inside_width
, inside_height
- end
,
5072 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5074 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5078 x_scroll_bar_remove (bar
)
5079 struct scroll_bar
*bar
;
5081 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5084 #ifdef USE_TOOLKIT_SCROLL_BARS
5086 xg_remove_scroll_bar (f
, bar
->x_window
);
5087 #else /* not USE_GTK */
5088 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5089 #endif /* not USE_GTK */
5091 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5094 /* Disassociate this scroll bar from its window. */
5095 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
5101 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5102 that we are displaying PORTION characters out of a total of WHOLE
5103 characters, starting at POSITION. If WINDOW has no scroll bar,
5107 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
5109 int portion
, whole
, position
;
5111 struct frame
*f
= XFRAME (w
->frame
);
5112 struct scroll_bar
*bar
;
5113 int top
, height
, left
, sb_left
, width
, sb_width
;
5114 int window_y
, window_height
;
5115 #ifdef USE_TOOLKIT_SCROLL_BARS
5116 int fringe_extended_p
;
5119 /* Get window dimensions. */
5120 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5122 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5123 height
= window_height
;
5125 /* Compute the left edge of the scroll bar area. */
5126 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5128 /* Compute the width of the scroll bar which might be less than
5129 the width of the area reserved for the scroll bar. */
5130 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5131 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5135 /* Compute the left edge of the scroll bar. */
5136 #ifdef USE_TOOLKIT_SCROLL_BARS
5137 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5138 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5140 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5142 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5143 sb_left
= left
+ width
- sb_width
;
5148 #ifdef USE_TOOLKIT_SCROLL_BARS
5149 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5150 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5151 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5152 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5153 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5155 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5156 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5157 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5158 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5161 /* Does the scroll bar exist yet? */
5162 if (NILP (w
->vertical_scroll_bar
))
5164 if (width
> 0 && height
> 0)
5167 #ifdef USE_TOOLKIT_SCROLL_BARS
5168 if (fringe_extended_p
)
5169 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5170 sb_left
, top
, sb_width
, height
, False
);
5173 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5174 left
, top
, width
, height
, False
);
5178 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5182 /* It may just need to be moved and resized. */
5183 unsigned int mask
= 0;
5185 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5189 if (sb_left
!= bar
->left
)
5191 if (top
!= bar
->top
)
5193 if (sb_width
!= bar
->width
)
5195 if (height
!= bar
->height
)
5198 #ifdef USE_TOOLKIT_SCROLL_BARS
5200 /* Move/size the scroll bar widget. */
5201 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5203 /* Since toolkit scroll bars are smaller than the space reserved
5204 for them on the frame, we have to clear "under" them. */
5205 if (width
> 0 && height
> 0)
5207 if (fringe_extended_p
)
5208 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5209 sb_left
, top
, sb_width
, height
, False
);
5211 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5212 left
, top
, width
, height
, False
);
5215 xg_update_scrollbar_pos (f
,
5218 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5219 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5221 #else /* not USE_GTK */
5222 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5223 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5225 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5226 max (height
, 1), 0);
5227 #endif /* not USE_GTK */
5229 #else /* not USE_TOOLKIT_SCROLL_BARS */
5231 /* Clear areas not covered by the scroll bar because of
5232 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5233 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5235 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5236 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5238 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5239 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5240 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5244 /* Clear areas not covered by the scroll bar because it's not as
5245 wide as the area reserved for it. This makes sure a
5246 previous mode line display is cleared after C-x 2 C-x 1, for
5249 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5250 int rest
= area_width
- sb_width
;
5251 if (rest
> 0 && height
> 0)
5253 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5254 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5255 left
+ area_width
- rest
, top
,
5256 rest
, height
, False
);
5258 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5259 left
, top
, rest
, height
, False
);
5263 /* Move/size the scroll bar window. */
5268 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5270 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5272 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5276 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5278 /* Remember new settings. */
5279 bar
->left
= sb_left
;
5281 bar
->width
= sb_width
;
5282 bar
->height
= height
;
5287 #ifdef USE_TOOLKIT_SCROLL_BARS
5288 bar
->fringe_extended_p
= fringe_extended_p
;
5290 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5291 #else /* not USE_TOOLKIT_SCROLL_BARS */
5292 /* Set the scroll bar's current state, unless we're currently being
5294 if (NILP (bar
->dragging
))
5296 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5299 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5302 int start
= ((double) position
* top_range
) / whole
;
5303 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5304 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5307 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5309 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5313 /* The following three hooks are used when we're doing a thorough
5314 redisplay of the frame. We don't explicitly know which scroll bars
5315 are going to be deleted, because keeping track of when windows go
5316 away is a real pain - "Can you say set-window-configuration, boys
5317 and girls?" Instead, we just assert at the beginning of redisplay
5318 that *all* scroll bars are to be removed, and then save a scroll bar
5319 from the fiery pit when we actually redisplay its window. */
5321 /* Arrange for all scroll bars on FRAME to be removed at the next call
5322 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5323 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5326 XTcondemn_scroll_bars (frame
)
5329 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5330 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5333 bar
= FRAME_SCROLL_BARS (frame
);
5334 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5335 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5336 XSCROLL_BAR (bar
)->prev
= Qnil
;
5337 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5338 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5339 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5344 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5345 Note that WINDOW isn't necessarily condemned at all. */
5348 XTredeem_scroll_bar (window
)
5349 struct window
*window
;
5351 struct scroll_bar
*bar
;
5354 /* We can't redeem this window's scroll bar if it doesn't have one. */
5355 if (NILP (window
->vertical_scroll_bar
))
5358 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5360 /* Unlink it from the condemned list. */
5361 f
= XFRAME (WINDOW_FRAME (window
));
5362 if (NILP (bar
->prev
))
5364 /* If the prev pointer is nil, it must be the first in one of
5366 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5367 /* It's not condemned. Everything's fine. */
5369 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5370 window
->vertical_scroll_bar
))
5371 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5373 /* If its prev pointer is nil, it must be at the front of
5374 one or the other! */
5378 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5380 if (! NILP (bar
->next
))
5381 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5383 bar
->next
= FRAME_SCROLL_BARS (f
);
5385 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5386 if (! NILP (bar
->next
))
5387 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5390 /* Remove all scroll bars on FRAME that haven't been saved since the
5391 last call to `*condemn_scroll_bars_hook'. */
5394 XTjudge_scroll_bars (f
)
5397 Lisp_Object bar
, next
;
5399 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5401 /* Clear out the condemned list now so we won't try to process any
5402 more events on the hapless scroll bars. */
5403 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5405 for (; ! NILP (bar
); bar
= next
)
5407 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5409 x_scroll_bar_remove (b
);
5412 b
->next
= b
->prev
= Qnil
;
5415 /* Now there should be no references to the condemned scroll bars,
5416 and they should get garbage-collected. */
5420 #ifndef USE_TOOLKIT_SCROLL_BARS
5421 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5422 is a no-op when using toolkit scroll bars.
5424 This may be called from a signal handler, so we have to ignore GC
5428 x_scroll_bar_expose (bar
, event
)
5429 struct scroll_bar
*bar
;
5432 Window w
= bar
->x_window
;
5433 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5434 GC gc
= f
->output_data
.x
->normal_gc
;
5435 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5439 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5441 /* Switch to scroll bar foreground color. */
5442 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5443 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5444 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5446 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5447 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5449 /* x, y, width, height */
5451 bar
->width
- 1 - width_trim
- width_trim
,
5454 /* Restore the foreground color of the GC if we changed it above. */
5455 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5456 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5457 FRAME_FOREGROUND_PIXEL (f
));
5462 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5464 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5465 is set to something other than NO_EVENT, it is enqueued.
5467 This may be called from a signal handler, so we have to ignore GC
5472 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5473 struct scroll_bar
*bar
;
5475 struct input_event
*emacs_event
;
5477 if (! WINDOWP (bar
->window
))
5480 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5481 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5482 emacs_event
->modifiers
5483 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5484 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5485 event
->xbutton
.state
)
5486 | (event
->type
== ButtonRelease
5489 emacs_event
->frame_or_window
= bar
->window
;
5490 emacs_event
->arg
= Qnil
;
5491 emacs_event
->timestamp
= event
->xbutton
.time
;
5494 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5495 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5498 if (y
> top_range
) y
= top_range
;
5501 emacs_event
->part
= scroll_bar_above_handle
;
5502 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5503 emacs_event
->part
= scroll_bar_handle
;
5505 emacs_event
->part
= scroll_bar_below_handle
;
5507 #ifndef USE_TOOLKIT_SCROLL_BARS
5508 /* If the user has released the handle, set it to its final position. */
5509 if (event
->type
== ButtonRelease
5510 && ! NILP (bar
->dragging
))
5512 int new_start
= y
- XINT (bar
->dragging
);
5513 int new_end
= new_start
+ bar
->end
- bar
->start
;
5515 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5516 bar
->dragging
= Qnil
;
5520 XSETINT (emacs_event
->x
, y
);
5521 XSETINT (emacs_event
->y
, top_range
);
5525 #ifndef USE_TOOLKIT_SCROLL_BARS
5527 /* Handle some mouse motion while someone is dragging the scroll bar.
5529 This may be called from a signal handler, so we have to ignore GC
5533 x_scroll_bar_note_movement (bar
, event
)
5534 struct scroll_bar
*bar
;
5537 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5539 last_mouse_movement_time
= event
->xmotion
.time
;
5542 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5544 /* If we're dragging the bar, display it. */
5545 if (! NILP (bar
->dragging
))
5547 /* Where should the handle be now? */
5548 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5550 if (new_start
!= bar
->start
)
5552 int new_end
= new_start
+ bar
->end
- bar
->start
;
5554 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5559 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5561 /* Return information to the user about the current position of the mouse
5562 on the scroll bar. */
5565 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5567 Lisp_Object
*bar_window
;
5568 enum scroll_bar_part
*part
;
5570 unsigned long *time
;
5572 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5573 Window w
= bar
->x_window
;
5574 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5576 Window dummy_window
;
5578 unsigned int dummy_mask
;
5582 /* Get the mouse's position relative to the scroll bar window, and
5584 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5586 /* Root, child, root x and root y. */
5587 &dummy_window
, &dummy_window
,
5588 &dummy_coord
, &dummy_coord
,
5590 /* Position relative to scroll bar. */
5593 /* Mouse buttons and modifier keys. */
5599 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5601 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5603 if (! NILP (bar
->dragging
))
5604 win_y
-= XINT (bar
->dragging
);
5608 if (win_y
> top_range
)
5612 *bar_window
= bar
->window
;
5614 if (! NILP (bar
->dragging
))
5615 *part
= scroll_bar_handle
;
5616 else if (win_y
< bar
->start
)
5617 *part
= scroll_bar_above_handle
;
5618 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5619 *part
= scroll_bar_handle
;
5621 *part
= scroll_bar_below_handle
;
5623 XSETINT (*x
, win_y
);
5624 XSETINT (*y
, top_range
);
5627 last_mouse_scroll_bar
= Qnil
;
5630 *time
= last_mouse_movement_time
;
5636 /* The screen has been cleared so we may have changed foreground or
5637 background colors, and the scroll bars may need to be redrawn.
5638 Clear out the scroll bars, and ask for expose events, so we can
5642 x_scroll_bar_clear (f
)
5645 #ifndef USE_TOOLKIT_SCROLL_BARS
5648 /* We can have scroll bars even if this is 0,
5649 if we just turned off scroll bar mode.
5650 But in that case we should not clear them. */
5651 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5652 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5653 bar
= XSCROLL_BAR (bar
)->next
)
5654 XClearArea (FRAME_X_DISPLAY (f
),
5655 XSCROLL_BAR (bar
)->x_window
,
5657 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5661 /* The main X event-reading loop - XTread_socket. */
5663 /* This holds the state XLookupString needs to implement dead keys
5664 and other tricks known as "compose processing". _X Window System_
5665 says that a portable program can't use this, but Stephen Gildea assures
5666 me that letting the compiler initialize it to zeros will work okay.
5668 This must be defined outside of XTread_socket, for the same reasons
5669 given for enter_timestamp, above. */
5671 static XComposeStatus compose_status
;
5673 /* Record the last 100 characters stored
5674 to help debug the loss-of-chars-during-GC problem. */
5676 static int temp_index
;
5677 static short temp_buffer
[100];
5679 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5680 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5682 temp_buffer[temp_index++] = (keysym)
5684 /* Set this to nonzero to fake an "X I/O error"
5685 on a particular display. */
5687 struct x_display_info
*XTread_socket_fake_io_error
;
5689 /* When we find no input here, we occasionally do a no-op command
5690 to verify that the X server is still running and we can still talk with it.
5691 We try all the open displays, one by one.
5692 This variable is used for cycling thru the displays. */
5694 static struct x_display_info
*next_noop_dpyinfo
;
5696 #define SET_SAVED_MENU_EVENT(size) \
5699 if (f->output_data.x->saved_menu_event == 0) \
5700 f->output_data.x->saved_menu_event \
5701 = (XEvent *) xmalloc (sizeof (XEvent)); \
5702 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5703 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5704 XSETFRAME (inev.ie.frame_or_window, f); \
5708 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5709 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5719 /* Filter events for the current X input method.
5720 DPYINFO is the display this event is for.
5721 EVENT is the X event to filter.
5723 Returns non-zero if the event was filtered, caller shall not process
5725 Returns zero if event is wasn't filtered. */
5729 x_filter_event (dpyinfo
, event
)
5730 struct x_display_info
*dpyinfo
;
5733 /* XFilterEvent returns non-zero if the input method has
5734 consumed the event. We pass the frame's X window to
5735 XFilterEvent because that's the one for which the IC
5738 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5739 event
->xclient
.window
);
5741 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5746 static int current_count
;
5747 static int current_finish
;
5748 static struct input_event
*current_hold_quit
;
5750 /* This is the filter function invoked by the GTK event loop.
5751 It is invoked before the XEvent is translated to a GdkEvent,
5752 so we have a chance to act on the event before GTK. */
5753 static GdkFilterReturn
5754 event_handler_gdk (gxev
, ev
, data
)
5759 XEvent
*xev
= (XEvent
*) gxev
;
5761 if (current_count
>= 0)
5763 struct x_display_info
*dpyinfo
;
5765 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5768 /* Filter events for the current X input method.
5769 GTK calls XFilterEvent but not for key press and release,
5770 so we do it here. */
5771 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5772 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5773 return GDK_FILTER_REMOVE
;
5777 current_finish
= X_EVENT_NORMAL
;
5781 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5786 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5788 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5789 return GDK_FILTER_REMOVE
;
5791 return GDK_FILTER_CONTINUE
;
5793 #endif /* USE_GTK */
5796 /* Handles the XEvent EVENT on display DPYINFO.
5798 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5799 *FINISH is zero if caller should continue reading events.
5800 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5802 We return the number of characters stored into the buffer. */
5805 handle_one_xevent (dpyinfo
, eventp
, finish
, hold_quit
)
5806 struct x_display_info
*dpyinfo
;
5809 struct input_event
*hold_quit
;
5812 struct input_event ie
;
5813 struct selection_input_event sie
;
5818 struct frame
*f
= NULL
;
5819 struct coding_system coding
;
5820 XEvent event
= *eventp
;
5822 *finish
= X_EVENT_NORMAL
;
5824 EVENT_INIT (inev
.ie
);
5825 inev
.ie
.kind
= NO_EVENT
;
5832 if (event
.xclient
.message_type
5833 == dpyinfo
->Xatom_wm_protocols
5834 && event
.xclient
.format
== 32)
5836 if (event
.xclient
.data
.l
[0]
5837 == dpyinfo
->Xatom_wm_take_focus
)
5839 /* Use x_any_window_to_frame because this
5840 could be the shell widget window
5841 if the frame has no title bar. */
5842 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5844 /* Not quite sure this is needed -pd */
5845 if (f
&& FRAME_XIC (f
))
5846 XSetICFocus (FRAME_XIC (f
));
5848 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5849 instructs the WM to set the input focus automatically for
5850 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5851 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5852 it has set the focus. So, XSetInputFocus below is not
5855 The call to XSetInputFocus below has also caused trouble. In
5856 cases where the XSetInputFocus done by the WM and the one
5857 below are temporally close (on a fast machine), the call
5858 below can generate additional FocusIn events which confuse
5861 /* Since we set WM_TAKE_FOCUS, we must call
5862 XSetInputFocus explicitly. But not if f is null,
5863 since that might be an event for a deleted frame. */
5866 Display
*d
= event
.xclient
.display
;
5867 /* Catch and ignore errors, in case window has been
5868 iconified by a window manager such as GWM. */
5870 XSetInputFocus (d
, event
.xclient
.window
,
5871 /* The ICCCM says this is
5872 the only valid choice. */
5874 event
.xclient
.data
.l
[1]);
5875 /* This is needed to detect the error
5876 if there is an error. */
5878 x_uncatch_errors ();
5880 /* Not certain about handling scroll bars here */
5885 if (event
.xclient
.data
.l
[0]
5886 == dpyinfo
->Xatom_wm_save_yourself
)
5888 /* Save state modify the WM_COMMAND property to
5889 something which can reinstate us. This notifies
5890 the session manager, who's looking for such a
5891 PropertyNotify. Can restart processing when
5892 a keyboard or mouse event arrives. */
5893 /* If we have a session manager, don't set this.
5894 KDE will then start two Emacsen, one for the
5895 session manager and one for this. */
5897 if (! x_session_have_connection ())
5900 f
= x_top_window_to_frame (dpyinfo
,
5901 event
.xclient
.window
);
5902 /* This is just so we only give real data once
5903 for a single Emacs process. */
5904 if (f
== SELECTED_FRAME ())
5905 XSetCommand (FRAME_X_DISPLAY (f
),
5906 event
.xclient
.window
,
5907 initial_argv
, initial_argc
);
5909 XSetCommand (FRAME_X_DISPLAY (f
),
5910 event
.xclient
.window
,
5916 if (event
.xclient
.data
.l
[0]
5917 == dpyinfo
->Xatom_wm_delete_window
)
5919 f
= x_any_window_to_frame (dpyinfo
,
5920 event
.xclient
.window
);
5922 goto OTHER
; /* May be a dialog that is to be removed */
5924 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5925 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5932 if (event
.xclient
.message_type
5933 == dpyinfo
->Xatom_wm_configure_denied
)
5938 if (event
.xclient
.message_type
5939 == dpyinfo
->Xatom_wm_window_moved
)
5942 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5944 new_x
= event
.xclient
.data
.s
[0];
5945 new_y
= event
.xclient
.data
.s
[1];
5949 f
->left_pos
= new_x
;
5956 if (event
.xclient
.message_type
5957 == dpyinfo
->Xatom_editres
)
5959 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5961 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5965 #endif /* HACK_EDITRES */
5967 if ((event
.xclient
.message_type
5968 == dpyinfo
->Xatom_DONE
)
5969 || (event
.xclient
.message_type
5970 == dpyinfo
->Xatom_PAGE
))
5972 /* Ghostview job completed. Kill it. We could
5973 reply with "Next" if we received "Page", but we
5974 currently never do because we are interested in
5975 images, only, which should have 1 page. */
5976 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5977 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5980 x_kill_gs_process (pixmap
, f
);
5981 expose_frame (f
, 0, 0, 0, 0);
5985 #ifdef USE_TOOLKIT_SCROLL_BARS
5986 /* Scroll bar callbacks send a ClientMessage from which
5987 we construct an input_event. */
5988 if (event
.xclient
.message_type
5989 == dpyinfo
->Xatom_Scrollbar
)
5991 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
5992 *finish
= X_EVENT_GOTO_OUT
;
5995 #endif /* USE_TOOLKIT_SCROLL_BARS */
5997 /* XEmbed messages from the embedder (if any). */
5998 if (event
.xclient
.message_type
5999 == dpyinfo
->Xatom_XEMBED
)
6001 enum xembed_message msg
= event
.xclient
.data
.l
[1];
6002 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6003 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6005 *finish
= X_EVENT_GOTO_OUT
;
6009 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6012 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6013 *finish
= X_EVENT_DROP
;
6017 case SelectionNotify
:
6018 last_user_time
= event
.xselection
.time
;
6019 #ifdef USE_X_TOOLKIT
6020 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6022 #endif /* not USE_X_TOOLKIT */
6023 x_handle_selection_notify (&event
.xselection
);
6026 case SelectionClear
: /* Someone has grabbed ownership. */
6027 last_user_time
= event
.xselectionclear
.time
;
6028 #ifdef USE_X_TOOLKIT
6029 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6031 #endif /* USE_X_TOOLKIT */
6033 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
6035 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6036 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6037 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6038 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6039 inev
.ie
.frame_or_window
= Qnil
;
6043 case SelectionRequest
: /* Someone wants our selection. */
6044 last_user_time
= event
.xselectionrequest
.time
;
6045 #ifdef USE_X_TOOLKIT
6046 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6048 #endif /* USE_X_TOOLKIT */
6050 XSelectionRequestEvent
*eventp
6051 = (XSelectionRequestEvent
*) &event
;
6053 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6054 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6055 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6056 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6057 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6058 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6059 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6060 inev
.ie
.frame_or_window
= Qnil
;
6064 case PropertyNotify
:
6065 last_user_time
= event
.xproperty
.time
;
6066 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
6067 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6068 x_handle_net_wm_state (f
, &event
.xproperty
);
6070 x_handle_property_notify (&event
.xproperty
);
6073 case ReparentNotify
:
6074 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6078 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6079 x_real_positions (f
, &x
, &y
);
6083 /* Perhaps reparented due to a WM restart. Reset this. */
6084 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6085 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6090 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6094 /* This seems to be needed for GTK 2.6. */
6095 x_clear_area (event
.xexpose
.display
,
6096 event
.xexpose
.window
,
6097 event
.xexpose
.x
, event
.xexpose
.y
,
6098 event
.xexpose
.width
, event
.xexpose
.height
,
6101 if (f
->async_visible
== 0)
6103 f
->async_visible
= 1;
6104 f
->async_iconified
= 0;
6105 f
->output_data
.x
->has_been_visible
= 1;
6106 SET_FRAME_GARBAGED (f
);
6110 event
.xexpose
.x
, event
.xexpose
.y
,
6111 event
.xexpose
.width
, event
.xexpose
.height
);
6115 #ifndef USE_TOOLKIT_SCROLL_BARS
6116 struct scroll_bar
*bar
;
6118 #if defined USE_LUCID
6119 /* Submenus of the Lucid menu bar aren't widgets
6120 themselves, so there's no way to dispatch events
6121 to them. Recognize this case separately. */
6124 = x_window_to_menu_bar (event
.xexpose
.window
);
6126 xlwmenu_redisplay (widget
);
6128 #endif /* USE_LUCID */
6130 #ifdef USE_TOOLKIT_SCROLL_BARS
6131 /* Dispatch event to the widget. */
6133 #else /* not USE_TOOLKIT_SCROLL_BARS */
6134 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6135 event
.xexpose
.window
);
6138 x_scroll_bar_expose (bar
, &event
);
6139 #ifdef USE_X_TOOLKIT
6142 #endif /* USE_X_TOOLKIT */
6143 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6147 case GraphicsExpose
: /* This occurs when an XCopyArea's
6148 source area was obscured or not
6150 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6154 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6155 event
.xgraphicsexpose
.width
,
6156 event
.xgraphicsexpose
.height
);
6158 #ifdef USE_X_TOOLKIT
6161 #endif /* USE_X_TOOLKIT */
6164 case NoExpose
: /* This occurs when an XCopyArea's
6165 source area was completely
6170 /* Redo the mouse-highlight after the tooltip has gone. */
6171 if (event
.xmap
.window
== tip_window
)
6174 redo_mouse_highlight ();
6177 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6178 if (f
) /* F may no longer exist if
6179 the frame was deleted. */
6181 /* While a frame is unmapped, display generation is
6182 disabled; you don't want to spend time updating a
6183 display that won't ever be seen. */
6184 f
->async_visible
= 0;
6185 /* We can't distinguish, from the event, whether the window
6186 has become iconified or invisible. So assume, if it
6187 was previously visible, than now it is iconified.
6188 But x_make_frame_invisible clears both
6189 the visible flag and the iconified flag;
6190 and that way, we know the window is not iconified now. */
6191 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6193 f
->async_iconified
= 1;
6195 inev
.ie
.kind
= ICONIFY_EVENT
;
6196 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6202 if (event
.xmap
.window
== tip_window
)
6203 /* The tooltip has been drawn already. Avoid
6204 the SET_FRAME_GARBAGED below. */
6207 /* We use x_top_window_to_frame because map events can
6208 come for sub-windows and they don't mean that the
6209 frame is visible. */
6210 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6213 /* wait_reading_process_output will notice this and update
6214 the frame's display structures.
6215 If we where iconified, we should not set garbaged,
6216 because that stops redrawing on Expose events. This looks
6217 bad if we are called from a recursive event loop
6218 (x_dispatch_event), for example when a dialog is up. */
6219 if (! f
->async_iconified
)
6220 SET_FRAME_GARBAGED (f
);
6222 /* Check if fullscreen was specified before we where mapped the
6223 first time, i.e. from the command line. */
6224 if (!f
->output_data
.x
->has_been_visible
)
6225 x_check_fullscreen (f
);
6227 f
->async_visible
= 1;
6228 f
->async_iconified
= 0;
6229 f
->output_data
.x
->has_been_visible
= 1;
6233 inev
.ie
.kind
= DEICONIFY_EVENT
;
6234 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6236 else if (! NILP (Vframe_list
)
6237 && ! NILP (XCDR (Vframe_list
)))
6238 /* Force a redisplay sooner or later
6239 to update the frame titles
6240 in case this is the second frame. */
6241 record_asynch_buffer_change ();
6244 xg_frame_resized (f
, -1, -1);
6251 last_user_time
= event
.xkey
.time
;
6252 ignore_next_mouse_click_timeout
= 0;
6254 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6255 /* Dispatch KeyPress events when in menu. */
6256 if (popup_activated ())
6260 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6262 /* If mouse-highlight is an integer, input clears out
6263 mouse highlighting. */
6264 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6266 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6268 clear_mouse_face (dpyinfo
);
6269 dpyinfo
->mouse_face_hidden
= 1;
6272 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6275 /* Scroll bars consume key events, but we want
6276 the keys to go to the scroll bar's frame. */
6277 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6279 if (widget
&& XmIsScrollBar (widget
))
6281 widget
= XtParent (widget
);
6282 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6285 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6289 KeySym keysym
, orig_keysym
;
6290 /* al%imercury@uunet.uu.net says that making this 81
6291 instead of 80 fixed a bug whereby meta chars made
6294 It seems that some version of XmbLookupString has
6295 a bug of not returning XBufferOverflow in
6296 status_return even if the input is too long to
6297 fit in 81 bytes. So, we must prepare sufficient
6298 bytes for copy_buffer. 513 bytes (256 chars for
6299 two-byte character set) seems to be a fairly good
6300 approximation. -- 2000.8.10 handa@etl.go.jp */
6301 unsigned char copy_buffer
[513];
6302 unsigned char *copy_bufptr
= copy_buffer
;
6303 int copy_bufsiz
= sizeof (copy_buffer
);
6305 Lisp_Object coding_system
= Qlatin_1
;
6309 /* Don't pass keys to GTK. A Tab will shift focus to the
6310 tool bar in GTK 2.4. Keys will still go to menus and
6311 dialogs because in that case popup_activated is TRUE
6313 *finish
= X_EVENT_DROP
;
6317 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6318 extra_keyboard_modifiers
);
6319 modifiers
= event
.xkey
.state
;
6321 /* This will have to go some day... */
6323 /* make_lispy_event turns chars into control chars.
6324 Don't do it here because XLookupString is too eager. */
6325 event
.xkey
.state
&= ~ControlMask
;
6326 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6327 | dpyinfo
->super_mod_mask
6328 | dpyinfo
->hyper_mod_mask
6329 | dpyinfo
->alt_mod_mask
);
6331 /* In case Meta is ComposeCharacter,
6332 clear its status. According to Markus Ehrnsperger
6333 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6334 this enables ComposeCharacter to work whether or
6335 not it is combined with Meta. */
6336 if (modifiers
& dpyinfo
->meta_mod_mask
)
6337 bzero (&compose_status
, sizeof (compose_status
));
6342 Status status_return
;
6344 coding_system
= Vlocale_coding_system
;
6345 nbytes
= XmbLookupString (FRAME_XIC (f
),
6346 &event
.xkey
, copy_bufptr
,
6347 copy_bufsiz
, &keysym
,
6349 if (status_return
== XBufferOverflow
)
6351 copy_bufsiz
= nbytes
+ 1;
6352 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6353 nbytes
= XmbLookupString (FRAME_XIC (f
),
6354 &event
.xkey
, copy_bufptr
,
6355 copy_bufsiz
, &keysym
,
6358 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6359 if (status_return
== XLookupNone
)
6361 else if (status_return
== XLookupChars
)
6366 else if (status_return
!= XLookupKeySym
6367 && status_return
!= XLookupBoth
)
6371 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6372 copy_bufsiz
, &keysym
,
6375 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6376 copy_bufsiz
, &keysym
,
6380 /* If not using XIM/XIC, and a compose sequence is in progress,
6381 we break here. Otherwise, chars_matched is always 0. */
6382 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6385 bzero (&compose_status
, sizeof (compose_status
));
6386 orig_keysym
= keysym
;
6388 /* Common for all keysym input events. */
6389 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6391 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6392 inev
.ie
.timestamp
= event
.xkey
.time
;
6394 /* First deal with keysyms which have defined
6395 translations to characters. */
6396 if (keysym
>= 32 && keysym
< 128)
6397 /* Avoid explicitly decoding each ASCII character. */
6399 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6400 inev
.ie
.code
= keysym
;
6404 /* Keysyms directly mapped to Unicode characters. */
6405 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6407 if (keysym
< 0x01000080)
6408 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6410 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6411 inev
.ie
.code
= keysym
& 0xFFFFFF;
6415 /* Now non-ASCII. */
6416 if (HASH_TABLE_P (Vx_keysym_table
)
6417 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6421 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6422 ? ASCII_KEYSTROKE_EVENT
6423 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6424 inev
.ie
.code
= XFASTINT (c
);
6428 /* Random non-modifier sorts of keysyms. */
6429 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6430 || keysym
== XK_Delete
6431 #ifdef XK_ISO_Left_Tab
6432 || (keysym
>= XK_ISO_Left_Tab
6433 && keysym
<= XK_ISO_Enter
)
6435 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6436 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6438 /* This recognizes the "extended function
6439 keys". It seems there's no cleaner way.
6440 Test IsModifierKey to avoid handling
6441 mode_switch incorrectly. */
6442 || ((unsigned) (keysym
) >= XK_Select
6443 && (unsigned)(keysym
) < XK_KP_Space
)
6445 #ifdef XK_dead_circumflex
6446 || orig_keysym
== XK_dead_circumflex
6448 #ifdef XK_dead_grave
6449 || orig_keysym
== XK_dead_grave
6451 #ifdef XK_dead_tilde
6452 || orig_keysym
== XK_dead_tilde
6454 #ifdef XK_dead_diaeresis
6455 || orig_keysym
== XK_dead_diaeresis
6457 #ifdef XK_dead_macron
6458 || orig_keysym
== XK_dead_macron
6460 #ifdef XK_dead_degree
6461 || orig_keysym
== XK_dead_degree
6463 #ifdef XK_dead_acute
6464 || orig_keysym
== XK_dead_acute
6466 #ifdef XK_dead_cedilla
6467 || orig_keysym
== XK_dead_cedilla
6469 #ifdef XK_dead_breve
6470 || orig_keysym
== XK_dead_breve
6472 #ifdef XK_dead_ogonek
6473 || orig_keysym
== XK_dead_ogonek
6475 #ifdef XK_dead_caron
6476 || orig_keysym
== XK_dead_caron
6478 #ifdef XK_dead_doubleacute
6479 || orig_keysym
== XK_dead_doubleacute
6481 #ifdef XK_dead_abovedot
6482 || orig_keysym
== XK_dead_abovedot
6484 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6485 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6486 /* Any "vendor-specific" key is ok. */
6487 || (orig_keysym
& (1 << 28))
6488 || (keysym
!= NoSymbol
&& nbytes
== 0))
6489 && ! (IsModifierKey (orig_keysym
)
6490 /* The symbols from XK_ISO_Lock
6491 to XK_ISO_Last_Group_Lock
6492 don't have real modifiers but
6493 should be treated similarly to
6494 Mode_switch by Emacs. */
6495 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6496 || ((unsigned)(orig_keysym
)
6498 && (unsigned)(orig_keysym
)
6499 <= XK_ISO_Last_Group_Lock
)
6503 STORE_KEYSYM_FOR_DEBUG (keysym
);
6504 /* make_lispy_event will convert this to a symbolic
6506 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6507 inev
.ie
.code
= keysym
;
6511 { /* Raw bytes, not keysym. */
6516 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6518 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6520 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6523 if (nchars
< nbytes
)
6525 /* Decode the input data. */
6529 /* The input should be decoded with `coding_system'
6530 which depends on which X*LookupString function
6531 we used just above and the locale. */
6532 setup_coding_system (coding_system
, &coding
);
6533 coding
.src_multibyte
= 0;
6534 coding
.dst_multibyte
= 1;
6535 /* The input is converted to events, thus we can't
6536 handle composition. Anyway, there's no XIM that
6537 gives us composition information. */
6538 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6540 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6541 coding
.destination
= alloca (require
);
6542 coding
.dst_bytes
= require
;
6543 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6544 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6545 nbytes
= coding
.produced
;
6546 nchars
= coding
.produced_char
;
6547 copy_bufptr
= coding
.destination
;
6550 /* Convert the input data to a sequence of
6551 character events. */
6552 for (i
= 0; i
< nbytes
; i
+= len
)
6554 if (nchars
== nbytes
)
6555 c
= copy_bufptr
[i
], len
= 1;
6557 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6559 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6560 ? ASCII_KEYSTROKE_EVENT
6561 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6563 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6568 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6570 if (keysym
== NoSymbol
)
6576 /* Don't dispatch this event since XtDispatchEvent calls
6577 XFilterEvent, and two calls in a row may freeze the
6585 last_user_time
= event
.xkey
.time
;
6587 /* Don't dispatch this event since XtDispatchEvent calls
6588 XFilterEvent, and two calls in a row may freeze the
6596 last_user_time
= event
.xcrossing
.time
;
6597 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6599 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6601 if (f
&& x_mouse_click_focus_ignore_position
)
6602 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6604 /* EnterNotify counts as mouse movement,
6605 so update things that depend on mouse position. */
6606 if (f
&& !f
->output_data
.x
->hourglass_p
)
6607 note_mouse_movement (f
, &event
.xmotion
);
6609 /* We may get an EnterNotify on the buttons in the toolbar. In that
6610 case we moved out of any highlighted area and need to note this. */
6611 if (!f
&& last_mouse_glyph_frame
)
6612 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6617 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6621 last_user_time
= event
.xcrossing
.time
;
6622 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6624 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6627 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6629 /* If we move outside the frame, then we're
6630 certainly no longer on any text in the frame. */
6631 clear_mouse_face (dpyinfo
);
6632 dpyinfo
->mouse_face_mouse_frame
= 0;
6635 /* Generate a nil HELP_EVENT to cancel a help-echo.
6636 Do it only if there's something to cancel.
6637 Otherwise, the startup message is cleared when
6638 the mouse leaves the frame. */
6639 if (any_help_event_p
)
6643 /* See comment in EnterNotify above */
6644 else if (last_mouse_glyph_frame
)
6645 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6650 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6655 last_user_time
= event
.xmotion
.time
;
6656 previous_help_echo_string
= help_echo_string
;
6657 help_echo_string
= Qnil
;
6659 if (dpyinfo
->grabbed
&& last_mouse_frame
6660 && FRAME_LIVE_P (last_mouse_frame
))
6661 f
= last_mouse_frame
;
6663 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6665 if (dpyinfo
->mouse_face_hidden
)
6667 dpyinfo
->mouse_face_hidden
= 0;
6668 clear_mouse_face (dpyinfo
);
6674 /* Generate SELECT_WINDOW_EVENTs when needed.
6675 Don't let popup menus influence things (bug#1261). */
6676 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6680 window
= window_from_coordinates (f
,
6681 event
.xmotion
.x
, event
.xmotion
.y
,
6684 /* Window will be selected only when it is not selected now and
6685 last mouse movement event was not in it. Minibuffer window
6686 will be selected only when it is active. */
6687 if (WINDOWP (window
)
6688 && !EQ (window
, last_window
)
6689 && !EQ (window
, selected_window
)
6690 /* For click-to-focus window managers
6691 create event iff we don't leave the
6693 && (focus_follows_mouse
6694 || (EQ (XWINDOW (window
)->frame
,
6695 XWINDOW (selected_window
)->frame
))))
6697 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6698 inev
.ie
.frame_or_window
= window
;
6703 if (!note_mouse_movement (f
, &event
.xmotion
))
6704 help_echo_string
= previous_help_echo_string
;
6708 #ifndef USE_TOOLKIT_SCROLL_BARS
6709 struct scroll_bar
*bar
6710 = x_window_to_scroll_bar (event
.xmotion
.display
,
6711 event
.xmotion
.window
);
6714 x_scroll_bar_note_movement (bar
, &event
);
6715 #endif /* USE_TOOLKIT_SCROLL_BARS */
6717 /* If we move outside the frame, then we're
6718 certainly no longer on any text in the frame. */
6719 clear_mouse_face (dpyinfo
);
6722 /* If the contents of the global variable help_echo_string
6723 has changed, generate a HELP_EVENT. */
6724 if (!NILP (help_echo_string
)
6725 || !NILP (previous_help_echo_string
))
6730 case ConfigureNotify
:
6731 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6734 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6735 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6737 xg_frame_resized (f
, event
.xconfigure
.width
,
6738 event
.xconfigure
.height
);
6744 #ifndef USE_X_TOOLKIT
6746 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6747 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6749 /* In the toolkit version, change_frame_size
6750 is called by the code that handles resizing
6751 of the EmacsFrame widget. */
6753 /* Even if the number of character rows and columns has
6754 not changed, the font size may have changed, so we need
6755 to check the pixel dimensions as well. */
6756 if (columns
!= FRAME_COLS (f
)
6757 || rows
!= FRAME_LINES (f
)
6758 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6759 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6761 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6762 SET_FRAME_GARBAGED (f
);
6763 cancel_mouse_face (f
);
6766 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6767 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6768 #endif /* not USE_GTK */
6772 /* GTK creates windows but doesn't map them.
6773 Only get real positions and check fullscreen when mapped. */
6774 if (FRAME_GTK_OUTER_WIDGET (f
)
6775 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6778 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6782 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6783 xic_set_statusarea (f
);
6787 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
6789 /* Since the WM decorations come below top_pos now,
6790 we must put them below top_pos in the future. */
6791 f
->win_gravity
= NorthWestGravity
;
6792 x_wm_set_size_hint (f
, (long) 0, 0);
6801 /* If we decide we want to generate an event to be seen
6802 by the rest of Emacs, we put it here. */
6805 bzero (&compose_status
, sizeof (compose_status
));
6806 last_mouse_glyph_frame
= 0;
6807 last_user_time
= event
.xbutton
.time
;
6809 if (dpyinfo
->grabbed
6811 && FRAME_LIVE_P (last_mouse_frame
))
6812 f
= last_mouse_frame
;
6814 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6818 /* Is this in the tool-bar? */
6819 if (WINDOWP (f
->tool_bar_window
)
6820 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6823 int x
= event
.xbutton
.x
;
6824 int y
= event
.xbutton
.y
;
6826 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6827 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6829 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6831 handle_tool_bar_click (f
, x
, y
,
6832 event
.xbutton
.type
== ButtonPress
,
6833 x_x_to_emacs_modifiers (dpyinfo
,
6834 event
.xbutton
.state
));
6839 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6840 if (! popup_activated ())
6843 if (ignore_next_mouse_click_timeout
)
6845 if (event
.type
== ButtonPress
6846 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6848 ignore_next_mouse_click_timeout
= 0;
6849 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6851 if (event
.type
== ButtonRelease
)
6852 ignore_next_mouse_click_timeout
= 0;
6855 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6857 if (FRAME_X_EMBEDDED_P (f
))
6858 xembed_send_message (f
, event
.xbutton
.time
,
6859 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6863 struct scroll_bar
*bar
6864 = x_window_to_scroll_bar (event
.xbutton
.display
,
6865 event
.xbutton
.window
);
6867 #ifdef USE_TOOLKIT_SCROLL_BARS
6868 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6870 if (bar
&& event
.xbutton
.state
& ControlMask
)
6872 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6873 *finish
= X_EVENT_DROP
;
6875 #else /* not USE_TOOLKIT_SCROLL_BARS */
6877 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6878 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6881 if (event
.type
== ButtonPress
)
6883 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6884 last_mouse_frame
= f
;
6887 last_tool_bar_item
= -1;
6890 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6892 /* Ignore any mouse motion that happened before this event;
6893 any subsequent mouse-movement Emacs events should reflect
6894 only motion after the ButtonPress/Release. */
6898 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6899 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6900 /* For a down-event in the menu bar,
6901 don't pass it to Xt right now.
6902 Instead, save it away
6903 and we will pass it to Xt from kbd_buffer_get_event.
6904 That way, we can run some Lisp code first. */
6907 ! popup_activated ()
6908 /* Gtk+ menus only react to the first three buttons. */
6909 && event
.xbutton
.button
< 3
6912 f
&& event
.type
== ButtonPress
6913 /* Verify the event is really within the menu bar
6914 and not just sent to it due to grabbing. */
6915 && event
.xbutton
.x
>= 0
6916 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6917 && event
.xbutton
.y
>= 0
6918 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6919 && event
.xbutton
.same_screen
)
6921 SET_SAVED_BUTTON_EVENT
;
6922 XSETFRAME (last_mouse_press_frame
, f
);
6924 *finish
= X_EVENT_DROP
;
6927 else if (event
.type
== ButtonPress
)
6929 last_mouse_press_frame
= Qnil
;
6933 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6934 but I am trying to be cautious. */
6935 else if (event
.type
== ButtonRelease
)
6937 if (!NILP (last_mouse_press_frame
))
6939 f
= XFRAME (last_mouse_press_frame
);
6940 if (f
->output_data
.x
)
6941 SET_SAVED_BUTTON_EVENT
;
6946 #endif /* USE_MOTIF */
6949 #endif /* USE_X_TOOLKIT || USE_GTK */
6953 case CirculateNotify
:
6956 case CirculateRequest
:
6959 case VisibilityNotify
:
6963 /* Someone has changed the keyboard mapping - update the
6965 switch (event
.xmapping
.request
)
6967 case MappingModifier
:
6968 x_find_modifier_meanings (dpyinfo
);
6969 /* This is meant to fall through. */
6970 case MappingKeyboard
:
6971 XRefreshKeyboardMapping (&event
.xmapping
);
6977 #ifdef USE_X_TOOLKIT
6979 if (*finish
!= X_EVENT_DROP
)
6980 XtDispatchEvent (&event
);
6982 #endif /* USE_X_TOOLKIT */
6987 if (inev
.ie
.kind
!= NO_EVENT
)
6989 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6994 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6999 XSETFRAME (frame
, f
);
7005 any_help_event_p
= 1;
7006 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7007 help_echo_object
, help_echo_pos
);
7011 help_echo_string
= Qnil
;
7012 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7022 /* Handles the XEvent EVENT on display DISPLAY.
7023 This is used for event loops outside the normal event handling,
7024 i.e. looping while a popup menu or a dialog is posted.
7026 Returns the value handle_one_xevent sets in the finish argument. */
7028 x_dispatch_event (event
, display
)
7032 struct x_display_info
*dpyinfo
;
7033 int finish
= X_EVENT_NORMAL
;
7035 dpyinfo
= x_display_info_for_display (display
);
7038 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7044 /* Read events coming from the X server.
7045 This routine is called by the SIGIO handler.
7046 We return as soon as there are no more events to be read.
7048 We return the number of characters stored into the buffer,
7049 thus pretending to be `read' (except the characters we store
7050 in the keyboard buffer can be multibyte, so are not necessarily
7053 EXPECTED is nonzero if the caller knows input is available. */
7056 XTread_socket (terminal
, expected
, hold_quit
)
7057 struct terminal
*terminal
;
7059 struct input_event
*hold_quit
;
7063 int event_found
= 0;
7065 if (interrupt_input_blocked
)
7067 interrupt_input_pending
= 1;
7069 pending_signals
= 1;
7074 interrupt_input_pending
= 0;
7076 pending_signals
= pending_atimers
;
7080 /* So people can tell when we have read the available input. */
7081 input_signal_count
++;
7086 /* Only check session manager input for the primary display. */
7087 if (terminal
->id
== 1 && x_session_have_connection ())
7089 struct input_event inev
;
7091 /* We don't need to EVENT_INIT (inev) here, as
7092 x_session_check_input copies an entire input_event. */
7093 if (x_session_check_input (&inev
))
7095 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7102 /* For debugging, this gives a way to fake an I/O error. */
7103 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7105 XTread_socket_fake_io_error
= 0;
7106 x_io_error_quitter (terminal
->display_info
.x
->display
);
7110 while (XPending (terminal
->display_info
.x
->display
))
7114 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7117 /* Filter events for the current X input method. */
7118 if (x_filter_event (terminal
->display_info
.x
, &event
))
7123 count
+= handle_one_xevent (terminal
->display_info
.x
,
7124 &event
, &finish
, hold_quit
);
7126 if (finish
== X_EVENT_GOTO_OUT
)
7132 /* For GTK we must use the GTK event loop. But XEvents gets passed
7133 to our filter function above, and then to the big event switch.
7134 We use a bunch of globals to communicate with our filter function,
7135 that is kind of ugly, but it works.
7137 There is no way to do one display at the time, GTK just does events
7138 from all displays. */
7140 while (gtk_events_pending ())
7142 current_count
= count
;
7143 current_hold_quit
= hold_quit
;
7145 gtk_main_iteration ();
7147 count
= current_count
;
7149 current_hold_quit
= 0;
7151 if (current_finish
== X_EVENT_GOTO_OUT
)
7154 #endif /* USE_GTK */
7158 /* On some systems, an X bug causes Emacs to get no more events
7159 when the window is destroyed. Detect that. (1994.) */
7162 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7163 One XNOOP in 100 loops will make Emacs terminate.
7164 B. Bretthauer, 1994 */
7166 if (x_noop_count
>= 100)
7170 if (next_noop_dpyinfo
== 0)
7171 next_noop_dpyinfo
= x_display_list
;
7173 XNoOp (next_noop_dpyinfo
->display
);
7175 /* Each time we get here, cycle through the displays now open. */
7176 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7180 /* If the focus was just given to an auto-raising frame,
7182 /* ??? This ought to be able to handle more than one such frame. */
7183 if (pending_autoraise_frame
)
7185 x_raise_frame (pending_autoraise_frame
);
7186 pending_autoraise_frame
= 0;
7198 /***********************************************************************
7200 ***********************************************************************/
7202 /* Set clipping for output in glyph row ROW. W is the window in which
7203 we operate. GC is the graphics context to set clipping in.
7205 ROW may be a text row or, e.g., a mode line. Text rows must be
7206 clipped to the interior of the window dedicated to text display,
7207 mode lines must be clipped to the whole window. */
7210 x_clip_to_row (w
, row
, area
, gc
)
7212 struct glyph_row
*row
;
7216 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7217 XRectangle clip_rect
;
7218 int window_x
, window_y
, window_width
;
7220 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7222 clip_rect
.x
= window_x
;
7223 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7224 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7225 clip_rect
.width
= window_width
;
7226 clip_rect
.height
= row
->visible_height
;
7228 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7232 /* Draw a hollow box cursor on window W in glyph row ROW. */
7235 x_draw_hollow_cursor (w
, row
)
7237 struct glyph_row
*row
;
7239 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7240 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7241 Display
*dpy
= FRAME_X_DISPLAY (f
);
7244 struct glyph
*cursor_glyph
;
7247 /* Get the glyph the cursor is on. If we can't tell because
7248 the current matrix is invalid or such, give up. */
7249 cursor_glyph
= get_phys_cursor_glyph (w
);
7250 if (cursor_glyph
== NULL
)
7253 /* Compute frame-relative coordinates for phys cursor. */
7254 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7255 wd
= w
->phys_cursor_width
;
7257 /* The foreground of cursor_gc is typically the same as the normal
7258 background color, which can cause the cursor box to be invisible. */
7259 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7260 if (dpyinfo
->scratch_cursor_gc
)
7261 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7263 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7264 GCForeground
, &xgcv
);
7265 gc
= dpyinfo
->scratch_cursor_gc
;
7267 /* Set clipping, draw the rectangle, and reset clipping again. */
7268 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7269 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7270 XSetClipMask (dpy
, gc
, None
);
7274 /* Draw a bar cursor on window W in glyph row ROW.
7276 Implementation note: One would like to draw a bar cursor with an
7277 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7278 Unfortunately, I didn't find a font yet that has this property set.
7282 x_draw_bar_cursor (w
, row
, width
, kind
)
7284 struct glyph_row
*row
;
7286 enum text_cursor_kinds kind
;
7288 struct frame
*f
= XFRAME (w
->frame
);
7289 struct glyph
*cursor_glyph
;
7291 /* If cursor is out of bounds, don't draw garbage. This can happen
7292 in mini-buffer windows when switching between echo area glyphs
7294 cursor_glyph
= get_phys_cursor_glyph (w
);
7295 if (cursor_glyph
== NULL
)
7298 /* If on an image, draw like a normal cursor. That's usually better
7299 visible than drawing a bar, esp. if the image is large so that
7300 the bar might not be in the window. */
7301 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7303 struct glyph_row
*row
;
7304 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7305 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7309 Display
*dpy
= FRAME_X_DISPLAY (f
);
7310 Window window
= FRAME_X_WINDOW (f
);
7311 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7312 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7313 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7316 /* If the glyph's background equals the color we normally draw
7317 the bars cursor in, the bar cursor in its normal color is
7318 invisible. Use the glyph's foreground color instead in this
7319 case, on the assumption that the glyph's colors are chosen so
7320 that the glyph is legible. */
7321 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7322 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7324 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7325 xgcv
.graphics_exposures
= 0;
7328 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7331 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7332 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7335 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7337 if (kind
== BAR_CURSOR
)
7340 width
= FRAME_CURSOR_WIDTH (f
);
7341 width
= min (cursor_glyph
->pixel_width
, width
);
7343 w
->phys_cursor_width
= width
;
7345 XFillRectangle (dpy
, window
, gc
,
7346 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7347 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7348 width
, row
->height
);
7352 int dummy_x
, dummy_y
, dummy_h
;
7355 width
= row
->height
;
7357 width
= min (row
->height
, width
);
7359 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7360 &dummy_y
, &dummy_h
);
7362 XFillRectangle (dpy
, window
, gc
,
7363 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7364 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7365 row
->height
- width
),
7366 w
->phys_cursor_width
, width
);
7369 XSetClipMask (dpy
, gc
, None
);
7374 /* RIF: Define cursor CURSOR on frame F. */
7377 x_define_frame_cursor (f
, cursor
)
7381 if (!f
->pointer_invisible
7382 && f
->output_data
.x
->current_cursor
!= cursor
)
7383 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7384 f
->output_data
.x
->current_cursor
= cursor
;
7388 /* RIF: Clear area on frame F. */
7391 x_clear_frame_area (f
, x
, y
, width
, height
)
7393 int x
, y
, width
, height
;
7395 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7396 x
, y
, width
, height
, False
);
7400 /* RIF: Draw cursor on window W. */
7403 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7405 struct glyph_row
*glyph_row
;
7407 int cursor_type
, cursor_width
;
7410 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7414 w
->phys_cursor_type
= cursor_type
;
7415 w
->phys_cursor_on_p
= 1;
7417 if (glyph_row
->exact_window_width_line_p
7418 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7420 glyph_row
->cursor_in_fringe_p
= 1;
7421 draw_fringe_bitmap (w
, glyph_row
, 0);
7424 switch (cursor_type
)
7426 case HOLLOW_BOX_CURSOR
:
7427 x_draw_hollow_cursor (w
, glyph_row
);
7430 case FILLED_BOX_CURSOR
:
7431 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7435 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7439 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7443 w
->phys_cursor_width
= 0;
7451 if (w
== XWINDOW (f
->selected_window
))
7452 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7453 xic_set_preeditarea (w
, x
, y
);
7458 XFlush (FRAME_X_DISPLAY (f
));
7465 /* Make the x-window of frame F use the gnu icon bitmap. */
7468 x_bitmap_icon (f
, file
)
7474 if (FRAME_X_WINDOW (f
) == 0)
7477 /* Free up our existing icon bitmap and mask if any. */
7478 if (f
->output_data
.x
->icon_bitmap
> 0)
7479 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7480 f
->output_data
.x
->icon_bitmap
= 0;
7485 /* Use gtk_window_set_icon_from_file () if available,
7486 It's not restricted to bitmaps */
7487 if (xg_set_icon (f
, file
))
7489 #endif /* USE_GTK */
7490 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7491 x_create_bitmap_mask (f
, bitmap_id
);
7495 /* Create the GNU bitmap and mask if necessary. */
7496 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7502 if (xg_set_icon (f
, xg_default_icon_file
)
7503 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7506 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7508 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7510 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7514 /* If all else fails, use the (black and white) xbm image. */
7517 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7518 gnu_xbm_width
, gnu_xbm_height
);
7522 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7523 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7527 /* The first time we create the GNU bitmap and mask,
7528 this increments the ref-count one extra time.
7529 As a result, the GNU bitmap and mask are never freed.
7530 That way, we don't have to worry about allocating it again. */
7531 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7533 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7536 x_wm_set_icon_pixmap (f
, bitmap_id
);
7537 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7543 /* Make the x-window of frame F use a rectangle with text.
7544 Use ICON_NAME as the text. */
7547 x_text_icon (f
, icon_name
)
7551 if (FRAME_X_WINDOW (f
) == 0)
7556 text
.value
= (unsigned char *) icon_name
;
7557 text
.encoding
= XA_STRING
;
7559 text
.nitems
= strlen (icon_name
);
7560 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7563 if (f
->output_data
.x
->icon_bitmap
> 0)
7564 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7565 f
->output_data
.x
->icon_bitmap
= 0;
7566 x_wm_set_icon_pixmap (f
, 0);
7571 #define X_ERROR_MESSAGE_SIZE 200
7573 /* If non-nil, this should be a string.
7574 It means catch X errors and store the error message in this string.
7576 The reason we use a stack is that x_catch_error/x_uncatch_error can
7577 be called from a signal handler.
7580 struct x_error_message_stack
{
7581 char string
[X_ERROR_MESSAGE_SIZE
];
7583 struct x_error_message_stack
*prev
;
7585 static struct x_error_message_stack
*x_error_message
;
7587 /* An X error handler which stores the error message in
7588 *x_error_message. This is called from x_error_handler if
7589 x_catch_errors is in effect. */
7592 x_error_catcher (display
, error
)
7596 XGetErrorText (display
, error
->error_code
,
7597 x_error_message
->string
,
7598 X_ERROR_MESSAGE_SIZE
);
7601 /* Begin trapping X errors for display DPY. Actually we trap X errors
7602 for all displays, but DPY should be the display you are actually
7605 After calling this function, X protocol errors no longer cause
7606 Emacs to exit; instead, they are recorded in the string
7607 stored in *x_error_message.
7609 Calling x_check_errors signals an Emacs error if an X error has
7610 occurred since the last call to x_catch_errors or x_check_errors.
7612 Calling x_uncatch_errors resumes the normal error handling. */
7614 void x_check_errors ();
7617 x_catch_errors (dpy
)
7620 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7622 /* Make sure any errors from previous requests have been dealt with. */
7626 data
->string
[0] = 0;
7627 data
->prev
= x_error_message
;
7628 x_error_message
= data
;
7631 /* Undo the last x_catch_errors call.
7632 DPY should be the display that was passed to x_catch_errors. */
7637 struct x_error_message_stack
*tmp
;
7641 /* The display may have been closed before this function is called.
7642 Check if it is still open before calling XSync. */
7643 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7644 XSync (x_error_message
->dpy
, False
);
7646 tmp
= x_error_message
;
7647 x_error_message
= x_error_message
->prev
;
7652 /* If any X protocol errors have arrived since the last call to
7653 x_catch_errors or x_check_errors, signal an Emacs error using
7654 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7657 x_check_errors (dpy
, format
)
7661 /* Make sure to catch any errors incurred so far. */
7664 if (x_error_message
->string
[0])
7666 char string
[X_ERROR_MESSAGE_SIZE
];
7667 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7668 x_uncatch_errors ();
7669 error (format
, string
);
7673 /* Nonzero if we had any X protocol errors
7674 since we did x_catch_errors on DPY. */
7677 x_had_errors_p (dpy
)
7680 /* Make sure to catch any errors incurred so far. */
7683 return x_error_message
->string
[0] != 0;
7686 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7689 x_clear_errors (dpy
)
7692 x_error_message
->string
[0] = 0;
7695 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7696 * idea. --lorentey */
7697 /* Close off all unclosed x_catch_errors calls. */
7700 x_fully_uncatch_errors ()
7702 while (x_error_message
)
7703 x_uncatch_errors ();
7707 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7710 x_catching_errors ()
7712 return x_error_message
!= 0;
7716 static unsigned int x_wire_count
;
7719 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7724 /* Handle SIGPIPE, which can happen when the connection to a server
7725 simply goes away. SIGPIPE is handled by x_connection_signal.
7726 Don't need to do anything, because the write which caused the
7727 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7728 which will do the appropriate cleanup for us. */
7731 x_connection_signal (signalnum
) /* If we don't have an argument, */
7732 int signalnum
; /* some compilers complain in signal calls. */
7735 /* USG systems forget handlers when they are used;
7736 must reestablish each time */
7737 signal (signalnum
, x_connection_signal
);
7742 /************************************************************************
7744 ************************************************************************/
7746 /* Error message passed to x_connection_closed. */
7748 static char *error_msg
;
7750 /* Function installed as fatal_error_signal_hook in
7751 x_connection_closed. Print the X error message, and exit normally,
7752 instead of dumping core when XtCloseDisplay fails. */
7755 x_fatal_error_signal ()
7757 fprintf (stderr
, "%s\n", error_msg
);
7761 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7762 the text of an error message that lead to the connection loss. */
7765 x_connection_closed (dpy
, error_message
)
7767 char *error_message
;
7769 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7770 Lisp_Object frame
, tail
;
7771 int index
= SPECPDL_INDEX ();
7773 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7774 strcpy (error_msg
, error_message
);
7775 handling_signal
= 0;
7777 /* Prevent being called recursively because of an error condition
7778 below. Otherwise, we might end up with printing ``can't find per
7779 display information'' in the recursive call instead of printing
7780 the original message here. */
7781 x_catch_errors (dpy
);
7783 /* Inhibit redisplay while frames are being deleted. */
7784 specbind (Qinhibit_redisplay
, Qt
);
7788 /* Protect display from being closed when we delete the last
7790 dpyinfo
->reference_count
++;
7791 dpyinfo
->terminal
->reference_count
++;
7794 /* First delete frames whose mini-buffers are on frames
7795 that are on the dead display. */
7796 FOR_EACH_FRAME (tail
, frame
)
7798 Lisp_Object minibuf_frame
;
7800 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7801 if (FRAME_X_P (XFRAME (frame
))
7802 && FRAME_X_P (XFRAME (minibuf_frame
))
7803 && ! EQ (frame
, minibuf_frame
)
7804 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7805 delete_frame (frame
, Qnoelisp
);
7808 /* Now delete all remaining frames on the dead display.
7809 We are now sure none of these is used as the mini-buffer
7810 for another frame that we need to delete. */
7811 FOR_EACH_FRAME (tail
, frame
)
7812 if (FRAME_X_P (XFRAME (frame
))
7813 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7815 /* Set this to t so that delete_frame won't get confused
7816 trying to find a replacement. */
7817 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7818 delete_frame (frame
, Qnoelisp
);
7821 /* We have to close the display to inform Xt that it doesn't
7822 exist anymore. If we don't, Xt will continue to wait for
7823 events from the display. As a consequence, a sequence of
7825 M-x make-frame-on-display RET :1 RET
7826 ...kill the new frame, so that we get an IO error...
7827 M-x make-frame-on-display RET :1 RET
7829 will indefinitely wait in Xt for events for display `:1', opened
7830 in the first call to make-frame-on-display.
7832 Closing the display is reported to lead to a bus error on
7833 OpenWindows in certain situations. I suspect that is a bug
7834 in OpenWindows. I don't know how to circumvent it here. */
7838 #ifdef USE_X_TOOLKIT
7839 /* If DPYINFO is null, this means we didn't open the display
7840 in the first place, so don't try to close it. */
7842 extern void (*fatal_error_signal_hook
) P_ ((void));
7843 fatal_error_signal_hook
= x_fatal_error_signal
;
7844 XtCloseDisplay (dpy
);
7845 fatal_error_signal_hook
= NULL
;
7850 /* Due to bugs in some Gtk+ versions, just exit here if this
7851 is the last display/terminal. */
7852 if (terminal_list
->next_terminal
== NULL
)
7854 fprintf (stderr
, "%s\n", error_msg
);
7855 shut_down_emacs (0, 0, Qnil
);
7858 xg_display_close (dpyinfo
->display
);
7861 /* Indicate that this display is dead. */
7862 dpyinfo
->display
= 0;
7864 dpyinfo
->reference_count
--;
7865 dpyinfo
->terminal
->reference_count
--;
7866 if (dpyinfo
->reference_count
!= 0)
7867 /* We have just closed all frames on this display. */
7872 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7873 Fdelete_terminal (tmp
, Qnoelisp
);
7877 x_uncatch_errors ();
7879 if (terminal_list
== 0)
7881 fprintf (stderr
, "%s\n", error_msg
);
7882 shut_down_emacs (0, 0, Qnil
);
7886 /* Ordinary stack unwind doesn't deal with these. */
7888 sigunblock (sigmask (SIGIO
));
7890 sigunblock (sigmask (SIGALRM
));
7891 TOTALLY_UNBLOCK_INPUT
;
7893 unbind_to (index
, Qnil
);
7894 clear_waiting_for_input ();
7895 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7896 longjmp), because returning from this function would get us back into
7897 Xlib's code which will directly call `exit'. */
7898 error ("%s", error_msg
);
7901 /* We specifically use it before defining it, so that gcc doesn't inline it,
7902 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7903 static void x_error_quitter
P_ ((Display
*, XErrorEvent
*));
7905 /* This is the first-level handler for X protocol errors.
7906 It calls x_error_quitter or x_error_catcher. */
7909 x_error_handler (display
, error
)
7913 if (x_error_message
)
7914 x_error_catcher (display
, error
);
7916 x_error_quitter (display
, error
);
7920 /* This is the usual handler for X protocol errors.
7921 It kills all frames on the display that we got the error for.
7922 If that was the only one, it prints an error message and kills Emacs. */
7924 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7926 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
7927 #define NO_INLINE __attribute__((noinline))
7932 /* Some versions of GNU/Linux define noinline in their headers. */
7938 /* On older GCC versions, just putting x_error_quitter
7939 after x_error_handler prevents inlining into the former. */
7941 static void NO_INLINE
7942 x_error_quitter (display
, error
)
7946 char buf
[256], buf1
[356];
7948 /* Ignore BadName errors. They can happen because of fonts
7949 or colors that are not defined. */
7951 if (error
->error_code
== BadName
)
7954 /* Note that there is no real way portable across R3/R4 to get the
7955 original error handler. */
7957 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7958 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7959 buf
, error
->request_code
);
7960 x_connection_closed (display
, buf1
);
7964 /* This is the handler for X IO errors, always.
7965 It kills all frames on the display that we lost touch with.
7966 If that was the only one, it prints an error message and kills Emacs. */
7969 x_io_error_quitter (display
)
7974 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7975 x_connection_closed (display
, buf
);
7979 /* Changing the font of the frame. */
7981 /* Give frame F the font FONT-OBJECT as its default font. The return
7982 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7983 frame. If it is negative, generate a new fontset from
7987 x_new_font (f
, font_object
, fontset
)
7989 Lisp_Object font_object
;
7992 struct font
*font
= XFONT_OBJECT (font_object
);
7995 fontset
= fontset_from_font (font_object
);
7996 FRAME_FONTSET (f
) = fontset
;
7997 if (FRAME_FONT (f
) == font
)
7998 /* This font is already set in frame F. There's nothing more to
8002 FRAME_FONT (f
) = font
;
8003 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
8004 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
8005 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
8006 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
8008 compute_fringe_widths (f
, 1);
8010 /* Compute the scroll bar width in character columns. */
8011 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8013 int wid
= FRAME_COLUMN_WIDTH (f
);
8014 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8015 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8019 int wid
= FRAME_COLUMN_WIDTH (f
);
8020 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8023 if (FRAME_X_WINDOW (f
) != 0)
8025 /* Don't change the size of a tip frame; there's no point in
8026 doing it because it's done in Fx_show_tip, and it leads to
8027 problems because the tip frame has no widget. */
8028 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8030 /* When the frame is maximized/fullscreen or running under for
8031 example Xmonad, x_set_window_size will be a no-op.
8032 In that case, the right thing to do is extend rows/cols to
8033 the current frame size. We do that first if x_set_window_size
8034 turns out to not be a no-op (there is no way to know).
8035 The size will be adjusted again if the frame gets a
8036 ConfigureNotify event as a result of x_set_window_size. */
8037 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
,
8038 FRAME_PIXEL_HEIGHT (f
));
8039 int cols
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8040 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8041 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8047 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8050 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8059 /***********************************************************************
8061 ***********************************************************************/
8067 /* XIM destroy callback function, which is called whenever the
8068 connection to input method XIM dies. CLIENT_DATA contains a
8069 pointer to the x_display_info structure corresponding to XIM. */
8072 xim_destroy_callback (xim
, client_data
, call_data
)
8074 XPointer client_data
;
8077 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8078 Lisp_Object frame
, tail
;
8082 /* No need to call XDestroyIC.. */
8083 FOR_EACH_FRAME (tail
, frame
)
8085 struct frame
*f
= XFRAME (frame
);
8086 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8088 FRAME_XIC (f
) = NULL
;
8089 xic_free_xfontset (f
);
8093 /* No need to call XCloseIM. */
8094 dpyinfo
->xim
= NULL
;
8095 XFree (dpyinfo
->xim_styles
);
8099 #endif /* HAVE_X11R6 */
8102 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8103 extern char *XSetIMValues
P_ ((XIM
, ...));
8106 /* Open the connection to the XIM server on display DPYINFO.
8107 RESOURCE_NAME is the resource name Emacs uses. */
8110 xim_open_dpy (dpyinfo
, resource_name
)
8111 struct x_display_info
*dpyinfo
;
8112 char *resource_name
;
8120 XCloseIM (dpyinfo
->xim
);
8121 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8128 XIMCallback destroy
;
8131 /* Get supported styles and XIM values. */
8132 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8135 destroy
.callback
= xim_destroy_callback
;
8136 destroy
.client_data
= (XPointer
)dpyinfo
;
8137 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8143 #endif /* HAVE_XIM */
8144 dpyinfo
->xim
= NULL
;
8148 #ifdef HAVE_X11R6_XIM
8150 /* XIM instantiate callback function, which is called whenever an XIM
8151 server is available. DISPLAY is the display of the XIM.
8152 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8153 when the callback was registered. */
8156 xim_instantiate_callback (display
, client_data
, call_data
)
8158 XPointer client_data
;
8161 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8162 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8164 /* We don't support multiple XIM connections. */
8168 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8170 /* Create XIC for the existing frames on the same display, as long
8171 as they have no XIC. */
8172 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8174 Lisp_Object tail
, frame
;
8177 FOR_EACH_FRAME (tail
, frame
)
8179 struct frame
*f
= XFRAME (frame
);
8182 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8183 if (FRAME_XIC (f
) == NULL
)
8185 create_frame_xic (f
);
8186 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8187 xic_set_statusarea (f
);
8188 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8190 struct window
*w
= XWINDOW (f
->selected_window
);
8191 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8200 #endif /* HAVE_X11R6_XIM */
8203 /* Open a connection to the XIM server on display DPYINFO.
8204 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8205 connection only at the first time. On X11R6, open the connection
8206 in the XIM instantiate callback function. */
8209 xim_initialize (dpyinfo
, resource_name
)
8210 struct x_display_info
*dpyinfo
;
8211 char *resource_name
;
8213 dpyinfo
->xim
= NULL
;
8217 #ifdef HAVE_X11R6_XIM
8218 struct xim_inst_t
*xim_inst
;
8221 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8222 dpyinfo
->xim_callback_data
= xim_inst
;
8223 xim_inst
->dpyinfo
= dpyinfo
;
8224 len
= strlen (resource_name
);
8225 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8226 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8227 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8228 resource_name
, EMACS_CLASS
,
8229 xim_instantiate_callback
,
8230 /* This is XPointer in XFree86
8231 but (XPointer *) on Tru64, at
8232 least, hence the configure test. */
8233 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8234 #else /* not HAVE_X11R6_XIM */
8235 xim_open_dpy (dpyinfo
, resource_name
);
8236 #endif /* not HAVE_X11R6_XIM */
8238 #endif /* HAVE_XIM */
8242 /* Close the connection to the XIM server on display DPYINFO. */
8245 xim_close_dpy (dpyinfo
)
8246 struct x_display_info
*dpyinfo
;
8251 #ifdef HAVE_X11R6_XIM
8252 if (dpyinfo
->display
)
8253 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8255 xim_instantiate_callback
, NULL
);
8256 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8257 xfree (dpyinfo
->xim_callback_data
);
8258 #endif /* HAVE_X11R6_XIM */
8259 if (dpyinfo
->display
)
8260 XCloseIM (dpyinfo
->xim
);
8261 dpyinfo
->xim
= NULL
;
8262 XFree (dpyinfo
->xim_styles
);
8264 #endif /* HAVE_XIM */
8267 #endif /* not HAVE_X11R6_XIM */
8271 /* Calculate the absolute position in frame F
8272 from its current recorded position values and gravity. */
8275 x_calc_absolute_position (f
)
8278 int flags
= f
->size_hint_flags
;
8280 /* We have nothing to do if the current position
8281 is already for the top-left corner. */
8282 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8285 /* Treat negative positions as relative to the leftmost bottommost
8286 position that fits on the screen. */
8287 if (flags
& XNegative
)
8288 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8289 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8292 int height
= FRAME_PIXEL_HEIGHT (f
);
8294 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8295 /* Something is fishy here. When using Motif, starting Emacs with
8296 `-g -0-0', the frame appears too low by a few pixels.
8298 This seems to be so because initially, while Emacs is starting,
8299 the column widget's height and the frame's pixel height are
8300 different. The column widget's height is the right one. In
8301 later invocations, when Emacs is up, the frame's pixel height
8304 It's not obvious where the initial small difference comes from.
8305 2000-12-01, gerd. */
8307 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8310 if (flags
& YNegative
)
8311 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8312 - height
+ f
->top_pos
;
8315 /* The left_pos and top_pos
8316 are now relative to the top and left screen edges,
8317 so the flags should correspond. */
8318 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8321 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8322 to really change the position, and 0 when calling from
8323 x_make_frame_visible (in that case, XOFF and YOFF are the current
8324 position values). It is -1 when calling from x_set_frame_parameters,
8325 which means, do adjust for borders but don't change the gravity. */
8328 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8330 register int xoff
, yoff
;
8333 int modified_top
, modified_left
;
8335 if (change_gravity
> 0)
8337 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8338 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8342 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8344 f
->size_hint_flags
|= XNegative
;
8346 f
->size_hint_flags
|= YNegative
;
8347 f
->win_gravity
= NorthWestGravity
;
8349 x_calc_absolute_position (f
);
8352 x_wm_set_size_hint (f
, (long) 0, 0);
8354 modified_left
= f
->left_pos
;
8355 modified_top
= f
->top_pos
;
8357 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8359 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8360 than the WM decorations. So we use the calculated offset instead
8361 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8362 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8363 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8366 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8367 modified_left
, modified_top
);
8369 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8370 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8373 /* change_gravity is non-zero when this function is called from Lisp to
8374 programmatically move a frame. In that case, we call
8375 x_check_expected_move to discover if we have a "Type A" or "Type B"
8376 window manager, and, for a "Type A" window manager, adjust the position
8379 We call x_check_expected_move if a programmatic move occurred, and
8380 either the window manager type (A/B) is unknown or it is Type A but we
8381 need to compute the top/left offset adjustment for this frame. */
8383 if (change_gravity
!= 0 &&
8384 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8385 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8386 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8387 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8388 x_check_expected_move (f
, modified_left
, modified_top
);
8393 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8394 on the root window for frame F contains ATOMNAME.
8395 This is how a WM check shall be done according to the Window Manager
8396 Specification/Extended Window Manager Hints at
8397 http://freedesktop.org/wiki/Specifications/wm-spec. */
8400 wm_supports (f
, atomname
)
8402 const char *atomname
;
8405 unsigned long actual_size
, bytes_remaining
;
8406 int i
, rc
, actual_format
;
8408 Window wmcheck_window
;
8409 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8410 Window target_window
= dpyinfo
->root_window
;
8411 long max_len
= 65536;
8412 Display
*dpy
= FRAME_X_DISPLAY (f
);
8413 unsigned char *tmp_data
= NULL
;
8414 Atom target_type
= XA_WINDOW
;
8419 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8421 x_catch_errors (dpy
);
8422 rc
= XGetWindowProperty (dpy
, target_window
,
8423 prop_atom
, 0, max_len
, False
, target_type
,
8424 &actual_type
, &actual_format
, &actual_size
,
8425 &bytes_remaining
, &tmp_data
);
8427 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8429 if (tmp_data
) XFree (tmp_data
);
8430 x_uncatch_errors ();
8435 wmcheck_window
= *(Window
*) tmp_data
;
8438 /* Check if window exists. */
8439 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8441 if (x_had_errors_p (dpy
))
8443 x_uncatch_errors ();
8448 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8450 /* Window changed, reload atoms */
8451 if (dpyinfo
->net_supported_atoms
!= NULL
)
8452 XFree (dpyinfo
->net_supported_atoms
);
8453 dpyinfo
->net_supported_atoms
= NULL
;
8454 dpyinfo
->nr_net_supported_atoms
= 0;
8455 dpyinfo
->net_supported_window
= 0;
8457 target_type
= XA_ATOM
;
8458 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8460 rc
= XGetWindowProperty (dpy
, target_window
,
8461 prop_atom
, 0, max_len
, False
, target_type
,
8462 &actual_type
, &actual_format
, &actual_size
,
8463 &bytes_remaining
, &tmp_data
);
8465 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8467 if (tmp_data
) XFree (tmp_data
);
8468 x_uncatch_errors ();
8473 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8474 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8475 dpyinfo
->net_supported_window
= wmcheck_window
;
8479 want_atom
= XInternAtom (dpy
, atomname
, False
);
8481 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8482 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8484 x_uncatch_errors ();
8491 set_wm_state (frame
, add
, what
, what2
)
8497 const char *atom
= "_NET_WM_STATE";
8498 Fx_send_client_event (frame
, make_number (0), frame
,
8499 make_unibyte_string (atom
, strlen (atom
)),
8501 /* 1 = add, 0 = remove */
8503 (make_number (add
? 1 : 0),
8505 (make_unibyte_string (what
, strlen (what
)),
8507 ? Fcons (make_unibyte_string (what2
, strlen (what2
)),
8513 x_set_sticky (f
, new_value
, old_value
)
8515 Lisp_Object new_value
, old_value
;
8519 XSETFRAME (frame
, f
);
8520 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8521 "_NET_WM_STATE_STICKY", NULL
);
8524 /* Do fullscreen as specified in extended window manager hints */
8527 do_ewmh_fullscreen (f
)
8530 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8532 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8533 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8535 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8540 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8541 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8542 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8544 XSETFRAME (frame
, f
);
8546 set_wm_state (frame
, 0, fs
, NULL
);
8547 set_wm_state (frame
, 0, fh
, NULL
);
8548 set_wm_state (frame
, 0, fw
, NULL
);
8550 /* If there are _NET_ atoms we assume we have extended window manager
8552 switch (f
->want_fullscreen
)
8554 case FULLSCREEN_BOTH
:
8555 set_wm_state (frame
, 1, fs
, NULL
);
8557 case FULLSCREEN_WIDTH
:
8558 set_wm_state (frame
, 1, fw
, NULL
);
8560 case FULLSCREEN_HEIGHT
:
8561 set_wm_state (frame
, 1, fh
, NULL
);
8563 case FULLSCREEN_MAXIMIZED
:
8564 set_wm_state (frame
, 1, fw
, fh
);
8568 f
->want_fullscreen
= FULLSCREEN_NONE
;
8572 return have_net_atom
;
8576 XTfullscreen_hook (f
)
8579 if (f
->async_visible
)
8582 x_check_fullscreen (f
);
8590 x_handle_net_wm_state (f
, event
)
8592 XPropertyEvent
*event
;
8595 unsigned long actual_size
, bytes_remaining
;
8596 int i
, rc
, actual_format
, value
= FULLSCREEN_NONE
;
8597 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8598 long max_len
= 65536;
8599 Display
*dpy
= FRAME_X_DISPLAY (f
);
8600 unsigned char *tmp_data
= NULL
;
8601 Atom target_type
= XA_ATOM
;
8606 x_catch_errors (dpy
);
8607 rc
= XGetWindowProperty (dpy
, event
->window
,
8608 event
->atom
, 0, max_len
, False
, target_type
,
8609 &actual_type
, &actual_format
, &actual_size
,
8610 &bytes_remaining
, &tmp_data
);
8612 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8614 if (tmp_data
) XFree (tmp_data
);
8615 x_uncatch_errors ();
8620 x_uncatch_errors ();
8622 for (i
= 0; i
< actual_size
; ++i
)
8624 Atom a
= ((Atom
*)tmp_data
)[i
];
8625 if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8627 if (value
== FULLSCREEN_HEIGHT
)
8628 value
= FULLSCREEN_MAXIMIZED
;
8630 value
= FULLSCREEN_WIDTH
;
8632 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8634 if (value
== FULLSCREEN_WIDTH
)
8635 value
= FULLSCREEN_MAXIMIZED
;
8637 value
= FULLSCREEN_HEIGHT
;
8639 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen_atom
)
8640 value
= FULLSCREEN_BOTH
;
8641 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8648 case FULLSCREEN_WIDTH
:
8651 case FULLSCREEN_HEIGHT
:
8654 case FULLSCREEN_BOTH
:
8657 case FULLSCREEN_MAXIMIZED
:
8662 store_frame_param (f
, Qfullscreen
, lval
);
8663 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8665 if (tmp_data
) XFree (tmp_data
);
8669 /* Check if we need to resize the frame due to a fullscreen request.
8670 If so needed, resize the frame. */
8672 x_check_fullscreen (f
)
8675 if (do_ewmh_fullscreen (f
))
8678 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8679 return; /* Only fullscreen without WM or with EWM hints (above). */
8681 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8683 int width
= FRAME_COLS (f
), height
= FRAME_LINES (f
);
8684 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8686 switch (f
->want_fullscreen
)
8688 /* No difference between these two when there is no WM */
8689 case FULLSCREEN_BOTH
:
8690 case FULLSCREEN_MAXIMIZED
:
8691 width
= x_display_pixel_width (dpyinfo
);
8692 height
= x_display_pixel_height (dpyinfo
);
8694 case FULLSCREEN_WIDTH
:
8695 width
= x_display_pixel_width (dpyinfo
);
8697 case FULLSCREEN_HEIGHT
:
8698 height
= x_display_pixel_height (dpyinfo
);
8701 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8703 change_frame_size (f
, height
, width
, 0, 1, 0);
8704 SET_FRAME_GARBAGED (f
);
8705 cancel_mouse_face (f
);
8710 /* This function is called by x_set_offset to determine whether the window
8711 manager interfered with the positioning of the frame. Type A window
8712 managers position the surrounding window manager decorations a small
8713 amount above and left of the user-supplied position. Type B window
8714 managers position the surrounding window manager decorations at the
8715 user-specified position. If we detect a Type A window manager, we
8716 compensate by moving the window right and down by the proper amount. */
8719 x_check_expected_move (f
, expected_left
, expected_top
)
8724 int current_left
= 0, current_top
= 0;
8726 /* x_real_positions returns the left and top offsets of the outermost
8727 window manager window around the frame. */
8729 x_real_positions (f
, ¤t_left
, ¤t_top
);
8731 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8733 /* It's a "Type A" window manager. */
8738 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8739 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8740 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8742 /* Now fix the mispositioned frame's location. */
8744 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8745 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8747 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8748 adjusted_left
, adjusted_top
);
8750 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8753 /* It's a "Type B" window manager. We don't have to adjust the
8754 frame's position. */
8756 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8760 /* Wait for XGetGeometry to return up-to-date position information for a
8761 recently-moved frame. Call this immediately after calling XMoveWindow.
8762 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8763 frame has been moved to, so we use a fuzzy position comparison instead
8764 of an exact comparison. */
8767 x_sync_with_move (f
, left
, top
, fuzzy
)
8769 int left
, top
, fuzzy
;
8773 while (count
++ < 50)
8775 int current_left
= 0, current_top
= 0;
8777 /* In theory, this call to XSync only needs to happen once, but in
8778 practice, it doesn't seem to work, hence the need for the surrounding
8781 XSync (FRAME_X_DISPLAY (f
), False
);
8782 x_real_positions (f
, ¤t_left
, ¤t_top
);
8786 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8789 if (eabs (current_left
- left
) <= 10
8790 && eabs (current_top
- top
) <= 40)
8793 else if (current_left
== left
&& current_top
== top
)
8797 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8798 will then return up-to-date position info. */
8800 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8804 /* Change the size of frame F's X window to COLS/ROWS in the case F
8805 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8806 top-left-corner window gravity for this size change and subsequent
8807 size changes. Otherwise we leave the window gravity unchanged. */
8810 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8815 int pixelwidth
, pixelheight
;
8817 check_frame_size (f
, &rows
, &cols
);
8818 f
->scroll_bar_actual_width
8819 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8821 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
8822 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
8823 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
8825 compute_fringe_widths (f
, 0);
8827 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
8828 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8830 f
->win_gravity
= NorthWestGravity
;
8831 x_wm_set_size_hint (f
, (long) 0, 0);
8833 XSync (FRAME_X_DISPLAY (f
), False
);
8834 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8835 pixelwidth
, pixelheight
);
8837 /* Now, strictly speaking, we can't be sure that this is accurate,
8838 but the window manager will get around to dealing with the size
8839 change request eventually, and we'll hear how it went when the
8840 ConfigureNotify event gets here.
8842 We could just not bother storing any of this information here,
8843 and let the ConfigureNotify event set everything up, but that
8844 might be kind of confusing to the Lisp code, since size changes
8845 wouldn't be reported in the frame parameters until some random
8846 point in the future when the ConfigureNotify event arrives.
8848 We pass 1 for DELAY since we can't run Lisp code inside of
8850 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8851 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8852 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8854 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8855 receive in the ConfigureNotify event; if we get what we asked
8856 for, then the event won't cause the screen to become garbaged, so
8857 we have to make sure to do it here. */
8858 SET_FRAME_GARBAGED (f
);
8860 XFlush (FRAME_X_DISPLAY (f
));
8864 /* Call this to change the size of frame F's x-window.
8865 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8866 for this size change and subsequent size changes.
8867 Otherwise we leave the window gravity unchanged. */
8870 x_set_window_size (f
, change_gravity
, cols
, rows
)
8878 if (FRAME_GTK_WIDGET (f
))
8879 xg_frame_set_char_size (f
, cols
, rows
);
8881 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8884 if (f
->output_data
.x
->widget
!= NULL
)
8886 /* The x and y position of the widget is clobbered by the
8887 call to XtSetValues within EmacsFrameSetCharSize.
8888 This is a real kludge, but I don't understand Xt so I can't
8889 figure out a correct fix. Can anyone else tell me? -- rms. */
8890 int xpos
= f
->output_data
.x
->widget
->core
.x
;
8891 int ypos
= f
->output_data
.x
->widget
->core
.y
;
8892 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
8893 f
->output_data
.x
->widget
->core
.x
= xpos
;
8894 f
->output_data
.x
->widget
->core
.y
= ypos
;
8897 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8899 #else /* not USE_X_TOOLKIT */
8901 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8903 #endif /* not USE_X_TOOLKIT */
8905 /* If cursor was outside the new size, mark it as off. */
8906 mark_window_cursors_off (XWINDOW (f
->root_window
));
8908 /* Clear out any recollection of where the mouse highlighting was,
8909 since it might be in a place that's outside the new frame size.
8910 Actually checking whether it is outside is a pain in the neck,
8911 so don't try--just let the highlighting be done afresh with new size. */
8912 cancel_mouse_face (f
);
8917 /* Mouse warping. */
8920 x_set_mouse_position (f
, x
, y
)
8926 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8927 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8929 if (pix_x
< 0) pix_x
= 0;
8930 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8932 if (pix_y
< 0) pix_y
= 0;
8933 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8937 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8938 0, 0, 0, 0, pix_x
, pix_y
);
8942 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8945 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
8951 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8952 0, 0, 0, 0, pix_x
, pix_y
);
8956 /* focus shifting, raising and lowering. */
8959 x_focus_on_frame (f
)
8963 /* I don't think that the ICCCM allows programs to do things like this
8964 without the interaction of the window manager. Whatever you end up
8965 doing with this code, do it to x_unfocus_frame too. */
8966 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8967 RevertToPointerRoot
, CurrentTime
);
8976 /* Look at the remarks in x_focus_on_frame. */
8977 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8978 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8979 RevertToPointerRoot
, CurrentTime
);
8983 /* Raise frame F. */
8990 if (f
->async_visible
)
8991 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8993 XFlush (FRAME_X_DISPLAY (f
));
8997 /* Lower frame F. */
9003 if (f
->async_visible
)
9006 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9007 XFlush (FRAME_X_DISPLAY (f
));
9012 /* Activate frame with Extended Window Manager Hints */
9015 x_ewmh_activate_frame (f
)
9018 /* See Window Manager Specification/Extended Window Manager Hints at
9019 http://freedesktop.org/wiki/Specifications/wm-spec */
9021 const char *atom
= "_NET_ACTIVE_WINDOW";
9022 if (f
->async_visible
&& wm_supports (f
, atom
))
9025 XSETFRAME (frame
, f
);
9026 Fx_send_client_event (frame
, make_number (0), frame
,
9027 make_unibyte_string (atom
, strlen (atom
)),
9029 Fcons (make_number (1),
9030 Fcons (make_number (last_user_time
),
9036 XTframe_raise_lower (f
, raise_flag
)
9046 /* XEmbed implementation. */
9049 xembed_set_info (f
, flags
)
9051 enum xembed_info flags
;
9054 unsigned long data
[2];
9056 atom
= XInternAtom (FRAME_X_DISPLAY (f
), "_XEMBED_INFO", False
);
9058 data
[0] = XEMBED_VERSION
;
9061 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), atom
, atom
,
9062 32, PropModeReplace
, (unsigned char *) data
, 2);
9066 xembed_send_message (f
, time
, message
, detail
, data1
, data2
)
9069 enum xembed_message message
;
9076 event
.xclient
.type
= ClientMessage
;
9077 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9078 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9079 event
.xclient
.format
= 32;
9080 event
.xclient
.data
.l
[0] = time
;
9081 event
.xclient
.data
.l
[1] = message
;
9082 event
.xclient
.data
.l
[2] = detail
;
9083 event
.xclient
.data
.l
[3] = data1
;
9084 event
.xclient
.data
.l
[4] = data2
;
9086 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9087 False
, NoEventMask
, &event
);
9088 XSync (FRAME_X_DISPLAY (f
), False
);
9091 /* Change of visibility. */
9093 /* This tries to wait until the frame is really visible.
9094 However, if the window manager asks the user where to position
9095 the frame, this will return before the user finishes doing that.
9096 The frame will not actually be visible at that time,
9097 but it will become visible later when the window manager
9098 finishes with it. */
9101 x_make_frame_visible (f
)
9105 int original_top
, original_left
;
9106 int retry_count
= 2;
9112 type
= x_icon_type (f
);
9114 x_bitmap_icon (f
, type
);
9116 if (! FRAME_VISIBLE_P (f
))
9118 /* We test FRAME_GARBAGED_P here to make sure we don't
9119 call x_set_offset a second time
9120 if we get to x_make_frame_visible a second time
9121 before the window gets really visible. */
9122 if (! FRAME_ICONIFIED_P (f
)
9123 && ! FRAME_X_EMBEDDED_P (f
)
9124 && ! f
->output_data
.x
->asked_for_visible
)
9125 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9127 f
->output_data
.x
->asked_for_visible
= 1;
9129 if (! EQ (Vx_no_window_manager
, Qt
))
9130 x_wm_set_window_state (f
, NormalState
);
9131 #ifdef USE_X_TOOLKIT
9132 if (FRAME_X_EMBEDDED_P (f
))
9133 xembed_set_info (f
, XEMBED_MAPPED
);
9136 /* This was XtPopup, but that did nothing for an iconified frame. */
9137 XtMapWidget (f
->output_data
.x
->widget
);
9139 #else /* not USE_X_TOOLKIT */
9141 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9142 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9144 if (FRAME_X_EMBEDDED_P (f
))
9145 xembed_set_info (f
, XEMBED_MAPPED
);
9147 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9148 #endif /* not USE_GTK */
9149 #endif /* not USE_X_TOOLKIT */
9152 XFlush (FRAME_X_DISPLAY (f
));
9154 /* Synchronize to ensure Emacs knows the frame is visible
9155 before we do anything else. We do this loop with input not blocked
9156 so that incoming events are handled. */
9160 /* This must be before UNBLOCK_INPUT
9161 since events that arrive in response to the actions above
9162 will set it when they are handled. */
9163 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9165 original_left
= f
->left_pos
;
9166 original_top
= f
->top_pos
;
9168 /* This must come after we set COUNT. */
9171 /* We unblock here so that arriving X events are processed. */
9173 /* Now move the window back to where it was "supposed to be".
9174 But don't do it if the gravity is negative.
9175 When the gravity is negative, this uses a position
9176 that is 3 pixels too low. Perhaps that's really the border width.
9178 Don't do this if the window has never been visible before,
9179 because the window manager may choose the position
9180 and we don't want to override it. */
9182 if (! FRAME_VISIBLE_P (f
)
9183 && ! FRAME_ICONIFIED_P (f
)
9184 && ! FRAME_X_EMBEDDED_P (f
)
9185 && f
->win_gravity
== NorthWestGravity
9186 && previously_visible
)
9190 unsigned int width
, height
, border
, depth
;
9194 /* On some window managers (such as FVWM) moving an existing
9195 window, even to the same place, causes the window manager
9196 to introduce an offset. This can cause the window to move
9197 to an unexpected location. Check the geometry (a little
9198 slow here) and then verify that the window is in the right
9199 place. If the window is not in the right place, move it
9200 there, and take the potential window manager hit. */
9201 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9202 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9204 if (original_left
!= x
|| original_top
!= y
)
9205 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9206 original_left
, original_top
);
9211 XSETFRAME (frame
, f
);
9213 /* Wait until the frame is visible. Process X events until a
9214 MapNotify event has been seen, or until we think we won't get a
9215 MapNotify at all.. */
9216 for (count
= input_signal_count
+ 10;
9217 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9219 /* Force processing of queued events. */
9222 /* Machines that do polling rather than SIGIO have been
9223 observed to go into a busy-wait here. So we'll fake an
9224 alarm signal to let the handler know that there's something
9225 to be read. We used to raise a real alarm, but it seems
9226 that the handler isn't always enabled here. This is
9228 if (input_polling_used ())
9230 /* It could be confusing if a real alarm arrives while
9231 processing the fake one. Turn it off and let the
9232 handler reset it. */
9233 extern void poll_for_input_1
P_ ((void));
9234 int old_poll_suppress_count
= poll_suppress_count
;
9235 poll_suppress_count
= 1;
9236 poll_for_input_1 ();
9237 poll_suppress_count
= old_poll_suppress_count
;
9240 /* See if a MapNotify event has been processed. */
9241 FRAME_SAMPLE_VISIBILITY (f
);
9246 (let ((f (selected-frame)))
9250 the frame is not raised with various window managers on
9251 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9252 unknown reason, the call to XtMapWidget is completely ignored.
9253 Mapping the widget a second time works. */
9255 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9260 /* Change from mapped state to withdrawn state. */
9262 /* Make the frame visible (mapped and not iconified). */
9265 x_make_frame_invisible (f
)
9270 /* Use the frame's outermost window, not the one we normally draw on. */
9271 window
= FRAME_OUTER_WINDOW (f
);
9273 /* Don't keep the highlight on an invisible frame. */
9274 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9275 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9279 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9280 that the current position of the window is user-specified, rather than
9281 program-specified, so that when the window is mapped again, it will be
9282 placed at the same location, without forcing the user to position it
9283 by hand again (they have already done that once for this window.) */
9284 x_wm_set_size_hint (f
, (long) 0, 1);
9287 if (FRAME_GTK_OUTER_WIDGET (f
))
9288 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9291 if (FRAME_X_EMBEDDED_P (f
))
9292 xembed_set_info (f
, 0);
9297 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9298 DefaultScreen (FRAME_X_DISPLAY (f
))))
9300 UNBLOCK_INPUT_RESIGNAL
;
9301 error ("Can't notify window manager of window withdrawal");
9305 /* We can't distinguish this from iconification
9306 just by the event that we get from the server.
9307 So we can't win using the usual strategy of letting
9308 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9309 and synchronize with the server to make sure we agree. */
9311 FRAME_ICONIFIED_P (f
) = 0;
9312 f
->async_visible
= 0;
9313 f
->async_iconified
= 0;
9320 /* Change window state from mapped to iconified. */
9329 /* Don't keep the highlight on an invisible frame. */
9330 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9331 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9333 if (f
->async_iconified
)
9338 FRAME_SAMPLE_VISIBILITY (f
);
9340 type
= x_icon_type (f
);
9342 x_bitmap_icon (f
, type
);
9345 if (FRAME_GTK_OUTER_WIDGET (f
))
9347 if (! FRAME_VISIBLE_P (f
))
9348 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9350 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9353 f
->async_iconified
= 1;
9354 f
->async_visible
= 0;
9360 #ifdef USE_X_TOOLKIT
9362 if (! FRAME_VISIBLE_P (f
))
9364 if (! EQ (Vx_no_window_manager
, Qt
))
9365 x_wm_set_window_state (f
, IconicState
);
9366 /* This was XtPopup, but that did nothing for an iconified frame. */
9367 XtMapWidget (f
->output_data
.x
->widget
);
9368 /* The server won't give us any event to indicate
9369 that an invisible frame was changed to an icon,
9370 so we have to record it here. */
9373 f
->async_iconified
= 1;
9374 f
->async_visible
= 0;
9379 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9380 XtWindow (f
->output_data
.x
->widget
),
9381 DefaultScreen (FRAME_X_DISPLAY (f
)));
9385 error ("Can't notify window manager of iconification");
9387 f
->async_iconified
= 1;
9388 f
->async_visible
= 0;
9392 XFlush (FRAME_X_DISPLAY (f
));
9394 #else /* not USE_X_TOOLKIT */
9396 /* Make sure the X server knows where the window should be positioned,
9397 in case the user deiconifies with the window manager. */
9398 if (! FRAME_VISIBLE_P (f
)
9399 && ! FRAME_ICONIFIED_P (f
)
9400 && ! FRAME_X_EMBEDDED_P (f
))
9401 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9403 /* Since we don't know which revision of X we're running, we'll use both
9404 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9406 /* X11R4: send a ClientMessage to the window manager using the
9407 WM_CHANGE_STATE type. */
9411 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9412 message
.xclient
.type
= ClientMessage
;
9413 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9414 message
.xclient
.format
= 32;
9415 message
.xclient
.data
.l
[0] = IconicState
;
9417 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9418 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9420 SubstructureRedirectMask
| SubstructureNotifyMask
,
9423 UNBLOCK_INPUT_RESIGNAL
;
9424 error ("Can't notify window manager of iconification");
9428 /* X11R3: set the initial_state field of the window manager hints to
9430 x_wm_set_window_state (f
, IconicState
);
9432 if (!FRAME_VISIBLE_P (f
))
9434 /* If the frame was withdrawn, before, we must map it. */
9435 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9438 f
->async_iconified
= 1;
9439 f
->async_visible
= 0;
9441 XFlush (FRAME_X_DISPLAY (f
));
9443 #endif /* not USE_X_TOOLKIT */
9447 /* Free X resources of frame F. */
9450 x_free_frame_resources (f
)
9453 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9455 struct scroll_bar
*b
;
9459 /* If a display connection is dead, don't try sending more
9460 commands to the X server. */
9461 if (dpyinfo
->display
)
9463 /* We must free faces before destroying windows because some
9464 font-driver (e.g. xft) access a window while finishing a
9466 if (FRAME_FACE_CACHE (f
))
9467 free_frame_faces (f
);
9469 if (f
->output_data
.x
->icon_desc
)
9470 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9472 #ifdef USE_X_TOOLKIT
9473 /* Explicitly destroy the scroll bars of the frame. Without
9474 this, we get "BadDrawable" errors from the toolkit later on,
9475 presumably from expose events generated for the disappearing
9476 toolkit scroll bars. */
9477 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9479 b
= XSCROLL_BAR (bar
);
9480 x_scroll_bar_remove (b
);
9489 #ifdef USE_X_TOOLKIT
9490 if (f
->output_data
.x
->widget
)
9492 XtDestroyWidget (f
->output_data
.x
->widget
);
9493 f
->output_data
.x
->widget
= NULL
;
9495 /* Tooltips don't have widgets, only a simple X window, even if
9496 we are using a toolkit. */
9497 else if (FRAME_X_WINDOW (f
))
9498 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9500 free_frame_menubar (f
);
9501 #else /* !USE_X_TOOLKIT */
9504 /* In the GTK version, tooltips are normal X
9505 frames. We must check and free both types. */
9506 if (FRAME_GTK_OUTER_WIDGET (f
))
9508 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9509 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9510 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9512 #endif /* USE_GTK */
9514 if (FRAME_X_WINDOW (f
))
9515 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9516 #endif /* !USE_X_TOOLKIT */
9518 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9519 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9520 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9521 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9522 unload_color (f
, f
->output_data
.x
->border_pixel
);
9523 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9525 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9526 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9527 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9528 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9529 #ifdef USE_TOOLKIT_SCROLL_BARS
9530 /* Scrollbar shadow colors. */
9531 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9532 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9533 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9534 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9535 #endif /* USE_TOOLKIT_SCROLL_BARS */
9536 if (f
->output_data
.x
->white_relief
.allocated_p
)
9537 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9538 if (f
->output_data
.x
->black_relief
.allocated_p
)
9539 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9542 XFlush (FRAME_X_DISPLAY (f
));
9545 xfree (f
->output_data
.x
->saved_menu_event
);
9546 xfree (f
->output_data
.x
);
9547 f
->output_data
.x
= NULL
;
9549 if (f
== dpyinfo
->x_focus_frame
)
9550 dpyinfo
->x_focus_frame
= 0;
9551 if (f
== dpyinfo
->x_focus_event_frame
)
9552 dpyinfo
->x_focus_event_frame
= 0;
9553 if (f
== dpyinfo
->x_highlight_frame
)
9554 dpyinfo
->x_highlight_frame
= 0;
9556 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9558 dpyinfo
->mouse_face_beg_row
9559 = dpyinfo
->mouse_face_beg_col
= -1;
9560 dpyinfo
->mouse_face_end_row
9561 = dpyinfo
->mouse_face_end_col
= -1;
9562 dpyinfo
->mouse_face_window
= Qnil
;
9563 dpyinfo
->mouse_face_deferred_gc
= 0;
9564 dpyinfo
->mouse_face_mouse_frame
= 0;
9571 /* Destroy the X window of frame F. */
9574 x_destroy_window (f
)
9577 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9579 /* If a display connection is dead, don't try sending more
9580 commands to the X server. */
9581 if (dpyinfo
->display
!= 0)
9582 x_free_frame_resources (f
);
9584 dpyinfo
->reference_count
--;
9588 /* Setting window manager hints. */
9590 /* Set the normal size hints for the window manager, for frame F.
9591 FLAGS is the flags word to use--or 0 meaning preserve the flags
9592 that the window now has.
9593 If USER_POSITION is nonzero, we set the USPosition
9594 flag (this is useful when FLAGS is 0).
9595 The GTK version is in gtkutils.c */
9599 x_wm_set_size_hint (f
, flags
, user_position
)
9604 XSizeHints size_hints
;
9606 #ifdef USE_X_TOOLKIT
9609 Dimension widget_width
, widget_height
;
9612 Window window
= FRAME_OUTER_WINDOW (f
);
9614 /* Setting PMaxSize caused various problems. */
9615 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9617 size_hints
.x
= f
->left_pos
;
9618 size_hints
.y
= f
->top_pos
;
9620 #ifdef USE_X_TOOLKIT
9621 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9622 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9623 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9624 size_hints
.height
= widget_height
;
9625 size_hints
.width
= widget_width
;
9626 #else /* not USE_X_TOOLKIT */
9627 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9628 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9629 #endif /* not USE_X_TOOLKIT */
9631 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9632 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9633 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9634 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9635 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9636 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9638 /* Calculate the base and minimum sizes.
9640 (When we use the X toolkit, we don't do it here.
9641 Instead we copy the values that the widgets are using, below.) */
9642 #ifndef USE_X_TOOLKIT
9644 int base_width
, base_height
;
9645 int min_rows
= 0, min_cols
= 0;
9647 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9648 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9650 check_frame_size (f
, &min_rows
, &min_cols
);
9652 /* The window manager uses the base width hints to calculate the
9653 current number of rows and columns in the frame while
9654 resizing; min_width and min_height aren't useful for this
9655 purpose, since they might not give the dimensions for a
9656 zero-row, zero-column frame.
9658 We use the base_width and base_height members if we have
9659 them; otherwise, we set the min_width and min_height members
9660 to the size for a zero x zero frame. */
9662 size_hints
.flags
|= PBaseSize
;
9663 size_hints
.base_width
= base_width
;
9664 size_hints
.base_height
= base_height
;
9665 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9666 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9669 /* If we don't need the old flags, we don't need the old hint at all. */
9672 size_hints
.flags
|= flags
;
9675 #endif /* not USE_X_TOOLKIT */
9678 XSizeHints hints
; /* Sometimes I hate X Windows... */
9679 long supplied_return
;
9682 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9685 #ifdef USE_X_TOOLKIT
9686 size_hints
.base_height
= hints
.base_height
;
9687 size_hints
.base_width
= hints
.base_width
;
9688 size_hints
.min_height
= hints
.min_height
;
9689 size_hints
.min_width
= hints
.min_width
;
9693 size_hints
.flags
|= flags
;
9698 if (hints
.flags
& PSize
)
9699 size_hints
.flags
|= PSize
;
9700 if (hints
.flags
& PPosition
)
9701 size_hints
.flags
|= PPosition
;
9702 if (hints
.flags
& USPosition
)
9703 size_hints
.flags
|= USPosition
;
9704 if (hints
.flags
& USSize
)
9705 size_hints
.flags
|= USSize
;
9709 #ifndef USE_X_TOOLKIT
9714 size_hints
.win_gravity
= f
->win_gravity
;
9715 size_hints
.flags
|= PWinGravity
;
9719 size_hints
.flags
&= ~ PPosition
;
9720 size_hints
.flags
|= USPosition
;
9722 #endif /* PWinGravity */
9724 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9726 #endif /* not USE_GTK */
9728 /* Used for IconicState or NormalState */
9731 x_wm_set_window_state (f
, state
)
9735 #ifdef USE_X_TOOLKIT
9738 XtSetArg (al
[0], XtNinitialState
, state
);
9739 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9740 #else /* not USE_X_TOOLKIT */
9741 Window window
= FRAME_X_WINDOW (f
);
9743 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9744 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9746 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9747 #endif /* not USE_X_TOOLKIT */
9751 x_wm_set_icon_pixmap (f
, pixmap_id
)
9755 Pixmap icon_pixmap
, icon_mask
;
9757 #ifndef USE_X_TOOLKIT
9758 Window window
= FRAME_OUTER_WINDOW (f
);
9763 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9764 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9765 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9766 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9770 /* It seems there is no way to turn off use of an icon
9778 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9782 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9786 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9787 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9788 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9789 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9792 #else /* not USE_X_TOOLKIT && not USE_GTK */
9794 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9795 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9797 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9801 x_wm_set_icon_position (f
, icon_x
, icon_y
)
9805 Window window
= FRAME_OUTER_WINDOW (f
);
9807 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9808 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9809 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9811 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9815 /***********************************************************************
9817 ***********************************************************************/
9821 /* Check that FONT is valid on frame F. It is if it can be found in F's
9825 x_check_font (f
, font
)
9831 xassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9832 if (font
->driver
->check
)
9833 xassert (font
->driver
->check (f
, font
) == 0);
9836 #endif /* GLYPH_DEBUG != 0 */
9839 /***********************************************************************
9841 ***********************************************************************/
9843 #ifdef USE_X_TOOLKIT
9844 static XrmOptionDescRec emacs_options
[] = {
9845 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9846 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9848 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9849 XrmoptionSepArg
, NULL
},
9850 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9852 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9853 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9854 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9855 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9856 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9857 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9858 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9861 /* Whether atimer for Xt timeouts is activated or not. */
9863 static int x_timeout_atimer_activated_flag
;
9865 #endif /* USE_X_TOOLKIT */
9867 static int x_initialized
;
9870 static int x_session_initialized
;
9873 /* Test whether two display-name strings agree up to the dot that separates
9874 the screen number from the server number. */
9876 same_x_server (name1
, name2
)
9877 const char *name1
, *name2
;
9880 const unsigned char *system_name
= SDATA (Vsystem_name
);
9881 int system_name_length
= strlen (system_name
);
9882 int length_until_period
= 0;
9884 while (system_name
[length_until_period
] != 0
9885 && system_name
[length_until_period
] != '.')
9886 length_until_period
++;
9888 /* Treat `unix' like an empty host name. */
9889 if (! strncmp (name1
, "unix:", 5))
9891 if (! strncmp (name2
, "unix:", 5))
9893 /* Treat this host's name like an empty host name. */
9894 if (! strncmp (name1
, system_name
, system_name_length
)
9895 && name1
[system_name_length
] == ':')
9896 name1
+= system_name_length
;
9897 if (! strncmp (name2
, system_name
, system_name_length
)
9898 && name2
[system_name_length
] == ':')
9899 name2
+= system_name_length
;
9900 /* Treat this host's domainless name like an empty host name. */
9901 if (! strncmp (name1
, system_name
, length_until_period
)
9902 && name1
[length_until_period
] == ':')
9903 name1
+= length_until_period
;
9904 if (! strncmp (name2
, system_name
, length_until_period
)
9905 && name2
[length_until_period
] == ':')
9906 name2
+= length_until_period
;
9908 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9912 if (seen_colon
&& *name1
== '.')
9916 && (*name1
== '.' || *name1
== '\0')
9917 && (*name2
== '.' || *name2
== '\0'));
9920 /* Count number of set bits in mask and number of bits to shift to
9921 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9924 get_bits_and_offset (mask
, bits
, offset
)
9948 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9949 But don't permanently open it, just test its availability. */
9952 x_display_ok (display
)
9953 const char *display
;
9958 dpy
= XOpenDisplay (display
);
9960 XCloseDisplay (dpy
);
9966 /* Open a connection to X display DISPLAY_NAME, and return
9967 the structure that describes the open display.
9968 If we cannot contact the display, return null. */
9970 struct x_display_info
*
9971 x_term_init (display_name
, xrm_option
, resource_name
)
9972 Lisp_Object display_name
;
9974 char *resource_name
;
9978 struct terminal
*terminal
;
9979 struct x_display_info
*dpyinfo
;
9990 if (! x_display_ok (SDATA (display_name
)))
9991 error ("Display %s can't be opened", SDATA (display_name
));
9997 char *argv
[NUM_ARGV
];
9998 char **argv2
= argv
;
10001 #ifndef HAVE_GTK_MULTIDISPLAY
10002 if (!EQ (Vinitial_window_system
, Qx
))
10003 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
10006 if (x_initialized
++ > 1)
10008 #ifdef HAVE_GTK_MULTIDISPLAY
10009 /* Opening another display. If xg_display_open returns less
10010 than zero, we are probably on GTK 2.0, which can only handle
10011 one display. GTK 2.2 or later can handle more than one. */
10012 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
10014 error ("Sorry, this version of GTK can only handle one display");
10018 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10022 argv
[argc
++] = initial_argv
[0];
10024 if (! NILP (display_name
))
10026 argv
[argc
++] = "--display";
10027 argv
[argc
++] = SDATA (display_name
);
10030 argv
[argc
++] = "--name";
10031 argv
[argc
++] = resource_name
;
10033 XSetLocaleModifiers ("");
10035 gtk_init (&argc
, &argv2
);
10037 /* gtk_init does set_locale. We must fix locale after calling it. */
10041 dpy
= GDK_DISPLAY ();
10043 /* NULL window -> events for all windows go to our function */
10044 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10046 /* Load our own gtkrc if it exists. */
10048 char *file
= "~/.emacs.d/gtkrc";
10049 Lisp_Object s
, abs_file
;
10051 s
= make_string (file
, strlen (file
));
10052 abs_file
= Fexpand_file_name (s
, Qnil
);
10054 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10055 gtk_rc_parse (SDATA (abs_file
));
10058 XSetErrorHandler (x_error_handler
);
10059 XSetIOErrorHandler (x_io_error_quitter
);
10062 #else /* not USE_GTK */
10063 #ifdef USE_X_TOOLKIT
10064 /* weiner@footloose.sps.mot.com reports that this causes
10066 X protocol error: BadAtom (invalid Atom parameter)
10067 on protocol request 18skiloaf.
10068 So let's not use it until R6. */
10069 #ifdef HAVE_X11XTR6
10070 XtSetLanguageProc (NULL
, NULL
, NULL
);
10081 argv
[argc
++] = "-xrm";
10082 argv
[argc
++] = xrm_option
;
10084 turn_on_atimers (0);
10085 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
10086 resource_name
, EMACS_CLASS
,
10087 emacs_options
, XtNumber (emacs_options
),
10089 turn_on_atimers (1);
10091 #ifdef HAVE_X11XTR6
10092 /* I think this is to compensate for XtSetLanguageProc. */
10097 #else /* not USE_X_TOOLKIT */
10098 XSetLocaleModifiers ("");
10099 dpy
= XOpenDisplay (SDATA (display_name
));
10100 #endif /* not USE_X_TOOLKIT */
10101 #endif /* not USE_GTK*/
10103 /* Detect failure. */
10110 /* We have definitely succeeded. Record the new connection. */
10112 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
10113 bzero (dpyinfo
, sizeof *dpyinfo
);
10115 terminal
= x_create_terminal (dpyinfo
);
10118 struct x_display_info
*share
;
10121 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10122 share
= share
->next
, tail
= XCDR (tail
))
10123 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
10124 SDATA (display_name
)))
10127 terminal
->kboard
= share
->terminal
->kboard
;
10130 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
10131 init_kboard (terminal
->kboard
);
10132 terminal
->kboard
->Vwindow_system
= Qx
;
10133 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10135 char *vendor
= ServerVendor (dpy
);
10136 /* Temporarily hide the partially initialized terminal */
10137 terminal_list
= terminal
->next_terminal
;
10139 terminal
->kboard
->Vsystem_key_alist
10140 = call1 (Qvendor_specific_keysyms
,
10141 vendor
? build_string (vendor
) : empty_unibyte_string
);
10143 terminal
->next_terminal
= terminal_list
;
10144 terminal_list
= terminal
;
10147 terminal
->kboard
->next_kboard
= all_kboards
;
10148 all_kboards
= terminal
->kboard
;
10149 /* Don't let the initial kboard remain current longer than necessary.
10150 That would cause problems if a file loaded on startup tries to
10151 prompt in the mini-buffer. */
10152 if (current_kboard
== initial_kboard
)
10153 current_kboard
= terminal
->kboard
;
10155 terminal
->kboard
->reference_count
++;
10158 /* Put this display on the chain. */
10159 dpyinfo
->next
= x_display_list
;
10160 x_display_list
= dpyinfo
;
10162 /* Put it on x_display_name_list as well, to keep them parallel. */
10163 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10164 x_display_name_list
);
10165 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10167 dpyinfo
->display
= dpy
;
10169 /* Set the name of the terminal. */
10170 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
10171 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
10172 terminal
->name
[SBYTES (display_name
)] = 0;
10175 XSetAfterFunction (x_current_display
, x_trace_wire
);
10179 = (char *) xmalloc (SBYTES (Vinvocation_name
)
10180 + SBYTES (Vsystem_name
)
10182 sprintf (dpyinfo
->x_id_name
, "%s@%s",
10183 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10185 /* Figure out which modifier bits mean what. */
10186 x_find_modifier_meanings (dpyinfo
);
10188 /* Get the scroll bar cursor. */
10190 /* We must create a GTK cursor, it is required for GTK widgets. */
10191 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10192 #endif /* USE_GTK */
10194 dpyinfo
->vertical_scroll_bar_cursor
10195 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10197 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10198 resource_name
, EMACS_CLASS
);
10199 #ifdef HAVE_XRMSETDATABASE
10200 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10202 dpyinfo
->display
->db
= xrdb
;
10204 /* Put the rdb where we can find it in a way that works on
10206 dpyinfo
->xrdb
= xrdb
;
10208 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10209 DefaultScreen (dpyinfo
->display
));
10210 select_visual (dpyinfo
);
10211 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10212 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10213 dpyinfo
->client_leader_window
= 0;
10214 dpyinfo
->grabbed
= 0;
10215 dpyinfo
->reference_count
= 0;
10216 dpyinfo
->icon_bitmap_id
= -1;
10217 dpyinfo
->n_fonts
= 0;
10218 dpyinfo
->bitmaps
= 0;
10219 dpyinfo
->bitmaps_size
= 0;
10220 dpyinfo
->bitmaps_last
= 0;
10221 dpyinfo
->scratch_cursor_gc
= 0;
10222 dpyinfo
->mouse_face_mouse_frame
= 0;
10223 dpyinfo
->mouse_face_deferred_gc
= 0;
10224 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10225 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10226 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10227 dpyinfo
->mouse_face_window
= Qnil
;
10228 dpyinfo
->mouse_face_overlay
= Qnil
;
10229 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10230 dpyinfo
->mouse_face_defer
= 0;
10231 dpyinfo
->mouse_face_hidden
= 0;
10232 dpyinfo
->x_focus_frame
= 0;
10233 dpyinfo
->x_focus_event_frame
= 0;
10234 dpyinfo
->x_highlight_frame
= 0;
10235 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10237 /* See if we can construct pixel values from RGB values. */
10238 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10239 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10241 if (dpyinfo
->visual
->class == TrueColor
)
10243 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10244 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10245 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10246 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10247 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10248 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10251 /* See if a private colormap is requested. */
10252 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10254 if (dpyinfo
->visual
->class == PseudoColor
)
10257 value
= display_x_get_resource (dpyinfo
,
10258 build_string ("privateColormap"),
10259 build_string ("PrivateColormap"),
10261 if (STRINGP (value
)
10262 && (!strcmp (SDATA (value
), "true")
10263 || !strcmp (SDATA (value
), "on")))
10264 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10268 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10269 dpyinfo
->visual
, AllocNone
);
10272 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10273 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10274 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10275 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10276 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10277 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10278 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10279 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10280 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10283 dpyinfo
->Xatom_wm_protocols
10284 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10285 dpyinfo
->Xatom_wm_take_focus
10286 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10287 dpyinfo
->Xatom_wm_save_yourself
10288 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10289 dpyinfo
->Xatom_wm_delete_window
10290 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10291 dpyinfo
->Xatom_wm_change_state
10292 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10293 dpyinfo
->Xatom_wm_configure_denied
10294 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10295 dpyinfo
->Xatom_wm_window_moved
10296 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10297 dpyinfo
->Xatom_wm_client_leader
10298 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10299 dpyinfo
->Xatom_editres
10300 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10301 dpyinfo
->Xatom_CLIPBOARD
10302 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10303 dpyinfo
->Xatom_TIMESTAMP
10304 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10305 dpyinfo
->Xatom_TEXT
10306 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10307 dpyinfo
->Xatom_COMPOUND_TEXT
10308 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10309 dpyinfo
->Xatom_UTF8_STRING
10310 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10311 dpyinfo
->Xatom_DELETE
10312 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10313 dpyinfo
->Xatom_MULTIPLE
10314 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10315 dpyinfo
->Xatom_INCR
10316 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10317 dpyinfo
->Xatom_EMACS_TMP
10318 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10319 dpyinfo
->Xatom_TARGETS
10320 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10321 dpyinfo
->Xatom_NULL
10322 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10323 dpyinfo
->Xatom_ATOM_PAIR
10324 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10325 /* For properties of font. */
10326 dpyinfo
->Xatom_PIXEL_SIZE
10327 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10328 dpyinfo
->Xatom_AVERAGE_WIDTH
10329 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10330 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10331 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10332 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10333 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10334 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10335 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10337 /* Ghostscript support. */
10338 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10339 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10341 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10344 dpyinfo
->Xatom_XEMBED
= XInternAtom (dpyinfo
->display
, "_XEMBED",
10347 dpyinfo
->Xatom_net_wm_state
10348 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE", False
);
10349 dpyinfo
->Xatom_net_wm_state_fullscreen_atom
10350 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_FULLSCREEN", False
);
10351 dpyinfo
->Xatom_net_wm_state_maximized_horz
10352 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_HORZ", False
);
10353 dpyinfo
->Xatom_net_wm_state_maximized_vert
10354 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_VERT", False
);
10355 dpyinfo
->Xatom_net_wm_state_sticky
10356 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_STICKY", False
);
10358 dpyinfo
->cut_buffers_initialized
= 0;
10360 dpyinfo
->x_dnd_atoms_size
= 8;
10361 dpyinfo
->x_dnd_atoms_length
= 0;
10362 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
10363 * dpyinfo
->x_dnd_atoms_size
);
10365 dpyinfo
->net_supported_atoms
= NULL
;
10366 dpyinfo
->nr_net_supported_atoms
= 0;
10367 dpyinfo
->net_supported_window
= 0;
10369 connection
= ConnectionNumber (dpyinfo
->display
);
10370 dpyinfo
->connection
= connection
;
10373 extern int gray_bitmap_width
, gray_bitmap_height
;
10374 extern char *gray_bitmap_bits
;
10376 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10378 gray_bitmap_width
, gray_bitmap_height
,
10379 (unsigned long) 1, (unsigned long) 0, 1);
10383 xim_initialize (dpyinfo
, resource_name
);
10386 #ifdef subprocesses
10387 /* This is only needed for distinguishing keyboard and process input. */
10388 if (connection
!= 0)
10389 add_keyboard_wait_descriptor (connection
);
10393 fcntl (connection
, F_SETOWN
, getpid ());
10394 #endif /* ! defined (F_SETOWN) */
10397 if (interrupt_input
)
10398 init_sigio (connection
);
10399 #endif /* ! defined (SIGIO) */
10403 Display
*dpy
= dpyinfo
->display
;
10404 XrmValue d
, fr
, to
;
10407 d
.addr
= (XPointer
)&dpy
;
10408 d
.size
= sizeof (Display
*);
10409 fr
.addr
= XtDefaultFont
;
10410 fr
.size
= sizeof (XtDefaultFont
);
10411 to
.size
= sizeof (Font
*);
10412 to
.addr
= (XPointer
)&font
;
10413 x_catch_errors (dpy
);
10414 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10416 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10417 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10418 x_uncatch_errors ();
10422 /* See if we should run in synchronous mode. This is useful
10423 for debugging X code. */
10426 value
= display_x_get_resource (dpyinfo
,
10427 build_string ("synchronous"),
10428 build_string ("Synchronous"),
10430 if (STRINGP (value
)
10431 && (!strcmp (SDATA (value
), "true")
10432 || !strcmp (SDATA (value
), "on")))
10433 XSynchronize (dpyinfo
->display
, True
);
10438 value
= display_x_get_resource (dpyinfo
,
10439 build_string ("useXIM"),
10440 build_string ("UseXIM"),
10443 if (STRINGP (value
)
10444 && (!strcmp (SDATA (value
), "false")
10445 || !strcmp (SDATA (value
), "off")))
10448 if (STRINGP (value
)
10449 && (!strcmp (SDATA (value
), "true")
10450 || !strcmp (SDATA (value
), "on")))
10456 /* Only do this for the very first display in the Emacs session.
10457 Ignore X session management when Emacs was first started on a
10459 if (terminal
->id
== 1)
10460 x_session_initialize (dpyinfo
);
10468 /* Get rid of display DPYINFO, deleting all frames on it,
10469 and without sending any more commands to the X server. */
10472 x_delete_display (dpyinfo
)
10473 struct x_display_info
*dpyinfo
;
10476 struct terminal
*t
;
10478 /* Close all frames and delete the generic struct terminal for this
10480 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10481 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10484 /* Close X session management when we close its display. */
10485 if (t
->id
== 1 && x_session_have_connection ())
10488 delete_terminal (t
);
10492 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10494 /* Discard this display from x_display_name_list and x_display_list.
10495 We can't use Fdelq because that can quit. */
10496 if (! NILP (x_display_name_list
)
10497 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10498 x_display_name_list
= XCDR (x_display_name_list
);
10503 tail
= x_display_name_list
;
10504 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10506 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10508 XSETCDR (tail
, XCDR (XCDR (tail
)));
10511 tail
= XCDR (tail
);
10515 if (next_noop_dpyinfo
== dpyinfo
)
10516 next_noop_dpyinfo
= dpyinfo
->next
;
10518 if (x_display_list
== dpyinfo
)
10519 x_display_list
= dpyinfo
->next
;
10522 struct x_display_info
*tail
;
10524 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10525 if (tail
->next
== dpyinfo
)
10526 tail
->next
= tail
->next
->next
;
10529 xfree (dpyinfo
->x_id_name
);
10530 xfree (dpyinfo
->x_dnd_atoms
);
10531 xfree (dpyinfo
->color_cells
);
10535 #ifdef USE_X_TOOLKIT
10537 /* Atimer callback function for TIMER. Called every 0.1s to process
10538 Xt timeouts, if needed. We must avoid calling XtAppPending as
10539 much as possible because that function does an implicit XFlush
10540 that slows us down. */
10543 x_process_timeouts (timer
)
10544 struct atimer
*timer
;
10547 x_timeout_atimer_activated_flag
= 0;
10548 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10550 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10551 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10552 /* Reactivate the atimer for next time. */
10553 x_activate_timeout_atimer ();
10558 /* Install an asynchronous timer that processes Xt timeout events
10559 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10560 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10561 function whenever these variables are set. This is necessary
10562 because some widget sets use timeouts internally, for example the
10563 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10564 processed, these widgets don't behave normally. */
10567 x_activate_timeout_atimer ()
10570 if (!x_timeout_atimer_activated_flag
)
10572 EMACS_TIME interval
;
10574 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10575 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10576 x_timeout_atimer_activated_flag
= 1;
10581 #endif /* USE_X_TOOLKIT */
10584 /* Set up use of X before we make the first connection. */
10586 extern frame_parm_handler x_frame_parm_handlers
[];
10588 static struct redisplay_interface x_redisplay_interface
=
10590 x_frame_parm_handlers
,
10594 x_clear_end_of_line
,
10596 x_after_update_window_line
,
10597 x_update_window_begin
,
10598 x_update_window_end
,
10604 0, /* flush_display_optional */
10606 x_clear_window_mouse_face
,
10607 x_get_glyph_overhangs
,
10608 x_fix_overlapping_area
,
10609 x_draw_fringe_bitmap
,
10610 0, /* define_fringe_bitmap */
10611 0, /* destroy_fringe_bitmap */
10612 x_compute_glyph_string_overhangs
,
10613 x_draw_glyph_string
,
10614 x_define_frame_cursor
,
10615 x_clear_frame_area
,
10616 x_draw_window_cursor
,
10617 x_draw_vertical_window_border
,
10618 x_shift_glyphs_for_insert
10622 /* This function is called when the last frame on a display is deleted. */
10624 x_delete_terminal (struct terminal
*terminal
)
10626 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10629 /* Protect against recursive calls. delete_frame in
10630 delete_terminal calls us back when it deletes our last frame. */
10631 if (!terminal
->name
)
10636 /* We must close our connection to the XIM server before closing the
10639 xim_close_dpy (dpyinfo
);
10642 /* If called from x_connection_closed, the display may already be closed
10643 and dpyinfo->display was set to 0 to indicate that. */
10644 if (dpyinfo
->display
)
10646 x_destroy_all_bitmaps (dpyinfo
);
10647 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10649 /* Whether or not XCloseDisplay destroys the associated resource
10650 database depends on the version of libX11. To avoid both
10651 crash and memory leak, we dissociate the database from the
10652 display and then destroy dpyinfo->xrdb ourselves.
10654 Unfortunately, the above strategy does not work in some
10655 situations due to a bug in newer versions of libX11: because
10656 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10657 dpy->db is NULL, XCloseDisplay destroys the associated
10658 database whereas it has not been created by XGetDefault
10659 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10660 don't destroy the database here in order to avoid the crash
10661 in the above situations for now, though that may cause memory
10662 leaks in other situations. */
10664 #ifdef HAVE_XRMSETDATABASE
10665 XrmSetDatabase (dpyinfo
->display
, NULL
);
10667 dpyinfo
->display
->db
= NULL
;
10669 /* We used to call XrmDestroyDatabase from x_delete_display, but
10670 some older versions of libX11 crash if we call it after
10671 closing all the displays. */
10672 XrmDestroyDatabase (dpyinfo
->xrdb
);
10676 xg_display_close (dpyinfo
->display
);
10678 #ifdef USE_X_TOOLKIT
10679 XtCloseDisplay (dpyinfo
->display
);
10681 XCloseDisplay (dpyinfo
->display
);
10683 #endif /* ! USE_GTK */
10686 x_delete_display (dpyinfo
);
10690 /* Create a struct terminal, initialize it with the X11 specific
10691 functions and make DISPLAY->TERMINAL point to it. */
10693 static struct terminal
*
10694 x_create_terminal (struct x_display_info
*dpyinfo
)
10696 struct terminal
*terminal
;
10698 terminal
= create_terminal ();
10700 terminal
->type
= output_x_window
;
10701 terminal
->display_info
.x
= dpyinfo
;
10702 dpyinfo
->terminal
= terminal
;
10704 /* kboard is initialized in x_term_init. */
10706 terminal
->clear_frame_hook
= x_clear_frame
;
10707 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10708 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10709 terminal
->ring_bell_hook
= XTring_bell
;
10710 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10711 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10712 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
10713 terminal
->update_begin_hook
= x_update_begin
;
10714 terminal
->update_end_hook
= x_update_end
;
10715 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
10716 terminal
->read_socket_hook
= XTread_socket
;
10717 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10718 terminal
->mouse_position_hook
= XTmouse_position
;
10719 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10720 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10721 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10722 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10723 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10724 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10725 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10727 terminal
->delete_frame_hook
= x_destroy_window
;
10728 terminal
->delete_terminal_hook
= x_delete_terminal
;
10730 terminal
->rif
= &x_redisplay_interface
;
10731 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10732 terminal
->char_ins_del_ok
= 1;
10733 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10734 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10735 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10747 last_tool_bar_item
= -1;
10748 any_help_event_p
= 0;
10749 ignore_next_mouse_click_timeout
= 0;
10751 x_session_initialized
= 0;
10755 current_count
= -1;
10758 /* Try to use interrupt input; if we can't, then start polling. */
10759 Fset_input_interrupt_mode (Qt
);
10761 #ifdef USE_X_TOOLKIT
10762 XtToolkitInitialize ();
10764 Xt_app_con
= XtCreateApplicationContext ();
10766 /* Register a converter from strings to pixels, which uses
10767 Emacs' color allocation infrastructure. */
10768 XtAppSetTypeConverter (Xt_app_con
,
10769 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10770 cvt_string_to_pixel_args
,
10771 XtNumber (cvt_string_to_pixel_args
),
10772 XtCacheByDisplay
, cvt_pixel_dtor
);
10774 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10777 #ifdef USE_TOOLKIT_SCROLL_BARS
10779 xaw3d_arrow_scroll
= False
;
10780 xaw3d_pick_top
= True
;
10784 /* Note that there is no real way portable across R3/R4 to get the
10785 original error handler. */
10786 XSetErrorHandler (x_error_handler
);
10787 XSetIOErrorHandler (x_io_error_quitter
);
10789 signal (SIGPIPE
, x_connection_signal
);
10796 x_error_message
= NULL
;
10798 staticpro (&x_display_name_list
);
10799 x_display_name_list
= Qnil
;
10801 staticpro (&last_mouse_scroll_bar
);
10802 last_mouse_scroll_bar
= Qnil
;
10804 staticpro (&Qvendor_specific_keysyms
);
10805 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
10807 staticpro (&Qlatin_1
);
10808 Qlatin_1
= intern ("latin-1");
10810 staticpro (&last_mouse_press_frame
);
10811 last_mouse_press_frame
= Qnil
;
10814 xg_default_icon_file
= build_string ("icons/hicolor/scalable/apps/emacs.svg");
10815 staticpro (&xg_default_icon_file
);
10817 Qx_gtk_map_stock
= intern ("x-gtk-map-stock");
10818 staticpro (&Qx_gtk_map_stock
);
10821 DEFVAR_BOOL ("x-use-underline-position-properties",
10822 &x_use_underline_position_properties
,
10823 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10824 A value of nil means ignore them. If you encounter fonts with bogus
10825 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10826 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10827 to override the font's UNDERLINE_POSITION for small font display
10829 x_use_underline_position_properties
= 1;
10831 DEFVAR_BOOL ("x-underline-at-descent-line",
10832 &x_underline_at_descent_line
,
10833 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
10834 A value of nil means to draw the underline according to the value of the
10835 variable `x-use-underline-position-properties', which is usually at the
10836 baseline level. The default value is nil. */);
10837 x_underline_at_descent_line
= 0;
10839 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10840 &x_mouse_click_focus_ignore_position
,
10841 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10842 This variable is only used when the window manager requires that you
10843 click on a frame to select it (give it focus). In that case, a value
10844 of nil, means that the selected window and cursor position changes to
10845 reflect the mouse click position, while a non-nil value means that the
10846 selected window or cursor position is preserved. */);
10847 x_mouse_click_focus_ignore_position
= 0;
10849 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10850 doc
: /* What X toolkit scroll bars Emacs uses.
10851 A value of nil means Emacs doesn't use X toolkit scroll bars.
10852 Otherwise, value is a symbol describing the X toolkit. */);
10853 #ifdef USE_TOOLKIT_SCROLL_BARS
10855 Vx_toolkit_scroll_bars
= intern ("motif");
10856 #elif defined HAVE_XAW3D
10857 Vx_toolkit_scroll_bars
= intern ("xaw3d");
10859 Vx_toolkit_scroll_bars
= intern ("gtk");
10861 Vx_toolkit_scroll_bars
= intern ("xaw");
10864 Vx_toolkit_scroll_bars
= Qnil
;
10867 staticpro (&last_mouse_motion_frame
);
10868 last_mouse_motion_frame
= Qnil
;
10870 Qmodifier_value
= intern ("modifier-value");
10871 Qalt
= intern ("alt");
10872 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10873 Qhyper
= intern ("hyper");
10874 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10875 Qmeta
= intern ("meta");
10876 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10877 Qsuper
= intern ("super");
10878 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10880 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10881 doc
: /* Which keys Emacs uses for the alt modifier.
10882 This should be one of the symbols `alt', `hyper', `meta', `super'.
10883 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10884 is nil, which is the same as `alt'. */);
10885 Vx_alt_keysym
= Qnil
;
10887 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10888 doc
: /* Which keys Emacs uses for the hyper modifier.
10889 This should be one of the symbols `alt', `hyper', `meta', `super'.
10890 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10891 default is nil, which is the same as `hyper'. */);
10892 Vx_hyper_keysym
= Qnil
;
10894 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10895 doc
: /* Which keys Emacs uses for the meta modifier.
10896 This should be one of the symbols `alt', `hyper', `meta', `super'.
10897 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10898 default is nil, which is the same as `meta'. */);
10899 Vx_meta_keysym
= Qnil
;
10901 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10902 doc
: /* Which keys Emacs uses for the super modifier.
10903 This should be one of the symbols `alt', `hyper', `meta', `super'.
10904 For example, `super' means use the Super_L and Super_R keysyms. The
10905 default is nil, which is the same as `super'. */);
10906 Vx_super_keysym
= Qnil
;
10908 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10909 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10910 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10911 make_float (DEFAULT_REHASH_SIZE
),
10912 make_float (DEFAULT_REHASH_THRESHOLD
),
10916 #endif /* HAVE_X_WINDOWS */
10918 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
10919 (do not change this comment) */