Commit graph

155 commits

Author SHA1 Message Date
John Lindgren
e1475a1e47 include: reduce global includes in labwc.h 2025-07-30 21:04:31 +01:00
John Lindgren
e21fc065c4 include: split output.h from labwc.h 2025-07-30 21:04:31 +01:00
John Lindgren
9782ffa868 desktop: give focus to a modal dialog rather than its parent
Fixes: #2722
2025-06-13 18:40:29 +01:00
John Lindgren
8fb2ecefcb xwayland: always offer focus in Globally Active case
In 9e3785f8cd, a heuristic was added to assume that NORMAL and DIALOG
window types were always focusable. (This was before we had the "offer
focus" mechanism in place.)

However, we should still call wlr_xwayland_surface_offer_focus() for
these views, in case they actually don't want focus. (This is uncommon
but has recently been seen with WeChat popups, which have both NORMAL
and UTILITY type.)

To make this possible, refine view_wants_focus() to return either
LIKELY or UNLIKELY for Globally Active input windows. This decouples
the question of "should we try to focus this view" from the actual
mechanism used to do so.
2025-06-10 11:03:54 -04:00
John Lindgren
a3d6226728 treewide: remove empty statements in switch cases
For longer cases, factor out the logic to new functions.
For very short cases, just move the declaration before the switch.

v2: in one case, replace the switch with if/else.
2025-05-22 22:52:43 +01:00
John Lindgren
c00baa1651 xwayland: use wlr_xwayland_surface_offer_focus()
Offer focus by sending WM_TAKE_FOCUS to a client window supporting it.
The client may accept or ignore the offer. If it accepts, the surface will
emit a focus_in signal notifying the compositor that it has received focus.
The compositor should then call wlr_xwayland_surface_activate(surface, true).

This is a more compatible method of giving focus to windows using the
Globally Active input model (see wlr_xwayland_icccm_input_model()) than
calling wlr_xwayland_surface_activate() unconditionally, since there is no
reliable way to know in advance whether these windows want to be focused.

v2: add caution not to use view_offer_focus() directly
v3: remove obsolete comment
2025-05-21 20:30:19 +02:00
Consolatis
a617accfd8 chase wlroots: _wants_focus and input_model renames MR 2434
Ref: d3b7e040af46ab03114d5a40e9ed0c7c6aff15be
("wlr_xwayland_surface: fix prefix of two functions")
2025-05-21 06:36:08 +01:00
tokyo4j
270b45da88 desktop: harden window stacking order while window switching
This commit moves the check against server->input_mode from the callers
of desktop_focus_view() into desktop_focus_view() itself. This
eliminates code duplications and makes it harder to mess up the window
stacking order while window switching.

I also added the same check in view_minimize() so that minimize requests
from panels never messes up the window stacking order (I think only this
should be described in the release note).
2025-03-09 20:41:26 +00:00
tokyo4j
950337b895 ssd: fix resizing on border corners and add <resize><cornerRange>
Eliminate corner extents and instead use cursor position to map SSD
borders and extents to corner contexts, with a size configurable by the
<resize><cornerRange> parameter. This simplifies extent handling,
eliminates bugs in the detection of corner context, and allows users to
expand corner targets if they wish.

