Compare commits

...

44 Commits

Author SHA1 Message Date
8488cd9d97 Merge branch 'master' of https://codeberg.org/river/river 2025-04-17 21:25:40 +09:00
46f77f30dc Seat: put all keyboards in a single group
Deprecate and ignore the riverctl commands for creating explicit
keyboard groups.

In my mind, the only reason to have more than one keyboard group is if
different keyboard devices are assigned different keymaps or repeat
rates. River does not currently allow such things to be configured
however.

When river eventually makes it possible to configure different keymaps
and repeat rates per keyboard device, there is no reason we can't 100%
automatically group keyboards based on the keymap/repeat rate.

Exposing this keyboard group abstraction to the user is just bad UX.

Failing to group keyboards automatically also creates confusing/buggy
behavior for the user if the hardware, for example, exposes some of the
the XF86 buttons on a laptop as a separate keyboard device from the main
keyboard. Creating keybindings for these XF86 buttons that use modifiers
doesn't work by default, but there's no reason it shouldn't just work.

Closes: https://codeberg.org/river/river/issues/1138
2025-03-29 15:44:56 +01:00
8490558b8b Cursor: restore previous image on unhide
If client A has an xdg_popup open and the user moves the cursor over a
surface of client B and waits for the cursor to be hidden after a
timeout, the cursor will not be shown on movement until the (invisible)
cursor is moved back into a surface of client A or somewhere the
compositor is responsible for rendering the cursor.

This is due to the (flawed) xdg popup grab interface of wlroots which
prevents wlr_seat_pointer_notify_enter() from sending events to clients
other than the one with the active xdg popup.

Closes: https://codeberg.org/river/river/issues/1192
2025-03-16 13:48:09 +01:00
14f63f3099 Merge branch 'master' of https://codeberg.org/river/river 2025-02-05 15:17:43 -08:00
543697847f Xwayland: don't inherit rlimit changes from river 2025-01-07 11:00:44 -06:00
c1fc15dbc6 Merge branch 'master' of https://codeberg.org/river/river 2025-01-06 20:14:25 -08:00
6abcc68a19 river: wrap monotonic time > 2^32-1 milliseconds
Fixes: https://codeberg.org/river/river/issues/1176
2024-12-30 09:23:52 -06:00
ab879e245c Output: check scene damage before rendering
This should fix adaptive sync/VRR, which was regressed by db7de8151.
2024-12-29 16:09:44 -06:00
9f8b689f8a security-context-v1: fix assertion failure
There's a bit of subtlety I missed with the zig-wayland upgrade.
Since zig-wayland now generates its own wl_interface structs the pointer
comparison we used to do here is no longer sufficient.
2024-12-27 09:49:14 -06:00
e575485f0d deps: upgrade to latest zig-wayland 2024-12-23 14:14:35 -06:00
4fba7505f3 deps: update to latest zig-wayland 2024-12-17 17:35:16 -06:00
5ca829bd5a docs: mention key repeat defaults 2024-11-24 15:11:42 +01:00
a2a5e8f463 alpha-modifier-v1: implement protocol
Implement the alpha-modifier-v1 protocol, which allows clients to
offload alpha blending operations to the compositor.

wlroots' scene graph code takes care of updating the opacity of
wlr_scene_buffers with an associated wp_alpha_modifier_surface_v1.
2024-11-08 18:56:20 -05:00
33a69405c4 Fix riverctl.1.csd 2024-11-02 08:16:58 -07:00
5080f07724 Add cursor warp option 2024-11-02 08:00:50 -07:00
d66decb7c4 Open view relative to mouse, take 2 2024-11-01 22:08:20 -07:00
eab34c7c03 Merge branch 'master' of https://codeberg.org/river/river 2024-11-01 15:43:44 -07:00
dbe2cb72f8 Allow floating views to appear at the mouse 2024-11-01 15:43:17 -07:00
1b5dd21ee6 layer-surface: fix clip box coordinates
The clip box must be relative to the layer surface, not the output.
2024-10-24 12:07:49 +02:00
3529463569 Output: workaround wlroots headless output bug 2024-10-24 10:55:44 +02:00
2061ae2c4c Merge branch 'master' of https://codeberg.org/river/river 2024-10-21 05:37:26 -07:00
fd55f51ba1 input: support scroll button lock config 2024-10-03 11:42:21 +02:00
26f599b56b docs: fix broken repology link 2024-09-18 16:12:18 +02:00
fbb9cc0f76 build: load tablet-v2 protocol from its new location 2024-09-04 10:57:16 +00:00
55974987b6 tearing-control: fix security-context related assert 2024-08-28 11:26:35 +02:00
f82b2f5816 tearing-control: minor cleanups/style improvements
This commit also tweaks the riverctl interface to make the global
allow-tearing option apply only to tearing-control-v1 hints from
clients. The global option no longer affects tearing/no-tearing rules
explicitly created by the user.
2024-08-15 11:49:51 +02:00
066baa5753 tearing-control-v1: implement
Implement the wp-tearing-control-v1 protocol allowing window to hint
the compositor that they prefer async "tearing" page flips.

Add tearing/no-tearing rules to allow the user to manually
enabled/disable tearing for a window.

Use async "tearing" page flips when a window that should be allowed to
tear is fullscreen.

This still requires several kernel patches to work with the wlroots
atomic DRM backend. For now, either set WLR_DRM_NO_ATOMIC=1 or use a
custom kernel that includes the unmerged patches (such as CachyOS).

Closes: https://codeberg.org/river/river/issues/1094
2024-08-15 11:45:53 +02:00
db7de8151c Root: simplify scene tree reparenting
Making these reparent() calls unconditional avoids inconsistent state.
It's also simpler and less error-prone and the wlroots function returns
immediately if the parent doesn't change anyways.
2024-08-07 11:09:38 +02:00
f5d37f9b4d docs: clarify input device name description
The word "numerical" suggests both decimal and hexadecimal, so changed
it to decimal.
2024-07-28 14:02:04 +02:00
93863b132e Output: don't configure uninitialized layer surfaces
It is possible for a layer surface to notably delay its initial commit;
for example shotman[1] creates two layer surfaces and uses one of them
to get enough information for a screenshot and initializing the other.
River could also have sent a configure before initial commit if two
clients raced against each other.

Fixes https://codeberg.org/river/river/issues/1123

[1]:https://sr.ht/~whynothugo/shotman/
2024-07-26 07:53:42 +00:00
85a1673a9e river: attempt to recover from GPU resets 2024-07-22 16:21:15 +02:00
2cc1d1cef3 LayerSurface: minor style/naming tweaks
No functional changes
2024-07-17 11:10:02 +02:00
f27bbf03f1 LayerSurface: focus on_demand-interactive surfaces on map
This is done specifically for lxqt-runner and qterminal to work as
expected, consistently among (almost) all compositors with layer-shell.
The most prominent drawback of this is that top- and overlay-layer
status bars with on_demand interactivity also get focus on map.

See https://codeberg.org/river/river/issues/1111 for more details.
2024-07-16 21:28:01 +00:00
99ef96a389 build: update to wlroots 0.18.0 2024-07-16 14:34:40 +02:00
ccd676e5a9 completions: zsh click-method option fix
"button-areas" seems to be the argument this command expects instead of
"button-area" -- other shells also have the option as "button-areas".
2024-07-12 09:16:41 +01:00
a7411ef2a6 PointerConstraint: fix assertion failure
The assertion in PointerConstraint.confine() can currently still be
triggered if the input region of a surface is changed and the pointer is
moved outside of the new intersection of input region and constraint
region before PointerConstraint.updateState() is called.

This can happen, for example, when a client is made non-fullscreen at
the same time as the pointer is moved across the boundary of the new,
post-fullscreen, input region. If the pointer crosses the boundary
before the transaction completes and updateState() is called, the
assertion in PointerConstraint.confine() will fail.

To fix this, listen for the surface commit event rather than the
set_region event to handle possible deactivation on region changes.
2024-07-10 12:16:42 +02:00
1f5bf1d972 docs: mention zig build -h in readme 2024-07-09 18:26:17 +02:00
14a5609dae Merge branch 'master' of https://codeberg.org/river/river 2024-07-07 22:30:06 -07:00
4232d6b99f layer-shell: fix on_demand keyboard focus
Currently keyboard focus is stolen from layer surfaces with
on_demand keyboard interactivity any time Root.applyPending() is called.

This commit fixes the behavior to only steal focus when explicitly
focusing a different window/layer surface.
2024-07-02 15:03:22 +02:00
ec16f1c375 XdgPopup: send configure after initial commit
Currently we send the first configure for xdg popups before the popup
has made its initial commit. This is incorrect according to the protocol
and may confuse clients.
2024-07-01 12:55:35 +02:00
a80e0f7322 Output: fix Wayland backend support
The wlroots Wayland backend does not support gamma LUT application and
will currently fail to render anything if river commits a gamma LUT.

To fix this, test the state when applying a gamma LUT and fall back to a
state with no gamma LUT set if that fails.

This problem was revealed by 2e09b66 which flags gamma as dirty on all
outputs when they are enabled.
2024-07-01 12:27:16 +02:00
0997fde28e docs: tweak repology link wording in readme 2024-06-30 12:12:00 +02:00
ae7f4b8fcb Xwayland: fix unsound cast
The X11 protocol uses 16 bit integers for width/height but we use
32 bit integers everywhere else in river. Make sure that values outside
the range of a 16 bit integer don't cause river to crash with an
assertion failure.

I think that coordinates outside the range of a 16 bit integer could
theoretically be reasonable with tiled high resolution displays in the
future. I doubt they ever get used in practice today but at the same
time we can't allow an errant layout generator to crash river.
2024-06-25 12:24:25 +02:00
2e09b66963 Output: flag gamma as dirty on enable
We can end up with stale gamma settings if we don't re-check the
current gamma settings for the output on enable.
2024-06-24 19:29:19 +02:00
37 changed files with 646 additions and 559 deletions

View File

@ -28,15 +28,17 @@ sources:
tasks:
- install_deps: |
cd wayland
git checkout 1.22.0
git checkout 1.23.0
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
sudo ninja -C build install
cd ..
cd wlroots
git checkout 0.17.2
meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \
-Dwerror=false -Db_ndebug=false -Dxcb-errors=disabled --prefix /usr
git checkout 0.18.0
meson setup build --auto-features=enabled -Drenderers=gles2 \
-Dcolor-management=disabled -Dlibliftoff=disabled \
-Dexamples=false -Dwerror=false -Db_ndebug=false \
-Dxcb-errors=disabled --prefix /usr
sudo ninja -C build/ install
cd ..

View File

@ -26,15 +26,17 @@ sources:
tasks:
- install_deps: |
cd wayland
git checkout 1.22.0
git checkout 1.23.0
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
sudo ninja -C build install
cd ..
cd wlroots
git checkout 0.17.2
meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \
-Dwerror=false -Db_ndebug=false --prefix /usr
git checkout 0.18.0
meson setup build --auto-features=enabled -Drenderers=gles2 \
-Dcolor-management=disabled -Dlibliftoff=disabled \
-Dexamples=false -Dwerror=false -Db_ndebug=false \
-Dxcb-errors=disabled --prefix /usr
sudo ninja -C build/ install
cd ..

View File

@ -31,15 +31,17 @@ sources:
tasks:
- install_deps: |
cd wayland
git checkout 1.22.0
git checkout 1.23.0
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
sudo ninja -C build install
cd ..
cd wlroots
git checkout 0.17.2
meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \
-Dwerror=false -Db_ndebug=false --prefix /usr
git checkout 0.18.0
meson setup build --auto-features=enabled -Drenderers=gles2 \
-Dcolor-management=disabled -Dlibliftoff=disabled \
-Dexamples=false -Dwerror=false -Db_ndebug=false \
-Dxcb-errors=disabled --prefix /usr
sudo ninja -C build/ install
cd ..

View File

