complete reinfra to prevent weird race scenarios
This commit is contained in:
parent
f6c5fc3c48
commit
f73bbbd0d3
4 changed files with 58 additions and 24 deletions
|
@ -1,6 +1,8 @@
|
||||||
import std/[os, strformat, strutils, streams, tables, net, sugar]
|
import std/[
|
||||||
|
os, osproc, strformat, strutils,
|
||||||
|
streams, tables, net, sugar, times
|
||||||
|
]
|
||||||
import ./[lib, swww]
|
import ./[lib, swww]
|
||||||
export tables
|
|
||||||
import yaml, jsony
|
import yaml, jsony
|
||||||
|
|
||||||
type
|
type
|
||||||
|
@ -119,20 +121,16 @@ const redrawEvents = [
|
||||||
"movewindowv2", # emitted when a window is moved to a workspace WINDOWADDRESS,WORKSPACEID,WORKSPACENAME
|
"movewindowv2", # emitted when a window is moved to a workspace WINDOWADDRESS,WORKSPACEID,WORKSPACENAME
|
||||||
]
|
]
|
||||||
|
|
||||||
proc handleHyprEvent(event: string) =
|
const monitorChangeEvents = [
|
||||||
let
|
"monitorremoved", # emitted when a monitor is removed (disconnected) MONITORNAME
|
||||||
s = event.split(">>", 1)
|
"monitoraddedv2", # emitted when a monitor is added (connected) MONITORID,MONITORNAME,MONITORDESCRIPTION
|
||||||
event = s[0]
|
]
|
||||||
|
|
||||||
if event in ["monitoraddedv2", "monitorremoved"]:
|
proc parseEvent(line: string): (string, string) =
|
||||||
# TODO: open as many bars as necessary depending on num monitors
|
let s = line.split(">>", 1)
|
||||||
notify("monitor added")
|
result = (s[0], s[1])
|
||||||
oneShotSwww()
|
|
||||||
|
|
||||||
if event in redrawEvents:
|
proc streamEwwClasses*() =
|
||||||
writeEwwClasses()
|
|
||||||
|
|
||||||
proc watchHyprland*() =
|
|
||||||
let socket = newSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)
|
let socket = newSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)
|
||||||
try:
|
try:
|
||||||
socket.connectUnix(hyprSocket2)
|
socket.connectUnix(hyprSocket2)
|
||||||
|
@ -144,4 +142,39 @@ proc watchHyprland*() =
|
||||||
while true:
|
while true:
|
||||||
var line: string
|
var line: string
|
||||||
socket.readLine line
|
socket.readLine line
|
||||||
handleHyprEvent line
|
let (e, _) = parseEvent(line)
|
||||||
|
if e in redrawEvents:
|
||||||
|
writeEwwClasses()
|
||||||
|
|
||||||
|
|
||||||
|
proc handleHyprEvent(e: string) =
|
||||||
|
if e in monitorChangeEvents:
|
||||||
|
notify("detected monitor change")
|
||||||
|
oneShotSwww()
|
||||||
|
for i in 0..<getMonitors().len:
|
||||||
|
let (output, code) = execCmdEx("eww open bar" & $i)
|
||||||
|
if code != 0:
|
||||||
|
notify("eww failed:\n" & output)
|
||||||
|
|
||||||
|
proc maybeTriggerSwww(last: var DateTime) =
|
||||||
|
const swwwTimeout = 10 # seconds
|
||||||
|
let current = now()
|
||||||
|
if (current - last).inSeconds > swwwTimeout:
|
||||||
|
oneShotSwww()
|
||||||
|
last = current
|
||||||
|
|
||||||
|
proc watchHyprland*() =
|
||||||
|
let socket = newSocket(AF_UNIX, SOCK_STREAM, IPPROTO_IP)
|
||||||
|
try:
|
||||||
|
socket.connectUnix(hyprSocket2)
|
||||||
|
except OSError:
|
||||||
|
raise newException(
|
||||||
|
HyprlandDefect, "Could not connect to Hyprland IPC UNIX path; is Hyprland running?"
|
||||||
|
)
|
||||||
|
var lastSwww= now()
|
||||||
|
while true:
|
||||||
|
var line: string
|
||||||
|
socket.readLine line
|
||||||
|
let (e, _) = parseEvent(line)
|
||||||
|
handleHyprEvent e
|
||||||
|
maybeTriggerSwww lastSwww
|
||||||
|
|
|
@ -1,12 +1,11 @@
|
||||||
## hyprman, the hyprland companion
|
## hyprman, the hyprland companion
|
||||||
|
|
||||||
import std/[os, osproc, strformat]
|
import std/[osproc, strformat]
|
||||||
import hwylterm/cligen, cligen
|
import hwylterm/cligen, cligen
|
||||||
import ./[
|
import ./[
|
||||||
hyprland,
|
hyprland,
|
||||||
lib,
|
lib,
|
||||||
mako,
|
mako,
|
||||||
swww
|
|
||||||
]
|
]
|
||||||
|
|
||||||
hwylCli(clCfg)
|
hwylCli(clCfg)
|
||||||
|
@ -19,13 +18,13 @@ proc start() =
|
||||||
if code != 0:
|
if code != 0:
|
||||||
notify(fmt"failed to open eww bar{i}")
|
notify(fmt"failed to open eww bar{i}")
|
||||||
|
|
||||||
proc watch() =
|
proc eww() =
|
||||||
## watch hyprland events for eww class changes
|
## watch hyprland events for eww class changes
|
||||||
watchHyprland()
|
streamEwwClasses()
|
||||||
|
|
||||||
proc swww() =
|
proc watch() =
|
||||||
## set swww to cycle through wallpapers
|
## handle monitor changes on hyprland
|
||||||
persistentSwww()
|
watchHyprland()
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
const
|
const
|
||||||
|
@ -38,6 +37,6 @@ when isMainModule:
|
||||||
dispatchMulti(
|
dispatchMulti(
|
||||||
[makoCmd, usage = clCfg.use, help = makoHelp, cmdName = "mako",],
|
[makoCmd, usage = clCfg.use, help = makoHelp, cmdName = "mako",],
|
||||||
[start , usage = clCfg.use],
|
[start , usage = clCfg.use],
|
||||||
|
[eww , usage = clCfg.use],
|
||||||
[watch , usage = clCfg.use],
|
[watch , usage = clCfg.use],
|
||||||
[swww , usage = clCfg.use],
|
|
||||||
)
|
)
|
||||||
|
|
|
@ -5,8 +5,9 @@ export tables
|
||||||
import yaml
|
import yaml
|
||||||
|
|
||||||
proc notify*(message: string) =
|
proc notify*(message: string) =
|
||||||
var cmd = "notify-send --app-name=hyprman --transient hyprman "
|
var cmd = "notify-send --app-name=hyprman --transient hyprman \""
|
||||||
cmd.add message
|
cmd.add message
|
||||||
|
cmd.add "\""
|
||||||
discard execCmd(cmd)
|
discard execCmd(cmd)
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
|
@ -45,3 +45,4 @@ proc persistentSwww*() =
|
||||||
setImg(gallery.sample(), monitor)
|
setImg(gallery.sample(), monitor)
|
||||||
sleep 5 * oneMinute
|
sleep 5 * oneMinute
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue