65 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
ffb24267b8 Merge branch 'master' of https://codeberg.org/river/river 2024-06-19 13:28:50 -07:00
de3035563c input: apply map-to-output on output activation
Currently a map-to-output input config setting loses effect when an
output is disabled and re-enabled for example.
2024-06-14 15:32:37 +02:00
28a14c6794 SceneNodeData: fix fromSurface() use after free
We must clean up the user data of the wlr_surface for layer surfaces and
lock surfaces as fromSurface() may be called (e.g. by the idle inhibit
implementation) after the scene node has been destroyed but before the
wlr_surface is destroyed.
2024-06-13 12:36:00 +02:00
e2f3cd8252 ci: log build summaries 2024-06-13 11:37:13 +02:00
f9201ae7cd ci: re-enable FreeBSD builds
Official FreeBSD zig tarballs have returned!

This reverts commit 7fdba05b82.
2024-06-13 11:32:38 +02:00
16c938111d ci: use mirror for zig tarball downloads
Eat Github's resources rather than the Zig Software Foundation's
resources!
2024-06-13 11:16:47 +02:00
68dda1a48a Update .gitignore 2024-06-08 16:26:20 -07:00
fac47ffb5d Merge branch 'master' of https://codeberg.org/river/river 2024-06-08 16:25:41 -07:00
8da69699e9 build: update to Zig 0.13.0 2024-06-07 14:01:30 +02:00
c5b1d1de4e ci: cleanup messy tar invocations 2024-05-23 16:21:02 +02:00
4d44ca6d5d ci: Check the formatting of build.zig.zon 2024-05-20 13:13:05 +02:00
7fdba05b82 ci: drop FreeBSD CI for now
There is no FreeBSD tarball from ziglang.org and FreeBSD itself has not
yet updated their Zig package to 0.12.0. This commit should be reverted
when a good way is found to obtain Zig 0.12.0 for the FreeBSD CI.
2024-05-20 11:45:09 +02:00
958f8798b6 build: switch to the Zig package manager
No more git submodules!
2024-05-20 11:44:08 +02:00
045ee7bd25 build: add -Dno-llvm build option 2024-05-20 11:35:36 +02:00
033cad47bf build: update to Zig 0.12 2024-05-20 11:35:36 +02:00
680cb8ef69 PointerConstraint: remove overly tight assert 2
This is a second copy of the same assert that was removed in the last
commit. It should have been removed by that commit as well but was
overlooked.
2024-05-18 16:28:28 +02:00
5d1fc034bc PointerConstraint: remove overly tight assert
This assert is incorrect if Xwayland is enabled and an Override Redirect
window steals the keyboard focus from the parent surface.

It also seems likely to be hit if a Wayland client attempts to use a
pointer constraint on a subsurface. I don't think a pointer constraint
on a subsurface is likely to work entirely correctly and I don't know of
any Wayland clients that try such a thing. We can't let them crash river
by trying though.
2024-05-18 14:40:20 +02:00
c75d32c88b InputPopup: fix minor issues, simplify code 2024-05-16 11:40:41 +02:00
b35a40b9df TextInput: ignore enable requests without focus 2024-05-15 12:21:22 +02:00
ba6023e38a InputPopup: fix naming 2024-05-15 11:50:58 +02:00
74baf7225a input-method-v2: Implement popups 2024-05-15 11:23:41 +02:00
52 changed files with 505 additions and 634 deletions

View File

@ -14,7 +14,6 @@ packages:
- xcb-util-wm-dev
- pixman-dev
- libevdev-dev
- wayland-dev
- wayland-protocols
- xwayland-dev
- meson
@ -24,11 +23,18 @@ packages:
- xz
sources:
- https://codeberg.org/river/river
- https://gitlab.freedesktop.org/wayland/wayland.git
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- install_deps: |
cd wayland
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.19.0
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 \
@ -37,10 +43,10 @@ tasks:
cd ..
# Eat Github's resources rather than the Zig Software Foundation's resources!
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz
tar xf zig-x86_64-linux-0.15.1.tar.xz
sudo mv zig-x86_64-linux-0.15.1/zig /usr/bin/
sudo mv zig-x86_64-linux-0.15.1/lib /usr/lib/zig
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz
tar xf zig-linux-x86_64-0.13.0.tar.xz
sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig
- build: |
cd river
zig build --summary all
@ -53,3 +59,4 @@ tasks:
zig fmt --check riverctl/
zig fmt --check rivertile/
zig fmt --check build.zig
zig fmt --check build.zig.zon

View File

@ -21,11 +21,18 @@ packages:
- xz
sources:
- https://codeberg.org/river/river
- https://gitlab.freedesktop.org/wayland/wayland.git
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- install_deps: |
cd wayland
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.19.0
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 \
@ -34,10 +41,10 @@ tasks:
cd ..
# Eat Github's resources rather than the Zig Software Foundation's resources!
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz
tar xf zig-x86_64-linux-0.15.1.tar.xz
sudo mv zig-x86_64-linux-0.15.1/zig /usr/bin/
sudo mv zig-x86_64-linux-0.15.1/lib /usr/lib/zig
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz
tar xf zig-linux-x86_64-0.13.0.tar.xz
sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/
sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig
- build: |
cd river
zig build --summary all
@ -50,3 +57,4 @@ tasks:
zig fmt --check riverctl/
zig fmt --check rivertile/
zig fmt --check build.zig
zig fmt --check build.zig.zon

View File

@ -7,7 +7,6 @@ packages:
- devel/meson
- devel/pkgconf
- graphics/mesa-libs
- graphics/wayland
- graphics/wayland-protocols
- misc/hwdata
- x11/libX11
@ -27,13 +26,19 @@ packages:
- wget
sources:
- https://codeberg.org/river/river
- https://gitlab.freedesktop.org/wayland/wayland.git
- https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks:
- install_deps: |
cd wayland
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.19.0
git checkout 0.18.0
meson setup build --auto-features=enabled -Drenderers=gles2 \
-Dallocators=gbm \
-Dcolor-management=disabled -Dlibliftoff=disabled \
-Dexamples=false -Dwerror=false -Db_ndebug=false \
-Dxcb-errors=disabled --prefix /usr
@ -41,10 +46,10 @@ tasks:
cd ..
# Eat Github's resources rather than the Zig Software Foundation's resources!
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.15.1/zig-x86_64-freebsd-0.15.1.tar.xz
tar xf zig-x86_64-freebsd-0.15.1.tar.xz
sudo mv zig-x86_64-freebsd-0.15.1/zig /usr/bin/
sudo mv zig-x86_64-freebsd-0.15.1/lib /usr/lib/zig
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-freebsd-x86_64-0.13.0.tar.xz
tar xf zig-freebsd-x86_64-0.13.0.tar.xz
sudo mv zig-freebsd-x86_64-0.13.0/zig /usr/bin/
sudo mv zig-freebsd-x86_64-0.13.0/lib /usr/lib/zig
- build: |
cd river
zig build --summary all

2
.gitignore vendored
View File

@ -1,2 +1,4 @@
.zig-cache/
zig-cache/
zig-out/
deps/

View File

