Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump version to 1.0.9 #233

Merged
merged 3 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
dde-tray-loader (1.0.9) unstable; urgency=medium

* fix: submenu position not right
* fix: small black block when there is no compositor

-- xionglinlin <[email protected]> Tue, 31 Dec 2024 11:47:27 +0800

dde-tray-loader (1.0.8) unstable; urgency=medium

* fix: unable to click application tray border
Expand Down
2 changes: 1 addition & 1 deletion plugins/application-tray/traywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ TrayWidget::TrayWidget(QPointer<AbstractTrayProtocolHandler> handler)
setFixedSize(trayIconSize, trayIconSize);

m_handler->setParent(this);
setMouseTracking(true);

connect(m_handler, &AbstractTrayProtocolHandler::iconChanged, this, [this](){update();});
connect(m_handler, &AbstractTrayProtocolHandler::overlayIconChanged, this, [this](){update();});
Expand All @@ -49,6 +48,7 @@ void TrayWidget::showEvent(QShowEvent* event)
{
m_handler->setWindow(window());
window()->installEventFilter(m_handler);
window()->setMouseTracking(true);
}

void TrayWidget::paintEvent(QPaintEvent* event)
Expand Down
15 changes: 15 additions & 0 deletions plugins/application-tray/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include <QDebug>

Check warning on line 5 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QDebug> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include "util.h"
#include "xcbthread.h"

#include <QSize>

Check warning on line 10 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSize> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QPixmap>

Check warning on line 11 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QPixmap> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <QBitmap>
#include <QFileInfo>
#include <QtGlobal>
Expand Down Expand Up @@ -49,6 +50,8 @@
m_rootWindow = screen->root;

xcb_ewmh_init_atoms_replies(&m_ewmh, xcb_ewmh_init_atoms(m_x11connection, &m_ewmh), nullptr);
m_xcbThread = new XcbThread(m_x11connection);

Check warning on line 53 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'Util' does not have a copy constructor which is recommended since it has dynamic memory/resource allocation(s).

Check warning on line 53 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

Class 'Util' does not have a operator= which is recommended since it has dynamic memory/resource allocation(s).
m_xcbThread->start();
}

Util::~Util()
Expand Down Expand Up @@ -359,4 +362,16 @@

return image;
}

QPoint Util::getMousePos() const

Check warning on line 366 in plugins/application-tray/util.cpp

View workflow job for this annotation

GitHub Actions / cppcheck

The function 'getMousePos' is never used.
{
QPoint pos;
xcb_query_pointer_cookie_t cookie = xcb_query_pointer(m_x11connection, m_rootWindow);
QScopedPointer<xcb_query_pointer_reply_t> reply(xcb_query_pointer_reply(m_x11connection, cookie, NULL));
if (reply) {
pos = QPoint(reply->root_x, reply->root_y);
}

return pos;
}
}
7 changes: 5 additions & 2 deletions plugins/application-tray/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@
#include <QHash>
#include <QImage>
#include <QSharedPointer>
#include <QSet>

Check warning on line 10 in plugins/application-tray/util.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <QSet> not found. Please note: Cppcheck does not need standard library headers to get proper results.

#include <cstdint>

Check warning on line 12 in plugins/application-tray/util.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <cstdint> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <mutex>
#include <sys/types.h>

Check warning on line 13 in plugins/application-tray/util.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <sys/types.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <xcb/xcb.h>

Check warning on line 14 in plugins/application-tray/util.h

View workflow job for this annotation

GitHub Actions / cppcheck

Include file: <xcb/xcb.h> not found. Please note: Cppcheck does not need standard library headers to get proper results.
#include <xcb/xproto.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_image.h>
Expand All @@ -21,7 +20,7 @@

