keybinds are not stored in a Rc<RefCell<>>
to prevent cloning
this could be blocking if i ever add dynamic keybinds
This commit is contained in:
parent
aafbcf2314
commit
696559d0af
|
@ -15,3 +15,4 @@ log4rs = "1.0.0"
|
||||||
indexmap = "1.6.2"
|
indexmap = "1.6.2"
|
||||||
thiserror = "1.0.30"
|
thiserror = "1.0.30"
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
|
derivative = "2.2.0"
|
||||||
|
|
38
src/state.rs
38
src/state.rs
|
@ -1,8 +1,8 @@
|
||||||
use std::rc::Rc;
|
use std::{cell::RefCell, rc::Rc};
|
||||||
|
|
||||||
use log::{error, info};
|
use log::{error, info};
|
||||||
|
|
||||||
use x11::xlib::{self, Window, XEvent, XKeyEvent, XMotionEvent};
|
use x11::xlib::{self, Window, XEvent, XMotionEvent};
|
||||||
use xlib::{
|
use xlib::{
|
||||||
XConfigureRequestEvent, XCrossingEvent, XDestroyWindowEvent,
|
XConfigureRequestEvent, XCrossingEvent, XDestroyWindowEvent,
|
||||||
XMapRequestEvent, XUnmapEvent,
|
XMapRequestEvent, XUnmapEvent,
|
||||||
|
@ -13,7 +13,7 @@ use crate::{
|
||||||
keycodes::{MouseButton, VirtualKeyCode},
|
keycodes::{MouseButton, VirtualKeyCode},
|
||||||
window_event::{
|
window_event::{
|
||||||
ButtonEvent, KeyBind, KeyEvent, KeyState, ModifierKey,
|
ButtonEvent, KeyBind, KeyEvent, KeyState, ModifierKey,
|
||||||
ModifierState, Point,
|
ModifierState, Point, WindowEvent,
|
||||||
},
|
},
|
||||||
xlib::XLib,
|
xlib::XLib,
|
||||||
WindowServerBackend,
|
WindowServerBackend,
|
||||||
|
@ -37,7 +37,7 @@ where
|
||||||
{
|
{
|
||||||
clients: ClientState,
|
clients: ClientState,
|
||||||
move_resize_window: MoveResizeInfo,
|
move_resize_window: MoveResizeInfo,
|
||||||
keybinds: Vec<KeyBinding<B>>,
|
keybinds: Rc<RefCell<Vec<KeyBinding<B>>>>,
|
||||||
backend: B,
|
backend: B,
|
||||||
|
|
||||||
config: WMConfig,
|
config: WMConfig,
|
||||||
|
@ -69,7 +69,10 @@ struct ResizeInfoInner {
|
||||||
starting_window_size: Point<i32>,
|
starting_window_size: Point<i32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
use derivative::*;
|
||||||
|
|
||||||
|
#[derive(Derivative)]
|
||||||
|
#[derivative(Clone(bound = ""))]
|
||||||
struct KeyBinding<B: WindowServerBackend> {
|
struct KeyBinding<B: WindowServerBackend> {
|
||||||
key: KeyBind,
|
key: KeyBind,
|
||||||
closure: Rc<dyn Fn(&mut WindowManager<B>, &KeyEvent<B::Window>)>,
|
closure: Rc<dyn Fn(&mut WindowManager<B>, &KeyEvent<B::Window>)>,
|
||||||
|
@ -108,7 +111,7 @@ where
|
||||||
Self {
|
Self {
|
||||||
clients,
|
clients,
|
||||||
move_resize_window: MoveResizeInfo::None,
|
move_resize_window: MoveResizeInfo::None,
|
||||||
keybinds: Vec::new(),
|
keybinds: Rc::new(RefCell::new(Vec::new())),
|
||||||
backend,
|
backend,
|
||||||
config,
|
config,
|
||||||
}
|
}
|
||||||
|
@ -254,7 +257,7 @@ where
|
||||||
|
|
||||||
fn add_keybind(&mut self, keybind: KeyBinding<B>) {
|
fn add_keybind(&mut self, keybind: KeyBinding<B>) {
|
||||||
//self.xlib.add_global_keybind(keybind.key);
|
//self.xlib.add_global_keybind(keybind.key);
|
||||||
self.keybinds.push(keybind);
|
self.keybinds.borrow_mut().push(keybind);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn add_vs_switch_keybinds(&mut self) {
|
fn add_vs_switch_keybinds(&mut self) {
|
||||||
|
@ -358,6 +361,14 @@ where
|
||||||
let event = self.backend.next_event();
|
let event = self.backend.next_event();
|
||||||
|
|
||||||
match event {
|
match event {
|
||||||
|
WindowEvent::KeyEvent(event @ KeyEvent { window, .. }) => {
|
||||||
|
self.handle_keybinds(&event);
|
||||||
|
}
|
||||||
|
WindowEvent::ButtonEvent(
|
||||||
|
event @ ButtonEvent { window, .. },
|
||||||
|
) => {
|
||||||
|
self.button_event(&event);
|
||||||
|
}
|
||||||
// xlib::MapRequest => self.map_request(&event),
|
// xlib::MapRequest => self.map_request(&event),
|
||||||
// xlib::UnmapNotify => self.unmap_notify(&event),
|
// xlib::UnmapNotify => self.unmap_notify(&event),
|
||||||
// xlib::ConfigureRequest => self.configure_request(&event),
|
// xlib::ConfigureRequest => self.configure_request(&event),
|
||||||
|
@ -385,7 +396,16 @@ where
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: change this somehow cuz I'm not a big fan of this "hardcoded" keybind stuff
|
// TODO: change this somehow cuz I'm not a big fan of this "hardcoded" keybind stuff
|
||||||
fn handle_keybinds(&mut self, event: &XKeyEvent) {
|
fn handle_keybinds(&mut self, event: &KeyEvent<B::Window>) {
|
||||||
|
let keybinds = self.keybinds.clone();
|
||||||
|
|
||||||
|
for kb in keybinds.borrow().iter() {
|
||||||
|
if kb.key.key == event.keycode
|
||||||
|
&& kb.key.modifiers == event.modifierstate
|
||||||
|
{
|
||||||
|
kb.call(self, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
//let clean_mask = self.xlib.get_clean_mask();
|
//let clean_mask = self.xlib.get_clean_mask();
|
||||||
// TODO: Fix this
|
// TODO: Fix this
|
||||||
// for kb in self.keybinds.clone().into_iter() {
|
// for kb in self.keybinds.clone().into_iter() {
|
||||||
|
@ -775,7 +795,7 @@ where
|
||||||
if ModifierState::from([self
|
if ModifierState::from([self
|
||||||
.config
|
.config
|
||||||
.mod_key])
|
.mod_key])
|
||||||
.eq_ignore_lock(&event.modifierstate)
|
.eq(&event.modifierstate)
|
||||||
&& self.clients.contains(&event.window) =>
|
&& self.clients.contains(&event.window) =>
|
||||||
{
|
{
|
||||||
self.start_move_resize_window(event)
|
self.start_move_resize_window(event)
|
||||||
|
|
Loading…
Reference in a new issue