This repository was archived by the owner on Jun 19, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaction.go
More file actions
49 lines (43 loc) · 1.23 KB
/
action.go
File metadata and controls
49 lines (43 loc) · 1.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
package main
import (
"fmt"
"os/exec"
)
// Translated events from raw device events.
type event int
const (
// Click is rapid press and release.
evClick event = iota
// RotRight is unpressed clockwise rotation.
evRotRight
// RotLeft is unpressed counter-clockwise rotation.
evRotLeft
// PressedRotRight is pressed clockwise rotation.
evPressedRotRight
// PressedRotLeft is pressed counter-clockwise rotation.
evPressedRotLeft
)
// Mapping of actions to be triggered for each event.
var actions = map[event]func(){
evClick: executeFn("playerctl", "play-pause"),
evRotRight: executeFn("amixer", "-D", "pulse", "sset", "Master", "1%+"),
evRotLeft: executeFn("amixer", "-D", "pulse", "sset", "Master", "1%-"),
evPressedRotRight: executeFn("playerctl", "next"),
evPressedRotLeft: executeFn("playerctl", "previous"),
}
func trigger(e event) {
if a := actions[e]; a != nil {
a()
}
}
// executeFn returns a func() suitable for use in actions map that will execute
// the given command with arguments on each call.
func executeFn(cmd string, args ...string) func() {
return func() {
out, err := exec.Command(cmd, args...).CombinedOutput()
if err != nil {
fmt.Println(string(out))
fmt.Println(err)
}
}
}