Documentation
¶
Overview ¶
Package events handles events from Niri event-stream.
Listens to the event stream on the NIRI_SOCKET and reacts to events in a specified manner.
Index ¶
- Variables
- func ActionsFromRaw(rawActions map[string]json.RawMessage) []actions.Action
- func EvaluateCondition(condition string, model any) (bool, error)
- func EventStream() (<-chan Event, error)
- func Run()
- type ConfigLoaded
- type EName
- type Event
- type KeyboardLayoutSwitched
- type KeyboardLayoutsChanged
- type OverviewOpenedOrClosed
- type ScreenshotCaptured
- type Timestamp
- type WindowClosed
- type WindowFocusChanged
- type WindowFocusTimestampChanged
- type WindowLayoutChange
- type WindowLayoutsChanged
- type WindowOpenedOrChanged
- type WindowUrgencyChanged
- type WindowsChanged
- type WorkspaceActivated
- type WorkspaceActiveWindowChanged
- type WorkspaceUrgencyChanged
- type WorkspacesChanged
Constants ¶
This section is empty.
Variables ¶
var EventRegistry = map[string]func() Event{ "ConfigLoaded": func() Event { return &ConfigLoaded{EName: EName{Name: "ConfigLoaded"}} }, "KeyboardLayoutSwitched": func() Event { return &KeyboardLayoutSwitched{EName: EName{Name: "KeyboardLayoutSwitched"}} }, "KeyboardLayoutsChanged": func() Event { return &KeyboardLayoutsChanged{EName: EName{Name: "KeyboardLayoutsChanged"}} }, "OverviewOpenedOrClosed": func() Event { return &OverviewOpenedOrClosed{EName: EName{Name: "OverviewOpenedOrClosed"}} }, "ScreenshotCaptured": func() Event { return &ScreenshotCaptured{EName: EName{Name: "ScreenshotCaptured"}} }, "WindowClosed": func() Event { return &WindowClosed{EName: EName{Name: "WindowClosed"}} }, "WindowFocusChanged": func() Event { return &WindowFocusChanged{EName: EName{Name: "WindowFocusChanged"}} }, "WindowFocusTimestampChanged": func() Event { return &WindowFocusTimestampChanged{EName: EName{Name: "WindowFocusTimestampChanged"}} }, "WindowLayoutsChanged": func() Event { return &WindowLayoutsChanged{EName: EName{Name: "WindowLayoutsChanged"}} }, "WindowOpenedOrChanged": func() Event { return &WindowOpenedOrChanged{EName: EName{Name: "WindowOpenedOrChanged"}} }, "WindowUrgencyChanged": func() Event { return &WindowUrgencyChanged{EName: EName{Name: "WindowUrgencyChanged"}} }, "WindowsChanged": func() Event { return &WindowsChanged{EName: EName{Name: "WindowsChanged"}} }, "WorkspaceActivated": func() Event { return &WorkspaceActivated{EName: EName{Name: "WorkspaceActivated"}} }, "WorkspaceActiveWindowChanged": func() Event { return &WorkspaceActiveWindowChanged{EName: EName{Name: "WorkspaceActiveWindowChanged"}} }, "WorkspaceUrgencyChanged": func() Event { return &WorkspaceUrgencyChanged{EName: EName{Name: "WorkspaceUrgencyChanged"}} }, "WorkspacesChanged": func() Event { return &WorkspacesChanged{EName: EName{Name: "WorkspacesChanged"}} }, }
EventRegistry contains all the events Niri currently sends.
The key needs to be the event name, and it should return the correct event model, and set its EName embedded struct. If you know of a better way to handle this, please let me know.
Functions ¶
func ActionsFromRaw ¶ added in v0.5.0
func ActionsFromRaw(rawActions map[string]json.RawMessage) []actions.Action
ActionsFromRaw converts the raw actions from the config into a list of Action structs.
func EvaluateCondition ¶ added in v0.6.0
EvaluateCondition evaluates the given condition on the given model.
If the model is a "WindowUrgencyChanged" event, we know that it has a field called Urgent, so the condition could be "model.Urgent == true" to run an action only when the event urgency is set. Note: The model can be an event, action, window, workspace or any other model.
func EventStream ¶
EventStream listens on the events in Niri event-stream.
The function will use a goroutine to return the event models. Inspiration from: https://github.com/probeldev/niri-float-sticky
func Run ¶
func Run()
Run starts listening on the event stream, and handle the events.
Initially the thought was to support the "Dynamic open-float script, for Bitwarden and other windows that set title/app-id late": https://github.com/YaLTeR/niri/discussions/1599 But it doesn't stop us from handling other types of events as well.
Types ¶
type ConfigLoaded ¶ added in v0.6.1
type ConfigLoaded struct {
EName
// Failed indicates that the configuration couldn't be reloaded.
//
// This can happen e.g. when the config validation
// fails.
Failed bool `json:"failed"`
}
ConfigLoaded when the configuration was reloaded
This will always be received when connecting to the event stream, indicating the last config load attempt
type EName ¶
type EName struct {
Name string
}
EName defines the name of the event.
func (EName) GetPossibleKeys ¶ added in v0.5.0
func (e EName) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts relevant IDs and fields from any event. This is a default implementation that should work for most events.
type Event ¶
type Event interface {
GetName() string
GetPossibleKeys() models.PossibleKeys
}
Event defines the "base" interface for all the events.
NOTE: We have to use GetName, since the field is called Name.
func FromRegistry ¶
FromRegistry returns the populated model from the EventRegistry by given name.
func ParseEvent ¶
ParseEvent parses the given event into it's struct.
Returns the name, model, error. The name is the name of the event, model is the populated struct.
type KeyboardLayoutSwitched ¶
type KeyboardLayoutSwitched struct {
EName
// Idx contains the index of the newly active layout.
Idx uint8 `json:"idx"`
}
KeyboardLayoutSwitched when the keyboard layout switched.
func (KeyboardLayoutSwitched) GetPossibleKeys ¶ added in v0.5.0
func (k KeyboardLayoutSwitched) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the layout index from this event.
type KeyboardLayoutsChanged ¶
type KeyboardLayoutsChanged struct {
EName
// KeyboardLayouts contains the new keyboard layout configuration.
KeyboardLayouts models.KeyboardLayouts `json:"keyboard_layouts"`
}
KeyboardLayoutsChanged when the configured keyboard layouts have changed.
type OverviewOpenedOrClosed ¶
type OverviewOpenedOrClosed struct {
EName
// IsOpen contains the new state of the overview.
IsOpen bool `json:"is_open"`
}
OverviewOpenedOrClosed when the overview was opened or closed.
type ScreenshotCaptured ¶ added in v0.10.0
type ScreenshotCaptured struct {
EName
// Path indicates the file path where the screenshot was saved, if it was written to disk.
//
// If None, the screenshot was wither only copied to the clipboard, or the path couldn't be
// converted to a String (e.g. contained invalid UTF-8 bytes).
Path string `json:"path,omitempty"`
}
ScreenshotCaptured when a screenshot was captured.
type Timestamp ¶ added in v0.10.0
type Timestamp struct {
// Secs is the number of whole seconds.
Secs uint64 `json:"secs,omitempty"`
// Nanos is the fractional part of the timestamp in nanoseconds.
Nanos uint32 `json:"nanos,omitempty"`
}
Timestamp is a moment in time
type WindowClosed ¶
WindowClosed when a toplevel window was closed.
func (WindowClosed) GetPossibleKeys ¶ added in v0.5.0
func (w WindowClosed) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the window ID from this event.
type WindowFocusChanged ¶
type WindowFocusChanged struct {
EName
// ID the ID of the newly focused window, or omitted if no window is now focused.
ID uint64 `json:"id"`
}
WindowFocusChanged when a window focus changed.
All other windows are no longer focused.
func (WindowFocusChanged) GetPossibleKeys ¶ added in v0.5.0
func (w WindowFocusChanged) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the window ID from this event.
type WindowFocusTimestampChanged ¶ added in v0.10.0
type WindowFocusTimestampChanged struct {
EName
// Id is the window ID.
ID uint64 `json:"id"`
// FocusTimestamp is the new focus timestamp.
FocusTimestamp Timestamp `json:"focus_timestamp"`
}
WindowFocusTimestampChanged when the window focus timestamp changed.
This event is separate from WindowFocusChanged because the focus timestamp only updates after some debounce time so that quick window switching doesn't mark intermediate windows as recently focused.
func (WindowFocusTimestampChanged) GetPossibleKeys ¶ added in v0.10.0
func (w WindowFocusTimestampChanged) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the window ID from this event.
type WindowLayoutChange ¶ added in v0.8.0
type WindowLayoutChange struct {
// WindowID the window id in the layout change.
WindowID uint64
// Layout the layout of the window.
Layout models.WindowLayout
}
WindowLayoutChange represents the tuple for changes in the WindowLayoutsChanged event.
func (*WindowLayoutChange) UnmarshalJSON ¶ added in v0.8.0
func (w *WindowLayoutChange) UnmarshalJSON(data []byte) error
UnmarshalJSON custom unmarshal method to handle tuples.
type WindowLayoutsChanged ¶ added in v0.8.0
type WindowLayoutsChanged struct {
EName
// Pairs consisting of a window id and new layout information for the window.
Changes []WindowLayoutChange `json:"changes"`
}
WindowLayoutsChanged when the layout of one or more windows has changed.
type WindowOpenedOrChanged ¶
type WindowOpenedOrChanged struct {
EName
// Window contains the new or updated window.
//
// If the window is focused, all other windows are no longer focused.
Window *models.Window `json:"window"`
}
WindowOpenedOrChanged when a new toplevel window was opened, or an existing toplevel window changed.
type WindowUrgencyChanged ¶
type WindowUrgencyChanged struct {
EName
// ID the ID of the window.
ID uint64 `json:"id"`
// Urgent the new urgency state of the window.
Urgent bool `json:"urgent"`
}
WindowUrgencyChanged when a window urgency changed.
func (WindowUrgencyChanged) GetPossibleKeys ¶ added in v0.5.0
func (w WindowUrgencyChanged) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the window ID from this event.
type WindowsChanged ¶
type WindowsChanged struct {
EName
// Windows contains the new window configuration.
//
// This configuration completely replaces the previous configuration. If any windows
// are missing from here, then they were closed.
Windows []*models.Window `json:"windows"`
}
WindowsChanged when the window configuration has changed.
type WorkspaceActivated ¶
type WorkspaceActivated struct {
EName
// ID the ID of the newly active workspace.
ID uint64 `json:"id"`
// Focused tells if this workspace also became focused.
//
// If true, this is now the single focused workspace. All other workspaces are no longer
// focused, but they may remain active on their respective outputs.
Focused bool `json:"focused"`
}
WorkspaceActivated when a workspace was activated on an output.
func (WorkspaceActivated) GetPossibleKeys ¶ added in v0.5.0
func (w WorkspaceActivated) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the workspace ID from this event.
type WorkspaceActiveWindowChanged ¶
type WorkspaceActiveWindowChanged struct {
EName
// WorkspaceID the ID of the workspace on which the active window changed.
WorkspaceID uint64 `json:"workspace_id"`
// ActiveWindowID the ID of the new active window, if any.
ActiveWindowID uint64 `json:"active_window_id"`
}
WorkspaceActiveWindowChanged when an active window changed on a workspace.
func (WorkspaceActiveWindowChanged) GetPossibleKeys ¶ added in v0.5.0
func (w WorkspaceActiveWindowChanged) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the workspace and window IDs from this event.
type WorkspaceUrgencyChanged ¶
type WorkspaceUrgencyChanged struct {
EName
// ID the ID of the workspace.
ID uint64 `json:"id"`
// Urgent tells if this workspace has an urgent window.
Urgent bool `json:"urgent"`
}
WorkspaceUrgencyChanged when the workspace urgency changed.
func (WorkspaceUrgencyChanged) GetPossibleKeys ¶ added in v0.5.0
func (w WorkspaceUrgencyChanged) GetPossibleKeys() models.PossibleKeys
GetPossibleKeys extracts the workspace ID from this event.
type WorkspacesChanged ¶
type WorkspacesChanged struct {
EName
// Workspaces contains the new workspace configuration.
//
// This configuration completely replaces the previous configuration. If any workspaces
// are missing from here, then they were deleted.
Workspaces []*models.Workspace `json:"workspaces"`
}
WorkspacesChanged when the workspace configuration has changed.