event subscription implemented

This commit is contained in:
Milarin 2024-02-09 20:57:18 +01:00
parent 7a704e08fd
commit bec954ef31
2 changed files with 59 additions and 26 deletions

View File

@ -27,38 +27,38 @@ type EventType = string
const (
EventTypeTick EventType = "tick"
EventTypeActiveWindow EventType = "activeWindow"
EventTypeActiveWindowV2 EventType = "activeWindowV2"
EventTypeKeyboardFocus EventType = "keyboardFocus"
EventTypeMoveWorkspace EventType = "moveWorkspace"
EventTypeFocusedMon EventType = "focusedMon"
EventTypeMoveWindow EventType = "moveWindow"
EventTypeOpenLayer EventType = "openLayer"
EventTypeCloseLayer EventType = "closeLayer"
EventTypeOpenWindow EventType = "openWindow"
EventTypeCloseWindow EventType = "closeWindow"
EventTypeActiveWindow EventType = "activewindow"
EventTypeActiveWindowV2 EventType = "activewindowv2"
EventTypeKeyboardFocus EventType = "keyboardfocus"
EventTypeMoveWorkspace EventType = "moveworkspace"
EventTypeFocusedMon EventType = "focusedmon"
EventTypeMoveWindow EventType = "movewindow"
EventTypeOpenLayer EventType = "openlayer"
EventTypeCloseLayer EventType = "closelayer"
EventTypeOpenWindow EventType = "openwindow"
EventTypeCloseWindow EventType = "closewindow"
EventTypeUrgent EventType = "urgent"
EventTypeMinimize EventType = "minimize"
EventTypeMonitorAdded EventType = "monitorAdded"
EventTypeMonitorRemoved EventType = "monitorRemoved"
EventTypeCreateWorkspace EventType = "createWorkspace"
EventTypeDestroyWorkspace EventType = "destroyWorkspace"
EventTypeMonitorAdded EventType = "monitoradded"
EventTypeMonitorRemoved EventType = "monitorremoved"
EventTypeCreateWorkspace EventType = "createworkspace"
EventTypeDestroyWorkspace EventType = "destroyworkspace"
EventTypeFullscreen EventType = "fullscreen"
EventTypeChangeFloatingMode EventType = "changeFloatingMode"
EventTypeChangeFloatingMode EventType = "changefloatingmode"
EventTypeWorkspace EventType = "workspace"
EventTypeSubmap EventType = "submap"
EventTypeMouseMove EventType = "mouseMove"
EventTypeMouseButton EventType = "mouseButton"
EventTypeMouseAxis EventType = "mouseAxis"
EventTypeTouchDown EventType = "touchDown"
EventTypeTouchUp EventType = "touchUp"
EventTypeTouchMove EventType = "touchMove"
EventTypeActiveLayout EventType = "activeLayout"
EventTypePreRender EventType = "preRender"
EventTypeMouseMove EventType = "mousemove"
EventTypeMouseButton EventType = "mousebutton"
EventTypeMouseAxis EventType = "mouseaxis"
EventTypeTouchDown EventType = "touchdown"
EventTypeTouchUp EventType = "touchup"
EventTypeTouchMove EventType = "touchmove"
EventTypeActiveLayout EventType = "activelayout"
EventTypePreRender EventType = "prerender"
EventTypeScreencast EventType = "screencast"
EventTypeRender EventType = "render"
EventTypeWindowtitle EventType = "windowtitle"
EventTypeConfigReloaded EventType = "configReloaded"
EventTypePreConfigReload EventType = "preConfigReload"
EventTypeKeyPress EventType = "keyPress"
EventTypeConfigReloaded EventType = "configreloaded"
EventTypePreConfigReload EventType = "preconfigreload"
EventTypeKeyPress EventType = "keypress"
)

33
subscribe_event.go Normal file
View File

@ -0,0 +1,33 @@
package hypr
import (
"bufio"
"strings"
"git.milar.in/milarin/slices"
)
func (i *Instance) Subscribe(events ...EventType) (<-chan Event, error) {
r, err := readSocketRaw(i.EventSocketPath(), strings.NewReader(""))
if err != nil {
return nil, err
}
out := make(chan Event, 10)
eventMap := slices.ToStructMap(events)
go func() {
defer r.Close()
defer close(out)
sc := bufio.NewScanner(r)
for sc.Scan() {
event := parseEvent(sc.Text())
if _, ok := eventMap[event.Type]; ok {
out <- event
}
}
}()
return out, nil
}