Commit graph

86 commits

Author SHA1 Message Date
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
Consolatis
343918dee0 treewide: properly clear the buffer
Before this patch, the OSD would repeat the last buffer
content in case the new buffer content would be empty.

This was mostly happening for the `title` OSD field that is intended
to be empty when it matches the app_id / WM_CLASS of the application.
Due to only buffer.len being reset but its internal allocations being
untouched, buffer.buf would still carry the old data.

This patch fixes it by also overwriting the first byte in the buffer
allocation with '\0' via the new `buf_clear()` function.

Do the same for buf_expand_shell_variables() although that one should
have been fine before as it always writes new data to the buffer.
2024-04-18 07:00:23 +01:00
tokyo4j
8096df19ba osd: add theme settings for window-switcher preview
Adds theme settings like:
osd.window-switcher.preview.border.width: 2
osd.window-switcher.preview.border.color: #ffffff,#00a2ff,#ffffff
2024-04-16 09:58:34 +02:00
droc12345
d672765ea7
osd: add window-switcher custom field (#1670)
Add custom field with subset of printf style formatting
to replace the original field formats.

Example:

    <windowSwitcher preview="no" outlines="no" allWorkspaces="yes">
      <fields>
        <field content="custom" format="foobar %b %3s %-10o %-20W %-10i%t" width="100%" />
      </fields>
    </windowSwitcher>

Mono space font recommended. May need OSD width adjusted

Co-authored-by: @Consolatis (based on work done by them)
2024-04-10 23:39:31 +01:00
Droc
eb5e855b69 osd: support percent values for window switcher width
Add ability to set width with percentage of monitor instead of just pixels.
With this the OSD sizes itself properly on both my 4k and 2k monitors.

example: 50% or 75% instead of 600, max 100%
2024-04-08 15:44:53 +02:00
droc12345
b0c2ac1a6d
osd: add window-switcher field content types (#1623)
...`workspace`, `state`, `type_short` and `output`.

Example usage:

    <windowSwitcher allWorkspaces="yes">
      <fields>
        <field content="workspace" width="5%" />
        <field content="state" width="3%" />
        <field content="type_short" width="3%" />
        <field content="output" width="9%" />
        <field content="identifier" width="30%" />
        <field content="title" width="50%" />
      </fields>
    </windowSwitcher>
2024-03-16 15:28:37 +00:00
Johan Malm
4d68ee424a osd: show preview for windows on other workspaces
Written-by: @Consolatis
2024-03-05 22:16:55 +01:00
Johan Malm
72a41058af osd: only call wl_array_{init,relesase} once 2024-03-05 22:16:55 +01:00
Johan Malm
247d2b581c osd: optionally show windows on all workspaces
Also share common config option (rc.window_switcher.criteria) in osd.c and
desktop.c to make sure the window lists are always consistent.

Configure with `<windowSwitcher allWorkspaces="yes|no">`
2024-03-05 22:16:55 +01:00
Johan Malm
41419d9479 osd: do not use server->workspace_current->tree
...as it is no longer needed following the use of shared infrastructure
between osd.c and desktop.c introduced in the last few commits.
2024-03-05 22:16:55 +01:00
Johan Malm
79bca44cb1 window-rules: add root-toplevel critiera 2024-03-05 22:16:55 +01:00
Johan Malm
c71fccbcec osd: include always-on-top views in window-switcher 2024-03-05 22:16:55 +01:00
Johan Malm
4b6239ee0c osd: refactor to eliminate usage of g_strcmp0()
...to allow inclusion of ./scripts/find-banned in CI

No functional change intended.
2023-12-28 20:41:49 +01:00
kyak
d2d469133f
osd: support full app_id in window switcher (#1309)
Support showing full application
identifier or the trimmed variant in window switcher OSD.

Regression notice: For anyone using ‘identifier’ in window-switcher field configuration, change it to ‘trimmed_identifier’.
2023-12-27 10:55:49 +00:00
John Lindgren
1f541be481 view: fix some inconsistencies in view_ functions
... especially regarding whether a (view *) parameter may be NULL. It's
confusing when some functions accept NULL and others don't, and could
trip someone up.

I'm partly to blame for the inconsistency, since (if memory serves) I
added view_is_tiled() and view_is_floating(), which do accept NULL.

In detail:

- Make view_is_tiled() and view_is_floating() no longer accept NULL.

- Rename view_isfocusable -> view_is_focusable for consistency with
  other view_is_ functions.

- Eliminate view_inhibits_keybinds() as it only existed to safely accept
  NULL and check a single flag, which can be checked directly.

- Add assert(view) to remaining public view_ functions to catch
  accidentally passing NULL.

- Inline inhibit_keybinds() into view_toggle_keybinds(). It is closely
  related and not called from anywhere else; inlining it allows
  eliminating an extra assert() which is now impossible.
2023-10-09 20:34:13 +01:00
Consolatis
a3a5d9a21b src/osd.c: prevent crash with theme setting osd.window-switcher.width: 0
Fixes: #1050
Reported-by: @4ffy (thanks)
2023-08-27 21:25:32 +02:00
Johan Malm
206db43786 config: s/app_id/identifier/ for window-switcher field
...to be consistent with window rules.

The use of 'app_id' for window-switcher fields is hereby deprecated.
2023-08-20 20:49:27 +01:00
Johan Malm
e5a6c57a6e Move isfocusable() from desktop.c to view.c 2023-08-20 17:00:23 +01:00
Johan Malm
602d59a3b2 Add common/array.h with wl_array_len() 2023-08-20 13:08:45 +02:00
Johan Malm
a9e123393c osd: refactor to remove get_osd_height() 2023-08-20 09:56:49 +01:00
Johan Malm
f2479090a2 osd: simplify to only use one view-array 2023-08-20 09:56:49 +01:00
Johan Malm
57b9efeb45 view: add view_array_append()
...to reduce code duplication.

The function populates an array with views which meet any set of critera
from:

  - current-workspace
  - no-always-on-top
  - no-skipWindowSwitcher (window-rule)

Make src/osd.c use this new interface. Note that always-on-top views are
still filtered out from the window-switcher and that desktop_cycle_view()
needs to be re-worked before always-on-top views can be opted in.
2023-08-20 09:56:49 +01:00
Johan Malm
b6dfffc782 osd: move get_osd_height() closer to where it is called from 2023-07-05 21:31:30 +01:00
Johan Malm
2c66fa279f osd: make item-border part of item-height 2023-07-05 21:31:30 +01:00
Consolatis
660127acb0 theme: add option osd.window-switcher.item.active.border.width
...and change default values for the variables below to keep the
window-switcher look the same as it was at the last release.

osd.window-switcher.padding = 4
osd.window-switcher.item.padding.y = 1
osd.window-switcher.item.active.border.width = 2
2023-07-05 21:31:30 +01:00
Johan Malm
55bf79c3fe theme: add option osd.window-switcher.padding
Fixes: issue #969
2023-07-05 21:31:30 +01:00
Johan Malm
b200dd2e7b osd: use theme->osd_border_width for focused item 2023-06-29 19:14:08 +01:00
Johan Malm
df53c28a0f theme: add window-switcher width/padding
...and calculate item-height based on font-height

Add theme options
  - osd.window-switcher.width
  - osd.window-switcher.item.padding.x
  - osd.window-switcher.item.padding.y

Issue #879
2023-06-29 19:14:08 +01:00
Johan Malm
11ff820105 osd: use theme->osd_border_width consistently 2023-06-29 19:14:08 +01:00
Johan Malm
a6f0fc9c62 window-rules: add skipTaskbar and skipWindowSwitcher 2023-05-22 20:37:49 +01:00
Johan Malm
09c1cdd2dc osd: set field width to ellipsize 2023-04-24 04:25:52 +02:00
Johan Malm
693c5bd937 config: move cycle_* bools to window_switcher struct 2023-04-21 16:05:48 +01:00
Johan Malm
0f37c04df0 config: support window switcher field definitions
<windowSwitcher>
  <fields>
    <field content="type" width="25%" />
    <field content="app_id" width="25%" />
    <field content="title" width="50%" />
  </fields>
</windowSwitcher>

Relates to issues #852 #855 #879
2023-04-21 16:05:48 +01:00
Consolatis
e45fe0804d followMouse: allow focus switching via A-Tab
Fixes a regression caused by the recent enhancement of followMouse behavior.

Fixes: #849
Reported-by: mitigate via IRC
2023-03-26 20:02:04 +01:00
Flrian
00ebcdc290 osd: add config option to disable osd 2023-03-08 21:54:47 +00:00
John Lindgren
6efc6a9db4 output: Add output_is_usable() helper 2023-02-17 06:59:39 -05:00
Consolatis
7e99d8ba08 SnapToRegion: Add overlay while moving and pressing a modifier 2023-01-11 18:52:24 +01:00
bi4k8
ab74d726c6 osd: bookend with calls to cursor_update_focus
this updates the cursor if it is within the OSD area when OSD appears
or disappears
2022-12-14 12:29:16 +01:00
bi4k8
4f0b72c341 osd: factor drawing out of osd_update 2022-12-13 21:41:41 +01:00
John Lindgren
4da37c6532 view: Move xdg_surface + xwayland_surface to derived structs
Add xdg_surface_from_view() + xwayland_surface_from_view() accessors
that assert() the view is of the expected type before returning.

Fix a real bug in xdg.c parent_of() that dereferenced
`view->xdg_surface->toplevel` without first checking `view->type`.

The goal of the new accessors is to catch similar bugs in future.
2022-11-25 22:21:17 +00:00
John Lindgren
f08e931a29 include: Break out view.h from labwc.h
IMHO it encourages better design (by making dependencies more obvious)
to have source file/header file pairs like view.c/view.h, rather than a
monolithic header like labwc.h with everything in it.

I don't think we need to break up all of labwc.h at once, but maybe we
can start pulling it apart bit by bit as it's convenient.

Also:

- Move "struct border" to ssd.h so that view.h can use it without pulling
  in all of labwc.h.
- Add a missing required #include within scaled_font_buffer.h (forward
  declaration of "struct font" is not enough).
2022-11-21 21:42:37 +00:00
Consolatis
92976f30d0 src/osd.c: Ensure destroying views are not used as preview anchors 2022-09-27 17:35:10 +01:00
Consolatis
c83c1beace src/osd.c: Prevent showing invalid windows
This might happen when closing the last
application "to tray" like VLC, Discord or Steam.

Reported-by: @Flrian
2022-09-27 17:35:10 +01:00
Johan Malm
d424514e24 Fix minor coding-style violations
...based on https://github.com/johanmalm/checkpatch.pl
2022-09-22 22:39:44 +01:00
John Lindgren
07a83c19f0 config: Add support for font slant and weight 2022-09-15 21:48:05 +01:00
Consolatis
2550c984f8 Move OSD handler for view destruction to osd.c 2022-08-28 20:40:49 +02:00
Consolatis
ca3c83aafc src/osd.c: Integrate preview outline into OSD state 2022-08-28 20:40:44 +02:00
Consolatis
15a5b710db alt-tab preview: restore functionality after move to scene-graph 2022-08-28 20:40:36 +02:00
Consolatis
296e58079f Prepare OSD for reimplementation of the preview feature 2022-08-28 20:40:29 +02:00