mirror of
https://github.com/telegramdesktop/tdesktop
synced 2025-03-18 17:40:59 +00:00
Fix bad window rendering with maximize-on-launch.
I have no idea why MainWindow is ruined completely in case you call MainWindow::show, MainWindow::setWindowState(maximized) and then in the same context (without crl::on_main) create full screen viewer.
This commit is contained in:
parent
1a2b2c15c5
commit
a88423a33f
@ -235,13 +235,16 @@ void Application::run() {
|
||||
_window->setupIntro();
|
||||
}
|
||||
}
|
||||
DEBUG_LOG(("Application Info: showing."));
|
||||
_window->firstShow();
|
||||
|
||||
_window->widget()->show();
|
||||
|
||||
const auto currentGeometry = _window->widget()->geometry();
|
||||
_mediaView = std::make_unique<Media::View::OverlayWidget>();
|
||||
_window->widget()->setGeometry(currentGeometry);
|
||||
|
||||
DEBUG_LOG(("Application Info: showing."));
|
||||
_window->finishFirstShow();
|
||||
|
||||
if (!locked() && cStartToSettings()) {
|
||||
_window->showSettings();
|
||||
}
|
||||
@ -274,6 +277,8 @@ void Application::showPhoto(not_null<const PhotoOpenClickHandler*> link) {
|
||||
}
|
||||
|
||||
void Application::showPhoto(not_null<PhotoData*> photo, HistoryItem *item) {
|
||||
Expects(_mediaView != nullptr);
|
||||
|
||||
_mediaView->showPhoto(photo, item);
|
||||
_mediaView->activateWindow();
|
||||
_mediaView->setFocus();
|
||||
@ -282,12 +287,16 @@ void Application::showPhoto(not_null<PhotoData*> photo, HistoryItem *item) {
|
||||
void Application::showPhoto(
|
||||
not_null<PhotoData*> photo,
|
||||
not_null<PeerData*> peer) {
|
||||
Expects(_mediaView != nullptr);
|
||||
|
||||
_mediaView->showPhoto(photo, peer);
|
||||
_mediaView->activateWindow();
|
||||
_mediaView->setFocus();
|
||||
}
|
||||
|
||||
void Application::showDocument(not_null<DocumentData*> document, HistoryItem *item) {
|
||||
Expects(_mediaView != nullptr);
|
||||
|
||||
if (cUseExternalVideoPlayer()
|
||||
&& document->isVideoFile()
|
||||
&& document->loaded()) {
|
||||
@ -302,6 +311,8 @@ void Application::showDocument(not_null<DocumentData*> document, HistoryItem *it
|
||||
void Application::showTheme(
|
||||
not_null<DocumentData*> document,
|
||||
const Data::CloudTheme &cloud) {
|
||||
Expects(_mediaView != nullptr);
|
||||
|
||||
_mediaView->showTheme(document, cloud);
|
||||
_mediaView->activateWindow();
|
||||
_mediaView->setFocus();
|
||||
|
@ -130,7 +130,7 @@ void MainWindow::initHook() {
|
||||
Qt::QueuedConnection);
|
||||
}
|
||||
|
||||
void MainWindow::firstShow() {
|
||||
void MainWindow::createTrayIconMenu() {
|
||||
#ifdef Q_OS_WIN
|
||||
trayIconMenu = new Ui::PopupMenu(nullptr);
|
||||
trayIconMenu->deleteOnHide(false);
|
||||
@ -148,9 +148,48 @@ void MainWindow::firstShow() {
|
||||
trayIconMenu->addAction(tr::lng_minimize_to_tray(tr::now), this, SLOT(minimizeToTray()));
|
||||
trayIconMenu->addAction(notificationActionText, this, SLOT(toggleDisplayNotifyFromTray()));
|
||||
trayIconMenu->addAction(tr::lng_quit_from_tray(tr::now), this, SLOT(quitFromTray()));
|
||||
|
||||
initTrayMenuHook();
|
||||
}
|
||||
|
||||
void MainWindow::applyInitialWorkMode() {
|
||||
Global::RefWorkMode().setForced(Global::WorkMode().value(), true);
|
||||
|
||||
psFirstShow();
|
||||
if (cWindowPos().maximized) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
if (cStartInTray()
|
||||
|| (cLaunchMode() == LaunchModeAutoStart
|
||||
&& cStartMinimized()
|
||||
&& !Core::App().passcodeLocked())) {
|
||||
const auto minimizeAndHide = [=] {
|
||||
DEBUG_LOG(("Window Pos: First show, setting minimized after."));
|
||||
setWindowState(windowState() | Qt::WindowMinimized);
|
||||
if (Global::WorkMode().value() == dbiwmTrayOnly
|
||||
|| Global::WorkMode().value() == dbiwmWindowAndTray) {
|
||||
hide();
|
||||
}
|
||||
};
|
||||
|
||||
if (Platform::IsLinux()) {
|
||||
// If I call hide() synchronously here after show() then on Ubuntu 14.04
|
||||
// it will show a window frame with transparent window body, without content.
|
||||
// And to be able to "Show from tray" one more hide() will be required.
|
||||
crl::on_main(this, minimizeAndHide);
|
||||
} else {
|
||||
minimizeAndHide();
|
||||
}
|
||||
}
|
||||
setPositionInited();
|
||||
}
|
||||
|
||||
void MainWindow::finishFirstShow() {
|
||||
createTrayIconMenu();
|
||||
initShadows();
|
||||
applyInitialWorkMode();
|
||||
createGlobalMenu();
|
||||
firstShadowsUpdate();
|
||||
updateTrayMenu();
|
||||
|
||||
windowDeactivateEvents(
|
||||
|
@ -49,7 +49,7 @@ public:
|
||||
explicit MainWindow(not_null<Window::Controller*> controller);
|
||||
~MainWindow();
|
||||
|
||||
void firstShow();
|
||||
void finishFirstShow();
|
||||
|
||||
void setupPasscodeLock();
|
||||
void clearPasscodeLock();
|
||||
@ -152,9 +152,11 @@ signals:
|
||||
private:
|
||||
[[nodiscard]] bool skipTrayClick() const;
|
||||
|
||||
void createTrayIconMenu();
|
||||
void handleTrayIconActication(
|
||||
QSystemTrayIcon::ActivationReason reason) override;
|
||||
|
||||
void applyInitialWorkMode();
|
||||
void ensureLayerCreated();
|
||||
void destroyLayer();
|
||||
|
||||
|
@ -455,7 +455,7 @@ void MainWindow::LibsLoaded() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::psFirstShow() {
|
||||
void MainWindow::initTrayMenuHook() {
|
||||
const auto trayAvailable = IsSNIAvailable()
|
||||
|| QSystemTrayIcon::isSystemTrayAvailable();
|
||||
|
||||
@ -490,30 +490,6 @@ void MainWindow::psFirstShow() {
|
||||
LOG(("Not using Unity Launcher count."));
|
||||
}
|
||||
#endif // !TDESKTOP_DISABLE_DBUS_INTEGRATION
|
||||
|
||||
show();
|
||||
if (cWindowPos().maximized) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
|
||||
if ((cLaunchMode() == LaunchModeAutoStart && cStartMinimized())
|
||||
|| cStartInTray()) {
|
||||
// If I call hide() synchronously here after show() then on Ubuntu 14.04
|
||||
// it will show a window frame with transparent window body, without content.
|
||||
// And to be able to "Show from tray" one more hide() will be required.
|
||||
crl::on_main(this, [=] {
|
||||
setWindowState(Qt::WindowMinimized);
|
||||
if (Global::WorkMode().value() == dbiwmTrayOnly
|
||||
|| Global::WorkMode().value() == dbiwmWindowAndTray) {
|
||||
hide();
|
||||
} else {
|
||||
show();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
setPositionInited();
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
|
@ -24,8 +24,6 @@ class MainWindow : public Window::MainWindow {
|
||||
public:
|
||||
explicit MainWindow(not_null<Window::Controller*> controller);
|
||||
|
||||
void psFirstShow();
|
||||
|
||||
virtual QImage iconWithCounter(
|
||||
int size,
|
||||
int count,
|
||||
@ -43,6 +41,7 @@ public slots:
|
||||
protected:
|
||||
void unreadCounterChangedHook() override;
|
||||
|
||||
void initTrayMenuHook() override;
|
||||
bool hasTrayIcon() const override;
|
||||
|
||||
void workmodeUpdated(DBIWorkMode mode) override;
|
||||
|
@ -23,8 +23,6 @@ class MainWindow : public Window::MainWindow {
|
||||
public:
|
||||
explicit MainWindow(not_null<Window::Controller*> controller);
|
||||
|
||||
void psFirstShow();
|
||||
|
||||
bool psFilterNativeEvent(void *event);
|
||||
|
||||
virtual QImage iconWithCounter(int size, int count, style::color bg, style::color fg, bool smallIcon) = 0;
|
||||
@ -87,14 +85,15 @@ protected:
|
||||
|
||||
QTimer psUpdatedPositionTimer;
|
||||
|
||||
void initShadows() override;
|
||||
void closeWithoutDestroy() override;
|
||||
void createGlobalMenu() override;
|
||||
|
||||
private:
|
||||
friend class Private;
|
||||
|
||||
void initTouchBar();
|
||||
void hideAndDeactivate();
|
||||
void createGlobalMenu();
|
||||
void updateTitleCounter();
|
||||
void updateIconCounters();
|
||||
|
||||
|
@ -663,31 +663,8 @@ void MainWindow::updateIconCounters() {
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::psFirstShow() {
|
||||
bool showShadows = true;
|
||||
|
||||
show();
|
||||
void MainWindow::initShadows() {
|
||||
_private->enableShadow(winId());
|
||||
if (cWindowPos().maximized) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
|
||||
if ((cLaunchMode() == LaunchModeAutoStart && cStartMinimized()) || cStartInTray()) {
|
||||
setWindowState(Qt::WindowMinimized);
|
||||
if (Global::WorkMode().value() == dbiwmTrayOnly || Global::WorkMode().value() == dbiwmWindowAndTray) {
|
||||
hide();
|
||||
} else {
|
||||
show();
|
||||
}
|
||||
showShadows = false;
|
||||
} else {
|
||||
show();
|
||||
}
|
||||
|
||||
setPositionInited();
|
||||
|
||||
createGlobalMenu();
|
||||
}
|
||||
|
||||
void MainWindow::createGlobalMenu() {
|
||||
|
@ -808,37 +808,15 @@ void MainWindow::initHook() {
|
||||
psInitSysMenu();
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QMargins);
|
||||
void MainWindow::psFirstShow() {
|
||||
void MainWindow::initShadows() {
|
||||
_psShadowWindows.init(this, st::windowShadowFg->c);
|
||||
_shadowsWorking = true;
|
||||
|
||||
psUpdateMargins();
|
||||
|
||||
shadowsUpdate(ShadowsChange::Hidden);
|
||||
bool showShadows = true;
|
||||
}
|
||||
|
||||
show();
|
||||
if (cWindowPos().maximized) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting maximized."));
|
||||
setWindowState(Qt::WindowMaximized);
|
||||
}
|
||||
|
||||
if (cStartInTray()
|
||||
|| (cLaunchMode() == LaunchModeAutoStart
|
||||
&& cStartMinimized()
|
||||
&& !Core::App().passcodeLocked())) {
|
||||
DEBUG_LOG(("Window Pos: First show, setting minimized after."));
|
||||
setWindowState(windowState() | Qt::WindowMinimized);
|
||||
if (Global::WorkMode().value() == dbiwmTrayOnly
|
||||
|| Global::WorkMode().value() == dbiwmWindowAndTray) {
|
||||
hide();
|
||||
}
|
||||
showShadows = false;
|
||||
}
|
||||
|
||||
setPositionInited();
|
||||
if (showShadows) {
|
||||
void MainWindow::firstShadowsUpdate() {
|
||||
if (!(windowState() & Qt::WindowMinimized) && !isHidden()) {
|
||||
shadowsUpdate(ShadowsChange::Moved | ShadowsChange::Resized | ShadowsChange::Shown);
|
||||
}
|
||||
}
|
||||
@ -896,6 +874,7 @@ void MainWindow::updateSystemMenu(Qt::WindowState state) {
|
||||
}
|
||||
}
|
||||
|
||||
Q_DECLARE_METATYPE(QMargins);
|
||||
void MainWindow::psUpdateMargins() {
|
||||
if (!ps_hWnd || _inUpdateMargins) return;
|
||||
|
||||
|
@ -28,7 +28,6 @@ public:
|
||||
HWND psHwnd() const;
|
||||
HMENU psMenu() const;
|
||||
|
||||
void psFirstShow();
|
||||
void psInitSysMenu();
|
||||
void updateSystemMenu(Qt::WindowState state);
|
||||
void psUpdateMargins();
|
||||
@ -77,6 +76,8 @@ protected:
|
||||
int32 screenNameChecksum(const QString &name) const override;
|
||||
void unreadCounterChangedHook() override;
|
||||
|
||||
void initShadows() override;
|
||||
void firstShadowsUpdate() override;
|
||||
void stateChangedHook(Qt::WindowState state) override;
|
||||
|
||||
bool hasTrayIcon() const override {
|
||||
|
@ -137,6 +137,8 @@ protected:
|
||||
virtual void updateGlobalMenuHook() {
|
||||
}
|
||||
|
||||
virtual void initTrayMenuHook() {
|
||||
}
|
||||
virtual bool hasTrayIcon() const {
|
||||
return false;
|
||||
}
|
||||
@ -148,6 +150,13 @@ protected:
|
||||
|
||||
virtual void updateControlsGeometry();
|
||||
|
||||
virtual void createGlobalMenu() {
|
||||
}
|
||||
virtual void initShadows() {
|
||||
}
|
||||
virtual void firstShadowsUpdate() {
|
||||
}
|
||||
|
||||
// This one is overriden in Windows for historical reasons.
|
||||
virtual int32 screenNameChecksum(const QString &name) const;
|
||||
|
||||
|
@ -42,8 +42,8 @@ Controller::~Controller() {
|
||||
_widget.clearWidgets();
|
||||
}
|
||||
|
||||
void Controller::firstShow() {
|
||||
_widget.firstShow();
|
||||
void Controller::finishFirstShow() {
|
||||
_widget.finishFirstShow();
|
||||
checkThemeEditor();
|
||||
}
|
||||
|
||||
|
@ -34,7 +34,7 @@ public:
|
||||
return _sessionController.get();
|
||||
}
|
||||
|
||||
void firstShow();
|
||||
void finishFirstShow();
|
||||
|
||||
void setupPasscodeLock();
|
||||
void clearPasscodeLock();
|
||||
|
Loading…
Reference in New Issue
Block a user