@@ -48,14 +48,14 @@ MainWindow::MainWindow(QWidget* parent)
4848 GlobalSettings::instance ().WINDOW_SIZE ->HEIGHT
4949 );
5050 // move main window to desired position on startup
51- auto const screen_geometry = QGuiApplication::primaryScreen ()->availableGeometry ();
52- uint32_t const screen_width = (uint32_t )screen_geometry.width ();
53- uint32_t const screen_height = (uint32_t )screen_geometry.height ();
54- int32_t initial_x_pos_main = GlobalSettings::instance ().WINDOW_SIZE ->INITIAL_X_POS ;
55- int32_t initial_y_pos_main = GlobalSettings::instance ().WINDOW_SIZE ->INITIAL_Y_POS ;
56- int32_t move_x_main = std::max ( 0 , std::min (initial_x_pos_main, ( int32_t )(screen_width* 0.97 )) );
57- int32_t move_y_main = std::max ( 0 , std::min (initial_y_pos_main, ( int32_t )(screen_height* 0.97 )) );
58- move (scale_dpi_width ( move_x_main), scale_dpi_height ( move_y_main) );
51+ // auto const screen_geometry = QGuiApplication::primaryScreen()->availableGeometry();
52+ // uint32_t const screen_width = (uint32_t)screen_geometry.width();
53+ // uint32_t const screen_height = (uint32_t)screen_geometry.height();
54+ int32_t x_pos_main = GlobalSettings::instance ().WINDOW_SIZE ->X_POS ;
55+ int32_t y_pos_main = GlobalSettings::instance ().WINDOW_SIZE ->Y_POS ;
56+ int32_t move_x_main = move_x_within_screen_bounds (x_pos_main );
57+ int32_t move_y_main = move_y_within_screen_bounds (y_pos_main );
58+ move (move_x_main, move_y_main);
5959
6060 centralwidget = new QWidget (this );
6161 centralwidget->setObjectName (QString::fromUtf8 (" centralwidget" ));
@@ -222,8 +222,8 @@ MainWindow::MainWindow(QWidget* parent)
222222 );
223223 // get snapshot of the saved initial x/y position, since activating the window seems to change the window coordinates,
224224 // which then causes initial x/y position to change, due to triggering moveEvent().
225- int32_t initial_x_pos_log = GlobalSettings::instance ().LOG_WINDOW_SIZE ->INITIAL_X_POS ;
226- int32_t initial_y_pos_log = GlobalSettings::instance ().LOG_WINDOW_SIZE ->INITIAL_Y_POS ;
225+ int32_t x_pos_log = GlobalSettings::instance ().LOG_WINDOW_SIZE ->X_POS ;
226+ int32_t y_pos_log = GlobalSettings::instance ().LOG_WINDOW_SIZE ->Y_POS ;
227227
228228 if (GlobalSettings::instance ().LOG_WINDOW_STARTUP ){ // show the Output Window on startup
229229 m_output_window->show ();
@@ -232,9 +232,9 @@ MainWindow::MainWindow(QWidget* parent)
232232 }
233233
234234 // move the output window to desired position on startup
235- int32_t move_x_log = std::max ( 0 , std::min (initial_x_pos_log, ( int32_t )(screen_width* 0.97 ))); // ensure move_x is greater than 0, but less than screen_width
236- int32_t move_y_log = std::max ( 0 , std::min (initial_y_pos_log, ( int32_t )(screen_height* 0.97 )) );
237- m_output_window->move (scale_dpi_width ( move_x_log), scale_dpi_height ( move_y_log) );
235+ int32_t move_x_log = move_x_within_screen_bounds (x_pos_log);
236+ int32_t move_y_log = move_y_within_screen_bounds (y_pos_log );
237+ m_output_window->move (move_x_log, move_y_log);
238238 }
239239 {
240240 QPushButton* settings = new QPushButton (" Settings" , support_box);
@@ -260,6 +260,8 @@ MainWindow::MainWindow(QWidget* parent)
260260
261261 GlobalSettings::instance ().WINDOW_SIZE ->WIDTH .add_listener (*this );
262262 GlobalSettings::instance ().WINDOW_SIZE ->HEIGHT .add_listener (*this );
263+ GlobalSettings::instance ().WINDOW_SIZE ->X_POS .add_listener (*this );
264+ GlobalSettings::instance ().WINDOW_SIZE ->Y_POS .add_listener (*this );
263265 SystemSleepController::instance ().add_listener (*this );
264266// cout << "Done constructing" << endl;
265267}
@@ -268,6 +270,24 @@ MainWindow::~MainWindow(){
268270 SystemSleepController::instance ().remove_listener (*this );
269271 GlobalSettings::instance ().WINDOW_SIZE ->WIDTH .remove_listener (*this );
270272 GlobalSettings::instance ().WINDOW_SIZE ->HEIGHT .remove_listener (*this );
273+ GlobalSettings::instance ().WINDOW_SIZE ->X_POS .remove_listener (*this );
274+ GlobalSettings::instance ().WINDOW_SIZE ->Y_POS .remove_listener (*this );
275+ }
276+
277+ int32_t move_x_within_screen_bounds (int32_t x_pos){
278+ auto static const screen_geometry = QGuiApplication::primaryScreen ()->availableGeometry ();
279+ uint32_t static const screen_width = (uint32_t )screen_geometry.width ();
280+ // ensure move_x is greater than 0, but less than screen_width
281+ return scale_dpi_width (std::max (0 , std::min (x_pos, (int32_t )(screen_width*0.97 ))));
282+
283+ }
284+
285+ int32_t move_y_within_screen_bounds (int32_t y_pos){
286+ auto static const screen_geometry = QGuiApplication::primaryScreen ()->availableGeometry ();
287+ uint32_t const screen_height = (uint32_t )screen_geometry.height ();
288+ // ensure move_y is greater than 0, but less than screen_height
289+ return scale_dpi_width (std::max (0 , std::min (y_pos, (int32_t )(screen_height*0.97 ))));
290+
271291}
272292
273293
@@ -283,8 +303,10 @@ void MainWindow::resizeEvent(QResizeEvent* event){
283303}
284304
285305void MainWindow::moveEvent (QMoveEvent* event){
286- GlobalSettings::instance ().WINDOW_SIZE ->INITIAL_X_POS .set (x ());
287- GlobalSettings::instance ().WINDOW_SIZE ->INITIAL_Y_POS .set (y ());
306+ m_pending_move = true ;
307+ GlobalSettings::instance ().WINDOW_SIZE ->X_POS .set (x ());
308+ GlobalSettings::instance ().WINDOW_SIZE ->Y_POS .set (y ());
309+ m_pending_move = false ;
288310}
289311
290312void MainWindow::close_panel () noexcept {
@@ -373,14 +395,25 @@ void MainWindow::on_idle(){
373395
374396
375397void MainWindow::on_config_value_changed (void * object){
376- QMetaObject::invokeMethod (this , [this ]{
377- if (!m_pending_resize){
378- resize (
379- GlobalSettings::instance ().WINDOW_SIZE ->WIDTH ,
380- GlobalSettings::instance ().WINDOW_SIZE ->HEIGHT
381- );
382- }
383- });
398+ if (object == &GlobalSettings::instance ().WINDOW_SIZE ->WIDTH || object == &GlobalSettings::instance ().WINDOW_SIZE ->HEIGHT ){
399+ QMetaObject::invokeMethod (this , [this ]{
400+ if (!m_pending_resize){
401+ resize (
402+ GlobalSettings::instance ().WINDOW_SIZE ->WIDTH ,
403+ GlobalSettings::instance ().WINDOW_SIZE ->HEIGHT
404+ );
405+ }
406+ });
407+ }else if (object == &GlobalSettings::instance ().WINDOW_SIZE ->X_POS || object == &GlobalSettings::instance ().WINDOW_SIZE ->Y_POS ){
408+ QMetaObject::invokeMethod (this , [this ]{
409+ if (!m_pending_move){
410+ move (
411+ move_x_within_screen_bounds (GlobalSettings::instance ().WINDOW_SIZE ->X_POS ),
412+ move_y_within_screen_bounds (GlobalSettings::instance ().WINDOW_SIZE ->Y_POS )
413+ );
414+ }
415+ });
416+ }
384417}
385418void MainWindow::sleep_suppress_state_changed (SleepSuppress new_state){
386419 QMetaObject::invokeMethod (this , [=, this ]{
0 commit comments