more small changes to satisfy karx
This commit is contained in:
parent
a6059ab533
commit
043bbb63ff
20
src/main.rs
20
src/main.rs
|
@ -141,7 +141,7 @@ async fn main() -> Result<()> {
|
|||
|
||||
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 keymap = x11::client::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())
|
||||
})?;
|
||||
|
@ -220,7 +220,6 @@ async fn main() -> Result<()> {
|
|||
}
|
||||
|
||||
#[allow(clippy::too_many_lines)]
|
||||
|
||||
async fn process_event<Dpy: AsyncDisplay + ?Sized>(
|
||||
ev: Event,
|
||||
manager: &mut XcrabWindowManager,
|
||||
|
@ -283,20 +282,3 @@ async fn process_event<Dpy: AsyncDisplay + ?Sized>(
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
// I will move this to x11/client.rs eventually
|
||||
// this is just ease of coding for now
|
||||
|
||||
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());
|
||||
let keysyms = state.lookup_keysyms(keycode);
|
||||
if key != None {
|
||||
for keysym in keysyms {
|
||||
map.insert(*keysym, keycode);
|
||||
}
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
||||
|
|
|
@ -1,28 +1,34 @@
|
|||
// Copyright (C) 2022 Infoshock Tech
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
use crate::Result;
|
||||
use serde::Deserialize;
|
||||
use std::path::PathBuf;
|
||||
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Clone, Debug, Default, Deserialize)]
|
||||
// Dummy struct for deserializing the message config - we're using the same file for both binaries
|
||||
pub struct XcrabConfig {
|
||||
pub msg: XcrabMsgConfig,
|
||||
}
|
||||
|
||||
#[allow(clippy::module_name_repetitions)]
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
pub struct XcrabMsgConfig {
|
||||
pub socket_path: PathBuf,
|
||||
}
|
||||
|
||||
impl Default for XcrabMsgConfig {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
|
@ -30,15 +36,18 @@ impl Default for XcrabMsgConfig {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn load_file_inner() -> Result<XcrabConfig> {
|
||||
let home_dir = get_home();
|
||||
let contents = std::fs::read_to_string(format!("{}/.config/xcrab/config.toml", home_dir))?;
|
||||
let config: XcrabConfig = toml::from_str(&contents)?;
|
||||
Ok(config)
|
||||
}
|
||||
|
||||
pub fn load_file() -> XcrabConfig {
|
||||
load_file_inner().unwrap_or_default()
|
||||
}
|
||||
|
||||
fn get_home() -> String {
|
||||
std::env::var("HOME").expect("Error: $HOME variable was not set")
|
||||
}
|
||||
|
|
|
@ -1,47 +1,67 @@
|
|||
// Copyright (C) 2022 Infoshock Tech
|
||||
|
||||
// This program is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
#![warn(clippy::pedantic)]
|
||||
|
||||
mod config;
|
||||
|
||||
use std::error::Error;
|
||||
use std::fmt::{Debug, Display, Formatter, Result as FmtResult};
|
||||
use tokio::io::{AsyncReadExt, AsyncWriteExt};
|
||||
use tokio::net::UnixStream;
|
||||
|
||||
type Result<T> = std::result::Result<T, Box<dyn Error>>;
|
||||
|
||||
struct CustomError(String);
|
||||
|
||||
impl Debug for CustomError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Display for CustomError {
|
||||
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
|
||||
f.write_str(&self.0)
|
||||
}
|
||||
}
|
||||
|
||||
impl Error for CustomError {}
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
let msg = std::env::args().skip(1).collect::<Vec<String>>().join(" ");
|
||||
|
||||
let conf = config::load_file();
|
||||
|
||||
let path = conf.msg.socket_path;
|
||||
|
||||
let stream = UnixStream::connect(path).await?;
|
||||
|
||||
let (mut read, mut write) = stream.into_split();
|
||||
|
||||
write.write_all(msg.as_bytes()).await?;
|
||||
drop(write); // Shutdown the writer half so that the write actually goes through
|
||||
// "Don't cross the streams!""
|
||||
|
||||
let mut buf = String::new();
|
||||
|
||||
read.read_to_string(&mut buf).await?;
|
||||
if !buf.is_empty() {
|
||||
return Err(CustomError(buf).into());
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
@ -13,15 +13,10 @@
|
|||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
use breadx::{
|
||||
auto::xproto::{ClientMessageEvent, InputFocus, SetInputFocusRequest},
|
||||
client_message_data::ClientMessageData,
|
||||
prelude::{AsByteSequence, AsyncDisplayXprotoExt, PropertyType, SetMode},
|
||||
AsyncDisplay, AsyncDisplayExt, Atom, BreadError, ConfigureWindowParameters, ErrorCode, Event,
|
||||
EventMask, Window, WindowParameters, XidType,
|
||||
};
|
||||
use breadx::{auto::xproto::{ClientMessageEvent, InputFocus, SetInputFocusRequest}, client_message_data::ClientMessageData, prelude::{AsByteSequence, AsyncDisplayXprotoExt, PropertyType, SetMode}, AsyncDisplay, AsyncDisplayExt, Atom, BreadError, ConfigureWindowParameters, ErrorCode, Event, EventMask, Window, WindowParameters, XidType, KeyboardState};
|
||||
use slotmap::{new_key_type, SlotMap};
|
||||
use std::{collections::HashMap, future::Future, pin::Pin, slice};
|
||||
use breadx::auto::xproto::{KeyButMask, Keycode, Keysym};
|
||||
|
||||
use crate::{Result, XcrabError, CONFIG};
|
||||
|
||||
|
@ -844,3 +839,17 @@ async fn frame<Dpy: AsyncDisplay + ?Sized>(conn: &mut Dpy, win: Window) -> Resul
|
|||
|
||||
Ok(FramedWindow { frame, win })
|
||||
}
|
||||
|
||||
pub 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());
|
||||
let keysyms = state.lookup_keysyms(keycode);
|
||||
if key != None {
|
||||
for keysym in keysyms {
|
||||
map.insert(*keysym, keycode);
|
||||
}
|
||||
}
|
||||
}
|
||||
map
|
||||
}
|
Loading…
Reference in a new issue