Skip to content

Commit

Permalink
feat(config): update border opts, add deprecations
Browse files Browse the repository at this point in the history
This commit includes backwards-compatible renames of
active_window_border_offset and active_window_border_width to
border_offset and border_width respectively.

Since the invisible window border adjustments were removed in #678, the
invisible window borders set by the OS can now also be adjusted via
border_offset and border_width, which is the primary reason for the
rename.

invisible_borders has been marked as deprecated and the previously
deprecated alt_focus_hack option has been removed.
  • Loading branch information
LGUG2Z committed Feb 26, 2024
1 parent 94d8f72 commit e0e3afa
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 55 deletions.
6 changes: 1 addition & 5 deletions komorebi/src/border.rs
Expand Up @@ -86,11 +86,7 @@ impl Border {
}
}

pub fn set_position(
self,
window: Window,
activate: bool,
) -> Result<()> {
pub fn set_position(self, window: Window, activate: bool) -> Result<()> {
if self.hwnd == 0 {
Ok(())
} else {
Expand Down
1 change: 0 additions & 1 deletion komorebi/src/lib.rs
Expand Up @@ -205,7 +205,6 @@ pub static DEFAULT_CONTAINER_PADDING: AtomicI32 = AtomicI32::new(10);
pub static INITIAL_CONFIGURATION_LOADED: AtomicBool = AtomicBool::new(false);
pub static CUSTOM_FFM: AtomicBool = AtomicBool::new(false);
pub static SESSION_ID: AtomicU32 = AtomicU32::new(0);
pub static ALT_FOCUS_HACK: AtomicBool = AtomicBool::new(false);
pub static BORDER_ENABLED: AtomicBool = AtomicBool::new(false);
pub static BORDER_HWND: AtomicIsize = AtomicIsize::new(0);
pub static BORDER_HIDDEN: AtomicBool = AtomicBool::new(false);
Expand Down
5 changes: 1 addition & 4 deletions komorebi/src/monitor.rs
Expand Up @@ -192,10 +192,7 @@ impl Monitor {
self.workspaces().len()
}

pub fn update_focused_workspace(
&mut self,
offset: Option<Rect>,
) -> Result<()> {
pub fn update_focused_workspace(&mut self, offset: Option<Rect>) -> Result<()> {
let work_area = *self.work_area_size();
let offset = if self.work_area_offset().is_some() {
self.work_area_offset()
Expand Down
5 changes: 2 additions & 3 deletions komorebi/src/process_command.rs
Expand Up @@ -48,7 +48,6 @@ use crate::window_manager::WindowManager;
use crate::windows_api::WindowsApi;
use crate::Notification;
use crate::NotificationEvent;
use crate::ALT_FOCUS_HACK;
use crate::BORDER_COLOUR_CURRENT;
use crate::BORDER_COLOUR_MONOCLE;
use crate::BORDER_COLOUR_SINGLE;
Expand Down Expand Up @@ -1252,8 +1251,8 @@ impl WindowManager {
BORDER_OFFSET.store(offset, Ordering::SeqCst);
WindowsApi::invalidate_border_rect()?;
}
SocketMessage::AltFocusHack(enable) => {
ALT_FOCUS_HACK.store(enable, Ordering::SeqCst);
SocketMessage::AltFocusHack(_) => {
tracing::info!("this action is deprecated");
}
SocketMessage::ApplicationSpecificConfigurationSchema => {
let asc = schema_for!(Vec<ApplicationConfiguration>);
Expand Down
3 changes: 1 addition & 2 deletions komorebi/src/process_event.rs
Expand Up @@ -376,8 +376,7 @@ impl WindowManager {

// If we have moved across the monitors, use that override, otherwise determine
// if a move has taken place by ruling out a resize
let is_move = moved_across_monitors
|| resize.right == 0 && resize.bottom == 0;
let is_move = moved_across_monitors || resize.right == 0 && resize.bottom == 0;

if is_move {
tracing::info!("moving with mouse");
Expand Down
31 changes: 17 additions & 14 deletions komorebi/src/static_config.rs
Expand Up @@ -214,7 +214,7 @@ impl From<&Monitor> for MonitorConfig {
#[derive(Debug, Serialize, Deserialize, JsonSchema)]
/// The `komorebi.json` static configuration file reference for `v0.1.20`
pub struct StaticConfig {
/// Dimensions of Windows' own invisible borders; don't set these yourself unless you are told to
/// DEPRECATED from v0.1.22: no longer required
#[serde(skip_serializing_if = "Option::is_none")]
pub invisible_borders: Option<Rect>,
/// Delta to resize windows by (default 50)
Expand All @@ -238,12 +238,14 @@ pub struct StaticConfig {
/// Path to applications.yaml from komorebi-application-specific-configurations (default: None)
#[serde(skip_serializing_if = "Option::is_none")]
pub app_specific_configuration_path: Option<PathBuf>,
/// Width of the active window border (default: 20)
/// Width of the window border (default: 8)
#[serde(skip_serializing_if = "Option::is_none")]
pub active_window_border_width: Option<i32>,
/// Offset of the active window border (default: None)
#[serde(alias = "active_window_border_width")]
pub border_width: Option<i32>,
/// Offset of the window border (default: -1)
#[serde(skip_serializing_if = "Option::is_none")]
pub active_window_border_offset: Option<i32>,
#[serde(alias = "active_window_border_offset")]
pub border_offset: Option<i32>,
/// Display an active window border (default: false)
#[serde(skip_serializing_if = "Option::is_none")]
pub active_window_border: Option<bool>,
Expand All @@ -259,10 +261,6 @@ pub struct StaticConfig {
/// Monitor and workspace configurations
#[serde(skip_serializing_if = "Option::is_none")]
pub monitors: Option<Vec<MonitorConfig>>,
/// DEPRECATED from v0.1.20: no longer required
#[schemars(skip)]
#[serde(skip_serializing)]
pub alt_focus_hack: Option<bool>,
/// Which Windows signal to use when hiding windows (default: minimize)
#[serde(skip_serializing_if = "Option::is_none")]
pub window_hiding_behaviour: Option<HidingBehaviour>,
Expand Down Expand Up @@ -377,8 +375,8 @@ impl From<&WindowManager> for StaticConfig {
focus_follows_mouse: value.focus_follows_mouse,
mouse_follows_focus: Option::from(value.mouse_follows_focus),
app_specific_configuration_path: None,
active_window_border_width: Option::from(BORDER_WIDTH.load(Ordering::SeqCst)),
active_window_border_offset: Option::from(BORDER_OFFSET.load(Ordering::SeqCst)),
border_width: Option::from(BORDER_WIDTH.load(Ordering::SeqCst)),
border_offset: Option::from(BORDER_OFFSET.load(Ordering::SeqCst)),
active_window_border: Option::from(BORDER_ENABLED.load(Ordering::SeqCst)),
active_window_border_colours: border_colours,
default_workspace_padding: Option::from(
Expand All @@ -388,7 +386,6 @@ impl From<&WindowManager> for StaticConfig {
DEFAULT_CONTAINER_PADDING.load(Ordering::SeqCst),
),
monitors: Option::from(monitors),
alt_focus_hack: None,
window_hiding_behaviour: Option::from(*HIDING_BEHAVIOUR.lock()),
global_work_area_offset: value.work_area_offset,
float_rules: None,
Expand Down Expand Up @@ -429,7 +426,7 @@ impl StaticConfig {
DEFAULT_WORKSPACE_PADDING.store(workspace, Ordering::SeqCst);
}

self.active_window_border_width.map_or_else(
self.border_width.map_or_else(
|| {
BORDER_WIDTH.store(8, Ordering::SeqCst);
},
Expand All @@ -438,7 +435,7 @@ impl StaticConfig {
},
);

BORDER_OFFSET.store(self.active_window_border_offset.unwrap_or(-1), Ordering::SeqCst);
BORDER_OFFSET.store(self.border_offset.unwrap_or(-1), Ordering::SeqCst);

if let Some(colours) = &self.active_window_border_colours {
BORDER_COLOUR_SINGLE.store(u32::from(colours.single), Ordering::SeqCst);
Expand Down Expand Up @@ -895,6 +892,12 @@ impl StaticConfig {

wm.focus_follows_mouse = value.focus_follows_mouse;

let monitor_count = wm.monitors().len();

for i in 0..monitor_count {
wm.update_focused_workspace_by_monitor_idx(i)?;
}

Ok(())
}
}
20 changes: 1 addition & 19 deletions komorebi/src/window.rs
Expand Up @@ -4,7 +4,6 @@ use std::convert::TryFrom;
use std::fmt::Display;
use std::fmt::Formatter;
use std::fmt::Write as _;
use std::sync::atomic::Ordering;

use color_eyre::eyre;
use color_eyre::eyre::anyhow;
Expand All @@ -19,9 +18,6 @@ use serde::Deserialize;
use serde::Serialize;
use serde::Serializer;
use windows::Win32::Foundation::HWND;
use winput::press;
use winput::release;
use winput::Vk;

use komorebi_core::ApplicationIdentifier;
use komorebi_core::HidingBehaviour;
Expand All @@ -31,7 +27,6 @@ use crate::styles::ExtendedWindowStyle;
use crate::styles::WindowStyle;
use crate::window_manager_event::WindowManagerEvent;
use crate::windows_api::WindowsApi;
use crate::ALT_FOCUS_HACK;
use crate::FLOAT_IDENTIFIERS;
use crate::HIDDEN_HWNDS;
use crate::HIDING_BEHAVIOUR;
Expand Down Expand Up @@ -143,11 +138,7 @@ impl Window {
)
}

pub fn set_position(
&mut self,
layout: &Rect,
top: bool,
) -> Result<()> {
pub fn set_position(&mut self, layout: &Rect, top: bool) -> Result<()> {
let rect = *layout;
WindowsApi::position_window(self.hwnd(), &rect, top)
}
Expand Down Expand Up @@ -298,12 +289,7 @@ impl Window {
let mut tried_resetting_foreground_access = false;
let mut max_attempts = 10;

let hotkey_uses_alt = WindowsApi::alt_is_pressed();
while !foregrounded && max_attempts > 0 {
if ALT_FOCUS_HACK.load(Ordering::SeqCst) {
press(Vk::Alt);
}

match WindowsApi::set_foreground_window(self.hwnd()) {
Ok(()) => {
foregrounded = true;
Expand All @@ -324,10 +310,6 @@ impl Window {
}
}
};

if ALT_FOCUS_HACK.load(Ordering::SeqCst) && !hotkey_uses_alt {
release(Vk::Alt);
}
}

// Center cursor in Window
Expand Down
2 changes: 1 addition & 1 deletion komorebi/src/windows_api.rs
Expand Up @@ -352,7 +352,7 @@ impl WindowsApi {
| SetWindowPosition::FRAME_CHANGED;

let shadow_rect = Self::shadow_rect(hwnd)?;
let rect = Rect{
let rect = Rect {
left: layout.left + shadow_rect.left,
top: layout.top + shadow_rect.top,
right: layout.right + shadow_rect.right,
Expand Down
6 changes: 1 addition & 5 deletions komorebi/src/workspace.rs
Expand Up @@ -203,11 +203,7 @@ impl Workspace {
Ok(())
}

pub fn update(
&mut self,
work_area: &Rect,
offset: Option<Rect>,
) -> Result<()> {
pub fn update(&mut self, work_area: &Rect, offset: Option<Rect>) -> Result<()> {
if !INITIAL_CONFIGURATION_LOADED.load(Ordering::SeqCst) {
return Ok(());
}
Expand Down
3 changes: 2 additions & 1 deletion komorebic/src/main.rs
Expand Up @@ -1077,8 +1077,9 @@ enum SubCommand {
WatchConfiguration(WatchConfiguration),
/// Signal that the final configuration option has been sent
CompleteConfiguration,
/// Enable or disable a hack simulating ALT key presses to ensure focus changes succeed
/// DEPRECATED since v0.1.22
#[clap(arg_required_else_help = true)]
#[clap(hide = true)]
AltFocusHack(AltFocusHack),
/// Set the window behaviour when switching workspaces / cycling stacks
#[clap(arg_required_else_help = true)]
Expand Down

0 comments on commit e0e3afa

Please sign in to comment.