kanata icon indicating copy to clipboard operation
kanata copied to clipboard

Application-aware layer switching

Open jtroo opened this issue 2 years ago • 3 comments

For Linux, can use https://github.com/k0kubun/xremap for inspiration.

For Windows: https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getforegroundwindow

jtroo avatar Jul 17 '22 05:07 jtroo

Is tcp server needed? In linux xdotool can get the activewindow xdotool getactivewindow getwindowclassname and xdotool can also simulate keystroke movements( based on result of getactivewindow) xdotool keydown n (can be used to switch to layer)

13minutes-yt avatar Jul 28 '22 23:07 13minutes-yt

The TCP server is not necessary for this particular feature as you've shown. There can be workarounds that don't involve inter-process communication.

However, the TCP server is nice to have for software integrations.

jtroo avatar Jul 28 '22 23:07 jtroo

For ease of discovery:

  • Windows has the komokana project that integrates with kanata's TCP server
  • Linux has no fancy solution, but as 13minutes-yt said, xdotool could be one way to do this

jtroo avatar Aug 06 '22 05:08 jtroo

Just a thought. I have been using Espanso as a text expander and noticed they have application aware triggers. Can't a crate be used in kanata for that purpose? https://github.com/espanso/espanso/search?q=Appinfo

13minutes-yt avatar Dec 18 '22 07:12 13minutes-yt

Yep, that's a good reference to use if one were to implement this in kanata.

https://github.com/espanso/espanso/tree/9f82b4e146e6090897c876a02f5eee697b85e979/espanso-info

jtroo avatar Dec 18 '22 11:12 jtroo

espanso offers similar features than autohotkey hotstrings, and similar to ahk hotstrings espanso won't work while kanata is running (at least on windows).

But if we could tell espanso to listen to the kanata ouput instead of the real keyboard it should work? Is the kanata tcp server the right thing to use to make espanso listen to it?

gerhard-h avatar Dec 19 '22 09:12 gerhard-h

I quickly put together a rough draft.

~~It uses swaymsg~~ for getting information about windows (wayland/sway) which also shows which windows is focused. I searched, but it seems there is no universal way to get this information in wayland, so this only works in sway.

Sends a request to change the layer to the current window name.

Needs significant improvements, for example switch to the default layer, if current window is not in the list of application-specific layers.

Here is the code: https://github.com/veyxov/qanata (sorry for the name 😅)

Updates: Saw the xremap implementation for sway, it looks a lot cleaner. Maybe I can integrate some parts from that. Now using swayipc to get the window name.

veyxov avatar Jul 19 '23 18:07 veyxov

I use SetWinEventHook implemented a simple tool in windows: kanawin. This is my first code with rust. I referenced ChatGPT and komokana. This might help a little.

Aqaao avatar Feb 20 '24 04:02 Aqaao

Wow, would you believe that timing! I just finished my own daemon to interact with Kanata's TCP server. I guess it's pretty similar to kanawin with a few pros and cons.

Cons

  • It's not Rust :(
  • Looping is less efficient than using the Windows event hook (but I've yet to see it break 0% CPU usage in Task Manager)
  • No pattern matching for mapping applications to layers

Pros

  • For those of us with Rust skill issues, C isn't bad!
  • No config file needed. You open firefox.exe, layer "firefox" is activated.
  • Additional utility "window_manager" allows you to use hotkeys to save and activate windows. Always find yourself searching for that one browser window? Bind it to a hotkey and refocus it later with a single button press.
  • No dependencies
  • Doesn't need to run as administrator

While it's still a work in progress, it's 100% working on my end. I'd love feedback if anyone gives it a try!

Logo

Window Tools

https://github.com/reidprichard/window_tools

reidprichard avatar Feb 20 '24 22:02 reidprichard

I think it makes sense to convert this to a discussion instead of an open issue. With the TCP server it makes more sense to me to keep the functionality outside of kanata.

I also now added links to the community projects

jtroo avatar Feb 22 '24 13:02 jtroo