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.
This commit is contained in:
omark96
2025-06-06 23:42:12 +02:00
committed by LGUG2Z
parent db96f2cc5a
commit 59c3c14731
9 changed files with 656 additions and 1 deletions

View File

@@ -202,6 +202,7 @@ pub enum SocketMessage {
StackbarFontFamily(Option<String>),
WorkAreaOffset(Rect),
MonitorWorkAreaOffset(usize, Rect),
WorkspaceWorkAreaOffset(usize, usize, Rect),
ToggleWindowBasedWorkAreaOffset,
ResizeDelta(i32),
InitialWorkspaceRule(ApplicationIdentifier, String, usize, usize),

View File

@@ -1886,6 +1886,14 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
self.retile_all(false)?;
}
}
SocketMessage::WorkspaceWorkAreaOffset(monitor_idx, workspace_idx, rect) => {
if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx) {
if let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx) {
workspace.set_work_area_offset(Option::from(rect));
self.retile_all(false)?
}
}
}
SocketMessage::ToggleWindowBasedWorkAreaOffset => {
let workspace = self.focused_workspace_mut()?;
workspace.set_apply_window_based_work_area_offset(

View File

@@ -218,6 +218,9 @@ pub struct WorkspaceConfig {
/// Permanent workspace application rules
#[serde(skip_serializing_if = "Option::is_none")]
pub workspace_rules: Option<Vec<MatchingRule>>,
/// Workspace specific work area offset (default: None)
#[serde(skip_serializing_if = "Option::is_none")]
pub work_area_offset: Option<Rect>,
/// Apply this monitor's window-based work area offset (default: true)
#[serde(skip_serializing_if = "Option::is_none")]
pub apply_window_based_work_area_offset: Option<bool>,
@@ -310,6 +313,7 @@ impl From<&Workspace> for WorkspaceConfig {
.workspace_config()
.as_ref()
.and_then(|c| c.workspace_rules.clone()),
work_area_offset: value.work_area_offset(),
apply_window_based_work_area_offset: Some(value.apply_window_based_work_area_offset()),
window_container_behaviour: *value.window_container_behaviour(),
window_container_behaviour_rules: Option::from(window_container_behaviour_rules),

View File

@@ -337,6 +337,7 @@ impl From<&WindowManager> for State {
latest_layout: workspace.latest_layout.clone(),
resize_dimensions: workspace.resize_dimensions.clone(),
tile: workspace.tile,
work_area_offset: workspace.work_area_offset,
apply_window_based_work_area_offset: workspace
.apply_window_based_work_area_offset,
window_container_behaviour: workspace.window_container_behaviour,

View File

@@ -87,6 +87,8 @@ pub struct Workspace {
#[getset(get = "pub", set = "pub")]
pub tile: bool,
#[getset(get_copy = "pub", set = "pub")]
pub work_area_offset: Option<Rect>,
#[getset(get_copy = "pub", set = "pub")]
pub apply_window_based_work_area_offset: bool,
#[getset(get = "pub", get_mut = "pub", set = "pub")]
pub window_container_behaviour: Option<WindowContainerBehaviour>,
@@ -147,6 +149,7 @@ impl Default for Workspace {
latest_layout: vec![],
resize_dimensions: vec![],
tile: true,
work_area_offset: None,
apply_window_based_work_area_offset: true,
window_container_behaviour: None,
window_container_behaviour_rules: None,
@@ -241,6 +244,8 @@ impl Workspace {
self.set_layout_rules(all_layout_rules);
}
self.set_work_area_offset(config.work_area_offset);
self.set_apply_window_based_work_area_offset(
config.apply_window_based_work_area_offset.unwrap_or(true),
);
@@ -496,7 +501,7 @@ impl Workspace {
let border_width = self.globals().border_width;
let border_offset = self.globals().border_offset;
let work_area = self.globals().work_area;
let work_area_offset = self.globals().work_area_offset;
let work_area_offset = self.work_area_offset().or(self.globals().work_area_offset);
let window_based_work_area_offset = self.globals().window_based_work_area_offset;
let window_based_work_area_offset_limit =
self.globals().window_based_work_area_offset_limit;

View File

@@ -184,6 +184,10 @@ MonitorWorkAreaOffset(monitor, left, top, right, bottom) {
RunWait("komorebic.exe monitor-work-area-offset " monitor " " left " " top " " right " " bottom, , "Hide")
}
WorkspaceWorkAreaOffset(monitor, workspace, left, top, right, bottom) {
RunWait("komorebic.exe workspace-work-area-offset " monitor " "workspace" " left " " top " " right " " bottom, , "Hide")
}
AdjustContainerPadding(sizing, adjustment) {
RunWait("komorebic.exe adjust-container-padding " sizing " " adjustment, , "Hide")
}

View File

@@ -428,6 +428,22 @@ struct MonitorWorkAreaOffset {
bottom: i32,
}
#[derive(Parser)]
struct WorkspaceWorkAreaOffset {
/// Monitor index (zero-indexed)
monitor: usize,
/// Workspace index (zero-indexed)
workspace: usize,
/// Size of the left work area offset (set right to left * 2 to maintain right padding)
left: i32,
/// Size of the top work area offset (set bottom to the same value to maintain bottom padding)
top: i32,
/// Size of the right work area offset
right: i32,
/// Size of the bottom work area offset
bottom: i32,
}
#[derive(Parser)]
struct MonitorIndexPreference {
/// Preferred monitor index (zero-indexed)
@@ -1188,6 +1204,9 @@ enum SubCommand {
/// Set offsets for a monitor to exclude parts of the work area from tiling
#[clap(arg_required_else_help = true)]
MonitorWorkAreaOffset(MonitorWorkAreaOffset),
/// Set offsets for a workspace to exclude parts of the work area from tiling
#[clap(arg_required_else_help = true)]
WorkspaceWorkAreaOffset(WorkspaceWorkAreaOffset),
/// Toggle application of the window-based work area offset for the focused workspace
ToggleWindowBasedWorkAreaOffset,
/// Set container padding on the focused workspace
@@ -1938,6 +1957,20 @@ fn main() -> Result<()> {
bottom: arg.bottom,
}))?;
}
SubCommand::WorkspaceWorkAreaOffset(arg) => {
send_message(&SocketMessage::WorkspaceWorkAreaOffset(
arg.monitor,
arg.workspace,
Rect {
left: arg.left,
top: arg.top,
right: arg.right,
bottom: arg.bottom,
},
))?;
}
SubCommand::ToggleWindowBasedWorkAreaOffset => {
send_message(&SocketMessage::ToggleWindowBasedWorkAreaOffset)?;
}

View File

@@ -8217,6 +8217,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -14295,6 +14358,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -20373,6 +20499,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -26451,6 +26640,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -32529,6 +32781,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -38607,6 +38922,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -44685,6 +45063,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -50763,6 +51204,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [
@@ -56841,6 +57345,69 @@
}
}
},
{
"type": "object",
"required": [
"content",
"type"
],
"properties": {
"content": {
"type": "array",
"items": [
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "integer",
"format": "uint",
"minimum": 0.0
},
{
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
}
],
"maxItems": 3,
"minItems": 3
},
"type": {
"type": "string",
"enum": [
"WorkspaceWorkAreaOffset"
]
}
}
},
{
"type": "object",
"required": [

View File

@@ -2138,6 +2138,38 @@
]
}
},
"work_area_offset": {
"description": "Workspace specific work area offset (default: None)",
"type": "object",
"required": [
"bottom",
"left",
"right",
"top"
],
"properties": {
"bottom": {
"description": "The bottom point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"left": {
"description": "The left point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"right": {
"description": "The right point in a Win32 Rect",
"type": "integer",
"format": "int32"
},
"top": {
"description": "The top point in a Win32 Rect",
"type": "integer",
"format": "int32"
}
}
},
"workspace_padding": {
"description": "Workspace padding (default: global)",
"type": "integer",