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
+45 -44
View File
@@ -171,50 +171,51 @@ keybindings with. You can run `komorebic.exe <COMMAND> --help` to get a full exp
each command. each command.
``` ```
start Start komorebi.exe as a background process start Start komorebi.exe as a background process
stop Stop the komorebi.exe process and restore all hidden windows stop Stop the komorebi.exe process and restore all hidden windows
state Show a JSON representation of the current window manager state state Show a JSON representation of the current window manager state
log Tail komorebi.exe's process logs (cancel with Ctrl-C) log Tail komorebi.exe's process logs (cancel with Ctrl-C)
focus Change focus to the window in the specified direction focus Change focus to the window in the specified direction
move Move the focused window in the specified direction move Move the focused window in the specified direction
stack Stack the focused window in the specified direction stack Stack the focused window in the specified direction
resize Resize the focused window in the specified direction resize Resize the focused window in the specified direction
unstack Unstack the focused window unstack Unstack the focused window
cycle-stack Cycle the focused stack in the specified cycle direction cycle-stack Cycle the focused stack in the specified cycle direction
move-to-monitor Move the focused window to the specified monitor move-to-monitor Move the focused window to the specified monitor
move-to-workspace Move the focused window to the specified workspace move-to-workspace Move the focused window to the specified workspace
focus-monitor Focus the specified monitor focus-monitor Focus the specified monitor
focus-workspace Focus the specified workspace on the focused monitor focus-workspace Focus the specified workspace on the focused monitor
new-workspace Create and append a new workspace on the focused monitor new-workspace Create and append a new workspace on the focused monitor
adjust-container-padding Adjust container padding on the focused workspace adjust-container-padding Adjust container padding on the focused workspace
adjust-workspace-padding Adjust workspace padding on the focused workspace adjust-workspace-padding Adjust workspace padding on the focused workspace
change-layout Set the layout on the focused workspace change-layout Set the layout on the focused workspace
flip-layout Flip the layout on the focused workspace (BSP only) flip-layout Flip the layout on the focused workspace (BSP only)
promote Promote the focused window to the top of the tree promote Promote the focused window to the top of the tree
retile Force the retiling of all managed windows retile Force the retiling of all managed windows
ensure-workspaces Create at least this many workspaces for the specified monitor ensure-workspaces Create at least this many workspaces for the specified monitor
container-padding Set the container padding for the specified workspace container-padding Set the container padding for the specified workspace
workspace-padding Set the workspace padding for the specified workspace workspace-padding Set the workspace padding for the specified workspace
workspace-layout Set the layout for the specified workspace workspace-layout Set the layout for the specified workspace
workspace-tiling Enable or disable window tiling for the specified workspace workspace-tiling Enable or disable window tiling for the specified workspace
workspace-name Set the workspace name for the specified workspace workspace-name Set the workspace name for the specified workspace
toggle-pause Toggle the window manager on and off across all monitors toggle-pause Toggle the window manager on and off across all monitors
toggle-tiling Toggle window tiling on the focused workspace toggle-tiling Toggle window tiling on the focused workspace
toggle-float Toggle floating mode for the focused window toggle-float Toggle floating mode for the focused window
toggle-monocle Toggle monocle mode for the focused container toggle-monocle Toggle monocle mode for the focused container
toggle-maximize Toggle native maximization for the focused window toggle-maximize Toggle native maximization for the focused window
restore-windows Restore all hidden windows (debugging command) 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
ahk-library Generate a library of AutoHotKey helper functions toggle-focus-follows-mouse Toggle focus follows mouse for the operating system
help Print this message or the help of the given subcommand(s) ahk-library Generate a library of AutoHotKey helper functions
help Print this message or the help of the given subcommand(s)
``` ```
### AutoHotKey Helper Library for `komorebic` ### AutoHotKey Helper Library for `komorebic`
+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,
+89 -85
View File
@@ -1,173 +1,177 @@
; Generated by komorebic.exe ; Generated by komorebic.exe
Start() { Start() {
Run, komorebic.exe start, , Hide Run, komorebic.exe start, , Hide
} }
Stop() { Stop() {
Run, komorebic.exe stop, , Hide Run, komorebic.exe stop, , Hide
} }
State() { State() {
Run, komorebic.exe state, , Hide Run, komorebic.exe state, , Hide
} }
Log() { Log() {
Run, komorebic.exe log, , Hide Run, komorebic.exe log, , Hide
} }
Focus(operation_direction) { Focus(operation_direction) {
Run, komorebic.exe focus %operation_direction%, , Hide Run, komorebic.exe focus %operation_direction%, , Hide
} }
Move(operation_direction) { Move(operation_direction) {
Run, komorebic.exe move %operation_direction%, , Hide Run, komorebic.exe move %operation_direction%, , Hide
} }
Stack(operation_direction) { Stack(operation_direction) {
Run, komorebic.exe stack %operation_direction%, , Hide Run, komorebic.exe stack %operation_direction%, , Hide
} }
Resize(edge, sizing) { Resize(edge, sizing) {
Run, komorebic.exe resize %edge% %sizing%, , Hide Run, komorebic.exe resize %edge% %sizing%, , Hide
} }
Unstack() { Unstack() {
Run, komorebic.exe unstack, , Hide Run, komorebic.exe unstack, , Hide
} }
CycleStack(cycle_direction) { CycleStack(cycle_direction) {
Run, komorebic.exe cycle-stack %cycle_direction%, , Hide Run, komorebic.exe cycle-stack %cycle_direction%, , Hide
} }
MoveToMonitor(target) { MoveToMonitor(target) {
Run, komorebic.exe move-to-monitor %target%, , Hide Run, komorebic.exe move-to-monitor %target%, , Hide
} }
MoveToWorkspace(target) { MoveToWorkspace(target) {
Run, komorebic.exe move-to-workspace %target%, , Hide Run, komorebic.exe move-to-workspace %target%, , Hide
} }
FocusMonitor(target) { FocusMonitor(target) {
Run, komorebic.exe focus-monitor %target%, , Hide Run, komorebic.exe focus-monitor %target%, , Hide
} }
FocusWorkspace(target) { FocusWorkspace(target) {
Run, komorebic.exe focus-workspace %target%, , Hide Run, komorebic.exe focus-workspace %target%, , Hide
} }
NewWorkspace() { NewWorkspace() {
Run, komorebic.exe new-workspace, , Hide Run, komorebic.exe new-workspace, , Hide
} }
AdjustContainerPadding(sizing, adjustment) { AdjustContainerPadding(sizing, adjustment) {
Run, komorebic.exe adjust-container-padding %sizing% %adjustment%, , Hide Run, komorebic.exe adjust-container-padding %sizing% %adjustment%, , Hide
} }
AdjustWorkspacePadding(sizing, adjustment) { AdjustWorkspacePadding(sizing, adjustment) {
Run, komorebic.exe adjust-workspace-padding %sizing% %adjustment%, , Hide Run, komorebic.exe adjust-workspace-padding %sizing% %adjustment%, , Hide
} }
ChangeLayout(layout) { ChangeLayout(layout) {
Run, komorebic.exe change-layout %layout%, , Hide Run, komorebic.exe change-layout %layout%, , Hide
} }
FlipLayout(flip) { FlipLayout(flip) {
Run, komorebic.exe flip-layout %flip%, , Hide Run, komorebic.exe flip-layout %flip%, , Hide
} }
Promote() { Promote() {
Run, komorebic.exe promote, , Hide Run, komorebic.exe promote, , Hide
} }
Retile() { Retile() {
Run, komorebic.exe retile, , Hide Run, komorebic.exe retile, , Hide
} }
EnsureWorkspaces(monitor, workspace_count) { EnsureWorkspaces(monitor, workspace_count) {
Run, komorebic.exe ensure-workspaces %monitor% %workspace_count%, , Hide Run, komorebic.exe ensure-workspaces %monitor% %workspace_count%, , Hide
} }
ContainerPadding(monitor, workspace, size) { ContainerPadding(monitor, workspace, size) {
Run, komorebic.exe container-padding %monitor% %workspace% %size%, , Hide Run, komorebic.exe container-padding %monitor% %workspace% %size%, , Hide
} }
WorkspacePadding(monitor, workspace, size) { WorkspacePadding(monitor, workspace, size) {
Run, komorebic.exe workspace-padding %monitor% %workspace% %size%, , Hide Run, komorebic.exe workspace-padding %monitor% %workspace% %size%, , Hide
} }
WorkspaceLayout(monitor, workspace, value) { WorkspaceLayout(monitor, workspace, value) {
Run, komorebic.exe workspace-layout %monitor% %workspace% %value%, , Hide Run, komorebic.exe workspace-layout %monitor% %workspace% %value%, , Hide
} }
WorkspaceTiling(monitor, workspace, value) { WorkspaceTiling(monitor, workspace, value) {
Run, komorebic.exe workspace-tiling %monitor% %workspace% %value%, , Hide Run, komorebic.exe workspace-tiling %monitor% %workspace% %value%, , Hide
} }
WorkspaceName(monitor, workspace, value) { WorkspaceName(monitor, workspace, value) {
Run, komorebic.exe workspace-name %monitor% %workspace% %value%, , Hide Run, komorebic.exe workspace-name %monitor% %workspace% %value%, , Hide
} }
TogglePause() { TogglePause() {
Run, komorebic.exe toggle-pause, , Hide Run, komorebic.exe toggle-pause, , Hide
} }
ToggleTiling() { ToggleTiling() {
Run, komorebic.exe toggle-tiling, , Hide Run, komorebic.exe toggle-tiling, , Hide
} }
ToggleFloat() { ToggleFloat() {
Run, komorebic.exe toggle-float, , Hide Run, komorebic.exe toggle-float, , Hide
} }
ToggleMonocle() { ToggleMonocle() {
Run, komorebic.exe toggle-monocle, , Hide Run, komorebic.exe toggle-monocle, , Hide
} }
ToggleMaximize() { ToggleMaximize() {
Run, komorebic.exe toggle-maximize, , Hide Run, komorebic.exe toggle-maximize, , Hide
} }
RestoreWindows() { RestoreWindows() {
Run, komorebic.exe restore-windows, , Hide Run, komorebic.exe restore-windows, , Hide
} }
Manage() { Manage() {
Run, komorebic.exe manage, , Hide Run, komorebic.exe manage, , Hide
} }
Unmanage() { Unmanage() {
Run, komorebic.exe unmanage, , Hide Run, komorebic.exe unmanage, , Hide
} }
ReloadConfiguration() { ReloadConfiguration() {
Run, komorebic.exe reload-configuration, , Hide Run, komorebic.exe reload-configuration, , Hide
} }
WatchConfiguration(boolean_state) { WatchConfiguration(boolean_state) {
Run, komorebic.exe watch-configuration %boolean_state%, , Hide Run, komorebic.exe watch-configuration %boolean_state%, , Hide
} }
FloatRule(identifier, id) { FloatRule(identifier, id) {
Run, komorebic.exe float-rule %identifier% %id%, , Hide Run, komorebic.exe float-rule %identifier% %id%, , Hide
} }
ManageRule(identifier, id) { ManageRule(identifier, id) {
Run, komorebic.exe manage-rule %identifier% %id%, , Hide Run, komorebic.exe manage-rule %identifier% %id%, , Hide
} }
WorkspaceRule(identifier, id, monitor, workspace) { WorkspaceRule(identifier, id, monitor, workspace) {
Run, komorebic.exe workspace-rule %identifier% %id% %monitor% %workspace%, , Hide Run, komorebic.exe workspace-rule %identifier% %id% %monitor% %workspace%, , Hide
} }
IdentifyTrayApplication(identifier, id) { IdentifyTrayApplication(identifier, id) {
Run, komorebic.exe identify-tray-application %identifier% %id%, , Hide Run, komorebic.exe identify-tray-application %identifier% %id%, , Hide
} }
FocusFollowsMouse(boolean_state) { 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()?)?;
} }