Skip to content

Commit

Permalink
fix duplicate creating of wl_pointer / wl_keyboard (#92)
Browse files Browse the repository at this point in the history
closes #91
  • Loading branch information
feschber authored Mar 15, 2024
1 parent 0196cfe commit 9a75a76
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
50 changes: 30 additions & 20 deletions src/backend/producer/wayland.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,12 @@ use wayland_client::{
delegate_noop,
globals::{registry_queue_init, GlobalListContents},
protocol::{
wl_buffer, wl_compositor, wl_keyboard,
wl_buffer, wl_compositor,
wl_keyboard::{self, WlKeyboard},
wl_output::{self, WlOutput},
wl_pointer, wl_region, wl_registry, wl_seat, wl_shm, wl_shm_pool, wl_surface,
wl_pointer::{self, WlPointer},
wl_region, wl_registry, wl_seat, wl_shm, wl_shm_pool,
wl_surface::WlSurface,
},
Connection, Dispatch, DispatchError, EventQueue, QueueHandle, WEnum,
};
Expand All @@ -73,7 +76,7 @@ struct Globals {
seat: wl_seat::WlSeat,
shm: wl_shm::WlShm,
layer_shell: ZwlrLayerShellV1,
outputs: Vec<wl_output::WlOutput>,
outputs: Vec<WlOutput>,
xdg_output_manager: ZxdgOutputManagerV1,
}

Expand All @@ -95,6 +98,8 @@ impl OutputInfo {
}

struct State {
pointer: Option<WlPointer>,
keyboard: Option<WlKeyboard>,
pointer_lock: Option<ZwpLockedPointerV1>,
rel_pointer: Option<ZwpRelativePointerV1>,
shortcut_inhibitor: Option<ZwpKeyboardShortcutsInhibitorV1>,
Expand Down Expand Up @@ -123,7 +128,7 @@ pub struct WaylandEventProducer(AsyncFd<Inner>);

struct Window {
buffer: wl_buffer::WlBuffer,
surface: wl_surface::WlSurface,
surface: WlSurface,
layer_surface: ZwlrLayerSurfaceV1,
pos: Position,
}
Expand All @@ -136,6 +141,7 @@ impl Window {
pos: Position,
size: (i32, i32),
) -> Window {
log::debug!("creating window output: {output:?}, size: {size:?}");
let g = &state.g;

let (width, height) = match pos {
Expand Down Expand Up @@ -217,6 +223,7 @@ fn get_edges(outputs: &[(WlOutput, OutputInfo)], pos: Position) -> Vec<(WlOutput
fn get_output_configuration(state: &State, pos: Position) -> Vec<(WlOutput, OutputInfo)> {
// get all output edges corresponding to the position
let edges = get_edges(&state.output_info, pos);
log::debug!("edges: {edges:?}");
let opposite_edges = get_edges(&state.output_info, pos.opposite());

// remove those edges that are at the same position
Expand Down Expand Up @@ -331,6 +338,8 @@ impl WaylandEventProducer {
std::mem::drop(read_guard);

let mut state = State {
pointer: None,
keyboard: None,
g,
pointer_lock: None,
rel_pointer: None,
Expand Down Expand Up @@ -406,8 +415,8 @@ impl WaylandEventProducer {
impl State {
fn grab(
&mut self,
surface: &wl_surface::WlSurface,
pointer: &wl_pointer::WlPointer,
surface: &WlSurface,
pointer: &WlPointer,
serial: u32,
qh: &QueueHandle<State>,
) {
Expand Down Expand Up @@ -489,6 +498,7 @@ impl State {
fn add_client(&mut self, client: ClientHandle, pos: Position) {
let outputs = get_output_configuration(self, pos);

log::debug!("outputs: {outputs:?}");
outputs.iter().for_each(|(o, i)| {
let window = Window::new(self, &self.qh, o, pos, i.size);
let window = Rc::new(window);
Expand Down Expand Up @@ -654,7 +664,7 @@ impl Stream for WaylandEventProducer {

impl Dispatch<wl_seat::WlSeat, ()> for State {
fn event(
_: &mut Self,
state: &mut Self,
seat: &wl_seat::WlSeat,
event: <wl_seat::WlSeat as wayland_client::Proxy>::Event,
_: &(),
Expand All @@ -665,21 +675,21 @@ impl Dispatch<wl_seat::WlSeat, ()> for State {
capabilities: WEnum::Value(capabilities),
} = event
{
if capabilities.contains(wl_seat::Capability::Pointer) {
seat.get_pointer(qh, ());
if capabilities.contains(wl_seat::Capability::Pointer) && state.pointer.is_none() {
state.pointer.replace(seat.get_pointer(qh, ()));
}
if capabilities.contains(wl_seat::Capability::Keyboard) {
if capabilities.contains(wl_seat::Capability::Keyboard) && state.keyboard.is_none() {
seat.get_keyboard(qh, ());
}
}
}
}

impl Dispatch<wl_pointer::WlPointer, ()> for State {
impl Dispatch<WlPointer, ()> for State {
fn event(
app: &mut Self,
pointer: &wl_pointer::WlPointer,
event: <wl_pointer::WlPointer as wayland_client::Proxy>::Event,
pointer: &WlPointer,
event: <WlPointer as wayland_client::Proxy>::Event,
_: &(),
_: &Connection,
qh: &QueueHandle<Self>,
Expand Down Expand Up @@ -761,10 +771,10 @@ impl Dispatch<wl_pointer::WlPointer, ()> for State {
}
}

impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
impl Dispatch<WlKeyboard, ()> for State {
fn event(
app: &mut Self,
_: &wl_keyboard::WlKeyboard,
_: &WlKeyboard,
event: wl_keyboard::Event,
_: &(),
_: &Connection,
Expand Down Expand Up @@ -917,7 +927,7 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
state
.g
.outputs
.push(registry.bind::<wl_output::WlOutput, _, _>(name, 4, qh, ()))
.push(registry.bind::<WlOutput, _, _>(name, 4, qh, ()))
}
}
wl_registry::Event::GlobalRemove { .. } => {}
Expand Down Expand Up @@ -962,11 +972,11 @@ impl Dispatch<ZxdgOutputV1, WlOutput> for State {
}
}

impl Dispatch<wl_output::WlOutput, ()> for State {
impl Dispatch<WlOutput, ()> for State {
fn event(
state: &mut Self,
_proxy: &wl_output::WlOutput,
event: <wl_output::WlOutput as wayland_client::Proxy>::Event,
_proxy: &WlOutput,
event: <WlOutput as wayland_client::Proxy>::Event,
_data: &(),
_conn: &Connection,
_qhandle: &QueueHandle<Self>,
Expand All @@ -990,6 +1000,6 @@ delegate_noop!(State: ZwpPointerConstraintsV1);
delegate_noop!(State: ignore ZxdgOutputManagerV1);
delegate_noop!(State: ignore wl_shm::WlShm);
delegate_noop!(State: ignore wl_buffer::WlBuffer);
delegate_noop!(State: ignore wl_surface::WlSurface);
delegate_noop!(State: ignore WlSurface);
delegate_noop!(State: ignore ZwpKeyboardShortcutsInhibitorV1);
delegate_noop!(State: ignore ZwpLockedPointerV1);
4 changes: 2 additions & 2 deletions src/server/ping_task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ pub fn new(

// give clients time to resond
if receiving {
log::debug!("waiting {MAX_RESPONSE_TIME:?} for response from client with pressed keys ...");
log::trace!("waiting {MAX_RESPONSE_TIME:?} for response from client with pressed keys ...");
} else {
log::debug!(
log::trace!(
"state: {:?} => waiting {MAX_RESPONSE_TIME:?} for client to respond ...",
server.state.get()
);
Expand Down

0 comments on commit 9a75a76

Please sign in to comment.