Commit graph

211 commits

Author SHA1 Message Date
John Lindgren
50ceae5fb4 cursor: backport null check from wlroots-0.17 branch
Check that wlr_layer_surface_v1_from_wlr_surface() doesn't return NULL.
This may be unnecessary with wlroots 0.16 (not sure) but doesn't hurt
and reduces the delta to the wlroots-0.17 branch.
2023-10-14 20:01:51 +02:00
Johan Malm
c7c8b373b5 cursor: fix layer subsurface focus bug
...by simply not focusing layer-shell subsurfaces on button press.

This is a temporary patch to fix a regression.

Fixes: issue #1131
2023-10-03 00:03:35 +02: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
8d3b15576b Add ARRAY_SIZE() macro 2023-09-19 22:03:59 +01:00
Consolatis
97ac960fee src/cursor: ensure interactive move/resize ends correctly for CSD clients
Before this patch, when moving a CSD client below a layershell surface -
like a panel that was configured with either the "top" or "overlay"
layers - we'd only send a matching release button event to the client but
not actually end the interactive move operation. That caused the drag to
continue even though the user already released the mouse button.

In comparison, SSD clients were not suffering from the same issue because
the initial mouse "down" event was not attached to any client surface and
thus it would not take the first early return because there was no surface
attached to the release event.

This patch fixes the issue by reordering the conditions where we return
early. It also ensures that when we finish the move, we still send the
release event to CSD clients.

Fixes: #1053
Reported-by: @DynamoFox (thanks)
2023-09-10 16:49:54 +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
3111c57d6f cursor: cancel popup grab on mouse-press outside client itself
...for example on any part of the server side decoration

Supercedes #826 for xdg-shell popups

Helped-by: @Consolatis
2023-08-10 15:33:56 +01:00
Consolatis
7a19184e5e src/cursor.c: end popup grab on desktop click
Fixes #949
2023-08-07 09:59:30 +02:00
Consolatis
40aba9e542 Add support for ext_idle_notify_v1..
..and combine both idle variants into a standalone manager
2023-07-09 08:26:33 +01:00
Consolatis
9a9e20d2b0 followMouse: add followMouseRequiresMovement
This implements the same config option as `underMouse` in Openbox.

Fixes #862
2023-05-06 14:13:20 +01:00
Jean-Luc Mackail
4fc88dca44 src/cursor.c: handle pointer constraint position hint
Now cursor hints are respected once cursor movement occurs
after unlocking the pointer.

Fixes Overwatch 2 failing to center the mouse pointer when
opening the communication wheel in-game.

Fixes #872
2023-04-13 06:01:42 +02: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
Consolatis
e44d565672 src/cursor.c: make sure the cursor is visible after startup
Before this patch, the cursor was invisible after labwc startup
unless manually moved by the user (or being positioned on top
of some some automatically spawned client surface). This patch
sets the cursor from its uninitialized value (LAB_CURSOR_CLIENT)
to the default cursor.
2023-03-29 21:39:11 +01:00
Consolatis
4cd8afa83e src/cursor.c: fix invisible cursor on output loss / restore
Previously, the cursor image was only updated on output loss when the
cursor was on a labwc owned surface. This patch forces a re-enter of a
client surface in the remaining case of cursor being over a non-labwc
surface which causes the client to re-set its own cursor image.

This fixes a regression caused by 4dc99e2f38.
Thanks to @Flrian for finding the root cause of the issue.

Fixes #820

Reported-by: @Flrian
Tested-by: @Flrian
2023-03-29 21:39:11 +01:00
Johan Malm
a8e0248f47 config: support scroll-factor
Fixes: issue #846
2023-03-27 20:30:00 +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
Johan Malm
f5c4651c67 cursor: fix focus.followMouse glitches
Update focus correctly when using `<focus><followMouse>` and (a) the
focused window is closed; and (b) after switching desktops using action
GoToDesktop. Issue #830

Written-by: @Consolatis
Reported-by: @jech
2023-03-23 23:02:29 +01:00
Consolatis
a4fb5b093b Prevent cursor based region-snapping when starting a move with A-Left
When wanting to snap to a region when starting the move
operation with A-Left (or a similar mousebind which includes a
modifier), the modifier - or another one - must be pressed again.

Fixes #761
2023-03-07 20:55:35 +00:00
Consolatis
22ba7f6744 src/cursor.c: add cursor lock confinement 2023-02-24 21:32:25 +00:00
Ph42oN
c25e2c7a7d src/cursor.c: Implement cursor constraints 2023-02-24 21:32:25 +00:00
Consolatis
231d88706a src/cursor.c: explain X11 cursor name fallback 2023-02-12 09:34:37 +00:00
Consolatis
f9882d8dd3 src/cursor.c: cursor names: use absence of "grab" to trigger fallback
This is necessary because wlroots backported a patch containing
cursor name aliases to the 0.16 branch. That internal mapping
does not alias "grab" to "grabbing" because it is not technically
part of the cursor-names spec.

