From 28a16449218739dc41387b71233e9f9c0d62ceb9 Mon Sep 17 00:00:00 2001 From: Eli Zaretskii Date: Wed, 18 Sep 2013 11:26:03 +0300 Subject: [PATCH] Turn off text cursor when dropping down menus. --- src/term.c | 24 ++++++++++++++---------- src/w32console.c | 17 +++++++++++++++++ src/w32term.h | 4 ++++ 3 files changed, 35 insertions(+), 10 deletions(-) diff --git a/src/term.c b/src/term.c index 5dd70ac9249..b3d0faa8597 100644 --- a/src/term.c +++ b/src/term.c @@ -304,7 +304,11 @@ tty_hide_cursor (struct tty_display_info *tty) if (tty->cursor_hidden == 0) { tty->cursor_hidden = 1; +#ifdef WINDOWSNT + w32con_hide_cursor (); +#else OUTPUT_IF (tty, tty->TS_cursor_invisible); +#endif } } @@ -317,9 +321,13 @@ tty_show_cursor (struct tty_display_info *tty) if (tty->cursor_hidden) { tty->cursor_hidden = 0; +#ifdef WINDOWSNT + w32con_show_cursor (); +#else OUTPUT_IF (tty, tty->TS_cursor_normal); if (visible_cursor) OUTPUT_IF (tty, tty->TS_cursor_visible); +#endif } } @@ -3244,6 +3252,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, int title_faces[4]; /* face to display the menu title */ int faces[4], buffers_num_deleted = 0; struct frame *sf = SELECTED_FRAME (); + struct tty_display_info *tty = FRAME_TTY (sf); bool first_time; Lisp_Object saved_echo_area_message, selectface; @@ -3307,9 +3316,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, /* Turn off the cursor. Otherwise it shows through the menu panes, which is ugly. */ -#if 0 - show_cursor (0); /* FIXME: need a new hook, for w32console. */ -#endif + tty_hide_cursor (tty); /* Display the menu title. We subtract 1 from x0 and y0 because we want to interpret them as zero-based column and row coordinates, @@ -3405,9 +3412,7 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, { help_callback (menu_help_message, menu_help_paneno, menu_help_itemno); -#if 0 - show_cursor (0); /* FIXME */ -#endif + tty_hide_cursor (tty); prev_menu_help_message = menu_help_message; } /* We are busy-waiting for the mouse to move, so let's be nice @@ -3459,10 +3464,9 @@ tty_menu_activate (tty_menu *menu, int *pane, int *selidx, #endif while (statecount--) free_saved_screen (state[statecount].screen_behind); -#if 0 - show_cursor (1); /* turn cursor back on */ -#endif - /* Clean up any mouse events that are waiting inside Emacs event queue. + tty_show_cursor (tty); /* turn cursor back on */ + +/* Clean up any mouse events that are waiting inside Emacs event queue. These events are likely to be generated before the menu was even displayed, probably because the user pressed and released the button (which invoked the menu) too quickly. If we don't remove these events, diff --git a/src/w32console.c b/src/w32console.c index cb42bae1421..94bb5df07a4 100644 --- a/src/w32console.c +++ b/src/w32console.c @@ -62,6 +62,7 @@ static HANDLE prev_screen, cur_screen; static WORD char_attr_normal; static DWORD prev_console_mode; +static CONSOLE_CURSOR_INFO console_cursor_info; #ifndef USE_SEPARATE_SCREEN static CONSOLE_CURSOR_INFO prev_console_cursor; #endif @@ -95,6 +96,22 @@ w32con_move_cursor (struct frame *f, int row, int col) SetConsoleCursorPosition (cur_screen, cursor_coords); } +void +w32con_hide_cursor (void) +{ + GetConsoleCursorInfo (cur_screen, &console_cursor_info); + console_cursor_info.bVisible = FALSE; + SetConsoleCursorInfo (cur_screen, &console_cursor_info); +} + +void +w32con_show_cursor (void) +{ + GetConsoleCursorInfo (cur_screen, &console_cursor_info); + console_cursor_info.bVisible = TRUE; + SetConsoleCursorInfo (cur_screen, &console_cursor_info); +} + /* Clear from cursor to end of screen. */ static void w32con_clear_to_end (struct frame *f) diff --git a/src/w32term.h b/src/w32term.h index 41c5c71832a..e65c1146294 100644 --- a/src/w32term.h +++ b/src/w32term.h @@ -236,6 +236,10 @@ extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key); extern Lisp_Object x_get_focus_frame (struct frame *); +/* w32console.c */ +extern void w32con_hide_cursor (void); +extern void w32con_show_cursor (void); + #define PIX_TYPE COLORREF -- 2.39.2