Skip to content

Commit fc2dbec

Browse files
committed
protocol: Impl ext-image-capture-source and ext-image-copy-capture
1 parent 819a983 commit fc2dbec

File tree

18 files changed

+1868
-111
lines changed

18 files changed

+1868
-111
lines changed

TODO.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
- Work on `ConnectorSavedState`
77
- Keyboard focus in Idea Xwayland is weird when creating a new Java file
88

9-
Snowcap
10-
- Add `send_message` for layers
9+
- Snowcap crashes when a window opens and immediately closes because the foreign toplevel handle is no longer valid
1110

1211
Testing
1312
- Test layout mode changing and how it interacts with client fullscreen/maximized requests

src/backend/udev.rs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ pub struct Udev {
121121
pub session: LibSeatSession,
122122
udev_dispatcher: Dispatcher<'static, UdevBackend, State>,
123123
display_handle: DisplayHandle,
124-
pub(super) primary_gpu: DrmNode,
124+
pub primary_gpu: DrmNode,
125125
pub(super) gpu_manager: GpuManager<GbmGlesBackend<GlesRenderer, DrmDeviceFd>>,
126126
devices: HashMap<DrmNode, Device>,
127127
/// The global corresponding to the primary gpu
@@ -1375,6 +1375,11 @@ impl Udev {
13751375
return;
13761376
}
13771377

1378+
let Some(output_geo) = pinnacle.space.output_geometry(output) else {
1379+
make_idle(&mut surface.render_state, &pinnacle.loop_handle);
1380+
return;
1381+
};
1382+
13781383
assert_matches!(
13791384
surface.render_state,
13801385
RenderState::Scheduled | RenderState::WaitingForEstimatedVblankAndScheduled(_)
@@ -1410,12 +1415,13 @@ impl Udev {
14101415
|| (pinnacle.lock_state.is_locked()
14111416
&& output.with_state(|state| state.lock_surface.is_none()));
14121417

1418+
let scale = output.current_scale().fractional_scale();
1419+
14131420
let (pointer_render_elements, cursor_ids) = pointer_render_elements(
1414-
output,
1421+
(pointer_location - output_geo.loc.to_f64()).to_physical_precise_round(scale),
1422+
scale,
14151423
&mut renderer,
14161424
&mut pinnacle.cursor_state,
1417-
&pinnacle.space,
1418-
pointer_location,
14191425
pinnacle.dnd_icon.as_ref(),
14201426
&pinnacle.clock,
14211427
);
@@ -1552,6 +1558,10 @@ impl Udev {
15521558
&pinnacle.loop_handle,
15531559
cursor_ids,
15541560
);
1561+
1562+
pinnacle.loop_handle.insert_idle(|state| {
1563+
state.process_capture_sessions();
1564+
});
15551565
}
15561566

15571567
pinnacle.update_primary_scanout_output(output, &res.states);

src/backend/winit.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,14 @@ impl Winit {
243243
.map(|ptr| ptr.current_location())
244244
.unwrap_or((0.0, 0.0).into());
245245

246+
let output_loc = pinnacle.space.output_geometry(&self.output).unwrap().loc;
247+
let scale = self.output.current_scale().fractional_scale();
248+
246249
let (pointer_render_elements, _cursor_ids) = pointer_render_elements(
247-
&self.output,
250+
(pointer_location - output_loc.to_f64()).to_physical_precise_round(scale),
251+
scale,
248252
self.backend.renderer(),
249253
&mut pinnacle.cursor_state,
250-
&pinnacle.space,
251-
pointer_location,
252254
pinnacle.dnd_icon.as_ref(),
253255
&pinnacle.clock,
254256
);
@@ -374,6 +376,10 @@ impl Winit {
374376
&render_output_result,
375377
&pinnacle.loop_handle,
376378
);
379+
380+
pinnacle.loop_handle.insert_idle(|state| {
381+
state.process_capture_sessions();
382+
});
377383
}
378384

379385
let now = pinnacle.clock.now();

src/handlers.rs

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ mod drm;
55
mod foreign_toplevel;
66
pub mod foreign_toplevel_list;
77
pub mod idle;
8+
mod image_capture_source;
9+
pub mod image_copy_capture;
810
pub mod session_lock;
911
#[cfg(feature = "snowcap")]
1012
pub mod snowcap_decoration;
@@ -214,9 +216,7 @@ impl CompositorHandler for State {
214216
}
215217

216218
// Window surface commit
217-
if let Some(window) = self.pinnacle.window_for_surface(surface).cloned()
218-
&& window.is_wayland()
219-
{
219+
if let Some(window) = self.pinnacle.window_for_surface(surface).cloned() {
220220
let Some(is_mapped) =
221221
with_renderer_surface_state(surface, |state| state.buffer().is_some())
222222
else {
@@ -225,28 +225,30 @@ impl CompositorHandler for State {
225225

226226
window.on_commit();
227227

228-
// Toplevel has become unmapped,
229-
// see https://wayland.app/protocols/xdg-shell#xdg_toplevel
230-
if !is_mapped {
231-
self.pinnacle.remove_window(&window, true);
228+
if window.is_wayland() {
229+
// Toplevel has become unmapped,
230+
// see https://wayland.app/protocols/xdg-shell#xdg_toplevel
231+
if !is_mapped {
232+
self.pinnacle.remove_window(&window, true);
232233

233-
let output = window.output(&self.pinnacle);
234+
let output = window.output(&self.pinnacle);
234235

235-
if let Some(output) = output {
236-
self.pinnacle.request_layout(&output);
236+
if let Some(output) = output {
237+
self.pinnacle.request_layout(&output);
238+
}
237239
}
238-
}
239240

240-
// Update reactive popups
241-
for (popup, _) in PopupManager::popups_for_surface(surface) {
242-
if let PopupKind::Xdg(popup) = popup
243-
&& popup.with_pending_state(|state| state.positioner.reactive)
244-
{
245-
if let Err(err) = self.pinnacle.position_popup(&popup) {
246-
debug!("Failed to position reactive popup: {err}");
247-
}
248-
if let Err(err) = popup.send_configure() {
249-
warn!("Failed to configure reactive popup: {err}");
241+
// Update reactive popups
242+
for (popup, _) in PopupManager::popups_for_surface(surface) {
243+
if let PopupKind::Xdg(popup) = popup
244+
&& popup.with_pending_state(|state| state.positioner.reactive)
245+
{
246+
if let Err(err) = self.pinnacle.position_popup(&popup) {
247+
debug!("Failed to position reactive popup: {err}");
248+
}
249+
if let Err(err) = popup.send_configure() {
250+
warn!("Failed to configure reactive popup: {err}");
251+
}
250252
}
251253
}
252254
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
use crate::{protocol::image_capture_source::delegate_image_capture_source, state::State};
2+
3+
delegate_image_capture_source!(State);

0 commit comments

Comments
 (0)