Commit Graph

30 Commits

Author SHA1 Message Date
LGUG2Z
a59bbacb29 feat(tracing): use hook to log errors on panics
The two bugs raised in issues #1 and #2 were due to panics that were not
visible in the logs, which left the process hanging and unresponsive,
ultimately needing to be force killed with a command like 'Stop-Process
-Name komorebi'.

The only way to even verify that a panic had taken place and what the
panic related to, was to run '$env:RUST_BACKTRACE ='full';
komorebi.exe', wait for the panic, then restore the now-hidden window
with 'komorebic restore-windows' to finally see the panic message.

This commit integrates an example from the 'tracing' repo,  which
through the addition of a panic hook, logs out panics as errors.
Hopefully this will debugging much easier in the future.

re #1, re #2
2021-08-15 06:42:10 -07:00
LGUG2Z
a53b2cc28c fix(wm): skip layout calc for empty workspaces
While investigating issue #2 I was able to reproduce it and view the
panic that causes the komorebi process to become non-responsive.

When switching to a columnar layout (which is the default for the 2nd
workspace in the sample ahk config), there is the possibility to cause a
divide by zero panic if the len passed to Layout::calculate is 0.

I have remedied this by changing the type of len from usize to
NonZeroUsize, and also by ensuring that Layout::calculate is only called
from within the komorebi crate if the workspace has at least one
container.

While moving containers around I also noticed that creating a new
container for a window may also cause a panic if focused_idx + 1 is
greater than the length of the VecDeque of containers, so this was
addressed by pushing to the back of the VecDeque in that case.

re #2
2021-08-15 06:27:54 -07:00
LGUG2Z
a550c088dc fix(wm): don't attach to the desktop window thread
Noticed in the logs when looking at issue #2 that an "Access is denied.
(os error 5)" error was being reported when trying to attach to the
thread of the special Desktop Window, which only happens when switching
to a workspace which doesn't contain any windows. Calling
WindowsApi::set_foreground_window on the HWND directly seems to be the
better option here.
2021-08-14 21:39:20 -07:00
LGUG2Z
820432f9d4 feat(wm): add per-workspace tiling config + toggle
Added two commands, 'komorebic toggle-tiling' and 'komorebic
workspace-tiling MONITOR_IDX WORKSPACE_IDX on|off' which allow for
tiling on the currently focused workspace to be toggled on and off, and
for the tiling for a specific workspace to be set to on or off (useful
if you want a specific workspace to always have tiling set to off at
startup).

resolve #5
2021-08-14 10:19:32 -07:00
LGUG2Z
b8929cbead feat(wm): add command to create new workspace
This commit adds a new command, 'komorebic.exe new-workspace', which
will append a new, empty workspace, to the list of workspaces on the
currently focused monitor, and then switch focus to it.

Also took the opportunity to clean up some unnecessary unwraps in
komorebic/src/main.rs.

resolve #4
2021-08-14 09:42:12 -07:00
LGUG2Z
91ddb2c22b feat(ahk): autoload config on start
When AutoHotKey is detected, and %USERPROFILE%\komorebi.ahk exists,
komorebi.exe will now try to run the ahk script after starting the
command listener.

For this to work smoothly, it is important to set the #SingleInstance
directive to Force in komorebi.ahk, which will ensure that duplicates of
the script are not run, and a new version of the script is loaded
without displaying a GUI confirmation prompt.

resolve #3
2021-08-14 07:53:40 -07:00
LGUG2Z
55b62c2bc9 fix(wm): check resize_dimensions before removing
A user, possibly using multiple monitors, reported a panic on startup
which I traced back to an unchecked remove op on a Vec. Spent so much
time working with VecDeque that I forgot that removing from a Vec panics
instead of returning an Option<T>.

This change ensures that when trying to remove a container's resize
dimensions in a workspace, we check that the container actually has a
corresponding resize dimension before calling remove.

Similarly, in order to ensure consistency with workspace updates which
always resize the length of the resize dimensions to match the length of
the number of container layouts, sets the length of the resize
dimensions array when initialising a workspace in
WindowsApi::load_workspace_information.

fix #1
2021-08-14 07:02:12 -07:00
LGUG2Z
0d3751a7cc refactor(wm): reduce boilerplate with getset
This commit introduces the getset crate to reduce a lot of the
boilerplate, especially in workspace.rs, around different variations of
getters. Hopefully this will make the codebase easier to navigate for
contributors in the future.

Also trying to avoid pinning to patch versions and minor versions
wherever possible.
2021-08-13 10:38:11 -07:00
LGUG2Z
c15f1e1d7b ci(windows): add basic build pipeline
Adding a basic MSVC build pipeline based on the workflows used in the
rustup repo.
2021-08-10 12:48:15 -07:00
LGUG2Z
579a5556cc refactor(ring): gen element impls using macro
Using macros to generate common type-specific Ring element accessors.
Should make codebase navigation a little easier my making logic-heavy
functions more visible in impl blocks.
2021-08-10 08:10:56 -07:00
LGUG2Z
be1d07e397 fix(wm): enforce resize constraints universally
Previously resize constraints on odd and even container numbers were not
being enforced consistently. Now, instead of trying to enforce them on
individual operations, every time an update operation is called for a
workspace, the resize constraints will be enforced before trying to
calculate and apply an updated layout.
2021-08-09 12:27:03 -07:00
LGUG2Z
f3661325d9 feat(wm): add focus follows mouse toggle 2021-08-09 07:49:00 -07:00
LGUG2Z
8b4ce48a66 feat(wm): add container resizing
The last remaining feature to bring komorebi to feature parity with
yatta. Implementing this in komorebi was a lot harder because I had to
make sure that resizing worked even when the layout is flipped (in any
one of the three possible ways).

