Skip to content

Commit

Permalink
simple_window: Test xdg-activation
Browse files Browse the repository at this point in the history
  • Loading branch information
Drakulix committed Oct 31, 2023
1 parent 1a74a19 commit 67adadd
Showing 1 changed file with 35 additions and 2 deletions.
37 changes: 35 additions & 2 deletions examples/simple_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ use std::{convert::TryInto, time::Duration};
use smithay_client_toolkit::reexports::calloop::{EventLoop, LoopHandle};
use smithay_client_toolkit::reexports::calloop_wayland_source::WaylandSource;
use smithay_client_toolkit::{
activation::{ActivationHandler, ActivationState},
compositor::{CompositorHandler, CompositorState},
delegate_compositor, delegate_keyboard, delegate_output, delegate_pointer, delegate_registry,
delegate_seat, delegate_shm, delegate_xdg_shell, delegate_xdg_window,
delegate_activation, delegate_compositor, delegate_keyboard, delegate_output, delegate_pointer,
delegate_registry, delegate_seat, delegate_shm, delegate_xdg_shell, delegate_xdg_window,
output::{OutputHandler, OutputState},
registry::{ProvidesRegistryState, RegistryState},
registry_handlers,
Expand Down Expand Up @@ -54,6 +55,8 @@ fn main() {
// Since we are not using the GPU in this example, we use wl_shm to allow software rendering to a buffer
// we share with the compositor process.
let shm = Shm::bind(&globals, &qh).expect("wl shm is not available.");
// If the compositor supports xdg-activation it probably wants us to use it to get focus
let xdg_activation = ActivationState::bind(&globals, &qh).ok();

// A window is created from a surface.
let surface = compositor.create_surface(&qh);
Expand All @@ -73,6 +76,18 @@ fn main() {
// the correct options.
window.commit();

// To request focus, we first need to request a token
if let Some(activation) = xdg_activation.as_ref() {
activation.request_token(
&qh,
(
None,
Some(window.wl_surface().clone()),
Some(String::from("io.github.smithay.client-toolkit.SimpleWindow")),
),
)
}

// We don't know how large the window will be yet, so lets assume the minimum size we suggested for the
// initial memory allocation.
let pool = SlotPool::new(256 * 256 * 4, &shm).expect("Failed to create pool");
Expand All @@ -84,6 +99,7 @@ fn main() {
seat_state: SeatState::new(&globals, &qh),
output_state: OutputState::new(&globals, &qh),
shm,
xdg_activation,

exit: false,
first_configure: true,
Expand Down Expand Up @@ -115,6 +131,7 @@ struct SimpleWindow {
seat_state: SeatState,
output_state: OutputState,
shm: Shm,
xdg_activation: Option<ActivationState>,

exit: bool,
first_configure: bool,
Expand Down Expand Up @@ -219,6 +236,18 @@ impl WindowHandler for SimpleWindow {
}
}

impl ActivationHandler for SimpleWindow {
type RequestData =
(Option<(wl_seat::WlSeat, u32)>, Option<wl_surface::WlSurface>, Option<String>);

fn new_token(&mut self, _data: &Self::RequestData, token: String) {

Check failure on line 243 in examples/simple_window.rs

View workflow job for this annotation

GitHub Actions / ci (1.65.0)

method `new_token` has an incompatible type for trait

Check failure on line 243 in examples/simple_window.rs

View workflow job for this annotation

GitHub Actions / ci (stable)

method `new_token` has an incompatible type for trait

Check failure on line 243 in examples/simple_window.rs

View workflow job for this annotation

GitHub Actions / ci (beta)

method `new_token` has an incompatible type for trait
self.xdg_activation
.as_ref()
.unwrap()
.activate::<SimpleWindow>(self.window.wl_surface(), token);
}
}

impl SeatHandler for SimpleWindow {
fn seat_state(&mut self) -> &mut SeatState {
&mut self.seat_state
Expand Down Expand Up @@ -464,6 +493,10 @@ delegate_pointer!(SimpleWindow);

delegate_xdg_shell!(SimpleWindow);
delegate_xdg_window!(SimpleWindow);
delegate_activation!(
SimpleWindow,
(Option<(wl_seat::WlSeat, u32)>, Option<wl_surface::WlSurface>, Option<String>)
);

delegate_registry!(SimpleWindow);

Expand Down

0 comments on commit 67adadd

Please sign in to comment.