Move Window::wmClientLeader to X11Window

This commit is contained in:
Vlad Zahorodnii 2023-03-29 12:49:28 +03:00
parent e403c5bf63
commit d35f88adee
5 changed files with 75 additions and 74 deletions

View file

@ -8,8 +8,8 @@
*/
#include "activities.h"
// KWin
#include "window.h"
#include "workspace.h"
#include "x11window.h"
// KDE
#include <KConfigGroup>
// Qt
@ -175,13 +175,14 @@ void Activities::reallyStop(const QString &id)
QSet<QByteArray> dontCloseSessionIds;
const auto windows = ws->windows();
for (auto *const window : windows) {
if (!window->isClient()) {
auto x11Window = qobject_cast<X11Window *>(window);
if (!window || window->isUnmanaged()) {
continue;
}
if (window->isDesktop()) {
continue;
}
const QByteArray sessionId = window->sessionId();
const QByteArray sessionId = x11Window->sessionId();
if (sessionId.isEmpty()) {
continue; // TODO support old wm_command apps too?
}

View file

@ -70,7 +70,6 @@ Window::Window()
, m_internalId(QUuid::createUuid())
, m_client()
, m_clientMachine(new ClientMachine(this))
, m_wmClientLeader(XCB_WINDOW_NONE)
, m_skipCloseAnimation(false)
, m_colorScheme(QStringLiteral("kdeglobals"))
, m_moveResizeOutput(workspace()->activeOutput())
@ -174,54 +173,6 @@ QRectF Window::visibleGeometry() const
return QRectF();
}
Xcb::Property Window::fetchWmClientLeader() const
{
return Xcb::Property(false, window(), atoms->wm_client_leader, XCB_ATOM_WINDOW, 0, 10000);
}
void Window::readWmClientLeader(Xcb::Property &prop)
{
m_wmClientLeader = prop.value<xcb_window_t>(window());
}
void Window::getWmClientLeader()
{
auto prop = fetchWmClientLeader();
readWmClientLeader(prop);
}
/**
* Returns sessionId for this window,
* taken either from its window or from the leader window.
*/
QByteArray Window::sessionId() const
{
QByteArray result = Xcb::StringProperty(window(), atoms->sm_client_id);
if (result.isEmpty() && m_wmClientLeader && m_wmClientLeader != window()) {
result = Xcb::StringProperty(m_wmClientLeader, atoms->sm_client_id);
}
return result;
}
/**
* Returns command property for this window,
* taken either from its window or from the leader window.
*/
QString Window::wmCommand()
{
QByteArray result = Xcb::StringProperty(window(), XCB_ATOM_WM_COMMAND);
if (result.isEmpty() && m_wmClientLeader && m_wmClientLeader != window()) {
result = Xcb::StringProperty(m_wmClientLeader, XCB_ATOM_WM_COMMAND);
}
result.replace(0, ' ');
return result;
}
void Window::getWmClientMachine()
{
m_clientMachine->resolve(window(), wmClientLeader());
}
/**
* Returns client machine for this window,
* taken either from its window or from the leader window.
@ -239,18 +190,6 @@ QString Window::wmClientMachine(bool use_localhost) const
return m_clientMachine->hostName();
}
/**
* Returns client leader window for this client.
* Returns the client window itself if no leader window is defined.
*/
xcb_window_t Window::wmClientLeader() const
{
if (m_wmClientLeader != XCB_WINDOW_NONE) {
return m_wmClientLeader;
}
return window();
}
void Window::setResourceClass(const QString &name, const QString &className)
{
resource_name = name;

View file

@ -672,14 +672,11 @@ public:
void setLockScreenOverlay(bool allowed);
virtual QString windowRole() const;
QByteArray sessionId() const;
QString resourceName() const;
QString resourceClass() const;
QString wmCommand();
QString wmClientMachine(bool use_localhost) const;
const ClientMachine *clientMachine() const;
ClientMachine *clientMachine() const;
virtual bool isLocalhost() const;
xcb_window_t wmClientLeader() const;
virtual pid_t pid() const;
static bool resourceMatch(const Window *c1, const Window *c2);
@ -1475,10 +1472,6 @@ Q_SIGNALS:
protected:
void setWindowHandles(xcb_window_t client);
Xcb::Property fetchWmClientLeader() const;
void readWmClientLeader(Xcb::Property &p);
void getWmClientLeader();
void getWmClientMachine();
virtual std::unique_ptr<WindowItem> createItem(Scene *scene) = 0;
@ -1801,7 +1794,6 @@ private:
QString resource_name;
QString resource_class;
ClientMachine *m_clientMachine;
xcb_window_t m_wmClientLeader;
bool m_skipCloseAnimation;
QPointer<KWaylandServer::SurfaceInterface> m_surface;
// when adding new data members, check also copyToDeleted()
@ -2143,7 +2135,7 @@ inline QString Window::resourceClass() const
return resource_class; // it is always lowercase
}
inline const ClientMachine *Window::clientMachine() const
inline ClientMachine *Window::clientMachine() const
{
return m_clientMachine;
}

View file

@ -5118,4 +5118,64 @@ void X11Window::discardShapeRegion()
m_shapeRegion.clear();
}
Xcb::Property X11Window::fetchWmClientLeader() const
{
return Xcb::Property(false, window(), atoms->wm_client_leader, XCB_ATOM_WINDOW, 0, 10000);
}
void X11Window::readWmClientLeader(Xcb::Property &prop)
{
m_wmClientLeader = prop.value<xcb_window_t>(window());
}
void X11Window::getWmClientLeader()
{
auto prop = fetchWmClientLeader();
readWmClientLeader(prop);
}
/**
* Returns sessionId for this window,
* taken either from its window or from the leader window.
*/
QByteArray X11Window::sessionId() const
{
QByteArray result = Xcb::StringProperty(window(), atoms->sm_client_id);
if (result.isEmpty() && m_wmClientLeader && m_wmClientLeader != window()) {
result = Xcb::StringProperty(m_wmClientLeader, atoms->sm_client_id);
}
return result;
}
/**
* Returns command property for this window,
* taken either from its window or from the leader window.
*/
QString X11Window::wmCommand()
{
QByteArray result = Xcb::StringProperty(window(), XCB_ATOM_WM_COMMAND);
if (result.isEmpty() && m_wmClientLeader && m_wmClientLeader != window()) {
result = Xcb::StringProperty(m_wmClientLeader, XCB_ATOM_WM_COMMAND);
}
result.replace(0, ' ');
return result;
}
/**
* Returns client leader window for this client.
* Returns the client window itself if no leader window is defined.
*/
xcb_window_t X11Window::wmClientLeader() const
{
if (m_wmClientLeader != XCB_WINDOW_NONE) {
return m_wmClientLeader;
}
return window();
}
void X11Window::getWmClientMachine()
{
clientMachine()->resolve(window(), wmClientLeader());
}
} // namespace

