mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-08-31 14:38:15 +00:00
Add "ctrl-click-chat-new-window" option.
This commit is contained in:
@@ -489,7 +489,7 @@ void MainWindow::handleStateChanged(Qt::WindowState state) {
|
||||
|
||||
void MainWindow::handleActiveChanged() {
|
||||
if (isActiveWindow()) {
|
||||
Core::App().checkMediaViewActivation();
|
||||
Core::App().windowActivated(&controller());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -737,10 +737,9 @@ void MainWindow::initGeometry() {
|
||||
if (initGeometryFromSystem()) {
|
||||
return;
|
||||
}
|
||||
// #TODO windows
|
||||
const auto geometry = countInitialGeometry(isPrimary()
|
||||
? positionFromSettings()
|
||||
: Core::WindowPosition());
|
||||
: SecondaryInitPosition());
|
||||
DEBUG_LOG(("Window Pos: Setting first %1, %2, %3, %4"
|
||||
).arg(geometry.x()
|
||||
).arg(geometry.y()
|
||||
@@ -836,30 +835,7 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||
realPosition.moncrc = 0;
|
||||
|
||||
DEBUG_LOG(("Window Pos: Saving non-maximized position: %1, %2, %3, %4").arg(realPosition.x).arg(realPosition.y).arg(realPosition.w).arg(realPosition.h));
|
||||
|
||||
auto centerX = realPosition.x + realPosition.w / 2;
|
||||
auto centerY = realPosition.y + realPosition.h / 2;
|
||||
int minDelta = 0;
|
||||
QScreen *chosen = nullptr;
|
||||
const auto screens = QGuiApplication::screens();
|
||||
for (auto screen : screens) {
|
||||
auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
|
||||
if (!chosen || delta < minDelta) {
|
||||
minDelta = delta;
|
||||
chosen = screen;
|
||||
}
|
||||
}
|
||||
if (chosen) {
|
||||
auto screenGeometry = chosen->geometry();
|
||||
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4"
|
||||
).arg(screenGeometry.x()
|
||||
).arg(screenGeometry.y()
|
||||
).arg(screenGeometry.width()
|
||||
).arg(screenGeometry.height()));
|
||||
realPosition.x -= screenGeometry.x();
|
||||
realPosition.y -= screenGeometry.y();
|
||||
realPosition.moncrc = screenNameChecksum(chosen->name());
|
||||
}
|
||||
realPosition = withScreenInPosition(realPosition);
|
||||
}
|
||||
if (realPosition.w >= st::windowMinWidth && realPosition.h >= st::windowMinHeight) {
|
||||
if (realPosition.x != savedPosition.x
|
||||
@@ -882,6 +858,51 @@ void MainWindow::savePosition(Qt::WindowState state) {
|
||||
}
|
||||
}
|
||||
|
||||
Core::WindowPosition MainWindow::withScreenInPosition(
|
||||
Core::WindowPosition position) const {
|
||||
auto centerX = position.x + position.w / 2;
|
||||
auto centerY = position.y + position.h / 2;
|
||||
int minDelta = 0;
|
||||
QScreen *chosen = nullptr;
|
||||
const auto screens = QGuiApplication::screens();
|
||||
for (auto screen : screens) {
|
||||
auto delta = (screen->geometry().center() - QPoint(centerX, centerY)).manhattanLength();
|
||||
if (!chosen || delta < minDelta) {
|
||||
minDelta = delta;
|
||||
chosen = screen;
|
||||
}
|
||||
}
|
||||
if (!chosen) {
|
||||
return position;
|
||||
}
|
||||
auto screenGeometry = chosen->geometry();
|
||||
DEBUG_LOG(("Window Pos: Screen found, geometry: %1, %2, %3, %4"
|
||||
).arg(screenGeometry.x()
|
||||
).arg(screenGeometry.y()
|
||||
).arg(screenGeometry.width()
|
||||
).arg(screenGeometry.height()));
|
||||
position.x -= screenGeometry.x();
|
||||
position.y -= screenGeometry.y();
|
||||
position.moncrc = screenNameChecksum(chosen->name());
|
||||
return position;
|
||||
}
|
||||
|
||||
Core::WindowPosition MainWindow::SecondaryInitPosition() {
|
||||
const auto active = Core::App().activeWindow();
|
||||
if (!active) {
|
||||
return {};
|
||||
}
|
||||
const auto geometry = active->widget()->geometry();
|
||||
const auto skip = st::windowMinWidth / 6;
|
||||
return active->widget()->withScreenInPosition({
|
||||
.scale = cScale(),
|
||||
.x = geometry.x() + skip,
|
||||
.y = geometry.y() + skip,
|
||||
.w = st::windowMinWidth,
|
||||
.h = st::windowDefaultHeight,
|
||||
});
|
||||
}
|
||||
|
||||
bool MainWindow::minimizeToTray() {
|
||||
if (Core::Quitting()/* || !hasTrayIcon()*/) {
|
||||
return false;
|
||||
|
Reference in New Issue
Block a user