Skip to content

Commit

Permalink
Merge pull request #17 from thiagokokada/simplify-event-api
Browse files Browse the repository at this point in the history
Simplify event api
  • Loading branch information
thiagokokada authored Aug 31, 2024
2 parents bf027a2 + c8d5db6 commit ecee9b0
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 47 deletions.
24 changes: 24 additions & 0 deletions event/event_default.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package event

// DefaultEventHandler is an implementation of [EventHandler] interface with
// all handlers doing nothing. It is a good starting point to be embedded your
// own struct to be extended.
type DefaultEventHandler struct{}

func (e *DefaultEventHandler) Workspace(WorkspaceName) {}
func (e *DefaultEventHandler) FocusedMonitor(FocusedMonitor) {}
func (e *DefaultEventHandler) ActiveWindow(ActiveWindow) {}
func (e *DefaultEventHandler) Fullscreen(bool) {}
func (e *DefaultEventHandler) MonitorRemoved(MonitorName) {}
func (e *DefaultEventHandler) MonitorAdded(MonitorName) {}
func (e *DefaultEventHandler) CreateWorkspace(WorkspaceName) {}
func (e *DefaultEventHandler) DestroyWorkspace(WorkspaceName) {}
func (e *DefaultEventHandler) MoveWorkspace(MoveWorkspace) {}
func (e *DefaultEventHandler) ActiveLayout(ActiveLayout) {}
func (e *DefaultEventHandler) OpenWindow(OpenWindow) {}
func (e *DefaultEventHandler) CloseWindow(CloseWindow) {}
func (e *DefaultEventHandler) MoveWindow(MoveWindow) {}
func (e *DefaultEventHandler) OpenLayer(OpenLayer) {}
func (e *DefaultEventHandler) CloseLayer(CloseLayer) {}
func (e *DefaultEventHandler) SubMap(SubMap) {}
func (e *DefaultEventHandler) Screencast(Screencast) {}
24 changes: 0 additions & 24 deletions event/event_noop.go

This file was deleted.

4 changes: 2 additions & 2 deletions event/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type FakeEventClient struct {
}

type FakeEventHandler struct {
NoopEventHandler
DefaultEventHandler
}

func (f *FakeEventClient) Receive() ([]ReceivedData, error) {
Expand Down Expand Up @@ -97,7 +97,7 @@ func (f *FakeEventClient) Receive() ([]ReceivedData, error) {
}

func TestSubscribe(t *testing.T) {
err := SubscribeWithoutLoop(*c, h, GetAllEvents()...)
err := SubscribeWithoutLoop(*c, h, AllEvents...)
if err != nil {
t.Error(err)
}
Expand Down
42 changes: 22 additions & 20 deletions event/event_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,26 +80,28 @@ const (
EventScreencast EventType = "screencast"
)

func GetAllEvents() []EventType {
return []EventType{
EventWorkspace,
EventFocusedMonitor,
EventActiveWindow,
EventFullscreen,
EventMonitorRemoved,
EventMonitorAdded,
EventCreateWorkspace,
EventDestroyWorkspace,
EventMoveWorkspace,
EventActiveLayout,
EventOpenWindow,
EventCloseWindow,
EventMoveWindow,
EventOpenLayer,
EventCloseLayer,
EventSubMap,
EventScreencast,
}
// AllEvents is the combination of all event types, useful if you want to
// subscribe to all supported events at the same time.
// Keep in mind that generally explicit declaring which events you want to
// subscribe is better, since new events will be added in future.
var AllEvents = []EventType{
EventWorkspace,
EventFocusedMonitor,
EventActiveWindow,
EventFullscreen,
EventMonitorRemoved,
EventMonitorAdded,
EventCreateWorkspace,
EventDestroyWorkspace,
EventMoveWorkspace,
EventActiveLayout,
EventOpenWindow,
EventCloseWindow,
EventMoveWindow,
EventOpenLayer,
EventCloseLayer,
EventSubMap,
EventScreencast,
}

type MoveWorkspace struct {
Expand Down
2 changes: 1 addition & 1 deletion examples/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

type ev struct {
event.NoopEventHandler
event.DefaultEventHandler
}

func (e *ev) Workspace(w event.WorkspaceName) {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
module github.com/thiagokokada/hyprland-go

retract v0.0.3 // Published too soon without proper event API consideration.

go 1.20

0 comments on commit ecee9b0

Please sign in to comment.