Skip to content

Commit 5b26ee3

Browse files
committed
autocommit 2026-01-12 17:45:25 CET
1 parent ded0055 commit 5b26ee3

File tree

312 files changed

+3492
-64
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

312 files changed

+3492
-64
lines changed

generator/src/formatter.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1201,6 +1201,7 @@ fn format_wayland_debug(
12011201
if !outgoing {
12021202
prefix = " ";
12031203
}
1204+
wl!(r#"{prefix}#[cfg(feature = "logging")]"#)?;
12041205
wl!(r#"{prefix}if self.core.state.log {{"#)?;
12051206
wl!(r#"{prefix} #[cold]"#)?;
12061207
w!(r#"{prefix} fn log(state: &State"#)?;

protocols/wlproxy/wlproxy-test.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,10 @@
4040
<event name="sent_object">
4141
<arg name="echo" type="new_id" interface="wlproxy_test_server_sent"/>
4242
</event>
43+
44+
<request name="create_non_forward">
45+
<arg name="id" type="new_id" interface="wlproxy_test_non_forward"/>
46+
</request>
4347
</interface>
4448

4549
<interface name="wlproxy_test_array_echo" version="1">
@@ -74,4 +78,9 @@
7478

7579
<event name="destroyed" type="destructor"/>
7680
</interface>
81+
82+
<interface name="wlproxy_test_non_forward" version="1">
83+
<request name="echo"/>
84+
<event name="echoed"/>
85+
</interface>
7786
</protocol>

wl-proxy/Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ parking_lot = "0.12.5"
2525
env_logger = "0.11.8"
2626

2727
[features]
28+
default = ["logging"]
29+
logging = []
2830

2931
# --generated start--
3032
all-protocols = [

wl-proxy/src/baseline/versions/prototyping.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ const wlproxy_test_array_echo: u32 = 1;
148148
const wlproxy_test_dummy: u32 = 1;
149149
const wlproxy_test_fd_echo: u32 = 1;
150150
const wlproxy_test_hops: u32 = 1;
151+
const wlproxy_test_non_forward: u32 = 1;
151152
const wlproxy_test_object_echo: u32 = 1;
152153
const wlproxy_test_server_sent: u32 = 1;
153154
const wp_alpha_modifier_surface_v1: u32 = 1;
@@ -574,6 +575,8 @@ pub(in super::super) const BASELINE: &StaticCopyMap<ObjectInterface, u32> = {
574575
#[cfg(test)]
575576
{ baseline[ObjectInterface::WlproxyTestHops.__linearize_d66aa8fa_6974_4651_b2b7_75291a9e7105()] = wlproxy_test_hops; }
576577
#[cfg(test)]
578+
{ baseline[ObjectInterface::WlproxyTestNonForward.__linearize_d66aa8fa_6974_4651_b2b7_75291a9e7105()] = wlproxy_test_non_forward; }
579+
#[cfg(test)]
577580
{ baseline[ObjectInterface::WlproxyTestObjectEcho.__linearize_d66aa8fa_6974_4651_b2b7_75291a9e7105()] = wlproxy_test_object_echo; }
578581
#[cfg(test)]
579582
{ baseline[ObjectInterface::WlproxyTestServerSent.__linearize_d66aa8fa_6974_4651_b2b7_75291a9e7105()] = wlproxy_test_server_sent; }

wl-proxy/src/baseline/versions/prototyping.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,7 @@ wlproxy_test_array_echo = 1
143143
wlproxy_test_dummy = 1
144144
wlproxy_test_fd_echo = 1
145145
wlproxy_test_hops = 1
146+
wlproxy_test_non_forward = 1
146147
wlproxy_test_object_echo = 1
147148
wlproxy_test_server_sent = 1
148149
wp_alpha_modifier_surface_v1 = 1

wl-proxy/src/lib.rs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,51 @@
317317
//!
318318
//! This [wlproxy_sync_v1](https://github.com/mahkoh/wl-proxy/blob/master/protocols/wlproxy/wlproxy-sync-v1.xml)
319319
//! protocol can be used for this.
320+
//!
321+
//! # Logging
322+
//!
323+
//! Messages sent in all directions can be logged. The logged messages look like this:
324+
//!
325+
//! ```text
326+
//! [1679788.330] {socket-1} client#2 -> wl_display#1.get_registry(registry: wl_registry#2)
327+
//! ^~~~~~~~~~~~~
328+
//! timestamp of the message
329+
//! ^~~~~~~~~~
330+
//! the logging prefix of the State
331+
//! ^~~~~~~~
332+
//! the sender or receiver
333+
//! ^~
334+
//! the direction of the message
335+
//! ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
336+
//! the message
337+
//! ```
338+
//!
339+
//! By default, logging is controlled by the `WL_PROXY_DEBUG` environment variable. If it
340+
//! is set to 1, messages are logged, otherwise messages are not logged. Messages are
341+
//! always written to STDERR.
342+
//!
343+
//! Applications can disable or enable logging programmatically via
344+
//! [`StateBuilder::with_logging`](state::StateBuilder::with_logging).
345+
//!
346+
//! Messages can have a prefix that is taken from the `WL_PROXY_PREFIX` environment
347+
//! variable. Applications can augment this prefix via
348+
//! [`StateBuilder::with_log_prefix`](state::StateBuilder::with_log_prefix). This can be
349+
//! used to easily distinguish these log messages from WAYLAND_DEBUG messages. The
350+
//! [`SimpleProxy`](simple::SimpleProxy) always sets the prefix to a unique identifier
351+
//! of the connection to allow distinguishing messages from different clients.
352+
//!
353+
//! Each message indicates the sender or receiver of the message. For messages sent by/to
354+
//! clients, the client is identified as `client#N`. Note that `N` does not start at 1 nor
355+
//! are the number contiguous. For messages sent by/to the compositor, the identifier is
356+
//! `server`.
357+
//!
358+
//! The symbols `->` and `<=` indicate the direction of the message.
359+
//!
360+
//! Logging can be disabled at compile time by disabling the default-enabled `logging`
361+
//! feature. This can significantly improve compile times and reduce binary size. For
362+
//! example, the wl-veil application has a program size of 6.7 MB by default but only
363+
//! 4.4 MB with logging disabled at compile time. Most programs should leave logging
364+
//! enabled to aid debuggability.
320365
321366
pub mod acceptor;
322367
pub mod client;

wl-proxy/src/object.rs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,12 @@ pub trait ObjectCoreApi {
111111
/// This ID is not reused for any other object for the lifetime of the [`State`].
112112
fn unique_id(&self) -> u64;
113113

114+
/// Returns the client ID of this object, if any.
115+
fn client_id(&self) -> Option<u32>;
116+
117+
/// Returns the server ID of this object, if any.
118+
fn server_id(&self) -> Option<u32>;
119+
114120
/// Sends a wl_display.delete_id event for this object.
115121
///
116122
/// This is similar to [`ObjectCoreApi::try_delete_id`] but logs a message instead of
@@ -162,6 +168,14 @@ impl ObjectCoreApi for ObjectCore {
162168
self.id
163169
}
164170

171+
fn client_id(&self) -> Option<u32> {
172+
self.client_obj_id.get()
173+
}
174+
175+
fn server_id(&self) -> Option<u32> {
176+
self.server_obj_id.get()
177+
}
178+
165179
fn delete_id(&self) {
166180
if let Err(e) = self.try_delete_id() {
167181
log::warn!("Could not release a client id: {}", Report::new(e));
@@ -227,6 +241,14 @@ where
227241
self.core().unique_id()
228242
}
229243

244+
fn client_id(&self) -> Option<u32> {
245+
self.core().client_id()
246+
}
247+
248+
fn server_id(&self) -> Option<u32> {
249+
self.core().server_id()
250+
}
251+
230252
fn delete_id(&self) {
231253
self.core().delete_id()
232254
}
@@ -445,9 +467,6 @@ impl ObjectCore {
445467
slf: Rc<dyn Object>,
446468
) -> Result<(), IdError> {
447469
self.check_server_destroyed()?;
448-
if let Some(id) = self.server_obj_id.get() {
449-
return Err(IdError::HasServerId(id));
450-
}
451470
let Some(server) = &self.state.server else {
452471
return Err(IdError::NoServer);
453472
};

wl-proxy/src/object/tests.rs

Lines changed: 188 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
use {
22
crate::{
33
baseline::Baseline,
4-
object::{Object, ObjectRcUtils, ObjectUtils},
4+
object::{Object, ObjectCoreApi, ObjectRcUtils, ObjectUtils},
55
protocols::{
66
wayland::wl_keyboard::WlKeyboard,
77
wlproxy_test::{
88
wlproxy_test::{WlproxyTest, WlproxyTestHandler},
9+
wlproxy_test_non_forward::{WlproxyTestNonForward, WlproxyTestNonForwardHandler},
910
wlproxy_test_server_sent::{WlproxyTestServerSent, WlproxyTestServerSentHandler},
1011
},
1112
},
@@ -77,3 +78,189 @@ fn duplicate_client_id() {
7778
tp.client_test.send_create_dummy(&dummy);
7879
tp.await_client_disconnected();
7980
}
81+
82+
#[test]
83+
fn client_object_with_server_id() {
84+
let tp = test_proxy();
85+
tp.client_state
86+
.server
87+
.as_ref()
88+
.unwrap()
89+
.outgoing
90+
.borrow_mut()
91+
.formatter()
92+
.words([1, 0, !0]);
93+
tp.client_display.new_send_sync();
94+
tp.await_client_disconnected();
95+
}
96+
97+
#[test]
98+
fn duplicate_generated_client_id() {
99+
let tp = test_proxy();
100+
let ss = tp.proxy_test.new_send_sent_object();
101+
assert!(tp.proxy_test.try_send_sent_object(&ss).is_err());
102+
}
103+
104+
#[test]
105+
fn destroyed_client() {
106+
let tp = test_proxy();
107+
tp.proxy_client.disconnect();
108+
assert!(tp.proxy_test.new_try_send_sent_object().is_err());
109+
}
110+
111+
#[test]
112+
#[should_panic(expected = "NotServerId(50)")]
113+
fn invalid_server_id() {
114+
let tp = test_proxy();
115+
tp.proxy_client
116+
.endpoint
117+
.outgoing
118+
.borrow_mut()
119+
.formatter()
120+
.words([
121+
tp.proxy_test.client_id().unwrap(),
122+
1, // event sent_object
123+
50, // id
124+
]);
125+
tp.sync();
126+
}
127+
128+
#[test]
129+
#[should_panic(expected = "ServerIdInUse(4294967295)")]
130+
fn duplicate_server_id() {
131+
let tp = test_proxy();
132+
for _ in 0..2 {
133+
tp.proxy_client
134+
.endpoint
135+
.outgoing
136+
.borrow_mut()
137+
.formatter()
138+
.words([
139+
tp.proxy_test.client_id().unwrap(),
140+
1, // event sent_object
141+
!0, // id
142+
]);
143+
}
144+
tp.sync();
145+
}
146+
147+
#[test]
148+
fn server_destroyed() {
149+
let tp = test_proxy();
150+
tp.client_state.destroy();
151+
assert!(tp.client_display.new_try_send_sync().is_err());
152+
}
153+
154+
#[test]
155+
fn get_handler() {
156+
struct H;
157+
impl WlproxyTestHandler for H {}
158+
159+
let tp = test_proxy();
160+
tp.client_test.set_handler(H);
161+
tp.client_test.get_handler_mut::<H>();
162+
tp.client_test.get_handler_ref::<H>();
163+
assert!(tp.client_test.try_get_handler_mut::<H>().is_ok());
164+
assert!(tp.client_test.try_get_handler_ref::<H>().is_ok());
165+
let handler = tp.client_test.get_handler_ref::<H>();
166+
assert!(tp.client_test.try_get_handler_ref::<H>().is_ok());
167+
assert!(tp.client_test.try_get_handler_mut::<H>().is_err());
168+
drop(handler);
169+
let _handler = tp.client_test.get_handler_mut::<H>();
170+
assert!(tp.client_test.try_get_handler_ref::<H>().is_err());
171+
assert!(tp.client_test.try_get_handler_mut::<H>().is_err());
172+
}
173+
174+
#[test]
175+
fn state() {
176+
let tp = test_proxy();
177+
assert!(Rc::ptr_eq(&tp.client_state, tp.client_test.state()));
178+
}
179+
180+
#[test]
181+
fn client() {
182+
let tp = test_proxy();
183+
assert!(Rc::ptr_eq(
184+
&tp.proxy_client,
185+
tp.proxy_test.client().as_ref().unwrap()
186+
));
187+
}
188+
189+
#[test]
190+
fn version() {
191+
let tp = test_proxy();
192+
assert_eq!(tp.client_test.version(), 1);
193+
}
194+
195+
#[test]
196+
fn client_id() {
197+
let tp = test_proxy();
198+
assert_eq!(
199+
tp.client_test.server_id().unwrap(),
200+
tp.proxy_test.client_id().unwrap()
201+
);
202+
}
203+
204+
#[test]
205+
fn forward() {
206+
struct Nfh(bool);
207+
impl WlproxyTestNonForwardHandler for Nfh {
208+
fn handle_echoed(&mut self, _slf: &Rc<WlproxyTestNonForward>) {
209+
self.0 = true;
210+
}
211+
}
212+
213+
struct Th1;
214+
impl WlproxyTestHandler for Th1 {
215+
fn handle_create_non_forward(
216+
&mut self,
217+
_slf: &Rc<WlproxyTest>,
218+
id: &Rc<WlproxyTestNonForward>,
219+
) {
220+
id.set_forward_to_server(false);
221+
}
222+
}
223+
224+
struct Th2;
225+
impl WlproxyTestHandler for Th2 {
226+
fn handle_create_non_forward(
227+
&mut self,
228+
_slf: &Rc<WlproxyTest>,
229+
id: &Rc<WlproxyTestNonForward>,
230+
) {
231+
id.set_forward_to_client(false);
232+
}
233+
}
234+
235+
let tp = test_proxy();
236+
237+
let non_forward = tp.client_test.new_send_create_non_forward();
238+
non_forward.set_handler(Nfh(false));
239+
non_forward.send_echo();
240+
tp.sync();
241+
assert!(non_forward.get_handler_mut::<Nfh>().0);
242+
243+
tp.proxy_test.set_handler(Th1);
244+
245+
let non_forward = tp.client_test.new_send_create_non_forward();
246+
non_forward.set_handler(Nfh(false));
247+
non_forward.send_echo();
248+
tp.sync();
249+
assert!(!non_forward.get_handler_mut::<Nfh>().0);
250+
251+
tp.proxy_test.set_handler(Th2);
252+
253+
let non_forward = tp.client_test.new_send_create_non_forward();
254+
non_forward.set_handler(Nfh(false));
255+
non_forward.send_echo();
256+
tp.sync();
257+
assert!(!non_forward.get_handler_mut::<Nfh>().0);
258+
259+
tp.proxy_test.unset_handler();
260+
261+
let non_forward = tp.client_test.new_send_create_non_forward();
262+
non_forward.set_handler(Nfh(false));
263+
non_forward.send_echo();
264+
tp.sync();
265+
assert!(non_forward.get_handler_mut::<Nfh>().0);
266+
}

0 commit comments

Comments
 (0)