-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.go
More file actions
115 lines (106 loc) · 3.03 KB
/
Copy pathconfig.go
File metadata and controls
115 lines (106 loc) · 3.03 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
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
package main
import (
"fmt"
"os"
"path/filepath"
"strings"
"gopkg.in/yaml.v3"
)
type Config struct {
Padding int32 `yaml:"padding"`
IgnoreList []string `yaml:"ignoreList"`
Hotkeys struct {
Workspace1 string `yaml:"workspace1"`
Workspace2 string `yaml:"workspace2"`
Workspace3 string `yaml:"workspace3"`
Workspace4 string `yaml:"workspace4"`
Workspace5 string `yaml:"workspace5"`
Workspace6 string `yaml:"workspace6"`
Workspace7 string `yaml:"workspace7"`
Workspace8 string `yaml:"workspace8"`
Workspace9 string `yaml:"workspace9"`
MoveTo1 string `yaml:"moveTo1"`
MoveTo2 string `yaml:"moveTo2"`
MoveTo3 string `yaml:"moveTo3"`
MoveTo4 string `yaml:"moveTo4"`
MoveTo5 string `yaml:"moveTo5"`
MoveTo6 string `yaml:"moveTo6"`
MoveTo7 string `yaml:"moveTo7"`
MoveTo8 string `yaml:"moveTo8"`
MoveTo9 string `yaml:"moveTo9"`
ResizeFull string `yaml:"resizeFull"`
ResizeHalf string `yaml:"resizeHalf"`
ResizeSmall string `yaml:"resizeSmall"`
} `yaml:"hotkeys"`
}
var currentConfig Config
func getConfigPath() string {
exePath, err := os.Executable()
if err != nil {
return "config.yaml"
}
return filepath.Join(filepath.Dir(exePath), "config.yaml")
}
func loadConfig() {
currentConfig = Config{}
// Default config
currentConfig.Padding = 15
currentConfig.IgnoreList = []string{}
currentConfig.Hotkeys.Workspace1 = "Alt+1"
currentConfig.Hotkeys.Workspace2 = "Alt+2"
currentConfig.Hotkeys.Workspace3 = "Alt+3"
currentConfig.Hotkeys.Workspace4 = "Alt+4"
currentConfig.Hotkeys.Workspace5 = "Alt+5"
currentConfig.Hotkeys.Workspace6 = "Alt+6"
currentConfig.Hotkeys.Workspace7 = "Alt+7"
currentConfig.Hotkeys.Workspace8 = "Alt+8"
currentConfig.Hotkeys.Workspace9 = "Alt+9"
currentConfig.Hotkeys.MoveTo1 = "Alt+Shift+1"
currentConfig.Hotkeys.MoveTo2 = "Alt+Shift+2"
currentConfig.Hotkeys.MoveTo3 = "Alt+Shift+3"
currentConfig.Hotkeys.MoveTo4 = "Alt+Shift+4"
currentConfig.Hotkeys.MoveTo5 = "Alt+Shift+5"
currentConfig.Hotkeys.MoveTo6 = "Alt+Shift+6"
currentConfig.Hotkeys.MoveTo7 = "Alt+Shift+7"
currentConfig.Hotkeys.MoveTo8 = "Alt+Shift+8"
currentConfig.Hotkeys.MoveTo9 = "Alt+Shift+9"
currentConfig.Hotkeys.ResizeFull = "Alt+Q"
currentConfig.Hotkeys.ResizeHalf = "Alt+W"
currentConfig.Hotkeys.ResizeSmall = "Alt+E"
configPath := getConfigPath()
data, err := os.ReadFile(configPath)
if err == nil {
err = yaml.Unmarshal(data, ¤tConfig)
if err != nil {
fmt.Println(err)
}
} else {
out, _ := yaml.Marshal(currentConfig)
err = os.WriteFile(configPath, out, 0644)
if err != nil {
fmt.Println(err)
}
}
}
func parseHotkey(hotkeyStr string) (uintptr, uintptr) {
var modifiers uintptr
var key uintptr
parts := strings.SplitSeq(strings.ToUpper(hotkeyStr), "+")
for p := range parts {
switch p {
case "ALT":
modifiers |= MOD_ALT
case "SHIFT":
modifiers |= MOD_SHIFT
case "CTRL":
modifiers |= MOD_CONTROL
case "WIN":
modifiers |= MOD_WIN
default:
if len(p) == 1 {
key = uintptr(p[0])
}
}
}
return modifiers, key
}