In yatta, resize dimension information was stored on the window. In
komorebi, I initially tried storing this information on the Container
itself, but eventually decided to store it for all Containers in the
Workspace.

There is some additional work required to ensure that this Vec is kept
up to date whenever containers are added or destroyed, but it all seems
to be working fairly well.

I got rid of the iterative fibonacci code that I adapted from leftwm and
went back and reworked the recursive code that I was using in yatta
(originally from umberwm I think) to integrate layout flipping. At least
for me, it is much easier to reason about.
2021-08-08 23:04:35 -07:00
LGUG2Z
ca27730b01 fix(operation_direction): adjust for layout flips
If the BSP layout was flipped on the X or Y axis (or both),
OperationDirection commands would not adjust their directions
accordingly and prevent the user from focusing, moving etc in a valid
direction on the flipped layout.

This commit addresses that bug by ensuring that we always try to apply
any axis adjustments to an OperationDirection before calling the
is_valid or new_idx functions.
2021-08-06 14:57:18 -07:00
LGUG2Z
f97cdf7c15 refactor(windows_api): gen from impls using macro
My first time writing a macro. Figured I could clean up the repetition a
little by using a macro to generate From impls for WindowsResult on the
primative integer types that various windows-rs functions return.
2021-08-06 11:16:14 -07:00
LGUG2Z
88d6eee7af fix(wm): clean stale floating windows from state
Floating windows that were minimised or destroyed remained in the
Workspace state because the call to workspace.remove_window() was only
checking containers for a matching hwnd.

This commit ensures that floating windows are checked before other
window containers and removes the window from the Workspace state if
necessary.

This commit also adds steam.exe to the MULTI_WINDOW_EXES list to ensure
the expected behaviour when responding to an ObjectHide event.
2021-08-06 08:23:26 -07:00
LGUG2Z
bebf2f791a docs(readme): add screenshot, features and debugging info 2021-08-06 07:57:49 -07:00
LGUG2Z
b456097ca2 fix(wm): track programmatically hidden hwnds
Introducing another global Vec to keep track of HWNDs that have been
hidden by komorebi, so that when responding to ObjectHide WinEvents, we
don't stop managing windows that we have hidden when cycling through
container stacks.
2021-08-05 19:49:12 -07:00
LGUG2Z
b96a302451 docs(readme): initial readme, license and sample config 2021-08-05 18:16:49 -07:00
LGUG2Z
0ca3320939 refactor(logging): make use of tracing::instrument 2021-08-05 13:46:22 -07:00
LGUG2Z
77aa4c0d21 feat(debug): track and hard-restore hwnds
This stores a constantly updated list of known HWNDs at
~/komorebi.hwnd.json which can be used to restore windows that may
disappear into a permanently hidden state during development using a new
'restore-windows' command with komorebic.
2021-08-05 11:36:07 -07:00
LGUG2Z
da8214cdc7 fix(wm): switch only to different workspaces
Previously a Show event when clicking Firefox tabs would trigger a
refocusing of monitors and workspaces every time for a known hwnd, which
meant that in practice, the tab would be taken out of the current window
and a new window would be created.

This commit ensures that the workspace switch is only done if it would
be to a different monitor/workspace combination.
2021-08-05 09:52:03 -07:00
LGUG2Z
73568922d5 fix(workspaces): let set_foreground_window fail
When hiding/restoring windows as part of workspace switching, calls to
SetForegroundWindow fail, and if they fail, other hidden windows get
lost forever in hidden mode when the error is returned up the call chain
using the ? operator.

This commit separates out the focus() calls from the loops restoring
windows when switching workspaces, and also ensures that calls to
SetForegroundWindow will log an error, but ultimately continue to the
end of the focus() function call.
2021-07-30 21:05:02 -07:00
LGUG2Z
b867db1900 fix(wm): switch to focused workspace
This commit fixes corruption of workspace state when clicking a link
brings to the foreground a window in a different workspace, and also
ensures that the workspace containing the window coming to the
foreground will be focused and switched to as part of the Show event.
2021-07-30 14:41:59 -07:00
LGUG2Z
230b534735 feat(wm): add query command to cli
Added a query command to komorebic to return the WindowManager struct
serialized to JSON to help with debugging and maybe help others to build
tools like stackline for yabai in the future.
2021-07-30 14:11:09 -07:00
LGUG2Z
793ba51695 fix(wm): add settings to multi-window exes 2021-07-30 12:29:28 -07:00
LGUG2Z
8c939328d1 feat(wm): ensure workspace count
Allow the number of workspaces for a given monitor to be pre-created, so
that configuration options can be sent (name, padding, layout) before
the workspace has ever been activated.
2021-07-30 12:06:31 -07:00
LGUG2Z
d8a717950c fix(wm): unmanage multi-window exes on hide
Looks like explorer.exe is not the only one. Making the comparison
against a list instead.
2021-07-30 10:59:23 -07:00
LGUG2Z
b0c3480262 fix(wm): float/monocle toggle, invisible borders
This commit fixes issues with toggling on and off Monocle and Floating
Window mode by ensuring that the relevant windows are always at the top
of the Z order, and in the latter case, ensuring that the top visible
window is used to search the local floating window state of the process.

After some experimenting I seem to have been able to adjust to remove
all of the invisible window borders by default, so if desired, a user
can now have no gaps at all.

Also upgraded to the latest version of the windows-rs crate since I saw
it was available. Thankfully no breaking changes.
2021-07-30 10:44:31 -07:00
LGUG2Z
61cee458a1 feat(wm): initial commit
One week of blissful, in-the-zone coding, applying all of the lessons
learnt from the development of yatta.
2021-07-29 16:23:42 -07:00