Commit graph

147 commits

Author SHA1 Message Date
tokyo4j
4072a80eba menu: fix unexpected behavior when a menu is opened from another menu
server->menu_current should be cleared before calling actions_run() as
it may internally call menu_open_root(). Clearing it after actions_run()
leads to an inconsistent state where a menu is opened but
server->menu_current is NULL. It even lead to a segfault when the item
opening another menu is contained in a pipemenu, because
menu_open_root() calls destroy_pipemenu() when server->menu_current is
set, which makes accessing item->actions a UAF.
2025-02-07 17:58:55 +01:00
Consolatis
ed4553fc7e src/menu: add global config for menu.showIcons 2025-02-02 15:05:37 +00:00
Consolatis
1fa4070025 src/menu: add support for scalable menu icons 2025-02-02 15:05:37 +00:00
tinyboxvk
1a6dd845a2 Fix typos
Signed-off-by: tinyboxvk <13696594+tinyboxvk@users.noreply.github.com>
2025-01-09 06:59:57 +00:00
Johan Malm
956b271f9b menu: support pipemenu with the toplevel <menu> element
For example:

    <?xml version="1.0"?>
    <openbox_menu>
      <menu id="root-menu" label="" execute="obmenu-generator"/>
    </openbox_menu>

Fixes: #2238

Co-Authored-By: @Consolatis
2025-01-03 04:41:25 +01:00
tokyo4j
bad788ccdd Clear keyboard/pointer focus on Move/Resize, window switcher and menu
The previous revert fixed the problem of stuck modifier keys with
keybinds in Blender, but made Firefox show its menu bar with Alt-*
keybinds. This is fundamentally inevitable due to the limitation of
wayland protocol, but at least for the default Alt-Tab keybind for
window switcher, we can mitigate this problem by clearing the keyboard
focus when the window switcher is activated. This is what KWin does, and
we decided to follow that.

So in this commit, keyboard and pointer focus are temporarily cleared
while Move/Resize, window switcher and menu interactions and restored
after them. We slightly deviate from KWin as KWin doesn't clear the
keyboard focus while Move/Resize, but it solves our existing problem
that Firefox shows its menu bar after dragging it with default Alt-Drag
mousebind, and this is what Mutter does.

We considered other solutions, but they don't work well:
1. Send wl_keyboard.{leave,enter} every time keybinds/mousebinds are
   triggered. This solves the Firefox's menu bar problem, but that
   sounds like a workaround and sending unnecessary events every time is
   not desirable.
2. Send release events for both modifiers and keys even when they are
   bound to keybinds. This is what Mutter is doing, but it looks like an
   implementation issue and violates wayland protocol.
2024-12-29 16:27:34 +09:00
tokyo4j
66a3beb98b Don't open menu or start window switching while other server interaction
This should make the transition of the server state more predictable and
prevent potential bugs.
2024-12-28 21:28:22 +00:00
Johan Malm
2446c46069 string-helpers.c: add str_starts_with() 2024-12-18 18:32:25 +00:00
Johan Malm
cc838e79ed s/xmlParseMemory/xmlReadMemory/
...as xmlParseMemory() is deprecated
2024-12-17 21:51:47 +00:00
tokyo4j
40c7350064 menu: improve algorithm for menu placement with xdg-positioner
This commit delegates the calculation for menu position into wlroots
utilities for xdg_positioner.

Notable functional changes are:
- Slide the menu to fit in the output when it's opened out of the output
  (e.g. top-left window menu is opened when the window is overflowing to
  the left), rather than not updating the menu at all.
- The horizontal alignment of menus is now determined based on the size of
  each (sub)menu alone rather than the total width of entire menu tree.
  This means submenus can now overlap with is parents, but this is no
  longer a problem since we recently added support for menu borders.
- Fixed that pipemenus always follow the alignment of its parent even when
  it overflows from the output.
2024-12-15 11:43:23 +09:00
tokyo4j
01032ef3bd font: remove arrow character from font buffer
Arrow signs are specific to submenu items, so they would be more natural
to be handled in menu.c rather than accepting "arrow" in
font_buffer_create().

Also I allowed non-positive numbers for max_width in font_buffer_create(),
in which case the natural font width is used as the buffer width.
2024-12-14 20:09:53 +00:00
tokyo4j
10fc656c23 menu: some refactor
- Don't store font/background buffers in menuitem struct since we no
  longer dynamically update buffers of existing menuitems.
- Factor out the duplicated codes for creating menu item scenes for each
  unselected/selected states.
