Compare commits

..

129 Commits

Author SHA1 Message Date
96b54bde86 Merge branch 'main' of git.zander.im:Zander671/river 2025-12-30 16:08:45 -08:00
f6fd7655e2 Merge branch 'main' of https://codeberg.org/river/river-classic 2025-12-30 16:07:48 -08:00
df131f9a9d LayerSurface: don't configure in response to unmap
We should wait until the next "initial commit" before
sending a configure after a layer surface unmaps itself.
2025-12-20 18:40:30 +00:00
d38d4105c4 docs: update wiki link 2025-12-18 23:37:34 +00:00
242b62a9d4 Merge new river-classic 2025-12-14 08:12:14 -08:00
be722b2a3f docs: fix typo in README 2025-12-10 20:24:22 +01:00
82613a56db Fix focused view sometimes being reported as having no tags 2025-10-09 16:05:23 -07:00
936d1157b4 Fix last commit 2025-10-09 15:51:32 -07:00
7ce21a44d8 Fix current view tags being wrong 2025-10-09 15:36:11 -07:00
9c42ed788a build: bump version to 0.3.14-dev 2025-10-03 11:36:58 +02:00
3ef7b69112 build: bump version to 0.3.13 2025-10-03 11:35:50 +02:00
165871e0fc command: fix possible crash on focus
If the currently focused view has been moved to a different output but
the transaction has not yet been completed, we can hit unreachable code
in this function.

thread 1073 panic: reached unreachable code
/home/pkaplan/Software/river/river/command/view_operations.zig💯21: 0x11752d6 in getTarget (river)
                    unreachable;
                    ^
