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
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();
@@ -332,7 +332,6 @@ pub fn apply_theme(
style.visuals.widgets.open.corner_radius = rounding.into();
});
}
}
// Update RenderConfig's background_color so that widgets will have the new color
render_config.borrow_mut().background_color = *bg_color.borrow();
@@ -672,8 +671,8 @@ 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();
@@ -688,7 +687,6 @@ impl Komobar {
}
}
}
}
pub fn new(
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) {
output = None;
if let Ok(mut batteries) = self.manager.batteries() {
if let Some(Ok(first)) = batteries.nth(0) {
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 {
@@ -123,7 +124,6 @@ impl Battery {
})
}
}
}
self.last_state.clone_from(&output);
self.last_updated = now;
@@ -176,14 +176,12 @@ 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}")
}
}
});
}
}
+1 -3
View File
@@ -120,13 +120,11 @@ 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}")
}
}
});
}
}
+4 -6
View File
@@ -271,8 +271,9 @@ 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 {
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
@@ -280,7 +281,6 @@ impl Komorebi {
.show(ctx, ui, config, layout_config, workspace_idx);
}
}
}
/// 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));
}
});
if HOVEL {
if let Some(title) = &info.title {
if HOVEL && let Some(title) = &info.title {
inner_response.response.on_hover_text(title);
}
}
}
/// Renders the window title label in color, truncating if needed.
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>) {
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,
@@ -102,7 +102,6 @@ impl KomorebiLayout {
tracing::error!("could not send message to komorebi: WorkspaceLayout");
}
}
}
KomorebiLayout::Monocle => {
if komorebi_client::send_batch([
SocketMessage::FocusMonitorAtCursor,
@@ -269,8 +268,7 @@ impl KomorebiLayout {
show_options = self.on_click(&show_options, monitor_idx, workspace_idx);
}
if show_options {
if let Some(workspace_idx) = workspace_idx {
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())
@@ -285,9 +283,7 @@ impl KomorebiLayout {
KomorebiLayout::Default(
komorebi_client::DefaultLayout::RightMainVerticalStack,
),
KomorebiLayout::Default(
komorebi_client::DefaultLayout::HorizontalStack,
),
KomorebiLayout::Default(komorebi_client::DefaultLayout::HorizontalStack),
KomorebiLayout::Default(
komorebi_client::DefaultLayout::UltrawideVerticalStack,
),
@@ -320,7 +316,6 @@ impl KomorebiLayout {
}
});
}
}
});
RenderConfig::store_show_komorebi_layout_options(show_options);
+8 -10
View File
@@ -46,18 +46,19 @@ impl Media {
}
pub fn toggle(&self) {
if let Ok(session) = self.session_manager.GetCurrentSession() {
if let Ok(op) = session.TryTogglePlayPauseAsync() {
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 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}");
}
@@ -68,9 +69,6 @@ impl Media {
return format!("{artist} - {title}");
}
}
}
}
String::new()
}
+1 -3
View File
@@ -124,13 +124,11 @@ 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}")
}
}
});
}
}
+10 -14
View File
@@ -110,11 +110,11 @@ 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 {
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,8 +131,9 @@ impl Network {
activity.clear();
total_activity.clear();
if let Ok(interface) = netdev::get_default_interface() {
if let Some(friendly_name) = &interface.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);
@@ -140,10 +141,8 @@ impl Network {
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 received =
Self::to_pretty_bytes(data.received(), self.data_refresh_interval);
let transmitted = Self::to_pretty_bytes(
data.transmitted(),
self.data_refresh_interval,
@@ -157,8 +156,7 @@ impl Network {
}
if self.show_total_activity {
let total_received =
Self::to_pretty_bytes(data.total_received(), 1);
let total_received = Self::to_pretty_bytes(data.total_received(), 1);
let total_transmitted =
Self::to_pretty_bytes(data.total_transmitted(), 1);
@@ -171,7 +169,6 @@ impl Network {
}
}
}
}
self.last_state_activity.clone_from(&activity);
self.last_state_total_activity.clone_from(&total_activity);
@@ -327,12 +324,11 @@ 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}");
}
}
}
}
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)
.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",
@@ -167,7 +166,6 @@ impl BarWidget for Storage {
{
eprintln!("{error}")
}
}
});
}
}
+1 -3
View File
@@ -140,8 +140,7 @@ 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
@@ -150,7 +149,6 @@ impl BarWidget for Update {
{
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 hwnd = hwnd.0 as isize;
if let Ok(class) = WindowsApi::real_window_class_w(hwnd) {
if class.starts_with("komoborder") {
if let Ok(class) = WindowsApi::real_window_class_w(hwnd)
&& class.starts_with("komoborder")
{
hwnds.push(hwnd);
}
}
true.into()
}
@@ -392,8 +392,9 @@ 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() {
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;
@@ -450,7 +451,6 @@ impl Border {
let _ = render_target.EndDraw(None, None);
}
}
}
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;
}
if !should_process_notification {
if let Some(Notification::Update(ref previous)) = previous_notification
{
if previous.unwrap_or_default()
!= notification_hwnd.unwrap_or_default()
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
}
+10 -11
View File
@@ -45,13 +45,12 @@ 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 {
if !should_hide
&& let Some(omit) = omit
&& omit != window.hwnd
{
should_hide = true
}
}
}
if should_hide {
window.hide();
@@ -82,24 +81,24 @@ 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 {
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Option::from(window.hwnd);
}
}
}
None
}
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 {
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Option::from(idx);
}
}
}
None
}
+23 -33
View File
@@ -70,12 +70,11 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
) && let 2.. = len
{
columns_reverse(&mut layouts);
}
}
}
// treat >= column_count as scrolling
len => {
let visible_columns = area.right / column_width;
@@ -166,11 +165,10 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
) && let 2.. = len
{
columns_reverse(&mut layouts);
}
}
layouts
}
@@ -191,11 +189,10 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
) && let 2.. = len
{
rows_reverse(&mut layouts);
}
}
layouts
}
@@ -245,8 +242,8 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
) && let 2.. = len
{
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
@@ -255,16 +252,14 @@ impl Arrangement for DefaultLayout {
}
primary.left = rest[0].left + rest[0].right;
}
}
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 3.. = len {
) && let 3.. = len
{
rows_reverse(&mut layouts[1..]);
}
}
layouts
}
@@ -317,8 +312,8 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
) && let 2.. = len
{
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
@@ -327,16 +322,14 @@ impl Arrangement for DefaultLayout {
rect.left = primary.left + primary.right;
}
}
}
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 3.. = len {
) && let 3.. = len
{
rows_reverse(&mut layouts[1..]);
}
}
layouts
}
@@ -386,8 +379,8 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 2.. = len {
) && let 2.. = len
{
let (primary, rest) = layouts.split_at_mut(1);
let primary = &mut primary[0];
@@ -396,16 +389,14 @@ impl Arrangement for DefaultLayout {
}
primary.top = rest[0].top + rest[0].bottom;
}
}
if matches!(
layout_flip,
Some(Axis::Horizontal | Axis::HorizontalAndVertical)
) {
if let 3.. = len {
) && let 3.. = len
{
columns_reverse(&mut layouts[1..]);
}
}
layouts
}
@@ -513,11 +504,10 @@ impl Arrangement for DefaultLayout {
if matches!(
layout_flip,
Some(Axis::Vertical | Axis::HorizontalAndVertical)
) {
if let 4.. = len {
) && let 4.. = len
{
rows_reverse(&mut layouts[2..]);
}
}
layouts
}
@@ -782,8 +772,9 @@ 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 let Some(resize_ref) = opt
&& i > 0
{
if resize_ref.left != 0 {
#[allow(clippy::if_not_else)]
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
.iter()
+2 -3
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
};
+3 -3
View File
@@ -233,12 +233,12 @@ 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") {
if let Some(executable_path) = proc.exe()
&& executable_path.to_string_lossy().contains("shims")
{
len -= 1;
}
}
}
if len > 1 {
tracing::error!(
+6 -6
View File
@@ -100,15 +100,15 @@ 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 {
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());
}
}
}
}
Ok(all_displays
.into_iter()
@@ -221,8 +221,9 @@ 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 {
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,
@@ -232,7 +233,6 @@ where
should_update = true;
}
}
if should_update {
tracing::info!("updated work area for {}", monitor.device_id);
+92 -120
View File
@@ -195,17 +195,16 @@ 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 {
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)]
// We don't have From implemented for &mut WindowManager
@@ -532,12 +531,12 @@ impl WindowManager {
let mut should_push = true;
for m in &*manage_identifiers {
if let MatchingRule::Simple(m) = m {
if m.id.eq(id) {
if let MatchingRule::Simple(m) = m
&& m.id.eq(id)
{
should_push = false;
}
}
}
if should_push {
manage_identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -599,12 +598,12 @@ impl WindowManager {
let mut should_push = true;
for i in &*ignore_identifiers {
if let MatchingRule::Simple(i) = i {
if i.id.eq(id) {
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
}
if should_push {
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
// 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() {
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
.focused_monitor()
.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 {
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()
.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
// 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() {
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
.focused_monitor()
.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 {
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")?
.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
// 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() {
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,17 +1057,14 @@ 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() {
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,17 +1101,14 @@ 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() {
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,8 +1116,8 @@ 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
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()
@@ -1142,7 +1126,6 @@ impl WindowManager {
{
can_close = true;
}
}
if can_close
&& monitor
@@ -1158,28 +1141,25 @@ 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() {
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
.focused_monitor()
.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 {
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()
.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
// 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() {
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 {
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
// 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() {
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,12 +1271,12 @@ impl WindowManager {
}
}
if let Some(monocle) = &workspace.monocle_container {
if let Some(window) = monocle.focused_window() {
if let Some(monocle) = &workspace.monocle_container
&& let Some(window) = monocle.focused_window()
{
window.lower()?;
}
}
}
WorkspaceLayer::Floating => {
workspace.layer = WorkspaceLayer::Tiling;
@@ -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 {
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);
custom.set_primary_width_percentage(percentage + 5.0);
}
Sizing::Decrease => {
custom
.set_primary_width_percentage(percentage - 5.0);
}
custom.set_primary_width_percentage(percentage - 5.0);
}
}
}
@@ -1807,12 +1779,12 @@ 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) {
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
}
if should_push {
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 should_push = true;
for i in &*identifiers {
if let MatchingRule::Simple(i) = i {
if i.id.eq(id) {
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
}
if should_push {
identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -1846,12 +1818,12 @@ 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) {
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
}
if should_push {
identifiers.push(MatchingRule::Simple(IdWithIdentifier {
@@ -1879,13 +1851,13 @@ 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) {
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 => {
let workspace = self.focused_workspace_mut()?;
workspace.apply_window_based_work_area_offset =
@@ -2251,12 +2223,12 @@ 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) {
if let MatchingRule::Simple(i) = i
&& i.id.eq(id)
{
should_push = false;
}
}
}
if should_push {
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
// triggering monitor reconciliation is known to not be tied to a specific monitor.
if let Ok(class) = window.class() {
if class != "OleMainThreadWndClass"
if let Ok(class) = window.class()
&& class != "OleMainThreadWndClass"
&& self.focused_monitor_idx() != monitor_idx
{
self.focus_monitor(monitor_idx)?;
}
}
}
}
_ => {}
}
@@ -323,11 +322,11 @@ impl WindowManager {
match floating_window_idx {
None => {
if let Some(w) = &workspace.maximized_window {
if w.hwnd == window.hwnd {
if let Some(w) = &workspace.maximized_window
&& w.hwnd == window.hwnd
{
return Ok(());
}
}
if let Some(monocle) = &workspace.monocle_container {
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(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()
&& *m_idx != self.focused_monitor_idx()
&& *w_idx != focused_workspace_idx
{
tracing::debug!(
@@ -409,8 +407,6 @@ impl WindowManager {
window.hide();
proceed = false;
}
}
}
if proceed {
let behaviour = self.window_management_behaviour(
@@ -508,13 +504,12 @@ 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 {
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()?;
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
// is not related to this current move, if so abort this operation.
if let Some((_, _, w_hwnd)) = pending {
if 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
.monitor_idx_from_current_pos()
@@ -583,11 +578,11 @@ 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 {
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 {
// 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) =
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"
);
@@ -857,7 +852,6 @@ impl WindowManager {
}
}
}
}
} else {
tracing::debug!("Needs reconciliation for a different monitor/workspace pair");
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
// 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!(
@@ -363,7 +363,6 @@ impl Stackbar {
err
);
}
}
// Restore the window corresponding to the tab we have clicked
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() {
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.
+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() {
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,
@@ -171,7 +172,6 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
should_make_transparent = !is_blacklisted;
}
}
if should_make_transparent {
match window.transparent() {
+19 -19
View File
@@ -568,8 +568,9 @@ 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 {
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)?)?;
@@ -577,7 +578,6 @@ impl Window {
return Ok(());
}
}
WindowsApi::raise_and_focus_window(self.hwnd)?;
@@ -817,14 +817,14 @@ 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;
}
}
debug.allow_cloaked = allow_cloaked;
@@ -1302,33 +1302,33 @@ 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) {
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) {
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) {
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) {
if let Some(re) = regex_identifiers.get(&identifier.id)
&& re.is_match(path)
{
should_act = true;
}
}
}
},
}
+61 -73
View File
@@ -486,12 +486,12 @@ impl WindowManager {
}
}
if let Some(window) = workspace.maximized_window {
if window.exe().is_err() {
if let Some(window) = workspace.maximized_window
&& window.exe().is_err()
{
can_apply = false;
break;
}
}
if let Some(container) = &workspace.monocle_container {
for window in container.windows() {
@@ -522,8 +522,8 @@ 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)
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;
@@ -539,7 +539,6 @@ impl WindowManager {
}
}
}
}
if let Err(error) = monitor.focus_workspace(focused_workspace) {
tracing::warn!(
@@ -622,10 +621,10 @@ 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 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)
{
@@ -673,16 +672,11 @@ impl WindowManager {
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,
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 {
current_behaviour: WindowContainerBehaviour::Create,
@@ -1049,11 +1043,11 @@ impl WindowManager {
}
}
if workspace.wallpaper.is_some() || monitor_wp.is_some() {
if let Err(error) = workspace.apply_wallpaper(hmonitor, &monitor_wp) {
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,28 +1075,26 @@ 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() {
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() {
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);
}
}
}
}
}
}
// finally try matching the other way using a hwnd returned from the cursor pos
if hwnd.is_none() {
@@ -1399,11 +1391,11 @@ 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 {
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 {
window.focus(self.mouse_follows_focus)?;
@@ -1443,15 +1435,13 @@ 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)?;
}
}
}
}
}
Ok(())
}
@@ -1889,11 +1879,11 @@ impl WindowManager {
let focused_monitor_idx = self.focused_monitor_idx();
if focused_monitor_idx == monitor_idx {
if let Some(workspace_idx) = workspace_idx {
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;
let mouse_follows_focus = self.mouse_follows_focus;
@@ -1937,12 +1927,12 @@ 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() {
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()
.ok_or_eyre("there is no focused workspace on target monitor")?;
@@ -1979,14 +1969,14 @@ impl WindowManager {
target_monitor.add_container(container, workspace_idx)?;
}
if let Some(workspace) = target_monitor.focused_workspace() {
if !workspace.tile {
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 {
bail!("failed to find a window to move");
}
@@ -2223,8 +2213,9 @@ impl WindowManager {
self.focus_workspace(next_idx)?;
if let Ok(focused_workspace) = self.focused_workspace_mut() {
if focused_workspace.monocle_container.is_none() {
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) => {
@@ -2251,7 +2242,6 @@ impl WindowManager {
_ => {}
};
}
}
return Ok(());
}
@@ -2378,8 +2368,9 @@ impl WindowManager {
self.focus_workspace(next_idx)?;
if let Ok(focused_workspace) = self.focused_workspace_mut() {
if focused_workspace.monocle_container.is_none() {
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) => {
@@ -2406,7 +2397,6 @@ impl WindowManager {
_ => {}
};
}
}
return Ok(());
}
@@ -2652,11 +2642,11 @@ 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() {
if let Ok(target_workspace) = self.focused_workspace()
&& target_workspace.monocle_container.is_some()
{
target_workspace_has_monocle = true;
}
}
if target_workspace_has_monocle {
self.toggle_monocle()?;
@@ -2782,11 +2772,11 @@ impl WindowManager {
}
}
if let Some(idx) = target_idx {
if let Some(window) = focused_workspace.floating_windows().get(idx) {
if let Some(idx) = target_idx
&& let Some(window) = focused_workspace.floating_windows().get(idx)
{
window.focus(mouse_follows_focus)?;
}
}
Ok(())
}
@@ -2962,11 +2952,11 @@ 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() {
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));
while workspace.focused_container_idx() > 0 {
@@ -2989,11 +2979,11 @@ 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() {
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();
let mut focused_container = workspace.focused_container().cloned();
@@ -3061,11 +3051,11 @@ impl WindowManager {
let mut target_container_is_stack = false;
if let Some(container) = workspace.containers().get(adjusted_new_index) {
if container.windows().len() > 1 {
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() {
if current.windows().len() > 1 && !target_container_is_stack {
@@ -3077,14 +3067,12 @@ impl WindowManager {
}
}
if changed_focus {
if let Some(container) = workspace.focused_container_mut() {
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)?;
}
}
}
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 (workspace_idx, workspace) in monitor.workspaces().iter().enumerate() {
if let Some(workspace_name) = &workspace.name {
if workspace_name == name {
if let Some(workspace_name) = &workspace.name
&& workspace_name == name
{
return Option::from((monitor_idx, workspace_idx));
}
}
}
}
None
}
+3 -3
View File
@@ -282,15 +282,15 @@ 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 {
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());
}
}
}
}
'read: for mut display in all_displays {
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 {
let window = Window::from(hwnd);
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
if should_manage {
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default())
&& should_manage
{
if is_maximized {
WindowsApi::restore_window(window.hwnd);
}
@@ -44,7 +45,6 @@ pub extern "system" fn enum_window(hwnd: HWND, lparam: LPARAM) -> BOOL {
containers.push_back(container);
}
}
}
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 {
let window = Window::from(hwnd);
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default()) {
if should_manage {
if let Ok(should_manage) = window.should_manage(None, &mut RuleDebug::default())
&& should_manage
{
windows.push(window);
}
}
}
true.into()
}
+66 -71
View File
@@ -238,13 +238,12 @@ 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 {
if !should_hide
&& let Some(omit) = omit
&& omit != window.hwnd
{
should_hide = true
}
}
}
if should_hide {
window.hide();
@@ -386,23 +385,23 @@ impl Workspace {
hmonitor: isize,
monitor_wp: &Option<Wallpaper>,
) -> Result<()> {
if let Some(container) = &self.monocle_container {
if let Some(window) = container.focused_window() {
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 {
if let Some(window) = container.focused_window_mut()
&& idx == i
{
to_focus = Option::from(*window);
}
}
container.restore();
}
@@ -665,12 +664,12 @@ 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)) {
if let Some(rect) = self.latest_layout.get(i)
&& rect.contains_point((point.x, point.y))
{
idx = Option::from(i);
}
}
}
idx
}
@@ -682,27 +681,26 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
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) {
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 {
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Option::from(window.hwnd);
}
}
}
None
}
@@ -717,27 +715,26 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if let Ok(window_exe) = window.exe() {
if exe == window_exe {
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) {
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 {
if let Ok(window_exe) = window.exe()
&& exe == window_exe
{
return Some(WorkspaceWindowLocation::Floating(window_idx));
}
}
}
None
}
@@ -749,34 +746,34 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if hwnd == window.hwnd {
if let Some(window) = self.maximized_window
&& hwnd == window.hwnd
{
return true;
}
}
if let Some(container) = &self.monocle_container {
if container.contains_window(hwnd) {
if let Some(container) = &self.monocle_container
&& container.contains_window(hwnd)
{
return true;
}
}
false
}
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 {
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) {
if let Some(container) = &self.monocle_container
&& container.contains_window(hwnd)
{
return Ok(true);
}
}
Ok(false)
}
@@ -795,17 +792,17 @@ impl Workspace {
}
}
if let Some(window) = self.maximized_window {
if hwnd == window.hwnd {
if let Some(window) = self.maximized_window
&& hwnd == window.hwnd
{
return true;
}
}
if let Some(container) = &self.monocle_container {
if container.contains_window(hwnd) {
if let Some(container) = &self.monocle_container
&& container.contains_window(hwnd)
{
return true;
}
}
for window in self.floating_windows() {
if hwnd == window.hwnd {
@@ -897,8 +894,8 @@ 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)
@@ -918,16 +915,15 @@ impl Workspace {
return Ok(());
}
}
if let Some(window) = self.maximized_window {
if window.hwnd == hwnd {
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
.container_idx_for_window(hwnd)
@@ -1632,27 +1628,26 @@ 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() {
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() {
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() {
if let Some(focused) = container.focused_window()
&& let Ok(details) = (*focused).try_into()
{
vec.push(details);
}
}
}
for window in self.floating_windows() {
if let Ok(details) = (*window).try_into() {
+6 -6
View File
@@ -2182,11 +2182,11 @@ 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() {
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() {
bail!(
@@ -2360,8 +2360,9 @@ if (!(Get-Process whkd -ErrorAction SilentlyContinue))
komorebi_json.is_file().then_some(komorebi_json)
});
if arg.bar {
if let Some(config) = &static_config {
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 {
@@ -2396,7 +2397,6 @@ if (!(Get-Process komorebi-bar -ErrorAction SilentlyContinue))
}
}
}
}
if arg.masir {
let script = r"