From 012e39878ed6c8c767f14f7af2404044e60f4f42 Mon Sep 17 00:00:00 2001 From: Philipp Kaeser <130065133+phkaeser@users.noreply.github.com> Date: Sun, 1 Dec 2024 22:28:38 +0200 Subject: [PATCH] Slight refactor of wlmaker_root_menu_create, for bundling mapping + pointer-grabbing. (#146) --- src/action.c | 16 +++++----------- src/root_menu.c | 9 +++++++++ src/root_menu.h | 2 ++ src/server.c | 14 ++------------ 4 files changed, 18 insertions(+), 23 deletions(-) diff --git a/src/action.c b/src/action.c index a6ed9d3c..5a710e56 100644 --- a/src/action.c +++ b/src/action.c @@ -261,19 +261,13 @@ void wlmaker_action_execute(wlmaker_server_t *server_ptr, &server_ptr->style.window, &server_ptr->style.menu, false, + wlmtk_root_get_current_workspace(server_ptr->root_ptr), server_ptr->env_ptr); - } - - if (NULL == server_ptr->root_menu_ptr) break; - - window_ptr = wlmaker_root_menu_window(server_ptr->root_menu_ptr); - workspace_ptr = wlmtk_window_get_workspace(window_ptr); - if (NULL == workspace_ptr) { - workspace_ptr = wlmtk_root_get_current_workspace( - server_ptr->root_ptr); - wlmtk_workspace_map_window(workspace_ptr, window_ptr); } else { - wlmtk_workspace_activate_window(workspace_ptr, window_ptr); + window_ptr = wlmaker_root_menu_window(server_ptr->root_menu_ptr); + wlmtk_workspace_activate_window( + workspace_ptr = wlmtk_window_get_workspace(window_ptr), + window_ptr); } break; diff --git a/src/root_menu.c b/src/root_menu.c index 34d1c344..ab2d31b2 100644 --- a/src/root_menu.c +++ b/src/root_menu.c @@ -75,6 +75,7 @@ wlmaker_root_menu_t *wlmaker_root_menu_create( const wlmtk_window_style_t *window_style_ptr, const wlmtk_menu_style_t *menu_style_ptr, bool right_click_mode, + wlmtk_workspace_t *workspace_ptr, wlmtk_env_t *env_ptr) { wlmaker_root_menu_t *root_menu_ptr = logged_calloc( @@ -151,6 +152,14 @@ wlmaker_root_menu_t *wlmaker_root_menu_create( } wlmtk_window_set_properties(root_menu_ptr->window_ptr, properties); + wlmtk_workspace_map_window(workspace_ptr, root_menu_ptr->window_ptr); + if (right_click_mode) { + wlmtk_container_pointer_grab( + wlmtk_window_element(root_menu_ptr->window_ptr)->parent_container_ptr, + wlmtk_window_element(root_menu_ptr->window_ptr)); + } + + return root_menu_ptr; } diff --git a/src/root_menu.h b/src/root_menu.h index 6b638dd6..e5d8b240 100644 --- a/src/root_menu.h +++ b/src/root_menu.h @@ -38,6 +38,7 @@ extern "C" { * @param window_style_ptr * @param menu_style_ptr * @param env_ptr + * @param workspace_ptr * @param right_click_mode * * @return Handle of the root menu, or NULL on error. @@ -47,6 +48,7 @@ wlmaker_root_menu_t *wlmaker_root_menu_create( const wlmtk_window_style_t *window_style_ptr, const wlmtk_menu_style_t *menu_style_ptr, bool right_click_mode, + wlmtk_workspace_t *workspace_ptr, wlmtk_env_t *env_ptr); /** diff --git a/src/server.c b/src/server.c index 18e5a036..97ad2266 100644 --- a/src/server.c +++ b/src/server.c @@ -799,23 +799,13 @@ void _wlmaker_server_unclaimed_button_event_handler( &server_ptr->style.window, &server_ptr->style.menu, true, + wlmtk_root_get_current_workspace(server_ptr->root_ptr), server_ptr->env_ptr); - if (NULL != server_ptr->root_menu_ptr) { - - wlmtk_window_t *window_ptr = wlmaker_root_menu_window( - server_ptr->root_menu_ptr); - wlmtk_workspace_t *workspace_ptr = - wlmtk_root_get_current_workspace(server_ptr->root_ptr); - wlmtk_workspace_map_window(workspace_ptr, window_ptr); - wlmtk_container_pointer_grab( - wlmtk_window_element(window_ptr)->parent_container_ptr, - wlmtk_window_element(window_ptr)); - // TODO(kaeser@gubbe.ch): Keep the menu window's position entirely // within the desktop area. wlmtk_window_set_position( - window_ptr, + wlmaker_root_menu_window(server_ptr->root_menu_ptr), server_ptr->cursor_ptr->wlr_cursor_ptr->x, server_ptr->cursor_ptr->wlr_cursor_ptr->y); }