This commit is contained in:
ElKowar 2023-12-20 14:40:44 +01:00 committed by elkowar
parent 86078f5d78
commit fd7a08f125
Signed by: ElKowar
GPG key ID: 862BA3D7D7760F13
3 changed files with 93 additions and 52 deletions

View file

@ -11,15 +11,15 @@
(bottom :screen screen)))) (bottom :screen screen))))
(defwidget top [screen] (defwidget top [screen]
(workspaces :screen screen)) (workspaces :screen {screen == 1 ? "DP-2" : "HDMI-A-1"}))
;(workspaces :wsp_yuck {screen == 1 ? workspaces_1_yuck : workspaces_2_yuck})) ;(workspaces :wsp_yuck {screen == 1 ? workspaces_1_yuck : workspaces_2_yuck}))
(defwidget workspaces [screen] (defwidget workspaces [screen]
(box :orientation "v" (box :orientation "v" :class "workspaces"
(for wsp in {workspaces[screen]} (for wsp in {workspaces[screen]}
(button :class "${wsp.occupied ? "occupied" : "empty"} ${wsp.focused ? "active" : "inactive"}" (button :class "${wsp.focused ? "active" : "inactive"}"
:onclick "swaymsg workspace ${wsp.name}" :onclick "swaymsg workspace ${wsp.name}"
{wsp.occupied ? "◆" : "◇"})))) {wsp.name}))))
;(defwidget workspaces [wsp_yuck] ;(defwidget workspaces [wsp_yuck]
@ -96,7 +96,7 @@
(defvar audio_sink "") (defvar audio_sink "")
(deflisten volume :initial "0" "./audio.sh volume") (deflisten volume :initial "0" "./audio.sh volume")
(deflisten workspaces :initial '{"0": [], "1": []}' "./swayspaces.py") (deflisten workspaces :initial '{"DP-2": [], "HDMI-A-1": []}' "./swayspaces.py")
(defpoll hour :interval "1s" "date +%H") (defpoll hour :interval "1s" "date +%H")

View file

@ -3,38 +3,26 @@
import subprocess import subprocess
import json import json
WSP_COUNT = 5
MONITOR_COUNT = 2
def get_workspaces(): def get_workspaces():
output = subprocess.check_output(["swaymsg", "-t", "get_workspaces"]) output = subprocess.check_output(["swaymsg", "-t", "get_workspaces"])
return json.loads(output.decode("utf-8")) return json.loads(output.decode("utf-8"))
def generate_workspace_data_for_monitor(monitor: int) -> list[dict]:
workspaces = {w["name"]: w for w in get_workspaces()}
data = []
for i in range(WSP_COUNT):
name = f"{monitor+1}{i+1}"
wsp_data = workspaces.get(name)
entry = {
"name": name,
"monitor": monitor,
"occupied": False,
"focused": False,
"visible": False,
}
if wsp_data is not None:
entry["focused"] = wsp_data["focused"]
entry["visible"] = wsp_data["visible"]
entry["occupied"] = True
data.append(entry)
return data
def generate_workspace_data() -> dict: def generate_workspace_data() -> dict:
return {i: generate_workspace_data_for_monitor(i) for i in range(MONITOR_COUNT)} data = {}
for wsp in get_workspaces():
if wsp["output"] not in data:
data[wsp["output"]] = []
data[wsp["output"]].append(
{
"name": wsp["name"],
"monitor": wsp["output"],
"focused": wsp["focused"],
"visible": wsp["visible"],
}
)
return data
if __name__ == "__main__": if __name__ == "__main__":
@ -50,3 +38,56 @@ if __name__ == "__main__":
line = process.stdout.readline().decode("utf-8") line = process.stdout.readline().decode("utf-8")
if line == "": if line == "":
break break
# #!/usr/bin/env python3
#
# import subprocess
# import json
#
# WSP_COUNT = 5
# MONITOR_COUNT = 2
#
#
# def get_workspaces():
# output = subprocess.check_output(["swaymsg", "-t", "get_workspaces"])
# return json.loads(output.decode("utf-8"))
#
#
# def generate_workspace_data_for_monitor(monitor: int) -> list[dict]:
# workspaces = {w["name"]: w for w in get_workspaces()}
# data = []
# for i in range(WSP_COUNT):
# name = f"{monitor+1}{i+1}"
# wsp_data = workspaces.get(name)
# entry = {
# "name": name,
# "monitor": monitor,
# "occupied": False,
# "focused": False,
# "visible": False,
# }
# if wsp_data is not None:
# entry["focused"] = wsp_data["focused"]
# entry["visible"] = wsp_data["visible"]
# entry["occupied"] = True
# data.append(entry)
# return data
#
#
# def generate_workspace_data() -> dict:
# return {i: generate_workspace_data_for_monitor(i) for i in range(MONITOR_COUNT)}
#
#
# if __name__ == "__main__":
# process = subprocess.Popen(
# ["swaymsg", "-t", "subscribe", "-m", '["workspace"]', "--raw"],
# stdout=subprocess.PIPE,
# )
# if process.stdout is None:
# print("Error: could not subscribe to sway events")
# exit(1)
# while True:
# print(json.dumps(generate_workspace_data()), flush=True)
# line = process.stdout.readline().decode("utf-8")
# if line == "":
# break

View file

@ -113,27 +113,27 @@ input "type:keyboard" {
# Workspaces: # Workspaces:
# #
# Switch to workspace # Switch to workspace
# bindsym $mod+1 workspace number 1 bindsym $mod+1 workspace number 1
# bindsym $mod+2 workspace number 2 bindsym $mod+2 workspace number 2
# bindsym $mod+3 workspace number 3 bindsym $mod+3 workspace number 3
# bindsym $mod+4 workspace number 4 bindsym $mod+4 workspace number 4
# bindsym $mod+5 workspace number 5 bindsym $mod+5 workspace number 5
# bindsym $mod+6 workspace number 6 bindsym $mod+6 workspace number 6
# bindsym $mod+7 workspace number 7 bindsym $mod+7 workspace number 7
# bindsym $mod+8 workspace number 8 bindsym $mod+8 workspace number 8
# bindsym $mod+9 workspace number 9 bindsym $mod+9 workspace number 9
# bindsym $mod+0 workspace number 10 bindsym $mod+0 workspace number 10
# # Move focused container to workspace # Move focused container to workspace
# bindsym $mod+Shift+1 move container to workspace number 1 bindsym $mod+Shift+1 move container to workspace number 1
# bindsym $mod+Shift+2 move container to workspace number 2 bindsym $mod+Shift+2 move container to workspace number 2
# bindsym $mod+Shift+3 move container to workspace number 3 bindsym $mod+Shift+3 move container to workspace number 3
# bindsym $mod+Shift+4 move container to workspace number 4 bindsym $mod+Shift+4 move container to workspace number 4
# bindsym $mod+Shift+5 move container to workspace number 5 bindsym $mod+Shift+5 move container to workspace number 5
# bindsym $mod+Shift+6 move container to workspace number 6 bindsym $mod+Shift+6 move container to workspace number 6
# bindsym $mod+Shift+7 move container to workspace number 7 bindsym $mod+Shift+7 move container to workspace number 7
# bindsym $mod+Shift+8 move container to workspace number 8 bindsym $mod+Shift+8 move container to workspace number 8
# bindsym $mod+Shift+9 move container to workspace number 9 bindsym $mod+Shift+9 move container to workspace number 9
# bindsym $mod+Shift+0 move container to workspace number 10 bindsym $mod+Shift+0 move container to workspace number 10
# Note: workspaces can have any name you want, not just numbers. # Note: workspaces can have any name you want, not just numbers.
# We just use 1-10 as the default. # We just use 1-10 as the default.
# #
@ -198,7 +198,7 @@ mode "resize" {
# } # }
# } # }
include ~/.config/sway/config.d/* # include ~/.config/sway/config.d/*
# required for flameshot # required for flameshot
exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK exec systemctl --user import-environment DISPLAY WAYLAND_DISPLAY SWAYSOCK