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 extern int xlwmenu_window_p (Widget w
, Window window
);
108 extern void xlwmenu_redisplay (Widget
);
111 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
113 extern void free_frame_menubar (struct frame
*);
117 #if !defined(NO_EDITRES)
119 extern void _XEditResCheckMessages ();
120 #endif /* not NO_EDITRES */
122 /* Include toolkit specific headers for the scroll bar widget. */
124 #ifdef USE_TOOLKIT_SCROLL_BARS
125 #if defined USE_MOTIF
126 #include <Xm/Xm.h> /* for LESSTIF_VERSION */
127 #include <Xm/ScrollBar.h>
128 #else /* !USE_MOTIF i.e. use Xaw */
131 #include <X11/Xaw3d/Simple.h>
132 #include <X11/Xaw3d/Scrollbar.h>
133 #include <X11/Xaw3d/ThreeD.h>
134 #else /* !HAVE_XAW3D */
135 #include <X11/Xaw/Simple.h>
136 #include <X11/Xaw/Scrollbar.h>
137 #endif /* !HAVE_XAW3D */
139 #define XtNpickTop "pickTop"
140 #endif /* !XtNpickTop */
141 #endif /* !USE_MOTIF */
142 #endif /* USE_TOOLKIT_SCROLL_BARS */
144 #endif /* USE_X_TOOLKIT */
148 #ifndef XtNinitialState
149 #define XtNinitialState "initialState"
153 /* Default to using XIM if available. */
157 int use_xim
= 0; /* configure --without-xim */
162 /* Non-nil means Emacs uses toolkit scroll bars. */
164 Lisp_Object Vx_toolkit_scroll_bars
;
166 /* Non-zero means that a HELP_EVENT has been generated since Emacs
169 static int any_help_event_p
;
171 /* Last window where we saw the mouse. Used by mouse-autoselect-window. */
172 static Lisp_Object last_window
;
174 /* Non-zero means make use of UNDERLINE_POSITION font properties. */
176 int x_use_underline_position_properties
;
178 /* Non-zero means to draw the underline at the same place as the descent line. */
180 int x_underline_at_descent_line
;
182 /* This is a chain of structures for all the X displays currently in
185 struct x_display_info
*x_display_list
;
187 /* This is a list of cons cells, each of the form (NAME
188 . FONT-LIST-CACHE), one for each element of x_display_list and in
189 the same order. NAME is the name of the frame. FONT-LIST-CACHE
190 records previous values returned by x-list-fonts. */
192 Lisp_Object x_display_name_list
;
194 /* Frame being updated by update_frame. This is declared in term.c.
195 This is set by update_begin and looked at by all the XT functions.
196 It is zero while not inside an update. In that case, the XT
197 functions assume that `selected_frame' is the frame to apply to. */
199 extern struct frame
*updating_frame
;
201 /* This is a frame waiting to be auto-raised, within XTread_socket. */
203 static struct frame
*pending_autoraise_frame
;
205 /* This is a frame waiting for an event matching mask, within XTread_socket. */
210 } pending_event_wait
;
213 /* The application context for Xt use. */
214 XtAppContext Xt_app_con
;
215 static String Xt_default_resources
[] = {0};
216 #endif /* USE_X_TOOLKIT */
218 /* Non-zero means user is interacting with a toolkit scroll bar. */
220 static int toolkit_scroll_bar_interaction
;
222 /* Non-zero means to not move point as a result of clicking on a
223 frame to focus it (when focus-follows-mouse is nil). */
225 int x_mouse_click_focus_ignore_position
;
227 /* Non-zero timeout value means ignore next mouse click if it arrives
228 before that timeout elapses (i.e. as part of the same sequence of
229 events resulting from clicking on a frame to select it). */
231 static unsigned long ignore_next_mouse_click_timeout
;
235 Formerly, we used PointerMotionHintMask (in standard_event_mask)
236 so that we would have to call XQueryPointer after each MotionNotify
237 event to ask for another such event. However, this made mouse tracking
238 slow, and there was a bug that made it eventually stop.
240 Simply asking for MotionNotify all the time seems to work better.
242 In order to avoid asking for motion events and then throwing most
243 of them away or busy-polling the server for mouse positions, we ask
244 the server for pointer motion hints. This means that we get only
245 one event per group of mouse movements. "Groups" are delimited by
246 other kinds of events (focus changes and button clicks, for
247 example), or by XQueryPointer calls; when one of these happens, we
248 get another MotionNotify event the next time the mouse moves. This
249 is at least as efficient as getting motion events when mouse
250 tracking is on, and I suspect only negligibly worse when tracking
253 /* Where the mouse was last time we reported a mouse event. */
255 static XRectangle last_mouse_glyph
;
256 static FRAME_PTR last_mouse_glyph_frame
;
257 static Lisp_Object last_mouse_press_frame
;
259 /* The scroll bar in which the last X motion event occurred.
261 If the last X motion event occurred in a scroll bar, we set this so
262 XTmouse_position can know whether to report a scroll bar motion or
265 If the last X motion event didn't occur in a scroll bar, we set
266 this to Qnil, to tell XTmouse_position to return an ordinary motion
269 static Lisp_Object last_mouse_scroll_bar
;
271 /* This is a hack. We would really prefer that XTmouse_position would
272 return the time associated with the position it returns, but there
273 doesn't seem to be any way to wrest the time-stamp from the server
274 along with the position query. So, we just keep track of the time
275 of the last movement we received, and return that in hopes that
276 it's somewhat accurate. */
278 static Time last_mouse_movement_time
;
280 /* Time for last user interaction as returned in X events. */
282 static Time last_user_time
;
284 /* Incremented by XTread_socket whenever it really tries to read
288 static int volatile input_signal_count
;
290 static int input_signal_count
;
293 /* Used locally within XTread_socket. */
295 static int x_noop_count
;
297 /* Initial values of argv and argc. */
299 extern char **initial_argv
;
300 extern int initial_argc
;
302 extern Lisp_Object Vcommand_line_args
, Vsystem_name
;
304 /* Tells if a window manager is present or not. */
306 extern Lisp_Object Vx_no_window_manager
;
308 extern Lisp_Object Qeql
;
310 /* A mask of extra modifier bits to put into every keyboard char. */
312 extern EMACS_INT extra_keyboard_modifiers
;
314 /* The keysyms to use for the various modifiers. */
316 Lisp_Object Vx_alt_keysym
, Vx_hyper_keysym
, Vx_meta_keysym
, Vx_super_keysym
;
317 Lisp_Object Vx_keysym_table
;
318 static Lisp_Object Qalt
, Qhyper
, Qmeta
, Qsuper
, Qmodifier_value
;
320 static Lisp_Object Qvendor_specific_keysyms
;
321 static Lisp_Object Qlatin_1
;
324 /* The name of the Emacs icon file. */
325 static Lisp_Object xg_default_icon_file
;
327 /* Used in gtkutil.c. */
328 Lisp_Object Qx_gtk_map_stock
;
331 /* Used in x_flush. */
333 extern Lisp_Object Vinhibit_redisplay
;
335 extern XrmDatabase
x_load_resources (Display
*, char *, char *, 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
*, 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
, client_data
, call_data
)
4164 XtPointer client_data
, call_data
;
4166 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4167 XmScrollBarCallbackStruct
*cs
= (XmScrollBarCallbackStruct
*) call_data
;
4168 int part
= -1, whole
= 0, portion
= 0;
4172 case XmCR_DECREMENT
:
4173 bar
->dragging
= Qnil
;
4174 part
= scroll_bar_up_arrow
;
4177 case XmCR_INCREMENT
:
4178 bar
->dragging
= Qnil
;
4179 part
= scroll_bar_down_arrow
;
4182 case XmCR_PAGE_DECREMENT
:
4183 bar
->dragging
= Qnil
;
4184 part
= scroll_bar_above_handle
;
4187 case XmCR_PAGE_INCREMENT
:
4188 bar
->dragging
= Qnil
;
4189 part
= scroll_bar_below_handle
;
4193 bar
->dragging
= Qnil
;
4194 part
= scroll_bar_to_top
;
4197 case XmCR_TO_BOTTOM
:
4198 bar
->dragging
= Qnil
;
4199 part
= scroll_bar_to_bottom
;
4206 /* Get the slider size. */
4208 XtVaGetValues (widget
, XmNsliderSize
, &slider_size
, NULL
);
4211 whole
= XM_SB_MAX
- slider_size
;
4212 portion
= min (cs
->value
, whole
);
4213 part
= scroll_bar_handle
;
4214 bar
->dragging
= make_number (cs
->value
);
4218 case XmCR_VALUE_CHANGED
:
4224 window_being_scrolled
= bar
->window
;
4225 last_scroll_bar_part
= part
;
4226 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4230 #elif defined USE_GTK
4232 /* Scroll bar callback for GTK scroll bars. WIDGET is the scroll
4233 bar widget. DATA is a pointer to the scroll_bar structure. */
4236 xg_scroll_callback (GtkRange
*range
,
4237 GtkScrollType scroll
,
4241 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4243 int part
= -1, whole
= 0, portion
= 0;
4244 GtkAdjustment
*adj
= GTK_ADJUSTMENT (gtk_range_get_adjustment (range
));
4245 FRAME_PTR f
= (FRAME_PTR
) g_object_get_data (G_OBJECT (range
), XG_FRAME_DATA
);
4247 if (xg_ignore_gtk_scrollbar
) return FALSE
;
4248 position
= gtk_adjustment_get_value (adj
);
4253 case GTK_SCROLL_JUMP
:
4254 /* Buttons 1 2 or 3 must be grabbed. */
4255 if (FRAME_X_DISPLAY_INFO (f
)->grabbed
!= 0
4256 && FRAME_X_DISPLAY_INFO (f
)->grabbed
< (1 << 4))
4258 part
= scroll_bar_handle
;
4259 whole
= gtk_adjustment_get_upper (adj
) -
4260 gtk_adjustment_get_page_size (adj
);
4261 portion
= min ((int)position
, whole
);
4262 bar
->dragging
= make_number ((int)portion
);
4265 case GTK_SCROLL_STEP_BACKWARD
:
4266 part
= scroll_bar_up_arrow
;
4267 bar
->dragging
= Qnil
;
4269 case GTK_SCROLL_STEP_FORWARD
:
4270 part
= scroll_bar_down_arrow
;
4271 bar
->dragging
= Qnil
;
4273 case GTK_SCROLL_PAGE_BACKWARD
:
4274 part
= scroll_bar_above_handle
;
4275 bar
->dragging
= Qnil
;
4277 case GTK_SCROLL_PAGE_FORWARD
:
4278 part
= scroll_bar_below_handle
;
4279 bar
->dragging
= Qnil
;
4285 window_being_scrolled
= bar
->window
;
4286 last_scroll_bar_part
= part
;
4287 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4293 /* Callback for button release. Sets dragging to Qnil when dragging is done. */
4296 xg_end_scroll_callback (GtkWidget
*widget
,
4297 GdkEventButton
*event
,
4300 struct scroll_bar
*bar
= (struct scroll_bar
*) user_data
;
4301 bar
->dragging
= Qnil
;
4302 if (WINDOWP (window_being_scrolled
))
4304 x_send_scroll_bar_event (window_being_scrolled
,
4305 scroll_bar_end_scroll
, 0, 0);
4306 window_being_scrolled
= Qnil
;
4313 #else /* not USE_GTK and not USE_MOTIF */
4315 /* Xaw scroll bar callback. Invoked when the thumb is dragged.
4316 WIDGET is the scroll bar widget. CLIENT_DATA is a pointer to the
4317 scroll bar struct. CALL_DATA is a pointer to a float saying where
4321 xaw_jump_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4323 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4324 float top
= *(float *) call_data
;
4326 int whole
, portion
, height
;
4329 /* Get the size of the thumb, a value between 0 and 1. */
4331 XtVaGetValues (widget
, XtNshown
, &shown
, XtNheight
, &height
, NULL
);
4335 portion
= shown
< 1 ? top
* whole
: 0;
4337 if (shown
< 1 && (eabs (top
+ shown
- 1) < 1.0/height
))
4338 /* Some derivatives of Xaw refuse to shrink the thumb when you reach
4339 the bottom, so we force the scrolling whenever we see that we're
4340 too close to the bottom (in x_set_toolkit_scroll_bar_thumb
4341 we try to ensure that we always stay two pixels away from the
4343 part
= scroll_bar_down_arrow
;
4345 part
= scroll_bar_handle
;
4347 window_being_scrolled
= bar
->window
;
4348 bar
->dragging
= make_number (portion
);
4349 last_scroll_bar_part
= part
;
4350 x_send_scroll_bar_event (bar
->window
, part
, portion
, whole
);
4354 /* Xaw scroll bar callback. Invoked for incremental scrolling.,
4355 i.e. line or page up or down. WIDGET is the Xaw scroll bar
4356 widget. CLIENT_DATA is a pointer to the scroll_bar structure for
4357 the scroll bar. CALL_DATA is an integer specifying the action that
4358 has taken place. Its magnitude is in the range 0..height of the
4359 scroll bar. Negative values mean scroll towards buffer start.
4360 Values < height of scroll bar mean line-wise movement. */
4363 xaw_scroll_callback (Widget widget
, XtPointer client_data
, XtPointer call_data
)
4365 struct scroll_bar
*bar
= (struct scroll_bar
*) client_data
;
4366 /* The position really is stored cast to a pointer. */
4367 int position
= (long) call_data
;
4371 /* Get the height of the scroll bar. */
4373 XtVaGetValues (widget
, XtNheight
, &height
, NULL
);
4376 if (eabs (position
) >= height
)
4377 part
= (position
< 0) ? scroll_bar_above_handle
: scroll_bar_below_handle
;
4379 /* If Xaw3d was compiled with ARROW_SCROLLBAR,
4380 it maps line-movement to call_data = max(5, height/20). */
4381 else if (xaw3d_arrow_scroll
&& eabs (position
) <= max (5, height
/ 20))
4382 part
= (position
< 0) ? scroll_bar_up_arrow
: scroll_bar_down_arrow
;
4384 part
= scroll_bar_move_ratio
;
4386 window_being_scrolled
= bar
->window
;
4387 bar
->dragging
= Qnil
;
4388 last_scroll_bar_part
= part
;
4389 x_send_scroll_bar_event (bar
->window
, part
, position
, height
);
4392 #endif /* not USE_GTK and not USE_MOTIF */
4394 #define SCROLL_BAR_NAME "verticalScrollBar"
4396 /* Create the widget for scroll bar BAR on frame F. Record the widget
4397 and X window of the scroll bar in BAR. */
4401 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4403 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4406 xg_create_scroll_bar (f
, bar
, G_CALLBACK (xg_scroll_callback
),
4407 G_CALLBACK (xg_end_scroll_callback
),
4412 #else /* not USE_GTK */
4415 x_create_toolkit_scroll_bar (struct frame
*f
, struct scroll_bar
*bar
)
4421 char *scroll_bar_name
= SCROLL_BAR_NAME
;
4422 unsigned long pixel
;
4427 /* Set resources. Create the widget. */
4428 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4429 XtSetArg (av
[ac
], XmNminimum
, 0); ++ac
;
4430 XtSetArg (av
[ac
], XmNmaximum
, XM_SB_MAX
); ++ac
;
4431 XtSetArg (av
[ac
], XmNorientation
, XmVERTICAL
); ++ac
;
4432 XtSetArg (av
[ac
], XmNprocessingDirection
, XmMAX_ON_BOTTOM
), ++ac
;
4433 XtSetArg (av
[ac
], XmNincrement
, 1); ++ac
;
4434 XtSetArg (av
[ac
], XmNpageIncrement
, 1); ++ac
;
4436 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4439 XtSetArg (av
[ac
], XmNforeground
, pixel
);
4443 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4446 XtSetArg (av
[ac
], XmNbackground
, pixel
);
4450 widget
= XmCreateScrollBar (f
->output_data
.x
->edit_widget
,
4451 scroll_bar_name
, av
, ac
);
4453 /* Add one callback for everything that can happen. */
4454 XtAddCallback (widget
, XmNdecrementCallback
, xm_scroll_callback
,
4456 XtAddCallback (widget
, XmNdragCallback
, xm_scroll_callback
,
4458 XtAddCallback (widget
, XmNincrementCallback
, xm_scroll_callback
,
4460 XtAddCallback (widget
, XmNpageDecrementCallback
, xm_scroll_callback
,
4462 XtAddCallback (widget
, XmNpageIncrementCallback
, xm_scroll_callback
,
4464 XtAddCallback (widget
, XmNtoBottomCallback
, xm_scroll_callback
,
4466 XtAddCallback (widget
, XmNtoTopCallback
, xm_scroll_callback
,
4469 /* Realize the widget. Only after that is the X window created. */
4470 XtRealizeWidget (widget
);
4472 /* Set the cursor to an arrow. I didn't find a resource to do that.
4473 And I'm wondering why it hasn't an arrow cursor by default. */
4474 XDefineCursor (XtDisplay (widget
), XtWindow (widget
),
4475 f
->output_data
.x
->nontext_cursor
);
4477 #else /* !USE_MOTIF i.e. use Xaw */
4479 /* Set resources. Create the widget. The background of the
4480 Xaw3d scroll bar widget is a little bit light for my taste.
4481 We don't alter it here to let users change it according
4482 to their taste with `emacs*verticalScrollBar.background: xxx'. */
4483 XtSetArg (av
[ac
], XtNmappedWhenManaged
, False
); ++ac
;
4484 XtSetArg (av
[ac
], XtNorientation
, XtorientVertical
); ++ac
;
4485 /* For smoother scrolling with Xaw3d -sm */
4486 /* XtSetArg (av[ac], XtNpickTop, True); ++ac; */
4488 pixel
= f
->output_data
.x
->scroll_bar_foreground_pixel
;
4491 XtSetArg (av
[ac
], XtNforeground
, pixel
);
4495 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4498 XtSetArg (av
[ac
], XtNbackground
, pixel
);
4502 /* Top/bottom shadow colors. */
4504 /* Allocate them, if necessary. */
4505 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1)
4507 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4510 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4511 FRAME_X_COLORMAP (f
),
4512 &pixel
, 1.2, 0x8000))
4514 f
->output_data
.x
->scroll_bar_top_shadow_pixel
= pixel
;
4517 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4519 pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4522 if (!x_alloc_lighter_color (f
, FRAME_X_DISPLAY (f
),
4523 FRAME_X_COLORMAP (f
),
4524 &pixel
, 0.6, 0x4000))
4526 f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
= pixel
;
4530 #ifdef XtNbeNiceToColormap
4531 /* Tell the toolkit about them. */
4532 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
== -1
4533 || f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
== -1)
4534 /* We tried to allocate a color for the top/bottom shadow, and
4535 failed, so tell Xaw3d to use dithering instead. */
4537 XtSetArg (av
[ac
], XtNbeNiceToColormap
, True
);
4541 /* Tell what colors Xaw3d should use for the top/bottom shadow, to
4542 be more consistent with other emacs 3d colors, and since Xaw3d is
4543 not good at dealing with allocation failure. */
4545 /* This tells Xaw3d to use real colors instead of dithering for
4547 XtSetArg (av
[ac
], XtNbeNiceToColormap
, False
);
4550 /* Specify the colors. */
4551 pixel
= f
->output_data
.x
->scroll_bar_top_shadow_pixel
;
4554 XtSetArg (av
[ac
], XtNtopShadowPixel
, pixel
);
4557 pixel
= f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
;
4560 XtSetArg (av
[ac
], XtNbottomShadowPixel
, pixel
);
4566 widget
= XtCreateWidget (scroll_bar_name
, scrollbarWidgetClass
,
4567 f
->output_data
.x
->edit_widget
, av
, ac
);
4571 char *val
= initial
;
4572 XtVaGetValues (widget
, XtNscrollVCursor
, (XtPointer
) &val
,
4573 #ifdef XtNarrowScrollbars
4574 XtNarrowScrollbars
, (XtPointer
) &xaw3d_arrow_scroll
,
4576 XtNpickTop
, (XtPointer
) &xaw3d_pick_top
, NULL
);
4577 if (xaw3d_arrow_scroll
|| val
== initial
)
4578 { /* ARROW_SCROLL */
4579 xaw3d_arrow_scroll
= True
;
4580 /* Isn't that just a personal preference ? --Stef */
4581 XtVaSetValues (widget
, XtNcursorName
, "top_left_arrow", NULL
);
4585 /* Define callbacks. */
4586 XtAddCallback (widget
, XtNjumpProc
, xaw_jump_callback
, (XtPointer
) bar
);
4587 XtAddCallback (widget
, XtNscrollProc
, xaw_scroll_callback
,
4590 /* Realize the widget. Only after that is the X window created. */
4591 XtRealizeWidget (widget
);
4593 #endif /* !USE_MOTIF */
4595 /* Install an action hook that lets us detect when the user
4596 finishes interacting with a scroll bar. */
4597 if (action_hook_id
== 0)
4598 action_hook_id
= XtAppAddActionHook (Xt_app_con
, xt_action_hook
, 0);
4600 /* Remember X window and widget in the scroll bar vector. */
4601 SET_SCROLL_BAR_X_WIDGET (bar
, widget
);
4602 xwindow
= XtWindow (widget
);
4603 bar
->x_window
= xwindow
;
4607 #endif /* not USE_GTK */
4610 /* Set the thumb size and position of scroll bar BAR. We are currently
4611 displaying PORTION out of a whole WHOLE, and our position POSITION. */
4615 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
, int whole
)
4617 xg_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
4620 #else /* not USE_GTK */
4622 x_set_toolkit_scroll_bar_thumb (struct scroll_bar
*bar
, int portion
, int position
,
4625 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4626 Widget widget
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4633 /* We use an estimate of 30 chars per line rather than the real
4634 `portion' value. This has the disadvantage that the thumb size
4635 is not very representative, but it makes our life a lot easier.
4636 Otherwise, we have to constantly adjust the thumb size, which
4637 we can't always do quickly enough: while dragging, the size of
4638 the thumb might prevent the user from dragging the thumb all the
4639 way to the end. but Motif and some versions of Xaw3d don't allow
4640 updating the thumb size while dragging. Also, even if we can update
4641 its size, the update will often happen too late.
4642 If you don't believe it, check out revision 1.650 of xterm.c to see
4643 what hoops we were going through and the still poor behavior we got. */
4644 portion
= WINDOW_TOTAL_LINES (XWINDOW (bar
->window
)) * 30;
4645 /* When the thumb is at the bottom, position == whole.
4646 So we need to increase `whole' to make space for the thumb. */
4653 top
= (float) position
/ whole
;
4654 shown
= (float) portion
/ whole
;
4657 if (NILP (bar
->dragging
))
4661 /* Slider size. Must be in the range [1 .. MAX - MIN] where MAX
4662 is the scroll bar's maximum and MIN is the scroll bar's minimum
4664 size
= shown
* XM_SB_MAX
;
4665 size
= min (size
, XM_SB_MAX
);
4666 size
= max (size
, 1);
4668 /* Position. Must be in the range [MIN .. MAX - SLIDER_SIZE]. */
4669 value
= top
* XM_SB_MAX
;
4670 value
= min (value
, XM_SB_MAX
- size
);
4672 XmScrollBarSetValues (widget
, value
, size
, 0, 0, False
);
4674 #else /* !USE_MOTIF i.e. use Xaw */
4680 top
= (float) position
/ whole
;
4681 shown
= (float) portion
/ whole
;
4685 float old_top
, old_shown
;
4687 XtVaGetValues (widget
,
4688 XtNtopOfThumb
, &old_top
,
4689 XtNshown
, &old_shown
,
4693 /* Massage the top+shown values. */
4694 if (NILP (bar
->dragging
) || last_scroll_bar_part
== scroll_bar_down_arrow
)
4695 top
= max (0, min (1, top
));
4698 /* Keep two pixels available for moving the thumb down. */
4699 shown
= max (0, min (1 - top
- (2.0 / height
), shown
));
4701 /* If the call to XawScrollbarSetThumb below doesn't seem to work,
4702 check that your system's configuration file contains a define
4703 for `NARROWPROTO'. See s/freebsd.h for an example. */
4704 if (top
!= old_top
|| shown
!= old_shown
)
4706 if (NILP (bar
->dragging
))
4707 XawScrollbarSetThumb (widget
, top
, shown
);
4710 /* Try to make the scrolling a tad smoother. */
4711 if (!xaw3d_pick_top
)
4712 shown
= min (shown
, old_shown
);
4714 XawScrollbarSetThumb (widget
, top
, shown
);
4718 #endif /* !USE_MOTIF */
4722 #endif /* not USE_GTK */
4724 #endif /* USE_TOOLKIT_SCROLL_BARS */
4728 /************************************************************************
4729 Scroll bars, general
4730 ************************************************************************/
4732 /* Create a scroll bar and return the scroll bar vector for it. W is
4733 the Emacs window on which to create the scroll bar. TOP, LEFT,
4734 WIDTH and HEIGHT are the pixel coordinates and dimensions of the
4737 static struct scroll_bar
*
4738 x_scroll_bar_create (struct window
*w
, int top
, int left
, int width
, int height
)
4740 struct frame
*f
= XFRAME (w
->frame
);
4741 struct scroll_bar
*bar
4742 = ALLOCATE_PSEUDOVECTOR (struct scroll_bar
, x_window
, PVEC_OTHER
);
4746 #ifdef USE_TOOLKIT_SCROLL_BARS
4747 x_create_toolkit_scroll_bar (f
, bar
);
4748 #else /* not USE_TOOLKIT_SCROLL_BARS */
4750 XSetWindowAttributes a
;
4754 a
.background_pixel
= f
->output_data
.x
->scroll_bar_background_pixel
;
4755 if (a
.background_pixel
== -1)
4756 a
.background_pixel
= FRAME_BACKGROUND_PIXEL (f
);
4758 a
.event_mask
= (ButtonPressMask
| ButtonReleaseMask
4759 | ButtonMotionMask
| PointerMotionHintMask
4761 a
.cursor
= FRAME_X_DISPLAY_INFO (f
)->vertical_scroll_bar_cursor
;
4763 mask
= (CWBackPixel
| CWEventMask
| CWCursor
);
4765 /* Clear the area of W that will serve as a scroll bar. This is
4766 for the case that a window has been split horizontally. In
4767 this case, no clear_frame is generated to reduce flickering. */
4768 if (width
> 0 && height
> 0)
4769 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4771 window_box_height (w
), False
);
4773 window
= XCreateWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
4774 /* Position and size of scroll bar. */
4775 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4777 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4779 /* Border width, depth, class, and visual. */
4786 bar
->x_window
= window
;
4788 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4790 XSETWINDOW (bar
->window
, w
);
4794 bar
->height
= height
;
4797 bar
->dragging
= Qnil
;
4798 bar
->fringe_extended_p
= 0;
4800 /* Add bar to its frame's list of scroll bars. */
4801 bar
->next
= FRAME_SCROLL_BARS (f
);
4803 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
4804 if (!NILP (bar
->next
))
4805 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
4807 /* Map the window/widget. */
4808 #ifdef USE_TOOLKIT_SCROLL_BARS
4811 xg_update_scrollbar_pos (f
,
4814 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4815 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4817 #else /* not USE_GTK */
4818 Widget scroll_bar
= SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
);
4819 XtConfigureWidget (scroll_bar
,
4820 left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
4822 width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
4823 max (height
, 1), 0);
4824 XtMapWidget (scroll_bar
);
4825 #endif /* not USE_GTK */
4827 #else /* not USE_TOOLKIT_SCROLL_BARS */
4828 XMapRaised (FRAME_X_DISPLAY (f
), bar
->x_window
);
4829 #endif /* not USE_TOOLKIT_SCROLL_BARS */
4836 #ifndef USE_TOOLKIT_SCROLL_BARS
4838 /* Draw BAR's handle in the proper position.
4840 If the handle is already drawn from START to END, don't bother
4841 redrawing it, unless REBUILD is non-zero; in that case, always
4842 redraw it. (REBUILD is handy for drawing the handle after expose
4845 Normally, we want to constrain the start and end of the handle to
4846 fit inside its rectangle, but if the user is dragging the scroll
4847 bar handle, we want to let them drag it down all the way, so that
4848 the bar's top is as far down as it goes; otherwise, there's no way
4849 to move to the very end of the buffer. */
4852 x_scroll_bar_set_handle (struct scroll_bar
*bar
, int start
, int end
, int rebuild
)
4854 int dragging
= ! NILP (bar
->dragging
);
4855 Window w
= bar
->x_window
;
4856 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4857 GC gc
= f
->output_data
.x
->normal_gc
;
4859 /* If the display is already accurate, do nothing. */
4861 && start
== bar
->start
4868 int inside_width
= VERTICAL_SCROLL_BAR_INSIDE_WIDTH (f
, bar
->width
);
4869 int inside_height
= VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f
, bar
->height
);
4870 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
4872 /* Make sure the values are reasonable, and try to preserve
4873 the distance between start and end. */
4875 int length
= end
- start
;
4879 else if (start
> top_range
)
4881 end
= start
+ length
;
4885 else if (end
> top_range
&& ! dragging
)
4889 /* Store the adjusted setting in the scroll bar. */
4893 /* Clip the end position, just for display. */
4894 if (end
> top_range
)
4897 /* Draw bottom positions VERTICAL_SCROLL_BAR_MIN_HANDLE pixels
4898 below top positions, to make sure the handle is always at least
4899 that many pixels tall. */
4900 end
+= VERTICAL_SCROLL_BAR_MIN_HANDLE
;
4902 /* Draw the empty space above the handle. Note that we can't clear
4903 zero-height areas; that means "clear to end of window." */
4905 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4906 /* x, y, width, height, and exposures. */
4907 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4908 VERTICAL_SCROLL_BAR_TOP_BORDER
,
4909 inside_width
, start
,
4912 /* Change to proper foreground color if one is specified. */
4913 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4914 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4915 f
->output_data
.x
->scroll_bar_foreground_pixel
);
4917 /* Draw the handle itself. */
4918 XFillRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
4919 /* x, y, width, height */
4920 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4921 VERTICAL_SCROLL_BAR_TOP_BORDER
+ start
,
4922 inside_width
, end
- start
);
4924 /* Restore the foreground color of the GC if we changed it above. */
4925 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
4926 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
4927 FRAME_FOREGROUND_PIXEL (f
));
4929 /* Draw the empty space below the handle. Note that we can't
4930 clear zero-height areas; that means "clear to end of window." */
4931 if (end
< inside_height
)
4932 x_clear_area (FRAME_X_DISPLAY (f
), w
,
4933 /* x, y, width, height, and exposures. */
4934 VERTICAL_SCROLL_BAR_LEFT_BORDER
,
4935 VERTICAL_SCROLL_BAR_TOP_BORDER
+ end
,
4936 inside_width
, inside_height
- end
,
4944 #endif /* !USE_TOOLKIT_SCROLL_BARS */
4946 /* Destroy scroll bar BAR, and set its Emacs window's scroll bar to
4950 x_scroll_bar_remove (struct scroll_bar
*bar
)
4952 struct frame
*f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
4955 #ifdef USE_TOOLKIT_SCROLL_BARS
4957 xg_remove_scroll_bar (f
, bar
->x_window
);
4958 #else /* not USE_GTK */
4959 XtDestroyWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
));
4960 #endif /* not USE_GTK */
4962 XDestroyWindow (FRAME_X_DISPLAY (f
), bar
->x_window
);
4965 /* Disassociate this scroll bar from its window. */
4966 XWINDOW (bar
->window
)->vertical_scroll_bar
= Qnil
;
4972 /* Set the handle of the vertical scroll bar for WINDOW to indicate
4973 that we are displaying PORTION characters out of a total of WHOLE
4974 characters, starting at POSITION. If WINDOW has no scroll bar,
4978 XTset_vertical_scroll_bar (struct window
*w
, int portion
, int whole
, int position
)
4980 struct frame
*f
= XFRAME (w
->frame
);
4981 struct scroll_bar
*bar
;
4982 int top
, height
, left
, sb_left
, width
, sb_width
;
4983 int window_y
, window_height
;
4984 #ifdef USE_TOOLKIT_SCROLL_BARS
4985 int fringe_extended_p
;
4988 /* Get window dimensions. */
4989 window_box (w
, -1, 0, &window_y
, 0, &window_height
);
4991 width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
4992 height
= window_height
;
4994 /* Compute the left edge of the scroll bar area. */
4995 left
= WINDOW_SCROLL_BAR_AREA_X (w
);
4997 /* Compute the width of the scroll bar which might be less than
4998 the width of the area reserved for the scroll bar. */
4999 if (WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
) > 0)
5000 sb_width
= WINDOW_CONFIG_SCROLL_BAR_WIDTH (w
);
5004 /* Compute the left edge of the scroll bar. */
5005 #ifdef USE_TOOLKIT_SCROLL_BARS
5006 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5007 sb_left
= left
+ (WINDOW_RIGHTMOST_P (w
) ? width
- sb_width
: 0);
5009 sb_left
= left
+ (WINDOW_LEFTMOST_P (w
) ? 0 : width
- sb_width
);
5011 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_RIGHT (w
))
5012 sb_left
= left
+ width
- sb_width
;
5017 #ifdef USE_TOOLKIT_SCROLL_BARS
5018 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5019 fringe_extended_p
= (WINDOW_LEFTMOST_P (w
)
5020 && WINDOW_LEFT_FRINGE_WIDTH (w
)
5021 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5022 || WINDOW_LEFT_MARGIN_COLS (w
) == 0));
5024 fringe_extended_p
= (WINDOW_RIGHTMOST_P (w
)
5025 && WINDOW_RIGHT_FRINGE_WIDTH (w
)
5026 && (WINDOW_HAS_FRINGES_OUTSIDE_MARGINS (w
)
5027 || WINDOW_RIGHT_MARGIN_COLS (w
) == 0));
5030 /* Does the scroll bar exist yet? */
5031 if (NILP (w
->vertical_scroll_bar
))
5033 if (width
> 0 && height
> 0)
5036 #ifdef USE_TOOLKIT_SCROLL_BARS
5037 if (fringe_extended_p
)
5038 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5039 sb_left
, top
, sb_width
, height
, False
);
5042 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5043 left
, top
, width
, height
, False
);
5047 bar
= x_scroll_bar_create (w
, top
, sb_left
, sb_width
, height
);
5051 /* It may just need to be moved and resized. */
5052 unsigned int mask
= 0;
5054 bar
= XSCROLL_BAR (w
->vertical_scroll_bar
);
5058 if (sb_left
!= bar
->left
)
5060 if (top
!= bar
->top
)
5062 if (sb_width
!= bar
->width
)
5064 if (height
!= bar
->height
)
5067 #ifdef USE_TOOLKIT_SCROLL_BARS
5069 /* Move/size the scroll bar widget. */
5070 if (mask
|| bar
->fringe_extended_p
!= fringe_extended_p
)
5072 /* Since toolkit scroll bars are smaller than the space reserved
5073 for them on the frame, we have to clear "under" them. */
5074 if (width
> 0 && height
> 0)
5076 if (fringe_extended_p
)
5077 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5078 sb_left
, top
, sb_width
, height
, False
);
5080 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5081 left
, top
, width
, height
, False
);
5084 xg_update_scrollbar_pos (f
,
5087 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5088 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
*2,
5090 #else /* not USE_GTK */
5091 XtConfigureWidget (SCROLL_BAR_X_WIDGET (FRAME_X_DISPLAY (f
), bar
),
5092 sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5094 sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2,
5095 max (height
, 1), 0);
5096 #endif /* not USE_GTK */
5098 #else /* not USE_TOOLKIT_SCROLL_BARS */
5100 /* Clear areas not covered by the scroll bar because of
5101 VERTICAL_SCROLL_BAR_WIDTH_TRIM. */
5102 if (VERTICAL_SCROLL_BAR_WIDTH_TRIM
)
5104 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5105 left
, top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5107 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5108 left
+ width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5109 top
, VERTICAL_SCROLL_BAR_WIDTH_TRIM
,
5113 /* Clear areas not covered by the scroll bar because it's not as
5114 wide as the area reserved for it. This makes sure a
5115 previous mode line display is cleared after C-x 2 C-x 1, for
5118 int area_width
= WINDOW_CONFIG_SCROLL_BAR_COLS (w
) * FRAME_COLUMN_WIDTH (f
);
5119 int rest
= area_width
- sb_width
;
5120 if (rest
> 0 && height
> 0)
5122 if (WINDOW_HAS_VERTICAL_SCROLL_BAR_ON_LEFT (w
))
5123 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5124 left
+ area_width
- rest
, top
,
5125 rest
, height
, False
);
5127 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
5128 left
, top
, rest
, height
, False
);
5132 /* Move/size the scroll bar window. */
5137 wc
.x
= sb_left
+ VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5139 wc
.width
= sb_width
- VERTICAL_SCROLL_BAR_WIDTH_TRIM
* 2;
5141 XConfigureWindow (FRAME_X_DISPLAY (f
), bar
->x_window
,
5145 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5147 /* Remember new settings. */
5148 bar
->left
= sb_left
;
5150 bar
->width
= sb_width
;
5151 bar
->height
= height
;
5156 #ifdef USE_TOOLKIT_SCROLL_BARS
5157 bar
->fringe_extended_p
= fringe_extended_p
;
5159 x_set_toolkit_scroll_bar_thumb (bar
, portion
, position
, whole
);
5160 #else /* not USE_TOOLKIT_SCROLL_BARS */
5161 /* Set the scroll bar's current state, unless we're currently being
5163 if (NILP (bar
->dragging
))
5165 int top_range
= VERTICAL_SCROLL_BAR_TOP_RANGE (f
, height
);
5168 x_scroll_bar_set_handle (bar
, 0, top_range
, 0);
5171 int start
= ((double) position
* top_range
) / whole
;
5172 int end
= ((double) (position
+ portion
) * top_range
) / whole
;
5173 x_scroll_bar_set_handle (bar
, start
, end
, 0);
5176 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5178 XSETVECTOR (w
->vertical_scroll_bar
, bar
);
5182 /* The following three hooks are used when we're doing a thorough
5183 redisplay of the frame. We don't explicitly know which scroll bars
5184 are going to be deleted, because keeping track of when windows go
5185 away is a real pain - "Can you say set-window-configuration, boys
5186 and girls?" Instead, we just assert at the beginning of redisplay
5187 that *all* scroll bars are to be removed, and then save a scroll bar
5188 from the fiery pit when we actually redisplay its window. */
5190 /* Arrange for all scroll bars on FRAME to be removed at the next call
5191 to `*judge_scroll_bars_hook'. A scroll bar may be spared if
5192 `*redeem_scroll_bar_hook' is applied to its window before the judgment. */
5195 XTcondemn_scroll_bars (FRAME_PTR frame
)
5197 /* Transfer all the scroll bars to FRAME_CONDEMNED_SCROLL_BARS. */
5198 while (! NILP (FRAME_SCROLL_BARS (frame
)))
5201 bar
= FRAME_SCROLL_BARS (frame
);
5202 FRAME_SCROLL_BARS (frame
) = XSCROLL_BAR (bar
)->next
;
5203 XSCROLL_BAR (bar
)->next
= FRAME_CONDEMNED_SCROLL_BARS (frame
);
5204 XSCROLL_BAR (bar
)->prev
= Qnil
;
5205 if (! NILP (FRAME_CONDEMNED_SCROLL_BARS (frame
)))
5206 XSCROLL_BAR (FRAME_CONDEMNED_SCROLL_BARS (frame
))->prev
= bar
;
5207 FRAME_CONDEMNED_SCROLL_BARS (frame
) = bar
;
5212 /* Un-mark WINDOW's scroll bar for deletion in this judgment cycle.
5213 Note that WINDOW isn't necessarily condemned at all. */
5216 XTredeem_scroll_bar (struct window
*window
)
5218 struct scroll_bar
*bar
;
5221 /* We can't redeem this window's scroll bar if it doesn't have one. */
5222 if (NILP (window
->vertical_scroll_bar
))
5225 bar
= XSCROLL_BAR (window
->vertical_scroll_bar
);
5227 /* Unlink it from the condemned list. */
5228 f
= XFRAME (WINDOW_FRAME (window
));
5229 if (NILP (bar
->prev
))
5231 /* If the prev pointer is nil, it must be the first in one of
5233 if (EQ (FRAME_SCROLL_BARS (f
), window
->vertical_scroll_bar
))
5234 /* It's not condemned. Everything's fine. */
5236 else if (EQ (FRAME_CONDEMNED_SCROLL_BARS (f
),
5237 window
->vertical_scroll_bar
))
5238 FRAME_CONDEMNED_SCROLL_BARS (f
) = bar
->next
;
5240 /* If its prev pointer is nil, it must be at the front of
5241 one or the other! */
5245 XSCROLL_BAR (bar
->prev
)->next
= bar
->next
;
5247 if (! NILP (bar
->next
))
5248 XSCROLL_BAR (bar
->next
)->prev
= bar
->prev
;
5250 bar
->next
= FRAME_SCROLL_BARS (f
);
5252 XSETVECTOR (FRAME_SCROLL_BARS (f
), bar
);
5253 if (! NILP (bar
->next
))
5254 XSETVECTOR (XSCROLL_BAR (bar
->next
)->prev
, bar
);
5257 /* Remove all scroll bars on FRAME that haven't been saved since the
5258 last call to `*condemn_scroll_bars_hook'. */
5261 XTjudge_scroll_bars (FRAME_PTR f
)
5263 Lisp_Object bar
, next
;
5265 bar
= FRAME_CONDEMNED_SCROLL_BARS (f
);
5267 /* Clear out the condemned list now so we won't try to process any
5268 more events on the hapless scroll bars. */
5269 FRAME_CONDEMNED_SCROLL_BARS (f
) = Qnil
;
5271 for (; ! NILP (bar
); bar
= next
)
5273 struct scroll_bar
*b
= XSCROLL_BAR (bar
);
5275 x_scroll_bar_remove (b
);
5278 b
->next
= b
->prev
= Qnil
;
5281 /* Now there should be no references to the condemned scroll bars,
5282 and they should get garbage-collected. */
5286 #ifndef USE_TOOLKIT_SCROLL_BARS
5287 /* Handle an Expose or GraphicsExpose event on a scroll bar. This
5288 is a no-op when using toolkit scroll bars.
5290 This may be called from a signal handler, so we have to ignore GC
5294 x_scroll_bar_expose (struct scroll_bar
*bar
, XEvent
*event
)
5296 Window w
= bar
->x_window
;
5297 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5298 GC gc
= f
->output_data
.x
->normal_gc
;
5299 int width_trim
= VERTICAL_SCROLL_BAR_WIDTH_TRIM
;
5303 x_scroll_bar_set_handle (bar
, bar
->start
, bar
->end
, 1);
5305 /* Switch to scroll bar foreground color. */
5306 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5307 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5308 f
->output_data
.x
->scroll_bar_foreground_pixel
);
5310 /* Draw a one-pixel border just inside the edges of the scroll bar. */
5311 XDrawRectangle (FRAME_X_DISPLAY (f
), w
, gc
,
5313 /* x, y, width, height */
5315 bar
->width
- 1 - width_trim
- width_trim
,
5318 /* Restore the foreground color of the GC if we changed it above. */
5319 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
5320 XSetForeground (FRAME_X_DISPLAY (f
), gc
,
5321 FRAME_FOREGROUND_PIXEL (f
));
5326 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5328 /* Handle a mouse click on the scroll bar BAR. If *EMACS_EVENT's kind
5329 is set to something other than NO_EVENT, it is enqueued.
5331 This may be called from a signal handler, so we have to ignore GC
5336 x_scroll_bar_handle_click (struct scroll_bar
*bar
, XEvent
*event
, struct input_event
*emacs_event
)
5338 if (! WINDOWP (bar
->window
))
5341 emacs_event
->kind
= SCROLL_BAR_CLICK_EVENT
;
5342 emacs_event
->code
= event
->xbutton
.button
- Button1
;
5343 emacs_event
->modifiers
5344 = (x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO
5345 (XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)))),
5346 event
->xbutton
.state
)
5347 | (event
->type
== ButtonRelease
5350 emacs_event
->frame_or_window
= bar
->window
;
5351 emacs_event
->arg
= Qnil
;
5352 emacs_event
->timestamp
= event
->xbutton
.time
;
5355 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5356 int y
= event
->xbutton
.y
- VERTICAL_SCROLL_BAR_TOP_BORDER
;
5359 if (y
> top_range
) y
= top_range
;
5362 emacs_event
->part
= scroll_bar_above_handle
;
5363 else if (y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5364 emacs_event
->part
= scroll_bar_handle
;
5366 emacs_event
->part
= scroll_bar_below_handle
;
5368 #ifndef USE_TOOLKIT_SCROLL_BARS
5369 /* If the user has released the handle, set it to its final position. */
5370 if (event
->type
== ButtonRelease
5371 && ! NILP (bar
->dragging
))
5373 int new_start
= y
- XINT (bar
->dragging
);
5374 int new_end
= new_start
+ bar
->end
- bar
->start
;
5376 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5377 bar
->dragging
= Qnil
;
5381 XSETINT (emacs_event
->x
, y
);
5382 XSETINT (emacs_event
->y
, top_range
);
5386 #ifndef USE_TOOLKIT_SCROLL_BARS
5388 /* Handle some mouse motion while someone is dragging the scroll bar.
5390 This may be called from a signal handler, so we have to ignore GC
5394 x_scroll_bar_note_movement (struct scroll_bar
*bar
, XEvent
*event
)
5396 FRAME_PTR f
= XFRAME (XWINDOW (bar
->window
)->frame
);
5398 last_mouse_movement_time
= event
->xmotion
.time
;
5401 XSETVECTOR (last_mouse_scroll_bar
, bar
);
5403 /* If we're dragging the bar, display it. */
5404 if (! NILP (bar
->dragging
))
5406 /* Where should the handle be now? */
5407 int new_start
= event
->xmotion
.y
- XINT (bar
->dragging
);
5409 if (new_start
!= bar
->start
)
5411 int new_end
= new_start
+ bar
->end
- bar
->start
;
5413 x_scroll_bar_set_handle (bar
, new_start
, new_end
, 0);
5418 #endif /* !USE_TOOLKIT_SCROLL_BARS */
5420 /* Return information to the user about the current position of the mouse
5421 on the scroll bar. */
5424 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
)
5426 struct scroll_bar
*bar
= XSCROLL_BAR (last_mouse_scroll_bar
);
5427 Window w
= bar
->x_window
;
5428 FRAME_PTR f
= XFRAME (WINDOW_FRAME (XWINDOW (bar
->window
)));
5430 Window dummy_window
;
5432 unsigned int dummy_mask
;
5436 /* Get the mouse's position relative to the scroll bar window, and
5438 if (! XQueryPointer (FRAME_X_DISPLAY (f
), w
,
5440 /* Root, child, root x and root y. */
5441 &dummy_window
, &dummy_window
,
5442 &dummy_coord
, &dummy_coord
,
5444 /* Position relative to scroll bar. */
5447 /* Mouse buttons and modifier keys. */
5453 = VERTICAL_SCROLL_BAR_TOP_RANGE (f
, bar
->height
);
5455 win_y
-= VERTICAL_SCROLL_BAR_TOP_BORDER
;
5457 if (! NILP (bar
->dragging
))
5458 win_y
-= XINT (bar
->dragging
);
5462 if (win_y
> top_range
)
5466 *bar_window
= bar
->window
;
5468 if (! NILP (bar
->dragging
))
5469 *part
= scroll_bar_handle
;
5470 else if (win_y
< bar
->start
)
5471 *part
= scroll_bar_above_handle
;
5472 else if (win_y
< bar
->end
+ VERTICAL_SCROLL_BAR_MIN_HANDLE
)
5473 *part
= scroll_bar_handle
;
5475 *part
= scroll_bar_below_handle
;
5477 XSETINT (*x
, win_y
);
5478 XSETINT (*y
, top_range
);
5481 last_mouse_scroll_bar
= Qnil
;
5484 *time
= last_mouse_movement_time
;
5490 /* The screen has been cleared so we may have changed foreground or
5491 background colors, and the scroll bars may need to be redrawn.
5492 Clear out the scroll bars, and ask for expose events, so we can
5496 x_scroll_bar_clear (FRAME_PTR f
)
5498 #ifndef USE_TOOLKIT_SCROLL_BARS
5501 /* We can have scroll bars even if this is 0,
5502 if we just turned off scroll bar mode.
5503 But in that case we should not clear them. */
5504 if (FRAME_HAS_VERTICAL_SCROLL_BARS (f
))
5505 for (bar
= FRAME_SCROLL_BARS (f
); VECTORP (bar
);
5506 bar
= XSCROLL_BAR (bar
)->next
)
5507 XClearArea (FRAME_X_DISPLAY (f
),
5508 XSCROLL_BAR (bar
)->x_window
,
5510 #endif /* not USE_TOOLKIT_SCROLL_BARS */
5514 /* The main X event-reading loop - XTread_socket. */
5516 /* This holds the state XLookupString needs to implement dead keys
5517 and other tricks known as "compose processing". _X Window System_
5518 says that a portable program can't use this, but Stephen Gildea assures
5519 me that letting the compiler initialize it to zeros will work okay.
5521 This must be defined outside of XTread_socket, for the same reasons
5522 given for enter_timestamp, above. */
5524 static XComposeStatus compose_status
;
5526 /* Record the last 100 characters stored
5527 to help debug the loss-of-chars-during-GC problem. */
5529 static int temp_index
;
5530 static short temp_buffer
[100];
5532 #define STORE_KEYSYM_FOR_DEBUG(keysym) \
5533 if (temp_index == sizeof temp_buffer / sizeof (short)) \
5535 temp_buffer[temp_index++] = (keysym)
5537 /* Set this to nonzero to fake an "X I/O error"
5538 on a particular display. */
5540 struct x_display_info
*XTread_socket_fake_io_error
;
5542 /* When we find no input here, we occasionally do a no-op command
5543 to verify that the X server is still running and we can still talk with it.
5544 We try all the open displays, one by one.
5545 This variable is used for cycling thru the displays. */
5547 static struct x_display_info
*next_noop_dpyinfo
;
5549 #define SET_SAVED_MENU_EVENT(size) \
5552 if (f->output_data.x->saved_menu_event == 0) \
5553 f->output_data.x->saved_menu_event \
5554 = (XEvent *) xmalloc (sizeof (XEvent)); \
5555 memcpy (f->output_data.x->saved_menu_event, &event, size); \
5556 inev.ie.kind = MENU_BAR_ACTIVATE_EVENT; \
5557 XSETFRAME (inev.ie.frame_or_window, f); \
5561 #define SET_SAVED_BUTTON_EVENT SET_SAVED_MENU_EVENT (sizeof (XButtonEvent))
5562 #define SET_SAVED_KEY_EVENT SET_SAVED_MENU_EVENT (sizeof (XKeyEvent))
5572 /* Filter events for the current X input method.
5573 DPYINFO is the display this event is for.
5574 EVENT is the X event to filter.
5576 Returns non-zero if the event was filtered, caller shall not process
5578 Returns zero if event is wasn't filtered. */
5582 x_filter_event (struct x_display_info
*dpyinfo
, XEvent
*event
)
5584 /* XFilterEvent returns non-zero if the input method has
5585 consumed the event. We pass the frame's X window to
5586 XFilterEvent because that's the one for which the IC
5589 struct frame
*f1
= x_any_window_to_frame (dpyinfo
,
5590 event
->xclient
.window
);
5592 return XFilterEvent (event
, f1
? FRAME_X_WINDOW (f1
) : None
);
5597 static int current_count
;
5598 static int current_finish
;
5599 static struct input_event
*current_hold_quit
;
5601 /* This is the filter function invoked by the GTK event loop.
5602 It is invoked before the XEvent is translated to a GdkEvent,
5603 so we have a chance to act on the event before GTK. */
5604 static GdkFilterReturn
5605 event_handler_gdk (GdkXEvent
*gxev
, GdkEvent
*ev
, gpointer data
)
5607 XEvent
*xev
= (XEvent
*) gxev
;
5610 if (current_count
>= 0)
5612 struct x_display_info
*dpyinfo
;
5614 dpyinfo
= x_display_info_for_display (xev
->xany
.display
);
5617 /* Filter events for the current X input method.
5618 GTK calls XFilterEvent but not for key press and release,
5619 so we do it here. */
5620 if ((xev
->type
== KeyPress
|| xev
->type
== KeyRelease
)
5622 && x_filter_event (dpyinfo
, xev
))
5625 return GDK_FILTER_REMOVE
;
5630 current_finish
= X_EVENT_NORMAL
;
5633 handle_one_xevent (dpyinfo
, xev
, ¤t_finish
,
5637 current_finish
= x_dispatch_event (xev
, xev
->xany
.display
);
5641 if (current_finish
== X_EVENT_GOTO_OUT
|| current_finish
== X_EVENT_DROP
)
5642 return GDK_FILTER_REMOVE
;
5644 return GDK_FILTER_CONTINUE
;
5646 #endif /* USE_GTK */
5649 /* Handles the XEvent EVENT on display DPYINFO.
5651 *FINISH is X_EVENT_GOTO_OUT if caller should stop reading events.
5652 *FINISH is zero if caller should continue reading events.
5653 *FINISH is X_EVENT_DROP if event should not be passed to the toolkit.
5655 We return the number of characters stored into the buffer. */
5658 handle_one_xevent (struct x_display_info
*dpyinfo
, XEvent
*eventp
, int *finish
, struct input_event
*hold_quit
)
5661 struct input_event ie
;
5662 struct selection_input_event sie
;
5667 struct frame
*f
= NULL
;
5668 struct coding_system coding
;
5669 XEvent event
= *eventp
;
5671 *finish
= X_EVENT_NORMAL
;
5673 EVENT_INIT (inev
.ie
);
5674 inev
.ie
.kind
= NO_EVENT
;
5677 if (pending_event_wait
.eventtype
== event
.type
)
5678 pending_event_wait
.eventtype
= 0; /* Indicates we got it. */
5684 if (event
.xclient
.message_type
5685 == dpyinfo
->Xatom_wm_protocols
5686 && event
.xclient
.format
== 32)
5688 if (event
.xclient
.data
.l
[0]
5689 == dpyinfo
->Xatom_wm_take_focus
)
5691 /* Use x_any_window_to_frame because this
5692 could be the shell widget window
5693 if the frame has no title bar. */
5694 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5696 /* Not quite sure this is needed -pd */
5697 if (f
&& FRAME_XIC (f
))
5698 XSetICFocus (FRAME_XIC (f
));
5700 #if 0 /* Emacs sets WM hints whose `input' field is `true'. This
5701 instructs the WM to set the input focus automatically for
5702 Emacs with a call to XSetInputFocus. Setting WM_TAKE_FOCUS
5703 tells the WM to send us a ClientMessage WM_TAKE_FOCUS after
5704 it has set the focus. So, XSetInputFocus below is not
5707 The call to XSetInputFocus below has also caused trouble. In
5708 cases where the XSetInputFocus done by the WM and the one
5709 below are temporally close (on a fast machine), the call
5710 below can generate additional FocusIn events which confuse
5713 /* Since we set WM_TAKE_FOCUS, we must call
5714 XSetInputFocus explicitly. But not if f is null,
5715 since that might be an event for a deleted frame. */
5718 Display
*d
= event
.xclient
.display
;
5719 /* Catch and ignore errors, in case window has been
5720 iconified by a window manager such as GWM. */
5722 XSetInputFocus (d
, event
.xclient
.window
,
5723 /* The ICCCM says this is
5724 the only valid choice. */
5726 event
.xclient
.data
.l
[1]);
5727 /* This is needed to detect the error
5728 if there is an error. */
5730 x_uncatch_errors ();
5732 /* Not certain about handling scroll bars here */
5737 if (event
.xclient
.data
.l
[0]
5738 == dpyinfo
->Xatom_wm_save_yourself
)
5740 /* Save state modify the WM_COMMAND property to
5741 something which can reinstate us. This notifies
5742 the session manager, who's looking for such a
5743 PropertyNotify. Can restart processing when
5744 a keyboard or mouse event arrives. */
5745 /* If we have a session manager, don't set this.
5746 KDE will then start two Emacsen, one for the
5747 session manager and one for this. */
5749 if (! x_session_have_connection ())
5752 f
= x_top_window_to_frame (dpyinfo
,
5753 event
.xclient
.window
);
5754 /* This is just so we only give real data once
5755 for a single Emacs process. */
5756 if (f
== SELECTED_FRAME ())
5757 XSetCommand (FRAME_X_DISPLAY (f
),
5758 event
.xclient
.window
,
5759 initial_argv
, initial_argc
);
5761 XSetCommand (FRAME_X_DISPLAY (f
),
5762 event
.xclient
.window
,
5768 if (event
.xclient
.data
.l
[0]
5769 == dpyinfo
->Xatom_wm_delete_window
)
5771 f
= x_any_window_to_frame (dpyinfo
,
5772 event
.xclient
.window
);
5774 goto OTHER
; /* May be a dialog that is to be removed */
5776 inev
.ie
.kind
= DELETE_WINDOW_EVENT
;
5777 XSETFRAME (inev
.ie
.frame_or_window
, f
);
5784 if (event
.xclient
.message_type
5785 == dpyinfo
->Xatom_wm_configure_denied
)
5790 if (event
.xclient
.message_type
5791 == dpyinfo
->Xatom_wm_window_moved
)
5794 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5796 new_x
= event
.xclient
.data
.s
[0];
5797 new_y
= event
.xclient
.data
.s
[1];
5801 f
->left_pos
= new_x
;
5808 if (event
.xclient
.message_type
5809 == dpyinfo
->Xatom_editres
)
5811 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5813 _XEditResCheckMessages (f
->output_data
.x
->widget
, NULL
,
5817 #endif /* HACK_EDITRES */
5819 if ((event
.xclient
.message_type
5820 == dpyinfo
->Xatom_DONE
)
5821 || (event
.xclient
.message_type
5822 == dpyinfo
->Xatom_PAGE
))
5824 /* Ghostview job completed. Kill it. We could
5825 reply with "Next" if we received "Page", but we
5826 currently never do because we are interested in
5827 images, only, which should have 1 page. */
5828 Pixmap pixmap
= (Pixmap
) event
.xclient
.data
.l
[1];
5829 f
= x_window_to_frame (dpyinfo
, event
.xclient
.window
);
5832 x_kill_gs_process (pixmap
, f
);
5833 expose_frame (f
, 0, 0, 0, 0);
5837 #ifdef USE_TOOLKIT_SCROLL_BARS
5838 /* Scroll bar callbacks send a ClientMessage from which
5839 we construct an input_event. */
5840 if (event
.xclient
.message_type
5841 == dpyinfo
->Xatom_Scrollbar
)
5843 x_scroll_bar_to_input_event (&event
, &inev
.ie
);
5844 *finish
= X_EVENT_GOTO_OUT
;
5847 #endif /* USE_TOOLKIT_SCROLL_BARS */
5849 /* XEmbed messages from the embedder (if any). */
5850 if (event
.xclient
.message_type
5851 == dpyinfo
->Xatom_XEMBED
)
5853 enum xembed_message msg
= event
.xclient
.data
.l
[1];
5854 if (msg
== XEMBED_FOCUS_IN
|| msg
== XEMBED_FOCUS_OUT
)
5855 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
5857 *finish
= X_EVENT_GOTO_OUT
;
5861 xft_settings_event (dpyinfo
, &event
);
5863 f
= x_any_window_to_frame (dpyinfo
, event
.xclient
.window
);
5866 if (x_handle_dnd_message (f
, &event
.xclient
, dpyinfo
, &inev
.ie
))
5867 *finish
= X_EVENT_DROP
;
5871 case SelectionNotify
:
5872 last_user_time
= event
.xselection
.time
;
5873 #ifdef USE_X_TOOLKIT
5874 if (! x_window_to_frame (dpyinfo
, event
.xselection
.requestor
))
5876 #endif /* not USE_X_TOOLKIT */
5877 x_handle_selection_notify (&event
.xselection
);
5880 case SelectionClear
: /* Someone has grabbed ownership. */
5881 last_user_time
= event
.xselectionclear
.time
;
5882 #ifdef USE_X_TOOLKIT
5883 if (! x_window_to_frame (dpyinfo
, event
.xselectionclear
.window
))
5885 #endif /* USE_X_TOOLKIT */
5887 XSelectionClearEvent
*eventp
= (XSelectionClearEvent
*) &event
;
5889 inev
.ie
.kind
= SELECTION_CLEAR_EVENT
;
5890 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5891 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5892 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5893 inev
.ie
.frame_or_window
= Qnil
;
5897 case SelectionRequest
: /* Someone wants our selection. */
5898 last_user_time
= event
.xselectionrequest
.time
;
5899 #ifdef USE_X_TOOLKIT
5900 if (!x_window_to_frame (dpyinfo
, event
.xselectionrequest
.owner
))
5902 #endif /* USE_X_TOOLKIT */
5904 XSelectionRequestEvent
*eventp
5905 = (XSelectionRequestEvent
*) &event
;
5907 inev
.ie
.kind
= SELECTION_REQUEST_EVENT
;
5908 SELECTION_EVENT_DISPLAY (&inev
.sie
) = eventp
->display
;
5909 SELECTION_EVENT_REQUESTOR (&inev
.sie
) = eventp
->requestor
;
5910 SELECTION_EVENT_SELECTION (&inev
.sie
) = eventp
->selection
;
5911 SELECTION_EVENT_TARGET (&inev
.sie
) = eventp
->target
;
5912 SELECTION_EVENT_PROPERTY (&inev
.sie
) = eventp
->property
;
5913 SELECTION_EVENT_TIME (&inev
.sie
) = eventp
->time
;
5914 inev
.ie
.frame_or_window
= Qnil
;
5918 case PropertyNotify
:
5919 last_user_time
= event
.xproperty
.time
;
5920 f
= x_top_window_to_frame (dpyinfo
, event
.xproperty
.window
);
5921 if (f
&& event
.xproperty
.atom
== dpyinfo
->Xatom_net_wm_state
)
5922 x_handle_net_wm_state (f
, &event
.xproperty
);
5924 x_handle_property_notify (&event
.xproperty
);
5925 xft_settings_event (dpyinfo
, &event
);
5928 case ReparentNotify
:
5929 f
= x_top_window_to_frame (dpyinfo
, event
.xreparent
.window
);
5933 f
->output_data
.x
->parent_desc
= event
.xreparent
.parent
;
5934 x_real_positions (f
, &x
, &y
);
5938 /* Perhaps reparented due to a WM restart. Reset this. */
5939 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_UNKNOWN
;
5940 FRAME_X_DISPLAY_INFO (f
)->net_supported_window
= 0;
5945 f
= x_window_to_frame (dpyinfo
, event
.xexpose
.window
);
5949 /* This seems to be needed for GTK 2.6. */
5950 x_clear_area (event
.xexpose
.display
,
5951 event
.xexpose
.window
,
5952 event
.xexpose
.x
, event
.xexpose
.y
,
5953 event
.xexpose
.width
, event
.xexpose
.height
,
5956 if (f
->async_visible
== 0)
5958 f
->async_visible
= 1;
5959 f
->async_iconified
= 0;
5960 f
->output_data
.x
->has_been_visible
= 1;
5961 SET_FRAME_GARBAGED (f
);
5965 event
.xexpose
.x
, event
.xexpose
.y
,
5966 event
.xexpose
.width
, event
.xexpose
.height
);
5970 #ifndef USE_TOOLKIT_SCROLL_BARS
5971 struct scroll_bar
*bar
;
5973 #if defined USE_LUCID
5974 /* Submenus of the Lucid menu bar aren't widgets
5975 themselves, so there's no way to dispatch events
5976 to them. Recognize this case separately. */
5979 = x_window_to_menu_bar (event
.xexpose
.window
);
5981 xlwmenu_redisplay (widget
);
5983 #endif /* USE_LUCID */
5985 #ifdef USE_TOOLKIT_SCROLL_BARS
5986 /* Dispatch event to the widget. */
5988 #else /* not USE_TOOLKIT_SCROLL_BARS */
5989 bar
= x_window_to_scroll_bar (event
.xexpose
.display
,
5990 event
.xexpose
.window
);
5993 x_scroll_bar_expose (bar
, &event
);
5994 #ifdef USE_X_TOOLKIT
5997 #endif /* USE_X_TOOLKIT */
5998 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6002 case GraphicsExpose
: /* This occurs when an XCopyArea's
6003 source area was obscured or not
6005 f
= x_window_to_frame (dpyinfo
, event
.xgraphicsexpose
.drawable
);
6009 event
.xgraphicsexpose
.x
, event
.xgraphicsexpose
.y
,
6010 event
.xgraphicsexpose
.width
,
6011 event
.xgraphicsexpose
.height
);
6013 #ifdef USE_X_TOOLKIT
6016 #endif /* USE_X_TOOLKIT */
6019 case NoExpose
: /* This occurs when an XCopyArea's
6020 source area was completely
6025 /* Redo the mouse-highlight after the tooltip has gone. */
6026 if (event
.xmap
.window
== tip_window
)
6029 redo_mouse_highlight ();
6032 f
= x_top_window_to_frame (dpyinfo
, event
.xunmap
.window
);
6033 if (f
) /* F may no longer exist if
6034 the frame was deleted. */
6036 /* While a frame is unmapped, display generation is
6037 disabled; you don't want to spend time updating a
6038 display that won't ever be seen. */
6039 f
->async_visible
= 0;
6040 /* We can't distinguish, from the event, whether the window
6041 has become iconified or invisible. So assume, if it
6042 was previously visible, than now it is iconified.
6043 But x_make_frame_invisible clears both
6044 the visible flag and the iconified flag;
6045 and that way, we know the window is not iconified now. */
6046 if (FRAME_VISIBLE_P (f
) || FRAME_ICONIFIED_P (f
))
6048 f
->async_iconified
= 1;
6050 inev
.ie
.kind
= ICONIFY_EVENT
;
6051 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6057 if (event
.xmap
.window
== tip_window
)
6058 /* The tooltip has been drawn already. Avoid
6059 the SET_FRAME_GARBAGED below. */
6062 /* We use x_top_window_to_frame because map events can
6063 come for sub-windows and they don't mean that the
6064 frame is visible. */
6065 f
= x_top_window_to_frame (dpyinfo
, event
.xmap
.window
);
6068 /* wait_reading_process_output will notice this and update
6069 the frame's display structures.
6070 If we where iconified, we should not set garbaged,
6071 because that stops redrawing on Expose events. This looks
6072 bad if we are called from a recursive event loop
6073 (x_dispatch_event), for example when a dialog is up. */
6074 if (! f
->async_iconified
)
6075 SET_FRAME_GARBAGED (f
);
6077 /* Check if fullscreen was specified before we where mapped the
6078 first time, i.e. from the command line. */
6079 if (!f
->output_data
.x
->has_been_visible
)
6080 x_check_fullscreen (f
);
6082 f
->async_visible
= 1;
6083 f
->async_iconified
= 0;
6084 f
->output_data
.x
->has_been_visible
= 1;
6088 inev
.ie
.kind
= DEICONIFY_EVENT
;
6089 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6091 else if (! NILP (Vframe_list
)
6092 && ! NILP (XCDR (Vframe_list
)))
6093 /* Force a redisplay sooner or later
6094 to update the frame titles
6095 in case this is the second frame. */
6096 record_asynch_buffer_change ();
6099 xg_frame_resized (f
, -1, -1);
6106 last_user_time
= event
.xkey
.time
;
6107 ignore_next_mouse_click_timeout
= 0;
6109 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6110 /* Dispatch KeyPress events when in menu. */
6111 if (popup_activated ())
6115 f
= x_any_window_to_frame (dpyinfo
, event
.xkey
.window
);
6117 /* If mouse-highlight is an integer, input clears out
6118 mouse highlighting. */
6119 if (!dpyinfo
->mouse_face_hidden
&& INTEGERP (Vmouse_highlight
)
6121 || !EQ (f
->tool_bar_window
, dpyinfo
->mouse_face_window
)))
6123 clear_mouse_face (dpyinfo
);
6124 dpyinfo
->mouse_face_hidden
= 1;
6127 #if defined USE_MOTIF && defined USE_TOOLKIT_SCROLL_BARS
6130 /* Scroll bars consume key events, but we want
6131 the keys to go to the scroll bar's frame. */
6132 Widget widget
= XtWindowToWidget (dpyinfo
->display
,
6134 if (widget
&& XmIsScrollBar (widget
))
6136 widget
= XtParent (widget
);
6137 f
= x_any_window_to_frame (dpyinfo
, XtWindow (widget
));
6140 #endif /* USE_MOTIF and USE_TOOLKIT_SCROLL_BARS */
6144 KeySym keysym
, orig_keysym
;
6145 /* al%imercury@uunet.uu.net says that making this 81
6146 instead of 80 fixed a bug whereby meta chars made
6149 It seems that some version of XmbLookupString has
6150 a bug of not returning XBufferOverflow in
6151 status_return even if the input is too long to
6152 fit in 81 bytes. So, we must prepare sufficient
6153 bytes for copy_buffer. 513 bytes (256 chars for
6154 two-byte character set) seems to be a fairly good
6155 approximation. -- 2000.8.10 handa@etl.go.jp */
6156 unsigned char copy_buffer
[513];
6157 unsigned char *copy_bufptr
= copy_buffer
;
6158 int copy_bufsiz
= sizeof (copy_buffer
);
6160 Lisp_Object coding_system
= Qlatin_1
;
6164 /* Don't pass keys to GTK. A Tab will shift focus to the
6165 tool bar in GTK 2.4. Keys will still go to menus and
6166 dialogs because in that case popup_activated is TRUE
6168 *finish
= X_EVENT_DROP
;
6172 |= x_emacs_to_x_modifiers (FRAME_X_DISPLAY_INFO (f
),
6173 extra_keyboard_modifiers
);
6174 modifiers
= event
.xkey
.state
;
6176 /* This will have to go some day... */
6178 /* make_lispy_event turns chars into control chars.
6179 Don't do it here because XLookupString is too eager. */
6180 event
.xkey
.state
&= ~ControlMask
;
6181 event
.xkey
.state
&= ~(dpyinfo
->meta_mod_mask
6182 | dpyinfo
->super_mod_mask
6183 | dpyinfo
->hyper_mod_mask
6184 | dpyinfo
->alt_mod_mask
);
6186 /* In case Meta is ComposeCharacter,
6187 clear its status. According to Markus Ehrnsperger
6188 Markus.Ehrnsperger@lehrstuhl-bross.physik.uni-muenchen.de
6189 this enables ComposeCharacter to work whether or
6190 not it is combined with Meta. */
6191 if (modifiers
& dpyinfo
->meta_mod_mask
)
6192 memset (&compose_status
, 0, sizeof (compose_status
));
6197 Status status_return
;
6199 coding_system
= Vlocale_coding_system
;
6200 nbytes
= XmbLookupString (FRAME_XIC (f
),
6201 &event
.xkey
, copy_bufptr
,
6202 copy_bufsiz
, &keysym
,
6204 if (status_return
== XBufferOverflow
)
6206 copy_bufsiz
= nbytes
+ 1;
6207 copy_bufptr
= (unsigned char *) alloca (copy_bufsiz
);
6208 nbytes
= XmbLookupString (FRAME_XIC (f
),
6209 &event
.xkey
, copy_bufptr
,
6210 copy_bufsiz
, &keysym
,
6213 /* Xutf8LookupString is a new but already deprecated interface. -stef */
6214 if (status_return
== XLookupNone
)
6216 else if (status_return
== XLookupChars
)
6221 else if (status_return
!= XLookupKeySym
6222 && status_return
!= XLookupBoth
)
6226 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6227 copy_bufsiz
, &keysym
,
6230 nbytes
= XLookupString (&event
.xkey
, copy_bufptr
,
6231 copy_bufsiz
, &keysym
,
6235 /* If not using XIM/XIC, and a compose sequence is in progress,
6236 we break here. Otherwise, chars_matched is always 0. */
6237 if (compose_status
.chars_matched
> 0 && nbytes
== 0)
6240 memset (&compose_status
, 0, sizeof (compose_status
));
6241 orig_keysym
= keysym
;
6243 /* Common for all keysym input events. */
6244 XSETFRAME (inev
.ie
.frame_or_window
, f
);
6246 = x_x_to_emacs_modifiers (FRAME_X_DISPLAY_INFO (f
), modifiers
);
6247 inev
.ie
.timestamp
= event
.xkey
.time
;
6249 /* First deal with keysyms which have defined
6250 translations to characters. */
6251 if (keysym
>= 32 && keysym
< 128)
6252 /* Avoid explicitly decoding each ASCII character. */
6254 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6255 inev
.ie
.code
= keysym
;
6259 /* Keysyms directly mapped to Unicode characters. */
6260 if (keysym
>= 0x01000000 && keysym
<= 0x0110FFFF)
6262 if (keysym
< 0x01000080)
6263 inev
.ie
.kind
= ASCII_KEYSTROKE_EVENT
;
6265 inev
.ie
.kind
= MULTIBYTE_CHAR_KEYSTROKE_EVENT
;
6266 inev
.ie
.code
= keysym
& 0xFFFFFF;
6270 /* Now non-ASCII. */
6271 if (HASH_TABLE_P (Vx_keysym_table
)
6272 && (NATNUMP (c
= Fgethash (make_number (keysym
),
6276 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (XFASTINT (c
))
6277 ? ASCII_KEYSTROKE_EVENT
6278 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6279 inev
.ie
.code
= XFASTINT (c
);
6283 /* Random non-modifier sorts of keysyms. */
6284 if (((keysym
>= XK_BackSpace
&& keysym
<= XK_Escape
)
6285 || keysym
== XK_Delete
6286 #ifdef XK_ISO_Left_Tab
6287 || (keysym
>= XK_ISO_Left_Tab
6288 && keysym
<= XK_ISO_Enter
)
6290 || IsCursorKey (keysym
) /* 0xff50 <= x < 0xff60 */
6291 || IsMiscFunctionKey (keysym
) /* 0xff60 <= x < VARIES */
6293 /* This recognizes the "extended function
6294 keys". It seems there's no cleaner way.
6295 Test IsModifierKey to avoid handling
6296 mode_switch incorrectly. */
6297 || ((unsigned) (keysym
) >= XK_Select
6298 && (unsigned)(keysym
) < XK_KP_Space
)
6300 #ifdef XK_dead_circumflex
6301 || orig_keysym
== XK_dead_circumflex
6303 #ifdef XK_dead_grave
6304 || orig_keysym
== XK_dead_grave
6306 #ifdef XK_dead_tilde
6307 || orig_keysym
== XK_dead_tilde
6309 #ifdef XK_dead_diaeresis
6310 || orig_keysym
== XK_dead_diaeresis
6312 #ifdef XK_dead_macron
6313 || orig_keysym
== XK_dead_macron
6315 #ifdef XK_dead_degree
6316 || orig_keysym
== XK_dead_degree
6318 #ifdef XK_dead_acute
6319 || orig_keysym
== XK_dead_acute
6321 #ifdef XK_dead_cedilla
6322 || orig_keysym
== XK_dead_cedilla
6324 #ifdef XK_dead_breve
6325 || orig_keysym
== XK_dead_breve
6327 #ifdef XK_dead_ogonek
6328 || orig_keysym
== XK_dead_ogonek
6330 #ifdef XK_dead_caron
6331 || orig_keysym
== XK_dead_caron
6333 #ifdef XK_dead_doubleacute
6334 || orig_keysym
== XK_dead_doubleacute
6336 #ifdef XK_dead_abovedot
6337 || orig_keysym
== XK_dead_abovedot
6339 || IsKeypadKey (keysym
) /* 0xff80 <= x < 0xffbe */
6340 || IsFunctionKey (keysym
) /* 0xffbe <= x < 0xffe1 */
6341 /* Any "vendor-specific" key is ok. */
6342 || (orig_keysym
& (1 << 28))
6343 || (keysym
!= NoSymbol
&& nbytes
== 0))
6344 && ! (IsModifierKey (orig_keysym
)
6345 /* The symbols from XK_ISO_Lock
6346 to XK_ISO_Last_Group_Lock
6347 don't have real modifiers but
6348 should be treated similarly to
6349 Mode_switch by Emacs. */
6350 #if defined XK_ISO_Lock && defined XK_ISO_Last_Group_Lock
6351 || ((unsigned)(orig_keysym
)
6353 && (unsigned)(orig_keysym
)
6354 <= XK_ISO_Last_Group_Lock
)
6358 STORE_KEYSYM_FOR_DEBUG (keysym
);
6359 /* make_lispy_event will convert this to a symbolic
6361 inev
.ie
.kind
= NON_ASCII_KEYSTROKE_EVENT
;
6362 inev
.ie
.code
= keysym
;
6366 { /* Raw bytes, not keysym. */
6371 for (i
= 0, nchars
= 0; i
< nbytes
; i
++)
6373 if (ASCII_BYTE_P (copy_bufptr
[i
]))
6375 STORE_KEYSYM_FOR_DEBUG (copy_bufptr
[i
]);
6378 if (nchars
< nbytes
)
6380 /* Decode the input data. */
6384 /* The input should be decoded with `coding_system'
6385 which depends on which X*LookupString function
6386 we used just above and the locale. */
6387 setup_coding_system (coding_system
, &coding
);
6388 coding
.src_multibyte
= 0;
6389 coding
.dst_multibyte
= 1;
6390 /* The input is converted to events, thus we can't
6391 handle composition. Anyway, there's no XIM that
6392 gives us composition information. */
6393 coding
.common_flags
&= ~CODING_ANNOTATION_MASK
;
6395 require
= MAX_MULTIBYTE_LENGTH
* nbytes
;
6396 coding
.destination
= alloca (require
);
6397 coding
.dst_bytes
= require
;
6398 coding
.mode
|= CODING_MODE_LAST_BLOCK
;
6399 decode_coding_c_string (&coding
, copy_bufptr
, nbytes
, Qnil
);
6400 nbytes
= coding
.produced
;
6401 nchars
= coding
.produced_char
;
6402 copy_bufptr
= coding
.destination
;
6405 /* Convert the input data to a sequence of
6406 character events. */
6407 for (i
= 0; i
< nbytes
; i
+= len
)
6409 if (nchars
== nbytes
)
6410 c
= copy_bufptr
[i
], len
= 1;
6412 c
= STRING_CHAR_AND_LENGTH (copy_bufptr
+ i
, len
);
6413 inev
.ie
.kind
= (SINGLE_BYTE_CHAR_P (c
)
6414 ? ASCII_KEYSTROKE_EVENT
6415 : MULTIBYTE_CHAR_KEYSTROKE_EVENT
);
6417 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6422 inev
.ie
.kind
= NO_EVENT
; /* Already stored above. */
6424 if (keysym
== NoSymbol
)
6430 /* Don't dispatch this event since XtDispatchEvent calls
6431 XFilterEvent, and two calls in a row may freeze the
6439 last_user_time
= event
.xkey
.time
;
6441 /* Don't dispatch this event since XtDispatchEvent calls
6442 XFilterEvent, and two calls in a row may freeze the
6450 last_user_time
= event
.xcrossing
.time
;
6451 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6453 f
= x_any_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6455 if (f
&& x_mouse_click_focus_ignore_position
)
6456 ignore_next_mouse_click_timeout
= event
.xmotion
.time
+ 200;
6458 /* EnterNotify counts as mouse movement,
6459 so update things that depend on mouse position. */
6460 if (f
&& !f
->output_data
.x
->hourglass_p
)
6461 note_mouse_movement (f
, &event
.xmotion
);
6463 /* We may get an EnterNotify on the buttons in the toolbar. In that
6464 case we moved out of any highlighted area and need to note this. */
6465 if (!f
&& last_mouse_glyph_frame
)
6466 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6471 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6475 last_user_time
= event
.xcrossing
.time
;
6476 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6478 f
= x_top_window_to_frame (dpyinfo
, event
.xcrossing
.window
);
6481 if (f
== dpyinfo
->mouse_face_mouse_frame
)
6483 /* If we move outside the frame, then we're
6484 certainly no longer on any text in the frame. */
6485 clear_mouse_face (dpyinfo
);
6486 dpyinfo
->mouse_face_mouse_frame
= 0;
6489 /* Generate a nil HELP_EVENT to cancel a help-echo.
6490 Do it only if there's something to cancel.
6491 Otherwise, the startup message is cleared when
6492 the mouse leaves the frame. */
6493 if (any_help_event_p
)
6497 /* See comment in EnterNotify above */
6498 else if (last_mouse_glyph_frame
)
6499 note_mouse_movement (last_mouse_glyph_frame
, &event
.xmotion
);
6504 x_detect_focus_change (dpyinfo
, &event
, &inev
.ie
);
6509 last_user_time
= event
.xmotion
.time
;
6510 previous_help_echo_string
= help_echo_string
;
6511 help_echo_string
= Qnil
;
6513 if (dpyinfo
->grabbed
&& last_mouse_frame
6514 && FRAME_LIVE_P (last_mouse_frame
))
6515 f
= last_mouse_frame
;
6517 f
= x_window_to_frame (dpyinfo
, event
.xmotion
.window
);
6519 if (dpyinfo
->mouse_face_hidden
)
6521 dpyinfo
->mouse_face_hidden
= 0;
6522 clear_mouse_face (dpyinfo
);
6526 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6532 /* Generate SELECT_WINDOW_EVENTs when needed.
6533 Don't let popup menus influence things (bug#1261). */
6534 if (!NILP (Vmouse_autoselect_window
) && !popup_activated ())
6538 window
= window_from_coordinates (f
,
6539 event
.xmotion
.x
, event
.xmotion
.y
,
6542 /* Window will be selected only when it is not selected now and
6543 last mouse movement event was not in it. Minibuffer window
6544 will be selected only when it is active. */
6545 if (WINDOWP (window
)
6546 && !EQ (window
, last_window
)
6547 && !EQ (window
, selected_window
)
6548 /* For click-to-focus window managers
6549 create event iff we don't leave the
6551 && (focus_follows_mouse
6552 || (EQ (XWINDOW (window
)->frame
,
6553 XWINDOW (selected_window
)->frame
))))
6555 inev
.ie
.kind
= SELECT_WINDOW_EVENT
;
6556 inev
.ie
.frame_or_window
= window
;
6561 if (!note_mouse_movement (f
, &event
.xmotion
))
6562 help_echo_string
= previous_help_echo_string
;
6566 #ifndef USE_TOOLKIT_SCROLL_BARS
6567 struct scroll_bar
*bar
6568 = x_window_to_scroll_bar (event
.xmotion
.display
,
6569 event
.xmotion
.window
);
6572 x_scroll_bar_note_movement (bar
, &event
);
6573 #endif /* USE_TOOLKIT_SCROLL_BARS */
6575 /* If we move outside the frame, then we're
6576 certainly no longer on any text in the frame. */
6577 clear_mouse_face (dpyinfo
);
6580 /* If the contents of the global variable help_echo_string
6581 has changed, generate a HELP_EVENT. */
6582 if (!NILP (help_echo_string
)
6583 || !NILP (previous_help_echo_string
))
6588 case ConfigureNotify
:
6589 f
= x_top_window_to_frame (dpyinfo
, event
.xconfigure
.window
);
6592 && (f
= x_any_window_to_frame (dpyinfo
, event
.xconfigure
.window
))
6593 && event
.xconfigure
.window
== FRAME_X_WINDOW (f
))
6595 xg_frame_resized (f
, event
.xconfigure
.width
,
6596 event
.xconfigure
.height
);
6602 #ifndef USE_X_TOOLKIT
6604 int rows
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, event
.xconfigure
.height
);
6605 int columns
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, event
.xconfigure
.width
);
6607 /* In the toolkit version, change_frame_size
6608 is called by the code that handles resizing
6609 of the EmacsFrame widget. */
6611 /* Even if the number of character rows and columns has
6612 not changed, the font size may have changed, so we need
6613 to check the pixel dimensions as well. */
6614 if (columns
!= FRAME_COLS (f
)
6615 || rows
!= FRAME_LINES (f
)
6616 || event
.xconfigure
.width
!= FRAME_PIXEL_WIDTH (f
)
6617 || event
.xconfigure
.height
!= FRAME_PIXEL_HEIGHT (f
))
6619 change_frame_size (f
, rows
, columns
, 0, 1, 0);
6620 SET_FRAME_GARBAGED (f
);
6621 cancel_mouse_face (f
);
6624 FRAME_PIXEL_WIDTH (f
) = event
.xconfigure
.width
;
6625 FRAME_PIXEL_HEIGHT (f
) = event
.xconfigure
.height
;
6626 #endif /* not USE_GTK */
6630 /* GTK creates windows but doesn't map them.
6631 Only get real positions when mapped. */
6632 if (FRAME_GTK_OUTER_WIDGET (f
)
6633 && gtk_widget_get_mapped (FRAME_GTK_OUTER_WIDGET (f
)))
6636 x_real_positions (f
, &f
->left_pos
, &f
->top_pos
);
6640 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMStatusArea
))
6641 xic_set_statusarea (f
);
6650 /* If we decide we want to generate an event to be seen
6651 by the rest of Emacs, we put it here. */
6654 memset (&compose_status
, 0, sizeof (compose_status
));
6655 last_mouse_glyph_frame
= 0;
6656 last_user_time
= event
.xbutton
.time
;
6658 if (dpyinfo
->grabbed
6660 && FRAME_LIVE_P (last_mouse_frame
))
6661 f
= last_mouse_frame
;
6663 f
= x_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6666 if (f
&& xg_event_is_for_scrollbar (f
, &event
))
6671 /* Is this in the tool-bar? */
6672 if (WINDOWP (f
->tool_bar_window
)
6673 && WINDOW_TOTAL_LINES (XWINDOW (f
->tool_bar_window
)))
6676 int x
= event
.xbutton
.x
;
6677 int y
= event
.xbutton
.y
;
6679 window
= window_from_coordinates (f
, x
, y
, 0, 0, 0, 1);
6680 tool_bar_p
= EQ (window
, f
->tool_bar_window
);
6682 if (tool_bar_p
&& event
.xbutton
.button
< 4)
6684 handle_tool_bar_click (f
, x
, y
,
6685 event
.xbutton
.type
== ButtonPress
,
6686 x_x_to_emacs_modifiers (dpyinfo
,
6687 event
.xbutton
.state
));
6692 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6693 if (! popup_activated ())
6696 if (ignore_next_mouse_click_timeout
)
6698 if (event
.type
== ButtonPress
6699 && (int)(event
.xbutton
.time
- ignore_next_mouse_click_timeout
) > 0)
6701 ignore_next_mouse_click_timeout
= 0;
6702 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6704 if (event
.type
== ButtonRelease
)
6705 ignore_next_mouse_click_timeout
= 0;
6708 construct_mouse_click (&inev
.ie
, &event
.xbutton
, f
);
6710 if (FRAME_X_EMBEDDED_P (f
))
6711 xembed_send_message (f
, event
.xbutton
.time
,
6712 XEMBED_REQUEST_FOCUS
, 0, 0, 0);
6716 struct scroll_bar
*bar
6717 = x_window_to_scroll_bar (event
.xbutton
.display
,
6718 event
.xbutton
.window
);
6720 #ifdef USE_TOOLKIT_SCROLL_BARS
6721 /* Make the "Ctrl-Mouse-2 splits window" work for toolkit
6723 if (bar
&& event
.xbutton
.state
& ControlMask
)
6725 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6726 *finish
= X_EVENT_DROP
;
6728 #else /* not USE_TOOLKIT_SCROLL_BARS */
6730 x_scroll_bar_handle_click (bar
, &event
, &inev
.ie
);
6731 #endif /* not USE_TOOLKIT_SCROLL_BARS */
6734 if (event
.type
== ButtonPress
)
6736 dpyinfo
->grabbed
|= (1 << event
.xbutton
.button
);
6737 last_mouse_frame
= f
;
6740 last_tool_bar_item
= -1;
6743 dpyinfo
->grabbed
&= ~(1 << event
.xbutton
.button
);
6745 /* Ignore any mouse motion that happened before this event;
6746 any subsequent mouse-movement Emacs events should reflect
6747 only motion after the ButtonPress/Release. */
6751 #if defined (USE_X_TOOLKIT) || defined (USE_GTK)
6752 f
= x_menubar_window_to_frame (dpyinfo
, event
.xbutton
.window
);
6753 /* For a down-event in the menu bar,
6754 don't pass it to Xt right now.
6755 Instead, save it away
6756 and we will pass it to Xt from kbd_buffer_get_event.
6757 That way, we can run some Lisp code first. */
6760 ! popup_activated ()
6761 /* Gtk+ menus only react to the first three buttons. */
6762 && event
.xbutton
.button
< 3
6765 f
&& event
.type
== ButtonPress
6766 /* Verify the event is really within the menu bar
6767 and not just sent to it due to grabbing. */
6768 && event
.xbutton
.x
>= 0
6769 && event
.xbutton
.x
< FRAME_PIXEL_WIDTH (f
)
6770 && event
.xbutton
.y
>= 0
6771 && event
.xbutton
.y
< f
->output_data
.x
->menubar_height
6772 && event
.xbutton
.same_screen
)
6774 SET_SAVED_BUTTON_EVENT
;
6775 XSETFRAME (last_mouse_press_frame
, f
);
6777 *finish
= X_EVENT_DROP
;
6780 else if (event
.type
== ButtonPress
)
6782 last_mouse_press_frame
= Qnil
;
6786 #ifdef USE_MOTIF /* This should do not harm for Lucid,
6787 but I am trying to be cautious. */
6788 else if (event
.type
== ButtonRelease
)
6790 if (!NILP (last_mouse_press_frame
))
6792 f
= XFRAME (last_mouse_press_frame
);
6793 if (f
->output_data
.x
)
6794 SET_SAVED_BUTTON_EVENT
;
6799 #endif /* USE_MOTIF */
6802 #endif /* USE_X_TOOLKIT || USE_GTK */
6806 case CirculateNotify
:
6809 case CirculateRequest
:
6812 case VisibilityNotify
:
6816 /* Someone has changed the keyboard mapping - update the
6818 switch (event
.xmapping
.request
)
6820 case MappingModifier
:
6821 x_find_modifier_meanings (dpyinfo
);
6822 /* This is meant to fall through. */
6823 case MappingKeyboard
:
6824 XRefreshKeyboardMapping (&event
.xmapping
);
6829 xft_settings_event (dpyinfo
, &event
);
6834 #ifdef USE_X_TOOLKIT
6836 if (*finish
!= X_EVENT_DROP
)
6837 XtDispatchEvent (&event
);
6839 #endif /* USE_X_TOOLKIT */
6844 if (inev
.ie
.kind
!= NO_EVENT
)
6846 kbd_buffer_store_event_hold (&inev
.ie
, hold_quit
);
6851 && !(hold_quit
&& hold_quit
->kind
!= NO_EVENT
))
6856 XSETFRAME (frame
, f
);
6862 any_help_event_p
= 1;
6863 gen_help_event (help_echo_string
, frame
, help_echo_window
,
6864 help_echo_object
, help_echo_pos
);
6868 help_echo_string
= Qnil
;
6869 gen_help_event (Qnil
, frame
, Qnil
, Qnil
, 0);
6879 /* Handles the XEvent EVENT on display DISPLAY.
6880 This is used for event loops outside the normal event handling,
6881 i.e. looping while a popup menu or a dialog is posted.
6883 Returns the value handle_one_xevent sets in the finish argument. */
6885 x_dispatch_event (XEvent
*event
, Display
*display
)
6887 struct x_display_info
*dpyinfo
;
6888 int finish
= X_EVENT_NORMAL
;
6890 dpyinfo
= x_display_info_for_display (display
);
6893 handle_one_xevent (dpyinfo
, event
, &finish
, 0);
6899 /* Read events coming from the X server.
6900 This routine is called by the SIGIO handler.
6901 We return as soon as there are no more events to be read.
6903 We return the number of characters stored into the buffer,
6904 thus pretending to be `read' (except the characters we store
6905 in the keyboard buffer can be multibyte, so are not necessarily
6908 EXPECTED is nonzero if the caller knows input is available. */
6911 XTread_socket (struct terminal
*terminal
, int expected
, struct input_event
*hold_quit
)
6915 int event_found
= 0;
6917 if (interrupt_input_blocked
)
6919 interrupt_input_pending
= 1;
6921 pending_signals
= 1;
6926 interrupt_input_pending
= 0;
6928 pending_signals
= pending_atimers
;
6932 /* So people can tell when we have read the available input. */
6933 input_signal_count
++;
6938 /* Only check session manager input for the primary display. */
6939 if (terminal
->id
== 1 && x_session_have_connection ())
6941 struct input_event inev
;
6943 /* We don't need to EVENT_INIT (inev) here, as
6944 x_session_check_input copies an entire input_event. */
6945 if (x_session_check_input (&inev
))
6947 kbd_buffer_store_event_hold (&inev
, hold_quit
);
6954 /* For debugging, this gives a way to fake an I/O error. */
6955 if (terminal
->display_info
.x
== XTread_socket_fake_io_error
)
6957 XTread_socket_fake_io_error
= 0;
6958 x_io_error_quitter (terminal
->display_info
.x
->display
);
6962 while (XPending (terminal
->display_info
.x
->display
))
6966 XNextEvent (terminal
->display_info
.x
->display
, &event
);
6969 /* Filter events for the current X input method. */
6970 if (x_filter_event (terminal
->display_info
.x
, &event
))
6975 count
+= handle_one_xevent (terminal
->display_info
.x
,
6976 &event
, &finish
, hold_quit
);
6978 if (finish
== X_EVENT_GOTO_OUT
)
6984 /* For GTK we must use the GTK event loop. But XEvents gets passed
6985 to our filter function above, and then to the big event switch.
6986 We use a bunch of globals to communicate with our filter function,
6987 that is kind of ugly, but it works.
6989 There is no way to do one display at the time, GTK just does events
6990 from all displays. */
6992 while (gtk_events_pending ())
6994 current_count
= count
;
6995 current_hold_quit
= hold_quit
;
6997 gtk_main_iteration ();
6999 count
= current_count
;
7001 current_hold_quit
= 0;
7003 if (current_finish
== X_EVENT_GOTO_OUT
)
7006 #endif /* USE_GTK */
7010 /* On some systems, an X bug causes Emacs to get no more events
7011 when the window is destroyed. Detect that. (1994.) */
7014 /* Emacs and the X Server eats up CPU time if XNoOp is done every time.
7015 One XNOOP in 100 loops will make Emacs terminate.
7016 B. Bretthauer, 1994 */
7018 if (x_noop_count
>= 100)
7022 if (next_noop_dpyinfo
== 0)
7023 next_noop_dpyinfo
= x_display_list
;
7025 XNoOp (next_noop_dpyinfo
->display
);
7027 /* Each time we get here, cycle through the displays now open. */
7028 next_noop_dpyinfo
= next_noop_dpyinfo
->next
;
7032 /* If the focus was just given to an auto-raising frame,
7034 /* ??? This ought to be able to handle more than one such frame. */
7035 if (pending_autoraise_frame
)
7037 x_raise_frame (pending_autoraise_frame
);
7038 pending_autoraise_frame
= 0;
7050 /***********************************************************************
7052 ***********************************************************************/
7054 /* Set clipping for output in glyph row ROW. W is the window in which
7055 we operate. GC is the graphics context to set clipping in.
7057 ROW may be a text row or, e.g., a mode line. Text rows must be
7058 clipped to the interior of the window dedicated to text display,
7059 mode lines must be clipped to the whole window. */
7062 x_clip_to_row (struct window
*w
, struct glyph_row
*row
, int area
, GC gc
)
7064 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7065 XRectangle clip_rect
;
7066 int window_x
, window_y
, window_width
;
7068 window_box (w
, area
, &window_x
, &window_y
, &window_width
, 0);
7070 clip_rect
.x
= window_x
;
7071 clip_rect
.y
= WINDOW_TO_FRAME_PIXEL_Y (w
, max (0, row
->y
));
7072 clip_rect
.y
= max (clip_rect
.y
, window_y
);
7073 clip_rect
.width
= window_width
;
7074 clip_rect
.height
= row
->visible_height
;
7076 XSetClipRectangles (FRAME_X_DISPLAY (f
), gc
, 0, 0, &clip_rect
, 1, Unsorted
);
7080 /* Draw a hollow box cursor on window W in glyph row ROW. */
7083 x_draw_hollow_cursor (struct window
*w
, struct glyph_row
*row
)
7085 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7086 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
7087 Display
*dpy
= FRAME_X_DISPLAY (f
);
7090 struct glyph
*cursor_glyph
;
7093 /* Get the glyph the cursor is on. If we can't tell because
7094 the current matrix is invalid or such, give up. */
7095 cursor_glyph
= get_phys_cursor_glyph (w
);
7096 if (cursor_glyph
== NULL
)
7099 /* Compute frame-relative coordinates for phys cursor. */
7100 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &x
, &y
, &h
);
7101 wd
= w
->phys_cursor_width
;
7103 /* The foreground of cursor_gc is typically the same as the normal
7104 background color, which can cause the cursor box to be invisible. */
7105 xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7106 if (dpyinfo
->scratch_cursor_gc
)
7107 XChangeGC (dpy
, dpyinfo
->scratch_cursor_gc
, GCForeground
, &xgcv
);
7109 dpyinfo
->scratch_cursor_gc
= XCreateGC (dpy
, FRAME_X_WINDOW (f
),
7110 GCForeground
, &xgcv
);
7111 gc
= dpyinfo
->scratch_cursor_gc
;
7113 /* Set clipping, draw the rectangle, and reset clipping again. */
7114 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7115 XDrawRectangle (dpy
, FRAME_X_WINDOW (f
), gc
, x
, y
, wd
, h
- 1);
7116 XSetClipMask (dpy
, gc
, None
);
7120 /* Draw a bar cursor on window W in glyph row ROW.
7122 Implementation note: One would like to draw a bar cursor with an
7123 angle equal to the one given by the font property XA_ITALIC_ANGLE.
7124 Unfortunately, I didn't find a font yet that has this property set.
7128 x_draw_bar_cursor (struct window
*w
, struct glyph_row
*row
, int width
, enum text_cursor_kinds kind
)
7130 struct frame
*f
= XFRAME (w
->frame
);
7131 struct glyph
*cursor_glyph
;
7133 /* If cursor is out of bounds, don't draw garbage. This can happen
7134 in mini-buffer windows when switching between echo area glyphs
7136 cursor_glyph
= get_phys_cursor_glyph (w
);
7137 if (cursor_glyph
== NULL
)
7140 /* If on an image, draw like a normal cursor. That's usually better
7141 visible than drawing a bar, esp. if the image is large so that
7142 the bar might not be in the window. */
7143 if (cursor_glyph
->type
== IMAGE_GLYPH
)
7145 struct glyph_row
*row
;
7146 row
= MATRIX_ROW (w
->current_matrix
, w
->phys_cursor
.vpos
);
7147 draw_phys_cursor_glyph (w
, row
, DRAW_CURSOR
);
7151 Display
*dpy
= FRAME_X_DISPLAY (f
);
7152 Window window
= FRAME_X_WINDOW (f
);
7153 GC gc
= FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
;
7154 unsigned long mask
= GCForeground
| GCBackground
| GCGraphicsExposures
;
7155 struct face
*face
= FACE_FROM_ID (f
, cursor_glyph
->face_id
);
7158 /* If the glyph's background equals the color we normally draw
7159 the bars cursor in, the bar cursor in its normal color is
7160 invisible. Use the glyph's foreground color instead in this
7161 case, on the assumption that the glyph's colors are chosen so
7162 that the glyph is legible. */
7163 if (face
->background
== f
->output_data
.x
->cursor_pixel
)
7164 xgcv
.background
= xgcv
.foreground
= face
->foreground
;
7166 xgcv
.background
= xgcv
.foreground
= f
->output_data
.x
->cursor_pixel
;
7167 xgcv
.graphics_exposures
= 0;
7170 XChangeGC (dpy
, gc
, mask
, &xgcv
);
7173 gc
= XCreateGC (dpy
, window
, mask
, &xgcv
);
7174 FRAME_X_DISPLAY_INFO (f
)->scratch_cursor_gc
= gc
;
7177 x_clip_to_row (w
, row
, TEXT_AREA
, gc
);
7179 if (kind
== BAR_CURSOR
)
7182 width
= FRAME_CURSOR_WIDTH (f
);
7183 width
= min (cursor_glyph
->pixel_width
, width
);
7185 w
->phys_cursor_width
= width
;
7187 XFillRectangle (dpy
, window
, gc
,
7188 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7189 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
),
7190 width
, row
->height
);
7194 int dummy_x
, dummy_y
, dummy_h
;
7197 width
= row
->height
;
7199 width
= min (row
->height
, width
);
7201 get_phys_cursor_geometry (w
, row
, cursor_glyph
, &dummy_x
,
7202 &dummy_y
, &dummy_h
);
7204 XFillRectangle (dpy
, window
, gc
,
7205 WINDOW_TEXT_TO_FRAME_PIXEL_X (w
, w
->phys_cursor
.x
),
7206 WINDOW_TO_FRAME_PIXEL_Y (w
, w
->phys_cursor
.y
+
7207 row
->height
- width
),
7208 w
->phys_cursor_width
, width
);
7211 XSetClipMask (dpy
, gc
, None
);
7216 /* RIF: Define cursor CURSOR on frame F. */
7219 x_define_frame_cursor (struct frame
*f
, Cursor cursor
)
7221 if (!f
->pointer_invisible
7222 && f
->output_data
.x
->current_cursor
!= cursor
)
7223 XDefineCursor (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
), cursor
);
7224 f
->output_data
.x
->current_cursor
= cursor
;
7228 /* RIF: Clear area on frame F. */
7231 x_clear_frame_area (struct frame
*f
, int x
, int y
, int width
, int height
)
7233 x_clear_area (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
7234 x
, y
, width
, height
, False
);
7236 /* Must queue a redraw, because scroll bars might have been cleared. */
7237 if (FRAME_GTK_WIDGET (f
))
7238 gtk_widget_queue_draw (FRAME_GTK_WIDGET (f
));
7243 /* RIF: Draw cursor on window W. */
7246 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
)
7248 struct frame
*f
= XFRAME (WINDOW_FRAME (w
));
7252 w
->phys_cursor_type
= cursor_type
;
7253 w
->phys_cursor_on_p
= 1;
7255 if (glyph_row
->exact_window_width_line_p
7256 && (glyph_row
->reversed_p
7257 ? (w
->phys_cursor
.hpos
< 0)
7258 : (w
->phys_cursor
.hpos
>= glyph_row
->used
[TEXT_AREA
])))
7260 glyph_row
->cursor_in_fringe_p
= 1;
7261 draw_fringe_bitmap (w
, glyph_row
, glyph_row
->reversed_p
);
7265 switch (cursor_type
)
7267 case HOLLOW_BOX_CURSOR
:
7268 x_draw_hollow_cursor (w
, glyph_row
);
7271 case FILLED_BOX_CURSOR
:
7272 draw_phys_cursor_glyph (w
, glyph_row
, DRAW_CURSOR
);
7276 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, BAR_CURSOR
);
7280 x_draw_bar_cursor (w
, glyph_row
, cursor_width
, HBAR_CURSOR
);
7284 w
->phys_cursor_width
= 0;
7293 if (w
== XWINDOW (f
->selected_window
))
7294 if (FRAME_XIC (f
) && (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
))
7295 xic_set_preeditarea (w
, x
, y
);
7300 XFlush (FRAME_X_DISPLAY (f
));
7307 /* Make the x-window of frame F use the gnu icon bitmap. */
7310 x_bitmap_icon (struct frame
*f
, Lisp_Object file
)
7314 if (FRAME_X_WINDOW (f
) == 0)
7317 /* Free up our existing icon bitmap and mask if any. */
7318 if (f
->output_data
.x
->icon_bitmap
> 0)
7319 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7320 f
->output_data
.x
->icon_bitmap
= 0;
7325 /* Use gtk_window_set_icon_from_file () if available,
7326 It's not restricted to bitmaps */
7327 if (xg_set_icon (f
, file
))
7329 #endif /* USE_GTK */
7330 bitmap_id
= x_create_bitmap_from_file (f
, file
);
7331 x_create_bitmap_mask (f
, bitmap_id
);
7335 /* Create the GNU bitmap and mask if necessary. */
7336 if (FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
< 0)
7342 if (xg_set_icon (f
, xg_default_icon_file
)
7343 || xg_set_icon_from_xpm_data (f
, gnu_xpm_bits
))
7346 #elif defined (HAVE_XPM) && defined (HAVE_X_WINDOWS)
7348 rc
= x_create_bitmap_from_xpm_data (f
, gnu_xpm_bits
);
7350 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7354 /* If all else fails, use the (black and white) xbm image. */
7357 rc
= x_create_bitmap_from_data (f
, gnu_xbm_bits
,
7358 gnu_xbm_width
, gnu_xbm_height
);
7362 FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
= rc
;
7363 x_create_bitmap_mask (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7367 /* The first time we create the GNU bitmap and mask,
7368 this increments the ref-count one extra time.
7369 As a result, the GNU bitmap and mask are never freed.
7370 That way, we don't have to worry about allocating it again. */
7371 x_reference_bitmap (f
, FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
);
7373 bitmap_id
= FRAME_X_DISPLAY_INFO (f
)->icon_bitmap_id
;
7376 x_wm_set_icon_pixmap (f
, bitmap_id
);
7377 f
->output_data
.x
->icon_bitmap
= bitmap_id
;
7383 /* Make the x-window of frame F use a rectangle with text.
7384 Use ICON_NAME as the text. */
7387 x_text_icon (struct frame
*f
, char *icon_name
)
7389 if (FRAME_X_WINDOW (f
) == 0)
7394 text
.value
= (unsigned char *) icon_name
;
7395 text
.encoding
= XA_STRING
;
7397 text
.nitems
= strlen (icon_name
);
7398 XSetWMIconName (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), &text
);
7401 if (f
->output_data
.x
->icon_bitmap
> 0)
7402 x_destroy_bitmap (f
, f
->output_data
.x
->icon_bitmap
);
7403 f
->output_data
.x
->icon_bitmap
= 0;
7404 x_wm_set_icon_pixmap (f
, 0);
7409 #define X_ERROR_MESSAGE_SIZE 200
7411 /* If non-nil, this should be a string.
7412 It means catch X errors and store the error message in this string.
7414 The reason we use a stack is that x_catch_error/x_uncatch_error can
7415 be called from a signal handler.
7418 struct x_error_message_stack
{
7419 char string
[X_ERROR_MESSAGE_SIZE
];
7421 struct x_error_message_stack
*prev
;
7423 static struct x_error_message_stack
*x_error_message
;
7425 /* An X error handler which stores the error message in
7426 *x_error_message. This is called from x_error_handler if
7427 x_catch_errors is in effect. */
7430 x_error_catcher (Display
*display
, XErrorEvent
*error
)
7432 XGetErrorText (display
, error
->error_code
,
7433 x_error_message
->string
,
7434 X_ERROR_MESSAGE_SIZE
);
7437 /* Begin trapping X errors for display DPY. Actually we trap X errors
7438 for all displays, but DPY should be the display you are actually
7441 After calling this function, X protocol errors no longer cause
7442 Emacs to exit; instead, they are recorded in the string
7443 stored in *x_error_message.
7445 Calling x_check_errors signals an Emacs error if an X error has
7446 occurred since the last call to x_catch_errors or x_check_errors.
7448 Calling x_uncatch_errors resumes the normal error handling. */
7450 void x_check_errors (Display
*dpy
, char *format
);
7453 x_catch_errors (Display
*dpy
)
7455 struct x_error_message_stack
*data
= xmalloc (sizeof (*data
));
7457 /* Make sure any errors from previous requests have been dealt with. */
7461 data
->string
[0] = 0;
7462 data
->prev
= x_error_message
;
7463 x_error_message
= data
;
7466 /* Undo the last x_catch_errors call.
7467 DPY should be the display that was passed to x_catch_errors. */
7470 x_uncatch_errors (void)
7472 struct x_error_message_stack
*tmp
;
7476 /* The display may have been closed before this function is called.
7477 Check if it is still open before calling XSync. */
7478 if (x_display_info_for_display (x_error_message
->dpy
) != 0)
7479 XSync (x_error_message
->dpy
, False
);
7481 tmp
= x_error_message
;
7482 x_error_message
= x_error_message
->prev
;
7487 /* If any X protocol errors have arrived since the last call to
7488 x_catch_errors or x_check_errors, signal an Emacs error using
7489 sprintf (a buffer, FORMAT, the x error message text) as the text. */
7492 x_check_errors (Display
*dpy
, char *format
)
7494 /* Make sure to catch any errors incurred so far. */
7497 if (x_error_message
->string
[0])
7499 char string
[X_ERROR_MESSAGE_SIZE
];
7500 memcpy (string
, x_error_message
->string
, X_ERROR_MESSAGE_SIZE
);
7501 x_uncatch_errors ();
7502 error (format
, string
);
7506 /* Nonzero if we had any X protocol errors
7507 since we did x_catch_errors on DPY. */
7510 x_had_errors_p (Display
*dpy
)
7512 /* Make sure to catch any errors incurred so far. */
7515 return x_error_message
->string
[0] != 0;
7518 /* Forget about any errors we have had, since we did x_catch_errors on DPY. */
7521 x_clear_errors (Display
*dpy
)
7523 x_error_message
->string
[0] = 0;
7526 #if 0 /* See comment in unwind_to_catch why calling this is a bad
7527 * idea. --lorentey */
7528 /* Close off all unclosed x_catch_errors calls. */
7531 x_fully_uncatch_errors ()
7533 while (x_error_message
)
7534 x_uncatch_errors ();
7538 /* Nonzero if x_catch_errors has been done and not yet canceled. */
7541 x_catching_errors (void)
7543 return x_error_message
!= 0;
7547 static unsigned int x_wire_count
;
7550 fprintf (stderr
, "Lib call: %d\n", ++x_wire_count
);
7555 /* Handle SIGPIPE, which can happen when the connection to a server
7556 simply goes away. SIGPIPE is handled by x_connection_signal.
7557 Don't need to do anything, because the write which caused the
7558 SIGPIPE will fail, causing Xlib to invoke the X IO error handler,
7559 which will do the appropriate cleanup for us. */
7562 x_connection_signal (int signalnum
) /* If we don't have an argument, */
7563 /* some compilers complain in signal calls. */
7566 /* USG systems forget handlers when they are used;
7567 must reestablish each time */
7568 signal (signalnum
, x_connection_signal
);
7573 /************************************************************************
7575 ************************************************************************/
7577 /* Error message passed to x_connection_closed. */
7579 static char *error_msg
;
7581 /* Function installed as fatal_error_signal_hook in
7582 x_connection_closed. Print the X error message, and exit normally,
7583 instead of dumping core when XtCloseDisplay fails. */
7586 x_fatal_error_signal (void)
7588 fprintf (stderr
, "%s\n", error_msg
);
7592 /* Handle the loss of connection to display DPY. ERROR_MESSAGE is
7593 the text of an error message that lead to the connection loss. */
7596 x_connection_closed (Display
*dpy
, char *error_message
)
7598 struct x_display_info
*dpyinfo
= x_display_info_for_display (dpy
);
7599 Lisp_Object frame
, tail
;
7600 int index
= SPECPDL_INDEX ();
7602 error_msg
= (char *) alloca (strlen (error_message
) + 1);
7603 strcpy (error_msg
, error_message
);
7604 handling_signal
= 0;
7606 /* Prevent being called recursively because of an error condition
7607 below. Otherwise, we might end up with printing ``can't find per
7608 display information'' in the recursive call instead of printing
7609 the original message here. */
7610 x_catch_errors (dpy
);
7612 /* Inhibit redisplay while frames are being deleted. */
7613 specbind (Qinhibit_redisplay
, Qt
);
7617 /* Protect display from being closed when we delete the last
7619 dpyinfo
->reference_count
++;
7620 dpyinfo
->terminal
->reference_count
++;
7623 /* First delete frames whose mini-buffers are on frames
7624 that are on the dead display. */
7625 FOR_EACH_FRAME (tail
, frame
)
7627 Lisp_Object minibuf_frame
;
7629 = WINDOW_FRAME (XWINDOW (FRAME_MINIBUF_WINDOW (XFRAME (frame
))));
7630 if (FRAME_X_P (XFRAME (frame
))
7631 && FRAME_X_P (XFRAME (minibuf_frame
))
7632 && ! EQ (frame
, minibuf_frame
)
7633 && FRAME_X_DISPLAY_INFO (XFRAME (minibuf_frame
)) == dpyinfo
)
7634 delete_frame (frame
, Qnoelisp
);
7637 /* Now delete all remaining frames on the dead display.
7638 We are now sure none of these is used as the mini-buffer
7639 for another frame that we need to delete. */
7640 FOR_EACH_FRAME (tail
, frame
)
7641 if (FRAME_X_P (XFRAME (frame
))
7642 && FRAME_X_DISPLAY_INFO (XFRAME (frame
)) == dpyinfo
)
7644 /* Set this to t so that delete_frame won't get confused
7645 trying to find a replacement. */
7646 FRAME_KBOARD (XFRAME (frame
))->Vdefault_minibuffer_frame
= Qt
;
7647 delete_frame (frame
, Qnoelisp
);
7650 /* We have to close the display to inform Xt that it doesn't
7651 exist anymore. If we don't, Xt will continue to wait for
7652 events from the display. As a consequence, a sequence of
7654 M-x make-frame-on-display RET :1 RET
7655 ...kill the new frame, so that we get an IO error...
7656 M-x make-frame-on-display RET :1 RET
7658 will indefinitely wait in Xt for events for display `:1', opened
7659 in the first call to make-frame-on-display.
7661 Closing the display is reported to lead to a bus error on
7662 OpenWindows in certain situations. I suspect that is a bug
7663 in OpenWindows. I don't know how to circumvent it here. */
7667 #ifdef USE_X_TOOLKIT
7668 /* If DPYINFO is null, this means we didn't open the display
7669 in the first place, so don't try to close it. */
7671 extern void (*fatal_error_signal_hook
) (void);
7672 fatal_error_signal_hook
= x_fatal_error_signal
;
7673 XtCloseDisplay (dpy
);
7674 fatal_error_signal_hook
= NULL
;
7679 /* Due to bugs in some Gtk+ versions, just exit here if this
7680 is the last display/terminal. */
7681 if (terminal_list
->next_terminal
== NULL
)
7683 fprintf (stderr
, "%s\n", error_msg
);
7684 Fkill_emacs (make_number (70));
7687 xg_display_close (dpyinfo
->display
);
7690 /* Indicate that this display is dead. */
7691 dpyinfo
->display
= 0;
7693 dpyinfo
->reference_count
--;
7694 dpyinfo
->terminal
->reference_count
--;
7695 if (dpyinfo
->reference_count
!= 0)
7696 /* We have just closed all frames on this display. */
7701 XSETTERMINAL (tmp
, dpyinfo
->terminal
);
7702 Fdelete_terminal (tmp
, Qnoelisp
);
7706 x_uncatch_errors ();
7708 if (terminal_list
== 0)
7710 fprintf (stderr
, "%s\n", error_msg
);
7711 Fkill_emacs (make_number (70));
7715 /* Ordinary stack unwind doesn't deal with these. */
7717 sigunblock (sigmask (SIGIO
));
7719 sigunblock (sigmask (SIGALRM
));
7720 TOTALLY_UNBLOCK_INPUT
;
7722 unbind_to (index
, Qnil
);
7723 clear_waiting_for_input ();
7724 /* Here, we absolutely have to use a non-local exit (e.g. signal, throw,
7725 longjmp), because returning from this function would get us back into
7726 Xlib's code which will directly call `exit'. */
7727 error ("%s", error_msg
);
7730 /* We specifically use it before defining it, so that gcc doesn't inline it,
7731 otherwise gdb doesn't know how to properly put a breakpoint on it. */
7732 static void x_error_quitter (Display
*, XErrorEvent
*);
7734 /* This is the first-level handler for X protocol errors.
7735 It calls x_error_quitter or x_error_catcher. */
7738 x_error_handler (Display
*display
, XErrorEvent
*error
)
7740 if (x_error_message
)
7741 x_error_catcher (display
, error
);
7743 x_error_quitter (display
, error
);
7747 /* This is the usual handler for X protocol errors.
7748 It kills all frames on the display that we got the error for.
7749 If that was the only one, it prints an error message and kills Emacs. */
7751 /* .gdbinit puts a breakpoint here, so make sure it is not inlined. */
7753 #if __GNUC__ >= 3 /* On GCC 3.0 we might get a warning. */
7754 #define NO_INLINE __attribute__((noinline))
7759 /* Some versions of GNU/Linux define noinline in their headers. */
7765 /* On older GCC versions, just putting x_error_quitter
7766 after x_error_handler prevents inlining into the former. */
7768 static void NO_INLINE
7769 x_error_quitter (Display
*display
, XErrorEvent
*error
)
7771 char buf
[256], buf1
[356];
7773 /* Ignore BadName errors. They can happen because of fonts
7774 or colors that are not defined. */
7776 if (error
->error_code
== BadName
)
7779 /* Note that there is no real way portable across R3/R4 to get the
7780 original error handler. */
7782 XGetErrorText (display
, error
->error_code
, buf
, sizeof (buf
));
7783 sprintf (buf1
, "X protocol error: %s on protocol request %d",
7784 buf
, error
->request_code
);
7785 x_connection_closed (display
, buf1
);
7789 /* This is the handler for X IO errors, always.
7790 It kills all frames on the display that we lost touch with.
7791 If that was the only one, it prints an error message and kills Emacs. */
7794 x_io_error_quitter (Display
*display
)
7798 sprintf (buf
, "Connection lost to X server `%s'", DisplayString (display
));
7799 x_connection_closed (display
, buf
);
7803 /* Changing the font of the frame. */
7805 /* Give frame F the font FONT-OBJECT as its default font. The return
7806 value is FONT-OBJECT. FONTSET is an ID of the fontset for the
7807 frame. If it is negative, generate a new fontset from
7811 x_new_font (struct frame
*f
, Lisp_Object font_object
, int fontset
)
7813 struct font
*font
= XFONT_OBJECT (font_object
);
7816 fontset
= fontset_from_font (font_object
);
7817 FRAME_FONTSET (f
) = fontset
;
7818 if (FRAME_FONT (f
) == font
)
7819 /* This font is already set in frame F. There's nothing more to
7823 FRAME_FONT (f
) = font
;
7824 FRAME_BASELINE_OFFSET (f
) = font
->baseline_offset
;
7825 FRAME_COLUMN_WIDTH (f
) = font
->average_width
;
7826 FRAME_SPACE_WIDTH (f
) = font
->space_width
;
7827 FRAME_LINE_HEIGHT (f
) = FONT_HEIGHT (font
);
7829 compute_fringe_widths (f
, 1);
7831 /* Compute the scroll bar width in character columns. */
7832 if (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0)
7834 int wid
= FRAME_COLUMN_WIDTH (f
);
7835 FRAME_CONFIG_SCROLL_BAR_COLS (f
)
7836 = (FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) + wid
-1) / wid
;
7840 int wid
= FRAME_COLUMN_WIDTH (f
);
7841 FRAME_CONFIG_SCROLL_BAR_COLS (f
) = (14 + wid
- 1) / wid
;
7844 if (FRAME_X_WINDOW (f
) != 0)
7846 /* Don't change the size of a tip frame; there's no point in
7847 doing it because it's done in Fx_show_tip, and it leads to
7848 problems because the tip frame has no widget. */
7849 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
7850 x_set_window_size (f
, 0, FRAME_COLS (f
), FRAME_LINES (f
));
7855 && (FRAME_XIC_STYLE (f
) & (XIMPreeditPosition
| XIMStatusArea
)))
7858 xic_set_xfontset (f
, SDATA (fontset_ascii (fontset
)));
7867 /***********************************************************************
7869 ***********************************************************************/
7875 /* XIM destroy callback function, which is called whenever the
7876 connection to input method XIM dies. CLIENT_DATA contains a
7877 pointer to the x_display_info structure corresponding to XIM. */
7880 xim_destroy_callback (XIM xim
, XPointer client_data
, XPointer call_data
)
7882 struct x_display_info
*dpyinfo
= (struct x_display_info
*) client_data
;
7883 Lisp_Object frame
, tail
;
7887 /* No need to call XDestroyIC.. */
7888 FOR_EACH_FRAME (tail
, frame
)
7890 struct frame
*f
= XFRAME (frame
);
7891 if (FRAME_X_P (f
) && FRAME_X_DISPLAY_INFO (f
) == dpyinfo
)
7893 FRAME_XIC (f
) = NULL
;
7894 xic_free_xfontset (f
);
7898 /* No need to call XCloseIM. */
7899 dpyinfo
->xim
= NULL
;
7900 XFree (dpyinfo
->xim_styles
);
7904 #endif /* HAVE_X11R6 */
7907 /* This isn't prototyped in OSF 5.0 or 5.1a. */
7908 extern char *XSetIMValues (XIM
, ...);
7911 /* Open the connection to the XIM server on display DPYINFO.
7912 RESOURCE_NAME is the resource name Emacs uses. */
7915 xim_open_dpy (struct x_display_info
*dpyinfo
, char *resource_name
)
7923 XCloseIM (dpyinfo
->xim
);
7924 xim
= XOpenIM (dpyinfo
->display
, dpyinfo
->xrdb
, resource_name
,
7931 XIMCallback destroy
;
7934 /* Get supported styles and XIM values. */
7935 XGetIMValues (xim
, XNQueryInputStyle
, &dpyinfo
->xim_styles
, NULL
);
7938 destroy
.callback
= xim_destroy_callback
;
7939 destroy
.client_data
= (XPointer
)dpyinfo
;
7940 XSetIMValues (xim
, XNDestroyCallback
, &destroy
, NULL
);
7946 #endif /* HAVE_XIM */
7947 dpyinfo
->xim
= NULL
;
7951 #ifdef HAVE_X11R6_XIM
7953 /* XIM instantiate callback function, which is called whenever an XIM
7954 server is available. DISPLAY is the display of the XIM.
7955 CLIENT_DATA contains a pointer to an xim_inst_t structure created
7956 when the callback was registered. */
7959 xim_instantiate_callback (Display
*display
, XPointer client_data
, XPointer call_data
)
7961 struct xim_inst_t
*xim_inst
= (struct xim_inst_t
*) client_data
;
7962 struct x_display_info
*dpyinfo
= xim_inst
->dpyinfo
;
7964 /* We don't support multiple XIM connections. */
7968 xim_open_dpy (dpyinfo
, xim_inst
->resource_name
);
7970 /* Create XIC for the existing frames on the same display, as long
7971 as they have no XIC. */
7972 if (dpyinfo
->xim
&& dpyinfo
->reference_count
> 0)
7974 Lisp_Object tail
, frame
;
7977 FOR_EACH_FRAME (tail
, frame
)
7979 struct frame
*f
= XFRAME (frame
);
7982 && FRAME_X_DISPLAY_INFO (f
) == xim_inst
->dpyinfo
)
7983 if (FRAME_XIC (f
) == NULL
)
7985 create_frame_xic (f
);
7986 if (FRAME_XIC_STYLE (f
) & XIMStatusArea
)
7987 xic_set_statusarea (f
);
7988 if (FRAME_XIC_STYLE (f
) & XIMPreeditPosition
)
7990 struct window
*w
= XWINDOW (f
->selected_window
);
7991 xic_set_preeditarea (w
, w
->cursor
.x
, w
->cursor
.y
);
8000 #endif /* HAVE_X11R6_XIM */
8003 /* Open a connection to the XIM server on display DPYINFO.
8004 RESOURCE_NAME is the resource name for Emacs. On X11R5, open the
8005 connection only at the first time. On X11R6, open the connection
8006 in the XIM instantiate callback function. */
8009 xim_initialize (struct x_display_info
*dpyinfo
, char *resource_name
)
8011 dpyinfo
->xim
= NULL
;
8015 #ifdef HAVE_X11R6_XIM
8016 struct xim_inst_t
*xim_inst
;
8019 xim_inst
= (struct xim_inst_t
*) xmalloc (sizeof (struct xim_inst_t
));
8020 dpyinfo
->xim_callback_data
= xim_inst
;
8021 xim_inst
->dpyinfo
= dpyinfo
;
8022 len
= strlen (resource_name
);
8023 xim_inst
->resource_name
= (char *) xmalloc (len
+ 1);
8024 memcpy (xim_inst
->resource_name
, resource_name
, len
+ 1);
8025 XRegisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8026 resource_name
, EMACS_CLASS
,
8027 xim_instantiate_callback
,
8028 /* This is XPointer in XFree86
8029 but (XPointer *) on Tru64, at
8030 least, hence the configure test. */
8031 (XRegisterIMInstantiateCallback_arg6
) xim_inst
);
8032 #else /* not HAVE_X11R6_XIM */
8033 xim_open_dpy (dpyinfo
, resource_name
);
8034 #endif /* not HAVE_X11R6_XIM */
8036 #endif /* HAVE_XIM */
8040 /* Close the connection to the XIM server on display DPYINFO. */
8043 xim_close_dpy (struct x_display_info
*dpyinfo
)
8048 #ifdef HAVE_X11R6_XIM
8049 if (dpyinfo
->display
)
8050 XUnregisterIMInstantiateCallback (dpyinfo
->display
, dpyinfo
->xrdb
,
8052 xim_instantiate_callback
, NULL
);
8053 xfree (dpyinfo
->xim_callback_data
->resource_name
);
8054 xfree (dpyinfo
->xim_callback_data
);
8055 #endif /* HAVE_X11R6_XIM */
8056 if (dpyinfo
->display
)
8057 XCloseIM (dpyinfo
->xim
);
8058 dpyinfo
->xim
= NULL
;
8059 XFree (dpyinfo
->xim_styles
);
8061 #endif /* HAVE_XIM */
8064 #endif /* not HAVE_X11R6_XIM */
8068 /* Calculate the absolute position in frame F
8069 from its current recorded position values and gravity. */
8072 x_calc_absolute_position (struct frame
*f
)
8074 int flags
= f
->size_hint_flags
;
8076 /* We have nothing to do if the current position
8077 is already for the top-left corner. */
8078 if (! ((flags
& XNegative
) || (flags
& YNegative
)))
8081 /* Treat negative positions as relative to the leftmost bottommost
8082 position that fits on the screen. */
8083 if (flags
& XNegative
)
8084 f
->left_pos
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
8085 - FRAME_PIXEL_WIDTH (f
) + f
->left_pos
;
8088 int height
= FRAME_PIXEL_HEIGHT (f
);
8090 #if defined USE_X_TOOLKIT && defined USE_MOTIF
8091 /* Something is fishy here. When using Motif, starting Emacs with
8092 `-g -0-0', the frame appears too low by a few pixels.
8094 This seems to be so because initially, while Emacs is starting,
8095 the column widget's height and the frame's pixel height are
8096 different. The column widget's height is the right one. In
8097 later invocations, when Emacs is up, the frame's pixel height
8100 It's not obvious where the initial small difference comes from.
8101 2000-12-01, gerd. */
8103 XtVaGetValues (f
->output_data
.x
->column_widget
, XtNheight
, &height
, NULL
);
8106 if (flags
& YNegative
)
8107 f
->top_pos
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
8108 - height
+ f
->top_pos
;
8111 /* The left_pos and top_pos
8112 are now relative to the top and left screen edges,
8113 so the flags should correspond. */
8114 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8117 /* CHANGE_GRAVITY is 1 when calling from Fset_frame_position,
8118 to really change the position, and 0 when calling from
8119 x_make_frame_visible (in that case, XOFF and YOFF are the current
8120 position values). It is -1 when calling from x_set_frame_parameters,
8121 which means, do adjust for borders but don't change the gravity. */
8124 x_set_offset (struct frame
*f
, register int xoff
, register int yoff
, int change_gravity
)
8126 int modified_top
, modified_left
;
8128 if (change_gravity
> 0)
8130 FRAME_X_OUTPUT (f
)->left_before_move
= f
->left_pos
;
8131 FRAME_X_OUTPUT (f
)->top_before_move
= f
->top_pos
;
8135 f
->size_hint_flags
&= ~ (XNegative
| YNegative
);
8137 f
->size_hint_flags
|= XNegative
;
8139 f
->size_hint_flags
|= YNegative
;
8140 f
->win_gravity
= NorthWestGravity
;
8142 x_calc_absolute_position (f
);
8145 x_wm_set_size_hint (f
, (long) 0, 0);
8147 modified_left
= f
->left_pos
;
8148 modified_top
= f
->top_pos
;
8150 if (change_gravity
!= 0 && FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
)
8152 /* Some WMs (twm, wmaker at least) has an offset that is smaller
8153 than the WM decorations. So we use the calculated offset instead
8154 of the WM decoration sizes here (x/y_pixels_outer_diff). */
8155 modified_left
+= FRAME_X_OUTPUT (f
)->move_offset_left
;
8156 modified_top
+= FRAME_X_OUTPUT (f
)->move_offset_top
;
8159 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8160 modified_left
, modified_top
);
8162 x_sync_with_move (f
, f
->left_pos
, f
->top_pos
,
8163 FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8166 /* change_gravity is non-zero when this function is called from Lisp to
8167 programmatically move a frame. In that case, we call
8168 x_check_expected_move to discover if we have a "Type A" or "Type B"
8169 window manager, and, for a "Type A" window manager, adjust the position
8172 We call x_check_expected_move if a programmatic move occurred, and
8173 either the window manager type (A/B) is unknown or it is Type A but we
8174 need to compute the top/left offset adjustment for this frame. */
8176 if (change_gravity
!= 0 &&
8177 (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_UNKNOWN
8178 || (FRAME_X_DISPLAY_INFO (f
)->wm_type
== X_WMTYPE_A
8179 && (FRAME_X_OUTPUT (f
)->move_offset_left
== 0
8180 && FRAME_X_OUTPUT (f
)->move_offset_top
== 0))))
8181 x_check_expected_move (f
, modified_left
, modified_top
);
8186 /* Return non-zero if _NET_SUPPORTING_WM_CHECK window exists and _NET_SUPPORTED
8187 on the root window for frame F contains ATOMNAME.
8188 This is how a WM check shall be done according to the Window Manager
8189 Specification/Extended Window Manager Hints at
8190 http://freedesktop.org/wiki/Specifications/wm-spec. */
8193 wm_supports (struct frame
*f
, const char *atomname
)
8196 unsigned long actual_size
, bytes_remaining
;
8197 int i
, rc
, actual_format
;
8199 Window wmcheck_window
;
8200 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8201 Window target_window
= dpyinfo
->root_window
;
8202 long max_len
= 65536;
8203 Display
*dpy
= FRAME_X_DISPLAY (f
);
8204 unsigned char *tmp_data
= NULL
;
8205 Atom target_type
= XA_WINDOW
;
8210 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTING_WM_CHECK", False
);
8212 x_catch_errors (dpy
);
8213 rc
= XGetWindowProperty (dpy
, target_window
,
8214 prop_atom
, 0, max_len
, False
, target_type
,
8215 &actual_type
, &actual_format
, &actual_size
,
8216 &bytes_remaining
, &tmp_data
);
8218 if (rc
!= Success
|| actual_type
!= XA_WINDOW
|| x_had_errors_p (dpy
))
8220 if (tmp_data
) XFree (tmp_data
);
8221 x_uncatch_errors ();
8226 wmcheck_window
= *(Window
*) tmp_data
;
8229 /* Check if window exists. */
8230 XSelectInput (dpy
, wmcheck_window
, StructureNotifyMask
);
8232 if (x_had_errors_p (dpy
))
8234 x_uncatch_errors ();
8239 if (dpyinfo
->net_supported_window
!= wmcheck_window
)
8241 /* Window changed, reload atoms */
8242 if (dpyinfo
->net_supported_atoms
!= NULL
)
8243 XFree (dpyinfo
->net_supported_atoms
);
8244 dpyinfo
->net_supported_atoms
= NULL
;
8245 dpyinfo
->nr_net_supported_atoms
= 0;
8246 dpyinfo
->net_supported_window
= 0;
8248 target_type
= XA_ATOM
;
8249 prop_atom
= XInternAtom (dpy
, "_NET_SUPPORTED", False
);
8251 rc
= XGetWindowProperty (dpy
, target_window
,
8252 prop_atom
, 0, max_len
, False
, target_type
,
8253 &actual_type
, &actual_format
, &actual_size
,
8254 &bytes_remaining
, &tmp_data
);
8256 if (rc
!= Success
|| actual_type
!= XA_ATOM
|| x_had_errors_p (dpy
))
8258 if (tmp_data
) XFree (tmp_data
);
8259 x_uncatch_errors ();
8264 dpyinfo
->net_supported_atoms
= (Atom
*)tmp_data
;
8265 dpyinfo
->nr_net_supported_atoms
= actual_size
;
8266 dpyinfo
->net_supported_window
= wmcheck_window
;
8270 want_atom
= XInternAtom (dpy
, atomname
, False
);
8272 for (i
= 0; rc
== 0 && i
< dpyinfo
->nr_net_supported_atoms
; ++i
)
8273 rc
= dpyinfo
->net_supported_atoms
[i
] == want_atom
;
8275 x_uncatch_errors ();
8282 set_wm_state (Lisp_Object frame
, int add
, const char *what
, const char *what2
)
8284 const char *atom
= "_NET_WM_STATE";
8285 Fx_send_client_event (frame
, make_number (0), frame
,
8286 make_unibyte_string (atom
, strlen (atom
)),
8288 /* 1 = add, 0 = remove */
8290 (make_number (add
? 1 : 0),
8292 (make_unibyte_string (what
, strlen (what
)),
8294 ? Fcons (make_unibyte_string (what2
, strlen (what2
)),
8300 x_set_sticky (struct frame
*f
, Lisp_Object new_value
, Lisp_Object old_value
)
8304 XSETFRAME (frame
, f
);
8305 set_wm_state (frame
, NILP (new_value
) ? 0 : 1,
8306 "_NET_WM_STATE_STICKY", NULL
);
8309 /* Do fullscreen as specified in extended window manager hints */
8312 do_ewmh_fullscreen (struct frame
*f
)
8314 int have_net_atom
= wm_supports (f
, "_NET_WM_STATE");
8316 /* Some window managers don't say they support _NET_WM_STATE, but they do say
8317 they support _NET_WM_STATE_FULLSCREEN. Try that also. */
8319 have_net_atom
= wm_supports (f
, "_NET_WM_STATE_FULLSCREEN");
8324 const char *fs
= "_NET_WM_STATE_FULLSCREEN";
8325 const char *fw
= "_NET_WM_STATE_MAXIMIZED_HORZ";
8326 const char *fh
= "_NET_WM_STATE_MAXIMIZED_VERT";
8328 XSETFRAME (frame
, f
);
8330 set_wm_state (frame
, 0, fs
, NULL
);
8331 set_wm_state (frame
, 0, fh
, NULL
);
8332 set_wm_state (frame
, 0, fw
, NULL
);
8334 /* If there are _NET_ atoms we assume we have extended window manager
8336 switch (f
->want_fullscreen
)
8338 case FULLSCREEN_BOTH
:
8339 set_wm_state (frame
, 1, fs
, NULL
);
8341 case FULLSCREEN_WIDTH
:
8342 set_wm_state (frame
, 1, fw
, NULL
);
8344 case FULLSCREEN_HEIGHT
:
8345 set_wm_state (frame
, 1, fh
, NULL
);
8347 case FULLSCREEN_MAXIMIZED
:
8348 set_wm_state (frame
, 1, fw
, fh
);
8352 f
->want_fullscreen
= FULLSCREEN_NONE
;
8356 return have_net_atom
;
8360 XTfullscreen_hook (FRAME_PTR f
)
8362 if (f
->async_visible
)
8365 x_check_fullscreen (f
);
8373 x_handle_net_wm_state (struct frame
*f
, XPropertyEvent
*event
)
8376 unsigned long actual_size
, bytes_remaining
;
8377 int i
, rc
, actual_format
, value
= FULLSCREEN_NONE
;
8378 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8379 long max_len
= 65536;
8380 Display
*dpy
= FRAME_X_DISPLAY (f
);
8381 unsigned char *tmp_data
= NULL
;
8382 Atom target_type
= XA_ATOM
;
8387 x_catch_errors (dpy
);
8388 rc
= XGetWindowProperty (dpy
, event
->window
,
8389 event
->atom
, 0, max_len
, False
, target_type
,
8390 &actual_type
, &actual_format
, &actual_size
,
8391 &bytes_remaining
, &tmp_data
);
8393 if (rc
!= Success
|| actual_type
!= target_type
|| x_had_errors_p (dpy
))
8395 if (tmp_data
) XFree (tmp_data
);
8396 x_uncatch_errors ();
8401 x_uncatch_errors ();
8403 for (i
= 0; i
< actual_size
; ++i
)
8405 Atom a
= ((Atom
*)tmp_data
)[i
];
8406 if (a
== dpyinfo
->Xatom_net_wm_state_maximized_horz
)
8408 if (value
== FULLSCREEN_HEIGHT
)
8409 value
= FULLSCREEN_MAXIMIZED
;
8411 value
= FULLSCREEN_WIDTH
;
8413 else if (a
== dpyinfo
->Xatom_net_wm_state_maximized_vert
)
8415 if (value
== FULLSCREEN_WIDTH
)
8416 value
= FULLSCREEN_MAXIMIZED
;
8418 value
= FULLSCREEN_HEIGHT
;
8420 else if (a
== dpyinfo
->Xatom_net_wm_state_fullscreen_atom
)
8421 value
= FULLSCREEN_BOTH
;
8422 else if (a
== dpyinfo
->Xatom_net_wm_state_sticky
)
8429 case FULLSCREEN_WIDTH
:
8432 case FULLSCREEN_HEIGHT
:
8435 case FULLSCREEN_BOTH
:
8438 case FULLSCREEN_MAXIMIZED
:
8443 store_frame_param (f
, Qfullscreen
, lval
);
8444 store_frame_param (f
, Qsticky
, sticky
? Qt
: Qnil
);
8446 if (tmp_data
) XFree (tmp_data
);
8450 /* Check if we need to resize the frame due to a fullscreen request.
8451 If so needed, resize the frame. */
8453 x_check_fullscreen (struct frame
*f
)
8455 if (do_ewmh_fullscreen (f
))
8458 if (f
->output_data
.x
->parent_desc
!= FRAME_X_DISPLAY_INFO (f
)->root_window
)
8459 return; /* Only fullscreen without WM or with EWM hints (above). */
8461 if (f
->want_fullscreen
!= FULLSCREEN_NONE
)
8463 int width
= FRAME_COLS (f
), height
= FRAME_LINES (f
);
8464 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
8466 switch (f
->want_fullscreen
)
8468 /* No difference between these two when there is no WM */
8469 case FULLSCREEN_BOTH
:
8470 case FULLSCREEN_MAXIMIZED
:
8471 width
= x_display_pixel_width (dpyinfo
);
8472 height
= x_display_pixel_height (dpyinfo
);
8474 case FULLSCREEN_WIDTH
:
8475 width
= x_display_pixel_width (dpyinfo
);
8477 case FULLSCREEN_HEIGHT
:
8478 height
= x_display_pixel_height (dpyinfo
);
8481 if (FRAME_COLS (f
) != width
|| FRAME_LINES (f
) != height
)
8483 change_frame_size (f
, height
, width
, 0, 1, 0);
8484 SET_FRAME_GARBAGED (f
);
8485 cancel_mouse_face (f
);
8490 /* This function is called by x_set_offset to determine whether the window
8491 manager interfered with the positioning of the frame. Type A window
8492 managers position the surrounding window manager decorations a small
8493 amount above and left of the user-supplied position. Type B window
8494 managers position the surrounding window manager decorations at the
8495 user-specified position. If we detect a Type A window manager, we
8496 compensate by moving the window right and down by the proper amount. */
8499 x_check_expected_move (struct frame
*f
, int expected_left
, int expected_top
)
8501 int current_left
= 0, current_top
= 0;
8503 /* x_real_positions returns the left and top offsets of the outermost
8504 window manager window around the frame. */
8506 x_real_positions (f
, ¤t_left
, ¤t_top
);
8508 if (current_left
!= expected_left
|| current_top
!= expected_top
)
8510 /* It's a "Type A" window manager. */
8515 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_A
;
8516 FRAME_X_OUTPUT (f
)->move_offset_left
= expected_left
- current_left
;
8517 FRAME_X_OUTPUT (f
)->move_offset_top
= expected_top
- current_top
;
8519 /* Now fix the mispositioned frame's location. */
8521 adjusted_left
= expected_left
+ FRAME_X_OUTPUT (f
)->move_offset_left
;
8522 adjusted_top
= expected_top
+ FRAME_X_OUTPUT (f
)->move_offset_top
;
8524 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8525 adjusted_left
, adjusted_top
);
8527 x_sync_with_move (f
, expected_left
, expected_top
, 0);
8530 /* It's a "Type B" window manager. We don't have to adjust the
8531 frame's position. */
8533 FRAME_X_DISPLAY_INFO (f
)->wm_type
= X_WMTYPE_B
;
8537 /* Wait for XGetGeometry to return up-to-date position information for a
8538 recently-moved frame. Call this immediately after calling XMoveWindow.
8539 If FUZZY is non-zero, then LEFT and TOP are just estimates of where the
8540 frame has been moved to, so we use a fuzzy position comparison instead
8541 of an exact comparison. */
8544 x_sync_with_move (struct frame
*f
, int left
, int top
, int fuzzy
)
8548 while (count
++ < 50)
8550 int current_left
= 0, current_top
= 0;
8552 /* In theory, this call to XSync only needs to happen once, but in
8553 practice, it doesn't seem to work, hence the need for the surrounding
8556 XSync (FRAME_X_DISPLAY (f
), False
);
8557 x_real_positions (f
, ¤t_left
, ¤t_top
);
8561 /* The left fuzz-factor is 10 pixels. The top fuzz-factor is 40
8564 if (eabs (current_left
- left
) <= 10
8565 && eabs (current_top
- top
) <= 40)
8568 else if (current_left
== left
&& current_top
== top
)
8572 /* As a last resort, just wait 0.5 seconds and hope that XGetGeometry
8573 will then return up-to-date position info. */
8575 wait_reading_process_output (0, 500000, 0, 0, Qnil
, NULL
, 0);
8579 /* Wait for an event on frame F matching EVENTTYPE. */
8581 x_wait_for_event (struct frame
*f
, int eventtype
)
8583 int level
= interrupt_input_blocked
;
8586 EMACS_TIME tmo
, tmo_at
, time_now
;
8587 int fd
= ConnectionNumber (FRAME_X_DISPLAY (f
));
8589 pending_event_wait
.f
= f
;
8590 pending_event_wait
.eventtype
= eventtype
;
8592 /* Set timeout to 0.1 second. Hopefully not noticable.
8593 Maybe it should be configurable. */
8594 EMACS_SET_SECS_USECS (tmo
, 0, 100000);
8595 EMACS_GET_TIME (tmo_at
);
8596 EMACS_ADD_TIME (tmo_at
, tmo_at
, tmo
);
8598 while (pending_event_wait
.eventtype
)
8600 interrupt_input_pending
= 1;
8601 TOTALLY_UNBLOCK_INPUT
;
8602 /* XTread_socket is called after unblock. */
8604 interrupt_input_blocked
= level
;
8609 EMACS_GET_TIME (time_now
);
8610 EMACS_SUB_TIME (tmo
, tmo_at
, time_now
);
8612 if (EMACS_TIME_NEG_P (tmo
) || select (fd
+1, &fds
, NULL
, NULL
, &tmo
) == 0)
8613 break; /* Timeout */
8615 pending_event_wait
.f
= 0;
8616 pending_event_wait
.eventtype
= 0;
8620 /* Change the size of frame F's X window to COLS/ROWS in the case F
8621 doesn't have a widget. If CHANGE_GRAVITY is 1, we change to
8622 top-left-corner window gravity for this size change and subsequent
8623 size changes. Otherwise we leave the window gravity unchanged. */
8626 x_set_window_size_1 (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8628 int pixelwidth
, pixelheight
;
8630 check_frame_size (f
, &rows
, &cols
);
8631 f
->scroll_bar_actual_width
8632 = (!FRAME_HAS_VERTICAL_SCROLL_BARS (f
)
8634 : FRAME_CONFIG_SCROLL_BAR_WIDTH (f
) > 0
8635 ? FRAME_CONFIG_SCROLL_BAR_WIDTH (f
)
8636 : (FRAME_CONFIG_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
)));
8638 compute_fringe_widths (f
, 0);
8640 pixelwidth
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, cols
);
8641 pixelheight
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, rows
)
8642 + FRAME_MENUBAR_HEIGHT (f
) + FRAME_TOOLBAR_HEIGHT (f
);
8644 if (change_gravity
) f
->win_gravity
= NorthWestGravity
;
8645 x_wm_set_size_hint (f
, (long) 0, 0);
8646 XResizeWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
8647 pixelwidth
, pixelheight
);
8650 /* We've set {FRAME,PIXEL}_{WIDTH,HEIGHT} to the values we hope to
8651 receive in the ConfigureNotify event; if we get what we asked
8652 for, then the event won't cause the screen to become garbaged, so
8653 we have to make sure to do it here. */
8654 SET_FRAME_GARBAGED (f
);
8656 /* Now, strictly speaking, we can't be sure that this is accurate,
8657 but the window manager will get around to dealing with the size
8658 change request eventually, and we'll hear how it went when the
8659 ConfigureNotify event gets here.
8661 We could just not bother storing any of this information here,
8662 and let the ConfigureNotify event set everything up, but that
8663 might be kind of confusing to the Lisp code, since size changes
8664 wouldn't be reported in the frame parameters until some random
8665 point in the future when the ConfigureNotify event arrives.
8667 We pass 1 for DELAY since we can't run Lisp code inside of
8670 /* But the ConfigureNotify may in fact never arrive, and then this is
8671 not right if the frame is visible. Instead wait (with timeout)
8672 for the ConfigureNotify. */
8673 if (f
->async_visible
)
8674 x_wait_for_event (f
, ConfigureNotify
);
8677 change_frame_size (f
, rows
, cols
, 0, 1, 0);
8678 FRAME_PIXEL_WIDTH (f
) = pixelwidth
;
8679 FRAME_PIXEL_HEIGHT (f
) = pixelheight
;
8685 /* Call this to change the size of frame F's x-window.
8686 If CHANGE_GRAVITY is 1, we change to top-left-corner window gravity
8687 for this size change and subsequent size changes.
8688 Otherwise we leave the window gravity unchanged. */
8691 x_set_window_size (struct frame
*f
, int change_gravity
, int cols
, int rows
)
8695 if (NILP (tip_frame
) || XFRAME (tip_frame
) != f
)
8699 /* When the frame is maximized/fullscreen or running under for
8700 example Xmonad, x_set_window_size_1 will be a no-op.
8701 In that case, the right thing to do is extend rows/cols to
8702 the current frame size. We do that first if x_set_window_size_1
8703 turns out to not be a no-op (there is no way to know).
8704 The size will be adjusted again if the frame gets a
8705 ConfigureNotify event as a result of x_set_window_size. */
8706 int pixelh
= FRAME_PIXEL_HEIGHT (f
);
8707 #ifdef USE_X_TOOLKIT
8708 /* The menu bar is not part of text lines. The tool bar
8710 pixelh
-= FRAME_MENUBAR_HEIGHT (f
);
8712 r
= FRAME_PIXEL_HEIGHT_TO_TEXT_LINES (f
, pixelh
);
8713 /* Update f->scroll_bar_actual_width because it is used in
8714 FRAME_PIXEL_WIDTH_TO_TEXT_COLS. */
8715 f
->scroll_bar_actual_width
8716 = FRAME_SCROLL_BAR_COLS (f
) * FRAME_COLUMN_WIDTH (f
);
8717 c
= FRAME_PIXEL_WIDTH_TO_TEXT_COLS (f
, FRAME_PIXEL_WIDTH (f
));
8718 change_frame_size (f
, r
, c
, 0, 1, 0);
8722 if (FRAME_GTK_WIDGET (f
))
8723 xg_frame_set_char_size (f
, cols
, rows
);
8725 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8726 #else /* not USE_GTK */
8728 x_set_window_size_1 (f
, change_gravity
, cols
, rows
);
8730 #endif /* not USE_GTK */
8732 /* If cursor was outside the new size, mark it as off. */
8733 mark_window_cursors_off (XWINDOW (f
->root_window
));
8735 /* Clear out any recollection of where the mouse highlighting was,
8736 since it might be in a place that's outside the new frame size.
8737 Actually checking whether it is outside is a pain in the neck,
8738 so don't try--just let the highlighting be done afresh with new size. */
8739 cancel_mouse_face (f
);
8744 /* Mouse warping. */
8747 x_set_mouse_position (struct frame
*f
, int x
, int y
)
8751 pix_x
= FRAME_COL_TO_PIXEL_X (f
, x
) + FRAME_COLUMN_WIDTH (f
) / 2;
8752 pix_y
= FRAME_LINE_TO_PIXEL_Y (f
, y
) + FRAME_LINE_HEIGHT (f
) / 2;
8754 if (pix_x
< 0) pix_x
= 0;
8755 if (pix_x
> FRAME_PIXEL_WIDTH (f
)) pix_x
= FRAME_PIXEL_WIDTH (f
);
8757 if (pix_y
< 0) pix_y
= 0;
8758 if (pix_y
> FRAME_PIXEL_HEIGHT (f
)) pix_y
= FRAME_PIXEL_HEIGHT (f
);
8762 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8763 0, 0, 0, 0, pix_x
, pix_y
);
8767 /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */
8770 x_set_mouse_pixel_position (struct frame
*f
, int pix_x
, int pix_y
)
8774 XWarpPointer (FRAME_X_DISPLAY (f
), None
, FRAME_X_WINDOW (f
),
8775 0, 0, 0, 0, pix_x
, pix_y
);
8779 /* focus shifting, raising and lowering. */
8782 x_focus_on_frame (struct frame
*f
)
8785 /* I don't think that the ICCCM allows programs to do things like this
8786 without the interaction of the window manager. Whatever you end up
8787 doing with this code, do it to x_unfocus_frame too. */
8788 XSetInputFocus (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
),
8789 RevertToPointerRoot
, CurrentTime
);
8794 x_unfocus_frame (struct frame
*f
)
8797 /* Look at the remarks in x_focus_on_frame. */
8798 if (FRAME_X_DISPLAY_INFO (f
)->x_focus_frame
== f
)
8799 XSetInputFocus (FRAME_X_DISPLAY (f
), PointerRoot
,
8800 RevertToPointerRoot
, CurrentTime
);
8804 /* Raise frame F. */
8807 x_raise_frame (struct frame
*f
)
8810 if (f
->async_visible
)
8811 XRaiseWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8813 XFlush (FRAME_X_DISPLAY (f
));
8817 /* Lower frame F. */
8820 x_lower_frame (struct frame
*f
)
8822 if (f
->async_visible
)
8825 XLowerWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
));
8826 XFlush (FRAME_X_DISPLAY (f
));
8831 /* Activate frame with Extended Window Manager Hints */
8834 x_ewmh_activate_frame (FRAME_PTR f
)
8836 /* See Window Manager Specification/Extended Window Manager Hints at
8837 http://freedesktop.org/wiki/Specifications/wm-spec */
8839 const char *atom
= "_NET_ACTIVE_WINDOW";
8840 if (f
->async_visible
&& wm_supports (f
, atom
))
8843 XSETFRAME (frame
, f
);
8844 Fx_send_client_event (frame
, make_number (0), frame
,
8845 make_unibyte_string (atom
, strlen (atom
)),
8847 Fcons (make_number (1),
8848 Fcons (make_number (last_user_time
),
8854 XTframe_raise_lower (FRAME_PTR f
, int raise_flag
)
8862 /* XEmbed implementation. */
8865 xembed_set_info (struct frame
*f
, enum xembed_info flags
)
8868 unsigned long data
[2];
8870 atom
= XInternAtom (FRAME_X_DISPLAY (f
), "_XEMBED_INFO", False
);
8872 data
[0] = XEMBED_VERSION
;
8875 XChangeProperty (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
), atom
, atom
,
8876 32, PropModeReplace
, (unsigned char *) data
, 2);
8880 xembed_send_message (struct frame
*f
, Time time
, enum xembed_message message
, long int detail
, long int data1
, long int data2
)
8884 event
.xclient
.type
= ClientMessage
;
8885 event
.xclient
.window
= FRAME_X_OUTPUT (f
)->parent_desc
;
8886 event
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_XEMBED
;
8887 event
.xclient
.format
= 32;
8888 event
.xclient
.data
.l
[0] = time
;
8889 event
.xclient
.data
.l
[1] = message
;
8890 event
.xclient
.data
.l
[2] = detail
;
8891 event
.xclient
.data
.l
[3] = data1
;
8892 event
.xclient
.data
.l
[4] = data2
;
8894 XSendEvent (FRAME_X_DISPLAY (f
), FRAME_X_OUTPUT (f
)->parent_desc
,
8895 False
, NoEventMask
, &event
);
8896 XSync (FRAME_X_DISPLAY (f
), False
);
8899 /* Change of visibility. */
8901 /* This tries to wait until the frame is really visible.
8902 However, if the window manager asks the user where to position
8903 the frame, this will return before the user finishes doing that.
8904 The frame will not actually be visible at that time,
8905 but it will become visible later when the window manager
8906 finishes with it. */
8909 x_make_frame_visible (struct frame
*f
)
8912 int original_top
, original_left
;
8913 int retry_count
= 2;
8919 type
= x_icon_type (f
);
8921 x_bitmap_icon (f
, type
);
8923 if (! FRAME_VISIBLE_P (f
))
8925 /* We test FRAME_GARBAGED_P here to make sure we don't
8926 call x_set_offset a second time
8927 if we get to x_make_frame_visible a second time
8928 before the window gets really visible. */
8929 if (! FRAME_ICONIFIED_P (f
)
8930 && ! FRAME_X_EMBEDDED_P (f
)
8931 && ! f
->output_data
.x
->asked_for_visible
)
8932 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
8934 f
->output_data
.x
->asked_for_visible
= 1;
8936 if (! EQ (Vx_no_window_manager
, Qt
))
8937 x_wm_set_window_state (f
, NormalState
);
8938 #ifdef USE_X_TOOLKIT
8939 if (FRAME_X_EMBEDDED_P (f
))
8940 xembed_set_info (f
, XEMBED_MAPPED
);
8943 /* This was XtPopup, but that did nothing for an iconified frame. */
8944 XtMapWidget (f
->output_data
.x
->widget
);
8946 #else /* not USE_X_TOOLKIT */
8948 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
8949 gtk_window_deiconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
8951 if (FRAME_X_EMBEDDED_P (f
))
8952 xembed_set_info (f
, XEMBED_MAPPED
);
8954 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
8955 #endif /* not USE_GTK */
8956 #endif /* not USE_X_TOOLKIT */
8959 XFlush (FRAME_X_DISPLAY (f
));
8961 /* Synchronize to ensure Emacs knows the frame is visible
8962 before we do anything else. We do this loop with input not blocked
8963 so that incoming events are handled. */
8967 /* This must be before UNBLOCK_INPUT
8968 since events that arrive in response to the actions above
8969 will set it when they are handled. */
8970 int previously_visible
= f
->output_data
.x
->has_been_visible
;
8972 original_left
= f
->left_pos
;
8973 original_top
= f
->top_pos
;
8975 /* This must come after we set COUNT. */
8978 /* We unblock here so that arriving X events are processed. */
8980 /* Now move the window back to where it was "supposed to be".
8981 But don't do it if the gravity is negative.
8982 When the gravity is negative, this uses a position
8983 that is 3 pixels too low. Perhaps that's really the border width.
8985 Don't do this if the window has never been visible before,
8986 because the window manager may choose the position
8987 and we don't want to override it. */
8989 if (! FRAME_VISIBLE_P (f
)
8990 && ! FRAME_ICONIFIED_P (f
)
8991 && ! FRAME_X_EMBEDDED_P (f
)
8992 && f
->win_gravity
== NorthWestGravity
8993 && previously_visible
)
8997 unsigned int width
, height
, border
, depth
;
9001 /* On some window managers (such as FVWM) moving an existing
9002 window, even to the same place, causes the window manager
9003 to introduce an offset. This can cause the window to move
9004 to an unexpected location. Check the geometry (a little
9005 slow here) and then verify that the window is in the right
9006 place. If the window is not in the right place, move it
9007 there, and take the potential window manager hit. */
9008 XGetGeometry (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9009 &rootw
, &x
, &y
, &width
, &height
, &border
, &depth
);
9011 if (original_left
!= x
|| original_top
!= y
)
9012 XMoveWindow (FRAME_X_DISPLAY (f
), FRAME_OUTER_WINDOW (f
),
9013 original_left
, original_top
);
9018 XSETFRAME (frame
, f
);
9020 /* Wait until the frame is visible. Process X events until a
9021 MapNotify event has been seen, or until we think we won't get a
9022 MapNotify at all.. */
9023 for (count
= input_signal_count
+ 10;
9024 input_signal_count
< count
&& !FRAME_VISIBLE_P (f
);)
9026 /* Force processing of queued events. */
9029 /* Machines that do polling rather than SIGIO have been
9030 observed to go into a busy-wait here. So we'll fake an
9031 alarm signal to let the handler know that there's something
9032 to be read. We used to raise a real alarm, but it seems
9033 that the handler isn't always enabled here. This is
9035 if (input_polling_used ())
9037 /* It could be confusing if a real alarm arrives while
9038 processing the fake one. Turn it off and let the
9039 handler reset it. */
9040 extern void poll_for_input_1 (void);
9041 int old_poll_suppress_count
= poll_suppress_count
;
9042 poll_suppress_count
= 1;
9043 poll_for_input_1 ();
9044 poll_suppress_count
= old_poll_suppress_count
;
9047 /* See if a MapNotify event has been processed. */
9048 FRAME_SAMPLE_VISIBILITY (f
);
9053 (let ((f (selected-frame)))
9057 the frame is not raised with various window managers on
9058 FreeBSD, GNU/Linux and Solaris. It turns out that, for some
9059 unknown reason, the call to XtMapWidget is completely ignored.
9060 Mapping the widget a second time works. */
9062 if (!FRAME_VISIBLE_P (f
) && --retry_count
> 0)
9067 /* Change from mapped state to withdrawn state. */
9069 /* Make the frame visible (mapped and not iconified). */
9072 x_make_frame_invisible (struct frame
*f
)
9076 /* Use the frame's outermost window, not the one we normally draw on. */
9077 window
= FRAME_OUTER_WINDOW (f
);
9079 /* Don't keep the highlight on an invisible frame. */
9080 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9081 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9085 /* Before unmapping the window, update the WM_SIZE_HINTS property to claim
9086 that the current position of the window is user-specified, rather than
9087 program-specified, so that when the window is mapped again, it will be
9088 placed at the same location, without forcing the user to position it
9089 by hand again (they have already done that once for this window.) */
9090 x_wm_set_size_hint (f
, (long) 0, 1);
9093 if (FRAME_GTK_OUTER_WIDGET (f
))
9094 gtk_widget_hide (FRAME_GTK_OUTER_WIDGET (f
));
9097 if (FRAME_X_EMBEDDED_P (f
))
9098 xembed_set_info (f
, 0);
9103 if (! XWithdrawWindow (FRAME_X_DISPLAY (f
), window
,
9104 DefaultScreen (FRAME_X_DISPLAY (f
))))
9106 UNBLOCK_INPUT_RESIGNAL
;
9107 error ("Can't notify window manager of window withdrawal");
9111 /* We can't distinguish this from iconification
9112 just by the event that we get from the server.
9113 So we can't win using the usual strategy of letting
9114 FRAME_SAMPLE_VISIBILITY set this. So do it by hand,
9115 and synchronize with the server to make sure we agree. */
9117 FRAME_ICONIFIED_P (f
) = 0;
9118 f
->async_visible
= 0;
9119 f
->async_iconified
= 0;
9126 /* Change window state from mapped to iconified. */
9129 x_iconify_frame (struct frame
*f
)
9134 /* Don't keep the highlight on an invisible frame. */
9135 if (FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
== f
)
9136 FRAME_X_DISPLAY_INFO (f
)->x_highlight_frame
= 0;
9138 if (f
->async_iconified
)
9143 FRAME_SAMPLE_VISIBILITY (f
);
9145 type
= x_icon_type (f
);
9147 x_bitmap_icon (f
, type
);
9150 if (FRAME_GTK_OUTER_WIDGET (f
))
9152 if (! FRAME_VISIBLE_P (f
))
9153 gtk_widget_show_all (FRAME_GTK_OUTER_WIDGET (f
));
9155 gtk_window_iconify (GTK_WINDOW (FRAME_GTK_OUTER_WIDGET (f
)));
9158 f
->async_iconified
= 1;
9159 f
->async_visible
= 0;
9165 #ifdef USE_X_TOOLKIT
9167 if (! FRAME_VISIBLE_P (f
))
9169 if (! EQ (Vx_no_window_manager
, Qt
))
9170 x_wm_set_window_state (f
, IconicState
);
9171 /* This was XtPopup, but that did nothing for an iconified frame. */
9172 XtMapWidget (f
->output_data
.x
->widget
);
9173 /* The server won't give us any event to indicate
9174 that an invisible frame was changed to an icon,
9175 so we have to record it here. */
9178 f
->async_iconified
= 1;
9179 f
->async_visible
= 0;
9184 result
= XIconifyWindow (FRAME_X_DISPLAY (f
),
9185 XtWindow (f
->output_data
.x
->widget
),
9186 DefaultScreen (FRAME_X_DISPLAY (f
)));
9190 error ("Can't notify window manager of iconification");
9192 f
->async_iconified
= 1;
9193 f
->async_visible
= 0;
9197 XFlush (FRAME_X_DISPLAY (f
));
9199 #else /* not USE_X_TOOLKIT */
9201 /* Make sure the X server knows where the window should be positioned,
9202 in case the user deiconifies with the window manager. */
9203 if (! FRAME_VISIBLE_P (f
)
9204 && ! FRAME_ICONIFIED_P (f
)
9205 && ! FRAME_X_EMBEDDED_P (f
))
9206 x_set_offset (f
, f
->left_pos
, f
->top_pos
, 0);
9208 /* Since we don't know which revision of X we're running, we'll use both
9209 the X11R3 and X11R4 techniques. I don't know if this is a good idea. */
9211 /* X11R4: send a ClientMessage to the window manager using the
9212 WM_CHANGE_STATE type. */
9216 message
.xclient
.window
= FRAME_X_WINDOW (f
);
9217 message
.xclient
.type
= ClientMessage
;
9218 message
.xclient
.message_type
= FRAME_X_DISPLAY_INFO (f
)->Xatom_wm_change_state
;
9219 message
.xclient
.format
= 32;
9220 message
.xclient
.data
.l
[0] = IconicState
;
9222 if (! XSendEvent (FRAME_X_DISPLAY (f
),
9223 DefaultRootWindow (FRAME_X_DISPLAY (f
)),
9225 SubstructureRedirectMask
| SubstructureNotifyMask
,
9228 UNBLOCK_INPUT_RESIGNAL
;
9229 error ("Can't notify window manager of iconification");
9233 /* X11R3: set the initial_state field of the window manager hints to
9235 x_wm_set_window_state (f
, IconicState
);
9237 if (!FRAME_VISIBLE_P (f
))
9239 /* If the frame was withdrawn, before, we must map it. */
9240 XMapRaised (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9243 f
->async_iconified
= 1;
9244 f
->async_visible
= 0;
9246 XFlush (FRAME_X_DISPLAY (f
));
9248 #endif /* not USE_X_TOOLKIT */
9252 /* Free X resources of frame F. */
9255 x_free_frame_resources (struct frame
*f
)
9257 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9259 struct scroll_bar
*b
;
9263 /* If a display connection is dead, don't try sending more
9264 commands to the X server. */
9265 if (dpyinfo
->display
)
9267 /* We must free faces before destroying windows because some
9268 font-driver (e.g. xft) access a window while finishing a
9270 if (FRAME_FACE_CACHE (f
))
9271 free_frame_faces (f
);
9273 if (f
->output_data
.x
->icon_desc
)
9274 XDestroyWindow (FRAME_X_DISPLAY (f
), f
->output_data
.x
->icon_desc
);
9276 #ifdef USE_X_TOOLKIT
9277 /* Explicitly destroy the scroll bars of the frame. Without
9278 this, we get "BadDrawable" errors from the toolkit later on,
9279 presumably from expose events generated for the disappearing
9280 toolkit scroll bars. */
9281 for (bar
= FRAME_SCROLL_BARS (f
); !NILP (bar
); bar
= b
->next
)
9283 b
= XSCROLL_BAR (bar
);
9284 x_scroll_bar_remove (b
);
9293 #ifdef USE_X_TOOLKIT
9294 if (f
->output_data
.x
->widget
)
9296 XtDestroyWidget (f
->output_data
.x
->widget
);
9297 f
->output_data
.x
->widget
= NULL
;
9299 /* Tooltips don't have widgets, only a simple X window, even if
9300 we are using a toolkit. */
9301 else if (FRAME_X_WINDOW (f
))
9302 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9304 free_frame_menubar (f
);
9305 #else /* !USE_X_TOOLKIT */
9308 /* In the GTK version, tooltips are normal X
9309 frames. We must check and free both types. */
9310 if (FRAME_GTK_OUTER_WIDGET (f
))
9312 gtk_widget_destroy (FRAME_GTK_OUTER_WIDGET (f
));
9313 FRAME_X_WINDOW (f
) = 0; /* Set to avoid XDestroyWindow below */
9314 FRAME_GTK_OUTER_WIDGET (f
) = 0;
9316 #endif /* USE_GTK */
9318 if (FRAME_X_WINDOW (f
))
9319 XDestroyWindow (FRAME_X_DISPLAY (f
), FRAME_X_WINDOW (f
));
9320 #endif /* !USE_X_TOOLKIT */
9322 unload_color (f
, FRAME_FOREGROUND_PIXEL (f
));
9323 unload_color (f
, FRAME_BACKGROUND_PIXEL (f
));
9324 unload_color (f
, f
->output_data
.x
->cursor_pixel
);
9325 unload_color (f
, f
->output_data
.x
->cursor_foreground_pixel
);
9326 unload_color (f
, f
->output_data
.x
->border_pixel
);
9327 unload_color (f
, f
->output_data
.x
->mouse_pixel
);
9329 if (f
->output_data
.x
->scroll_bar_background_pixel
!= -1)
9330 unload_color (f
, f
->output_data
.x
->scroll_bar_background_pixel
);
9331 if (f
->output_data
.x
->scroll_bar_foreground_pixel
!= -1)
9332 unload_color (f
, f
->output_data
.x
->scroll_bar_foreground_pixel
);
9333 #ifdef USE_TOOLKIT_SCROLL_BARS
9334 /* Scrollbar shadow colors. */
9335 if (f
->output_data
.x
->scroll_bar_top_shadow_pixel
!= -1)
9336 unload_color (f
, f
->output_data
.x
->scroll_bar_top_shadow_pixel
);
9337 if (f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
!= -1)
9338 unload_color (f
, f
->output_data
.x
->scroll_bar_bottom_shadow_pixel
);
9339 #endif /* USE_TOOLKIT_SCROLL_BARS */
9340 if (f
->output_data
.x
->white_relief
.allocated_p
)
9341 unload_color (f
, f
->output_data
.x
->white_relief
.pixel
);
9342 if (f
->output_data
.x
->black_relief
.allocated_p
)
9343 unload_color (f
, f
->output_data
.x
->black_relief
.pixel
);
9346 XFlush (FRAME_X_DISPLAY (f
));
9349 xfree (f
->output_data
.x
->saved_menu_event
);
9350 xfree (f
->output_data
.x
);
9351 f
->output_data
.x
= NULL
;
9353 if (f
== dpyinfo
->x_focus_frame
)
9354 dpyinfo
->x_focus_frame
= 0;
9355 if (f
== dpyinfo
->x_focus_event_frame
)
9356 dpyinfo
->x_focus_event_frame
= 0;
9357 if (f
== dpyinfo
->x_highlight_frame
)
9358 dpyinfo
->x_highlight_frame
= 0;
9360 if (f
== dpyinfo
->mouse_face_mouse_frame
)
9362 dpyinfo
->mouse_face_beg_row
9363 = dpyinfo
->mouse_face_beg_col
= -1;
9364 dpyinfo
->mouse_face_end_row
9365 = dpyinfo
->mouse_face_end_col
= -1;
9366 dpyinfo
->mouse_face_window
= Qnil
;
9367 dpyinfo
->mouse_face_deferred_gc
= 0;
9368 dpyinfo
->mouse_face_mouse_frame
= 0;
9375 /* Destroy the X window of frame F. */
9378 x_destroy_window (struct frame
*f
)
9380 struct x_display_info
*dpyinfo
= FRAME_X_DISPLAY_INFO (f
);
9382 /* If a display connection is dead, don't try sending more
9383 commands to the X server. */
9384 if (dpyinfo
->display
!= 0)
9385 x_free_frame_resources (f
);
9387 dpyinfo
->reference_count
--;
9391 /* Setting window manager hints. */
9393 /* Set the normal size hints for the window manager, for frame F.
9394 FLAGS is the flags word to use--or 0 meaning preserve the flags
9395 that the window now has.
9396 If USER_POSITION is nonzero, we set the USPosition
9397 flag (this is useful when FLAGS is 0).
9398 The GTK version is in gtkutils.c */
9402 x_wm_set_size_hint (struct frame
*f
, long flags
, int user_position
)
9404 XSizeHints size_hints
;
9405 Window window
= FRAME_OUTER_WINDOW (f
);
9407 /* Setting PMaxSize caused various problems. */
9408 size_hints
.flags
= PResizeInc
| PMinSize
/* | PMaxSize */;
9410 size_hints
.x
= f
->left_pos
;
9411 size_hints
.y
= f
->top_pos
;
9413 size_hints
.height
= FRAME_PIXEL_HEIGHT (f
);
9414 size_hints
.width
= FRAME_PIXEL_WIDTH (f
);
9416 size_hints
.width_inc
= FRAME_COLUMN_WIDTH (f
);
9417 size_hints
.height_inc
= FRAME_LINE_HEIGHT (f
);
9418 size_hints
.max_width
= x_display_pixel_width (FRAME_X_DISPLAY_INFO (f
))
9419 - FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9420 size_hints
.max_height
= x_display_pixel_height (FRAME_X_DISPLAY_INFO (f
))
9421 - FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9423 /* Calculate the base and minimum sizes. */
9425 int base_width
, base_height
;
9426 int min_rows
= 0, min_cols
= 0;
9428 base_width
= FRAME_TEXT_COLS_TO_PIXEL_WIDTH (f
, 0);
9429 base_height
= FRAME_TEXT_LINES_TO_PIXEL_HEIGHT (f
, 0);
9431 check_frame_size (f
, &min_rows
, &min_cols
);
9433 /* The window manager uses the base width hints to calculate the
9434 current number of rows and columns in the frame while
9435 resizing; min_width and min_height aren't useful for this
9436 purpose, since they might not give the dimensions for a
9437 zero-row, zero-column frame.
9439 We use the base_width and base_height members if we have
9440 them; otherwise, we set the min_width and min_height members
9441 to the size for a zero x zero frame. */
9443 size_hints
.flags
|= PBaseSize
;
9444 size_hints
.base_width
= base_width
;
9445 size_hints
.base_height
= base_height
+ FRAME_MENUBAR_HEIGHT (f
);
9446 size_hints
.min_width
= base_width
+ min_cols
* size_hints
.width_inc
;
9447 size_hints
.min_height
= base_height
+ min_rows
* size_hints
.height_inc
;
9450 /* If we don't need the old flags, we don't need the old hint at all. */
9453 size_hints
.flags
|= flags
;
9458 XSizeHints hints
; /* Sometimes I hate X Windows... */
9459 long supplied_return
;
9462 value
= XGetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &hints
,
9466 size_hints
.flags
|= flags
;
9471 if (hints
.flags
& PSize
)
9472 size_hints
.flags
|= PSize
;
9473 if (hints
.flags
& PPosition
)
9474 size_hints
.flags
|= PPosition
;
9475 if (hints
.flags
& USPosition
)
9476 size_hints
.flags
|= USPosition
;
9477 if (hints
.flags
& USSize
)
9478 size_hints
.flags
|= USSize
;
9485 size_hints
.win_gravity
= f
->win_gravity
;
9486 size_hints
.flags
|= PWinGravity
;
9490 size_hints
.flags
&= ~ PPosition
;
9491 size_hints
.flags
|= USPosition
;
9493 #endif /* PWinGravity */
9495 XSetWMNormalHints (FRAME_X_DISPLAY (f
), window
, &size_hints
);
9497 #endif /* not USE_GTK */
9499 /* Used for IconicState or NormalState */
9502 x_wm_set_window_state (struct frame
*f
, int state
)
9504 #ifdef USE_X_TOOLKIT
9507 XtSetArg (al
[0], XtNinitialState
, state
);
9508 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9509 #else /* not USE_X_TOOLKIT */
9510 Window window
= FRAME_X_WINDOW (f
);
9512 f
->output_data
.x
->wm_hints
.flags
|= StateHint
;
9513 f
->output_data
.x
->wm_hints
.initial_state
= state
;
9515 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9516 #endif /* not USE_X_TOOLKIT */
9520 x_wm_set_icon_pixmap (struct frame
*f
, int pixmap_id
)
9522 Pixmap icon_pixmap
, icon_mask
;
9524 #if !defined USE_X_TOOLKIT && !defined USE_GTK
9525 Window window
= FRAME_OUTER_WINDOW (f
);
9530 icon_pixmap
= x_bitmap_pixmap (f
, pixmap_id
);
9531 f
->output_data
.x
->wm_hints
.icon_pixmap
= icon_pixmap
;
9532 icon_mask
= x_bitmap_mask (f
, pixmap_id
);
9533 f
->output_data
.x
->wm_hints
.icon_mask
= icon_mask
;
9537 /* It seems there is no way to turn off use of an icon
9545 xg_set_frame_icon (f
, icon_pixmap
, icon_mask
);
9549 #elif defined (USE_X_TOOLKIT) /* same as in x_wm_set_window_state. */
9553 XtSetArg (al
[0], XtNiconPixmap
, icon_pixmap
);
9554 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9555 XtSetArg (al
[0], XtNiconMask
, icon_mask
);
9556 XtSetValues (f
->output_data
.x
->widget
, al
, 1);
9559 #else /* not USE_X_TOOLKIT && not USE_GTK */
9561 f
->output_data
.x
->wm_hints
.flags
|= (IconPixmapHint
| IconMaskHint
);
9562 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9564 #endif /* not USE_X_TOOLKIT && not USE_GTK */
9568 x_wm_set_icon_position (struct frame
*f
, int icon_x
, int icon_y
)
9570 Window window
= FRAME_OUTER_WINDOW (f
);
9572 f
->output_data
.x
->wm_hints
.flags
|= IconPositionHint
;
9573 f
->output_data
.x
->wm_hints
.icon_x
= icon_x
;
9574 f
->output_data
.x
->wm_hints
.icon_y
= icon_y
;
9576 XSetWMHints (FRAME_X_DISPLAY (f
), window
, &f
->output_data
.x
->wm_hints
);
9580 /***********************************************************************
9582 ***********************************************************************/
9586 /* Check that FONT is valid on frame F. It is if it can be found in F's
9590 x_check_font (f
, font
)
9596 xassert (font
!= NULL
&& ! NILP (font
->props
[FONT_TYPE_INDEX
]));
9597 if (font
->driver
->check
)
9598 xassert (font
->driver
->check (f
, font
) == 0);
9601 #endif /* GLYPH_DEBUG != 0 */
9604 /***********************************************************************
9606 ***********************************************************************/
9608 #ifdef USE_X_TOOLKIT
9609 static XrmOptionDescRec emacs_options
[] = {
9610 {"-geometry", ".geometry", XrmoptionSepArg
, NULL
},
9611 {"-iconic", ".iconic", XrmoptionNoArg
, (XtPointer
) "yes"},
9613 {"-internal-border-width", "*EmacsScreen.internalBorderWidth",
9614 XrmoptionSepArg
, NULL
},
9615 {"-ib", "*EmacsScreen.internalBorderWidth", XrmoptionSepArg
, NULL
},
9617 {"-T", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9618 {"-wn", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9619 {"-title", "*EmacsShell.title", XrmoptionSepArg
, (XtPointer
) NULL
},
9620 {"-iconname", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9621 {"-in", "*EmacsShell.iconName", XrmoptionSepArg
, (XtPointer
) NULL
},
9622 {"-mc", "*pointerColor", XrmoptionSepArg
, (XtPointer
) NULL
},
9623 {"-cr", "*cursorColor", XrmoptionSepArg
, (XtPointer
) NULL
}
9626 /* Whether atimer for Xt timeouts is activated or not. */
9628 static int x_timeout_atimer_activated_flag
;
9630 #endif /* USE_X_TOOLKIT */
9632 static int x_initialized
;
9635 static int x_session_initialized
;
9638 /* Test whether two display-name strings agree up to the dot that separates
9639 the screen number from the server number. */
9641 same_x_server (const char *name1
, const char *name2
)
9644 const unsigned char *system_name
= SDATA (Vsystem_name
);
9645 int system_name_length
= strlen (system_name
);
9646 int length_until_period
= 0;
9648 while (system_name
[length_until_period
] != 0
9649 && system_name
[length_until_period
] != '.')
9650 length_until_period
++;
9652 /* Treat `unix' like an empty host name. */
9653 if (! strncmp (name1
, "unix:", 5))
9655 if (! strncmp (name2
, "unix:", 5))
9657 /* Treat this host's name like an empty host name. */
9658 if (! strncmp (name1
, system_name
, system_name_length
)
9659 && name1
[system_name_length
] == ':')
9660 name1
+= system_name_length
;
9661 if (! strncmp (name2
, system_name
, system_name_length
)
9662 && name2
[system_name_length
] == ':')
9663 name2
+= system_name_length
;
9664 /* Treat this host's domainless name like an empty host name. */
9665 if (! strncmp (name1
, system_name
, length_until_period
)
9666 && name1
[length_until_period
] == ':')
9667 name1
+= length_until_period
;
9668 if (! strncmp (name2
, system_name
, length_until_period
)
9669 && name2
[length_until_period
] == ':')
9670 name2
+= length_until_period
;
9672 for (; *name1
!= '\0' && *name1
== *name2
; name1
++, name2
++)
9676 if (seen_colon
&& *name1
== '.')
9680 && (*name1
== '.' || *name1
== '\0')
9681 && (*name2
== '.' || *name2
== '\0'));
9684 /* Count number of set bits in mask and number of bits to shift to
9685 get to the first bit. With MASK 0x7e0, *BITS is set to 6, and *OFFSET
9688 get_bits_and_offset (long unsigned int mask
, int *bits
, int *offset
)
9709 /* Return 1 if display DISPLAY is available for use, 0 otherwise.
9710 But don't permanently open it, just test its availability. */
9713 x_display_ok (const char *display
)
9718 dpy
= XOpenDisplay (display
);
9720 XCloseDisplay (dpy
);
9728 my_log_handler (const gchar
*log_domain
, GLogLevelFlags log_level
, const gchar
*message
, gpointer user_data
)
9730 if (!strstr (message
, "g_set_prgname"))
9731 fprintf (stderr
, "%s-WARNING **: %s\n", log_domain
, message
);
9735 /* Open a connection to X display DISPLAY_NAME, and return
9736 the structure that describes the open display.
9737 If we cannot contact the display, return null. */
9739 struct x_display_info
*
9740 x_term_init (Lisp_Object display_name
, char *xrm_option
, char *resource_name
)
9744 struct terminal
*terminal
;
9745 struct x_display_info
*dpyinfo
;
9756 if (! x_display_ok (SDATA (display_name
)))
9757 error ("Display %s can't be opened", SDATA (display_name
));
9763 char *argv
[NUM_ARGV
];
9764 char **argv2
= argv
;
9767 if (x_initialized
++ > 1)
9769 xg_display_open (SDATA (display_name
), &dpy
);
9773 for (argc
= 0; argc
< NUM_ARGV
; ++argc
)
9777 argv
[argc
++] = initial_argv
[0];
9779 if (! NILP (display_name
))
9781 argv
[argc
++] = "--display";
9782 argv
[argc
++] = SDATA (display_name
);
9785 argv
[argc
++] = "--name";
9786 argv
[argc
++] = resource_name
;
9788 XSetLocaleModifiers ("");
9790 /* Work around GLib bug that outputs a faulty warning. See
9791 https://bugzilla.gnome.org/show_bug.cgi?id=563627. */
9792 id
= g_log_set_handler ("GLib", G_LOG_LEVEL_WARNING
| G_LOG_FLAG_FATAL
9793 | G_LOG_FLAG_RECURSION
, my_log_handler
, NULL
);
9794 gtk_init (&argc
, &argv2
);
9795 g_log_remove_handler ("GLib", id
);
9797 /* gtk_init does set_locale. We must fix locale after calling it. */
9801 dpy
= GDK_DISPLAY ();
9803 /* NULL window -> events for all windows go to our function */
9804 gdk_window_add_filter (NULL
, event_handler_gdk
, NULL
);
9806 /* Load our own gtkrc if it exists. */
9808 char *file
= "~/.emacs.d/gtkrc";
9809 Lisp_Object s
, abs_file
;
9811 s
= make_string (file
, strlen (file
));
9812 abs_file
= Fexpand_file_name (s
, Qnil
);
9814 if (! NILP (abs_file
) && !NILP (Ffile_readable_p (abs_file
)))
9815 gtk_rc_parse (SDATA (abs_file
));
9818 XSetErrorHandler (x_error_handler
);
9819 XSetIOErrorHandler (x_io_error_quitter
);
9822 #else /* not USE_GTK */
9823 #ifdef USE_X_TOOLKIT
9824 /* weiner@footloose.sps.mot.com reports that this causes
9826 X protocol error: BadAtom (invalid Atom parameter)
9827 on protocol request 18skiloaf.
9828 So let's not use it until R6. */
9830 XtSetLanguageProc (NULL
, NULL
, NULL
);
9841 argv
[argc
++] = "-xrm";
9842 argv
[argc
++] = xrm_option
;
9844 turn_on_atimers (0);
9845 dpy
= XtOpenDisplay (Xt_app_con
, SDATA (display_name
),
9846 resource_name
, EMACS_CLASS
,
9847 emacs_options
, XtNumber (emacs_options
),
9849 turn_on_atimers (1);
9852 /* I think this is to compensate for XtSetLanguageProc. */
9857 #else /* not USE_X_TOOLKIT */
9858 XSetLocaleModifiers ("");
9859 dpy
= XOpenDisplay (SDATA (display_name
));
9860 #endif /* not USE_X_TOOLKIT */
9861 #endif /* not USE_GTK*/
9863 /* Detect failure. */
9870 /* We have definitely succeeded. Record the new connection. */
9872 dpyinfo
= (struct x_display_info
*) xmalloc (sizeof (struct x_display_info
));
9873 memset (dpyinfo
, 0, sizeof *dpyinfo
);
9875 terminal
= x_create_terminal (dpyinfo
);
9878 struct x_display_info
*share
;
9881 for (share
= x_display_list
, tail
= x_display_name_list
; share
;
9882 share
= share
->next
, tail
= XCDR (tail
))
9883 if (same_x_server (SDATA (XCAR (XCAR (tail
))),
9884 SDATA (display_name
)))
9887 terminal
->kboard
= share
->terminal
->kboard
;
9890 terminal
->kboard
= (KBOARD
*) xmalloc (sizeof (KBOARD
));
9891 init_kboard (terminal
->kboard
);
9892 terminal
->kboard
->Vwindow_system
= Qx
;
9894 /* Add the keyboard to the list before running Lisp code (via
9895 Qvendor_specific_keysyms below), since these are not traced
9896 via terminals but only through all_kboards. */
9897 terminal
->kboard
->next_kboard
= all_kboards
;
9898 all_kboards
= terminal
->kboard
;
9900 if (!EQ (XSYMBOL (Qvendor_specific_keysyms
)->function
, Qunbound
))
9902 char *vendor
= ServerVendor (dpy
);
9904 /* Protect terminal from GC before removing it from the
9905 list of terminals. */
9906 struct gcpro gcpro1
;
9907 Lisp_Object gcpro_term
;
9908 XSETTERMINAL (gcpro_term
, terminal
);
9909 GCPRO1 (gcpro_term
);
9911 /* Temporarily hide the partially initialized terminal. */
9912 terminal_list
= terminal
->next_terminal
;
9914 terminal
->kboard
->Vsystem_key_alist
9915 = call1 (Qvendor_specific_keysyms
,
9916 vendor
? build_string (vendor
) : empty_unibyte_string
);
9918 terminal
->next_terminal
= terminal_list
;
9919 terminal_list
= terminal
;
9923 /* Don't let the initial kboard remain current longer than necessary.
9924 That would cause problems if a file loaded on startup tries to
9925 prompt in the mini-buffer. */
9926 if (current_kboard
== initial_kboard
)
9927 current_kboard
= terminal
->kboard
;
9929 terminal
->kboard
->reference_count
++;
9932 /* Put this display on the chain. */
9933 dpyinfo
->next
= x_display_list
;
9934 x_display_list
= dpyinfo
;
9936 /* Put it on x_display_name_list as well, to keep them parallel. */
9937 x_display_name_list
= Fcons (Fcons (display_name
, Qnil
),
9938 x_display_name_list
);
9939 dpyinfo
->name_list_element
= XCAR (x_display_name_list
);
9941 dpyinfo
->display
= dpy
;
9943 /* Set the name of the terminal. */
9944 terminal
->name
= (char *) xmalloc (SBYTES (display_name
) + 1);
9945 strncpy (terminal
->name
, SDATA (display_name
), SBYTES (display_name
));
9946 terminal
->name
[SBYTES (display_name
)] = 0;
9949 XSetAfterFunction (x_current_display
, x_trace_wire
);
9953 = (char *) xmalloc (SBYTES (Vinvocation_name
)
9954 + SBYTES (Vsystem_name
)
9956 sprintf (dpyinfo
->x_id_name
, "%s@%s",
9957 SDATA (Vinvocation_name
), SDATA (Vsystem_name
));
9959 /* Figure out which modifier bits mean what. */
9960 x_find_modifier_meanings (dpyinfo
);
9962 /* Get the scroll bar cursor. */
9964 /* We must create a GTK cursor, it is required for GTK widgets. */
9965 dpyinfo
->xg_cursor
= xg_create_default_cursor (dpyinfo
->display
);
9966 #endif /* USE_GTK */
9968 dpyinfo
->vertical_scroll_bar_cursor
9969 = XCreateFontCursor (dpyinfo
->display
, XC_sb_v_double_arrow
);
9971 xrdb
= x_load_resources (dpyinfo
->display
, xrm_option
,
9972 resource_name
, EMACS_CLASS
);
9973 #ifdef HAVE_XRMSETDATABASE
9974 XrmSetDatabase (dpyinfo
->display
, xrdb
);
9976 dpyinfo
->display
->db
= xrdb
;
9978 /* Put the rdb where we can find it in a way that works on
9980 dpyinfo
->xrdb
= xrdb
;
9982 dpyinfo
->screen
= ScreenOfDisplay (dpyinfo
->display
,
9983 DefaultScreen (dpyinfo
->display
));
9984 select_visual (dpyinfo
);
9985 dpyinfo
->cmap
= DefaultColormapOfScreen (dpyinfo
->screen
);
9986 dpyinfo
->root_window
= RootWindowOfScreen (dpyinfo
->screen
);
9987 dpyinfo
->client_leader_window
= 0;
9988 dpyinfo
->grabbed
= 0;
9989 dpyinfo
->reference_count
= 0;
9990 dpyinfo
->icon_bitmap_id
= -1;
9991 dpyinfo
->n_fonts
= 0;
9992 dpyinfo
->bitmaps
= 0;
9993 dpyinfo
->bitmaps_size
= 0;
9994 dpyinfo
->bitmaps_last
= 0;
9995 dpyinfo
->scratch_cursor_gc
= 0;
9996 dpyinfo
->mouse_face_mouse_frame
= 0;
9997 dpyinfo
->mouse_face_deferred_gc
= 0;
9998 dpyinfo
->mouse_face_beg_row
= dpyinfo
->mouse_face_beg_col
= -1;
9999 dpyinfo
->mouse_face_end_row
= dpyinfo
->mouse_face_end_col
= -1;
10000 dpyinfo
->mouse_face_face_id
= DEFAULT_FACE_ID
;
10001 dpyinfo
->mouse_face_window
= Qnil
;
10002 dpyinfo
->mouse_face_overlay
= Qnil
;
10003 dpyinfo
->mouse_face_mouse_x
= dpyinfo
->mouse_face_mouse_y
= 0;
10004 dpyinfo
->mouse_face_defer
= 0;
10005 dpyinfo
->mouse_face_hidden
= 0;
10006 dpyinfo
->x_focus_frame
= 0;
10007 dpyinfo
->x_focus_event_frame
= 0;
10008 dpyinfo
->x_highlight_frame
= 0;
10009 dpyinfo
->wm_type
= X_WMTYPE_UNKNOWN
;
10011 /* See if we can construct pixel values from RGB values. */
10012 dpyinfo
->red_bits
= dpyinfo
->blue_bits
= dpyinfo
->green_bits
= 0;
10013 dpyinfo
->red_offset
= dpyinfo
->blue_offset
= dpyinfo
->green_offset
= 0;
10015 if (dpyinfo
->visual
->class == TrueColor
)
10017 get_bits_and_offset (dpyinfo
->visual
->red_mask
,
10018 &dpyinfo
->red_bits
, &dpyinfo
->red_offset
);
10019 get_bits_and_offset (dpyinfo
->visual
->blue_mask
,
10020 &dpyinfo
->blue_bits
, &dpyinfo
->blue_offset
);
10021 get_bits_and_offset (dpyinfo
->visual
->green_mask
,
10022 &dpyinfo
->green_bits
, &dpyinfo
->green_offset
);
10025 /* See if a private colormap is requested. */
10026 if (dpyinfo
->visual
== DefaultVisualOfScreen (dpyinfo
->screen
))
10028 if (dpyinfo
->visual
->class == PseudoColor
)
10031 value
= display_x_get_resource (dpyinfo
,
10032 build_string ("privateColormap"),
10033 build_string ("PrivateColormap"),
10035 if (STRINGP (value
)
10036 && (!strcmp (SDATA (value
), "true")
10037 || !strcmp (SDATA (value
), "on")))
10038 dpyinfo
->cmap
= XCopyColormapAndFree (dpyinfo
->display
, dpyinfo
->cmap
);
10042 dpyinfo
->cmap
= XCreateColormap (dpyinfo
->display
, dpyinfo
->root_window
,
10043 dpyinfo
->visual
, AllocNone
);
10047 /* If we are using Xft, check dpi value in X resources.
10048 It is better we use it as well, since Xft will use it, as will all
10049 Gnome applications. If our real DPI is smaller or larger than the
10050 one Xft uses, our font will look smaller or larger than other
10051 for other applications, even if it is the same font name (monospace-10
10053 char *v
= XGetDefault (dpyinfo
->display
, "Xft", "dpi");
10055 if (v
!= NULL
&& sscanf (v
, "%lf", &d
) == 1)
10056 dpyinfo
->resy
= dpyinfo
->resx
= d
;
10060 if (dpyinfo
->resy
< 1)
10062 int screen_number
= XScreenNumberOfScreen (dpyinfo
->screen
);
10063 double pixels
= DisplayHeight (dpyinfo
->display
, screen_number
);
10064 double mm
= DisplayHeightMM (dpyinfo
->display
, screen_number
);
10065 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10066 dpyinfo
->resy
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10067 pixels
= DisplayWidth (dpyinfo
->display
, screen_number
);
10068 mm
= DisplayWidthMM (dpyinfo
->display
, screen_number
);
10069 /* Mac OS X 10.3's Xserver sometimes reports 0.0mm. */
10070 dpyinfo
->resx
= (mm
< 1) ? 100 : pixels
* 25.4 / mm
;
10073 dpyinfo
->Xatom_wm_protocols
10074 = XInternAtom (dpyinfo
->display
, "WM_PROTOCOLS", False
);
10075 dpyinfo
->Xatom_wm_take_focus
10076 = XInternAtom (dpyinfo
->display
, "WM_TAKE_FOCUS", False
);
10077 dpyinfo
->Xatom_wm_save_yourself
10078 = XInternAtom (dpyinfo
->display
, "WM_SAVE_YOURSELF", False
);
10079 dpyinfo
->Xatom_wm_delete_window
10080 = XInternAtom (dpyinfo
->display
, "WM_DELETE_WINDOW", False
);
10081 dpyinfo
->Xatom_wm_change_state
10082 = XInternAtom (dpyinfo
->display
, "WM_CHANGE_STATE", False
);
10083 dpyinfo
->Xatom_wm_configure_denied
10084 = XInternAtom (dpyinfo
->display
, "WM_CONFIGURE_DENIED", False
);
10085 dpyinfo
->Xatom_wm_window_moved
10086 = XInternAtom (dpyinfo
->display
, "WM_MOVED", False
);
10087 dpyinfo
->Xatom_wm_client_leader
10088 = XInternAtom (dpyinfo
->display
, "WM_CLIENT_LEADER", False
);
10089 dpyinfo
->Xatom_editres
10090 = XInternAtom (dpyinfo
->display
, "Editres", False
);
10091 dpyinfo
->Xatom_CLIPBOARD
10092 = XInternAtom (dpyinfo
->display
, "CLIPBOARD", False
);
10093 dpyinfo
->Xatom_TIMESTAMP
10094 = XInternAtom (dpyinfo
->display
, "TIMESTAMP", False
);
10095 dpyinfo
->Xatom_TEXT
10096 = XInternAtom (dpyinfo
->display
, "TEXT", False
);
10097 dpyinfo
->Xatom_COMPOUND_TEXT
10098 = XInternAtom (dpyinfo
->display
, "COMPOUND_TEXT", False
);
10099 dpyinfo
->Xatom_UTF8_STRING
10100 = XInternAtom (dpyinfo
->display
, "UTF8_STRING", False
);
10101 dpyinfo
->Xatom_DELETE
10102 = XInternAtom (dpyinfo
->display
, "DELETE", False
);
10103 dpyinfo
->Xatom_MULTIPLE
10104 = XInternAtom (dpyinfo
->display
, "MULTIPLE", False
);
10105 dpyinfo
->Xatom_INCR
10106 = XInternAtom (dpyinfo
->display
, "INCR", False
);
10107 dpyinfo
->Xatom_EMACS_TMP
10108 = XInternAtom (dpyinfo
->display
, "_EMACS_TMP_", False
);
10109 dpyinfo
->Xatom_TARGETS
10110 = XInternAtom (dpyinfo
->display
, "TARGETS", False
);
10111 dpyinfo
->Xatom_NULL
10112 = XInternAtom (dpyinfo
->display
, "NULL", False
);
10113 dpyinfo
->Xatom_ATOM_PAIR
10114 = XInternAtom (dpyinfo
->display
, "ATOM_PAIR", False
);
10115 /* For properties of font. */
10116 dpyinfo
->Xatom_PIXEL_SIZE
10117 = XInternAtom (dpyinfo
->display
, "PIXEL_SIZE", False
);
10118 dpyinfo
->Xatom_AVERAGE_WIDTH
10119 = XInternAtom (dpyinfo
->display
, "AVERAGE_WIDTH", False
);
10120 dpyinfo
->Xatom_MULE_BASELINE_OFFSET
10121 = XInternAtom (dpyinfo
->display
, "_MULE_BASELINE_OFFSET", False
);
10122 dpyinfo
->Xatom_MULE_RELATIVE_COMPOSE
10123 = XInternAtom (dpyinfo
->display
, "_MULE_RELATIVE_COMPOSE", False
);
10124 dpyinfo
->Xatom_MULE_DEFAULT_ASCENT
10125 = XInternAtom (dpyinfo
->display
, "_MULE_DEFAULT_ASCENT", False
);
10127 /* Ghostscript support. */
10128 dpyinfo
->Xatom_PAGE
= XInternAtom (dpyinfo
->display
, "PAGE", False
);
10129 dpyinfo
->Xatom_DONE
= XInternAtom (dpyinfo
->display
, "DONE", False
);
10131 dpyinfo
->Xatom_Scrollbar
= XInternAtom (dpyinfo
->display
, "SCROLLBAR",
10134 dpyinfo
->Xatom_XEMBED
= XInternAtom (dpyinfo
->display
, "_XEMBED",
10137 dpyinfo
->Xatom_net_wm_state
10138 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE", False
);
10139 dpyinfo
->Xatom_net_wm_state_fullscreen_atom
10140 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_FULLSCREEN", False
);
10141 dpyinfo
->Xatom_net_wm_state_maximized_horz
10142 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_HORZ", False
);
10143 dpyinfo
->Xatom_net_wm_state_maximized_vert
10144 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_MAXIMIZED_VERT", False
);
10145 dpyinfo
->Xatom_net_wm_state_sticky
10146 = XInternAtom (dpyinfo
->display
, "_NET_WM_STATE_STICKY", False
);
10147 dpyinfo
->Xatom_net_window_type
10148 = XInternAtom (dpyinfo
->display
, "_NET_WM_WINDOW_TYPE", False
);
10149 dpyinfo
->Xatom_net_window_type_tooltip
10150 = XInternAtom (dpyinfo
->display
, "_NET_WM_WINDOW_TYPE_TOOLTIP", False
);
10151 dpyinfo
->Xatom_net_wm_icon_name
10152 = XInternAtom (dpyinfo
->display
, "_NET_WM_ICON_NAME", False
);
10153 dpyinfo
->Xatom_net_wm_name
10154 = XInternAtom (dpyinfo
->display
, "_NET_WM_NAME", False
);
10156 dpyinfo
->cut_buffers_initialized
= 0;
10158 dpyinfo
->x_dnd_atoms_size
= 8;
10159 dpyinfo
->x_dnd_atoms_length
= 0;
10160 dpyinfo
->x_dnd_atoms
= xmalloc (sizeof (*dpyinfo
->x_dnd_atoms
)
10161 * dpyinfo
->x_dnd_atoms_size
);
10163 dpyinfo
->net_supported_atoms
= NULL
;
10164 dpyinfo
->nr_net_supported_atoms
= 0;
10165 dpyinfo
->net_supported_window
= 0;
10167 connection
= ConnectionNumber (dpyinfo
->display
);
10168 dpyinfo
->connection
= connection
;
10171 extern int gray_bitmap_width
, gray_bitmap_height
;
10172 extern char *gray_bitmap_bits
;
10174 = XCreatePixmapFromBitmapData (dpyinfo
->display
, dpyinfo
->root_window
,
10176 gray_bitmap_width
, gray_bitmap_height
,
10177 (unsigned long) 1, (unsigned long) 0, 1);
10181 xim_initialize (dpyinfo
, resource_name
);
10184 xsettings_initialize (dpyinfo
);
10186 /* This is only needed for distinguishing keyboard and process input. */
10187 if (connection
!= 0)
10188 add_keyboard_wait_descriptor (connection
);
10191 fcntl (connection
, F_SETOWN
, getpid ());
10192 #endif /* ! defined (F_SETOWN) */
10195 if (interrupt_input
)
10196 init_sigio (connection
);
10197 #endif /* ! defined (SIGIO) */
10201 Display
*dpy
= dpyinfo
->display
;
10202 XrmValue d
, fr
, to
;
10205 d
.addr
= (XPointer
)&dpy
;
10206 d
.size
= sizeof (Display
*);
10207 fr
.addr
= XtDefaultFont
;
10208 fr
.size
= sizeof (XtDefaultFont
);
10209 to
.size
= sizeof (Font
*);
10210 to
.addr
= (XPointer
)&font
;
10211 x_catch_errors (dpy
);
10212 if (!XtCallConverter (dpy
, XtCvtStringToFont
, &d
, 1, &fr
, &to
, NULL
))
10214 if (x_had_errors_p (dpy
) || !XQueryFont (dpy
, font
))
10215 XrmPutLineResource (&xrdb
, "Emacs.dialog.*.font: 9x15");
10216 x_uncatch_errors ();
10220 /* See if we should run in synchronous mode. This is useful
10221 for debugging X code. */
10224 value
= display_x_get_resource (dpyinfo
,
10225 build_string ("synchronous"),
10226 build_string ("Synchronous"),
10228 if (STRINGP (value
)
10229 && (!strcmp (SDATA (value
), "true")
10230 || !strcmp (SDATA (value
), "on")))
10231 XSynchronize (dpyinfo
->display
, True
);
10236 value
= display_x_get_resource (dpyinfo
,
10237 build_string ("useXIM"),
10238 build_string ("UseXIM"),
10241 if (STRINGP (value
)
10242 && (!strcmp (SDATA (value
), "false")
10243 || !strcmp (SDATA (value
), "off")))
10246 if (STRINGP (value
)
10247 && (!strcmp (SDATA (value
), "true")
10248 || !strcmp (SDATA (value
), "on")))
10254 /* Only do this for the very first display in the Emacs session.
10255 Ignore X session management when Emacs was first started on a
10257 if (terminal
->id
== 1)
10258 x_session_initialize (dpyinfo
);
10266 /* Get rid of display DPYINFO, deleting all frames on it,
10267 and without sending any more commands to the X server. */
10270 x_delete_display (struct x_display_info
*dpyinfo
)
10272 struct terminal
*t
;
10274 /* Close all frames and delete the generic struct terminal for this
10276 for (t
= terminal_list
; t
; t
= t
->next_terminal
)
10277 if (t
->type
== output_x_window
&& t
->display_info
.x
== dpyinfo
)
10280 /* Close X session management when we close its display. */
10281 if (t
->id
== 1 && x_session_have_connection ())
10282 x_session_close ();
10284 delete_terminal (t
);
10288 delete_keyboard_wait_descriptor (dpyinfo
->connection
);
10290 /* Discard this display from x_display_name_list and x_display_list.
10291 We can't use Fdelq because that can quit. */
10292 if (! NILP (x_display_name_list
)
10293 && EQ (XCAR (x_display_name_list
), dpyinfo
->name_list_element
))
10294 x_display_name_list
= XCDR (x_display_name_list
);
10299 tail
= x_display_name_list
;
10300 while (CONSP (tail
) && CONSP (XCDR (tail
)))
10302 if (EQ (XCAR (XCDR (tail
)), dpyinfo
->name_list_element
))
10304 XSETCDR (tail
, XCDR (XCDR (tail
)));
10307 tail
= XCDR (tail
);
10311 if (next_noop_dpyinfo
== dpyinfo
)
10312 next_noop_dpyinfo
= dpyinfo
->next
;
10314 if (x_display_list
== dpyinfo
)
10315 x_display_list
= dpyinfo
->next
;
10318 struct x_display_info
*tail
;
10320 for (tail
= x_display_list
; tail
; tail
= tail
->next
)
10321 if (tail
->next
== dpyinfo
)
10322 tail
->next
= tail
->next
->next
;
10325 xfree (dpyinfo
->x_id_name
);
10326 xfree (dpyinfo
->x_dnd_atoms
);
10327 xfree (dpyinfo
->color_cells
);
10331 #ifdef USE_X_TOOLKIT
10333 /* Atimer callback function for TIMER. Called every 0.1s to process
10334 Xt timeouts, if needed. We must avoid calling XtAppPending as
10335 much as possible because that function does an implicit XFlush
10336 that slows us down. */
10339 x_process_timeouts (timer
)
10340 struct atimer
*timer
;
10343 x_timeout_atimer_activated_flag
= 0;
10344 if (toolkit_scroll_bar_interaction
|| popup_activated ())
10346 while (XtAppPending (Xt_app_con
) & XtIMTimer
)
10347 XtAppProcessEvent (Xt_app_con
, XtIMTimer
);
10348 /* Reactivate the atimer for next time. */
10349 x_activate_timeout_atimer ();
10354 /* Install an asynchronous timer that processes Xt timeout events
10355 every 0.1s as long as either `toolkit_scroll_bar_interaction' or
10356 `popup_activated_flag' (in xmenu.c) is set. Make sure to call this
10357 function whenever these variables are set. This is necessary
10358 because some widget sets use timeouts internally, for example the
10359 LessTif menu bar, or the Xaw3d scroll bar. When Xt timeouts aren't
10360 processed, these widgets don't behave normally. */
10363 x_activate_timeout_atimer (void)
10366 if (!x_timeout_atimer_activated_flag
)
10368 EMACS_TIME interval
;
10370 EMACS_SET_SECS_USECS (interval
, 0, 100000);
10371 start_atimer (ATIMER_RELATIVE
, interval
, x_process_timeouts
, 0);
10372 x_timeout_atimer_activated_flag
= 1;
10377 #endif /* USE_X_TOOLKIT */
10380 /* Set up use of X before we make the first connection. */
10382 extern frame_parm_handler x_frame_parm_handlers
[];
10384 static struct redisplay_interface x_redisplay_interface
=
10386 x_frame_parm_handlers
,
10390 x_clear_end_of_line
,
10392 x_after_update_window_line
,
10393 x_update_window_begin
,
10394 x_update_window_end
,
10400 0, /* flush_display_optional */
10402 x_clear_window_mouse_face
,
10403 x_get_glyph_overhangs
,
10404 x_fix_overlapping_area
,
10405 x_draw_fringe_bitmap
,
10406 0, /* define_fringe_bitmap */
10407 0, /* destroy_fringe_bitmap */
10408 x_compute_glyph_string_overhangs
,
10409 x_draw_glyph_string
,
10410 x_define_frame_cursor
,
10411 x_clear_frame_area
,
10412 x_draw_window_cursor
,
10413 x_draw_vertical_window_border
,
10414 x_shift_glyphs_for_insert
10418 /* This function is called when the last frame on a display is deleted. */
10420 x_delete_terminal (struct terminal
*terminal
)
10422 struct x_display_info
*dpyinfo
= terminal
->display_info
.x
;
10424 /* Protect against recursive calls. delete_frame in
10425 delete_terminal calls us back when it deletes our last frame. */
10426 if (!terminal
->name
)
10431 /* We must close our connection to the XIM server before closing the
10434 xim_close_dpy (dpyinfo
);
10437 /* If called from x_connection_closed, the display may already be closed
10438 and dpyinfo->display was set to 0 to indicate that. */
10439 if (dpyinfo
->display
)
10441 x_destroy_all_bitmaps (dpyinfo
);
10442 XSetCloseDownMode (dpyinfo
->display
, DestroyAll
);
10444 /* Whether or not XCloseDisplay destroys the associated resource
10445 database depends on the version of libX11. To avoid both
10446 crash and memory leak, we dissociate the database from the
10447 display and then destroy dpyinfo->xrdb ourselves.
10449 Unfortunately, the above strategy does not work in some
10450 situations due to a bug in newer versions of libX11: because
10451 XrmSetDatabase doesn't clear the flag XlibDisplayDfltRMDB if
10452 dpy->db is NULL, XCloseDisplay destroys the associated
10453 database whereas it has not been created by XGetDefault
10454 (Bug#21974 in freedesktop.org Bugzilla). As a workaround, we
10455 don't destroy the database here in order to avoid the crash
10456 in the above situations for now, though that may cause memory
10457 leaks in other situations. */
10459 #ifdef HAVE_XRMSETDATABASE
10460 XrmSetDatabase (dpyinfo
->display
, NULL
);
10462 dpyinfo
->display
->db
= NULL
;
10464 /* We used to call XrmDestroyDatabase from x_delete_display, but
10465 some older versions of libX11 crash if we call it after
10466 closing all the displays. */
10467 XrmDestroyDatabase (dpyinfo
->xrdb
);
10471 xg_display_close (dpyinfo
->display
);
10473 #ifdef USE_X_TOOLKIT
10474 XtCloseDisplay (dpyinfo
->display
);
10476 XCloseDisplay (dpyinfo
->display
);
10478 #endif /* ! USE_GTK */
10481 /* Mark as dead. */
10482 dpyinfo
->display
= NULL
;
10483 x_delete_display (dpyinfo
);
10487 /* Create a struct terminal, initialize it with the X11 specific
10488 functions and make DISPLAY->TERMINAL point to it. */
10490 static struct terminal
*
10491 x_create_terminal (struct x_display_info
*dpyinfo
)
10493 struct terminal
*terminal
;
10495 terminal
= create_terminal ();
10497 terminal
->type
= output_x_window
;
10498 terminal
->display_info
.x
= dpyinfo
;
10499 dpyinfo
->terminal
= terminal
;
10501 /* kboard is initialized in x_term_init. */
10503 terminal
->clear_frame_hook
= x_clear_frame
;
10504 terminal
->ins_del_lines_hook
= x_ins_del_lines
;
10505 terminal
->delete_glyphs_hook
= x_delete_glyphs
;
10506 terminal
->ring_bell_hook
= XTring_bell
;
10507 terminal
->toggle_invisible_pointer_hook
= XTtoggle_invisible_pointer
;
10508 terminal
->reset_terminal_modes_hook
= XTreset_terminal_modes
;
10509 terminal
->set_terminal_modes_hook
= XTset_terminal_modes
;
10510 terminal
->update_begin_hook
= x_update_begin
;
10511 terminal
->update_end_hook
= x_update_end
;
10512 terminal
->set_terminal_window_hook
= XTset_terminal_window
;
10513 terminal
->read_socket_hook
= XTread_socket
;
10514 terminal
->frame_up_to_date_hook
= XTframe_up_to_date
;
10515 terminal
->mouse_position_hook
= XTmouse_position
;
10516 terminal
->frame_rehighlight_hook
= XTframe_rehighlight
;
10517 terminal
->frame_raise_lower_hook
= XTframe_raise_lower
;
10518 terminal
->fullscreen_hook
= XTfullscreen_hook
;
10519 terminal
->set_vertical_scroll_bar_hook
= XTset_vertical_scroll_bar
;
10520 terminal
->condemn_scroll_bars_hook
= XTcondemn_scroll_bars
;
10521 terminal
->redeem_scroll_bar_hook
= XTredeem_scroll_bar
;
10522 terminal
->judge_scroll_bars_hook
= XTjudge_scroll_bars
;
10524 terminal
->delete_frame_hook
= x_destroy_window
;
10525 terminal
->delete_terminal_hook
= x_delete_terminal
;
10527 terminal
->rif
= &x_redisplay_interface
;
10528 terminal
->scroll_region_ok
= 1; /* We'll scroll partial frames. */
10529 terminal
->char_ins_del_ok
= 1;
10530 terminal
->line_ins_del_ok
= 1; /* We'll just blt 'em. */
10531 terminal
->fast_clear_end_of_line
= 1; /* X does this well. */
10532 terminal
->memory_below_frame
= 0; /* We don't remember what scrolls
10539 x_initialize (void)
10544 last_tool_bar_item
= -1;
10545 any_help_event_p
= 0;
10546 ignore_next_mouse_click_timeout
= 0;
10548 x_session_initialized
= 0;
10552 current_count
= -1;
10555 /* Try to use interrupt input; if we can't, then start polling. */
10556 Fset_input_interrupt_mode (Qt
);
10558 #ifdef USE_X_TOOLKIT
10559 XtToolkitInitialize ();
10561 Xt_app_con
= XtCreateApplicationContext ();
10563 /* Register a converter from strings to pixels, which uses
10564 Emacs' color allocation infrastructure. */
10565 XtAppSetTypeConverter (Xt_app_con
,
10566 XtRString
, XtRPixel
, cvt_string_to_pixel
,
10567 cvt_string_to_pixel_args
,
10568 XtNumber (cvt_string_to_pixel_args
),
10569 XtCacheByDisplay
, cvt_pixel_dtor
);
10571 XtAppSetFallbackResources (Xt_app_con
, Xt_default_resources
);
10574 #ifdef USE_TOOLKIT_SCROLL_BARS
10576 xaw3d_arrow_scroll
= False
;
10577 xaw3d_pick_top
= True
;
10581 pending_autoraise_frame
= 0;
10582 pending_event_wait
.f
= 0;
10583 pending_event_wait
.eventtype
= 0;
10585 /* Note that there is no real way portable across R3/R4 to get the
10586 original error handler. */
10587 XSetErrorHandler (x_error_handler
);
10588 XSetIOErrorHandler (x_io_error_quitter
);
10590 signal (SIGPIPE
, x_connection_signal
);
10592 xgselect_initialize ();
10597 syms_of_xterm (void)
10599 x_error_message
= NULL
;
10601 staticpro (&x_display_name_list
);
10602 x_display_name_list
= Qnil
;
10604 staticpro (&last_mouse_scroll_bar
);
10605 last_mouse_scroll_bar
= Qnil
;
10607 staticpro (&Qvendor_specific_keysyms
);
10608 Qvendor_specific_keysyms
= intern_c_string ("vendor-specific-keysyms");
10610 staticpro (&Qlatin_1
);
10611 Qlatin_1
= intern_c_string ("latin-1");
10613 staticpro (&last_mouse_press_frame
);
10614 last_mouse_press_frame
= Qnil
;
10617 xg_default_icon_file
= make_pure_c_string ("icons/hicolor/scalable/apps/emacs.svg");
10618 staticpro (&xg_default_icon_file
);
10620 Qx_gtk_map_stock
= intern_c_string ("x-gtk-map-stock");
10621 staticpro (&Qx_gtk_map_stock
);
10624 DEFVAR_BOOL ("x-use-underline-position-properties",
10625 &x_use_underline_position_properties
,
10626 doc
: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
10627 A value of nil means ignore them. If you encounter fonts with bogus
10628 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
10629 to 4.1, set this to nil. You can also use `underline-minimum-offset'
10630 to override the font's UNDERLINE_POSITION for small font display
10632 x_use_underline_position_properties
= 1;
10634 DEFVAR_BOOL ("x-underline-at-descent-line",
10635 &x_underline_at_descent_line
,
10636 doc
: /* *Non-nil means to draw the underline at the same place as the descent line.
10637 A value of nil means to draw the underline according to the value of the
10638 variable `x-use-underline-position-properties', which is usually at the
10639 baseline level. The default value is nil. */);
10640 x_underline_at_descent_line
= 0;
10642 DEFVAR_BOOL ("x-mouse-click-focus-ignore-position",
10643 &x_mouse_click_focus_ignore_position
,
10644 doc
: /* Non-nil means that a mouse click to focus a frame does not move point.
10645 This variable is only used when the window manager requires that you
10646 click on a frame to select it (give it focus). In that case, a value
10647 of nil, means that the selected window and cursor position changes to
10648 reflect the mouse click position, while a non-nil value means that the
10649 selected window or cursor position is preserved. */);
10650 x_mouse_click_focus_ignore_position
= 0;
10652 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars
,
10653 doc
: /* What X toolkit scroll bars Emacs uses.
10654 A value of nil means Emacs doesn't use X toolkit scroll bars.
10655 Otherwise, value is a symbol describing the X toolkit. */);
10656 #ifdef USE_TOOLKIT_SCROLL_BARS
10658 Vx_toolkit_scroll_bars
= intern_c_string ("motif");
10659 #elif defined HAVE_XAW3D
10660 Vx_toolkit_scroll_bars
= intern_c_string ("xaw3d");
10662 Vx_toolkit_scroll_bars
= intern_c_string ("gtk");
10664 Vx_toolkit_scroll_bars
= intern_c_string ("xaw");
10667 Vx_toolkit_scroll_bars
= Qnil
;
10670 staticpro (&last_mouse_motion_frame
);
10671 last_mouse_motion_frame
= Qnil
;
10673 Qmodifier_value
= intern_c_string ("modifier-value");
10674 Qalt
= intern_c_string ("alt");
10675 Fput (Qalt
, Qmodifier_value
, make_number (alt_modifier
));
10676 Qhyper
= intern_c_string ("hyper");
10677 Fput (Qhyper
, Qmodifier_value
, make_number (hyper_modifier
));
10678 Qmeta
= intern_c_string ("meta");
10679 Fput (Qmeta
, Qmodifier_value
, make_number (meta_modifier
));
10680 Qsuper
= intern_c_string ("super");
10681 Fput (Qsuper
, Qmodifier_value
, make_number (super_modifier
));
10683 DEFVAR_LISP ("x-alt-keysym", &Vx_alt_keysym
,
10684 doc
: /* Which keys Emacs uses for the alt modifier.
10685 This should be one of the symbols `alt', `hyper', `meta', `super'.
10686 For example, `alt' means use the Alt_L and Alt_R keysyms. The default
10687 is nil, which is the same as `alt'. */);
10688 Vx_alt_keysym
= Qnil
;
10690 DEFVAR_LISP ("x-hyper-keysym", &Vx_hyper_keysym
,
10691 doc
: /* Which keys Emacs uses for the hyper modifier.
10692 This should be one of the symbols `alt', `hyper', `meta', `super'.
10693 For example, `hyper' means use the Hyper_L and Hyper_R keysyms. The
10694 default is nil, which is the same as `hyper'. */);
10695 Vx_hyper_keysym
= Qnil
;
10697 DEFVAR_LISP ("x-meta-keysym", &Vx_meta_keysym
,
10698 doc
: /* Which keys Emacs uses for the meta modifier.
10699 This should be one of the symbols `alt', `hyper', `meta', `super'.
10700 For example, `meta' means use the Meta_L and Meta_R keysyms. The
10701 default is nil, which is the same as `meta'. */);
10702 Vx_meta_keysym
= Qnil
;
10704 DEFVAR_LISP ("x-super-keysym", &Vx_super_keysym
,
10705 doc
: /* Which keys Emacs uses for the super modifier.
10706 This should be one of the symbols `alt', `hyper', `meta', `super'.
10707 For example, `super' means use the Super_L and Super_R keysyms. The
10708 default is nil, which is the same as `super'. */);
10709 Vx_super_keysym
= Qnil
;
10711 DEFVAR_LISP ("x-keysym-table", &Vx_keysym_table
,
10712 doc
: /* Hash table of character codes indexed by X keysym codes. */);
10713 Vx_keysym_table
= make_hash_table (Qeql
, make_number (900),
10714 make_float (DEFAULT_REHASH_SIZE
),
10715 make_float (DEFAULT_REHASH_THRESHOLD
),
10719 #endif /* HAVE_X_WINDOWS */
10721 /* arch-tag: 6d4e4cb7-abc1-4302-9585-d84dcfb09d0f
10722 (do not change this comment) */