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

restrict superKey to meta or ctrl #52

Closed
wants to merge 8 commits into from
Closed
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
9 changes: 1 addition & 8 deletions .github/workflows/rust.yml → .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
name: Rust
name: Release

on:
push:
branches:
- master
tags:
- 'v*'
pull_request:
branches:
- master

jobs:
build:
Expand Down Expand Up @@ -38,5 +33,3 @@ jobs:
asset_name: Hadlock
tag: ${{ github.ref }}
overwrite: true


30 changes: 30 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Test

on:
push:
branches:
- master
pull_request:
branches:
- master

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: Install dependencies
run: |
sudo apt update
sudo apt install libxinerama-dev
sudo apt install libdbus-1-dev
- name: rustfmt
run: cargo fmt -- --check
- name: clippy
run: cargo clippy
- name: Build
run: cargo build
- name: Run tests
run: cargo test --verbose
18 changes: 10 additions & 8 deletions src/config/config_model.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use super::KeyAction;
use crate::layout::LayoutTag;
use crate::xlibwrapper::util::{
keysym_lookup::{into_mod, ModMask},
Color,
keysym_lookup::{ModMask, into_mod}
};
use crate::layout::LayoutTag;
use x11_dl::xlib::Mod4Mask;
use serde::{self, Deserialize, Serialize, Deserializer, de};
use serde::{self, de, Deserialize, Deserializer, Serialize};
use std::collections::BTreeMap;
use x11_dl::xlib::Mod4Mask;

#[derive(Serialize, Deserialize, Debug)]
pub struct Config {
Expand Down Expand Up @@ -70,12 +70,14 @@ where

let ret = into_mod(&s);
if ret != 0 {
debug!("ControlMask: {}, super_key: {}", x11_dl::xlib::ControlMask, ret);
debug!(
"ControlMask: {}, super_key: {}",
x11_dl::xlib::ControlMask,
ret
);
Ok(ret)
} else {
Err(de::Error::custom(format!(
"{} is not a valid key", s
)))
Err(de::Error::custom(format!("{} is not a valid key", s)))
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/config/loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ pub(super) fn load_config() -> Config {
let path = Path::new(path);

if path.exists() && path.is_file() {
let mut file = fs::File::open(path).unwrap_or_else(|_| panic!("Failed to open file: {:?}", path));
let mut file =
fs::File::open(path).unwrap_or_else(|_| panic!("Failed to open file: {:?}", path));
let mut file_content = String::new();
file.read_to_string(&mut file_content)
.unwrap_or_else(|_| panic!("Failed to read file content: {:?}", path));
Expand Down
15 changes: 8 additions & 7 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,20 @@ use serde::{Deserialize, Serialize};

use config_model::*;

lazy_static! { pub static ref CONFIG: Config = loader::load_config(); }
lazy_static! {
pub static ref CONFIG: Config = loader::load_config();
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum Axis {
Horizontal,
Vertical
Vertical,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum Key {
Letter(String),
Number
Number,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
Expand All @@ -37,23 +39,22 @@ pub enum KeyEffect {
SwapMaster,
ToggleMonocle,
ToggleMaximize,
Custom(Command)
Custom(Command),
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub struct KeyAction {
#[serde(rename = "modKey")]
pub mod_key: Option<String>,
pub key: Key,
pub effect: KeyEffect
pub effect: KeyEffect,
}


#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
pub enum ExecTime {
Pre,
Post,
Now
Now,
}

#[derive(Serialize, Deserialize, Debug, Clone, PartialEq, Eq)]
Expand Down
18 changes: 9 additions & 9 deletions src/hdl_dispatcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ pub fn run(xlib: Box<Rc<dyn DisplayServer>>, sender: Sender<bool>) {
xlib::MapRequest => {
let event = xlib::XMapRequestEvent::from(xevent);
/*debug!(
"window type: {}",
xlib.get_window_type(event.window).get_name()
);*/
"window type: {}",
xlib.get_window_type(event.window).get_name()
);*/
store.dispatch(action::MapRequest {
win: event.window,
parent: event.parent,
Expand Down Expand Up @@ -94,9 +94,9 @@ pub fn run(xlib: Box<Rc<dyn DisplayServer>>, sender: Sender<bool>) {
})
}
/*xlib::KeyRelease => {
let event = xlib::XKeyEvent::from(xevent);
action::KeyRelease{win: event.window, state: event.state, keycode: event.keycode};
},*/
let event = xlib::XKeyEvent::from(xevent);
action::KeyRelease{win: event.window, state: event.state, keycode: event.keycode};
},*/
xlib::MotionNotify => {
//debug!("motion");

Expand All @@ -121,9 +121,9 @@ pub fn run(xlib: Box<Rc<dyn DisplayServer>>, sender: Sender<bool>) {
store.dispatch(action::LeaveNotify { win: event.window })
}
/*xlib::Expose => {
let event = xlib::XExposeEvent::from(xevent);
action::Expose{win: event.window};
},*/
let event = xlib::XExposeEvent::from(xevent);
action::Expose{win: event.window};
},*/
xlib::DestroyNotify => {
let event = xlib::XDestroyWindowEvent::from(xevent);
store.dispatch(action::Destroy { win: event.window })
Expand Down
35 changes: 19 additions & 16 deletions src/hdl_reactor.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use {
crate::config::{CONFIG, Key},
crate::config::{Key, CONFIG},
crate::models::{internal_action::InternalAction, windowwrapper::*, HandleState, WindowState},
crate::state::*,
crate::{
Expand Down Expand Up @@ -131,7 +131,7 @@ impl Reactor<State> for HdlReactor {
HandleState::MaximizeRestore | HandleState::MonocleRestore => {
self.lib.move_window(*key, val.get_position());
self.lib.resize_window(*key, val.get_size());
if ws.clients.len() > 1 {
if ws.clients.len() > 1 {
self.lib.set_border_width(*key, CONFIG.border_width as u32);
self.lib.set_border_color(*key, CONFIG.background_color);
}
Expand Down Expand Up @@ -174,12 +174,12 @@ impl HdlReactor {
self.lib.select_input(
w,
SubstructureNotifyMask
| SubstructureRedirectMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
| PropertyChangeMask
| PointerMotionMask,
| SubstructureRedirectMask
| EnterWindowMask
| LeaveWindowMask
| FocusChangeMask
| PropertyChangeMask
| PointerMotionMask,
);
self.lib.flush();
}
Expand All @@ -202,21 +202,24 @@ impl HdlReactor {
}

fn grab_keys(&self, w: Window) {
let key_list = CONFIG.key_bindings
let key_list = CONFIG
.key_bindings
.iter()
.filter(|binding| match binding.key {
Key::Letter(_) => true,
_ => false
_ => false,
})
.cloned()
.map(|binding|{
match binding.key {
Key::Letter(x) => x,
_ => "".to_string()
}
.map(|binding| match binding.key {
Key::Letter(x) => x,
_ => "".to_string(),
})
.filter(|key| !key.is_empty())
.chain(vec![1,2,3,4,5,6,7,8,9].iter().map(|x| x.to_string()))
.chain(
vec![1, 2, 3, 4, 5, 6, 7, 8, 9]
.iter()
.map(|x| x.to_string()),
)
.collect::<Vec<String>>();

for mod_key in mod_masks_vec() {
Expand Down
8 changes: 5 additions & 3 deletions src/layout/column_master.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ impl ColumnMaster {
} else {
1
})
- 2 * CONFIG.border_width;
- 2 * CONFIG.border_width;

if column.len() > 2 {
ret -= ((column.len() as i32 - 1).abs() * CONFIG.inner_gap) / column.len() as i32
Expand All @@ -92,7 +92,6 @@ impl std::fmt::Display for ColumnMaster {
}

impl Layout for ColumnMaster {

fn get_type(&self) -> LayoutTag {
self.layout_type
}
Expand All @@ -105,7 +104,10 @@ impl Layout for ColumnMaster {
windows: Vec<&WindowWrapper>,
) -> Vec<(Window, Rect)> {
//debug!("Incoming window vector in column_master: {:#?}", windows);
let windows = windows.into_iter().filter(|ww| !ww.is_trans).collect::<Vec<&WindowWrapper>>();
let windows = windows
.into_iter()
.filter(|ww| !ww.is_trans)
.collect::<Vec<&WindowWrapper>>();

let dock_height = match dock_area.as_rect(screen) {
Some(dock_rect) => dock_rect.get_size().height,
Expand Down
27 changes: 17 additions & 10 deletions src/layout/floating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ impl Layout for Floating {
)
}


fn reorder(
&mut self,
focus: Window,
Expand All @@ -132,37 +131,46 @@ impl Layout for Floating {
None => {
let rect_tuple: (Position, Size) = screen.clone().into();
Rect::new(rect_tuple.0, rect_tuple.1)
},
}
};

let win_size_x = (space_rect.get_size().width / 2) - 2 * CONFIG.border_width;
let win_size_y = (space_rect.get_size().height / 2) - 2 * CONFIG.border_width;

let center_win_pos = Position {
x: space_rect.get_position().x + (space_rect.get_size().width / 2) - (win_size_x / 2),
y: space_rect.get_position().y + (space_rect.get_size().height / 2) - (win_size_y / 2)
y: space_rect.get_position().y + (space_rect.get_size().height / 2) - (win_size_y / 2),
};

let step_size_x = (space_rect.get_position().x - center_win_pos.x).abs() / if !windows.is_empty() {windows.len() as i32} else { 1 };
let step_size_y = (space_rect.get_position().y - center_win_pos.y).abs() / if !windows.is_empty() {windows.len() as i32} else { 1 };
let step_size_x = (space_rect.get_position().x - center_win_pos.x).abs()
/ if !windows.is_empty() {
windows.len() as i32
} else {
1
};
let step_size_y = (space_rect.get_position().y - center_win_pos.y).abs()
/ if !windows.is_empty() {
windows.len() as i32
} else {
1
};

windows
.iter()
.rev()
.enumerate()
.map(|(index, win)| {
let pos = Position {
x: center_win_pos.x
- (index as i32 * step_size_x),
y: center_win_pos.y - (index as i32 * step_size_y),
x: center_win_pos.x - (index as i32 * step_size_x),
y: center_win_pos.y - (index as i32 * step_size_y),
};
let size = Size {
width: win_size_x,
height: win_size_y,
};
(win.window(), Rect::new(pos, size))
})
.collect::<Vec<(Window, Rect)>>()
.collect::<Vec<(Window, Rect)>>()
}

fn resize_window(
Expand Down Expand Up @@ -340,4 +348,3 @@ impl Layout for Floating {
}
}
}

1 change: 0 additions & 1 deletion src/layout/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ pub fn layout_from_tag(tag: LayoutTag) -> Box<dyn Layout> {
}

pub trait Layout: std::fmt::Debug + std::fmt::Display {

fn get_type(&self) -> LayoutTag;

fn place_window(
Expand Down
10 changes: 6 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ mod wm;
mod xlibwrapper;

use std::{process::Command, rc::Rc, sync::mpsc, thread};
use xlibwrapper::{DisplayServer, core::*};
use xlibwrapper::{core::*, DisplayServer};

use crate::config::*;
use nix::sys::signal::{self, SigHandler, Signal};
use lazy_static::initialize;
use nix::sys::signal::{self, SigHandler, Signal};

pub type HadlockResult<T> = Result<T, Box<dyn std::error::Error>>;
pub type HadlockOption<T> = Option<T>;
Expand All @@ -36,8 +36,10 @@ fn main() -> HadlockResult<()> {
// Avoid zombies by ignoring SIGCHLD
unsafe { signal::signal(Signal::SIGCHLD, SigHandler::SigIgn) }.unwrap();
call_commands(ExecTime::Pre);
thread::spawn(move || if let Ok(true) = rx.recv() {
call_commands(ExecTime::Post)
thread::spawn(move || {
if let Ok(true) = rx.recv() {
call_commands(ExecTime::Post)
}
});

hdl_dispatcher::run(Box::new(xlib), tx);
Expand Down
2 changes: 1 addition & 1 deletion src/models/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ pub mod window_type;
pub mod windowwrapper;
pub mod workspace;

use std::cell::RefCell;
use serde::{Deserialize, Serialize};
use std::cell::RefCell;

#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub enum WindowState {
Expand Down
Loading