Commit graph

381 commits

Author SHA1 Message Date
Consolatis
b359b1560c Move keyboard functions into input/keyboard.h 2023-10-30 21:14:04 +00:00
Consolatis
5e1562fae6 Make touch depend on cursor to prevent racing 2023-10-30 21:14:04 +00:00
Consolatis
8d0812d45a Move gesture handling out of cursor.c 2023-10-30 21:14:04 +00:00
Consolatis
67a8ae8561 Move input related source files into src/input/ 2023-10-30 21:14:04 +00:00
John Lindgren
db591d1400 view: avoid raising same view over and over
Since view_move_to_front() now does more work than it used to
(updating XWayland server stacking order), try to avoid doing that
work unnecessarily.
2023-10-21 21:42:24 +01:00
John Lindgren
048d22d473 common: move MIN and MAX to common/macros.h 2023-10-21 12:37:42 +01:00
Johan Malm
7f30de1134 xdg: add xdg_shell_init()
...to have the event-handler functions in the same translation unit as
the signal connector.

No functional change intended.
2023-10-20 18:14:11 -04:00
Axel Burri
afe92654fd Add output_usable_area_scaled() helper
Preparatory for snap to window edge framework.
2023-10-19 19:09:42 +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
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
John Lindgren
ecad76560e keyboard: add option to enable Num Lock automatically (default=enabled)
Co-authored-by: @Consolatis
2023-10-09 20:48:03 +01:00
John Lindgren
b7bd5a52e4 desktop: add commentary clarifying focus rules 2023-10-04 10:28:39 -04:00
Johan Malm
db41b5eec0 s/::/./ 2023-10-04 06:06:52 +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
bi4k8
a49e12e112 touch: store initial coordinate adjustments
this avoids touch offsets jumping when a touch point moves off of a surface
2023-08-27 23:13:24 +02:00
Johan Malm
e5a6c57a6e Move isfocusable() from desktop.c to view.c 2023-08-20 17:00:23 +01: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
235a8ad9bc ToggleKeybinds per window 2023-07-06 06:02:28 +01:00
Johan Malm
15cd093f2e action: add ToggleAlwaysOnBottom 2023-05-22 20:37:49 +01:00
Johan Malm
78aec7945c xdg-popup: render above always-on-top 2023-05-22 20:37:49 +01:00
Tomi Ollila
7ad5200f2e includes: identifier consistency in include guards
Made all header files to have LABWC_ prefix in include guard identifers.

Converted from __LABWC_ in 35 include/ files.
Converted from __LAB_ in 5 include/ files.
Added LABWC prefix to 3 include/ files.
Added include guards to 3 include/ files.

The double underscores were removed since according to C standard
those "are always reserved for any use".
2023-05-13 22:29:21 +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
ef30e3750d Decorations: handle results of kde-server-decoration negotiations 2023-03-25 07:24:40 +00:00
Consolatis
5ee2ec7fff Decorations: minor refactoring, no logical changes intended 2023-03-25 07:24:40 +00: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
a0b5a80ce1 Add FocusOutput action
Fixes #806

Suggested-by: @EysseW
Tested-by: @EysseW
2023-03-06 21:58:11 +00:00
Consolatis
c33a404dc1 Add ToggleKeybinds action
This can be used to better control Virtual Machines, VNC clients, nested
compositors or similar. All keybinds other than ToggleKeybinds itself are
disabled when first called, a 2nd call will restore handling of all keybinds.

Fixes #738
Fixes #810
2023-03-04 13:24:59 +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
976136299d output: Add output_nearest_to()
Reimplement output_from_cursor_coords() as output_nearest_to_cursor().
2023-02-21 08:46:22 +01:00
John Lindgren
5062c5bea3 view: Add optional output parameter to view_center()
Allows centering the view on a specific output without the workaround of
overwriting view->current.x/y.
2023-02-20 11:50:12 -05:00
John Lindgren
6efc6a9db4 output: Add output_is_usable() helper 2023-02-17 06:59:39 -05:00
Consolatis
f56d07aa47 Add xdg-activation protocol
This PR allows applications to activate themselves *if they provide
a valid xdg_activation token* (e.g. raise to the top and get keyboard
focus).