Co-authored-by: Andrew J. Hesford <ajh@sideband.org>
2025-02-04 11:13:32 -05:00
tinyboxvk
1a6dd845a2 Fix typos
Signed-off-by: tinyboxvk <13696594+tinyboxvk@users.noreply.github.com>
2025-01-09 06:59:57 +00:00
tokyo4j
a98b535362 osd: make desktop_cycle_view() private in osd.c 2024-12-30 18:07:45 +09:00
tokyo4j
1e0a7e2562 src/desktop.c: remove osd_review_restore() call in desktop_cycle_view()
It was a cruft from days when we used to walk scene-nodes to get the next
view to cycle.
2024-12-30 18:07:45 +09:00
tokyo4j
9a3412324d node: add node_scaled_scene_buffer_from_node 2024-12-23 18:11:32 +09:00
Johan Malm
d18e67eea8
Merge pull request #2030 from Consolatis/wip/cosmic_workspaces
Initial implementation of cosmic-workspace-unstable-v1
2024-10-01 21:31:04 +01:00
Orfeas
dda47a5e14 action: make "FocusOutput" behave like "MoveToOutput" 2024-08-24 14:59:42 -04:00
Consolatis
d9866aafa5 workspaces: slight struct reordering 2024-08-02 19:35:36 +02:00
tokyo4j
d00711bc45 session-lock: allow client to update cursor shape 2024-05-31 11:21:29 +09:00
tokyo4j
1c8d347a61 desktop: show/hide top layer more smartly
Before this commit, `top` layers were hidden whenever there is a
fullscreen window in the corresponding output.

With this commit, `top` layers are hidden only when there is a fullscreen
window without other windows above it in the corresponding output.

A caveat is that `bottom` layer is still always hidden by a fullscreen
window.
2024-05-14 15:57:27 +02:00
Franz Berger
097ac44eda view: fix top-layer not showing when there's a minimized full-screen view 2024-05-08 21:33:49 +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
tokyo4j
b6d576922b IME: support IME popup 2024-03-14 20:11:03 +00:00
Johan Malm
a5fcbfaf72 cursor: process layer subsurfaces in cursor_button_press()
...to give keyboard focus to layer-shell clients if exclusive or on-demand
interactivity is set, so that menu popups can be navigated with the
keyboard. This still only works if the client is in top (or overlay)
layers. Support for bottom and background to be done as a separate patch
set.

Revert 06b19f0 to process layer-shell subsurfaces in
`cursor_button_press()`, but only when their parent layer-shell surface
has keyboard interactivity.

Fix bug in `get_cursor_context()` which resulted in layer-surfaces not
being detected correctly.

Background:

