Skip to content
Open
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
31 changes: 29 additions & 2 deletions plugins/application-tray/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void Util::dispatchEvents(DispatchEventsMode mode)
qCWarning(TRAYUTIL, "Attempting to dispatch X11 events with no connection");
return;
}
if (m_x11ConnectionFailed || handleX11ConnectionError()) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_x11ConnectionFailed 这个在handleX11ConnectionError里已经判断了,上面的connection判断也可以去掉了吧,

return;
}

auto pollEventFunc = mode == DispatchEventsMode::Poll ? xcb_poll_for_event : xcb_poll_for_queued_event;

Expand All @@ -60,7 +63,31 @@ void Util::dispatchEvents(DispatchEventsMode mode)
free(event);
}

if (handleX11ConnectionError()) {
return;
}

xcb_flush(connection);
handleX11ConnectionError();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

需要判断这么多次么?

}

bool Util::handleX11ConnectionError()
{
if (m_x11ConnectionFailed || !m_x11connection) {
return m_x11ConnectionFailed;
}

const int error = xcb_connection_has_error(m_x11connection);
if (error == 0) {
return false;
}

m_x11ConnectionFailed = true;
if (m_x11EventNotifier) {
m_x11EventNotifier->setEnabled(false);
}
qCWarning(TRAYUTIL) << "X11 connection failed; disabling event notifier. Error:" << error;
return true;
}

Util::Util()
Expand All @@ -80,8 +107,8 @@ Util::Util()
xcb_ewmh_init_atoms_replies(&m_ewmh, xcb_ewmh_init_atoms(m_x11connection, &m_ewmh), nullptr);

const int fd = xcb_get_file_descriptor(m_x11connection);
QSocketNotifier * qfd = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(qfd, &QSocketNotifier::activated, this, [this](){
m_x11EventNotifier = new QSocketNotifier(fd, QSocketNotifier::Read, this);
connect(m_x11EventNotifier, &QSocketNotifier::activated, this, [this](){
dispatchEvents(DispatchEventsMode::Poll);
});

Expand Down
4 changes: 4 additions & 0 deletions plugins/application-tray/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
#include <xcb/xcb.h>
#include <xcb/xproto.h>
#include <xcb/xcb_ewmh.h>
#include <xcb/xcb_image.h>

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

View workflow job for this annotation

GitHub Actions / cppcheck

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

struct _XDisplay;
class QSocketNotifier;

namespace tray {
#define UTIL Util::instance()
Expand Down Expand Up @@ -69,6 +70,7 @@
EventQueue
};
void dispatchEvents(DispatchEventsMode mode);
bool handleX11ConnectionError();

bool isTransparentImage(const QImage &image);

Expand All @@ -81,6 +83,8 @@
xcb_connection_t* m_x11connection;
xcb_window_t m_rootWindow;
_XDisplay *m_display;
QSocketNotifier *m_x11EventNotifier = nullptr;
bool m_x11ConnectionFailed = false;

QSet<QString> m_currentIds;
QMutex m_idMutex;
Expand Down
Loading