Skip to content

Commit

Permalink
fix(config): align border opts in st/dyn configs
Browse files Browse the repository at this point in the history
This commit aligns the border option naming and arguments between the
dynamic and static configuration approaches.

The previously named border_width and border_offset options in the
static config will be replaced by active_window_border_width and
active_window_border_offset in v0.1.19.

Similarly the option for the offset will now take a single signed
integer, as it does when using the komorebic command.

re #526
  • Loading branch information
LGUG2Z committed Sep 21, 2023
1 parent 4591274 commit 57cc02f
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 22 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[workspace]

resolver = "2"
members = [
"derive-ahk",
"komorebi",
Expand Down
4 changes: 2 additions & 2 deletions komorebi/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ pub fn current_virtual_desktop() -> Option<Vec<u8>> {
// This is the path on Windows 11
if current.is_none() {
current = hkcu
.open_subkey(r#"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops"#)
.open_subkey(r"SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\VirtualDesktops")
.ok()
.and_then(
|desktops| match desktops.get_raw_value("CurrentVirtualDesktop") {
Expand Down Expand Up @@ -357,7 +357,7 @@ pub struct Notification {
pub fn notify_subscribers(notification: &str) -> Result<()> {
let mut stale_subscriptions = vec![];
let mut subscriptions = SUBSCRIPTION_PIPES.lock();
for (subscriber, pipe) in subscriptions.iter_mut() {
for (subscriber, pipe) in &mut *subscriptions {
match writeln!(pipe, "{notification}") {
Ok(_) => {
tracing::debug!("pushed notification to subscriber: {}", subscriber);
Expand Down
3 changes: 1 addition & 2 deletions komorebi/src/process_command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,8 @@ impl WindowManager {
.focused_workspace()
.ok_or_else(|| anyhow!("there is no workspace"))?
.containers()
.iter()
{
for window in container.windows().iter() {
for window in container.windows() {
match identifier {
ApplicationIdentifier::Exe => {
if window.exe()? == *id {
Expand Down
49 changes: 38 additions & 11 deletions komorebi/src/static_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,18 @@ 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)
/// DEPRECATED from v0.1.19: use active_window_border_width instead
#[serde(skip_serializing_if = "Option::is_none")]
pub border_width: Option<i32>,
/// Offset of the active window border (default: None)
/// DEPRECATED from v0.1.19: use active_window_border_offset instead
#[serde(skip_serializing_if = "Option::is_none")]
pub border_offset: Option<Rect>,
/// Width of the active window border (default: 20)
#[serde(skip_serializing_if = "Option::is_none")]
pub active_window_border_width: Option<i32>,
/// Offset of the active window border (default: None)
#[serde(skip_serializing_if = "Option::is_none")]
pub active_window_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 Down Expand Up @@ -396,8 +402,12 @@ 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,
border_width: Option::from(BORDER_WIDTH.load(Ordering::SeqCst)),
border_offset: *BORDER_OFFSET.lock(),
active_window_border_width: Option::from(BORDER_WIDTH.load(Ordering::SeqCst)),
active_window_border_offset: BORDER_OFFSET
.lock()
.map_or(None, |offset| Option::from(offset.left)),
border_width: None,
border_offset: None,
active_window_border: Option::from(BORDER_ENABLED.load(Ordering::SeqCst)),
active_window_border_colours: border_colours,
default_workspace_padding: Option::from(
Expand Down Expand Up @@ -446,14 +456,31 @@ impl StaticConfig {
DEFAULT_WORKSPACE_PADDING.store(workspace, Ordering::SeqCst);
}

if let Some(width) = self.border_width {
BORDER_WIDTH.store(width, Ordering::SeqCst);
}
self.active_window_border_width.map_or_else(
|| {
BORDER_WIDTH.store(20, Ordering::SeqCst);
},
|width| {
BORDER_WIDTH.store(width, Ordering::SeqCst);
},
);
self.active_window_border_offset.map_or_else(
|| {
let mut border_offset = BORDER_OFFSET.lock();
*border_offset = None;
},
|offset| {
let new_border_offset = Rect {
left: offset,
top: offset,
right: offset * 2,
bottom: offset * 2,
};

if let Some(offset) = self.border_offset {
let mut border_offset = BORDER_OFFSET.lock();
*border_offset = Some(offset);
}
let mut border_offset = BORDER_OFFSET.lock();
*border_offset = Some(new_border_offset);
},
);

if let Some(colours) = &self.active_window_border_colours {
BORDER_COLOUR_SINGLE.store(
Expand Down
9 changes: 3 additions & 6 deletions komorebi/src/windows_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ impl WindowsApi {
}

pub fn enum_windows(callback: WNDENUMPROC, callback_data_address: isize) -> Result<()> {
unsafe { EnumWindows(callback, LPARAM(callback_data_address)) }
.process()
unsafe { EnumWindows(callback, LPARAM(callback_data_address)) }.process()
}

pub fn load_workspace_information(monitors: &mut Ring<Monitor>) -> Result<()> {
Expand Down Expand Up @@ -274,8 +273,7 @@ impl WindowsApi {
}

pub fn allow_set_foreground_window(process_id: u32) -> Result<()> {
unsafe { AllowSetForegroundWindow(process_id) }
.process()
unsafe { AllowSetForegroundWindow(process_id) }.process()
}

pub fn monitor_from_window(hwnd: HWND) -> isize {
Expand Down Expand Up @@ -365,8 +363,7 @@ impl WindowsApi {
}

fn post_message(hwnd: HWND, message: u32, wparam: WPARAM, lparam: LPARAM) -> Result<()> {
unsafe { PostMessageW(hwnd, message, wparam, lparam) }
.process()
unsafe { PostMessageW(hwnd, message, wparam, lparam) }.process()
}

pub fn close_window(hwnd: HWND) -> Result<()> {
Expand Down
2 changes: 1 addition & 1 deletion komorebic/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,7 @@ fn main() -> Result<()> {
"'--config=\"{}\"'",
path.as_os_str()
.to_string_lossy()
.trim_start_matches(r#"\\?\"#),
.trim_start_matches(r"\\?\"),
));
}

Expand Down

0 comments on commit 57cc02f

Please sign in to comment.