View file

@ -81,6 +81,10 @@ public:
}
xcb_window_t frameId() const override;
QByteArray sessionId() const;
xcb_window_t wmClientLeader() const;
QString wmCommand();
QRectF inputGeometry() const override;
QPointF framePosToClientPos(const QPointF &point) const override;
@ -363,6 +367,7 @@ private:
QRect fullscreenMonitorsArea(NETFullscreenMonitors topology) const;
void getResourceClass();
void getWmNormalHints();
void getWmClientMachine();
void getMotifHints();
void getIcons();
void getWmOpaqueRegion();
@ -373,6 +378,9 @@ private:
void setCaption(const QString &s, bool force = false);
bool hasTransientInternal(const X11Window *c, bool indirect, QList<const X11Window *> &set) const;
void setShortcutInternal() override;
Xcb::Property fetchWmClientLeader() const;
void readWmClientLeader(Xcb::Property &p);
void getWmClientLeader();
void configureRequest(int value_mask, qreal rx, qreal ry, qreal rw, qreal rh, int gravity, bool from_tool);
NETExtendedStrut strut() const;
@ -436,6 +444,7 @@ private:
Xcb::Window m_client;
Xcb::Window m_wrapper;
Xcb::Window m_frame;
xcb_window_t m_wmClientLeader = XCB_WINDOW_NONE;
int m_activityUpdatesBlocked;
bool m_blockedActivityUpdatesRequireTransients;
Xcb::Window m_moveResizeGrabWindow;