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

Switch MainWindow to Ui::RpWindow

This commit is contained in:
Ilya Fedin
2021-07-26 01:30:56 +04:00
committed by John Preston
parent 4ef2d3b957
commit 1ebf27bfa1
29 changed files with 116 additions and 1933 deletions

View File

@@ -21,128 +21,73 @@ using namespace KWayland::Client;
namespace Platform {
namespace internal {
class WaylandIntegration::Private : public QObject {
public:
Private();
[[nodiscard]] Registry &registry() {
return _registry;
}
[[nodiscard]] XdgExporter *xdgExporter() {
return _xdgExporter.get();
}
[[nodiscard]] PlasmaShell *plasmaShell() {
return _plasmaShell.get();
}
[[nodiscard]] AppMenuManager *appMenuManager() {
return _appMenuManager.get();
}
[[nodiscard]] QEventLoop &interfacesLoop() {
return _interfacesLoop;
}
[[nodiscard]] bool interfacesAnnounced() const {
return _interfacesAnnounced;
}
private:
ConnectionThread _connection;
ConnectionThread *_applicationConnection = nullptr;
Registry _registry;
Registry _applicationRegistry;
std::unique_ptr<XdgExporter> _xdgExporter;
std::unique_ptr<PlasmaShell> _plasmaShell;
std::unique_ptr<AppMenuManager> _appMenuManager;
QEventLoop _interfacesLoop;
bool _interfacesAnnounced = false;
struct WaylandIntegration::Private {
std::unique_ptr<ConnectionThread> connection;
Registry registry;
std::unique_ptr<XdgExporter> xdgExporter;
std::unique_ptr<PlasmaShell> plasmaShell;
std::unique_ptr<AppMenuManager> appMenuManager;
};
WaylandIntegration::Private::Private()
: _applicationConnection(ConnectionThread::fromApplication(this)) {
_applicationRegistry.create(_applicationConnection);
_applicationRegistry.setup();
connect(
_applicationConnection,
&ConnectionThread::connectionDied,
&_applicationRegistry,
&Registry::destroy);
connect(&_connection, &ConnectionThread::connected, [=] {
LOG(("Successfully connected to Wayland server at socket: %1")
.arg(_connection.socketName()));
_registry.create(&_connection);
_registry.setup();
});
connect(
&_connection,
&ConnectionThread::connectionDied,
&_registry,
&Registry::destroy);
connect(&_registry, &Registry::interfacesAnnounced, [=] {
_interfacesAnnounced = true;
if (_interfacesLoop.isRunning()) {
_interfacesLoop.quit();
}
});
connect(
&_applicationRegistry,
&Registry::exporterUnstableV2Announced,
[=](uint name, uint version) {
_xdgExporter = std::unique_ptr<XdgExporter>{
_applicationRegistry.createXdgExporter(name, version),
};
connect(
_applicationConnection,
&ConnectionThread::connectionDied,
_xdgExporter.get(),
&XdgExporter::destroy);
});
connect(
&_applicationRegistry,
&Registry::plasmaShellAnnounced,
[=](uint name, uint version) {
_plasmaShell = std::unique_ptr<PlasmaShell>{
_applicationRegistry.createPlasmaShell(name, version),
};
connect(
_applicationConnection,
&ConnectionThread::connectionDied,
_plasmaShell.get(),
&PlasmaShell::destroy);
});
connect(
&_applicationRegistry,
&Registry::appMenuAnnounced,
[=](uint name, uint version) {
_appMenuManager = std::unique_ptr<AppMenuManager>{
_applicationRegistry.createAppMenuManager(name, version),
};
connect(
_applicationConnection,
&ConnectionThread::connectionDied,
_appMenuManager.get(),
&AppMenuManager::destroy);
});
_connection.initConnection();
}
WaylandIntegration::WaylandIntegration()
: _private(std::make_unique<Private>()) {
_private->connection = std::unique_ptr<ConnectionThread>{
ConnectionThread::fromApplication(),
};
_private->registry.create(_private->connection.get());
_private->registry.setup();
QObject::connect(
_private->connection.get(),
&ConnectionThread::connectionDied,
&_private->registry,
&Registry::destroy);
QObject::connect(
&_private->registry,
&Registry::exporterUnstableV2Announced,
[=](uint name, uint version) {
_private->xdgExporter = std::unique_ptr<XdgExporter>{
_private->registry.createXdgExporter(name, version),
};
QObject::connect(
_private->connection.get(),
&ConnectionThread::connectionDied,
_private->xdgExporter.get(),
&XdgExporter::destroy);
});
QObject::connect(
&_private->registry,
&Registry::plasmaShellAnnounced,
[=](uint name, uint version) {
_private->plasmaShell = std::unique_ptr<PlasmaShell>{
_private->registry.createPlasmaShell(name, version),
};
QObject::connect(
_private->connection.get(),
&ConnectionThread::connectionDied,
_private->plasmaShell.get(),
&PlasmaShell::destroy);
});
QObject::connect(
&_private->registry,
&Registry::appMenuAnnounced,
[=](uint name, uint version) {
_private->appMenuManager = std::unique_ptr<AppMenuManager>{
_private->registry.createAppMenuManager(name, version),
};
QObject::connect(
_private->connection.get(),
&ConnectionThread::connectionDied,
_private->appMenuManager.get(),
&AppMenuManager::destroy);
});
}
WaylandIntegration::~WaylandIntegration() = default;
@@ -153,20 +98,8 @@ WaylandIntegration *WaylandIntegration::Instance() {
return &instance;
}
void WaylandIntegration::waitForInterfaceAnnounce() {
Expects(!_private->interfacesLoop().isRunning());
if (!_private->interfacesAnnounced()) {
_private->interfacesLoop().exec();
}
}
bool WaylandIntegration::supportsXdgDecoration() {
return _private->registry().hasInterface(
Registry::Interface::XdgDecorationUnstableV1);
}
QString WaylandIntegration::nativeHandle(QWindow *window) {
if (const auto exporter = _private->xdgExporter()) {
if (const auto exporter = _private->xdgExporter.get()) {
if (const auto surface = Surface::fromWindow(window)) {
if (const auto exported = exporter->exportTopLevel(
surface,
@@ -186,11 +119,11 @@ QString WaylandIntegration::nativeHandle(QWindow *window) {
}
bool WaylandIntegration::skipTaskbarSupported() {
return _private->plasmaShell();
return _private->plasmaShell != nullptr;
}
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
const auto shell = _private->plasmaShell();
const auto shell = _private->plasmaShell.get();
if (!shell) {
return;
}
@@ -212,7 +145,7 @@ void WaylandIntegration::registerAppMenu(
QWindow *window,
const QString &serviceName,
const QString &objectPath) {
const auto manager = _private->appMenuManager();
const auto manager = _private->appMenuManager.get();
if (!manager) {
return;
}

View File

@@ -13,8 +13,7 @@ namespace internal {
class WaylandIntegration {
public:
[[nodiscard]] static WaylandIntegration *Instance();
void waitForInterfaceAnnounce();
[[nodiscard]] bool supportsXdgDecoration();
[[nodiscard]] QString nativeHandle(QWindow *window);
[[nodiscard]] bool skipTaskbarSupported();
void skipTaskbar(QWindow *window, bool skip);
@@ -27,7 +26,7 @@ private:
WaylandIntegration();
~WaylandIntegration();
class Private;
struct Private;
const std::unique_ptr<Private> _private;
};

View File

@@ -12,7 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Platform {
namespace internal {
class WaylandIntegration::Private {
struct WaylandIntegration::Private {
};
WaylandIntegration::WaylandIntegration() {
@@ -26,13 +26,6 @@ WaylandIntegration *WaylandIntegration::Instance() {
return &instance;
}
void WaylandIntegration::waitForInterfaceAnnounce() {
}
bool WaylandIntegration::supportsXdgDecoration() {
return false;
}
QString WaylandIntegration::nativeHandle(QWindow *window) {
return {};
}

View File

@@ -971,7 +971,6 @@ void MainWindow::workmodeUpdated(Core::Settings::WorkMode mode) {
}
void MainWindow::unreadCounterChangedHook() {
setWindowTitle(titleText());
updateIconCounters();
}

View File

@@ -11,6 +11,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "base/platform/base_platform_info.h"
#include "base/platform/linux/base_linux_glibmm_helper.h"
#include "base/platform/linux/base_linux_gtk_integration.h"
#include "ui/platform/linux/ui_linux_wayland_integration.h"
#include "platform/linux/linux_desktop_environment.h"
#include "platform/linux/linux_gtk_integration.h"
#include "platform/linux/linux_wayland_integration.h"
@@ -60,6 +61,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
using namespace Platform;
using BaseGtkIntegration = base::Platform::GtkIntegration;
using UiWaylandIntegration = Ui::Platform::WaylandIntegration;
using Platform::internal::WaylandIntegration;
using Platform::internal::GtkIntegration;
@@ -799,7 +801,7 @@ void start() {
}
// wait for interface announce to know if native window frame is supported
if (const auto integration = WaylandIntegration::Instance()) {
if (const auto integration = UiWaylandIntegration::Instance()) {
integration->waitForInterfaceAnnounce();
}

View File

@@ -1,47 +0,0 @@
/*
This file is part of Telegram Desktop,
the official desktop application for the Telegram messaging service.
For license and copyright information please follow this link:
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#pragma once
#include "platform/platform_window_title.h"
#include "platform/linux/linux_wayland_integration.h"
#include "base/object_ptr.h"
namespace Window {
namespace Theme {
int DefaultPreviewTitleHeight();
void DefaultPreviewWindowFramePaint(QImage &preview, const style::palette &palette, QRect body, int outerWidth);
} // namespace Theme
} // namespace Window
namespace Platform {
inline bool AllowNativeWindowFrameToggle() {
const auto waylandIntegration = internal::WaylandIntegration::Instance();
return !waylandIntegration
|| waylandIntegration->supportsXdgDecoration();
}
inline object_ptr<Window::TitleWidget> CreateTitleWidget(QWidget *parent) {
return object_ptr<Window::TitleWidgetQt>(parent);
}
inline bool NativeTitleRequiresShadow() {
return false;
}
inline int PreviewTitleHeight() {
return Window::Theme::DefaultPreviewTitleHeight();
}
inline void PreviewWindowFramePaint(QImage &preview, const style::palette &palette, QRect body, int outerWidth) {
return Window::Theme::DefaultPreviewWindowFramePaint(preview, palette, body, outerWidth);
}
} // namespace Platform