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

View File

@@ -322,16 +322,15 @@ pub fn apply_theme(
// apply rounding to the widgets
if let Some(Grouping::Bar(config) | Grouping::Alignment(config) | Grouping::Widget(config)) =
&grouping
&& let Some(rounding) = config.rounding
{
if let Some(rounding) = config.rounding {
ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.corner_radius = rounding.into();
style.visuals.widgets.inactive.corner_radius = rounding.into();
style.visuals.widgets.hovered.corner_radius = rounding.into();
style.visuals.widgets.active.corner_radius = rounding.into();
style.visuals.widgets.open.corner_radius = rounding.into();
});
}
ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.corner_radius = rounding.into();
style.visuals.widgets.inactive.corner_radius = rounding.into();
style.visuals.widgets.hovered.corner_radius = rounding.into();
style.visuals.widgets.active.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
@@ -672,17 +671,16 @@ impl Komobar {
| Grouping::Alignment(config)
| Grouping::Widget(config),
) = &bar_grouping
&& let Some(rounding) = config.rounding
{
if let Some(rounding) = config.rounding {
ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.corner_radius =
rounding.into();
style.visuals.widgets.inactive.corner_radius = rounding.into();
style.visuals.widgets.hovered.corner_radius = rounding.into();
style.visuals.widgets.active.corner_radius = rounding.into();
style.visuals.widgets.open.corner_radius = rounding.into();
});
}
ctx.style_mut(|style| {
style.visuals.widgets.noninteractive.corner_radius =
rounding.into();
style.visuals.widgets.inactive.corner_radius = rounding.into();
style.visuals.widgets.hovered.corner_radius = rounding.into();
style.visuals.widgets.active.corner_radius = rounding.into();
style.visuals.widgets.open.corner_radius = rounding.into();
});
}
}
}

View File

