Skip to content

Commit

Permalink
Merge pull request #369 from pol-rivero/launch-filters
Browse files Browse the repository at this point in the history
Implement launch filters
  • Loading branch information
nwg-piotr authored Dec 29, 2024
2 parents 00357f5 + a223ab7 commit 1a58fe3
Show file tree
Hide file tree
Showing 7 changed files with 124 additions and 2 deletions.
28 changes: 28 additions & 0 deletions nwg_panel/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
SKELETON_PANEL: dict = {
"name": "",
"output": "",
"run-if-output-exist": [],
"run-if-output-absent": [],
"layer": "bottom",
"position": "top",
"controls": "off",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -917,6 +923,8 @@ def check_defaults(self):
defaults = {
"name": "",
"output": "",
"run-if-output-exist": [],
"run-if-output-absent": [],
"monitor": "",
"layer": "bottom",
"position": "top",
Expand Down Expand Up @@ -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"])
Expand Down Expand Up @@ -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 ""

Expand Down
66 changes: 65 additions & 1 deletion nwg_panel/glade/config_panel.glade
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<property name="label-xalign">0.5</property>
<property name="shadow-type">out</property>
<child>
<!-- n-columns=4 n-rows=21 -->
<!-- n-columns=4 n-rows=23 -->
<object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="can-focus">False</property>
Expand Down Expand Up @@ -514,6 +514,70 @@
<property name="top-attach">7</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl-run-if-output-exist">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Run if outputs exist:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">20</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="lbl-run-if-output-absent">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="halign">end</property>
<property name="label" translatable="yes">Run if outputs absent:</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">21</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="run-if-output-exist">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="max-length">20</property>
<property name="width-chars">20</property>
<property name="max-width-chars">24</property>
<property name="caps-lock-warning">False</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">20</property>
</packing>
</child>
<child>
<object class="GtkEntry" id="run-if-output-absent">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="max-length">20</property>
<property name="width-chars">20</property>
<property name="max-width-chars">24</property>
<property name="caps-lock-warning">False</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">21</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
Expand Down
4 changes: 4 additions & 0 deletions nwg_panel/langs/en_US.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cmd>' on sway and 'hyprctl dispatch exec <cmd>' on Hyprland",
"save-to-database": "Save to database",
Expand Down
4 changes: 4 additions & 0 deletions nwg_panel/langs/ja_JP.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cmd>'、Hyprland では 'hyprctl dispatch exec <cmd>' を介してプログラムを実行するかどうかを決定します。",
"save-to-database": "データベースに保存",
Expand Down
4 changes: 4 additions & 0 deletions nwg_panel/langs/pl_PL.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cmd>' na sway lub 'hyprctl dispatch exec <cmd>' na Hyprland.",
"save-to-database": "Zapisz w bazie danych",
Expand Down
4 changes: 4 additions & 0 deletions nwg_panel/langs/pt_BR.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 <cmd>' no sway e 'hyprctl dispatch exec <cmd>' no Hyprland",
"save-to-database": "Salvar para bando de dados",
Expand Down
16 changes: 15 additions & 1 deletion nwg_panel/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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"]]
Expand All @@ -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

Expand Down

0 comments on commit 1a58fe3

Please sign in to comment.