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 /* Initial values of argv and argc. */
298 extern char **initial_argv
;
299 extern int initial_argc
;
301 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
303 /* Tells if a window manager is present or not. */
305 extern Lisp_Object Vx_no_window_manager
;
307 extern Lisp_Object Qeql
;
309 /* A mask of extra modifier bits to put into every keyboard char. */
311 extern EMACS_INT extra_keyboard_modifiers
;
313 /* The keysyms to use for the various modifiers. */
315 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
316 Lisp_Object Vx_keysym_table
;
317 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
319 static Lisp_Object Qvendor_specific_keysyms
;
320 static Lisp_Object Qlatin_1
;
323 /* The name of the Emacs icon file. */
324 static Lisp_Object xg_default_icon_file
;
326 /* Used in gtkutil.c. */
327 Lisp_Object Qx_gtk_map_stock
;
330 /* Used in x_flush. */
332 extern Lisp_Object Vinhibit_redisplay
;
334 extern XrmDatabase
x_load_resources (Display
*, const char *, const char *,
336 extern int x_bitmap_mask (FRAME_PTR
, int);
338 static int x_alloc_nearest_color_1 (Display
*, Colormap
, XColor
*);
339 static void x_set_window_size_1 (struct frame
*, int, int, int);
340 static const XColor
*x_color_cells (Display
*, int *);
341 static void x_update_window_end (struct window
*, int, int);
343 static int x_io_error_quitter (Display
*);
344 static struct terminal
*x_create_terminal (struct x_display_info
*);
345 void x_delete_terminal (struct terminal
*);
346 static void x_update_end (struct frame
*);
347 static void XTframe_up_to_date (struct frame
*);
348 static void XTset_terminal_modes (struct terminal
*);
349 static void XTreset_terminal_modes (struct terminal
*);
350 static void x_clear_frame (struct frame
*);
351 static void frame_highlight (struct frame
*);
352 static void frame_unhighlight (struct frame
*);
353 static void x_new_focus_frame (struct x_display_info
*, struct frame
*);
354 static void x_focus_changed (int, int, struct x_display_info
*,
355 struct frame
*, struct input_event
*);
356 static void x_detect_focus_change (struct x_display_info
*,
357 XEvent
*, struct input_event
*);
358 static void XTframe_rehighlight (struct frame
*);
359 static void x_frame_rehighlight (struct x_display_info
*);
360 static void x_draw_hollow_cursor (struct window
*, struct glyph_row
*);
361 static void x_draw_bar_cursor (struct window
*, struct glyph_row
*, int,
362 enum text_cursor_kinds
);
364 static void x_clip_to_row (struct window
*, struct glyph_row
*, int, GC
);
365 static void x_flush (struct frame
*f
);
366 static void x_update_begin (struct frame
*);
367 static void x_update_window_begin (struct window
*);
368 static void x_after_update_window_line (struct glyph_row
*);
369 static struct scroll_bar
*x_window_to_scroll_bar (Display
*, Window
);
370 static void x_scroll_bar_report_motion (struct frame
**, Lisp_Object
*,
371 enum scroll_bar_part
*,
372 Lisp_Object
*, Lisp_Object
*,
374 static void x_handle_net_wm_state (struct frame
*, XPropertyEvent
*);
375 static void x_check_fullscreen (struct frame
*);
376 static void x_check_expected_move (struct frame
*, int, int);
377 static void x_sync_with_move (struct frame
*, int, int, int);
378 static int handle_one_xevent (struct x_display_info
*, XEvent
*,
379 int *, struct input_event
*);
380 /* Don't declare this NO_RETURN because we want no
381 interference with debugging failing X calls. */
382 static SIGTYPE
x_connection_closed (Display
*, const char *);
385 /* Flush display of frame F, or of all frames if F is null. */
388 x_flush (struct frame
*f
)
390 /* Don't call XFlush when it is not safe to redisplay; the X
391 connection may be broken. */
392 if (!NILP (Vinhibit_redisplay
))
398 Lisp_Object rest
, frame
;
399 FOR_EACH_FRAME (rest
, frame
)
400 if (FRAME_X_P (XFRAME (frame
)))
401 x_flush (XFRAME (frame
));
403 else if (FRAME_X_P (f
))
404 XFlush (FRAME_X_DISPLAY (f
));
409 /* Remove calls to XFlush by defining XFlush to an empty replacement.
410 Calls to XFlush should be unnecessary because the X output buffer
411 is flushed automatically as needed by calls to XPending,
412 XNextEvent, or XWindowEvent according to the XFlush man page.
413 XTread_socket calls XPending. Removing XFlush improves
416 #define XFlush(DISPLAY) (void) 0
419 /***********************************************************************
421 ***********************************************************************/
425 /* This is a function useful for recording debugging information about
426 the sequence of occurrences in this file. */
434 struct record event_record
[100];
436 int event_record_index
;
438 record_event (locus
, type
)
442 if (event_record_index
== sizeof (event_record
) / sizeof (struct record
))
443 event_record_index
= 0;
445 event_record
[event_record_index
].locus
= locus
;
446 event_record
[event_record_index
].type
= type
;
447 event_record_index
++;
454 /* Return the struct x_display_info corresponding to DPY. */
456 struct x_display_info
*
457 x_display_info_for_display (Display
*dpy
)
459 struct x_display_info
*dpyinfo
;
461 for (dpyinfo
= x_display_list
; dpyinfo
; dpyinfo
= dpyinfo
->next
)
462 if (dpyinfo
->display
== dpy
)
468 #define OPAQUE 0xffffffff
469 #define OPACITY "_NET_WM_WINDOW_OPACITY"
472 x_set_frame_alpha (struct frame
*f
)
474 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
475 Display
*dpy
= FRAME_X_DISPLAY (f
);
476 Window win
= FRAME_OUTER_WINDOW (f
);
478 double alpha_min
= 1.0;
481 if (FRAME_X_DISPLAY_INFO (f
)->root_window
!= FRAME_X_OUTPUT (f
)->parent_desc
)
482 /* Since the WM decoration lies under the FRAME_OUTER_WINDOW,
483 we must treat the former instead of the latter. */
484 win
= FRAME_X_OUTPUT (f
)->parent_desc
;
486 if (dpyinfo
->x_highlight_frame
== f
)
491 if (FLOATP (Vframe_alpha_lower_limit
))
492 alpha_min
= XFLOAT_DATA (Vframe_alpha_lower_limit
);
493 else if (INTEGERP (Vframe_alpha_lower_limit
))
494 alpha_min
= (XINT (Vframe_alpha_lower_limit
)) / 100.0;
498 else if (alpha
> 1.0)
500 else if (0.0 <= alpha
&& alpha
< alpha_min
&& alpha_min
<= 1.0)
503 opac
= alpha
* OPAQUE
;
505 /* return unless necessary */
510 unsigned long n
, left
;
512 x_catch_errors (dpy
);
513 rc
= XGetWindowProperty (dpy
, win
, XInternAtom(dpy
, OPACITY
, False
),
514 0L, 1L, False
, XA_CARDINAL
,
515 &actual
, &format
, &n
, &left
,
518 if (rc
== Success
&& actual
!= None
)
519 if (*(unsigned long *)data
== opac
)
521 XFree ((void *) data
);
526 XFree ((void *) data
);
530 x_catch_errors (dpy
);
531 XChangeProperty (dpy
, win
, XInternAtom (dpy
, OPACITY
, False
),
532 XA_CARDINAL
, 32, PropModeReplace
,
533 (unsigned char *) &opac
, 1L);
538 x_display_pixel_height (struct x_display_info
*dpyinfo
)
540 return HeightOfScreen (dpyinfo
->screen
);
544 x_display_pixel_width (struct x_display_info
*dpyinfo
)
546 return WidthOfScreen (dpyinfo
->screen
);
550 /***********************************************************************
551 Starting and ending an update
552 ***********************************************************************/
554 /* Start an update of frame F. This function is installed as a hook
555 for update_begin, i.e. it is called when update_begin is called.
556 This function is called prior to calls to x_update_window_begin for
557 each window being updated. Currently, there is nothing to do here
558 because all interesting stuff is done on a window basis. */
561 x_update_begin (struct frame
*f
)
567 /* Start update of window W. Set the global variable updated_window
568 to the window being updated and set output_cursor to the cursor
572 x_update_window_begin (struct window
*w
)
574 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
575 struct x_display_info
*display_info
= FRAME_X_DISPLAY_INFO (f
);
578 set_output_cursor (&w
->cursor
);
582 if (f
== display_info
->mouse_face_mouse_frame
)
584 /* Don't do highlighting for mouse motion during the update. */
585 display_info
->mouse_face_defer
= 1;
587 /* If F needs to be redrawn, simply forget about any prior mouse
589 if (FRAME_GARBAGED_P (f
))
590 display_info
->mouse_face_window
= Qnil
;
597 /* Draw a vertical window border from (x,y0) to (x,y1) */
600 x_draw_vertical_window_border (struct window
*w
, int x
, int y0
, int y1
)
602 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
605 face
= FACE_FROM_ID (f
, VERTICAL_BORDER_FACE_ID
);
607 XSetForeground (FRAME_X_DISPLAY (f
), f
->output_data
.x
->normal_gc
,
610 XDrawLine (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
611 f
->output_data
.x
->normal_gc
, x
, y0
, x
, y1
);
614 /* End update of window W (which is equal to updated_window).
616 Draw vertical borders between horizontally adjacent windows, and
617 display W's cursor if CURSOR_ON_P is non-zero.
619 MOUSE_FACE_OVERWRITTEN_P non-zero means that some row containing
620 glyphs in mouse-face were overwritten. In that case we have to
621 make sure that the mouse-highlight is properly redrawn.
623 W may be a menu bar pseudo-window in case we don't have X toolkit
624 support. Such windows don't have a cursor, so don't display it
628 x_update_window_end (struct window
*w
, int cursor_on_p
, int mouse_face_overwritten_p
)
630 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (XFRAME (w
->frame
));
632 if (!w
->pseudo_window_p
)
637 display_and_set_cursor (w
, 1, output_cursor
.hpos
,
639 output_cursor
.x
, output_cursor
.y
);
641 if (draw_window_fringes (w
, 1))
642 x_draw_vertical_border (w
);
647 /* If a row with mouse-face was overwritten, arrange for
648 XTframe_up_to_date to redisplay the mouse highlight. */
649 if (mouse_face_overwritten_p
)
651 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
652 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
653 dpyinfo
->mouse_face_window
= Qnil
;
656 updated_window
= NULL
;
660 /* End update of frame F. This function is installed as a hook in
664 x_update_end (struct frame
*f
)
666 /* Mouse highlight may be displayed again. */
667 FRAME_X_DISPLAY_INFO (f
)->mouse_face_defer
= 0;
671 XFlush (FRAME_X_DISPLAY (f
));
677 /* This function is called from various places in xdisp.c whenever a
678 complete update has been performed. The global variable
679 updated_window is not available here. */
682 XTframe_up_to_date (struct frame
*f
)
686 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
688 if (dpyinfo
->mouse_face_deferred_gc
689 || f
== dpyinfo
->mouse_face_mouse_frame
)
692 if (dpyinfo
->mouse_face_mouse_frame
)
693 note_mouse_highlight (dpyinfo
->mouse_face_mouse_frame
,
694 dpyinfo
->mouse_face_mouse_x
,
695 dpyinfo
->mouse_face_mouse_y
);
696 dpyinfo
->mouse_face_deferred_gc
= 0;
703 /* Draw truncation mark bitmaps, continuation mark bitmaps, overlay
704 arrow bitmaps, or clear the fringes if no bitmaps are required
705 before DESIRED_ROW is made current. The window being updated is
706 found in updated_window. This function It is called from
707 update_window_line only if it is known that there are differences
708 between bitmaps to be drawn between current row and DESIRED_ROW. */
711 x_after_update_window_line (struct glyph_row
*desired_row
)
713 struct window
*w
= updated_window
;
719 if (!desired_row
->mode_line_p
&& !w
->pseudo_window_p
)
720 desired_row
->redraw_fringe_bitmaps_p
= 1;
722 /* When a window has disappeared, make sure that no rest of
723 full-width rows stays visible in the internal border. Could
724 check here if updated_window is the leftmost/rightmost window,
725 but I guess it's not worth doing since vertically split windows
726 are almost never used, internal border is rarely set, and the
727 overhead is very small. */
728 if (windows_or_buffers_changed
729 && desired_row
->full_width_p
730 && (f
= XFRAME (w
->frame
),
731 width
= FRAME_INTERNAL_BORDER_WIDTH (f
),
733 && (height
= desired_row
->visible_height
,
736 int y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, desired_row
->y
));
739 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
740 0, y
, width
, height
, False
);
741 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
742 FRAME_PIXEL_WIDTH (f
) - width
,
743 y
, width
, height
, False
);
749 x_draw_fringe_bitmap (struct window
*w
, struct glyph_row
*row
, struct draw_fringe_bitmap_params
*p
)
751 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
752 Display
*display
= FRAME_X_DISPLAY (f
);
753 Window window
= FRAME_X_WINDOW (f
);
754 GC gc
= f
->output_data
.x
->normal_gc
;
755 struct face
*face
= p
->face
;
757 /* Must clip because of partially visible lines. */
758 x_clip_to_row (w
, row
, -1, gc
);
762 int bx
= p
->bx
, by
= p
->by
, nx
= p
->nx
, ny
= p
->ny
;
764 /* In case the same realized face is used for fringes and
765 for something displayed in the text (e.g. face `region' on
766 mono-displays, the fill style may have been changed to
767 FillSolid in x_draw_glyph_string_background. */
769 XSetFillStyle (display
, face
->gc
, FillOpaqueStippled
);
771 XSetForeground (display
, face
->gc
, face
->background
);
773 #ifdef USE_TOOLKIT_SCROLL_BARS
774 /* If the fringe is adjacent to the left (right) scroll bar of a
775 leftmost (rightmost, respectively) window, then extend its
776 background to the gap between the fringe and the bar. */
777 if ((WINDOW_LEFTMOST_P (w
)
778 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
779 || (WINDOW_RIGHTMOST_P (w
)
780 && WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
)))
782 int sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
786 int left
= WINDOW_SCROLL_BAR_AREA_X (w
);
787 int width
= (WINDOW_CONFIG_SCROLL_BAR_COLS (w
)
788 * FRAME_COLUMN_WIDTH (f
));
792 /* Bitmap fills the fringe. */
793 if (left
+ width
== p
->x
)
794 bx
= left
+ sb_width
;
795 else if (p
->x
+ p
->wd
== left
)
799 int header_line_height
= WINDOW_HEADER_LINE_HEIGHT (w
);
801 nx
= width
- sb_width
;
802 by
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (header_line_height
,
804 ny
= row
->visible_height
;
809 if (left
+ width
== bx
)
811 bx
= left
+ sb_width
;
812 nx
+= width
- sb_width
;
814 else if (bx
+ nx
== left
)
815 nx
+= width
- sb_width
;
820 if (bx
>= 0 && nx
> 0)
821 XFillRectangle (display
, window
, face
->gc
, bx
, by
, nx
, ny
);
824 XSetForeground (display
, face
->gc
, face
->foreground
);
830 Pixmap pixmap
, clipmask
= (Pixmap
) 0;
831 int depth
= DefaultDepthOfScreen (FRAME_X_SCREEN (f
));
835 bits
= (unsigned char *)(p
->bits
+ p
->dh
);
837 bits
= (unsigned char *)p
->bits
+ p
->dh
;
839 /* Draw the bitmap. I believe these small pixmaps can be cached
841 pixmap
= XCreatePixmapFromBitmapData (display
, window
, bits
, p
->wd
, p
->h
,
843 ? (p
->overlay_p
? face
->background
844 : f
->output_data
.x
->cursor_pixel
)
846 face
->background
, depth
);
850 clipmask
= XCreatePixmapFromBitmapData (display
,
851 FRAME_X_DISPLAY_INFO (f
)->root_window
,
854 gcv
.clip_mask
= clipmask
;
855 gcv
.clip_x_origin
= p
->x
;
856 gcv
.clip_y_origin
= p
->y
;
857 XChangeGC (display
, gc
, GCClipMask
| GCClipXOrigin
| GCClipYOrigin
, &gcv
);
860 XCopyArea (display
, pixmap
, window
, gc
, 0, 0,
861 p
->wd
, p
->h
, p
->x
, p
->y
);
862 XFreePixmap (display
, pixmap
);
866 gcv
.clip_mask
= (Pixmap
) 0;
867 XChangeGC (display
, gc
, GCClipMask
, &gcv
);
868 XFreePixmap (display
, clipmask
);
872 XSetClipMask (display
, gc
, None
);
877 /* This is called when starting Emacs and when restarting after
878 suspend. When starting Emacs, no X window is mapped. And nothing
879 must be done to Emacs's own window if it is suspended (though that
883 XTset_terminal_modes (struct terminal
*terminal
)
887 /* This is called when exiting or suspending Emacs. Exiting will make
888 the X-windows go away, and suspending requires no action. */
891 XTreset_terminal_modes (struct terminal
*terminal
)
896 /***********************************************************************
898 ***********************************************************************/
902 static void x_set_glyph_string_clipping (struct glyph_string
*);
903 static void x_set_glyph_string_gc (struct glyph_string
*);
904 static void x_draw_glyph_string_background (struct glyph_string
*,
906 static void x_draw_glyph_string_foreground (struct glyph_string
*);
907 static void x_draw_composite_glyph_string_foreground (struct glyph_string
*);
908 static void x_draw_glyph_string_box (struct glyph_string
*);
909 static void x_draw_glyph_string (struct glyph_string
*);
910 static void x_compute_glyph_string_overhangs (struct glyph_string
*);
911 static void x_set_cursor_gc (struct glyph_string
*);
912 static void x_set_mode_line_face_gc (struct glyph_string
*);
913 static void x_set_mouse_face_gc (struct glyph_string
*);
914 static int x_alloc_lighter_color (struct frame
*, Display
*, Colormap
,
915 unsigned long *, double, int);
916 static void x_setup_relief_color (struct frame
*, struct relief
*,
917 double, int, unsigned long);
918 static void x_setup_relief_colors (struct glyph_string
*);
919 static void x_draw_image_glyph_string (struct glyph_string
*);
920 static void x_draw_image_relief (struct glyph_string
*);
921 static void x_draw_image_foreground (struct glyph_string
*);
922 static void x_draw_image_foreground_1 (struct glyph_string
*, Pixmap
);
923 static void x_clear_glyph_string_rect (struct glyph_string
*, int,
925 static void x_draw_relief_rect (struct frame
*, int, int, int, int,
926 int, int, int, int, int, int,
928 static void x_draw_box_rect (struct glyph_string
*, int, int, int, int,
929 int, int, int, XRectangle
*);
932 static void x_check_font (struct frame
*, struct font
*);
936 /* Set S->gc to a suitable GC for drawing glyph string S in cursor
940 x_set_cursor_gc (struct glyph_string
*s
)
942 if (s
->font
== FRAME_FONT (s
->f
)
943 && s
->face
->background
== FRAME_BACKGROUND_PIXEL (s
->f
)
944 && s
->face
->foreground
== FRAME_FOREGROUND_PIXEL (s
->f
)
946 s
->gc
= s
->f
->output_data
.x
->cursor_gc
;
949 /* Cursor on non-default face: must merge. */
953 xgcv
.background
= s
->f
->output_data
.x
->cursor_pixel
;
954 xgcv
.foreground
= s
->face
->background
;
956 /* If the glyph would be invisible, try a different foreground. */
957 if (xgcv
.foreground
== xgcv
.background
)
958 xgcv
.foreground
= s
->face
->foreground
;
959 if (xgcv
.foreground
== xgcv
.background
)
960 xgcv
.foreground
= s
->f
->output_data
.x
->cursor_foreground_pixel
;
961 if (xgcv
.foreground
== xgcv
.background
)
962 xgcv
.foreground
= s
->face
->foreground
;
964 /* Make sure the cursor is distinct from text in this face. */
965 if (xgcv
.background
== s
->face
->background
966 && xgcv
.foreground
== s
->face
->foreground
)
968 xgcv
.background
= s
->face
->foreground
;
969 xgcv
.foreground
= s
->face
->background
;
972 IF_DEBUG (x_check_font (s
->f
, s
->font
));
973 xgcv
.graphics_exposures
= False
;
974 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
976 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
977 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
980 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
981 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
983 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
988 /* Set up S->gc of glyph string S for drawing text in mouse face. */
991 x_set_mouse_face_gc (struct glyph_string
*s
)
996 /* What face has to be used last for the mouse face? */
997 face_id
= FRAME_X_DISPLAY_INFO (s
->f
)->mouse_face_face_id
;
998 face
= FACE_FROM_ID (s
->f
, face_id
);
1000 face
= FACE_FROM_ID (s
->f
, MOUSE_FACE_ID
);
1002 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1003 face_id
= FACE_FOR_CHAR (s
->f
, face
, s
->first_glyph
->u
.ch
, -1, Qnil
);
1005 face_id
= FACE_FOR_CHAR (s
->f
, face
, 0, -1, Qnil
);
1006 s
->face
= FACE_FROM_ID (s
->f
, face_id
);
1007 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1009 if (s
->font
== s
->face
->font
)
1010 s
->gc
= s
->face
->gc
;
1013 /* Otherwise construct scratch_cursor_gc with values from FACE
1018 xgcv
.background
= s
->face
->background
;
1019 xgcv
.foreground
= s
->face
->foreground
;
1020 xgcv
.graphics_exposures
= False
;
1021 mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
1023 if (FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
)
1024 XChangeGC (s
->display
, FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
,
1027 FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
1028 = XCreateGC (s
->display
, s
->window
, mask
, &xgcv
);
1030 s
->gc
= FRAME_X_DISPLAY_INFO (s
->f
)->scratch_cursor_gc
;
1033 xassert (s
->gc
!= 0);
1037 /* Set S->gc of glyph string S to a GC suitable for drawing a mode line.
1038 Faces to use in the mode line have already been computed when the
1039 matrix was built, so there isn't much to do, here. */
1042 x_set_mode_line_face_gc (struct glyph_string
*s
)
1044 s
->gc
= s
->face
->gc
;
1048 /* Set S->gc of glyph string S for drawing that glyph string. Set
1049 S->stippled_p to a non-zero value if the face of S has a stipple
1053 x_set_glyph_string_gc (struct glyph_string
*s
)
1055 PREPARE_FACE_FOR_DISPLAY (s
->f
, s
->face
);
1057 if (s
->hl
== DRAW_NORMAL_TEXT
)
1059 s
->gc
= s
->face
->gc
;
1060 s
->stippled_p
= s
->face
->stipple
!= 0;
1062 else if (s
->hl
== DRAW_INVERSE_VIDEO
)
1064 x_set_mode_line_face_gc (s
);
1065 s
->stippled_p
= s
->face
->stipple
!= 0;
1067 else if (s
->hl
== DRAW_CURSOR
)
1069 x_set_cursor_gc (s
);
1072 else if (s
->hl
== DRAW_MOUSE_FACE
)
1074 x_set_mouse_face_gc (s
);
1075 s
->stippled_p
= s
->face
->stipple
!= 0;
1077 else if (s
->hl
== DRAW_IMAGE_RAISED
1078 || s
->hl
== DRAW_IMAGE_SUNKEN
)
1080 s
->gc
= s
->face
->gc
;
1081 s
->stippled_p
= s
->face
->stipple
!= 0;
1085 s
->gc
= s
->face
->gc
;
1086 s
->stippled_p
= s
->face
->stipple
!= 0;
1089 /* GC must have been set. */
1090 xassert (s
->gc
!= 0);
1094 /* Set clipping for output of glyph string S. S may be part of a mode
1095 line or menu if we don't have X toolkit support. */
1098 x_set_glyph_string_clipping (struct glyph_string
*s
)
1100 XRectangle
*r
= s
->clip
;
1101 int n
= get_glyph_string_clip_rects (s
, r
, 2);
1104 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, r
, n
, Unsorted
);
1109 /* Set SRC's clipping for output of glyph string DST. This is called
1110 when we are drawing DST's left_overhang or right_overhang only in
1114 x_set_glyph_string_clipping_exactly (struct glyph_string
*src
, struct glyph_string
*dst
)
1119 r
.width
= src
->width
;
1121 r
.height
= src
->height
;
1124 XSetClipRectangles (dst
->display
, dst
->gc
, 0, 0, &r
, 1, Unsorted
);
1129 Compute left and right overhang of glyph string S. */
1132 x_compute_glyph_string_overhangs (struct glyph_string
*s
)
1135 && (s
->first_glyph
->type
== CHAR_GLYPH
1136 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
1138 struct font_metrics metrics
;
1140 if (s
->first_glyph
->type
== CHAR_GLYPH
)
1142 unsigned *code
= alloca (sizeof (unsigned) * s
->nchars
);
1143 struct font
*font
= s
->font
;
1146 for (i
= 0; i
< s
->nchars
; i
++)
1147 code
[i
] = (s
->char2b
[i
].byte1
<< 8) | s
->char2b
[i
].byte2
;
1148 font
->driver
->text_extents (font
, code
, s
->nchars
, &metrics
);
1152 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1154 composition_gstring_width (gstring
, s
->cmp_from
, s
->cmp_to
, &metrics
);
1156 s
->right_overhang
= (metrics
.rbearing
> metrics
.width
1157 ? metrics
.rbearing
- metrics
.width
: 0);
1158 s
->left_overhang
= metrics
.lbearing
< 0 ? - metrics
.lbearing
: 0;
1162 s
->right_overhang
= s
->cmp
->rbearing
- s
->cmp
->pixel_width
;
1163 s
->left_overhang
= - s
->cmp
->lbearing
;
1168 /* Fill rectangle X, Y, W, H with background color of glyph string S. */
1171 x_clear_glyph_string_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
1174 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
, &xgcv
);
1175 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
1176 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
1177 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
1181 /* Draw the background of glyph_string S. If S->background_filled_p
1182 is non-zero don't draw it. FORCE_P non-zero means draw the
1183 background even if it wouldn't be drawn normally. This is used
1184 when a string preceding S draws into the background of S, or S
1185 contains the first component of a composition. */
1188 x_draw_glyph_string_background (struct glyph_string
*s
, int force_p
)
1190 /* Nothing to do if background has already been drawn or if it
1191 shouldn't be drawn in the first place. */
1192 if (!s
->background_filled_p
)
1194 int box_line_width
= max (s
->face
->box_line_width
, 0);
1198 /* Fill background with a stipple pattern. */
1199 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
1200 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
,
1201 s
->y
+ box_line_width
,
1202 s
->background_width
,
1203 s
->height
- 2 * box_line_width
);
1204 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
1205 s
->background_filled_p
= 1;
1207 else if (FONT_HEIGHT (s
->font
) < s
->height
- 2 * box_line_width
1208 || s
->font_not_found_p
1209 || s
->extends_to_end_of_line_p
1212 x_clear_glyph_string_rect (s
, s
->x
, s
->y
+ box_line_width
,
1213 s
->background_width
,
1214 s
->height
- 2 * box_line_width
);
1215 s
->background_filled_p
= 1;
1221 /* Draw the foreground of glyph string S. */
1224 x_draw_glyph_string_foreground (struct glyph_string
*s
)
1228 /* If first glyph of S has a left box line, start drawing the text
1229 of S to the right of that box line. */
1230 if (s
->face
->box
!= FACE_NO_BOX
1231 && s
->first_glyph
->left_box_line_p
)
1232 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1236 /* Draw characters of S as rectangles if S's font could not be
1238 if (s
->font_not_found_p
)
1240 for (i
= 0; i
< s
->nchars
; ++i
)
1242 struct glyph
*g
= s
->first_glyph
+ i
;
1243 XDrawRectangle (s
->display
, s
->window
,
1244 s
->gc
, x
, s
->y
, g
->pixel_width
- 1,
1246 x
+= g
->pixel_width
;
1251 struct font
*font
= s
->font
;
1252 int boff
= font
->baseline_offset
;
1255 if (font
->vertical_centering
)
1256 boff
= VCENTER_BASELINE_OFFSET (font
, s
->f
) - boff
;
1258 y
= s
->ybase
- boff
;
1260 || (s
->background_filled_p
&& s
->hl
!= DRAW_CURSOR
))
1261 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 0);
1263 font
->driver
->draw (s
, 0, s
->nchars
, x
, y
, 1);
1264 if (s
->face
->overstrike
)
1265 font
->driver
->draw (s
, 0, s
->nchars
, x
+ 1, y
, 0);
1269 /* Draw the foreground of composite glyph string S. */
1272 x_draw_composite_glyph_string_foreground (struct glyph_string
*s
)
1275 struct font
*font
= s
->font
;
1277 /* If first glyph of S has a left box line, start drawing the text
1278 of S to the right of that box line. */
1279 if (s
->face
&& s
->face
->box
!= FACE_NO_BOX
1280 && s
->first_glyph
->left_box_line_p
)
1281 x
= s
->x
+ eabs (s
->face
->box_line_width
);
1285 /* S is a glyph string for a composition. S->cmp_from is the index
1286 of the first character drawn for glyphs of this composition.
1287 S->cmp_from == 0 means we are drawing the very first character of
1288 this composition. */
1290 /* Draw a rectangle for the composition if the font for the very
1291 first character of the composition could not be loaded. */
1292 if (s
->font_not_found_p
)
1294 if (s
->cmp_from
== 0)
1295 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, s
->y
,
1296 s
->width
- 1, s
->height
- 1);
1298 else if (! s
->first_glyph
->u
.cmp
.automatic
)
1302 for (i
= 0, j
= s
->cmp_from
; i
< s
->nchars
; i
++, j
++)
1303 if (COMPOSITION_GLYPH (s
->cmp
, j
) != '\t')
1305 int xx
= x
+ s
->cmp
->offsets
[j
* 2];
1306 int yy
= y
- s
->cmp
->offsets
[j
* 2 + 1];
1308 font
->driver
->draw (s
, j
, j
+ 1, xx
, yy
, 0);
1309 if (s
->face
->overstrike
)
1310 font
->driver
->draw (s
, j
, j
+ 1, xx
+ 1, yy
, 0);
1315 Lisp_Object gstring
= composition_gstring_from_id (s
->cmp_id
);
1320 for (i
= j
= s
->cmp_from
; i
< s
->cmp_to
; i
++)
1322 glyph
= LGSTRING_GLYPH (gstring
, i
);
1323 if (NILP (LGLYPH_ADJUSTMENT (glyph
)))
1324 width
+= LGLYPH_WIDTH (glyph
);
1327 int xoff
, yoff
, wadjust
;
1331 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1332 if (s
->face
->overstrike
)
1333 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1336 xoff
= LGLYPH_XOFF (glyph
);
1337 yoff
= LGLYPH_YOFF (glyph
);
1338 wadjust
= LGLYPH_WADJUST (glyph
);
1339 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
, y
+ yoff
, 0);
1340 if (s
->face
->overstrike
)
1341 font
->driver
->draw (s
, i
, i
+ 1, x
+ xoff
+ 1, y
+ yoff
, 0);
1349 font
->driver
->draw (s
, j
, i
, x
, y
, 0);
1350 if (s
->face
->overstrike
)
1351 font
->driver
->draw (s
, j
, i
, x
+ 1, y
, 0);
1357 #ifdef USE_X_TOOLKIT
1359 static struct frame
*x_frame_of_widget (Widget
);
1360 static Boolean
cvt_string_to_pixel (Display
*, XrmValue
*, Cardinal
*,
1361 XrmValue
*, XrmValue
*, XtPointer
*);
1362 static void cvt_pixel_dtor (XtAppContext
, XrmValue
*, XtPointer
,
1363 XrmValue
*, Cardinal
*);
1366 /* Return the frame on which widget WIDGET is used.. Abort if frame
1367 cannot be determined. */
1369 static struct frame
*
1370 x_frame_of_widget (Widget widget
)
1372 struct x_display_info
*dpyinfo
;
1376 dpyinfo
= x_display_info_for_display (XtDisplay (widget
));
1378 /* Find the top-level shell of the widget. Note that this function
1379 can be called when the widget is not yet realized, so XtWindow
1380 (widget) == 0. That's the reason we can't simply use
1381 x_any_window_to_frame. */
1382 while (!XtIsTopLevelShell (widget
))
1383 widget
= XtParent (widget
);
1385 /* Look for a frame with that top-level widget. Allocate the color
1386 on that frame to get the right gamma correction value. */
1387 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
1388 if (FRAMEP (XCAR (tail
))
1389 && (f
= XFRAME (XCAR (tail
)),
1391 && f
->output_data
.nothing
!= 1
1392 && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
))
1393 && f
->output_data
.x
->widget
== widget
)
1400 /* Allocate the color COLOR->pixel on the screen and display of
1401 widget WIDGET in colormap CMAP. If an exact match cannot be
1402 allocated, try the nearest color available. Value is non-zero
1403 if successful. This is called from lwlib. */
1406 x_alloc_nearest_color_for_widget (Widget widget
, Colormap cmap
, XColor
*color
)
1408 struct frame
*f
= x_frame_of_widget (widget
);
1409 return x_alloc_nearest_color (f
, cmap
, color
);
1413 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1414 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1415 If this produces the same color as PIXEL, try a color where all RGB
1416 values have DELTA added. Return the allocated color in *PIXEL.
1417 DISPLAY is the X display, CMAP is the colormap to operate on.
1418 Value is non-zero if successful. */
1421 x_alloc_lighter_color_for_widget (Widget widget
, Display
*display
, Colormap cmap
,
1422 unsigned long *pixel
, double factor
, int delta
)
1424 struct frame
*f
= x_frame_of_widget (widget
);
1425 return x_alloc_lighter_color (f
, display
, cmap
, pixel
, factor
, delta
);
1429 /* Structure specifying which arguments should be passed by Xt to
1430 cvt_string_to_pixel. We want the widget's screen and colormap. */
1432 static XtConvertArgRec cvt_string_to_pixel_args
[] =
1434 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.screen
),
1436 {XtWidgetBaseOffset
, (XtPointer
) XtOffset (Widget
, core
.colormap
),
1441 /* The address of this variable is returned by
1442 cvt_string_to_pixel. */
1444 static Pixel cvt_string_to_pixel_value
;
1447 /* Convert a color name to a pixel color.
1449 DPY is the display we are working on.
1451 ARGS is an array of *NARGS XrmValue structures holding additional
1452 information about the widget for which the conversion takes place.
1453 The contents of this array are determined by the specification
1454 in cvt_string_to_pixel_args.
1456 FROM is a pointer to an XrmValue which points to the color name to
1457 convert. TO is an XrmValue in which to return the pixel color.
1459 CLOSURE_RET is a pointer to user-data, in which we record if
1460 we allocated the color or not.
1462 Value is True if successful, False otherwise. */
1465 cvt_string_to_pixel (Display
*dpy
, XrmValue
*args
, Cardinal
*nargs
,
1466 XrmValue
*from
, XrmValue
*to
,
1467 XtPointer
*closure_ret
)
1477 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1478 "wrongParameters", "cvt_string_to_pixel",
1480 "Screen and colormap args required", NULL
, NULL
);
1484 screen
= *(Screen
**) args
[0].addr
;
1485 cmap
= *(Colormap
*) args
[1].addr
;
1486 color_name
= (String
) from
->addr
;
1488 if (strcmp (color_name
, XtDefaultBackground
) == 0)
1490 *closure_ret
= (XtPointer
) False
;
1491 pixel
= WhitePixelOfScreen (screen
);
1493 else if (strcmp (color_name
, XtDefaultForeground
) == 0)
1495 *closure_ret
= (XtPointer
) False
;
1496 pixel
= BlackPixelOfScreen (screen
);
1498 else if (XParseColor (dpy
, cmap
, color_name
, &color
)
1499 && x_alloc_nearest_color_1 (dpy
, cmap
, &color
))
1501 pixel
= color
.pixel
;
1502 *closure_ret
= (XtPointer
) True
;
1507 Cardinal nparams
= 1;
1509 params
[0] = color_name
;
1510 XtAppWarningMsg (XtDisplayToApplicationContext (dpy
),
1511 "badValue", "cvt_string_to_pixel",
1512 "XtToolkitError", "Invalid color `%s'",
1517 if (to
->addr
!= NULL
)
1519 if (to
->size
< sizeof (Pixel
))
1521 to
->size
= sizeof (Pixel
);
1525 *(Pixel
*) to
->addr
= pixel
;
1529 cvt_string_to_pixel_value
= pixel
;
1530 to
->addr
= (XtPointer
) &cvt_string_to_pixel_value
;
1533 to
->size
= sizeof (Pixel
);
1538 /* Free a pixel color which was previously allocated via
1539 cvt_string_to_pixel. This is registered as the destructor
1540 for this type of resource via XtSetTypeConverter.
1542 APP is the application context in which we work.
1544 TO is a pointer to an XrmValue holding the color to free.
1545 CLOSURE is the value we stored in CLOSURE_RET for this color
1546 in cvt_string_to_pixel.
1548 ARGS and NARGS are like for cvt_string_to_pixel. */
1551 cvt_pixel_dtor (XtAppContext app
, XrmValuePtr to
, XtPointer closure
, XrmValuePtr args
,
1556 XtAppWarningMsg (app
, "wrongParameters", "cvt_pixel_dtor",
1558 "Screen and colormap arguments required",
1561 else if (closure
!= NULL
)
1563 /* We did allocate the pixel, so free it. */
1564 Screen
*screen
= *(Screen
**) args
[0].addr
;
1565 Colormap cmap
= *(Colormap
*) args
[1].addr
;
1566 x_free_dpy_colors (DisplayOfScreen (screen
), screen
, cmap
,
1567 (Pixel
*) to
->addr
, 1);
1572 #endif /* USE_X_TOOLKIT */
1575 /* Value is an array of XColor structures for the contents of the
1576 color map of display DPY. Set *NCELLS to the size of the array.
1577 Note that this probably shouldn't be called for large color maps,
1578 say a 24-bit TrueColor map. */
1580 static const XColor
*
1581 x_color_cells (Display
*dpy
, int *ncells
)
1583 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1585 if (dpyinfo
->color_cells
== NULL
)
1587 Screen
*screen
= dpyinfo
->screen
;
1590 dpyinfo
->ncolor_cells
1591 = XDisplayCells (dpy
, XScreenNumberOfScreen (screen
));
1592 dpyinfo
->color_cells
1593 = (XColor
*) xmalloc (dpyinfo
->ncolor_cells
1594 * sizeof *dpyinfo
->color_cells
);
1596 for (i
= 0; i
< dpyinfo
->ncolor_cells
; ++i
)
1597 dpyinfo
->color_cells
[i
].pixel
= i
;
1599 XQueryColors (dpy
, dpyinfo
->cmap
,
1600 dpyinfo
->color_cells
, dpyinfo
->ncolor_cells
);
1603 *ncells
= dpyinfo
->ncolor_cells
;
1604 return dpyinfo
->color_cells
;
1608 /* On frame F, translate pixel colors to RGB values for the NCOLORS
1609 colors in COLORS. Use cached information, if available. */
1612 x_query_colors (struct frame
*f
, XColor
*colors
, int ncolors
)
1614 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1616 if (dpyinfo
->color_cells
)
1619 for (i
= 0; i
< ncolors
; ++i
)
1621 unsigned long pixel
= colors
[i
].pixel
;
1622 xassert (pixel
< dpyinfo
->ncolor_cells
);
1623 xassert (dpyinfo
->color_cells
[pixel
].pixel
== pixel
);
1624 colors
[i
] = dpyinfo
->color_cells
[pixel
];
1628 XQueryColors (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), colors
, ncolors
);
1632 /* On frame F, translate pixel color to RGB values for the color in
1633 COLOR. Use cached information, if available. */
1636 x_query_color (struct frame
*f
, XColor
*color
)
1638 x_query_colors (f
, color
, 1);
1642 /* Allocate the color COLOR->pixel on DISPLAY, colormap CMAP. If an
1643 exact match can't be allocated, try the nearest color available.
1644 Value is non-zero if successful. Set *COLOR to the color
1648 x_alloc_nearest_color_1 (Display
*dpy
, Colormap cmap
, XColor
*color
)
1652 rc
= XAllocColor (dpy
, cmap
, color
);
1655 /* If we got to this point, the colormap is full, so we're going
1656 to try to get the next closest color. The algorithm used is
1657 a least-squares matching, which is what X uses for closest
1658 color matching with StaticColor visuals. */
1660 unsigned long nearest_delta
= ~0;
1662 const XColor
*cells
= x_color_cells (dpy
, &ncells
);
1664 for (nearest
= i
= 0; i
< ncells
; ++i
)
1666 long dred
= (color
->red
>> 8) - (cells
[i
].red
>> 8);
1667 long dgreen
= (color
->green
>> 8) - (cells
[i
].green
>> 8);
1668 long dblue
= (color
->blue
>> 8) - (cells
[i
].blue
>> 8);
1669 unsigned long delta
= dred
* dred
+ dgreen
* dgreen
+ dblue
* dblue
;
1671 if (delta
< nearest_delta
)
1674 nearest_delta
= delta
;
1678 color
->red
= cells
[nearest
].red
;
1679 color
->green
= cells
[nearest
].green
;
1680 color
->blue
= cells
[nearest
].blue
;
1681 rc
= XAllocColor (dpy
, cmap
, color
);
1685 /* If allocation succeeded, and the allocated pixel color is not
1686 equal to a cached pixel color recorded earlier, there was a
1687 change in the colormap, so clear the color cache. */
1688 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
1689 XColor
*cached_color
;
1691 if (dpyinfo
->color_cells
1692 && (cached_color
= &dpyinfo
->color_cells
[color
->pixel
],
1693 (cached_color
->red
!= color
->red
1694 || cached_color
->blue
!= color
->blue
1695 || cached_color
->green
!= color
->green
)))
1697 xfree (dpyinfo
->color_cells
);
1698 dpyinfo
->color_cells
= NULL
;
1699 dpyinfo
->ncolor_cells
= 0;
1703 #ifdef DEBUG_X_COLORS
1705 register_color (color
->pixel
);
1706 #endif /* DEBUG_X_COLORS */
1712 /* Allocate the color COLOR->pixel on frame F, colormap CMAP. If an
1713 exact match can't be allocated, try the nearest color available.
1714 Value is non-zero if successful. Set *COLOR to the color
1718 x_alloc_nearest_color (struct frame
*f
, Colormap cmap
, XColor
*color
)
1720 gamma_correct (f
, color
);
1721 return x_alloc_nearest_color_1 (FRAME_X_DISPLAY (f
), cmap
, color
);
1725 /* Allocate color PIXEL on frame F. PIXEL must already be allocated.
1726 It's necessary to do this instead of just using PIXEL directly to
1727 get color reference counts right. */
1730 x_copy_color (struct frame
*f
, long unsigned int pixel
)
1734 color
.pixel
= pixel
;
1736 x_query_color (f
, &color
);
1737 XAllocColor (FRAME_X_DISPLAY (f
), FRAME_X_COLORMAP (f
), &color
);
1739 #ifdef DEBUG_X_COLORS
1740 register_color (pixel
);
1746 /* Allocate color PIXEL on display DPY. PIXEL must already be allocated.
1747 It's necessary to do this instead of just using PIXEL directly to
1748 get color reference counts right. */
1751 x_copy_dpy_color (Display
*dpy
, Colormap cmap
, long unsigned int pixel
)
1755 color
.pixel
= pixel
;
1757 XQueryColor (dpy
, cmap
, &color
);
1758 XAllocColor (dpy
, cmap
, &color
);
1760 #ifdef DEBUG_X_COLORS
1761 register_color (pixel
);
1767 /* Brightness beyond which a color won't have its highlight brightness
1770 Nominally, highlight colors for `3d' faces are calculated by
1771 brightening an object's color by a constant scale factor, but this
1772 doesn't yield good results for dark colors, so for colors who's
1773 brightness is less than this value (on a scale of 0-65535) have an
1774 use an additional additive factor.
1776 The value here is set so that the default menu-bar/mode-line color
1777 (grey75) will not have its highlights changed at all. */
1778 #define HIGHLIGHT_COLOR_DARK_BOOST_LIMIT 48000
1781 /* Allocate a color which is lighter or darker than *PIXEL by FACTOR
1782 or DELTA. Try a color with RGB values multiplied by FACTOR first.
1783 If this produces the same color as PIXEL, try a color where all RGB
1784 values have DELTA added. Return the allocated color in *PIXEL.
1785 DISPLAY is the X display, CMAP is the colormap to operate on.
1786 Value is non-zero if successful. */
1789 x_alloc_lighter_color (struct frame
*f
, Display
*display
, Colormap cmap
, long unsigned int *pixel
, double factor
, int delta
)
1795 /* Get RGB color values. */
1796 color
.pixel
= *pixel
;
1797 x_query_color (f
, &color
);
1799 /* Change RGB values by specified FACTOR. Avoid overflow! */
1800 xassert (factor
>= 0);
1801 new.red
= min (0xffff, factor
* color
.red
);
1802 new.green
= min (0xffff, factor
* color
.green
);
1803 new.blue
= min (0xffff, factor
* color
.blue
);
1805 /* Calculate brightness of COLOR. */
1806 bright
= (2 * color
.red
+ 3 * color
.green
+ color
.blue
) / 6;
1808 /* We only boost colors that are darker than
1809 HIGHLIGHT_COLOR_DARK_BOOST_LIMIT. */
1810 if (bright
< HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
)
1811 /* Make an additive adjustment to NEW, because it's dark enough so
1812 that scaling by FACTOR alone isn't enough. */
1814 /* How far below the limit this color is (0 - 1, 1 being darker). */
1815 double dimness
= 1 - (double)bright
/ HIGHLIGHT_COLOR_DARK_BOOST_LIMIT
;
1816 /* The additive adjustment. */
1817 int min_delta
= delta
* dimness
* factor
/ 2;
1821 new.red
= max (0, new.red
- min_delta
);
1822 new.green
= max (0, new.green
- min_delta
);
1823 new.blue
= max (0, new.blue
- min_delta
);
1827 new.red
= min (0xffff, min_delta
+ new.red
);
1828 new.green
= min (0xffff, min_delta
+ new.green
);
1829 new.blue
= min (0xffff, min_delta
+ new.blue
);
1833 /* Try to allocate the color. */
1834 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1837 if (new.pixel
== *pixel
)
1839 /* If we end up with the same color as before, try adding
1840 delta to the RGB values. */
1841 x_free_colors (f
, &new.pixel
, 1);
1843 new.red
= min (0xffff, delta
+ color
.red
);
1844 new.green
= min (0xffff, delta
+ color
.green
);
1845 new.blue
= min (0xffff, delta
+ color
.blue
);
1846 success_p
= x_alloc_nearest_color (f
, cmap
, &new);
1857 /* Set up the foreground color for drawing relief lines of glyph
1858 string S. RELIEF is a pointer to a struct relief containing the GC
1859 with which lines will be drawn. Use a color that is FACTOR or
1860 DELTA lighter or darker than the relief's background which is found
1861 in S->f->output_data.x->relief_background. If such a color cannot
1862 be allocated, use DEFAULT_PIXEL, instead. */
1865 x_setup_relief_color (struct frame
*f
, struct relief
*relief
, double factor
, int delta
, long unsigned int default_pixel
)
1868 struct x_output
*di
= f
->output_data
.x
;
1869 unsigned long mask
= GCForeground
| GCLineWidth
| GCGraphicsExposures
;
1870 unsigned long pixel
;
1871 unsigned long background
= di
->relief_background
;
1872 Colormap cmap
= FRAME_X_COLORMAP (f
);
1873 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
1874 Display
*dpy
= FRAME_X_DISPLAY (f
);
1876 xgcv
.graphics_exposures
= False
;
1877 xgcv
.line_width
= 1;
1879 /* Free previously allocated color. The color cell will be reused
1880 when it has been freed as many times as it was allocated, so this
1881 doesn't affect faces using the same colors. */
1883 && relief
->allocated_p
)
1885 x_free_colors (f
, &relief
->pixel
, 1);
1886 relief
->allocated_p
= 0;
1889 /* Allocate new color. */
1890 xgcv
.foreground
= default_pixel
;
1892 if (dpyinfo
->n_planes
!= 1
1893 && x_alloc_lighter_color (f
, dpy
, cmap
, &pixel
, factor
, delta
))
1895 relief
->allocated_p
= 1;
1896 xgcv
.foreground
= relief
->pixel
= pixel
;
1899 if (relief
->gc
== 0)
1901 xgcv
.stipple
= dpyinfo
->gray
;
1903 relief
->gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
), mask
, &xgcv
);
1906 XChangeGC (dpy
, relief
->gc
, mask
, &xgcv
);
1910 /* Set up colors for the relief lines around glyph string S. */
1913 x_setup_relief_colors (struct glyph_string
*s
)
1915 struct x_output
*di
= s
->f
->output_data
.x
;
1916 unsigned long color
;
1918 if (s
->face
->use_box_color_for_shadows_p
)
1919 color
= s
->face
->box_color
;
1920 else if (s
->first_glyph
->type
== IMAGE_GLYPH
1922 && !IMAGE_BACKGROUND_TRANSPARENT (s
->img
, s
->f
, 0))
1923 color
= IMAGE_BACKGROUND (s
->img
, s
->f
, 0);
1928 /* Get the background color of the face. */
1929 XGetGCValues (s
->display
, s
->gc
, GCBackground
, &xgcv
);
1930 color
= xgcv
.background
;
1933 if (di
->white_relief
.gc
== 0
1934 || color
!= di
->relief_background
)
1936 di
->relief_background
= color
;
1937 x_setup_relief_color (s
->f
, &di
->white_relief
, 1.2, 0x8000,
1938 WHITE_PIX_DEFAULT (s
->f
));
1939 x_setup_relief_color (s
->f
, &di
->black_relief
, 0.6, 0x4000,
1940 BLACK_PIX_DEFAULT (s
->f
));
1945 /* Draw a relief on frame F inside the rectangle given by LEFT_X,
1946 TOP_Y, RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the relief
1947 to draw, it must be >= 0. RAISED_P non-zero means draw a raised
1948 relief. LEFT_P non-zero means draw a relief on the left side of
1949 the rectangle. RIGHT_P non-zero means draw a relief on the right
1950 side of the rectangle. CLIP_RECT is the clipping rectangle to use
1954 x_draw_relief_rect (struct frame
*f
,
1955 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
1956 int raised_p
, int top_p
, int bot_p
, int left_p
, int right_p
,
1957 XRectangle
*clip_rect
)
1959 Display
*dpy
= FRAME_X_DISPLAY (f
);
1960 Window window
= FRAME_X_WINDOW (f
);
1965 gc
= f
->output_data
.x
->white_relief
.gc
;
1967 gc
= f
->output_data
.x
->black_relief
.gc
;
1968 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1972 for (i
= 0; i
< width
; ++i
)
1973 XDrawLine (dpy
, window
, gc
,
1974 left_x
+ i
* left_p
, top_y
+ i
,
1975 right_x
+ 1 - i
* right_p
, top_y
+ i
);
1979 for (i
= 0; i
< width
; ++i
)
1980 XDrawLine (dpy
, window
, gc
,
1981 left_x
+ i
, top_y
+ i
, left_x
+ i
, bottom_y
- i
+ 1);
1983 XSetClipMask (dpy
, gc
, None
);
1985 gc
= f
->output_data
.x
->black_relief
.gc
;
1987 gc
= f
->output_data
.x
->white_relief
.gc
;
1988 XSetClipRectangles (dpy
, gc
, 0, 0, clip_rect
, 1, Unsorted
);
1992 for (i
= 0; i
< width
; ++i
)
1993 XDrawLine (dpy
, window
, gc
,
1994 left_x
+ i
* left_p
, bottom_y
- i
,
1995 right_x
+ 1 - i
* right_p
, bottom_y
- i
);
1999 for (i
= 0; i
< width
; ++i
)
2000 XDrawLine (dpy
, window
, gc
,
2001 right_x
- i
, top_y
+ i
+ 1, right_x
- i
, bottom_y
- i
);
2003 XSetClipMask (dpy
, gc
, None
);
2007 /* Draw a box on frame F inside the rectangle given by LEFT_X, TOP_Y,
2008 RIGHT_X, and BOTTOM_Y. WIDTH is the thickness of the lines to
2009 draw, it must be >= 0. LEFT_P non-zero means draw a line on the
2010 left side of the rectangle. RIGHT_P non-zero means draw a line
2011 on the right side of the rectangle. CLIP_RECT is the clipping
2012 rectangle to use when drawing. */
2015 x_draw_box_rect (struct glyph_string
*s
,
2016 int left_x
, int top_y
, int right_x
, int bottom_y
, int width
,
2017 int left_p
, int right_p
, XRectangle
*clip_rect
)
2021 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2022 XSetForeground (s
->display
, s
->gc
, s
->face
->box_color
);
2023 XSetClipRectangles (s
->display
, s
->gc
, 0, 0, clip_rect
, 1, Unsorted
);
2026 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2027 left_x
, top_y
, right_x
- left_x
+ 1, width
);
2031 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2032 left_x
, top_y
, width
, bottom_y
- top_y
+ 1);
2035 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2036 left_x
, bottom_y
- width
+ 1, right_x
- left_x
+ 1, width
);
2040 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2041 right_x
- width
+ 1, top_y
, width
, bottom_y
- top_y
+ 1);
2043 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2044 XSetClipMask (s
->display
, s
->gc
, None
);
2048 /* Draw a box around glyph string S. */
2051 x_draw_glyph_string_box (struct glyph_string
*s
)
2053 int width
, left_x
, right_x
, top_y
, bottom_y
, last_x
, raised_p
;
2054 int left_p
, right_p
;
2055 struct glyph
*last_glyph
;
2056 XRectangle clip_rect
;
2058 last_x
= ((s
->row
->full_width_p
&& !s
->w
->pseudo_window_p
)
2059 ? WINDOW_RIGHT_EDGE_X (s
->w
)
2060 : window_box_right (s
->w
, s
->area
));
2062 /* The glyph that may have a right box line. */
2063 last_glyph
= (s
->cmp
|| s
->img
2065 : s
->first_glyph
+ s
->nchars
- 1);
2067 width
= eabs (s
->face
->box_line_width
);
2068 raised_p
= s
->face
->box
== FACE_RAISED_BOX
;
2070 right_x
= (s
->row
->full_width_p
&& s
->extends_to_end_of_line_p
2072 : min (last_x
, s
->x
+ s
->background_width
) - 1);
2074 bottom_y
= top_y
+ s
->height
- 1;
2076 left_p
= (s
->first_glyph
->left_box_line_p
2077 || (s
->hl
== DRAW_MOUSE_FACE
2079 || s
->prev
->hl
!= s
->hl
)));
2080 right_p
= (last_glyph
->right_box_line_p
2081 || (s
->hl
== DRAW_MOUSE_FACE
2083 || s
->next
->hl
!= s
->hl
)));
2085 get_glyph_string_clip_rect (s
, &clip_rect
);
2087 if (s
->face
->box
== FACE_SIMPLE_BOX
)
2088 x_draw_box_rect (s
, left_x
, top_y
, right_x
, bottom_y
, width
,
2089 left_p
, right_p
, &clip_rect
);
2092 x_setup_relief_colors (s
);
2093 x_draw_relief_rect (s
->f
, left_x
, top_y
, right_x
, bottom_y
,
2094 width
, raised_p
, 1, 1, left_p
, right_p
, &clip_rect
);
2099 /* Draw foreground of image glyph string S. */
2102 x_draw_image_foreground (struct glyph_string
*s
)
2105 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2107 /* If first glyph of S has a left box line, start drawing it to the
2108 right of that line. */
2109 if (s
->face
->box
!= FACE_NO_BOX
2110 && s
->first_glyph
->left_box_line_p
2112 x
+= eabs (s
->face
->box_line_width
);
2114 /* If there is a margin around the image, adjust x- and y-position
2116 if (s
->slice
.x
== 0)
2117 x
+= s
->img
->hmargin
;
2118 if (s
->slice
.y
== 0)
2119 y
+= s
->img
->vmargin
;
2125 /* We can't set both a clip mask and use XSetClipRectangles
2126 because the latter also sets a clip mask. We also can't
2127 trust on the shape extension to be available
2128 (XShapeCombineRegion). So, compute the rectangle to draw
2130 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2133 XRectangle clip_rect
, image_rect
, r
;
2135 xgcv
.clip_mask
= s
->img
->mask
;
2136 xgcv
.clip_x_origin
= x
;
2137 xgcv
.clip_y_origin
= y
;
2138 xgcv
.function
= GXcopy
;
2139 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2141 get_glyph_string_clip_rect (s
, &clip_rect
);
2144 image_rect
.width
= s
->slice
.width
;
2145 image_rect
.height
= s
->slice
.height
;
2146 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2147 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2148 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2149 r
.width
, r
.height
, r
.x
, r
.y
);
2153 XRectangle clip_rect
, image_rect
, r
;
2155 get_glyph_string_clip_rect (s
, &clip_rect
);
2158 image_rect
.width
= s
->slice
.width
;
2159 image_rect
.height
= s
->slice
.height
;
2160 if (x_intersect_rectangles (&clip_rect
, &image_rect
, &r
))
2161 XCopyArea (s
->display
, s
->img
->pixmap
, s
->window
, s
->gc
,
2162 s
->slice
.x
+ r
.x
- x
, s
->slice
.y
+ r
.y
- y
,
2163 r
.width
, r
.height
, r
.x
, r
.y
);
2165 /* When the image has a mask, we can expect that at
2166 least part of a mouse highlight or a block cursor will
2167 be visible. If the image doesn't have a mask, make
2168 a block cursor visible by drawing a rectangle around
2169 the image. I believe it's looking better if we do
2170 nothing here for mouse-face. */
2171 if (s
->hl
== DRAW_CURSOR
)
2173 int r
= s
->img
->relief
;
2175 XDrawRectangle (s
->display
, s
->window
, s
->gc
,
2177 s
->slice
.width
+ r
*2 - 1,
2178 s
->slice
.height
+ r
*2 - 1);
2183 /* Draw a rectangle if image could not be loaded. */
2184 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
, y
,
2185 s
->slice
.width
- 1, s
->slice
.height
- 1);
2189 /* Draw a relief around the image glyph string S. */
2192 x_draw_image_relief (struct glyph_string
*s
)
2194 int x0
, y0
, x1
, y1
, thick
, raised_p
, extra
;
2197 int y
= s
->ybase
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2199 /* If first glyph of S has a left box line, start drawing it to the
2200 right of that line. */
2201 if (s
->face
->box
!= FACE_NO_BOX
2202 && s
->first_glyph
->left_box_line_p
2204 x
+= eabs (s
->face
->box_line_width
);
2206 /* If there is a margin around the image, adjust x- and y-position
2208 if (s
->slice
.x
== 0)
2209 x
+= s
->img
->hmargin
;
2210 if (s
->slice
.y
== 0)
2211 y
+= s
->img
->vmargin
;
2213 if (s
->hl
== DRAW_IMAGE_SUNKEN
2214 || s
->hl
== DRAW_IMAGE_RAISED
)
2216 thick
= tool_bar_button_relief
>= 0 ? tool_bar_button_relief
: DEFAULT_TOOL_BAR_BUTTON_RELIEF
;
2217 raised_p
= s
->hl
== DRAW_IMAGE_RAISED
;
2221 thick
= eabs (s
->img
->relief
);
2222 raised_p
= s
->img
->relief
> 0;
2225 extra
= s
->face
->id
== TOOL_BAR_FACE_ID
2226 ? XINT (Vtool_bar_button_margin
) : 0;
2228 x0
= x
- thick
- extra
;
2229 y0
= y
- thick
- extra
;
2230 x1
= x
+ s
->slice
.width
+ thick
- 1 + extra
;
2231 y1
= y
+ s
->slice
.height
+ thick
- 1 + extra
;
2233 x_setup_relief_colors (s
);
2234 get_glyph_string_clip_rect (s
, &r
);
2235 x_draw_relief_rect (s
->f
, x0
, y0
, x1
, y1
, thick
, raised_p
,
2237 s
->slice
.y
+ s
->slice
.height
== s
->img
->height
,
2239 s
->slice
.x
+ s
->slice
.width
== s
->img
->width
,
2244 /* Draw the foreground of image glyph string S to PIXMAP. */
2247 x_draw_image_foreground_1 (struct glyph_string
*s
, Pixmap pixmap
)
2250 int y
= s
->ybase
- s
->y
- image_ascent (s
->img
, s
->face
, &s
->slice
);
2252 /* If first glyph of S has a left box line, start drawing it to the
2253 right of that line. */
2254 if (s
->face
->box
!= FACE_NO_BOX
2255 && s
->first_glyph
->left_box_line_p
2257 x
+= eabs (s
->face
->box_line_width
);
2259 /* If there is a margin around the image, adjust x- and y-position
2261 if (s
->slice
.x
== 0)
2262 x
+= s
->img
->hmargin
;
2263 if (s
->slice
.y
== 0)
2264 y
+= s
->img
->vmargin
;
2270 /* We can't set both a clip mask and use XSetClipRectangles
2271 because the latter also sets a clip mask. We also can't
2272 trust on the shape extension to be available
2273 (XShapeCombineRegion). So, compute the rectangle to draw
2275 unsigned long mask
= (GCClipMask
| GCClipXOrigin
| GCClipYOrigin
2279 xgcv
.clip_mask
= s
->img
->mask
;
2280 xgcv
.clip_x_origin
= x
- s
->slice
.x
;
2281 xgcv
.clip_y_origin
= y
- s
->slice
.y
;
2282 xgcv
.function
= GXcopy
;
2283 XChangeGC (s
->display
, s
->gc
, mask
, &xgcv
);
2285 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2286 s
->slice
.x
, s
->slice
.y
,
2287 s
->slice
.width
, s
->slice
.height
, x
, y
);
2288 XSetClipMask (s
->display
, s
->gc
, None
);
2292 XCopyArea (s
->display
, s
->img
->pixmap
, pixmap
, s
->gc
,
2293 s
->slice
.x
, s
->slice
.y
,
2294 s
->slice
.width
, s
->slice
.height
, x
, y
);
2296 /* When the image has a mask, we can expect that at
2297 least part of a mouse highlight or a block cursor will
2298 be visible. If the image doesn't have a mask, make
2299 a block cursor visible by drawing a rectangle around
2300 the image. I believe it's looking better if we do
2301 nothing here for mouse-face. */
2302 if (s
->hl
== DRAW_CURSOR
)
2304 int r
= s
->img
->relief
;
2306 XDrawRectangle (s
->display
, s
->window
, s
->gc
, x
- r
, y
- r
,
2307 s
->slice
.width
+ r
*2 - 1,
2308 s
->slice
.height
+ r
*2 - 1);
2313 /* Draw a rectangle if image could not be loaded. */
2314 XDrawRectangle (s
->display
, pixmap
, s
->gc
, x
, y
,
2315 s
->slice
.width
- 1, s
->slice
.height
- 1);
2319 /* Draw part of the background of glyph string S. X, Y, W, and H
2320 give the rectangle to draw. */
2323 x_draw_glyph_string_bg_rect (struct glyph_string
*s
, int x
, int y
, int w
, int h
)
2327 /* Fill background with a stipple pattern. */
2328 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2329 XFillRectangle (s
->display
, s
->window
, s
->gc
, x
, y
, w
, h
);
2330 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2333 x_clear_glyph_string_rect (s
, x
, y
, w
, h
);
2337 /* Draw image glyph string S.
2340 s->x +-------------------------
2343 | +-------------------------
2346 | | +-------------------
2352 x_draw_image_glyph_string (struct glyph_string
*s
)
2354 int box_line_hwidth
= eabs (s
->face
->box_line_width
);
2355 int box_line_vwidth
= max (s
->face
->box_line_width
, 0);
2357 Pixmap pixmap
= None
;
2360 if (s
->slice
.y
== 0)
2361 height
-= box_line_vwidth
;
2362 if (s
->slice
.y
+ s
->slice
.height
>= s
->img
->height
)
2363 height
-= box_line_vwidth
;
2365 /* Fill background with face under the image. Do it only if row is
2366 taller than image or if image has a clip mask to reduce
2368 s
->stippled_p
= s
->face
->stipple
!= 0;
2369 if (height
> s
->slice
.height
2373 || s
->img
->pixmap
== 0
2374 || s
->width
!= s
->background_width
)
2378 /* Create a pixmap as large as the glyph string. Fill it
2379 with the background color. Copy the image to it, using
2380 its mask. Copy the temporary pixmap to the display. */
2381 Screen
*screen
= FRAME_X_SCREEN (s
->f
);
2382 int depth
= DefaultDepthOfScreen (screen
);
2384 /* Create a pixmap as large as the glyph string. */
2385 pixmap
= XCreatePixmap (s
->display
, s
->window
,
2386 s
->background_width
,
2389 /* Don't clip in the following because we're working on the
2391 XSetClipMask (s
->display
, s
->gc
, None
);
2393 /* Fill the pixmap with the background color/stipple. */
2396 /* Fill background with a stipple pattern. */
2397 XSetFillStyle (s
->display
, s
->gc
, FillOpaqueStippled
);
2398 XSetTSOrigin (s
->display
, s
->gc
, - s
->x
, - s
->y
);
2399 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2400 0, 0, s
->background_width
, s
->height
);
2401 XSetFillStyle (s
->display
, s
->gc
, FillSolid
);
2402 XSetTSOrigin (s
->display
, s
->gc
, 0, 0);
2407 XGetGCValues (s
->display
, s
->gc
, GCForeground
| GCBackground
,
2409 XSetForeground (s
->display
, s
->gc
, xgcv
.background
);
2410 XFillRectangle (s
->display
, pixmap
, s
->gc
,
2411 0, 0, s
->background_width
, s
->height
);
2412 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2420 if (s
->first_glyph
->left_box_line_p
2422 x
+= box_line_hwidth
;
2424 if (s
->slice
.y
== 0)
2425 y
+= box_line_vwidth
;
2427 x_draw_glyph_string_bg_rect (s
, x
, y
, s
->background_width
, height
);
2430 s
->background_filled_p
= 1;
2433 /* Draw the foreground. */
2436 x_draw_image_foreground_1 (s
, pixmap
);
2437 x_set_glyph_string_clipping (s
);
2438 XCopyArea (s
->display
, pixmap
, s
->window
, s
->gc
,
2439 0, 0, s
->background_width
, s
->height
, s
->x
, s
->y
);
2440 XFreePixmap (s
->display
, pixmap
);
2443 x_draw_image_foreground (s
);
2445 /* If we must draw a relief around the image, do it. */
2447 || s
->hl
== DRAW_IMAGE_RAISED
2448 || s
->hl
== DRAW_IMAGE_SUNKEN
)
2449 x_draw_image_relief (s
);
2453 /* Draw stretch glyph string S. */
2456 x_draw_stretch_glyph_string (struct glyph_string
*s
)
2458 xassert (s
->first_glyph
->type
== STRETCH_GLYPH
);
2460 if (s
->hl
== DRAW_CURSOR
2461 && !x_stretch_cursor_p
)
2463 /* If `x-stretch-block-cursor' is nil, don't draw a block cursor
2464 as wide as the stretch glyph. */
2465 int width
, background_width
= s
->background_width
;
2466 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2470 background_width
-= left_x
- x
;
2473 width
= min (FRAME_COLUMN_WIDTH (s
->f
), background_width
);
2476 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, width
, s
->height
);
2478 /* Clear rest using the GC of the original non-cursor face. */
2479 if (width
< background_width
)
2482 int w
= background_width
- width
, h
= s
->height
;
2487 if (s
->row
->mouse_face_p
2488 && cursor_in_mouse_face_p (s
->w
))
2490 x_set_mouse_face_gc (s
);
2496 get_glyph_string_clip_rect (s
, &r
);
2497 XSetClipRectangles (s
->display
, gc
, 0, 0, &r
, 1, Unsorted
);
2499 if (s
->face
->stipple
)
2501 /* Fill background with a stipple pattern. */
2502 XSetFillStyle (s
->display
, gc
, FillOpaqueStippled
);
2503 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2504 XSetFillStyle (s
->display
, gc
, FillSolid
);
2509 XGetGCValues (s
->display
, gc
, GCForeground
| GCBackground
, &xgcv
);
2510 XSetForeground (s
->display
, gc
, xgcv
.background
);
2511 XFillRectangle (s
->display
, s
->window
, gc
, x
, y
, w
, h
);
2512 XSetForeground (s
->display
, gc
, xgcv
.foreground
);
2516 else if (!s
->background_filled_p
)
2518 int background_width
= s
->background_width
;
2519 int x
= s
->x
, left_x
= window_box_left_offset (s
->w
, TEXT_AREA
);
2521 /* Don't draw into left margin, fringe or scrollbar area
2522 except for header line and mode line. */
2523 if (x
< left_x
&& !s
->row
->mode_line_p
)
2525 background_width
-= left_x
- x
;
2528 if (background_width
> 0)
2529 x_draw_glyph_string_bg_rect (s
, x
, s
->y
, background_width
, s
->height
);
2532 s
->background_filled_p
= 1;
2536 /* Draw glyph string S. */
2539 x_draw_glyph_string (struct glyph_string
*s
)
2541 int relief_drawn_p
= 0;
2543 /* If S draws into the background of its successors, draw the
2544 background of the successors first so that S can draw into it.
2545 This makes S->next use XDrawString instead of XDrawImageString. */
2546 if (s
->next
&& s
->right_overhang
&& !s
->for_overlaps
)
2549 struct glyph_string
*next
;
2551 for (width
= 0, next
= s
->next
;
2552 next
&& width
< s
->right_overhang
;
2553 width
+= next
->width
, next
= next
->next
)
2554 if (next
->first_glyph
->type
!= IMAGE_GLYPH
)
2556 x_set_glyph_string_gc (next
);
2557 x_set_glyph_string_clipping (next
);
2558 if (next
->first_glyph
->type
== STRETCH_GLYPH
)
2559 x_draw_stretch_glyph_string (next
);
2561 x_draw_glyph_string_background (next
, 1);
2562 next
->num_clips
= 0;
2566 /* Set up S->gc, set clipping and draw S. */
2567 x_set_glyph_string_gc (s
);
2569 /* Draw relief (if any) in advance for char/composition so that the
2570 glyph string can be drawn over it. */
2571 if (!s
->for_overlaps
2572 && s
->face
->box
!= FACE_NO_BOX
2573 && (s
->first_glyph
->type
== CHAR_GLYPH
2574 || s
->first_glyph
->type
== COMPOSITE_GLYPH
))
2577 x_set_glyph_string_clipping (s
);
2578 x_draw_glyph_string_background (s
, 1);
2579 x_draw_glyph_string_box (s
);
2580 x_set_glyph_string_clipping (s
);
2583 else if (!s
->clip_head
/* draw_glyphs didn't specify a clip mask. */
2585 && ((s
->prev
&& s
->prev
->hl
!= s
->hl
&& s
->left_overhang
)
2586 || (s
->next
&& s
->next
->hl
!= s
->hl
&& s
->right_overhang
)))
2587 /* We must clip just this glyph. left_overhang part has already
2588 drawn when s->prev was drawn, and right_overhang part will be
2589 drawn later when s->next is drawn. */
2590 x_set_glyph_string_clipping_exactly (s
, s
);
2592 x_set_glyph_string_clipping (s
);
2594 switch (s
->first_glyph
->type
)
2597 x_draw_image_glyph_string (s
);
2601 x_draw_stretch_glyph_string (s
);
2605 if (s
->for_overlaps
)
2606 s
->background_filled_p
= 1;
2608 x_draw_glyph_string_background (s
, 0);
2609 x_draw_glyph_string_foreground (s
);
2612 case COMPOSITE_GLYPH
:
2613 if (s
->for_overlaps
|| (s
->cmp_from
> 0
2614 && ! s
->first_glyph
->u
.cmp
.automatic
))
2615 s
->background_filled_p
= 1;
2617 x_draw_glyph_string_background (s
, 1);
2618 x_draw_composite_glyph_string_foreground (s
);
2625 if (!s
->for_overlaps
)
2627 /* Draw underline. */
2628 if (s
->face
->underline_p
)
2630 unsigned long thickness
, position
;
2633 if (s
->prev
&& s
->prev
->face
->underline_p
)
2635 /* We use the same underline style as the previous one. */
2636 thickness
= s
->prev
->underline_thickness
;
2637 position
= s
->prev
->underline_position
;
2641 /* Get the underline thickness. Default is 1 pixel. */
2642 if (s
->font
&& s
->font
->underline_thickness
> 0)
2643 thickness
= s
->font
->underline_thickness
;
2646 if (x_underline_at_descent_line
)
2647 position
= (s
->height
- thickness
) - (s
->ybase
- s
->y
);
2650 /* Get the underline position. This is the recommended
2651 vertical offset in pixels from the baseline to the top of
2652 the underline. This is a signed value according to the
2653 specs, and its default is
2655 ROUND ((maximum descent) / 2), with
2656 ROUND(x) = floor (x + 0.5) */
2658 if (x_use_underline_position_properties
2659 && s
->font
&& s
->font
->underline_position
>= 0)
2660 position
= s
->font
->underline_position
;
2662 position
= (s
->font
->descent
+ 1) / 2;
2664 position
= underline_minimum_offset
;
2666 position
= max (position
, underline_minimum_offset
);
2668 /* Check the sanity of thickness and position. We should
2669 avoid drawing underline out of the current line area. */
2670 if (s
->y
+ s
->height
<= s
->ybase
+ position
)
2671 position
= (s
->height
- 1) - (s
->ybase
- s
->y
);
2672 if (s
->y
+ s
->height
< s
->ybase
+ position
+ thickness
)
2673 thickness
= (s
->y
+ s
->height
) - (s
->ybase
+ position
);
2674 s
->underline_thickness
= thickness
;
2675 s
->underline_position
= position
;
2676 y
= s
->ybase
+ position
;
2677 if (s
->face
->underline_defaulted_p
)
2678 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2679 s
->x
, y
, s
->width
, thickness
);
2683 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2684 XSetForeground (s
->display
, s
->gc
, s
->face
->underline_color
);
2685 XFillRectangle (s
->display
, s
->window
, s
->gc
,
2686 s
->x
, y
, s
->width
, thickness
);
2687 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2691 /* Draw overline. */
2692 if (s
->face
->overline_p
)
2694 unsigned long dy
= 0, h
= 1;
2696 if (s
->face
->overline_color_defaulted_p
)
2697 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2702 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2703 XSetForeground (s
->display
, s
->gc
, s
->face
->overline_color
);
2704 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2706 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2710 /* Draw strike-through. */
2711 if (s
->face
->strike_through_p
)
2713 unsigned long h
= 1;
2714 unsigned long dy
= (s
->height
- h
) / 2;
2716 if (s
->face
->strike_through_color_defaulted_p
)
2717 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2722 XGetGCValues (s
->display
, s
->gc
, GCForeground
, &xgcv
);
2723 XSetForeground (s
->display
, s
->gc
, s
->face
->strike_through_color
);
2724 XFillRectangle (s
->display
, s
->window
, s
->gc
, s
->x
, s
->y
+ dy
,
2726 XSetForeground (s
->display
, s
->gc
, xgcv
.foreground
);
2730 /* Draw relief if not yet drawn. */
2731 if (!relief_drawn_p
&& s
->face
->box
!= FACE_NO_BOX
)
2732 x_draw_glyph_string_box (s
);
2736 struct glyph_string
*prev
;
2738 for (prev
= s
->prev
; prev
; prev
= prev
->prev
)
2739 if (prev
->hl
!= s
->hl
2740 && prev
->x
+ prev
->width
+ prev
->right_overhang
> s
->x
)
2742 /* As prev was drawn while clipped to its own area, we
2743 must draw the right_overhang part using s->hl now. */
2744 enum draw_glyphs_face save
= prev
->hl
;
2747 x_set_glyph_string_gc (prev
);
2748 x_set_glyph_string_clipping_exactly (s
, prev
);
2749 if (prev
->first_glyph
->type
== CHAR_GLYPH
)
2750 x_draw_glyph_string_foreground (prev
);
2752 x_draw_composite_glyph_string_foreground (prev
);
2753 XSetClipMask (prev
->display
, prev
->gc
, None
);
2755 prev
->num_clips
= 0;
2761 struct glyph_string
*next
;
2763 for (next
= s
->next
; next
; next
= next
->next
)
2764 if (next
->hl
!= s
->hl
2765 && next
->x
- next
->left_overhang
< s
->x
+ s
->width
)
2767 /* As next will be drawn while clipped to its own area,
2768 we must draw the left_overhang part using s->hl now. */
2769 enum draw_glyphs_face save
= next
->hl
;
2772 x_set_glyph_string_gc (next
);
2773 x_set_glyph_string_clipping_exactly (s
, next
);
2774 if (next
->first_glyph
->type
== CHAR_GLYPH
)
2775 x_draw_glyph_string_foreground (next
);
2777 x_draw_composite_glyph_string_foreground (next
);
2778 XSetClipMask (next
->display
, next
->gc
, None
);
2780 next
->num_clips
= 0;
2785 /* Reset clipping. */
2786 XSetClipMask (s
->display
, s
->gc
, None
);
2790 /* Shift display to make room for inserted glyphs. */
2793 x_shift_glyphs_for_insert (struct frame
*f
, int x
, int y
, int width
, int height
, int shift_by
)
2795 XCopyArea (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
2796 f
->output_data
.x
->normal_gc
,
2797 x
, y
, width
, height
,
2801 /* Delete N glyphs at the nominal cursor position. Not implemented
2805 x_delete_glyphs (struct frame
*f
, register int n
)
2811 /* Like XClearArea, but check that WIDTH and HEIGHT are reasonable.
2812 If they are <= 0, this is probably an error. */
2815 x_clear_area (Display
*dpy
, Window window
, int x
, int y
, int width
, int height
, int exposures
)
2817 xassert (width
> 0 && height
> 0);
2818 XClearArea (dpy
, window
, x
, y
, width
, height
, exposures
);
2822 /* Clear an entire frame. */
2825 x_clear_frame (struct frame
*f
)
2827 /* Clearing the frame will erase any cursor, so mark them all as no
2829 mark_window_cursors_off (XWINDOW (FRAME_ROOT_WINDOW (f
)));
2830 output_cursor
.hpos
= output_cursor
.vpos
= 0;
2831 output_cursor
.x
= -1;
2833 /* We don't set the output cursor here because there will always
2834 follow an explicit cursor_to. */
2836 XClearWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
2838 /* We have to clear the scroll bars, too. If we have changed
2839 colors or something like that, then they should be notified. */
2840 x_scroll_bar_clear (f
);
2842 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
2843 /* Make sure scroll bars are redrawn. As they aren't redrawn by
2844 redisplay, do it here. */
2845 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
2848 XFlush (FRAME_X_DISPLAY (f
));
2855 /* Invert the middle quarter of the frame for .15 sec. */
2857 /* We use the select system call to do the waiting, so we have to make
2858 sure it's available. If it isn't, we just won't do visual bells. */
2860 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
2863 /* Subtract the `struct timeval' values X and Y, storing the result in
2864 *RESULT. Return 1 if the difference is negative, otherwise 0. */
2867 timeval_subtract (struct timeval
*result
, struct timeval x
, struct timeval y
)
2869 /* Perform the carry for the later subtraction by updating y. This
2870 is safer because on some systems the tv_sec member is unsigned. */
2871 if (x
.tv_usec
< y
.tv_usec
)
2873 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000 + 1;
2874 y
.tv_usec
-= 1000000 * nsec
;
2878 if (x
.tv_usec
- y
.tv_usec
> 1000000)
2880 int nsec
= (y
.tv_usec
- x
.tv_usec
) / 1000000;
2881 y
.tv_usec
+= 1000000 * nsec
;
2885 /* Compute the time remaining to wait. tv_usec is certainly
2887 result
->tv_sec
= x
.tv_sec
- y
.tv_sec
;
2888 result
->tv_usec
= x
.tv_usec
- y
.tv_usec
;
2890 /* Return indication of whether the result should be considered
2892 return x
.tv_sec
< y
.tv_sec
;
2896 XTflash (struct frame
*f
)
2902 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
2903 when the scroll bars and the edit widget share the same X window. */
2904 GdkWindow
*window
= gtk_widget_get_window (FRAME_GTK_WIDGET (f
));
2907 vals
.foreground
.pixel
= (FRAME_FOREGROUND_PIXEL (f
)
2908 ^ FRAME_BACKGROUND_PIXEL (f
));
2909 vals
.function
= GDK_XOR
;
2910 gc
= gdk_gc_new_with_values (window
,
2911 &vals
, GDK_GC_FUNCTION
| GDK_GC_FOREGROUND
);
2912 #define XFillRectangle(d, win, gc, x, y, w, h) \
2913 gdk_draw_rectangle (window, gc, TRUE, x, y, w, h)
2917 /* Create a GC that will use the GXxor function to flip foreground
2918 pixels into background pixels. */
2922 values
.function
= GXxor
;
2923 values
.foreground
= (FRAME_FOREGROUND_PIXEL (f
)
2924 ^ FRAME_BACKGROUND_PIXEL (f
));
2926 gc
= XCreateGC (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
2927 GCFunction
| GCForeground
, &values
);
2931 /* Get the height not including a menu bar widget. */
2932 int height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, FRAME_LINES (f
));
2933 /* Height of each line to flash. */
2934 int flash_height
= FRAME_LINE_HEIGHT (f
);
2935 /* These will be the left and right margins of the rectangles. */
2936 int flash_left
= FRAME_INTERNAL_BORDER_WIDTH (f
);
2937 int flash_right
= FRAME_PIXEL_WIDTH (f
) - FRAME_INTERNAL_BORDER_WIDTH (f
);
2941 /* Don't flash the area between a scroll bar and the frame
2942 edge it is next to. */
2943 switch (FRAME_VERTICAL_SCROLL_BAR_TYPE (f
))
2945 case vertical_scroll_bar_left
:
2946 flash_left
+= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2949 case vertical_scroll_bar_right
:
2950 flash_right
-= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
2957 width
= flash_right
- flash_left
;
2959 /* If window is tall, flash top and bottom line. */
2960 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
2962 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2964 (FRAME_INTERNAL_BORDER_WIDTH (f
)
2965 + FRAME_TOP_MARGIN_HEIGHT (f
)),
2966 width
, flash_height
);
2967 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2969 (height
- flash_height
2970 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
2971 width
, flash_height
);
2975 /* If it is short, flash it all. */
2976 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
2977 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
2978 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
2983 struct timeval wakeup
;
2985 EMACS_GET_TIME (wakeup
);
2987 /* Compute time to wait until, propagating carry from usecs. */
2988 wakeup
.tv_usec
+= 150000;
2989 wakeup
.tv_sec
+= (wakeup
.tv_usec
/ 1000000);
2990 wakeup
.tv_usec
%= 1000000;
2992 /* Keep waiting until past the time wakeup or any input gets
2994 while (! detect_input_pending ())
2996 struct timeval current
;
2997 struct timeval timeout
;
2999 EMACS_GET_TIME (current
);
3001 /* Break if result would be negative. */
3002 if (timeval_subtract (¤t
, wakeup
, current
))
3005 /* How long `select' should wait. */
3007 timeout
.tv_usec
= 10000;
3009 /* Try to wait that long--but we might wake up sooner. */
3010 select (0, NULL
, NULL
, NULL
, &timeout
);
3014 /* If window is tall, flash top and bottom line. */
3015 if (height
> 3 * FRAME_LINE_HEIGHT (f
))
3017 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3019 (FRAME_INTERNAL_BORDER_WIDTH (f
)
3020 + FRAME_TOP_MARGIN_HEIGHT (f
)),
3021 width
, flash_height
);
3022 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3024 (height
- flash_height
3025 - FRAME_INTERNAL_BORDER_WIDTH (f
)),
3026 width
, flash_height
);
3029 /* If it is short, flash it all. */
3030 XFillRectangle (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), gc
,
3031 flash_left
, FRAME_INTERNAL_BORDER_WIDTH (f
),
3032 width
, height
- 2 * FRAME_INTERNAL_BORDER_WIDTH (f
));
3035 g_object_unref (G_OBJECT (gc
));
3036 #undef XFillRectangle
3038 XFreeGC (FRAME_X_DISPLAY (f
), gc
);
3047 #endif /* defined (HAVE_TIMEVAL) && defined (HAVE_SELECT) */
3051 XTtoggle_invisible_pointer (FRAME_PTR f
, int invisible
)
3056 if (FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
!= 0)
3057 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3058 FRAME_X_DISPLAY_INFO (f
)->invisible_cursor
);
3061 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3062 f
->output_data
.x
->current_cursor
);
3063 f
->pointer_invisible
= invisible
;
3068 /* Make audible bell. */
3071 XTring_bell (struct frame
*f
)
3073 if (FRAME_X_DISPLAY (f
))
3075 #if defined (HAVE_TIMEVAL) && defined (HAVE_SELECT)
3082 XBell (FRAME_X_DISPLAY (f
), 0);
3083 XFlush (FRAME_X_DISPLAY (f
));
3090 /* Specify how many text lines, from the top of the window,
3091 should be affected by insert-lines and delete-lines operations.
3092 This, and those operations, are used only within an update
3093 that is bounded by calls to x_update_begin and x_update_end. */
3096 XTset_terminal_window (struct frame
*f
, int n
)
3098 /* This function intentionally left blank. */
3103 /***********************************************************************
3105 ***********************************************************************/
3107 /* Perform an insert-lines or delete-lines operation, inserting N
3108 lines or deleting -N lines at vertical position VPOS. */
3111 x_ins_del_lines (struct frame
*f
, int vpos
, int n
)
3117 /* Scroll part of the display as described by RUN. */
3120 x_scroll_run (struct window
*w
, struct run
*run
)
3122 struct frame
*f
= XFRAME (w
->frame
);
3123 int x
, y
, width
, height
, from_y
, to_y
, bottom_y
;
3125 /* Get frame-relative bounding box of the text display area of W,
3126 without mode lines. Include in this box the left and right
3128 window_box (w
, -1, &x
, &y
, &width
, &height
);
3130 from_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->current_y
);
3131 to_y
= WINDOW_TO_FRAME_PIXEL_Y (w
, run
->desired_y
);
3132 bottom_y
= y
+ height
;
3136 /* Scrolling up. Make sure we don't copy part of the mode
3137 line at the bottom. */
3138 if (from_y
+ run
->height
> bottom_y
)
3139 height
= bottom_y
- from_y
;
3141 height
= run
->height
;
3145 /* Scolling down. Make sure we don't copy over the mode line.
3147 if (to_y
+ run
->height
> bottom_y
)
3148 height
= bottom_y
- to_y
;
3150 height
= run
->height
;
3155 /* Cursor off. Will be switched on again in x_update_window_end. */
3159 XCopyArea (FRAME_X_DISPLAY (f
),
3160 FRAME_X_WINDOW (f
), FRAME_X_WINDOW (f
),
3161 f
->output_data
.x
->normal_gc
,
3171 /***********************************************************************
3173 ***********************************************************************/
3177 frame_highlight (struct frame
*f
)
3179 /* We used to only do this if Vx_no_window_manager was non-nil, but
3180 the ICCCM (section 4.1.6) says that the window's border pixmap
3181 and border pixel are window attributes which are "private to the
3182 client", so we can always change it to whatever we want. */
3184 XSetWindowBorder (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3185 f
->output_data
.x
->border_pixel
);
3187 x_update_cursor (f
, 1);
3188 x_set_frame_alpha (f
);
3192 frame_unhighlight (struct frame
*f
)
3194 /* We used to only do this if Vx_no_window_manager was non-nil, but
3195 the ICCCM (section 4.1.6) says that the window's border pixmap
3196 and border pixel are window attributes which are "private to the
3197 client", so we can always change it to whatever we want. */
3199 XSetWindowBorderPixmap (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
3200 f
->output_data
.x
->border_tile
);
3202 x_update_cursor (f
, 1);
3203 x_set_frame_alpha (f
);
3206 /* The focus has changed. Update the frames as necessary to reflect
3207 the new situation. Note that we can't change the selected frame
3208 here, because the Lisp code we are interrupting might become confused.
3209 Each event gets marked with the frame in which it occurred, so the
3210 Lisp code can tell when the switch took place by examining the events. */
3213 x_new_focus_frame (struct x_display_info
*dpyinfo
, struct frame
*frame
)
3215 struct frame
*old_focus
= dpyinfo
->x_focus_frame
;
3217 if (frame
!= dpyinfo
->x_focus_frame
)
3219 /* Set this before calling other routines, so that they see
3220 the correct value of x_focus_frame. */
3221 dpyinfo
->x_focus_frame
= frame
;
3223 if (old_focus
&& old_focus
->auto_lower
)
3224 x_lower_frame (old_focus
);
3226 if (dpyinfo
->x_focus_frame
&& dpyinfo
->x_focus_frame
->auto_raise
)
3227 pending_autoraise_frame
= dpyinfo
->x_focus_frame
;
3229 pending_autoraise_frame
= 0;
3232 x_frame_rehighlight (dpyinfo
);
3235 /* Handle FocusIn and FocusOut state changes for FRAME.
3236 If FRAME has focus and there exists more than one frame, puts
3237 a FOCUS_IN_EVENT into *BUFP. */
3240 x_focus_changed (int type
, int state
, struct x_display_info
*dpyinfo
, struct frame
*frame
, struct input_event
*bufp
)
3242 if (type
== FocusIn
)
3244 if (dpyinfo
->x_focus_event_frame
!= frame
)
3246 x_new_focus_frame (dpyinfo
, frame
);
3247 dpyinfo
->x_focus_event_frame
= frame
;
3249 /* Don't stop displaying the initial startup message
3250 for a switch-frame event we don't need. */
3251 if (NILP (Vterminal_frame
)
3252 && CONSP (Vframe_list
)
3253 && !NILP (XCDR (Vframe_list
)))
3255 bufp
->kind
= FOCUS_IN_EVENT
;
3256 XSETFRAME (bufp
->frame_or_window
, frame
);
3260 frame
->output_data
.x
->focus_state
|= state
;
3263 if (FRAME_XIC (frame
))
3264 XSetICFocus (FRAME_XIC (frame
));
3267 else if (type
== FocusOut
)
3269 frame
->output_data
.x
->focus_state
&= ~state
;
3271 if (dpyinfo
->x_focus_event_frame
== frame
)
3273 dpyinfo
->x_focus_event_frame
= 0;
3274 x_new_focus_frame (dpyinfo
, 0);
3278 if (FRAME_XIC (frame
))
3279 XUnsetICFocus (FRAME_XIC (frame
));
3281 if (frame
->pointer_invisible
)
3282 XTtoggle_invisible_pointer (frame
, 0);
3286 /* The focus may have changed. Figure out if it is a real focus change,
3287 by checking both FocusIn/Out and Enter/LeaveNotify events.
3289 Returns FOCUS_IN_EVENT event in *BUFP. */
3292 x_detect_focus_change (struct x_display_info
*dpyinfo
, XEvent
*event
, struct input_event
*bufp
)
3294 struct frame
*frame
;
3296 frame
= x_any_window_to_frame (dpyinfo
, event
->xany
.window
);
3300 switch (event
->type
)
3305 struct frame
*focus_frame
= dpyinfo
->x_focus_event_frame
;
3307 = focus_frame
? focus_frame
->output_data
.x
->focus_state
: 0;
3309 if (event
->xcrossing
.detail
!= NotifyInferior
3310 && event
->xcrossing
.focus
3311 && ! (focus_state
& FOCUS_EXPLICIT
))
3312 x_focus_changed ((event
->type
== EnterNotify
? FocusIn
: FocusOut
),
3314 dpyinfo
, frame
, bufp
);
3320 x_focus_changed (event
->type
,
3321 (event
->xfocus
.detail
== NotifyPointer
?
3322 FOCUS_IMPLICIT
: FOCUS_EXPLICIT
),
3323 dpyinfo
, frame
, bufp
);
3327 if (event
->xclient
.message_type
== dpyinfo
->Xatom_XEMBED
)
3329 enum xembed_message msg
= event
->xclient
.data
.l
[1];
3330 x_focus_changed ((msg
== XEMBED_FOCUS_IN
? FocusIn
: FocusOut
),
3331 FOCUS_EXPLICIT
, dpyinfo
, frame
, bufp
);
3338 /* Handle an event saying the mouse has moved out of an Emacs frame. */
3341 x_mouse_leave (struct x_display_info
*dpyinfo
)
3343 x_new_focus_frame (dpyinfo
, dpyinfo
->x_focus_event_frame
);
3346 /* The focus has changed, or we have redirected a frame's focus to
3347 another frame (this happens when a frame uses a surrogate
3348 mini-buffer frame). Shift the highlight as appropriate.
3350 The FRAME argument doesn't necessarily have anything to do with which
3351 frame is being highlighted or un-highlighted; we only use it to find
3352 the appropriate X display info. */
3355 XTframe_rehighlight (struct frame
*frame
)
3357 x_frame_rehighlight (FRAME_X_DISPLAY_INFO (frame
));
3361 x_frame_rehighlight (struct x_display_info
*dpyinfo
)
3363 struct frame
*old_highlight
= dpyinfo
->x_highlight_frame
;
3365 if (dpyinfo
->x_focus_frame
)
3367 dpyinfo
->x_highlight_frame
3368 = ((FRAMEP (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
)))
3369 ? XFRAME (FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
))
3370 : dpyinfo
->x_focus_frame
);
3371 if (! FRAME_LIVE_P (dpyinfo
->x_highlight_frame
))
3373 FRAME_FOCUS_FRAME (dpyinfo
->x_focus_frame
) = Qnil
;
3374 dpyinfo
->x_highlight_frame
= dpyinfo
->x_focus_frame
;
3378 dpyinfo
->x_highlight_frame
= 0;
3380 if (dpyinfo
->x_highlight_frame
!= old_highlight
)
3383 frame_unhighlight (old_highlight
);
3384 if (dpyinfo
->x_highlight_frame
)
3385 frame_highlight (dpyinfo
->x_highlight_frame
);
3391 /* Keyboard processing - modifier keys, vendor-specific keysyms, etc. */
3393 /* Initialize mode_switch_bit and modifier_meaning. */
3395 x_find_modifier_meanings (struct x_display_info
*dpyinfo
)
3397 int min_code
, max_code
;
3400 XModifierKeymap
*mods
;
3402 dpyinfo
->meta_mod_mask
= 0;
3403 dpyinfo
->shift_lock_mask
= 0;
3404 dpyinfo
->alt_mod_mask
= 0;
3405 dpyinfo
->super_mod_mask
= 0;
3406 dpyinfo
->hyper_mod_mask
= 0;
3408 XDisplayKeycodes (dpyinfo
->display
, &min_code
, &max_code
);
3410 syms
= XGetKeyboardMapping (dpyinfo
->display
,
3411 min_code
, max_code
- min_code
+ 1,
3413 mods
= XGetModifierMapping (dpyinfo
->display
);
3415 /* Scan the modifier table to see which modifier bits the Meta and
3416 Alt keysyms are on. */
3418 int row
, col
; /* The row and column in the modifier table. */
3419 int found_alt_or_meta
;
3421 for (row
= 3; row
< 8; row
++)
3423 found_alt_or_meta
= 0;
3424 for (col
= 0; col
< mods
->max_keypermod
; col
++)
3426 KeyCode code
= mods
->modifiermap
[(row
* mods
->max_keypermod
) + col
];
3428 /* Zeroes are used for filler. Skip them. */
3432 /* Are any of this keycode's keysyms a meta key? */
3436 for (code_col
= 0; code_col
< syms_per_code
; code_col
++)
3438 int sym
= syms
[((code
- min_code
) * syms_per_code
) + code_col
];
3444 found_alt_or_meta
= 1;
3445 dpyinfo
->meta_mod_mask
|= (1 << row
);
3450 found_alt_or_meta
= 1;
3451 dpyinfo
->alt_mod_mask
|= (1 << row
);
3456 if (!found_alt_or_meta
)
3457 dpyinfo
->hyper_mod_mask
|= (1 << row
);
3458 code_col
= syms_per_code
;
3459 col
= mods
->max_keypermod
;
3464 if (!found_alt_or_meta
)
3465 dpyinfo
->super_mod_mask
|= (1 << row
);
3466 code_col
= syms_per_code
;
3467 col
= mods
->max_keypermod
;
3471 /* Ignore this if it's not on the lock modifier. */
3472 if (!found_alt_or_meta
&& ((1 << row
) == LockMask
))
3473 dpyinfo
->shift_lock_mask
= LockMask
;
3474 code_col
= syms_per_code
;
3475 col
= mods
->max_keypermod
;
3484 /* If we couldn't find any meta keys, accept any alt keys as meta keys. */
3485 if (! dpyinfo
->meta_mod_mask
)
3487 dpyinfo
->meta_mod_mask
= dpyinfo
->alt_mod_mask
;
3488 dpyinfo
->alt_mod_mask
= 0;
3491 /* If some keys are both alt and meta,
3492 make them just meta, not alt. */
3493 if (dpyinfo
->alt_mod_mask
& dpyinfo
->meta_mod_mask
)
3495 dpyinfo
->alt_mod_mask
&= ~dpyinfo
->meta_mod_mask
;
3498 XFree ((char *) syms
);
3499 XFreeModifiermap (mods
);
3502 /* Convert between the modifier bits X uses and the modifier bits
3506 x_x_to_emacs_modifiers (struct x_display_info
*dpyinfo
, unsigned int state
)
3508 EMACS_UINT mod_meta
= meta_modifier
;
3509 EMACS_UINT mod_alt
= alt_modifier
;
3510 EMACS_UINT mod_hyper
= hyper_modifier
;
3511 EMACS_UINT mod_super
= super_modifier
;
3514 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3515 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3516 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3517 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3518 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3519 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3520 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3521 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3524 return ( ((state
& (ShiftMask
| dpyinfo
->shift_lock_mask
)) ? shift_modifier
: 0)
3525 | ((state
& ControlMask
) ? ctrl_modifier
: 0)
3526 | ((state
& dpyinfo
->meta_mod_mask
) ? mod_meta
: 0)
3527 | ((state
& dpyinfo
->alt_mod_mask
) ? mod_alt
: 0)
3528 | ((state
& dpyinfo
->super_mod_mask
) ? mod_super
: 0)
3529 | ((state
& dpyinfo
->hyper_mod_mask
) ? mod_hyper
: 0));
3533 x_emacs_to_x_modifiers (struct x_display_info
*dpyinfo
, unsigned int state
)
3535 EMACS_UINT mod_meta
= meta_modifier
;
3536 EMACS_UINT mod_alt
= alt_modifier
;
3537 EMACS_UINT mod_hyper
= hyper_modifier
;
3538 EMACS_UINT mod_super
= super_modifier
;
3542 tem
= Fget (Vx_alt_keysym
, Qmodifier_value
);
3543 if (! EQ (tem
, Qnil
)) mod_alt
= XUINT (tem
);
3544 tem
= Fget (Vx_meta_keysym
, Qmodifier_value
);
3545 if (! EQ (tem
, Qnil
)) mod_meta
= XUINT (tem
);
3546 tem
= Fget (Vx_hyper_keysym
, Qmodifier_value
);
3547 if (! EQ (tem
, Qnil
)) mod_hyper
= XUINT (tem
);
3548 tem
= Fget (Vx_super_keysym
, Qmodifier_value
);
3549 if (! EQ (tem
, Qnil
)) mod_super
= XUINT (tem
);
3552 return ( ((state
& mod_alt
) ? dpyinfo
->alt_mod_mask
: 0)
3553 | ((state
& mod_super
) ? dpyinfo
->super_mod_mask
: 0)
3554 | ((state
& mod_hyper
) ? dpyinfo
->hyper_mod_mask
: 0)
3555 | ((state
& shift_modifier
) ? ShiftMask
: 0)
3556 | ((state
& ctrl_modifier
) ? ControlMask
: 0)
3557 | ((state
& mod_meta
) ? dpyinfo
->meta_mod_mask
: 0));
3560 /* Convert a keysym to its name. */
3563 x_get_keysym_name (int keysym
)
3568 value
= XKeysymToString (keysym
);
3576 /* Mouse clicks and mouse movement. Rah. */
3578 /* Prepare a mouse-event in *RESULT for placement in the input queue.
3580 If the event is a button press, then note that we have grabbed
3584 construct_mouse_click (struct input_event
*result
, XButtonEvent
*event
, struct frame
*f
)
3586 /* Make the event type NO_EVENT; we'll change that when we decide
3588 result
->kind
= MOUSE_CLICK_EVENT
;
3589 result
->code
= event
->button
- Button1
;
3590 result
->timestamp
= event
->time
;
3591 result
->modifiers
= (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
),
3593 | (event
->type
== ButtonRelease
3597 XSETINT (result
->x
, event
->x
);
3598 XSETINT (result
->y
, event
->y
);
3599 XSETFRAME (result
->frame_or_window
, f
);
3605 /* Function to report a mouse movement to the mainstream Emacs code.
3606 The input handler calls this.
3608 We have received a mouse movement event, which is given in *event.
3609 If the mouse is over a different glyph than it was last time, tell
3610 the mainstream emacs code by setting mouse_moved. If not, ask for
3611 another motion event, so we can check again the next time it moves. */
3613 static XMotionEvent last_mouse_motion_event
;
3614 static Lisp_Object last_mouse_motion_frame
;
3617 note_mouse_movement (FRAME_PTR frame
, XMotionEvent
*event
)
3619 last_mouse_movement_time
= event
->time
;
3620 last_mouse_motion_event
= *event
;
3621 XSETFRAME (last_mouse_motion_frame
, frame
);
3623 if (!FRAME_X_OUTPUT (frame
))
3626 if (event
->window
!= FRAME_X_WINDOW (frame
))
3628 frame
->mouse_moved
= 1;
3629 last_mouse_scroll_bar
= Qnil
;
3630 note_mouse_highlight (frame
, -1, -1);
3631 last_mouse_glyph_frame
= 0;
3636 /* Has the mouse moved off the glyph it was on at the last sighting? */
3637 if (frame
!= last_mouse_glyph_frame
3638 || event
->x
< last_mouse_glyph
.x
3639 || event
->x
>= last_mouse_glyph
.x
+ last_mouse_glyph
.width
3640 || event
->y
< last_mouse_glyph
.y
3641 || event
->y
>= last_mouse_glyph
.y
+ last_mouse_glyph
.height
)
3643 frame
->mouse_moved
= 1;
3644 last_mouse_scroll_bar
= Qnil
;
3645 note_mouse_highlight (frame
, event
->x
, event
->y
);
3646 /* Remember which glyph we're now on. */
3647 remember_mouse_glyph (frame
, event
->x
, event
->y
, &last_mouse_glyph
);
3648 last_mouse_glyph_frame
= frame
;
3656 /************************************************************************
3658 ************************************************************************/
3661 redo_mouse_highlight (void)
3663 if (!NILP (last_mouse_motion_frame
)
3664 && FRAME_LIVE_P (XFRAME (last_mouse_motion_frame
)))
3665 note_mouse_highlight (XFRAME (last_mouse_motion_frame
),
3666 last_mouse_motion_event
.x
,
3667 last_mouse_motion_event
.y
);
3672 /* Return the current position of the mouse.
3673 *FP should be a frame which indicates which display to ask about.
3675 If the mouse movement started in a scroll bar, set *FP, *BAR_WINDOW,
3676 and *PART to the frame, window, and scroll bar part that the mouse
3677 is over. Set *X and *Y to the portion and whole of the mouse's
3678 position on the scroll bar.
3680 If the mouse movement started elsewhere, set *FP to the frame the
3681 mouse is on, *BAR_WINDOW to nil, and *X and *Y to the character cell
3684 Set *TIME to the server time-stamp for the time at which the mouse
3685 was at this position.
3687 Don't store anything if we don't have a valid set of values to report.
3689 This clears the mouse_moved flag, so we can wait for the next mouse
3693 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
)
3699 if (! NILP (last_mouse_scroll_bar
) && insist
== 0)
3700 x_scroll_bar_report_motion (fp
, bar_window
, part
, x
, y
, time
);
3706 Window dummy_window
;
3709 Lisp_Object frame
, tail
;
3711 /* Clear the mouse-moved flag for every frame on this display. */
3712 FOR_EACH_FRAME (tail
, frame
)
3713 if (FRAME_X_P (XFRAME (frame
))
3714 && FRAME_X_DISPLAY (XFRAME (frame
)) == FRAME_X_DISPLAY (*fp
))
3715 XFRAME (frame
)->mouse_moved
= 0;
3717 last_mouse_scroll_bar
= Qnil
;
3719 /* Figure out which root window we're on. */
3720 XQueryPointer (FRAME_X_DISPLAY (*fp
),
3721 DefaultRootWindow (FRAME_X_DISPLAY (*fp
)),
3723 /* The root window which contains the pointer. */
3726 /* Trash which we can't trust if the pointer is on
3727 a different screen. */
3730 /* The position on that root window. */
3733 /* More trash we can't trust. */
3736 /* Modifier keys and pointer buttons, about which
3738 (unsigned int *) &dummy
);
3740 /* Now we have a position on the root; find the innermost window
3741 containing the pointer. */
3745 int parent_x
= 0, parent_y
= 0;
3749 /* XTranslateCoordinates can get errors if the window
3750 structure is changing at the same time this function
3751 is running. So at least we must not crash from them. */
3753 x_catch_errors (FRAME_X_DISPLAY (*fp
));
3755 if (FRAME_X_DISPLAY_INFO (*fp
)->grabbed
&& last_mouse_frame
3756 && FRAME_LIVE_P (last_mouse_frame
))
3758 /* If mouse was grabbed on a frame, give coords for that frame
3759 even if the mouse is now outside it. */
3760 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3762 /* From-window, to-window. */
3763 root
, FRAME_X_WINDOW (last_mouse_frame
),
3765 /* From-position, to-position. */
3766 root_x
, root_y
, &win_x
, &win_y
,
3770 f1
= last_mouse_frame
;
3776 XTranslateCoordinates (FRAME_X_DISPLAY (*fp
),
3778 /* From-window, to-window. */
3781 /* From-position, to-position. */
3782 root_x
, root_y
, &win_x
, &win_y
,
3787 if (child
== None
|| child
== win
)
3790 /* We don't wan't to know the innermost window. We
3791 want the edit window. For non-Gtk+ the innermost
3792 window is the edit window. For Gtk+ it might not
3793 be. It might be the tool bar for example. */
3794 if (x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
))
3802 /* Now we know that:
3803 win is the innermost window containing the pointer
3804 (XTC says it has no child containing the pointer),
3805 win_x and win_y are the pointer's position in it
3806 (XTC did this the last time through), and
3807 parent_x and parent_y are the pointer's position in win's parent.
3808 (They are what win_x and win_y were when win was child.
3809 If win is the root window, it has no parent, and
3810 parent_{x,y} are invalid, but that's okay, because we'll
3811 never use them in that case.) */
3814 /* We don't wan't to know the innermost window. We
3815 want the edit window. */
3816 f1
= x_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3818 /* Is win one of our frames? */
3819 f1
= x_any_window_to_frame (FRAME_X_DISPLAY_INFO (*fp
), win
);
3822 #ifdef USE_X_TOOLKIT
3823 /* If we end up with the menu bar window, say it's not
3826 && f1
->output_data
.x
->menubar_widget
3827 && win
== XtWindow (f1
->output_data
.x
->menubar_widget
))
3829 #endif /* USE_X_TOOLKIT */
3832 if (x_had_errors_p (FRAME_X_DISPLAY (*fp
)))
3835 x_uncatch_errors ();
3837 /* If not, is it one of our scroll bars? */
3840 struct scroll_bar
*bar
;
3842 bar
= x_window_to_scroll_bar (FRAME_X_DISPLAY (*fp
), win
);
3846 f1
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
3852 if (f1
== 0 && insist
> 0)
3853 f1
= SELECTED_FRAME ();
3857 /* Ok, we found a frame. Store all the values.
3858 last_mouse_glyph is a rectangle used to reduce the
3859 generation of mouse events. To not miss any motion
3860 events, we must divide the frame into rectangles of the
3861 size of the smallest character that could be displayed
3862 on it, i.e. into the same rectangles that matrices on
3863 the frame are divided into. */
3865 remember_mouse_glyph (f1
, win_x
, win_y
, &last_mouse_glyph
);
3866 last_mouse_glyph_frame
= f1
;
3871 XSETINT (*x
, win_x
);
3872 XSETINT (*y
, win_y
);
3873 *time
= last_mouse_movement_time
;
3883 /***********************************************************************
3885 ***********************************************************************/
3887 /* Scroll bar support. */
3889 /* Given an X window ID and a DISPLAY, find the struct scroll_bar which
3891 This can be called in GC, so we have to make sure to strip off mark
3894 static struct scroll_bar
*
3895 x_window_to_scroll_bar (Display
*display
, Window window_id
)
3899 #if defined (USE_GTK) && defined (USE_TOOLKIT_SCROLL_BARS)
3900 window_id
= (Window
) xg_get_scroll_id_for_window (display
, window_id
);
3901 #endif /* USE_GTK && USE_TOOLKIT_SCROLL_BARS */
3903 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
3905 Lisp_Object frame
, bar
, condemned
;
3907 frame
= XCAR (tail
);
3908 /* All elements of Vframe_list should be frames. */
3909 if (! FRAMEP (frame
))
3912 if (! FRAME_X_P (XFRAME (frame
)))
3915 /* Scan this frame's scroll bar list for a scroll bar with the
3917 condemned
= FRAME_CONDEMNED_SCROLL_BARS (XFRAME (frame
));
3918 for (bar
= FRAME_SCROLL_BARS (XFRAME (frame
));
3919 /* This trick allows us to search both the ordinary and
3920 condemned scroll bar lists with one loop. */
3921 ! NILP (bar
) || (bar
= condemned
,
3924 bar
= XSCROLL_BAR (bar
)->next
)
3925 if (XSCROLL_BAR (bar
)->x_window
== window_id
&&
3926 FRAME_X_DISPLAY (XFRAME (frame
)) == display
)
3927 return XSCROLL_BAR (bar
);
3934 #if defined USE_LUCID
3936 /* Return the Lucid menu bar WINDOW is part of. Return null
3937 if WINDOW is not part of a menu bar. */
3940 x_window_to_menu_bar (Window window
)
3944 for (tail
= Vframe_list
; CONSP (tail
); tail
= XCDR (tail
))
3946 if (FRAME_X_P (XFRAME (XCAR (tail
))))
3948 Lisp_Object frame
= XCAR (tail
);
3949 Widget menu_bar
= XFRAME (frame
)->output_data
.x
->menubar_widget
;
3951 if (menu_bar
&& xlwmenu_window_p (menu_bar
, window
))
3959 #endif /* USE_LUCID */
3962 /************************************************************************
3964 ************************************************************************/
3966 #ifdef USE_TOOLKIT_SCROLL_BARS
3968 static void x_scroll_bar_to_input_event (XEvent
*, struct input_event
*);
3969 static void x_send_scroll_bar_event (Lisp_Object
, int, int, int);
3970 static void x_create_toolkit_scroll_bar (struct frame
*,
3971 struct scroll_bar
*);
3972 static void x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*,
3976 /* Lisp window being scrolled. Set when starting to interact with
3977 a toolkit scroll bar, reset to nil when ending the interaction. */
3979 static Lisp_Object window_being_scrolled
;
3981 /* Last scroll bar part sent in xm_scroll_callback. */
3983 static int last_scroll_bar_part
;
3985 /* Whether this is an Xaw with arrow-scrollbars. This should imply
3986 that movements of 1/20 of the screen size are mapped to up/down. */
3989 /* Id of action hook installed for scroll bars. */
3991 static XtActionHookId action_hook_id
;
3993 static Boolean xaw3d_arrow_scroll
;
3995 /* Whether the drag scrolling maintains the mouse at the top of the
3996 thumb. If not, resizing the thumb needs to be done more carefully
3997 to avoid jerkyness. */
3999 static Boolean xaw3d_pick_top
;
4001 /* Action hook installed via XtAppAddActionHook when toolkit scroll
4002 bars are used.. The hook is responsible for detecting when
4003 the user ends an interaction with the scroll bar, and generates
4004 a `end-scroll' SCROLL_BAR_CLICK_EVENT' event if so. */
4007 xt_action_hook (Widget widget
, XtPointer client_data
, String action_name
,
4008 XEvent
*event
, String
*params
, Cardinal
*num_params
)
4014 scroll_bar_p
= XmIsScrollBar (widget
);
4015 end_action
= "Release";
4016 #else /* !USE_MOTIF i.e. use Xaw */
4017 scroll_bar_p
= XtIsSubclass (widget
, scrollbarWidgetClass
);
4018 end_action
= "EndScroll";
4019 #endif /* USE_MOTIF */
4022 && strcmp (action_name
, end_action
) == 0
4023 && WINDOWP (window_being_scrolled
))
4027 x_send_scroll_bar_event (window_being_scrolled
,
4028 scroll_bar_end_scroll
, 0, 0);
4029 w
= XWINDOW (window_being_scrolled
);
4031 if (!NILP (XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
))
4033 XSCROLL_BAR (w
->vertical_scroll_bar
)->dragging
= Qnil
;
4034 /* The thumb size is incorrect while dragging: fix it. */
4035 set_vertical_scroll_bar (w
);
4037 window_being_scrolled
= Qnil
;
4038 last_scroll_bar_part
= -1;
4040 /* Xt timeouts no longer needed. */
4041 toolkit_scroll_bar_interaction
= 0;
4044 #endif /* not USE_GTK */
4046 /* A vector of windows used for communication between
4047 x_send_scroll_bar_event and x_scroll_bar_to_input_event. */
4049 static struct window
**scroll_bar_windows
;
4050 static int scroll_bar_windows_size
;
4053 /* Send a client message with message type Xatom_Scrollbar for a
4054 scroll action to the frame of WINDOW. PART is a value identifying
4055 the part of the scroll bar that was clicked on. PORTION is the
4056 amount to scroll of a whole of WHOLE. */
4059 x_send_scroll_bar_event (Lisp_Object window
, int part
, int portion
, int whole
)
4062 XClientMessageEvent
*ev
= (XClientMessageEvent
*) &event
;
4063 struct window
*w
= XWINDOW (window
);
4064 struct frame
*f
= XFRAME (w
->frame
);
4069 /* Construct a ClientMessage event to send to the frame. */
4070 ev
->type
= ClientMessage
;
4071 ev
->message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_Scrollbar
;
4072 ev
->display
= FRAME_X_DISPLAY (f
);
4073 ev
->window
= FRAME_X_WINDOW (f
);
4076 /* We can only transfer 32 bits in the XClientMessageEvent, which is
4077 not enough to store a pointer or Lisp_Object on a 64 bit system.
4078 So, store the window in scroll_bar_windows and pass the index
4079 into that array in the event. */
4080 for (i
= 0; i
< scroll_bar_windows_size
; ++i
)
4081 if (scroll_bar_windows
[i
] == NULL
)
4084 if (i
== scroll_bar_windows_size
)
4086 int new_size
= max (10, 2 * scroll_bar_windows_size
);
4087 size_t nbytes
= new_size
* sizeof *scroll_bar_windows
;
4088 size_t old_nbytes
= scroll_bar_windows_size
* sizeof *scroll_bar_windows
;
4090 scroll_bar_windows
= (struct window
**) xrealloc (scroll_bar_windows
,
4092 memset (&scroll_bar_windows
[i
], 0, nbytes
- old_nbytes
);
4093 scroll_bar_windows_size
= new_size
;
4096 scroll_bar_windows
[i
] = w
;
4097 ev
->data
.l
[0] = (long) i
;
4098 ev
->data
.l
[1] = (long) part
;
4099 ev
->data
.l
[2] = (long) 0;
4100 ev
->data
.l
[3] = (long) portion
;
4101 ev
->data
.l
[4] = (long) whole
;
4103 /* Make Xt timeouts work while the scroll bar is active. */
4104 toolkit_scroll_bar_interaction
= 1;
4105 #ifdef USE_X_TOOLKIT
4106 x_activate_timeout_atimer ();
4109 /* Setting the event mask to zero means that the message will
4110 be sent to the client that created the window, and if that
4111 window no longer exists, no event will be sent. */
4112 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), False
, 0, &event
);
4117 /* Transform a scroll bar ClientMessage EVENT to an Emacs input event
4121 x_scroll_bar_to_input_event (XEvent
*event
, struct input_event
*ievent
)
4123 XClientMessageEvent
*ev
= (XClientMessageEvent
*) event
;
4128 w
= scroll_bar_windows
[ev
->data
.l
[0]];
4129 scroll_bar_windows
[ev
->data
.l
[0]] = NULL
;
4131 XSETWINDOW (window
, w
);
4132 f
= XFRAME (w
->frame
);
4134 ievent
->kind
= SCROLL_BAR_CLICK_EVENT
;
4135 ievent
->frame_or_window
= window
;
4138 ievent
->timestamp
= CurrentTime
;
4140 ievent
->timestamp
= XtLastTimestampProcessed (FRAME_X_DISPLAY (f
));
4142 ievent
->part
= ev
->data
.l
[1];
4143 ievent
->code
= ev
->data
.l
[2];
4144 ievent
->x
= make_number ((int) ev
->data
.l
[3]);
4145 ievent
->y
= make_number ((int) ev
->data
.l
[4]);
4146 ievent
->modifiers
= 0;
4152 /* Minimum and maximum values used for Motif scroll bars. */
4154 #define XM_SB_MAX 10000000
4157 /* Scroll bar callback for Motif scroll bars. WIDGET is the scroll
4158 bar widget. CLIENT_DATA is a pointer to the scroll_bar structure.
4159 CALL_DATA is a pointer to a XmScrollBarCallbackStruct. */
4162 xm_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4164 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4165 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4166 int part
= -1, whole
= 0, portion
= 0;
4170 case XmCR_DECREMENT
:
4171 bar
->dragging
= Qnil
;
4172 part
= scroll_bar_up_arrow
;
4175 case XmCR_INCREMENT
:
4176 bar
->dragging
= Qnil
;
4177 part
= scroll_bar_down_arrow
;
4180 case XmCR_PAGE_DECREMENT
:
4181 bar
->dragging
= Qnil
;
4182 part
= scroll_bar_above_handle
;
4185 case XmCR_PAGE_INCREMENT
:
4186 bar
->dragging
= Qnil
;
4187 part
= scroll_bar_below_handle
;
4191 bar
->dragging
= Qnil
;
4192 part
= scroll_bar_to_top
;
4195 case XmCR_TO_BOTTOM
:
4196 bar
->dragging
= Qnil
;
4197 part
= scroll_bar_to_bottom
;
4204 /* Get the slider size. */
4206 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4209 whole
= XM_SB_MAX
- slider_size
;
4210 portion
= min (cs
->value
, whole
);
4211 part
= scroll_bar_handle
;
4212 bar
->dragging
= make_number (cs
->value
);
4216 case XmCR_VALUE_CHANGED
:
4222 window_being_scrolled
= bar
->window
;
4223 last_scroll_bar_part
= part
;
4224 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4228 #elif defined USE_GTK
4230 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4231 bar widget. DATA is a pointer to the scroll_bar structure. */
4234 xg_scroll_callback (GtkRange
*range
,
4235 GtkScrollType scroll
,
4239 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4241 int part
= -1, whole
= 0, portion
= 0;
4242 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4243 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4245 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4246 position
= gtk_adjustment_get_value (adj
);
4251 case GTK_SCROLL_JUMP
:
4252 /* Buttons 1 2 or 3 must be grabbed. */
4253 if (FRAME_X_DISPLAY_INFO (f
)->grabbed
!= 0
4254 && FRAME_X_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4256 part
= scroll_bar_handle
;
4257 whole
= gtk_adjustment_get_upper (adj
) -
4258 gtk_adjustment_get_page_size (adj
);
4259 portion
= min ((int)position
, whole
);
4260 bar
->dragging
= make_number ((int)portion
);
4263 case GTK_SCROLL_STEP_BACKWARD
:
4264 part
= scroll_bar_up_arrow
;
4265 bar
->dragging
= Qnil
;
4267 case GTK_SCROLL_STEP_FORWARD
:
4268 part
= scroll_bar_down_arrow
;
4269 bar
->dragging
= Qnil
;
4271 case GTK_SCROLL_PAGE_BACKWARD
:
4272 part
= scroll_bar_above_handle
;
4273 bar
->dragging
= Qnil
;
4275 case GTK_SCROLL_PAGE_FORWARD
:
4276 part
= scroll_bar_below_handle
;
4277 bar
->dragging
= Qnil
;
4283 window_being_scrolled
= bar
->window
;
4284 last_scroll_bar_part
= part
;
4285 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4291 /* Callback for button release. Sets dragging to Qnil when dragging is done. */
4294 xg_end_scroll_callback (GtkWidget
*widget
,
4295 GdkEventButton
*event
,
4298 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4299 bar
->dragging
= Qnil
;
4300 if (WINDOWP (window_being_scrolled
))
4302 x_send_scroll_bar_event (window_being_scrolled
,
4303 scroll_bar_end_scroll
, 0, 0);
4304 window_being_scrolled
= Qnil
;
4311 #else /* not USE_GTK and not USE_MOTIF */
4313 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4314 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4315 scroll bar struct. CALL_DATA is a pointer to a float saying where
4319 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4321 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4322 float top
= *(float *) call_data
;
4324 int whole
, portion
, height
;
4327 /* Get the size of the thumb, a value between 0 and 1. */
4329 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4333 portion
= shown
< 1 ? top
* whole
: 0;
4335 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4336 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4337 the bottom, so we force the scrolling whenever we see that we're
4338 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4339 we try to ensure that we always stay two pixels away from the
4341 part
= scroll_bar_down_arrow
;
4343 part
= scroll_bar_handle
;
4345 window_being_scrolled
= bar
->window
;
4346 bar
->dragging
= make_number (portion
);
4347 last_scroll_bar_part
= part
;
4348 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4352 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4353 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4354 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4355 the scroll bar. CALL_DATA is an integer specifying the action that
4356 has taken place. Its magnitude is in the range 0..height of the
4357 scroll bar. Negative values mean scroll towards buffer start.
4358 Values < height of scroll bar mean line-wise movement. */
4361 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4363 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4364 /* The position really is stored cast to a pointer. */
4365 int position
= (long) call_data
;
4369 /* Get the height of the scroll bar. */
4371 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4374 if (eabs (position
) >= height
)
4375 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4377 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4378 it maps line-movement to call_data = max(5, height/20). */
4379 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4380 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4382 part
= scroll_bar_move_ratio
;
4384 window_being_scrolled
= bar
->window
;
4385 bar
->dragging
= Qnil
;
4386 last_scroll_bar_part
= part
;
4387 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4390 #endif /* not USE_GTK and not USE_MOTIF */
4392 #define SCROLL_BAR_NAME "verticalScrollBar"
4394 /* Create the widget for scroll bar BAR on frame F. Record the widget
4395 and X window of the scroll bar in BAR. */
4399 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4401 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4404 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4405 G_CALLBACK (xg_end_scroll_callback
),
4410 #else /* not USE_GTK */
4413 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4419 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4420 unsigned long pixel
;
4425 /* Set resources. Create the widget. */
4426 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4427 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4428 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4429 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4430 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4431 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4432 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4434 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4437 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4441 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4444 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4448 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4449 scroll_bar_name
, av
, ac
);
4451 /* Add one callback for everything that can happen. */
4452 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4454 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4456 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4458 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4460 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4462 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4464 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4467 /* Realize the widget. Only after that is the X window created. */
4468 XtRealizeWidget (widget
);
4470 /* Set the cursor to an arrow. I didn't find a resource to do that.
4471 And I'm wondering why it hasn't an arrow cursor by default. */
4472 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4473 f
->output_data
.x
->nontext_cursor
);
4475 #else /* !USE_MOTIF i.e. use Xaw */
4477 /* Set resources. Create the widget. The background of the
4478 Xaw3d scroll bar widget is a little bit light for my taste.
4479 We don't alter it here to let users change it according
4480 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4481 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4482 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4483 /* For smoother scrolling with Xaw3d -sm */
4484 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4486 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4489 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4493 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4496 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4500 /* Top/bottom shadow colors. */
4502 /* Allocate them, if necessary. */
4503 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4505 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4508 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4509 FRAME_X_COLORMAP (f
),
4510 &pixel
, 1.2, 0x8000))
4512 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4515 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4517 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4520 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4521 FRAME_X_COLORMAP (f
),
4522 &pixel
, 0.6, 0x4000))
4524 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4528 #ifdef XtNbeNiceToColormap
4529 /* Tell the toolkit about them. */
4530 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4531 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4532 /* We tried to allocate a color for the top/bottom shadow, and
4533 failed, so tell Xaw3d to use dithering instead. */
4535 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4539 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4540 be more consistent with other emacs 3d colors, and since Xaw3d is
4541 not good at dealing with allocation failure. */
4543 /* This tells Xaw3d to use real colors instead of dithering for
4545 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4548 /* Specify the colors. */
4549 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4552 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4555 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4558 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4564 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4565 f
->output_data
.x
->edit_widget
, av
, ac
);
4569 char *val
= initial
;
4570 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4571 #ifdef XtNarrowScrollbars
4572 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4574 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4575 if (xaw3d_arrow_scroll
|| val
== initial
)
4576 { /* ARROW_SCROLL */
4577 xaw3d_arrow_scroll
= True
;
4578 /* Isn't that just a personal preference ? --Stef */
4579 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4583 /* Define callbacks. */
4584 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4585 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4588 /* Realize the widget. Only after that is the X window created. */
4589 XtRealizeWidget (widget
);
4591 #endif /* !USE_MOTIF */
4593 /* Install an action hook that lets us detect when the user
4594 finishes interacting with a scroll bar. */
4595 if (action_hook_id
== 0)
4596 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4598 /* Remember X window and widget in the scroll bar vector. */
4599 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4600 xwindow
= XtWindow (widget
);
4601 bar
->x_window
= xwindow
;
4605 #endif /* not USE_GTK */
4608 /* Set the thumb size and position of scroll bar BAR. We are currently
4609 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4613 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4615 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4618 #else /* not USE_GTK */
4620 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4623 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4624 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4631 /* We use an estimate of 30 chars per line rather than the real
4632 `portion' value. This has the disadvantage that the thumb size
4633 is not very representative, but it makes our life a lot easier.
4634 Otherwise, we have to constantly adjust the thumb size, which
4635 we can't always do quickly enough: while dragging, the size of
4636 the thumb might prevent the user from dragging the thumb all the
4637 way to the end. but Motif and some versions of Xaw3d don't allow
4638 updating the thumb size while dragging. Also, even if we can update
4639 its size, the update will often happen too late.
4640 If you don't believe it, check out revision 1.650 of xterm.c to see
4641 what hoops we were going through and the still poor behavior we got. */
4642 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4643 /* When the thumb is at the bottom, position == whole.
4644 So we need to increase `whole' to make space for the thumb. */
4651 top
= (float) position
/ whole
;
4652 shown
= (float) portion
/ whole
;
4655 if (NILP (bar
->dragging
))
4659 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4660 is the scroll bar's maximum and MIN is the scroll bar's minimum
4662 size
= shown
* XM_SB_MAX
;
4663 size
= min (size
, XM_SB_MAX
);
4664 size
= max (size
, 1);
4666 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4667 value
= top
* XM_SB_MAX
;
4668 value
= min (value
, XM_SB_MAX
- size
);
4670 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4672 #else /* !USE_MOTIF i.e. use Xaw */
4678 top
= (float) position
/ whole
;
4679 shown
= (float) portion
/ whole
;
4683 float old_top
, old_shown
;
4685 XtVaGetValues (widget
,
4686 XtNtopOfThumb
, &old_top
,
4687 XtNshown
, &old_shown
,
4691 /* Massage the top+shown values. */
4692 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4693 top
= max (0, min (1, top
));
4696 /* Keep two pixels available for moving the thumb down. */
4697 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4699 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4700 check that your system's configuration file contains a define
4701 for `NARROWPROTO'. See s/freebsd.h for an example. */
4702 if (top
!= old_top
|| shown
!= old_shown
)
4704 if (NILP (bar
->dragging
))
4705 XawScrollbarSetThumb (widget
, top
, shown
);
4708 /* Try to make the scrolling a tad smoother. */
4709 if (!xaw3d_pick_top
)
4710 shown
= min (shown
, old_shown
);
4712 XawScrollbarSetThumb (widget
, top
, shown
);
4716 #endif /* !USE_MOTIF */
4720 #endif /* not USE_GTK */
4722 #endif /* USE_TOOLKIT_SCROLL_BARS */
4726 /************************************************************************
4727 Scroll bars, general
4728 ************************************************************************/
4730 /* Create a scroll bar and return the scroll bar vector for it. W is
4731 the Emacs window on which to create the scroll bar. TOP, LEFT,
4732 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4735 static struct scroll_bar
*
4736 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
4738 struct frame
*f
= XFRAME (w
->frame
);
4739 struct scroll_bar
*bar
4740 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4744 #ifdef USE_TOOLKIT_SCROLL_BARS
4745 x_create_toolkit_scroll_bar (f
, bar
);
4746 #else /* not USE_TOOLKIT_SCROLL_BARS */
4748 XSetWindowAttributes a
;
4752 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4753 if (a
.background_pixel
== -1)
4754 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4756 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4757 | ButtonMotionMask
| PointerMotionHintMask
4759 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4761 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4763 /* Clear the area of W that will serve as a scroll bar. This is
4764 for the case that a window has been split horizontally. In
4765 this case, no clear_frame is generated to reduce flickering. */
4766 if (width
> 0 && height
> 0)
4767 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4769 window_box_height (w
), False
);
4771 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4772 /* Position and size of scroll bar. */
4773 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4775 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4777 /* Border width, depth, class, and visual. */
4784 bar
->x_window
= window
;
4786 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4788 XSETWINDOW (bar
->window
, w
);
4792 bar
->height
= height
;
4795 bar
->dragging
= Qnil
;
4796 bar
->fringe_extended_p
= 0;
4798 /* Add bar to its frame's list of scroll bars. */
4799 bar
->next
= FRAME_SCROLL_BARS (f
);
4801 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4802 if (!NILP (bar
->next
))
4803 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4805 /* Map the window/widget. */
4806 #ifdef USE_TOOLKIT_SCROLL_BARS
4809 xg_update_scrollbar_pos (f
,
4812 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4813 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4815 #else /* not USE_GTK */
4816 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4817 XtConfigureWidget (scroll_bar
,
4818 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4820 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4821 max (height
, 1), 0);
4822 XtMapWidget (scroll_bar
);
4823 #endif /* not USE_GTK */
4825 #else /* not USE_TOOLKIT_SCROLL_BARS */
4826 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
4827 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4834 #ifndef USE_TOOLKIT_SCROLL_BARS
4836 /* Draw BAR's handle in the proper position.
4838 If the handle is already drawn from START to END, don't bother
4839 redrawing it, unless REBUILD is non-zero; in that case, always
4840 redraw it. (REBUILD is handy for drawing the handle after expose
4843 Normally, we want to constrain the start and end of the handle to
4844 fit inside its rectangle, but if the user is dragging the scroll
4845 bar handle, we want to let them drag it down all the way, so that
4846 the bar's top is as far down as it goes; otherwise, there's no way
4847 to move to the very end of the buffer. */
4850 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
4852 int dragging
= ! NILP (bar
->dragging
);
4853 Window w
= bar
->x_window
;
4854 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4855 GC gc
= f
->output_data
.x
->normal_gc
;
4857 /* If the display is already accurate, do nothing. */
4859 && start
== bar
->start
4866 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
4867 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
4868 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4870 /* Make sure the values are reasonable, and try to preserve
4871 the distance between start and end. */
4873 int length
= end
- start
;
4877 else if (start
> top_range
)
4879 end
= start
+ length
;
4883 else if (end
> top_range
&& ! dragging
)
4887 /* Store the adjusted setting in the scroll bar. */
4891 /* Clip the end position, just for display. */
4892 if (end
> top_range
)
4895 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4896 below top positions, to make sure the handle is always at least
4897 that many pixels tall. */
4898 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4900 /* Draw the empty space above the handle. Note that we can't clear
4901 zero-height areas; that means "clear to end of window." */
4903 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4904 /* x, y, width, height, and exposures. */
4905 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4906 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4907 inside_width
, start
,
4910 /* Change to proper foreground color if one is specified. */
4911 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4912 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4913 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4915 /* Draw the handle itself. */
4916 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4917 /* x, y, width, height */
4918 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4919 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4920 inside_width
, end
- start
);
4922 /* Restore the foreground color of the GC if we changed it above. */
4923 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4924 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4925 FRAME_FOREGROUND_PIXEL (f
));
4927 /* Draw the empty space below the handle. Note that we can't
4928 clear zero-height areas; that means "clear to end of window." */
4929 if (end
< inside_height
)
4930 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4931 /* x, y, width, height, and exposures. */
4932 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4933 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4934 inside_width
, inside_height
- end
,
4942 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4944 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4948 x_scroll_bar_remove (struct scroll_bar
*bar
)
4950 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4953 #ifdef USE_TOOLKIT_SCROLL_BARS
4955 xg_remove_scroll_bar (f
, bar
->x_window
);
4956 #else /* not USE_GTK */
4957 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4958 #endif /* not USE_GTK */
4960 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
4963 /* Disassociate this scroll bar from its window. */
4964 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4970 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4971 that we are displaying PORTION characters out of a total of WHOLE
4972 characters, starting at POSITION. If WINDOW has no scroll bar,
4976 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
4978 struct frame
*f
= XFRAME (w
->frame
);
4979 struct scroll_bar
*bar
;
4980 int top
, height
, left
, sb_left
, width
, sb_width
;
4981 int window_y
, window_height
;
4982 #ifdef USE_TOOLKIT_SCROLL_BARS
4983 int fringe_extended_p
;
4986 /* Get window dimensions. */
4987 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4989 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4990 height
= window_height
;
4992 /* Compute the left edge of the scroll bar area. */
4993 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4995 /* Compute the width of the scroll bar which might be less than
4996 the width of the area reserved for the scroll bar. */
4997 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
4998 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5002 /* Compute the left edge of the scroll bar. */
5003 #ifdef USE_TOOLKIT_SCROLL_BARS
5004 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5005 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5007 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5009 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5010 sb_left
= left
+ width
- sb_width
;
5015 #ifdef USE_TOOLKIT_SCROLL_BARS
5016 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5017 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5018 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5019 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5020 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5022 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5023 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5024 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5025 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5028 /* Does the scroll bar exist yet? */
5029 if (NILP (w
->vertical_scroll_bar
))
5031 if (width
> 0 && height
> 0)
5034 #ifdef USE_TOOLKIT_SCROLL_BARS
5035 if (fringe_extended_p
)
5036 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5037 sb_left
, top
, sb_width
, height
, False
);
5040 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5041 left
, top
, width
, height
, False
);
5045 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5049 /* It may just need to be moved and resized. */
5050 unsigned int mask
= 0;
5052 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5056 if (sb_left
!= bar
->left
)
5058 if (top
!= bar
->top
)
5060 if (sb_width
!= bar
->width
)
5062 if (height
!= bar
->height
)
5065 #ifdef USE_TOOLKIT_SCROLL_BARS
5067 /* Move/size the scroll bar widget. */
5068 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5070 /* Since toolkit scroll bars are smaller than the space reserved
5071 for them on the frame, we have to clear "under" them. */
5072 if (width
> 0 && height
> 0)
5074 if (fringe_extended_p
)
5075 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5076 sb_left
, top
, sb_width
, height
, False
);
5078 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5079 left
, top
, width
, height
, False
);
5082 xg_update_scrollbar_pos (f
,
5085 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5086 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5088 #else /* not USE_GTK */
5089 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5090 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5092 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5093 max (height
, 1), 0);
5094 #endif /* not USE_GTK */
5096 #else /* not USE_TOOLKIT_SCROLL_BARS */
5098 /* Clear areas not covered by the scroll bar because of
5099 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5100 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5102 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5103 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5105 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5106 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5107 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5111 /* Clear areas not covered by the scroll bar because it's not as
5112 wide as the area reserved for it. This makes sure a
5113 previous mode line display is cleared after C-x 2 C-x 1, for
5116 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5117 int rest
= area_width
- sb_width
;
5118 if (rest
> 0 && height
> 0)
5120 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5121 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5122 left
+ area_width
- rest
, top
,
5123 rest
, height
, False
);
5125 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5126 left
, top
, rest
, height
, False
);
5130 /* Move/size the scroll bar window. */
5135 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5137 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5139 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5143 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5145 /* Remember new settings. */
5146 bar
->left
= sb_left
;
5148 bar
->width
= sb_width
;
5149 bar
->height
= height
;
5154 #ifdef USE_TOOLKIT_SCROLL_BARS
5155 bar
->fringe_extended_p
= fringe_extended_p
;
5157 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5158 #else /* not USE_TOOLKIT_SCROLL_BARS */
5159 /* Set the scroll bar's current state, unless we're currently being
5161 if (NILP (bar
->dragging
))
5163 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5166 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5169 int start
= ((double) position
* top_range
) / whole
;
5170 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5171 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5174 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5176 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5180 /* The following three hooks are used when we're doing a thorough
5181 redisplay of the frame. We don't explicitly know which scroll bars
5182 are going to be deleted, because keeping track of when windows go
5183 away is a real pain - "Can you say set-window-configuration, boys
5184 and girls?" Instead, we just assert at the beginning of redisplay
5185 that *all* scroll bars are to be removed, and then save a scroll bar
5186 from the fiery pit when we actually redisplay its window. */
5188 /* Arrange for all scroll bars on FRAME to be removed at the next call
5189 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5190 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5193 XTcondemn_scroll_bars (FRAME_PTR frame
)
5195 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5196 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5199 bar
= FRAME_SCROLL_BARS (frame
);
5200 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5201 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5202 XSCROLL_BAR (bar
)->prev
= Qnil
;
5203 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5204 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5205 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5210 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5211 Note that WINDOW isn't necessarily condemned at all. */
5214 XTredeem_scroll_bar (struct window
*window
)
5216 struct scroll_bar
*bar
;
5219 /* We can't redeem this window's scroll bar if it doesn't have one. */
5220 if (NILP (window
->vertical_scroll_bar
))
5223 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5225 /* Unlink it from the condemned list. */
5226 f
= XFRAME (WINDOW_FRAME (window
));
5227 if (NILP (bar
->prev
))
5229 /* If the prev pointer is nil, it must be the first in one of
5231 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5232 /* It's not condemned. Everything's fine. */
5234 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5235 window
->vertical_scroll_bar
))
5236 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5238 /* If its prev pointer is nil, it must be at the front of
5239 one or the other! */
5243 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5245 if (! NILP (bar
->next
))
5246 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5248 bar
->next
= FRAME_SCROLL_BARS (f
);
5250 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5251 if (! NILP (bar
->next
))
5252 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5255 /* Remove all scroll bars on FRAME that haven't been saved since the
5256 last call to `*condemn_scroll_bars_hook'. */
5259 XTjudge_scroll_bars (FRAME_PTR f
)
5261 Lisp_Object bar
, next
;
5263 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5265 /* Clear out the condemned list now so we won't try to process any
5266 more events on the hapless scroll bars. */
5267 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5269 for (; ! NILP (bar
); bar
= next
)
5271 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5273 x_scroll_bar_remove (b
);
5276 b
->next
= b
->prev
= Qnil
;
5279 /* Now there should be no references to the condemned scroll bars,
5280 and they should get garbage-collected. */
5284 #ifndef USE_TOOLKIT_SCROLL_BARS
5285 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5286 is a no-op when using toolkit scroll bars.
5288 This may be called from a signal handler, so we have to ignore GC
5292 x_scroll_bar_expose (struct scroll_bar
*bar
, XEvent
*event
)
5294 Window w
= bar
->x_window
;
5295 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5296 GC gc
= f
->output_data
.x
->normal_gc
;
5297 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5301 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5303 /* Switch to scroll bar foreground color. */
5304 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5305 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5306 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5308 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5309 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5311 /* x, y, width, height */
5313 bar
->width
- 1 - width_trim
- width_trim
,
5316 /* Restore the foreground color of the GC if we changed it above. */
5317 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5318 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5319 FRAME_FOREGROUND_PIXEL (f
));
5324 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5326 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5327 is set to something other than NO_EVENT, it is enqueued.
5329 This may be called from a signal handler, so we have to ignore GC
5334 x_scroll_bar_handle_click (struct scroll_bar
*bar
, XEvent
*event
, struct input_event
*emacs_event
)
5336 if (! WINDOWP (bar
->window
))
5339 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5340 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5341 emacs_event
->modifiers
5342 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5343 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5344 event
->xbutton
.state
)
5345 | (event
->type
== ButtonRelease
5348 emacs_event
->frame_or_window
= bar
->window
;
5349 emacs_event
->arg
= Qnil
;
5350 emacs_event
->timestamp
= event
->xbutton
.time
;
5353 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5354 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5357 if (y
> top_range
) y
= top_range
;
5360 emacs_event
->part
= scroll_bar_above_handle
;
5361 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5362 emacs_event
->part
= scroll_bar_handle
;
5364 emacs_event
->part
= scroll_bar_below_handle
;
5366 #ifndef USE_TOOLKIT_SCROLL_BARS
5367 /* If the user has released the handle, set it to its final position. */
5368 if (event
->type
== ButtonRelease
5369 && ! NILP (bar
->dragging
))
5371 int new_start
= y
- XINT (bar
->dragging
);
5372 int new_end
= new_start
+ bar
->end
- bar
->start
;
5374 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5375 bar
->dragging
= Qnil
;
5379 XSETINT (emacs_event
->x
, y
);
5380 XSETINT (emacs_event
->y
, top_range
);
5384 #ifndef USE_TOOLKIT_SCROLL_BARS
5386 /* Handle some mouse motion while someone is dragging the scroll bar.
5388 This may be called from a signal handler, so we have to ignore GC
5392 x_scroll_bar_note_movement (struct scroll_bar
*bar
, XEvent
*event
)
5394 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5396 last_mouse_movement_time
= event
->xmotion
.time
;
5399 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5401 /* If we're dragging the bar, display it. */
5402 if (! NILP (bar
->dragging
))
5404 /* Where should the handle be now? */
5405 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5407 if (new_start
!= bar
->start
)
5409 int new_end
= new_start
+ bar
->end
- bar
->start
;
5411 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5416 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5418 /* Return information to the user about the current position of the mouse
5419 on the scroll bar. */
5422 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
)
5424 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5425 Window w
= bar
->x_window
;
5426 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5428 Window dummy_window
;
5430 unsigned int dummy_mask
;
5434 /* Get the mouse's position relative to the scroll bar window, and
5436 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5438 /* Root, child, root x and root y. */
5439 &dummy_window
, &dummy_window
,
5440 &dummy_coord
, &dummy_coord
,
5442 /* Position relative to scroll bar. */
5445 /* Mouse buttons and modifier keys. */
5451 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5453 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5455 if (! NILP (bar
->dragging
))
5456 win_y
-= XINT (bar
->dragging
);
5460 if (win_y
> top_range
)
5464 *bar_window
= bar
->window
;
5466 if (! NILP (bar
->dragging
))
5467 *part
= scroll_bar_handle
;
5468 else if (win_y
< bar
->start
)
5469 *part
= scroll_bar_above_handle
;
5470 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5471 *part
= scroll_bar_handle
;
5473 *part
= scroll_bar_below_handle
;
5475 XSETINT (*x
, win_y
);
5476 XSETINT (*y
, top_range
);
5479 last_mouse_scroll_bar
= Qnil
;
5482 *time
= last_mouse_movement_time
;
5488 /* The screen has been cleared so we may have changed foreground or
5489 background colors, and the scroll bars may need to be redrawn.
5490 Clear out the scroll bars, and ask for expose events, so we can
5494 x_scroll_bar_clear (FRAME_PTR f
)
5496 #ifndef USE_TOOLKIT_SCROLL_BARS
5499 /* We can have scroll bars even if this is 0,
5500 if we just turned off scroll bar mode.
5501 But in that case we should not clear them. */
5502 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5503 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5504 bar
= XSCROLL_BAR (bar
)->next
)
5505 XClearArea (FRAME_X_DISPLAY (f
),
5506 XSCROLL_BAR (bar
)->x_window
,
5508 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5512 /* The main X event-reading loop - XTread_socket. */
5514 /* This holds the state XLookupString needs to implement dead keys
5515 and other tricks known as "compose processing". _X Window System_
5516 says that a portable program can't use this, but Stephen Gildea assures
5517 me that letting the compiler initialize it to zeros will work okay.
5519 This must be defined outside of XTread_socket, for the same reasons
5520 given for enter_timestamp, above. */
5522 static XComposeStatus compose_status
;
5524 /* Record the last 100 characters stored
5525 to help debug the loss-of-chars-during-GC problem. */
5527 static int temp_index
;
5528 static short temp_buffer
[100];
5530 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5531 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5533 temp_buffer[temp_index++] = (keysym)
5535 /* Set this to nonzero to fake an "X I/O error"
5536 on a particular display. */
5538 struct x_display_info
*XTread_socket_fake_io_error
;
5540 /* When we find no input here, we occasionally do a no-op command
5541 to verify that the X server is still running and we can still talk with it.
5542 We try all the open displays, one by one.
5543 This variable is used for cycling thru the displays. */
5545 static struct x_display_info
*next_noop_dpyinfo
;
5547 #define SET_SAVED_BUTTON_EVENT \
5550 if (f->output_data.x->saved_menu_event == 0) \
5551 f->output_data.x->saved_menu_event \
5552 = (XEvent *) xmalloc (sizeof (XEvent)); \
5553 *f->output_data.x->saved_menu_event = event; \
5554 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5555 XSETFRAME (inev.ie.frame_or_window, f); \
5566 /* Filter events for the current X input method.
5567 DPYINFO is the display this event is for.
5568 EVENT is the X event to filter.
5570 Returns non-zero if the event was filtered, caller shall not process
5572 Returns zero if event is wasn't filtered. */
5576 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5578 /* XFilterEvent returns non-zero if the input method has
5579 consumed the event. We pass the frame's X window to
5580 XFilterEvent because that's the one for which the IC
5583 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5584 event
->xclient
.window
);
5586 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5591 static int current_count
;
5592 static int current_finish
;
5593 static struct input_event
*current_hold_quit
;
5595 /* This is the filter function invoked by the GTK event loop.
5596 It is invoked before the XEvent is translated to a GdkEvent,
5597 so we have a chance to act on the event before GTK. */
5598 static GdkFilterReturn
5599 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5601 XEvent
*xev
= (XEvent
*) gxev
;
5604 if (current_count
>= 0)
5606 struct x_display_info
*dpyinfo
;
5608 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5611 /* Filter events for the current X input method.
5612 GTK calls XFilterEvent but not for key press and release,
5613 so we do it here. */
5614 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5616 && x_filter_event (dpyinfo
, xev
))
5619 return GDK_FILTER_REMOVE
;
5624 current_finish
= X_EVENT_NORMAL
;
5627 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5631 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5635 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5636 return GDK_FILTER_REMOVE
;
5638 return GDK_FILTER_CONTINUE
;
5640 #endif /* USE_GTK */
5643 /* Handles the XEvent EVENT on display DPYINFO.
5645 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5646 *FINISH is zero if caller should continue reading events.
5647 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5649 We return the number of characters stored into the buffer. */
5652 handle_one_xevent (struct x_display_info
*dpyinfo
, XEvent
*eventp
, int *finish
, struct input_event
*hold_quit
)
5655 struct input_event ie
;
5656 struct selection_input_event sie
;
5661 struct frame
*f
= NULL
;
5662 struct coding_system coding
;
5663 XEvent event
= *eventp
;
5665 *finish
= X_EVENT_NORMAL
;
5667 EVENT_INIT (inev
.ie
);
5668 inev
.ie
.kind
= NO_EVENT
;
5671 if (pending_event_wait
.eventtype
== event
.type
)
5672 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5678 if (event
.xclient
.message_type
5679 == dpyinfo
->Xatom_wm_protocols
5680 && event
.xclient
.format
== 32)
5682 if (event
.xclient
.data
.l
[0]
5683 == dpyinfo
->Xatom_wm_take_focus
)
5685 /* Use x_any_window_to_frame because this
5686 could be the shell widget window
5687 if the frame has no title bar. */
5688 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5690 /* Not quite sure this is needed -pd */
5691 if (f
&& FRAME_XIC (f
))
5692 XSetICFocus (FRAME_XIC (f
));
5694 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5695 instructs the WM to set the input focus automatically for
5696 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5697 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5698 it has set the focus. So, XSetInputFocus below is not
5701 The call to XSetInputFocus below has also caused trouble. In
5702 cases where the XSetInputFocus done by the WM and the one
5703 below are temporally close (on a fast machine), the call
5704 below can generate additional FocusIn events which confuse
5707 /* Since we set WM_TAKE_FOCUS, we must call
5708 XSetInputFocus explicitly. But not if f is null,
5709 since that might be an event for a deleted frame. */
5712 Display
*d
= event
.xclient
.display
;
5713 /* Catch and ignore errors, in case window has been
5714 iconified by a window manager such as GWM. */
5716 XSetInputFocus (d
, event
.xclient
.window
,
5717 /* The ICCCM says this is
5718 the only valid choice. */
5720 event
.xclient
.data
.l
[1]);
5721 /* This is needed to detect the error
5722 if there is an error. */
5724 x_uncatch_errors ();
5726 /* Not certain about handling scroll bars here */
5731 if (event
.xclient
.data
.l
[0]
5732 == dpyinfo
->Xatom_wm_save_yourself
)
5734 /* Save state modify the WM_COMMAND property to
5735 something which can reinstate us. This notifies
5736 the session manager, who's looking for such a
5737 PropertyNotify. Can restart processing when
5738 a keyboard or mouse event arrives. */
5739 /* If we have a session manager, don't set this.
5740 KDE will then start two Emacsen, one for the
5741 session manager and one for this. */
5743 if (! x_session_have_connection ())
5746 f
= x_top_window_to_frame (dpyinfo
,
5747 event
.xclient
.window
);
5748 /* This is just so we only give real data once
5749 for a single Emacs process. */
5750 if (f
== SELECTED_FRAME ())
5751 XSetCommand (FRAME_X_DISPLAY (f
),
5752 event
.xclient
.window
,
5753 initial_argv
, initial_argc
);
5755 XSetCommand (FRAME_X_DISPLAY (f
),
5756 event
.xclient
.window
,
5762 if (event
.xclient
.data
.l
[0]
5763 == dpyinfo
->Xatom_wm_delete_window
)
5765 f
= x_any_window_to_frame (dpyinfo
,
5766 event
.xclient
.window
);
5768 goto OTHER
; /* May be a dialog that is to be removed */
5770 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5771 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5778 if (event
.xclient
.message_type
5779 == dpyinfo
->Xatom_wm_configure_denied
)
5784 if (event
.xclient
.message_type
5785 == dpyinfo
->Xatom_wm_window_moved
)
5788 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5790 new_x
= event
.xclient
.data
.s
[0];
5791 new_y
= event
.xclient
.data
.s
[1];
5795 f
->left_pos
= new_x
;
5802 if (event
.xclient
.message_type
5803 == dpyinfo
->Xatom_editres
)
5805 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5807 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5811 #endif /* HACK_EDITRES */
5813 if ((event
.xclient
.message_type
5814 == dpyinfo
->Xatom_DONE
)
5815 || (event
.xclient
.message_type
5816 == dpyinfo
->Xatom_PAGE
))
5818 /* Ghostview job completed. Kill it. We could
5819 reply with "Next" if we received "Page", but we
5820 currently never do because we are interested in
5821 images, only, which should have 1 page. */
5822 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5823 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5826 x_kill_gs_process (pixmap
, f
);
5827 expose_frame (f
, 0, 0, 0, 0);
5831 #ifdef USE_TOOLKIT_SCROLL_BARS
5832 /* Scroll bar callbacks send a ClientMessage from which
5833 we construct an input_event. */
5834 if (event
.xclient
.message_type
5835 == dpyinfo
->Xatom_Scrollbar
)
5837 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
5838 *finish
= X_EVENT_GOTO_OUT
;
5841 #endif /* USE_TOOLKIT_SCROLL_BARS */
5843 /* XEmbed messages from the embedder (if any). */
5844 if (event
.xclient
.message_type
5845 == dpyinfo
->Xatom_XEMBED
)
5847 enum xembed_message msg
= event
.xclient
.data
.l
[1];
5848 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
5849 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
5851 *finish
= X_EVENT_GOTO_OUT
;
5855 xft_settings_event (dpyinfo
, &event
);
5857 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5860 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
5861 *finish
= X_EVENT_DROP
;
5865 case SelectionNotify
:
5866 last_user_time
= event
.xselection
.time
;
5867 #ifdef USE_X_TOOLKIT
5868 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5870 #endif /* not USE_X_TOOLKIT */
5871 x_handle_selection_notify (&event
.xselection
);
5874 case SelectionClear
: /* Someone has grabbed ownership. */
5875 last_user_time
= event
.xselectionclear
.time
;
5876 #ifdef USE_X_TOOLKIT
5877 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5879 #endif /* USE_X_TOOLKIT */
5881 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5883 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
5884 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5885 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5886 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5887 inev
.ie
.frame_or_window
= Qnil
;
5891 case SelectionRequest
: /* Someone wants our selection. */
5892 last_user_time
= event
.xselectionrequest
.time
;
5893 #ifdef USE_X_TOOLKIT
5894 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5896 #endif /* USE_X_TOOLKIT */
5898 XSelectionRequestEvent
*eventp
5899 = (XSelectionRequestEvent
*) &event
;
5901 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
5902 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5903 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
5904 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5905 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
5906 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
5907 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5908 inev
.ie
.frame_or_window
= Qnil
;
5912 case PropertyNotify
:
5913 last_user_time
= event
.xproperty
.time
;
5914 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
5915 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
5916 x_handle_net_wm_state (f
, &event
.xproperty
);
5918 x_handle_property_notify (&event
.xproperty
);
5919 xft_settings_event (dpyinfo
, &event
);
5922 case ReparentNotify
:
5923 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
5927 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
5928 x_real_positions (f
, &x
, &y
);
5932 /* Perhaps reparented due to a WM restart. Reset this. */
5933 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
5934 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
5939 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
5943 /* This seems to be needed for GTK 2.6. */
5944 x_clear_area (event
.xexpose
.display
,
5945 event
.xexpose
.window
,
5946 event
.xexpose
.x
, event
.xexpose
.y
,
5947 event
.xexpose
.width
, event
.xexpose
.height
,
5950 if (f
->async_visible
== 0)
5952 f
->async_visible
= 1;
5953 f
->async_iconified
= 0;
5954 f
->output_data
.x
->has_been_visible
= 1;
5955 SET_FRAME_GARBAGED (f
);
5959 event
.xexpose
.x
, event
.xexpose
.y
,
5960 event
.xexpose
.width
, event
.xexpose
.height
);
5964 #ifndef USE_TOOLKIT_SCROLL_BARS
5965 struct scroll_bar
*bar
;
5967 #if defined USE_LUCID
5968 /* Submenus of the Lucid menu bar aren't widgets
5969 themselves, so there's no way to dispatch events
5970 to them. Recognize this case separately. */
5973 = x_window_to_menu_bar (event
.xexpose
.window
);
5975 xlwmenu_redisplay (widget
);
5977 #endif /* USE_LUCID */
5979 #ifdef USE_TOOLKIT_SCROLL_BARS
5980 /* Dispatch event to the widget. */
5982 #else /* not USE_TOOLKIT_SCROLL_BARS */
5983 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
5984 event
.xexpose
.window
);
5987 x_scroll_bar_expose (bar
, &event
);
5988 #ifdef USE_X_TOOLKIT
5991 #endif /* USE_X_TOOLKIT */
5992 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5996 case GraphicsExpose
: /* This occurs when an XCopyArea's
5997 source area was obscured or not
5999 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6003 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6004 event
.xgraphicsexpose
.width
,
6005 event
.xgraphicsexpose
.height
);
6007 #ifdef USE_X_TOOLKIT
6010 #endif /* USE_X_TOOLKIT */
6013 case NoExpose
: /* This occurs when an XCopyArea's
6014 source area was completely
6019 /* Redo the mouse-highlight after the tooltip has gone. */
6020 if (event
.xmap
.window
== tip_window
)
6023 redo_mouse_highlight ();
6026 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6027 if (f
) /* F may no longer exist if
6028 the frame was deleted. */
6030 /* While a frame is unmapped, display generation is
6031 disabled; you don't want to spend time updating a
6032 display that won't ever be seen. */
6033 f
->async_visible
= 0;
6034 /* We can't distinguish, from the event, whether the window
6035 has become iconified or invisible. So assume, if it
6036 was previously visible, than now it is iconified.
6037 But x_make_frame_invisible clears both
6038 the visible flag and the iconified flag;
6039 and that way, we know the window is not iconified now. */
6040 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6042 f
->async_iconified
= 1;
6044 inev
.ie
.kind
= ICONIFY_EVENT
;
6045 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6051 if (event
.xmap
.window
== tip_window
)
6052 /* The tooltip has been drawn already. Avoid
6053 the SET_FRAME_GARBAGED below. */
6056 /* We use x_top_window_to_frame because map events can
6057 come for sub-windows and they don't mean that the
6058 frame is visible. */
6059 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6062 /* wait_reading_process_output will notice this and update
6063 the frame's display structures.
6064 If we where iconified, we should not set garbaged,
6065 because that stops redrawing on Expose events. This looks
6066 bad if we are called from a recursive event loop
6067 (x_dispatch_event), for example when a dialog is up. */
6068 if (! f
->async_iconified
)
6069 SET_FRAME_GARBAGED (f
);
6071 /* Check if fullscreen was specified before we where mapped the
6072 first time, i.e. from the command line. */
6073 if (!f
->output_data
.x
->has_been_visible
)
6074 x_check_fullscreen (f
);
6076 f
->async_visible
= 1;
6077 f
->async_iconified
= 0;
6078 f
->output_data
.x
->has_been_visible
= 1;
6082 inev
.ie
.kind
= DEICONIFY_EVENT
;
6083 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6085 else if (! NILP (Vframe_list
)
6086 && ! NILP (XCDR (Vframe_list
)))
6087 /* Force a redisplay sooner or later
6088 to update the frame titles
6089 in case this is the second frame. */
6090 record_asynch_buffer_change ();
6093 xg_frame_resized (f
, -1, -1);
6100 last_user_time
= event
.xkey
.time
;
6101 ignore_next_mouse_click_timeout
= 0;
6103 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6104 /* Dispatch KeyPress events when in menu. */
6105 if (popup_activated ())
6109 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6111 /* If mouse-highlight is an integer, input clears out
6112 mouse highlighting. */
6113 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6115 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6117 clear_mouse_face (dpyinfo
);
6118 dpyinfo
->mouse_face_hidden
= 1;
6121 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6124 /* Scroll bars consume key events, but we want
6125 the keys to go to the scroll bar's frame. */
6126 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6128 if (widget
&& XmIsScrollBar (widget
))
6130 widget
= XtParent (widget
);
6131 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6134 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6138 KeySym keysym
, orig_keysym
;
6139 /* al%imercury@uunet.uu.net says that making this 81
6140 instead of 80 fixed a bug whereby meta chars made
6143 It seems that some version of XmbLookupString has
6144 a bug of not returning XBufferOverflow in
6145 status_return even if the input is too long to
6146 fit in 81 bytes. So, we must prepare sufficient
6147 bytes for copy_buffer. 513 bytes (256 chars for
6148 two-byte character set) seems to be a fairly good
6149 approximation. -- 2000.8.10 handa@etl.go.jp */
6150 unsigned char copy_buffer
[513];
6151 unsigned char *copy_bufptr
= copy_buffer
;
6152 int copy_bufsiz
= sizeof (copy_buffer
);
6154 Lisp_Object coding_system
= Qlatin_1
;
6158 /* Don't pass keys to GTK. A Tab will shift focus to the
6159 tool bar in GTK 2.4. Keys will still go to menus and
6160 dialogs because in that case popup_activated is TRUE
6162 *finish
= X_EVENT_DROP
;
6166 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6167 extra_keyboard_modifiers
);
6168 modifiers
= event
.xkey
.state
;
6170 /* This will have to go some day... */
6172 /* make_lispy_event turns chars into control chars.
6173 Don't do it here because XLookupString is too eager. */
6174 event
.xkey
.state
&= ~ControlMask
;
6175 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6176 | dpyinfo
->super_mod_mask
6177 | dpyinfo
->hyper_mod_mask
6178 | dpyinfo
->alt_mod_mask
);
6180 /* In case Meta is ComposeCharacter,
6181 clear its status. According to Markus Ehrnsperger
6182 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6183 this enables ComposeCharacter to work whether or
6184 not it is combined with Meta. */
6185 if (modifiers
& dpyinfo
->meta_mod_mask
)
6186 memset (&compose_status
, 0, sizeof (compose_status
));
6191 Status status_return
;
6193 coding_system
= Vlocale_coding_system
;
6194 nbytes
= XmbLookupString (FRAME_XIC (f
),
6195 &event
.xkey
, copy_bufptr
,
6196 copy_bufsiz
, &keysym
,
6198 if (status_return
== XBufferOverflow
)
6200 copy_bufsiz
= nbytes
+ 1;
6201 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6202 nbytes
= XmbLookupString (FRAME_XIC (f
),
6203 &event
.xkey
, copy_bufptr
,
6204 copy_bufsiz
, &keysym
,
6207 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6208 if (status_return
== XLookupNone
)
6210 else if (status_return
== XLookupChars
)
6215 else if (status_return
!= XLookupKeySym
6216 && status_return
!= XLookupBoth
)
6220 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6221 copy_bufsiz
, &keysym
,
6224 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6225 copy_bufsiz
, &keysym
,
6229 /* If not using XIM/XIC, and a compose sequence is in progress,
6230 we break here. Otherwise, chars_matched is always 0. */
6231 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6234 memset (&compose_status
, 0, sizeof (compose_status
));
6235 orig_keysym
= keysym
;
6237 /* Common for all keysym input events. */
6238 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6240 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6241 inev
.ie
.timestamp
= event
.xkey
.time
;
6243 /* First deal with keysyms which have defined
6244 translations to characters. */
6245 if (keysym
>= 32 && keysym
< 128)
6246 /* Avoid explicitly decoding each ASCII character. */
6248 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6249 inev
.ie
.code
= keysym
;
6253 /* Keysyms directly mapped to Unicode characters. */
6254 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6256 if (keysym
< 0x01000080)
6257 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6259 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6260 inev
.ie
.code
= keysym
& 0xFFFFFF;
6264 /* Now non-ASCII. */
6265 if (HASH_TABLE_P (Vx_keysym_table
)
6266 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6270 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6271 ? ASCII_KEYSTROKE_EVENT
6272 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6273 inev
.ie
.code
= XFASTINT (c
);
6277 /* Random non-modifier sorts of keysyms. */
6278 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6279 || keysym
== XK_Delete
6280 #ifdef XK_ISO_Left_Tab
6281 || (keysym
>= XK_ISO_Left_Tab
6282 && keysym
<= XK_ISO_Enter
)
6284 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6285 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6287 /* This recognizes the "extended function
6288 keys". It seems there's no cleaner way.
6289 Test IsModifierKey to avoid handling
6290 mode_switch incorrectly. */
6291 || ((unsigned) (keysym
) >= XK_Select
6292 && (unsigned)(keysym
) < XK_KP_Space
)
6294 #ifdef XK_dead_circumflex
6295 || orig_keysym
== XK_dead_circumflex
6297 #ifdef XK_dead_grave
6298 || orig_keysym
== XK_dead_grave
6300 #ifdef XK_dead_tilde
6301 || orig_keysym
== XK_dead_tilde
6303 #ifdef XK_dead_diaeresis
6304 || orig_keysym
== XK_dead_diaeresis
6306 #ifdef XK_dead_macron
6307 || orig_keysym
== XK_dead_macron
6309 #ifdef XK_dead_degree
6310 || orig_keysym
== XK_dead_degree
6312 #ifdef XK_dead_acute
6313 || orig_keysym
== XK_dead_acute
6315 #ifdef XK_dead_cedilla
6316 || orig_keysym
== XK_dead_cedilla
6318 #ifdef XK_dead_breve
6319 || orig_keysym
== XK_dead_breve
6321 #ifdef XK_dead_ogonek
6322 || orig_keysym
== XK_dead_ogonek
6324 #ifdef XK_dead_caron
6325 || orig_keysym
== XK_dead_caron
6327 #ifdef XK_dead_doubleacute
6328 || orig_keysym
== XK_dead_doubleacute
6330 #ifdef XK_dead_abovedot
6331 || orig_keysym
== XK_dead_abovedot
6333 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6334 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6335 /* Any "vendor-specific" key is ok. */
6336 || (orig_keysym
& (1 << 28))
6337 || (keysym
!= NoSymbol
&& nbytes
== 0))
6338 && ! (IsModifierKey (orig_keysym
)
6339 /* The symbols from XK_ISO_Lock
6340 to XK_ISO_Last_Group_Lock
6341 don't have real modifiers but
6342 should be treated similarly to
6343 Mode_switch by Emacs. */
6344 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6345 || ((unsigned)(orig_keysym
)
6347 && (unsigned)(orig_keysym
)
6348 <= XK_ISO_Last_Group_Lock
)
6352 STORE_KEYSYM_FOR_DEBUG (keysym
);
6353 /* make_lispy_event will convert this to a symbolic
6355 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6356 inev
.ie
.code
= keysym
;
6360 { /* Raw bytes, not keysym. */
6365 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6367 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6369 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6372 if (nchars
< nbytes
)
6374 /* Decode the input data. */
6378 /* The input should be decoded with `coding_system'
6379 which depends on which X*LookupString function
6380 we used just above and the locale. */
6381 setup_coding_system (coding_system
, &coding
);
6382 coding
.src_multibyte
= 0;
6383 coding
.dst_multibyte
= 1;
6384 /* The input is converted to events, thus we can't
6385 handle composition. Anyway, there's no XIM that
6386 gives us composition information. */
6387 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6389 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6390 coding
.destination
= alloca (require
);
6391 coding
.dst_bytes
= require
;
6392 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6393 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6394 nbytes
= coding
.produced
;
6395 nchars
= coding
.produced_char
;
6396 copy_bufptr
= coding
.destination
;
6399 /* Convert the input data to a sequence of
6400 character events. */
6401 for (i
= 0; i
< nbytes
; i
+= len
)
6403 if (nchars
== nbytes
)
6404 c
= copy_bufptr
[i
], len
= 1;
6406 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6407 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6408 ? ASCII_KEYSTROKE_EVENT
6409 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6411 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6416 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6418 if (keysym
== NoSymbol
)
6424 /* Don't dispatch this event since XtDispatchEvent calls
6425 XFilterEvent, and two calls in a row may freeze the
6433 last_user_time
= event
.xkey
.time
;
6435 /* Don't dispatch this event since XtDispatchEvent calls
6436 XFilterEvent, and two calls in a row may freeze the
6444 last_user_time
= event
.xcrossing
.time
;
6445 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6447 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6449 if (f
&& x_mouse_click_focus_ignore_position
)
6450 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6452 /* EnterNotify counts as mouse movement,
6453 so update things that depend on mouse position. */
6454 if (f
&& !f
->output_data
.x
->hourglass_p
)
6455 note_mouse_movement (f
, &event
.xmotion
);
6457 /* We may get an EnterNotify on the buttons in the toolbar. In that
6458 case we moved out of any highlighted area and need to note this. */
6459 if (!f
&& last_mouse_glyph_frame
)
6460 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6465 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6469 last_user_time
= event
.xcrossing
.time
;
6470 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6472 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6475 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6477 /* If we move outside the frame, then we're
6478 certainly no longer on any text in the frame. */
6479 clear_mouse_face (dpyinfo
);
6480 dpyinfo
->mouse_face_mouse_frame
= 0;
6483 /* Generate a nil HELP_EVENT to cancel a help-echo.
6484 Do it only if there's something to cancel.
6485 Otherwise, the startup message is cleared when
6486 the mouse leaves the frame. */
6487 if (any_help_event_p
)
6491 /* See comment in EnterNotify above */
6492 else if (last_mouse_glyph_frame
)
6493 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6498 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6503 last_user_time
= event
.xmotion
.time
;
6504 previous_help_echo_string
= help_echo_string
;
6505 help_echo_string
= Qnil
;
6507 if (dpyinfo
->grabbed
&& last_mouse_frame
6508 && FRAME_LIVE_P (last_mouse_frame
))
6509 f
= last_mouse_frame
;
6511 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6513 if (dpyinfo
->mouse_face_hidden
)
6515 dpyinfo
->mouse_face_hidden
= 0;
6516 clear_mouse_face (dpyinfo
);
6520 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6526 /* Generate SELECT_WINDOW_EVENTs when needed.
6527 Don't let popup menus influence things (bug#1261). */
6528 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6532 window
= window_from_coordinates (f
,
6533 event
.xmotion
.x
, event
.xmotion
.y
,
6536 /* Window will be selected only when it is not selected now and
6537 last mouse movement event was not in it. Minibuffer window
6538 will be selected only when it is active. */
6539 if (WINDOWP (window
)
6540 && !EQ (window
, last_window
)
6541 && !EQ (window
, selected_window
)
6542 /* For click-to-focus window managers
6543 create event iff we don't leave the
6545 && (focus_follows_mouse
6546 || (EQ (XWINDOW (window
)->frame
,
6547 XWINDOW (selected_window
)->frame
))))
6549 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6550 inev
.ie
.frame_or_window
= window
;
6555 if (!note_mouse_movement (f
, &event
.xmotion
))
6556 help_echo_string
= previous_help_echo_string
;
6560 #ifndef USE_TOOLKIT_SCROLL_BARS
6561 struct scroll_bar
*bar
6562 = x_window_to_scroll_bar (event
.xmotion
.display
,
6563 event
.xmotion
.window
);
6566 x_scroll_bar_note_movement (bar
, &event
);
6567 #endif /* USE_TOOLKIT_SCROLL_BARS */
6569 /* If we move outside the frame, then we're
6570 certainly no longer on any text in the frame. */
6571 clear_mouse_face (dpyinfo
);
6574 /* If the contents of the global variable help_echo_string
6575 has changed, generate a HELP_EVENT. */
6576 if (!NILP (help_echo_string
)
6577 || !NILP (previous_help_echo_string
))
6582 case ConfigureNotify
:
6583 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6586 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6587 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6589 xg_frame_resized (f
, event
.xconfigure
.width
,
6590 event
.xconfigure
.height
);
6596 #ifndef USE_X_TOOLKIT
6598 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6599 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6601 /* In the toolkit version, change_frame_size
6602 is called by the code that handles resizing
6603 of the EmacsFrame widget. */
6605 /* Even if the number of character rows and columns has
6606 not changed, the font size may have changed, so we need
6607 to check the pixel dimensions as well. */
6608 if (columns
!= FRAME_COLS (f
)
6609 || rows
!= FRAME_LINES (f
)
6610 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6611 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6613 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6614 SET_FRAME_GARBAGED (f
);
6615 cancel_mouse_face (f
);
6618 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6619 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6620 #endif /* not USE_GTK */
6624 /* GTK creates windows but doesn't map them.
6625 Only get real positions when mapped. */
6626 if (FRAME_GTK_OUTER_WIDGET (f
)
6627 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6630 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6634 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6635 xic_set_statusarea (f
);
6644 /* If we decide we want to generate an event to be seen
6645 by the rest of Emacs, we put it here. */
6648 memset (&compose_status
, 0, sizeof (compose_status
));
6649 last_mouse_glyph_frame
= 0;
6650 last_user_time
= event
.xbutton
.time
;
6652 if (dpyinfo
->grabbed
6654 && FRAME_LIVE_P (last_mouse_frame
))
6655 f
= last_mouse_frame
;
6657 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6660 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6665 /* Is this in the tool-bar? */
6666 if (WINDOWP (f
->tool_bar_window
)
6667 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6670 int x
= event
.xbutton
.x
;
6671 int y
= event
.xbutton
.y
;
6673 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6674 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6676 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6678 handle_tool_bar_click (f
, x
, y
,
6679 event
.xbutton
.type
== ButtonPress
,
6680 x_x_to_emacs_modifiers (dpyinfo
,
6681 event
.xbutton
.state
));
6686 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6687 if (! popup_activated ())
6690 if (ignore_next_mouse_click_timeout
)
6692 if (event
.type
== ButtonPress
6693 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6695 ignore_next_mouse_click_timeout
= 0;
6696 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6698 if (event
.type
== ButtonRelease
)
6699 ignore_next_mouse_click_timeout
= 0;
6702 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6704 if (FRAME_X_EMBEDDED_P (f
))
6705 xembed_send_message (f
, event
.xbutton
.time
,
6706 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6710 struct scroll_bar
*bar
6711 = x_window_to_scroll_bar (event
.xbutton
.display
,
6712 event
.xbutton
.window
);
6714 #ifdef USE_TOOLKIT_SCROLL_BARS
6715 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6717 if (bar
&& event
.xbutton
.state
& ControlMask
)
6719 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6720 *finish
= X_EVENT_DROP
;
6722 #else /* not USE_TOOLKIT_SCROLL_BARS */
6724 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6725 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6728 if (event
.type
== ButtonPress
)
6730 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6731 last_mouse_frame
= f
;
6734 last_tool_bar_item
= -1;
6737 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6739 /* Ignore any mouse motion that happened before this event;
6740 any subsequent mouse-movement Emacs events should reflect
6741 only motion after the ButtonPress/Release. */
6745 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6746 f
= x_menubar_window_to_frame (dpyinfo
, &event
);
6747 /* For a down-event in the menu bar,
6748 don't pass it to Xt right now.
6749 Instead, save it away
6750 and we will pass it to Xt from kbd_buffer_get_event.
6751 That way, we can run some Lisp code first. */
6752 if (! popup_activated ()
6754 /* Gtk+ menus only react to the first three buttons. */
6755 && event
.xbutton
.button
< 3
6757 && f
&& event
.type
== ButtonPress
6758 /* Verify the event is really within the menu bar
6759 and not just sent to it due to grabbing. */
6760 && event
.xbutton
.x
>= 0
6761 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6762 && event
.xbutton
.y
>= 0
6763 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6764 && event
.xbutton
.same_screen
)
6766 SET_SAVED_BUTTON_EVENT
;
6767 XSETFRAME (last_mouse_press_frame
, f
);
6768 *finish
= X_EVENT_DROP
;
6770 else if (event
.type
== ButtonPress
)
6772 last_mouse_press_frame
= Qnil
;
6777 #endif /* USE_X_TOOLKIT || USE_GTK */
6781 case CirculateNotify
:
6784 case CirculateRequest
:
6787 case VisibilityNotify
:
6791 /* Someone has changed the keyboard mapping - update the
6793 switch (event
.xmapping
.request
)
6795 case MappingModifier
:
6796 x_find_modifier_meanings (dpyinfo
);
6797 /* This is meant to fall through. */
6798 case MappingKeyboard
:
6799 XRefreshKeyboardMapping (&event
.xmapping
);
6804 xft_settings_event (dpyinfo
, &event
);
6809 #ifdef USE_X_TOOLKIT
6811 if (*finish
!= X_EVENT_DROP
)
6812 XtDispatchEvent (&event
);
6814 #endif /* USE_X_TOOLKIT */
6819 if (inev
.ie
.kind
!= NO_EVENT
)
6821 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6826 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6831 XSETFRAME (frame
, f
);
6837 any_help_event_p
= 1;
6838 gen_help_event (help_echo_string
, frame
, help_echo_window
,
6839 help_echo_object
, help_echo_pos
);
6843 help_echo_string
= Qnil
;
6844 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
6854 /* Handles the XEvent EVENT on display DISPLAY.
6855 This is used for event loops outside the normal event handling,
6856 i.e. looping while a popup menu or a dialog is posted.
6858 Returns the value handle_one_xevent sets in the finish argument. */
6860 x_dispatch_event (XEvent
*event
, Display
*display
)
6862 struct x_display_info
*dpyinfo
;
6863 int finish
= X_EVENT_NORMAL
;
6865 dpyinfo
= x_display_info_for_display (display
);
6868 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
6874 /* Read events coming from the X server.
6875 This routine is called by the SIGIO handler.
6876 We return as soon as there are no more events to be read.
6878 We return the number of characters stored into the buffer,
6879 thus pretending to be `read' (except the characters we store
6880 in the keyboard buffer can be multibyte, so are not necessarily
6883 EXPECTED is nonzero if the caller knows input is available. */
6886 XTread_socket (struct terminal
*terminal
, int expected
, struct input_event
*hold_quit
)
6890 int event_found
= 0;
6892 if (interrupt_input_blocked
)
6894 interrupt_input_pending
= 1;
6896 pending_signals
= 1;
6901 interrupt_input_pending
= 0;
6903 pending_signals
= pending_atimers
;
6907 /* So people can tell when we have read the available input. */
6908 input_signal_count
++;
6913 /* Only check session manager input for the primary display. */
6914 if (terminal
->id
== 1 && x_session_have_connection ())
6916 struct input_event inev
;
6918 /* We don't need to EVENT_INIT (inev) here, as
6919 x_session_check_input copies an entire input_event. */
6920 if (x_session_check_input (&inev
))
6922 kbd_buffer_store_event_hold (&inev
, hold_quit
);
6929 /* For debugging, this gives a way to fake an I/O error. */
6930 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
6932 XTread_socket_fake_io_error
= 0;
6933 x_io_error_quitter (terminal
->display_info
.x
->display
);
6937 while (XPending (terminal
->display_info
.x
->display
))
6941 XNextEvent (terminal
->display_info
.x
->display
, &event
);
6944 /* Filter events for the current X input method. */
6945 if (x_filter_event (terminal
->display_info
.x
, &event
))
6950 count
+= handle_one_xevent (terminal
->display_info
.x
,
6951 &event
, &finish
, hold_quit
);
6953 if (finish
== X_EVENT_GOTO_OUT
)
6959 /* For GTK we must use the GTK event loop. But XEvents gets passed
6960 to our filter function above, and then to the big event switch.
6961 We use a bunch of globals to communicate with our filter function,
6962 that is kind of ugly, but it works.
6964 There is no way to do one display at the time, GTK just does events
6965 from all displays. */
6967 while (gtk_events_pending ())
6969 current_count
= count
;
6970 current_hold_quit
= hold_quit
;
6972 gtk_main_iteration ();
6974 count
= current_count
;
6976 current_hold_quit
= 0;
6978 if (current_finish
== X_EVENT_GOTO_OUT
)
6981 #endif /* USE_GTK */
6985 /* On some systems, an X bug causes Emacs to get no more events
6986 when the window is destroyed. Detect that. (1994.) */
6989 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
6990 One XNOOP in 100 loops will make Emacs terminate.
6991 B. Bretthauer, 1994 */
6993 if (x_noop_count
>= 100)
6997 if (next_noop_dpyinfo
== 0)
6998 next_noop_dpyinfo
= x_display_list
;
7000 XNoOp (next_noop_dpyinfo
->display
);
7002 /* Each time we get here, cycle through the displays now open. */
7003 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7007 /* If the focus was just given to an auto-raising frame,
7009 /* ??? This ought to be able to handle more than one such frame. */
7010 if (pending_autoraise_frame
)
7012 x_raise_frame (pending_autoraise_frame
);
7013 pending_autoraise_frame
= 0;
7025 /***********************************************************************
7027 ***********************************************************************/
7029 /* Set clipping for output in glyph row ROW. W is the window in which
7030 we operate. GC is the graphics context to set clipping in.
7032 ROW may be a text row or, e.g., a mode line. Text rows must be
7033 clipped to the interior of the window dedicated to text display,
7034 mode lines must be clipped to the whole window. */
7037 x_clip_to_row (struct window
*w
, struct glyph_row
*row
, int area
, GC gc
)
7039 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7040 XRectangle clip_rect
;
7041 int window_x
, window_y
, window_width
;
7043 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7045 clip_rect
.x
= window_x
;
7046 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7047 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7048 clip_rect
.width
= window_width
;
7049 clip_rect
.height
= row
->visible_height
;
7051 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7055 /* Draw a hollow box cursor on window W in glyph row ROW. */
7058 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7060 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7061 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7062 Display
*dpy
= FRAME_X_DISPLAY (f
);
7065 struct glyph
*cursor_glyph
;
7068 /* Get the glyph the cursor is on. If we can't tell because
7069 the current matrix is invalid or such, give up. */
7070 cursor_glyph
= get_phys_cursor_glyph (w
);
7071 if (cursor_glyph
== NULL
)
7074 /* Compute frame-relative coordinates for phys cursor. */
7075 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7076 wd
= w
->phys_cursor_width
;
7078 /* The foreground of cursor_gc is typically the same as the normal
7079 background color, which can cause the cursor box to be invisible. */
7080 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7081 if (dpyinfo
->scratch_cursor_gc
)
7082 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7084 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7085 GCForeground
, &xgcv
);
7086 gc
= dpyinfo
->scratch_cursor_gc
;
7088 /* Set clipping, draw the rectangle, and reset clipping again. */
7089 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7090 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7091 XSetClipMask (dpy
, gc
, None
);
7095 /* Draw a bar cursor on window W in glyph row ROW.
7097 Implementation note: One would like to draw a bar cursor with an
7098 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7099 Unfortunately, I didn't find a font yet that has this property set.
7103 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7105 struct frame
*f
= XFRAME (w
->frame
);
7106 struct glyph
*cursor_glyph
;
7108 /* If cursor is out of bounds, don't draw garbage. This can happen
7109 in mini-buffer windows when switching between echo area glyphs
7111 cursor_glyph
= get_phys_cursor_glyph (w
);
7112 if (cursor_glyph
== NULL
)
7115 /* If on an image, draw like a normal cursor. That's usually better
7116 visible than drawing a bar, esp. if the image is large so that
7117 the bar might not be in the window. */
7118 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7120 struct glyph_row
*row
;
7121 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7122 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7126 Display
*dpy
= FRAME_X_DISPLAY (f
);
7127 Window window
= FRAME_X_WINDOW (f
);
7128 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7129 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7130 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7133 /* If the glyph's background equals the color we normally draw
7134 the bars cursor in, the bar cursor in its normal color is
7135 invisible. Use the glyph's foreground color instead in this
7136 case, on the assumption that the glyph's colors are chosen so
7137 that the glyph is legible. */
7138 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7139 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7141 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7142 xgcv
.graphics_exposures
= 0;
7145 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7148 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7149 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7152 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7154 if (kind
== BAR_CURSOR
)
7157 width
= FRAME_CURSOR_WIDTH (f
);
7158 width
= min (cursor_glyph
->pixel_width
, width
);
7160 w
->phys_cursor_width
= width
;
7162 XFillRectangle (dpy
, window
, gc
,
7163 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7164 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7165 width
, row
->height
);
7169 int dummy_x
, dummy_y
, dummy_h
;
7172 width
= row
->height
;
7174 width
= min (row
->height
, width
);
7176 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7177 &dummy_y
, &dummy_h
);
7179 XFillRectangle (dpy
, window
, gc
,
7180 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7181 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7182 row
->height
- width
),
7183 w
->phys_cursor_width
, width
);
7186 XSetClipMask (dpy
, gc
, None
);
7191 /* RIF: Define cursor CURSOR on frame F. */
7194 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7196 if (!f
->pointer_invisible
7197 && f
->output_data
.x
->current_cursor
!= cursor
)
7198 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7199 f
->output_data
.x
->current_cursor
= cursor
;
7203 /* RIF: Clear area on frame F. */
7206 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7208 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7209 x
, y
, width
, height
, False
);
7211 /* Must queue a redraw, because scroll bars might have been cleared. */
7212 if (FRAME_GTK_WIDGET (f
))
7213 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7218 /* RIF: Draw cursor on window W. */
7221 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
)
7223 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7227 w
->phys_cursor_type
= cursor_type
;
7228 w
->phys_cursor_on_p
= 1;
7230 if (glyph_row
->exact_window_width_line_p
7231 && (glyph_row
->reversed_p
7232 ? (w
->phys_cursor
.hpos
< 0)
7233 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7235 glyph_row
->cursor_in_fringe_p
= 1;
7236 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7240 switch (cursor_type
)
7242 case HOLLOW_BOX_CURSOR
:
7243 x_draw_hollow_cursor (w
, glyph_row
);
7246 case FILLED_BOX_CURSOR
:
7247 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7251 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7255 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7259 w
->phys_cursor_width
= 0;
7268 if (w
== XWINDOW (f
->selected_window
))
7269 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7270 xic_set_preeditarea (w
, x
, y
);
7275 XFlush (FRAME_X_DISPLAY (f
));
7282 /* Make the x-window of frame F use the gnu icon bitmap. */
7285 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7289 if (FRAME_X_WINDOW (f
) == 0)
7292 /* Free up our existing icon bitmap and mask if any. */
7293 if (f
->output_data
.x
->icon_bitmap
> 0)
7294 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7295 f
->output_data
.x
->icon_bitmap
= 0;
7300 /* Use gtk_window_set_icon_from_file () if available,
7301 It's not restricted to bitmaps */
7302 if (xg_set_icon (f
, file
))
7304 #endif /* USE_GTK */
7305 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7306 x_create_bitmap_mask (f
, bitmap_id
);
7310 /* Create the GNU bitmap and mask if necessary. */
7311 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7317 if (xg_set_icon (f
, xg_default_icon_file
)
7318 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7321 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7323 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7325 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7329 /* If all else fails, use the (black and white) xbm image. */
7332 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7333 gnu_xbm_width
, gnu_xbm_height
);
7337 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7338 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7342 /* The first time we create the GNU bitmap and mask,
7343 this increments the ref-count one extra time.
7344 As a result, the GNU bitmap and mask are never freed.
7345 That way, we don't have to worry about allocating it again. */
7346 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7348 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7351 x_wm_set_icon_pixmap (f
, bitmap_id
);
7352 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7358 /* Make the x-window of frame F use a rectangle with text.
7359 Use ICON_NAME as the text. */
7362 x_text_icon (struct frame
*f
, const char *icon_name
)
7364 if (FRAME_X_WINDOW (f
) == 0)
7369 text
.value
= (unsigned char *) icon_name
;
7370 text
.encoding
= XA_STRING
;
7372 text
.nitems
= strlen (icon_name
);
7373 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7376 if (f
->output_data
.x
->icon_bitmap
> 0)
7377 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7378 f
->output_data
.x
->icon_bitmap
= 0;
7379 x_wm_set_icon_pixmap (f
, 0);
7384 #define X_ERROR_MESSAGE_SIZE 200
7386 /* If non-nil, this should be a string.
7387 It means catch X errors and store the error message in this string.
7389 The reason we use a stack is that x_catch_error/x_uncatch_error can
7390 be called from a signal handler.
7393 struct x_error_message_stack
{
7394 char string
[X_ERROR_MESSAGE_SIZE
];
7396 struct x_error_message_stack
*prev
;
7398 static struct x_error_message_stack
*x_error_message
;
7400 /* An X error handler which stores the error message in
7401 *x_error_message. This is called from x_error_handler if
7402 x_catch_errors is in effect. */
7405 x_error_catcher (Display
*display
, XErrorEvent
*error
)
7407 XGetErrorText (display
, error
->error_code
,
7408 x_error_message
->string
,
7409 X_ERROR_MESSAGE_SIZE
);
7412 /* Begin trapping X errors for display DPY. Actually we trap X errors
7413 for all displays, but DPY should be the display you are actually
7416 After calling this function, X protocol errors no longer cause
7417 Emacs to exit; instead, they are recorded in the string
7418 stored in *x_error_message.
7420 Calling x_check_errors signals an Emacs error if an X error has
7421 occurred since the last call to x_catch_errors or x_check_errors.
7423 Calling x_uncatch_errors resumes the normal error handling. */
7425 void x_check_errors (Display
*dpy
, const char *format
);
7428 x_catch_errors (Display
*dpy
)
7430 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7432 /* Make sure any errors from previous requests have been dealt with. */
7436 data
->string
[0] = 0;
7437 data
->prev
= x_error_message
;
7438 x_error_message
= data
;
7441 /* Undo the last x_catch_errors call.
7442 DPY should be the display that was passed to x_catch_errors. */
7445 x_uncatch_errors (void)
7447 struct x_error_message_stack
*tmp
;
7451 /* The display may have been closed before this function is called.
7452 Check if it is still open before calling XSync. */
7453 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7454 XSync (x_error_message
->dpy
, False
);
7456 tmp
= x_error_message
;
7457 x_error_message
= x_error_message
->prev
;
7462 /* If any X protocol errors have arrived since the last call to
7463 x_catch_errors or x_check_errors, signal an Emacs error using
7464 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7467 x_check_errors (Display
*dpy
, const char *format
)
7469 /* Make sure to catch any errors incurred so far. */
7472 if (x_error_message
->string
[0])
7474 char string
[X_ERROR_MESSAGE_SIZE
];
7475 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7476 x_uncatch_errors ();
7477 error (format
, string
);
7481 /* Nonzero if we had any X protocol errors
7482 since we did x_catch_errors on DPY. */
7485 x_had_errors_p (Display
*dpy
)
7487 /* Make sure to catch any errors incurred so far. */
7490 return x_error_message
->string
[0] != 0;
7493 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7496 x_clear_errors (Display
*dpy
)
7498 x_error_message
->string
[0] = 0;
7501 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7502 * idea. --lorentey */
7503 /* Close off all unclosed x_catch_errors calls. */
7506 x_fully_uncatch_errors (void)
7508 while (x_error_message
)
7509 x_uncatch_errors ();
7513 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7516 x_catching_errors (void)
7518 return x_error_message
!= 0;
7522 static unsigned int x_wire_count
;
7525 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7530 /* Handle SIGPIPE, which can happen when the connection to a server
7531 simply goes away. SIGPIPE is handled by x_connection_signal.
7532 Don't need to do anything, because the write which caused the
7533 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7534 which will do the appropriate cleanup for us. */
7537 x_connection_signal (int signalnum
) /* If we don't have an argument, */
7538 /* some compilers complain in signal calls. */
7541 /* USG systems forget handlers when they are used;
7542 must reestablish each time */
7543 signal (signalnum
, x_connection_signal
);
7548 /************************************************************************
7550 ************************************************************************/
7552 /* Error message passed to x_connection_closed. */
7554 static char *error_msg
;
7556 /* Function installed as fatal_error_signal_hook in
7557 x_connection_closed. Print the X error message, and exit normally,
7558 instead of dumping core when XtCloseDisplay fails. */
7561 x_fatal_error_signal (void)
7563 fprintf (stderr
, "%s\n", error_msg
);
7567 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7568 the text of an error message that lead to the connection loss. */
7571 x_connection_closed (Display
*dpy
, const char *error_message
)
7573 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7574 Lisp_Object frame
, tail
;
7575 int index
= SPECPDL_INDEX ();
7577 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7578 strcpy (error_msg
, error_message
);
7579 handling_signal
= 0;
7581 /* Prevent being called recursively because of an error condition
7582 below. Otherwise, we might end up with printing ``can't find per
7583 display information'' in the recursive call instead of printing
7584 the original message here. */
7585 x_catch_errors (dpy
);
7587 /* Inhibit redisplay while frames are being deleted. */
7588 specbind (Qinhibit_redisplay
, Qt
);
7592 /* Protect display from being closed when we delete the last
7594 dpyinfo
->reference_count
++;
7595 dpyinfo
->terminal
->reference_count
++;
7598 /* First delete frames whose mini-buffers are on frames
7599 that are on the dead display. */
7600 FOR_EACH_FRAME (tail
, frame
)
7602 Lisp_Object minibuf_frame
;
7604 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7605 if (FRAME_X_P (XFRAME (frame
))
7606 && FRAME_X_P (XFRAME (minibuf_frame
))
7607 && ! EQ (frame
, minibuf_frame
)
7608 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7609 delete_frame (frame
, Qnoelisp
);
7612 /* Now delete all remaining frames on the dead display.
7613 We are now sure none of these is used as the mini-buffer
7614 for another frame that we need to delete. */
7615 FOR_EACH_FRAME (tail
, frame
)
7616 if (FRAME_X_P (XFRAME (frame
))
7617 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7619 /* Set this to t so that delete_frame won't get confused
7620 trying to find a replacement. */
7621 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7622 delete_frame (frame
, Qnoelisp
);
7625 /* We have to close the display to inform Xt that it doesn't
7626 exist anymore. If we don't, Xt will continue to wait for
7627 events from the display. As a consequence, a sequence of
7629 M-x make-frame-on-display RET :1 RET
7630 ...kill the new frame, so that we get an IO error...
7631 M-x make-frame-on-display RET :1 RET
7633 will indefinitely wait in Xt for events for display `:1', opened
7634 in the first call to make-frame-on-display.
7636 Closing the display is reported to lead to a bus error on
7637 OpenWindows in certain situations. I suspect that is a bug
7638 in OpenWindows. I don't know how to circumvent it here. */
7642 #ifdef USE_X_TOOLKIT
7643 /* If DPYINFO is null, this means we didn't open the display
7644 in the first place, so don't try to close it. */
7646 extern void (*fatal_error_signal_hook
) (void);
7647 fatal_error_signal_hook
= x_fatal_error_signal
;
7648 XtCloseDisplay (dpy
);
7649 fatal_error_signal_hook
= NULL
;
7654 /* Due to bugs in some Gtk+ versions, just exit here if this
7655 is the last display/terminal. */
7656 if (terminal_list
->next_terminal
== NULL
)
7658 fprintf (stderr
, "%s\n", error_msg
);
7659 Fkill_emacs (make_number (70));
7662 xg_display_close (dpyinfo
->display
);
7665 /* Indicate that this display is dead. */
7666 dpyinfo
->display
= 0;
7668 dpyinfo
->reference_count
--;
7669 dpyinfo
->terminal
->reference_count
--;
7670 if (dpyinfo
->reference_count
!= 0)
7671 /* We have just closed all frames on this display. */
7676 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7677 Fdelete_terminal (tmp
, Qnoelisp
);
7681 x_uncatch_errors ();
7683 if (terminal_list
== 0)
7685 fprintf (stderr
, "%s\n", error_msg
);
7686 Fkill_emacs (make_number (70));
7690 /* Ordinary stack unwind doesn't deal with these. */
7692 sigunblock (sigmask (SIGIO
));
7694 sigunblock (sigmask (SIGALRM
));
7695 TOTALLY_UNBLOCK_INPUT
;
7697 unbind_to (index
, Qnil
);
7698 clear_waiting_for_input ();
7699 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7700 longjmp), because returning from this function would get us back into
7701 Xlib's code which will directly call `exit'. */
7702 error ("%s", error_msg
);
7705 /* We specifically use it before defining it, so that gcc doesn't inline it,
7706 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7707 static void x_error_quitter (Display
*, XErrorEvent
*);
7709 /* This is the first-level handler for X protocol errors.
7710 It calls x_error_quitter or x_error_catcher. */
7713 x_error_handler (Display
*display
, XErrorEvent
*error
)
7715 if (x_error_message
)
7716 x_error_catcher (display
, error
);
7718 x_error_quitter (display
, error
);
7722 /* This is the usual handler for X protocol errors.
7723 It kills all frames on the display that we got the error for.
7724 If that was the only one, it prints an error message and kills Emacs. */
7726 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7728 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
7729 #define NO_INLINE __attribute__((noinline))
7734 /* Some versions of GNU/Linux define noinline in their headers. */
7740 /* On older GCC versions, just putting x_error_quitter
7741 after x_error_handler prevents inlining into the former. */
7743 static void NO_INLINE
7744 x_error_quitter (Display
*display
, XErrorEvent
*error
)
7746 char buf
[256], buf1
[356];
7748 /* Ignore BadName errors. They can happen because of fonts
7749 or colors that are not defined. */
7751 if (error
->error_code
== BadName
)
7754 /* Note that there is no real way portable across R3/R4 to get the
7755 original error handler. */
7757 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7758 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7759 buf
, error
->request_code
);
7760 x_connection_closed (display
, buf1
);
7764 /* This is the handler for X IO errors, always.
7765 It kills all frames on the display that we lost touch with.
7766 If that was the only one, it prints an error message and kills Emacs. */
7769 x_io_error_quitter (Display
*display
)
7773 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7774 x_connection_closed (display
, buf
);
7778 /* Changing the font of the frame. */
7780 /* Give frame F the font FONT-OBJECT as its default font. The return
7781 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7782 frame. If it is negative, generate a new fontset from
7786 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7788 struct font
*font
= XFONT_OBJECT (font_object
);
7791 fontset
= fontset_from_font (font_object
);
7792 FRAME_FONTSET (f
) = fontset
;
7793 if (FRAME_FONT (f
) == font
)
7794 /* This font is already set in frame F. There's nothing more to
7798 FRAME_FONT (f
) = font
;
7799 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7800 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7801 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
7802 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7804 compute_fringe_widths (f
, 1);
7806 /* Compute the scroll bar width in character columns. */
7807 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7809 int wid
= FRAME_COLUMN_WIDTH (f
);
7810 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7811 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7815 int wid
= FRAME_COLUMN_WIDTH (f
);
7816 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7819 if (FRAME_X_WINDOW (f
) != 0)
7821 /* Don't change the size of a tip frame; there's no point in
7822 doing it because it's done in Fx_show_tip, and it leads to
7823 problems because the tip frame has no widget. */
7824 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7825 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7830 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7833 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
7842 /***********************************************************************
7844 ***********************************************************************/
7850 /* XIM destroy callback function, which is called whenever the
7851 connection to input method XIM dies. CLIENT_DATA contains a
7852 pointer to the x_display_info structure corresponding to XIM. */
7855 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
7857 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7858 Lisp_Object frame
, tail
;
7862 /* No need to call XDestroyIC.. */
7863 FOR_EACH_FRAME (tail
, frame
)
7865 struct frame
*f
= XFRAME (frame
);
7866 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
7868 FRAME_XIC (f
) = NULL
;
7869 xic_free_xfontset (f
);
7873 /* No need to call XCloseIM. */
7874 dpyinfo
->xim
= NULL
;
7875 XFree (dpyinfo
->xim_styles
);
7879 #endif /* HAVE_X11R6 */
7882 /* This isn't prototyped in OSF 5.0 or 5.1a. */
7883 extern char *XSetIMValues (XIM
, ...);
7886 /* Open the connection to the XIM server on display DPYINFO.
7887 RESOURCE_NAME is the resource name Emacs uses. */
7890 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
7898 XCloseIM (dpyinfo
->xim
);
7899 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
7906 XIMCallback destroy
;
7909 /* Get supported styles and XIM values. */
7910 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
7913 destroy
.callback
= xim_destroy_callback
;
7914 destroy
.client_data
= (XPointer
)dpyinfo
;
7915 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
7921 #endif /* HAVE_XIM */
7922 dpyinfo
->xim
= NULL
;
7926 #ifdef HAVE_X11R6_XIM
7928 /* XIM instantiate callback function, which is called whenever an XIM
7929 server is available. DISPLAY is the display of the XIM.
7930 CLIENT_DATA contains a pointer to an xim_inst_t structure created
7931 when the callback was registered. */
7934 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
7936 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
7937 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
7939 /* We don't support multiple XIM connections. */
7943 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
7945 /* Create XIC for the existing frames on the same display, as long
7946 as they have no XIC. */
7947 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
7949 Lisp_Object tail
, frame
;
7952 FOR_EACH_FRAME (tail
, frame
)
7954 struct frame
*f
= XFRAME (frame
);
7957 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
7958 if (FRAME_XIC (f
) == NULL
)
7960 create_frame_xic (f
);
7961 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
7962 xic_set_statusarea (f
);
7963 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
7965 struct window
*w
= XWINDOW (f
->selected_window
);
7966 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
7975 #endif /* HAVE_X11R6_XIM */
7978 /* Open a connection to the XIM server on display DPYINFO.
7979 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
7980 connection only at the first time. On X11R6, open the connection
7981 in the XIM instantiate callback function. */
7984 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
7986 dpyinfo
->xim
= NULL
;
7990 #ifdef HAVE_X11R6_XIM
7991 struct xim_inst_t
*xim_inst
;
7994 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
7995 dpyinfo
->xim_callback_data
= xim_inst
;
7996 xim_inst
->dpyinfo
= dpyinfo
;
7997 len
= strlen (resource_name
);
7998 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
7999 memcpy (xim_inst
->resource_name
, resource_name
, len
+ 1);
8000 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8001 resource_name
, EMACS_CLASS
,
8002 xim_instantiate_callback
,
8003 /* This is XPointer in XFree86
8004 but (XPointer *) on Tru64, at
8005 least, hence the configure test. */
8006 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8007 #else /* not HAVE_X11R6_XIM */
8008 xim_open_dpy (dpyinfo
, resource_name
);
8009 #endif /* not HAVE_X11R6_XIM */
8011 #endif /* HAVE_XIM */
8015 /* Close the connection to the XIM server on display DPYINFO. */
8018 xim_close_dpy (struct x_display_info
*dpyinfo
)
8023 #ifdef HAVE_X11R6_XIM
8024 if (dpyinfo
->display
)
8025 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8027 xim_instantiate_callback
, NULL
);
8028 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8029 xfree (dpyinfo
->xim_callback_data
);
8030 #endif /* HAVE_X11R6_XIM */
8031 if (dpyinfo
->display
)
8032 XCloseIM (dpyinfo
->xim
);
8033 dpyinfo
->xim
= NULL
;
8034 XFree (dpyinfo
->xim_styles
);
8036 #endif /* HAVE_XIM */
8039 #endif /* not HAVE_X11R6_XIM */
8043 /* Calculate the absolute position in frame F
8044 from its current recorded position values and gravity. */
8047 x_calc_absolute_position (struct frame
*f
)
8049 int flags
= f
->size_hint_flags
;
8051 /* We have nothing to do if the current position
8052 is already for the top-left corner. */
8053 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8056 /* Treat negative positions as relative to the leftmost bottommost
8057 position that fits on the screen. */
8058 if (flags
& XNegative
)
8059 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8060 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8063 int height
= FRAME_PIXEL_HEIGHT (f
);
8065 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8066 /* Something is fishy here. When using Motif, starting Emacs with
8067 `-g -0-0', the frame appears too low by a few pixels.
8069 This seems to be so because initially, while Emacs is starting,
8070 the column widget's height and the frame's pixel height are
8071 different. The column widget's height is the right one. In
8072 later invocations, when Emacs is up, the frame's pixel height
8075 It's not obvious where the initial small difference comes from.
8076 2000-12-01, gerd. */
8078 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8081 if (flags
& YNegative
)
8082 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8083 - height
+ f
->top_pos
;
8086 /* The left_pos and top_pos
8087 are now relative to the top and left screen edges,
8088 so the flags should correspond. */
8089 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8092 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8093 to really change the position, and 0 when calling from
8094 x_make_frame_visible (in that case, XOFF and YOFF are the current
8095 position values). It is -1 when calling from x_set_frame_parameters,
8096 which means, do adjust for borders but don't change the gravity. */
8099 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8101 int modified_top
, modified_left
;
8103 if (change_gravity
> 0)
8105 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8106 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8110 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8112 f
->size_hint_flags
|= XNegative
;
8114 f
->size_hint_flags
|= YNegative
;
8115 f
->win_gravity
= NorthWestGravity
;
8117 x_calc_absolute_position (f
);
8120 x_wm_set_size_hint (f
, (long) 0, 0);
8122 modified_left
= f
->left_pos
;
8123 modified_top
= f
->top_pos
;
8125 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8127 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8128 than the WM decorations. So we use the calculated offset instead
8129 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8130 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8131 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8134 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8135 modified_left
, modified_top
);
8137 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8138 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8141 /* change_gravity is non-zero when this function is called from Lisp to
8142 programmatically move a frame. In that case, we call
8143 x_check_expected_move to discover if we have a "Type A" or "Type B"
8144 window manager, and, for a "Type A" window manager, adjust the position
8147 We call x_check_expected_move if a programmatic move occurred, and
8148 either the window manager type (A/B) is unknown or it is Type A but we
8149 need to compute the top/left offset adjustment for this frame. */
8151 if (change_gravity
!= 0 &&
8152 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8153 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8154 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8155 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8156 x_check_expected_move (f
, modified_left
, modified_top
);
8161 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8162 on the root window for frame F contains ATOMNAME.
8163 This is how a WM check shall be done according to the Window Manager
8164 Specification/Extended Window Manager Hints at
8165 http://freedesktop.org/wiki/Specifications/wm-spec. */
8168 wm_supports (struct frame
*f
, const char *atomname
)
8171 unsigned long actual_size
, bytes_remaining
;
8172 int i
, rc
, actual_format
;
8174 Window wmcheck_window
;
8175 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8176 Window target_window
= dpyinfo
->root_window
;
8177 long max_len
= 65536;
8178 Display
*dpy
= FRAME_X_DISPLAY (f
);
8179 unsigned char *tmp_data
= NULL
;
8180 Atom target_type
= XA_WINDOW
;
8185 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8187 x_catch_errors (dpy
);
8188 rc
= XGetWindowProperty (dpy
, target_window
,
8189 prop_atom
, 0, max_len
, False
, target_type
,
8190 &actual_type
, &actual_format
, &actual_size
,
8191 &bytes_remaining
, &tmp_data
);
8193 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8195 if (tmp_data
) XFree (tmp_data
);
8196 x_uncatch_errors ();
8201 wmcheck_window
= *(Window
*) tmp_data
;
8204 /* Check if window exists. */
8205 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8207 if (x_had_errors_p (dpy
))
8209 x_uncatch_errors ();
8214 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8216 /* Window changed, reload atoms */
8217 if (dpyinfo
->net_supported_atoms
!= NULL
)
8218 XFree (dpyinfo
->net_supported_atoms
);
8219 dpyinfo
->net_supported_atoms
= NULL
;
8220 dpyinfo
->nr_net_supported_atoms
= 0;
8221 dpyinfo
->net_supported_window
= 0;
8223 target_type
= XA_ATOM
;
8224 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8226 rc
= XGetWindowProperty (dpy
, target_window
,
8227 prop_atom
, 0, max_len
, False
, target_type
,
8228 &actual_type
, &actual_format
, &actual_size
,
8229 &bytes_remaining
, &tmp_data
);
8231 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8233 if (tmp_data
) XFree (tmp_data
);
8234 x_uncatch_errors ();
8239 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8240 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8241 dpyinfo
->net_supported_window
= wmcheck_window
;
8245 want_atom
= XInternAtom (dpy
, atomname
, False
);
8247 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8248 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8250 x_uncatch_errors ();
8257 set_wm_state (Lisp_Object frame
, int add
, const char *what
, const char *what2
)
8259 const char *atom
= "_NET_WM_STATE";
8260 Fx_send_client_event (frame
, make_number (0), frame
,
8261 make_unibyte_string (atom
, strlen (atom
)),
8263 /* 1 = add, 0 = remove */
8265 (make_number (add
? 1 : 0),
8267 (make_unibyte_string (what
, strlen (what
)),
8269 ? Fcons (make_unibyte_string (what2
, strlen (what2
)),
8275 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8279 XSETFRAME (frame
, f
);
8280 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8281 "_NET_WM_STATE_STICKY", NULL
);
8284 /* Do fullscreen as specified in extended window manager hints */
8287 do_ewmh_fullscreen (struct frame
*f
)
8289 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8291 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8292 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8294 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8299 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8300 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8301 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8303 XSETFRAME (frame
, f
);
8305 set_wm_state (frame
, 0, fs
, NULL
);
8306 set_wm_state (frame
, 0, fh
, NULL
);
8307 set_wm_state (frame
, 0, fw
, NULL
);
8309 /* If there are _NET_ atoms we assume we have extended window manager
8311 switch (f
->want_fullscreen
)
8313 case FULLSCREEN_BOTH
:
8314 set_wm_state (frame
, 1, fs
, NULL
);
8316 case FULLSCREEN_WIDTH
:
8317 set_wm_state (frame
, 1, fw
, NULL
);
8319 case FULLSCREEN_HEIGHT
:
8320 set_wm_state (frame
, 1, fh
, NULL
);
8322 case FULLSCREEN_MAXIMIZED
:
8323 set_wm_state (frame
, 1, fw
, fh
);
8327 f
->want_fullscreen
= FULLSCREEN_NONE
;
8331 return have_net_atom
;
8335 XTfullscreen_hook (FRAME_PTR f
)
8337 if (f
->async_visible
)
8340 x_check_fullscreen (f
);
8348 x_handle_net_wm_state (struct frame
*f
, XPropertyEvent
*event
)
8351 unsigned long actual_size
, bytes_remaining
;
8352 int i
, rc
, actual_format
, value
= FULLSCREEN_NONE
;
8353 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8354 long max_len
= 65536;
8355 Display
*dpy
= FRAME_X_DISPLAY (f
);
8356 unsigned char *tmp_data
= NULL
;
8357 Atom target_type
= XA_ATOM
;
8362 x_catch_errors (dpy
);
8363 rc
= XGetWindowProperty (dpy
, event
->window
,
8364 event
->atom
, 0, max_len
, False
, target_type
,
8365 &actual_type
, &actual_format
, &actual_size
,
8366 &bytes_remaining
, &tmp_data
);
8368 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8370 if (tmp_data
) XFree (tmp_data
);
8371 x_uncatch_errors ();
8376 x_uncatch_errors ();
8378 for (i
= 0; i
< actual_size
; ++i
)
8380 Atom a
= ((Atom
*)tmp_data
)[i
];
8381 if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8383 if (value
== FULLSCREEN_HEIGHT
)
8384 value
= FULLSCREEN_MAXIMIZED
;
8386 value
= FULLSCREEN_WIDTH
;
8388 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8390 if (value
== FULLSCREEN_WIDTH
)
8391 value
= FULLSCREEN_MAXIMIZED
;
8393 value
= FULLSCREEN_HEIGHT
;
8395 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen_atom
)
8396 value
= FULLSCREEN_BOTH
;
8397 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8404 case FULLSCREEN_WIDTH
:
8407 case FULLSCREEN_HEIGHT
:
8410 case FULLSCREEN_BOTH
:
8413 case FULLSCREEN_MAXIMIZED
:
8418 store_frame_param (f
, Qfullscreen
, lval
);
8419 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8421 if (tmp_data
) XFree (tmp_data
);
8425 /* Check if we need to resize the frame due to a fullscreen request.
8426 If so needed, resize the frame. */
8428 x_check_fullscreen (struct frame
*f
)
8430 if (do_ewmh_fullscreen (f
))
8433 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8434 return; /* Only fullscreen without WM or with EWM hints (above). */
8436 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8438 int width
= FRAME_COLS (f
), height
= FRAME_LINES (f
);
8439 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8441 switch (f
->want_fullscreen
)
8443 /* No difference between these two when there is no WM */
8444 case FULLSCREEN_BOTH
:
8445 case FULLSCREEN_MAXIMIZED
:
8446 width
= x_display_pixel_width (dpyinfo
);
8447 height
= x_display_pixel_height (dpyinfo
);
8449 case FULLSCREEN_WIDTH
:
8450 width
= x_display_pixel_width (dpyinfo
);
8452 case FULLSCREEN_HEIGHT
:
8453 height
= x_display_pixel_height (dpyinfo
);
8456 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8458 change_frame_size (f
, height
, width
, 0, 1, 0);
8459 SET_FRAME_GARBAGED (f
);
8460 cancel_mouse_face (f
);
8465 /* This function is called by x_set_offset to determine whether the window
8466 manager interfered with the positioning of the frame. Type A window
8467 managers position the surrounding window manager decorations a small
8468 amount above and left of the user-supplied position. Type B window
8469 managers position the surrounding window manager decorations at the
8470 user-specified position. If we detect a Type A window manager, we
8471 compensate by moving the window right and down by the proper amount. */
8474 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8476 int current_left
= 0, current_top
= 0;
8478 /* x_real_positions returns the left and top offsets of the outermost
8479 window manager window around the frame. */
8481 x_real_positions (f
, ¤t_left
, ¤t_top
);
8483 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8485 /* It's a "Type A" window manager. */
8490 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8491 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8492 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8494 /* Now fix the mispositioned frame's location. */
8496 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8497 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8499 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8500 adjusted_left
, adjusted_top
);
8502 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8505 /* It's a "Type B" window manager. We don't have to adjust the
8506 frame's position. */
8508 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8512 /* Wait for XGetGeometry to return up-to-date position information for a
8513 recently-moved frame. Call this immediately after calling XMoveWindow.
8514 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8515 frame has been moved to, so we use a fuzzy position comparison instead
8516 of an exact comparison. */
8519 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8523 while (count
++ < 50)
8525 int current_left
= 0, current_top
= 0;
8527 /* In theory, this call to XSync only needs to happen once, but in
8528 practice, it doesn't seem to work, hence the need for the surrounding
8531 XSync (FRAME_X_DISPLAY (f
), False
);
8532 x_real_positions (f
, ¤t_left
, ¤t_top
);
8536 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8539 if (eabs (current_left
- left
) <= 10
8540 && eabs (current_top
- top
) <= 40)
8543 else if (current_left
== left
&& current_top
== top
)
8547 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8548 will then return up-to-date position info. */
8550 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8554 /* Wait for an event on frame F matching EVENTTYPE. */
8556 x_wait_for_event (struct frame
*f
, int eventtype
)
8558 int level
= interrupt_input_blocked
;
8561 EMACS_TIME tmo
, tmo_at
, time_now
;
8562 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8564 pending_event_wait
.f
= f
;
8565 pending_event_wait
.eventtype
= eventtype
;
8567 /* Set timeout to 0.1 second. Hopefully not noticable.
8568 Maybe it should be configurable. */
8569 EMACS_SET_SECS_USECS (tmo
, 0, 100000);
8570 EMACS_GET_TIME (tmo_at
);
8571 EMACS_ADD_TIME (tmo_at
, tmo_at
, tmo
);
8573 while (pending_event_wait
.eventtype
)
8575 interrupt_input_pending
= 1;
8576 TOTALLY_UNBLOCK_INPUT
;
8577 /* XTread_socket is called after unblock. */
8579 interrupt_input_blocked
= level
;
8584 EMACS_GET_TIME (time_now
);
8585 EMACS_SUB_TIME (tmo
, tmo_at
, time_now
);
8587 if (EMACS_TIME_NEG_P (tmo
) || select (fd
+1, &fds
, NULL
, NULL
, &tmo
) == 0)
8588 break; /* Timeout */
8590 pending_event_wait
.f
= 0;
8591 pending_event_wait
.eventtype
= 0;
8595 /* Change the size of frame F's X window to COLS/ROWS in the case F
8596 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8597 top-left-corner window gravity for this size change and subsequent
8598 size changes. Otherwise we leave the window gravity unchanged. */
8601 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8603 int pixelwidth
, pixelheight
;
8605 check_frame_size (f
, &rows
, &cols
);
8606 f
->scroll_bar_actual_width
8607 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8609 : FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
));
8611 compute_fringe_widths (f
, 0);
8613 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
8614 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8615 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8617 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8618 x_wm_set_size_hint (f
, (long) 0, 0);
8619 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8620 pixelwidth
, pixelheight
);
8623 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8624 receive in the ConfigureNotify event; if we get what we asked
8625 for, then the event won't cause the screen to become garbaged, so
8626 we have to make sure to do it here. */
8627 SET_FRAME_GARBAGED (f
);
8629 /* Now, strictly speaking, we can't be sure that this is accurate,
8630 but the window manager will get around to dealing with the size
8631 change request eventually, and we'll hear how it went when the
8632 ConfigureNotify event gets here.
8634 We could just not bother storing any of this information here,
8635 and let the ConfigureNotify event set everything up, but that
8636 might be kind of confusing to the Lisp code, since size changes
8637 wouldn't be reported in the frame parameters until some random
8638 point in the future when the ConfigureNotify event arrives.
8640 We pass 1 for DELAY since we can't run Lisp code inside of
8643 /* But the ConfigureNotify may in fact never arrive, and then this is
8644 not right if the frame is visible. Instead wait (with timeout)
8645 for the ConfigureNotify. */
8646 if (f
->async_visible
)
8647 x_wait_for_event (f
, ConfigureNotify
);
8650 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8651 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8652 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8658 /* Call this to change the size of frame F's x-window.
8659 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8660 for this size change and subsequent size changes.
8661 Otherwise we leave the window gravity unchanged. */
8664 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8668 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8672 /* When the frame is maximized/fullscreen or running under for
8673 example Xmonad, x_set_window_size_1 will be a no-op.
8674 In that case, the right thing to do is extend rows/cols to
8675 the current frame size. We do that first if x_set_window_size_1
8676 turns out to not be a no-op (there is no way to know).
8677 The size will be adjusted again if the frame gets a
8678 ConfigureNotify event as a result of x_set_window_size. */
8679 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8680 #ifdef USE_X_TOOLKIT
8681 /* The menu bar is not part of text lines. The tool bar
8683 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8685 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8686 /* Update f->scroll_bar_actual_width because it is used in
8687 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8688 f
->scroll_bar_actual_width
8689 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8690 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8691 change_frame_size (f
, r
, c
, 0, 1, 0);
8695 if (FRAME_GTK_WIDGET (f
))
8696 xg_frame_set_char_size (f
, cols
, rows
);
8698 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8699 #else /* not USE_GTK */
8701 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8703 #endif /* not USE_GTK */
8705 /* If cursor was outside the new size, mark it as off. */
8706 mark_window_cursors_off (XWINDOW (f
->root_window
));
8708 /* Clear out any recollection of where the mouse highlighting was,
8709 since it might be in a place that's outside the new frame size.
8710 Actually checking whether it is outside is a pain in the neck,
8711 so don't try--just let the highlighting be done afresh with new size. */
8712 cancel_mouse_face (f
);
8717 /* Mouse warping. */
8720 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8724 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8725 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8727 if (pix_x
< 0) pix_x
= 0;
8728 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8730 if (pix_y
< 0) pix_y
= 0;
8731 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8735 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8736 0, 0, 0, 0, pix_x
, pix_y
);
8740 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8743 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8747 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8748 0, 0, 0, 0, pix_x
, pix_y
);
8752 /* focus shifting, raising and lowering. */
8755 x_focus_on_frame (struct frame
*f
)
8758 /* I don't think that the ICCCM allows programs to do things like this
8759 without the interaction of the window manager. Whatever you end up
8760 doing with this code, do it to x_unfocus_frame too. */
8761 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8762 RevertToPointerRoot
, CurrentTime
);
8767 x_unfocus_frame (struct frame
*f
)
8770 /* Look at the remarks in x_focus_on_frame. */
8771 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8772 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8773 RevertToPointerRoot
, CurrentTime
);
8777 /* Raise frame F. */
8780 x_raise_frame (struct frame
*f
)
8783 if (f
->async_visible
)
8784 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8786 XFlush (FRAME_X_DISPLAY (f
));
8790 /* Lower frame F. */
8793 x_lower_frame (struct frame
*f
)
8795 if (f
->async_visible
)
8798 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8799 XFlush (FRAME_X_DISPLAY (f
));
8804 /* Activate frame with Extended Window Manager Hints */
8807 x_ewmh_activate_frame (FRAME_PTR f
)
8809 /* See Window Manager Specification/Extended Window Manager Hints at
8810 http://freedesktop.org/wiki/Specifications/wm-spec */
8812 const char *atom
= "_NET_ACTIVE_WINDOW";
8813 if (f
->async_visible
&& wm_supports (f
, atom
))
8816 XSETFRAME (frame
, f
);
8817 Fx_send_client_event (frame
, make_number (0), frame
,
8818 make_unibyte_string (atom
, strlen (atom
)),
8820 Fcons (make_number (1),
8821 Fcons (make_number (last_user_time
),
8827 XTframe_raise_lower (FRAME_PTR f
, int raise_flag
)
8835 /* XEmbed implementation. */
8838 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
8841 unsigned long data
[2];
8843 atom
= XInternAtom (FRAME_X_DISPLAY (f
), "_XEMBED_INFO", False
);
8845 data
[0] = XEMBED_VERSION
;
8848 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), atom
, atom
,
8849 32, PropModeReplace
, (unsigned char *) data
, 2);
8853 xembed_send_message (struct frame
*f
, Time time
, enum xembed_message message
, long int detail
, long int data1
, long int data2
)
8857 event
.xclient
.type
= ClientMessage
;
8858 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
8859 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
8860 event
.xclient
.format
= 32;
8861 event
.xclient
.data
.l
[0] = time
;
8862 event
.xclient
.data
.l
[1] = message
;
8863 event
.xclient
.data
.l
[2] = detail
;
8864 event
.xclient
.data
.l
[3] = data1
;
8865 event
.xclient
.data
.l
[4] = data2
;
8867 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
8868 False
, NoEventMask
, &event
);
8869 XSync (FRAME_X_DISPLAY (f
), False
);
8872 /* Change of visibility. */
8874 /* This tries to wait until the frame is really visible.
8875 However, if the window manager asks the user where to position
8876 the frame, this will return before the user finishes doing that.
8877 The frame will not actually be visible at that time,
8878 but it will become visible later when the window manager
8879 finishes with it. */
8882 x_make_frame_visible (struct frame
*f
)
8885 int original_top
, original_left
;
8886 int retry_count
= 2;
8892 type
= x_icon_type (f
);
8894 x_bitmap_icon (f
, type
);
8896 if (! FRAME_VISIBLE_P (f
))
8898 /* We test FRAME_GARBAGED_P here to make sure we don't
8899 call x_set_offset a second time
8900 if we get to x_make_frame_visible a second time
8901 before the window gets really visible. */
8902 if (! FRAME_ICONIFIED_P (f
)
8903 && ! FRAME_X_EMBEDDED_P (f
)
8904 && ! f
->output_data
.x
->asked_for_visible
)
8905 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8907 f
->output_data
.x
->asked_for_visible
= 1;
8909 if (! EQ (Vx_no_window_manager
, Qt
))
8910 x_wm_set_window_state (f
, NormalState
);
8911 #ifdef USE_X_TOOLKIT
8912 if (FRAME_X_EMBEDDED_P (f
))
8913 xembed_set_info (f
, XEMBED_MAPPED
);
8916 /* This was XtPopup, but that did nothing for an iconified frame. */
8917 XtMapWidget (f
->output_data
.x
->widget
);
8919 #else /* not USE_X_TOOLKIT */
8921 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8922 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8924 if (FRAME_X_EMBEDDED_P (f
))
8925 xembed_set_info (f
, XEMBED_MAPPED
);
8927 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8928 #endif /* not USE_GTK */
8929 #endif /* not USE_X_TOOLKIT */
8932 XFlush (FRAME_X_DISPLAY (f
));
8934 /* Synchronize to ensure Emacs knows the frame is visible
8935 before we do anything else. We do this loop with input not blocked
8936 so that incoming events are handled. */
8940 /* This must be before UNBLOCK_INPUT
8941 since events that arrive in response to the actions above
8942 will set it when they are handled. */
8943 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8945 original_left
= f
->left_pos
;
8946 original_top
= f
->top_pos
;
8948 /* This must come after we set COUNT. */
8951 /* We unblock here so that arriving X events are processed. */
8953 /* Now move the window back to where it was "supposed to be".
8954 But don't do it if the gravity is negative.
8955 When the gravity is negative, this uses a position
8956 that is 3 pixels too low. Perhaps that's really the border width.
8958 Don't do this if the window has never been visible before,
8959 because the window manager may choose the position
8960 and we don't want to override it. */
8962 if (! FRAME_VISIBLE_P (f
)
8963 && ! FRAME_ICONIFIED_P (f
)
8964 && ! FRAME_X_EMBEDDED_P (f
)
8965 && f
->win_gravity
== NorthWestGravity
8966 && previously_visible
)
8970 unsigned int width
, height
, border
, depth
;
8974 /* On some window managers (such as FVWM) moving an existing
8975 window, even to the same place, causes the window manager
8976 to introduce an offset. This can cause the window to move
8977 to an unexpected location. Check the geometry (a little
8978 slow here) and then verify that the window is in the right
8979 place. If the window is not in the right place, move it
8980 there, and take the potential window manager hit. */
8981 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8982 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
8984 if (original_left
!= x
|| original_top
!= y
)
8985 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8986 original_left
, original_top
);
8991 XSETFRAME (frame
, f
);
8993 /* Wait until the frame is visible. Process X events until a
8994 MapNotify event has been seen, or until we think we won't get a
8995 MapNotify at all.. */
8996 for (count
= input_signal_count
+ 10;
8997 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
8999 /* Force processing of queued events. */
9002 /* Machines that do polling rather than SIGIO have been
9003 observed to go into a busy-wait here. So we'll fake an
9004 alarm signal to let the handler know that there's something
9005 to be read. We used to raise a real alarm, but it seems
9006 that the handler isn't always enabled here. This is
9008 if (input_polling_used ())
9010 /* It could be confusing if a real alarm arrives while
9011 processing the fake one. Turn it off and let the
9012 handler reset it. */
9013 int old_poll_suppress_count
= poll_suppress_count
;
9014 poll_suppress_count
= 1;
9015 poll_for_input_1 ();
9016 poll_suppress_count
= old_poll_suppress_count
;
9019 /* See if a MapNotify event has been processed. */
9020 FRAME_SAMPLE_VISIBILITY (f
);
9025 (let ((f (selected-frame)))
9029 the frame is not raised with various window managers on
9030 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9031 unknown reason, the call to XtMapWidget is completely ignored.
9032 Mapping the widget a second time works. */
9034 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9039 /* Change from mapped state to withdrawn state. */
9041 /* Make the frame visible (mapped and not iconified). */
9044 x_make_frame_invisible (struct frame
*f
)
9048 /* Use the frame's outermost window, not the one we normally draw on. */
9049 window
= FRAME_OUTER_WINDOW (f
);
9051 /* Don't keep the highlight on an invisible frame. */
9052 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9053 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9057 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9058 that the current position of the window is user-specified, rather than
9059 program-specified, so that when the window is mapped again, it will be
9060 placed at the same location, without forcing the user to position it
9061 by hand again (they have already done that once for this window.) */
9062 x_wm_set_size_hint (f
, (long) 0, 1);
9065 if (FRAME_GTK_OUTER_WIDGET (f
))
9066 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9069 if (FRAME_X_EMBEDDED_P (f
))
9070 xembed_set_info (f
, 0);
9075 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9076 DefaultScreen (FRAME_X_DISPLAY (f
))))
9078 UNBLOCK_INPUT_RESIGNAL
;
9079 error ("Can't notify window manager of window withdrawal");
9083 /* We can't distinguish this from iconification
9084 just by the event that we get from the server.
9085 So we can't win using the usual strategy of letting
9086 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9087 and synchronize with the server to make sure we agree. */
9089 FRAME_ICONIFIED_P (f
) = 0;
9090 f
->async_visible
= 0;
9091 f
->async_iconified
= 0;
9098 /* Change window state from mapped to iconified. */
9101 x_iconify_frame (struct frame
*f
)
9106 /* Don't keep the highlight on an invisible frame. */
9107 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9108 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9110 if (f
->async_iconified
)
9115 FRAME_SAMPLE_VISIBILITY (f
);
9117 type
= x_icon_type (f
);
9119 x_bitmap_icon (f
, type
);
9122 if (FRAME_GTK_OUTER_WIDGET (f
))
9124 if (! FRAME_VISIBLE_P (f
))
9125 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9127 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9130 f
->async_iconified
= 1;
9131 f
->async_visible
= 0;
9137 #ifdef USE_X_TOOLKIT
9139 if (! FRAME_VISIBLE_P (f
))
9141 if (! EQ (Vx_no_window_manager
, Qt
))
9142 x_wm_set_window_state (f
, IconicState
);
9143 /* This was XtPopup, but that did nothing for an iconified frame. */
9144 XtMapWidget (f
->output_data
.x
->widget
);
9145 /* The server won't give us any event to indicate
9146 that an invisible frame was changed to an icon,
9147 so we have to record it here. */
9150 f
->async_iconified
= 1;
9151 f
->async_visible
= 0;
9156 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9157 XtWindow (f
->output_data
.x
->widget
),
9158 DefaultScreen (FRAME_X_DISPLAY (f
)));
9162 error ("Can't notify window manager of iconification");
9164 f
->async_iconified
= 1;
9165 f
->async_visible
= 0;
9169 XFlush (FRAME_X_DISPLAY (f
));
9171 #else /* not USE_X_TOOLKIT */
9173 /* Make sure the X server knows where the window should be positioned,
9174 in case the user deiconifies with the window manager. */
9175 if (! FRAME_VISIBLE_P (f
)
9176 && ! FRAME_ICONIFIED_P (f
)
9177 && ! FRAME_X_EMBEDDED_P (f
))
9178 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9180 /* Since we don't know which revision of X we're running, we'll use both
9181 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9183 /* X11R4: send a ClientMessage to the window manager using the
9184 WM_CHANGE_STATE type. */
9188 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9189 message
.xclient
.type
= ClientMessage
;
9190 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9191 message
.xclient
.format
= 32;
9192 message
.xclient
.data
.l
[0] = IconicState
;
9194 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9195 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9197 SubstructureRedirectMask
| SubstructureNotifyMask
,
9200 UNBLOCK_INPUT_RESIGNAL
;
9201 error ("Can't notify window manager of iconification");
9205 /* X11R3: set the initial_state field of the window manager hints to
9207 x_wm_set_window_state (f
, IconicState
);
9209 if (!FRAME_VISIBLE_P (f
))
9211 /* If the frame was withdrawn, before, we must map it. */
9212 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9215 f
->async_iconified
= 1;
9216 f
->async_visible
= 0;
9218 XFlush (FRAME_X_DISPLAY (f
));
9220 #endif /* not USE_X_TOOLKIT */
9224 /* Free X resources of frame F. */
9227 x_free_frame_resources (struct frame
*f
)
9229 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9231 struct scroll_bar
*b
;
9235 /* If a display connection is dead, don't try sending more
9236 commands to the X server. */
9237 if (dpyinfo
->display
)
9239 /* We must free faces before destroying windows because some
9240 font-driver (e.g. xft) access a window while finishing a
9242 if (FRAME_FACE_CACHE (f
))
9243 free_frame_faces (f
);
9245 if (f
->output_data
.x
->icon_desc
)
9246 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9248 #ifdef USE_X_TOOLKIT
9249 /* Explicitly destroy the scroll bars of the frame. Without
9250 this, we get "BadDrawable" errors from the toolkit later on,
9251 presumably from expose events generated for the disappearing
9252 toolkit scroll bars. */
9253 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9255 b
= XSCROLL_BAR (bar
);
9256 x_scroll_bar_remove (b
);
9265 #ifdef USE_X_TOOLKIT
9266 if (f
->output_data
.x
->widget
)
9268 XtDestroyWidget (f
->output_data
.x
->widget
);
9269 f
->output_data
.x
->widget
= NULL
;
9271 /* Tooltips don't have widgets, only a simple X window, even if
9272 we are using a toolkit. */
9273 else if (FRAME_X_WINDOW (f
))
9274 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9276 free_frame_menubar (f
);
9277 #else /* !USE_X_TOOLKIT */
9280 /* In the GTK version, tooltips are normal X
9281 frames. We must check and free both types. */
9282 if (FRAME_GTK_OUTER_WIDGET (f
))
9284 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9285 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9286 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9288 #endif /* USE_GTK */
9290 if (FRAME_X_WINDOW (f
))
9291 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9292 #endif /* !USE_X_TOOLKIT */
9294 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9295 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9296 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9297 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9298 unload_color (f
, f
->output_data
.x
->border_pixel
);
9299 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9301 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9302 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9303 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9304 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9305 #ifdef USE_TOOLKIT_SCROLL_BARS
9306 /* Scrollbar shadow colors. */
9307 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9308 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9309 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9310 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9311 #endif /* USE_TOOLKIT_SCROLL_BARS */
9312 if (f
->output_data
.x
->white_relief
.allocated_p
)
9313 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9314 if (f
->output_data
.x
->black_relief
.allocated_p
)
9315 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9318 XFlush (FRAME_X_DISPLAY (f
));
9321 xfree (f
->output_data
.x
->saved_menu_event
);
9322 xfree (f
->output_data
.x
);
9323 f
->output_data
.x
= NULL
;
9325 if (f
== dpyinfo
->x_focus_frame
)
9326 dpyinfo
->x_focus_frame
= 0;
9327 if (f
== dpyinfo
->x_focus_event_frame
)
9328 dpyinfo
->x_focus_event_frame
= 0;
9329 if (f
== dpyinfo
->x_highlight_frame
)
9330 dpyinfo
->x_highlight_frame
= 0;
9332 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9334 dpyinfo
->mouse_face_beg_row
9335 = dpyinfo
->mouse_face_beg_col
= -1;
9336 dpyinfo
->mouse_face_end_row
9337 = dpyinfo
->mouse_face_end_col
= -1;
9338 dpyinfo
->mouse_face_window
= Qnil
;
9339 dpyinfo
->mouse_face_deferred_gc
= 0;
9340 dpyinfo
->mouse_face_mouse_frame
= 0;
9347 /* Destroy the X window of frame F. */
9350 x_destroy_window (struct frame
*f
)
9352 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9354 /* If a display connection is dead, don't try sending more
9355 commands to the X server. */
9356 if (dpyinfo
->display
!= 0)
9357 x_free_frame_resources (f
);
9359 dpyinfo
->reference_count
--;
9363 /* Setting window manager hints. */
9365 /* Set the normal size hints for the window manager, for frame F.
9366 FLAGS is the flags word to use--or 0 meaning preserve the flags
9367 that the window now has.
9368 If USER_POSITION is nonzero, we set the USPosition
9369 flag (this is useful when FLAGS is 0).
9370 The GTK version is in gtkutils.c */
9374 x_wm_set_size_hint (struct frame
*f
, long flags
, int user_position
)
9376 XSizeHints size_hints
;
9377 Window window
= FRAME_OUTER_WINDOW (f
);
9379 /* Setting PMaxSize caused various problems. */
9380 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9382 size_hints
.x
= f
->left_pos
;
9383 size_hints
.y
= f
->top_pos
;
9385 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9386 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9388 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9389 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9390 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9391 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9392 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9393 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9395 /* Calculate the base and minimum sizes. */
9397 int base_width
, base_height
;
9398 int min_rows
= 0, min_cols
= 0;
9400 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9401 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9403 check_frame_size (f
, &min_rows
, &min_cols
);
9405 /* The window manager uses the base width hints to calculate the
9406 current number of rows and columns in the frame while
9407 resizing; min_width and min_height aren't useful for this
9408 purpose, since they might not give the dimensions for a
9409 zero-row, zero-column frame.
9411 We use the base_width and base_height members if we have
9412 them; otherwise, we set the min_width and min_height members
9413 to the size for a zero x zero frame. */
9415 size_hints
.flags
|= PBaseSize
;
9416 size_hints
.base_width
= base_width
;
9417 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9418 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9419 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9422 /* If we don't need the old flags, we don't need the old hint at all. */
9425 size_hints
.flags
|= flags
;
9430 XSizeHints hints
; /* Sometimes I hate X Windows... */
9431 long supplied_return
;
9434 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9438 size_hints
.flags
|= flags
;
9443 if (hints
.flags
& PSize
)
9444 size_hints
.flags
|= PSize
;
9445 if (hints
.flags
& PPosition
)
9446 size_hints
.flags
|= PPosition
;
9447 if (hints
.flags
& USPosition
)
9448 size_hints
.flags
|= USPosition
;
9449 if (hints
.flags
& USSize
)
9450 size_hints
.flags
|= USSize
;
9457 size_hints
.win_gravity
= f
->win_gravity
;
9458 size_hints
.flags
|= PWinGravity
;
9462 size_hints
.flags
&= ~ PPosition
;
9463 size_hints
.flags
|= USPosition
;
9465 #endif /* PWinGravity */
9467 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9469 #endif /* not USE_GTK */
9471 /* Used for IconicState or NormalState */
9474 x_wm_set_window_state (struct frame
*f
, int state
)
9476 #ifdef USE_X_TOOLKIT
9479 XtSetArg (al
[0], XtNinitialState
, state
);
9480 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9481 #else /* not USE_X_TOOLKIT */
9482 Window window
= FRAME_X_WINDOW (f
);
9484 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9485 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9487 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9488 #endif /* not USE_X_TOOLKIT */
9492 x_wm_set_icon_pixmap (struct frame
*f
, int pixmap_id
)
9494 Pixmap icon_pixmap
, icon_mask
;
9496 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9497 Window window
= FRAME_OUTER_WINDOW (f
);
9502 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9503 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9504 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9505 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9509 /* It seems there is no way to turn off use of an icon
9517 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9521 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9525 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9526 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9527 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9528 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9531 #else /* not USE_X_TOOLKIT && not USE_GTK */
9533 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9534 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9536 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9540 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9542 Window window
= FRAME_OUTER_WINDOW (f
);
9544 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9545 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9546 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9548 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9552 /***********************************************************************
9554 ***********************************************************************/
9558 /* Check that FONT is valid on frame F. It is if it can be found in F's
9562 x_check_font (struct frame
*f
, struct font
*font
)
9566 xassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9567 if (font
->driver
->check
)
9568 xassert (font
->driver
->check (f
, font
) == 0);
9571 #endif /* GLYPH_DEBUG != 0 */
9574 /***********************************************************************
9576 ***********************************************************************/
9578 #ifdef USE_X_TOOLKIT
9579 static XrmOptionDescRec emacs_options
[] = {
9580 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9581 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9583 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9584 XrmoptionSepArg
, NULL
},
9585 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9587 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9588 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9589 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9590 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9591 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9592 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9593 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9596 /* Whether atimer for Xt timeouts is activated or not. */
9598 static int x_timeout_atimer_activated_flag
;
9600 #endif /* USE_X_TOOLKIT */
9602 static int x_initialized
;
9605 static int x_session_initialized
;
9608 /* Test whether two display-name strings agree up to the dot that separates
9609 the screen number from the server number. */
9611 same_x_server (const char *name1
, const char *name2
)
9614 const unsigned char *system_name
= SDATA (Vsystem_name
);
9615 int system_name_length
= strlen (system_name
);
9616 int length_until_period
= 0;
9618 while (system_name
[length_until_period
] != 0
9619 && system_name
[length_until_period
] != '.')
9620 length_until_period
++;
9622 /* Treat `unix' like an empty host name. */
9623 if (! strncmp (name1
, "unix:", 5))
9625 if (! strncmp (name2
, "unix:", 5))
9627 /* Treat this host's name like an empty host name. */
9628 if (! strncmp (name1
, system_name
, system_name_length
)
9629 && name1
[system_name_length
] == ':')
9630 name1
+= system_name_length
;
9631 if (! strncmp (name2
, system_name
, system_name_length
)
9632 && name2
[system_name_length
] == ':')
9633 name2
+= system_name_length
;
9634 /* Treat this host's domainless name like an empty host name. */
9635 if (! strncmp (name1
, system_name
, length_until_period
)
9636 && name1
[length_until_period
] == ':')
9637 name1
+= length_until_period
;
9638 if (! strncmp (name2
, system_name
, length_until_period
)
9639 && name2
[length_until_period
] == ':')
9640 name2
+= length_until_period
;
9642 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9646 if (seen_colon
&& *name1
== '.')
9650 && (*name1
== '.' || *name1
== '\0')
9651 && (*name2
== '.' || *name2
== '\0'));
9654 /* Count number of set bits in mask and number of bits to shift to
9655 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9658 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9679 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9680 But don't permanently open it, just test its availability. */
9683 x_display_ok (const char *display
)
9688 dpy
= XOpenDisplay (display
);
9690 XCloseDisplay (dpy
);
9698 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
, const gchar
*message
, gpointer user_data
)
9700 if (!strstr (message
, "g_set_prgname"))
9701 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, message
);
9705 /* Open a connection to X display DISPLAY_NAME, and return
9706 the structure that describes the open display.
9707 If we cannot contact the display, return null. */
9709 struct x_display_info
*
9710 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9714 struct terminal
*terminal
;
9715 struct x_display_info
*dpyinfo
;
9726 if (! x_display_ok (SDATA (display_name
)))
9727 error ("Display %s can't be opened", SDATA (display_name
));
9733 char *argv
[NUM_ARGV
];
9734 char **argv2
= argv
;
9737 if (x_initialized
++ > 1)
9739 xg_display_open (SDATA (display_name
), &dpy
);
9743 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9747 argv
[argc
++] = initial_argv
[0];
9749 if (! NILP (display_name
))
9751 argv
[argc
++] = "--display";
9752 argv
[argc
++] = SDATA (display_name
);
9755 argv
[argc
++] = "--name";
9756 argv
[argc
++] = resource_name
;
9758 XSetLocaleModifiers ("");
9760 /* Work around GLib bug that outputs a faulty warning. See
9761 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9762 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9763 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9764 gtk_init (&argc
, &argv2
);
9765 g_log_remove_handler ("GLib", id
);
9767 /* gtk_init does set_locale. We must fix locale after calling it. */
9771 dpy
= GDK_DISPLAY ();
9773 /* NULL window -> events for all windows go to our function */
9774 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9776 /* Load our own gtkrc if it exists. */
9778 char *file
= "~/.emacs.d/gtkrc";
9779 Lisp_Object s
, abs_file
;
9781 s
= make_string (file
, strlen (file
));
9782 abs_file
= Fexpand_file_name (s
, Qnil
);
9784 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
9785 gtk_rc_parse (SDATA (abs_file
));
9788 XSetErrorHandler (x_error_handler
);
9789 XSetIOErrorHandler (x_io_error_quitter
);
9792 #else /* not USE_GTK */
9793 #ifdef USE_X_TOOLKIT
9794 /* weiner@footloose.sps.mot.com reports that this causes
9796 X protocol error: BadAtom (invalid Atom parameter)
9797 on protocol request 18skiloaf.
9798 So let's not use it until R6. */
9800 XtSetLanguageProc (NULL
, NULL
, NULL
);
9811 argv
[argc
++] = "-xrm";
9812 argv
[argc
++] = xrm_option
;
9814 turn_on_atimers (0);
9815 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
9816 resource_name
, EMACS_CLASS
,
9817 emacs_options
, XtNumber (emacs_options
),
9819 turn_on_atimers (1);
9822 /* I think this is to compensate for XtSetLanguageProc. */
9827 #else /* not USE_X_TOOLKIT */
9828 XSetLocaleModifiers ("");
9829 dpy
= XOpenDisplay (SDATA (display_name
));
9830 #endif /* not USE_X_TOOLKIT */
9831 #endif /* not USE_GTK*/
9833 /* Detect failure. */
9840 /* We have definitely succeeded. Record the new connection. */
9842 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
9843 memset (dpyinfo
, 0, sizeof *dpyinfo
);
9845 terminal
= x_create_terminal (dpyinfo
);
9848 struct x_display_info
*share
;
9851 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
9852 share
= share
->next
, tail
= XCDR (tail
))
9853 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
9854 SDATA (display_name
)))
9857 terminal
->kboard
= share
->terminal
->kboard
;
9860 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
9861 init_kboard (terminal
->kboard
);
9862 terminal
->kboard
->Vwindow_system
= Qx
;
9864 /* Add the keyboard to the list before running Lisp code (via
9865 Qvendor_specific_keysyms below), since these are not traced
9866 via terminals but only through all_kboards. */
9867 terminal
->kboard
->next_kboard
= all_kboards
;
9868 all_kboards
= terminal
->kboard
;
9870 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
9872 char *vendor
= ServerVendor (dpy
);
9874 /* Protect terminal from GC before removing it from the
9875 list of terminals. */
9876 struct gcpro gcpro1
;
9877 Lisp_Object gcpro_term
;
9878 XSETTERMINAL (gcpro_term
, terminal
);
9879 GCPRO1 (gcpro_term
);
9881 /* Temporarily hide the partially initialized terminal. */
9882 terminal_list
= terminal
->next_terminal
;
9884 terminal
->kboard
->Vsystem_key_alist
9885 = call1 (Qvendor_specific_keysyms
,
9886 vendor
? build_string (vendor
) : empty_unibyte_string
);
9888 terminal
->next_terminal
= terminal_list
;
9889 terminal_list
= terminal
;
9893 /* Don't let the initial kboard remain current longer than necessary.
9894 That would cause problems if a file loaded on startup tries to
9895 prompt in the mini-buffer. */
9896 if (current_kboard
== initial_kboard
)
9897 current_kboard
= terminal
->kboard
;
9899 terminal
->kboard
->reference_count
++;
9902 /* Put this display on the chain. */
9903 dpyinfo
->next
= x_display_list
;
9904 x_display_list
= dpyinfo
;
9906 /* Put it on x_display_name_list as well, to keep them parallel. */
9907 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
9908 x_display_name_list
);
9909 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
9911 dpyinfo
->display
= dpy
;
9913 /* Set the name of the terminal. */
9914 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
9915 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
9916 terminal
->name
[SBYTES (display_name
)] = 0;
9919 XSetAfterFunction (x_current_display
, x_trace_wire
);
9923 = (char *) xmalloc (SBYTES (Vinvocation_name
)
9924 + SBYTES (Vsystem_name
)
9926 sprintf (dpyinfo
->x_id_name
, "%s@%s",
9927 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
9929 /* Figure out which modifier bits mean what. */
9930 x_find_modifier_meanings (dpyinfo
);
9932 /* Get the scroll bar cursor. */
9934 /* We must create a GTK cursor, it is required for GTK widgets. */
9935 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
9936 #endif /* USE_GTK */
9938 dpyinfo
->vertical_scroll_bar_cursor
9939 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
9941 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
9942 resource_name
, EMACS_CLASS
);
9943 #ifdef HAVE_XRMSETDATABASE
9944 XrmSetDatabase (dpyinfo
->display
, xrdb
);
9946 dpyinfo
->display
->db
= xrdb
;
9948 /* Put the rdb where we can find it in a way that works on
9950 dpyinfo
->xrdb
= xrdb
;
9952 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
9953 DefaultScreen (dpyinfo
->display
));
9954 select_visual (dpyinfo
);
9955 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
9956 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
9957 dpyinfo
->client_leader_window
= 0;
9958 dpyinfo
->grabbed
= 0;
9959 dpyinfo
->reference_count
= 0;
9960 dpyinfo
->icon_bitmap_id
= -1;
9961 dpyinfo
->n_fonts
= 0;
9962 dpyinfo
->bitmaps
= 0;
9963 dpyinfo
->bitmaps_size
= 0;
9964 dpyinfo
->bitmaps_last
= 0;
9965 dpyinfo
->scratch_cursor_gc
= 0;
9966 dpyinfo
->mouse_face_mouse_frame
= 0;
9967 dpyinfo
->mouse_face_deferred_gc
= 0;
9968 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
9969 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
9970 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
9971 dpyinfo
->mouse_face_window
= Qnil
;
9972 dpyinfo
->mouse_face_overlay
= Qnil
;
9973 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
9974 dpyinfo
->mouse_face_defer
= 0;
9975 dpyinfo
->mouse_face_hidden
= 0;
9976 dpyinfo
->x_focus_frame
= 0;
9977 dpyinfo
->x_focus_event_frame
= 0;
9978 dpyinfo
->x_highlight_frame
= 0;
9979 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
9981 /* See if we can construct pixel values from RGB values. */
9982 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
9983 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
9985 if (dpyinfo
->visual
->class == TrueColor
)
9987 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
9988 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
9989 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
9990 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
9991 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
9992 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
9995 /* See if a private colormap is requested. */
9996 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
9998 if (dpyinfo
->visual
->class == PseudoColor
)
10001 value
= display_x_get_resource (dpyinfo
,
10002 build_string ("privateColormap"),
10003 build_string ("PrivateColormap"),
10005 if (STRINGP (value
)
10006 && (!strcmp (SDATA (value
), "true")
10007 || !strcmp (SDATA (value
), "on")))
10008 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10012 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10013 dpyinfo
->visual
, AllocNone
);
10017 /* If we are using Xft, check dpi value in X resources.
10018 It is better we use it as well, since Xft will use it, as will all
10019 Gnome applications. If our real DPI is smaller or larger than the
10020 one Xft uses, our font will look smaller or larger than other
10021 for other applications, even if it is the same font name (monospace-10
10023 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10025 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10026 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10030 if (dpyinfo
->resy
< 1)
10032 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10033 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10034 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10035 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10036 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10037 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10038 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10039 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10040 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10043 dpyinfo
->Xatom_wm_protocols
10044 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10045 dpyinfo
->Xatom_wm_take_focus
10046 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10047 dpyinfo
->Xatom_wm_save_yourself
10048 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10049 dpyinfo
->Xatom_wm_delete_window
10050 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10051 dpyinfo
->Xatom_wm_change_state
10052 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10053 dpyinfo
->Xatom_wm_configure_denied
10054 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10055 dpyinfo
->Xatom_wm_window_moved
10056 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10057 dpyinfo
->Xatom_wm_client_leader
10058 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10059 dpyinfo
->Xatom_editres
10060 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10061 dpyinfo
->Xatom_CLIPBOARD
10062 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10063 dpyinfo
->Xatom_TIMESTAMP
10064 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10065 dpyinfo
->Xatom_TEXT
10066 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10067 dpyinfo
->Xatom_COMPOUND_TEXT
10068 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10069 dpyinfo
->Xatom_UTF8_STRING
10070 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10071 dpyinfo
->Xatom_DELETE
10072 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10073 dpyinfo
->Xatom_MULTIPLE
10074 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10075 dpyinfo
->Xatom_INCR
10076 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10077 dpyinfo
->Xatom_EMACS_TMP
10078 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10079 dpyinfo
->Xatom_TARGETS
10080 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10081 dpyinfo
->Xatom_NULL
10082 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10083 dpyinfo
->Xatom_ATOM_PAIR
10084 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10085 /* For properties of font. */
10086 dpyinfo
->Xatom_PIXEL_SIZE
10087 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10088 dpyinfo
->Xatom_AVERAGE_WIDTH
10089 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10090 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10091 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10092 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10093 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10094 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10095 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10097 /* Ghostscript support. */
10098 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10099 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10101 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10104 dpyinfo
->Xatom_XEMBED
= XInternAtom (dpyinfo
->display
, "_XEMBED",
10107 dpyinfo
->Xatom_net_wm_state
10108 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE", False
);
10109 dpyinfo
->Xatom_net_wm_state_fullscreen_atom
10110 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_FULLSCREEN", False
);
10111 dpyinfo
->Xatom_net_wm_state_maximized_horz
10112 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_HORZ", False
);
10113 dpyinfo
->Xatom_net_wm_state_maximized_vert
10114 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_VERT", False
);
10115 dpyinfo
->Xatom_net_wm_state_sticky
10116 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_STICKY", False
);
10117 dpyinfo
->Xatom_net_window_type
10118 = XInternAtom (dpyinfo
->display
, "_NET_WM_WINDOW_TYPE", False
);
10119 dpyinfo
->Xatom_net_window_type_tooltip
10120 = XInternAtom (dpyinfo
->display
, "_NET_WM_WINDOW_TYPE_TOOLTIP", False
);
10121 dpyinfo
->Xatom_net_wm_icon_name
10122 = XInternAtom (dpyinfo
->display
, "_NET_WM_ICON_NAME", False
);
10123 dpyinfo
->Xatom_net_wm_name
10124 = XInternAtom (dpyinfo
->display
, "_NET_WM_NAME", False
);
10126 dpyinfo
->cut_buffers_initialized
= 0;
10128 dpyinfo
->x_dnd_atoms_size
= 8;
10129 dpyinfo
->x_dnd_atoms_length
= 0;
10130 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
10131 * dpyinfo
->x_dnd_atoms_size
);
10133 dpyinfo
->net_supported_atoms
= NULL
;
10134 dpyinfo
->nr_net_supported_atoms
= 0;
10135 dpyinfo
->net_supported_window
= 0;
10137 connection
= ConnectionNumber (dpyinfo
->display
);
10138 dpyinfo
->connection
= connection
;
10142 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10144 gray_bitmap_width
, gray_bitmap_height
,
10145 (unsigned long) 1, (unsigned long) 0, 1);
10149 xim_initialize (dpyinfo
, resource_name
);
10152 xsettings_initialize (dpyinfo
);
10154 /* This is only needed for distinguishing keyboard and process input. */
10155 if (connection
!= 0)
10156 add_keyboard_wait_descriptor (connection
);
10159 fcntl (connection
, F_SETOWN
, getpid ());
10160 #endif /* ! defined (F_SETOWN) */
10163 if (interrupt_input
)
10164 init_sigio (connection
);
10165 #endif /* ! defined (SIGIO) */
10169 Display
*dpy
= dpyinfo
->display
;
10170 XrmValue d
, fr
, to
;
10173 d
.addr
= (XPointer
)&dpy
;
10174 d
.size
= sizeof (Display
*);
10175 fr
.addr
= XtDefaultFont
;
10176 fr
.size
= sizeof (XtDefaultFont
);
10177 to
.size
= sizeof (Font
*);
10178 to
.addr
= (XPointer
)&font
;
10179 x_catch_errors (dpy
);
10180 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10182 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10183 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10184 x_uncatch_errors ();
10188 /* See if we should run in synchronous mode. This is useful
10189 for debugging X code. */
10192 value
= display_x_get_resource (dpyinfo
,
10193 build_string ("synchronous"),
10194 build_string ("Synchronous"),
10196 if (STRINGP (value
)
10197 && (!strcmp (SDATA (value
), "true")
10198 || !strcmp (SDATA (value
), "on")))
10199 XSynchronize (dpyinfo
->display
, True
);
10204 value
= display_x_get_resource (dpyinfo
,
10205 build_string ("useXIM"),
10206 build_string ("UseXIM"),
10209 if (STRINGP (value
)
10210 && (!strcmp (SDATA (value
), "false")
10211 || !strcmp (SDATA (value
), "off")))
10214 if (STRINGP (value
)
10215 && (!strcmp (SDATA (value
), "true")
10216 || !strcmp (SDATA (value
), "on")))
10222 /* Only do this for the very first display in the Emacs session.
10223 Ignore X session management when Emacs was first started on a
10225 if (terminal
->id
== 1)
10226 x_session_initialize (dpyinfo
);
10234 /* Get rid of display DPYINFO, deleting all frames on it,
10235 and without sending any more commands to the X server. */
10238 x_delete_display (struct x_display_info
*dpyinfo
)
10240 struct terminal
*t
;
10242 /* Close all frames and delete the generic struct terminal for this
10244 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10245 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10248 /* Close X session management when we close its display. */
10249 if (t
->id
== 1 && x_session_have_connection ())
10250 x_session_close ();
10252 delete_terminal (t
);
10256 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10258 /* Discard this display from x_display_name_list and x_display_list.
10259 We can't use Fdelq because that can quit. */
10260 if (! NILP (x_display_name_list
)
10261 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10262 x_display_name_list
= XCDR (x_display_name_list
);
10267 tail
= x_display_name_list
;
10268 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10270 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10272 XSETCDR (tail
, XCDR (XCDR (tail
)));
10275 tail
= XCDR (tail
);
10279 if (next_noop_dpyinfo
== dpyinfo
)
10280 next_noop_dpyinfo
= dpyinfo
->next
;
10282 if (x_display_list
== dpyinfo
)
10283 x_display_list
= dpyinfo
->next
;
10286 struct x_display_info
*tail
;
10288 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10289 if (tail
->next
== dpyinfo
)
10290 tail
->next
= tail
->next
->next
;
10293 xfree (dpyinfo
->x_id_name
);
10294 xfree (dpyinfo
->x_dnd_atoms
);
10295 xfree (dpyinfo
->color_cells
);
10299 #ifdef USE_X_TOOLKIT
10301 /* Atimer callback function for TIMER. Called every 0.1s to process
10302 Xt timeouts, if needed. We must avoid calling XtAppPending as
10303 much as possible because that function does an implicit XFlush
10304 that slows us down. */
10307 x_process_timeouts (struct atimer
*timer
)
10310 x_timeout_atimer_activated_flag
= 0;
10311 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10313 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10314 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10315 /* Reactivate the atimer for next time. */
10316 x_activate_timeout_atimer ();
10321 /* Install an asynchronous timer that processes Xt timeout events
10322 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10323 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10324 function whenever these variables are set. This is necessary
10325 because some widget sets use timeouts internally, for example the
10326 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10327 processed, these widgets don't behave normally. */
10330 x_activate_timeout_atimer (void)
10333 if (!x_timeout_atimer_activated_flag
)
10335 EMACS_TIME interval
;
10337 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10338 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10339 x_timeout_atimer_activated_flag
= 1;
10344 #endif /* USE_X_TOOLKIT */
10347 /* Set up use of X before we make the first connection. */
10349 extern frame_parm_handler x_frame_parm_handlers
[];
10351 static struct redisplay_interface x_redisplay_interface
=
10353 x_frame_parm_handlers
,
10357 x_clear_end_of_line
,
10359 x_after_update_window_line
,
10360 x_update_window_begin
,
10361 x_update_window_end
,
10367 0, /* flush_display_optional */
10369 x_clear_window_mouse_face
,
10370 x_get_glyph_overhangs
,
10371 x_fix_overlapping_area
,
10372 x_draw_fringe_bitmap
,
10373 0, /* define_fringe_bitmap */
10374 0, /* destroy_fringe_bitmap */
10375 x_compute_glyph_string_overhangs
,
10376 x_draw_glyph_string
,
10377 x_define_frame_cursor
,
10378 x_clear_frame_area
,
10379 x_draw_window_cursor
,
10380 x_draw_vertical_window_border
,
10381 x_shift_glyphs_for_insert
10385 /* This function is called when the last frame on a display is deleted. */
10387 x_delete_terminal (struct terminal
*terminal
)
10389 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10391 /* Protect against recursive calls. delete_frame in
10392 delete_terminal calls us back when it deletes our last frame. */
10393 if (!terminal
->name
)
10398 /* We must close our connection to the XIM server before closing the
10401 xim_close_dpy (dpyinfo
);
10404 /* If called from x_connection_closed, the display may already be closed
10405 and dpyinfo->display was set to 0 to indicate that. */
10406 if (dpyinfo
->display
)
10408 x_destroy_all_bitmaps (dpyinfo
);
10409 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10411 /* Whether or not XCloseDisplay destroys the associated resource
10412 database depends on the version of libX11. To avoid both
10413 crash and memory leak, we dissociate the database from the
10414 display and then destroy dpyinfo->xrdb ourselves.
10416 Unfortunately, the above strategy does not work in some
10417 situations due to a bug in newer versions of libX11: because
10418 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10419 dpy->db is NULL, XCloseDisplay destroys the associated
10420 database whereas it has not been created by XGetDefault
10421 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10422 don't destroy the database here in order to avoid the crash
10423 in the above situations for now, though that may cause memory
10424 leaks in other situations. */
10426 #ifdef HAVE_XRMSETDATABASE
10427 XrmSetDatabase (dpyinfo
->display
, NULL
);
10429 dpyinfo
->display
->db
= NULL
;
10431 /* We used to call XrmDestroyDatabase from x_delete_display, but
10432 some older versions of libX11 crash if we call it after
10433 closing all the displays. */
10434 XrmDestroyDatabase (dpyinfo
->xrdb
);
10438 xg_display_close (dpyinfo
->display
);
10440 #ifdef USE_X_TOOLKIT
10441 XtCloseDisplay (dpyinfo
->display
);
10443 XCloseDisplay (dpyinfo
->display
);
10445 #endif /* ! USE_GTK */
10448 /* Mark as dead. */
10449 dpyinfo
->display
= NULL
;
10450 x_delete_display (dpyinfo
);
10454 /* Create a struct terminal, initialize it with the X11 specific
10455 functions and make DISPLAY->TERMINAL point to it. */
10457 static struct terminal
*
10458 x_create_terminal (struct x_display_info
*dpyinfo
)
10460 struct terminal
*terminal
;
10462 terminal
= create_terminal ();
10464 terminal
->type
= output_x_window
;
10465 terminal
->display_info
.x
= dpyinfo
;
10466 dpyinfo
->terminal
= terminal
;
10468 /* kboard is initialized in x_term_init. */
10470 terminal
->clear_frame_hook
= x_clear_frame
;
10471 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10472 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10473 terminal
->ring_bell_hook
= XTring_bell
;
10474 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10475 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10476 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
10477 terminal
->update_begin_hook
= x_update_begin
;
10478 terminal
->update_end_hook
= x_update_end
;
10479 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
10480 terminal
->read_socket_hook
= XTread_socket
;
10481 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10482 terminal
->mouse_position_hook
= XTmouse_position
;
10483 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10484 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10485 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10486 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10487 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10488 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10489 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10491 terminal
->delete_frame_hook
= x_destroy_window
;
10492 terminal
->delete_terminal_hook
= x_delete_terminal
;
10494 terminal
->rif
= &x_redisplay_interface
;
10495 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10496 terminal
->char_ins_del_ok
= 1;
10497 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10498 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10499 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10506 x_initialize (void)
10511 last_tool_bar_item
= -1;
10512 any_help_event_p
= 0;
10513 ignore_next_mouse_click_timeout
= 0;
10515 x_session_initialized
= 0;
10519 current_count
= -1;
10522 /* Try to use interrupt input; if we can't, then start polling. */
10523 Fset_input_interrupt_mode (Qt
);
10525 #ifdef USE_X_TOOLKIT
10526 XtToolkitInitialize ();
10528 Xt_app_con
= XtCreateApplicationContext ();
10530 /* Register a converter from strings to pixels, which uses
10531 Emacs' color allocation infrastructure. */
10532 XtAppSetTypeConverter (Xt_app_con
,
10533 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10534 cvt_string_to_pixel_args
,
10535 XtNumber (cvt_string_to_pixel_args
),
10536 XtCacheByDisplay
, cvt_pixel_dtor
);
10538 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10541 #ifdef USE_TOOLKIT_SCROLL_BARS
10543 xaw3d_arrow_scroll
= False
;
10544 xaw3d_pick_top
= True
;
10548 pending_autoraise_frame
= 0;
10549 pending_event_wait
.f
= 0;
10550 pending_event_wait
.eventtype
= 0;
10552 /* Note that there is no real way portable across R3/R4 to get the
10553 original error handler. */
10554 XSetErrorHandler (x_error_handler
);
10555 XSetIOErrorHandler (x_io_error_quitter
);
10557 signal (SIGPIPE
, x_connection_signal
);
10559 xgselect_initialize ();
10564 syms_of_xterm (void)
10566 x_error_message
= NULL
;
10568 staticpro (&x_display_name_list
);
10569 x_display_name_list
= Qnil
;
10571 staticpro (&last_mouse_scroll_bar
);
10572 last_mouse_scroll_bar
= Qnil
;
10574 staticpro (&Qvendor_specific_keysyms
);
10575 Qvendor_specific_keysyms
= intern_c_string ("vendor-specific-keysyms");
10577 staticpro (&Qlatin_1
);
10578 Qlatin_1
= intern_c_string ("latin-1");
10580 staticpro (&last_mouse_press_frame
);
10581 last_mouse_press_frame
= Qnil
;
10584 xg_default_icon_file
= make_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10585 staticpro (&xg_default_icon_file
);
10587 Qx_gtk_map_stock
= intern_c_string ("x-gtk-map-stock");
10588 staticpro (&Qx_gtk_map_stock
);
10591 DEFVAR_BOOL ("x-use-underline-position-properties",
10592 &x_use_underline_position_properties
,
10593 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10594 A value of nil means ignore them. If you encounter fonts with bogus
10595 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10596 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10597 to override the font's UNDERLINE_POSITION for small font display
10599 x_use_underline_position_properties
= 1;
10601 DEFVAR_BOOL ("x-underline-at-descent-line",
10602 &x_underline_at_descent_line
,
10603 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
10604 A value of nil means to draw the underline according to the value of the
10605 variable `x-use-underline-position-properties', which is usually at the
10606 baseline level. The default value is nil. */);
10607 x_underline_at_descent_line
= 0;
10609 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10610 &x_mouse_click_focus_ignore_position
,
10611 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10612 This variable is only used when the window manager requires that you
10613 click on a frame to select it (give it focus). In that case, a value
10614 of nil, means that the selected window and cursor position changes to
10615 reflect the mouse click position, while a non-nil value means that the
10616 selected window or cursor position is preserved. */);
10617 x_mouse_click_focus_ignore_position
= 0;
10619 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10620 doc
: /* What X toolkit scroll bars Emacs uses.
10621 A value of nil means Emacs doesn't use X toolkit scroll bars.
10622 Otherwise, value is a symbol describing the X toolkit. */);
10623 #ifdef USE_TOOLKIT_SCROLL_BARS
10625 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10626 #elif defined HAVE_XAW3D
10627 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10629 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10631 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10634 Vx_toolkit_scroll_bars
= Qnil
;
10637 staticpro (&last_mouse_motion_frame
);
10638 last_mouse_motion_frame
= Qnil
;
10640 Qmodifier_value
= intern_c_string ("modifier-value");
10641 Qalt
= intern_c_string ("alt");
10642 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10643 Qhyper
= intern_c_string ("hyper");
10644 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10645 Qmeta
= intern_c_string ("meta");
10646 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10647 Qsuper
= intern_c_string ("super");
10648 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10650 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10651 doc
: /* Which keys Emacs uses for the alt modifier.
10652 This should be one of the symbols `alt', `hyper', `meta', `super'.
10653 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10654 is nil, which is the same as `alt'. */);
10655 Vx_alt_keysym
= Qnil
;
10657 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10658 doc
: /* Which keys Emacs uses for the hyper modifier.
10659 This should be one of the symbols `alt', `hyper', `meta', `super'.
10660 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10661 default is nil, which is the same as `hyper'. */);
10662 Vx_hyper_keysym
= Qnil
;
10664 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10665 doc
: /* Which keys Emacs uses for the meta modifier.
10666 This should be one of the symbols `alt', `hyper', `meta', `super'.
10667 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10668 default is nil, which is the same as `meta'. */);
10669 Vx_meta_keysym
= Qnil
;
10671 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10672 doc
: /* Which keys Emacs uses for the super modifier.
10673 This should be one of the symbols `alt', `hyper', `meta', `super'.
10674 For example, `super' means use the Super_L and Super_R keysyms. The
10675 default is nil, which is the same as `super'. */);
10676 Vx_super_keysym
= Qnil
;
10678 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10679 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10680 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10681 make_float (DEFAULT_REHASH_SIZE
),
10682 make_float (DEFAULT_REHASH_THRESHOLD
),
10686 #endif /* HAVE_X_WINDOWS */
10688 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
10689 (do not change this comment) */