X-Git-Url: https://git.hcoop.net/bpt/emacs.git/blobdiff_plain/ed859c7aea4db00135a2c0e692895b3d13e99351..2bfa3d3e1fb347ba76bddf77f3e288049635821d:/src/xterm.c diff --git a/src/xterm.c b/src/xterm.c index 8c4e78073d..b64ca2d4d0 100644 --- a/src/xterm.c +++ b/src/xterm.c @@ -32,6 +32,16 @@ along with GNU Emacs. If not, see . */ #include "xterm.h" #include +/* If we have Xfixes extension, use it for pointer blanking. */ +#ifdef HAVE_XFIXES +#include +#endif + +/* Using Xft implies that XRender is available. */ +#ifdef HAVE_XFT +#include +#endif + /* Load sys/types.h if not already loaded. In some systems loading it twice is suicidal. */ #ifndef makedev @@ -70,6 +80,7 @@ along with GNU Emacs. If not, see . */ #include "xsettings.h" #include "xgselect.h" #include "sysselect.h" +#include "menu.h" #ifdef USE_X_TOOLKIT #include @@ -215,7 +226,6 @@ static void x_lower_frame (struct frame *); static const XColor *x_color_cells (Display *, int *); static int x_io_error_quitter (Display *); static struct terminal *x_create_terminal (struct x_display_info *); -void x_delete_terminal (struct terminal *); static void x_update_end (struct frame *); static void XTframe_up_to_date (struct frame *); static void x_clear_frame (struct frame *); @@ -308,7 +318,7 @@ int event_record_index; void record_event (char *locus, int type) { - if (event_record_index == sizeof (event_record) / sizeof (struct record)) + if (event_record_index == ARRAYELTS (event_record)) event_record_index = 0; event_record[event_record_index].locus = locus; @@ -348,8 +358,10 @@ x_find_topmost_parent (struct frame *f) unsigned int nchildren; win = wi; - XQueryTree (dpy, win, &root, &wi, &children, &nchildren); - XFree (children); + if (XQueryTree (dpy, win, &root, &wi, &children, &nchildren)) + XFree (children); + else + break; } return win; @@ -597,7 +609,13 @@ x_update_window_end (struct window *w, bool cursor_on_p, /* If a row with mouse-face was overwritten, arrange for XTframe_up_to_date to redisplay the mouse highlight. */ if (mouse_face_overwritten_p) - reset_mouse_highlight (MOUSE_HL_INFO (XFRAME (w->frame))); + { + Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (XFRAME (w->frame)); + + hlinfo->mouse_face_beg_row = hlinfo->mouse_face_beg_col = -1; + hlinfo->mouse_face_end_row = hlinfo->mouse_face_end_col = -1; + hlinfo->mouse_face_window = Qnil; + } } @@ -891,7 +909,7 @@ x_set_mouse_face_gc (struct glyph_string *s) else face_id = FACE_FOR_CHAR (s->f, face, 0, -1, Qnil); s->face = FACE_FROM_ID (s->f, face_id); - PREPARE_FACE_FOR_DISPLAY (s->f, s->face); + prepare_face_for_display (s->f, s->face); if (s->font == s->face->font) s->gc = s->face->gc; @@ -939,7 +957,7 @@ x_set_mode_line_face_gc (struct glyph_string *s) static void x_set_glyph_string_gc (struct glyph_string *s) { - PREPARE_FACE_FOR_DISPLAY (s->f, s->face); + prepare_face_for_display (s->f, s->face); if (s->hl == DRAW_NORMAL_TEXT) { @@ -3096,16 +3114,7 @@ static void XTtoggle_invisible_pointer (struct frame *f, int invisible) { block_input (); - if (invisible) - { - if (FRAME_DISPLAY_INFO (f)->invisible_cursor != 0) - XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), - FRAME_DISPLAY_INFO (f)->invisible_cursor); - } - else - XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), - f->output_data.x->current_cursor); - f->pointer_invisible = invisible; + FRAME_DISPLAY_INFO (f)->toggle_visible_pointer (f, invisible); unblock_input (); } @@ -4432,14 +4441,11 @@ xg_scroll_callback (GtkRange *range, gpointer user_data) { struct scroll_bar *bar = user_data; - gdouble position; int part = -1, whole = 0, portion = 0; GtkAdjustment *adj = GTK_ADJUSTMENT (gtk_range_get_adjustment (range)); struct frame *f = g_object_get_data (G_OBJECT (range), XG_FRAME_DATA); if (xg_ignore_gtk_scrollbar) return FALSE; - position = gtk_adjustment_get_value (adj); - switch (scroll) { @@ -4451,7 +4457,7 @@ xg_scroll_callback (GtkRange *range, part = scroll_bar_handle; whole = gtk_adjustment_get_upper (adj) - gtk_adjustment_get_page_size (adj); - portion = min ((int)position, whole); + portion = min ((int)value, whole); bar->dragging = portion; } break; @@ -5624,7 +5630,7 @@ static int temp_index; static short temp_buffer[100]; #define STORE_KEYSYM_FOR_DEBUG(keysym) \ - if (temp_index == sizeof temp_buffer / sizeof (short)) \ + if (temp_index == ARRAYELTS (temp_buffer)) \ temp_index = 0; \ temp_buffer[temp_index++] = (keysym) @@ -6454,7 +6460,7 @@ handle_one_xevent (struct x_display_info *dpyinfo, for (i = 0, nchars = 0; i < nbytes; i++) { - if (ASCII_BYTE_P (copy_bufptr[i])) + if (ASCII_CHAR_P (copy_bufptr[i])) nchars++; STORE_KEYSYM_FOR_DEBUG (copy_bufptr[i]); } @@ -6809,9 +6815,10 @@ handle_one_xevent (struct x_display_info *dpyinfo, { dpyinfo->grabbed |= (1 << event->xbutton.button); dpyinfo->last_mouse_frame = f; - - if (!tool_bar_p) - last_tool_bar_item = -1; +#if ! defined (USE_GTK) + if (f && !tool_bar_p) + f->last_tool_bar_item = -1; +#endif /* not USE_GTK */ } else dpyinfo->grabbed &= ~(1 << event->xbutton.button); @@ -7577,7 +7584,7 @@ x_connection_closed (Display *dpy, const char *error_message) { struct x_display_info *dpyinfo = x_display_info_for_display (dpy); Lisp_Object frame, tail; - ptrdiff_t idx = SPECPDL_INDEX (); + dynwind_begin (); error_msg = alloca (strlen (error_message) + 1); strcpy (error_msg, error_message); @@ -7666,7 +7673,7 @@ For details, see etc/PROBLEMS.\n", totally_unblock_input (); - unbind_to (idx, Qnil); + dynwind_end (); clear_waiting_for_input (); /* Tell GCC not to suggest attribute 'noreturn' for this function. */ @@ -7853,11 +7860,6 @@ xim_destroy_callback (XIM xim, XPointer client_data, XPointer call_data) #endif /* HAVE_X11R6 */ -#ifdef HAVE_X11R6 -/* This isn't prototyped in OSF 5.0 or 5.1a. */ -extern char *XSetIMValues (XIM, ...); -#endif - /* Open the connection to the XIM server on display DPYINFO. RESOURCE_NAME is the resource name Emacs uses. */ @@ -8739,34 +8741,11 @@ x_set_window_size (struct frame *f, int change_gravity, int width, int height, b unblock_input (); } - -/* Mouse warping. */ - -void -x_set_mouse_position (struct frame *f, int x, int y) -{ - int pix_x, pix_y; - - pix_x = FRAME_COL_TO_PIXEL_X (f, x) + FRAME_COLUMN_WIDTH (f) / 2; - pix_y = FRAME_LINE_TO_PIXEL_Y (f, y) + FRAME_LINE_HEIGHT (f) / 2; - - if (pix_x < 0) pix_x = 0; - if (pix_x > FRAME_PIXEL_WIDTH (f)) pix_x = FRAME_PIXEL_WIDTH (f); - - if (pix_y < 0) pix_y = 0; - if (pix_y > FRAME_PIXEL_HEIGHT (f)) pix_y = FRAME_PIXEL_HEIGHT (f); - - block_input (); - - XWarpPointer (FRAME_X_DISPLAY (f), None, FRAME_X_WINDOW (f), - 0, 0, 0, 0, pix_x, pix_y); - unblock_input (); -} /* Move the mouse to position pixel PIX_X, PIX_Y relative to frame F. */ void -x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) +frame_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y) { block_input (); @@ -8900,6 +8879,7 @@ void x_make_frame_visible (struct frame *f) { int original_top, original_left; + int tries = 0; block_input (); @@ -9007,7 +8987,13 @@ x_make_frame_visible (struct frame *f) /* Force processing of queued events. */ x_sync (f); - /* This hack is still in use at least for Cygwin. See + /* If on another desktop, the deiconify/map may be ignored and the + frame never becomes visible. XMonad does this. + Prevent an endless loop. */ + if (FRAME_ICONIFIED_P (f) && ++tries > 100) + break; + + /* This hack is still in use at least for Cygwin. See http://lists.gnu.org/archive/html/emacs-devel/2013-12/msg00351.html. Machines that do polling rather than SIGIO have been @@ -9230,6 +9216,11 @@ x_free_frame_resources (struct frame *f) commands to the X server. */ if (dpyinfo->display) { + /* Always exit with visible pointer to avoid weird issue + with Xfixes (Bug#17609). */ + if (f->pointer_invisible) + FRAME_DISPLAY_INFO (f)->toggle_visible_pointer (f, 0); + /* We must free faces before destroying windows because some font-driver (e.g. xft) access a window while finishing a face. */ @@ -9713,6 +9704,96 @@ my_log_handler (const gchar *log_domain, GLogLevelFlags log_level, } #endif +/* Create invisible cursor on X display referred by DPYINFO. */ + +static Cursor +make_invisible_cursor (struct x_display_info *dpyinfo) +{ + Display *dpy = dpyinfo->display; + static char const no_data[] = { 0 }; + Pixmap pix; + XColor col; + Cursor c = 0; + + x_catch_errors (dpy); + pix = XCreateBitmapFromData (dpy, dpyinfo->root_window, no_data, 1, 1); + if (! x_had_errors_p (dpy) && pix != None) + { + Cursor pixc; + col.pixel = 0; + col.red = col.green = col.blue = 0; + col.flags = DoRed | DoGreen | DoBlue; + pixc = XCreatePixmapCursor (dpy, pix, pix, &col, &col, 0, 0); + if (! x_had_errors_p (dpy) && pixc != None) + c = pixc; + XFreePixmap (dpy, pix); + } + + x_uncatch_errors (); + + return c; +} + +/* True if DPY supports Xfixes extension >= 4. */ + +static bool +x_probe_xfixes_extension (Display *dpy) +{ +#ifdef HAVE_XFIXES + int major, minor; + return XFixesQueryVersion (dpy, &major, &minor) && major >= 4; +#else + return false; +#endif /* HAVE_XFIXES */ +} + +/* Toggle mouse pointer visibility on frame F by using Xfixes functions. */ + +static void +xfixes_toggle_visible_pointer (struct frame *f, bool invisible) +{ +#ifdef HAVE_XFIXES + if (invisible) + XFixesHideCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); + else + XFixesShowCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f)); + f->pointer_invisible = invisible; +#else + emacs_abort (); +#endif /* HAVE_XFIXES */ +} + +/* Toggle mouse pointer visibility on frame F by using invisible cursor. */ + +static void +x_toggle_visible_pointer (struct frame *f, bool invisible) +{ + eassert (FRAME_DISPLAY_INFO (f)->invisible_cursor != 0); + if (invisible) + XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + FRAME_DISPLAY_INFO (f)->invisible_cursor); + else + XDefineCursor (FRAME_X_DISPLAY (f), FRAME_X_WINDOW (f), + f->output_data.x->current_cursor); + f->pointer_invisible = invisible; +} + +/* Setup pointer blanking, prefer Xfixes if available. */ + +static void +x_setup_pointer_blanking (struct x_display_info *dpyinfo) +{ + /* FIXME: the brave tester should set EMACS_XFIXES because we're suspecting + X server bug, see http://debbugs.gnu.org/cgi/bugreport.cgi?bug=17609. */ + if (egetenv ("EMACS_XFIXES") && x_probe_xfixes_extension (dpyinfo->display)) + dpyinfo->toggle_visible_pointer = xfixes_toggle_visible_pointer; + else + { + dpyinfo->toggle_visible_pointer = x_toggle_visible_pointer; + dpyinfo->invisible_cursor = make_invisible_cursor (dpyinfo); + } +} + /* Current X display connection identifier. Incremented for each next connection established. */ static unsigned x_display_id; @@ -9935,8 +10016,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) if (lim - SBYTES (Vinvocation_name) < SBYTES (Vsystem_name)) memory_full (SIZE_MAX); dpyinfo->x_id = ++x_display_id; - dpyinfo->x_id_name = xmalloc (SBYTES (Vinvocation_name) - + SBYTES (Vsystem_name) + 2); + dpyinfo->x_id_name = xmalloc_atomic (SBYTES (Vinvocation_name) + + SBYTES (Vsystem_name) + 2); strcat (strcat (strcpy (dpyinfo->x_id_name, SSDATA (Vinvocation_name)), "@"), SSDATA (Vsystem_name)); @@ -10006,14 +10087,27 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) #ifdef HAVE_XFT { - /* If we are using Xft, check dpi value in X resources. - It is better we use it as well, since Xft will use it, as will all - Gnome applications. If our real DPI is smaller or larger than the - one Xft uses, our font will look smaller or larger than other - for other applications, even if it is the same font name (monospace-10 - for example). */ - char *v = XGetDefault (dpyinfo->display, "Xft", "dpi"); + /* If we are using Xft, the following precautions should be made: + + 1. Make sure that the Xrender extension is added before the Xft one. + Otherwise, the close-display hook set by Xft is called after the one + for Xrender, and the former tries to re-add the latter. This results + in inconsistency of internal states and leads to X protocol error when + one reconnects to the same X server (Bug#1696). + + 2. Check dpi value in X resources. It is better we use it as well, + since Xft will use it, as will all Gnome applications. If our real DPI + is smaller or larger than the one Xft uses, our font will look smaller + or larger than other for other applications, even if it is the same + font name (monospace-10 for example). */ + + int event_base, error_base; + char *v; double d; + + XRenderQueryExtension (dpyinfo->display, &event_base, &error_base); + + v = XGetDefault (dpyinfo->display, "Xft", "dpi"); if (v != NULL && sscanf (v, "%lf", &d) == 1) dpyinfo->resy = dpyinfo->resx = d; } @@ -10103,7 +10197,7 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) }; int i; - const int atom_count = sizeof (atom_refs) / sizeof (atom_refs[0]); + const int atom_count = ARRAYELTS (atom_refs); /* 1 for _XSETTINGS_SN */ const int total_atom_count = 1 + atom_count; Atom *atoms_return = xmalloc (total_atom_count * sizeof *atoms_return); @@ -10141,6 +10235,8 @@ x_term_init (Lisp_Object display_name, char *xrm_option, char *resource_name) gray_bits, gray_width, gray_height, 1, 0, 1); + x_setup_pointer_blanking (dpyinfo); + #ifdef HAVE_X_I18N xim_initialize (dpyinfo, resource_name); #endif @@ -10433,9 +10529,8 @@ x_create_terminal (struct x_display_info *dpyinfo) { struct terminal *terminal; - terminal = create_terminal (); + terminal = create_terminal (output_x_window, &x_redisplay_interface); - terminal->type = output_x_window; terminal->display_info.x = dpyinfo; dpyinfo->terminal = terminal; @@ -10446,37 +10541,35 @@ x_create_terminal (struct x_display_info *dpyinfo) terminal->delete_glyphs_hook = x_delete_glyphs; terminal->ring_bell_hook = XTring_bell; terminal->toggle_invisible_pointer_hook = XTtoggle_invisible_pointer; - terminal->reset_terminal_modes_hook = NULL; - terminal->set_terminal_modes_hook = NULL; terminal->update_begin_hook = x_update_begin; terminal->update_end_hook = x_update_end; - terminal->set_terminal_window_hook = NULL; terminal->read_socket_hook = XTread_socket; terminal->frame_up_to_date_hook = XTframe_up_to_date; terminal->mouse_position_hook = XTmouse_position; terminal->frame_rehighlight_hook = XTframe_rehighlight; terminal->frame_raise_lower_hook = XTframe_raise_lower; terminal->fullscreen_hook = XTfullscreen_hook; + terminal->menu_show_hook = x_menu_show; +#if defined (USE_X_TOOLKIT) || defined (USE_GTK) + terminal->popup_dialog_hook = xw_popup_dialog; +#endif terminal->set_vertical_scroll_bar_hook = XTset_vertical_scroll_bar; terminal->condemn_scroll_bars_hook = XTcondemn_scroll_bars; terminal->redeem_scroll_bar_hook = XTredeem_scroll_bar; terminal->judge_scroll_bars_hook = XTjudge_scroll_bars; - terminal->delete_frame_hook = x_destroy_window; terminal->delete_terminal_hook = x_delete_terminal; - - terminal->rif = &x_redisplay_interface; + /* Other hooks are NULL by default. */ return terminal; } -void +static void x_initialize (void) { baud_rate = 19200; x_noop_count = 0; - last_tool_bar_item = -1; any_help_event_p = 0; ignore_next_mouse_click_timeout = 0;