Skip to content

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

feat: handle focus events from windows on hidden workspaces

Lars Berger1062bd624e31
diff --git a/packages/wm/src/common/events/handle_window_focused.rs b/packages/wm/src/common/events/handle_window_focused.rs
index d6e0a9c6..ad148ed8 100644
--- a/packages/wm/src/common/events/handle_window_focused.rs
+++ b/packages/wm/src/common/events/handle_window_focused.rs
@@ -1,12 +1,14 @@
+use anyhow::Context;
use tracing::info;
use crate::{
common::{platform::NativeWindow, DisplayState},
- containers::commands::set_focused_descendant,
+ containers::{commands::set_focused_descendant, traits::CommonGetters},
user_config::UserConfig,
windows::traits::WindowGetters,
wm_event::WmEvent,
wm_state::WmState,
+ workspaces::commands::{focus_workspace, FocusWorkspaceTarget},
};
pub fn handle_window_focused(
@@ -52,8 +54,13 @@ pub fn handle_window_focused(
if window.clone().display_state() == DisplayState::Hidden {
// TODO: Log window details.
info!("Focusing off-screen window.");
- // TODO: Focus the workspace of the hidden window.
- return Ok(());
+
+ let workspace = window.workspace().context("No workspace")?;
+ focus_workspace(
+ FocusWorkspaceTarget::Name(workspace.config().name),
+ state,
+ config,
+ )?;
}
// Update the WM's focus state.
diff --git a/packages/wm/src/common/platform/event_listener.rs b/packages/wm/src/common/platform/event_listener.rs
index 7d3c26b0..3c1ee25b 100644
--- a/packages/wm/src/common/platform/event_listener.rs
+++ b/packages/wm/src/common/platform/event_listener.rs
@@ -9,7 +9,6 @@ use super::{EventWindow, NativeWindow};
#[derive(Debug)]
pub enum PlatformEvent {
- PowerModeChanged,
DisplaySettingsChanged,
KeybindingTriggered(KeybindingConfig),
MouseMove(MouseMoveEvent),
diff --git a/packages/wm/src/common/platform/keyboard_hook.rs b/packages/wm/src/common/platform/keyboard_hook.rs
index 0bd31690..9e474809 100644
--- a/packages/wm/src/common/platform/keyboard_hook.rs
+++ b/packages/wm/src/common/platform/keyboard_hook.rs
@@ -4,7 +4,7 @@ use std::{
};
use tokio::sync::mpsc;
-use tracing::{error, warn};
+use tracing::warn;
use windows::Win32::{
Foundation::{LPARAM, LRESULT, WPARAM},
UI::{
diff --git a/packages/wm/src/common/units.rs b/packages/wm/src/common/units.rs
index 2acc810c..21a9c211 100644
--- a/packages/wm/src/common/units.rs
+++ b/packages/wm/src/common/units.rs
@@ -25,13 +25,6 @@ impl LengthValue {
}
}
- pub fn new_percent(amount: f32) -> Self {
- Self {
- amount,
- unit: LengthUnit::Percentage,
- }
- }
-
pub fn to_pixels(&self, total: i32) -> i32 {
match self.unit {
LengthUnit::Pixel => self.amount as i32,
diff --git a/packages/wm/src/user_config.rs b/packages/wm/src/user_config.rs
index 3d9897ac..fd1bdf8b 100644
--- a/packages/wm/src/user_config.rs
+++ b/packages/wm/src/user_config.rs
@@ -2,7 +2,7 @@ use std::path::PathBuf;
use anyhow::{Context, Result};
use serde::{Deserialize, Serialize};
-use tokio::{fs, sync::mpsc};
+use tokio::fs;
use crate::{
app_command::InvokeCommand,
diff --git a/packages/wm/src/wm.rs b/packages/wm/src/wm.rs
index 4632b568..9b3ba0af 100644
--- a/packages/wm/src/wm.rs
+++ b/packages/wm/src/wm.rs
@@ -45,7 +45,6 @@ impl WindowManager {
let state = &mut self.state;
match event {
- PlatformEvent::PowerModeChanged => Ok(()),
PlatformEvent::DisplaySettingsChanged => {
handle_display_settings_changed(state, config)
}