From adae5a2e2b1316a0bbfc413e8f08a42cf4e80090 Mon Sep 17 00:00:00 2001 From: "Peter F. Patel-Schneider" Date: Mon, 29 Nov 2021 11:43:03 -0500 Subject: [PATCH] ui: add option to specify use of explict tray icon files and their size --- docs/index.md | 7 +++++-- lib/solaar/gtk.py | 3 +++ lib/solaar/ui/tray.py | 8 +++++--- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/docs/index.md b/docs/index.md index fd384eef..c02d8bb5 100644 --- a/docs/index.md +++ b/docs/index.md @@ -121,8 +121,11 @@ for the step-by-step procedure for manual installation. - If some icons appear broken in the application, make sure you've properly configured the Gtk theme and icon theme in your control panel. -- There are several implementations of the system tray. Some of these have problems - that can result in missing or wrong-sized icons. +- Solaar normally uses icon names for its icons, which in some system tray implementatations + results in missing or wrong-sized icons. + The `--tray-icon-size` option forces Solaar to use icon files of appropriate size + for tray icons instead, which produces better results in some system tray implementatations. + To use icon files close to 32 pixels in size use `--tray-icon-size=32`. - The icon in the system tray can show up as 'black on black' in dark themes or as non-symbolic when the theme uses symbolic icons. This is due to problems diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index 10644fbf..6d88e4d7 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -81,6 +81,7 @@ def _parse_arguments(): choices=('regular', 'symbolic', 'solaar'), help='prefer regular battery / symbolic battery / solaar icons' ) + arg_parser.add_argument('--tray-icon-size', type=int, help='explicit size for tray 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') @@ -96,6 +97,8 @@ def _parse_arguments(): global battery_icons_style battery_icons_style = args.battery_icons if args.battery_icons is not None else 'regular' + global tray_icon_size + tray_icon_size = args.tray_icon_size import logging if args.debug > 0: diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py index 68f6b86c..15371492 100644 --- a/lib/solaar/ui/tray.py +++ b/lib/solaar/ui/tray.py @@ -42,7 +42,7 @@ del getLogger # constants # -_TRAY_ICON_SIZE = 64 # pixels - make large as downscaling is done but not always upscaling +_TRAY_ICON_SIZE = 48 _MENU_ICON_SIZE = Gtk.IconSize.LARGE_TOOLBAR _RECEIVER_SEPARATOR = ('~', None, None, None) @@ -174,9 +174,11 @@ try: # https://bugs.launchpad.net/ubuntu/+source/libappindicator/+bug/1363277 # Defense against bug that shows up in XFCE 4.16 where icons are not upscaled def _icon_file(icon_name): - if False and not os.path.isfile(icon_name): + if gtk.tray_icon_size is None and not os.path.isfile(icon_name): return icon_name - icon_info = Gtk.IconTheme.get_default().lookup_icon(icon_name, _TRAY_ICON_SIZE, Gtk.IconLookupFlags.FORCE_SVG) + icon_info = Gtk.IconTheme.get_default().lookup_icon( + icon_name, gtk.tray_icon_size or _TRAY_ICON_SIZE, Gtk.IconLookupFlags.FORCE_SVG + ) return icon_info.get_filename() if icon_info else icon_name def _create(menu):