Switched back to old workspace implementation but added support for
focusdemon parsing
This commit is contained in:
1 parent
293dff9e07
commit
56f0651875
3 files changed
+30
-106
No files matched your search
+2
-8
@@ -55,19 +55,13 @@ window.Bar {
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
||||||
|
|
||||||
&.active-focused-monitor {
|
&.active {
|
||||||
min-width: 45px; // Horizontal expansion, slightly less wide
|
min-width: 45px; // Horizontal expansion, slightly less wide
|
||||||
background-color: wal.$color2;
|
background-color: wal.$color2;
|
||||||
color: wal.$background;
|
color: wal.$background;
|
||||||
}
|
}
|
||||||
|
|
||||||
&.active-unfocused-monitor {
|
&:hover:not(.active) {
|
||||||
min-width: 45px;
|
|
||||||
background-color: rgba(wal.$color4, 0.35);
|
|
||||||
color: wal.$foreground;
|
|
||||||
}
|
|
||||||
|
|
||||||
&:hover:not(.active-focused-monitor):not(.active-unfocused-monitor) {
|
|
||||||
background-color: rgba(wal.$color2, 0.2);
|
background-color: rgba(wal.$color2, 0.2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,7 +126,9 @@ export async function setTheme(wallpaperPath: string) {
|
|||||||
// 2. Generate colors with pywal16
|
// 2. Generate colors with pywal16
|
||||||
try {
|
try {
|
||||||
// -q: quiet, -i: image, -n: skip setting wallpaper (hyprpaper does it)
|
// -q: quiet, -i: image, -n: skip setting wallpaper (hyprpaper does it)
|
||||||
await execAsync(`wal -q -n -i "${wallpaperPath}"`)
|
await execAsync(
|
||||||
|
`wal --backend modern-colorthief -q -n -i "${wallpaperPath}"`,
|
||||||
|
)
|
||||||
|
|
||||||
// Add this line so hyprlock always knows the current wallpaper:
|
// Add this line so hyprlock always knows the current wallpaper:
|
||||||
await execAsync([
|
await execAsync([
|
||||||
|
|||||||
+25
-97
@@ -1,115 +1,43 @@
|
|||||||
import { execAsync, createSubprocess } from "ags/process"
|
import { execAsync, createSubprocess } from "ags/process"
|
||||||
import GLib from "gi://GLib"
|
import GLib from "gi://GLib?version=2.0"
|
||||||
import { Gdk } from "ags/gtk4"
|
|
||||||
|
|
||||||
const HIS = GLib.getenv("HYPRLAND_INSTANCE_SIGNATURE")
|
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`
|
||||||
|
|
||||||
type WorkspaceState = {
|
export default function Workspaces() {
|
||||||
focusedMonitor: string
|
// Listen to the Hyprland socket for instant workspace updates
|
||||||
activeByMonitor: Record<string, number>
|
const activeWs = createSubprocess(
|
||||||
}
|
1,
|
||||||
|
[
|
||||||
|
"sh",
|
||||||
|
"-c",
|
||||||
|
`hyprctl activeworkspace -j | grep '"id":' | head -1 | awk '{print $2}' | tr -d ','; nc -U ${sock}`,
|
||||||
|
],
|
||||||
|
(out, prev) => {
|
||||||
|
// Multi-monitor focus changes emit focusedmon without workspace events.
|
||||||
|
const focusedMonMatch = out.match(/(?:^|\n)focusedmon>>[^,\n]+,(\d+)/)
|
||||||
|
if (focusedMonMatch) return parseInt(focusedMonMatch[1])
|
||||||
|
|
||||||
const INITIAL_STATE: WorkspaceState = {
|
const match = out.match(/(?:^|\n)workspace>>(\d+)/)
|
||||||
focusedMonitor: "",
|
if (match) return parseInt(match[1])
|
||||||
activeByMonitor: {},
|
|
||||||
}
|
|
||||||
|
|
||||||
function parseMonitors(json: string): WorkspaceState {
|
const matchV2 = out.match(/(?:^|\n)workspacev2>>(\d+),/)
|
||||||
try {
|
if (matchV2) return parseInt(matchV2[1])
|
||||||
const monitors = JSON.parse(json) as Array<{
|
|
||||||
name?: string
|
|
||||||
focused?: boolean
|
|
||||||
activeWorkspace?: { id?: number }
|
|
||||||
}>
|
|
||||||
|
|
||||||
const activeByMonitor: Record<string, number> = {}
|
const num = parseInt(out)
|
||||||
let focusedMonitor = ""
|
if (!isNaN(num) && num > 0) return num
|
||||||
|
|
||||||
for (const mon of monitors) {
|
return prev
|
||||||
const name = mon?.name ?? ""
|
},
|
||||||
const ws = Number(mon?.activeWorkspace?.id ?? 0)
|
|
||||||
|
|
||||||
if (name && ws > 0) activeByMonitor[name] = ws
|
|
||||||
if (mon?.focused && name) focusedMonitor = name
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!focusedMonitor && monitors[0]?.name) focusedMonitor = monitors[0].name
|
|
||||||
|
|
||||||
return { focusedMonitor, activeByMonitor }
|
|
||||||
} catch {
|
|
||||||
return INITIAL_STATE
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function updateState(out: string, prev: WorkspaceState): WorkspaceState {
|
|
||||||
let state: WorkspaceState = {
|
|
||||||
focusedMonitor: prev.focusedMonitor,
|
|
||||||
activeByMonitor: { ...prev.activeByMonitor },
|
|
||||||
}
|
|
||||||
|
|
||||||
// Initial/refresh snapshots injected by shell command
|
|
||||||
const monmapMatches = out.match(/__MONMAP__>>(.*)/g)
|
|
||||||
if (monmapMatches?.length) {
|
|
||||||
const latest = monmapMatches[monmapMatches.length - 1]
|
|
||||||
const payload = latest.replace("__MONMAP__>>", "")
|
|
||||||
const parsed = parseMonitors(payload)
|
|
||||||
if (Object.keys(parsed.activeByMonitor).length > 0) state = parsed
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hyprland event: focusedmon>>MONITOR,WORKSPACE_ID
|
|
||||||
const focusedMonMatches = Array.from(
|
|
||||||
out.matchAll(/(?:^|\n)focusedmon>>([^,\n]+),(\d+)/g),
|
|
||||||
)
|
|
||||||
for (const m of focusedMonMatches) {
|
|
||||||
const mon = m[1]
|
|
||||||
const ws = parseInt(m[2])
|
|
||||||
if (mon && !Number.isNaN(ws) && ws > 0) {
|
|
||||||
state.focusedMonitor = mon
|
|
||||||
state.activeByMonitor[mon] = ws
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Hyprland event: workspace>>WORKSPACE_ID
|
|
||||||
// Applies to currently focused monitor.
|
|
||||||
const workspaceMatches = Array.from(out.matchAll(/(?:^|\n)workspace>>(\d+)/g))
|
|
||||||
for (const m of workspaceMatches) {
|
|
||||||
const ws = parseInt(m[1])
|
|
||||||
if (!Number.isNaN(ws) && ws > 0 && state.focusedMonitor) {
|
|
||||||
state.activeByMonitor[state.focusedMonitor] = ws
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return state
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Workspaces({
|
|
||||||
gdkmonitor,
|
|
||||||
}: {
|
|
||||||
gdkmonitor: Gdk.Monitor
|
|
||||||
}) {
|
|
||||||
const monitorName = gdkmonitor.get_connector()
|
|
||||||
|
|
||||||
const wsState = createSubprocess(
|
|
||||||
INITIAL_STATE,
|
|
||||||
["sh", "-c", `echo "__MONMAP__>>$(hyprctl monitors -j)"; nc -U ${sock}`],
|
|
||||||
updateState,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<box cssClasses={["workspaces"]} spacing={4}>
|
<box cssClasses={["workspaces"]} spacing={4}>
|
||||||
{Array.from({ length: 9 }, (_, i) => i + 1).map((i) => (
|
{Array.from({ length: 9 }, (_, i) => i + 1).map((i) => (
|
||||||
<button
|
<button
|
||||||
cssClasses={wsState((state) => {
|
cssClasses={activeWs((active) =>
|
||||||
const isActiveOnThisMonitor =
|
active === i ? ["workspace-btn", "active"] : ["workspace-btn"],
|
||||||
monitorName != null && state.activeByMonitor[monitorName] === i
|
)}
|
||||||
if (!isActiveOnThisMonitor) return ["workspace-btn"]
|
|
||||||
|
|
||||||
const isFocusedMonitor = state.focusedMonitor === monitorName
|
|
||||||
return isFocusedMonitor
|
|
||||||
? ["workspace-btn", "active-focused-monitor"]
|
|
||||||
: ["workspace-btn", "active-unfocused-monitor"]
|
|
||||||
})}
|
|
||||||
onClicked={() => execAsync(`hyprctl dispatch workspace ${i}`)}
|
onClicked={() => execAsync(`hyprctl dispatch workspace ${i}`)}
|
||||||
>
|
>
|
||||||
<label label={`${i}`} />
|
<label label={`${i}`} />
|
||||||
|
|||||||
Reference in new issue
Block a user