detached 089fa12

Merge pull request #3 from bnema/feat/session-lock

feat(protocol): add ext-session-lock-v1 client binding
commit
089fa128d117868d235c3676ce4e6edcb5207e74
author
bnema · · 2026-09-30 19:50 UTC
committer
GitHub · · 2026-09-30 19:50 UTC
merge of
9c230c3 + ab8528e · diff against the first parent
signature
GPG UnverifiedB5690EEEBB952194 The key is unknown
refs
tag: v0.5.0
6 files · +879 -1
M README.md +1 -1
@@ -28,7 +28,7 @@ Packages under `protocol/` cover:
2828 | Presentation and color | `presentation`, `tearingcontrol`, `fifo`, `committiming`, `contenttype`, `alphamodifier`, `colormanagement`, `colorrepresentation`, `drmlease` |
2929 | Input | `cursorshape`, `tablet`, `textinput`, `relativepointer`, `pointerconstraints`, `pointerwarp`, `shortcutsinhibit`, `virtualkeyboard`, `inputmethod` |
3030 | Clipboard | Core data-device, `primaryselection`, `datacontrol` (ext-data-control) |
31-| Desktop and outputs | `layershell`, `xdgoutput`, `outputmanagement`, `outputpower`, `workspace`, `foreigntoplevel` (wlr), `extforeigntoplevel`, `kdeserverdecoration` |
31+| Desktop and outputs | `layershell`, `xdgoutput`, `outputmanagement`, `outputpower`, `workspace`, `foreigntoplevel` (wlr), `extforeigntoplevel`, `extsessionlock`, `kdeserverdecoration` |
3232 | Idle | `idleinhibit`, `idlenotify` |
3333 | Capture | `screencopy` (wlr), `imagecapturesource`, `imagecopycapture` |
3434
@@ -28,7 +28,7 @@ Packages under `protocol/` cover:
28 | Presentation and color | `presentation`, `tearingcontrol`, `fifo`, `committiming`, `contenttype`, `alphamodifier`, `colormanagement`, `colorrepresentation`, `drmlease` |28 | Presentation and color | `presentation`, `tearingcontrol`, `fifo`, `committiming`, `contenttype`, `alphamodifier`, `colormanagement`, `colorrepresentation`, `drmlease` |
29 | Input | `cursorshape`, `tablet`, `textinput`, `relativepointer`, `pointerconstraints`, `pointerwarp`, `shortcutsinhibit`, `virtualkeyboard`, `inputmethod` |29 | Input | `cursorshape`, `tablet`, `textinput`, `relativepointer`, `pointerconstraints`, `pointerwarp`, `shortcutsinhibit`, `virtualkeyboard`, `inputmethod` |
30 | Clipboard | Core data-device, `primaryselection`, `datacontrol` (ext-data-control) |30 | Clipboard | Core data-device, `primaryselection`, `datacontrol` (ext-data-control) |
31-| Desktop and outputs | `layershell`, `xdgoutput`, `outputmanagement`, `outputpower`, `workspace`, `foreigntoplevel` (wlr), `extforeigntoplevel`, `kdeserverdecoration` |31+| Desktop and outputs | `layershell`, `xdgoutput`, `outputmanagement`, `outputpower`, `workspace`, `foreigntoplevel` (wlr), `extforeigntoplevel`, `extsessionlock`, `kdeserverdecoration` |
32 | Idle | `idleinhibit`, `idlenotify` |32 | Idle | `idleinhibit`, `idlenotify` |
33 | Capture | `screencopy` (wlr), `imagecapturesource`, `imagecopycapture` |33 | Capture | `screencopy` (wlr), `imagecapturesource`, `imagecopycapture` |
34 34
M protocol/SOURCE.md +1 -0
@@ -36,6 +36,7 @@ SHA-256 (of the vendored XML bytes):
3636 | `staging/ext-idle-notify/ext-idle-notify-v1.xml` | `idlenotify/ext-idle-notify-v1.xml` | `e56a9c22684e6b46655f7221b798328e304c1efc8f63f01241a1cf8c070f4c30` |
3737 | `staging/ext-image-capture-source/ext-image-capture-source-v1.xml` | `imagecapturesource/ext-image-capture-source-v1.xml` | `4ef41d15e4cdb9f550158391358ceec724a6708b43b7efedec03121a6bb8458d` |
3838 | `staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml` | `imagecopycapture/ext-image-copy-capture-v1.xml` | `41a446653f788fabb404cab3168c0bd667c1ff4b54f1f0bb1e18810a1f47d73f` |
39+| `staging/ext-session-lock/ext-session-lock-v1.xml` | `extsessionlock/ext-session-lock-v1.xml` | `a05df7d95c5e523e457037b3a149484e8064828cda66971f3c7caeb87d597a81` |
3940 | `unstable/pointer-constraints/pointer-constraints-unstable-v1.xml` | `pointerconstraints/pointer-constraints-unstable-v1.xml` | `f980fac900ba1dcfbbe97f588fc17b893926bd2b57624563653a1bfe4d035948` |
4041 | `staging/pointer-warp/pointer-warp-v1.xml` | `pointerwarp/pointer-warp-v1.xml` | `1389e89c68c6f6d231fd2dcda57fa9c75c5230d0ac1deffa8d80a7648e197e66` |
4142 | `stable/presentation-time/presentation-time.xml` | `presentation/presentation-time.xml` | `dffac93bcb2bb1d8c385e72b8a8c2c0d4d79a336866322f3ba886dce2b27b1e2` |
@@ -36,6 +36,7 @@ SHA-256 (of the vendored XML bytes):
36 | `staging/ext-idle-notify/ext-idle-notify-v1.xml` | `idlenotify/ext-idle-notify-v1.xml` | `e56a9c22684e6b46655f7221b798328e304c1efc8f63f01241a1cf8c070f4c30` |36 | `staging/ext-idle-notify/ext-idle-notify-v1.xml` | `idlenotify/ext-idle-notify-v1.xml` | `e56a9c22684e6b46655f7221b798328e304c1efc8f63f01241a1cf8c070f4c30` |
37 | `staging/ext-image-capture-source/ext-image-capture-source-v1.xml` | `imagecapturesource/ext-image-capture-source-v1.xml` | `4ef41d15e4cdb9f550158391358ceec724a6708b43b7efedec03121a6bb8458d` |37 | `staging/ext-image-capture-source/ext-image-capture-source-v1.xml` | `imagecapturesource/ext-image-capture-source-v1.xml` | `4ef41d15e4cdb9f550158391358ceec724a6708b43b7efedec03121a6bb8458d` |
38 | `staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml` | `imagecopycapture/ext-image-copy-capture-v1.xml` | `41a446653f788fabb404cab3168c0bd667c1ff4b54f1f0bb1e18810a1f47d73f` |38 | `staging/ext-image-copy-capture/ext-image-copy-capture-v1.xml` | `imagecopycapture/ext-image-copy-capture-v1.xml` | `41a446653f788fabb404cab3168c0bd667c1ff4b54f1f0bb1e18810a1f47d73f` |
39+| `staging/ext-session-lock/ext-session-lock-v1.xml` | `extsessionlock/ext-session-lock-v1.xml` | `a05df7d95c5e523e457037b3a149484e8064828cda66971f3c7caeb87d597a81` |
39 | `unstable/pointer-constraints/pointer-constraints-unstable-v1.xml` | `pointerconstraints/pointer-constraints-unstable-v1.xml` | `f980fac900ba1dcfbbe97f588fc17b893926bd2b57624563653a1bfe4d035948` |40 | `unstable/pointer-constraints/pointer-constraints-unstable-v1.xml` | `pointerconstraints/pointer-constraints-unstable-v1.xml` | `f980fac900ba1dcfbbe97f588fc17b893926bd2b57624563653a1bfe4d035948` |
40 | `staging/pointer-warp/pointer-warp-v1.xml` | `pointerwarp/pointer-warp-v1.xml` | `1389e89c68c6f6d231fd2dcda57fa9c75c5230d0ac1deffa8d80a7648e197e66` |41 | `staging/pointer-warp/pointer-warp-v1.xml` | `pointerwarp/pointer-warp-v1.xml` | `1389e89c68c6f6d231fd2dcda57fa9c75c5230d0ac1deffa8d80a7648e197e66` |
41 | `stable/presentation-time/presentation-time.xml` | `presentation/presentation-time.xml` | `dffac93bcb2bb1d8c385e72b8a8c2c0d4d79a336866322f3ba886dce2b27b1e2` |42 | `stable/presentation-time/presentation-time.xml` | `presentation/presentation-time.xml` | `dffac93bcb2bb1d8c385e72b8a8c2c0d4d79a336866322f3ba886dce2b27b1e2` |
A protocol/extsessionlock/ext-session-lock-v1.xml +328 -0
@@ -0,0 +1,328 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<protocol name="ext_session_lock_v1">
3+ <copyright>
4+ Copyright 2021 Isaac Freund
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a
7+ copy of this software and associated documentation files (the "Software"),
8+ to deal in the Software without restriction, including without limitation
9+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+ and/or sell copies of the Software, and to permit persons to whom the
11+ Software is furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in
14+ all copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ THE SOFTWARE.
23+ </copyright>
24+
25+ <description summary="secure session locking with arbitrary graphics">
26+ This protocol allows for a privileged Wayland client to lock the session
27+ and display arbitrary graphics while the session is locked.
28+
29+ The compositor may choose to restrict this protocol to a special client
30+ launched by the compositor itself or expose it to all privileged clients,
31+ this is compositor policy.
32+
33+ The client is responsible for performing authentication and informing the
34+ compositor when the session should be unlocked. If the client dies while
35+ the session is locked the session remains locked, possibly permanently
36+ depending on compositor policy.
37+
38+ The key words "must", "must not", "required", "shall", "shall not",
39+ "should", "should not", "recommended", "may", and "optional" in this
40+ document are to be interpreted as described in IETF RFC 2119.
41+
42+ Warning! The protocol described in this file is currently in the
43+ testing phase. Backward compatible changes may be added together with
44+ the corresponding interface version bump. Backward incompatible changes
45+ can only be done by creating a new major version of the extension.
46+ </description>
47+
48+ <interface name="ext_session_lock_manager_v1" version="1">
49+ <description summary="used to lock the session">
50+ This interface is used to request that the session be locked.
51+ </description>
52+
53+ <request name="destroy" type="destructor">
54+ <description summary="destroy the session lock manager object">
55+ This informs the compositor that the session lock manager object will
56+ no longer be used. Existing objects created through this interface
57+ remain valid.
58+ </description>
59+ </request>
60+
61+ <request name="lock">
62+ <description summary="attempt to lock the session">
63+ This request creates a session lock and asks the compositor to lock the
64+ session. The compositor will send either the ext_session_lock_v1.locked
65+ or ext_session_lock_v1.finished event on the created object in
66+ response to this request.
67+ </description>
68+ <arg name="id" type="new_id" interface="ext_session_lock_v1"/>
69+ </request>
70+ </interface>
71+
72+ <interface name="ext_session_lock_v1" version="1">
73+ <description summary="manage lock state and create lock surfaces">
74+ In response to the creation of this object the compositor must send
75+ either the locked or finished event.
76+
77+ The locked event indicates that the session is locked. This means
78+ that the compositor must stop rendering and providing input to normal
79+ clients. Instead the compositor must blank all outputs with an opaque
80+ color such that their normal content is fully hidden.
81+
82+ The only surfaces that should be rendered while the session is locked
83+ are the lock surfaces created through this interface and optionally,
84+ at the compositor's discretion, special privileged surfaces such as
85+ input methods or portions of desktop shell UIs.
86+
87+ The locked event must not be sent until a new "locked" frame (either
88+ from a session lock surface or the compositor blanking the output) has
89+ been presented on all outputs and no security sensitive normal/unlocked
90+ content is possibly visible.
91+
92+ The finished event should be sent immediately on creation of this
93+ object if the compositor decides that the locked event will not be sent.
94+
95+ The compositor may wait for the client to create and render session lock
96+ surfaces before sending the locked event to avoid displaying intermediate
97+ blank frames. However, it must impose a reasonable time limit if
98+ waiting and send the locked event as soon as the hard requirements
99+ described above can be met if the time limit expires. Clients should
100+ immediately create lock surfaces for all outputs on creation of this
101+ object to make this possible.
102+
103+ This behavior of the locked event is required in order to prevent
104+ possible race conditions with clients that wish to suspend the system
105+ or similar after locking the session. Without these semantics, clients
106+ triggering a suspend after receiving the locked event would race with
107+ the first "locked" frame being presented and normal/unlocked frames
108+ might be briefly visible as the system is resumed if the suspend
109+ operation wins the race.
110+
111+ If the client dies while the session is locked, the compositor must not
112+ unlock the session in response. It is acceptable for the session to be
113+ permanently locked if this happens. The compositor may choose to continue
114+ to display the lock surfaces the client had mapped before it died or
115+ alternatively fall back to a solid color, this is compositor policy.
116+
117+ Compositors may also allow a secure way to recover the session, the
118+ details of this are compositor policy. Compositors may allow a new
119+ client to create a ext_session_lock_v1 object and take responsibility
120+ for unlocking the session, they may even start a new lock client
121+ instance automatically.
122+ </description>
123+
124+ <enum name="error">
125+ <entry name="invalid_destroy" value="0"
126+ summary="attempted to destroy session lock while locked"/>
127+ <entry name="invalid_unlock" value="1"
128+ summary="unlock requested but locked event was never sent"/>
129+ <entry name="role" value="2"
130+ summary="given wl_surface already has a role"/>
131+ <entry name="duplicate_output" value="3"
132+ summary="given output already has a lock surface"/>
133+ <entry name="already_constructed" value="4"
134+ summary="given wl_surface has a buffer attached or committed"/>
135+ </enum>
136+
137+ <request name="destroy" type="destructor">
138+ <description summary="destroy the session lock">
139+ This informs the compositor that the lock object will no longer be
140+ used. Existing objects created through this interface remain valid.
141+
142+ After this request is made, lock surfaces created through this object
143+ should be destroyed by the client as they will no longer be used by
144+ the compositor.
145+
146+ It is a protocol error to make this request if the locked event was
147+ sent, the unlock_and_destroy request must be used instead.
148+ </description>
149+ </request>
150+
151+ <event name="locked">
152+ <description summary="session successfully locked">
153+ This client is now responsible for displaying graphics while the
154+ session is locked and deciding when to unlock the session.
155+
156+ The locked event must not be sent until a new "locked" frame has been
157+ presented on all outputs and no security sensitive normal/unlocked
158+ content is possibly visible.
159+
160+ If this event is sent, making the destroy request is a protocol error,
161+ the lock object must be destroyed using the unlock_and_destroy request.
162+ </description>
163+ </event>
164+
165+ <event name="finished">
166+ <description summary="the session lock object should be destroyed">
167+ The compositor has decided that the session lock should be destroyed
168+ as it will no longer be used by the compositor. Exactly when this
169+ event is sent is compositor policy, but it must never be sent more
170+ than once for a given session lock object.
171+
172+ This might be sent because there is already another ext_session_lock_v1
173+ object held by a client, or the compositor has decided to deny the
174+ request to lock the session for some other reason. This might also
175+ be sent because the compositor implements some alternative, secure
176+ way to authenticate and unlock the session.
177+
178+ The finished event should be sent immediately on creation of this
179+ object if the compositor decides that the locked event will not
180+ be sent.
181+
182+ If the locked event is sent on creation of this object the finished
183+ event may still be sent at some later time in this object's
184+ lifetime. This is compositor policy.
185+
186+ Upon receiving this event, the client should make either the destroy
187+ request or the unlock_and_destroy request, depending on whether or
188+ not the locked event was received on this object.
189+ </description>
190+ </event>
191+
192+ <request name="get_lock_surface">
193+ <description summary="create a lock surface for a given output">
194+ The client is expected to create lock surfaces for all outputs
195+ currently present and any new outputs as they are advertised. These
196+ won't be displayed by the compositor unless the lock is successful
197+ and the locked event is sent.
198+
199+ Providing a wl_surface which already has a role or already has a buffer
200+ attached or committed is a protocol error, as is attaching/committing
201+ a buffer before the first ext_session_lock_surface_v1.configure event.
202+
203+ Attempting to create more than one lock surface for a given output
204+ is a duplicate_output protocol error.
205+ </description>
206+ <arg name="id" type="new_id" interface="ext_session_lock_surface_v1"/>
207+ <arg name="surface" type="object" interface="wl_surface"/>
208+ <arg name="output" type="object" interface="wl_output"/>
209+ </request>
210+
211+ <request name="unlock_and_destroy" type="destructor">
212+ <description summary="unlock the session, destroying the object">
213+ This request indicates that the session should be unlocked, for
214+ example because the user has entered their password and it has been
215+ verified by the client.
216+
217+ This request also informs the compositor that the lock object will
218+ no longer be used and should be destroyed. Existing objects created
219+ through this interface remain valid.
220+
221+ After this request is made, lock surfaces created through this object
222+ should be destroyed by the client as they will no longer be used by
223+ the compositor.
224+
225+ It is a protocol error to make this request if the locked event has
226+ not been sent. In that case, the lock object must be destroyed using
227+ the destroy request.
228+
229+ Note that a correct client that wishes to exit directly after unlocking
230+ the session must use the wl_display.sync request to ensure the server
231+ receives and processes the unlock_and_destroy request. Otherwise
232+ there is no guarantee that the server has unlocked the session due
233+ to the asynchronous nature of the Wayland protocol. For example,
234+ the server might terminate the client with a protocol error before
235+ it processes the unlock_and_destroy request.
236+ </description>
237+ </request>
238+ </interface>
239+
240+ <interface name="ext_session_lock_surface_v1" version="1">
241+ <description summary="a surface displayed while the session is locked">
242+ The client may use lock surfaces to display a screensaver, render a
243+ dialog to enter a password and unlock the session, or however else it
244+ sees fit.
245+
246+ On binding this interface the compositor will immediately send the
247+ first configure event. After making the ack_configure request in
248+ response to this event the client should attach and commit the first
249+ buffer. Committing the surface before acking the first configure is a
250+ protocol error. Committing the surface with a null buffer at any time
251+ is a protocol error.
252+
253+ The compositor is free to handle keyboard/pointer focus for lock
254+ surfaces however it chooses. A reasonable way to do this would be to
255+ give the first lock surface created keyboard focus and change keyboard
256+ focus if the user clicks on other surfaces.
257+ </description>
258+
259+ <enum name="error">
260+ <entry name="commit_before_first_ack" value="0"
261+ summary="surface committed before first ack_configure request"/>
262+ <entry name="null_buffer" value="1"
263+ summary="surface committed with a null buffer"/>
264+ <entry name="dimensions_mismatch" value="2"
265+ summary="failed to match ack'd width/height"/>
266+ <entry name="invalid_serial" value="3"
267+ summary="serial provided in ack_configure is invalid"/>
268+ </enum>
269+
270+ <request name="destroy" type="destructor">
271+ <description summary="destroy the lock surface object">
272+ This informs the compositor that the lock surface object will no
273+ longer be used.
274+
275+ It is recommended for a lock client to destroy lock surfaces if
276+ their corresponding wl_output global is removed.
277+
278+ If a lock surface on an active output is destroyed before the
279+ ext_session_lock_v1.unlock_and_destroy event is sent, the compositor
280+ must fall back to rendering a solid color.
281+ </description>
282+ </request>
283+
284+ <request name="ack_configure">
285+ <description summary="ack a configure event">
286+ When a configure event is received, if a client commits the surface
287+ in response to the configure event, then the client must make an
288+ ack_configure request sometime before the commit request, passing
289+ along the serial of the configure event.
290+
291+ If the client receives multiple configure events before it can
292+ respond to one, it only has to ack the last configure event.
293+
294+ A client is not required to commit immediately after sending an
295+ ack_configure request - it may even ack_configure several times
296+ before its next surface commit.
297+
298+ A client may send multiple ack_configure requests before committing,
299+ but only the last request sent before a commit indicates which
300+ configure event the client really is responding to.
301+
302+ Sending an ack_configure request consumes the configure event
303+ referenced by the given serial, as well as all older configure events
304+ sent on this object.
305+
306+ It is a protocol error to issue multiple ack_configure requests
307+ referencing the same configure event or to issue an ack_configure
308+ request referencing a configure event older than the last configure
309+ event acked for a given lock surface.
310+ </description>
311+ <arg name="serial" type="uint" summary="serial from the configure event"/>
312+ </request>
313+
314+ <event name="configure">
315+ <description summary="the client should resize its surface">
316+ This event is sent once on binding the interface and may be sent again
317+ at the compositor's discretion, for example if output geometry changes.
318+
319+ The width and height are in surface-local coordinates and are exact
320+ requirements. Failing to match these surface dimensions in the next
321+ commit after acking a configure is a protocol error.
322+ </description>
323+ <arg name="serial" type="uint" summary="serial for use in ack_configure"/>
324+ <arg name="width" type="uint"/>
325+ <arg name="height" type="uint"/>
326+ </event>
327+ </interface>
328+</protocol>
@@ -0,0 +1,328 @@
1+<?xml version="1.0" encoding="UTF-8"?>
2+<protocol name="ext_session_lock_v1">
3+ <copyright>
4+ Copyright 2021 Isaac Freund
5+
6+ Permission is hereby granted, free of charge, to any person obtaining a
7+ copy of this software and associated documentation files (the "Software"),
8+ to deal in the Software without restriction, including without limitation
9+ the rights to use, copy, modify, merge, publish, distribute, sublicense,
10+ and/or sell copies of the Software, and to permit persons to whom the
11+ Software is furnished to do so, subject to the following conditions:
12+
13+ The above copyright notice and this permission notice shall be included in
14+ all copies or substantial portions of the Software.
15+
16+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19+ THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22+ THE SOFTWARE.
23+ </copyright>
24+
25+ <description summary="secure session locking with arbitrary graphics">
26+ This protocol allows for a privileged Wayland client to lock the session
27+ and display arbitrary graphics while the session is locked.
28+
29+ The compositor may choose to restrict this protocol to a special client
30+ launched by the compositor itself or expose it to all privileged clients,
31+ this is compositor policy.
32+
33+ The client is responsible for performing authentication and informing the
34+ compositor when the session should be unlocked. If the client dies while
35+ the session is locked the session remains locked, possibly permanently
36+ depending on compositor policy.
37+
38+ The key words "must", "must not", "required", "shall", "shall not",
39+ "should", "should not", "recommended", "may", and "optional" in this
40+ document are to be interpreted as described in IETF RFC 2119.
41+
42+ Warning! The protocol described in this file is currently in the
43+ testing phase. Backward compatible changes may be added together with
44+ the corresponding interface version bump. Backward incompatible changes
45+ can only be done by creating a new major version of the extension.
46+ </description>
47+
48+ <interface name="ext_session_lock_manager_v1" version="1">
49+ <description summary="used to lock the session">
50+ This interface is used to request that the session be locked.
51+ </description>
52+
53+ <request name="destroy" type="destructor">
54+ <description summary="destroy the session lock manager object">
55+ This informs the compositor that the session lock manager object will
56+ no longer be used. Existing objects created through this interface
57+ remain valid.
58+ </description>
59+ </request>
60+
61+ <request name="lock">
62+ <description summary="attempt to lock the session">
63+ This request creates a session lock and asks the compositor to lock the
64+ session. The compositor will send either the ext_session_lock_v1.locked
65+ or ext_session_lock_v1.finished event on the created object in
66+ response to this request.
67+ </description>
68+ <arg name="id" type="new_id" interface="ext_session_lock_v1"/>
69+ </request>
70+ </interface>
71+
72+ <interface name="ext_session_lock_v1" version="1">
73+ <description summary="manage lock state and create lock surfaces">
74+ In response to the creation of this object the compositor must send
75+ either the locked or finished event.
76+
77+ The locked event indicates that the session is locked. This means
78+ that the compositor must stop rendering and providing input to normal
79+ clients. Instead the compositor must blank all outputs with an opaque
80+ color such that their normal content is fully hidden.
81+
82+ The only surfaces that should be rendered while the session is locked
83+ are the lock surfaces created through this interface and optionally,
84+ at the compositor's discretion, special privileged surfaces such as
85+ input methods or portions of desktop shell UIs.
86+
87+ The locked event must not be sent until a new "locked" frame (either
88+ from a session lock surface or the compositor blanking the output) has
89+ been presented on all outputs and no security sensitive normal/unlocked
90+ content is possibly visible.
91+
92+ The finished event should be sent immediately on creation of this
93+ object if the compositor decides that the locked event will not be sent.
94+
95+ The compositor may wait for the client to create and render session lock
96+ surfaces before sending the locked event to avoid displaying intermediate
97+ blank frames. However, it must impose a reasonable time limit if
98+ waiting and send the locked event as soon as the hard requirements
99+ described above can be met if the time limit expires. Clients should
100+ immediately create lock surfaces for all outputs on creation of this
101+ object to make this possible.
102+
103+ This behavior of the locked event is required in order to prevent
104+ possible race conditions with clients that wish to suspend the system
105+ or similar after locking the session. Without these semantics, clients
106+ triggering a suspend after receiving the locked event would race with
107+ the first "locked" frame being presented and normal/unlocked frames
108+ might be briefly visible as the system is resumed if the suspend
109+ operation wins the race.
110+
111+ If the client dies while the session is locked, the compositor must not
112+ unlock the session in response. It is acceptable for the session to be
113+ permanently locked if this happens. The compositor may choose to continue
114+ to display the lock surfaces the client had mapped before it died or
115+ alternatively fall back to a solid color, this is compositor policy.
116+
117+ Compositors may also allow a secure way to recover the session, the
118+ details of this are compositor policy. Compositors may allow a new
119+ client to create a ext_session_lock_v1 object and take responsibility
120+ for unlocking the session, they may even start a new lock client
121+ instance automatically.
122+ </description>
123+
124+ <enum name="error">
125+ <entry name="invalid_destroy" value="0"
126+ summary="attempted to destroy session lock while locked"/>
127+ <entry name="invalid_unlock" value="1"
128+ summary="unlock requested but locked event was never sent"/>
129+ <entry name="role" value="2"
130+ summary="given wl_surface already has a role"/>
131+ <entry name="duplicate_output" value="3"
132+ summary="given output already has a lock surface"/>
133+ <entry name="already_constructed" value="4"
134+ summary="given wl_surface has a buffer attached or committed"/>
135+ </enum>
136+
137+ <request name="destroy" type="destructor">
138+ <description summary="destroy the session lock">
139+ This informs the compositor that the lock object will no longer be
140+ used. Existing objects created through this interface remain valid.
141+
142+ After this request is made, lock surfaces created through this object
143+ should be destroyed by the client as they will no longer be used by
144+ the compositor.
145+
146+ It is a protocol error to make this request if the locked event was
147+ sent, the unlock_and_destroy request must be used instead.
148+ </description>
149+ </request>
150+
151+ <event name="locked">
152+ <description summary="session successfully locked">
153+ This client is now responsible for displaying graphics while the
154+ session is locked and deciding when to unlock the session.
155+
156+ The locked event must not be sent until a new "locked" frame has been
157+ presented on all outputs and no security sensitive normal/unlocked
158+ content is possibly visible.
159+
160+ If this event is sent, making the destroy request is a protocol error,
161+ the lock object must be destroyed using the unlock_and_destroy request.
162+ </description>
163+ </event>
164+
165+ <event name="finished">
166+ <description summary="the session lock object should be destroyed">
167+ The compositor has decided that the session lock should be destroyed
168+ as it will no longer be used by the compositor. Exactly when this
169+ event is sent is compositor policy, but it must never be sent more
170+ than once for a given session lock object.
171+
172+ This might be sent because there is already another ext_session_lock_v1
173+ object held by a client, or the compositor has decided to deny the
174+ request to lock the session for some other reason. This might also
175+ be sent because the compositor implements some alternative, secure
176+ way to authenticate and unlock the session.
177+
178+ The finished event should be sent immediately on creation of this
179+ object if the compositor decides that the locked event will not
180+ be sent.
181+
182+ If the locked event is sent on creation of this object the finished
183+ event may still be sent at some later time in this object's
184+ lifetime. This is compositor policy.
185+
186+ Upon receiving this event, the client should make either the destroy
187+ request or the unlock_and_destroy request, depending on whether or
188+ not the locked event was received on this object.
189+ </description>
190+ </event>
191+
192+ <request name="get_lock_surface">
193+ <description summary="create a lock surface for a given output">
194+ The client is expected to create lock surfaces for all outputs
195+ currently present and any new outputs as they are advertised. These
196+ won't be displayed by the compositor unless the lock is successful
197+ and the locked event is sent.
198+
199+ Providing a wl_surface which already has a role or already has a buffer
200+ attached or committed is a protocol error, as is attaching/committing
201+ a buffer before the first ext_session_lock_surface_v1.configure event.
202+
203+ Attempting to create more than one lock surface for a given output
204+ is a duplicate_output protocol error.
205+ </description>
206+ <arg name="id" type="new_id" interface="ext_session_lock_surface_v1"/>
207+ <arg name="surface" type="object" interface="wl_surface"/>
208+ <arg name="output" type="object" interface="wl_output"/>
209+ </request>
210+
211+ <request name="unlock_and_destroy" type="destructor">
212+ <description summary="unlock the session, destroying the object">
213+ This request indicates that the session should be unlocked, for
214+ example because the user has entered their password and it has been
215+ verified by the client.
216+
217+ This request also informs the compositor that the lock object will
218+ no longer be used and should be destroyed. Existing objects created
219+ through this interface remain valid.
220+
221+ After this request is made, lock surfaces created through this object
222+ should be destroyed by the client as they will no longer be used by
223+ the compositor.
224+
225+ It is a protocol error to make this request if the locked event has
226+ not been sent. In that case, the lock object must be destroyed using
227+ the destroy request.
228+
229+ Note that a correct client that wishes to exit directly after unlocking
230+ the session must use the wl_display.sync request to ensure the server
231+ receives and processes the unlock_and_destroy request. Otherwise
232+ there is no guarantee that the server has unlocked the session due
233+ to the asynchronous nature of the Wayland protocol. For example,
234+ the server might terminate the client with a protocol error before
235+ it processes the unlock_and_destroy request.
236+ </description>
237+ </request>
238+ </interface>
239+
240+ <interface name="ext_session_lock_surface_v1" version="1">
241+ <description summary="a surface displayed while the session is locked">
242+ The client may use lock surfaces to display a screensaver, render a
243+ dialog to enter a password and unlock the session, or however else it
244+ sees fit.
245+
246+ On binding this interface the compositor will immediately send the
247+ first configure event. After making the ack_configure request in
248+ response to this event the client should attach and commit the first
249+ buffer. Committing the surface before acking the first configure is a
250+ protocol error. Committing the surface with a null buffer at any time
251+ is a protocol error.
252+
253+ The compositor is free to handle keyboard/pointer focus for lock
254+ surfaces however it chooses. A reasonable way to do this would be to
255+ give the first lock surface created keyboard focus and change keyboard
256+ focus if the user clicks on other surfaces.
257+ </description>
258+
259+ <enum name="error">
260+ <entry name="commit_before_first_ack" value="0"
261+ summary="surface committed before first ack_configure request"/>
262+ <entry name="null_buffer" value="1"
263+ summary="surface committed with a null buffer"/>
264+ <entry name="dimensions_mismatch" value="2"
265+ summary="failed to match ack'd width/height"/>
266+ <entry name="invalid_serial" value="3"
267+ summary="serial provided in ack_configure is invalid"/>
268+ </enum>
269+
270+ <request name="destroy" type="destructor">
271+ <description summary="destroy the lock surface object">
272+ This informs the compositor that the lock surface object will no
273+ longer be used.
274+
275+ It is recommended for a lock client to destroy lock surfaces if
276+ their corresponding wl_output global is removed.
277+
278+ If a lock surface on an active output is destroyed before the
279+ ext_session_lock_v1.unlock_and_destroy event is sent, the compositor
280+ must fall back to rendering a solid color.
281+ </description>
282+ </request>
283+
284+ <request name="ack_configure">
285+ <description summary="ack a configure event">
286+ When a configure event is received, if a client commits the surface
287+ in response to the configure event, then the client must make an
288+ ack_configure request sometime before the commit request, passing
289+ along the serial of the configure event.
290+
291+ If the client receives multiple configure events before it can
292+ respond to one, it only has to ack the last configure event.
293+
294+ A client is not required to commit immediately after sending an
295+ ack_configure request - it may even ack_configure several times
296+ before its next surface commit.
297+
298+ A client may send multiple ack_configure requests before committing,
299+ but only the last request sent before a commit indicates which
300+ configure event the client really is responding to.
301+
302+ Sending an ack_configure request consumes the configure event
303+ referenced by the given serial, as well as all older configure events
304+ sent on this object.
305+
306+ It is a protocol error to issue multiple ack_configure requests
307+ referencing the same configure event or to issue an ack_configure
308+ request referencing a configure event older than the last configure
309+ event acked for a given lock surface.
310+ </description>
311+ <arg name="serial" type="uint" summary="serial from the configure event"/>
312+ </request>
313+
314+ <event name="configure">
315+ <description summary="the client should resize its surface">
316+ This event is sent once on binding the interface and may be sent again
317+ at the compositor's discretion, for example if output geometry changes.
318+
319+ The width and height are in surface-local coordinates and are exact
320+ requirements. Failing to match these surface dimensions in the next
321+ commit after acking a configure is a protocol error.
322+ </description>
323+ <arg name="serial" type="uint" summary="serial for use in ack_configure"/>
324+ <arg name="width" type="uint"/>
325+ <arg name="height" type="uint"/>
326+ </event>
327+ </interface>
328+</protocol>
A protocol/extsessionlock/ext-session-lock-v1_generated.go +324 -0
@@ -0,0 +1,324 @@
1+// Code generated by wlturbo-scanner. DO NOT EDIT.
2+// Protocol: ext_session_lock_v1
3+// Source: ext-session-lock-v1.xml
4+
5+// Upstream protocol copyright and license:
6+// Copyright 2021 Isaac Freund
7+//
8+// Permission is hereby granted, free of charge, to any person obtaining a
9+// copy of this software and associated documentation files (the "Software"),
10+// to deal in the Software without restriction, including without limitation
11+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+// and/or sell copies of the Software, and to permit persons to whom the
13+// Software is furnished to do so, subject to the following conditions:
14+//
15+// The above copyright notice and this permission notice shall be included in
16+// all copies or substantial portions of the Software.
17+//
18+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+// THE SOFTWARE.
25+
26+package extsessionlock
27+
28+import (
29+ "sync"
30+
31+ cross_wl_output "github.com/bnema/wlturbo/protocol/core"
32+ cross_wl_surface "github.com/bnema/wlturbo/protocol/core"
33+ "github.com/bnema/wlturbo/wl"
34+)
35+
36+// ERROR_INVALID_DESTROY is the error invalid_destroy value.
37+const ERROR_INVALID_DESTROY = 0
38+
39+// ERROR_INVALID_UNLOCK is the error invalid_unlock value.
40+const ERROR_INVALID_UNLOCK = 1
41+
42+// ERROR_ROLE is the error role value.
43+const ERROR_ROLE = 2
44+
45+// ERROR_DUPLICATE_OUTPUT is the error duplicate_output value.
46+const ERROR_DUPLICATE_OUTPUT = 3
47+
48+// ERROR_ALREADY_CONSTRUCTED is the error already_constructed value.
49+const ERROR_ALREADY_CONSTRUCTED = 4
50+
51+// ERROR_COMMIT_BEFORE_FIRST_ACK is the error commit_before_first_ack value.
52+const ERROR_COMMIT_BEFORE_FIRST_ACK = 0
53+
54+// ERROR_NULL_BUFFER is the error null_buffer value.
55+const ERROR_NULL_BUFFER = 1
56+
57+// ERROR_DIMENSIONS_MISMATCH is the error dimensions_mismatch value.
58+const ERROR_DIMENSIONS_MISMATCH = 2
59+
60+// ERROR_INVALID_SERIAL is the error invalid_serial value.
61+const ERROR_INVALID_SERIAL = 3
62+
63+// ExtSessionLockManagerInterface is the protocol interface name.
64+const ExtSessionLockManagerInterface = "ext_session_lock_manager_v1"
65+
66+// ExtSessionLockManager is the generated binding for ext_session_lock_manager_v1 version 1.
67+type ExtSessionLockManager struct {
68+ wl.BaseProxy
69+}
70+
71+// NewExtSessionLockManager returns an unbound ExtSessionLockManager.
72+func NewExtSessionLockManager(ctx *wl.Context) *ExtSessionLockManager {
73+ obj := &ExtSessionLockManager{}
74+ obj.SetContext(ctx)
75+ ctx.Register(obj)
76+ return obj
77+}
78+
79+// This informs the compositor that the session lock manager object will no longer be used. Existing objects created through this interface remain valid.
80+func (o *ExtSessionLockManager) Destroy() error {
81+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_session_lock_manager_v1.destroy", Destructor: true}); err != nil {
82+ return err
83+ }
84+ return nil
85+}
86+
87+// This request creates a session lock and asks the compositor to lock the session. The compositor will send either the ext_session_lock_v1.locked or ext_session_lock_v1.finished event on the created object in response to this request.
88+func (o *ExtSessionLockManager) Lock() (*ExtSessionLock, error) {
89+ child := &ExtSessionLock{}
90+ child.SetContext(o.Context())
91+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_session_lock_manager_v1.lock", Child: child}, wl.ArgObject(child)); err != nil {
92+ return nil, err
93+ }
94+ return child, nil
95+}
96+
97+// EventSignature returns the declared event argument types in wire order.
98+func (o *ExtSessionLockManager) EventSignature(opcode uint16) (string, bool) {
99+ switch opcode {
100+ default:
101+ return "", false
102+ }
103+}
104+
105+// Dispatch decodes one event on ext_session_lock_manager_v1 and calls the registered handlers.
106+func (o *ExtSessionLockManager) Dispatch(event *wl.Event) {
107+ switch event.Opcode {
108+ default:
109+ }
110+}
111+
112+// ExtSessionLockInterface is the protocol interface name.
113+const ExtSessionLockInterface = "ext_session_lock_v1"
114+
115+// ExtSessionLock is the generated binding for ext_session_lock_v1 version 1.
116+type ExtSessionLock struct {
117+ wl.BaseProxy
118+ // handlersMu guards the handler slices: a client may register or replace
119+ // handlers while another goroutine dispatches events.
120+ handlersMu sync.Mutex
121+ onLocked []func()
122+ onFinished []func()
123+}
124+
125+// NewExtSessionLock returns an unbound ExtSessionLock.
126+func NewExtSessionLock(ctx *wl.Context) *ExtSessionLock {
127+ obj := &ExtSessionLock{}
128+ obj.SetContext(ctx)
129+ ctx.Register(obj)
130+ return obj
131+}
132+
133+// This informs the compositor that the lock object will no longer be used. Existing objects created through this interface remain valid. After this request is made, lock surfaces created through this object should be destroyed by the client as they will no longer be used by the compositor. It is a protocol error to make this request if the locked event was sent, the unlock_and_destroy request must be used instead.
134+func (o *ExtSessionLock) Destroy() error {
135+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_session_lock_v1.destroy", Destructor: true}); err != nil {
136+ return err
137+ }
138+ return nil
139+}
140+
141+// The client is expected to create lock surfaces for all outputs currently present and any new outputs as they are advertised. These won't be displayed by the compositor unless the lock is successful and the locked event is sent. Providing a wl_surface which already has a role or already has a buffer attached or committed is a protocol error, as is attaching/committing a buffer before the first ext_session_lock_surface_v1.configure event. Attempting to create more than one lock surface for a given output is a duplicate_output protocol error.
142+func (o *ExtSessionLock) GetLockSurface(surface *cross_wl_surface.Surface, output *cross_wl_output.Output) (*ExtSessionLockSurface, error) {
143+ var arg1 wl.Object
144+ if surface != nil {
145+ arg1 = surface
146+ }
147+ var arg2 wl.Object
148+ if output != nil {
149+ arg2 = output
150+ }
151+ child := &ExtSessionLockSurface{}
152+ child.SetContext(o.Context())
153+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_session_lock_v1.get_lock_surface", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1), wl.ArgObject(arg2)); err != nil {
154+ return nil, err
155+ }
156+ return child, nil
157+}
158+
159+// This request indicates that the session should be unlocked, for example because the user has entered their password and it has been verified by the client. This request also informs the compositor that the lock object will no longer be used and should be destroyed. Existing objects created through this interface remain valid. After this request is made, lock surfaces created through this object should be destroyed by the client as they will no longer be used by the compositor. It is a protocol error to make this request if the locked event has not been sent. In that case, the lock object must be destroyed using the destroy request. Note that a correct client that wishes to exit directly after unlocking the session must use the wl_display.sync request to ensure the server receives and processes the unlock_and_destroy request. Otherwise there is no guarantee that the server has unlocked the session due to the asynchronous nature of the Wayland protocol. For example, the server might terminate the client with a protocol error before it processes the unlock_and_destroy request.
160+func (o *ExtSessionLock) UnlockAndDestroy() error {
161+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_session_lock_v1.unlock_and_destroy", Destructor: true}); err != nil {
162+ return err
163+ }
164+ return nil
165+}
166+
167+// OnLocked registers a handler for the locked event.
168+//
169+// Handlers are appended, so a second call adds another handler rather than
170+// replacing the first. Registration is safe while another goroutine dispatches.
171+func (o *ExtSessionLock) OnLocked(handler func()) {
172+ if handler == nil {
173+ return
174+ }
175+ o.handlersMu.Lock()
176+ defer o.handlersMu.Unlock()
177+ o.onLocked = append(o.onLocked, handler)
178+}
179+
180+// handlersForLocked returns the handlers registered for locked, taken
181+// under the lock so a handler may register another handler while events are
182+// being dispatched.
183+func (o *ExtSessionLock) handlersForLocked() []func() {
184+ o.handlersMu.Lock()
185+ defer o.handlersMu.Unlock()
186+ return o.onLocked
187+}
188+
189+// OnFinished registers a handler for the finished event.
190+//
191+// Handlers are appended, so a second call adds another handler rather than
192+// replacing the first. Registration is safe while another goroutine dispatches.
193+func (o *ExtSessionLock) OnFinished(handler func()) {
194+ if handler == nil {
195+ return
196+ }
197+ o.handlersMu.Lock()
198+ defer o.handlersMu.Unlock()
199+ o.onFinished = append(o.onFinished, handler)
200+}
201+
202+// handlersForFinished returns the handlers registered for finished, taken
203+// under the lock so a handler may register another handler while events are
204+// being dispatched.
205+func (o *ExtSessionLock) handlersForFinished() []func() {
206+ o.handlersMu.Lock()
207+ defer o.handlersMu.Unlock()
208+ return o.onFinished
209+}
210+
211+// EventSignature returns the declared event argument types in wire order.
212+func (o *ExtSessionLock) EventSignature(opcode uint16) (string, bool) {
213+ switch opcode {
214+ case 0:
215+ return "", true
216+ case 1:
217+ return "", true
218+ default:
219+ return "", false
220+ }
221+}
222+
223+// Dispatch decodes one event on ext_session_lock_v1 and calls the registered handlers.
224+func (o *ExtSessionLock) Dispatch(event *wl.Event) {
225+ switch event.Opcode {
226+ case 0: // locked
227+
228+ for i, handler := range o.handlersForLocked() {
229+ _ = i
230+ handler()
231+ }
232+ case 1: // finished
233+
234+ for i, handler := range o.handlersForFinished() {
235+ _ = i
236+ handler()
237+ }
238+ default:
239+ }
240+}
241+
242+// ExtSessionLockSurfaceInterface is the protocol interface name.
243+const ExtSessionLockSurfaceInterface = "ext_session_lock_surface_v1"
244+
245+// ExtSessionLockSurface is the generated binding for ext_session_lock_surface_v1 version 1.
246+type ExtSessionLockSurface struct {
247+ wl.BaseProxy
248+ // handlersMu guards the handler slices: a client may register or replace
249+ // handlers while another goroutine dispatches events.
250+ handlersMu sync.Mutex
251+ onConfigure []func(serial uint32, width uint32, height uint32)
252+}
253+
254+// NewExtSessionLockSurface returns an unbound ExtSessionLockSurface.
255+func NewExtSessionLockSurface(ctx *wl.Context) *ExtSessionLockSurface {
256+ obj := &ExtSessionLockSurface{}
257+ obj.SetContext(ctx)
258+ ctx.Register(obj)
259+ return obj
260+}
261+
262+// This informs the compositor that the lock surface object will no longer be used. It is recommended for a lock client to destroy lock surfaces if their corresponding wl_output global is removed. If a lock surface on an active output is destroyed before the ext_session_lock_v1.unlock_and_destroy event is sent, the compositor must fall back to rendering a solid color.
263+func (o *ExtSessionLockSurface) Destroy() error {
264+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_session_lock_surface_v1.destroy", Destructor: true}); err != nil {
265+ return err
266+ }
267+ return nil
268+}
269+
270+// When a configure event is received, if a client commits the surface in response to the configure event, then the client must make an ack_configure request sometime before the commit request, passing along the serial of the configure event. If the client receives multiple configure events before it can respond to one, it only has to ack the last configure event. A client is not required to commit immediately after sending an ack_configure request - it may even ack_configure several times before its next surface commit. A client may send multiple ack_configure requests before committing, but only the last request sent before a commit indicates which configure event the client really is responding to. Sending an ack_configure request consumes the configure event referenced by the given serial, as well as all older configure events sent on this object. It is a protocol error to issue multiple ack_configure requests referencing the same configure event or to issue an ack_configure request referencing a configure event older than the last configure event acked for a given lock surface.
271+func (o *ExtSessionLockSurface) AckConfigure(serial uint32) error {
272+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_session_lock_surface_v1.ack_configure"}, wl.ArgUint(serial)); err != nil {
273+ return err
274+ }
275+ return nil
276+}
277+
278+// OnConfigure registers a handler for the configure event.
279+//
280+// Handlers are appended, so a second call adds another handler rather than
281+// replacing the first. Registration is safe while another goroutine dispatches.
282+func (o *ExtSessionLockSurface) OnConfigure(handler func(serial uint32, width uint32, height uint32)) {
283+ if handler == nil {
284+ return
285+ }
286+ o.handlersMu.Lock()
287+ defer o.handlersMu.Unlock()
288+ o.onConfigure = append(o.onConfigure, handler)
289+}
290+
291+// handlersForConfigure returns the handlers registered for configure, taken
292+// under the lock so a handler may register another handler while events are
293+// being dispatched.
294+func (o *ExtSessionLockSurface) handlersForConfigure() []func(serial uint32, width uint32, height uint32) {
295+ o.handlersMu.Lock()
296+ defer o.handlersMu.Unlock()
297+ return o.onConfigure
298+}
299+
300+// EventSignature returns the declared event argument types in wire order.
301+func (o *ExtSessionLockSurface) EventSignature(opcode uint16) (string, bool) {
302+ switch opcode {
303+ case 0:
304+ return "uint,uint,uint,", true
305+ default:
306+ return "", false
307+ }
308+}
309+
310+// Dispatch decodes one event on ext_session_lock_surface_v1 and calls the registered handlers.
311+func (o *ExtSessionLockSurface) Dispatch(event *wl.Event) {
312+ switch event.Opcode {
313+ case 0: // configure
314+ serial := event.Uint32()
315+ width := event.Uint32()
316+ height := event.Uint32()
317+
318+ for i, handler := range o.handlersForConfigure() {
319+ _ = i
320+ handler(serial, width, height)
321+ }
322+ default:
323+ }
324+}
@@ -0,0 +1,324 @@
1+// Code generated by wlturbo-scanner. DO NOT EDIT.
2+// Protocol: ext_session_lock_v1
3+// Source: ext-session-lock-v1.xml
4+
5+// Upstream protocol copyright and license:
6+// Copyright 2021 Isaac Freund
7+//
8+// Permission is hereby granted, free of charge, to any person obtaining a
9+// copy of this software and associated documentation files (the "Software"),
10+// to deal in the Software without restriction, including without limitation
11+// the rights to use, copy, modify, merge, publish, distribute, sublicense,
12+// and/or sell copies of the Software, and to permit persons to whom the
13+// Software is furnished to do so, subject to the following conditions:
14+//
15+// The above copyright notice and this permission notice shall be included in
16+// all copies or substantial portions of the Software.
17+//
18+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20+// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21+// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22+// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23+// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24+// THE SOFTWARE.
25+
26+package extsessionlock
27+
28+import (
29+ "sync"
30+
31+ cross_wl_output "github.com/bnema/wlturbo/protocol/core"
32+ cross_wl_surface "github.com/bnema/wlturbo/protocol/core"
33+ "github.com/bnema/wlturbo/wl"
34+)
35+
36+// ERROR_INVALID_DESTROY is the error invalid_destroy value.
37+const ERROR_INVALID_DESTROY = 0
38+
39+// ERROR_INVALID_UNLOCK is the error invalid_unlock value.
40+const ERROR_INVALID_UNLOCK = 1
41+
42+// ERROR_ROLE is the error role value.
43+const ERROR_ROLE = 2
44+
45+// ERROR_DUPLICATE_OUTPUT is the error duplicate_output value.
46+const ERROR_DUPLICATE_OUTPUT = 3
47+
48+// ERROR_ALREADY_CONSTRUCTED is the error already_constructed value.
49+const ERROR_ALREADY_CONSTRUCTED = 4
50+
51+// ERROR_COMMIT_BEFORE_FIRST_ACK is the error commit_before_first_ack value.
52+const ERROR_COMMIT_BEFORE_FIRST_ACK = 0
53+
54+// ERROR_NULL_BUFFER is the error null_buffer value.
55+const ERROR_NULL_BUFFER = 1
56+
57+// ERROR_DIMENSIONS_MISMATCH is the error dimensions_mismatch value.
58+const ERROR_DIMENSIONS_MISMATCH = 2
59+
60+// ERROR_INVALID_SERIAL is the error invalid_serial value.
61+const ERROR_INVALID_SERIAL = 3
62+
63+// ExtSessionLockManagerInterface is the protocol interface name.
64+const ExtSessionLockManagerInterface = "ext_session_lock_manager_v1"
65+
66+// ExtSessionLockManager is the generated binding for ext_session_lock_manager_v1 version 1.
67+type ExtSessionLockManager struct {
68+ wl.BaseProxy
69+}
70+
71+// NewExtSessionLockManager returns an unbound ExtSessionLockManager.
72+func NewExtSessionLockManager(ctx *wl.Context) *ExtSessionLockManager {
73+ obj := &ExtSessionLockManager{}
74+ obj.SetContext(ctx)
75+ ctx.Register(obj)
76+ return obj
77+}
78+
79+// This informs the compositor that the session lock manager object will no longer be used. Existing objects created through this interface remain valid.
80+func (o *ExtSessionLockManager) Destroy() error {
81+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_session_lock_manager_v1.destroy", Destructor: true}); err != nil {
82+ return err
83+ }
84+ return nil
85+}
86+
87+// This request creates a session lock and asks the compositor to lock the session. The compositor will send either the ext_session_lock_v1.locked or ext_session_lock_v1.finished event on the created object in response to this request.
88+func (o *ExtSessionLockManager) Lock() (*ExtSessionLock, error) {
89+ child := &ExtSessionLock{}
90+ child.SetContext(o.Context())
91+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_session_lock_manager_v1.lock", Child: child}, wl.ArgObject(child)); err != nil {
92+ return nil, err
93+ }
94+ return child, nil
95+}
96+
97+// EventSignature returns the declared event argument types in wire order.
98+func (o *ExtSessionLockManager) EventSignature(opcode uint16) (string, bool) {
99+ switch opcode {
100+ default:
101+ return "", false
102+ }
103+}
104+
105+// Dispatch decodes one event on ext_session_lock_manager_v1 and calls the registered handlers.
106+func (o *ExtSessionLockManager) Dispatch(event *wl.Event) {
107+ switch event.Opcode {
108+ default:
109+ }
110+}
111+
112+// ExtSessionLockInterface is the protocol interface name.
113+const ExtSessionLockInterface = "ext_session_lock_v1"
114+
115+// ExtSessionLock is the generated binding for ext_session_lock_v1 version 1.
116+type ExtSessionLock struct {
117+ wl.BaseProxy
118+ // handlersMu guards the handler slices: a client may register or replace
119+ // handlers while another goroutine dispatches events.
120+ handlersMu sync.Mutex
121+ onLocked []func()
122+ onFinished []func()
123+}
124+
125+// NewExtSessionLock returns an unbound ExtSessionLock.
126+func NewExtSessionLock(ctx *wl.Context) *ExtSessionLock {
127+ obj := &ExtSessionLock{}
128+ obj.SetContext(ctx)
129+ ctx.Register(obj)
130+ return obj
131+}
132+
133+// This informs the compositor that the lock object will no longer be used. Existing objects created through this interface remain valid. After this request is made, lock surfaces created through this object should be destroyed by the client as they will no longer be used by the compositor. It is a protocol error to make this request if the locked event was sent, the unlock_and_destroy request must be used instead.
134+func (o *ExtSessionLock) Destroy() error {
135+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_session_lock_v1.destroy", Destructor: true}); err != nil {
136+ return err
137+ }
138+ return nil
139+}
140+
141+// The client is expected to create lock surfaces for all outputs currently present and any new outputs as they are advertised. These won't be displayed by the compositor unless the lock is successful and the locked event is sent. Providing a wl_surface which already has a role or already has a buffer attached or committed is a protocol error, as is attaching/committing a buffer before the first ext_session_lock_surface_v1.configure event. Attempting to create more than one lock surface for a given output is a duplicate_output protocol error.
142+func (o *ExtSessionLock) GetLockSurface(surface *cross_wl_surface.Surface, output *cross_wl_output.Output) (*ExtSessionLockSurface, error) {
143+ var arg1 wl.Object
144+ if surface != nil {
145+ arg1 = surface
146+ }
147+ var arg2 wl.Object
148+ if output != nil {
149+ arg2 = output
150+ }
151+ child := &ExtSessionLockSurface{}
152+ child.SetContext(o.Context())
153+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_session_lock_v1.get_lock_surface", Child: child}, wl.ArgObject(child), wl.ArgObject(arg1), wl.ArgObject(arg2)); err != nil {
154+ return nil, err
155+ }
156+ return child, nil
157+}
158+
159+// This request indicates that the session should be unlocked, for example because the user has entered their password and it has been verified by the client. This request also informs the compositor that the lock object will no longer be used and should be destroyed. Existing objects created through this interface remain valid. After this request is made, lock surfaces created through this object should be destroyed by the client as they will no longer be used by the compositor. It is a protocol error to make this request if the locked event has not been sent. In that case, the lock object must be destroyed using the destroy request. Note that a correct client that wishes to exit directly after unlocking the session must use the wl_display.sync request to ensure the server receives and processes the unlock_and_destroy request. Otherwise there is no guarantee that the server has unlocked the session due to the asynchronous nature of the Wayland protocol. For example, the server might terminate the client with a protocol error before it processes the unlock_and_destroy request.
160+func (o *ExtSessionLock) UnlockAndDestroy() error {
161+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 2, Name: "ext_session_lock_v1.unlock_and_destroy", Destructor: true}); err != nil {
162+ return err
163+ }
164+ return nil
165+}
166+
167+// OnLocked registers a handler for the locked event.
168+//
169+// Handlers are appended, so a second call adds another handler rather than
170+// replacing the first. Registration is safe while another goroutine dispatches.
171+func (o *ExtSessionLock) OnLocked(handler func()) {
172+ if handler == nil {
173+ return
174+ }
175+ o.handlersMu.Lock()
176+ defer o.handlersMu.Unlock()
177+ o.onLocked = append(o.onLocked, handler)
178+}
179+
180+// handlersForLocked returns the handlers registered for locked, taken
181+// under the lock so a handler may register another handler while events are
182+// being dispatched.
183+func (o *ExtSessionLock) handlersForLocked() []func() {
184+ o.handlersMu.Lock()
185+ defer o.handlersMu.Unlock()
186+ return o.onLocked
187+}
188+
189+// OnFinished registers a handler for the finished event.
190+//
191+// Handlers are appended, so a second call adds another handler rather than
192+// replacing the first. Registration is safe while another goroutine dispatches.
193+func (o *ExtSessionLock) OnFinished(handler func()) {
194+ if handler == nil {
195+ return
196+ }
197+ o.handlersMu.Lock()
198+ defer o.handlersMu.Unlock()
199+ o.onFinished = append(o.onFinished, handler)
200+}
201+
202+// handlersForFinished returns the handlers registered for finished, taken
203+// under the lock so a handler may register another handler while events are
204+// being dispatched.
205+func (o *ExtSessionLock) handlersForFinished() []func() {
206+ o.handlersMu.Lock()
207+ defer o.handlersMu.Unlock()
208+ return o.onFinished
209+}
210+
211+// EventSignature returns the declared event argument types in wire order.
212+func (o *ExtSessionLock) EventSignature(opcode uint16) (string, bool) {
213+ switch opcode {
214+ case 0:
215+ return "", true
216+ case 1:
217+ return "", true
218+ default:
219+ return "", false
220+ }
221+}
222+
223+// Dispatch decodes one event on ext_session_lock_v1 and calls the registered handlers.
224+func (o *ExtSessionLock) Dispatch(event *wl.Event) {
225+ switch event.Opcode {
226+ case 0: // locked
227+
228+ for i, handler := range o.handlersForLocked() {
229+ _ = i
230+ handler()
231+ }
232+ case 1: // finished
233+
234+ for i, handler := range o.handlersForFinished() {
235+ _ = i
236+ handler()
237+ }
238+ default:
239+ }
240+}
241+
242+// ExtSessionLockSurfaceInterface is the protocol interface name.
243+const ExtSessionLockSurfaceInterface = "ext_session_lock_surface_v1"
244+
245+// ExtSessionLockSurface is the generated binding for ext_session_lock_surface_v1 version 1.
246+type ExtSessionLockSurface struct {
247+ wl.BaseProxy
248+ // handlersMu guards the handler slices: a client may register or replace
249+ // handlers while another goroutine dispatches events.
250+ handlersMu sync.Mutex
251+ onConfigure []func(serial uint32, width uint32, height uint32)
252+}
253+
254+// NewExtSessionLockSurface returns an unbound ExtSessionLockSurface.
255+func NewExtSessionLockSurface(ctx *wl.Context) *ExtSessionLockSurface {
256+ obj := &ExtSessionLockSurface{}
257+ obj.SetContext(ctx)
258+ ctx.Register(obj)
259+ return obj
260+}
261+
262+// This informs the compositor that the lock surface object will no longer be used. It is recommended for a lock client to destroy lock surfaces if their corresponding wl_output global is removed. If a lock surface on an active output is destroyed before the ext_session_lock_v1.unlock_and_destroy event is sent, the compositor must fall back to rendering a solid color.
263+func (o *ExtSessionLockSurface) Destroy() error {
264+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 0, Name: "ext_session_lock_surface_v1.destroy", Destructor: true}); err != nil {
265+ return err
266+ }
267+ return nil
268+}
269+
270+// When a configure event is received, if a client commits the surface in response to the configure event, then the client must make an ack_configure request sometime before the commit request, passing along the serial of the configure event. If the client receives multiple configure events before it can respond to one, it only has to ack the last configure event. A client is not required to commit immediately after sending an ack_configure request - it may even ack_configure several times before its next surface commit. A client may send multiple ack_configure requests before committing, but only the last request sent before a commit indicates which configure event the client really is responding to. Sending an ack_configure request consumes the configure event referenced by the given serial, as well as all older configure events sent on this object. It is a protocol error to issue multiple ack_configure requests referencing the same configure event or to issue an ack_configure request referencing a configure event older than the last configure event acked for a given lock surface.
271+func (o *ExtSessionLockSurface) AckConfigure(serial uint32) error {
272+ if err := o.Context().RequestArgs(wl.Request{Proxy: o, Opcode: 1, Name: "ext_session_lock_surface_v1.ack_configure"}, wl.ArgUint(serial)); err != nil {
273+ return err
274+ }
275+ return nil
276+}
277+
278+// OnConfigure registers a handler for the configure event.
279+//
280+// Handlers are appended, so a second call adds another handler rather than
281+// replacing the first. Registration is safe while another goroutine dispatches.
282+func (o *ExtSessionLockSurface) OnConfigure(handler func(serial uint32, width uint32, height uint32)) {
283+ if handler == nil {
284+ return
285+ }
286+ o.handlersMu.Lock()
287+ defer o.handlersMu.Unlock()
288+ o.onConfigure = append(o.onConfigure, handler)
289+}
290+
291+// handlersForConfigure returns the handlers registered for configure, taken
292+// under the lock so a handler may register another handler while events are
293+// being dispatched.
294+func (o *ExtSessionLockSurface) handlersForConfigure() []func(serial uint32, width uint32, height uint32) {
295+ o.handlersMu.Lock()
296+ defer o.handlersMu.Unlock()
297+ return o.onConfigure
298+}
299+
300+// EventSignature returns the declared event argument types in wire order.
301+func (o *ExtSessionLockSurface) EventSignature(opcode uint16) (string, bool) {
302+ switch opcode {
303+ case 0:
304+ return "uint,uint,uint,", true
305+ default:
306+ return "", false
307+ }
308+}
309+
310+// Dispatch decodes one event on ext_session_lock_surface_v1 and calls the registered handlers.
311+func (o *ExtSessionLockSurface) Dispatch(event *wl.Event) {
312+ switch event.Opcode {
313+ case 0: // configure
314+ serial := event.Uint32()
315+ width := event.Uint32()
316+ height := event.Uint32()
317+
318+ for i, handler := range o.handlersForConfigure() {
319+ _ = i
320+ handler(serial, width, height)
321+ }
322+ default:
323+ }
324+}
A protocol/extsessionlock/generate.go +3 -0
@@ -0,0 +1,3 @@
1+package extsessionlock
2+
3+//go:generate go run ../../cmd/wlturbo-scanner -p extsessionlock -o ext-session-lock-v1_generated.go -import wl_surface=github.com/bnema/wlturbo/protocol/core -import wl_output=github.com/bnema/wlturbo/protocol/core ext-session-lock-v1.xml
@@ -0,0 +1,3 @@
1+package extsessionlock
2+
3+//go:generate go run ../../cmd/wlturbo-scanner -p extsessionlock -o ext-session-lock-v1_generated.go -import wl_surface=github.com/bnema/wlturbo/protocol/core -import wl_output=github.com/bnema/wlturbo/protocol/core ext-session-lock-v1.xml
A protocol/session_lock_test.go +222 -0
@@ -0,0 +1,222 @@
1+//go:build linux
2+
3+package protocol_test
4+
5+import (
6+ "errors"
7+ "reflect"
8+ "sync"
9+ "testing"
10+
11+ "github.com/bnema/wlturbo"
12+ "github.com/bnema/wlturbo/protocol/core"
13+ "github.com/bnema/wlturbo/protocol/extsessionlock"
14+)
15+
16+// These tests use ordinary generated proxies and the production transport on a
17+// socketpair. Only the server wire peer is scripted; no request/dispatch hooks
18+// are replaced, and no live compositor or session lock is used.
19+func TestSessionLockLockedLifetime(t *testing.T) {
20+ s := newWireEnv(t)
21+ ctx := s.d.Context()
22+ compositor := core.NewCompositor(ctx)
23+ s.bind(1, core.CompositorInterface, 6, 6, compositor)
24+ surface, err := compositor.CreateSurface()
25+ noerr(t, err)
26+ wantWords(t, "create_surface", s.req(compositor.ID(), 0), surface.ID())
27+ out := core.NewOutput(ctx)
28+ s.bind(2, core.OutputInterface, 4, 4, out)
29+ mgr := extsessionlock.NewExtSessionLockManager(ctx)
30+ s.bind(3, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
31+ lock, err := mgr.Lock()
32+ noerr(t, err)
33+ wantWords(t, "lock", s.req(mgr.ID(), 1), lock.ID())
34+ if lock.Version() != 1 || lock.Context() != ctx {
35+ t.Fatalf("lock version=%d context=%p", lock.Version(), lock.Context())
36+ }
37+ noerr(t, ctx.CheckProxy(lock))
38+
39+ // The manager destructor must not invalidate its lock children.
40+ noerr(t, mgr.Destroy())
41+ wantWords(t, "manager.destroy", s.req(mgr.ID(), 0))
42+ if ctx.CheckProxy(mgr) == nil {
43+ t.Fatal("destroyed manager remains registered")
44+ }
45+ s.event(1, 1, wordBytes(mgr.ID())...) // wl_display.delete_id
46+ noerr(t, ctx.CheckProxy(lock))
47+ ls, err := lock.GetLockSurface(surface, out)
48+ noerr(t, err)
49+ wantWords(t, "get_lock_surface", s.req(lock.ID(), 1), ls.ID(), surface.ID(), out.ID())
50+ if ls.Version() != 1 || ls.Context() != ctx {
51+ t.Fatalf("lock surface version=%d context=%p", ls.Version(), ls.Context())
52+ }
53+ noerr(t, ctx.CheckProxy(ls))
54+
55+ var events []string
56+ lock.OnLocked(func() { events = append(events, "locked") })
57+ lock.OnFinished(func() { events = append(events, "finished") })
58+ var configures [][3]uint32
59+ ls.OnConfigure(func(serial, width, height uint32) {
60+ configures = append(configures, [3]uint32{serial, width, height})
61+ noerr(t, ls.AckConfigure(serial))
62+ })
63+ s.event(ls.ID(), 0, wordBytes(0x89abcdef, 1920, 1080)...)
64+ wantWords(t, "ack_configure", s.req(ls.ID(), 1), 0x89abcdef)
65+ s.event(lock.ID(), 0)
66+ s.event(lock.ID(), 1) // finished after locked still requires unlock_and_destroy
67+ if !reflect.DeepEqual(events, []string{"locked", "finished"}) ||
68+ !reflect.DeepEqual(configures, [][3]uint32{{0x89abcdef, 1920, 1080}}) {
69+ t.Fatalf("events=%v configures=%v", events, configures)
70+ }
71+ // Neither event is a destructor; the application must choose the request.
72+ noerr(t, ctx.CheckProxy(lock))
73+ noerr(t, lock.UnlockAndDestroy())
74+ wantWords(t, "unlock_and_destroy", s.req(lock.ID(), 2))
75+ if ctx.CheckProxy(lock) == nil {
76+ t.Fatal("unlocked lock remains registered")
77+ }
78+ s.event(1, 1, wordBytes(lock.ID())...)
79+
80+ // Lock destruction also leaves its children and core objects valid.
81+ noerr(t, ctx.CheckProxy(ls))
82+ noerr(t, ctx.CheckProxy(surface))
83+ noerr(t, ctx.CheckProxy(out))
84+ s.event(ls.ID(), 0, wordBytes(0xffffffff, 800, 600)...)
85+ wantWords(t, "ack after parent destruction", s.req(ls.ID(), 1), 0xffffffff)
86+ if len(configures) != 2 || configures[1] != [3]uint32{0xffffffff, 800, 600} {
87+ t.Fatal(configures)
88+ }
89+ noerr(t, ls.Destroy())
90+ wantWords(t, "surface.destroy", s.req(ls.ID(), 0))
91+ if ctx.CheckProxy(ls) == nil {
92+ t.Fatal("destroyed lock surface remains registered")
93+ }
94+ // Events in flight on a destroyed object are dropped until delete_id.
95+ s.event(ls.ID(), 0, wordBytes(12, 640, 480)...)
96+ if len(configures) != 2 {
97+ t.Fatal("configure delivered to destroyed surface")
98+ }
99+ s.event(1, 1, wordBytes(ls.ID())...)
100+ if err := ls.AckConfigure(12); err == nil {
101+ t.Fatal("ack on destroyed surface succeeded")
102+ }
103+ if err := ls.Destroy(); err == nil {
104+ t.Fatal("second surface destructor succeeded")
105+ }
106+ if err := lock.Destroy(); err == nil {
107+ t.Fatal("second lock destructor succeeded")
108+ }
109+ if child, err := mgr.Lock(); err == nil || child != nil {
110+ t.Fatal("destroyed manager created a child", child, err)
111+ }
112+ if child, err := lock.GetLockSurface(surface, out); err == nil || child != nil {
113+ t.Fatal("destroyed lock created a child", child, err)
114+ }
115+ s.noRequest()
116+ noerr(t, surface.Destroy())
117+ wantWords(t, "wl_surface.destroy", s.req(surface.ID(), 0))
118+ noerr(t, out.Release())
119+ wantWords(t, "wl_output.release", s.req(out.ID(), 0))
120+}
121+
122+func TestSessionLockDeniedDestroy(t *testing.T) {
123+ s := newWireEnv(t)
124+ mgr := extsessionlock.NewExtSessionLockManager(s.d.Context())
125+ s.bind(1, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
126+ lock, err := mgr.Lock()
127+ noerr(t, err)
128+ wantWords(t, "lock", s.req(mgr.ID(), 1), lock.ID())
129+ var locked, finished bool
130+ lock.OnLocked(func() { locked = true })
131+ lock.OnFinished(func() { finished = true })
132+ s.event(lock.ID(), 1)
133+ if locked || !finished {
134+ t.Fatalf("locked=%t finished=%t", locked, finished)
135+ }
136+ noerr(t, s.d.Context().CheckProxy(lock))
137+ noerr(t, lock.Destroy()) // never locked: destroy, not unlock_and_destroy
138+ wantWords(t, "denied.destroy", s.req(lock.ID(), 0))
139+ if err := lock.UnlockAndDestroy(); err == nil {
140+ t.Fatal("second destructor succeeded")
141+ }
142+ s.noRequest()
143+ // Destroying one child must not invalidate the manager or its next child.
144+ noerr(t, s.d.Context().CheckProxy(mgr))
145+ next, err := mgr.Lock()
146+ noerr(t, err)
147+ wantWords(t, "next lock", s.req(mgr.ID(), 1), next.ID())
148+ noerr(t, next.Destroy())
149+ wantWords(t, "next.destroy", s.req(next.ID(), 0))
150+ noerr(t, mgr.Destroy())
151+ wantWords(t, "manager.destroy", s.req(mgr.ID(), 0))
152+}
153+
154+func TestSessionLockConcurrentDestructors(t *testing.T) {
155+ s := newWireEnv(t)
156+ mgr := extsessionlock.NewExtSessionLockManager(s.d.Context())
157+ s.bind(1, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
158+ lock, err := mgr.Lock()
159+ noerr(t, err)
160+ wantWords(t, "lock", s.req(mgr.ID(), 1), lock.ID())
161+ s.event(lock.ID(), 1)
162+ var wg sync.WaitGroup
163+ results := make(chan error, 8)
164+ for range 8 {
165+ wg.Add(1)
166+ go func() { defer wg.Done(); results <- lock.Destroy() }()
167+ }
168+ wg.Wait()
169+ close(results)
170+ successes := 0
171+ for err := range results {
172+ if err == nil {
173+ successes++
174+ }
175+ }
176+ if successes != 1 {
177+ t.Fatalf("successful destructors=%d, want 1", successes)
178+ }
179+ wantWords(t, "single destructor", s.req(lock.ID(), 0))
180+ s.noRequest()
181+}
182+
183+func TestSessionLockMalformedEvents(t *testing.T) {
184+ for _, tc := range []struct {
185+ name string
186+ surface bool
187+ op uint16
188+ body []byte
189+ }{
190+ {"locked trailing word", false, 0, wordBytes(1)},
191+ {"finished trailing word", false, 1, wordBytes(1)},
192+ {"configure missing height", true, 0, wordBytes(1, 800)},
193+ {"configure trailing word", true, 0, wordBytes(1, 800, 600, 1)},
194+ } {
195+ t.Run(tc.name, func(t *testing.T) {
196+ s := newWireEnv(t)
197+ mgr := extsessionlock.NewExtSessionLockManager(s.d.Context())
198+ s.bind(1, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
199+ lock, err := mgr.Lock()
200+ noerr(t, err)
201+ s.req(mgr.ID(), 1)
202+ id := lock.ID()
203+ called := false
204+ lock.OnLocked(func() { called = true })
205+ lock.OnFinished(func() { called = true })
206+ if tc.surface {
207+ ls, err := lock.GetLockSurface(s.surface(), s.output())
208+ noerr(t, err)
209+ s.req(lock.ID(), 1)
210+ ls.OnConfigure(func(_, _, _ uint32) { called = true })
211+ id = ls.ID()
212+ }
213+ send(t, s.p, payload(id, tc.op, tc.body...))
214+ if err := s.d.Dispatch(); !errors.Is(err, wlturbo.ErrMalformedFrame) {
215+ t.Fatalf("malformed event: %v", err)
216+ }
217+ if called {
218+ t.Fatal("malformed event reached a handler")
219+ }
220+ })
221+ }
222+}
@@ -0,0 +1,222 @@
1+//go:build linux
2+
3+package protocol_test
4+
5+import (
6+ "errors"
7+ "reflect"
8+ "sync"
9+ "testing"
10+
11+ "github.com/bnema/wlturbo"
12+ "github.com/bnema/wlturbo/protocol/core"
13+ "github.com/bnema/wlturbo/protocol/extsessionlock"
14+)
15+
16+// These tests use ordinary generated proxies and the production transport on a
17+// socketpair. Only the server wire peer is scripted; no request/dispatch hooks
18+// are replaced, and no live compositor or session lock is used.
19+func TestSessionLockLockedLifetime(t *testing.T) {
20+ s := newWireEnv(t)
21+ ctx := s.d.Context()
22+ compositor := core.NewCompositor(ctx)
23+ s.bind(1, core.CompositorInterface, 6, 6, compositor)
24+ surface, err := compositor.CreateSurface()
25+ noerr(t, err)
26+ wantWords(t, "create_surface", s.req(compositor.ID(), 0), surface.ID())
27+ out := core.NewOutput(ctx)
28+ s.bind(2, core.OutputInterface, 4, 4, out)
29+ mgr := extsessionlock.NewExtSessionLockManager(ctx)
30+ s.bind(3, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
31+ lock, err := mgr.Lock()
32+ noerr(t, err)
33+ wantWords(t, "lock", s.req(mgr.ID(), 1), lock.ID())
34+ if lock.Version() != 1 || lock.Context() != ctx {
35+ t.Fatalf("lock version=%d context=%p", lock.Version(), lock.Context())
36+ }
37+ noerr(t, ctx.CheckProxy(lock))
38+
39+ // The manager destructor must not invalidate its lock children.
40+ noerr(t, mgr.Destroy())
41+ wantWords(t, "manager.destroy", s.req(mgr.ID(), 0))
42+ if ctx.CheckProxy(mgr) == nil {
43+ t.Fatal("destroyed manager remains registered")
44+ }
45+ s.event(1, 1, wordBytes(mgr.ID())...) // wl_display.delete_id
46+ noerr(t, ctx.CheckProxy(lock))
47+ ls, err := lock.GetLockSurface(surface, out)
48+ noerr(t, err)
49+ wantWords(t, "get_lock_surface", s.req(lock.ID(), 1), ls.ID(), surface.ID(), out.ID())
50+ if ls.Version() != 1 || ls.Context() != ctx {
51+ t.Fatalf("lock surface version=%d context=%p", ls.Version(), ls.Context())
52+ }
53+ noerr(t, ctx.CheckProxy(ls))
54+
55+ var events []string
56+ lock.OnLocked(func() { events = append(events, "locked") })
57+ lock.OnFinished(func() { events = append(events, "finished") })
58+ var configures [][3]uint32
59+ ls.OnConfigure(func(serial, width, height uint32) {
60+ configures = append(configures, [3]uint32{serial, width, height})
61+ noerr(t, ls.AckConfigure(serial))
62+ })
63+ s.event(ls.ID(), 0, wordBytes(0x89abcdef, 1920, 1080)...)
64+ wantWords(t, "ack_configure", s.req(ls.ID(), 1), 0x89abcdef)
65+ s.event(lock.ID(), 0)
66+ s.event(lock.ID(), 1) // finished after locked still requires unlock_and_destroy
67+ if !reflect.DeepEqual(events, []string{"locked", "finished"}) ||
68+ !reflect.DeepEqual(configures, [][3]uint32{{0x89abcdef, 1920, 1080}}) {
69+ t.Fatalf("events=%v configures=%v", events, configures)
70+ }
71+ // Neither event is a destructor; the application must choose the request.
72+ noerr(t, ctx.CheckProxy(lock))
73+ noerr(t, lock.UnlockAndDestroy())
74+ wantWords(t, "unlock_and_destroy", s.req(lock.ID(), 2))
75+ if ctx.CheckProxy(lock) == nil {
76+ t.Fatal("unlocked lock remains registered")
77+ }
78+ s.event(1, 1, wordBytes(lock.ID())...)
79+
80+ // Lock destruction also leaves its children and core objects valid.
81+ noerr(t, ctx.CheckProxy(ls))
82+ noerr(t, ctx.CheckProxy(surface))
83+ noerr(t, ctx.CheckProxy(out))
84+ s.event(ls.ID(), 0, wordBytes(0xffffffff, 800, 600)...)
85+ wantWords(t, "ack after parent destruction", s.req(ls.ID(), 1), 0xffffffff)
86+ if len(configures) != 2 || configures[1] != [3]uint32{0xffffffff, 800, 600} {
87+ t.Fatal(configures)
88+ }
89+ noerr(t, ls.Destroy())
90+ wantWords(t, "surface.destroy", s.req(ls.ID(), 0))
91+ if ctx.CheckProxy(ls) == nil {
92+ t.Fatal("destroyed lock surface remains registered")
93+ }
94+ // Events in flight on a destroyed object are dropped until delete_id.
95+ s.event(ls.ID(), 0, wordBytes(12, 640, 480)...)
96+ if len(configures) != 2 {
97+ t.Fatal("configure delivered to destroyed surface")
98+ }
99+ s.event(1, 1, wordBytes(ls.ID())...)
100+ if err := ls.AckConfigure(12); err == nil {
101+ t.Fatal("ack on destroyed surface succeeded")
102+ }
103+ if err := ls.Destroy(); err == nil {
104+ t.Fatal("second surface destructor succeeded")
105+ }
106+ if err := lock.Destroy(); err == nil {
107+ t.Fatal("second lock destructor succeeded")
108+ }
109+ if child, err := mgr.Lock(); err == nil || child != nil {
110+ t.Fatal("destroyed manager created a child", child, err)
111+ }
112+ if child, err := lock.GetLockSurface(surface, out); err == nil || child != nil {
113+ t.Fatal("destroyed lock created a child", child, err)
114+ }
115+ s.noRequest()
116+ noerr(t, surface.Destroy())
117+ wantWords(t, "wl_surface.destroy", s.req(surface.ID(), 0))
118+ noerr(t, out.Release())
119+ wantWords(t, "wl_output.release", s.req(out.ID(), 0))
120+}
121+
122+func TestSessionLockDeniedDestroy(t *testing.T) {
123+ s := newWireEnv(t)
124+ mgr := extsessionlock.NewExtSessionLockManager(s.d.Context())
125+ s.bind(1, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
126+ lock, err := mgr.Lock()
127+ noerr(t, err)
128+ wantWords(t, "lock", s.req(mgr.ID(), 1), lock.ID())
129+ var locked, finished bool
130+ lock.OnLocked(func() { locked = true })
131+ lock.OnFinished(func() { finished = true })
132+ s.event(lock.ID(), 1)
133+ if locked || !finished {
134+ t.Fatalf("locked=%t finished=%t", locked, finished)
135+ }
136+ noerr(t, s.d.Context().CheckProxy(lock))
137+ noerr(t, lock.Destroy()) // never locked: destroy, not unlock_and_destroy
138+ wantWords(t, "denied.destroy", s.req(lock.ID(), 0))
139+ if err := lock.UnlockAndDestroy(); err == nil {
140+ t.Fatal("second destructor succeeded")
141+ }
142+ s.noRequest()
143+ // Destroying one child must not invalidate the manager or its next child.
144+ noerr(t, s.d.Context().CheckProxy(mgr))
145+ next, err := mgr.Lock()
146+ noerr(t, err)
147+ wantWords(t, "next lock", s.req(mgr.ID(), 1), next.ID())
148+ noerr(t, next.Destroy())
149+ wantWords(t, "next.destroy", s.req(next.ID(), 0))
150+ noerr(t, mgr.Destroy())
151+ wantWords(t, "manager.destroy", s.req(mgr.ID(), 0))
152+}
153+
154+func TestSessionLockConcurrentDestructors(t *testing.T) {
155+ s := newWireEnv(t)
156+ mgr := extsessionlock.NewExtSessionLockManager(s.d.Context())
157+ s.bind(1, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
158+ lock, err := mgr.Lock()
159+ noerr(t, err)
160+ wantWords(t, "lock", s.req(mgr.ID(), 1), lock.ID())
161+ s.event(lock.ID(), 1)
162+ var wg sync.WaitGroup
163+ results := make(chan error, 8)
164+ for range 8 {
165+ wg.Add(1)
166+ go func() { defer wg.Done(); results <- lock.Destroy() }()
167+ }
168+ wg.Wait()
169+ close(results)
170+ successes := 0
171+ for err := range results {
172+ if err == nil {
173+ successes++
174+ }
175+ }
176+ if successes != 1 {
177+ t.Fatalf("successful destructors=%d, want 1", successes)
178+ }
179+ wantWords(t, "single destructor", s.req(lock.ID(), 0))
180+ s.noRequest()
181+}
182+
183+func TestSessionLockMalformedEvents(t *testing.T) {
184+ for _, tc := range []struct {
185+ name string
186+ surface bool
187+ op uint16
188+ body []byte
189+ }{
190+ {"locked trailing word", false, 0, wordBytes(1)},
191+ {"finished trailing word", false, 1, wordBytes(1)},
192+ {"configure missing height", true, 0, wordBytes(1, 800)},
193+ {"configure trailing word", true, 0, wordBytes(1, 800, 600, 1)},
194+ } {
195+ t.Run(tc.name, func(t *testing.T) {
196+ s := newWireEnv(t)
197+ mgr := extsessionlock.NewExtSessionLockManager(s.d.Context())
198+ s.bind(1, extsessionlock.ExtSessionLockManagerInterface, 1, 1, mgr)
199+ lock, err := mgr.Lock()
200+ noerr(t, err)
201+ s.req(mgr.ID(), 1)
202+ id := lock.ID()
203+ called := false
204+ lock.OnLocked(func() { called = true })
205+ lock.OnFinished(func() { called = true })
206+ if tc.surface {
207+ ls, err := lock.GetLockSurface(s.surface(), s.output())
208+ noerr(t, err)
209+ s.req(lock.ID(), 1)
210+ ls.OnConfigure(func(_, _, _ uint32) { called = true })
211+ id = ls.ID()
212+ }
213+ send(t, s.p, payload(id, tc.op, tc.body...))
214+ if err := s.d.Dispatch(); !errors.Is(err, wlturbo.ErrMalformedFrame) {
215+ t.Fatalf("malformed event: %v", err)
216+ }
217+ if called {
218+ t.Fatal("malformed event reached a handler")
219+ }
220+ })
221+ }
222+}

Keyboard shortcuts

Single-key shortcuts are on. ctrl k and esc work whatever this says.

ctrl k :
go to a section, branch, tag, file or repository
?
this list
j k
move the row cursor down / up
enter
open the row under the cursor; on Files, a directory opens or closes in place
↑ ↓ ← → home end
in the file tree (focus on a row): previous / next row, close / open a directory or go to its parent / first entry, first / last row. They never open a file
l h
on Files: open a directory or a file / close a directory or go up to its parent, then to the parent page. Elsewhere: into the side panel (on a merge request, its files) / back to the content; there j k move between its controls
g g G
first / last row
/
filter the list; on Files, find a file anywhere in the repository (esc clears, enter opens the best match)
b
switch branch or tag
g s g f g c g b g m g i g r g a
tabs: summary, files, commits, branches & tags, merge requests, issues, releases, actions (when available)
g h
home
w
wide mode: use the whole width of the screen, or not (remembered)
y
copy a permalink pinned to the commit
d u x
diff: split / unified / collapse or expand all
e E
diff: the whole file in view / every file, with the lines the hunks hide
n
merge request: next note in the diff
esc
close a dialog, leave a field

Branches 1

Tags 8

↑↓ moveenter openesc close