From 68b99a3e6615a7f3eb21dbd72b0b796960831a5e Mon Sep 17 00:00:00 2001 From: Yuuki Harano Date: Mon, 8 Jul 2019 01:56:21 +0900 Subject: [PATCH] Implement invisible-pointer to create blinking effect MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/pgtkterm.h (struct pgtk_display_info): add cursor and callback * src/pgtkterm.c (x_setup_pointer_blanking) (XTtoggle_invisible_pointer, x_toggle_visible_pointer): new functions (pgtk_create_terminal, pgtk_term_init): use gdkcursor * src/pgtkgui.h: define Emacs_cursor as a GdkCursor invisible pointer 実装。 --- src/pgtkgui.h | 2 +- src/pgtkterm.c | 39 +++++++++++++++++++++++++++++++++------ src/pgtkterm.h | 7 +++++++ 3 files changed, 41 insertions(+), 7 deletions(-) diff --git a/src/pgtkgui.h b/src/pgtkgui.h index e7e614ea1fd..be9fb25bfe2 100644 --- a/src/pgtkgui.h +++ b/src/pgtkgui.h @@ -43,7 +43,7 @@ typedef unichar XChar2b; (*(chp) & 0x00ff) -typedef void *Emacs_Cursor; +typedef struct _GdkCursor *Emacs_Cursor; typedef void * Color; typedef int Window; diff --git a/src/pgtkterm.c b/src/pgtkterm.c index 6d0dc9695ad..2e98dedbc75 100644 --- a/src/pgtkterm.c +++ b/src/pgtkterm.c @@ -4527,6 +4527,36 @@ XTframe_rehighlight (struct frame *frame) pgtk_frame_rehighlight (FRAME_DISPLAY_INFO (frame)); } + +/* Toggle mouse pointer visibility on frame F by using invisible cursor. */ + +static void +x_toggle_visible_pointer (struct frame *f, bool invisible) +{ + Emacs_Cursor cursor; + if (invisible) + cursor = FRAME_DISPLAY_INFO (f)->invisible_cursor; + else + cursor = f->output_data.pgtk->current_cursor; + gdk_window_set_cursor(gtk_widget_get_window(FRAME_GTK_WIDGET(f)), cursor); + f->pointer_invisible = invisible; +} + +static void +x_setup_pointer_blanking (struct pgtk_display_info *dpyinfo) +{ + dpyinfo->toggle_visible_pointer = x_toggle_visible_pointer; + dpyinfo->invisible_cursor = gdk_cursor_new_for_display(dpyinfo->gdpy, GDK_BLANK_CURSOR); +} + +static void +XTtoggle_invisible_pointer (struct frame *f, bool invisible) +{ + block_input (); + FRAME_DISPLAY_INFO (f)->toggle_visible_pointer (f, invisible); + unblock_input (); +} + /* The focus has changed. Update the frames as necessary to reflect the new situation. Note that we can't change the selected frame here, because the Lisp code we are interrupting might become confused. @@ -4570,6 +4600,7 @@ pgtk_create_terminal (struct pgtk_display_info *dpyinfo) terminal->clear_frame_hook = pgtk_clear_frame; terminal->ring_bell_hook = pgtk_ring_bell; + terminal->toggle_invisible_pointer_hook = XTtoggle_invisible_pointer; terminal->update_begin_hook = pgtk_update_begin; terminal->update_end_hook = pgtk_update_end; terminal->read_socket_hook = pgtk_read_socket; @@ -6136,13 +6167,11 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name) /* We must create a GTK cursor, it is required for GTK widgets. */ dpyinfo->xg_cursor = xg_create_default_cursor (dpyinfo->gdpy); -#if 0 dpyinfo->vertical_scroll_bar_cursor - = XCreateFontCursor (dpyinfo->display, XC_sb_v_double_arrow); + = gdk_cursor_new_for_display(dpyinfo->gdpy, GDK_SB_V_DOUBLE_ARROW); dpyinfo->horizontal_scroll_bar_cursor - = XCreateFontCursor (dpyinfo->display, XC_sb_h_double_arrow); -#endif + = gdk_cursor_new_for_display(dpyinfo->gdpy, GDK_SB_H_DOUBLE_ARROW); reset_mouse_highlight (&dpyinfo->mouse_highlight); @@ -6153,9 +6182,7 @@ pgtk_term_init (Lisp_Object display_name, char *resource_name) dpyinfo->resy = dpi; } -#if 0 x_setup_pointer_blanking (dpyinfo); -#endif xsettings_initialize (dpyinfo); diff --git a/src/pgtkterm.h b/src/pgtkterm.h index c48b1b3e00f..3222bb25975 100644 --- a/src/pgtkterm.h +++ b/src/pgtkterm.h @@ -209,6 +209,13 @@ struct pgtk_display_info /* The scroll bar in which the last motion event occurred. */ void *last_mouse_scroll_bar; + /* The invisible cursor used for pointer blanking. + Unused if this display supports Xfixes extension. */ + Emacs_Cursor invisible_cursor; + + /* Function used to toggle pointer visibility on this display. */ + void (*toggle_visible_pointer) (struct frame *, bool); + /* The GDK cursor for scroll bars and popup menus. */ GdkCursor *xg_cursor; -- 2.39.5