AntiMicroX / antimicrox

Graphical program used to map keyboard buttons and mouse controls to a gamepad. Useful for playing games with no gamepad support.
GNU General Public License v3.0
2.45k stars 141 forks source link

Investigate possibility of implementing of Auto Profile functionality for Wayland #303

Closed pktiuk closed 2 years ago

pktiuk commented 2 years ago

LInked with: https://github.com/AntiMicroX/antimicrox/issues/301

Check whether Autoprofile Functionality is doable with wayland API.

If yes then implement it, if no make visible note about it in app.


UPDATE

This functionality will be broken until flatpak/wayland will implement any way of getting info about active windows:

You can track the progress of this task here https://github.com/flatpak/xdg-desktop-portal/issues/304 (but there is a very low chance of getting it anytime soon)


Upvote & Fund

Fund with Polar

Figuera commented 2 years ago

It should be possible. At least in wlroots (the Sway Compositor) matching windows is a little difference than from X. We usually use 3 windows properties:

app_id: Window's name. For Wayland native Windows. class: Window's class name. For X windows running on Xwayland. title: Window's public title. For both Wayland and X windows, generally used as a secondary matching option.

I will probably be able to implement the functionally on my machine using Sway + AntiMicroX CLI

pktiuk commented 2 years ago

I will probably be able to implement the functionally on my machine using Sway + AntiMicroX CLI

Really? That would be great.

pktiuk commented 2 years ago

Are there any (popular) DE-s which will not be compatible with your implementation?

Figuera commented 2 years ago

My initial implementation was proven faulty. I could get the profile to change when my target window is created but not when it is switched out or into focus. I will give it a look and try create a more complex script.

Are there any (popular) DE-s which will not be compatible with your implementation?

Unfortunately I am not capable to answer that question in its full. Sway is a i3 like windows manager so we get a lot of mid level configuration easily available.

For other popular desktop environment things would be different. But, for example, Gnome based desktops are using Mutter, which is the same for X and Wayland, so I would imagine that whatever you guys are currently doing for X should work for Wayland with some tweaks.

pktiuk commented 2 years ago

which is the same for X and Wayland, so I would imagine that whatever you guys are currently doing for X should work for Wayland with some tweaks.

I was not aware of that, maybe there are some universal ways of obtaining info about currently opened windows.

pktiuk commented 2 years ago

My initial implementation was proven faulty. I could get the profile to change when my target window is created but not when it is switched out or into focus. I will give it a look and try create a more complex script.

I am not sure whether is it worth your effort to work with solution making this feature available for only small fraction of users. I will try to look for something more universal.

Figuera commented 2 years ago

My initial implementation was proven faulty. I could get the profile to change when my target window is created but not when it is switched out or into focus. I will give it a look and try create a more complex script.

I am not sure whether is it worth your effort to work with solution making this feature available for only small fraction of users. I will try to look for something more universal.

I understand. I do not intend to send a pull request. It is more of a personal project while you guys can implement the feature.

Sorry for not being able to be of greater help.

pktiuk commented 2 years ago

At first glance this seems to be not implementable (at least not easily because of security reasons: https://stackoverflow.com/questions/45465016/how-do-i-get-the-active-window-on-gnome-wayland)

Figuera commented 2 years ago

At first glance this seems to be not implementable (at least not easily because of security reasons: https://stackoverflow.com/questions/45465016/how-do-i-get-the-active-window-on-gnome-wayland)

A shame that mutter hasn't implemented the protocol. Although, from what I understood, it is possible through some other (possibly unreliable) Gnome API.

I did manage to get it working on my machine using a python script, I will keep it here in case somewhere else is interested and stumble in this thread:

My python daemon:

https://pastebin.com/raw/2stA0hBv

The configuration file (Maps windows to profiles):

https://pastebin.com/raw/Jas1KYL6

It is still a naive implementation. I am not experience in writing this type of software and I haven't tested it extensively but it seems to be working fine for my needs.

pktiuk commented 2 years ago

This script is a good workaround for sway users.
Unluckily, other users can't use it.

I am closing because it is not implementable (at least for now) :disappointed: .

pktiuk commented 2 years ago

This functionality will be broken until flatpak/wayland will implement any way of getting info about active windows: