Skip to content

Commit

Permalink
Slight refactor of wlmaker_root_menu_create, for bundling mapping + p…
Browse files Browse the repository at this point in the history
…ointer-grabbing. (#146)
  • Loading branch information
phkaeser authored Dec 1, 2024
1 parent 9a92dd2 commit 012e398
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
16 changes: 5 additions & 11 deletions src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions src/root_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/root_menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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);

/**
Expand Down
14 changes: 2 additions & 12 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -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([email protected]): 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);
}
Expand Down

0 comments on commit 012e398

Please sign in to comment.