Commit graph

107 commits

Author SHA1 Message Date
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
John Lindgren
0573f16693 common: remove buf_init(), add BUF_INIT and buf_move()
Add a BUF_INIT macro, which makes it easier to initialize a struct buf
to an empty string (without a heap allocation).

Add buf_move() to move the contents of one struct buf to another (the
source is reset to BUF_INIT, analogous to C++ move-assignment).

Use buf_reset() instead of directly calling `free(s->buf)` since the
internal buf may not always be allocated by malloc() now.
2024-04-18 07:00:23 +01:00
Johan Malm
f3b68b8fb5 menu: support pipe menus
See labwc-menu(5) for usage.

Co-authored-by: @Consolatis
2024-03-24 21:44:16 +00:00
Johan Malm
0671a3bfd3 menu: move already-on-selected-item check
...menu_process_item_selection() as the previous variant did not work.
2024-03-24 21:44:16 +00:00
Johan Malm
38a60b04d9 menu: minor refactor of menu_configure() 2024-03-24 21:44:16 +00:00
Johan Malm
138979c506 menu: s/menu_open/menu_open_root/
...to be consistent with the 'close' equivalent
2024-03-24 21:44:16 +00:00
John Lindgren
4fa51b950c common: render text buffers with opaque background
After a roundabout discussion[1] with wlroots devs, it's become apparent
that subpixel text rendering (a.k.a. "ClearType") does not work properly
when rendering over a transparent background, as labwc currently does.

Basically it comes down to the fact that the color of semi-transparent
pixels (which is adjusted redder or bluer to compensate for RGB subpixel
alignment) depends somewhat on background color. When rendering over
transparency, the text engine doesn't know the intended background color
and can't adjust the pixel colors correctly.

With Pango/Cairo, the end result can range from grayscale rendering (no
subpixel rendering at all) to wrong/oversaturated colors (for example,
bright pink pixels when rendering white text on blue background).

This change solves the issue by first filling the text buffer with an
opaque background color before rendering the text over it. Currently,
this is easy since the background is always a solid color. It may be a
little more complex (but doable) if we implement gradients in future.

Note that GTK 4 (and to some degree, recent versions of Microsoft
Windows) avoid this issue by disabling subpixel rendering altogether. I
would much prefer that labwc NOT do this -- it results in noticeably
blurrier text on non-retina LCD screens, which are still common.

[1] https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3822
2024-03-17 19:09:53 +00:00
Hiroaki Yamamoto
be37f9a564
Fix various typos across the codebase 2024-03-08 13:59:20 +01:00
Johan Malm
698c7ace07 config: support merging multiple config files
Add the -m|--merge-config command line option to iterate backwards over
XDG Base Dir paths and read config/theme files multiple times.

For example if both ~/.config/labwc/rc.xml and /etc/xdg/labwc/rc.xml
exist, the latter will be read first and then the former (if
--merge-config is enabled).

When $XDG_CONFIG_HOME is defined, make it replace (not augment)
$HOME/.config. Similarly, make $XDG_CONFIG_DIRS replace /etc/xdg when
defined.

XDG Base Dir Spec does not specify whether or not an application (or a
compositor!) should (a) define that only the file under the most important
base directory should be used, or (b) define rules for merging the
information from the different files.

ref: https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

In the case of labwc there is a use-case for both positions, just to be
clear, the default behaviour, described by position (a) above, does NOT
change.

This change affects the following config/theme files:
  - rc.xml
  - menu.xml
  - autostart
  - environment
  - themerc
  - themerc-override
  - Theme buttons, for example max.xbm

Instead of caching global config/theme directories, create lists of paths
(e.g.  '/home/foo/.config/labwc/rc.xml', '/etc/xdg/labwc/rc.xml', etc).
This creates more common parsing logic and just reversing the direction
of iteration and breaks early if config-merge is not wanted.

Enable better fallback for themes. For example if a particular theme does
not exist in $HOME/.local/share/themes, it will be searched for in
~/.themes/ and so on. This also applies to theme buttons which now
fallback on an individual basis.

Avoid using stat() in most situations and just go straight to fopen().

Fixes #1406
2024-01-18 20:20:36 +00:00
Consolatis
e05bedb140 feat: add Shade/Unshade/ToggleShade actions
This builds on the work of @Consolatis in #1018.

Co-authored-by: Consolatis <35009135+Consolatis@users.noreply.github.com>
Co-authored-by: Andrew J. Hesford <ajh@sideband.org>
2024-01-15 21:37:36 +00:00
Johan Malm
e9023f51c6 menu: run actions on button release
...and call actions after closing menus so that virtual keyboard input
caused by actions are sent to the surface with keyboard-focus rather
than being consumed by the open menu.

Fixes: #1366
2024-01-11 20:31:24 +00:00
kyak
266690091f Remove headers not being used directly
Fix clangd warnings regarding headers not being used directly.
2023-12-22 20:19:39 +00:00
Johan Malm
3101b0c5b1 menu: move ToggleOmnipresent to workspaces
...and rename it to "Always on Visible Workspace"

