ui: add --battery-icons=symbolic option to prefer symbolic icons

This commit is contained in:
Peter F. Patel-Schneider 2020-05-11 07:42:57 -04:00 committed by Filipe Laíns
parent 813c238704
commit 302720b0db
4 changed files with 21 additions and 23 deletions

View File

@ -102,23 +102,13 @@ For many devices, Solaar shows the approximate battery level via icons that
show up in both main Solaar window and the system tray. Solaar used to use show up in both main Solaar window and the system tray. Solaar used to use
several heuristics to determine which icon names to use for this purpose, several heuristics to determine which icon names to use for this purpose,
but as more and more battery icon schemes have been developed this has but as more and more battery icon schemes have been developed this has
become impossible to do well. Solaar now only uses the eleven standard become impossible to do well. Solaar now uses the eleven standard
battery icon names `battery-{full,good,low,critical,empty}[-charging]` and battery icon names `battery-{full,good,low,critical,empty}[-charging]` and
`battery-missing`. To use different icons from you have to change (part of) `battery-missing`.
your GTK icon theme.
Solaar is not using the symbolic versions of these icons because of a bug
external to Solaar that results in these icons not changing to the
foreground colour in the system tray. This can leave these icons nearly
invisible in dark themes. It would be useful to be able to switch to
symbolic icons via GTK styling (using something like
`.solaar * { -gtk-icon-style: symbolic; }` in the user's gtk.css)
but most or all current system tray implementations do not allow for this.
As a temporary hack setting the SOLAAR_TRAY_BATTERY_ICON_SYBOLIC environment
variable will cause Solaar to use symbolic icons for battery levels in the
system tray.
Solaar will use the symbolic versions of these icons if started with the
option `--battery-icons=symbolic`. Because of bugs external to Solaar
these symbolic icons may be nearly invisible in dark themes.
[solaar]: https://github.com/pwr-Solaar/Solaar [solaar]: https://github.com/pwr-Solaar/Solaar
[logitech]: https://www.logitech.com [logitech]: https://www.logitech.com

View File

@ -40,6 +40,7 @@ def _require(module, os_package, gi=None, gi_package=None, gi_version=None):
import sys import sys
sys.exit("%s: missing required system package %s" % (NAME, os_package)) sys.exit("%s: missing required system package %s" % (NAME, os_package))
prefer_symbolic_battery_icons = False
def _parse_arguments(): def _parse_arguments():
import argparse import argparse
@ -51,6 +52,7 @@ def _parse_arguments():
arg_parser.add_argument('--restart-on-wake-up', action='store_true', arg_parser.add_argument('--restart-on-wake-up', action='store_true',
help='restart Solaar on sleep wake-up (experimental)') help='restart Solaar on sleep wake-up (experimental)')
arg_parser.add_argument('-w', '--window', choices=('show','hide','only'), help='start with window showing / hidden / only (no tray icon)') 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('-V', '--version', action='version', version='%(prog)s ' + __version__) arg_parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__)
arg_parser.add_argument('--help-actions', action='store_true', arg_parser.add_argument('--help-actions', action='store_true',
help='print help for the optional actions') help='print help for the optional actions')
@ -66,6 +68,9 @@ def _parse_arguments():
if args.window is None: if args.window is None:
args.window = 'show' # default behaviour is to show main window 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
import logging import logging
if args.debug > 0: if args.debug > 0:
log_level = logging.WARNING - 10 * args.debug log_level = logging.WARNING - 10 * args.debug

View File

@ -24,6 +24,7 @@ _log = getLogger(__name__)
del getLogger del getLogger
from gi.repository import Gtk from gi.repository import Gtk
import solaar.gtk as gtk
# #
# #
@ -73,6 +74,7 @@ def _look_for_application_icons():
_default_theme = None _default_theme = None
_use_symbolic_icons = False
def _init_icon_paths(): def _init_icon_paths():
global _default_theme global _default_theme
@ -85,6 +87,13 @@ def _init_icon_paths():
if _log.isEnabledFor(_DEBUG): if _log.isEnabledFor(_DEBUG):
_log.debug("icon theme paths: %s", _default_theme.get_search_path()) _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:
_log.warning("failed to detect symbolic icons")
if not _default_theme.has_icon('battery-good'): if not _default_theme.has_icon('battery-good'):
_log.warning("failed to detect icons") _log.warning("failed to detect icons")
@ -110,10 +119,10 @@ def _battery_icon_name(level, charging):
_init_icon_paths() _init_icon_paths()
if level is None or level < 0: if level is None or level < 0:
return 'battery-missing' return 'battery-missing' + ( '-symbolic' if _use_symbolic_icons else '' )
level_name = _first_res(level,((90,'full'), (50,'good'), (20,'low'), (5,'caution'), (0,'empty'))) level_name = _first_res(level,((90,'full'), (50,'good'), (20,'low'), (5,'caution'), (0,'empty')))
return 'battery-%s%s' % (level_name, '-charging' if charging else '') return 'battery-%s%s%s' % (level_name, '-charging' if charging else '', '-symbolic' if _use_symbolic_icons else '')
# #
# #

View File

@ -203,9 +203,6 @@ try:
battery_charging = device_status.get(_K.BATTERY_CHARGING) battery_charging = device_status.get(_K.BATTERY_CHARGING)
tray_icon_name = _icons.battery(battery_level, battery_charging) tray_icon_name = _icons.battery(battery_level, battery_charging)
# get around system tray icons not having styling and not having css class
tray_icon_name = tray_icon_name + ( "-symbolic" if "SOLAAR_TRAY_BATTERY_ICON_SYBOLIC" in os.environ else "" )
description = '%s: %s' % (name, device_status.to_string()) description = '%s: %s' % (name, device_status.to_string())
else: else:
# there may be a receiver, but no peripherals # there may be a receiver, but no peripherals
@ -263,9 +260,6 @@ except ImportError:
battery_level = device_status.get(_K.BATTERY_LEVEL) battery_level = device_status.get(_K.BATTERY_LEVEL)
battery_charging = device_status.get(_K.BATTERY_CHARGING) battery_charging = device_status.get(_K.BATTERY_CHARGING)
tray_icon_name = _icons.battery(battery_level, battery_charging) tray_icon_name = _icons.battery(battery_level, battery_charging)
# get around system tray icons not having styling and not having css class
tray_icon_name = tray_icon_name + ( "-symbolic" if "SOLAAR_TRAY_BATTERY_ICON_SYBOLIC" in os.environ else "" )
else: else:
# there may be a receiver, but no peripherals # there may be a receiver, but no peripherals
tray_icon_name = _icons.TRAY_OKAY if _devices_info else _icons.TRAY_ATTENTION tray_icon_name = _icons.TRAY_OKAY if _devices_info else _icons.TRAY_ATTENTION