diff --git a/nwg_panel/config.py b/nwg_panel/config.py
index 5ea29231..6771e7f0 100644
--- a/nwg_panel/config.py
+++ b/nwg_panel/config.py
@@ -59,6 +59,8 @@
SKELETON_PANEL: dict = {
"name": "",
"output": "",
+ "run-if-output-exist": [],
+ "run-if-output-absent": [],
"layer": "bottom",
"position": "top",
"controls": "off",
@@ -277,6 +279,8 @@ def clear_active_id(combo, target_combo):
if combo.get_active_id():
target_combo.set_active_id("")
+def split_comma_separated_list(text):
+ return [x.strip() for x in text.split(",") if x.strip()]
def load_vocabulary():
global voc
@@ -863,6 +867,8 @@ def __init__(self, parent, file, panel_idx, plugin_menu_start):
self.eb_name = None
self.cb_output = None
+ self.eb_run_if_output_exist = None
+ self.eb_run_if_output_absent = None
self.cb_monitor = None
self.cb_position = None
self.cb_controls = None
@@ -917,6 +923,8 @@ def check_defaults(self):
defaults = {
"name": "",
"output": "",
+ "run-if-output-exist": [],
+ "run-if-output-absent": [],
"monitor": "",
"layer": "bottom",
"position": "top",
@@ -970,6 +978,20 @@ def edit_panel(self, *args):
builder.get_object("lbl-css-name").set_text("{}:".format(voc["css-name"]))
builder.get_object("lbl-hide-show-signal").set_text("{}: ".format(voc["hide-show-signal"]))
+ self.eb_run_if_output_exist = builder.get_object("run-if-output-exist")
+ self.eb_run_if_output_exist.set_text(",".join(self.panel["run-if-output-exist"]))
+ self.eb_run_if_output_exist.set_tooltip_text(voc["run-if-output-exist-tooltip"])
+ cb = builder.get_object("lbl-run-if-output-exist")
+ cb.set_text("{}:".format(voc["run-if-output-exist"]))
+ cb.set_tooltip_text(voc["run-if-output-exist-tooltip"])
+
+ self.eb_run_if_output_absent = builder.get_object("run-if-output-absent")
+ self.eb_run_if_output_absent.set_text(",".join(self.panel["run-if-output-absent"]))
+ self.eb_run_if_output_absent.set_tooltip_text(voc["run-if-output-absent-tooltip"])
+ cb = builder.get_object("lbl-run-if-output-absent")
+ cb.set_text("{}:".format(voc["run-if-output-absent"]))
+ cb.set_tooltip_text(voc["run-if-output-absent-tooltip"])
+
cb = builder.get_object("homogeneous")
cb.set_label(voc["homogeneous"])
cb.set_tooltip_text(voc["homogeneous-tooltip"])
@@ -1154,6 +1176,12 @@ def update_panel(self):
val = self.cb_output.get_active_id()
self.panel["output"] = val if val else ""
+ val = self.eb_run_if_output_exist.get_text()
+ self.panel["run-if-output-exist"] = split_comma_separated_list(val)
+
+ val = self.eb_run_if_output_absent.get_text()
+ self.panel["run-if-output-absent"] = split_comma_separated_list(val)
+
val = self.cb_monitor.get_active_id()
self.panel["monitor"] = val if val else ""
diff --git a/nwg_panel/glade/config_panel.glade b/nwg_panel/glade/config_panel.glade
index b1164eec..e7d335d0 100644
--- a/nwg_panel/glade/config_panel.glade
+++ b/nwg_panel/glade/config_panel.glade
@@ -8,7 +8,7 @@
0.5
out
-
+
+
+
+
+ 0
+ 20
+
+
+
+
+
+ 0
+ 21
+
+
+
+
+
+ 1
+ 20
+
+
+
+
+
+ 1
+ 21
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/nwg_panel/langs/en_US.json b/nwg_panel/langs/en_US.json
index 63ee2036..bf3f9e3a 100644
--- a/nwg_panel/langs/en_US.json
+++ b/nwg_panel/langs/en_US.json
@@ -211,6 +211,10 @@
"resume-refresh": "Resume refresh",
"right-margin": "Right margin",
"root-css-name": "Root CSS name",
+ "run-if-output-exist": "Run if outputs exist",
+ "run-if-output-exist-tooltip": "The panel will be launched only if all these outputs are connected. Comma-separated list of output names.",
+ "run-if-output-absent": "Run if outputs absent",
+ "run-if-output-absent-tooltip": "The panel will be launched only if all these outputs are disconnected. Comma-separated list of output names.",
"run-through-compositor": "Run programs through compositor",
"run-through-compositor-tooltip": "Determines if to execute programs via 'swaymsg exec ' on sway and 'hyprctl dispatch exec ' on Hyprland",
"save-to-database": "Save to database",
diff --git a/nwg_panel/langs/ja_JP.json b/nwg_panel/langs/ja_JP.json
index 948d4f0e..b49ac34b 100644
--- a/nwg_panel/langs/ja_JP.json
+++ b/nwg_panel/langs/ja_JP.json
@@ -188,6 +188,10 @@
"restart-on-display": "ディスプレイ接続時に再起動",
"right-margin": "右マージン",
"root-css-name": "ルート CSS 名",
+ "run-if-output-exist": "出力が存在する場合に起動",
+ "run-if-output-exist-tooltip": "すべての出力が接続されている場合にのみパネルが起動します。出力名をカンマで区切って指定してください。",
+ "run-if-output-absent": "出力が存在しない場合に起動",
+ "run-if-output-absent-tooltip": "すべての出力が切断されている場合にのみパネルが起動します。出力名をカンマで区切って指定してください。",
"run-through-compositor": "コンポジタを介してプログラムを実行",
"run-through-compositor-tooltip": "Sway では 'swaymsg exec '、Hyprland では 'hyprctl dispatch exec ' を介してプログラムを実行するかどうかを決定します。",
"save-to-database": "データベースに保存",
diff --git a/nwg_panel/langs/pl_PL.json b/nwg_panel/langs/pl_PL.json
index c859dc1b..8e58c4d8 100644
--- a/nwg_panel/langs/pl_PL.json
+++ b/nwg_panel/langs/pl_PL.json
@@ -211,6 +211,10 @@
"resume-refresh": "Wznów odświeżanie",
"right-margin": "Prawy margines",
"root-css-name": "Pierwotna nazwa CSS",
+ "run-if-output-exist": "Uruchom, jeśli istnieją wyjścia",
+ "run-if-output-exist-tooltip": "Panel zostanie uruchomiony tylko wtedy, gdy wszystkie te wyjścia są podłączone. Lista nazw wyjść oddzielona przecinkami.",
+ "run-if-output-absent": "Uruchom, jeśli brak wyjść",
+ "run-if-output-absent-tooltip": "Panel zostanie uruchomiony tylko wtedy, gdy wszystkie te wyjścia są odłączone. Lista nazw wyjść oddzielona przecinkami.",
"run-through-compositor": "Uruchamiaj programy przez kompozytor",
"run-through-compositor-tooltip": "Określa czy uruchamiać programy przez 'swaymsg exec ' na sway lub 'hyprctl dispatch exec ' na Hyprland.",
"save-to-database": "Zapisz w bazie danych",
diff --git a/nwg_panel/langs/pt_BR.json b/nwg_panel/langs/pt_BR.json
index e56f5352..6d2ff308 100644
--- a/nwg_panel/langs/pt_BR.json
+++ b/nwg_panel/langs/pt_BR.json
@@ -189,6 +189,10 @@
"restart-on-display": "Reiniciar ao conectar tela",
"right-margin": "Margem direita",
"root-css-name": "Nome raiz CSS",
+ "run-if-output-exist": "Executar se as saídas existirem",
+ "run-if-output-exist-tooltip": "O painel será iniciado apenas se todas essas saídas estiverem conectadas. Lista de nomes de saídas separada por vírgulas.",
+ "run-if-output-absent": "Executar se as saídas estiverem ausentes",
+ "run-if-output-absent-tooltip": "O painel será iniciado apenas se todas essas saídas estiverem desconectadas. Lista de nomes de saídas separada por vírgulas.",
"run-through-compositor": "Rodar programas através de \"compositor\"",
"run-through-compositor-tooltip": "Determina se deve executar programa via 'swaymsg exec ' no sway e 'hyprctl dispatch exec ' no Hyprland",
"save-to-database": "Salvar para bando de dados",
diff --git a/nwg_panel/main.py b/nwg_panel/main.py
index 2124ffc8..61e5cd64 100644
--- a/nwg_panel/main.py
+++ b/nwg_panel/main.py
@@ -177,6 +177,10 @@ def hypr_watcher():
# print(f"events: {event_names}")
for event_name in event_names:
+ if common_settings["restart-on-display"] and (event_name in ["monitoradded", "monitorremoved"]):
+ print("Received event '{}'; restart in {} ms.".format(event_name, common_settings["restart-delay"]))
+ GLib.timeout_add(common_settings["restart-delay"], restart, priority=GLib.PRIORITY_HIGH)
+
if event_name in ["activespecial",
"activewindow",
"activewindowv2",
@@ -589,6 +593,8 @@ def main():
for panel in panels:
check_key(panel, "output", "")
check_key(panel, "monitor", "")
+ check_key(panel, "run-if-output-exist", [])
+ check_key(panel, "run-if-output-absent", [])
if panel["monitor"]:
try:
panel["output"] = common.mon_desc2output_name[panel["monitor"]]
@@ -604,9 +610,17 @@ def main():
clones.append(clone)
to_append = to_append + clones
+ else:
+ for output in panel["run-if-output-exist"]:
+ if output not in common.outputs:
+ to_remove.append(panel)
+ for output in panel["run-if-output-absent"]:
+ if output in common.outputs:
+ to_remove.append(panel)
for item in to_remove:
- panels.remove(item)
+ if item in panels:
+ panels.remove(item)
panels = panels + to_append