To keep the "grab" cursor working on systems with no cursor theme
available (or in an unusual location) change the trigger for our
internal cursor name aliasing to "grab".

See wlroots commit 1e345c74c3ca5d2575aa975d4d9af87cd0c7ba13
Alias existing cursor defaults to cursor-spec cursor names

for further details.
2023-02-11 13:27:03 +00:00
John Lindgren
b75dbd5b38 view: Use wlr_box for current/pending geometry 2023-02-09 10:44:15 -05:00
Consolatis
82e9e866ec Enable more compiler warnings 2023-02-01 10:42:22 +01:00
Consolatis
1995a33df9 CodeStyle: prevent space in code indents 2023-01-31 21:22:40 +00:00
Consolatis
4dc99e2f38 cursor: update cursor image on scale change 2023-01-26 22:02:13 +00:00
Consolatis
eb5c8cfdad SnapToRegion: Add dynamic overlay
Either uses a half transparent single rect if running
hardware accelerated or uses a solid struct multirect
outline if not.
2023-01-11 18:52:24 +01:00
Consolatis
7e99d8ba08 SnapToRegion: Add overlay while moving and pressing a modifier 2023-01-11 18:52:24 +01: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
Johan Malm
b203758ce1 Fix minor coding style breaches 2022-11-27 04:03:21 +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
John Lindgren
9021020f6e interactive: Refactor natural_geometry/tiled state handling
Currently, snapping to a screen edge and then snapping to maximize
results in both the natural_geometry and tiled state of the view
getting messed up. After unmaximize, the view ends up in a weird
state (tiled location but natural/untiled size).

There are also a couple of sketchy things going on in the code:

- interactive_begin() pokes its own values into view->natural_geometry
  to force view_maximize() to set a particular geometry.

- interactive_end() "fixes" view->natural_geometry after calling
  view_maximize() to save the original geometry from the start of the
  interactive move/resize.

To fix all this:

- Adjust/expand the API of view.c so that the interactive.c can
  avoid this "back door" of overwriting view->natural_geometry
  directly.

- Save the natural geometry and the tiled state of the view in
  interactive_begin() when starting to move the view.  When done,
  interactive_end() will update the tiled state if appropriate but
  *not* overwrite the natural geometry.
2022-11-20 20:45:50 +00:00
Johan Malm
11cfc49b12 cursor: combine two variables relating to frame-context
Mouse bindings, unlike key bindings, are made within contexts which
represent what was clicked/dragged.  The context 'Frame' refers to the
entire window frame including both the window decorations (if any) and the
client window itself. It is typically used for alti + left/right click to
move/resize the window.

'Frame' is a special case in that when a button is bound in this
context, the action will not be forwarded to the client, which is what
we describe with the 'consumed_by_frame_context' variable.
2022-11-15 22:23:14 +00:00
bi4k8
2b753a98b8 Support smooth scroll and horizontal scroll
note that this changes Scroll mousebinds from taking a "button"
attribute to taking a "direction" attribute
2022-11-15 21:57:36 +00:00
John Lindgren
6164ba73ff cursor: Make update_pressed_surface() no-op except during grabs
This matches Weston behavior more closely and fixes Firefox context
menus.
2022-11-15 21:56:48 +01:00
bi4k8
00002d67ea fix typo 2022-11-10 20:32:50 +01:00
Arnaud Vallette d'Osia
97dc681c3b src/cursor.c: Use 'handled' for state of consumed cursor actions 2022-11-06 22:03:50 +01:00
Arnaudv6
063a26ae9d Scroll-Bindings: Add support for mouse wheel bindings 2022-11-06 22:03:50 +01: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
John Lindgren
cd970945f4 cursor: Call wlr_seat_pointer_notify_clear_focus() only if needed
@Consolatis determined that apparently the extra "clear focus"
event confuses the drag source during drag-and-drop.

Fixes drag-and-drop of files into folders within the same Thunar
window.
2022-10-14 21:56:34 +01:00
Consolatis
2c83a5fcb8 cursor: Prevent setting cursor icon on drag
Partly fixes #549
2022-09-21 21:55:28 +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
Consolatis
e30fce6c34 cursor: Use enum for server set cursor names
This mainly prevents having to use strcmp() on every mouse move.
2022-09-16 21:30:40 +01:00
John Lindgren
bbc6c6bb94 action: Select resize edges for Resize triggered by keybind 2022-09-16 01:42:04 +02:00
John Lindgren
f112fb636e cursor: Split out cursor_button_press() and cursor_button_release() 2022-09-16 01:36:07 +02:00