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
*));
112 extern struct frame
*x_menubar_window_to_frame
P_ ((struct x_display_info
*,
117 #if (XtSpecificationRelease >= 5) && !defined(NO_EDITRES)
119 extern void _XEditResCheckMessages ();
120 #endif /* not NO_EDITRES */
122 /* Include toolkit specific headers for the scroll bar widget. */
124 #ifdef USE_TOOLKIT_SCROLL_BARS
125 #if defined USE_MOTIF
126 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
127 #include <Xm/ScrollBar.h>
128 #else /* !USE_MOTIF i.e. use Xaw */
131 #include <X11/Xaw3d/Simple.h>
132 #include <X11/Xaw3d/Scrollbar.h>
133 #include <X11/Xaw3d/ThreeD.h>
134 #else /* !HAVE_XAW3D */
135 #include <X11/Xaw/Simple.h>
136 #include <X11/Xaw/Scrollbar.h>
137 #endif /* !HAVE_XAW3D */
139 #define XtNpickTop "pickTop"
140 #endif /* !XtNpickTop */
141 #endif /* !USE_MOTIF */
142 #endif /* USE_TOOLKIT_SCROLL_BARS */
144 #endif /* USE_X_TOOLKIT */
146 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
147 #define x_any_window_to_frame x_window_to_frame
148 #define x_top_window_to_frame x_window_to_frame
153 #ifndef XtNinitialState
154 #define XtNinitialState "initialState"
158 /* Default to using XIM if available. */
162 int use_xim
= 0; /* configure --without-xim */
167 /* Non-nil means Emacs uses toolkit scroll bars. */
169 Lisp_Object Vx_toolkit_scroll_bars
;
171 /* Non-zero means that a HELP_EVENT has been generated since Emacs
174 static int any_help_event_p
;
176 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
177 static Lisp_Object last_window
;
179 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
181 int x_use_underline_position_properties
;
183 /* Non-zero means to draw the underline at the same place as the descent line. */
185 int x_underline_at_descent_line
;
187 /* This is a chain of structures for all the X displays currently in
190 struct x_display_info
*x_display_list
;
192 /* This is a list of cons cells, each of the form (NAME
193 . FONT-LIST-CACHE), one for each element of x_display_list and in
194 the same order. NAME is the name of the frame. FONT-LIST-CACHE
195 records previous values returned by x-list-fonts. */
197 Lisp_Object x_display_name_list
;
199 /* Frame being updated by update_frame. This is declared in term.c.
200 This is set by update_begin and looked at by all the XT functions.
201 It is zero while not inside an update. In that case, the XT
202 functions assume that `selected_frame' is the frame to apply to. */
204 extern struct frame
*updating_frame
;
206 /* This is a frame waiting to be auto-raised, within XTread_socket. */
208 struct frame
*pending_autoraise_frame
;
211 /* The application context for Xt use. */
212 XtAppContext Xt_app_con
;
213 static String Xt_default_resources
[] = {0};
214 #endif /* USE_X_TOOLKIT */
216 /* Non-zero means user is interacting with a toolkit scroll bar. */
218 static int toolkit_scroll_bar_interaction
;
220 /* Non-zero means to not move point as a result of clicking on a
221 frame to focus it (when focus-follows-mouse is nil). */
223 int x_mouse_click_focus_ignore_position
;
225 /* Non-zero timeout value means ignore next mouse click if it arrives
226 before that timeout elapses (i.e. as part of the same sequence of
227 events resulting from clicking on a frame to select it). */
229 static unsigned long ignore_next_mouse_click_timeout
;
233 Formerly, we used PointerMotionHintMask (in standard_event_mask)
234 so that we would have to call XQueryPointer after each MotionNotify
235 event to ask for another such event. However, this made mouse tracking
236 slow, and there was a bug that made it eventually stop.
238 Simply asking for MotionNotify all the time seems to work better.
240 In order to avoid asking for motion events and then throwing most
241 of them away or busy-polling the server for mouse positions, we ask
242 the server for pointer motion hints. This means that we get only
243 one event per group of mouse movements. "Groups" are delimited by
244 other kinds of events (focus changes and button clicks, for
245 example), or by XQueryPointer calls; when one of these happens, we
246 get another MotionNotify event the next time the mouse moves. This
247 is at least as efficient as getting motion events when mouse
248 tracking is on, and I suspect only negligibly worse when tracking
251 /* Where the mouse was last time we reported a mouse event. */
253 static XRectangle last_mouse_glyph
;
254 static FRAME_PTR last_mouse_glyph_frame
;
255 static Lisp_Object last_mouse_press_frame
;
257 /* The scroll bar in which the last X motion event occurred.
259 If the last X motion event occurred in a scroll bar, we set this so
260 XTmouse_position can know whether to report a scroll bar motion or
263 If the last X motion event didn't occur in a scroll bar, we set
264 this to Qnil, to tell XTmouse_position to return an ordinary motion
267 static Lisp_Object last_mouse_scroll_bar
;
269 /* This is a hack. We would really prefer that XTmouse_position would
270 return the time associated with the position it returns, but there
271 doesn't seem to be any way to wrest the time-stamp from the server
272 along with the position query. So, we just keep track of the time
273 of the last movement we received, and return that in hopes that
274 it's somewhat accurate. */
276 static Time last_mouse_movement_time
;
278 /* Time for last user interaction as returned in X events. */
280 static Time last_user_time
;
282 /* Incremented by XTread_socket whenever it really tries to read
286 static int volatile input_signal_count
;
288 static int input_signal_count
;
291 /* Used locally within XTread_socket. */
293 static int x_noop_count
;
295 /* Initial values of argv and argc. */
297 extern char **initial_argv
;
298 extern int initial_argc
;
300 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
302 /* Tells if a window manager is present or not. */
304 extern Lisp_Object Vx_no_window_manager
;
306 extern Lisp_Object Qeql
;
310 /* A mask of extra modifier bits to put into every keyboard char. */
312 extern EMACS_INT extra_keyboard_modifiers
;
314 /* The keysyms to use for the various modifiers. */
316 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
317 Lisp_Object Vx_keysym_table
;
318 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
320 static Lisp_Object Qvendor_specific_keysyms
;
321 static Lisp_Object Qlatin_1
;
323 /* Used in x_flush. */
325 extern Lisp_Object Vinhibit_redisplay
;
327 extern XrmDatabase x_load_resources
P_ ((Display
*, char *, char *, char *));
328 extern int x_bitmap_mask
P_ ((FRAME_PTR
, int));
330 static int x_alloc_nearest_color_1
P_ ((Display
*, Colormap
, XColor
*));
331 static void x_set_window_size_1
P_ ((struct frame
*, int, int, int));
332 static const XColor
*x_color_cells
P_ ((Display
*, int *));
333 static void x_update_window_end
P_ ((struct window
*, int, int));
335 static int x_io_error_quitter
P_ ((Display
*));
336 static struct terminal
*x_create_terminal
P_ ((struct x_display_info
*));
337 void x_delete_terminal
P_ ((struct terminal
*));
338 static void x_update_end
P_ ((struct frame
*));
339 static void XTframe_up_to_date
P_ ((struct frame
*));
340 static void XTset_terminal_modes
P_ ((struct terminal
*));
341 static void XTreset_terminal_modes
P_ ((struct terminal
*));
342 static void x_clear_frame
P_ ((struct frame
*));
343 static void frame_highlight
P_ ((struct frame
*));
344 static void frame_unhighlight
P_ ((struct frame
*));
345 static void x_new_focus_frame
P_ ((struct x_display_info
*, struct frame
*));
346 static void x_focus_changed
P_ ((int, int, struct x_display_info
*,
347 struct frame
*, struct input_event
*));
348 static void x_detect_focus_change
P_ ((struct x_display_info
*,
349 XEvent
*, struct input_event
*));
350 static void XTframe_rehighlight
P_ ((struct frame
*));
351 static void x_frame_rehighlight
P_ ((struct x_display_info
*));
352 static void x_draw_hollow_cursor
P_ ((struct window
*, struct glyph_row
*));
353 static void x_draw_bar_cursor
P_ ((struct window
*, struct glyph_row
*, int,
354 enum text_cursor_kinds
));
356 static void x_clip_to_row
P_ ((struct window
*, struct glyph_row
*, int, GC
));
357 static void x_flush
P_ ((struct frame
*f
));
358 static void x_update_begin
P_ ((struct frame
*));
359 static void x_update_window_begin
P_ ((struct window
*));
360 static void x_after_update_window_line
P_ ((struct glyph_row
*));
361 static struct scroll_bar
*x_window_to_scroll_bar
P_ ((Display
*, Window
));
362 static void x_scroll_bar_report_motion
P_ ((struct frame
**, Lisp_Object
*,
363 enum scroll_bar_part
*,
364 Lisp_Object
*, Lisp_Object
*,
366 static void x_handle_net_wm_state
P_ ((struct frame
*, XPropertyEvent
*));
367 static void x_check_fullscreen
P_ ((struct frame
*));
368 static void x_check_expected_move
P_ ((struct frame
*, int, int));
369 static void x_sync_with_move
P_ ((struct frame
*, int, int, int));
370 static int handle_one_xevent
P_ ((struct x_display_info
*, XEvent
*,
371 int *, struct input_event
*));
372 /* Don't declare this NO_RETURN because we want no
373 interference with debugging failing X calls. */
374 static SIGTYPE x_connection_closed
P_ ((Display
*, char *));
377 /* Flush display of frame F, or of all frames if F is null. */
383 /* Don't call XFlush when it is not safe to redisplay; the X
384 connection may be broken. */
385 if (!NILP (Vinhibit_redisplay
))
391 Lisp_Object rest
, frame
;
392 FOR_EACH_FRAME (rest
, frame
)
393 if (FRAME_X_P (XFRAME (frame
)))
394 x_flush (XFRAME (frame
));
396 else if (FRAME_X_P (f
))
397 XFlush (FRAME_X_DISPLAY (f
));
402 /* Remove calls to XFlush by defining XFlush to an empty replacement.
403 Calls to XFlush should be unnecessary because the X output buffer
404 is flushed automatically as needed by calls to XPending,
405 XNextEvent, or XWindowEvent according to the XFlush man page.
406 XTread_socket calls XPending. Removing XFlush improves
409 #define XFlush(DISPLAY) (void) 0
412 /***********************************************************************
414 ***********************************************************************/
418 /* This is a function useful for recording debugging information about
419 the sequence of occurrences in this file. */
427 struct record event_record
[100];
429 int event_record_index
;
431 record_event (locus
, type
)
435 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
436 event_record_index
= 0;
438 event_record
[event_record_index
].locus
= locus
;
439 event_record
[event_record_index
].type
= type
;
440 event_record_index
++;
447 /* Return the struct x_display_info corresponding to DPY. */
449 struct x_display_info
*
450 x_display_info_for_display (dpy
)
453 struct x_display_info
*dpyinfo
;
455 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
456 if (dpyinfo
->display
== dpy
)
462 #define OPAQUE 0xffffffff
463 #define OPACITY "_NET_WM_WINDOW_OPACITY"
466 x_set_frame_alpha (f
)
469 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
470 Display
*dpy
= FRAME_X_DISPLAY (f
);
471 Window win
= FRAME_OUTER_WINDOW (f
);
473 double alpha_min
= 1.0;
476 if (FRAME_X_DISPLAY_INFO (f
)->root_window
!= FRAME_X_OUTPUT (f
)->parent_desc
)
477 /* Since the WM decoration lies under the FRAME_OUTER_WINDOW,
478 we must treat the former instead of the latter. */
479 win
= FRAME_X_OUTPUT(f
)->parent_desc
;
481 if (dpyinfo
->x_highlight_frame
== f
)
486 if (FLOATP (Vframe_alpha_lower_limit
))
487 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
488 else if (INTEGERP (Vframe_alpha_lower_limit
))
489 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
493 else if (alpha
> 1.0)
495 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
498 opac
= alpha
* OPAQUE
;
500 /* return unless necessary */
505 unsigned long n
, left
;
507 x_catch_errors (dpy
);
508 rc
= XGetWindowProperty(dpy
, win
, XInternAtom(dpy
, OPACITY
, False
),
509 0L, 1L, False
, XA_CARDINAL
,
510 &actual
, &format
, &n
, &left
,
513 if (rc
== Success
&& actual
!= None
)
514 if (*(unsigned long *)data
== opac
)
516 XFree ((void *) data
);
521 XFree ((void *) data
);
525 x_catch_errors (dpy
);
526 XChangeProperty (dpy
, win
, XInternAtom (dpy
, OPACITY
, False
),
527 XA_CARDINAL
, 32, PropModeReplace
,
528 (unsigned char *) &opac
, 1L);
533 x_display_pixel_height (dpyinfo
)
534 struct x_display_info
*dpyinfo
;
536 return HeightOfScreen (dpyinfo
->screen
);
540 x_display_pixel_width (dpyinfo
)
541 struct x_display_info
*dpyinfo
;
543 return WidthOfScreen (dpyinfo
->screen
);
547 /***********************************************************************
548 Starting and ending an update
549 ***********************************************************************/
551 /* Start an update of frame F. This function is installed as a hook
552 for update_begin, i.e. it is called when update_begin is called.
553 This function is called prior to calls to x_update_window_begin for
554 each window being updated. Currently, there is nothing to do here
555 because all interesting stuff is done on a window basis. */
565 /* Start update of window W. Set the global variable updated_window
566 to the window being updated and set output_cursor to the cursor
570 x_update_window_begin (w
)
573 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
574 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
577 set_output_cursor (&w
->cursor
);
581 if (f
== display_info
->mouse_face_mouse_frame
)
583 /* Don't do highlighting for mouse motion during the update. */
584 display_info
->mouse_face_defer
= 1;
586 /* If F needs to be redrawn, simply forget about any prior mouse
588 if (FRAME_GARBAGED_P (f
))
589 display_info
->mouse_face_window
= Qnil
;
591 #if 0 /* Rows in a current matrix containing glyphs in mouse-face have
592 their mouse_face_p flag set, which means that they are always
593 unequal to rows in a desired matrix which never have that
594 flag set. So, rows containing mouse-face glyphs are never
595 scrolled, and we don't have to switch the mouse highlight off
596 here to prevent it from being scrolled. */
598 /* Can we tell that this update does not affect the window
599 where the mouse highlight is? If so, no need to turn off.
600 Likewise, don't do anything if the frame is garbaged;
601 in that case, the frame's current matrix that we would use
602 is all wrong, and we will redisplay that line anyway. */
603 if (!NILP (display_info
->mouse_face_window
)
604 && w
== XWINDOW (display_info
->mouse_face_window
))
608 for (i
= 0; i
< w
->desired_matrix
->nrows
; ++i
)
609 if (MATRIX_ROW_ENABLED_P (w
->desired_matrix
, i
))
612 if (i
< w
->desired_matrix
->nrows
)
613 clear_mouse_face (display_info
);
622 /* Draw a vertical window border from (x,y0) to (x,y1) */
625 x_draw_vertical_window_border (w
, x
, y0
, y1
)
629 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
632 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
634 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
637 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
638 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
641 /* End update of window W (which is equal to updated_window).
643 Draw vertical borders between horizontally adjacent windows, and
644 display W's cursor if CURSOR_ON_P is non-zero.
646 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
647 glyphs in mouse-face were overwritten. In that case we have to
648 make sure that the mouse-highlight is properly redrawn.
650 W may be a menu bar pseudo-window in case we don't have X toolkit
651 support. Such windows don't have a cursor, so don't display it
655 x_update_window_end (w
, cursor_on_p
, mouse_face_overwritten_p
)
657 int cursor_on_p
, mouse_face_overwritten_p
;
659 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
661 if (!w
->pseudo_window_p
)
666 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
668 output_cursor
.x
, output_cursor
.y
);
670 if (draw_window_fringes (w
, 1))
671 x_draw_vertical_border (w
);
676 /* If a row with mouse-face was overwritten, arrange for
677 XTframe_up_to_date to redisplay the mouse highlight. */
678 if (mouse_face_overwritten_p
)
680 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
681 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
682 dpyinfo
->mouse_face_window
= Qnil
;
685 updated_window
= NULL
;
689 /* End update of frame F. This function is installed as a hook in
696 /* Mouse highlight may be displayed again. */
697 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
701 XFlush (FRAME_X_DISPLAY (f
));
707 /* This function is called from various places in xdisp.c whenever a
708 complete update has been performed. The global variable
709 updated_window is not available here. */
712 XTframe_up_to_date (f
)
717 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
719 if (dpyinfo
->mouse_face_deferred_gc
720 || f
== dpyinfo
->mouse_face_mouse_frame
)
723 if (dpyinfo
->mouse_face_mouse_frame
)
724 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
725 dpyinfo
->mouse_face_mouse_x
,
726 dpyinfo
->mouse_face_mouse_y
);
727 dpyinfo
->mouse_face_deferred_gc
= 0;
734 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
735 arrow bitmaps, or clear the fringes if no bitmaps are required
736 before DESIRED_ROW is made current. The window being updated is
737 found in updated_window. This function It is called from
738 update_window_line only if it is known that there are differences
739 between bitmaps to be drawn between current row and DESIRED_ROW. */
742 x_after_update_window_line (desired_row
)
743 struct glyph_row
*desired_row
;
745 struct window
*w
= updated_window
;
751 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
752 desired_row
->redraw_fringe_bitmaps_p
= 1;
754 /* When a window has disappeared, make sure that no rest of
755 full-width rows stays visible in the internal border. Could
756 check here if updated_window is the leftmost/rightmost window,
757 but I guess it's not worth doing since vertically split windows
758 are almost never used, internal border is rarely set, and the
759 overhead is very small. */
760 if (windows_or_buffers_changed
761 && desired_row
->full_width_p
762 && (f
= XFRAME (w
->frame
),
763 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
765 && (height
= desired_row
->visible_height
,
768 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
770 /* Internal border is drawn below the tool bar. */
771 if (WINDOWP (f
->tool_bar_window
)
772 && w
== XWINDOW (f
->tool_bar_window
))
776 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
777 0, y
, width
, height
, False
);
778 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
779 FRAME_PIXEL_WIDTH (f
) - width
,
780 y
, width
, height
, False
);
786 x_draw_fringe_bitmap (w
, row
, p
)
788 struct glyph_row
*row
;
789 struct draw_fringe_bitmap_params
*p
;
791 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
792 Display
*display
= FRAME_X_DISPLAY (f
);
793 Window window
= FRAME_X_WINDOW (f
);
794 GC gc
= f
->output_data
.x
->normal_gc
;
795 struct face
*face
= p
->face
;
798 /* Must clip because of partially visible lines. */
799 rowY
= WINDOW_TO_FRAME_PIXEL_Y (w
, row
->y
);
802 /* Adjust position of "bottom aligned" bitmap on partially
805 int oldVH
= row
->visible_height
;
806 row
->visible_height
= p
->h
;
807 row
->y
-= rowY
- p
->y
;
808 x_clip_to_row (w
, row
, -1, gc
);
810 row
->visible_height
= oldVH
;
813 x_clip_to_row (w
, row
, -1, gc
);
817 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
819 /* In case the same realized face is used for fringes and
820 for something displayed in the text (e.g. face `region' on
821 mono-displays, the fill style may have been changed to
822 FillSolid in x_draw_glyph_string_background. */
824 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
826 XSetForeground (display
, face
->gc
, face
->background
);
828 #ifdef USE_TOOLKIT_SCROLL_BARS
829 /* If the fringe is adjacent to the left (right) scroll bar of a
830 leftmost (rightmost, respectively) window, then extend its
831 background to the gap between the fringe and the bar. */
832 if ((WINDOW_LEFTMOST_P (w
)
833 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
834 || (WINDOW_RIGHTMOST_P (w
)
835 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
837 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
841 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
842 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
843 * FRAME_COLUMN_WIDTH (f
));
847 /* Bitmap fills the fringe. */
848 if (left
+ width
== p
->x
)
849 bx
= left
+ sb_width
;
850 else if (p
->x
+ p
->wd
== left
)
854 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
856 nx
= width
- sb_width
;
857 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
859 ny
= row
->visible_height
;
864 if (left
+ width
== bx
)
866 bx
= left
+ sb_width
;
867 nx
+= width
- sb_width
;
869 else if (bx
+ nx
== left
)
870 nx
+= width
- sb_width
;
875 if (bx
>= 0 && nx
> 0)
876 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
879 XSetForeground (display
, face
->gc
, face
->foreground
);
885 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
886 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
890 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
892 bits
= (unsigned char *)p
->bits
+ p
->dh
;
894 /* Draw the bitmap. I believe these small pixmaps can be cached
896 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
898 ? (p
->overlay_p
? face
->background
899 : f
->output_data
.x
->cursor_pixel
)
901 face
->background
, depth
);
905 clipmask
= XCreatePixmapFromBitmapData (display
,
906 FRAME_X_DISPLAY_INFO (f
)->root_window
,
909 gcv
.clip_mask
= clipmask
;
910 gcv
.clip_x_origin
= p
->x
;
911 gcv
.clip_y_origin
= p
->y
;
912 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
915 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
916 p
->wd
, p
->h
, p
->x
, p
->y
);
917 XFreePixmap (display
, pixmap
);
921 gcv
.clip_mask
= (Pixmap
) 0;
922 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
923 XFreePixmap (display
, clipmask
);
927 XSetClipMask (display
, gc
, None
);
932 /* This is called when starting Emacs and when restarting after
933 suspend. When starting Emacs, no X window is mapped. And nothing
934 must be done to Emacs's own window if it is suspended (though that
938 XTset_terminal_modes (struct terminal
*terminal
)
942 /* This is called when exiting or suspending Emacs. Exiting will make
943 the X-windows go away, and suspending requires no action. */
946 XTreset_terminal_modes (struct terminal
*terminal
)
951 /***********************************************************************
953 ***********************************************************************/
957 static void x_set_glyph_string_clipping
P_ ((struct glyph_string
*));
958 static void x_set_glyph_string_gc
P_ ((struct glyph_string
*));
959 static void x_draw_glyph_string_background
P_ ((struct glyph_string
*,
961 static void x_draw_glyph_string_foreground
P_ ((struct glyph_string
*));
962 static void x_draw_composite_glyph_string_foreground
P_ ((struct glyph_string
*));
963 static void x_draw_glyph_string_box
P_ ((struct glyph_string
*));
964 static void x_draw_glyph_string
P_ ((struct glyph_string
*));
965 static void x_compute_glyph_string_overhangs
P_ ((struct glyph_string
*));
966 static void x_set_cursor_gc
P_ ((struct glyph_string
*));
967 static void x_set_mode_line_face_gc
P_ ((struct glyph_string
*));
968 static void x_set_mouse_face_gc
P_ ((struct glyph_string
*));
969 static int x_alloc_lighter_color
P_ ((struct frame
*, Display
*, Colormap
,
970 unsigned long *, double, int));
971 static void x_setup_relief_color
P_ ((struct frame
*, struct relief
*,
972 double, int, unsigned long));
973 static void x_setup_relief_colors
P_ ((struct glyph_string
*));
974 static void x_draw_image_glyph_string
P_ ((struct glyph_string
*));
975 static void x_draw_image_relief
P_ ((struct glyph_string
*));
976 static void x_draw_image_foreground
P_ ((struct glyph_string
*));
977 static void x_draw_image_foreground_1
P_ ((struct glyph_string
*, Pixmap
));
978 static void x_clear_glyph_string_rect
P_ ((struct glyph_string
*, int,
980 static void x_draw_relief_rect
P_ ((struct frame
*, int, int, int, int,
981 int, int, int, int, int, int,
983 static void x_draw_box_rect
P_ ((struct glyph_string
*, int, int, int, int,
984 int, int, int, XRectangle
*));
987 static void x_check_font
P_ ((struct frame
*, struct font
*));
991 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
996 struct glyph_string
*s
;
998 if (s
->font
== FRAME_FONT (s
->f
)
999 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
1000 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
1002 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
1005 /* Cursor on non-default face: must merge. */
1009 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
1010 xgcv
.foreground
= s
->face
->background
;
1012 /* If the glyph would be invisible, try a different foreground. */
1013 if (xgcv
.foreground
== xgcv
.background
)
1014 xgcv
.foreground
= s
->face
->foreground
;
1015 if (xgcv
.foreground
== xgcv
.background
)
1016 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
1017 if (xgcv
.foreground
== xgcv
.background
)
1018 xgcv
.foreground
= s
->face
->foreground
;
1020 /* Make sure the cursor is distinct from text in this face. */
1021 if (xgcv
.background
== s
->face
->background
1022 && xgcv
.foreground
== s
->face
->foreground
)
1024 xgcv
.background
= s
->face
->foreground
;
1025 xgcv
.foreground
= s
->face
->background
;
1028 IF_DEBUG (x_check_font (s
->f
, s
->font
));
1029 xgcv
.graphics_exposures
= False
;
1030 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1032 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1033 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1036 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1037 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1039 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1044 /* Set up S->gc of glyph string S for drawing text in mouse face. */
1047 x_set_mouse_face_gc (s
)
1048 struct glyph_string
*s
;
1053 /* What face has to be used last for the mouse face? */
1054 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
1055 face
= FACE_FROM_ID (s
->f
, face_id
);
1057 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1059 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1060 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1062 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1063 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1064 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1066 if (s
->font
== s
->face
->font
)
1067 s
->gc
= s
->face
->gc
;
1070 /* Otherwise construct scratch_cursor_gc with values from FACE
1075 xgcv
.background
= s
->face
->background
;
1076 xgcv
.foreground
= s
->face
->foreground
;
1077 xgcv
.graphics_exposures
= False
;
1078 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1080 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1081 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1084 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1085 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1087 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1090 xassert (s
->gc
!= 0);
1094 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1095 Faces to use in the mode line have already been computed when the
1096 matrix was built, so there isn't much to do, here. */
1099 x_set_mode_line_face_gc (s
)
1100 struct glyph_string
*s
;
1102 s
->gc
= s
->face
->gc
;
1106 /* Set S->gc of glyph string S for drawing that glyph string. Set
1107 S->stippled_p to a non-zero value if the face of S has a stipple
1111 x_set_glyph_string_gc (s
)
1112 struct glyph_string
*s
;
1114 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1116 if (s
->hl
== DRAW_NORMAL_TEXT
)
1118 s
->gc
= s
->face
->gc
;
1119 s
->stippled_p
= s
->face
->stipple
!= 0;
1121 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1123 x_set_mode_line_face_gc (s
);
1124 s
->stippled_p
= s
->face
->stipple
!= 0;
1126 else if (s
->hl
== DRAW_CURSOR
)
1128 x_set_cursor_gc (s
);
1131 else if (s
->hl
== DRAW_MOUSE_FACE
)
1133 x_set_mouse_face_gc (s
);
1134 s
->stippled_p
= s
->face
->stipple
!= 0;
1136 else if (s
->hl
== DRAW_IMAGE_RAISED
1137 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1139 s
->gc
= s
->face
->gc
;
1140 s
->stippled_p
= s
->face
->stipple
!= 0;
1144 s
->gc
= s
->face
->gc
;
1145 s
->stippled_p
= s
->face
->stipple
!= 0;
1148 /* GC must have been set. */
1149 xassert (s
->gc
!= 0);
1153 /* Set clipping for output of glyph string S. S may be part of a mode
1154 line or menu if we don't have X toolkit support. */
1157 x_set_glyph_string_clipping (s
)
1158 struct glyph_string
*s
;
1160 XRectangle
*r
= s
->clip
;
1161 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1164 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1169 /* Set SRC's clipping for output of glyph string DST. This is called
1170 when we are drawing DST's left_overhang or right_overhang only in
1174 x_set_glyph_string_clipping_exactly (src
, dst
)
1175 struct glyph_string
*src
, *dst
;
1180 r
.width
= src
->width
;
1182 r
.height
= src
->height
;
1185 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1190 Compute left and right overhang of glyph string S. */
1193 x_compute_glyph_string_overhangs (s
)
1194 struct glyph_string
*s
;
1197 && s
->first_glyph
->type
== CHAR_GLYPH
)
1199 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1200 struct font
*font
= s
->font
;
1201 struct font_metrics metrics
;
1204 for (i
= 0; i
< s
->nchars
; i
++)
1205 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1206 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1207 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1208 ? metrics
.rbearing
- metrics
.width
: 0);
1209 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1213 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1214 s
->left_overhang
= - s
->cmp
->lbearing
;
1219 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1222 x_clear_glyph_string_rect (s
, x
, y
, w
, h
)
1223 struct glyph_string
*s
;
1227 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1228 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1229 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1230 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1234 /* Draw the background of glyph_string S. If S->background_filled_p
1235 is non-zero don't draw it. FORCE_P non-zero means draw the
1236 background even if it wouldn't be drawn normally. This is used
1237 when a string preceding S draws into the background of S, or S
1238 contains the first component of a composition. */
1241 x_draw_glyph_string_background (s
, force_p
)
1242 struct glyph_string
*s
;
1245 /* Nothing to do if background has already been drawn or if it
1246 shouldn't be drawn in the first place. */
1247 if (!s
->background_filled_p
)
1249 int box_line_width
= max (s
->face
->box_line_width
, 0);
1253 /* Fill background with a stipple pattern. */
1254 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1255 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1256 s
->y
+ box_line_width
,
1257 s
->background_width
,
1258 s
->height
- 2 * box_line_width
);
1259 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1260 s
->background_filled_p
= 1;
1262 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1263 || s
->font_not_found_p
1264 || s
->extends_to_end_of_line_p
1267 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1268 s
->background_width
,
1269 s
->height
- 2 * box_line_width
);
1270 s
->background_filled_p
= 1;
1276 /* Draw the foreground of glyph string S. */
1279 x_draw_glyph_string_foreground (s
)
1280 struct glyph_string
*s
;
1284 /* If first glyph of S has a left box line, start drawing the text
1285 of S to the right of that box line. */
1286 if (s
->face
->box
!= FACE_NO_BOX
1287 && s
->first_glyph
->left_box_line_p
)
1288 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1292 /* Draw characters of S as rectangles if S's font could not be
1294 if (s
->font_not_found_p
)
1296 for (i
= 0; i
< s
->nchars
; ++i
)
1298 struct glyph
*g
= s
->first_glyph
+ i
;
1299 XDrawRectangle (s
->display
, s
->window
,
1300 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1302 x
+= g
->pixel_width
;
1307 struct font
*font
= s
->font
;
1308 int boff
= font
->baseline_offset
;
1311 if (font
->vertical_centering
)
1312 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1314 y
= s
->ybase
- boff
;
1316 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1317 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1319 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1320 if (s
->face
->overstrike
)
1321 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1325 /* Draw the foreground of composite glyph string S. */
1328 x_draw_composite_glyph_string_foreground (s
)
1329 struct glyph_string
*s
;
1332 struct font
*font
= s
->font
;
1334 /* If first glyph of S has a left box line, start drawing the text
1335 of S to the right of that box line. */
1336 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1337 && s
->first_glyph
->left_box_line_p
)
1338 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1342 /* S is a glyph string for a composition. S->cmp_from is the index
1343 of the first character drawn for glyphs of this composition.
1344 S->cmp_from == 0 means we are drawing the very first character of
1345 this composition. */
1347 /* Draw a rectangle for the composition if the font for the very
1348 first character of the composition could not be loaded. */
1349 if (s
->font_not_found_p
)
1351 if (s
->cmp_from
== 0)
1352 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1353 s
->width
- 1, s
->height
- 1);
1355 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1359 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1360 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1362 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1363 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1365 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1366 if (s
->face
->overstrike
)
1367 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1372 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1377 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1379 glyph
= LGSTRING_GLYPH (gstring
, i
);
1380 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1381 width
+= LGLYPH_WIDTH (glyph
);
1384 int xoff
, yoff
, wadjust
;
1388 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1391 xoff
= LGLYPH_XOFF (glyph
);
1392 yoff
= LGLYPH_YOFF (glyph
);
1393 wadjust
= LGLYPH_WADJUST (glyph
);
1394 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1401 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1406 #ifdef USE_X_TOOLKIT
1408 static struct frame
*x_frame_of_widget
P_ ((Widget
));
1409 static Boolean cvt_string_to_pixel
P_ ((Display
*, XrmValue
*, Cardinal
*,
1410 XrmValue
*, XrmValue
*, XtPointer
*));
1411 static void cvt_pixel_dtor
P_ ((XtAppContext
, XrmValue
*, XtPointer
,
1412 XrmValue
*, Cardinal
*));
1415 /* Return the frame on which widget WIDGET is used.. Abort if frame
1416 cannot be determined. */
1418 static struct frame
*
1419 x_frame_of_widget (widget
)
1422 struct x_display_info
*dpyinfo
;
1426 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1428 /* Find the top-level shell of the widget. Note that this function
1429 can be called when the widget is not yet realized, so XtWindow
1430 (widget) == 0. That's the reason we can't simply use
1431 x_any_window_to_frame. */
1432 while (!XtIsTopLevelShell (widget
))
1433 widget
= XtParent (widget
);
1435 /* Look for a frame with that top-level widget. Allocate the color
1436 on that frame to get the right gamma correction value. */
1437 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1438 if (FRAMEP (XCAR (tail
))
1439 && (f
= XFRAME (XCAR (tail
)),
1441 && f
->output_data
.nothing
!= 1
1442 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1443 && f
->output_data
.x
->widget
== widget
)
1450 /* Allocate the color COLOR->pixel on the screen and display of
1451 widget WIDGET in colormap CMAP. If an exact match cannot be
1452 allocated, try the nearest color available. Value is non-zero
1453 if successful. This is called from lwlib. */
1456 x_alloc_nearest_color_for_widget (widget
, cmap
, color
)
1461 struct frame
*f
= x_frame_of_widget (widget
);
1462 return x_alloc_nearest_color (f
, cmap
, color
);
1466 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1467 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1468 If this produces the same color as PIXEL, try a color where all RGB
1469 values have DELTA added. Return the allocated color in *PIXEL.
1470 DISPLAY is the X display, CMAP is the colormap to operate on.
1471 Value is non-zero if successful. */
1474 x_alloc_lighter_color_for_widget (widget
, display
, cmap
, pixel
, factor
, delta
)
1478 unsigned long *pixel
;
1482 struct frame
*f
= x_frame_of_widget (widget
);
1483 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1487 /* Structure specifying which arguments should be passed by Xt to
1488 cvt_string_to_pixel. We want the widget's screen and colormap. */
1490 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1492 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1494 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1499 /* The address of this variable is returned by
1500 cvt_string_to_pixel. */
1502 static Pixel cvt_string_to_pixel_value
;
1505 /* Convert a color name to a pixel color.
1507 DPY is the display we are working on.
1509 ARGS is an array of *NARGS XrmValue structures holding additional
1510 information about the widget for which the conversion takes place.
1511 The contents of this array are determined by the specification
1512 in cvt_string_to_pixel_args.
1514 FROM is a pointer to an XrmValue which points to the color name to
1515 convert. TO is an XrmValue in which to return the pixel color.
1517 CLOSURE_RET is a pointer to user-data, in which we record if
1518 we allocated the color or not.
1520 Value is True if successful, False otherwise. */
1523 cvt_string_to_pixel (dpy
, args
, nargs
, from
, to
, closure_ret
)
1527 XrmValue
*from
, *to
;
1528 XtPointer
*closure_ret
;
1538 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1539 "wrongParameters", "cvt_string_to_pixel",
1541 "Screen and colormap args required", NULL
, NULL
);
1545 screen
= *(Screen
**) args
[0].addr
;
1546 cmap
= *(Colormap
*) args
[1].addr
;
1547 color_name
= (String
) from
->addr
;
1549 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1551 *closure_ret
= (XtPointer
) False
;
1552 pixel
= WhitePixelOfScreen (screen
);
1554 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1556 *closure_ret
= (XtPointer
) False
;
1557 pixel
= BlackPixelOfScreen (screen
);
1559 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1560 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1562 pixel
= color
.pixel
;
1563 *closure_ret
= (XtPointer
) True
;
1568 Cardinal nparams
= 1;
1570 params
[0] = color_name
;
1571 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1572 "badValue", "cvt_string_to_pixel",
1573 "XtToolkitError", "Invalid color `%s'",
1578 if (to
->addr
!= NULL
)
1580 if (to
->size
< sizeof (Pixel
))
1582 to
->size
= sizeof (Pixel
);
1586 *(Pixel
*) to
->addr
= pixel
;
1590 cvt_string_to_pixel_value
= pixel
;
1591 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1594 to
->size
= sizeof (Pixel
);
1599 /* Free a pixel color which was previously allocated via
1600 cvt_string_to_pixel. This is registered as the destructor
1601 for this type of resource via XtSetTypeConverter.
1603 APP is the application context in which we work.
1605 TO is a pointer to an XrmValue holding the color to free.
1606 CLOSURE is the value we stored in CLOSURE_RET for this color
1607 in cvt_string_to_pixel.
1609 ARGS and NARGS are like for cvt_string_to_pixel. */
1612 cvt_pixel_dtor (app
, to
, closure
, args
, nargs
)
1621 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1623 "Screen and colormap arguments required",
1626 else if (closure
!= NULL
)
1628 /* We did allocate the pixel, so free it. */
1629 Screen
*screen
= *(Screen
**) args
[0].addr
;
1630 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1631 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1632 (Pixel
*) to
->addr
, 1);
1637 #endif /* USE_X_TOOLKIT */
1640 /* Value is an array of XColor structures for the contents of the
1641 color map of display DPY. Set *NCELLS to the size of the array.
1642 Note that this probably shouldn't be called for large color maps,
1643 say a 24-bit TrueColor map. */
1645 static const XColor
*
1646 x_color_cells (dpy
, ncells
)
1650 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1652 if (dpyinfo
->color_cells
== NULL
)
1654 Screen
*screen
= dpyinfo
->screen
;
1657 dpyinfo
->ncolor_cells
1658 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1659 dpyinfo
->color_cells
1660 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1661 * sizeof *dpyinfo
->color_cells
);
1663 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1664 dpyinfo
->color_cells
[i
].pixel
= i
;
1666 XQueryColors (dpy
, dpyinfo
->cmap
,
1667 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1670 *ncells
= dpyinfo
->ncolor_cells
;
1671 return dpyinfo
->color_cells
;
1675 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1676 colors in COLORS. Use cached information, if available. */
1679 x_query_colors (f
, colors
, ncolors
)
1684 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1686 if (dpyinfo
->color_cells
)
1689 for (i
= 0; i
< ncolors
; ++i
)
1691 unsigned long pixel
= colors
[i
].pixel
;
1692 xassert (pixel
< dpyinfo
->ncolor_cells
);
1693 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1694 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1698 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1702 /* On frame F, translate pixel color to RGB values for the color in
1703 COLOR. Use cached information, if available. */
1706 x_query_color (f
, color
)
1710 x_query_colors (f
, color
, 1);
1714 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1715 exact match can't be allocated, try the nearest color available.
1716 Value is non-zero if successful. Set *COLOR to the color
1720 x_alloc_nearest_color_1 (dpy
, cmap
, color
)
1727 rc
= XAllocColor (dpy
, cmap
, color
);
1730 /* If we got to this point, the colormap is full, so we're going
1731 to try to get the next closest color. The algorithm used is
1732 a least-squares matching, which is what X uses for closest
1733 color matching with StaticColor visuals. */
1735 unsigned long nearest_delta
= ~0;
1737 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1739 for (nearest
= i
= 0; i
< ncells
; ++i
)
1741 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1742 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1743 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1744 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1746 if (delta
< nearest_delta
)
1749 nearest_delta
= delta
;
1753 color
->red
= cells
[nearest
].red
;
1754 color
->green
= cells
[nearest
].green
;
1755 color
->blue
= cells
[nearest
].blue
;
1756 rc
= XAllocColor (dpy
, cmap
, color
);
1760 /* If allocation succeeded, and the allocated pixel color is not
1761 equal to a cached pixel color recorded earlier, there was a
1762 change in the colormap, so clear the color cache. */
1763 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1764 XColor
*cached_color
;
1766 if (dpyinfo
->color_cells
1767 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1768 (cached_color
->red
!= color
->red
1769 || cached_color
->blue
!= color
->blue
1770 || cached_color
->green
!= color
->green
)))
1772 xfree (dpyinfo
->color_cells
);
1773 dpyinfo
->color_cells
= NULL
;
1774 dpyinfo
->ncolor_cells
= 0;
1778 #ifdef DEBUG_X_COLORS
1780 register_color (color
->pixel
);
1781 #endif /* DEBUG_X_COLORS */
1787 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1788 exact match can't be allocated, try the nearest color available.
1789 Value is non-zero if successful. Set *COLOR to the color
1793 x_alloc_nearest_color (f
, cmap
, color
)
1798 gamma_correct (f
, color
);
1799 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1803 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1804 It's necessary to do this instead of just using PIXEL directly to
1805 get color reference counts right. */
1808 x_copy_color (f
, pixel
)
1810 unsigned long pixel
;
1814 color
.pixel
= pixel
;
1816 x_query_color (f
, &color
);
1817 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1819 #ifdef DEBUG_X_COLORS
1820 register_color (pixel
);
1826 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1827 It's necessary to do this instead of just using PIXEL directly to
1828 get color reference counts right. */
1831 x_copy_dpy_color (dpy
, cmap
, pixel
)
1834 unsigned long pixel
;
1838 color
.pixel
= pixel
;
1840 XQueryColor (dpy
, cmap
, &color
);
1841 XAllocColor (dpy
, cmap
, &color
);
1843 #ifdef DEBUG_X_COLORS
1844 register_color (pixel
);
1850 /* Brightness beyond which a color won't have its highlight brightness
1853 Nominally, highlight colors for `3d' faces are calculated by
1854 brightening an object's color by a constant scale factor, but this
1855 doesn't yield good results for dark colors, so for colors who's
1856 brightness is less than this value (on a scale of 0-65535) have an
1857 use an additional additive factor.
1859 The value here is set so that the default menu-bar/mode-line color
1860 (grey75) will not have its highlights changed at all. */
1861 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1864 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1865 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1866 If this produces the same color as PIXEL, try a color where all RGB
1867 values have DELTA added. Return the allocated color in *PIXEL.
1868 DISPLAY is the X display, CMAP is the colormap to operate on.
1869 Value is non-zero if successful. */
1872 x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
)
1876 unsigned long *pixel
;
1884 /* Get RGB color values. */
1885 color
.pixel
= *pixel
;
1886 x_query_color (f
, &color
);
1888 /* Change RGB values by specified FACTOR. Avoid overflow! */
1889 xassert (factor
>= 0);
1890 new.red
= min (0xffff, factor
* color
.red
);
1891 new.green
= min (0xffff, factor
* color
.green
);
1892 new.blue
= min (0xffff, factor
* color
.blue
);
1894 /* Calculate brightness of COLOR. */
1895 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1897 /* We only boost colors that are darker than
1898 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1899 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1900 /* Make an additive adjustment to NEW, because it's dark enough so
1901 that scaling by FACTOR alone isn't enough. */
1903 /* How far below the limit this color is (0 - 1, 1 being darker). */
1904 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1905 /* The additive adjustment. */
1906 int min_delta
= delta
* dimness
* factor
/ 2;
1910 new.red
= max (0, new.red
- min_delta
);
1911 new.green
= max (0, new.green
- min_delta
);
1912 new.blue
= max (0, new.blue
- min_delta
);
1916 new.red
= min (0xffff, min_delta
+ new.red
);
1917 new.green
= min (0xffff, min_delta
+ new.green
);
1918 new.blue
= min (0xffff, min_delta
+ new.blue
);
1922 /* Try to allocate the color. */
1923 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1926 if (new.pixel
== *pixel
)
1928 /* If we end up with the same color as before, try adding
1929 delta to the RGB values. */
1930 x_free_colors (f
, &new.pixel
, 1);
1932 new.red
= min (0xffff, delta
+ color
.red
);
1933 new.green
= min (0xffff, delta
+ color
.green
);
1934 new.blue
= min (0xffff, delta
+ color
.blue
);
1935 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1946 /* Set up the foreground color for drawing relief lines of glyph
1947 string S. RELIEF is a pointer to a struct relief containing the GC
1948 with which lines will be drawn. Use a color that is FACTOR or
1949 DELTA lighter or darker than the relief's background which is found
1950 in S->f->output_data.x->relief_background. If such a color cannot
1951 be allocated, use DEFAULT_PIXEL, instead. */
1954 x_setup_relief_color (f
, relief
, factor
, delta
, default_pixel
)
1956 struct relief
*relief
;
1959 unsigned long default_pixel
;
1962 struct x_output
*di
= f
->output_data
.x
;
1963 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1964 unsigned long pixel
;
1965 unsigned long background
= di
->relief_background
;
1966 Colormap cmap
= FRAME_X_COLORMAP (f
);
1967 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1968 Display
*dpy
= FRAME_X_DISPLAY (f
);
1970 xgcv
.graphics_exposures
= False
;
1971 xgcv
.line_width
= 1;
1973 /* Free previously allocated color. The color cell will be reused
1974 when it has been freed as many times as it was allocated, so this
1975 doesn't affect faces using the same colors. */
1977 && relief
->allocated_p
)
1979 x_free_colors (f
, &relief
->pixel
, 1);
1980 relief
->allocated_p
= 0;
1983 /* Allocate new color. */
1984 xgcv
.foreground
= default_pixel
;
1986 if (dpyinfo
->n_planes
!= 1
1987 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1989 relief
->allocated_p
= 1;
1990 xgcv
.foreground
= relief
->pixel
= pixel
;
1993 if (relief
->gc
== 0)
1995 xgcv
.stipple
= dpyinfo
->gray
;
1997 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
2000 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
2004 /* Set up colors for the relief lines around glyph string S. */
2007 x_setup_relief_colors (s
)
2008 struct glyph_string
*s
;
2010 struct x_output
*di
= s
->f
->output_data
.x
;
2011 unsigned long color
;
2013 if (s
->face
->use_box_color_for_shadows_p
)
2014 color
= s
->face
->box_color
;
2015 else if (s
->first_glyph
->type
== IMAGE_GLYPH
2017 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
2018 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
2023 /* Get the background color of the face. */
2024 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
2025 color
= xgcv
.background
;
2028 if (di
->white_relief
.gc
== 0
2029 || color
!= di
->relief_background
)
2031 di
->relief_background
= color
;
2032 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
2033 WHITE_PIX_DEFAULT (s
->f
));
2034 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
2035 BLACK_PIX_DEFAULT (s
->f
));
2040 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
2041 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
2042 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
2043 relief. LEFT_P non-zero means draw a relief on the left side of
2044 the rectangle. RIGHT_P non-zero means draw a relief on the right
2045 side of the rectangle. CLIP_RECT is the clipping rectangle to use
2049 x_draw_relief_rect (f
, left_x
, top_y
, right_x
, bottom_y
, width
,
2050 raised_p
, top_p
, bot_p
, left_p
, right_p
, clip_rect
)
2052 int left_x
, top_y
, right_x
, bottom_y
, width
;
2053 int top_p
, bot_p
, left_p
, right_p
, raised_p
;
2054 XRectangle
*clip_rect
;
2056 Display
*dpy
= FRAME_X_DISPLAY (f
);
2057 Window window
= FRAME_X_WINDOW (f
);
2062 gc
= f
->output_data
.x
->white_relief
.gc
;
2064 gc
= f
->output_data
.x
->black_relief
.gc
;
2065 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2069 for (i
= 0; i
< width
; ++i
)
2070 XDrawLine (dpy
, window
, gc
,
2071 left_x
+ i
* left_p
, top_y
+ i
,
2072 right_x
+ 1 - i
* right_p
, top_y
+ i
);
2076 for (i
= 0; i
< width
; ++i
)
2077 XDrawLine (dpy
, window
, gc
,
2078 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
2080 XSetClipMask (dpy
, gc
, None
);
2082 gc
= f
->output_data
.x
->black_relief
.gc
;
2084 gc
= f
->output_data
.x
->white_relief
.gc
;
2085 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
2089 for (i
= 0; i
< width
; ++i
)
2090 XDrawLine (dpy
, window
, gc
,
2091 left_x
+ i
* left_p
, bottom_y
- i
,
2092 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
2096 for (i
= 0; i
< width
; ++i
)
2097 XDrawLine (dpy
, window
, gc
,
2098 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2100 XSetClipMask (dpy
, gc
, None
);
2104 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2105 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2106 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2107 left side of the rectangle. RIGHT_P non-zero means draw a line
2108 on the right side of the rectangle. CLIP_RECT is the clipping
2109 rectangle to use when drawing. */
2112 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2113 left_p
, right_p
, clip_rect
)
2114 struct glyph_string
*s
;
2115 int left_x
, top_y
, right_x
, bottom_y
, width
, left_p
, right_p
;
2116 XRectangle
*clip_rect
;
2120 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2121 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2122 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2125 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2126 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2130 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2131 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2134 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2135 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2139 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2140 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2142 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2143 XSetClipMask (s
->display
, s
->gc
, None
);
2147 /* Draw a box around glyph string S. */
2150 x_draw_glyph_string_box (s
)
2151 struct glyph_string
*s
;
2153 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2154 int left_p
, right_p
;
2155 struct glyph
*last_glyph
;
2156 XRectangle clip_rect
;
2158 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2159 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2160 : window_box_right (s
->w
, s
->area
));
2162 /* The glyph that may have a right box line. */
2163 last_glyph
= (s
->cmp
|| s
->img
2165 : s
->first_glyph
+ s
->nchars
- 1);
2167 width
= eabs (s
->face
->box_line_width
);
2168 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2170 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2172 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2174 bottom_y
= top_y
+ s
->height
- 1;
2176 left_p
= (s
->first_glyph
->left_box_line_p
2177 || (s
->hl
== DRAW_MOUSE_FACE
2179 || s
->prev
->hl
!= s
->hl
)));
2180 right_p
= (last_glyph
->right_box_line_p
2181 || (s
->hl
== DRAW_MOUSE_FACE
2183 || s
->next
->hl
!= s
->hl
)));
2185 get_glyph_string_clip_rect (s
, &clip_rect
);
2187 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2188 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2189 left_p
, right_p
, &clip_rect
);
2192 x_setup_relief_colors (s
);
2193 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2194 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2199 /* Draw foreground of image glyph string S. */
2202 x_draw_image_foreground (s
)
2203 struct glyph_string
*s
;
2206 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2208 /* If first glyph of S has a left box line, start drawing it to the
2209 right of that line. */
2210 if (s
->face
->box
!= FACE_NO_BOX
2211 && s
->first_glyph
->left_box_line_p
2213 x
+= eabs (s
->face
->box_line_width
);
2215 /* If there is a margin around the image, adjust x- and y-position
2217 if (s
->slice
.x
== 0)
2218 x
+= s
->img
->hmargin
;
2219 if (s
->slice
.y
== 0)
2220 y
+= s
->img
->vmargin
;
2226 /* We can't set both a clip mask and use XSetClipRectangles
2227 because the latter also sets a clip mask. We also can't
2228 trust on the shape extension to be available
2229 (XShapeCombineRegion). So, compute the rectangle to draw
2231 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2234 XRectangle clip_rect
, image_rect
, r
;
2236 xgcv
.clip_mask
= s
->img
->mask
;
2237 xgcv
.clip_x_origin
= x
;
2238 xgcv
.clip_y_origin
= y
;
2239 xgcv
.function
= GXcopy
;
2240 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
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
);
2254 XRectangle clip_rect
, image_rect
, r
;
2256 get_glyph_string_clip_rect (s
, &clip_rect
);
2259 image_rect
.width
= s
->slice
.width
;
2260 image_rect
.height
= s
->slice
.height
;
2261 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2262 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2263 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2264 r
.width
, r
.height
, r
.x
, r
.y
);
2266 /* When the image has a mask, we can expect that at
2267 least part of a mouse highlight or a block cursor will
2268 be visible. If the image doesn't have a mask, make
2269 a block cursor visible by drawing a rectangle around
2270 the image. I believe it's looking better if we do
2271 nothing here for mouse-face. */
2272 if (s
->hl
== DRAW_CURSOR
)
2274 int r
= s
->img
->relief
;
2276 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2278 s
->slice
.width
+ r
*2 - 1,
2279 s
->slice
.height
+ r
*2 - 1);
2284 /* Draw a rectangle if image could not be loaded. */
2285 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2286 s
->slice
.width
- 1, s
->slice
.height
- 1);
2290 /* Draw a relief around the image glyph string S. */
2293 x_draw_image_relief (s
)
2294 struct glyph_string
*s
;
2296 int x0
, y0
, x1
, y1
, thick
, raised_p
;
2299 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2301 /* If first glyph of S has a left box line, start drawing it to the
2302 right of that line. */
2303 if (s
->face
->box
!= FACE_NO_BOX
2304 && s
->first_glyph
->left_box_line_p
2306 x
+= eabs (s
->face
->box_line_width
);
2308 /* If there is a margin around the image, adjust x- and y-position
2310 if (s
->slice
.x
== 0)
2311 x
+= s
->img
->hmargin
;
2312 if (s
->slice
.y
== 0)
2313 y
+= s
->img
->vmargin
;
2315 if (s
->hl
== DRAW_IMAGE_SUNKEN
2316 || s
->hl
== DRAW_IMAGE_RAISED
)
2318 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2319 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2323 thick
= eabs (s
->img
->relief
);
2324 raised_p
= s
->img
->relief
> 0;
2329 x1
= x
+ s
->slice
.width
+ thick
- 1;
2330 y1
= y
+ s
->slice
.height
+ thick
- 1;
2332 x_setup_relief_colors (s
);
2333 get_glyph_string_clip_rect (s
, &r
);
2334 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2336 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2338 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2343 /* Draw the foreground of image glyph string S to PIXMAP. */
2346 x_draw_image_foreground_1 (s
, pixmap
)
2347 struct glyph_string
*s
;
2351 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2353 /* If first glyph of S has a left box line, start drawing it to the
2354 right of that line. */
2355 if (s
->face
->box
!= FACE_NO_BOX
2356 && s
->first_glyph
->left_box_line_p
2358 x
+= eabs (s
->face
->box_line_width
);
2360 /* If there is a margin around the image, adjust x- and y-position
2362 if (s
->slice
.x
== 0)
2363 x
+= s
->img
->hmargin
;
2364 if (s
->slice
.y
== 0)
2365 y
+= s
->img
->vmargin
;
2371 /* We can't set both a clip mask and use XSetClipRectangles
2372 because the latter also sets a clip mask. We also can't
2373 trust on the shape extension to be available
2374 (XShapeCombineRegion). So, compute the rectangle to draw
2376 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2380 xgcv
.clip_mask
= s
->img
->mask
;
2381 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2382 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2383 xgcv
.function
= GXcopy
;
2384 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2386 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2387 s
->slice
.x
, s
->slice
.y
,
2388 s
->slice
.width
, s
->slice
.height
, x
, y
);
2389 XSetClipMask (s
->display
, s
->gc
, None
);
2393 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2394 s
->slice
.x
, s
->slice
.y
,
2395 s
->slice
.width
, s
->slice
.height
, x
, y
);
2397 /* When the image has a mask, we can expect that at
2398 least part of a mouse highlight or a block cursor will
2399 be visible. If the image doesn't have a mask, make
2400 a block cursor visible by drawing a rectangle around
2401 the image. I believe it's looking better if we do
2402 nothing here for mouse-face. */
2403 if (s
->hl
== DRAW_CURSOR
)
2405 int r
= s
->img
->relief
;
2407 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2408 s
->slice
.width
+ r
*2 - 1,
2409 s
->slice
.height
+ r
*2 - 1);
2414 /* Draw a rectangle if image could not be loaded. */
2415 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2416 s
->slice
.width
- 1, s
->slice
.height
- 1);
2420 /* Draw part of the background of glyph string S. X, Y, W, and H
2421 give the rectangle to draw. */
2424 x_draw_glyph_string_bg_rect (s
, x
, y
, w
, h
)
2425 struct glyph_string
*s
;
2430 /* Fill background with a stipple pattern. */
2431 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2432 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2433 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2436 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2440 /* Draw image glyph string S.
2443 s->x +-------------------------
2446 | +-------------------------
2449 | | +-------------------
2455 x_draw_image_glyph_string (s
)
2456 struct glyph_string
*s
;
2458 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2459 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2461 Pixmap pixmap
= None
;
2464 if (s
->slice
.y
== 0)
2465 height
-= box_line_vwidth
;
2466 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2467 height
-= box_line_vwidth
;
2469 /* Fill background with face under the image. Do it only if row is
2470 taller than image or if image has a clip mask to reduce
2472 s
->stippled_p
= s
->face
->stipple
!= 0;
2473 if (height
> s
->slice
.height
2477 || s
->img
->pixmap
== 0
2478 || s
->width
!= s
->background_width
)
2482 /* Create a pixmap as large as the glyph string. Fill it
2483 with the background color. Copy the image to it, using
2484 its mask. Copy the temporary pixmap to the display. */
2485 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2486 int depth
= DefaultDepthOfScreen (screen
);
2488 /* Create a pixmap as large as the glyph string. */
2489 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2490 s
->background_width
,
2493 /* Don't clip in the following because we're working on the
2495 XSetClipMask (s
->display
, s
->gc
, None
);
2497 /* Fill the pixmap with the background color/stipple. */
2500 /* Fill background with a stipple pattern. */
2501 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2502 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2503 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2504 0, 0, s
->background_width
, s
->height
);
2505 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2506 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2511 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2513 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2514 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2515 0, 0, s
->background_width
, s
->height
);
2516 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2524 if (s
->first_glyph
->left_box_line_p
2526 x
+= box_line_hwidth
;
2528 if (s
->slice
.y
== 0)
2529 y
+= box_line_vwidth
;
2531 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2534 s
->background_filled_p
= 1;
2537 /* Draw the foreground. */
2540 x_draw_image_foreground_1 (s
, pixmap
);
2541 x_set_glyph_string_clipping (s
);
2542 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2543 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2544 XFreePixmap (s
->display
, pixmap
);
2547 x_draw_image_foreground (s
);
2549 /* If we must draw a relief around the image, do it. */
2551 || s
->hl
== DRAW_IMAGE_RAISED
2552 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2553 x_draw_image_relief (s
);
2557 /* Draw stretch glyph string S. */
2560 x_draw_stretch_glyph_string (s
)
2561 struct glyph_string
*s
;
2563 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2565 if (s
->hl
== DRAW_CURSOR
2566 && !x_stretch_cursor_p
)
2568 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2569 as wide as the stretch glyph. */
2570 int width
, background_width
= s
->background_width
;
2571 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2575 background_width
-= left_x
- x
;
2578 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2581 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2583 /* Clear rest using the GC of the original non-cursor face. */
2584 if (width
< background_width
)
2587 int w
= background_width
- width
, h
= s
->height
;
2592 if (s
->row
->mouse_face_p
2593 && cursor_in_mouse_face_p (s
->w
))
2595 x_set_mouse_face_gc (s
);
2601 get_glyph_string_clip_rect (s
, &r
);
2602 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2604 if (s
->face
->stipple
)
2606 /* Fill background with a stipple pattern. */
2607 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2608 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2609 XSetFillStyle (s
->display
, gc
, FillSolid
);
2614 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2615 XSetForeground (s
->display
, gc
, xgcv
.background
);
2616 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2617 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2621 else if (!s
->background_filled_p
)
2623 int background_width
= s
->background_width
;
2624 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2626 /* Don't draw into left margin, fringe or scrollbar area
2627 except for header line and mode line. */
2628 if (x
< left_x
&& !s
->row
->mode_line_p
)
2630 background_width
-= left_x
- x
;
2633 if (background_width
> 0)
2634 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2637 s
->background_filled_p
= 1;
2641 /* Draw glyph string S. */
2644 x_draw_glyph_string (s
)
2645 struct glyph_string
*s
;
2647 int relief_drawn_p
= 0;
2649 /* If S draws into the background of its successors, draw the
2650 background of the successors first so that S can draw into it.
2651 This makes S->next use XDrawString instead of XDrawImageString. */
2652 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2655 struct glyph_string
*next
;
2657 for (width
= 0, next
= s
->next
;
2658 next
&& width
< s
->right_overhang
;
2659 width
+= next
->width
, next
= next
->next
)
2660 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2662 x_set_glyph_string_gc (next
);
2663 x_set_glyph_string_clipping (next
);
2664 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2665 x_draw_stretch_glyph_string (next
);
2667 x_draw_glyph_string_background (next
, 1);
2668 next
->num_clips
= 0;
2672 /* Set up S->gc, set clipping and draw S. */
2673 x_set_glyph_string_gc (s
);
2675 /* Draw relief (if any) in advance for char/composition so that the
2676 glyph string can be drawn over it. */
2677 if (!s
->for_overlaps
2678 && s
->face
->box
!= FACE_NO_BOX
2679 && (s
->first_glyph
->type
== CHAR_GLYPH
2680 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2683 x_set_glyph_string_clipping (s
);
2684 x_draw_glyph_string_background (s
, 1);
2685 x_draw_glyph_string_box (s
);
2686 x_set_glyph_string_clipping (s
);
2689 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2691 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2692 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2693 /* We must clip just this glyph. left_overhang part has already
2694 drawn when s->prev was drawn, and right_overhang part will be
2695 drawn later when s->next is drawn. */
2696 x_set_glyph_string_clipping_exactly (s
, s
);
2698 x_set_glyph_string_clipping (s
);
2700 switch (s
->first_glyph
->type
)
2703 x_draw_image_glyph_string (s
);
2707 x_draw_stretch_glyph_string (s
);
2711 if (s
->for_overlaps
)
2712 s
->background_filled_p
= 1;
2714 x_draw_glyph_string_background (s
, 0);
2715 x_draw_glyph_string_foreground (s
);
2718 case COMPOSITE_GLYPH
:
2719 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2720 && ! s
->first_glyph
->u
.cmp
.automatic
))
2721 s
->background_filled_p
= 1;
2723 x_draw_glyph_string_background (s
, 1);
2724 x_draw_composite_glyph_string_foreground (s
);
2731 if (!s
->for_overlaps
)
2733 /* Draw underline. */
2734 if (s
->face
->underline_p
)
2736 unsigned long thickness
, position
;
2739 if (s
->prev
&& s
->prev
->face
->underline_p
)
2741 /* We use the same underline style as the previous one. */
2742 thickness
= s
->prev
->underline_thickness
;
2743 position
= s
->prev
->underline_position
;
2747 /* Get the underline thickness. Default is 1 pixel. */
2748 if (s
->font
&& s
->font
->underline_thickness
> 0)
2749 thickness
= s
->font
->underline_thickness
;
2752 if (x_underline_at_descent_line
)
2753 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2756 /* Get the underline position. This is the recommended
2757 vertical offset in pixels from the baseline to the top of
2758 the underline. This is a signed value according to the
2759 specs, and its default is
2761 ROUND ((maximum descent) / 2), with
2762 ROUND(x) = floor (x + 0.5) */
2764 if (x_use_underline_position_properties
2765 && s
->font
&& s
->font
->underline_position
>= 0)
2766 position
= s
->font
->underline_position
;
2768 position
= (s
->font
->descent
+ 1) / 2;
2770 position
= underline_minimum_offset
;
2772 position
= max (position
, underline_minimum_offset
);
2774 /* Check the sanity of thickness and position. We should
2775 avoid drawing underline out of the current line area. */
2776 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2777 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2778 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2779 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2780 s
->underline_thickness
= thickness
;
2781 s
->underline_position
= position
;
2782 y
= s
->ybase
+ position
;
2783 if (s
->face
->underline_defaulted_p
)
2784 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2785 s
->x
, y
, s
->background_width
, thickness
);
2789 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2790 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2791 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2792 s
->x
, y
, s
->background_width
, thickness
);
2793 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2797 /* Draw overline. */
2798 if (s
->face
->overline_p
)
2800 unsigned long dy
= 0, h
= 1;
2802 if (s
->face
->overline_color_defaulted_p
)
2803 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2804 s
->background_width
, h
);
2808 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2809 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2810 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2811 s
->background_width
, h
);
2812 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2816 /* Draw strike-through. */
2817 if (s
->face
->strike_through_p
)
2819 unsigned long h
= 1;
2820 unsigned long dy
= (s
->height
- h
) / 2;
2822 if (s
->face
->strike_through_color_defaulted_p
)
2823 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2828 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2829 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2830 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2832 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2836 /* Draw relief if not yet drawn. */
2837 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2838 x_draw_glyph_string_box (s
);
2842 struct glyph_string
*prev
;
2844 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2845 if (prev
->hl
!= s
->hl
2846 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2848 /* As prev was drawn while clipped to its own area, we
2849 must draw the right_overhang part using s->hl now. */
2850 enum draw_glyphs_face save
= prev
->hl
;
2853 x_set_glyph_string_gc (prev
);
2854 x_set_glyph_string_clipping_exactly (s
, prev
);
2855 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2856 x_draw_glyph_string_foreground (prev
);
2858 x_draw_composite_glyph_string_foreground (prev
);
2859 XSetClipMask (prev
->display
, prev
->gc
, None
);
2861 prev
->num_clips
= 0;
2867 struct glyph_string
*next
;
2869 for (next
= s
->next
; next
; next
= next
->next
)
2870 if (next
->hl
!= s
->hl
2871 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2873 /* As next will be drawn while clipped to its own area,
2874 we must draw the left_overhang part using s->hl now. */
2875 enum draw_glyphs_face save
= next
->hl
;
2878 x_set_glyph_string_gc (next
);
2879 x_set_glyph_string_clipping_exactly (s
, next
);
2880 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2881 x_draw_glyph_string_foreground (next
);
2883 x_draw_composite_glyph_string_foreground (next
);
2884 XSetClipMask (next
->display
, next
->gc
, None
);
2886 next
->num_clips
= 0;
2891 /* Reset clipping. */
2892 XSetClipMask (s
->display
, s
->gc
, None
);
2896 /* Shift display to make room for inserted glyphs. */
2899 x_shift_glyphs_for_insert (f
, x
, y
, width
, height
, shift_by
)
2901 int x
, y
, width
, height
, shift_by
;
2903 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2904 f
->output_data
.x
->normal_gc
,
2905 x
, y
, width
, height
,
2909 /* Delete N glyphs at the nominal cursor position. Not implemented
2913 x_delete_glyphs (f
, n
)
2921 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2922 If they are <= 0, this is probably an error. */
2925 x_clear_area (dpy
, window
, x
, y
, width
, height
, exposures
)
2932 xassert (width
> 0 && height
> 0);
2933 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2937 /* Clear an entire frame. */
2940 x_clear_frame (struct frame
*f
)
2942 /* Clearing the frame will erase any cursor, so mark them all as no
2944 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2945 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2946 output_cursor
.x
= -1;
2948 /* We don't set the output cursor here because there will always
2949 follow an explicit cursor_to. */
2951 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2953 /* We have to clear the scroll bars, too. If we have changed
2954 colors or something like that, then they should be notified. */
2955 x_scroll_bar_clear (f
);
2957 XFlush (FRAME_X_DISPLAY (f
));
2964 /* Invert the middle quarter of the frame for .15 sec. */
2966 /* We use the select system call to do the waiting, so we have to make
2967 sure it's available. If it isn't, we just won't do visual bells. */
2969 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2972 /* Subtract the `struct timeval' values X and Y, storing the result in
2973 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2976 timeval_subtract (result
, x
, y
)
2977 struct timeval
*result
, x
, y
;
2979 /* Perform the carry for the later subtraction by updating y. This
2980 is safer because on some systems the tv_sec member is unsigned. */
2981 if (x
.tv_usec
< y
.tv_usec
)
2983 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2984 y
.tv_usec
-= 1000000 * nsec
;
2988 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2990 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2991 y
.tv_usec
+= 1000000 * nsec
;
2995 /* Compute the time remaining to wait. tv_usec is certainly
2997 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2998 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
3000 /* Return indication of whether the result should be considered
3002 return x
.tv_sec
< y
.tv_sec
;
3014 /* Create a GC that will use the GXxor function to flip foreground
3015 pixels into background pixels. */
3019 values
.function
= GXxor
;
3020 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
3021 ^ FRAME_BACKGROUND_PIXEL (f
));
3023 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3024 GCFunction
| GCForeground
, &values
);
3028 /* Get the height not including a menu bar widget. */
3029 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
3030 /* Height of each line to flash. */
3031 int flash_height
= FRAME_LINE_HEIGHT (f
);
3032 /* These will be the left and right margins of the rectangles. */
3033 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
3034 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
3038 /* Don't flash the area between a scroll bar and the frame
3039 edge it is next to. */
3040 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
3042 case vertical_scroll_bar_left
:
3043 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3046 case vertical_scroll_bar_right
:
3047 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
3054 width
= flash_right
- flash_left
;
3056 /* If window is tall, flash top and bottom line. */
3057 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3059 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3061 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3062 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3063 width
, flash_height
);
3064 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3066 (height
- flash_height
3067 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3068 width
, flash_height
);
3071 /* If it is short, flash it all. */
3072 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3073 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3074 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3079 struct timeval wakeup
;
3081 EMACS_GET_TIME (wakeup
);
3083 /* Compute time to wait until, propagating carry from usecs. */
3084 wakeup
.tv_usec
+= 150000;
3085 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
3086 wakeup
.tv_usec
%= 1000000;
3088 /* Keep waiting until past the time wakeup or any input gets
3090 while (! detect_input_pending ())
3092 struct timeval current
;
3093 struct timeval timeout
;
3095 EMACS_GET_TIME (current
);
3097 /* Break if result would be negative. */
3098 if (timeval_subtract (¤t
, wakeup
, current
))
3101 /* How long `select' should wait. */
3103 timeout
.tv_usec
= 10000;
3105 /* Try to wait that long--but we might wake up sooner. */
3106 select (0, NULL
, NULL
, NULL
, &timeout
);
3110 /* If window is tall, flash top and bottom line. */
3111 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3113 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3115 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3116 + FRAME_TOOL_BAR_LINES (f
) * FRAME_LINE_HEIGHT (f
)),
3117 width
, flash_height
);
3118 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3120 (height
- flash_height
3121 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3122 width
, flash_height
);
3125 /* If it is short, flash it all. */
3126 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3127 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3128 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3130 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3138 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3141 /* Make audible bell. */
3146 struct frame
*f
= SELECTED_FRAME ();
3148 if (FRAME_X_DISPLAY (f
))
3150 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3157 XBell (FRAME_X_DISPLAY (f
), 0);
3158 XFlush (FRAME_X_DISPLAY (f
));
3165 /* Specify how many text lines, from the top of the window,
3166 should be affected by insert-lines and delete-lines operations.
3167 This, and those operations, are used only within an update
3168 that is bounded by calls to x_update_begin and x_update_end. */
3171 XTset_terminal_window (n
)
3174 /* This function intentionally left blank. */
3179 /***********************************************************************
3181 ***********************************************************************/
3183 /* Perform an insert-lines or delete-lines operation, inserting N
3184 lines or deleting -N lines at vertical position VPOS. */
3187 x_ins_del_lines (f
, vpos
, n
)
3195 /* Scroll part of the display as described by RUN. */
3198 x_scroll_run (w
, run
)
3202 struct frame
*f
= XFRAME (w
->frame
);
3203 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3205 /* Get frame-relative bounding box of the text display area of W,
3206 without mode lines. Include in this box the left and right
3208 window_box (w
, -1, &x
, &y
, &width
, &height
);
3210 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3211 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3212 bottom_y
= y
+ height
;
3216 /* Scrolling up. Make sure we don't copy part of the mode
3217 line at the bottom. */
3218 if (from_y
+ run
->height
> bottom_y
)
3219 height
= bottom_y
- from_y
;
3221 height
= run
->height
;
3225 /* Scolling down. Make sure we don't copy over the mode line.
3227 if (to_y
+ run
->height
> bottom_y
)
3228 height
= bottom_y
- to_y
;
3230 height
= run
->height
;
3235 /* Cursor off. Will be switched on again in x_update_window_end. */
3239 XCopyArea (FRAME_X_DISPLAY (f
),
3240 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3241 f
->output_data
.x
->normal_gc
,
3251 /***********************************************************************
3253 ***********************************************************************/
3260 /* We used to only do this if Vx_no_window_manager was non-nil, but
3261 the ICCCM (section 4.1.6) says that the window's border pixmap
3262 and border pixel are window attributes which are "private to the
3263 client", so we can always change it to whatever we want. */
3265 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3266 f
->output_data
.x
->border_pixel
);
3268 x_update_cursor (f
, 1);
3269 x_set_frame_alpha (f
);
3273 frame_unhighlight (f
)
3276 /* We used to only do this if Vx_no_window_manager was non-nil, but
3277 the ICCCM (section 4.1.6) says that the window's border pixmap
3278 and border pixel are window attributes which are "private to the
3279 client", so we can always change it to whatever we want. */
3281 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3282 f
->output_data
.x
->border_tile
);
3284 x_update_cursor (f
, 1);
3285 x_set_frame_alpha (f
);
3288 /* The focus has changed. Update the frames as necessary to reflect
3289 the new situation. Note that we can't change the selected frame
3290 here, because the Lisp code we are interrupting might become confused.
3291 Each event gets marked with the frame in which it occurred, so the
3292 Lisp code can tell when the switch took place by examining the events. */
3295 x_new_focus_frame (dpyinfo
, frame
)
3296 struct x_display_info
*dpyinfo
;
3297 struct frame
*frame
;
3299 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3301 if (frame
!= dpyinfo
->x_focus_frame
)
3303 /* Set this before calling other routines, so that they see
3304 the correct value of x_focus_frame. */
3305 dpyinfo
->x_focus_frame
= frame
;
3307 if (old_focus
&& old_focus
->auto_lower
)
3308 x_lower_frame (old_focus
);
3311 selected_frame
= frame
;
3312 XSETFRAME (XWINDOW (selected_frame
->selected_window
)->frame
,
3314 Fselect_window (selected_frame
->selected_window
, Qnil
);
3315 choose_minibuf_frame ();
3318 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3319 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3321 pending_autoraise_frame
= 0;
3324 x_frame_rehighlight (dpyinfo
);
3327 /* Handle FocusIn and FocusOut state changes for FRAME.
3328 If FRAME has focus and there exists more than one frame, puts
3329 a FOCUS_IN_EVENT into *BUFP. */
3332 x_focus_changed (type
, state
, dpyinfo
, frame
, bufp
)
3335 struct x_display_info
*dpyinfo
;
3336 struct frame
*frame
;
3337 struct input_event
*bufp
;
3339 if (type
== FocusIn
)
3341 if (dpyinfo
->x_focus_event_frame
!= frame
)
3343 x_new_focus_frame (dpyinfo
, frame
);
3344 dpyinfo
->x_focus_event_frame
= frame
;
3346 /* Don't stop displaying the initial startup message
3347 for a switch-frame event we don't need. */
3348 if (NILP (Vterminal_frame
)
3349 && CONSP (Vframe_list
)
3350 && !NILP (XCDR (Vframe_list
)))
3352 bufp
->kind
= FOCUS_IN_EVENT
;
3353 XSETFRAME (bufp
->frame_or_window
, frame
);
3357 frame
->output_data
.x
->focus_state
|= state
;
3360 if (FRAME_XIC (frame
))
3361 XSetICFocus (FRAME_XIC (frame
));
3364 else if (type
== FocusOut
)
3366 frame
->output_data
.x
->focus_state
&= ~state
;
3368 if (dpyinfo
->x_focus_event_frame
== frame
)
3370 dpyinfo
->x_focus_event_frame
= 0;
3371 x_new_focus_frame (dpyinfo
, 0);
3375 if (FRAME_XIC (frame
))
3376 XUnsetICFocus (FRAME_XIC (frame
));
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
)
3913 /* Now we know that:
3914 win is the innermost window containing the pointer
3915 (XTC says it has no child containing the pointer),
3916 win_x and win_y are the pointer's position in it
3917 (XTC did this the last time through), and
3918 parent_x and parent_y are the pointer's position in win's parent.
3919 (They are what win_x and win_y were when win was child.
3920 If win is the root window, it has no parent, and
3921 parent_{x,y} are invalid, but that's okay, because we'll
3922 never use them in that case.) */
3924 /* Is win one of our frames? */
3925 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3927 #ifdef USE_X_TOOLKIT
3928 /* If we end up with the menu bar window, say it's not
3931 && f1
->output_data
.x
->menubar_widget
3932 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3934 #endif /* USE_X_TOOLKIT */
3937 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3940 x_uncatch_errors ();
3942 /* If not, is it one of our scroll bars? */
3945 struct scroll_bar
*bar
;
3947 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3951 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3957 if (f1
== 0 && insist
> 0)
3958 f1
= SELECTED_FRAME ();
3962 /* Ok, we found a frame. Store all the values.
3963 last_mouse_glyph is a rectangle used to reduce the
3964 generation of mouse events. To not miss any motion
3965 events, we must divide the frame into rectangles of the
3966 size of the smallest character that could be displayed
3967 on it, i.e. into the same rectangles that matrices on
3968 the frame are divided into. */
3970 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3971 last_mouse_glyph_frame
= f1
;
3976 XSETINT (*x
, win_x
);
3977 XSETINT (*y
, win_y
);
3978 *time
= last_mouse_movement_time
;
3988 /***********************************************************************
3990 ***********************************************************************/
3992 /* Scroll bar support. */
3994 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3996 This can be called in GC, so we have to make sure to strip off mark
3999 static struct scroll_bar
*
4000 x_window_to_scroll_bar (display
, window_id
)
4006 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
4007 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
4008 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
4010 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4012 Lisp_Object frame
, bar
, condemned
;
4014 frame
= XCAR (tail
);
4015 /* All elements of Vframe_list should be frames. */
4016 if (! FRAMEP (frame
))
4019 if (! FRAME_X_P (XFRAME (frame
)))
4022 /* Scan this frame's scroll bar list for a scroll bar with the
4024 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
4025 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
4026 /* This trick allows us to search both the ordinary and
4027 condemned scroll bar lists with one loop. */
4028 ! NILP (bar
) || (bar
= condemned
,
4031 bar
= XSCROLL_BAR (bar
)->next
)
4032 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
4033 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
4034 return XSCROLL_BAR (bar
);
4041 #if defined USE_LUCID
4043 /* Return the Lucid menu bar WINDOW is part of. Return null
4044 if WINDOW is not part of a menu bar. */
4047 x_window_to_menu_bar (window
)
4052 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
4054 if (FRAME_X_P (XFRAME (XCAR (tail
))))
4056 Lisp_Object frame
= XCAR (tail
);
4057 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
4059 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
4067 #endif /* USE_LUCID */
4070 /************************************************************************
4072 ************************************************************************/
4074 #ifdef USE_TOOLKIT_SCROLL_BARS
4076 static void x_scroll_bar_to_input_event
P_ ((XEvent
*, struct input_event
*));
4077 static void x_send_scroll_bar_event
P_ ((Lisp_Object
, int, int, int));
4078 static void x_create_toolkit_scroll_bar
P_ ((struct frame
*,
4079 struct scroll_bar
*));
4080 static void x_set_toolkit_scroll_bar_thumb
P_ ((struct scroll_bar
*,
4084 /* Lisp window being scrolled. Set when starting to interact with
4085 a toolkit scroll bar, reset to nil when ending the interaction. */
4087 static Lisp_Object window_being_scrolled
;
4089 /* Last scroll bar part sent in xm_scroll_callback. */
4091 static int last_scroll_bar_part
;
4093 /* Whether this is an Xaw with arrow-scrollbars. This should imply
4094 that movements of 1/20 of the screen size are mapped to up/down. */
4097 /* Id of action hook installed for scroll bars. */
4099 static XtActionHookId action_hook_id
;
4101 static Boolean xaw3d_arrow_scroll
;
4103 /* Whether the drag scrolling maintains the mouse at the top of the
4104 thumb. If not, resizing the thumb needs to be done more carefully
4105 to avoid jerkyness. */
4107 static Boolean xaw3d_pick_top
;
4109 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4110 bars are used.. The hook is responsible for detecting when
4111 the user ends an interaction with the scroll bar, and generates
4112 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4115 xt_action_hook (widget
, client_data
, action_name
, event
, params
,
4118 XtPointer client_data
;
4122 Cardinal
*num_params
;
4128 scroll_bar_p
= XmIsScrollBar (widget
);
4129 end_action
= "Release";
4130 #else /* !USE_MOTIF i.e. use Xaw */
4131 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4132 end_action
= "EndScroll";
4133 #endif /* USE_MOTIF */
4136 && strcmp (action_name
, end_action
) == 0
4137 && WINDOWP (window_being_scrolled
))
4141 x_send_scroll_bar_event (window_being_scrolled
,
4142 scroll_bar_end_scroll
, 0, 0);
4143 w
= XWINDOW (window_being_scrolled
);
4145 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4147 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4148 /* The thumb size is incorrect while dragging: fix it. */
4149 set_vertical_scroll_bar (w
);
4151 window_being_scrolled
= Qnil
;
4152 last_scroll_bar_part
= -1;
4154 /* Xt timeouts no longer needed. */
4155 toolkit_scroll_bar_interaction
= 0;
4158 #endif /* not USE_GTK */
4160 /* A vector of windows used for communication between
4161 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4163 static struct window
**scroll_bar_windows
;
4164 static int scroll_bar_windows_size
;
4167 /* Send a client message with message type Xatom_Scrollbar for a
4168 scroll action to the frame of WINDOW. PART is a value identifying
4169 the part of the scroll bar that was clicked on. PORTION is the
4170 amount to scroll of a whole of WHOLE. */
4173 x_send_scroll_bar_event (window
, part
, portion
, whole
)
4175 int part
, portion
, whole
;
4178 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4179 struct window
*w
= XWINDOW (window
);
4180 struct frame
*f
= XFRAME (w
->frame
);
4185 /* Construct a ClientMessage event to send to the frame. */
4186 ev
->type
= ClientMessage
;
4187 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4188 ev
->display
= FRAME_X_DISPLAY (f
);
4189 ev
->window
= FRAME_X_WINDOW (f
);
4192 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4193 not enough to store a pointer or Lisp_Object on a 64 bit system.
4194 So, store the window in scroll_bar_windows and pass the index
4195 into that array in the event. */
4196 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4197 if (scroll_bar_windows
[i
] == NULL
)
4200 if (i
== scroll_bar_windows_size
)
4202 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4203 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4204 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4206 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4208 bzero (&scroll_bar_windows
[i
], nbytes
- old_nbytes
);
4209 scroll_bar_windows_size
= new_size
;
4212 scroll_bar_windows
[i
] = w
;
4213 ev
->data
.l
[0] = (long) i
;
4214 ev
->data
.l
[1] = (long) part
;
4215 ev
->data
.l
[2] = (long) 0;
4216 ev
->data
.l
[3] = (long) portion
;
4217 ev
->data
.l
[4] = (long) whole
;
4219 /* Make Xt timeouts work while the scroll bar is active. */
4220 toolkit_scroll_bar_interaction
= 1;
4221 #ifdef USE_X_TOOLKIT
4222 x_activate_timeout_atimer ();
4225 /* Setting the event mask to zero means that the message will
4226 be sent to the client that created the window, and if that
4227 window no longer exists, no event will be sent. */
4228 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4233 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4237 x_scroll_bar_to_input_event (event
, ievent
)
4239 struct input_event
*ievent
;
4241 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4246 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4247 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4249 XSETWINDOW (window
, w
);
4250 f
= XFRAME (w
->frame
);
4252 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4253 ievent
->frame_or_window
= window
;
4256 ievent
->timestamp
= CurrentTime
;
4258 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4260 ievent
->part
= ev
->data
.l
[1];
4261 ievent
->code
= ev
->data
.l
[2];
4262 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4263 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4264 ievent
->modifiers
= 0;
4270 /* Minimum and maximum values used for Motif scroll bars. */
4272 #define XM_SB_MAX 10000000
4275 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4276 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4277 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4280 xm_scroll_callback (widget
, client_data
, call_data
)
4282 XtPointer client_data
, call_data
;
4284 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4285 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4286 int part
= -1, whole
= 0, portion
= 0;
4290 case XmCR_DECREMENT
:
4291 bar
->dragging
= Qnil
;
4292 part
= scroll_bar_up_arrow
;
4295 case XmCR_INCREMENT
:
4296 bar
->dragging
= Qnil
;
4297 part
= scroll_bar_down_arrow
;
4300 case XmCR_PAGE_DECREMENT
:
4301 bar
->dragging
= Qnil
;
4302 part
= scroll_bar_above_handle
;
4305 case XmCR_PAGE_INCREMENT
:
4306 bar
->dragging
= Qnil
;
4307 part
= scroll_bar_below_handle
;
4311 bar
->dragging
= Qnil
;
4312 part
= scroll_bar_to_top
;
4315 case XmCR_TO_BOTTOM
:
4316 bar
->dragging
= Qnil
;
4317 part
= scroll_bar_to_bottom
;
4324 /* Get the slider size. */
4326 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4329 whole
= XM_SB_MAX
- slider_size
;
4330 portion
= min (cs
->value
, whole
);
4331 part
= scroll_bar_handle
;
4332 bar
->dragging
= make_number (cs
->value
);
4336 case XmCR_VALUE_CHANGED
:
4342 window_being_scrolled
= bar
->window
;
4343 last_scroll_bar_part
= part
;
4344 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4348 #elif defined USE_GTK
4350 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4351 bar widget. DATA is a pointer to the scroll_bar structure. */
4354 xg_scroll_callback (widget
, data
)
4358 struct scroll_bar
*bar
= (struct scroll_bar
*) data
;
4364 int part
= -1, whole
= 0, portion
= 0;
4365 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (widget
));
4367 position
= gtk_adjustment_get_value (adj
);
4369 p
= g_object_get_data (G_OBJECT (widget
), XG_LAST_SB_DATA
);
4372 p
= (gdouble
*) xmalloc (sizeof (gdouble
));
4374 g_object_set_data (G_OBJECT (widget
), XG_LAST_SB_DATA
, p
);
4380 if (xg_ignore_gtk_scrollbar
) return;
4382 diff
= (int) (position
- previous
);
4384 if (diff
== (int) adj
->step_increment
)
4386 part
= scroll_bar_down_arrow
;
4387 bar
->dragging
= Qnil
;
4389 else if (-diff
== (int) adj
->step_increment
)
4391 part
= scroll_bar_up_arrow
;
4392 bar
->dragging
= Qnil
;
4394 else if (diff
== (int) adj
->page_increment
)
4396 part
= scroll_bar_below_handle
;
4397 bar
->dragging
= Qnil
;
4399 else if (-diff
== (int) adj
->page_increment
)
4401 part
= scroll_bar_above_handle
;
4402 bar
->dragging
= Qnil
;
4406 part
= scroll_bar_handle
;
4407 whole
= adj
->upper
- adj
->page_size
;
4408 portion
= min ((int)position
, whole
);
4409 bar
->dragging
= make_number ((int)portion
);
4414 window_being_scrolled
= bar
->window
;
4415 last_scroll_bar_part
= part
;
4416 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4420 #else /* not USE_GTK and not USE_MOTIF */
4422 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4423 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4424 scroll bar struct. CALL_DATA is a pointer to a float saying where
4428 xaw_jump_callback (widget
, client_data
, call_data
)
4430 XtPointer client_data
, call_data
;
4432 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4433 float top
= *(float *) call_data
;
4435 int whole
, portion
, height
;
4438 /* Get the size of the thumb, a value between 0 and 1. */
4440 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4444 portion
= shown
< 1 ? top
* whole
: 0;
4446 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4447 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4448 the bottom, so we force the scrolling whenever we see that we're
4449 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4450 we try to ensure that we always stay two pixels away from the
4452 part
= scroll_bar_down_arrow
;
4454 part
= scroll_bar_handle
;
4456 window_being_scrolled
= bar
->window
;
4457 bar
->dragging
= make_number (portion
);
4458 last_scroll_bar_part
= part
;
4459 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4463 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4464 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4465 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4466 the scroll bar. CALL_DATA is an integer specifying the action that
4467 has taken place. Its magnitude is in the range 0..height of the
4468 scroll bar. Negative values mean scroll towards buffer start.
4469 Values < height of scroll bar mean line-wise movement. */
4472 xaw_scroll_callback (widget
, client_data
, call_data
)
4474 XtPointer client_data
, call_data
;
4476 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4477 /* The position really is stored cast to a pointer. */
4478 int position
= (long) call_data
;
4482 /* Get the height of the scroll bar. */
4484 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4487 if (eabs (position
) >= height
)
4488 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4490 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4491 it maps line-movement to call_data = max(5, height/20). */
4492 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4493 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4495 part
= scroll_bar_move_ratio
;
4497 window_being_scrolled
= bar
->window
;
4498 bar
->dragging
= Qnil
;
4499 last_scroll_bar_part
= part
;
4500 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4503 #endif /* not USE_GTK and not USE_MOTIF */
4505 #define SCROLL_BAR_NAME "verticalScrollBar"
4507 /* Create the widget for scroll bar BAR on frame F. Record the widget
4508 and X window of the scroll bar in BAR. */
4512 x_create_toolkit_scroll_bar (f
, bar
)
4514 struct scroll_bar
*bar
;
4516 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4519 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4524 #else /* not USE_GTK */
4527 x_create_toolkit_scroll_bar (f
, bar
)
4529 struct scroll_bar
*bar
;
4535 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4536 unsigned long pixel
;
4541 /* Set resources. Create the widget. */
4542 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4543 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4544 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4545 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4546 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4547 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4548 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4550 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4553 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4557 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4560 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4564 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4565 scroll_bar_name
, av
, ac
);
4567 /* Add one callback for everything that can happen. */
4568 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4570 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4572 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4574 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4576 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4578 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4580 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4583 /* Realize the widget. Only after that is the X window created. */
4584 XtRealizeWidget (widget
);
4586 /* Set the cursor to an arrow. I didn't find a resource to do that.
4587 And I'm wondering why it hasn't an arrow cursor by default. */
4588 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4589 f
->output_data
.x
->nontext_cursor
);
4591 #else /* !USE_MOTIF i.e. use Xaw */
4593 /* Set resources. Create the widget. The background of the
4594 Xaw3d scroll bar widget is a little bit light for my taste.
4595 We don't alter it here to let users change it according
4596 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4597 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4598 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4599 /* For smoother scrolling with Xaw3d -sm */
4600 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4602 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4605 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4609 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4612 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4616 /* Top/bottom shadow colors. */
4618 /* Allocate them, if necessary. */
4619 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4621 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4622 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4623 &pixel
, 1.2, 0x8000))
4625 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4627 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4629 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4630 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
),
4631 &pixel
, 0.6, 0x4000))
4633 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4636 #ifdef XtNbeNiceToColormap
4637 /* Tell the toolkit about them. */
4638 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4639 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4640 /* We tried to allocate a color for the top/bottom shadow, and
4641 failed, so tell Xaw3d to use dithering instead. */
4643 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4647 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4648 be more consistent with other emacs 3d colors, and since Xaw3d is
4649 not good at dealing with allocation failure. */
4651 /* This tells Xaw3d to use real colors instead of dithering for
4653 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4656 /* Specify the colors. */
4657 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4660 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4663 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4666 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4672 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4673 f
->output_data
.x
->edit_widget
, av
, ac
);
4677 char *val
= initial
;
4678 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4679 #ifdef XtNarrowScrollbars
4680 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4682 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4683 if (xaw3d_arrow_scroll
|| val
== initial
)
4684 { /* ARROW_SCROLL */
4685 xaw3d_arrow_scroll
= True
;
4686 /* Isn't that just a personal preference ? --Stef */
4687 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4691 /* Define callbacks. */
4692 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4693 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4696 /* Realize the widget. Only after that is the X window created. */
4697 XtRealizeWidget (widget
);
4699 #endif /* !USE_MOTIF */
4701 /* Install an action hook that lets us detect when the user
4702 finishes interacting with a scroll bar. */
4703 if (action_hook_id
== 0)
4704 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4706 /* Remember X window and widget in the scroll bar vector. */
4707 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4708 xwindow
= XtWindow (widget
);
4709 bar
->x_window
= xwindow
;
4713 #endif /* not USE_GTK */
4716 /* Set the thumb size and position of scroll bar BAR. We are currently
4717 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4721 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4722 struct scroll_bar
*bar
;
4723 int portion
, position
, whole
;
4725 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4728 #else /* not USE_GTK */
4730 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
)
4731 struct scroll_bar
*bar
;
4732 int portion
, position
, whole
;
4734 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4735 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4742 /* We use an estimate of 30 chars per line rather than the real
4743 `portion' value. This has the disadvantage that the thumb size
4744 is not very representative, but it makes our life a lot easier.
4745 Otherwise, we have to constantly adjust the thumb size, which
4746 we can't always do quickly enough: while dragging, the size of
4747 the thumb might prevent the user from dragging the thumb all the
4748 way to the end. but Motif and some versions of Xaw3d don't allow
4749 updating the thumb size while dragging. Also, even if we can update
4750 its size, the update will often happen too late.
4751 If you don't believe it, check out revision 1.650 of xterm.c to see
4752 what hoops we were going through and the still poor behavior we got. */
4753 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4754 /* When the thumb is at the bottom, position == whole.
4755 So we need to increase `whole' to make space for the thumb. */
4762 top
= (float) position
/ whole
;
4763 shown
= (float) portion
/ whole
;
4766 if (NILP (bar
->dragging
))
4770 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4771 is the scroll bar's maximum and MIN is the scroll bar's minimum
4773 size
= shown
* XM_SB_MAX
;
4774 size
= min (size
, XM_SB_MAX
);
4775 size
= max (size
, 1);
4777 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4778 value
= top
* XM_SB_MAX
;
4779 value
= min (value
, XM_SB_MAX
- size
);
4781 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4783 #else /* !USE_MOTIF i.e. use Xaw */
4789 top
= (float) position
/ whole
;
4790 shown
= (float) portion
/ whole
;
4794 float old_top
, old_shown
;
4796 XtVaGetValues (widget
,
4797 XtNtopOfThumb
, &old_top
,
4798 XtNshown
, &old_shown
,
4802 /* Massage the top+shown values. */
4803 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4804 top
= max (0, min (1, top
));
4807 /* Keep two pixels available for moving the thumb down. */
4808 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4810 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4811 check that your system's configuration file contains a define
4812 for `NARROWPROTO'. See s/freebsd.h for an example. */
4813 if (top
!= old_top
|| shown
!= old_shown
)
4815 if (NILP (bar
->dragging
))
4816 XawScrollbarSetThumb (widget
, top
, shown
);
4819 /* Try to make the scrolling a tad smoother. */
4820 if (!xaw3d_pick_top
)
4821 shown
= min (shown
, old_shown
);
4823 XawScrollbarSetThumb (widget
, top
, shown
);
4827 #endif /* !USE_MOTIF */
4831 #endif /* not USE_GTK */
4833 #endif /* USE_TOOLKIT_SCROLL_BARS */
4837 /************************************************************************
4838 Scroll bars, general
4839 ************************************************************************/
4841 /* Create a scroll bar and return the scroll bar vector for it. W is
4842 the Emacs window on which to create the scroll bar. TOP, LEFT,
4843 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4846 static struct scroll_bar
*
4847 x_scroll_bar_create (w
, top
, left
, width
, height
)
4849 int top
, left
, width
, height
;
4851 struct frame
*f
= XFRAME (w
->frame
);
4852 struct scroll_bar
*bar
4853 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4857 #ifdef USE_TOOLKIT_SCROLL_BARS
4858 x_create_toolkit_scroll_bar (f
, bar
);
4859 #else /* not USE_TOOLKIT_SCROLL_BARS */
4861 XSetWindowAttributes a
;
4865 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4866 if (a
.background_pixel
== -1)
4867 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4869 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4870 | ButtonMotionMask
| PointerMotionHintMask
4872 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4874 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4876 /* Clear the area of W that will serve as a scroll bar. This is
4877 for the case that a window has been split horizontally. In
4878 this case, no clear_frame is generated to reduce flickering. */
4879 if (width
> 0 && height
> 0)
4880 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4882 window_box_height (w
), False
);
4884 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4885 /* Position and size of scroll bar. */
4886 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4888 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4890 /* Border width, depth, class, and visual. */
4897 bar
->x_window
= window
;
4899 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4901 XSETWINDOW (bar
->window
, w
);
4905 bar
->height
= height
;
4908 bar
->dragging
= Qnil
;
4909 bar
->fringe_extended_p
= 0;
4911 /* Add bar to its frame's list of scroll bars. */
4912 bar
->next
= FRAME_SCROLL_BARS (f
);
4914 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4915 if (!NILP (bar
->next
))
4916 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4918 /* Map the window/widget. */
4919 #ifdef USE_TOOLKIT_SCROLL_BARS
4922 xg_update_scrollbar_pos (f
,
4925 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4926 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4928 xg_show_scroll_bar (bar
->x_window
);
4929 #else /* not USE_GTK */
4930 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4931 XtConfigureWidget (scroll_bar
,
4932 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4934 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4935 max (height
, 1), 0);
4936 XtMapWidget (scroll_bar
);
4937 #endif /* not USE_GTK */
4939 #else /* not USE_TOOLKIT_SCROLL_BARS */
4940 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
4941 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4948 #ifndef USE_TOOLKIT_SCROLL_BARS
4950 /* Draw BAR's handle in the proper position.
4952 If the handle is already drawn from START to END, don't bother
4953 redrawing it, unless REBUILD is non-zero; in that case, always
4954 redraw it. (REBUILD is handy for drawing the handle after expose
4957 Normally, we want to constrain the start and end of the handle to
4958 fit inside its rectangle, but if the user is dragging the scroll
4959 bar handle, we want to let them drag it down all the way, so that
4960 the bar's top is as far down as it goes; otherwise, there's no way
4961 to move to the very end of the buffer. */
4964 x_scroll_bar_set_handle (bar
, start
, end
, rebuild
)
4965 struct scroll_bar
*bar
;
4969 int dragging
= ! NILP (bar
->dragging
);
4970 Window w
= bar
->x_window
;
4971 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4972 GC gc
= f
->output_data
.x
->normal_gc
;
4974 /* If the display is already accurate, do nothing. */
4976 && start
== bar
->start
4983 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
4984 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
4985 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4987 /* Make sure the values are reasonable, and try to preserve
4988 the distance between start and end. */
4990 int length
= end
- start
;
4994 else if (start
> top_range
)
4996 end
= start
+ length
;
5000 else if (end
> top_range
&& ! dragging
)
5004 /* Store the adjusted setting in the scroll bar. */
5008 /* Clip the end position, just for display. */
5009 if (end
> top_range
)
5012 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
5013 below top positions, to make sure the handle is always at least
5014 that many pixels tall. */
5015 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
5017 /* Draw the empty space above the handle. Note that we can't clear
5018 zero-height areas; that means "clear to end of window." */
5020 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5021 /* x, y, width, height, and exposures. */
5022 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5023 VERTICAL_SCROLL_BAR_TOP_BORDER
,
5024 inside_width
, start
,
5027 /* Change to proper foreground color if one is specified. */
5028 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5029 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5030 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5032 /* Draw the handle itself. */
5033 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5034 /* x, y, width, height */
5035 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5036 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
5037 inside_width
, end
- start
);
5039 /* Restore the foreground color of the GC if we changed it above. */
5040 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5041 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5042 FRAME_FOREGROUND_PIXEL (f
));
5044 /* Draw the empty space below the handle. Note that we can't
5045 clear zero-height areas; that means "clear to end of window." */
5046 if (end
< inside_height
)
5047 x_clear_area (FRAME_X_DISPLAY (f
), w
,
5048 /* x, y, width, height, and exposures. */
5049 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
5050 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
5051 inside_width
, inside_height
- end
,
5059 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5061 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
5065 x_scroll_bar_remove (bar
)
5066 struct scroll_bar
*bar
;
5068 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5071 #ifdef USE_TOOLKIT_SCROLL_BARS
5073 xg_remove_scroll_bar (f
, bar
->x_window
);
5074 #else /* not USE_GTK */
5075 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
5076 #endif /* not USE_GTK */
5078 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
5081 /* Disassociate this scroll bar from its window. */
5082 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
5088 /* Set the handle of the vertical scroll bar for WINDOW to indicate
5089 that we are displaying PORTION characters out of a total of WHOLE
5090 characters, starting at POSITION. If WINDOW has no scroll bar,
5094 XTset_vertical_scroll_bar (w
, portion
, whole
, position
)
5096 int portion
, whole
, position
;
5098 struct frame
*f
= XFRAME (w
->frame
);
5099 struct scroll_bar
*bar
;
5100 int top
, height
, left
, sb_left
, width
, sb_width
;
5101 int window_y
, window_height
;
5102 #ifdef USE_TOOLKIT_SCROLL_BARS
5103 int fringe_extended_p
;
5106 /* Get window dimensions. */
5107 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
5109 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5110 height
= window_height
;
5112 /* Compute the left edge of the scroll bar area. */
5113 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
5115 /* Compute the width of the scroll bar which might be less than
5116 the width of the area reserved for the scroll bar. */
5117 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5118 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5122 /* Compute the left edge of the scroll bar. */
5123 #ifdef USE_TOOLKIT_SCROLL_BARS
5124 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5125 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5127 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5129 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5130 sb_left
= left
+ width
- sb_width
;
5135 #ifdef USE_TOOLKIT_SCROLL_BARS
5136 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5137 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5138 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5139 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5140 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5142 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5143 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5144 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5145 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5148 /* Does the scroll bar exist yet? */
5149 if (NILP (w
->vertical_scroll_bar
))
5151 if (width
> 0 && height
> 0)
5154 #ifdef USE_TOOLKIT_SCROLL_BARS
5155 if (fringe_extended_p
)
5156 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5157 sb_left
, top
, sb_width
, height
, False
);
5160 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5161 left
, top
, width
, height
, False
);
5165 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5169 /* It may just need to be moved and resized. */
5170 unsigned int mask
= 0;
5172 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5176 if (sb_left
!= bar
->left
)
5178 if (top
!= bar
->top
)
5180 if (sb_width
!= bar
->width
)
5182 if (height
!= bar
->height
)
5185 #ifdef USE_TOOLKIT_SCROLL_BARS
5187 /* Move/size the scroll bar widget. */
5188 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5190 /* Since toolkit scroll bars are smaller than the space reserved
5191 for them on the frame, we have to clear "under" them. */
5192 if (width
> 0 && height
> 0)
5194 if (fringe_extended_p
)
5195 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5196 sb_left
, top
, sb_width
, height
, False
);
5198 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5199 left
, top
, width
, height
, False
);
5202 xg_update_scrollbar_pos (f
,
5205 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5206 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5208 #else /* not USE_GTK */
5209 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5210 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5212 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5213 max (height
, 1), 0);
5214 #endif /* not USE_GTK */
5216 #else /* not USE_TOOLKIT_SCROLL_BARS */
5218 /* Clear areas not covered by the scroll bar because of
5219 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5220 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5222 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5223 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5225 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5226 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5227 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5231 /* Clear areas not covered by the scroll bar because it's not as
5232 wide as the area reserved for it. This makes sure a
5233 previous mode line display is cleared after C-x 2 C-x 1, for
5236 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5237 int rest
= area_width
- sb_width
;
5238 if (rest
> 0 && height
> 0)
5240 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5241 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5242 left
+ area_width
- rest
, top
,
5243 rest
, height
, False
);
5245 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5246 left
, top
, rest
, height
, False
);
5250 /* Move/size the scroll bar window. */
5255 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5257 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5259 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5263 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5265 /* Remember new settings. */
5266 bar
->left
= sb_left
;
5268 bar
->width
= sb_width
;
5269 bar
->height
= height
;
5274 #ifdef USE_TOOLKIT_SCROLL_BARS
5275 bar
->fringe_extended_p
= fringe_extended_p
;
5277 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5278 #else /* not USE_TOOLKIT_SCROLL_BARS */
5279 /* Set the scroll bar's current state, unless we're currently being
5281 if (NILP (bar
->dragging
))
5283 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5286 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5289 int start
= ((double) position
* top_range
) / whole
;
5290 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5291 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5294 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5296 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5300 /* The following three hooks are used when we're doing a thorough
5301 redisplay of the frame. We don't explicitly know which scroll bars
5302 are going to be deleted, because keeping track of when windows go
5303 away is a real pain - "Can you say set-window-configuration, boys
5304 and girls?" Instead, we just assert at the beginning of redisplay
5305 that *all* scroll bars are to be removed, and then save a scroll bar
5306 from the fiery pit when we actually redisplay its window. */
5308 /* Arrange for all scroll bars on FRAME to be removed at the next call
5309 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5310 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5313 XTcondemn_scroll_bars (frame
)
5316 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5317 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5320 bar
= FRAME_SCROLL_BARS (frame
);
5321 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5322 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5323 XSCROLL_BAR (bar
)->prev
= Qnil
;
5324 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5325 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5326 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5331 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5332 Note that WINDOW isn't necessarily condemned at all. */
5335 XTredeem_scroll_bar (window
)
5336 struct window
*window
;
5338 struct scroll_bar
*bar
;
5341 /* We can't redeem this window's scroll bar if it doesn't have one. */
5342 if (NILP (window
->vertical_scroll_bar
))
5345 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5347 /* Unlink it from the condemned list. */
5348 f
= XFRAME (WINDOW_FRAME (window
));
5349 if (NILP (bar
->prev
))
5351 /* If the prev pointer is nil, it must be the first in one of
5353 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5354 /* It's not condemned. Everything's fine. */
5356 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5357 window
->vertical_scroll_bar
))
5358 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5360 /* If its prev pointer is nil, it must be at the front of
5361 one or the other! */
5365 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5367 if (! NILP (bar
->next
))
5368 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5370 bar
->next
= FRAME_SCROLL_BARS (f
);
5372 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5373 if (! NILP (bar
->next
))
5374 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5377 /* Remove all scroll bars on FRAME that haven't been saved since the
5378 last call to `*condemn_scroll_bars_hook'. */
5381 XTjudge_scroll_bars (f
)
5384 Lisp_Object bar
, next
;
5386 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5388 /* Clear out the condemned list now so we won't try to process any
5389 more events on the hapless scroll bars. */
5390 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5392 for (; ! NILP (bar
); bar
= next
)
5394 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5396 x_scroll_bar_remove (b
);
5399 b
->next
= b
->prev
= Qnil
;
5402 /* Now there should be no references to the condemned scroll bars,
5403 and they should get garbage-collected. */
5407 #ifndef USE_TOOLKIT_SCROLL_BARS
5408 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5409 is a no-op when using toolkit scroll bars.
5411 This may be called from a signal handler, so we have to ignore GC
5415 x_scroll_bar_expose (bar
, event
)
5416 struct scroll_bar
*bar
;
5419 Window w
= bar
->x_window
;
5420 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5421 GC gc
= f
->output_data
.x
->normal_gc
;
5422 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5426 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5428 /* Switch to scroll bar foreground color. */
5429 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5430 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5431 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5433 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5434 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5436 /* x, y, width, height */
5438 bar
->width
- 1 - width_trim
- width_trim
,
5441 /* Restore the foreground color of the GC if we changed it above. */
5442 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5443 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5444 FRAME_FOREGROUND_PIXEL (f
));
5449 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5451 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5452 is set to something other than NO_EVENT, it is enqueued.
5454 This may be called from a signal handler, so we have to ignore GC
5459 x_scroll_bar_handle_click (bar
, event
, emacs_event
)
5460 struct scroll_bar
*bar
;
5462 struct input_event
*emacs_event
;
5464 if (! WINDOWP (bar
->window
))
5467 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5468 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5469 emacs_event
->modifiers
5470 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5471 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5472 event
->xbutton
.state
)
5473 | (event
->type
== ButtonRelease
5476 emacs_event
->frame_or_window
= bar
->window
;
5477 emacs_event
->arg
= Qnil
;
5478 emacs_event
->timestamp
= event
->xbutton
.time
;
5481 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5483 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5486 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5487 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5490 if (y
> top_range
) y
= top_range
;
5493 emacs_event
->part
= scroll_bar_above_handle
;
5494 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5495 emacs_event
->part
= scroll_bar_handle
;
5497 emacs_event
->part
= scroll_bar_below_handle
;
5499 /* Just because the user has clicked on the handle doesn't mean
5500 they want to drag it. Lisp code needs to be able to decide
5501 whether or not we're dragging. */
5503 /* If the user has just clicked on the handle, record where they're
5505 if (event
->type
== ButtonPress
5506 && emacs_event
->part
== scroll_bar_handle
)
5507 XSETINT (bar
->dragging
, y
- bar
->start
);
5510 #ifndef USE_TOOLKIT_SCROLL_BARS
5511 /* If the user has released the handle, set it to its final position. */
5512 if (event
->type
== ButtonRelease
5513 && ! NILP (bar
->dragging
))
5515 int new_start
= y
- XINT (bar
->dragging
);
5516 int new_end
= new_start
+ bar
->end
- bar
->start
;
5518 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5519 bar
->dragging
= Qnil
;
5523 /* Same deal here as the other #if 0. */
5525 /* Clicks on the handle are always reported as occurring at the top of
5527 if (emacs_event
->part
== scroll_bar_handle
)
5528 emacs_event
->x
= bar
->start
;
5530 XSETINT (emacs_event
->x
, y
);
5532 XSETINT (emacs_event
->x
, y
);
5535 XSETINT (emacs_event
->y
, top_range
);
5539 #ifndef USE_TOOLKIT_SCROLL_BARS
5541 /* Handle some mouse motion while someone is dragging the scroll bar.
5543 This may be called from a signal handler, so we have to ignore GC
5547 x_scroll_bar_note_movement (bar
, event
)
5548 struct scroll_bar
*bar
;
5551 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5553 last_mouse_movement_time
= event
->xmotion
.time
;
5556 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5558 /* If we're dragging the bar, display it. */
5559 if (! NILP (bar
->dragging
))
5561 /* Where should the handle be now? */
5562 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5564 if (new_start
!= bar
->start
)
5566 int new_end
= new_start
+ bar
->end
- bar
->start
;
5568 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5573 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5575 /* Return information to the user about the current position of the mouse
5576 on the scroll bar. */
5579 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
)
5581 Lisp_Object
*bar_window
;
5582 enum scroll_bar_part
*part
;
5584 unsigned long *time
;
5586 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5587 Window w
= bar
->x_window
;
5588 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5590 Window dummy_window
;
5592 unsigned int dummy_mask
;
5596 /* Get the mouse's position relative to the scroll bar window, and
5598 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5600 /* Root, child, root x and root y. */
5601 &dummy_window
, &dummy_window
,
5602 &dummy_coord
, &dummy_coord
,
5604 /* Position relative to scroll bar. */
5607 /* Mouse buttons and modifier keys. */
5614 = VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
5617 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5619 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5621 if (! NILP (bar
->dragging
))
5622 win_y
-= XINT (bar
->dragging
);
5626 if (win_y
> top_range
)
5630 *bar_window
= bar
->window
;
5632 if (! NILP (bar
->dragging
))
5633 *part
= scroll_bar_handle
;
5634 else if (win_y
< bar
->start
)
5635 *part
= scroll_bar_above_handle
;
5636 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5637 *part
= scroll_bar_handle
;
5639 *part
= scroll_bar_below_handle
;
5641 XSETINT (*x
, win_y
);
5642 XSETINT (*y
, top_range
);
5645 last_mouse_scroll_bar
= Qnil
;
5648 *time
= last_mouse_movement_time
;
5654 /* The screen has been cleared so we may have changed foreground or
5655 background colors, and the scroll bars may need to be redrawn.
5656 Clear out the scroll bars, and ask for expose events, so we can
5660 x_scroll_bar_clear (f
)
5663 #ifndef USE_TOOLKIT_SCROLL_BARS
5666 /* We can have scroll bars even if this is 0,
5667 if we just turned off scroll bar mode.
5668 But in that case we should not clear them. */
5669 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5670 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5671 bar
= XSCROLL_BAR (bar
)->next
)
5672 XClearArea (FRAME_X_DISPLAY (f
),
5673 XSCROLL_BAR (bar
)->x_window
,
5675 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5679 /* The main X event-reading loop - XTread_socket. */
5682 /* Time stamp of enter window event. This is only used by XTread_socket,
5683 but we have to put it out here, since static variables within functions
5684 sometimes don't work. */
5686 static Time enter_timestamp
;
5689 /* This holds the state XLookupString needs to implement dead keys
5690 and other tricks known as "compose processing". _X Window System_
5691 says that a portable program can't use this, but Stephen Gildea assures
5692 me that letting the compiler initialize it to zeros will work okay.
5694 This must be defined outside of XTread_socket, for the same reasons
5695 given for enter_timestamp, above. */
5697 static XComposeStatus compose_status
;
5699 /* Record the last 100 characters stored
5700 to help debug the loss-of-chars-during-GC problem. */
5702 static int temp_index
;
5703 static short temp_buffer
[100];
5705 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5706 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5708 temp_buffer[temp_index++] = (keysym)
5710 /* Set this to nonzero to fake an "X I/O error"
5711 on a particular display. */
5713 struct x_display_info
*XTread_socket_fake_io_error
;
5715 /* When we find no input here, we occasionally do a no-op command
5716 to verify that the X server is still running and we can still talk with it.
5717 We try all the open displays, one by one.
5718 This variable is used for cycling thru the displays. */
5720 static struct x_display_info
*next_noop_dpyinfo
;
5722 #define SET_SAVED_MENU_EVENT(size) \
5725 if (f->output_data.x->saved_menu_event == 0) \
5726 f->output_data.x->saved_menu_event \
5727 = (XEvent *) xmalloc (sizeof (XEvent)); \
5728 bcopy (&event, f->output_data.x->saved_menu_event, size); \
5729 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5730 XSETFRAME (inev.ie.frame_or_window, f); \
5734 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5735 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5745 /* Filter events for the current X input method.
5746 DPYINFO is the display this event is for.
5747 EVENT is the X event to filter.
5749 Returns non-zero if the event was filtered, caller shall not process
5751 Returns zero if event is wasn't filtered. */
5755 x_filter_event (dpyinfo
, event
)
5756 struct x_display_info
*dpyinfo
;
5759 /* XFilterEvent returns non-zero if the input method has
5760 consumed the event. We pass the frame's X window to
5761 XFilterEvent because that's the one for which the IC
5764 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5765 event
->xclient
.window
);
5767 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5772 static int current_count
;
5773 static int current_finish
;
5774 static struct input_event
*current_hold_quit
;
5776 /* This is the filter function invoked by the GTK event loop.
5777 It is invoked before the XEvent is translated to a GdkEvent,
5778 so we have a chance to act on the event before GTK. */
5779 static GdkFilterReturn
5780 event_handler_gdk (gxev
, ev
, data
)
5785 XEvent
*xev
= (XEvent
*) gxev
;
5787 if (current_count
>= 0)
5789 struct x_display_info
*dpyinfo
;
5791 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5794 /* Filter events for the current X input method.
5795 GTK calls XFilterEvent but not for key press and release,
5796 so we do it here. */
5797 if (xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5798 if (dpyinfo
&& x_filter_event (dpyinfo
, xev
))
5799 return GDK_FILTER_REMOVE
;
5803 current_finish
= X_EVENT_NORMAL
;
5807 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5812 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5814 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5815 return GDK_FILTER_REMOVE
;
5817 return GDK_FILTER_CONTINUE
;
5819 #endif /* USE_GTK */
5822 /* Handles the XEvent EVENT on display DPYINFO.
5824 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5825 *FINISH is zero if caller should continue reading events.
5826 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5828 We return the number of characters stored into the buffer. */
5831 handle_one_xevent (dpyinfo
, eventp
, finish
, hold_quit
)
5832 struct x_display_info
*dpyinfo
;
5835 struct input_event
*hold_quit
;
5838 struct input_event ie
;
5839 struct selection_input_event sie
;
5844 struct frame
*f
= NULL
;
5845 struct coding_system coding
;
5846 XEvent event
= *eventp
;
5848 *finish
= X_EVENT_NORMAL
;
5850 EVENT_INIT (inev
.ie
);
5851 inev
.ie
.kind
= NO_EVENT
;
5858 if (event
.xclient
.message_type
5859 == dpyinfo
->Xatom_wm_protocols
5860 && event
.xclient
.format
== 32)
5862 if (event
.xclient
.data
.l
[0]
5863 == dpyinfo
->Xatom_wm_take_focus
)
5865 /* Use x_any_window_to_frame because this
5866 could be the shell widget window
5867 if the frame has no title bar. */
5868 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5870 /* Not quite sure this is needed -pd */
5871 if (f
&& FRAME_XIC (f
))
5872 XSetICFocus (FRAME_XIC (f
));
5874 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5875 instructs the WM to set the input focus automatically for
5876 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5877 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5878 it has set the focus. So, XSetInputFocus below is not
5881 The call to XSetInputFocus below has also caused trouble. In
5882 cases where the XSetInputFocus done by the WM and the one
5883 below are temporally close (on a fast machine), the call
5884 below can generate additional FocusIn events which confuse
5887 /* Since we set WM_TAKE_FOCUS, we must call
5888 XSetInputFocus explicitly. But not if f is null,
5889 since that might be an event for a deleted frame. */
5892 Display
*d
= event
.xclient
.display
;
5893 /* Catch and ignore errors, in case window has been
5894 iconified by a window manager such as GWM. */
5896 XSetInputFocus (d
, event
.xclient
.window
,
5897 /* The ICCCM says this is
5898 the only valid choice. */
5900 event
.xclient
.data
.l
[1]);
5901 /* This is needed to detect the error
5902 if there is an error. */
5904 x_uncatch_errors ();
5906 /* Not certain about handling scroll bars here */
5911 if (event
.xclient
.data
.l
[0]
5912 == dpyinfo
->Xatom_wm_save_yourself
)
5914 /* Save state modify the WM_COMMAND property to
5915 something which can reinstate us. This notifies
5916 the session manager, who's looking for such a
5917 PropertyNotify. Can restart processing when
5918 a keyboard or mouse event arrives. */
5919 /* If we have a session manager, don't set this.
5920 KDE will then start two Emacsen, one for the
5921 session manager and one for this. */
5923 if (! x_session_have_connection ())
5926 f
= x_top_window_to_frame (dpyinfo
,
5927 event
.xclient
.window
);
5928 /* This is just so we only give real data once
5929 for a single Emacs process. */
5930 if (f
== SELECTED_FRAME ())
5931 XSetCommand (FRAME_X_DISPLAY (f
),
5932 event
.xclient
.window
,
5933 initial_argv
, initial_argc
);
5935 XSetCommand (FRAME_X_DISPLAY (f
),
5936 event
.xclient
.window
,
5942 if (event
.xclient
.data
.l
[0]
5943 == dpyinfo
->Xatom_wm_delete_window
)
5945 f
= x_any_window_to_frame (dpyinfo
,
5946 event
.xclient
.window
);
5948 goto OTHER
; /* May be a dialog that is to be removed */
5950 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5951 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5958 if (event
.xclient
.message_type
5959 == dpyinfo
->Xatom_wm_configure_denied
)
5964 if (event
.xclient
.message_type
5965 == dpyinfo
->Xatom_wm_window_moved
)
5968 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5970 new_x
= event
.xclient
.data
.s
[0];
5971 new_y
= event
.xclient
.data
.s
[1];
5975 f
->left_pos
= new_x
;
5982 if (event
.xclient
.message_type
5983 == dpyinfo
->Xatom_editres
)
5985 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5987 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5991 #endif /* HACK_EDITRES */
5993 if ((event
.xclient
.message_type
5994 == dpyinfo
->Xatom_DONE
)
5995 || (event
.xclient
.message_type
5996 == dpyinfo
->Xatom_PAGE
))
5998 /* Ghostview job completed. Kill it. We could
5999 reply with "Next" if we received "Page", but we
6000 currently never do because we are interested in
6001 images, only, which should have 1 page. */
6002 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
6003 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
6006 x_kill_gs_process (pixmap
, f
);
6007 expose_frame (f
, 0, 0, 0, 0);
6011 #ifdef USE_TOOLKIT_SCROLL_BARS
6012 /* Scroll bar callbacks send a ClientMessage from which
6013 we construct an input_event. */
6014 if (event
.xclient
.message_type
6015 == dpyinfo
->Xatom_Scrollbar
)
6017 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
6018 *finish
= X_EVENT_GOTO_OUT
;
6021 #endif /* USE_TOOLKIT_SCROLL_BARS */
6023 /* XEmbed messages from the embedder (if any). */
6024 if (event
.xclient
.message_type
6025 == dpyinfo
->Xatom_XEMBED
)
6027 enum xembed_message msg
= event
.xclient
.data
.l
[1];
6028 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
6029 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6031 *finish
= X_EVENT_GOTO_OUT
;
6035 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
6038 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
6039 *finish
= X_EVENT_DROP
;
6043 case SelectionNotify
:
6044 last_user_time
= event
.xselection
.time
;
6045 #ifdef USE_X_TOOLKIT
6046 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
6048 #endif /* not USE_X_TOOLKIT */
6049 x_handle_selection_notify (&event
.xselection
);
6052 case SelectionClear
: /* Someone has grabbed ownership. */
6053 last_user_time
= event
.xselectionclear
.time
;
6054 #ifdef USE_X_TOOLKIT
6055 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
6057 #endif /* USE_X_TOOLKIT */
6059 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
6061 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
6062 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6063 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6064 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6065 inev
.ie
.frame_or_window
= Qnil
;
6069 case SelectionRequest
: /* Someone wants our selection. */
6070 last_user_time
= event
.xselectionrequest
.time
;
6071 #ifdef USE_X_TOOLKIT
6072 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
6074 #endif /* USE_X_TOOLKIT */
6076 XSelectionRequestEvent
*eventp
6077 = (XSelectionRequestEvent
*) &event
;
6079 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
6080 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
6081 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
6082 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
6083 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
6084 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
6085 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
6086 inev
.ie
.frame_or_window
= Qnil
;
6090 case PropertyNotify
:
6091 last_user_time
= event
.xproperty
.time
;
6092 #if 0 /* This is plain wrong. In the case that we are waiting for a
6093 PropertyNotify used as an ACK in incremental selection
6094 transfer, the property will be on the receiver's window. */
6095 #if defined USE_X_TOOLKIT
6096 if (!x_any_window_to_frame (dpyinfo
, event
.xproperty
.window
))
6100 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
6101 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
6102 x_handle_net_wm_state (f
, &event
.xproperty
);
6104 x_handle_property_notify (&event
.xproperty
);
6107 case ReparentNotify
:
6108 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
6112 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
6113 x_real_positions (f
, &x
, &y
);
6117 /* Perhaps reparented due to a WM restart. Reset this. */
6118 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
6119 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
6124 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
6127 x_check_fullscreen (f
);
6130 /* This seems to be needed for GTK 2.6. */
6131 x_clear_area (event
.xexpose
.display
,
6132 event
.xexpose
.window
,
6133 event
.xexpose
.x
, event
.xexpose
.y
,
6134 event
.xexpose
.width
, event
.xexpose
.height
,
6137 if (f
->async_visible
== 0)
6139 f
->async_visible
= 1;
6140 f
->async_iconified
= 0;
6141 f
->output_data
.x
->has_been_visible
= 1;
6142 SET_FRAME_GARBAGED (f
);
6146 event
.xexpose
.x
, event
.xexpose
.y
,
6147 event
.xexpose
.width
, event
.xexpose
.height
);
6151 #ifndef USE_TOOLKIT_SCROLL_BARS
6152 struct scroll_bar
*bar
;
6154 #if defined USE_LUCID
6155 /* Submenus of the Lucid menu bar aren't widgets
6156 themselves, so there's no way to dispatch events
6157 to them. Recognize this case separately. */
6160 = x_window_to_menu_bar (event
.xexpose
.window
);
6162 xlwmenu_redisplay (widget
);
6164 #endif /* USE_LUCID */
6166 #ifdef USE_TOOLKIT_SCROLL_BARS
6167 /* Dispatch event to the widget. */
6169 #else /* not USE_TOOLKIT_SCROLL_BARS */
6170 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
6171 event
.xexpose
.window
);
6174 x_scroll_bar_expose (bar
, &event
);
6175 #ifdef USE_X_TOOLKIT
6178 #endif /* USE_X_TOOLKIT */
6179 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6183 case GraphicsExpose
: /* This occurs when an XCopyArea's
6184 source area was obscured or not
6186 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6190 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6191 event
.xgraphicsexpose
.width
,
6192 event
.xgraphicsexpose
.height
);
6194 #ifdef USE_X_TOOLKIT
6197 #endif /* USE_X_TOOLKIT */
6200 case NoExpose
: /* This occurs when an XCopyArea's
6201 source area was completely
6206 /* Redo the mouse-highlight after the tooltip has gone. */
6207 if (event
.xmap
.window
== tip_window
)
6210 redo_mouse_highlight ();
6213 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6214 if (f
) /* F may no longer exist if
6215 the frame was deleted. */
6217 /* While a frame is unmapped, display generation is
6218 disabled; you don't want to spend time updating a
6219 display that won't ever be seen. */
6220 f
->async_visible
= 0;
6221 /* We can't distinguish, from the event, whether the window
6222 has become iconified or invisible. So assume, if it
6223 was previously visible, than now it is iconified.
6224 But x_make_frame_invisible clears both
6225 the visible flag and the iconified flag;
6226 and that way, we know the window is not iconified now. */
6227 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6229 f
->async_iconified
= 1;
6231 inev
.ie
.kind
= ICONIFY_EVENT
;
6232 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6238 if (event
.xmap
.window
== tip_window
)
6239 /* The tooltip has been drawn already. Avoid
6240 the SET_FRAME_GARBAGED below. */
6243 /* We use x_top_window_to_frame because map events can
6244 come for sub-windows and they don't mean that the
6245 frame is visible. */
6246 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6249 /* wait_reading_process_output will notice this and update
6250 the frame's display structures.
6251 If we where iconified, we should not set garbaged,
6252 because that stops redrawing on Expose events. This looks
6253 bad if we are called from a recursive event loop
6254 (x_dispatch_event), for example when a dialog is up. */
6255 if (! f
->async_iconified
)
6256 SET_FRAME_GARBAGED (f
);
6258 f
->async_visible
= 1;
6259 f
->async_iconified
= 0;
6260 f
->output_data
.x
->has_been_visible
= 1;
6264 inev
.ie
.kind
= DEICONIFY_EVENT
;
6265 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6267 else if (! NILP (Vframe_list
)
6268 && ! NILP (XCDR (Vframe_list
)))
6269 /* Force a redisplay sooner or later
6270 to update the frame titles
6271 in case this is the second frame. */
6272 record_asynch_buffer_change ();
6278 last_user_time
= event
.xkey
.time
;
6279 ignore_next_mouse_click_timeout
= 0;
6281 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6282 /* Dispatch KeyPress events when in menu. */
6283 if (popup_activated ())
6287 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6289 /* If mouse-highlight is an integer, input clears out
6290 mouse highlighting. */
6291 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6293 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6295 clear_mouse_face (dpyinfo
);
6296 dpyinfo
->mouse_face_hidden
= 1;
6299 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6302 /* Scroll bars consume key events, but we want
6303 the keys to go to the scroll bar's frame. */
6304 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6306 if (widget
&& XmIsScrollBar (widget
))
6308 widget
= XtParent (widget
);
6309 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6312 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6316 KeySym keysym
, orig_keysym
;
6317 /* al%imercury@uunet.uu.net says that making this 81
6318 instead of 80 fixed a bug whereby meta chars made
6321 It seems that some version of XmbLookupString has
6322 a bug of not returning XBufferOverflow in
6323 status_return even if the input is too long to
6324 fit in 81 bytes. So, we must prepare sufficient
6325 bytes for copy_buffer. 513 bytes (256 chars for
6326 two-byte character set) seems to be a fairly good
6327 approximation. -- 2000.8.10 handa@etl.go.jp */
6328 unsigned char copy_buffer
[513];
6329 unsigned char *copy_bufptr
= copy_buffer
;
6330 int copy_bufsiz
= sizeof (copy_buffer
);
6332 Lisp_Object coding_system
= Qlatin_1
;
6336 /* Don't pass keys to GTK. A Tab will shift focus to the
6337 tool bar in GTK 2.4. Keys will still go to menus and
6338 dialogs because in that case popup_activated is TRUE
6340 *finish
= X_EVENT_DROP
;
6344 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6345 extra_keyboard_modifiers
);
6346 modifiers
= event
.xkey
.state
;
6348 /* This will have to go some day... */
6350 /* make_lispy_event turns chars into control chars.
6351 Don't do it here because XLookupString is too eager. */
6352 event
.xkey
.state
&= ~ControlMask
;
6353 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6354 | dpyinfo
->super_mod_mask
6355 | dpyinfo
->hyper_mod_mask
6356 | dpyinfo
->alt_mod_mask
);
6358 /* In case Meta is ComposeCharacter,
6359 clear its status. According to Markus Ehrnsperger
6360 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6361 this enables ComposeCharacter to work whether or
6362 not it is combined with Meta. */
6363 if (modifiers
& dpyinfo
->meta_mod_mask
)
6364 bzero (&compose_status
, sizeof (compose_status
));
6369 Status status_return
;
6371 coding_system
= Vlocale_coding_system
;
6372 nbytes
= XmbLookupString (FRAME_XIC (f
),
6373 &event
.xkey
, copy_bufptr
,
6374 copy_bufsiz
, &keysym
,
6376 if (status_return
== XBufferOverflow
)
6378 copy_bufsiz
= nbytes
+ 1;
6379 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6380 nbytes
= XmbLookupString (FRAME_XIC (f
),
6381 &event
.xkey
, copy_bufptr
,
6382 copy_bufsiz
, &keysym
,
6385 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6386 #if 0 && defined X_HAVE_UTF8_STRING
6387 else if (status_return
== XLookupKeySym
)
6388 { /* Try again but with utf-8. */
6389 coding_system
= Qutf_8
;
6390 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6391 &event
.xkey
, copy_bufptr
,
6392 copy_bufsiz
, &keysym
,
6394 if (status_return
== XBufferOverflow
)
6396 copy_bufsiz
= nbytes
+ 1;
6397 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6398 nbytes
= Xutf8LookupString (FRAME_XIC (f
),
6401 copy_bufsiz
, &keysym
,
6407 if (status_return
== XLookupNone
)
6409 else if (status_return
== XLookupChars
)
6414 else if (status_return
!= XLookupKeySym
6415 && status_return
!= XLookupBoth
)
6419 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6420 copy_bufsiz
, &keysym
,
6423 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6424 copy_bufsiz
, &keysym
,
6428 /* If not using XIM/XIC, and a compose sequence is in progress,
6429 we break here. Otherwise, chars_matched is always 0. */
6430 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6433 bzero (&compose_status
, sizeof (compose_status
));
6434 orig_keysym
= keysym
;
6436 /* Common for all keysym input events. */
6437 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6439 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6440 inev
.ie
.timestamp
= event
.xkey
.time
;
6442 /* First deal with keysyms which have defined
6443 translations to characters. */
6444 if (keysym
>= 32 && keysym
< 128)
6445 /* Avoid explicitly decoding each ASCII character. */
6447 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6448 inev
.ie
.code
= keysym
;
6452 /* Keysyms directly mapped to Unicode characters. */
6453 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6455 if (keysym
< 0x01000080)
6456 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6458 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6459 inev
.ie
.code
= keysym
& 0xFFFFFF;
6463 /* Now non-ASCII. */
6464 if (HASH_TABLE_P (Vx_keysym_table
)
6465 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6469 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6470 ? ASCII_KEYSTROKE_EVENT
6471 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6472 inev
.ie
.code
= XFASTINT (c
);
6476 /* Random non-modifier sorts of keysyms. */
6477 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6478 || keysym
== XK_Delete
6479 #ifdef XK_ISO_Left_Tab
6480 || (keysym
>= XK_ISO_Left_Tab
6481 && keysym
<= XK_ISO_Enter
)
6483 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6484 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6486 /* This recognizes the "extended function
6487 keys". It seems there's no cleaner way.
6488 Test IsModifierKey to avoid handling
6489 mode_switch incorrectly. */
6490 || ((unsigned) (keysym
) >= XK_Select
6491 && (unsigned)(keysym
) < XK_KP_Space
)
6493 #ifdef XK_dead_circumflex
6494 || orig_keysym
== XK_dead_circumflex
6496 #ifdef XK_dead_grave
6497 || orig_keysym
== XK_dead_grave
6499 #ifdef XK_dead_tilde
6500 || orig_keysym
== XK_dead_tilde
6502 #ifdef XK_dead_diaeresis
6503 || orig_keysym
== XK_dead_diaeresis
6505 #ifdef XK_dead_macron
6506 || orig_keysym
== XK_dead_macron
6508 #ifdef XK_dead_degree
6509 || orig_keysym
== XK_dead_degree
6511 #ifdef XK_dead_acute
6512 || orig_keysym
== XK_dead_acute
6514 #ifdef XK_dead_cedilla
6515 || orig_keysym
== XK_dead_cedilla
6517 #ifdef XK_dead_breve
6518 || orig_keysym
== XK_dead_breve
6520 #ifdef XK_dead_ogonek
6521 || orig_keysym
== XK_dead_ogonek
6523 #ifdef XK_dead_caron
6524 || orig_keysym
== XK_dead_caron
6526 #ifdef XK_dead_doubleacute
6527 || orig_keysym
== XK_dead_doubleacute
6529 #ifdef XK_dead_abovedot
6530 || orig_keysym
== XK_dead_abovedot
6532 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6533 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6534 /* Any "vendor-specific" key is ok. */
6535 || (orig_keysym
& (1 << 28))
6536 || (keysym
!= NoSymbol
&& nbytes
== 0))
6537 && ! (IsModifierKey (orig_keysym
)
6538 /* The symbols from XK_ISO_Lock
6539 to XK_ISO_Last_Group_Lock
6540 don't have real modifiers but
6541 should be treated similarly to
6542 Mode_switch by Emacs. */
6543 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6544 || ((unsigned)(orig_keysym
)
6546 && (unsigned)(orig_keysym
)
6547 <= XK_ISO_Last_Group_Lock
)
6551 STORE_KEYSYM_FOR_DEBUG (keysym
);
6552 /* make_lispy_event will convert this to a symbolic
6554 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6555 inev
.ie
.code
= keysym
;
6559 { /* Raw bytes, not keysym. */
6564 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6566 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6568 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6571 if (nchars
< nbytes
)
6573 /* Decode the input data. */
6577 /* The input should be decoded with `coding_system'
6578 which depends on which X*LookupString function
6579 we used just above and the locale. */
6580 setup_coding_system (coding_system
, &coding
);
6581 coding
.src_multibyte
= 0;
6582 coding
.dst_multibyte
= 1;
6583 /* The input is converted to events, thus we can't
6584 handle composition. Anyway, there's no XIM that
6585 gives us composition information. */
6586 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6588 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6589 coding
.destination
= alloca (require
);
6590 coding
.dst_bytes
= require
;
6591 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6592 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6593 nbytes
= coding
.produced
;
6594 nchars
= coding
.produced_char
;
6595 copy_bufptr
= coding
.destination
;
6598 /* Convert the input data to a sequence of
6599 character events. */
6600 for (i
= 0; i
< nbytes
; i
+= len
)
6602 if (nchars
== nbytes
)
6603 c
= copy_bufptr
[i
], len
= 1;
6605 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
,
6607 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6608 ? ASCII_KEYSTROKE_EVENT
6609 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6611 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6616 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6618 if (keysym
== NoSymbol
)
6624 /* Don't dispatch this event since XtDispatchEvent calls
6625 XFilterEvent, and two calls in a row may freeze the
6633 last_user_time
= event
.xkey
.time
;
6635 /* Don't dispatch this event since XtDispatchEvent calls
6636 XFilterEvent, and two calls in a row may freeze the
6644 last_user_time
= event
.xcrossing
.time
;
6645 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6647 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6649 if (f
&& x_mouse_click_focus_ignore_position
)
6650 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6653 if (event
.xcrossing
.focus
)
6655 /* Avoid nasty pop/raise loops. */
6656 if (f
&& (!(f
->auto_raise
)
6658 || (event
.xcrossing
.time
- enter_timestamp
) > 500))
6660 x_new_focus_frame (dpyinfo
, f
);
6661 enter_timestamp
= event
.xcrossing
.time
;
6664 else if (f
== dpyinfo
->x_focus_frame
)
6665 x_new_focus_frame (dpyinfo
, 0);
6668 /* EnterNotify counts as mouse movement,
6669 so update things that depend on mouse position. */
6670 if (f
&& !f
->output_data
.x
->hourglass_p
)
6671 note_mouse_movement (f
, &event
.xmotion
);
6673 /* We may get an EnterNotify on the buttons in the toolbar. In that
6674 case we moved out of any highlighted area and need to note this. */
6675 if (!f
&& last_mouse_glyph_frame
)
6676 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6681 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6685 last_user_time
= event
.xcrossing
.time
;
6686 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6688 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6691 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6693 /* If we move outside the frame, then we're
6694 certainly no longer on any text in the frame. */
6695 clear_mouse_face (dpyinfo
);
6696 dpyinfo
->mouse_face_mouse_frame
= 0;
6699 /* Generate a nil HELP_EVENT to cancel a help-echo.
6700 Do it only if there's something to cancel.
6701 Otherwise, the startup message is cleared when
6702 the mouse leaves the frame. */
6703 if (any_help_event_p
)
6707 /* See comment in EnterNotify above */
6708 else if (last_mouse_glyph_frame
)
6709 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6714 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6719 last_user_time
= event
.xmotion
.time
;
6720 previous_help_echo_string
= help_echo_string
;
6721 help_echo_string
= Qnil
;
6723 if (dpyinfo
->grabbed
&& last_mouse_frame
6724 && FRAME_LIVE_P (last_mouse_frame
))
6725 f
= last_mouse_frame
;
6727 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6729 if (dpyinfo
->mouse_face_hidden
)
6731 dpyinfo
->mouse_face_hidden
= 0;
6732 clear_mouse_face (dpyinfo
);
6738 /* Generate SELECT_WINDOW_EVENTs when needed.
6739 Don't let popup menus influence things (bug#1261). */
6740 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6744 window
= window_from_coordinates (f
,
6745 event
.xmotion
.x
, event
.xmotion
.y
,
6748 /* Window will be selected only when it is not selected now and
6749 last mouse movement event was not in it. Minibuffer window
6750 will be selected only when it is active. */
6751 if (WINDOWP (window
)
6752 && !EQ (window
, last_window
)
6753 && !EQ (window
, selected_window
)
6754 /* For click-to-focus window managers
6755 create event iff we don't leave the
6757 && (focus_follows_mouse
6758 || (EQ (XWINDOW (window
)->frame
,
6759 XWINDOW (selected_window
)->frame
))))
6761 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6762 inev
.ie
.frame_or_window
= window
;
6767 if (!note_mouse_movement (f
, &event
.xmotion
))
6768 help_echo_string
= previous_help_echo_string
;
6772 #ifndef USE_TOOLKIT_SCROLL_BARS
6773 struct scroll_bar
*bar
6774 = x_window_to_scroll_bar (event
.xmotion
.display
,
6775 event
.xmotion
.window
);
6778 x_scroll_bar_note_movement (bar
, &event
);
6779 #endif /* USE_TOOLKIT_SCROLL_BARS */
6781 /* If we move outside the frame, then we're
6782 certainly no longer on any text in the frame. */
6783 clear_mouse_face (dpyinfo
);
6786 /* If the contents of the global variable help_echo_string
6787 has changed, generate a HELP_EVENT. */
6788 if (!NILP (help_echo_string
)
6789 || !NILP (previous_help_echo_string
))
6794 case ConfigureNotify
:
6795 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6798 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6799 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6801 xg_frame_resized (f
, event
.xconfigure
.width
,
6802 event
.xconfigure
.height
);
6808 #ifndef USE_X_TOOLKIT
6810 /* If there is a pending resize for fullscreen, don't
6811 do this one, the right one will come later.
6812 The toolkit version doesn't seem to need this, but we
6813 need to reset it below. */
6815 = ((f
->want_fullscreen
& FULLSCREEN_WAIT
)
6816 && f
->new_text_cols
!= 0);
6817 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6818 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6823 /* In the toolkit version, change_frame_size
6824 is called by the code that handles resizing
6825 of the EmacsFrame widget. */
6827 /* Even if the number of character rows and columns has
6828 not changed, the font size may have changed, so we need
6829 to check the pixel dimensions as well. */
6830 if (columns
!= FRAME_COLS (f
)
6831 || rows
!= FRAME_LINES (f
)
6832 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6833 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6835 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6836 SET_FRAME_GARBAGED (f
);
6837 cancel_mouse_face (f
);
6840 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6841 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6842 #endif /* not USE_GTK */
6846 /* GTK creates windows but doesn't map them.
6847 Only get real positions and check fullscreen when mapped. */
6848 if (FRAME_GTK_OUTER_WIDGET (f
)
6849 && GTK_WIDGET_MAPPED (FRAME_GTK_OUTER_WIDGET (f
)))
6852 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6854 if (f
->want_fullscreen
& FULLSCREEN_WAIT
)
6855 f
->want_fullscreen
&= ~(FULLSCREEN_WAIT
|FULLSCREEN_BOTH
);
6859 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6860 xic_set_statusarea (f
);
6863 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
6865 /* Since the WM decorations come below top_pos now,
6866 we must put them below top_pos in the future. */
6867 f
->win_gravity
= NorthWestGravity
;
6868 x_wm_set_size_hint (f
, (long) 0, 0);
6876 /* If we decide we want to generate an event to be seen
6877 by the rest of Emacs, we put it here. */
6880 bzero (&compose_status
, sizeof (compose_status
));
6881 last_mouse_glyph_frame
= 0;
6882 last_user_time
= event
.xbutton
.time
;
6884 if (dpyinfo
->grabbed
6886 && FRAME_LIVE_P (last_mouse_frame
))
6887 f
= last_mouse_frame
;
6889 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6893 /* Is this in the tool-bar? */
6894 if (WINDOWP (f
->tool_bar_window
)
6895 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6898 int x
= event
.xbutton
.x
;
6899 int y
= event
.xbutton
.y
;
6901 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6902 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6904 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6906 handle_tool_bar_click (f
, x
, y
,
6907 event
.xbutton
.type
== ButtonPress
,
6908 x_x_to_emacs_modifiers (dpyinfo
,
6909 event
.xbutton
.state
));
6914 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6915 if (! popup_activated ())
6918 if (ignore_next_mouse_click_timeout
)
6920 if (event
.type
== ButtonPress
6921 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6923 ignore_next_mouse_click_timeout
= 0;
6924 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6926 if (event
.type
== ButtonRelease
)
6927 ignore_next_mouse_click_timeout
= 0;
6930 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6932 if (FRAME_X_EMBEDDED_P (f
))
6933 xembed_send_message (f
, event
.xbutton
.time
,
6934 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6938 struct scroll_bar
*bar
6939 = x_window_to_scroll_bar (event
.xbutton
.display
,
6940 event
.xbutton
.window
);
6942 #ifdef USE_TOOLKIT_SCROLL_BARS
6943 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6945 if (bar
&& event
.xbutton
.state
& ControlMask
)
6947 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6948 *finish
= X_EVENT_DROP
;
6950 #else /* not USE_TOOLKIT_SCROLL_BARS */
6952 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6953 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6956 if (event
.type
== ButtonPress
)
6958 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6959 last_mouse_frame
= f
;
6962 last_tool_bar_item
= -1;
6965 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6967 /* Ignore any mouse motion that happened before this event;
6968 any subsequent mouse-movement Emacs events should reflect
6969 only motion after the ButtonPress/Release. */
6973 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6974 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6975 /* For a down-event in the menu bar,
6976 don't pass it to Xt right now.
6977 Instead, save it away
6978 and we will pass it to Xt from kbd_buffer_get_event.
6979 That way, we can run some Lisp code first. */
6982 ! popup_activated ()
6983 /* Gtk+ menus only react to the first three buttons. */
6984 && event
.xbutton
.button
< 3
6987 f
&& event
.type
== ButtonPress
6988 /* Verify the event is really within the menu bar
6989 and not just sent to it due to grabbing. */
6990 && event
.xbutton
.x
>= 0
6991 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6992 && event
.xbutton
.y
>= 0
6993 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6994 && event
.xbutton
.same_screen
)
6996 SET_SAVED_BUTTON_EVENT
;
6997 XSETFRAME (last_mouse_press_frame
, f
);
6999 *finish
= X_EVENT_DROP
;
7002 else if (event
.type
== ButtonPress
)
7004 last_mouse_press_frame
= Qnil
;
7008 #ifdef USE_MOTIF /* This should do not harm for Lucid,
7009 but I am trying to be cautious. */
7010 else if (event
.type
== ButtonRelease
)
7012 if (!NILP (last_mouse_press_frame
))
7014 f
= XFRAME (last_mouse_press_frame
);
7015 if (f
->output_data
.x
)
7016 SET_SAVED_BUTTON_EVENT
;
7021 #endif /* USE_MOTIF */
7024 #endif /* USE_X_TOOLKIT || USE_GTK */
7028 case CirculateNotify
:
7031 case CirculateRequest
:
7034 case VisibilityNotify
:
7038 /* Someone has changed the keyboard mapping - update the
7040 switch (event
.xmapping
.request
)
7042 case MappingModifier
:
7043 x_find_modifier_meanings (dpyinfo
);
7044 /* This is meant to fall through. */
7045 case MappingKeyboard
:
7046 XRefreshKeyboardMapping (&event
.xmapping
);
7052 #ifdef USE_X_TOOLKIT
7054 if (*finish
!= X_EVENT_DROP
)
7055 XtDispatchEvent (&event
);
7057 #endif /* USE_X_TOOLKIT */
7062 if (inev
.ie
.kind
!= NO_EVENT
)
7064 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
7069 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
7074 XSETFRAME (frame
, f
);
7080 any_help_event_p
= 1;
7081 gen_help_event (help_echo_string
, frame
, help_echo_window
,
7082 help_echo_object
, help_echo_pos
);
7086 help_echo_string
= Qnil
;
7087 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
7097 /* Handles the XEvent EVENT on display DISPLAY.
7098 This is used for event loops outside the normal event handling,
7099 i.e. looping while a popup menu or a dialog is posted.
7101 Returns the value handle_one_xevent sets in the finish argument. */
7103 x_dispatch_event (event
, display
)
7107 struct x_display_info
*dpyinfo
;
7108 int finish
= X_EVENT_NORMAL
;
7110 dpyinfo
= x_display_info_for_display (display
);
7113 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
7119 /* Read events coming from the X server.
7120 This routine is called by the SIGIO handler.
7121 We return as soon as there are no more events to be read.
7123 We return the number of characters stored into the buffer,
7124 thus pretending to be `read' (except the characters we store
7125 in the keyboard buffer can be multibyte, so are not necessarily
7128 EXPECTED is nonzero if the caller knows input is available. */
7131 XTread_socket (terminal
, expected
, hold_quit
)
7132 struct terminal
*terminal
;
7134 struct input_event
*hold_quit
;
7138 int event_found
= 0;
7140 struct x_display_info
*dpyinfo
;
7143 if (interrupt_input_blocked
)
7145 interrupt_input_pending
= 1;
7147 pending_signals
= 1;
7152 interrupt_input_pending
= 0;
7154 pending_signals
= pending_atimers
;
7158 /* So people can tell when we have read the available input. */
7159 input_signal_count
++;
7164 /* Only check session manager input for the primary display. */
7165 if (terminal
->id
== 1 && x_session_have_connection ())
7167 struct input_event inev
;
7169 /* We don't need to EVENT_INIT (inev) here, as
7170 x_session_check_input copies an entire input_event. */
7171 if (x_session_check_input (&inev
))
7173 kbd_buffer_store_event_hold (&inev
, hold_quit
);
7180 /* For debugging, this gives a way to fake an I/O error. */
7181 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
7183 XTread_socket_fake_io_error
= 0;
7184 x_io_error_quitter (terminal
->display_info
.x
->display
);
7187 #if 0 /* This loop is a noop now. */
7188 /* Find the display we are supposed to read input for.
7189 It's the one communicating on descriptor SD. */
7190 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
7192 #if 0 /* This ought to be unnecessary; let's verify it. */
7194 /* If available, Xlib uses FIOSNBIO to make the socket
7195 non-blocking, and then looks for EWOULDBLOCK. If O_NDELAY is set,
7196 FIOSNBIO is ignored, and instead of signaling EWOULDBLOCK,
7197 a read returns 0, which Xlib interprets as equivalent to EPIPE. */
7198 fcntl (dpyinfo
->connection
, F_SETFL
, 0);
7199 #endif /* ! defined (FIOSNBIO) */
7202 #if 0 /* This code can't be made to work, with multiple displays,
7203 and appears not to be used on any system any more.
7204 Also keyboard.c doesn't turn O_NDELAY on and off
7205 for X connections. */
7208 if (! (fcntl (dpyinfo
->connection
, F_GETFL
, 0) & O_NDELAY
))
7210 extern int read_alarm_should_throw
;
7211 read_alarm_should_throw
= 1;
7212 XPeekEvent (dpyinfo
->display
, &event
);
7213 read_alarm_should_throw
= 0;
7215 #endif /* HAVE_SELECT */
7222 while (XPending (terminal
->display_info
.x
->display
))
7226 XNextEvent (terminal
->display_info
.x
->display
, &event
);
7229 /* Filter events for the current X input method. */
7230 if (x_filter_event (terminal
->display_info
.x
, &event
))
7235 count
+= handle_one_xevent (terminal
->display_info
.x
,
7236 &event
, &finish
, hold_quit
);
7238 if (finish
== X_EVENT_GOTO_OUT
)
7244 /* For GTK we must use the GTK event loop. But XEvents gets passed
7245 to our filter function above, and then to the big event switch.
7246 We use a bunch of globals to communicate with our filter function,
7247 that is kind of ugly, but it works.
7249 There is no way to do one display at the time, GTK just does events
7250 from all displays. */
7252 while (gtk_events_pending ())
7254 current_count
= count
;
7255 current_hold_quit
= hold_quit
;
7257 gtk_main_iteration ();
7259 count
= current_count
;
7261 current_hold_quit
= 0;
7263 if (current_finish
== X_EVENT_GOTO_OUT
)
7266 #endif /* USE_GTK */
7270 /* On some systems, an X bug causes Emacs to get no more events
7271 when the window is destroyed. Detect that. (1994.) */
7274 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7275 One XNOOP in 100 loops will make Emacs terminate.
7276 B. Bretthauer, 1994 */
7278 if (x_noop_count
>= 100)
7282 if (next_noop_dpyinfo
== 0)
7283 next_noop_dpyinfo
= x_display_list
;
7285 XNoOp (next_noop_dpyinfo
->display
);
7287 /* Each time we get here, cycle through the displays now open. */
7288 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7292 /* If the focus was just given to an auto-raising frame,
7294 /* ??? This ought to be able to handle more than one such frame. */
7295 if (pending_autoraise_frame
)
7297 x_raise_frame (pending_autoraise_frame
);
7298 pending_autoraise_frame
= 0;
7310 /***********************************************************************
7312 ***********************************************************************/
7314 /* Set clipping for output in glyph row ROW. W is the window in which
7315 we operate. GC is the graphics context to set clipping in.
7317 ROW may be a text row or, e.g., a mode line. Text rows must be
7318 clipped to the interior of the window dedicated to text display,
7319 mode lines must be clipped to the whole window. */
7322 x_clip_to_row (w
, row
, area
, gc
)
7324 struct glyph_row
*row
;
7328 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7329 XRectangle clip_rect
;
7330 int window_x
, window_y
, window_width
;
7332 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7334 clip_rect
.x
= window_x
;
7335 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7336 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7337 clip_rect
.width
= window_width
;
7338 clip_rect
.height
= row
->visible_height
;
7340 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7344 /* Draw a hollow box cursor on window W in glyph row ROW. */
7347 x_draw_hollow_cursor (w
, row
)
7349 struct glyph_row
*row
;
7351 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7352 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7353 Display
*dpy
= FRAME_X_DISPLAY (f
);
7356 struct glyph
*cursor_glyph
;
7359 /* Get the glyph the cursor is on. If we can't tell because
7360 the current matrix is invalid or such, give up. */
7361 cursor_glyph
= get_phys_cursor_glyph (w
);
7362 if (cursor_glyph
== NULL
)
7365 /* Compute frame-relative coordinates for phys cursor. */
7366 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7367 wd
= w
->phys_cursor_width
;
7369 /* The foreground of cursor_gc is typically the same as the normal
7370 background color, which can cause the cursor box to be invisible. */
7371 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7372 if (dpyinfo
->scratch_cursor_gc
)
7373 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7375 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7376 GCForeground
, &xgcv
);
7377 gc
= dpyinfo
->scratch_cursor_gc
;
7379 /* Set clipping, draw the rectangle, and reset clipping again. */
7380 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7381 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7382 XSetClipMask (dpy
, gc
, None
);
7386 /* Draw a bar cursor on window W in glyph row ROW.
7388 Implementation note: One would like to draw a bar cursor with an
7389 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7390 Unfortunately, I didn't find a font yet that has this property set.
7394 x_draw_bar_cursor (w
, row
, width
, kind
)
7396 struct glyph_row
*row
;
7398 enum text_cursor_kinds kind
;
7400 struct frame
*f
= XFRAME (w
->frame
);
7401 struct glyph
*cursor_glyph
;
7403 /* If cursor is out of bounds, don't draw garbage. This can happen
7404 in mini-buffer windows when switching between echo area glyphs
7406 cursor_glyph
= get_phys_cursor_glyph (w
);
7407 if (cursor_glyph
== NULL
)
7410 /* If on an image, draw like a normal cursor. That's usually better
7411 visible than drawing a bar, esp. if the image is large so that
7412 the bar might not be in the window. */
7413 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7415 struct glyph_row
*row
;
7416 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7417 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7421 Display
*dpy
= FRAME_X_DISPLAY (f
);
7422 Window window
= FRAME_X_WINDOW (f
);
7423 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7424 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7425 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7428 /* If the glyph's background equals the color we normally draw
7429 the bar cursor in, the bar cursor in its normal color is
7430 invisible. Use the glyph's foreground color instead in this
7431 case, on the assumption that the glyph's colors are chosen so
7432 that the glyph is legible. */
7433 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7434 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7436 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7437 xgcv
.graphics_exposures
= 0;
7440 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7443 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7444 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7448 width
= FRAME_CURSOR_WIDTH (f
);
7449 width
= min (cursor_glyph
->pixel_width
, width
);
7451 w
->phys_cursor_width
= width
;
7452 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7454 if (kind
== BAR_CURSOR
)
7455 XFillRectangle (dpy
, window
, gc
,
7456 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7457 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7458 width
, row
->height
);
7460 XFillRectangle (dpy
, window
, gc
,
7461 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7462 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7463 row
->height
- width
),
7464 min (FRAME_COLUMN_WIDTH (f
), cursor_glyph
->pixel_width
),
7467 XSetClipMask (dpy
, gc
, None
);
7472 /* RIF: Define cursor CURSOR on frame F. */
7475 x_define_frame_cursor (f
, cursor
)
7479 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7483 /* RIF: Clear area on frame F. */
7486 x_clear_frame_area (f
, x
, y
, width
, height
)
7488 int x
, y
, width
, height
;
7490 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7491 x
, y
, width
, height
, False
);
7495 /* RIF: Draw cursor on window W. */
7498 x_draw_window_cursor (w
, glyph_row
, x
, y
, cursor_type
, cursor_width
, on_p
, active_p
)
7500 struct glyph_row
*glyph_row
;
7502 int cursor_type
, cursor_width
;
7505 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7509 w
->phys_cursor_type
= cursor_type
;
7510 w
->phys_cursor_on_p
= 1;
7512 if (glyph_row
->exact_window_width_line_p
7513 && w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])
7515 glyph_row
->cursor_in_fringe_p
= 1;
7516 draw_fringe_bitmap (w
, glyph_row
, 0);
7519 switch (cursor_type
)
7521 case HOLLOW_BOX_CURSOR
:
7522 x_draw_hollow_cursor (w
, glyph_row
);
7525 case FILLED_BOX_CURSOR
:
7526 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7530 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7534 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7538 w
->phys_cursor_width
= 0;
7546 if (w
== XWINDOW (f
->selected_window
))
7547 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7548 xic_set_preeditarea (w
, x
, y
);
7553 XFlush (FRAME_X_DISPLAY (f
));
7560 /* Make the x-window of frame F use the gnu icon bitmap. */
7563 x_bitmap_icon (f
, file
)
7569 if (FRAME_X_WINDOW (f
) == 0)
7572 /* Free up our existing icon bitmap and mask if any. */
7573 if (f
->output_data
.x
->icon_bitmap
> 0)
7574 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7575 f
->output_data
.x
->icon_bitmap
= 0;
7580 /* Use gtk_window_set_icon_from_file () if available,
7581 It's not restricted to bitmaps */
7582 if (xg_set_icon (f
, file
))
7584 #endif /* USE_GTK */
7585 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7586 x_create_bitmap_mask (f
, bitmap_id
);
7590 /* Create the GNU bitmap and mask if necessary. */
7591 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7595 #if defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7597 if (xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7600 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7602 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7603 #endif /* USE_GTK */
7604 #endif /* defined (HAVE_XPM) && defined (HAVE_X_WINDOWS) */
7606 /* If all else fails, use the (black and white) xbm image. */
7609 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7610 gnu_xbm_width
, gnu_xbm_height
);
7614 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7615 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7619 /* The first time we create the GNU bitmap and mask,
7620 this increments the ref-count one extra time.
7621 As a result, the GNU bitmap and mask are never freed.
7622 That way, we don't have to worry about allocating it again. */
7623 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7625 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7628 x_wm_set_icon_pixmap (f
, bitmap_id
);
7629 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7635 /* Make the x-window of frame F use a rectangle with text.
7636 Use ICON_NAME as the text. */
7639 x_text_icon (f
, icon_name
)
7643 if (FRAME_X_WINDOW (f
) == 0)
7648 text
.value
= (unsigned char *) icon_name
;
7649 text
.encoding
= XA_STRING
;
7651 text
.nitems
= strlen (icon_name
);
7652 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7655 if (f
->output_data
.x
->icon_bitmap
> 0)
7656 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7657 f
->output_data
.x
->icon_bitmap
= 0;
7658 x_wm_set_icon_pixmap (f
, 0);
7663 #define X_ERROR_MESSAGE_SIZE 200
7665 /* If non-nil, this should be a string.
7666 It means catch X errors and store the error message in this string.
7668 The reason we use a stack is that x_catch_error/x_uncatch_error can
7669 be called from a signal handler.
7672 struct x_error_message_stack
{
7673 char string
[X_ERROR_MESSAGE_SIZE
];
7675 struct x_error_message_stack
*prev
;
7677 static struct x_error_message_stack
*x_error_message
;
7679 /* An X error handler which stores the error message in
7680 *x_error_message. This is called from x_error_handler if
7681 x_catch_errors is in effect. */
7684 x_error_catcher (display
, error
)
7688 XGetErrorText (display
, error
->error_code
,
7689 x_error_message
->string
,
7690 X_ERROR_MESSAGE_SIZE
);
7693 /* Begin trapping X errors for display DPY. Actually we trap X errors
7694 for all displays, but DPY should be the display you are actually
7697 After calling this function, X protocol errors no longer cause
7698 Emacs to exit; instead, they are recorded in the string
7699 stored in *x_error_message.
7701 Calling x_check_errors signals an Emacs error if an X error has
7702 occurred since the last call to x_catch_errors or x_check_errors.
7704 Calling x_uncatch_errors resumes the normal error handling. */
7706 void x_check_errors ();
7709 x_catch_errors (dpy
)
7712 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7714 /* Make sure any errors from previous requests have been dealt with. */
7718 data
->string
[0] = 0;
7719 data
->prev
= x_error_message
;
7720 x_error_message
= data
;
7723 /* Undo the last x_catch_errors call.
7724 DPY should be the display that was passed to x_catch_errors. */
7729 struct x_error_message_stack
*tmp
;
7733 /* The display may have been closed before this function is called.
7734 Check if it is still open before calling XSync. */
7735 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7736 XSync (x_error_message
->dpy
, False
);
7738 tmp
= x_error_message
;
7739 x_error_message
= x_error_message
->prev
;
7744 /* If any X protocol errors have arrived since the last call to
7745 x_catch_errors or x_check_errors, signal an Emacs error using
7746 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7749 x_check_errors (dpy
, format
)
7753 /* Make sure to catch any errors incurred so far. */
7756 if (x_error_message
->string
[0])
7758 char string
[X_ERROR_MESSAGE_SIZE
];
7759 bcopy (x_error_message
->string
, string
, X_ERROR_MESSAGE_SIZE
);
7760 x_uncatch_errors ();
7761 error (format
, string
);
7765 /* Nonzero if we had any X protocol errors
7766 since we did x_catch_errors on DPY. */
7769 x_had_errors_p (dpy
)
7772 /* Make sure to catch any errors incurred so far. */
7775 return x_error_message
->string
[0] != 0;
7778 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7781 x_clear_errors (dpy
)
7784 x_error_message
->string
[0] = 0;
7787 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7788 * idea. --lorentey */
7789 /* Close off all unclosed x_catch_errors calls. */
7792 x_fully_uncatch_errors ()
7794 while (x_error_message
)
7795 x_uncatch_errors ();
7799 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7802 x_catching_errors ()
7804 return x_error_message
!= 0;
7808 static unsigned int x_wire_count
;
7811 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7816 /* Handle SIGPIPE, which can happen when the connection to a server
7817 simply goes away. SIGPIPE is handled by x_connection_signal.
7818 Don't need to do anything, because the write which caused the
7819 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7820 which will do the appropriate cleanup for us. */
7823 x_connection_signal (signalnum
) /* If we don't have an argument, */
7824 int signalnum
; /* some compilers complain in signal calls. */
7827 /* USG systems forget handlers when they are used;
7828 must reestablish each time */
7829 signal (signalnum
, x_connection_signal
);
7834 /************************************************************************
7836 ************************************************************************/
7838 /* Error message passed to x_connection_closed. */
7840 static char *error_msg
;
7842 /* Function installed as fatal_error_signal_hook in
7843 x_connection_closed. Print the X error message, and exit normally,
7844 instead of dumping core when XtCloseDisplay fails. */
7847 x_fatal_error_signal ()
7849 fprintf (stderr
, "%s\n", error_msg
);
7853 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7854 the text of an error message that lead to the connection loss. */
7857 x_connection_closed (dpy
, error_message
)
7859 char *error_message
;
7861 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7862 Lisp_Object frame
, tail
;
7863 int index
= SPECPDL_INDEX ();
7865 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7866 strcpy (error_msg
, error_message
);
7867 handling_signal
= 0;
7869 /* Prevent being called recursively because of an error condition
7870 below. Otherwise, we might end up with printing ``can't find per
7871 display information'' in the recursive call instead of printing
7872 the original message here. */
7873 x_catch_errors (dpy
);
7875 /* Inhibit redisplay while frames are being deleted. */
7876 specbind (Qinhibit_redisplay
, Qt
);
7880 /* Protect display from being closed when we delete the last
7882 dpyinfo
->reference_count
++;
7883 dpyinfo
->terminal
->reference_count
++;
7886 /* First delete frames whose mini-buffers are on frames
7887 that are on the dead display. */
7888 FOR_EACH_FRAME (tail
, frame
)
7890 Lisp_Object minibuf_frame
;
7892 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7893 if (FRAME_X_P (XFRAME (frame
))
7894 && FRAME_X_P (XFRAME (minibuf_frame
))
7895 && ! EQ (frame
, minibuf_frame
)
7896 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7897 delete_frame (frame
, Qnoelisp
);
7900 /* Now delete all remaining frames on the dead display.
7901 We are now sure none of these is used as the mini-buffer
7902 for another frame that we need to delete. */
7903 FOR_EACH_FRAME (tail
, frame
)
7904 if (FRAME_X_P (XFRAME (frame
))
7905 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7907 /* Set this to t so that delete_frame won't get confused
7908 trying to find a replacement. */
7909 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7910 delete_frame (frame
, Qnoelisp
);
7913 /* We have to close the display to inform Xt that it doesn't
7914 exist anymore. If we don't, Xt will continue to wait for
7915 events from the display. As a consequence, a sequence of
7917 M-x make-frame-on-display RET :1 RET
7918 ...kill the new frame, so that we get an IO error...
7919 M-x make-frame-on-display RET :1 RET
7921 will indefinitely wait in Xt for events for display `:1', opened
7922 in the first call to make-frame-on-display.
7924 Closing the display is reported to lead to a bus error on
7925 OpenWindows in certain situations. I suspect that is a bug
7926 in OpenWindows. I don't know how to circumvent it here. */
7930 #ifdef USE_X_TOOLKIT
7931 /* If DPYINFO is null, this means we didn't open the display
7932 in the first place, so don't try to close it. */
7934 extern void (*fatal_error_signal_hook
) P_ ((void));
7935 fatal_error_signal_hook
= x_fatal_error_signal
;
7936 XtCloseDisplay (dpy
);
7937 fatal_error_signal_hook
= NULL
;
7942 /* Due to bugs in some Gtk+ versions, just exit here if this
7943 is the last display/terminal. */
7944 if (terminal_list
->next_terminal
== NULL
)
7946 fprintf (stderr
, "%s\n", error_msg
);
7947 shut_down_emacs (0, 0, Qnil
);
7950 xg_display_close (dpyinfo
->display
);
7953 /* Indicate that this display is dead. */
7954 dpyinfo
->display
= 0;
7956 dpyinfo
->reference_count
--;
7957 dpyinfo
->terminal
->reference_count
--;
7958 if (dpyinfo
->reference_count
!= 0)
7959 /* We have just closed all frames on this display. */
7964 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7965 Fdelete_terminal (tmp
, Qnoelisp
);
7969 x_uncatch_errors ();
7971 if (terminal_list
== 0)
7973 fprintf (stderr
, "%s\n", error_msg
);
7974 shut_down_emacs (0, 0, Qnil
);
7978 /* Ordinary stack unwind doesn't deal with these. */
7980 sigunblock (sigmask (SIGIO
));
7982 sigunblock (sigmask (SIGALRM
));
7983 TOTALLY_UNBLOCK_INPUT
;
7985 unbind_to (index
, Qnil
);
7986 clear_waiting_for_input ();
7987 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7988 longjmp), because returning from this function would get us back into
7989 Xlib's code which will directly call `exit'. */
7990 error ("%s", error_msg
);
7993 /* We specifically use it before defining it, so that gcc doesn't inline it,
7994 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7995 static void x_error_quitter
P_ ((Display
*, XErrorEvent
*));
7997 /* This is the first-level handler for X protocol errors.
7998 It calls x_error_quitter or x_error_catcher. */
8001 x_error_handler (display
, error
)
8005 if (x_error_message
)
8006 x_error_catcher (display
, error
);
8008 x_error_quitter (display
, error
);
8012 /* This is the usual handler for X protocol errors.
8013 It kills all frames on the display that we got the error for.
8014 If that was the only one, it prints an error message and kills Emacs. */
8016 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
8018 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
8019 #define NO_INLINE __attribute__((noinline))
8024 /* Some versions of GNU/Linux define noinline in their headers. */
8030 /* On older GCC versions, just putting x_error_quitter
8031 after x_error_handler prevents inlining into the former. */
8033 static void NO_INLINE
8034 x_error_quitter (display
, error
)
8038 char buf
[256], buf1
[356];
8040 /* Ignore BadName errors. They can happen because of fonts
8041 or colors that are not defined. */
8043 if (error
->error_code
== BadName
)
8046 /* Note that there is no real way portable across R3/R4 to get the
8047 original error handler. */
8049 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
8050 sprintf (buf1
, "X protocol error: %s on protocol request %d",
8051 buf
, error
->request_code
);
8052 x_connection_closed (display
, buf1
);
8056 /* This is the handler for X IO errors, always.
8057 It kills all frames on the display that we lost touch with.
8058 If that was the only one, it prints an error message and kills Emacs. */
8061 x_io_error_quitter (display
)
8066 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
8067 x_connection_closed (display
, buf
);
8071 /* Changing the font of the frame. */
8073 /* Give frame F the font FONT-OBJECT as its default font. The return
8074 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
8075 frame. If it is negative, generate a new fontset from
8079 x_new_font (f
, font_object
, fontset
)
8081 Lisp_Object font_object
;
8084 struct font
*font
= XFONT_OBJECT (font_object
);
8087 fontset
= fontset_from_font (font_object
);
8088 FRAME_FONTSET (f
) = fontset
;
8089 if (FRAME_FONT (f
) == font
)
8090 /* This font is already set in frame F. There's nothing more to
8094 FRAME_FONT (f
) = font
;
8095 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
8096 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
8097 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
8098 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
8100 compute_fringe_widths (f
, 1);
8102 /* Compute the scroll bar width in character columns. */
8103 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
8105 int wid
= FRAME_COLUMN_WIDTH (f
);
8106 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
8107 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
8111 int wid
= FRAME_COLUMN_WIDTH (f
);
8112 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
8115 if (FRAME_X_WINDOW (f
) != 0)
8117 /* Don't change the size of a tip frame; there's no point in
8118 doing it because it's done in Fx_show_tip, and it leads to
8119 problems because the tip frame has no widget. */
8120 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8121 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
8126 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
8129 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
8138 /***********************************************************************
8140 ***********************************************************************/
8146 /* XIM destroy callback function, which is called whenever the
8147 connection to input method XIM dies. CLIENT_DATA contains a
8148 pointer to the x_display_info structure corresponding to XIM. */
8151 xim_destroy_callback (xim
, client_data
, call_data
)
8153 XPointer client_data
;
8156 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
8157 Lisp_Object frame
, tail
;
8161 /* No need to call XDestroyIC.. */
8162 FOR_EACH_FRAME (tail
, frame
)
8164 struct frame
*f
= XFRAME (frame
);
8165 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
8167 FRAME_XIC (f
) = NULL
;
8168 xic_free_xfontset (f
);
8172 /* No need to call XCloseIM. */
8173 dpyinfo
->xim
= NULL
;
8174 XFree (dpyinfo
->xim_styles
);
8178 #endif /* HAVE_X11R6 */
8181 /* This isn't prototyped in OSF 5.0 or 5.1a. */
8182 extern char *XSetIMValues
P_ ((XIM
, ...));
8185 /* Open the connection to the XIM server on display DPYINFO.
8186 RESOURCE_NAME is the resource name Emacs uses. */
8189 xim_open_dpy (dpyinfo
, resource_name
)
8190 struct x_display_info
*dpyinfo
;
8191 char *resource_name
;
8199 XCloseIM (dpyinfo
->xim
);
8200 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
8207 XIMCallback destroy
;
8210 /* Get supported styles and XIM values. */
8211 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
8214 destroy
.callback
= xim_destroy_callback
;
8215 destroy
.client_data
= (XPointer
)dpyinfo
;
8216 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
8222 #endif /* HAVE_XIM */
8223 dpyinfo
->xim
= NULL
;
8227 #ifdef HAVE_X11R6_XIM
8229 /* XIM instantiate callback function, which is called whenever an XIM
8230 server is available. DISPLAY is the display of the XIM.
8231 CLIENT_DATA contains a pointer to an xim_inst_t structure created
8232 when the callback was registered. */
8235 xim_instantiate_callback (display
, client_data
, call_data
)
8237 XPointer client_data
;
8240 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
8241 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
8243 /* We don't support multiple XIM connections. */
8247 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
8249 /* Create XIC for the existing frames on the same display, as long
8250 as they have no XIC. */
8251 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
8253 Lisp_Object tail
, frame
;
8256 FOR_EACH_FRAME (tail
, frame
)
8258 struct frame
*f
= XFRAME (frame
);
8261 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
8262 if (FRAME_XIC (f
) == NULL
)
8264 create_frame_xic (f
);
8265 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
8266 xic_set_statusarea (f
);
8267 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
8269 struct window
*w
= XWINDOW (f
->selected_window
);
8270 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8279 #endif /* HAVE_X11R6_XIM */
8282 /* Open a connection to the XIM server on display DPYINFO.
8283 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8284 connection only at the first time. On X11R6, open the connection
8285 in the XIM instantiate callback function. */
8288 xim_initialize (dpyinfo
, resource_name
)
8289 struct x_display_info
*dpyinfo
;
8290 char *resource_name
;
8292 dpyinfo
->xim
= NULL
;
8296 #ifdef HAVE_X11R6_XIM
8297 struct xim_inst_t
*xim_inst
;
8300 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8301 dpyinfo
->xim_callback_data
= xim_inst
;
8302 xim_inst
->dpyinfo
= dpyinfo
;
8303 len
= strlen (resource_name
);
8304 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8305 bcopy (resource_name
, xim_inst
->resource_name
, len
+ 1);
8306 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8307 resource_name
, EMACS_CLASS
,
8308 xim_instantiate_callback
,
8309 /* This is XPointer in XFree86
8310 but (XPointer *) on Tru64, at
8311 least, hence the configure test. */
8312 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8313 #else /* not HAVE_X11R6_XIM */
8314 xim_open_dpy (dpyinfo
, resource_name
);
8315 #endif /* not HAVE_X11R6_XIM */
8317 #endif /* HAVE_XIM */
8321 /* Close the connection to the XIM server on display DPYINFO. */
8324 xim_close_dpy (dpyinfo
)
8325 struct x_display_info
*dpyinfo
;
8330 #ifdef HAVE_X11R6_XIM
8331 if (dpyinfo
->display
)
8332 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8334 xim_instantiate_callback
, NULL
);
8335 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8336 xfree (dpyinfo
->xim_callback_data
);
8337 #endif /* HAVE_X11R6_XIM */
8338 if (dpyinfo
->display
)
8339 XCloseIM (dpyinfo
->xim
);
8340 dpyinfo
->xim
= NULL
;
8341 XFree (dpyinfo
->xim_styles
);
8343 #endif /* HAVE_XIM */
8346 #endif /* not HAVE_X11R6_XIM */
8350 /* Calculate the absolute position in frame F
8351 from its current recorded position values and gravity. */
8354 x_calc_absolute_position (f
)
8357 int flags
= f
->size_hint_flags
;
8359 /* We have nothing to do if the current position
8360 is already for the top-left corner. */
8361 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8364 /* Treat negative positions as relative to the leftmost bottommost
8365 position that fits on the screen. */
8366 if (flags
& XNegative
)
8367 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8368 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8371 int height
= FRAME_PIXEL_HEIGHT (f
);
8373 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8374 /* Something is fishy here. When using Motif, starting Emacs with
8375 `-g -0-0', the frame appears too low by a few pixels.
8377 This seems to be so because initially, while Emacs is starting,
8378 the column widget's height and the frame's pixel height are
8379 different. The column widget's height is the right one. In
8380 later invocations, when Emacs is up, the frame's pixel height
8383 It's not obvious where the initial small difference comes from.
8384 2000-12-01, gerd. */
8386 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8389 if (flags
& YNegative
)
8390 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8391 - height
+ f
->top_pos
;
8394 /* The left_pos and top_pos
8395 are now relative to the top and left screen edges,
8396 so the flags should correspond. */
8397 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8400 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8401 to really change the position, and 0 when calling from
8402 x_make_frame_visible (in that case, XOFF and YOFF are the current
8403 position values). It is -1 when calling from x_set_frame_parameters,
8404 which means, do adjust for borders but don't change the gravity. */
8407 x_set_offset (f
, xoff
, yoff
, change_gravity
)
8409 register int xoff
, yoff
;
8412 int modified_top
, modified_left
;
8414 if (change_gravity
> 0)
8416 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8417 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8421 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8423 f
->size_hint_flags
|= XNegative
;
8425 f
->size_hint_flags
|= YNegative
;
8426 f
->win_gravity
= NorthWestGravity
;
8428 x_calc_absolute_position (f
);
8431 x_wm_set_size_hint (f
, (long) 0, 0);
8433 modified_left
= f
->left_pos
;
8434 modified_top
= f
->top_pos
;
8436 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8438 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8439 than the WM decorations. So we use the calculated offset instead
8440 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8441 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8442 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8445 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8446 modified_left
, modified_top
);
8448 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8449 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8452 /* change_gravity is non-zero when this function is called from Lisp to
8453 programmatically move a frame. In that case, we call
8454 x_check_expected_move to discover if we have a "Type A" or "Type B"
8455 window manager, and, for a "Type A" window manager, adjust the position
8458 We call x_check_expected_move if a programmatic move occurred, and
8459 either the window manager type (A/B) is unknown or it is Type A but we
8460 need to compute the top/left offset adjustment for this frame. */
8462 if (change_gravity
!= 0 &&
8463 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8464 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8465 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8466 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8467 x_check_expected_move (f
, modified_left
, modified_top
);
8472 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8473 on the root window for frame F contains ATOMNAME.
8474 This is how a WM check shall be done according to the Window Manager
8475 Specification/Extended Window Manager Hints at
8476 http://freedesktop.org/wiki/Specifications/wm-spec. */
8479 wm_supports (f
, atomname
)
8481 const char *atomname
;
8484 unsigned long actual_size
, bytes_remaining
;
8485 int i
, rc
, actual_format
;
8487 Window wmcheck_window
;
8488 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8489 Window target_window
= dpyinfo
->root_window
;
8490 long max_len
= 65536;
8491 Display
*dpy
= FRAME_X_DISPLAY (f
);
8492 unsigned char *tmp_data
= NULL
;
8493 Atom target_type
= XA_WINDOW
;
8498 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8500 x_catch_errors (dpy
);
8501 rc
= XGetWindowProperty (dpy
, target_window
,
8502 prop_atom
, 0, max_len
, False
, target_type
,
8503 &actual_type
, &actual_format
, &actual_size
,
8504 &bytes_remaining
, &tmp_data
);
8506 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8508 if (tmp_data
) XFree (tmp_data
);
8509 x_uncatch_errors ();
8514 wmcheck_window
= *(Window
*) tmp_data
;
8517 /* Check if window exists. */
8518 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8520 if (x_had_errors_p (dpy
))
8522 x_uncatch_errors ();
8527 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8529 /* Window changed, reload atoms */
8530 if (dpyinfo
->net_supported_atoms
!= NULL
)
8531 XFree (dpyinfo
->net_supported_atoms
);
8532 dpyinfo
->net_supported_atoms
= NULL
;
8533 dpyinfo
->nr_net_supported_atoms
= 0;
8534 dpyinfo
->net_supported_window
= 0;
8536 target_type
= XA_ATOM
;
8537 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8539 rc
= XGetWindowProperty (dpy
, target_window
,
8540 prop_atom
, 0, max_len
, False
, target_type
,
8541 &actual_type
, &actual_format
, &actual_size
,
8542 &bytes_remaining
, &tmp_data
);
8544 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8546 if (tmp_data
) XFree (tmp_data
);
8547 x_uncatch_errors ();
8552 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8553 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8554 dpyinfo
->net_supported_window
= wmcheck_window
;
8558 want_atom
= XInternAtom (dpy
, atomname
, False
);
8560 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8561 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8563 x_uncatch_errors ();
8569 /* Do fullscreen as specified in extended window manager hints */
8572 do_ewmh_fullscreen (f
)
8575 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8577 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8578 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8580 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8585 const char *atom
= "_NET_WM_STATE";
8586 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8587 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8588 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8589 const char *what
= NULL
;
8591 XSETFRAME (frame
, f
);
8593 /* If there are _NET_ atoms we assume we have extended window manager
8595 switch (f
->want_fullscreen
)
8597 case FULLSCREEN_BOTH
:
8600 case FULLSCREEN_WIDTH
:
8603 case FULLSCREEN_HEIGHT
:
8608 if (what
!= NULL
&& !wm_supports (f
, what
)) return 0;
8611 Fx_send_client_event (frame
, make_number (0), frame
,
8612 make_unibyte_string (atom
, strlen (atom
)),
8614 Fcons (make_number (0), /* Remove */
8616 (make_unibyte_string (fs
,
8619 Fx_send_client_event (frame
, make_number (0), frame
,
8620 make_unibyte_string (atom
, strlen (atom
)),
8622 Fcons (make_number (0), /* Remove */
8624 (make_unibyte_string (fh
,
8627 Fx_send_client_event (frame
, make_number (0), frame
,
8628 make_unibyte_string (atom
, strlen (atom
)),
8630 Fcons (make_number (0), /* Remove */
8632 (make_unibyte_string (fw
,
8635 f
->want_fullscreen
= FULLSCREEN_NONE
;
8637 Fx_send_client_event (frame
, make_number (0), frame
,
8638 make_unibyte_string (atom
, strlen (atom
)),
8640 Fcons (make_number (1), /* Add */
8642 (make_unibyte_string (what
,
8647 return have_net_atom
;
8651 XTfullscreen_hook (f
)
8654 if (f
->async_visible
)
8657 do_ewmh_fullscreen (f
);
8664 extern Lisp_Object Qfullwidth
, Qfullheight
, Qfullboth
;
8666 x_handle_net_wm_state (f
, event
)
8668 XPropertyEvent
*event
;
8671 unsigned long actual_size
, bytes_remaining
;
8672 int i
, rc
, actual_format
, value
= 0;
8673 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8674 long max_len
= 65536;
8675 Display
*dpy
= FRAME_X_DISPLAY (f
);
8676 unsigned char *tmp_data
= NULL
;
8677 Atom target_type
= XA_ATOM
;
8680 x_catch_errors (dpy
);
8681 rc
= XGetWindowProperty (dpy
, event
->window
,
8682 event
->atom
, 0, max_len
, False
, target_type
,
8683 &actual_type
, &actual_format
, &actual_size
,
8684 &bytes_remaining
, &tmp_data
);
8686 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8688 if (tmp_data
) XFree (tmp_data
);
8689 x_uncatch_errors ();
8694 x_uncatch_errors ();
8696 for (i
= 0; i
< actual_size
; ++i
)
8698 Atom a
= ((Atom
*)tmp_data
)[i
];
8699 if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8700 value
|= FULLSCREEN_WIDTH
;
8701 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8702 value
|= FULLSCREEN_HEIGHT
;
8703 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen_atom
)
8704 value
|= FULLSCREEN_BOTH
;
8707 Lisp_Object lval
= Qnil
;
8710 case FULLSCREEN_WIDTH
:
8713 case FULLSCREEN_HEIGHT
:
8716 case FULLSCREEN_BOTH
:
8721 store_frame_param (f
, Qfullscreen
, lval
);
8723 if (tmp_data
) XFree (tmp_data
);
8727 /* Check if we need to resize the frame due to a fullscreen request.
8728 If so needed, resize the frame. */
8730 x_check_fullscreen (f
)
8733 if (f
->want_fullscreen
& FULLSCREEN_BOTH
)
8735 int width
, height
, ign
;
8737 if (do_ewmh_fullscreen (f
))
8740 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
8742 x_fullscreen_adjust (f
, &width
, &height
, &ign
, &ign
);
8744 /* We do not need to move the window, it shall be taken care of
8745 when setting WM manager hints.
8746 If the frame is visible already, the position is checked by
8747 x_check_expected_move. */
8748 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8750 change_frame_size (f
, height
, width
, 0, 1, 0);
8751 SET_FRAME_GARBAGED (f
);
8752 cancel_mouse_face (f
);
8754 /* Wait for the change of frame size to occur */
8755 f
->want_fullscreen
|= FULLSCREEN_WAIT
;
8760 /* This function is called by x_set_offset to determine whether the window
8761 manager interfered with the positioning of the frame. Type A window
8762 managers position the surrounding window manager decorations a small
8763 amount above and left of the user-supplied position. Type B window
8764 managers position the surrounding window manager decorations at the
8765 user-specified position. If we detect a Type A window manager, we
8766 compensate by moving the window right and down by the proper amount. */
8769 x_check_expected_move (f
, expected_left
, expected_top
)
8774 int current_left
= 0, current_top
= 0;
8776 /* x_real_positions returns the left and top offsets of the outermost
8777 window manager window around the frame. */
8779 x_real_positions (f
, ¤t_left
, ¤t_top
);
8781 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8783 /* It's a "Type A" window manager. */
8788 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8789 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8790 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8792 /* Now fix the mispositioned frame's location. */
8794 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8795 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8797 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8798 adjusted_left
, adjusted_top
);
8800 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8803 /* It's a "Type B" window manager. We don't have to adjust the
8804 frame's position. */
8806 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8810 /* Wait for XGetGeometry to return up-to-date position information for a
8811 recently-moved frame. Call this immediately after calling XMoveWindow.
8812 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8813 frame has been moved to, so we use a fuzzy position comparison instead
8814 of an exact comparison. */
8817 x_sync_with_move (f
, left
, top
, fuzzy
)
8819 int left
, top
, fuzzy
;
8823 while (count
++ < 50)
8825 int current_left
= 0, current_top
= 0;
8827 /* In theory, this call to XSync only needs to happen once, but in
8828 practice, it doesn't seem to work, hence the need for the surrounding
8831 XSync (FRAME_X_DISPLAY (f
), False
);
8832 x_real_positions (f
, ¤t_left
, ¤t_top
);
8836 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8839 if (eabs (current_left
- left
) <= 10
8840 && eabs (current_top
- top
) <= 40)
8843 else if (current_left
== left
&& current_top
== top
)
8847 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8848 will then return up-to-date position info. */
8850 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8854 /* Change the size of frame F's X window to COLS/ROWS in the case F
8855 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8856 top-left-corner window gravity for this size change and subsequent
8857 size changes. Otherwise we leave the window gravity unchanged. */
8860 x_set_window_size_1 (f
, change_gravity
, cols
, rows
)
8865 int pixelwidth
, pixelheight
;
8867 check_frame_size (f
, &rows
, &cols
);
8868 f
->scroll_bar_actual_width
8869 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8871 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
8872 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
8873 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
8875 compute_fringe_widths (f
, 0);
8877 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
8878 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
);
8880 f
->win_gravity
= NorthWestGravity
;
8881 x_wm_set_size_hint (f
, (long) 0, 0);
8883 XSync (FRAME_X_DISPLAY (f
), False
);
8884 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8885 pixelwidth
, pixelheight
);
8887 /* Now, strictly speaking, we can't be sure that this is accurate,
8888 but the window manager will get around to dealing with the size
8889 change request eventually, and we'll hear how it went when the
8890 ConfigureNotify event gets here.
8892 We could just not bother storing any of this information here,
8893 and let the ConfigureNotify event set everything up, but that
8894 might be kind of confusing to the Lisp code, since size changes
8895 wouldn't be reported in the frame parameters until some random
8896 point in the future when the ConfigureNotify event arrives.
8898 We pass 1 for DELAY since we can't run Lisp code inside of
8900 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8901 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8902 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8904 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8905 receive in the ConfigureNotify event; if we get what we asked
8906 for, then the event won't cause the screen to become garbaged, so
8907 we have to make sure to do it here. */
8908 SET_FRAME_GARBAGED (f
);
8910 XFlush (FRAME_X_DISPLAY (f
));
8914 /* Call this to change the size of frame F's x-window.
8915 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8916 for this size change and subsequent size changes.
8917 Otherwise we leave the window gravity unchanged. */
8920 x_set_window_size (f
, change_gravity
, cols
, rows
)
8928 if (FRAME_GTK_WIDGET (f
))
8929 xg_frame_set_char_size (f
, cols
, rows
);
8931 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8934 if (f
->output_data
.x
->widget
!= NULL
)
8936 /* The x and y position of the widget is clobbered by the
8937 call to XtSetValues within EmacsFrameSetCharSize.
8938 This is a real kludge, but I don't understand Xt so I can't
8939 figure out a correct fix. Can anyone else tell me? -- rms. */
8940 int xpos
= f
->output_data
.x
->widget
->core
.x
;
8941 int ypos
= f
->output_data
.x
->widget
->core
.y
;
8942 EmacsFrameSetCharSize (f
->output_data
.x
->edit_widget
, cols
, rows
);
8943 f
->output_data
.x
->widget
->core
.x
= xpos
;
8944 f
->output_data
.x
->widget
->core
.y
= ypos
;
8947 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8949 #else /* not USE_X_TOOLKIT */
8951 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8953 #endif /* not USE_X_TOOLKIT */
8955 /* If cursor was outside the new size, mark it as off. */
8956 mark_window_cursors_off (XWINDOW (f
->root_window
));
8958 /* Clear out any recollection of where the mouse highlighting was,
8959 since it might be in a place that's outside the new frame size.
8960 Actually checking whether it is outside is a pain in the neck,
8961 so don't try--just let the highlighting be done afresh with new size. */
8962 cancel_mouse_face (f
);
8967 /* Mouse warping. */
8970 x_set_mouse_position (f
, x
, y
)
8976 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8977 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8979 if (pix_x
< 0) pix_x
= 0;
8980 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8982 if (pix_y
< 0) pix_y
= 0;
8983 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8987 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8988 0, 0, 0, 0, pix_x
, pix_y
);
8992 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8995 x_set_mouse_pixel_position (f
, pix_x
, pix_y
)
9001 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
9002 0, 0, 0, 0, pix_x
, pix_y
);
9006 /* focus shifting, raising and lowering. */
9009 x_focus_on_frame (f
)
9012 #if 0 /* This proves to be unpleasant. */
9016 /* I don't think that the ICCCM allows programs to do things like this
9017 without the interaction of the window manager. Whatever you end up
9018 doing with this code, do it to x_unfocus_frame too. */
9019 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
9020 RevertToPointerRoot
, CurrentTime
);
9029 /* Look at the remarks in x_focus_on_frame. */
9030 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
9031 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
9032 RevertToPointerRoot
, CurrentTime
);
9036 /* Raise frame F. */
9043 if (f
->async_visible
)
9044 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9046 XFlush (FRAME_X_DISPLAY (f
));
9050 /* Lower frame F. */
9056 if (f
->async_visible
)
9059 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
9060 XFlush (FRAME_X_DISPLAY (f
));
9065 /* Activate frame with Extended Window Manager Hints */
9068 x_ewmh_activate_frame (f
)
9071 /* See Window Manager Specification/Extended Window Manager Hints at
9072 http://freedesktop.org/wiki/Specifications/wm-spec */
9074 const char *atom
= "_NET_ACTIVE_WINDOW";
9075 if (f
->async_visible
&& wm_supports (f
, atom
))
9078 XSETFRAME (frame
, f
);
9079 Fx_send_client_event (frame
, make_number (0), frame
,
9080 make_unibyte_string (atom
, strlen (atom
)),
9082 Fcons (make_number (1),
9083 Fcons (make_number (last_user_time
),
9089 XTframe_raise_lower (f
, raise_flag
)
9099 /* XEmbed implementation. */
9102 xembed_set_info (f
, flags
)
9104 enum xembed_info flags
;
9107 unsigned long data
[2];
9109 atom
= XInternAtom (FRAME_X_DISPLAY (f
), "_XEMBED_INFO", False
);
9111 data
[0] = XEMBED_VERSION
;
9114 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), atom
, atom
,
9115 32, PropModeReplace
, (unsigned char *) data
, 2);
9119 xembed_send_message (f
, time
, message
, detail
, data1
, data2
)
9122 enum xembed_message message
;
9129 event
.xclient
.type
= ClientMessage
;
9130 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
9131 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
9132 event
.xclient
.format
= 32;
9133 event
.xclient
.data
.l
[0] = time
;
9134 event
.xclient
.data
.l
[1] = message
;
9135 event
.xclient
.data
.l
[2] = detail
;
9136 event
.xclient
.data
.l
[3] = data1
;
9137 event
.xclient
.data
.l
[4] = data2
;
9139 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
9140 False
, NoEventMask
, &event
);
9141 XSync (FRAME_X_DISPLAY (f
), False
);
9144 /* Change of visibility. */
9146 /* This tries to wait until the frame is really visible.
9147 However, if the window manager asks the user where to position
9148 the frame, this will return before the user finishes doing that.
9149 The frame will not actually be visible at that time,
9150 but it will become visible later when the window manager
9151 finishes with it. */
9154 x_make_frame_visible (f
)
9158 int original_top
, original_left
;
9159 int retry_count
= 2;
9165 type
= x_icon_type (f
);
9167 x_bitmap_icon (f
, type
);
9169 if (! FRAME_VISIBLE_P (f
))
9171 /* We test FRAME_GARBAGED_P here to make sure we don't
9172 call x_set_offset a second time
9173 if we get to x_make_frame_visible a second time
9174 before the window gets really visible. */
9175 if (! FRAME_ICONIFIED_P (f
)
9176 && ! FRAME_X_EMBEDDED_P (f
)
9177 && ! f
->output_data
.x
->asked_for_visible
)
9178 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9180 f
->output_data
.x
->asked_for_visible
= 1;
9182 if (! EQ (Vx_no_window_manager
, Qt
))
9183 x_wm_set_window_state (f
, NormalState
);
9184 #ifdef USE_X_TOOLKIT
9185 if (FRAME_X_EMBEDDED_P (f
))
9186 xembed_set_info (f
, XEMBED_MAPPED
);
9189 /* This was XtPopup, but that did nothing for an iconified frame. */
9190 XtMapWidget (f
->output_data
.x
->widget
);
9192 #else /* not USE_X_TOOLKIT */
9194 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9195 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9197 if (FRAME_X_EMBEDDED_P (f
))
9198 xembed_set_info (f
, XEMBED_MAPPED
);
9200 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9201 #endif /* not USE_GTK */
9202 #endif /* not USE_X_TOOLKIT */
9203 #if 0 /* This seems to bring back scroll bars in the wrong places
9204 if the window configuration has changed. They seem
9205 to come back ok without this. */
9206 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
9207 XMapSubwindows (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9211 XFlush (FRAME_X_DISPLAY (f
));
9213 /* Synchronize to ensure Emacs knows the frame is visible
9214 before we do anything else. We do this loop with input not blocked
9215 so that incoming events are handled. */
9219 /* This must be before UNBLOCK_INPUT
9220 since events that arrive in response to the actions above
9221 will set it when they are handled. */
9222 int previously_visible
= f
->output_data
.x
->has_been_visible
;
9224 original_left
= f
->left_pos
;
9225 original_top
= f
->top_pos
;
9227 /* This must come after we set COUNT. */
9230 /* We unblock here so that arriving X events are processed. */
9232 /* Now move the window back to where it was "supposed to be".
9233 But don't do it if the gravity is negative.
9234 When the gravity is negative, this uses a position
9235 that is 3 pixels too low. Perhaps that's really the border width.
9237 Don't do this if the window has never been visible before,
9238 because the window manager may choose the position
9239 and we don't want to override it. */
9241 if (! FRAME_VISIBLE_P (f
)
9242 && ! FRAME_ICONIFIED_P (f
)
9243 && ! FRAME_X_EMBEDDED_P (f
)
9244 && f
->win_gravity
== NorthWestGravity
9245 && previously_visible
)
9249 unsigned int width
, height
, border
, depth
;
9253 /* On some window managers (such as FVWM) moving an existing
9254 window, even to the same place, causes the window manager
9255 to introduce an offset. This can cause the window to move
9256 to an unexpected location. Check the geometry (a little
9257 slow here) and then verify that the window is in the right
9258 place. If the window is not in the right place, move it
9259 there, and take the potential window manager hit. */
9260 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9261 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9263 if (original_left
!= x
|| original_top
!= y
)
9264 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9265 original_left
, original_top
);
9270 XSETFRAME (frame
, f
);
9272 /* Wait until the frame is visible. Process X events until a
9273 MapNotify event has been seen, or until we think we won't get a
9274 MapNotify at all.. */
9275 for (count
= input_signal_count
+ 10;
9276 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9278 /* Force processing of queued events. */
9281 /* Machines that do polling rather than SIGIO have been
9282 observed to go into a busy-wait here. So we'll fake an
9283 alarm signal to let the handler know that there's something
9284 to be read. We used to raise a real alarm, but it seems
9285 that the handler isn't always enabled here. This is
9287 if (input_polling_used ())
9289 /* It could be confusing if a real alarm arrives while
9290 processing the fake one. Turn it off and let the
9291 handler reset it. */
9292 extern void poll_for_input_1
P_ ((void));
9293 int old_poll_suppress_count
= poll_suppress_count
;
9294 poll_suppress_count
= 1;
9295 poll_for_input_1 ();
9296 poll_suppress_count
= old_poll_suppress_count
;
9299 /* See if a MapNotify event has been processed. */
9300 FRAME_SAMPLE_VISIBILITY (f
);
9305 (let ((f (selected-frame)))
9309 the frame is not raised with various window managers on
9310 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9311 unknown reason, the call to XtMapWidget is completely ignored.
9312 Mapping the widget a second time works. */
9314 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9319 /* Change from mapped state to withdrawn state. */
9321 /* Make the frame visible (mapped and not iconified). */
9324 x_make_frame_invisible (f
)
9329 /* Use the frame's outermost window, not the one we normally draw on. */
9330 window
= FRAME_OUTER_WINDOW (f
);
9332 /* Don't keep the highlight on an invisible frame. */
9333 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9334 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9336 #if 0/* This might add unreliability; I don't trust it -- rms. */
9337 if (! f
->async_visible
&& ! f
->async_iconified
)
9343 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9344 that the current position of the window is user-specified, rather than
9345 program-specified, so that when the window is mapped again, it will be
9346 placed at the same location, without forcing the user to position it
9347 by hand again (they have already done that once for this window.) */
9348 x_wm_set_size_hint (f
, (long) 0, 1);
9351 if (FRAME_GTK_OUTER_WIDGET (f
))
9352 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9355 if (FRAME_X_EMBEDDED_P (f
))
9356 xembed_set_info (f
, 0);
9361 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9362 DefaultScreen (FRAME_X_DISPLAY (f
))))
9364 UNBLOCK_INPUT_RESIGNAL
;
9365 error ("Can't notify window manager of window withdrawal");
9369 /* We can't distinguish this from iconification
9370 just by the event that we get from the server.
9371 So we can't win using the usual strategy of letting
9372 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9373 and synchronize with the server to make sure we agree. */
9375 FRAME_ICONIFIED_P (f
) = 0;
9376 f
->async_visible
= 0;
9377 f
->async_iconified
= 0;
9384 /* Change window state from mapped to iconified. */
9393 /* Don't keep the highlight on an invisible frame. */
9394 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9395 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9397 if (f
->async_iconified
)
9402 FRAME_SAMPLE_VISIBILITY (f
);
9404 type
= x_icon_type (f
);
9406 x_bitmap_icon (f
, type
);
9409 if (FRAME_GTK_OUTER_WIDGET (f
))
9411 if (! FRAME_VISIBLE_P (f
))
9412 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9414 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9417 f
->async_iconified
= 1;
9418 f
->async_visible
= 0;
9424 #ifdef USE_X_TOOLKIT
9426 if (! FRAME_VISIBLE_P (f
))
9428 if (! EQ (Vx_no_window_manager
, Qt
))
9429 x_wm_set_window_state (f
, IconicState
);
9430 /* This was XtPopup, but that did nothing for an iconified frame. */
9431 XtMapWidget (f
->output_data
.x
->widget
);
9432 /* The server won't give us any event to indicate
9433 that an invisible frame was changed to an icon,
9434 so we have to record it here. */
9437 f
->async_iconified
= 1;
9438 f
->async_visible
= 0;
9443 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9444 XtWindow (f
->output_data
.x
->widget
),
9445 DefaultScreen (FRAME_X_DISPLAY (f
)));
9449 error ("Can't notify window manager of iconification");
9451 f
->async_iconified
= 1;
9452 f
->async_visible
= 0;
9456 XFlush (FRAME_X_DISPLAY (f
));
9458 #else /* not USE_X_TOOLKIT */
9460 /* Make sure the X server knows where the window should be positioned,
9461 in case the user deiconifies with the window manager. */
9462 if (! FRAME_VISIBLE_P (f
)
9463 && ! FRAME_ICONIFIED_P (f
)
9464 && ! FRAME_X_EMBEDDED_P (f
))
9465 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9467 /* Since we don't know which revision of X we're running, we'll use both
9468 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9470 /* X11R4: send a ClientMessage to the window manager using the
9471 WM_CHANGE_STATE type. */
9475 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9476 message
.xclient
.type
= ClientMessage
;
9477 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9478 message
.xclient
.format
= 32;
9479 message
.xclient
.data
.l
[0] = IconicState
;
9481 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9482 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9484 SubstructureRedirectMask
| SubstructureNotifyMask
,
9487 UNBLOCK_INPUT_RESIGNAL
;
9488 error ("Can't notify window manager of iconification");
9492 /* X11R3: set the initial_state field of the window manager hints to
9494 x_wm_set_window_state (f
, IconicState
);
9496 if (!FRAME_VISIBLE_P (f
))
9498 /* If the frame was withdrawn, before, we must map it. */
9499 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9502 f
->async_iconified
= 1;
9503 f
->async_visible
= 0;
9505 XFlush (FRAME_X_DISPLAY (f
));
9507 #endif /* not USE_X_TOOLKIT */
9511 /* Free X resources of frame F. */
9514 x_free_frame_resources (f
)
9517 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9519 struct scroll_bar
*b
;
9523 /* If a display connection is dead, don't try sending more
9524 commands to the X server. */
9525 if (dpyinfo
->display
)
9527 /* We must free faces before destroying windows because some
9528 font-driver (e.g. xft) access a window while finishing a
9530 if (FRAME_FACE_CACHE (f
))
9531 free_frame_faces (f
);
9533 if (f
->output_data
.x
->icon_desc
)
9534 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9536 #ifdef USE_X_TOOLKIT
9537 /* Explicitly destroy the scroll bars of the frame. Without
9538 this, we get "BadDrawable" errors from the toolkit later on,
9539 presumably from expose events generated for the disappearing
9540 toolkit scroll bars. */
9541 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9543 b
= XSCROLL_BAR (bar
);
9544 x_scroll_bar_remove (b
);
9553 #ifdef USE_X_TOOLKIT
9554 if (f
->output_data
.x
->widget
)
9556 XtDestroyWidget (f
->output_data
.x
->widget
);
9557 f
->output_data
.x
->widget
= NULL
;
9559 /* Tooltips don't have widgets, only a simple X window, even if
9560 we are using a toolkit. */
9561 else if (FRAME_X_WINDOW (f
))
9562 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9564 free_frame_menubar (f
);
9565 #else /* !USE_X_TOOLKIT */
9568 /* In the GTK version, tooltips are normal X
9569 frames. We must check and free both types. */
9570 if (FRAME_GTK_OUTER_WIDGET (f
))
9572 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9573 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9574 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9576 #endif /* USE_GTK */
9578 if (FRAME_X_WINDOW (f
))
9579 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9580 #endif /* !USE_X_TOOLKIT */
9582 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9583 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9584 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9585 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9586 unload_color (f
, f
->output_data
.x
->border_pixel
);
9587 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9589 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9590 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9591 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9592 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9593 #ifdef USE_TOOLKIT_SCROLL_BARS
9594 /* Scrollbar shadow colors. */
9595 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9596 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9597 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9598 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9599 #endif /* USE_TOOLKIT_SCROLL_BARS */
9600 if (f
->output_data
.x
->white_relief
.allocated_p
)
9601 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9602 if (f
->output_data
.x
->black_relief
.allocated_p
)
9603 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9606 XFlush (FRAME_X_DISPLAY (f
));
9609 xfree (f
->output_data
.x
->saved_menu_event
);
9610 xfree (f
->output_data
.x
);
9611 f
->output_data
.x
= NULL
;
9613 if (f
== dpyinfo
->x_focus_frame
)
9614 dpyinfo
->x_focus_frame
= 0;
9615 if (f
== dpyinfo
->x_focus_event_frame
)
9616 dpyinfo
->x_focus_event_frame
= 0;
9617 if (f
== dpyinfo
->x_highlight_frame
)
9618 dpyinfo
->x_highlight_frame
= 0;
9620 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9622 dpyinfo
->mouse_face_beg_row
9623 = dpyinfo
->mouse_face_beg_col
= -1;
9624 dpyinfo
->mouse_face_end_row
9625 = dpyinfo
->mouse_face_end_col
= -1;
9626 dpyinfo
->mouse_face_window
= Qnil
;
9627 dpyinfo
->mouse_face_deferred_gc
= 0;
9628 dpyinfo
->mouse_face_mouse_frame
= 0;
9635 /* Destroy the X window of frame F. */
9638 x_destroy_window (f
)
9641 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9643 /* If a display connection is dead, don't try sending more
9644 commands to the X server. */
9645 if (dpyinfo
->display
!= 0)
9646 x_free_frame_resources (f
);
9648 dpyinfo
->reference_count
--;
9652 /* Setting window manager hints. */
9654 /* Set the normal size hints for the window manager, for frame F.
9655 FLAGS is the flags word to use--or 0 meaning preserve the flags
9656 that the window now has.
9657 If USER_POSITION is nonzero, we set the USPosition
9658 flag (this is useful when FLAGS is 0).
9659 The GTK version is in gtkutils.c */
9663 x_wm_set_size_hint (f
, flags
, user_position
)
9668 XSizeHints size_hints
;
9670 #ifdef USE_X_TOOLKIT
9673 Dimension widget_width
, widget_height
;
9676 Window window
= FRAME_OUTER_WINDOW (f
);
9678 /* Setting PMaxSize caused various problems. */
9679 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9681 size_hints
.x
= f
->left_pos
;
9682 size_hints
.y
= f
->top_pos
;
9684 #ifdef USE_X_TOOLKIT
9685 XtSetArg (al
[ac
], XtNwidth
, &widget_width
); ac
++;
9686 XtSetArg (al
[ac
], XtNheight
, &widget_height
); ac
++;
9687 XtGetValues (f
->output_data
.x
->widget
, al
, ac
);
9688 size_hints
.height
= widget_height
;
9689 size_hints
.width
= widget_width
;
9690 #else /* not USE_X_TOOLKIT */
9691 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9692 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9693 #endif /* not USE_X_TOOLKIT */
9695 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9696 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9697 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9698 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9699 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9700 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9702 /* Calculate the base and minimum sizes.
9704 (When we use the X toolkit, we don't do it here.
9705 Instead we copy the values that the widgets are using, below.) */
9706 #ifndef USE_X_TOOLKIT
9708 int base_width
, base_height
;
9709 int min_rows
= 0, min_cols
= 0;
9711 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9712 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9714 check_frame_size (f
, &min_rows
, &min_cols
);
9716 /* The window manager uses the base width hints to calculate the
9717 current number of rows and columns in the frame while
9718 resizing; min_width and min_height aren't useful for this
9719 purpose, since they might not give the dimensions for a
9720 zero-row, zero-column frame.
9722 We use the base_width and base_height members if we have
9723 them; otherwise, we set the min_width and min_height members
9724 to the size for a zero x zero frame. */
9726 size_hints
.flags
|= PBaseSize
;
9727 size_hints
.base_width
= base_width
;
9728 size_hints
.base_height
= base_height
;
9729 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9730 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9733 /* If we don't need the old flags, we don't need the old hint at all. */
9736 size_hints
.flags
|= flags
;
9739 #endif /* not USE_X_TOOLKIT */
9742 XSizeHints hints
; /* Sometimes I hate X Windows... */
9743 long supplied_return
;
9746 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9749 #ifdef USE_X_TOOLKIT
9750 size_hints
.base_height
= hints
.base_height
;
9751 size_hints
.base_width
= hints
.base_width
;
9752 size_hints
.min_height
= hints
.min_height
;
9753 size_hints
.min_width
= hints
.min_width
;
9757 size_hints
.flags
|= flags
;
9762 if (hints
.flags
& PSize
)
9763 size_hints
.flags
|= PSize
;
9764 if (hints
.flags
& PPosition
)
9765 size_hints
.flags
|= PPosition
;
9766 if (hints
.flags
& USPosition
)
9767 size_hints
.flags
|= USPosition
;
9768 if (hints
.flags
& USSize
)
9769 size_hints
.flags
|= USSize
;
9773 #ifndef USE_X_TOOLKIT
9778 size_hints
.win_gravity
= f
->win_gravity
;
9779 size_hints
.flags
|= PWinGravity
;
9783 size_hints
.flags
&= ~ PPosition
;
9784 size_hints
.flags
|= USPosition
;
9786 #endif /* PWinGravity */
9788 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9790 #endif /* not USE_GTK */
9792 /* Used for IconicState or NormalState */
9795 x_wm_set_window_state (f
, state
)
9799 #ifdef USE_X_TOOLKIT
9802 XtSetArg (al
[0], XtNinitialState
, state
);
9803 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9804 #else /* not USE_X_TOOLKIT */
9805 Window window
= FRAME_X_WINDOW (f
);
9807 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9808 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9810 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9811 #endif /* not USE_X_TOOLKIT */
9815 x_wm_set_icon_pixmap (f
, pixmap_id
)
9819 Pixmap icon_pixmap
, icon_mask
;
9821 #ifndef USE_X_TOOLKIT
9822 Window window
= FRAME_OUTER_WINDOW (f
);
9827 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9828 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9829 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9830 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9834 /* It seems there is no way to turn off use of an icon pixmap.
9835 The following line does it, only if no icon has yet been created,
9836 for some window managers. But with mwm it crashes.
9837 Some people say it should clear the IconPixmapHint bit in this case,
9838 but that doesn't work, and the X consortium said it isn't the
9839 right thing at all. Since there is no way to win,
9840 best to explicitly give up. */
9842 f
->output_data
.x
->wm_hints
.icon_pixmap
= None
;
9843 f
->output_data
.x
->wm_hints
.icon_mask
= None
;
9852 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9856 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9860 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9861 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9862 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9863 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9866 #else /* not USE_X_TOOLKIT && not USE_GTK */
9868 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9869 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9871 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9875 x_wm_set_icon_position (f
, icon_x
, icon_y
)
9879 Window window
= FRAME_OUTER_WINDOW (f
);
9881 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9882 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9883 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9885 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9889 /***********************************************************************
9891 ***********************************************************************/
9895 /* Check that FONT is valid on frame F. It is if it can be found in F's
9899 x_check_font (f
, font
)
9905 xassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9906 if (font
->driver
->check
)
9907 xassert (font
->driver
->check (f
, font
) == 0);
9910 #endif /* GLYPH_DEBUG != 0 */
9913 /***********************************************************************
9915 ***********************************************************************/
9917 #ifdef USE_X_TOOLKIT
9918 static XrmOptionDescRec emacs_options
[] = {
9919 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9920 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9922 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9923 XrmoptionSepArg
, NULL
},
9924 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9926 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9927 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9928 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9929 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9930 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9931 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9932 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9935 /* Whether atimer for Xt timeouts is activated or not. */
9937 static int x_timeout_atimer_activated_flag
;
9939 #endif /* USE_X_TOOLKIT */
9941 static int x_initialized
;
9944 static int x_session_initialized
;
9947 /* Test whether two display-name strings agree up to the dot that separates
9948 the screen number from the server number. */
9950 same_x_server (name1
, name2
)
9951 const char *name1
, *name2
;
9954 const unsigned char *system_name
= SDATA (Vsystem_name
);
9955 int system_name_length
= strlen (system_name
);
9956 int length_until_period
= 0;
9958 while (system_name
[length_until_period
] != 0
9959 && system_name
[length_until_period
] != '.')
9960 length_until_period
++;
9962 /* Treat `unix' like an empty host name. */
9963 if (! strncmp (name1
, "unix:", 5))
9965 if (! strncmp (name2
, "unix:", 5))
9967 /* Treat this host's name like an empty host name. */
9968 if (! strncmp (name1
, system_name
, system_name_length
)
9969 && name1
[system_name_length
] == ':')
9970 name1
+= system_name_length
;
9971 if (! strncmp (name2
, system_name
, system_name_length
)
9972 && name2
[system_name_length
] == ':')
9973 name2
+= system_name_length
;
9974 /* Treat this host's domainless name like an empty host name. */
9975 if (! strncmp (name1
, system_name
, length_until_period
)
9976 && name1
[length_until_period
] == ':')
9977 name1
+= length_until_period
;
9978 if (! strncmp (name2
, system_name
, length_until_period
)
9979 && name2
[length_until_period
] == ':')
9980 name2
+= length_until_period
;
9982 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9986 if (seen_colon
&& *name1
== '.')
9990 && (*name1
== '.' || *name1
== '\0')
9991 && (*name2
== '.' || *name2
== '\0'));
9994 /* Count number of set bits in mask and number of bits to shift to
9995 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9998 get_bits_and_offset (mask
, bits
, offset
)
10006 while (!(mask
& 1))
10022 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
10023 But don't permanently open it, just test its availability. */
10026 x_display_ok (display
)
10027 const char *display
;
10032 dpy
= XOpenDisplay (display
);
10034 XCloseDisplay (dpy
);
10040 /* Open a connection to X display DISPLAY_NAME, and return
10041 the structure that describes the open display.
10042 If we cannot contact the display, return null. */
10044 struct x_display_info
*
10045 x_term_init (display_name
, xrm_option
, resource_name
)
10046 Lisp_Object display_name
;
10048 char *resource_name
;
10052 struct terminal
*terminal
;
10053 struct x_display_info
*dpyinfo
;
10058 if (!x_initialized
)
10064 if (! x_display_ok (SDATA (display_name
)))
10065 error ("Display %s can't be opened", SDATA (display_name
));
10069 #define NUM_ARGV 10
10071 char *argv
[NUM_ARGV
];
10072 char **argv2
= argv
;
10075 #ifndef HAVE_GTK_MULTIDISPLAY
10076 if (!EQ (Vinitial_window_system
, intern ("x")))
10077 error ("Sorry, you cannot connect to X servers with the GTK toolkit");
10080 if (x_initialized
++ > 1)
10082 #ifdef HAVE_GTK_MULTIDISPLAY
10083 /* Opening another display. If xg_display_open returns less
10084 than zero, we are probably on GTK 2.0, which can only handle
10085 one display. GTK 2.2 or later can handle more than one. */
10086 if (xg_display_open (SDATA (display_name
), &dpy
) < 0)
10088 error ("Sorry, this version of GTK can only handle one display");
10092 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
10096 argv
[argc
++] = initial_argv
[0];
10098 if (! NILP (display_name
))
10100 argv
[argc
++] = "--display";
10101 argv
[argc
++] = SDATA (display_name
);
10104 argv
[argc
++] = "--name";
10105 argv
[argc
++] = resource_name
;
10107 XSetLocaleModifiers ("");
10109 gtk_init (&argc
, &argv2
);
10111 /* gtk_init does set_locale. We must fix locale after calling it. */
10115 dpy
= GDK_DISPLAY ();
10117 /* NULL window -> events for all windows go to our function */
10118 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
10120 /* Load our own gtkrc if it exists. */
10122 char *file
= "~/.emacs.d/gtkrc";
10123 Lisp_Object s
, abs_file
;
10125 s
= make_string (file
, strlen (file
));
10126 abs_file
= Fexpand_file_name (s
, Qnil
);
10128 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
10129 gtk_rc_parse (SDATA (abs_file
));
10132 XSetErrorHandler (x_error_handler
);
10133 XSetIOErrorHandler (x_io_error_quitter
);
10136 #else /* not USE_GTK */
10137 #ifdef USE_X_TOOLKIT
10138 /* weiner@footloose.sps.mot.com reports that this causes
10140 X protocol error: BadAtom (invalid Atom parameter)
10141 on protocol request 18skiloaf.
10142 So let's not use it until R6. */
10143 #ifdef HAVE_X11XTR6
10144 XtSetLanguageProc (NULL
, NULL
, NULL
);
10155 argv
[argc
++] = "-xrm";
10156 argv
[argc
++] = xrm_option
;
10158 turn_on_atimers (0);
10159 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
10160 resource_name
, EMACS_CLASS
,
10161 emacs_options
, XtNumber (emacs_options
),
10163 turn_on_atimers (1);
10165 #ifdef HAVE_X11XTR6
10166 /* I think this is to compensate for XtSetLanguageProc. */
10171 #else /* not USE_X_TOOLKIT */
10172 XSetLocaleModifiers ("");
10173 dpy
= XOpenDisplay (SDATA (display_name
));
10174 #endif /* not USE_X_TOOLKIT */
10175 #endif /* not USE_GTK*/
10177 /* Detect failure. */
10184 /* We have definitely succeeded. Record the new connection. */
10186 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
10187 bzero (dpyinfo
, sizeof *dpyinfo
);
10189 terminal
= x_create_terminal (dpyinfo
);
10192 struct x_display_info
*share
;
10195 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
10196 share
= share
->next
, tail
= XCDR (tail
))
10197 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
10198 SDATA (display_name
)))
10201 terminal
->kboard
= share
->terminal
->kboard
;
10204 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
10205 init_kboard (terminal
->kboard
);
10206 terminal
->kboard
->Vwindow_system
= intern ("x");
10207 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
10209 char *vendor
= ServerVendor (dpy
);
10210 /* Temporarily hide the partially initialized terminal */
10211 terminal_list
= terminal
->next_terminal
;
10213 terminal
->kboard
->Vsystem_key_alist
10214 = call1 (Qvendor_specific_keysyms
,
10215 vendor
? build_string (vendor
) : empty_unibyte_string
);
10217 terminal
->next_terminal
= terminal_list
;
10218 terminal_list
= terminal
;
10221 terminal
->kboard
->next_kboard
= all_kboards
;
10222 all_kboards
= terminal
->kboard
;
10223 /* Don't let the initial kboard remain current longer than necessary.
10224 That would cause problems if a file loaded on startup tries to
10225 prompt in the mini-buffer. */
10226 if (current_kboard
== initial_kboard
)
10227 current_kboard
= terminal
->kboard
;
10229 terminal
->kboard
->reference_count
++;
10232 /* Put this display on the chain. */
10233 dpyinfo
->next
= x_display_list
;
10234 x_display_list
= dpyinfo
;
10236 /* Put it on x_display_name_list as well, to keep them parallel. */
10237 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
10238 x_display_name_list
);
10239 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
10241 dpyinfo
->display
= dpy
;
10243 /* Set the name of the terminal. */
10244 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
10245 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
10246 terminal
->name
[SBYTES (display_name
)] = 0;
10249 XSetAfterFunction (x_current_display
, x_trace_wire
);
10253 = (char *) xmalloc (SBYTES (Vinvocation_name
)
10254 + SBYTES (Vsystem_name
)
10256 sprintf (dpyinfo
->x_id_name
, "%s@%s",
10257 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
10259 /* Figure out which modifier bits mean what. */
10260 x_find_modifier_meanings (dpyinfo
);
10262 /* Get the scroll bar cursor. */
10264 /* We must create a GTK cursor, it is required for GTK widgets. */
10265 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
10266 #endif /* USE_GTK */
10268 dpyinfo
->vertical_scroll_bar_cursor
10269 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
10271 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
10272 resource_name
, EMACS_CLASS
);
10273 #ifdef HAVE_XRMSETDATABASE
10274 XrmSetDatabase (dpyinfo
->display
, xrdb
);
10276 dpyinfo
->display
->db
= xrdb
;
10278 /* Put the rdb where we can find it in a way that works on
10280 dpyinfo
->xrdb
= xrdb
;
10282 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
10283 DefaultScreen (dpyinfo
->display
));
10284 select_visual (dpyinfo
);
10285 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
10286 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
10287 dpyinfo
->client_leader_window
= 0;
10288 dpyinfo
->grabbed
= 0;
10289 dpyinfo
->reference_count
= 0;
10290 dpyinfo
->icon_bitmap_id
= -1;
10291 dpyinfo
->n_fonts
= 0;
10292 dpyinfo
->bitmaps
= 0;
10293 dpyinfo
->bitmaps_size
= 0;
10294 dpyinfo
->bitmaps_last
= 0;
10295 dpyinfo
->scratch_cursor_gc
= 0;
10296 dpyinfo
->mouse_face_mouse_frame
= 0;
10297 dpyinfo
->mouse_face_deferred_gc
= 0;
10298 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
10299 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10300 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10301 dpyinfo
->mouse_face_window
= Qnil
;
10302 dpyinfo
->mouse_face_overlay
= Qnil
;
10303 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10304 dpyinfo
->mouse_face_defer
= 0;
10305 dpyinfo
->mouse_face_hidden
= 0;
10306 dpyinfo
->x_focus_frame
= 0;
10307 dpyinfo
->x_focus_event_frame
= 0;
10308 dpyinfo
->x_highlight_frame
= 0;
10309 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10311 /* See if we can construct pixel values from RGB values. */
10312 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10313 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10315 if (dpyinfo
->visual
->class == TrueColor
)
10317 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10318 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10319 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10320 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10321 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10322 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10325 /* See if a private colormap is requested. */
10326 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10328 if (dpyinfo
->visual
->class == PseudoColor
)
10331 value
= display_x_get_resource (dpyinfo
,
10332 build_string ("privateColormap"),
10333 build_string ("PrivateColormap"),
10335 if (STRINGP (value
)
10336 && (!strcmp (SDATA (value
), "true")
10337 || !strcmp (SDATA (value
), "on")))
10338 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10342 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10343 dpyinfo
->visual
, AllocNone
);
10346 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10347 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10348 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10349 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10350 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10351 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10352 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10353 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10354 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10357 dpyinfo
->Xatom_wm_protocols
10358 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10359 dpyinfo
->Xatom_wm_take_focus
10360 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10361 dpyinfo
->Xatom_wm_save_yourself
10362 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10363 dpyinfo
->Xatom_wm_delete_window
10364 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10365 dpyinfo
->Xatom_wm_change_state
10366 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10367 dpyinfo
->Xatom_wm_configure_denied
10368 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10369 dpyinfo
->Xatom_wm_window_moved
10370 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10371 dpyinfo
->Xatom_wm_client_leader
10372 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10373 dpyinfo
->Xatom_editres
10374 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10375 dpyinfo
->Xatom_CLIPBOARD
10376 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10377 dpyinfo
->Xatom_TIMESTAMP
10378 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10379 dpyinfo
->Xatom_TEXT
10380 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10381 dpyinfo
->Xatom_COMPOUND_TEXT
10382 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10383 dpyinfo
->Xatom_UTF8_STRING
10384 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10385 dpyinfo
->Xatom_DELETE
10386 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10387 dpyinfo
->Xatom_MULTIPLE
10388 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10389 dpyinfo
->Xatom_INCR
10390 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10391 dpyinfo
->Xatom_EMACS_TMP
10392 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10393 dpyinfo
->Xatom_TARGETS
10394 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10395 dpyinfo
->Xatom_NULL
10396 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10397 dpyinfo
->Xatom_ATOM_PAIR
10398 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10399 /* For properties of font. */
10400 dpyinfo
->Xatom_PIXEL_SIZE
10401 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10402 dpyinfo
->Xatom_AVERAGE_WIDTH
10403 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10404 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10405 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10406 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10407 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10408 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10409 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10411 /* Ghostscript support. */
10412 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10413 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10415 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10418 dpyinfo
->Xatom_XEMBED
= XInternAtom (dpyinfo
->display
, "_XEMBED",
10421 dpyinfo
->Xatom_net_wm_state
10422 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE", False
);
10423 dpyinfo
->Xatom_net_wm_state_fullscreen_atom
10424 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_FULLSCREEN", False
);
10425 dpyinfo
->Xatom_net_wm_state_maximized_horz
10426 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_HORZ", False
);
10427 dpyinfo
->Xatom_net_wm_state_maximized_vert
10428 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_VERT", False
);
10430 dpyinfo
->cut_buffers_initialized
= 0;
10432 dpyinfo
->x_dnd_atoms_size
= 8;
10433 dpyinfo
->x_dnd_atoms_length
= 0;
10434 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
10435 * dpyinfo
->x_dnd_atoms_size
);
10437 dpyinfo
->net_supported_atoms
= NULL
;
10438 dpyinfo
->nr_net_supported_atoms
= 0;
10439 dpyinfo
->net_supported_window
= 0;
10441 connection
= ConnectionNumber (dpyinfo
->display
);
10442 dpyinfo
->connection
= connection
;
10445 extern int gray_bitmap_width
, gray_bitmap_height
;
10446 extern char *gray_bitmap_bits
;
10448 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10450 gray_bitmap_width
, gray_bitmap_height
,
10451 (unsigned long) 1, (unsigned long) 0, 1);
10455 xim_initialize (dpyinfo
, resource_name
);
10458 #ifdef subprocesses
10459 /* This is only needed for distinguishing keyboard and process input. */
10460 if (connection
!= 0)
10461 add_keyboard_wait_descriptor (connection
);
10465 fcntl (connection
, F_SETOWN
, getpid ());
10466 #endif /* ! defined (F_SETOWN) */
10469 if (interrupt_input
)
10470 init_sigio (connection
);
10471 #endif /* ! defined (SIGIO) */
10475 Display
*dpy
= dpyinfo
->display
;
10476 XrmValue d
, fr
, to
;
10479 d
.addr
= (XPointer
)&dpy
;
10480 d
.size
= sizeof (Display
*);
10481 fr
.addr
= XtDefaultFont
;
10482 fr
.size
= sizeof (XtDefaultFont
);
10483 to
.size
= sizeof (Font
*);
10484 to
.addr
= (XPointer
)&font
;
10485 x_catch_errors (dpy
);
10486 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10488 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10489 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10490 x_uncatch_errors ();
10494 /* See if we should run in synchronous mode. This is useful
10495 for debugging X code. */
10498 value
= display_x_get_resource (dpyinfo
,
10499 build_string ("synchronous"),
10500 build_string ("Synchronous"),
10502 if (STRINGP (value
)
10503 && (!strcmp (SDATA (value
), "true")
10504 || !strcmp (SDATA (value
), "on")))
10505 XSynchronize (dpyinfo
->display
, True
);
10510 value
= display_x_get_resource (dpyinfo
,
10511 build_string ("useXIM"),
10512 build_string ("UseXIM"),
10515 if (STRINGP (value
)
10516 && (!strcmp (SDATA (value
), "false")
10517 || !strcmp (SDATA (value
), "off")))
10520 if (STRINGP (value
)
10521 && (!strcmp (SDATA (value
), "true")
10522 || !strcmp (SDATA (value
), "on")))
10528 /* Only do this for the very first display in the Emacs session.
10529 Ignore X session management when Emacs was first started on a
10531 if (terminal
->id
== 1)
10532 x_session_initialize (dpyinfo
);
10540 /* Get rid of display DPYINFO, deleting all frames on it,
10541 and without sending any more commands to the X server. */
10544 x_delete_display (dpyinfo
)
10545 struct x_display_info
*dpyinfo
;
10548 struct terminal
*t
;
10550 /* Close all frames and delete the generic struct terminal for this
10552 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10553 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10556 /* Close X session management when we close its display. */
10557 if (t
->id
== 1 && x_session_have_connection ())
10560 delete_terminal (t
);
10564 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10566 /* Discard this display from x_display_name_list and x_display_list.
10567 We can't use Fdelq because that can quit. */
10568 if (! NILP (x_display_name_list
)
10569 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10570 x_display_name_list
= XCDR (x_display_name_list
);
10575 tail
= x_display_name_list
;
10576 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10578 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10580 XSETCDR (tail
, XCDR (XCDR (tail
)));
10583 tail
= XCDR (tail
);
10587 if (next_noop_dpyinfo
== dpyinfo
)
10588 next_noop_dpyinfo
= dpyinfo
->next
;
10590 if (x_display_list
== dpyinfo
)
10591 x_display_list
= dpyinfo
->next
;
10594 struct x_display_info
*tail
;
10596 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10597 if (tail
->next
== dpyinfo
)
10598 tail
->next
= tail
->next
->next
;
10601 /* Xt and GTK do this themselves. */
10602 #if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
10603 #ifndef AIX /* On AIX, XCloseDisplay calls this. */
10604 XrmDestroyDatabase (dpyinfo
->xrdb
);
10608 xfree (dpyinfo
->x_id_name
);
10609 xfree (dpyinfo
->x_dnd_atoms
);
10610 xfree (dpyinfo
->color_cells
);
10614 #ifdef USE_X_TOOLKIT
10616 /* Atimer callback function for TIMER. Called every 0.1s to process
10617 Xt timeouts, if needed. We must avoid calling XtAppPending as
10618 much as possible because that function does an implicit XFlush
10619 that slows us down. */
10622 x_process_timeouts (timer
)
10623 struct atimer
*timer
;
10626 x_timeout_atimer_activated_flag
= 0;
10627 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10629 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10630 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10631 /* Reactivate the atimer for next time. */
10632 x_activate_timeout_atimer ();
10637 /* Install an asynchronous timer that processes Xt timeout events
10638 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10639 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10640 function whenever these variables are set. This is necessary
10641 because some widget sets use timeouts internally, for example the
10642 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10643 processed, these widgets don't behave normally. */
10646 x_activate_timeout_atimer ()
10649 if (!x_timeout_atimer_activated_flag
)
10651 EMACS_TIME interval
;
10653 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10654 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10655 x_timeout_atimer_activated_flag
= 1;
10660 #endif /* USE_X_TOOLKIT */
10663 /* Set up use of X before we make the first connection. */
10665 extern frame_parm_handler x_frame_parm_handlers
[];
10667 static struct redisplay_interface x_redisplay_interface
=
10669 x_frame_parm_handlers
,
10673 x_clear_end_of_line
,
10675 x_after_update_window_line
,
10676 x_update_window_begin
,
10677 x_update_window_end
,
10683 0, /* flush_display_optional */
10685 x_clear_window_mouse_face
,
10686 x_get_glyph_overhangs
,
10687 x_fix_overlapping_area
,
10688 x_draw_fringe_bitmap
,
10689 0, /* define_fringe_bitmap */
10690 0, /* destroy_fringe_bitmap */
10691 x_compute_glyph_string_overhangs
,
10692 x_draw_glyph_string
,
10693 x_define_frame_cursor
,
10694 x_clear_frame_area
,
10695 x_draw_window_cursor
,
10696 x_draw_vertical_window_border
,
10697 x_shift_glyphs_for_insert
10701 /* This function is called when the last frame on a display is deleted. */
10703 x_delete_terminal (struct terminal
*terminal
)
10705 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10708 /* Protect against recursive calls. delete_frame in
10709 delete_terminal calls us back when it deletes our last frame. */
10710 if (!terminal
->name
)
10715 /* We must close our connection to the XIM server before closing the
10718 xim_close_dpy (dpyinfo
);
10721 /* If called from x_connection_closed, the display may already be closed
10722 and dpyinfo->display was set to 0 to indicate that. */
10723 if (dpyinfo
->display
)
10725 x_destroy_all_bitmaps (dpyinfo
);
10726 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10729 xg_display_close (dpyinfo
->display
);
10731 #ifdef USE_X_TOOLKIT
10732 XtCloseDisplay (dpyinfo
->display
);
10734 XCloseDisplay (dpyinfo
->display
);
10736 #endif /* ! USE_GTK */
10739 x_delete_display (dpyinfo
);
10743 /* Create a struct terminal, initialize it with the X11 specific
10744 functions and make DISPLAY->TERMINAL point to it. */
10746 static struct terminal
*
10747 x_create_terminal (struct x_display_info
*dpyinfo
)
10749 struct terminal
*terminal
;
10751 terminal
= create_terminal ();
10753 terminal
->type
= output_x_window
;
10754 terminal
->display_info
.x
= dpyinfo
;
10755 dpyinfo
->terminal
= terminal
;
10757 /* kboard is initialized in x_term_init. */
10759 terminal
->clear_frame_hook
= x_clear_frame
;
10760 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10761 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10762 terminal
->ring_bell_hook
= XTring_bell
;
10763 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10764 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
10765 terminal
->update_begin_hook
= x_update_begin
;
10766 terminal
->update_end_hook
= x_update_end
;
10767 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
10768 terminal
->read_socket_hook
= XTread_socket
;
10769 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10770 terminal
->mouse_position_hook
= XTmouse_position
;
10771 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10772 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10773 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10774 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10775 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10776 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10777 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10779 terminal
->delete_frame_hook
= x_destroy_window
;
10780 terminal
->delete_terminal_hook
= x_delete_terminal
;
10782 terminal
->rif
= &x_redisplay_interface
;
10783 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10784 terminal
->char_ins_del_ok
= 1;
10785 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10786 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10787 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10799 last_tool_bar_item
= -1;
10800 any_help_event_p
= 0;
10801 ignore_next_mouse_click_timeout
= 0;
10803 x_session_initialized
= 0;
10807 current_count
= -1;
10810 /* Try to use interrupt input; if we can't, then start polling. */
10811 Fset_input_interrupt_mode (Qt
);
10813 #ifdef USE_X_TOOLKIT
10814 XtToolkitInitialize ();
10816 Xt_app_con
= XtCreateApplicationContext ();
10818 /* Register a converter from strings to pixels, which uses
10819 Emacs' color allocation infrastructure. */
10820 XtAppSetTypeConverter (Xt_app_con
,
10821 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10822 cvt_string_to_pixel_args
,
10823 XtNumber (cvt_string_to_pixel_args
),
10824 XtCacheByDisplay
, cvt_pixel_dtor
);
10826 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10829 #ifdef USE_TOOLKIT_SCROLL_BARS
10831 xaw3d_arrow_scroll
= False
;
10832 xaw3d_pick_top
= True
;
10836 /* Note that there is no real way portable across R3/R4 to get the
10837 original error handler. */
10838 XSetErrorHandler (x_error_handler
);
10839 XSetIOErrorHandler (x_io_error_quitter
);
10841 /* Disable Window Change signals; they are handled by X events. */
10842 #if 0 /* Don't. We may want to open tty frames later. */
10844 signal (SIGWINCH
, SIG_DFL
);
10845 #endif /* SIGWINCH */
10848 signal (SIGPIPE
, x_connection_signal
);
10855 x_error_message
= NULL
;
10857 staticpro (&x_display_name_list
);
10858 x_display_name_list
= Qnil
;
10860 staticpro (&last_mouse_scroll_bar
);
10861 last_mouse_scroll_bar
= Qnil
;
10863 staticpro (&Qvendor_specific_keysyms
);
10864 Qvendor_specific_keysyms
= intern ("vendor-specific-keysyms");
10866 staticpro (&Qlatin_1
);
10867 Qlatin_1
= intern ("latin-1");
10869 staticpro (&last_mouse_press_frame
);
10870 last_mouse_press_frame
= Qnil
;
10872 DEFVAR_BOOL ("x-use-underline-position-properties",
10873 &x_use_underline_position_properties
,
10874 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10875 A value of nil means ignore them. If you encounter fonts with bogus
10876 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10877 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10878 to override the font's UNDERLINE_POSITION for small font display
10880 x_use_underline_position_properties
= 1;
10882 DEFVAR_BOOL ("x-underline-at-descent-line",
10883 &x_underline_at_descent_line
,
10884 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
10885 A value of nil means to draw the underline according to the value of the
10886 variable `x-use-underline-position-properties', which is usually at the
10887 baseline level. The default value is nil. */);
10888 x_underline_at_descent_line
= 0;
10890 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10891 &x_mouse_click_focus_ignore_position
,
10892 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10893 This variable is only used when the window manager requires that you
10894 click on a frame to select it (give it focus). In that case, a value
10895 of nil, means that the selected window and cursor position changes to
10896 reflect the mouse click position, while a non-nil value means that the
10897 selected window or cursor position is preserved. */);
10898 x_mouse_click_focus_ignore_position
= 0;
10900 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10901 doc
: /* What X toolkit scroll bars Emacs uses.
10902 A value of nil means Emacs doesn't use X toolkit scroll bars.
10903 Otherwise, value is a symbol describing the X toolkit. */);
10904 #ifdef USE_TOOLKIT_SCROLL_BARS
10906 Vx_toolkit_scroll_bars
= intern ("motif");
10907 #elif defined HAVE_XAW3D
10908 Vx_toolkit_scroll_bars
= intern ("xaw3d");
10910 Vx_toolkit_scroll_bars
= intern ("gtk");
10912 Vx_toolkit_scroll_bars
= intern ("xaw");
10915 Vx_toolkit_scroll_bars
= Qnil
;
10918 staticpro (&last_mouse_motion_frame
);
10919 last_mouse_motion_frame
= Qnil
;
10921 Qmodifier_value
= intern ("modifier-value");
10922 Qalt
= intern ("alt");
10923 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10924 Qhyper
= intern ("hyper");
10925 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10926 Qmeta
= intern ("meta");
10927 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10928 Qsuper
= intern ("super");
10929 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10931 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10932 doc
: /* Which keys Emacs uses for the alt modifier.
10933 This should be one of the symbols `alt', `hyper', `meta', `super'.
10934 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10935 is nil, which is the same as `alt'. */);
10936 Vx_alt_keysym
= Qnil
;
10938 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10939 doc
: /* Which keys Emacs uses for the hyper modifier.
10940 This should be one of the symbols `alt', `hyper', `meta', `super'.
10941 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10942 default is nil, which is the same as `hyper'. */);
10943 Vx_hyper_keysym
= Qnil
;
10945 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10946 doc
: /* Which keys Emacs uses for the meta modifier.
10947 This should be one of the symbols `alt', `hyper', `meta', `super'.
10948 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10949 default is nil, which is the same as `meta'. */);
10950 Vx_meta_keysym
= Qnil
;
10952 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10953 doc
: /* Which keys Emacs uses for the super modifier.
10954 This should be one of the symbols `alt', `hyper', `meta', `super'.
10955 For example, `super' means use the Super_L and Super_R keysyms. The
10956 default is nil, which is the same as `super'. */);
10957 Vx_super_keysym
= Qnil
;
10959 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10960 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10961 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10962 make_float (DEFAULT_REHASH_SIZE
),
10963 make_float (DEFAULT_REHASH_THRESHOLD
),
10967 #endif /* HAVE_X_WINDOWS */
10969 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
10970 (do not change this comment) */