These tokens are given out by the xdg_activation protocol implemented
by wlroots and can be configured by the client requesting the token
in three ways:
- an "empty" token
  (apparently used to tell the compositor about "urgency")
- seat / input serial attached
- surface attached

Wlroots makes sure that
- If the client attached the seat / input serial: those two are valid.
- If the client attached a surface: that it has keyboard focus at the
  point where the request is finalized. There is a patch [1] pending
  for backport to wlroots 0.16 that also allows valid tokens when the
  supplied surface had cursor focus.
- a token is only valid for 30 seconds after being given out

The token can then be used by the client or given to other clients by
unspecified means (e.g. via environment variable or dbus) which then
may use the token on their own surface and request activation.

We only handle the actual request activation part:
- If the seat is set on the token we know wlroots validated seat and
  input serial
- Thus, if no seat is set we deny the activation request so we don't
  have windows suddenly popping up and taking over the keyboard focus
  (focus stealing prevention)
- We should also check for the surface being set but we can't do that
  with wlroots 0.16 as it will reset the surface to `NULL` when it is
  destroyed (which is something that usually happens for
  notifications). Once we move to wlroots 0.17.x we can add the
  missing surface check because it provides a `new_token` signal.
  We can use it to attach further details to the token which are then
  verified later when we decide if we allow the activate request or
  not.

With this PR in place the following setup should activate windows:
- launching an URL in foot should activate the target application if
  it is already running, foot requests a proper token and then sets it
  as `XDG_ACTIVATION_TOKEN` environment var before spawning `xdg-open`
- clicking on a `mako` notification with a `default` action defined
  should request a proper token which is then given to the application
  starting the notification and can thus be used to activate itself

This protocol is still very much in the process of being
implemented / finalized all over the place (e.g. GTK / QT / Firefox /
notification daemons, ..) but we should do our part and remove labwc
from the puzzle of potential issues causing this not to work.

[1] f6008ffff4)
2023-02-10 20:51:29 +00:00
Consolatis
3a21c39509 src/foreign.c: track outputs
Fixes #744
2023-02-02 13:26:53 +01:00
Consolatis
1995a33df9 CodeStyle: prevent space in code indents 2023-01-31 21:22:40 +00:00
Consolatis
07ee56176d SnapToRegion: Allow for live config updates 2023-01-11 18:52:24 +01: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
Consolatis
67952cd749 SnapToRegion: Wire up output and handle usable_area changes 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
Consolatis
bc4108fec0 output: Use better arg naming for output_update_all_usable_areas()
This restores the original approach of naming the argument `layout_changed`
which fits much better than `enforce_view_arrange`. Especially when extending
the function to also handle region updates once merged.
2023-01-06 20:39:04 +01:00
Consolatis
7b48da4ab2 include/labwc.h: Provide MIN/MAX macros 2023-01-06 18:33:25 +01:00
Consolatis
7790da7b4e src/view.c: move xwayland specific function to xwayland.c
Also remove the `<xcb/xcb_icccm.h>` include as its already included
by `"labwc.h"` -> `<wlr/xwayland.h>` -> `<wlr/xwayland/xwayland.h>`.
2023-01-06 14:54:28 +01:00
John Lindgren
ed31381eb8 output: Add output_update_usable_area/all_usable_areas()
Move the desktop_arrange_all_views() call outside layers_arrange() into
a new function, output_update_usable_area().  The new function currently
does exactly what layers_arrange() used to, but will be expanded in a
later commit.

Add output_update_all_usable_areas(), which is the same as calling
output_update_usable_area() for each output, but only calls
desktop_arrange_all_views() once.

Rebased and slightly modified by @Consolatis
2023-01-06 14:51:46 +01:00
Johan Malm
f01071e72c layer: remove wl_list layers[] from struct output
...and just use `struct wlr_scene_tree *layer_tree[]`
2022-12-29 23:18:08 +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