mirror of
https://github.com/kotatogram/kotatogram-desktop
synced 2025-09-01 23:25:15 +00:00
Use new methods from lib_ui
This commit is contained in:
@@ -41,8 +41,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||
#include <QtDBus/QDBusError>
|
||||
#endif // !DESKTOP_APP_DISABLE_DBUS_INTEGRATION
|
||||
|
||||
#include <xcb/xcb.h>
|
||||
|
||||
#include <glib.h>
|
||||
|
||||
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<internal::NotificationServiceWatcher> 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<const char*>(&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<const char*>(&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>{
|
||||
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<QMargins>(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<Window::ControlsLayout> {
|
||||
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<Window::Control> controlsLeft;
|
||||
ranges::transform(
|
||||
decorationLayout[0].split(','),
|
||||
ranges::back_inserter(controlsLeft),
|
||||
GtkKeywordToWindowControl);
|
||||
|
||||
std::vector<Window::Control> 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() {
|
||||
|
Reference in New Issue
Block a user