2024-12-14 20:09:53 +00:00
tokyo4j
45646c694f menu: invert the y-offset of submenus applied by menu.overlap.y
This follows Openbox's behavior.
2024-11-25 21:19:59 +00:00
tokyo4j
d70040c750 menu: overlap submenus by menu.border.width
This follows Openbox's behavior that aligns the first item of a submenu
with its parent item
2024-11-25 19:41:07 +00:00
tokyo4j
da418f9720 menu: support borders
This commit adds following theme configurations:

  menu.border.width: 1
  menu.border.color: #aaaaaa
2024-11-25 19:41:07 +00:00
tokyo4j
9703c1deca src/menu.c: remove unnecessary re-renderings of font buffers
I missed that `scaled_font_buffer_update()` has `max_width` argument and
the subsequent calls to `scaled_font_buffer_set_max_width()` caused
unnecessary re-renderings.
2024-11-19 03:12:28 +01:00
tokyo4j
f8ed199197 menu: fix UAFs in menu_destroy() and item_destroy()
This fixes use-after-free when there's only 1 desktop and
menu_hide_submenu() is called to delete "Workspaces" submenu in
client-menu before menu scenes are initialized.

As menu_create() and item_create() no longer initialize scenes after
76515316, menu->scene_tree and item->tree should be null-checked.
2024-11-14 16:32:54 +01:00
tokyo4j
b96742a039 menu: eliminate dead code
The deleted lines were dead code that didn't make any sense (even if it
were not dead, it should have recreated the parent of the hidden menu
rather than the hidden menu itself).
2024-11-14 06:11:13 +00:00
tokyo4j
10ee838c3b menu: fix menus disappearing when opening pipemenu
Commit 7651531 introduced a regression: `menu_update_scene()` which
re-creates a menu scene was called for all the menus when a pipemenu is
created, so the menus (parent of the pipemenu) were always moved to (0,0)
and hidden, and the pipemenu was incorrectly positioned.