namespace tray {
#define UTIL Util::instance()

class XcbThread;
class Util
{

Expand Down Expand Up @@ -51,6 +50,8 @@
QString generateUniqueId(const QString &id);
void removeUniqueId(const QString &id);

QPoint getMousePos() const;

private:
Util();
~Util();
Expand All @@ -68,6 +69,8 @@
_XDisplay *m_display;

QSet<QString> m_currentIds;

XcbThread *m_xcbThread;
};

}
42 changes: 42 additions & 0 deletions plugins/application-tray/xcbthread.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "xcbthread.h"
#include "util.h"

namespace tray {
XcbThread::XcbThread(xcb_connection_t *connection, QObject *parent)
: QThread(parent)
, m_connection(connection)
{
}

XcbThread::~XcbThread()
{
}

void XcbThread::run()
{
if (!m_connection) {
return;
}
// The Xembed type tray needs to reset the xwindow state of the receiving event to the state of not receiving events after the mouse
// leaves. This thread is used to receive the leave event and apply the operation.
QScopedPointer<xcb_generic_event_t> event;
while (!isInterruptionRequested()) {
event.reset(xcb_wait_for_event(m_connection));
if (event) {
uint8_t responseType = event->response_type & ~0x80;
switch (responseType) {
case XCB_LEAVE_NOTIFY: {
xcb_leave_notify_event_t *lE = (xcb_leave_notify_event_t *)event.data();
UTIL->setX11WindowInputShape(lE->event, QSize(0, 0));
break;
}
}
}
}
}
}

22 changes: 22 additions & 0 deletions plugins/application-tray/xcbthread.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-FileCopyrightText: 2024 UnionTech Software Technology Co., Ltd.
//
// SPDX-License-Identifier: GPL-3.0-or-later

#pragma once

#include <QThread>
#include <xcb/xcb.h>

namespace tray {
class XcbThread : public QThread {
Q_OBJECT
public:
XcbThread(xcb_connection_t *connection, QObject *parent = nullptr);
~XcbThread();

void run() override;

private:
xcb_connection_t *m_connection;
};
}
109 changes: 19 additions & 90 deletions plugins/application-tray/xembedprotocolhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//
// SPDX-License-Identifier: GPL-3.0-or-later

#include "plugin.h"
#include "abstracttrayprotocol.h"
#include "traymanager1interface.h"
#include "xembedprotocolhandler.h"
Expand Down Expand Up @@ -99,7 +98,7 @@ XembedProtocolHandler::XembedProtocolHandler(const uint32_t& id, QObject* parent
generateId();

m_hoverTimer->setSingleShot(true);
m_hoverTimer->setInterval(100);
m_hoverTimer->setInterval(500);

m_attentionTimer->setSingleShot(true);
m_attentionTimer->setInterval(100);
Expand Down Expand Up @@ -190,7 +189,7 @@ bool XembedProtocolHandler::eventFilter(QObject *watched, QEvent *event)
if (watched == window()) {
// 有透明通道时,可以做到container一直透明隐藏,就走Enter触发
// 没有透明通道时,走旧dock的方式 QEvent::Move防止在 dock/container 之前一直切换
if ((event->type() == QEvent::Enter)) {
if ((event->type() == QEvent::MouseMove)) {
m_hoverTimer->start();
} else if (event->type() == QEvent::Leave && m_hoverTimer->isActive()) {
m_hoverTimer->stop();
Expand All @@ -199,7 +198,7 @@ bool XembedProtocolHandler::eventFilter(QObject *watched, QEvent *event)
m_hoverTimer->stop();
}

auto p = getGlobalPos();
auto p = UTIL->getMousePos();
auto mouseEvent = static_cast<QMouseEvent*>(event);
sendClick(mouseEvent->button(), p.x(), p.y());
}
Expand All @@ -216,15 +215,15 @@ void XembedProtocolHandler::initX11resources()
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_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT;
values[2] = XCB_EVENT_MASK_STRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_NOTIFY | XCB_EVENT_MASK_SUBSTRUCTURE_REDIRECT | XCB_EVENT_MASK_LEAVE_WINDOW | XCB_EVENT_MASK_ENTER_WINDOW;
const auto ratio = qApp->devicePixelRatio();
xcb_create_window(c,
XCB_COPY_FROM_PARENT,
m_containerWid,
screen->root,
0,
0,
trayIconSize * ratio, trayIconSize * ratio,
1, 1,
0,
XCB_WINDOW_CLASS_INPUT_OUTPUT,
screen->root_visual,
Expand All @@ -241,10 +240,8 @@ void XembedProtocolHandler::initX11resources()
xcb_change_save_set(c, XCB_SET_MODE_INSERT, m_windowId);
UTIL->sendXembedMessage(m_windowId, 0, 0, m_containerWid, 0);

QSize clientWindowSize = calculateClientWindowSize();

xcb_map_window(c, m_windowId);
xcb_clear_area(c, 0, m_windowId, 0, 0, clientWindowSize.width(), clientWindowSize.height());
xcb_clear_area(c, 0, m_windowId, 0, 0, 1, 1);
xcb_flush(c);

auto waCookie = xcb_get_window_attributes(c, m_windowId);
Expand All @@ -265,12 +262,6 @@ void XembedProtocolHandler::initX11resources()
});
}

QSize XembedProtocolHandler::calculateClientWindowSize() const
{
auto size = UTIL->getX11WindowSize(m_containerWid);
return (size.isEmpty() || size.width() > trayIconSize || size.height() > trayIconSize) ? QSize(trayIconSize, trayIconSize) : size;
}

QPixmap XembedProtocolHandler::getPixmapFromWidnow()
{
QPixmap res;
Expand All @@ -290,43 +281,26 @@ QPixmap XembedProtocolHandler::getPixmapFromWidnow()
return res;
}

QPoint XembedProtocolHandler::getGlobalPos()
{
int x = 0, y = 0;
auto widget = static_cast<QWidget*>(parent());
if (!widget) return QPoint();

auto plugin = Plugin::EmbedPlugin::get(widget->window()->windowHandle());
if (!plugin) return QPoint();

return plugin->rawGlobalPos();
}

void XembedProtocolHandler::updateEmbedWindowPosForGetInputEvent()
{
// update pos
QPoint p = getGlobalPos();
const QPoint clickPoint = calculateClickPoint();
uint32_t configVals[2] = {0, 0};
configVals[0] = static_cast<uint32_t>(p.x() + clickPoint.x());
configVals[1] = static_cast<uint32_t>(p.y() + clickPoint.y());
UTIL->moveX11Window(m_containerWid, configVals[0], configVals[1]);
QPoint p = UTIL->getMousePos();
UTIL->moveX11Window(m_containerWid, p.x(), p.y());

// make window normal and above for get input
UTIL->setX11WindowInputShape(m_containerWid, QSize(trayIconSize, trayIconSize));
UTIL->setX11WindowInputShape(m_containerWid, QSize(1, 1));
}

void XembedProtocolHandler::sendHover()
{
updateEmbedWindowPosForGetInputEvent();

Display *display = UTIL->getDisplay();
QPoint p = getGlobalPos();
const QPoint clickPoint = calculateClickPoint();
QPoint p = UTIL->getMousePos();

if (m_injectMode == XTest) {
// fake enter event
XTestFakeRelativeMotionEvent(display, 0, 0, CurrentTime);
XTestFakeMotionEvent(display, 0, p.x(), p.y(), CurrentTime);
XFlush(display);
} else {
// 发送 montion notify event到client,实现hover事件
Expand All @@ -339,18 +313,14 @@ void XembedProtocolHandler::sendHover()
event->time = 0;
event->root_x = p.x();
event->root_y = p.y();
event->event_x = clickPoint.x();
event->event_y = clickPoint.y();
event->event_x = 0;
event->event_y = 0;
event->child = 0;
event->state = 0;
xcb_send_event(UTIL->getX11Connection(), false, m_windowId, XCB_EVENT_MASK_POINTER_MOTION, (char*)event);
delete event;
xcb_flush(UTIL->getX11Connection());
}

QTimer::singleShot(100,[this](){
UTIL->setX11WindowInputShape(m_containerWid, QSize(0, 0));
});
}

