2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

Remove some App::wnd() calls.

This commit is contained in:
John Preston
2021-02-25 19:12:51 +04:00
parent 204dd0a869
commit 54f06740d5
27 changed files with 137 additions and 106 deletions

View File

@@ -218,6 +218,15 @@ void MainWindow::updateWindowIcon() {
setWindowIcon(_icon);
}
QRect MainWindow::desktopRect() const {
const auto now = crl::now();
if (now >= _monitorLastGot && now <= _monitorLastGot + crl::time(1000)) {
_monitorLastGot = now;
_monitorRect = computeDesktopRect();
}
return _monitorRect;
}
void MainWindow::init() {
Expects(!windowHandle());
@@ -612,6 +621,10 @@ void MainWindow::updateUnreadCounter() {
unreadCounterChangedHook();
}
QRect MainWindow::computeDesktopRect() const {
return QApplication::desktop()->availableGeometry(this);
}
void MainWindow::savePosition(Qt::WindowState state) {
if (state == Qt::WindowActive) {
state = windowHandle()->windowState();
@@ -698,8 +711,9 @@ bool MainWindow::minimizeToTray() {
void MainWindow::reActivateWindow() {
#if defined Q_OS_UNIX && !defined Q_OS_MAC
const auto weak = Ui::MakeWeak(this);
const auto reActivate = [=] {
if (const auto w = App::wnd()) {
if (const auto w = weak.data()) {
if (auto f = QApplication::focusWidget()) {
f->clearFocus();
}
@@ -723,8 +737,8 @@ void MainWindow::showRightColumn(object_ptr<TWidget> widget) {
_rightColumn->setParent(this);
_rightColumn->show();
_rightColumn->setFocus();
} else if (App::wnd()) {
App::wnd()->setInnerFocus();
} else {
setInnerFocus();
}
const auto nowRightWidth = _rightColumn ? _rightColumn->width() : 0;
const auto wasMaximized = isMaximized();
@@ -777,7 +791,7 @@ int MainWindow::tryToExtendWidthBy(int addToWidth) {
void MainWindow::launchDrag(std::unique_ptr<QMimeData> data) {
auto weak = QPointer<MainWindow>(this);
auto drag = std::make_unique<QDrag>(App::wnd());
auto drag = std::make_unique<QDrag>(this);
drag->setMimeData(data.release());
drag->exec(Qt::CopyAction);

View File

@@ -37,10 +37,9 @@ QIcon CreateIcon(Main::Session *session = nullptr);
void ConvertIconToBlack(QImage &image);
class MainWindow : public Ui::RpWidget, protected base::Subscriber {
Q_OBJECT
public:
explicit MainWindow(not_null<Controller*> controller);
virtual ~MainWindow();
[[nodiscard]] Window::Controller &controller() const {
return *_controller;
@@ -57,15 +56,17 @@ public:
showFromTray();
}
[[nodiscard]] QRect desktopRect() const;
void init();
HitTestResult hitTest(const QPoint &p) const;
[[nodiscard]] HitTestResult hitTest(const QPoint &p) const;
void updateIsActive();
bool isActive() const {
[[nodiscard]] bool isActive() const {
return _isActive;
}
virtual bool isActiveForTrayMenu() {
[[nodiscard]] virtual bool isActiveForTrayMenu() {
updateIsActive();
return isActive();
}
@@ -94,8 +95,9 @@ public:
}
virtual void fixOrder() {
}
virtual ~MainWindow();
virtual void setInnerFocus() {
setFocus();
}
Ui::RpWidget *bodyWidget() {
return _body.data();
@@ -121,7 +123,6 @@ public:
bool hasShadow() const;
public slots:
bool minimizeToTray();
void updateGlobalMenu() {
updateGlobalMenuHook();
@@ -199,6 +200,8 @@ protected:
QSystemTrayIcon::ActivationReason reason) = 0;
void updateUnreadCounter();
virtual QRect computeDesktopRect() const;
private:
void refreshTitleWidget();
void updateMinimumSize();
@@ -231,6 +234,9 @@ private:
bool _maximizedBeforeHide = false;
mutable QRect _monitorRect;
mutable crl::time _monitorLastGot = 0;
};
} // namespace Window

View File

@@ -19,6 +19,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "data/data_channel.h"
#include "data/data_user.h"
#include "base/unixtime.h"
#include "window/window_controller.h"
#include "window/window_session_controller.h"
#include "core/application.h"
#include "mainwindow.h"
@@ -391,10 +392,10 @@ void System::showNext() {
const auto &settings = Core::App().settings();
if (alert) {
if (settings.flashBounceNotify() && !Platform::Notifications::SkipFlashBounce()) {
if (const auto widget = App::wnd()) {
if (const auto window = widget->windowHandle()) {
window->alert(kSystemAlertDuration);
// (window, SLOT(_q_clearAlert())); in the future.
if (const auto window = Core::App().activeWindow()) {
if (const auto handle = window->widget()->windowHandle()) {
handle->alert(kSystemAlertDuration);
// (handle, SLOT(_q_clearAlert())); in the future.
}
}
}
@@ -635,9 +636,9 @@ void Manager::notificationActivated(NotificationId id) {
} else {
openNotificationMessage(history, id.msgId);
}
onAfterNotificationActivated(id, window);
}
}
onAfterNotificationActivated(id);
}
void Manager::openNotificationMessage(

View File

@@ -32,6 +32,9 @@ class Track;
} // namespace Media
namespace Window {
class SessionController;
namespace Notifications {
enum class ManagerType {
@@ -217,7 +220,9 @@ protected:
virtual void doClearFromSession(not_null<Main::Session*> session) = 0;
virtual void onBeforeNotificationActivated(NotificationId id) {
}
virtual void onAfterNotificationActivated(NotificationId id) {
virtual void onAfterNotificationActivated(
NotificationId id,
not_null<SessionController*> window) {
}
[[nodiscard]] virtual QString accountNameSeparator();

View File

@@ -20,6 +20,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/ui_utility.h"
#include "dialogs/dialogs_layout.h"
#include "window/themes/window_theme.h"
#include "window/window_controller.h"
#include "storage/file_download.h"
#include "main/main_session.h"
#include "main/main_account.h"
@@ -34,7 +35,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "styles/style_layers.h"
#include "styles/style_window.h"
#include <QtCore/QCoreApplication>
#include <QtGui/QGuiApplication>
#include <QtGui/QScreen>
namespace Window {
namespace Notifications {
@@ -47,7 +49,10 @@ int notificationMaxHeight() {
QPoint notificationStartPosition() {
const auto corner = Core::App().settings().notificationsCorner();
const auto r = psDesktopRect();
const auto window = Core::App().activeWindow();
const auto r = window
? window->widget()->desktopRect()
: QGuiApplication::primaryScreen()->availableGeometry();
const auto isLeft = Core::Settings::IsLeftCorner(corner);
const auto isTop = Core::Settings::IsTopCorner(corner);
const auto x = (isLeft == rtl()) ? (r.x() + r.width() - st::notifyWidth - st::notifyDeltaX) : (r.x() + st::notifyDeltaX);

View File

@@ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "core/shortcuts.h"
#include "core/application.h"
#include "core/core_settings.h"
#include "core/click_handler_types.h"
#include "base/unixtime.h"
#include "ui/layers/generic_box.h"
#include "ui/text/text_utilities.h"
@@ -78,7 +79,10 @@ void DateClickHandler::setDate(QDate date) {
}
void DateClickHandler::onClick(ClickContext context) const {
App::wnd()->sessionController()->showJumpToDate(_chat, _date);
const auto my = context.other.value<ClickHandlerContext>();
if (const auto window = my.sessionWindow.get()) {
window->showJumpToDate(_chat, _date);
}
}
SessionNavigation::SessionNavigation(not_null<Main::Session*> session)