Repository: pwr-Solaar/Solaar

Issue:
Diverted key only works when unlocking and relocking divertion settings after reboot
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
```

- Contents of `~/.config/solaar/config.yaml` (or `~/.config/solaar/config.json` if `~/.config/solaar/config.yaml` not present):
```
- 1.1.11
- _NAME: MX Keys S
  _absent: [hi-res-scroll, lowres-scroll-mode, hires-smooth-invert, hires-smooth-resolution, hires-scroll-mode, scroll-ratchet, smart-shift, thumb-scroll-invert,
    thumb-scroll-mode, onboard_profiles, report_rate, report_rate_extended, pointer_speed, dpi, speed-change, backlight-timed, led_control, led_zone_, reprogrammable-keys,
    persistent-remappable-keys, crown-smooth, divert-crown, divert-gkeys, m-key-leds, mr-key-led, gesture2-gestures, gesture2-divert, gesture2-params, sidetone,
    equalizer, adc_power_management]
  _battery: 0x1004
  _modelId: B37800000000
  _sensitive: {divert-keys: false, fn-swap: false, hires-scroll-mode: ignore, hires-smooth-invert: ignore, hires-smooth-resolution: ignore}
  _serial: 1A86B75B
  _unitId: 1A86B75B
  _wpid: B378
  backlight_duration_hands_in: 0x6
  backlight_duration_hands_out: 0x3
  backlight_duration_powered: 0x3c
  backlight_level: 0x2
  change-host: null
  disable-keyboard-keys: {0x1: false, 0x2: false, 0x4: false, 0x8: false, 0x10: false}
  divert-keys: {0xa: 0x0, 0x6f: 0x0, 0xc7: 0x0, 0xc8: 0x0, 0xe2: 0x0, 0xe3: 0x0, 0xe4: 0x0, 0xe5: 0x0, 0xe6: 0x0, 0xe7: 0x0, 0xe8: 0x0, 0xe9: 0x0, 0xea: 0x0,
    0x103: 0x0, 0x108: 0x0, 0x10a: 0x1, 0x11c: 0x0}
  fn-swap: false
  multiplatform: 0x0
- _NAME: Wireless Mobile Mouse MX Anywhere 2S
  _absent: [hi-res-scroll, lowres-scroll-mode, scroll-ratchet, smart-shift, thumb-scroll-invert, thumb-scroll-mode, onboard_profiles, report_rate, report_rate_extended,
    pointer_speed, speed-change, backlight, backlight_level, backlight_duration_hands_out, backlight_duration_hands_in, backlight_duration_powered, backlight-timed,
    led_control, led_zone_, fn-swap, persistent-remappable-keys, disable-keyboard-keys, crown-smooth, divert-crown, divert-gkeys, m-key-leds, mr-key-led,
    multiplatform, gesture2-gestures, gesture2-divert, gesture2-params, sidetone, equalizer, adc_power_management]
  _battery: 0x1000
  _modelId: B01A406A0000
  _sensitive: {hires-scroll-mode: ignore, hires-smooth-invert: ignore, hires-smooth-resolution: ignore}
  _serial: BEF8B3F4
  _unitId: 4B1BB953
  _wpid: 406A
  change-host: null
  divert-keys: {0x52: 0x0, 0x53: 0x0, 0x56: 0x0, 0x5b: 0x0, 0x5d: 0x0}
  dpi: 0x3e8
  hires-scroll-mode: false
  hires-smooth-invert: false
  hires-smooth-resolution: true
  reprogrammable-keys: {0x50: 0x50, 0x51: 0x51, 0x52: 0x52, 0x53: 0x53, 0x56: 0x56, 0x5b: 0x5b, 0x5d: 0x5d}
```





Discussion:
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.
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.
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.
The error in `solaar show` needs to be investigated.  Can you provide the output of `solaar -ddd show`?
Here you go https://pastebin.com/c0ifpxDa
Ok diversion works as soon as I unlock the setting. before it does not after a reload of solaar

Resolving patch:
diff --git a/lib/logitech_receiver/settings_templates.py b/lib/logitech_receiver/settings_templates.py
--- a/lib/logitech_receiver/settings_templates.py
+++ b/lib/logitech_receiver/settings_templates.py
@@ -270,9 +270,9 @@ def __init__(self, feature):
         def read(self, device):
             backlight = device.backlight
             if not backlight.enabled:
-                return 0xFF
+                return b"\xFF"
             else:
-                return backlight.mode
+                return _int2bytes(backlight.mode, 1)
 
         def write(self, device, data_bytes):
             backlight = device.backlight


Test patch: