mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-04-11 08:12:09 -04:00
miraclewm: add support for Miracle WM
This commit is contained in:
@@ -97,6 +97,11 @@ func initializeProviders() {
|
||||
log.Warnf("Failed to register Scroll provider: %v", err)
|
||||
}
|
||||
|
||||
miracleProvider := providers.NewMiracleProvider("$HOME/.config/miracle-wm")
|
||||
if err := registry.Register(miracleProvider); err != nil {
|
||||
log.Warnf("Failed to register Miracle WM provider: %v", err)
|
||||
}
|
||||
|
||||
swayProvider := providers.NewSwayProvider("$HOME/.config/sway")
|
||||
if err := registry.Register(swayProvider); err != nil {
|
||||
log.Warnf("Failed to register Sway provider: %v", err)
|
||||
@@ -144,6 +149,8 @@ func makeProviderWithPath(name, path string) keybinds.Provider {
|
||||
return providers.NewSwayProvider(path)
|
||||
case "scroll":
|
||||
return providers.NewSwayProvider(path)
|
||||
case "miracle":
|
||||
return providers.NewMiracleProvider(path)
|
||||
case "niri":
|
||||
return providers.NewNiriProvider(path)
|
||||
default:
|
||||
|
||||
10
core/go.mod
10
core/go.mod
@@ -19,7 +19,7 @@ require (
|
||||
github.com/yuin/goldmark v1.7.16
|
||||
github.com/yuin/goldmark-highlighting/v2 v2.0.0-20230729083705-37449abec8cc
|
||||
go.etcd.io/bbolt v1.4.3
|
||||
golang.org/x/exp v0.0.0-20260211191109-2735e65f0518
|
||||
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a
|
||||
golang.org/x/image v0.36.0
|
||||
)
|
||||
|
||||
@@ -27,7 +27,7 @@ require (
|
||||
github.com/Microsoft/go-winio v0.6.2 // indirect
|
||||
github.com/ProtonMail/go-crypto v1.3.0 // indirect
|
||||
github.com/clipperhouse/displaywidth v0.10.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.6.0 // indirect
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 // indirect
|
||||
github.com/cloudflare/circl v1.6.3 // indirect
|
||||
github.com/cyphar/filepath-securejoin v0.6.1 // indirect
|
||||
github.com/dlclark/regexp2 v1.11.5 // indirect
|
||||
@@ -36,7 +36,7 @@ require (
|
||||
github.com/go-git/go-billy/v6 v6.0.0-20260209124918-37866f83c2d3 // indirect
|
||||
github.com/go-logfmt/logfmt v0.6.1 // indirect
|
||||
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
|
||||
github.com/kevinburke/ssh_config v1.4.0 // indirect
|
||||
github.com/kevinburke/ssh_config v1.6.0 // indirect
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
|
||||
github.com/pjbgf/sha1cd v0.5.0 // indirect
|
||||
github.com/sergi/go-diff v1.4.0 // indirect
|
||||
@@ -55,7 +55,7 @@ require (
|
||||
github.com/charmbracelet/x/term v0.2.2 // indirect
|
||||
github.com/davecgh/go-spew v1.1.1 // indirect
|
||||
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
|
||||
github.com/go-git/go-git/v6 v6.0.0-20260210102253-e4d10f0e569a
|
||||
github.com/go-git/go-git/v6 v6.0.0-20260216160506-e6a3f881772f
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.3.0
|
||||
github.com/mattn/go-isatty v0.0.20 // indirect
|
||||
@@ -71,7 +71,7 @@ require (
|
||||
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
|
||||
golang.org/x/sys v0.41.0
|
||||
golang.org/x/text v0.34.0
|
||||
gopkg.in/yaml.v3 v3.0.1 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.1
|
||||
)
|
||||
|
||||
// v0.0.1 tag is missing a LICENSE file; master has it.
|
||||
|
||||
16
core/go.sum
16
core/go.sum
@@ -40,8 +40,8 @@ github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSg
|
||||
github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI=
|
||||
github.com/clipperhouse/displaywidth v0.10.0 h1:GhBG8WuerxjFQQYeuZAeVTuyxuX+UraiZGD4HJQ3Y8g=
|
||||
github.com/clipperhouse/displaywidth v0.10.0/go.mod h1:XqJajYsaiEwkxOj4bowCTMcT1SgvHo9flfF3jQasdbs=
|
||||
github.com/clipperhouse/uax29/v2 v2.6.0 h1:z0cDbUV+aPASdFb2/ndFnS9ts/WNXgTNNGFoKXuhpos=
|
||||
github.com/clipperhouse/uax29/v2 v2.6.0/go.mod h1:Wn1g7MK6OoeDT0vL+Q0SQLDz/KpfsVRgg6W7ihQeh4g=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk=
|
||||
github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJSwu5BF98AuoVM=
|
||||
github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8=
|
||||
github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g=
|
||||
@@ -68,8 +68,8 @@ github.com/go-git/go-billy/v6 v6.0.0-20260209124918-37866f83c2d3 h1:UU7oARtwQ5g8
|
||||
github.com/go-git/go-billy/v6 v6.0.0-20260209124918-37866f83c2d3/go.mod h1:ZW9JC5gionMP1kv5uiaOaV23q0FFmNrVOV8VW+y/acc=
|
||||
github.com/go-git/go-git-fixtures/v5 v5.1.2-0.20260122163445-0622d7459a67 h1:3hutPZF+/FBjR/9MdsLJ7e1mlt9pwHgwxMW7CrbmWII=
|
||||
github.com/go-git/go-git-fixtures/v5 v5.1.2-0.20260122163445-0622d7459a67/go.mod h1:xKt0pNHST9tYHvbiLxSY27CQWFwgIxBJuDrOE0JvbZw=
|
||||
github.com/go-git/go-git/v6 v6.0.0-20260210102253-e4d10f0e569a h1:LLju0NuXQqR4WmGl1Dm86b9ZXsvXgLYbx/aaAjdQr6w=
|
||||
github.com/go-git/go-git/v6 v6.0.0-20260210102253-e4d10f0e569a/go.mod h1:IdXOePSwsMKGpuAbpczsm+f0Uy5fdHHjwgDPOymKA78=
|
||||
github.com/go-git/go-git/v6 v6.0.0-20260216160506-e6a3f881772f h1:TBkCJv9YwPOuXq1OG0r01bcxRrvs15Hp/DtZuPt4H6s=
|
||||
github.com/go-git/go-git/v6 v6.0.0-20260216160506-e6a3f881772f/go.mod h1:B88nWzfnhTlIikoJ4d84Nc9noKS5mJoA7SgDdkt0aPU=
|
||||
github.com/go-logfmt/logfmt v0.6.1 h1:4hvbpePJKnIzH1B+8OR/JPbTx37NktoI9LE2QZBBkvE=
|
||||
github.com/go-logfmt/logfmt v0.6.1/go.mod h1:EV2pOAQoZaT1ZXZbqDl5hrymndi4SY9ED9/z6CO0XAk=
|
||||
github.com/godbus/dbus/v5 v5.1.0/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
|
||||
@@ -86,8 +86,8 @@ github.com/holoplot/go-evdev v0.0.0-20250804134636-ab1d56a1fe83 h1:B+A58zGFuDrvE
|
||||
github.com/holoplot/go-evdev v0.0.0-20250804134636-ab1d56a1fe83/go.mod h1:iHAf8OIncO2gcQ8XOjS7CMJ2aPbX2Bs0wl5pZyanEqk=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
github.com/kevinburke/ssh_config v1.4.0 h1:6xxtP5bZ2E4NF5tuQulISpTO2z8XbtH8cg1PWkxoFkQ=
|
||||
github.com/kevinburke/ssh_config v1.4.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
|
||||
github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY=
|
||||
github.com/kevinburke/ssh_config v1.6.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y=
|
||||
github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0=
|
||||
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
|
||||
@@ -152,8 +152,8 @@ go.etcd.io/bbolt v1.4.3/go.mod h1:tKQlpPaYCVFctUIgFKFnAlvbmB3tpy1vkTnDWohtc0E=
|
||||
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
|
||||
golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts=
|
||||
golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos=
|
||||
golang.org/x/exp v0.0.0-20260211191109-2735e65f0518 h1:2E1CW7v5QB+Wi3N+MXllOtVR6SFmI8iJM8EdzgxrgrU=
|
||||
golang.org/x/exp v0.0.0-20260211191109-2735e65f0518/go.mod h1:K79w1Vqn7PoiZn+TkNpx3BUWUQksGO3JcVX6qIjytmA=
|
||||
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a h1:ovFr6Z0MNmU7nH8VaX5xqw+05ST2uO1exVfZPVqRC5o=
|
||||
golang.org/x/exp v0.0.0-20260212183809-81e46e3db34a/go.mod h1:K79w1Vqn7PoiZn+TkNpx3BUWUQksGO3JcVX6qIjytmA=
|
||||
golang.org/x/image v0.36.0 h1:Iknbfm1afbgtwPTmHnS2gTM/6PPZfH+z2EFuOkSbqwc=
|
||||
golang.org/x/image v0.36.0/go.mod h1:YsWD2TyyGKiIX1kZlu9QfKIsQ4nAAK9bdgdrIsE7xy4=
|
||||
golang.org/x/net v0.50.0 h1:ucWh9eiCGyDR3vtzso0WMQinm2Dnt8cFMuQa9K33J60=
|
||||
|
||||
97
core/internal/keybinds/providers/miracle.go
Normal file
97
core/internal/keybinds/providers/miracle.go
Normal file
@@ -0,0 +1,97 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/keybinds"
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/utils"
|
||||
)
|
||||
|
||||
type MiracleProvider struct {
|
||||
configPath string
|
||||
}
|
||||
|
||||
func NewMiracleProvider(configPath string) *MiracleProvider {
|
||||
if configPath == "" {
|
||||
configDir, err := os.UserConfigDir()
|
||||
if err == nil {
|
||||
configPath = filepath.Join(configDir, "miracle-wm")
|
||||
} else {
|
||||
configPath = "$HOME/.config/miracle-wm"
|
||||
}
|
||||
}
|
||||
return &MiracleProvider{configPath: configPath}
|
||||
}
|
||||
|
||||
func (m *MiracleProvider) Name() string {
|
||||
return "miracle"
|
||||
}
|
||||
|
||||
func (m *MiracleProvider) GetCheatSheet() (*keybinds.CheatSheet, error) {
|
||||
config, err := ParseMiracleConfig(m.configPath)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse miracle-wm config: %w", err)
|
||||
}
|
||||
|
||||
bindings := MiracleConfigToBindings(config)
|
||||
categorizedBinds := make(map[string][]keybinds.Keybind)
|
||||
|
||||
for _, kb := range bindings {
|
||||
category := m.categorizeAction(kb.Action)
|
||||
bind := keybinds.Keybind{
|
||||
Key: m.formatKey(kb),
|
||||
Description: kb.Comment,
|
||||
Action: kb.Action,
|
||||
}
|
||||
categorizedBinds[category] = append(categorizedBinds[category], bind)
|
||||
}
|
||||
|
||||
return &keybinds.CheatSheet{
|
||||
Title: "Miracle WM Keybinds",
|
||||
Provider: m.Name(),
|
||||
Binds: categorizedBinds,
|
||||
}, nil
|
||||
}
|
||||
|
||||
func (m *MiracleProvider) GetOverridePath() string {
|
||||
expanded, err := utils.ExpandPath(m.configPath)
|
||||
if err != nil {
|
||||
return filepath.Join(m.configPath, "config.yaml")
|
||||
}
|
||||
return filepath.Join(expanded, "config.yaml")
|
||||
}
|
||||
|
||||
func (m *MiracleProvider) formatKey(kb MiracleKeyBinding) string {
|
||||
parts := make([]string, 0, len(kb.Mods)+1)
|
||||
parts = append(parts, kb.Mods...)
|
||||
parts = append(parts, kb.Key)
|
||||
return strings.Join(parts, "+")
|
||||
}
|
||||
|
||||
func (m *MiracleProvider) categorizeAction(action string) string {
|
||||
switch {
|
||||
case strings.HasPrefix(action, "select_workspace_") || strings.HasPrefix(action, "move_to_workspace_"):
|
||||
return "Workspace"
|
||||
case strings.Contains(action, "select_") || strings.Contains(action, "move_"):
|
||||
return "Window"
|
||||
case action == "toggle_resize" || strings.HasPrefix(action, "resize_"):
|
||||
return "Window"
|
||||
case action == "fullscreen" || action == "toggle_floating" || action == "quit_active_window" || action == "toggle_pinned_to_workspace":
|
||||
return "Window"
|
||||
case action == "toggle_tabbing" || action == "toggle_stacking" || action == "request_vertical" || action == "request_horizontal":
|
||||
return "Layout"
|
||||
case action == "quit_compositor":
|
||||
return "System"
|
||||
case action == "terminal":
|
||||
return "Execute"
|
||||
case strings.HasPrefix(action, "magnifier_"):
|
||||
return "Accessibility"
|
||||
case strings.HasPrefix(action, "dms ") || strings.Contains(action, "dms ipc"):
|
||||
return "Execute"
|
||||
default:
|
||||
return "Execute"
|
||||
}
|
||||
}
|
||||
320
core/internal/keybinds/providers/miracle_parser.go
Normal file
320
core/internal/keybinds/providers/miracle_parser.go
Normal file
@@ -0,0 +1,320 @@
|
||||
package providers
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/AvengeMedia/DankMaterialShell/core/internal/utils"
|
||||
"gopkg.in/yaml.v3"
|
||||
)
|
||||
|
||||
type MiracleConfig struct {
|
||||
Terminal string `yaml:"terminal"`
|
||||
ActionKey string `yaml:"action_key"`
|
||||
DefaultActionOverrides []MiracleActionOverride `yaml:"default_action_overrides"`
|
||||
CustomActions []MiracleCustomAction `yaml:"custom_actions"`
|
||||
}
|
||||
|
||||
type MiracleActionOverride struct {
|
||||
Name string `yaml:"name"`
|
||||
Action string `yaml:"action"`
|
||||
Modifiers []string `yaml:"modifiers"`
|
||||
Key string `yaml:"key"`
|
||||
}
|
||||
|
||||
type MiracleCustomAction struct {
|
||||
Command string `yaml:"command"`
|
||||
Action string `yaml:"action"`
|
||||
Modifiers []string `yaml:"modifiers"`
|
||||
Key string `yaml:"key"`
|
||||
}
|
||||
|
||||
type MiracleKeyBinding struct {
|
||||
Mods []string
|
||||
Key string
|
||||
Action string
|
||||
Comment string
|
||||
}
|
||||
|
||||
var miracleDefaultBinds = []MiracleKeyBinding{
|
||||
{Mods: []string{"Super"}, Key: "Return", Action: "terminal", Comment: "Open terminal"},
|
||||
{Mods: []string{"Super"}, Key: "v", Action: "request_vertical", Comment: "Layout windows vertically"},
|
||||
{Mods: []string{"Super"}, Key: "h", Action: "request_horizontal", Comment: "Layout windows horizontally"},
|
||||
{Mods: []string{"Super"}, Key: "Up", Action: "select_up", Comment: "Select window above"},
|
||||
{Mods: []string{"Super"}, Key: "Down", Action: "select_down", Comment: "Select window below"},
|
||||
{Mods: []string{"Super"}, Key: "Left", Action: "select_left", Comment: "Select window left"},
|
||||
{Mods: []string{"Super"}, Key: "Right", Action: "select_right", Comment: "Select window right"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "Up", Action: "move_up", Comment: "Move window up"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "Down", Action: "move_down", Comment: "Move window down"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "Left", Action: "move_left", Comment: "Move window left"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "Right", Action: "move_right", Comment: "Move window right"},
|
||||
{Mods: []string{"Super"}, Key: "r", Action: "toggle_resize", Comment: "Toggle resize mode"},
|
||||
{Mods: []string{"Super"}, Key: "f", Action: "fullscreen", Comment: "Toggle fullscreen"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "q", Action: "quit_active_window", Comment: "Close window"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "e", Action: "quit_compositor", Comment: "Exit compositor"},
|
||||
{Mods: []string{"Super"}, Key: "Space", Action: "toggle_floating", Comment: "Toggle floating"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "p", Action: "toggle_pinned_to_workspace", Comment: "Toggle pinned to workspace"},
|
||||
{Mods: []string{"Super"}, Key: "w", Action: "toggle_tabbing", Comment: "Toggle tabbing layout"},
|
||||
{Mods: []string{"Super"}, Key: "s", Action: "toggle_stacking", Comment: "Toggle stacking layout"},
|
||||
{Mods: []string{"Super"}, Key: "1", Action: "select_workspace_0", Comment: "Workspace 1"},
|
||||
{Mods: []string{"Super"}, Key: "2", Action: "select_workspace_1", Comment: "Workspace 2"},
|
||||
{Mods: []string{"Super"}, Key: "3", Action: "select_workspace_2", Comment: "Workspace 3"},
|
||||
{Mods: []string{"Super"}, Key: "4", Action: "select_workspace_3", Comment: "Workspace 4"},
|
||||
{Mods: []string{"Super"}, Key: "5", Action: "select_workspace_4", Comment: "Workspace 5"},
|
||||
{Mods: []string{"Super"}, Key: "6", Action: "select_workspace_5", Comment: "Workspace 6"},
|
||||
{Mods: []string{"Super"}, Key: "7", Action: "select_workspace_6", Comment: "Workspace 7"},
|
||||
{Mods: []string{"Super"}, Key: "8", Action: "select_workspace_7", Comment: "Workspace 8"},
|
||||
{Mods: []string{"Super"}, Key: "9", Action: "select_workspace_8", Comment: "Workspace 9"},
|
||||
{Mods: []string{"Super"}, Key: "0", Action: "select_workspace_9", Comment: "Workspace 10"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "1", Action: "move_to_workspace_0", Comment: "Move to workspace 1"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "2", Action: "move_to_workspace_1", Comment: "Move to workspace 2"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "3", Action: "move_to_workspace_2", Comment: "Move to workspace 3"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "4", Action: "move_to_workspace_3", Comment: "Move to workspace 4"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "5", Action: "move_to_workspace_4", Comment: "Move to workspace 5"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "6", Action: "move_to_workspace_5", Comment: "Move to workspace 6"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "7", Action: "move_to_workspace_6", Comment: "Move to workspace 7"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "8", Action: "move_to_workspace_7", Comment: "Move to workspace 8"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "9", Action: "move_to_workspace_8", Comment: "Move to workspace 9"},
|
||||
{Mods: []string{"Super", "Shift"}, Key: "0", Action: "move_to_workspace_9", Comment: "Move to workspace 10"},
|
||||
}
|
||||
|
||||
func ParseMiracleConfig(configPath string) (*MiracleConfig, error) {
|
||||
expanded, err := utils.ExpandPath(configPath)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
info, err := os.Stat(expanded)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var configFile string
|
||||
if info.IsDir() {
|
||||
configFile = filepath.Join(expanded, "config.yaml")
|
||||
} else {
|
||||
configFile = expanded
|
||||
}
|
||||
|
||||
data, err := os.ReadFile(configFile)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var config MiracleConfig
|
||||
if err := yaml.Unmarshal(data, &config); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if config.ActionKey == "" {
|
||||
config.ActionKey = "meta"
|
||||
}
|
||||
|
||||
return &config, nil
|
||||
}
|
||||
|
||||
func resolveMiracleModifier(mod, actionKey string) string {
|
||||
switch mod {
|
||||
case "primary":
|
||||
return resolveActionKey(actionKey)
|
||||
case "alt", "alt_left", "alt_right":
|
||||
return "Alt"
|
||||
case "shift", "shift_left", "shift_right":
|
||||
return "Shift"
|
||||
case "ctrl", "ctrl_left", "ctrl_right":
|
||||
return "Ctrl"
|
||||
case "meta", "meta_left", "meta_right":
|
||||
return "Super"
|
||||
default:
|
||||
return mod
|
||||
}
|
||||
}
|
||||
|
||||
func resolveActionKey(actionKey string) string {
|
||||
switch actionKey {
|
||||
case "meta":
|
||||
return "Super"
|
||||
case "alt":
|
||||
return "Alt"
|
||||
case "ctrl":
|
||||
return "Ctrl"
|
||||
default:
|
||||
return "Super"
|
||||
}
|
||||
}
|
||||
|
||||
func miracleKeyCodeToName(keyCode string) string {
|
||||
name := strings.TrimPrefix(keyCode, "KEY_")
|
||||
name = strings.ToLower(name)
|
||||
|
||||
switch name {
|
||||
case "enter":
|
||||
return "Return"
|
||||
case "space":
|
||||
return "Space"
|
||||
case "up":
|
||||
return "Up"
|
||||
case "down":
|
||||
return "Down"
|
||||
case "left":
|
||||
return "Left"
|
||||
case "right":
|
||||
return "Right"
|
||||
case "tab":
|
||||
return "Tab"
|
||||
case "escape", "esc":
|
||||
return "Escape"
|
||||
case "delete":
|
||||
return "Delete"
|
||||
case "backspace":
|
||||
return "BackSpace"
|
||||
case "home":
|
||||
return "Home"
|
||||
case "end":
|
||||
return "End"
|
||||
case "pageup":
|
||||
return "Page_Up"
|
||||
case "pagedown":
|
||||
return "Page_Down"
|
||||
case "print":
|
||||
return "Print"
|
||||
case "pause":
|
||||
return "Pause"
|
||||
case "volumeup":
|
||||
return "XF86AudioRaiseVolume"
|
||||
case "volumedown":
|
||||
return "XF86AudioLowerVolume"
|
||||
case "mute":
|
||||
return "XF86AudioMute"
|
||||
case "micmute":
|
||||
return "XF86AudioMicMute"
|
||||
case "brightnessup":
|
||||
return "XF86MonBrightnessUp"
|
||||
case "brightnessdown":
|
||||
return "XF86MonBrightnessDown"
|
||||
case "kbdillumup":
|
||||
return "XF86KbdBrightnessUp"
|
||||
case "kbdillumdown":
|
||||
return "XF86KbdBrightnessDown"
|
||||
case "comma":
|
||||
return "comma"
|
||||
case "minus":
|
||||
return "minus"
|
||||
case "equal":
|
||||
return "equal"
|
||||
}
|
||||
|
||||
if len(name) == 1 {
|
||||
return name
|
||||
}
|
||||
|
||||
return name
|
||||
}
|
||||
|
||||
func MiracleConfigToBindings(config *MiracleConfig) []MiracleKeyBinding {
|
||||
overridden := make(map[string]bool)
|
||||
var bindings []MiracleKeyBinding
|
||||
|
||||
for _, override := range config.DefaultActionOverrides {
|
||||
mods := make([]string, 0, len(override.Modifiers))
|
||||
for _, mod := range override.Modifiers {
|
||||
mods = append(mods, resolveMiracleModifier(mod, config.ActionKey))
|
||||
}
|
||||
|
||||
bindings = append(bindings, MiracleKeyBinding{
|
||||
Mods: mods,
|
||||
Key: miracleKeyCodeToName(override.Key),
|
||||
Action: override.Name,
|
||||
Comment: miracleActionDescription(override.Name),
|
||||
})
|
||||
overridden[override.Name] = true
|
||||
}
|
||||
|
||||
for _, def := range miracleDefaultBinds {
|
||||
if overridden[def.Action] {
|
||||
continue
|
||||
}
|
||||
bindings = append(bindings, def)
|
||||
}
|
||||
|
||||
for _, custom := range config.CustomActions {
|
||||
mods := make([]string, 0, len(custom.Modifiers))
|
||||
for _, mod := range custom.Modifiers {
|
||||
mods = append(mods, resolveMiracleModifier(mod, config.ActionKey))
|
||||
}
|
||||
|
||||
bindings = append(bindings, MiracleKeyBinding{
|
||||
Mods: mods,
|
||||
Key: miracleKeyCodeToName(custom.Key),
|
||||
Action: custom.Command,
|
||||
Comment: custom.Command,
|
||||
})
|
||||
}
|
||||
|
||||
return bindings
|
||||
}
|
||||
|
||||
func miracleActionDescription(action string) string {
|
||||
switch action {
|
||||
case "terminal":
|
||||
return "Open terminal"
|
||||
case "request_vertical":
|
||||
return "Layout windows vertically"
|
||||
case "request_horizontal":
|
||||
return "Layout windows horizontally"
|
||||
case "select_up":
|
||||
return "Select window above"
|
||||
case "select_down":
|
||||
return "Select window below"
|
||||
case "select_left":
|
||||
return "Select window left"
|
||||
case "select_right":
|
||||
return "Select window right"
|
||||
case "move_up":
|
||||
return "Move window up"
|
||||
case "move_down":
|
||||
return "Move window down"
|
||||
case "move_left":
|
||||
return "Move window left"
|
||||
case "move_right":
|
||||
return "Move window right"
|
||||
case "toggle_resize":
|
||||
return "Toggle resize mode"
|
||||
case "fullscreen":
|
||||
return "Toggle fullscreen"
|
||||
case "quit_active_window":
|
||||
return "Close window"
|
||||
case "quit_compositor":
|
||||
return "Exit compositor"
|
||||
case "toggle_floating":
|
||||
return "Toggle floating"
|
||||
case "toggle_pinned_to_workspace":
|
||||
return "Toggle pinned to workspace"
|
||||
case "toggle_tabbing":
|
||||
return "Toggle tabbing layout"
|
||||
case "toggle_stacking":
|
||||
return "Toggle stacking layout"
|
||||
case "magnifier_on":
|
||||
return "Enable magnifier"
|
||||
case "magnifier_off":
|
||||
return "Disable magnifier"
|
||||
case "magnifier_increase_size":
|
||||
return "Increase magnifier area"
|
||||
case "magnifier_decrease_size":
|
||||
return "Decrease magnifier area"
|
||||
case "magnifier_increase_scale":
|
||||
return "Increase magnifier scale"
|
||||
case "magnifier_decrease_scale":
|
||||
return "Decrease magnifier scale"
|
||||
}
|
||||
|
||||
if num, ok := strings.CutPrefix(action, "select_workspace_"); ok {
|
||||
return "Workspace " + num
|
||||
}
|
||||
if num, ok := strings.CutPrefix(action, "move_to_workspace_"); ok {
|
||||
return "Move to workspace " + num
|
||||
}
|
||||
|
||||
return action
|
||||
}
|
||||
@@ -25,7 +25,6 @@ func NewSwayProvider(configPath string) *SwayProvider {
|
||||
configPath = "$HOME/.config/sway"
|
||||
}
|
||||
} else {
|
||||
// Determine isScroll based on the provided config path
|
||||
isScroll = strings.Contains(configPath, "scroll")
|
||||
}
|
||||
|
||||
@@ -36,16 +35,16 @@ func NewSwayProvider(configPath string) *SwayProvider {
|
||||
}
|
||||
|
||||
func (s *SwayProvider) Name() string {
|
||||
if s != nil && s.isScroll {
|
||||
return "scroll"
|
||||
}
|
||||
if s == nil {
|
||||
_, ok := os.LookupEnv("SCROLLSOCK")
|
||||
if ok {
|
||||
if os.Getenv("SCROLLSOCK") != "" {
|
||||
return "scroll"
|
||||
}
|
||||
return "sway"
|
||||
}
|
||||
|
||||
if s.isScroll {
|
||||
return "scroll"
|
||||
}
|
||||
return "sway"
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ const (
|
||||
CompositorNiri
|
||||
CompositorDWL
|
||||
CompositorScroll
|
||||
CompositorMiracle
|
||||
)
|
||||
|
||||
var detectedCompositor Compositor = -1
|
||||
@@ -34,6 +35,7 @@ func DetectCompositor() Compositor {
|
||||
niriSocket := os.Getenv("NIRI_SOCKET")
|
||||
swaySocket := os.Getenv("SWAYSOCK")
|
||||
scrollSocket := os.Getenv("SCROLLSOCK")
|
||||
miracleSocket := os.Getenv("MIRACLESOCK")
|
||||
|
||||
switch {
|
||||
case niriSocket != "":
|
||||
@@ -46,7 +48,11 @@ func DetectCompositor() Compositor {
|
||||
detectedCompositor = CompositorScroll
|
||||
return detectedCompositor
|
||||
}
|
||||
|
||||
case miracleSocket != "":
|
||||
if _, err := os.Stat(miracleSocket); err == nil {
|
||||
detectedCompositor = CompositorMiracle
|
||||
return detectedCompositor
|
||||
}
|
||||
case swaySocket != "":
|
||||
if _, err := os.Stat(swaySocket); err == nil {
|
||||
detectedCompositor = CompositorSway
|
||||
@@ -260,6 +266,25 @@ func getScrollFocusedMonitor() string {
|
||||
return ""
|
||||
}
|
||||
|
||||
func getMiracleFocusedMonitor() string {
|
||||
output, err := exec.Command("miraclemsg", "-t", "get_workspaces").Output()
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
var workspaces []swayWorkspace
|
||||
if err := json.Unmarshal(output, &workspaces); err != nil {
|
||||
return ""
|
||||
}
|
||||
|
||||
for _, ws := range workspaces {
|
||||
if ws.Focused {
|
||||
return ws.Output
|
||||
}
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
type niriWorkspace struct {
|
||||
Output string `json:"output"`
|
||||
IsFocused bool `json:"is_focused"`
|
||||
@@ -407,6 +432,8 @@ func GetFocusedMonitor() string {
|
||||
return getSwayFocusedMonitor()
|
||||
case CompositorScroll:
|
||||
return getScrollFocusedMonitor()
|
||||
case CompositorMiracle:
|
||||
return getMiracleFocusedMonitor()
|
||||
case CompositorNiri:
|
||||
return getNiriFocusedMonitor()
|
||||
case CompositorDWL:
|
||||
|
||||
Reference in New Issue
Block a user