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 EventStream() (<-chan any, error)
- func ParseEvent(event map[string]json.RawMessage) (string, any, error)
- func Run()
- type EName
- type Event
- type KeyboardLayoutSwitched
- type KeyboardLayoutsChanged
- type OverviewOpenedOrClosed
- type WindowClosed
- type WindowFocusChanged
- 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{ "WorkspacesChanged": func() Event { return &WorkspacesChanged{EName: EName{Name: "WorkspacesChanged"}} }, "WorkspaceUrgencyChanged": func() Event { return &WorkspaceUrgencyChanged{EName: EName{Name: "WorkspaceUrgencyChanged"}} }, "WorkspaceActivated": func() Event { return &WorkspaceActivated{EName: EName{Name: "WorkspaceActivated"}} }, "WorkspaceActiveWindowChanged": func() Event { return &WorkspaceActiveWindowChanged{EName: EName{Name: "WorkspaceActiveWindowChanged"}} }, "WindowsChanged": func() Event { return &WindowsChanged{EName: EName{Name: "WindowsChanged"}} }, "WindowOpenedOrChanged": func() Event { return &WindowOpenedOrChanged{EName: EName{Name: "WindowOpenedOrChanged"}} }, "WindowClosed": func() Event { return &WindowClosed{EName: EName{Name: "WindowClosed"}} }, "WindowFocusChanged": func() Event { return &WindowFocusChanged{EName: EName{Name: "WindowFocusChanged"}} }, "WindowUrgencyChanged": func() Event { return &WindowUrgencyChanged{EName: EName{Name: "WindowUrgencyChanged"}} }, "KeyboardLayoutsChanged": func() Event { return &KeyboardLayoutsChanged{EName: EName{Name: "KeyboardLayoutsChanged"}} }, "KeyboardLayoutSwitched": func() Event { return &KeyboardLayoutSwitched{EName: EName{Name: "KeyboardLayoutSwitched"}} }, "OverviewOpenedOrClosed": func() Event { return &OverviewOpenedOrClosed{EName: EName{Name: "OverviewOpenedOrClosed"}} }, }
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 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 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.
func Run ¶
func Run()
Run starts listening on the event stream, and handle the events.
Currently we only handle a few events, `WindowsChanged`, `WindowOpenedOrChanged` and `WindowClosed`. If you need to handle more events, add them in the switch statement. 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 Event ¶
type Event interface {
GetName() string
}
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.
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.
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 WindowClosed ¶
WindowClosed when a toplevel window was closed.
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.
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.
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.
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.
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.
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.