From 51ac64d9aa6aec969c38a3774310479d1cbb4dc9 Mon Sep 17 00:00:00 2001 From: Juri Linkov Date: Mon, 2 Sep 2019 00:30:18 +0300 Subject: [PATCH] Try to add more tab-bar support on Windows --- src/w32fns.c | 17 +++++++++++++++ src/w32reg.c | 2 ++ src/w32term.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+) diff --git a/src/w32fns.c b/src/w32fns.c index 0d6369461cd..8bc61d15ef6 100644 --- a/src/w32fns.c +++ b/src/w32fns.c @@ -6059,6 +6059,11 @@ DEFUN ("x-create-frame", Fx_create_frame, Sx_create_frame, /* No menu bar for child frames. */ store_frame_param (f, Qmenu_bar_lines, make_fixnum (0)); + gui_default_parameter (f, parameters, Qtab_bar_lines, + NILP (Vtab_bar_mode) + ? make_fixnum (0) : make_fixnum (1), + NULL, NULL, RES_TYPE_NUMBER); + gui_default_parameter (f, parameters, Qtool_bar_lines, NILP (Vtool_bar_mode) ? make_fixnum (0) : make_fixnum (1), @@ -8808,6 +8813,9 @@ and width values are in pixels. `menu-bar-size' is a cons of the width and height of the menu bar of FRAME. +`tab-bar-size' is a cons of the width and height of the tab bar of + FRAME. + `tool-bar-external', if non-nil, means the tool bar is external (never included in the inner edges of FRAME). @@ -8830,6 +8838,7 @@ and width values are in pixels. unsigned int external_border_width, external_border_height; int title_bar_width = 0, title_bar_height = 0; int single_menu_bar_height, wrapped_menu_bar_height, menu_bar_height; + int tab_bar_height = FRAME_TAB_BAR_HEIGHT (f); int tool_bar_height = FRAME_TOOL_BAR_HEIGHT (f); int internal_border_width = FRAME_INTERNAL_BORDER_WIDTH (f); @@ -8903,6 +8912,13 @@ and width values are in pixels. Fcons (make_fixnum (menu_bar.rcBar.right - menu_bar.rcBar.left), make_fixnum (menu_bar_height))), + Fcons (Qtab_bar_size, + Fcons (make_fixnum + (tab_bar_height + ? (right - left - 2 * external_border_width + - 2 * internal_border_width) + : 0), + make_fixnum (tab_bar_height))), Fcons (Qtool_bar_external, Qnil), Fcons (Qtool_bar_position, tool_bar_height ? Qtop : Qnil), Fcons (Qtool_bar_size, @@ -8994,6 +9010,7 @@ menu bar or tool bar of FRAME. */) return list4 (make_fixnum (left + internal_border_width), make_fixnum (top + + FRAME_TAB_BAR_HEIGHT (f) + FRAME_TOOL_BAR_HEIGHT (f) + internal_border_width), make_fixnum (right - internal_border_width), diff --git a/src/w32reg.c b/src/w32reg.c index 99b3973d708..f156c378f93 100644 --- a/src/w32reg.c +++ b/src/w32reg.c @@ -36,6 +36,8 @@ along with GNU Emacs. If not, see . */ "emacs.tooltip.attributeBackground:SystemInfoWindow\0" \ "emacs.tool-bar.attributeForeground:SystemButtonText\0" \ "emacs.tool-bar.attributeBackground:SystemButtonFace\0" \ + "emacs.tab-bar.attributeForeground:SystemButtonText\0" \ + "emacs.tab-bar.attributeBackground:SystemButtonFace\0" \ "emacs.menu.attributeForeground:SystemMenuText\0" \ "emacs.menu.attributeBackground:SystemMenu\0" \ "emacs.scroll-bar.attributeForeground:SystemScrollbar\0" diff --git a/src/w32term.c b/src/w32term.c index 1f57635f6db..dc516390d16 100644 --- a/src/w32term.c +++ b/src/w32term.c @@ -168,6 +168,8 @@ int w32_keyboard_codepage; int w32_message_fd = -1; #endif /* CYGWIN */ +static void w32_handle_tab_bar_click (struct frame *, + struct input_event *); static void w32_handle_tool_bar_click (struct frame *, struct input_event *); static void w32_define_cursor (Window, Emacs_Cursor); @@ -3602,6 +3604,29 @@ w32_mouse_position (struct frame **fp, int insist, Lisp_Object *bar_window, unblock_input (); } + +/*********************************************************************** + Tab-bars + ***********************************************************************/ + +/* Handle mouse button event on the tab-bar of frame F, at + frame-relative coordinates X/Y. EVENT_TYPE is either ButtonPress + or ButtonRelease. */ + +static void +w32_handle_tab_bar_click (struct frame *f, struct input_event *button_event) +{ + int x = XFIXNAT (button_event->x); + int y = XFIXNAT (button_event->y); + + if (button_event->modifiers & down_modifier) + handle_tab_bar_click (f, x, y, 1, 0); + else + handle_tab_bar_click (f, x, y, 0, + button_event->modifiers & ~up_modifier); +} + + /*********************************************************************** Tool-bars @@ -4843,6 +4868,7 @@ w32_read_socket (struct terminal *terminal, if (f && !FRAME_ICONIFIED_P (f)) { if (!hlinfo->mouse_face_hidden && FIXNUMP (Vmouse_highlight) + && !EQ (f->tab_bar_window, hlinfo->mouse_face_window) && !EQ (f->tool_bar_window, hlinfo->mouse_face_window)) { clear_mouse_face (hlinfo); @@ -4868,6 +4894,7 @@ w32_read_socket (struct terminal *terminal, if (f && !FRAME_ICONIFIED_P (f)) { if (!hlinfo->mouse_face_hidden && FIXNUMP (Vmouse_highlight) + && !EQ (f->tab_bar_window, hlinfo->mouse_face_window) && !EQ (f->tool_bar_window, hlinfo->mouse_face_window)) { clear_mouse_face (hlinfo); @@ -4946,6 +4973,7 @@ w32_read_socket (struct terminal *terminal, if (f && !FRAME_ICONIFIED_P (f)) { if (!hlinfo->mouse_face_hidden && FIXNUMP (Vmouse_highlight) + && !EQ (f->tab_bar_window, hlinfo->mouse_face_window) && !EQ (f->tool_bar_window, hlinfo->mouse_face_window)) { clear_mouse_face (hlinfo); @@ -5051,6 +5079,7 @@ w32_read_socket (struct terminal *terminal, { /* If we decide we want to generate an event to be seen by the rest of Emacs, we put it here. */ + bool tab_bar_p = 0; bool tool_bar_p = 0; int button = 0; int up = 0; @@ -5060,6 +5089,31 @@ w32_read_socket (struct terminal *terminal, { w32_construct_mouse_click (&inev, &msg, f); + /* Is this in the tab-bar? */ + if (WINDOWP (f->tab_bar_window) + && WINDOW_TOTAL_LINES (XWINDOW (f->tab_bar_window))) + { + Lisp_Object window; + int x = XFIXNAT (inev.x); + int y = XFIXNAT (inev.y); + + window = window_from_coordinates (f, x, y, 0, 1, 0); + + if (EQ (window, f->tab_bar_window)) + { + w32_handle_tab_bar_click (f, &inev); + tab_bar_p = 1; + } + } + + if (tab_bar_p + || (dpyinfo->w32_focus_frame + && f != dpyinfo->w32_focus_frame + /* This does not help when the click happens in + a grand-parent frame. */ + && !frame_ancestor_p (f, dpyinfo->w32_focus_frame))) + inev.kind = NO_EVENT; + /* Is this in the tool-bar? */ if (WINDOWP (f->tool_bar_window) && WINDOW_TOTAL_LINES (XWINDOW (f->tool_bar_window))) @@ -5104,6 +5158,8 @@ w32_read_socket (struct terminal *terminal, if (f != 0) { f->mouse_moved = false; + if (!tab_bar_p) + f->last_tab_bar_item = -1; if (!tool_bar_p) f->last_tool_bar_item = -1; } @@ -5127,6 +5183,7 @@ w32_read_socket (struct terminal *terminal, event; any subsequent mouse-movement Emacs events should reflect only motion after the ButtonPress. */ f->mouse_moved = false; + f->last_tab_bar_item = -1; f->last_tool_bar_item = -1; dpyinfo->last_mouse_frame = f; } @@ -5140,6 +5197,7 @@ w32_read_socket (struct terminal *terminal, { w32_construct_mouse_wheel (&inev, &msg, f1); f1->mouse_moved = false; + f1->last_tab_bar_item = -1; f1->last_tool_bar_item = -1; dpyinfo->last_mouse_frame = f1; } -- 2.39.2