Skip to content

Commit ce0255e

Browse files
omark96LGUG2Z
authored andcommitted
feat(config): add work-area-offset per workspace
This commit adds the option to set 'work_area_offset' per workspace. If no workspace work area offset is set for that workspace it will instead use the value of the globals.work_area_offset for that workspace. This commit adds a command to set the work area offset of a workspace given a monitor index and a workspace index.
1 parent 0a65c6d commit ce0255e

File tree

9 files changed

+756
-101
lines changed

9 files changed

+756
-101
lines changed

komorebi/src/core/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ pub enum SocketMessage {
202202
StackbarFontFamily(Option<String>),
203203
WorkAreaOffset(Rect),
204204
MonitorWorkAreaOffset(usize, Rect),
205+
WorkspaceWorkAreaOffset(usize, usize, Rect),
205206
ToggleWindowBasedWorkAreaOffset,
206207
ResizeDelta(i32),
207208
InitialWorkspaceRule(ApplicationIdentifier, String, usize, usize),

komorebi/src/process_command.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1886,6 +1886,14 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
18861886
self.retile_all(false)?;
18871887
}
18881888
}
1889+
SocketMessage::WorkspaceWorkAreaOffset(monitor_idx, workspace_idx, rect) => {
1890+
if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx) {
1891+
if let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx) {
1892+
workspace.set_work_area_offset(Option::from(rect));
1893+
self.retile_all(false)?
1894+
}
1895+
}
1896+
}
18891897
SocketMessage::ToggleWindowBasedWorkAreaOffset => {
18901898
let workspace = self.focused_workspace_mut()?;
18911899
workspace.set_apply_window_based_work_area_offset(

komorebi/src/static_config.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,9 @@ pub struct WorkspaceConfig {
218218
/// Permanent workspace application rules
219219
#[serde(skip_serializing_if = "Option::is_none")]
220220
pub workspace_rules: Option<Vec<MatchingRule>>,
221+
/// Workspace specific work area offset (default: None)
222+
#[serde(skip_serializing_if = "Option::is_none")]
223+
pub work_area_offset: Option<Rect>,
221224
/// Apply this monitor's window-based work area offset (default: true)
222225
#[serde(skip_serializing_if = "Option::is_none")]
223226
pub apply_window_based_work_area_offset: Option<bool>,
@@ -310,6 +313,7 @@ impl From<&Workspace> for WorkspaceConfig {
310313
.workspace_config()
311314
.as_ref()
312315
.and_then(|c| c.workspace_rules.clone()),
316+
work_area_offset: value.work_area_offset(),
313317
apply_window_based_work_area_offset: Some(value.apply_window_based_work_area_offset()),
314318
window_container_behaviour: *value.window_container_behaviour(),
315319
window_container_behaviour_rules: Option::from(window_container_behaviour_rules),

komorebi/src/window_manager.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,7 @@ impl From<&WindowManager> for State {
337337
latest_layout: workspace.latest_layout.clone(),
338338
resize_dimensions: workspace.resize_dimensions.clone(),
339339
tile: workspace.tile,
340+
work_area_offset: workspace.work_area_offset,
340341
apply_window_based_work_area_offset: workspace
341342
.apply_window_based_work_area_offset,
342343
window_container_behaviour: workspace.window_container_behaviour,

komorebi/src/workspace.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,8 @@ pub struct Workspace {
8787
#[getset(get = "pub", set = "pub")]
8888
pub tile: bool,
8989
#[getset(get_copy = "pub", set = "pub")]
90+
pub work_area_offset: Option<Rect>,
91+
#[getset(get_copy = "pub", set = "pub")]
9092
pub apply_window_based_work_area_offset: bool,
9193
#[getset(get = "pub", get_mut = "pub", set = "pub")]
9294
pub window_container_behaviour: Option<WindowContainerBehaviour>,
@@ -147,6 +149,7 @@ impl Default for Workspace {
147149
latest_layout: vec![],
148150
resize_dimensions: vec![],
149151
tile: true,
152+
work_area_offset: None,
150153
apply_window_based_work_area_offset: true,
151154
window_container_behaviour: None,
152155
window_container_behaviour_rules: None,
@@ -241,6 +244,8 @@ impl Workspace {
241244
self.set_layout_rules(all_layout_rules);
242245
}
243246

247+
self.set_work_area_offset(config.work_area_offset);
248+
244249
self.set_apply_window_based_work_area_offset(
245250
config.apply_window_based_work_area_offset.unwrap_or(true),
246251
);
@@ -496,7 +501,7 @@ impl Workspace {
496501
let border_width = self.globals().border_width;
497502
let border_offset = self.globals().border_offset;
498503
let work_area = self.globals().work_area;
499-
let work_area_offset = self.globals().work_area_offset;
504+
let work_area_offset = self.work_area_offset().or(self.globals().work_area_offset);
500505
let window_based_work_area_offset = self.globals().window_based_work_area_offset;
501506
let window_based_work_area_offset_limit =
502507
self.globals().window_based_work_area_offset_limit;

komorebic.lib.ahk

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,10 @@ MonitorWorkAreaOffset(monitor, left, top, right, bottom) {
184184
RunWait("komorebic.exe monitor-work-area-offset " monitor " " left " " top " " right " " bottom, , "Hide")
185185
}
186186

187+
WorkspaceWorkAreaOffset(monitor, workspace, left, top, right, bottom) {
188+
RunWait("komorebic.exe workspace-work-area-offset " monitor " "workspace" " left " " top " " right " " bottom, , "Hide")
189+
}
190+
187191
AdjustContainerPadding(sizing, adjustment) {
188192
RunWait("komorebic.exe adjust-container-padding " sizing " " adjustment, , "Hide")
189193
}

komorebic/src/main.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,22 @@ struct MonitorWorkAreaOffset {
428428
bottom: i32,
429429
}
430430

431+
#[derive(Parser)]
432+
struct WorkspaceWorkAreaOffset {
433+
/// Monitor index (zero-indexed)
434+
monitor: usize,
435+
/// Workspace index (zero-indexed)
436+
workspace: usize,
437+
/// Size of the left work area offset (set right to left * 2 to maintain right padding)
438+
left: i32,
439+
/// Size of the top work area offset (set bottom to the same value to maintain bottom padding)
440+
top: i32,
441+
/// Size of the right work area offset
442+
right: i32,
443+
/// Size of the bottom work area offset
444+
bottom: i32,
445+
}
446+
431447
#[derive(Parser)]
432448
struct MonitorIndexPreference {
433449
/// Preferred monitor index (zero-indexed)
@@ -1188,6 +1204,9 @@ enum SubCommand {
11881204
/// Set offsets for a monitor to exclude parts of the work area from tiling
11891205
#[clap(arg_required_else_help = true)]
11901206
MonitorWorkAreaOffset(MonitorWorkAreaOffset),
1207+
/// Set offsets for a workspace to exclude parts of the work area from tiling
1208+
#[clap(arg_required_else_help = true)]
1209+
WorkspaceWorkAreaOffset(WorkspaceWorkAreaOffset),
11911210
/// Toggle application of the window-based work area offset for the focused workspace
11921211
ToggleWindowBasedWorkAreaOffset,
11931212
/// Set container padding on the focused workspace
@@ -1938,6 +1957,20 @@ fn main() -> Result<()> {
19381957
bottom: arg.bottom,
19391958
}))?;
19401959
}
1960+
1961+
SubCommand::WorkspaceWorkAreaOffset(arg) => {
1962+
send_message(&SocketMessage::WorkspaceWorkAreaOffset(
1963+
arg.monitor,
1964+
arg.workspace,
1965+
Rect {
1966+
left: arg.left,
1967+
top: arg.top,
1968+
right: arg.right,
1969+
bottom: arg.bottom,
1970+
},
1971+
))?;
1972+
}
1973+
19411974
SubCommand::ToggleWindowBasedWorkAreaOffset => {
19421975
send_message(&SocketMessage::ToggleWindowBasedWorkAreaOffset)?;
19431976
}

0 commit comments

Comments
 (0)