@ -7,7 +7,7 @@
River is a dynamic tiling Wayland compositor with flexible runtime
configuration.
Install from your [package manager](https://repology.org/project/river/versions) —
Check [packaging status](https://repology.org/project/river-compositor/versions) —
Join us at [#river](https://web.libera.chat/?channels=#river) on irc.libera.chat —
Read our man pages, [wiki](https://codeberg.org/river/wiki), and
[Code of Conduct](CODE_OF_CONDUCT.md)
@ -60,7 +60,7 @@ distribution.
- [zig](https://ziglang.org/download/) 0.13
- wayland
- wayland-protocols
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.17.2
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.18
- xkbcommon
- libevdev
- pixman
@ -72,6 +72,7 @@ Then run, for example:
zig build -Doptimize=ReleaseSafe --prefix ~/.local install
```
To enable Xwayland support pass the `-Dxwayland` option as well.
Run `zig build -h` to see a list of all options.
## Usage

View File

@ -92,18 +92,19 @@ pub fn build(b: *Build) !void {
const scanner = Scanner.create(b, .{});
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
scanner.addSystemProtocol("stable/tablet/tablet-v2.xml");
scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml");
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
scanner.addSystemProtocol("staging/tearing-control/tearing-control-v1.xml");
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
scanner.addSystemProtocol("unstable/tablet/tablet-unstable-v2.xml");
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
scanner.addCustomProtocol("protocol/river-control-unstable-v1.xml");
scanner.addCustomProtocol("protocol/river-status-unstable-v1.xml");
scanner.addCustomProtocol("protocol/river-layout-v3.xml");
scanner.addCustomProtocol("protocol/wlr-layer-shell-unstable-v1.xml");
scanner.addCustomProtocol("protocol/wlr-output-power-management-unstable-v1.xml");
scanner.addCustomProtocol(b.path("protocol/river-control-unstable-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/river-status-unstable-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/river-layout-v3.xml"));
scanner.addCustomProtocol(b.path("protocol/wlr-layer-shell-unstable-v1.xml"));
scanner.addCustomProtocol(b.path("protocol/wlr-output-power-management-unstable-v1.xml"));
// Some of these versions may be out of date with what wlroots implements.
// This is not a problem in practice though as long as river successfully compiles.
@ -124,6 +125,7 @@ pub fn build(b: *Build) !void {
scanner.generate("zxdg_decoration_manager_v1", 1);
scanner.generate("ext_session_lock_manager_v1", 1);
scanner.generate("wp_cursor_shape_manager_v1", 1);
scanner.generate("wp_tearing_control_manager_v1", 1);
scanner.generate("zriver_control_v1", 1);
scanner.generate("zriver_status_manager_v1", 4);
@ -146,7 +148,7 @@ pub fn build(b: *Build) !void {
// exposed to the wlroots module for @cImport() to work. This seems to be
// the best way to do so with the current std.Build API.
wlroots.resolved_target = target;
wlroots.linkSystemLibrary("wlroots", .{});
wlroots.linkSystemLibrary("wlroots-0.18", .{});
const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") });
const globber = b.createModule(.{ .root_source_file = b.path("common/globber.zig") });
@ -167,7 +169,7 @@ pub fn build(b: *Build) !void {
river.linkSystemLibrary("libevdev");
river.linkSystemLibrary("libinput");
river.linkSystemLibrary("wayland-server");
river.linkSystemLibrary("wlroots");
river.linkSystemLibrary("wlroots-0.18");
river.linkSystemLibrary("xkbcommon");
river.linkSystemLibrary("pixman-1");
@ -183,9 +185,6 @@ pub fn build(b: *Build) !void {
.flags = &.{ "-std=c99", "-O2" },
});
// TODO: remove when zig issue #131 is implemented
scanner.addCSource(river);
river.pie = pie;
river.root_module.omit_frame_pointer = omit_frame_pointer;
@ -209,8 +208,6 @@ pub fn build(b: *Build) !void {
riverctl.linkLibC();
riverctl.linkSystemLibrary("wayland-client");
scanner.addCSource(riverctl);
riverctl.pie = pie;
riverctl.root_module.omit_frame_pointer = omit_frame_pointer;
@ -234,8 +231,6 @@ pub fn build(b: *Build) !void {
rivertile.linkLibC();
rivertile.linkSystemLibrary("wayland-client");
scanner.addCSource(rivertile);
rivertile.pie = pie;
rivertile.root_module.omit_frame_pointer = omit_frame_pointer;

View File

@ -8,12 +8,12 @@
.hash = "12209db20ce873af176138b76632931def33a10539387cba745db72933c43d274d56",
},
.@"zig-wayland" = .{
.url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.2.0.tar.gz",
.hash = "1220687c8c47a48ba285d26a05600f8700d37fc637e223ced3aa8324f3650bf52242",
.url = "https://codeberg.org/ifreund/zig-wayland/archive/bd8afd256fb6beed7d72e3580b00f33dea7155a1.tar.gz",
.hash = "1220218a0e5c2cd63a2311417f4d3f2411dd17d75815f67c704ee657bd846ecbc3e0",
},
.@"zig-wlroots" = .{
.url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.17.1.tar.gz",
.hash = "1220c65ab884c236cc950b564c70f6cd04046d86485ee76e0cde886cef7438021b4f",
.url = "https://codeberg.org/ifreund/zig-wlroots/archive/afbbbbe5579c750feed8de12b073fa50b0651137.tar.gz",
.hash = "122060ddef836b7872cb2088764a8bd2fb2e9254327673e8176b7f7a621ec897484f",
},
.@"zig-xkbcommon" = .{
.url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz",

View File

@ -18,12 +18,11 @@
const std = @import("std");
const mem = std.mem;
/// Validate a glob, returning error.InvalidGlob if it is empty, "**" or has a
/// '*' at any position other than the first and/or last byte.
/// Validate a glob, returning error.InvalidGlob if is "**" or has a '*'
/// at any position other than the first and/or last byte.
pub fn validate(glob: []const u8) error{InvalidGlob}!void {
switch (glob.len) {
0 => return error.InvalidGlob,
1 => {},
0, 1 => {},
2 => if (glob[0] == '*' and glob[1] == '*') return error.InvalidGlob,
else => if (mem.indexOfScalar(u8, glob[1 .. glob.len - 1], '*') != null) {
return error.InvalidGlob;
@ -34,6 +33,7 @@ pub fn validate(glob: []const u8) error{InvalidGlob}!void {
test validate {
const testing = std.testing;
try validate("");
try validate("*");
try validate("a");
try validate("*a");
@ -48,7 +48,6 @@ test validate {
try validate("abc*");
try validate("*abc*");
try testing.expectError(error.InvalidGlob, validate(""));
try testing.expectError(error.InvalidGlob, validate("**"));
try testing.expectError(error.InvalidGlob, validate("***"));
try testing.expectError(error.InvalidGlob, validate("a*c"));
@ -67,7 +66,9 @@ pub fn match(s: []const u8, glob: []const u8) bool {
validate(glob) catch unreachable;
}
if (glob.len == 1) {
if (glob.len == 0) {
return s.len == 0;
} else if (glob.len == 1) {
return glob[0] == '*' or mem.eql(u8, s, glob);
}
@ -89,6 +90,9 @@ test match {
const testing = std.testing;
try testing.expect(match("", "*"));
try testing.expect(match("", ""));
try testing.expect(!match("a", ""));
try testing.expect(!match("", "a"));
try testing.expect(match("a", "*"));
try testing.expect(match("a", "*a*"));
@ -165,8 +169,10 @@ pub fn order(a: []const u8, b: []const u8) std.math.Order {
return .lt;
}
const count_a = @as(u2, @intFromBool(a[0] == '*')) + @intFromBool(a[a.len - 1] == '*');
const count_b = @as(u2, @intFromBool(b[0] == '*')) + @intFromBool(b[b.len - 1] == '*');
const count_a = if (a.len != 0) @as(u2, @intFromBool(a[0] == '*')) +
@intFromBool(a[a.len - 1] == '*') else 0;
const count_b = if (b.len != 0) @as(u2, @intFromBool(b[0] == '*')) +
@intFromBool(b[b.len - 1] == '*') else 0;
if (count_a == 0 and count_b == 0) {
return .eq;
@ -182,6 +188,7 @@ test order {
const testing = std.testing;
const Order = std.math.Order;
try testing.expectEqual(Order.eq, order("", ""));
try testing.expectEqual(Order.eq, order("*", "*"));
try testing.expectEqual(Order.eq, order("*a*", "*b*"));
try testing.expectEqual(Order.eq, order("a*", "*b"));
@ -204,6 +211,7 @@ test order {
"bababab",
"b",
"a",
"",
};
for (descending, 0..) |a, i| {

View File

@ -1,13 +1,9 @@
function __riverctl_completion ()
{
local rule_actions="float no-float ssd csd tags output position dimensions fullscreen no-fullscreen"
local rule_actions="float no-float ssd csd tags output position relative-position dimensions fullscreen no-fullscreen warp no-warp"
if [ "${COMP_CWORD}" -eq 1 ]
then
OPTS=" \
keyboard-group-create \
keyboard-group-destroy \
keyboard-group-add \
keyboard-group-remove \
keyboard-layout \
keyboard-layout-file \
close \
@ -99,6 +95,7 @@ function __riverctl_completion ()
tap-button-map \
scroll-method \
scroll-button \
scroll-button-lock \
map-to-output"
COMPREPLY=($(compgen -W "${OPTS}" -- "${COMP_WORDS[3]}"))
elif [ "${COMP_WORDS[1]}" == "hide-cursor" ]
@ -117,7 +114,7 @@ function __riverctl_completion ()
"events") OPTS="enabled disabled disabled-on-external-mouse" ;;
"accel-profile") OPTS="none flat adaptive" ;;
"click-method") OPTS="none button-areas clickfinger" ;;
"drag"|"drag-lock"|"disable-while-typing"|"middle-emulation"|"left-handed"|"tap") OPTS="enabled disabled" ;;
"drag"|"drag-lock"|"disable-while-typing"|"middle-emulation"|"left-handed"|"tap"|"scroll-button-lock") OPTS="enabled disabled" ;;
"tap-button-map") OPTS="left-right-middle left-middle-right" ;;
"scroll-method") OPTS="none two-finger edge button" ;;
*) return ;;

View File

@ -72,11 +72,6 @@ complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'hide-cursor'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'set-repeat' -d 'Set the keyboard repeat rate and repeat delay'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'set-cursor-warp' -d 'Set the cursor warp mode'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'xcursor-theme' -d 'Set the xcursor theme'
# Keyboardgroups
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-create' -d 'Create a keyboard group'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-destroy' -d 'Destroy a keyboard group'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-add' -d 'Add a keyboard to a keyboard group'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-remove' -d 'Remove a keyboard from a keyboard group'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-layout' -d 'Set the keyboard layout'
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-layout-file' -d 'Set the keyboard layout from a file.'
@ -91,10 +86,10 @@ complete -c riverctl -n '__fish_seen_subcommand_from default-attach-mode'
complete -c riverctl -n '__fish_seen_subcommand_from output-attach-mode' -n '__fish_riverctl_complete_arg 2' -a 'top bottom above below after'
complete -c riverctl -n '__fish_seen_subcommand_from focus-follows-cursor' -n '__fish_riverctl_complete_arg 2' -a 'disabled normal always'
complete -c riverctl -n '__fish_seen_subcommand_from set-cursor-warp' -n '__fish_riverctl_complete_arg 2' -a 'disabled on-output-change on-focus-change'
complete -c riverctl -n '__fish_seen_subcommand_from list-rules' -n '__fish_riverctl_complete_arg 2' -a 'float ssd tags output position dimensions fullscreen'
complete -c riverctl -n '__fish_seen_subcommand_from list-rules' -n '__fish_riverctl_complete_arg 2' -a 'float ssd tags output position dimensions fullscreen warp'
# Options and subcommands for 'rule-add' and 'rule-del'
set -l rule_actions float no-float ssd csd tags output position dimensions fullscreen no-fullscreen
set -l rule_actions float no-float ssd csd tags output position relative-position dimensions fullscreen no-fullscreen warp no-warp
complete -c riverctl -n '__fish_seen_subcommand_from rule-add rule-del' -n "not __fish_seen_subcommand_from $rule_actions" -n 'not __fish_seen_argument -o app-id' -o 'app-id' -r
complete -c riverctl -n '__fish_seen_subcommand_from rule-add rule-del' -n "not __fish_seen_subcommand_from $rule_actions" -n 'not __fish_seen_argument -o title' -o 'title' -r
complete -c riverctl -n '__fish_seen_subcommand_from rule-add rule-del' -n "not __fish_seen_subcommand_from $rule_actions" -n 'test (math (count (commandline -opc)) % 2) -eq 0' -a "$rule_actions"
@ -119,10 +114,11 @@ complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'tap-button-map' -d 'Configure the button mapping for tapping'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-method' -d 'Set the scroll method'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-button' -d 'Set the scroll button'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-button-lock' -d 'Enable or disable the scroll button lock functionality'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'map-to-output' -d 'Map to a given output'
# Subcommands for the subcommands of 'input'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from drag drag-lock disable-while-typing disable-while-trackpointing middle-emulation natural-scroll left-handed tap' -a 'enabled disabled'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from drag drag-lock disable-while-typing disable-while-trackpointing middle-emulation natural-scroll left-handed tap scroll-button-lock' -a 'enabled disabled'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from events' -a 'enabled disabled disabled-on-external-mouse'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from accel-profile' -a 'none flat adaptive'
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from click-method' -a 'none button-areas clickfinger'

View File

@ -62,11 +62,6 @@ _riverctl_commands()
'set-repeat:Set the keyboard repeat rate and repeat delay'
'set-cursor-warp:Set the cursor warp mode.'
'xcursor-theme:Set the xcursor theme'
# Keyboard groups
'keyboard-group-create:Create a keyboard group'
'keyboard-group-destroy:Destroy a keyboard group'
'keyboard-group-add:Add a keyboard to a keyboard group'
'keyboard-group-remove:Remove a keyboard from a keyboard group'
'keyboard-layout:Set the keyboard layout'
'keyboard-layout-file:Set the keyboard layout from a file'
# Input
@ -126,6 +121,7 @@ _riverctl()
'tap-button-map:Configure the button mapping for tapping'
'scroll-method:Set the scroll method'
'scroll-button:Set the scroll button'
'scroll-button-lock:Enable or disable the scroll button lock functionality'
'map-to-output:Map to a given output'
)
@ -135,7 +131,7 @@ _riverctl()
case "$line[2]" in
events) _alternative 'input-cmds:args:(enabled disabled disabled-on-external-mouse)' ;;
accel-profile) _alternative 'input-cmds:args:(none flat adaptive)' ;;
click-method) _alternative 'input-cmds:args:(none button-area clickfinger)' ;;
click-method) _alternative 'input-cmds:args:(none button-areas clickfinger)' ;;
drag) _alternative 'input-cmds:args:(enabled disabled)' ;;
drag-lock) _alternative 'input-cmds:args:(enabled disabled)' ;;
disable-while-typing) _alternative 'input-cmds:args:(enabled disabled)' ;;
@ -144,6 +140,7 @@ _riverctl()
natural-scroll) _alternative 'input-cmds:args:(enabled disabled)' ;;
left-handed) _alternative 'input-cmds:args:(enabled disabled)' ;;
tap) _alternative 'input-cmds:args:(enabled disabled)' ;;
scroll-button-lock) _alternative 'input-cmds:args:(enabled disabled)' ;;
tap-button-map) _alternative 'input-cmds:args:(left-right-middle left-middle-right)' ;;
scroll-method) _alternative 'input-cmds:args:(none two-finger edge button)' ;;
*) return 0 ;;
@ -205,9 +202,9 @@ _riverctl()
# In case of a new rule added in river, we just need
# to add it to the third option between '()',
# i.e (float no-float <new-option>)
_arguments '1: :(-app-id -title)' '2: : ' ':: :(float no-float ssd csd tags output position dimensions fullscreen no-fullscreen)'
_arguments '1: :(-app-id -title)' '2: : ' ':: :(float no-float ssd csd tags output position relative-position dimensions fullscreen no-fullscreen warp no-warp)'
;;
list-rules) _alternative 'arguments:args:(float ssd tags output position dimensions fullscreen)' ;;
list-rules) _alternative 'arguments:args:(float ssd tags output position dimensions fullscreen warp)' ;;
*) return 0 ;;
esac
;;

View File

@ -298,20 +298,33 @@ matches everything while _\*\*_ and the empty string are invalid.
with make: _HP Inc._, model: _HP 22w_, and serial: _CNC93720WF_, the
identifier would be: _HP Inc. HP 22w CNC93720WF_. If the make, model, or
serial is unknown, the word "Unknown" is used instead.
- *position*: Set the initial position of the view, clamping to the
bounds of the output. Requires x and y coordinates of the view as
arguments, both of which must be non-negative. Applies only to new views.
- *position*: Set the initial position of the view, clamping to the bounds
of the output. Requires x and y coordinates of the view as arguments, both
of which must be non-negative. Applies only to new views.
- *relative-position*: Set the position of the view relative to
something. Requires the anchor and the x and y coordinates of the
view. The coordinates are either positive or negative numbers that are
relative to the anchor. Applies only to new views.
- *dimensions*: Set the initial dimensions of the view, clamping to the
constraints of the view. Requires width and height of the view as
arguments, both of which must be non-negative. Applies only to new views.
- *fullscreen*: Make the view fullscreen. Applies only to new views.
- *no-fullscreen*: Don't make the view fullscreen. Applies only to
new views.
- *tearing*: Allow the view to tear when fullscreen regardless of the
view's preference. Applies to new and existing views.
- *no-tearing*: Disable tearing for the view regardless of the view's
preference. Applies to new and existing views.
- *warp*: Always warp the cursor when switching to this view, regardless of
the _set-cursor-warp_ setting. Applies to new and existing views.
- *no-warp*: Never warp the cursor when switching to this view, regardless
of the _set-cursor-warp_ setting. Applies to new and existing views.
Both *float* and *no-float* rules are added to the same list,
which means that adding a *no-float* rule with the same arguments
as a *float* rule will overwrite it. The same holds for *ssd* and
*csd*, *fullscreen* and *no-fullscreen* rules.
*csd*, *fullscreen* and *no-fullscreen*, *tearing* and
*no-tearing*, *warp* and *no-warp* rules.
If multiple rules in a list match a given view the most specific
rule will be applied. For example with the following rules
@ -339,7 +352,7 @@ matches everything while _\*\*_ and the empty string are invalid.
*rule-del* [*-app-id* _glob_|*-title* _glob_] _action_
Delete a rule created using *rule-add* with the given arguments.
*list-rules* *float*|*ssd*|*tags*|*position*|*dimensions*|*fullscreen*
*list-rules* *float*|*ssd*|*tags*|*position*|*dimensions*|*fullscreen*|*warp*
Print the specified rule list. The output is ordered from most specific
to least specific, the same order in which views are checked against
when searching for a match. Only the first matching rule in the list
@ -364,6 +377,10 @@ matches everything while _\*\*_ and the empty string are invalid.
Set the attach mode of the currently focused output, overriding the value of
default-attach-mode if any.
*allow-tearing* *enabled*|*disabled*
Allow fullscreen views to tear if requested by the view. See also the
*tearing* rule to force enable tearing for specific views.
*background-color* _0xRRGGBB_|_0xRRGGBBAA_
Set the background color.
@ -413,7 +430,8 @@ matches everything while _\*\*_ and the empty string are invalid.
*set-repeat* _rate_ _delay_
Set the keyboard repeat rate to _rate_ key repeats per second and
repeat delay to _delay_ milliseconds.
repeat delay to _delay_ milliseconds. The default is a rate of 25
repeats per second and a delay of 600ms.
*xcursor-theme* _theme_name_ [_size_]
Set the xcursor theme to _theme_name_ and optionally set the _size_.
@ -444,29 +462,10 @@ matches everything while _\*\*_ and the empty string are invalid.
following URL:
https://xkbcommon.org/doc/current/keymap-text-format-v1.html
*keyboard-group-create* _group_name_
Create a keyboard group. A keyboard group collects multiple keyboards in
a single logical keyboard. This means that all state, like the active
modifiers, is shared between the keyboards in a group.
*keyboard-group-destroy* _group_name_
Destroy the keyboard group with the given name. All attached keyboards
will be released, making them act as separate devices again.
*keyboard-group-add* _group_name_ _input_device_name_
Add a keyboard to a keyboard group, identified by the keyboard's
input device name. Any currently connected and future keyboards with
the given name will be added to the group. Simple globbing patterns are
supported, see the rules section for further information on globs.
*keyboard-group-remove* _group_name_ _input_device_name_
Remove a keyboard from a keyboard group, identified by the keyboard's
input device name.
The _input_ command can be used to create a configuration rule for an input
device identified by its _name_.
The _name_ of an input device consists of its type, its numerical vendor id,
its numerical product id and finally its self-advertised name, separated by -.
The _name_ of an input device consists of its type, its decimal vendor id,
its decimal product id and finally its self-advertised name, separated by -.
Simple globbing patterns are supported, see the rules section for further
information on globs.
@ -536,6 +535,11 @@ However note that not every input device supports every property.
Set the scroll button of an input device. _button_ is the name of a Linux
input event code.
*input* _name_ *scroll-button-lock* *enabled*|*disabled*
Enable or disable the scroll button lock functionality of the input device. If
active, the button does not need to be held down. One press makes the button
considered to be held down, and a second press releases the button.
*input* _name_ *map-to-output* _output_|*disabled*
Maps the input to a given output. This is valid even if the output isn't
currently active and will lead to the device being mapped once it is

View File

@ -58,9 +58,15 @@ pub const HideCursorWhenTypingMode = enum {
enabled,
};
pub const Anchor = enum {
absolute,
mouse,
};
pub const Position = struct {
x: u31,
y: u31,
anchor: Anchor,
x: i31,
y: i31,
};
pub const Dimensions = struct {
@ -68,6 +74,9 @@ pub const Dimensions = struct {
height: u31,
};
/// Whether to allow tearing page flips when fullscreen if a view requests it.
allow_tearing: bool = false,
/// Color of background in RGBA with premultiplied alpha (alpha should only affect nested sessions)
background_color: [4]f32 = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }, // Solarized base03
@ -98,6 +107,8 @@ rules: struct {
position: RuleList(Position) = .{},
dimensions: RuleList(Dimensions) = .{},
fullscreen: RuleList(bool) = .{},
tearing: RuleList(bool) = .{},
warp: RuleList(bool) = .{},
} = .{},
/// The selected focus_follows_cursor mode
@ -182,6 +193,7 @@ pub fn deinit(config: *Config) void {
config.rules.position.deinit();
config.rules.dimensions.deinit();
config.rules.fullscreen.deinit();
config.rules.warp.deinit();
util.gpa.free(config.default_layout_namespace);

View File

@ -108,6 +108,19 @@ const LayoutPoint = struct {
ly: f64,
};
const Image = union(enum) {
/// No cursor image
none,
/// Name of the current Xcursor shape
xcursor: [*:0]const u8,
/// Cursor surface configured by a client
client: struct {
surface: *wlr.Surface,
hotspot_x: i32,
hotspot_y: i32,
},
};
const log = std.log.scoped(.cursor);
/// Current cursor mode as well as any state needed to implement that mode
@ -124,9 +137,8 @@ wlr_cursor: *wlr.Cursor,
/// Xcursor manager for the currently configured Xcursor theme.
xcursor_manager: *wlr.XcursorManager,
/// Name of the current Xcursor shape, or null if a client has configured a
/// surface to be used as the cursor shape instead.
xcursor_name: ?[*:0]const u8 = null,
image: Image = .none,
image_surface_destroy: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleImageSurfaceDestroy),
/// Number of distinct buttons currently pressed
pressed_count: u32 = 0,
@ -286,18 +298,40 @@ pub fn setTheme(cursor: *Cursor, theme: ?[*:0]const u8, _size: ?u32) !void {
cursor.xcursor_manager.destroy();
cursor.xcursor_manager = xcursor_manager;
if (cursor.xcursor_name) |name| {
cursor.setXcursor(name);
switch (cursor.image) {
.none, .client => {},
.xcursor => |name| cursor.wlr_cursor.setXcursor(xcursor_manager, name),
}
}
pub fn setXcursor(cursor: *Cursor, name: [*:0]const u8) void {
cursor.wlr_cursor.setXcursor(cursor.xcursor_manager, name);
cursor.xcursor_name = name;
pub fn setImage(cursor: *Cursor, image: Image) void {
switch (cursor.image) {
.none, .xcursor => {},
.client => {
cursor.image_surface_destroy.link.remove();
},
}
cursor.image = image;
switch (cursor.image) {
.none => cursor.wlr_cursor.unsetImage(),
.xcursor => |name| cursor.wlr_cursor.setXcursor(cursor.xcursor_manager, name),
.client => |client| {
cursor.wlr_cursor.setSurface(client.surface, client.hotspot_x, client.hotspot_y);
client.surface.events.destroy.add(&cursor.image_surface_destroy);
},
}
}
fn handleImageSurfaceDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const cursor: *Cursor = @fieldParentPtr("image_surface_destroy", listener);
// wlroots calls wlr_cursor_unset_image() automatically
// when the cursor surface is destroyed.
cursor.image = .none;
cursor.image_surface_destroy.link.remove();
}
fn clearFocus(cursor: *Cursor) void {
cursor.setXcursor("default");
cursor.setImage(.{ .xcursor = "default" });
cursor.seat.wlr_seat.pointerNotifyClearFocus();
}
@ -324,6 +358,7 @@ fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Point
math.maxInt(i32) / 2,
)),
event.source,
event.relative_direction,
);
}
@ -568,7 +603,7 @@ fn handleTouchUp(
cursor.seat.handleActivity();
if (cursor.touch_points.remove(event.touch_id)) {
cursor.seat.wlr_seat.touchNotifyUp(event.time_msec, event.touch_id);
_ = cursor.seat.wlr_seat.touchNotifyUp(event.time_msec, event.touch_id);
}
}
@ -582,32 +617,9 @@ fn handleTouchCancel(
cursor.touch_points.clearRetainingCapacity();
// We can't call touchNotifyCancel() from inside the loop over touch points as it also loops
// over touch points and may destroy multiple touch points in a single call.
//
// What we should do here is `while (touch_points.first()) |point| cancel()` but since the
// surface may be null we can't rely on the fact tha all touch points will be destroyed
// and risk an infinite loop if the surface of any wlr_touch_point is null.
//
// This is all really silly and totally unnecessary since all touchNotifyCancel() does with
// the surface argument is obtain a seat client and touch_point.seat_client is never null.
// TODO(wlroots) clean this up after the wlroots MR fixing this is merged:
// https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4613
// The upper bound of 32 comes from an implementation detail of libinput which uses
// a 32-bit integer as a map to keep track of touch points.
var surfaces: std.BoundedArray(*wlr.Surface, 32) = .{};
{
var it = cursor.seat.wlr_seat.touch_state.touch_points.iterator(.forward);
while (it.next()) |touch_point| {
if (touch_point.surface) |surface| {
surfaces.append(surface) catch break;
}
}
}
for (surfaces.slice()) |surface| {
cursor.seat.wlr_seat.touchNotifyCancel(surface);
const wlr_seat = cursor.seat.wlr_seat;
while (wlr_seat.touch_state.touch_points.first()) |touch_point| {
wlr_seat.touchNotifyCancel(touch_point.client);
}
}
@ -762,8 +774,15 @@ fn handleRequestSetCursor(
// on the output that it's currently on and continue to do so as the
// cursor moves between outputs.
log.debug("focused client set cursor", .{});
cursor.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y);
cursor.xcursor_name = null;
if (event.surface) |surface| {
cursor.setImage(.{ .client = .{
.surface = surface,
.hotspot_x = event.hotspot_x,
.hotspot_y = event.hotspot_y,
} });
} else {
cursor.setImage(.none);
}
}
}
@ -779,8 +798,6 @@ pub fn hide(cursor: *Cursor) void {
cursor.hidden = true;
cursor.wlr_cursor.unsetImage();
cursor.xcursor_name = null;
cursor.seat.wlr_seat.pointerNotifyClearFocus();
cursor.hide_cursor_timer.timerUpdate(0) catch {
log.err("failed to update cursor hide timeout", .{});
};
@ -792,6 +809,7 @@ pub fn unhide(cursor: *Cursor) void {
};
if (!cursor.hidden) return;
cursor.hidden = false;
cursor.setImage(cursor.image);
cursor.updateState();
}
@ -890,7 +908,7 @@ fn computeEdges(cursor: *const Cursor, view: *const View) wlr.Edges {
}
}
fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor_name: [*:0]const u8) void {
fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor: [*:0]const u8) void {
assert(cursor.mode == .passthrough or cursor.mode == .down);
assert(mode == .move or mode == .resize);
@ -906,7 +924,7 @@ fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor_name: [*:0]const
}
cursor.seat.wlr_seat.pointerNotifyClearFocus();
cursor.setXcursor(xcursor_name);
cursor.setImage(.{ .xcursor = xcursor });
server.root.applyPending();
}
@ -1113,8 +1131,13 @@ pub fn updateState(cursor: *Cursor) void {
if (!cursor.hidden) {
var now: posix.timespec = undefined;
posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
const msec: u32 = @intCast(now.tv_sec * std.time.ms_per_s +
@divTrunc(now.tv_nsec, std.time.ns_per_ms));
// 2^32-1 milliseconds is ~50 days, which is a realistic uptime.
// This means that we must wrap if the monotonic time is greater than
// 2^32-1 milliseconds and hope that clients don't get too confused.
const msec: u32 = @intCast(@rem(
now.tv_sec *% std.time.ms_per_s +% @divTrunc(now.tv_nsec, std.time.ns_per_ms),
math.maxInt(u32),
));
cursor.passthrough(msec);
}
},
@ -1200,10 +1223,18 @@ fn warp(cursor: *Cursor) void {
const focused_output = cursor.seat.focused_output orelse return;
var mode = server.config.warp_cursor;
if (cursor.seat.focused == .view) {
const view = cursor.seat.focused.view;
if (server.config.rules.warp.match(view)) |w| {
mode = if (w) .@"on-focus-change" else .disabled;
}
}
// Warp pointer to center of the focused view/output (In layout coordinates) if enabled.
var output_layout_box: wlr.Box = undefined;
server.root.output_layout.getBox(focused_output.wlr_output, &output_layout_box);
const target_box = switch (server.config.warp_cursor) {
const target_box = switch (mode) {
.disabled => return,
.@"on-output-change" => output_layout_box,
.@"on-focus-change" => switch (cursor.seat.focused) {

View File

@ -215,6 +215,18 @@ pub const ScrollButton = struct {
}
};
pub const ScrollButtonLock = enum {
enabled,
disabled,
fn apply(scroll_button_lock: ScrollButtonLock, device: *c.libinput_device) void {
_ = c.libinput_device_config_scroll_set_button_lock(device, switch (scroll_button_lock) {
.enabled => c.LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED,
.disabled => c.LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED,
});
}
};
pub const MapToOutput = struct {
output_name: ?[]const u8,
@ -232,7 +244,7 @@ pub const MapToOutput = struct {
};
switch (device.wlr_device.type) {
.pointer, .touch, .tablet_tool => {
.pointer, .touch, .tablet => {
log.debug("mapping input '{s}' -> '{s}'", .{
device.identifier,
if (wlr_output) |o| o.name else "<no output>",
@ -240,14 +252,14 @@ pub const MapToOutput = struct {
device.seat.cursor.wlr_cursor.mapInputToOutput(device.wlr_device, wlr_output);
if (device.wlr_device.type == .tablet_tool) {
if (device.wlr_device.type == .tablet) {
const tablet: *Tablet = @fieldParentPtr("device", device);
tablet.output_mapping = wlr_output;
}
},
// These devices do not support being mapped to outputs.
.keyboard, .tablet_pad, .switch_device => {},
.keyboard, .tablet_pad, .@"switch" => {},
}
}
};
@ -279,6 +291,7 @@ tap: ?TapState = null,
@"pointer-accel": ?PointerAccel = null,
@"scroll-method": ?ScrollMethod = null,
@"scroll-button": ?ScrollButton = null,
@"scroll-button-lock": ?ScrollButtonLock = null,
@"map-to-output": ?MapToOutput = null,
pub fn deinit(config: *InputConfig) void {

View File

@ -24,6 +24,7 @@ const wl = @import("wayland").server.wl;
const globber = @import("globber");
const c = @import("c.zig");
const server = &@import("main.zig").server;
const util = @import("util.zig");
@ -52,19 +53,21 @@ config: struct {
link: wl.list.Link,
pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !void {
const device_type: []const u8 = switch (wlr_device.type) {
.switch_device => "switch",
.tablet_tool => "tablet",
else => @tagName(wlr_device.type),
};
var vendor: c_uint = 0;
var product: c_uint = 0;
if (wlr_device.getLibinputDevice()) |d| {
vendor = c.libinput_device_get_id_vendor(@ptrCast(d));
product = c.libinput_device_get_id_product(@ptrCast(d));
}
const identifier = try std.fmt.allocPrint(
util.gpa,
"{s}-{}-{}-{s}",
.{
device_type,
wlr_device.vendor,
wlr_device.product,
@tagName(wlr_device.type),
vendor,
product,
mem.trim(u8, mem.sliceTo(wlr_device.name orelse "unknown", 0), &ascii.whitespace),
},
);
@ -139,11 +142,11 @@ fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice)
device.deinit();
util.gpa.destroy(device);
},
.tablet_tool => {
.tablet => {
const tablet: *Tablet = @fieldParentPtr("device", device);
tablet.destroy();
},
.switch_device => {
.@"switch" => {
const switch_device: *Switch = @fieldParentPtr("device", device);
switch_device.deinit();
util.gpa.destroy(switch_device);

View File

@ -101,16 +101,9 @@ pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice) !voi
// wlroots will log a more detailed error if this fails.
if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory;
// Add to keyboard-group, if applicable.
var group_it = seat.keyboard_groups.first;
outer: while (group_it) |group_node| : (group_it = group_node.next) {
for (group_node.data.globs.items) |glob| {
if (globber.match(glob, keyboard.device.identifier)) {
// wlroots will log an error if this fails explaining the reason.
_ = group_node.data.wlr_group.addKeyboard(wlr_keyboard);
break :outer;
}
}
if (wlr.KeyboardGroup.fromKeyboard(wlr_keyboard) == null) {
// wlroots will log an error on failure
_ = seat.keyboard_group.addKeyboard(wlr_keyboard);
}
wlr_keyboard.setRepeatInfo(server.config.repeat_rate, server.config.repeat_delay);

View File

@ -1,141 +0,0 @@
// This file is part of river, a dynamic tiling wayland compositor.
//
// Copyright 2022 The River Developers
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, version 3.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const KeyboardGroup = @This();
const std = @import("std");
const assert = std.debug.assert;
const mem = std.mem;
const globber = @import("globber");
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const xkb = @import("xkbcommon");
const log = std.log.scoped(.keyboard_group);
const server = &@import("main.zig").server;
const util = @import("util.zig");
const Seat = @import("Seat.zig");
const Keyboard = @import("Keyboard.zig");
seat: *Seat,
wlr_group: *wlr.KeyboardGroup,
name: []const u8,
globs: std.ArrayListUnmanaged([]const u8) = .{},
pub fn create(seat: *Seat, name: []const u8) !void {
log.debug("new keyboard group: '{s}'", .{name});
const node = try util.gpa.create(std.TailQueue(KeyboardGroup).Node);
errdefer util.gpa.destroy(node);
const wlr_group = try wlr.KeyboardGroup.create();
errdefer wlr_group.destroy();
const owned_name = try util.gpa.dupe(u8, name);
errdefer util.gpa.free(owned_name);
node.data = .{
.wlr_group = wlr_group,
.name = owned_name,
.seat = seat,
};
seat.addDevice(&wlr_group.keyboard.base);
seat.keyboard_groups.append(node);
}
pub fn destroy(group: *KeyboardGroup) void {
log.debug("destroying keyboard group: '{s}'", .{group.name});
util.gpa.free(group.name);
for (group.globs.items) |glob| {
util.gpa.free(glob);
}
group.globs.deinit(util.gpa);
group.wlr_group.destroy();
const node: *std.TailQueue(KeyboardGroup).Node = @fieldParentPtr("data", group);
group.seat.keyboard_groups.remove(node);
util.gpa.destroy(node);
}
pub fn addIdentifier(group: *KeyboardGroup, new_id: []const u8) !void {
for (group.globs.items) |glob| {
if (mem.eql(u8, glob, new_id)) return;
}
log.debug("keyboard group '{s}' adding identifier: '{s}'", .{ group.name, new_id });
const owned_id = try util.gpa.dupe(u8, new_id);
errdefer util.gpa.free(owned_id);
// Glob is validated in the command handler.
try group.globs.append(util.gpa, owned_id);
errdefer {
// Not used now, but if at any point this function is modified to that
// it may return an error after the glob pattern is added to the list,
// the list will have a pointer to freed memory in its last position.
_ = group.globs.pop();
}
// Add any existing matching keyboards to the group.
var it = server.input_manager.devices.iterator(.forward);
while (it.next()) |device| {
if (device.seat != group.seat) continue;
if (device.wlr_device.type != .keyboard) continue;
if (globber.match(device.identifier, new_id)) {
log.debug("found existing matching keyboard; adding to group", .{});
if (!group.wlr_group.addKeyboard(device.wlr_device.toKeyboard())) {
// wlroots logs an error message to explain why this failed.
continue;
}
}
// Continue, because we may have more than one device with the exact
// same identifier. That is in fact one reason for the keyboard group
// feature to exist in the first place.
}
}
pub fn removeIdentifier(group: *KeyboardGroup, id: []const u8) !void {
for (group.globs.items, 0..) |glob, index| {
if (mem.eql(u8, glob, id)) {
_ = group.globs.orderedRemove(index);
break;
}
} else {
return;
}
var it = server.input_manager.devices.iterator(.forward);
while (it.next()) |device| {
if (device.seat != group.seat) continue;
if (device.wlr_device.type != .keyboard) continue;
if (globber.match(device.identifier, id)) {
const wlr_keyboard = device.wlr_device.toKeyboard();
assert(wlr_keyboard.group == group.wlr_group);
group.wlr_group.removeKeyboard(wlr_keyboard);
}
}
}

View File

@ -66,11 +66,6 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
wlr_layer_surface.surface.events.unmap.add(&layer_surface.unmap);
wlr_layer_surface.surface.events.commit.add(&layer_surface.commit);
wlr_layer_surface.events.new_popup.add(&layer_surface.new_popup);
// wlroots only informs us of the new surface after the first commit,
// so our listener does not get called for this first commit. However,
// we do want our listener called in order to send the initial configure.
handleCommit(&layer_surface.commit, wlr_layer_surface.surface);
}
pub fn destroyPopups(layer_surface: *LayerSurface) void {
@ -100,11 +95,19 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa
fn handleMap(listener: *wl.Listener(void)) void {
const layer_surface: *LayerSurface = @fieldParentPtr("map", listener);
const wlr_surface = layer_surface.wlr_layer_surface;
log.debug("layer surface '{s}' mapped", .{layer_surface.wlr_layer_surface.namespace});
log.debug("layer surface '{s}' mapped", .{wlr_surface.namespace});
layer_surface.output.arrangeLayers();
handleKeyboardInteractiveExclusive(layer_surface.output);
const consider = wlr_surface.current.keyboard_interactive == .on_demand and
(wlr_surface.current.layer == .top or wlr_surface.current.layer == .overlay);
handleKeyboardInteractiveExclusive(
layer_surface.output,
if (consider) layer_surface else null,
);
server.root.applyPending();
}
@ -114,7 +117,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
log.debug("layer surface '{s}' unmapped", .{layer_surface.wlr_layer_surface.namespace});
layer_surface.output.arrangeLayers();
handleKeyboardInteractiveExclusive(layer_surface.output);
handleKeyboardInteractiveExclusive(layer_surface.output, null);
server.root.applyPending();
}
@ -134,18 +137,20 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
@as(u32, @bitCast(wlr_layer_surface.current.committed)) != 0)
{
layer_surface.output.arrangeLayers();
handleKeyboardInteractiveExclusive(layer_surface.output);
handleKeyboardInteractiveExclusive(layer_surface.output, null);
server.root.applyPending();
}
}
/// Focus topmost keyboard-interactivity-exclusive layer surface above normal
/// content, or if none found, focus the surface given as `consider`.
/// Requires a call to Root.applyPending()
fn handleKeyboardInteractiveExclusive(output: *Output) void {
fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) void {
if (server.lock_manager.state != .unlocked) return;
// Find the topmost layer surface in the top or overlay layers which
// requests keyboard interactivity if any.
const topmost_surface = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| {
// Find the topmost layer surface (if any) in the top or overlay layers which
// requests exclusive keyboard interactivity.
const to_focus = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| {
const tree = output.layerSurfaceTree(layer);
// Iterate in reverse to match rendering order.
var it = tree.children.iterator(.reverse);
@ -161,17 +166,21 @@ fn handleKeyboardInteractiveExclusive(output: *Output) void {
}
}
}
} else null;
} else consider;
if (to_focus) |s| {
assert(s.wlr_layer_surface.current.keyboard_interactive != .none);
}
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
if (seat.focused_output == output) {
if (topmost_surface) |to_focus| {
if (to_focus) |s| {
// If we found a surface on the output that requires focus, grab the focus of all
// seats that are focusing that output.
seat.setFocusRaw(.{ .layer = to_focus });
seat.setFocusRaw(.{ .layer = s });
continue;
}
}

View File

@ -367,6 +367,8 @@ fn sendLayerConfigures(
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
const layer_surface = node_data.data.layer_surface;
if (!layer_surface.wlr_layer_surface.initialized) continue;
const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0;
if (exclusive != (mode == .exclusive)) {
continue;
@ -391,11 +393,15 @@ fn sendLayerConfigures(
usable_box.* = new_usable_box;
}
layer_surface.popup_tree.node.setPosition(
layer_surface.scene_layer_surface.tree.node.x,
layer_surface.scene_layer_surface.tree.node.y,
);
layer_surface.scene_layer_surface.tree.node.subsurfaceTreeSetClip(&full_box);
const x = layer_surface.scene_layer_surface.tree.node.x;
const y = layer_surface.scene_layer_surface.tree.node.y;
layer_surface.popup_tree.node.setPosition(x, y);
layer_surface.scene_layer_surface.tree.node.subsurfaceTreeSetClip(&.{
.x = -x,
.y = -y,
.width = full_box.width,
.height = full_box.height,
});
}
}
}
@ -474,6 +480,7 @@ pub fn applyState(output: *Output, state: *wlr.Output.State) error{CommitFailed}
fn handleEnableDisable(output: *Output) void {
output.updateLockRenderStateOnEnableDisable();
output.gamma_dirty = true;
if (output.wlr_output.enabled) {
// Add the output to root.active_outputs and the output layout if it has not
@ -535,28 +542,50 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
}
fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void {
if (output.gamma_dirty) {
var state = wlr.Output.State.init();
defer state.finish();
if (server.root.gamma_control_manager.getControl(output.wlr_output)) |control| {
log.info("applying gamma settings from client", .{});
if (!control.apply(&state)) return error.OutOfMemory;
} else {
log.info("clearing gamma settings from client", .{});
state.clearGammaLut();
}
if (!scene_output.buildState(&state, null)) return error.CommitFailed;
if (!output.wlr_output.commitState(&state)) return error.CommitFailed;
scene_output.damage_ring.rotate();
output.gamma_dirty = false;
} else {
if (!scene_output.commit(null)) return error.CommitFailed;
// TODO(wlroots): replace this with wlr_scene_output_needs_frame()
if (!output.wlr_output.needs_frame and !output.gamma_dirty and
!scene_output.pending_commit_damage.notEmpty())
{
return;
}
var state = wlr.Output.State.init();
defer state.finish();
if (!scene_output.buildState(&state, null)) return error.CommitFailed;
if (output.gamma_dirty) {
const control = server.root.gamma_control_manager.getControl(output.wlr_output);
if (!wlr.GammaControlV1.apply(control, &state)) return error.OutOfMemory;
// TODO(wlroots): remove this isHeadless() workaround after upstream fix is available
// in a release: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4868
if (!output.wlr_output.testState(&state) or output.wlr_output.isHeadless()) {
wlr.GammaControlV1.sendFailedAndDestroy(control);
state.clearGammaLut();
// If the backend does not support gamma LUTs it will reject any
// state with the gamma LUT committed bit set even if the state
// has a null LUT. The wayland backend for example has this behavior.
state.committed.gamma_lut = false;
}
}
if (output.current.fullscreen) |fullscreen| {
if (fullscreen.allowTearing()) {
state.tearing_page_flip = true;
if (!output.wlr_output.testState(&state)) {
log.debug("tearing page flip test failed for {s}, retrying without tearing", .{
output.wlr_output.name,
});
state.tearing_page_flip = false;
}
}
}
if (!output.wlr_output.commitState(&state)) return error.CommitFailed;
output.gamma_dirty = false;
if (server.lock_manager.state == .locked or
(server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or
server.lock_manager.state == .waiting_for_blank)

View File

@ -42,7 +42,7 @@ state: union(enum) {
} = .inactive,
destroy: wl.Listener(*wlr.PointerConstraintV1) = wl.Listener(*wlr.PointerConstraintV1).init(handleDestroy),
set_region: wl.Listener(void) = wl.Listener(void).init(handleSetRegion),
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy),
@ -58,7 +58,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
wlr_constraint.data = @intFromPtr(constraint);
wlr_constraint.events.destroy.add(&constraint.destroy);
wlr_constraint.events.set_region.add(&constraint.set_region);
wlr_constraint.surface.events.commit.add(&constraint.commit);
if (seat.wlr_seat.keyboard_state.focused_surface) |surface| {
if (surface == wlr_constraint.surface) {
@ -169,7 +169,7 @@ pub fn deactivate(constraint: *PointerConstraint) void {
fn warpToHintIfSet(constraint: *PointerConstraint) void {
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
if (constraint.wlr_constraint.current.committed.cursor_hint) {
if (constraint.wlr_constraint.current.cursor_hint.enabled) {
var lx: i32 = undefined;
var ly: i32 = undefined;
_ = constraint.state.active.node.coords(&lx, &ly);
@ -201,7 +201,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point
}
constraint.destroy.link.remove();
constraint.set_region.link.remove();
constraint.commit.link.remove();
if (seat.cursor.constraint == constraint) {
seat.cursor.constraint = null;
@ -210,8 +210,11 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point
util.gpa.destroy(constraint);
}
fn handleSetRegion(listener: *wl.Listener(void)) void {
const constraint: *PointerConstraint = @fieldParentPtr("set_region", listener);
// It is necessary to listen for the commit event rather than the set_region
// event as the latter is not triggered by wlroots when the input region of
// the surface changes.
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const constraint: *PointerConstraint = @fieldParentPtr("commit", listener);
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
switch (constraint.state) {
@ -219,7 +222,7 @@ fn handleSetRegion(listener: *wl.Listener(void)) void {
const sx: i32 = @intFromFloat(state.sx);
const sy: i32 = @intFromFloat(state.sy);
if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) {
log.info("deactivating pointer constraint, region change left pointer outside constraint", .{});
log.info("deactivating pointer constraint, (input) region change left pointer outside constraint", .{});
constraint.deactivate();
}
},

View File

@ -117,7 +117,7 @@ transaction_timeout: *wl.EventSource,
pending_state_dirty: bool = false,
pub fn init(root: *Root) !void {
const output_layout = try wlr.OutputLayout.create();
const output_layout = try wlr.OutputLayout.create(server.wl_server);
errdefer output_layout.destroy();
const scene = try wlr.Scene.create();
@ -131,9 +131,6 @@ pub fn init(root: *Root) !void {
const outputs = try interactive_content.createSceneTree();
const override_redirect = if (build_options.xwayland) try interactive_content.createSceneTree();
const presentation = try wlr.Presentation.create(server.wl_server, server.backend);
scene.setPresentation(presentation);
const event_loop = server.wl_server.getEventLoop();
const transaction_timeout = try event_loop.addTimer(*Root, handleTransactionTimeout, root);
errdefer transaction_timeout.remove();
@ -166,7 +163,7 @@ pub fn init(root: *Root) !void {
.all_outputs = undefined,
.active_outputs = undefined,
.presentation = presentation,
.presentation = try wlr.Presentation.create(server.wl_server, server.backend),
.xdg_output_manager = try wlr.XdgOutputManagerV1.create(server.wl_server, output_layout),
.output_manager = try wlr.OutputManagerV1.create(server.wl_server),
.power_manager = try wlr.OutputPowerManagerV1.create(server.wl_server),
@ -676,24 +673,12 @@ fn commitTransaction(root: *Root) void {
while (focus_stack_it.next()) |view| {
assert(view.inflight.output == output);
if (view.current.output != view.inflight.output or
(output.current.fullscreen == view and output.inflight.fullscreen != view))
{
if (view.inflight.float) {
view.tree.node.reparent(output.layers.float);
} else {
view.tree.node.reparent(output.layers.layout);
}
view.popup_tree.node.reparent(output.layers.popups);
}
if (view.current.float != view.inflight.float) {
if (view.inflight.float) {
view.tree.node.reparent(output.layers.float);
} else {
view.tree.node.reparent(output.layers.layout);
}
if (view.inflight.float) {
view.tree.node.reparent(output.layers.float);
} else {
view.tree.node.reparent(output.layers.layout);
}
view.popup_tree.node.reparent(output.layers.popups);
view.commitTransaction();
@ -706,15 +691,13 @@ fn commitTransaction(root: *Root) void {
}
}
if (output.inflight.fullscreen != output.current.fullscreen) {
if (output.inflight.fullscreen) |view| {
assert(view.inflight.output == output);
assert(view.current.output == output);
view.tree.node.reparent(output.layers.fullscreen);
}
output.current.fullscreen = output.inflight.fullscreen;
output.layers.fullscreen.node.setEnabled(output.current.fullscreen != null);
if (output.inflight.fullscreen) |view| {
assert(view.inflight.output == output);
assert(view.current.output == output);
view.tree.node.reparent(output.layers.fullscreen);
}
output.current.fullscreen = output.inflight.fullscreen;
output.layers.fullscreen.node.setEnabled(output.current.fullscreen != null);
output.status.handleTransactionCommit(output);
}
@ -897,6 +880,7 @@ fn handlePowerManagerSetMode(
}
output.updateLockRenderStateOnEnableDisable();
output.gamma_dirty = true;
}
fn handleSetGamma(

View File

@ -33,7 +33,6 @@ const InputDevice = @import("InputDevice.zig");
const InputManager = @import("InputManager.zig");
const InputRelay = @import("InputRelay.zig");
const Keyboard = @import("Keyboard.zig");
const KeyboardGroup = @import("KeyboardGroup.zig");
const LayerSurface = @import("LayerSurface.zig");
const LockSurface = @import("LockSurface.zig");
const Mapping = @import("Mapping.zig");
@ -84,7 +83,7 @@ mapping_repeat_timer: *wl.EventSource,
/// Currently repeating mapping, if any
repeating_mapping: ?*const Mapping = null,
keyboard_groups: std.TailQueue(KeyboardGroup) = .{},
keyboard_group: *wlr.KeyboardGroup,
/// Currently focused output. Null only when there are no outputs at all.
focused_output: ?*Output = null,
@ -121,12 +120,15 @@ pub fn init(seat: *Seat, name: [*:0]const u8) !void {
.cursor = undefined,
.relay = undefined,
.mapping_repeat_timer = mapping_repeat_timer,
.keyboard_group = try wlr.KeyboardGroup.create(),
};
seat.wlr_seat.data = @intFromPtr(seat);
try seat.cursor.init(seat);
seat.relay.init();
try seat.tryAddDevice(&seat.keyboard_group.keyboard.base);
seat.wlr_seat.events.request_set_selection.add(&seat.request_set_selection);
seat.wlr_seat.events.request_start_drag.add(&seat.request_start_drag);
seat.wlr_seat.events.start_drag.add(&seat.start_drag);
@ -142,9 +144,7 @@ pub fn deinit(seat: *Seat) void {
seat.cursor.deinit();
seat.mapping_repeat_timer.remove();
while (seat.keyboard_groups.first) |node| {
node.data.destroy();
}
seat.keyboard_group.destroy();
seat.request_set_selection.link.remove();
seat.request_start_drag.link.remove();
@ -165,14 +165,21 @@ pub fn focus(seat: *Seat, _target: ?*View) void {
// Views may not receive focus while locked.
if (server.lock_manager.state != .unlocked) return;
// While a layer surface is exclusively focused, views may not receive focus
// A layer surface with exclusive focus will prevent any view from gaining
// focus if it is on the top or overlay layer. Otherwise, only steal focus
// from a focused layer surface if there is an explicit target view.
if (seat.focused == .layer) {
const wlr_layer_surface = seat.focused.layer.wlr_layer_surface;
assert(wlr_layer_surface.surface.mapped);
if (wlr_layer_surface.current.keyboard_interactive == .exclusive and
(wlr_layer_surface.current.layer == .top or wlr_layer_surface.current.layer == .overlay))
{
return;
switch (wlr_layer_surface.current.keyboard_interactive) {
.none => {},
.exclusive => switch (wlr_layer_surface.current.layer) {
.top, .overlay => return,
.bottom, .background => if (target == null) return,
_ => {},
},
.on_demand => if (target == null) return,
_ => {},
}
}
@ -504,11 +511,11 @@ fn tryAddDevice(seat: *Seat, wlr_device: *wlr.InputDevice) !void {
seat.cursor.wlr_cursor.attachInputDevice(wlr_device);
},
.tablet_tool => {
.tablet => {
try Tablet.create(seat, wlr_device);
seat.cursor.wlr_cursor.attachInputDevice(wlr_device);
},
.switch_device => {
.@"switch" => {
const switch_device = try util.gpa.create(Switch);
errdefer util.gpa.destroy(switch_device);
@ -531,7 +538,7 @@ pub fn updateCapabilities(seat: *Seat) void {
switch (device.wlr_device.type) {
.keyboard => capabilities.keyboard = true,
.touch => capabilities.touch = true,
.pointer, .switch_device, .tablet_tool => {},
.pointer, .@"switch", .tablet => {},
.tablet_pad => unreachable,
}
}

View File

@ -19,6 +19,7 @@ const Server = @This();
const build_options = @import("build_options");
const std = @import("std");
const assert = std.debug.assert;
const mem = std.mem;
const posix = std.posix;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
@ -38,6 +39,7 @@ const Root = @import("Root.zig");
const Seat = @import("Seat.zig");
const SceneNodeData = @import("SceneNodeData.zig");
const StatusManager = @import("StatusManager.zig");
const TabletTool = @import("TabletTool.zig");
const XdgDecoration = @import("XdgDecoration.zig");
const XdgToplevel = @import("XdgToplevel.zig");
const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig");
@ -83,6 +85,10 @@ screencopy_manager: *wlr.ScreencopyManagerV1,
foreign_toplevel_manager: *wlr.ForeignToplevelManagerV1,
tearing_control_manager: *wlr.TearingControlManagerV1,
alpha_modifier: *wlr.AlphaModifierV1,
input_manager: InputManager,
root: Root,
config: Config,
@ -96,8 +102,10 @@ xwayland: if (build_options.xwayland) ?*wlr.Xwayland else void = if (build_optio
new_xwayland_surface: if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface) else void =
if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface).init(handleNewXwaylandSurface),
new_xdg_surface: wl.Listener(*wlr.XdgSurface) =
wl.Listener(*wlr.XdgSurface).init(handleNewXdgSurface),
renderer_lost: wl.Listener(void) = wl.Listener(void).init(handleRendererLost),
new_xdg_toplevel: wl.Listener(*wlr.XdgToplevel) =
wl.Listener(*wlr.XdgToplevel).init(handleNewXdgToplevel),
new_toplevel_decoration: wl.Listener(*wlr.XdgToplevelDecorationV1) =
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleNewToplevelDecoration),
new_layer_surface: wl.Listener(*wlr.LayerSurfaceV1) =
@ -113,14 +121,14 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
// This keeps the code simpler and more readable.
const wl_server = try wl.Server.create();
const loop = wl_server.getEventLoop();
var session: ?*wlr.Session = undefined;
const backend = try wlr.Backend.autocreate(wl_server, &session);
const backend = try wlr.Backend.autocreate(loop, &session);
const renderer = try wlr.Renderer.autocreate(backend);
const compositor = try wlr.Compositor.create(wl_server, 6, renderer);
const loop = wl_server.getEventLoop();
server.* = .{
.wl_server = wl_server,
.sigint_source = try loop.addSignal(*wl.Server, posix.SIG.INT, terminate, wl_server),
@ -156,6 +164,10 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
.foreign_toplevel_manager = try wlr.ForeignToplevelManagerV1.create(wl_server),
.tearing_control_manager = try wlr.TearingControlManagerV1.create(wl_server, 1),
.alpha_modifier = try wlr.AlphaModifierV1.create(wl_server),
.config = try Config.init(),
.root = undefined,
@ -167,7 +179,7 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
.lock_manager = undefined,
};
if (renderer.getDmabufFormats() != null and renderer.getDrmFd() >= 0) {
if (renderer.getTextureFormats(@intFromEnum(wlr.BufferCap.dmabuf)) != null) {
// wl_drm is a legacy interface and all clients should switch to linux_dmabuf.
// However, enough widely used clients still rely on wl_drm that the pragmatic option
// is to keep it around for the near future.
@ -190,7 +202,8 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
try server.idle_inhibit_manager.init();
try server.lock_manager.init();
server.xdg_shell.events.new_surface.add(&server.new_xdg_surface);
server.renderer.events.lost.add(&server.renderer_lost);
server.xdg_shell.events.new_toplevel.add(&server.new_xdg_toplevel);
server.xdg_decoration_manager.events.new_toplevel_decoration.add(&server.new_toplevel_decoration);
server.layer_shell.events.new_surface.add(&server.new_layer_surface);
server.xdg_activation.events.request_activate.add(&server.request_activate);
@ -204,7 +217,8 @@ pub fn deinit(server: *Server) void {
server.sigint_source.remove();
server.sigterm_source.remove();
server.new_xdg_surface.link.remove();
server.renderer_lost.link.remove();
server.new_xdg_toplevel.link.remove();
server.new_toplevel_decoration.link.remove();
server.new_layer_surface.link.remove();
server.request_activate.link.remove();
@ -277,14 +291,6 @@ fn globalFilter(client: *const wl.Client, global: *const wl.Global, server: *Ser
}
}
fn hackGlobal(ptr: *anyopaque) *wl.Global {
// TODO(wlroots) MR that eliminates the need for this hack:
// https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4612
if (wlr.version.major != 0 or wlr.version.minor != 17) @compileError("FIXME");
return @as(*extern struct { global: *wl.Global }, @alignCast(@ptrCast(ptr))).global;
}
/// Returns true if the global is allowlisted for security contexts
fn allowlist(server: *Server, global: *const wl.Global) bool {
if (server.drm) |drm| if (global == drm.global) return true;
@ -294,14 +300,17 @@ fn allowlist(server: *Server, global: *const wl.Global) bool {
// such as wl_output and wl_seat since the wl_global_create() function will
// advertise the global to clients and invoke this filter before returning
// the new global pointer.
//
if ((mem.orderZ(u8, global.getInterface().name, "wl_output") == .eq) or
(mem.orderZ(u8, global.getInterface().name, "wl_seat") == .eq))
{
return true;
}
// For other globals I like the current pointer comparison approach as it
// should catch river accidentally exposing multiple copies of e.g. wl_shm
// with an assertion failure.
return global.getInterface() == wl.Output.getInterface() or
global.getInterface() == wl.Seat.getInterface() or
global == hackGlobal(server.shm) or
global == hackGlobal(server.single_pixel_buffer_manager) or
return global == server.shm.global or
global == server.single_pixel_buffer_manager.global or
global == server.viewporter.global or
global == server.fractional_scale_manager.global or
global == server.compositor.global or
@ -319,7 +328,9 @@ fn allowlist(server: *Server, global: *const wl.Global) bool {
global == server.input_manager.text_input_manager.global or
global == server.input_manager.tablet_manager.global or
global == server.input_manager.pointer_gestures.global or
global == server.idle_inhibit_manager.wlr_manager.global;
global == server.idle_inhibit_manager.wlr_manager.global or
global == server.tearing_control_manager.global or
global == server.alpha_modifier.global;
}
/// Returns true if the global is blocked for security contexts
@ -336,7 +347,7 @@ fn blocklist(server: *Server, global: *const wl.Global) bool {
global == server.root.output_manager.global or
global == server.root.power_manager.global or
global == server.root.gamma_control_manager.global or
global == hackGlobal(server.input_manager.idle_notifier) or
global == server.input_manager.idle_notifier.global or
global == server.input_manager.virtual_pointer_manager.global or
global == server.input_manager.virtual_keyboard_manager.global or
global == server.input_manager.input_method_manager.global or
@ -349,17 +360,55 @@ fn terminate(_: c_int, wl_server: *wl.Server) c_int {
return 0;
}
fn handleNewXdgSurface(_: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurface) void {
if (xdg_surface.role == .popup) {
log.debug("new xdg_popup", .{});
return;
fn handleRendererLost(listener: *wl.Listener(void)) void {
const server: *Server = @fieldParentPtr("renderer_lost", listener);
log.info("recovering from GPU reset", .{});
// There's not much that can be done if creating a new renderer or allocator fails.
// With luck there might be another GPU reset after which we try again and succeed.
server.recoverFromGpuReset() catch |err| switch (err) {
error.RendererCreateFailed => log.err("failed to create new renderer after GPU reset", .{}),
error.AllocatorCreateFailed => log.err("failed to create new allocator after GPU reset", .{}),
};
}
fn recoverFromGpuReset(server: *Server) !void {
const new_renderer = try wlr.Renderer.autocreate(server.backend);
errdefer new_renderer.destroy();
const new_allocator = try wlr.Allocator.autocreate(server.backend, new_renderer);
errdefer comptime unreachable; // no failure allowed after this point
server.renderer_lost.link.remove();
new_renderer.events.lost.add(&server.renderer_lost);
server.compositor.setRenderer(new_renderer);
{
var it = server.root.all_outputs.iterator(.forward);
while (it.next()) |output| {
// This should never fail here as failure with this combination of
// renderer, allocator, and backend should have prevented creating
// the output in the first place.
_ = output.wlr_output.initRender(new_allocator, new_renderer);
}
}
server.renderer.destroy();
server.renderer = new_renderer;
server.allocator.destroy();
server.allocator = new_allocator;
}
fn handleNewXdgToplevel(_: *wl.Listener(*wlr.XdgToplevel), xdg_toplevel: *wlr.XdgToplevel) void {
log.debug("new xdg_toplevel", .{});
XdgToplevel.create(xdg_surface.role_data.toplevel.?) catch {
XdgToplevel.create(xdg_toplevel) catch {
log.err("out of memory", .{});
xdg_surface.resource.postNoMemory();
xdg_toplevel.resource.postNoMemory();
return;
};
}
@ -450,17 +499,27 @@ fn handleRequestSetCursorShape(
_: *wl.Listener(*wlr.CursorShapeManagerV1.event.RequestSetShape),
event: *wlr.CursorShapeManagerV1.event.RequestSetShape,
) void {
// Ignore requests to set a tablet tool's cursor shape for now
// TODO(wlroots): https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3821
if (event.device_type == .tablet_tool) return;
const seat: *Seat = @ptrFromInt(event.seat_client.seat.data);
const focused_client = event.seat_client.seat.pointer_state.focused_client;
if (event.tablet_tool) |wp_tool| {
assert(event.device_type == .tablet_tool);
// This can be sent by any client, so we check to make sure this one is
// actually has pointer focus first.
if (focused_client == event.seat_client) {
const seat: *Seat = @ptrFromInt(event.seat_client.seat.data);
const name = wlr.CursorShapeManagerV1.shapeName(event.shape);
seat.cursor.setXcursor(name);
const tool = TabletTool.get(event.seat_client.seat, wp_tool.wlr_tool) catch return;
if (tool.allowSetCursor(event.seat_client, event.serial)) {
const name = wlr.CursorShapeManagerV1.shapeName(event.shape);
tool.wlr_cursor.setXcursor(seat.cursor.xcursor_manager, name);
}
} else {
assert(event.device_type == .pointer);
const focused_client = event.seat_client.seat.pointer_state.focused_client;
// This can be sent by any client, so we check to make sure this one is
// actually has pointer focus first.
if (focused_client == event.seat_client) {
const name = wlr.CursorShapeManagerV1.shapeName(event.shape);
seat.cursor.setImage(.{ .xcursor = name });
}
}
}

View File

@ -33,7 +33,7 @@ wp_tablet: *wlr.TabletV2Tablet,
output_mapping: ?*wlr.Output = null,
pub fn create(seat: *Seat, wlr_device: *wlr.InputDevice) !void {
assert(wlr_device.type == .tablet_tool);
assert(wlr_device.type == .tablet);
const tablet = try util.gpa.create(Tablet);
errdefer util.gpa.destroy(tablet);

View File

@ -102,24 +102,29 @@ fn handleDestroy(listener: *wl.Listener(*wlr.TabletTool), _: *wlr.TabletTool) vo
util.gpa.destroy(tool);
}
pub fn allowSetCursor(tool: *TabletTool, seat_client: *wlr.Seat.Client, serial: u32) bool {
if (tool.wp_tool.focused_surface == null or
tool.wp_tool.focused_surface.?.resource.getClient() != seat_client.client)
{
log.debug("client tried to set cursor without focus", .{});
return false;
}
if (serial != tool.wp_tool.proximity_serial) {
log.debug("focused client tried to set cursor with incorrect serial", .{});
return false;
}
return true;
}
fn handleSetCursor(
listener: *wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor),
event: *wlr.TabletV2TabletTool.event.SetCursor,
) void {
const tool: *TabletTool = @fieldParentPtr("set_cursor", listener);
if (tool.wp_tool.focused_surface == null or
tool.wp_tool.focused_surface.?.resource.getClient() != event.seat_client.client)
{
log.debug("client tried to set cursor without focus", .{});
return;
if (tool.allowSetCursor(event.seat_client, event.serial)) {
tool.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y);
}
if (event.serial != tool.wp_tool.proximity_serial) {
log.debug("focused client tried to set cursor with incorrect serial", .{});
return;
}
tool.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y);
}
pub fn axis(tool: *TabletTool, tablet: *Tablet, event: *wlr.Tablet.event.Axis) void {

View File

@ -23,6 +23,7 @@ const math = std.math;
const posix = std.posix;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const wp = @import("wayland").server.wp;
const server = &@import("main.zig").server;
const util = @import("util.zig");
@ -59,6 +60,12 @@ const AttachRelativeMode = enum {
below,
};
const TearingMode = enum {
no_tearing,
tearing,
window_hint,
};
pub const State = struct {
/// The output the view is currently assigned to.
/// May be null if there are no outputs or for newly created views.
@ -177,6 +184,8 @@ foreign_toplevel_handle: ForeignToplevelHandle = .{},
/// Connector name of the output this view occupied before an evacuation.
output_before_evac: ?[]const u8 = null,
tearing_mode: TearingMode = .window_hint,
pub fn create(impl: Impl) error{OutOfMemory}!*View {
assert(impl != .none);
@ -572,6 +581,22 @@ pub fn getAppId(view: View) ?[*:0]const u8 {
};
}
/// Return true if tearing should be allowed for the view.
pub fn allowTearing(view: *View) bool {
switch (view.tearing_mode) {
.no_tearing => return false,
.tearing => return true,
.window_hint => {
if (server.config.allow_tearing) {
if (view.rootSurface()) |root_surface| {
return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async";
}
}
return false;
},
}
}
/// Clamp the width/height of the box to the constraints of the view
pub fn applyConstraints(view: *View, box: *wlr.Box) void {
box.width = math.clamp(box.width, view.constraints.min_width, view.constraints.max_width);
@ -640,6 +665,10 @@ pub fn map(view: *View) !void {
view.pending.ssd = ssd;
}
if (server.config.rules.tearing.match(view)) |tearing| {
view.tearing_mode = if (tearing) .tearing else .no_tearing;
}
if (server.config.rules.dimensions.match(view)) |dimensions| {
view.pending.box.width = dimensions.width;
view.pending.box.height = dimensions.height;
@ -649,8 +678,18 @@ pub fn map(view: *View) !void {
server.input_manager.defaultSeat().focused_output;
if (server.config.rules.position.match(view)) |position| {
view.pending.box.x = position.x;
view.pending.box.y = position.y;
var base_x: i31 = 0;
var base_y: i31 = 0;
switch (position.anchor) {
.absolute => {},
.mouse => {
const cursor = server.input_manager.defaultSeat().wlr_seat.pointer_state;
base_x = @intCast(@as(i31, @intFromFloat(cursor.sx)));
base_y = @intCast(@as(i31, @intFromFloat(cursor.sy)));
},
}
view.pending.box.x = base_x + position.x;
view.pending.box.y = base_y + position.y;
} else if (output) |o| {
// Center the initial pending box on the output
view.pending.box.x = @divTrunc(@max(0, o.usable_box.width - view.pending.box.width), 2);

View File

@ -42,14 +42,9 @@ pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
wlr_decoration.events.destroy.add(&decoration.destroy);
wlr_decoration.events.request_mode.add(&decoration.request_mode);
const ssd = server.config.rules.ssd.match(toplevel.view) orelse
(decoration.wlr_decoration.requested_mode != .client_side);
// TODO(wlroots): make sure this is properly batched in a single configure
// with all other initial state when wlroots makes this possible.
_ = wlr_decoration.setMode(if (ssd) .server_side else .client_side);
toplevel.view.pending.ssd = ssd;
if (toplevel.wlr_toplevel.base.initialized) {
handleRequestMode(&decoration.request_mode, wlr_decoration);
}
}
pub fn deinit(decoration: *XdgDecoration) void {

View File

@ -35,6 +35,7 @@ root: *wlr.SceneTree,
tree: *wlr.SceneTree,
destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy),
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
reposition: wl.Listener(void) = wl.Listener(void).init(handleReposition),
@ -53,23 +54,31 @@ pub fn create(
.tree = try parent.createSceneXdgSurface(wlr_xdg_popup.base),
};
wlr_xdg_popup.base.events.destroy.add(&xdg_popup.destroy);
wlr_xdg_popup.events.destroy.add(&xdg_popup.destroy);
wlr_xdg_popup.base.surface.events.commit.add(&xdg_popup.commit);
wlr_xdg_popup.base.events.new_popup.add(&xdg_popup.new_popup);
wlr_xdg_popup.events.reposition.add(&xdg_popup.reposition);
handleReposition(&xdg_popup.reposition);
}
fn handleDestroy(listener: *wl.Listener(void)) void {
const xdg_popup: *XdgPopup = @fieldParentPtr("destroy", listener);
xdg_popup.destroy.link.remove();
xdg_popup.commit.link.remove();
xdg_popup.new_popup.link.remove();
xdg_popup.reposition.link.remove();
util.gpa.destroy(xdg_popup);
}
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const xdg_popup: *XdgPopup = @fieldParentPtr("commit", listener);
if (xdg_popup.wlr_xdg_popup.base.initial_commit) {
handleReposition(&xdg_popup.reposition);
}
}
fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void {
const xdg_popup: *XdgPopup = @fieldParentPtr("new_popup", listener);

View File

@ -62,12 +62,12 @@ configure_state: union(enum) {
destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy),
map: wl.Listener(void) = wl.Listener(void).init(handleMap),
unmap: wl.Listener(void) = wl.Listener(void).init(handleUnmap),
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
// Listeners that are only active while the view is mapped
ack_configure: wl.Listener(*wlr.XdgSurface.Configure) =
wl.Listener(*wlr.XdgSurface.Configure).init(handleAckConfigure),
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
request_fullscreen: wl.Listener(void) = wl.Listener(void).init(handleRequestFullscreen),
request_move: wl.Listener(*wlr.XdgToplevel.event.Move) =
wl.Listener(*wlr.XdgToplevel.event.Move).init(handleRequestMove),
@ -104,11 +104,10 @@ pub fn create(wlr_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
wlr_toplevel.base.surface.data = @intFromPtr(&view.tree.node);
// Add listeners that are active over the toplevel's entire lifetime
wlr_toplevel.base.events.destroy.add(&toplevel.destroy);
wlr_toplevel.events.destroy.add(&toplevel.destroy);
wlr_toplevel.base.surface.events.map.add(&toplevel.map);
wlr_toplevel.base.surface.events.commit.add(&toplevel.commit);
wlr_toplevel.base.events.new_popup.add(&toplevel.new_popup);
_ = wlr_toplevel.setWmCapabilities(.{ .fullscreen = true });
}
/// Send a configure event, applying the inflight state of the view.
@ -213,8 +212,10 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
toplevel.destroy.link.remove();
toplevel.map.link.remove();
toplevel.unmap.link.remove();
toplevel.commit.link.remove();
toplevel.new_popup.link.remove();
// The wlr_surface may outlive the wlr_xdg_surface so we must clean up the user data.
// The wlr_surface may outlive the wlr_xdg_toplevel so we must clean up the user data.
toplevel.wlr_toplevel.base.surface.data = 0;
const view = toplevel.view;
@ -228,7 +229,6 @@ fn handleMap(listener: *wl.Listener(void)) void {
// Add listeners that are only active while mapped
toplevel.wlr_toplevel.base.events.ack_configure.add(&toplevel.ack_configure);
toplevel.wlr_toplevel.base.surface.events.commit.add(&toplevel.commit);
toplevel.wlr_toplevel.events.request_fullscreen.add(&toplevel.request_fullscreen);
toplevel.wlr_toplevel.events.request_move.add(&toplevel.request_move);
toplevel.wlr_toplevel.events.request_resize.add(&toplevel.request_resize);
@ -270,7 +270,6 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
// Remove listeners that are only active while mapped
toplevel.ack_configure.link.remove();
toplevel.commit.link.remove();
toplevel.request_fullscreen.link.remove();
toplevel.request_move.link.remove();
toplevel.request_resize.link.remove();
@ -309,6 +308,23 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const toplevel: *XdgToplevel = @fieldParentPtr("commit", listener);
const view = toplevel.view;
if (toplevel.wlr_toplevel.base.initial_commit) {
_ = toplevel.wlr_toplevel.setWmCapabilities(.{ .fullscreen = true });
if (toplevel.decoration) |decoration| {
const ssd = server.config.rules.ssd.match(toplevel.view) orelse
(decoration.wlr_decoration.requested_mode != .client_side);
_ = decoration.wlr_decoration.setMode(if (ssd) .server_side else .client_side);
toplevel.view.pending.ssd = ssd;
}
return;
}
if (!view.mapped) {
return;
}
{
const state = &toplevel.wlr_toplevel.current;
view.constraints = .{

View File

@ -106,10 +106,10 @@ pub fn configure(xwayland_view: XwaylandView) bool {
}
xwayland_view.xwayland_surface.configure(
@intCast(inflight.box.x + output_box.x),
@intCast(inflight.box.y + output_box.y),
@intCast(inflight.box.width),
@intCast(inflight.box.height),
math.lossyCast(i16, inflight.box.x + output_box.x),
math.lossyCast(i16, inflight.box.y + output_box.y),
math.lossyCast(u16, inflight.box.width),
math.lossyCast(u16, inflight.box.height),
);
xwayland_view.setActivated(inflight.focus != 0);

View File

@ -41,6 +41,7 @@ const command_impls = std.StaticStringMap(
).initComptime(
.{
// zig fmt: off
.{ "allow-tearing", @import("command/config.zig").allowTearing },
.{ "attach-mode", @import("command/attach_mode.zig").defaultAttachMode },
.{ "background-color", @import("command/config.zig").backgroundColor },
.{ "border-color-focused", @import("command/config.zig").borderColorFocused },

View File

@ -24,6 +24,20 @@ const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const Config = @import("../Config.zig");
pub fn allowTearing(
_: *Seat,
args: []const [:0]const u8,
_: *?[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const arg = std.meta.stringToEnum(enum { enabled, disabled }, args[1]) orelse
return Error.UnknownOption;
server.config.allow_tearing = arg == .enabled;
}
pub fn borderWidth(
_: *Seat,
args: []const [:0]const u8,

View File

@ -24,77 +24,13 @@ const util = @import("../util.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const KeyboardGroup = @import("../KeyboardGroup.zig");
pub fn keyboardGroupCreate(
seat: *Seat,
args: []const [:0]const u8,
out: *?[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
pub const keyboardGroupCreate = keyboardGroupDeprecated;
pub const keyboardGroupDestroy = keyboardGroupDeprecated;
pub const keyboardGroupAdd = keyboardGroupDeprecated;
pub const keyboardGroupRemove = keyboardGroupDeprecated;
if (keyboardGroupFromName(seat, args[1]) != null) {
const msg = try util.gpa.dupe(u8, "error: failed to create keybaord group: group of same name already exists\n");
out.* = msg;
return;
}
try KeyboardGroup.create(seat, args[1]);
}
pub fn keyboardGroupDestroy(
seat: *Seat,
args: []const [:0]const u8,
out: *?[]const u8,
) Error!void {
if (args.len < 2) return Error.NotEnoughArguments;
if (args.len > 2) return Error.TooManyArguments;
const group = keyboardGroupFromName(seat, args[1]) orelse {
const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n");
out.* = msg;
return;
};
group.destroy();
}
pub fn keyboardGroupAdd(
seat: *Seat,
args: []const [:0]const u8,
out: *?[]const u8,
) Error!void {
if (args.len < 3) return Error.NotEnoughArguments;
if (args.len > 3) return Error.TooManyArguments;
const group = keyboardGroupFromName(seat, args[1]) orelse {
const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n");
out.* = msg;
return;
};
try globber.validate(args[2]);
try group.addIdentifier(args[2]);
}
pub fn keyboardGroupRemove(
seat: *Seat,
args: []const [:0]const u8,
out: *?[]const u8,
) Error!void {
if (args.len < 3) return Error.NotEnoughArguments;
if (args.len > 3) return Error.TooManyArguments;
const group = keyboardGroupFromName(seat, args[1]) orelse {
const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n");
out.* = msg;
return;
};
try group.removeIdentifier(args[2]);
}
fn keyboardGroupFromName(seat: *Seat, name: []const u8) ?*KeyboardGroup {
var it = seat.keyboard_groups.first;
while (it) |node| : (it = node.next) {
if (mem.eql(u8, node.data.name, name)) return &node.data;
}
return null;
fn keyboardGroupDeprecated(_: *Seat, _: []const [:0]const u8, out: *?[]const u8) Error!void {
out.* = try util.gpa.dupe(u8, "warning: explicit keyboard groups are deprecated, " ++
"all keyboards are now automatically added to a single group\n");
}

View File

@ -26,6 +26,7 @@ const util = @import("../util.zig");
const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const View = @import("../View.zig");
const Anchor = @import("../Config.zig").Anchor;
const Action = enum {
float,
@ -35,9 +36,14 @@ const Action = enum {
tags,
output,
position,
@"relative-position",
dimensions,
fullscreen,
@"no-fullscreen",
tearing,
@"no-tearing",
warp,
@"no-warp",
};
pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void {
@ -53,9 +59,10 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
const action = std.meta.stringToEnum(Action, result.args[0]) orelse return Error.UnknownOption;
const positional_arguments_count: u8 = switch (action) {
.float, .@"no-float", .ssd, .csd, .fullscreen, .@"no-fullscreen" => 1,
.float, .@"no-float", .ssd, .csd, .fullscreen, .@"no-fullscreen", .tearing, .@"no-tearing", .warp, .@"no-warp" => 1,
.tags, .output => 2,
.position, .dimensions => 3,
.@"relative-position" => 4,
};
if (result.args.len > positional_arguments_count) return Error.TooManyArguments;
if (result.args.len < positional_arguments_count) return Error.NotEnoughArguments;
@ -83,6 +90,14 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
apply_ssd_rules();
server.root.applyPending();
},
.tearing, .@"no-tearing" => {
try server.config.rules.tearing.add(.{
.app_id_glob = app_id_glob,
.title_glob = title_glob,
.value = (action == .tearing),
});
apply_tearing_rules();
},
.tags => {
const tags = try fmt.parseInt(u32, result.args[1], 10);
try server.config.rules.tags.add(.{
@ -101,14 +116,32 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
});
},
.position => {
const x = try fmt.parseInt(u31, result.args[1], 10);
const y = try fmt.parseInt(u31, result.args[2], 10);
const x = try fmt.parseInt(i31, result.args[1], 10);
const y = try fmt.parseInt(i31, result.args[2], 10);
if (x < 0 or y < 0) return Error.OutOfBounds;
try server.config.rules.position.add(.{
.app_id_glob = app_id_glob,
.title_glob = title_glob,
.value = .{
.x = x,
.y = y,
.anchor = .absolute,
.x = @intCast(x),
.y = @intCast(y),
},
});
},
.@"relative-position" => {
const anchor = std.meta.stringToEnum(Anchor, result.args[1]) orelse return Error.UnknownOption;
// force the use of the normal position command for absolute positions
if (anchor == .absolute) return Error.UnknownOption;
const x_off = try fmt.parseInt(i31, result.args[2], 10);
const y_off = try fmt.parseInt(i31, result.args[3], 10);
try server.config.rules.position.add(.{
.app_id_glob = app_id_glob,
.title_glob = title_glob,
.value = .{
.anchor = anchor,
.x = x_off,
.y = y_off,
},
});
},
@ -131,6 +164,13 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
.value = (action == .fullscreen),
});
},
.warp, .@"no-warp" => {
try server.config.rules.warp.add(.{
.app_id_glob = app_id_glob,
.title_glob = title_glob,
.value = (action == .warp),
});
},
}
}
@ -168,7 +208,7 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
util.gpa.free(output_rule);
}
},
.position => {
.position, .@"relative-position" => {
_ = server.config.rules.position.del(rule);
},
.dimensions => {
@ -177,6 +217,13 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
.fullscreen, .@"no-fullscreen" => {
_ = server.config.rules.fullscreen.del(rule);
},
.tearing, .@"no-tearing" => {
_ = server.config.rules.tearing.del(rule);
apply_tearing_rules();
},
.warp, .@"no-warp" => {
_ = server.config.rules.warp.del(rule);
},
}
}
@ -191,6 +238,17 @@ fn apply_ssd_rules() void {
}
}
fn apply_tearing_rules() void {
var it = server.root.views.iterator(.forward);
while (it.next()) |view| {
if (view.destroying) continue;
if (server.config.rules.tearing.match(view)) |tearing| {
view.tearing_mode = if (tearing) .tearing else .no_tearing;
}
}
}
pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!void {
if (args.len < 2) return error.NotEnoughArguments;
if (args.len > 2) return error.TooManyArguments;
@ -203,6 +261,8 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
position,
dimensions,
fullscreen,
tearing,
warp,
}, args[1]) orelse return Error.UnknownOption;
const max_glob_len = switch (rule_list) {
inline else => |list| @field(server.config.rules, @tagName(list)).getMaxGlobLen(),
@ -218,12 +278,14 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
try writer.writeAll("action\n");
switch (rule_list) {
inline .float, .ssd, .output, .fullscreen => |list| {
inline .float, .ssd, .output, .fullscreen, .tearing, .warp => |list| {
const rules = switch (list) {
.float => server.config.rules.float.rules.items,
.ssd => server.config.rules.ssd.rules.items,
.output => server.config.rules.output.rules.items,
.fullscreen => server.config.rules.fullscreen.rules.items,
.tearing => server.config.rules.tearing.rules.items,
.warp => server.config.rules.warp.rules.items,
else => unreachable,
};
for (rules) |rule| {
@ -234,6 +296,8 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
.ssd => if (rule.value) "ssd" else "csd",
.output => rule.value,
.fullscreen => if (rule.value) "fullscreen" else "no-fullscreen",
.tearing => if (rule.value) "tearing" else "no-tearing",
.warp => if (rule.value) "warp" else "no-warp",
else => unreachable,
}});
}
@ -249,7 +313,7 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
for (server.config.rules.position.rules.items) |rule| {
try fmt.formatBuf(rule.title_glob, .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf(rule.app_id_glob, .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.print("{d},{d}\n", .{ rule.value.x, rule.value.y });
try writer.print("{s},{d},{d}", .{ @tagName(rule.value.anchor), rule.value.x, rule.value.y });
}
},
.dimensions => {

View File

@ -31,12 +31,6 @@ const process = @import("process.zig");
const Server = @import("Server.zig");
comptime {
if (wlr.version.major != 0 or wlr.version.minor != 17 or wlr.version.micro < 2) {
@compileError("river requires at least wlroots version 0.17.2 due to bugs in wlroots 0.17.0/0.17.1");
}
}
const usage: []const u8 =
\\usage: river [options]
\\
@ -90,7 +84,7 @@ pub fn main() anyerror!void {
posix.exit(1);
}
}
const enable_xwayland = !result.flags.@"no-xwayland";
const runtime_xwayland = !result.flags.@"no-xwayland";
const startup_command = blk: {
if (result.flags.c) |command| {
break :blk try util.gpa.dupeZ(u8, command);
@ -101,17 +95,25 @@ pub fn main() anyerror!void {
log.info("river version {s}, initializing server", .{build_options.version});
process.setup();
river_init_wlroots_log(switch (runtime_log_level) {
.debug => .debug,
.info => .info,
.warn, .err => .err,
});
try server.init(enable_xwayland);
try server.init(runtime_xwayland);
defer server.deinit();
// wlroots starts the Xwayland process from an idle event source, the reasoning being that
// this gives the compositor time to set up event listeners before Xwayland is actually
// started. We want Xwayland to be started by wlroots before we modify our rlimits in
// process.setup() since wlroots does not offer a way for us to reset the rlimit post-fork.
if (build_options.xwayland and runtime_xwayland) {
server.wl_server.getEventLoop().dispatchIdle();
}
process.setup();
try server.start();
// Run the child in a new process group so that we can send SIGTERM to all

View File

@ -110,10 +110,10 @@ fn _main() !void {
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, globals: *Globals) void {
switch (event) {
.global => |global| {
if (mem.orderZ(u8, global.interface, wl.Seat.getInterface().name) == .eq) {
if (mem.orderZ(u8, global.interface, wl.Seat.interface.name) == .eq) {
assert(globals.seat == null); // TODO: support multiple seats
globals.seat = registry.bind(global.name, wl.Seat, 1) catch @panic("out of memory");
} else if (mem.orderZ(u8, global.interface, zriver.ControlV1.getInterface().name) == .eq) {
} else if (mem.orderZ(u8, global.interface, zriver.ControlV1.interface.name) == .eq) {
globals.control = registry.bind(global.name, zriver.ControlV1, 1) catch @panic("out of memory");
}
},

View File

@ -382,9 +382,9 @@ pub fn main() !void {
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *Context) void {
switch (event) {
.global => |global| {
if (mem.orderZ(u8, global.interface, river.LayoutManagerV3.getInterface().name) == .eq) {
if (mem.orderZ(u8, global.interface, river.LayoutManagerV3.interface.name) == .eq) {
context.layout_manager = registry.bind(global.name, river.LayoutManagerV3, 1) catch return;
} else if (mem.orderZ(u8, global.interface, wl.Output.getInterface().name) == .eq) {
} else if (mem.orderZ(u8, global.interface, wl.Output.interface.name) == .eq) {
context.addOutput(registry, global.name) catch |err| fatal("failed to bind output: {}", .{err});
}
},