refactor(rust): upgrade to edition 2024 part 2 (clippy --fix)

This commit is contained in:
LGUG2Z
2025-09-24 11:12:29 -07:00
parent 80877cc449
commit 52a745d0a3
28 changed files with 929 additions and 1022 deletions
+2 -4
View File
@@ -322,8 +322,8 @@ pub fn apply_theme(
// apply rounding to the widgets // apply rounding to the widgets
if let Some(Grouping::Bar(config) | Grouping::Alignment(config) | Grouping::Widget(config)) = if let Some(Grouping::Bar(config) | Grouping::Alignment(config) | Grouping::Widget(config)) =
&grouping &grouping
&& let Some(rounding) = config.rounding
{ {
if let Some(rounding) = config.rounding {
ctx.style_mut(|style| { ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.corner_radius = rounding.into(); style.visuals.widgets.noninteractive.corner_radius = rounding.into();
style.visuals.widgets.inactive.corner_radius = rounding.into(); style.visuals.widgets.inactive.corner_radius = rounding.into();
@@ -332,7 +332,6 @@ pub fn apply_theme(
style.visuals.widgets.open.corner_radius = rounding.into(); style.visuals.widgets.open.corner_radius = rounding.into();
}); });
} }
}
// Update RenderConfig's background_color so that widgets will have the new color // Update RenderConfig's background_color so that widgets will have the new color
render_config.borrow_mut().background_color = *bg_color.borrow(); render_config.borrow_mut().background_color = *bg_color.borrow();
@@ -672,8 +671,8 @@ impl Komobar {
| Grouping::Alignment(config) | Grouping::Alignment(config)
| Grouping::Widget(config), | Grouping::Widget(config),
) = &bar_grouping ) = &bar_grouping
&& let Some(rounding) = config.rounding
{ {
if let Some(rounding) = config.rounding {
ctx.style_mut(|style| { ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.corner_radius = style.visuals.widgets.noninteractive.corner_radius =
rounding.into(); rounding.into();
@@ -688,7 +687,6 @@ impl Komobar {
} }
} }
} }
}
pub fn new( pub fn new(
cc: &eframe::CreationContext<'_>, cc: &eframe::CreationContext<'_>,
+4 -6
View File
@@ -87,8 +87,9 @@ impl Battery {
if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) { if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) {
output = None; output = None;
if let Ok(mut batteries) = self.manager.batteries() { if let Ok(mut batteries) = self.manager.batteries()
if let Some(Ok(first)) = batteries.nth(0) { && let Some(Ok(first)) = batteries.nth(0)
{
let percentage = first.state_of_charge().get::<percent>().round() as u8; let percentage = first.state_of_charge().get::<percent>().round() as u8;
if percentage == 100 && self.hide_on_full_charge { if percentage == 100 && self.hide_on_full_charge {
@@ -123,7 +124,6 @@ impl Battery {
}) })
} }
} }
}
self.last_state.clone_from(&output); self.last_state.clone_from(&output);
self.last_updated = now; self.last_updated = now;
@@ -176,14 +176,12 @@ impl BarWidget for Battery {
if SelectableFrame::new_auto(output.selected, auto_focus_fill) if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked() .clicked()
{ && let Err(error) = Command::new("cmd.exe")
if let Err(error) = Command::new("cmd.exe")
.args(["/C", "start", "ms-settings:batterysaver"]) .args(["/C", "start", "ms-settings:batterysaver"])
.spawn() .spawn()
{ {
eprintln!("{error}") eprintln!("{error}")
} }
}
}); });
} }
} }
+1 -3
View File
@@ -120,13 +120,11 @@ impl BarWidget for Cpu {
if SelectableFrame::new_auto(output.selected, auto_focus_fill) if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked() .clicked()
{ && let Err(error) =
if let Err(error) =
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn() Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{ {
eprintln!("{error}") eprintln!("{error}")
} }
}
}); });
} }
} }
+4 -6
View File
@@ -271,8 +271,9 @@ impl Komorebi {
} }
fn render_layout(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) { fn render_layout(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) {
if let Some(layout_config) = &self.layout { if let Some(layout_config) = &self.layout
if layout_config.enable { && layout_config.enable
{
let monitor_info = &mut *self.monitor_info.borrow_mut(); let monitor_info = &mut *self.monitor_info.borrow_mut();
let workspace_idx = monitor_info.focused_workspace_idx; let workspace_idx = monitor_info.focused_workspace_idx;
monitor_info monitor_info
@@ -280,7 +281,6 @@ impl Komorebi {
.show(ctx, ui, config, layout_config, workspace_idx); .show(ctx, ui, config, layout_config, workspace_idx);
} }
} }
}
/// Renders the locked container bar for the current monitor. /// Renders the locked container bar for the current monitor.
/// ///
@@ -558,12 +558,10 @@ impl FocusedContainerBar {
ui.add(img.fit_to_exact_size(self.icon_size)); ui.add(img.fit_to_exact_size(self.icon_size));
} }
}); });
if HOVEL { if HOVEL && let Some(title) = &info.title {
if let Some(title) = &info.title {
inner_response.response.on_hover_text(title); inner_response.response.on_hover_text(title);
} }
} }
}
/// Renders the window title label in color, truncating if needed. /// Renders the window title label in color, truncating if needed.
fn show_title(&self, ui: &mut Ui, info: &WindowInfo, color: Color32) { fn show_title(&self, ui: &mut Ui, info: &WindowInfo, color: Color32) {
+4 -9
View File
@@ -91,8 +91,8 @@ impl KomorebiLayout {
fn on_click_option(&mut self, monitor_idx: usize, workspace_idx: Option<usize>) { fn on_click_option(&mut self, monitor_idx: usize, workspace_idx: Option<usize>) {
match self { match self {
KomorebiLayout::Default(option) => { KomorebiLayout::Default(option) => {
if let Some(ws_idx) = workspace_idx { if let Some(ws_idx) = workspace_idx
if komorebi_client::send_message(&SocketMessage::WorkspaceLayout( && komorebi_client::send_message(&SocketMessage::WorkspaceLayout(
monitor_idx, monitor_idx,
ws_idx, ws_idx,
*option, *option,
@@ -102,7 +102,6 @@ impl KomorebiLayout {
tracing::error!("could not send message to komorebi: WorkspaceLayout"); tracing::error!("could not send message to komorebi: WorkspaceLayout");
} }
} }
}
KomorebiLayout::Monocle => { KomorebiLayout::Monocle => {
if komorebi_client::send_batch([ if komorebi_client::send_batch([
SocketMessage::FocusMonitorAtCursor, SocketMessage::FocusMonitorAtCursor,
@@ -269,8 +268,7 @@ impl KomorebiLayout {
show_options = self.on_click(&show_options, monitor_idx, workspace_idx); show_options = self.on_click(&show_options, monitor_idx, workspace_idx);
} }
if show_options { if show_options && let Some(workspace_idx) = workspace_idx {
if let Some(workspace_idx) = workspace_idx {
Frame::NONE.show(ui, |ui| { Frame::NONE.show(ui, |ui| {
ui.add( ui.add(
Label::new(egui_phosphor::regular::ARROW_FAT_LINES_RIGHT.to_string()) Label::new(egui_phosphor::regular::ARROW_FAT_LINES_RIGHT.to_string())
@@ -285,9 +283,7 @@ impl KomorebiLayout {
KomorebiLayout::Default( KomorebiLayout::Default(
komorebi_client::DefaultLayout::RightMainVerticalStack, komorebi_client::DefaultLayout::RightMainVerticalStack,
), ),
KomorebiLayout::Default( KomorebiLayout::Default(komorebi_client::DefaultLayout::HorizontalStack),
komorebi_client::DefaultLayout::HorizontalStack,
),
KomorebiLayout::Default( KomorebiLayout::Default(
komorebi_client::DefaultLayout::UltrawideVerticalStack, komorebi_client::DefaultLayout::UltrawideVerticalStack,
), ),
@@ -320,7 +316,6 @@ impl KomorebiLayout {
} }
}); });
} }
}
}); });
RenderConfig::store_show_komorebi_layout_options(show_options); RenderConfig::store_show_komorebi_layout_options(show_options);
+8 -10
View File
@@ -46,18 +46,19 @@ impl Media {
} }
pub fn toggle(&self) { pub fn toggle(&self) {
if let Ok(session) = self.session_manager.GetCurrentSession() { if let Ok(session) = self.session_manager.GetCurrentSession()
if let Ok(op) = session.TryTogglePlayPauseAsync() { && let Ok(op) = session.TryTogglePlayPauseAsync()
{
op.get().unwrap_or_default(); op.get().unwrap_or_default();
} }
} }
}
fn output(&mut self) -> String { fn output(&mut self) -> String {
if let Ok(session) = self.session_manager.GetCurrentSession() { if let Ok(session) = self.session_manager.GetCurrentSession()
if let Ok(operation) = session.TryGetMediaPropertiesAsync() { && let Ok(operation) = session.TryGetMediaPropertiesAsync()
if let Ok(properties) = operation.get() { && let Ok(properties) = operation.get()
if let (Ok(artist), Ok(title)) = (properties.Artist(), properties.Title()) { && let (Ok(artist), Ok(title)) = (properties.Artist(), properties.Title())
{
if artist.is_empty() { if artist.is_empty() {
return format!("{title}"); return format!("{title}");
} }
@@ -68,9 +69,6 @@ impl Media {
return format!("{artist} - {title}"); return format!("{artist} - {title}");
} }
}
}
}
String::new() String::new()
} }
+1 -3
View File
@@ -124,13 +124,11 @@ impl BarWidget for Memory {
if SelectableFrame::new_auto(output.selected, auto_focus_fill) if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked() .clicked()
{ && let Err(error) =
if let Err(error) =
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn() Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{ {
eprintln!("{error}") eprintln!("{error}")
} }
}
}); });
} }
} }
+10 -14
View File
@@ -110,11 +110,11 @@ impl Network {
if now.duration_since(self.last_updated_default_interface) if now.duration_since(self.last_updated_default_interface)
> Duration::from_secs(self.default_refresh_interval) > Duration::from_secs(self.default_refresh_interval)
{ {
if let Ok(interface) = netdev::get_default_interface() { if let Ok(interface) = netdev::get_default_interface()
if let Some(friendly_name) = &interface.friendly_name { && let Some(friendly_name) = &interface.friendly_name
{
self.default_interface.clone_from(friendly_name); self.default_interface.clone_from(friendly_name);
} }
}
self.last_updated_default_interface = now; self.last_updated_default_interface = now;
} }
@@ -131,8 +131,9 @@ impl Network {
activity.clear(); activity.clear();
total_activity.clear(); total_activity.clear();
if let Ok(interface) = netdev::get_default_interface() { if let Ok(interface) = netdev::get_default_interface()
if let Some(friendly_name) = &interface.friendly_name { && let Some(friendly_name) = &interface.friendly_name
{
self.default_interface.clone_from(friendly_name); self.default_interface.clone_from(friendly_name);
self.networks_network_activity.refresh(true); self.networks_network_activity.refresh(true);
@@ -140,10 +141,8 @@ impl Network {
for (interface_name, data) in &self.networks_network_activity { for (interface_name, data) in &self.networks_network_activity {
if friendly_name.eq(interface_name) { if friendly_name.eq(interface_name) {
if self.show_activity { if self.show_activity {
let received = Self::to_pretty_bytes( let received =
data.received(), Self::to_pretty_bytes(data.received(), self.data_refresh_interval);
self.data_refresh_interval,
);
let transmitted = Self::to_pretty_bytes( let transmitted = Self::to_pretty_bytes(
data.transmitted(), data.transmitted(),
self.data_refresh_interval, self.data_refresh_interval,
@@ -157,8 +156,7 @@ impl Network {
} }
if self.show_total_activity { if self.show_total_activity {
let total_received = let total_received = Self::to_pretty_bytes(data.total_received(), 1);
Self::to_pretty_bytes(data.total_received(), 1);
let total_transmitted = let total_transmitted =
Self::to_pretty_bytes(data.total_transmitted(), 1); Self::to_pretty_bytes(data.total_transmitted(), 1);
@@ -171,7 +169,6 @@ impl Network {
} }
} }
} }
}
self.last_state_activity.clone_from(&activity); self.last_state_activity.clone_from(&activity);
self.last_state_total_activity.clone_from(&total_activity); self.last_state_total_activity.clone_from(&total_activity);
@@ -327,12 +324,11 @@ impl Network {
if SelectableFrame::new_auto(selected, auto_focus_fill) if SelectableFrame::new_auto(selected, auto_focus_fill)
.show(ui, add_contents) .show(ui, add_contents)
.clicked() .clicked()
&& let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn()
{ {
if let Err(error) = Command::new("cmd.exe").args(["/C", "ncpa"]).spawn() {
eprintln!("{error}"); eprintln!("{error}");
} }
} }
}
} }
impl BarWidget for Network { impl BarWidget for Network {
+1 -3
View File
@@ -156,8 +156,7 @@ impl BarWidget for Storage {
if SelectableFrame::new_auto(output.selected, auto_focus_fill) if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked() .clicked()
{ && let Err(error) = Command::new("cmd.exe")
if let Err(error) = Command::new("cmd.exe")
.args([ .args([
"/C", "/C",
"explorer.exe", "explorer.exe",
@@ -167,7 +166,6 @@ impl BarWidget for Storage {
{ {
eprintln!("{error}") eprintln!("{error}")
} }
}
}); });
} }
} }
+1 -3
View File
@@ -140,8 +140,7 @@ impl BarWidget for Update {
if SelectableFrame::new(false) if SelectableFrame::new(false)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false))) .show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked() .clicked()
{ && let Err(error) = Command::new("explorer.exe")
if let Err(error) = Command::new("explorer.exe")
.args([format!( .args([format!(
"https://github.com/LGUG2Z/komorebi/releases/v{}", "https://github.com/LGUG2Z/komorebi/releases/v{}",
self.latest_version self.latest_version
@@ -150,7 +149,6 @@ impl BarWidget for Update {
{ {
eprintln!("{error}") eprintln!("{error}")
} }
}
}); });
} }
} }
+6 -6
View File
@@ -102,11 +102,11 @@ pub extern "system" fn border_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL {
let hwnds = unsafe { &mut *(lparam.0 as *mut Vec<isize>) }; let hwnds = unsafe { &mut *(lparam.0 as *mut Vec<isize>) };
let hwnd = hwnd.0 as isize; let hwnd = hwnd.0 as isize;
if let Ok(class) = WindowsApi::real_window_class_w(hwnd) { if let Ok(class) = WindowsApi::real_window_class_w(hwnd)
if class.starts_with("komoborder") { && class.starts_with("komoborder")
{
hwnds.push(hwnd); hwnds.push(hwnd);
} }
}
true.into() true.into()
} }
@@ -392,8 +392,9 @@ impl Border {
tracing::error!("failed to update border position {error}"); tracing::error!("failed to update border position {error}");
} }
if !rect.is_same_size_as(&old_rect) || !rect.has_same_position_as(&old_rect) { if (!rect.is_same_size_as(&old_rect) || !rect.has_same_position_as(&old_rect))
if let Some(render_target) = (*border_pointer).render_target.as_ref() { && let Some(render_target) = (*border_pointer).render_target.as_ref()
{
let border_width = (*border_pointer).width; let border_width = (*border_pointer).width;
let border_offset = (*border_pointer).offset; let border_offset = (*border_pointer).offset;
@@ -450,7 +451,6 @@ impl Border {
let _ = render_target.EndDraw(None, None); let _ = render_target.EndDraw(None, None);
} }
} }
}
LRESULT(0) LRESULT(0)
} }
+3 -7
View File
@@ -341,16 +341,12 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
should_process_notification = true; should_process_notification = true;
} }
if !should_process_notification { if !should_process_notification
if let Some(Notification::Update(ref previous)) = previous_notification && let Some(Notification::Update(ref previous)) = previous_notification
{ && previous.unwrap_or_default() != notification_hwnd.unwrap_or_default()
if previous.unwrap_or_default()
!= notification_hwnd.unwrap_or_default()
{ {
should_process_notification = true; should_process_notification = true;
} }
}
}
should_process_notification should_process_notification
} }
+10 -11
View File
@@ -45,13 +45,12 @@ impl Container {
for window in self.windows().iter().rev() { for window in self.windows().iter().rev() {
let mut should_hide = omit.is_none(); let mut should_hide = omit.is_none();
if !should_hide { if !should_hide
if let Some(omit) = omit { && let Some(omit) = omit
if omit != window.hwnd { && omit != window.hwnd
{
should_hide = true should_hide = true
} }
}
}
if should_hide { if should_hide {
window.hide(); window.hide();
@@ -82,24 +81,24 @@ impl Container {
pub fn hwnd_from_exe(&self, exe: &str) -> Option<isize> { pub fn hwnd_from_exe(&self, exe: &str) -> Option<isize> {
for window in self.windows() { for window in self.windows() {
if let Ok(window_exe) = window.exe() { if let Ok(window_exe) = window.exe()
if exe == window_exe { && exe == window_exe
{
return Option::from(window.hwnd); return Option::from(window.hwnd);
} }
} }
}
None None
} }
pub fn idx_from_exe(&self, exe: &str) -> Option<usize> { pub fn idx_from_exe(&self, exe: &str) -> Option<usize> {
for (idx, window) in self.windows().iter().enumerate() { for (idx, window) in self.windows().iter().enumerate() {
if let Ok(window_exe) = window.exe() { if let Ok(window_exe) = window.exe()
if exe == window_exe { && exe == window_exe
{
return Option::from(idx); return Option::from(idx);
} }
} }
}
None None
} }
+23 -33
View File
@@ -70,12 +70,11 @@ impl Arrangement for DefaultLayout {
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical) Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) { ) && let 2.. = len
if let 2.. = len { {
columns_reverse(&mut layouts); columns_reverse(&mut layouts);
} }
} }
}
// treat >= column_count as scrolling // treat >= column_count as scrolling
len => { len => {
let visible_columns = area.right / column_width; let visible_columns = area.right / column_width;
@@ -166,11 +165,10 @@ impl Arrangement for DefaultLayout {
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical) Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) { ) && let 2.. = len
if let 2.. = len { {
columns_reverse(&mut layouts); columns_reverse(&mut layouts);
} }
}
layouts layouts
} }
@@ -191,11 +189,10 @@ impl Arrangement for DefaultLayout {
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical) Some(Axis::Vertical | Axis::HorizontalAndVertical)
) { ) && let 2.. = len
if let 2.. = len { {
rows_reverse(&mut layouts); rows_reverse(&mut layouts);
} }
}
layouts layouts
} }
@@ -245,8 +242,8 @@ impl Arrangement for DefaultLayout {
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical) Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) { ) && let 2.. = len
if let 2.. = len { {
let (primary, rest) = layouts.split_at_mut(1); let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0]; let primary = &mut primary[0];
@@ -255,16 +252,14 @@ impl Arrangement for DefaultLayout {
} }
primary.left = rest[0].left + rest[0].right; primary.left = rest[0].left + rest[0].right;
} }
}
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical) Some(Axis::Vertical | Axis::HorizontalAndVertical)
) { ) && let 3.. = len
if let 3.. = len { {
rows_reverse(&mut layouts[1..]); rows_reverse(&mut layouts[1..]);
} }
}
layouts layouts
} }
@@ -317,8 +312,8 @@ impl Arrangement for DefaultLayout {
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical) Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) { ) && let 2.. = len
if let 2.. = len { {
let (primary, rest) = layouts.split_at_mut(1); let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0]; let primary = &mut primary[0];
@@ -327,16 +322,14 @@ impl Arrangement for DefaultLayout {
rect.left = primary.left + primary.right; rect.left = primary.left + primary.right;
} }
} }
}
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical) Some(Axis::Vertical | Axis::HorizontalAndVertical)
) { ) && let 3.. = len
if let 3.. = len { {
rows_reverse(&mut layouts[1..]); rows_reverse(&mut layouts[1..]);
} }
}
layouts layouts
} }
@@ -386,8 +379,8 @@ impl Arrangement for DefaultLayout {
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical) Some(Axis::Vertical | Axis::HorizontalAndVertical)
) { ) && let 2.. = len
if let 2.. = len { {
let (primary, rest) = layouts.split_at_mut(1); let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0]; let primary = &mut primary[0];
@@ -396,16 +389,14 @@ impl Arrangement for DefaultLayout {
} }
primary.top = rest[0].top + rest[0].bottom; primary.top = rest[0].top + rest[0].bottom;
} }
}
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical) Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) { ) && let 3.. = len
if let 3.. = len { {
columns_reverse(&mut layouts[1..]); columns_reverse(&mut layouts[1..]);
} }
}
layouts layouts
} }
@@ -513,11 +504,10 @@ impl Arrangement for DefaultLayout {
if matches!( if matches!(
layout_flip, layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical) Some(Axis::Vertical | Axis::HorizontalAndVertical)
) { ) && let 4.. = len
if let 4.. = len { {
rows_reverse(&mut layouts[2..]); rows_reverse(&mut layouts[2..]);
} }
}
layouts layouts
} }
@@ -782,8 +772,9 @@ fn calculate_resize_adjustments(resize_dimensions: &[Option<Rect>]) -> Vec<Optio
// This needs to be aware of layout flips // This needs to be aware of layout flips
for (i, opt) in resize_dimensions.iter().enumerate() { for (i, opt) in resize_dimensions.iter().enumerate() {
if let Some(resize_ref) = opt { if let Some(resize_ref) = opt
if i > 0 { && i > 0
{
if resize_ref.left != 0 { if resize_ref.left != 0 {
#[allow(clippy::if_not_else)] #[allow(clippy::if_not_else)]
let range = if i == 1 { let range = if i == 1 {
@@ -846,7 +837,6 @@ fn calculate_resize_adjustments(resize_dimensions: &[Option<Rect>]) -> Vec<Optio
} }
} }
} }
}
let cleaned_resize_adjustments: Vec<_> = resize_adjustments let cleaned_resize_adjustments: Vec<_> = resize_adjustments
.iter() .iter()
+2 -3
View File
@@ -211,11 +211,10 @@ lazy_static! {
pub static ref AHK_EXE: String = { pub static ref AHK_EXE: String = {
let mut ahk: String = String::from("autohotkey.exe"); let mut ahk: String = String::from("autohotkey.exe");
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE") { if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE")
if which(&komorebi_ahk_exe).is_ok() { && which(&komorebi_ahk_exe).is_ok() {
ahk = komorebi_ahk_exe; ahk = komorebi_ahk_exe;
} }
}
ahk ahk
}; };
+3 -3
View File
@@ -233,12 +233,12 @@ fn main() -> Result<()> {
if matched_procs.len() > 1 { if matched_procs.len() > 1 {
let mut len = matched_procs.len(); let mut len = matched_procs.len();
for proc in matched_procs { for proc in matched_procs {
if let Some(executable_path) = proc.exe() { if let Some(executable_path) = proc.exe()
if executable_path.to_string_lossy().contains("shims") { && executable_path.to_string_lossy().contains("shims")
{
len -= 1; len -= 1;
} }
} }
}
if len > 1 { if len > 1 {
tracing::error!( tracing::error!(
+6 -6
View File
@@ -100,15 +100,15 @@ where
} }
for d in &all_displays { for d in &all_displays {
if let Some(id) = &d.serial_number_id { if let Some(id) = &d.serial_number_id
if serial_id_map.get(id).copied().unwrap_or_default() > 1 { && serial_id_map.get(id).copied().unwrap_or_default() > 1
{
let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write(); let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write();
if !dupes.contains(id) { if !dupes.contains(id) {
(*dupes).push(id.clone()); (*dupes).push(id.clone());
} }
} }
} }
}
Ok(all_displays Ok(all_displays
.into_iter() .into_iter()
@@ -221,8 +221,9 @@ where
let mut should_update = false; let mut should_update = false;
// Update work areas as necessary // Update work areas as necessary
if let Ok(reference) = WindowsApi::monitor(monitor.id) { if let Ok(reference) = WindowsApi::monitor(monitor.id)
if reference.work_area_size != monitor.work_area_size { && reference.work_area_size != monitor.work_area_size
{
monitor.work_area_size = Rect { monitor.work_area_size = Rect {
left: reference.work_area_size.left, left: reference.work_area_size.left,
top: reference.work_area_size.top, top: reference.work_area_size.top,
@@ -232,7 +233,6 @@ where
should_update = true; should_update = true;
} }
}
if should_update { if should_update {
tracing::info!("updated work area for {}", monitor.device_id); tracing::info!("updated work area for {}", monitor.device_id);
+92 -120
View File
@@ -195,17 +195,16 @@ impl WindowManager {
message: SocketMessage, message: SocketMessage,
mut reply: impl std::io::Write, mut reply: impl std::io::Write,
) -> Result<()> { ) -> Result<()> {
if let Some(virtual_desktop_id) = &self.virtual_desktop_id { if let Some(virtual_desktop_id) = &self.virtual_desktop_id
if let Some(id) = current_virtual_desktop() { && let Some(id) = current_virtual_desktop()
if id != *virtual_desktop_id { && id != *virtual_desktop_id
{
tracing::info!( tracing::info!(
"ignoring events and commands while not on virtual desktop {:?}", "ignoring events and commands while not on virtual desktop {:?}",
virtual_desktop_id virtual_desktop_id
); );
return Ok(()); return Ok(());
} }
}
}
#[allow(clippy::useless_asref)] #[allow(clippy::useless_asref)]
// We don't have From implemented for &mut WindowManager // We don't have From implemented for &mut WindowManager
@@ -532,12 +531,12 @@ impl WindowManager {
let mut should_push = true; let mut should_push = true;
for m in &*manage_identifiers { for m in &*manage_identifiers {
if let MatchingRule::Simple(m) = m { if let MatchingRule::Simple(m) = m
if m.id.eq(id) { && m.id.eq(id)
{
should_push = false; should_push = false;
} }
} }
}
if should_push { if should_push {
manage_identifiers.push(MatchingRule::Simple(IdWithIdentifier { manage_identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -599,12 +598,12 @@ impl WindowManager {
let mut should_push = true; let mut should_push = true;
for i in &*ignore_identifiers { for i in &*ignore_identifiers {
if let MatchingRule::Simple(i) = i { if let MatchingRule::Simple(i) = i
if i.id.eq(id) { && i.id.eq(id)
{
should_push = false; should_push = false;
} }
} }
}
if should_push { if should_push {
ignore_identifiers.push(MatchingRule::Simple(IdWithIdentifier { ignore_identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -692,28 +691,25 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
let idx = self let idx = self
.focused_monitor() .focused_monitor()
.ok_or_eyre("there is no monitor")? .ok_or_eyre("there is no monitor")?
.focused_workspace_idx(); .focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() { if let Some(monitor) = self.focused_monitor_mut()
if let Some(last_focused_workspace) = monitor.last_focused_workspace { && let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.move_container_to_workspace(last_focused_workspace, true, None)?; self.move_container_to_workspace(last_focused_workspace, true, None)?;
} }
}
self.focused_monitor_mut() self.focused_monitor_mut()
.ok_or_eyre("there is no monitor")? .ok_or_eyre("there is no monitor")?
@@ -723,28 +719,25 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
let idx = self let idx = self
.focused_monitor() .focused_monitor()
.ok_or_eyre("there is no monitor")? .ok_or_eyre("there is no monitor")?
.focused_workspace_idx(); .focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() { if let Some(monitor) = self.focused_monitor_mut()
if let Some(last_focused_workspace) = monitor.last_focused_workspace { && let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.move_container_to_workspace(last_focused_workspace, false, None)?; self.move_container_to_workspace(last_focused_workspace, false, None)?;
} }
}
self.focused_monitor_mut() self.focused_monitor_mut()
.ok_or_eyre("there is no monitor")? .ok_or_eyre("there is no monitor")?
.last_focused_workspace = Option::from(idx); .last_focused_workspace = Option::from(idx);
@@ -1038,17 +1031,14 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?; let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
@@ -1067,17 +1057,14 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?; let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
@@ -1114,17 +1101,14 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
let mut can_close = false; let mut can_close = false;
@@ -1132,8 +1116,8 @@ impl WindowManager {
let focused_workspace_idx = monitor.focused_workspace_idx(); let focused_workspace_idx = monitor.focused_workspace_idx();
let next_focused_workspace_idx = focused_workspace_idx.saturating_sub(1); let next_focused_workspace_idx = focused_workspace_idx.saturating_sub(1);
if let Some(workspace) = monitor.focused_workspace() { if let Some(workspace) = monitor.focused_workspace()
if monitor.workspaces().len() > 1 && monitor.workspaces().len() > 1
&& workspace.containers().is_empty() && workspace.containers().is_empty()
&& workspace.floating_windows().is_empty() && workspace.floating_windows().is_empty()
&& workspace.monocle_container.is_none() && workspace.monocle_container.is_none()
@@ -1142,7 +1126,6 @@ impl WindowManager {
{ {
can_close = true; can_close = true;
} }
}
if can_close if can_close
&& monitor && monitor
@@ -1158,28 +1141,25 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
let idx = self let idx = self
.focused_monitor() .focused_monitor()
.ok_or_eyre("there is no monitor")? .ok_or_eyre("there is no monitor")?
.focused_workspace_idx(); .focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() { if let Some(monitor) = self.focused_monitor_mut()
if let Some(last_focused_workspace) = monitor.last_focused_workspace { && let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.focus_workspace(last_focused_workspace)?; self.focus_workspace(last_focused_workspace)?;
} }
}
self.focused_monitor_mut() self.focused_monitor_mut()
.ok_or_eyre("there is no monitor")? .ok_or_eyre("there is no monitor")?
@@ -1189,17 +1169,14 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
if self.focused_workspace_idx().unwrap_or_default() != workspace_idx { if self.focused_workspace_idx().unwrap_or_default() != workspace_idx {
self.focus_workspace(workspace_idx)?; self.focus_workspace(workspace_idx)?;
@@ -1209,17 +1186,14 @@ impl WindowManager {
// This is to ensure that even on an empty workspace on a secondary monitor, the // This is to ensure that even on an empty workspace on a secondary monitor, the
// secondary monitor where the cursor is focused will be used as the target for // secondary monitor where the cursor is focused will be used as the target for
// the workspace switch op // the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() { if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
if monitor_idx != self.focused_monitor_idx() { && monitor_idx != self.focused_monitor_idx()
if let Some(monitor) = self.monitors().get(monitor_idx) { && let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.focused_workspace() { && let Some(workspace) = monitor.focused_workspace()
if workspace.is_empty() { && workspace.is_empty()
{
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
}
}
}
}
let focused_monitor_idx = self.focused_monitor_idx(); let focused_monitor_idx = self.focused_monitor_idx();
@@ -1297,12 +1271,12 @@ impl WindowManager {
} }
} }
if let Some(monocle) = &workspace.monocle_container { if let Some(monocle) = &workspace.monocle_container
if let Some(window) = monocle.focused_window() { && let Some(window) = monocle.focused_window()
{
window.lower()?; window.lower()?;
} }
} }
}
WorkspaceLayer::Floating => { WorkspaceLayer::Floating => {
workspace.layer = WorkspaceLayer::Tiling; workspace.layer = WorkspaceLayer::Tiling;
@@ -1515,17 +1489,15 @@ impl WindowManager {
} }
} else { } else {
for rule in &mut workspace.layout_rules { for rule in &mut workspace.layout_rules {
if container_len >= rule.0 { if container_len >= rule.0
if let Layout::Custom(ref mut custom) = rule.1 { && let Layout::Custom(ref mut custom) = rule.1
{
match sizing { match sizing {
Sizing::Increase => { Sizing::Increase => {
custom custom.set_primary_width_percentage(percentage + 5.0);
.set_primary_width_percentage(percentage + 5.0);
} }
Sizing::Decrease => { Sizing::Decrease => {
custom custom.set_primary_width_percentage(percentage - 5.0);
.set_primary_width_percentage(percentage - 5.0);
}
} }
} }
} }
@@ -1807,12 +1779,12 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut should_push = true; let mut should_push = true;
for i in &*identifiers { for i in &*identifiers {
if let MatchingRule::Simple(i) = i { if let MatchingRule::Simple(i) = i
if i.id.eq(id) { && i.id.eq(id)
{
should_push = false; should_push = false;
} }
} }
}
if should_push { if should_push {
identifiers.push(MatchingRule::Simple(IdWithIdentifier { identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -1826,12 +1798,12 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut identifiers = TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock(); let mut identifiers = TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock();
let mut should_push = true; let mut should_push = true;
for i in &*identifiers { for i in &*identifiers {
if let MatchingRule::Simple(i) = i { if let MatchingRule::Simple(i) = i
if i.id.eq(id) { && i.id.eq(id)
{
should_push = false; should_push = false;
} }
} }
}
if should_push { if should_push {
identifiers.push(MatchingRule::Simple(IdWithIdentifier { identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -1846,12 +1818,12 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut should_push = true; let mut should_push = true;
for i in &*identifiers { for i in &*identifiers {
if let MatchingRule::Simple(i) = i { if let MatchingRule::Simple(i) = i
if i.id.eq(id) { && i.id.eq(id)
{
should_push = false; should_push = false;
} }
} }
}
if should_push { if should_push {
identifiers.push(MatchingRule::Simple(IdWithIdentifier { identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -1879,13 +1851,13 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
} }
} }
SocketMessage::WorkspaceWorkAreaOffset(monitor_idx, workspace_idx, rect) => { SocketMessage::WorkspaceWorkAreaOffset(monitor_idx, workspace_idx, rect) => {
if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx) { if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx)
if let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx) { && let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx)
{
workspace.work_area_offset = Option::from(rect); workspace.work_area_offset = Option::from(rect);
self.retile_all(false)? self.retile_all(false)?
} }
} }
}
SocketMessage::ToggleWindowBasedWorkAreaOffset => { SocketMessage::ToggleWindowBasedWorkAreaOffset => {
let workspace = self.focused_workspace_mut()?; let workspace = self.focused_workspace_mut()?;
workspace.apply_window_based_work_area_offset = workspace.apply_window_based_work_area_offset =
@@ -2251,12 +2223,12 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut should_push = true; let mut should_push = true;
for i in &*identifiers { for i in &*identifiers {
if let MatchingRule::Simple(i) = i { if let MatchingRule::Simple(i) = i
if i.id.eq(id) { && i.id.eq(id)
{
should_push = false; should_push = false;
} }
} }
}
if should_push { if should_push {
identifiers.push(MatchingRule::Simple(IdWithIdentifier { identifiers.push(MatchingRule::Simple(IdWithIdentifier {
+19 -25
View File
@@ -207,15 +207,14 @@ impl WindowManager {
// //
// This check ensures that we only update the focused monitor when the window // This check ensures that we only update the focused monitor when the window
// triggering monitor reconciliation is known to not be tied to a specific monitor. // triggering monitor reconciliation is known to not be tied to a specific monitor.
if let Ok(class) = window.class() { if let Ok(class) = window.class()
if class != "OleMainThreadWndClass" && class != "OleMainThreadWndClass"
&& self.focused_monitor_idx() != monitor_idx && self.focused_monitor_idx() != monitor_idx
{ {
self.focus_monitor(monitor_idx)?; self.focus_monitor(monitor_idx)?;
} }
} }
} }
}
_ => {} _ => {}
} }
@@ -323,11 +322,11 @@ impl WindowManager {
match floating_window_idx { match floating_window_idx {
None => { None => {
if let Some(w) = &workspace.maximized_window { if let Some(w) = &workspace.maximized_window
if w.hwnd == window.hwnd { && w.hwnd == window.hwnd
{
return Ok(()); return Ok(());
} }
}
if let Some(monocle) = &workspace.monocle_container { if let Some(monocle) = &workspace.monocle_container {
if let Some(window) = monocle.focused_window() { if let Some(window) = monocle.focused_window() {
@@ -393,13 +392,12 @@ impl WindowManager {
} }
} }
if let Some((m_idx, w_idx)) = self.known_hwnds.get(&window.hwnd) { if let Some((m_idx, w_idx)) = self.known_hwnds.get(&window.hwnd)
if let Some(focused_workspace_idx) = self && let Some(focused_workspace_idx) = self
.monitors() .monitors()
.get(*m_idx) .get(*m_idx)
.map(|m| m.focused_workspace_idx()) .map(|m| m.focused_workspace_idx())
{ && *m_idx != self.focused_monitor_idx()
if *m_idx != self.focused_monitor_idx()
&& *w_idx != focused_workspace_idx && *w_idx != focused_workspace_idx
{ {
tracing::debug!( tracing::debug!(
@@ -409,8 +407,6 @@ impl WindowManager {
window.hide(); window.hide();
proceed = false; proceed = false;
} }
}
}
if proceed { if proceed {
let behaviour = self.window_management_behaviour( let behaviour = self.window_management_behaviour(
@@ -508,13 +504,12 @@ impl WindowManager {
if workspace_contains_window { if workspace_contains_window {
let mut monocle_window_event = false; let mut monocle_window_event = false;
if let Some(ref monocle) = monocle_container { if let Some(ref monocle) = monocle_container
if let Some(monocle_window) = monocle.focused_window() { && let Some(monocle_window) = monocle.focused_window()
if monocle_window.hwnd == window.hwnd { && monocle_window.hwnd == window.hwnd
{
monocle_window_event = true; monocle_window_event = true;
} }
}
}
let workspace = self.focused_workspace()?; let workspace = self.focused_workspace()?;
if !(monocle_window_event || workspace.layer != WorkspaceLayer::Tiling) if !(monocle_window_event || workspace.layer != WorkspaceLayer::Tiling)
@@ -548,15 +543,15 @@ impl WindowManager {
// If the window handles don't match then something went wrong and the pending move // If the window handles don't match then something went wrong and the pending move
// is not related to this current move, if so abort this operation. // is not related to this current move, if so abort this operation.
if let Some((_, _, w_hwnd)) = pending { if let Some((_, _, w_hwnd)) = pending
if w_hwnd != window.hwnd { && w_hwnd != window.hwnd
{
color_eyre::eyre::bail!( color_eyre::eyre::bail!(
"window handles for move operation don't match: {} != {}", "window handles for move operation don't match: {} != {}",
w_hwnd, w_hwnd,
window.hwnd window.hwnd
); );
} }
}
let target_monitor_idx = self let target_monitor_idx = self
.monitor_idx_from_current_pos() .monitor_idx_from_current_pos()
@@ -583,11 +578,11 @@ impl WindowManager {
// This will be true if we have moved to another monitor // This will be true if we have moved to another monitor
let mut moved_across_monitors = false; let mut moved_across_monitors = false;
if let Some((m_idx, _)) = self.known_hwnds.get(&window.hwnd) { if let Some((m_idx, _)) = self.known_hwnds.get(&window.hwnd)
if *m_idx != target_monitor_idx { && *m_idx != target_monitor_idx
{
moved_across_monitors = true; moved_across_monitors = true;
} }
}
if let Some((origin_monitor_idx, origin_workspace_idx, _)) = pending { if let Some((origin_monitor_idx, origin_workspace_idx, _)) = pending {
// If we didn't move to another monitor with an empty workspace, it is // If we didn't move to another monitor with an empty workspace, it is
@@ -848,8 +843,8 @@ impl WindowManager {
if let Some(target_container) = if let Some(target_container) =
c_idx.and_then(|c_idx| target_workspace.containers().get(c_idx)) c_idx.and_then(|c_idx| target_workspace.containers().get(c_idx))
&& target_container.focused_window() != Some(&window)
{ {
if target_container.focused_window() != Some(&window) {
tracing::debug!( tracing::debug!(
"Needs reconciliation within a stack on the focused workspace" "Needs reconciliation within a stack on the focused workspace"
); );
@@ -857,7 +852,6 @@ impl WindowManager {
} }
} }
} }
}
} else { } else {
tracing::debug!("Needs reconciliation for a different monitor/workspace pair"); tracing::debug!("Needs reconciliation for a different monitor/workspace pair");
needs_reconciliation = Some((*m_idx, *ws_idx)); needs_reconciliation = Some((*m_idx, *ws_idx));
+2 -3
View File
@@ -353,8 +353,8 @@ impl Stackbar {
// stackbar, make sure we update its location so that it doesn't render // stackbar, make sure we update its location so that it doesn't render
// on top of other tiles before eventually ending up in the correct // on top of other tiles before eventually ending up in the correct
// tile // tile
if index != focused_window_idx { if index != focused_window_idx
if let Err(err) = && let Err(err) =
window.set_position(&focused_window_rect, false) window.set_position(&focused_window_rect, false)
{ {
tracing::error!( tracing::error!(
@@ -363,7 +363,6 @@ impl Stackbar {
err err
); );
} }
}
// Restore the window corresponding to the tab we have clicked // Restore the window corresponding to the tab we have clicked
window.restore_with_border(false); window.restore_with_border(false);
+6 -6
View File
@@ -1367,12 +1367,12 @@ impl StaticConfig {
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
let preferred_config_idx = { let preferred_config_idx = {
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read();
let c_idx = display_index_preferences.iter().find_map(|(c_idx, id)| {
display_index_preferences.iter().find_map(|(c_idx, id)| {
(monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id) (monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id)
|| monitor.device_id.eq(id)) || monitor.device_id.eq(id))
.then_some(*c_idx) .then_some(*c_idx)
}); })
c_idx
}; };
let idx = preferred_config_idx.or({ let idx = preferred_config_idx.or({
// Monitor without preferred config idx. // Monitor without preferred config idx.
@@ -1538,12 +1538,12 @@ impl StaticConfig {
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() { for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
let preferred_config_idx = { let preferred_config_idx = {
let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read(); let display_index_preferences = DISPLAY_INDEX_PREFERENCES.read();
let c_idx = display_index_preferences.iter().find_map(|(c_idx, id)| {
display_index_preferences.iter().find_map(|(c_idx, id)| {
(monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id) (monitor.serial_number_id.as_ref().is_some_and(|sn| sn == id)
|| monitor.device_id.eq(id)) || monitor.device_id.eq(id))
.then_some(*c_idx) .then_some(*c_idx)
}); })
c_idx
}; };
let idx = preferred_config_idx.or({ let idx = preferred_config_idx.or({
// Monitor without preferred config idx. // Monitor without preferred config idx.
+4 -4
View File
@@ -152,13 +152,14 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
for (window_idx, window) in c.windows().iter().enumerate() { for (window_idx, window) in c.windows().iter().enumerate() {
if window_idx == focused_window_idx { if window_idx == focused_window_idx {
let mut should_make_transparent = true; let mut should_make_transparent = true;
if !transparency_blacklist.is_empty() { if !transparency_blacklist.is_empty()
if let (Ok(title), Ok(exe_name), Ok(class), Ok(path)) = ( && let (Ok(title), Ok(exe_name), Ok(class), Ok(path)) = (
window.title(), window.title(),
window.exe(), window.exe(),
window.class(), window.class(),
window.path(), window.path(),
) { )
{
let is_blacklisted = should_act( let is_blacklisted = should_act(
&title, &title,
&exe_name, &exe_name,
@@ -171,7 +172,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
should_make_transparent = !is_blacklisted; should_make_transparent = !is_blacklisted;
} }
}
if should_make_transparent { if should_make_transparent {
match window.transparent() { match window.transparent() {
+19 -19
View File
@@ -568,8 +568,9 @@ impl Window {
pub fn focus(self, mouse_follows_focus: bool) -> Result<()> { pub fn focus(self, mouse_follows_focus: bool) -> Result<()> {
// If the target window is already focused, do nothing. // If the target window is already focused, do nothing.
if let Ok(ihwnd) = WindowsApi::foreground_window() { if let Ok(ihwnd) = WindowsApi::foreground_window()
if ihwnd == self.hwnd { && ihwnd == self.hwnd
{
// Center cursor in Window // Center cursor in Window
if mouse_follows_focus { if mouse_follows_focus {
WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(self.hwnd)?)?; WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(self.hwnd)?)?;
@@ -577,7 +578,6 @@ impl Window {
return Ok(()); return Ok(());
} }
}
WindowsApi::raise_and_focus_window(self.hwnd)?; WindowsApi::raise_and_focus_window(self.hwnd)?;
@@ -817,14 +817,14 @@ impl Window {
let mut allow_cloaked = false; let mut allow_cloaked = false;
if let Some(event) = event { if let Some(event) = event
if matches!( && matches!(
event, event,
WindowManagerEvent::Hide(_, _) | WindowManagerEvent::Cloak(_, _) WindowManagerEvent::Hide(_, _) | WindowManagerEvent::Cloak(_, _)
) { )
{
allow_cloaked = true; allow_cloaked = true;
} }
}
debug.allow_cloaked = allow_cloaked; debug.allow_cloaked = allow_cloaked;
@@ -1302,33 +1302,33 @@ pub fn should_act_individual(
}, },
Some(MatchingStrategy::Regex) => match identifier.kind { Some(MatchingStrategy::Regex) => match identifier.kind {
ApplicationIdentifier::Title => { ApplicationIdentifier::Title => {
if let Some(re) = regex_identifiers.get(&identifier.id) { if let Some(re) = regex_identifiers.get(&identifier.id)
if re.is_match(title) { && re.is_match(title)
{
should_act = true; should_act = true;
} }
} }
}
ApplicationIdentifier::Class => { ApplicationIdentifier::Class => {
if let Some(re) = regex_identifiers.get(&identifier.id) { if let Some(re) = regex_identifiers.get(&identifier.id)
if re.is_match(class) { && re.is_match(class)
{
should_act = true; should_act = true;
} }
} }
}
ApplicationIdentifier::Exe => { ApplicationIdentifier::Exe => {
if let Some(re) = regex_identifiers.get(&identifier.id) { if let Some(re) = regex_identifiers.get(&identifier.id)
if re.is_match(exe_name) { && re.is_match(exe_name)
{
should_act = true; should_act = true;
} }
} }
}
ApplicationIdentifier::Path => { ApplicationIdentifier::Path => {
if let Some(re) = regex_identifiers.get(&identifier.id) { if let Some(re) = regex_identifiers.get(&identifier.id)
if re.is_match(path) { && re.is_match(path)
{
should_act = true; should_act = true;
} }
} }
}
}, },
} }
+61 -73
View File
@@ -486,12 +486,12 @@ impl WindowManager {
} }
} }
if let Some(window) = workspace.maximized_window { if let Some(window) = workspace.maximized_window
if window.exe().is_err() { && window.exe().is_err()
{
can_apply = false; can_apply = false;
break; break;
} }
}
if let Some(container) = &workspace.monocle_container { if let Some(container) = &workspace.monocle_container {
for window in container.windows() { for window in container.windows() {
@@ -522,8 +522,8 @@ impl WindowManager {
for (monitor_idx, monitor) in self.monitors_mut().iter_mut().enumerate() { for (monitor_idx, monitor) in self.monitors_mut().iter_mut().enumerate() {
let mut focused_workspace = 0; let mut focused_workspace = 0;
for (workspace_idx, workspace) in monitor.workspaces_mut().iter_mut().enumerate() { for (workspace_idx, workspace) in monitor.workspaces_mut().iter_mut().enumerate() {
if let Some(state_monitor) = state.monitors.elements().get(monitor_idx) { if let Some(state_monitor) = state.monitors.elements().get(monitor_idx)
if let Some(state_workspace) = state_monitor.workspaces().get(workspace_idx) && let Some(state_workspace) = state_monitor.workspaces().get(workspace_idx)
{ {
// to make sure padding changes get applied for users after a quick restart // to make sure padding changes get applied for users after a quick restart
let container_padding = workspace.container_padding; let container_padding = workspace.container_padding;
@@ -539,7 +539,6 @@ impl WindowManager {
} }
} }
} }
}
if let Err(error) = monitor.focus_workspace(focused_workspace) { if let Err(error) = monitor.focus_workspace(focused_workspace) {
tracing::warn!( tracing::warn!(
@@ -622,10 +621,10 @@ impl WindowManager {
monitor_idx: usize, monitor_idx: usize,
workspace_idx: usize, workspace_idx: usize,
) -> WindowManagementBehaviour { ) -> WindowManagementBehaviour {
if let Some(monitor) = self.monitors().get(monitor_idx) { if let Some(monitor) = self.monitors().get(monitor_idx)
if let Some(workspace) = monitor.workspaces().get(workspace_idx) { && let Some(workspace) = monitor.workspaces().get(workspace_idx)
let current_behaviour = {
if let Some(behaviour) = workspace.window_container_behaviour { let current_behaviour = if let Some(behaviour) = workspace.window_container_behaviour {
if workspace.containers().is_empty() if workspace.containers().is_empty()
&& matches!(behaviour, WindowContainerBehaviour::Append) && matches!(behaviour, WindowContainerBehaviour::Append)
{ {
@@ -673,16 +672,11 @@ impl WindowManager {
floating_layer_override, floating_layer_override,
floating_layer_behaviour, floating_layer_behaviour,
toggle_float_placement: self.window_management_behaviour.toggle_float_placement, toggle_float_placement: self.window_management_behaviour.toggle_float_placement,
floating_layer_placement: self floating_layer_placement: self.window_management_behaviour.floating_layer_placement,
.window_management_behaviour float_override_placement: self.window_management_behaviour.float_override_placement,
.floating_layer_placement,
float_override_placement: self
.window_management_behaviour
.float_override_placement,
float_rule_placement: self.window_management_behaviour.float_rule_placement, float_rule_placement: self.window_management_behaviour.float_rule_placement,
}; };
} }
}
WindowManagementBehaviour { WindowManagementBehaviour {
current_behaviour: WindowContainerBehaviour::Create, current_behaviour: WindowContainerBehaviour::Create,
@@ -1049,11 +1043,11 @@ impl WindowManager {
} }
} }
if workspace.wallpaper.is_some() || monitor_wp.is_some() { if (workspace.wallpaper.is_some() || monitor_wp.is_some())
if let Err(error) = workspace.apply_wallpaper(hmonitor, &monitor_wp) { && let Err(error) = workspace.apply_wallpaper(hmonitor, &monitor_wp)
{
tracing::error!("failed to apply wallpaper: {}", error); tracing::error!("failed to apply wallpaper: {}", error);
} }
}
workspace.update()?; workspace.update()?;
} }
@@ -1081,28 +1075,26 @@ impl WindowManager {
let workspace = self.focused_workspace()?; let workspace = self.focused_workspace()?;
// first check the focused workspace // first check the focused workspace
if let Some(container_idx) = workspace.container_idx_from_current_point() { if let Some(container_idx) = workspace.container_idx_from_current_point()
if let Some(container) = workspace.containers().get(container_idx) { && let Some(container) = workspace.containers().get(container_idx)
if let Some(window) = container.focused_window() { && let Some(window) = container.focused_window()
{
hwnd = Some(window.hwnd); hwnd = Some(window.hwnd);
} }
}
}
// then check all workspaces // then check all workspaces
if hwnd.is_none() { if hwnd.is_none() {
for monitor in self.monitors() { for monitor in self.monitors() {
for ws in monitor.workspaces() { for ws in monitor.workspaces() {
if let Some(container_idx) = ws.container_idx_from_current_point() { if let Some(container_idx) = ws.container_idx_from_current_point()
if let Some(container) = ws.containers().get(container_idx) { && let Some(container) = ws.containers().get(container_idx)
if let Some(window) = container.focused_window() { && let Some(window) = container.focused_window()
{
hwnd = Some(window.hwnd); hwnd = Some(window.hwnd);
} }
} }
} }
} }
}
}
// finally try matching the other way using a hwnd returned from the cursor pos // finally try matching the other way using a hwnd returned from the cursor pos
if hwnd.is_none() { if hwnd.is_none() {
@@ -1399,11 +1391,11 @@ impl WindowManager {
window.focus(self.mouse_follows_focus)?; window.focus(self.mouse_follows_focus)?;
} }
} else if let Some(container) = &self.focused_workspace()?.monocle_container { } else if let Some(container) = &self.focused_workspace()?.monocle_container {
if let Some(window) = container.focused_window() { if let Some(window) = container.focused_window()
if trigger_focus { && trigger_focus
{
window.focus(self.mouse_follows_focus)?; window.focus(self.mouse_follows_focus)?;
} }
}
} else if let Ok(window) = self.focused_window_mut() { } else if let Ok(window) = self.focused_window_mut() {
if trigger_focus { if trigger_focus {
window.focus(self.mouse_follows_focus)?; window.focus(self.mouse_follows_focus)?;
@@ -1443,15 +1435,13 @@ impl WindowManager {
&& self.focused_workspace()?.monocle_container.is_none() && self.focused_workspace()?.monocle_container.is_none()
// and we don't have any floating windows that should show on top // and we don't have any floating windows that should show on top
&& self.focused_workspace()?.floating_windows().is_empty() && self.focused_workspace()?.floating_windows().is_empty()
&& let Ok(window) = self.focused_window_mut()
&& trigger_focus
{ {
if let Ok(window) = self.focused_window_mut() {
if trigger_focus {
window.focus(self.mouse_follows_focus)?; window.focus(self.mouse_follows_focus)?;
} }
} }
} }
}
}
Ok(()) Ok(())
} }
@@ -1889,11 +1879,11 @@ impl WindowManager {
let focused_monitor_idx = self.focused_monitor_idx(); let focused_monitor_idx = self.focused_monitor_idx();
if focused_monitor_idx == monitor_idx { if focused_monitor_idx == monitor_idx
if let Some(workspace_idx) = workspace_idx { && let Some(workspace_idx) = workspace_idx
{
return self.move_container_to_workspace(workspace_idx, follow, None); return self.move_container_to_workspace(workspace_idx, follow, None);
} }
}
let offset = self.work_area_offset; let offset = self.work_area_offset;
let mouse_follows_focus = self.mouse_follows_focus; let mouse_follows_focus = self.mouse_follows_focus;
@@ -1937,12 +1927,12 @@ impl WindowManager {
.ok_or_eyre("there is no monitor")?; .ok_or_eyre("there is no monitor")?;
let mut should_load_workspace = false; let mut should_load_workspace = false;
if let Some(workspace_idx) = workspace_idx { if let Some(workspace_idx) = workspace_idx
if workspace_idx != target_monitor.focused_workspace_idx() { && workspace_idx != target_monitor.focused_workspace_idx()
{
target_monitor.focus_workspace(workspace_idx)?; target_monitor.focus_workspace(workspace_idx)?;
should_load_workspace = true; should_load_workspace = true;
} }
}
let target_workspace = target_monitor let target_workspace = target_monitor
.focused_workspace_mut() .focused_workspace_mut()
.ok_or_eyre("there is no focused workspace on target monitor")?; .ok_or_eyre("there is no focused workspace on target monitor")?;
@@ -1979,14 +1969,14 @@ impl WindowManager {
target_monitor.add_container(container, workspace_idx)?; target_monitor.add_container(container, workspace_idx)?;
} }
if let Some(workspace) = target_monitor.focused_workspace() { if let Some(workspace) = target_monitor.focused_workspace()
if !workspace.tile { && !workspace.tile
{
for hwnd in container_hwnds { for hwnd in container_hwnds {
Window::from(hwnd) Window::from(hwnd)
.move_to_area(&current_area, &target_monitor.work_area_size)?; .move_to_area(&current_area, &target_monitor.work_area_size)?;
} }
} }
}
} else { } else {
bail!("failed to find a window to move"); bail!("failed to find a window to move");
} }
@@ -2223,8 +2213,9 @@ impl WindowManager {
self.focus_workspace(next_idx)?; self.focus_workspace(next_idx)?;
if let Ok(focused_workspace) = self.focused_workspace_mut() { if let Ok(focused_workspace) = self.focused_workspace_mut()
if focused_workspace.monocle_container.is_none() { && focused_workspace.monocle_container.is_none()
{
match direction { match direction {
OperationDirection::Left => match focused_workspace.layout { OperationDirection::Left => match focused_workspace.layout {
Layout::Default(layout) => { Layout::Default(layout) => {
@@ -2251,7 +2242,6 @@ impl WindowManager {
_ => {} _ => {}
}; };
} }
}
return Ok(()); return Ok(());
} }
@@ -2378,8 +2368,9 @@ impl WindowManager {
self.focus_workspace(next_idx)?; self.focus_workspace(next_idx)?;
if let Ok(focused_workspace) = self.focused_workspace_mut() { if let Ok(focused_workspace) = self.focused_workspace_mut()
if focused_workspace.monocle_container.is_none() { && focused_workspace.monocle_container.is_none()
{
match direction { match direction {
OperationDirection::Left => match focused_workspace.layout { OperationDirection::Left => match focused_workspace.layout {
Layout::Default(layout) => { Layout::Default(layout) => {
@@ -2406,7 +2397,6 @@ impl WindowManager {
_ => {} _ => {}
}; };
} }
}
return Ok(()); return Ok(());
} }
@@ -2652,11 +2642,11 @@ impl WindowManager {
// unset monocle container on target workspace if there is one // unset monocle container on target workspace if there is one
let mut target_workspace_has_monocle = false; let mut target_workspace_has_monocle = false;
if let Ok(target_workspace) = self.focused_workspace() { if let Ok(target_workspace) = self.focused_workspace()
if target_workspace.monocle_container.is_some() { && target_workspace.monocle_container.is_some()
{
target_workspace_has_monocle = true; target_workspace_has_monocle = true;
} }
}
if target_workspace_has_monocle { if target_workspace_has_monocle {
self.toggle_monocle()?; self.toggle_monocle()?;
@@ -2782,11 +2772,11 @@ impl WindowManager {
} }
} }
if let Some(idx) = target_idx { if let Some(idx) = target_idx
if let Some(window) = focused_workspace.floating_windows().get(idx) { && let Some(window) = focused_workspace.floating_windows().get(idx)
{
window.focus(mouse_follows_focus)?; window.focus(mouse_follows_focus)?;
} }
}
Ok(()) Ok(())
} }
@@ -2962,11 +2952,11 @@ impl WindowManager {
let workspace = self.focused_workspace_mut()?; let workspace = self.focused_workspace_mut()?;
let mut focused_hwnd = None; let mut focused_hwnd = None;
if let Some(container) = workspace.focused_container() { if let Some(container) = workspace.focused_container()
if let Some(window) = container.focused_window() { && let Some(window) = container.focused_window()
{
focused_hwnd = Some(window.hwnd); focused_hwnd = Some(window.hwnd);
} }
}
workspace.focus_container(workspace.containers().len().saturating_sub(1)); workspace.focus_container(workspace.containers().len().saturating_sub(1));
while workspace.focused_container_idx() > 0 { while workspace.focused_container_idx() > 0 {
@@ -2989,11 +2979,11 @@ impl WindowManager {
let workspace = self.focused_workspace_mut()?; let workspace = self.focused_workspace_mut()?;
let mut focused_hwnd = None; let mut focused_hwnd = None;
if let Some(container) = workspace.focused_container() { if let Some(container) = workspace.focused_container()
if let Some(window) = container.focused_window() { && let Some(window) = container.focused_window()
{
focused_hwnd = Some(window.hwnd); focused_hwnd = Some(window.hwnd);
} }
}
let initial_focused_container_index = workspace.focused_container_idx(); let initial_focused_container_index = workspace.focused_container_idx();
let mut focused_container = workspace.focused_container().cloned(); let mut focused_container = workspace.focused_container().cloned();
@@ -3061,11 +3051,11 @@ impl WindowManager {
let mut target_container_is_stack = false; let mut target_container_is_stack = false;
if let Some(container) = workspace.containers().get(adjusted_new_index) { if let Some(container) = workspace.containers().get(adjusted_new_index)
if container.windows().len() > 1 { && container.windows().len() > 1
{
target_container_is_stack = true; target_container_is_stack = true;
} }
}
if let Some(current) = workspace.focused_container() { if let Some(current) = workspace.focused_container() {
if current.windows().len() > 1 && !target_container_is_stack { if current.windows().len() > 1 && !target_container_is_stack {
@@ -3077,14 +3067,12 @@ impl WindowManager {
} }
} }
if changed_focus { if changed_focus && let Some(container) = workspace.focused_container_mut() {
if let Some(container) = workspace.focused_container_mut() {
container.load_focused_window(); container.load_focused_window();
if let Some(window) = container.focused_window() { if let Some(window) = container.focused_window() {
window.focus(self.mouse_follows_focus)?; window.focus(self.mouse_follows_focus)?;
} }
} }
}
self.update_focused_workspace(self.mouse_follows_focus, false)?; self.update_focused_workspace(self.mouse_follows_focus, false)?;
} }
@@ -3929,13 +3917,13 @@ impl WindowManager {
for (monitor_idx, monitor) in self.monitors().iter().enumerate() { for (monitor_idx, monitor) in self.monitors().iter().enumerate() {
for (workspace_idx, workspace) in monitor.workspaces().iter().enumerate() { for (workspace_idx, workspace) in monitor.workspaces().iter().enumerate() {
if let Some(workspace_name) = &workspace.name { if let Some(workspace_name) = &workspace.name
if workspace_name == name { && workspace_name == name
{
return Option::from((monitor_idx, workspace_idx)); return Option::from((monitor_idx, workspace_idx));
} }
} }
} }
}
None None
} }
+3 -3
View File
@@ -282,15 +282,15 @@ impl WindowsApi {
} }
for d in &all_displays { for d in &all_displays {
if let Some(id) = &d.serial_number_id { if let Some(id) = &d.serial_number_id
if serial_id_map.get(id).copied().unwrap_or_default() > 1 { && serial_id_map.get(id).copied().unwrap_or_default() > 1
{
let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write(); let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write();
if !dupes.contains(id) { if !dupes.contains(id) {
(*dupes).push(id.clone()); (*dupes).push(id.clone());
} }
} }
} }
}
'read: for mut display in all_displays { 'read: for mut display in all_displays {
let path = display.device_path.clone(); let path = display.device_path.clone();
+6 -6
View File
@@ -33,8 +33,9 @@ pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
if is_visible && is_window && !is_minimized { if is_visible && is_window && !is_minimized {
let window = Window::from(hwnd); let window = Window::from(hwnd);
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) { if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default())
if should_manage { && should_manage
{
if is_maximized { if is_maximized {
WindowsApi::restore_window(window.hwnd); WindowsApi::restore_window(window.hwnd);
} }
@@ -44,7 +45,6 @@ pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
containers.push_back(container); containers.push_back(container);
} }
} }
}
true.into() true.into()
} }
@@ -59,12 +59,12 @@ pub extern "system" fn alt_tab_windows(hwnd: HWND, lparam: LPARAM) -> BOOL {
if is_visible && is_window && !is_minimized { if is_visible && is_window && !is_minimized {
let window = Window::from(hwnd); let window = Window::from(hwnd);
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) { if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default())
if should_manage { && should_manage
{
windows.push(window); windows.push(window);
} }
} }
}
true.into() true.into()
} }
+66 -71
View File
@@ -238,13 +238,12 @@ impl Workspace {
for window in self.floating_windows_mut().iter_mut().rev() { for window in self.floating_windows_mut().iter_mut().rev() {
let mut should_hide = omit.is_none(); let mut should_hide = omit.is_none();
if !should_hide { if !should_hide
if let Some(omit) = omit { && let Some(omit) = omit
if omit != window.hwnd { && omit != window.hwnd
{
should_hide = true should_hide = true
} }
}
}
if should_hide { if should_hide {
window.hide(); window.hide();
@@ -386,23 +385,23 @@ impl Workspace {
hmonitor: isize, hmonitor: isize,
monitor_wp: &Option<Wallpaper>, monitor_wp: &Option<Wallpaper>,
) -> Result<()> { ) -> Result<()> {
if let Some(container) = &self.monocle_container { if let Some(container) = &self.monocle_container
if let Some(window) = container.focused_window() { && let Some(window) = container.focused_window()
{
container.restore(); container.restore();
window.focus(mouse_follows_focus)?; window.focus(mouse_follows_focus)?;
return self.apply_wallpaper(hmonitor, monitor_wp); return self.apply_wallpaper(hmonitor, monitor_wp);
} }
}
let idx = self.focused_container_idx(); let idx = self.focused_container_idx();
let mut to_focus = None; let mut to_focus = None;
for (i, container) in self.containers_mut().iter_mut().enumerate() { for (i, container) in self.containers_mut().iter_mut().enumerate() {
if let Some(window) = container.focused_window_mut() { if let Some(window) = container.focused_window_mut()
if idx == i { && idx == i
{
to_focus = Option::from(*window); to_focus = Option::from(*window);
} }
}
container.restore(); container.restore();
} }
@@ -665,12 +664,12 @@ impl Workspace {
let point = WindowsApi::cursor_pos().ok()?; let point = WindowsApi::cursor_pos().ok()?;
for (i, _container) in self.containers().iter().enumerate() { for (i, _container) in self.containers().iter().enumerate() {
if let Some(rect) = self.latest_layout.get(i) { if let Some(rect) = self.latest_layout.get(i)
if rect.contains_point((point.x, point.y)) { && rect.contains_point((point.x, point.y))
{
idx = Option::from(i); idx = Option::from(i);
} }
} }
}
idx idx
} }
@@ -682,27 +681,26 @@ impl Workspace {
} }
} }
if let Some(window) = self.maximized_window { if let Some(window) = self.maximized_window
if let Ok(window_exe) = window.exe() { && let Ok(window_exe) = window.exe()
if exe == window_exe { && exe == window_exe
{
return Option::from(window.hwnd); return Option::from(window.hwnd);
} }
}
}
if let Some(container) = &self.monocle_container { if let Some(container) = &self.monocle_container
if let Some(hwnd) = container.hwnd_from_exe(exe) { && let Some(hwnd) = container.hwnd_from_exe(exe)
{
return Option::from(hwnd); return Option::from(hwnd);
} }
}
for window in self.floating_windows() { for window in self.floating_windows() {
if let Ok(window_exe) = window.exe() { if let Ok(window_exe) = window.exe()
if exe == window_exe { && exe == window_exe
{
return Option::from(window.hwnd); return Option::from(window.hwnd);
} }
} }
}
None None
} }
@@ -717,27 +715,26 @@ impl Workspace {
} }
} }
if let Some(window) = self.maximized_window { if let Some(window) = self.maximized_window
if let Ok(window_exe) = window.exe() { && let Ok(window_exe) = window.exe()
if exe == window_exe { && exe == window_exe
{
return Some(WorkspaceWindowLocation::Maximized); return Some(WorkspaceWindowLocation::Maximized);
} }
}
}
if let Some(container) = &self.monocle_container { if let Some(container) = &self.monocle_container
if let Some(window_idx) = container.idx_from_exe(exe) { && let Some(window_idx) = container.idx_from_exe(exe)
{
return Some(WorkspaceWindowLocation::Monocle(window_idx)); return Some(WorkspaceWindowLocation::Monocle(window_idx));
} }
}
for (window_idx, window) in self.floating_windows().iter().enumerate() { for (window_idx, window) in self.floating_windows().iter().enumerate() {
if let Ok(window_exe) = window.exe() { if let Ok(window_exe) = window.exe()
if exe == window_exe { && exe == window_exe
{
return Some(WorkspaceWindowLocation::Floating(window_idx)); return Some(WorkspaceWindowLocation::Floating(window_idx));
} }
} }
}
None None
} }
@@ -749,34 +746,34 @@ impl Workspace {
} }
} }
if let Some(window) = self.maximized_window { if let Some(window) = self.maximized_window
if hwnd == window.hwnd { && hwnd == window.hwnd
{
return true; return true;
} }
}
if let Some(container) = &self.monocle_container { if let Some(container) = &self.monocle_container
if container.contains_window(hwnd) { && container.contains_window(hwnd)
{
return true; return true;
} }
}
false false
} }
pub fn is_focused_window_monocle_or_maximized(&self) -> Result<bool> { pub fn is_focused_window_monocle_or_maximized(&self) -> Result<bool> {
let hwnd = WindowsApi::foreground_window()?; let hwnd = WindowsApi::foreground_window()?;
if let Some(window) = self.maximized_window { if let Some(window) = self.maximized_window
if hwnd == window.hwnd { && hwnd == window.hwnd
{
return Ok(true); return Ok(true);
} }
}
if let Some(container) = &self.monocle_container { if let Some(container) = &self.monocle_container
if container.contains_window(hwnd) { && container.contains_window(hwnd)
{
return Ok(true); return Ok(true);
} }
}
Ok(false) Ok(false)
} }
@@ -795,17 +792,17 @@ impl Workspace {
} }
} }
if let Some(window) = self.maximized_window { if let Some(window) = self.maximized_window
if hwnd == window.hwnd { && hwnd == window.hwnd
{
return true; return true;
} }
}
if let Some(container) = &self.monocle_container { if let Some(container) = &self.monocle_container
if container.contains_window(hwnd) { && container.contains_window(hwnd)
{
return true; return true;
} }
}
for window in self.floating_windows() { for window in self.floating_windows() {
if hwnd == window.hwnd { if hwnd == window.hwnd {
@@ -897,8 +894,8 @@ impl Workspace {
return Ok(()); return Ok(());
} }
if let Some(container) = &mut self.monocle_container { if let Some(container) = &mut self.monocle_container
if let Some(window_idx) = container && let Some(window_idx) = container
.windows() .windows()
.iter() .iter()
.position(|window| window.hwnd == hwnd) .position(|window| window.hwnd == hwnd)
@@ -918,16 +915,15 @@ impl Workspace {
return Ok(()); return Ok(());
} }
}
if let Some(window) = self.maximized_window { if let Some(window) = self.maximized_window
if window.hwnd == hwnd { && window.hwnd == hwnd
{
window.unmaximize(); window.unmaximize();
self.maximized_window = None; self.maximized_window = None;
self.maximized_window_restore_idx = None; self.maximized_window_restore_idx = None;
return Ok(()); return Ok(());
} }
}
let container_idx = self let container_idx = self
.container_idx_for_window(hwnd) .container_idx_for_window(hwnd)
@@ -1632,27 +1628,26 @@ impl Workspace {
pub fn visible_window_details(&self) -> Vec<WindowDetails> { pub fn visible_window_details(&self) -> Vec<WindowDetails> {
let mut vec: Vec<WindowDetails> = vec![]; let mut vec: Vec<WindowDetails> = vec![];
if let Some(maximized) = self.maximized_window { if let Some(maximized) = self.maximized_window
if let Ok(details) = (maximized).try_into() { && let Ok(details) = (maximized).try_into()
{
vec.push(details); vec.push(details);
} }
}
if let Some(monocle) = &self.monocle_container { if let Some(monocle) = &self.monocle_container
if let Some(focused) = monocle.focused_window() { && let Some(focused) = monocle.focused_window()
if let Ok(details) = (*focused).try_into() { && let Ok(details) = (*focused).try_into()
{
vec.push(details); vec.push(details);
} }
}
}
for container in self.containers() { for container in self.containers() {
if let Some(focused) = container.focused_window() { if let Some(focused) = container.focused_window()
if let Ok(details) = (*focused).try_into() { && let Ok(details) = (*focused).try_into()
{
vec.push(details); vec.push(details);
} }
} }
}
for window in self.floating_windows() { for window in self.floating_windows() {
if let Ok(details) = (*window).try_into() { if let Ok(details) = (*window).try_into() {
+6 -6
View File
@@ -2182,11 +2182,11 @@ fn main() -> Result<()> {
SubCommand::Start(arg) => { SubCommand::Start(arg) => {
let mut ahk: String = String::from("autohotkey.exe"); let mut ahk: String = String::from("autohotkey.exe");
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE") { if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE")
if which(&komorebi_ahk_exe).is_ok() { && which(&komorebi_ahk_exe).is_ok()
{
ahk = komorebi_ahk_exe; ahk = komorebi_ahk_exe;
} }
}
if arg.whkd && which("whkd").is_err() { if arg.whkd && which("whkd").is_err() {
bail!( bail!(
@@ -2360,8 +2360,9 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue))
komorebi_json.is_file().then_some(komorebi_json) komorebi_json.is_file().then_some(komorebi_json)
}); });
if arg.bar { if arg.bar
if let Some(config) = &static_config { && let Some(config) = &static_config
{
let mut config = StaticConfig::read(config)?; let mut config = StaticConfig::read(config)?;
if let Some(display_bar_configurations) = &mut config.bar_configurations { if let Some(display_bar_configurations) = &mut config.bar_configurations {
for config_file_path in &mut *display_bar_configurations { for config_file_path in &mut *display_bar_configurations {
@@ -2396,7 +2397,6 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
} }
} }
} }
}
if arg.masir { if arg.masir {
let script = r" let script = r"