From 2431da2a8667abede3d5edb41be093704b19c25e Mon Sep 17 00:00:00 2001 From: Thiago Kenji Okada Date: Mon, 22 Jul 2024 23:01:12 +0100 Subject: [PATCH] event: mark it as experimental --- event.go | 9 +++++++++ event_types.go | 19 +++++++++++++++++++ types.go | 14 -------------- 3 files changed, 28 insertions(+), 14 deletions(-) create mode 100644 event_types.go diff --git a/event.go b/event.go index 608fdf7..13574c3 100644 --- a/event.go +++ b/event.go @@ -8,6 +8,13 @@ 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"))) } @@ -15,6 +22,7 @@ func MustEventClient() *EventClient { // 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 { @@ -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) diff --git a/event_types.go b/event_types.go new file mode 100644 index 0000000..9db6885 --- /dev/null +++ b/event_types.go @@ -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 +} + diff --git a/types.go b/types.go index 346c0bf..a22e77a 100644 --- a/types.go +++ b/types.go @@ -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. @@ -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.