use trayloader utils

This commit is contained in:
2025-12-24 16:35:31 +08:00
parent b8f5165fc4
commit b0df2b9e27
5 changed files with 11 additions and 135 deletions

View File

@@ -21,7 +21,7 @@
#include <xcb/xcb_event.h>
#include "traymanager1.h"
#include "xcbutils.h"
#include "c_ptr.h"
#include "util.h"
using Util = tray::Util;
@@ -32,7 +32,7 @@ using Util = tray::Util;
FdoSelectionManager::FdoSelectionManager()
: QObject()
, m_selectionOwner(new KSelectionOwner(Xcb::atoms->selectionAtom, -1, this))
, m_selectionOwner(new KSelectionOwner(Util::instance()->getAtomFromDisplay("_NET_SYSTEM_TRAY"), -1, this))
{
qDebug(SNIPROXY) << "starting";
@@ -116,7 +116,7 @@ bool FdoSelectionManager::nativeEventFilter(const QByteArray &eventType, void *m
const auto responseType = XCB_EVENT_RESPONSE_TYPE(ev);
if (responseType == XCB_CLIENT_MESSAGE) {
const auto ce = reinterpret_cast<xcb_client_message_event_t *>(ev);
if (ce->type == Xcb::atoms->opcodeAtom) {
if (ce->type == UTIL->getAtomByName("_NET_SYSTEM_TRAY_OPCODE")) {
switch (ce->data.data32[1]) {
case SYSTEM_TRAY_REQUEST_DOCK:
dock(ce->data.data32[2]);
@@ -232,7 +232,7 @@ void FdoSelectionManager::setSystemTrayVisual()
}
}
xcb_change_property(c, XCB_PROP_MODE_REPLACE, m_selectionOwner->ownerWindow(), Xcb::atoms->visualAtom, XCB_ATOM_VISUALID, 32, 1, &trayVisual);
xcb_change_property(c, XCB_PROP_MODE_REPLACE, m_selectionOwner->ownerWindow(), UTIL->getAtomByName("_NET_SYSTEM_TRAY_VISUAL"), XCB_ATOM_VISUALID, 32, 1, &trayVisual);
}
void FdoSelectionManager::initTrayManager()

View File

@@ -10,7 +10,6 @@
#include "fdoselectionmanager.h"
#include "debug.h"
#include "xcbutils.h"
#ifdef None
#ifndef FIXX11H_None
@@ -26,11 +25,6 @@ inline constexpr XID None = XNone;
#include <KWindowSystem>
namespace Xcb
{
Xcb::Atoms *atoms;
}
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
@@ -48,12 +42,9 @@ int main(int argc, char **argv)
app.setQuitOnLastWindowClosed(false);
Xcb::atoms = new Xcb::Atoms();
FdoSelectionManager manager;
auto rc = app.exec();
delete Xcb::atoms;
return rc;
}

View File

@@ -18,6 +18,7 @@
#include <mutex>
#include <xcb/res.h>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
#include <xcb/xtest.h>
#include <xcb/xproto.h>
#include <xcb/composite.h>
@@ -143,6 +144,11 @@ QString Util::getNameByAtom(const xcb_atom_t& atom)
return name;
}
xcb_atom_t Util::getAtomFromDisplay(const char * name)
{
return getAtomByName(xcb_atom_name_by_screen(name, DefaultScreen(getDisplay())));
}
void Util::moveX11Window(const xcb_window_t& window, const uint32_t& x, const uint32_t& y)
{
const uint32_t windowMoveConfigVals[2] = {x, y};

1
util.h
View File

@@ -34,6 +34,7 @@ public:
xcb_atom_t getAtomByName(const QString& name);
QString getNameByAtom(const xcb_atom_t& atom);
xcb_atom_t getAtomFromDisplay(const char * name);
void moveX11Window(const xcb_window_t& window, const uint32_t& x, const uint32_t& y);
void setX11WindowSize(const xcb_window_t& window, const QSize& size);

View File

@@ -1,122 +0,0 @@
/*
SPDX-FileCopyrightText: 2012, 2013 Martin Graesslin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2015 David Edmudson <davidedmundson@kde.org>
SPDX-License-Identifier: GPL-2.0-or-later
*/
#pragma once
#include <xcb/composite.h>
#include <xcb/damage.h>
#include <xcb/randr.h>
#include <xcb/shm.h>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_event.h>
#include <QGuiApplication>
#include <QList>
#include "c_ptr.h"
#include <X11/Xlib.h>
/** XEMBED messages */
#define XEMBED_EMBEDDED_NOTIFY 0
#define XEMBED_WINDOW_ACTIVATE 1
#define XEMBED_WINDOW_DEACTIVATE 2
#define XEMBED_REQUEST_FOCUS 3
#define XEMBED_FOCUS_IN 4
#define XEMBED_FOCUS_OUT 5
#define XEMBED_FOCUS_NEXT 6
#define XEMBED_FOCUS_PREV 7
namespace Xcb
{
typedef xcb_window_t WindowId;
class Atom
{
public:
explicit Atom(const QByteArray &name,
bool onlyIfExists = false,
xcb_connection_t *c = qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->connection())
: m_connection(c)
, m_retrieved(false)
, m_cookie(xcb_intern_atom_unchecked(m_connection, onlyIfExists, name.length(), name.constData()))
, m_atom(XCB_ATOM_NONE)
, m_name(name)
{
}
Atom() = delete;
Atom(const Atom &) = delete;
~Atom()
{
if (!m_retrieved && m_cookie.sequence) {
xcb_discard_reply(m_connection, m_cookie.sequence);
}
}
operator xcb_atom_t() const
{
(const_cast<Atom *>(this))->getReply();
return m_atom;
}
bool isValid()
{
getReply();
return m_atom != XCB_ATOM_NONE;
}
bool isValid() const
{
(const_cast<Atom *>(this))->getReply();
return m_atom != XCB_ATOM_NONE;
}
inline const QByteArray &name() const
{
return m_name;
}
private:
void getReply()
{
if (m_retrieved || !m_cookie.sequence) {
return;
}
UniqueCPointer<xcb_intern_atom_reply_t> reply(xcb_intern_atom_reply(m_connection, m_cookie, nullptr));
if (reply) {
m_atom = reply->atom;
}
m_retrieved = true;
}
xcb_connection_t *m_connection;
bool m_retrieved;
xcb_intern_atom_cookie_t m_cookie;
xcb_atom_t m_atom;
QByteArray m_name;
};
class Atoms
{
public:
Atoms()
: xembedAtom("_XEMBED")
, selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", DefaultScreen(qGuiApp->nativeInterface<QNativeInterface::QX11Application>()->display())))
, opcodeAtom("_NET_SYSTEM_TRAY_OPCODE")
, messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA")
, visualAtom("_NET_SYSTEM_TRAY_VISUAL")
{
}
Atom xembedAtom;
Atom selectionAtom;
Atom opcodeAtom;
Atom messageData;
Atom visualAtom;
};
extern Atoms *atoms;
} // namespace Xcb