174 lines
3.9 KiB
Go
174 lines
3.9 KiB
Go
package sway
|
|
|
|
import "encoding/json"
|
|
|
|
type EventType uint32
|
|
|
|
const (
|
|
// i3 events
|
|
EventTypeWorkspace EventType = 0x80000000 + iota
|
|
_ EventType = 0x80000000 + iota // output event not available in sway
|
|
EventTypeMode EventType = 0x80000000 + iota
|
|
EventTypeWindow EventType = 0x80000000 + iota
|
|
_ EventType = 0x80000000 + iota // TODO implement EventTypeBarConfigUpdate
|
|
EventTypeBinding EventType = 0x80000000 + iota
|
|
EventTypeShutdown EventType = 0x80000000 + iota
|
|
EventTypeTick EventType = 0x80000000 + iota
|
|
|
|
// sway-only events
|
|
EventTypeBarStateUpdate EventType = 0x80000014
|
|
EventTypeInput EventType = 0x80000015
|
|
)
|
|
|
|
var eventStringRepresentations = map[EventType]string{
|
|
EventTypeWorkspace: "workspace",
|
|
EventTypeMode: "mode",
|
|
EventTypeWindow: "window",
|
|
//EventTypeBarConfigUpdate: "barconfig_update",
|
|
EventTypeBinding: "binding",
|
|
EventTypeShutdown: "shutdown",
|
|
EventTypeTick: "tick",
|
|
EventTypeBarStateUpdate: "bar_state_update",
|
|
EventTypeInput: "input",
|
|
}
|
|
|
|
func (et EventType) String() string {
|
|
return eventStringRepresentations[et]
|
|
}
|
|
|
|
type Event interface {
|
|
Type() EventType
|
|
}
|
|
|
|
type WorkspaceEvent struct {
|
|
Change WorkspaceEventChange `json:"change"`
|
|
Current *Workspace `json:"current"`
|
|
Old *Workspace `json:"old"`
|
|
}
|
|
|
|
var _ Event = &WorkspaceEvent{}
|
|
|
|
func (e WorkspaceEvent) Type() EventType {
|
|
return EventTypeWorkspace
|
|
}
|
|
|
|
func (e WorkspaceEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type ModeEvent struct {
|
|
Change string `json:"change"`
|
|
PangoMarkup bool `json:"pango_markup"`
|
|
}
|
|
|
|
var _ Event = &ModeEvent{}
|
|
|
|
func (e ModeEvent) Type() EventType {
|
|
return EventTypeMode
|
|
}
|
|
|
|
func (e ModeEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type WindowEvent struct {
|
|
Change WindowEventChange `json:"change"`
|
|
Container *Node `json:"container"`
|
|
}
|
|
|
|
var _ Event = &WindowEvent{}
|
|
|
|
func (e WindowEvent) Type() EventType {
|
|
return EventTypeWindow
|
|
}
|
|
|
|
func (e WindowEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type BindingEvent struct {
|
|
Change string `json:"change"`
|
|
Command string `json:"command"`
|
|
EventStateMask []string `json:"event_state_mask"`
|
|
InputCode int `json:"input_code"`
|
|
Symbol string `json:"symbol"`
|
|
InputType InputType `json:"input_type"`
|
|
}
|
|
|
|
var _ Event = &BindingEvent{}
|
|
|
|
func (e BindingEvent) Type() EventType {
|
|
return EventTypeBinding
|
|
}
|
|
|
|
func (e BindingEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type ShutdownEvent struct {
|
|
Change string `json:"change"`
|
|
}
|
|
|
|
var _ Event = &ShutdownEvent{}
|
|
|
|
func (e ShutdownEvent) Type() EventType {
|
|
return EventTypeShutdown
|
|
}
|
|
|
|
func (e ShutdownEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type TickEvent struct {
|
|
First bool `json:"first"`
|
|
Payload string `json:"payload"`
|
|
}
|
|
|
|
var _ Event = &TickEvent{}
|
|
|
|
func (e TickEvent) Type() EventType {
|
|
return EventTypeTick
|
|
}
|
|
|
|
func (e TickEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type BarStateUpdateEvent struct {
|
|
ID string `json:"id"`
|
|
VisibleByModifier bool `json:"visible_by_modifier"`
|
|
}
|
|
|
|
var _ Event = &BarStateUpdateEvent{}
|
|
|
|
func (e BarStateUpdateEvent) Type() EventType {
|
|
return EventTypeBarStateUpdate
|
|
}
|
|
|
|
func (e BarStateUpdateEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|
|
|
|
type InputEvent struct {
|
|
Change InputEventChange `json:"change"`
|
|
//Input Input `json:"input"` // TODO implement
|
|
}
|
|
|
|
var _ Event = &InputEvent{}
|
|
|
|
func (e InputEvent) Type() EventType {
|
|
return EventTypeInput
|
|
}
|
|
|
|
func (e InputEvent) String() string {
|
|
data, _ := json.MarshalIndent(e, "", "\t")
|
|
return string(data)
|
|
}
|