Skip to content

Commit

Permalink
event: mark it as experimental
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 22, 2024
1 parent 16a7d84 commit 2431da2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 14 deletions.
9 changes: 9 additions & 0 deletions event.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,21 @@ import (

const SEPARATOR = ">>"

// Initiate a new client or panic.
// This should be the preferred method for user scripts, since it will
// automatically find the proper socket to connect and use the
// 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 must1(NewEventClient(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 @@ -25,6 +33,7 @@ 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, BUF_SIZE)
n, err := c.conn.Read(buf)
Expand Down
19 changes: 19 additions & 0 deletions event_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package hyprland

import "net"

type RawData string

type EventType string

type ReceivedData struct {
Type EventType
Data RawData
}

// EventClient is the event struct from hyprland-go.
// Experimental: WIP
type EventClient struct {
conn net.Conn
}

14 changes: 0 additions & 14 deletions types.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,6 @@ type RawRequest []byte

type RawResponse []byte

type RawData string

type EventType string

type ReceivedData struct {
Type EventType
Data RawData
}

// RequestClient is the main struct from hyprland-go.
// You may want to set 'Validate' as false to avoid (possibly costly)
// validations, at the expense of not reporting some errors in the IPC.
Expand All @@ -23,11 +14,6 @@ type RequestClient struct {
conn *net.UnixAddr
}

// EventClient is the event struct from hyprland-go.
type EventClient struct {
conn net.Conn
}

// Try to keep struct fields in the same order as the output for `hyprctl` for
// sanity.

Expand Down

0 comments on commit 2431da2

Please sign in to comment.