pwr-Solaar / Solaar

Linux device manager for Logitech devices
https://pwr-solaar.github.io/Solaar
GNU General Public License v2.0
5.54k stars 409 forks source link

Diverted key only works when unlocking and relocking divertion settings after reboot #2352

Closed piratenpanda closed 8 months ago

piratenpanda commented 8 months ago

I'm using Solaar 1.1.11 on latest Arch (kernel 6.7.6) with a Logitech MX Keys S keyboard. I'm diverting the snipping tool so that it is recognized as "Print Screen" to get access to the screenshot tool. This works fine when setting it up. I also put the desktop file to the autostart folder so solaar runs on start-up.

But after reboot the key does nothing again. Diversion setting for the snipping tool is saved but "Print Screen" only works after unlocking, selecting the key and re-locking the diversion settings again.

I'm not using the udev rules as the Bolt receiver is invisible to my normal user then even though I created a plugdev group and put my user there. I'm a noob and the group could be named differently under arch though.

I read the known issues but don't think my problem is listed there. But I totally believe this could be user error so I'm sorry if I'm doing something stupid.

solaar show:

solaar version 1.1.11

Bolt Empfänger
  Device path  : /dev/hidraw2
  USB id       : 046d:C548
  Serial       : 32333541333136463344374342343444
  Has 1 paired device(s) out of a maximum of 6.
  Notifications: wireless (0x000100)
  Device activity counters: 1=8

  1: MX Keys S
     Device path  : None
     WPID         : B378
     Codename     : MX KEYS S
     Kind         : keyboard
     Protocol     : HID++ 4.5
     Report Rate : 0ms
     Serial number: 1A86B75B
     Model ID:      B37800000000
     Unit ID:       1A86B75B
        Bootloader: BL1 88.01.B0015
          Firmware: RBK 81.01.B0015
             Other: 
     The power switch is located on the (unknown).
     Supports 34 HID++ 2.0 features:
         0: ROOT                   {0000} V0     
         1: FEATURE SET            {0001} V0     
         2: DEVICE FW VERSION      {0003} V4     
            Firmware: Bootloader BL1 88.01.B0015 B37802EEF676
            Firmware: Firmware RBK 81.01.B0015 B37802EEF676
            Firmware: Other   
            Unit ID: 1A86B75B  Model ID: B37800000000  Transport IDs: {'btleid': 'B378'}
         3: DEVICE NAME            {0005} V0     
            Name: MX Keys S
            Kind: keyboard
         4: WIRELESS DEVICE STATUS {1D4B} V0     
         5: CONFIG CHANGE          {0020} V0     
         6: DEVICE FRIENDLY NAME   {0007} V0     
            Friendly Name: MX KEYS S
         7: unknown:0011           {0011} V0     
         8: UNIFIED BATTERY        {1004} V3     
            Battery: 90%, discharging.
         9: REPROG CONTROLS V4     {1B04} V5     
            Taste/Maustaste umleiten (saved): {Calculator:Normal, Lock PC:Normal, Brightness Down:Normal, Brightness Up:Normal, Backlight Down:Normal, Backlight Up:Normal, Previous Fn:Normal, Play/Pause Fn:Normal, Next Fn:Normal, Mute Fn:Normal, Volume Down Fn:Normal, Volume Up Fn:Normal, App Contextual Menu/Right Click:Normal, Voice Dictation:Normal, Open Emoji Panel:Normal, Snipping Tool:Umgeleitet, Mute Microphone:Normal}
            Taste/Maustaste umleiten        : {Calculator:Normal, Lock PC:Normal, Brightness Down:Normal, Brightness Up:Normal, Backlight Down:Normal, Backlight Up:Normal, Previous Fn:Normal, Play/Pause Fn:Normal, Next Fn:Normal, Mute Fn:Normal, Volume Down Fn:Normal, Volume Up Fn:Normal, App Contextual Menu/Right Click:Normal, Voice Dictation:Normal, Open Emoji Panel:Normal, Snipping Tool:Umgeleitet, Mute Microphone:Normal}
        10: CHANGE HOST            {1814} V1     
            Anderen Empfänger wählen        : 1:pandahome
        11: HOSTS INFO             {1815} V2     
            Host 0 (paired): pandahome
            Host 1 (unpaired): 
            Host 2 (unpaired): 
        12: BACKLIGHT2             {1982} V3     
solaar: error: Traceback (most recent call last):
  File "/usr/lib/python3.11/site-packages/solaar/cli/__init__.py", line 217, in run
    m.run(c, args, _find_receiver, _find_device)
  File "/usr/lib/python3.11/site-packages/solaar/cli/show.py", line 305, in run
    _print_device(dev, dev.number)
  File "/usr/lib/python3.11/site-packages/solaar/cli/show.py", line 243, in _print_device
    v = setting.val_to_string(setting.read(False))
                              ^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/logitech_receiver/settings.py", line 287, in read
    self._value = self._validator.validate_read(reply)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/site-packages/logitech_receiver/settings.py", line 1026, in validate_read
    reply_value = _bytes2int(reply_bytes[self._read_skip_byte_count:self._read_skip_byte_count + self._byte_count])
                             ~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
TypeError: 'int' object is not subscriptable
pfps commented 8 months ago

Using the plugdev group is no longer recommended. Instead the udev rule manipulates user-level permissions on /dev/hidrawN nodes. Going with the older mechanism may cause problems.

piratenpanda commented 8 months ago

I cloned the repo and used the udev file from there so this was the way to go? Anyway, after putting the file the bolt receiver vanished for non-root users.

pfps commented 8 months ago

Yes, this was the way to go. But after moving the udev file you have to both reload the udev rules and remove and reinsert the receiver.

pfps commented 8 months ago

The error in solaar show needs to be investigated. Can you provide the output of solaar -ddd show?

piratenpanda commented 8 months ago

Here you go https://pastebin.com/c0ifpxDa

piratenpanda commented 8 months ago

Ok diversion works as soon as I unlock the setting. before it does not after a reload of solaar

pfps commented 8 months ago

When you start Solaar it should push all your settings to all your devices. What you probably need to do to see that this is working for you is to quit out of Solaar, then turn your keyboard off and on again (to clear its internal settings), and then start Solaar. The key should then be diverted. If it is not, then do this all again except run Solaar as solaar -ddd and post the result.

pfps commented 8 months ago

I have a fix for the crash in solaar show but this does not affect anything else, I hope, so I'll put off creating a PR for it until we can figure out whether there is a but in diversions.

piratenpanda commented 8 months ago

If it is not, then do this all again except run Solaar as solaar -ddd and post the result.

Here's the output https://pastebin.com/sGUgwBbZ At the end I'm unlocking the diversion setting and it works again. Before it does not. Yet in the dropdown if I select Snipping Tool solaar knows the key is diverted

piratenpanda commented 8 months ago

Now it's even losing the function while solaar is running. Very strange

pfps commented 8 months ago

I'm now suspecting that the error shown up in solaar show could be responsible. There is a delay of about 8 seconds in setting up the Keys and until this setup is completed the key diversion is not active. The error could be terminating part of Solaar's setup process and is not continued until some user input causes Solaar to try the setup again, in a different manner. When the device becomes active after going into power-saving mode this setup has to be repeated, and may be failing again until there is user input into Solaar.

EDIT: This is pretty much confirmed as going from ignore to unlocked state for a setting causes Solaar to update the device for that setting.

The way to check for this is to install the patch. See below for more.

Here is a summary of bits of the log you provided.

