Skip to content

Commit 78a720d

Browse files
committed
fix: dnd improvements
1 parent 0c07b79 commit 78a720d

8 files changed

Lines changed: 53 additions & 74 deletions

File tree

cosmic-panel-bin/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ fn main() -> Result<()> {
8787
let usage = "USAGE: cosmic-panel";
8888
let config = match arg.as_ref().map(|s| &s[..]) {
8989
Some(arg) if arg == "--help" || arg == "-h" => {
90-
println!("{}", usage);
9190
std::process::exit(1);
9291
},
9392
None => match cosmic_panel_config::CosmicPanelContainerConfig::load() {
@@ -101,7 +100,6 @@ fn main() -> Result<()> {
101100
},
102101
},
103102
_ => {
104-
println!("{}", usage);
105103
std::process::exit(1);
106104
},
107105
};

cosmic-panel-bin/src/xdg_shell_wrapper/client/handlers/compositor.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,19 @@ impl CompositorHandler for GlobalState {
2828
time: u32,
2929
) {
3030
// TODO proxied layer surfaces
31-
if let Some(seat) = self
32-
.server_state
33-
.seats
34-
.iter_mut()
35-
.find(|s| s.client.dnd_icon.iter().any(|dnd_icon| &dnd_icon.1 == surface))
36-
{
37-
seat.client.dnd_icon.as_mut().unwrap().4 = Some(time);
31+
if let Some((icon, s_surface)) = self.server_state.seats.iter_mut().find_map(|s| {
32+
s.client
33+
.dnd_icon
34+
.iter_mut()
35+
.find(|dnd_icon| &dnd_icon.surface == surface)
36+
.map(|dnd_icon| (dnd_icon, s.server.dnd_icon.clone()))
37+
}) {
38+
icon.has_frame = true;
39+
if let Some(s_surface) = s_surface
40+
&& icon.egl_surface.is_none()
41+
{
42+
smithay::wayland::compositor::CompositorHandler::commit(self, &s_surface);
43+
}
3844
self.draw_dnd_icon();
3945
} else {
4046
self.space.frame(surface, time);

cosmic-panel-bin/src/xdg_shell_wrapper/client/handlers/data_device/data_device.rs

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ impl DataDeviceHandler for GlobalState {
4040
_qh: &sctk::reexports::client::QueueHandle<Self>,
4141
data_device: &WlDataDevice,
4242
) {
43-
println!("selection");
44-
4543
let seat = match self
4644
.server_state
4745
.seats
@@ -72,7 +70,6 @@ impl DataDeviceHandler for GlobalState {
7270
mime_types,
7371
(),
7472
);
75-
println!("set");
7673
}
7774

7875
fn enter(
@@ -84,8 +81,6 @@ impl DataDeviceHandler for GlobalState {
8481
_y: f64,
8582
surface: &WlSurface,
8683
) {
87-
println!("Enter");
88-
8984
let seat = match self
9085
.server_state
9186
.seats
@@ -134,7 +129,6 @@ impl DataDeviceHandler for GlobalState {
134129
} else if c_action.contains(ClientDndAction::Ask) {
135130
dnd_actions.push(DndAction::Ask);
136131
}
137-
dbg!(&dnd_actions);
138132

139133
let metadata = SourceMetadata { mime_types, dnd_actions };
140134
let (x, y) = (offer.x, offer.y);
@@ -148,27 +142,11 @@ impl DataDeviceHandler for GlobalState {
148142
offer.surface.clone(),
149143
&ptr,
150144
);
151-
dbg!(seat.client.next_dnd_offer_is_mine);
152145

153146
// TODO: touch vs pointer start data
154147
if !seat.client.next_dnd_offer_is_mine {
155148
let focus = server_focus;
156-
eprintln!("START DND");
157-
/* TODO start server drag
158-
start_dnd(
159-
&self.server_state.display_handle.clone(),
160-
&seat.server.seat.clone(),
161-
self,
162-
SERIAL_COUNTER.next_serial(),
163-
Some(GrabStartData {
164-
focus: focus.map(|f| (f.surface, f.s_pos.to_f64())),
165-
button: 0x110, // assume left button for now, maybe there is another way..
166-
location: (x, y).into(),
167-
}),
168-
None,
169-
metadata,
170-
);
171-
*/
149+
172150
let pointer_start_data = GrabStartData {
173151
focus: focus.map(|f| (f.surface, f.s_pos.to_f64())),
174152
button: 0x110, // assume left button for now, maybe there is another way..
@@ -179,7 +157,6 @@ impl DataDeviceHandler for GlobalState {
179157
use smithay::input::dnd::DnDGrab;
180158
use smithay::input::pointer::Focus;
181159
let source = ServerGrabSource { metadata, dnd_offer: offer };
182-
dbg!("START DND GRAB");
183160
let dnd_grab = DnDGrab::new_pointer(
184161
&self.server_state.display_handle,
185162
pointer_start_data,
@@ -189,7 +166,7 @@ impl DataDeviceHandler for GlobalState {
189166
pointer.set_grab(self, dnd_grab, SERIAL_COUNTER.next_serial(), Focus::Keep);
190167
}
191168
} else {
192-
dbg!("Internal DND not starting server drag");
169+
tracing::info!("Internal DND not starting server drag");
193170
}
194171
}
195172

@@ -199,7 +176,6 @@ impl DataDeviceHandler for GlobalState {
199176
qh: &sctk::reexports::client::QueueHandle<Self>,
200177
data_device: &WlDataDevice,
201178
) {
202-
println!("Leave");
203179
let seat = match self
204180
.server_state
205181
.seats
@@ -251,7 +227,6 @@ impl DataDeviceHandler for GlobalState {
251227
_x: f64,
252228
_y: f64,
253229
) {
254-
// println!("Motion");
255230
// treat it as pointer motion
256231
let seat = match self
257232
.server_state
@@ -303,7 +278,6 @@ impl DataDeviceHandler for GlobalState {
303278
qh: &sctk::reexports::client::QueueHandle<Self>,
304279
data_device: &WlDataDevice,
305280
) {
306-
println!("Drop performed");
307281
// treat it as pointer button release
308282
let seat = match self
309283
.server_state

cosmic-panel-bin/src/xdg_shell_wrapper/client/state.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,15 @@ use super::handlers::wp_fractional_scaling::FractionalScalingManager;
6262
use super::handlers::wp_security_context::SecurityContextManager;
6363
use super::handlers::wp_viewporter::ViewporterState;
6464

65+
#[derive(Debug)]
66+
pub(crate) struct DndIcon {
67+
pub(crate) egl_surface: Option<EGLSurface>,
68+
pub(crate) surface: WlSurface,
69+
pub(crate) output_tracker: OutputDamageTracker,
70+
pub(crate) is_ready: bool,
71+
pub(crate) has_frame: bool,
72+
}
73+
6574
#[derive(Debug)]
6675
pub(crate) struct ClientSeat {
6776
pub(crate) _seat: WlSeat,
@@ -78,8 +87,7 @@ pub(crate) struct ClientSeat {
7887
pub(crate) selection_offer: Option<SelectionOffer>,
7988
pub(crate) next_selection_offer_is_mine: bool,
8089
pub(crate) next_dnd_offer_is_mine: bool,
81-
pub(crate) dnd_icon:
82-
Option<(Option<EGLSurface>, WlSurface, OutputDamageTracker, bool, Option<u32>)>,
90+
pub(crate) dnd_icon: Option<DndIcon>,
8391
}
8492

8593
impl ClientSeat {

cosmic-panel-bin/src/xdg_shell_wrapper/server/handlers/compositor.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,6 @@ impl CompositorHandler for GlobalState {
243243
}
244244
}
245245
} else if role == "dnd_icon".into() {
246-
info!("dnd_icon commit");
247246
// render dnd icon to the active dnd icon surface
248247
on_commit_buffer_handler::<GlobalState>(surface);
249248
let seat = match self
@@ -259,11 +258,10 @@ impl CompositorHandler for GlobalState {
259258
},
260259
};
261260
if let Some(c_icon) = seat.client.dnd_icon.as_mut() {
262-
dbg!("Committing DND icon");
263261
let size = bbox_from_surface_tree(surface, (0, 0)).size;
264262

265263
if let Some(renderer) = self.space.renderer() {
266-
match c_icon.0.as_mut() {
264+
match c_icon.egl_surface.as_mut() {
267265
Some(egl_surface) => {
268266
_ = unsafe {
269267
renderer.egl_context().make_current_with_surface(egl_surface)
@@ -274,7 +272,7 @@ impl CompositorHandler for GlobalState {
274272
}
275273
},
276274
None => {
277-
let c_surface = &c_icon.1;
275+
let c_surface = &c_icon.surface;
278276
let client_egl_surface = unsafe {
279277
ClientEglSurface::new(
280278
WlEglSurface::new(c_surface.id(), size.w.max(1), size.h.max(1))
@@ -299,20 +297,20 @@ impl CompositorHandler for GlobalState {
299297
renderer.egl_context().make_current_with_surface(&egl_surface)
300298
};
301299
_ = renderer.bind(&mut egl_surface);
302-
c_icon.0 = Some(egl_surface);
300+
c_icon.egl_surface = Some(egl_surface);
303301
},
304302
};
305303

306-
c_icon.2 = OutputDamageTracker::new(
304+
c_icon.output_tracker = OutputDamageTracker::new(
307305
(size.w.max(1), size.h.max(1)),
308306
self.space.space_list[0].scale,
309307
Transform::Flipped180,
310308
);
311309
}
312310

313-
c_icon.3 = true;
314-
c_icon.1.commit();
315-
c_icon.1.frame(&self.client_state.queue_handle, c_icon.1.clone());
311+
c_icon.is_ready = true;
312+
c_icon.surface.commit();
313+
c_icon.surface.frame(&self.client_state.queue_handle, c_icon.surface.clone());
316314
}
317315
} else if role == "subsurface".into() {
318316
on_commit_buffer_handler::<GlobalState>(surface);

cosmic-panel-bin/src/xdg_shell_wrapper/server/handlers/mod.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,6 @@ impl DataDeviceHandler for GlobalState {
231231
client_preferred |= ClientDndAction::Ask;
232232
}
233233
offer.set_actions(client_actions, client_preferred);
234-
dbg!("set actions", client_actions, client_preferred);
235234
preferred
236235
}
237236
}
@@ -273,15 +272,11 @@ impl WaylandDndGrabHandler for GlobalState {
273272
) {
274273
// TODO icon
275274

276-
println!("FOO dnd_requested");
277-
278275
let seat = match self.server_state.seats.iter_mut().find(|s| s.server.seat == seat) {
279276
Some(s) => s,
280277
None => return,
281278
};
282279

283-
dbg!("FOO DND REQUESTED 2");
284-
285280
if let Some(metadata) = source.metadata() {
286281
seat.client.next_dnd_offer_is_mine = true;
287282
let mut actions = ClientDndAction::empty();
@@ -294,7 +289,6 @@ impl WaylandDndGrabHandler for GlobalState {
294289
if metadata.dnd_actions.contains(&DndAction::Ask) {
295290
actions |= ClientDndAction::Ask;
296291
}
297-
dbg!(&metadata.mime_types);
298292

299293
let dnd_source = self.client_state.data_device_manager.create_drag_and_drop_source(
300294
&self.client_state.queue_handle,
@@ -310,38 +304,38 @@ impl WaylandDndGrabHandler for GlobalState {
310304
.create_surface(&self.client_state.queue_handle)
311305
});
312306

313-
dbg!("FOO DND CLIENT START");
314307
dnd_source.start_drag(
315308
&seat.client.data_device,
316309
&focus.0,
317310
c_icon_surface.as_ref(),
318311
seat.client.get_serial_of_last_seat_event(),
319312
);
320313
if let Some(client_surface) = c_icon_surface.as_ref() {
321-
dbg!("FOO DND ICON SURFACE CREATED");
322314
client_surface.frame(&self.client_state.queue_handle, client_surface.clone());
323315
client_surface.commit();
324316

325-
seat.client.dnd_icon = Some((
326-
None,
327-
client_surface.clone(),
328-
OutputDamageTracker::new((32, 32), 1., Transform::Flipped180),
329-
false,
330-
Some(0),
331-
));
317+
seat.client.dnd_icon = Some(DndIcon {
318+
surface: client_surface.clone(),
319+
egl_surface: None,
320+
output_tracker: OutputDamageTracker::new(
321+
(32, 32),
322+
self.space.space_list[0].scale,
323+
Transform::Flipped180,
324+
),
325+
is_ready: false,
326+
has_frame: false,
327+
});
332328
}
333329
}
334330
seat.client.dnd_source = Some(dnd_source);
335331
}
336332

337-
dbg!("FOO DND REQUESTED 3");
338333
//seat.server.dnd_source = source;
339334
seat.server.dnd_icon = icon;
340335

341336
let seat = seat.server.seat.clone();
342337
match type_ {
343338
GrabType::Pointer => {
344-
dbg!("Starting server pointer grab for DND");
345339
let pointer = seat.get_pointer().unwrap();
346340
let start_data = pointer.grab_start_data().unwrap();
347341
pointer.set_grab(
@@ -426,7 +420,7 @@ impl ServerDndGrabHandler for GlobalState {
426420

427421
use sctk::data_device_manager::data_offer::DragOffer;
428422
// TODO rename
429-
use crate::xdg_shell_wrapper::client_state::ClientSeat;
423+
use crate::xdg_shell_wrapper::client_state::{ClientSeat, DndIcon};
430424
pub(crate) struct ServerGrabSource {
431425
pub metadata: smithay::input::dnd::SourceMetadata,
432426
pub dnd_offer: DragOffer,

cosmic-panel-bin/src/xdg_shell_wrapper/server/state.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ pub struct ServerState {
6666
pub(crate) _fractional_scale_state: FractionalScaleManagerState,
6767
pub(crate) _viewporter_state: ViewporterState,
6868
pub(crate) corner_radius_state: CornerRadiusState,
69-
pub(crate) background_effect_state: BackgroundEffectState,
69+
pub(crate) _background_effect_state: BackgroundEffectState,
7070
}
7171

7272
impl ServerState {
@@ -89,7 +89,7 @@ impl ServerState {
8989
_fractional_scale_state: FractionalScaleManagerState::new::<GlobalState>(&dh),
9090
_viewporter_state: ViewporterState::new::<GlobalState>(&dh),
9191
corner_radius_state: CornerRadiusState::new::<GlobalState>(&dh),
92-
background_effect_state: BackgroundEffectState::new::<GlobalState>(&dh),
92+
_background_effect_state: BackgroundEffectState::new::<GlobalState>(&dh),
9393

9494
dmabuf_state: None,
9595
}

cosmic-panel-bin/src/xdg_shell_wrapper/shared_state.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,15 @@ use smithay::backend::renderer::{Bind, ImportDma, ImportEgl};
1616
use smithay::desktop::utils::send_frames_surface_tree;
1717
use smithay::input::keyboard::FilterResult;
1818
use smithay::reexports::wayland_server::DisplayHandle;
19+
use smithay::reexports::wayland_server::protocol::wl_surface;
1920
use smithay::utils::SERIAL_COUNTER;
2021
use smithay::wayland::compositor::with_states;
2122
use smithay::wayland::dmabuf::DmabufState;
2223
use smithay::wayland::fractional_scale::with_fractional_scale;
2324
use tracing::{error, info};
2425

2526
use crate::space_container::SpaceContainer;
26-
use crate::xdg_shell_wrapper::client_state::ClientState;
27+
use crate::xdg_shell_wrapper::client_state::{ClientState, DndIcon};
2728
use crate::xdg_shell_wrapper::server_state::ServerState;
2829
use crate::xdg_shell_wrapper::space::WrapperSpace;
2930

@@ -153,15 +154,15 @@ impl GlobalState {
153154
pub fn draw_dnd_icon(&mut self) {
154155
// TODO proxied layer surfaces
155156
if let Some((
156-
(egl_surface, wl_surface, dmg_tracked_renderer, is_dirty, has_frame),
157+
DndIcon { egl_surface, surface: wl_surface, output_tracker, is_ready, has_frame },
157158
s_icon,
158159
)) = self
159160
.server_state
160161
.seats
161162
.iter_mut()
162163
.find_map(|s| s.client.dnd_icon.as_mut().zip(s.server.dnd_icon.as_mut()))
163164
{
164-
if !*is_dirty || has_frame.is_none() {
165+
if !*is_ready || !*has_frame {
165166
return;
166167
}
167168
let Some(egl_surface) = egl_surface.as_mut() else {
@@ -194,7 +195,7 @@ impl GlobalState {
194195
smithay::backend::renderer::element::Kind::Unspecified,
195196
);
196197

197-
_ = dmg_tracked_renderer.render_output(renderer, &mut f, age, &elements, *clear_color);
198+
_ = output_tracker.render_output(renderer, &mut f, age, &elements, *clear_color);
198199
drop(f);
199200
egl_surface.swap_buffers(None).unwrap();
200201
// FIXME: damage tracking issues on integrated graphics but not nvidia
@@ -217,8 +218,8 @@ impl GlobalState {
217218
wl_surface.frame(&self.client_state.queue_handle, wl_surface.clone());
218219
wl_surface.commit();
219220

220-
*is_dirty = false;
221-
*has_frame = None;
221+
*is_ready = false;
222+
*has_frame = false;
222223
}
223224
}
224225

0 commit comments

Comments
 (0)