From 15d18077b812a0ef72e4192e3807f80f0b6fddf7 Mon Sep 17 00:00:00 2001 From: Ilya Fedin Date: Fri, 19 Feb 2021 08:26:46 +0400 Subject: [PATCH] Use new methods from lib_ui --- Telegram/CMakeLists.txt | 14 - Telegram/SourceFiles/core/application.cpp | 3 - Telegram/SourceFiles/core/core_settings.h | 14 - Telegram/SourceFiles/mainwindow.cpp | 4 +- .../SourceFiles/media/view/media_view_pip.cpp | 13 +- .../platform/linux/linux_gtk_integration.cpp | 11 - .../linux/linux_wayland_integration.cpp | 96 +----- .../linux/linux_wayland_integration.h | 3 - .../linux/linux_wayland_integration_dummy.cpp | 12 - .../platform/linux/specific_linux.cpp | 308 ------------------ .../platform/linux/window_title_linux.cpp | 39 --- .../platform/linux/window_title_linux.h | 12 +- .../SourceFiles/platform/mac/specific_mac.h | 24 -- .../SourceFiles/platform/mac/specific_mac.mm | 10 - .../SourceFiles/platform/platform_specific.h | 9 - .../SourceFiles/platform/win/specific_win.cpp | 22 -- .../SourceFiles/platform/win/specific_win.h | 20 -- .../SourceFiles/ui/widgets/separate_panel.cpp | 6 - Telegram/SourceFiles/window/main_window.cpp | 2 +- .../window/window_controls_layout.h | 24 -- .../SourceFiles/window/window_title_qt.cpp | 49 +-- Telegram/SourceFiles/window/window_title_qt.h | 6 +- 22 files changed, 31 insertions(+), 670 deletions(-) delete mode 100644 Telegram/SourceFiles/platform/linux/window_title_linux.cpp delete mode 100644 Telegram/SourceFiles/window/window_controls_layout.h diff --git a/Telegram/CMakeLists.txt b/Telegram/CMakeLists.txt index 600e9e37b..b14b0aafa 100644 --- a/Telegram/CMakeLists.txt +++ b/Telegram/CMakeLists.txt @@ -92,18 +92,6 @@ if (LINUX) ) endif() - if (DESKTOP_APP_USE_PACKAGED - AND NOT DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION - AND Qt5WaylandClient_VERSION VERSION_LESS 5.13.0) - find_package(PkgConfig REQUIRED) - pkg_check_modules(WAYLAND_CLIENT REQUIRED wayland-client) - - target_include_directories(Telegram - PRIVATE - ${WAYLAND_CLIENT_INCLUDE_DIRS} - ) - endif() - if (NOT DESKTOP_APP_DISABLE_GTK_INTEGRATION) find_package(PkgConfig REQUIRED) @@ -852,7 +840,6 @@ PRIVATE platform/linux/notifications_manager_linux.h platform/linux/specific_linux.cpp platform/linux/specific_linux.h - platform/linux/window_title_linux.cpp platform/linux/window_title_linux.h platform/mac/file_utilities_mac.mm platform/mac/file_utilities_mac.h @@ -1057,7 +1044,6 @@ PRIVATE window/window_connecting_widget.h window/window_controller.cpp window/window_controller.h - window/window_controls_layout.h window/window_filters_menu.cpp window/window_filters_menu.h window/window_history_hider.cpp diff --git a/Telegram/SourceFiles/core/application.cpp b/Telegram/SourceFiles/core/application.cpp index 2990e596f..3b5d6fb98 100644 --- a/Telegram/SourceFiles/core/application.cpp +++ b/Telegram/SourceFiles/core/application.cpp @@ -21,7 +21,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "core/local_url_handlers.h" #include "core/launcher.h" #include "core/ui_integration.h" -#include "core/core_settings.h" #include "chat_helpers/emoji_keywords.h" #include "chat_helpers/stickers_emoji_image_loader.h" #include "base/platform/base_platform_info.h" @@ -212,8 +211,6 @@ void Application::run() { return; } - Core::App().settings().setWindowControlsLayout(Platform::WindowControlsLayout()); - _translator = std::make_unique(); QCoreApplication::instance()->installTranslator(_translator.get()); diff --git a/Telegram/SourceFiles/core/core_settings.h b/Telegram/SourceFiles/core/core_settings.h index 76320ad9e..732f75b2f 100644 --- a/Telegram/SourceFiles/core/core_settings.h +++ b/Telegram/SourceFiles/core/core_settings.h @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "window/themes/window_themes_embedded.h" -#include "window/window_controls_layout.h" #include "ui/chat/attach/attach_send_files_way.h" #include "platform/platform_notifications_manager.h" @@ -503,18 +502,6 @@ public: [[nodiscard]] rpl::producer systemDarkModeEnabledChanges() const { return _systemDarkModeEnabled.changes(); } - void setWindowControlsLayout(Window::ControlsLayout value) { - _windowControlsLayout = value; - } - [[nodiscard]] Window::ControlsLayout windowControlsLayout() const { - return _windowControlsLayout.current(); - } - [[nodiscard]] rpl::producer windowControlsLayoutValue() const { - return _windowControlsLayout.value(); - } - [[nodiscard]] rpl::producer windowControlsLayoutChanges() const { - return _windowControlsLayout.changes(); - } [[nodiscard]] const WindowPosition &windowPosition() const { return _windowPosition; } @@ -602,7 +589,6 @@ private: rpl::variable _nativeWindowFrame = false; rpl::variable> _systemDarkMode = std::nullopt; rpl::variable _systemDarkModeEnabled = false; - rpl::variable _windowControlsLayout; WindowPosition _windowPosition; // per-window bool _tabbedReplacedWithInfo = false; // per-window diff --git a/Telegram/SourceFiles/mainwindow.cpp b/Telegram/SourceFiles/mainwindow.cpp index fdeaa0af8..39c2a4fd0 100644 --- a/Telegram/SourceFiles/mainwindow.cpp +++ b/Telegram/SourceFiles/mainwindow.cpp @@ -38,9 +38,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "apiwrap.h" #include "api/api_updates.h" #include "settings/settings_intro.h" -#include "platform/platform_specific.h" #include "platform/platform_notifications_manager.h" #include "base/platform/base_platform_info.h" +#include "ui/platform/ui_platform_utility.h" #include "base/call_delayed.h" #include "window/notifications_manager.h" #include "window/themes/window_theme.h" @@ -111,7 +111,7 @@ MainWindow::MainWindow(not_null controller) setAttribute(Qt::WA_NoSystemBackground); - if (Platform::WindowsNeedShadow()) { + if (Ui::Platform::WindowExtentsSupported()) { setAttribute(Qt::WA_TranslucentBackground); } else { setAttribute(Qt::WA_OpaquePaintEvent); diff --git a/Telegram/SourceFiles/media/view/media_view_pip.cpp b/Telegram/SourceFiles/media/view/media_view_pip.cpp index 83e716456..695bc639b 100644 --- a/Telegram/SourceFiles/media/view/media_view_pip.cpp +++ b/Telegram/SourceFiles/media/view/media_view_pip.cpp @@ -20,7 +20,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "main/main_account.h" #include "main/main_session.h" #include "core/application.h" -#include "platform/platform_specific.h" #include "base/platform/base_platform_info.h" #include "ui/platform/ui_platform_utility.h" #include "ui/widgets/buttons.h" @@ -724,17 +723,9 @@ void PipPanel::startSystemDrag() { const auto stateEdges = RectPartToQtEdges(*_dragState); if (stateEdges) { - if (!Platform::StartSystemResize(windowHandle(), stateEdges)) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED - windowHandle()->startSystemResize(stateEdges); -#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED - } + windowHandle()->startSystemResize(stateEdges); } else { - if (!Platform::StartSystemMove(windowHandle())) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED - windowHandle()->startSystemMove(); -#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED - } + windowHandle()->startSystemMove(); } } diff --git a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp index 75b2cd18e..4aa024d56 100644 --- a/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_gtk_integration.cpp @@ -71,13 +71,6 @@ void DarkModeChanged() { }); } -void DecorationLayoutChanged() { - Core::Sandbox::Instance().customEnterFromEventLoop([] { - Core::App().settings().setWindowControlsLayout( - WindowControlsLayout()); - }); -} - } // namespace GtkIntegration::GtkIntegration() { @@ -182,10 +175,6 @@ void GtkIntegration::load() { } if (BaseGtkIntegration::Instance()->checkVersion(3, 12, 0)) { - BaseGtkIntegration::Instance()->connectToSetting( - "gtk-decoration-layout", - DecorationLayoutChanged); - BaseGtkIntegration::Instance()->connectToSetting( "gtk-decoration-layout", Ui::Platform::NotifyTitleControlsLayoutChanged); diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp index baefa943b..a3ff42761 100644 --- a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.cpp @@ -9,52 +9,14 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" -#include - -#include -#include -#include - #include #include -#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED -#include -#endif // Qt < 5.13 && !DESKTOP_APP_QT_PATCHED - -using QtWaylandClient::QWaylandWindow; using namespace KWayland::Client; namespace Platform { namespace internal { -namespace { - -#if QT_VERSION < QT_VERSION_CHECK(5, 13, 0) && !defined DESKTOP_APP_QT_PATCHED -enum wl_shell_surface_resize WlResizeFromEdges(Qt::Edges edges) { - if (edges == (Qt::TopEdge | Qt::LeftEdge)) - return WL_SHELL_SURFACE_RESIZE_TOP_LEFT; - if (edges == Qt::TopEdge) - return WL_SHELL_SURFACE_RESIZE_TOP; - if (edges == (Qt::TopEdge | Qt::RightEdge)) - return WL_SHELL_SURFACE_RESIZE_TOP_RIGHT; - if (edges == Qt::RightEdge) - return WL_SHELL_SURFACE_RESIZE_RIGHT; - if (edges == (Qt::RightEdge | Qt::BottomEdge)) - return WL_SHELL_SURFACE_RESIZE_BOTTOM_RIGHT; - if (edges == Qt::BottomEdge) - return WL_SHELL_SURFACE_RESIZE_BOTTOM; - if (edges == (Qt::BottomEdge | Qt::LeftEdge)) - return WL_SHELL_SURFACE_RESIZE_BOTTOM_LEFT; - if (edges == Qt::LeftEdge) - return WL_SHELL_SURFACE_RESIZE_LEFT; - - return WL_SHELL_SURFACE_RESIZE_NONE; -} -#endif // Qt < 5.13 && !DESKTOP_APP_QT_PATCHED - -} // namespace - class WaylandIntegration::Private : public QObject { public: Private(); @@ -95,7 +57,9 @@ WaylandIntegration::Private::Private() { connect(&_registry, &Registry::interfacesAnnounced, [=] { _interfacesAnnounced = true; - _interfacesLoop.quit(); + if (_interfacesLoop.isRunning()) { + _interfacesLoop.quit(); + } }); _connection.initConnection(); @@ -114,6 +78,7 @@ WaylandIntegration *WaylandIntegration::Instance() { } void WaylandIntegration::waitForInterfaceAnnounce() { + Expects(!_private->interfacesLoop().isRunning()); if (!_private->interfacesAnnounced()) { _private->interfacesLoop().exec(); } @@ -124,58 +89,5 @@ bool WaylandIntegration::supportsXdgDecoration() { Registry::Interface::XdgDecorationUnstableV1); } -bool WaylandIntegration::startMove(QWindow *window) { - // There are startSystemMove on Qt 5.15 -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) && !defined DESKTOP_APP_QT_PATCHED - if (const auto waylandWindow = static_cast( - window->handle())) { - if (const auto seat = waylandWindow->display()->lastInputDevice()) { - if (const auto shellSurface = waylandWindow->shellSurface()) { - return shellSurface->move(seat); - } - } - } -#endif // Qt < 5.15 && !DESKTOP_APP_QT_PATCHED - - return false; -} - -bool WaylandIntegration::startResize(QWindow *window, Qt::Edges edges) { - // There are startSystemResize on Qt 5.15 -#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0) && !defined DESKTOP_APP_QT_PATCHED - if (const auto waylandWindow = static_cast( - window->handle())) { - if (const auto seat = waylandWindow->display()->lastInputDevice()) { - if (const auto shellSurface = waylandWindow->shellSurface()) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) - shellSurface->resize(seat, edges); - return true; -#else // Qt >= 5.13 - shellSurface->resize(seat, WlResizeFromEdges(edges)); - return true; -#endif // Qt < 5.13 - } - } - } -#endif // Qt < 5.15 && !DESKTOP_APP_QT_PATCHED - - return false; -} - -bool WaylandIntegration::showWindowMenu(QWindow *window) { -#if QT_VERSION >= QT_VERSION_CHECK(5, 13, 0) || defined DESKTOP_APP_QT_PATCHED - if (const auto waylandWindow = static_cast( - window->handle())) { - if (const auto seat = waylandWindow->display()->lastInputDevice()) { - if (const auto shellSurface = waylandWindow->shellSurface()) { - return shellSurface->showWindowMenu(seat); - } - } - } -#endif // Qt >= 5.13 || DESKTOP_APP_QT_PATCHED - - return false; -} - } // namespace internal } // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h index a6e582042..3a8705c08 100644 --- a/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration.h @@ -17,9 +17,6 @@ public: static WaylandIntegration *Instance(); void waitForInterfaceAnnounce(); bool supportsXdgDecoration(); - bool startMove(QWindow *window); - bool startResize(QWindow *window, Qt::Edges edges); - bool showWindowMenu(QWindow *window); private: WaylandIntegration(); diff --git a/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp b/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp index 7a5b52e96..166e8b575 100644 --- a/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp +++ b/Telegram/SourceFiles/platform/linux/linux_wayland_integration_dummy.cpp @@ -33,17 +33,5 @@ bool WaylandIntegration::supportsXdgDecoration() { return false; } -bool WaylandIntegration::startMove(QWindow *window) { - return false; -} - -bool WaylandIntegration::startResize(QWindow *window, Qt::Edges edges) { - return false; -} - -bool WaylandIntegration::showWindowMenu(QWindow *window) { - return false; -} - } // namespace internal } // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/specific_linux.cpp b/Telegram/SourceFiles/platform/linux/specific_linux.cpp index 6fab06580..566bb1d40 100644 --- a/Telegram/SourceFiles/platform/linux/specific_linux.cpp +++ b/Telegram/SourceFiles/platform/linux/specific_linux.cpp @@ -41,8 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION -#include - #include extern "C" { @@ -78,8 +76,6 @@ constexpr auto kXDGDesktopPortalService = "org.freedesktop.portal.Desktop"_cs; constexpr auto kXDGDesktopPortalObjectPath = "/org/freedesktop/portal/desktop"_cs; constexpr auto kPropertiesInterface = "org.freedesktop.DBus.Properties"_cs; -constexpr auto kXCBFrameExtentsAtomName = "_GTK_FRAME_EXTENTS"_cs; - #ifndef DESKTOP_APP_DISABLE_DBUS_INTEGRATION std::unique_ptr NSWInstance; @@ -351,187 +347,6 @@ bool GenerateDesktopFile( } } -uint XCBMoveResizeFromEdges(Qt::Edges edges) { - if (edges == (Qt::TopEdge | Qt::LeftEdge)) - return 0; - if (edges == Qt::TopEdge) - return 1; - if (edges == (Qt::TopEdge | Qt::RightEdge)) - return 2; - if (edges == Qt::RightEdge) - return 3; - if (edges == (Qt::RightEdge | Qt::BottomEdge)) - return 4; - if (edges == Qt::BottomEdge) - return 5; - if (edges == (Qt::BottomEdge | Qt::LeftEdge)) - return 6; - if (edges == Qt::LeftEdge) - return 7; - - return 0; -} - -bool StartXCBMoveResize(QWindow *window, int edges) { - const auto connection = base::Platform::XCB::GetConnectionFromQt(); - if (!connection) { - return false; - } - - const auto root = base::Platform::XCB::GetRootWindowFromQt(); - if (!root.has_value()) { - return false; - } - - const auto moveResizeAtom = base::Platform::XCB::GetAtom( - connection, - "_NET_WM_MOVERESIZE"); - - if (!moveResizeAtom.has_value()) { - return false; - } - - const auto globalPos = QCursor::pos(); - - xcb_client_message_event_t xev; - xev.response_type = XCB_CLIENT_MESSAGE; - xev.type = *moveResizeAtom; - xev.sequence = 0; - xev.window = window->winId(); - xev.format = 32; - xev.data.data32[0] = globalPos.x(); - xev.data.data32[1] = globalPos.y(); - xev.data.data32[2] = (edges == 16) - ? 8 // move - : XCBMoveResizeFromEdges(Qt::Edges(edges)); - xev.data.data32[3] = XCB_BUTTON_INDEX_1; - xev.data.data32[4] = 0; - - xcb_ungrab_pointer(connection, XCB_CURRENT_TIME); - xcb_send_event( - connection, - false, - *root, - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT - | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY, - reinterpret_cast(&xev)); - - return true; -} - -bool ShowXCBWindowMenu(QWindow *window) { - const auto connection = base::Platform::XCB::GetConnectionFromQt(); - if (!connection) { - return false; - } - - const auto root = base::Platform::XCB::GetRootWindowFromQt(); - if (!root.has_value()) { - return false; - } - - const auto showWindowMenuAtom = base::Platform::XCB::GetAtom( - connection, - "_GTK_SHOW_WINDOW_MENU"); - - if (!showWindowMenuAtom.has_value()) { - return false; - } - - const auto globalPos = QCursor::pos(); - - xcb_client_message_event_t xev; - xev.response_type = XCB_CLIENT_MESSAGE; - xev.type = *showWindowMenuAtom; - xev.sequence = 0; - xev.window = window->winId(); - xev.format = 32; - xev.data.data32[0] = 0; - xev.data.data32[1] = globalPos.x(); - xev.data.data32[2] = globalPos.y(); - xev.data.data32[3] = 0; - xev.data.data32[4] = 0; - - xcb_ungrab_pointer(connection, XCB_CURRENT_TIME); - xcb_send_event( - connection, - false, - *root, - XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT - | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY, - reinterpret_cast(&xev)); - - return true; -} - -bool SetXCBFrameExtents(QWindow *window, const QMargins &extents) { - const auto connection = base::Platform::XCB::GetConnectionFromQt(); - if (!connection) { - return false; - } - - const auto frameExtentsAtom = base::Platform::XCB::GetAtom( - connection, - kXCBFrameExtentsAtomName.utf16()); - - if (!frameExtentsAtom.has_value()) { - return false; - } - - const auto extentsVector = std::vector{ - uint(extents.left()), - uint(extents.right()), - uint(extents.top()), - uint(extents.bottom()), - }; - - xcb_change_property( - connection, - XCB_PROP_MODE_REPLACE, - window->winId(), - *frameExtentsAtom, - XCB_ATOM_CARDINAL, - 32, - extentsVector.size(), - extentsVector.data()); - - return true; -} - -bool UnsetXCBFrameExtents(QWindow *window) { - const auto connection = base::Platform::XCB::GetConnectionFromQt(); - if (!connection) { - return false; - } - - const auto frameExtentsAtom = base::Platform::XCB::GetAtom( - connection, - kXCBFrameExtentsAtomName.utf16()); - - if (!frameExtentsAtom.has_value()) { - return false; - } - - xcb_delete_property( - connection, - window->winId(), - *frameExtentsAtom); - - return true; -} - -Window::Control GtkKeywordToWindowControl(const QString &keyword) { - if (keyword == qstr("minimize")) { - return Window::Control::Minimize; - } else if (keyword == qstr("maximize")) { - return Window::Control::Maximize; - } else if (keyword == qstr("close")) { - return Window::Control::Close; - } - - return Window::Control::Unknown; -} - } // namespace void SetWatchingMediaKeys(bool watching) { @@ -741,129 +556,6 @@ bool SkipTaskbarSupported() { && base::Platform::XCB::IsSupportedByWM("_NET_WM_STATE_SKIP_TASKBAR"); } -bool StartSystemMove(QWindow *window) { - if (const auto integration = WaylandIntegration::Instance()) { - return integration->startMove(window); - } else { - return StartXCBMoveResize(window, 16); - } -} - -bool StartSystemResize(QWindow *window, Qt::Edges edges) { - if (const auto integration = WaylandIntegration::Instance()) { - return integration->startResize(window, edges); - } else { - return StartXCBMoveResize(window, edges); - } -} - -bool ShowWindowMenu(QWindow *window) { - if (const auto integration = WaylandIntegration::Instance()) { - return integration->showWindowMenu(window); - } else { - return ShowXCBWindowMenu(window); - } -} - -bool SetWindowExtents(QWindow *window, const QMargins &extents) { - if (IsWayland()) { -#ifdef DESKTOP_APP_QT_PATCHED - window->setProperty("WaylandCustomMargins", QVariant::fromValue(extents)); - return true; -#else // DESKTOP_APP_QT_PATCHED - return false; -#endif // !DESKTOP_APP_QT_PATCHED - } else { - return SetXCBFrameExtents(window, extents); - } -} - -bool UnsetWindowExtents(QWindow *window) { - if (IsWayland()) { -#ifdef DESKTOP_APP_QT_PATCHED - window->setProperty("WaylandCustomMargins", QVariant()); - return true; -#else // DESKTOP_APP_QT_PATCHED - return false; -#endif // !DESKTOP_APP_QT_PATCHED - } else { - return UnsetXCBFrameExtents(window); - } -} - -bool WindowsNeedShadow() { -#ifdef DESKTOP_APP_QT_PATCHED - if (IsWayland()) { - return true; - } -#endif // DESKTOP_APP_QT_PATCHED - - namespace XCB = base::Platform::XCB; - if (!IsWayland() - && XCB::IsSupportedByWM(kXCBFrameExtentsAtomName.utf16())) { - return true; - } - - return false; -} - -Window::ControlsLayout WindowControlsLayout() { - const auto gtkResult = []() -> std::optional { - const auto integration = BaseGtkIntegration::Instance(); - if (!integration || !integration->checkVersion(3, 12, 0)) { - return std::nullopt; - } - - const auto decorationLayoutSetting = integration->getStringSetting( - qsl("gtk-decoration-layout")); - - if (!decorationLayoutSetting.has_value()) { - return std::nullopt; - } - - const auto decorationLayout = decorationLayoutSetting->split(':'); - - std::vector controlsLeft; - ranges::transform( - decorationLayout[0].split(','), - ranges::back_inserter(controlsLeft), - GtkKeywordToWindowControl); - - std::vector controlsRight; - if (decorationLayout.size() > 1) { - ranges::transform( - decorationLayout[1].split(','), - ranges::back_inserter(controlsRight), - GtkKeywordToWindowControl); - } - - return Window::ControlsLayout{ - .left = controlsLeft, - .right = controlsRight - }; - }(); - - if (gtkResult.has_value()) { - return *gtkResult; - } else if (DesktopEnvironment::IsUnity()) { - return Window::ControlsLayout{ - .left = { - Window::Control::Close, - Window::Control::Minimize, - Window::Control::Maximize, - } - }; - } else { - return Window::ControlsLayout{ - .right = { - Window::Control::Minimize, - Window::Control::Maximize, - Window::Control::Close, - } - }; - } -} - } // namespace Platform QRect psDesktopRect() { diff --git a/Telegram/SourceFiles/platform/linux/window_title_linux.cpp b/Telegram/SourceFiles/platform/linux/window_title_linux.cpp deleted file mode 100644 index bd990755c..000000000 --- a/Telegram/SourceFiles/platform/linux/window_title_linux.cpp +++ /dev/null @@ -1,39 +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 -*/ -#include "platform/linux/window_title_linux.h" - -#include "platform/linux/linux_wayland_integration.h" -#include "base/platform/base_platform_info.h" - -namespace Platform { -namespace { - -bool SystemMoveResizeSupported() { -#if !defined DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION || QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED - return true; -#else // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION || Qt >= 5.15 || DESKTOP_APP_QT_PATCHED - return !IsWayland(); -#endif // !DESKTOP_APP_DISABLE_WAYLAND_INTEGRATION || Qt >= 5.15 || DESKTOP_APP_QT_PATCHED -} - -} // namespace - -bool AllowNativeWindowFrameToggle() { - const auto waylandIntegration = internal::WaylandIntegration::Instance(); - return SystemMoveResizeSupported() - && (!waylandIntegration - || waylandIntegration->supportsXdgDecoration()); -} - -object_ptr CreateTitleWidget(QWidget *parent) { - return SystemMoveResizeSupported() - ? object_ptr(parent) - : object_ptr{ nullptr }; -} - -} // namespace Platform diff --git a/Telegram/SourceFiles/platform/linux/window_title_linux.h b/Telegram/SourceFiles/platform/linux/window_title_linux.h index c493976c2..3bfebc236 100644 --- a/Telegram/SourceFiles/platform/linux/window_title_linux.h +++ b/Telegram/SourceFiles/platform/linux/window_title_linux.h @@ -8,6 +8,7 @@ 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 { @@ -21,8 +22,15 @@ void DefaultPreviewWindowFramePaint(QImage &preview, const style::palette &palet namespace Platform { -bool AllowNativeWindowFrameToggle(); -object_ptr CreateTitleWidget(QWidget *parent); +inline bool AllowNativeWindowFrameToggle() { + const auto waylandIntegration = internal::WaylandIntegration::Instance(); + return !waylandIntegration + || waylandIntegration->supportsXdgDecoration(); +} + +inline object_ptr CreateTitleWidget(QWidget *parent) { + return object_ptr(parent); +} inline bool NativeTitleRequiresShadow() { return false; diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.h b/Telegram/SourceFiles/platform/mac/specific_mac.h index 00b0bb44c..9c91e2c32 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.h +++ b/Telegram/SourceFiles/platform/mac/specific_mac.h @@ -22,18 +22,6 @@ inline QImage GetImageFromClipboard() { return {}; } -inline bool StartSystemMove(QWindow *window) { - return false; -} - -inline bool StartSystemResize(QWindow *window, Qt::Edges edges) { - return false; -} - -inline bool ShowWindowMenu(QWindow *window) { - return false; -} - inline bool AutostartSupported() { return false; } @@ -46,18 +34,6 @@ inline bool SkipTaskbarSupported() { return false; } -inline bool SetWindowExtents(QWindow *window, const QMargins &extents) { - return false; -} - -inline bool UnsetWindowExtents(QWindow *window) { - return false; -} - -inline bool WindowsNeedShadow() { - return false; -} - namespace ThirdParty { inline void start() { diff --git a/Telegram/SourceFiles/platform/mac/specific_mac.mm b/Telegram/SourceFiles/platform/mac/specific_mac.mm index 162629e89..a08342d87 100644 --- a/Telegram/SourceFiles/platform/mac/specific_mac.mm +++ b/Telegram/SourceFiles/platform/mac/specific_mac.mm @@ -203,16 +203,6 @@ void IgnoreApplicationActivationRightNow() { objc_ignoreApplicationActivationRightNow(); } -Window::ControlsLayout WindowControlsLayout() { - return Window::ControlsLayout{ - .left = { - Window::Control::Close, - Window::Control::Minimize, - Window::Control::Maximize, - } - }; -} - } // namespace Platform void psNewVersion() { diff --git a/Telegram/SourceFiles/platform/platform_specific.h b/Telegram/SourceFiles/platform/platform_specific.h index 45fafaefa..d0bfb84dc 100644 --- a/Telegram/SourceFiles/platform/platform_specific.h +++ b/Telegram/SourceFiles/platform/platform_specific.h @@ -7,8 +7,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #pragma once -#include "window/window_controls_layout.h" - namespace Platform { void start(); @@ -42,13 +40,6 @@ bool AutostartSupported(); bool TrayIconSupported(); bool SkipTaskbarSupported(); QImage GetImageFromClipboard(); -bool StartSystemMove(QWindow *window); -bool StartSystemResize(QWindow *window, Qt::Edges edges); -bool ShowWindowMenu(QWindow *window); -bool WindowsNeedShadow(); -bool SetWindowExtents(QWindow *window, const QMargins &extents); -bool UnsetWindowExtents(QWindow *window); -Window::ControlsLayout WindowControlsLayout(); [[nodiscard]] std::optional IsDarkMode(); [[nodiscard]] inline bool IsDarkModeSupported() { diff --git a/Telegram/SourceFiles/platform/win/specific_win.cpp b/Telegram/SourceFiles/platform/win/specific_win.cpp index cec77bfa6..6e015b378 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.cpp +++ b/Telegram/SourceFiles/platform/win/specific_win.cpp @@ -312,28 +312,6 @@ bool AutostartSupported() { return !IsWindowsStoreBuild(); } -bool ShowWindowMenu(QWindow *window) { - const auto pos = QCursor::pos(); - - SendMessage( - HWND(window->winId()), - WM_SYSCOMMAND, - SC_MOUSEMENU, - MAKELPARAM(pos.x(), pos.y())); - - return true; -} - -Window::ControlsLayout WindowControlsLayout() { - return Window::ControlsLayout{ - .right = { - Window::Control::Minimize, - Window::Control::Maximize, - Window::Control::Close, - } - }; -} - } // namespace Platform namespace { diff --git a/Telegram/SourceFiles/platform/win/specific_win.h b/Telegram/SourceFiles/platform/win/specific_win.h index c5fa006a5..4ef32a72c 100644 --- a/Telegram/SourceFiles/platform/win/specific_win.h +++ b/Telegram/SourceFiles/platform/win/specific_win.h @@ -26,14 +26,6 @@ inline QImage GetImageFromClipboard() { return {}; } -inline bool StartSystemMove(QWindow *window) { - return false; -} - -inline bool StartSystemResize(QWindow *window, Qt::Edges edges) { - return false; -} - inline bool TrayIconSupported() { return true; } @@ -42,18 +34,6 @@ inline bool SkipTaskbarSupported() { return true; } -inline bool SetWindowExtents(QWindow *window, const QMargins &extents) { - return false; -} - -inline bool UnsetWindowExtents(QWindow *window) { - return false; -} - -inline bool WindowsNeedShadow() { - return false; -} - namespace ThirdParty { void start(); diff --git a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp index d2caed510..799405a79 100644 --- a/Telegram/SourceFiles/ui/widgets/separate_panel.cpp +++ b/Telegram/SourceFiles/ui/widgets/separate_panel.cpp @@ -8,7 +8,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/separate_panel.h" #include "window/main_window.h" -#include "platform/platform_specific.h" #include "ui/widgets/shadow.h" #include "ui/widgets/buttons.h" #include "ui/widgets/labels.h" @@ -554,14 +553,9 @@ void SeparatePanel::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) { if (dragArea.contains(e->pos())) { const auto dragViaSystem = [&] { - if (::Platform::StartSystemMove(windowHandle())) { - return true; - } -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED if (windowHandle()->startSystemMove()) { return true; } -#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED return false; }(); if (!dragViaSystem) { diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index 6ed2698c3..ccd0d047a 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -346,7 +346,7 @@ HitTestResult MainWindow::hitTest(const QPoint &p) const { bool MainWindow::hasShadow() const { const auto center = geometry().center(); - return Platform::WindowsNeedShadow() + return Ui::Platform::WindowExtentsSupported() && Ui::Platform::TranslucentWindowsSupported(center) && _title; } diff --git a/Telegram/SourceFiles/window/window_controls_layout.h b/Telegram/SourceFiles/window/window_controls_layout.h deleted file mode 100644 index cb8c47bd7..000000000 --- a/Telegram/SourceFiles/window/window_controls_layout.h +++ /dev/null @@ -1,24 +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 - -namespace Window { - -enum class Control { - Unknown, - Minimize, - Maximize, - Close, -}; - -struct ControlsLayout { - std::vector left; - std::vector right; -}; - -} // namespace Window diff --git a/Telegram/SourceFiles/window/window_title_qt.cpp b/Telegram/SourceFiles/window/window_title_qt.cpp index 558e0d14e..4815dc082 100644 --- a/Telegram/SourceFiles/window/window_title_qt.cpp +++ b/Telegram/SourceFiles/window/window_title_qt.cpp @@ -7,12 +7,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL */ #include "window/window_title_qt.h" -#include "platform/platform_specific.h" #include "ui/platform/ui_platform_utility.h" #include "ui/widgets/buttons.h" #include "ui/widgets/shadow.h" -#include "core/core_settings.h" -#include "core/application.h" #include "styles/style_widgets.h" #include "styles/style_window.h" @@ -66,7 +63,7 @@ TitleWidgetQt::TitleWidgetQt(QWidget *parent) }); _close->setPointerCursor(false); - Core::App().settings().windowControlsLayoutChanges( + Ui::Platform::TitleControlsLayoutChanged( ) | rpl::start_with_next([=] { updateControlsPosition(); }, lifetime()); @@ -94,7 +91,7 @@ TitleWidgetQt::~TitleWidgetQt() { } if (_extentsSet) { - Platform::UnsetWindowExtents(window()->windowHandle()); + Ui::Platform::UnsetWindowExtents(window()->windowHandle()); } } @@ -116,7 +113,7 @@ void TitleWidgetQt::init() { bool TitleWidgetQt::hasShadow() const { const auto center = window()->geometry().center(); - return Platform::WindowsNeedShadow() + return Ui::Platform::WindowExtentsSupported() && Ui::Platform::TranslucentWindowsSupported(center); } @@ -145,19 +142,19 @@ void TitleWidgetQt::toggleFramelessWindow(bool enabled) { void TitleWidgetQt::updateWindowExtents() { if (hasShadow()) { - Platform::SetWindowExtents( + Ui::Platform::SetWindowExtents( window()->windowHandle(), resizeArea() * cIntRetinaFactor()); _extentsSet = true; } else if (_extentsSet) { - Platform::UnsetWindowExtents(window()->windowHandle()); + Ui::Platform::UnsetWindowExtents(window()->windowHandle()); _extentsSet = false; } } void TitleWidgetQt::updateControlsPosition() { - const auto controlsLayout = Core::App().settings().windowControlsLayout(); + const auto controlsLayout = Ui::Platform::TitleControlsLayout(); const auto controlsLeft = controlsLayout.left; const auto controlsRight = controlsLayout.right; @@ -223,7 +220,7 @@ void TitleWidgetQt::mousePressEvent(QMouseEvent *e) { if (e->button() == Qt::LeftButton) { _mousePressed = true; } else if (e->button() == Qt::RightButton) { - Platform::ShowWindowMenu(window()->windowHandle()); + Ui::Platform::ShowWindowMenu(window()->windowHandle()); } } @@ -235,7 +232,7 @@ void TitleWidgetQt::mouseReleaseEvent(QMouseEvent *e) { void TitleWidgetQt::mouseMoveEvent(QMouseEvent *e) { if (_mousePressed) { - startMove(); + window()->windowHandle()->startSystemMove(); } } @@ -264,7 +261,7 @@ bool TitleWidgetQt::eventFilter(QObject *obj, QEvent *e) { if (e->type() == QEvent::MouseButtonPress && mouseEvent->button() == Qt::LeftButton && edges) { - return startResize(edges); + return window()->windowHandle()->startSystemResize(edges); } } } else if (e->type() == QEvent::Leave) { @@ -413,32 +410,4 @@ void TitleWidgetQt::restoreCursor() { } } -bool TitleWidgetQt::startMove() { - if (Platform::StartSystemMove(window()->windowHandle())) { - return true; - } - -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED - if (window()->windowHandle()->startSystemMove()) { - return true; - } -#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED - - return false; -} - -bool TitleWidgetQt::startResize(Qt::Edges edges) { - if (Platform::StartSystemResize(window()->windowHandle(), edges)) { - return true; - } - -#if QT_VERSION >= QT_VERSION_CHECK(5, 15, 0) || defined DESKTOP_APP_QT_PATCHED - if (window()->windowHandle()->startSystemResize(edges)) { - return true; - } -#endif // Qt >= 5.15 || DESKTOP_APP_QT_PATCHED - - return false; -} - } // namespace Window diff --git a/Telegram/SourceFiles/window/window_title_qt.h b/Telegram/SourceFiles/window/window_title_qt.h index 9bed67470..4767f045b 100644 --- a/Telegram/SourceFiles/window/window_title_qt.h +++ b/Telegram/SourceFiles/window/window_title_qt.h @@ -8,7 +8,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #pragma once #include "window/window_title.h" -#include "window/window_controls_layout.h" +#include "ui/platform/ui_platform_window_title.h" #include "base/object_ptr.h" namespace style { @@ -24,6 +24,8 @@ namespace Window { class TitleWidgetQt : public TitleWidget { public: + using Control = Ui::Platform::TitleControls::Control; + TitleWidgetQt(QWidget *parent); ~TitleWidgetQt(); @@ -56,8 +58,6 @@ private: Qt::Edges edgesFromPos(const QPoint &pos) const; void updateCursor(Qt::Edges edges); void restoreCursor(); - bool startMove(); - bool startResize(Qt::Edges edges); const style::WindowTitle &_st; object_ptr _minimize;