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, 2010
4 Free Software Foundation, Inc.
6 This file is part of GNU Emacs.
8 GNU Emacs is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
13 GNU Emacs is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
21 /* New display code by Gerd Moellmann <gerd@gnu.org>. */
22 /* Xt features made by Fred Pierresteguy. */
26 /* On 4.3 these lose if they come after xterm.h. */
27 /* Putting these at the beginning seems to be standard for other .c files. */
36 #include "blockinput.h"
38 /* Need syssignal.h for various externs and definitions that may be required
39 by some configurations for calls to signal later in this source file. */
40 #include "syssignal.h"
42 /* This may include sys/types.h, and that somehow loses
43 if this is not done before the other system files. */
45 #include <X11/cursorfont.h>
47 /* Load sys/types.h if not already loaded.
48 In some systems loading it twice is suicidal. */
50 #include <sys/types.h>
53 #ifdef HAVE_SYS_IOCTL_H
54 #include <sys/ioctl.h>
55 #endif /* ! defined (HAVE_SYS_IOCTL_H) */
64 /* Caused redefinition of DBL_DIG on Netbsd; seems not to be needed. */
65 /* #include <sys/param.h> */
68 #include "character.h"
71 #include "dispextern.h"
73 #include "termhooks.h"
76 #include "emacs-icon.h"
81 #include "intervals.h"
87 #include "xsettings.h"
89 #include "sysselect.h"
92 #include <X11/Shell.h>
95 #ifdef HAVE_SYS_TIME_H
107 #include "../lwlib/xlwmenu.h"
110 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
112 extern void free_frame_menubar (struct frame
*);
116 #if !defined(NO_EDITRES)
118 extern void _XEditResCheckMessages ();
119 #endif /* not NO_EDITRES */
121 /* Include toolkit specific headers for the scroll bar widget. */
123 #ifdef USE_TOOLKIT_SCROLL_BARS
124 #if defined USE_MOTIF
125 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
126 #include <Xm/ScrollBar.h>
127 #else /* !USE_MOTIF i.e. use Xaw */
130 #include <X11/Xaw3d/Simple.h>
131 #include <X11/Xaw3d/Scrollbar.h>
132 #include <X11/Xaw3d/ThreeD.h>
133 #else /* !HAVE_XAW3D */
134 #include <X11/Xaw/Simple.h>
135 #include <X11/Xaw/Scrollbar.h>
136 #endif /* !HAVE_XAW3D */
138 #define XtNpickTop "pickTop"
139 #endif /* !XtNpickTop */
140 #endif /* !USE_MOTIF */
141 #endif /* USE_TOOLKIT_SCROLL_BARS */
143 #endif /* USE_X_TOOLKIT */
147 #ifndef XtNinitialState
148 #define XtNinitialState "initialState"
152 /* Default to using XIM if available. */
156 int use_xim
= 0; /* configure --without-xim */
161 /* Non-nil means Emacs uses toolkit scroll bars. */
163 Lisp_Object Vx_toolkit_scroll_bars
;
165 /* Non-zero means that a HELP_EVENT has been generated since Emacs
168 static int any_help_event_p
;
170 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
171 static Lisp_Object last_window
;
173 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
175 int x_use_underline_position_properties
;
177 /* Non-zero means to draw the underline at the same place as the descent line. */
179 int x_underline_at_descent_line
;
181 /* This is a chain of structures for all the X displays currently in
184 struct x_display_info
*x_display_list
;
186 /* This is a list of cons cells, each of the form (NAME
187 . FONT-LIST-CACHE), one for each element of x_display_list and in
188 the same order. NAME is the name of the frame. FONT-LIST-CACHE
189 records previous values returned by x-list-fonts. */
191 Lisp_Object x_display_name_list
;
193 /* Frame being updated by update_frame. This is declared in term.c.
194 This is set by update_begin and looked at by all the XT functions.
195 It is zero while not inside an update. In that case, the XT
196 functions assume that `selected_frame' is the frame to apply to. */
198 extern struct frame
*updating_frame
;
200 /* This is a frame waiting to be auto-raised, within XTread_socket. */
202 static struct frame
*pending_autoraise_frame
;
204 /* This is a frame waiting for an event matching mask, within XTread_socket. */
209 } pending_event_wait
;
212 /* The application context for Xt use. */
213 XtAppContext Xt_app_con
;
214 static String Xt_default_resources
[] = {0};
215 #endif /* USE_X_TOOLKIT */
217 /* Non-zero means user is interacting with a toolkit scroll bar. */
219 static int toolkit_scroll_bar_interaction
;
221 /* Non-zero means to not move point as a result of clicking on a
222 frame to focus it (when focus-follows-mouse is nil). */
224 int x_mouse_click_focus_ignore_position
;
226 /* Non-zero timeout value means ignore next mouse click if it arrives
227 before that timeout elapses (i.e. as part of the same sequence of
228 events resulting from clicking on a frame to select it). */
230 static unsigned long ignore_next_mouse_click_timeout
;
234 Formerly, we used PointerMotionHintMask (in standard_event_mask)
235 so that we would have to call XQueryPointer after each MotionNotify
236 event to ask for another such event. However, this made mouse tracking
237 slow, and there was a bug that made it eventually stop.
239 Simply asking for MotionNotify all the time seems to work better.
241 In order to avoid asking for motion events and then throwing most
242 of them away or busy-polling the server for mouse positions, we ask
243 the server for pointer motion hints. This means that we get only
244 one event per group of mouse movements. "Groups" are delimited by
245 other kinds of events (focus changes and button clicks, for
246 example), or by XQueryPointer calls; when one of these happens, we
247 get another MotionNotify event the next time the mouse moves. This
248 is at least as efficient as getting motion events when mouse
249 tracking is on, and I suspect only negligibly worse when tracking
252 /* Where the mouse was last time we reported a mouse event. */
254 static XRectangle last_mouse_glyph
;
255 static FRAME_PTR last_mouse_glyph_frame
;
256 static Lisp_Object last_mouse_press_frame
;
258 /* The scroll bar in which the last X motion event occurred.
260 If the last X motion event occurred in a scroll bar, we set this so
261 XTmouse_position can know whether to report a scroll bar motion or
264 If the last X motion event didn't occur in a scroll bar, we set
265 this to Qnil, to tell XTmouse_position to return an ordinary motion
268 static Lisp_Object last_mouse_scroll_bar
;
270 /* This is a hack. We would really prefer that XTmouse_position would
271 return the time associated with the position it returns, but there
272 doesn't seem to be any way to wrest the time-stamp from the server
273 along with the position query. So, we just keep track of the time
274 of the last movement we received, and return that in hopes that
275 it's somewhat accurate. */
277 static Time last_mouse_movement_time
;
279 /* Time for last user interaction as returned in X events. */
281 static Time last_user_time
;
283 /* Incremented by XTread_socket whenever it really tries to read
287 static int volatile input_signal_count
;
289 static int input_signal_count
;
292 /* Used locally within XTread_socket. */
294 static int x_noop_count
;
296 /* The keysyms to use for the various modifiers. */
298 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
299 Lisp_Object Vx_keysym_table
;
300 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
302 static Lisp_Object Qvendor_specific_keysyms
;
303 static Lisp_Object Qlatin_1
;
306 /* The name of the Emacs icon file. */
307 static Lisp_Object xg_default_icon_file
;
309 /* Used in gtkutil.c. */
310 Lisp_Object Qx_gtk_map_stock
;
313 /* Used in x_flush. */
315 extern XrmDatabase
x_load_resources (Display
*, const char *, const char *,
317 extern int x_bitmap_mask (FRAME_PTR
, int);
319 static int x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
320 static void x_set_window_size_1 (struct frame
*, int, int, int);
321 static const XColor
*x_color_cells (Display
*, int *);
322 static void x_update_window_end (struct window
*, int, int);
324 static int x_io_error_quitter (Display
*);
325 static struct terminal
*x_create_terminal (struct x_display_info
*);
326 void x_delete_terminal (struct terminal
*);
327 static void x_update_end (struct frame
*);
328 static void XTframe_up_to_date (struct frame
*);
329 static void XTset_terminal_modes (struct terminal
*);
330 static void XTreset_terminal_modes (struct terminal
*);
331 static void x_clear_frame (struct frame
*);
332 static void frame_highlight (struct frame
*);
333 static void frame_unhighlight (struct frame
*);
334 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
335 static void x_focus_changed (int, int, struct x_display_info
*,
336 struct frame
*, struct input_event
*);
337 static void x_detect_focus_change (struct x_display_info
*,
338 XEvent
*, struct input_event
*);
339 static void XTframe_rehighlight (struct frame
*);
340 static void x_frame_rehighlight (struct x_display_info
*);
341 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
342 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
343 enum text_cursor_kinds
);
345 static void x_clip_to_row (struct window
*, struct glyph_row
*, int, GC
);
346 static void x_flush (struct frame
*f
);
347 static void x_update_begin (struct frame
*);
348 static void x_update_window_begin (struct window
*);
349 static void x_after_update_window_line (struct glyph_row
*);
350 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
351 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
352 enum scroll_bar_part
*,
353 Lisp_Object
*, Lisp_Object
*,
355 static void x_handle_net_wm_state (struct frame
*, XPropertyEvent
*);
356 static void x_check_fullscreen (struct frame
*);
357 static void x_check_expected_move (struct frame
*, int, int);
358 static void x_sync_with_move (struct frame
*, int, int, int);
359 static int handle_one_xevent (struct x_display_info
*, XEvent
*,
360 int *, struct input_event
*);
361 /* Don't declare this NO_RETURN because we want no
362 interference with debugging failing X calls. */
363 static SIGTYPE
x_connection_closed (Display
*, const char *);
366 /* Flush display of frame F, or of all frames if F is null. */
369 x_flush (struct frame
*f
)
371 /* Don't call XFlush when it is not safe to redisplay; the X
372 connection may be broken. */
373 if (!NILP (Vinhibit_redisplay
))
379 Lisp_Object rest
, frame
;
380 FOR_EACH_FRAME (rest
, frame
)
381 if (FRAME_X_P (XFRAME (frame
)))
382 x_flush (XFRAME (frame
));
384 else if (FRAME_X_P (f
))
385 XFlush (FRAME_X_DISPLAY (f
));
390 /* Remove calls to XFlush by defining XFlush to an empty replacement.
391 Calls to XFlush should be unnecessary because the X output buffer
392 is flushed automatically as needed by calls to XPending,
393 XNextEvent, or XWindowEvent according to the XFlush man page.
394 XTread_socket calls XPending. Removing XFlush improves
397 #define XFlush(DISPLAY) (void) 0
400 /***********************************************************************
402 ***********************************************************************/
406 /* This is a function useful for recording debugging information about
407 the sequence of occurrences in this file. */
415 struct record event_record
[100];
417 int event_record_index
;
419 record_event (locus
, type
)
423 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
424 event_record_index
= 0;
426 event_record
[event_record_index
].locus
= locus
;
427 event_record
[event_record_index
].type
= type
;
428 event_record_index
++;
435 /* Return the struct x_display_info corresponding to DPY. */
437 struct x_display_info
*
438 x_display_info_for_display (Display
*dpy
)
440 struct x_display_info
*dpyinfo
;
442 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
443 if (dpyinfo
->display
== dpy
)
449 #define OPAQUE 0xffffffff
450 #define OPACITY "_NET_WM_WINDOW_OPACITY"
453 x_set_frame_alpha (struct frame
*f
)
455 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
456 Display
*dpy
= FRAME_X_DISPLAY (f
);
457 Window win
= FRAME_OUTER_WINDOW (f
);
459 double alpha_min
= 1.0;
462 if (FRAME_X_DISPLAY_INFO (f
)->root_window
!= FRAME_X_OUTPUT (f
)->parent_desc
)
463 /* Since the WM decoration lies under the FRAME_OUTER_WINDOW,
464 we must treat the former instead of the latter. */
465 win
= FRAME_X_OUTPUT (f
)->parent_desc
;
467 if (dpyinfo
->x_highlight_frame
== f
)
472 if (FLOATP (Vframe_alpha_lower_limit
))
473 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
474 else if (INTEGERP (Vframe_alpha_lower_limit
))
475 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
479 else if (alpha
> 1.0)
481 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
484 opac
= alpha
* OPAQUE
;
486 /* return unless necessary */
491 unsigned long n
, left
;
493 x_catch_errors (dpy
);
494 rc
= XGetWindowProperty (dpy
, win
, XInternAtom(dpy
, OPACITY
, False
),
495 0L, 1L, False
, XA_CARDINAL
,
496 &actual
, &format
, &n
, &left
,
499 if (rc
== Success
&& actual
!= None
)
500 if (*(unsigned long *)data
== opac
)
502 XFree ((void *) data
);
507 XFree ((void *) data
);
511 x_catch_errors (dpy
);
512 XChangeProperty (dpy
, win
, XInternAtom (dpy
, OPACITY
, False
),
513 XA_CARDINAL
, 32, PropModeReplace
,
514 (unsigned char *) &opac
, 1L);
519 x_display_pixel_height (struct x_display_info
*dpyinfo
)
521 return HeightOfScreen (dpyinfo
->screen
);
525 x_display_pixel_width (struct x_display_info
*dpyinfo
)
527 return WidthOfScreen (dpyinfo
->screen
);
531 /***********************************************************************
532 Starting and ending an update
533 ***********************************************************************/
535 /* Start an update of frame F. This function is installed as a hook
536 for update_begin, i.e. it is called when update_begin is called.
537 This function is called prior to calls to x_update_window_begin for
538 each window being updated. Currently, there is nothing to do here
539 because all interesting stuff is done on a window basis. */
542 x_update_begin (struct frame
*f
)
548 /* Start update of window W. Set the global variable updated_window
549 to the window being updated and set output_cursor to the cursor
553 x_update_window_begin (struct window
*w
)
555 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
556 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
559 set_output_cursor (&w
->cursor
);
563 if (f
== display_info
->mouse_face_mouse_frame
)
565 /* Don't do highlighting for mouse motion during the update. */
566 display_info
->mouse_face_defer
= 1;
568 /* If F needs to be redrawn, simply forget about any prior mouse
570 if (FRAME_GARBAGED_P (f
))
571 display_info
->mouse_face_window
= Qnil
;
578 /* Draw a vertical window border from (x,y0) to (x,y1) */
581 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
583 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
586 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
588 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
591 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
592 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
595 /* End update of window W (which is equal to updated_window).
597 Draw vertical borders between horizontally adjacent windows, and
598 display W's cursor if CURSOR_ON_P is non-zero.
600 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
601 glyphs in mouse-face were overwritten. In that case we have to
602 make sure that the mouse-highlight is properly redrawn.
604 W may be a menu bar pseudo-window in case we don't have X toolkit
605 support. Such windows don't have a cursor, so don't display it
609 x_update_window_end (struct window
*w
, int cursor_on_p
, int mouse_face_overwritten_p
)
611 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
613 if (!w
->pseudo_window_p
)
618 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
620 output_cursor
.x
, output_cursor
.y
);
622 if (draw_window_fringes (w
, 1))
623 x_draw_vertical_border (w
);
628 /* If a row with mouse-face was overwritten, arrange for
629 XTframe_up_to_date to redisplay the mouse highlight. */
630 if (mouse_face_overwritten_p
)
632 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
633 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
634 dpyinfo
->mouse_face_window
= Qnil
;
637 updated_window
= NULL
;
641 /* End update of frame F. This function is installed as a hook in
645 x_update_end (struct frame
*f
)
647 /* Mouse highlight may be displayed again. */
648 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
652 XFlush (FRAME_X_DISPLAY (f
));
658 /* This function is called from various places in xdisp.c whenever a
659 complete update has been performed. The global variable
660 updated_window is not available here. */
663 XTframe_up_to_date (struct frame
*f
)
667 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
669 if (dpyinfo
->mouse_face_deferred_gc
670 || f
== dpyinfo
->mouse_face_mouse_frame
)
673 if (dpyinfo
->mouse_face_mouse_frame
)
674 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
675 dpyinfo
->mouse_face_mouse_x
,
676 dpyinfo
->mouse_face_mouse_y
);
677 dpyinfo
->mouse_face_deferred_gc
= 0;
684 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
685 arrow bitmaps, or clear the fringes if no bitmaps are required
686 before DESIRED_ROW is made current. The window being updated is
687 found in updated_window. This function It is called from
688 update_window_line only if it is known that there are differences
689 between bitmaps to be drawn between current row and DESIRED_ROW. */
692 x_after_update_window_line (struct glyph_row
*desired_row
)
694 struct window
*w
= updated_window
;
700 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
701 desired_row
->redraw_fringe_bitmaps_p
= 1;
703 /* When a window has disappeared, make sure that no rest of
704 full-width rows stays visible in the internal border. Could
705 check here if updated_window is the leftmost/rightmost window,
706 but I guess it's not worth doing since vertically split windows
707 are almost never used, internal border is rarely set, and the
708 overhead is very small. */
709 if (windows_or_buffers_changed
710 && desired_row
->full_width_p
711 && (f
= XFRAME (w
->frame
),
712 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
714 && (height
= desired_row
->visible_height
,
717 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
720 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
721 0, y
, width
, height
, False
);
722 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
723 FRAME_PIXEL_WIDTH (f
) - width
,
724 y
, width
, height
, False
);
730 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
732 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
733 Display
*display
= FRAME_X_DISPLAY (f
);
734 Window window
= FRAME_X_WINDOW (f
);
735 GC gc
= f
->output_data
.x
->normal_gc
;
736 struct face
*face
= p
->face
;
738 /* Must clip because of partially visible lines. */
739 x_clip_to_row (w
, row
, -1, gc
);
743 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
745 /* In case the same realized face is used for fringes and
746 for something displayed in the text (e.g. face `region' on
747 mono-displays, the fill style may have been changed to
748 FillSolid in x_draw_glyph_string_background. */
750 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
752 XSetForeground (display
, face
->gc
, face
->background
);
754 #ifdef USE_TOOLKIT_SCROLL_BARS
755 /* If the fringe is adjacent to the left (right) scroll bar of a
756 leftmost (rightmost, respectively) window, then extend its
757 background to the gap between the fringe and the bar. */
758 if ((WINDOW_LEFTMOST_P (w
)
759 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
760 || (WINDOW_RIGHTMOST_P (w
)
761 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
763 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
767 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
768 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
769 * FRAME_COLUMN_WIDTH (f
));
773 /* Bitmap fills the fringe. */
774 if (left
+ width
== p
->x
)
775 bx
= left
+ sb_width
;
776 else if (p
->x
+ p
->wd
== left
)
780 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
782 nx
= width
- sb_width
;
783 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
785 ny
= row
->visible_height
;
790 if (left
+ width
== bx
)
792 bx
= left
+ sb_width
;
793 nx
+= width
- sb_width
;
795 else if (bx
+ nx
== left
)
796 nx
+= width
- sb_width
;
801 if (bx
>= 0 && nx
> 0)
802 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
805 XSetForeground (display
, face
->gc
, face
->foreground
);
811 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
812 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
816 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
818 bits
= (unsigned char *)p
->bits
+ p
->dh
;
820 /* Draw the bitmap. I believe these small pixmaps can be cached
822 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
824 ? (p
->overlay_p
? face
->background
825 : f
->output_data
.x
->cursor_pixel
)
827 face
->background
, depth
);
831 clipmask
= XCreatePixmapFromBitmapData (display
,
832 FRAME_X_DISPLAY_INFO (f
)->root_window
,
835 gcv
.clip_mask
= clipmask
;
836 gcv
.clip_x_origin
= p
->x
;
837 gcv
.clip_y_origin
= p
->y
;
838 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
841 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
842 p
->wd
, p
->h
, p
->x
, p
->y
);
843 XFreePixmap (display
, pixmap
);
847 gcv
.clip_mask
= (Pixmap
) 0;
848 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
849 XFreePixmap (display
, clipmask
);
853 XSetClipMask (display
, gc
, None
);
858 /* This is called when starting Emacs and when restarting after
859 suspend. When starting Emacs, no X window is mapped. And nothing
860 must be done to Emacs's own window if it is suspended (though that
864 XTset_terminal_modes (struct terminal
*terminal
)
868 /* This is called when exiting or suspending Emacs. Exiting will make
869 the X-windows go away, and suspending requires no action. */
872 XTreset_terminal_modes (struct terminal
*terminal
)
877 /***********************************************************************
879 ***********************************************************************/
883 static void x_set_glyph_string_clipping (struct glyph_string
*);
884 static void x_set_glyph_string_gc (struct glyph_string
*);
885 static void x_draw_glyph_string_background (struct glyph_string
*,
887 static void x_draw_glyph_string_foreground (struct glyph_string
*);
888 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
889 static void x_draw_glyph_string_box (struct glyph_string
*);
890 static void x_draw_glyph_string (struct glyph_string
*);
891 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
892 static void x_set_cursor_gc (struct glyph_string
*);
893 static void x_set_mode_line_face_gc (struct glyph_string
*);
894 static void x_set_mouse_face_gc (struct glyph_string
*);
895 static int x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
896 unsigned long *, double, int);
897 static void x_setup_relief_color (struct frame
*, struct relief
*,
898 double, int, unsigned long);
899 static void x_setup_relief_colors (struct glyph_string
*);
900 static void x_draw_image_glyph_string (struct glyph_string
*);
901 static void x_draw_image_relief (struct glyph_string
*);
902 static void x_draw_image_foreground (struct glyph_string
*);
903 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
904 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
906 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
907 int, int, int, int, int, int,
909 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
910 int, int, int, XRectangle
*);
913 static void x_check_font (struct frame
*, struct font
*);
917 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
921 x_set_cursor_gc (struct glyph_string
*s
)
923 if (s
->font
== FRAME_FONT (s
->f
)
924 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
925 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
927 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
930 /* Cursor on non-default face: must merge. */
934 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
935 xgcv
.foreground
= s
->face
->background
;
937 /* If the glyph would be invisible, try a different foreground. */
938 if (xgcv
.foreground
== xgcv
.background
)
939 xgcv
.foreground
= s
->face
->foreground
;
940 if (xgcv
.foreground
== xgcv
.background
)
941 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
942 if (xgcv
.foreground
== xgcv
.background
)
943 xgcv
.foreground
= s
->face
->foreground
;
945 /* Make sure the cursor is distinct from text in this face. */
946 if (xgcv
.background
== s
->face
->background
947 && xgcv
.foreground
== s
->face
->foreground
)
949 xgcv
.background
= s
->face
->foreground
;
950 xgcv
.foreground
= s
->face
->background
;
953 IF_DEBUG (x_check_font (s
->f
, s
->font
));
954 xgcv
.graphics_exposures
= False
;
955 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
957 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
958 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
961 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
962 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
964 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
969 /* Set up S->gc of glyph string S for drawing text in mouse face. */
972 x_set_mouse_face_gc (struct glyph_string
*s
)
977 /* What face has to be used last for the mouse face? */
978 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
979 face
= FACE_FROM_ID (s
->f
, face_id
);
981 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
983 if (s
->first_glyph
->type
== CHAR_GLYPH
)
984 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
986 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
987 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
988 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
990 if (s
->font
== s
->face
->font
)
994 /* Otherwise construct scratch_cursor_gc with values from FACE
999 xgcv
.background
= s
->face
->background
;
1000 xgcv
.foreground
= s
->face
->foreground
;
1001 xgcv
.graphics_exposures
= False
;
1002 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1004 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1005 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1008 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1009 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1011 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1014 xassert (s
->gc
!= 0);
1018 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1019 Faces to use in the mode line have already been computed when the
1020 matrix was built, so there isn't much to do, here. */
1023 x_set_mode_line_face_gc (struct glyph_string
*s
)
1025 s
->gc
= s
->face
->gc
;
1029 /* Set S->gc of glyph string S for drawing that glyph string. Set
1030 S->stippled_p to a non-zero value if the face of S has a stipple
1034 x_set_glyph_string_gc (struct glyph_string
*s
)
1036 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1038 if (s
->hl
== DRAW_NORMAL_TEXT
)
1040 s
->gc
= s
->face
->gc
;
1041 s
->stippled_p
= s
->face
->stipple
!= 0;
1043 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1045 x_set_mode_line_face_gc (s
);
1046 s
->stippled_p
= s
->face
->stipple
!= 0;
1048 else if (s
->hl
== DRAW_CURSOR
)
1050 x_set_cursor_gc (s
);
1053 else if (s
->hl
== DRAW_MOUSE_FACE
)
1055 x_set_mouse_face_gc (s
);
1056 s
->stippled_p
= s
->face
->stipple
!= 0;
1058 else if (s
->hl
== DRAW_IMAGE_RAISED
1059 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1061 s
->gc
= s
->face
->gc
;
1062 s
->stippled_p
= s
->face
->stipple
!= 0;
1066 s
->gc
= s
->face
->gc
;
1067 s
->stippled_p
= s
->face
->stipple
!= 0;
1070 /* GC must have been set. */
1071 xassert (s
->gc
!= 0);
1075 /* Set clipping for output of glyph string S. S may be part of a mode
1076 line or menu if we don't have X toolkit support. */
1079 x_set_glyph_string_clipping (struct glyph_string
*s
)
1081 XRectangle
*r
= s
->clip
;
1082 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1085 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1090 /* Set SRC's clipping for output of glyph string DST. This is called
1091 when we are drawing DST's left_overhang or right_overhang only in
1095 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1100 r
.width
= src
->width
;
1102 r
.height
= src
->height
;
1105 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1110 Compute left and right overhang of glyph string S. */
1113 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1116 && (s
->first_glyph
->type
== CHAR_GLYPH
1117 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1119 struct font_metrics metrics
;
1121 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1123 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1124 struct font
*font
= s
->font
;
1127 for (i
= 0; i
< s
->nchars
; i
++)
1128 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1129 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1133 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1135 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1137 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1138 ? metrics
.rbearing
- metrics
.width
: 0);
1139 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1143 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1144 s
->left_overhang
= - s
->cmp
->lbearing
;
1149 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1152 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1155 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1156 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1157 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1158 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1162 /* Draw the background of glyph_string S. If S->background_filled_p
1163 is non-zero don't draw it. FORCE_P non-zero means draw the
1164 background even if it wouldn't be drawn normally. This is used
1165 when a string preceding S draws into the background of S, or S
1166 contains the first component of a composition. */
1169 x_draw_glyph_string_background (struct glyph_string
*s
, int force_p
)
1171 /* Nothing to do if background has already been drawn or if it
1172 shouldn't be drawn in the first place. */
1173 if (!s
->background_filled_p
)
1175 int box_line_width
= max (s
->face
->box_line_width
, 0);
1179 /* Fill background with a stipple pattern. */
1180 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1181 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1182 s
->y
+ box_line_width
,
1183 s
->background_width
,
1184 s
->height
- 2 * box_line_width
);
1185 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1186 s
->background_filled_p
= 1;
1188 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1189 || s
->font_not_found_p
1190 || s
->extends_to_end_of_line_p
1193 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1194 s
->background_width
,
1195 s
->height
- 2 * box_line_width
);
1196 s
->background_filled_p
= 1;
1202 /* Draw the foreground of glyph string S. */
1205 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1209 /* If first glyph of S has a left box line, start drawing the text
1210 of S to the right of that box line. */
1211 if (s
->face
->box
!= FACE_NO_BOX
1212 && s
->first_glyph
->left_box_line_p
)
1213 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1217 /* Draw characters of S as rectangles if S's font could not be
1219 if (s
->font_not_found_p
)
1221 for (i
= 0; i
< s
->nchars
; ++i
)
1223 struct glyph
*g
= s
->first_glyph
+ i
;
1224 XDrawRectangle (s
->display
, s
->window
,
1225 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1227 x
+= g
->pixel_width
;
1232 struct font
*font
= s
->font
;
1233 int boff
= font
->baseline_offset
;
1236 if (font
->vertical_centering
)
1237 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1239 y
= s
->ybase
- boff
;
1241 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1242 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1244 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1245 if (s
->face
->overstrike
)
1246 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1250 /* Draw the foreground of composite glyph string S. */
1253 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1256 struct font
*font
= s
->font
;
1258 /* If first glyph of S has a left box line, start drawing the text
1259 of S to the right of that box line. */
1260 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1261 && s
->first_glyph
->left_box_line_p
)
1262 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1266 /* S is a glyph string for a composition. S->cmp_from is the index
1267 of the first character drawn for glyphs of this composition.
1268 S->cmp_from == 0 means we are drawing the very first character of
1269 this composition. */
1271 /* Draw a rectangle for the composition if the font for the very
1272 first character of the composition could not be loaded. */
1273 if (s
->font_not_found_p
)
1275 if (s
->cmp_from
== 0)
1276 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1277 s
->width
- 1, s
->height
- 1);
1279 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1283 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1284 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1286 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1287 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1289 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1290 if (s
->face
->overstrike
)
1291 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1296 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1301 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1303 glyph
= LGSTRING_GLYPH (gstring
, i
);
1304 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1305 width
+= LGLYPH_WIDTH (glyph
);
1308 int xoff
, yoff
, wadjust
;
1312 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1313 if (s
->face
->overstrike
)
1314 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1317 xoff
= LGLYPH_XOFF (glyph
);
1318 yoff
= LGLYPH_YOFF (glyph
);
1319 wadjust
= LGLYPH_WADJUST (glyph
);
1320 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1321 if (s
->face
->overstrike
)
1322 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1330 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1331 if (s
->face
->overstrike
)
1332 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1338 #ifdef USE_X_TOOLKIT
1340 static struct frame
*x_frame_of_widget (Widget
);
1341 static Boolean
cvt_string_to_pixel (Display
*, XrmValue
*, Cardinal
*,
1342 XrmValue
*, XrmValue
*, XtPointer
*);
1343 static void cvt_pixel_dtor (XtAppContext
, XrmValue
*, XtPointer
,
1344 XrmValue
*, Cardinal
*);
1347 /* Return the frame on which widget WIDGET is used.. Abort if frame
1348 cannot be determined. */
1350 static struct frame
*
1351 x_frame_of_widget (Widget widget
)
1353 struct x_display_info
*dpyinfo
;
1357 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1359 /* Find the top-level shell of the widget. Note that this function
1360 can be called when the widget is not yet realized, so XtWindow
1361 (widget) == 0. That's the reason we can't simply use
1362 x_any_window_to_frame. */
1363 while (!XtIsTopLevelShell (widget
))
1364 widget
= XtParent (widget
);
1366 /* Look for a frame with that top-level widget. Allocate the color
1367 on that frame to get the right gamma correction value. */
1368 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1369 if (FRAMEP (XCAR (tail
))
1370 && (f
= XFRAME (XCAR (tail
)),
1372 && f
->output_data
.nothing
!= 1
1373 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1374 && f
->output_data
.x
->widget
== widget
)
1381 /* Allocate the color COLOR->pixel on the screen and display of
1382 widget WIDGET in colormap CMAP. If an exact match cannot be
1383 allocated, try the nearest color available. Value is non-zero
1384 if successful. This is called from lwlib. */
1387 x_alloc_nearest_color_for_widget (Widget widget
, Colormap cmap
, XColor
*color
)
1389 struct frame
*f
= x_frame_of_widget (widget
);
1390 return x_alloc_nearest_color (f
, cmap
, color
);
1394 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1395 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1396 If this produces the same color as PIXEL, try a color where all RGB
1397 values have DELTA added. Return the allocated color in *PIXEL.
1398 DISPLAY is the X display, CMAP is the colormap to operate on.
1399 Value is non-zero if successful. */
1402 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1403 unsigned long *pixel
, double factor
, int delta
)
1405 struct frame
*f
= x_frame_of_widget (widget
);
1406 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1410 /* Structure specifying which arguments should be passed by Xt to
1411 cvt_string_to_pixel. We want the widget's screen and colormap. */
1413 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1415 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1417 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1422 /* The address of this variable is returned by
1423 cvt_string_to_pixel. */
1425 static Pixel cvt_string_to_pixel_value
;
1428 /* Convert a color name to a pixel color.
1430 DPY is the display we are working on.
1432 ARGS is an array of *NARGS XrmValue structures holding additional
1433 information about the widget for which the conversion takes place.
1434 The contents of this array are determined by the specification
1435 in cvt_string_to_pixel_args.
1437 FROM is a pointer to an XrmValue which points to the color name to
1438 convert. TO is an XrmValue in which to return the pixel color.
1440 CLOSURE_RET is a pointer to user-data, in which we record if
1441 we allocated the color or not.
1443 Value is True if successful, False otherwise. */
1446 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1447 XrmValue
*from
, XrmValue
*to
,
1448 XtPointer
*closure_ret
)
1458 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1459 "wrongParameters", "cvt_string_to_pixel",
1461 "Screen and colormap args required", NULL
, NULL
);
1465 screen
= *(Screen
**) args
[0].addr
;
1466 cmap
= *(Colormap
*) args
[1].addr
;
1467 color_name
= (String
) from
->addr
;
1469 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1471 *closure_ret
= (XtPointer
) False
;
1472 pixel
= WhitePixelOfScreen (screen
);
1474 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1476 *closure_ret
= (XtPointer
) False
;
1477 pixel
= BlackPixelOfScreen (screen
);
1479 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1480 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1482 pixel
= color
.pixel
;
1483 *closure_ret
= (XtPointer
) True
;
1488 Cardinal nparams
= 1;
1490 params
[0] = color_name
;
1491 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1492 "badValue", "cvt_string_to_pixel",
1493 "XtToolkitError", "Invalid color `%s'",
1498 if (to
->addr
!= NULL
)
1500 if (to
->size
< sizeof (Pixel
))
1502 to
->size
= sizeof (Pixel
);
1506 *(Pixel
*) to
->addr
= pixel
;
1510 cvt_string_to_pixel_value
= pixel
;
1511 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1514 to
->size
= sizeof (Pixel
);
1519 /* Free a pixel color which was previously allocated via
1520 cvt_string_to_pixel. This is registered as the destructor
1521 for this type of resource via XtSetTypeConverter.
1523 APP is the application context in which we work.
1525 TO is a pointer to an XrmValue holding the color to free.
1526 CLOSURE is the value we stored in CLOSURE_RET for this color
1527 in cvt_string_to_pixel.
1529 ARGS and NARGS are like for cvt_string_to_pixel. */
1532 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1537 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1539 "Screen and colormap arguments required",
1542 else if (closure
!= NULL
)
1544 /* We did allocate the pixel, so free it. */
1545 Screen
*screen
= *(Screen
**) args
[0].addr
;
1546 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1547 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1548 (Pixel
*) to
->addr
, 1);
1553 #endif /* USE_X_TOOLKIT */
1556 /* Value is an array of XColor structures for the contents of the
1557 color map of display DPY. Set *NCELLS to the size of the array.
1558 Note that this probably shouldn't be called for large color maps,
1559 say a 24-bit TrueColor map. */
1561 static const XColor
*
1562 x_color_cells (Display
*dpy
, int *ncells
)
1564 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1566 if (dpyinfo
->color_cells
== NULL
)
1568 Screen
*screen
= dpyinfo
->screen
;
1571 dpyinfo
->ncolor_cells
1572 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1573 dpyinfo
->color_cells
1574 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1575 * sizeof *dpyinfo
->color_cells
);
1577 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1578 dpyinfo
->color_cells
[i
].pixel
= i
;
1580 XQueryColors (dpy
, dpyinfo
->cmap
,
1581 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1584 *ncells
= dpyinfo
->ncolor_cells
;
1585 return dpyinfo
->color_cells
;
1589 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1590 colors in COLORS. Use cached information, if available. */
1593 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1595 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1597 if (dpyinfo
->color_cells
)
1600 for (i
= 0; i
< ncolors
; ++i
)
1602 unsigned long pixel
= colors
[i
].pixel
;
1603 xassert (pixel
< dpyinfo
->ncolor_cells
);
1604 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1605 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1609 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1613 /* On frame F, translate pixel color to RGB values for the color in
1614 COLOR. Use cached information, if available. */
1617 x_query_color (struct frame
*f
, XColor
*color
)
1619 x_query_colors (f
, color
, 1);
1623 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1624 exact match can't be allocated, try the nearest color available.
1625 Value is non-zero if successful. Set *COLOR to the color
1629 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1633 rc
= XAllocColor (dpy
, cmap
, color
);
1636 /* If we got to this point, the colormap is full, so we're going
1637 to try to get the next closest color. The algorithm used is
1638 a least-squares matching, which is what X uses for closest
1639 color matching with StaticColor visuals. */
1641 unsigned long nearest_delta
= ~0;
1643 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1645 for (nearest
= i
= 0; i
< ncells
; ++i
)
1647 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1648 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1649 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1650 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1652 if (delta
< nearest_delta
)
1655 nearest_delta
= delta
;
1659 color
->red
= cells
[nearest
].red
;
1660 color
->green
= cells
[nearest
].green
;
1661 color
->blue
= cells
[nearest
].blue
;
1662 rc
= XAllocColor (dpy
, cmap
, color
);
1666 /* If allocation succeeded, and the allocated pixel color is not
1667 equal to a cached pixel color recorded earlier, there was a
1668 change in the colormap, so clear the color cache. */
1669 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1670 XColor
*cached_color
;
1672 if (dpyinfo
->color_cells
1673 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1674 (cached_color
->red
!= color
->red
1675 || cached_color
->blue
!= color
->blue
1676 || cached_color
->green
!= color
->green
)))
1678 xfree (dpyinfo
->color_cells
);
1679 dpyinfo
->color_cells
= NULL
;
1680 dpyinfo
->ncolor_cells
= 0;
1684 #ifdef DEBUG_X_COLORS
1686 register_color (color
->pixel
);
1687 #endif /* DEBUG_X_COLORS */
1693 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1694 exact match can't be allocated, try the nearest color available.
1695 Value is non-zero if successful. Set *COLOR to the color
1699 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1701 gamma_correct (f
, color
);
1702 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1706 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1707 It's necessary to do this instead of just using PIXEL directly to
1708 get color reference counts right. */
1711 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1715 color
.pixel
= pixel
;
1717 x_query_color (f
, &color
);
1718 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1720 #ifdef DEBUG_X_COLORS
1721 register_color (pixel
);
1727 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1728 It's necessary to do this instead of just using PIXEL directly to
1729 get color reference counts right. */
1732 x_copy_dpy_color (Display
*dpy
, Colormap cmap
, long unsigned int pixel
)
1736 color
.pixel
= pixel
;
1738 XQueryColor (dpy
, cmap
, &color
);
1739 XAllocColor (dpy
, cmap
, &color
);
1741 #ifdef DEBUG_X_COLORS
1742 register_color (pixel
);
1748 /* Brightness beyond which a color won't have its highlight brightness
1751 Nominally, highlight colors for `3d' faces are calculated by
1752 brightening an object's color by a constant scale factor, but this
1753 doesn't yield good results for dark colors, so for colors who's
1754 brightness is less than this value (on a scale of 0-65535) have an
1755 use an additional additive factor.
1757 The value here is set so that the default menu-bar/mode-line color
1758 (grey75) will not have its highlights changed at all. */
1759 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1762 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1763 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1764 If this produces the same color as PIXEL, try a color where all RGB
1765 values have DELTA added. Return the allocated color in *PIXEL.
1766 DISPLAY is the X display, CMAP is the colormap to operate on.
1767 Value is non-zero if successful. */
1770 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1776 /* Get RGB color values. */
1777 color
.pixel
= *pixel
;
1778 x_query_color (f
, &color
);
1780 /* Change RGB values by specified FACTOR. Avoid overflow! */
1781 xassert (factor
>= 0);
1782 new.red
= min (0xffff, factor
* color
.red
);
1783 new.green
= min (0xffff, factor
* color
.green
);
1784 new.blue
= min (0xffff, factor
* color
.blue
);
1786 /* Calculate brightness of COLOR. */
1787 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1789 /* We only boost colors that are darker than
1790 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1791 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1792 /* Make an additive adjustment to NEW, because it's dark enough so
1793 that scaling by FACTOR alone isn't enough. */
1795 /* How far below the limit this color is (0 - 1, 1 being darker). */
1796 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1797 /* The additive adjustment. */
1798 int min_delta
= delta
* dimness
* factor
/ 2;
1802 new.red
= max (0, new.red
- min_delta
);
1803 new.green
= max (0, new.green
- min_delta
);
1804 new.blue
= max (0, new.blue
- min_delta
);
1808 new.red
= min (0xffff, min_delta
+ new.red
);
1809 new.green
= min (0xffff, min_delta
+ new.green
);
1810 new.blue
= min (0xffff, min_delta
+ new.blue
);
1814 /* Try to allocate the color. */
1815 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1818 if (new.pixel
== *pixel
)
1820 /* If we end up with the same color as before, try adding
1821 delta to the RGB values. */
1822 x_free_colors (f
, &new.pixel
, 1);
1824 new.red
= min (0xffff, delta
+ color
.red
);
1825 new.green
= min (0xffff, delta
+ color
.green
);
1826 new.blue
= min (0xffff, delta
+ color
.blue
);
1827 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1838 /* Set up the foreground color for drawing relief lines of glyph
1839 string S. RELIEF is a pointer to a struct relief containing the GC
1840 with which lines will be drawn. Use a color that is FACTOR or
1841 DELTA lighter or darker than the relief's background which is found
1842 in S->f->output_data.x->relief_background. If such a color cannot
1843 be allocated, use DEFAULT_PIXEL, instead. */
1846 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1849 struct x_output
*di
= f
->output_data
.x
;
1850 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1851 unsigned long pixel
;
1852 unsigned long background
= di
->relief_background
;
1853 Colormap cmap
= FRAME_X_COLORMAP (f
);
1854 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1855 Display
*dpy
= FRAME_X_DISPLAY (f
);
1857 xgcv
.graphics_exposures
= False
;
1858 xgcv
.line_width
= 1;
1860 /* Free previously allocated color. The color cell will be reused
1861 when it has been freed as many times as it was allocated, so this
1862 doesn't affect faces using the same colors. */
1864 && relief
->allocated_p
)
1866 x_free_colors (f
, &relief
->pixel
, 1);
1867 relief
->allocated_p
= 0;
1870 /* Allocate new color. */
1871 xgcv
.foreground
= default_pixel
;
1873 if (dpyinfo
->n_planes
!= 1
1874 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1876 relief
->allocated_p
= 1;
1877 xgcv
.foreground
= relief
->pixel
= pixel
;
1880 if (relief
->gc
== 0)
1882 xgcv
.stipple
= dpyinfo
->gray
;
1884 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1887 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1891 /* Set up colors for the relief lines around glyph string S. */
1894 x_setup_relief_colors (struct glyph_string
*s
)
1896 struct x_output
*di
= s
->f
->output_data
.x
;
1897 unsigned long color
;
1899 if (s
->face
->use_box_color_for_shadows_p
)
1900 color
= s
->face
->box_color
;
1901 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1903 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1904 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1909 /* Get the background color of the face. */
1910 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1911 color
= xgcv
.background
;
1914 if (di
->white_relief
.gc
== 0
1915 || color
!= di
->relief_background
)
1917 di
->relief_background
= color
;
1918 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1919 WHITE_PIX_DEFAULT (s
->f
));
1920 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1921 BLACK_PIX_DEFAULT (s
->f
));
1926 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1927 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1928 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1929 relief. LEFT_P non-zero means draw a relief on the left side of
1930 the rectangle. RIGHT_P non-zero means draw a relief on the right
1931 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1935 x_draw_relief_rect (struct frame
*f
,
1936 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1937 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1938 XRectangle
*clip_rect
)
1940 Display
*dpy
= FRAME_X_DISPLAY (f
);
1941 Window window
= FRAME_X_WINDOW (f
);
1946 gc
= f
->output_data
.x
->white_relief
.gc
;
1948 gc
= f
->output_data
.x
->black_relief
.gc
;
1949 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1953 for (i
= 0; i
< width
; ++i
)
1954 XDrawLine (dpy
, window
, gc
,
1955 left_x
+ i
* left_p
, top_y
+ i
,
1956 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1960 for (i
= 0; i
< width
; ++i
)
1961 XDrawLine (dpy
, window
, gc
,
1962 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
1964 XSetClipMask (dpy
, gc
, None
);
1966 gc
= f
->output_data
.x
->black_relief
.gc
;
1968 gc
= f
->output_data
.x
->white_relief
.gc
;
1969 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1973 for (i
= 0; i
< width
; ++i
)
1974 XDrawLine (dpy
, window
, gc
,
1975 left_x
+ i
* left_p
, bottom_y
- i
,
1976 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
1980 for (i
= 0; i
< width
; ++i
)
1981 XDrawLine (dpy
, window
, gc
,
1982 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
1984 XSetClipMask (dpy
, gc
, None
);
1988 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
1989 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
1990 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
1991 left side of the rectangle. RIGHT_P non-zero means draw a line
1992 on the right side of the rectangle. CLIP_RECT is the clipping
1993 rectangle to use when drawing. */
1996 x_draw_box_rect (struct glyph_string
*s
,
1997 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1998 int left_p
, int right_p
, XRectangle
*clip_rect
)
2002 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2003 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2004 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2007 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2008 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2012 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2013 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2016 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2017 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2021 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2022 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2024 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2025 XSetClipMask (s
->display
, s
->gc
, None
);
2029 /* Draw a box around glyph string S. */
2032 x_draw_glyph_string_box (struct glyph_string
*s
)
2034 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2035 int left_p
, right_p
;
2036 struct glyph
*last_glyph
;
2037 XRectangle clip_rect
;
2039 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2040 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2041 : window_box_right (s
->w
, s
->area
));
2043 /* The glyph that may have a right box line. */
2044 last_glyph
= (s
->cmp
|| s
->img
2046 : s
->first_glyph
+ s
->nchars
- 1);
2048 width
= eabs (s
->face
->box_line_width
);
2049 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2051 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2053 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2055 bottom_y
= top_y
+ s
->height
- 1;
2057 left_p
= (s
->first_glyph
->left_box_line_p
2058 || (s
->hl
== DRAW_MOUSE_FACE
2060 || s
->prev
->hl
!= s
->hl
)));
2061 right_p
= (last_glyph
->right_box_line_p
2062 || (s
->hl
== DRAW_MOUSE_FACE
2064 || s
->next
->hl
!= s
->hl
)));
2066 get_glyph_string_clip_rect (s
, &clip_rect
);
2068 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2069 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2070 left_p
, right_p
, &clip_rect
);
2073 x_setup_relief_colors (s
);
2074 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2075 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2080 /* Draw foreground of image glyph string S. */
2083 x_draw_image_foreground (struct glyph_string
*s
)
2086 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2088 /* If first glyph of S has a left box line, start drawing it to the
2089 right of that line. */
2090 if (s
->face
->box
!= FACE_NO_BOX
2091 && s
->first_glyph
->left_box_line_p
2093 x
+= eabs (s
->face
->box_line_width
);
2095 /* If there is a margin around the image, adjust x- and y-position
2097 if (s
->slice
.x
== 0)
2098 x
+= s
->img
->hmargin
;
2099 if (s
->slice
.y
== 0)
2100 y
+= s
->img
->vmargin
;
2106 /* We can't set both a clip mask and use XSetClipRectangles
2107 because the latter also sets a clip mask. We also can't
2108 trust on the shape extension to be available
2109 (XShapeCombineRegion). So, compute the rectangle to draw
2111 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2114 XRectangle clip_rect
, image_rect
, r
;
2116 xgcv
.clip_mask
= s
->img
->mask
;
2117 xgcv
.clip_x_origin
= x
;
2118 xgcv
.clip_y_origin
= y
;
2119 xgcv
.function
= GXcopy
;
2120 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2122 get_glyph_string_clip_rect (s
, &clip_rect
);
2125 image_rect
.width
= s
->slice
.width
;
2126 image_rect
.height
= s
->slice
.height
;
2127 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2128 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2129 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2130 r
.width
, r
.height
, r
.x
, r
.y
);
2134 XRectangle clip_rect
, image_rect
, r
;
2136 get_glyph_string_clip_rect (s
, &clip_rect
);
2139 image_rect
.width
= s
->slice
.width
;
2140 image_rect
.height
= s
->slice
.height
;
2141 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2142 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2143 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2144 r
.width
, r
.height
, r
.x
, r
.y
);
2146 /* When the image has a mask, we can expect that at
2147 least part of a mouse highlight or a block cursor will
2148 be visible. If the image doesn't have a mask, make
2149 a block cursor visible by drawing a rectangle around
2150 the image. I believe it's looking better if we do
2151 nothing here for mouse-face. */
2152 if (s
->hl
== DRAW_CURSOR
)
2154 int r
= s
->img
->relief
;
2156 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2158 s
->slice
.width
+ r
*2 - 1,
2159 s
->slice
.height
+ r
*2 - 1);
2164 /* Draw a rectangle if image could not be loaded. */
2165 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2166 s
->slice
.width
- 1, s
->slice
.height
- 1);
2170 /* Draw a relief around the image glyph string S. */
2173 x_draw_image_relief (struct glyph_string
*s
)
2175 int x0
, y0
, x1
, y1
, thick
, raised_p
, extra
;
2178 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2180 /* If first glyph of S has a left box line, start drawing it to the
2181 right of that line. */
2182 if (s
->face
->box
!= FACE_NO_BOX
2183 && s
->first_glyph
->left_box_line_p
2185 x
+= eabs (s
->face
->box_line_width
);
2187 /* If there is a margin around the image, adjust x- and y-position
2189 if (s
->slice
.x
== 0)
2190 x
+= s
->img
->hmargin
;
2191 if (s
->slice
.y
== 0)
2192 y
+= s
->img
->vmargin
;
2194 if (s
->hl
== DRAW_IMAGE_SUNKEN
2195 || s
->hl
== DRAW_IMAGE_RAISED
)
2197 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2198 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2202 thick
= eabs (s
->img
->relief
);
2203 raised_p
= s
->img
->relief
> 0;
2206 extra
= s
->face
->id
== TOOL_BAR_FACE_ID
2207 ? XINT (Vtool_bar_button_margin
) : 0;
2209 x0
= x
- thick
- extra
;
2210 y0
= y
- thick
- extra
;
2211 x1
= x
+ s
->slice
.width
+ thick
- 1 + extra
;
2212 y1
= y
+ s
->slice
.height
+ thick
- 1 + extra
;
2214 x_setup_relief_colors (s
);
2215 get_glyph_string_clip_rect (s
, &r
);
2216 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2218 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2220 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2225 /* Draw the foreground of image glyph string S to PIXMAP. */
2228 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2231 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2233 /* If first glyph of S has a left box line, start drawing it to the
2234 right of that line. */
2235 if (s
->face
->box
!= FACE_NO_BOX
2236 && s
->first_glyph
->left_box_line_p
2238 x
+= eabs (s
->face
->box_line_width
);
2240 /* If there is a margin around the image, adjust x- and y-position
2242 if (s
->slice
.x
== 0)
2243 x
+= s
->img
->hmargin
;
2244 if (s
->slice
.y
== 0)
2245 y
+= s
->img
->vmargin
;
2251 /* We can't set both a clip mask and use XSetClipRectangles
2252 because the latter also sets a clip mask. We also can't
2253 trust on the shape extension to be available
2254 (XShapeCombineRegion). So, compute the rectangle to draw
2256 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2260 xgcv
.clip_mask
= s
->img
->mask
;
2261 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2262 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2263 xgcv
.function
= GXcopy
;
2264 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2266 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2267 s
->slice
.x
, s
->slice
.y
,
2268 s
->slice
.width
, s
->slice
.height
, x
, y
);
2269 XSetClipMask (s
->display
, s
->gc
, None
);
2273 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2274 s
->slice
.x
, s
->slice
.y
,
2275 s
->slice
.width
, s
->slice
.height
, x
, y
);
2277 /* When the image has a mask, we can expect that at
2278 least part of a mouse highlight or a block cursor will
2279 be visible. If the image doesn't have a mask, make
2280 a block cursor visible by drawing a rectangle around
2281 the image. I believe it's looking better if we do
2282 nothing here for mouse-face. */
2283 if (s
->hl
== DRAW_CURSOR
)
2285 int r
= s
->img
->relief
;
2287 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2288 s
->slice
.width
+ r
*2 - 1,
2289 s
->slice
.height
+ r
*2 - 1);
2294 /* Draw a rectangle if image could not be loaded. */
2295 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2296 s
->slice
.width
- 1, s
->slice
.height
- 1);
2300 /* Draw part of the background of glyph string S. X, Y, W, and H
2301 give the rectangle to draw. */
2304 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2308 /* Fill background with a stipple pattern. */
2309 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2310 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2311 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2314 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2318 /* Draw image glyph string S.
2321 s->x +-------------------------
2324 | +-------------------------
2327 | | +-------------------
2333 x_draw_image_glyph_string (struct glyph_string
*s
)
2335 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2336 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2338 Pixmap pixmap
= None
;
2341 if (s
->slice
.y
== 0)
2342 height
-= box_line_vwidth
;
2343 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2344 height
-= box_line_vwidth
;
2346 /* Fill background with face under the image. Do it only if row is
2347 taller than image or if image has a clip mask to reduce
2349 s
->stippled_p
= s
->face
->stipple
!= 0;
2350 if (height
> s
->slice
.height
2354 || s
->img
->pixmap
== 0
2355 || s
->width
!= s
->background_width
)
2359 /* Create a pixmap as large as the glyph string. Fill it
2360 with the background color. Copy the image to it, using
2361 its mask. Copy the temporary pixmap to the display. */
2362 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2363 int depth
= DefaultDepthOfScreen (screen
);
2365 /* Create a pixmap as large as the glyph string. */
2366 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2367 s
->background_width
,
2370 /* Don't clip in the following because we're working on the
2372 XSetClipMask (s
->display
, s
->gc
, None
);
2374 /* Fill the pixmap with the background color/stipple. */
2377 /* Fill background with a stipple pattern. */
2378 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2379 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2380 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2381 0, 0, s
->background_width
, s
->height
);
2382 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2383 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2388 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2390 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2391 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2392 0, 0, s
->background_width
, s
->height
);
2393 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2401 if (s
->first_glyph
->left_box_line_p
2403 x
+= box_line_hwidth
;
2405 if (s
->slice
.y
== 0)
2406 y
+= box_line_vwidth
;
2408 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2411 s
->background_filled_p
= 1;
2414 /* Draw the foreground. */
2417 x_draw_image_foreground_1 (s
, pixmap
);
2418 x_set_glyph_string_clipping (s
);
2419 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2420 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2421 XFreePixmap (s
->display
, pixmap
);
2424 x_draw_image_foreground (s
);
2426 /* If we must draw a relief around the image, do it. */
2428 || s
->hl
== DRAW_IMAGE_RAISED
2429 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2430 x_draw_image_relief (s
);
2434 /* Draw stretch glyph string S. */
2437 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2439 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2441 if (s
->hl
== DRAW_CURSOR
2442 && !x_stretch_cursor_p
)
2444 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2445 as wide as the stretch glyph. */
2446 int width
, background_width
= s
->background_width
;
2447 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2451 background_width
-= left_x
- x
;
2454 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2457 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2459 /* Clear rest using the GC of the original non-cursor face. */
2460 if (width
< background_width
)
2463 int w
= background_width
- width
, h
= s
->height
;
2468 if (s
->row
->mouse_face_p
2469 && cursor_in_mouse_face_p (s
->w
))
2471 x_set_mouse_face_gc (s
);
2477 get_glyph_string_clip_rect (s
, &r
);
2478 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2480 if (s
->face
->stipple
)
2482 /* Fill background with a stipple pattern. */
2483 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2484 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2485 XSetFillStyle (s
->display
, gc
, FillSolid
);
2490 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2491 XSetForeground (s
->display
, gc
, xgcv
.background
);
2492 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2493 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2497 else if (!s
->background_filled_p
)
2499 int background_width
= s
->background_width
;
2500 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2502 /* Don't draw into left margin, fringe or scrollbar area
2503 except for header line and mode line. */
2504 if (x
< left_x
&& !s
->row
->mode_line_p
)
2506 background_width
-= left_x
- x
;
2509 if (background_width
> 0)
2510 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2513 s
->background_filled_p
= 1;
2517 /* Draw glyph string S. */
2520 x_draw_glyph_string (struct glyph_string
*s
)
2522 int relief_drawn_p
= 0;
2524 /* If S draws into the background of its successors, draw the
2525 background of the successors first so that S can draw into it.
2526 This makes S->next use XDrawString instead of XDrawImageString. */
2527 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2530 struct glyph_string
*next
;
2532 for (width
= 0, next
= s
->next
;
2533 next
&& width
< s
->right_overhang
;
2534 width
+= next
->width
, next
= next
->next
)
2535 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2537 x_set_glyph_string_gc (next
);
2538 x_set_glyph_string_clipping (next
);
2539 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2540 x_draw_stretch_glyph_string (next
);
2542 x_draw_glyph_string_background (next
, 1);
2543 next
->num_clips
= 0;
2547 /* Set up S->gc, set clipping and draw S. */
2548 x_set_glyph_string_gc (s
);
2550 /* Draw relief (if any) in advance for char/composition so that the
2551 glyph string can be drawn over it. */
2552 if (!s
->for_overlaps
2553 && s
->face
->box
!= FACE_NO_BOX
2554 && (s
->first_glyph
->type
== CHAR_GLYPH
2555 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2558 x_set_glyph_string_clipping (s
);
2559 x_draw_glyph_string_background (s
, 1);
2560 x_draw_glyph_string_box (s
);
2561 x_set_glyph_string_clipping (s
);
2564 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2566 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2567 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2568 /* We must clip just this glyph. left_overhang part has already
2569 drawn when s->prev was drawn, and right_overhang part will be
2570 drawn later when s->next is drawn. */
2571 x_set_glyph_string_clipping_exactly (s
, s
);
2573 x_set_glyph_string_clipping (s
);
2575 switch (s
->first_glyph
->type
)
2578 x_draw_image_glyph_string (s
);
2582 x_draw_stretch_glyph_string (s
);
2586 if (s
->for_overlaps
)
2587 s
->background_filled_p
= 1;
2589 x_draw_glyph_string_background (s
, 0);
2590 x_draw_glyph_string_foreground (s
);
2593 case COMPOSITE_GLYPH
:
2594 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2595 && ! s
->first_glyph
->u
.cmp
.automatic
))
2596 s
->background_filled_p
= 1;
2598 x_draw_glyph_string_background (s
, 1);
2599 x_draw_composite_glyph_string_foreground (s
);
2606 if (!s
->for_overlaps
)
2608 /* Draw underline. */
2609 if (s
->face
->underline_p
)
2611 unsigned long thickness
, position
;
2614 if (s
->prev
&& s
->prev
->face
->underline_p
)
2616 /* We use the same underline style as the previous one. */
2617 thickness
= s
->prev
->underline_thickness
;
2618 position
= s
->prev
->underline_position
;
2622 /* Get the underline thickness. Default is 1 pixel. */
2623 if (s
->font
&& s
->font
->underline_thickness
> 0)
2624 thickness
= s
->font
->underline_thickness
;
2627 if (x_underline_at_descent_line
)
2628 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2631 /* Get the underline position. This is the recommended
2632 vertical offset in pixels from the baseline to the top of
2633 the underline. This is a signed value according to the
2634 specs, and its default is
2636 ROUND ((maximum descent) / 2), with
2637 ROUND(x) = floor (x + 0.5) */
2639 if (x_use_underline_position_properties
2640 && s
->font
&& s
->font
->underline_position
>= 0)
2641 position
= s
->font
->underline_position
;
2643 position
= (s
->font
->descent
+ 1) / 2;
2645 position
= underline_minimum_offset
;
2647 position
= max (position
, underline_minimum_offset
);
2649 /* Check the sanity of thickness and position. We should
2650 avoid drawing underline out of the current line area. */
2651 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2652 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2653 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2654 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2655 s
->underline_thickness
= thickness
;
2656 s
->underline_position
= position
;
2657 y
= s
->ybase
+ position
;
2658 if (s
->face
->underline_defaulted_p
)
2659 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2660 s
->x
, y
, s
->width
, thickness
);
2664 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2665 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2666 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2667 s
->x
, y
, s
->width
, thickness
);
2668 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2672 /* Draw overline. */
2673 if (s
->face
->overline_p
)
2675 unsigned long dy
= 0, h
= 1;
2677 if (s
->face
->overline_color_defaulted_p
)
2678 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2683 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2684 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2685 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2687 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2691 /* Draw strike-through. */
2692 if (s
->face
->strike_through_p
)
2694 unsigned long h
= 1;
2695 unsigned long dy
= (s
->height
- h
) / 2;
2697 if (s
->face
->strike_through_color_defaulted_p
)
2698 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2703 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2704 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2705 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2707 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2711 /* Draw relief if not yet drawn. */
2712 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2713 x_draw_glyph_string_box (s
);
2717 struct glyph_string
*prev
;
2719 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2720 if (prev
->hl
!= s
->hl
2721 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2723 /* As prev was drawn while clipped to its own area, we
2724 must draw the right_overhang part using s->hl now. */
2725 enum draw_glyphs_face save
= prev
->hl
;
2728 x_set_glyph_string_gc (prev
);
2729 x_set_glyph_string_clipping_exactly (s
, prev
);
2730 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2731 x_draw_glyph_string_foreground (prev
);
2733 x_draw_composite_glyph_string_foreground (prev
);
2734 XSetClipMask (prev
->display
, prev
->gc
, None
);
2736 prev
->num_clips
= 0;
2742 struct glyph_string
*next
;
2744 for (next
= s
->next
; next
; next
= next
->next
)
2745 if (next
->hl
!= s
->hl
2746 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2748 /* As next will be drawn while clipped to its own area,
2749 we must draw the left_overhang part using s->hl now. */
2750 enum draw_glyphs_face save
= next
->hl
;
2753 x_set_glyph_string_gc (next
);
2754 x_set_glyph_string_clipping_exactly (s
, next
);
2755 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2756 x_draw_glyph_string_foreground (next
);
2758 x_draw_composite_glyph_string_foreground (next
);
2759 XSetClipMask (next
->display
, next
->gc
, None
);
2761 next
->num_clips
= 0;
2766 /* Reset clipping. */
2767 XSetClipMask (s
->display
, s
->gc
, None
);
2771 /* Shift display to make room for inserted glyphs. */
2774 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2776 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2777 f
->output_data
.x
->normal_gc
,
2778 x
, y
, width
, height
,
2782 /* Delete N glyphs at the nominal cursor position. Not implemented
2786 x_delete_glyphs (struct frame
*f
, register int n
)
2792 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2793 If they are <= 0, this is probably an error. */
2796 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
, int exposures
)
2798 xassert (width
> 0 && height
> 0);
2799 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2803 /* Clear an entire frame. */
2806 x_clear_frame (struct frame
*f
)
2808 /* Clearing the frame will erase any cursor, so mark them all as no
2810 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2811 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2812 output_cursor
.x
= -1;
2814 /* We don't set the output cursor here because there will always
2815 follow an explicit cursor_to. */
2817 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2819 /* We have to clear the scroll bars, too. If we have changed
2820 colors or something like that, then they should be notified. */
2821 x_scroll_bar_clear (f
);
2823 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2824 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2825 redisplay, do it here. */
2826 if (FRAME_GTK_WIDGET (f
))
2827 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2830 XFlush (FRAME_X_DISPLAY (f
));
2837 /* Invert the middle quarter of the frame for .15 sec. */
2839 /* We use the select system call to do the waiting, so we have to make
2840 sure it's available. If it isn't, we just won't do visual bells. */
2842 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2845 /* Subtract the `struct timeval' values X and Y, storing the result in
2846 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2849 timeval_subtract (struct timeval
*result
, struct timeval x
, struct timeval y
)
2851 /* Perform the carry for the later subtraction by updating y. This
2852 is safer because on some systems the tv_sec member is unsigned. */
2853 if (x
.tv_usec
< y
.tv_usec
)
2855 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2856 y
.tv_usec
-= 1000000 * nsec
;
2860 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2862 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2863 y
.tv_usec
+= 1000000 * nsec
;
2867 /* Compute the time remaining to wait. tv_usec is certainly
2869 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2870 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2872 /* Return indication of whether the result should be considered
2874 return x
.tv_sec
< y
.tv_sec
;
2878 XTflash (struct frame
*f
)
2884 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
2885 when the scroll bars and the edit widget share the same X window. */
2886 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
2889 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
2890 ^ FRAME_BACKGROUND_PIXEL (f
));
2891 vals
.function
= GDK_XOR
;
2892 gc
= gdk_gc_new_with_values (window
,
2893 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
2894 #define XFillRectangle(d, win, gc, x, y, w, h) \
2895 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
2899 /* Create a GC that will use the GXxor function to flip foreground
2900 pixels into background pixels. */
2904 values
.function
= GXxor
;
2905 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
2906 ^ FRAME_BACKGROUND_PIXEL (f
));
2908 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2909 GCFunction
| GCForeground
, &values
);
2913 /* Get the height not including a menu bar widget. */
2914 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
2915 /* Height of each line to flash. */
2916 int flash_height
= FRAME_LINE_HEIGHT (f
);
2917 /* These will be the left and right margins of the rectangles. */
2918 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2919 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2923 /* Don't flash the area between a scroll bar and the frame
2924 edge it is next to. */
2925 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
2927 case vertical_scroll_bar_left
:
2928 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2931 case vertical_scroll_bar_right
:
2932 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2939 width
= flash_right
- flash_left
;
2941 /* If window is tall, flash top and bottom line. */
2942 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2944 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2946 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2947 + FRAME_TOP_MARGIN_HEIGHT (f
)),
2948 width
, flash_height
);
2949 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2951 (height
- flash_height
2952 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2953 width
, flash_height
);
2957 /* If it is short, flash it all. */
2958 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2959 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2960 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2965 struct timeval wakeup
;
2967 EMACS_GET_TIME (wakeup
);
2969 /* Compute time to wait until, propagating carry from usecs. */
2970 wakeup
.tv_usec
+= 150000;
2971 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
2972 wakeup
.tv_usec
%= 1000000;
2974 /* Keep waiting until past the time wakeup or any input gets
2976 while (! detect_input_pending ())
2978 struct timeval current
;
2979 struct timeval timeout
;
2981 EMACS_GET_TIME (current
);
2983 /* Break if result would be negative. */
2984 if (timeval_subtract (¤t
, wakeup
, current
))
2987 /* How long `select' should wait. */
2989 timeout
.tv_usec
= 10000;
2991 /* Try to wait that long--but we might wake up sooner. */
2992 select (0, NULL
, NULL
, NULL
, &timeout
);
2996 /* If window is tall, flash top and bottom line. */
2997 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2999 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3001 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3002 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3003 width
, flash_height
);
3004 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3006 (height
- flash_height
3007 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3008 width
, flash_height
);
3011 /* If it is short, flash it all. */
3012 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3013 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3014 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3017 g_object_unref (G_OBJECT (gc
));
3018 #undef XFillRectangle
3020 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3029 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3033 XTtoggle_invisible_pointer (FRAME_PTR f
, int invisible
)
3038 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3039 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3040 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
);
3043 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3044 f
->output_data
.x
->current_cursor
);
3045 f
->pointer_invisible
= invisible
;
3050 /* Make audible bell. */
3053 XTring_bell (struct frame
*f
)
3055 if (FRAME_X_DISPLAY (f
))
3057 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3064 XBell (FRAME_X_DISPLAY (f
), 0);
3065 XFlush (FRAME_X_DISPLAY (f
));
3072 /* Specify how many text lines, from the top of the window,
3073 should be affected by insert-lines and delete-lines operations.
3074 This, and those operations, are used only within an update
3075 that is bounded by calls to x_update_begin and x_update_end. */
3078 XTset_terminal_window (struct frame
*f
, int n
)
3080 /* This function intentionally left blank. */
3085 /***********************************************************************
3087 ***********************************************************************/
3089 /* Perform an insert-lines or delete-lines operation, inserting N
3090 lines or deleting -N lines at vertical position VPOS. */
3093 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3099 /* Scroll part of the display as described by RUN. */
3102 x_scroll_run (struct window
*w
, struct run
*run
)
3104 struct frame
*f
= XFRAME (w
->frame
);
3105 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3107 /* Get frame-relative bounding box of the text display area of W,
3108 without mode lines. Include in this box the left and right
3110 window_box (w
, -1, &x
, &y
, &width
, &height
);
3112 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3113 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3114 bottom_y
= y
+ height
;
3118 /* Scrolling up. Make sure we don't copy part of the mode
3119 line at the bottom. */
3120 if (from_y
+ run
->height
> bottom_y
)
3121 height
= bottom_y
- from_y
;
3123 height
= run
->height
;
3127 /* Scolling down. Make sure we don't copy over the mode line.
3129 if (to_y
+ run
->height
> bottom_y
)
3130 height
= bottom_y
- to_y
;
3132 height
= run
->height
;
3137 /* Cursor off. Will be switched on again in x_update_window_end. */
3141 XCopyArea (FRAME_X_DISPLAY (f
),
3142 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3143 f
->output_data
.x
->normal_gc
,
3153 /***********************************************************************
3155 ***********************************************************************/
3159 frame_highlight (struct frame
*f
)
3161 /* We used to only do this if Vx_no_window_manager was non-nil, but
3162 the ICCCM (section 4.1.6) says that the window's border pixmap
3163 and border pixel are window attributes which are "private to the
3164 client", so we can always change it to whatever we want. */
3166 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3167 f
->output_data
.x
->border_pixel
);
3169 x_update_cursor (f
, 1);
3170 x_set_frame_alpha (f
);
3174 frame_unhighlight (struct frame
*f
)
3176 /* We used to only do this if Vx_no_window_manager was non-nil, but
3177 the ICCCM (section 4.1.6) says that the window's border pixmap
3178 and border pixel are window attributes which are "private to the
3179 client", so we can always change it to whatever we want. */
3181 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3182 f
->output_data
.x
->border_tile
);
3184 x_update_cursor (f
, 1);
3185 x_set_frame_alpha (f
);
3188 /* The focus has changed. Update the frames as necessary to reflect
3189 the new situation. Note that we can't change the selected frame
3190 here, because the Lisp code we are interrupting might become confused.
3191 Each event gets marked with the frame in which it occurred, so the
3192 Lisp code can tell when the switch took place by examining the events. */
3195 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3197 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3199 if (frame
!= dpyinfo
->x_focus_frame
)
3201 /* Set this before calling other routines, so that they see
3202 the correct value of x_focus_frame. */
3203 dpyinfo
->x_focus_frame
= frame
;
3205 if (old_focus
&& old_focus
->auto_lower
)
3206 x_lower_frame (old_focus
);
3208 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3209 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3211 pending_autoraise_frame
= 0;
3214 x_frame_rehighlight (dpyinfo
);
3217 /* Handle FocusIn and FocusOut state changes for FRAME.
3218 If FRAME has focus and there exists more than one frame, puts
3219 a FOCUS_IN_EVENT into *BUFP. */
3222 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3224 if (type
== FocusIn
)
3226 if (dpyinfo
->x_focus_event_frame
!= frame
)
3228 x_new_focus_frame (dpyinfo
, frame
);
3229 dpyinfo
->x_focus_event_frame
= frame
;
3231 /* Don't stop displaying the initial startup message
3232 for a switch-frame event we don't need. */
3233 if (NILP (Vterminal_frame
)
3234 && CONSP (Vframe_list
)
3235 && !NILP (XCDR (Vframe_list
)))
3237 bufp
->kind
= FOCUS_IN_EVENT
;
3238 XSETFRAME (bufp
->frame_or_window
, frame
);
3242 frame
->output_data
.x
->focus_state
|= state
;
3245 if (FRAME_XIC (frame
))
3246 XSetICFocus (FRAME_XIC (frame
));
3249 else if (type
== FocusOut
)
3251 frame
->output_data
.x
->focus_state
&= ~state
;
3253 if (dpyinfo
->x_focus_event_frame
== frame
)
3255 dpyinfo
->x_focus_event_frame
= 0;
3256 x_new_focus_frame (dpyinfo
, 0);
3260 if (FRAME_XIC (frame
))
3261 XUnsetICFocus (FRAME_XIC (frame
));
3263 if (frame
->pointer_invisible
)
3264 XTtoggle_invisible_pointer (frame
, 0);
3268 /* The focus may have changed. Figure out if it is a real focus change,
3269 by checking both FocusIn/Out and Enter/LeaveNotify events.
3271 Returns FOCUS_IN_EVENT event in *BUFP. */
3274 x_detect_focus_change (struct x_display_info
*dpyinfo
, XEvent
*event
, struct input_event
*bufp
)
3276 struct frame
*frame
;
3278 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3282 switch (event
->type
)
3287 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3289 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3291 if (event
->xcrossing
.detail
!= NotifyInferior
3292 && event
->xcrossing
.focus
3293 && ! (focus_state
& FOCUS_EXPLICIT
))
3294 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3296 dpyinfo
, frame
, bufp
);
3302 x_focus_changed (event
->type
,
3303 (event
->xfocus
.detail
== NotifyPointer
?
3304 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3305 dpyinfo
, frame
, bufp
);
3309 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3311 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3312 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3313 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3320 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3323 x_mouse_leave (struct x_display_info
*dpyinfo
)
3325 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3328 /* The focus has changed, or we have redirected a frame's focus to
3329 another frame (this happens when a frame uses a surrogate
3330 mini-buffer frame). Shift the highlight as appropriate.
3332 The FRAME argument doesn't necessarily have anything to do with which
3333 frame is being highlighted or un-highlighted; we only use it to find
3334 the appropriate X display info. */
3337 XTframe_rehighlight (struct frame
*frame
)
3339 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3343 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3345 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3347 if (dpyinfo
->x_focus_frame
)
3349 dpyinfo
->x_highlight_frame
3350 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3351 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3352 : dpyinfo
->x_focus_frame
);
3353 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3355 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3356 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3360 dpyinfo
->x_highlight_frame
= 0;
3362 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3365 frame_unhighlight (old_highlight
);
3366 if (dpyinfo
->x_highlight_frame
)
3367 frame_highlight (dpyinfo
->x_highlight_frame
);
3373 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3375 /* Initialize mode_switch_bit and modifier_meaning. */
3377 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3379 int min_code
, max_code
;
3382 XModifierKeymap
*mods
;
3384 dpyinfo
->meta_mod_mask
= 0;
3385 dpyinfo
->shift_lock_mask
= 0;
3386 dpyinfo
->alt_mod_mask
= 0;
3387 dpyinfo
->super_mod_mask
= 0;
3388 dpyinfo
->hyper_mod_mask
= 0;
3390 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3392 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3393 min_code
, max_code
- min_code
+ 1,
3395 mods
= XGetModifierMapping (dpyinfo
->display
);
3397 /* Scan the modifier table to see which modifier bits the Meta and
3398 Alt keysyms are on. */
3400 int row
, col
; /* The row and column in the modifier table. */
3401 int found_alt_or_meta
;
3403 for (row
= 3; row
< 8; row
++)
3405 found_alt_or_meta
= 0;
3406 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3408 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3410 /* Zeroes are used for filler. Skip them. */
3414 /* Are any of this keycode's keysyms a meta key? */
3418 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3420 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3426 found_alt_or_meta
= 1;
3427 dpyinfo
->meta_mod_mask
|= (1 << row
);
3432 found_alt_or_meta
= 1;
3433 dpyinfo
->alt_mod_mask
|= (1 << row
);
3438 if (!found_alt_or_meta
)
3439 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3440 code_col
= syms_per_code
;
3441 col
= mods
->max_keypermod
;
3446 if (!found_alt_or_meta
)
3447 dpyinfo
->super_mod_mask
|= (1 << row
);
3448 code_col
= syms_per_code
;
3449 col
= mods
->max_keypermod
;
3453 /* Ignore this if it's not on the lock modifier. */
3454 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3455 dpyinfo
->shift_lock_mask
= LockMask
;
3456 code_col
= syms_per_code
;
3457 col
= mods
->max_keypermod
;
3466 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3467 if (! dpyinfo
->meta_mod_mask
)
3469 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3470 dpyinfo
->alt_mod_mask
= 0;
3473 /* If some keys are both alt and meta,
3474 make them just meta, not alt. */
3475 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3477 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3480 XFree ((char *) syms
);
3481 XFreeModifiermap (mods
);
3484 /* Convert between the modifier bits X uses and the modifier bits
3488 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, unsigned int state
)
3490 EMACS_UINT mod_meta
= meta_modifier
;
3491 EMACS_UINT mod_alt
= alt_modifier
;
3492 EMACS_UINT mod_hyper
= hyper_modifier
;
3493 EMACS_UINT mod_super
= super_modifier
;
3496 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3497 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3498 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3499 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3500 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3501 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3502 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3503 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3506 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3507 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3508 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3509 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3510 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3511 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3515 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, unsigned int state
)
3517 EMACS_UINT mod_meta
= meta_modifier
;
3518 EMACS_UINT mod_alt
= alt_modifier
;
3519 EMACS_UINT mod_hyper
= hyper_modifier
;
3520 EMACS_UINT mod_super
= super_modifier
;
3524 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3525 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3526 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3527 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3528 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3529 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3530 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3531 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3534 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3535 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3536 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3537 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3538 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3539 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3542 /* Convert a keysym to its name. */
3545 x_get_keysym_name (int keysym
)
3550 value
= XKeysymToString (keysym
);
3558 /* Mouse clicks and mouse movement. Rah. */
3560 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3562 If the event is a button press, then note that we have grabbed
3566 construct_mouse_click (struct input_event
*result
, XButtonEvent
*event
, struct frame
*f
)
3568 /* Make the event type NO_EVENT; we'll change that when we decide
3570 result
->kind
= MOUSE_CLICK_EVENT
;
3571 result
->code
= event
->button
- Button1
;
3572 result
->timestamp
= event
->time
;
3573 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3575 | (event
->type
== ButtonRelease
3579 XSETINT (result
->x
, event
->x
);
3580 XSETINT (result
->y
, event
->y
);
3581 XSETFRAME (result
->frame_or_window
, f
);
3587 /* Function to report a mouse movement to the mainstream Emacs code.
3588 The input handler calls this.
3590 We have received a mouse movement event, which is given in *event.
3591 If the mouse is over a different glyph than it was last time, tell
3592 the mainstream emacs code by setting mouse_moved. If not, ask for
3593 another motion event, so we can check again the next time it moves. */
3595 static XMotionEvent last_mouse_motion_event
;
3596 static Lisp_Object last_mouse_motion_frame
;
3599 note_mouse_movement (FRAME_PTR frame
, XMotionEvent
*event
)
3601 last_mouse_movement_time
= event
->time
;
3602 last_mouse_motion_event
= *event
;
3603 XSETFRAME (last_mouse_motion_frame
, frame
);
3605 if (!FRAME_X_OUTPUT (frame
))
3608 if (event
->window
!= FRAME_X_WINDOW (frame
))
3610 frame
->mouse_moved
= 1;
3611 last_mouse_scroll_bar
= Qnil
;
3612 note_mouse_highlight (frame
, -1, -1);
3613 last_mouse_glyph_frame
= 0;
3618 /* Has the mouse moved off the glyph it was on at the last sighting? */
3619 if (frame
!= last_mouse_glyph_frame
3620 || event
->x
< last_mouse_glyph
.x
3621 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3622 || event
->y
< last_mouse_glyph
.y
3623 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3625 frame
->mouse_moved
= 1;
3626 last_mouse_scroll_bar
= Qnil
;
3627 note_mouse_highlight (frame
, event
->x
, event
->y
);
3628 /* Remember which glyph we're now on. */
3629 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3630 last_mouse_glyph_frame
= frame
;
3638 /************************************************************************
3640 ************************************************************************/
3643 redo_mouse_highlight (void)
3645 if (!NILP (last_mouse_motion_frame
)
3646 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3647 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3648 last_mouse_motion_event
.x
,
3649 last_mouse_motion_event
.y
);
3654 /* Return the current position of the mouse.
3655 *FP should be a frame which indicates which display to ask about.
3657 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3658 and *PART to the frame, window, and scroll bar part that the mouse
3659 is over. Set *X and *Y to the portion and whole of the mouse's
3660 position on the scroll bar.
3662 If the mouse movement started elsewhere, set *FP to the frame the
3663 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3666 Set *TIME to the server time-stamp for the time at which the mouse
3667 was at this position.
3669 Don't store anything if we don't have a valid set of values to report.
3671 This clears the mouse_moved flag, so we can wait for the next mouse
3675 XTmouse_position (FRAME_PTR
*fp
, int insist
, Lisp_Object
*bar_window
, enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
, long unsigned int *time
)
3681 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3682 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3688 Window dummy_window
;
3691 Lisp_Object frame
, tail
;
3693 /* Clear the mouse-moved flag for every frame on this display. */
3694 FOR_EACH_FRAME (tail
, frame
)
3695 if (FRAME_X_P (XFRAME (frame
))
3696 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3697 XFRAME (frame
)->mouse_moved
= 0;
3699 last_mouse_scroll_bar
= Qnil
;
3701 /* Figure out which root window we're on. */
3702 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3703 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3705 /* The root window which contains the pointer. */
3708 /* Trash which we can't trust if the pointer is on
3709 a different screen. */
3712 /* The position on that root window. */
3715 /* More trash we can't trust. */
3718 /* Modifier keys and pointer buttons, about which
3720 (unsigned int *) &dummy
);
3722 /* Now we have a position on the root; find the innermost window
3723 containing the pointer. */
3727 int parent_x
= 0, parent_y
= 0;
3731 /* XTranslateCoordinates can get errors if the window
3732 structure is changing at the same time this function
3733 is running. So at least we must not crash from them. */
3735 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3737 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3738 && FRAME_LIVE_P (last_mouse_frame
))
3740 /* If mouse was grabbed on a frame, give coords for that frame
3741 even if the mouse is now outside it. */
3742 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3744 /* From-window, to-window. */
3745 root
, FRAME_X_WINDOW (last_mouse_frame
),
3747 /* From-position, to-position. */
3748 root_x
, root_y
, &win_x
, &win_y
,
3752 f1
= last_mouse_frame
;
3758 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3760 /* From-window, to-window. */
3763 /* From-position, to-position. */
3764 root_x
, root_y
, &win_x
, &win_y
,
3769 if (child
== None
|| child
== win
)
3772 /* We don't wan't to know the innermost window. We
3773 want the edit window. For non-Gtk+ the innermost
3774 window is the edit window. For Gtk+ it might not
3775 be. It might be the tool bar for example. */
3776 if (x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
))
3784 /* Now we know that:
3785 win is the innermost window containing the pointer
3786 (XTC says it has no child containing the pointer),
3787 win_x and win_y are the pointer's position in it
3788 (XTC did this the last time through), and
3789 parent_x and parent_y are the pointer's position in win's parent.
3790 (They are what win_x and win_y were when win was child.
3791 If win is the root window, it has no parent, and
3792 parent_{x,y} are invalid, but that's okay, because we'll
3793 never use them in that case.) */
3796 /* We don't wan't to know the innermost window. We
3797 want the edit window. */
3798 f1
= x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3800 /* Is win one of our frames? */
3801 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3804 #ifdef USE_X_TOOLKIT
3805 /* If we end up with the menu bar window, say it's not
3808 && f1
->output_data
.x
->menubar_widget
3809 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3811 #endif /* USE_X_TOOLKIT */
3814 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3817 x_uncatch_errors ();
3819 /* If not, is it one of our scroll bars? */
3822 struct scroll_bar
*bar
;
3824 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3828 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3834 if (f1
== 0 && insist
> 0)
3835 f1
= SELECTED_FRAME ();
3839 /* Ok, we found a frame. Store all the values.
3840 last_mouse_glyph is a rectangle used to reduce the
3841 generation of mouse events. To not miss any motion
3842 events, we must divide the frame into rectangles of the
3843 size of the smallest character that could be displayed
3844 on it, i.e. into the same rectangles that matrices on
3845 the frame are divided into. */
3847 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3848 last_mouse_glyph_frame
= f1
;
3853 XSETINT (*x
, win_x
);
3854 XSETINT (*y
, win_y
);
3855 *time
= last_mouse_movement_time
;
3865 /***********************************************************************
3867 ***********************************************************************/
3869 /* Scroll bar support. */
3871 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3873 This can be called in GC, so we have to make sure to strip off mark
3876 static struct scroll_bar
*
3877 x_window_to_scroll_bar (Display
*display
, Window window_id
)
3881 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3882 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
3883 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
3885 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
3887 Lisp_Object frame
, bar
, condemned
;
3889 frame
= XCAR (tail
);
3890 /* All elements of Vframe_list should be frames. */
3891 if (! FRAMEP (frame
))
3894 if (! FRAME_X_P (XFRAME (frame
)))
3897 /* Scan this frame's scroll bar list for a scroll bar with the
3899 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3900 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3901 /* This trick allows us to search both the ordinary and
3902 condemned scroll bar lists with one loop. */
3903 ! NILP (bar
) || (bar
= condemned
,
3906 bar
= XSCROLL_BAR (bar
)->next
)
3907 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
3908 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
3909 return XSCROLL_BAR (bar
);
3916 #if defined USE_LUCID
3918 /* Return the Lucid menu bar WINDOW is part of. Return null
3919 if WINDOW is not part of a menu bar. */
3922 x_window_to_menu_bar (Window window
)
3926 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
3928 if (FRAME_X_P (XFRAME (XCAR (tail
))))
3930 Lisp_Object frame
= XCAR (tail
);
3931 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
3933 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
3941 #endif /* USE_LUCID */
3944 /************************************************************************
3946 ************************************************************************/
3948 #ifdef USE_TOOLKIT_SCROLL_BARS
3950 static void x_scroll_bar_to_input_event (XEvent
*, struct input_event
*);
3951 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
3952 static void x_create_toolkit_scroll_bar (struct frame
*,
3953 struct scroll_bar
*);
3954 static void x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*,
3958 /* Lisp window being scrolled. Set when starting to interact with
3959 a toolkit scroll bar, reset to nil when ending the interaction. */
3961 static Lisp_Object window_being_scrolled
;
3963 /* Last scroll bar part sent in xm_scroll_callback. */
3965 static int last_scroll_bar_part
;
3967 /* Whether this is an Xaw with arrow-scrollbars. This should imply
3968 that movements of 1/20 of the screen size are mapped to up/down. */
3971 /* Id of action hook installed for scroll bars. */
3973 static XtActionHookId action_hook_id
;
3975 static Boolean xaw3d_arrow_scroll
;
3977 /* Whether the drag scrolling maintains the mouse at the top of the
3978 thumb. If not, resizing the thumb needs to be done more carefully
3979 to avoid jerkyness. */
3981 static Boolean xaw3d_pick_top
;
3983 /* Action hook installed via XtAppAddActionHook when toolkit scroll
3984 bars are used.. The hook is responsible for detecting when
3985 the user ends an interaction with the scroll bar, and generates
3986 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
3989 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
3990 XEvent
*event
, String
*params
, Cardinal
*num_params
)
3996 scroll_bar_p
= XmIsScrollBar (widget
);
3997 end_action
= "Release";
3998 #else /* !USE_MOTIF i.e. use Xaw */
3999 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4000 end_action
= "EndScroll";
4001 #endif /* USE_MOTIF */
4004 && strcmp (action_name
, end_action
) == 0
4005 && WINDOWP (window_being_scrolled
))
4009 x_send_scroll_bar_event (window_being_scrolled
,
4010 scroll_bar_end_scroll
, 0, 0);
4011 w
= XWINDOW (window_being_scrolled
);
4013 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4015 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4016 /* The thumb size is incorrect while dragging: fix it. */
4017 set_vertical_scroll_bar (w
);
4019 window_being_scrolled
= Qnil
;
4020 last_scroll_bar_part
= -1;
4022 /* Xt timeouts no longer needed. */
4023 toolkit_scroll_bar_interaction
= 0;
4026 #endif /* not USE_GTK */
4028 /* A vector of windows used for communication between
4029 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4031 static struct window
**scroll_bar_windows
;
4032 static int scroll_bar_windows_size
;
4035 /* Send a client message with message type Xatom_Scrollbar for a
4036 scroll action to the frame of WINDOW. PART is a value identifying
4037 the part of the scroll bar that was clicked on. PORTION is the
4038 amount to scroll of a whole of WHOLE. */
4041 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4044 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4045 struct window
*w
= XWINDOW (window
);
4046 struct frame
*f
= XFRAME (w
->frame
);
4051 /* Construct a ClientMessage event to send to the frame. */
4052 ev
->type
= ClientMessage
;
4053 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4054 ev
->display
= FRAME_X_DISPLAY (f
);
4055 ev
->window
= FRAME_X_WINDOW (f
);
4058 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4059 not enough to store a pointer or Lisp_Object on a 64 bit system.
4060 So, store the window in scroll_bar_windows and pass the index
4061 into that array in the event. */
4062 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4063 if (scroll_bar_windows
[i
] == NULL
)
4066 if (i
== scroll_bar_windows_size
)
4068 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4069 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4070 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4072 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4074 memset (&scroll_bar_windows
[i
], 0, nbytes
- old_nbytes
);
4075 scroll_bar_windows_size
= new_size
;
4078 scroll_bar_windows
[i
] = w
;
4079 ev
->data
.l
[0] = (long) i
;
4080 ev
->data
.l
[1] = (long) part
;
4081 ev
->data
.l
[2] = (long) 0;
4082 ev
->data
.l
[3] = (long) portion
;
4083 ev
->data
.l
[4] = (long) whole
;
4085 /* Make Xt timeouts work while the scroll bar is active. */
4086 toolkit_scroll_bar_interaction
= 1;
4087 #ifdef USE_X_TOOLKIT
4088 x_activate_timeout_atimer ();
4091 /* Setting the event mask to zero means that the message will
4092 be sent to the client that created the window, and if that
4093 window no longer exists, no event will be sent. */
4094 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4099 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4103 x_scroll_bar_to_input_event (XEvent
*event
, struct input_event
*ievent
)
4105 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4110 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4111 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4113 XSETWINDOW (window
, w
);
4114 f
= XFRAME (w
->frame
);
4116 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4117 ievent
->frame_or_window
= window
;
4120 ievent
->timestamp
= CurrentTime
;
4122 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4124 ievent
->part
= ev
->data
.l
[1];
4125 ievent
->code
= ev
->data
.l
[2];
4126 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4127 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4128 ievent
->modifiers
= 0;
4134 /* Minimum and maximum values used for Motif scroll bars. */
4136 #define XM_SB_MAX 10000000
4139 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4140 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4141 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4144 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4146 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4147 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4148 int part
= -1, whole
= 0, portion
= 0;
4152 case XmCR_DECREMENT
:
4153 bar
->dragging
= Qnil
;
4154 part
= scroll_bar_up_arrow
;
4157 case XmCR_INCREMENT
:
4158 bar
->dragging
= Qnil
;
4159 part
= scroll_bar_down_arrow
;
4162 case XmCR_PAGE_DECREMENT
:
4163 bar
->dragging
= Qnil
;
4164 part
= scroll_bar_above_handle
;
4167 case XmCR_PAGE_INCREMENT
:
4168 bar
->dragging
= Qnil
;
4169 part
= scroll_bar_below_handle
;
4173 bar
->dragging
= Qnil
;
4174 part
= scroll_bar_to_top
;
4177 case XmCR_TO_BOTTOM
:
4178 bar
->dragging
= Qnil
;
4179 part
= scroll_bar_to_bottom
;
4186 /* Get the slider size. */
4188 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4191 whole
= XM_SB_MAX
- slider_size
;
4192 portion
= min (cs
->value
, whole
);
4193 part
= scroll_bar_handle
;
4194 bar
->dragging
= make_number (cs
->value
);
4198 case XmCR_VALUE_CHANGED
:
4204 window_being_scrolled
= bar
->window
;
4205 last_scroll_bar_part
= part
;
4206 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4210 #elif defined USE_GTK
4212 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4213 bar widget. DATA is a pointer to the scroll_bar structure. */
4216 xg_scroll_callback (GtkRange
*range
,
4217 GtkScrollType scroll
,
4221 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4223 int part
= -1, whole
= 0, portion
= 0;
4224 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4225 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4227 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4228 position
= gtk_adjustment_get_value (adj
);
4233 case GTK_SCROLL_JUMP
:
4234 /* Buttons 1 2 or 3 must be grabbed. */
4235 if (FRAME_X_DISPLAY_INFO (f
)->grabbed
!= 0
4236 && FRAME_X_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4238 part
= scroll_bar_handle
;
4239 whole
= gtk_adjustment_get_upper (adj
) -
4240 gtk_adjustment_get_page_size (adj
);
4241 portion
= min ((int)position
, whole
);
4242 bar
->dragging
= make_number ((int)portion
);
4245 case GTK_SCROLL_STEP_BACKWARD
:
4246 part
= scroll_bar_up_arrow
;
4247 bar
->dragging
= Qnil
;
4249 case GTK_SCROLL_STEP_FORWARD
:
4250 part
= scroll_bar_down_arrow
;
4251 bar
->dragging
= Qnil
;
4253 case GTK_SCROLL_PAGE_BACKWARD
:
4254 part
= scroll_bar_above_handle
;
4255 bar
->dragging
= Qnil
;
4257 case GTK_SCROLL_PAGE_FORWARD
:
4258 part
= scroll_bar_below_handle
;
4259 bar
->dragging
= Qnil
;
4265 window_being_scrolled
= bar
->window
;
4266 last_scroll_bar_part
= part
;
4267 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4273 /* Callback for button release. Sets dragging to Qnil when dragging is done. */
4276 xg_end_scroll_callback (GtkWidget
*widget
,
4277 GdkEventButton
*event
,
4280 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4281 bar
->dragging
= Qnil
;
4282 if (WINDOWP (window_being_scrolled
))
4284 x_send_scroll_bar_event (window_being_scrolled
,
4285 scroll_bar_end_scroll
, 0, 0);
4286 window_being_scrolled
= Qnil
;
4293 #else /* not USE_GTK and not USE_MOTIF */
4295 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4296 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4297 scroll bar struct. CALL_DATA is a pointer to a float saying where
4301 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4303 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4304 float top
= *(float *) call_data
;
4306 int whole
, portion
, height
;
4309 /* Get the size of the thumb, a value between 0 and 1. */
4311 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4315 portion
= shown
< 1 ? top
* whole
: 0;
4317 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4318 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4319 the bottom, so we force the scrolling whenever we see that we're
4320 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4321 we try to ensure that we always stay two pixels away from the
4323 part
= scroll_bar_down_arrow
;
4325 part
= scroll_bar_handle
;
4327 window_being_scrolled
= bar
->window
;
4328 bar
->dragging
= make_number (portion
);
4329 last_scroll_bar_part
= part
;
4330 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4334 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4335 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4336 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4337 the scroll bar. CALL_DATA is an integer specifying the action that
4338 has taken place. Its magnitude is in the range 0..height of the
4339 scroll bar. Negative values mean scroll towards buffer start.
4340 Values < height of scroll bar mean line-wise movement. */
4343 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4345 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4346 /* The position really is stored cast to a pointer. */
4347 int position
= (long) call_data
;
4351 /* Get the height of the scroll bar. */
4353 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4356 if (eabs (position
) >= height
)
4357 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4359 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4360 it maps line-movement to call_data = max(5, height/20). */
4361 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4362 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4364 part
= scroll_bar_move_ratio
;
4366 window_being_scrolled
= bar
->window
;
4367 bar
->dragging
= Qnil
;
4368 last_scroll_bar_part
= part
;
4369 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4372 #endif /* not USE_GTK and not USE_MOTIF */
4374 #define SCROLL_BAR_NAME "verticalScrollBar"
4376 /* Create the widget for scroll bar BAR on frame F. Record the widget
4377 and X window of the scroll bar in BAR. */
4381 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4383 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4386 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4387 G_CALLBACK (xg_end_scroll_callback
),
4392 #else /* not USE_GTK */
4395 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4401 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4402 unsigned long pixel
;
4407 /* Set resources. Create the widget. */
4408 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4409 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4410 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4411 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4412 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4413 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4414 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4416 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4419 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4423 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4426 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4430 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4431 scroll_bar_name
, av
, ac
);
4433 /* Add one callback for everything that can happen. */
4434 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4436 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4438 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4440 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4442 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4444 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4446 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4449 /* Realize the widget. Only after that is the X window created. */
4450 XtRealizeWidget (widget
);
4452 /* Set the cursor to an arrow. I didn't find a resource to do that.
4453 And I'm wondering why it hasn't an arrow cursor by default. */
4454 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4455 f
->output_data
.x
->nontext_cursor
);
4457 #else /* !USE_MOTIF i.e. use Xaw */
4459 /* Set resources. Create the widget. The background of the
4460 Xaw3d scroll bar widget is a little bit light for my taste.
4461 We don't alter it here to let users change it according
4462 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4463 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4464 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4465 /* For smoother scrolling with Xaw3d -sm */
4466 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4468 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4471 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4475 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4478 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4482 /* Top/bottom shadow colors. */
4484 /* Allocate them, if necessary. */
4485 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4487 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4490 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4491 FRAME_X_COLORMAP (f
),
4492 &pixel
, 1.2, 0x8000))
4494 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4497 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4499 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4502 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4503 FRAME_X_COLORMAP (f
),
4504 &pixel
, 0.6, 0x4000))
4506 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4510 #ifdef XtNbeNiceToColormap
4511 /* Tell the toolkit about them. */
4512 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4513 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4514 /* We tried to allocate a color for the top/bottom shadow, and
4515 failed, so tell Xaw3d to use dithering instead. */
4516 /* But only if we have a small colormap. Xaw3d can allocate nice
4519 XtSetArg (av
[ac
], XtNbeNiceToColormap
,
4520 DefaultDepthOfScreen (FRAME_X_SCREEN (f
)) < 16);
4524 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4525 be more consistent with other emacs 3d colors, and since Xaw3d is
4526 not good at dealing with allocation failure. */
4528 /* This tells Xaw3d to use real colors instead of dithering for
4530 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4533 /* Specify the colors. */
4534 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4537 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4540 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4543 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4549 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4550 f
->output_data
.x
->edit_widget
, av
, ac
);
4554 char *val
= initial
;
4555 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4556 #ifdef XtNarrowScrollbars
4557 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4559 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4560 if (xaw3d_arrow_scroll
|| val
== initial
)
4561 { /* ARROW_SCROLL */
4562 xaw3d_arrow_scroll
= True
;
4563 /* Isn't that just a personal preference ? --Stef */
4564 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4568 /* Define callbacks. */
4569 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4570 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4573 /* Realize the widget. Only after that is the X window created. */
4574 XtRealizeWidget (widget
);
4576 #endif /* !USE_MOTIF */
4578 /* Install an action hook that lets us detect when the user
4579 finishes interacting with a scroll bar. */
4580 if (action_hook_id
== 0)
4581 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4583 /* Remember X window and widget in the scroll bar vector. */
4584 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4585 xwindow
= XtWindow (widget
);
4586 bar
->x_window
= xwindow
;
4590 #endif /* not USE_GTK */
4593 /* Set the thumb size and position of scroll bar BAR. We are currently
4594 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4598 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4600 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4603 #else /* not USE_GTK */
4605 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4608 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4609 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4616 /* We use an estimate of 30 chars per line rather than the real
4617 `portion' value. This has the disadvantage that the thumb size
4618 is not very representative, but it makes our life a lot easier.
4619 Otherwise, we have to constantly adjust the thumb size, which
4620 we can't always do quickly enough: while dragging, the size of
4621 the thumb might prevent the user from dragging the thumb all the
4622 way to the end. but Motif and some versions of Xaw3d don't allow
4623 updating the thumb size while dragging. Also, even if we can update
4624 its size, the update will often happen too late.
4625 If you don't believe it, check out revision 1.650 of xterm.c to see
4626 what hoops we were going through and the still poor behavior we got. */
4627 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4628 /* When the thumb is at the bottom, position == whole.
4629 So we need to increase `whole' to make space for the thumb. */
4636 top
= (float) position
/ whole
;
4637 shown
= (float) portion
/ whole
;
4640 if (NILP (bar
->dragging
))
4644 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4645 is the scroll bar's maximum and MIN is the scroll bar's minimum
4647 size
= shown
* XM_SB_MAX
;
4648 size
= min (size
, XM_SB_MAX
);
4649 size
= max (size
, 1);
4651 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4652 value
= top
* XM_SB_MAX
;
4653 value
= min (value
, XM_SB_MAX
- size
);
4655 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4657 #else /* !USE_MOTIF i.e. use Xaw */
4663 top
= (float) position
/ whole
;
4664 shown
= (float) portion
/ whole
;
4668 float old_top
, old_shown
;
4670 XtVaGetValues (widget
,
4671 XtNtopOfThumb
, &old_top
,
4672 XtNshown
, &old_shown
,
4676 /* Massage the top+shown values. */
4677 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4678 top
= max (0, min (1, top
));
4681 /* Keep two pixels available for moving the thumb down. */
4682 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4684 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4685 check that your system's configuration file contains a define
4686 for `NARROWPROTO'. See s/freebsd.h for an example. */
4687 if (top
!= old_top
|| shown
!= old_shown
)
4689 if (NILP (bar
->dragging
))
4690 XawScrollbarSetThumb (widget
, top
, shown
);
4693 /* Try to make the scrolling a tad smoother. */
4694 if (!xaw3d_pick_top
)
4695 shown
= min (shown
, old_shown
);
4697 XawScrollbarSetThumb (widget
, top
, shown
);
4701 #endif /* !USE_MOTIF */
4705 #endif /* not USE_GTK */
4707 #endif /* USE_TOOLKIT_SCROLL_BARS */
4711 /************************************************************************
4712 Scroll bars, general
4713 ************************************************************************/
4715 /* Create a scroll bar and return the scroll bar vector for it. W is
4716 the Emacs window on which to create the scroll bar. TOP, LEFT,
4717 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4720 static struct scroll_bar
*
4721 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
4723 struct frame
*f
= XFRAME (w
->frame
);
4724 struct scroll_bar
*bar
4725 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4729 #ifdef USE_TOOLKIT_SCROLL_BARS
4730 x_create_toolkit_scroll_bar (f
, bar
);
4731 #else /* not USE_TOOLKIT_SCROLL_BARS */
4733 XSetWindowAttributes a
;
4737 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4738 if (a
.background_pixel
== -1)
4739 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4741 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4742 | ButtonMotionMask
| PointerMotionHintMask
4744 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4746 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4748 /* Clear the area of W that will serve as a scroll bar. This is
4749 for the case that a window has been split horizontally. In
4750 this case, no clear_frame is generated to reduce flickering. */
4751 if (width
> 0 && height
> 0)
4752 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4754 window_box_height (w
), False
);
4756 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4757 /* Position and size of scroll bar. */
4758 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4760 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4762 /* Border width, depth, class, and visual. */
4769 bar
->x_window
= window
;
4771 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4773 XSETWINDOW (bar
->window
, w
);
4777 bar
->height
= height
;
4780 bar
->dragging
= Qnil
;
4781 bar
->fringe_extended_p
= 0;
4783 /* Add bar to its frame's list of scroll bars. */
4784 bar
->next
= FRAME_SCROLL_BARS (f
);
4786 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4787 if (!NILP (bar
->next
))
4788 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4790 /* Map the window/widget. */
4791 #ifdef USE_TOOLKIT_SCROLL_BARS
4794 xg_update_scrollbar_pos (f
,
4797 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4798 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4800 #else /* not USE_GTK */
4801 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4802 XtConfigureWidget (scroll_bar
,
4803 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4805 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4806 max (height
, 1), 0);
4807 XtMapWidget (scroll_bar
);
4808 #endif /* not USE_GTK */
4810 #else /* not USE_TOOLKIT_SCROLL_BARS */
4811 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
4812 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4819 #ifndef USE_TOOLKIT_SCROLL_BARS
4821 /* Draw BAR's handle in the proper position.
4823 If the handle is already drawn from START to END, don't bother
4824 redrawing it, unless REBUILD is non-zero; in that case, always
4825 redraw it. (REBUILD is handy for drawing the handle after expose
4828 Normally, we want to constrain the start and end of the handle to
4829 fit inside its rectangle, but if the user is dragging the scroll
4830 bar handle, we want to let them drag it down all the way, so that
4831 the bar's top is as far down as it goes; otherwise, there's no way
4832 to move to the very end of the buffer. */
4835 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
4837 int dragging
= ! NILP (bar
->dragging
);
4838 Window w
= bar
->x_window
;
4839 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4840 GC gc
= f
->output_data
.x
->normal_gc
;
4842 /* If the display is already accurate, do nothing. */
4844 && start
== bar
->start
4851 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
4852 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
4853 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4855 /* Make sure the values are reasonable, and try to preserve
4856 the distance between start and end. */
4858 int length
= end
- start
;
4862 else if (start
> top_range
)
4864 end
= start
+ length
;
4868 else if (end
> top_range
&& ! dragging
)
4872 /* Store the adjusted setting in the scroll bar. */
4876 /* Clip the end position, just for display. */
4877 if (end
> top_range
)
4880 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4881 below top positions, to make sure the handle is always at least
4882 that many pixels tall. */
4883 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4885 /* Draw the empty space above the handle. Note that we can't clear
4886 zero-height areas; that means "clear to end of window." */
4888 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4889 /* x, y, width, height, and exposures. */
4890 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4891 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4892 inside_width
, start
,
4895 /* Change to proper foreground color if one is specified. */
4896 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4897 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4898 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4900 /* Draw the handle itself. */
4901 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4902 /* x, y, width, height */
4903 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4904 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4905 inside_width
, end
- start
);
4907 /* Restore the foreground color of the GC if we changed it above. */
4908 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4909 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4910 FRAME_FOREGROUND_PIXEL (f
));
4912 /* Draw the empty space below the handle. Note that we can't
4913 clear zero-height areas; that means "clear to end of window." */
4914 if (end
< inside_height
)
4915 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4916 /* x, y, width, height, and exposures. */
4917 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4918 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4919 inside_width
, inside_height
- end
,
4927 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4929 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4933 x_scroll_bar_remove (struct scroll_bar
*bar
)
4935 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4938 #ifdef USE_TOOLKIT_SCROLL_BARS
4940 xg_remove_scroll_bar (f
, bar
->x_window
);
4941 #else /* not USE_GTK */
4942 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4943 #endif /* not USE_GTK */
4945 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
4948 /* Disassociate this scroll bar from its window. */
4949 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4955 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4956 that we are displaying PORTION characters out of a total of WHOLE
4957 characters, starting at POSITION. If WINDOW has no scroll bar,
4961 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
4963 struct frame
*f
= XFRAME (w
->frame
);
4964 struct scroll_bar
*bar
;
4965 int top
, height
, left
, sb_left
, width
, sb_width
;
4966 int window_y
, window_height
;
4967 #ifdef USE_TOOLKIT_SCROLL_BARS
4968 int fringe_extended_p
;
4971 /* Get window dimensions. */
4972 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4974 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4975 height
= window_height
;
4977 /* Compute the left edge of the scroll bar area. */
4978 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4980 /* Compute the width of the scroll bar which might be less than
4981 the width of the area reserved for the scroll bar. */
4982 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4983 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
4987 /* Compute the left edge of the scroll bar. */
4988 #ifdef USE_TOOLKIT_SCROLL_BARS
4989 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4990 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
4992 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
4994 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
4995 sb_left
= left
+ width
- sb_width
;
5000 #ifdef USE_TOOLKIT_SCROLL_BARS
5001 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5002 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5003 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5004 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5005 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5007 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5008 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5009 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5010 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5013 /* Does the scroll bar exist yet? */
5014 if (NILP (w
->vertical_scroll_bar
))
5016 if (width
> 0 && height
> 0)
5019 #ifdef USE_TOOLKIT_SCROLL_BARS
5020 if (fringe_extended_p
)
5021 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5022 sb_left
, top
, sb_width
, height
, False
);
5025 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5026 left
, top
, width
, height
, False
);
5030 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5034 /* It may just need to be moved and resized. */
5035 unsigned int mask
= 0;
5037 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5041 if (sb_left
!= bar
->left
)
5043 if (top
!= bar
->top
)
5045 if (sb_width
!= bar
->width
)
5047 if (height
!= bar
->height
)
5050 #ifdef USE_TOOLKIT_SCROLL_BARS
5052 /* Move/size the scroll bar widget. */
5053 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5055 /* Since toolkit scroll bars are smaller than the space reserved
5056 for them on the frame, we have to clear "under" them. */
5057 if (width
> 0 && height
> 0)
5059 if (fringe_extended_p
)
5060 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5061 sb_left
, top
, sb_width
, height
, False
);
5063 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5064 left
, top
, width
, height
, False
);
5067 xg_update_scrollbar_pos (f
,
5070 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5071 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5073 #else /* not USE_GTK */
5074 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5075 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5077 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5078 max (height
, 1), 0);
5079 #endif /* not USE_GTK */
5081 #else /* not USE_TOOLKIT_SCROLL_BARS */
5083 /* Clear areas not covered by the scroll bar because of
5084 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5085 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5087 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5088 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5090 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5091 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5092 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5096 /* Clear areas not covered by the scroll bar because it's not as
5097 wide as the area reserved for it. This makes sure a
5098 previous mode line display is cleared after C-x 2 C-x 1, for
5101 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5102 int rest
= area_width
- sb_width
;
5103 if (rest
> 0 && height
> 0)
5105 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5106 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5107 left
+ area_width
- rest
, top
,
5108 rest
, height
, False
);
5110 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5111 left
, top
, rest
, height
, False
);
5115 /* Move/size the scroll bar window. */
5120 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5122 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5124 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5128 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5130 /* Remember new settings. */
5131 bar
->left
= sb_left
;
5133 bar
->width
= sb_width
;
5134 bar
->height
= height
;
5139 #ifdef USE_TOOLKIT_SCROLL_BARS
5140 bar
->fringe_extended_p
= fringe_extended_p
;
5142 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5143 #else /* not USE_TOOLKIT_SCROLL_BARS */
5144 /* Set the scroll bar's current state, unless we're currently being
5146 if (NILP (bar
->dragging
))
5148 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5151 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5154 int start
= ((double) position
* top_range
) / whole
;
5155 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5156 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5159 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5161 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5165 /* The following three hooks are used when we're doing a thorough
5166 redisplay of the frame. We don't explicitly know which scroll bars
5167 are going to be deleted, because keeping track of when windows go
5168 away is a real pain - "Can you say set-window-configuration, boys
5169 and girls?" Instead, we just assert at the beginning of redisplay
5170 that *all* scroll bars are to be removed, and then save a scroll bar
5171 from the fiery pit when we actually redisplay its window. */
5173 /* Arrange for all scroll bars on FRAME to be removed at the next call
5174 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5175 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5178 XTcondemn_scroll_bars (FRAME_PTR frame
)
5180 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5181 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5184 bar
= FRAME_SCROLL_BARS (frame
);
5185 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5186 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5187 XSCROLL_BAR (bar
)->prev
= Qnil
;
5188 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5189 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5190 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5195 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5196 Note that WINDOW isn't necessarily condemned at all. */
5199 XTredeem_scroll_bar (struct window
*window
)
5201 struct scroll_bar
*bar
;
5204 /* We can't redeem this window's scroll bar if it doesn't have one. */
5205 if (NILP (window
->vertical_scroll_bar
))
5208 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5210 /* Unlink it from the condemned list. */
5211 f
= XFRAME (WINDOW_FRAME (window
));
5212 if (NILP (bar
->prev
))
5214 /* If the prev pointer is nil, it must be the first in one of
5216 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5217 /* It's not condemned. Everything's fine. */
5219 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5220 window
->vertical_scroll_bar
))
5221 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5223 /* If its prev pointer is nil, it must be at the front of
5224 one or the other! */
5228 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5230 if (! NILP (bar
->next
))
5231 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5233 bar
->next
= FRAME_SCROLL_BARS (f
);
5235 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5236 if (! NILP (bar
->next
))
5237 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5240 /* Remove all scroll bars on FRAME that haven't been saved since the
5241 last call to `*condemn_scroll_bars_hook'. */
5244 XTjudge_scroll_bars (FRAME_PTR f
)
5246 Lisp_Object bar
, next
;
5248 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5250 /* Clear out the condemned list now so we won't try to process any
5251 more events on the hapless scroll bars. */
5252 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5254 for (; ! NILP (bar
); bar
= next
)
5256 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5258 x_scroll_bar_remove (b
);
5261 b
->next
= b
->prev
= Qnil
;
5264 /* Now there should be no references to the condemned scroll bars,
5265 and they should get garbage-collected. */
5269 #ifndef USE_TOOLKIT_SCROLL_BARS
5270 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5271 is a no-op when using toolkit scroll bars.
5273 This may be called from a signal handler, so we have to ignore GC
5277 x_scroll_bar_expose (struct scroll_bar
*bar
, XEvent
*event
)
5279 Window w
= bar
->x_window
;
5280 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5281 GC gc
= f
->output_data
.x
->normal_gc
;
5282 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5286 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5288 /* Switch to scroll bar foreground color. */
5289 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5290 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5291 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5293 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5294 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5296 /* x, y, width, height */
5298 bar
->width
- 1 - width_trim
- width_trim
,
5301 /* Restore the foreground color of the GC if we changed it above. */
5302 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5303 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5304 FRAME_FOREGROUND_PIXEL (f
));
5309 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5311 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5312 is set to something other than NO_EVENT, it is enqueued.
5314 This may be called from a signal handler, so we have to ignore GC
5319 x_scroll_bar_handle_click (struct scroll_bar
*bar
, XEvent
*event
, struct input_event
*emacs_event
)
5321 if (! WINDOWP (bar
->window
))
5324 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5325 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5326 emacs_event
->modifiers
5327 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5328 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5329 event
->xbutton
.state
)
5330 | (event
->type
== ButtonRelease
5333 emacs_event
->frame_or_window
= bar
->window
;
5334 emacs_event
->arg
= Qnil
;
5335 emacs_event
->timestamp
= event
->xbutton
.time
;
5338 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5339 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5342 if (y
> top_range
) y
= top_range
;
5345 emacs_event
->part
= scroll_bar_above_handle
;
5346 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5347 emacs_event
->part
= scroll_bar_handle
;
5349 emacs_event
->part
= scroll_bar_below_handle
;
5351 #ifndef USE_TOOLKIT_SCROLL_BARS
5352 /* If the user has released the handle, set it to its final position. */
5353 if (event
->type
== ButtonRelease
5354 && ! NILP (bar
->dragging
))
5356 int new_start
= y
- XINT (bar
->dragging
);
5357 int new_end
= new_start
+ bar
->end
- bar
->start
;
5359 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5360 bar
->dragging
= Qnil
;
5364 XSETINT (emacs_event
->x
, y
);
5365 XSETINT (emacs_event
->y
, top_range
);
5369 #ifndef USE_TOOLKIT_SCROLL_BARS
5371 /* Handle some mouse motion while someone is dragging the scroll bar.
5373 This may be called from a signal handler, so we have to ignore GC
5377 x_scroll_bar_note_movement (struct scroll_bar
*bar
, XEvent
*event
)
5379 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5381 last_mouse_movement_time
= event
->xmotion
.time
;
5384 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5386 /* If we're dragging the bar, display it. */
5387 if (! NILP (bar
->dragging
))
5389 /* Where should the handle be now? */
5390 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5392 if (new_start
!= bar
->start
)
5394 int new_end
= new_start
+ bar
->end
- bar
->start
;
5396 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5401 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5403 /* Return information to the user about the current position of the mouse
5404 on the scroll bar. */
5407 x_scroll_bar_report_motion (FRAME_PTR
*fp
, Lisp_Object
*bar_window
, enum scroll_bar_part
*part
, Lisp_Object
*x
, Lisp_Object
*y
, long unsigned int *time
)
5409 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5410 Window w
= bar
->x_window
;
5411 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5413 Window dummy_window
;
5415 unsigned int dummy_mask
;
5419 /* Get the mouse's position relative to the scroll bar window, and
5421 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5423 /* Root, child, root x and root y. */
5424 &dummy_window
, &dummy_window
,
5425 &dummy_coord
, &dummy_coord
,
5427 /* Position relative to scroll bar. */
5430 /* Mouse buttons and modifier keys. */
5436 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5438 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5440 if (! NILP (bar
->dragging
))
5441 win_y
-= XINT (bar
->dragging
);
5445 if (win_y
> top_range
)
5449 *bar_window
= bar
->window
;
5451 if (! NILP (bar
->dragging
))
5452 *part
= scroll_bar_handle
;
5453 else if (win_y
< bar
->start
)
5454 *part
= scroll_bar_above_handle
;
5455 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5456 *part
= scroll_bar_handle
;
5458 *part
= scroll_bar_below_handle
;
5460 XSETINT (*x
, win_y
);
5461 XSETINT (*y
, top_range
);
5464 last_mouse_scroll_bar
= Qnil
;
5467 *time
= last_mouse_movement_time
;
5473 /* The screen has been cleared so we may have changed foreground or
5474 background colors, and the scroll bars may need to be redrawn.
5475 Clear out the scroll bars, and ask for expose events, so we can
5479 x_scroll_bar_clear (FRAME_PTR f
)
5481 #ifndef USE_TOOLKIT_SCROLL_BARS
5484 /* We can have scroll bars even if this is 0,
5485 if we just turned off scroll bar mode.
5486 But in that case we should not clear them. */
5487 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5488 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5489 bar
= XSCROLL_BAR (bar
)->next
)
5490 XClearArea (FRAME_X_DISPLAY (f
),
5491 XSCROLL_BAR (bar
)->x_window
,
5493 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5497 /* The main X event-reading loop - XTread_socket. */
5499 /* This holds the state XLookupString needs to implement dead keys
5500 and other tricks known as "compose processing". _X Window System_
5501 says that a portable program can't use this, but Stephen Gildea assures
5502 me that letting the compiler initialize it to zeros will work okay.
5504 This must be defined outside of XTread_socket, for the same reasons
5505 given for enter_timestamp, above. */
5507 static XComposeStatus compose_status
;
5509 /* Record the last 100 characters stored
5510 to help debug the loss-of-chars-during-GC problem. */
5512 static int temp_index
;
5513 static short temp_buffer
[100];
5515 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5516 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5518 temp_buffer[temp_index++] = (keysym)
5520 /* Set this to nonzero to fake an "X I/O error"
5521 on a particular display. */
5523 struct x_display_info
*XTread_socket_fake_io_error
;
5525 /* When we find no input here, we occasionally do a no-op command
5526 to verify that the X server is still running and we can still talk with it.
5527 We try all the open displays, one by one.
5528 This variable is used for cycling thru the displays. */
5530 static struct x_display_info
*next_noop_dpyinfo
;
5532 #define SET_SAVED_BUTTON_EVENT \
5535 if (f->output_data.x->saved_menu_event == 0) \
5536 f->output_data.x->saved_menu_event \
5537 = (XEvent *) xmalloc (sizeof (XEvent)); \
5538 *f->output_data.x->saved_menu_event = event; \
5539 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5540 XSETFRAME (inev.ie.frame_or_window, f); \
5551 /* Filter events for the current X input method.
5552 DPYINFO is the display this event is for.
5553 EVENT is the X event to filter.
5555 Returns non-zero if the event was filtered, caller shall not process
5557 Returns zero if event is wasn't filtered. */
5561 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5563 /* XFilterEvent returns non-zero if the input method has
5564 consumed the event. We pass the frame's X window to
5565 XFilterEvent because that's the one for which the IC
5568 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5569 event
->xclient
.window
);
5571 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5576 static int current_count
;
5577 static int current_finish
;
5578 static struct input_event
*current_hold_quit
;
5580 /* This is the filter function invoked by the GTK event loop.
5581 It is invoked before the XEvent is translated to a GdkEvent,
5582 so we have a chance to act on the event before GTK. */
5583 static GdkFilterReturn
5584 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5586 XEvent
*xev
= (XEvent
*) gxev
;
5589 if (current_count
>= 0)
5591 struct x_display_info
*dpyinfo
;
5593 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5596 /* Filter events for the current X input method.
5597 GTK calls XFilterEvent but not for key press and release,
5598 so we do it here. */
5599 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5601 && x_filter_event (dpyinfo
, xev
))
5604 return GDK_FILTER_REMOVE
;
5609 current_finish
= X_EVENT_NORMAL
;
5612 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5616 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5620 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5621 return GDK_FILTER_REMOVE
;
5623 return GDK_FILTER_CONTINUE
;
5625 #endif /* USE_GTK */
5628 /* Handles the XEvent EVENT on display DPYINFO.
5630 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5631 *FINISH is zero if caller should continue reading events.
5632 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5634 We return the number of characters stored into the buffer. */
5637 handle_one_xevent (struct x_display_info
*dpyinfo
, XEvent
*eventp
, int *finish
, struct input_event
*hold_quit
)
5640 struct input_event ie
;
5641 struct selection_input_event sie
;
5646 struct frame
*f
= NULL
;
5647 struct coding_system coding
;
5648 XEvent event
= *eventp
;
5650 *finish
= X_EVENT_NORMAL
;
5652 EVENT_INIT (inev
.ie
);
5653 inev
.ie
.kind
= NO_EVENT
;
5656 if (pending_event_wait
.eventtype
== event
.type
)
5657 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5663 if (event
.xclient
.message_type
5664 == dpyinfo
->Xatom_wm_protocols
5665 && event
.xclient
.format
== 32)
5667 if (event
.xclient
.data
.l
[0]
5668 == dpyinfo
->Xatom_wm_take_focus
)
5670 /* Use x_any_window_to_frame because this
5671 could be the shell widget window
5672 if the frame has no title bar. */
5673 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5675 /* Not quite sure this is needed -pd */
5676 if (f
&& FRAME_XIC (f
))
5677 XSetICFocus (FRAME_XIC (f
));
5679 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5680 instructs the WM to set the input focus automatically for
5681 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5682 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5683 it has set the focus. So, XSetInputFocus below is not
5686 The call to XSetInputFocus below has also caused trouble. In
5687 cases where the XSetInputFocus done by the WM and the one
5688 below are temporally close (on a fast machine), the call
5689 below can generate additional FocusIn events which confuse
5692 /* Since we set WM_TAKE_FOCUS, we must call
5693 XSetInputFocus explicitly. But not if f is null,
5694 since that might be an event for a deleted frame. */
5697 Display
*d
= event
.xclient
.display
;
5698 /* Catch and ignore errors, in case window has been
5699 iconified by a window manager such as GWM. */
5701 XSetInputFocus (d
, event
.xclient
.window
,
5702 /* The ICCCM says this is
5703 the only valid choice. */
5705 event
.xclient
.data
.l
[1]);
5706 /* This is needed to detect the error
5707 if there is an error. */
5709 x_uncatch_errors ();
5711 /* Not certain about handling scroll bars here */
5716 if (event
.xclient
.data
.l
[0]
5717 == dpyinfo
->Xatom_wm_save_yourself
)
5719 /* Save state modify the WM_COMMAND property to
5720 something which can reinstate us. This notifies
5721 the session manager, who's looking for such a
5722 PropertyNotify. Can restart processing when
5723 a keyboard or mouse event arrives. */
5724 /* If we have a session manager, don't set this.
5725 KDE will then start two Emacsen, one for the
5726 session manager and one for this. */
5728 if (! x_session_have_connection ())
5731 f
= x_top_window_to_frame (dpyinfo
,
5732 event
.xclient
.window
);
5733 /* This is just so we only give real data once
5734 for a single Emacs process. */
5735 if (f
== SELECTED_FRAME ())
5736 XSetCommand (FRAME_X_DISPLAY (f
),
5737 event
.xclient
.window
,
5738 initial_argv
, initial_argc
);
5740 XSetCommand (FRAME_X_DISPLAY (f
),
5741 event
.xclient
.window
,
5747 if (event
.xclient
.data
.l
[0]
5748 == dpyinfo
->Xatom_wm_delete_window
)
5750 f
= x_any_window_to_frame (dpyinfo
,
5751 event
.xclient
.window
);
5753 goto OTHER
; /* May be a dialog that is to be removed */
5755 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5756 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5763 if (event
.xclient
.message_type
5764 == dpyinfo
->Xatom_wm_configure_denied
)
5769 if (event
.xclient
.message_type
5770 == dpyinfo
->Xatom_wm_window_moved
)
5773 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5775 new_x
= event
.xclient
.data
.s
[0];
5776 new_y
= event
.xclient
.data
.s
[1];
5780 f
->left_pos
= new_x
;
5787 if (event
.xclient
.message_type
5788 == dpyinfo
->Xatom_editres
)
5790 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5792 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5796 #endif /* HACK_EDITRES */
5798 if ((event
.xclient
.message_type
5799 == dpyinfo
->Xatom_DONE
)
5800 || (event
.xclient
.message_type
5801 == dpyinfo
->Xatom_PAGE
))
5803 /* Ghostview job completed. Kill it. We could
5804 reply with "Next" if we received "Page", but we
5805 currently never do because we are interested in
5806 images, only, which should have 1 page. */
5807 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5808 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5811 x_kill_gs_process (pixmap
, f
);
5812 expose_frame (f
, 0, 0, 0, 0);
5816 #ifdef USE_TOOLKIT_SCROLL_BARS
5817 /* Scroll bar callbacks send a ClientMessage from which
5818 we construct an input_event. */
5819 if (event
.xclient
.message_type
5820 == dpyinfo
->Xatom_Scrollbar
)
5822 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
5823 *finish
= X_EVENT_GOTO_OUT
;
5826 #endif /* USE_TOOLKIT_SCROLL_BARS */
5828 /* XEmbed messages from the embedder (if any). */
5829 if (event
.xclient
.message_type
5830 == dpyinfo
->Xatom_XEMBED
)
5832 enum xembed_message msg
= event
.xclient
.data
.l
[1];
5833 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
5834 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
5836 *finish
= X_EVENT_GOTO_OUT
;
5840 xft_settings_event (dpyinfo
, &event
);
5842 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5845 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
5846 *finish
= X_EVENT_DROP
;
5850 case SelectionNotify
:
5851 last_user_time
= event
.xselection
.time
;
5852 #ifdef USE_X_TOOLKIT
5853 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5855 #endif /* not USE_X_TOOLKIT */
5856 x_handle_selection_notify (&event
.xselection
);
5859 case SelectionClear
: /* Someone has grabbed ownership. */
5860 last_user_time
= event
.xselectionclear
.time
;
5861 #ifdef USE_X_TOOLKIT
5862 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5864 #endif /* USE_X_TOOLKIT */
5866 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5868 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
5869 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5870 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5871 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5872 inev
.ie
.frame_or_window
= Qnil
;
5876 case SelectionRequest
: /* Someone wants our selection. */
5877 last_user_time
= event
.xselectionrequest
.time
;
5878 #ifdef USE_X_TOOLKIT
5879 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5881 #endif /* USE_X_TOOLKIT */
5883 XSelectionRequestEvent
*eventp
5884 = (XSelectionRequestEvent
*) &event
;
5886 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
5887 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5888 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
5889 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5890 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
5891 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
5892 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5893 inev
.ie
.frame_or_window
= Qnil
;
5897 case PropertyNotify
:
5898 last_user_time
= event
.xproperty
.time
;
5899 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
5900 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
5901 x_handle_net_wm_state (f
, &event
.xproperty
);
5903 x_handle_property_notify (&event
.xproperty
);
5904 xft_settings_event (dpyinfo
, &event
);
5907 case ReparentNotify
:
5908 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
5912 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
5913 x_real_positions (f
, &x
, &y
);
5917 /* Perhaps reparented due to a WM restart. Reset this. */
5918 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
5919 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
5924 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
5928 /* This seems to be needed for GTK 2.6. */
5929 x_clear_area (event
.xexpose
.display
,
5930 event
.xexpose
.window
,
5931 event
.xexpose
.x
, event
.xexpose
.y
,
5932 event
.xexpose
.width
, event
.xexpose
.height
,
5935 if (f
->async_visible
== 0)
5937 f
->async_visible
= 1;
5938 f
->async_iconified
= 0;
5939 f
->output_data
.x
->has_been_visible
= 1;
5940 SET_FRAME_GARBAGED (f
);
5944 event
.xexpose
.x
, event
.xexpose
.y
,
5945 event
.xexpose
.width
, event
.xexpose
.height
);
5949 #ifndef USE_TOOLKIT_SCROLL_BARS
5950 struct scroll_bar
*bar
;
5952 #if defined USE_LUCID
5953 /* Submenus of the Lucid menu bar aren't widgets
5954 themselves, so there's no way to dispatch events
5955 to them. Recognize this case separately. */
5958 = x_window_to_menu_bar (event
.xexpose
.window
);
5960 xlwmenu_redisplay (widget
);
5962 #endif /* USE_LUCID */
5964 #ifdef USE_TOOLKIT_SCROLL_BARS
5965 /* Dispatch event to the widget. */
5967 #else /* not USE_TOOLKIT_SCROLL_BARS */
5968 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
5969 event
.xexpose
.window
);
5972 x_scroll_bar_expose (bar
, &event
);
5973 #ifdef USE_X_TOOLKIT
5976 #endif /* USE_X_TOOLKIT */
5977 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5981 case GraphicsExpose
: /* This occurs when an XCopyArea's
5982 source area was obscured or not
5984 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
5988 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
5989 event
.xgraphicsexpose
.width
,
5990 event
.xgraphicsexpose
.height
);
5992 #ifdef USE_X_TOOLKIT
5995 #endif /* USE_X_TOOLKIT */
5998 case NoExpose
: /* This occurs when an XCopyArea's
5999 source area was completely
6004 /* Redo the mouse-highlight after the tooltip has gone. */
6005 if (event
.xmap
.window
== tip_window
)
6008 redo_mouse_highlight ();
6011 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6012 if (f
) /* F may no longer exist if
6013 the frame was deleted. */
6015 /* While a frame is unmapped, display generation is
6016 disabled; you don't want to spend time updating a
6017 display that won't ever be seen. */
6018 f
->async_visible
= 0;
6019 /* We can't distinguish, from the event, whether the window
6020 has become iconified or invisible. So assume, if it
6021 was previously visible, than now it is iconified.
6022 But x_make_frame_invisible clears both
6023 the visible flag and the iconified flag;
6024 and that way, we know the window is not iconified now. */
6025 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6027 f
->async_iconified
= 1;
6029 inev
.ie
.kind
= ICONIFY_EVENT
;
6030 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6036 if (event
.xmap
.window
== tip_window
)
6037 /* The tooltip has been drawn already. Avoid
6038 the SET_FRAME_GARBAGED below. */
6041 /* We use x_top_window_to_frame because map events can
6042 come for sub-windows and they don't mean that the
6043 frame is visible. */
6044 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6047 /* wait_reading_process_output will notice this and update
6048 the frame's display structures.
6049 If we where iconified, we should not set garbaged,
6050 because that stops redrawing on Expose events. This looks
6051 bad if we are called from a recursive event loop
6052 (x_dispatch_event), for example when a dialog is up. */
6053 if (! f
->async_iconified
)
6054 SET_FRAME_GARBAGED (f
);
6056 /* Check if fullscreen was specified before we where mapped the
6057 first time, i.e. from the command line. */
6058 if (!f
->output_data
.x
->has_been_visible
)
6059 x_check_fullscreen (f
);
6061 f
->async_visible
= 1;
6062 f
->async_iconified
= 0;
6063 f
->output_data
.x
->has_been_visible
= 1;
6067 inev
.ie
.kind
= DEICONIFY_EVENT
;
6068 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6070 else if (! NILP (Vframe_list
)
6071 && ! NILP (XCDR (Vframe_list
)))
6072 /* Force a redisplay sooner or later
6073 to update the frame titles
6074 in case this is the second frame. */
6075 record_asynch_buffer_change ();
6078 xg_frame_resized (f
, -1, -1);
6085 last_user_time
= event
.xkey
.time
;
6086 ignore_next_mouse_click_timeout
= 0;
6088 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6089 /* Dispatch KeyPress events when in menu. */
6090 if (popup_activated ())
6094 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6096 /* If mouse-highlight is an integer, input clears out
6097 mouse highlighting. */
6098 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6100 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6102 clear_mouse_face (dpyinfo
);
6103 dpyinfo
->mouse_face_hidden
= 1;
6106 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6109 /* Scroll bars consume key events, but we want
6110 the keys to go to the scroll bar's frame. */
6111 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6113 if (widget
&& XmIsScrollBar (widget
))
6115 widget
= XtParent (widget
);
6116 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6119 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6123 KeySym keysym
, orig_keysym
;
6124 /* al%imercury@uunet.uu.net says that making this 81
6125 instead of 80 fixed a bug whereby meta chars made
6128 It seems that some version of XmbLookupString has
6129 a bug of not returning XBufferOverflow in
6130 status_return even if the input is too long to
6131 fit in 81 bytes. So, we must prepare sufficient
6132 bytes for copy_buffer. 513 bytes (256 chars for
6133 two-byte character set) seems to be a fairly good
6134 approximation. -- 2000.8.10 handa@etl.go.jp */
6135 unsigned char copy_buffer
[513];
6136 unsigned char *copy_bufptr
= copy_buffer
;
6137 int copy_bufsiz
= sizeof (copy_buffer
);
6139 Lisp_Object coding_system
= Qlatin_1
;
6143 /* Don't pass keys to GTK. A Tab will shift focus to the
6144 tool bar in GTK 2.4. Keys will still go to menus and
6145 dialogs because in that case popup_activated is TRUE
6147 *finish
= X_EVENT_DROP
;
6151 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6152 extra_keyboard_modifiers
);
6153 modifiers
= event
.xkey
.state
;
6155 /* This will have to go some day... */
6157 /* make_lispy_event turns chars into control chars.
6158 Don't do it here because XLookupString is too eager. */
6159 event
.xkey
.state
&= ~ControlMask
;
6160 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6161 | dpyinfo
->super_mod_mask
6162 | dpyinfo
->hyper_mod_mask
6163 | dpyinfo
->alt_mod_mask
);
6165 /* In case Meta is ComposeCharacter,
6166 clear its status. According to Markus Ehrnsperger
6167 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6168 this enables ComposeCharacter to work whether or
6169 not it is combined with Meta. */
6170 if (modifiers
& dpyinfo
->meta_mod_mask
)
6171 memset (&compose_status
, 0, sizeof (compose_status
));
6176 Status status_return
;
6178 coding_system
= Vlocale_coding_system
;
6179 nbytes
= XmbLookupString (FRAME_XIC (f
),
6180 &event
.xkey
, copy_bufptr
,
6181 copy_bufsiz
, &keysym
,
6183 if (status_return
== XBufferOverflow
)
6185 copy_bufsiz
= nbytes
+ 1;
6186 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6187 nbytes
= XmbLookupString (FRAME_XIC (f
),
6188 &event
.xkey
, copy_bufptr
,
6189 copy_bufsiz
, &keysym
,
6192 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6193 if (status_return
== XLookupNone
)
6195 else if (status_return
== XLookupChars
)
6200 else if (status_return
!= XLookupKeySym
6201 && status_return
!= XLookupBoth
)
6205 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6206 copy_bufsiz
, &keysym
,
6209 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6210 copy_bufsiz
, &keysym
,
6214 /* If not using XIM/XIC, and a compose sequence is in progress,
6215 we break here. Otherwise, chars_matched is always 0. */
6216 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6219 memset (&compose_status
, 0, sizeof (compose_status
));
6220 orig_keysym
= keysym
;
6222 /* Common for all keysym input events. */
6223 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6225 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6226 inev
.ie
.timestamp
= event
.xkey
.time
;
6228 /* First deal with keysyms which have defined
6229 translations to characters. */
6230 if (keysym
>= 32 && keysym
< 128)
6231 /* Avoid explicitly decoding each ASCII character. */
6233 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6234 inev
.ie
.code
= keysym
;
6238 /* Keysyms directly mapped to Unicode characters. */
6239 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6241 if (keysym
< 0x01000080)
6242 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6244 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6245 inev
.ie
.code
= keysym
& 0xFFFFFF;
6249 /* Now non-ASCII. */
6250 if (HASH_TABLE_P (Vx_keysym_table
)
6251 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6255 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6256 ? ASCII_KEYSTROKE_EVENT
6257 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6258 inev
.ie
.code
= XFASTINT (c
);
6262 /* Random non-modifier sorts of keysyms. */
6263 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6264 || keysym
== XK_Delete
6265 #ifdef XK_ISO_Left_Tab
6266 || (keysym
>= XK_ISO_Left_Tab
6267 && keysym
<= XK_ISO_Enter
)
6269 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6270 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6272 /* This recognizes the "extended function
6273 keys". It seems there's no cleaner way.
6274 Test IsModifierKey to avoid handling
6275 mode_switch incorrectly. */
6276 || ((unsigned) (keysym
) >= XK_Select
6277 && (unsigned)(keysym
) < XK_KP_Space
)
6279 #ifdef XK_dead_circumflex
6280 || orig_keysym
== XK_dead_circumflex
6282 #ifdef XK_dead_grave
6283 || orig_keysym
== XK_dead_grave
6285 #ifdef XK_dead_tilde
6286 || orig_keysym
== XK_dead_tilde
6288 #ifdef XK_dead_diaeresis
6289 || orig_keysym
== XK_dead_diaeresis
6291 #ifdef XK_dead_macron
6292 || orig_keysym
== XK_dead_macron
6294 #ifdef XK_dead_degree
6295 || orig_keysym
== XK_dead_degree
6297 #ifdef XK_dead_acute
6298 || orig_keysym
== XK_dead_acute
6300 #ifdef XK_dead_cedilla
6301 || orig_keysym
== XK_dead_cedilla
6303 #ifdef XK_dead_breve
6304 || orig_keysym
== XK_dead_breve
6306 #ifdef XK_dead_ogonek
6307 || orig_keysym
== XK_dead_ogonek
6309 #ifdef XK_dead_caron
6310 || orig_keysym
== XK_dead_caron
6312 #ifdef XK_dead_doubleacute
6313 || orig_keysym
== XK_dead_doubleacute
6315 #ifdef XK_dead_abovedot
6316 || orig_keysym
== XK_dead_abovedot
6318 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6319 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6320 /* Any "vendor-specific" key is ok. */
6321 || (orig_keysym
& (1 << 28))
6322 || (keysym
!= NoSymbol
&& nbytes
== 0))
6323 && ! (IsModifierKey (orig_keysym
)
6324 /* The symbols from XK_ISO_Lock
6325 to XK_ISO_Last_Group_Lock
6326 don't have real modifiers but
6327 should be treated similarly to
6328 Mode_switch by Emacs. */
6329 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6330 || ((unsigned)(orig_keysym
)
6332 && (unsigned)(orig_keysym
)
6333 <= XK_ISO_Last_Group_Lock
)
6337 STORE_KEYSYM_FOR_DEBUG (keysym
);
6338 /* make_lispy_event will convert this to a symbolic
6340 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6341 inev
.ie
.code
= keysym
;
6345 { /* Raw bytes, not keysym. */
6350 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6352 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6354 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6357 if (nchars
< nbytes
)
6359 /* Decode the input data. */
6363 /* The input should be decoded with `coding_system'
6364 which depends on which X*LookupString function
6365 we used just above and the locale. */
6366 setup_coding_system (coding_system
, &coding
);
6367 coding
.src_multibyte
= 0;
6368 coding
.dst_multibyte
= 1;
6369 /* The input is converted to events, thus we can't
6370 handle composition. Anyway, there's no XIM that
6371 gives us composition information. */
6372 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6374 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6375 coding
.destination
= alloca (require
);
6376 coding
.dst_bytes
= require
;
6377 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6378 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6379 nbytes
= coding
.produced
;
6380 nchars
= coding
.produced_char
;
6381 copy_bufptr
= coding
.destination
;
6384 /* Convert the input data to a sequence of
6385 character events. */
6386 for (i
= 0; i
< nbytes
; i
+= len
)
6388 if (nchars
== nbytes
)
6389 c
= copy_bufptr
[i
], len
= 1;
6391 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6392 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6393 ? ASCII_KEYSTROKE_EVENT
6394 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6396 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6401 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6403 if (keysym
== NoSymbol
)
6409 /* Don't dispatch this event since XtDispatchEvent calls
6410 XFilterEvent, and two calls in a row may freeze the
6418 last_user_time
= event
.xkey
.time
;
6420 /* Don't dispatch this event since XtDispatchEvent calls
6421 XFilterEvent, and two calls in a row may freeze the
6429 last_user_time
= event
.xcrossing
.time
;
6430 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6432 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6434 if (f
&& x_mouse_click_focus_ignore_position
)
6435 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6437 /* EnterNotify counts as mouse movement,
6438 so update things that depend on mouse position. */
6439 if (f
&& !f
->output_data
.x
->hourglass_p
)
6440 note_mouse_movement (f
, &event
.xmotion
);
6442 /* We may get an EnterNotify on the buttons in the toolbar. In that
6443 case we moved out of any highlighted area and need to note this. */
6444 if (!f
&& last_mouse_glyph_frame
)
6445 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6450 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6454 last_user_time
= event
.xcrossing
.time
;
6455 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6457 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6460 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6462 /* If we move outside the frame, then we're
6463 certainly no longer on any text in the frame. */
6464 clear_mouse_face (dpyinfo
);
6465 dpyinfo
->mouse_face_mouse_frame
= 0;
6468 /* Generate a nil HELP_EVENT to cancel a help-echo.
6469 Do it only if there's something to cancel.
6470 Otherwise, the startup message is cleared when
6471 the mouse leaves the frame. */
6472 if (any_help_event_p
)
6476 /* See comment in EnterNotify above */
6477 else if (last_mouse_glyph_frame
)
6478 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6483 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6488 last_user_time
= event
.xmotion
.time
;
6489 previous_help_echo_string
= help_echo_string
;
6490 help_echo_string
= Qnil
;
6492 if (dpyinfo
->grabbed
&& last_mouse_frame
6493 && FRAME_LIVE_P (last_mouse_frame
))
6494 f
= last_mouse_frame
;
6496 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6498 if (dpyinfo
->mouse_face_hidden
)
6500 dpyinfo
->mouse_face_hidden
= 0;
6501 clear_mouse_face (dpyinfo
);
6505 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6511 /* Generate SELECT_WINDOW_EVENTs when needed.
6512 Don't let popup menus influence things (bug#1261). */
6513 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6517 window
= window_from_coordinates (f
,
6518 event
.xmotion
.x
, event
.xmotion
.y
,
6521 /* Window will be selected only when it is not selected now and
6522 last mouse movement event was not in it. Minibuffer window
6523 will be selected only when it is active. */
6524 if (WINDOWP (window
)
6525 && !EQ (window
, last_window
)
6526 && !EQ (window
, selected_window
)
6527 /* For click-to-focus window managers
6528 create event iff we don't leave the
6530 && (focus_follows_mouse
6531 || (EQ (XWINDOW (window
)->frame
,
6532 XWINDOW (selected_window
)->frame
))))
6534 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6535 inev
.ie
.frame_or_window
= window
;
6540 if (!note_mouse_movement (f
, &event
.xmotion
))
6541 help_echo_string
= previous_help_echo_string
;
6545 #ifndef USE_TOOLKIT_SCROLL_BARS
6546 struct scroll_bar
*bar
6547 = x_window_to_scroll_bar (event
.xmotion
.display
,
6548 event
.xmotion
.window
);
6551 x_scroll_bar_note_movement (bar
, &event
);
6552 #endif /* USE_TOOLKIT_SCROLL_BARS */
6554 /* If we move outside the frame, then we're
6555 certainly no longer on any text in the frame. */
6556 clear_mouse_face (dpyinfo
);
6559 /* If the contents of the global variable help_echo_string
6560 has changed, generate a HELP_EVENT. */
6561 if (!NILP (help_echo_string
)
6562 || !NILP (previous_help_echo_string
))
6567 case ConfigureNotify
:
6568 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6571 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6572 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6574 xg_frame_resized (f
, event
.xconfigure
.width
,
6575 event
.xconfigure
.height
);
6581 #ifndef USE_X_TOOLKIT
6583 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6584 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6586 /* In the toolkit version, change_frame_size
6587 is called by the code that handles resizing
6588 of the EmacsFrame widget. */
6590 /* Even if the number of character rows and columns has
6591 not changed, the font size may have changed, so we need
6592 to check the pixel dimensions as well. */
6593 if (columns
!= FRAME_COLS (f
)
6594 || rows
!= FRAME_LINES (f
)
6595 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6596 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6598 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6599 SET_FRAME_GARBAGED (f
);
6600 cancel_mouse_face (f
);
6603 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6604 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6605 #endif /* not USE_GTK */
6609 /* GTK creates windows but doesn't map them.
6610 Only get real positions when mapped. */
6611 if (FRAME_GTK_OUTER_WIDGET (f
)
6612 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6615 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6619 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6620 xic_set_statusarea (f
);
6629 /* If we decide we want to generate an event to be seen
6630 by the rest of Emacs, we put it here. */
6633 memset (&compose_status
, 0, sizeof (compose_status
));
6634 last_mouse_glyph_frame
= 0;
6635 last_user_time
= event
.xbutton
.time
;
6637 if (dpyinfo
->grabbed
6639 && FRAME_LIVE_P (last_mouse_frame
))
6640 f
= last_mouse_frame
;
6642 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6645 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6650 /* Is this in the tool-bar? */
6651 if (WINDOWP (f
->tool_bar_window
)
6652 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6655 int x
= event
.xbutton
.x
;
6656 int y
= event
.xbutton
.y
;
6658 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6659 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6661 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6663 handle_tool_bar_click (f
, x
, y
,
6664 event
.xbutton
.type
== ButtonPress
,
6665 x_x_to_emacs_modifiers (dpyinfo
,
6666 event
.xbutton
.state
));
6671 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6672 if (! popup_activated ())
6675 if (ignore_next_mouse_click_timeout
)
6677 if (event
.type
== ButtonPress
6678 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6680 ignore_next_mouse_click_timeout
= 0;
6681 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6683 if (event
.type
== ButtonRelease
)
6684 ignore_next_mouse_click_timeout
= 0;
6687 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6689 if (FRAME_X_EMBEDDED_P (f
))
6690 xembed_send_message (f
, event
.xbutton
.time
,
6691 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6695 struct scroll_bar
*bar
6696 = x_window_to_scroll_bar (event
.xbutton
.display
,
6697 event
.xbutton
.window
);
6699 #ifdef USE_TOOLKIT_SCROLL_BARS
6700 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6702 if (bar
&& event
.xbutton
.state
& ControlMask
)
6704 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6705 *finish
= X_EVENT_DROP
;
6707 #else /* not USE_TOOLKIT_SCROLL_BARS */
6709 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6710 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6713 if (event
.type
== ButtonPress
)
6715 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6716 last_mouse_frame
= f
;
6719 last_tool_bar_item
= -1;
6722 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6724 /* Ignore any mouse motion that happened before this event;
6725 any subsequent mouse-movement Emacs events should reflect
6726 only motion after the ButtonPress/Release. */
6730 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6731 f
= x_menubar_window_to_frame (dpyinfo
, &event
);
6732 /* For a down-event in the menu bar,
6733 don't pass it to Xt right now.
6734 Instead, save it away
6735 and we will pass it to Xt from kbd_buffer_get_event.
6736 That way, we can run some Lisp code first. */
6737 if (! popup_activated ()
6739 /* Gtk+ menus only react to the first three buttons. */
6740 && event
.xbutton
.button
< 3
6742 && f
&& event
.type
== ButtonPress
6743 /* Verify the event is really within the menu bar
6744 and not just sent to it due to grabbing. */
6745 && event
.xbutton
.x
>= 0
6746 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6747 && event
.xbutton
.y
>= 0
6748 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6749 && event
.xbutton
.same_screen
)
6751 SET_SAVED_BUTTON_EVENT
;
6752 XSETFRAME (last_mouse_press_frame
, f
);
6753 *finish
= X_EVENT_DROP
;
6755 else if (event
.type
== ButtonPress
)
6757 last_mouse_press_frame
= Qnil
;
6762 #endif /* USE_X_TOOLKIT || USE_GTK */
6766 case CirculateNotify
:
6769 case CirculateRequest
:
6772 case VisibilityNotify
:
6776 /* Someone has changed the keyboard mapping - update the
6778 switch (event
.xmapping
.request
)
6780 case MappingModifier
:
6781 x_find_modifier_meanings (dpyinfo
);
6782 /* This is meant to fall through. */
6783 case MappingKeyboard
:
6784 XRefreshKeyboardMapping (&event
.xmapping
);
6789 xft_settings_event (dpyinfo
, &event
);
6794 #ifdef USE_X_TOOLKIT
6796 if (*finish
!= X_EVENT_DROP
)
6797 XtDispatchEvent (&event
);
6799 #endif /* USE_X_TOOLKIT */
6804 if (inev
.ie
.kind
!= NO_EVENT
)
6806 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6811 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6816 XSETFRAME (frame
, f
);
6822 any_help_event_p
= 1;
6823 gen_help_event (help_echo_string
, frame
, help_echo_window
,
6824 help_echo_object
, help_echo_pos
);
6828 help_echo_string
= Qnil
;
6829 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
6839 /* Handles the XEvent EVENT on display DISPLAY.
6840 This is used for event loops outside the normal event handling,
6841 i.e. looping while a popup menu or a dialog is posted.
6843 Returns the value handle_one_xevent sets in the finish argument. */
6845 x_dispatch_event (XEvent
*event
, Display
*display
)
6847 struct x_display_info
*dpyinfo
;
6848 int finish
= X_EVENT_NORMAL
;
6850 dpyinfo
= x_display_info_for_display (display
);
6853 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
6859 /* Read events coming from the X server.
6860 This routine is called by the SIGIO handler.
6861 We return as soon as there are no more events to be read.
6863 We return the number of characters stored into the buffer,
6864 thus pretending to be `read' (except the characters we store
6865 in the keyboard buffer can be multibyte, so are not necessarily
6868 EXPECTED is nonzero if the caller knows input is available. */
6871 XTread_socket (struct terminal
*terminal
, int expected
, struct input_event
*hold_quit
)
6875 int event_found
= 0;
6877 if (interrupt_input_blocked
)
6879 interrupt_input_pending
= 1;
6881 pending_signals
= 1;
6886 interrupt_input_pending
= 0;
6888 pending_signals
= pending_atimers
;
6892 /* So people can tell when we have read the available input. */
6893 input_signal_count
++;
6898 /* Only check session manager input for the primary display. */
6899 if (terminal
->id
== 1 && x_session_have_connection ())
6901 struct input_event inev
;
6903 /* We don't need to EVENT_INIT (inev) here, as
6904 x_session_check_input copies an entire input_event. */
6905 if (x_session_check_input (&inev
))
6907 kbd_buffer_store_event_hold (&inev
, hold_quit
);
6914 /* For debugging, this gives a way to fake an I/O error. */
6915 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
6917 XTread_socket_fake_io_error
= 0;
6918 x_io_error_quitter (terminal
->display_info
.x
->display
);
6922 while (XPending (terminal
->display_info
.x
->display
))
6926 XNextEvent (terminal
->display_info
.x
->display
, &event
);
6929 /* Filter events for the current X input method. */
6930 if (x_filter_event (terminal
->display_info
.x
, &event
))
6935 count
+= handle_one_xevent (terminal
->display_info
.x
,
6936 &event
, &finish
, hold_quit
);
6938 if (finish
== X_EVENT_GOTO_OUT
)
6944 /* For GTK we must use the GTK event loop. But XEvents gets passed
6945 to our filter function above, and then to the big event switch.
6946 We use a bunch of globals to communicate with our filter function,
6947 that is kind of ugly, but it works.
6949 There is no way to do one display at the time, GTK just does events
6950 from all displays. */
6952 while (gtk_events_pending ())
6954 current_count
= count
;
6955 current_hold_quit
= hold_quit
;
6957 gtk_main_iteration ();
6959 count
= current_count
;
6961 current_hold_quit
= 0;
6963 if (current_finish
== X_EVENT_GOTO_OUT
)
6966 #endif /* USE_GTK */
6970 /* On some systems, an X bug causes Emacs to get no more events
6971 when the window is destroyed. Detect that. (1994.) */
6974 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
6975 One XNOOP in 100 loops will make Emacs terminate.
6976 B. Bretthauer, 1994 */
6978 if (x_noop_count
>= 100)
6982 if (next_noop_dpyinfo
== 0)
6983 next_noop_dpyinfo
= x_display_list
;
6985 XNoOp (next_noop_dpyinfo
->display
);
6987 /* Each time we get here, cycle through the displays now open. */
6988 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
6992 /* If the focus was just given to an auto-raising frame,
6994 /* ??? This ought to be able to handle more than one such frame. */
6995 if (pending_autoraise_frame
)
6997 x_raise_frame (pending_autoraise_frame
);
6998 pending_autoraise_frame
= 0;
7010 /***********************************************************************
7012 ***********************************************************************/
7014 /* Set clipping for output in glyph row ROW. W is the window in which
7015 we operate. GC is the graphics context to set clipping in.
7017 ROW may be a text row or, e.g., a mode line. Text rows must be
7018 clipped to the interior of the window dedicated to text display,
7019 mode lines must be clipped to the whole window. */
7022 x_clip_to_row (struct window
*w
, struct glyph_row
*row
, int area
, GC gc
)
7024 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7025 XRectangle clip_rect
;
7026 int window_x
, window_y
, window_width
;
7028 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7030 clip_rect
.x
= window_x
;
7031 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7032 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7033 clip_rect
.width
= window_width
;
7034 clip_rect
.height
= row
->visible_height
;
7036 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7040 /* Draw a hollow box cursor on window W in glyph row ROW. */
7043 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7045 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7046 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7047 Display
*dpy
= FRAME_X_DISPLAY (f
);
7050 struct glyph
*cursor_glyph
;
7053 /* Get the glyph the cursor is on. If we can't tell because
7054 the current matrix is invalid or such, give up. */
7055 cursor_glyph
= get_phys_cursor_glyph (w
);
7056 if (cursor_glyph
== NULL
)
7059 /* Compute frame-relative coordinates for phys cursor. */
7060 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7061 wd
= w
->phys_cursor_width
;
7063 /* The foreground of cursor_gc is typically the same as the normal
7064 background color, which can cause the cursor box to be invisible. */
7065 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7066 if (dpyinfo
->scratch_cursor_gc
)
7067 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7069 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7070 GCForeground
, &xgcv
);
7071 gc
= dpyinfo
->scratch_cursor_gc
;
7073 /* Set clipping, draw the rectangle, and reset clipping again. */
7074 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7075 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7076 XSetClipMask (dpy
, gc
, None
);
7080 /* Draw a bar cursor on window W in glyph row ROW.
7082 Implementation note: One would like to draw a bar cursor with an
7083 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7084 Unfortunately, I didn't find a font yet that has this property set.
7088 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7090 struct frame
*f
= XFRAME (w
->frame
);
7091 struct glyph
*cursor_glyph
;
7093 /* If cursor is out of bounds, don't draw garbage. This can happen
7094 in mini-buffer windows when switching between echo area glyphs
7096 cursor_glyph
= get_phys_cursor_glyph (w
);
7097 if (cursor_glyph
== NULL
)
7100 /* If on an image, draw like a normal cursor. That's usually better
7101 visible than drawing a bar, esp. if the image is large so that
7102 the bar might not be in the window. */
7103 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7105 struct glyph_row
*row
;
7106 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7107 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7111 Display
*dpy
= FRAME_X_DISPLAY (f
);
7112 Window window
= FRAME_X_WINDOW (f
);
7113 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7114 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7115 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7118 /* If the glyph's background equals the color we normally draw
7119 the bars cursor in, the bar cursor in its normal color is
7120 invisible. Use the glyph's foreground color instead in this
7121 case, on the assumption that the glyph's colors are chosen so
7122 that the glyph is legible. */
7123 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7124 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7126 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7127 xgcv
.graphics_exposures
= 0;
7130 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7133 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7134 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7137 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7139 if (kind
== BAR_CURSOR
)
7142 width
= FRAME_CURSOR_WIDTH (f
);
7143 width
= min (cursor_glyph
->pixel_width
, width
);
7145 w
->phys_cursor_width
= width
;
7147 XFillRectangle (dpy
, window
, gc
,
7148 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7149 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7150 width
, row
->height
);
7154 int dummy_x
, dummy_y
, dummy_h
;
7157 width
= row
->height
;
7159 width
= min (row
->height
, width
);
7161 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7162 &dummy_y
, &dummy_h
);
7164 XFillRectangle (dpy
, window
, gc
,
7165 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7166 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7167 row
->height
- width
),
7168 w
->phys_cursor_width
, width
);
7171 XSetClipMask (dpy
, gc
, None
);
7176 /* RIF: Define cursor CURSOR on frame F. */
7179 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7181 if (!f
->pointer_invisible
7182 && f
->output_data
.x
->current_cursor
!= cursor
)
7183 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7184 f
->output_data
.x
->current_cursor
= cursor
;
7188 /* RIF: Clear area on frame F. */
7191 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7193 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7194 x
, y
, width
, height
, False
);
7196 /* Must queue a redraw, because scroll bars might have been cleared. */
7197 if (FRAME_GTK_WIDGET (f
))
7198 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7203 /* RIF: Draw cursor on window W. */
7206 x_draw_window_cursor (struct window
*w
, struct glyph_row
*glyph_row
, int x
, int y
, int cursor_type
, int cursor_width
, int on_p
, int active_p
)
7208 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7212 w
->phys_cursor_type
= cursor_type
;
7213 w
->phys_cursor_on_p
= 1;
7215 if (glyph_row
->exact_window_width_line_p
7216 && (glyph_row
->reversed_p
7217 ? (w
->phys_cursor
.hpos
< 0)
7218 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7220 glyph_row
->cursor_in_fringe_p
= 1;
7221 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7225 switch (cursor_type
)
7227 case HOLLOW_BOX_CURSOR
:
7228 x_draw_hollow_cursor (w
, glyph_row
);
7231 case FILLED_BOX_CURSOR
:
7232 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7236 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7240 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7244 w
->phys_cursor_width
= 0;
7253 if (w
== XWINDOW (f
->selected_window
))
7254 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7255 xic_set_preeditarea (w
, x
, y
);
7260 XFlush (FRAME_X_DISPLAY (f
));
7267 /* Make the x-window of frame F use the gnu icon bitmap. */
7270 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7274 if (FRAME_X_WINDOW (f
) == 0)
7277 /* Free up our existing icon bitmap and mask if any. */
7278 if (f
->output_data
.x
->icon_bitmap
> 0)
7279 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7280 f
->output_data
.x
->icon_bitmap
= 0;
7285 /* Use gtk_window_set_icon_from_file () if available,
7286 It's not restricted to bitmaps */
7287 if (xg_set_icon (f
, file
))
7289 #endif /* USE_GTK */
7290 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7291 x_create_bitmap_mask (f
, bitmap_id
);
7295 /* Create the GNU bitmap and mask if necessary. */
7296 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7302 if (xg_set_icon (f
, xg_default_icon_file
)
7303 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7306 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7308 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7310 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7314 /* If all else fails, use the (black and white) xbm image. */
7317 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7318 gnu_xbm_width
, gnu_xbm_height
);
7322 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7323 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7327 /* The first time we create the GNU bitmap and mask,
7328 this increments the ref-count one extra time.
7329 As a result, the GNU bitmap and mask are never freed.
7330 That way, we don't have to worry about allocating it again. */
7331 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7333 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7336 x_wm_set_icon_pixmap (f
, bitmap_id
);
7337 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7343 /* Make the x-window of frame F use a rectangle with text.
7344 Use ICON_NAME as the text. */
7347 x_text_icon (struct frame
*f
, const char *icon_name
)
7349 if (FRAME_X_WINDOW (f
) == 0)
7354 text
.value
= (unsigned char *) icon_name
;
7355 text
.encoding
= XA_STRING
;
7357 text
.nitems
= strlen (icon_name
);
7358 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7361 if (f
->output_data
.x
->icon_bitmap
> 0)
7362 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7363 f
->output_data
.x
->icon_bitmap
= 0;
7364 x_wm_set_icon_pixmap (f
, 0);
7369 #define X_ERROR_MESSAGE_SIZE 200
7371 /* If non-nil, this should be a string.
7372 It means catch X errors and store the error message in this string.
7374 The reason we use a stack is that x_catch_error/x_uncatch_error can
7375 be called from a signal handler.
7378 struct x_error_message_stack
{
7379 char string
[X_ERROR_MESSAGE_SIZE
];
7381 struct x_error_message_stack
*prev
;
7383 static struct x_error_message_stack
*x_error_message
;
7385 /* An X error handler which stores the error message in
7386 *x_error_message. This is called from x_error_handler if
7387 x_catch_errors is in effect. */
7390 x_error_catcher (Display
*display
, XErrorEvent
*error
)
7392 XGetErrorText (display
, error
->error_code
,
7393 x_error_message
->string
,
7394 X_ERROR_MESSAGE_SIZE
);
7397 /* Begin trapping X errors for display DPY. Actually we trap X errors
7398 for all displays, but DPY should be the display you are actually
7401 After calling this function, X protocol errors no longer cause
7402 Emacs to exit; instead, they are recorded in the string
7403 stored in *x_error_message.
7405 Calling x_check_errors signals an Emacs error if an X error has
7406 occurred since the last call to x_catch_errors or x_check_errors.
7408 Calling x_uncatch_errors resumes the normal error handling. */
7410 void x_check_errors (Display
*dpy
, const char *format
);
7413 x_catch_errors (Display
*dpy
)
7415 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7417 /* Make sure any errors from previous requests have been dealt with. */
7421 data
->string
[0] = 0;
7422 data
->prev
= x_error_message
;
7423 x_error_message
= data
;
7426 /* Undo the last x_catch_errors call.
7427 DPY should be the display that was passed to x_catch_errors. */
7430 x_uncatch_errors (void)
7432 struct x_error_message_stack
*tmp
;
7436 /* The display may have been closed before this function is called.
7437 Check if it is still open before calling XSync. */
7438 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7439 XSync (x_error_message
->dpy
, False
);
7441 tmp
= x_error_message
;
7442 x_error_message
= x_error_message
->prev
;
7447 /* If any X protocol errors have arrived since the last call to
7448 x_catch_errors or x_check_errors, signal an Emacs error using
7449 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7452 x_check_errors (Display
*dpy
, const char *format
)
7454 /* Make sure to catch any errors incurred so far. */
7457 if (x_error_message
->string
[0])
7459 char string
[X_ERROR_MESSAGE_SIZE
];
7460 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7461 x_uncatch_errors ();
7462 error (format
, string
);
7466 /* Nonzero if we had any X protocol errors
7467 since we did x_catch_errors on DPY. */
7470 x_had_errors_p (Display
*dpy
)
7472 /* Make sure to catch any errors incurred so far. */
7475 return x_error_message
->string
[0] != 0;
7478 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7481 x_clear_errors (Display
*dpy
)
7483 x_error_message
->string
[0] = 0;
7486 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7487 * idea. --lorentey */
7488 /* Close off all unclosed x_catch_errors calls. */
7491 x_fully_uncatch_errors (void)
7493 while (x_error_message
)
7494 x_uncatch_errors ();
7498 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7501 x_catching_errors (void)
7503 return x_error_message
!= 0;
7507 static unsigned int x_wire_count
;
7510 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7515 /* Handle SIGPIPE, which can happen when the connection to a server
7516 simply goes away. SIGPIPE is handled by x_connection_signal.
7517 Don't need to do anything, because the write which caused the
7518 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7519 which will do the appropriate cleanup for us. */
7522 x_connection_signal (int signalnum
) /* If we don't have an argument, */
7523 /* some compilers complain in signal calls. */
7526 /* USG systems forget handlers when they are used;
7527 must reestablish each time */
7528 signal (signalnum
, x_connection_signal
);
7533 /************************************************************************
7535 ************************************************************************/
7537 /* Error message passed to x_connection_closed. */
7539 static char *error_msg
;
7541 /* Function installed as fatal_error_signal_hook in
7542 x_connection_closed. Print the X error message, and exit normally,
7543 instead of dumping core when XtCloseDisplay fails. */
7546 x_fatal_error_signal (void)
7548 fprintf (stderr
, "%s\n", error_msg
);
7552 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7553 the text of an error message that lead to the connection loss. */
7556 x_connection_closed (Display
*dpy
, const char *error_message
)
7558 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7559 Lisp_Object frame
, tail
;
7560 int index
= SPECPDL_INDEX ();
7562 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7563 strcpy (error_msg
, error_message
);
7564 handling_signal
= 0;
7566 /* Prevent being called recursively because of an error condition
7567 below. Otherwise, we might end up with printing ``can't find per
7568 display information'' in the recursive call instead of printing
7569 the original message here. */
7570 x_catch_errors (dpy
);
7572 /* Inhibit redisplay while frames are being deleted. */
7573 specbind (Qinhibit_redisplay
, Qt
);
7577 /* Protect display from being closed when we delete the last
7579 dpyinfo
->reference_count
++;
7580 dpyinfo
->terminal
->reference_count
++;
7583 /* First delete frames whose mini-buffers are on frames
7584 that are on the dead display. */
7585 FOR_EACH_FRAME (tail
, frame
)
7587 Lisp_Object minibuf_frame
;
7589 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7590 if (FRAME_X_P (XFRAME (frame
))
7591 && FRAME_X_P (XFRAME (minibuf_frame
))
7592 && ! EQ (frame
, minibuf_frame
)
7593 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7594 delete_frame (frame
, Qnoelisp
);
7597 /* Now delete all remaining frames on the dead display.
7598 We are now sure none of these is used as the mini-buffer
7599 for another frame that we need to delete. */
7600 FOR_EACH_FRAME (tail
, frame
)
7601 if (FRAME_X_P (XFRAME (frame
))
7602 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7604 /* Set this to t so that delete_frame won't get confused
7605 trying to find a replacement. */
7606 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7607 delete_frame (frame
, Qnoelisp
);
7610 /* We have to close the display to inform Xt that it doesn't
7611 exist anymore. If we don't, Xt will continue to wait for
7612 events from the display. As a consequence, a sequence of
7614 M-x make-frame-on-display RET :1 RET
7615 ...kill the new frame, so that we get an IO error...
7616 M-x make-frame-on-display RET :1 RET
7618 will indefinitely wait in Xt for events for display `:1', opened
7619 in the first call to make-frame-on-display.
7621 Closing the display is reported to lead to a bus error on
7622 OpenWindows in certain situations. I suspect that is a bug
7623 in OpenWindows. I don't know how to circumvent it here. */
7627 #ifdef USE_X_TOOLKIT
7628 /* If DPYINFO is null, this means we didn't open the display
7629 in the first place, so don't try to close it. */
7631 extern void (*fatal_error_signal_hook
) (void);
7632 fatal_error_signal_hook
= x_fatal_error_signal
;
7633 XtCloseDisplay (dpy
);
7634 fatal_error_signal_hook
= NULL
;
7639 /* Due to bugs in some Gtk+ versions, just exit here if this
7640 is the last display/terminal. */
7641 if (terminal_list
->next_terminal
== NULL
)
7643 fprintf (stderr
, "%s\n", error_msg
);
7644 Fkill_emacs (make_number (70));
7647 xg_display_close (dpyinfo
->display
);
7650 /* Indicate that this display is dead. */
7651 dpyinfo
->display
= 0;
7653 dpyinfo
->reference_count
--;
7654 dpyinfo
->terminal
->reference_count
--;
7655 if (dpyinfo
->reference_count
!= 0)
7656 /* We have just closed all frames on this display. */
7661 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7662 Fdelete_terminal (tmp
, Qnoelisp
);
7666 x_uncatch_errors ();
7668 if (terminal_list
== 0)
7670 fprintf (stderr
, "%s\n", error_msg
);
7671 Fkill_emacs (make_number (70));
7675 /* Ordinary stack unwind doesn't deal with these. */
7677 sigunblock (sigmask (SIGIO
));
7679 sigunblock (sigmask (SIGALRM
));
7680 TOTALLY_UNBLOCK_INPUT
;
7682 unbind_to (index
, Qnil
);
7683 clear_waiting_for_input ();
7684 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7685 longjmp), because returning from this function would get us back into
7686 Xlib's code which will directly call `exit'. */
7687 error ("%s", error_msg
);
7690 /* We specifically use it before defining it, so that gcc doesn't inline it,
7691 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7692 static void x_error_quitter (Display
*, XErrorEvent
*);
7694 /* This is the first-level handler for X protocol errors.
7695 It calls x_error_quitter or x_error_catcher. */
7698 x_error_handler (Display
*display
, XErrorEvent
*error
)
7700 if (x_error_message
)
7701 x_error_catcher (display
, error
);
7703 x_error_quitter (display
, error
);
7707 /* This is the usual handler for X protocol errors.
7708 It kills all frames on the display that we got the error for.
7709 If that was the only one, it prints an error message and kills Emacs. */
7711 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7713 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
7714 #define NO_INLINE __attribute__((noinline))
7719 /* Some versions of GNU/Linux define noinline in their headers. */
7725 /* On older GCC versions, just putting x_error_quitter
7726 after x_error_handler prevents inlining into the former. */
7728 static void NO_INLINE
7729 x_error_quitter (Display
*display
, XErrorEvent
*error
)
7731 char buf
[256], buf1
[356];
7733 /* Ignore BadName errors. They can happen because of fonts
7734 or colors that are not defined. */
7736 if (error
->error_code
== BadName
)
7739 /* Note that there is no real way portable across R3/R4 to get the
7740 original error handler. */
7742 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7743 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7744 buf
, error
->request_code
);
7745 x_connection_closed (display
, buf1
);
7749 /* This is the handler for X IO errors, always.
7750 It kills all frames on the display that we lost touch with.
7751 If that was the only one, it prints an error message and kills Emacs. */
7754 x_io_error_quitter (Display
*display
)
7758 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7759 x_connection_closed (display
, buf
);
7763 /* Changing the font of the frame. */
7765 /* Give frame F the font FONT-OBJECT as its default font. The return
7766 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7767 frame. If it is negative, generate a new fontset from
7771 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7773 struct font
*font
= XFONT_OBJECT (font_object
);
7776 fontset
= fontset_from_font (font_object
);
7777 FRAME_FONTSET (f
) = fontset
;
7778 if (FRAME_FONT (f
) == font
)
7779 /* This font is already set in frame F. There's nothing more to
7783 FRAME_FONT (f
) = font
;
7784 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7785 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7786 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
7787 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7789 compute_fringe_widths (f
, 1);
7791 /* Compute the scroll bar width in character columns. */
7792 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7794 int wid
= FRAME_COLUMN_WIDTH (f
);
7795 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7796 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7800 int wid
= FRAME_COLUMN_WIDTH (f
);
7801 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7804 if (FRAME_X_WINDOW (f
) != 0)
7806 /* Don't change the size of a tip frame; there's no point in
7807 doing it because it's done in Fx_show_tip, and it leads to
7808 problems because the tip frame has no widget. */
7809 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7810 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7815 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7818 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
7827 /***********************************************************************
7829 ***********************************************************************/
7835 /* XIM destroy callback function, which is called whenever the
7836 connection to input method XIM dies. CLIENT_DATA contains a
7837 pointer to the x_display_info structure corresponding to XIM. */
7840 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
7842 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7843 Lisp_Object frame
, tail
;
7847 /* No need to call XDestroyIC.. */
7848 FOR_EACH_FRAME (tail
, frame
)
7850 struct frame
*f
= XFRAME (frame
);
7851 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
7853 FRAME_XIC (f
) = NULL
;
7854 xic_free_xfontset (f
);
7858 /* No need to call XCloseIM. */
7859 dpyinfo
->xim
= NULL
;
7860 XFree (dpyinfo
->xim_styles
);
7864 #endif /* HAVE_X11R6 */
7867 /* This isn't prototyped in OSF 5.0 or 5.1a. */
7868 extern char *XSetIMValues (XIM
, ...);
7871 /* Open the connection to the XIM server on display DPYINFO.
7872 RESOURCE_NAME is the resource name Emacs uses. */
7875 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
7883 XCloseIM (dpyinfo
->xim
);
7884 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
7891 XIMCallback destroy
;
7894 /* Get supported styles and XIM values. */
7895 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
7898 destroy
.callback
= xim_destroy_callback
;
7899 destroy
.client_data
= (XPointer
)dpyinfo
;
7900 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
7906 #endif /* HAVE_XIM */
7907 dpyinfo
->xim
= NULL
;
7911 #ifdef HAVE_X11R6_XIM
7913 /* XIM instantiate callback function, which is called whenever an XIM
7914 server is available. DISPLAY is the display of the XIM.
7915 CLIENT_DATA contains a pointer to an xim_inst_t structure created
7916 when the callback was registered. */
7919 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
7921 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
7922 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
7924 /* We don't support multiple XIM connections. */
7928 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
7930 /* Create XIC for the existing frames on the same display, as long
7931 as they have no XIC. */
7932 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
7934 Lisp_Object tail
, frame
;
7937 FOR_EACH_FRAME (tail
, frame
)
7939 struct frame
*f
= XFRAME (frame
);
7942 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
7943 if (FRAME_XIC (f
) == NULL
)
7945 create_frame_xic (f
);
7946 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
7947 xic_set_statusarea (f
);
7948 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
7950 struct window
*w
= XWINDOW (f
->selected_window
);
7951 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
7960 #endif /* HAVE_X11R6_XIM */
7963 /* Open a connection to the XIM server on display DPYINFO.
7964 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
7965 connection only at the first time. On X11R6, open the connection
7966 in the XIM instantiate callback function. */
7969 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
7971 dpyinfo
->xim
= NULL
;
7975 #ifdef HAVE_X11R6_XIM
7976 struct xim_inst_t
*xim_inst
;
7979 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
7980 dpyinfo
->xim_callback_data
= xim_inst
;
7981 xim_inst
->dpyinfo
= dpyinfo
;
7982 len
= strlen (resource_name
);
7983 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
7984 memcpy (xim_inst
->resource_name
, resource_name
, len
+ 1);
7985 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
7986 resource_name
, EMACS_CLASS
,
7987 xim_instantiate_callback
,
7988 /* This is XPointer in XFree86
7989 but (XPointer *) on Tru64, at
7990 least, hence the configure test. */
7991 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
7992 #else /* not HAVE_X11R6_XIM */
7993 xim_open_dpy (dpyinfo
, resource_name
);
7994 #endif /* not HAVE_X11R6_XIM */
7996 #endif /* HAVE_XIM */
8000 /* Close the connection to the XIM server on display DPYINFO. */
8003 xim_close_dpy (struct x_display_info
*dpyinfo
)
8008 #ifdef HAVE_X11R6_XIM
8009 if (dpyinfo
->display
)
8010 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8012 xim_instantiate_callback
, NULL
);
8013 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8014 xfree (dpyinfo
->xim_callback_data
);
8015 #endif /* HAVE_X11R6_XIM */
8016 if (dpyinfo
->display
)
8017 XCloseIM (dpyinfo
->xim
);
8018 dpyinfo
->xim
= NULL
;
8019 XFree (dpyinfo
->xim_styles
);
8021 #endif /* HAVE_XIM */
8024 #endif /* not HAVE_X11R6_XIM */
8028 /* Calculate the absolute position in frame F
8029 from its current recorded position values and gravity. */
8032 x_calc_absolute_position (struct frame
*f
)
8034 int flags
= f
->size_hint_flags
;
8036 /* We have nothing to do if the current position
8037 is already for the top-left corner. */
8038 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8041 /* Treat negative positions as relative to the leftmost bottommost
8042 position that fits on the screen. */
8043 if (flags
& XNegative
)
8044 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8045 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8048 int height
= FRAME_PIXEL_HEIGHT (f
);
8050 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8051 /* Something is fishy here. When using Motif, starting Emacs with
8052 `-g -0-0', the frame appears too low by a few pixels.
8054 This seems to be so because initially, while Emacs is starting,
8055 the column widget's height and the frame's pixel height are
8056 different. The column widget's height is the right one. In
8057 later invocations, when Emacs is up, the frame's pixel height
8060 It's not obvious where the initial small difference comes from.
8061 2000-12-01, gerd. */
8063 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8066 if (flags
& YNegative
)
8067 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8068 - height
+ f
->top_pos
;
8071 /* The left_pos and top_pos
8072 are now relative to the top and left screen edges,
8073 so the flags should correspond. */
8074 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8077 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8078 to really change the position, and 0 when calling from
8079 x_make_frame_visible (in that case, XOFF and YOFF are the current
8080 position values). It is -1 when calling from x_set_frame_parameters,
8081 which means, do adjust for borders but don't change the gravity. */
8084 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8086 int modified_top
, modified_left
;
8088 if (change_gravity
> 0)
8090 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8091 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8095 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8097 f
->size_hint_flags
|= XNegative
;
8099 f
->size_hint_flags
|= YNegative
;
8100 f
->win_gravity
= NorthWestGravity
;
8102 x_calc_absolute_position (f
);
8105 x_wm_set_size_hint (f
, (long) 0, 0);
8107 modified_left
= f
->left_pos
;
8108 modified_top
= f
->top_pos
;
8110 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8112 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8113 than the WM decorations. So we use the calculated offset instead
8114 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8115 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8116 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8119 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8120 modified_left
, modified_top
);
8122 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8123 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8126 /* change_gravity is non-zero when this function is called from Lisp to
8127 programmatically move a frame. In that case, we call
8128 x_check_expected_move to discover if we have a "Type A" or "Type B"
8129 window manager, and, for a "Type A" window manager, adjust the position
8132 We call x_check_expected_move if a programmatic move occurred, and
8133 either the window manager type (A/B) is unknown or it is Type A but we
8134 need to compute the top/left offset adjustment for this frame. */
8136 if (change_gravity
!= 0 &&
8137 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8138 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8139 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8140 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8141 x_check_expected_move (f
, modified_left
, modified_top
);
8146 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8147 on the root window for frame F contains ATOMNAME.
8148 This is how a WM check shall be done according to the Window Manager
8149 Specification/Extended Window Manager Hints at
8150 http://freedesktop.org/wiki/Specifications/wm-spec. */
8153 wm_supports (struct frame
*f
, const char *atomname
)
8156 unsigned long actual_size
, bytes_remaining
;
8157 int i
, rc
, actual_format
;
8159 Window wmcheck_window
;
8160 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8161 Window target_window
= dpyinfo
->root_window
;
8162 long max_len
= 65536;
8163 Display
*dpy
= FRAME_X_DISPLAY (f
);
8164 unsigned char *tmp_data
= NULL
;
8165 Atom target_type
= XA_WINDOW
;
8170 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8172 x_catch_errors (dpy
);
8173 rc
= XGetWindowProperty (dpy
, target_window
,
8174 prop_atom
, 0, max_len
, False
, target_type
,
8175 &actual_type
, &actual_format
, &actual_size
,
8176 &bytes_remaining
, &tmp_data
);
8178 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8180 if (tmp_data
) XFree (tmp_data
);
8181 x_uncatch_errors ();
8186 wmcheck_window
= *(Window
*) tmp_data
;
8189 /* Check if window exists. */
8190 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8192 if (x_had_errors_p (dpy
))
8194 x_uncatch_errors ();
8199 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8201 /* Window changed, reload atoms */
8202 if (dpyinfo
->net_supported_atoms
!= NULL
)
8203 XFree (dpyinfo
->net_supported_atoms
);
8204 dpyinfo
->net_supported_atoms
= NULL
;
8205 dpyinfo
->nr_net_supported_atoms
= 0;
8206 dpyinfo
->net_supported_window
= 0;
8208 target_type
= XA_ATOM
;
8209 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8211 rc
= XGetWindowProperty (dpy
, target_window
,
8212 prop_atom
, 0, max_len
, False
, target_type
,
8213 &actual_type
, &actual_format
, &actual_size
,
8214 &bytes_remaining
, &tmp_data
);
8216 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8218 if (tmp_data
) XFree (tmp_data
);
8219 x_uncatch_errors ();
8224 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8225 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8226 dpyinfo
->net_supported_window
= wmcheck_window
;
8230 want_atom
= XInternAtom (dpy
, atomname
, False
);
8232 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8233 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8235 x_uncatch_errors ();
8242 set_wm_state (Lisp_Object frame
, int add
, const char *what
, const char *what2
)
8244 const char *atom
= "_NET_WM_STATE";
8245 Fx_send_client_event (frame
, make_number (0), frame
,
8246 make_unibyte_string (atom
, strlen (atom
)),
8248 /* 1 = add, 0 = remove */
8250 (make_number (add
? 1 : 0),
8252 (make_unibyte_string (what
, strlen (what
)),
8254 ? Fcons (make_unibyte_string (what2
, strlen (what2
)),
8260 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8264 XSETFRAME (frame
, f
);
8265 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8266 "_NET_WM_STATE_STICKY", NULL
);
8269 /* Do fullscreen as specified in extended window manager hints */
8272 do_ewmh_fullscreen (struct frame
*f
)
8274 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8276 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8277 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8279 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8284 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8285 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8286 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8288 XSETFRAME (frame
, f
);
8290 set_wm_state (frame
, 0, fs
, NULL
);
8291 set_wm_state (frame
, 0, fh
, NULL
);
8292 set_wm_state (frame
, 0, fw
, NULL
);
8294 /* If there are _NET_ atoms we assume we have extended window manager
8296 switch (f
->want_fullscreen
)
8298 case FULLSCREEN_BOTH
:
8299 set_wm_state (frame
, 1, fs
, NULL
);
8301 case FULLSCREEN_WIDTH
:
8302 set_wm_state (frame
, 1, fw
, NULL
);
8304 case FULLSCREEN_HEIGHT
:
8305 set_wm_state (frame
, 1, fh
, NULL
);
8307 case FULLSCREEN_MAXIMIZED
:
8308 set_wm_state (frame
, 1, fw
, fh
);
8312 f
->want_fullscreen
= FULLSCREEN_NONE
;
8316 return have_net_atom
;
8320 XTfullscreen_hook (FRAME_PTR f
)
8322 if (f
->async_visible
)
8325 x_check_fullscreen (f
);
8333 x_handle_net_wm_state (struct frame
*f
, XPropertyEvent
*event
)
8336 unsigned long actual_size
, bytes_remaining
;
8337 int i
, rc
, actual_format
, value
= FULLSCREEN_NONE
;
8338 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8339 long max_len
= 65536;
8340 Display
*dpy
= FRAME_X_DISPLAY (f
);
8341 unsigned char *tmp_data
= NULL
;
8342 Atom target_type
= XA_ATOM
;
8347 x_catch_errors (dpy
);
8348 rc
= XGetWindowProperty (dpy
, event
->window
,
8349 event
->atom
, 0, max_len
, False
, target_type
,
8350 &actual_type
, &actual_format
, &actual_size
,
8351 &bytes_remaining
, &tmp_data
);
8353 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8355 if (tmp_data
) XFree (tmp_data
);
8356 x_uncatch_errors ();
8361 x_uncatch_errors ();
8363 for (i
= 0; i
< actual_size
; ++i
)
8365 Atom a
= ((Atom
*)tmp_data
)[i
];
8366 if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8368 if (value
== FULLSCREEN_HEIGHT
)
8369 value
= FULLSCREEN_MAXIMIZED
;
8371 value
= FULLSCREEN_WIDTH
;
8373 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8375 if (value
== FULLSCREEN_WIDTH
)
8376 value
= FULLSCREEN_MAXIMIZED
;
8378 value
= FULLSCREEN_HEIGHT
;
8380 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen_atom
)
8381 value
= FULLSCREEN_BOTH
;
8382 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8389 case FULLSCREEN_WIDTH
:
8392 case FULLSCREEN_HEIGHT
:
8395 case FULLSCREEN_BOTH
:
8398 case FULLSCREEN_MAXIMIZED
:
8403 store_frame_param (f
, Qfullscreen
, lval
);
8404 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8406 if (tmp_data
) XFree (tmp_data
);
8410 /* Check if we need to resize the frame due to a fullscreen request.
8411 If so needed, resize the frame. */
8413 x_check_fullscreen (struct frame
*f
)
8415 if (do_ewmh_fullscreen (f
))
8418 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8419 return; /* Only fullscreen without WM or with EWM hints (above). */
8421 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8423 int width
= FRAME_COLS (f
), height
= FRAME_LINES (f
);
8424 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8426 switch (f
->want_fullscreen
)
8428 /* No difference between these two when there is no WM */
8429 case FULLSCREEN_BOTH
:
8430 case FULLSCREEN_MAXIMIZED
:
8431 width
= x_display_pixel_width (dpyinfo
);
8432 height
= x_display_pixel_height (dpyinfo
);
8434 case FULLSCREEN_WIDTH
:
8435 width
= x_display_pixel_width (dpyinfo
);
8437 case FULLSCREEN_HEIGHT
:
8438 height
= x_display_pixel_height (dpyinfo
);
8441 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8443 change_frame_size (f
, height
, width
, 0, 1, 0);
8444 SET_FRAME_GARBAGED (f
);
8445 cancel_mouse_face (f
);
8450 /* This function is called by x_set_offset to determine whether the window
8451 manager interfered with the positioning of the frame. Type A window
8452 managers position the surrounding window manager decorations a small
8453 amount above and left of the user-supplied position. Type B window
8454 managers position the surrounding window manager decorations at the
8455 user-specified position. If we detect a Type A window manager, we
8456 compensate by moving the window right and down by the proper amount. */
8459 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8461 int current_left
= 0, current_top
= 0;
8463 /* x_real_positions returns the left and top offsets of the outermost
8464 window manager window around the frame. */
8466 x_real_positions (f
, ¤t_left
, ¤t_top
);
8468 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8470 /* It's a "Type A" window manager. */
8475 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8476 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8477 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8479 /* Now fix the mispositioned frame's location. */
8481 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8482 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8484 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8485 adjusted_left
, adjusted_top
);
8487 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8490 /* It's a "Type B" window manager. We don't have to adjust the
8491 frame's position. */
8493 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8497 /* Wait for XGetGeometry to return up-to-date position information for a
8498 recently-moved frame. Call this immediately after calling XMoveWindow.
8499 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8500 frame has been moved to, so we use a fuzzy position comparison instead
8501 of an exact comparison. */
8504 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8508 while (count
++ < 50)
8510 int current_left
= 0, current_top
= 0;
8512 /* In theory, this call to XSync only needs to happen once, but in
8513 practice, it doesn't seem to work, hence the need for the surrounding
8516 XSync (FRAME_X_DISPLAY (f
), False
);
8517 x_real_positions (f
, ¤t_left
, ¤t_top
);
8521 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8524 if (eabs (current_left
- left
) <= 10
8525 && eabs (current_top
- top
) <= 40)
8528 else if (current_left
== left
&& current_top
== top
)
8532 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8533 will then return up-to-date position info. */
8535 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8539 /* Wait for an event on frame F matching EVENTTYPE. */
8541 x_wait_for_event (struct frame
*f
, int eventtype
)
8543 int level
= interrupt_input_blocked
;
8546 EMACS_TIME tmo
, tmo_at
, time_now
;
8547 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8549 pending_event_wait
.f
= f
;
8550 pending_event_wait
.eventtype
= eventtype
;
8552 /* Set timeout to 0.1 second. Hopefully not noticable.
8553 Maybe it should be configurable. */
8554 EMACS_SET_SECS_USECS (tmo
, 0, 100000);
8555 EMACS_GET_TIME (tmo_at
);
8556 EMACS_ADD_TIME (tmo_at
, tmo_at
, tmo
);
8558 while (pending_event_wait
.eventtype
)
8560 interrupt_input_pending
= 1;
8561 TOTALLY_UNBLOCK_INPUT
;
8562 /* XTread_socket is called after unblock. */
8564 interrupt_input_blocked
= level
;
8569 EMACS_GET_TIME (time_now
);
8570 EMACS_SUB_TIME (tmo
, tmo_at
, time_now
);
8572 if (EMACS_TIME_NEG_P (tmo
) || select (fd
+1, &fds
, NULL
, NULL
, &tmo
) == 0)
8573 break; /* Timeout */
8575 pending_event_wait
.f
= 0;
8576 pending_event_wait
.eventtype
= 0;
8580 /* Change the size of frame F's X window to COLS/ROWS in the case F
8581 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8582 top-left-corner window gravity for this size change and subsequent
8583 size changes. Otherwise we leave the window gravity unchanged. */
8586 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8588 int pixelwidth
, pixelheight
;
8590 check_frame_size (f
, &rows
, &cols
);
8591 f
->scroll_bar_actual_width
8592 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8594 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8596 compute_fringe_widths (f
, 0);
8598 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
)
8599 + FRAME_TOOLBAR_WIDTH (f
);
8600 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8601 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8603 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8604 x_wm_set_size_hint (f
, (long) 0, 0);
8605 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8606 pixelwidth
, pixelheight
);
8609 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8610 receive in the ConfigureNotify event; if we get what we asked
8611 for, then the event won't cause the screen to become garbaged, so
8612 we have to make sure to do it here. */
8613 SET_FRAME_GARBAGED (f
);
8615 /* Now, strictly speaking, we can't be sure that this is accurate,
8616 but the window manager will get around to dealing with the size
8617 change request eventually, and we'll hear how it went when the
8618 ConfigureNotify event gets here.
8620 We could just not bother storing any of this information here,
8621 and let the ConfigureNotify event set everything up, but that
8622 might be kind of confusing to the Lisp code, since size changes
8623 wouldn't be reported in the frame parameters until some random
8624 point in the future when the ConfigureNotify event arrives.
8626 We pass 1 for DELAY since we can't run Lisp code inside of
8629 /* But the ConfigureNotify may in fact never arrive, and then this is
8630 not right if the frame is visible. Instead wait (with timeout)
8631 for the ConfigureNotify. */
8632 if (f
->async_visible
)
8633 x_wait_for_event (f
, ConfigureNotify
);
8636 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8637 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8638 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8644 /* Call this to change the size of frame F's x-window.
8645 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8646 for this size change and subsequent size changes.
8647 Otherwise we leave the window gravity unchanged. */
8650 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8654 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8658 /* When the frame is maximized/fullscreen or running under for
8659 example Xmonad, x_set_window_size_1 will be a no-op.
8660 In that case, the right thing to do is extend rows/cols to
8661 the current frame size. We do that first if x_set_window_size_1
8662 turns out to not be a no-op (there is no way to know).
8663 The size will be adjusted again if the frame gets a
8664 ConfigureNotify event as a result of x_set_window_size. */
8665 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8666 #ifdef USE_X_TOOLKIT
8667 /* The menu bar is not part of text lines. The tool bar
8669 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8671 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8672 /* Update f->scroll_bar_actual_width because it is used in
8673 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8674 f
->scroll_bar_actual_width
8675 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8676 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8677 change_frame_size (f
, r
, c
, 0, 1, 0);
8681 if (FRAME_GTK_WIDGET (f
))
8682 xg_frame_set_char_size (f
, cols
, rows
);
8684 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8685 #else /* not USE_GTK */
8687 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8689 #endif /* not USE_GTK */
8691 /* If cursor was outside the new size, mark it as off. */
8692 mark_window_cursors_off (XWINDOW (f
->root_window
));
8694 /* Clear out any recollection of where the mouse highlighting was,
8695 since it might be in a place that's outside the new frame size.
8696 Actually checking whether it is outside is a pain in the neck,
8697 so don't try--just let the highlighting be done afresh with new size. */
8698 cancel_mouse_face (f
);
8703 /* Mouse warping. */
8706 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8710 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8711 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8713 if (pix_x
< 0) pix_x
= 0;
8714 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8716 if (pix_y
< 0) pix_y
= 0;
8717 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8721 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8722 0, 0, 0, 0, pix_x
, pix_y
);
8726 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8729 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8733 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8734 0, 0, 0, 0, pix_x
, pix_y
);
8738 /* focus shifting, raising and lowering. */
8741 x_focus_on_frame (struct frame
*f
)
8744 /* I don't think that the ICCCM allows programs to do things like this
8745 without the interaction of the window manager. Whatever you end up
8746 doing with this code, do it to x_unfocus_frame too. */
8747 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8748 RevertToPointerRoot
, CurrentTime
);
8753 x_unfocus_frame (struct frame
*f
)
8756 /* Look at the remarks in x_focus_on_frame. */
8757 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8758 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8759 RevertToPointerRoot
, CurrentTime
);
8763 /* Raise frame F. */
8766 x_raise_frame (struct frame
*f
)
8769 if (f
->async_visible
)
8770 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8772 XFlush (FRAME_X_DISPLAY (f
));
8776 /* Lower frame F. */
8779 x_lower_frame (struct frame
*f
)
8781 if (f
->async_visible
)
8784 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8785 XFlush (FRAME_X_DISPLAY (f
));
8790 /* Activate frame with Extended Window Manager Hints */
8793 x_ewmh_activate_frame (FRAME_PTR f
)
8795 /* See Window Manager Specification/Extended Window Manager Hints at
8796 http://freedesktop.org/wiki/Specifications/wm-spec */
8798 const char *atom
= "_NET_ACTIVE_WINDOW";
8799 if (f
->async_visible
&& wm_supports (f
, atom
))
8802 XSETFRAME (frame
, f
);
8803 Fx_send_client_event (frame
, make_number (0), frame
,
8804 make_unibyte_string (atom
, strlen (atom
)),
8806 Fcons (make_number (1),
8807 Fcons (make_number (last_user_time
),
8813 XTframe_raise_lower (FRAME_PTR f
, int raise_flag
)
8821 /* XEmbed implementation. */
8824 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
8827 unsigned long data
[2];
8829 atom
= XInternAtom (FRAME_X_DISPLAY (f
), "_XEMBED_INFO", False
);
8831 data
[0] = XEMBED_VERSION
;
8834 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), atom
, atom
,
8835 32, PropModeReplace
, (unsigned char *) data
, 2);
8839 xembed_send_message (struct frame
*f
, Time time
, enum xembed_message message
, long int detail
, long int data1
, long int data2
)
8843 event
.xclient
.type
= ClientMessage
;
8844 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
8845 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
8846 event
.xclient
.format
= 32;
8847 event
.xclient
.data
.l
[0] = time
;
8848 event
.xclient
.data
.l
[1] = message
;
8849 event
.xclient
.data
.l
[2] = detail
;
8850 event
.xclient
.data
.l
[3] = data1
;
8851 event
.xclient
.data
.l
[4] = data2
;
8853 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
8854 False
, NoEventMask
, &event
);
8855 XSync (FRAME_X_DISPLAY (f
), False
);
8858 /* Change of visibility. */
8860 /* This tries to wait until the frame is really visible.
8861 However, if the window manager asks the user where to position
8862 the frame, this will return before the user finishes doing that.
8863 The frame will not actually be visible at that time,
8864 but it will become visible later when the window manager
8865 finishes with it. */
8868 x_make_frame_visible (struct frame
*f
)
8871 int original_top
, original_left
;
8872 int retry_count
= 2;
8878 type
= x_icon_type (f
);
8880 x_bitmap_icon (f
, type
);
8882 if (! FRAME_VISIBLE_P (f
))
8884 /* We test FRAME_GARBAGED_P here to make sure we don't
8885 call x_set_offset a second time
8886 if we get to x_make_frame_visible a second time
8887 before the window gets really visible. */
8888 if (! FRAME_ICONIFIED_P (f
)
8889 && ! FRAME_X_EMBEDDED_P (f
)
8890 && ! f
->output_data
.x
->asked_for_visible
)
8891 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8893 f
->output_data
.x
->asked_for_visible
= 1;
8895 if (! EQ (Vx_no_window_manager
, Qt
))
8896 x_wm_set_window_state (f
, NormalState
);
8897 #ifdef USE_X_TOOLKIT
8898 if (FRAME_X_EMBEDDED_P (f
))
8899 xembed_set_info (f
, XEMBED_MAPPED
);
8902 /* This was XtPopup, but that did nothing for an iconified frame. */
8903 XtMapWidget (f
->output_data
.x
->widget
);
8905 #else /* not USE_X_TOOLKIT */
8907 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8908 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8910 if (FRAME_X_EMBEDDED_P (f
))
8911 xembed_set_info (f
, XEMBED_MAPPED
);
8913 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8914 #endif /* not USE_GTK */
8915 #endif /* not USE_X_TOOLKIT */
8918 XFlush (FRAME_X_DISPLAY (f
));
8920 /* Synchronize to ensure Emacs knows the frame is visible
8921 before we do anything else. We do this loop with input not blocked
8922 so that incoming events are handled. */
8926 /* This must be before UNBLOCK_INPUT
8927 since events that arrive in response to the actions above
8928 will set it when they are handled. */
8929 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8931 original_left
= f
->left_pos
;
8932 original_top
= f
->top_pos
;
8934 /* This must come after we set COUNT. */
8937 /* We unblock here so that arriving X events are processed. */
8939 /* Now move the window back to where it was "supposed to be".
8940 But don't do it if the gravity is negative.
8941 When the gravity is negative, this uses a position
8942 that is 3 pixels too low. Perhaps that's really the border width.
8944 Don't do this if the window has never been visible before,
8945 because the window manager may choose the position
8946 and we don't want to override it. */
8948 if (! FRAME_VISIBLE_P (f
)
8949 && ! FRAME_ICONIFIED_P (f
)
8950 && ! FRAME_X_EMBEDDED_P (f
)
8951 && f
->win_gravity
== NorthWestGravity
8952 && previously_visible
)
8956 unsigned int width
, height
, border
, depth
;
8960 /* On some window managers (such as FVWM) moving an existing
8961 window, even to the same place, causes the window manager
8962 to introduce an offset. This can cause the window to move
8963 to an unexpected location. Check the geometry (a little
8964 slow here) and then verify that the window is in the right
8965 place. If the window is not in the right place, move it
8966 there, and take the potential window manager hit. */
8967 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8968 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
8970 if (original_left
!= x
|| original_top
!= y
)
8971 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8972 original_left
, original_top
);
8977 XSETFRAME (frame
, f
);
8979 /* Wait until the frame is visible. Process X events until a
8980 MapNotify event has been seen, or until we think we won't get a
8981 MapNotify at all.. */
8982 for (count
= input_signal_count
+ 10;
8983 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
8985 /* Force processing of queued events. */
8988 /* Machines that do polling rather than SIGIO have been
8989 observed to go into a busy-wait here. So we'll fake an
8990 alarm signal to let the handler know that there's something
8991 to be read. We used to raise a real alarm, but it seems
8992 that the handler isn't always enabled here. This is
8994 if (input_polling_used ())
8996 /* It could be confusing if a real alarm arrives while
8997 processing the fake one. Turn it off and let the
8998 handler reset it. */
8999 int old_poll_suppress_count
= poll_suppress_count
;
9000 poll_suppress_count
= 1;
9001 poll_for_input_1 ();
9002 poll_suppress_count
= old_poll_suppress_count
;
9005 /* See if a MapNotify event has been processed. */
9006 FRAME_SAMPLE_VISIBILITY (f
);
9011 (let ((f (selected-frame)))
9015 the frame is not raised with various window managers on
9016 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9017 unknown reason, the call to XtMapWidget is completely ignored.
9018 Mapping the widget a second time works. */
9020 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9025 /* Change from mapped state to withdrawn state. */
9027 /* Make the frame visible (mapped and not iconified). */
9030 x_make_frame_invisible (struct frame
*f
)
9034 /* Use the frame's outermost window, not the one we normally draw on. */
9035 window
= FRAME_OUTER_WINDOW (f
);
9037 /* Don't keep the highlight on an invisible frame. */
9038 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9039 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9043 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9044 that the current position of the window is user-specified, rather than
9045 program-specified, so that when the window is mapped again, it will be
9046 placed at the same location, without forcing the user to position it
9047 by hand again (they have already done that once for this window.) */
9048 x_wm_set_size_hint (f
, (long) 0, 1);
9051 if (FRAME_GTK_OUTER_WIDGET (f
))
9052 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9055 if (FRAME_X_EMBEDDED_P (f
))
9056 xembed_set_info (f
, 0);
9061 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9062 DefaultScreen (FRAME_X_DISPLAY (f
))))
9064 UNBLOCK_INPUT_RESIGNAL
;
9065 error ("Can't notify window manager of window withdrawal");
9069 /* We can't distinguish this from iconification
9070 just by the event that we get from the server.
9071 So we can't win using the usual strategy of letting
9072 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9073 and synchronize with the server to make sure we agree. */
9075 FRAME_ICONIFIED_P (f
) = 0;
9076 f
->async_visible
= 0;
9077 f
->async_iconified
= 0;
9084 /* Change window state from mapped to iconified. */
9087 x_iconify_frame (struct frame
*f
)
9092 /* Don't keep the highlight on an invisible frame. */
9093 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9094 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9096 if (f
->async_iconified
)
9101 FRAME_SAMPLE_VISIBILITY (f
);
9103 type
= x_icon_type (f
);
9105 x_bitmap_icon (f
, type
);
9108 if (FRAME_GTK_OUTER_WIDGET (f
))
9110 if (! FRAME_VISIBLE_P (f
))
9111 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9113 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9116 f
->async_iconified
= 1;
9117 f
->async_visible
= 0;
9123 #ifdef USE_X_TOOLKIT
9125 if (! FRAME_VISIBLE_P (f
))
9127 if (! EQ (Vx_no_window_manager
, Qt
))
9128 x_wm_set_window_state (f
, IconicState
);
9129 /* This was XtPopup, but that did nothing for an iconified frame. */
9130 XtMapWidget (f
->output_data
.x
->widget
);
9131 /* The server won't give us any event to indicate
9132 that an invisible frame was changed to an icon,
9133 so we have to record it here. */
9136 f
->async_iconified
= 1;
9137 f
->async_visible
= 0;
9142 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9143 XtWindow (f
->output_data
.x
->widget
),
9144 DefaultScreen (FRAME_X_DISPLAY (f
)));
9148 error ("Can't notify window manager of iconification");
9150 f
->async_iconified
= 1;
9151 f
->async_visible
= 0;
9155 XFlush (FRAME_X_DISPLAY (f
));
9157 #else /* not USE_X_TOOLKIT */
9159 /* Make sure the X server knows where the window should be positioned,
9160 in case the user deiconifies with the window manager. */
9161 if (! FRAME_VISIBLE_P (f
)
9162 && ! FRAME_ICONIFIED_P (f
)
9163 && ! FRAME_X_EMBEDDED_P (f
))
9164 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9166 /* Since we don't know which revision of X we're running, we'll use both
9167 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9169 /* X11R4: send a ClientMessage to the window manager using the
9170 WM_CHANGE_STATE type. */
9174 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9175 message
.xclient
.type
= ClientMessage
;
9176 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9177 message
.xclient
.format
= 32;
9178 message
.xclient
.data
.l
[0] = IconicState
;
9180 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9181 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9183 SubstructureRedirectMask
| SubstructureNotifyMask
,
9186 UNBLOCK_INPUT_RESIGNAL
;
9187 error ("Can't notify window manager of iconification");
9191 /* X11R3: set the initial_state field of the window manager hints to
9193 x_wm_set_window_state (f
, IconicState
);
9195 if (!FRAME_VISIBLE_P (f
))
9197 /* If the frame was withdrawn, before, we must map it. */
9198 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9201 f
->async_iconified
= 1;
9202 f
->async_visible
= 0;
9204 XFlush (FRAME_X_DISPLAY (f
));
9206 #endif /* not USE_X_TOOLKIT */
9210 /* Free X resources of frame F. */
9213 x_free_frame_resources (struct frame
*f
)
9215 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9217 struct scroll_bar
*b
;
9221 /* If a display connection is dead, don't try sending more
9222 commands to the X server. */
9223 if (dpyinfo
->display
)
9225 /* We must free faces before destroying windows because some
9226 font-driver (e.g. xft) access a window while finishing a
9228 if (FRAME_FACE_CACHE (f
))
9229 free_frame_faces (f
);
9231 if (f
->output_data
.x
->icon_desc
)
9232 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9234 #ifdef USE_X_TOOLKIT
9235 /* Explicitly destroy the scroll bars of the frame. Without
9236 this, we get "BadDrawable" errors from the toolkit later on,
9237 presumably from expose events generated for the disappearing
9238 toolkit scroll bars. */
9239 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9241 b
= XSCROLL_BAR (bar
);
9242 x_scroll_bar_remove (b
);
9251 #ifdef USE_X_TOOLKIT
9252 if (f
->output_data
.x
->widget
)
9254 XtDestroyWidget (f
->output_data
.x
->widget
);
9255 f
->output_data
.x
->widget
= NULL
;
9257 /* Tooltips don't have widgets, only a simple X window, even if
9258 we are using a toolkit. */
9259 else if (FRAME_X_WINDOW (f
))
9260 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9262 free_frame_menubar (f
);
9263 #else /* !USE_X_TOOLKIT */
9266 xg_free_frame_widgets (f
);
9267 #endif /* USE_GTK */
9269 if (FRAME_X_WINDOW (f
))
9270 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9271 #endif /* !USE_X_TOOLKIT */
9273 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9274 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9275 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9276 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9277 unload_color (f
, f
->output_data
.x
->border_pixel
);
9278 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9280 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9281 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9282 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9283 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9284 #ifdef USE_TOOLKIT_SCROLL_BARS
9285 /* Scrollbar shadow colors. */
9286 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9287 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9288 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9289 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9290 #endif /* USE_TOOLKIT_SCROLL_BARS */
9291 if (f
->output_data
.x
->white_relief
.allocated_p
)
9292 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9293 if (f
->output_data
.x
->black_relief
.allocated_p
)
9294 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9297 XFlush (FRAME_X_DISPLAY (f
));
9300 xfree (f
->output_data
.x
->saved_menu_event
);
9301 xfree (f
->output_data
.x
);
9302 f
->output_data
.x
= NULL
;
9304 if (f
== dpyinfo
->x_focus_frame
)
9305 dpyinfo
->x_focus_frame
= 0;
9306 if (f
== dpyinfo
->x_focus_event_frame
)
9307 dpyinfo
->x_focus_event_frame
= 0;
9308 if (f
== dpyinfo
->x_highlight_frame
)
9309 dpyinfo
->x_highlight_frame
= 0;
9311 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9313 dpyinfo
->mouse_face_beg_row
9314 = dpyinfo
->mouse_face_beg_col
= -1;
9315 dpyinfo
->mouse_face_end_row
9316 = dpyinfo
->mouse_face_end_col
= -1;
9317 dpyinfo
->mouse_face_window
= Qnil
;
9318 dpyinfo
->mouse_face_deferred_gc
= 0;
9319 dpyinfo
->mouse_face_mouse_frame
= 0;
9326 /* Destroy the X window of frame F. */
9329 x_destroy_window (struct frame
*f
)
9331 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9333 /* If a display connection is dead, don't try sending more
9334 commands to the X server. */
9335 if (dpyinfo
->display
!= 0)
9336 x_free_frame_resources (f
);
9338 dpyinfo
->reference_count
--;
9342 /* Setting window manager hints. */
9344 /* Set the normal size hints for the window manager, for frame F.
9345 FLAGS is the flags word to use--or 0 meaning preserve the flags
9346 that the window now has.
9347 If USER_POSITION is nonzero, we set the USPosition
9348 flag (this is useful when FLAGS is 0).
9349 The GTK version is in gtkutils.c */
9353 x_wm_set_size_hint (struct frame
*f
, long flags
, int user_position
)
9355 XSizeHints size_hints
;
9356 Window window
= FRAME_OUTER_WINDOW (f
);
9358 /* Setting PMaxSize caused various problems. */
9359 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9361 size_hints
.x
= f
->left_pos
;
9362 size_hints
.y
= f
->top_pos
;
9364 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9365 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9367 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9368 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9369 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9370 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9371 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9372 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9374 /* Calculate the base and minimum sizes. */
9376 int base_width
, base_height
;
9377 int min_rows
= 0, min_cols
= 0;
9379 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9380 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9382 check_frame_size (f
, &min_rows
, &min_cols
);
9384 /* The window manager uses the base width hints to calculate the
9385 current number of rows and columns in the frame while
9386 resizing; min_width and min_height aren't useful for this
9387 purpose, since they might not give the dimensions for a
9388 zero-row, zero-column frame.
9390 We use the base_width and base_height members if we have
9391 them; otherwise, we set the min_width and min_height members
9392 to the size for a zero x zero frame. */
9394 size_hints
.flags
|= PBaseSize
;
9395 size_hints
.base_width
= base_width
;
9396 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9397 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9398 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9401 /* If we don't need the old flags, we don't need the old hint at all. */
9404 size_hints
.flags
|= flags
;
9409 XSizeHints hints
; /* Sometimes I hate X Windows... */
9410 long supplied_return
;
9413 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9417 size_hints
.flags
|= flags
;
9422 if (hints
.flags
& PSize
)
9423 size_hints
.flags
|= PSize
;
9424 if (hints
.flags
& PPosition
)
9425 size_hints
.flags
|= PPosition
;
9426 if (hints
.flags
& USPosition
)
9427 size_hints
.flags
|= USPosition
;
9428 if (hints
.flags
& USSize
)
9429 size_hints
.flags
|= USSize
;
9436 size_hints
.win_gravity
= f
->win_gravity
;
9437 size_hints
.flags
|= PWinGravity
;
9441 size_hints
.flags
&= ~ PPosition
;
9442 size_hints
.flags
|= USPosition
;
9444 #endif /* PWinGravity */
9446 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9448 #endif /* not USE_GTK */
9450 /* Used for IconicState or NormalState */
9453 x_wm_set_window_state (struct frame
*f
, int state
)
9455 #ifdef USE_X_TOOLKIT
9458 XtSetArg (al
[0], XtNinitialState
, state
);
9459 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9460 #else /* not USE_X_TOOLKIT */
9461 Window window
= FRAME_X_WINDOW (f
);
9463 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9464 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9466 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9467 #endif /* not USE_X_TOOLKIT */
9471 x_wm_set_icon_pixmap (struct frame
*f
, int pixmap_id
)
9473 Pixmap icon_pixmap
, icon_mask
;
9475 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9476 Window window
= FRAME_OUTER_WINDOW (f
);
9481 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9482 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9483 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9484 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9488 /* It seems there is no way to turn off use of an icon
9496 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9500 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9504 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9505 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9506 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9507 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9510 #else /* not USE_X_TOOLKIT && not USE_GTK */
9512 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9513 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9515 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9519 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9521 Window window
= FRAME_OUTER_WINDOW (f
);
9523 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9524 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9525 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9527 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9531 /***********************************************************************
9533 ***********************************************************************/
9537 /* Check that FONT is valid on frame F. It is if it can be found in F's
9541 x_check_font (struct frame
*f
, struct font
*font
)
9545 xassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9546 if (font
->driver
->check
)
9547 xassert (font
->driver
->check (f
, font
) == 0);
9550 #endif /* GLYPH_DEBUG != 0 */
9553 /***********************************************************************
9555 ***********************************************************************/
9557 #ifdef USE_X_TOOLKIT
9558 static XrmOptionDescRec emacs_options
[] = {
9559 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9560 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9562 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9563 XrmoptionSepArg
, NULL
},
9564 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9566 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9567 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9568 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9569 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9570 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9571 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9572 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9575 /* Whether atimer for Xt timeouts is activated or not. */
9577 static int x_timeout_atimer_activated_flag
;
9579 #endif /* USE_X_TOOLKIT */
9581 static int x_initialized
;
9584 static int x_session_initialized
;
9587 /* Test whether two display-name strings agree up to the dot that separates
9588 the screen number from the server number. */
9590 same_x_server (const char *name1
, const char *name2
)
9593 const unsigned char *system_name
= SDATA (Vsystem_name
);
9594 int system_name_length
= strlen (system_name
);
9595 int length_until_period
= 0;
9597 while (system_name
[length_until_period
] != 0
9598 && system_name
[length_until_period
] != '.')
9599 length_until_period
++;
9601 /* Treat `unix' like an empty host name. */
9602 if (! strncmp (name1
, "unix:", 5))
9604 if (! strncmp (name2
, "unix:", 5))
9606 /* Treat this host's name like an empty host name. */
9607 if (! strncmp (name1
, system_name
, system_name_length
)
9608 && name1
[system_name_length
] == ':')
9609 name1
+= system_name_length
;
9610 if (! strncmp (name2
, system_name
, system_name_length
)
9611 && name2
[system_name_length
] == ':')
9612 name2
+= system_name_length
;
9613 /* Treat this host's domainless name like an empty host name. */
9614 if (! strncmp (name1
, system_name
, length_until_period
)
9615 && name1
[length_until_period
] == ':')
9616 name1
+= length_until_period
;
9617 if (! strncmp (name2
, system_name
, length_until_period
)
9618 && name2
[length_until_period
] == ':')
9619 name2
+= length_until_period
;
9621 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9625 if (seen_colon
&& *name1
== '.')
9629 && (*name1
== '.' || *name1
== '\0')
9630 && (*name2
== '.' || *name2
== '\0'));
9633 /* Count number of set bits in mask and number of bits to shift to
9634 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9637 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9658 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9659 But don't permanently open it, just test its availability. */
9662 x_display_ok (const char *display
)
9667 dpy
= XOpenDisplay (display
);
9669 XCloseDisplay (dpy
);
9677 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
, const gchar
*message
, gpointer user_data
)
9679 if (!strstr (message
, "g_set_prgname"))
9680 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, message
);
9684 /* Open a connection to X display DISPLAY_NAME, and return
9685 the structure that describes the open display.
9686 If we cannot contact the display, return null. */
9688 struct x_display_info
*
9689 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9693 struct terminal
*terminal
;
9694 struct x_display_info
*dpyinfo
;
9705 if (! x_display_ok (SDATA (display_name
)))
9706 error ("Display %s can't be opened", SDATA (display_name
));
9712 char *argv
[NUM_ARGV
];
9713 char **argv2
= argv
;
9716 if (x_initialized
++ > 1)
9718 xg_display_open (SDATA (display_name
), &dpy
);
9722 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9726 argv
[argc
++] = initial_argv
[0];
9728 if (! NILP (display_name
))
9730 argv
[argc
++] = "--display";
9731 argv
[argc
++] = SDATA (display_name
);
9734 argv
[argc
++] = "--name";
9735 argv
[argc
++] = resource_name
;
9737 XSetLocaleModifiers ("");
9739 /* Work around GLib bug that outputs a faulty warning. See
9740 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9741 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9742 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9743 gtk_init (&argc
, &argv2
);
9744 g_log_remove_handler ("GLib", id
);
9746 /* gtk_init does set_locale. We must fix locale after calling it. */
9750 dpy
= GDK_DISPLAY ();
9752 /* NULL window -> events for all windows go to our function */
9753 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9755 /* Load our own gtkrc if it exists. */
9757 char *file
= "~/.emacs.d/gtkrc";
9758 Lisp_Object s
, abs_file
;
9760 s
= make_string (file
, strlen (file
));
9761 abs_file
= Fexpand_file_name (s
, Qnil
);
9763 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
9764 gtk_rc_parse (SDATA (abs_file
));
9767 XSetErrorHandler (x_error_handler
);
9768 XSetIOErrorHandler (x_io_error_quitter
);
9771 #else /* not USE_GTK */
9772 #ifdef USE_X_TOOLKIT
9773 /* weiner@footloose.sps.mot.com reports that this causes
9775 X protocol error: BadAtom (invalid Atom parameter)
9776 on protocol request 18skiloaf.
9777 So let's not use it until R6. */
9779 XtSetLanguageProc (NULL
, NULL
, NULL
);
9790 argv
[argc
++] = "-xrm";
9791 argv
[argc
++] = xrm_option
;
9793 turn_on_atimers (0);
9794 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
9795 resource_name
, EMACS_CLASS
,
9796 emacs_options
, XtNumber (emacs_options
),
9798 turn_on_atimers (1);
9801 /* I think this is to compensate for XtSetLanguageProc. */
9806 #else /* not USE_X_TOOLKIT */
9807 XSetLocaleModifiers ("");
9808 dpy
= XOpenDisplay (SDATA (display_name
));
9809 #endif /* not USE_X_TOOLKIT */
9810 #endif /* not USE_GTK*/
9812 /* Detect failure. */
9819 /* We have definitely succeeded. Record the new connection. */
9821 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
9822 memset (dpyinfo
, 0, sizeof *dpyinfo
);
9824 terminal
= x_create_terminal (dpyinfo
);
9827 struct x_display_info
*share
;
9830 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
9831 share
= share
->next
, tail
= XCDR (tail
))
9832 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
9833 SDATA (display_name
)))
9836 terminal
->kboard
= share
->terminal
->kboard
;
9839 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
9840 init_kboard (terminal
->kboard
);
9841 terminal
->kboard
->Vwindow_system
= Qx
;
9843 /* Add the keyboard to the list before running Lisp code (via
9844 Qvendor_specific_keysyms below), since these are not traced
9845 via terminals but only through all_kboards. */
9846 terminal
->kboard
->next_kboard
= all_kboards
;
9847 all_kboards
= terminal
->kboard
;
9849 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
9851 char *vendor
= ServerVendor (dpy
);
9853 /* Protect terminal from GC before removing it from the
9854 list of terminals. */
9855 struct gcpro gcpro1
;
9856 Lisp_Object gcpro_term
;
9857 XSETTERMINAL (gcpro_term
, terminal
);
9858 GCPRO1 (gcpro_term
);
9860 /* Temporarily hide the partially initialized terminal. */
9861 terminal_list
= terminal
->next_terminal
;
9863 terminal
->kboard
->Vsystem_key_alist
9864 = call1 (Qvendor_specific_keysyms
,
9865 vendor
? build_string (vendor
) : empty_unibyte_string
);
9867 terminal
->next_terminal
= terminal_list
;
9868 terminal_list
= terminal
;
9872 /* Don't let the initial kboard remain current longer than necessary.
9873 That would cause problems if a file loaded on startup tries to
9874 prompt in the mini-buffer. */
9875 if (current_kboard
== initial_kboard
)
9876 current_kboard
= terminal
->kboard
;
9878 terminal
->kboard
->reference_count
++;
9881 /* Put this display on the chain. */
9882 dpyinfo
->next
= x_display_list
;
9883 x_display_list
= dpyinfo
;
9885 /* Put it on x_display_name_list as well, to keep them parallel. */
9886 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
9887 x_display_name_list
);
9888 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
9890 dpyinfo
->display
= dpy
;
9892 /* Set the name of the terminal. */
9893 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
9894 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
9895 terminal
->name
[SBYTES (display_name
)] = 0;
9898 XSetAfterFunction (x_current_display
, x_trace_wire
);
9902 = (char *) xmalloc (SBYTES (Vinvocation_name
)
9903 + SBYTES (Vsystem_name
)
9905 sprintf (dpyinfo
->x_id_name
, "%s@%s",
9906 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
9908 /* Figure out which modifier bits mean what. */
9909 x_find_modifier_meanings (dpyinfo
);
9911 /* Get the scroll bar cursor. */
9913 /* We must create a GTK cursor, it is required for GTK widgets. */
9914 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
9915 #endif /* USE_GTK */
9917 dpyinfo
->vertical_scroll_bar_cursor
9918 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
9920 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
9921 resource_name
, EMACS_CLASS
);
9922 #ifdef HAVE_XRMSETDATABASE
9923 XrmSetDatabase (dpyinfo
->display
, xrdb
);
9925 dpyinfo
->display
->db
= xrdb
;
9927 /* Put the rdb where we can find it in a way that works on
9929 dpyinfo
->xrdb
= xrdb
;
9931 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
9932 DefaultScreen (dpyinfo
->display
));
9933 select_visual (dpyinfo
);
9934 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
9935 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
9936 dpyinfo
->client_leader_window
= 0;
9937 dpyinfo
->grabbed
= 0;
9938 dpyinfo
->reference_count
= 0;
9939 dpyinfo
->icon_bitmap_id
= -1;
9940 dpyinfo
->n_fonts
= 0;
9941 dpyinfo
->bitmaps
= 0;
9942 dpyinfo
->bitmaps_size
= 0;
9943 dpyinfo
->bitmaps_last
= 0;
9944 dpyinfo
->scratch_cursor_gc
= 0;
9945 dpyinfo
->mouse_face_mouse_frame
= 0;
9946 dpyinfo
->mouse_face_deferred_gc
= 0;
9947 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
9948 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
9949 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
9950 dpyinfo
->mouse_face_window
= Qnil
;
9951 dpyinfo
->mouse_face_overlay
= Qnil
;
9952 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
9953 dpyinfo
->mouse_face_defer
= 0;
9954 dpyinfo
->mouse_face_hidden
= 0;
9955 dpyinfo
->x_focus_frame
= 0;
9956 dpyinfo
->x_focus_event_frame
= 0;
9957 dpyinfo
->x_highlight_frame
= 0;
9958 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
9960 /* See if we can construct pixel values from RGB values. */
9961 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
9962 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
9964 if (dpyinfo
->visual
->class == TrueColor
)
9966 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
9967 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
9968 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
9969 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
9970 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
9971 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
9974 /* See if a private colormap is requested. */
9975 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
9977 if (dpyinfo
->visual
->class == PseudoColor
)
9980 value
= display_x_get_resource (dpyinfo
,
9981 build_string ("privateColormap"),
9982 build_string ("PrivateColormap"),
9985 && (!strcmp (SDATA (value
), "true")
9986 || !strcmp (SDATA (value
), "on")))
9987 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
9991 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
9992 dpyinfo
->visual
, AllocNone
);
9996 /* If we are using Xft, check dpi value in X resources.
9997 It is better we use it as well, since Xft will use it, as will all
9998 Gnome applications. If our real DPI is smaller or larger than the
9999 one Xft uses, our font will look smaller or larger than other
10000 for other applications, even if it is the same font name (monospace-10
10002 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10004 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10005 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10009 if (dpyinfo
->resy
< 1)
10011 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10012 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10013 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10014 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10015 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10016 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10017 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10018 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10019 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10022 dpyinfo
->Xatom_wm_protocols
10023 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10024 dpyinfo
->Xatom_wm_take_focus
10025 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10026 dpyinfo
->Xatom_wm_save_yourself
10027 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10028 dpyinfo
->Xatom_wm_delete_window
10029 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10030 dpyinfo
->Xatom_wm_change_state
10031 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10032 dpyinfo
->Xatom_wm_configure_denied
10033 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10034 dpyinfo
->Xatom_wm_window_moved
10035 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10036 dpyinfo
->Xatom_wm_client_leader
10037 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10038 dpyinfo
->Xatom_editres
10039 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10040 dpyinfo
->Xatom_CLIPBOARD
10041 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10042 dpyinfo
->Xatom_TIMESTAMP
10043 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10044 dpyinfo
->Xatom_TEXT
10045 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10046 dpyinfo
->Xatom_COMPOUND_TEXT
10047 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10048 dpyinfo
->Xatom_UTF8_STRING
10049 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10050 dpyinfo
->Xatom_DELETE
10051 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10052 dpyinfo
->Xatom_MULTIPLE
10053 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10054 dpyinfo
->Xatom_INCR
10055 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10056 dpyinfo
->Xatom_EMACS_TMP
10057 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10058 dpyinfo
->Xatom_TARGETS
10059 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10060 dpyinfo
->Xatom_NULL
10061 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10062 dpyinfo
->Xatom_ATOM_PAIR
10063 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10064 /* For properties of font. */
10065 dpyinfo
->Xatom_PIXEL_SIZE
10066 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10067 dpyinfo
->Xatom_AVERAGE_WIDTH
10068 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10069 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10070 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10071 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10072 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10073 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10074 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10076 /* Ghostscript support. */
10077 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10078 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10080 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10083 dpyinfo
->Xatom_XEMBED
= XInternAtom (dpyinfo
->display
, "_XEMBED",
10086 dpyinfo
->Xatom_net_wm_state
10087 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE", False
);
10088 dpyinfo
->Xatom_net_wm_state_fullscreen_atom
10089 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_FULLSCREEN", False
);
10090 dpyinfo
->Xatom_net_wm_state_maximized_horz
10091 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_HORZ", False
);
10092 dpyinfo
->Xatom_net_wm_state_maximized_vert
10093 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_VERT", False
);
10094 dpyinfo
->Xatom_net_wm_state_sticky
10095 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_STICKY", False
);
10096 dpyinfo
->Xatom_net_window_type
10097 = XInternAtom (dpyinfo
->display
, "_NET_WM_WINDOW_TYPE", False
);
10098 dpyinfo
->Xatom_net_window_type_tooltip
10099 = XInternAtom (dpyinfo
->display
, "_NET_WM_WINDOW_TYPE_TOOLTIP", False
);
10100 dpyinfo
->Xatom_net_wm_icon_name
10101 = XInternAtom (dpyinfo
->display
, "_NET_WM_ICON_NAME", False
);
10102 dpyinfo
->Xatom_net_wm_name
10103 = XInternAtom (dpyinfo
->display
, "_NET_WM_NAME", False
);
10105 dpyinfo
->cut_buffers_initialized
= 0;
10107 dpyinfo
->x_dnd_atoms_size
= 8;
10108 dpyinfo
->x_dnd_atoms_length
= 0;
10109 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
10110 * dpyinfo
->x_dnd_atoms_size
);
10112 dpyinfo
->net_supported_atoms
= NULL
;
10113 dpyinfo
->nr_net_supported_atoms
= 0;
10114 dpyinfo
->net_supported_window
= 0;
10116 connection
= ConnectionNumber (dpyinfo
->display
);
10117 dpyinfo
->connection
= connection
;
10121 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10123 gray_bitmap_width
, gray_bitmap_height
,
10124 (unsigned long) 1, (unsigned long) 0, 1);
10128 xim_initialize (dpyinfo
, resource_name
);
10131 xsettings_initialize (dpyinfo
);
10133 /* This is only needed for distinguishing keyboard and process input. */
10134 if (connection
!= 0)
10135 add_keyboard_wait_descriptor (connection
);
10138 fcntl (connection
, F_SETOWN
, getpid ());
10139 #endif /* ! defined (F_SETOWN) */
10142 if (interrupt_input
)
10143 init_sigio (connection
);
10144 #endif /* ! defined (SIGIO) */
10148 Display
*dpy
= dpyinfo
->display
;
10149 XrmValue d
, fr
, to
;
10152 d
.addr
= (XPointer
)&dpy
;
10153 d
.size
= sizeof (Display
*);
10154 fr
.addr
= XtDefaultFont
;
10155 fr
.size
= sizeof (XtDefaultFont
);
10156 to
.size
= sizeof (Font
*);
10157 to
.addr
= (XPointer
)&font
;
10158 x_catch_errors (dpy
);
10159 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10161 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10162 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10163 x_uncatch_errors ();
10167 /* See if we should run in synchronous mode. This is useful
10168 for debugging X code. */
10171 value
= display_x_get_resource (dpyinfo
,
10172 build_string ("synchronous"),
10173 build_string ("Synchronous"),
10175 if (STRINGP (value
)
10176 && (!strcmp (SDATA (value
), "true")
10177 || !strcmp (SDATA (value
), "on")))
10178 XSynchronize (dpyinfo
->display
, True
);
10183 value
= display_x_get_resource (dpyinfo
,
10184 build_string ("useXIM"),
10185 build_string ("UseXIM"),
10188 if (STRINGP (value
)
10189 && (!strcmp (SDATA (value
), "false")
10190 || !strcmp (SDATA (value
), "off")))
10193 if (STRINGP (value
)
10194 && (!strcmp (SDATA (value
), "true")
10195 || !strcmp (SDATA (value
), "on")))
10201 /* Only do this for the very first display in the Emacs session.
10202 Ignore X session management when Emacs was first started on a
10204 if (terminal
->id
== 1)
10205 x_session_initialize (dpyinfo
);
10213 /* Get rid of display DPYINFO, deleting all frames on it,
10214 and without sending any more commands to the X server. */
10217 x_delete_display (struct x_display_info
*dpyinfo
)
10219 struct terminal
*t
;
10221 /* Close all frames and delete the generic struct terminal for this
10223 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10224 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10227 /* Close X session management when we close its display. */
10228 if (t
->id
== 1 && x_session_have_connection ())
10229 x_session_close ();
10231 delete_terminal (t
);
10235 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10237 /* Discard this display from x_display_name_list and x_display_list.
10238 We can't use Fdelq because that can quit. */
10239 if (! NILP (x_display_name_list
)
10240 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10241 x_display_name_list
= XCDR (x_display_name_list
);
10246 tail
= x_display_name_list
;
10247 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10249 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10251 XSETCDR (tail
, XCDR (XCDR (tail
)));
10254 tail
= XCDR (tail
);
10258 if (next_noop_dpyinfo
== dpyinfo
)
10259 next_noop_dpyinfo
= dpyinfo
->next
;
10261 if (x_display_list
== dpyinfo
)
10262 x_display_list
= dpyinfo
->next
;
10265 struct x_display_info
*tail
;
10267 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10268 if (tail
->next
== dpyinfo
)
10269 tail
->next
= tail
->next
->next
;
10272 xfree (dpyinfo
->x_id_name
);
10273 xfree (dpyinfo
->x_dnd_atoms
);
10274 xfree (dpyinfo
->color_cells
);
10278 #ifdef USE_X_TOOLKIT
10280 /* Atimer callback function for TIMER. Called every 0.1s to process
10281 Xt timeouts, if needed. We must avoid calling XtAppPending as
10282 much as possible because that function does an implicit XFlush
10283 that slows us down. */
10286 x_process_timeouts (struct atimer
*timer
)
10289 x_timeout_atimer_activated_flag
= 0;
10290 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10292 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10293 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10294 /* Reactivate the atimer for next time. */
10295 x_activate_timeout_atimer ();
10300 /* Install an asynchronous timer that processes Xt timeout events
10301 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10302 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10303 function whenever these variables are set. This is necessary
10304 because some widget sets use timeouts internally, for example the
10305 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10306 processed, these widgets don't behave normally. */
10309 x_activate_timeout_atimer (void)
10312 if (!x_timeout_atimer_activated_flag
)
10314 EMACS_TIME interval
;
10316 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10317 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10318 x_timeout_atimer_activated_flag
= 1;
10323 #endif /* USE_X_TOOLKIT */
10326 /* Set up use of X before we make the first connection. */
10328 extern frame_parm_handler x_frame_parm_handlers
[];
10330 static struct redisplay_interface x_redisplay_interface
=
10332 x_frame_parm_handlers
,
10336 x_clear_end_of_line
,
10338 x_after_update_window_line
,
10339 x_update_window_begin
,
10340 x_update_window_end
,
10346 0, /* flush_display_optional */
10348 x_clear_window_mouse_face
,
10349 x_get_glyph_overhangs
,
10350 x_fix_overlapping_area
,
10351 x_draw_fringe_bitmap
,
10352 0, /* define_fringe_bitmap */
10353 0, /* destroy_fringe_bitmap */
10354 x_compute_glyph_string_overhangs
,
10355 x_draw_glyph_string
,
10356 x_define_frame_cursor
,
10357 x_clear_frame_area
,
10358 x_draw_window_cursor
,
10359 x_draw_vertical_window_border
,
10360 x_shift_glyphs_for_insert
10364 /* This function is called when the last frame on a display is deleted. */
10366 x_delete_terminal (struct terminal
*terminal
)
10368 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10370 /* Protect against recursive calls. delete_frame in
10371 delete_terminal calls us back when it deletes our last frame. */
10372 if (!terminal
->name
)
10377 /* We must close our connection to the XIM server before closing the
10380 xim_close_dpy (dpyinfo
);
10383 /* If called from x_connection_closed, the display may already be closed
10384 and dpyinfo->display was set to 0 to indicate that. */
10385 if (dpyinfo
->display
)
10387 x_destroy_all_bitmaps (dpyinfo
);
10388 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10390 /* Whether or not XCloseDisplay destroys the associated resource
10391 database depends on the version of libX11. To avoid both
10392 crash and memory leak, we dissociate the database from the
10393 display and then destroy dpyinfo->xrdb ourselves.
10395 Unfortunately, the above strategy does not work in some
10396 situations due to a bug in newer versions of libX11: because
10397 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10398 dpy->db is NULL, XCloseDisplay destroys the associated
10399 database whereas it has not been created by XGetDefault
10400 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10401 don't destroy the database here in order to avoid the crash
10402 in the above situations for now, though that may cause memory
10403 leaks in other situations. */
10405 #ifdef HAVE_XRMSETDATABASE
10406 XrmSetDatabase (dpyinfo
->display
, NULL
);
10408 dpyinfo
->display
->db
= NULL
;
10410 /* We used to call XrmDestroyDatabase from x_delete_display, but
10411 some older versions of libX11 crash if we call it after
10412 closing all the displays. */
10413 XrmDestroyDatabase (dpyinfo
->xrdb
);
10417 xg_display_close (dpyinfo
->display
);
10419 #ifdef USE_X_TOOLKIT
10420 XtCloseDisplay (dpyinfo
->display
);
10422 XCloseDisplay (dpyinfo
->display
);
10424 #endif /* ! USE_GTK */
10427 /* Mark as dead. */
10428 dpyinfo
->display
= NULL
;
10429 x_delete_display (dpyinfo
);
10433 /* Create a struct terminal, initialize it with the X11 specific
10434 functions and make DISPLAY->TERMINAL point to it. */
10436 static struct terminal
*
10437 x_create_terminal (struct x_display_info
*dpyinfo
)
10439 struct terminal
*terminal
;
10441 terminal
= create_terminal ();
10443 terminal
->type
= output_x_window
;
10444 terminal
->display_info
.x
= dpyinfo
;
10445 dpyinfo
->terminal
= terminal
;
10447 /* kboard is initialized in x_term_init. */
10449 terminal
->clear_frame_hook
= x_clear_frame
;
10450 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10451 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10452 terminal
->ring_bell_hook
= XTring_bell
;
10453 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10454 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10455 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
10456 terminal
->update_begin_hook
= x_update_begin
;
10457 terminal
->update_end_hook
= x_update_end
;
10458 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
10459 terminal
->read_socket_hook
= XTread_socket
;
10460 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10461 terminal
->mouse_position_hook
= XTmouse_position
;
10462 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10463 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10464 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10465 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10466 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10467 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10468 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10470 terminal
->delete_frame_hook
= x_destroy_window
;
10471 terminal
->delete_terminal_hook
= x_delete_terminal
;
10473 terminal
->rif
= &x_redisplay_interface
;
10474 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10475 terminal
->char_ins_del_ok
= 1;
10476 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10477 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10478 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10485 x_initialize (void)
10490 last_tool_bar_item
= -1;
10491 any_help_event_p
= 0;
10492 ignore_next_mouse_click_timeout
= 0;
10494 x_session_initialized
= 0;
10498 current_count
= -1;
10501 /* Try to use interrupt input; if we can't, then start polling. */
10502 Fset_input_interrupt_mode (Qt
);
10504 #ifdef USE_X_TOOLKIT
10505 XtToolkitInitialize ();
10507 Xt_app_con
= XtCreateApplicationContext ();
10509 /* Register a converter from strings to pixels, which uses
10510 Emacs' color allocation infrastructure. */
10511 XtAppSetTypeConverter (Xt_app_con
,
10512 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10513 cvt_string_to_pixel_args
,
10514 XtNumber (cvt_string_to_pixel_args
),
10515 XtCacheByDisplay
, cvt_pixel_dtor
);
10517 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10520 #ifdef USE_TOOLKIT_SCROLL_BARS
10522 xaw3d_arrow_scroll
= False
;
10523 xaw3d_pick_top
= True
;
10527 pending_autoraise_frame
= 0;
10528 pending_event_wait
.f
= 0;
10529 pending_event_wait
.eventtype
= 0;
10531 /* Note that there is no real way portable across R3/R4 to get the
10532 original error handler. */
10533 XSetErrorHandler (x_error_handler
);
10534 XSetIOErrorHandler (x_io_error_quitter
);
10536 signal (SIGPIPE
, x_connection_signal
);
10538 xgselect_initialize ();
10543 syms_of_xterm (void)
10545 x_error_message
= NULL
;
10547 staticpro (&x_display_name_list
);
10548 x_display_name_list
= Qnil
;
10550 staticpro (&last_mouse_scroll_bar
);
10551 last_mouse_scroll_bar
= Qnil
;
10553 staticpro (&Qvendor_specific_keysyms
);
10554 Qvendor_specific_keysyms
= intern_c_string ("vendor-specific-keysyms");
10556 staticpro (&Qlatin_1
);
10557 Qlatin_1
= intern_c_string ("latin-1");
10559 staticpro (&last_mouse_press_frame
);
10560 last_mouse_press_frame
= Qnil
;
10563 xg_default_icon_file
= make_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10564 staticpro (&xg_default_icon_file
);
10566 Qx_gtk_map_stock
= intern_c_string ("x-gtk-map-stock");
10567 staticpro (&Qx_gtk_map_stock
);
10570 DEFVAR_BOOL ("x-use-underline-position-properties",
10571 &x_use_underline_position_properties
,
10572 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10573 A value of nil means ignore them. If you encounter fonts with bogus
10574 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10575 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10576 to override the font's UNDERLINE_POSITION for small font display
10578 x_use_underline_position_properties
= 1;
10580 DEFVAR_BOOL ("x-underline-at-descent-line",
10581 &x_underline_at_descent_line
,
10582 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
10583 A value of nil means to draw the underline according to the value of the
10584 variable `x-use-underline-position-properties', which is usually at the
10585 baseline level. The default value is nil. */);
10586 x_underline_at_descent_line
= 0;
10588 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10589 &x_mouse_click_focus_ignore_position
,
10590 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10591 This variable is only used when the window manager requires that you
10592 click on a frame to select it (give it focus). In that case, a value
10593 of nil, means that the selected window and cursor position changes to
10594 reflect the mouse click position, while a non-nil value means that the
10595 selected window or cursor position is preserved. */);
10596 x_mouse_click_focus_ignore_position
= 0;
10598 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10599 doc
: /* What X toolkit scroll bars Emacs uses.
10600 A value of nil means Emacs doesn't use X toolkit scroll bars.
10601 Otherwise, value is a symbol describing the X toolkit. */);
10602 #ifdef USE_TOOLKIT_SCROLL_BARS
10604 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10605 #elif defined HAVE_XAW3D
10606 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10608 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10610 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10613 Vx_toolkit_scroll_bars
= Qnil
;
10616 staticpro (&last_mouse_motion_frame
);
10617 last_mouse_motion_frame
= Qnil
;
10619 Qmodifier_value
= intern_c_string ("modifier-value");
10620 Qalt
= intern_c_string ("alt");
10621 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10622 Qhyper
= intern_c_string ("hyper");
10623 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10624 Qmeta
= intern_c_string ("meta");
10625 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10626 Qsuper
= intern_c_string ("super");
10627 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10629 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10630 doc
: /* Which keys Emacs uses for the alt modifier.
10631 This should be one of the symbols `alt', `hyper', `meta', `super'.
10632 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10633 is nil, which is the same as `alt'. */);
10634 Vx_alt_keysym
= Qnil
;
10636 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10637 doc
: /* Which keys Emacs uses for the hyper modifier.
10638 This should be one of the symbols `alt', `hyper', `meta', `super'.
10639 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10640 default is nil, which is the same as `hyper'. */);
10641 Vx_hyper_keysym
= Qnil
;
10643 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10644 doc
: /* Which keys Emacs uses for the meta modifier.
10645 This should be one of the symbols `alt', `hyper', `meta', `super'.
10646 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10647 default is nil, which is the same as `meta'. */);
10648 Vx_meta_keysym
= Qnil
;
10650 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10651 doc
: /* Which keys Emacs uses for the super modifier.
10652 This should be one of the symbols `alt', `hyper', `meta', `super'.
10653 For example, `super' means use the Super_L and Super_R keysyms. The
10654 default is nil, which is the same as `super'. */);
10655 Vx_super_keysym
= Qnil
;
10657 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10658 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10659 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10660 make_float (DEFAULT_REHASH_SIZE
),
10661 make_float (DEFAULT_REHASH_THRESHOLD
),
10665 #endif /* HAVE_X_WINDOWS */
10667 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
10668 (do not change this comment) */