mirror of
https://github.com/lelgenio/wl-crosshair.git
synced 2024-12-24 20:05:34 -03:00
Merge pull request #1 from DeltaTimo/main
Don't close the window on mouse over and allow clicking through window.
This commit is contained in:
commit
2f8e211f25
39
src/main.rs
39
src/main.rs
|
@ -2,8 +2,7 @@ use std::{fs::File, io::Write, os::unix::prelude::AsRawFd};
|
||||||
|
|
||||||
use wayland_client::{
|
use wayland_client::{
|
||||||
protocol::{
|
protocol::{
|
||||||
wl_buffer, wl_compositor, wl_keyboard, wl_pointer, wl_registry, wl_seat, wl_shm,
|
wl_buffer, wl_compositor, wl_keyboard, wl_region::WlRegion, wl_registry, wl_seat, wl_shm, wl_shm_pool, wl_surface
|
||||||
wl_shm_pool, wl_surface,
|
|
||||||
},
|
},
|
||||||
Connection, Dispatch, Proxy, QueueHandle,
|
Connection, Dispatch, Proxy, QueueHandle,
|
||||||
};
|
};
|
||||||
|
@ -26,7 +25,6 @@ struct State {
|
||||||
layer_surface: Option<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1>,
|
layer_surface: Option<zwlr_layer_surface_v1::ZwlrLayerSurfaceV1>,
|
||||||
buffer: Option<wl_buffer::WlBuffer>,
|
buffer: Option<wl_buffer::WlBuffer>,
|
||||||
wm_base: Option<xdg_wm_base::XdgWmBase>,
|
wm_base: Option<xdg_wm_base::XdgWmBase>,
|
||||||
pointer: Option<wl_pointer::WlPointer>,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
@ -47,7 +45,6 @@ fn main() {
|
||||||
layer_surface: None,
|
layer_surface: None,
|
||||||
buffer: None,
|
buffer: None,
|
||||||
wm_base: None,
|
wm_base: None,
|
||||||
pointer: None,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
event_queue.blocking_dispatch(&mut state).unwrap();
|
event_queue.blocking_dispatch(&mut state).unwrap();
|
||||||
|
@ -109,9 +106,6 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
||||||
(),
|
(),
|
||||||
);
|
);
|
||||||
state.buffer = Some(buffer);
|
state.buffer = Some(buffer);
|
||||||
} else if interface == wl_seat::WlSeat::interface().name {
|
|
||||||
let seat = registry.bind::<wl_seat::WlSeat, _, _>(name, version, qh, ());
|
|
||||||
state.pointer = Some(seat.get_pointer(qh, ()));
|
|
||||||
} else if interface == xdg_wm_base::XdgWmBase::interface().name {
|
} else if interface == xdg_wm_base::XdgWmBase::interface().name {
|
||||||
let wm_base = registry.bind::<xdg_wm_base::XdgWmBase, _, _>(name, 1, qh, ());
|
let wm_base = registry.bind::<xdg_wm_base::XdgWmBase, _, _>(name, 1, qh, ());
|
||||||
state.wm_base = Some(wm_base);
|
state.wm_base = Some(wm_base);
|
||||||
|
@ -120,31 +114,15 @@ impl Dispatch<wl_registry::WlRegistry, ()> for State {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Dispatch<wl_pointer::WlPointer, ()> for State {
|
impl Dispatch<WlRegion, ()> for State {
|
||||||
fn event(
|
fn event(
|
||||||
state: &mut Self,
|
_: &mut Self,
|
||||||
_: &wl_pointer::WlPointer,
|
_: &WlRegion,
|
||||||
event: wl_pointer::Event,
|
_: <WlRegion as Proxy>::Event,
|
||||||
_: &(),
|
_: &(),
|
||||||
_: &Connection,
|
_: &Connection,
|
||||||
qh: &QueueHandle<Self>,
|
_: &QueueHandle<Self>,
|
||||||
) {
|
) {
|
||||||
eprintln!("WlPointer event {event:#?}");
|
|
||||||
match event {
|
|
||||||
wl_pointer::Event::Enter { .. } => {
|
|
||||||
if let Some(surface) = &state.base_surface {
|
|
||||||
surface.destroy();
|
|
||||||
}
|
|
||||||
state.base_surface = None;
|
|
||||||
}
|
|
||||||
wl_pointer::Event::Leave { .. } => {
|
|
||||||
let surface = state.compositor.as_ref().unwrap().create_surface(qh, ());
|
|
||||||
state.base_surface = Some(surface);
|
|
||||||
|
|
||||||
state.init_layer_surface(qh);
|
|
||||||
}
|
|
||||||
_ => {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -197,6 +175,11 @@ impl State {
|
||||||
// A negative value means we will be centered on the screen
|
// A negative value means we will be centered on the screen
|
||||||
// independently of any other xdg_layer_shell
|
// independently of any other xdg_layer_shell
|
||||||
layer.set_exclusive_zone(-1);
|
layer.set_exclusive_zone(-1);
|
||||||
|
// Set empty input region to allow clicking through the window.
|
||||||
|
if let Some(compositor) = &self.compositor {
|
||||||
|
let region = compositor.create_region(qh, ());
|
||||||
|
self.base_surface.as_ref().unwrap().set_input_region(Some(®ion));
|
||||||
|
}
|
||||||
self.base_surface.as_ref().unwrap().commit();
|
self.base_surface.as_ref().unwrap().commit();
|
||||||
|
|
||||||
self.layer_surface = Some(layer);
|
self.layer_surface = Some(layer);
|
||||||
|
|
Loading…
Reference in a new issue