Merge branch '0.3.x' of https://codeberg.org/river/river
This commit is contained in:
commit
0c095f0c93
@ -14,6 +14,7 @@ packages:
|
||||
- xcb-util-wm-dev
|
||||
- pixman-dev
|
||||
- libevdev-dev
|
||||
- wayland-dev
|
||||
- wayland-protocols
|
||||
- xwayland-dev
|
||||
- meson
|
||||
@ -23,34 +24,29 @@ 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.22.0
|
||||
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
|
||||
sudo ninja -C build install
|
||||
cd ..
|
||||
|
||||
cd wlroots
|
||||
git checkout 0.17.2
|
||||
meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \
|
||||
-Dwerror=false -Db_ndebug=false -Dxcb-errors=disabled --prefix /usr
|
||||
git checkout 0.19.0
|
||||
meson setup build --auto-features=enabled -Drenderers=gles2 \
|
||||
-Dcolor-management=disabled -Dlibliftoff=disabled \
|
||||
-Dexamples=false -Dwerror=false -Db_ndebug=false \
|
||||
-Dxcb-errors=disabled --prefix /usr
|
||||
sudo ninja -C build/ install
|
||||
cd ..
|
||||
|
||||
wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz
|
||||
# Remove a lot of useless lines from tar output.
|
||||
tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null
|
||||
sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/
|
||||
sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig
|
||||
# Eat Github's resources rather than the Zig Software Foundation's resources!
|
||||
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz
|
||||
tar xf zig-linux-x86_64-0.14.0.tar.xz
|
||||
sudo mv zig-linux-x86_64-0.14.0/zig /usr/bin/
|
||||
sudo mv zig-linux-x86_64-0.14.0/lib /usr/lib/zig
|
||||
- build: |
|
||||
cd river
|
||||
zig build
|
||||
zig build --summary all
|
||||
- build_xwayland: |
|
||||
cd river
|
||||
zig build -Dxwayland
|
||||
zig build --summary all -Dxwayland
|
||||
- fmt: |
|
||||
cd river
|
||||
zig fmt --check river/
|
||||
|
@ -21,34 +21,29 @@ 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.22.0
|
||||
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
|
||||
sudo ninja -C build install
|
||||
cd ..
|
||||
|
||||
cd wlroots
|
||||
git checkout 0.17.2
|
||||
meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \
|
||||
-Dwerror=false -Db_ndebug=false --prefix /usr
|
||||
git checkout 0.19.0
|
||||
meson setup build --auto-features=enabled -Drenderers=gles2 \
|
||||
-Dcolor-management=disabled -Dlibliftoff=disabled \
|
||||
-Dexamples=false -Dwerror=false -Db_ndebug=false \
|
||||
-Dxcb-errors=disabled --prefix /usr
|
||||
sudo ninja -C build/ install
|
||||
cd ..
|
||||
|
||||
wget -nv https://ziglang.org/download/0.11.0/zig-linux-x86_64-0.11.0.tar.xz
|
||||
# Remove a lot of useless lines from tar output.
|
||||
tar -xvf zig-linux-x86_64-0.11.0.tar.xz 1>/dev/null
|
||||
sudo mv zig-linux-x86_64-0.11.0/zig /usr/bin/
|
||||
sudo mv zig-linux-x86_64-0.11.0/lib /usr/lib/zig
|
||||
# Eat Github's resources rather than the Zig Software Foundation's resources!
|
||||
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.14.0/zig-linux-x86_64-0.14.0.tar.xz
|
||||
tar xf zig-linux-x86_64-0.14.0.tar.xz
|
||||
sudo mv zig-linux-x86_64-0.14.0/zig /usr/bin/
|
||||
sudo mv zig-linux-x86_64-0.14.0/lib /usr/lib/zig
|
||||
- build: |
|
||||
cd river
|
||||
zig build
|
||||
zig build --summary all
|
||||
- build_xwayland: |
|
||||
cd river
|
||||
zig build -Dxwayland
|
||||
zig build --summary all -Dxwayland
|
||||
- fmt: |
|
||||
cd river
|
||||
zig fmt --check river/
|
||||
|
@ -7,6 +7,7 @@ packages:
|
||||
- devel/meson
|
||||
- devel/pkgconf
|
||||
- graphics/mesa-libs
|
||||
- graphics/wayland
|
||||
- graphics/wayland-protocols
|
||||
- misc/hwdata
|
||||
- x11/libX11
|
||||
@ -18,6 +19,7 @@ packages:
|
||||
- x11/xcb-util-renderutil
|
||||
- x11/xcb-util-wm
|
||||
- x11-servers/xwayland
|
||||
- security/ca_root_nss
|
||||
- sysutils/seatd
|
||||
- sysutils/libdisplay-info
|
||||
- gmake
|
||||
@ -25,34 +27,30 @@ 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.22.0
|
||||
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
|
||||
sudo ninja -C build install
|
||||
cd ..
|
||||
|
||||
cd wlroots
|
||||
git checkout 0.17.2
|
||||
meson setup build --auto-features=enabled -Drenderers=gles2 -Dexamples=false \
|
||||
-Dwerror=false -Db_ndebug=false --prefix /usr
|
||||
git checkout 0.19.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
|
||||
sudo ninja -C build/ install
|
||||
cd ..
|
||||
|
||||
wget -nv https://ziglang.org/download/0.11.0/zig-freebsd-x86_64-0.11.0.tar.xz
|
||||
# Remove a lot of useless lines from tar output.
|
||||
tar -xvf zig-freebsd-x86_64-0.11.0.tar.xz 1>/dev/null
|
||||
sudo mv zig-freebsd-x86_64-0.11.0/zig /usr/bin/
|
||||
sudo mv zig-freebsd-x86_64-0.11.0/lib /usr/lib/zig
|
||||
# Eat Github's resources rather than the Zig Software Foundation's resources!
|
||||
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.14.0/zig-freebsd-x86_64-0.14.0-unofficial.tar.xz
|
||||
tar xf zig-freebsd-x86_64-0.14.0-unofficial.tar.xz
|
||||
sudo mv zig-freebsd-x86_64-0.14.0-unofficial/zig /usr/bin/
|
||||
sudo mv zig-freebsd-x86_64-0.14.0-unofficial/lib /usr/lib/zig
|
||||
- build: |
|
||||
cd river
|
||||
zig build
|
||||
zig build --summary all
|
||||
- build_xwayland: |
|
||||
cd river
|
||||
zig build -Dxwayland
|
||||
zig build --summary all -Dxwayland
|
||||
- fmt: |
|
||||
cd river
|
||||
zig fmt --check river/
|
||||
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,2 +1,2 @@
|
||||
zig-cache/
|
||||
.zig-cache/
|
||||
zig-out/
|
||||
|
12
.gitmodules
vendored
12
.gitmodules
vendored
@ -1,12 +0,0 @@
|
||||
[submodule "deps/zig-wayland"]
|
||||
path = deps/zig-wayland
|
||||
url = https://codeberg.org/ifreund/zig-wayland
|
||||
[submodule "deps/zig-pixman"]
|
||||
path = deps/zig-pixman
|
||||
url = https://codeberg.org/ifreund/zig-pixman
|
||||
[submodule "deps/zig-xkbcommon"]
|
||||
path = deps/zig-xkbcommon
|
||||
url = https://codeberg.org/ifreund/zig-xkbcommon
|
||||
[submodule "deps/zig-wlroots"]
|
||||
path = deps/zig-wlroots
|
||||
url = https://codeberg.org/ifreund/zig-wlroots
|
39
PACKAGING.md
39
PACKAGING.md
@ -26,6 +26,45 @@ and is only compatible with that release and any patch releases. At the time
|
||||
of writing for example river is compatible with Zig 0.9.0 and 0.9.1 but
|
||||
not Zig 0.8.0 or 0.10.0.
|
||||
|
||||
## Zig Package Manager
|
||||
|
||||
River uses the built-in Zig package manager for its (few) Zig dependencies.
|
||||
By default, running `zig build` will fetch river's Zig dependencies from the
|
||||
internet and store them in the global zig cache before building river. Since
|
||||
accessing the internet is forbidden or at least frowned upon by most distro
|
||||
packaging infrastructure, there are ways to fetch the Zig dependencies in a
|
||||
separate step before building river:
|
||||
|
||||
1. Fetch step with internet access:
|
||||
|
||||
For each package in the `build.zig.zon` manifest file run the following command
|
||||
with the tarball URL in the `build.zig.zon`:
|
||||
|
||||
```
|
||||
zig fetch --global-cache-dir /tmp/foobar $URL
|
||||
```
|
||||
|
||||
This command will download and unpack the tarball, hash the contents of the
|
||||
tarball, and store the contents in the `/tmp/foobar/p/$HASH` directory. This
|
||||
hash should match the corresponding hash field in the `build.zig.zon`.
|
||||
|
||||
2. Build step with no internet access:
|
||||
|
||||
The `--system` flag for `zig build` takes a path to an arbitrary directory in
|
||||
which zig packages stored in subdirectories matching their hash can be found.
|
||||
|
||||
```
|
||||
zig build --system /tmp/foobar/p/ ...
|
||||
```
|
||||
|
||||
This flag will disable all internet access and error if a package is not found
|
||||
in the provided directory.
|
||||
|
||||
It is also possible for distros to distribute Zig package manager packages as
|
||||
distro packages, although there are still some rough edges as the support for
|
||||
this is not yet mature. See this patchset for Chimera Linux for an example of
|
||||
how this can work: https://github.com/chimera-linux/cports/pull/1395
|
||||
|
||||
## Build options
|
||||
|
||||
River is built using the Zig build system. To see all available build
|
||||
|
19
README.md
19
README.md
@ -7,7 +7,7 @@
|
||||
River is a dynamic tiling Wayland compositor with flexible runtime
|
||||
configuration.
|
||||
|
||||
Install from your [package manager](https://repology.org/project/river/versions) —
|
||||
Check [packaging status](https://repology.org/project/river-compositor/versions) —
|
||||
Join us at [#river](https://web.libera.chat/?channels=#river) on irc.libera.chat —
|
||||
Read our man pages, [wiki](https://codeberg.org/river/wiki), and
|
||||
[Code of Conduct](CODE_OF_CONDUCT.md)
|
||||
@ -51,21 +51,16 @@ commands to set up the user's configuration.
|
||||
|
||||
## Building
|
||||
|
||||
On cloning the repository, you must init and update the submodules as well
|
||||
with e.g.
|
||||
|
||||
```
|
||||
git submodule update --init
|
||||
```
|
||||
Note: If you are packaging river for distribution, see [PACKAGING.md](PACKAGING.md).
|
||||
|
||||
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.11
|
||||
- [zig](https://ziglang.org/download/) 0.14
|
||||
- wayland
|
||||
- wayland-protocols
|
||||
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.17.2
|
||||
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.19
|
||||
- xkbcommon
|
||||
- libevdev
|
||||
- pixman
|
||||
@ -76,10 +71,8 @@ Then run, for example:
|
||||
```
|
||||
zig build -Doptimize=ReleaseSafe --prefix ~/.local install
|
||||
```
|
||||
To enable experimental Xwayland support pass the `-Dxwayland` option as well.
|
||||
|
||||
If you are packaging river for distribution, see also
|
||||
[PACKAGING.md](PACKAGING.md).
|
||||
To enable Xwayland support pass the `-Dxwayland` option as well.
|
||||
Run `zig build -h` to see a list of all options.
|
||||
|
||||
## Usage
|
||||
|
||||
|
165
build.zig
165
build.zig
@ -4,13 +4,7 @@ const Build = std.Build;
|
||||
const fs = std.fs;
|
||||
const mem = std.mem;
|
||||
|
||||
const Scanner = @import("deps/zig-wayland/build.zig").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";
|
||||
const Scanner = @import("wayland").Scanner;
|
||||
|
||||
pub fn build(b: *Build) !void {
|
||||
const target = b.standardTargetOptions(.{});
|
||||
@ -18,6 +12,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,13 +59,13 @@ pub fn build(b: *Build) !void {
|
||||
if (mem.endsWith(u8, version, "-dev")) {
|
||||
var ret: u8 = undefined;
|
||||
|
||||
const git_describe_long = b.execAllowFail(
|
||||
const git_describe_long = b.runAllowFail(
|
||||
&.{ "git", "-C", b.build_root.path orelse ".", "describe", "--long" },
|
||||
&ret,
|
||||
.Inherit,
|
||||
) catch break :blk version;
|
||||
|
||||
var it = mem.split(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), "-");
|
||||
var it = mem.splitScalar(u8, mem.trim(u8, git_describe_long, &std.ascii.whitespace), '-');
|
||||
_ = it.next().?; // previous tag
|
||||
const commit_count = it.next().?;
|
||||
const commit_hash = it.next().?;
|
||||
@ -91,18 +86,19 @@ pub fn build(b: *Build) !void {
|
||||
const scanner = Scanner.create(b, .{});
|
||||
|
||||
scanner.addSystemProtocol("stable/xdg-shell/xdg-shell.xml");
|
||||
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/tablet/tablet-unstable-v2.xml");
|
||||
scanner.addSystemProtocol("stable/tablet/tablet-v2.xml");
|
||||
scanner.addSystemProtocol("staging/cursor-shape/cursor-shape-v1.xml");
|
||||
scanner.addSystemProtocol("staging/ext-session-lock/ext-session-lock-v1.xml");
|
||||
scanner.addSystemProtocol("staging/tearing-control/tearing-control-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/pointer-constraints/pointer-constraints-unstable-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/pointer-gestures/pointer-gestures-unstable-v1.xml");
|
||||
scanner.addSystemProtocol("unstable/xdg-decoration/xdg-decoration-unstable-v1.xml");
|
||||
|
||||
scanner.addCustomProtocol("protocol/river-control-unstable-v1.xml");
|
||||
scanner.addCustomProtocol("protocol/river-status-unstable-v1.xml");
|
||||
scanner.addCustomProtocol("protocol/river-layout-v3.xml");
|
||||
scanner.addCustomProtocol("protocol/wlr-layer-shell-unstable-v1.xml");
|
||||
scanner.addCustomProtocol("protocol/wlr-output-power-management-unstable-v1.xml");
|
||||
scanner.addCustomProtocol(b.path("protocol/river-control-unstable-v1.xml"));
|
||||
scanner.addCustomProtocol(b.path("protocol/river-status-unstable-v1.xml"));
|
||||
scanner.addCustomProtocol(b.path("protocol/river-layout-v3.xml"));
|
||||
scanner.addCustomProtocol(b.path("protocol/wlr-layer-shell-unstable-v1.xml"));
|
||||
scanner.addCustomProtocol(b.path("protocol/wlr-output-power-management-unstable-v1.xml"));
|
||||
|
||||
// Some of these versions may be out of date with what wlroots implements.
|
||||
// This is not a problem in practice though as long as river successfully compiles.
|
||||
@ -123,6 +119,7 @@ pub fn build(b: *Build) !void {
|
||||
scanner.generate("zxdg_decoration_manager_v1", 1);
|
||||
scanner.generate("ext_session_lock_manager_v1", 1);
|
||||
scanner.generate("wp_cursor_shape_manager_v1", 1);
|
||||
scanner.generate("wp_tearing_control_manager_v1", 1);
|
||||
|
||||
scanner.generate("zriver_control_v1", 1);
|
||||
scanner.generate("zriver_status_manager_v1", 4);
|
||||
@ -131,63 +128,59 @@ pub fn build(b: *Build) !void {
|
||||
scanner.generate("zwlr_layer_shell_v1", 4);
|
||||
scanner.generate("zwlr_output_power_manager_v1", 1);
|
||||
|
||||
const wayland = b.createModule(.{ .source_file = scanner.result });
|
||||
const xkbcommon = b.createModule(.{
|
||||
.source_file = .{ .path = "deps/zig-xkbcommon/src/xkbcommon.zig" },
|
||||
});
|
||||
const pixman = b.createModule(.{
|
||||
.source_file = .{ .path = "deps/zig-pixman/pixman.zig" },
|
||||
});
|
||||
const wlroots = b.createModule(.{
|
||||
.source_file = .{ .path = "deps/zig-wlroots/src/wlroots.zig" },
|
||||
.dependencies = &.{
|
||||
.{ .name = "wayland", .module = wayland },
|
||||
.{ .name = "xkbcommon", .module = xkbcommon },
|
||||
.{ .name = "pixman", .module = pixman },
|
||||
},
|
||||
});
|
||||
const wayland = b.createModule(.{ .root_source_file = scanner.result });
|
||||
|
||||
const flags = b.createModule(.{ .source_file = .{ .path = "common/flags.zig" } });
|
||||
const globber = b.createModule(.{ .source_file = .{ .path = "common/globber.zig" } });
|
||||
const xkbcommon = b.dependency("xkbcommon", .{}).module("xkbcommon");
|
||||
const pixman = b.dependency("pixman", .{}).module("pixman");
|
||||
|
||||
const wlroots = b.dependency("wlroots", .{}).module("wlroots");
|
||||
wlroots.addImport("wayland", wayland);
|
||||
wlroots.addImport("xkbcommon", xkbcommon);
|
||||
wlroots.addImport("pixman", pixman);
|
||||
|
||||
// We need to ensure the wlroots include path obtained from pkg-config is
|
||||
// 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", .{});
|
||||
|
||||
const flags = b.createModule(.{ .root_source_file = b.path("common/flags.zig") });
|
||||
const globber = b.createModule(.{ .root_source_file = b.path("common/globber.zig") });
|
||||
|
||||
{
|
||||
const river = b.addExecutable(.{
|
||||
.name = "river",
|
||||
.root_source_file = .{ .path = "river/main.zig" },
|
||||
.root_source_file = b.path("river/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.strip = strip,
|
||||
.use_llvm = llvm,
|
||||
.use_lld = llvm,
|
||||
});
|
||||
river.addOptions("build_options", options);
|
||||
river.root_module.addOptions("build_options", options);
|
||||
|
||||
river.linkLibC();
|
||||
river.linkSystemLibrary("libevdev");
|
||||
river.linkSystemLibrary("libinput");
|
||||
|
||||
river.addModule("wayland", wayland);
|
||||
river.linkSystemLibrary("wayland-server");
|
||||
|
||||
river.addModule("xkbcommon", xkbcommon);
|
||||
river.linkSystemLibrary("wlroots-0.19");
|
||||
river.linkSystemLibrary("xkbcommon");
|
||||
|
||||
river.addModule("pixman", pixman);
|
||||
river.linkSystemLibrary("pixman-1");
|
||||
|
||||
river.addModule("wlroots", wlroots);
|
||||
river.linkSystemLibrary("wlroots");
|
||||
river.root_module.addImport("wayland", wayland);
|
||||
river.root_module.addImport("xkbcommon", xkbcommon);
|
||||
river.root_module.addImport("pixman", pixman);
|
||||
river.root_module.addImport("wlroots", wlroots);
|
||||
river.root_module.addImport("flags", flags);
|
||||
river.root_module.addImport("globber", globber);
|
||||
|
||||
river.addModule("flags", flags);
|
||||
river.addModule("globber", globber);
|
||||
river.addCSourceFile(.{
|
||||
.file = .{ .path = "river/wlroots_log_wrapper.c" },
|
||||
.file = b.path("river/wlroots_log_wrapper.c"),
|
||||
.flags = &.{ "-std=c99", "-O2" },
|
||||
});
|
||||
|
||||
// TODO: remove when zig issue #131 is implemented
|
||||
scanner.addCSource(river);
|
||||
|
||||
river.strip = strip;
|
||||
river.pie = pie;
|
||||
river.omit_frame_pointer = omit_frame_pointer;
|
||||
river.root_module.omit_frame_pointer = omit_frame_pointer;
|
||||
|
||||
b.installArtifact(river);
|
||||
}
|
||||
@ -195,22 +188,22 @@ pub fn build(b: *Build) !void {
|
||||
{
|
||||
const riverctl = b.addExecutable(.{
|
||||
.name = "riverctl",
|
||||
.root_source_file = .{ .path = "riverctl/main.zig" },
|
||||
.root_source_file = b.path("riverctl/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.strip = strip,
|
||||
.use_llvm = llvm,
|
||||
.use_lld = llvm,
|
||||
});
|
||||
riverctl.addOptions("build_options", options);
|
||||
riverctl.root_module.addOptions("build_options", options);
|
||||
|
||||
riverctl.addModule("flags", flags);
|
||||
riverctl.addModule("wayland", wayland);
|
||||
riverctl.root_module.addImport("flags", flags);
|
||||
riverctl.root_module.addImport("wayland", wayland);
|
||||
riverctl.linkLibC();
|
||||
riverctl.linkSystemLibrary("wayland-client");
|
||||
|
||||
scanner.addCSource(riverctl);
|
||||
|
||||
riverctl.strip = strip;
|
||||
riverctl.pie = pie;
|
||||
riverctl.omit_frame_pointer = omit_frame_pointer;
|
||||
riverctl.root_module.omit_frame_pointer = omit_frame_pointer;
|
||||
|
||||
b.installArtifact(riverctl);
|
||||
}
|
||||
@ -218,22 +211,22 @@ pub fn build(b: *Build) !void {
|
||||
{
|
||||
const rivertile = b.addExecutable(.{
|
||||
.name = "rivertile",
|
||||
.root_source_file = .{ .path = "rivertile/main.zig" },
|
||||
.root_source_file = b.path("rivertile/main.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
.strip = strip,
|
||||
.use_llvm = llvm,
|
||||
.use_lld = llvm,
|
||||
});
|
||||
rivertile.addOptions("build_options", options);
|
||||
rivertile.root_module.addOptions("build_options", options);
|
||||
|
||||
rivertile.addModule("flags", flags);
|
||||
rivertile.addModule("wayland", wayland);
|
||||
rivertile.root_module.addImport("flags", flags);
|
||||
rivertile.root_module.addImport("wayland", wayland);
|
||||
rivertile.linkLibC();
|
||||
rivertile.linkSystemLibrary("wayland-client");
|
||||
|
||||
scanner.addCSource(rivertile);
|
||||
|
||||
rivertile.strip = strip;
|
||||
rivertile.pie = pie;
|
||||
rivertile.omit_frame_pointer = omit_frame_pointer;
|
||||
rivertile.root_module.omit_frame_pointer = omit_frame_pointer;
|
||||
|
||||
b.installArtifact(rivertile);
|
||||
}
|
||||
@ -261,7 +254,7 @@ pub fn build(b: *Build) !void {
|
||||
// Even passing a buffer to std.Build.Step.Run appears to be racy and occasionally deadlocks.
|
||||
const scdoc = b.addSystemCommand(&.{ "/bin/sh", "-c", "scdoc < doc/" ++ page ++ ".1.scd" });
|
||||
// This makes the caching work for the Workaround, and the extra argument is ignored by /bin/sh.
|
||||
scdoc.addFileArg(.{ .path = "doc/" ++ page ++ ".1.scd" });
|
||||
scdoc.addFileArg(b.path("doc/" ++ page ++ ".1.scd"));
|
||||
|
||||
const stdout = scdoc.captureStdOut();
|
||||
b.getInstallStep().dependOn(&b.addInstallFile(stdout, "share/man/man1/" ++ page ++ ".1").step);
|
||||
@ -282,7 +275,7 @@ pub fn build(b: *Build) !void {
|
||||
|
||||
{
|
||||
const globber_test = b.addTest(.{
|
||||
.root_source_file = .{ .path = "common/globber.zig" },
|
||||
.root_source_file = b.path("common/globber.zig"),
|
||||
.target = target,
|
||||
.optimize = optimize,
|
||||
});
|
||||
@ -292,3 +285,31 @@ 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");
|
||||
|
29
build.zig.zon
Normal file
29
build.zig.zon
Normal file
@ -0,0 +1,29 @@
|
||||
.{
|
||||
.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.11-dev",
|
||||
.paths = .{""},
|
||||
.dependencies = .{
|
||||
.pixman = .{
|
||||
.url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.3.0.tar.gz",
|
||||
.hash = "pixman-0.3.0-LClMnz2VAAAs7QSCGwLimV5VUYx0JFnX5xWU6HwtMuDX",
|
||||
},
|
||||
.wayland = .{
|
||||
.url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.3.0.tar.gz",
|
||||
.hash = "wayland-0.3.0-lQa1kjPIAQDmhGYpY-zxiRzQJFHQ2VqhJkQLbKKdt5wl",
|
||||
},
|
||||
.wlroots = .{
|
||||
.url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.19.1.tar.gz",
|
||||
.hash = "wlroots-0.19.1-jmOlcs7dAwCajnVWlQZIc-ySYjRlbLxy0F5FvTQqYA3P",
|
||||
},
|
||||
.xkbcommon = .{
|
||||
.url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.3.0.tar.gz",
|
||||
.hash = "xkbcommon-0.3.0-VDqIe3K9AQB2fG5ZeRcMC9i7kfrp5m2rWgLrmdNn9azr",
|
||||
},
|
||||
},
|
||||
.fingerprint = 0xf5e3672b8e8d6efc,
|
||||
}
|
@ -18,7 +18,7 @@ const std = @import("std");
|
||||
const mem = std.mem;
|
||||
|
||||
pub const Flag = struct {
|
||||
name: []const u8,
|
||||
name: [:0]const u8,
|
||||
kind: enum { boolean, arg },
|
||||
};
|
||||
|
||||
@ -37,27 +37,27 @@ pub fn parser(comptime Arg: type, comptime flags: []const Flag) type {
|
||||
|
||||
pub const Flags = flags_type: {
|
||||
var fields: []const std.builtin.Type.StructField = &.{};
|
||||
inline for (flags) |flag| {
|
||||
for (flags) |flag| {
|
||||
const field: std.builtin.Type.StructField = switch (flag.kind) {
|
||||
.boolean => .{
|
||||
.name = flag.name,
|
||||
.type = bool,
|
||||
.default_value = &false,
|
||||
.default_value_ptr = &false,
|
||||
.is_comptime = false,
|
||||
.alignment = @alignOf(bool),
|
||||
},
|
||||
.arg => .{
|
||||
.name = flag.name,
|
||||
.type = ?[:0]const u8,
|
||||
.default_value = &@as(?[:0]const u8, null),
|
||||
.default_value_ptr = &@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 = .{
|
||||
.layout = .Auto,
|
||||
break :flags_type @Type(.{ .@"struct" = .{
|
||||
.layout = .auto,
|
||||
.fields = fields,
|
||||
.decls = &.{},
|
||||
.is_tuple = false,
|
||||
|
@ -4,10 +4,6 @@ function __riverctl_completion ()
|
||||
if [ "${COMP_CWORD}" -eq 1 ]
|
||||
then
|
||||
OPTS=" \
|
||||
keyboard-group-create \
|
||||
keyboard-group-destroy \
|
||||
keyboard-group-add \
|
||||
keyboard-group-remove \
|
||||
keyboard-layout \
|
||||
keyboard-layout-file \
|
||||
close \
|
||||
@ -99,6 +95,7 @@ function __riverctl_completion ()
|
||||
tap-button-map \
|
||||
scroll-method \
|
||||
scroll-button \
|
||||
scroll-button-lock \
|
||||
map-to-output"
|
||||
COMPREPLY=($(compgen -W "${OPTS}" -- "${COMP_WORDS[3]}"))
|
||||
elif [ "${COMP_WORDS[1]}" == "hide-cursor" ]
|
||||
@ -117,7 +114,7 @@ function __riverctl_completion ()
|
||||
"events") OPTS="enabled disabled disabled-on-external-mouse" ;;
|
||||
"accel-profile") OPTS="none flat adaptive" ;;
|
||||
"click-method") OPTS="none button-areas clickfinger" ;;
|
||||
"drag"|"drag-lock"|"disable-while-typing"|"middle-emulation"|"left-handed"|"tap") OPTS="enabled disabled" ;;
|
||||
"drag"|"drag-lock"|"disable-while-typing"|"middle-emulation"|"left-handed"|"tap"|"scroll-button-lock") OPTS="enabled disabled" ;;
|
||||
"tap-button-map") OPTS="left-right-middle left-middle-right" ;;
|
||||
"scroll-method") OPTS="none two-finger edge button" ;;
|
||||
*) return ;;
|
||||
|
@ -72,11 +72,6 @@ complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'hide-cursor'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'set-repeat' -d 'Set the keyboard repeat rate and repeat delay'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'set-cursor-warp' -d 'Set the cursor warp mode'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'xcursor-theme' -d 'Set the xcursor theme'
|
||||
# Keyboardgroups
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-create' -d 'Create a keyboard group'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-destroy' -d 'Destroy a keyboard group'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-add' -d 'Add a keyboard to a keyboard group'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-group-remove' -d 'Remove a keyboard from a keyboard group'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-layout' -d 'Set the keyboard layout'
|
||||
complete -c riverctl -n '__fish_riverctl_complete_arg 1' -a 'keyboard-layout-file' -d 'Set the keyboard layout from a file.'
|
||||
|
||||
@ -119,10 +114,11 @@ complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'tap-button-map' -d 'Configure the button mapping for tapping'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-method' -d 'Set the scroll method'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-button' -d 'Set the scroll button'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'scroll-button-lock' -d 'Enable or disable the scroll button lock functionality'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 3' -a 'map-to-output' -d 'Map to a given output'
|
||||
|
||||
# Subcommands for the subcommands of 'input'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from drag drag-lock disable-while-typing disable-while-trackpointing middle-emulation natural-scroll left-handed tap' -a 'enabled disabled'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from drag drag-lock disable-while-typing disable-while-trackpointing middle-emulation natural-scroll left-handed tap scroll-button-lock' -a 'enabled disabled'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from events' -a 'enabled disabled disabled-on-external-mouse'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from accel-profile' -a 'none flat adaptive'
|
||||
complete -c riverctl -n '__fish_seen_subcommand_from input; and __fish_riverctl_complete_arg 4; and __fish_seen_subcommand_from click-method' -a 'none button-areas clickfinger'
|
||||
|
@ -62,11 +62,6 @@ _riverctl_commands()
|
||||
'set-repeat:Set the keyboard repeat rate and repeat delay'
|
||||
'set-cursor-warp:Set the cursor warp mode.'
|
||||
'xcursor-theme:Set the xcursor theme'
|
||||
# Keyboard groups
|
||||
'keyboard-group-create:Create a keyboard group'
|
||||
'keyboard-group-destroy:Destroy a keyboard group'
|
||||
'keyboard-group-add:Add a keyboard to a keyboard group'
|
||||
'keyboard-group-remove:Remove a keyboard from a keyboard group'
|
||||
'keyboard-layout:Set the keyboard layout'
|
||||
'keyboard-layout-file:Set the keyboard layout from a file'
|
||||
# Input
|
||||
@ -126,6 +121,7 @@ _riverctl()
|
||||
'tap-button-map:Configure the button mapping for tapping'
|
||||
'scroll-method:Set the scroll method'
|
||||
'scroll-button:Set the scroll button'
|
||||
'scroll-button-lock:Enable or disable the scroll button lock functionality'
|
||||
'map-to-output:Map to a given output'
|
||||
)
|
||||
|
||||
@ -135,7 +131,7 @@ _riverctl()
|
||||
case "$line[2]" in
|
||||
events) _alternative 'input-cmds:args:(enabled disabled disabled-on-external-mouse)' ;;
|
||||
accel-profile) _alternative 'input-cmds:args:(none flat adaptive)' ;;
|
||||
click-method) _alternative 'input-cmds:args:(none button-area clickfinger)' ;;
|
||||
click-method) _alternative 'input-cmds:args:(none button-areas clickfinger)' ;;
|
||||
drag) _alternative 'input-cmds:args:(enabled disabled)' ;;
|
||||
drag-lock) _alternative 'input-cmds:args:(enabled disabled)' ;;
|
||||
disable-while-typing) _alternative 'input-cmds:args:(enabled disabled)' ;;
|
||||
@ -144,6 +140,7 @@ _riverctl()
|
||||
natural-scroll) _alternative 'input-cmds:args:(enabled disabled)' ;;
|
||||
left-handed) _alternative 'input-cmds:args:(enabled disabled)' ;;
|
||||
tap) _alternative 'input-cmds:args:(enabled disabled)' ;;
|
||||
scroll-button-lock) _alternative 'input-cmds:args:(enabled disabled)' ;;
|
||||
tap-button-map) _alternative 'input-cmds:args:(left-right-middle left-middle-right)' ;;
|
||||
scroll-method) _alternative 'input-cmds:args:(none two-finger edge button)' ;;
|
||||
*) return 0 ;;
|
||||
|
1
deps/zig-pixman
vendored
1
deps/zig-pixman
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 70bff91beec4ad4c026dfc4465613e360dc85527
|
1
deps/zig-wayland
vendored
1
deps/zig-wayland
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 73fed093301b2e5f58998aa4797ce952bd148676
|
1
deps/zig-wlroots
vendored
1
deps/zig-wlroots
vendored
@ -1 +0,0 @@
|
||||
Subproject commit a579f9f7dae72c960e8804737109815c78e471f4
|
1
deps/zig-xkbcommon
vendored
1
deps/zig-xkbcommon
vendored
@ -1 +0,0 @@
|
||||
Subproject commit 7e09b389373b060148c0ca050e0b525e118d91e7
|
@ -307,11 +307,16 @@ matches everything while _\*\*_ and the empty string are invalid.
|
||||
- *fullscreen*: Make the view fullscreen. Applies only to new views.
|
||||
- *no-fullscreen*: Don't make the view fullscreen. Applies only to
|
||||
new views.
|
||||
- *tearing*: Allow the view to tear when fullscreen regardless of the
|
||||
view's preference. Applies to new and existing views.
|
||||
- *no-tearing*: Disable tearing for the view regardless of the view's
|
||||
preference. Applies to new and existing views.
|
||||
|
||||
Both *float* and *no-float* rules are added to the same list,
|
||||
which means that adding a *no-float* rule with the same arguments
|
||||
as a *float* rule will overwrite it. The same holds for *ssd* and
|
||||
*csd*, *fullscreen* and *no-fullscreen* rules.
|
||||
*csd*, *fullscreen* and *no-fullscreen*, *tearing* and
|
||||
*no-tearing* rules.
|
||||
|
||||
If multiple rules in a list match a given view the most specific
|
||||
rule will be applied. For example with the following rules
|
||||
@ -364,6 +369,10 @@ matches everything while _\*\*_ and the empty string are invalid.
|
||||
Set the attach mode of the currently focused output, overriding the value of
|
||||
default-attach-mode if any.
|
||||
|
||||
*allow-tearing* *enabled*|*disabled*
|
||||
Allow fullscreen views to tear if requested by the view. See also the
|
||||
*tearing* rule to force enable tearing for specific views.
|
||||
|
||||
*background-color* _0xRRGGBB_|_0xRRGGBBAA_
|
||||
Set the background color.
|
||||
|
||||
@ -413,7 +422,8 @@ matches everything while _\*\*_ and the empty string are invalid.
|
||||
|
||||
*set-repeat* _rate_ _delay_
|
||||
Set the keyboard repeat rate to _rate_ key repeats per second and
|
||||
repeat delay to _delay_ milliseconds.
|
||||
repeat delay to _delay_ milliseconds. The default is a rate of 25
|
||||
repeats per second and a delay of 600ms.
|
||||
|
||||
*xcursor-theme* _theme_name_ [_size_]
|
||||
Set the xcursor theme to _theme_name_ and optionally set the _size_.
|
||||
@ -444,29 +454,10 @@ matches everything while _\*\*_ and the empty string are invalid.
|
||||
following URL:
|
||||
https://xkbcommon.org/doc/current/keymap-text-format-v1.html
|
||||
|
||||
*keyboard-group-create* _group_name_
|
||||
Create a keyboard group. A keyboard group collects multiple keyboards in
|
||||
a single logical keyboard. This means that all state, like the active
|
||||
modifiers, is shared between the keyboards in a group.
|
||||
|
||||
*keyboard-group-destroy* _group_name_
|
||||
Destroy the keyboard group with the given name. All attached keyboards
|
||||
will be released, making them act as separate devices again.
|
||||
|
||||
*keyboard-group-add* _group_name_ _input_device_name_
|
||||
Add a keyboard to a keyboard group, identified by the keyboard's
|
||||
input device name. Any currently connected and future keyboards with
|
||||
the given name will be added to the group. Simple globbing patterns are
|
||||
supported, see the rules section for further information on globs.
|
||||
|
||||
*keyboard-group-remove* _group_name_ _input_device_name_
|
||||
Remove a keyboard from a keyboard group, identified by the keyboard's
|
||||
input device name.
|
||||
|
||||
The _input_ command can be used to create a configuration rule for an input
|
||||
device identified by its _name_.
|
||||
The _name_ of an input device consists of its type, its numerical vendor id,
|
||||
its numerical product id and finally its self-advertised name, separated by -.
|
||||
The _name_ of an input device consists of its type, its decimal vendor id,
|
||||
its decimal product id and finally its self-advertised name, separated by -.
|
||||
Simple globbing patterns are supported, see the rules section for further
|
||||
information on globs.
|
||||
|
||||
@ -536,6 +527,11 @@ However note that not every input device supports every property.
|
||||
Set the scroll button of an input device. _button_ is the name of a Linux
|
||||
input event code.
|
||||
|
||||
*input* _name_ *scroll-button-lock* *enabled*|*disabled*
|
||||
Enable or disable the scroll button lock functionality of the input device. If
|
||||
active, the button does not need to be held down. One press makes the button
|
||||
considered to be held down, and a second press releases the button.
|
||||
|
||||
*input* _name_ *map-to-output* _output_|*disabled*
|
||||
Maps the input to a given output. This is valid even if the output isn't
|
||||
currently active and will lead to the device being mapped once it is
|
||||
|
@ -68,6 +68,9 @@ pub const Dimensions = struct {
|
||||
height: u31,
|
||||
};
|
||||
|
||||
/// Whether to allow tearing page flips when fullscreen if a view requests it.
|
||||
allow_tearing: bool = false,
|
||||
|
||||
/// Color of background in RGBA with premultiplied alpha (alpha should only affect nested sessions)
|
||||
background_color: [4]f32 = [_]f32{ 0.0, 0.16862745, 0.21176471, 1.0 }, // Solarized base03
|
||||
|
||||
@ -98,6 +101,7 @@ rules: struct {
|
||||
position: RuleList(Position) = .{},
|
||||
dimensions: RuleList(Dimensions) = .{},
|
||||
fullscreen: RuleList(bool) = .{},
|
||||
tearing: RuleList(bool) = .{},
|
||||
} = .{},
|
||||
|
||||
/// The selected focus_follows_cursor mode
|
||||
|
@ -48,7 +48,7 @@ pub fn init(control: *Control) !void {
|
||||
}
|
||||
|
||||
fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void {
|
||||
const control = @fieldParentPtr(Control, "server_destroy", listener);
|
||||
const control: *Control = @fieldParentPtr("server_destroy", listener);
|
||||
control.global.destroy();
|
||||
control.args_map.deinit();
|
||||
}
|
||||
@ -84,7 +84,7 @@ fn handleRequest(control_v1: *zriver.ControlV1, request: zriver.ControlV1.Reques
|
||||
};
|
||||
},
|
||||
.run_command => |run_command| {
|
||||
const seat: *Seat = @ptrFromInt(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(wlr.Seat.Client.fromWlSeat(run_command.seat).?.seat.data));
|
||||
|
||||
const callback = zriver.CommandCallbackV1.create(
|
||||
control_v1.getClient(),
|
||||
|
196
river/Cursor.zig
196
river/Cursor.zig
@ -19,7 +19,7 @@ const Cursor = @This();
|
||||
const build_options = @import("build_options");
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
const math = std.math;
|
||||
const wlr = @import("wlroots");
|
||||
const wayland = @import("wayland");
|
||||
@ -108,6 +108,19 @@ const LayoutPoint = struct {
|
||||
ly: f64,
|
||||
};
|
||||
|
||||
const Image = union(enum) {
|
||||
/// No cursor image
|
||||
none,
|
||||
/// Name of the current Xcursor shape
|
||||
xcursor: [*:0]const u8,
|
||||
/// Cursor surface configured by a client
|
||||
client: struct {
|
||||
surface: *wlr.Surface,
|
||||
hotspot_x: i32,
|
||||
hotspot_y: i32,
|
||||
},
|
||||
};
|
||||
|
||||
const log = std.log.scoped(.cursor);
|
||||
|
||||
/// Current cursor mode as well as any state needed to implement that mode
|
||||
@ -124,9 +137,8 @@ wlr_cursor: *wlr.Cursor,
|
||||
|
||||
/// Xcursor manager for the currently configured Xcursor theme.
|
||||
xcursor_manager: *wlr.XcursorManager,
|
||||
/// Name of the current Xcursor shape, or null if a client has configured a
|
||||
/// surface to be used as the cursor shape instead.
|
||||
xcursor_name: ?[*:0]const u8 = null,
|
||||
image: Image = .none,
|
||||
image_surface_destroy: wl.Listener(*wlr.Surface) = .init(handleImageSurfaceDestroy),
|
||||
|
||||
/// Number of distinct buttons currently pressed
|
||||
pressed_count: u32 = 0,
|
||||
@ -243,6 +255,30 @@ 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();
|
||||
@ -286,25 +322,47 @@ pub fn setTheme(cursor: *Cursor, theme: ?[*:0]const u8, _size: ?u32) !void {
|
||||
cursor.xcursor_manager.destroy();
|
||||
cursor.xcursor_manager = xcursor_manager;
|
||||
|
||||
if (cursor.xcursor_name) |name| {
|
||||
cursor.setXcursor(name);
|
||||
switch (cursor.image) {
|
||||
.none, .client => {},
|
||||
.xcursor => |name| cursor.wlr_cursor.setXcursor(xcursor_manager, name),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn setXcursor(cursor: *Cursor, name: [*:0]const u8) void {
|
||||
cursor.wlr_cursor.setXcursor(cursor.xcursor_manager, name);
|
||||
cursor.xcursor_name = name;
|
||||
pub fn setImage(cursor: *Cursor, image: Image) void {
|
||||
switch (cursor.image) {
|
||||
.none, .xcursor => {},
|
||||
.client => {
|
||||
cursor.image_surface_destroy.link.remove();
|
||||
},
|
||||
}
|
||||
cursor.image = image;
|
||||
switch (cursor.image) {
|
||||
.none => cursor.wlr_cursor.unsetImage(),
|
||||
.xcursor => |name| cursor.wlr_cursor.setXcursor(cursor.xcursor_manager, name),
|
||||
.client => |client| {
|
||||
cursor.wlr_cursor.setSurface(client.surface, client.hotspot_x, client.hotspot_y);
|
||||
client.surface.events.destroy.add(&cursor.image_surface_destroy);
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
fn handleImageSurfaceDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const cursor: *Cursor = @fieldParentPtr("image_surface_destroy", listener);
|
||||
// wlroots calls wlr_cursor_unset_image() automatically
|
||||
// when the cursor surface is destroyed.
|
||||
cursor.image = .none;
|
||||
cursor.image_surface_destroy.link.remove();
|
||||
}
|
||||
|
||||
fn clearFocus(cursor: *Cursor) void {
|
||||
cursor.setXcursor("default");
|
||||
cursor.setImage(.{ .xcursor = "default" });
|
||||
cursor.seat.wlr_seat.pointerNotifyClearFocus();
|
||||
}
|
||||
|
||||
/// 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 = @fieldParentPtr(Cursor, "axis", listener);
|
||||
const device: *InputDevice = @ptrFromInt(event.device.data);
|
||||
const cursor: *Cursor = @fieldParentPtr("axis", listener);
|
||||
const device: *InputDevice = @alignCast(@ptrCast(event.device.data));
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
cursor.unhide();
|
||||
@ -324,11 +382,12 @@ fn handleAxis(listener: *wl.Listener(*wlr.Pointer.event.Axis), event: *wlr.Point
|
||||
math.maxInt(i32) / 2,
|
||||
)),
|
||||
event.source,
|
||||
event.relative_direction,
|
||||
);
|
||||
}
|
||||
|
||||
fn handleButton(listener: *wl.Listener(*wlr.Pointer.event.Button), event: *wlr.Pointer.event.Button) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "button", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("button", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
cursor.unhide();
|
||||
@ -423,7 +482,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 = @ptrFromInt(wlr_output.data);
|
||||
const output: *Output = @alignCast(@ptrCast(wlr_output.data));
|
||||
cursor.seat.focusOutput(output);
|
||||
}
|
||||
}
|
||||
@ -432,7 +491,7 @@ fn handlePinchBegin(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.PinchBegin),
|
||||
event: *wlr.Pointer.event.PinchBegin,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "pinch_begin", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("pinch_begin", listener);
|
||||
server.input_manager.pointer_gestures.sendPinchBegin(
|
||||
cursor.seat.wlr_seat,
|
||||
event.time_msec,
|
||||
@ -444,7 +503,7 @@ fn handlePinchUpdate(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.PinchUpdate),
|
||||
event: *wlr.Pointer.event.PinchUpdate,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "pinch_update", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("pinch_update", listener);
|
||||
server.input_manager.pointer_gestures.sendPinchUpdate(
|
||||
cursor.seat.wlr_seat,
|
||||
event.time_msec,
|
||||
@ -459,7 +518,7 @@ fn handlePinchEnd(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.PinchEnd),
|
||||
event: *wlr.Pointer.event.PinchEnd,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "pinch_end", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("pinch_end", listener);
|
||||
server.input_manager.pointer_gestures.sendPinchEnd(
|
||||
cursor.seat.wlr_seat,
|
||||
event.time_msec,
|
||||
@ -471,7 +530,7 @@ fn handleSwipeBegin(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.SwipeBegin),
|
||||
event: *wlr.Pointer.event.SwipeBegin,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "swipe_begin", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("swipe_begin", listener);
|
||||
server.input_manager.pointer_gestures.sendSwipeBegin(
|
||||
cursor.seat.wlr_seat,
|
||||
event.time_msec,
|
||||
@ -483,7 +542,7 @@ fn handleSwipeUpdate(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.SwipeUpdate),
|
||||
event: *wlr.Pointer.event.SwipeUpdate,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "swipe_update", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("swipe_update", listener);
|
||||
server.input_manager.pointer_gestures.sendSwipeUpdate(
|
||||
cursor.seat.wlr_seat,
|
||||
event.time_msec,
|
||||
@ -496,7 +555,7 @@ fn handleSwipeEnd(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.SwipeEnd),
|
||||
event: *wlr.Pointer.event.SwipeEnd,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "swipe_end", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("swipe_end", listener);
|
||||
server.input_manager.pointer_gestures.sendSwipeEnd(
|
||||
cursor.seat.wlr_seat,
|
||||
event.time_msec,
|
||||
@ -508,7 +567,7 @@ fn handleTouchDown(
|
||||
listener: *wl.Listener(*wlr.Touch.event.Down),
|
||||
event: *wlr.Touch.event.Down,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "touch_down", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("touch_down", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
|
||||
@ -544,7 +603,7 @@ fn handleTouchMotion(
|
||||
listener: *wl.Listener(*wlr.Touch.event.Motion),
|
||||
event: *wlr.Touch.event.Motion,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "touch_motion", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("touch_motion", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
|
||||
@ -563,12 +622,12 @@ fn handleTouchUp(
|
||||
listener: *wl.Listener(*wlr.Touch.event.Up),
|
||||
event: *wlr.Touch.event.Up,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "touch_up", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("touch_up", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
|
||||
if (cursor.touch_points.remove(event.touch_id)) {
|
||||
cursor.seat.wlr_seat.touchNotifyUp(event.time_msec, event.touch_id);
|
||||
_ = cursor.seat.wlr_seat.touchNotifyUp(event.time_msec, event.touch_id);
|
||||
}
|
||||
}
|
||||
|
||||
@ -576,43 +635,20 @@ fn handleTouchCancel(
|
||||
listener: *wl.Listener(*wlr.Touch.event.Cancel),
|
||||
_: *wlr.Touch.event.Cancel,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "touch_cancel", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("touch_cancel", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
|
||||
cursor.touch_points.clearRetainingCapacity();
|
||||
|
||||
// We can't call touchNotifyCancel() from inside the loop over touch points as it also loops
|
||||
// over touch points and may destroy multiple touch points in a single call.
|
||||
//
|
||||
// What we should do here is `while (touch_points.first()) |point| cancel()` but since the
|
||||
// surface may be null we can't rely on the fact tha all touch points will be destroyed
|
||||
// and risk an infinite loop if the surface of any wlr_touch_point is null.
|
||||
//
|
||||
// This is all really silly and totally unnecessary since all touchNotifyCancel() does with
|
||||
// the surface argument is obtain a seat client and touch_point.seat_client is never null.
|
||||
// TODO(wlroots) clean this up after the wlroots MR fixing this is merged:
|
||||
// https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4613
|
||||
|
||||
// The upper bound of 32 comes from an implementation detail of libinput which uses
|
||||
// a 32-bit integer as a map to keep track of touch points.
|
||||
var surfaces: std.BoundedArray(*wlr.Surface, 32) = .{};
|
||||
{
|
||||
var it = cursor.seat.wlr_seat.touch_state.touch_points.iterator(.forward);
|
||||
while (it.next()) |touch_point| {
|
||||
if (touch_point.surface) |surface| {
|
||||
surfaces.append(surface) catch break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (surfaces.slice()) |surface| {
|
||||
cursor.seat.wlr_seat.touchNotifyCancel(surface);
|
||||
const wlr_seat = cursor.seat.wlr_seat;
|
||||
while (wlr_seat.touch_state.touch_points.first()) |touch_point| {
|
||||
wlr_seat.touchNotifyCancel(touch_point.client);
|
||||
}
|
||||
}
|
||||
|
||||
fn handleTouchFrame(listener: *wl.Listener(void)) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "touch_frame", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("touch_frame", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
|
||||
@ -623,8 +659,8 @@ fn handleTabletToolAxis(
|
||||
_: *wl.Listener(*wlr.Tablet.event.Axis),
|
||||
event: *wlr.Tablet.event.Axis,
|
||||
) void {
|
||||
const device: *InputDevice = @ptrFromInt(event.device.data);
|
||||
const tablet = @fieldParentPtr(Tablet, "device", device);
|
||||
const device: *InputDevice = @alignCast(@ptrCast(event.device.data));
|
||||
const tablet: *Tablet = @fieldParentPtr("device", device);
|
||||
|
||||
device.seat.handleActivity();
|
||||
|
||||
@ -637,8 +673,8 @@ fn handleTabletToolProximity(
|
||||
_: *wl.Listener(*wlr.Tablet.event.Proximity),
|
||||
event: *wlr.Tablet.event.Proximity,
|
||||
) void {
|
||||
const device: *InputDevice = @ptrFromInt(event.device.data);
|
||||
const tablet = @fieldParentPtr(Tablet, "device", device);
|
||||
const device: *InputDevice = @alignCast(@ptrCast(event.device.data));
|
||||
const tablet: *Tablet = @fieldParentPtr("device", device);
|
||||
|
||||
device.seat.handleActivity();
|
||||
|
||||
@ -651,8 +687,8 @@ fn handleTabletToolTip(
|
||||
_: *wl.Listener(*wlr.Tablet.event.Tip),
|
||||
event: *wlr.Tablet.event.Tip,
|
||||
) void {
|
||||
const device: *InputDevice = @ptrFromInt(event.device.data);
|
||||
const tablet = @fieldParentPtr(Tablet, "device", device);
|
||||
const device: *InputDevice = @alignCast(@ptrCast(event.device.data));
|
||||
const tablet: *Tablet = @fieldParentPtr("device", device);
|
||||
|
||||
device.seat.handleActivity();
|
||||
|
||||
@ -665,8 +701,8 @@ fn handleTabletToolButton(
|
||||
_: *wl.Listener(*wlr.Tablet.event.Button),
|
||||
event: *wlr.Tablet.event.Button,
|
||||
) void {
|
||||
const device: *InputDevice = @ptrFromInt(event.device.data);
|
||||
const tablet = @fieldParentPtr(Tablet, "device", device);
|
||||
const device: *InputDevice = @alignCast(@ptrCast(event.device.data));
|
||||
const tablet: *Tablet = @fieldParentPtr("device", device);
|
||||
|
||||
device.seat.handleActivity();
|
||||
|
||||
@ -706,7 +742,7 @@ fn handlePointerMapping(cursor: *Cursor, event: *wlr.Pointer.event.Button, view:
|
||||
/// events together. For instance, two axis events may happen at the same
|
||||
/// time, in which case a frame event won't be sent in between.
|
||||
fn handleFrame(listener: *wl.Listener(*wlr.Cursor), _: *wlr.Cursor) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "frame", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("frame", listener);
|
||||
cursor.seat.wlr_seat.pointerNotifyFrame();
|
||||
}
|
||||
|
||||
@ -720,7 +756,7 @@ fn handleMotionAbsolute(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.MotionAbsolute),
|
||||
event: *wlr.Pointer.event.MotionAbsolute,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "motion_absolute", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("motion_absolute", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
|
||||
@ -739,7 +775,7 @@ fn handleMotion(
|
||||
listener: *wl.Listener(*wlr.Pointer.event.Motion),
|
||||
event: *wlr.Pointer.event.Motion,
|
||||
) void {
|
||||
const cursor = @fieldParentPtr(Cursor, "motion", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("motion", listener);
|
||||
|
||||
cursor.seat.handleActivity();
|
||||
|
||||
@ -751,7 +787,7 @@ fn handleRequestSetCursor(
|
||||
event: *wlr.Seat.event.RequestSetCursor,
|
||||
) void {
|
||||
// This event is rasied by the seat when a client provides a cursor image
|
||||
const cursor = @fieldParentPtr(Cursor, "request_set_cursor", listener);
|
||||
const cursor: *Cursor = @fieldParentPtr("request_set_cursor", listener);
|
||||
const focused_client = cursor.seat.wlr_seat.pointer_state.focused_client;
|
||||
|
||||
// This can be sent by any client, so we check to make sure this one is
|
||||
@ -762,8 +798,15 @@ fn handleRequestSetCursor(
|
||||
// on the output that it's currently on and continue to do so as the
|
||||
// cursor moves between outputs.
|
||||
log.debug("focused client set cursor", .{});
|
||||
cursor.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y);
|
||||
cursor.xcursor_name = null;
|
||||
if (event.surface) |surface| {
|
||||
cursor.setImage(.{ .client = .{
|
||||
.surface = surface,
|
||||
.hotspot_x = event.hotspot_x,
|
||||
.hotspot_y = event.hotspot_y,
|
||||
} });
|
||||
} else {
|
||||
cursor.setImage(.none);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -779,8 +822,6 @@ pub fn hide(cursor: *Cursor) void {
|
||||
|
||||
cursor.hidden = true;
|
||||
cursor.wlr_cursor.unsetImage();
|
||||
cursor.xcursor_name = null;
|
||||
cursor.seat.wlr_seat.pointerNotifyClearFocus();
|
||||
cursor.hide_cursor_timer.timerUpdate(0) catch {
|
||||
log.err("failed to update cursor hide timeout", .{});
|
||||
};
|
||||
@ -792,6 +833,7 @@ pub fn unhide(cursor: *Cursor) void {
|
||||
};
|
||||
if (!cursor.hidden) return;
|
||||
cursor.hidden = false;
|
||||
cursor.setImage(cursor.image);
|
||||
cursor.updateState();
|
||||
}
|
||||
|
||||
@ -890,7 +932,7 @@ fn computeEdges(cursor: *const Cursor, view: *const View) wlr.Edges {
|
||||
}
|
||||
}
|
||||
|
||||
fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor_name: [*:0]const u8) void {
|
||||
fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor: [*:0]const u8) void {
|
||||
assert(cursor.mode == .passthrough or cursor.mode == .down);
|
||||
assert(mode == .move or mode == .resize);
|
||||
|
||||
@ -906,7 +948,7 @@ fn enterMode(cursor: *Cursor, mode: Mode, view: *View, xcursor_name: [*:0]const
|
||||
}
|
||||
|
||||
cursor.seat.wlr_seat.pointerNotifyClearFocus();
|
||||
cursor.setXcursor(xcursor_name);
|
||||
cursor.setImage(.{ .xcursor = xcursor });
|
||||
|
||||
server.root.applyPending();
|
||||
}
|
||||
@ -1111,10 +1153,14 @@ pub fn updateState(cursor: *Cursor) void {
|
||||
.passthrough => {
|
||||
cursor.updateFocusFollowsCursorTarget();
|
||||
if (!cursor.hidden) {
|
||||
var now: os.timespec = undefined;
|
||||
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
|
||||
const msec: u32 = @intCast(now.tv_sec * std.time.ms_per_s +
|
||||
@divTrunc(now.tv_nsec, std.time.ns_per_ms));
|
||||
const now = posix.clock_gettime(.MONOTONIC) 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),
|
||||
math.maxInt(u32),
|
||||
));
|
||||
cursor.passthrough(msec);
|
||||
}
|
||||
},
|
||||
@ -1246,7 +1292,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 = @as(*DragIcon, @ptrFromInt(node.data));
|
||||
const icon: *DragIcon = @alignCast(@ptrCast(node.data));
|
||||
|
||||
if (icon.wlr_drag_icon.drag.seat == cursor.seat.wlr_seat) {
|
||||
icon.updatePosition(cursor);
|
||||
|
@ -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 = @intFromPtr(drag_icon);
|
||||
scene_drag_icon.node.data = drag_icon;
|
||||
|
||||
drag_icon.updatePosition(cursor);
|
||||
|
||||
@ -71,7 +71,7 @@ pub fn updatePosition(drag_icon: *DragIcon, cursor: *Cursor) void {
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.Drag.Icon), _: *wlr.Drag.Icon) void {
|
||||
const drag_icon = @fieldParentPtr(DragIcon, "destroy", listener);
|
||||
const drag_icon: *DragIcon = @fieldParentPtr("destroy", listener);
|
||||
|
||||
drag_icon.destroy.link.remove();
|
||||
|
||||
|
@ -36,7 +36,7 @@ foreign_close: wl.Listener(*wlr.ForeignToplevelHandleV1) =
|
||||
wl.Listener(*wlr.ForeignToplevelHandleV1).init(handleForeignClose),
|
||||
|
||||
pub fn map(handle: *ForeignToplevelHandle) void {
|
||||
const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle);
|
||||
const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle);
|
||||
|
||||
assert(handle.wlr_handle == null);
|
||||
|
||||
@ -67,7 +67,7 @@ pub fn unmap(handle: *ForeignToplevelHandle) void {
|
||||
|
||||
/// Must be called just before the view's inflight state is made current.
|
||||
pub fn update(handle: *ForeignToplevelHandle) void {
|
||||
const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle);
|
||||
const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle);
|
||||
|
||||
const wlr_handle = handle.wlr_handle orelse return;
|
||||
|
||||
@ -87,9 +87,9 @@ fn handleForeignActivate(
|
||||
listener: *wl.Listener(*wlr.ForeignToplevelHandleV1.event.Activated),
|
||||
event: *wlr.ForeignToplevelHandleV1.event.Activated,
|
||||
) void {
|
||||
const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_activate", listener);
|
||||
const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle);
|
||||
const seat: *Seat = @ptrFromInt(event.seat.data);
|
||||
const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_activate", listener);
|
||||
const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle);
|
||||
const seat: *Seat = @alignCast(@ptrCast(event.seat.data));
|
||||
|
||||
seat.focus(view);
|
||||
server.root.applyPending();
|
||||
@ -99,8 +99,8 @@ fn handleForeignFullscreen(
|
||||
listener: *wl.Listener(*wlr.ForeignToplevelHandleV1.event.Fullscreen),
|
||||
event: *wlr.ForeignToplevelHandleV1.event.Fullscreen,
|
||||
) void {
|
||||
const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_fullscreen", listener);
|
||||
const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle);
|
||||
const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_fullscreen", listener);
|
||||
const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle);
|
||||
|
||||
view.pending.fullscreen = event.fullscreen;
|
||||
server.root.applyPending();
|
||||
@ -110,8 +110,8 @@ fn handleForeignClose(
|
||||
listener: *wl.Listener(*wlr.ForeignToplevelHandleV1),
|
||||
_: *wlr.ForeignToplevelHandleV1,
|
||||
) void {
|
||||
const handle = @fieldParentPtr(ForeignToplevelHandle, "foreign_close", listener);
|
||||
const view = @fieldParentPtr(View, "foreign_toplevel_handle", handle);
|
||||
const handle: *ForeignToplevelHandle = @fieldParentPtr("foreign_close", listener);
|
||||
const view: *View = @fieldParentPtr("foreign_toplevel_handle", handle);
|
||||
|
||||
view.close();
|
||||
}
|
||||
|
@ -30,7 +30,7 @@ const View = @import("View.zig");
|
||||
wlr_manager: *wlr.IdleInhibitManagerV1,
|
||||
new_idle_inhibitor: wl.Listener(*wlr.IdleInhibitorV1) =
|
||||
wl.Listener(*wlr.IdleInhibitorV1).init(handleNewIdleInhibitor),
|
||||
inhibitors: std.TailQueue(IdleInhibitor) = .{},
|
||||
inhibitors: std.DoublyLinkedList(IdleInhibitor) = .{},
|
||||
|
||||
pub fn init(inhibit_manager: *IdleInhibitManager) !void {
|
||||
inhibit_manager.* = .{
|
||||
@ -78,8 +78,8 @@ pub fn checkActive(inhibit_manager: *IdleInhibitManager) void {
|
||||
}
|
||||
|
||||
fn handleNewIdleInhibitor(listener: *wl.Listener(*wlr.IdleInhibitorV1), inhibitor: *wlr.IdleInhibitorV1) void {
|
||||
const inhibit_manager = @fieldParentPtr(IdleInhibitManager, "new_idle_inhibitor", listener);
|
||||
const inhibitor_node = util.gpa.create(std.TailQueue(IdleInhibitor).Node) catch return;
|
||||
const inhibit_manager: *IdleInhibitManager = @fieldParentPtr("new_idle_inhibitor", listener);
|
||||
const inhibitor_node = util.gpa.create(std.DoublyLinkedList(IdleInhibitor).Node) catch return;
|
||||
inhibitor_node.data.init(inhibitor, inhibit_manager) catch {
|
||||
util.gpa.destroy(inhibitor_node);
|
||||
return;
|
||||
|
@ -45,11 +45,11 @@ pub fn init(
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const inhibitor = @fieldParentPtr(IdleInhibitor, "destroy", listener);
|
||||
const inhibitor: *IdleInhibitor = @fieldParentPtr("destroy", listener);
|
||||
|
||||
inhibitor.destroy.link.remove();
|
||||
|
||||
const node = @fieldParentPtr(std.TailQueue(IdleInhibitor).Node, "data", inhibitor);
|
||||
const node: *std.DoublyLinkedList(IdleInhibitor).Node = @fieldParentPtr("data", inhibitor);
|
||||
server.idle_inhibit_manager.inhibitors.remove(node);
|
||||
|
||||
inhibitor.inhibit_manager.checkActive();
|
||||
|
@ -215,6 +215,18 @@ pub const ScrollButton = struct {
|
||||
}
|
||||
};
|
||||
|
||||
pub const ScrollButtonLock = enum {
|
||||
enabled,
|
||||
disabled,
|
||||
|
||||
fn apply(scroll_button_lock: ScrollButtonLock, device: *c.libinput_device) void {
|
||||
_ = c.libinput_device_config_scroll_set_button_lock(device, switch (scroll_button_lock) {
|
||||
.enabled => c.LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_ENABLED,
|
||||
.disabled => c.LIBINPUT_CONFIG_SCROLL_BUTTON_LOCK_DISABLED,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
pub const MapToOutput = struct {
|
||||
output_name: ?[]const u8,
|
||||
|
||||
@ -232,7 +244,7 @@ pub const MapToOutput = struct {
|
||||
};
|
||||
|
||||
switch (device.wlr_device.type) {
|
||||
.pointer, .touch, .tablet_tool => {
|
||||
.pointer, .touch, .tablet => {
|
||||
log.debug("mapping input '{s}' -> '{s}'", .{
|
||||
device.identifier,
|
||||
if (wlr_output) |o| o.name else "<no output>",
|
||||
@ -240,14 +252,14 @@ pub const MapToOutput = struct {
|
||||
|
||||
device.seat.cursor.wlr_cursor.mapInputToOutput(device.wlr_device, wlr_output);
|
||||
|
||||
if (device.wlr_device.type == .tablet_tool) {
|
||||
const tablet = @fieldParentPtr(Tablet, "device", device);
|
||||
if (device.wlr_device.type == .tablet) {
|
||||
const tablet: *Tablet = @fieldParentPtr("device", device);
|
||||
tablet.output_mapping = wlr_output;
|
||||
}
|
||||
},
|
||||
|
||||
// These devices do not support being mapped to outputs.
|
||||
.keyboard, .tablet_pad, .switch_device => {},
|
||||
.keyboard, .tablet_pad, .@"switch" => {},
|
||||
}
|
||||
}
|
||||
};
|
||||
@ -279,6 +291,7 @@ tap: ?TapState = null,
|
||||
@"pointer-accel": ?PointerAccel = null,
|
||||
@"scroll-method": ?ScrollMethod = null,
|
||||
@"scroll-button": ?ScrollButton = null,
|
||||
@"scroll-button-lock": ?ScrollButtonLock = null,
|
||||
@"map-to-output": ?MapToOutput = null,
|
||||
|
||||
pub fn deinit(config: *InputConfig) void {
|
||||
@ -294,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| {
|
||||
@ -311,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)) {
|
||||
@ -345,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
|
||||
@ -363,7 +376,7 @@ pub fn parse(config: *InputConfig, setting: []const u8, value: []const u8) !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")) {
|
||||
@ -383,8 +396,8 @@ pub fn write(config: *InputConfig, writer: anytype) !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) });
|
||||
|
@ -24,6 +24,7 @@ const wl = @import("wayland").server.wl;
|
||||
|
||||
const globber = @import("globber");
|
||||
|
||||
const c = @import("c.zig");
|
||||
const server = &@import("main.zig").server;
|
||||
const util = @import("util.zig");
|
||||
|
||||
@ -52,19 +53,21 @@ config: struct {
|
||||
link: wl.list.Link,
|
||||
|
||||
pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !void {
|
||||
const device_type: []const u8 = switch (wlr_device.type) {
|
||||
.switch_device => "switch",
|
||||
.tablet_tool => "tablet",
|
||||
else => @tagName(wlr_device.type),
|
||||
};
|
||||
var vendor: c_uint = 0;
|
||||
var product: c_uint = 0;
|
||||
|
||||
if (wlr_device.getLibinputDevice()) |d| {
|
||||
vendor = c.libinput_device_get_id_vendor(@ptrCast(d));
|
||||
product = c.libinput_device_get_id_product(@ptrCast(d));
|
||||
}
|
||||
|
||||
const identifier = try std.fmt.allocPrint(
|
||||
util.gpa,
|
||||
"{s}-{}-{}-{s}",
|
||||
.{
|
||||
device_type,
|
||||
wlr_device.vendor,
|
||||
wlr_device.product,
|
||||
@tagName(wlr_device.type),
|
||||
vendor,
|
||||
product,
|
||||
mem.trim(u8, mem.sliceTo(wlr_device.name orelse "unknown", 0), &ascii.whitespace),
|
||||
},
|
||||
);
|
||||
@ -83,7 +86,7 @@ pub fn init(device: *InputDevice, seat: *Seat, wlr_device: *wlr.InputDevice) !vo
|
||||
.link = undefined,
|
||||
};
|
||||
|
||||
wlr_device.data = @intFromPtr(device);
|
||||
wlr_device.data = device;
|
||||
|
||||
wlr_device.events.destroy.add(&device.destroy);
|
||||
|
||||
@ -114,7 +117,7 @@ pub fn deinit(device: *InputDevice) void {
|
||||
device.seat.updateCapabilities();
|
||||
}
|
||||
|
||||
device.wlr_device.data = 0;
|
||||
device.wlr_device.data = null;
|
||||
|
||||
device.* = undefined;
|
||||
}
|
||||
@ -125,13 +128,13 @@ fn isKeyboardGroup(wlr_device: *wlr.InputDevice) bool {
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice) void {
|
||||
const device = @fieldParentPtr(InputDevice, "destroy", listener);
|
||||
const device: *InputDevice = @fieldParentPtr("destroy", listener);
|
||||
|
||||
log.debug("removed input device: {s}", .{device.identifier});
|
||||
|
||||
switch (device.wlr_device.type) {
|
||||
.keyboard => {
|
||||
const keyboard = @fieldParentPtr(Keyboard, "device", device);
|
||||
const keyboard: *Keyboard = @fieldParentPtr("device", device);
|
||||
keyboard.deinit();
|
||||
util.gpa.destroy(keyboard);
|
||||
},
|
||||
@ -139,12 +142,12 @@ fn handleDestroy(listener: *wl.Listener(*wlr.InputDevice), _: *wlr.InputDevice)
|
||||
device.deinit();
|
||||
util.gpa.destroy(device);
|
||||
},
|
||||
.tablet_tool => {
|
||||
const tablet = @fieldParentPtr(Tablet, "device", device);
|
||||
.tablet => {
|
||||
const tablet: *Tablet = @fieldParentPtr("device", device);
|
||||
tablet.destroy();
|
||||
},
|
||||
.switch_device => {
|
||||
const switch_device = @fieldParentPtr(Switch, "device", device);
|
||||
.@"switch" => {
|
||||
const switch_device: *Switch = @fieldParentPtr("device", device);
|
||||
switch_device.deinit();
|
||||
util.gpa.destroy(switch_device);
|
||||
},
|
||||
|
@ -58,7 +58,7 @@ tablet_manager: *wlr.TabletManagerV2,
|
||||
configs: std.ArrayList(InputConfig),
|
||||
|
||||
devices: wl.list.Head(InputDevice, .link),
|
||||
seats: std.TailQueue(Seat) = .{},
|
||||
seats: std.DoublyLinkedList(Seat) = .{},
|
||||
|
||||
exclusive_client: ?*wl.Client = null,
|
||||
|
||||
@ -74,7 +74,7 @@ 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);
|
||||
const seat_node = try util.gpa.create(std.DoublyLinkedList(Seat).Node);
|
||||
errdefer util.gpa.destroy(seat_node);
|
||||
|
||||
input_manager.* = .{
|
||||
@ -158,7 +158,7 @@ pub fn reconfigureDevices(input_manager: *InputManager) void {
|
||||
}
|
||||
|
||||
fn handleNewInput(listener: *wl.Listener(*wlr.InputDevice), wlr_device: *wlr.InputDevice) void {
|
||||
const input_manager = @fieldParentPtr(InputManager, "new_input", listener);
|
||||
const input_manager: *InputManager = @fieldParentPtr("new_input", listener);
|
||||
|
||||
input_manager.defaultSeat().addDevice(wlr_device);
|
||||
}
|
||||
@ -167,7 +167,7 @@ fn handleNewVirtualPointer(
|
||||
listener: *wl.Listener(*wlr.VirtualPointerManagerV1.event.NewPointer),
|
||||
event: *wlr.VirtualPointerManagerV1.event.NewPointer,
|
||||
) void {
|
||||
const input_manager = @fieldParentPtr(InputManager, "new_virtual_pointer", listener);
|
||||
const input_manager: *InputManager = @fieldParentPtr("new_virtual_pointer", listener);
|
||||
|
||||
// TODO Support multiple seats and don't ignore
|
||||
if (event.suggested_seat != null) {
|
||||
@ -185,7 +185,7 @@ fn handleNewVirtualKeyboard(
|
||||
_: *wl.Listener(*wlr.VirtualKeyboardV1),
|
||||
virtual_keyboard: *wlr.VirtualKeyboardV1,
|
||||
) void {
|
||||
const seat: *Seat = @ptrFromInt(virtual_keyboard.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(virtual_keyboard.seat.data));
|
||||
seat.addDevice(&virtual_keyboard.keyboard.base);
|
||||
}
|
||||
|
||||
@ -200,7 +200,7 @@ fn handleNewConstraint(
|
||||
}
|
||||
|
||||
fn handleNewInputMethod(_: *wl.Listener(*wlr.InputMethodV2), input_method: *wlr.InputMethodV2) void {
|
||||
const seat: *Seat = @ptrFromInt(input_method.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(input_method.seat.data));
|
||||
|
||||
log.debug("new input method on seat {s}", .{seat.wlr_seat.name});
|
||||
|
||||
|
188
river/InputPopup.zig
Normal file
188
river/InputPopup.zig
Normal file
@ -0,0 +1,188 @@
|
||||
// This file is part of river, a dynamic tiling wayland compositor.
|
||||
//
|
||||
// Copyright 2024 The River Developers
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const InputPopup = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const wlr = @import("wlroots");
|
||||
const wl = @import("wayland").server.wl;
|
||||
|
||||
const server = &@import("main.zig").server;
|
||||
const util = @import("util.zig");
|
||||
|
||||
const InputRelay = @import("InputRelay.zig");
|
||||
const SceneNodeData = @import("SceneNodeData.zig");
|
||||
|
||||
link: wl.list.Link,
|
||||
input_relay: *InputRelay,
|
||||
|
||||
wlr_popup: *wlr.InputPopupSurfaceV2,
|
||||
surface_tree: *wlr.SceneTree,
|
||||
|
||||
destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy),
|
||||
map: wl.Listener(void) = wl.Listener(void).init(handleMap),
|
||||
unmap: wl.Listener(void) = wl.Listener(void).init(handleUnmap),
|
||||
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
|
||||
|
||||
pub fn create(wlr_popup: *wlr.InputPopupSurfaceV2, input_relay: *InputRelay) !void {
|
||||
const input_popup = try util.gpa.create(InputPopup);
|
||||
errdefer util.gpa.destroy(input_popup);
|
||||
|
||||
input_popup.* = .{
|
||||
.link = undefined,
|
||||
.input_relay = input_relay,
|
||||
.wlr_popup = wlr_popup,
|
||||
.surface_tree = try server.root.hidden.tree.createSceneSubsurfaceTree(wlr_popup.surface),
|
||||
};
|
||||
|
||||
input_relay.input_popups.append(input_popup);
|
||||
|
||||
input_popup.wlr_popup.events.destroy.add(&input_popup.destroy);
|
||||
input_popup.wlr_popup.surface.events.map.add(&input_popup.map);
|
||||
input_popup.wlr_popup.surface.events.unmap.add(&input_popup.unmap);
|
||||
input_popup.wlr_popup.surface.events.commit.add(&input_popup.commit);
|
||||
|
||||
input_popup.update();
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const input_popup: *InputPopup = @fieldParentPtr("destroy", listener);
|
||||
|
||||
input_popup.destroy.link.remove();
|
||||
input_popup.map.link.remove();
|
||||
input_popup.unmap.link.remove();
|
||||
input_popup.commit.link.remove();
|
||||
|
||||
input_popup.link.remove();
|
||||
|
||||
util.gpa.destroy(input_popup);
|
||||
}
|
||||
|
||||
fn handleMap(listener: *wl.Listener(void)) void {
|
||||
const input_popup: *InputPopup = @fieldParentPtr("map", listener);
|
||||
|
||||
input_popup.update();
|
||||
}
|
||||
|
||||
fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||
const input_popup: *InputPopup = @fieldParentPtr("unmap", listener);
|
||||
|
||||
input_popup.surface_tree.node.reparent(server.root.hidden.tree);
|
||||
}
|
||||
|
||||
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const input_popup: *InputPopup = @fieldParentPtr("commit", listener);
|
||||
|
||||
input_popup.update();
|
||||
}
|
||||
|
||||
pub fn update(input_popup: *InputPopup) void {
|
||||
const text_input = input_popup.input_relay.text_input orelse {
|
||||
input_popup.surface_tree.node.reparent(server.root.hidden.tree);
|
||||
return;
|
||||
};
|
||||
|
||||
if (!input_popup.wlr_popup.surface.mapped) return;
|
||||
|
||||
// This seems like it could be null if the focused surface is destroyed
|
||||
const focused_surface = text_input.wlr_text_input.focused_surface orelse return;
|
||||
|
||||
// Focus should never be sent to subsurfaces
|
||||
assert(focused_surface.getRootSurface() == focused_surface);
|
||||
|
||||
const focused = SceneNodeData.fromSurface(focused_surface) orelse return;
|
||||
|
||||
const output = switch (focused.data) {
|
||||
.view => |view| view.current.output orelse return,
|
||||
.layer_surface => |layer_surface| layer_surface.output,
|
||||
.lock_surface => |lock_surface| lock_surface.getOutput(),
|
||||
// Xwayland doesn't use the text-input protocol
|
||||
.override_redirect => unreachable,
|
||||
};
|
||||
|
||||
const popup_tree = switch (focused.data) {
|
||||
.view => |view| view.popup_tree,
|
||||
.layer_surface => |layer_surface| layer_surface.popup_tree,
|
||||
.lock_surface => |lock_surface| lock_surface.getOutput().layers.popups,
|
||||
// Xwayland doesn't use the text-input protocol
|
||||
.override_redirect => unreachable,
|
||||
};
|
||||
|
||||
input_popup.surface_tree.node.reparent(popup_tree);
|
||||
|
||||
if (!text_input.wlr_text_input.current.features.cursor_rectangle) {
|
||||
// If the text-input client does not inform us where in the surface
|
||||
// the active text input is there's not much we can do. Placing the
|
||||
// popup at the top left corner of the window is nice and simple
|
||||
// while not looking terrible.
|
||||
input_popup.surface_tree.node.setPosition(0, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
var focused_x: c_int = undefined;
|
||||
var focused_y: c_int = undefined;
|
||||
_ = focused.node.coords(&focused_x, &focused_y);
|
||||
|
||||
var output_box: wlr.Box = undefined;
|
||||
server.root.output_layout.getBox(output.wlr_output, &output_box);
|
||||
|
||||
// Relative to the surface with the active text input
|
||||
var cursor_box = text_input.wlr_text_input.current.cursor_rectangle;
|
||||
|
||||
// Adjust to be relative to the output
|
||||
cursor_box.x += focused_x - output_box.x;
|
||||
cursor_box.y += focused_y - output_box.y;
|
||||
|
||||
// Choose popup x/y relative to the output:
|
||||
|
||||
// Align the left edge of the popup with the left edge of the cursor.
|
||||
// If the popup wouldn't fit on the output instead align the right edge
|
||||
// of the popup with the right edge of the cursor.
|
||||
const popup_x = blk: {
|
||||
const popup_width = input_popup.wlr_popup.surface.current.width;
|
||||
if (output_box.width - cursor_box.x >= popup_width) {
|
||||
break :blk cursor_box.x;
|
||||
} else {
|
||||
break :blk cursor_box.x + cursor_box.width - popup_width;
|
||||
}
|
||||
};
|
||||
|
||||
// Align the top edge of the popup with the bottom edge of the cursor.
|
||||
// If the popup wouldn't fit on the output instead align the bottom edge
|
||||
// of the popup with the top edge of the cursor.
|
||||
const popup_y = blk: {
|
||||
const popup_height = input_popup.wlr_popup.surface.current.height;
|
||||
if (output_box.height - (cursor_box.y + cursor_box.height) >= popup_height) {
|
||||
break :blk cursor_box.y + cursor_box.height;
|
||||
} else {
|
||||
break :blk cursor_box.y - popup_height;
|
||||
}
|
||||
};
|
||||
|
||||
// Scene node position is relative to the parent so adjust popup x/y to
|
||||
// be relative to the focused surface.
|
||||
input_popup.surface_tree.node.setPosition(
|
||||
popup_x - focused_x + output_box.x,
|
||||
popup_y - focused_y + output_box.y,
|
||||
);
|
||||
|
||||
// The text input rectangle sent to the input method is relative to the popup.
|
||||
cursor_box.x -= popup_x;
|
||||
cursor_box.y -= popup_y;
|
||||
input_popup.wlr_popup.sendTextInputRectangle(&cursor_box);
|
||||
}
|
@ -26,6 +26,7 @@ const wl = @import("wayland").server.wl;
|
||||
const util = @import("util.zig");
|
||||
|
||||
const TextInput = @import("TextInput.zig");
|
||||
const InputPopup = @import("InputPopup.zig");
|
||||
const Seat = @import("Seat.zig");
|
||||
|
||||
const log = std.log.scoped(.input_relay);
|
||||
@ -40,6 +41,7 @@ text_inputs: wl.list.Head(TextInput, .link),
|
||||
/// already in use new input methods are ignored.
|
||||
/// If this is null, no text input enter events will be sent.
|
||||
input_method: ?*wlr.InputMethodV2 = null,
|
||||
input_popups: wl.list.Head(InputPopup, .link),
|
||||
/// The currently enabled text input for the currently focused surface.
|
||||
/// Always null if there is no input method.
|
||||
text_input: ?*TextInput = null,
|
||||
@ -50,18 +52,21 @@ grab_keyboard: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) =
|
||||
wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboard),
|
||||
input_method_destroy: wl.Listener(*wlr.InputMethodV2) =
|
||||
wl.Listener(*wlr.InputMethodV2).init(handleInputMethodDestroy),
|
||||
input_method_new_popup: wl.Listener(*wlr.InputPopupSurfaceV2) =
|
||||
wl.Listener(*wlr.InputPopupSurfaceV2).init(handleInputMethodNewPopup),
|
||||
|
||||
grab_keyboard_destroy: wl.Listener(*wlr.InputMethodV2.KeyboardGrab) =
|
||||
wl.Listener(*wlr.InputMethodV2.KeyboardGrab).init(handleInputMethodGrabKeyboardDestroy),
|
||||
|
||||
pub fn init(relay: *InputRelay) void {
|
||||
relay.* = .{ .text_inputs = undefined };
|
||||
relay.* = .{ .text_inputs = undefined, .input_popups = undefined };
|
||||
|
||||
relay.text_inputs.init();
|
||||
relay.input_popups.init();
|
||||
}
|
||||
|
||||
pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void {
|
||||
const seat = @fieldParentPtr(Seat, "relay", relay);
|
||||
const seat: *Seat = @fieldParentPtr("relay", relay);
|
||||
|
||||
log.debug("new input method on seat {s}", .{seat.wlr_seat.name});
|
||||
|
||||
@ -77,6 +82,7 @@ pub fn newInputMethod(relay: *InputRelay, input_method: *wlr.InputMethodV2) void
|
||||
input_method.events.commit.add(&relay.input_method_commit);
|
||||
input_method.events.grab_keyboard.add(&relay.grab_keyboard);
|
||||
input_method.events.destroy.add(&relay.input_method_destroy);
|
||||
input_method.events.new_popup_surface.add(&relay.input_method_new_popup);
|
||||
|
||||
if (seat.focused.surface()) |surface| {
|
||||
relay.focus(surface);
|
||||
@ -87,7 +93,7 @@ fn handleInputMethodCommit(
|
||||
listener: *wl.Listener(*wlr.InputMethodV2),
|
||||
input_method: *wlr.InputMethodV2,
|
||||
) void {
|
||||
const relay = @fieldParentPtr(InputRelay, "input_method_commit", listener);
|
||||
const relay: *InputRelay = @fieldParentPtr("input_method_commit", listener);
|
||||
assert(input_method == relay.input_method);
|
||||
|
||||
if (!input_method.client_active) return;
|
||||
@ -121,13 +127,13 @@ fn handleInputMethodDestroy(
|
||||
listener: *wl.Listener(*wlr.InputMethodV2),
|
||||
input_method: *wlr.InputMethodV2,
|
||||
) void {
|
||||
const relay = @fieldParentPtr(InputRelay, "input_method_destroy", listener);
|
||||
const relay: *InputRelay = @fieldParentPtr("input_method_destroy", listener);
|
||||
assert(input_method == relay.input_method);
|
||||
|
||||
relay.input_method_commit.link.remove();
|
||||
relay.grab_keyboard.link.remove();
|
||||
relay.input_method_destroy.link.remove();
|
||||
|
||||
relay.input_method_new_popup.link.remove();
|
||||
relay.input_method = null;
|
||||
|
||||
relay.focus(null);
|
||||
@ -139,8 +145,8 @@ fn handleInputMethodGrabKeyboard(
|
||||
listener: *wl.Listener(*wlr.InputMethodV2.KeyboardGrab),
|
||||
keyboard_grab: *wlr.InputMethodV2.KeyboardGrab,
|
||||
) void {
|
||||
const relay = @fieldParentPtr(InputRelay, "grab_keyboard", listener);
|
||||
const seat = @fieldParentPtr(Seat, "relay", relay);
|
||||
const relay: *InputRelay = @fieldParentPtr("grab_keyboard", listener);
|
||||
const seat: *Seat = @fieldParentPtr("relay", relay);
|
||||
|
||||
const active_keyboard = seat.wlr_seat.getKeyboard();
|
||||
keyboard_grab.setKeyboard(active_keyboard);
|
||||
@ -148,11 +154,23 @@ fn handleInputMethodGrabKeyboard(
|
||||
keyboard_grab.events.destroy.add(&relay.grab_keyboard_destroy);
|
||||
}
|
||||
|
||||
fn handleInputMethodNewPopup(
|
||||
listener: *wl.Listener(*wlr.InputPopupSurfaceV2),
|
||||
wlr_popup: *wlr.InputPopupSurfaceV2,
|
||||
) void {
|
||||
const relay: *InputRelay = @fieldParentPtr("input_method_new_popup", listener);
|
||||
|
||||
InputPopup.create(wlr_popup, relay) catch {
|
||||
log.err("out of memory", .{});
|
||||
return;
|
||||
};
|
||||
}
|
||||
|
||||
fn handleInputMethodGrabKeyboardDestroy(
|
||||
listener: *wl.Listener(*wlr.InputMethodV2.KeyboardGrab),
|
||||
keyboard_grab: *wlr.InputMethodV2.KeyboardGrab,
|
||||
) void {
|
||||
const relay = @fieldParentPtr(InputRelay, "grab_keyboard_destroy", listener);
|
||||
const relay: *InputRelay = @fieldParentPtr("grab_keyboard_destroy", listener);
|
||||
relay.grab_keyboard_destroy.link.remove();
|
||||
|
||||
if (keyboard_grab.keyboard) |keyboard| {
|
||||
@ -162,13 +180,16 @@ fn handleInputMethodGrabKeyboardDestroy(
|
||||
|
||||
pub fn disableTextInput(relay: *InputRelay) void {
|
||||
assert(relay.text_input != null);
|
||||
relay.text_input = null;
|
||||
|
||||
if (relay.input_method) |input_method| {
|
||||
{
|
||||
var it = relay.input_popups.iterator(.forward);
|
||||
while (it.next()) |popup| popup.update();
|
||||
}
|
||||
input_method.sendDeactivate();
|
||||
input_method.sendDone();
|
||||
}
|
||||
|
||||
relay.text_input = null;
|
||||
}
|
||||
|
||||
pub fn sendInputMethodState(relay: *InputRelay) void {
|
||||
@ -197,6 +218,11 @@ pub fn sendInputMethodState(relay: *InputRelay) void {
|
||||
);
|
||||
}
|
||||
|
||||
{
|
||||
var it = relay.input_popups.iterator(.forward);
|
||||
while (it.next()) |popup| popup.update();
|
||||
}
|
||||
|
||||
input_method.sendDone();
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ 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: std.BoundedArray(Key, capacity) = .{},
|
||||
@ -96,21 +96,14 @@ pub fn init(keyboard: *Keyboard, seat: *Seat, wlr_device: *wlr.InputDevice) !voi
|
||||
errdefer keyboard.device.deinit();
|
||||
|
||||
const wlr_keyboard = keyboard.device.wlr_device.toKeyboard();
|
||||
wlr_keyboard.data = @intFromPtr(keyboard);
|
||||
wlr_keyboard.data = keyboard;
|
||||
|
||||
// wlroots will log a more detailed error if this fails.
|
||||
if (!wlr_keyboard.setKeymap(server.config.keymap)) return error.OutOfMemory;
|
||||
|
||||
// Add to keyboard-group, if applicable.
|
||||
var group_it = seat.keyboard_groups.first;
|
||||
outer: while (group_it) |group_node| : (group_it = group_node.next) {
|
||||
for (group_node.data.globs.items) |glob| {
|
||||
if (globber.match(glob, keyboard.device.identifier)) {
|
||||
// wlroots will log an error if this fails explaining the reason.
|
||||
_ = group_node.data.wlr_group.addKeyboard(wlr_keyboard);
|
||||
break :outer;
|
||||
}
|
||||
}
|
||||
if (wlr.KeyboardGroup.fromKeyboard(wlr_keyboard) == null) {
|
||||
// wlroots will log an error on failure
|
||||
_ = seat.keyboard_group.addKeyboard(wlr_keyboard);
|
||||
}
|
||||
|
||||
wlr_keyboard.setRepeatInfo(server.config.repeat_rate, server.config.repeat_delay);
|
||||
@ -146,7 +139,7 @@ pub fn deinit(keyboard: *Keyboard) void {
|
||||
|
||||
fn handleKey(listener: *wl.Listener(*wlr.Keyboard.event.Key), event: *wlr.Keyboard.event.Key) void {
|
||||
// This event is raised when a key is pressed or released.
|
||||
const keyboard = @fieldParentPtr(Keyboard, "key", listener);
|
||||
const keyboard: *Keyboard = @fieldParentPtr("key", listener);
|
||||
const wlr_keyboard = keyboard.device.wlr_device.toKeyboard();
|
||||
|
||||
// If the keyboard is in a group, this event will be handled by the group's Keyboard instance.
|
||||
@ -247,7 +240,7 @@ fn isModifier(keysym: xkb.Keysym) bool {
|
||||
}
|
||||
|
||||
fn handleModifiers(listener: *wl.Listener(*wlr.Keyboard), _: *wlr.Keyboard) void {
|
||||
const keyboard = @fieldParentPtr(Keyboard, "modifiers", listener);
|
||||
const keyboard: *Keyboard = @fieldParentPtr("modifiers", listener);
|
||||
const wlr_keyboard = keyboard.device.wlr_device.toKeyboard();
|
||||
|
||||
// If the keyboard is in a group, this event will be handled by the group's Keyboard instance.
|
||||
|
@ -1,141 +0,0 @@
|
||||
// This file is part of river, a dynamic tiling wayland compositor.
|
||||
//
|
||||
// Copyright 2022 The River Developers
|
||||
//
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, version 3.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const KeyboardGroup = @This();
|
||||
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const mem = std.mem;
|
||||
|
||||
const globber = @import("globber");
|
||||
const wlr = @import("wlroots");
|
||||
const wl = @import("wayland").server.wl;
|
||||
const xkb = @import("xkbcommon");
|
||||
|
||||
const log = std.log.scoped(.keyboard_group);
|
||||
|
||||
const server = &@import("main.zig").server;
|
||||
const util = @import("util.zig");
|
||||
|
||||
const Seat = @import("Seat.zig");
|
||||
const Keyboard = @import("Keyboard.zig");
|
||||
|
||||
seat: *Seat,
|
||||
wlr_group: *wlr.KeyboardGroup,
|
||||
name: []const u8,
|
||||
globs: std.ArrayListUnmanaged([]const u8) = .{},
|
||||
|
||||
pub fn create(seat: *Seat, name: []const u8) !void {
|
||||
log.debug("new keyboard group: '{s}'", .{name});
|
||||
|
||||
const node = try util.gpa.create(std.TailQueue(KeyboardGroup).Node);
|
||||
errdefer util.gpa.destroy(node);
|
||||
|
||||
const wlr_group = try wlr.KeyboardGroup.create();
|
||||
errdefer wlr_group.destroy();
|
||||
|
||||
const owned_name = try util.gpa.dupe(u8, name);
|
||||
errdefer util.gpa.free(owned_name);
|
||||
|
||||
node.data = .{
|
||||
.wlr_group = wlr_group,
|
||||
.name = owned_name,
|
||||
.seat = seat,
|
||||
};
|
||||
|
||||
seat.addDevice(&wlr_group.keyboard.base);
|
||||
seat.keyboard_groups.append(node);
|
||||
}
|
||||
|
||||
pub fn destroy(group: *KeyboardGroup) void {
|
||||
log.debug("destroying keyboard group: '{s}'", .{group.name});
|
||||
|
||||
util.gpa.free(group.name);
|
||||
|
||||
for (group.globs.items) |glob| {
|
||||
util.gpa.free(glob);
|
||||
}
|
||||
group.globs.deinit(util.gpa);
|
||||
|
||||
group.wlr_group.destroy();
|
||||
|
||||
const node = @fieldParentPtr(std.TailQueue(KeyboardGroup).Node, "data", group);
|
||||
group.seat.keyboard_groups.remove(node);
|
||||
util.gpa.destroy(node);
|
||||
}
|
||||
|
||||
pub fn addIdentifier(group: *KeyboardGroup, new_id: []const u8) !void {
|
||||
for (group.globs.items) |glob| {
|
||||
if (mem.eql(u8, glob, new_id)) return;
|
||||
}
|
||||
|
||||
log.debug("keyboard group '{s}' adding identifier: '{s}'", .{ group.name, new_id });
|
||||
|
||||
const owned_id = try util.gpa.dupe(u8, new_id);
|
||||
errdefer util.gpa.free(owned_id);
|
||||
|
||||
// Glob is validated in the command handler.
|
||||
try group.globs.append(util.gpa, owned_id);
|
||||
errdefer {
|
||||
// Not used now, but if at any point this function is modified to that
|
||||
// it may return an error after the glob pattern is added to the list,
|
||||
// the list will have a pointer to freed memory in its last position.
|
||||
_ = group.globs.pop();
|
||||
}
|
||||
|
||||
// Add any existing matching keyboards to the group.
|
||||
var it = server.input_manager.devices.iterator(.forward);
|
||||
while (it.next()) |device| {
|
||||
if (device.seat != group.seat) continue;
|
||||
if (device.wlr_device.type != .keyboard) continue;
|
||||
|
||||
if (globber.match(device.identifier, new_id)) {
|
||||
log.debug("found existing matching keyboard; adding to group", .{});
|
||||
|
||||
if (!group.wlr_group.addKeyboard(device.wlr_device.toKeyboard())) {
|
||||
// wlroots logs an error message to explain why this failed.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
// Continue, because we may have more than one device with the exact
|
||||
// same identifier. That is in fact one reason for the keyboard group
|
||||
// feature to exist in the first place.
|
||||
}
|
||||
}
|
||||
|
||||
pub fn removeIdentifier(group: *KeyboardGroup, id: []const u8) !void {
|
||||
for (group.globs.items, 0..) |glob, index| {
|
||||
if (mem.eql(u8, glob, id)) {
|
||||
_ = group.globs.orderedRemove(index);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
|
||||
var it = server.input_manager.devices.iterator(.forward);
|
||||
while (it.next()) |device| {
|
||||
if (device.seat != group.seat) continue;
|
||||
if (device.wlr_device.type != .keyboard) continue;
|
||||
|
||||
if (globber.match(device.identifier, id)) {
|
||||
const wlr_keyboard = device.wlr_device.toKeyboard();
|
||||
assert(wlr_keyboard.group == group.wlr_group);
|
||||
group.wlr_group.removeKeyboard(wlr_keyboard);
|
||||
}
|
||||
}
|
||||
}
|
@ -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 = @ptrFromInt(wlr_layer_surface.output.?.data);
|
||||
const output: *Output = @alignCast(@ptrCast(wlr_layer_surface.output.?.data));
|
||||
const layer_surface = try util.gpa.create(LayerSurface);
|
||||
errdefer util.gpa.destroy(layer_surface);
|
||||
|
||||
@ -55,23 +55,17 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
|
||||
.scene_layer_surface = try layer_tree.createSceneLayerSurfaceV1(wlr_layer_surface),
|
||||
.popup_tree = try output.layers.popups.createSceneTree(),
|
||||
};
|
||||
wlr_layer_surface.data = @intFromPtr(layer_surface);
|
||||
|
||||
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 = @intFromPtr(&layer_surface.scene_layer_surface.tree.node);
|
||||
wlr_layer_surface.surface.data = &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);
|
||||
wlr_layer_surface.surface.events.unmap.add(&layer_surface.unmap);
|
||||
wlr_layer_surface.surface.events.commit.add(&layer_surface.commit);
|
||||
wlr_layer_surface.events.new_popup.add(&layer_surface.new_popup);
|
||||
|
||||
// wlroots only informs us of the new surface after the first commit,
|
||||
// so our listener does not get called for this first commit. However,
|
||||
// we do want our listener called in order to send the initial configure.
|
||||
handleCommit(&layer_surface.commit, wlr_layer_surface.surface);
|
||||
}
|
||||
|
||||
pub fn destroyPopups(layer_surface: *LayerSurface) void {
|
||||
@ -80,7 +74,7 @@ pub fn destroyPopups(layer_surface: *LayerSurface) void {
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfaceV1) void {
|
||||
const layer_surface = @fieldParentPtr(LayerSurface, "destroy", listener);
|
||||
const layer_surface: *LayerSurface = @fieldParentPtr("destroy", listener);
|
||||
|
||||
log.debug("layer surface '{s}' destroyed", .{layer_surface.wlr_layer_surface.namespace});
|
||||
|
||||
@ -88,36 +82,48 @@ 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;
|
||||
|
||||
util.gpa.destroy(layer_surface);
|
||||
}
|
||||
|
||||
fn handleMap(listener: *wl.Listener(void)) void {
|
||||
const layer_surface = @fieldParentPtr(LayerSurface, "map", listener);
|
||||
const layer_surface: *LayerSurface = @fieldParentPtr("map", listener);
|
||||
const wlr_surface = layer_surface.wlr_layer_surface;
|
||||
|
||||
log.debug("layer surface '{s}' mapped", .{layer_surface.wlr_layer_surface.namespace});
|
||||
log.debug("layer surface '{s}' mapped", .{wlr_surface.namespace});
|
||||
|
||||
layer_surface.output.arrangeLayers();
|
||||
handleKeyboardInteractiveExclusive(layer_surface.output);
|
||||
|
||||
const consider = wlr_surface.current.keyboard_interactive == .on_demand and
|
||||
(wlr_surface.current.layer == .top or wlr_surface.current.layer == .overlay);
|
||||
handleKeyboardInteractiveExclusive(
|
||||
layer_surface.output,
|
||||
if (consider) layer_surface else null,
|
||||
);
|
||||
|
||||
server.root.applyPending();
|
||||
}
|
||||
|
||||
fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||
const layer_surface = @fieldParentPtr(LayerSurface, "unmap", listener);
|
||||
const layer_surface: *LayerSurface = @fieldParentPtr("unmap", listener);
|
||||
|
||||
log.debug("layer surface '{s}' unmapped", .{layer_surface.wlr_layer_surface.namespace});
|
||||
|
||||
layer_surface.output.arrangeLayers();
|
||||
handleKeyboardInteractiveExclusive(layer_surface.output);
|
||||
handleKeyboardInteractiveExclusive(layer_surface.output, null);
|
||||
server.root.applyPending();
|
||||
}
|
||||
|
||||
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const layer_surface = @fieldParentPtr(LayerSurface, "commit", listener);
|
||||
const layer_surface: *LayerSurface = @fieldParentPtr("commit", listener);
|
||||
const wlr_layer_surface = layer_surface.wlr_layer_surface;
|
||||
|
||||
assert(wlr_layer_surface.output != null);
|
||||
@ -132,24 +138,26 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
@as(u32, @bitCast(wlr_layer_surface.current.committed)) != 0)
|
||||
{
|
||||
layer_surface.output.arrangeLayers();
|
||||
handleKeyboardInteractiveExclusive(layer_surface.output);
|
||||
handleKeyboardInteractiveExclusive(layer_surface.output, null);
|
||||
server.root.applyPending();
|
||||
}
|
||||
}
|
||||
|
||||
/// Focus topmost keyboard-interactivity-exclusive layer surface above normal
|
||||
/// content, or if none found, focus the surface given as `consider`.
|
||||
/// Requires a call to Root.applyPending()
|
||||
fn handleKeyboardInteractiveExclusive(output: *Output) void {
|
||||
fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) void {
|
||||
if (server.lock_manager.state != .unlocked) return;
|
||||
|
||||
// Find the topmost layer surface in the top or overlay layers which
|
||||
// requests keyboard interactivity if any.
|
||||
const topmost_surface = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| {
|
||||
// Find the topmost layer surface (if any) in the top or overlay layers which
|
||||
// requests exclusive keyboard interactivity.
|
||||
const to_focus = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| {
|
||||
const tree = output.layerSurfaceTree(layer);
|
||||
// Iterate in reverse to match rendering order.
|
||||
var it = tree.children.iterator(.reverse);
|
||||
while (it.next()) |node| {
|
||||
assert(node.type == .tree);
|
||||
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
|
||||
if (@as(?*SceneNodeData, @alignCast(@ptrCast(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
|
||||
@ -159,17 +167,21 @@ fn handleKeyboardInteractiveExclusive(output: *Output) void {
|
||||
}
|
||||
}
|
||||
}
|
||||
} else null;
|
||||
} else consider;
|
||||
|
||||
if (to_focus) |s| {
|
||||
assert(s.wlr_layer_surface.current.keyboard_interactive != .none);
|
||||
}
|
||||
|
||||
var it = server.input_manager.seats.first;
|
||||
while (it) |node| : (it = node.next) {
|
||||
const seat = &node.data;
|
||||
|
||||
if (seat.focused_output == output) {
|
||||
if (topmost_surface) |to_focus| {
|
||||
if (to_focus) |s| {
|
||||
// If we found a surface on the output that requires focus, grab the focus of all
|
||||
// seats that are focusing that output.
|
||||
seat.setFocusRaw(.{ .layer = to_focus });
|
||||
seat.setFocusRaw(.{ .layer = s });
|
||||
continue;
|
||||
}
|
||||
}
|
||||
@ -186,7 +198,7 @@ fn handleKeyboardInteractiveExclusive(output: *Output) void {
|
||||
}
|
||||
|
||||
fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void {
|
||||
const layer_surface = @fieldParentPtr(LayerSurface, "new_popup", listener);
|
||||
const layer_surface: *LayerSurface = @fieldParentPtr("new_popup", listener);
|
||||
|
||||
XdgPopup.create(
|
||||
wlr_xdg_popup,
|
||||
|
@ -47,7 +47,7 @@ pub fn create(client: *wl.Client, version: u32, id: u32, output: *Output, namesp
|
||||
return;
|
||||
}
|
||||
|
||||
const node = try util.gpa.create(std.TailQueue(Layout).Node);
|
||||
const node = try util.gpa.create(std.DoublyLinkedList(Layout).Node);
|
||||
errdefer util.gpa.destroy(node);
|
||||
node.data = .{
|
||||
.layout_v3 = layout_v3,
|
||||
@ -186,7 +186,7 @@ pub fn destroy(layout: *Layout) void {
|
||||
);
|
||||
|
||||
// Remove layout from the list
|
||||
const node = @fieldParentPtr(std.TailQueue(Layout).Node, "data", layout);
|
||||
const node: *std.DoublyLinkedList(Layout).Node = @fieldParentPtr("data", layout);
|
||||
layout.output.layouts.remove(node);
|
||||
|
||||
// If we are the currently active layout of an output, clean up.
|
||||
|
@ -44,7 +44,7 @@ pub fn init(layout_manager: *LayoutManager) !void {
|
||||
}
|
||||
|
||||
fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void {
|
||||
const layout_manager = @fieldParentPtr(LayoutManager, "server_destroy", listener);
|
||||
const layout_manager: *LayoutManager = @fieldParentPtr("server_destroy", listener);
|
||||
layout_manager.global.destroy();
|
||||
}
|
||||
|
||||
@ -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 = @ptrFromInt(wlr_output.data);
|
||||
const output: *Output = @alignCast(@ptrCast(wlr_output.data));
|
||||
|
||||
log.debug("bind layout '{s}' on output '{s}'", .{ req.namespace, output.wlr_output.name });
|
||||
|
||||
|
@ -85,7 +85,7 @@ pub fn deinit(manager: *LockManager) void {
|
||||
}
|
||||
|
||||
fn handleLock(listener: *wl.Listener(*wlr.SessionLockV1), lock: *wlr.SessionLockV1) void {
|
||||
const manager = @fieldParentPtr(LockManager, "new_lock", listener);
|
||||
const manager: *LockManager = @fieldParentPtr("new_lock", listener);
|
||||
|
||||
if (manager.lock != null) {
|
||||
log.info("denying new session lock client, an active one already exists", .{});
|
||||
@ -191,7 +191,7 @@ pub fn maybeLock(manager: *LockManager) void {
|
||||
}
|
||||
|
||||
fn handleUnlock(listener: *wl.Listener(void)) void {
|
||||
const manager = @fieldParentPtr(LockManager, "unlock", listener);
|
||||
const manager: *LockManager = @fieldParentPtr("unlock", listener);
|
||||
|
||||
manager.state = .unlocked;
|
||||
|
||||
@ -229,7 +229,7 @@ fn handleUnlock(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const manager = @fieldParentPtr(LockManager, "destroy", listener);
|
||||
const manager: *LockManager = @fieldParentPtr("destroy", listener);
|
||||
|
||||
log.debug("ext_session_lock_v1 destroyed", .{});
|
||||
|
||||
@ -248,7 +248,7 @@ fn handleSurface(
|
||||
listener: *wl.Listener(*wlr.SessionLockSurfaceV1),
|
||||
wlr_lock_surface: *wlr.SessionLockSurfaceV1,
|
||||
) void {
|
||||
const manager = @fieldParentPtr(LockManager, "new_surface", listener);
|
||||
const manager: *LockManager = @fieldParentPtr("new_surface", listener);
|
||||
|
||||
log.debug("new ext_session_lock_surface_v1 created", .{});
|
||||
|
||||
@ -266,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 = @ptrFromInt(wlr_lock_surface.data);
|
||||
const lock_surface: *LockSurface = @alignCast(@ptrCast(wlr_lock_surface.data));
|
||||
if (output == lock_surface.getOutput()) {
|
||||
lock_surface.configure();
|
||||
}
|
||||
|
@ -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 = @intFromPtr(lock_surface);
|
||||
wlr_lock_surface.data = 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 = @intFromPtr(&tree.node);
|
||||
wlr_lock_surface.surface.data = &tree.node;
|
||||
|
||||
wlr_lock_surface.surface.events.map.add(&lock_surface.map);
|
||||
wlr_lock_surface.events.destroy.add(&lock_surface.surface_destroy);
|
||||
@ -65,7 +65,7 @@ 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 = @ptrFromInt(surface.data) };
|
||||
break .{ .lock_surface = @alignCast(@ptrCast(surface.data)) };
|
||||
} else .none;
|
||||
|
||||
var seat_it = server.input_manager.seats.first;
|
||||
@ -85,11 +85,14 @@ pub fn destroy(lock_surface: *LockSurface) void {
|
||||
lock_surface.map.link.remove();
|
||||
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;
|
||||
|
||||
util.gpa.destroy(lock_surface);
|
||||
}
|
||||
|
||||
pub fn getOutput(lock_surface: *LockSurface) *Output {
|
||||
return @ptrFromInt(lock_surface.wlr_lock_surface.output.data);
|
||||
return @alignCast(@ptrCast(lock_surface.wlr_lock_surface.output.data));
|
||||
}
|
||||
|
||||
pub fn configure(lock_surface: *LockSurface) void {
|
||||
@ -100,7 +103,7 @@ pub fn configure(lock_surface: *LockSurface) void {
|
||||
}
|
||||
|
||||
fn handleMap(listener: *wl.Listener(void)) void {
|
||||
const lock_surface = @fieldParentPtr(LockSurface, "map", listener);
|
||||
const lock_surface: *LockSurface = @fieldParentPtr("map", listener);
|
||||
const output = lock_surface.getOutput();
|
||||
|
||||
output.normal_content.node.setEnabled(false);
|
||||
@ -132,7 +135,7 @@ fn updateFocus(lock_surface: *LockSurface) void {
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const lock_surface = @fieldParentPtr(LockSurface, "surface_destroy", listener);
|
||||
const lock_surface: *LockSurface = @fieldParentPtr("surface_destroy", listener);
|
||||
|
||||
lock_surface.destroy();
|
||||
}
|
||||
|
@ -20,6 +20,7 @@ const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const math = std.math;
|
||||
const mem = std.mem;
|
||||
const posix = std.posix;
|
||||
const fmt = std.fmt;
|
||||
const wlr = @import("wlroots");
|
||||
const wayland = @import("wayland");
|
||||
@ -99,7 +100,7 @@ layers: struct {
|
||||
fullscreen: *wlr.SceneTree,
|
||||
/// Overlay layer shell layer
|
||||
overlay: *wlr.SceneTree,
|
||||
/// xdg-popups of views and layer-shell surfaces
|
||||
/// Popups from xdg-shell and input-method-v2 clients.
|
||||
popups: *wlr.SceneTree,
|
||||
},
|
||||
|
||||
@ -124,10 +125,6 @@ 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
|
||||
@ -170,7 +167,7 @@ previous_tags: u32 = 1 << 0,
|
||||
attach_mode: ?Config.AttachMode = null,
|
||||
|
||||
/// List of all layouts
|
||||
layouts: std.TailQueue(Layout) = .{},
|
||||
layouts: std.DoublyLinkedList(Layout) = .{},
|
||||
|
||||
/// The current layout namespace of the output. If null,
|
||||
/// config.default_layout_namespace should be used instead.
|
||||
@ -294,7 +291,7 @@ pub fn create(wlr_output: *wlr.Output) !void {
|
||||
},
|
||||
.status = undefined,
|
||||
};
|
||||
wlr_output.data = @intFromPtr(output);
|
||||
wlr_output.data = output;
|
||||
|
||||
output.pending.focus_stack.init();
|
||||
output.pending.wm_stack.init();
|
||||
@ -363,9 +360,11 @@ fn sendLayerConfigures(
|
||||
var it = tree.children.safeIterator(.forward);
|
||||
while (it.next()) |node| {
|
||||
assert(node.type == .tree);
|
||||
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| {
|
||||
if (@as(?*SceneNodeData, @alignCast(@ptrCast(node.data)))) |node_data| {
|
||||
const layer_surface = node_data.data.layer_surface;
|
||||
|
||||
if (!layer_surface.wlr_layer_surface.initialized) continue;
|
||||
|
||||
const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0;
|
||||
if (exclusive != (mode == .exclusive)) {
|
||||
continue;
|
||||
@ -390,18 +389,22 @@ fn sendLayerConfigures(
|
||||
usable_box.* = new_usable_box;
|
||||
}
|
||||
|
||||
layer_surface.popup_tree.node.setPosition(
|
||||
layer_surface.scene_layer_surface.tree.node.x,
|
||||
layer_surface.scene_layer_surface.tree.node.y,
|
||||
);
|
||||
layer_surface.scene_layer_surface.tree.node.subsurfaceTreeSetClip(&full_box);
|
||||
const x = layer_surface.scene_layer_surface.tree.node.x;
|
||||
const y = layer_surface.scene_layer_surface.tree.node.y;
|
||||
layer_surface.popup_tree.node.setPosition(x, y);
|
||||
layer_surface.scene_layer_surface.tree.node.subsurfaceTreeSetClip(&.{
|
||||
.x = -x,
|
||||
.y = -y,
|
||||
.width = full_box.width,
|
||||
.height = full_box.height,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
||||
const output = @fieldParentPtr(Output, "destroy", listener);
|
||||
const output: *Output = @fieldParentPtr("destroy", listener);
|
||||
|
||||
log.debug("output '{s}' destroyed", .{output.wlr_output.name});
|
||||
|
||||
@ -426,7 +429,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
||||
|
||||
if (output.layout_namespace) |namespace| util.gpa.free(namespace);
|
||||
|
||||
output.wlr_output.data = 0;
|
||||
output.wlr_output.data = null;
|
||||
|
||||
util.gpa.destroy(output);
|
||||
|
||||
@ -436,7 +439,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
||||
}
|
||||
|
||||
fn handleRequestState(listener: *wl.Listener(*wlr.Output.event.RequestState), event: *wlr.Output.event.RequestState) void {
|
||||
const output = @fieldParentPtr(Output, "request_state", listener);
|
||||
const output: *Output = @fieldParentPtr("request_state", listener);
|
||||
|
||||
output.applyState(event.state) catch {
|
||||
log.err("failed to commit requested state", .{});
|
||||
@ -514,47 +517,44 @@ pub fn updateBackgroundRect(output: *Output) void {
|
||||
output.layers.background_color_rect.setSize(width, height);
|
||||
|
||||
var it = output.layers.fullscreen.children.iterator(.forward);
|
||||
const fullscreen_background = @fieldParentPtr(wlr.SceneRect, "node", it.next().?);
|
||||
const fullscreen_background: *wlr.SceneRect = @fieldParentPtr("node", it.next().?);
|
||||
fullscreen_background.setSize(width, height);
|
||||
}
|
||||
|
||||
fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
|
||||
const output = @fieldParentPtr(Output, "frame", listener);
|
||||
const output: *Output = @fieldParentPtr("frame", listener);
|
||||
const scene_output = server.root.scene.getSceneOutput(output.wlr_output).?;
|
||||
|
||||
// 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: std.os.timespec = undefined;
|
||||
std.os.clock_gettime(std.os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
|
||||
var now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
|
||||
scene_output.sendFrameDone(&now);
|
||||
}
|
||||
|
||||
fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void {
|
||||
if (output.gamma_dirty) {
|
||||
if (!scene_output.needsFrame()) return;
|
||||
|
||||
var state = wlr.Output.State.init();
|
||||
defer state.finish();
|
||||
|
||||
if (server.root.gamma_control_manager.getControl(output.wlr_output)) |control| {
|
||||
log.info("applying gamma settings from client", .{});
|
||||
if (!control.apply(&state)) return error.OutOfMemory;
|
||||
} else {
|
||||
log.info("clearing gamma settings from client", .{});
|
||||
state.clearGammaLut();
|
||||
}
|
||||
|
||||
if (!scene_output.buildState(&state, null)) return error.CommitFailed;
|
||||
|
||||
if (!output.wlr_output.commitState(&state)) return error.CommitFailed;
|
||||
|
||||
scene_output.damage_ring.rotate();
|
||||
output.gamma_dirty = false;
|
||||
} else {
|
||||
if (!scene_output.commit(null)) return error.CommitFailed;
|
||||
if (output.current.fullscreen) |fullscreen| {
|
||||
if (fullscreen.allowTearing()) {
|
||||
state.tearing_page_flip = true;
|
||||
if (!output.wlr_output.testState(&state)) {
|
||||
log.debug("tearing page flip test failed for {s}, retrying without tearing", .{
|
||||
output.wlr_output.name,
|
||||
});
|
||||
state.tearing_page_flip = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!output.wlr_output.commitState(&state)) return error.CommitFailed;
|
||||
|
||||
if (server.lock_manager.state == .locked or
|
||||
(server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or
|
||||
@ -591,7 +591,7 @@ fn handlePresent(
|
||||
listener: *wl.Listener(*wlr.Output.event.Present),
|
||||
event: *wlr.Output.event.Present,
|
||||
) void {
|
||||
const output = @fieldParentPtr(Output, "present", listener);
|
||||
const output: *Output = @fieldParentPtr("present", listener);
|
||||
|
||||
if (!event.presented) {
|
||||
return;
|
||||
|
@ -42,12 +42,12 @@ state: union(enum) {
|
||||
} = .inactive,
|
||||
|
||||
destroy: wl.Listener(*wlr.PointerConstraintV1) = wl.Listener(*wlr.PointerConstraintV1).init(handleDestroy),
|
||||
set_region: wl.Listener(void) = wl.Listener(void).init(handleSetRegion),
|
||||
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
|
||||
|
||||
node_destroy: wl.Listener(void) = wl.Listener(void).init(handleNodeDestroy),
|
||||
|
||||
pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void {
|
||||
const seat: *Seat = @ptrFromInt(wlr_constraint.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(wlr_constraint.seat.data));
|
||||
|
||||
const constraint = try util.gpa.create(PointerConstraint);
|
||||
errdefer util.gpa.destroy(constraint);
|
||||
@ -55,10 +55,10 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
|
||||
constraint.* = .{
|
||||
.wlr_constraint = wlr_constraint,
|
||||
};
|
||||
wlr_constraint.data = @intFromPtr(constraint);
|
||||
wlr_constraint.data = constraint;
|
||||
|
||||
wlr_constraint.events.destroy.add(&constraint.destroy);
|
||||
wlr_constraint.events.set_region.add(&constraint.set_region);
|
||||
wlr_constraint.surface.events.commit.add(&constraint.commit);
|
||||
|
||||
if (seat.wlr_seat.keyboard_state.focused_surface) |surface| {
|
||||
if (surface == wlr_constraint.surface) {
|
||||
@ -70,10 +70,9 @@ pub fn create(wlr_constraint: *wlr.PointerConstraintV1) error{OutOfMemory}!void
|
||||
}
|
||||
|
||||
pub fn maybeActivate(constraint: *PointerConstraint) void {
|
||||
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data));
|
||||
|
||||
assert(seat.cursor.constraint == constraint);
|
||||
assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface);
|
||||
|
||||
if (constraint.state == .active) return;
|
||||
|
||||
@ -103,9 +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 = @ptrFromInt(constraint.wlr_constraint.seat.data);
|
||||
|
||||
assert(seat.wlr_seat.keyboard_state.focused_surface == constraint.wlr_constraint.surface);
|
||||
const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data));
|
||||
|
||||
constraint.maybeActivate();
|
||||
|
||||
@ -157,7 +154,7 @@ pub fn confine(constraint: *PointerConstraint, dx: *f64, dy: *f64) void {
|
||||
}
|
||||
|
||||
pub fn deactivate(constraint: *PointerConstraint) void {
|
||||
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data));
|
||||
|
||||
assert(seat.cursor.constraint == constraint);
|
||||
assert(constraint.state == .active);
|
||||
@ -170,9 +167,9 @@ pub fn deactivate(constraint: *PointerConstraint) void {
|
||||
}
|
||||
|
||||
fn warpToHintIfSet(constraint: *PointerConstraint) void {
|
||||
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data));
|
||||
|
||||
if (constraint.wlr_constraint.current.committed.cursor_hint) {
|
||||
if (constraint.wlr_constraint.current.cursor_hint.enabled) {
|
||||
var lx: i32 = undefined;
|
||||
var ly: i32 = undefined;
|
||||
_ = constraint.state.active.node.coords(&lx, &ly);
|
||||
@ -185,15 +182,15 @@ fn warpToHintIfSet(constraint: *PointerConstraint) void {
|
||||
}
|
||||
|
||||
fn handleNodeDestroy(listener: *wl.Listener(void)) void {
|
||||
const constraint = @fieldParentPtr(PointerConstraint, "node_destroy", listener);
|
||||
const constraint: *PointerConstraint = @fieldParentPtr("node_destroy", listener);
|
||||
|
||||
log.info("deactivating pointer constraint, scene node destroyed", .{});
|
||||
constraint.deactivate();
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.PointerConstraintV1) void {
|
||||
const constraint = @fieldParentPtr(PointerConstraint, "destroy", listener);
|
||||
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
|
||||
const constraint: *PointerConstraint = @fieldParentPtr("destroy", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data));
|
||||
|
||||
if (constraint.state == .active) {
|
||||
// We can't simply call deactivate() here as it calls sendDeactivated(),
|
||||
@ -204,7 +201,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point
|
||||
}
|
||||
|
||||
constraint.destroy.link.remove();
|
||||
constraint.set_region.link.remove();
|
||||
constraint.commit.link.remove();
|
||||
|
||||
if (seat.cursor.constraint == constraint) {
|
||||
seat.cursor.constraint = null;
|
||||
@ -213,16 +210,19 @@ fn handleDestroy(listener: *wl.Listener(*wlr.PointerConstraintV1), _: *wlr.Point
|
||||
util.gpa.destroy(constraint);
|
||||
}
|
||||
|
||||
fn handleSetRegion(listener: *wl.Listener(void)) void {
|
||||
const constraint = @fieldParentPtr(PointerConstraint, "set_region", listener);
|
||||
const seat: *Seat = @ptrFromInt(constraint.wlr_constraint.seat.data);
|
||||
// It is necessary to listen for the commit event rather than the set_region
|
||||
// event as the latter is not triggered by wlroots when the input region of
|
||||
// the surface changes.
|
||||
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const constraint: *PointerConstraint = @fieldParentPtr("commit", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(constraint.wlr_constraint.seat.data));
|
||||
|
||||
switch (constraint.state) {
|
||||
.active => |state| {
|
||||
const sx: i32 = @intFromFloat(state.sx);
|
||||
const sy: i32 = @intFromFloat(state.sy);
|
||||
if (!constraint.wlr_constraint.region.containsPoint(sx, sy, null)) {
|
||||
log.info("deactivating pointer constraint, region change left pointer outside constraint", .{});
|
||||
log.info("deactivating pointer constraint, (input) region change left pointer outside constraint", .{});
|
||||
constraint.deactivate();
|
||||
}
|
||||
},
|
||||
|
@ -97,8 +97,6 @@ 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),
|
||||
@ -117,12 +115,17 @@ transaction_timeout: *wl.EventSource,
|
||||
pending_state_dirty: bool = false,
|
||||
|
||||
pub fn init(root: *Root) !void {
|
||||
const output_layout = try wlr.OutputLayout.create();
|
||||
const output_layout = try wlr.OutputLayout.create(server.wl_server);
|
||||
errdefer output_layout.destroy();
|
||||
|
||||
const scene = try wlr.Scene.create();
|
||||
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();
|
||||
@ -131,9 +134,6 @@ pub fn init(root: *Root) !void {
|
||||
const outputs = try interactive_content.createSceneTree();
|
||||
const override_redirect = if (build_options.xwayland) try interactive_content.createSceneTree();
|
||||
|
||||
const presentation = try wlr.Presentation.create(server.wl_server, server.backend);
|
||||
scene.setPresentation(presentation);
|
||||
|
||||
const event_loop = server.wl_server.getEventLoop();
|
||||
const transaction_timeout = try event_loop.addTimer(*Root, handleTransactionTimeout, root);
|
||||
errdefer transaction_timeout.remove();
|
||||
@ -166,11 +166,11 @@ pub fn init(root: *Root) !void {
|
||||
.all_outputs = undefined,
|
||||
.active_outputs = undefined,
|
||||
|
||||
.presentation = presentation,
|
||||
.presentation = try wlr.Presentation.create(server.wl_server, server.backend, 2),
|
||||
.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 = try wlr.GammaControlManagerV1.create(server.wl_server),
|
||||
.gamma_control_manager = gamma_control_manager,
|
||||
.transaction_timeout = transaction_timeout,
|
||||
};
|
||||
root.hidden.pending.focus_stack.init();
|
||||
@ -190,10 +190,14 @@ 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();
|
||||
}
|
||||
@ -326,7 +330,7 @@ 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, @ptrFromInt(scene_node.data))) |node_data| {
|
||||
if (@as(?*SceneNodeData, @alignCast(@ptrCast(scene_node.data)))) |node_data| {
|
||||
node_data.data.layer_surface.wlr_layer_surface.destroy();
|
||||
}
|
||||
}
|
||||
@ -416,6 +420,9 @@ pub fn activateOutput(root: *Root, output: *Output) void {
|
||||
}
|
||||
assert(root.fallback_pending.focus_stack.empty());
|
||||
assert(root.fallback_pending.wm_stack.empty());
|
||||
|
||||
// Enforce map-to-output configuration for the newly active output.
|
||||
server.input_manager.reconfigureDevices();
|
||||
}
|
||||
|
||||
/// Trigger asynchronous application of pending state for all outputs and views.
|
||||
@ -673,24 +680,12 @@ fn commitTransaction(root: *Root) void {
|
||||
while (focus_stack_it.next()) |view| {
|
||||
assert(view.inflight.output == output);
|
||||
|
||||
if (view.current.output != view.inflight.output or
|
||||
(output.current.fullscreen == view and output.inflight.fullscreen != view))
|
||||
{
|
||||
if (view.inflight.float) {
|
||||
view.tree.node.reparent(output.layers.float);
|
||||
} else {
|
||||
view.tree.node.reparent(output.layers.layout);
|
||||
}
|
||||
view.popup_tree.node.reparent(output.layers.popups);
|
||||
}
|
||||
|
||||
if (view.current.float != view.inflight.float) {
|
||||
if (view.inflight.float) {
|
||||
view.tree.node.reparent(output.layers.float);
|
||||
} else {
|
||||
view.tree.node.reparent(output.layers.layout);
|
||||
}
|
||||
}
|
||||
|
||||
view.commitTransaction();
|
||||
|
||||
@ -703,7 +698,6 @@ fn commitTransaction(root: *Root) void {
|
||||
}
|
||||
}
|
||||
|
||||
if (output.inflight.fullscreen != output.current.fullscreen) {
|
||||
if (output.inflight.fullscreen) |view| {
|
||||
assert(view.inflight.output == output);
|
||||
assert(view.current.output == output);
|
||||
@ -711,7 +705,6 @@ fn commitTransaction(root: *Root) void {
|
||||
}
|
||||
output.current.fullscreen = output.inflight.fullscreen;
|
||||
output.layers.fullscreen.node.setEnabled(output.current.fullscreen != null);
|
||||
}
|
||||
|
||||
output.status.handleTransactionCommit(output);
|
||||
}
|
||||
@ -743,7 +736,7 @@ fn commitTransaction(root: *Root) void {
|
||||
// We need this listener to deal with outputs that have their position auto-configured
|
||||
// by the wlr_output_layout.
|
||||
fn handleLayoutChange(listener: *wl.Listener(*wlr.OutputLayout), _: *wlr.OutputLayout) void {
|
||||
const root = @fieldParentPtr(Root, "layout_change", listener);
|
||||
const root: *Root = @fieldParentPtr("layout_change", listener);
|
||||
|
||||
root.handleOutputConfigChange() catch std.log.err("out of memory", .{});
|
||||
}
|
||||
@ -778,7 +771,7 @@ fn handleManagerApply(
|
||||
listener: *wl.Listener(*wlr.OutputConfigurationV1),
|
||||
config: *wlr.OutputConfigurationV1,
|
||||
) void {
|
||||
const root = @fieldParentPtr(Root, "manager_apply", listener);
|
||||
const root: *Root = @fieldParentPtr("manager_apply", listener);
|
||||
defer config.destroy();
|
||||
|
||||
std.log.scoped(.output_manager).info("applying output configuration", .{});
|
||||
@ -792,7 +785,7 @@ fn handleManagerTest(
|
||||
listener: *wl.Listener(*wlr.OutputConfigurationV1),
|
||||
config: *wlr.OutputConfigurationV1,
|
||||
) void {
|
||||
const root = @fieldParentPtr(Root, "manager_test", listener);
|
||||
const root: *Root = @fieldParentPtr("manager_test", listener);
|
||||
defer config.destroy();
|
||||
|
||||
root.processOutputConfig(config, .test_only);
|
||||
@ -812,7 +805,7 @@ fn processOutputConfig(
|
||||
var it = config.heads.iterator(.forward);
|
||||
while (it.next()) |head| {
|
||||
const wlr_output = head.state.output;
|
||||
const output: *Output = @ptrFromInt(wlr_output.data);
|
||||
const output: *Output = @alignCast(@ptrCast(wlr_output.data));
|
||||
|
||||
var proposed_state = wlr.Output.State.init();
|
||||
head.state.apply(&proposed_state);
|
||||
@ -864,7 +857,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 = @as(?*Output, @ptrFromInt(event.output.data)) orelse return;
|
||||
const output: *Output = @alignCast(@ptrCast(event.output.data orelse return));
|
||||
|
||||
std.log.debug("client requested dpms {s} for output {s}", .{
|
||||
@tagName(event.mode),
|
||||
@ -895,16 +888,3 @@ fn handlePowerManagerSetMode(
|
||||
|
||||
output.updateLockRenderStateOnEnableDisable();
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ const util = @import("util.zig");
|
||||
|
||||
const LayerSurface = @import("LayerSurface.zig");
|
||||
const LockSurface = @import("LockSurface.zig");
|
||||
const InputPopup = @import("InputPopup.zig");
|
||||
const View = @import("View.zig");
|
||||
const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig");
|
||||
|
||||
@ -45,7 +46,7 @@ pub fn attach(node: *wlr.SceneNode, data: Data) error{OutOfMemory}!void {
|
||||
.node = node,
|
||||
.data = data,
|
||||
};
|
||||
node.data = @intFromPtr(scene_node_data);
|
||||
node.data = scene_node_data;
|
||||
|
||||
node.events.destroy.add(&scene_node_data.destroy);
|
||||
}
|
||||
@ -53,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, @ptrFromInt(n.data))) |scene_node_data| {
|
||||
if (@as(?*SceneNodeData, @alignCast(@ptrCast(n.data)))) |scene_node_data| {
|
||||
return scene_node_data;
|
||||
}
|
||||
if (n.parent) |parent_tree| {
|
||||
@ -65,19 +66,17 @@ pub fn fromNode(node: *wlr.SceneNode) ?*SceneNodeData {
|
||||
}
|
||||
|
||||
pub fn fromSurface(surface: *wlr.Surface) ?*SceneNodeData {
|
||||
if (surface.getRootSurface()) |root_surface| {
|
||||
if (@as(?*wlr.SceneNode, @ptrFromInt(root_surface.data))) |node| {
|
||||
if (@as(?*wlr.SceneNode, @alignCast(@ptrCast(surface.getRootSurface().data)))) |node| {
|
||||
return fromNode(node);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const scene_node_data = @fieldParentPtr(SceneNodeData, "destroy", listener);
|
||||
const scene_node_data: *SceneNodeData = @fieldParentPtr("destroy", listener);
|
||||
|
||||
scene_node_data.destroy.link.remove();
|
||||
scene_node_data.node.data = 0;
|
||||
scene_node_data.node.data = null;
|
||||
|
||||
util.gpa.destroy(scene_node_data);
|
||||
}
|
||||
|
@ -33,7 +33,6 @@ const InputDevice = @import("InputDevice.zig");
|
||||
const InputManager = @import("InputManager.zig");
|
||||
const InputRelay = @import("InputRelay.zig");
|
||||
const Keyboard = @import("Keyboard.zig");
|
||||
const KeyboardGroup = @import("KeyboardGroup.zig");
|
||||
const LayerSurface = @import("LayerSurface.zig");
|
||||
const LockSurface = @import("LockSurface.zig");
|
||||
const Mapping = @import("Mapping.zig");
|
||||
@ -84,7 +83,7 @@ mapping_repeat_timer: *wl.EventSource,
|
||||
/// Currently repeating mapping, if any
|
||||
repeating_mapping: ?*const Mapping = null,
|
||||
|
||||
keyboard_groups: std.TailQueue(KeyboardGroup) = .{},
|
||||
keyboard_group: *wlr.KeyboardGroup,
|
||||
|
||||
/// Currently focused output. Null only when there are no outputs at all.
|
||||
focused_output: ?*Output = null,
|
||||
@ -121,12 +120,15 @@ pub fn init(seat: *Seat, name: [*:0]const u8) !void {
|
||||
.cursor = undefined,
|
||||
.relay = undefined,
|
||||
.mapping_repeat_timer = mapping_repeat_timer,
|
||||
.keyboard_group = try wlr.KeyboardGroup.create(),
|
||||
};
|
||||
seat.wlr_seat.data = @intFromPtr(seat);
|
||||
seat.wlr_seat.data = seat;
|
||||
|
||||
try seat.cursor.init(seat);
|
||||
seat.relay.init();
|
||||
|
||||
try seat.tryAddDevice(&seat.keyboard_group.keyboard.base);
|
||||
|
||||
seat.wlr_seat.events.request_set_selection.add(&seat.request_set_selection);
|
||||
seat.wlr_seat.events.request_start_drag.add(&seat.request_start_drag);
|
||||
seat.wlr_seat.events.start_drag.add(&seat.start_drag);
|
||||
@ -142,9 +144,7 @@ pub fn deinit(seat: *Seat) void {
|
||||
seat.cursor.deinit();
|
||||
seat.mapping_repeat_timer.remove();
|
||||
|
||||
while (seat.keyboard_groups.first) |node| {
|
||||
node.data.destroy();
|
||||
}
|
||||
seat.keyboard_group.destroy();
|
||||
|
||||
seat.request_set_selection.link.remove();
|
||||
seat.request_start_drag.link.remove();
|
||||
@ -165,14 +165,21 @@ pub fn focus(seat: *Seat, _target: ?*View) void {
|
||||
// Views may not receive focus while locked.
|
||||
if (server.lock_manager.state != .unlocked) return;
|
||||
|
||||
// While a layer surface is exclusively focused, views may not receive focus
|
||||
// A layer surface with exclusive focus will prevent any view from gaining
|
||||
// focus if it is on the top or overlay layer. Otherwise, only steal focus
|
||||
// from a focused layer surface if there is an explicit target view.
|
||||
if (seat.focused == .layer) {
|
||||
const wlr_layer_surface = seat.focused.layer.wlr_layer_surface;
|
||||
assert(wlr_layer_surface.surface.mapped);
|
||||
if (wlr_layer_surface.current.keyboard_interactive == .exclusive and
|
||||
(wlr_layer_surface.current.layer == .top or wlr_layer_surface.current.layer == .overlay))
|
||||
{
|
||||
return;
|
||||
switch (wlr_layer_surface.current.keyboard_interactive) {
|
||||
.none => {},
|
||||
.exclusive => switch (wlr_layer_surface.current.layer) {
|
||||
.top, .overlay => return,
|
||||
.bottom, .background => if (target == null) return,
|
||||
_ => {},
|
||||
},
|
||||
.on_demand => if (target == null) return,
|
||||
_ => {},
|
||||
}
|
||||
}
|
||||
|
||||
@ -282,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 = @ptrFromInt(wlr_constraint.data);
|
||||
seat.cursor.constraint = @alignCast(@ptrCast(wlr_constraint.data));
|
||||
assert(seat.cursor.constraint != null);
|
||||
}
|
||||
}
|
||||
@ -309,7 +316,7 @@ 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 = @ptrFromInt(wlr_keyboard.data);
|
||||
const keyboard: *Keyboard = @alignCast(@ptrCast(wlr_keyboard.data));
|
||||
|
||||
var keycodes: std.BoundedArray(u32, Keyboard.Pressed.capacity) = .{};
|
||||
for (keyboard.pressed.keys.constSlice()) |item| {
|
||||
@ -504,11 +511,11 @@ fn tryAddDevice(seat: *Seat, wlr_device: *wlr.InputDevice) !void {
|
||||
|
||||
seat.cursor.wlr_cursor.attachInputDevice(wlr_device);
|
||||
},
|
||||
.tablet_tool => {
|
||||
.tablet => {
|
||||
try Tablet.create(seat, wlr_device);
|
||||
seat.cursor.wlr_cursor.attachInputDevice(wlr_device);
|
||||
},
|
||||
.switch_device => {
|
||||
.@"switch" => {
|
||||
const switch_device = try util.gpa.create(Switch);
|
||||
errdefer util.gpa.destroy(switch_device);
|
||||
|
||||
@ -531,7 +538,7 @@ pub fn updateCapabilities(seat: *Seat) void {
|
||||
switch (device.wlr_device.type) {
|
||||
.keyboard => capabilities.keyboard = true,
|
||||
.touch => capabilities.touch = true,
|
||||
.pointer, .switch_device, .tablet_tool => {},
|
||||
.pointer, .@"switch", .tablet => {},
|
||||
.tablet_pad => unreachable,
|
||||
}
|
||||
}
|
||||
@ -544,7 +551,7 @@ fn handleRequestSetSelection(
|
||||
listener: *wl.Listener(*wlr.Seat.event.RequestSetSelection),
|
||||
event: *wlr.Seat.event.RequestSetSelection,
|
||||
) void {
|
||||
const seat = @fieldParentPtr(Seat, "request_set_selection", listener);
|
||||
const seat: *Seat = @fieldParentPtr("request_set_selection", listener);
|
||||
seat.wlr_seat.setSelection(event.source, event.serial);
|
||||
}
|
||||
|
||||
@ -552,7 +559,7 @@ fn handleRequestStartDrag(
|
||||
listener: *wl.Listener(*wlr.Seat.event.RequestStartDrag),
|
||||
event: *wlr.Seat.event.RequestStartDrag,
|
||||
) void {
|
||||
const seat = @fieldParentPtr(Seat, "request_start_drag", listener);
|
||||
const seat: *Seat = @fieldParentPtr("request_start_drag", listener);
|
||||
|
||||
// The start_drag request is ignored by wlroots if a drag is currently in progress.
|
||||
assert(seat.drag == .none);
|
||||
@ -576,7 +583,7 @@ fn handleRequestStartDrag(
|
||||
}
|
||||
|
||||
fn handleStartDrag(listener: *wl.Listener(*wlr.Drag), wlr_drag: *wlr.Drag) void {
|
||||
const seat = @fieldParentPtr(Seat, "start_drag", listener);
|
||||
const seat: *Seat = @fieldParentPtr("start_drag", listener);
|
||||
|
||||
assert(seat.drag == .none);
|
||||
switch (wlr_drag.grab_type) {
|
||||
@ -599,7 +606,7 @@ fn handleStartDrag(listener: *wl.Listener(*wlr.Drag), wlr_drag: *wlr.Drag) void
|
||||
}
|
||||
|
||||
fn handleDragDestroy(listener: *wl.Listener(*wlr.Drag), _: *wlr.Drag) void {
|
||||
const seat = @fieldParentPtr(Seat, "drag_destroy", listener);
|
||||
const seat: *Seat = @fieldParentPtr("drag_destroy", listener);
|
||||
seat.drag_destroy.link.remove();
|
||||
|
||||
switch (seat.drag) {
|
||||
@ -617,6 +624,6 @@ fn handleRequestSetPrimarySelection(
|
||||
listener: *wl.Listener(*wlr.Seat.event.RequestSetPrimarySelection),
|
||||
event: *wlr.Seat.event.RequestSetPrimarySelection,
|
||||
) void {
|
||||
const seat = @fieldParentPtr(Seat, "request_set_primary_selection", listener);
|
||||
const seat: *Seat = @fieldParentPtr("request_set_primary_selection", listener);
|
||||
seat.wlr_seat.setPrimarySelection(event.source, event.serial);
|
||||
}
|
||||
|
@ -51,7 +51,7 @@ fn handleRequest(seat_status_v1: *zriver.SeatStatusV1, request: zriver.SeatStatu
|
||||
}
|
||||
|
||||
fn handleDestroy(_: *zriver.SeatStatusV1, seat_status: *SeatStatus) void {
|
||||
const node = @fieldParentPtr(std.SinglyLinkedList(SeatStatus).Node, "data", seat_status);
|
||||
const node: *std.SinglyLinkedList(SeatStatus).Node = @fieldParentPtr("data", seat_status);
|
||||
seat_status.seat.status_trackers.remove(node);
|
||||
util.gpa.destroy(node);
|
||||
}
|
||||
|
158
river/Server.zig
158
river/Server.zig
@ -19,6 +19,8 @@ const Server = @This();
|
||||
const build_options = @import("build_options");
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const mem = std.mem;
|
||||
const posix = std.posix;
|
||||
const wlr = @import("wlroots");
|
||||
const wl = @import("wayland").server.wl;
|
||||
|
||||
@ -37,6 +39,7 @@ const Root = @import("Root.zig");
|
||||
const Seat = @import("Seat.zig");
|
||||
const SceneNodeData = @import("SceneNodeData.zig");
|
||||
const StatusManager = @import("StatusManager.zig");
|
||||
const TabletTool = @import("TabletTool.zig");
|
||||
const XdgDecoration = @import("XdgDecoration.zig");
|
||||
const XdgToplevel = @import("XdgToplevel.zig");
|
||||
const XwaylandOverrideRedirect = @import("XwaylandOverrideRedirect.zig");
|
||||
@ -58,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,
|
||||
@ -82,6 +85,10 @@ screencopy_manager: *wlr.ScreencopyManagerV1,
|
||||
|
||||
foreign_toplevel_manager: *wlr.ForeignToplevelManagerV1,
|
||||
|
||||
tearing_control_manager: *wlr.TearingControlManagerV1,
|
||||
|
||||
alpha_modifier: *wlr.AlphaModifierV1,
|
||||
|
||||
input_manager: InputManager,
|
||||
root: Root,
|
||||
config: Config,
|
||||
@ -95,8 +102,10 @@ xwayland: if (build_options.xwayland) ?*wlr.Xwayland else void = if (build_optio
|
||||
new_xwayland_surface: if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface) else void =
|
||||
if (build_options.xwayland) wl.Listener(*wlr.XwaylandSurface).init(handleNewXwaylandSurface),
|
||||
|
||||
new_xdg_surface: wl.Listener(*wlr.XdgSurface) =
|
||||
wl.Listener(*wlr.XdgSurface).init(handleNewXdgSurface),
|
||||
renderer_lost: wl.Listener(void) = wl.Listener(void).init(handleRendererLost),
|
||||
|
||||
new_xdg_toplevel: wl.Listener(*wlr.XdgToplevel) =
|
||||
wl.Listener(*wlr.XdgToplevel).init(handleNewXdgToplevel),
|
||||
new_toplevel_decoration: wl.Listener(*wlr.XdgToplevelDecorationV1) =
|
||||
wl.Listener(*wlr.XdgToplevelDecorationV1).init(handleNewToplevelDecoration),
|
||||
new_layer_surface: wl.Listener(*wlr.LayerSurfaceV1) =
|
||||
@ -112,18 +121,18 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
|
||||
// This keeps the code simpler and more readable.
|
||||
|
||||
const wl_server = try wl.Server.create();
|
||||
const loop = wl_server.getEventLoop();
|
||||
|
||||
var session: ?*wlr.Session = undefined;
|
||||
const backend = try wlr.Backend.autocreate(wl_server, &session);
|
||||
const backend = try wlr.Backend.autocreate(loop, &session);
|
||||
const renderer = try wlr.Renderer.autocreate(backend);
|
||||
|
||||
const compositor = try wlr.Compositor.create(wl_server, 6, renderer);
|
||||
|
||||
const loop = wl_server.getEventLoop();
|
||||
server.* = .{
|
||||
.wl_server = wl_server,
|
||||
.sigint_source = try loop.addSignal(*wl.Server, std.os.SIG.INT, terminate, wl_server),
|
||||
.sigterm_source = try loop.addSignal(*wl.Server, std.os.SIG.TERM, terminate, wl_server),
|
||||
.sigint_source = try loop.addSignal(*wl.Server, posix.SIG.INT, terminate, wl_server),
|
||||
.sigterm_source = try loop.addSignal(*wl.Server, posix.SIG.TERM, terminate, wl_server),
|
||||
|
||||
.backend = backend,
|
||||
.session = session,
|
||||
@ -155,6 +164,10 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
|
||||
|
||||
.foreign_toplevel_manager = try wlr.ForeignToplevelManagerV1.create(wl_server),
|
||||
|
||||
.tearing_control_manager = try wlr.TearingControlManagerV1.create(wl_server, 1),
|
||||
|
||||
.alpha_modifier = try wlr.AlphaModifierV1.create(wl_server),
|
||||
|
||||
.config = try Config.init(),
|
||||
|
||||
.root = undefined,
|
||||
@ -166,15 +179,15 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
|
||||
.lock_manager = undefined,
|
||||
};
|
||||
|
||||
if (renderer.getDmabufFormats() != null and renderer.getDrmFd() >= 0) {
|
||||
// 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);
|
||||
|
||||
if (renderer.getTextureFormats(@intFromEnum(wlr.BufferCap.dmabuf)) != null) {
|
||||
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);
|
||||
@ -189,7 +202,8 @@ pub fn init(server: *Server, runtime_xwayland: bool) !void {
|
||||
try server.idle_inhibit_manager.init();
|
||||
try server.lock_manager.init();
|
||||
|
||||
server.xdg_shell.events.new_surface.add(&server.new_xdg_surface);
|
||||
server.renderer.events.lost.add(&server.renderer_lost);
|
||||
server.xdg_shell.events.new_toplevel.add(&server.new_xdg_toplevel);
|
||||
server.xdg_decoration_manager.events.new_toplevel_decoration.add(&server.new_toplevel_decoration);
|
||||
server.layer_shell.events.new_surface.add(&server.new_layer_surface);
|
||||
server.xdg_activation.events.request_activate.add(&server.request_activate);
|
||||
@ -203,7 +217,8 @@ pub fn deinit(server: *Server) void {
|
||||
server.sigint_source.remove();
|
||||
server.sigterm_source.remove();
|
||||
|
||||
server.new_xdg_surface.link.remove();
|
||||
server.renderer_lost.link.remove();
|
||||
server.new_xdg_toplevel.link.remove();
|
||||
server.new_toplevel_decoration.link.remove();
|
||||
server.new_layer_surface.link.remove();
|
||||
server.request_activate.link.remove();
|
||||
@ -218,6 +233,8 @@ 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
|
||||
@ -276,31 +293,30 @@ fn globalFilter(client: *const wl.Client, global: *const wl.Global, server: *Ser
|
||||
}
|
||||
}
|
||||
|
||||
fn hackGlobal(ptr: *anyopaque) *wl.Global {
|
||||
// TODO(wlroots) MR that eliminates the need for this hack:
|
||||
// https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4612
|
||||
if (wlr.version.major != 0 or wlr.version.minor != 17) @compileError("FIXME");
|
||||
|
||||
return @as(*extern struct { global: *wl.Global }, @alignCast(@ptrCast(ptr))).global;
|
||||
}
|
||||
|
||||
/// Returns true if the global is allowlisted for security contexts
|
||||
fn allowlist(server: *Server, global: *const wl.Global) bool {
|
||||
if (server.drm) |drm| if (global == drm.global) return true;
|
||||
if (server.linux_dmabuf) |linux_dmabuf| if (global == linux_dmabuf.global) return true;
|
||||
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;
|
||||
}
|
||||
|
||||
// We must use the getInterface() approach for dynamically created globals
|
||||
// such as wl_output and wl_seat since the wl_global_create() function will
|
||||
// advertise the global to clients and invoke this filter before returning
|
||||
// the new global pointer.
|
||||
//
|
||||
if ((mem.orderZ(u8, global.getInterface().name, "wl_output") == .eq) or
|
||||
(mem.orderZ(u8, global.getInterface().name, "wl_seat") == .eq))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
// For other globals I like the current pointer comparison approach as it
|
||||
// should catch river accidentally exposing multiple copies of e.g. wl_shm
|
||||
// with an assertion failure.
|
||||
return global.getInterface() == wl.Output.getInterface() or
|
||||
global.getInterface() == wl.Seat.getInterface() or
|
||||
global == hackGlobal(server.shm) or
|
||||
global == hackGlobal(server.single_pixel_buffer_manager) or
|
||||
return global == server.shm.global or
|
||||
global == server.single_pixel_buffer_manager.global or
|
||||
global == server.viewporter.global or
|
||||
global == server.fractional_scale_manager.global or
|
||||
global == server.compositor.global or
|
||||
@ -318,7 +334,9 @@ fn allowlist(server: *Server, global: *const wl.Global) bool {
|
||||
global == server.input_manager.text_input_manager.global or
|
||||
global == server.input_manager.tablet_manager.global or
|
||||
global == server.input_manager.pointer_gestures.global or
|
||||
global == server.idle_inhibit_manager.wlr_manager.global;
|
||||
global == server.idle_inhibit_manager.wlr_manager.global or
|
||||
global == server.tearing_control_manager.global or
|
||||
global == server.alpha_modifier.global;
|
||||
}
|
||||
|
||||
/// Returns true if the global is blocked for security contexts
|
||||
@ -335,7 +353,7 @@ fn blocklist(server: *Server, global: *const wl.Global) bool {
|
||||
global == server.root.output_manager.global or
|
||||
global == server.root.power_manager.global or
|
||||
global == server.root.gamma_control_manager.global or
|
||||
global == hackGlobal(server.input_manager.idle_notifier) or
|
||||
global == server.input_manager.idle_notifier.global or
|
||||
global == server.input_manager.virtual_pointer_manager.global or
|
||||
global == server.input_manager.virtual_keyboard_manager.global or
|
||||
global == server.input_manager.input_method_manager.global or
|
||||
@ -348,17 +366,55 @@ fn terminate(_: c_int, wl_server: *wl.Server) c_int {
|
||||
return 0;
|
||||
}
|
||||
|
||||
fn handleNewXdgSurface(_: *wl.Listener(*wlr.XdgSurface), xdg_surface: *wlr.XdgSurface) void {
|
||||
if (xdg_surface.role == .popup) {
|
||||
log.debug("new xdg_popup", .{});
|
||||
return;
|
||||
fn handleRendererLost(listener: *wl.Listener(void)) void {
|
||||
const server: *Server = @fieldParentPtr("renderer_lost", listener);
|
||||
|
||||
log.info("recovering from GPU reset", .{});
|
||||
|
||||
// There's not much that can be done if creating a new renderer or allocator fails.
|
||||
// With luck there might be another GPU reset after which we try again and succeed.
|
||||
|
||||
server.recoverFromGpuReset() catch |err| switch (err) {
|
||||
error.RendererCreateFailed => log.err("failed to create new renderer after GPU reset", .{}),
|
||||
error.AllocatorCreateFailed => log.err("failed to create new allocator after GPU reset", .{}),
|
||||
};
|
||||
}
|
||||
|
||||
fn recoverFromGpuReset(server: *Server) !void {
|
||||
const new_renderer = try wlr.Renderer.autocreate(server.backend);
|
||||
errdefer new_renderer.destroy();
|
||||
|
||||
const new_allocator = try wlr.Allocator.autocreate(server.backend, new_renderer);
|
||||
errdefer comptime unreachable; // no failure allowed after this point
|
||||
|
||||
server.renderer_lost.link.remove();
|
||||
new_renderer.events.lost.add(&server.renderer_lost);
|
||||
|
||||
server.compositor.setRenderer(new_renderer);
|
||||
|
||||
{
|
||||
var it = server.root.all_outputs.iterator(.forward);
|
||||
while (it.next()) |output| {
|
||||
// This should never fail here as failure with this combination of
|
||||
// renderer, allocator, and backend should have prevented creating
|
||||
// the output in the first place.
|
||||
_ = output.wlr_output.initRender(new_allocator, new_renderer);
|
||||
}
|
||||
}
|
||||
|
||||
server.renderer.destroy();
|
||||
server.renderer = new_renderer;
|
||||
|
||||
server.allocator.destroy();
|
||||
server.allocator = new_allocator;
|
||||
}
|
||||
|
||||
fn handleNewXdgToplevel(_: *wl.Listener(*wlr.XdgToplevel), xdg_toplevel: *wlr.XdgToplevel) void {
|
||||
log.debug("new xdg_toplevel", .{});
|
||||
|
||||
XdgToplevel.create(xdg_surface.role_data.toplevel.?) catch {
|
||||
XdgToplevel.create(xdg_toplevel) catch {
|
||||
log.err("out of memory", .{});
|
||||
xdg_surface.resource.postNoMemory();
|
||||
xdg_toplevel.resource.postNoMemory();
|
||||
return;
|
||||
};
|
||||
}
|
||||
@ -371,7 +427,7 @@ fn handleNewToplevelDecoration(
|
||||
}
|
||||
|
||||
fn handleNewLayerSurface(listener: *wl.Listener(*wlr.LayerSurfaceV1), wlr_layer_surface: *wlr.LayerSurfaceV1) void {
|
||||
const server = @fieldParentPtr(Server, "new_layer_surface", listener);
|
||||
const server: *Server = @fieldParentPtr("new_layer_surface", listener);
|
||||
|
||||
log.debug(
|
||||
"new layer surface: namespace {s}, layer {s}, anchor {b:0>4}, size {},{}, margin {},{},{},{}, exclusive_zone {}",
|
||||
@ -431,7 +487,7 @@ fn handleRequestActivate(
|
||||
listener: *wl.Listener(*wlr.XdgActivationV1.event.RequestActivate),
|
||||
event: *wlr.XdgActivationV1.event.RequestActivate,
|
||||
) void {
|
||||
const server = @fieldParentPtr(Server, "request_activate", listener);
|
||||
const server: *Server = @fieldParentPtr("request_activate", listener);
|
||||
|
||||
const node_data = SceneNodeData.fromSurface(event.surface) orelse return;
|
||||
switch (node_data.data) {
|
||||
@ -449,17 +505,27 @@ fn handleRequestSetCursorShape(
|
||||
_: *wl.Listener(*wlr.CursorShapeManagerV1.event.RequestSetShape),
|
||||
event: *wlr.CursorShapeManagerV1.event.RequestSetShape,
|
||||
) void {
|
||||
// Ignore requests to set a tablet tool's cursor shape for now
|
||||
// TODO(wlroots): https://gitlab.freedesktop.org/wlroots/wlroots/-/issues/3821
|
||||
if (event.device_type == .tablet_tool) return;
|
||||
const seat: *Seat = @alignCast(@ptrCast(event.seat_client.seat.data));
|
||||
|
||||
if (event.tablet_tool) |wp_tool| {
|
||||
assert(event.device_type == .tablet_tool);
|
||||
|
||||
const tool = TabletTool.get(event.seat_client.seat, wp_tool.wlr_tool) catch return;
|
||||
|
||||
if (tool.allowSetCursor(event.seat_client, event.serial)) {
|
||||
const name = wlr.CursorShapeManagerV1.shapeName(event.shape);
|
||||
tool.wlr_cursor.setXcursor(seat.cursor.xcursor_manager, name);
|
||||
}
|
||||
} else {
|
||||
assert(event.device_type == .pointer);
|
||||
|
||||
const focused_client = event.seat_client.seat.pointer_state.focused_client;
|
||||
|
||||
// This can be sent by any client, so we check to make sure this one is
|
||||
// actually has pointer focus first.
|
||||
if (focused_client == event.seat_client) {
|
||||
const seat: *Seat = @ptrFromInt(event.seat_client.seat.data);
|
||||
const name = wlr.CursorShapeManagerV1.shapeName(event.shape);
|
||||
seat.cursor.setXcursor(name);
|
||||
seat.cursor.setImage(.{ .xcursor = name });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -46,7 +46,7 @@ pub fn init(status_manager: *StatusManager) !void {
|
||||
}
|
||||
|
||||
fn handleServerDestroy(listener: *wl.Listener(*wl.Server), _: *wl.Server) void {
|
||||
const status_manager = @fieldParentPtr(StatusManager, "server_destroy", listener);
|
||||
const status_manager: *StatusManager = @fieldParentPtr("server_destroy", listener);
|
||||
status_manager.global.destroy();
|
||||
}
|
||||
|
||||
@ -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 = @ptrFromInt(wlr_output.data);
|
||||
const output: *Output = @alignCast(@ptrCast(wlr_output.data));
|
||||
|
||||
const resource = zriver.OutputStatusV1.create(
|
||||
status_manager_v1.getClient(),
|
||||
@ -86,7 +86,7 @@ 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 = @ptrFromInt(wlr_seat.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(wlr_seat.seat.data));
|
||||
|
||||
const node = util.gpa.create(std.SinglyLinkedList(SeatStatus).Node) catch {
|
||||
status_manager_v1.getClient().postNoMemory();
|
||||
|
@ -71,7 +71,7 @@ pub fn deinit(switch_device: *Switch) void {
|
||||
}
|
||||
|
||||
fn handleToggle(listener: *wl.Listener(*wlr.Switch.event.Toggle), event: *wlr.Switch.event.Toggle) void {
|
||||
const switch_device = @fieldParentPtr(Switch, "toggle", listener);
|
||||
const switch_device: *Switch = @fieldParentPtr("toggle", listener);
|
||||
|
||||
switch_device.device.seat.handleActivity();
|
||||
|
||||
|
@ -33,7 +33,7 @@ wp_tablet: *wlr.TabletV2Tablet,
|
||||
output_mapping: ?*wlr.Output = null,
|
||||
|
||||
pub fn create(seat: *Seat, wlr_device: *wlr.InputDevice) !void {
|
||||
assert(wlr_device.type == .tablet_tool);
|
||||
assert(wlr_device.type == .tablet);
|
||||
|
||||
const tablet = try util.gpa.create(Tablet);
|
||||
errdefer util.gpa.destroy(tablet);
|
||||
|
@ -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, @ptrFromInt(wlr_tool.data))) |tool| {
|
||||
if (@as(?*TabletTool, @alignCast(@ptrCast(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 = @intFromPtr(tool);
|
||||
wlr_tool.data = tool;
|
||||
|
||||
wlr_tool.events.destroy.add(&tool.destroy);
|
||||
tool.wp_tool.events.set_cursor.add(&tool.set_cursor);
|
||||
@ -90,9 +90,9 @@ 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 = @fieldParentPtr(TabletTool, "destroy", listener);
|
||||
const tool: *TabletTool = @fieldParentPtr("destroy", listener);
|
||||
|
||||
tool.wp_tool.wlr_tool.data = 0;
|
||||
tool.wp_tool.wlr_tool.data = null;
|
||||
|
||||
tool.wlr_cursor.destroy();
|
||||
|
||||
@ -102,24 +102,29 @@ fn handleDestroy(listener: *wl.Listener(*wlr.TabletTool), _: *wlr.TabletTool) vo
|
||||
util.gpa.destroy(tool);
|
||||
}
|
||||
|
||||
pub fn allowSetCursor(tool: *TabletTool, seat_client: *wlr.Seat.Client, serial: u32) bool {
|
||||
if (tool.wp_tool.focused_surface == null or
|
||||
tool.wp_tool.focused_surface.?.resource.getClient() != seat_client.client)
|
||||
{
|
||||
log.debug("client tried to set cursor without focus", .{});
|
||||
return false;
|
||||
}
|
||||
if (serial != tool.wp_tool.proximity_serial) {
|
||||
log.debug("focused client tried to set cursor with incorrect serial", .{});
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
fn handleSetCursor(
|
||||
listener: *wl.Listener(*wlr.TabletV2TabletTool.event.SetCursor),
|
||||
event: *wlr.TabletV2TabletTool.event.SetCursor,
|
||||
) void {
|
||||
const tool = @fieldParentPtr(TabletTool, "set_cursor", listener);
|
||||
|
||||
if (tool.wp_tool.focused_surface == null or
|
||||
tool.wp_tool.focused_surface.?.resource.getClient() != event.seat_client.client)
|
||||
{
|
||||
log.debug("client tried to set cursor without focus", .{});
|
||||
return;
|
||||
}
|
||||
if (event.serial != tool.wp_tool.proximity_serial) {
|
||||
log.debug("focused client tried to set cursor with incorrect serial", .{});
|
||||
return;
|
||||
}
|
||||
const tool: *TabletTool = @fieldParentPtr("set_cursor", listener);
|
||||
|
||||
if (tool.allowSetCursor(event.seat_client, event.serial)) {
|
||||
tool.wlr_cursor.setSurface(event.surface, event.hotspot_x, event.hotspot_y);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn axis(tool: *TabletTool, tablet: *Tablet, event: *wlr.Tablet.event.Axis) void {
|
||||
|
@ -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 = @ptrFromInt(wlr_text_input.seat.data);
|
||||
const seat: *Seat = @alignCast(@ptrCast(wlr_text_input.seat.data));
|
||||
|
||||
const text_input = try util.gpa.create(TextInput);
|
||||
|
||||
@ -63,8 +63,13 @@ pub fn create(wlr_text_input: *wlr.TextInputV3) !void {
|
||||
}
|
||||
|
||||
fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
|
||||
const text_input = @fieldParentPtr(TextInput, "enable", listener);
|
||||
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
|
||||
const text_input: *TextInput = @fieldParentPtr("enable", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(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", .{});
|
||||
return;
|
||||
}
|
||||
|
||||
// The same text_input object may be enabled multiple times consecutively
|
||||
// without first disabling it. Enabling a different text input object without
|
||||
@ -85,8 +90,8 @@ fn handleEnable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v
|
||||
}
|
||||
|
||||
fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
|
||||
const text_input = @fieldParentPtr(TextInput, "commit", listener);
|
||||
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
|
||||
const text_input: *TextInput = @fieldParentPtr("commit", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(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?", .{});
|
||||
@ -99,8 +104,8 @@ fn handleCommit(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) v
|
||||
}
|
||||
|
||||
fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
|
||||
const text_input = @fieldParentPtr(TextInput, "disable", listener);
|
||||
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
|
||||
const text_input: *TextInput = @fieldParentPtr("disable", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(text_input.wlr_text_input.seat.data));
|
||||
|
||||
if (seat.relay.text_input == text_input) {
|
||||
seat.relay.disableTextInput();
|
||||
@ -108,8 +113,8 @@ fn handleDisable(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3)
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(*wlr.TextInputV3), _: *wlr.TextInputV3) void {
|
||||
const text_input = @fieldParentPtr(TextInput, "destroy", listener);
|
||||
const seat: *Seat = @ptrFromInt(text_input.wlr_text_input.seat.data);
|
||||
const text_input: *TextInput = @fieldParentPtr("destroy", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(text_input.wlr_text_input.seat.data));
|
||||
|
||||
if (seat.relay.text_input == text_input) {
|
||||
seat.relay.disableTextInput();
|
||||
|
@ -44,7 +44,7 @@ pub fn direction(v: Vector) ?wlr.OutputLayout.Direction {
|
||||
// A zero length vector has no direction
|
||||
if (v.x == 0 and v.y == 0) return null;
|
||||
|
||||
if ((math.absInt(v.y) catch return null) > (math.absInt(v.x) catch return null)) {
|
||||
if (@abs(v.y) > @abs(v.x)) {
|
||||
// Careful: We are operating in a Y-inverted coordinate system.
|
||||
return if (v.y > 0) .down else .up;
|
||||
} else {
|
||||
|
@ -20,9 +20,10 @@ const build_options = @import("build_options");
|
||||
const std = @import("std");
|
||||
const assert = std.debug.assert;
|
||||
const math = std.math;
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
const wlr = @import("wlroots");
|
||||
const wl = @import("wayland").server.wl;
|
||||
const wp = @import("wayland").server.wp;
|
||||
|
||||
const server = &@import("main.zig").server;
|
||||
const util = @import("util.zig");
|
||||
@ -59,6 +60,12 @@ const AttachRelativeMode = enum {
|
||||
below,
|
||||
};
|
||||
|
||||
const TearingMode = enum {
|
||||
no_tearing,
|
||||
tearing,
|
||||
window_hint,
|
||||
};
|
||||
|
||||
pub const State = struct {
|
||||
/// The output the view is currently assigned to.
|
||||
/// May be null if there are no outputs or for newly created views.
|
||||
@ -177,6 +184,8 @@ foreign_toplevel_handle: ForeignToplevelHandle = .{},
|
||||
/// Connector name of the output this view occupied before an evacuation.
|
||||
output_before_evac: ?[]const u8 = null,
|
||||
|
||||
tearing_mode: TearingMode = .window_hint,
|
||||
|
||||
pub fn create(impl: Impl) error{OutOfMemory}!*View {
|
||||
assert(impl != .none);
|
||||
|
||||
@ -437,7 +446,11 @@ pub fn updateSceneState(view: *View) void {
|
||||
for (&view.borders, &border_boxes) |border, *border_box| {
|
||||
border_box.x += box.x;
|
||||
border_box.y += box.y;
|
||||
_ = border_box.intersection(border_box, &output_box);
|
||||
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.x -= box.x;
|
||||
border_box.y -= box.y;
|
||||
|
||||
@ -472,8 +485,8 @@ pub fn rootSurface(view: View) ?*wlr.Surface {
|
||||
|
||||
pub fn sendFrameDone(view: View) void {
|
||||
assert(view.mapped and !view.destroying);
|
||||
var now: os.timespec = undefined;
|
||||
os.clock_gettime(os.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
|
||||
|
||||
const now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
|
||||
view.rootSurface().?.sendFrameDone(&now);
|
||||
}
|
||||
|
||||
@ -571,6 +584,22 @@ pub fn getAppId(view: View) ?[*:0]const u8 {
|
||||
};
|
||||
}
|
||||
|
||||
/// Return true if tearing should be allowed for the view.
|
||||
pub fn allowTearing(view: *View) bool {
|
||||
switch (view.tearing_mode) {
|
||||
.no_tearing => return false,
|
||||
.tearing => return true,
|
||||
.window_hint => {
|
||||
if (server.config.allow_tearing) {
|
||||
if (view.rootSurface()) |root_surface| {
|
||||
return server.tearing_control_manager.hintFromSurface(root_surface) == .@"async";
|
||||
}
|
||||
}
|
||||
return false;
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
/// Clamp the width/height of the box to the constraints of the view
|
||||
pub fn applyConstraints(view: *View, box: *wlr.Box) void {
|
||||
box.width = math.clamp(box.width, view.constraints.min_width, view.constraints.max_width);
|
||||
@ -639,6 +668,10 @@ pub fn map(view: *View) !void {
|
||||
view.pending.ssd = ssd;
|
||||
}
|
||||
|
||||
if (server.config.rules.tearing.match(view)) |tearing| {
|
||||
view.tearing_mode = if (tearing) .tearing else .no_tearing;
|
||||
}
|
||||
|
||||
if (server.config.rules.dimensions.match(view)) |dimensions| {
|
||||
view.pending.box.width = dimensions.width;
|
||||
view.pending.box.height = dimensions.height;
|
||||
|
@ -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 = @ptrFromInt(wlr_decoration.toplevel.base.data);
|
||||
const toplevel: *XdgToplevel = @alignCast(@ptrCast(wlr_decoration.toplevel.base.data));
|
||||
|
||||
toplevel.decoration = .{ .wlr_decoration = wlr_decoration };
|
||||
const decoration = &toplevel.decoration.?;
|
||||
@ -42,18 +42,13 @@ pub fn init(wlr_decoration: *wlr.XdgToplevelDecorationV1) void {
|
||||
wlr_decoration.events.destroy.add(&decoration.destroy);
|
||||
wlr_decoration.events.request_mode.add(&decoration.request_mode);
|
||||
|
||||
const ssd = server.config.rules.ssd.match(toplevel.view) orelse
|
||||
(decoration.wlr_decoration.requested_mode != .client_side);
|
||||
|
||||
// TODO(wlroots): make sure this is properly batched in a single configure
|
||||
// with all other initial state when wlroots makes this possible.
|
||||
_ = wlr_decoration.setMode(if (ssd) .server_side else .client_side);
|
||||
|
||||
toplevel.view.pending.ssd = ssd;
|
||||
if (toplevel.wlr_toplevel.base.initialized) {
|
||||
handleRequestMode(&decoration.request_mode, wlr_decoration);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn deinit(decoration: *XdgDecoration) void {
|
||||
const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
|
||||
const toplevel: *XdgToplevel = @alignCast(@ptrCast(decoration.wlr_decoration.toplevel.base.data));
|
||||
|
||||
decoration.destroy.link.remove();
|
||||
decoration.request_mode.link.remove();
|
||||
@ -66,7 +61,7 @@ fn handleDestroy(
|
||||
listener: *wl.Listener(*wlr.XdgToplevelDecorationV1),
|
||||
_: *wlr.XdgToplevelDecorationV1,
|
||||
) void {
|
||||
const decoration = @fieldParentPtr(XdgDecoration, "destroy", listener);
|
||||
const decoration: *XdgDecoration = @fieldParentPtr("destroy", listener);
|
||||
|
||||
decoration.deinit();
|
||||
}
|
||||
@ -75,9 +70,9 @@ fn handleRequestMode(
|
||||
listener: *wl.Listener(*wlr.XdgToplevelDecorationV1),
|
||||
_: *wlr.XdgToplevelDecorationV1,
|
||||
) void {
|
||||
const decoration = @fieldParentPtr(XdgDecoration, "request_mode", listener);
|
||||
const decoration: *XdgDecoration = @fieldParentPtr("request_mode", listener);
|
||||
|
||||
const toplevel: *XdgToplevel = @ptrFromInt(decoration.wlr_decoration.toplevel.base.data);
|
||||
const toplevel: *XdgToplevel = @alignCast(@ptrCast(decoration.wlr_decoration.toplevel.base.data));
|
||||
const view = toplevel.view;
|
||||
|
||||
const ssd = server.config.rules.ssd.match(toplevel.view) orelse
|
||||
|
@ -35,6 +35,7 @@ root: *wlr.SceneTree,
|
||||
tree: *wlr.SceneTree,
|
||||
|
||||
destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy),
|
||||
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
|
||||
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
|
||||
reposition: wl.Listener(void) = wl.Listener(void).init(handleReposition),
|
||||
|
||||
@ -53,25 +54,33 @@ pub fn create(
|
||||
.tree = try parent.createSceneXdgSurface(wlr_xdg_popup.base),
|
||||
};
|
||||
|
||||
wlr_xdg_popup.base.events.destroy.add(&xdg_popup.destroy);
|
||||
wlr_xdg_popup.events.destroy.add(&xdg_popup.destroy);
|
||||
wlr_xdg_popup.base.surface.events.commit.add(&xdg_popup.commit);
|
||||
wlr_xdg_popup.base.events.new_popup.add(&xdg_popup.new_popup);
|
||||
wlr_xdg_popup.events.reposition.add(&xdg_popup.reposition);
|
||||
|
||||
handleReposition(&xdg_popup.reposition);
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const xdg_popup = @fieldParentPtr(XdgPopup, "destroy", listener);
|
||||
const xdg_popup: *XdgPopup = @fieldParentPtr("destroy", listener);
|
||||
|
||||
xdg_popup.destroy.link.remove();
|
||||
xdg_popup.commit.link.remove();
|
||||
xdg_popup.new_popup.link.remove();
|
||||
xdg_popup.reposition.link.remove();
|
||||
|
||||
util.gpa.destroy(xdg_popup);
|
||||
}
|
||||
|
||||
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const xdg_popup: *XdgPopup = @fieldParentPtr("commit", listener);
|
||||
|
||||
if (xdg_popup.wlr_xdg_popup.base.initial_commit) {
|
||||
handleReposition(&xdg_popup.reposition);
|
||||
}
|
||||
}
|
||||
|
||||
fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void {
|
||||
const xdg_popup = @fieldParentPtr(XdgPopup, "new_popup", listener);
|
||||
const xdg_popup: *XdgPopup = @fieldParentPtr("new_popup", listener);
|
||||
|
||||
XdgPopup.create(
|
||||
wlr_xdg_popup,
|
||||
@ -84,7 +93,7 @@ fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.Xdg
|
||||
}
|
||||
|
||||
fn handleReposition(listener: *wl.Listener(void)) void {
|
||||
const xdg_popup = @fieldParentPtr(XdgPopup, "reposition", listener);
|
||||
const xdg_popup: *XdgPopup = @fieldParentPtr("reposition", listener);
|
||||
|
||||
const output = switch (SceneNodeData.fromNode(&xdg_popup.root.node).?.data) {
|
||||
.view => |view| view.current.output orelse return,
|
||||
|
@ -62,12 +62,12 @@ configure_state: union(enum) {
|
||||
destroy: wl.Listener(void) = wl.Listener(void).init(handleDestroy),
|
||||
map: wl.Listener(void) = wl.Listener(void).init(handleMap),
|
||||
unmap: wl.Listener(void) = wl.Listener(void).init(handleUnmap),
|
||||
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
|
||||
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
|
||||
|
||||
// Listeners that are only active while the view is mapped
|
||||
ack_configure: wl.Listener(*wlr.XdgSurface.Configure) =
|
||||
wl.Listener(*wlr.XdgSurface.Configure).init(handleAckConfigure),
|
||||
commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit),
|
||||
request_fullscreen: wl.Listener(void) = wl.Listener(void).init(handleRequestFullscreen),
|
||||
request_move: wl.Listener(*wlr.XdgToplevel.event.Move) =
|
||||
wl.Listener(*wlr.XdgToplevel.event.Move).init(handleRequestMove),
|
||||
@ -100,15 +100,14 @@ pub fn create(wlr_toplevel: *wlr.XdgToplevel) error{OutOfMemory}!void {
|
||||
|
||||
toplevel.view = view;
|
||||
|
||||
wlr_toplevel.base.data = @intFromPtr(toplevel);
|
||||
wlr_toplevel.base.surface.data = @intFromPtr(&view.tree.node);
|
||||
wlr_toplevel.base.data = toplevel;
|
||||
wlr_toplevel.base.surface.data = &view.tree.node;
|
||||
|
||||
// Add listeners that are active over the toplevel's entire lifetime
|
||||
wlr_toplevel.base.events.destroy.add(&toplevel.destroy);
|
||||
wlr_toplevel.events.destroy.add(&toplevel.destroy);
|
||||
wlr_toplevel.base.surface.events.map.add(&toplevel.map);
|
||||
wlr_toplevel.base.surface.events.commit.add(&toplevel.commit);
|
||||
wlr_toplevel.base.events.new_popup.add(&toplevel.new_popup);
|
||||
|
||||
_ = wlr_toplevel.setWmCapabilities(.{ .fullscreen = true });
|
||||
}
|
||||
|
||||
/// Send a configure event, applying the inflight state of the view.
|
||||
@ -200,7 +199,7 @@ pub fn destroyPopups(toplevel: XdgToplevel) void {
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "destroy", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("destroy", listener);
|
||||
|
||||
// This can be be non-null here if the client commits a protocol error or
|
||||
// if it exits without destroying its wayland objects.
|
||||
@ -213,9 +212,11 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
toplevel.destroy.link.remove();
|
||||
toplevel.map.link.remove();
|
||||
toplevel.unmap.link.remove();
|
||||
toplevel.commit.link.remove();
|
||||
toplevel.new_popup.link.remove();
|
||||
|
||||
// The wlr_surface may outlive the wlr_xdg_surface so we must clean up the user data.
|
||||
toplevel.wlr_toplevel.base.surface.data = 0;
|
||||
// The wlr_surface may outlive the wlr_xdg_toplevel so we must clean up the user data.
|
||||
toplevel.wlr_toplevel.base.surface.data = null;
|
||||
|
||||
const view = toplevel.view;
|
||||
view.impl = .none;
|
||||
@ -223,19 +224,18 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleMap(listener: *wl.Listener(void)) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "map", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("map", listener);
|
||||
const view = toplevel.view;
|
||||
|
||||
// Add listeners that are only active while mapped
|
||||
toplevel.wlr_toplevel.base.events.ack_configure.add(&toplevel.ack_configure);
|
||||
toplevel.wlr_toplevel.base.surface.events.commit.add(&toplevel.commit);
|
||||
toplevel.wlr_toplevel.events.request_fullscreen.add(&toplevel.request_fullscreen);
|
||||
toplevel.wlr_toplevel.events.request_move.add(&toplevel.request_move);
|
||||
toplevel.wlr_toplevel.events.request_resize.add(&toplevel.request_resize);
|
||||
toplevel.wlr_toplevel.events.set_title.add(&toplevel.set_title);
|
||||
toplevel.wlr_toplevel.events.set_app_id.add(&toplevel.set_app_id);
|
||||
|
||||
toplevel.wlr_toplevel.base.getGeometry(&toplevel.geometry);
|
||||
toplevel.geometry = toplevel.wlr_toplevel.base.geometry;
|
||||
|
||||
view.pending.box = .{
|
||||
.x = 0,
|
||||
@ -266,11 +266,10 @@ fn handleMap(listener: *wl.Listener(void)) void {
|
||||
|
||||
/// Called when the surface is unmapped and will no longer be displayed.
|
||||
fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "unmap", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("unmap", listener);
|
||||
|
||||
// Remove listeners that are only active while mapped
|
||||
toplevel.ack_configure.link.remove();
|
||||
toplevel.commit.link.remove();
|
||||
toplevel.request_fullscreen.link.remove();
|
||||
toplevel.request_move.link.remove();
|
||||
toplevel.request_resize.link.remove();
|
||||
@ -281,7 +280,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleNewPopup(listener: *wl.Listener(*wlr.XdgPopup), wlr_xdg_popup: *wlr.XdgPopup) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "new_popup", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("new_popup", listener);
|
||||
|
||||
XdgPopup.create(wlr_xdg_popup, toplevel.view.popup_tree, toplevel.view.popup_tree) catch {
|
||||
wlr_xdg_popup.resource.postNoMemory();
|
||||
@ -293,7 +292,7 @@ fn handleAckConfigure(
|
||||
listener: *wl.Listener(*wlr.XdgSurface.Configure),
|
||||
acked_configure: *wlr.XdgSurface.Configure,
|
||||
) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "ack_configure", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("ack_configure", listener);
|
||||
switch (toplevel.configure_state) {
|
||||
.inflight => |serial| if (acked_configure.serial == serial) {
|
||||
toplevel.configure_state = .acked;
|
||||
@ -306,9 +305,26 @@ fn handleAckConfigure(
|
||||
}
|
||||
|
||||
fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "commit", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("commit", listener);
|
||||
const view = toplevel.view;
|
||||
|
||||
if (toplevel.wlr_toplevel.base.initial_commit) {
|
||||
_ = toplevel.wlr_toplevel.setWmCapabilities(.{ .fullscreen = true });
|
||||
|
||||
if (toplevel.decoration) |decoration| {
|
||||
const ssd = server.config.rules.ssd.match(toplevel.view) orelse
|
||||
(decoration.wlr_decoration.requested_mode != .client_side);
|
||||
_ = decoration.wlr_decoration.setMode(if (ssd) .server_side else .client_side);
|
||||
toplevel.view.pending.ssd = ssd;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!view.mapped) {
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
const state = &toplevel.wlr_toplevel.current;
|
||||
view.constraints = .{
|
||||
@ -322,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.wlr_toplevel.base.getGeometry(&toplevel.geometry);
|
||||
toplevel.geometry = toplevel.wlr_toplevel.base.geometry;
|
||||
|
||||
const size_changed = toplevel.geometry.width != old_geometry.width or
|
||||
toplevel.geometry.height != old_geometry.height;
|
||||
@ -365,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.wlr_toplevel.base.getGeometry(&toplevel.geometry);
|
||||
toplevel.geometry = toplevel.wlr_toplevel.base.geometry;
|
||||
|
||||
if (view.inflight.resizing) {
|
||||
view.resizeUpdatePosition(toplevel.geometry.width, toplevel.geometry.height);
|
||||
@ -395,7 +411,7 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
|
||||
/// Called when the client asks to be fullscreened. We always honor the request
|
||||
/// for now, perhaps it should be denied in some cases in the future.
|
||||
fn handleRequestFullscreen(listener: *wl.Listener(void)) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "request_fullscreen", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("request_fullscreen", listener);
|
||||
if (toplevel.view.pending.fullscreen != toplevel.wlr_toplevel.requested.fullscreen) {
|
||||
toplevel.view.pending.fullscreen = toplevel.wlr_toplevel.requested.fullscreen;
|
||||
server.root.applyPending();
|
||||
@ -406,8 +422,8 @@ fn handleRequestMove(
|
||||
listener: *wl.Listener(*wlr.XdgToplevel.event.Move),
|
||||
event: *wlr.XdgToplevel.event.Move,
|
||||
) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "request_move", listener);
|
||||
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("request_move", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(event.seat.seat.data));
|
||||
const view = toplevel.view;
|
||||
|
||||
if (view.pending.fullscreen) return;
|
||||
@ -429,8 +445,8 @@ fn handleRequestMove(
|
||||
}
|
||||
|
||||
fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), event: *wlr.XdgToplevel.event.Resize) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "request_resize", listener);
|
||||
const seat: *Seat = @ptrFromInt(event.seat.seat.data);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("request_resize", listener);
|
||||
const seat: *Seat = @alignCast(@ptrCast(event.seat.seat.data));
|
||||
const view = toplevel.view;
|
||||
|
||||
if (view.pending.fullscreen) return;
|
||||
@ -453,12 +469,12 @@ fn handleRequestResize(listener: *wl.Listener(*wlr.XdgToplevel.event.Resize), ev
|
||||
|
||||
/// Called when the client sets / updates its title
|
||||
fn handleSetTitle(listener: *wl.Listener(void)) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "set_title", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("set_title", listener);
|
||||
toplevel.view.notifyState();
|
||||
}
|
||||
|
||||
/// Called when the client sets / updates its app_id
|
||||
fn handleSetAppId(listener: *wl.Listener(void)) void {
|
||||
const toplevel = @fieldParentPtr(XdgToplevel, "set_app_id", listener);
|
||||
const toplevel: *XdgToplevel = @fieldParentPtr("set_app_id", listener);
|
||||
toplevel.view.notifyAppId();
|
||||
}
|
||||
|
@ -78,7 +78,7 @@ fn handleRequestConfigure(
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "destroy", listener);
|
||||
const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("destroy", listener);
|
||||
|
||||
override_redirect.request_configure.link.remove();
|
||||
override_redirect.destroy.link.remove();
|
||||
@ -90,21 +90,21 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleAssociate(listener: *wl.Listener(void)) void {
|
||||
const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "associate", listener);
|
||||
const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("associate", listener);
|
||||
|
||||
override_redirect.xwayland_surface.surface.?.events.map.add(&override_redirect.map);
|
||||
override_redirect.xwayland_surface.surface.?.events.unmap.add(&override_redirect.unmap);
|
||||
}
|
||||
|
||||
fn handleDissociate(listener: *wl.Listener(void)) void {
|
||||
const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "dissociate", listener);
|
||||
const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("dissociate", listener);
|
||||
|
||||
override_redirect.map.link.remove();
|
||||
override_redirect.unmap.link.remove();
|
||||
}
|
||||
|
||||
pub fn handleMap(listener: *wl.Listener(void)) void {
|
||||
const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "map", listener);
|
||||
const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("map", listener);
|
||||
|
||||
override_redirect.mapImpl() catch {
|
||||
log.err("out of memory", .{});
|
||||
@ -120,7 +120,7 @@ fn mapImpl(override_redirect: *XwaylandOverrideRedirect) error{OutOfMemory}!void
|
||||
.override_redirect = override_redirect,
|
||||
});
|
||||
|
||||
surface.data = @intFromPtr(&override_redirect.surface_tree.?.node);
|
||||
surface.data = &override_redirect.surface_tree.?.node;
|
||||
|
||||
override_redirect.surface_tree.?.node.setPosition(
|
||||
override_redirect.xwayland_surface.x,
|
||||
@ -155,11 +155,11 @@ pub fn focusIfDesired(override_redirect: *XwaylandOverrideRedirect) void {
|
||||
}
|
||||
|
||||
fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||
const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "unmap", listener);
|
||||
const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("unmap", listener);
|
||||
|
||||
override_redirect.set_geometry.link.remove();
|
||||
|
||||
override_redirect.xwayland_surface.surface.?.data = 0;
|
||||
override_redirect.xwayland_surface.surface.?.data = null;
|
||||
override_redirect.surface_tree.?.node.destroy();
|
||||
override_redirect.surface_tree = null;
|
||||
|
||||
@ -180,7 +180,7 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleSetGeometry(listener: *wl.Listener(void)) void {
|
||||
const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "set_geometry", listener);
|
||||
const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("set_geometry", listener);
|
||||
|
||||
override_redirect.surface_tree.?.node.setPosition(
|
||||
override_redirect.xwayland_surface.x,
|
||||
@ -189,7 +189,7 @@ fn handleSetGeometry(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void {
|
||||
const override_redirect = @fieldParentPtr(XwaylandOverrideRedirect, "set_override_redirect", listener);
|
||||
const override_redirect: *XwaylandOverrideRedirect = @fieldParentPtr("set_override_redirect", listener);
|
||||
const xwayland_surface = override_redirect.xwayland_surface;
|
||||
|
||||
log.debug("xwayland surface unset override redirect", .{});
|
||||
|
@ -106,10 +106,10 @@ pub fn configure(xwayland_view: XwaylandView) bool {
|
||||
}
|
||||
|
||||
xwayland_view.xwayland_surface.configure(
|
||||
@intCast(inflight.box.x + output_box.x),
|
||||
@intCast(inflight.box.y + output_box.y),
|
||||
@intCast(inflight.box.width),
|
||||
@intCast(inflight.box.height),
|
||||
math.lossyCast(i16, inflight.box.x + output_box.x),
|
||||
math.lossyCast(i16, inflight.box.y + output_box.y),
|
||||
math.lossyCast(u16, inflight.box.width),
|
||||
math.lossyCast(u16, inflight.box.height),
|
||||
);
|
||||
|
||||
xwayland_view.setActivated(inflight.focus != 0);
|
||||
@ -131,7 +131,7 @@ fn setActivated(xwayland_view: XwaylandView, activated: bool) void {
|
||||
}
|
||||
|
||||
fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "destroy", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("destroy", listener);
|
||||
|
||||
// Remove listeners that are active for the entire lifetime of the view
|
||||
xwayland_view.destroy.link.remove();
|
||||
@ -146,25 +146,25 @@ fn handleDestroy(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleAssociate(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "associate", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("associate", listener);
|
||||
|
||||
xwayland_view.xwayland_surface.surface.?.events.map.add(&xwayland_view.map);
|
||||
xwayland_view.xwayland_surface.surface.?.events.unmap.add(&xwayland_view.unmap);
|
||||
}
|
||||
|
||||
fn handleDissociate(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "dissociate", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("dissociate", listener);
|
||||
xwayland_view.map.link.remove();
|
||||
xwayland_view.unmap.link.remove();
|
||||
}
|
||||
|
||||
pub fn handleMap(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "map", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("map", listener);
|
||||
const view = xwayland_view.view;
|
||||
|
||||
const xwayland_surface = xwayland_view.xwayland_surface;
|
||||
const surface = xwayland_surface.surface.?;
|
||||
surface.data = @intFromPtr(&view.tree.node);
|
||||
surface.data = &view.tree.node;
|
||||
|
||||
// Add listeners that are only active while mapped
|
||||
xwayland_surface.events.set_title.add(&xwayland_view.set_title);
|
||||
@ -213,13 +213,14 @@ pub fn handleMap(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleUnmap(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "unmap", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("unmap", listener);
|
||||
|
||||
xwayland_view.xwayland_surface.surface.?.data = 0;
|
||||
xwayland_view.xwayland_surface.surface.?.data = null;
|
||||
|
||||
// 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();
|
||||
|
||||
@ -235,7 +236,7 @@ fn handleRequestConfigure(
|
||||
listener: *wl.Listener(*wlr.XwaylandSurface.event.Configure),
|
||||
event: *wlr.XwaylandSurface.event.Configure,
|
||||
) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "request_configure", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("request_configure", listener);
|
||||
|
||||
// If unmapped, let the client do whatever it wants
|
||||
if (xwayland_view.xwayland_surface.surface == null or
|
||||
@ -254,7 +255,7 @@ fn handleRequestConfigure(
|
||||
}
|
||||
|
||||
fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "set_override_redirect", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("set_override_redirect", listener);
|
||||
const xwayland_surface = xwayland_view.xwayland_surface;
|
||||
|
||||
log.debug("xwayland surface set override redirect", .{});
|
||||
@ -276,17 +277,17 @@ fn handleSetOverrideRedirect(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleSetTitle(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "set_title", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("set_title", listener);
|
||||
xwayland_view.view.notifyState();
|
||||
}
|
||||
|
||||
fn handleSetClass(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "set_class", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("set_class", listener);
|
||||
xwayland_view.view.notifyAppId();
|
||||
}
|
||||
|
||||
fn handleSetDecorations(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "set_decorations", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("set_decorations", listener);
|
||||
const view = xwayland_view.view;
|
||||
|
||||
const ssd = server.config.rules.ssd.match(view) orelse
|
||||
@ -299,7 +300,7 @@ fn handleSetDecorations(listener: *wl.Listener(void)) void {
|
||||
}
|
||||
|
||||
fn handleRequestFullscreen(listener: *wl.Listener(void)) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "request_fullscreen", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("request_fullscreen", listener);
|
||||
if (xwayland_view.view.pending.fullscreen != xwayland_view.xwayland_surface.fullscreen) {
|
||||
xwayland_view.view.pending.fullscreen = xwayland_view.xwayland_surface.fullscreen;
|
||||
server.root.applyPending();
|
||||
@ -314,6 +315,6 @@ fn handleRequestMinimize(
|
||||
listener: *wl.Listener(*wlr.XwaylandSurface.event.Minimize),
|
||||
event: *wlr.XwaylandSurface.event.Minimize,
|
||||
) void {
|
||||
const xwayland_view = @fieldParentPtr(XwaylandView, "request_minimize", listener);
|
||||
const xwayland_view: *XwaylandView = @fieldParentPtr("request_minimize", listener);
|
||||
xwayland_view.xwayland_surface.setMinimized(event.minimize);
|
||||
}
|
||||
|
@ -36,10 +36,12 @@ pub const Orientation = enum {
|
||||
vertical,
|
||||
};
|
||||
|
||||
// zig fmt: off
|
||||
const command_impls = std.ComptimeStringMap(
|
||||
const command_impls = std.StaticStringMap(
|
||||
*const fn (*Seat, []const [:0]const u8, *?[]const u8) Error!void,
|
||||
).initComptime(
|
||||
.{
|
||||
// zig fmt: off
|
||||
.{ "allow-tearing", @import("command/config.zig").allowTearing },
|
||||
.{ "attach-mode", @import("command/attach_mode.zig").defaultAttachMode },
|
||||
.{ "background-color", @import("command/config.zig").backgroundColor },
|
||||
.{ "border-color-focused", @import("command/config.zig").borderColorFocused },
|
||||
@ -96,9 +98,9 @@ const command_impls = std.ComptimeStringMap(
|
||||
.{ "unmap-switch", @import("command/map.zig").unmapSwitch },
|
||||
.{ "xcursor-theme", @import("command/xcursor_theme.zig").xcursorTheme },
|
||||
.{ "zoom", @import("command/zoom.zig").zoom },
|
||||
// zig fmt: on
|
||||
},
|
||||
);
|
||||
// zig fmt: on
|
||||
|
||||
pub const Error = error{
|
||||
NoCommand,
|
||||
|
@ -24,6 +24,20 @@ const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
const Config = @import("../Config.zig");
|
||||
|
||||
pub fn allowTearing(
|
||||
_: *Seat,
|
||||
args: []const [:0]const u8,
|
||||
_: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
|
||||
const arg = std.meta.stringToEnum(enum { enabled, disabled }, args[1]) orelse
|
||||
return Error.UnknownOption;
|
||||
|
||||
server.config.allow_tearing = arg == .enabled;
|
||||
}
|
||||
|
||||
pub fn borderWidth(
|
||||
_: *Seat,
|
||||
args: []const [:0]const u8,
|
||||
|
@ -24,77 +24,13 @@ const util = @import("../util.zig");
|
||||
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
const KeyboardGroup = @import("../KeyboardGroup.zig");
|
||||
|
||||
pub fn keyboardGroupCreate(
|
||||
seat: *Seat,
|
||||
args: []const [:0]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
pub const keyboardGroupCreate = keyboardGroupDeprecated;
|
||||
pub const keyboardGroupDestroy = keyboardGroupDeprecated;
|
||||
pub const keyboardGroupAdd = keyboardGroupDeprecated;
|
||||
pub const keyboardGroupRemove = keyboardGroupDeprecated;
|
||||
|
||||
if (keyboardGroupFromName(seat, args[1]) != null) {
|
||||
const msg = try util.gpa.dupe(u8, "error: failed to create keybaord group: group of same name already exists\n");
|
||||
out.* = msg;
|
||||
return;
|
||||
}
|
||||
|
||||
try KeyboardGroup.create(seat, args[1]);
|
||||
}
|
||||
|
||||
pub fn keyboardGroupDestroy(
|
||||
seat: *Seat,
|
||||
args: []const [:0]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 2) return Error.NotEnoughArguments;
|
||||
if (args.len > 2) return Error.TooManyArguments;
|
||||
const group = keyboardGroupFromName(seat, args[1]) orelse {
|
||||
const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n");
|
||||
out.* = msg;
|
||||
return;
|
||||
};
|
||||
group.destroy();
|
||||
}
|
||||
|
||||
pub fn keyboardGroupAdd(
|
||||
seat: *Seat,
|
||||
args: []const [:0]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 3) return Error.NotEnoughArguments;
|
||||
if (args.len > 3) return Error.TooManyArguments;
|
||||
|
||||
const group = keyboardGroupFromName(seat, args[1]) orelse {
|
||||
const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n");
|
||||
out.* = msg;
|
||||
return;
|
||||
};
|
||||
try globber.validate(args[2]);
|
||||
try group.addIdentifier(args[2]);
|
||||
}
|
||||
|
||||
pub fn keyboardGroupRemove(
|
||||
seat: *Seat,
|
||||
args: []const [:0]const u8,
|
||||
out: *?[]const u8,
|
||||
) Error!void {
|
||||
if (args.len < 3) return Error.NotEnoughArguments;
|
||||
if (args.len > 3) return Error.TooManyArguments;
|
||||
|
||||
const group = keyboardGroupFromName(seat, args[1]) orelse {
|
||||
const msg = try util.gpa.dupe(u8, "error: no keyboard group with that name exists\n");
|
||||
out.* = msg;
|
||||
return;
|
||||
};
|
||||
try group.removeIdentifier(args[2]);
|
||||
}
|
||||
|
||||
fn keyboardGroupFromName(seat: *Seat, name: []const u8) ?*KeyboardGroup {
|
||||
var it = seat.keyboard_groups.first;
|
||||
while (it) |node| : (it = node.next) {
|
||||
if (mem.eql(u8, node.data.name, name)) return &node.data;
|
||||
}
|
||||
return null;
|
||||
fn keyboardGroupDeprecated(_: *Seat, _: []const [:0]const u8, out: *?[]const u8) Error!void {
|
||||
out.* = try util.gpa.dupe(u8, "warning: explicit keyboard groups are deprecated, " ++
|
||||
"all keyboards are now automatically added to a single group\n");
|
||||
}
|
||||
|
@ -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.split(u8, modifiers_str, "+");
|
||||
var it = mem.splitScalar(u8, modifiers_str, '+');
|
||||
var modifiers = wlr.Keyboard.ModifierMask{};
|
||||
outer: while (it.next()) |mod_name| {
|
||||
if (mem.eql(u8, mod_name, "None")) continue;
|
||||
|
@ -109,7 +109,7 @@ fn getOutput(seat: *Seat, str: []const u8) !?*Output {
|
||||
.previous => link.prev.?,
|
||||
};
|
||||
}
|
||||
return @fieldParentPtr(Output, "active_link", link);
|
||||
return @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 @as(*Output, @ptrFromInt(wlr_output.data));
|
||||
return @alignCast(@ptrCast(wlr_output.data));
|
||||
} else {
|
||||
// Check if an output matches by name
|
||||
var it = server.root.active_outputs.iterator(.forward);
|
||||
|
@ -26,6 +26,7 @@ const util = @import("../util.zig");
|
||||
const Error = @import("../command.zig").Error;
|
||||
const Seat = @import("../Seat.zig");
|
||||
const View = @import("../View.zig");
|
||||
const RuleGlobs = @import("../rule_list.zig").RuleGlobs;
|
||||
|
||||
const Action = enum {
|
||||
float,
|
||||
@ -38,6 +39,8 @@ const Action = enum {
|
||||
dimensions,
|
||||
fullscreen,
|
||||
@"no-fullscreen",
|
||||
tearing,
|
||||
@"no-tearing",
|
||||
};
|
||||
|
||||
pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void {
|
||||
@ -53,7 +56,7 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
|
||||
const action = std.meta.stringToEnum(Action, result.args[0]) orelse return Error.UnknownOption;
|
||||
|
||||
const positional_arguments_count: u8 = switch (action) {
|
||||
.float, .@"no-float", .ssd, .csd, .fullscreen, .@"no-fullscreen" => 1,
|
||||
.float, .@"no-float", .ssd, .csd, .fullscreen, .@"no-fullscreen", .tearing, .@"no-tearing" => 1,
|
||||
.tags, .output => 2,
|
||||
.position, .dimensions => 3,
|
||||
};
|
||||
@ -83,6 +86,14 @@ pub fn ruleAdd(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
|
||||
apply_ssd_rules();
|
||||
server.root.applyPending();
|
||||
},
|
||||
.tearing, .@"no-tearing" => {
|
||||
try server.config.rules.tearing.add(.{
|
||||
.app_id_glob = app_id_glob,
|
||||
.title_glob = title_glob,
|
||||
.value = (action == .tearing),
|
||||
});
|
||||
apply_tearing_rules();
|
||||
},
|
||||
.tags => {
|
||||
const tags = try fmt.parseInt(u32, result.args[1], 10);
|
||||
try server.config.rules.tags.add(.{
|
||||
@ -147,7 +158,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 = .{
|
||||
const rule: RuleGlobs = .{
|
||||
.app_id_glob = result.flags.@"app-id" orelse "*",
|
||||
.title_glob = result.flags.title orelse "*",
|
||||
};
|
||||
@ -177,6 +188,10 @@ pub fn ruleDel(_: *Seat, args: []const [:0]const u8, _: *?[]const u8) Error!void
|
||||
.fullscreen, .@"no-fullscreen" => {
|
||||
_ = server.config.rules.fullscreen.del(rule);
|
||||
},
|
||||
.tearing, .@"no-tearing" => {
|
||||
_ = server.config.rules.tearing.del(rule);
|
||||
apply_tearing_rules();
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
@ -191,6 +206,17 @@ fn apply_ssd_rules() void {
|
||||
}
|
||||
}
|
||||
|
||||
fn apply_tearing_rules() void {
|
||||
var it = server.root.views.iterator(.forward);
|
||||
while (it.next()) |view| {
|
||||
if (view.destroying) continue;
|
||||
|
||||
if (server.config.rules.tearing.match(view)) |tearing| {
|
||||
view.tearing_mode = if (tearing) .tearing else .no_tearing;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!void {
|
||||
if (args.len < 2) return error.NotEnoughArguments;
|
||||
if (args.len > 2) return error.TooManyArguments;
|
||||
@ -203,6 +229,7 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
|
||||
position,
|
||||
dimensions,
|
||||
fullscreen,
|
||||
tearing,
|
||||
}, args[1]) orelse return Error.UnknownOption;
|
||||
const max_glob_len = switch (rule_list) {
|
||||
inline else => |list| @field(server.config.rules, @tagName(list)).getMaxGlobLen(),
|
||||
@ -218,12 +245,13 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
|
||||
try writer.writeAll("action\n");
|
||||
|
||||
switch (rule_list) {
|
||||
inline .float, .ssd, .output, .fullscreen => |list| {
|
||||
inline .float, .ssd, .output, .fullscreen, .tearing => |list| {
|
||||
const rules = switch (list) {
|
||||
.float => server.config.rules.float.rules.items,
|
||||
.ssd => server.config.rules.ssd.rules.items,
|
||||
.output => server.config.rules.output.rules.items,
|
||||
.fullscreen => server.config.rules.fullscreen.rules.items,
|
||||
.tearing => server.config.rules.tearing.rules.items,
|
||||
else => unreachable,
|
||||
};
|
||||
for (rules) |rule| {
|
||||
@ -234,6 +262,7 @@ pub fn listRules(_: *Seat, args: []const [:0]const u8, out: *?[]const u8) Error!
|
||||
.ssd => if (rule.value) "ssd" else "csd",
|
||||
.output => rule.value,
|
||||
.fullscreen => if (rule.value) "fullscreen" else "no-fullscreen",
|
||||
.tearing => if (rule.value) "tearing" else "no-tearing",
|
||||
else => unreachable,
|
||||
}});
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
|
||||
const c = @import("../c.zig");
|
||||
const util = @import("../util.zig");
|
||||
@ -35,23 +35,26 @@ pub fn spawn(
|
||||
|
||||
const child_args = [_:null]?[*:0]const u8{ "/bin/sh", "-c", args[1], null };
|
||||
|
||||
const pid = os.fork() catch {
|
||||
const pid = posix.fork() catch {
|
||||
out.* = try std.fmt.allocPrint(util.gpa, "fork/execve failed", .{});
|
||||
return Error.Other;
|
||||
};
|
||||
|
||||
if (pid == 0) {
|
||||
process.cleanupChild();
|
||||
const pid2 = os.fork() catch c._exit(1);
|
||||
if (pid2 == 0) os.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1);
|
||||
|
||||
const pid2 = posix.fork() catch c._exit(1);
|
||||
if (pid2 == 0) {
|
||||
posix.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1);
|
||||
}
|
||||
|
||||
c._exit(0);
|
||||
}
|
||||
|
||||
// Wait the intermediate child.
|
||||
const ret = os.waitpid(pid, 0);
|
||||
if (!os.W.IFEXITED(ret.status) or
|
||||
(os.W.IFEXITED(ret.status) and os.W.EXITSTATUS(ret.status) != 0))
|
||||
const ret = posix.waitpid(pid, 0);
|
||||
if (!posix.W.IFEXITED(ret.status) or
|
||||
(posix.W.IFEXITED(ret.status) and posix.W.EXITSTATUS(ret.status) != 0))
|
||||
{
|
||||
out.* = try std.fmt.allocPrint(util.gpa, "fork/execve failed", .{});
|
||||
return Error.Other;
|
||||
|
@ -20,7 +20,7 @@ const mem = std.mem;
|
||||
const fs = std.fs;
|
||||
const io = std.io;
|
||||
const log = std.log;
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
const builtin = @import("builtin");
|
||||
const wlr = @import("wlroots");
|
||||
const flags = @import("flags");
|
||||
@ -31,12 +31,6 @@ const process = @import("process.zig");
|
||||
|
||||
const Server = @import("Server.zig");
|
||||
|
||||
comptime {
|
||||
if (wlr.version.major != 0 or wlr.version.minor != 17 or wlr.version.micro < 2) {
|
||||
@compileError("river requires at least wlroots version 0.17.2 due to bugs in wlroots 0.17.0/0.17.1");
|
||||
}
|
||||
}
|
||||
|
||||
const usage: []const u8 =
|
||||
\\usage: river [options]
|
||||
\\
|
||||
@ -57,23 +51,23 @@ pub fn main() anyerror!void {
|
||||
.{ .name = "c", .kind = .arg },
|
||||
.{ .name = "log-level", .kind = .arg },
|
||||
.{ .name = "no-xwayland", .kind = .boolean },
|
||||
}).parse(os.argv[1..]) catch {
|
||||
}).parse(std.os.argv[1..]) catch {
|
||||
try io.getStdErr().writeAll(usage);
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
};
|
||||
if (result.flags.h) {
|
||||
try io.getStdOut().writeAll(usage);
|
||||
os.exit(0);
|
||||
posix.exit(0);
|
||||
}
|
||||
if (result.args.len != 0) {
|
||||
log.err("unknown option '{s}'", .{result.args[0]});
|
||||
try io.getStdErr().writeAll(usage);
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
}
|
||||
|
||||
if (result.flags.version) {
|
||||
try io.getStdOut().writeAll(build_options.version ++ "\n");
|
||||
os.exit(0);
|
||||
posix.exit(0);
|
||||
}
|
||||
if (result.flags.@"log-level") |level| {
|
||||
if (mem.eql(u8, level, "error")) {
|
||||
@ -87,10 +81,10 @@ pub fn main() anyerror!void {
|
||||
} else {
|
||||
log.err("invalid log level '{s}'", .{level});
|
||||
try io.getStdErr().writeAll(usage);
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
}
|
||||
}
|
||||
const enable_xwayland = !result.flags.@"no-xwayland";
|
||||
const runtime_xwayland = !result.flags.@"no-xwayland";
|
||||
const startup_command = blk: {
|
||||
if (result.flags.c) |command| {
|
||||
break :blk try util.gpa.dupeZ(u8, command);
|
||||
@ -101,17 +95,25 @@ pub fn main() anyerror!void {
|
||||
|
||||
log.info("river version {s}, initializing server", .{build_options.version});
|
||||
|
||||
process.setup();
|
||||
|
||||
river_init_wlroots_log(switch (runtime_log_level) {
|
||||
.debug => .debug,
|
||||
.info => .info,
|
||||
.warn, .err => .err,
|
||||
});
|
||||
|
||||
try server.init(enable_xwayland);
|
||||
try server.init(runtime_xwayland);
|
||||
defer server.deinit();
|
||||
|
||||
// wlroots starts the Xwayland process from an idle event source, the reasoning being that
|
||||
// this gives the compositor time to set up event listeners before Xwayland is actually
|
||||
// started. We want Xwayland to be started by wlroots before we modify our rlimits in
|
||||
// process.setup() since wlroots does not offer a way for us to reset the rlimit post-fork.
|
||||
if (build_options.xwayland and runtime_xwayland) {
|
||||
server.wl_server.getEventLoop().dispatchIdle();
|
||||
}
|
||||
|
||||
process.setup();
|
||||
|
||||
try server.start();
|
||||
|
||||
// Run the child in a new process group so that we can send SIGTERM to all
|
||||
@ -119,16 +121,16 @@ pub fn main() anyerror!void {
|
||||
const child_pgid = if (startup_command) |cmd| blk: {
|
||||
log.info("running init executable '{s}'", .{cmd});
|
||||
const child_args = [_:null]?[*:0]const u8{ "/bin/sh", "-c", cmd, null };
|
||||
const pid = try os.fork();
|
||||
const pid = try posix.fork();
|
||||
if (pid == 0) {
|
||||
process.cleanupChild();
|
||||
os.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1);
|
||||
posix.execveZ("/bin/sh", &child_args, std.c.environ) catch c._exit(1);
|
||||
}
|
||||
util.gpa.free(cmd);
|
||||
// Since the child has called setsid, the pid is the pgid
|
||||
break :blk pid;
|
||||
} else null;
|
||||
defer if (child_pgid) |pgid| os.kill(-pgid, os.SIG.TERM) catch |err| {
|
||||
defer if (child_pgid) |pgid| posix.kill(-pgid, posix.SIG.TERM) catch |err| {
|
||||
log.err("failed to kill init process group: {s}", .{@errorName(err)});
|
||||
};
|
||||
|
||||
@ -141,20 +143,20 @@ pub fn main() anyerror!void {
|
||||
|
||||
fn defaultInitPath() !?[:0]const u8 {
|
||||
const path = blk: {
|
||||
if (os.getenv("XDG_CONFIG_HOME")) |xdg_config_home| {
|
||||
if (posix.getenv("XDG_CONFIG_HOME")) |xdg_config_home| {
|
||||
break :blk try fs.path.joinZ(util.gpa, &[_][]const u8{ xdg_config_home, "river/init" });
|
||||
} else if (os.getenv("HOME")) |home| {
|
||||
} else if (posix.getenv("HOME")) |home| {
|
||||
break :blk try fs.path.joinZ(util.gpa, &[_][]const u8{ home, ".config/river/init" });
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
os.accessZ(path, os.X_OK) catch |err| {
|
||||
posix.accessZ(path, posix.X_OK) catch |err| {
|
||||
if (err == error.PermissionDenied) {
|
||||
if (os.accessZ(path, os.R_OK)) {
|
||||
if (posix.accessZ(path, posix.R_OK)) {
|
||||
log.err("failed to run init executable {s}: the file is not executable", .{path});
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
} else |_| {}
|
||||
}
|
||||
log.err("failed to run init executable {s}: {s}", .{ path, @errorName(err) });
|
||||
@ -171,24 +173,25 @@ var runtime_log_level: log.Level = switch (builtin.mode) {
|
||||
.ReleaseSafe, .ReleaseFast, .ReleaseSmall => .info,
|
||||
};
|
||||
|
||||
pub const std_options = struct {
|
||||
/// Tell std.log to leave all log level filtering to us.
|
||||
pub const log_level: log.Level = .debug;
|
||||
pub const std_options: std.Options = .{
|
||||
// Tell std.log to leave all log level filtering to us.
|
||||
.log_level = .debug,
|
||||
.logFn = logFn,
|
||||
};
|
||||
|
||||
pub fn logFn(
|
||||
pub fn logFn(
|
||||
comptime level: log.Level,
|
||||
comptime scope: @TypeOf(.EnumLiteral),
|
||||
comptime format: []const u8,
|
||||
args: anytype,
|
||||
) void {
|
||||
) void {
|
||||
if (@intFromEnum(level) > @intFromEnum(runtime_log_level)) return;
|
||||
|
||||
const scope_prefix = if (scope == .default) ": " else "(" ++ @tagName(scope) ++ "): ";
|
||||
|
||||
const stderr = io.getStdErr().writer();
|
||||
stderr.print(level.asText() ++ scope_prefix ++ format ++ "\n", args) catch {};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
/// See wlroots_log_wrapper.c
|
||||
extern fn river_init_wlroots_log(importance: wlr.log.Importance) void;
|
||||
|
@ -15,21 +15,21 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
const std = @import("std");
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
|
||||
const c = @import("c.zig");
|
||||
|
||||
var original_rlimit: ?os.rlimit = null;
|
||||
var original_rlimit: ?posix.rlimit = null;
|
||||
|
||||
pub fn setup() void {
|
||||
// Ignore SIGPIPE so we don't get killed when writing to a socket that
|
||||
// has had its read end closed by another process.
|
||||
const sig_ign = os.Sigaction{
|
||||
.handler = .{ .handler = os.SIG.IGN },
|
||||
.mask = os.empty_sigset,
|
||||
const sig_ign = posix.Sigaction{
|
||||
.handler = .{ .handler = posix.SIG.IGN },
|
||||
.mask = posix.empty_sigset,
|
||||
.flags = 0,
|
||||
};
|
||||
os.sigaction(os.SIG.PIPE, &sig_ign, null) catch unreachable;
|
||||
posix.sigaction(posix.SIG.PIPE, &sig_ign, null);
|
||||
|
||||
// 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
|
||||
@ -41,13 +41,13 @@ pub fn setup() void {
|
||||
// to catch any fd leaks. Therefore, don't use some crazy high limit that
|
||||
// can never be reached before the system runs out of memory. This can be
|
||||
// raised further if anyone reaches it in practice.
|
||||
if (os.getrlimit(.NOFILE)) |original| {
|
||||
if (posix.getrlimit(.NOFILE)) |original| {
|
||||
original_rlimit = original;
|
||||
const new: os.rlimit = .{
|
||||
const new: posix.rlimit = .{
|
||||
.cur = @min(4096, original.max),
|
||||
.max = original.max,
|
||||
};
|
||||
if (os.setrlimit(.NOFILE, new)) {
|
||||
if (posix.setrlimit(.NOFILE, new)) {
|
||||
std.log.info("raised file descriptor limit of the river process to {d}", .{new.cur});
|
||||
} else |_| {
|
||||
std.log.err("setrlimit failed, using system default file descriptor limit of {d}", .{
|
||||
@ -61,17 +61,17 @@ pub fn setup() void {
|
||||
|
||||
pub fn cleanupChild() void {
|
||||
if (c.setsid() < 0) unreachable;
|
||||
if (os.system.sigprocmask(os.SIG.SETMASK, &os.empty_sigset, null) < 0) unreachable;
|
||||
if (posix.system.sigprocmask(posix.SIG.SETMASK, &posix.empty_sigset, null) < 0) unreachable;
|
||||
|
||||
const sig_dfl = os.Sigaction{
|
||||
.handler = .{ .handler = os.SIG.DFL },
|
||||
.mask = os.empty_sigset,
|
||||
const sig_dfl = posix.Sigaction{
|
||||
.handler = .{ .handler = posix.SIG.DFL },
|
||||
.mask = posix.empty_sigset,
|
||||
.flags = 0,
|
||||
};
|
||||
os.sigaction(os.SIG.PIPE, &sig_dfl, null) catch unreachable;
|
||||
posix.sigaction(posix.SIG.PIPE, &sig_dfl, null);
|
||||
|
||||
if (original_rlimit) |original| {
|
||||
os.setrlimit(.NOFILE, original) catch {
|
||||
posix.setrlimit(.NOFILE, original) catch {
|
||||
std.log.err("failed to restore original file descriptor limit for " ++
|
||||
"child process, setrlimit failed", .{});
|
||||
};
|
||||
|
@ -23,6 +23,11 @@ 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,
|
||||
@ -83,7 +88,7 @@ pub fn RuleList(comptime T: type) type {
|
||||
});
|
||||
}
|
||||
|
||||
pub fn del(list: *List, rule: struct { app_id_glob: []const u8, title_glob: []const u8 }) ?T {
|
||||
pub fn del(list: *List, rule: RuleGlobs) ?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))
|
||||
|
@ -17,7 +17,7 @@
|
||||
const std = @import("std");
|
||||
const mem = std.mem;
|
||||
const io = std.io;
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
const assert = std.debug.assert;
|
||||
const builtin = @import("builtin");
|
||||
|
||||
@ -57,7 +57,7 @@ pub fn main() !void {
|
||||
, .{}),
|
||||
error.ConnectFailed => {
|
||||
std.log.err("Unable to connect to the Wayland server.", .{});
|
||||
if (os.getenvZ("WAYLAND_DISPLAY") == null) {
|
||||
if (posix.getenvZ("WAYLAND_DISPLAY") == null) {
|
||||
fatal("WAYLAND_DISPLAY is not set.", .{});
|
||||
} else {
|
||||
fatal("Does WAYLAND_DISPLAY contain the socket name of a running server?", .{});
|
||||
@ -72,17 +72,17 @@ fn _main() !void {
|
||||
const result = flags.parser([*:0]const u8, &.{
|
||||
.{ .name = "h", .kind = .boolean },
|
||||
.{ .name = "version", .kind = .boolean },
|
||||
}).parse(os.argv[1..]) catch {
|
||||
}).parse(std.os.argv[1..]) catch {
|
||||
try io.getStdErr().writeAll(usage);
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
};
|
||||
if (result.flags.h) {
|
||||
try io.getStdOut().writeAll(usage);
|
||||
os.exit(0);
|
||||
posix.exit(0);
|
||||
}
|
||||
if (result.flags.version) {
|
||||
try io.getStdOut().writeAll(@import("build_options").version ++ "\n");
|
||||
os.exit(0);
|
||||
posix.exit(0);
|
||||
}
|
||||
|
||||
const display = try wl.Display.connect(null);
|
||||
@ -110,10 +110,10 @@ fn _main() !void {
|
||||
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, globals: *Globals) void {
|
||||
switch (event) {
|
||||
.global => |global| {
|
||||
if (mem.orderZ(u8, global.interface, wl.Seat.getInterface().name) == .eq) {
|
||||
if (mem.orderZ(u8, global.interface, wl.Seat.interface.name) == .eq) {
|
||||
assert(globals.seat == null); // TODO: support multiple seats
|
||||
globals.seat = registry.bind(global.name, wl.Seat, 1) catch @panic("out of memory");
|
||||
} else if (mem.orderZ(u8, global.interface, zriver.ControlV1.getInterface().name) == .eq) {
|
||||
} else if (mem.orderZ(u8, global.interface, zriver.ControlV1.interface.name) == .eq) {
|
||||
globals.control = registry.bind(global.name, zriver.ControlV1, 1) catch @panic("out of memory");
|
||||
}
|
||||
},
|
||||
@ -128,14 +128,14 @@ fn callbackListener(_: *zriver.CommandCallbackV1, event: zriver.CommandCallbackV
|
||||
const stdout = io.getStdOut().writer();
|
||||
stdout.print("{s}\n", .{success.output}) catch @panic("failed to write to stdout");
|
||||
}
|
||||
os.exit(0);
|
||||
posix.exit(0);
|
||||
},
|
||||
.failure => |failure| {
|
||||
// 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", .{});
|
||||
io.getStdErr().writeAll(usage) catch {};
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
}
|
||||
fatal("{s}", .{failure.failure_message});
|
||||
},
|
||||
@ -144,5 +144,5 @@ fn callbackListener(_: *zriver.CommandCallbackV1, event: zriver.CommandCallbackV
|
||||
|
||||
fn fatal(comptime format: []const u8, args: anytype) noreturn {
|
||||
std.log.err(format, args);
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ const std = @import("std");
|
||||
const fmt = std.fmt;
|
||||
const mem = std.mem;
|
||||
const math = std.math;
|
||||
const os = std.os;
|
||||
const posix = std.posix;
|
||||
const assert = std.debug.assert;
|
||||
|
||||
const wayland = @import("wayland");
|
||||
@ -91,12 +91,12 @@ const gpa = std.heap.c_allocator;
|
||||
const Context = struct {
|
||||
initialized: bool = false,
|
||||
layout_manager: ?*river.LayoutManagerV3 = null,
|
||||
outputs: std.TailQueue(Output) = .{},
|
||||
outputs: std.DoublyLinkedList(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();
|
||||
const node = try gpa.create(std.TailQueue(Output).Node);
|
||||
const node = try gpa.create(std.DoublyLinkedList(Output).Node);
|
||||
errdefer gpa.destroy(node);
|
||||
try node.data.init(context, wl_output, name);
|
||||
context.outputs.append(node);
|
||||
@ -140,7 +140,7 @@ const Output = struct {
|
||||
.namespace_in_use => fatal("namespace 'rivertile' already in use.", .{}),
|
||||
|
||||
.user_command => |ev| {
|
||||
var it = mem.tokenize(u8, mem.span(ev.command), " ");
|
||||
var it = mem.tokenizeScalar(u8, mem.span(ev.command), ' ');
|
||||
const raw_cmd = it.next() orelse {
|
||||
std.log.err("not enough arguments", .{});
|
||||
return;
|
||||
@ -311,19 +311,19 @@ pub fn main() !void {
|
||||
.{ .name = "main-location", .kind = .arg },
|
||||
.{ .name = "main-count", .kind = .arg },
|
||||
.{ .name = "main-ratio", .kind = .arg },
|
||||
}).parse(os.argv[1..]) catch {
|
||||
}).parse(std.os.argv[1..]) catch {
|
||||
try std.io.getStdErr().writeAll(usage);
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
};
|
||||
if (result.flags.h) {
|
||||
try std.io.getStdOut().writeAll(usage);
|
||||
os.exit(0);
|
||||
posix.exit(0);
|
||||
}
|
||||
if (result.args.len != 0) fatalPrintUsage("unknown option '{s}'", .{result.args[0]});
|
||||
|
||||
if (result.flags.version) {
|
||||
try std.io.getStdOut().writeAll(@import("build_options").version ++ "\n");
|
||||
os.exit(0);
|
||||
posix.exit(0);
|
||||
}
|
||||
if (result.flags.@"view-padding") |raw| {
|
||||
view_padding = fmt.parseUnsigned(u31, raw, 10) catch
|
||||
@ -352,7 +352,7 @@ pub fn main() !void {
|
||||
|
||||
const display = wl.Display.connect(null) catch {
|
||||
std.debug.print("Unable to connect to Wayland server.\n", .{});
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
};
|
||||
defer display.disconnect();
|
||||
|
||||
@ -382,9 +382,9 @@ pub fn main() !void {
|
||||
fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *Context) void {
|
||||
switch (event) {
|
||||
.global => |global| {
|
||||
if (mem.orderZ(u8, global.interface, river.LayoutManagerV3.getInterface().name) == .eq) {
|
||||
if (mem.orderZ(u8, global.interface, river.LayoutManagerV3.interface.name) == .eq) {
|
||||
context.layout_manager = registry.bind(global.name, river.LayoutManagerV3, 1) catch return;
|
||||
} else if (mem.orderZ(u8, global.interface, wl.Output.getInterface().name) == .eq) {
|
||||
} else if (mem.orderZ(u8, global.interface, wl.Output.interface.name) == .eq) {
|
||||
context.addOutput(registry, global.name) catch |err| fatal("failed to bind output: {}", .{err});
|
||||
}
|
||||
},
|
||||
@ -405,13 +405,13 @@ fn registryListener(registry: *wl.Registry, event: wl.Registry.Event, context: *
|
||||
|
||||
fn fatal(comptime format: []const u8, args: anytype) noreturn {
|
||||
std.log.err(format, args);
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
}
|
||||
|
||||
fn fatalPrintUsage(comptime format: []const u8, args: anytype) noreturn {
|
||||
std.log.err(format, args);
|
||||
std.io.getStdErr().writeAll(usage) catch {};
|
||||
os.exit(1);
|
||||
posix.exit(1);
|
||||
}
|
||||
|
||||
fn saturatingCast(comptime T: type, x: anytype) T {
|
||||
|
Loading…
x
Reference in New Issue
Block a user