mirror of
https://github.com/AyuGram/AyuGramDesktop.git
synced 2025-06-05 06:33:57 +02:00
Implement taskbar icon hidding on Wayland with org_kde_plasma_shell protocol
This commit is contained in:
parent
166c28c215
commit
434ef34378
5 changed files with 76 additions and 14 deletions
|
@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
#include <registry.h>
|
#include <registry.h>
|
||||||
#include <surface.h>
|
#include <surface.h>
|
||||||
#include <xdgforeign.h>
|
#include <xdgforeign.h>
|
||||||
|
#include <plasmashell.h>
|
||||||
|
|
||||||
using namespace KWayland::Client;
|
using namespace KWayland::Client;
|
||||||
|
|
||||||
|
@ -31,6 +32,10 @@ public:
|
||||||
return _xdgExporter.get();
|
return _xdgExporter.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] PlasmaShell *plasmaShell() {
|
||||||
|
return _plasmaShell.get();
|
||||||
|
}
|
||||||
|
|
||||||
[[nodiscard]] QEventLoop &interfacesLoop() {
|
[[nodiscard]] QEventLoop &interfacesLoop() {
|
||||||
return _interfacesLoop;
|
return _interfacesLoop;
|
||||||
}
|
}
|
||||||
|
@ -45,6 +50,7 @@ private:
|
||||||
Registry _registry;
|
Registry _registry;
|
||||||
Registry _applicationRegistry;
|
Registry _applicationRegistry;
|
||||||
std::unique_ptr<XdgExporter> _xdgExporter;
|
std::unique_ptr<XdgExporter> _xdgExporter;
|
||||||
|
std::unique_ptr<PlasmaShell> _plasmaShell;
|
||||||
QEventLoop _interfacesLoop;
|
QEventLoop _interfacesLoop;
|
||||||
bool _interfacesAnnounced = false;
|
bool _interfacesAnnounced = false;
|
||||||
};
|
};
|
||||||
|
@ -96,6 +102,21 @@ WaylandIntegration::Private::Private()
|
||||||
&XdgExporter::destroy);
|
&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);
|
||||||
|
});
|
||||||
|
|
||||||
_connection.initConnection();
|
_connection.initConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -143,5 +164,28 @@ QString WaylandIntegration::nativeHandle(QWindow *window) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WaylandIntegration::skipTaskbarSupported() {
|
||||||
|
return _private->plasmaShell();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
||||||
|
const auto shell = _private->plasmaShell();
|
||||||
|
if (!shell) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto surface = Surface::fromWindow(window);
|
||||||
|
if (!surface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto plasmaSurface = shell->createSurface(surface, surface);
|
||||||
|
if (!plasmaSurface) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
plasmaSurface->setSkipTaskbar(skip);
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -16,6 +16,8 @@ public:
|
||||||
void waitForInterfaceAnnounce();
|
void waitForInterfaceAnnounce();
|
||||||
bool supportsXdgDecoration();
|
bool supportsXdgDecoration();
|
||||||
QString nativeHandle(QWindow *window);
|
QString nativeHandle(QWindow *window);
|
||||||
|
bool skipTaskbarSupported();
|
||||||
|
void skipTaskbar(QWindow *window, bool skip);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
WaylandIntegration();
|
WaylandIntegration();
|
||||||
|
|
|
@ -37,5 +37,12 @@ QString WaylandIntegration::nativeHandle(QWindow *window) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool WaylandIntegration::skipTaskbarSupported() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WaylandIntegration::skipTaskbar(QWindow *window, bool skip) {
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace internal
|
} // namespace internal
|
||||||
} // namespace Platform
|
} // namespace Platform
|
||||||
|
|
|
@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
|
|
||||||
#include "styles/style_window.h"
|
#include "styles/style_window.h"
|
||||||
#include "platform/linux/specific_linux.h"
|
#include "platform/linux/specific_linux.h"
|
||||||
|
#include "platform/linux/linux_wayland_integration.h"
|
||||||
#include "history/history.h"
|
#include "history/history.h"
|
||||||
#include "history/history_widget.h"
|
#include "history/history_widget.h"
|
||||||
#include "history/history_inner_widget.h"
|
#include "history/history_inner_widget.h"
|
||||||
|
@ -59,6 +60,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
||||||
namespace Platform {
|
namespace Platform {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
|
using internal::WaylandIntegration;
|
||||||
|
|
||||||
constexpr auto kPanelTrayIconName = "telegram-panel"_cs;
|
constexpr auto kPanelTrayIconName = "telegram-panel"_cs;
|
||||||
constexpr auto kMutePanelTrayIconName = "telegram-mute-panel"_cs;
|
constexpr auto kMutePanelTrayIconName = "telegram-mute-panel"_cs;
|
||||||
constexpr auto kAttentionPanelTrayIconName = "telegram-attention-panel"_cs;
|
constexpr auto kAttentionPanelTrayIconName = "telegram-attention-panel"_cs;
|
||||||
|
@ -83,15 +86,15 @@ QIcon TrayIcon;
|
||||||
QString TrayIconThemeName, TrayIconName;
|
QString TrayIconThemeName, TrayIconName;
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
bool XCBSkipTaskbar(QWindow *window, bool set) {
|
void XCBSkipTaskbar(QWindow *window, bool skip) {
|
||||||
const auto connection = base::Platform::XCB::GetConnectionFromQt();
|
const auto connection = base::Platform::XCB::GetConnectionFromQt();
|
||||||
if (!connection) {
|
if (!connection) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto root = base::Platform::XCB::GetRootWindowFromQt();
|
const auto root = base::Platform::XCB::GetRootWindowFromQt();
|
||||||
if (!root.has_value()) {
|
if (!root.has_value()) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto stateAtom = base::Platform::XCB::GetAtom(
|
const auto stateAtom = base::Platform::XCB::GetAtom(
|
||||||
|
@ -99,7 +102,7 @@ bool XCBSkipTaskbar(QWindow *window, bool set) {
|
||||||
"_NET_WM_STATE");
|
"_NET_WM_STATE");
|
||||||
|
|
||||||
if (!stateAtom.has_value()) {
|
if (!stateAtom.has_value()) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const auto skipTaskbarAtom = base::Platform::XCB::GetAtom(
|
const auto skipTaskbarAtom = base::Platform::XCB::GetAtom(
|
||||||
|
@ -107,7 +110,7 @@ bool XCBSkipTaskbar(QWindow *window, bool set) {
|
||||||
"_NET_WM_STATE_SKIP_TASKBAR");
|
"_NET_WM_STATE_SKIP_TASKBAR");
|
||||||
|
|
||||||
if (!skipTaskbarAtom.has_value()) {
|
if (!skipTaskbarAtom.has_value()) {
|
||||||
return false;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
xcb_client_message_event_t xev;
|
xcb_client_message_event_t xev;
|
||||||
|
@ -116,7 +119,7 @@ bool XCBSkipTaskbar(QWindow *window, bool set) {
|
||||||
xev.sequence = 0;
|
xev.sequence = 0;
|
||||||
xev.window = window->winId();
|
xev.window = window->winId();
|
||||||
xev.format = 32;
|
xev.format = 32;
|
||||||
xev.data.data32[0] = set ? 1 : 0;
|
xev.data.data32[0] = skip ? 1 : 0;
|
||||||
xev.data.data32[1] = *skipTaskbarAtom;
|
xev.data.data32[1] = *skipTaskbarAtom;
|
||||||
xev.data.data32[2] = 0;
|
xev.data.data32[2] = 0;
|
||||||
xev.data.data32[3] = 0;
|
xev.data.data32[3] = 0;
|
||||||
|
@ -129,19 +132,19 @@ bool XCBSkipTaskbar(QWindow *window, bool set) {
|
||||||
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT
|
||||||
| XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
|
| XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY,
|
||||||
reinterpret_cast<const char*>(&xev));
|
reinterpret_cast<const char*>(&xev));
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
|
||||||
bool SkipTaskbar(QWindow *window, bool set) {
|
void SkipTaskbar(QWindow *window, bool skip) {
|
||||||
|
if (const auto integration = WaylandIntegration::Instance()) {
|
||||||
|
integration->skipTaskbar(window, skip);
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
if (IsX11()) {
|
if (IsX11()) {
|
||||||
return XCBSkipTaskbar(window, set);
|
XCBSkipTaskbar(window, skip);
|
||||||
}
|
}
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString GetPanelIconName(int counter, bool muted) {
|
QString GetPanelIconName(int counter, bool muted) {
|
||||||
|
|
|
@ -644,9 +644,15 @@ bool TrayIconSupported() {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkipTaskbarSupported() {
|
bool SkipTaskbarSupported() {
|
||||||
|
if (const auto integration = WaylandIntegration::Instance()) {
|
||||||
|
return integration->skipTaskbarSupported();
|
||||||
|
}
|
||||||
|
|
||||||
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#ifndef DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
return IsX11()
|
if (IsX11()) {
|
||||||
&& base::Platform::XCB::IsSupportedByWM("_NET_WM_STATE_SKIP_TASKBAR");
|
return base::Platform::XCB::IsSupportedByWM(
|
||||||
|
"_NET_WM_STATE_SKIP_TASKBAR");
|
||||||
|
}
|
||||||
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
#endif // !DESKTOP_APP_DISABLE_X11_INTEGRATION
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
|
|
Loading…
Add table
Reference in a new issue