1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
|
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2.1+
*
* LXQt - a lightweight, Qt based, desktop toolset
* https://lxqt.org
*
* Copyright: 2015 David Edmundson <davidedmundson@kde.org>
* 2019 Konrad Materka <materka@gmail.com>
* 2022 LXQt team
*
* This program or 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
*
* END_COMMON_COPYRIGHT_HEADER */
#pragma once
#include <QDBusArgument>
#include <QDBusConnection>
#include <QDBusObjectPath>
#include <QObject>
#include <QImage>
#include <QPoint>
#include <xcb/xcb.h>
#include <xcb/xcb_image.h>
#include "snidbus.h"
namespace Xcb {
class Atoms;
}
class SNIProxy : public QObject
{
Q_OBJECT
Q_PROPERTY(QString Category READ Category)
Q_PROPERTY(QString Id READ Id)
Q_PROPERTY(QString Title READ Title)
Q_PROPERTY(QString Status READ Status)
Q_PROPERTY(int WindowId READ WindowId)
Q_PROPERTY(bool ItemIsMenu READ ItemIsMenu)
Q_PROPERTY(KDbusImageVector IconPixmap READ IconPixmap)
public:
explicit SNIProxy(xcb_window_t wid, Xcb::Atoms & atoms, QObject *parent = nullptr);
~SNIProxy() override;
void update();
void resizeWindow(const uint16_t width, const uint16_t height) const;
void hideContainerWindow(xcb_window_t windowId) const;
inline void vanished(bool vanished) { m_vanished = vanished; }
/**
* @return the category of the application associated to this item
* @see Category
*/
QString Category() const;
/**
* @return the id of this item
*/
QString Id() const;
/**
* @return the title of this item
*/
QString Title() const;
/**
* @return The status of this item
* @see Status
*/
QString Status() const;
/**
* @return The id of the main window of the application that controls the item
*/
int WindowId() const;
/**
* @return The item only support the context menu, the visualization should prefer sending ContextMenu() instead of Activate()
*/
bool ItemIsMenu() const;
/**
* @return a serialization of the icon data
*/
KDbusImageVector IconPixmap() const;
public Q_SLOTS:
// interaction
/**
* Shows the context menu associated to this item
* at the desired screen position
*/
void ContextMenu(int x, int y);
/**
* Shows the main widget and try to position it on top
* of the other windows, if the widget is already visible, hide it.
*/
void Activate(int x, int y);
/**
* The user activated the item in an alternate way (for instance with middle mouse button, this depends from the systray implementation)
*/
void SecondaryActivate(int x, int y);
/**
* Inform this item that the mouse wheel was used on its representation
*/
void Scroll(int delta, const QString &orientation);
Q_SIGNALS:
/**
* Inform the systemtray that the own main icon has been changed,
* so should be reloaded
*/
void NewIcon();
/**
* Inform the systemtray that there is a new icon to be used as overlay
*/
void NewOverlayIcon();
/**
* Inform the systemtray that the requesting attention icon
* has been changed, so should be reloaded
*/
void NewAttentionIcon();
/**
* Inform the systemtray that something in the tooltip has been changed
*/
void NewToolTip();
/**
* Signal the new status when it has been changed
* @see Status
*/
void NewStatus(const QString &status);
private:
enum InjectMode {
Direct,
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_connection_t *m_connection;
xcb_window_t m_windowId;
xcb_window_t m_containerWid;
static int s_serviceCount;
QImage m_windowImage;
QImage m_iconImage;
bool sendingClickEvent;
InjectMode m_injectMode;
Xcb::Atoms & m_atoms;
bool m_vanished = false;
};
|