removed unused client tests and added keybinds to change stack widths
This commit is contained in:
parent
984f0763c7
commit
e536bb6f37
130
src/clients.rs
130
src/clients.rs
|
@ -117,66 +117,7 @@ mod client {
|
||||||
|
|
||||||
pub use client::*;
|
pub use client::*;
|
||||||
|
|
||||||
#[cfg(test)]
|
use std::collections::VecDeque;
|
||||||
mod tests {
|
|
||||||
use super::*;
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn client_lists_test() {
|
|
||||||
let mut clients = ClientState::with_virtualscreens(3);
|
|
||||||
|
|
||||||
clients.insert(Client {
|
|
||||||
window: 1,
|
|
||||||
size: (1, 1),
|
|
||||||
position: (1, 1),
|
|
||||||
transient_for: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
clients.insert(Client {
|
|
||||||
window: 2,
|
|
||||||
size: (1, 1),
|
|
||||||
position: (1, 1),
|
|
||||||
transient_for: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
clients.arrange_virtual_screen(600, 400, None);
|
|
||||||
|
|
||||||
println!("{:#?}", clients);
|
|
||||||
|
|
||||||
clients
|
|
||||||
.iter_current_screen()
|
|
||||||
.for_each(|c| println!("{:?}", c));
|
|
||||||
|
|
||||||
clients.remove(&1u64);
|
|
||||||
|
|
||||||
clients.arrange_virtual_screen(600, 400, None);
|
|
||||||
|
|
||||||
println!("{:#?}", clients);
|
|
||||||
|
|
||||||
clients.rotate_right();
|
|
||||||
|
|
||||||
clients.insert(Client {
|
|
||||||
window: 3,
|
|
||||||
size: (1, 1),
|
|
||||||
position: (1, 1),
|
|
||||||
transient_for: None,
|
|
||||||
});
|
|
||||||
|
|
||||||
clients.arrange_virtual_screen(600, 400, None);
|
|
||||||
|
|
||||||
println!("{:#?}", clients);
|
|
||||||
|
|
||||||
clients.toggle_floating(&2u64);
|
|
||||||
|
|
||||||
clients.rotate_left();
|
|
||||||
|
|
||||||
clients.arrange_virtual_screen(600, 400, None);
|
|
||||||
|
|
||||||
println!("{:#?}", clients);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
use std::{collections::VecDeque, iter::repeat};
|
|
||||||
|
|
||||||
type Clients = IndexMap<u64, Client, BuildIdentityHasher>;
|
type Clients = IndexMap<u64, Client, BuildIdentityHasher>;
|
||||||
type ClientRef = u64;
|
type ClientRef = u64;
|
||||||
|
@ -200,8 +141,9 @@ pub struct ClientState {
|
||||||
focused: Option<ClientRef>,
|
focused: Option<ClientRef>,
|
||||||
pub(self) virtual_screens: VecDeque<VirtualScreen>,
|
pub(self) virtual_screens: VecDeque<VirtualScreen>,
|
||||||
|
|
||||||
gap: i32,
|
pub(self) gap: i32,
|
||||||
screen_size: (i32, i32),
|
pub(self) screen_size: (i32, i32),
|
||||||
|
pub(self) master_size: f32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
@ -222,6 +164,7 @@ impl Default for ClientState {
|
||||||
virtual_screens: vss,
|
virtual_screens: vss,
|
||||||
gap: 0,
|
gap: 0,
|
||||||
screen_size: (1, 1),
|
screen_size: (1, 1),
|
||||||
|
master_size: 1.0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -666,7 +609,22 @@ impl ClientState {
|
||||||
// should be fine to unwrap since we will always have at least 1 virtual screen
|
// should be fine to unwrap since we will always have at least 1 virtual screen
|
||||||
if let Some(vs) = self.virtual_screens.front_mut() {
|
if let Some(vs) = self.virtual_screens.front_mut() {
|
||||||
// if aux is empty -> width : width / 2
|
// if aux is empty -> width : width / 2
|
||||||
let width = (width - gap * 2) / (1 + i32::from(!vs.aux.is_empty()));
|
|
||||||
|
let (master_width, aux_width) = {
|
||||||
|
let effective_width = width - gap * 2;
|
||||||
|
|
||||||
|
let master_size = if vs.aux.is_empty() {
|
||||||
|
1.0
|
||||||
|
} else {
|
||||||
|
self.master_size / 2.0
|
||||||
|
};
|
||||||
|
|
||||||
|
let master_width =
|
||||||
|
(effective_width as f32 * master_size) as i32;
|
||||||
|
let aux_width = effective_width - master_width;
|
||||||
|
|
||||||
|
(master_width, aux_width)
|
||||||
|
};
|
||||||
|
|
||||||
// make sure we dont devide by 0
|
// make sure we dont devide by 0
|
||||||
// height is max height / number of clients in the stack
|
// height is max height / number of clients in the stack
|
||||||
|
@ -683,24 +641,25 @@ impl ClientState {
|
||||||
None => 1,
|
None => 1,
|
||||||
};
|
};
|
||||||
|
|
||||||
// chaining master and aux together with `Zip`s for height and x
|
// Master
|
||||||
// reduces duplicate code
|
for (i, key) in vs.master.iter().enumerate() {
|
||||||
for ((i, key), (height, x)) in vs
|
let size = (master_width - gap * 2, master_height - gap * 2);
|
||||||
.master
|
let position = (gap * 2, master_height * i as i32 + gap * 2);
|
||||||
.iter()
|
|
||||||
.enumerate()
|
if let Some(client) = self.clients.get_mut(key) {
|
||||||
// add repeating height for each window and x pos for each window
|
*client = Client {
|
||||||
.zip(repeat(master_height).zip(repeat(0i32)))
|
size,
|
||||||
.chain(
|
position,
|
||||||
// same things for aux stack
|
..*client
|
||||||
vs.aux
|
};
|
||||||
.iter()
|
}
|
||||||
.enumerate()
|
}
|
||||||
.zip(repeat(aux_height).zip(repeat(width))),
|
|
||||||
)
|
// Aux
|
||||||
{
|
for (i, key) in vs.aux.iter().enumerate() {
|
||||||
let size = (width - gap * 2, height - gap * 2);
|
let size = (aux_width - gap * 2, aux_height - gap * 2);
|
||||||
let position = (x + gap * 2, height * i as i32 + gap * 2);
|
let position =
|
||||||
|
(master_width + gap * 2, aux_height * i as i32 + gap * 2);
|
||||||
|
|
||||||
if let Some(client) = self.clients.get_mut(key) {
|
if let Some(client) = self.clients.get_mut(key) {
|
||||||
*client = Client {
|
*client = Client {
|
||||||
|
@ -712,10 +671,15 @@ impl ClientState {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//info!("{:#?}", self);
|
// Should have xlib send those changes back to the x server after this function
|
||||||
}
|
}
|
||||||
|
|
||||||
// Should have xlib send those changes back to the x server after this function
|
pub fn change_master_size(&mut self, delta: f32) {
|
||||||
|
let tmp = self.master_size + delta;
|
||||||
|
self.master_size = f32::min(1.8, f32::max(0.2, tmp));
|
||||||
|
|
||||||
|
self.arrange_virtual_screen();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for VirtualScreen {
|
impl Default for VirtualScreen {
|
||||||
|
|
134
src/state.rs
134
src/state.rs
|
@ -156,21 +156,6 @@ impl WindowManager {
|
||||||
|wm, _| wm.spawn("alacritty", &[]),
|
|wm, _| wm.spawn("alacritty", &[]),
|
||||||
));
|
));
|
||||||
|
|
||||||
self.add_keybind(KeyBinding::new(
|
|
||||||
self.xlib.make_key("Left", self.config.mod_key),
|
|
||||||
|wm, _| wm.rotate_virtual_screen(Direction::west()),
|
|
||||||
));
|
|
||||||
|
|
||||||
self.add_keybind(KeyBinding::new(
|
|
||||||
self.xlib.make_key("Right", self.config.mod_key),
|
|
||||||
|wm, _| wm.rotate_virtual_screen(Direction::east()),
|
|
||||||
));
|
|
||||||
|
|
||||||
self.add_keybind(KeyBinding::new(
|
|
||||||
self.xlib.make_key("Tab", self.config.mod_key),
|
|
||||||
|wm, _| wm.rotate_virtual_screen_back(),
|
|
||||||
));
|
|
||||||
|
|
||||||
self.add_keybind(KeyBinding::new(
|
self.add_keybind(KeyBinding::new(
|
||||||
self.xlib.make_key("J", self.config.mod_key),
|
self.xlib.make_key("J", self.config.mod_key),
|
||||||
|wm, _| wm.move_focus(Direction::south()),
|
|wm, _| wm.move_focus(Direction::south()),
|
||||||
|
@ -191,16 +176,26 @@ impl WindowManager {
|
||||||
|wm, _| wm.move_focus(Direction::east()),
|
|wm, _| wm.move_focus(Direction::east()),
|
||||||
));
|
));
|
||||||
|
|
||||||
self.add_keybind(KeyBinding::new(
|
// resize master stack
|
||||||
self.xlib.make_key("J", self.config.mod_key | ShiftMask),
|
|
||||||
|wm, _| wm.rotate_virtual_screen(Direction::west()),
|
|
||||||
));
|
|
||||||
|
|
||||||
self.add_keybind(KeyBinding::new(
|
self.add_keybind(KeyBinding::new(
|
||||||
self.xlib.make_key("K", self.config.mod_key | ShiftMask),
|
self.xlib.make_key("K", self.config.mod_key | ShiftMask),
|
||||||
|wm, _| wm.rotate_virtual_screen(Direction::east()),
|
|wm, _| {
|
||||||
|
wm.clients.change_master_size(0.1);
|
||||||
|
wm.arrange_clients();
|
||||||
|
},
|
||||||
));
|
));
|
||||||
|
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("J", self.config.mod_key | ShiftMask),
|
||||||
|
|wm, _| {
|
||||||
|
wm.clients.change_master_size(-0.1);
|
||||||
|
wm.arrange_clients();
|
||||||
|
},
|
||||||
|
));
|
||||||
|
|
||||||
|
self.add_vs_switch_keybinds();
|
||||||
|
|
||||||
self.xlib.init();
|
self.xlib.init();
|
||||||
|
|
||||||
self
|
self
|
||||||
|
@ -211,6 +206,105 @@ impl WindowManager {
|
||||||
self.keybinds.push(keybind);
|
self.keybinds.push(keybind);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn add_vs_switch_keybinds(&mut self) {
|
||||||
|
fn rotate_west<const N: usize>(wm: &mut WindowManager, _: &XKeyEvent) {
|
||||||
|
wm.rotate_virtual_screen(Direction::West(N));
|
||||||
|
}
|
||||||
|
|
||||||
|
fn rotate_east<const N: usize>(wm: &mut WindowManager, _: &XKeyEvent) {
|
||||||
|
wm.rotate_virtual_screen(Direction::East(N));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Old keybinds
|
||||||
|
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("Left", self.config.mod_key),
|
||||||
|
rotate_west::<1>,
|
||||||
|
));
|
||||||
|
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("H", self.config.mod_key | ShiftMask),
|
||||||
|
rotate_west::<1>,
|
||||||
|
));
|
||||||
|
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("Right", self.config.mod_key),
|
||||||
|
rotate_east::<1>,
|
||||||
|
));
|
||||||
|
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("L", self.config.mod_key | ShiftMask),
|
||||||
|
rotate_east::<1>,
|
||||||
|
));
|
||||||
|
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("Tab", self.config.mod_key),
|
||||||
|
|wm, _| wm.rotate_virtual_screen_back(),
|
||||||
|
));
|
||||||
|
|
||||||
|
// Mod + (Shift) + Num
|
||||||
|
|
||||||
|
// Press Mod + `1` to move `1` virtual screen to the right
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("1", self.config.mod_key),
|
||||||
|
rotate_east::<1>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + Shift + `1` to move `1` virtual screen to the left
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("1", self.config.mod_key | ShiftMask),
|
||||||
|
rotate_west::<1>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + `2` to move `2` virtual screen to the right
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("2", self.config.mod_key),
|
||||||
|
rotate_east::<2>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + Shift + `2` to move `2` virtual screen to the left
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("2", self.config.mod_key | ShiftMask),
|
||||||
|
rotate_west::<2>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + `3` to move `3` virtual screen to the right
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("3", self.config.mod_key),
|
||||||
|
rotate_east::<3>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + Shift + `3` to move `3` virtual screen to the left
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("3", self.config.mod_key | ShiftMask),
|
||||||
|
rotate_west::<3>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + `4` to move `4` virtual screen to the right
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("4", self.config.mod_key),
|
||||||
|
rotate_east::<4>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + Shift + `4` to move `4` virtual screen to the left
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("4", self.config.mod_key | ShiftMask),
|
||||||
|
rotate_west::<4>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + `5` to move `5` virtual screen to the right
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("5", self.config.mod_key),
|
||||||
|
rotate_east::<5>,
|
||||||
|
));
|
||||||
|
|
||||||
|
// Press Mod + Shift + `5` to move `5` virtual screen to the left
|
||||||
|
self.add_keybind(KeyBinding::new(
|
||||||
|
self.xlib.make_key("5", self.config.mod_key | ShiftMask),
|
||||||
|
rotate_west::<5>,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
pub fn run(mut self) -> ! {
|
pub fn run(mut self) -> ! {
|
||||||
loop {
|
loop {
|
||||||
let event = self.xlib.next_event();
|
let event = self.xlib.next_event();
|
||||||
|
|
Loading…
Reference in a new issue