Skip to content

Commit

Permalink
freedesktop: improve event handling
Browse files Browse the repository at this point in the history
  • Loading branch information
hattya committed Aug 21, 2024
1 parent 40c4894 commit bb24fa2
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions freedesktop/notify.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// go.notify/freedesktop :: notify.go
//
// Copyright (c) 2017-2020 Akinori Hattori <[email protected]>
// Copyright (c) 2017-2024 Akinori Hattori <[email protected]>
//
// SPDX-License-Identifier: MIT
//
Expand Down Expand Up @@ -193,6 +193,7 @@ func (c *Client) signal() {

var closed chan NotificationClosed
var invoked chan ActionInvoked
var closedIdx, invokedIdx int
closedBuf := make([]NotificationClosed, 1)
invokedBuf := make([]ActionInvoked, 1)

Expand All @@ -204,7 +205,7 @@ func (c *Client) signal() {
case notificationClosed:
if closed == nil {
closed = c.NotificationClosed
closedBuf = closedBuf[1:]
closedIdx = 1
}
closedBuf = append(closedBuf, NotificationClosed{
ID: sig.Body[0].(uint32),
Expand All @@ -213,25 +214,29 @@ func (c *Client) signal() {
case actionInvoked:
if invoked == nil {
invoked = c.ActionInvoked
invokedBuf = invokedBuf[1:]
invokedIdx = 1
}
invokedBuf = append(invokedBuf, ActionInvoked{
ID: sig.Body[0].(uint32),
Key: sig.Body[1].(string),
})
}
}
case closed <- closedBuf[0]:
if len(closedBuf) == 1 {
case closed <- closedBuf[closedIdx]:
if closedIdx == len(closedBuf)-1 {
closed = nil
closedIdx = 0
closedBuf = closedBuf[:1]
} else {
closedBuf = closedBuf[1:]
closedIdx++
}
case invoked <- invokedBuf[0]:
if len(invokedBuf) == 1 {
case invoked <- invokedBuf[invokedIdx]:
if invokedIdx == len(invokedBuf)-1 {
invoked = nil
invokedIdx = 0
invokedBuf = invokedBuf[:1]
} else {
invokedBuf = invokedBuf[1:]
invokedIdx++
}
case <-c.done:
for _, sig := range []string{notificationClosed, actionInvoked} {
Expand Down

0 comments on commit bb24fa2

Please sign in to comment.