diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 6d2ea38a2e..f3bbacb669 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -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(); _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 link) { } void Application::showPhoto(not_null photo, HistoryItem *item) { + Expects(_mediaView != nullptr); + _mediaView->showPhoto(photo, item); _mediaView->activateWindow(); _mediaView->setFocus(); @@ -282,12 +287,16 @@ void Application::showPhoto(not_null photo, HistoryItem *item) { void Application::showPhoto( not_null photo, not_null peer) { + Expects(_mediaView != nullptr); + _mediaView->showPhoto(photo, peer); _mediaView->activateWindow(); _mediaView->setFocus(); } void Application::showDocument(not_null document, HistoryItem *item) { + Expects(_mediaView != nullptr); + if (cUseExternalVideoPlayer() && document->isVideoFile() && document->loaded()) { @@ -302,6 +311,8 @@ void Application::showDocument(not_null document, HistoryItem *it void Application::showTheme( not_null document, const Data::CloudTheme &cloud) { + Expects(_mediaView != nullptr); + _mediaView->showTheme(document, cloud); _mediaView->activateWindow(); _mediaView->setFocus(); diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index 84113702eb..6e360c89db 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -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( diff --git a/Telegram/SourceFiles/mainwindow.h b/Telegram/SourceFiles/mainwindow.h index 11ba00c6df..4635bbea6e 100644 --- a/Telegram/SourceFiles/mainwindow.h +++ b/Telegram/SourceFiles/mainwindow.h @@ -49,7 +49,7 @@ public: explicit MainWindow(not_null 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(); diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp index 63a2a5ecbf..75ce5ce950 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.cpp @@ -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() { diff --git a/Telegram/SourceFiles/platform/linux/main_window_linux.h b/Telegram/SourceFiles/platform/linux/main_window_linux.h index fa175b2e1a..104e8e5b61 100644 --- a/Telegram/SourceFiles/platform/linux/main_window_linux.h +++ b/Telegram/SourceFiles/platform/linux/main_window_linux.h @@ -24,8 +24,6 @@ class MainWindow : public Window::MainWindow { public: explicit MainWindow(not_null 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; diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.h b/Telegram/SourceFiles/platform/mac/main_window_mac.h index f02027294a..f8a90c9d73 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.h +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.h @@ -23,8 +23,6 @@ class MainWindow : public Window::MainWindow { public: explicit MainWindow(not_null 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(); diff --git a/Telegram/SourceFiles/platform/mac/main_window_mac.mm b/Telegram/SourceFiles/platform/mac/main_window_mac.mm index 023ab2b909..58927dc3c2 100644 --- a/Telegram/SourceFiles/platform/mac/main_window_mac.mm +++ b/Telegram/SourceFiles/platform/mac/main_window_mac.mm @@ -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() { diff --git a/Telegram/SourceFiles/platform/win/main_window_win.cpp b/Telegram/SourceFiles/platform/win/main_window_win.cpp index 2dffbccfb1..4192df23f1 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.cpp +++ b/Telegram/SourceFiles/platform/win/main_window_win.cpp @@ -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; diff --git a/Telegram/SourceFiles/platform/win/main_window_win.h b/Telegram/SourceFiles/platform/win/main_window_win.h index 6ec9648d1d..f599de881b 100644 --- a/Telegram/SourceFiles/platform/win/main_window_win.h +++ b/Telegram/SourceFiles/platform/win/main_window_win.h @@ -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 { diff --git a/Telegram/SourceFiles/window/main_window.h b/Telegram/SourceFiles/window/main_window.h index a8eedea572..3282483f06 100644 --- a/Telegram/SourceFiles/window/main_window.h +++ b/Telegram/SourceFiles/window/main_window.h @@ -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; diff --git a/Telegram/SourceFiles/window/window_controller.cpp b/Telegram/SourceFiles/window/window_controller.cpp index a6e4c8da99..69afd5e886 100644 --- a/Telegram/SourceFiles/window/window_controller.cpp +++ b/Telegram/SourceFiles/window/window_controller.cpp @@ -42,8 +42,8 @@ Controller::~Controller() { _widget.clearWidgets(); } -void Controller::firstShow() { - _widget.firstShow(); +void Controller::finishFirstShow() { + _widget.finishFirstShow(); checkThemeEditor(); } diff --git a/Telegram/SourceFiles/window/window_controller.h b/Telegram/SourceFiles/window/window_controller.h index d8adfc2e69..7ce23ca04e 100644 --- a/Telegram/SourceFiles/window/window_controller.h +++ b/Telegram/SourceFiles/window/window_controller.h @@ -34,7 +34,7 @@ public: return _sessionController.get(); } - void firstShow(); + void finishFirstShow(); void setupPasscodeLock(); void clearPasscodeLock();