-
Notifications
You must be signed in to change notification settings - Fork 76
/
gnome_introspector.go
48 lines (43 loc) · 1.04 KB
/
gnome_introspector.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
package main
import (
"errors"
"github.com/godbus/dbus/v5"
)
func gnomeGetFocusWindowClass() (string, error) {
conn, err := dbus.SessionBus()
var s string
if err != nil {
return s, err
}
defer func() {
if err = conn.Hello(); err == nil {
conn.Close()
}
}()
js_code := "global.get_window_actors().find(window => !Main.overview.visible && window.meta_window.has_focus()).get_meta_window().get_wm_class()"
obj := conn.Object("org.gnome.Shell", "/org/gnome/Shell")
var ok bool
err = obj.Call("org.gnome.Shell.Eval", 0, js_code).Store(&ok, &s)
if !ok {
if isGnomeOverviewVisible(conn) {
return "org.gnome.Overview", nil
} else {
err = errors.New(s)
}
}
if err != nil {
return "", err
}
return s, nil
}
func isGnomeOverviewVisible(conn *dbus.Conn) bool {
js_code := "Main.overview.visible"
obj := conn.Object("org.gnome.Shell", "/org/gnome/Shell")
var visible string
var ok bool
err := obj.Call("org.gnome.Shell.Eval", 0, js_code).Store(&ok, &visible)
if !ok || err != nil {
return false
}
return visible == "true"
}