forked from InfoshockTech/xcrab
an attempt at event forwarding (not working)
This commit is contained in:
parent
8c3accec43
commit
225fe7fcaf
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -604,6 +604,7 @@ name = "xcrab"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"breadx",
|
||||
"gluten-keyboard",
|
||||
"lazy_static",
|
||||
"serde",
|
||||
"slotmap",
|
||||
|
|
|
@ -10,6 +10,7 @@ toml = "0.5.9"
|
|||
serde = { version = "1.0.137", features = ["derive"]}
|
||||
lazy_static = "1.4.0"
|
||||
slotmap = "1.0.6"
|
||||
gluten-keyboard = "0.1.2"
|
||||
|
||||
[[bin]]
|
||||
name = "xcrab-msg"
|
||||
|
|
59
src/main.rs
59
src/main.rs
|
@ -25,6 +25,8 @@ use breadx::{
|
|||
EventMask, Window,
|
||||
};
|
||||
|
||||
use gluten_keyboard::Key;
|
||||
|
||||
use lazy_static::lazy_static;
|
||||
|
||||
use tokio::sync::mpsc::unbounded_channel;
|
||||
|
@ -156,6 +158,9 @@ async fn process_event<Dpy: AsyncDisplay + ?Sized>(
|
|||
root: Window,
|
||||
keyboard_state: &mut KeyboardState,
|
||||
) -> Result<()> {
|
||||
let focused = manager.get_focused().await?;
|
||||
let focused_frame: x11::client::FramedWindow = manager.get_framed_window(focused).await?;
|
||||
|
||||
match ev {
|
||||
Event::MapRequest(ev) => {
|
||||
manager.add_client(conn, ev.window).await?;
|
||||
|
@ -191,28 +196,56 @@ async fn process_event<Dpy: AsyncDisplay + ?Sized>(
|
|||
manager.remove_client(conn, ev.window).await?;
|
||||
}
|
||||
}
|
||||
Event::ButtonPress(ev) => {
|
||||
dbg!(&ev);
|
||||
Event::ButtonPress(mut ev) => {
|
||||
if ev.detail == 1 && manager.has_client(ev.event) {
|
||||
manager.set_focus(conn, ev.event).await?;
|
||||
}
|
||||
if ev.event == focused_frame.input {
|
||||
ev.event = focused;
|
||||
conn.send_event_async(focused, EventMask::BUTTON_PRESS, Event::ButtonPress(ev))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Event::KeyPress(ev) => {
|
||||
println!(
|
||||
"{:?}",
|
||||
keyboard_state.process_keycode(ev.detail, ev.state).unwrap()
|
||||
);
|
||||
if keyboard_state
|
||||
.process_keycode(ev.detail, ev.state)
|
||||
.unwrap()
|
||||
.as_char()
|
||||
.unwrap()
|
||||
== 'X'
|
||||
Event::KeyPress(mut ev) => {
|
||||
if keyboard_state.process_keycode(ev.detail, ev.state).unwrap() == Key::X
|
||||
&& ev.state.control()
|
||||
{
|
||||
manager.destroy_focused_client(conn).await?;
|
||||
} else {
|
||||
ev.event = focused;
|
||||
conn.send_event_async(focused, EventMask::KEY_PRESS, Event::KeyPress(ev))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Event::KeyRelease(mut ev) => {
|
||||
if ev.event == focused_frame.input {
|
||||
ev.event = focused;
|
||||
conn.send_event_async(focused, EventMask::KEY_RELEASE, Event::KeyRelease(ev))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Event::ButtonRelease(mut ev) => {
|
||||
if ev.event == focused_frame.input {
|
||||
ev.event = focused;
|
||||
conn.send_event_async(focused, EventMask::BUTTON_RELEASE, Event::ButtonRelease(ev))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Event::EnterNotify(mut ev) => {
|
||||
if ev.event == focused_frame.input {
|
||||
ev.event = focused;
|
||||
conn.send_event_async(focused, EventMask::ENTER_WINDOW, Event::EnterNotify(ev))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
Event::LeaveNotify(mut ev) => {
|
||||
if ev.event == focused_frame.input {
|
||||
ev.event = focused;
|
||||
conn.send_event_async(focused, EventMask::LEAVE_WINDOW, Event::LeaveNotify(ev))
|
||||
.await?;
|
||||
}
|
||||
}
|
||||
|
||||
_ => {}
|
||||
}
|
||||
Ok(())
|
||||
|
|
|
@ -613,6 +613,21 @@ impl XcrabWindowManager {
|
|||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn get_focused(&self) -> Result<Window> {
|
||||
if self.focused != None {
|
||||
Ok(self.focused.unwrap())
|
||||
} else {
|
||||
Err(XcrabError::ClientDoesntExist)
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn get_framed_window(&self, window: Window) -> Result<FramedWindow> {
|
||||
let focused_key = self.clients.get(&window).unwrap();
|
||||
let focused = self.rects.get(*focused_key).unwrap();
|
||||
let focused_frame = focused.unwrap_client().frame;
|
||||
Ok(focused_frame)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn may_not_exist(res: breadx::Result) -> breadx::Result {
|
||||
|
@ -628,10 +643,10 @@ pub fn may_not_exist(res: breadx::Result) -> breadx::Result {
|
|||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy)]
|
||||
struct FramedWindow {
|
||||
frame: Window,
|
||||
win: Window,
|
||||
input: Window,
|
||||
pub struct FramedWindow {
|
||||
pub frame: Window,
|
||||
pub win: Window,
|
||||
pub input: Window,
|
||||
}
|
||||
|
||||
impl FramedWindow {
|
||||
|
@ -729,9 +744,10 @@ impl FramedWindow {
|
|||
|
||||
self.input.unmap_async(conn).await?;
|
||||
|
||||
self.frame.free_async(conn).await?;
|
||||
self.input.free_async(conn).await?;
|
||||
|
||||
self.frame.free_async(conn).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
@ -866,16 +882,17 @@ async fn frame<Dpy: AsyncDisplay + ?Sized>(conn: &mut Dpy, win: Window) -> Resul
|
|||
win.set_event_mask_async(conn, EventMask::BUTTON_PRESS)
|
||||
.await?;
|
||||
|
||||
input.set_event_mask_async(
|
||||
conn,
|
||||
EventMask::BUTTON_PRESS
|
||||
| EventMask::BUTTON_RELEASE
|
||||
| EventMask::KEY_PRESS
|
||||
| EventMask::KEY_RELEASE
|
||||
| EventMask::ENTER_WINDOW
|
||||
| EventMask::LEAVE_WINDOW,
|
||||
)
|
||||
.await?;
|
||||
input
|
||||
.set_event_mask_async(
|
||||
conn,
|
||||
EventMask::BUTTON_PRESS
|
||||
| EventMask::BUTTON_RELEASE
|
||||
| EventMask::KEY_PRESS
|
||||
| EventMask::KEY_RELEASE
|
||||
| EventMask::ENTER_WINDOW
|
||||
| EventMask::LEAVE_WINDOW,
|
||||
)
|
||||
.await?;
|
||||
|
||||
may_not_exist(win.change_save_set_async(conn, SetMode::Insert).await)?;
|
||||
|
||||
|
|
Loading…
Reference in a new issue