-
Notifications
You must be signed in to change notification settings - Fork 0
/
gnome_wayland_monitor_active_app.go
85 lines (76 loc) · 1.97 KB
/
gnome_wayland_monitor_active_app.go
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package main
import (
"bufio"
"fmt"
"log"
"os/exec"
"strings"
)
func readln(buf *bufio.Reader) string {
line, _, _ := buf.ReadLine()
return string(line)
}
func main() {
cmd := exec.Command("dbus-monitor")
stdout, err := cmd.StdoutPipe()
if err != nil {
log.Fatal(err)
}
cmd.Start()
buf := bufio.NewReader(stdout)
for {
line := readln(buf)
if strings.Contains(line, "member=RunningApplicationsChanged") {
line := readln(buf)
if strings.Contains(line, "member=GetRunningApplications") {
last_line := ""
for line := ""; !strings.Contains(line, "string \"active-on-seats\""); line = readln(buf) {
if strings.Contains(line, "string \"") {
last_line = line
}
}
if last_line != "" {
app := strings.Split(last_line, "\"")[1]
fmt.Println(app)
}
}
}
}
}
/*
Example event from dbus-monitor
$ dbus-monitor | grep 'member=RunningApplicationsChanged' -A 30
...
signal time=1653308837.299322 sender=:1.14 -> destination=(null destination) serial=629 path=/org/gnome/Shell/Introspect; interface=org.gnome.Shell.Introspect; member=RunningApplicationsChanged
method call time=1653308837.300012 sender=:1.65 -> destination=:1.14 serial=144 path=/org/gnome/Shell/Introspect; interface=org.gnome.Shell.Introspect; member=GetRunningApplications
method return time=1653308837.305183 sender=:1.14 -> destination=:1.65 serial=630 reply_serial=144
array [
dict entry(
string "org.wezfurlong.wezterm.desktop"
array [
]
)
dict entry(
string "org.thonny.Thonny.desktop"
array [
dict entry(
string "active-on-seats"
variant array [
string "seat0"
]
)
]
)
dict entry(
string "librewolf.desktop"
array [
]
)
dict entry(
string "rambox.desktop"
array [
]
)
dict entry(
...
*/