Skip to content
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

Improve Solaar rules in Wayland #1020

Closed
intelfx opened this issue Nov 29, 2020 · 114 comments · Fixed by #1461 or #1530
Closed

Improve Solaar rules in Wayland #1020

intelfx opened this issue Nov 29, 2020 · 114 comments · Fixed by #1461 or #1530

Comments

@intelfx
Copy link

intelfx commented Nov 29, 2020

Information

  • Solaar version: 1.0.4.r54.g0427e56
  • Distribution: Arch GNU/Linux
  • Kernel version: 5.8.x, 5.9.x
  • Output of solaar show:
  1: Craft Advanced Keyboard
     Device path  : /dev/hidraw1
     WPID         : 4066
     Codename     : Craft
     Kind         : keyboard
     Protocol     : HID++ 4.5
     Polling rate : 8 ms (125Hz)
     Serial number: 02AFBAD2
     Model ID:      B35040660000
     Unit ID:       78CEC42D
        Bootloader: BOT 41.01.B0015
          Firmware: MPK 07.01.B0015
             Other:
             Other:
     The power switch is located on the edge of top right corner.
     Supports 39 HID++ 2.0 features:
         0: ROOT                   {0000}
         1: FEATURE SET            {0001}
         2: DEVICE FW VERSION      {0003}
            Firmware: Bootloader BOT 41.01.B0015 0000B6A2C54601
            Firmware: Firmware MPK 07.01.B0015 4066B6A2C54601
            Firmware: Other
            Firmware: Other
            Unit ID: 78CEC42D  Model ID: B35040660000  Transport IDs: {'btleid': 'B350', 'wpid': '4066'}
         3: DEVICE NAME            {0005}
            Name: Craft Advanced Keyboard
            Kind: keyboard
         4: WIRELESS DEVICE STATUS {1D4B}
         5: RESET                  {0020}
         6: DEVICE FRIENDLY NAME   {0007}
         7: BATTERY STATUS         {1000}
            Battery: 50%, discharging, next level 20%.
         8: CHANGE HOST            {1814}
            Change Host: 1:able
         9: HOSTS INFO             {1815}
            Host 0 (paired):
            Host 1 (paired): ARCADIA
            Host 2 (paired): whitepad
        10: BACKLIGHT2             {1982}
            Backlight: True
        11: REPROG CONTROLS V4     {1B04}
            Key/Button Diversion: {'209': 0, '210': 0, '211': 0, '199': 0, '200': 0, '224': 0, '225': 0, '110': 0, '226': 0, '227': 0, '228': 0, '229': 0, '230': 0, '231': 0, '232': 0, '233': 0, '10': 0, '191': 0, '234': 0, '111': 0, '236': 0, '235': 0}
        12: PERSISTENT REMAPPABLE ACTION {1C00}
        13: K375S FN INVERSION     {40A3}
            Swap Fx function: False
        14: ENCRYPTION             {4100}
        15: LOCK KEY STATE         {4220}
        16: KEYBOARD DISABLE KEYS  {4521}
            Disable keys: {'1': False, '2': False, '4': False, '8': False, '16': False}
        17: MULTIPLATFORM          {4531}
            Set OS: Windows
        18: CROWN                  {4600}
            Divert crown events: False
        19: DFUCONTROL SIGNED      {00C2}
        20: unknown:1803           {1803}   internal, hidden
        21: CONFIG DEVICE PROPS    {1806}   internal, hidden
        22: unknown:1813           {1813}   internal, hidden
        23: OOBSTATE               {1805}   internal, hidden
        24: unknown:1830           {1830}   internal, hidden
        25: unknown:1890           {1890}   internal, hidden
        26: unknown:1891           {1891}   internal, hidden
        27: unknown:1801           {1801}   internal, hidden
        28: unknown:18A1           {18A1}   internal, hidden
        29: unknown:9280           {9280}   internal, hidden
        30: unknown:1A20           {1A20}   internal, hidden
        31: unknown:1DF3           {1DF3}   internal, hidden
        32: unknown:1E00           {1E00}   hidden
        33: unknown:1EB0           {1EB0}   internal, hidden
        34: unknown:1861           {1861}   internal, hidden
        35: unknown:18B0           {18B0}   internal, hidden
        36: unknown:92C0           {92C0}   internal, hidden
        37: unknown:9203           {9203}   internal, hidden
        38: unknown:3615           {3615}   internal, hidden
     Has 24 reprogrammable keys:
         0: Host Switch Channel 1     , default: HostSwitch Channel 1        => HostSwitch Channel 1
             nonstandard, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
         1: Host Switch Channel 2     , default: HostSwitch Channel 2        => HostSwitch Channel 2
             nonstandard, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
         2: Host Switch Channel 3     , default: HostSwitch Channel 3        => HostSwitch Channel 3
             nonstandard, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
         3: Brightness Down           , default: Brightness Down             => Brightness Down
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:1, group:0, group mask:empty
             reporting: default
         4: Brightness Up             , default: Brightness Up               => Brightness Up
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:2, group:0, group mask:empty
             reporting: default
         5: Mission Control/Task View , default: Mission Control/Task View   => Mission Control/Task View
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:3, group:0, group mask:empty
             reporting: default
         6: Dashboard Launchpad/Action Center, default: Dashboard Launchpad/Action Center => Dashboard Launchpad/Action Center
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:4, group:0, group mask:empty
             reporting: default
         7: Show Desktop              , default: Show Desktop                => Show Desktop
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:5, group:0, group mask:empty
             reporting: default
         8: Backlight Down            , default: Backlight Down              => Backlight Down
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:6, group:0, group mask:empty
             reporting: default
         9: Backlight Up              , default: Backlight Up                => Backlight Up
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:7, group:0, group mask:empty
             reporting: default
        10: Previous Fn               , default: Previous                    => Previous
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:8, group:0, group mask:empty
             reporting: default
        11: Play/Pause Fn             , default: Play/Pause                  => Play/Pause
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:9, group:0, group mask:empty
             reporting: default
        12: Next Fn                   , default: Next                        => Next
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:10, group:0, group mask:empty
             reporting: default
        13: Mute Fn                   , default: Mute                        => Mute
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:11, group:0, group mask:empty
             reporting: default
        14: Volume Down Fn            , default: Volume Down                 => Volume Down
             is FN, FN sensitive, reprogrammable, divertable, persistently divertable, pos:12, group:0, group mask:empty
             reporting: default
        15: Volume Up Fn              , default: Volume Up                   => Volume Up
             nonstandard, reprogrammable, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
        16: Calculator                , default: Calculator                  => Calculator
             nonstandard, reprogrammable, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
        17: Screen Capture/Print Screen, default: Screen Capture              => Screen Capture
             nonstandard, reprogrammable, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
        18: App Contextual Menu/Right Click, default: Right Click/App Contextual Menu => Right Click/App Contextual Menu
             nonstandard, reprogrammable, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
        19: Lock PC                   , default: WindowsLock                 => WindowsLock
             nonstandard, reprogrammable, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
        20: Left Arrow                , default: Keyboard Left Arrow         => Keyboard Left Arrow
             nonstandard, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
        21: Right Arrow               , default: Keyboard Right Arrow        => Keyboard Right Arrow
             nonstandard, divertable, persistently divertable, pos:0, group:0, group mask:empty
             reporting: default
        22: F Lock                    , default: Do Nothing One              => Do Nothing One
             is FN, pos:0, group:0, group mask:empty
             reporting: default
        23: unknown:0034              , default: Do Nothing One              => Do Nothing One
             nonstandard, pos:0, group:0, group mask:empty
             reporting: default
     Battery: 50%, discharging, next level 20%.
**Is your feature request related to a problem? Please describe.**

The newly introduced rule-based crown handling (#987, #988) does not appear to work in Wayland environments. As I understand, this is not a bug but a deliberately missing feature.

Describe the solution you'd like

It would be nice to have this working in Wayland environments.

Describe alternatives you've considered

I don't know, use X11 maybe.

Additional context

As I understand, input injection can happen via non-X11-dependent mechanisms, like pynput's uinput backend. What else does solaar need from the window system?

@pfps
Copy link
Collaborator

pfps commented Nov 29, 2020

See Issue #1006. Pynput complained when run under Wayland.
What is needed is a way to inject input events in Wayland without root access. And also a way to find out the name of the process that is receiving input events. And either a way to find out which keyboard modifiers are active or some way to send a modified key event that does not change the keyboard modifiers.

@intelfx
Copy link
Author

intelfx commented Nov 29, 2020

Ah, I see. The title of that issue was not prominent enough, I guess.

What is needed is a way to inject input events in Wayland without root access.

uinput should work for that... on my system, /dev/uinput is assigned an ACL corresponding to the user of the active session, so it's doable in theory.

And also a way to find out the name of the process that is receiving input events. And either a way to find out which keyboard modifiers are active or some way to send a modified key event that does not change the keyboard modifiers.

This would be trickier for sure.

@pfps
Copy link
Collaborator

pfps commented Nov 29, 2020

What is needed is someone who knows about Wayland and can help put together a solution.

On my Fedora system there does not appear to be any ACLs set up for input devices.

@intelfx
Copy link
Author

intelfx commented Nov 29, 2020

On my Fedora system there does not appear to be any ACLs set up for input devices.

TBH any system with functional logind will do that (and a default Fedora absolutely counts). Try getfacl /dev/uinput while your graphical session is active.

What is needed is someone who knows about Wayland and can help put together a solution.

So I googled a bit. There actually is a protocol, wlr-foreign-toplevel-management, that does what Solaar wants. Unfortunately (for me) GNOME does not implement it and likely will not. There is also said to be some GNOME-specific DBus API (edit: an example of its usage), but whatever it will be, I doubt that you would want to support an exception just for GNOME.

@pfps
Copy link
Collaborator

pfps commented Nov 30, 2020

No ACLs on /dev/uinput here. Perhaps it is only done in Wayland?

@intelfx
Copy link
Author

intelfx commented Dec 1, 2020

$ grep uinput -r /etc/udev/rules.d /usr/lib/udev/rules.d 
/usr/lib/udev/rules.d/70-steam-input.rules:KERNEL=="uinput", SUBSYSTEM=="misc", OPTIONS+="static_node=uinput", TAG+="uaccess", OPTIONS+="static_node=uinput"

Right. The udev rule that assigns ACLs to uinput node is not built-in as I thought, but is rather supplied by Steam on my system.

That said, nothing prevents Solaar from shipping a similar rule itself (the significant part is TAG+="uaccess").

@pfps
Copy link
Collaborator

pfps commented Dec 20, 2020

The help of someone who knows about Wayland and can program in Python would be very helpful. There isn't too much that is needed - faking input (probably using uinput) and determining the active program are the major bits.

@pfps
Copy link
Collaborator

pfps commented Jul 20, 2021

I wrote a little program to fake input using /dev/uinput. It works for keyboard input but not for mouse buttons and I have no idea why. If someone can figure it out it would be possible to do more Solaar rule processing under Wayland.

EDIT: It turns out that you need to synchronize between mouse down and up to register a click, but not for keyboard keys. The buggy behaviour is really for keyboards, not for mice.

@pfps
Copy link
Collaborator

pfps commented Jul 20, 2021

If someone can find something saying how to determine the current program in Wayland that would help in getting Solaar rules running in Wayland.

@pfps
Copy link
Collaborator

pfps commented Jul 20, 2021

If you have X11 (emulation?) running in Wayland then Solaar rules will be active. They can't see the active program or fake input, but at least they can respond to notifications and run programs.

@nnuel
Copy link

nnuel commented Dec 24, 2021

So as of yet this hasn't been implemented right? I can see Solaar intercepting my Mouse Gesture Button of Ctrl + Alt + Shift, but I can't give it any new inputs. I figure these are send over X and therefore not registered. I might check to see if it would run in a contained X client through xwayland.

But I guess a workaround would be to give the keyboard bindings a new function through a bindsym in Sway.

@pfps
Copy link
Collaborator

pfps commented Dec 24, 2021

The problem in Wayland is that it is difficult to emulate input.
What should work is diverting keys and having them trigger rules that execute programs.
If this isn't working then provide output of solaar -dd as diverted keys are being pressed. Also provide contents of ~/.config/solaar/rules.yaml and ~/.config/solaar/config.json.

@nnuel
Copy link

nnuel commented Dec 24, 2021

solaar -dd            
14:21:34,514     INFO [MainThread] root: language en_US (UTF-8), translations path /usr/share/locale
14:21:34,694    DEBUG [MainThread] logitech_receiver.diversion: rule Key assuming action "pressed" for "Brightness Down"
14:21:34,695    DEBUG [MainThread] logitech_receiver.diversion: rule Key assuming action "pressed" for "Brightness Up"
14:21:34,697    DEBUG [MainThread] logitech_receiver.diversion: load rule: Rule(/home/wout/.config/solaar/rules.yaml)[Key: Mouse Gesture Button (pressed),  KeyPress: Control_L w]
14:21:34,697     INFO [MainThread] logitech_receiver.diversion: loaded 1 rules from /home/wout/.config/solaar/rules.yaml
14:21:34,699    DEBUG [MainThread] solaar.ui.tray: using AppIndicator3
14:21:34,712     INFO [MainThread] solaar.upower: connected to system dbus, watching for suspend/resume events

Rules

%YAML 1.3
---
- Key: [Mouse Gesture Button, pressed]
- KeyPress: [Control_L, w]
...

Lastly, the config:

{
  "4071:DA5B3453": {
    "_modelId": "B01E40710000",
    "_name": "Wireless Mouse MX Master",
    "_sensitive": {
      "mouse-gestures": false
    },
    "_serial": "DA5B3453",
    "_unitId": "E7B71F3A",
    "divert-keys": {
      "195": 1,
      "196": 0,
      "82": 0,
      "83": 0,
      "86": 0
    },
    "dpi": 1000,
    "dpi-sliding": 0,
    "gesture2-gestures": {
      "45": true,
      "46": true
    },
    "hires-smooth-invert": false,
    "hires-smooth-resolution": true,
    "mouse-gestures": "195",
    "reprogrammable-keys": {
      "195": 195,
      "196": 196,
      "80": 80,
      "81": 81,
      "82": 82,
      "83": 83,
      "86": 86
    },
    "smart-shift": 16
  },
  "_version": "1.1.0"

So you are saying that I should make the Mouse Gesture button to make a script, and in that script put a keybind for Control_L and w, as a workaround that is guaranteed to work?

@pfps
Copy link
Collaborator

pfps commented Dec 24, 2021

It looks as if you had a running Solaar. To get debug output you need to quit out of Solaar and then run solaar -dd. This should produce a lot of output - the useful part will we what is output when you press the diverted button.

One way to debug rules is to include an action to execute a command that pops up an on-screen notification, like notify-send with an argument like rule X run.

@pfps
Copy link
Collaborator

pfps commented Dec 24, 2021

The KeyPress action uses XTest, which might not work in Wayland.

@nnuel
Copy link

nnuel commented Dec 24, 2021

One way to debug rules is to include an action to execute a command that pops up an on-screen notification, like notify-send with an argument like rule X run.

That's very helpful, thanks. I do think it Solaar works as it should, just that my use-case is limiting. The keypress might be not supported, but I could circumvent it also, by rebinding the Ctrl+Alt+Tab, which is the default for the mouse gesture button to Ctrl+w.

Will try the solaar -dd command now and list the output:

@nnuel
Copy link

nnuel commented Dec 24, 2021

16:35:38,539    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: diverted controls pressed: 195, 0, 0, 0
16:35:38,540    ERROR [ReceiverListener:hidraw0] logitech_receiver.listener: processing Notification(11,1,0A,00,00C30000000000000000000000000000)

Then more error code info

Traceback (most recent call last):
  File "/usr/lib/python3.9/site-packages/logitech_receiver/listener.py", line 190, in run
    self._notifications_callback(n)
  File "/usr/lib/python3.9/site-packages/solaar/listener.py", line 262, in _notifications_handler
    _notifications.process(dev, n)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/notifications.py", line 60, in process
    return _process_device_notification(device, status, notification)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/notifications.py", line 195, in _process_device_notification
    return _process_feature_notification(device, status, n, feature)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/notifications.py", line 438, in _process_feature_notification
    _diversion.process_notification(device, status, n, feature)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/diversion.py", line 795, in process_notification
    rules.evaluate(feature, notification, device, status, True)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/diversion.py", line 203, in evaluate
    result = component.evaluate(feature, notification, device, status, result)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/diversion.py", line 203, in evaluate
    result = component.evaluate(feature, notification, device, status, result)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/diversion.py", line 203, in evaluate
    result = component.evaluate(feature, notification, device, status, result)
  File "/usr/lib/python3.9/site-packages/logitech_receiver/diversion.py", line 324, in evaluate
    result = any(bool(s and s.startswith(self.process)) for s in x11_focus_prog())
TypeError: 'NoneType' object is not iterable
16:33:24,124    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 FFFF0000000000000000000000000000]
16:33:24,124    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
16:33:24,124    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=-1 dy=0
16:33:24,124    ERROR [ReceiverListener:hidraw0] logitech_receiver.listener: processing Notification(11,1,0A,10,FFFF0000000000000000000000000000)

@pfps
Copy link
Collaborator

pfps commented Dec 24, 2021

Hmm. That looks like a bit of a bug. Solaar rules haven't been tested under XWayland.

@pfps
Copy link
Collaborator

pfps commented Dec 24, 2021

It looks like you put in a Process condition in your rule. You probably wanted to use an Execute action instead.

@pfps
Copy link
Collaborator

pfps commented Dec 24, 2021

PR #1391 should fix the crash you experienced.

To download and use Solar from its GitHub repository

git clone https://github.com/pwr-Solaar/Solaar.git
cd Solaar

Run Solaar as bin/solaar from this directory.

To run PR #1391, first clone Solaar if you have not already done so and cd to the clone directory. The first time you download the pull request, fetch it into a new branch and checkout that branch, as in:

git fetch origin pull/1391/head:pull_1391
git checkout pull_1391

To download a new version of the pull request, fetch it and then set your pull branch
to the new fetch, as in:

git checkout pull_1391
git fetch origin pull/1391/head
git reset --hard FETCH_HEAD

@nnuel
Copy link

nnuel commented Dec 24, 2021

Running the above commands, and setting 'firefox' as an execute command. I can verify that working, but that might have been also the case before. The Keypresses of Ctrl+w are not working yet. I was sure to close solaar before I opening the command. I will have a play around, I am not the most well-versed when it comes to linux, so thanks for the initial pointers, also how to git into new repos.

@nnuel
Copy link

nnuel commented Dec 24, 2021

It seems to hang a bit, but definitely gives different and no error like before.

22:44:11,432    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 00C30000000000000000000000000000
22:44:11,432    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: diverted controls pressed: 0xc3, 0x0, 0x0, 0x0
22:44:11,432     INFO [ReceiverListener:hidraw0] logitech_receiver.diversion: KeyPress action: ['Control_L', 'w'], modifiers 0 ['0x25', '0x19']
22:44:11,439    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[20 01 0200 0001D0FF00006E00000000]
22:44:11,447    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0000FFFD000000000000000000000000]
22:44:11,448    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,448    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0000FFFD000000000000000000000000
22:44:11,448    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=0 dy=-3
22:44:11,455    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0000FFFE000000000000000000000000]
22:44:11,455    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,456    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0000FFFE000000000000000000000000
22:44:11,456    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=0 dy=-2
22:44:11,463    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0001FFFF000000000000000000000000]
22:44:11,464    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,464    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0001FFFF000000000000000000000000
22:44:11,464    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=1 dy=-1
22:44:11,471    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0000FFFE000000000000000000000000]
22:44:11,471    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,471    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0000FFFE000000000000000000000000
22:44:11,472    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=0 dy=-2
22:44:11,479    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0000FFFF000000000000000000000000]
22:44:11,480    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,480    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0000FFFF000000000000000000000000
22:44:11,480    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=0 dy=-1
22:44:11,487    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0000FFFF000000000000000000000000]
22:44:11,487    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,488    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0000FFFF000000000000000000000000
22:44:11,488    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=0 dy=-1
22:44:11,495    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0001FFFF000000000000000000000000]
22:44:11,496    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,496    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0001FFFF000000000000000000000000
22:44:11,496    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=1 dy=-1
22:44:11,617    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0000FFFF000000000000000000000000]
22:44:11,618    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,618    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0000FFFF000000000000000000000000
22:44:11,618    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=0 dy=-1
22:44:11,681    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 0000FFFE000000000000000000000000]
22:44:11,682    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,682    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data 0000FFFE000000000000000000000000
22:44:11,682    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=0 dy=-2
22:44:11,689    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 FFFDFFFC000000000000000000000000]
22:44:11,689    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,690    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data FFFDFFFC000000000000000000000000
22:44:11,690    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=-3 dy=-4
22:44:11,697    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 FFFDFFFC000000000000000000000000]
22:44:11,698    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,698    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data FFFDFFFC000000000000000000000000
22:44:11,698    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=-3 dy=-4
22:44:11,705    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 FFFAFFFC000000000000000000000000]
22:44:11,706    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,706    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data FFFAFFFC000000000000000000000000
22:44:11,706    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=-6 dy=-4
22:44:11,713    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 FFF9FFFC000000000000000000000000]
22:44:11,714    DEBUG [ReceiverListener:hidraw0] logitech_receiver.settings: dpi: settings read 1000 from <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>
22:44:11,714    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: notification for feature REPROG CONTROLS V4, report 0, data FFF9FFFC000000000000000000000000
22:44:11,714    DEBUG [ReceiverListener:hidraw0] logitech_receiver.notifications: <Device(1,4071,Wireless Mouse MX Master,DA5B3453)>: rawXY dx=-7 dy=-4
22:44:11,721    DEBUG [ReceiverListener:hidraw0] logitech_receiver.base: (20) => r[11 01 0A10 FFFBFFFD000000000000000000000000]

</details.

@pfps
Copy link
Collaborator

pfps commented Dec 24, 2021

The KeyPress action is unlikely to work in Wayland. You should execute some command that has the desired effect, if this is possible.

@pfps pfps changed the title Rule-based HID++ event processing does not work on Wayland Improve Solaar rules in Wayland Jan 1, 2022
@pfps
Copy link
Collaborator

pfps commented Jan 25, 2022

If someone is willing to do the testing, it should be possible to get part of Solaar rules running under Wayland. It might even be possible to get Solaar to optionally use /dev/uinput for simulating keypresses and mouse movement. If someone is willing to do some testing please respond here.

@nnuel
Copy link

nnuel commented Jan 25, 2022

I am up for some testing, I am using Sway under Wayland. I don't think it should matter which DE is being used, but I thought I should mention.

@pfps
Copy link
Collaborator

pfps commented Apr 2, 2022

Yes, I made that change to make it more obvious what the devices where for.

@daduke
Copy link

daduke commented Apr 3, 2022

it's even weirder: with latest PR #1530,

  • keyboard events don't show up in solaar-keyboard
  • mouse events don't show up in solaar-mouse
  • BUT: my middle click rule does actually produce a middle click (w/o event showing in event13), but in some random window (not the focused one)
  • w/o solaar running, the middle mouse button doesn't do anything

@daduke
Copy link

daduke commented Apr 3, 2022

reboot doesn't change anything other than ACL getting lost

@pfps
Copy link
Collaborator

pfps commented Apr 3, 2022

I tried running Gnome several ways. Even when I tried Gnome under Wayland some X11 functionality remained.

What I did was fix up the Solaar code a bit to document what features are set up. I also modified how the uinput device is created - there is only one device now. I am also seeing evtest not picking up simulated input. The most reliable way I found to see what exactly is going on is to use emacs and its C-h l command, which shows the last few inputs it sees.

I noticed that even if there is only one uinput device that keyboard and mouse events are not seriallized correctly through to the end process. I added a very short sleep and that seems to result in correct serialization.

So please try out the newest PR #1530 with bin/solaar -dd. There should be new messages about what is set up for simulated input, like:

09:58:38,967     INFO [MainThread] root: language en_US (UTF-8), translations path /home/local/SoftwareDownloads/Solaar/share/locale
09:58:39,119     INFO [MainThread] logitech_receiver.diversion: X11 library loaded
09:58:39,119     INFO [MainThread] logitech_receiver.diversion: XKB display set up
09:58:39,120     INFO [MainThread] logitech_receiver.diversion: GDK Keymap set up
09:58:39,125     INFO [MainThread] logitech_receiver.diversion: Display for Xtest set up
09:58:39,227     INFO [MainThread] logitech_receiver.diversion: Uinput device set up
09:58:39,237     INFO [MainThread] logitech_receiver.diversion: loaded 7 rules from /home/pfps/.config/solaar/rules.yaml