Commit 06b19f0 (issue #1131) disabled processing of layer-shell
subsurfaces in cursor_button_press() because when pressing a task in
Waybar (Gtk panel using layer-shell subsurfaces) the foreign-toplevel
minimize-raise action did not work correctly as the action logic relied on
the recipient window being activated and by clicking on the panel, the
panel itself was both surface-focusd and activated (and thus the window
de-activated).

The un-intended consequence was that by not responding to layer-subsurface
cursor buttons presses, layer-shell clients (such as panels) were not
given keyboard focus if they indeed wanted it by setting exclusive or
on-demand keyboard interactivity.

The good news is that that following @jlindgren90's refactoring (various)
the only place where we call `view_set_actived()` is in
`focus_change_notify()` in `seat.c` and we now only do it for views
(bb8f0bc).

Another side-effect (positive) of 06b19f0 was that a Waybar dnd bug was
fixed (pointer-serial-number validation failure).

Have tested with sfwbar, waybar and tint (test-panel) the following
results:
- Minimize-raise works even when on-demand keyboard interactivity is set
- Keyboard interactivity is given popup-menus (sfwbar and tint) when the
  panels are in the top layer (support for bottom will be as a separate
  patch set)
- Waybar dnd still works (even when hard-coding keyboard-interactivity)

References:
- bb8f0bc960
- 40ce95a68c/src/seat.c (L481-L483)
- 40ce95a68c/src/dnd.c (L24)
- https://github.com/johanmalm/tint

Fixes: #1572
2024-03-09 00:44:19 +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
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
777e6bb868 desktop: refactor desktop_cycle_view()
...in preparation for using common window-rule criteria with osd.c

No functional change intended.

Related-to #1454
2024-03-05 22:16:55 +01:00
John Lindgren
11cdad0c11 Revert "desktop: allow re-focus between "globally active" views of the same PID"
This is undesired when a focusable popup (e.g. applications menu) of an
unfocusable view (e.g. XWayland panel) is closed.

This reverts commit f6e3527767.
2024-03-05 20:51:32 +00:00
Consolatis
e0c3635282 src/desktop.c: reduce OSD log spam on hover 2024-02-02 21:36:20 +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
3a959cc74b s/focused_view/active_view/ 2023-12-19 20:34:07 +00:00
John Lindgren
b5220a723e Chase wlroots: convert to try_from
Chases: 711a1a3ed42150fdbc716e80719d482006075f69
xdg-shell: convert to try_from

Chases: f9bd416d4156942ce3951a6c5cf9f81a3cf4a3dd
layer-shell-v1: convert to try_from

Chases: fbf5982e3838ee28b5345e98832f6956c402b225
xwayland/xwm: introduce wlr_xwayland_surface_try_from_wlr_surface()
2023-11-27 21:01:53 +00:00
Consolatis
13d0b14244 Update top layer visiblity on workspace switch
Fixes: #1158
2023-11-12 17:39:00 +00:00
John Lindgren
c5437b1153 cursor: allow re-focusing xwayland-unmanaged surfaces
We already allow some xwayland-unmanaged surfaces to take focus on map,
if indicated by wlr_xwayland_or_surface_wants_focus(). But once these
surfaces lose focus, they never regain it again.

Add desktop_focus_view_or_surface() and call it in the appropriate
places to allow these views to regain focus in the usual ways (e.g.
clicking on them or focus-follows-mouse).
2023-11-02 19:31:10 +00:00
John Lindgren
f6e3527767 desktop: allow re-focus between "globally active" views of the same PID
Commit 7e72bf975f changed behavior to not automatically focus xwayland
views using the "Globally Active" input model (WM_HINTS.inputs = false
but WM_TAKE_FOCUS listed in WM_PROTOCOLS).

One undesired side effect of this change is that when a dialog is
closed, the parent window is not re-focused if "Globally Active". This
issue is seen for example with JDownloader. It can be solved taking a
similar approach to what is done for unmanaged xwayland views: allow
automatic re-focus between views sharing the same PID.

Note that it's difficult to completely solve all of the focus issues
with Globally Active views without proper WM_TAKE_FOCUS support.
Implementing proper support is difficult since it requires wlroots
changes and would also mean waiting for a message round-trip in
desktop_focus_topmost_view().

Fixes (partially): 7e72bf975f
("view/xwayland: avoid focusing views that don't want focus")
2023-10-16 20:28:18 +01:00
John Lindgren
8bb2e2123f seat: move session-lock check down to seat_focus() level
We were checking for a locked session in desktop_focus_view(), but there
are several other call sites of seat_focus_surface() which were missing
such a check. Any one of those could cause the lock screen to lose focus
(making the session impossible to unlock) or another surface to gain it
(breaching the session lock).

To fix the issue, make any call to seat_focus_surface() no-op when the
session is locked. Add a specific seat_focus_lock_surface() function
which is the only way to bypass the check and is called only from
session-lock.c.
2023-10-15 21:32:41 +01:00
Consolatis
4174553124 desktop.c: prevent switching workspaces for always-on-bottom windows
Fixes: #1170

Reported-by: @stefonarch
Reported-by: @tsujan
2023-10-15 01:05:45 +02: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
John Lindgren
b7bd5a52e4 desktop: add commentary clarifying focus rules 2023-10-04 10:28:39 -04:00
John Lindgren
9be6bd8b1d Revert "desktop: try harder to avoid focusing unfocusable views"
Some X11 applications (MATLAB is known to be one) apparently still use
the outdated "globally active" input focus model, in which they declare
they don't want the window manager to give them input focus, but expect
to be able to take it explicitly themselves via XSetInputFocus().

Such applications are not a good fit for the Wayland world, and may have
issues even with remotely modern X11 window managers that prevent such
"focus stealing". Labwc certainly doesn't (and won't) allow it. However,
to avoid breaking such applications entirely, let's still allow the user
to give focus by clicking in the window.

For the sake of applications that legitimately don't want to be given
input focus (such as taskbars or other "panels"), we still don't give
focus to them automatically when another view is closed, and they aren't
shown in Alt-Tab.

