Commit graph

118 commits

Author SHA1 Message Date
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
John Lindgren
d7dd366bad view: Add view_move_to_front/back().
This avoids calling view->impl functions from cursor.c and desktop.c.

v2: Add an explicit recursion guard in cursor_update_focus().
2023-04-01 22:50:01 +02:00
Johan Malm
a6896e6978 desktop: move scene-tree node in move-to-back
view_minimize() does not need to call desktop_move_to_back() because the
stacking order is not changed and the windowSwitcher uses the scene-tree
nodes anyway.

Note: Movement of xwayland sub-views still relies on keeping server->views
in sync with z-order
2023-03-26 20:22:57 +01:00
Consolatis
a0b5a80ce1 Add FocusOutput action
Fixes #806

Suggested-by: @EysseW
Tested-by: @EysseW
2023-03-06 21:58:11 +00:00
Johan Malm
b8ec5a3e2e view: add move_to_front to struct view_impl
...to increase xwayland and xdg-shell encapsulation and to avoid passing a
function pointer as an argument in `xwayland_move_sub_views_to_front()`
which is inconsistent with labwc design patterns.

Rename view-impl.c to view-impl-common.c

Move function declarations that are common to view-implementations from
view.h into view-impl-common.h
2023-02-24 20:42:01 +00:00
John Lindgren
859eba1c6b desktop: Avoid centering views without initial geometry 2023-02-15 18:59:26 +00:00
Johan Malm
6f3043b08d layer: improve keyboard-interactivity
- Process layer-shell keyboard interactivity in the map and commit
  handlers only, rather than in layers_arrange(). This allows handling of
  the layer-surface that emitted the event rather than iterating over all
  surfaces in the output layer-tree, and therefore avoids having to guess
  which surface should have keyboard preference (and it might not be the
  last one added to the list which was the assumption previously).

- Prevent seat_focus_surface() from setting keyboard focus if a layer-shell
  surface with exclusive keyboard-interactivity has the focus.

- Set cursor_context type for layer-surfaces without node-descriptors
  in order to set keyboard focus correctly in cursor_button_press().

Tested satisfactorily with xfce4-panel and gtk-layer-demo.

Fixes #725 and #704
2023-01-29 14:31:49 +00:00
Consolatis
7e99d8ba08 SnapToRegion: Add overlay while moving and pressing a modifier 2023-01-11 18:52:24 +01:00
John Lindgren
45e0a4f48c xwayland: Add xwayland.h and move more things to xwayland.c
- Move xwayland-specific struct definitions to new xwayland.h header
- Move xwayland_move_sub_views_to_front() from desktop.c to xwayland.c
- Split out xwayland_server_init/finish() from server_init/finish()
- Rename new_xwayland_surface -> xwayland_new_surface and
  xwayland_surface_new() -> handle_new_surface() for consistency
- Add "mapped" argument to xwayland_unmanaged_create() so that we can
  make unmanaged_handle_map() private to xwayland-unmanaged.c
2023-01-07 22:22:55 -05:00
Johan Malm
86fa0c0a65 desktop.c: handle layer-subsurfaces in get_cursor_context()
...to allow these surfaces to receive pointer button events

Test by running `gtk-layer-demo --keyboard exclusive`, then open the
'set margin' dialog and try setting the margin with the pointer.
2022-12-29 23:18:08 +01:00
Johan Malm
9dbac2e06f layer: use scene-graph API more fully
...and thus simplify the usage of wlr_scene_node_at(). Specifically:

- desktop.c: in get_cursor_context() use node-description for
  layer-surfaces and layer-popups. This lays the foundations for a
  pointer-enter-event being sent when a new layer-surfaces appears under
  the pointer (even if the pointer doesn not move).

- layers.c:

  * Iterate over `struct wlr_scene_tree *layer_tree[]` rather than
    `struct wl_list layers[]` when arranging layers to avoid surfaces
    being out of sync with nodes

  * Set signal handlers after scene node creation to avoid configure
    race conditions

  * Handle scene-node destroy event rather than event of
    `struct wlr_layer_surface_v1`

  * Arrange layers on map and unmap

  * Handle client request for layer-change

Fixes issue #667
2022-12-29 23:18:08 +01:00
John Lindgren
b67eccc99a ssd: Move implementation details from ssd.h to ssd-internal.h
- Move private structs and functions to `ssd-internal.h`
- Add `ssd_button_get_type()` and `ssd_button_get_view()`
2022-11-27 15:09:45 +00:00
John Lindgren
1e8b0414fe ssd: Allocate struct ssd and struct ssd_hover_state separately
- Store a pointer to the `struct view` in `struct ssd`
- Pass `struct ssd *` instead of `struct view *` to ssd functions
- Add `ssd_get_margin()` convenience function
2022-11-27 06:48:41 +00:00
John Lindgren
957d9e5926 ssd: Cosmetic cleanups
- Minimize includes in `ssd.h`
- Avoid repetitive `view->ssd.margin` pattern
- Use `struct ssd *` or `const struct ssd *` rather than `struct view *`
  where convenient