Also post your ~/.config/solaar/rules.yaml file.

With the newest PR #1530 I'm seeing correct behaviour under both Gnome (Wayland and forcing X11 off) and XFCE. Here are the two rules that I worked with:

---
- Key: [Forward Button, pressed]
- KeyPress: i
- MouseClick: [left, 1]
...
---
- Key: [Back Button, pressed]
- MouseClick: [left, 1]
- KeyPress: [Shift_L, i]
...

@daduke
Copy link

daduke commented Apr 3, 2022

16:15:10,694     INFO [MainThread] logitech_receiver.diversion: X11 library loaded
16:15:10,695     INFO [MainThread] logitech_receiver.diversion: XKB display set up
16:15:10,695     INFO [MainThread] logitech_receiver.diversion: GDK Keymap set up
16:15:10,697     INFO [MainThread] logitech_receiver.diversion: Display for Xtest set up
16:15:10,799     INFO [MainThread] logitech_receiver.diversion: Uinput device set up
16:15:10,801     INFO [MainThread] logitech_receiver.diversion: loaded 3 rules from /home/daduke/.config/solaar/rules.yaml
16:15:10,811     INFO [MainThread] solaar.upower: connected to system dbus, watching for suspend/resume events
16:15:10,828     INFO [MainThread] solaar.ui.notify: starting desktop notifications
16:15:10,858     INFO [MainThread] solaar.listener: starting receiver listening threads
16:15:10,861     INFO [MainThread] solaar.listener: receiver event add DeviceInfo(path='/dev/hidraw1', vendor_id='046D', product_id='C52B', serial='', release=None, manufacturer=None, product=None, interface=2, driver='logitech-djreceiver', bus_id=3, isDevice=None)
16:15:10,861     INFO [MainThread] logitech_receiver.base: New lock 23
16:15:10,872     INFO [ReceiverListener:hidraw1] logitech_receiver.listener: started with <UnifyingReceiver(/dev/hidraw1,23)> (23)
16:15:10,872     INFO [ReceiverListener:hidraw1] solaar.listener: <UnifyingReceiver(/dev/hidraw1,23)>: notifications listener has started (23)

