Updated workspaces to only show active workspaces per monitor,
formatting
This commit is contained in:
1 parent
788342c846
commit
f7e43077c5
3 files changed
+112
-41
No files matched your search
+2
-2
@@ -1,7 +1,7 @@
|
||||
@use "/tmp/ags-colors.scss" as wal;
|
||||
|
||||
$fg-color: wal.$foreground;
|
||||
$bg-color: rgba(wal.$background, 1.0);
|
||||
$bg-color: rgba(wal.$background, 1);
|
||||
|
||||
$btn-height: 30px;
|
||||
$btn-radius: 8px;
|
||||
@@ -14,7 +14,7 @@ window.Bar {
|
||||
font-weight: bold;
|
||||
|
||||
> centerbox {
|
||||
background: rgba(wal.$background, 1.0);
|
||||
background: rgba(wal.$background, 1);
|
||||
border-radius: 10px;
|
||||
margin: 4px 8px;
|
||||
padding: 0 8px;
|
||||
|
||||
@@ -121,9 +121,7 @@ export async function setTheme(wallpaperPath: string) {
|
||||
// 2. Generate colors with pywal16
|
||||
try {
|
||||
// -q: quiet, -i: image, -n: skip setting wallpaper (hyprpaper does it)
|
||||
await execAsync(
|
||||
`wal --contrast 21.0 -q -n -i "${wallpaperPath}"`,
|
||||
)
|
||||
await execAsync(`wal --contrast 21.0 -q -n -i "${wallpaperPath}"`)
|
||||
|
||||
// Add this line so hyprlock always knows the current wallpaper:
|
||||
await execAsync([
|
||||
|
||||
+109
-36
@@ -1,9 +1,92 @@
|
||||
import { execAsync, createSubprocess } from "ags/process"
|
||||
import { For, createComputed } from "ags"
|
||||
import { Gdk } from "ags/gtk4"
|
||||
import { createSubprocess, execAsync } from "ags/process"
|
||||
import GLib from "gi://GLib?version=2.0"
|
||||
|
||||
interface WorkspaceInfo {
|
||||
address: string
|
||||
name: string
|
||||
monitor: string
|
||||
active: boolean
|
||||
}
|
||||
|
||||
const HIS = GLib.getenv("HYPRLAND_INSTANCE_SIGNATURE")
|
||||
const sock = `${GLib.getenv("XDG_RUNTIME_DIR")}/hypr/${HIS}/.socket2.sock`
|
||||
const SOCK = `${GLib.getenv("XDG_RUNTIME_DIR")}/hypr/${HIS}/.socket2.sock`
|
||||
|
||||
// Hyprland 0.57 omits the numeric "id" on specialWorkspace, which makes
|
||||
// AstalHyprland's monitor parsing log Json-CRITICAL errors on every workspace
|
||||
// switch. Read the IPC JSON directly instead. Only numbered workspaces are
|
||||
// shown in the bar.
|
||||
const WORKSPACES_SCRIPT = `
|
||||
SOCK="${SOCK}"
|
||||
|
||||
print_state() {
|
||||
hyprctl -j monitors | python3 -c '
|
||||
import json, subprocess, sys
|
||||
|
||||
try:
|
||||
monitors = json.load(sys.stdin)
|
||||
workspaces = json.loads(subprocess.check_output(["hyprctl", "-j", "workspaces"]))
|
||||
except Exception:
|
||||
raise SystemExit(0)
|
||||
|
||||
def ident(ws):
|
||||
return ws.get("address") or ws.get("name") or str(ws.get("id") or "")
|
||||
|
||||
seen = set()
|
||||
out = []
|
||||
|
||||
def add(ws, monitor, active):
|
||||
address = ident(ws)
|
||||
# only numbered workspaces; special and named ones are not part of the bar
|
||||
if not address.isdigit():
|
||||
return
|
||||
key = (monitor, address)
|
||||
if key in seen:
|
||||
return
|
||||
seen.add(key)
|
||||
out.append({
|
||||
"address": address,
|
||||
"name": ws.get("name") or address,
|
||||
"monitor": monitor,
|
||||
"active": active,
|
||||
})
|
||||
|
||||
for monitor in monitors:
|
||||
name = monitor.get("name") or ""
|
||||
active = monitor.get("activeWorkspace") or {}
|
||||
for ws in workspaces:
|
||||
if ws.get("monitor") == name:
|
||||
add(ws, name, ident(ws) == ident(active))
|
||||
# an active workspace always exists, even if it is empty and not listed
|
||||
add(active, name, True)
|
||||
|
||||
print(json.dumps(out))
|
||||
'
|
||||
}
|
||||
|
||||
print_state
|
||||
nc -U "$SOCK" | while IFS= read -r line; do
|
||||
case "$line" in
|
||||
workspace*|focusedmon*|createworkspace*|destroyworkspace*|moveworkspace*|renameworkspace*|changeworkspaceid*|activespecial*|monitoradded*|monitorremoved*)
|
||||
print_state
|
||||
;;
|
||||
esac
|
||||
done
|
||||
`
|
||||
|
||||
const workspaces = createSubprocess<WorkspaceInfo[]>(
|
||||
[],
|
||||
["sh", "-c", WORKSPACES_SCRIPT],
|
||||
(out, prev) => {
|
||||
try {
|
||||
const parsed = JSON.parse(out)
|
||||
return Array.isArray(parsed) ? parsed : prev
|
||||
} catch {
|
||||
return prev
|
||||
}
|
||||
},
|
||||
)
|
||||
|
||||
export default function Workspaces({
|
||||
gdkmonitor,
|
||||
@@ -12,48 +95,38 @@ export default function Workspaces({
|
||||
}) {
|
||||
const monitorName = gdkmonitor.get_connector()
|
||||
|
||||
// Listen to the Hyprland socket for instant workspace updates
|
||||
const activeWs = createSubprocess(
|
||||
1,
|
||||
[
|
||||
"sh",
|
||||
"-c",
|
||||
`
|
||||
MON="${monitorName}"
|
||||
print_ws() {
|
||||
hyprctl monitors -j | python3 -c "import json, sys; mon = sys.argv[1]; data = json.load(sys.stdin); print(next((m.get('activeWorkspace', {}).get('id', 0) for m in data if m.get('name') == mon), 0))" "$MON"
|
||||
}
|
||||
|
||||
print_ws
|
||||
nc -U ${sock} | while IFS= read -r line; do
|
||||
case "$line" in
|
||||
focusedmon*|workspace*|workspacev2*|moveworkspace*|moveworkspacev2*|createworkspace*|destroyworkspace*)
|
||||
print_ws
|
||||
;;
|
||||
esac
|
||||
done
|
||||
`,
|
||||
],
|
||||
(out, prev) => {
|
||||
const num = parseInt(out.trim())
|
||||
if (!isNaN(num) && num > 0) return num
|
||||
|
||||
return prev
|
||||
},
|
||||
const monitorWorkspaces = workspaces.as((all) =>
|
||||
all
|
||||
.filter((ws) => ws.monitor === monitorName)
|
||||
.sort((a, b) => Number(a.address) - Number(b.address)),
|
||||
)
|
||||
|
||||
return (
|
||||
<box cssClasses={["workspaces"]} spacing={4}>
|
||||
{Array.from({ length: 9 }, (_, i) => i + 1).map((i) => (
|
||||
<For each={monitorWorkspaces} id={(ws) => ws.address}>
|
||||
{(ws) => {
|
||||
// Look the workspace up by identity so the button survives state
|
||||
// updates and only its props change (keeps the active transition).
|
||||
const current = createComputed(() =>
|
||||
workspaces().find(
|
||||
(w) => w.monitor === monitorName && w.address === ws.address,
|
||||
),
|
||||
)
|
||||
|
||||
return (
|
||||
<button
|
||||
cssClasses={activeWs((active) =>
|
||||
active === i ? ["workspace-btn", "active"] : ["workspace-btn"],
|
||||
cssClasses={current.as((w) =>
|
||||
w?.active ? ["workspace-btn", "active"] : ["workspace-btn"],
|
||||
)}
|
||||
onClicked={() => execAsync(`hyprctl dispatch workspace ${i}`)}
|
||||
onClicked={() =>
|
||||
execAsync(["hyprctl", "dispatch", "workspace", ws.address])
|
||||
}
|
||||
>
|
||||
<label label={`${i}`} />
|
||||
<label label={current.as((w) => w?.name ?? ws.name)} />
|
||||
</button>
|
||||
))}
|
||||
)
|
||||
}}
|
||||
</For>
|
||||
</box>
|
||||
)
|
||||
}
|
||||
Reference in new issue
Block a user