From 65d4f50269b54624d70346a58d472cb912be090a Mon Sep 17 00:00:00 2001 From: Midgard <2885-Midgard@users.noreply.framagit.org> Date: Sat, 25 May 2024 19:35:25 +0200 Subject: [PATCH] [yambar.sway] Don't spam placeholders when sway isn't running --- yambar/config.yml | 200 +++++++++++++++++++++++----------------------- yambar/sway.py | 11 ++- 2 files changed, 112 insertions(+), 99 deletions(-) diff --git a/yambar/config.yml b/yambar/config.yml index f99d3ca..6da25b6 100644 --- a/yambar/config.yml +++ b/yambar/config.yml @@ -94,104 +94,108 @@ bar: ws_focused: &ws_focused {foreground: *col_fg, <<: *ws_common} ws_visible: &ws_visible {foreground: *col_visible_ws, <<: *ws_common} content: - - list: - spacing: 0 - items: - - map: - default: {string: {text: "{ws0}", <<: *ws_default}} - conditions: - ws0_state == unused: {empty: {}} - ws0_state == focused: {string: {text: "{ws0}", <<: *ws_focused}} - ws0_state == visible: {string: {text: "{ws0}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws1_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws1}", <<: *ws_default}} - conditions: - ws1_state == unused: {empty: {}} - ws1_state == focused: {string: {text: "{ws1}", <<: *ws_focused}} - ws1_state == visible: {string: {text: "{ws1}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws2_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws2}", <<: *ws_default}} - conditions: - ws2_state == unused: {empty: {}} - ws2_state == focused: {string: {text: "{ws2}", <<: *ws_focused}} - ws2_state == visible: {string: {text: "{ws2}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws3_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws3}", <<: *ws_default}} - conditions: - ws3_state == unused: {empty: {}} - ws3_state == focused: {string: {text: "{ws3}", <<: *ws_focused}} - ws3_state == visible: {string: {text: "{ws3}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws4_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws4}", <<: *ws_default}} - conditions: - ws4_state == unused: {empty: {}} - ws4_state == focused: {string: {text: "{ws4}", <<: *ws_focused}} - ws4_state == visible: {string: {text: "{ws4}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws5_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws5}", <<: *ws_default}} - conditions: - ws5_state == unused: {empty: {}} - ws5_state == focused: {string: {text: "{ws5}", <<: *ws_focused}} - ws5_state == visible: {string: {text: "{ws5}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws6_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws6}", <<: *ws_default}} - conditions: - ws6_state == unused: {empty: {}} - ws6_state == focused: {string: {text: "{ws6}", <<: *ws_focused}} - ws6_state == visible: {string: {text: "{ws6}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws7_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws7}", <<: *ws_default}} - conditions: - ws7_state == unused: {empty: {}} - ws7_state == focused: {string: {text: "{ws7}", <<: *ws_focused}} - ws7_state == visible: {string: {text: "{ws7}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws8_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws8}", <<: *ws_default}} - conditions: - ws8_state == unused: {empty: {}} - ws8_state == focused: {string: {text: "{ws8}", <<: *ws_focused}} - ws8_state == visible: {string: {text: "{ws8}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws9_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws9}", <<: *ws_default}} - conditions: - ws9_state == unused: {empty: {}} - ws9_state == focused: {string: {text: "{ws9}", <<: *ws_focused}} - ws9_state == visible: {string: {text: "{ws9}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws10_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws10}", <<: *ws_default}} - conditions: - ws10_state == unused: {empty: {}} - ws10_state == focused: {string: {text: "{ws10}", <<: *ws_focused}} - ws10_state == visible: {string: {text: "{ws10}", <<: *ws_visible}} - - map: {default: {empty: {}}, conditions: {ws11_new_monitor: *monitor_sep}} - - map: - default: {string: {text: "{ws11}", <<: *ws_default}} - conditions: - ws11_state == unused: {empty: {}} - ws11_state == focused: {string: {text: "{ws11}", <<: *ws_focused}} - ws11_state == visible: {string: {text: "{ws11}", <<: *ws_visible}} - - map: - default: - - {empty: {left-margin: 5}} - - string: - text: "{mode}" - left-margin: 5 - right-margin: 5 - deco: - background: - color: 9c5842d8 - conditions: - mode == default: {empty: {}} + - map: + conditions: + ~sway_running: {empty: {}} + default: + list: + spacing: 0 + items: + - map: + default: {string: {text: "{ws0}", <<: *ws_default}} + conditions: + ws0_state == unused: {empty: {}} + ws0_state == focused: {string: {text: "{ws0}", <<: *ws_focused}} + ws0_state == visible: {string: {text: "{ws0}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws1_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws1}", <<: *ws_default}} + conditions: + ws1_state == unused: {empty: {}} + ws1_state == focused: {string: {text: "{ws1}", <<: *ws_focused}} + ws1_state == visible: {string: {text: "{ws1}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws2_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws2}", <<: *ws_default}} + conditions: + ws2_state == unused: {empty: {}} + ws2_state == focused: {string: {text: "{ws2}", <<: *ws_focused}} + ws2_state == visible: {string: {text: "{ws2}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws3_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws3}", <<: *ws_default}} + conditions: + ws3_state == unused: {empty: {}} + ws3_state == focused: {string: {text: "{ws3}", <<: *ws_focused}} + ws3_state == visible: {string: {text: "{ws3}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws4_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws4}", <<: *ws_default}} + conditions: + ws4_state == unused: {empty: {}} + ws4_state == focused: {string: {text: "{ws4}", <<: *ws_focused}} + ws4_state == visible: {string: {text: "{ws4}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws5_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws5}", <<: *ws_default}} + conditions: + ws5_state == unused: {empty: {}} + ws5_state == focused: {string: {text: "{ws5}", <<: *ws_focused}} + ws5_state == visible: {string: {text: "{ws5}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws6_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws6}", <<: *ws_default}} + conditions: + ws6_state == unused: {empty: {}} + ws6_state == focused: {string: {text: "{ws6}", <<: *ws_focused}} + ws6_state == visible: {string: {text: "{ws6}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws7_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws7}", <<: *ws_default}} + conditions: + ws7_state == unused: {empty: {}} + ws7_state == focused: {string: {text: "{ws7}", <<: *ws_focused}} + ws7_state == visible: {string: {text: "{ws7}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws8_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws8}", <<: *ws_default}} + conditions: + ws8_state == unused: {empty: {}} + ws8_state == focused: {string: {text: "{ws8}", <<: *ws_focused}} + ws8_state == visible: {string: {text: "{ws8}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws9_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws9}", <<: *ws_default}} + conditions: + ws9_state == unused: {empty: {}} + ws9_state == focused: {string: {text: "{ws9}", <<: *ws_focused}} + ws9_state == visible: {string: {text: "{ws9}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws10_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws10}", <<: *ws_default}} + conditions: + ws10_state == unused: {empty: {}} + ws10_state == focused: {string: {text: "{ws10}", <<: *ws_focused}} + ws10_state == visible: {string: {text: "{ws10}", <<: *ws_visible}} + - map: {default: {empty: {}}, conditions: {ws11_new_monitor: *monitor_sep}} + - map: + default: {string: {text: "{ws11}", <<: *ws_default}} + conditions: + ws11_state == unused: {empty: {}} + ws11_state == focused: {string: {text: "{ws11}", <<: *ws_focused}} + ws11_state == visible: {string: {text: "{ws11}", <<: *ws_visible}} + - map: + default: + - {empty: {left-margin: 5}} + - string: + text: "{mode}" + left-margin: 5 + right-margin: 5 + deco: + background: + color: 9c5842d8 + conditions: + mode == default: {empty: {}} - mem: poll-interval: 1500 diff --git a/yambar/sway.py b/yambar/sway.py index 737ff7a..8e9ea47 100755 --- a/yambar/sway.py +++ b/yambar/sway.py @@ -6,6 +6,7 @@ import socket import struct import json import traceback +import time from typing import List @@ -19,7 +20,14 @@ magic = b"i3-ipc" msg_header = struct.Struct("II") s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) -s.connect(os.getenvb(b"SWAYSOCK")) +SWAYSOCK = os.getenvb(b"SWAYSOCK") +if not SWAYSOCK: + while True: + # print("\n".join(result), flush=True) + print("sway_running|bool|false\n", flush=True) + time.sleep(60 * 60 * 60) + +s.connect(SWAYSOCK) def recv(): reply_magic = s.recv(6) @@ -90,6 +98,7 @@ def print_state(): global state_mode print(f"""{format_workspaces(state_workspaces)} mode|string|{state_mode} +sway_running|bool|true """, flush=True) print_state()