Skip to content

Commit 1f4f94f

Browse files
committed
Run cargo fmt
WIP Update smithay module paths WIP data offer Use WlOfferData WIP server dnd grab WIP `DndGrab` WIP dnd_requested dnd_requested WIP `Source` choose_action
1 parent d518c7d commit 1f4f94f

14 files changed

Lines changed: 490 additions & 197 deletions

File tree

Cargo.lock

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cosmic-panel-bin/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ smithay = { git = "https://github.com/smithay/smithay", default-features = false
1717
"backend_egl",
1818
"backend_drm",
1919
"renderer_gl",
20-
], rev = "20d2dac" }
20+
], rev = "89e58f7" }
2121
# sctk = { git = "https://github.com/smithay/client-toolkit", package = "smithay-client-toolkit", features = ["calloop", "xkbcommon"] }
2222
sctk.workspace = true
2323
# sctk = { package = "smithay-client-toolkit", path = "../../fork/client-toolkit", default-features = false, features = ["calloop", "xkbcommon"] }
@@ -67,3 +67,5 @@ cosmic-notifications-util = { git = "https://github.com/pop-os/cosmic-notificati
6767
wayland-backend = { version = "0.3.14", features = ["client_system"] }
6868
zbus = { version = "5.14", features = ["tokio", "p2p"] }
6969
ordered-stream = "0.2.0"
70+
futures = "0.3.31"
71+
smallvec = "1.15.1"

cosmic-panel-bin/src/iced/elements/target.rs

Lines changed: 82 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,19 @@ use super::{CosmicMappedInternal, PopupMappedInternal};
33
use crate::xdg_shell_wrapper::shared_state::GlobalState;
44

55
use anyhow::bail;
6-
use smithay::input::keyboard::KeyboardTarget;
7-
use smithay::input::pointer::PointerTarget;
8-
use smithay::input::touch::TouchTarget;
9-
use smithay::reexports::wayland_server::protocol::wl_surface::WlSurface;
10-
use smithay::utils::IsAlive;
11-
use smithay::wayland::seat::WaylandFocus;
6+
use smithay::{
7+
input::{
8+
Seat,
9+
dnd::{self, DndFocus},
10+
keyboard::KeyboardTarget,
11+
pointer::PointerTarget,
12+
touch::TouchTarget,
13+
},
14+
reexports::wayland_server::{DisplayHandle, protocol::wl_surface::WlSurface},
15+
utils::IsAlive,
16+
wayland::{seat::WaylandFocus, selection::data_device::WlOfferData},
17+
};
18+
use std::sync::Arc;
1219

1320
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
1421
pub enum SpaceTarget {
@@ -349,3 +356,72 @@ impl WaylandFocus for SpaceTarget {
349356
}
350357
}
351358
}
359+
360+
impl DndFocus<GlobalState> for SpaceTarget {
361+
type OfferData<S>
362+
= WlOfferData<S>
363+
where
364+
S: dnd::Source;
365+
366+
fn enter<S>(
367+
&self,
368+
data: &mut GlobalState,
369+
dh: &DisplayHandle,
370+
source: Arc<S>,
371+
seat: &Seat<GlobalState>,
372+
location: smithay::utils::Point<f64, smithay::utils::Logical>,
373+
serial: &smithay::utils::Serial,
374+
) -> std::option::Option<WlOfferData<S>>
375+
where
376+
S: dnd::Source,
377+
{
378+
match self {
379+
SpaceTarget::Surface(s) => DndFocus::enter(s, data, dh, source, seat, location, serial),
380+
SpaceTarget::OverflowButton(_b) => None,
381+
}
382+
}
383+
384+
fn motion<S>(
385+
&self,
386+
data: &mut GlobalState,
387+
offer: Option<&mut WlOfferData<S>>,
388+
seat: &Seat<GlobalState>,
389+
location: smithay::utils::Point<f64, smithay::utils::Logical>,
390+
time: u32,
391+
) where
392+
S: dnd::Source,
393+
{
394+
match self {
395+
SpaceTarget::Surface(s) => DndFocus::motion(s, data, offer, seat, location, time),
396+
SpaceTarget::OverflowButton(_b) => {},
397+
}
398+
}
399+
400+
fn leave<S>(
401+
&self,
402+
data: &mut GlobalState,
403+
offer: Option<&mut WlOfferData<S>>,
404+
seat: &Seat<GlobalState>,
405+
) where
406+
S: dnd::Source,
407+
{
408+
match self {
409+
SpaceTarget::Surface(s) => DndFocus::leave(s, data, offer, seat),
410+
SpaceTarget::OverflowButton(_b) => {},
411+
}
412+
}
413+
414+
fn drop<S>(
415+
&self,
416+
data: &mut GlobalState,
417+
offer: Option<&mut WlOfferData<S>>,
418+
seat: &Seat<GlobalState>,
419+
) where
420+
S: dnd::Source,
421+
{
422+
match self {
423+
SpaceTarget::Surface(s) => DndFocus::drop(s, data, offer, seat),
424+
SpaceTarget::OverflowButton(_b) => {},
425+
}
426+
}
427+
}

cosmic-panel-bin/src/space/layout.rs

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -286,8 +286,11 @@ impl PanelSpace {
286286
let (mut size, mut suggested_bounds) = w
287287
.toplevel()
288288
.map(|t| {
289-
let s = t.current_state();
290-
(s.size.unwrap_or_default(), s.bounds.unwrap_or_default())
289+
t.with_committed_state(|state| {
290+
state.map_or_else(Default::default, |state| {
291+
(state.size.unwrap_or_default(), state.bounds.unwrap_or_default())
292+
})
293+
})
291294
})
292295
.unwrap_or_else(|| {
293296
if let CosmicMappedInternal::Spacer(s) = w {
@@ -648,8 +651,10 @@ impl PanelSpace {
648651
-> f64 {
649652
for (_, w, minimize_priority, padding_shrinkable) in windows {
650653
let mut size = w.geometry().size.to_f64();
651-
let configured_size =
652-
w.toplevel().and_then(|t| t.current_state().bounds).unwrap_or_else(|| {
654+
let configured_size = w
655+
.toplevel()
656+
.and_then(|t| t.with_committed_state(|s| s.as_ref().and_then(|s| s.bounds)))
657+
.unwrap_or_else(|| {
653658
if let CosmicMappedInternal::Spacer(s) = w {
654659
s.bbox().size
655660
} else {
@@ -1214,8 +1219,9 @@ impl PanelSpace {
12141219
let suggested_bounds = w
12151220
.toplevel()
12161221
.map(|t| {
1217-
let s = t.current_state();
1218-
s.bounds.unwrap_or_default()
1222+
t.with_committed_state(|s| {
1223+
s.as_ref().and_then(|s| s.bounds).unwrap_or_default()
1224+
})
12191225
})
12201226
.unwrap();
12211227

@@ -1228,7 +1234,7 @@ impl PanelSpace {
12281234
}
12291235
let configured_size = w
12301236
.toplevel()
1231-
.and_then(|t| t.current_state().size)
1237+
.and_then(|t| t.with_committed_state(|s| s.as_ref().and_then(|s| s.size)))
12321238
.map(|s| s.to_f64())
12331239
.unwrap_or(size);
12341240
if configured_size.w >= 1. {
@@ -1801,18 +1807,18 @@ impl OverflowClientPartition {
18011807
.iter()
18021808
.filter(|ShrinkableClient { window: w, .. }| {
18031809
w.toplevel().is_some_and(|t| {
1804-
let state = t.current_state();
1810+
let bounds = t.with_committed_state(|s| s.as_ref().and_then(|s| s.bounds));
18051811
let cur_size = w.geometry().size;
18061812
if is_horizontal {
1807-
state.bounds.is_none()
1808-
|| state.bounds.is_some_and(|s| {
1813+
bounds.is_none()
1814+
|| bounds.is_some_and(|s| {
18091815
s.w != 0
18101816
|| cur_size.w.saturating_sub((s.w as f64 * scale) as i32)
18111817
> self.suggested_size as i32
18121818
})
18131819
} else {
1814-
state.bounds.is_none()
1815-
|| state.bounds.is_some_and(|s| {
1820+
bounds.is_none()
1821+
|| bounds.is_some_and(|s| {
18161822
s.h != 0
18171823
|| cur_size.h.saturating_sub((s.h as f64 * scale) as i32)
18181824
> self.suggested_size as i32
@@ -1828,20 +1834,20 @@ impl OverflowClientPartition {
18281834
self.shrinkable.is_empty() || {
18291835
self.shrinkable.iter().all(|ShrinkableClient { window: w, .. }| {
18301836
w.toplevel().is_some_and(|t| {
1831-
let state = t.current_state();
1837+
let bounds = t.with_committed_state(|s| s.as_ref().and_then(|s| s.bounds));
18321838
let cur_size = w.geometry().size;
18331839
if is_horizontal {
1834-
state.bounds.is_none()
1835-
|| state.bounds.is_some_and(|s| {
1840+
bounds.is_none()
1841+
|| bounds.is_some_and(|s| {
18361842
s.w == 0
18371843
|| cur_size
18381844
.w
18391845
.saturating_sub((s.w as f64 * scale).round() as i32)
18401846
> self.suggested_size as i32
18411847
})
18421848
} else {
1843-
state.bounds.is_none()
1844-
|| state.bounds.is_some_and(|s| {
1849+
bounds.is_none()
1850+
|| bounds.is_some_and(|s| {
18451851
s.h == 0
18461852
|| cur_size
18471853
.h

cosmic-panel-bin/src/space/render.rs

Lines changed: 37 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -133,10 +133,10 @@ impl PanelSpace {
133133
anyhow::bail!("Failed to clear panel.");
134134
};
135135

136-
_ = frame.clear(Color32F::new(0.0, 0.0, 0.0, 0.0), &[Rectangle::new(
137-
(0, 0).into(),
138-
dim,
139-
)]);
136+
_ = frame.clear(
137+
Color32F::new(0.0, 0.0, 0.0, 0.0),
138+
&[Rectangle::new((0, 0).into(), dim)],
139+
);
140140
if let Ok(sync_point) = frame.finish() {
141141
if let Err(err) = sync_point.wait() {
142142
tracing::error!("Error waiting for sync point: {:?}", err);
@@ -196,23 +196,25 @@ impl PanelSpace {
196196
}
197197

198198
w.toplevel().map(|t| {
199-
let configured_size = t.current_state().size.map(|s| {
200-
let mut r = Rectangle::new(
201-
self.space
202-
.element_location(w)
203-
.unwrap_or_default()
204-
.to_f64()
205-
.to_physical_precise_round(self.scale),
206-
s.to_f64().to_physical_precise_round(self.scale),
207-
);
208-
if r.size.w == 0 {
209-
r.size.w = i32::MAX;
210-
}
211-
if r.size.h == 0 {
212-
r.size.h = i32::MAX;
213-
}
214-
r
215-
});
199+
let configured_size = t
200+
.with_committed_state(|s| s.as_ref().and_then(|s| s.size))
201+
.map(|s| {
202+
let mut r = Rectangle::new(
203+
self.space
204+
.element_location(w)
205+
.unwrap_or_default()
206+
.to_f64()
207+
.to_physical_precise_round(self.scale),
208+
s.to_f64().to_physical_precise_round(self.scale),
209+
);
210+
if r.size.w == 0 {
211+
r.size.w = i32::MAX;
212+
}
213+
if r.size.h == 0 {
214+
r.size.h = i32::MAX;
215+
}
216+
r
217+
});
216218

217219
render_elements_from_surface_tree(
218220
renderer,
@@ -428,19 +430,20 @@ impl PanelSpace {
428430
.to_physical(self.scale)
429431
.to_i32_round();
430432

431-
let configured_size = t.current_state().size.map(|s| {
432-
let mut r = Rectangle::new(
433-
loc,
434-
s.to_f64().to_physical_precise_round(self.scale),
435-
);
436-
if r.size.w == 0 {
437-
r.size.w = i32::MAX;
438-
}
439-
if r.size.h == 0 {
440-
r.size.h = i32::MAX;
441-
}
442-
r
443-
});
433+
let configured_size =
434+
t.with_committed_state(|s| s.as_ref().and_then(|s| s.size)).map(|s| {
435+
let mut r = Rectangle::new(
436+
loc,
437+
s.to_f64().to_physical_precise_round(self.scale),
438+
);
439+
if r.size.w == 0 {
440+
r.size.w = i32::MAX;
441+
}
442+
if r.size.h == 0 {
443+
r.size.h = i32::MAX;
444+
}
445+
r
446+
});
444447
Some(
445448
render_elements_from_surface_tree(
446449
renderer,

cosmic-panel-bin/src/space/wrapper_space.rs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,9 @@ where
9494
let location = space.element_location(e)?;
9595
let mut bbox = e.geometry().to_f64();
9696
bbox.loc += location.to_f64();
97-
if let Some(configured_size) = e.toplevel().and_then(|t| t.current_state().size) {
97+
if let Some(configured_size) =
98+
e.toplevel().and_then(|t| t.with_committed_state(|s| s.as_ref().and_then(|s| s.size)))
99+
{
98100
if configured_size.w > 0 {
99101
bbox.size.w = bbox.size.w.min(configured_size.w as f64);
100102
}
@@ -708,10 +710,13 @@ impl WrapperSpace for PanelSpace {
708710
return;
709711
};
710712
if let Err(err) = pman
711-
.update_process_env(&key, vec![(
712-
"COSMIC_NOTIFICATIONS".to_string(),
713-
fd.as_raw_fd().to_string(),
714-
)])
713+
.update_process_env(
714+
&key,
715+
vec![(
716+
"COSMIC_NOTIFICATIONS".to_string(),
717+
fd.as_raw_fd().to_string(),
718+
)],
719+
)
715720
.await
716721
{
717722
error!("Failed to update process env: {}", err);

0 commit comments

Comments
 (0)