Update sniproxy code

pull/21/head
kateleet 4 years ago
parent 0faedfd4a0
commit 908cad1c20

@ -55,6 +55,7 @@ set(XEMBED_SNI_PROXY_SOURCES
fdoselectionmanager.cpp
snidbus.cpp
sniproxy.cpp
debug.cpp
xtestsender.cpp
)

@ -0,0 +1,8 @@
/* This file is part of the KDE project
SPDX-FileCopyrightText: 2015 Bhushan Shah <bshah@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#include "debug.h"
Q_LOGGING_CATEGORY(SNIPROXY, "com.cutefish.sniproxy", QtWarningMsg)

@ -0,0 +1,12 @@
/* This file is part of the KDE project
SPDX-FileCopyrightText: 2015 Bhushan Shah <bshah@kde.org>
SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef DEBUG_H
#define DEBUG_H
#include <QLoggingCategory>
Q_DECLARE_LOGGING_CATEGORY(SNIPROXY)
#endif

@ -1,76 +1,60 @@
/*
* Registers as a embed container
* Copyright (C) 2015 <davidedmundson@kde.org> David Edmundson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Registers as a embed container
SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2019 Konrad Materka <materka@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "fdoselectionmanager.h"
#include "debug.h"
#include <QCoreApplication>
#include <QHash>
#include <QTimer>
#include <QDebug>
#include <QTextDocument>
#include <QX11Info>
#include <KWindowSystem>
#include <KSelectionOwner>
#include <xcb/xcb.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_event.h>
#include <xcb/composite.h>
#include <xcb/damage.h>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_event.h>
#include "xcbutils.h"
#include "sniproxy.h"
#include "xcbutils.h"
#define SYSTEM_TRAY_REQUEST_DOCK 0
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
#define SYSTEM_TRAY_REQUEST_DOCK 0
#define SYSTEM_TRAY_BEGIN_MESSAGE 1
#define SYSTEM_TRAY_CANCEL_MESSAGE 2
FdoSelectionManager::FdoSelectionManager():
QObject(),
m_selectionOwner(new KSelectionOwner(Xcb::atoms->selectionAtom, -1, this))
FdoSelectionManager::FdoSelectionManager()
: QObject()
, m_selectionOwner(new KSelectionOwner(Xcb::atoms->selectionAtom, -1, this))
{
qDebug() << "starting";
qCDebug(SNIPROXY) << "starting";
//we may end up calling QCoreApplication::quit() in this method, at which point we need the event loop running
// we may end up calling QCoreApplication::quit() in this method, at which point we need the event loop running
QTimer::singleShot(0, this, &FdoSelectionManager::init);
}
FdoSelectionManager::~FdoSelectionManager()
{
qDebug() << "closing";
qCDebug(SNIPROXY) << "closing";
m_selectionOwner->release();
}
void FdoSelectionManager::init()
{
//load damage extension
// load damage extension
xcb_connection_t *c = QX11Info::connection();
xcb_prefetch_extension_data(c, &xcb_damage_id);
const auto *reply = xcb_get_extension_data(c, &xcb_damage_id);
if (reply->present) {
if (reply && reply->present) {
m_damageEventBase = reply->first_event;
xcb_damage_query_version_unchecked(c, XCB_DAMAGE_MAJOR_VERSION, XCB_DAMAGE_MINOR_VERSION);
} else {
//no XDamage means
qCritical() << "could not load damage extension. Quitting";
// no XDamage means
qCCritical(SNIPROXY) << "could not load damage extension. Quitting";
qApp->exit(-1);
}
@ -84,7 +68,7 @@ void FdoSelectionManager::init()
bool FdoSelectionManager::addDamageWatch(xcb_window_t client)
{
qDebug() << "adding damage watch for " << client;
qCDebug(SNIPROXY) << "adding damage watch for " << client;
xcb_connection_t *c = QX11Info::connection();
const auto attribsCookie = xcb_get_window_attributes_unchecked(c, client);
@ -116,24 +100,24 @@ bool FdoSelectionManager::addDamageWatch(xcb_window_t client)
return true;
}
bool FdoSelectionManager::nativeEventFilter(const QByteArray& eventType, void* message, long int* result)
bool FdoSelectionManager::nativeEventFilter(const QByteArray &eventType, void *message, long int *result)
{
Q_UNUSED(result);
Q_UNUSED(result)
if (eventType != "xcb_generic_event_t") {
return false;
}
xcb_generic_event_t* ev = static_cast<xcb_generic_event_t *>(message);
xcb_generic_event_t *ev = static_cast<xcb_generic_event_t *>(message);
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) {
switch (ce->data.data32[1]) {
case SYSTEM_TRAY_REQUEST_DOCK:
dock(ce->data.data32[2]);
return true;
case SYSTEM_TRAY_REQUEST_DOCK:
dock(ce->data.data32[2]);
return true;
}
}
} else if (responseType == XCB_UNMAP_NOTIFY) {
@ -148,11 +132,29 @@ bool FdoSelectionManager::nativeEventFilter(const QByteArray& eventType, void* m
}
} else if (responseType == m_damageEventBase + XCB_DAMAGE_NOTIFY) {
const auto damagedWId = reinterpret_cast<xcb_damage_notify_event_t *>(ev)->drawable;
const auto sniProx = m_proxies.value(damagedWId);
if(sniProx) {
sniProx->update();
const auto sniProxy = m_proxies.value(damagedWId);
if (sniProxy) {
sniProxy->update();
xcb_damage_subtract(QX11Info::connection(), m_damageWatches[damagedWId], XCB_NONE, XCB_NONE);
}
} else if (responseType == XCB_CONFIGURE_REQUEST) {
const auto event = reinterpret_cast<xcb_configure_request_event_t *>(ev);
const auto sniProxy = m_proxies.value(event->window);
if (sniProxy) {
// The embedded window tries to move or resize. Ignore move, handle resize only.
if ((event->value_mask & XCB_CONFIG_WINDOW_WIDTH) || (event->value_mask & XCB_CONFIG_WINDOW_HEIGHT)) {
sniProxy->resizeWindow(event->width, event->height);
}
}
} else if (responseType == XCB_VISIBILITY_NOTIFY) {
const auto event = reinterpret_cast<xcb_visibility_notify_event_t *>(ev);
// it's possible that something showed our container window, we have to hide it
// workaround for BUG 357443: when KWin is restarted, container window is shown on top
if (event->state == XCB_VISIBILITY_UNOBSCURED) {
for (auto sniProxy : m_proxies.values()) {
sniProxy->hideContainerWindow(event->window);
}
}
}
return false;
@ -160,7 +162,7 @@ bool FdoSelectionManager::nativeEventFilter(const QByteArray& eventType, void* m
void FdoSelectionManager::dock(xcb_window_t winId)
{
qDebug() << "trying to dock window " << winId;
qCDebug(SNIPROXY) << "trying to dock window " << winId;
if (m_proxies.contains(winId)) {
return;
@ -173,7 +175,7 @@ void FdoSelectionManager::dock(xcb_window_t winId)
void FdoSelectionManager::undock(xcb_window_t winId)
{
qDebug() << "trying to undock window " << winId;
qCDebug(SNIPROXY) << "trying to undock window " << winId;
if (!m_proxies.contains(winId)) {
return;
@ -184,61 +186,50 @@ void FdoSelectionManager::undock(xcb_window_t winId)
void FdoSelectionManager::onClaimedOwnership()
{
qDebug() << "Manager selection claimed";
qCDebug(SNIPROXY) << "Manager selection claimed";
connect(KWindowSystem::self(), &KWindowSystem::compositingChanged, this, &FdoSelectionManager::compositingChanged);
compositingChanged();
setSystemTrayVisual();
}
void FdoSelectionManager::onFailedToClaimOwnership()
{
qWarning() << "failed to claim ownership of Systray Manager";
qCWarning(SNIPROXY) << "failed to claim ownership of Systray Manager";
qApp->exit(-1);
}
void FdoSelectionManager::onLostOwnership()
{
qWarning() << "lost ownership of Systray Manager";
disconnect(KWindowSystem::self(), &KWindowSystem::compositingChanged, this, &FdoSelectionManager::compositingChanged);
qCWarning(SNIPROXY) << "lost ownership of Systray Manager";
qApp->exit(-1);
}
void FdoSelectionManager::compositingChanged()
void FdoSelectionManager::setSystemTrayVisual()
{
xcb_connection_t *c = QX11Info::connection();
auto screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
auto screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
auto trayVisual = screen->root_visual;
if (KWindowSystem::compositingActive()) {
xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(screen);
xcb_depth_t *depth = nullptr;
xcb_depth_iterator_t depth_iterator = xcb_screen_allowed_depths_iterator(screen);
xcb_depth_t *depth = nullptr;
while (depth_iterator.rem) {
if (depth_iterator.data->depth == 32) {
depth = depth_iterator.data;
break;
}
xcb_depth_next(&depth_iterator);
while (depth_iterator.rem) {
if (depth_iterator.data->depth == 32) {
depth = depth_iterator.data;
break;
}
xcb_depth_next(&depth_iterator);
}
if (depth) {
xcb_visualtype_iterator_t visualtype_iterator = xcb_depth_visuals_iterator(depth);
while (visualtype_iterator.rem) {
xcb_visualtype_t *visualtype = visualtype_iterator.data;
if (visualtype->_class == XCB_VISUAL_CLASS_TRUE_COLOR) {
trayVisual = visualtype->visual_id;
break;
}
xcb_visualtype_next(&visualtype_iterator);
if (depth) {
xcb_visualtype_iterator_t visualtype_iterator = xcb_depth_visuals_iterator(depth);
while (visualtype_iterator.rem) {
xcb_visualtype_t *visualtype = visualtype_iterator.data;
if (visualtype->_class == XCB_VISUAL_CLASS_TRUE_COLOR) {
trayVisual = visualtype->visual_id;
break;
}
xcb_visualtype_next(&visualtype_iterator);
}
}
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(), Xcb::atoms->visualAtom, XCB_ATOM_VISUALID, 32, 1, &trayVisual);
}

@ -1,29 +1,15 @@
/*
* Registers as a embed container
* Copyright (C) 2015 <davidedmundson@kde.org> David Edmundson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Registers as a embed container
SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
#ifndef FDOSELECTIONMANAGER_H
#define FDOSELECTIONMANAGER_H
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#include <QObject>
#include <QHash>
#include <QAbstractNativeEventFilter>
#include <QHash>
#include <QObject>
#include <xcb/xcb.h>
@ -39,7 +25,7 @@ public:
~FdoSelectionManager() override;
protected:
bool nativeEventFilter(const QByteArray & eventType, void * message, long * result) override;
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result) override;
private Q_SLOTS:
void onClaimedOwnership();
@ -51,14 +37,11 @@ private:
bool addDamageWatch(xcb_window_t client);
void dock(xcb_window_t embed_win);
void undock(xcb_window_t client);
void compositingChanged();
void setSystemTrayVisual();
uint8_t m_damageEventBase;
QHash<xcb_window_t, u_int32_t> m_damageWatches;
QHash<xcb_window_t, SNIProxy*> m_proxies;
QHash<xcb_window_t, SNIProxy *> m_proxies;
KSelectionOwner *m_selectionOwner;
};
#endif

@ -1,43 +1,32 @@
/*
* Main
* Copyright (C) 2015 <davidedmundson@kde.org> David Edmundson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Main
SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <QGuiApplication>
#include <QSessionManager>
#include "fdoselectionmanager.h"
#include "xcbutils.h"
#include "debug.h"
#include "snidbus.h"
#include "xcbutils.h"
#include <QDBusMetaType>
#include <KWindowSystem>
namespace Xcb {
Xcb::Atoms* atoms;
namespace Xcb
{
Xcb::Atoms *atoms;
}
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
//if the QPA can't load xcb, this app is useless anyway.
// 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.
qputenv("QT_QPA_PLATFORM", "xcb");
QGuiApplication::setDesktopSettingsAware(false);

@ -1,5 +1,7 @@
<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
<node>
<!-- This is a minimally cut down version of the interface only implementing the
methods and properties used by xembedsniproxy -->
<interface name="org.kde.StatusNotifierItem">
<property name="Category" type="s" access="read"/>
@ -8,48 +10,13 @@
<property name="Status" type="s" access="read"/>
<property name="WindowId" type="i" access="read"/>
<!-- An additional path to add to the theme search path to find the icons specified above. -->
<!-- <property name="IconThemePath" type="s" access="read"/> -->
<!-- <property name="Menu" type="o" access="read"/> -->
<property name="ItemIsMenu" type="b" access="read"/>
<!-- main icon -->
<!-- names are preferred over pixmaps -->
<!-- <property name="IconName" type="s" access="read"/> -->
<!--struct containing width, height and image data-->
<property name="IconPixmap" type="(iiay)" access="read">
<annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusImageVector"/>
</property>
<!-- <property name="OverlayIconName" type="s" access="read"/> -->
<!-- <property name="OverlayIconPixmap" type="(iiay)" access="read"> -->
<!-- <annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusImageVector"/> -->
<!-- </property> -->
<!-- Requesting attention icon -->
<!-- <property name="AttentionIconName" type="s" access="read"/> -->
<!--same definition as image-->
<!-- <property name="AttentionIconPixmap" type="(iiay)" access="read"> -->
<!-- <annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusImageVector"/> -->
<!-- </property> -->
<!-- <property name="AttentionMovieName" type="s" access="read"/> -->
<!-- tooltip data -->
<!--(iiay) is an image-->
<!-- <property name="ToolTip" type="(s(iiay)ss)" access="read"> -->
<!-- <annotation name="org.qtproject.QtDBus.QtTypeName" value="KDbusToolTipStruct"/> -->
<!-- </property> -->
<!-- interaction: the systemtray wants the application to do something -->
<method name="ContextMenu">
<!-- we're passing the coordinates of the icon, so the app knows where to put the popup window -->

@ -1,32 +1,17 @@
/*
* SNI DBus Serialisers
* Copyright 2015 David Edmundson <davidedmundson@kde.org>
* Copyright 2009 by Marco Martin <notmart@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
SNI DBus Serialisers
SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2009 Marco Martin <notmart@gmail.com>
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#include "snidbus.h"
#include <QSysInfo>
#include <QtEndian>
//mostly copied from KStatusNotiferItemDbus.cpps from knotification
// mostly copied from KStatusNotiferItemDbus.cpps from knotification
KDbusImageStruct::KDbusImageStruct()
{
@ -37,15 +22,15 @@ KDbusImageStruct::KDbusImageStruct(const QImage &image)
width = image.size().width();
height = image.size().height();
if (image.format() == QImage::Format_ARGB32) {
data = QByteArray((char *)image.bits(), image.byteCount());
data = QByteArray((char *)image.bits(), image.sizeInBytes());
} else {
QImage image32 = image.convertToFormat(QImage::Format_ARGB32);
data = QByteArray((char *)image32.bits(), image32.byteCount());
data = QByteArray((char *)image32.bits(), image32.sizeInBytes());
}
//swap to network byte order if we are little endian
// swap to network byte order if we are little endian
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
quint32 *uintBuf = (quint32 *) data.data();
quint32 *uintBuf = (quint32 *)data.data();
for (uint i = 0; i < data.size() / sizeof(quint32); ++i) {
*uintBuf = qToBigEndian(*uintBuf);
++uintBuf;

@ -1,35 +1,19 @@
/*
* SNI Dbus serialisers
* Copyright 2015 <davidedmundson@kde.org> David Edmundson
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
SNI Dbus serialisers
Copyright 2015 <davidedmundson@kde.org> David Edmundson
#ifndef SNIDBUS_H
#define SNIDBUS_H
SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*/
#pragma once
#include <QString>
#include <QByteArray>
#include <QDBusArgument>
#include <QVector>
#include <QImage>
#include <QString>
#include <QVector>
//Custom message type for DBus
// Custom message type for DBus
struct KDbusImageStruct {
KDbusImageStruct();
KDbusImageStruct(const QImage &image);
@ -61,5 +45,3 @@ const QDBusArgument &operator<<(QDBusArgument &argument, const KDbusToolTipStruc
const QDBusArgument &operator>>(const QDBusArgument &argument, KDbusToolTipStruct &toolTip);
Q_DECLARE_METATYPE(KDbusToolTipStruct)
#endif // SNIDBUS_H

@ -1,37 +1,24 @@
/*
* Holds one embedded window, registers as DBus entry
* Copyright (C) 2015 <davidedmundson@kde.org> David Edmundson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
Holds one embedded window, registers as DBus entry
SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2019 Konrad Materka <materka@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "sniproxy.h"
#include <xcb/xcb.h>
#include <algorithm>
#include <xcb/xcb_atom.h>
#include <xcb/xcb_event.h>
#include <xcb/xcb_image.h>
#include "debug.h"
#include "xcbutils.h"
#include <QX11Info>
#include <QScreen>
#include <QGuiApplication>
#include <QScreen>
#include <QTimer>
#include <QDebug>
#include <QX11Info>
#include <QBitmap>
@ -48,13 +35,12 @@
#define SNI_WATCHER_SERVICE_NAME "org.kde.StatusNotifierWatcher"
#define SNI_WATCHER_PATH "/StatusNotifierWatcher"
static uint16_t s_embedSize = 32; //max size of window to embed. We no longer resize the embedded window as Chromium acts stupidly.
static uint16_t s_embedSize = 32; // max size of window to embed. We no longer resize the embedded window as Chromium acts stupidly.
static unsigned int XEMBED_VERSION = 0;
int SNIProxy::s_serviceCount = 0;
void
xembed_message_send(xcb_window_t towin,
long message, long d1, long d2, long d3)
void xembed_message_send(xcb_window_t towin, long message, long d1, long d2, long d3)
{
xcb_client_message_event_t ev;
@ -67,57 +53,63 @@ xembed_message_send(xcb_window_t towin,
ev.data.data32[3] = d2;
ev.data.data32[4] = d3;
ev.type = Xcb::atoms->xembedAtom;
xcb_send_event(QX11Info::connection(), false, towin, XCB_EVENT_MASK_NO_EVENT, (char *) &ev);
xcb_send_event(QX11Info::connection(), false, towin, XCB_EVENT_MASK_NO_EVENT, (char *)&ev);
}
SNIProxy::SNIProxy(xcb_window_t wid, QObject* parent):
QObject(parent),
//Work round a bug in our SNIWatcher with multiple SNIs per connection.
//there is an undocumented feature that you can register an SNI by path, however it doesn't detect an object on a service being removed, only the entire service closing
//instead lets use one DBus connection per SNI
m_dbus(QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("XembedSniProxy%1").arg(s_serviceCount++))),
m_windowId(wid),
m_injectMode(Direct)
SNIProxy::SNIProxy(xcb_window_t wid, QObject *parent)
: QObject(parent)
,
// Work round a bug in our SNIWatcher with multiple SNIs per connection.
// there is an undocumented feature that you can register an SNI by path, however it doesn't detect an object on a service being removed, only the entire
// service closing instead lets use one DBus connection per SNI
m_dbus(QDBusConnection::connectToBus(QDBusConnection::SessionBus, QStringLiteral("XembedSniProxy%1").arg(s_serviceCount++)))
, m_windowId(wid)
, sendingClickEvent(false)
, m_injectMode(Direct)
{
//create new SNI
// create new SNI
new StatusNotifierItemAdaptor(this);
m_dbus.registerObject(QStringLiteral("/StatusNotifierItem"), this);
auto statusNotifierWatcher = new org::kde::StatusNotifierWatcher(QStringLiteral(SNI_WATCHER_SERVICE_NAME), QStringLiteral(SNI_WATCHER_PATH), QDBusConnection::sessionBus(), this);
auto statusNotifierWatcher =
new org::kde::StatusNotifierWatcher(QStringLiteral(SNI_WATCHER_SERVICE_NAME), QStringLiteral(SNI_WATCHER_PATH), QDBusConnection::sessionBus(), this);
auto reply = statusNotifierWatcher->RegisterStatusNotifierItem(m_dbus.baseService());
reply.waitForFinished();
if (reply.isError()) {
qWarning() << "could not register SNI:" << reply.error().message();
qCWarning(SNIPROXY) << "could not register SNI:" << reply.error().message();
}
auto c = QX11Info::connection();
auto cookie = xcb_get_geometry(c, m_windowId);
QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter>
clientGeom(xcb_get_geometry_reply(c, cookie, nullptr));
//create a container window
auto screen = xcb_setup_roots_iterator (xcb_get_setup (c)).data;
// create a container window
auto screen = xcb_setup_roots_iterator(xcb_get_setup(c)).data;
m_containerWid = xcb_generate_id(c);
uint32_t values[2];
auto mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT;
values[0] = screen->black_pixel; //draw a solid background so the embedded icon doesn't get garbage in it
values[1] = true; //bypass wM
xcb_create_window (c, /* connection */
XCB_COPY_FROM_PARENT, /* depth */
m_containerWid, /* window Id */
screen->root, /* parent window */
0, 0, /* x, y */
s_embedSize, s_embedSize, /* width, height */
0, /* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT,/* class */
screen->root_visual, /* visual */
mask, values); /* masks */
uint32_t values[3];
uint32_t mask = XCB_CW_BACK_PIXEL | XCB_CW_OVERRIDE_REDIRECT | XCB_CW_EVENT_MASK;
values[0] = screen->black_pixel; // draw a solid background so the embedded icon doesn't get garbage in it
values[1] = true; // bypass wM
values[2] = XCB_EVENT_MASK_VISIBILITY_CHANGE | // receive visibility change, to handle KWin restart #357443
// Redirect and handle structure (size, position) requests from the embedded window.
XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
xcb_create_window(c, /* connection */
XCB_COPY_FROM_PARENT, /* depth */
m_containerWid, /* window Id */
screen->root, /* parent window */
0,
0, /* x, y */
s_embedSize,
s_embedSize, /* width, height */
0, /* border_width */
XCB_WINDOW_CLASS_INPUT_OUTPUT, /* class */
screen->root_visual, /* visual */
mask,
values); /* masks */
/*
We need the window to exist and be mapped otherwise the child won't render it's contents
We also need it to exist in the right place to get the clicks working as GTK will check sendEvent locations to see if our window is in the right place. So even though our contents are drawn via compositing we still put this window in the right place
We also need it to exist in the right place to get the clicks working as GTK will check sendEvent locations to see if our window is in the right place.
So even though our contents are drawn via compositing we still put this window in the right place
We can't composite it away anything parented owned by the root window (apparently)
Stack Under works in the non composited case, but it doesn't seem to work in kwin's composited case (probably need set relevant NETWM hint)
@ -126,8 +118,7 @@ SNIProxy::SNIProxy(xcb_window_t wid, QObject* parent):
*/
#ifndef VISUAL_DEBUG
const uint32_t stackBelowData[] = {XCB_STACK_MODE_BELOW};
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackBelowData);
stackContainerWindow(XCB_STACK_MODE_BELOW);
NETWinInfo wm(c, m_containerWid, screen->root, NET::Properties(), NET::Properties2());
wm.setOpacity(0);
@ -137,85 +128,51 @@ SNIProxy::SNIProxy(xcb_window_t wid, QObject* parent):
xcb_map_window(c, m_containerWid);
xcb_reparent_window(c, wid,
m_containerWid,
0, 0);
xcb_reparent_window(c, wid, m_containerWid, 0, 0);
/*
* Render the embedded window offscreen
*/
xcb_composite_redirect_window(c, wid, XCB_COMPOSITE_REDIRECT_MANUAL);
/* we grab the window, but also make sure it's automatically reparented back
* to the root window if we should die.
*/
*/
xcb_change_save_set(c, XCB_SET_MODE_INSERT, wid);
//tell client we're embedding it
xembed_message_send(wid, XEMBED_EMBEDDED_NOTIFY, m_containerWid, 0, 0);
// tell client we're embedding it
xembed_message_send(wid, XEMBED_EMBEDDED_NOTIFY, 0, m_containerWid, XEMBED_VERSION);
//move window we're embedding
const uint32_t windowMoveConfigVals[2] = { 0, 0 };
// move window we're embedding
const uint32_t windowMoveConfigVals[2] = {0, 0};
xcb_configure_window(c, wid,
XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y,
windowMoveConfigVals);
xcb_configure_window(c, wid, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, windowMoveConfigVals);
QSize clientWindowSize = calculateClientWindowSize();
QSize clientWindowSize;
if (clientGeom) {
clientWindowSize = QSize(clientGeom->width, clientGeom->height);
}
//if the window is a clearly stupid size resize to be something sensible
//this is needed as chormium and such when resized just fill the icon with transparent space and only draw in the middle
//however spotify does need this as by default the window size is 900px wide.
//use an artbitrary heuristic to make sure icons are always sensible
if (clientWindowSize.isEmpty() || clientWindowSize.width() > s_embedSize || clientWindowSize.height() > s_embedSize )
{
qDebug() << "Resizing window" << wid << Title() << "from w*h" << clientWindowSize;
xcb_configure_notify_event_t event;
memset(&event, 0x00, sizeof(xcb_configure_notify_event_t));
event.response_type = XCB_CONFIGURE_NOTIFY;
event.event = wid;
event.window = wid;
event.width = s_embedSize;
event.height = s_embedSize;
xcb_send_event(c, false, wid, XCB_EVENT_MASK_STRUCTURE_NOTIFY, (char *) &event);
const uint32_t windowMoveConfigVals[2] = { s_embedSize, s_embedSize };
xcb_configure_window(c, wid,
XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT,
windowMoveConfigVals);
clientWindowSize = QSize(s_embedSize, s_embedSize);
}
//show the embedded window otherwise nothing happens
// show the embedded window otherwise nothing happens
xcb_map_window(c, wid);
xcb_clear_area(c, 0, wid, 0, 0, clientWindowSize.width(), clientWindowSize.height());
xcb_flush(c);
//guess which input injection method to use
//we can either send an X event to the client or XTest
//some don't support direct X events (GTK3/4), and some don't support XTest because reasons
//note also some clients might not have the XTest extension. We may as well assume it does and just fail to send later.
// guess which input injection method to use
// we can either send an X event to the client or XTest
// some don't support direct X events (GTK3/4), and some don't support XTest because reasons
// note also some clients might not have the XTest extension. We may as well assume it does and just fail to send later.
//we query if the client selected button presses in the event mask
//if the client does supports that we send directly, otherwise we'll use xtest
// we query if the client selected button presses in the event mask
// if the client does supports that we send directly, otherwise we'll use xtest
auto waCookie = xcb_get_window_attributes(c, wid);
QScopedPointer<xcb_get_window_attributes_reply_t, QScopedPointerPodDeleter> windowAttributes(xcb_get_window_attributes_reply(c, waCookie, nullptr));
if (windowAttributes && ! (windowAttributes->all_event_masks & XCB_EVENT_MASK_BUTTON_PRESS)) {
if (windowAttributes && !(windowAttributes->all_event_masks & XCB_EVENT_MASK_BUTTON_PRESS)) {
m_injectMode = XTest;
}
//there's no damage event for the first paint, and sometimes it's not drawn immediately
//not ideal, but it works better than nothing
//test with xchat before changing
// there's no damage event for the first paint, and sometimes it's not drawn immediately
// not ideal, but it works better than nothing
// test with xchat before changing
QTimer::singleShot(500, this, &SNIProxy::update);
}
@ -231,7 +188,7 @@ void SNIProxy::update()
{
const QImage image = getImageNonComposite();
if (image.isNull()) {
qDebug() << "No xembed icon for" << m_windowId << Title();
qCDebug(SNIPROXY) << "No xembed icon for" << m_windowId << Title();
return;
}
@ -239,25 +196,73 @@ void SNIProxy::update()
int h = image.height();
m_pixmap = QPixmap::fromImage(image);
if (w != s_embedSize || h != s_embedSize) {
qDebug() << "Scaling pixmap of window" << m_windowId << Title() << "from w*h" << w << h;
if (w > s_embedSize || h > s_embedSize) {
qCDebug(SNIPROXY) << "Scaling pixmap of window" << m_windowId << Title() << "from w*h" << w << h;
m_pixmap = m_pixmap.scaled(s_embedSize, s_embedSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
}
emit NewIcon();
emit NewToolTip();
}
void sni_cleanup_xcb_image(void *data) {
xcb_image_destroy(static_cast<xcb_image_t*>(data));
void SNIProxy::resizeWindow(const uint16_t width, const uint16_t height) const
{
auto connection = QX11Info::connection();
uint16_t widthNormalized = std::min(width, s_embedSize);
uint16_t heighNormalized = std::min(height, s_embedSize);
const uint32_t windowSizeConfigVals[2] = {widthNormalized, heighNormalized};
xcb_configure_window(connection, m_windowId, XCB_CONFIG_WINDOW_WIDTH | XCB_CONFIG_WINDOW_HEIGHT, windowSizeConfigVals);
xcb_flush(connection);
}
bool SNIProxy::isTransparentImage(const QImage& image) const
void SNIProxy::hideContainerWindow(xcb_window_t windowId) const
{
if (m_containerWid == windowId && !sendingClickEvent) {
qDebug() << "Container window visible, stack below";
stackContainerWindow(XCB_STACK_MODE_BELOW);
}
}
QSize SNIProxy::calculateClientWindowSize() const
{
auto c = QX11Info::connection();
auto cookie = xcb_get_geometry(c, m_windowId);
QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter> clientGeom(xcb_get_geometry_reply(c, cookie, nullptr));
QSize clientWindowSize;
if (clientGeom) {
clientWindowSize = QSize(clientGeom->width, clientGeom->height);
}
// if the window is a clearly stupid size resize to be something sensible
// this is needed as chromium and such when resized just fill the icon with transparent space and only draw in the middle
// however KeePass2 does need this as by default the window size is 273px wide and is not transparent
// use an arbitrary heuristic to make sure icons are always sensible
if (clientWindowSize.isEmpty() || clientWindowSize.width() > s_embedSize || clientWindowSize.height() > s_embedSize) {
qCDebug(SNIPROXY) << "Resizing window" << m_windowId << Title() << "from w*h" << clientWindowSize;
resizeWindow(s_embedSize, s_embedSize);
clientWindowSize = QSize(s_embedSize, s_embedSize);
}
return clientWindowSize;
}
void sni_cleanup_xcb_image(void *data)
{
xcb_image_destroy(static_cast<xcb_image_t *>(data));
}
bool SNIProxy::isTransparentImage(const QImage &image) const
{
int w = image.width();
int h = image.height();
// check for the center and sub-center pixels first and avoid full image scan
if (! (qAlpha(image.pixel(w >> 1, h >> 1)) + qAlpha(image.pixel(w >> 2, h >> 2)) == 0))
if (!(qAlpha(image.pixel(w >> 1, h >> 1)) + qAlpha(image.pixel(w >> 2, h >> 2)) == 0))
return false;
// skip scan altogether if sub-center pixel found to be opaque
@ -277,22 +282,17 @@ bool SNIProxy::isTransparentImage(const QImage& image) const
QImage SNIProxy::getImageNonComposite() const
{
auto c = QX11Info::connection();
auto cookie = xcb_get_geometry(c, m_windowId);
QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter>
geom(xcb_get_geometry_reply(c, cookie, nullptr));
if (!geom) {
return QImage();
}
QSize clientWindowSize = calculateClientWindowSize();
xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, geom->width, geom->height, 0xFFFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP);
xcb_image_t *image = xcb_image_get(c, m_windowId, 0, 0, clientWindowSize.width(), clientWindowSize.height(), 0xFFFFFFFF, XCB_IMAGE_FORMAT_Z_PIXMAP);
// Don't hook up cleanup yet, we may use a different QImage after all
QImage naiveConversion;
if (image) {
naiveConversion = QImage(image->data, image->width, image->height, QImage::Format_ARGB32);
} else {
qDebug() << "Skip NULL image returned from xcb_image_get() for" << m_windowId << Title();
qCDebug(SNIPROXY) << "Skip NULL image returned from xcb_image_get() for" << m_windowId << Title();
return QImage();
}
@ -304,7 +304,7 @@ QImage SNIProxy::getImageNonComposite() const
// become transparent for a one or few frames. Reproducible at least
// with WINE applications.
if (isTransparentImage(elaborateConversion)) {
qDebug() << "Skip transparent xembed icon for" << m_windowId << Title();
qCDebug(SNIPROXY) << "Skip transparent xembed icon for" << m_windowId << Title();
return QImage();
} else
return elaborateConversion;
@ -334,11 +334,12 @@ QImage SNIProxy::convertFromNative(xcb_image_t *xcbImage) const
for (uint i = 0; i < (xcbImage->size / 4); i++) {
int r = (pixels[i] >> 22) & 0xff;
int g = (pixels[i] >> 12) & 0xff;
int b = (pixels[i] >> 2) & 0xff;
int b = (pixels[i] >> 2) & 0xff;
pixels[i] = qRgba(r, g, b, 0xff);
}
// fall through, Qt format is still Format_ARGB32_Premultiplied
Q_FALLTHROUGH();
}
case 32:
format = QImage::Format_ARGB32_Premultiplied;
@ -353,8 +354,7 @@ QImage SNIProxy::convertFromNative(xcb_image_t *xcbImage) const
return QImage();
}
if (format == QImage::Format_RGB32 && xcbImage->bpp == 32)
{
if (format == QImage::Format_RGB32 && xcbImage->bpp == 32) {
QImage m = image.createHeuristicMask();
QBitmap mask(QPixmap::fromImage(m));
QPixmap p = QPixmap::fromImage(image);
@ -372,6 +372,56 @@ QImage SNIProxy::convertFromNative(xcb_image_t *xcbImage) const
return image;
}
/*
Wine is using XWindow Shape Extension for transparent tray icons.
We need to find first clickable point starting from top-left.
*/
QPoint SNIProxy::calculateClickPoint() const
{
QPoint clickPoint = QPoint(0, 0);
auto c = QX11Info::connection();
// request extent to check if shape has been set
xcb_shape_query_extents_cookie_t extentsCookie = xcb_shape_query_extents(c, m_windowId);
// at the same time make the request for rectangles (even if this request isn't needed)
xcb_shape_get_rectangles_cookie_t rectaglesCookie = xcb_shape_get_rectangles(c, m_windowId, XCB_SHAPE_SK_BOUNDING);
QScopedPointer<xcb_shape_query_extents_reply_t, QScopedPointerPodDeleter> extentsReply(xcb_shape_query_extents_reply(c, extentsCookie, nullptr));
QScopedPointer<xcb_shape_get_rectangles_reply_t, QScopedPointerPodDeleter> rectanglesReply(xcb_shape_get_rectangles_reply(c, rectaglesCookie, nullptr));
if (!extentsReply || !rectanglesReply || !extentsReply->bounding_shaped) {
return clickPoint;
}
xcb_rectangle_t *rectangles = xcb_shape_get_rectangles_rectangles(rectanglesReply.get());
if (!rectangles) {
return clickPoint;
}
const QImage image = getImageNonComposite();
double minLength = sqrt(pow(image.height(), 2) + pow(image.width(), 2));
const int nRectangles = xcb_shape_get_rectangles_rectangles_length(rectanglesReply.get());
for (int i = 0; i < nRectangles; ++i) {
double length = sqrt(pow(rectangles[i].x, 2) + pow(rectangles[i].y, 2));
if (length < minLength) {
minLength = length;
clickPoint = QPoint(rectangles[i].x, rectangles[i].y);
}
}
qCDebug(SNIPROXY) << "Click point:" << clickPoint;
return clickPoint;
}
void SNIProxy::stackContainerWindow(const uint32_t stackMode) const
{
auto c = QX11Info::connection();
const uint32_t stackData[] = {stackMode};
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackData);
}
//____________properties__________
QString SNIProxy::Category() const
@ -382,7 +432,7 @@ QString SNIProxy::Category() const
QString SNIProxy::Id() const
{
const auto title = Title();
//we always need /some/ ID so if no window title exists, just use the winId.
// we always need /some/ ID so if no window title exists, just use the winId.
if (title.isEmpty()) {
return QString::number(m_windowId);
}
@ -407,7 +457,7 @@ QString SNIProxy::Status() const
QString SNIProxy::Title() const
{
KWindowInfo window (m_windowId, NET::WMName);
KWindowInfo window(m_windowId, NET::WMName);
return window.name();
}
@ -433,69 +483,68 @@ void SNIProxy::ContextMenu(int x, int y)
sendClick(XCB_BUTTON_INDEX_3, x, y);
}
void SNIProxy::Scroll(int delta, const QString& orientation)
void SNIProxy::Scroll(int delta, const QString &orientation)
{
if (orientation == QLatin1String("vertical")) {
sendClick(delta > 0 ? XCB_BUTTON_INDEX_4: XCB_BUTTON_INDEX_5, 0, 0);
sendClick(delta > 0 ? XCB_BUTTON_INDEX_4 : XCB_BUTTON_INDEX_5, 0, 0);
} else {
sendClick(delta > 0 ? 6: 7, 0, 0);
sendClick(delta > 0 ? 6 : 7, 0, 0);
}
}
void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
{
//it's best not to look at this code
//GTK doesn't like send_events and double checks the mouse position matches where the window is and is top level
//in order to solve this we move the embed container over to where the mouse is then replay the event using send_event
//if patching, test with xchat + xchat context menus
// it's best not to look at this code
// GTK doesn't like send_events and double checks the mouse position matches where the window is and is top level
// in order to solve this we move the embed container over to where the mouse is then replay the event using send_event
// if patching, test with xchat + xchat context menus
//note x,y are not actually where the mouse is, but the plasmoid
//ideally we should make this match the plasmoid hit area
// note x,y are not actually where the mouse is, but the plasmoid
// ideally we should make this match the plasmoid hit area
qDebug() << "Received click" << mouseButton << "with passed x*y" << x << y;
qCDebug(SNIPROXY) << "Received click" << mouseButton << "with passed x*y" << x << y;
sendingClickEvent = true;
auto c = QX11Info::connection();
auto cookieSize = xcb_get_geometry(c, m_windowId);
QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter>
clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr));
QScopedPointer<xcb_get_geometry_reply_t, QScopedPointerPodDeleter> clientGeom(xcb_get_geometry_reply(c, cookieSize, nullptr));
if (!clientGeom) {
return;
}
auto cookie = xcb_query_pointer(c, m_windowId);
QScopedPointer<xcb_query_pointer_reply_t, QScopedPointerPodDeleter>
pointer(xcb_query_pointer_reply(c, cookie, nullptr));
/*qDebug() << "samescreen" << pointer->same_screen << endl
<< "root x*y" << pointer->root_x << pointer->root_y << endl
<< "win x*y" << pointer->win_x << pointer->win_y;*/
QScopedPointer<xcb_query_pointer_reply_t, QScopedPointerPodDeleter> pointer(xcb_query_pointer_reply(c, cookie, nullptr));
/*qCDebug(SNIPROXY) << "samescreen" << pointer->same_screen << endl
<< "root x*y" << pointer->root_x << pointer->root_y << endl
<< "win x*y" << pointer->win_x << pointer->win_y;*/
//move our window so the mouse is within its geometry
// move our window so the mouse is within its geometry
uint32_t configVals[2] = {0, 0};
const QPoint clickPoint = calculateClickPoint();
if (mouseButton >= XCB_BUTTON_INDEX_4) {
//scroll event, take pointer position
configVals[0] = pointer->root_x;
configVals[1] = pointer->root_y;
// scroll event, take pointer position
configVals[0] = pointer->root_x;
configVals[1] = pointer->root_y;
} else {
if (pointer->root_x > x + clientGeom->width)
configVals[0] = pointer->root_x - clientGeom->width + 1;
else
configVals[0] = static_cast<uint32_t>(x);
if (pointer->root_y > y + clientGeom->height)
configVals[1] = pointer->root_y - clientGeom->height + 1;
else
configVals[1] = static_cast<uint32_t>(y);
if (pointer->root_x > x + clientGeom->width)
configVals[0] = pointer->root_x - clientGeom->width + 1;
else
configVals[0] = static_cast<uint32_t>(x - clickPoint.x());
if (pointer->root_y > y + clientGeom->height)
configVals[1] = pointer->root_y - clientGeom->height + 1;
else
configVals[1] = static_cast<uint32_t>(y - clickPoint.y());
}
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_X | XCB_CONFIG_WINDOW_Y, configVals);
//pull window up
const uint32_t stackAboveData[] = {XCB_STACK_MODE_ABOVE};
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackAboveData);
// pull window up
stackContainerWindow(XCB_STACK_MODE_ABOVE);
//mouse down
// mouse down
if (m_injectMode == Direct) {
xcb_button_press_event_t* event = new xcb_button_press_event_t;
xcb_button_press_event_t *event = new xcb_button_press_event_t;
memset(event, 0x00, sizeof(xcb_button_press_event_t));
event->response_type = XCB_BUTTON_PRESS;
event->event = m_windowId;
@ -504,22 +553,21 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
event->root = QX11Info::appRootWindow();
event->root_x = x;
event->root_y = y;
event->event_x = 0;
event->event_y = 0;
event->event_x = static_cast<int16_t>(clickPoint.x());
event->event_y = static_cast<int16_t>(clickPoint.y());
event->child = 0;
event->state = 0;
event->detail = mouseButton;
xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_PRESS, (char *) event);
xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_PRESS, (char *)event);
delete event;
} else {
sendXTestPressed(QX11Info::display(), mouseButton);
}
//mouse up
if (m_injectMode == Direct)
{
xcb_button_release_event_t* event = new xcb_button_release_event_t;
// mouse up
if (m_injectMode == Direct) {
xcb_button_release_event_t *event = new xcb_button_release_event_t;
memset(event, 0x00, sizeof(xcb_button_release_event_t));
event->response_type = XCB_BUTTON_RELEASE;
event->event = m_windowId;
@ -528,20 +576,21 @@ void SNIProxy::sendClick(uint8_t mouseButton, int x, int y)
event->root = QX11Info::appRootWindow();
event->root_x = x;
event->root_y = y;
event->event_x = 0;
event->event_y = 0;
event->event_x = static_cast<int16_t>(clickPoint.x());
event->event_y = static_cast<int16_t>(clickPoint.y());
event->child = 0;
event->state = 0;
event->detail = mouseButton;
xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_RELEASE, (char *) event);
xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_RELEASE, (char *)event);
delete event;
} else {
sendXTestReleased(QX11Info::display(), mouseButton);
}
#ifndef VISUAL_DEBUG
const uint32_t stackBelowData[] = {XCB_STACK_MODE_BELOW};
xcb_configure_window(c, m_containerWid, XCB_CONFIG_WINDOW_STACK_MODE, stackBelowData);
stackContainerWindow(XCB_STACK_MODE_BELOW);
#endif
sendingClickEvent = false;
}

