Repository: pwr-Solaar/Solaar

Issue:
Use default Solaar icon for system tray
**Information**
<!-- Do not bother opening an issue for a version older than 1.0.1.  Please update to the latest version and see if your issue persists. -->
- Solaar version (`solaar --version` or `git describe --tags` if cloned from this repository): 1.0.4
- Distribution:  Fedora

**Describe the bug**
The current icon for Solaar in the system tray is a battery. This is slightly confusing, and moreover, the regular Solaar icon looks way better. I suggest to use the standard Solaar icon as the icon for the system tray.

See also [this issue](https://github.com/pwr-Solaar/Solaar/issues/918#issuecomment-673839905).

**Additional information**
The [Top Indicator App](https://extensions.gnome.org/extension/3681/top-indicator-app/) GNOME extension has to be installed on Fedora 33 GNOME Wayland to make the icon visible.


Discussion:

Resolving patch:
diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py
--- a/lib/solaar/gtk.py
+++ b/lib/solaar/gtk.py
@@ -49,7 +49,7 @@ def _require(module, os_package, gi=None, gi_package=None, gi_version=None):
         sys.exit('%s: missing required system package %s' % (NAME, os_package))
 
 
-prefer_symbolic_battery_icons = False
+battery_icons_style = 'regular'
 
 
 def _parse_arguments():
@@ -74,7 +74,12 @@ def _parse_arguments():
     arg_parser.add_argument(
         '-w', '--window', choices=('show', 'hide', 'only'), help='start with window showing / hidden / only (no tray icon)'
     )
-    arg_parser.add_argument('-b', '--battery-icons', choices=('regular', 'symbolic'), help='prefer regular / symbolic icons')
+    arg_parser.add_argument(
+        '-b',
+        '--battery-icons',
+        choices=('regular', 'symbolic', 'solaar'),
+        help='prefer regular battery / symbolic battery / solaar icons'
+    )
     arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
     arg_parser.add_argument('--help-actions', action='store_true', help='print help for the optional actions')
     arg_parser.add_argument('action', nargs=argparse.REMAINDER, choices=_cli.actions, help='optional actions to perform')
@@ -88,8 +93,8 @@ def _parse_arguments():
     if args.window is None:
         args.window = 'show'  # default behaviour is to show main window
 
-    global prefer_symbolic_battery_icons
-    prefer_symbolic_battery_icons = True if args.battery_icons == 'symbolic' else False
+    global battery_icons_style
+    battery_icons_style = args.battery_icons if args.battery_icons is not None else 'regular'
 
     import logging
     if args.debug > 0:
diff --git a/lib/solaar/ui/icons.py b/lib/solaar/ui/icons.py
--- a/lib/solaar/ui/icons.py
+++ b/lib/solaar/ui/icons.py
@@ -79,7 +79,6 @@ def _look_for_application_icons():
 
 
 _default_theme = None
-_use_symbolic_icons = False
 
 
 def _init_icon_paths():
@@ -93,15 +92,14 @@ def _init_icon_paths():
     if _log.isEnabledFor(_DEBUG):
         _log.debug('icon theme paths: %s', _default_theme.get_search_path())
 
-    if gtk.prefer_symbolic_battery_icons:
-        if _default_theme.has_icon('battery-good-symbolic'):
-            global _use_symbolic_icons
-            _use_symbolic_icons = True
-            return
-        else:
+    if gtk.battery_icons_style == 'symbolic':
+        if not _default_theme.has_icon('battery-good-symbolic'):
             _log.warning('failed to detect symbolic icons')
-    if not _default_theme.has_icon('battery-good'):
-        _log.warning('failed to detect icons')
+            gtk.battery_icons_style = 'regular'
+    if gtk.battery_icons_style == 'regular':
+        if not _default_theme.has_icon('battery-good'):
+            _log.warning('failed to detect icons')
+            gtk.battery_icons_style = 'none'
 
 
 #
@@ -129,10 +127,12 @@ def _battery_icon_name(level, charging):
     _init_icon_paths()
 
     if level is None or level < 0:
-        return 'battery-missing' + ('-symbolic' if _use_symbolic_icons else '')
+        return 'battery-missing' + ('-symbolic' if gtk.battery_icons_style == 'symbolic' else '')
 
     level_name = _first_res(level, ((90, 'full'), (50, 'good'), (20, 'low'), (5, 'caution'), (0, 'empty')))
-    return 'battery-%s%s%s' % (level_name, '-charging' if charging else '', '-symbolic' if _use_symbolic_icons else '')
+    return 'battery-%s%s%s' % (
+        level_name, '-charging' if charging else '', '-symbolic' if gtk.battery_icons_style == 'symbolic' else ''
+    )
 
 
 #
diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py
--- a/lib/solaar/ui/tray.py
+++ b/lib/solaar/ui/tray.py
@@ -25,6 +25,8 @@
 from logging import getLogger
 from time import time as _timestamp
 
+import solaar.gtk as gtk
+
 from gi.repository import GLib, Gtk
 from gi.repository.Gdk import ScrollDirection
 from logitech_receiver.status import KEYS as _K
@@ -198,7 +200,7 @@ def _destroy(indicator):
         indicator.set_status(AppIndicator3.IndicatorStatus.PASSIVE)
 
     def _update_tray_icon():
-        if _picked_device:
+        if _picked_device and gtk.battery_icons_style != 'solaar':
             _ignore, _ignore, name, device_status = _picked_device
             battery_level = device_status.get(_K.BATTERY_LEVEL)
             battery_charging = device_status.get(_K.BATTERY_CHARGING)
@@ -251,7 +253,7 @@ def _update_tray_icon():
         tooltip = '\n'.join(tooltip_lines).rstrip('\n')
         _icon.set_tooltip_markup(tooltip)
 
-        if _picked_device:
+        if _picked_device and gtk.battery_icons_style != 'solaar':
             _ignore, _ignore, name, device_status = _picked_device
             battery_level = device_status.get(_K.BATTERY_LEVEL)
             battery_charging = device_status.get(_K.BATTERY_CHARGING)


Test patch: