Skip to content

Commit bdf6792

Browse files
peer review
1 parent 2451da9 commit bdf6792

File tree

13 files changed

+60
-244
lines changed

13 files changed

+60
-244
lines changed

druid-shell/examples/empty_window.rs

Lines changed: 0 additions & 136 deletions
This file was deleted.

druid-shell/src/backend/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ pub use x11::*;
3535
#[cfg(all(feature = "x11", any(target_os = "linux", target_os = "openbsd")))]
3636
pub(crate) mod shared;
3737

38-
#[cfg(all(feature = "wayland", target_os = "linux"))]
38+
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "openbsd")))]
3939
mod wayland;
40-
#[cfg(all(feature = "wayland", target_os = "linux"))]
40+
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "openbsd")))]
4141
pub use wayland::*;
42-
#[cfg(all(feature = "wayland", target_os = "linux"))]
42+
#[cfg(all(feature = "wayland", any(target_os = "linux", target_os = "openbsd")))]
4343
pub(crate) mod shared;
4444

4545
#[cfg(all(

druid-shell/src/backend/shared/keyboard.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@
1818
use keyboard_types::{Code, Location};
1919

2020
#[cfg(any(
21-
all(feature = "x11", any(target_os = "linux", target_os = "openbsd")),
22-
all(feature = "wayland", target_os = "linux"),
21+
all(
22+
any(feature = "x11", feature = "wayland"),
23+
any(target_os = "linux", target_os = "openbsd")
24+
),
2325
target_os = "macos"
2426
))]
2527
/// Map key code to location.

druid-shell/src/backend/wayland/application.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,10 +106,6 @@ pub(crate) struct ApplicationData {
106106
/// necessary, but it negligable cost).
107107
pub(super) outputs: Rc<RefCell<BTreeMap<u32, outputs::Meta>>>,
108108
pub(super) seats: Rc<RefCell<BTreeMap<u32, Rc<RefCell<Seat>>>>>,
109-
/// Handles to any surfaces that have been created.
110-
///
111-
/// This is where the window data is owned. Other handles should be weak.
112-
// pub(super) surfaces: RefCell<im::OrdMap<u32, std::sync::Arc<surfaces::surface::Data>>>,
113109

114110
/// Handles to any surfaces that have been created.
115111
pub(super) handles: RefCell<im::OrdMap<u64, WindowHandle>>,
@@ -257,6 +253,10 @@ impl Application {
257253
wayland: env,
258254
});
259255

256+
for m in outputs::current()? {
257+
app_data.outputs.borrow_mut().insert(m.id(), m);
258+
}
259+
260260
// Collect the supported image formats.
261261
wl_shm.quick_assign(with_cloned!(app_data; move |d1, event, d3| {
262262
tracing::debug!("shared memory events {:?} {:?} {:?}", d1, event, d3);

druid-shell/src/backend/wayland/clipboard.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,8 @@ impl Data {
4848
fn receive(&self, mimetype: &str) -> Option<Offer> {
4949
for offer in self.current.borrow().iter() {
5050
if !offer.mimetype.starts_with(mimetype) {
51-
// tracing::debug!("compared {:?} {:?}", offer.mimetype, mimetype);
5251
continue;
5352
}
54-
// tracing::debug!("retrieving {:?} {:?}", offer.mimetype, mimetype);
5553
return Some(offer.clone());
5654
}
5755
None

druid-shell/src/backend/wayland/display.rs

Lines changed: 8 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ use wayland_client as wlc;
55
use wayland_client::protocol::wl_registry;
66
use wayland_protocols::xdg_shell::client::xdg_wm_base;
77

8+
type GlobalEventConsumer = dyn Fn(&wlc::GlobalEvent, &wlc::Attached<wl_registry::WlRegistry>, &wlc::DispatchData)
9+
+ 'static;
10+
811
#[derive(Clone)]
912
pub struct GlobalEventSubscription {
1013
id: u64,
11-
sub: std::sync::Arc<dyn GlobalEventConsumer>,
14+
sub: std::sync::Arc<GlobalEventConsumer>,
1215
}
1316

1417
impl GlobalEventSubscription {
@@ -18,22 +21,20 @@ impl GlobalEventSubscription {
1821
}
1922
}
2023

21-
impl GlobalEventConsumer for GlobalEventSubscription {
24+
impl GlobalEventSubscription {
2225
fn consume(
2326
&self,
2427
event: &wlc::GlobalEvent,
2528
registry: &wlc::Attached<wl_registry::WlRegistry>,
2629
ctx: &wlc::DispatchData,
2730
) {
28-
self.sub.consume(event, registry, ctx)
31+
(self.sub)(event, registry, ctx)
2932
}
3033
}
3134

3235
impl<X> From<X> for GlobalEventSubscription
3336
where
34-
X: Fn(&wlc::GlobalEvent, &wlc::Attached<wl_registry::WlRegistry>, &wlc::DispatchData)
35-
+ GlobalEventConsumer
36-
+ 'static,
37+
X: Fn(&wlc::GlobalEvent, &wlc::Attached<wl_registry::WlRegistry>, &wlc::DispatchData) + 'static,
3738
{
3839
fn from(closure: X) -> Self {
3940
Self {
@@ -43,34 +44,11 @@ where
4344
}
4445
}
4546

46-
impl<X> GlobalEventConsumer for X
47-
where
48-
X: Fn(&wlc::GlobalEvent, &wlc::Attached<wl_registry::WlRegistry>, &wlc::DispatchData) + 'static,
49-
{
50-
fn consume(
51-
&self,
52-
event: &wlc::GlobalEvent,
53-
registry: &wlc::Attached<wl_registry::WlRegistry>,
54-
ctx: &wlc::DispatchData,
55-
) {
56-
self(event, registry, ctx)
57-
}
58-
}
59-
6047
pub trait GlobalEventDispatch {
6148
fn subscribe(&self, sub: impl Into<GlobalEventSubscription>) -> GlobalEventSubscription;
6249
fn release(&self, s: &GlobalEventSubscription);
6350
}
6451

65-
pub trait GlobalEventConsumer {
66-
fn consume(
67-
&self,
68-
event: &wlc::GlobalEvent,
69-
registry: &wlc::Attached<wl_registry::WlRegistry>,
70-
ctx: &wlc::DispatchData,
71-
);
72-
}
73-
7452
pub(super) struct Dispatcher {
7553
incr: crate::Counter,
7654
subscriptions: std::cell::RefCell<BTreeMap<u64, GlobalEventSubscription>>,
@@ -85,18 +63,16 @@ impl Default for Dispatcher {
8563
}
8664
}
8765

88-
impl GlobalEventConsumer for Dispatcher {
66+
impl Dispatcher {
8967
fn consume(
9068
&self,
9169
event: &wlc::GlobalEvent,
9270
registry: &wlc::Attached<wl_registry::WlRegistry>,
9371
ctx: &wlc::DispatchData,
9472
) {
95-
// tracing::info!("global event initiated {:?} {:?}", registry, event);
9673
for (_, sub) in self.subscriptions.borrow().iter() {
9774
sub.consume(event, registry, ctx);
9875
}
99-
// tracing::info!("global event completed {:?} {:?}", registry, event);
10076
}
10177
}
10278

@@ -120,12 +96,6 @@ pub(super) struct Environment {
12096
dispatcher: std::sync::Arc<Dispatcher>,
12197
}
12298

123-
// because we have the global environment we need to mark these as safe/send.
124-
// strictly speaking we should probably guard the access to the various fields
125-
// behind a mutex, but in practice we are not actually accessing across threads.
126-
unsafe impl Sync for Environment {}
127-
unsafe impl Send for Environment {}
128-
12999
impl GlobalEventDispatch for Environment {
130100
fn subscribe(&self, sub: impl Into<GlobalEventSubscription>) -> GlobalEventSubscription {
131101
self.dispatcher.subscribe(sub)

druid-shell/src/backend/wayland/outputs/output.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@ use wayland_client::protocol::wl_registry;
77
use wayland_protocols::unstable::xdg_output::v1::client::zxdg_output_manager_v1;
88
use wayland_protocols::unstable::xdg_output::v1::client::zxdg_output_v1;
99

10-
pub trait Consumer {
11-
fn consume(
12-
&mut self,
13-
obj: &wlc::Main<wl_output::WlOutput>,
14-
event: &wl_output::Event,
15-
) -> Option<outputs::Meta>;
16-
}
17-
1810
pub fn detect(
1911
env: &impl display::GlobalEventDispatch,
2012
) -> Result<calloop::channel::Channel<outputs::Event>, error::Error> {
@@ -155,7 +147,7 @@ struct Meta {
155147
meta: outputs::Meta,
156148
}
157149

158-
impl Consumer for Meta {
150+
impl Meta {
159151
/// Incorporate update data from the server for this output.
160152
fn consume(
161153
&mut self,

0 commit comments

Comments
 (0)