Use gtk integration from lib_base
This commit is contained in:
parent
9d57ba47b0
commit
0b74c396cb
5 changed files with 74 additions and 62 deletions
|
|
@ -101,6 +101,7 @@ PRIVATE
|
|||
ui/platform/ui_platform_window_title.h
|
||||
ui/platform/ui_platform_window.cpp
|
||||
ui/platform/ui_platform_window.h
|
||||
ui/platform/ui_platform_utility.cpp
|
||||
ui/platform/ui_platform_utility.h
|
||||
ui/style/style_core.cpp
|
||||
ui/style/style_core.h
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@
|
|||
|
||||
#include "ui/ui_log.h"
|
||||
#include "base/platform/base_platform_info.h"
|
||||
#include "base/platform/linux/base_xcb_utilities_linux.h"
|
||||
#include "base/platform/linux/base_linux_xcb_utilities.h"
|
||||
#include "base/platform/linux/base_linux_gtk_integration.h"
|
||||
#include "ui/platform/linux/ui_linux_wayland_integration.h"
|
||||
#include "base/const_string.h"
|
||||
#include "base/qt_adapters.h"
|
||||
|
|
@ -20,13 +21,6 @@
|
|||
#include <QtWidgets/QApplication>
|
||||
#include <qpa/qplatformnativeinterface.h>
|
||||
|
||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
#include <QtDBus/QDBusConnection>
|
||||
#include <QtDBus/QDBusMessage>
|
||||
#include <QtDBus/QDBusReply>
|
||||
#include <QtDBus/QDBusVariant>
|
||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
|
||||
Q_DECLARE_METATYPE(QMargins);
|
||||
|
||||
namespace Ui {
|
||||
|
|
@ -152,56 +146,6 @@ TitleControls::Control GtkKeywordToTitleControl(const QString &keyword) {
|
|||
return TitleControls::Control::Unknown;
|
||||
}
|
||||
|
||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
std::optional<TitleControls::Layout> PortalTitleControlsLayout() {
|
||||
auto message = QDBusMessage::createMethodCall(
|
||||
kXDGDesktopPortalService.utf16(),
|
||||
kXDGDesktopPortalObjectPath.utf16(),
|
||||
kSettingsPortalInterface.utf16(),
|
||||
"Read");
|
||||
|
||||
message.setArguments({
|
||||
"org.gnome.desktop.wm.preferences",
|
||||
"button-layout"
|
||||
});
|
||||
|
||||
const QDBusReply<QVariant> reply = QDBusConnection::sessionBus().call(
|
||||
message);
|
||||
|
||||
if (!reply.isValid() || !reply.value().canConvert<QDBusVariant>()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto valueVariant = qvariant_cast<QDBusVariant>(
|
||||
reply.value()).variant();
|
||||
|
||||
if (!valueVariant.canConvert<QString>()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto valueBySides = valueVariant.toString().split(':');
|
||||
|
||||
std::vector<TitleControls::Control> controlsLeft;
|
||||
ranges::transform(
|
||||
valueBySides[0].split(','),
|
||||
ranges::back_inserter(controlsLeft),
|
||||
GtkKeywordToTitleControl);
|
||||
|
||||
std::vector<TitleControls::Control> controlsRight;
|
||||
if (valueBySides.size() > 1) {
|
||||
ranges::transform(
|
||||
valueBySides[1].split(','),
|
||||
ranges::back_inserter(controlsRight),
|
||||
GtkKeywordToTitleControl);
|
||||
}
|
||||
|
||||
return TitleControls::Layout{
|
||||
.left = controlsLeft,
|
||||
.right = controlsRight
|
||||
};
|
||||
}
|
||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
|
||||
} // namespace
|
||||
|
||||
bool IsApplicationActive() {
|
||||
|
|
@ -286,11 +230,44 @@ bool ShowWindowMenu(QWindow *window) {
|
|||
}
|
||||
|
||||
TitleControls::Layout TitleControlsLayout() {
|
||||
#ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
if (const auto portalLayout = PortalTitleControlsLayout()) {
|
||||
return *portalLayout;
|
||||
const auto gtkResult = []() -> std::optional<TitleControls::Layout> {
|
||||
const auto integration = base::Platform::GtkIntegration::Instance();
|
||||
if (!integration || !integration->checkVersion(3, 12, 0)) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto decorationLayoutSetting = integration->getStringSetting(
|
||||
"gtk-decoration-layout");
|
||||
|
||||
if (!decorationLayoutSetting.has_value()) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto decorationLayout = decorationLayoutSetting->split(':');
|
||||
|
||||
std::vector<TitleControls::Control> controlsLeft;
|
||||
ranges::transform(
|
||||
decorationLayout[0].split(','),
|
||||
ranges::back_inserter(controlsLeft),
|
||||
GtkKeywordToTitleControl);
|
||||
|
||||
std::vector<TitleControls::Control> controlsRight;
|
||||
if (decorationLayout.size() > 1) {
|
||||
ranges::transform(
|
||||
decorationLayout[1].split(','),
|
||||
ranges::back_inserter(controlsRight),
|
||||
GtkKeywordToTitleControl);
|
||||
}
|
||||
|
||||
return TitleControls::Layout{
|
||||
.left = controlsLeft,
|
||||
.right = controlsRight
|
||||
};
|
||||
}();
|
||||
|
||||
if (gtkResult.has_value()) {
|
||||
return *gtkResult;
|
||||
}
|
||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
|
||||
return TitleControls::Layout{
|
||||
.right = {
|
||||
|
|
|
|||
26
ui/platform/ui_platform_utility.cpp
Normal file
26
ui/platform/ui_platform_utility.cpp
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
// This file is part of Desktop App Toolkit,
|
||||
// a set of libraries for developing nice desktop applications.
|
||||
//
|
||||
// For license and copyright information please follow this link:
|
||||
// https://github.com/desktop-app/legal/blob/master/LEGAL
|
||||
//
|
||||
#include "ui/platform/ui_platform_utility.h"
|
||||
|
||||
namespace Ui {
|
||||
namespace Platform {
|
||||
namespace {
|
||||
|
||||
rpl::event_stream<> TitleControlsLayoutChanges;
|
||||
|
||||
} // namespace
|
||||
|
||||
rpl::producer<> TitleControlsLayoutChanged() {
|
||||
return TitleControlsLayoutChanges.events();
|
||||
}
|
||||
|
||||
void NotifyTitleControlsLayoutChanged() {
|
||||
TitleControlsLayoutChanges.fire({});
|
||||
}
|
||||
|
||||
} // namespace Platform
|
||||
} // namespace Ui
|
||||
|
|
@ -36,7 +36,10 @@ void DrainMainQueue(); // Needed only if UseMainQueueGeneric() is false.
|
|||
bool SetWindowExtents(QWindow *window, const QMargins &extents);
|
||||
bool UnsetWindowExtents(QWindow *window);
|
||||
bool ShowWindowMenu(QWindow *window);
|
||||
|
||||
[[nodiscard]] TitleControls::Layout TitleControlsLayout();
|
||||
[[nodiscard]] rpl::producer<> TitleControlsLayoutChanged();
|
||||
void NotifyTitleControlsLayoutChanged();
|
||||
|
||||
} // namespace Platform
|
||||
} // namespace Ui
|
||||
|
|
|
|||
|
|
@ -117,6 +117,11 @@ void TitleControls::init(Fn<void(bool maximized)> maximize) {
|
|||
updateControlsPosition();
|
||||
}, _close->lifetime());
|
||||
|
||||
TitleControlsLayoutChanged(
|
||||
) | rpl::start_with_next([=] {
|
||||
updateControlsPosition();
|
||||
}, _close->lifetime());
|
||||
|
||||
const auto winIdEventFilter = std::make_shared<QObject*>(nullptr);
|
||||
*winIdEventFilter = base::install_event_filter(
|
||||
window(),
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue