Skip to content

GlazeWM is a tiling window manager for macOS and Windows inspired by i3wm.

style: add comment and import formatting

Lars Bergerfe88cada7b1f
diff --git a/packages/watcher/src/main.rs b/packages/watcher/src/main.rs
index 83f15b9f..f8f6ded7 100644
--- a/packages/watcher/src/main.rs
+++ b/packages/watcher/src/main.rs
@@ -1,6 +1,5 @@
use anyhow::{bail, Context};
use tracing::info;
-
use wm::{
cleanup::run_cleanup, common::platform::NativeWindow,
containers::ContainerDto, ipc_client::IpcClient,
diff --git a/packages/wm/src/app_command.rs b/packages/wm/src/app_command.rs
index 2ab830e2..f0c54141 100644
--- a/packages/wm/src/app_command.rs
+++ b/packages/wm/src/app_command.rs
@@ -143,7 +143,8 @@ pub enum QueryCommand {
AppMetadata,
/// Outputs the active binding modes.
BindingModes,
- /// Outputs the focused container (either a window or an empty workspace).
+ /// Outputs the focused container (either a window or an empty
+ /// workspace).
Focused,
/// Outputs all monitors.
Monitors,
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm/src/common/platform/event_listener.rs
index 02888392..f8e0cec1 100644
--- a/packages/wm/src/common/platform/event_listener.rs
+++ b/packages/wm/src/common/platform/event_listener.rs
@@ -1,12 +1,11 @@
use tokio::sync::mpsc::{self, UnboundedReceiver};
+use super::{EventWindow, NativeWindow};
use crate::{
common::Point,
user_config::{BindingModeConfig, KeybindingConfig, UserConfig},
};
-use super::{EventWindow, NativeWindow};
-
#[derive(Debug)]
pub enum PlatformEvent {
DisplaySettingsChanged,
diff --git a/packages/wm/src/common/platform/event_window.rs b/packages/wm/src/common/platform/event_window.rs
index 95430b44..ecdd24d8 100644
--- a/packages/wm/src/common/platform/event_window.rs
+++ b/packages/wm/src/common/platform/event_window.rs
@@ -30,11 +30,10 @@ use windows::Win32::{
},
};
-use crate::{common::Point, user_config::KeybindingConfig};
-
use super::{
KeyboardHook, MouseMoveEvent, Platform, PlatformEvent, WindowEventHook,
};
+use crate::{common::Point, user_config::KeybindingConfig};
/// Global instance of sender for platform events.
///
diff --git a/packages/wm/src/common/platform/keyboard_hook.rs b/packages/wm/src/common/platform/keyboard_hook.rs
index faf4a95a..f75b461d 100644
--- a/packages/wm/src/common/platform/keyboard_hook.rs
+++ b/packages/wm/src/common/platform/keyboard_hook.rs
@@ -16,9 +16,8 @@ use windows::Win32::{
},
};
-use crate::user_config::KeybindingConfig;
-
use super::PlatformEvent;
+use crate::user_config::KeybindingConfig;
/// Global instance of `KeyboardHook`.
///
@@ -356,7 +355,8 @@ impl KeyboardHook {
return false;
}
- // Invoke the callback function for the longest matching keybinding.
+ // Invoke the callback function for the longest matching
+ // keybinding.
let _ = self.event_tx.send(PlatformEvent::KeybindingTriggered(
longest_keybinding.config.clone(),
));
diff --git a/packages/wm/src/common/platform/platform.rs b/packages/wm/src/common/platform/platform.rs
index 472cd764..3a267681 100644
--- a/packages/wm/src/common/platform/platform.rs
+++ b/packages/wm/src/common/platform/platform.rs
@@ -31,12 +31,11 @@ use windows::{
},
};
-use crate::{common::Point, user_config::UserConfig};
-
use super::{
native_monitor, native_window, EventListener, NativeMonitor,
NativeWindow, SingleInstance,
};
+use crate::{common::Point, user_config::UserConfig};
pub type WindowProcedure = WNDPROC;
@@ -305,12 +304,13 @@ impl Platform {
/// Parses a command string into a program name/path and arguments. This
/// also expands any environment variables found in the command string if
- /// they are wrapped in `%` characters. If the command string is a path, a
- /// file extension is required.
+ /// they are wrapped in `%` characters. If the command string is a path,
+ /// a file extension is required.
///
/// This is similar to the `SHEvaluateSystemCommandTemplate` function. It
/// also parses program name/path and arguments, but can't handle `/` as
- /// file path delimiters and it errors for certain programs (e.g. `code`).
+ /// file path delimiters and it errors for certain programs (e.g.
+ /// `code`).
///
/// Returns a tuple containing the program name/path and arguments.
///
@@ -407,9 +407,9 @@ impl Platform {
.to_owned();
// Inlining the wide variables within the `SHELLEXECUTEINFOW` struct
- // causes issues where the pointer is dropped while `ShellExecuteExW` is
- // using it. This is likely a `windows-rs` bug, and we can avoid it by
- // keeping separate variables for the wide strings.
+ // causes issues where the pointer is dropped while `ShellExecuteExW`
+ // is using it. This is likely a `windows-rs` bug, and we can avoid
+ // it by keeping separate variables for the wide strings.
let program_wide = to_wide(&program);
let args_wide = to_wide(&args);
let home_dir_wide = to_wide(&home_dir);
diff --git a/packages/wm/src/containers/commands/attach_container.rs b/packages/wm/src/containers/commands/attach_container.rs
index 24de79de..e221e9ba 100644
--- a/packages/wm/src/containers/commands/attach_container.rs
+++ b/packages/wm/src/containers/commands/attach_container.rs
@@ -1,12 +1,11 @@
use anyhow::bail;
+use super::resize_tiling_container;
use crate::containers::{
traits::{CommonGetters, TilingSizeGetters},
Container,
};
-use super::resize_tiling_container;
-
/// Inserts a child container at the specified index.
///
/// The inserted child will be resized to fit the available space.
diff --git a/packages/wm/src/containers/commands/detach_container.rs b/packages/wm/src/containers/commands/detach_container.rs
index 857370bc..05649667 100644
--- a/packages/wm/src/containers/commands/detach_container.rs
+++ b/packages/wm/src/containers/commands/detach_container.rs
@@ -2,13 +2,12 @@ use std::collections::VecDeque;
use anyhow::Context;
+use super::flatten_split_container;
use crate::containers::{
traits::{CommonGetters, TilingSizeGetters},
Container,
};
-use super::flatten_split_container;
-
/// Removes a container from the tree.
///
/// If the container is a tiling container, the siblings will be resized to
diff --git a/packages/wm/src/containers/commands/flatten_child_split_containers.rs b/packages/wm/src/containers/commands/flatten_child_split_containers.rs
index ba239d06..ebc46113 100644
--- a/packages/wm/src/containers/commands/flatten_child_split_containers.rs
+++ b/packages/wm/src/containers/commands/flatten_child_split_containers.rs
@@ -1,10 +1,9 @@
+use super::flatten_split_container;
use crate::containers::{
traits::{CommonGetters, TilingDirectionGetters},
Container,
};
-use super::flatten_split_container;
-
/// Flattens any redundant split containers at the top-level of the given
/// parent container.
///
@@ -27,8 +26,8 @@ pub fn flatten_child_split_containers(
match tiling_children.len() {
1 => {
- // Handle case where the parent is a split container and has a single
- // split container child.
+ // Handle case where the parent is a split container and has a
+ // single split container child.
if let Some(split_child) = tiling_children[0].as_split() {
flatten_split_container(split_child.clone())?;
parent.set_tiling_direction(parent.tiling_direction().inverse());
diff --git a/packages/wm/src/containers/commands/focus_in_direction.rs b/packages/wm/src/containers/commands/focus_in_direction.rs
index ed9a0056..9e6fd7a4 100644
--- a/packages/wm/src/containers/commands/focus_in_direction.rs
+++ b/packages/wm/src/containers/commands/focus_in_direction.rs
@@ -1,5 +1,6 @@
use anyhow::Context;
+use super::set_focused_descendant;
use crate::{
common::{Direction, TilingDirection},
containers::{
@@ -11,8 +12,6 @@ use crate::{
wm_state::WmState,
};
-use super::set_focused_descendant;
-
pub fn focus_in_direction(
origin_container: Container,
direction: &Direction,
diff --git a/packages/wm/src/containers/commands/move_container_within_tree.rs b/packages/wm/src/containers/commands/move_container_within_tree.rs
index 2caf7d74..128378b9 100644
--- a/packages/wm/src/containers/commands/move_container_within_tree.rs
+++ b/packages/wm/src/containers/commands/move_container_within_tree.rs
@@ -1,5 +1,9 @@
use anyhow::Context;
+use super::{
+ attach_container, detach_container, flatten_child_split_containers,
+ set_focused_descendant,
+};
use crate::{
common::VecDequeExt,
containers::{traits::CommonGetters, Container},
@@ -7,11 +11,6 @@ use crate::{
wm_state::WmState,
};
-use super::{
- attach_container, detach_container, flatten_child_split_containers,
- set_focused_descendant,
-};
-
/// Move a container to a new location in the tree. This detaches the
/// container from its current parent and attaches it to the new parent at
/// the specified index.
diff --git a/packages/wm/src/containers/commands/replace_container.rs b/packages/wm/src/containers/commands/replace_container.rs
index cc1ae95c..0b420a01 100644
--- a/packages/wm/src/containers/commands/replace_container.rs
+++ b/packages/wm/src/containers/commands/replace_container.rs
@@ -1,5 +1,6 @@
use anyhow::{bail, Context};
+use super::{attach_container, detach_container, resize_tiling_container};
use crate::{
common::VecDequeExt,
containers::{
@@ -8,8 +9,6 @@ use crate::{
},
};
-use super::{attach_container, detach_container, resize_tiling_container};
-
/// Replaces a container at the specified index.
///
/// The replaced container will be detached from the tree.
diff --git a/packages/wm/src/containers/commands/toggle_tiling_direction.rs b/packages/wm/src/containers/commands/toggle_tiling_direction.rs
index 7f32dbdd..c4920851 100644
--- a/packages/wm/src/containers/commands/toggle_tiling_direction.rs
+++ b/packages/wm/src/containers/commands/toggle_tiling_direction.rs
@@ -1,6 +1,7 @@
use anyhow::Context;
use uuid::Uuid;
+use super::{flatten_split_container, wrap_in_split_container};
use crate::{
common::TilingDirection,
containers::{
@@ -14,8 +15,6 @@ use crate::{
workspaces::Workspace,
};
-use super::{flatten_split_container, wrap_in_split_container};
-
pub fn toggle_tiling_direction(
container: Container,
state: &mut WmState,
diff --git a/packages/wm/src/containers/container.rs b/packages/wm/src/containers/container.rs
index eb1494fa..fbb373e5 100644
--- a/packages/wm/src/containers/container.rs
+++ b/packages/wm/src/containers/container.rs
@@ -1,14 +1,13 @@
use enum_as_inner::EnumAsInner;
use enum_dispatch::enum_dispatch;
+use super::{traits::CommonGetters, RootContainer, SplitContainer};
use crate::{
monitors::Monitor,
windows::{NonTilingWindow, TilingWindow},
workspaces::Workspace,
};
-use super::{traits::CommonGetters, RootContainer, SplitContainer};
-
/// A container of any type.
#[derive(Clone, Debug, EnumAsInner)]
#[enum_dispatch(CommonGetters, PositionGetters)]
diff --git a/packages/wm/src/containers/container_dto.rs b/packages/wm/src/containers/container_dto.rs
index 16994cb0..1ee10117 100644
--- a/packages/wm/src/containers/container_dto.rs
+++ b/packages/wm/src/containers/container_dto.rs
@@ -1,11 +1,10 @@
use serde::{Deserialize, Serialize};
+use super::{RootContainerDto, SplitContainerDto};
use crate::{
monitors::MonitorDto, windows::WindowDto, workspaces::WorkspaceDto,
};
-use super::{RootContainerDto, SplitContainerDto};
-
/// User-friendly representation of a container.
///
/// Used for IPC and debug logging.
diff --git a/packages/wm/src/containers/root_container.rs b/packages/wm/src/containers/root_container.rs
index 839d352e..fb74a766 100644
--- a/packages/wm/src/containers/root_container.rs
+++ b/packages/wm/src/containers/root_container.rs
@@ -8,13 +8,12 @@ use anyhow::bail;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
-use crate::{common::Rect, impl_common_getters, impl_container_debug};
-
use super::{
traits::{CommonGetters, PositionGetters},
Container, ContainerDto, DirectionContainer, TilingContainer,
WindowContainer,
};
+use crate::{common::Rect, impl_common_getters, impl_container_debug};
/// Root node of the container tree.
#[derive(Clone)]
diff --git a/packages/wm/src/containers/split_container.rs b/packages/wm/src/containers/split_container.rs
index d4bcf754..7602b78b 100644
--- a/packages/wm/src/containers/split_container.rs
+++ b/packages/wm/src/containers/split_container.rs
@@ -8,13 +8,6 @@ use anyhow::Context;
use serde::{Deserialize, Serialize};
use uuid::Uuid;
-use crate::{
- common::{LengthValue, Rect, TilingDirection},
- impl_common_getters, impl_container_debug,
- impl_position_getters_as_resizable, impl_tiling_direction_getters,
- impl_tiling_size_getters,
-};
-
use super::{
traits::{
CommonGetters, PositionGetters, TilingDirectionGetters,
@@ -23,6 +16,12 @@ use super::{
Container, ContainerDto, DirectionContainer, TilingContainer,
WindowContainer,
};
+use crate::{
+ common::{LengthValue, Rect, TilingDirection},
+ impl_common_getters, impl_container_debug,
+ impl_position_getters_as_resizable, impl_tiling_direction_getters,
+ impl_tiling_size_getters,
+};
#[derive(Clone)]
pub struct SplitContainer(Rc<RefCell<SplitContainerInner>>);
diff --git a/packages/wm/src/containers/traits/position_getters.rs b/packages/wm/src/containers/traits/position_getters.rs
index 787a50c2..45699983 100644
--- a/packages/wm/src/containers/traits/position_getters.rs
+++ b/packages/wm/src/containers/traits/position_getters.rs
@@ -13,7 +13,7 @@ pub trait PositionGetters {
}
/// Implements the `PositionGetters` trait for tiling containers that can
-/// be resized. Specifically, this is for `SplitContainer` and `TilingWindow`.
+/// be resized. This is used by `SplitContainer` and `TilingWindow`.
///
/// Expects that the struct has a wrapping `RefCell` containing a struct
/// with an `id` and a `parent` field.
diff --git a/packages/wm/src/containers/traits/tiling_direction_getters.rs b/packages/wm/src/containers/traits/tiling_direction_getters.rs
index 38a998c3..a53867c8 100644
--- a/packages/wm/src/containers/traits/tiling_direction_getters.rs
+++ b/packages/wm/src/containers/traits/tiling_direction_getters.rs
@@ -1,13 +1,12 @@
use enum_dispatch::enum_dispatch;
+use super::CommonGetters;
use crate::{
common::{Direction, TilingDirection},
containers::{DirectionContainer, TilingContainer},
windows::TilingWindow,
};
-use super::CommonGetters;
-
#[enum_dispatch]
pub trait TilingDirectionGetters: CommonGetters {
fn tiling_direction(&self) -> TilingDirection;
diff --git a/packages/wm/src/containers/traits/tiling_size_getters.rs b/packages/wm/src/containers/traits/tiling_size_getters.rs
index 50d09bc0..13efb0dc 100644
--- a/packages/wm/src/containers/traits/tiling_size_getters.rs
+++ b/packages/wm/src/containers/traits/tiling_size_getters.rs
@@ -1,13 +1,12 @@
use anyhow::Context;
use enum_dispatch::enum_dispatch;
+use super::{CommonGetters, TilingDirectionGetters};
use crate::{
common::{LengthValue, TilingDirection},
containers::{Container, DirectionContainer, TilingContainer},
};
-use super::{CommonGetters, TilingDirectionGetters};
-
#[enum_dispatch]
pub trait TilingSizeGetters: CommonGetters {
fn tiling_size(&self) -> f32;
diff --git a/packages/wm/src/windows/commands/move_window_in_direction.rs b/packages/wm/src/windows/commands/move_window_in_direction.rs
index 5e9c4f0d..84a920bb 100644
--- a/packages/wm/src/windows/commands/move_window_in_direction.rs
+++ b/packages/wm/src/windows/commands/move_window_in_direction.rs
@@ -321,7 +321,8 @@ fn invert_workspace_tiling_direction(
// up results in H[3 H[1 2]], and needs to be flattened to H[3 1 2].
flatten_child_split_containers(workspace.clone().into())?;
- // Resize the window such that the split container and window are each 0.5.
+ // Resize the window such that the split container and window are each
+ // 0.5.
resize_tiling_container(&window_to_move.into(), 0.5);
state
@@ -384,7 +385,8 @@ fn move_floating_window(
// Mark window as needing DPI adjustment if it crosses monitors. The
// handler for `PlatformEvent::LocationChanged` will update the
- // window's workspace if it goes out of bounds of its current workspace.
+ // window's workspace if it goes out of bounds of its current
+ // workspace.
if monitor.id() != target_monitor.id()
&& monitor.has_dpi_difference(&target_monitor.into())?
{
diff --git a/packages/wm/src/windows/commands/resize_window.rs b/packages/wm/src/windows/commands/resize_window.rs
index 860f1713..a9d66587 100644
--- a/packages/wm/src/windows/commands/resize_window.rs
+++ b/packages/wm/src/windows/commands/resize_window.rs
@@ -1,5 +1,6 @@
use anyhow::Context;
+use super::set_window_size;
use crate::{
common::LengthValue,
containers::{
@@ -9,8 +10,6 @@ use crate::{
wm_state::WmState,
};
-use super::set_window_size;
-
pub fn resize_window(
window: WindowContainer,
width_delta: Option<LengthValue>,
diff --git a/packages/wm/src/windows/non_tiling_window.rs b/packages/wm/src/windows/non_tiling_window.rs
index 84c53ca9..b9396346 100644
--- a/packages/wm/src/windows/non_tiling_window.rs
+++ b/packages/wm/src/windows/non_tiling_window.rs
@@ -7,6 +7,7 @@ use std::{
use anyhow::Context;
use uuid::Uuid;
+use super::{traits::WindowGetters, TilingWindow, WindowDto, WindowState};
use crate::{
common::{
platform::NativeWindow, DisplayState, LengthValue, Rect, RectDelta,
@@ -20,8 +21,6 @@ use crate::{
user_config::WindowRuleConfig,
};
-use super::{traits::WindowGetters, TilingWindow, WindowDto, WindowState};
-
#[derive(Clone)]
pub struct NonTilingWindow(Rc<RefCell<NonTilingWindowInner>>);
diff --git a/packages/wm/src/windows/tiling_window.rs b/packages/wm/src/windows/tiling_window.rs
index 6d713693..2baf7ff7 100644
--- a/packages/wm/src/windows/tiling_window.rs
+++ b/packages/wm/src/windows/tiling_window.rs
@@ -7,6 +7,9 @@ use std::{
use anyhow::Context;
use uuid::Uuid;
+use super::{
+ traits::WindowGetters, NonTilingWindow, WindowDto, WindowState,
+};
use crate::{
common::{
platform::NativeWindow, DisplayState, LengthValue, Rect, RectDelta,
@@ -26,10 +29,6 @@ use crate::{
user_config::WindowRuleConfig,
};
-use super::{
- traits::WindowGetters, NonTilingWindow, WindowDto, WindowState,
-};
-
#[derive(Clone)]
pub struct TilingWindow(Rc<RefCell<TilingWindowInner>>);
diff --git a/packages/wm/src/windows/traits/window_getters.rs b/packages/wm/src/windows/traits/window_getters.rs
index e6a71703..c3fe190b 100644
--- a/packages/wm/src/windows/traits/window_getters.rs
+++ b/packages/wm/src/windows/traits/window_getters.rs
@@ -113,8 +113,8 @@ pub trait WindowGetters {
/// Implements the `WindowGetters` trait for a given struct.
///
/// Expects that the struct has a wrapping `RefCell` containing a struct
-/// with a `state`, `prev_state`, `native`, `border_delta`, `display_state`,
-/// `has_pending_dpi_adjustment`, and a `done_window_rules` field.
+/// with a `state`, `prev_state`, `native`, `has_pending_dpi_adjustment`,
+/// `border_delta`, `display_state`, and a `done_window_rules` field.
#[macro_export]
macro_rules! impl_window_getters {
($struct_name:ident) => {
diff --git a/packages/wm/src/windows/window_dto.rs b/packages/wm/src/windows/window_dto.rs
index 8064d4fb..d4224788 100644
--- a/packages/wm/src/windows/window_dto.rs
+++ b/packages/wm/src/windows/window_dto.rs
@@ -1,9 +1,8 @@
use serde::{Deserialize, Serialize};
use uuid::Uuid;
-use crate::common::{DisplayState, Rect, RectDelta};
-
use super::WindowState;
+use crate::common::{DisplayState, Rect, RectDelta};
/// User-friendly representation of a tiling or non-tiling window.
///
diff --git a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs b/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
index 4f0c53d4..a093b129 100644
--- a/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
+++ b/packages/wm/src/workspaces/commands/move_workspace_in_direction.rs
@@ -1,5 +1,6 @@
use anyhow::Context;
+use super::activate_workspace;
use crate::{
common::Direction,
containers::{
@@ -14,8 +15,6 @@ use crate::{
workspaces::Workspace,
};
-use super::activate_workspace;
-
pub fn move_workspace_in_direction(
workspace: Workspace,
direction: Direction,
diff --git a/rustfmt.toml b/rustfmt.toml
index d0912512..b1eb44c1 100644
--- a/rustfmt.toml
+++ b/rustfmt.toml
@@ -1,2 +1,6 @@
tab_spaces = 2
max_width = 75
+imports_granularity = "Crate"
+group_imports = "StdExternalCrate"
+use_field_init_shorthand = true
+wrap_comments = true