This reverts commit cae96b0cce.
2023-10-04 10:28:39 -04:00
John Lindgren
cae96b0cce desktop: try harder to avoid focusing unfocusable views
Make desktop_focus_view() do nothing if the view is not focusable.
2023-09-29 18:04:32 +01:00
John Lindgren
7e72bf975f view/xwayland: avoid focusing views that don't want focus
XWayland views can self-declare that they don't want keyboard focus via
the ICCCM WM_HINTS property. Most of the logic is already in place to
avoid giving focus to such views (e.g. taskbars).

Add a couple of missing pieces to make this work:

- Hook up view_isfocusable() to look at WM_HINTS for XWayland views
- Adjust desktop_focus_topmost_mapped_view() to skip unfocusable views
2023-09-29 18:04:32 +01:00
John Lindgren
4028a9482f seat: use focus_change event to update focused/active view
- Connect to wlr_seat_keyboard_state's focus_change event.
- Add view_from_wlr_surface(), which does what the name says.
- Use focus_change event along with view_from_wlr_surface() to update
  server->focused_view and set SSD states via view_set_activated().
- Eliminate desktop_focused_view() since server->focused_view should be
  reliably up-to-date now.
- Eliminate view_focus/defocus() since we can now just call
  seat_focus_surface() directly.
2023-09-28 22:52:30 +01:00
John Lindgren
e5aef03319 desktop: switch workspaces and optionally raise in desktop_focus_view()
Make desktop_focus_view() always switch to the workspace containing the
view being focused. It doesn't make much sense for an invisible view to
have the keyboard focus.

Also add an optional "raise" parameter to desktop_focus_view(). This
allows the common pattern of desktop_focus_view() + view_move_to_front()
to be reduced to a single function call.
2023-09-28 03:38:51 +02:00
John Lindgren
3022985ba7 view: try to reduce confusion in focused_view tracking
Our current approach to handling the focused/active view is a bit
confusing. In particular, it's hard to be sure when server->focused_view
is or isn't in sync with the real wlroots keyboard focus.

Try to clean things up a bit. In particular:

- Add comments to server->focused_view and desktop_focused_view() to
  clarify that they should match, but it's not guaranteed.

- desktop_focused_view() now prints a warning if it detects that
  server->focused_view is out of sync. We should keep an eye out for
  this warning, and if we see it, try to figure out why it happened.

- For consistency, use only "focus/defocus" as the verbs in function
  names rather than "activate". This is a bit arbitrary, but the idea is
  that focus is the primary action while the active/inactive state is a
  side effect.

- view_focus/defocus() replace view_set_activated() and now update both
  focus and active/inactive state, to try to keep them in sync.

- Add comments at view_focus/defocus() to warn against calling them
  directly (we should generally call the desktop.c functions).

- desktop_focus_view(NULL) is now forbidden and is no longer handled as
  a special case to clear the focus. This was (at least to me) a
  surprising behavior and caused trouble when working on another change.

- To maintain existing behavior, desktop_focus_topmost_mapped_view() now
  explicitly clears the focus if there are no mapped views.

There should be no behavioral change here.
2023-09-27 17:13:08 +01:00
Johan Malm
e5a6c57a6e Move isfocusable() from desktop.c to view.c 2023-08-20 17:00:23 +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
a89bcc3c60 cursor: prevent press on layer-subsurface from cancelling popup grab
Fixes: #1030
2023-08-15 20:25:58 +01:00
Johan Malm
a6f0fc9c62 window-rules: add skipTaskbar and skipWindowSwitcher 2023-05-22 20:37:49 +01:00
Johan Malm
5744bba849 xwayland: validate PID before activating unmanaged surface
Check that an unmanaged surface trying to grab focus is actually a child
of the topmost mapped view.
2023-04-21 15:59:36 +01:00
Johan Malm
d4288415c9 Support ext-session-lock protocol 2023-04-02 23:09:38 +01:00