``` Solaar discovers Bolt Receiver 2024-03-02 12:25:33,326,326 INFO [MainThread] solaar.listener: receiver event add DeviceInfo(path='/dev/hidraw2', bus_id=3, vendor_id='046D', product_id='C548', interface=2, driver='hid-generic', manufacturer=None, product=None, serial='', release=None, isDevice=None, hidpp_short=True, hidpp_long=True) Solaar discovers Unifying Receiver 2024-03-02 12:25:33,330,330 INFO [MainThread] solaar.listener: receiver event add DeviceInfo(path='/dev/hidraw4', bus_id=3, vendor_id='046D', product_id='C52B', interface=2, driver='logitech-djreceiver', manufacturer=None, product=None, serial='', release=None, isDevice=None, hidpp_short=True, hidpp_long=True) Bolt Receiver tells Solaar about MX Keys S 2024-03-02 12:25:33,343,343 DEBUG [ReceiverListener:hidraw2] logitech_receiver.base: (17) => r[10 01 4110 0178B3] Unifying Receiver tells Solaar about Wireless Mobile Mouse MX Anywhere 2S 2024-03-02 12:25:33,347,347 DEBUG [ReceiverListener:hidraw4] logitech_receiver.base: (18) => r[10 01 4104 326A40] Solaar starts setup of 2S 2024-03-02 12:25:33,421,421 INFO [ReceiverListener:hidraw4] solaar.listener: connection Notification(10,1,41,04,326A40) for Solaar finishes setup of 2S 2024-03-02 12:25:34,551,551 INFO [ReceiverListener:hidraw4] solaar.listener: status_changed : paired online, {'LINK ENCRYPTED': True, 'BATTERY LEVEL': 90, 'BATTERY STATUS': NamedInt(0, 'discharging'), 'BATTERY NEXT LEVEL': 50, 'BATTERY VOLTAGE': None, 'BATTERY CHARGING': False, 'ERROR': None} (0) Solaar starts GUI setup for 2S 2024-03-02 12:25:34,553,553 DEBUG [AsyncUI] logitech_receiver.settings: hires-smooth-invert: cached value False on Solaar starts setup of Keys 2024-03-02 12:25:35,151,151 INFO [ReceiverListener:hidraw2] solaar.listener: connection Notification(10,1,41,10,0178B3) for Solaar encounters error also seen in `solaar show` for Keys 2024-03-02 12:25:36,134,134 ERROR [ReceiverListener:hidraw2] logitech_receiver.listener: processing Notification(10,1,41,10,0178B3) Solaar stalls for about 8 seconds 2024-03-02 12:25:38,984,984 DEBUG [ReceiverListener:hidraw2] logitech_receiver.base: (17) => r[11 01 0817 5A080000000000000000000000000000] Solaar continues setup for Keys, key diversion not set up yet 2024-03-02 12:25:47,511,511 DEBUG [AsyncUI] logitech_receiver.settings: divert-keys: settings write {10: 0, 111: 0, 199: 0, 200: 0, 226: 0, 227: 0, 228: 0, 229: 0, 230: 0, 231: 0, 232: 0, 233: 0, 234: 0, 259: 0, 264: 0, 266: 1, 284: 0} to Solaar sets up key diversion for Keys 2024-03-02 12:25:48,591,591 DEBUG [AsyncUI] logitech_receiver.settings: divert-keys: settings prepare map write(266,1) => b'\x01' Solaar finishes setup for Keys 2024-03-02 12:25:48,629,629 DEBUG [AsyncUI] logitech_receiver.base: (21) => r[11 01 093D 011C0200000000000000000000000000] Solaar processes diverted key click 2024-03-02 12:25:52,296,296 DEBUG [ReceiverListener:hidraw2] logitech_receiver.notifications: : diverted controls pressed: 0x10a, 0x0, 0x0, 0x0 ```
pfps commented 8 months ago

PR #2353 may fix your problem. Clone it and run bin/solaar from the download directory. If the problem is not fixed, run bin/solaar -ddd. Then wait for several seconds, press the diverted key, wait for several seconds, unlock and relock key diversion, wait for several seconds, and then press the diverted key again. Post the output.

To clone 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 #2353, 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/2353/head:pull_2353
git checkout pull_2353

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_2353
git fetch origin pull/2353/head
git reset --hard FETCH_HEAD
piratenpanda commented 8 months ago

Seems to work fine. Solaar show now works properly and Snipping tool diversion and screenshot tool works right after starting solaar. Thank you!

piratenpanda commented 8 months ago

Is this a solaar issue that the snipping tool key is recognized as "S" when the device is in powersave and the rules divert it to the Print Screen key when it wakes up or is this a device limitation?

pfps commented 8 months ago

If the device is in power-save mode then the diversion will be forgotten. If the device is woken up by pressing the snipping tool key Solaar does not (currently?) have a chance to divert the key before the device sends it. There is some Logitech information on something that might address this issue but attempts to implement it in Solaar have not worked (so far).

If you are interested in having this fixed some testing of code changes would be helpful. The best way to proceed would be to open an enhancement request.

piratenpanda commented 8 months ago

will do, thanks