/home/pkaplan/Software/river/river/command/view_operations.zig:46:22: 0x1146f36 in focusView (river)
    if (try getTarget(
                     ^
/home/pkaplan/Software/river/river/command.zig:144:16: 0x11124e3 in run (river)
    try impl_fn(seat, args, out);
               ^
/home/pkaplan/Software/river/river/Seat.zig:447:16: 0x10eb00f in runCommand (river)
    command.run(seat, args, &out) catch |err| {
               ^
/home/pkaplan/Software/river/river/Seat.zig:423:24: 0x1110350 in handleMapping (river)
        seat.runCommand(mapping.command_args);
                       ^
/home/pkaplan/Software/river/river/Keyboard.zig:213:47: 0x10e83b8 in wrapper (river)
        if (keyboard.device.seat.handleMapping(keycode, modifiers, released, xkb_state)) {
                                              ^
???:?:?: 0x7d8f73aa051d in ??? (libwayland-server.so.0)
Unwind information for `libwayland-server.so.0:0x7d8f73aa051d` was not available, trace may be incomplete

???:?:?: 0x7d8f739fecc7 in ??? (libwlroots-0.18.so)
???:?:?: 0x7d8f739d0dbb in ??? (libwlroots-0.18.so)
???:?:?: 0x7d8f73aa2111 in ??? (libwayland-server.so.0)
???:?:?: 0x7d8f73aa41f6 in ??? (libwayland-server.so.0)
/home/pkaplan/Software/river/river/main.zig:139:25: 0x10715dd in main (river)
    server.wl_server.run();
                        ^
/usr/lib/zig/std/start.zig:524:37: 0x107083e in main (river)
            const result = root.main() catch |err| {
                                    ^
???:?:?: 0x7d8f736b06b4 in ??? (libc.so.6)
???:?:?: 0x7d8f736b0768 in ??? (libc.so.6)
???:?:?: 0x1070354 in ??? (???)
2025-10-03 11:28:19 +02:00
633f4e2733 river: remove dead code 2025-10-03 11:28:01 +02:00
170cac310d linux-dmabuf: disable fine-grained feedback again
Despite the better debouncing in wlroots 0.19, this is still causing
problems. In particular, certain clients (mostly Xwayland games it
seems) have a bad interaction with this additional feedback, possibly
related to the cursor buffer.

The reported symptoms are significant framerate drops and stuttering on
pointer input.

Probably there's a wlroots bug here at fault but I don't have the
resources to fix it myself currently and would rather not force river
users to suffer.

Setting WLR_SCENE_DISABLE_DIRECT_SCANOUT=1 isn't sufficient to solve
these problems either, as wlr_scene still sends enough extra feedback
to trigger the problems.

Closes: https://codeberg.org/river/river/issues/1277
2025-09-02 10:52:57 +02:00
c18ed4aae1 river: fix logging to non-pipe
Since the Zig 0.15 upgrade, if stderr is redirected to a file, river
writes every log message to the beginning of the file, overwriting the
previous message. This commit fixes that and also switches to the nicer
new std.debug API for stderr logging.
2025-09-02 09:46:46 +02:00
f0c7f57d36 LayerSurface: fix crash on bad exclusive zone
River closes layer surfaces with an unreasonably large exclusive zone.
However, due to unfortunate/awkward code structure, this currently
may cause a use-after-free on mapping layer surface.
2025-09-01 09:55:49 +02:00
52b312d08d Merge branch '0.3.x' of https://codeberg.org/river/river 2025-08-31 15:54:01 -07:00
d412c9cdd1 doc: tweak README formatting 2025-08-30 19:23:45 +02:00
e5c7d75dcc build: bump version to 0.3.13-dev 2025-08-30 19:01:32 +02:00
8e4f3f6800 build: bump version to 0.3.12 2025-08-30 19:01:32 +02:00
50d5108d1f ci: rename to river-classic 2025-08-30 19:01:32 +02:00
1168a3f47a doc: rename to river-classic 2025-08-30 18:56:31 +02:00
265461162f build: rename to river-classic 2025-08-30 18:56:31 +02:00
b3b79944cc build: bump version to 0.3.12 2025-08-30 18:13:56 +02:00
7bc761306e Cursor: clear pointer focus on hide
This line seems to have been removed by accident while fixing a
different unrelated bug.

Fixes: f482b9ddaa
2025-08-30 18:08:24 +02:00
88a8c45ac0 river: run 0.15 zig fmt 2025-08-22 15:11:50 +02:00
d72408df18 build: update to Zig 0.15 2025-08-22 15:09:07 +02:00
e97a63f0fa Merge branch '0.3.x' of https://codeberg.org/river/river 2025-08-17 17:23:31 -07:00
63542fdf3e build: bump zig-wlroots version
This version includes a fix for a regression introduced with the wlroots
0.19 upgrade.
2025-07-10 14:55:38 +02:00
b8ec02796f build: bump version to 0.3.12-dev 2025-07-01 09:40:25 +02:00
0898a06a96 build: bump version to 0.3.11 2025-07-01 09:37:56 +02:00
d2520301cd build: switch to zig-wlroots tag 2025-07-01 09:36:30 +02:00
1db51285c0 ext-foreign-toplevel-list-v1: implement protocol 2025-07-01 09:26:26 +02:00
d08c170571 Seat: ignore virtual keyboards until keymap set
The wlr-virtual-keyboard-v1 protocol fails to make keyboard creation
atomic. There is nothing a client can do with a virtual keyboard that
has no keymap except for destroy it, so we can completely ignore them
until a keymap is set.

This fixes a regression with fcitx caused by river sending the null
keymap of a new virtual keyboard to fcitx.
2025-06-30 12:57:06 +02:00
fe759d2d8a Keyboard: don't add virtual keyboards to group
Also don't set their keymap, the client handles that.

This is the first step towards fixing a regression with fcitx5.
2025-06-30 12:56:51 +02:00
9cc6c1e09b Fix riverctl.1.csd 2025-06-29 19:40:56 +09:00
82f2f02c00 Add cursor warp option 2025-06-29 19:40:36 +09:00
dc1d5c8418 Allow floating views to appear at the mouse 2025-06-29 19:40:00 +09:00
0c095f0c93 Merge branch '0.3.x' of https://codeberg.org/river/river 2025-06-29 19:31:25 +09:00
fcf8b1e442 Cursor: fix formatting
This is a behavior change in zig 0.14
2025-06-26 11:01:19 +02:00
ed85b4401e build: bump version to 0.3.11-dev 2025-06-18 14:14:46 +02:00
6af8369624 build: bump version to 0.3.10 2025-06-18 14:06:52 +02:00
7fc7b570f0 View: workaround wlr_box_intersect() quirk 2025-06-18 13:46:17 +02:00
6385d71c37 XwaylandView: remove set_decorations listener on unmap 2025-06-18 12:26:46 +02:00
c8fb3952f8 XwaylandView: drop set_decorations link in handleDestroy()
Fixes yet another assertion in wlroots:

    river: xwayland/xwm.c:601: xwayland_surface_destroy: Assertion `wl_list_empty(&xsurface->events.set_decorations.listener_list)' failed.
2025-06-18 12:22:17 +02:00
40294223d4 LayerSurface: drop new_popup link in handleDestroy()
This fixes an assertion in wlroots:

    river: types/wlr_layer_shell_v1.c:55: layer_surface_destroy: Assertion `wl_list_empty(&surface->events.new_popup.listener_list)' failed.
2025-06-18 12:22:17 +02:00
c111fc9905 river: drop wl_drm support
Looks like other compositors have completely dropped this by now.
2025-06-18 12:22:17 +02:00
bbb62ac8d8 linux-drm-syncobj: implement protocol 2025-06-18 12:22:17 +02:00
15736c57d7 linux-dmabuf: re-enable per-surface feedback
This was disabled due to being too spammy in the past. Since wlr_scene
now debounces per-surface feedback it should be fine to re-enable this.
2025-06-18 12:22:17 +02:00
037314823e build: update to wlroots 0.19 2025-06-18 12:22:17 +02:00
ecd2a396d3 Seat: put all keyboards in a single group
Deprecate and ignore the riverctl commands for creating explicit
keyboard groups.

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

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

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

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

Closes: https://codeberg.org/river/river/issues/1138

(cherry picked from commit 46f77f30dc)
2025-03-29 15:54:45 +01:00
f482b9ddaa Cursor: restore previous image on unhide
If client A has an xdg_popup open and the user moves the cursor over a
surface of client B and waits for the cursor to be hidden after a
timeout, the cursor will not be shown on movement until the (invisible)
cursor is moved back into a surface of client A or somewhere the
compositor is responsible for rendering the cursor.

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

Closes: https://codeberg.org/river/river/issues/1192
2025-03-16 13:37:57 +01:00
f1904d4e6f build: bump version to 0.3.10-dev 2025-03-16 12:14:07 +01:00
bdc3c0ccf9 build: bump version to 0.3.9 2025-03-10 08:20:10 +01:00
60f954c2b0 build: eliminate duplicate version string
There is now a single source of truth for river's version. It is no
longer possible for the versions in build.zig and build.zig.zon to get
out of sync as build.zig now parses the version from build.zig.zon.
2025-03-10 08:17:17 +01:00
8f4a746da0 security-context: fix assertion failure
This regression was caused by turning my brain off a bit too much during
the zig 0.14 upgrade.
2025-03-10 07:55:56 +01:00
00ab4910e0 build: bump version to 0.3.9-dev 2025-03-07 12:52:50 +01:00
23ad9aa412 build: bump version to 0.3.8 2025-03-07 12:50:31 +01:00
933701d7f9 build: update to zig 0.14.0 2025-03-07 12:44:28 +01:00
0eb478b06a Xwayland: don't inherit rlimit changes from river
(cherry picked from commit 543697847f)
2025-03-02 10:21:00 +01:00
295bbb241a build: bump version to 0.3.8-dev 2025-01-04 11:39:28 -06:00
189cf6e68b build: bump version to 0.3.7 2025-01-04 11:35:17 -06:00
840eacae62 river: wrap monotonic time > 2^32-1 milliseconds
Fixes: https://codeberg.org/river/river/issues/1176
(cherry picked from commit 6abcc68a19)
2025-01-04 11:34:16 -06:00
a5f94268e6 Output: check scene damage before rendering
This should fix adaptive sync/VRR, which was regressed by db7de8151.

(cherry picked from commit ab879e245c)
2025-01-04 11:34:06 -06:00
6254211a26 build: bump version to 0.3.7-dev 2024-12-09 15:07:58 +01:00
4b24287da7 build: bump version to 0.3.6 2024-12-09 15:01:53 +01:00
59f0fb2882 docs: mention key repeat defaults
(cherry picked from commit 5ca829bd5a)
2024-12-09 15:01:03 +01:00
be0e372fbc alpha-modifier-v1: implement protocol
Implement the alpha-modifier-v1 protocol, which allows clients to
offload alpha blending operations to the compositor.

wlroots' scene graph code takes care of updating the opacity of
wlr_scene_buffers with an associated wp_alpha_modifier_surface_v1.

(cherry picked from commit a2a5e8f463)
2024-12-09 15:00:34 +01:00
f0798f7536 layer-surface: fix clip box coordinates
The clip box must be relative to the layer surface, not the output.

(cherry picked from commit 1b5dd21ee6)
2024-12-09 15:00:08 +01:00
08cc135ebd Output: workaround wlroots headless output bug
(cherry picked from commit 3529463569)
2024-12-09 15:00:02 +01:00
42b339fbb8 input: support scroll button lock config
(cherry picked from commit fd55f51ba1)
2024-12-09 14:59:53 +01:00
fd58a84f18 docs: fix broken repology link
(cherry picked from commit 26f599b56b)
2024-12-09 14:59:45 +01:00
b281d196e4 build: load tablet-v2 protocol from its new location
(cherry picked from commit fbb9cc0f76)
2024-12-09 14:59:39 +01:00
a50573082b tearing-control: fix security-context related assert
(cherry picked from commit 55974987b6)
2024-12-09 14:59:34 +01:00
c691396448 tearing-control: minor cleanups/style improvements
This commit also tweaks the riverctl interface to make the global
allow-tearing option apply only to tearing-control-v1 hints from
clients. The global option no longer affects tearing/no-tearing rules
explicitly created by the user.

(cherry picked from commit f82b2f5816)
2024-12-09 14:59:22 +01:00
aa1ef64448 tearing-control-v1: implement
Implement the wp-tearing-control-v1 protocol allowing window to hint
the compositor that they prefer async "tearing" page flips.

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

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

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

Closes: https://codeberg.org/river/river/issues/1094
(cherry picked from commit 066baa5753)
2024-12-09 14:59:09 +01:00
993bdf96d1 Root: simplify scene tree reparenting
Making these reparent() calls unconditional avoids inconsistent state.
It's also simpler and less error-prone and the wlroots function returns
immediately if the parent doesn't change anyways.

(cherry picked from commit db7de8151c)
2024-12-09 14:49:55 +01:00
4d11cd97e0 docs: clarify input device name description
The word "numerical" suggests both decimal and hexadecimal, so changed
it to decimal.

(cherry picked from commit f5d37f9b4d)
2024-12-09 14:49:50 +01:00
379f25fb3b Output: don't configure uninitialized layer surfaces
It is possible for a layer surface to notably delay its initial commit;
for example shotman[1] creates two layer surfaces and uses one of them
to get enough information for a screenshot and initializing the other.
River could also have sent a configure before initial commit if two
clients raced against each other.

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

[1]:https://sr.ht/~whynothugo/shotman/

(cherry picked from commit 93863b132e)
2024-12-09 14:49:29 +01:00
dcc8e5cb9d build: bump version to 0.3.6-dev 2024-07-22 17:25:15 +02:00
0e1b1862ca build: bump version to 0.3.5 2024-07-22 17:21:01 +02:00
510268d83a river: attempt to recover from GPU resets
(cherry picked from commit 85a1673a9e)
2024-07-22 17:20:08 +02:00
62576d792c LayerSurface: minor style/naming tweaks
No functional changes

(cherry picked from commit 2cc1d1cef3)
2024-07-22 17:20:02 +02:00
2a75d51eec LayerSurface: focus on_demand-interactive surfaces on map
This is done specifically for lxqt-runner and qterminal to work as
expected, consistently among (almost) all compositors with layer-shell.
The most prominent drawback of this is that top- and overlay-layer
status bars with on_demand interactivity also get focus on map.

See https://codeberg.org/river/river/issues/1111 for more details.

(cherry picked from commit f27bbf03f1)
2024-07-22 17:19:59 +02:00
eb32deaf76 build: update to wlroots 0.18.0
(cherry picked from commit 99ef96a389)
2024-07-22 17:19:44 +02:00
4e2a1a12f8 completions: zsh click-method option fix
"button-areas" seems to be the argument this command expects instead of
"button-area" -- other shells also have the option as "button-areas".

(cherry picked from commit ccd676e5a9)
2024-07-22 17:12:24 +02:00
dc0d8112a6 build: bump version to 0.3.5-dev 2024-07-10 12:58:47 +02:00
4f39ce79e9 build: bump version to 0.3.4 2024-07-10 12:55:32 +02:00
6849176e25 PointerConstraint: fix assertion failure
The assertion in PointerConstraint.confine() can currently still be
triggered if the input region of a surface is changed and the pointer is
moved outside of the new intersection of input region and constraint
region before PointerConstraint.updateState() is called.

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

To fix this, listen for the surface commit event rather than the
set_region event to handle possible deactivation on region changes.

(cherry picked from commit a7411ef2a6)
2024-07-10 12:55:02 +02:00
667b047cdf docs: mention zig build -h in readme
(cherry picked from commit 1f5bf1d972)
2024-07-10 12:55:02 +02:00
eab893c481 layer-shell: fix on_demand keyboard focus
Currently keyboard focus is stolen from layer surfaces with
on_demand keyboard interactivity any time Root.applyPending() is called.

This commit fixes the behavior to only steal focus when explicitly
focusing a different window/layer surface.

(cherry picked from commit 4232d6b99f)
2024-07-10 12:55:02 +02:00
cf63d16846 XdgPopup: send configure after initial commit
Currently we send the first configure for xdg popups before the popup
has made its initial commit. This is incorrect according to the protocol
and may confuse clients.

(cherry picked from commit ec16f1c375)
2024-07-10 12:55:02 +02:00
6e0c103705 Output: fix Wayland backend support
The wlroots Wayland backend does not support gamma LUT application and
will currently fail to render anything if river commits a gamma LUT.

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

This problem was revealed by 2e09b66 which flags gamma as dirty on all
outputs when they are enabled.

(cherry picked from commit a80e0f7322)
2024-07-10 12:55:02 +02:00
5cfa1fc8f5 docs: tweak repology link wording in readme
(cherry picked from commit 0997fde28e)
2024-07-10 12:29:14 +02:00
6564db22df Xwayland: fix unsound cast
The X11 protocol uses 16 bit integers for width/height but we use
32 bit integers everywhere else in river. Make sure that values outside
the range of a 16 bit integer don't cause river to crash with an
assertion failure.

I think that coordinates outside the range of a 16 bit integer could
theoretically be reasonable with tiled high resolution displays in the
future. I doubt they ever get used in practice today but at the same
time we can't allow an errant layout generator to crash river.

(cherry picked from commit ae7f4b8fcb)
2024-07-10 12:29:06 +02:00
b85da67886 Output: flag gamma as dirty on enable
We can end up with stale gamma settings if we don't re-check the
current gamma settings for the output on enable.

(cherry picked from commit 2e09b66963)
2024-07-10 12:28:57 +02:00
99b31c39f3 input: apply map-to-output on output activation
Currently a map-to-output input config setting loses effect when an
output is disabled and re-enabled for example.

(cherry picked from commit de3035563c)
2024-07-10 12:28:49 +02:00
36cdbbc087 SceneNodeData: fix fromSurface() use after free
We must clean up the user data of the wlr_surface for layer surfaces and
lock surfaces as fromSurface() may be called (e.g. by the idle inhibit
implementation) after the scene node has been destroyed but before the
wlr_surface is destroyed.

(cherry picked from commit 28a14c6794)
2024-07-10 12:28:44 +02:00
4653a7730e ci: log build summaries
(cherry picked from commit e2f3cd8252)
2024-07-10 12:28:33 +02:00
f577cb5f2e ci: re-enable FreeBSD builds
Official FreeBSD zig tarballs have returned!

This reverts commit 7fdba05b82.

(cherry picked from commit f9201ae7cd)
2024-07-10 12:28:23 +02:00
77699aa0ba ci: use mirror for zig tarball downloads
Eat Github's resources rather than the Zig Software Foundation's
resources!

(cherry picked from commit 16c938111d)
2024-07-10 12:28:17 +02:00
64e2555505 build: bump version to 0.3.4-dev 2024-06-07 14:16:32 +02:00
1e65e652c2 build: bump version to 0.3.3 2024-06-07 14:11:31 +02:00
a17270721e build: update to Zig 0.13.0
(cherry picked from commit 8da69699e9)
2024-06-07 14:10:24 +02:00
914f5fae20 ci: cleanup messy tar invocations
(cherry picked from commit c5b1d1de4e)
2024-06-07 14:10:24 +02:00
5cd22edb58 build: bump version to 0.3.3-dev 2024-05-20 12:17:38 +02:00
3ff620fae3 build: bump version to 0.3.2 2024-05-20 12:14:13 +02:00
25675e4fcb ci: drop FreeBSD CI for now
There is no FreeBSD tarball from ziglang.org and FreeBSD itself has not
yet updated their Zig package to 0.12.0. This commit should be reverted
when a good way is found to obtain Zig 0.12.0 for the FreeBSD CI.

(cherry picked from commit 7fdba05b82)
2024-05-20 12:13:18 +02:00
b1bac96731 build: switch to the Zig package manager
No more git submodules!

(cherry picked from commit 958f8798b6)
2024-05-20 12:13:18 +02:00
9cbd66f543 build: add -Dno-llvm build option
(cherry picked from commit 045ee7bd25)
2024-05-20 12:07:52 +02:00
312465e0cb build: update to Zig 0.12
(cherry picked from commit 033cad47bf)
2024-05-20 12:07:52 +02:00
c757e1b33e build: bump version to 0.3.2-dev 2024-05-18 17:43:46 +02:00
6a2eeba9ed bulid: bump version to 0.3.1 2024-05-18 17:09:03 +02:00
a019045a16 PointerConstraint: remove overly tight assert 2
This is a second copy of the same assert that was removed in the last
commit. It should have been removed by that commit as well but was
overlooked.

(cherry picked from commit 680cb8ef69)
2024-05-18 17:07:48 +02:00
7b42c38276 PointerConstraint: remove overly tight assert
This assert is incorrect if Xwayland is enabled and an Override Redirect
window steals the keyboard focus from the parent surface.

It also seems likely to be hit if a Wayland client attempts to use a
pointer constraint on a subsurface. I don't think a pointer constraint
on a subsurface is likely to work entirely correctly and I don't know of
any Wayland clients that try such a thing. We can't let them crash river
by trying though.

(cherry picked from commit 5d1fc034bc)
2024-05-18 17:07:48 +02:00
fa077d31b4 InputPopup: fix minor issues, simplify code
(cherry picked from commit c75d32c88b)
2024-05-18 13:41:28 +02:00
cc5a249e9e TextInput: ignore enable requests without focus
(cherry picked from commit b35a40b9df)
2024-05-18 13:41:28 +02:00
84ec97aff2 InputPopup: fix naming
(cherry picked from commit ba6023e38a)
2024-05-18 13:41:28 +02:00
7db9ade574 input-method-v2: Implement popups
(cherry picked from commit 74baf7225a)
2024-05-18 13:41:28 +02:00
9c56eb051f Server: fix filtering of newly created globals
Fixes: https://codeberg.org/river/river/issues/1068
(cherry picked from commit b5a80c7b9b)
2024-05-18 13:41:28 +02:00
9b0e90cdb4 command/swap: fix cursor warp on focus change
(cherry picked from commit bed50f0dd2)
2024-05-18 13:41:28 +02:00
cfb67b9e7a Keyboard: fix redundant leave/enter on creation
Currently if a second keyboard input device is created river will send
a wl_keyboard.leave event immediately followed by a wl_keyboard.enter
event. This serves no purpose and can confuse clients, in particular due
to fctix creating/destroying virtual keyboards on focus change.

Fixes: https://codeberg.org/river/river/issues/1062
References: https://github.com/fcitx/fcitx5/issues/1044
(cherry picked from commit 1e3ef88bd5)
2024-05-18 13:41:05 +02:00
717894b007 Cursor: don't hide while pointer constraint active
Fixes: https://codeberg.org/river/river/issues/1053
(cherry picked from commit f66eec9248)
2024-05-18 13:30:59 +02:00
442913fa82 input: change ScrollFactor and MapToOutput to align with other options
(cherry picked from commit 5262a4c5a6)
2024-04-27 13:39:47 +02:00
b5964d7f1f input: fix scroll-factor resetting if unspecified
(cherry picked from commit bd5da261eb)
2024-04-27 13:39:47 +02:00
33cc85d5ef input: prevent duplicate input configs
(cherry picked from commit 5fbf174c36)
2024-04-27 13:39:47 +02:00
b2c4d38e09 XdgToplevel: update clip on geometry x/y change
Currently if a client commits a geometry with a different x/y value but
does not change the width/height we might not update the clip
coordinates of the surface tree, potentially causing part of the surface
to be unintentionally clipped off.

To fix this, check for change in geometry x/y as well as width/height on
commit if the client is not currently part of an ongoing transaction.

Firefox for example it seems may respond to a configure non-atomically
with multiple commits:

1. commit new buffer and new geometry of a new width/height.
2. commit again with the same width/height but a new geometry x/y.

I don't think this is technically a bug but it doesn't seem like the
most efficient way to do things. I think this may also cause imperfect
frames. In any case, this should no longer cause river to crop off part
of firefox's surface.

(cherry picked from commit 9bbd34a0e3)
2024-04-27 13:39:47 +02:00
dbfaa05a67 XdgToplevel: don't update geometry if configure inflight
(cherry picked from commit d1dc873408)
2024-04-27 13:39:47 +02:00
822690146d build: bump version to 0.3.1-dev 2024-04-19 14:00:29 +02:00
54 changed files with 768 additions and 631 deletions

View File

@ -14,6 +14,7 @@ packages:
- xcb-util-wm-dev - xcb-util-wm-dev
- pixman-dev - pixman-dev
- libevdev-dev - libevdev-dev
- wayland-dev
- wayland-protocols - wayland-protocols
- xwayland-dev - xwayland-dev
- meson - meson
@ -22,19 +23,12 @@ packages:
- wget - wget
- xz - xz
sources: sources:
- https://codeberg.org/river/river - https://codeberg.org/river/river-classic
- https://gitlab.freedesktop.org/wayland/wayland.git
- https://gitlab.freedesktop.org/wlroots/wlroots.git - https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks: tasks:
- install_deps: | - install_deps: |
cd wayland
git checkout 1.23.0
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
sudo ninja -C build install
cd ..
cd wlroots cd wlroots
git checkout 0.18.0 git checkout 0.19.0
meson setup build --auto-features=enabled -Drenderers=gles2 \ meson setup build --auto-features=enabled -Drenderers=gles2 \
-Dcolor-management=disabled -Dlibliftoff=disabled \ -Dcolor-management=disabled -Dlibliftoff=disabled \
-Dexamples=false -Dwerror=false -Db_ndebug=false \ -Dexamples=false -Dwerror=false -Db_ndebug=false \
@ -43,20 +37,19 @@ tasks:
cd .. cd ..
# Eat Github's resources rather than the Zig Software Foundation's resources! # Eat Github's resources rather than the Zig Software Foundation's resources!
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz
tar xf zig-linux-x86_64-0.13.0.tar.xz tar xf zig-x86_64-linux-0.15.1.tar.xz
sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/ sudo mv zig-x86_64-linux-0.15.1/zig /usr/bin/
sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig sudo mv zig-x86_64-linux-0.15.1/lib /usr/lib/zig
- build: | - build: |
cd river cd river-classic
zig build --summary all zig build --summary all
- build_xwayland: | - build_xwayland: |
cd river cd river-classic
zig build --summary all -Dxwayland zig build --summary all -Dxwayland
- fmt: | - fmt: |
cd river cd river-classic
zig fmt --check river/ zig fmt --check river/
zig fmt --check riverctl/ zig fmt --check riverctl/
zig fmt --check rivertile/ zig fmt --check rivertile/
zig fmt --check build.zig zig fmt --check build.zig
zig fmt --check build.zig.zon

View File

@ -20,19 +20,12 @@ packages:
- wget - wget
- xz - xz
sources: sources:
- https://codeberg.org/river/river - https://codeberg.org/river/river-classic
- https://gitlab.freedesktop.org/wayland/wayland.git
- https://gitlab.freedesktop.org/wlroots/wlroots.git - https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks: tasks:
- install_deps: | - install_deps: |
cd wayland
git checkout 1.23.0
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
sudo ninja -C build install
cd ..
cd wlroots cd wlroots
git checkout 0.18.0 git checkout 0.19.0
meson setup build --auto-features=enabled -Drenderers=gles2 \ meson setup build --auto-features=enabled -Drenderers=gles2 \
-Dcolor-management=disabled -Dlibliftoff=disabled \ -Dcolor-management=disabled -Dlibliftoff=disabled \
-Dexamples=false -Dwerror=false -Db_ndebug=false \ -Dexamples=false -Dwerror=false -Db_ndebug=false \
@ -41,20 +34,19 @@ tasks:
cd .. cd ..
# Eat Github's resources rather than the Zig Software Foundation's resources! # Eat Github's resources rather than the Zig Software Foundation's resources!
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-linux-x86_64-0.13.0.tar.xz wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.15.1/zig-x86_64-linux-0.15.1.tar.xz
tar xf zig-linux-x86_64-0.13.0.tar.xz tar xf zig-x86_64-linux-0.15.1.tar.xz
sudo mv zig-linux-x86_64-0.13.0/zig /usr/bin/ sudo mv zig-x86_64-linux-0.15.1/zig /usr/bin/
sudo mv zig-linux-x86_64-0.13.0/lib /usr/lib/zig sudo mv zig-x86_64-linux-0.15.1/lib /usr/lib/zig
- build: | - build: |
cd river cd river-classic
zig build --summary all zig build --summary all
- build_xwayland: | - build_xwayland: |
cd river cd river-classic
zig build --summary all -Dxwayland zig build --summary all -Dxwayland
- fmt: | - fmt: |
cd river cd river-classic
zig fmt --check river/ zig fmt --check river/
zig fmt --check riverctl/ zig fmt --check riverctl/
zig fmt --check rivertile/ zig fmt --check rivertile/
zig fmt --check build.zig zig fmt --check build.zig
zig fmt --check build.zig.zon

View File

@ -7,6 +7,7 @@ packages:
- devel/meson - devel/meson
- devel/pkgconf - devel/pkgconf
- graphics/mesa-libs - graphics/mesa-libs
- graphics/wayland
- graphics/wayland-protocols - graphics/wayland-protocols
- misc/hwdata - misc/hwdata
- x11/libX11 - x11/libX11
@ -25,20 +26,14 @@ packages:
- scdoc - scdoc
- wget - wget
sources: sources:
- https://codeberg.org/river/river - https://codeberg.org/river/river-classic
- https://gitlab.freedesktop.org/wayland/wayland.git
- https://gitlab.freedesktop.org/wlroots/wlroots.git - https://gitlab.freedesktop.org/wlroots/wlroots.git
tasks: tasks:
- install_deps: | - install_deps: |
cd wayland
git checkout 1.23.0
meson setup build -Ddocumentation=false -Dtests=false --prefix /usr
sudo ninja -C build install
cd ..
cd wlroots cd wlroots
git checkout 0.18.0 git checkout 0.19.0
meson setup build --auto-features=enabled -Drenderers=gles2 \ meson setup build --auto-features=enabled -Drenderers=gles2 \
-Dallocators=gbm \
-Dcolor-management=disabled -Dlibliftoff=disabled \ -Dcolor-management=disabled -Dlibliftoff=disabled \
-Dexamples=false -Dwerror=false -Db_ndebug=false \ -Dexamples=false -Dwerror=false -Db_ndebug=false \
-Dxcb-errors=disabled --prefix /usr -Dxcb-errors=disabled --prefix /usr
@ -46,18 +41,18 @@ tasks:
cd .. cd ..
# Eat Github's resources rather than the Zig Software Foundation's resources! # Eat Github's resources rather than the Zig Software Foundation's resources!
wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.13.0/zig-freebsd-x86_64-0.13.0.tar.xz wget -nv https://github.com/ifreund/zig-tarball-mirror/releases/download/0.15.1/zig-x86_64-freebsd-0.15.1.tar.xz
tar xf zig-freebsd-x86_64-0.13.0.tar.xz tar xf zig-x86_64-freebsd-0.15.1.tar.xz
sudo mv zig-freebsd-x86_64-0.13.0/zig /usr/bin/ sudo mv zig-x86_64-freebsd-0.15.1/zig /usr/bin/
sudo mv zig-freebsd-x86_64-0.13.0/lib /usr/lib/zig sudo mv zig-x86_64-freebsd-0.15.1/lib /usr/lib/zig
- build: | - build: |
cd river cd river-classic
zig build --summary all zig build --summary all
- build_xwayland: | - build_xwayland: |
cd river cd river-classic
zig build --summary all -Dxwayland zig build --summary all -Dxwayland
- fmt: | - fmt: |
cd river cd river-classic
zig fmt --check river/ zig fmt --check river/
zig fmt --check riverctl/ zig fmt --check riverctl/
zig fmt --check rivertile/ zig fmt --check rivertile/

2
.gitignore vendored
View File

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

View File

@ -1,39 +1,39 @@
# Packaging river for distribution # Packaging river-classic for distribution
First of all, I apologize for writing river in Zig. It will likely make First of all, I apologize for writing river-classic in Zig. It will likely make
your job harder until Zig is more mature/stable. I do however believe that your job harder until Zig is more mature/stable. I do however believe that
writing my software in Zig allows me to deliver the best quality I can writing my software in Zig allows me to deliver the best quality I can despite
despite the drawbacks of depending on a relatively immature language/toolchain. the drawbacks of depending on a relatively immature language/toolchain.
## Source tarballs ## Source tarballs
Source tarballs with stable checksums and git submodule sources included may Source tarballs with stable checksums may be found on the
be found on the [codeberg releases page](https://codeberg.org/river/river/releases). [codeberg releases page](https://codeberg.org/river/river-classic/releases).
These tarballs are signed with the PGP key available on my website at These tarballs are signed with the PGP key available on my website at
<https://isaacfreund.com/public_key.txt>. <https://isaacfreund.com/public_key.txt>.
For the 0.1.3 release for example, the tarball and signature URLs are: For the 0.3.12 release for example, the tarball and signature URLs are:
``` ```
https://codeberg.org/river/river/releases/download/v0.1.3/river-0.1.3.tar.gz https://codeberg.org/river/river-classic/releases/download/v0.1.3/river-classic-0.3.12.tar.gz
https://codeberg.org/river/river/releases/download/v0.1.3/river-0.1.3.tar.gz.sig https://codeberg.org/river/river-classic/releases/download/v0.1.3/river-classic-0.3.12.tar.gz.sig
``` ```
## Zig version ## Zig version
Until Zig 1.0, Zig releases will often have breaking changes that prevent Until Zig 1.0, Zig releases will often have breaking changes that prevent
river from building. River tracks the latest minor version Zig release river-classic from building. river-classic tracks the latest minor version Zig
and is only compatible with that release and any patch releases. At the time release and is only compatible with that release and any patch releases. At the
of writing for example river is compatible with Zig 0.9.0 and 0.9.1 but time of writing for example river is compatible with Zig 0.9.0 and 0.9.1 but not
not Zig 0.8.0 or 0.10.0. Zig 0.8.0 or 0.10.0.
## Zig Package Manager ## Zig Package Manager
River uses the built-in Zig package manager for its (few) Zig dependencies. river-classic uses the built-in Zig package manager for its (few) Zig
By default, running `zig build` will fetch river's Zig dependencies from the dependencies. By default, running `zig build` will fetch river-classic's Zig
internet and store them in the global zig cache before building river. Since dependencies from the internet and store them in the global zig cache before
accessing the internet is forbidden or at least frowned upon by most distro building river-classic. Since accessing the internet is forbidden or at least
packaging infrastructure, there are ways to fetch the Zig dependencies in a frowned upon by most distro packaging infrastructure, there are ways to fetch
separate step before building river: the Zig dependencies in a separate step before building river-classic:
1. Fetch step with internet access: 1. Fetch step with internet access:
@ -114,10 +114,10 @@ in the first place. For greatest effect, both may be used.
- `-Doptimize=ReleaseSmall`: Optimize for binary size, - `-Doptimize=ReleaseSmall`: Optimize for binary size,
disable all assertions and runtime safety checks. disable all assertions and runtime safety checks.
Please use `-Doptimize=ReleaseSafe` when building river for general Please use `-Doptimize=ReleaseSafe` when building river-classic for general use.
use. CPU execution speed is not the performance bottleneck for river, the CPU execution speed is not the performance bottleneck for river-classic, the GPU
GPU is. Additionally, the increased safety is more than worth the binary is. Additionally, the increased safety is more than worth the binary size
size trade-off in my opinion. trade-off in my opinion.
## Build prefix and DESTDIR ## Build prefix and DESTDIR
@ -126,7 +126,7 @@ environment variable. For example
```bash ```bash
DESTDIR="/foo/bar" zig build --prefix /usr install DESTDIR="/foo/bar" zig build --prefix /usr install
``` ```
will install river to `/foo/bar/usr/bin/river`. will install river-classic to `/foo/bar/usr/bin/river`.
The Zig build system only has a single install step, there is no way to build The Zig build system only has a single install step, there is no way to build
artifacts for a given prefix and then install those artifacts to that prefix artifacts for a given prefix and then install those artifacts to that prefix
@ -147,7 +147,7 @@ install() {
## River specific suggestions ## River specific suggestions
I recommend installing the example init file found at `example/init` to I recommend installing the example init file found at `example/init` to
`/usr/share/examples/river/init` or similar if your distribution has such `/usr/share/examples/river-classic/init` or similar if your distribution has such
a convention. a convention.
## Examples ## Examples

View File

@ -1,66 +1,59 @@
<div align="center"> # river-classic
<img src="logo/logo_text_adaptive_color.svg" width="600em">
</div>
## Overview river-classic is a dynamic tiling Wayland compositor with flexible runtime
River is a dynamic tiling Wayland compositor with flexible runtime
configuration. configuration.
Check [packaging status](https://repology.org/project/river-compositor/versions) — It is a fork of [river](https://codeberg.org/river/river) 0.3 intended for users
that are happy with how river 0.3 works and do not wish to deal with the majorly
breaking changes planned for the river 0.4.0 release.
Join us at [#river](https://web.libera.chat/?channels=#river) on irc.libera.chat — 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 Read our man pages, [wiki](https://codeberg.org/river/wiki-classic), and
[Code of Conduct](CODE_OF_CONDUCT.md) [Code of Conduct](CODE_OF_CONDUCT.md)
The main repository is on [codeberg](https://codeberg.org/river/river), The main repository is on [codeberg](https://codeberg.org/river/river-classic),
which is where the issue tracker may be found and where contributions are accepted. which is where the issue tracker may be found and where contributions are accepted.
Read-only mirrors exist on [sourcehut](https://git.sr.ht/~ifreund/river) Read-only mirrors exist on [sourcehut](https://git.sr.ht/~ifreund/river-classic)
and [github](https://github.com/riverwm/river). and [github](https://github.com/riverwm/river-classic).
*Note: river has not yet seen a stable 1.0 release and it will be necessary to
make significant breaking changes before 1.0 to realize my longer term plans.
That said, I do my best to avoid gratuitous breaking changes and bugs/crashes
should be rare. If you find a bug don't hesitate to
[open an issue](https://codeberg.org/river/river/issues/new/choose).*
## Features ## Features
Currently river's window management style is quite similar to river-classic's window management style is quite similar to
[dwm](http://dwm.suckless.org), [xmonad](https://xmonad.org), and other classic [dwm](http://dwm.suckless.org), [xmonad](https://xmonad.org), and other classic
dynamic tiling X11 window managers. Windows are automatically arranged in a tiled dynamic tiling X11 window managers. Windows are automatically arranged in a tiled
layout and shifted around as windows are opened/closed. layout and shifted around as windows are opened/closed.
Rather than having the tiled layout logic built into the compositor process, Rather than having the tiled layout logic built into the compositor process,
river uses a [custom Wayland river-classic uses a [custom Wayland
protocol](https://codeberg.org/river/river/src/branch/master/protocol/river-layout-v3.xml) protocol](https://codeberg.org/river/river-classic/src/branch/master/protocol/river-layout-v3.xml)
and separate "layout generator" process. A basic layout generator, `rivertile`, and separate "layout generator" process. A basic layout generator, `rivertile`,
is provided but users are encouraged to use community-developed [layout is provided but users are encouraged to use community-developed [layout
generators](https://codeberg.org/river/wiki/src/branch/master/pages/Community-Layouts.md) generators](https://codeberg.org/river/wiki/src/branch/master/pages/Community-Layouts.md)
or write their own. Examples in C and Python may be found or write their own. Examples in C and Python may be found
[here](https://codeberg.org/river/river/src/branch/master/contrib). [here](https://codeberg.org/river/river-classic/src/branch/master/contrib).
Tags are used to organize windows rather than workspaces. A window may be Tags are used to organize windows rather than workspaces. A window may be
assigned to one or more tags. Likewise, one or more tags may be displayed on a assigned to one or more tags. Likewise, one or more tags may be displayed on a
monitor at a time. monitor at a time.
River is configured at runtime using the `riverctl` tool. It can define river-classic is configured at runtime using the `riverctl` tool. It can define
keybindings, set the active layout generator, configure input devices, and more. keybindings, set the active layout generator, configure input devices, and more.
On startup, river runs a user-defined init script which usually runs `riverctl` On startup, river-classic runs a user-defined init script which usually runs
commands to set up the user's configuration. `riverctl` commands to set up the user's configuration.
## Building ## Building
Note: If you are packaging river for distribution, see [PACKAGING.md](PACKAGING.md). Note: If you are packaging river-classic for distribution, see [PACKAGING.md](PACKAGING.md).
To compile river first ensure that you have the following dependencies To compile river-classic first ensure that you have the following dependencies
installed. The "development" versions are required if applicable to your installed. The "development" versions are required if applicable to your
distribution. distribution.
- [zig](https://ziglang.org/download/) 0.13 - [zig](https://ziglang.org/download/) 0.15
- wayland - wayland
- wayland-protocols - wayland-protocols
- [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.18 - [wlroots](https://gitlab.freedesktop.org/wlroots/wlroots) 0.19
- xkbcommon - xkbcommon
- libevdev - libevdev
- pixman - pixman
@ -79,7 +72,7 @@ Run `zig build -h` to see a list of all options.
River can either be run nested in an X11/Wayland session or directly River can either be run nested in an X11/Wayland session or directly
from a tty using KMS/DRM. Simply run the `river` command. from a tty using KMS/DRM. Simply run the `river` command.
On startup river will run an executable file at `$XDG_CONFIG_HOME/river/init` On startup river-classic will run an executable file at `$XDG_CONFIG_HOME/river/init`
if such an executable exists. If `$XDG_CONFIG_HOME` is not set, if such an executable exists. If `$XDG_CONFIG_HOME` is not set,
`~/.config/river/init` will be used instead. `~/.config/river/init` will be used instead.
@ -93,34 +86,14 @@ in the example directory.
For complete documentation see the `river(1)`, `riverctl(1)`, and For complete documentation see the `river(1)`, `riverctl(1)`, and
`rivertile(1)` man pages. `rivertile(1)` man pages.
## Future Plans
Currently details such as how tags work across multiple monitors are not
possible for users to configure. It would be possible to extend river's source
code to allow more flexibility here but this comes at the cost of complexity and
there will always be someone who prefers something slightly different.
My long term plan to address this is to move as much window management policy as
possible out of the river compositor process and into the "layout generator"
process which will need to be renamed to "window manager." This will give users
much more power and control over river's behavior and also enable some really
cool workflows. For example, it would be possible to write a window manager in
lisp and use hot code reloading to edit its behavior it while it is running.
This is a non-trivial architectural change and will take a while to implement. I
plan to focus on this change for the 0.4.0 release cycle. Unfortunately, it will
almost certainly break existing river configurations as well. I think the
benefits outweigh that downside though and I will do my best to offer a
reasonable upgrade path.
## Donate ## Donate
If my work on river adds value to your life and you'd like to support me If my work on river-classic adds value to your life and you'd like to support me
financially you can find donation information [here](https://isaacfreund.com/donate/). financially you can find donation information [here](https://isaacfreund.com/donate/).
## Licensing ## Licensing
River is released under the GNU General Public License v3.0 only. river-classic is released under the GNU General Public License v3.0 only.
The protocols in the `protocol` directory are released under various licenses by The protocols in the `protocol` directory are released under various licenses by
various parties. You should refer to the copyright block of each protocol for various parties. You should refer to the copyright block of each protocol for

View File

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

View File

@ -1,23 +1,29 @@
.{ .{
.name = "river", .name = .river_classic,
.version = "0.4.0-dev", // 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.14-dev",
.paths = .{""}, .paths = .{""},
.dependencies = .{ .dependencies = .{
.@"zig-pixman" = .{ .pixman = .{
.url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.2.0.tar.gz", .url = "https://codeberg.org/ifreund/zig-pixman/archive/v0.3.0.tar.gz",
.hash = "12209db20ce873af176138b76632931def33a10539387cba745db72933c43d274d56", .hash = "pixman-0.3.0-LClMnz2VAAAs7QSCGwLimV5VUYx0JFnX5xWU6HwtMuDX",
}, },
.@"zig-wayland" = .{ .wayland = .{
.url = "https://codeberg.org/ifreund/zig-wayland/archive/bd8afd256fb6beed7d72e3580b00f33dea7155a1.tar.gz", .url = "https://codeberg.org/ifreund/zig-wayland/archive/v0.4.0.tar.gz",
.hash = "1220218a0e5c2cd63a2311417f4d3f2411dd17d75815f67c704ee657bd846ecbc3e0", .hash = "wayland-0.4.0-lQa1khbMAQAsLS2eBR7M5lofyEGPIbu2iFDmoz8lPC27",
}, },
.@"zig-wlroots" = .{ .wlroots = .{
.url = "https://codeberg.org/ifreund/zig-wlroots/archive/afbbbbe5579c750feed8de12b073fa50b0651137.tar.gz", .url = "https://codeberg.org/ifreund/zig-wlroots/archive/v0.19.3.tar.gz",
.hash = "122060ddef836b7872cb2088764a8bd2fb2e9254327673e8176b7f7a621ec897484f", .hash = "wlroots-0.19.3-jmOlcuL_AwBHhLCwpFsXbTizE3q9BugFmGX-XIxqcPMc",
}, },
.@"zig-xkbcommon" = .{ .xkbcommon = .{
.url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.2.0.tar.gz", .url = "https://codeberg.org/ifreund/zig-xkbcommon/archive/v0.3.0.tar.gz",
.hash = "1220c90b2228d65fd8427a837d31b0add83e9fade1dcfa539bb56fd06f1f8461605f", .hash = "xkbcommon-0.3.0-VDqIe3K9AQB2fG5ZeRcMC9i7kfrp5m2rWgLrmdNn9azr",
}, },
}, },
.fingerprint = 0x3dae7aba2ea52a3b,
} }

View File

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

View File

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

View File

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

View File

@ -42,7 +42,7 @@ pub fn create(wlr_drag_icon: *wlr.Drag.Icon, cursor: *Cursor) error{OutOfMemory}
.wlr_drag_icon = wlr_drag_icon, .wlr_drag_icon = wlr_drag_icon,
.scene_drag_icon = scene_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); drag_icon.updatePosition(cursor);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -36,6 +36,8 @@ wlr_layer_surface: *wlr.LayerSurfaceV1,
scene_layer_surface: *wlr.SceneLayerSurfaceV1, scene_layer_surface: *wlr.SceneLayerSurfaceV1,
popup_tree: *wlr.SceneTree, popup_tree: *wlr.SceneTree,
newly_mapped: bool = false,
destroy: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleDestroy), destroy: wl.Listener(*wlr.LayerSurfaceV1) = wl.Listener(*wlr.LayerSurfaceV1).init(handleDestroy),
map: wl.Listener(void) = wl.Listener(void).init(handleMap), map: wl.Listener(void) = wl.Listener(void).init(handleMap),
unmap: wl.Listener(void) = wl.Listener(void).init(handleUnmap), unmap: wl.Listener(void) = wl.Listener(void).init(handleUnmap),
@ -43,7 +45,7 @@ commit: wl.Listener(*wlr.Surface) = wl.Listener(*wlr.Surface).init(handleCommit)
new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup), new_popup: wl.Listener(*wlr.XdgPopup) = wl.Listener(*wlr.XdgPopup).init(handleNewPopup),
pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void { pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
const output: *Output = @ptrFromInt(wlr_layer_surface.output.?.data); const output: *Output = @ptrCast(@alignCast(wlr_layer_surface.output.?.data));
const layer_surface = try util.gpa.create(LayerSurface); const layer_surface = try util.gpa.create(LayerSurface);
errdefer util.gpa.destroy(layer_surface); errdefer util.gpa.destroy(layer_surface);
@ -59,7 +61,7 @@ pub fn create(wlr_layer_surface: *wlr.LayerSurfaceV1) error{OutOfMemory}!void {
try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface }); try SceneNodeData.attach(&layer_surface.scene_layer_surface.tree.node, .{ .layer_surface = layer_surface });
try SceneNodeData.attach(&layer_surface.popup_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.events.destroy.add(&layer_surface.destroy);
wlr_layer_surface.surface.events.map.add(&layer_surface.map); wlr_layer_surface.surface.events.map.add(&layer_surface.map);
@ -82,32 +84,33 @@ fn handleDestroy(listener: *wl.Listener(*wlr.LayerSurfaceV1), _: *wlr.LayerSurfa
layer_surface.map.link.remove(); layer_surface.map.link.remove();
layer_surface.unmap.link.remove(); layer_surface.unmap.link.remove();
layer_surface.commit.link.remove(); layer_surface.commit.link.remove();
layer_surface.new_popup.link.remove();
layer_surface.destroyPopups(); layer_surface.destroyPopups();
layer_surface.popup_tree.node.destroy(); layer_surface.popup_tree.node.destroy();
// The wlr_surface may outlive the wlr_layer_surface so we must clean up the user data. // The wlr_surface may outlive the wlr_layer_surface so we must clean up the user data.
layer_surface.wlr_layer_surface.surface.data = 0; layer_surface.wlr_layer_surface.surface.data = null;
util.gpa.destroy(layer_surface); util.gpa.destroy(layer_surface);
} }
fn handleMap(listener: *wl.Listener(void)) void { fn handleMap(listener: *wl.Listener(void)) void {
const layer_surface: *LayerSurface = @fieldParentPtr("map", listener); const layer_surface: *LayerSurface = @fieldParentPtr("map", listener);
const wlr_surface = layer_surface.wlr_layer_surface; const wlr_layer_surface = layer_surface.wlr_layer_surface;
log.debug("layer surface '{s}' mapped", .{wlr_surface.namespace}); log.debug("layer surface '{s}' mapped", .{wlr_layer_surface.namespace});
layer_surface.output.arrangeLayers(); // This is a bit of a hack, but layer surfaces are not part of the
// transaction system in river 0.3 so there's not a significantly cleaner
const consider = wlr_surface.current.keyboard_interactive == .on_demand and // way I see to do this.
(wlr_surface.current.layer == .top or wlr_surface.current.layer == .overlay); layer_surface.newly_mapped = true;
handleKeyboardInteractiveExclusive(
layer_surface.output,
if (consider) layer_surface else null,
);
// Beware: it is possible for arrangeLayers() to destroy this LayerSurface!
const output = layer_surface.output;
output.arrangeLayers();
handleKeyboardInteractiveExclusive(output);
server.root.applyPending(); server.root.applyPending();
} }
@ -116,8 +119,10 @@ fn handleUnmap(listener: *wl.Listener(void)) void {
log.debug("layer surface '{s}' unmapped", .{layer_surface.wlr_layer_surface.namespace}); log.debug("layer surface '{s}' unmapped", .{layer_surface.wlr_layer_surface.namespace});
layer_surface.output.arrangeLayers(); // Beware: it is possible for arrangeLayers() to destroy this LayerSurface!
handleKeyboardInteractiveExclusive(layer_surface.output, null); const output = layer_surface.output;
output.arrangeLayers();
handleKeyboardInteractiveExclusive(output);
server.root.applyPending(); server.root.applyPending();
} }
@ -136,46 +141,68 @@ fn handleCommit(listener: *wl.Listener(*wlr.Surface), _: *wlr.Surface) void {
if (wlr_layer_surface.initial_commit or if (wlr_layer_surface.initial_commit or
@as(u32, @bitCast(wlr_layer_surface.current.committed)) != 0) @as(u32, @bitCast(wlr_layer_surface.current.committed)) != 0)
{ {
layer_surface.output.arrangeLayers(); // Beware: it is possible for arrangeLayers() to destroy this LayerSurface!
handleKeyboardInteractiveExclusive(layer_surface.output, null); const output = layer_surface.output;
output.arrangeLayers();
handleKeyboardInteractiveExclusive(output);
server.root.applyPending(); server.root.applyPending();
} }
layer_surface.newly_mapped = false;
} }
/// Focus topmost keyboard-interactivity-exclusive layer surface above normal fn handleKeyboardInteractiveExclusive(output: *Output) void {
/// content, or if none found, focus the surface given as `consider`.
/// Requires a call to Root.applyPending()
fn handleKeyboardInteractiveExclusive(output: *Output, consider: ?*LayerSurface) void {
if (server.lock_manager.state != .unlocked) return; if (server.lock_manager.state != .unlocked) return;
// Find the topmost layer surface (if any) in the top or overlay layers which // Find the topmost layer surface (if any) in the top or overlay layers which
// requests exclusive keyboard interactivity. // requests exclusive keyboard interactivity.
const to_focus = outer: for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| { // If none is found, check for a newly mapped surface in the same layers with
const tree = output.layerSurfaceTree(layer); // on demand keyboard interactivity.
// Iterate in reverse to match rendering order. const to_focus = blk: {
var it = tree.children.iterator(.reverse); for ([_]zwlr.LayerShellV1.Layer{ .overlay, .top }) |layer| {
while (it.next()) |node| { const tree = output.layerSurfaceTree(layer);
assert(node.type == .tree); // Iterate in reverse to match rendering order.
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| { var it = tree.children.iterator(.reverse);
const layer_surface = node_data.data.layer_surface; while (it.next()) |node| {
const wlr_layer_surface = layer_surface.wlr_layer_surface; assert(node.type == .tree);
if (wlr_layer_surface.surface.mapped and if (@as(?*SceneNodeData, @ptrCast(@alignCast(node.data)))) |node_data| {
wlr_layer_surface.current.keyboard_interactive == .exclusive) const layer_surface = node_data.data.layer_surface;
{ const wlr_layer_surface = layer_surface.wlr_layer_surface;
break :outer layer_surface; if (wlr_layer_surface.surface.mapped and
wlr_layer_surface.current.keyboard_interactive == .exclusive)
{
break :blk layer_surface;
}
} }
} }
} }
} else consider; 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, @ptrCast(@alignCast(node.data)))) |node_data| {
const layer_surface = node_data.data.layer_surface;
const wlr_layer_surface = layer_surface.wlr_layer_surface;
if (layer_surface.newly_mapped and
wlr_layer_surface.surface.mapped and
wlr_layer_surface.current.keyboard_interactive == .on_demand)
{
break :blk layer_surface;
}
}
}
}
break :blk null;
};
if (to_focus) |s| { if (to_focus) |s| {
assert(s.wlr_layer_surface.current.keyboard_interactive != .none); assert(s.wlr_layer_surface.current.keyboard_interactive != .none);
} }
var it = server.input_manager.seats.first; var it = server.input_manager.seats.iterator(.forward);
while (it) |node| : (it = node.next) { while (it.next()) |seat| {
const seat = &node.data;
if (seat.focused_output == output) { if (seat.focused_output == output) {
if (to_focus) |s| { if (to_focus) |s| {
// If we found a surface on the output that requires focus, grab the focus of all // If we found a surface on the output that requires focus, grab the focus of all

View File

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

View File

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

View File

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

View File

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

View File

@ -125,10 +125,6 @@ lock_render_state: enum {
lock_surface, lock_surface,
} = .blanked, } = .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. /// 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 /// Pending state will be copied to the inflight state and communicated to clients
@ -171,7 +167,7 @@ previous_tags: u32 = 1 << 0,
attach_mode: ?Config.AttachMode = null, attach_mode: ?Config.AttachMode = null,
/// List of all layouts /// List of all layouts
layouts: std.TailQueue(Layout) = .{}, layouts: wl.list.Head(Layout, .link),
/// The current layout namespace of the output. If null, /// The current layout namespace of the output. If null,
/// config.default_layout_namespace should be used instead. /// config.default_layout_namespace should be used instead.
@ -294,8 +290,11 @@ pub fn create(wlr_output: *wlr.Output) !void {
.height = height, .height = height,
}, },
.status = undefined, .status = undefined,
.layouts = undefined,
}; };
wlr_output.data = @intFromPtr(output); wlr_output.data = output;
output.layouts.init();
output.pending.focus_stack.init(); output.pending.focus_stack.init();
output.pending.wm_stack.init(); output.pending.wm_stack.init();
@ -364,10 +363,14 @@ fn sendLayerConfigures(
var it = tree.children.safeIterator(.forward); var it = tree.children.safeIterator(.forward);
while (it.next()) |node| { while (it.next()) |node| {
assert(node.type == .tree); assert(node.type == .tree);
if (@as(?*SceneNodeData, @ptrFromInt(node.data))) |node_data| { if (@as(?*SceneNodeData, @ptrCast(@alignCast(node.data)))) |node_data| {
const layer_surface = node_data.data.layer_surface; const layer_surface = node_data.data.layer_surface;
if (!layer_surface.wlr_layer_surface.initialized) continue; if (!layer_surface.wlr_layer_surface.surface.mapped and
!layer_surface.wlr_layer_surface.initial_commit)
{
continue;
}
const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0; const exclusive = layer_surface.wlr_layer_surface.current.exclusive_zone > 0;
if (exclusive != (mode == .exclusive)) { if (exclusive != (mode == .exclusive)) {
@ -420,7 +423,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
assert(output.inflight.focus_stack.empty()); assert(output.inflight.focus_stack.empty());
assert(output.inflight.wm_stack.empty()); assert(output.inflight.wm_stack.empty());
assert(output.inflight.layout_demand == null); assert(output.inflight.layout_demand == null);
assert(output.layouts.len == 0); assert(output.layouts.length() == 0);
output.all_link.remove(); output.all_link.remove();
@ -433,7 +436,7 @@ fn handleDestroy(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
if (output.layout_namespace) |namespace| util.gpa.free(namespace); if (output.layout_namespace) |namespace| util.gpa.free(namespace);
output.wlr_output.data = 0; output.wlr_output.data = null;
util.gpa.destroy(output); util.gpa.destroy(output);
@ -456,7 +459,7 @@ fn handleRequestState(listener: *wl.Listener(*wlr.Output.event.RequestState), ev
// TODO double buffer output state changes for frame perfection and cleaner code. // TODO double buffer output state changes for frame perfection and cleaner code.
// Schedule a frame and commit in the frame handler. // Schedule a frame and commit in the frame handler.
// Get rid of this function. // Get rid of this function.
pub fn applyState(output: *Output, state: *wlr.Output.State) error{CommitFailed}!void { pub fn applyState(output: *Output, state: *const wlr.Output.State) error{CommitFailed}!void {
// We need to be precise about this state change to make assertions // We need to be precise about this state change to make assertions
// in updateLockRenderStateOnEnableDisable() possible. // in updateLockRenderStateOnEnableDisable() possible.
@ -480,7 +483,6 @@ pub fn applyState(output: *Output, state: *wlr.Output.State) error{CommitFailed}
fn handleEnableDisable(output: *Output) void { fn handleEnableDisable(output: *Output) void {
output.updateLockRenderStateOnEnableDisable(); output.updateLockRenderStateOnEnableDisable();
output.gamma_dirty = true;
if (output.wlr_output.enabled) { if (output.wlr_output.enabled) {
// Add the output to root.active_outputs and the output layout if it has not // Add the output to root.active_outputs and the output layout if it has not
@ -532,44 +534,21 @@ fn handleFrame(listener: *wl.Listener(*wlr.Output), _: *wlr.Output) void {
// TODO this should probably be retried on failure // TODO this should probably be retried on failure
output.renderAndCommit(scene_output) catch |err| switch (err) { 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}), error.CommitFailed => log.err("output commit failed for {s}", .{output.wlr_output.name}),
}; };
var now: posix.timespec = undefined; var now = posix.clock_gettime(.MONOTONIC) catch @panic("CLOCK_MONOTONIC not supported");
posix.clock_gettime(posix.CLOCK.MONOTONIC, &now) catch @panic("CLOCK_MONOTONIC not supported");
scene_output.sendFrameDone(&now); scene_output.sendFrameDone(&now);
} }
fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void { fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void {
// TODO(wlroots): replace this with wlr_scene_output_needs_frame() if (!scene_output.needsFrame()) return;
if (!output.wlr_output.needs_frame and !output.gamma_dirty and
!scene_output.pending_commit_damage.notEmpty())
{
return;
}
var state = wlr.Output.State.init(); var state = wlr.Output.State.init();
defer state.finish(); defer state.finish();
if (!scene_output.buildState(&state, null)) return error.CommitFailed; if (!scene_output.buildState(&state, null)) return error.CommitFailed;
if (output.gamma_dirty) {
const control = server.root.gamma_control_manager.getControl(output.wlr_output);
if (!wlr.GammaControlV1.apply(control, &state)) return error.OutOfMemory;
// TODO(wlroots): remove this isHeadless() workaround after upstream fix is available
// in a release: https://gitlab.freedesktop.org/wlroots/wlroots/-/merge_requests/4868
if (!output.wlr_output.testState(&state) or output.wlr_output.isHeadless()) {
wlr.GammaControlV1.sendFailedAndDestroy(control);
state.clearGammaLut();
// If the backend does not support gamma LUTs it will reject any
// state with the gamma LUT committed bit set even if the state
// has a null LUT. The wayland backend for example has this behavior.
state.committed.gamma_lut = false;
}
}
if (output.current.fullscreen) |fullscreen| { if (output.current.fullscreen) |fullscreen| {
if (fullscreen.allowTearing()) { if (fullscreen.allowTearing()) {
state.tearing_page_flip = true; state.tearing_page_flip = true;
@ -584,8 +563,6 @@ fn renderAndCommit(output: *Output, scene_output: *wlr.SceneOutput) !void {
if (!output.wlr_output.commitState(&state)) return error.CommitFailed; if (!output.wlr_output.commitState(&state)) return error.CommitFailed;
output.gamma_dirty = false;
if (server.lock_manager.state == .locked or if (server.lock_manager.state == .locked or
(server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or (server.lock_manager.state == .waiting_for_lock_surfaces and output.locked_content.node.enabled) or
server.lock_manager.state == .waiting_for_blank) server.lock_manager.state == .waiting_for_blank)
@ -649,7 +626,7 @@ fn handlePresent(
} }
fn setTitle(output: Output) void { fn setTitle(output: Output) void {
const title = fmt.allocPrintZ(util.gpa, "river - {s}", .{output.wlr_output.name}) catch return; const title = fmt.allocPrintSentinel(util.gpa, "river - {s}", .{output.wlr_output.name}, 0) catch return;
defer util.gpa.free(title); defer util.gpa.free(title);
if (output.wlr_output.isWl()) { if (output.wlr_output.isWl()) {
output.wlr_output.wlSetTitle(title); output.wlr_output.wlSetTitle(title);
@ -661,9 +638,9 @@ fn setTitle(output: Output) void {
pub fn handleLayoutNamespaceChange(output: *Output) void { pub fn handleLayoutNamespaceChange(output: *Output) void {
// The user changed the layout namespace of this output. Try to find a // The user changed the layout namespace of this output. Try to find a
// matching layout. // matching layout.
var it = output.layouts.first; var it = output.layouts.iterator(.forward);
output.layout = while (it) |node| : (it = node.next) { output.layout = while (it.next()) |layout| {
if (mem.eql(u8, output.layoutNamespace(), node.data.namespace)) break &node.data; if (mem.eql(u8, output.layoutNamespace(), layout.namespace)) break layout;
} else null; } else null;
server.root.applyPending(); server.root.applyPending();
} }

View File

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

View File

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

View File

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

View File

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

View File

@ -33,8 +33,19 @@ const View = @import("View.zig");
seat: *Seat, seat: *Seat,
seat_status_v1: *zriver.SeatStatusV1, seat_status_v1: *zriver.SeatStatusV1,
pub fn init(seat_status: *SeatStatus, seat: *Seat, seat_status_v1: *zriver.SeatStatusV1) void { link: wl.list.Link,
seat_status.* = .{ .seat = seat, .seat_status_v1 = seat_status_v1 };
pub fn create(seat: *Seat, seat_status_v1: *zriver.SeatStatusV1) !void {
const seat_status = try util.gpa.create(SeatStatus);
errdefer util.gpa.destroy(seat_status);
seat_status.* = .{
.seat = seat,
.seat_status_v1 = seat_status_v1,
.link = undefined,
};
seat.status_trackers.append(seat_status);
errdefer comptime unreachable;
seat_status_v1.setHandler(*SeatStatus, handleRequest, handleDestroy, seat_status); seat_status_v1.setHandler(*SeatStatus, handleRequest, handleDestroy, seat_status);
@ -51,9 +62,8 @@ fn handleRequest(seat_status_v1: *zriver.SeatStatusV1, request: zriver.SeatStatu
} }
fn handleDestroy(_: *zriver.SeatStatusV1, seat_status: *SeatStatus) void { fn handleDestroy(_: *zriver.SeatStatusV1, seat_status: *SeatStatus) void {
const node: *std.SinglyLinkedList(SeatStatus).Node = @fieldParentPtr("data", seat_status); seat_status.link.remove();
seat_status.seat.status_trackers.remove(node); util.gpa.destroy(seat_status);
util.gpa.destroy(node);
} }
pub fn sendOutput(seat_status: SeatStatus, output: *Output, state: enum { focused, unfocused }) void { pub fn sendOutput(seat_status: SeatStatus, output: *Output, state: enum { focused, unfocused }) void {
@ -71,8 +81,12 @@ pub fn sendFocusedView(seat_status: SeatStatus) void {
if (seat_status.seat_status_v1.getVersion() >= 4) { if (seat_status.seat_status_v1.getVersion() >= 4) {
switch (seat_status.seat.focused) { switch (seat_status.seat.focused) {
.view => |view| { .view => |view| {
//assert(view.inflight.tags == view.current.tags); if (view.current.tags != 0) {
seat_status.seat_status_v1.sendFocusedView(view.getTitle() orelse "", view.current.tags); // A view can't be on no tags, so we need to wait for the
// layout to update. There is probably a better way to do
// this, but this way seems to work.
seat_status.seat_status_v1.sendFocusedView(view.getTitle() orelse "", view.current.tags);
}
}, },
else => seat_status.seat_status_v1.sendFocusedView("", 0), else => seat_status.seat_status_v1.sendFocusedView("", 0),
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -100,7 +100,7 @@ pub fn configure(xwayland_view: XwaylandView) bool {
xwayland_view.xwayland_surface.height == inflight.box.height and xwayland_view.xwayland_surface.height == inflight.box.height and
(inflight.focus != 0) == (current.focus != 0) and (inflight.focus != 0) == (current.focus != 0) and
(output.inflight.fullscreen == xwayland_view.view) == (output.inflight.fullscreen == xwayland_view.view) ==
(current.output != null and current.output.?.current.fullscreen == xwayland_view.view)) (current.output != null and current.output.?.current.fullscreen == xwayland_view.view))
{ {
return false; return false;
} }
@ -164,7 +164,7 @@ pub fn handleMap(listener: *wl.Listener(void)) void {
const xwayland_surface = xwayland_view.xwayland_surface; const xwayland_surface = xwayland_view.xwayland_surface;
const surface = xwayland_surface.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 // Add listeners that are only active while mapped
xwayland_surface.events.set_title.add(&xwayland_view.set_title); xwayland_surface.events.set_title.add(&xwayland_view.set_title);
@ -215,11 +215,12 @@ pub fn handleMap(listener: *wl.Listener(void)) void {
fn handleUnmap(listener: *wl.Listener(void)) void { fn handleUnmap(listener: *wl.Listener(void)) void {
const xwayland_view: *XwaylandView = @fieldParentPtr("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 // Remove listeners that are only active while mapped
xwayland_view.set_title.link.remove(); xwayland_view.set_title.link.remove();
xwayland_view.set_class.link.remove(); xwayland_view.set_class.link.remove();
xwayland_view.set_decorations.link.remove();
xwayland_view.request_fullscreen.link.remove(); xwayland_view.request_fullscreen.link.remove();
xwayland_view.request_minimize.link.remove(); xwayland_view.request_minimize.link.remove();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -78,12 +78,7 @@ fn getTarget(seat: *Seat, direction_str: []const u8, target_mode: TargetMode) !?
if (seat.focused.view.pending.fullscreen) return null; if (seat.focused.view.pending.fullscreen) return null;
if (target_mode == .skip_float and seat.focused.view.pending.float) return null; if (target_mode == .skip_float and seat.focused.view.pending.float) return null;
const output = seat.focused_output orelse return null; const output = seat.focused_output orelse return null;
if (seat.focused.view.pending.output != output) return null;
// If no currently view is focused, focus the first in the stack.
if (seat.focused != .view) {
var it = output.pending.wm_stack.iterator(.forward);
return it.next();
}
// Logical direction, based on the view stack. // Logical direction, based on the view stack.
if (std.meta.stringToEnum(Direction, direction_str)) |direction| { if (std.meta.stringToEnum(Direction, direction_str)) |direction| {

View File

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

View File

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

View File

@ -23,6 +23,11 @@ const util = @import("util.zig");
const View = @import("View.zig"); const View = @import("View.zig");
pub const RuleGlobs = struct {
app_id_glob: []const u8,
title_glob: []const u8,
};
pub const MaxGlobLen = struct { pub const MaxGlobLen = struct {
app_id: usize, app_id: usize,
title: 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| { for (list.rules.items, 0..) |existing, i| {
if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and if (mem.eql(u8, rule.app_id_glob, existing.app_id_glob) and
mem.eql(u8, rule.title_glob, existing.title_glob)) mem.eql(u8, rule.title_glob, existing.title_glob))

View File

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

View File

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