jtroo/kanata

Application-aware layer switching

jtroo opened this issue ยท 10 comments

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)

jtroo commented

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 commented

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

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

jtroo commented

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

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?

veyxov commented

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.

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.

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

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