Skip to content

Commit

Permalink
event: remove WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Aug 31, 2024
1 parent 6f039d6 commit 82603a4
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 17 deletions.
6 changes: 3 additions & 3 deletions event/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ const (
// HYPRLAND_INSTANCE_SIGNATURE for the current user.
// If you need to connect to arbitrary user instances or need a method that
// will not panic on error, use [NewEventClient] instead.
// Experimental: WIP
func MustEventClient() *EventClient {
return assert.Must1(NewEventClient(helpers.MustSocket(".socket2.sock")))
}

// Initiate a new event client.
// Receive as parameters a socket that is generally localised in
// '$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock'.
// Experimental: WIP
func NewEventClient(socket string) (*EventClient, error) {
conn, err := net.Dial("unix", socket)
if err != nil {
Expand All @@ -39,7 +37,6 @@ func NewEventClient(socket string) (*EventClient, error) {

// Low-level receive event method, should be avoided unless there is no
// alternative.
// Experimental: WIP
func (c *EventClient) Receive() ([]ReceivedData, error) {
buf := make([]byte, bufSize)
n, err := c.conn.Read(buf)
Expand Down Expand Up @@ -70,6 +67,9 @@ func (c *EventClient) Receive() ([]ReceivedData, error) {
return recv, nil
}

// Subscribe to events.
// You need to pass an implementation of [EventHandler] interface for each of
// the events you want to handle and all event types you want to handle.
func (c *EventClient) Subscribe(ev EventHandler, events ...EventType) error {
for {
msg, err := c.Receive()
Expand Down
34 changes: 20 additions & 14 deletions event/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package event
import "net"

// EventClient is the event struct from hyprland-go.
// Experimental: WIP
type EventClient struct {
conn net.Conn
}
Expand All @@ -17,40 +16,47 @@ type ReceivedData struct {
Data RawData
}

// EventHandler Hyprland will write to each connected ipc live events like this:
// EventHandler is the interface that defines all methods to handle each of
// events emitted by Hyprland.
// You can find move information about each event in the main Hyprland Wiki:
// https://wiki.hyprland.org/Plugins/Development/Event-list/.
type EventHandler interface {
// Workspace emitted on workspace change. Is emitted ONLY when a user requests a workspace change, and is not emitted on mouse movements (see activemon)
// Workspace emitted on workspace change. Is emitted ONLY when a user
// requests a workspace change, and is not emitted on mouse movements.
Workspace(w WorkspaceName)
// FocusedMonitor emitted on the active monitor being changed.
FocusedMonitor(m FocusedMonitor)
// ActiveWindow emitted on the active window being changed.
ActiveWindow(w ActiveWindow)
// Fullscreen emitted when a fullscreen status of a window changes.
Fullscreen(f bool)
// MonitorRemoved emitted when a monitor is removed (disconnected)
// MonitorRemoved emitted when a monitor is removed (disconnected).
MonitorRemoved(m MonitorName)
// MonitorAdded emitted when a monitor is added (connected)
// MonitorAdded emitted when a monitor is added (connected).
MonitorAdded(m MonitorName)
// CreateWorkspace emitted when a workspace is created
// CreateWorkspace emitted when a workspace is created.
CreateWorkspace(w WorkspaceName)
// DestroyWorkspace emitted when a workspace is destroyed
// DestroyWorkspace emitted when a workspace is destroyed.
DestroyWorkspace(w WorkspaceName)
// MoveWorkspace emitted when a workspace is moved to a different monitor
// MoveWorkspace emitted when a workspace is moved to a different
// monitor.
MoveWorkspace(w MoveWorkspace)
// ActiveLayout emitted on a layout change of the active keyboard
// ActiveLayout emitted on a layout change of the active keyboard.
ActiveLayout(l ActiveLayout)
// OpenWindow emitted when a window is opened
// OpenWindow emitted when a window is opened.
OpenWindow(o OpenWindow)
// CloseWindow emitted when a window is closed
// CloseWindow emitted when a window is closed.
CloseWindow(c CloseWindow)
// MoveWindow emitted when a window is moved to a workspace
// MoveWindow emitted when a window is moved to a workspace.
MoveWindow(m MoveWindow)
// OpenLayer emitted when a layerSurface is mapped
// OpenLayer emitted when a layerSurface is mapped.
OpenLayer(l OpenLayer)
// CloseLayer emitted when a layerSurface is unmapped
// CloseLayer emitted when a layerSurface is unmapped.
CloseLayer(c CloseLayer)
// SubMap emitted when a keybind submap changes. Empty means default.
SubMap(s SubMap)
// Screencast is fired when the screencopy state of a client changes.
// Keep in mind there might be multiple separate clients.
Screencast(s Screencast)
}

Expand Down

0 comments on commit 82603a4

Please sign in to comment.