Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Application-aware layer switching #40

Closed
jtroo opened this issue Jul 17, 2022 · 10 comments
Closed

Application-aware layer switching #40

jtroo opened this issue Jul 17, 2022 · 10 comments
Labels
enhancement New feature or request PRs welcome jtroo has no plans to work on this at present, but PRs are welcome

Comments

@jtroo
Copy link
Owner

jtroo commented Jul 17, 2022

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 jtroo added the enhancement New feature or request label Jul 17, 2022
@13minutes-yt
Copy link

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
Copy link
Owner Author

jtroo commented Jul 28, 2022

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 jtroo added the PRs welcome jtroo has no plans to work on this at present, but PRs are welcome label Aug 6, 2022
@jtroo
Copy link
Owner Author

jtroo commented Aug 6, 2022

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

@13minutes-yt
Copy link

13minutes-yt commented Dec 18, 2022

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
Copy link
Owner Author

jtroo commented Dec 18, 2022

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

@gerhard-h
Copy link
Contributor

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
Copy link
Contributor

veyxov commented Jul 19, 2023

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.

@Aqaao
Copy link

Aqaao commented Feb 20, 2024

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.

@reidprichard
Copy link
Contributor

reidprichard commented Feb 20, 2024

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

@jtroo
Copy link
Owner Author

jtroo commented Feb 22, 2024

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

Repository owner locked and limited conversation to collaborators Feb 22, 2024
@jtroo jtroo converted this issue into discussion #770 Feb 22, 2024

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
enhancement New feature or request PRs welcome jtroo has no plans to work on this at present, but PRs are welcome
Projects
None yet
Development

No branches or pull requests

6 participants