1414#include "timer/timer.h"
1515#include "window.h"
1616#include "config.h"
17+ #include "config/config_applier.h"
1718#include "log.h"
1819#include "language.h"
1920#include "startup.h"
2223#include "color/color.h"
2324#include "pomodoro.h"
2425#include "tray/tray.h"
26+
27+ extern void HandleStartupMode (HWND hwnd );
2528#include "dialog/dialog_procedure.h"
2629#include "hotkey.h"
2730#include "update_checker.h"
@@ -336,18 +339,56 @@ static LRESULT CmdBrowseFile(HWND hwnd, WPARAM wp, LPARAM lp) {
336339}
337340
338341static LRESULT CmdResetPosition (HWND hwnd , WPARAM wp , LPARAM lp ) {
339- (void )hwnd ; ( void ) wp ; (void )lp ;
342+ (void )wp ; (void )lp ;
340343
341- /* Use default values from config.h */
342- char posX [32 ], posY [32 ];
343- snprintf (posX , sizeof (posX ), "%d" , DEFAULT_WINDOW_POS_X );
344- snprintf (posY , sizeof (posY ), "%d" , DEFAULT_WINDOW_POS_Y );
344+ /* Write default values to config */
345+ char posXStr [32 ], posYStr [32 ];
346+ snprintf (posXStr , sizeof (posXStr ), "%d" , DEFAULT_WINDOW_POS_X );
347+ snprintf (posYStr , sizeof (posYStr ), "%d" , DEFAULT_WINDOW_POS_Y );
345348
346- WriteConfigKeyValue ("CLOCK_WINDOW_POS_X" , posX );
347- WriteConfigKeyValue ("CLOCK_WINDOW_POS_Y" , posY );
349+ WriteConfigKeyValue ("CLOCK_WINDOW_POS_X" , posXStr );
350+ WriteConfigKeyValue ("CLOCK_WINDOW_POS_Y" , posYStr );
348351 WriteConfigKeyValue ("WINDOW_SCALE" , DEFAULT_WINDOW_SCALE );
349352 WriteConfigKeyValue ("PLUGIN_SCALE" , DEFAULT_PLUGIN_SCALE );
350353
354+ /* Directly apply position (don't rely on hot-reload for special values) */
355+ RECT windowRect ;
356+ GetWindowRect (hwnd , & windowRect );
357+ int windowWidth = windowRect .right - windowRect .left ;
358+
359+ POINT pt = {0 , 0 };
360+ HMONITOR hMon = MonitorFromPoint (pt , MONITOR_DEFAULTTOPRIMARY );
361+ MONITORINFO mi = {sizeof (mi )};
362+ GetMonitorInfo (hMon , & mi );
363+ int screenWidth = mi .rcMonitor .right - mi .rcMonitor .left ;
364+
365+ int posX , posY ;
366+
367+ /* Handle special X position values */
368+ if (DEFAULT_WINDOW_POS_X == -2 ) {
369+ posX = mi .rcMonitor .left + (int )(screenWidth * 0.618f ) - (windowWidth / 2 );
370+ if (posX + windowWidth > mi .rcMonitor .right ) {
371+ posX = mi .rcMonitor .right - windowWidth - 20 ;
372+ }
373+ } else if (DEFAULT_WINDOW_POS_X == -1 ) {
374+ posX = mi .rcMonitor .left + (screenWidth - windowWidth ) / 2 ;
375+ } else {
376+ posX = mi .rcMonitor .left + DEFAULT_WINDOW_POS_X ;
377+ }
378+
379+ /* Handle special Y position value (-1 = top of monitor) */
380+ if (DEFAULT_WINDOW_POS_Y == -1 ) {
381+ posY = mi .rcMonitor .top ;
382+ } else if (DEFAULT_WINDOW_POS_Y < 0 ) {
383+ posY = mi .rcMonitor .top ;
384+ } else {
385+ posY = mi .rcMonitor .top + DEFAULT_WINDOW_POS_Y ;
386+ }
387+
388+ CLOCK_WINDOW_POS_X = posX ;
389+ CLOCK_WINDOW_POS_Y = posY ;
390+ SetWindowPos (hwnd , NULL , posX , posY , 0 , 0 , SWP_NOSIZE | SWP_NOZORDER );
391+
351392 return 0 ;
352393}
353394
@@ -375,18 +416,22 @@ static LRESULT CmdResetDefaults(HWND hwnd, WPARAM wp, LPARAM lp) {
375416
376417 /* Step 5: Reload all configuration (same as startup) */
377418 LOG_INFO ("Reset: Reloading default configuration..." );
419+ g_ForceApplyConfig = TRUE; /* Force apply all config values */
378420 ReadConfig ();
421+ g_ForceApplyConfig = FALSE;
379422 LOG_INFO ("Reset: Configuration reloaded successfully" );
380423
381- /* Step 5.5: Reset UI runtime state (not in config file) */
424+ /* Step 6: Apply startup mode from config */
425+ HandleStartupMode (hwnd );
426+ LOG_INFO ("Reset: Startup mode applied: %s" , CLOCK_STARTUP_MODE );
427+
428+ /* Step 7: Reset UI runtime state */
382429 CLOCK_EDIT_MODE = FALSE;
383430 SetClickThrough (hwnd , TRUE);
384- LOG_INFO ("Reset: UI runtime state reset" );
385-
386- /* Force timeout action to default (override config's preserve logic) */
387431 CLOCK_TIMEOUT_ACTION = TIMEOUT_ACTION_MESSAGE ;
432+ LOG_INFO ("Reset: UI runtime state reset" );
388433
389- /* Step 5.6 : Reload font (config sets FONT_FILE_NAME, but font needs to be loaded) */
434+ /* Step 8 : Reload font */
390435 if (IsFontsFolderPath (FONT_FILE_NAME )) {
391436 const char * relativePath = ExtractRelativePath (FONT_FILE_NAME );
392437 if (relativePath ) {
@@ -401,16 +446,16 @@ static LRESULT CmdResetDefaults(HWND hwnd, WPARAM wp, LPARAM lp) {
401446 }
402447 }
403448
404- /* Step 6 : Refresh UI to match new config */
449+ /* Step 9 : Refresh UI to match new config */
405450 RecalculateWindowSize (hwnd );
406451 ShowWindow (hwnd , SW_SHOW );
407452 ResetTimerWithInterval (hwnd );
408453
409- /* Step 7 : Re-enable redraw and refresh display */
454+ /* Step 10 : Re-enable redraw and refresh display */
410455 SendMessage (hwnd , WM_SETREDRAW , TRUE, 0 );
411456 RedrawWindow (hwnd , NULL , NULL , RDW_ERASE | RDW_FRAME | RDW_INVALIDATE | RDW_ALLCHILDREN );
412457
413- /* Step 8 : Re-register hotkeys with new config */
458+ /* Step 11 : Re-register hotkeys with new config */
414459 RegisterGlobalHotkeys (hwnd );
415460
416461 LOG_INFO ("========== Reset All Settings operation completed ==========\n" );
0 commit comments