@ -1,31 +1,19 @@
/*
* Holds one embedded window, registers as DBus entry
* Copyright (C) 2015 <davidedmundson@kde.org> David Edmundson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef SNI_PROXY_H
#define SNI_PROXY_H
Holds one embedded window, registers as DBus entry
SPDX-FileCopyrightText: 2015 David Edmundson <davidedmundson@kde.org>
SPDX-FileCopyrightText: 2019 Konrad Materka <materka@gmail.com>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
#include <QObject>
#include <QDBusArgument>
#include <QDBusConnection>
#include <QDBusObjectPath>
#include <QObject>
#include <QPixmap>
#include <QPoint>
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
@ -48,6 +36,8 @@ public:
~SNIProxy() override;
void update();
void resizeWindow(const uint16_t width, const uint16_t height) const;
void hideContainerWindow(xcb_window_t windowId) const;
/**
* @return the category of the application associated to this item
@ -87,7 +77,7 @@ public:
KDbusImageVector IconPixmap() const;
public Q_SLOTS:
//interaction
// interaction
/**
* Shows the context menu associated to this item
* at the desired screen position
@ -142,21 +132,22 @@ Q_SIGNALS:
private:
enum InjectMode {
Direct,
XTest
XTest,
};
QSize calculateClientWindowSize() const;
void sendClick(uint8_t mouseButton, int x, int y);
QImage getImageNonComposite() const;
bool isTransparentImage(const QImage &image) const;
QImage convertFromNative(xcb_image_t *xcbImage) const;
QPoint calculateClickPoint() const;
void stackContainerWindow(const uint32_t stackMode) const;
QDBusConnection m_dbus;
xcb_window_t m_windowId;
xcb_window_t m_containerWid;
static int s_serviceCount;
QPixmap m_pixmap;
bool sendingClickEvent;
InjectMode m_injectMode;
};
#endif // SNIPROXY_H

@ -1,52 +1,40 @@
/********************************************************************
Copyright (C) 2012, 2013 Martin Graesslin <mgraesslin@kde.org>
Copyright (C) 2015 David Edmudson <davidedmundson@kde.org>
/*
SPDX-FileCopyrightText: 2012, 2013 Martin Graesslin <mgraesslin@kde.org>
SPDX-FileCopyrightText: 2015 David Edmudson <davidedmundson@kde.org>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
SPDX-License-Identifier: GPL-2.0-or-later
*/
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
#pragma once
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*********************************************************************/
#ifndef KWIN_XCB_UTILS_H
#define KWIN_XCB_UTILS_H
#include <xcb/xcb.h>
#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 <xcb/damage.h>
#include <QScopedPointer>
#include <QVector>
#include <QX11Info>
/** 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 {
#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;
template <typename T> using ScopedCPointer = QScopedPointer<T, QScopedPointerPodDeleter>;
template<typename T>
using ScopedCPointer = QScopedPointer<T, QScopedPointerPodDeleter>;
class Atom
{
@ -57,36 +45,42 @@ public:
, 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() {
~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();
operator xcb_atom_t() const
{
(const_cast<Atom *>(this))->getReply();
return m_atom;
}
bool isValid() {
bool isValid()
{
getReply();
return m_atom != XCB_ATOM_NONE;
}
bool isValid() const {
(const_cast<Atom*>(this))->getReply();
bool isValid() const
{
(const_cast<Atom *>(this))->getReply();
return m_atom != XCB_ATOM_NONE;
}
inline const QByteArray &name() const {
inline const QByteArray &name() const
{
return m_name;
}
private:
void getReply() {
void getReply()
{
if (m_retrieved || !m_cookie.sequence) {
return;
}
@ -103,15 +97,17 @@ private:
QByteArray m_name;
};
class Atoms {
class Atoms
{
public:
Atoms() :
xembedAtom("_XEMBED"),
selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", QX11Info::appScreen())),
opcodeAtom("_NET_SYSTEM_TRAY_OPCODE"),
messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA"),
visualAtom("_NET_SYSTEM_TRAY_VISUAL")
{}
Atoms()
: xembedAtom("_XEMBED")
, selectionAtom(xcb_atom_name_by_screen("_NET_SYSTEM_TRAY", QX11Info::appScreen()))
, opcodeAtom("_NET_SYSTEM_TRAY_OPCODE")
, messageData("_NET_SYSTEM_TRAY_MESSAGE_DATA")
, visualAtom("_NET_SYSTEM_TRAY_VISUAL")
{
}
Atom xembedAtom;
Atom selectionAtom;
@ -120,8 +116,6 @@ public:
Atom visualAtom;
};
extern Atoms* atoms;
extern Atoms *atoms;
} // namespace Xcb
#endif // KWIN_XCB_UTILS_H

@ -1,25 +1,12 @@
/* Wrap XLIB code in a new file as it defines keywords that conflict with Qt
*
* Copyright (C) 2017 <davidedmundson@kde.org> David Edmundson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#include <X11/extensions/XTest.h>
SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "xtestsender.h"
#include <X11/extensions/XTest.h>
void sendXTestPressed(Display *display, int button)
{

@ -1,28 +1,12 @@
/* Wrap XLIB code in a new file as it defines keywords that conflict with Qt
*
* Copyright (C) 2017 <davidedmundson@kde.org> David Edmundson
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef XTEST_SENDER_H
#define XTEST_SENDER_H
typedef _XDisplay Display;
SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org>
SPDX-License-Identifier: LGPL-2.1-or-later
*/
#pragma once
typedef struct _XDisplay Display;
void sendXTestPressed(Display *display, int button);
void sendXTestReleased(Display *display, int button);
#endif

Loading…
Cancel
Save