sergei-mironov / xkb-switch

Switch your X keyboard layouts from the command line
MIT License
353 stars 40 forks source link

Doesn't work with Wayland #64

Open moceap opened 2 years ago

moceap commented 2 years ago

Can't detect current keyboard layout in Wayland session.

sergei-mironov commented 2 years ago

Unfortunately, it is a strictly X11 app right now. Try to find another tool for Wayland.

sergei-mironov commented 2 years ago

Originally I had no Wayland devices to think about it's support, but now I have a Pinephone which uses Wayland, so at least I can compile and run examples.

I think that it is not a good idea to integrate Wayland support to the originally-X11-only XkbSwitch.cpp files, but we may think about writing a separate tool with the same command-line interface.

Do you have any good examples of working with keyboard using this protocol?

timsofteng commented 2 years ago

@grwlf I use sway and layout can be changed with swaymsg externally. It should not be hard to implement it.

sergei-mironov commented 2 years ago

Afaik, X applications should run under Wayland's X compatibility layer called XWayland https://wayland.freedesktop.org/docs/html/ch05.html Has anybody tried it with xkb-switch?

1nikolas commented 1 year ago

Afaik, X applications should run under Wayland's X compatibility layer called XWayland https://wayland.freedesktop.org/docs/html/ch05.html Has anybody tried it with xkb-switch?

Yes it does run under xwayland but it seems xwayland doesn't sync the keyboard layouts with wayland.. It's like its own separate thing, I can set my layouts with setxkbmap and switch them/query them with xkb-switch but they don't affect the real keyboard layout in wayland. I have no idea where to open an issue about that..

FrolovRuslan1 commented 10 months ago

Afaik, X applications should run under Wayland's X compatibility layer called XWayland https://wayland.freedesktop.org/docs/html/ch05.html Has anybody tried it with xkb-switch?

Hello again. I can help develop xkb-switch under Wayland. Wayland support libxkbcommon and Wayland API libwayland. Here is my test code where I can get list of layouts. BUT how I found out here libxkbcommon doesnt have tools to switch layouts.

I have ru and us layouts. Here tests on Debian: In Plasma Wayland:

  1. -> % xkb-switch --list
    us
  2. -> % ./wxkb_switch    
    It prints keyboard layout only via xkbcommon
    num: 1
    English (US)
    It prints keyboard layout via xkbcommon and wayland
    num: 2
    English (US)
    Russian

In Plasma X11: 1.

-> % xkb-switch --list
us
ru

2.

-> % ./wxkb_switch
It prints keyboard layout only via xkbcommon
num: 1
English (US)
Failed to connect to Wayland display
sergei-mironov commented 10 months ago

@FrolovRuslan1 I would be happy to accept the PR. Have some questions:

  1. What do you think, can we write an abstraction which would run the existing code on X, and the wayland code you have prototyped if we are on wayland? I think we can depart from making this class a C-structure with function pointers pointing to either X11 or Wayland implementations depending on the build configuration flag? (I am ok with moving towards pure-C implementation)
  2. What changes do we need in the CMake?
FrolovRuslan1 commented 10 months ago

@FrolovRuslan1 I would be happy to accept the PR. Have some questions:

1. What do you think, can we write an abstraction which would run the existing code on X, and the wayland code you have prototyped if we are on wayland?  I think we can depart from making [this class](https://github.com/grwlf/xkb-switch/blob/master/src/XKeyboard.hpp) a C-structure with function pointers pointing to either X11 or Wayland implementations depending on the build configuration flag? (I am ok with moving towards pure-C implementation)

2. What changes do we need in the CMake?

I checked XKeyboard.hpp and yes, we can write an abstraction for Wayland. I think we can create Class automatically depends on environment variables. Or we can split the project on two. One for the X11 and one for Wayland because if we will be make project based on dependence of build configuration flag or runtime variable then the project growing up to unreadable size, moreover, I do not think that a new X11 analogue will appear under Linux in the near future.

P.S. I tested setxkbmap it is working but it crash DE switching. If you can please open issue for user help on Wayland and ask like that "Is Wayland have standard methods for switching keyboard layouts because xkbcommon doesnt have and setxkbmap crash DE switching layout." because for some reason I cant singup and register on Gitlab even through VPN it just doesnt send on google email. I think if Wayland doesnt have such methods then we can use libxkbcommon for getting information about keyboard and setting via setxkbmap or yours implementation.

UPDATE 15.12.2023: Open issue in Wayland.

lolmaus commented 3 months ago

Any progress on this one? :pray:

FrolovRuslan1 commented 3 months ago

Any progress on this one? 🙏

I hope that I get time at this summer for work at xkb-switch and my openswitcher projects, I have lot of work and study