Skip to content

Commit

Permalink
feat(wm): single_window -> window_based offset
Browse files Browse the repository at this point in the history
This commit updates the initial design of single_window_work_area_offset
to window_based_work_area_offset where the user can set
window_based_work_area_offset_limit to determine the limit of windows on
the screen that this offset should apply to.

By default this is 1, and in the most extreme case of someone using a
super ultrawide monitor this might be 2.
  • Loading branch information
LGUG2Z committed May 14, 2024
1 parent ae7bb3a commit a85a196
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 26 deletions.
15 changes: 11 additions & 4 deletions komorebi/src/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub struct Monitor {
#[getset(get_copy = "pub", set = "pub")]
work_area_offset: Option<Rect>,
#[getset(get_copy = "pub", set = "pub")]
single_window_work_area_offset: Option<Rect>,
window_based_work_area_offset: Option<Rect>,
#[getset(get_copy = "pub", set = "pub")]
window_based_work_area_offset_limit: isize,
workspaces: Ring<Workspace>,
#[serde(skip_serializing_if = "Option::is_none")]
#[getset(get_copy = "pub", set = "pub")]
Expand All @@ -60,7 +62,8 @@ pub fn new(id: isize, size: Rect, work_area_size: Rect, name: String) -> Monitor
size,
work_area_size,
work_area_offset: None,
single_window_work_area_offset: None,
window_based_work_area_offset: None,
window_based_work_area_offset_limit: 1,
workspaces,
last_focused_workspace: None,
workspace_names: HashMap::default(),
Expand Down Expand Up @@ -197,7 +200,11 @@ impl Monitor {

pub fn update_focused_workspace(&mut self, offset: Option<Rect>) -> Result<()> {
let work_area = *self.work_area_size();
let single_window_work_area_offset = self.single_window_work_area_offset();
let window_based_work_area_offset = (
self.window_based_work_area_offset_limit(),
self.window_based_work_area_offset(),
);

let offset = if self.work_area_offset().is_some() {
self.work_area_offset()
} else {
Expand All @@ -206,7 +213,7 @@ impl Monitor {

self.focused_workspace_mut()
.ok_or_else(|| anyhow!("there is no workspace"))?
.update(&work_area, offset, single_window_work_area_offset)?;
.update(&work_area, offset, window_based_work_area_offset)?;

Ok(())
}
Expand Down
8 changes: 6 additions & 2 deletions komorebi/src/process_event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,11 @@ impl WindowManager {

for (i, monitor) in self.monitors_mut().iter_mut().enumerate() {
let work_area = *monitor.work_area_size();
let single_window_work_area_offset = monitor.single_window_work_area_offset();
let window_based_work_area_offset = (
monitor.window_based_work_area_offset_limit(),
monitor.window_based_work_area_offset(),
);

let offset = if monitor.work_area_offset().is_some() {
monitor.work_area_offset()
} else {
Expand All @@ -140,7 +144,7 @@ impl WindowManager {

let reaped_orphans = workspace.reap_orphans()?;
if reaped_orphans.0 > 0 || reaped_orphans.1 > 0 {
workspace.update(&work_area, offset, single_window_work_area_offset)?;
workspace.update(&work_area, offset, window_based_work_area_offset)?;
tracing::info!(
"reaped {} orphan window(s) and {} orphaned container(s) on monitor: {}, workspace: {}",
reaped_orphans.0,
Expand Down
20 changes: 15 additions & 5 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,9 +201,12 @@ pub struct MonitorConfig {
/// Monitor-specific work area offset (default: None)
#[serde(skip_serializing_if = "Option::is_none")]
pub work_area_offset: Option<Rect>,
/// Single window work area offset (default: None)
/// Window based work area offset (default: None)
#[serde(skip_serializing_if = "Option::is_none")]
pub single_window_work_area_offset: Option<Rect>,
pub window_based_work_area_offset: Option<Rect>,
/// Open window limit after which the window based work area offset will no longer be applied (default: 1)
#[serde(skip_serializing_if = "Option::is_none")]
pub window_based_work_area_offset_limit: Option<isize>,
}

impl From<&Monitor> for MonitorConfig {
Expand All @@ -216,7 +219,8 @@ impl From<&Monitor> for MonitorConfig {
Self {
workspaces,
work_area_offset: value.work_area_offset(),
single_window_work_area_offset: value.single_window_work_area_offset(),
window_based_work_area_offset: value.window_based_work_area_offset(),
window_based_work_area_offset_limit: Some(value.window_based_work_area_offset_limit()),
}
}
}
Expand Down Expand Up @@ -698,7 +702,10 @@ impl StaticConfig {
if let Some(m) = wm.monitors_mut().get_mut(i) {
m.ensure_workspace_count(monitor.workspaces.len());
m.set_work_area_offset(monitor.work_area_offset);
m.set_single_window_work_area_offset(monitor.single_window_work_area_offset);
m.set_window_based_work_area_offset(monitor.window_based_work_area_offset);
m.set_window_based_work_area_offset_limit(
monitor.window_based_work_area_offset_limit.unwrap_or(1),
);

for (j, ws) in m.workspaces_mut().iter_mut().enumerate() {
ws.load_static_config(
Expand Down Expand Up @@ -754,7 +761,10 @@ impl StaticConfig {
if let Some(m) = wm.monitors_mut().get_mut(i) {
m.ensure_workspace_count(monitor.workspaces.len());
m.set_work_area_offset(monitor.work_area_offset);
m.set_single_window_work_area_offset(monitor.single_window_work_area_offset);
m.set_window_based_work_area_offset(monitor.window_based_work_area_offset);
m.set_window_based_work_area_offset_limit(
monitor.window_based_work_area_offset_limit.unwrap_or(1),
);

for (j, ws) in m.workspaces_mut().iter_mut().enumerate() {
ws.load_static_config(
Expand Down
48 changes: 36 additions & 12 deletions komorebi/src/window_manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,11 @@ impl WindowManager {

for monitor in self.monitors_mut() {
let work_area = *monitor.work_area_size();
let single_window_work_area_offset = monitor.single_window_work_area_offset();
let window_based_work_area_offset = (
monitor.window_based_work_area_offset_limit(),
monitor.window_based_work_area_offset(),
);

let offset = if monitor.work_area_offset().is_some() {
monitor.work_area_offset()
} else {
Expand All @@ -731,7 +735,7 @@ impl WindowManager {
}
}

workspace.update(&work_area, offset, single_window_work_area_offset)?;
workspace.update(&work_area, offset, window_based_work_area_offset)?;
}

Ok(())
Expand Down Expand Up @@ -1949,7 +1953,11 @@ impl WindowManager {
.ok_or_else(|| anyhow!("there is no monitor"))?;

let work_area = *monitor.work_area_size();
let single_window_work_area_offset = monitor.single_window_work_area_offset();
let window_based_work_area_offset = (
monitor.window_based_work_area_offset_limit(),
monitor.window_based_work_area_offset(),
);

let focused_workspace_idx = monitor.focused_workspace_idx();
let offset = if monitor.work_area_offset().is_some() {
monitor.work_area_offset()
Expand All @@ -1969,7 +1977,7 @@ impl WindowManager {

// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update(&work_area, offset, single_window_work_area_offset)?;
workspace.update(&work_area, offset, window_based_work_area_offset)?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
Expand Down Expand Up @@ -1998,7 +2006,11 @@ impl WindowManager {
.ok_or_else(|| anyhow!("there is no monitor"))?;

let work_area = *monitor.work_area_size();
let single_window_work_area_offset = monitor.single_window_work_area_offset();
let window_based_work_area_offset = (
monitor.window_based_work_area_offset_limit(),
monitor.window_based_work_area_offset(),
);

let focused_workspace_idx = monitor.focused_workspace_idx();
let offset = if monitor.work_area_offset().is_some() {
monitor.work_area_offset()
Expand All @@ -2020,7 +2032,7 @@ impl WindowManager {

// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update(&work_area, offset, single_window_work_area_offset)?;
workspace.update(&work_area, offset, window_based_work_area_offset)?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
Expand All @@ -2044,7 +2056,11 @@ impl WindowManager {
.ok_or_else(|| anyhow!("there is no monitor"))?;

let work_area = *monitor.work_area_size();
let single_window_work_area_offset = monitor.single_window_work_area_offset();
let window_based_work_area_offset = (
monitor.window_based_work_area_offset_limit(),
monitor.window_based_work_area_offset(),
);

let focused_workspace_idx = monitor.focused_workspace_idx();
let offset = if monitor.work_area_offset().is_some() {
monitor.work_area_offset()
Expand All @@ -2062,7 +2078,7 @@ impl WindowManager {

// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update(&work_area, offset, single_window_work_area_offset)?;
workspace.update(&work_area, offset, window_based_work_area_offset)?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
Expand All @@ -2087,7 +2103,11 @@ impl WindowManager {
.ok_or_else(|| anyhow!("there is no monitor"))?;

let work_area = *monitor.work_area_size();
let single_window_work_area_offset = monitor.single_window_work_area_offset();
let window_based_work_area_offset = (
monitor.window_based_work_area_offset_limit(),
monitor.window_based_work_area_offset(),
);

let focused_workspace_idx = monitor.focused_workspace_idx();
let offset = if monitor.work_area_offset().is_some() {
monitor.work_area_offset()
Expand All @@ -2104,7 +2124,7 @@ impl WindowManager {

// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update(&work_area, offset, single_window_work_area_offset)?;
workspace.update(&work_area, offset, window_based_work_area_offset)?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
Expand Down Expand Up @@ -2132,7 +2152,11 @@ impl WindowManager {
.ok_or_else(|| anyhow!("there is no monitor"))?;

let work_area = *monitor.work_area_size();
let single_window_work_area_offset = monitor.single_window_work_area_offset();
let window_based_work_area_offset = (
monitor.window_based_work_area_offset_limit(),
monitor.window_based_work_area_offset(),
);

let focused_workspace_idx = monitor.focused_workspace_idx();
let offset = if monitor.work_area_offset().is_some() {
monitor.work_area_offset()
Expand All @@ -2150,7 +2174,7 @@ impl WindowManager {

// If this is the focused workspace on a non-focused screen, let's update it
if focused_monitor_idx != monitor_idx && focused_workspace_idx == workspace_idx {
workspace.update(&work_area, offset, single_window_work_area_offset)?;
workspace.update(&work_area, offset, window_based_work_area_offset)?;
Ok(())
} else {
Ok(self.update_focused_workspace(false, false)?)
Expand Down
9 changes: 6 additions & 3 deletions komorebi/src/workspace.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,15 @@ impl Workspace {
&mut self,
work_area: &Rect,
work_area_offset: Option<Rect>,
single_window_work_area_offset: Option<Rect>,
window_based_work_area_offset: (isize, Option<Rect>),
) -> Result<()> {
if !INITIAL_CONFIGURATION_LOADED.load(Ordering::SeqCst) {
return Ok(());
}

let (window_based_work_area_offset_limit, window_based_work_area_offset) =
window_based_work_area_offset;

let container_padding = self.container_padding();
let mut adjusted_work_area = work_area_offset.map_or_else(
|| *work_area,
Expand All @@ -243,8 +246,8 @@ impl Workspace {
},
);

if self.containers().len() == 1 {
adjusted_work_area = single_window_work_area_offset.map_or_else(
if self.containers().len() <= window_based_work_area_offset_limit as usize {
adjusted_work_area = window_based_work_area_offset.map_or_else(
|| adjusted_work_area,
|offset| {
let mut with_offset = adjusted_work_area;
Expand Down

0 comments on commit a85a196

Please sign in to comment.