remove most of the idiotic stuff I did before (still doesn't work)

This commit is contained in:
Akshat Deshpande 2022-07-31 13:46:21 -05:00
parent f68559f233
commit 3ef4a2c9fc
8 changed files with 102 additions and 1538 deletions

65
Cargo.lock generated
View file

@ -40,9 +40,9 @@ dependencies = [
[[package]]
name = "async-task"
version = "4.2.0"
version = "4.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30696a84d817107fc028e049980e09d5e140e8da8f1caeb17e8e950658a3cea9"
checksum = "7a40729d2133846d9ed0ea60a8b9541bccddab49cd30f0715a1da672fe9a2524"
[[package]]
name = "atomic-waker"
@ -99,15 +99,15 @@ dependencies = [
[[package]]
name = "bytemuck"
version = "1.9.1"
version = "1.11.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cdead85bdec19c194affaeeb670c0e41fe23de31459efd1c174d049269cf02cc"
checksum = "a5377c8865e74a160d21f29c2d40669f53286db6eab59b88540cbb12ffc8b835"
[[package]]
name = "bytes"
version = "1.1.0"
version = "1.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c4872d67bab6358e59559027aa3b9157c53d9358c51423c17554809a8858e0f8"
checksum = "ec8a7b6a70fde80372154c65702f00a0f56f3e1c36abbc6c440484be248856db"
[[package]]
name = "cache-padded"
@ -129,9 +129,9 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "concurrent-queue"
version = "1.2.2"
version = "1.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "30ed07550be01594c6026cff2a1d7fe9c8f683caa798e12b68694ac9e88286a3"
checksum = "af4780a44ab5696ea9e28294517f1fffb421a83a25af521333c838635509db9c"
dependencies = [
"cache-padded",
]
@ -144,15 +144,15 @@ checksum = "b365fabc795046672053e29c954733ec3b05e4be654ab130fe8f1f94d7051f35"
[[package]]
name = "event-listener"
version = "2.5.2"
version = "2.5.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "77f3309417938f28bf8228fcff79a4a37103981e3e186d2ccd19c74b38f4eb71"
checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
[[package]]
name = "fastrand"
version = "1.7.0"
version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c3fcf0cee53519c866c09b5de1f6c56ff9d647101f81c1964fa632e148896cdf"
checksum = "a7a407cfaa3385c4ae6b23e84623d48c2798d06e3e6a1878f7f59f17b3f86499"
dependencies = [
"instant",
]
@ -290,9 +290,9 @@ dependencies = [
[[package]]
name = "once_cell"
version = "1.12.0"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7709cef83f0c1f58f666e746a08b21e0085f7440fa6a29cc194d68aac97a4225"
checksum = "18a6dbe30758c9f83eb00cbea4ac95966305f5a7772f3f42ebfc7fc7eddbd8e1"
[[package]]
name = "parking"
@ -344,9 +344,9 @@ dependencies = [
[[package]]
name = "proc-macro2"
version = "1.0.40"
version = "1.0.42"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dd96a1e8ed2596c337f8eae5f24924ec83f5ad5ab21ea8e455d3566c69fbcaf7"
checksum = "c278e965f1d8cf32d6e0e96de3d3e79712178ae67986d9cf9151f51e95aac89b"
dependencies = [
"unicode-ident",
]
@ -362,9 +362,9 @@ dependencies = [
[[package]]
name = "redox_syscall"
version = "0.2.13"
version = "0.2.16"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "62f25bc4c7e55e0b0b7a1d43fb893f4fa1361d0abe38b9ce4f323c2adfe6ef42"
checksum = "fb5a58c1855b4b6819d59012155603f0b22ad30cad752600aadfcb695265519a"
dependencies = [
"bitflags",
]
@ -377,18 +377,18 @@ checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]]
name = "serde"
version = "1.0.137"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61ea8d54c77f8315140a05f4c7237403bf38b72704d031543aa1d16abbf517d1"
checksum = "fc855a42c7967b7c369eb5860f7164ef1f6f81c20c7cc1141f2a604e18723b03"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.137"
version = "1.0.140"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1f26faba0c3959972377d3b2d306ee9f71faee9714294e41bb777f83f88578be"
checksum = "6f2122636b9fe3b81f1cb25099fcf2d3f542cdb1d45940d56c713158884a05da"
dependencies = [
"proc-macro2",
"quote",
@ -406,9 +406,12 @@ dependencies = [
[[package]]
name = "slab"
version = "0.4.6"
version = "0.4.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "eb703cfe953bccee95685111adeedb76fabe4e97549a58d16f03ea7b9367bb32"
checksum = "4614a76b2a8be0058caa9dbbaf66d988527d86d003c11a94fbd335d7661edcef"
dependencies = [
"autocfg",
]
[[package]]
name = "slotmap"
@ -421,9 +424,9 @@ dependencies = [
[[package]]
name = "smallvec"
version = "1.8.1"
version = "1.9.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "cc88c725d61fc6c3132893370cac4a0200e3fedf5da8331c570664b1987f5ca2"
checksum = "2fd0db749597d91ff862fd1d55ea87f7855a744a8425a64695b6fca237d1dad1"
[[package]]
name = "socket2"
@ -463,10 +466,11 @@ checksum = "cda74da7e1a664f795bb1f8a87ec406fb89a02522cf6e50620d016add6dbbf5c"
[[package]]
name = "tokio"
version = "1.19.2"
version = "1.20.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c51a52ed6686dd62c320f9b89299e9dfb46f730c7a48e635c19f21d116cb1439"
checksum = "7a8325f63a7d4774dd041e363b2409ed1c5cbbd0f867795e661df066b2b0a581"
dependencies = [
"autocfg",
"bytes",
"libc",
"memchr",
@ -503,9 +507,9 @@ dependencies = [
[[package]]
name = "unicode-ident"
version = "1.0.1"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5bd2fe26506023ed7b5e1e315add59d6f584c621d037f9368fea9cfb988f368c"
checksum = "15c61ba63f9235225a22310255a29b806b907c9b8c964bcbd0a2c70f3f2deea7"
[[package]]
name = "version_check"
@ -604,6 +608,7 @@ name = "xcrab"
version = "0.1.0"
dependencies = [
"breadx",
"gluten-keyboard",
"lazy_static",
"serde",
"slotmap",

View file

@ -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"

View file

@ -6,17 +6,4 @@ A window manager written in [Rust](https://rust-lang.org).
## Contributing
Please contribute, we don't know what the fuck we are doing. How we even got to this point is beyond us.
### A small side note about the config file and keybinds
If you wish to set a keybind, you must use a 32-bit unsigned integer value.
These values are pre-defined, and can be found in the `keysymdef.rs` file.
The file is an automatically generated binding from the `keysymdef.h` file
(which can be found at `/usr/include/X11`). Refer to both of these files if
you are having trouble with keybinds. Please note, however, that it is
not a direct binding - the constant names have been trimmed (the prefix `XK_`)
removed, and have been renamed to follow rust constant naming conventions. Some
keysyms (mostly greek ones) have been outright removed, due to me being too lazy
to bother with renaming them all in order to not have conflicts.
> `hungl was here`
Please contribute, we don't know what the fuck we are doing. How we even got to this point is beyond us.

View file

@ -159,7 +159,7 @@ impl<'de> Visitor<'de> for KeybindVisitor {
'C' => mask.set_control(true),
'S' => mask.set_shift(true),
'A' => mask.set_mod1(true), // alt key
'W' => mask.set_mod4(true), // super key, 'w' for windows BECAUSE S is taken
'W' => mask.set_mod4(true), // super key, 'w' for windows because S is taken
_ => return Err(E::custom(format!("no such modifier: {}", c))),
};
}

File diff suppressed because it is too large Load diff

View file

@ -28,16 +28,12 @@ use breadx::{
use lazy_static::lazy_static;
use tokio::sync::mpsc;
use tokio::sync::mpsc::unbounded_channel;
mod config;
mod msg_listener;
mod x11;
mod keysymdef;
use x11::client::{may_not_exist, XcrabWindowManager};
use std::collections::HashMap;
@ -143,35 +139,67 @@ async fn main() -> Result<()> {
conn.ungrab_server_async().await?;
let (send, mut recv) = unbounded_channel();
let (result_send, result_recv) = mpsc::unbounded_channel();
tokio::spawn(msg_listener::listener_task(
CONFIG.msg.clone().unwrap_or_default().socket_path,
send,
result_recv,
));
let mask = ModMask { inner: 20 };
let keymap = keymap(&mut conn).await.unwrap_or_default();
let key_u32 = u32::from_str_radix("0078", 16).unwrap_or_default();
let key: &u8 = keymap.get(&key_u32).ok_or_else(|| {
XcrabError::Custom("the keysym requested was not found in the keymap".to_string())
let mut mask = ModMask::new(false, false, true, false, false, false, false, false, false);
let mut keyboard_state = KeyboardState::new_async(&mut conn).await?;
let keymap = keymap(&mut keyboard_state);
let mut request_key = keymap.get(&120).ok_or_else(|| {
XcrabError::Custom("At least one letter could not be found in the keymap".to_string())
})?;
println!("got to this part");
for (&binds, _action) in &CONFIG.binds {
println!("started iteration");
mask.set_control(binds.mods.control());
mask.set_shift(binds.mods.shift());
mask.set_One(binds.mods.mod1());
mask.set_Four(binds.mods.mod4());
for keysym in 97..122_u32 {
let keycode = keymap.get(&keysym).ok_or_else(|| {
XcrabError::Custom(
"At least one letter could not be found in the keymap".to_string(),
)
})?;
if keyboard_state
.process_keycode(*keycode, KeyButMask::default())
.ok_or_else(|| {
XcrabError::Custom(
"The keycode returned from the keymap could not be processed".to_string(),
)
})?
.as_char()
.ok_or_else(|| {
XcrabError::Custom("The processed Key could not be cast as a char".to_string())
})?
== binds.key
{
request_key = keycode;
} else {
dbg!(binds.key.clone());
}
}
}
conn.exchange_request_async(GrabKeyRequest {
req_type: 33,
owner_events: false,
length: 4,
grab_window: root,
modifiers: mask,
key: *key,
key: *request_key,
pointer_mode: GrabMode::Async,
keyboard_mode: GrabMode::Async,
})
.await?;
// let mut keyboard_state = KeyboardState::new_async(&mut conn).await?;
let (send, mut recv) = unbounded_channel();
let (result_send, result_recv) = unbounded_channel();
tokio::spawn(msg_listener::listener_task(
CONFIG.msg.clone().unwrap_or_default().socket_path,
send,
result_recv,
));
loop {
// biased mode makes select! poll the channel first in order to keep xcrab-msg from being
@ -179,7 +207,7 @@ async fn main() -> Result<()> {
tokio::select! {
biased;
Some(s) = recv.recv() => msg_listener::on_recv(s, &mut manager, &mut conn, &result_send).await?,
Ok(ev) = conn.wait_for_event_async() => process_event(ev, &mut manager, &mut conn, root, &keymap,/* &mut keyboard_state */).await?,
Ok(ev) = conn.wait_for_event_async() => process_event(ev, &mut manager, &mut conn, root,&mut keyboard_state).await?,
}
}
}
@ -189,8 +217,7 @@ async fn process_event<Dpy: AsyncDisplay + ?Sized>(
manager: &mut XcrabWindowManager,
conn: &mut Dpy,
root: Window,
keymap: &HashMap<Keysym, Keycode>,
// keyboard_state: &mut KeyboardState,
keyboard_state: &mut KeyboardState,
) -> Result<()> {
match ev {
Event::MapRequest(ev) => {
@ -233,11 +260,14 @@ async fn process_event<Dpy: AsyncDisplay + ?Sized>(
}
}
Event::KeyPress(ev) => {
let keysym = u32::from_str_radix("0078", 16).unwrap_or_default();
let key = keymap.get(&keysym).unwrap_or(&u8::MIN);
if ev.detail == *key {
manager.destroy_focused_client(conn).await?;
if let Some(k) = keyboard_state.process_keycode(ev.detail, ev.state) {
if let Some(c) = k.as_char() {
for (&bind, action) in &CONFIG.binds {
if bind.key == c && bind.mods == ev.state {
action.eval(manager, conn).await?;
}
}
}
}
}
_ => {}
@ -248,8 +278,7 @@ async fn process_event<Dpy: AsyncDisplay + ?Sized>(
// I will move this to x11/client.rs eventually
// this is just ease of coding for now
async fn keymap<Dpy: AsyncDisplay + ?Sized>(conn: &mut Dpy) -> Option<HashMap<Keysym, Keycode>> {
let mut state = KeyboardState::new_async(conn).await.ok()?;
fn keymap(state: &mut KeyboardState) -> HashMap<Keysym, Keycode> {
let mut map: HashMap<Keysym, Keycode> = HashMap::new();
for keycode in 8..255_u8 {
let key = state.process_keycode(keycode, KeyButMask::default());
@ -260,5 +289,5 @@ async fn keymap<Dpy: AsyncDisplay + ?Sized>(conn: &mut Dpy) -> Option<HashMap<Ke
}
}
}
Some(map)
map
}

View file

@ -50,7 +50,7 @@ pub async fn listener_task<P: AsRef<Path>>(
drop(sender.send(buf)); // go back to ms word clippy
// we can unwrap here BECAUSE if the channel is closed then something's not right
// we can unwrap here because if the channel is closed then something's not right
if let Err(e) = result_recv.recv().await.unwrap() {
stream.write_all(format!("{}", e).as_bytes()).await?;
} else {
@ -68,7 +68,7 @@ pub async fn on_recv<Dpy: AsyncDisplay + ?Sized>(
let res = { data.parse::<Action>() };
if let Ok(ref a) = res {
a.eval(manager, conn).await?; // Don't send these errors over the channel, BECAUSE they're
a.eval(manager, conn).await?; // Don't send these errors over the channel, because they're
// xcrab errors, not msg errors
}

View file

@ -626,7 +626,7 @@ impl XcrabWindowManager {
pub fn may_not_exist(res: breadx::Result) -> breadx::Result {
match res {
// if its a `Window` error, that means it happened BECAUSE
// if its a `Window` error, that means it happened because
// a window failed to exist, and we want to allow those
Err(BreadError::XProtocol {
error_code: ErrorCode(3),
@ -834,7 +834,7 @@ impl FramedWindow {
async fn frame<Dpy: AsyncDisplay + ?Sized>(conn: &mut Dpy, win: Window) -> Result<FramedWindow> {
let root = conn.default_root();
// here, we cant use `may_not_exist` BECAUSE we need the geometry
// here, we cant use `may_not_exist` because we need the geometry
let geometry = win.geometry_immediate_async(conn).await?;
let frame = conn