event subscription implemented
This commit is contained in:
parent
7a704e08fd
commit
bec954ef31
@ -27,38 +27,38 @@ type EventType = string
|
|||||||
|
|
||||||
const (
|
const (
|
||||||
EventTypeTick EventType = "tick"
|
EventTypeTick EventType = "tick"
|
||||||
EventTypeActiveWindow EventType = "activeWindow"
|
EventTypeActiveWindow EventType = "activewindow"
|
||||||
EventTypeActiveWindowV2 EventType = "activeWindowV2"
|
EventTypeActiveWindowV2 EventType = "activewindowv2"
|
||||||
EventTypeKeyboardFocus EventType = "keyboardFocus"
|
EventTypeKeyboardFocus EventType = "keyboardfocus"
|
||||||
EventTypeMoveWorkspace EventType = "moveWorkspace"
|
EventTypeMoveWorkspace EventType = "moveworkspace"
|
||||||
EventTypeFocusedMon EventType = "focusedMon"
|
EventTypeFocusedMon EventType = "focusedmon"
|
||||||
EventTypeMoveWindow EventType = "moveWindow"
|
EventTypeMoveWindow EventType = "movewindow"
|
||||||
EventTypeOpenLayer EventType = "openLayer"
|
EventTypeOpenLayer EventType = "openlayer"
|
||||||
EventTypeCloseLayer EventType = "closeLayer"
|
EventTypeCloseLayer EventType = "closelayer"
|
||||||
EventTypeOpenWindow EventType = "openWindow"
|
EventTypeOpenWindow EventType = "openwindow"
|
||||||
EventTypeCloseWindow EventType = "closeWindow"
|
EventTypeCloseWindow EventType = "closewindow"
|
||||||
EventTypeUrgent EventType = "urgent"
|
EventTypeUrgent EventType = "urgent"
|
||||||
EventTypeMinimize EventType = "minimize"
|
EventTypeMinimize EventType = "minimize"
|
||||||
EventTypeMonitorAdded EventType = "monitorAdded"
|
EventTypeMonitorAdded EventType = "monitoradded"
|
||||||
EventTypeMonitorRemoved EventType = "monitorRemoved"
|
EventTypeMonitorRemoved EventType = "monitorremoved"
|
||||||
EventTypeCreateWorkspace EventType = "createWorkspace"
|
EventTypeCreateWorkspace EventType = "createworkspace"
|
||||||
EventTypeDestroyWorkspace EventType = "destroyWorkspace"
|
EventTypeDestroyWorkspace EventType = "destroyworkspace"
|
||||||
EventTypeFullscreen EventType = "fullscreen"
|
EventTypeFullscreen EventType = "fullscreen"
|
||||||
EventTypeChangeFloatingMode EventType = "changeFloatingMode"
|
EventTypeChangeFloatingMode EventType = "changefloatingmode"
|
||||||
EventTypeWorkspace EventType = "workspace"
|
EventTypeWorkspace EventType = "workspace"
|
||||||
EventTypeSubmap EventType = "submap"
|
EventTypeSubmap EventType = "submap"
|
||||||
EventTypeMouseMove EventType = "mouseMove"
|
EventTypeMouseMove EventType = "mousemove"
|
||||||
EventTypeMouseButton EventType = "mouseButton"
|
EventTypeMouseButton EventType = "mousebutton"
|
||||||
EventTypeMouseAxis EventType = "mouseAxis"
|
EventTypeMouseAxis EventType = "mouseaxis"
|
||||||
EventTypeTouchDown EventType = "touchDown"
|
EventTypeTouchDown EventType = "touchdown"
|
||||||
EventTypeTouchUp EventType = "touchUp"
|
EventTypeTouchUp EventType = "touchup"
|
||||||
EventTypeTouchMove EventType = "touchMove"
|
EventTypeTouchMove EventType = "touchmove"
|
||||||
EventTypeActiveLayout EventType = "activeLayout"
|
EventTypeActiveLayout EventType = "activelayout"
|
||||||
EventTypePreRender EventType = "preRender"
|
EventTypePreRender EventType = "prerender"
|
||||||
EventTypeScreencast EventType = "screencast"
|
EventTypeScreencast EventType = "screencast"
|
||||||
EventTypeRender EventType = "render"
|
EventTypeRender EventType = "render"
|
||||||
EventTypeWindowtitle EventType = "windowtitle"
|
EventTypeWindowtitle EventType = "windowtitle"
|
||||||
EventTypeConfigReloaded EventType = "configReloaded"
|
EventTypeConfigReloaded EventType = "configreloaded"
|
||||||
EventTypePreConfigReload EventType = "preConfigReload"
|
EventTypePreConfigReload EventType = "preconfigreload"
|
||||||
EventTypeKeyPress EventType = "keyPress"
|
EventTypeKeyPress EventType = "keypress"
|
||||||
)
|
)
|
||||||
|
33
subscribe_event.go
Normal file
33
subscribe_event.go
Normal 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
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user