@daduke
Copy link

daduke commented Apr 3, 2022

---
- Key: [Right Tilt, pressed]
- KeyPress: [Control_L, Left]
...
---
- Key: [Left Tilt, pressed]
- KeyPress: [Control_L, Right]
...
---
- Key: [Middle Button, pressed]
- MouseClick: [middle, 1]
...

@daduke
Copy link

daduke commented Apr 3, 2022

I think I know what's happening (no idea why tho..): this morning I told you that the middle mouse button is being registered in another window. Turns out the same is true for the key presses. I have a desktop full of windows (5 terminals, 4 browser windows, several other programs and Thunderbird). All events are being sent to Thunderbird, no matter which other window currently has the focus. If I switch to another window, keyboard focus changes, but Solaar simulated input stays in TB. This is new and appeared two 1530 revisions ago. I have rebooted in between.

@pfps
Copy link
Collaborator

pfps commented Apr 3, 2022

I expect that what is happening is that Solaar is using Xtest, even in Wayland, as the Xtest libraries and interface are available. But Xtest under Wayland probably isn't fully capable.

To see if this is the problem edit lib/logitech_receiver/diversion.py to cause an error at line 80 (just before the import Xlib) 1/0 works fine for this. Then uinput will be forced.

If this doesn't help, provide output of bin/solaar -dd without the change to diversion.py.

@daduke
Copy link

daduke commented Apr 3, 2022

force Xlib to fail: immediate success! Everything works like it should! Fantastic.

@pfps
Copy link
Collaborator

pfps commented Apr 4, 2022

OK. But that means that the way Solaar determines what to use for simulated input needs to be rethought, which may take a while.
You can run with the patch until the change has been implemented.

@daduke
Copy link

daduke commented Apr 4, 2022

yes, I'm a happy camper. In fact, Solaar was the only thing keeping me from switching to Wayland on my main workstation, and now I can. Thanks a bunch!

@pfps
Copy link
Collaborator

pfps commented Apr 5, 2022

