Skip to content

Commit

Permalink
refactor(wayland): use smithay xdg_shell handler
Browse files Browse the repository at this point in the history
  • Loading branch information
technobaboo committed Mar 9, 2024
1 parent fba4e10 commit 34aab26
Show file tree
Hide file tree
Showing 14 changed files with 661 additions and 1,785 deletions.
1 change: 0 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ serde = { version = "1.0.160", features = ["derive"] }
serde_repr = "0.1.16"
tracing = "0.1.37"
tracing-subscriber = { version = "0.3.17", features = ["env-filter"] }
global_counter = "0.2.2"
rand = "0.8.5"
atty = "0.2.14"
xkbcommon = { version = "0.7.0", default-features = false, optional = true }
Expand Down
3 changes: 1 addition & 2 deletions src/wayland/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ use self::xwayland_rootless::XWaylandState;
use self::{state::WaylandState, surface::CORE_SURFACES};
use crate::{core::task, wayland::state::ClientState};
use color_eyre::eyre::{ensure, Result};
use global_counter::primitive::exact::CounterU32;
use once_cell::sync::OnceCell;
use parking_lot::Mutex;
use sk::StereoKitDraw;
Expand Down Expand Up @@ -52,7 +51,6 @@ use tracing::{debug_span, info, instrument};

pub static X_DISPLAY: OnceCell<u32> = OnceCell::new();
pub static WAYLAND_DISPLAY: OnceCell<String> = OnceCell::new();
pub static SERIAL_COUNTER: CounterU32 = CounterU32::new(0);

struct EGLRawHandles {
display: *const c_void,
Expand Down Expand Up @@ -175,6 +173,7 @@ impl Wayland {
acc = listen_async.accept() => { // New client connected
let (stream, _) = acc?;
let client_state = Arc::new(ClientState {
pid: stream.peer_cred().ok().and_then(|c| c.pid()),
id: OnceCell::new(),
compositor_state: Default::default(),
display: Arc::downgrade(&display),
Expand Down
44 changes: 41 additions & 3 deletions src/wayland/seat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,32 +106,68 @@ impl SeatWrapper {
touches: Mutex::new(FxHashMap::default()),
}
}
pub fn unfocus(&self, surface: &WlSurface, state: &mut WaylandState) {
let pointer = self.seat.get_pointer().unwrap();
if pointer.current_focus() == Some(surface.clone()) {
pointer.motion(
state,
None,
&MotionEvent {
location: (0.0, 0.0).into(),
serial: SERIAL_COUNTER.next_serial(),
time: 0,
},
)
}
let keyboard = self.seat.get_keyboard().unwrap();
if keyboard.current_focus() == Some(surface.clone()) {
keyboard.set_focus(state, None, SERIAL_COUNTER.next_serial());
}
let touch = self.seat.get_touch().unwrap();
for (id, touch_surface) in self.touches.lock().iter() {
if touch_surface.id() == surface.id() {
self.touch_up(*id);
touch.up(
state,
&UpEvent {
slot: Some(*id).into(),
serial: SERIAL_COUNTER.next_serial(),
time: 0,
},
)
}
}
}

pub fn pointer_motion(&self, surface: WlSurface, position: Vector2<f32>) {
let Some(state) = self.wayland_state.upgrade() else {
return;
};
let mut state = state.lock();
let Some(pointer) = self.seat.get_pointer() else {
return;
};
pointer.motion(
&mut state.lock(),
&mut state,
Some((surface, (0, 0).into())),
&MotionEvent {
location: (position.x as f64, position.y as f64).into(),
serial: SERIAL_COUNTER.next_serial(),
time: 0,
},
);
pointer.frame(&mut state);
}
pub fn pointer_button(&self, button: u32, pressed: bool) {
let Some(state) = self.wayland_state.upgrade() else {
return;
};
let mut state = state.lock();
let Some(pointer) = self.seat.get_pointer() else {
return;
};
pointer.button(
&mut state.lock(),
&mut state,
&ButtonEvent {
button,
state: if pressed {
Expand All @@ -143,6 +179,7 @@ impl SeatWrapper {
time: 0,
},
);
pointer.frame(&mut state);
}
pub fn pointer_scroll(
&self,
Expand Down Expand Up @@ -171,7 +208,8 @@ impl SeatWrapper {
v120: scroll_steps.map(|d| ((d.x * 120.0) as i32, (d.y * 120.0) as i32)),
stop: (false, false),
},
)
);
pointer.frame(&mut state);
}

pub fn keyboard_keys(&self, surface: WlSurface, keymap_id: &str, keys: Vec<i32>) {
Expand Down
Loading

0 comments on commit 34aab26

Please sign in to comment.