chore: no longer rely on qpa x11 platform
This commit is contained in:
@@ -32,7 +32,7 @@ using Util = tray::Util;
|
|||||||
|
|
||||||
FdoSelectionManager::FdoSelectionManager()
|
FdoSelectionManager::FdoSelectionManager()
|
||||||
: QObject()
|
: QObject()
|
||||||
, m_selectionOwner(new KSelectionOwner(Util::instance()->getAtomFromDisplay("_NET_SYSTEM_TRAY"), -1, this))
|
, m_selectionOwner(new KSelectionOwner(UTIL->getAtomFromDisplay("_NET_SYSTEM_TRAY"), UTIL->getX11Connection(), UTIL->getRootWindow(), this))
|
||||||
{
|
{
|
||||||
qDebug(SNIPROXY) << "starting";
|
qDebug(SNIPROXY) << "starting";
|
||||||
|
|
||||||
|
|||||||
9
main.cpp
9
main.cpp
@@ -10,6 +10,7 @@
|
|||||||
#include "fdoselectionmanager.h"
|
#include "fdoselectionmanager.h"
|
||||||
|
|
||||||
#include "debug.h"
|
#include "debug.h"
|
||||||
|
#include "util.h"
|
||||||
|
|
||||||
#ifdef None
|
#ifdef None
|
||||||
#ifndef FIXX11H_None
|
#ifndef FIXX11H_None
|
||||||
@@ -25,18 +26,22 @@ inline constexpr XID None = XNone;
|
|||||||
|
|
||||||
#include <KWindowSystem>
|
#include <KWindowSystem>
|
||||||
|
|
||||||
|
using Util = tray::Util;
|
||||||
|
|
||||||
int main(int argc, char **argv)
|
int main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
// the whole point of this is to interact with X, if we are in any other session, force trying to connect to X
|
// the whole point of this is to interact with X, if we are in any other session, force trying to connect to X
|
||||||
// if the QPA can't load xcb, this app is useless anyway.
|
// if the QPA can't load xcb, this app is useless anyway.
|
||||||
qputenv("QT_QPA_PLATFORM", "xcb");
|
qputenv("QT_QPA_PLATFORM", "wayland");
|
||||||
|
qputenv("WAYLAND_DISPLAY", "dockplugin");
|
||||||
|
qputenv("QT_WAYLAND_SHELL_INTEGRATION", "plugin-shell");
|
||||||
|
|
||||||
QGuiApplication::setDesktopSettingsAware(false);
|
QGuiApplication::setDesktopSettingsAware(false);
|
||||||
QCoreApplication::setAttribute(Qt::AA_DisableSessionManager);
|
QCoreApplication::setAttribute(Qt::AA_DisableSessionManager);
|
||||||
|
|
||||||
QGuiApplication app(argc, argv);
|
QGuiApplication app(argc, argv);
|
||||||
|
|
||||||
if (!KWindowSystem::isPlatformX11()) {
|
if (!UTIL->isXAvaliable()) {
|
||||||
qFatal("xembed-traymanager-proxy requires X11. Aborting");
|
qFatal("xembed-traymanager-proxy requires X11. Aborting");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
43
util.cpp
43
util.cpp
@@ -4,6 +4,8 @@
|
|||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
|
#include "debug.h"
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "xcbthread.h"
|
#include "xcbthread.h"
|
||||||
|
|
||||||
@@ -12,6 +14,9 @@
|
|||||||
#include <QBitmap>
|
#include <QBitmap>
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QtGlobal>
|
#include <QtGlobal>
|
||||||
|
#include <QSocketNotifier>
|
||||||
|
#include <QCoreApplication>
|
||||||
|
#include <QAbstractEventDispatcher>
|
||||||
|
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
|
|
||||||
@@ -37,7 +42,29 @@ Util* Util::instance()
|
|||||||
return _instance;
|
return _instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Util::dispatchEvents(DispatchEventsMode mode)
|
||||||
|
{
|
||||||
|
xcb_connection_t *connection = m_x11connection;
|
||||||
|
if (!connection) {
|
||||||
|
qCWarning(SNIPROXY, "Attempting to dispatch X11 events with no connection");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto pollEventFunc = mode == DispatchEventsMode::Poll ? xcb_poll_for_event : xcb_poll_for_queued_event;
|
||||||
|
|
||||||
|
while (xcb_generic_event_t *event = pollEventFunc(connection)) {
|
||||||
|
qintptr result = 0;
|
||||||
|
|
||||||
|
QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher();
|
||||||
|
dispatcher->filterNativeEvent(QByteArrayLiteral("xcb_generic_event_t"), event, &result);
|
||||||
|
free(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
xcb_flush(connection);
|
||||||
|
}
|
||||||
|
|
||||||
Util::Util()
|
Util::Util()
|
||||||
|
: QObject()
|
||||||
{
|
{
|
||||||
m_x11connection = xcb_connect(nullptr, nullptr);
|
m_x11connection = xcb_connect(nullptr, nullptr);
|
||||||
m_display = XOpenDisplay("");
|
m_display = XOpenDisplay("");
|
||||||
@@ -51,8 +78,20 @@ Util::Util()
|
|||||||
m_rootWindow = screen->root;
|
m_rootWindow = screen->root;
|
||||||
|
|
||||||
xcb_ewmh_init_atoms_replies(&m_ewmh, xcb_ewmh_init_atoms(m_x11connection, &m_ewmh), nullptr);
|
xcb_ewmh_init_atoms_replies(&m_ewmh, xcb_ewmh_init_atoms(m_x11connection, &m_ewmh), nullptr);
|
||||||
m_xcbThread = new XcbThread(m_x11connection);
|
|
||||||
m_xcbThread->start();
|
const int fd = xcb_get_file_descriptor(m_x11connection);
|
||||||
|
QSocketNotifier * qfd = new QSocketNotifier(fd, QSocketNotifier::Read, this);
|
||||||
|
connect(qfd, &QSocketNotifier::activated, this, [this](){
|
||||||
|
dispatchEvents(DispatchEventsMode::Poll);
|
||||||
|
});
|
||||||
|
|
||||||
|
QAbstractEventDispatcher *dispatcher = QCoreApplication::eventDispatcher();
|
||||||
|
connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, this, [this]() {
|
||||||
|
dispatchEvents(DispatchEventsMode::EventQueue);
|
||||||
|
});
|
||||||
|
connect(dispatcher, &QAbstractEventDispatcher::awake, this, [this]() {
|
||||||
|
dispatchEvents(DispatchEventsMode::EventQueue);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
Util::~Util()
|
Util::~Util()
|
||||||
|
|||||||
9
util.h
9
util.h
@@ -8,6 +8,7 @@
|
|||||||
#include <QImage>
|
#include <QImage>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
#include <QObject>
|
||||||
|
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
@@ -21,7 +22,7 @@ struct _XDisplay;
|
|||||||
namespace tray {
|
namespace tray {
|
||||||
#define UTIL Util::instance()
|
#define UTIL Util::instance()
|
||||||
class XcbThread;
|
class XcbThread;
|
||||||
class Util
|
class Util : public QObject
|
||||||
{
|
{
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@@ -59,6 +60,12 @@ private:
|
|||||||
Util(const Util&) = delete;
|
Util(const Util&) = delete;
|
||||||
Util& operator=(const Util&) = delete;
|
Util& operator=(const Util&) = delete;
|
||||||
|
|
||||||
|
enum class DispatchEventsMode {
|
||||||
|
Poll,
|
||||||
|
EventQueue
|
||||||
|
};
|
||||||
|
void dispatchEvents(DispatchEventsMode mode);
|
||||||
|
|
||||||
bool isTransparentImage(const QImage &image);
|
bool isTransparentImage(const QImage &image);
|
||||||
|
|
||||||
QImage convertFromNative(xcb_image_t* image);
|
QImage convertFromNative(xcb_image_t* image);
|
||||||
|
|||||||
Reference in New Issue
Block a user