Skip to content

Commit e9521b2

Browse files
committed
settings: xdg activation
receive an xdg activation token from the trayicon and use it to activate the settings window. this is needed to bring the settings window to the front.
1 parent 6fb6d61 commit e9521b2

File tree

4 files changed

+26
-12
lines changed

4 files changed

+26
-12
lines changed

safeeyes/context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ def __getitem__(self, key: str) -> typing.Callable:
4040
"""This is soft-deprecated - it is preferred to access the property."""
4141
return getattr(self, key)
4242

43-
def show_settings(self) -> None:
44-
utility.execute_main_thread(self._application.show_settings)
43+
def show_settings(self, activation_token: typing.Optional[str] = None) -> None:
44+
utility.execute_main_thread(self._application.show_settings, activation_token)
4545

4646
def show_about(self) -> None:
4747
utility.execute_main_thread(self._application.show_about)

safeeyes/plugins/trayicon/plugin.py

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@
5353
<signal name="NewIcon"/>
5454
<signal name="NewTooltip"/>
5555
56+
<method name="ProvideXdgActivationToken">
57+
<arg name="token" type="s" direction="in"/>
58+
</method>
59+
5660
<property name="XAyatanaLabel" type="s" access="read"/>
5761
<signal name="XAyatanaNewLabel">
5862
<arg type="s" name="label" direction="out" />
@@ -374,6 +378,8 @@ class StatusNotifierItemService(DBusService):
374378
ItemIsMenu = True
375379
Menu = None
376380

381+
last_activation_token: typing.Optional[str] = None
382+
377383
def __init__(self, session_bus, menu_items):
378384
super().__init__(
379385
interface_info=SNI_NODE_INFO,
@@ -424,6 +430,9 @@ def set_xayatanalabel(self, label):
424430

425431
self.emit_signal("XAyatanaNewLabel", (label, ""))
426432

433+
def ProvideXdgActivationToken(self, token: str) -> None:
434+
self.last_activation_token = token
435+
427436

428437
class TrayIcon:
429438
"""Create and show the tray icon along with the tray menu."""
@@ -662,12 +671,12 @@ def quit_safe_eyes(self):
662671
self.idle_condition.release()
663672
self.quit()
664673

665-
def show_settings(self):
674+
def show_settings(self) -> None:
666675
"""Handle Settings menu action.
667676
668677
This action shows the Settings dialog.
669678
"""
670-
self.on_show_settings()
679+
self.on_show_settings(self.sni_service.last_activation_token)
671680

672681
def show_about(self):
673682
"""Handle About menu action.

safeeyes/safeeyes.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import atexit
2424
import logging
2525
from importlib import metadata
26+
import typing
2627

2728
import gi
2829
from safeeyes import context, utility
@@ -52,6 +53,8 @@ class SafeEyes(Gtk.Application):
5253
plugins_manager: PluginManager
5354
system_locale: str
5455

56+
_settings_dialog: typing.Optional[SettingsDialog] = None
57+
5558
def __init__(self, system_locale: str, config) -> None:
5659
super().__init__(
5760
application_id="io.github.slgobinath.SafeEyes",
@@ -60,7 +63,6 @@ def __init__(self, system_locale: str, config) -> None:
6063

6164
self.active = False
6265
self.config = config
63-
self.settings_dialog_active = False
6466
self._status = ""
6567
self.system_locale = system_locale
6668

@@ -314,17 +316,20 @@ def _retry_errored_plugins(self):
314316

315317
GLib.timeout_add_seconds(timeout, self._retry_errored_plugins)
316318

317-
def show_settings(self):
319+
def show_settings(self, activation_token: typing.Optional[str] = None) -> None:
318320
"""Listen to tray icon Settings action and send the signal to Settings
319321
dialog.
320322
"""
321-
if not self.settings_dialog_active:
323+
if self._settings_dialog is None:
322324
logging.info("Show Settings dialog")
323-
self.settings_dialog_active = True
324-
settings_dialog = SettingsDialog(
325+
self._settings_dialog = SettingsDialog(
325326
self, self.config.clone(), self.save_settings
326327
)
327-
settings_dialog.show()
328+
329+
if activation_token is not None:
330+
self._settings_dialog.set_startup_id(activation_token)
331+
332+
self._settings_dialog.show()
328333

329334
def show_required_plugin_dialog(self, error: RequiredPluginException) -> None:
330335
self.required_plugin_dialog_active = True
@@ -435,7 +440,7 @@ def save_settings(self, config):
435440
"""Listen to Settings dialog Save action and write to the config
436441
file.
437442
"""
438-
self.settings_dialog_active = False
443+
self._settings_dialog = None
439444

440445
if self.config == config:
441446
# Config is not modified

safeeyes/ui/settings_dialog.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ def __show_break_properties_dialog(
266266

267267
def show(self) -> None:
268268
"""Show the SettingsDialog."""
269-
super().show()
269+
self.present()
270270

271271
@Gtk.Template.Callback()
272272
def on_switch_postpone_activate(self, switch, state) -> None:

0 commit comments

Comments
 (0)