mirror of
https://github.com/LGUG2Z/komorebi.git
synced 2026-11-19 23:28:34 +01:00
feat(config): add window hiding position behaviour
This commit adds a new monitor configuration option "window_hiding_position", which takes an enum with the variants BottomLeft and BottomRight. Until now the behaviour had been hard-coded to hide windows at the bottom left of every monitor. If no value is given on a monitor configuration object, this option will default to BottomLeft.
This commit is contained in:
1 parent
05e4222a23
commit
ed2185a667
13 files changed
+167
-38
No files matched your search
@@ -1,4 +1,5 @@
|
||||
use crate::accessibility::error::AccessibilityError;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::lockable_sequence::Lockable;
|
||||
use crate::ring::Ring;
|
||||
use crate::window::Window;
|
||||
@@ -76,14 +77,18 @@ impl Container {
|
||||
self.remove_window_by_idx(focused_idx)
|
||||
}
|
||||
|
||||
pub fn add_window(&mut self, window: &Window) -> eyre::Result<()> {
|
||||
pub fn add_window(
|
||||
&mut self,
|
||||
window: &Window,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> eyre::Result<()> {
|
||||
self.windows_mut().push_back(window.clone());
|
||||
self.focus_window(self.windows().len().saturating_sub(1));
|
||||
let focused_window_idx = self.focused_window_idx();
|
||||
|
||||
for (i, window) in self.windows_mut().iter_mut().enumerate() {
|
||||
if i != focused_window_idx {
|
||||
window.hide()?;
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,14 +104,17 @@ impl Container {
|
||||
/// Hides the unfocused windows of the container and restores the focused one. This function
|
||||
/// is used to make sure we update the window that should be shown on a stack. If the container
|
||||
/// isn't a stack this function won't change anything.
|
||||
pub fn load_focused_window(&mut self) -> Result<(), AccessibilityError> {
|
||||
pub fn load_focused_window(
|
||||
&mut self,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> Result<(), AccessibilityError> {
|
||||
let focused_idx = self.focused_window_idx();
|
||||
|
||||
for (i, window) in self.windows_mut().iter_mut().enumerate() {
|
||||
if i == focused_idx {
|
||||
window.restore()?;
|
||||
} else {
|
||||
window.hide()?;
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -119,7 +127,11 @@ impl Container {
|
||||
window
|
||||
}
|
||||
|
||||
pub fn hide(&mut self, omit: Option<u32>) -> eyre::Result<()> {
|
||||
pub fn hide(
|
||||
&mut self,
|
||||
hiding_position: WindowHidingPosition,
|
||||
omit: Option<u32>,
|
||||
) -> eyre::Result<()> {
|
||||
for window in self.windows_mut().iter_mut().rev() {
|
||||
let mut should_hide = omit.is_none();
|
||||
|
||||
@@ -131,7 +143,7 @@ impl Container {
|
||||
}
|
||||
|
||||
if should_hide {
|
||||
window.hide()?;
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -110,6 +110,18 @@ pub enum FloatingLayerBehaviour {
|
||||
Float,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
|
||||
)]
|
||||
#[cfg_attr(feature = "schemars", derive(schemars::JsonSchema))]
|
||||
pub enum WindowHidingPosition {
|
||||
/// Hide windows in the bottom left corner of the screen
|
||||
#[default]
|
||||
BottomLeft,
|
||||
/// Hide windows in the bottom right corner of the screen
|
||||
BottomRight,
|
||||
}
|
||||
|
||||
#[derive(
|
||||
Clone, Copy, Debug, Default, Serialize, Deserialize, Display, EnumString, ValueEnum, PartialEq,
|
||||
)]
|
||||
|
||||
@@ -308,3 +308,11 @@ pub fn hidden_frame_bottom_left(screen_frame: CGRect, window_size: CGSize) -> CG
|
||||
|
||||
CGRect::new(CGPoint::new(origin_x, origin_y), window_size)
|
||||
}
|
||||
|
||||
pub fn hidden_frame_bottom_right(screen_frame: CGRect, window_size: CGSize) -> CGRect {
|
||||
let visible_sliver: f64 = 1.0;
|
||||
let origin_x = screen_frame.origin.x + screen_frame.size.width - visible_sliver;
|
||||
let origin_y = screen_frame.origin.y + screen_frame.size.height - visible_sliver;
|
||||
|
||||
CGRect::new(CGPoint::new(origin_x, origin_y), window_size)
|
||||
}
|
||||
@@ -2,6 +2,7 @@ use crate::DEFAULT_CONTAINER_PADDING;
|
||||
use crate::DEFAULT_WORKSPACE_PADDING;
|
||||
use crate::container::Container;
|
||||
use crate::core::FloatingLayerBehaviour;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::core::default_layout::DefaultLayout;
|
||||
use crate::core::layout::Layout;
|
||||
use crate::core::operation_direction::OperationDirection;
|
||||
@@ -70,6 +71,7 @@ pub struct Monitor {
|
||||
pub last_focused_workspace: Option<usize>,
|
||||
pub wallpaper: Option<Wallpaper>,
|
||||
pub floating_layer_behaviour: Option<FloatingLayerBehaviour>,
|
||||
pub window_hiding_position: WindowHidingPosition,
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
@@ -97,6 +99,7 @@ pub fn new(
|
||||
workspace_padding: None,
|
||||
wallpaper: None,
|
||||
floating_layer_behaviour: None,
|
||||
window_hiding_position: WindowHidingPosition::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,6 +130,7 @@ impl Monitor {
|
||||
last_focused_workspace: None,
|
||||
wallpaper: None,
|
||||
floating_layer_behaviour: None,
|
||||
window_hiding_position: WindowHidingPosition::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -147,6 +151,7 @@ impl Monitor {
|
||||
workspace_padding: None,
|
||||
wallpaper: None,
|
||||
floating_layer_behaviour: None,
|
||||
window_hiding_position: WindowHidingPosition::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,6 +186,7 @@ impl Monitor {
|
||||
let window_based_work_area_offset = self.window_based_work_area_offset;
|
||||
let window_based_work_area_offset_limit = self.window_based_work_area_offset_limit;
|
||||
let floating_layer_behaviour = self.floating_layer_behaviour;
|
||||
let window_hiding_position = self.window_hiding_position;
|
||||
|
||||
if let Some(workspace) = self.workspaces_mut().get_mut(workspace_idx) {
|
||||
workspace.globals = WorkspaceGlobals {
|
||||
@@ -193,6 +199,7 @@ impl Monitor {
|
||||
window_based_work_area_offset,
|
||||
window_based_work_area_offset_limit,
|
||||
floating_layer_behaviour,
|
||||
window_hiding_position,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -452,6 +459,7 @@ impl Monitor {
|
||||
let window_based_work_area_offset = self.window_based_work_area_offset;
|
||||
let window_based_work_area_offset_limit = self.window_based_work_area_offset_limit;
|
||||
let floating_layer_behaviour = self.floating_layer_behaviour;
|
||||
let window_hiding_position = self.window_hiding_position;
|
||||
|
||||
for workspace in self.workspaces_mut() {
|
||||
workspace.globals = WorkspaceGlobals {
|
||||
@@ -464,6 +472,7 @@ impl Monitor {
|
||||
window_based_work_area_offset,
|
||||
window_based_work_area_offset_limit,
|
||||
floating_layer_behaviour,
|
||||
window_hiding_position,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -383,6 +383,7 @@ pub fn handle_notifications(wm: Arc<Mutex<WindowManager>>) -> color_eyre::Result
|
||||
workspace_padding: cached.workspace_padding,
|
||||
wallpaper: cached.wallpaper.clone(),
|
||||
floating_layer_behaviour: cached.floating_layer_behaviour,
|
||||
window_hiding_position: cached.window_hiding_position,
|
||||
};
|
||||
|
||||
let focused_workspace_idx = m.focused_workspace_idx();
|
||||
|
||||
@@ -566,6 +566,10 @@ impl WindowManager {
|
||||
SocketMessage::ToggleFloat => self.toggle_float(false)?,
|
||||
SocketMessage::ToggleWorkspaceLayer => {
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let hiding_position = self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.window_hiding_position;
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
|
||||
let mut to_focus = None;
|
||||
@@ -631,7 +635,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
for window in workspace.floating_windows_mut() {
|
||||
window.hide()?;
|
||||
window.hide(hiding_position)?;
|
||||
}
|
||||
} else {
|
||||
let focused_container_idx = workspace.focused_container_idx();
|
||||
@@ -662,7 +666,7 @@ impl WindowManager {
|
||||
|
||||
for window in window_idx_pairs {
|
||||
// TODO: figure out z order
|
||||
window.hide()?;
|
||||
window.hide(hiding_position)?;
|
||||
// window.lower()?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@ use crate::app_kit_notification_constants::AppKitWorkspaceNotification;
|
||||
use crate::border_manager;
|
||||
use crate::core::Sizing;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::core::config_generation::MatchingRule;
|
||||
use crate::core::default_layout::DefaultLayout;
|
||||
use crate::core::layout::Layout;
|
||||
@@ -441,7 +442,8 @@ impl WindowManager {
|
||||
"ignoring show event for window already associated with another workspace"
|
||||
);
|
||||
|
||||
AdhocWindow::hide(window_id, element)?;
|
||||
// TODO: probably shouldn't default here
|
||||
AdhocWindow::hide(window_id, element, WindowHidingPosition::default())?;
|
||||
create = false;
|
||||
}
|
||||
}
|
||||
@@ -462,7 +464,6 @@ impl WindowManager {
|
||||
&& let Ok(mut window) = Window::new(element, application.clone())
|
||||
{
|
||||
window.observe(&self.run_loop, None)?;
|
||||
|
||||
let behaviour = self
|
||||
.window_management_behaviour(focused_monitor_idx, focused_workspace_idx);
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
@@ -534,10 +535,12 @@ impl WindowManager {
|
||||
self.update_focused_workspace(false, false)?;
|
||||
}
|
||||
WindowContainerBehaviour::Append => {
|
||||
let window_hiding_position =
|
||||
workspace.globals.window_hiding_position;
|
||||
workspace
|
||||
.focused_container_mut()
|
||||
.ok_or_eyre("there is no focused container")?
|
||||
.add_window(&window)?;
|
||||
.add_window(&window, window_hiding_position)?;
|
||||
workspace.layer = WorkspaceLayer::Tiling;
|
||||
self.update_focused_workspace(true, false)?;
|
||||
}
|
||||
@@ -575,7 +578,7 @@ impl WindowManager {
|
||||
if !(monocle_window_event || workspace.layer != WorkspaceLayer::Tiling)
|
||||
&& monocle_container.is_some()
|
||||
{
|
||||
window.hide()?;
|
||||
window.hide(workspace.globals.window_hiding_position)?;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -151,6 +151,7 @@ impl From<&WindowManager> for State {
|
||||
workspace_padding: monitor.workspace_padding,
|
||||
wallpaper: monitor.wallpaper.clone(),
|
||||
floating_layer_behaviour: monitor.floating_layer_behaviour,
|
||||
window_hiding_position: monitor.window_hiding_position,
|
||||
})
|
||||
.collect::<VecDeque<_>>();
|
||||
stripped_monitors.focus(wm.monitors.focused_idx());
|
||||
|
||||
@@ -17,6 +17,7 @@ use crate::core::OperationBehaviour;
|
||||
use crate::core::Placement;
|
||||
use crate::core::SocketMessage;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::core::WindowManagementBehaviour;
|
||||
use crate::core::arrangement::Axis;
|
||||
use crate::core::asc::ApplicationSpecificConfiguration;
|
||||
@@ -305,6 +306,9 @@ pub struct MonitorConfig {
|
||||
/// Determine what happens to a new window when the Floating workspace layer is active (default: Tile)
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub floating_layer_behaviour: Option<FloatingLayerBehaviour>,
|
||||
/// Determine which position windows should be hidden at on this monitor
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub window_hiding_position: Option<WindowHidingPosition>,
|
||||
}
|
||||
|
||||
impl From<&Monitor> for MonitorConfig {
|
||||
@@ -342,6 +346,7 @@ impl From<&Monitor> for MonitorConfig {
|
||||
workspace_padding,
|
||||
wallpaper: value.wallpaper.clone(),
|
||||
floating_layer_behaviour: value.floating_layer_behaviour,
|
||||
window_hiding_position: Some(value.window_hiding_position),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1252,6 +1257,8 @@ impl StaticConfig {
|
||||
monitor.workspace_padding = monitor_config.workspace_padding;
|
||||
monitor.wallpaper = monitor_config.wallpaper.clone();
|
||||
monitor.floating_layer_behaviour = monitor_config.floating_layer_behaviour;
|
||||
monitor.window_hiding_position =
|
||||
monitor_config.window_hiding_position.unwrap_or_default();
|
||||
|
||||
monitor.update_workspaces_globals(offset);
|
||||
for (j, ws) in monitor.workspaces_mut().iter_mut().enumerate() {
|
||||
@@ -1333,6 +1340,8 @@ impl StaticConfig {
|
||||
m.container_padding = monitor_config.container_padding;
|
||||
m.workspace_padding = monitor_config.workspace_padding;
|
||||
m.floating_layer_behaviour = monitor_config.floating_layer_behaviour;
|
||||
m.window_hiding_position =
|
||||
monitor_config.window_hiding_position.unwrap_or_default();
|
||||
|
||||
m.update_workspaces_globals(offset);
|
||||
|
||||
@@ -1418,6 +1427,8 @@ impl StaticConfig {
|
||||
monitor.workspace_padding = monitor_config.workspace_padding;
|
||||
monitor.wallpaper = monitor_config.wallpaper.clone();
|
||||
monitor.floating_layer_behaviour = monitor_config.floating_layer_behaviour;
|
||||
monitor.window_hiding_position =
|
||||
monitor_config.window_hiding_position.unwrap_or_default();
|
||||
|
||||
monitor.update_workspaces_globals(offset);
|
||||
|
||||
@@ -1491,6 +1502,8 @@ impl StaticConfig {
|
||||
m.container_padding = monitor_config.container_padding;
|
||||
m.workspace_padding = monitor_config.workspace_padding;
|
||||
m.floating_layer_behaviour = monitor_config.floating_layer_behaviour;
|
||||
m.window_hiding_position =
|
||||
monitor_config.window_hiding_position.unwrap_or_default();
|
||||
|
||||
m.update_workspaces_globals(offset);
|
||||
|
||||
|
||||
+27
-4
@@ -31,12 +31,14 @@ use crate::accessibility::notification_constants::kAXWindowResizedNotification;
|
||||
use crate::application::Application;
|
||||
use crate::cf_dictionary_value;
|
||||
use crate::core::ApplicationIdentifier;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::core::config_generation::IdWithIdentifier;
|
||||
use crate::core::config_generation::MatchingRule;
|
||||
use crate::core::config_generation::MatchingStrategy;
|
||||
use crate::core::rect::Rect;
|
||||
use crate::core_graphics::CoreGraphicsApi;
|
||||
use crate::hidden_frame_bottom_left;
|
||||
use crate::hidden_frame_bottom_right;
|
||||
use crate::macos_api::MacosApi;
|
||||
use crate::reaper;
|
||||
use crate::window_manager_event::SystemNotification;
|
||||
@@ -341,7 +343,10 @@ impl Window {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub fn hide(&mut self) -> Result<(), AccessibilityError> {
|
||||
pub fn hide(
|
||||
&mut self,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> Result<(), AccessibilityError> {
|
||||
let rect = MacosApi::window_rect(&self.element)?;
|
||||
|
||||
let mut window_restore_positions = WINDOW_RESTORE_POSITIONS.lock();
|
||||
@@ -352,7 +357,14 @@ impl Window {
|
||||
|
||||
if let Some(monitor_size) = CoreGraphicsApi::display_bounds_for_window_rect(rect) {
|
||||
// I don't love this, but it's basically what Aerospace does in lieu of an actual "Hide" API
|
||||
let hidden_rect = hidden_frame_bottom_left(monitor_size, rect.size);
|
||||
let hidden_rect = match hiding_position {
|
||||
WindowHidingPosition::BottomLeft => {
|
||||
hidden_frame_bottom_left(monitor_size, rect.size)
|
||||
}
|
||||
WindowHidingPosition::BottomRight => {
|
||||
hidden_frame_bottom_right(monitor_size, rect.size)
|
||||
}
|
||||
};
|
||||
|
||||
tracing::debug!(
|
||||
"hiding {} and setting restore point to {},{}",
|
||||
@@ -804,7 +816,11 @@ impl AdhocWindow {
|
||||
}
|
||||
|
||||
#[tracing::instrument(skip_all)]
|
||||
pub fn hide(id: u32, element: &CFRetained<AXUIElement>) -> Result<(), AccessibilityError> {
|
||||
pub fn hide(
|
||||
id: u32,
|
||||
element: &CFRetained<AXUIElement>,
|
||||
hiding_position: WindowHidingPosition,
|
||||
) -> Result<(), AccessibilityError> {
|
||||
let mut window_restore_positions = WINDOW_RESTORE_POSITIONS.lock();
|
||||
if let Entry::Vacant(entry) = window_restore_positions.entry(id) {
|
||||
let rect = MacosApi::window_rect(element)?;
|
||||
@@ -813,7 +829,14 @@ impl AdhocWindow {
|
||||
drop(window_restore_positions);
|
||||
|
||||
// I don't love this, but it's basically what Aerospace does in lieu of an actual "Hide" API
|
||||
let hidden_rect = hidden_frame_bottom_left(monitor_size, rect.size);
|
||||
let hidden_rect = match hiding_position {
|
||||
WindowHidingPosition::BottomLeft => {
|
||||
hidden_frame_bottom_left(monitor_size, rect.size)
|
||||
}
|
||||
WindowHidingPosition::BottomRight => {
|
||||
hidden_frame_bottom_right(monitor_size, rect.size)
|
||||
}
|
||||
};
|
||||
|
||||
tracing::debug!(
|
||||
"hiding window with id {id} and setting restore point to {},{}",
|
||||
|
||||
@@ -15,6 +15,7 @@ use crate::core::OperationBehaviour;
|
||||
use crate::core::Placement;
|
||||
use crate::core::Sizing;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::core::WindowManagementBehaviour;
|
||||
use crate::core::arrangement::Arrangement;
|
||||
use crate::core::arrangement::Axis;
|
||||
@@ -1122,8 +1123,9 @@ impl WindowManager {
|
||||
}
|
||||
}
|
||||
|
||||
let window_hiding_position = workspace.globals.window_hiding_position;
|
||||
if changed_focus && let Some(container) = workspace.focused_container_mut() {
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
}
|
||||
@@ -1204,6 +1206,7 @@ impl WindowManager {
|
||||
tracing::info!("cycling container windows");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let window_hiding_position = self.focused_workspace()?.globals.window_hiding_position;
|
||||
|
||||
let container = self.focused_container_mut()?;
|
||||
|
||||
@@ -1218,7 +1221,7 @@ impl WindowManager {
|
||||
let next_idx = direction.next_idx(current_idx, len);
|
||||
|
||||
container.focus_window(next_idx);
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -1280,11 +1283,16 @@ impl WindowManager {
|
||||
pub fn monocle_on(&mut self) -> eyre::Result<()> {
|
||||
tracing::info!("enabling monocle");
|
||||
|
||||
let hiding_position = self
|
||||
.focused_monitor()
|
||||
.ok_or_eyre("there is no monitor")?
|
||||
.window_hiding_position;
|
||||
|
||||
let workspace = self.focused_workspace_mut()?;
|
||||
workspace.new_monocle_container()?;
|
||||
|
||||
for container in workspace.containers_mut() {
|
||||
container.hide(None)?;
|
||||
container.hide(hiding_position, None)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -2161,6 +2169,7 @@ impl WindowManager {
|
||||
tracing::info!("cycling container window index");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let window_hiding_position = self.focused_workspace()?.globals.window_hiding_position;
|
||||
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
@@ -2181,7 +2190,7 @@ impl WindowManager {
|
||||
container.windows_mut().swap(current_idx, next_idx);
|
||||
|
||||
container.focus_window(next_idx);
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -2195,6 +2204,7 @@ impl WindowManager {
|
||||
tracing::info!("focusing container window at index {idx}");
|
||||
|
||||
let mouse_follows_focus = self.mouse_follows_focus;
|
||||
let window_hiding_position = self.focused_workspace()?.globals.window_hiding_position;
|
||||
|
||||
let container =
|
||||
if let Some(container) = &mut self.focused_workspace_mut()?.monocle_container {
|
||||
@@ -2215,7 +2225,7 @@ impl WindowManager {
|
||||
}
|
||||
|
||||
container.focus_window(idx);
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(mouse_follows_focus)?;
|
||||
@@ -2432,7 +2442,7 @@ impl WindowManager {
|
||||
|
||||
// Hide the window we are about to remove if it is on the currently focused workspace
|
||||
if op.is_origin(focused_monitor_idx, focused_workspace_idx) {
|
||||
window.hide()?;
|
||||
window.hide(WindowHidingPosition::default())?;
|
||||
should_update_focused_workspace = true;
|
||||
}
|
||||
|
||||
|
||||
+30
-16
@@ -3,6 +3,7 @@ use crate::container::Container;
|
||||
use crate::core::FloatingLayerBehaviour;
|
||||
use crate::core::SocketMessage;
|
||||
use crate::core::WindowContainerBehaviour;
|
||||
use crate::core::WindowHidingPosition;
|
||||
use crate::core::arrangement::Axis;
|
||||
use crate::core::cycle_direction::CycleDirection;
|
||||
use crate::core::default_layout::DefaultLayout;
|
||||
@@ -139,6 +140,7 @@ pub struct WorkspaceGlobals {
|
||||
pub window_based_work_area_offset: Option<Rect>,
|
||||
pub window_based_work_area_offset_limit: isize,
|
||||
pub floating_layer_behaviour: Option<FloatingLayerBehaviour>,
|
||||
pub window_hiding_position: WindowHidingPosition,
|
||||
}
|
||||
|
||||
impl Workspace {
|
||||
@@ -249,6 +251,8 @@ impl Workspace {
|
||||
.container_idx_for_window(window_id)
|
||||
.ok_or_eyre("there is no container/window")?;
|
||||
|
||||
let window_hiding_position = self.globals.window_hiding_position;
|
||||
|
||||
let container = self
|
||||
.containers_mut()
|
||||
.get_mut(container_idx)
|
||||
@@ -267,7 +271,7 @@ impl Workspace {
|
||||
container.focus_window(window_idx);
|
||||
|
||||
if should_load {
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
}
|
||||
|
||||
self.focus_container(container_idx);
|
||||
@@ -283,7 +287,7 @@ impl Workspace {
|
||||
};
|
||||
|
||||
let mut container = Container::default();
|
||||
container.add_window(window)?;
|
||||
container.add_window(window, self.globals.window_hiding_position)?;
|
||||
|
||||
self.insert_container_at_idx(next_idx, container);
|
||||
|
||||
@@ -437,6 +441,8 @@ impl Workspace {
|
||||
.container_idx_for_window(window_id)
|
||||
.ok_or_eyre("there is no window")?;
|
||||
|
||||
let window_hiding_position = self.globals.window_hiding_position;
|
||||
|
||||
let container = self
|
||||
.containers_mut()
|
||||
.get_mut(container_idx)
|
||||
@@ -456,7 +462,7 @@ impl Workspace {
|
||||
self.remove_container_by_idx(container_idx);
|
||||
self.focus_previous_container();
|
||||
} else {
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
if let Some(window) = container.focused_window() {
|
||||
window.focus(false)?;
|
||||
}
|
||||
@@ -593,6 +599,7 @@ impl Workspace {
|
||||
// this is what we use for stacking
|
||||
pub fn move_window_to_container(&mut self, target_container_idx: usize) -> eyre::Result<()> {
|
||||
let focused_idx = self.focused_container_idx();
|
||||
let window_hiding_position = self.globals.window_hiding_position;
|
||||
|
||||
let container = self
|
||||
.focused_container_mut()
|
||||
@@ -612,7 +619,7 @@ impl Workspace {
|
||||
target_container_idx
|
||||
}
|
||||
} else {
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
target_container_idx
|
||||
};
|
||||
|
||||
@@ -621,18 +628,19 @@ impl Workspace {
|
||||
.get_mut(adjusted_target_container_index)
|
||||
.ok_or_eyre("there is no container")?;
|
||||
|
||||
target_container.add_window(&window)?;
|
||||
target_container.add_window(&window, window_hiding_position)?;
|
||||
|
||||
self.focus_container(adjusted_target_container_index);
|
||||
self.focused_container_mut()
|
||||
.ok_or_eyre("there is no container")?
|
||||
.load_focused_window()?;
|
||||
.load_focused_window(window_hiding_position)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn new_container_for_focused_window(&mut self) -> eyre::Result<()> {
|
||||
let focused_container_idx = self.focused_container_idx();
|
||||
let window_hiding_position = self.globals.window_hiding_position;
|
||||
|
||||
let container = self
|
||||
.focused_container_mut()
|
||||
@@ -645,17 +653,19 @@ impl Workspace {
|
||||
if container.windows().is_empty() {
|
||||
self.remove_container_by_idx(focused_container_idx);
|
||||
} else {
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
}
|
||||
|
||||
self.new_container_for_window(&window)?;
|
||||
|
||||
let mut container = Container::default();
|
||||
container.add_window(&window)?;
|
||||
container.add_window(&window, window_hiding_position)?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn hide(&mut self, omit: Option<u32>) -> eyre::Result<()> {
|
||||
let window_hiding_position = self.globals.window_hiding_position;
|
||||
|
||||
for window in self.floating_windows_mut().iter_mut().rev() {
|
||||
let mut should_hide = omit.is_none();
|
||||
|
||||
@@ -666,7 +676,7 @@ impl Workspace {
|
||||
should_hide = true
|
||||
}
|
||||
|
||||
if should_hide && let Err(error) = window.hide() {
|
||||
if should_hide && let Err(error) = window.hide(window_hiding_position) {
|
||||
tracing::warn!(
|
||||
"failed to hide floating window, but this might be because it is already hidden: {error}"
|
||||
);
|
||||
@@ -674,7 +684,7 @@ impl Workspace {
|
||||
}
|
||||
|
||||
for container in self.containers_mut() {
|
||||
container.hide(omit)?;
|
||||
container.hide(window_hiding_position, omit)?;
|
||||
}
|
||||
|
||||
// if let Some(window) = self.maximized_window() {
|
||||
@@ -682,7 +692,7 @@ impl Workspace {
|
||||
// }
|
||||
|
||||
if let Some(container) = &mut self.monocle_container {
|
||||
container.hide(omit)?;
|
||||
container.hide(window_hiding_position, omit)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -822,12 +832,14 @@ impl Workspace {
|
||||
self.monocle_container
|
||||
.as_mut()
|
||||
.ok_or_eyre("there is no monocle container")?
|
||||
.load_focused_window()?;
|
||||
.load_focused_window(self.globals.window_hiding_position)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn reintegrate_monocle_container(&mut self) -> eyre::Result<()> {
|
||||
let window_hiding_position = self.globals.window_hiding_position;
|
||||
|
||||
let restore_idx = self
|
||||
.monocle_container_restore_idx
|
||||
.ok_or_eyre("there is no monocle restore index")?;
|
||||
@@ -850,7 +862,7 @@ impl Workspace {
|
||||
self.focus_container(restore_idx);
|
||||
self.focused_container_mut()
|
||||
.ok_or_eyre("there is no container")?
|
||||
.load_focused_window()?;
|
||||
.load_focused_window(window_hiding_position)?;
|
||||
|
||||
self.monocle_container = None;
|
||||
self.monocle_container_restore_idx = None;
|
||||
@@ -859,6 +871,8 @@ impl Workspace {
|
||||
}
|
||||
|
||||
pub fn new_floating_window(&mut self) -> eyre::Result<()> {
|
||||
let window_hiding_position = self.globals.window_hiding_position;
|
||||
|
||||
let window = if let Some(monocle_container) = &mut self.monocle_container {
|
||||
let window = monocle_container
|
||||
.remove_focused_window()
|
||||
@@ -868,7 +882,7 @@ impl Workspace {
|
||||
self.monocle_container = None;
|
||||
self.monocle_container_restore_idx = None;
|
||||
} else {
|
||||
monocle_container.load_focused_window()?;
|
||||
monocle_container.load_focused_window(self.globals.window_hiding_position)?;
|
||||
}
|
||||
|
||||
window
|
||||
@@ -890,7 +904,7 @@ impl Workspace {
|
||||
self.focus_container(focused_idx.saturating_sub(1));
|
||||
}
|
||||
} else {
|
||||
container.load_focused_window()?;
|
||||
container.load_focused_window(window_hiding_position)?;
|
||||
}
|
||||
|
||||
window
|
||||
@@ -908,7 +922,7 @@ impl Workspace {
|
||||
.ok_or_eyre("there is no floating window")?;
|
||||
|
||||
let mut container = Container::default();
|
||||
container.add_window(&window)?;
|
||||
container.add_window(&window, self.globals.window_hiding_position)?;
|
||||
|
||||
self.insert_container_at_idx(focused_idx, container);
|
||||
|
||||
|
||||
+19
@@ -1244,6 +1244,25 @@
|
||||
"type": "integer",
|
||||
"format": "int"
|
||||
},
|
||||
"window_hiding_position": {
|
||||
"description": "Determine which position windows should be hidden at on this monitor",
|
||||
"oneOf": [
|
||||
{
|
||||
"description": "Hide windows in the bottom left corner of the screen",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"BottomLeft"
|
||||
]
|
||||
},
|
||||
{
|
||||
"description": "Hide windows in the bottom right corner of the screen",
|
||||
"type": "string",
|
||||
"enum": [
|
||||
"BottomRight"
|
||||
]
|
||||
}
|
||||
]
|
||||
},
|
||||
"work_area_offset": {
|
||||
"description": "Monitor-specific work area offset (default: None)",
|
||||
"type": "object",
|
||||
|
||||
Reference in new issue
Block a user