Part of the motivation is to make it easier to separate `struct ssd`
from `struct view` in a future commit.
2022-11-26 21:24:46 +00: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
Johan Malm
e45e2c7e60 Fix coding style 2022-11-03 23:01:52 +01:00
Consolatis
deb658b672 cursor: Restore drag icon after the move to scene-graph
Also move everything DnD related to src/dnd.c
2022-10-17 21:22:12 +01:00
Consolatis
89ad0b808f s/wl_list_insert(list.prev...)/wl_list_append(list...)/ 2022-10-05 19:50:36 +01: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
429c388333 cursor: Add struct cursor_context and clean up code
v2:
 - Add surface to cursor_context, rename c -> ctx
 - Factor out determine_resize_edges()
2022-09-15 03:12:38 +02:00
John Lindgren
6c6e406507 cursor: Factor out cursor_update_common() and fix some glitches
Fix a couple of glitches seen when exiting interactive move/resize:

 - Cursor briefly set to left_ptr rather than the correct cursor image
 - Cursor not updated if the view being moved/resized is destroyed

Also make sure to exit interactive mode if the view is going fullscreen
(labwc gets very confused otherwise).

Code changes in detail:

 - Factor out set_server_cursor() which will set the correct cursor
   image for non-client areas (either XCURSOR_DEFAULT or one of the
   resize cursors).
 - Unify the logic from cursor_rebase() and process_cursor_motion by
   factoring out cursor_update_common().  This corrects some logic
   discrepancies between the two, which should be a good thing(TM).
 - Remove the extra cursor_set(XCURSOR_DEFAULT) from interactive_end()
   and instead rely on cursor_update_focus() to do the right thing.
 - Simplify cursor_button() by just calling interactive_end() when we
   want to exit interactive mode.
 - Call cursor_update_focus() from view_destroy() if the view had mouse
   focus or was being interactively moved/resized.

v2: Eliminate force_reenter parameters and figure out automatically
    when we need to re-enter the surface.
v3: Rename wlseat -> wlr_seat.
v4: Simplify client/server cursor logic.
2022-09-13 13:29:36 -04:00
Consolatis
c0f0e0c46e cursor: Allow re-enter for cursor_update_focus()
This allows forcing an application to re-set their desired cursor image.
2022-09-11 13:24:27 +01:00
John Lindgren
79d9cfcda6 desktop: Cycle first to topmost view if not already focused
The topmost view may not always be the focused view; for example,
when Audacious's main window is focused but the floating Search
Tool window remains on top of it.  In that case the floating window
(not the main window) should be the first view selected in the
window switcher.
2022-09-07 00:27:03 +02:00
Consolatis
15a5b710db alt-tab preview: restore functionality after move to scene-graph 2022-08-28 20:40:36 +02:00
John Lindgren
b7c4ba825a view/ssd: Refactor and fix visual indication for active windows
Partially fixes #494.

Co-Authored-by: Consolatis
2022-08-27 06:58:20 +01:00
Consolatis
f4aa6118e9 src/layers.c: Adjust views based on usable_area changes 2022-06-30 20:41:54 +01:00
Consolatis
8c5157a098 workspaces: Wire up workspaces 2022-06-15 22:26:21 +02:00
Consolatis
ca9226a7a6 src/ssd: Convert button node descriptors to struct ssd_button
This allows for way easier button hover detection and future
features like toggling rounded corner buttons on maximize.
2022-06-09 22:04:35 +01:00
Consolatis
f1ada7e407 src/ssd: Use LAB_SSD_PART_CORNER_x for rounded corner backgrounds
This matches the behavior of the surrounding borders and will usually
cause resizing instead of triggering the button itself. This effect
is only really visible when using a border width settings of > 1.

Fixes #379
2022-06-09 22:04:35 +01:00
Consolatis
2ed7a10779 Chase wlroots: every scene_node parent is now a tree
Chases wlroots ccd0f85c2a36308e35b153c7f9653abac7659af3
wlr_scene: Only allow parenting on a wlr_scene_tree
2022-06-07 07:13:37 +01:00
Consolatis
3f65a2ff77 Chase wlroots: wlr_scene is now a tree node
Chases wlroots 9eb71146ae56c509ee33c7e8a662549592aad870
wlr_scene: Refactor wlr_scene (the root element) to encase a wlr_scene_tree
2022-06-07 07:13:37 +01:00
Consolatis
163179dda1 Chase wlroots: wlr_scene_surface
To update the wlroots subproject use
meson subprojects update wlroots
2022-05-26 06:48:00 +01:00
Consolatis
3699a2a7f6 desktop_node_and_view_at(): handle layer surfaces
+ Replace some tabs with spaces in include/node.h

Fixes: #278
2022-05-25 21:48:28 +01:00
Johan Malm
48c9e6fda0 osd: show alt-tab switcher center-aligned on all outputs
Fixes issue #283
2022-04-20 17:45:10 +01:00
Johan Malm
97846ae45b cursor: add cursor_update_focus()
...and call it from desktop_move_to_front() in order force an enter event
on the surface below the cursor when cycling views.

Fixes #162 and #225
Inspired by PR #164 - just restructured it a bit.

Suggested-by: @bi4k8
Co-authored-by: Consolatis <35009135+Consolatis@users.noreply.github.com>
2022-03-21 17:57:20 +00:00