Add constants for mouse buttons
Signed-off-by: AKP <tom@tdpain.net>
This commit is contained in:
parent
04e65adead
commit
95cfbade9a
3 changed files with 36 additions and 17 deletions
|
@ -160,6 +160,8 @@ func (b *I3bar) consumerLoop(requestBarRefresh func()) {
|
|||
// delimiter."
|
||||
inputBytes = inputBytes[:len(inputBytes)-1]
|
||||
|
||||
log.Debug().Str("plainContent", string(inputBytes)).Msg("got event from window manager")
|
||||
|
||||
// try and parse inputted JSON
|
||||
event := new(ClickEvent)
|
||||
if err := json.Unmarshal(bytes.Trim(inputBytes, ","), event); err != nil {
|
||||
|
@ -207,18 +209,18 @@ type BlockGenerator interface {
|
|||
}
|
||||
|
||||
type ClickEvent struct {
|
||||
Name string `json:"name"`
|
||||
Instance string `json:"instance"`
|
||||
Button int `json:"button"`
|
||||
Modifiers []string `json:"modifiers"`
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
RelativeX int `json:"relative_x"`
|
||||
RelativeY int `json:"relative_y"`
|
||||
OutputX int `json:"output_x"`
|
||||
OutputY int `json:"output_y"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
Name string `json:"name"`
|
||||
Instance string `json:"instance"`
|
||||
Button MouseButtonType `json:"button"`
|
||||
Modifiers []string `json:"modifiers"`
|
||||
X int `json:"x"`
|
||||
Y int `json:"y"`
|
||||
RelativeX int `json:"relative_x"`
|
||||
RelativeY int `json:"relative_y"`
|
||||
OutputX int `json:"output_x"`
|
||||
OutputY int `json:"output_y"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
}
|
||||
|
||||
type ClickEventConsumer interface {
|
||||
|
@ -230,3 +232,13 @@ type ClickEventConsumer interface {
|
|||
// OnClick must not modify the ClickEvent as it may be reused elsewhere.
|
||||
OnClick(*ClickEvent) (shouldRefresh bool)
|
||||
}
|
||||
|
||||
type MouseButtonType uint8
|
||||
|
||||
const (
|
||||
LeftMouseButton MouseButtonType = iota + 1
|
||||
MiddleMouseButton
|
||||
RightMouseButton
|
||||
MouseWheelScrollUp
|
||||
MouseWheelScrollDown
|
||||
)
|
||||
|
|
|
@ -133,8 +133,11 @@ func (g *AudioPlayer) GetNameAndInstance() (string, string) {
|
|||
return g.name, ""
|
||||
}
|
||||
|
||||
func (g *AudioPlayer) OnClick(*i3bar.ClickEvent) bool {
|
||||
func (g *AudioPlayer) OnClick(event *i3bar.ClickEvent) bool {
|
||||
if event.Button != i3bar.LeftMouseButton {
|
||||
return false
|
||||
}
|
||||
_, _ = runCommand(playerctlExecutable, "play-pause")
|
||||
time.Sleep(time.Millisecond * 500)
|
||||
time.Sleep(time.Millisecond * 50)
|
||||
return true
|
||||
}
|
|
@ -29,16 +29,20 @@ func NewTimer(useShortLabel bool) i3bar.BlockGenerator {
|
|||
}
|
||||
|
||||
func (g *Timer) OnClick(event *i3bar.ClickEvent) bool {
|
||||
resetButtonPressed := event.Button == 3
|
||||
resetButtonPressed := event.Button == i3bar.RightMouseButton
|
||||
triggerButtonPressed := event.Button == i3bar.LeftMouseButton
|
||||
|
||||
numStoredTimes := len(g.times)
|
||||
|
||||
if numStoredTimes == 0 {
|
||||
// start
|
||||
// start only if the left mouse button pressed
|
||||
if !triggerButtonPressed {
|
||||
return false
|
||||
}
|
||||
g.times = []time.Time{time.Now()}
|
||||
} else if resetButtonPressed {
|
||||
g.times = nil
|
||||
} else {
|
||||
} else if triggerButtonPressed {
|
||||
// play/pause
|
||||
g.times = append(g.times, time.Now())
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue