feat(wm): add toggle-focus-follows-mouse cmd

Decided there should be a quick way to toggle the native ffm
functionality, it gets especially annoying when trying to click drop
downs from the system tray etc.

re #7
This commit is contained in:
LGUG2Z
2021-08-23 14:08:02 -07:00
parent fb4fe4d9c3
commit 87fe718754
7 changed files with 170 additions and 133 deletions
+2 -1
View File
@@ -207,12 +207,13 @@ restore-windows Restore all hidden windows (debugging command)
manage Force komorebi to manage the focused window manage Force komorebi to manage the focused window
unmanage Unmanage a window that was forcibly managed unmanage Unmanage a window that was forcibly managed
reload-configuration Reload ~/komorebi.ahk (if it exists) reload-configuration Reload ~/komorebi.ahk (if it exists)
watch-configuration Toggle the automatic reloading of ~/komorebi.ahk (if it exists) watch-configuration Enable or disable watching of ~/komorebi.ahk (if it exists)
float-rule Add a rule to always float the specified application float-rule Add a rule to always float the specified application
manage-rule Add a rule to always manage the specified application manage-rule Add a rule to always manage the specified application
workspace-rule Add a rule to associate an application with a workspace workspace-rule Add a rule to associate an application with a workspace
identify-tray-application Identify an application that closes to the system tray identify-tray-application Identify an application that closes to the system tray
focus-follows-mouse Enable or disable focus follows mouse for the operating system focus-follows-mouse Enable or disable focus follows mouse for the operating system
toggle-focus-follows-mouse Toggle focus follows mouse for the operating system
ahk-library Generate a library of AutoHotKey helper functions ahk-library Generate a library of AutoHotKey helper functions
help Print this message or the help of the given subcommand(s) help Print this message or the help of the given subcommand(s)
``` ```
+1
View File
@@ -66,6 +66,7 @@ pub enum SocketMessage {
IdentifyTrayApplication(ApplicationIdentifier, String), IdentifyTrayApplication(ApplicationIdentifier, String),
State, State,
FocusFollowsMouse(bool), FocusFollowsMouse(bool),
ToggleFocusFollowsMouse,
} }
impl SocketMessage { impl SocketMessage {
+8 -3
View File
@@ -4,9 +4,6 @@
; Enable hot reloading of changes to this file ; Enable hot reloading of changes to this file
WatchConfiguration("enable") WatchConfiguration("enable")
; Enable focus follows mouse
FocusFollowsMouse("enable")
; Ensure there are 5 workspaces created on monitor 0 ; Ensure there are 5 workspaces created on monitor 0
EnsureWorkspaces(0, 5) EnsureWorkspaces(0, 5)
@@ -41,6 +38,9 @@ FloatRule("exe", "wincompose.exe")
FloatRule("exe", "1Password.exe") FloatRule("exe", "1Password.exe")
FloatRule("exe", "Wox.exe") FloatRule("exe", "Wox.exe")
; Identify Minimize-to-Tray Applications
IdentifyTrayApplication("exe", "Discord.exe")
; Change the focused window, Alt + Vim direction keys ; Change the focused window, Alt + Vim direction keys
!h:: !h::
Focus("left") Focus("left")
@@ -170,6 +170,11 @@ return
TogglePause() TogglePause()
return return
; Toggle focus follows mouse
!0::
ToggleFocusFollowsMouse()
return
; Switch to workspace ; Switch to workspace
!1:: !1::
Send ! Send !
+7
View File
@@ -179,6 +179,13 @@ impl WindowManager {
WindowsApi::disable_focus_follows_mouse()?; WindowsApi::disable_focus_follows_mouse()?;
} }
} }
SocketMessage::ToggleFocusFollowsMouse => {
if WindowsApi::focus_follows_mouse()? {
WindowsApi::disable_focus_follows_mouse()?;
} else {
WindowsApi::enable_focus_follows_mouse()?;
}
}
SocketMessage::ReloadConfiguration => { SocketMessage::ReloadConfiguration => {
Self::reload_configuration(); Self::reload_configuration();
} }
+14
View File
@@ -67,6 +67,7 @@ use bindings::Windows::Win32::UI::WindowsAndMessaging::HWND_TOPMOST;
use bindings::Windows::Win32::UI::WindowsAndMessaging::SET_WINDOW_POS_FLAGS; use bindings::Windows::Win32::UI::WindowsAndMessaging::SET_WINDOW_POS_FLAGS;
use bindings::Windows::Win32::UI::WindowsAndMessaging::SHOW_WINDOW_CMD; use bindings::Windows::Win32::UI::WindowsAndMessaging::SHOW_WINDOW_CMD;
use bindings::Windows::Win32::UI::WindowsAndMessaging::SPIF_SENDCHANGE; use bindings::Windows::Win32::UI::WindowsAndMessaging::SPIF_SENDCHANGE;
use bindings::Windows::Win32::UI::WindowsAndMessaging::SPI_GETACTIVEWINDOWTRACKING;
use bindings::Windows::Win32::UI::WindowsAndMessaging::SPI_SETACTIVEWINDOWTRACKING; use bindings::Windows::Win32::UI::WindowsAndMessaging::SPI_SETACTIVEWINDOWTRACKING;
use bindings::Windows::Win32::UI::WindowsAndMessaging::SW_HIDE; use bindings::Windows::Win32::UI::WindowsAndMessaging::SW_HIDE;
use bindings::Windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE; use bindings::Windows::Win32::UI::WindowsAndMessaging::SW_MAXIMIZE;
@@ -557,6 +558,19 @@ impl WindowsApi {
})) }))
} }
pub fn focus_follows_mouse() -> Result<bool> {
let mut is_enabled: BOOL = unsafe { std::mem::zeroed() };
Self::system_parameters_info_w(
SPI_GETACTIVEWINDOWTRACKING,
0,
(&mut is_enabled as *mut BOOL).cast(),
SPIF_SENDCHANGE,
)?;
Ok(is_enabled.into())
}
pub fn enable_focus_follows_mouse() -> Result<()> { pub fn enable_focus_follows_mouse() -> Result<()> {
Self::system_parameters_info_w( Self::system_parameters_info_w(
SPI_SETACTIVEWINDOWTRACKING, SPI_SETACTIVEWINDOWTRACKING,
+4
View File
@@ -168,6 +168,10 @@ FocusFollowsMouse(boolean_state) {
Run, komorebic.exe focus-follows-mouse %boolean_state%, , Hide Run, komorebic.exe focus-follows-mouse %boolean_state%, , Hide
} }
ToggleFocusFollowsMouse() {
Run, komorebic.exe toggle-focus-follows-mouse, , Hide
}
AhkLibrary() { AhkLibrary() {
Run, komorebic.exe ahk-library, , Hide Run, komorebic.exe ahk-library, , Hide
} }
+6 -1
View File
@@ -328,7 +328,7 @@ enum SubCommand {
Unmanage, Unmanage,
/// Reload ~/komorebi.ahk (if it exists) /// Reload ~/komorebi.ahk (if it exists)
ReloadConfiguration, ReloadConfiguration,
/// Toggle the automatic reloading of ~/komorebi.ahk (if it exists) /// Enable or disable watching of ~/komorebi.ahk (if it exists)
#[clap(setting = AppSettings::ArgRequiredElseHelp)] #[clap(setting = AppSettings::ArgRequiredElseHelp)]
WatchConfiguration(WatchConfiguration), WatchConfiguration(WatchConfiguration),
/// Add a rule to always float the specified application /// Add a rule to always float the specified application
@@ -345,6 +345,8 @@ enum SubCommand {
IdentifyTrayApplication(IdentifyTrayApplication), IdentifyTrayApplication(IdentifyTrayApplication),
/// Enable or disable focus follows mouse for the operating system /// Enable or disable focus follows mouse for the operating system
FocusFollowsMouse(FocusFollowsMouse), FocusFollowsMouse(FocusFollowsMouse),
/// Toggle focus follows mouse for the operating system
ToggleFocusFollowsMouse,
/// Generate a library of AutoHotKey helper functions /// Generate a library of AutoHotKey helper functions
AhkLibrary, AhkLibrary,
} }
@@ -439,6 +441,9 @@ fn main() -> Result<()> {
&*SocketMessage::AdjustContainerPadding(arg.sizing, arg.adjustment).as_bytes()?, &*SocketMessage::AdjustContainerPadding(arg.sizing, arg.adjustment).as_bytes()?,
)?; )?;
} }
SubCommand::ToggleFocusFollowsMouse => {
send_message(&*SocketMessage::ToggleFocusFollowsMouse.as_bytes()?)?;
}
SubCommand::ToggleTiling => { SubCommand::ToggleTiling => {
send_message(&*SocketMessage::ToggleTiling.as_bytes()?)?; send_message(&*SocketMessage::ToggleTiling.as_bytes()?)?;
} }