@@ -64,12 +64,7 @@ func (a *AppManager) Run() error {
6464 // 3. Create UI manager.
6565 a .ui = ui .NewUIManager (a .app )
6666
67- // 4. Setup context menu and system tray.
68- a .ui .SetupContextMenu (
69- func () { a .openSettings () },
70- func (pos string ) { a .saveCornerPosition (pos ) },
71- func () { a .Shutdown () },
72- )
67+ // 4. Setup system tray.
7368 a .ui .SetupSystemTray (
7469 func () { a .openSettings () },
7570 func () { a .Shutdown () },
@@ -87,9 +82,21 @@ func (a *AppManager) Run() error {
8782 // 7. Show widget and apply Win32 styles.
8883 a .ui .ShowWidget (cfg .Cities )
8984 a .ui .ApplyWin32Styles ()
90- a .ui . SetCorner (cfg . CornerPosition )
85+ a .applyPosition (cfg )
9186 log .Printf ("WeatherWidget window shown at %s" , cfg .CornerPosition )
9287
88+ // 8. Enable drag-to-reposition — persists custom coordinates on drag end.
89+ a .ui .EnableDrag (func () {
90+ x , y := a .ui .GetPosition ()
91+ a .cfg .CustomX = & x
92+ a .cfg .CustomY = & y
93+ if err := a .config .Save (a .cfg ); err != nil {
94+ log .Printf ("failed to save custom position (%d, %d): %v" , x , y , err )
95+ } else {
96+ log .Printf ("custom position saved: (%d, %d)" , x , y )
97+ }
98+ })
99+
93100 // 8. Start clocks for each panel.
94101 a .startPanelClocks (cfg .Cities )
95102
@@ -140,15 +147,14 @@ func (a *AppManager) openSettings() {
140147 a .ui .ShowSettings (a .cfg , a .onSettingsSave )
141148}
142149
143- // saveCornerPosition updates the in-memory config with the new corner position
144- // and persists it to disk. Called when the user picks a position from the
145- // right-click context menu.
146- func (a * AppManager ) saveCornerPosition (pos string ) {
147- a .cfg .CornerPosition = pos
148- if err := a .config .Save (a .cfg ); err != nil {
149- log .Printf ("failed to save corner position %q: %v" , pos , err )
150+ // applyPosition moves the widget to custom coordinates if set, otherwise
151+ // falls back to the configured corner position.
152+ func (a * AppManager ) applyPosition (cfg * config.Config ) {
153+ if cfg .CustomX != nil && cfg .CustomY != nil {
154+ a .ui .SetPosition (* cfg .CustomX , * cfg .CustomY )
155+ log .Printf ("positioned widget at custom coordinates (%d, %d)" , * cfg .CustomX , * cfg .CustomY )
150156 } else {
151- log . Printf ( "corner position saved: %s" , pos )
157+ a . ui . SetCorner ( cfg . CornerPosition )
152158 }
153159}
154160
@@ -203,7 +209,7 @@ func (a *AppManager) onSettingsSave(newCfg *config.Config) error {
203209 }
204210
205211 // Always reposition the widget window (position may have changed independently).
206- a .ui . SetCorner (newCfg . CornerPosition )
212+ a .applyPosition (newCfg )
207213
208214 return nil
209215}
0 commit comments