Skip to content

Commit 4145711

Browse files
peer review
1 parent 2451da9 commit 4145711

File tree

11 files changed

+57
-105
lines changed

11 files changed

+57
-105
lines changed

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,

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

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,19 @@ const BTN_MIDDLE: u32 = 0x112;
1818

1919
// used to keep track of click event counts.
2020
#[derive(Debug, Clone)]
21-
struct ClickDebouncer(std::time::Instant, u8, mouse::MouseButton);
21+
struct ClickDebouncer {
22+
timestamp: std::time::Instant,
23+
count: u8,
24+
previous: mouse::MouseButton,
25+
}
2226

2327
impl Default for ClickDebouncer {
2428
fn default() -> Self {
25-
Self(std::time::Instant::now(), 1, mouse::MouseButton::None)
29+
Self {
30+
timestamp: std::time::Instant::now(),
31+
count: 1,
32+
previous: mouse::MouseButton::None,
33+
}
2634
}
2735
}
2836

@@ -34,28 +42,32 @@ impl ClickDebouncer {
3442
const THRESHOLD: std::time::Duration = std::time::Duration::from_millis(500);
3543

3644
fn reset(ts: std::time::Instant, btn: mouse::MouseButton) -> Self {
37-
Self(ts, 1, btn)
45+
Self {
46+
timestamp: ts,
47+
count: 1,
48+
previous: btn,
49+
}
3850
}
3951

4052
fn debounce(&mut self, current: MouseEvtKind) -> MouseEvtKind {
4153
let ts = std::time::Instant::now();
4254

4355
// reset counting and button.
44-
if self.0 + ClickDebouncer::THRESHOLD < ts {
56+
if self.timestamp + ClickDebouncer::THRESHOLD < ts {
4557
*self = ClickDebouncer::default();
4658
}
4759

4860
match current {
49-
MouseEvtKind::Up(mut evt) if self.2 == evt.button => {
50-
evt.count = self.1;
61+
MouseEvtKind::Up(mut evt) if self.previous == evt.button => {
62+
evt.count = self.count;
5163
MouseEvtKind::Up(evt)
5264
}
53-
MouseEvtKind::Down(mut evt) if self.2 == evt.button => {
54-
self.1 += 1;
55-
evt.count = self.1;
65+
MouseEvtKind::Down(mut evt) if self.previous == evt.button => {
66+
self.count += 1;
67+
evt.count = self.count;
5668
MouseEvtKind::Down(evt)
5769
}
58-
MouseEvtKind::Down(evt) if self.2 != evt.button => {
70+
MouseEvtKind::Down(evt) if self.previous != evt.button => {
5971
*self = ClickDebouncer::reset(ts, evt.button);
6072
MouseEvtKind::Down(evt)
6173
}
@@ -250,15 +262,7 @@ impl Pointer {
250262
appdata.pointer.push(PointerEvent::Axis { axis, value });
251263
}
252264
wl_pointer::Event::Frame => {
253-
let winhandle = match appdata.acquire_current_window() {
254-
Some(w) => w,
255-
None => {
256-
tracing::warn!("dropping mouse events, no window available");
257-
appdata.pointer.queued_events.borrow_mut().clear();
258-
return;
259-
}
260-
};
261-
let winhandle = match winhandle.data() {
265+
let winhandle = match appdata.acquire_current_window().and_then(|w| w.data()) {
262266
Some(w) => w,
263267
None => {
264268
tracing::warn!("dropping mouse events, no window available");

druid-shell/src/backend/wayland/surfaces/buffers.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,6 @@ impl From<Size> for RawSize {
582582
fn from(s: Size) -> Self {
583583
let width = s.width as i32;
584584
let height = s.height as i32;
585-
586585
// Sanity check
587586
assert!(width >= 0 && height >= 0);
588587

druid-shell/src/backend/wayland/surfaces/idle.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ impl std::fmt::Debug for Kind {
1111
fn fmt(&self, format: &mut std::fmt::Formatter<'_>) -> Result<(), std::fmt::Error> {
1212
match self {
1313
Kind::Callback(_) => format.debug_struct("Idle(Callback)").finish(),
14-
Kind::Token(_) => format.debug_struct("Idle(Token)").finish(),
14+
Kind::Token(token) => format
15+
.debug_struct("Idle(Token)")
16+
.field("token", &token)
17+
.finish(),
1518
}
1619
}
1720
}

druid-shell/src/backend/wayland/surfaces/surface.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ use std::cell::{Cell, RefCell};
22
use std::rc::Rc;
33
use wayland_client as wlc;
44
use wayland_client::protocol::wl_surface;
5+
use wayland_protocols::xdg_shell::client::xdg_popup;
6+
use wayland_protocols::xdg_shell::client::xdg_positioner;
7+
use wayland_protocols::xdg_shell::client::xdg_surface;
58

69
use crate::kurbo;
710
use crate::window;
@@ -566,10 +569,9 @@ impl Outputs for Dead {
566569
impl Popup for Dead {
567570
fn surface<'a>(
568571
&self,
569-
_: &'a wlc::Main<wayland_protocols::xdg_shell::client::xdg_surface::XdgSurface>,
570-
_: &'a wlc::Main<wayland_protocols::xdg_shell::client::xdg_positioner::XdgPositioner>,
571-
) -> Result<wlc::Main<wayland_protocols::xdg_shell::client::xdg_popup::XdgPopup>, error::Error>
572-
{
572+
_: &'a wlc::Main<xdg_surface::XdgSurface>,
573+
_: &'a wlc::Main<xdg_positioner::XdgPositioner>,
574+
) -> Result<wlc::Main<xdg_popup::XdgPopup>, error::Error> {
573575
tracing::warn!("popup invoked on a dead surface");
574576
Err(error::Error::InvalidParent(0))
575577
}

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

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

0 commit comments

Comments
 (0)