Manipulate windows by hwnd #58

Closed
opened 2026-01-05 14:47:58 +01:00 by adam · 5 comments
Owner

Originally created by @oHaiyang on GitHub (Nov 19, 2021).

First of all, I have to say surely komorebi is the best implementation of Windows tilling window manager so far (I have tried another two before ).

I use i3 on Linux a lot, sometimes I switch to windows 11. I strongly rely on the Scratchpad feature of i3(to call out or hide my terminal), and I am trying to implement an AHK script to mimic Scratchpad on komorebi. Then I found a window managed by komorebi can only be manipulated if it is focused. In my case, it should be wonderful if I can use komorebi commands to manipulate a specific window identified by hwnd.

I am not an experienced rust developer and haven't learned the source code yet, but I still want to ask If that is possible for komorebi, is it very hard or relatively easy, should I as a newbie 😅 rust developer to diving into the problem?

Thanks!

Originally created by @oHaiyang on GitHub (Nov 19, 2021). First of all, I have to say surely komorebi is the best implementation of Windows tilling window manager so far (I have tried another two before ). I use i3 on Linux a lot, sometimes I switch to windows 11. I strongly rely on the [Scratchpad]( https://i3wm.org/docs/userguide.html#_scratchpad) feature of i3(to call out or hide my terminal), and I am trying to implement an AHK script to mimic Scratchpad on komorebi. Then I found a window managed by komorebi can only be manipulated if it is focused. In my case, it should be wonderful if I can use komorebi commands to manipulate a specific window identified by hwnd. I am not an experienced rust developer and haven't learned the source code yet, but I still want to ask If that is possible for komorebi, is it very hard or relatively easy, should I as a newbie 😅 rust developer to diving into the problem? Thanks!
adam added the enhancement label 2026-01-05 14:47:58 +01:00
adam closed this issue 2026-01-05 14:47:58 +01:00
Author
Owner

@LGUG2Z commented on GitHub (Nov 19, 2021):

I'm not very familiar with i3 or scratchpads but after Googling a little I found this video which gave me a pretty good idea of how this works.

I think it should be possible to expose commands to Show, Hide (and probably Minimize) windows based on either their HWND or their titles.

Given that the main use of the scratchpad seems to revolve around terminal windows, and that Windows Terminal has the possibility to explicitly name terminal instances and prevent processes from overriding the window title, it would probably be more ergonomic to focus on doing this using titles than requiring the user to use the title to look up the HWND themselves.

I'm not sure how to go about storing references to these scratchpad windows in the window manager state; given that they are never part of the tiling layout hierarchy, they could possibly be stored as floating windows, though there is currently an assumption that floating windows are by default always visible on the workspace they are associated with.

I will spend some time thinking about how to approach this under the hood a little bit more. Any suggestions on how to integrate something like this cleanly are welcome!

@LGUG2Z commented on GitHub (Nov 19, 2021): I'm not very familiar with i3 or scratchpads but after Googling a little I found [this video](https://www.youtube.com/watch?v=q-l7DnDbiiU) which gave me a pretty good idea of how this works. I think it should be possible to expose commands to Show, Hide (and probably Minimize) windows based on either their HWND or their titles. Given that the main use of the scratchpad seems to revolve around terminal windows, and that Windows Terminal has the possibility to [explicitly name terminal instances and prevent processes from overriding the window title](https://docs.microsoft.com/en-us/windows/terminal/command-line-arguments?tabs=windows#using-application-title), it would probably be more ergonomic to focus on doing this using titles than requiring the user to use the title to look up the HWND themselves. I'm not sure how to go about storing references to these scratchpad windows in the window manager state; given that they are never part of the tiling layout hierarchy, they could possibly be stored as floating windows, though there is currently an assumption that floating windows are by default always visible on the workspace they are associated with. I will spend some time thinking about how to approach this under the hood a little bit more. Any suggestions on how to integrate something like this cleanly are welcome!
Author
Owner

@oHaiyang commented on GitHub (Nov 22, 2021):

Hi LGUG2Z, I am glad to share that I found a way to roughly mimic ScratchPad behavior 😄 .

I checked the link you posted which set the Windows Terminal title suppressed. however, that does not work, the command line arguments only set Tab Title, not Windows Title which can be used to set komorebic rules.

But I got the idea that to set Window Title using AHK WinSetTitle API, here is what I did:

  1. add an float-rule in my AHK script: Run, komorebic.exe float-rule title "Windows Terminal ScratchPad", , Hide
  2. set AHK shortcut to update the window title and toggle float on the fly
!+-::
WinGet, active_id, ID, A
WinGetTitle, OriginalTitle, A
WinSetTitle, A, , %OriginalTitle% ScratchPad
Run, komorebic.exe toggle-float, , Hide
return
  1. summon a Quake Window by Windows Terminal quakeMode action
  2. use the shortcut in 1 to update the window
  3. use the same shortcut in 2 to summon/hide the terminal

I'm not sure step 0 is required or not. Because, in my test, the rule has no effect when the title is updated on the fly, I have to manually toggle float in step 1 shortcuts.

@oHaiyang commented on GitHub (Nov 22, 2021): Hi LGUG2Z, I am glad to share that I found a way to roughly mimic ScratchPad behavior 😄 . I checked the link you posted which set the Windows Terminal title suppressed. however, that does not work, the command line arguments only set **Tab Title**, not **Windows Title** which can be used to set komorebic rules. But I got the idea that to set Window Title using [AHK WinSetTitle API](https://www.autohotkey.com/docs/commands/WinSetTitle.htm), here is what I did: 0. add an float-rule in my AHK script: `Run, komorebic.exe float-rule title "Windows Terminal ScratchPad", , Hide` 1. set AHK shortcut to update the window title and toggle float on the fly ```ahk !+-:: WinGet, active_id, ID, A WinGetTitle, OriginalTitle, A WinSetTitle, A, , %OriginalTitle% ScratchPad Run, komorebic.exe toggle-float, , Hide return ``` 2. summon a [Quake Window](https://docs.microsoft.com/en-us/windows/terminal/tips-and-tricks#quake-mode) by Windows Terminal [`quakeMode` action](https://docs.microsoft.com/en-us/windows/terminal/customize-settings/actions#open-the-quake-mode-window) 3. use the shortcut in `1` to update the window 4. use the same shortcut in `2` to summon/hide the terminal I'm not sure step 0 is required or not. Because, in my test, the rule has no effect when the title is updated on the fly, I have to manually toggle float in step 1 shortcuts.
Author
Owner

@oHaiyang commented on GitHub (Nov 23, 2021):

Okay, there is a problem with the steps above. Whenever switching back to the workspace Quake Window is initially created, the Quake Window is always active, even I have made it hidden in the previous workspace.

Update:
Found the solution for the problem above: make the Quake Window be created in a workspace that is barely used(eg. the 10th workspace).

@oHaiyang commented on GitHub (Nov 23, 2021): Okay, there is a problem with the steps above. Whenever switching back to the workspace Quake Window is initially created, the Quake Window is always active, even I have made it hidden in the previous workspace. Update: Found the solution for the problem above: make the Quake Window be created in a workspace that is barely used(eg. the 10th workspace).
Author
Owner

@neondeex commented on GitHub (Nov 21, 2023):

@oHaiyang Do you think i will be able to do this with the file explorer?

@neondeex commented on GitHub (Nov 21, 2023): @oHaiyang Do you think i will be able to do this with the file explorer?
Author
Owner

@ECon65 commented on GitHub (Sep 5, 2024):

would be nice to see a komorebi native scratchpad implementation. scratchpads are not just about terminals. you can place any window which you want to access quickly into scratchpad. That way you don't need to switch workspaces if you just want to make small adjustment in that window.

  • terminal
  • quick note taking
  • media player (changing a song or opening new album)
  • messaging
  • etc.
@ECon65 commented on GitHub (Sep 5, 2024): would be nice to see a komorebi native scratchpad implementation. scratchpads are not just about terminals. you can place any window which you want to access quickly into scratchpad. That way you don't need to switch workspaces if you just want to make small adjustment in that window. - terminal - quick note taking - media player (changing a song or opening new album) - messaging - etc.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/komorebi#58