Issue: #1316
2023-12-21 02:47:44 +01:00
nullableVoidPtr
41891209fc chase: use wlroots tree node getters 2023-12-03 18:24:26 +00:00
Brandon Nason
bad8f334ea Add omnipresent flag for views 2023-11-28 21:41:30 +00:00
Johan Malm
a105c8781a menu: use wl_list instead of array
...to make it easier to split menu.c into smaller chunks without
exposing nr_menus variable.
2023-10-10 06:17:37 +01:00
Johan Malm
b22722dafa menu: minor coding style tweaks 2023-10-10 06:13:55 +01:00
Johan Malm
c827c4c9e5 menu: split parse_xml() in readiness for pipemenus 2023-10-10 06:13:55 +01:00
Consolatis
1703b4d6cc src/menu/menu.c: support keyboard driven selection
Fixes: #1058
Requested-by: @stefonarch
2023-09-05 19:57:14 +01:00
Consolatis
a9ab8ebdaf src/menu/menu.c: convert to wl_list_append() 2023-09-05 19:57:14 +01:00
Consolatis
65b441a0ba config: validate keybind, mousebind and menu actions 2023-07-05 22:20:18 +02:00
Johan Malm
49dfba1507 menu: support CDATA for <command> element
...in order to support obmenu-generator output such as this:

  <menu id="root-menu" label="Applications">
    <item label="File Manager"><action name="Execute"><command><![CDATA[xdg-open .]]></command></action></item>
    <item label="Terminal"><action name="Execute"><command><![CDATA[xterm]]></command></action></item>
    <item label="Web Browser"><action name="Execute"><command><![CDATA[xdg-open http://]]></command></action></item>
    <item label="Run command"><action name="Execute"><command><![CDATA[gmrun]]></command></action></item>
  </menu>

References:
- https://github.com/trizen/obmenu-generator
- https://aur.archlinux.org/packages/obmenu-generator
- https://trizenx.blogspot.com/2012/02/obmenu-generator.html

Fixes: issue #972
2023-07-04 06:01:47 +01:00
Johan Malm
4a31972b6f menu: print menu.xml nodenames
...when LABWC_DEBUG_MENU_NODENAMES is set
2023-07-04 06:01:47 +01:00
Johan Malm
33b98b19aa action: support SendToDesktop 'follow' option
Make follow 'true' by default as per Openbox 3.6 specification.
Note: this is an interface change.

Fixes: issue #841
2023-03-26 19:52:50 +02:00
John Lindgren
3941991505 menu: Compute usable area for the correct output
If a menu was opened via keybind while the cursor was on another,
differently-sized output, the wrong usable area was used to
position the menu.
2023-02-09 00:33:56 -05:00
Consolatis
4a8b50603e src/config/rcxml.c: allow clearing key/mouse bindings
Fixes #567
2023-02-03 03:30:10 +01:00
Johan Malm
241e7de2b1 menu: minor refactoring to increase readability 2023-01-01 18:59:16 +00:00
Consolatis
7cc80b7a99 src/action.c: Provide generic parsing of XML action arguments
.. and use it within src/config/rcxml.c and src/menu/menu.c.

This fixes being unable to use the `direction` argument in menu entries.

Reported-by: mahk via IRC
2022-12-10 19:55:53 +00:00
Consolatis
d00327bc32 menu: Dynamically adjust menu width based on widest item
Adds two new theme vars:
- menu.width.min (menu will never be smaller than this)
- menu.width.max (menu will never be wider than this + padding)

A fixed menu width can be achieved by setting
menu.width.min == menu.width.max.
2022-12-06 21:08:43 +00:00
Consolatis
f0666ba5c9 menu: Convert hardcoded item padding to theme vars
Adds two new theme vars:
- menu.items.padding.x
- menu.items.padding.y
2022-12-06 21:08:43 +00:00
Consolatis
3da7cfd8c6 theme: Rename separator_width to separator_line_thickness 2022-12-06 21:08:43 +00:00
Consolatis
ccf68c5950 menu: Add generic menu_init() entry point 2022-12-06 21:08:43 +00:00
Johan Malm
e45e2c7e60 Fix coding style 2022-11-03 23:01:52 +01:00
Consolatis
ec8bc6e2d6 src/menu/menu.c: Add comments 2022-11-01 17:54:02 +01:00
Consolatis
89ad0b808f s/wl_list_insert(list.prev...)/wl_list_append(list...)/ 2022-10-05 19:50:36 +01:00
Consolatis
dcedfee5d1 src/menu.c: Clamp separator width
Reported-by: @Flrian
2022-09-20 21:06:31 +01:00
John Lindgren
a54d378e6c common: Add znew/znew_n() macros 2022-09-18 15:25:19 -04:00
John Lindgren
cb40cdc36c common: Add additional memory utilities (xzalloc() etc.) 2022-09-17 10:57:30 -04:00
John Lindgren
07a83c19f0 config: Add support for font slant and weight 2022-09-15 21:48:05 +01:00
Johan Malm
429df42a8f menu: render submenu arrows 2022-08-12 11:16:17 +02:00
Johan Malm
70421b1207 menu: do not require label attribute for highest level menu definition
Allow highest level menu definitions - typically used for root-menu and
client-menu - to be defined like this:

    <openbox_menu>
      <menu id="">
      </menu>
    </openbox>

Previously this required a label attribute (which was not used for
anything and could be an empty string) as show below:

    <openbox_menu>
      <menu id="" label="">
      </menu>
    </openbox>

Closes issue #472
2022-08-11 20:59:57 +01:00