The current version of PR #1530 should work for you, but if you try it out in the branch you are currently using you can't easily go back. I think the easiest way go keep both is to create a new branch and use that branch for the current version of PR #1530.

@daduke
Copy link

daduke commented Apr 6, 2022

the current PR #1530 only halfway works: only the first scroll-wheel-left or -right switches the workspace, then I have to restart Solaar. The 'force Xlib to fail' version runs without this issue.

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

Please provide output of bin/solaar -ddd showing the success and then the failure.

@daduke
Copy link

daduke commented Apr 6, 2022

ok here's mousewheel-right (working) + some mouse movement + mousewheel-left (not working)

18:58:46,342    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 00FFEFFF00005100000000]
18:58:46,342    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[10 02 8107 070000]
18:58:46,342    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 00FFFFFF00004100000000]
18:58:46,342    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 00FFFFFF00004100000000]
18:58:46,346    DEBUG [MainThread] solaar.ui: status changed: <Device(2,200A,Wireless Wave Keyboard K350,03BC2E38)> (NONE) None
18:58:46,346    DEBUG [MainThread] solaar.ui.icons: battery icon for full:False = battery-full
18:58:46,347    DEBUG [MainThread] solaar.ui.tray: picked device with lowest battery: ('/dev/hidraw1', 1, 'Wireless Mobile Mouse MX Anywhere 2S', {'LINK ENCRYPTED': True, 'BATTERY LEVEL': 50, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY NEXT LEVEL': 20, 'BATTERY VOLTAGE': None, 'BATTERY CHARGING': False, 'ERROR': None})
18:58:46,347    DEBUG [MainThread] solaar.ui.icons: battery icon for 50:False = battery-good
18:58:46,348    DEBUG [MainThread] solaar.ui.icons: battery icon for full:False = battery-full
18:58:46,349    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 0000F0FF00004F00000000]
18:58:46,407    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 00FF0F0000003000000000]
18:58:48,961    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[11 01 0900 005D0000000000000000000000000000]
18:58:48,962    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: notification for feature REPROG CONTROLS V4, report 0, data 005D0000000000000000000000000000
18:58:48,962    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: diverted controls pressed: 0x5d, 0x0, 0x0, 0x0
18:58:48,962     INFO [MainThread] logitech_receiver.diversion: KeyPress action: ['Control_L', 'Left'], modifiers 16 ['0xffe3', '0xff51']
18:58:48,964     INFO [MainThread] logitech_receiver.diversion: XKB display set up
18:58:48,998    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 0000F0FF00004F00000000]
18:58:49,022     INFO [MainThread] logitech_receiver.diversion: X11 library loaded and display set up
18:58:49,153    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[11 01 0900 00000000000000000000000000000000]
18:58:49,153    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: notification for feature REPROG CONTROLS V4, report 0, data 00000000000000000000000000000000
18:58:49,153    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: diverted controls pressed: 0x0, 0x0, 0x0, 0x0
18:58:49,871    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 0000F0FF00004F00000000]
18:58:49,879    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 0000F0FF00004F00000000]

[.. more mouse movements ..]

18:58:50,321    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 0000F0FF00004F00000000]
18:58:50,339    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 0000F0FF00004F00000000]
18:58:50,345    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 01 0200 00FF0F0000003000000000]
18:58:50,685    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[11 01 0900 005B0000000000000000000000000000]
18:58:50,686    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: notification for feature REPROG CONTROLS V4, report 0, data 005B0000000000000000000000000000
18:58:50,686    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: diverted controls pressed: 0x5b, 0x0, 0x0, 0x0
18:58:50,686     INFO [MainThread] logitech_receiver.diversion: KeyPress action: ['Control_L', 'Right'], modifiers 20 ['0xffe3', '0xff53']
18:58:50,951    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[11 01 0900 00000000000000000000000000000000]
18:58:50,951    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: notification for feature REPROG CONTROLS V4, report 0, data 00000000000000000000000000000000
18:58:50,951    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: diverted controls pressed: 0x0, 0x0, 0x0, 0x0
18:58:52,875    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 02 0110 0000000000000000000000]
18:58:53,721    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 02 0110 4F00000000000000000000]
18:58:53,853    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 02 0110 0000000000000000000000]
18:58:53,975    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 02 0100 0000000000000000000000]
18:58:54,747    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[20 02 0101 0000000000000000000000]       

@daduke
Copy link

daduke commented Apr 6, 2022

I noticed that sometimes the latest version works, but so far the patched one has always worked

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

I'm not seeing anything problematic but there isn't good visibility on exactly what is being done. I've added permanent debugging output for that so please try the current version of the PR again. It should show simulated uinput debug lines for each keydown and keyup.

I tested the current version of the PR on Gnome Wayland and I'm not seeing any problems there.

@daduke
Copy link

daduke commented Apr 6, 2022

https://daduke.org/junk/solaar -> again, first KeyPress worked, second didn't.

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

The relevant part is:

19:54:17,437    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: diverted controls pressed: 0x5d, 0x0, 0x0, 0x0
19:54:17,438     INFO [MainThread] logitech_receiver.diversion: KeyPress action: ['Control_L', 'Left'], modifiers 16 ['0xffe3', '0xff51']
19:54:17,440     INFO [MainThread] logitech_receiver.diversion: XKB display set up
19:54:17,496     INFO [MainThread] logitech_receiver.diversion: X11 library loaded and display set up
19:54:17,496    DEBUG [MainThread] logitech_receiver.diversion: uinput simulated input 1 29 1
19:54:17,496    DEBUG [MainThread] logitech_receiver.diversion: uinput simulated input 1 105 1
19:54:17,497    DEBUG [MainThread] logitech_receiver.diversion: uinput simulated input 1 105 0
19:54:17,497    DEBUG [MainThread] logitech_receiver.diversion: uinput simulated input 1 29 0
19:54:17,630    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[11 01 0900 00000000000000000000000000000000]
19:54:17,631    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: notification for feature REPROG CONTROLS V4, report 0, data 00000000000000000000000000000000
19:54:17,631    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: diverted controls pressed: 0x0, 0x0, 0x0, 0x0
19:54:18,850    DEBUG [ReceiverListener:hidraw1] logitech_receiver.base: (20) => r[11 01 0900 005B0000000000000000000000000000]
19:54:18,851    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: notification for feature REPROG CONTROLS V4, report 0, data 005B0000000000000000000000000000
19:54:18,851    DEBUG [ReceiverListener:hidraw1] logitech_receiver.notifications: <Device(1,406A,Wireless Mobile Mouse MX Anywhere 2S,75939D1C)>: diverted controls pressed: 0x5b, 0x0, 0x0, 0x0
19:54:18,851     INFO [MainThread] logitech_receiver.diversion: KeyPress action: ['Control_L', 'Right'], modifiers 20 ['0xffe3', '0xff53']
19:54:18,852    DEBUG [MainThread] logitech_receiver.diversion: uinput simulated input 1 106 1
19:54:18,853    DEBUG [MainThread] logitech_receiver.diversion: uinput simulated input 1 106 0

What is happening is that on the second notification Solaar thinks that a control modifier is on and doesn't bother to simulate pressing and releasing the control key. This may again a problem with Wayland in that there is no global notion of the keyboard modifiers. To verify, see if clicking on the Solaar window results in a good result.

The resolution might have to be to simulate pressing and releasing modifier keys unconditionally, which can cause problems if a modifier key is actually down.

@daduke
Copy link

daduke commented Apr 6, 2022

what do you mean by "see if clicking on the Solaar window results in a good result"? In the test as I'm doing it right now, the Solaar window isn't even visible after the first click since I just switched workspaces..

as for "The resolution might have to be to simulate pressing and releasing modifier keys unconditionally, which can cause problems if a modifier key is actually down" - why does the 'force Xlib to fail' version work so well then?

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

Thinking further, if the simulated input changes the window or does something else to change focus then this is likely to cause Solaar to have an incorrect notion of which modifier keys are down.

@daduke
Copy link

daduke commented Apr 6, 2022

uhm ok. All I can say is that it worked perfectly under X and it also works perfectly under Wayland with the frankensteined patch

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

I think the results may depend on whether a rule is ever run when the Solaar window is active. If so, then Solaar may end up with an incorrect notion of which modifier keys are down. The reason for this is that the control-key down is performed when the Solaar window is active but the control-key up is performed when another window is active. Under X there is a global notion of which control keys are down that all programs can see. Under Wayland programs only see what has happened in the input system when they are active. (At least this is my understanding.)
It has only been very recently that Solaar had access to the modifier key state in Wayland at all. The patched Solaar may be from before that but to verify that would require adding debugging statements similar to what was added in the most recent revision of PR #1530.

@daduke
Copy link

daduke commented Apr 6, 2022

I expect that what is happening is that Solaar is using Xtest, even in Wayland, as the Xtest libraries and interface are available. But Xtest under Wayland probably isn't fully capable.

To see if this is the problem edit lib/logitech_receiver/diversion.py to cause an error at line 80 (just before the import Xlib) 1/0 works fine for this. Then uinput will be forced.

If this doesn't help, provide output of bin/solaar -dd without the change to diversion.py.

my "patched" version is this ^ one - it was a git clone done on that day, pulled 1530 and disabled Xlib

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

It looks as if the patched Solaar doesn't refer to the modifier state.

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

Patching the current PR to not use the modifier state can be done via changing line 212 of diversion.py to

    if wayland or not x11_setup() or keycode == 0:

@daduke
Copy link

daduke commented Apr 6, 2022

this seems to work fine too

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

OK, I'll probably make this change to Solaar.

@pfps
Copy link
Collaborator

pfps commented Apr 6, 2022

I just added the patch to the PR. As this seems to work I'm going to merge it in.

@pfps pfps closed this as completed in #1530 Apr 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants