@@ -700,115 +700,12 @@ QRect MainWindow::countInitialGeometry(WindowPosition position) {
700700 .w = initialWidth,
701701 .h = initialHeight,
702702 };
703- return countInitialGeometry (
703+ return CountInitialGeometry (
704+ this ,
704705 position,
705706 initial,
706- { st::windowMinWidth, st::windowMinHeight });
707- }
708-
709- QRect MainWindow::countInitialGeometry (
710- WindowPosition position,
711- WindowPosition initial,
712- QSize minSize) const {
713- if (!position.w || !position.h ) {
714- return initial.rect ();
715- }
716- const auto screen = [&]() -> QScreen* {
717- for (const auto screen : QGuiApplication::screens ()) {
718- const auto sum = Platform::ScreenNameChecksum (screen->name ());
719- if (position.moncrc == sum) {
720- return screen;
721- }
722- }
723- return QGuiApplication::screenAt (position.rect ().center ());
724- }();
725- if (!screen) {
726- return initial.rect ();
727- }
728- const auto frame = frameMargins ();
729- const auto screenGeometry = screen->geometry ();
730- const auto availableGeometry = screen->availableGeometry ();
731- const auto spaceForInner = availableGeometry.marginsRemoved (frame);
732- DEBUG_LOG ((" Window Pos: "
733- " Screen found, screen geometry: %1, %2, %3, %4, "
734- " available: %5, %6, %7, %8"
735- ).arg (screenGeometry.x ()
736- ).arg (screenGeometry.y ()
737- ).arg (screenGeometry.width ()
738- ).arg (screenGeometry.height ()
739- ).arg (availableGeometry.x ()
740- ).arg (availableGeometry.y ()
741- ).arg (availableGeometry.width ()
742- ).arg (availableGeometry.height ()));
743- DEBUG_LOG ((" Window Pos: "
744- " Window frame margins: %1, %2, %3, %4, "
745- " available space for inner geometry: %5, %6, %7, %8"
746- ).arg (frame.left ()
747- ).arg (frame.top ()
748- ).arg (frame.right ()
749- ).arg (frame.bottom ()
750- ).arg (spaceForInner.x ()
751- ).arg (spaceForInner.y ()
752- ).arg (spaceForInner.width ()
753- ).arg (spaceForInner.height ()));
754-
755- const auto x = spaceForInner.x ()
756- - (position.moncrc ? screenGeometry.x () : 0 );
757- const auto y = spaceForInner.y ()
758- - (position.moncrc ? screenGeometry.y () : 0 );
759- const auto w = spaceForInner.width ();
760- const auto h = spaceForInner.height ();
761- if (w < st::windowMinWidth || h < st::windowMinHeight) {
762- return initial.rect ();
763- }
764- if (position.x < x) position.x = x;
765- if (position.y < y) position.y = y;
766- if (position.w > w) position.w = w;
767- if (position.h > h) position.h = h;
768- const auto rightPoint = position.x + position.w ;
769- const auto screenRightPoint = x + w;
770- if (rightPoint > screenRightPoint) {
771- const auto distance = rightPoint - screenRightPoint;
772- const auto newXPos = position.x - distance;
773- if (newXPos >= x) {
774- position.x = newXPos;
775- } else {
776- position.x = x;
777- const auto newRightPoint = position.x + position.w ;
778- const auto newDistance = newRightPoint - screenRightPoint;
779- position.w -= newDistance;
780- }
781- }
782- const auto bottomPoint = position.y + position.h ;
783- const auto screenBottomPoint = y + h;
784- if (bottomPoint > screenBottomPoint) {
785- const auto distance = bottomPoint - screenBottomPoint;
786- const auto newYPos = position.y - distance;
787- if (newYPos >= y) {
788- position.y = newYPos;
789- } else {
790- position.y = y;
791- const auto newBottomPoint = position.y + position.h ;
792- const auto newDistance = newBottomPoint - screenBottomPoint;
793- position.h -= newDistance;
794- }
795- }
796- if (position.moncrc ) {
797- position.x += screenGeometry.x ();
798- position.y += screenGeometry.y ();
799- }
800- if ((position.x + st::windowMinWidth
801- > screenGeometry.x () + screenGeometry.width ())
802- || (position.y + st::windowMinHeight
803- > screenGeometry.y () + screenGeometry.height ())) {
804- return initial.rect ();
805- }
806- DEBUG_LOG ((" Window Pos: Resulting geometry is %1, %2, %3, %4"
807- ).arg (position.x
808- ).arg (position.y
809- ).arg (position.w
810- ).arg (position.h ));
811- return position.rect ();
707+ { st::windowMinWidth, st::windowMinHeight },
708+ u" Window" _q);
812709}
813710
814711void MainWindow::firstShow () {
@@ -1136,4 +1033,114 @@ WindowPosition PositionWithScreen(
11361033 name);
11371034}
11381035
1036+ QRect CountInitialGeometry (
1037+ not_null<const Ui::RpWindow*> widget,
1038+ WindowPosition position,
1039+ WindowPosition initial,
1040+ QSize minSize,
1041+ const QString &name) {
1042+ if (!position.w || !position.h ) {
1043+ return initial.rect ();
1044+ }
1045+ const auto screen = [&]() -> QScreen* {
1046+ for (const auto screen : QGuiApplication::screens ()) {
1047+ const auto sum = Platform::ScreenNameChecksum (screen->name ());
1048+ if (position.moncrc == sum) {
1049+ return screen;
1050+ }
1051+ }
1052+ return QGuiApplication::screenAt (position.rect ().center ());
1053+ }();
1054+ if (!screen) {
1055+ return initial.rect ();
1056+ }
1057+ const auto frame = widget->frameMargins ();
1058+ const auto screenGeometry = screen->geometry ();
1059+ const auto availableGeometry = screen->availableGeometry ();
1060+ const auto spaceForInner = availableGeometry.marginsRemoved (frame);
1061+ DEBUG_LOG ((" %1 Pos: "
1062+ " Screen found, screen geometry: %2, %3, %4, %5, "
1063+ " available: %6, %7, %8, %9"
1064+ ).arg (name
1065+ ).arg (screenGeometry.x ()
1066+ ).arg (screenGeometry.y ()
1067+ ).arg (screenGeometry.width ()
1068+ ).arg (screenGeometry.height ()
1069+ ).arg (availableGeometry.x ()
1070+ ).arg (availableGeometry.y ()
1071+ ).arg (availableGeometry.width ()
1072+ ).arg (availableGeometry.height ()));
1073+ DEBUG_LOG ((" %1 Pos: "
1074+ " Window frame margins: %2, %3, %4, %5, "
1075+ " available space for inner geometry: %6, %7, %8, %9"
1076+ ).arg (name
1077+ ).arg (frame.left ()
1078+ ).arg (frame.top ()
1079+ ).arg (frame.right ()
1080+ ).arg (frame.bottom ()
1081+ ).arg (spaceForInner.x ()
1082+ ).arg (spaceForInner.y ()
1083+ ).arg (spaceForInner.width ()
1084+ ).arg (spaceForInner.height ()));
1085+
1086+ const auto x = spaceForInner.x ()
1087+ - (position.moncrc ? screenGeometry.x () : 0 );
1088+ const auto y = spaceForInner.y ()
1089+ - (position.moncrc ? screenGeometry.y () : 0 );
1090+ const auto w = spaceForInner.width ();
1091+ const auto h = spaceForInner.height ();
1092+ if (w < st::windowMinWidth || h < st::windowMinHeight) {
1093+ return initial.rect ();
1094+ }
1095+ if (position.x < x) position.x = x;
1096+ if (position.y < y) position.y = y;
1097+ if (position.w > w) position.w = w;
1098+ if (position.h > h) position.h = h;
1099+ const auto rightPoint = position.x + position.w ;
1100+ const auto screenRightPoint = x + w;
1101+ if (rightPoint > screenRightPoint) {
1102+ const auto distance = rightPoint - screenRightPoint;
1103+ const auto newXPos = position.x - distance;
1104+ if (newXPos >= x) {
1105+ position.x = newXPos;
1106+ } else {
1107+ position.x = x;
1108+ const auto newRightPoint = position.x + position.w ;
1109+ const auto newDistance = newRightPoint - screenRightPoint;
1110+ position.w -= newDistance;
1111+ }
1112+ }
1113+ const auto bottomPoint = position.y + position.h ;
1114+ const auto screenBottomPoint = y + h;
1115+ if (bottomPoint > screenBottomPoint) {
1116+ const auto distance = bottomPoint - screenBottomPoint;
1117+ const auto newYPos = position.y - distance;
1118+ if (newYPos >= y) {
1119+ position.y = newYPos;
1120+ } else {
1121+ position.y = y;
1122+ const auto newBottomPoint = position.y + position.h ;
1123+ const auto newDistance = newBottomPoint - screenBottomPoint;
1124+ position.h -= newDistance;
1125+ }
1126+ }
1127+ if (position.moncrc ) {
1128+ position.x += screenGeometry.x ();
1129+ position.y += screenGeometry.y ();
1130+ }
1131+ if ((position.x + st::windowMinWidth
1132+ > screenGeometry.x () + screenGeometry.width ())
1133+ || (position.y + st::windowMinHeight
1134+ > screenGeometry.y () + screenGeometry.height ())) {
1135+ return initial.rect ();
1136+ }
1137+ DEBUG_LOG ((" %1 Pos: Resulting geometry is %2, %3, %4, %5"
1138+ ).arg (name
1139+ ).arg (position.x
1140+ ).arg (position.y
1141+ ).arg (position.w
1142+ ).arg (position.h ));
1143+ return position.rect ();
1144+ }
1145+
11391146} // namespace Window
0 commit comments