aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--i3blocks/.config/i3blocks/config19
-rwxr-xr-xi3blocks/.local/bin/i3blocks-dunst38
-rwxr-xr-xi3blocks/.local/bin/i3blocks-title49
3 files changed, 106 insertions, 0 deletions
diff --git a/i3blocks/.config/i3blocks/config b/i3blocks/.config/i3blocks/config
new file mode 100644
index 0000000..e3b3095
--- /dev/null
+++ b/i3blocks/.config/i3blocks/config
@@ -0,0 +1,19 @@
+separator_block_width=15
+markup=pango
+
+[i3blocks-title]
+# command=~/.local/bin/i3blocks-title
+max_length=30
+interval=persist
+
+[weather]
+command=curl wttr.in/?m\&format="%c+%t\n" | sed 's/\s\++\(.*\)C/ \1/'
+interval=600
+
+[time]
+command=date +"%a %d/%m %T"
+interval=1
+
+[dunst]
+command=~/.local/bin/i3blocks-dunst
+interval=1
diff --git a/i3blocks/.local/bin/i3blocks-dunst b/i3blocks/.local/bin/i3blocks-dunst
new file mode 100755
index 0000000..b21042f
--- /dev/null
+++ b/i3blocks/.local/bin/i3blocks-dunst
@@ -0,0 +1,38 @@
+#!/usr/bin/env python3
+
+import os
+import subprocess
+
+
+def muted():
+ """Returns True if Dunst is muted"""
+ cmd = ["dunstctl", "is-paused"]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ output = proc.communicate()[0]
+ return "true" == output.strip().decode("UTF-8")
+
+
+def notif(t):
+ """Returns notification count"""
+ cmd = ["dunstctl", "count", t]
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE)
+ output = proc.communicate()[0]
+ return int(output.strip().decode("UTF-8"))
+
+
+button = os.environ.get("BLOCK_BUTTON", None)
+
+if button == "1":
+ subprocess.run(["dunstctl", "history-pop"], check=True)
+elif button == "3":
+ subprocess.run(["dunstctl", "set-paused", "toggle"], check=True)
+
+
+if notif("waiting") > 0:
+ print("\uf1f6")
+elif notif("displayed") > 0:
+ print("\uf0f3")
+elif muted():
+ print("\uf1f7")
+else:
+ print("\uf0a2")
diff --git a/i3blocks/.local/bin/i3blocks-title b/i3blocks/.local/bin/i3blocks-title
new file mode 100755
index 0000000..b8e3213
--- /dev/null
+++ b/i3blocks/.local/bin/i3blocks-title
@@ -0,0 +1,49 @@
+#!/usr/bin/env python3
+
+import os
+from typing import Union
+
+import i3ipc
+from i3ipc import Event
+from i3ipc.events import WindowEvent, WorkspaceEvent
+
+
+class Connection(i3ipc.Connection):
+ def handle(
+ self,
+ *events: Union[Event, str],
+ ):
+ def wrapped(handler):
+ for event in events:
+ self.on(event, handler)
+ return handler
+
+ return wrapped
+
+
+max_length = int(os.environ.get("max_length", 30))
+
+
+sway = Connection()
+
+
+@sway.handle(
+ Event.WINDOW_FOCUS,
+ Event.WINDOW_TITLE,
+ Event.WINDOW_NEW,
+ Event.WINDOW_CLOSE,
+ Event.WORKSPACE_FOCUS,
+)
+def on_window_event(sway: i3ipc.Connection, event: WindowEvent | WorkspaceEvent):
+ focused = sway.get_tree()
+ while focused is not None and focused.ipc_data["type"] != "con":
+ focused = focused.find_focused()
+
+ if focused:
+ print(focused.ipc_data["name"][:max_length])
+ else:
+ print("")
+
+
+if __name__ == "__main__":
+ sway.main()