void XembedProtocolHandler::sendClick(uint8_t qMouseButton, const int& x, const int& y)
Expand All @@ -376,9 +346,7 @@ void XembedProtocolHandler::sendClick(uint8_t qMouseButton, const int& x, const
}

updateEmbedWindowPosForGetInputEvent();
UTIL->setX11WindowInputShape(m_containerWid, QSize(trayIconSize, trayIconSize));
QPoint p = getGlobalPos();
const QPoint clickPoint = calculateClickPoint();
UTIL->setX11WindowInputShape(m_containerWid, QSize(1, 1));

if (m_injectMode == Direct) {
QSharedPointer<xcb_button_press_event_t> pressEvent =QSharedPointer<xcb_button_press_event_t>(new xcb_button_press_event_t);
Expand All @@ -390,8 +358,8 @@ void XembedProtocolHandler::sendClick(uint8_t qMouseButton, const int& x, const
pressEvent->root = Util::instance()->getRootWindow();
pressEvent->root_x = x;
pressEvent->root_y = y;
pressEvent->event_x = static_cast<int16_t>(clickPoint.x());
pressEvent->event_y = static_cast<int16_t>(clickPoint.y());
pressEvent->event_x = static_cast<int16_t>(0);
pressEvent->event_y = static_cast<int16_t>(0);
pressEvent->child = 0;
pressEvent->state = 0;
pressEvent->detail = mouseButton;
Expand All @@ -406,14 +374,14 @@ void XembedProtocolHandler::sendClick(uint8_t qMouseButton, const int& x, const
releaseEvent->root = Util::instance()->getRootWindow();
releaseEvent->root_x = x;
releaseEvent->root_y = y;
releaseEvent->event_x = static_cast<int16_t>(clickPoint.x());
releaseEvent->event_y = static_cast<int16_t>(clickPoint.y());
releaseEvent->event_x = static_cast<int16_t>(0);
releaseEvent->event_y = static_cast<int16_t>(0);
releaseEvent->child = 0;
releaseEvent->state = 0;
releaseEvent->detail = mouseButton;
xcb_send_event(c, false, m_windowId, XCB_EVENT_MASK_BUTTON_RELEASE, (char *)releaseEvent.get());
} else {
XTestFakeRelativeMotionEvent(dis, 0, 0, 0);
XTestFakeMotionEvent(dis, 0, x, y, CurrentTime);
XFlush(dis);
XTestFakeButtonEvent(dis, mouseButton, true, 0);
XFlush(dis);
Expand All @@ -426,43 +394,4 @@ void XembedProtocolHandler::sendClick(uint8_t qMouseButton, const int& x, const
UTIL->setX11WindowInputShape(m_containerWid, QSize(0, 0));
});
}

// from kde/plasma-workspace/xembed-sni-proxy
QPoint XembedProtocolHandler::calculateClickPoint() const
{
QSize clientSize = calculateClientWindowSize();
QPoint clickPoint = QPoint(clientSize.width() / 2, clientSize.height() / 2);

auto c = Util::instance()->getX11Connection();

xcb_shape_query_extents_cookie_t extentsCookie = xcb_shape_query_extents(c, m_windowId);
xcb_shape_get_rectangles_cookie_t rectaglesCookie = xcb_shape_get_rectangles(c, m_windowId, XCB_SHAPE_SK_BOUNDING);

QSharedPointer<xcb_shape_query_extents_reply_t> extentsReply(xcb_shape_query_extents_reply(c, extentsCookie, nullptr));
QSharedPointer<xcb_shape_get_rectangles_reply_t> 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 = UTIL->getX11WidnowImageNonComposite(m_windowId);

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);
}
}

return clickPoint;
}

}
Loading
Loading