Skip to content

Example: Diverted "Smart Shift" button for common devices

John Erling Blad edited this page Sep 9, 2022 · 4 revisions

Use Case

Assume there are two machines, one (“alpha”) and two (“beta”), and both use common HID devices. You want to control both machines with the same HID devices, a mouse and a keyboard. Both must support change host, the mouse have a “Smart Shift” button, and that button can be diverted.

The scheme can be confusing with more than two machines.

Prerequisite

The mouse MX Anywhere 3 has a button that can be diverted, but not all mice has such divertable buttons. Some mice may have other buttons that can be used for the same purpose. Using the “Smart Shift” will override the default free-wheeling of the scroll wheel on the MX Anywhere 3 mouse.

To check whether your mouse support a divertable “Smart Shift” button, running solaar show will give some variation of

     Has 7 reprogrammable keys:
         …
         5: Smart Shift               , default: Smart Shift                 => Smart Shift               
             mse, reprogrammable, divertable, raw XY, analytics key events, pos:0, group:2, group mask:g1,g2
             reporting: default
         …

Both machines must run solaar for the rules to work properly, and the version must be 1.1.4 or higher.

Configuration

The id for the mouse and keyboard can be found in the info-pane as the “serial” value, or by running the command

solaar show | grep -iE '(serial|codename)'

This may give something like

  Serial       : 789ABDEF
     Codename     : MX Anywhere 3
     Serial number: 123456AB
     Codename     : MX Keys
     Serial number: 654321CD

On the first machine (“alpha”) a file is created as ~/.config/solaar/rules.yaml, or an existing one is edited

%YAML 1.3
---
- Key: [Smart Shift, released]
- Rule:
  - And:
    - Active: 654321CD
    - Active: 123456AB
  - Set: [654321CD, change-host, 1]
  - Set: [123456AB, change-host, 1]
- Execute: [notify-send, --category=device, --expire-time=3000, --app-name=solaar,
    --icon=/usr/share/solaar/icons/solaar.svg, Change host, Not done – some device not active.]
...

The rule is checking whether the keyboard is active, and if it is then it is changed to the new host. Then the mouse is changed to the new host. Finalizing the two changes a notification is posted, and that terminates the processing.

If the mouse keyboard not active, solaar will proceed with changing the host for the mouse, and then finalizing the change with a notification before it terminates the processing.

The file on the second machine (“beta”) is created as

%YAML 1.3
---
- Key: [Smart Shift, released]
- Rule:
  - And:
    - Active: 654321CD
    - Active: 123456AB
  - Set: [654321CD, change-host, 0]
  - Set: [123456AB, change-host, 0]
- Execute: [notify-send, --category=device, --expire-time=3000, --app-name=solaar,
    --icon=/usr/share/solaar/icons/solaar.svg, Change host, Not done – some device not active.]
...

Note that the hosts are zero-based in rules.yaml file, while they are one-based in the GUI.

In the GUI go to “Key/Button Diversion” for the mouse, and change “Smart Shift” on beta to “Diverted”. Make a similar change for “Smart Shift” on alpha.

It should not be necessary to edit the rules with the Rule editor, but the rules could instead be created in the GUI. If the rules are not created in the Rule editor, they are not if you edit the file, then you should now restart solaar.

Alt Configuration

The rules can be changed slightly to include diverted "Host Switch Channel" keys. The generalization is quite simple. On the first machine (“alpha”) the rules file become

%YAML 1.3
---
- Or:
  - Key: [Smart Shift, released]
  - Key: [Host Switch Channel 2, released]
- Rule:
  - And:
    - Active: 654321CD
    - Active: 123456AB
  - Set: [654321CD, change-host, 1]
  - Set: [123456AB, change-host, 1]
- Execute: [notify-send, --category=device, --expire-time=3000, --app-name=solaar,
    --icon=/usr/share/solaar/icons/solaar.svg, Change host, Not done – some device not active.]
...

The file on the second machine (“beta”) become

%YAML 1.3
---
- Or:
  - Key: [Smart Shift, released]
  - Key: [Host Switch Channel 1, released]
- Rule:
  - And:
    - Active: 654321CD
    - Active: 123456AB
  - Set: [654321CD, change-host, 0]
  - Set: [123456AB, change-host, 0]
- Execute: [notify-send, --category=device, --expire-time=3000, --app-name=solaar,
    --icon=/usr/share/solaar/icons/solaar.svg, Change host, Not done – some device not active.]
...

For this to work the additional keys for the keyboard must be set as diverted in the GUI.

Issues

One of the devices can be offline, and then be left while the other does the change. It is a race condition where the device goes to sleep before the change host command commences.

The alternate configuration hasn't an easy fix when this happen, as it isn't possible to just repeat the operation. For the MX Anywhere 3 mouse the fix is to use the bottom of the device to force it to reconnect with the host with the keyboard.