aboutsummaryrefslogtreecommitdiffstats
path: root/src/xterm.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/xterm.c')
-rw-r--r--src/xterm.c374
1 files changed, 247 insertions, 127 deletions
diff --git a/src/xterm.c b/src/xterm.c
index ec415f5ffaf..36e0045d2ed 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -99,6 +99,12 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
99#include "xterm.h" 99#include "xterm.h"
100#include <X11/cursorfont.h> 100#include <X11/cursorfont.h>
101 101
102#ifdef USE_XCB
103#include <xcb/xproto.h>
104#include <xcb/xcb.h>
105#include <xcb/xcb_aux.h>
106#endif
107
102/* If we have Xfixes extension, use it for pointer blanking. */ 108/* If we have Xfixes extension, use it for pointer blanking. */
103#ifdef HAVE_XFIXES 109#ifdef HAVE_XFIXES
104#include <X11/extensions/Xfixes.h> 110#include <X11/extensions/Xfixes.h>
@@ -167,6 +173,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
167#include "../lwlib/xlwmenu.h" 173#include "../lwlib/xlwmenu.h"
168#endif 174#endif
169 175
176#ifdef HAVE_XWIDGETS
177#include <cairo-xlib.h>
178#endif
179
170#ifdef USE_X_TOOLKIT 180#ifdef USE_X_TOOLKIT
171 181
172/* Include toolkit specific headers for the scroll bar widget. */ 182/* Include toolkit specific headers for the scroll bar widget. */
@@ -206,6 +216,10 @@ along with GNU Emacs. If not, see <https://www.gnu.org/licenses/>. */
206#include <X11/XKBlib.h> 216#include <X11/XKBlib.h>
207#endif 217#endif
208 218
219#if defined USE_XCB && defined USE_CAIRO_XCB
220#define USE_CAIRO_XCB_SURFACE
221#endif
222
209/* Default to using XIM if available. */ 223/* Default to using XIM if available. */
210#ifdef USE_XIM 224#ifdef USE_XIM
211bool use_xim = true; 225bool use_xim = true;
@@ -777,11 +791,19 @@ x_begin_cr_clip (struct frame *f, GC gc)
777 { 791 {
778 int width = FRAME_CR_SURFACE_DESIRED_WIDTH (f); 792 int width = FRAME_CR_SURFACE_DESIRED_WIDTH (f);
779 int height = FRAME_CR_SURFACE_DESIRED_HEIGHT (f); 793 int height = FRAME_CR_SURFACE_DESIRED_HEIGHT (f);
780 cairo_surface_t *surface 794 cairo_surface_t *surface;
781 = cairo_xlib_surface_create (FRAME_X_DISPLAY (f), 795#ifdef USE_CAIRO_XCB_SURFACE
782 FRAME_X_RAW_DRAWABLE (f), 796 if (FRAME_DISPLAY_INFO (f)->xcb_visual)
783 FRAME_X_VISUAL (f), 797 surface = cairo_xcb_surface_create (FRAME_DISPLAY_INFO (f)->xcb_connection,
784 width, height); 798 (xcb_drawable_t) FRAME_X_RAW_DRAWABLE (f),
799 FRAME_DISPLAY_INFO (f)->xcb_visual,
800 width, height);
801 else
802#endif
803 surface = cairo_xlib_surface_create (FRAME_X_DISPLAY (f),
804 FRAME_X_RAW_DRAWABLE (f),
805 FRAME_X_VISUAL (f),
806 width, height);
785 807
786 cr = FRAME_CR_CONTEXT (f) = cairo_create (surface); 808 cr = FRAME_CR_CONTEXT (f) = cairo_create (surface);
787 cairo_surface_destroy (surface); 809 cairo_surface_destroy (surface);
@@ -850,6 +872,9 @@ x_try_cr_xlib_drawable (struct frame *f, GC gc)
850 switch (cairo_surface_get_type (surface)) 872 switch (cairo_surface_get_type (surface))
851 { 873 {
852 case CAIRO_SURFACE_TYPE_XLIB: 874 case CAIRO_SURFACE_TYPE_XLIB:
875#ifdef USE_CAIRO_XCB_SURFACE
876 case CAIRO_SURFACE_TYPE_XCB:
877#endif
853 cairo_surface_flush (surface); 878 cairo_surface_flush (surface);
854 return true; 879 return true;
855 880
@@ -1262,11 +1287,15 @@ x_clear_window (struct frame *f)
1262 cairo_paint (cr); 1287 cairo_paint (cr);
1263 x_end_cr_clip (f); 1288 x_end_cr_clip (f);
1264#else 1289#else
1290#ifndef USE_GTK
1265 if (FRAME_X_DOUBLE_BUFFERED_P (f)) 1291 if (FRAME_X_DOUBLE_BUFFERED_P (f))
1292#endif
1266 x_clear_area (f, 0, 0, FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f)); 1293 x_clear_area (f, 0, 0, FRAME_PIXEL_WIDTH (f), FRAME_PIXEL_HEIGHT (f));
1294#ifndef USE_GTK
1267 else 1295 else
1268 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); 1296 XClearWindow (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f));
1269#endif 1297#endif
1298#endif
1270} 1299}
1271 1300
1272#ifdef USE_CAIRO 1301#ifdef USE_CAIRO
@@ -2768,8 +2797,9 @@ x_query_frame_background_color (struct frame *f, XColor *bgcolor)
2768 and names we've actually looked up; list-colors-display is probably 2797 and names we've actually looked up; list-colors-display is probably
2769 the most color-intensive case we're likely to hit. */ 2798 the most color-intensive case we're likely to hit. */
2770 2799
2771Status x_parse_color (struct frame *f, const char *color_name, 2800Status
2772 XColor *color) 2801x_parse_color (struct frame *f, const char *color_name,
2802 XColor *color)
2773{ 2803{
2774 /* Don't pass #RGB strings directly to XParseColor, because that 2804 /* Don't pass #RGB strings directly to XParseColor, because that
2775 follows the X convention of zero-extending each channel 2805 follows the X convention of zero-extending each channel
@@ -2798,6 +2828,10 @@ Status x_parse_color (struct frame *f, const char *color_name,
2798 } 2828 }
2799 } 2829 }
2800 2830
2831 /* Some X servers send BadValue on empty color names. */
2832 if (!strlen (color_name))
2833 return 0;
2834
2801 if (XParseColor (dpy, cmap, color_name, color) == 0) 2835 if (XParseColor (dpy, cmap, color_name, color) == 0)
2802 /* No caching of negative results, currently. */ 2836 /* No caching of negative results, currently. */
2803 return 0; 2837 return 0;
@@ -4473,15 +4507,19 @@ x_clear_area (struct frame *f, int x, int y, int width, int height)
4473 cairo_fill (cr); 4507 cairo_fill (cr);
4474 x_end_cr_clip (f); 4508 x_end_cr_clip (f);
4475#else 4509#else
4510#ifndef USE_GTK
4476 if (FRAME_X_DOUBLE_BUFFERED_P (f)) 4511 if (FRAME_X_DOUBLE_BUFFERED_P (f))
4512#endif
4477 XFillRectangle (FRAME_X_DISPLAY (f), 4513 XFillRectangle (FRAME_X_DISPLAY (f),
4478 FRAME_X_DRAWABLE (f), 4514 FRAME_X_DRAWABLE (f),
4479 f->output_data.x->reverse_gc, 4515 f->output_data.x->reverse_gc,
4480 x, y, width, height); 4516 x, y, width, height);
4517#ifndef USE_GTK
4481 else 4518 else
4482 x_clear_area1 (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 4519 x_clear_area1 (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4483 x, y, width, height, False); 4520 x, y, width, height, False);
4484#endif 4521#endif
4522#endif
4485} 4523}
4486 4524
4487 4525
@@ -4528,6 +4566,7 @@ x_show_hourglass (struct frame *f)
4528 4566
4529 if (!x->hourglass_window) 4567 if (!x->hourglass_window)
4530 { 4568 {
4569#ifndef USE_XCB
4531 unsigned long mask = CWCursor; 4570 unsigned long mask = CWCursor;
4532 XSetWindowAttributes attrs; 4571 XSetWindowAttributes attrs;
4533#ifdef USE_GTK 4572#ifdef USE_GTK
@@ -4540,12 +4579,41 @@ x_show_hourglass (struct frame *f)
4540 x->hourglass_window = XCreateWindow 4579 x->hourglass_window = XCreateWindow
4541 (dpy, parent, 0, 0, 32000, 32000, 0, 0, 4580 (dpy, parent, 0, 0, 32000, 32000, 0, 0,
4542 InputOnly, CopyFromParent, mask, &attrs); 4581 InputOnly, CopyFromParent, mask, &attrs);
4582#else
4583 uint32_t cursor = (uint32_t) x->hourglass_cursor;
4584#ifdef USE_GTK
4585 xcb_window_t parent = (xcb_window_t) FRAME_X_WINDOW (f);
4586#else
4587 xcb_window_t parent = (xcb_window_t) FRAME_OUTER_WINDOW (f);
4588#endif
4589 x->hourglass_window
4590 = (Window) xcb_generate_id (FRAME_DISPLAY_INFO (f)->xcb_connection);
4591
4592 xcb_create_window (FRAME_DISPLAY_INFO (f)->xcb_connection,
4593 XCB_COPY_FROM_PARENT,
4594 (xcb_window_t) x->hourglass_window,
4595 parent, 0, 0, FRAME_PIXEL_WIDTH (f),
4596 FRAME_PIXEL_HEIGHT (f), 0,
4597 XCB_WINDOW_CLASS_INPUT_OUTPUT,
4598 XCB_COPY_FROM_PARENT, XCB_CW_CURSOR,
4599 &cursor);
4600#endif
4543 } 4601 }
4544 4602
4603#ifndef USE_XCB
4545 XMapRaised (dpy, x->hourglass_window); 4604 XMapRaised (dpy, x->hourglass_window);
4546 XFlush (dpy);
4547 /* Ensure that the spinning hourglass is shown. */ 4605 /* Ensure that the spinning hourglass is shown. */
4548 flush_frame (f); 4606 flush_frame (f);
4607#else
4608 uint32_t value = XCB_STACK_MODE_ABOVE;
4609
4610 xcb_configure_window (FRAME_DISPLAY_INFO (f)->xcb_connection,
4611 (xcb_window_t) x->hourglass_window,
4612 XCB_CONFIG_WINDOW_STACK_MODE, &value);
4613 xcb_map_window (FRAME_DISPLAY_INFO (f)->xcb_connection,
4614 (xcb_window_t) x->hourglass_window);
4615 xcb_flush (FRAME_DISPLAY_INFO (f)->xcb_connection);
4616#endif
4549 } 4617 }
4550 } 4618 }
4551} 4619}
@@ -4560,10 +4628,16 @@ x_hide_hourglass (struct frame *f)
4560 /* Watch out for newly created frames. */ 4628 /* Watch out for newly created frames. */
4561 if (x->hourglass_window) 4629 if (x->hourglass_window)
4562 { 4630 {
4631#ifndef USE_XCB
4563 XUnmapWindow (FRAME_X_DISPLAY (f), x->hourglass_window); 4632 XUnmapWindow (FRAME_X_DISPLAY (f), x->hourglass_window);
4564 /* Sync here because XTread_socket looks at the 4633 /* Sync here because XTread_socket looks at the
4565 hourglass_p flag that is reset to zero below. */ 4634 hourglass_p flag that is reset to zero below. */
4566 XSync (FRAME_X_DISPLAY (f), False); 4635 XSync (FRAME_X_DISPLAY (f), False);
4636#else
4637 xcb_unmap_window (FRAME_DISPLAY_INFO (f)->xcb_connection,
4638 (xcb_window_t) x->hourglass_window);
4639 xcb_aux_sync (FRAME_DISPLAY_INFO (f)->xcb_connection);
4640#endif
4567 x->hourglass_p = false; 4641 x->hourglass_p = false;
4568 } 4642 }
4569} 4643}
@@ -4576,38 +4650,6 @@ XTflash (struct frame *f)
4576 block_input (); 4650 block_input ();
4577 4651
4578 { 4652 {
4579#ifdef USE_GTK
4580 /* Use Gdk routines to draw. This way, we won't draw over scroll bars
4581 when the scroll bars and the edit widget share the same X window. */
4582 GdkWindow *window = gtk_widget_get_window (FRAME_GTK_WIDGET (f));
4583#ifdef HAVE_GTK3
4584#if GTK_CHECK_VERSION (3, 22, 0)
4585 cairo_region_t *region = gdk_window_get_visible_region (window);
4586 GdkDrawingContext *context = gdk_window_begin_draw_frame (window, region);
4587 cairo_t *cr = gdk_drawing_context_get_cairo_context (context);
4588#else
4589 cairo_t *cr = gdk_cairo_create (window);
4590#endif
4591 cairo_set_source_rgb (cr, 1, 1, 1);
4592 cairo_set_operator (cr, CAIRO_OPERATOR_DIFFERENCE);
4593#define XFillRectangle(d, win, gc, x, y, w, h) \
4594 do { \
4595 cairo_rectangle (cr, x, y, w, h); \
4596 cairo_fill (cr); \
4597 } \
4598 while (false)
4599#else /* ! HAVE_GTK3 */
4600 GdkGCValues vals;
4601 GdkGC *gc;
4602 vals.foreground.pixel = (FRAME_FOREGROUND_PIXEL (f)
4603 ^ FRAME_BACKGROUND_PIXEL (f));
4604 vals.function = GDK_XOR;
4605 gc = gdk_gc_new_with_values (window,
4606 &vals, GDK_GC_FUNCTION | GDK_GC_FOREGROUND);
4607#define XFillRectangle(d, win, gc, x, y, w, h) \
4608 gdk_draw_rectangle (window, gc, true, x, y, w, h)
4609#endif /* ! HAVE_GTK3 */
4610#else /* ! USE_GTK */
4611 GC gc; 4653 GC gc;
4612 4654
4613 /* Create a GC that will use the GXxor function to flip foreground 4655 /* Create a GC that will use the GXxor function to flip foreground
@@ -4622,7 +4664,6 @@ XTflash (struct frame *f)
4622 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), 4664 gc = XCreateGC (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f),
4623 GCFunction | GCForeground, &values); 4665 GCFunction | GCForeground, &values);
4624 } 4666 }
4625#endif
4626 { 4667 {
4627 /* Get the height not including a menu bar widget. */ 4668 /* Get the height not including a menu bar widget. */
4628 int height = FRAME_PIXEL_HEIGHT (f); 4669 int height = FRAME_PIXEL_HEIGHT (f);
@@ -4698,22 +4739,7 @@ XTflash (struct frame *f)
4698 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc, 4739 XFillRectangle (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), gc,
4699 flash_left, FRAME_INTERNAL_BORDER_WIDTH (f), 4740 flash_left, FRAME_INTERNAL_BORDER_WIDTH (f),
4700 width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f)); 4741 width, height - 2 * FRAME_INTERNAL_BORDER_WIDTH (f));
4701
4702#ifdef USE_GTK
4703#ifdef HAVE_GTK3
4704#if GTK_CHECK_VERSION (3, 22, 0)
4705 gdk_window_end_draw_frame (window, context);
4706 cairo_region_destroy (region);
4707#else
4708 cairo_destroy (cr);
4709#endif
4710#else
4711 g_object_unref (G_OBJECT (gc));
4712#endif
4713#undef XFillRectangle
4714#else
4715 XFreeGC (FRAME_X_DISPLAY (f), gc); 4742 XFreeGC (FRAME_X_DISPLAY (f), gc);
4716#endif
4717 x_flush (f); 4743 x_flush (f);
4718 } 4744 }
4719 } 4745 }
@@ -4921,6 +4947,18 @@ x_scroll_run (struct window *w, struct run *run)
4921 x, to_y); 4947 x, to_y);
4922 cairo_surface_mark_dirty_rectangle (surface, x, to_y, width, height); 4948 cairo_surface_mark_dirty_rectangle (surface, x, to_y, width, height);
4923 } 4949 }
4950#ifdef USE_CAIRO_XCB_SURFACE
4951 else if (cairo_surface_get_type (surface) == CAIRO_SURFACE_TYPE_XCB)
4952 {
4953 cairo_surface_flush (surface);
4954 xcb_copy_area (FRAME_DISPLAY_INFO (f)->xcb_connection,
4955 (xcb_drawable_t) FRAME_X_DRAWABLE (f),
4956 (xcb_drawable_t) FRAME_X_DRAWABLE (f),
4957 (xcb_gcontext_t) XGContextFromGC (f->output_data.x->normal_gc),
4958 x, from_y, x, to_y, width, height);
4959 cairo_surface_mark_dirty_rectangle (surface, x, to_y, width, height);
4960 }
4961#endif
4924 else 4962 else
4925 { 4963 {
4926 cairo_surface_t *s 4964 cairo_surface_t *s
@@ -5436,11 +5474,6 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo)
5436 int syms_per_code; 5474 int syms_per_code;
5437 XModifierKeymap *mods; 5475 XModifierKeymap *mods;
5438#ifdef HAVE_XKB 5476#ifdef HAVE_XKB
5439 Atom meta;
5440 Atom super;
5441 Atom hyper;
5442 Atom shiftlock;
5443 Atom alt;
5444 int i; 5477 int i;
5445 int found_meta_p = false; 5478 int found_meta_p = false;
5446#endif 5479#endif
@@ -5454,28 +5487,22 @@ x_find_modifier_meanings (struct x_display_info *dpyinfo)
5454#ifdef HAVE_XKB 5487#ifdef HAVE_XKB
5455 if (dpyinfo->xkb_desc) 5488 if (dpyinfo->xkb_desc)
5456 { 5489 {
5457 meta = XInternAtom (dpyinfo->display, "Meta", False);
5458 super = XInternAtom (dpyinfo->display, "Super", False);
5459 hyper = XInternAtom (dpyinfo->display, "Hyper", False);
5460 shiftlock = XInternAtom (dpyinfo->display, "ShiftLock", False);
5461 alt = XInternAtom (dpyinfo->display, "Alt", False);
5462
5463 for (i = 0; i < XkbNumVirtualMods; i++) 5490 for (i = 0; i < XkbNumVirtualMods; i++)
5464 { 5491 {
5465 uint vmodmask = dpyinfo->xkb_desc->server->vmods[i]; 5492 uint vmodmask = dpyinfo->xkb_desc->server->vmods[i];
5466 5493
5467 if (dpyinfo->xkb_desc->names->vmods[i] == meta) 5494 if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Meta)
5468 { 5495 {
5469 dpyinfo->meta_mod_mask |= vmodmask; 5496 dpyinfo->meta_mod_mask |= vmodmask;
5470 found_meta_p = vmodmask; 5497 found_meta_p = vmodmask;
5471 } 5498 }
5472 else if (dpyinfo->xkb_desc->names->vmods[i] == alt) 5499 else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Alt)
5473 dpyinfo->alt_mod_mask |= vmodmask; 5500 dpyinfo->alt_mod_mask |= vmodmask;
5474 else if (dpyinfo->xkb_desc->names->vmods[i] == super) 5501 else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Super)
5475 dpyinfo->super_mod_mask |= vmodmask; 5502 dpyinfo->super_mod_mask |= vmodmask;
5476 else if (dpyinfo->xkb_desc->names->vmods[i] == hyper) 5503 else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_Hyper)
5477 dpyinfo->hyper_mod_mask |= vmodmask; 5504 dpyinfo->hyper_mod_mask |= vmodmask;
5478 else if (dpyinfo->xkb_desc->names->vmods[i] == shiftlock) 5505 else if (dpyinfo->xkb_desc->names->vmods[i] == dpyinfo->Xatom_ShiftLock)
5479 dpyinfo->shift_lock_mask |= vmodmask; 5506 dpyinfo->shift_lock_mask |= vmodmask;
5480 } 5507 }
5481 5508
@@ -8373,6 +8400,7 @@ x_filter_event (struct x_display_info *dpyinfo, XEvent *event)
8373#ifdef USE_GTK 8400#ifdef USE_GTK
8374 } 8401 }
8375 else if (f1 && (event->type == KeyPress 8402 else if (f1 && (event->type == KeyPress
8403 || event->type == KeyRelease
8376#ifdef HAVE_XINPUT2 8404#ifdef HAVE_XINPUT2
8377 || xinput_event 8405 || xinput_event
8378#endif 8406#endif
@@ -8384,6 +8412,11 @@ x_filter_event (struct x_display_info *dpyinfo, XEvent *event)
8384 result = xg_filter_key (f1, event); 8412 result = xg_filter_key (f1, event);
8385 unblock_input (); 8413 unblock_input ();
8386 8414
8415 if (result && f1)
8416 /* There will probably be a GDK event generated soon, so
8417 exercise the wire to make pselect return. */
8418 XNoOp (FRAME_X_DISPLAY (f1));
8419
8387 return result; 8420 return result;
8388 } 8421 }
8389 8422
@@ -8434,8 +8467,10 @@ event_handler_gdk (GdkXEvent *gxev, GdkEvent *ev, gpointer data)
8434 && xev->type == GenericEvent 8467 && xev->type == GenericEvent
8435 && (xev->xgeneric.extension 8468 && (xev->xgeneric.extension
8436 == dpyinfo->xi2_opcode) 8469 == dpyinfo->xi2_opcode)
8437 && (xev->xgeneric.evtype 8470 && ((xev->xgeneric.evtype
8438 == XI_KeyPress)) 8471 == XI_KeyPress)
8472 || (xev->xgeneric.evtype
8473 == XI_KeyRelease)))
8439#endif 8474#endif
8440 )) 8475 ))
8441 { 8476 {
@@ -8947,12 +8982,17 @@ handle_one_xevent (struct x_display_info *dpyinfo,
8947 if (!FRAME_VISIBLE_P (f)) 8982 if (!FRAME_VISIBLE_P (f))
8948 { 8983 {
8949 block_input (); 8984 block_input ();
8950 /* The following two are commented out to avoid that a 8985 /* By default, do not set the frame's visibility here, see
8951 plain invisible frame gets reported as iconified. That 8986 https://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00133.html.
8952 problem occurred first for Emacs 26 and is described in 8987 The default behavior can be overridden by setting
8953 https://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00133.html. */ 8988 'x-set-frame-visibility-more-laxly' (Bug#49955,
8954/** SET_FRAME_VISIBLE (f, 1); **/ 8989 Bug#53298). */
8955/** SET_FRAME_ICONIFIED (f, false); **/ 8990 if (EQ (x_set_frame_visibility_more_laxly, Qexpose)
8991 || EQ (x_set_frame_visibility_more_laxly, Qt))
8992 {
8993 SET_FRAME_VISIBLE (f, 1);
8994 SET_FRAME_ICONIFIED (f, false);
8995 }
8956 8996
8957 if (FRAME_X_DOUBLE_BUFFERED_P (f)) 8997 if (FRAME_X_DOUBLE_BUFFERED_P (f))
8958 font_drop_xrender_surfaces (f); 8998 font_drop_xrender_surfaces (f);
@@ -9236,7 +9276,8 @@ handle_one_xevent (struct x_display_info *dpyinfo,
9236 int modifiers; 9276 int modifiers;
9237 Lisp_Object coding_system = Qlatin_1; 9277 Lisp_Object coding_system = Qlatin_1;
9238 Lisp_Object c; 9278 Lisp_Object c;
9239 /* Event will be modified. */ 9279 /* `xkey' will be modified, but it's not important to modify
9280 `event' itself. */
9240 XKeyEvent xkey = event->xkey; 9281 XKeyEvent xkey = event->xkey;
9241 9282
9242#ifdef USE_GTK 9283#ifdef USE_GTK
@@ -9498,8 +9539,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
9498 if (keysym == NoSymbol) 9539 if (keysym == NoSymbol)
9499 break; 9540 break;
9500 } 9541 }
9501 /* FIXME: check side effects and remove this. */
9502 ((XEvent *) event)->xkey = xkey;
9503 } 9542 }
9504 done_keysym: 9543 done_keysym:
9505#ifdef HAVE_X_I18N 9544#ifdef HAVE_X_I18N
@@ -9571,26 +9610,33 @@ handle_one_xevent (struct x_display_info *dpyinfo,
9571 goto OTHER; 9610 goto OTHER;
9572 9611
9573 case FocusIn: 9612 case FocusIn:
9574#ifndef USE_GTK 9613#ifdef USE_GTK
9575 /* Some WMs (e.g. Mutter in Gnome Shell), don't unmap 9614 /* Some WMs (e.g. Mutter in Gnome Shell), don't unmap
9576 minimized/iconified windows; thus, for those WMs we won't get 9615 minimized/iconified windows; thus, for those WMs we won't get
9577 a MapNotify when unminimizing/deconifying. Check here if we 9616 a MapNotify when unminimizing/deiconifying. Check here if we
9578 are deiconizing a window (Bug42655). 9617 are deiconizing a window (Bug42655).
9579 9618
9580 But don't do that on GTK since it may cause a plain invisible 9619 But don't do that by default on GTK since it may cause a plain
9581 frame get reported as iconified, compare 9620 invisible frame get reported as iconified, compare
9582 https://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00133.html. 9621 https://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00133.html.
9583 That is fixed above but bites us here again. */ 9622 That is fixed above but bites us here again.
9584 f = any; 9623
9585 if (f && FRAME_ICONIFIED_P (f)) 9624 The option x_set_frame_visibility_more_laxly allows to override
9586 { 9625 the default behavior (Bug#49955, Bug#53298). */
9587 SET_FRAME_VISIBLE (f, 1); 9626 if (EQ (x_set_frame_visibility_more_laxly, Qfocus_in)
9588 SET_FRAME_ICONIFIED (f, false); 9627 || EQ (x_set_frame_visibility_more_laxly, Qt))
9589 f->output_data.x->has_been_visible = true;
9590 inev.ie.kind = DEICONIFY_EVENT;
9591 XSETFRAME (inev.ie.frame_or_window, f);
9592 }
9593#endif /* USE_GTK */ 9628#endif /* USE_GTK */
9629 {
9630 f = any;
9631 if (f && FRAME_ICONIFIED_P (f))
9632 {
9633 SET_FRAME_VISIBLE (f, 1);
9634 SET_FRAME_ICONIFIED (f, false);
9635 f->output_data.x->has_been_visible = true;
9636 inev.ie.kind = DEICONIFY_EVENT;
9637 XSETFRAME (inev.ie.frame_or_window, f);
9638 }
9639 }
9594 9640
9595 x_detect_focus_change (dpyinfo, any, event, &inev.ie); 9641 x_detect_focus_change (dpyinfo, any, event, &inev.ie);
9596 goto OTHER; 9642 goto OTHER;
@@ -10194,26 +10240,33 @@ handle_one_xevent (struct x_display_info *dpyinfo,
10194 { 10240 {
10195 case XI_FocusIn: 10241 case XI_FocusIn:
10196 any = x_any_window_to_frame (dpyinfo, focusin->event); 10242 any = x_any_window_to_frame (dpyinfo, focusin->event);
10197#ifndef USE_GTK 10243#ifdef USE_GTK
10198 /* Some WMs (e.g. Mutter in Gnome Shell), don't unmap 10244 /* Some WMs (e.g. Mutter in Gnome Shell), don't unmap
10199 minimized/iconified windows; thus, for those WMs we won't get 10245 minimized/iconified windows; thus, for those WMs we won't get
10200 a MapNotify when unminimizing/deconifying. Check here if we 10246 a MapNotify when unminimizing/deiconifying. Check here if we
10201 are deiconizing a window (Bug42655). 10247 are deiconizing a window (Bug42655).
10202 10248
10203 But don't do that on GTK since it may cause a plain invisible 10249 But don't do that by default on GTK since it may cause a plain
10204 frame get reported as iconified, compare 10250 invisible frame get reported as iconified, compare
10205 https://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00133.html. 10251 https://lists.gnu.org/archive/html/emacs-devel/2017-02/msg00133.html.
10206 That is fixed above but bites us here again. */ 10252 That is fixed above but bites us here again.
10207 f = any; 10253
10208 if (f && FRAME_ICONIFIED_P (f)) 10254 The option x_set_frame_visibility_more_laxly allows to override
10255 the default behavior (Bug#49955, Bug#53298). */
10256 if (EQ (x_set_frame_visibility_more_laxly, Qfocus_in)
10257 || EQ (x_set_frame_visibility_more_laxly, Qt))
10258#endif /* USE_GTK */
10209 { 10259 {
10210 SET_FRAME_VISIBLE (f, 1); 10260 f = any;
10211 SET_FRAME_ICONIFIED (f, false); 10261 if (f && FRAME_ICONIFIED_P (f))
10212 f->output_data.x->has_been_visible = true; 10262 {
10213 inev.ie.kind = DEICONIFY_EVENT; 10263 SET_FRAME_VISIBLE (f, 1);
10214 XSETFRAME (inev.ie.frame_or_window, f); 10264 SET_FRAME_ICONIFIED (f, false);
10265 f->output_data.x->has_been_visible = true;
10266 inev.ie.kind = DEICONIFY_EVENT;
10267 XSETFRAME (inev.ie.frame_or_window, f);
10268 }
10215 } 10269 }
10216#endif /* USE_GTK */
10217 x_detect_focus_change (dpyinfo, any, event, &inev.ie); 10270 x_detect_focus_change (dpyinfo, any, event, &inev.ie);
10218 goto XI_OTHER; 10271 goto XI_OTHER;
10219 case XI_FocusOut: 10272 case XI_FocusOut:
@@ -10708,7 +10761,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
10708 10761
10709 if (f && xev->evtype == XI_ButtonPress 10762 if (f && xev->evtype == XI_ButtonPress
10710 && !popup_activated () 10763 && !popup_activated ()
10711 && !x_window_to_scroll_bar (xev->display, xev->event, 2) 10764 && !x_window_to_scroll_bar (dpyinfo->display, xev->event, 2)
10712 && !FRAME_NO_ACCEPT_FOCUS (f)) 10765 && !FRAME_NO_ACCEPT_FOCUS (f))
10713 { 10766 {
10714 /* When clicking into a child frame or when clicking 10767 /* When clicking into a child frame or when clicking
@@ -10881,7 +10934,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
10881 xkey.type = KeyPress; 10934 xkey.type = KeyPress;
10882 xkey.serial = xev->serial; 10935 xkey.serial = xev->serial;
10883 xkey.send_event = xev->send_event; 10936 xkey.send_event = xev->send_event;
10884 xkey.display = xev->display; 10937 xkey.display = dpyinfo->display;
10885 xkey.window = xev->event; 10938 xkey.window = xev->event;
10886 xkey.root = xev->root; 10939 xkey.root = xev->root;
10887 xkey.subwindow = xev->child; 10940 xkey.subwindow = xev->child;
@@ -11227,7 +11280,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
11227 xkey.type = KeyRelease; 11280 xkey.type = KeyRelease;
11228 xkey.serial = xev->serial; 11281 xkey.serial = xev->serial;
11229 xkey.send_event = xev->send_event; 11282 xkey.send_event = xev->send_event;
11230 xkey.display = xev->display; 11283 xkey.display = dpyinfo->display;
11231 xkey.window = xev->event; 11284 xkey.window = xev->event;
11232 xkey.root = xev->root; 11285 xkey.root = xev->root;
11233 xkey.subwindow = xev->child; 11286 xkey.subwindow = xev->child;
@@ -11523,8 +11576,6 @@ handle_one_xevent (struct x_display_info *dpyinfo,
11523 XkbFreeKeyboard (dpyinfo->xkb_desc, XkbAllComponentsMask, True); 11576 XkbFreeKeyboard (dpyinfo->xkb_desc, XkbAllComponentsMask, True);
11524 dpyinfo->xkb_desc = NULL; 11577 dpyinfo->xkb_desc = NULL;
11525 } 11578 }
11526
11527 x_find_modifier_meanings (dpyinfo);
11528 } 11579 }
11529 else 11580 else
11530 { 11581 {
@@ -11542,6 +11593,7 @@ handle_one_xevent (struct x_display_info *dpyinfo,
11542 } 11593 }
11543 11594
11544 XkbRefreshKeyboardMapping (&xkbevent->map); 11595 XkbRefreshKeyboardMapping (&xkbevent->map);
11596 x_find_modifier_meanings (dpyinfo);
11545 } 11597 }
11546 } 11598 }
11547#endif 11599#endif
@@ -12698,9 +12750,11 @@ xim_initialize (struct x_display_info *dpyinfo, char *resource_name)
12698 ret = XRegisterIMInstantiateCallback 12750 ret = XRegisterIMInstantiateCallback
12699 (dpyinfo->display, dpyinfo->rdb, xim_inst->resource_name, 12751 (dpyinfo->display, dpyinfo->rdb, xim_inst->resource_name,
12700 emacs_class, xim_instantiate_callback, 12752 emacs_class, xim_instantiate_callback,
12701 /* This is XPointer in XFree86 but (XPointer *) 12753 /* This is XPointer in XFree86 but (XPointer *) on Tru64, at
12702 on Tru64, at least, hence the configure test. */ 12754 least, but the configure test doesn't work because
12703 (XRegisterIMInstantiateCallback_arg6) xim_inst); 12755 xim_instantiate_callback can either be XIMProc or
12756 XIDProc, so just cast to void *. */
12757 (void *) xim_inst);
12704 eassert (ret == True); 12758 eassert (ret == True);
12705#else /* not HAVE_X11R6_XIM */ 12759#else /* not HAVE_X11R6_XIM */
12706 xim_open_dpy (dpyinfo, resource_name); 12760 xim_open_dpy (dpyinfo, resource_name);
@@ -12725,8 +12779,7 @@ xim_close_dpy (struct x_display_info *dpyinfo)
12725 { 12779 {
12726 Bool ret = XUnregisterIMInstantiateCallback 12780 Bool ret = XUnregisterIMInstantiateCallback
12727 (dpyinfo->display, dpyinfo->rdb, xim_inst->resource_name, 12781 (dpyinfo->display, dpyinfo->rdb, xim_inst->resource_name,
12728 emacs_class, xim_instantiate_callback, 12782 emacs_class, xim_instantiate_callback, (void *) xim_inst);
12729 (XRegisterIMInstantiateCallback_arg6) xim_inst);
12730 eassert (ret == True); 12783 eassert (ret == True);
12731 } 12784 }
12732 xfree (xim_inst->resource_name); 12785 xfree (xim_inst->resource_name);
@@ -15261,6 +15314,40 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
15261 dpyinfo->supports_xdbe = true; 15314 dpyinfo->supports_xdbe = true;
15262#endif 15315#endif
15263 15316
15317#ifdef USE_XCB
15318 xcb_screen_t *xcb_screen = NULL;
15319 xcb_screen_iterator_t iter;
15320 xcb_visualid_t wanted = { XVisualIDFromVisual (dpyinfo->visual) };
15321 xcb_depth_iterator_t depth_iter;
15322 xcb_visualtype_iterator_t visual_iter;
15323
15324 int screen = DefaultScreen (dpyinfo->display);
15325
15326 iter = xcb_setup_roots_iterator (xcb_get_setup (dpyinfo->xcb_connection));
15327 for (; iter.rem; --screen, xcb_screen_next (&iter))
15328 {
15329 if (!screen)
15330 xcb_screen = iter.data;
15331 }
15332
15333 if (xcb_screen)
15334 {
15335 depth_iter = xcb_screen_allowed_depths_iterator (xcb_screen);
15336 for (; depth_iter.rem; xcb_depth_next (&depth_iter))
15337 {
15338 visual_iter = xcb_depth_visuals_iterator (depth_iter.data);
15339 for (; visual_iter.rem; xcb_visualtype_next (&visual_iter))
15340 {
15341 if (wanted == visual_iter.data->visual_id)
15342 {
15343 dpyinfo->xcb_visual = visual_iter.data;
15344 break;
15345 }
15346 }
15347 }
15348 }
15349#endif
15350
15264#ifdef HAVE_XINPUT2 15351#ifdef HAVE_XINPUT2
15265 dpyinfo->supports_xi2 = false; 15352 dpyinfo->supports_xi2 = false;
15266 int rc; 15353 int rc;
@@ -15329,9 +15416,19 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
15329 XkbNewKeyboardNotifyMask | XkbMapNotifyMask, 15416 XkbNewKeyboardNotifyMask | XkbMapNotifyMask,
15330 XkbNewKeyboardNotifyMask | XkbMapNotifyMask); 15417 XkbNewKeyboardNotifyMask | XkbMapNotifyMask);
15331 } 15418 }
15419#endif
15332 15420
15333 /* Figure out which modifier bits mean what. */ 15421#ifdef HAVE_XRENDER
15334 x_find_modifier_meanings (dpyinfo); 15422 int event_base, error_base;
15423 dpyinfo->xrender_supported_p
15424 = XRenderQueryExtension (dpyinfo->display, &event_base, &error_base);
15425
15426 if (dpyinfo->xrender_supported_p)
15427 {
15428 if (!XRenderQueryVersion (dpyinfo->display, &dpyinfo->xrender_major,
15429 &dpyinfo->xrender_minor))
15430 dpyinfo->xrender_supported_p = false;
15431 }
15335#endif 15432#endif
15336 15433
15337#if defined USE_CAIRO || defined HAVE_XFT 15434#if defined USE_CAIRO || defined HAVE_XFT
@@ -15350,11 +15447,6 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
15350 or larger than other for other applications, even if it is the same 15447 or larger than other for other applications, even if it is the same
15351 font name (monospace-10 for example). */ 15448 font name (monospace-10 for example). */
15352 15449
15353# ifdef HAVE_XRENDER
15354 int event_base, error_base;
15355 XRenderQueryExtension (dpyinfo->display, &event_base, &error_base);
15356# endif
15357
15358 char *v = XGetDefault (dpyinfo->display, "Xft", "dpi"); 15450 char *v = XGetDefault (dpyinfo->display, "Xft", "dpi");
15359 double d; 15451 double d;
15360 if (v != NULL && sscanf (v, "%lf", &d) == 1) 15452 if (v != NULL && sscanf (v, "%lf", &d) == 1)
@@ -15447,6 +15539,13 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
15447 ATOM_REFS_INIT ("_NET_WM_STATE_SKIP_TASKBAR", Xatom_net_wm_state_skip_taskbar) 15539 ATOM_REFS_INIT ("_NET_WM_STATE_SKIP_TASKBAR", Xatom_net_wm_state_skip_taskbar)
15448 ATOM_REFS_INIT ("_NET_WM_STATE_ABOVE", Xatom_net_wm_state_above) 15540 ATOM_REFS_INIT ("_NET_WM_STATE_ABOVE", Xatom_net_wm_state_above)
15449 ATOM_REFS_INIT ("_NET_WM_STATE_BELOW", Xatom_net_wm_state_below) 15541 ATOM_REFS_INIT ("_NET_WM_STATE_BELOW", Xatom_net_wm_state_below)
15542#ifdef HAVE_XKB
15543 ATOM_REFS_INIT ("Meta", Xatom_Meta)
15544 ATOM_REFS_INIT ("Super", Xatom_Super)
15545 ATOM_REFS_INIT ("Hyper", Xatom_Hyper)
15546 ATOM_REFS_INIT ("ShiftLock", Xatom_ShiftLock)
15547 ATOM_REFS_INIT ("Alt", Xatom_Alt)
15548#endif
15450 }; 15549 };
15451 15550
15452 int i; 15551 int i;
@@ -15477,6 +15576,11 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name)
15477 dpyinfo->Xatom_xsettings_sel = atoms_return[i]; 15576 dpyinfo->Xatom_xsettings_sel = atoms_return[i];
15478 } 15577 }
15479 15578
15579#ifdef HAVE_XKB
15580 /* Figure out which modifier bits mean what. */
15581 x_find_modifier_meanings (dpyinfo);
15582#endif
15583
15480 dpyinfo->x_dnd_atoms_size = 8; 15584 dpyinfo->x_dnd_atoms_size = 8;
15481 dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms 15585 dpyinfo->x_dnd_atoms = xmalloc (sizeof *dpyinfo->x_dnd_atoms
15482 * dpyinfo->x_dnd_atoms_size); 15586 * dpyinfo->x_dnd_atoms_size);
@@ -16128,6 +16232,7 @@ always uses gtk_window_move and ignores the value of this variable. */);
16128This option is only effective when Emacs is built with XInput 2 16232This option is only effective when Emacs is built with XInput 2
16129support. */); 16233support. */);
16130 Vx_scroll_event_delta_factor = make_float (1.0); 16234 Vx_scroll_event_delta_factor = make_float (1.0);
16235 DEFSYM (Qexpose, "expose");
16131 16236
16132 DEFVAR_BOOL ("x-gtk-use-native-input", x_gtk_use_native_input, 16237 DEFVAR_BOOL ("x-gtk-use-native-input", x_gtk_use_native_input,
16133 doc: /* Non-nil means to use GTK for input method support. 16238 doc: /* Non-nil means to use GTK for input method support.
@@ -16135,6 +16240,21 @@ This provides better support for some modern input methods, and is
16135only effective when Emacs is built with GTK. */); 16240only effective when Emacs is built with GTK. */);
16136 x_gtk_use_native_input = false; 16241 x_gtk_use_native_input = false;
16137 16242
16243 DEFVAR_LISP ("x-set-frame-visibility-more-laxly",
16244 x_set_frame_visibility_more_laxly,
16245 doc: /* Non-nil means set frame visibility more laxly.
16246If this is nil, Emacs is more strict when marking a frame as visible.
16247Since this may cause problems on some window managers, this variable can
16248be also set as follows: The value `focus-in' means to mark a frame as
16249visible also when a FocusIn event is received for it on GTK builds. The
16250value `expose' means to mark a frame as visible also when an Expose
16251event is received for it on any X build. The value `t' means to mark a
16252frame as visible in either of these two cases.
16253
16254Note that any non-nil setting may cause invisible frames get erroneously
16255reported as iconified. */);
16256 x_set_frame_visibility_more_laxly = Qnil;
16257
16138 DEFVAR_BOOL ("x-input-grab-touch-events", x_input_grab_touch_events, 16258 DEFVAR_BOOL ("x-input-grab-touch-events", x_input_grab_touch_events,
16139 doc: /* Non-nil means to actively grab touch events. 16259 doc: /* Non-nil means to actively grab touch events.
16140This means touch sequences that started on an Emacs frame will 16260This means touch sequences that started on an Emacs frame will