Skip to content

Commit

Permalink
Add surface_enter/surface_leave methods to CompositorHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
vially authored and wash2 committed May 21, 2024
1 parent 18070ad commit 15dea44
Show file tree
Hide file tree
Showing 11 changed files with 217 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

#### Breaking Changes
- Updated `calloop` to 0.13.0, `calloop-wayland-source` to `0.3.0`
- Add `surface_enter`/`surface_leave` methods to `CompositorHandler` trait.

#### Fixed

Expand Down
20 changes: 20 additions & 0 deletions examples/data_device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,26 @@ impl CompositorHandler for DataDeviceWindow {
) {
self.draw(conn, qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for DataDeviceWindow {
Expand Down
20 changes: 20 additions & 0 deletions examples/generic_simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,26 @@ impl<T: Test + 'static> CompositorHandler for SimpleWindow<T> {
) {
self.draw(conn, qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl<T: Test + 'static> OutputHandler for SimpleWindow<T> {
Expand Down
20 changes: 20 additions & 0 deletions examples/image_viewer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ impl CompositorHandler for State {
) {
self.draw(conn, qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for State {
Expand Down
20 changes: 20 additions & 0 deletions examples/image_viewporter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,26 @@ impl CompositorHandler for State {
) {
self.draw(conn, qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for State {
Expand Down
20 changes: 20 additions & 0 deletions examples/relative_pointer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,26 @@ impl CompositorHandler for SimpleWindow {
) {
self.draw(conn, qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for SimpleWindow {
Expand Down
20 changes: 20 additions & 0 deletions examples/session_lock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,26 @@ impl CompositorHandler for AppData {
_time: u32,
) {
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for AppData {
Expand Down
20 changes: 20 additions & 0 deletions examples/simple_layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,26 @@ impl CompositorHandler for SimpleLayer {
) {
self.draw(qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for SimpleLayer {
Expand Down
20 changes: 20 additions & 0 deletions examples/simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,26 @@ impl CompositorHandler for SimpleWindow {
) {
self.draw(conn, qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for SimpleWindow {
Expand Down
20 changes: 20 additions & 0 deletions examples/themed_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,26 @@ impl CompositorHandler for SimpleWindow {
) {
self.draw(conn, qh);
}

fn surface_enter(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}

fn surface_leave(
&mut self,
_conn: &Connection,
_qh: &QueueHandle<Self>,
_surface: &wl_surface::WlSurface,
_output: &wl_output::WlOutput,
) {
// Not needed for this example.
}
}

impl OutputHandler for SimpleWindow {
Expand Down
37 changes: 36 additions & 1 deletion src/compositor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,24 @@ pub trait CompositorHandler: Sized {
surface: &wl_surface::WlSurface,
time: u32,
);

/// The surface has entered an output.
fn surface_enter(
&mut self,
conn: &Connection,
qh: &QueueHandle<Self>,
surface: &wl_surface::WlSurface,
output: &wl_output::WlOutput,
);

/// The surface has left an output.
fn surface_leave(
&mut self,
conn: &Connection,
qh: &QueueHandle<Self>,
surface: &wl_surface::WlSurface,
output: &wl_output::WlOutput,
);
}

pub trait SurfaceDataExt: Send + Sync {
Expand Down Expand Up @@ -293,12 +311,16 @@ where
let data = data.surface_data();
let mut inner = data.inner.lock().unwrap();

let mut enter_or_leave_output: Option<(wl_output::WlOutput, bool)> = None;

match event {
wl_surface::Event::Enter { output } => {
inner.outputs.push(output);
inner.outputs.push(output.clone());
enter_or_leave_output.replace((output, true));
}
wl_surface::Event::Leave { output } => {
inner.outputs.retain(|o| o != &output);
enter_or_leave_output.replace((output, false));
}
wl_surface::Event::PreferredBufferScale { factor } => {
let current_scale = data.scale_factor.load(Ordering::Relaxed);
Expand Down Expand Up @@ -326,6 +348,13 @@ where
// NOTE: with v6 we don't need any special handling of the scale factor, everything
// was handled from the above, so return.
if surface.version() >= 6 {
drop(inner);
match enter_or_leave_output {
Some((output, true)) => state.surface_enter(conn, qh, surface, &output),
Some((output, false)) => state.surface_leave(conn, qh, surface, &output),
None => {}
};

return;
}

Expand All @@ -346,6 +375,12 @@ where
});

dispatch_surface_state_updates(state, conn, qh, surface, data, inner);

match enter_or_leave_output {
Some((output, true)) => state.surface_enter(conn, qh, surface, &output),
Some((output, false)) => state.surface_leave(conn, qh, surface, &output),
None => {}
};
}
}

Expand Down

0 comments on commit 15dea44

Please sign in to comment.