@@ -12,19 +12,18 @@ import (
1212 "github.com/jialeicui/golibevdev"
1313 "github.com/samber/lo"
1414
15- "github.com/jialeicui/keyswift/pkg/conf"
16- "github.com/jialeicui/keyswift/pkg/dev"
15+ "github.com/jialeicui/keyswift/pkg/bus"
1716 "github.com/jialeicui/keyswift/pkg/evdev"
18- "github.com/jialeicui/keyswift/pkg/keys "
19- "github.com/jialeicui/keyswift/pkg/mode "
17+ "github.com/jialeicui/keyswift/pkg/handler "
18+ "github.com/jialeicui/keyswift/pkg/utils "
2019 "github.com/jialeicui/keyswift/pkg/wininfo/dbus"
2120)
2221
2322var (
24- flagKeyboards = flag .String ("keyboards" , "Apple " , "Comma-separated list of keyboard device name substrings" )
25- flagConfig = flag .String ("config" , "" , "Configuration file path (defaults to $XDG_CONFIG_HOME/keyswift/config.js)" )
26- // TODO change this to false
27- flagVerbose = flag .Bool ( "verbose " , true , "Enable verbose logging " )
23+ flagKeyboards = flag .String ("keyboards" , "HHKB " , "Comma-separated list of keyboard device name substrings" )
24+ flagConfig = flag .String ("config" , "" , "Configuration file path (defaults to $XDG_CONFIG_HOME/keyswift/config.js)" )
25+ flagVerbose = flag . Bool ( "verbose" , false , "Enable verbose logging" )
26+ flagOutputDeviceName = flag .String ( "output-device-name " , "keyswift" , "Name of the virtual keyboard device " )
2827)
2928
3029func main () {
@@ -40,7 +39,7 @@ func main() {
4039 // Load configuration
4140 configPath := * flagConfig
4241 if configPath == "" {
43- configPath = conf .DefaultConfigPath ()
42+ configPath = utils .DefaultConfigPath ()
4443 }
4544
4645 // Initialize window info service
@@ -53,27 +52,26 @@ func main() {
5352 slog .Info ("Window Monitor service is running..." )
5453
5554 // Initialize virtual keyboard for output
56- out , err := golibevdev .NewVirtualKeyboard ("keyswift" )
55+ out , err := golibevdev .NewVirtualKeyboard (* flagOutputDeviceName )
5756 if err != nil {
5857 slog .Error ("Failed to create virtual keyboard" , "error" , err )
5958 os .Exit (1 )
6059 }
6160 defer out .Close ()
62- gnomeKeys := keys .NewGnomeKeys (out )
6361
6462 script , err := os .ReadFile (configPath )
6563 if err != nil {
6664 slog .Error ("Failed to read configuration file" , "error" , err )
6765 os .Exit (1 )
6866 }
6967
70- // Initialize mode manager
71- modeManager , err := mode . NewManager (string (script ), gnomeKeys , windowMonitor )
68+ // Initialize bus manager
69+ busMgr , err := bus . New (string (script ), windowMonitor , out )
7270 if err != nil {
73- slog .Error ("Failed to initialize mode manager" , "error" , err )
71+ slog .Error ("Failed to initialize bus manager" , "error" , err )
7472 os .Exit (1 )
7573 }
76- slog .Info ("Mode manager initialized" )
74+ slog .Info ("bus manager initialized" )
7775
7876 // Find input devices
7977 devs , err := evdev .NewOverviewImpl ().ListInputDevices ()
@@ -93,7 +91,7 @@ func main() {
9391 }
9492
9593 matches := lo .Filter (devs , func (item * evdev.InputDevice , _ int ) bool {
96- return strings .Contains (item .Name , pattern )
94+ return strings .Contains (item .Name , pattern ) && item . Name != * flagOutputDeviceName
9795 })
9896
9997 matchedDevices = append (matchedDevices , matches ... )
@@ -114,7 +112,7 @@ func main() {
114112 }
115113
116114 // Initialize and set up the device manager
117- deviceManager := dev . NewInputDeviceManager ()
115+ deviceManager := handler . New ()
118116 defer deviceManager .Close ()
119117
120118 // Add all matched devices to the manager
@@ -140,8 +138,8 @@ func main() {
140138 }()
141139
142140 // Start processing events from all devices
143- slog .Info (fmt .Sprintf ("Processing events from %d devices... Press Ctrl+C to exit\n " , len (deviceManager .GetDevices ())))
144- deviceManager .ProcessEvents (out , modeManager )
141+ slog .Info (fmt .Sprintf ("Processing events from %d devices... Press Ctrl+C to exit" , len (deviceManager .GetDevices ())))
142+ deviceManager .ProcessEvents (out , busMgr )
145143
146144 // Wait for all processing to complete (typically won't reach here except on error)
147145 deviceManager .Wait ()
0 commit comments