forked from linuxdeepin/dde-daemon
-
Notifications
You must be signed in to change notification settings - Fork 0
/
kwin_shortcut.go
57 lines (49 loc) · 1.17 KB
/
kwin_shortcut.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
package shortcuts
import (
"errors"
"github.com/linuxdeepin/go-dbus-factory/com.deepin.wm"
"pkg.deepin.io/dde/daemon/keybinding/util"
)
type kWinShortcut struct {
BaseShortcut
wm *wm.Wm
}
func newKWinShortcut(id, name string, keystrokes []string, wm *wm.Wm) *kWinShortcut {
return &kWinShortcut{
BaseShortcut: BaseShortcut{
Id: id,
Type: ShortcutTypeWM,
Name: name,
Keystrokes: ParseKeystrokes(keystrokes),
},
wm: wm,
}
}
func (ks *kWinShortcut) ReloadKeystrokes() bool {
oldVal := ks.GetKeystrokes()
keystrokes, err := ks.wm.GetAccel(0, ks.Id)
if err != nil {
logger.Warningf("failed to get accel for %s: %v", ks.Id, err)
return false
}
newVal := ParseKeystrokes(keystrokes)
ks.setKeystrokes(newVal)
return !keystrokesEqual(oldVal, newVal)
}
func (ks *kWinShortcut) SaveKeystrokes() error {
accelJson, err := util.MarshalJSON(util.KWinAccel{
Id: ks.Id,
Keystrokes: ks.getKeystrokesStrv(),
})
if err != nil {
return err
}
ok, err := ks.wm.SetAccel(0, accelJson)
if !ok {
return errors.New("wm.SetAccel failed, id: " + ks.Id)
}
return err
}
func (ks *kWinShortcut) ShouldEmitSignalChanged() bool {
return true
}