Skip to content

Commit

Permalink
resize windows with keybinding (leftwm#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
theguy147 authored Jan 12, 2021
1 parent a1d2872 commit e905270
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ pub enum Command {
MouseMoveWindow,
NextLayout,
PreviousLayout,
IncreaseMainWidth,
DecreaseMainWidth,
}
23 changes: 23 additions & 0 deletions src/handlers/command_handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,29 @@ pub fn process(manager: &mut Manager, command: Command, val: Option<String>) ->
manager.hard_reload();
false
}

Command::IncreaseMainWidth if val.is_none() => false,
Command::IncreaseMainWidth => {
let workspace = manager.focused_workspace_mut();
if workspace.is_none() {
return false;
}
let workspace = workspace.unwrap();
let delta: u8 = (&val.unwrap()).parse().unwrap();
workspace.increase_main_width(delta);
true
}
Command::DecreaseMainWidth if val.is_none() => false,
Command::DecreaseMainWidth => {
let workspace = manager.focused_workspace_mut();
if workspace.is_none() {
return false;
}
let workspace = workspace.unwrap();
let delta: u8 = (&val.unwrap()).parse().unwrap();
workspace.decrease_main_width(delta);
true
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/layouts/main_and_vert_stack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub fn update(workspace: &Workspace, windows: &mut Vec<&mut &mut Window>) {

let width = match window_count {
1 => workspace.width() as i32,
_ => (workspace.width() as f32 / 2.0).floor() as i32,
_ => (workspace.width() as f32 / 100.0 * workspace.main_width()).floor() as i32,
};

//build build the main window.
Expand All @@ -31,7 +31,7 @@ pub fn update(workspace: &Workspace, windows: &mut Vec<&mut &mut Window>) {
let mut y = 0;
for w in iter {
w.set_height(height);
w.set_width(width);
w.set_width(workspace.width() - width);
w.set_x(workspace.x() + width);
w.set_y(workspace.y() + y);
y += height;
Expand Down
19 changes: 19 additions & 0 deletions src/models/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub struct Workspace {
pub tags: Vec<Tag>,
pub avoid: Vec<XYHW>,
pub xyhw: XYHW,
pub main_width_percentage: u8,
xyhw_avoided: XYHW,
}

Expand Down Expand Up @@ -45,6 +46,7 @@ impl Workspace {
layout: Layout::default(),
tags: vec![],
avoid: vec![],
main_width_percentage: 50,

xyhw: XYHWBuilder {
h: bbox.height,
Expand Down Expand Up @@ -138,6 +140,23 @@ impl Workspace {
self.xyhw_avoided.w()
}

pub fn increase_main_width(&mut self, delta: u8) {
self.main_width_percentage += delta;
if self.main_width_percentage > 100 {
self.main_width_percentage = 100
}
}
pub fn decrease_main_width(&mut self, delta: u8) {
if self.main_width_percentage > delta {
self.main_width_percentage -= delta;
} else {
self.main_width_percentage = 0;
}
}
pub fn main_width(&self) -> f32 {
self.main_width_percentage as f32
}

pub fn center_halfed(&self) -> XYHW {
self.xyhw_avoided.center_halfed()
}
Expand Down

0 comments on commit e905270

Please sign in to comment.