@@ -87,41 +87,41 @@ impl Battery {
if now.duration_since(self.last_updated) > Duration::from_secs(self.data_refresh_interval) {
output = None;
if let Ok(mut batteries) = self.manager.batteries() {
if let Some(Ok(first)) = batteries.nth(0) {
let percentage = first.state_of_charge().get::<percent>().round() as u8;
if let Ok(mut batteries) = self.manager.batteries()
&& let Some(Ok(first)) = batteries.nth(0)
{
let percentage = first.state_of_charge().get::<percent>().round() as u8;
if percentage == 100 && self.hide_on_full_charge {
output = None
} else {
match first.state() {
State::Charging => self.state = BatteryState::Charging,
State::Discharging => {
self.state = match percentage {
p if p > 75 => BatteryState::Discharging,
p if p > 50 => BatteryState::High,
p if p > 25 => BatteryState::Medium,
p if p > 10 => BatteryState::Low,
_ => BatteryState::Warning,
}
if percentage == 100 && self.hide_on_full_charge {
output = None
} else {
match first.state() {
State::Charging => self.state = BatteryState::Charging,
State::Discharging => {
self.state = match percentage {
p if p > 75 => BatteryState::Discharging,
p if p > 50 => BatteryState::High,
p if p > 25 => BatteryState::Medium,
p if p > 10 => BatteryState::Low,
_ => BatteryState::Warning,
}
_ => {}
}
let selected = self.auto_select_under.is_some_and(|u| percentage <= u);
output = Some(BatteryOutput {
label: match self.label_prefix {
LabelPrefix::Text | LabelPrefix::IconAndText => {
format!("BAT: {percentage}%")
}
LabelPrefix::None | LabelPrefix::Icon => {
format!("{percentage}%")
}
},
selected,
})
_ => {}
}
let selected = self.auto_select_under.is_some_and(|u| percentage <= u);
output = Some(BatteryOutput {
label: match self.label_prefix {
LabelPrefix::Text | LabelPrefix::IconAndText => {
format!("BAT: {percentage}%")
}
LabelPrefix::None | LabelPrefix::Icon => {
format!("{percentage}%")
}
},
selected,
})
}
}
@@ -176,13 +176,11 @@ impl BarWidget for Battery {
if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked()
{
if let Err(error) = Command::new("cmd.exe")
&& let Err(error) = Command::new("cmd.exe")
.args(["/C", "start", "ms-settings:batterysaver"])
.spawn()
{
eprintln!("{error}")
}
{
eprintln!("{error}")
}
});
}

View File

@@ -120,12 +120,10 @@ impl BarWidget for Cpu {
if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked()
{
if let Err(error) =
&& let Err(error) =
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{
eprintln!("{error}")
}
{
eprintln!("{error}")
}
});
}

View File

@@ -271,14 +271,14 @@ impl Komorebi {
}
fn render_layout(&mut self, ctx: &Context, ui: &mut Ui, config: &mut RenderConfig) {
if let Some(layout_config) = &self.layout {
if layout_config.enable {
let monitor_info = &mut *self.monitor_info.borrow_mut();
let workspace_idx = monitor_info.focused_workspace_idx;
monitor_info
.layout
.show(ctx, ui, config, layout_config, workspace_idx);
}
if let Some(layout_config) = &self.layout
&& layout_config.enable
{
let monitor_info = &mut *self.monitor_info.borrow_mut();
let workspace_idx = monitor_info.focused_workspace_idx;
monitor_info
.layout
.show(ctx, ui, config, layout_config, workspace_idx);
}
}
@@ -558,10 +558,8 @@ impl FocusedContainerBar {
ui.add(img.fit_to_exact_size(self.icon_size));
}
});
if HOVEL {
if let Some(title) = &info.title {
inner_response.response.on_hover_text(title);
}
if HOVEL && let Some(title) = &info.title {
inner_response.response.on_hover_text(title);
}
}

View File

@@ -91,16 +91,15 @@ impl KomorebiLayout {
fn on_click_option(&mut self, monitor_idx: usize, workspace_idx: Option<usize>) {
match self {
KomorebiLayout::Default(option) => {
if let Some(ws_idx) = workspace_idx {
if komorebi_client::send_message(&SocketMessage::WorkspaceLayout(
if let Some(ws_idx) = workspace_idx
&& komorebi_client::send_message(&SocketMessage::WorkspaceLayout(
monitor_idx,
ws_idx,
*option,
))
.is_err()
{
tracing::error!("could not send message to komorebi: WorkspaceLayout");
}
{
tracing::error!("could not send message to komorebi: WorkspaceLayout");
}
}
KomorebiLayout::Monocle => {
@@ -269,57 +268,53 @@ impl KomorebiLayout {
show_options = self.on_click(&show_options, monitor_idx, workspace_idx);
}
if show_options {
if let Some(workspace_idx) = workspace_idx {
Frame::NONE.show(ui, |ui| {
ui.add(
Label::new(egui_phosphor::regular::ARROW_FAT_LINES_RIGHT.to_string())
.selectable(false),
);
if show_options && let Some(workspace_idx) = workspace_idx {
Frame::NONE.show(ui, |ui| {
ui.add(
Label::new(egui_phosphor::regular::ARROW_FAT_LINES_RIGHT.to_string())
.selectable(false),
);
let mut layout_options = layout_config.options.clone().unwrap_or(vec![
KomorebiLayout::Default(komorebi_client::DefaultLayout::BSP),
KomorebiLayout::Default(komorebi_client::DefaultLayout::Columns),
KomorebiLayout::Default(komorebi_client::DefaultLayout::Rows),
KomorebiLayout::Default(komorebi_client::DefaultLayout::VerticalStack),
KomorebiLayout::Default(
komorebi_client::DefaultLayout::RightMainVerticalStack,
),
KomorebiLayout::Default(
komorebi_client::DefaultLayout::HorizontalStack,
),
KomorebiLayout::Default(
komorebi_client::DefaultLayout::UltrawideVerticalStack,
),
KomorebiLayout::Default(komorebi_client::DefaultLayout::Grid),
//KomorebiLayout::Custom,
KomorebiLayout::Monocle,
KomorebiLayout::Floating,
KomorebiLayout::Paused,
]);
let mut layout_options = layout_config.options.clone().unwrap_or(vec![
KomorebiLayout::Default(komorebi_client::DefaultLayout::BSP),
KomorebiLayout::Default(komorebi_client::DefaultLayout::Columns),
KomorebiLayout::Default(komorebi_client::DefaultLayout::Rows),
KomorebiLayout::Default(komorebi_client::DefaultLayout::VerticalStack),
KomorebiLayout::Default(
komorebi_client::DefaultLayout::RightMainVerticalStack,
),
KomorebiLayout::Default(komorebi_client::DefaultLayout::HorizontalStack),
KomorebiLayout::Default(
komorebi_client::DefaultLayout::UltrawideVerticalStack,
),
KomorebiLayout::Default(komorebi_client::DefaultLayout::Grid),
//KomorebiLayout::Custom,
KomorebiLayout::Monocle,
KomorebiLayout::Floating,
KomorebiLayout::Paused,
]);
for layout_option in &mut layout_options {
let is_selected = self == layout_option;
for layout_option in &mut layout_options {
let is_selected = self == layout_option;
if SelectableFrame::new(is_selected)
.show(ui, |ui| {
layout_option.show_icon(is_selected, font_id.clone(), ctx, ui)
})
.on_hover_text(match layout_option {
KomorebiLayout::Default(layout) => layout.to_string(),
KomorebiLayout::Monocle => "Toggle monocle".to_string(),
KomorebiLayout::Floating => "Toggle tiling".to_string(),
KomorebiLayout::Paused => "Toggle pause".to_string(),
KomorebiLayout::Custom => "Custom".to_string(),
})
.clicked()
{
layout_option.on_click_option(monitor_idx, Some(workspace_idx));
show_options = false;
};
}
});
}
if SelectableFrame::new(is_selected)
.show(ui, |ui| {
layout_option.show_icon(is_selected, font_id.clone(), ctx, ui)
})
.on_hover_text(match layout_option {
KomorebiLayout::Default(layout) => layout.to_string(),
KomorebiLayout::Monocle => "Toggle monocle".to_string(),
KomorebiLayout::Floating => "Toggle tiling".to_string(),
KomorebiLayout::Paused => "Toggle pause".to_string(),
KomorebiLayout::Custom => "Custom".to_string(),
})
.clicked()
{
layout_option.on_click_option(monitor_idx, Some(workspace_idx));
show_options = false;
};
}
});
}
});

View File

@@ -46,30 +46,28 @@ impl Media {
}
pub fn toggle(&self) {
if let Ok(session) = self.session_manager.GetCurrentSession() {
if let Ok(op) = session.TryTogglePlayPauseAsync() {
op.get().unwrap_or_default();
}
if let Ok(session) = self.session_manager.GetCurrentSession()
&& let Ok(op) = session.TryTogglePlayPauseAsync()
{
op.get().unwrap_or_default();
}
}
fn output(&mut self) -> String {
if let Ok(session) = self.session_manager.GetCurrentSession() {
if let Ok(operation) = session.TryGetMediaPropertiesAsync() {
if let Ok(properties) = operation.get() {
if let (Ok(artist), Ok(title)) = (properties.Artist(), properties.Title()) {
if artist.is_empty() {
return format!("{title}");
}
if title.is_empty() {
return format!("{artist}");
}
return format!("{artist} - {title}");
}
}
if let Ok(session) = self.session_manager.GetCurrentSession()
&& let Ok(operation) = session.TryGetMediaPropertiesAsync()
&& let Ok(properties) = operation.get()
&& let (Ok(artist), Ok(title)) = (properties.Artist(), properties.Title())
{
if artist.is_empty() {
return format!("{title}");
}
if title.is_empty() {
return format!("{artist}");
}
return format!("{artist} - {title}");
}
String::new()

View File

@@ -124,12 +124,10 @@ impl BarWidget for Memory {
if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked()
{
if let Err(error) =
&& let Err(error) =
Command::new("cmd.exe").args(["/C", "taskmgr.exe"]).spawn()
{
eprintln!("{error}")
}
{
eprintln!("{error}")
}
});
}

View File

@@ -110,10 +110,10 @@ impl Network {
if now.duration_since(self.last_updated_default_interface)
> Duration::from_secs(self.default_refresh_interval)
{
if let Ok(interface) = netdev::get_default_interface() {
if let Some(friendly_name) = &interface.friendly_name {
self.default_interface.clone_from(friendly_name);
}
if let Ok(interface) = netdev::get_default_interface()
&& let Some(friendly_name) = &interface.friendly_name
{
self.default_interface.clone_from(friendly_name);
}
self.last_updated_default_interface = now;
@@ -131,43 +131,40 @@ impl Network {
activity.clear();
total_activity.clear();
if let Ok(interface) = netdev::get_default_interface() {
if let Some(friendly_name) = &interface.friendly_name {
self.default_interface.clone_from(friendly_name);
if let Ok(interface) = netdev::get_default_interface()
&& let Some(friendly_name) = &interface.friendly_name
{
self.default_interface.clone_from(friendly_name);
self.networks_network_activity.refresh(true);
self.networks_network_activity.refresh(true);
for (interface_name, data) in &self.networks_network_activity {
if friendly_name.eq(interface_name) {
if self.show_activity {
let received = Self::to_pretty_bytes(
data.received(),
self.data_refresh_interval,
);
let transmitted = Self::to_pretty_bytes(
data.transmitted(),
self.data_refresh_interval,
);
for (interface_name, data) in &self.networks_network_activity {
if friendly_name.eq(interface_name) {
if self.show_activity {
let received =
Self::to_pretty_bytes(data.received(), self.data_refresh_interval);
let transmitted = Self::to_pretty_bytes(
data.transmitted(),
self.data_refresh_interval,
);
activity.push(NetworkReading::new(
NetworkReadingFormat::Speed,
ReadingValue::from(received),
ReadingValue::from(transmitted),
));
}
activity.push(NetworkReading::new(
NetworkReadingFormat::Speed,
ReadingValue::from(received),
ReadingValue::from(transmitted),
));
}
if self.show_total_activity {
let total_received =
Self::to_pretty_bytes(data.total_received(), 1);
let total_transmitted =
Self::to_pretty_bytes(data.total_transmitted(), 1);
if self.show_total_activity {
let total_received = Self::to_pretty_bytes(data.total_received(), 1);
let total_transmitted =
Self::to_pretty_bytes(data.total_transmitted(), 1);
total_activity.push(NetworkReading::new(
NetworkReadingFormat::Total,
ReadingValue::from(total_received),
ReadingValue::from(total_transmitted),
))
}
total_activity.push(NetworkReading::new(
NetworkReadingFormat::Total,
ReadingValue::from(total_received),
ReadingValue::from(total_transmitted),
))
}
}
}
@@ -327,10 +324,9 @@ impl Network {
if SelectableFrame::new_auto(selected, auto_focus_fill)
.show(ui, add_contents)
.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}");
}
}
}

View File

@@ -156,17 +156,15 @@ impl BarWidget for Storage {
if SelectableFrame::new_auto(output.selected, auto_focus_fill)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked()
{
if let Err(error) = Command::new("cmd.exe")
&& let Err(error) = Command::new("cmd.exe")
.args([
"/C",
"explorer.exe",
output.label.split(' ').collect::<Vec<&str>>()[0],
])
.spawn()
{
eprintln!("{error}")
}
{
eprintln!("{error}")
}
});
}

View File

@@ -140,16 +140,14 @@ impl BarWidget for Update {
if SelectableFrame::new(false)
.show(ui, |ui| ui.add(Label::new(layout_job).selectable(false)))
.clicked()
{
if let Err(error) = Command::new("explorer.exe")
&& let Err(error) = Command::new("explorer.exe")
.args([format!(
"https://github.com/LGUG2Z/komorebi/releases/v{}",
self.latest_version
)])
.spawn()
{
eprintln!("{error}")
}
{
eprintln!("{error}")
}
});
}

View File

@@ -102,10 +102,10 @@ pub extern "system" fn border_hwnds(hwnd: HWND, lparam: LPARAM) -> BOOL {
let hwnds = unsafe { &mut *(lparam.0 as *mut Vec<isize>) };
let hwnd = hwnd.0 as isize;
if let Ok(class) = WindowsApi::real_window_class_w(hwnd) {
if class.starts_with("komoborder") {
hwnds.push(hwnd);
}
if let Ok(class) = WindowsApi::real_window_class_w(hwnd)
&& class.starts_with("komoborder")
{
hwnds.push(hwnd);
}
true.into()
@@ -392,63 +392,63 @@ impl Border {
tracing::error!("failed to update border position {error}");
}
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 border_width = (*border_pointer).width;
let border_offset = (*border_pointer).offset;
if (!rect.is_same_size_as(&old_rect) || !rect.has_same_position_as(&old_rect))
&& let Some(render_target) = (*border_pointer).render_target.as_ref()
{
let border_width = (*border_pointer).width;
let border_offset = (*border_pointer).offset;
(*border_pointer).rounded_rect.rect = D2D_RECT_F {
left: (border_width / 2 - border_offset) as f32,
top: (border_width / 2 - border_offset) as f32,
right: (rect.right - border_width / 2 + border_offset) as f32,
bottom: (rect.bottom - border_width / 2 + border_offset) as f32,
(*border_pointer).rounded_rect.rect = D2D_RECT_F {
left: (border_width / 2 - border_offset) as f32,
top: (border_width / 2 - border_offset) as f32,
right: (rect.right - border_width / 2 + border_offset) as f32,
bottom: (rect.bottom - border_width / 2 + border_offset) as f32,
};
let _ = render_target.Resize(&D2D_SIZE_U {
width: rect.right as u32,
height: rect.bottom as u32,
});
let window_kind = (*border_pointer).window_kind;
if let Some(brush) = (*border_pointer).brushes.get(&window_kind) {
render_target.BeginDraw();
render_target.Clear(None);
// Calculate border radius based on style
let style = match (*border_pointer).style {
BorderStyle::System => {
if *WINDOWS_11 {
BorderStyle::Rounded
} else {
BorderStyle::Square
}
}
BorderStyle::Rounded => BorderStyle::Rounded,
BorderStyle::Square => BorderStyle::Square,
};
let _ = render_target.Resize(&D2D_SIZE_U {
width: rect.right as u32,
height: rect.bottom as u32,
});
let window_kind = (*border_pointer).window_kind;
if let Some(brush) = (*border_pointer).brushes.get(&window_kind) {
render_target.BeginDraw();
render_target.Clear(None);
// Calculate border radius based on style
let style = match (*border_pointer).style {
BorderStyle::System => {
if *WINDOWS_11 {
BorderStyle::Rounded
} else {
BorderStyle::Square
}
}
BorderStyle::Rounded => BorderStyle::Rounded,
BorderStyle::Square => BorderStyle::Square,
};
match style {
BorderStyle::Rounded => {
render_target.DrawRoundedRectangle(
&(*border_pointer).rounded_rect,
brush,
border_width as f32,
None,
);
}
BorderStyle::Square => {
render_target.DrawRectangle(
&(*border_pointer).rounded_rect.rect,
brush,
border_width as f32,
None,
);
}
_ => {}
match style {
BorderStyle::Rounded => {
render_target.DrawRoundedRectangle(
&(*border_pointer).rounded_rect,
brush,
border_width as f32,
None,
);
}
let _ = render_target.EndDraw(None, None);
BorderStyle::Square => {
render_target.DrawRectangle(
&(*border_pointer).rounded_rect.rect,
brush,
border_width as f32,
None,
);
}
_ => {}
}
let _ = render_target.EndDraw(None, None);
}
}

View File

@@ -341,15 +341,11 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
should_process_notification = true;
}
if !should_process_notification {
if let Some(Notification::Update(ref previous)) = previous_notification
{
if previous.unwrap_or_default()
!= notification_hwnd.unwrap_or_default()
{
should_process_notification = true;
}
}
if !should_process_notification
&& let Some(Notification::Update(ref previous)) = previous_notification
&& previous.unwrap_or_default() != notification_hwnd.unwrap_or_default()
{
should_process_notification = true;
}
should_process_notification

View File

@@ -45,12 +45,11 @@ impl Container {
for window in self.windows().iter().rev() {
let mut should_hide = omit.is_none();
if !should_hide {
if let Some(omit) = omit {
if omit != window.hwnd {
should_hide = true
}
}
if !should_hide
&& let Some(omit) = omit
&& omit != window.hwnd
{
should_hide = true
}
if should_hide {
@@ -82,10 +81,10 @@ impl Container {
pub fn hwnd_from_exe(&self, exe: &str) -> Option<isize> {
for window in self.windows() {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
return Option::from(window.hwnd);
}
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Option::from(window.hwnd);
}
}
@@ -94,10 +93,10 @@ impl Container {
pub fn idx_from_exe(&self, exe: &str) -> Option<usize> {
for (idx, window) in self.windows().iter().enumerate() {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
return Option::from(idx);
}
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Option::from(idx);
}
}

View File

@@ -70,10 +70,9 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
columns_reverse(&mut layouts);
}
) && let 2.. = len
{
columns_reverse(&mut layouts);
}
}
// treat >= column_count as scrolling
@@ -166,10 +165,9 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
columns_reverse(&mut layouts);
}
) && let 2.. = len
{
columns_reverse(&mut layouts);
}
layouts
@@ -191,10 +189,9 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
rows_reverse(&mut layouts);
}
) && let 2.. = len
{
rows_reverse(&mut layouts);
}
layouts
@@ -245,25 +242,23 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
) && let 2.. = len
{
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
for rect in rest.iter_mut() {
rect.left = primary.left;
}
primary.left = rest[0].left + rest[0].right;
for rect in rest.iter_mut() {
rect.left = primary.left;
}
primary.left = rest[0].left + rest[0].right;
}
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 3.. = len {
rows_reverse(&mut layouts[1..]);
}
) && let 3.. = len
{
rows_reverse(&mut layouts[1..]);
}
layouts
@@ -317,25 +312,23 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
) && let 2.. = len
{
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
primary.left = rest[0].left;
for rect in rest.iter_mut() {
rect.left = primary.left + primary.right;
}
primary.left = rest[0].left;
for rect in rest.iter_mut() {
rect.left = primary.left + primary.right;
}
}
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 3.. = len {
rows_reverse(&mut layouts[1..]);
}
) && let 3.. = len
{
rows_reverse(&mut layouts[1..]);
}
layouts
@@ -386,25 +379,23 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
) && let 2.. = len
{
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
for rect in rest.iter_mut() {
rect.top = primary.top;
}
primary.top = rest[0].top + rest[0].bottom;
for rect in rest.iter_mut() {
rect.top = primary.top;
}
primary.top = rest[0].top + rest[0].bottom;
}
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 3.. = len {
columns_reverse(&mut layouts[1..]);
}
) && let 3.. = len
{
columns_reverse(&mut layouts[1..]);
}
layouts
@@ -513,10 +504,9 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 4.. = len {
rows_reverse(&mut layouts[2..]);
}
) && let 4.. = len
{
rows_reverse(&mut layouts[2..]);
}
layouts
@@ -782,67 +772,67 @@ fn calculate_resize_adjustments(resize_dimensions: &[Option<Rect>]) -> Vec<Optio
// This needs to be aware of layout flips
for (i, opt) in resize_dimensions.iter().enumerate() {
if let Some(resize_ref) = opt {
if i > 0 {
if resize_ref.left != 0 {
#[allow(clippy::if_not_else)]
let range = if i == 1 {
0..1
} else if i & 1 != 0 {
i - 1..i
} else {
i - 2..i
};
if let Some(resize_ref) = opt
&& i > 0
{
if resize_ref.left != 0 {
#[allow(clippy::if_not_else)]
let range = if i == 1 {
0..1
} else if i & 1 != 0 {
i - 1..i
} else {
i - 2..i
};
for n in range {
let should_adjust = n % 2 == 0;
if should_adjust {
if let Some(Some(adjacent_resize)) = resize_adjustments.get_mut(n) {
adjacent_resize.right += resize_ref.left;
} else {
resize_adjustments[n] = Option::from(Rect {
left: 0,
top: 0,
right: resize_ref.left,
bottom: 0,
});
}
for n in range {
let should_adjust = n % 2 == 0;
if should_adjust {
if let Some(Some(adjacent_resize)) = resize_adjustments.get_mut(n) {
adjacent_resize.right += resize_ref.left;
} else {
resize_adjustments[n] = Option::from(Rect {
left: 0,
top: 0,
right: resize_ref.left,
bottom: 0,
});
}
}
if let Some(rr) = resize_adjustments[i].as_mut() {
rr.left = 0;
}
}
if resize_ref.top != 0 {
let range = if i == 1 {
0..1
} else if i & 1 == 0 {
i - 1..i
} else {
i - 2..i
};
if let Some(rr) = resize_adjustments[i].as_mut() {
rr.left = 0;
}
}
for n in range {
let should_adjust = n % 2 != 0;
if should_adjust {
if let Some(Some(adjacent_resize)) = resize_adjustments.get_mut(n) {
adjacent_resize.bottom += resize_ref.top;
} else {
resize_adjustments[n] = Option::from(Rect {
left: 0,
top: 0,
right: 0,
bottom: resize_ref.top,
});
}
if resize_ref.top != 0 {
let range = if i == 1 {
0..1
} else if i & 1 == 0 {
i - 1..i
} else {
i - 2..i
};
for n in range {
let should_adjust = n % 2 != 0;
if should_adjust {
if let Some(Some(adjacent_resize)) = resize_adjustments.get_mut(n) {
adjacent_resize.bottom += resize_ref.top;
} else {
resize_adjustments[n] = Option::from(Rect {
left: 0,
top: 0,
right: 0,
bottom: resize_ref.top,
});
}
}
}
if let Some(Some(resize)) = resize_adjustments.get_mut(i) {
resize.top = 0;
}
if let Some(Some(resize)) = resize_adjustments.get_mut(i) {
resize.top = 0;
}
}
}

View File

@@ -211,11 +211,10 @@ lazy_static! {
pub static ref AHK_EXE: String = {
let mut ahk: String = String::from("autohotkey.exe");
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE") {
if which(&komorebi_ahk_exe).is_ok() {
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE")
&& which(&komorebi_ahk_exe).is_ok() {
ahk = komorebi_ahk_exe;
}
}
ahk
};

View File

@@ -233,10 +233,10 @@ fn main() -> Result<()> {
if matched_procs.len() > 1 {
let mut len = matched_procs.len();
for proc in matched_procs {
if let Some(executable_path) = proc.exe() {
if executable_path.to_string_lossy().contains("shims") {
len -= 1;
}
if let Some(executable_path) = proc.exe()
&& executable_path.to_string_lossy().contains("shims")
{
len -= 1;
}
}

View File

@@ -100,12 +100,12 @@ where
}
for d in &all_displays {
if let Some(id) = &d.serial_number_id {
if serial_id_map.get(id).copied().unwrap_or_default() > 1 {
let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write();
if !dupes.contains(id) {
(*dupes).push(id.clone());
}
if let Some(id) = &d.serial_number_id
&& serial_id_map.get(id).copied().unwrap_or_default() > 1
{
let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write();
if !dupes.contains(id) {
(*dupes).push(id.clone());
}
}
}
@@ -221,17 +221,17 @@ where
let mut should_update = false;
// Update work areas as necessary
if let Ok(reference) = WindowsApi::monitor(monitor.id) {
if reference.work_area_size != monitor.work_area_size {
monitor.work_area_size = Rect {
left: reference.work_area_size.left,
top: reference.work_area_size.top,
right: reference.work_area_size.right,
bottom: reference.work_area_size.bottom,
};
if let Ok(reference) = WindowsApi::monitor(monitor.id)
&& reference.work_area_size != monitor.work_area_size
{
monitor.work_area_size = Rect {
left: reference.work_area_size.left,
top: reference.work_area_size.top,
right: reference.work_area_size.right,
bottom: reference.work_area_size.bottom,
};
should_update = true;
}
should_update = true;
}
if should_update {

View File

@@ -195,16 +195,15 @@ impl WindowManager {
message: SocketMessage,
mut reply: impl std::io::Write,
) -> Result<()> {
if let Some(virtual_desktop_id) = &self.virtual_desktop_id {
if let Some(id) = current_virtual_desktop() {
if id != *virtual_desktop_id {
tracing::info!(
"ignoring events and commands while not on virtual desktop {:?}",
virtual_desktop_id
);
return Ok(());
}
}
if let Some(virtual_desktop_id) = &self.virtual_desktop_id
&& let Some(id) = current_virtual_desktop()
&& id != *virtual_desktop_id
{
tracing::info!(
"ignoring events and commands while not on virtual desktop {:?}",
virtual_desktop_id
);
return Ok(());
}
#[allow(clippy::useless_asref)]
@@ -532,10 +531,10 @@ impl WindowManager {
let mut should_push = true;
for m in &*manage_identifiers {
if let MatchingRule::Simple(m) = m {
if m.id.eq(id) {
should_push = false;
}
if let MatchingRule::Simple(m) = m
&& m.id.eq(id)
{
should_push = false;
}
}
@@ -599,10 +598,10 @@ impl WindowManager {
let mut should_push = true;
for i in &*ignore_identifiers {
if let MatchingRule::Simple(i) = i {
if i.id.eq(id) {
should_push = false;
}
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
@@ -692,16 +691,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let idx = self
@@ -709,10 +705,10 @@ impl WindowManager {
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() {
if let Some(last_focused_workspace) = monitor.last_focused_workspace {
self.move_container_to_workspace(last_focused_workspace, true, None)?;
}
if let Some(monitor) = self.focused_monitor_mut()
&& let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.move_container_to_workspace(last_focused_workspace, true, None)?;
}
self.focused_monitor_mut()
@@ -723,16 +719,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let idx = self
@@ -740,10 +733,10 @@ impl WindowManager {
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() {
if let Some(last_focused_workspace) = monitor.last_focused_workspace {
self.move_container_to_workspace(last_focused_workspace, false, None)?;
}
if let Some(monitor) = self.focused_monitor_mut()
&& let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.move_container_to_workspace(last_focused_workspace, false, None)?;
}
self.focused_monitor_mut()
.ok_or_eyre("there is no monitor")?
@@ -1038,16 +1031,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
@@ -1067,16 +1057,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let focused_monitor = self.focused_monitor().ok_or_eyre("there is no monitor")?;
@@ -1114,16 +1101,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let mut can_close = false;
@@ -1132,16 +1116,15 @@ impl WindowManager {
let focused_workspace_idx = monitor.focused_workspace_idx();
let next_focused_workspace_idx = focused_workspace_idx.saturating_sub(1);
if let Some(workspace) = monitor.focused_workspace() {
if monitor.workspaces().len() > 1
&& workspace.containers().is_empty()
&& workspace.floating_windows().is_empty()
&& workspace.monocle_container.is_none()
&& workspace.maximized_window.is_none()
&& workspace.name.is_none()
{
can_close = true;
}
if let Some(workspace) = monitor.focused_workspace()
&& monitor.workspaces().len() > 1
&& workspace.containers().is_empty()
&& workspace.floating_windows().is_empty()
&& workspace.monocle_container.is_none()
&& workspace.maximized_window.is_none()
&& workspace.name.is_none()
{
can_close = true;
}
if can_close
@@ -1158,16 +1141,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let idx = self
@@ -1175,10 +1155,10 @@ impl WindowManager {
.ok_or_eyre("there is no monitor")?
.focused_workspace_idx();
if let Some(monitor) = self.focused_monitor_mut() {
if let Some(last_focused_workspace) = monitor.last_focused_workspace {
self.focus_workspace(last_focused_workspace)?;
}
if let Some(monitor) = self.focused_monitor_mut()
&& let Some(last_focused_workspace) = monitor.last_focused_workspace
{
self.focus_workspace(last_focused_workspace)?;
}
self.focused_monitor_mut()
@@ -1189,16 +1169,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
if self.focused_workspace_idx().unwrap_or_default() != workspace_idx {
@@ -1209,16 +1186,13 @@ impl WindowManager {
// 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
// the workspace switch op
if let Some(monitor_idx) = self.monitor_idx_from_current_pos() {
if monitor_idx != self.focused_monitor_idx() {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.focused_workspace() {
if workspace.is_empty() {
self.focus_monitor(monitor_idx)?;
}
}
}
}
if let Some(monitor_idx) = self.monitor_idx_from_current_pos()
&& monitor_idx != self.focused_monitor_idx()
&& let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.focused_workspace()
&& workspace.is_empty()
{
self.focus_monitor(monitor_idx)?;
}
let focused_monitor_idx = self.focused_monitor_idx();
@@ -1297,10 +1271,10 @@ impl WindowManager {
}
}
if let Some(monocle) = &workspace.monocle_container {
if let Some(window) = monocle.focused_window() {
window.lower()?;
}
if let Some(monocle) = &workspace.monocle_container
&& let Some(window) = monocle.focused_window()
{
window.lower()?;
}
}
WorkspaceLayer::Floating => {
@@ -1515,17 +1489,15 @@ impl WindowManager {
}
} else {
for rule in &mut workspace.layout_rules {
if container_len >= rule.0 {
if let Layout::Custom(ref mut custom) = rule.1 {
match sizing {
Sizing::Increase => {
custom
.set_primary_width_percentage(percentage + 5.0);
}
Sizing::Decrease => {
custom
.set_primary_width_percentage(percentage - 5.0);
}
if container_len >= rule.0
&& let Layout::Custom(ref mut custom) = rule.1
{
match sizing {
Sizing::Increase => {
custom.set_primary_width_percentage(percentage + 5.0);
}
Sizing::Decrease => {
custom.set_primary_width_percentage(percentage - 5.0);
}
}
}
@@ -1807,10 +1779,10 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut should_push = true;
for i in &*identifiers {
if let MatchingRule::Simple(i) = i {
if i.id.eq(id) {
should_push = false;
}
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
@@ -1826,10 +1798,10 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut identifiers = TRAY_AND_MULTI_WINDOW_IDENTIFIERS.lock();
let mut should_push = true;
for i in &*identifiers {
if let MatchingRule::Simple(i) = i {
if i.id.eq(id) {
should_push = false;
}
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
@@ -1846,10 +1818,10 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut should_push = true;
for i in &*identifiers {
if let MatchingRule::Simple(i) = i {
if i.id.eq(id) {
should_push = false;
}
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
@@ -1879,11 +1851,11 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
}
}
SocketMessage::WorkspaceWorkAreaOffset(monitor_idx, workspace_idx, rect) => {
if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx) {
if let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx) {
workspace.work_area_offset = Option::from(rect);
self.retile_all(false)?
}
if let Some(monitor) = self.monitors_mut().get_mut(monitor_idx)
&& let Some(workspace) = monitor.workspaces_mut().get_mut(workspace_idx)
{
workspace.work_area_offset = Option::from(rect);
self.retile_all(false)?
}
}
SocketMessage::ToggleWindowBasedWorkAreaOffset => {
@@ -2251,10 +2223,10 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
let mut should_push = true;
for i in &*identifiers {
if let MatchingRule::Simple(i) = i {
if i.id.eq(id) {
should_push = false;
}
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}

View File

@@ -207,12 +207,11 @@ impl WindowManager {
//
// 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.
if let Ok(class) = window.class() {
if class != "OleMainThreadWndClass"
&& self.focused_monitor_idx() != monitor_idx
{
self.focus_monitor(monitor_idx)?;
}
if let Ok(class) = window.class()
&& class != "OleMainThreadWndClass"
&& self.focused_monitor_idx() != monitor_idx
{
self.focus_monitor(monitor_idx)?;
}
}
}
@@ -323,10 +322,10 @@ impl WindowManager {
match floating_window_idx {
None => {
if let Some(w) = &workspace.maximized_window {
if w.hwnd == window.hwnd {
return Ok(());
}
if let Some(w) = &workspace.maximized_window
&& w.hwnd == window.hwnd
{
return Ok(());
}
if let Some(monocle) = &workspace.monocle_container {
@@ -393,23 +392,20 @@ impl WindowManager {
}
}
if let Some((m_idx, w_idx)) = self.known_hwnds.get(&window.hwnd) {
if let Some(focused_workspace_idx) = self
if let Some((m_idx, w_idx)) = self.known_hwnds.get(&window.hwnd)
&& let Some(focused_workspace_idx) = self
.monitors()
.get(*m_idx)
.map(|m| m.focused_workspace_idx())
{
if *m_idx != self.focused_monitor_idx()
&& *w_idx != focused_workspace_idx
{
tracing::debug!(
"ignoring show event for window already associated with another workspace"
);
&& *m_idx != self.focused_monitor_idx()
&& *w_idx != focused_workspace_idx
{
tracing::debug!(
"ignoring show event for window already associated with another workspace"
);
window.hide();
proceed = false;
}
}
window.hide();
proceed = false;
}
if proceed {
@@ -508,12 +504,11 @@ impl WindowManager {
if workspace_contains_window {
let mut monocle_window_event = false;
if let Some(ref monocle) = monocle_container {
if let Some(monocle_window) = monocle.focused_window() {
if monocle_window.hwnd == window.hwnd {
monocle_window_event = true;
}
}
if let Some(ref monocle) = monocle_container
&& let Some(monocle_window) = monocle.focused_window()
&& monocle_window.hwnd == window.hwnd
{
monocle_window_event = true;
}
let workspace = self.focused_workspace()?;
@@ -548,14 +543,14 @@ impl WindowManager {
// 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.
if let Some((_, _, w_hwnd)) = pending {
if w_hwnd != window.hwnd {
color_eyre::eyre::bail!(
"window handles for move operation don't match: {} != {}",
w_hwnd,
window.hwnd
);
}
if let Some((_, _, w_hwnd)) = pending
&& w_hwnd != window.hwnd
{
color_eyre::eyre::bail!(
"window handles for move operation don't match: {} != {}",
w_hwnd,
window.hwnd
);
}
let target_monitor_idx = self
@@ -583,10 +578,10 @@ impl WindowManager {
// This will be true if we have moved to another monitor
let mut moved_across_monitors = false;
if let Some((m_idx, _)) = self.known_hwnds.get(&window.hwnd) {
if *m_idx != target_monitor_idx {
moved_across_monitors = true;
}
if let Some((m_idx, _)) = self.known_hwnds.get(&window.hwnd)
&& *m_idx != target_monitor_idx
{
moved_across_monitors = true;
}
if let Some((origin_monitor_idx, origin_workspace_idx, _)) = pending {
@@ -848,13 +843,12 @@ impl WindowManager {
if let Some(target_container) =
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!(
"Needs reconciliation within a stack on the focused workspace"
);
needs_reconciliation = Some((*m_idx, *ws_idx));
}
tracing::debug!(
"Needs reconciliation within a stack on the focused workspace"
);
needs_reconciliation = Some((*m_idx, *ws_idx));
}
}
}

View File

@@ -353,16 +353,15 @@ impl Stackbar {
// 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
// tile
if index != focused_window_idx {
if let Err(err) =
if index != focused_window_idx
&& let Err(err) =
window.set_position(&focused_window_rect, false)
{
tracing::error!(
"stackbar WM_LBUTTONDOWN repositioning error: hwnd {} ({})",
*window,
err
);
}
{
tracing::error!(
"stackbar WM_LBUTTONDOWN repositioning error: hwnd {} ({})",
*window,
err
);
}
// Restore the window corresponding to the tab we have clicked

View File

@@ -1367,12 +1367,12 @@ impl StaticConfig {
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
let preferred_config_idx = {
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.device_id.eq(id))
.then_some(*c_idx)
});
c_idx
})
};
let idx = preferred_config_idx.or({
// Monitor without preferred config idx.
@@ -1538,12 +1538,12 @@ impl StaticConfig {
for (i, monitor) in wm.monitors_mut().iter_mut().enumerate() {
let preferred_config_idx = {
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.device_id.eq(id))
.then_some(*c_idx)
});
c_idx
})
};
let idx = preferred_config_idx.or({
// Monitor without preferred config idx.

View File

@@ -152,25 +152,25 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
for (window_idx, window) in c.windows().iter().enumerate() {
if window_idx == focused_window_idx {
let mut should_make_transparent = true;
if !transparency_blacklist.is_empty() {
if let (Ok(title), Ok(exe_name), Ok(class), Ok(path)) = (
if !transparency_blacklist.is_empty()
&& let (Ok(title), Ok(exe_name), Ok(class), Ok(path)) = (
window.title(),
window.exe(),
window.class(),
window.path(),
) {
let is_blacklisted = should_act(
&title,
&exe_name,
&class,
&path,
&transparency_blacklist,
&regex_identifiers,
)
.is_some();
)
{
let is_blacklisted = should_act(
&title,
&exe_name,
&class,
&path,
&transparency_blacklist,
&regex_identifiers,
)
.is_some();
should_make_transparent = !is_blacklisted;
}
should_make_transparent = !is_blacklisted;
}
if should_make_transparent {

View File

@@ -568,15 +568,15 @@ impl Window {
pub fn focus(self, mouse_follows_focus: bool) -> Result<()> {
// If the target window is already focused, do nothing.
if let Ok(ihwnd) = WindowsApi::foreground_window() {
if ihwnd == self.hwnd {
// Center cursor in Window
if mouse_follows_focus {
WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(self.hwnd)?)?;
}
return Ok(());
if let Ok(ihwnd) = WindowsApi::foreground_window()
&& ihwnd == self.hwnd
{
// Center cursor in Window
if mouse_follows_focus {
WindowsApi::center_cursor_in_rect(&WindowsApi::window_rect(self.hwnd)?)?;
}
return Ok(());
}
WindowsApi::raise_and_focus_window(self.hwnd)?;
@@ -817,13 +817,13 @@ impl Window {
let mut allow_cloaked = false;
if let Some(event) = event {
if matches!(
if let Some(event) = event
&& matches!(
event,
WindowManagerEvent::Hide(_, _) | WindowManagerEvent::Cloak(_, _)
) {
allow_cloaked = true;
}
)
{
allow_cloaked = true;
}
debug.allow_cloaked = allow_cloaked;
@@ -1302,31 +1302,31 @@ pub fn should_act_individual(
},
Some(MatchingStrategy::Regex) => match identifier.kind {
ApplicationIdentifier::Title => {
if let Some(re) = regex_identifiers.get(&identifier.id) {
if re.is_match(title) {
should_act = true;
}
if let Some(re) = regex_identifiers.get(&identifier.id)
&& re.is_match(title)
{
should_act = true;
}
}
ApplicationIdentifier::Class => {
if let Some(re) = regex_identifiers.get(&identifier.id) {
if re.is_match(class) {
should_act = true;
}
if let Some(re) = regex_identifiers.get(&identifier.id)
&& re.is_match(class)
{
should_act = true;
}
}
ApplicationIdentifier::Exe => {
if let Some(re) = regex_identifiers.get(&identifier.id) {
if re.is_match(exe_name) {
should_act = true;
}
if let Some(re) = regex_identifiers.get(&identifier.id)
&& re.is_match(exe_name)
{
should_act = true;
}
}
ApplicationIdentifier::Path => {
if let Some(re) = regex_identifiers.get(&identifier.id) {
if re.is_match(path) {
should_act = true;
}
if let Some(re) = regex_identifiers.get(&identifier.id)
&& re.is_match(path)
{
should_act = true;
}
}
},

View File

@@ -486,11 +486,11 @@ impl WindowManager {
}
}
if let Some(window) = workspace.maximized_window {
if window.exe().is_err() {
can_apply = false;
break;
}
if let Some(window) = workspace.maximized_window
&& window.exe().is_err()
{
can_apply = false;
break;
}
if let Some(container) = &workspace.monocle_container {
@@ -522,21 +522,20 @@ impl WindowManager {
for (monitor_idx, monitor) in self.monitors_mut().iter_mut().enumerate() {
let mut focused_workspace = 0;
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_workspace) = state_monitor.workspaces().get(workspace_idx)
{
// to make sure padding changes get applied for users after a quick restart
let container_padding = workspace.container_padding;
let workspace_padding = workspace.workspace_padding;
if let Some(state_monitor) = state.monitors.elements().get(monitor_idx)
&& let Some(state_workspace) = state_monitor.workspaces().get(workspace_idx)
{
// to make sure padding changes get applied for users after a quick restart
let container_padding = workspace.container_padding;
let workspace_padding = workspace.workspace_padding;
*workspace = state_workspace.clone();
*workspace = state_workspace.clone();
workspace.container_padding = container_padding;
workspace.workspace_padding = workspace_padding;
workspace.container_padding = container_padding;
workspace.workspace_padding = workspace_padding;
if state_monitor.focused_workspace_idx() == workspace_idx {
focused_workspace = workspace_idx;
}
if state_monitor.focused_workspace_idx() == workspace_idx {
focused_workspace = workspace_idx;
}
}
}
@@ -622,66 +621,61 @@ impl WindowManager {
monitor_idx: usize,
workspace_idx: usize,
) -> WindowManagementBehaviour {
if let Some(monitor) = self.monitors().get(monitor_idx) {
if let Some(workspace) = monitor.workspaces().get(workspace_idx) {
let current_behaviour =
if let Some(behaviour) = workspace.window_container_behaviour {
if workspace.containers().is_empty()
&& matches!(behaviour, WindowContainerBehaviour::Append)
{
// You can't append to an empty workspace
WindowContainerBehaviour::Create
} else {
behaviour
}
} else if workspace.containers().is_empty()
&& matches!(
self.window_management_behaviour.current_behaviour,
WindowContainerBehaviour::Append
)
{
// You can't append to an empty workspace
WindowContainerBehaviour::Create
} else {
self.window_management_behaviour.current_behaviour
};
let float_override = if let Some(float_override) = workspace.float_override {
float_override
if let Some(monitor) = self.monitors().get(monitor_idx)
&& let Some(workspace) = monitor.workspaces().get(workspace_idx)
{
let current_behaviour = if let Some(behaviour) = workspace.window_container_behaviour {
if workspace.containers().is_empty()
&& matches!(behaviour, WindowContainerBehaviour::Append)
{
// You can't append to an empty workspace
WindowContainerBehaviour::Create
} else {
self.window_management_behaviour.float_override
behaviour
}
} else if workspace.containers().is_empty()
&& matches!(
self.window_management_behaviour.current_behaviour,
WindowContainerBehaviour::Append
)
{
// You can't append to an empty workspace
WindowContainerBehaviour::Create
} else {
self.window_management_behaviour.current_behaviour
};
let float_override = if let Some(float_override) = workspace.float_override {
float_override
} else {
self.window_management_behaviour.float_override
};
let floating_layer_behaviour =
if let Some(behaviour) = workspace.floating_layer_behaviour {
behaviour
} else {
monitor
.floating_layer_behaviour
.unwrap_or(self.window_management_behaviour.floating_layer_behaviour)
};
let floating_layer_behaviour =
if let Some(behaviour) = workspace.floating_layer_behaviour {
behaviour
} else {
monitor
.floating_layer_behaviour
.unwrap_or(self.window_management_behaviour.floating_layer_behaviour)
};
// If the workspace layer is `Floating` and the floating layer behaviour should
// float then change floating_layer_override to true so that new windows spawn
// as floating
let floating_layer_override = matches!(workspace.layer, WorkspaceLayer::Floating)
&& floating_layer_behaviour.should_float();
// If the workspace layer is `Floating` and the floating layer behaviour should
// float then change floating_layer_override to true so that new windows spawn
// as floating
let floating_layer_override = matches!(workspace.layer, WorkspaceLayer::Floating)
&& floating_layer_behaviour.should_float();
return WindowManagementBehaviour {
current_behaviour,
float_override,
floating_layer_override,
floating_layer_behaviour,
toggle_float_placement: self.window_management_behaviour.toggle_float_placement,
floating_layer_placement: self
.window_management_behaviour
.floating_layer_placement,
float_override_placement: self
.window_management_behaviour
.float_override_placement,
float_rule_placement: self.window_management_behaviour.float_rule_placement,
};
}
return WindowManagementBehaviour {
current_behaviour,
float_override,
floating_layer_override,
floating_layer_behaviour,
toggle_float_placement: self.window_management_behaviour.toggle_float_placement,
floating_layer_placement: self.window_management_behaviour.floating_layer_placement,
float_override_placement: self.window_management_behaviour.float_override_placement,
float_rule_placement: self.window_management_behaviour.float_rule_placement,
};
}
WindowManagementBehaviour {
@@ -1049,10 +1043,10 @@ impl WindowManager {
}
}
if workspace.wallpaper.is_some() || monitor_wp.is_some() {
if let Err(error) = workspace.apply_wallpaper(hmonitor, &monitor_wp) {
tracing::error!("failed to apply wallpaper: {}", error);
}
if (workspace.wallpaper.is_some() || monitor_wp.is_some())
&& let Err(error) = workspace.apply_wallpaper(hmonitor, &monitor_wp)
{
tracing::error!("failed to apply wallpaper: {}", error);
}
workspace.update()?;
@@ -1081,24 +1075,22 @@ impl WindowManager {
let workspace = self.focused_workspace()?;
// first check the focused workspace
if let Some(container_idx) = workspace.container_idx_from_current_point() {
if let Some(container) = workspace.containers().get(container_idx) {
if let Some(window) = container.focused_window() {
hwnd = Some(window.hwnd);
}
}
if let Some(container_idx) = workspace.container_idx_from_current_point()
&& let Some(container) = workspace.containers().get(container_idx)
&& let Some(window) = container.focused_window()
{
hwnd = Some(window.hwnd);
}
// then check all workspaces
if hwnd.is_none() {
for monitor in self.monitors() {
for ws in monitor.workspaces() {
if let Some(container_idx) = ws.container_idx_from_current_point() {
if let Some(container) = ws.containers().get(container_idx) {
if let Some(window) = container.focused_window() {
hwnd = Some(window.hwnd);
}
}
if let Some(container_idx) = ws.container_idx_from_current_point()
&& let Some(container) = ws.containers().get(container_idx)
&& let Some(window) = container.focused_window()
{
hwnd = Some(window.hwnd);
}
}
}
@@ -1399,10 +1391,10 @@ impl WindowManager {
window.focus(self.mouse_follows_focus)?;
}
} else if let Some(container) = &self.focused_workspace()?.monocle_container {
if let Some(window) = container.focused_window() {
if trigger_focus {
window.focus(self.mouse_follows_focus)?;
}
if let Some(window) = container.focused_window()
&& trigger_focus
{
window.focus(self.mouse_follows_focus)?;
}
} else if let Ok(window) = self.focused_window_mut() {
if trigger_focus {
@@ -1443,12 +1435,10 @@ impl WindowManager {
&& self.focused_workspace()?.monocle_container.is_none()
// and we don't have any floating windows that should show on top
&& 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)?;
}
}
}
@@ -1889,10 +1879,10 @@ impl WindowManager {
let focused_monitor_idx = self.focused_monitor_idx();
if focused_monitor_idx == monitor_idx {
if let Some(workspace_idx) = workspace_idx {
return self.move_container_to_workspace(workspace_idx, follow, None);
}
if focused_monitor_idx == monitor_idx
&& let Some(workspace_idx) = workspace_idx
{
return self.move_container_to_workspace(workspace_idx, follow, None);
}
let offset = self.work_area_offset;
@@ -1937,11 +1927,11 @@ impl WindowManager {
.ok_or_eyre("there is no monitor")?;
let mut should_load_workspace = false;
if let Some(workspace_idx) = workspace_idx {
if workspace_idx != target_monitor.focused_workspace_idx() {
target_monitor.focus_workspace(workspace_idx)?;
should_load_workspace = true;
}
if let Some(workspace_idx) = workspace_idx
&& workspace_idx != target_monitor.focused_workspace_idx()
{
target_monitor.focus_workspace(workspace_idx)?;
should_load_workspace = true;
}
let target_workspace = target_monitor
.focused_workspace_mut()
@@ -1979,12 +1969,12 @@ impl WindowManager {
target_monitor.add_container(container, workspace_idx)?;
}
if let Some(workspace) = target_monitor.focused_workspace() {
if !workspace.tile {
for hwnd in container_hwnds {
Window::from(hwnd)
.move_to_area(&current_area, &target_monitor.work_area_size)?;
}
if let Some(workspace) = target_monitor.focused_workspace()
&& !workspace.tile
{
for hwnd in container_hwnds {
Window::from(hwnd)
.move_to_area(&current_area, &target_monitor.work_area_size)?;
}
}
} else {
@@ -2223,34 +2213,34 @@ impl WindowManager {
self.focus_workspace(next_idx)?;
if let Ok(focused_workspace) = self.focused_workspace_mut() {
if focused_workspace.monocle_container.is_none() {
match direction {
OperationDirection::Left => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.rightmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(
focused_workspace.containers().len().saturating_sub(1),
);
}
},
OperationDirection::Right => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.leftmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(0);
}
},
_ => {}
};
}
if let Ok(focused_workspace) = self.focused_workspace_mut()
&& focused_workspace.monocle_container.is_none()
{
match direction {
OperationDirection::Left => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.rightmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(
focused_workspace.containers().len().saturating_sub(1),
);
}
},
OperationDirection::Right => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.leftmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(0);
}
},
_ => {}
};
}
return Ok(());
@@ -2378,34 +2368,34 @@ impl WindowManager {
self.focus_workspace(next_idx)?;
if let Ok(focused_workspace) = self.focused_workspace_mut() {
if focused_workspace.monocle_container.is_none() {
match direction {
OperationDirection::Left => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.rightmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(
focused_workspace.containers().len().saturating_sub(1),
);
}
},
OperationDirection::Right => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.leftmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(0);
}
},
_ => {}
};
}
if let Ok(focused_workspace) = self.focused_workspace_mut()
&& focused_workspace.monocle_container.is_none()
{
match direction {
OperationDirection::Left => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.rightmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(
focused_workspace.containers().len().saturating_sub(1),
);
}
},
OperationDirection::Right => match focused_workspace.layout {
Layout::Default(layout) => {
let target_index =
layout.leftmost_index(focused_workspace.containers().len());
focused_workspace.focus_container(target_index);
}
Layout::Custom(_) => {
focused_workspace.focus_container(0);
}
},
_ => {}
};
}
return Ok(());
@@ -2652,10 +2642,10 @@ impl WindowManager {
// unset monocle container on target workspace if there is one
let mut target_workspace_has_monocle = false;
if let Ok(target_workspace) = self.focused_workspace() {
if target_workspace.monocle_container.is_some() {
target_workspace_has_monocle = true;
}
if let Ok(target_workspace) = self.focused_workspace()
&& target_workspace.monocle_container.is_some()
{
target_workspace_has_monocle = true;
}
if target_workspace_has_monocle {
@@ -2782,10 +2772,10 @@ impl WindowManager {
}
}
if let Some(idx) = target_idx {
if let Some(window) = focused_workspace.floating_windows().get(idx) {
window.focus(mouse_follows_focus)?;
}
if let Some(idx) = target_idx
&& let Some(window) = focused_workspace.floating_windows().get(idx)
{
window.focus(mouse_follows_focus)?;
}
Ok(())
@@ -2962,10 +2952,10 @@ impl WindowManager {
let workspace = self.focused_workspace_mut()?;
let mut focused_hwnd = None;
if let Some(container) = workspace.focused_container() {
if let Some(window) = container.focused_window() {
focused_hwnd = Some(window.hwnd);
}
if let Some(container) = workspace.focused_container()
&& let Some(window) = container.focused_window()
{
focused_hwnd = Some(window.hwnd);
}
workspace.focus_container(workspace.containers().len().saturating_sub(1));
@@ -2989,10 +2979,10 @@ impl WindowManager {
let workspace = self.focused_workspace_mut()?;
let mut focused_hwnd = None;
if let Some(container) = workspace.focused_container() {
if let Some(window) = container.focused_window() {
focused_hwnd = Some(window.hwnd);
}
if let Some(container) = workspace.focused_container()
&& let Some(window) = container.focused_window()
{
focused_hwnd = Some(window.hwnd);
}
let initial_focused_container_index = workspace.focused_container_idx();
@@ -3061,10 +3051,10 @@ impl WindowManager {
let mut target_container_is_stack = false;
if let Some(container) = workspace.containers().get(adjusted_new_index) {
if container.windows().len() > 1 {
target_container_is_stack = true;
}
if let Some(container) = workspace.containers().get(adjusted_new_index)
&& container.windows().len() > 1
{
target_container_is_stack = true;
}
if let Some(current) = workspace.focused_container() {
@@ -3077,12 +3067,10 @@ impl WindowManager {
}
}
if changed_focus {
if let Some(container) = workspace.focused_container_mut() {
container.load_focused_window();
if let Some(window) = container.focused_window() {
window.focus(self.mouse_follows_focus)?;
}
if changed_focus && let Some(container) = workspace.focused_container_mut() {
container.load_focused_window();
if let Some(window) = container.focused_window() {
window.focus(self.mouse_follows_focus)?;
}
}
@@ -3929,10 +3917,10 @@ impl WindowManager {
for (monitor_idx, monitor) in self.monitors().iter().enumerate() {
for (workspace_idx, workspace) in monitor.workspaces().iter().enumerate() {
if let Some(workspace_name) = &workspace.name {
if workspace_name == name {
return Option::from((monitor_idx, workspace_idx));
}
if let Some(workspace_name) = &workspace.name
&& workspace_name == name
{
return Option::from((monitor_idx, workspace_idx));
}
}
}

View File

@@ -282,12 +282,12 @@ impl WindowsApi {
}
for d in &all_displays {
if let Some(id) = &d.serial_number_id {
if serial_id_map.get(id).copied().unwrap_or_default() > 1 {
let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write();
if !dupes.contains(id) {
(*dupes).push(id.clone());
}
if let Some(id) = &d.serial_number_id
&& serial_id_map.get(id).copied().unwrap_or_default() > 1
{
let mut dupes = DUPLICATE_MONITOR_SERIAL_IDS.write();
if !dupes.contains(id) {
(*dupes).push(id.clone());
}
}
}

View File

@@ -33,16 +33,16 @@ pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
if is_visible && is_window && !is_minimized {
let window = Window::from(hwnd);
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
if should_manage {
if is_maximized {
WindowsApi::restore_window(window.hwnd);
}
let mut container = Container::default();
container.windows_mut().push_back(window);
containers.push_back(container);
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default())
&& should_manage
{
if is_maximized {
WindowsApi::restore_window(window.hwnd);
}
let mut container = Container::default();
container.windows_mut().push_back(window);
containers.push_back(container);
}
}
@@ -59,10 +59,10 @@ pub extern "system" fn alt_tab_windows(hwnd: HWND, lparam: LPARAM) -> BOOL {
if is_visible && is_window && !is_minimized {
let window = Window::from(hwnd);
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
if should_manage {
windows.push(window);
}
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default())
&& should_manage
{
windows.push(window);
}
}

View File

@@ -238,12 +238,11 @@ impl Workspace {
for window in self.floating_windows_mut().iter_mut().rev() {
let mut should_hide = omit.is_none();
if !should_hide {
if let Some(omit) = omit {
if omit != window.hwnd {
should_hide = true
}
}
if !should_hide
&& let Some(omit) = omit
&& omit != window.hwnd
{
should_hide = true
}
if should_hide {
@@ -386,22 +385,22 @@ impl Workspace {
hmonitor: isize,
monitor_wp: &Option<Wallpaper>,
) -> Result<()> {
if let Some(container) = &self.monocle_container {
if let Some(window) = container.focused_window() {
container.restore();
window.focus(mouse_follows_focus)?;
return self.apply_wallpaper(hmonitor, monitor_wp);
}
if let Some(container) = &self.monocle_container
&& let Some(window) = container.focused_window()
{
container.restore();
window.focus(mouse_follows_focus)?;
return self.apply_wallpaper(hmonitor, monitor_wp);
}
let idx = self.focused_container_idx();
let mut to_focus = None;
for (i, container) in self.containers_mut().iter_mut().enumerate() {
if let Some(window) = container.focused_window_mut() {
if idx == i {
to_focus = Option::from(*window);
}
if let Some(window) = container.focused_window_mut()
&& idx == i
{
to_focus = Option::from(*window);
}
container.restore();
@@ -665,10 +664,10 @@ impl Workspace {
let point = WindowsApi::cursor_pos().ok()?;
for (i, _container) in self.containers().iter().enumerate() {
if let Some(rect) = self.latest_layout.get(i) {
if rect.contains_point((point.x, point.y)) {
idx = Option::from(i);
}
if let Some(rect) = self.latest_layout.get(i)
&& rect.contains_point((point.x, point.y))
{
idx = Option::from(i);
}
}
@@ -682,25 +681,24 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
return Option::from(window.hwnd);
}
}
if let Some(window) = self.maximized_window
&& let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Option::from(window.hwnd);
}
if let Some(container) = &self.monocle_container {
if let Some(hwnd) = container.hwnd_from_exe(exe) {
return Option::from(hwnd);
}
if let Some(container) = &self.monocle_container
&& let Some(hwnd) = container.hwnd_from_exe(exe)
{
return Option::from(hwnd);
}
for window in self.floating_windows() {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
return Option::from(window.hwnd);
}
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Option::from(window.hwnd);
}
}
@@ -717,25 +715,24 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
return Some(WorkspaceWindowLocation::Maximized);
}
}
if let Some(window) = self.maximized_window
&& let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Some(WorkspaceWindowLocation::Maximized);
}
if let Some(container) = &self.monocle_container {
if let Some(window_idx) = container.idx_from_exe(exe) {
return Some(WorkspaceWindowLocation::Monocle(window_idx));
}
if let Some(container) = &self.monocle_container
&& let Some(window_idx) = container.idx_from_exe(exe)
{
return Some(WorkspaceWindowLocation::Monocle(window_idx));
}
for (window_idx, window) in self.floating_windows().iter().enumerate() {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
return Some(WorkspaceWindowLocation::Floating(window_idx));
}
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Some(WorkspaceWindowLocation::Floating(window_idx));
}
}
@@ -749,16 +746,16 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if hwnd == window.hwnd {
return true;
}
if let Some(window) = self.maximized_window
&& hwnd == window.hwnd
{
return true;
}
if let Some(container) = &self.monocle_container {
if container.contains_window(hwnd) {
return true;
}
if let Some(container) = &self.monocle_container
&& container.contains_window(hwnd)
{
return true;
}
false
@@ -766,16 +763,16 @@ impl Workspace {
pub fn is_focused_window_monocle_or_maximized(&self) -> Result<bool> {
let hwnd = WindowsApi::foreground_window()?;
if let Some(window) = self.maximized_window {
if hwnd == window.hwnd {
return Ok(true);
}
if let Some(window) = self.maximized_window
&& hwnd == window.hwnd
{
return Ok(true);
}
if let Some(container) = &self.monocle_container {
if container.contains_window(hwnd) {
return Ok(true);
}
if let Some(container) = &self.monocle_container
&& container.contains_window(hwnd)
{
return Ok(true);
}
Ok(false)
@@ -795,16 +792,16 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if hwnd == window.hwnd {
return true;
}
if let Some(window) = self.maximized_window
&& hwnd == window.hwnd
{
return true;
}
if let Some(container) = &self.monocle_container {
if container.contains_window(hwnd) {
return true;
}
if let Some(container) = &self.monocle_container
&& container.contains_window(hwnd)
{
return true;
}
for window in self.floating_windows() {
@@ -897,36 +894,35 @@ impl Workspace {
return Ok(());
}
if let Some(container) = &mut self.monocle_container {
if let Some(window_idx) = container
if let Some(container) = &mut self.monocle_container
&& let Some(window_idx) = container
.windows()
.iter()
.position(|window| window.hwnd == hwnd)
{
container
.remove_window_by_idx(window_idx)
.ok_or_eyre("there is no window")?;
{
container
.remove_window_by_idx(window_idx)
.ok_or_eyre("there is no window")?;
if container.windows().is_empty() {
self.monocle_container = None;
self.monocle_container_restore_idx = None;
}
for c in self.containers() {
c.restore();
}
return Ok(());
if container.windows().is_empty() {
self.monocle_container = None;
self.monocle_container_restore_idx = None;
}
for c in self.containers() {
c.restore();
}
return Ok(());
}
if let Some(window) = self.maximized_window {
if window.hwnd == hwnd {
window.unmaximize();
self.maximized_window = None;
self.maximized_window_restore_idx = None;
return Ok(());
}
if let Some(window) = self.maximized_window
&& window.hwnd == hwnd
{
window.unmaximize();
self.maximized_window = None;
self.maximized_window_restore_idx = None;
return Ok(());
}
let container_idx = self
@@ -1632,25 +1628,24 @@ impl Workspace {
pub fn visible_window_details(&self) -> Vec<WindowDetails> {
let mut vec: Vec<WindowDetails> = vec![];
if let Some(maximized) = self.maximized_window {
if let Ok(details) = (maximized).try_into() {
vec.push(details);
}
if let Some(maximized) = self.maximized_window
&& let Ok(details) = (maximized).try_into()
{
vec.push(details);
}
if let Some(monocle) = &self.monocle_container {
if let Some(focused) = monocle.focused_window() {
if let Ok(details) = (*focused).try_into() {
vec.push(details);
}
}
if let Some(monocle) = &self.monocle_container
&& let Some(focused) = monocle.focused_window()
&& let Ok(details) = (*focused).try_into()
{
vec.push(details);
}
for container in self.containers() {
if let Some(focused) = container.focused_window() {
if let Ok(details) = (*focused).try_into() {
vec.push(details);
}
if let Some(focused) = container.focused_window()
&& let Ok(details) = (*focused).try_into()
{
vec.push(details);
}
}

View File

@@ -2182,10 +2182,10 @@ fn main() -> Result<()> {
SubCommand::Start(arg) => {
let mut ahk: String = String::from("autohotkey.exe");
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE") {
if which(&komorebi_ahk_exe).is_ok() {
ahk = komorebi_ahk_exe;
}
if let Ok(komorebi_ahk_exe) = std::env::var("KOMOREBI_AHK_EXE")
&& which(&komorebi_ahk_exe).is_ok()
{
ahk = komorebi_ahk_exe;
}
if arg.whkd && which("whkd").is_err() {
@@ -2360,33 +2360,18 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue))
komorebi_json.is_file().then_some(komorebi_json)
});
if arg.bar {
if let Some(config) = &static_config {
let mut config = StaticConfig::read(config)?;
if let Some(display_bar_configurations) = &mut config.bar_configurations {
for config_file_path in &mut *display_bar_configurations {
let script = format!(
r#"Start-Process "komorebi-bar" '"--config" "{}"' -WindowStyle hidden"#,
config_file_path.to_string_lossy()
);
if arg.bar
&& let Some(config) = &static_config
{
let mut config = StaticConfig::read(config)?;
if let Some(display_bar_configurations) = &mut config.bar_configurations {
for config_file_path in &mut *display_bar_configurations {
let script = format!(
r#"Start-Process "komorebi-bar" '"--config" "{}"' -WindowStyle hidden"#,
config_file_path.to_string_lossy()
);
match powershell_script::run(&script) {
Ok(_) => {
println!("{script}");
}
Err(error) => {
println!("Error: {error}");
}
}
}
} else {
let script = r"
if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
{
Start-Process komorebi-bar -WindowStyle hidden
}
";
match powershell_script::run(script) {
match powershell_script::run(&script) {
Ok(_) => {
println!("{script}");
}
@@ -2395,6 +2380,21 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
}
}
}
} else {
let script = r"
if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
{
Start-Process komorebi-bar -WindowStyle hidden
}
";
match powershell_script::run(script) {
Ok(_) => {
println!("{script}");
}
Err(error) => {
println!("Error: {error}");
}
}
}
}