diff --git a/lib/solaar/gtk.py b/lib/solaar/gtk.py index fc0bd063..41aa9084 100755 --- a/lib/solaar/gtk.py +++ b/lib/solaar/gtk.py @@ -48,7 +48,7 @@ def _parse_arguments(): help='unifying receiver to use; the first detected receiver if unspecified. Example: /dev/hidraw2') arg_parser.add_argument('--restart-on-wake-up', action='store_true', help='restart Solaar on sleep wake-up (experimental)') - arg_parser.add_argument('-t', '--tray', action='store_true', help='start GUI with only tray icon') + arg_parser.add_argument('-w', '--window', choices=('hide','show','only'), help='start with window hidden / showing / only (no tray icon)') 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') @@ -61,6 +61,9 @@ def _parse_arguments(): _cli.print_help() return + if args.window is None: + args.window = 'hide' + import logging if args.debug > 0: log_level = logging.WARNING - 10 * args.debug @@ -106,7 +109,7 @@ def main(): _upower.watch(listener.ping_all) # main UI event loop - ui.run_loop(listener.start_all, listener.stop_all, args.tray) + ui.run_loop(listener.start_all, listener.stop_all, args.window!='only', args.window!='hide') except Exception as e: import sys sys.exit('%s: error: %s' % (NAME.lower(), e)) diff --git a/lib/solaar/ui/__init__.py b/lib/solaar/ui/__init__.py index 63a0bcd6..be437e44 100644 --- a/lib/solaar/ui/__init__.py +++ b/lib/solaar/ui/__init__.py @@ -86,7 +86,7 @@ def ui_async(function, *args, **kwargs): from . import notify, tray, window -def _startup(app, startup_hook, tray_only): +def _startup(app, startup_hook, use_tray, show_window): if _log.isEnabledFor(_DEBUG): _log.debug("startup registered=%s, remote=%s", app.get_is_registered(), app.get_is_remote()) @@ -96,8 +96,9 @@ def _startup(app, startup_hook, tray_only): _task_runner.start() notify.init() - tray.init(lambda _ignore: window.destroy()) - window.init(tray_only) + if use_tray: + tray.init(lambda _ignore: window.destroy()) + window.init(show_window, use_tray) startup_hook() @@ -133,12 +134,13 @@ def _shutdown(app, shutdown_hook): notify.uninit() -def run_loop(startup_hook, shutdown_hook, tray_only, args=None): +def run_loop(startup_hook, shutdown_hook, use_tray, show_window, args=None): + assert use_tray or show_window, 'need either tray or visible window' # from gi.repository.Gio import ApplicationFlags as _ApplicationFlags APP_ID = 'io.github.pwr.solaar' application = Gtk.Application.new(APP_ID, 0) # _ApplicationFlags.HANDLES_COMMAND_LINE) - application.connect('startup', lambda app, startup_hook:_startup(app,startup_hook,tray_only), startup_hook) + application.connect('startup', lambda app, startup_hook:_startup(app,startup_hook,use_tray,show_window), startup_hook) application.connect('command-line', _command_line) application.connect('activate', _activate) application.connect('shutdown', _shutdown, shutdown_hook) diff --git a/lib/solaar/ui/tray.py b/lib/solaar/ui/tray.py index 161775a5..f59a28ff 100644 --- a/lib/solaar/ui/tray.py +++ b/lib/solaar/ui/tray.py @@ -458,10 +458,10 @@ def init(_quit_handler): def destroy(): global _icon, _menu, _devices_info - assert _icon is not None - i, _icon = _icon, None - _destroy(i) - i = None + if _icon is not None: + i, _icon = _icon, None + _destroy(i) + i = None _icon = None _menu = None diff --git a/lib/solaar/ui/window.py b/lib/solaar/ui/window.py index b72b66e5..2086c6a6 100644 --- a/lib/solaar/ui/window.py +++ b/lib/solaar/ui/window.py @@ -304,11 +304,10 @@ def _create_window_layout(): panel.pack_start(_info, True, True, 0) panel.pack_start(_empty, True, True, 0) - about_button = _new_button(_("About") + ' ' + NAME, 'help-about', - icon_size=_SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window) - bottom_buttons_box = Gtk.ButtonBox(Gtk.Orientation.HORIZONTAL) bottom_buttons_box.set_layout(Gtk.ButtonBoxStyle.START) + about_button = _new_button(_("About") + ' ' + NAME, 'help-about', + icon_size=_SMALL_BUTTON_ICON_SIZE, clicked=_show_about_window) bottom_buttons_box.add(about_button) # solaar_version = Gtk.Label() @@ -327,7 +326,7 @@ def _create_window_layout(): return vbox -def _create(): +def _create(delete_action): window = Gtk.Window() window.set_title(NAME) window.set_role('status-window') @@ -335,7 +334,7 @@ def _create(): # window.set_type_hint(Gdk.WindowTypeHint.UTILITY) # window.set_skip_taskbar_hint(True) # window.set_skip_pager_hint(True) - window.connect('delete-event', _hide) + window.connect('delete-event', delete_action) vbox = _create_window_layout() window.add(vbox) @@ -731,7 +730,7 @@ _empty = None _window = None -def init(tray_only): +def init(show_window,hide_on_close): Gtk.Window.set_default_icon_name(NAME.lower()) Gtk.Window.set_default_icon_from_file(_icons.icon_file(NAME.lower())) @@ -741,12 +740,12 @@ def init(tray_only): _details = _create_details_panel() _info = _create_info_panel() _empty = _create_empty_panel() - _window = _create() - if (not tray_only) : + _window = _create(_hide if hide_on_close else destroy) + if show_window: _window.present() -def destroy(): +def destroy(_ignore1=None, _ignore2=None): global _model, _tree, _details, _info, _empty, _window w, _window = _window, None w.destroy()