Skip to content

Commit ab64066

Browse files
committed
refactor: remove layout maps from all switchers
- Remove layoutMap field from WindowsLayoutSwitcher and LinuxLayoutSwitcher - Remove getDefaultWindowsLayoutMap() and getDefaultLayoutMap() - Remove AddLayoutMapping() methods - Simplify getKLID() and getSetxkbmapIdentifier() to use SystemIdentifier only - All layout information now comes from memory repository - Switchers only responsible for switching, not managing layout data
1 parent c24f6c2 commit ab64066

File tree

2 files changed

+10
-97
lines changed

2 files changed

+10
-97
lines changed

internal/adapters/layouts/linux_layout_switcher.go

Lines changed: 5 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,11 @@ import (
1010
)
1111

1212
// LinuxLayoutSwitcher switches keyboard layouts on Linux using setxkbmap
13-
type LinuxLayoutSwitcher struct {
14-
// Map of layout names to setxkbmap identifiers
15-
layoutMap map[string]string
16-
}
13+
type LinuxLayoutSwitcher struct{}
1714

1815
// NewLinuxLayoutSwitcher creates a new Linux layout switcher
1916
func NewLinuxLayoutSwitcher() *LinuxLayoutSwitcher {
20-
return &LinuxLayoutSwitcher{
21-
layoutMap: getDefaultLayoutMap(),
22-
}
23-
}
24-
25-
// getDefaultLayoutMap returns a map of layout names to setxkbmap identifiers
26-
func getDefaultLayoutMap() map[string]string {
27-
return map[string]string{
28-
// US layouts
29-
domain.LayoutUSQwerty: "us",
30-
domain.LayoutUSInternational: "us -variant intl",
31-
domain.LayoutUSInternationalDeadKeys: "us -variant altgr-intl",
32-
33-
// French layouts
34-
domain.LayoutFrenchAzerty: "fr",
35-
36-
// UK layouts
37-
domain.LayoutUKQwerty: "gb",
38-
39-
// Alternative layouts
40-
domain.LayoutColemak: "us -variant colemak",
41-
domain.LayoutDvorak: "us -variant dvorak",
42-
43-
// Other languages
44-
domain.LayoutGerman: "de",
45-
domain.LayoutSpanish: "es",
46-
domain.LayoutItalian: "it",
47-
domain.LayoutPortuguese: "pt",
48-
domain.LayoutRussian: "ru",
49-
domain.LayoutJapanese: "jp",
50-
}
17+
return &LinuxLayoutSwitcher{}
5118
}
5219

5320
// SwitchLayout changes the system keyboard layout
@@ -98,21 +65,11 @@ func (s *LinuxLayoutSwitcher) SwitchLayout(ctx context.Context, layout *domain.K
9865

9966
// getSetxkbmapIdentifier returns the setxkbmap identifier for a layout
10067
func (s *LinuxLayoutSwitcher) getSetxkbmapIdentifier(layout *domain.KeyboardLayout) string {
101-
// First try to use the system identifier directly
68+
// Use the system identifier from the layout (set by the repository)
10269
if layout.SystemIdentifier != "" {
10370
return layout.SystemIdentifier
10471
}
10572

106-
// Otherwise, try to map the layout name
107-
if identifier, exists := s.layoutMap[layout.Name]; exists {
108-
return identifier
109-
}
110-
111-
// Fallback: assume the layout name is the identifier
112-
return strings.ToLower(layout.Name)
113-
}
114-
115-
// AddLayoutMapping adds a custom layout mapping
116-
func (s *LinuxLayoutSwitcher) AddLayoutMapping(name, setxkbmapIdentifier string) {
117-
s.layoutMap[name] = setxkbmapIdentifier
73+
// Fallback to "us" if no identifier is set
74+
return "us"
11875
}

internal/adapters/layouts/windows_layout_switcher.go

Lines changed: 5 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,45 +12,11 @@ import (
1212
)
1313

1414
// WindowsLayoutSwitcher switches keyboard layouts on Windows
15-
type WindowsLayoutSwitcher struct {
16-
// Map of layout names to Windows layout identifiers (KLID)
17-
layoutMap map[string]string
18-
}
15+
type WindowsLayoutSwitcher struct{}
1916

2017
// NewWindowsLayoutSwitcher creates a new Windows layout switcher
2118
func NewWindowsLayoutSwitcher() *WindowsLayoutSwitcher {
22-
return &WindowsLayoutSwitcher{
23-
layoutMap: getDefaultWindowsLayoutMap(),
24-
}
25-
}
26-
27-
// getDefaultWindowsLayoutMap returns a map of layout names to Windows KLIDs
28-
// KLIDs are 8-digit hex values representing keyboard layouts
29-
func getDefaultWindowsLayoutMap() map[string]string {
30-
return map[string]string{
31-
// US layouts
32-
domain.LayoutUSQwerty: "00000409", // US
33-
domain.LayoutUSInternational: "00020409", // US International
34-
domain.LayoutUSInternationalDeadKeys: "00020409", // US International
35-
36-
// French layouts
37-
domain.LayoutFrenchAzerty: "0000040c", // French
38-
39-
// UK layouts
40-
domain.LayoutUKQwerty: "00000809", // UK
41-
42-
// Alternative layouts
43-
domain.LayoutColemak: "00000409", // Colemak (requires separate installation)
44-
domain.LayoutDvorak: "00010409", // US Dvorak
45-
46-
// Other languages
47-
domain.LayoutGerman: "00000407", // German
48-
domain.LayoutSpanish: "0000040a", // Spanish
49-
domain.LayoutItalian: "00000410", // Italian
50-
domain.LayoutPortuguese: "00000816", // Portuguese
51-
domain.LayoutRussian: "00000419", // Russian
52-
domain.LayoutJapanese: "00000411", // Japanese
53-
}
19+
return &WindowsLayoutSwitcher{}
5420
}
5521

5622
// SwitchLayout changes the system keyboard layout
@@ -183,21 +149,11 @@ func (s *WindowsLayoutSwitcher) broadcastLayoutChange(hkl windows.Handle) error
183149

184150
// getKLID returns the Windows KLID for a layout
185151
func (s *WindowsLayoutSwitcher) getKLID(layout *domain.KeyboardLayout) string {
186-
// First try to use the system identifier directly
152+
// Use the system identifier from the layout (set by the repository)
187153
if layout.SystemIdentifier != "" {
188154
return layout.SystemIdentifier
189155
}
190156

191-
// Otherwise, try to map the layout name
192-
if klid, exists := s.layoutMap[layout.Name]; exists {
193-
return klid
194-
}
195-
196-
// Fallback
197-
return "00000409" // US layout
198-
}
199-
200-
// AddLayoutMapping adds a custom layout mapping
201-
func (s *WindowsLayoutSwitcher) AddLayoutMapping(name, klid string) {
202-
s.layoutMap[name] = klid
157+
// Fallback to US layout if no identifier is set
158+
return "00000409"
203159
}

0 commit comments

Comments
 (0)