Skip to content

Commit

Permalink
fix: duplicate tray for some app
Browse files Browse the repository at this point in the history
some gtk apps use libayatana-appindicator create tray will create xembed and sni duplicate tray
not show sni tray which path contains /org/ayatana/NotificationItem/ created by ayatana-appindicator

log: not show ayatana-appindicator sni tray on xorg
  • Loading branch information
tsic404 committed Mar 4, 2024
1 parent 1653473 commit eb7e8fb
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 46 deletions.
7 changes: 7 additions & 0 deletions frame/window/tray/tray_monitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "tray_monitor.h"
#include "quicksettingcontroller.h"
#include "pluginsiteminterface.h"
#include "utils.h"

TrayMonitor::TrayMonitor(QObject *parent)
: QObject(parent)
Expand Down Expand Up @@ -110,6 +111,12 @@ void TrayMonitor::onSniItemsChanged()
qWarning() << __FUNCTION__ << "invalid sni service" << s;
continue;
}

if (!Utils::IS_WAYLAND_DISPLAY && s.contains("/org/ayatana/NotificationItem/")) {
qDebug() << "SNI service path created by libayatana-appindicator, duplicate tray with legacy tray";
continue;
}

Q_EMIT sniTrayAdded(s);
}
}
Expand Down
11 changes: 0 additions & 11 deletions frame/window/tray/widgets/basetraywidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
BaseTrayWidget::BaseTrayWidget(QWidget *parent, Qt::WindowFlags f)
: QWidget(parent, f)
, m_handleMouseReleaseTimer(new QTimer(this))
, m_ownerPID(0)
, m_needShow(true)
{
m_handleMouseReleaseTimer->setSingleShot(true);
Expand Down Expand Up @@ -116,11 +115,6 @@ void BaseTrayWidget::resizeEvent(QResizeEvent *event)
}
}

uint BaseTrayWidget::getOwnerPID()
{
return this->m_ownerPID;
}

bool BaseTrayWidget::needShow()
{
return m_needShow;
Expand All @@ -139,8 +133,3 @@ void BaseTrayWidget::setNeedShow(bool needShow)

update();
}

void BaseTrayWidget::setOwnerPID(uint PID)
{
this->m_ownerPID = PID;
}
3 changes: 0 additions & 3 deletions frame/window/tray/widgets/basetraywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class BaseTrayWidget : public QWidget
virtual void sendClick(uint8_t mouseButton, int x, int y) = 0;
virtual inline TrayType trayType() const { return TrayType::ApplicationTray; } // default is ApplicationTray
virtual bool isValid() {return true;}
uint getOwnerPID();
virtual bool needShow();
virtual void setNeedShow(bool needShow);
virtual QPixmap icon() = 0;
Expand All @@ -48,14 +47,12 @@ class BaseTrayWidget : public QWidget
void handleMouseRelease();
const QRect perfectIconRect() const;
void resizeEvent(QResizeEvent *event) override;
void setOwnerPID(uint PID);

private:
QTimer *m_handleMouseReleaseTimer;

QPair<QPoint, Qt::MouseButton> m_lastMouseReleaseData;

uint m_ownerPID;
bool m_needShow;
};

1 change: 0 additions & 1 deletion frame/window/tray/widgets/snitrayitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ SNITrayItemWidget::SNITrayItemWidget(const QString &sniServicePath, QWidget *par
m_dbusPath = pair.second;

QDBusConnection conn = QDBusConnection::sessionBus();
setOwnerPID(conn.interface()->servicePid(m_dbusService));

m_sniInter = new StatusNotifierItem(m_dbusService, m_dbusPath, QDBusConnection::sessionBus(), this);
m_sniInter->setSync(false);
Expand Down
30 changes: 0 additions & 30 deletions frame/window/tray/widgets/xembedtrayitemwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ XEmbedTrayItemWidget::XEmbedTrayItemWidget(quint32 winId, xcb_connection_t *cnn,
, m_display(disp)
{
wrapWindow();
setOwnerPID(getWindowPID(winId));

m_updateTimer = new QTimer(this);
m_updateTimer->setInterval(100);
Expand Down Expand Up @@ -521,32 +520,3 @@ bool XEmbedTrayItemWidget::isBadWindow()

return result;
}

uint XEmbedTrayItemWidget::getWindowPID(uint winId)
{
const auto display = IS_WAYLAND_DISPLAY ? XOpenDisplay(nullptr) : QX11Info::display();
if (!display) {
qWarning() << "QX11Info::connection() is " << display;
return 0;
}

Atom nameAtom = XInternAtom(display, "_NET_WM_PID", 1);
Atom type;
int format, status;

unsigned long nitems, after;
unsigned char *data;
unsigned int pid = 0;

status = XGetWindowProperty(display, winId, nameAtom, 0, 1024, 0,
XInternAtom(display, "CARDINAL", 0), &type, &format, &nitems, &after, &data);
if (status == Success && data) {
pid = *((uint*)data);
XFree(data);
}

if (IS_WAYLAND_DISPLAY)
XCloseDisplay(display);

return pid;
}
1 change: 0 additions & 1 deletion frame/window/tray/widgets/xembedtrayitemwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ class XEmbedTrayItemWidget : public BaseTrayWidget
void sendClick(uint8_t mouseButton, int x, int y) override;

static QString toXEmbedKey(quint32 winId);
static uint getWindowPID(quint32 winId);
static bool isXEmbedKey(const QString &itemKey);
virtual bool isValid() override {return m_valid;}
QPixmap icon() override;
Expand Down

0 comments on commit eb7e8fb

Please sign in to comment.