@ -57,10 +57,10 @@ To compile river first ensure that you have the following dependencies
installed. The "development" versions are required if applicable to your
distribution.
- [zig](https://ziglang.org/download/) 0.15
- [zig](https://ziglang.org/download/) 0.13
- wayland
- wayland-protocols
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.19
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.18
- xkbcommon
- libevdev
- pixman

View File

@ -4,7 +4,13 @@ const Build = std.Build;
const fs = std.fs;
const mem = std.mem;
const Scanner = @import("wayland").Scanner;
const Scanner = @import("zig-wayland").Scanner;
/// While a river release is in development, this string should contain the version in development
/// with the "-dev" suffix.
/// When a release is tagged, the "-dev" suffix should be removed for the commit that gets tagged.
/// Directly after the tagged commit, the version should be bumped and the "-dev" suffix added.
const version = "0.4.0-dev";
pub fn build(b: *Build) !void {
const target = b.standardTargetOptions(.{});
@ -12,6 +18,7 @@ pub fn build(b: *Build) !void {
const strip = b.option(bool, "strip", "Omit debug information") orelse false;
const pie = b.option(bool, "pie", "Build a Position Independent Executable") orelse false;
const llvm = !(b.option(bool, "no-llvm", "(expirimental) Use non-LLVM x86 Zig backend") orelse false);
const omit_frame_pointer = switch (optimize) {
.Debug, .ReleaseSafe => false,
@ -64,7 +71,7 @@ pub fn build(b: *Build) !void {
.Inherit,
) catch break :blk version;
var it = mem.splitScalar(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), '-');
var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), "-");
_ = it.next().?; // previous tag
const commit_count = it.next().?;
const commit_hash = it.next().?;
@ -129,10 +136,10 @@ pub fn build(b: *Build) !void {
const wayland = b.createModule(.{ .root_source_file = scanner.result });
const xkbcommon = b.dependency("xkbcommon", .{}).module("xkbcommon");
const pixman = b.dependency("pixman", .{}).module("pixman");
const xkbcommon = b.dependency("zig-xkbcommon", .{}).module("xkbcommon");
const pixman = b.dependency("zig-pixman", .{}).module("pixman");
const wlroots = b.dependency("wlroots", .{}).module("wlroots");
const wlroots = b.dependency("zig-wlroots", .{}).module("wlroots");
wlroots.addImport("wayland", wayland);
wlroots.addImport("xkbcommon", xkbcommon);
wlroots.addImport("pixman", pixman);
@ -141,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-0.19", .{});
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") });
@ -149,12 +156,12 @@ pub fn build(b: *Build) !void {
{
const river = b.addExecutable(.{
.name = "river",
.root_module = b.createModule(.{
.root_source_file = b.path("river/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
}),
.use_llvm = llvm,
.use_lld = llvm,
});
river.root_module.addOptions("build_options", options);
@ -162,7 +169,7 @@ pub fn build(b: *Build) !void {
river.linkSystemLibrary("libevdev");
river.linkSystemLibrary("libinput");
river.linkSystemLibrary("wayland-server");
river.linkSystemLibrary("wlroots-0.19");
river.linkSystemLibrary("wlroots-0.18");
river.linkSystemLibrary("xkbcommon");
river.linkSystemLibrary("pixman-1");
@ -187,12 +194,12 @@ pub fn build(b: *Build) !void {
{
const riverctl = b.addExecutable(.{
.name = "riverctl",
.root_module = b.createModule(.{
.root_source_file = b.path("riverctl/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
}),
.use_llvm = llvm,
.use_lld = llvm,
});
riverctl.root_module.addOptions("build_options", options);
@ -210,12 +217,12 @@ pub fn build(b: *Build) !void {
{
const rivertile = b.addExecutable(.{
.name = "rivertile",
.root_module = b.createModule(.{
.root_source_file = b.path("rivertile/main.zig"),
.target = target,
.optimize = optimize,
.strip = strip,
}),
.use_llvm = llvm,
.use_lld = llvm,
});
rivertile.root_module.addOptions("build_options", options);
@ -274,11 +281,9 @@ pub fn build(b: *Build) !void {
{
const globber_test = b.addTest(.{
.root_module = b.createModule(.{
.root_source_file = b.path("common/globber.zig"),
.target = target,
.optimize = optimize,
}),
});
const run_globber_test = b.addRunArtifact(globber_test);
@ -286,31 +291,3 @@ pub fn build(b: *Build) !void {
test_step.dependOn(&run_globber_test.step);
}
}
const version = manifest.version;
/// Getting rid of this wart requires upstream zig improvements.
/// See: https://github.com/ziglang/zig/issues/22775
const manifest: struct {
name: @Type(.enum_literal),
version: []const u8,
paths: []const []const u8,
dependencies: struct {
pixman: struct {
url: []const u8,
hash: []const u8,
},
wayland: struct {
url: []const u8,
hash: []const u8,
},
wlroots: struct {
url: []const u8,
hash: []const u8,
},
xkbcommon: struct {
url: []const u8,
hash: []const u8,
},
},
fingerprint: u64,
} = @import("build.zig.zon");

View File

@ -1,29 +1,23 @@
.{
.name = .river,
// While a river release is in development, this string should contain
// the version in development with the "-dev" suffix.
// When a release is tagged, the "-dev" suffix should be removed for the
// commit that gets tagged. Directly after the tagged commit, the version
// should be bumped and the "-dev" suffix added.
.version = "0.3.12",
.name = "river",
.version = "0.4.0-dev",
.paths = .{""},
.dependencies = .{
.pixman = .{
.url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.3.0.tar.gz",
.hash = "pixman-0.3.0-LClMnz2VAAAs7QSCGwLimV5VUYx0JFnX5xWU6HwtMuDX",
.@"zig-pixman" = .{
.url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.2.0.tar.gz",
.hash = "12209db20ce873af176138b76632931def33a10539387cba745db72933c43d274d56",
},
.wayland = .{
.url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.4.0.tar.gz",
.hash = "wayland-0.4.0-lQa1khbMAQAsLS2eBR7M5lofyEGPIbu2iFDmoz8lPC27",
.@"zig-wayland" = .{
.url = "https://codeberg.org/ifreund/zig-wayland/archive/bd8afd256fb6beed7d72e3580b00f33dea7155a1.tar.gz",
.hash = "1220218a0e5c2cd63a2311417f4d3f2411dd17d75815f67c704ee657bd846ecbc3e0",
},
.wlroots = .{
.url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.19.3.tar.gz",
.hash = "wlroots-0.19.3-jmOlcuL_AwBHhLCwpFsXbTizE3q9BugFmGX-XIxqcPMc",
.@"zig-wlroots" = .{
.url = "https://codeberg.org/ifreund/zig-wlroots/archive/afbbbbe5579c750feed8de12b073fa50b0651137.tar.gz",
.hash = "122060ddef836b7872cb2088764a8bd2fb2e9254327673e8176b7f7a621ec897484f",
},
.xkbcommon = .{
.url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.3.0.tar.gz",
.hash = "xkbcommon-0.3.0-VDqIe3K9AQB2fG5ZeRcMC9i7kfrp5m2rWgLrmdNn9azr",
.@"zig-xkbcommon" = .{
.url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz",
.hash = "1220c90b2228d65fd8427a837d31b0add83e9fade1dcfa539bb56fd06f1f8461605f",
},
},
.fingerprint = 0xf5e3672b8e8d6efc,
}

View File

@ -42,21 +42,21 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
.boolean => .{
.name = flag.name,
.type = bool,
.default_value_ptr = &false,
.default_value = &false,
.is_comptime = false,
.alignment = @alignOf(bool),
},
.arg => .{
.name = flag.name,
.type = ?[:0]const u8,
.default_value_ptr = &@as(?[:0]const u8, null),
.default_value = &@as(?[:0]const u8, null),
.is_comptime = false,
.alignment = @alignOf(?[:0]const u8),
},
};
fields = fields ++ [_]std.builtin.Type.StructField{field};
}
break :flags_type @Type(.{ .@"struct" = .{
break :flags_type @Type(.{ .Struct = .{
.layout = .auto,
.fields = fields,
.decls = &.{},

View File

@ -84,7 +84,7 @@ fn handleRequest(control_v1: *zriver.ControlV1, request: zriver.ControlV1.Reques
};
},
.run_command => |run_command| {
const seat: *Seat = @ptrCast(@alignCast(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data));
const seat: *Seat = @ptrFromInt(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data);
const callback = zriver.CommandCallbackV1.create(
control_v1.getClient(),

View File

@ -26,7 +26,7 @@ const wayland = @import("wayland");
const wl = wayland.server.wl;
const zwlr = wayland.server.zwlr;
const c = @import("c.zig").c;
const c = @import("c.zig");
const server = &@import("main.zig").server;
const util = @import("util.zig");
@ -138,7 +138,7 @@ wlr_cursor: *wlr.Cursor,
/// Xcursor manager for the currently configured Xcursor theme.
xcursor_manager: *wlr.XcursorManager,
image: Image = .none,
image_surface_destroy: wl.Listener(*wlr.Surface) = .init(handleImageSurfaceDestroy),
image_surface_destroy: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleImageSurfaceDestroy),
/// Number of distinct buttons currently pressed
pressed_count: u32 = 0,
@ -255,30 +255,6 @@ pub fn init(cursor: *Cursor, seat: *Seat) !void {
}
pub fn deinit(cursor: *Cursor) void {
cursor.axis.link.remove();
cursor.button.link.remove();
cursor.frame.link.remove();
cursor.motion_absolute.link.remove();
cursor.motion.link.remove();
cursor.swipe_begin.link.remove();
cursor.swipe_update.link.remove();
cursor.swipe_end.link.remove();
cursor.pinch_begin.link.remove();
cursor.pinch_update.link.remove();
cursor.pinch_end.link.remove();
cursor.request_set_cursor.link.remove();
cursor.touch_down.link.remove();
cursor.touch_motion.link.remove();
cursor.touch_up.link.remove();
cursor.touch_cancel.link.remove();
cursor.touch_frame.link.remove();
cursor.tablet_tool_axis.link.remove();
cursor.tablet_tool_proximity.link.remove();
cursor.tablet_tool_tip.link.remove();
cursor.tablet_tool_button.link.remove();
cursor.hide_cursor_timer.remove();
cursor.xcursor_manager.destroy();
cursor.wlr_cursor.destroy();
@ -296,7 +272,7 @@ pub fn setTheme(cursor: *Cursor, theme: ?[*:0]const u8, _size: ?u32) !void {
// If this cursor belongs to the default seat, set the xcursor environment
// variables as well as the xwayland cursor theme.
if (cursor.seat == server.input_manager.defaultSeat()) {
const size_str = try std.fmt.allocPrintSentinel(util.gpa, "{}", .{size}, 0);
const size_str = try std.fmt.allocPrintZ(util.gpa, "{}", .{size});
defer util.gpa.free(size_str);
if (c.setenv("XCURSOR_SIZE", size_str.ptr, 1) < 0) return error.OutOfMemory;
if (theme) |t| if (c.setenv("XCURSOR_THEME", t, 1) < 0) return error.OutOfMemory;
@ -362,7 +338,7 @@ fn clearFocus(cursor: *Cursor) void {
/// Axis event is a scroll wheel or similiar
fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Pointer.event.Axis) void {
const cursor: *Cursor = @fieldParentPtr("axis", listener);
const device: *InputDevice = @ptrCast(@alignCast(event.device.data));
const device: *InputDevice = @ptrFromInt(event.device.data);
cursor.seat.handleActivity();
cursor.unhide();
@ -378,8 +354,8 @@ fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Point
// @intFromFloat() call safe due to the max/min i32 not being exactly representable
// by an f32. Dividing by 2 is a low effort way to ensure the value is in bounds and
// allow users to set their scroll-factor to inf without crashing river.
@as(f32, @floatFromInt(math.minInt(i32) / 2)),
@as(f32, @floatFromInt(math.maxInt(i32) / 2)),
math.minInt(i32) / 2,
math.maxInt(i32) / 2,
)),
event.source,
event.relative_direction,
@ -482,7 +458,7 @@ fn updateKeyboardFocus(cursor: Cursor, result: Root.AtResult) void {
/// Requires a call to Root.applyPending()
fn updateOutputFocus(cursor: Cursor, lx: f64, ly: f64) void {
if (server.root.output_layout.outputAt(lx, ly)) |wlr_output| {
const output: *Output = @ptrCast(@alignCast(wlr_output.data));
const output: *Output = @ptrFromInt(wlr_output.data);
cursor.seat.focusOutput(output);
}
}
@ -659,7 +635,7 @@ fn handleTabletToolAxis(
_: *wl.Listener(*wlr.Tablet.event.Axis),
event: *wlr.Tablet.event.Axis,
) void {
const device: *InputDevice = @ptrCast(@alignCast(event.device.data));
const device: *InputDevice = @ptrFromInt(event.device.data);
const tablet: *Tablet = @fieldParentPtr("device", device);
device.seat.handleActivity();
@ -673,7 +649,7 @@ fn handleTabletToolProximity(
_: *wl.Listener(*wlr.Tablet.event.Proximity),
event: *wlr.Tablet.event.Proximity,
) void {
const device: *InputDevice = @ptrCast(@alignCast(event.device.data));
const device: *InputDevice = @ptrFromInt(event.device.data);
const tablet: *Tablet = @fieldParentPtr("device", device);
device.seat.handleActivity();
@ -687,7 +663,7 @@ fn handleTabletToolTip(
_: *wl.Listener(*wlr.Tablet.event.Tip),
event: *wlr.Tablet.event.Tip,
) void {
const device: *InputDevice = @ptrCast(@alignCast(event.device.data));
const device: *InputDevice = @ptrFromInt(event.device.data);
const tablet: *Tablet = @fieldParentPtr("device", device);
device.seat.handleActivity();
@ -701,7 +677,7 @@ fn handleTabletToolButton(
_: *wl.Listener(*wlr.Tablet.event.Button),
event: *wlr.Tablet.event.Button,
) void {
const device: *InputDevice = @ptrCast(@alignCast(event.device.data));
const device: *InputDevice = @ptrFromInt(event.device.data);
const tablet: *Tablet = @fieldParentPtr("device", device);
device.seat.handleActivity();
@ -822,7 +798,6 @@ pub fn hide(cursor: *Cursor) void {
cursor.hidden = true;
cursor.wlr_cursor.unsetImage();
cursor.seat.wlr_seat.pointerNotifyClearFocus();
cursor.hide_cursor_timer.timerUpdate(0) catch {
log.err("failed to update cursor hide timeout", .{});
};
@ -1154,12 +1129,13 @@ pub fn updateState(cursor: *Cursor) void {
.passthrough => {
cursor.updateFocusFollowsCursorTarget();
if (!cursor.hidden) {
const now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
var now: posix.timespec = undefined;
posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
// 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.sec *% std.time.ms_per_s +% @divTrunc(now.nsec, std.time.ns_per_ms),
now.tv_sec *% std.time.ms_per_s +% @divTrunc(now.tv_nsec, std.time.ns_per_ms),
math.maxInt(u32),
));
cursor.passthrough(msec);
@ -1301,7 +1277,7 @@ fn warp(cursor: *Cursor) void {
fn updateDragIcons(cursor: *Cursor) void {
var it = server.root.drag_icons.children.iterator(.forward);
while (it.next()) |node| {
const icon: *DragIcon = @ptrCast(@alignCast(node.data));
const icon = @as(*DragIcon, @ptrFromInt(node.data));
if (icon.wlr_drag_icon.drag.seat == cursor.seat.wlr_seat) {
icon.updatePosition(cursor);

View File

@ -42,7 +42,7 @@ pub fn create(wlr_drag_icon: *wlr.Drag.Icon, cursor: *Cursor) error{OutOfMemory}
.wlr_drag_icon = wlr_drag_icon,
.scene_drag_icon = scene_drag_icon,
};
scene_drag_icon.node.data = drag_icon;
scene_drag_icon.node.data = @intFromPtr(drag_icon);
drag_icon.updatePosition(cursor);

View File

@ -89,7 +89,7 @@ fn handleForeignActivate(
) void {
const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_activate", listener);
const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle);
const seat: *Seat = @ptrCast(@alignCast(event.seat.data));
const seat: *Seat = @ptrFromInt(event.seat.data);
seat.focus(view);
server.root.applyPending();

View File

@ -30,29 +30,28 @@ const View = @import("View.zig");
wlr_manager: *wlr.IdleInhibitManagerV1,
new_idle_inhibitor: wl.Listener(*wlr.IdleInhibitorV1) =
wl.Listener(*wlr.IdleInhibitorV1).init(handleNewIdleInhibitor),
inhibitors: wl.list.Head(IdleInhibitor, .link),
inhibitors: std.TailQueue(IdleInhibitor) = .{},
pub fn init(inhibit_manager: *IdleInhibitManager) !void {
inhibit_manager.* = .{
.wlr_manager = try wlr.IdleInhibitManagerV1.create(server.wl_server),
.inhibitors = undefined,
};
inhibit_manager.inhibitors.init();
inhibit_manager.wlr_manager.events.new_inhibitor.add(&inhibit_manager.new_idle_inhibitor);
}
pub fn deinit(inhibit_manager: *IdleInhibitManager) void {
while (inhibit_manager.inhibitors.first()) |inhibitor| {
inhibitor.destroy();
while (inhibit_manager.inhibitors.pop()) |inhibitor| {
inhibitor.data.destroy.link.remove();
util.gpa.destroy(inhibitor);
}
inhibit_manager.new_idle_inhibitor.link.remove();
}
pub fn checkActive(inhibit_manager: *IdleInhibitManager) void {
var inhibited = false;
var it = inhibit_manager.inhibitors.iterator(.forward);
while (it.next()) |inhibitor| {
const node_data = SceneNodeData.fromSurface(inhibitor.wlr_inhibitor.surface) orelse continue;
var it = inhibit_manager.inhibitors.first;
while (it) |node| : (it = node.next) {
const node_data = SceneNodeData.fromSurface(node.data.wlr_inhibitor.surface) orelse continue;
switch (node_data.data) {
.view => |view| {
if (view.current.output != null and
@ -80,8 +79,13 @@ pub fn checkActive(inhibit_manager: *IdleInhibitManager) void {
fn handleNewIdleInhibitor(listener: *wl.Listener(*wlr.IdleInhibitorV1), inhibitor: *wlr.IdleInhibitorV1) void {
const inhibit_manager: *IdleInhibitManager = @fieldParentPtr("new_idle_inhibitor", listener);
IdleInhibitor.create(inhibitor, inhibit_manager) catch {
std.log.err("out of memory", .{});
const inhibitor_node = util.gpa.create(std.TailQueue(IdleInhibitor).Node) catch return;
inhibitor_node.data.init(inhibitor, inhibit_manager) catch {
util.gpa.destroy(inhibitor_node);
return;
};
inhibit_manager.inhibitors.append(inhibitor_node);
inhibit_manager.checkActive();
}

View File

@ -28,38 +28,31 @@ const IdleInhibitManager = @import("IdleInhibitManager.zig");
inhibit_manager: *IdleInhibitManager,
wlr_inhibitor: *wlr.IdleInhibitorV1,
listen_destroy: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleDestroy),
link: wl.list.Link,
pub fn create(wlr_inhibitor: *wlr.IdleInhibitorV1, inhibit_manager: *IdleInhibitManager) !void {
const inhibitor = try util.gpa.create(IdleInhibitor);
errdefer util.gpa.destroy(inhibitor);
destroy: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleDestroy),
pub fn init(
inhibitor: *IdleInhibitor,
wlr_inhibitor: *wlr.IdleInhibitorV1,
inhibit_manager: *IdleInhibitManager,
) !void {
inhibitor.* = .{
.inhibit_manager = inhibit_manager,
.wlr_inhibitor = wlr_inhibitor,
.link = undefined,
};
wlr_inhibitor.events.destroy.add(&inhibitor.listen_destroy);
inhibit_manager.inhibitors.append(inhibitor);
wlr_inhibitor.events.destroy.add(&inhibitor.destroy);
inhibit_manager.checkActive();
}
pub fn destroy(inhibitor: *IdleInhibitor) void {
inhibitor.listen_destroy.link.remove();
fn handleDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const inhibitor: *IdleInhibitor = @fieldParentPtr("destroy", listener);
inhibitor.link.remove();
inhibitor.destroy.link.remove();
const node: *std.TailQueue(IdleInhibitor).Node = @fieldParentPtr("data", inhibitor);
server.idle_inhibit_manager.inhibitors.remove(node);
inhibitor.inhibit_manager.checkActive();
util.gpa.destroy(inhibitor);
}
fn handleDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const inhibitor: *IdleInhibitor = @fieldParentPtr("listen_destroy", listener);
inhibitor.destroy();
util.gpa.destroy(node);
}

View File

@ -25,7 +25,7 @@ const wlr = @import("wlroots");
const log = std.log.scoped(.input_config);
const c = @import("c.zig").c;
const c = @import("c.zig");
const server = &@import("main.zig").server;
const util = @import("util.zig");
@ -307,7 +307,7 @@ pub fn apply(config: *const InputConfig, device: *InputDevice) void {
const libinput_device: *c.libinput_device = @ptrCast(device.wlr_device.getLibinputDevice() orelse return);
log.debug("applying input configuration '{s}' to device '{s}'.", .{ config.glob, device.identifier });
inline for (@typeInfo(InputConfig).@"struct".fields) |field| {
inline for (@typeInfo(InputConfig).Struct.fields) |field| {
if (comptime mem.eql(u8, field.name, "glob")) continue;
if (@field(config, field.name)) |setting| {
@ -324,7 +324,7 @@ pub fn apply(config: *const InputConfig, device: *InputDevice) void {
}
pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !void {
inline for (@typeInfo(InputConfig).@"struct".fields) |field| {
inline for (@typeInfo(InputConfig).Struct.fields) |field| {
if (comptime mem.eql(u8, field.name, "glob")) continue;
if (mem.eql(u8, setting, field.name)) {
@ -358,8 +358,8 @@ pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !void
}
config.@"map-to-output" = .{ .output_name = output_name_owned };
} else {
const T = @typeInfo(field.type).optional.child;
if (@typeInfo(T) != .@"enum") {
const T = @typeInfo(field.type).Optional.child;
if (@typeInfo(T) != .Enum) {
@compileError("You forgot to implement parsing for an input configuration setting.");
}
@field(config, field.name) = meta.stringToEnum(T, value) orelse
@ -373,10 +373,10 @@ pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !void
return error.UnknownCommand;
}
pub fn write(config: *InputConfig, writer: *std.Io.Writer) !void {
pub fn write(config: *InputConfig, writer: anytype) !void {
try writer.print("{s}\n", .{config.glob});
inline for (@typeInfo(InputConfig).@"struct".fields) |field| {
inline for (@typeInfo(InputConfig).Struct.fields) |field| {
if (comptime mem.eql(u8, field.name, "glob")) continue;
if (comptime mem.eql(u8, field.name, "map-to-output")) {
@ -396,8 +396,8 @@ pub fn write(config: *InputConfig, writer: *std.Io.Writer) !void {
mem.sliceTo(c.libevdev_event_code_get_name(c.EV_KEY, setting.button), 0),
});
} else {
const T = @typeInfo(field.type).optional.child;
if (@typeInfo(T) != .@"enum") {
const T = @typeInfo(field.type).Optional.child;
if (@typeInfo(T) != .Enum) {
@compileError("You forgot to implement listing for an input configuration setting.");
}
try writer.print("\t{s}: {s}\n", .{ field.name, @tagName(setting) });

View File

@ -24,7 +24,7 @@ const wl = @import("wayland").server.wl;
const globber = @import("globber");
const c = @import("c.zig").c;
const c = @import("c.zig");
const server = &@import("main.zig").server;
const util = @import("util.zig");
@ -86,7 +86,7 @@ pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !vo
.link = undefined,
};
wlr_device.data = device;
wlr_device.data = @intFromPtr(device);
wlr_device.events.destroy.add(&device.destroy);
@ -117,7 +117,7 @@ pub fn deinit(device: *InputDevice) void {
device.seat.updateCapabilities();
}
device.wlr_device.data = null;
device.wlr_device.data = 0;
device.* = undefined;
}

View File

@ -55,10 +55,10 @@ tablet_manager: *wlr.TabletManagerV2,
/// List of input device configurations. Ordered by glob generality, with
/// the most general towards the start and the most specific towards the end.
configs: std.ArrayList(InputConfig) = .{},
configs: std.ArrayList(InputConfig),
devices: wl.list.Head(InputDevice, .link),
seats: wl.list.Head(Seat, .link),
seats: std.TailQueue(Seat) = .{},
exclusive_client: ?*wl.Client = null,
@ -74,6 +74,9 @@ new_text_input: wl.Listener(*wlr.TextInputV3) =
wl.Listener(*wlr.TextInputV3).init(handleNewTextInput),
pub fn init(input_manager: *InputManager) !void {
const seat_node = try util.gpa.create(std.TailQueue(Seat).Node);
errdefer util.gpa.destroy(seat_node);
input_manager.* = .{
// These are automatically freed when the display is destroyed
.idle_notifier = try wlr.IdleNotifierV1.create(server.wl_server),
@ -85,14 +88,14 @@ pub fn init(input_manager: *InputManager) !void {
.input_method_manager = try wlr.InputMethodManagerV2.create(server.wl_server),
.text_input_manager = try wlr.TextInputManagerV3.create(server.wl_server),
.tablet_manager = try wlr.TabletManagerV2.create(server.wl_server),
.configs = std.ArrayList(InputConfig).init(util.gpa),
.seats = undefined,
.devices = undefined,
};
input_manager.seats.init();
input_manager.devices.init();
try Seat.create(default_seat_name);
input_manager.seats.prepend(seat_node);
try seat_node.data.init(default_seat_name);
if (build_options.xwayland) {
if (server.xwayland) |xwayland| {
@ -118,18 +121,19 @@ pub fn deinit(input_manager: *InputManager) void {
input_manager.new_input_method.link.remove();
input_manager.new_text_input.link.remove();
while (input_manager.seats.first()) |seat| {
seat.destroy();
while (input_manager.seats.pop()) |seat_node| {
seat_node.data.deinit();
util.gpa.destroy(seat_node);
}
for (input_manager.configs.items) |*config| {
config.deinit();
}
input_manager.configs.deinit(util.gpa);
input_manager.configs.deinit();
}
pub fn defaultSeat(input_manager: *InputManager) *Seat {
return input_manager.seats.first().?;
pub fn defaultSeat(input_manager: InputManager) *Seat {
return &input_manager.seats.first.?.data;
}
/// Returns true if input is currently allowed on the passed surface.
@ -156,7 +160,7 @@ pub fn reconfigureDevices(input_manager: *InputManager) void {
fn handleNewInput(listener: *wl.Listener(*wlr.InputDevice), wlr_device: *wlr.InputDevice) void {
const input_manager: *InputManager = @fieldParentPtr("new_input", listener);
input_manager.defaultSeat().addDevice(wlr_device, false);
input_manager.defaultSeat().addDevice(wlr_device);
}
fn handleNewVirtualPointer(
@ -174,53 +178,17 @@ fn handleNewVirtualPointer(
log.debug("Ignoring output suggestion from virtual pointer", .{});
}
input_manager.defaultSeat().addDevice(&event.new_pointer.pointer.base, true);
input_manager.defaultSeat().addDevice(&event.new_pointer.pointer.base);
}
fn handleNewVirtualKeyboard(
_: *wl.Listener(*wlr.VirtualKeyboardV1),
virtual_keyboard: *wlr.VirtualKeyboardV1,
) void {
const no_keymap = util.gpa.create(NoKeymapVirtKeyboard) catch {
log.err("out of memory", .{});
return;
};
errdefer util.gpa.destroy(no_keymap);
no_keymap.* = .{
.virtual_keyboard = virtual_keyboard,
};
virtual_keyboard.keyboard.base.events.destroy.add(&no_keymap.destroy);
virtual_keyboard.keyboard.events.keymap.add(&no_keymap.keymap);
const seat: *Seat = @ptrFromInt(virtual_keyboard.seat.data);
seat.addDevice(&virtual_keyboard.keyboard.base);
}
/// Ignore virtual keyboards completely until the client sets a keymap
/// Yes, wlroots should probably do this for us.
const NoKeymapVirtKeyboard = struct {
virtual_keyboard: *wlr.VirtualKeyboardV1,
destroy: wl.Listener(*wlr.InputDevice) = .init(handleDestroy),
keymap: wl.Listener(*wlr.Keyboard) = .init(handleKeymap),
fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) void {
const no_keymap: *NoKeymapVirtKeyboard = @fieldParentPtr("destroy", listener);
no_keymap.destroy.link.remove();
no_keymap.keymap.link.remove();
util.gpa.destroy(no_keymap);
}
fn handleKeymap(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void {
const no_keymap: *NoKeymapVirtKeyboard = @fieldParentPtr("keymap", listener);
const virtual_keyboard = no_keymap.virtual_keyboard;
handleDestroy(&no_keymap.destroy, &virtual_keyboard.keyboard.base);
const seat: *Seat = @ptrCast(@alignCast(virtual_keyboard.seat.data));
seat.addDevice(&virtual_keyboard.keyboard.base, true);
}
};
fn handleNewConstraint(
_: *wl.Listener(*wlr.PointerConstraintV1),
wlr_constraint: *wlr.PointerConstraintV1,
@ -232,7 +200,7 @@ fn handleNewConstraint(
}
fn handleNewInputMethod(_: *wl.Listener(*wlr.InputMethodV2), input_method: *wlr.InputMethodV2) void {
const seat: *Seat = @ptrCast(@alignCast(input_method.seat.data));
const seat: *Seat = @ptrFromInt(input_method.seat.data);
log.debug("new input method on seat {s}", .{seat.wlr_seat.name});

View File

@ -54,60 +54,41 @@ pub const Pressed = struct {
// Furthermore, wlroots will continue to forward key press/release events to river if more
// than 32 keys are pressed. Therefore river chooses to ignore keypresses that would take
// the keyboard beyond 32 simultaneously pressed keys.
assert(capacity == @typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).array.len);
assert(capacity == @typeInfo(std.meta.fieldInfo(wlr.Keyboard, .keycodes).type).Array.len);
}
keys: [capacity]Key,
len: usize,
const empty: Pressed = .{ .keys = undefined, .len = 0 };
pub fn slice(pressed: *Pressed) []Key {
return pressed.keys[0..pressed.len];
}
keys: std.BoundedArray(Key, capacity) = .{},
fn contains(pressed: *Pressed, code: u32) bool {
for (pressed.slice()) |item| {
for (pressed.keys.constSlice()) |item| {
if (item.code == code) return true;
}
return false;
}
fn addAssumeCapacity(pressed: *Pressed, new: Key) void {
assert(pressed.len < pressed.keys.len);
assert(!pressed.contains(new.code));
pressed.keys[pressed.len] = new;
pressed.len += 1;
pressed.keys.appendAssumeCapacity(new);
}
fn remove(pressed: *Pressed, code: u32) ?KeyConsumer {
for (pressed.slice(), 0..) |item, idx| {
if (item.code == code) return pressed.swapRemove(idx).consumer;
for (pressed.keys.constSlice(), 0..) |item, idx| {
if (item.code == code) return pressed.keys.swapRemove(idx).consumer;
}
return null;
}
fn swapRemove(pressed: *Pressed, index: usize) Key {
defer pressed.len -= 1;
if (index == pressed.len - 1) {
return pressed.keys[index];
}
const ret = pressed.keys[index];
pressed.keys[index] = pressed.keys[pressed.len - 1];
return ret;
}
};
device: InputDevice,
/// Pressed keys along with where their press event has been sent
pressed: Pressed = .empty,
pressed: Pressed = .{},
key: wl.Listener(*wlr.Keyboard.event.Key) = wl.Listener(*wlr.Keyboard.event.Key).init(handleKey),
modifiers: wl.Listener(*wlr.Keyboard) = wl.Listener(*wlr.Keyboard).init(handleModifiers),
pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice, virtual: bool) !void {
pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice) !void {
keyboard.* = .{
.device = undefined,
};
@ -115,9 +96,8 @@ pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice, virt
errdefer keyboard.device.deinit();
const wlr_keyboard = keyboard.device.wlr_device.toKeyboard();
wlr_keyboard.data = keyboard;
wlr_keyboard.data = @intFromPtr(keyboard);
if (!virtual) {
// wlroots will log a more detailed error if this fails.
if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory;
@ -125,7 +105,6 @@ pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice, virt
// wlroots will log an error on failure
_ = seat.keyboard_group.addKeyboard(wlr_keyboard);
}
}
wlr_keyboard.setRepeatInfo(server.config.repeat_rate, server.config.repeat_delay);
@ -222,9 +201,7 @@ fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboa
// Ignore key presses beyond 32 simultaneously pressed keys (see comments in Pressed).
// We must ensure capacity before calling handleMapping() to ensure that we either run
// both the press and release mapping for certain key or neither mapping.
if (keyboard.pressed.len >= keyboard.pressed.keys.len) {
return;
}
keyboard.pressed.keys.ensureUnusedCapacity(1) catch return;
if (keyboard.device.seat.handleMapping(keycode, modifiers, released, xkb_state)) {
break :blk .mapping;

View File

@ -43,7 +43,7 @@ commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit)
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
const output: *Output = @ptrCast(@alignCast(wlr_layer_surface.output.?.data));
const output: *Output = @ptrFromInt(wlr_layer_surface.output.?.data);
const layer_surface = try util.gpa.create(LayerSurface);
errdefer util.gpa.destroy(layer_surface);
@ -59,7 +59,7 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface });
try SceneNodeData.attach(&layer_surface.popup_tree.node, .{ .layer_surface = layer_surface });
wlr_layer_surface.surface.data = &layer_surface.scene_layer_surface.tree.node;
wlr_layer_surface.surface.data = @intFromPtr(&layer_surface.scene_layer_surface.tree.node);
wlr_layer_surface.events.destroy.add(&layer_surface.destroy);
wlr_layer_surface.surface.events.map.add(&layer_surface.map);
@ -82,14 +82,13 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa
layer_surface.map.link.remove();
layer_surface.unmap.link.remove();
layer_surface.commit.link.remove();
layer_surface.new_popup.link.remove();
layer_surface.destroyPopups();
layer_surface.popup_tree.node.destroy();
// The wlr_surface may outlive the wlr_layer_surface so we must clean up the user data.
layer_surface.wlr_layer_surface.surface.data = null;
layer_surface.wlr_layer_surface.surface.data = 0;
util.gpa.destroy(layer_surface);
}
@ -157,7 +156,7 @@ fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface)
var it = tree.children.iterator(.reverse);
while (it.next()) |node| {
assert(node.type == .tree);
if (@as(?*SceneNodeData, @ptrCast(@alignCast(node.data)))) |node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
const layer_surface = node_data.data.layer_surface;
const wlr_layer_surface = layer_surface.wlr_layer_surface;
if (wlr_layer_surface.surface.mapped and
@ -173,8 +172,10 @@ fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface)
assert(s.wlr_layer_surface.current.keyboard_interactive != .none);
}
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| {
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
if (seat.focused_output == output) {
if (to_focus) |s| {
// If we found a surface on the output that requires focus, grab the focus of all

View File

@ -38,9 +38,6 @@ layout_v3: *river.LayoutV3,
namespace: []const u8,
output: *Output,
// Output.layouts
link: wl.list.Link,
pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namespace: []const u8) !void {
const layout_v3 = try river.LayoutV3.create(client, version, id);
@ -50,22 +47,21 @@ pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namesp
return;
}
const layout = try util.gpa.create(Layout);
errdefer util.gpa.destroy(layout);
layout.* = .{
const node = try util.gpa.create(std.TailQueue(Layout).Node);
errdefer util.gpa.destroy(node);
node.data = .{
.layout_v3 = layout_v3,
.namespace = try util.gpa.dupe(u8, namespace),
.output = output,
.link = undefined,
};
output.layouts.append(layout);
output.layouts.append(node);
layout_v3.setHandler(*Layout, handleRequest, handleDestroy, layout);
layout_v3.setHandler(*Layout, handleRequest, handleDestroy, &node.data);
// If the namespace matches that of the output, set the layout as
// the active one of the output and arrange it.
if (mem.eql(u8, namespace, output.layoutNamespace())) {
output.layout = layout;
output.layout = &node.data;
server.root.applyPending();
}
}
@ -75,17 +71,17 @@ pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namesp
fn namespaceInUse(namespace: []const u8, output: *Output, client: *wl.Client) bool {
var output_it = server.root.active_outputs.iterator(.forward);
while (output_it.next()) |o| {
var layout_it = output.layouts.iterator(.forward);
var layout_it = output.layouts.first;
if (o == output) {
// On this output, no other layout can have our namespace.
while (layout_it.next()) |layout| {
if (mem.eql(u8, namespace, layout.namespace)) return true;
while (layout_it) |layout_node| : (layout_it = layout_node.next) {
if (mem.eql(u8, namespace, layout_node.data.namespace)) return true;
}
} else {
// Layouts on other outputs may share the namespace, if they come from the same client.
while (layout_it.next()) |layout| {
if (mem.eql(u8, namespace, layout.namespace) and
client != layout.layout_v3.getClient()) return true;
while (layout_it) |layout_node| : (layout_it = layout_node.next) {
if (mem.eql(u8, namespace, layout_node.data.namespace) and
client != layout_node.data.layout_v3.getClient()) return true;
}
}
}
@ -189,7 +185,9 @@ pub fn destroy(layout: *Layout) void {
.{ layout.namespace, layout.output.wlr_output.name },
);
layout.link.remove();
// Remove layout from the list
const node: *std.TailQueue(Layout).Node = @fieldParentPtr("data", layout);
layout.output.layouts.remove(node);
// If we are the currently active layout of an output, clean up.
if (layout.output.layout == layout) {
@ -210,5 +208,5 @@ pub fn destroy(layout: *Layout) void {
layout.layout_v3.setHandler(?*anyopaque, handleRequestInert, null, null);
util.gpa.free(layout.namespace);
util.gpa.destroy(layout);
util.gpa.destroy(node);
}

View File

@ -68,7 +68,7 @@ fn handleRequest(
.get_layout => |req| {
// Ignore if the output is inert
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
const output: *Output = @ptrCast(@alignCast(wlr_output.data));
const output: *Output = @ptrFromInt(wlr_output.data);
log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, output.wlr_output.name });

View File

@ -110,8 +110,9 @@ fn handleLock(listener: *wl.Listener(*wlr.SessionLockV1), lock: *wlr.SessionLock
};
{
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| {
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
seat.setFocusRaw(.none);
// Enter locked mode
@ -212,8 +213,9 @@ fn handleUnlock(listener: *wl.Listener(void)) void {
}
{
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| {
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
seat.setFocusRaw(.none);
// Exit locked mode
@ -264,7 +266,7 @@ pub fn updateLockSurfaceSize(manager: *LockManager, output: *Output) void {
var it = lock.surfaces.iterator(.forward);
while (it.next()) |wlr_lock_surface| {
const lock_surface: *LockSurface = @ptrCast(@alignCast(wlr_lock_surface.data));
const lock_surface: *LockSurface = @ptrFromInt(wlr_lock_surface.data);
if (output == lock_surface.getOutput()) {
lock_surface.configure();
}

View File

@ -44,7 +44,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc
.wlr_lock_surface = wlr_lock_surface,
.lock = lock,
};
wlr_lock_surface.data = lock_surface;
wlr_lock_surface.data = @intFromPtr(lock_surface);
const output = lock_surface.getOutput();
const tree = try output.locked_content.createSceneSubsurfaceTree(wlr_lock_surface.surface);
@ -52,7 +52,7 @@ pub fn create(wlr_lock_surface: *wlr.SessionLockSurfaceV1, lock: *wlr.SessionLoc
try SceneNodeData.attach(&tree.node, .{ .lock_surface = lock_surface });
wlr_lock_surface.surface.data = &tree.node;
wlr_lock_surface.surface.data = @intFromPtr(&tree.node);
wlr_lock_surface.surface.events.map.add(&lock_surface.map);
wlr_lock_surface.events.destroy.add(&lock_surface.surface_destroy);
@ -65,11 +65,12 @@ pub fn destroy(lock_surface: *LockSurface) void {
var surface_it = lock_surface.lock.surfaces.iterator(.forward);
const new_focus: Seat.FocusTarget = while (surface_it.next()) |surface| {
if (surface != lock_surface.wlr_lock_surface)
break .{ .lock_surface = @ptrCast(@alignCast(surface.data)) };
break .{ .lock_surface = @ptrFromInt(surface.data) };
} else .none;
var seat_it = server.input_manager.seats.iterator(.forward);
while (seat_it.next()) |seat| {
var seat_it = server.input_manager.seats.first;
while (seat_it) |node| : (seat_it = node.next) {
const seat = &node.data;
if (seat.focused == .lock_surface and seat.focused.lock_surface == lock_surface) {
seat.setFocusRaw(new_focus);
}
@ -85,13 +86,13 @@ pub fn destroy(lock_surface: *LockSurface) void {
lock_surface.surface_destroy.link.remove();
// The wlr_surface may outlive the wlr_lock_surface so we must clean up the user data.
lock_surface.wlr_lock_surface.surface.data = null;
lock_surface.wlr_lock_surface.surface.data = 0;
util.gpa.destroy(lock_surface);
}
pub fn getOutput(lock_surface: *LockSurface) *Output {
return @ptrCast(@alignCast(lock_surface.wlr_lock_surface.output.data));
return @ptrFromInt(lock_surface.wlr_lock_surface.output.data);
}
pub fn configure(lock_surface: *LockSurface) void {
@ -121,8 +122,9 @@ fn handleMap(listener: *wl.Listener(void)) void {
}
fn updateFocus(lock_surface: *LockSurface) void {
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| {
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const seat = &node.data;
if (seat.focused != .lock_surface) {
seat.setFocusRaw(.{ .lock_surface = lock_surface });
}

View File

@ -125,6 +125,10 @@ lock_render_state: enum {
lock_surface,
} = .blanked,
/// Set to true if a gamma control client makes a set gamma request.
/// This request is handled while rendering the next frame in handleFrame().
gamma_dirty: bool = false,
/// The state of the output that is directly acted upon/modified through user input.
///
/// Pending state will be copied to the inflight state and communicated to clients
@ -167,7 +171,7 @@ previous_tags: u32 = 1 << 0,
attach_mode: ?Config.AttachMode = null,
/// List of all layouts
layouts: wl.list.Head(Layout, .link),
layouts: std.TailQueue(Layout) = .{},
/// The current layout namespace of the output. If null,
/// config.default_layout_namespace should be used instead.
@ -290,11 +294,8 @@ pub fn create(wlr_output: *wlr.Output) !void {
.height = height,
},
.status = undefined,
.layouts = undefined,
};
wlr_output.data = output;
output.layouts.init();
wlr_output.data = @intFromPtr(output);
output.pending.focus_stack.init();
output.pending.wm_stack.init();
@ -363,7 +364,7 @@ fn sendLayerConfigures(
var it = tree.children.safeIterator(.forward);
while (it.next()) |node| {
assert(node.type == .tree);
if (@as(?*SceneNodeData, @ptrCast(@alignCast(node.data)))) |node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
const layer_surface = node_data.data.layer_surface;
if (!layer_surface.wlr_layer_surface.initialized) continue;
@ -419,7 +420,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
assert(output.inflight.focus_stack.empty());
assert(output.inflight.wm_stack.empty());
assert(output.inflight.layout_demand == null);
assert(output.layouts.length() == 0);
assert(output.layouts.len == 0);
output.all_link.remove();
@ -432,7 +433,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
if (output.layout_namespace) |namespace| util.gpa.free(namespace);
output.wlr_output.data = null;
output.wlr_output.data = 0;
util.gpa.destroy(output);
@ -455,7 +456,7 @@ fn handleRequestState(listener: *wl.Listener(*wlr.Output.event.RequestState), ev
// TODO double buffer output state changes for frame perfection and cleaner code.
// Schedule a frame and commit in the frame handler.
// Get rid of this function.
pub fn applyState(output: *Output, state: *const wlr.Output.State) error{CommitFailed}!void {
pub fn applyState(output: *Output, state: *wlr.Output.State) error{CommitFailed}!void {
// We need to be precise about this state change to make assertions
// in updateLockRenderStateOnEnableDisable() possible.
@ -479,6 +480,7 @@ pub fn applyState(output: *Output, state: *const wlr.Output.State) error{CommitF
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
@ -530,21 +532,44 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
// TODO this should probably be retried on failure
output.renderAndCommit(scene_output) catch |err| switch (err) {
error.OutOfMemory => log.err("out of memory", .{}),
error.CommitFailed => log.err("output commit failed for {s}", .{output.wlr_output.name}),
};
var now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
var now: posix.timespec = undefined;
posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
scene_output.sendFrameDone(&now);
}
fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void {
if (!scene_output.needsFrame()) return;
// 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;
@ -559,6 +584,8 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void {
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)
@ -622,7 +649,7 @@ fn handlePresent(
}
fn setTitle(output: Output) void {
const title = fmt.allocPrintSentinel(util.gpa, "river - {s}", .{output.wlr_output.name}, 0) catch return;
const title = fmt.allocPrintZ(util.gpa, "river - {s}", .{output.wlr_output.name}) catch return;
defer util.gpa.free(title);
if (output.wlr_output.isWl()) {
output.wlr_output.wlSetTitle(title);
@ -634,9 +661,9 @@ fn setTitle(output: Output) void {
pub fn handleLayoutNamespaceChange(output: *Output) void {
// The user changed the layout namespace of this output. Try to find a
// matching layout.
var it = output.layouts.iterator(.forward);
output.layout = while (it.next()) |layout| {
if (mem.eql(u8, output.layoutNamespace(), layout.namespace)) break layout;
var it = output.layouts.first;
output.layout = while (it) |node| : (it = node.next) {
if (mem.eql(u8, output.layoutNamespace(), node.data.namespace)) break &node.data;
} else null;
server.root.applyPending();
}

View File

@ -47,7 +47,7 @@ commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit)
node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy),
pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void {
const seat: *Seat = @ptrCast(@alignCast(wlr_constraint.seat.data));
const seat: *Seat = @ptrFromInt(wlr_constraint.seat.data);
const constraint = try util.gpa.create(PointerConstraint);
errdefer util.gpa.destroy(constraint);
@ -55,7 +55,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
constraint.* = .{
.wlr_constraint = wlr_constraint,
};
wlr_constraint.data = constraint;
wlr_constraint.data = @intFromPtr(constraint);
wlr_constraint.events.destroy.add(&constraint.destroy);
wlr_constraint.surface.events.commit.add(&constraint.commit);
@ -70,7 +70,7 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
}
pub fn maybeActivate(constraint: *PointerConstraint) void {
const seat: *Seat = @ptrCast(@alignCast(constraint.wlr_constraint.seat.data));
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.cursor.constraint == constraint);
@ -102,7 +102,7 @@ pub fn maybeActivate(constraint: *PointerConstraint) void {
/// Called when the cursor position or content in the scene graph changes
pub fn updateState(constraint: *PointerConstraint) void {
const seat: *Seat = @ptrCast(@alignCast(constraint.wlr_constraint.seat.data));
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
constraint.maybeActivate();
@ -154,7 +154,7 @@ pub fn confine(constraint: *PointerConstraint, dx: *f64, dy: *f64) void {
}
pub fn deactivate(constraint: *PointerConstraint) void {
const seat: *Seat = @ptrCast(@alignCast(constraint.wlr_constraint.seat.data));
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
assert(seat.cursor.constraint == constraint);
assert(constraint.state == .active);
@ -167,7 +167,7 @@ pub fn deactivate(constraint: *PointerConstraint) void {
}
fn warpToHintIfSet(constraint: *PointerConstraint) void {
const seat: *Seat = @ptrCast(@alignCast(constraint.wlr_constraint.seat.data));
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
if (constraint.wlr_constraint.current.cursor_hint.enabled) {
var lx: i32 = undefined;
@ -190,7 +190,7 @@ fn handleNodeDestroy(listener: *wl.Listener(void)) void {
fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void {
const constraint: *PointerConstraint = @fieldParentPtr("destroy", listener);
const seat: *Seat = @ptrCast(@alignCast(constraint.wlr_constraint.seat.data));
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
if (constraint.state == .active) {
// We can't simply call deactivate() here as it calls sendDeactivated(),
@ -215,7 +215,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point
// the surface changes.
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
const constraint: *PointerConstraint = @fieldParentPtr("commit", listener);
const seat: *Seat = @ptrCast(@alignCast(constraint.wlr_constraint.seat.data));
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
switch (constraint.state) {
.active => |state| {

View File

@ -97,6 +97,8 @@ power_manager_set_mode: wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode) =
wl.Listener(*wlr.OutputPowerManagerV1.event.SetMode).init(handlePowerManagerSetMode),
gamma_control_manager: *wlr.GammaControlManagerV1,
gamma_control_set_gamma: wl.Listener(*wlr.GammaControlManagerV1.event.SetGamma) =
wl.Listener(*wlr.GammaControlManagerV1.event.SetGamma).init(handleSetGamma),
/// A list of all outputs
all_outputs: wl.list.Head(Output, .all_link),
@ -121,11 +123,6 @@ pub fn init(root: *Root) !void {
const scene = try wlr.Scene.create();
errdefer scene.tree.node.destroy();
const gamma_control_manager = try wlr.GammaControlManagerV1.create(server.wl_server);
scene.setGammaControlManagerV1(gamma_control_manager);
if (server.linux_dmabuf) |linux_dmabuf| scene.setLinuxDmabufV1(linux_dmabuf);
const interactive_content = try scene.tree.createSceneTree();
const drag_icons = try scene.tree.createSceneTree();
const hidden_tree = try scene.tree.createSceneTree();
@ -166,11 +163,11 @@ pub fn init(root: *Root) !void {
.all_outputs = undefined,
.active_outputs = undefined,
.presentation = try wlr.Presentation.create(server.wl_server, server.backend, 2),
.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),
.gamma_control_manager = gamma_control_manager,
.gamma_control_manager = try wlr.GammaControlManagerV1.create(server.wl_server),
.transaction_timeout = transaction_timeout,
};
root.hidden.pending.focus_stack.init();
@ -190,14 +187,10 @@ pub fn init(root: *Root) !void {
root.output_manager.events.@"test".add(&root.manager_test);
root.output_layout.events.change.add(&root.layout_change);
root.power_manager.events.set_mode.add(&root.power_manager_set_mode);
root.gamma_control_manager.events.set_gamma.add(&root.gamma_control_set_gamma);
}
pub fn deinit(root: *Root) void {
root.manager_apply.link.remove();
root.manager_test.link.remove();
root.layout_change.link.remove();
root.power_manager_set_mode.link.remove();
root.output_layout.destroy();
root.transaction_timeout.remove();
}
@ -330,15 +323,16 @@ pub fn deactivateOutput(root: *Root, output: *Output) void {
var it = tree.children.safeIterator(.forward);
while (it.next()) |scene_node| {
assert(scene_node.type == .tree);
if (@as(?*SceneNodeData, @ptrCast(@alignCast(scene_node.data)))) |node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(scene_node.data))) |node_data| {
node_data.data.layer_surface.wlr_layer_surface.destroy();
}
}
}
// If any seat has the removed output focused, focus the fallback one
var seat_it = server.input_manager.seats.iterator(.forward);
while (seat_it.next()) |seat| {
var seat_it = server.input_manager.seats.first;
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
const seat = &seat_node.data;
if (seat.focused_output == output) {
seat.focusOutput(fallback_output);
}
@ -352,7 +346,7 @@ pub fn deactivateOutput(root: *Root, output: *Output) void {
output.inflight.layout_demand = null;
root.notifyLayoutDemandDone();
}
while (output.layouts.first()) |layout| layout.destroy();
while (output.layouts.first) |node| node.data.destroy();
// We must call reconfigureDevices here to unmap devices that might be mapped to this output
// in order to prevent a segfault in wlroots.
@ -396,8 +390,9 @@ pub fn activateOutput(root: *Root, output: *Output) void {
}
{
// Focus the new output with all seats
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| {
var it = server.input_manager.seats.first;
while (it) |seat_node| : (it = seat_node.next) {
const seat = &seat_node.data;
seat.focusOutput(output);
}
}
@ -433,8 +428,8 @@ pub fn applyPending(root: *Root) void {
// state consistent. Instead of having focus(null) calls spread all
// around the codebase and risk forgetting one, always ensure focus
// state is synchronized here.
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| seat.focus(null);
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) node.data.focus(null);
}
// If there is already a transaction inflight, wait until it completes.
@ -544,9 +539,11 @@ pub fn applyPending(root: *Root) void {
}
{
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| {
switch (seat.cursor.mode) {
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const cursor = &node.data.cursor;
switch (cursor.mode) {
.passthrough, .down => {},
inline .move, .resize => |data| {
if (data.view.inflight.output == null or
@ -554,14 +551,14 @@ pub fn applyPending(root: *Root) void {
(!data.view.inflight.float and data.view.inflight.output.?.layout != null) or
data.view.inflight.fullscreen)
{
seat.cursor.mode = .passthrough;
cursor.mode = .passthrough;
data.view.pending.resizing = false;
data.view.inflight.resizing = false;
}
},
}
seat.cursor.inflight_mode = seat.cursor.mode;
cursor.inflight_mode = cursor.mode;
}
}
@ -706,8 +703,11 @@ fn commitTransaction(root: *Root) void {
}
{
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| seat.cursor.updateState();
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
node.data.cursor.updateState();
node.data.sendFocusedView();
}
}
{
@ -798,7 +798,7 @@ fn processOutputConfig(
var it = config.heads.iterator(.forward);
while (it.next()) |head| {
const wlr_output = head.state.output;
const output: *Output = @ptrCast(@alignCast(wlr_output.data));
const output: *Output = @ptrFromInt(wlr_output.data);
var proposed_state = wlr.Output.State.init();
head.state.apply(&proposed_state);
@ -850,7 +850,7 @@ fn handlePowerManagerSetMode(
event: *wlr.OutputPowerManagerV1.event.SetMode,
) void {
// The output may have been destroyed, in which case there is nothing to do
const output: *Output = @ptrCast(@alignCast(event.output.data orelse return));
const output = @as(?*Output, @ptrFromInt(event.output.data)) orelse return;
std.log.debug("client requested dpms {s} for output {s}", .{
@tagName(event.mode),
@ -880,4 +880,18 @@ fn handlePowerManagerSetMode(
}
output.updateLockRenderStateOnEnableDisable();
output.gamma_dirty = true;
}
fn handleSetGamma(
_: *wl.Listener(*wlr.GammaControlManagerV1.event.SetGamma),
event: *wlr.GammaControlManagerV1.event.SetGamma,
) void {
// The output may have been destroyed, in which case there is nothing to do
const output = @as(?*Output, @ptrFromInt(event.output.data)) orelse return;
std.log.debug("client requested to set gamma", .{});
output.gamma_dirty = true;
output.wlr_output.scheduleFrame();
}

View File

@ -46,7 +46,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
.node = node,
.data = data,
};
node.data = scene_node_data;
node.data = @intFromPtr(scene_node_data);
node.events.destroy.add(&scene_node_data.destroy);
}
@ -54,7 +54,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
var n = node;
while (true) {
if (@as(?*SceneNodeData, @ptrCast(@alignCast(n.data)))) |scene_node_data| {
if (@as(?*SceneNodeData, @ptrFromInt(n.data))) |scene_node_data| {
return scene_node_data;
}
if (n.parent) |parent_tree| {
@ -66,7 +66,7 @@ pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
}
pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData {
if (@as(?*wlr.SceneNode, @ptrCast(@alignCast(surface.getRootSurface().data)))) |node| {
if (@as(?*wlr.SceneNode, @ptrFromInt(surface.getRootSurface().data))) |node| {
return fromNode(node);
}
return null;
@ -76,7 +76,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
const scene_node_data: *SceneNodeData = @fieldParentPtr("destroy", listener);
scene_node_data.destroy.link.remove();
scene_node_data.node.data = null;
scene_node_data.node.data = 0;
util.gpa.destroy(scene_node_data);
}

View File

@ -91,7 +91,7 @@ focused_output: ?*Output = null,
focused: FocusTarget = .none,
/// List of status tracking objects relaying changes to this seat to clients.
status_trackers: wl.list.Head(SeatStatus, .link),
status_trackers: std.SinglyLinkedList(SeatStatus) = .{},
/// The currently in progress drag operation type.
drag: enum {
@ -109,13 +109,7 @@ drag_destroy: wl.Listener(*wlr.Drag) = wl.Listener(*wlr.Drag).init(handleDragDes
request_set_primary_selection: wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection) =
wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection).init(handleRequestSetPrimarySelection),
// InputManager.seats
link: wl.list.Link = undefined,
pub fn create(name: [*:0]const u8) !void {
const seat = try util.gpa.create(Seat);
errdefer util.gpa.destroy(seat);
pub fn init(seat: *Seat, name: [*:0]const u8) !void {
const event_loop = server.wl_server.getEventLoop();
const mapping_repeat_timer = try event_loop.addTimer(*Seat, handleMappingRepeatTimeout, seat);
errdefer mapping_repeat_timer.remove();
@ -127,18 +121,13 @@ pub fn create(name: [*:0]const u8) !void {
.relay = undefined,
.mapping_repeat_timer = mapping_repeat_timer,
.keyboard_group = try wlr.KeyboardGroup.create(),
.status_trackers = undefined,
.link = undefined,
};
seat.wlr_seat.data = seat;
server.input_manager.seats.append(seat);
seat.status_trackers.init();
seat.wlr_seat.data = @intFromPtr(seat);
try seat.cursor.init(seat);
seat.relay.init();
try seat.tryAddDevice(&seat.keyboard_group.keyboard.base, false);
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);
@ -146,7 +135,7 @@ pub fn create(name: [*:0]const u8) !void {
seat.wlr_seat.events.request_set_primary_selection.add(&seat.request_set_primary_selection);
}
pub fn destroy(seat: *Seat) void {
pub fn deinit(seat: *Seat) void {
{
var it = server.input_manager.devices.iterator(.forward);
while (it.next()) |device| assert(device.seat != seat);
@ -162,10 +151,6 @@ pub fn destroy(seat: *Seat) void {
seat.start_drag.link.remove();
if (seat.drag != .none) seat.drag_destroy.link.remove();
seat.request_set_primary_selection.link.remove();
seat.link.remove();
util.gpa.destroy(seat);
}
/// Set the current focus. If a visible view is passed it will be focused.
@ -304,7 +289,7 @@ pub fn setFocusRaw(seat: *Seat, new_focus: FocusTarget) void {
if (seat.cursor.constraint) |constraint| {
assert(constraint.wlr_constraint == wlr_constraint);
} else {
seat.cursor.constraint = @ptrCast(@alignCast(wlr_constraint.data));
seat.cursor.constraint = @ptrFromInt(wlr_constraint.data);
assert(seat.cursor.constraint != null);
}
}
@ -315,10 +300,7 @@ pub fn setFocusRaw(seat: *Seat, new_focus: FocusTarget) void {
seat.cursor.may_need_warp = true;
// Inform any clients tracking status of the change
var it = seat.status_trackers.iterator(.forward);
while (it.next()) |tracker| {
tracker.sendFocusedView();
}
seat.sendFocusedView();
}
/// Send keyboard enter/leave events and handle pointer constraints
@ -334,17 +316,16 @@ pub fn keyboardEnterOrLeave(seat: *Seat, target_surface: ?*wlr.Surface) void {
fn keyboardNotifyEnter(seat: *Seat, wlr_surface: *wlr.Surface) void {
if (seat.wlr_seat.getKeyboard()) |wlr_keyboard| {
const keyboard: *Keyboard = @ptrCast(@alignCast(wlr_keyboard.data));
const keyboard: *Keyboard = @ptrFromInt(wlr_keyboard.data);
var buffer: [Keyboard.Pressed.capacity]u32 = undefined;
var keycodes: std.ArrayList(u32) = .initBuffer(&buffer);
for (keyboard.pressed.slice()) |item| {
var keycodes: std.BoundedArray(u32, Keyboard.Pressed.capacity) = .{};
for (keyboard.pressed.keys.constSlice()) |item| {
if (item.consumer == .focus) keycodes.appendAssumeCapacity(item.code);
}
seat.wlr_seat.keyboardNotifyEnter(
wlr_surface,
keycodes.items,
keycodes.constSlice(),
&wlr_keyboard.modifiers,
);
} else {
@ -357,15 +338,15 @@ pub fn focusOutput(seat: *Seat, output: ?*Output) void {
if (seat.focused_output == output) return;
if (seat.focused_output) |old| {
var it = seat.status_trackers.iterator(.forward);
while (it.next()) |tracker| tracker.sendOutput(old, .unfocused);
var it = seat.status_trackers.first;
while (it) |node| : (it = node.next) node.data.sendOutput(old, .unfocused);
}
seat.focused_output = output;
if (seat.focused_output) |new| {
var it = seat.status_trackers.iterator(.forward);
while (it.next()) |tracker| tracker.sendOutput(new, .focused);
var it = seat.status_trackers.first;
while (it) |node| : (it = node.next) node.data.sendOutput(new, .focused);
}
// Depending on configuration and cursor position, changing output focus
@ -380,9 +361,9 @@ pub fn handleActivity(seat: Seat) void {
pub fn enterMode(seat: *Seat, mode_id: u32) void {
seat.mode_id = mode_id;
var it = seat.status_trackers.iterator(.forward);
while (it.next()) |tracker| {
tracker.sendMode(server.config.modes.items[mode_id].name);
var it = seat.status_trackers.first;
while (it) |node| : (it = node.next) {
node.data.sendMode(server.config.modes.items[mode_id].name);
}
}
@ -476,8 +457,8 @@ pub fn runCommand(seat: *Seat, args: []const [:0]const u8) void {
return;
};
if (out) |s| {
var stdout = std.fs.File.stdout().writer(&.{});
stdout.interface.print("{s}", .{s}) catch |err| {
const stdout = std.io.getStdOut().writer();
stdout.print("{s}", .{s}) catch |err| {
std.log.scoped(.command).err("{s}: write to stdout failed {}", .{ args[0], err });
};
}
@ -503,19 +484,19 @@ fn handleMappingRepeatTimeout(seat: *Seat) c_int {
return 0;
}
pub fn addDevice(seat: *Seat, wlr_device: *wlr.InputDevice, virtual: bool) void {
seat.tryAddDevice(wlr_device, virtual) catch |err| switch (err) {
pub fn addDevice(seat: *Seat, wlr_device: *wlr.InputDevice) void {
seat.tryAddDevice(wlr_device) catch |err| switch (err) {
error.OutOfMemory => log.err("out of memory", .{}),
};
}
fn tryAddDevice(seat: *Seat, wlr_device: *wlr.InputDevice, virtual: bool) !void {
fn tryAddDevice(seat: *Seat, wlr_device: *wlr.InputDevice) !void {
switch (wlr_device.type) {
.keyboard => {
const keyboard = try util.gpa.create(Keyboard);
errdefer util.gpa.destroy(keyboard);
try keyboard.init(seat, wlr_device, virtual);
try keyboard.init(seat, wlr_device);
seat.wlr_seat.setKeyboard(keyboard.device.wlr_device.toKeyboard());
if (seat.wlr_seat.keyboard_state.focused_surface) |wlr_surface| {

View File

@ -33,19 +33,8 @@ const View = @import("View.zig");
seat: *Seat,
seat_status_v1: *zriver.SeatStatusV1,
link: wl.list.Link,
pub fn create(seat: *Seat, seat_status_v1: *zriver.SeatStatusV1) !void {
const seat_status = try util.gpa.create(SeatStatus);
errdefer util.gpa.destroy(seat_status);
seat_status.* = .{
.seat = seat,
.seat_status_v1 = seat_status_v1,
.link = undefined,
};
seat.status_trackers.append(seat_status);
errdefer comptime unreachable;
pub fn init(seat_status: *SeatStatus, seat: *Seat, seat_status_v1: *zriver.SeatStatusV1) void {
seat_status.* = .{ .seat = seat, .seat_status_v1 = seat_status_v1 };
seat_status_v1.setHandler(*SeatStatus, handleRequest, handleDestroy, seat_status);
@ -62,8 +51,9 @@ fn handleRequest(seat_status_v1: *zriver.SeatStatusV1, request: zriver.SeatStatu
}
fn handleDestroy(_: *zriver.SeatStatusV1, seat_status: *SeatStatus) void {
seat_status.link.remove();
util.gpa.destroy(seat_status);
const node: *std.SinglyLinkedList(SeatStatus).Node = @fieldParentPtr("data", seat_status);
seat_status.seat.status_trackers.remove(node);
util.gpa.destroy(node);
}
pub fn sendOutput(seat_status: SeatStatus, output: *Output, state: enum { focused, unfocused }) void {

View File

@ -24,7 +24,7 @@ const posix = std.posix;
const wlr = @import("wlroots");
const wl = @import("wayland").server.wl;
const c = @import("c.zig").c;
const c = @import("c.zig");
const util = @import("util.zig");
const Config = @import("Config.zig");
@ -61,8 +61,8 @@ allocator: *wlr.Allocator,
security_context_manager: *wlr.SecurityContextManagerV1,
shm: *wlr.Shm,
drm: ?*wlr.Drm = null,
linux_dmabuf: ?*wlr.LinuxDmabufV1 = null,
linux_drm_syncobj_manager: ?*wlr.LinuxDrmSyncobjManagerV1 = null,
single_pixel_buffer_manager: *wlr.SinglePixelBufferManagerV1,
viewporter: *wlr.Viewporter,
@ -85,8 +85,6 @@ screencopy_manager: *wlr.ScreencopyManagerV1,
foreign_toplevel_manager: *wlr.ForeignToplevelManagerV1,
foreign_toplevel_list: *wlr.ExtForeignToplevelListV1,
tearing_control_manager: *wlr.TearingControlManagerV1,
alpha_modifier: *wlr.AlphaModifierV1,
@ -166,8 +164,6 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
.foreign_toplevel_manager = try wlr.ForeignToplevelManagerV1.create(wl_server),
.foreign_toplevel_list = try wlr.ExtForeignToplevelListV1.create(wl_server, 1),
.tearing_control_manager = try wlr.TearingControlManagerV1.create(wl_server, 1),
.alpha_modifier = try wlr.AlphaModifierV1.create(wl_server),
@ -184,14 +180,14 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
};
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.
// TODO remove wl_drm support
server.drm = try wlr.Drm.create(wl_server, renderer);
server.linux_dmabuf = try wlr.LinuxDmabufV1.createWithRenderer(wl_server, 4, renderer);
}
if (renderer.features.timeline and backend.features.timeline) {
const drm_fd = renderer.getDrmFd();
if (drm_fd >= 0) {
server.linux_drm_syncobj_manager = wlr.LinuxDrmSyncobjManagerV1.create(wl_server, 1, drm_fd);
}
}
if (build_options.xwayland and runtime_xwayland) {
server.xwayland = try wlr.Xwayland.create(wl_server, compositor, false);
@ -237,8 +233,6 @@ pub fn deinit(server: *Server) void {
server.wl_server.destroyClients();
server.input_manager.new_input.link.remove();
server.root.new_output.link.remove();
server.backend.destroy();
// The scene graph needs to be destroyed after the backend but before the renderer
@ -299,12 +293,8 @@ fn globalFilter(client: *const wl.Client, global: *const wl.Global, server: *Ser
/// Returns true if the global is allowlisted for security contexts
fn allowlist(server: *Server, global: *const wl.Global) bool {
if (server.linux_dmabuf) |linux_dmabuf| {
if (global == linux_dmabuf.global) return true;
}
if (server.linux_drm_syncobj_manager) |linux_drm_syncobj_manager| {
if (global == linux_drm_syncobj_manager.global) return true;
}
if (server.drm) |drm| if (global == drm.global) return true;
if (server.linux_dmabuf) |linux_dmabuf| if (global == linux_dmabuf.global) return true;
// We must use the getInterface() approach for dynamically created globals
// such as wl_output and wl_seat since the wl_global_create() function will
@ -348,7 +338,6 @@ fn blocklist(server: *Server, global: *const wl.Global) bool {
return global == server.security_context_manager.global or
global == server.layer_shell.global or
global == server.foreign_toplevel_manager.global or
global == server.foreign_toplevel_list.global or
global == server.screencopy_manager.global or
global == server.export_dmabuf_manager.global or
global == server.data_control_manager.global or
@ -510,7 +499,7 @@ fn handleRequestSetCursorShape(
_: *wl.Listener(*wlr.CursorShapeManagerV1.event.RequestSetShape),
event: *wlr.CursorShapeManagerV1.event.RequestSetShape,
) void {
const seat: *Seat = @ptrCast(@alignCast(event.seat_client.seat.data));
const seat: *Seat = @ptrFromInt(event.seat_client.seat.data);
if (event.tablet_tool) |wp_tool| {
assert(event.device_type == .tablet_tool);

View File

@ -69,7 +69,7 @@ fn handleRequest(
.get_river_output_status => |req| {
// ignore if the output is inert
const wlr_output = wlr.Output.fromWlOutput(req.output) orelse return;
const output: *Output = @ptrCast(@alignCast(wlr_output.data));
const output: *Output = @ptrFromInt(wlr_output.data);
const resource = zriver.OutputStatusV1.create(
status_manager_v1.getClient(),
@ -86,7 +86,13 @@ fn handleRequest(
.get_river_seat_status => |req| {
// ignore if the seat is inert
const wlr_seat = wlr.Seat.Client.fromWlSeat(req.seat) orelse return;
const seat: *Seat = @ptrCast(@alignCast(wlr_seat.seat.data));
const seat: *Seat = @ptrFromInt(wlr_seat.seat.data);
const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch {
status_manager_v1.getClient().postNoMemory();
log.err("out of memory", .{});
return;
};
const seat_status = zriver.SeatStatusV1.create(
status_manager_v1.getClient(),
@ -94,15 +100,13 @@ fn handleRequest(
req.id,
) catch {
status_manager_v1.getClient().postNoMemory();
util.gpa.destroy(node);
log.err("out of memory", .{});
return;
};
SeatStatus.create(seat, seat_status) catch {
status_manager_v1.getClient().postNoMemory();
log.err("out of memory", .{});
return;
};
node.data.init(seat, seat_status);
seat.status_trackers.prepend(node);
},
}
}

View File

@ -59,7 +59,7 @@ set_cursor: wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor) =
wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor).init(handleSetCursor),
pub fn get(wlr_seat: *wlr.Seat, wlr_tool: *wlr.TabletTool) error{OutOfMemory}!*TabletTool {
if (@as(?*TabletTool, @ptrCast(@alignCast(wlr_tool.data)))) |tool| {
if (@as(?*TabletTool, @ptrFromInt(wlr_tool.data))) |tool| {
return tool;
} else {
return TabletTool.create(wlr_seat, wlr_tool);
@ -81,7 +81,7 @@ fn create(wlr_seat: *wlr.Seat, wlr_tool: *wlr.TabletTool) error{OutOfMemory}!*Ta
.wlr_cursor = wlr_cursor,
};
wlr_tool.data = tool;
wlr_tool.data = @intFromPtr(tool);
wlr_tool.events.destroy.add(&tool.destroy);
tool.wp_tool.events.set_cursor.add(&tool.set_cursor);
@ -92,7 +92,7 @@ fn create(wlr_seat: *wlr.Seat, wlr_tool: *wlr.TabletTool) error{OutOfMemory}!*Ta
fn handleDestroy(listener: *wl.Listener(*wlr.TabletTool), _: *wlr.TabletTool) void {
const tool: *TabletTool = @fieldParentPtr("destroy", listener);
tool.wp_tool.wlr_tool.data = null;
tool.wp_tool.wlr_tool.data = 0;
tool.wlr_cursor.destroy();

View File

@ -43,7 +43,7 @@ destroy: wl.Listener(*wlr.TextInputV3) =
wl.Listener(*wlr.TextInputV3).init(handleDestroy),
pub fn create(wlr_text_input: *wlr.TextInputV3) !void {
const seat: *Seat = @ptrCast(@alignCast(wlr_text_input.seat.data));
const seat: *Seat = @ptrFromInt(wlr_text_input.seat.data);
const text_input = try util.gpa.create(TextInput);
@ -64,7 +64,7 @@ pub fn create(wlr_text_input: *wlr.TextInputV3) !void {
fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
const text_input: *TextInput = @fieldParentPtr("enable", listener);
const seat: *Seat = @ptrCast(@alignCast(text_input.wlr_text_input.seat.data));
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
if (text_input.wlr_text_input.focused_surface == null) {
log.err("client requested to enable text input without focus, ignoring request", .{});
@ -91,7 +91,7 @@ fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v
fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
const text_input: *TextInput = @fieldParentPtr("commit", listener);
const seat: *Seat = @ptrCast(@alignCast(text_input.wlr_text_input.seat.data));
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
if (seat.relay.text_input != text_input) {
log.err("inactive text input tried to commit an update, client bug?", .{});
@ -105,7 +105,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v
fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
const text_input: *TextInput = @fieldParentPtr("disable", listener);
const seat: *Seat = @ptrCast(@alignCast(text_input.wlr_text_input.seat.data));
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
if (seat.relay.text_input == text_input) {
seat.relay.disableTextInput();
@ -114,7 +114,7 @@ fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3)
fn handleDestroy(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
const text_input: *TextInput = @fieldParentPtr("destroy", listener);
const seat: *Seat = @ptrCast(@alignCast(text_input.wlr_text_input.seat.data));
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
if (seat.relay.text_input == text_input) {
seat.relay.disableTextInput();

View File

@ -181,8 +181,6 @@ post_fullscreen_box: wlr.Box = undefined,
foreign_toplevel_handle: ForeignToplevelHandle = .{},
ext_foreign_toplevel_handle: ?*wlr.ExtForeignToplevelHandleV1 = null,
/// Connector name of the output this view occupied before an evacuation.
output_before_evac: ?[]const u8 = null,
@ -277,12 +275,11 @@ pub fn resizeUpdatePosition(view: *View, width: i32, height: i32) void {
assert(view.inflight.resizing);
const data = blk: {
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| {
if (seat.cursor.inflight_mode == .resize and
seat.cursor.inflight_mode.resize.view == view)
{
break :blk seat.cursor.inflight_mode.resize;
var it = server.input_manager.seats.first;
while (it) |node| : (it = node.next) {
const cursor = &node.data.cursor;
if (cursor.inflight_mode == .resize and cursor.inflight_mode.resize.view == view) {
break :blk cursor.inflight_mode.resize;
}
} else {
// The view resizing state should never be set when the view is
@ -449,11 +446,7 @@ pub fn updateSceneState(view: *View) void {
for (&view.borders, &border_boxes) |border, *border_box| {
border_box.x += box.x;
border_box.y += box.y;
if (!border_box.intersection(border_box, &output_box)) {
// TODO(wlroots): remove this redundant code after fixed upstream
// https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/5084
border_box.* = .{ .x = 0, .y = 0, .width = 0, .height = 0 };
}
_ = border_box.intersection(border_box, &output_box);
border_box.x -= box.x;
border_box.y -= box.y;
@ -489,7 +482,8 @@ pub fn rootSurface(view: View) ?*wlr.Surface {
pub fn sendFrameDone(view: View) void {
assert(view.mapped and !view.destroying);
const now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
var now: posix.timespec = undefined;
posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
view.rootSurface().?.sendFrameDone(&now);
}
@ -595,7 +589,7 @@ pub fn allowTearing(view: *View) bool {
.window_hint => {
if (server.config.allow_tearing) {
if (view.rootSurface()) |root_surface| {
return server.tearing_control_manager.hintFromSurface(root_surface) == .async;
return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async";
}
}
return false;
@ -659,15 +653,6 @@ pub fn map(view: *View) !void {
assert(!view.mapped and !view.destroying);
view.mapped = true;
if (wlr.ExtForeignToplevelHandleV1.create(server.foreign_toplevel_list, &.{
.title = view.getTitle(),
.app_id = view.getAppId(),
})) |handle| {
view.ext_foreign_toplevel_handle = handle;
} else |_| {
log.err("failed to create ext foreign toplevel handle", .{});
}
view.foreign_toplevel_handle.map();
if (server.config.rules.float.match(view)) |float| {
@ -721,8 +706,8 @@ pub fn map(view: *View) !void {
if (output) |o| {
view.setPendingOutput(o);
var it = server.input_manager.seats.iterator(.forward);
while (it.next()) |seat| seat.focus(view);
var it = server.input_manager.seats.first;
while (it) |seat_node| : (it = seat_node.next) seat_node.data.focus(view);
} else {
log.debug("no output available for newly mapped view, adding to fallback stacks", .{});
@ -767,10 +752,6 @@ pub fn unmap(view: *View) void {
assert(view.mapped and !view.destroying);
view.mapped = false;
if (view.ext_foreign_toplevel_handle) |handle| {
handle.destroy();
view.ext_foreign_toplevel_handle = null;
}
view.foreign_toplevel_handle.unmap();
server.root.applyPending();
@ -781,19 +762,12 @@ pub fn notifyState(view: *const View) void {
if (view.getTitle()) |title| wlr_handle.setTitle(title);
}
// Send title and tags to all status listeners attached to a seat which focuses this view
if (view.ext_foreign_toplevel_handle) |handle| {
handle.updateState(&.{
.title = view.getTitle(),
.app_id = view.getAppId(),
});
}
// Send title to all status listeners attached to a seat which focuses this view
var seat_it = server.input_manager.seats.iterator(.forward);
while (seat_it.next()) |seat| {
if (seat.focused == .view and seat.focused.view == view) {
var it = seat.status_trackers.iterator(.forward);
while (it.next()) |tracker| {
tracker.sendFocusedView();
var seat_it = server.input_manager.seats.first;
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
if (seat_node.data.focused == .view and seat_node.data.focused.view == view) {
var client_it = seat_node.data.status_trackers.first;
while (client_it) |client_node| : (client_it = client_node.next) {
client_node.data.sendFocusedView();
}
}
}
@ -803,11 +777,4 @@ pub fn notifyAppId(view: View) void {
if (view.foreign_toplevel_handle.wlr_handle) |wlr_handle| {
if (view.getAppId()) |app_id| wlr_handle.setAppId(app_id);
}
if (view.ext_foreign_toplevel_handle) |handle| {
handle.updateState(&.{
.title = view.getTitle(),
.app_id = view.getAppId(),
});
}
}

View File

@ -34,7 +34,7 @@ request_mode: wl.Listener(*wlr.XdgToplevelDecorationV1) =
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleRequestMode),
pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
const toplevel: *XdgToplevel = @ptrCast(@alignCast(wlr_decoration.toplevel.base.data));
const toplevel: *XdgToplevel = @ptrFromInt(wlr_decoration.toplevel.base.data);
toplevel.decoration = .{ .wlr_decoration = wlr_decoration };
const decoration = &toplevel.decoration.?;
@ -48,7 +48,7 @@ pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
}
pub fn deinit(decoration: *XdgDecoration) void {
const toplevel: *XdgToplevel = @ptrCast(@alignCast(decoration.wlr_decoration.toplevel.base.data));
const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
decoration.destroy.link.remove();
decoration.request_mode.link.remove();
@ -72,7 +72,7 @@ fn handleRequestMode(
) void {
const decoration: *XdgDecoration = @fieldParentPtr("request_mode", listener);
const toplevel: *XdgToplevel = @ptrCast(@alignCast(decoration.wlr_decoration.toplevel.base.data));
const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
const view = toplevel.view;
const ssd = server.config.rules.ssd.match(toplevel.view) orelse

View File

@ -100,8 +100,8 @@ pub fn create(wlr_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
toplevel.view = view;
wlr_toplevel.base.data = toplevel;
wlr_toplevel.base.surface.data = &view.tree.node;
wlr_toplevel.base.data = @intFromPtr(toplevel);
wlr_toplevel.base.surface.data = @intFromPtr(&view.tree.node);
// Add listeners that are active over the toplevel's entire lifetime
wlr_toplevel.events.destroy.add(&toplevel.destroy);
@ -216,7 +216,7 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
toplevel.new_popup.link.remove();
// The wlr_surface may outlive the wlr_xdg_toplevel so we must clean up the user data.
toplevel.wlr_toplevel.base.surface.data = null;
toplevel.wlr_toplevel.base.surface.data = 0;
const view = toplevel.view;
view.impl = .none;
@ -235,7 +235,7 @@ fn handleMap(listener: *wl.Listener(void)) void {
toplevel.wlr_toplevel.events.set_title.add(&toplevel.set_title);
toplevel.wlr_toplevel.events.set_app_id.add(&toplevel.set_app_id);
toplevel.geometry = toplevel.wlr_toplevel.base.geometry;
toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry);
view.pending.box = .{
.x = 0,
@ -338,7 +338,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
switch (toplevel.configure_state) {
.idle, .committed, .timed_out => {
const old_geometry = toplevel.geometry;
toplevel.geometry = toplevel.wlr_toplevel.base.geometry;
toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry);
const size_changed = toplevel.geometry.width != old_geometry.width or
toplevel.geometry.height != old_geometry.height;
@ -381,7 +381,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
// stashed buffer from when the transaction started.
.inflight => view.sendFrameDone(),
.acked, .timed_out_acked => {
toplevel.geometry = toplevel.wlr_toplevel.base.geometry;
toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry);
if (view.inflight.resizing) {
view.resizeUpdatePosition(toplevel.geometry.width, toplevel.geometry.height);
@ -423,7 +423,7 @@ fn handleRequestMove(
event: *wlr.XdgToplevel.event.Move,
) void {
const toplevel: *XdgToplevel = @fieldParentPtr("request_move", listener);
const seat: *Seat = @ptrCast(@alignCast(event.seat.seat.data));
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
const view = toplevel.view;
if (view.pending.fullscreen) return;
@ -446,7 +446,7 @@ fn handleRequestMove(
fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void {
const toplevel: *XdgToplevel = @fieldParentPtr("request_resize", listener);
const seat: *Seat = @ptrCast(@alignCast(event.seat.seat.data));
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
const view = toplevel.view;
if (view.pending.fullscreen) return;

View File

@ -120,7 +120,7 @@ fn mapImpl(override_redirect: *XwaylandOverrideRedirect) error{OutOfMemory}!void
.override_redirect = override_redirect,
});
surface.data = &override_redirect.surface_tree.?.node;
surface.data = @intFromPtr(&override_redirect.surface_tree.?.node);
override_redirect.surface_tree.?.node.setPosition(
override_redirect.xwayland_surface.x,
@ -159,14 +159,15 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
override_redirect.set_geometry.link.remove();
override_redirect.xwayland_surface.surface.?.data = null;
override_redirect.xwayland_surface.surface.?.data = 0;
override_redirect.surface_tree.?.node.destroy();
override_redirect.surface_tree = null;
// If the unmapped surface is currently focused, pass keyboard focus
// to the most appropriate surface.
var seat_it = server.input_manager.seats.iterator(.forward);
while (seat_it.next()) |seat| {
var seat_it = server.input_manager.seats.first;
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
const seat = &seat_node.data;
if (seat.focused == .view and seat.focused.view.impl == .xwayland_view and
seat.focused.view.impl.xwayland_view.xwayland_surface.pid == override_redirect.xwayland_surface.pid and
seat.wlr_seat.keyboard_state.focused_surface == override_redirect.xwayland_surface.surface)

View File

@ -164,7 +164,7 @@ pub fn handleMap(listener: *wl.Listener(void)) void {
const xwayland_surface = xwayland_view.xwayland_surface;
const surface = xwayland_surface.surface.?;
surface.data = &view.tree.node;
surface.data = @intFromPtr(&view.tree.node);
// Add listeners that are only active while mapped
xwayland_surface.events.set_title.add(&xwayland_view.set_title);
@ -215,12 +215,11 @@ pub fn handleMap(listener: *wl.Listener(void)) void {
fn handleUnmap(listener: *wl.Listener(void)) void {
const xwayland_view: *XwaylandView = @fieldParentPtr("unmap", listener);
xwayland_view.xwayland_surface.surface.?.data = null;
xwayland_view.xwayland_surface.surface.?.data = 0;
// Remove listeners that are only active while mapped
xwayland_view.set_title.link.remove();
xwayland_view.set_class.link.remove();
xwayland_view.set_decorations.link.remove();
xwayland_view.request_fullscreen.link.remove();
xwayland_view.request_minimize.link.remove();

View File

@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
pub const c = @cImport({
pub usingnamespace @cImport({
@cDefine("_POSIX_C_SOURCE", "200809L");
@cInclude("stdlib.h");

View File

@ -122,7 +122,6 @@ pub const Error = error{
CannotParseFile,
UnknownOption,
ConflictingOptions,
WriteFailed,
OutOfMemory,
Other,
};
@ -166,7 +165,7 @@ pub fn errToMsg(err: Error) [:0]const u8 {
Error.InvalidValue => "invalid value",
Error.CannotReadFile => "cannot read file",
Error.CannotParseFile => "cannot parse file",
Error.WriteFailed, Error.OutOfMemory => "out of memory",
Error.OutOfMemory => "out of memory",
Error.Other => unreachable,
};
}

View File

@ -35,8 +35,9 @@ pub fn cursor(
if (args.len < 3) return Error.NotEnoughArguments;
if (args.len > 3) return Error.TooManyArguments;
server.config.cursor_hide_timeout = try std.fmt.parseInt(u31, args[2], 10);
var seat_it = server.input_manager.seats.iterator(.forward);
while (seat_it.next()) |seat| {
var seat_it = server.input_manager.seats.first;
while (seat_it) |seat_node| : (seat_it = seat_node.next) {
const seat = &seat_node.data;
seat.cursor.unhide();
}
} else if (std.mem.eql(u8, "when-typing", args[1])) {

View File

@ -34,8 +34,8 @@ pub fn listInputs(
) Error!void {
if (args.len > 1) return error.TooManyArguments;
var aw: std.Io.Writer.Allocating = .init(util.gpa);
var input_list = std.ArrayList(u8).init(util.gpa);
const writer = input_list.writer();
var prev = false;
var it = server.input_manager.devices.iterator(.forward);
@ -46,16 +46,16 @@ pub fn listInputs(
}
} else false;
if (prev) try aw.writer.writeByte('\n');
if (prev) try input_list.appendSlice("\n");
prev = true;
try aw.writer.print("{s}\n\tconfigured: {}\n", .{
try writer.print("{s}\n\tconfigured: {}\n", .{
device.identifier,
configured,
});
}
out.* = try aw.toOwnedSlice();
out.* = try input_list.toOwnedSlice();
}
pub fn listInputConfigs(
@ -65,14 +65,15 @@ pub fn listInputConfigs(
) Error!void {
if (args.len > 1) return error.TooManyArguments;
var aw: std.Io.Writer.Allocating = .init(util.gpa);
var input_list = std.ArrayList(u8).init(util.gpa);
const writer = input_list.writer();
for (server.input_manager.configs.items, 0..) |*input_config, i| {
if (i > 0) try aw.writer.writeByte('\n');
try input_config.write(&aw.writer);
if (i > 0) try writer.writeByte('\n');
try input_config.write(writer);
}
out.* = try aw.toOwnedSlice();
out.* = try input_list.toOwnedSlice();
}
pub fn input(
@ -98,7 +99,7 @@ pub fn input(
};
errdefer util.gpa.free(input_config.glob);
try server.input_manager.configs.ensureUnusedCapacity(util.gpa, 1);
try server.input_manager.configs.ensureUnusedCapacity(1);
try input_config.parse(args[2], args[3]);

View File

@ -71,8 +71,9 @@ pub fn sendLayoutCmd(
const output = seat.focused_output orelse return;
const target_namespace = args[1];
var it = output.layouts.iterator(.forward);
const layout = while (it.next()) |layout| {
var it = output.layouts.first;
const layout = while (it) |node| : (it = node.next) {
const layout = &node.data;
if (mem.eql(u8, layout.namespace, target_namespace)) break layout;
} else return;

View File

@ -22,7 +22,7 @@ const wlr = @import("wlroots");
const xkb = @import("xkbcommon");
const flags = @import("flags");
const c = @import("../c.zig").c;
const c = @import("../c.zig");
const server = &@import("../main.zig").server;
const util = @import("../util.zig");
@ -285,7 +285,7 @@ fn parseKeysym(name: [:0]const u8, out: *?[]const u8) !xkb.Keysym {
}
fn parseModifiers(modifiers_str: []const u8, out: *?[]const u8) !wlr.Keyboard.ModifierMask {
var it = mem.splitScalar(u8, modifiers_str, '+');
var it = mem.split(u8, modifiers_str, "+");
var modifiers = wlr.Keyboard.ModifierMask{};
outer: while (it.next()) |mod_name| {
if (mem.eql(u8, mod_name, "None")) continue;

View File

@ -109,7 +109,7 @@ fn getOutput(seat: *Seat, str: []const u8) !?*Output {
.previous => link.prev.?,
};
}
return @fieldParentPtr("active_link", link);
return @as(*Output, @fieldParentPtr("active_link", link));
} else if (std.meta.stringToEnum(wlr.OutputLayout.Direction, str)) |direction| { // Spacial direction
var focus_box: wlr.Box = undefined;
server.root.output_layout.getBox(seat.focused_output.?.wlr_output, &focus_box);
@ -121,7 +121,7 @@ fn getOutput(seat: *Seat, str: []const u8) !?*Output {
@floatFromInt(focus_box.x + @divTrunc(focus_box.width, 2)),
@floatFromInt(focus_box.y + @divTrunc(focus_box.height, 2)),
) orelse return null;
return @ptrCast(@alignCast(wlr_output.data));
return @as(*Output, @ptrFromInt(wlr_output.data));
} else {
// Check if an output matches by name
var it = server.root.active_outputs.iterator(.forward);

View File

@ -15,7 +15,6 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
const std = @import("std");
const assert = std.debug.assert;
const fmt = std.fmt;
const globber = @import("globber");
@ -28,7 +27,6 @@ const Error = @import("../command.zig").Error;
const Seat = @import("../Seat.zig");
const View = @import("../View.zig");
const Anchor = @import("../Config.zig").Anchor;
const RuleGlobs = @import("../rule_list.zig").RuleGlobs;
const Action = enum {
float,
@ -189,7 +187,7 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
const action = std.meta.stringToEnum(Action, result.args[0]) orelse return Error.UnknownOption;
const rule: RuleGlobs = .{
const rule = .{
.app_id_glob = result.flags.@"app-id" orelse "*",
.title_glob = result.flags.title orelse "*",
};
@ -251,12 +249,6 @@ fn apply_tearing_rules() void {
}
}
fn alignLeft(buf: []const u8, width: usize, writer: *std.io.Writer) Error!void {
assert(buf.len <= width);
try writer.writeAll(buf);
try writer.splatByteAll(' ', width - buf.len);
}
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;
@ -278,12 +270,11 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
const app_id_column_max = 2 + @max("app-id".len, max_glob_len.app_id);
const title_column_max = 2 + @max("title".len, max_glob_len.title);
var buffer = std.io.Writer.Allocating.init(util.gpa);
defer buffer.deinit();
const writer = &buffer.writer;
var buffer = std.ArrayList(u8).init(util.gpa);
const writer = buffer.writer();
try alignLeft("title", title_column_max, writer);
try alignLeft("app-id", app_id_column_max, writer);
try fmt.formatBuf("title", .{ .width = title_column_max, .alignment = .left }, writer);
try fmt.formatBuf("app-id", .{ .width = app_id_column_max, .alignment = .left }, writer);
try writer.writeAll("action\n");
switch (rule_list) {
@ -298,8 +289,8 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
else => unreachable,
};
for (rules) |rule| {
try alignLeft(rule.title_glob, title_column_max, writer);
try alignLeft(rule.app_id_glob, app_id_column_max, writer);
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("{s}\n", .{switch (list) {
.float => if (rule.value) "float" else "no-float",
.ssd => if (rule.value) "ssd" else "csd",
@ -313,22 +304,22 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
},
.tags => {
for (server.config.rules.tags.rules.items) |rule| {
try alignLeft(rule.title_glob, title_column_max, writer);
try alignLeft(rule.app_id_glob, app_id_column_max, writer);
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("{b}\n", .{rule.value});
}
},
.position => {
for (server.config.rules.position.rules.items) |rule| {
try alignLeft(rule.title_glob, title_column_max, writer);
try alignLeft(rule.app_id_glob, app_id_column_max, writer);
try writer.print("{s},{d},{d}\n", .{ @tagName(rule.value.anchor), rule.value.x, rule.value.y });
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("{s},{d},{d}", .{ @tagName(rule.value.anchor), rule.value.x, rule.value.y });
}
},
.dimensions => {
for (server.config.rules.dimensions.rules.items) |rule| {
try alignLeft(rule.title_glob, title_column_max, writer);
try alignLeft(rule.app_id_glob, app_id_column_max, writer);
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}x{d}\n", .{ rule.value.width, rule.value.height });
}
},

View File

@ -17,7 +17,7 @@
const std = @import("std");
const posix = std.posix;
const c = @import("../c.zig").c;
const c = @import("../c.zig");
const util = @import("../util.zig");
const process = @import("../process.zig");

View File

@ -18,13 +18,14 @@ const build_options = @import("build_options");
const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const io = std.io;
const log = std.log;
const posix = std.posix;
const builtin = @import("builtin");
const wlr = @import("wlroots");
const flags = @import("flags");
const c = @import("c.zig").c;
const c = @import("c.zig");
const util = @import("util.zig");
const process = @import("process.zig");
@ -51,21 +52,21 @@ pub fn main() anyerror!void {
.{ .name = "log-level", .kind = .arg },
.{ .name = "no-xwayland", .kind = .boolean },
}).parse(std.os.argv[1..]) catch {
try fs.File.stderr().writeAll(usage);
try io.getStdErr().writeAll(usage);
posix.exit(1);
};
if (result.flags.h) {
try fs.File.stdout().writeAll(usage);
try io.getStdOut().writeAll(usage);
posix.exit(0);
}
if (result.args.len != 0) {
log.err("unknown option '{s}'", .{result.args[0]});
try fs.File.stderr().writeAll(usage);
try io.getStdErr().writeAll(usage);
posix.exit(1);
}
if (result.flags.version) {
try fs.File.stdout().writeAll(build_options.version ++ "\n");
try io.getStdOut().writeAll(build_options.version ++ "\n");
posix.exit(0);
}
if (result.flags.@"log-level") |level| {
@ -79,7 +80,7 @@ pub fn main() anyerror!void {
runtime_log_level = .debug;
} else {
log.err("invalid log level '{s}'", .{level});
try fs.File.stderr().writeAll(usage);
try io.getStdErr().writeAll(usage);
posix.exit(1);
}
}
@ -188,8 +189,8 @@ pub fn logFn(
const scope_prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
var stderr = fs.File.stderr().writer(&.{});
stderr.interface.print(level.asText() ++ scope_prefix ++ format ++ "\n", args) catch {};
const stderr = io.getStdErr().writer();
stderr.print(level.asText() ++ scope_prefix ++ format ++ "\n", args) catch {};
}
/// See wlroots_log_wrapper.c

View File

@ -17,7 +17,7 @@
const std = @import("std");
const posix = std.posix;
const c = @import("c.zig").c;
const c = @import("c.zig");
var original_rlimit: ?posix.rlimit = null;
@ -26,10 +26,10 @@ pub fn setup() void {
// has had its read end closed by another process.
const sig_ign = posix.Sigaction{
.handler = .{ .handler = posix.SIG.IGN },
.mask = posix.sigemptyset(),
.mask = posix.empty_sigset,
.flags = 0,
};
posix.sigaction(posix.SIG.PIPE, &sig_ign, null);
posix.sigaction(posix.SIG.PIPE, &sig_ign, null) catch unreachable;
// Most unix systems have a default limit of 1024 file descriptors and it
// seems unlikely for this default to be universally raised due to the
@ -61,14 +61,14 @@ pub fn setup() void {
pub fn cleanupChild() void {
if (c.setsid() < 0) unreachable;
if (posix.system.sigprocmask(posix.SIG.SETMASK, &posix.sigemptyset(), null) < 0) unreachable;
if (posix.system.sigprocmask(posix.SIG.SETMASK, &posix.empty_sigset, null) < 0) unreachable;
const sig_dfl = posix.Sigaction{
.handler = .{ .handler = posix.SIG.DFL },
.mask = posix.sigemptyset(),
.mask = posix.empty_sigset,
.flags = 0,
};
posix.sigaction(posix.SIG.PIPE, &sig_dfl, null);
posix.sigaction(posix.SIG.PIPE, &sig_dfl, null) catch unreachable;
if (original_rlimit) |original| {
posix.setrlimit(.NOFILE, original) catch {

View File

@ -23,11 +23,6 @@ const util = @import("util.zig");
const View = @import("View.zig");
pub const RuleGlobs = struct {
app_id_glob: []const u8,
title_glob: []const u8,
};
pub const MaxGlobLen = struct {
app_id: usize,
title: usize,
@ -88,7 +83,7 @@ pub fn RuleList(comptime T: type) type {
});
}
pub fn del(list: *List, rule: RuleGlobs) ?T {
pub fn del(list: *List, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) ?T {
for (list.rules.items, 0..) |existing, i| {
if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and
mem.eql(u8, rule.title_glob, existing.title_glob))

View File

@ -16,7 +16,7 @@
const std = @import("std");
const mem = std.mem;
const fs = std.fs;
const io = std.io;
const posix = std.posix;
const assert = std.debug.assert;
const builtin = @import("builtin");
@ -73,15 +73,15 @@ fn _main() !void {
.{ .name = "h", .kind = .boolean },
.{ .name = "version", .kind = .boolean },
}).parse(std.os.argv[1..]) catch {
try fs.File.stderr().writeAll(usage);
try io.getStdErr().writeAll(usage);
posix.exit(1);
};
if (result.flags.h) {
try fs.File.stdout().writeAll(usage);
try io.getStdOut().writeAll(usage);
posix.exit(0);
}
if (result.flags.version) {
try fs.File.stdout().writeAll(@import("build_options").version ++ "\n");
try io.getStdOut().writeAll(@import("build_options").version ++ "\n");
posix.exit(0);
}
@ -125,8 +125,8 @@ fn callbackListener(_: *zriver.CommandCallbackV1, event: zriver.CommandCallbackV
switch (event) {
.success => |success| {
if (mem.len(success.output) > 0) {
var stdout = fs.File.stdout().writer(&.{});
stdout.interface.print("{s}\n", .{success.output}) catch @panic("failed to write to stdout");
const stdout = io.getStdOut().writer();
stdout.print("{s}\n", .{success.output}) catch @panic("failed to write to stdout");
}
posix.exit(0);
},
@ -134,7 +134,7 @@ fn callbackListener(_: *zriver.CommandCallbackV1, event: zriver.CommandCallbackV
// A small hack to provide usage text when river reports an unknown command.
if (mem.orderZ(u8, failure.failure_message, "unknown command") == .eq) {
std.log.err("unknown command", .{});
fs.File.stderr().writeAll(usage) catch {};
io.getStdErr().writeAll(usage) catch {};
posix.exit(1);
}
fatal("{s}", .{failure.failure_message});

View File

@ -91,12 +91,15 @@ const gpa = std.heap.c_allocator;
const Context = struct {
initialized: bool = false,
layout_manager: ?*river.LayoutManagerV3 = null,
outputs: wl.list.Head(Output, .link),
outputs: std.TailQueue(Output) = .{},
fn addOutput(context: *Context, registry: *wl.Registry, name: u32) !void {
const wl_output = try registry.bind(name, wl.Output, 3);
errdefer wl_output.release();
try Output.create(context, wl_output, name);
const node = try gpa.create(std.TailQueue(Output).Node);
errdefer gpa.destroy(node);
try node.data.init(context, wl_output, name);
context.outputs.append(node);
}
};
@ -110,21 +113,15 @@ const Output = struct {
layout: *river.LayoutV3 = undefined,
link: wl.list.Link,
fn create(context: *Context, wl_output: *wl.Output, name: u32) !void {
const output = try gpa.create(Output);
errdefer gpa.destroy(output);
fn init(output: *Output, context: *Context, wl_output: *wl.Output, name: u32) !void {
output.* = .{
.wl_output = wl_output,
.name = name,
.main_location = default_main_location,
.main_count = default_main_count,
.main_ratio = default_main_ratio,
.link = undefined,
};
if (context.initialized) try output.getLayout(context);
context.outputs.append(output);
}
fn getLayout(output: *Output, context: *Context) !void {
@ -133,11 +130,9 @@ const Output = struct {
output.layout.setListener(*Output, layoutListener, output);
}
fn destroy(output: *Output) void {
fn deinit(output: *Output) void {
output.wl_output.release();
output.layout.destroy();
output.link.remove();
gpa.destroy(output);
}
fn layoutListener(layout: *river.LayoutV3, event: river.LayoutV3.Event, output: *Output) void {
@ -145,7 +140,7 @@ const Output = struct {
.namespace_in_use => fatal("namespace 'rivertile' already in use.", .{}),
.user_command => |ev| {
var it = mem.tokenizeScalar(u8, mem.span(ev.command), ' ');
var it = mem.tokenize(u8, mem.span(ev.command), " ");
const raw_cmd = it.next() orelse {
std.log.err("not enough arguments", .{});
return;
@ -317,17 +312,17 @@ pub fn main() !void {
.{ .name = "main-count", .kind = .arg },
.{ .name = "main-ratio", .kind = .arg },
}).parse(std.os.argv[1..]) catch {
try std.fs.File.stderr().writeAll(usage);
try std.io.getStdErr().writeAll(usage);
posix.exit(1);
};
if (result.flags.h) {
try std.fs.File.stdout().writeAll(usage);
try std.io.getStdOut().writeAll(usage);
posix.exit(0);
}
if (result.args.len != 0) fatalPrintUsage("unknown option '{s}'", .{result.args[0]});
if (result.flags.version) {
try std.fs.File.stdout().writeAll(@import("build_options").version ++ "\n");
try std.io.getStdOut().writeAll(@import("build_options").version ++ "\n");
posix.exit(0);
}
if (result.flags.@"view-padding") |raw| {
@ -361,10 +356,7 @@ pub fn main() !void {
};
defer display.disconnect();
var context: Context = .{
.outputs = undefined,
};
context.outputs.init();
var context: Context = .{};
const registry = try display.getRegistry();
registry.setListener(*Context, registryListener, &context);
@ -376,8 +368,9 @@ pub fn main() !void {
context.initialized = true;
var it = context.outputs.iterator(.forward);
while (it.next()) |output| {
var it = context.outputs.first;
while (it) |node| : (it = node.next) {
const output = &node.data;
try output.getLayout(&context);
}
@ -396,10 +389,13 @@ fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *
}
},
.global_remove => |ev| {
var it = context.outputs.safeIterator(.forward);
while (it.next()) |output| {
var it = context.outputs.first;
while (it) |node| : (it = node.next) {
const output = &node.data;
if (output.name == ev.name) {
output.destroy();
context.outputs.remove(node);
output.deinit();
gpa.destroy(node);
break;
}
}
@ -414,7 +410,7 @@ fn fatal(comptime format: []const u8, args: anytype) noreturn {
fn fatalPrintUsage(comptime format: []const u8, args: anytype) noreturn {
std.log.err(format, args);
std.fs.File.stderr().writeAll(usage) catch {};
std.io.getStdErr().writeAll(usage) catch {};
posix.exit(1);
}