This commit fixes it by calling `menu_update_scene()` only for the
pipemenu when it's created.
2024-11-14 06:11:13 +00:00
tokyo4j
d7e6f3a7a8 menu: invalidate nested duplicated menus
Prior to this commit, nesting the same menus caused stack overflow at
`close_all_submenus()` when trying to open it.
2024-11-14 05:28:06 +09:00
tokyo4j
3a7c6ce300 menu: consider padding when applying menu.width.{min,max} 2024-11-13 20:08:15 +00:00
tokyo4j
ec520d3520 menu: fix "menu.title.text.justify: right" not working 2024-11-13 20:08:15 +00:00
tokyo4j
7651531632 menu: refactor in preparation for richer menu design
This commit separates the process of creating scene-trees of the menu
items into `{item,separator,title}_create_scene()`. This will make it
easier to draw richer menu designs like borders, paddings and rounded
corners.
2024-11-13 20:08:15 +00:00
tokyo4j
90fad69027 src/menu.c: move some post_processing() and menu_update_width() 2024-11-13 20:08:15 +00:00
tokyo4j
d5daee6b96 menu: fix UAF of server->menu_current
This fixes segfault when exiting with a menu opened, which is a regression
from eaf11fac.
2024-11-13 16:52:19 +01:00
tokyo4j
1639919889 theme: rename menu_item_padding to menu_items_padding 2024-11-12 17:25:39 +00:00
Consolatis
2a825008c6 foreign-toplevel: create generic abstraction 2024-11-09 20:06:19 +00:00
Tomi Ollila
f052eaea6f menu: use only menu_separator_padding_width to pad separators w/o label
I.e. drop the extra padding from menu_item_padding_x that got there
when separators with labels were implemented.
2024-11-06 20:40:28 +00:00
Tomi Ollila
ad2d24fb42 menu: use "MenuHeader" font height in separators with label 2024-10-28 19:06:32 +00:00
Johan Malm
e912964f73 menu: fix UAF in client-list-combined-menu after window destruction
Update client-list-combined-menu when a window is destroyed to avoid
SEGFAULT when selecting an that window entry in it.
2024-10-24 20:52:17 +01:00
Hiroaki Yamamoto
bb87ca5493
menu: fix memory leak in update_client_send_to_menu() (#2252) 2024-10-20 09:44:32 +01:00
Hiroaki Yamamoto
1d79e34c2b
menu: fix the calculation for centered titles (#2251) 2024-10-20 09:41:53 +01:00
Johan Malm
c7983129d4 cosmic-workspaces: fix menu.c 2024-10-01 21:45:13 +01:00
tokyo4j
25f5cdd3a6 Refactor the logic of placing client-menu with ShowMenu action
Before this commit, we assumed `ShowMenu` action is not bound to any
buttons other than window menu button and always place the client-menu
under the window-menu button when atCursor="no". Also, it was going to be
difficult to distinguish whether the action is executed from the window
menu button or the window icon, which will be added soon.

This commit fixes it to open the menu under the actually-clicked button by
passing `cursor_context` to `actions_run()`, with some refactoring:
- `seat->pressed.resize_edges` is removed and it's calculated from the
  cursor position and `seat->pressed.type` just before running Resize
  action. This slightly changes the existing logic to determine the
  resizing edges with Alt-Right + Drag mousebinding, but
  `seat->pressed.type` is still stored on button press so it doesn't bring
  back the issue #543.
- `seat->pressed.toplevel` is removed and `get_toplevel()` in
  `update_pressed_surface()` may be called more often, but its overhead
  will be negligible.
2024-09-21 18:07:34 +01:00
Droc
331ded0328 client list combines fix empty title
this adds a check for title being null or empty as well as
existence of toplevel.handle
2024-09-19 20:57:39 +01:00
Droc
4a1375c701 client send to menu
Shows all workspaces that current view can be sent to.
Works best when added to Client menu.

<menu id="client-send-to-menu" label="Send to..." />

Menu uses ">" and "<"  to highlight the current workspace
2024-09-19 06:36:27 +01:00
Droc
71b2b5a4bc menu: support client-list-combined-menu
...showing windows across all workspaces.

<action name="ShowMenu" menu="client-list-combined-menu"/>
2024-09-17 22:13:23 +01:00
droc12345
8fda9968e6
menu: add title theme options (#2097)
Add theme options `menu.title.text.color` and `menu.title.text.justify`.

Add font place MenuHeader: `<font place="MenuHeader">`

Add `Oblique` font style

```
<theme>
  <font>
    <slant>Oblique</slant>
  </font>
</theme>
```
2024-08-21 18:27:07 +01:00
Johan Malm
9bc381d9e8 menu: use theme->menu_item_height instead of menu->item_height
...and set it in theme.c post_processing()
2024-08-20 18:01:22 +01:00
Johan Malm
0552c6b7f0 menu: support titles
...defined by `<separator label="">`.

Also add the theme option `menu.title.bg.color: #589bda`

The following will be added in separate commits
- menu.title.bg.border.color: #7cb6ec
- menu.title.text.color: #ffffff
- menu.title.text.justify: center
2024-08-20 18:01:22 +01:00
Consolatis
5ae9eed1ac
src/menu: prevent delayed pipe menu response on item destroy (#2094)
Without this patch we would happily access `pipe_ctx->item`
members even if the item had been destroyed in the meantime.
2024-08-20 17:09:17 +01:00
Johan Malm
7dd7b5cc59 menu: fix crash triggered by pipemenu without parent <menu>
...such as the one in the example below:

    <?xml version="1.0" encoding="UTF-8"?>
    <openbox_menu>
      <menu id="root-menu" label="obmenu-generator" execute="obmenu-generator"/>
    </openbox_menu>

We should consider supporting this construct in future.

Reported-by: cry0xen via IRC
2024-07-15 22:00:11 +01:00
John Lindgren
b1a6a36582 menu: fix small memory leaks 2024-07-08 19:44:50 +01:00
John Lindgren
3ca1e94b1f menu: try other paths (and fix memory leak) if fopen() fails 2024-07-08 19:44:50 +01:00
Johan Malm
b8c3e064e7 menu: support menu.overlap.x with pipemenus
No inteded functional change intended with refactoring of
get_submenu_position().

Fixes #1870
2024-06-28 19:58:01 +02:00
Johan Malm
1dadb12807 menu: capitalize Roll Up/Down
...because it seems like better English and is more consistent with other
menu entries.

Same for 'Move Left' and 'Move Right'
2024-06-15 21:31:00 +01:00
Johan Malm
4ee538c6cd menu: ignore <item> without parent <menu>
...to avoid assert() in item_create() because current_menu is NULL.

Reproduce crash with...

    <?xml version="1.0" encoding="utf-8"?>
    <openbox_menu>
      <item label="foo"/>
    </openbox_menu>
2024-06-13 23:17:16 +02:00
tokyo4j
23b96ad2a6 Replace _ with - in source file names 2024-05-22 07:10:51 +01:00
tokyo4j
95dc4ac4b5 menu: reset parser state in menu_finish()
This fixes use-after-free in `fill_item()` on Reconfigure with
invalid `menu.xml` like below:

<openbox_menu>
  <menu id="root-menu">
    <item id="rofi-run" label="Run command">
      <action name="Execute" command="rofi-run" />
    </item>
  </menu>
</openbox_menu>
2024-05-05 12:49:39 +02:00
John Lindgren
a8f98cb90b common/buf: rename buf->buf to buf->data 2024-04-18 07:00:23 +01:00