diff --git a/go.mod b/go.mod index a736609..bfb8f8a 100644 --- a/go.mod +++ b/go.mod @@ -3,13 +3,13 @@ module github.com/diogox/bspm go 1.16 require ( - github.com/diogox/bspc-go v0.0.0-20210302164947-8846a31c3273 + github.com/diogox/bspc-go v0.0.0-20210514160037-5a5903da7ba2 github.com/fatih/color v1.10.0 github.com/golang/mock v1.4.4 - github.com/golang/protobuf v1.4.3 + github.com/golang/protobuf v1.5.2 github.com/stretchr/testify v1.7.0 github.com/urfave/cli/v2 v2.3.0 go.uber.org/zap v1.16.0 google.golang.org/grpc v1.36.0 - google.golang.org/protobuf v1.25.0 + google.golang.org/protobuf v1.26.0 ) diff --git a/go.sum b/go.sum index f79dc04..1116539 100644 --- a/go.sum +++ b/go.sum @@ -13,6 +13,12 @@ github.com/diogox/bspc-go v0.0.0-20210223003857-a374b109650b h1:Z61d3aWQYD7DyngM github.com/diogox/bspc-go v0.0.0-20210223003857-a374b109650b/go.mod h1:d4jYBJhdGS8dxKhiT6+AMbjjUE3jIr3+SfG190UUMKk= github.com/diogox/bspc-go v0.0.0-20210302164947-8846a31c3273 h1:xMT4BtYMMDaMg5y58BrondplTEia5nokyTAYH6Hul9Q= github.com/diogox/bspc-go v0.0.0-20210302164947-8846a31c3273/go.mod h1:d4jYBJhdGS8dxKhiT6+AMbjjUE3jIr3+SfG190UUMKk= +github.com/diogox/bspc-go v0.0.0-20210514150622-4991467b2a50 h1:ejzbj0HYlxFCmHQD3CtWseCNCWT3mQRsvlCZEE42zNo= +github.com/diogox/bspc-go v0.0.0-20210514150622-4991467b2a50/go.mod h1:d4jYBJhdGS8dxKhiT6+AMbjjUE3jIr3+SfG190UUMKk= +github.com/diogox/bspc-go v0.0.0-20210514151947-04e6e669773b h1:qv3BNQVYFEMm0Y3ufliZZKxnLrCGqidl2swBcFF6O7A= +github.com/diogox/bspc-go v0.0.0-20210514151947-04e6e669773b/go.mod h1:d4jYBJhdGS8dxKhiT6+AMbjjUE3jIr3+SfG190UUMKk= +github.com/diogox/bspc-go v0.0.0-20210514160037-5a5903da7ba2 h1:lQFx9jHXfA83GQLtfhmU+UAcyFRJDatvLDI+8kLmN+4= +github.com/diogox/bspc-go v0.0.0-20210514160037-5a5903da7ba2/go.mod h1:d4jYBJhdGS8dxKhiT6+AMbjjUE3jIr3+SfG190UUMKk= github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4= github.com/envoyproxy/go-control-plane v0.9.9-0.20201210154907-fd9021fe5dad/go.mod h1:cXg6YxExXjJnVBQHBLXeUAgxn2UodCpnH306RInaBQk= @@ -35,12 +41,16 @@ github.com/golang/protobuf v1.4.2 h1:+Z5KGCizgyZCbGh1KZqA0fcLLkwbsjIzS4aV2v7wJX0 github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.4.3 h1:JjCZWpVbqXDqFVmTfYWEVTMIYrL/NPdPSCHPJ0T/raM= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= +github.com/golang/protobuf v1.5.2 h1:ROPKBNFfQgOUMifHyP+KYbvpjbdoFNs+aK7DXlji0Tw= +github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M= github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.0 h1:/QaMHBdZ26BB3SSst0Iwl10Epc+xhTquomWX0oZEB6w= github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/renameio v0.1.0/go.mod h1:KWCgfxg9yswjAJkECMjeO8J8rahYeXnNhOm40UhjYkI= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= @@ -141,6 +151,9 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0 h1:Ejskq+SyPohKW+1uil0JJMtmHCgJPJ/qWTxr8qp+R4c= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= +google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= +google.golang.org/protobuf v1.26.0 h1:bxAC2xTBsZGibn2RTntX0oH50xLsqy1OxA9tTL3p/lk= +google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/feature/transparent_monocle/transparent_monocle.go b/internal/feature/transparent_monocle/transparent_monocle.go index 858fd78..792a971 100644 --- a/internal/feature/transparent_monocle/transparent_monocle.go +++ b/internal/feature/transparent_monocle/transparent_monocle.go @@ -276,6 +276,48 @@ func Start( return nil }) + service.Events().On(bspc.EventTypeNodeState, func(eventPayload interface{}) error { + payload, ok := eventPayload.(bspc.EventNodeState) + if !ok { + return errors.New("invalid event payload") + } + + if payload.State != bspc.StateTypeFloating { + // Ignore state change + return nil + } + + if _, ok := desktops.Get(payload.DesktopID); !ok { + return nil + } + + switch payload.WasEnabled { + case true: + err := handleNodeRemoved(logger, service, desktops, payload.DesktopID, payload.NodeID) + if err != nil { + logger.Error("failed to handle removing floating node", + zap.Uint("desktop_id", uint(payload.DesktopID)), + zap.Error(err), + ) + + return err + } + + case false: + err := handleNodeAdded(logger, service, desktops, payload.DesktopID, payload.NodeID) + if err != nil { + logger.Error("failed to handle adding un-floated node", + zap.Uint("desktop_id", uint(payload.DesktopID)), + zap.Error(err), + ) + + return err + } + } + + return nil + }) + cancelFunc, err := service.Events().Start() if err != nil { return nil, nil, fmt.Errorf("failed to start event manager") diff --git a/internal/feature/transparent_monocle/transparent_monocle_test.go b/internal/feature/transparent_monocle/transparent_monocle_test.go index 9388883..32a82be 100644 --- a/internal/feature/transparent_monocle/transparent_monocle_test.go +++ b/internal/feature/transparent_monocle/transparent_monocle_test.go @@ -34,7 +34,7 @@ func TestNewTransparentMonocle(t *testing.T) { mockService.EXPECT(). Events(). Return(mockEventManager). - Times(6) + Times(7) mockEventManager.EXPECT(). On(bspc.EventTypeNodeAdd, gomock.Any()) mockEventManager.EXPECT(). @@ -45,6 +45,8 @@ func TestNewTransparentMonocle(t *testing.T) { On(bspc.EventTypeNodeSwap, gomock.Any()) mockEventManager.EXPECT(). On(bspc.EventTypeDesktopFocus, gomock.Any()) + mockEventManager.EXPECT(). + On(bspc.EventTypeNodeState, gomock.Any()) mockEventManager.EXPECT(). Start(). Return(nil, nil) diff --git a/internal/grpc/bspm/bspm.pb.go b/internal/grpc/bspm/bspm.pb.go index 27500db..92b05a3 100644 --- a/internal/grpc/bspm/bspm.pb.go +++ b/internal/grpc/bspm/bspm.pb.go @@ -1,7 +1,7 @@ // Code generated by protoc-gen-go. DO NOT EDIT. // versions: -// protoc-gen-go v1.25.0 -// protoc v3.12.4 +// protoc-gen-go v1.23.0 +// protoc v3.13.0 // source: bspm.proto package bspm @@ -334,8 +334,8 @@ var file_bspm_proto_rawDesc = []byte{ 0x6f, 0x64, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x69, 0x70, 0x63, 0x2e, 0x4d, 0x6f, 0x6e, 0x6f, 0x63, 0x6c, 0x65, 0x4d, 0x6f, 0x64, 0x65, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x08, 0x5a, 0x06, 0x2e, 0x3b, 0x62, 0x73, - 0x70, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x30, 0x01, 0x42, 0x09, 0x5a, 0x07, 0x2e, 0x2f, 0x3b, 0x62, + 0x73, 0x70, 0x6d, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/internal/grpc/bspm/bspm.proto b/internal/grpc/bspm/bspm.proto index 538b264..49206c5 100644 --- a/internal/grpc/bspm/bspm.proto +++ b/internal/grpc/bspm/bspm.proto @@ -2,7 +2,7 @@ syntax = "proto3"; package ipc; -option go_package = ".;bspm"; +option go_package = "./;bspm"; import "google/protobuf/empty.proto";