Repository: pwr-Solaar/Solaar

Issue:
Shows a useless notification upon startup
When I start Solaar up, it shows a notification claiming my keyboard is _connected_ (not that I already noticed by typing my password on it…)  This is unnecessary, and especially bad if it’s in autostart, which [happens by default](https://github.com/pwr/Solaar/blob/master/setup.py#L15) (without even asking for permission!)  There should be an option to disable all notifications altogether; or at least the first “connected” notifications should be suppressed.



Discussion:
I have just started getting this problem as well, having just upgraded to Kubuntu 17.10. I've been using Solaar for 2 years previously on previous versions of Kubuntu without getting the problem. I get an annoying notification window from Solaar popping up every time I log in, and there appears to be no way to disable this behaviour.
Just delete `/etc/xdg/autostart/solaar.desktop`
There have been quite a few changes to solaar over the past few years so this issue may have already been addressed. If you are still using solaar and this issue has not been resolved please download and run the current version from this github repository. If the problem still persists add a new comment here, providing the output of `solaar -V` and `solaar show` and any new information about the issue.

If you are still running solaar you should be able to download and run its current version (in Linux) as follows:

1. Install git on your machine if it is not already installed. This is generally done via `sudo apt install git` or `sudo dnf install git`
2. Change to a directory where you want the code.
3. Download solaar via `git clone https://github.com/pwr-Solaar/Solaar.git`
4. Run solaar via `Solaar/bin/solaar`

For more information on installing solaar from github see https://github.com/pwr-Solaar/Solaar/blob/master/docs/installation.md

(Myself, I’m not using Solaar nor the solar keyboard anymore; feel free to close this if this cannot be reproduced.)
Logitech MX Master3 mouse causes annoying notifier "connected" each time the mouse gets touched after 15min idle. Please allow for selectively enabling/disabling notifiers

as requested above:
```
jr@saturn:~> solaar -V
solaar 1.0.2
jr@saturn:~> solaar show
Unifying Receiver
  Device path  : /dev/hidraw4
  USB id       : 046d:c52b
  Serial       : AECC9DDE
    Firmware   : 12.11.B0032
    Bootloader : 04.16
    Other      : AA.AA
  Has 1 paired device(s) out of a maximum of 6.
  Notifications: wireless, software present (0x000900)
  Device activity counters: 1=147

  1: Wireless Mouse MX Master 3
     Codename     : MX Master 3
     Kind         : mouse
     Wireless PID : 4082
     Protocol     : HID++ 4.5
     Polling rate : 8 ms (125Hz)
     Serial number: AAC68E38
        Bootloader: BOT 95.00.B0013
          Firmware: MPM 19.00.B0013
             Other: 
     The power switch is located on the base.
     Supports 34 HID++ 2.0 features:
         0: ROOT                   {0000}   
         1: FEATURE SET            {0001}   
         2: DEVICE FW VERSION      {0003}   
         3: DEVICE NAME            {0005}   
         4: WIRELESS DEVICE STATUS {1D4B}   
         5: RESET                  {0020}                                                                                                                                                     
         6: CRYPTO ID              {0021}                                                                                                                                                     
         7: BATTERY STATUS         {1000}   
         8: REPROG CONTROLS V4     {1B04}   
         9: CHANGE HOST            {1814}   
        10: unknown:2250           {2250}   
        11: ADJUSTABLE DPI         {2201}   
        12: SMART SHIFT            {2110}   
        13: HIRES WHEEL            {2121}   
            Multiplier: 15
            Has invert
              Normal wheel motion
            Has ratchet switch
              Normal wheel mode
            Low resolution mode
            HID notification
        14: THUMB WHEEL            {2150}   
        15: unknown:2251           {2251}   
        16: DFUCONTROL SIGNED      {00C2}   
        17: DEVICE RESET           {1802}   internal, hidden
        18: unknown:1803           {1803}   internal, hidden
        19: CONFIG DEVICE PROPS    {1806}   internal, hidden
        20: unknown:1813           {1813}   internal, hidden
        21: OOBSTATE               {1805}   internal, hidden
        22: unknown:1830           {1830}   internal, hidden
        23: unknown:1890           {1890}   internal, hidden
        24: unknown:1891           {1891}   internal, hidden
        25: unknown:18A1           {18A1}   internal, hidden
        26: unknown:1DF3           {1DF3}   internal, hidden
        27: unknown:1E00           {1E00}   hidden
        28: unknown:1EB0           {1EB0}   internal, hidden
        29: unknown:1861           {1861}   internal, hidden
        30: unknown:9001           {9001}   internal, hidden
        31: unknown:9203           {9203}   internal, hidden
        32: unknown:9205           {9205}   internal, hidden
        33: unknown:9300           {9300}   internal, hidden
     Has 8 reprogrammable keys:
         0: LEFT CLICK                , default: LeftClick                   => LEFT CLICK                
             mse, pos:0, group:1, gmask:1
         1: RIGHT CLICK               , default: RightClick                  => RIGHT CLICK               
             mse, pos:0, group:1, gmask:1
         2: MIDDLE BUTTON             , default: MiddleMouseButton           => MIDDLE BUTTON             
             mse, reprogrammable, divertable, pos:0, group:3, gmask:7
         3: BACK AS BUTTON 4          , default: BackEx                      => BACK AS BUTTON 4          
             mse, reprogrammable, divertable, pos:0, group:2, gmask:3
         4: FORWARD AS BUTTON 5       , default: BrowserForwardEx            => FORWARD AS BUTTON 5       
             mse, reprogrammable, divertable, pos:0, group:2, gmask:3
         5: unknown:00C3              , default: unknown:00A9                => unknown:00C3              
             mse, reprogrammable, divertable, pos:0, group:3, gmask:7
         6: unknown:00C4              , default: unknown:009D                => unknown:00C4              
             mse, reprogrammable, divertable, pos:0, group:3, gmask:7
         7: unknown:00D7              , default: unknown:00B4                => unknown:00D7              
             divertable, virtual, pos:0, group:4, gmask:0
     Battery: 100%, discharging.

jr@saturn:~> 
```

thanks!
/j
One problem with selective notifications is how to set up the interface.   Suggestions are welcome.  (But don't expect quick action in any case.)
https://i.imgur.com/AwJEFOg.png

by interface you mean the config? I'll think about it, for a start an $ENV var would already be fine
`SolaarDisableNotifiers="<regex>,MX Master.*powered on,<regex3>,<regex4>..." solaar`
Yes, how to set up what you want.  I'm not keen on environment variables for something that is going to be a permanent part of Solaar.  Really this kind of control over which notifications show should be in the window manager - even XFCE can control by application, and this should be extended to distinguish between normal and urgent notifications
I don't know details of kde beyond https://i.imgur.com/Px59T3s.png nor anything about XFCE, but it seems plausible that the config UI shows a list of "fixed value" notifications provided by the application and user may configure in which way (popup, audio, ...) the system handles a particular notification of that list.
The problem with this is neither XFCE/KDE/whatever nor solaar knows details of the properties of the notification that user wants to control - here "matches a regex '^.*[Mm]ouse.*Master.\*powered on.\*$'" where at least the part "Master" isn't known at compile time neither possibly at time of config adjustment.

Thus solaar needs a way for user to define notification properties, I'd suggest
```
solaar --notification='[!]<regex>, <titlename>, [,off]'
 -n --notification : defines a new notifier class for config dialog
 <regex>           : grep(1) -P pcrepattern(3) PCRE regular expression, 
                          the regex will get matched against the full text of notifier.
                          First char "!" denotes inverse match like grep -v. 
 <titlename>       : the name of this notifier class as shown in config
  off 0 on 1 [del] : optional string defining initial state of this notifier class, default "on"
```
The option may occur multiple times.
A notifier's text gets matched against all defined regex and for each match the defined action (rise a notifier) gets executed (on) or not (off). Thus you may suppress all (.*, all, off) but 
a few (Master. my mouse, on) notifiers. Notifiers that don't match any regex default to "on".
Notifier classes defined by this option get added to solaar's config file and this way stay persistent, 
For already existing notifier classes the enable state won't get changed but a change in regex will
propagate to the config file. 
User may delete notifier classes from config file either manually via editor or by specifying "del" for state.
I've been looking at the notifications.  It seems to me that there isn't a good rationale for when notifications show up so I'll take a look at improving notifications.
This may end up with notifications only for things like changes in battery levels.
@Joerg-rw My mouse does not cause notifications when it goes idle or comes back from idle so I'm not sure why yours does.  Can you run `solaar -dd` and paste the output around when the mouse comes back from idle?

Resolving patch:
diff --git a/lib/logitech_receiver/notifications.py b/lib/logitech_receiver/notifications.py
--- a/lib/logitech_receiver/notifications.py
+++ b/lib/logitech_receiver/notifications.py
@@ -296,8 +296,13 @@ def _process_feature_notification(device, status, n, feature):
         if n.address == 0x00:
             if _log.isEnabledFor(_DEBUG):
                 _log.debug('wireless status: %s', n)
-            if n.data[0:3] == b'\x01\x01\x01':
-                status.changed(active=True, alert=_ALERT.NOTIFICATION, reason='powered on')
+            reason = 'powered on' if n.data[2] == 1 else None
+            if n.data[1] == 1:  # device is asking for software reconfiguration so need to change status
+                # only show a user notification if the device can change hosts
+                # as we want to notify when a device changes to this host
+                # but the only indication we get is this notification
+                alert = _ALERT.NOTIFICATION if _F.CHANGE_HOST in device.features else _ALERT.NONE
+                status.changed(active=True, alert=alert, reason=reason)
             else:
                 _log.warn('%s: unknown WIRELESS %s', device, n)
         else:
diff --git a/lib/logitech_receiver/status.py b/lib/logitech_receiver/status.py
--- a/lib/logitech_receiver/status.py
+++ b/lib/logitech_receiver/status.py
@@ -318,11 +318,16 @@ def changed(self, active=None, alert=ALERT.NONE, reason=None, timestamp=None):
                     if battery is not None:
                         self[KEYS.BATTERY_LEVEL] = battery
 
-        if self.updated == 0 and active is True:
-            # if the device is active on the very first status notification,
-            # (meaning just when the program started or a new receiver was just
-            # detected), pop-up a notification about it
-            alert |= ALERT.NOTIFICATION
+        # A device that is not active on the first status notification
+        # but becomes active afterwards does not produce a pop-up notification
+        # so don't produce one here.  This cuts off pop-ups when Solaar starts,
+        # which can be problematic if Solaar is autostarted.
+        ## if self.updated == 0 and active is True:
+        ## if the device is active on the very first status notification,
+        ## (meaning just when the program started or a new receiver was just
+        ## detected), pop up a notification about it
+        ##    alert |= ALERT.NOTIFICATION
+
         self.updated = timestamp
 
         # if _log.isEnabledFor(_DEBUG):


Test patch: