Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to x11rb 0.11 #250

Merged
merged 1 commit into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ thiserror = "1.0"
tracing = { version = "0.1", features = ["attributes", "log"] }

serde = { version = "1.0", features = ["derive"], optional = true }
x11rb = { version = "0.10", features = ["randr"], optional = true }
x11rb = { version = "0.11", features = ["randr"], optional = true }
anymap = "0.12.1"

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion crates/penrose_ui/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ pango = { version = "0.15.6" }
penrose = { version = "0.3", path = "../../" }
tracing = { version = "0.1", features = ["attributes", "log"] }
thiserror = "1.0.37"
x11rb = { version = "0.10", features = ["randr", "render"] }
x11rb = { version = "0.11", features = ["randr", "render"] }
7 changes: 4 additions & 3 deletions src/x11rb/conversions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use tracing::warn;
use x11rb::{
connection::Connection,
protocol::{
xproto::{ClientMessageEvent, ModMask},
xproto::{ClientMessageEvent, KeyButMask, ModMask},
Event,
},
};
Expand Down Expand Up @@ -67,7 +67,7 @@ pub(crate) fn convert_event<C: Connection>(conn: &Conn<C>, event: Event) -> Resu

Event::KeyPress(event) => {
let code = KeyCode {
mask: event.state,
mask: event.state.into(),
code: event.detail,
};
let numlock = ModMask::M2;
Expand Down Expand Up @@ -144,7 +144,7 @@ pub(crate) fn convert_event<C: Connection>(conn: &Conn<C>, event: Event) -> Resu
}
}

fn to_mouse_state(detail: u8, state: u16) -> Option<MouseState> {
fn to_mouse_state(detail: u8, state: KeyButMask) -> Option<MouseState> {
fn is_held(key: &ModifierKey, mask: u16) -> bool {
mask & u16::from(*key) > 0
}
Expand All @@ -159,6 +159,7 @@ fn to_mouse_state(detail: u8, state: u16) -> Option<MouseState> {
return None;
}
};
let state = u16::from(state);
let modifiers = ModifierKey::iter().filter(|m| is_held(m, state)).collect();
Some(MouseState { button, modifiers })
}
Expand Down
33 changes: 16 additions & 17 deletions src/x11rb/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ use crate::{
},
Error, Result, Xid,
};
use std::{collections::HashMap, convert::TryFrom, str::FromStr};
use std::{collections::HashMap, str::FromStr};
use strum::IntoEnumIterator;
use tracing::error;
use x11rb::{
Expand Down Expand Up @@ -277,17 +277,16 @@ where
let modifiers = &[0, u16::from(ModMask::M2)];
let mode = GrabMode::ASYNC;
let mask = EventMask::BUTTON_PRESS | EventMask::BUTTON_RELEASE | EventMask::BUTTON_MOTION;
let mask = u16::try_from(u32::from(mask)).unwrap();

for m in modifiers.iter() {
for k in key_codes.iter() {
self.conn.grab_key(
false, // don't pass grabbed events through to the client
self.root, // the window to grab: in this case the root window
k.mask | m, // modifiers to grab
k.code, // keycode to grab
mode, // don't lock pointer input while grabbing
mode, // don't lock keyboard input while grabbing
false, // don't pass grabbed events through to the client
self.root, // the window to grab: in this case the root window
(k.mask | m).into(), // modifiers to grab
k.code, // keycode to grab
mode, // don't lock pointer input while grabbing
mode, // don't lock keyboard input while grabbing
)?;
}
}
Expand All @@ -296,15 +295,15 @@ where
for state in mouse_states.iter() {
let button = state.button().into();
self.conn.grab_button(
false, // don't pass grabbed events through to the client
self.root, // the window to grab: in this case the root window
mask, // which events are reported to the client
mode, // don't lock pointer input while grabbing
mode, // don't lock keyboard input while grabbing
x11rb::NONE, // don't confine the cursor to a specific window
x11rb::NONE, // don't change the cursor type
button, // the button to grab
state.mask() | m, // modifiers to grab
false, // don't pass grabbed events through to the client
self.root, // the window to grab: in this case the root window
mask, // which events are reported to the client
mode, // don't lock pointer input while grabbing
mode, // don't lock keyboard input while grabbing
x11rb::NONE, // don't confine the cursor to a specific window
x11rb::NONE, // don't change the cursor type
button, // the button to grab
(state.mask() | m).into(), // modifiers to grab
)?;
}
}
Expand Down