Skip to content

Commit

Permalink
Create root menu on right-click, and destroy when releasing right but…
Browse files Browse the repository at this point in the history
…ton. (#144)

* Adds header declaration for wlmtk_workspace_hog_window_focus.

* Document some thoughts around input grabbing.

* Remove definition of wlmtk_workspace_hog_window. Needs to be implemented at lower layers.

* Adds methods for pointer grabbing and releasing.

* Improves documentation about pointer grabbing.

* Fixes typo.

* Starts with tests for pointer grab.

* Adds test to verify pointer grab cancellation propagates to parent, when grab-element is removed.

* Add tests to verify pointer grab handling.

* Cancels grab in elements added to a container.

* Removes empty 'Data' section header comment.

* Adds right-click handling to the window.

* Exposes right-click-mode through root menu option.

* Prevents double deletion.

* Updates roadmap.

* More consistent handling of button event in titlebar title.
  • Loading branch information
phkaeser authored Dec 1, 2024
1 parent 9cec255 commit 826944f
Show file tree
Hide file tree
Showing 14 changed files with 412 additions and 12 deletions.
2 changes: 1 addition & 1 deletion doc/ROADMAP.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Support for visual effects to improve usability, but not for pure show.
* Menu, based on toolkit.
* [done] Root menu: Basic actions (quit, lock, next- or previous workspace).
* [done] Menu shown on right-button-down, items trigger on right-button-up.
* When invoked on unclaimed button, exits menu on button release.
* [done] When invoked on unclaimed button, exits menu on button release.
* Available as window menu in windows.
* Available as (hardcoded) application menu.
* Menu with submenus.
Expand Down
1 change: 1 addition & 0 deletions src/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,7 @@ void wlmaker_action_execute(wlmaker_server_t *server_ptr,
server_ptr,
&server_ptr->style.window,
&server_ptr->style.menu,
false,
server_ptr->env_ptr);
}

Expand Down
16 changes: 13 additions & 3 deletions src/root_menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ wlmaker_root_menu_t *wlmaker_root_menu_create(
wlmaker_server_t *server_ptr,
const wlmtk_window_style_t *window_style_ptr,
const wlmtk_menu_style_t *menu_style_ptr,
bool right_click_mode,
wlmtk_env_t *env_ptr)
{
wlmaker_root_menu_t *root_menu_ptr = logged_calloc(
Expand All @@ -88,6 +89,11 @@ wlmaker_root_menu_t *wlmaker_root_menu_create(
wlmaker_root_menu_destroy(root_menu_ptr);
return NULL;
}
if (right_click_mode) {
wlmtk_menu_set_mode(
wlmaker_root_menu_menu(server_ptr->root_menu_ptr),
WLMTK_MENU_MODE_RIGHTCLICK);
}

for (const wlmaker_root_menu_item_t *i_ptr = &_wlmaker_root_menu_items[0];
i_ptr->text_ptr != NULL;
Expand Down Expand Up @@ -137,9 +143,13 @@ wlmaker_root_menu_t *wlmaker_root_menu_create(
}
wlmtk_window_set_title(root_menu_ptr->window_ptr, "Root Menu");
wlmtk_window_set_server_side_decorated(root_menu_ptr->window_ptr, true);
wlmtk_window_set_properties(
root_menu_ptr->window_ptr,
WLMTK_WINDOW_PROPERTY_CLOSABLE);
uint32_t properties = 0;
if (right_click_mode) {
properties |= WLMTK_WINDOW_PROPERTY_RIGHTCLICK;
} else {
properties |= WLMTK_WINDOW_PROPERTY_CLOSABLE;
}
wlmtk_window_set_properties(root_menu_ptr->window_ptr, properties);

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,13 +38,15 @@ extern "C" {
* @param window_style_ptr
* @param menu_style_ptr
* @param env_ptr
* @param right_click_mode
*
* @return Handle of the root menu, or NULL on error.
*/
wlmaker_root_menu_t *wlmaker_root_menu_create(
wlmaker_server_t *server_ptr,
const wlmtk_window_style_t *window_style_ptr,
const wlmtk_menu_style_t *menu_style_ptr,
bool right_click_mode,
wlmtk_env_t *env_ptr);

/**
Expand Down
7 changes: 4 additions & 3 deletions src/server.c
Original file line number Diff line number Diff line change
Expand Up @@ -798,18 +798,19 @@ void _wlmaker_server_unclaimed_button_event_handler(
server_ptr,
&server_ptr->style.window,
&server_ptr->style.menu,
true,
server_ptr->env_ptr);

if (NULL != server_ptr->root_menu_ptr) {
wlmtk_menu_set_mode(
wlmaker_root_menu_menu(server_ptr->root_menu_ptr),
WLMTK_MENU_MODE_RIGHTCLICK);

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.
Expand Down
Loading

0 comments on commit 826944f

Please sign in to comment.