Skip to content

Commit

Permalink
qt5 compat fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Ri0n committed Mar 14, 2024
1 parent d668704 commit 694f428
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 22 deletions.
15 changes: 1 addition & 14 deletions src/common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,20 +467,7 @@ void bringToFront(QWidget *widget, bool)
QWidget *w = widget->window();

#ifdef HAVE_X11
if (QX11Info::isPlatformX11()) {
// If we're not on the current desktop, do the hide/show trick
long dsk, curr_dsk;
Window win = w->winId();
if (X11WindowSystem::instance()->desktopOfWindow(&win, &dsk)
&& X11WindowSystem::instance()->currentDesktop(&curr_dsk)) {
// qDebug() << "bringToFront current desktop=" << curr_dsk << " windowDesktop=" << dsk;
if ((dsk != curr_dsk) && (dsk != -1)) { // second condition for sticky windows
w->hide();
}
}
}

// FIXME: multi-desktop hacks for Win and Mac required
X11WindowSystem::instance()->bringToFront(w);
#endif

if (w->isMaximized()) {
Expand Down
3 changes: 1 addition & 2 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ TabbableWidget *findActiveTab();
#include "x11windowsystem.h"
#define X11WM_CLASS(x) \
{ \
if (QX11Info::isPlatformX11()) \
X11WindowSystem::instance()->x11wmClass(winId(), (x)); \
X11WindowSystem::instance()->x11wmClass(winId(), (x)); \
};
#else
#define X11WM_CLASS(x) /* dummy */
Expand Down
2 changes: 1 addition & 1 deletion src/contactmanager/contactmanagermodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void ContactManagerModel::invertByMatch(int columnIndex, int matchType, const QS
for (UserListItem *u : std::as_const(_userList)) {
data = userFieldString(u, columnRole);
if ((matchType == ContactManagerModel::SimpleMatch && str == data)
|| (matchType == ContactManagerModel::RegexpMatch && reg.indexIn(data) != -1)) {
|| (matchType == ContactManagerModel::RegexpMatch && reg.match(data).hasMatch())) {
QString jid = u->jid().full();
if (checks.contains(jid)) {
checks.remove(jid);
Expand Down
5 changes: 3 additions & 2 deletions src/mainwin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1578,9 +1578,10 @@ void MainWin::toggleVisible(bool fromTray)
}
#elif defined(HAVE_X11)
Q_UNUSED(fromTray);
if (QX11Info::isPlatformX11()) {
auto x11 = X11WindowSystem::instance();
if (x11->isValid()) {
hidden = isHidden()
|| X11WindowSystem::instance()->isWindowObscured(
|| x11->isWindowObscured(
this, PsiOptions::instance()->getOption("options.ui.contactlist.always-on-top").toBool());
} else {
hidden = isHidden() || !isActiveWindow();
Expand Down
1 change: 1 addition & 0 deletions src/mcmdmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "mcmdmanager.h"

#include <QDebug>
#include <QRegularExpression>

MCmdSimpleState::MCmdSimpleState(QString name, QString prompt) : name_(name), prompt_(prompt), flags_(0) { }

Expand Down
5 changes: 3 additions & 2 deletions src/msgmle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,9 @@ public slots:
return;
} else {
QRegularExpression capitalizeAfter("(?:^[^.][.]+\\s+)|(?:\\s*[^.]{2,}[.]+\\s+)|(?:[!?]\\s+)");
int index = te_->toPlainText().lastIndexOf(capitalizeAfter);
if (index != -1 && index == pos - capitalizeAfter.matchedLength()) {
QRegularExpressionMatch match;
int index = te_->toPlainText().lastIndexOf(capitalizeAfter, 0, &match);
if (index != -1 && index == pos - match.capturedLength()) {
capitalizeNext_ = true;
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/x11windowsystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
const long MAX_PROP_SIZE = 100000;
X11WindowSystem *X11WindowSystem::_instance = nullptr;

bool X11WindowSystem::isValid() const {
return QX11Info::isPlatformX11();
}

void X11WindowSystem::x11wmClass(WId wid, QString resName)
{
#if defined(LIMIT_X11_USAGE)
Expand All @@ -30,6 +34,24 @@ void X11WindowSystem::x11wmClass(WId wid, QString resName)
XFree(classhint.res_class);
}

void X11WindowSystem::bringToFront(QWidget *w)
{
if (QX11Info::isPlatformX11()) {
// If we're not on the current desktop, do the hide/show trick
long dsk, curr_dsk;
Window win = w->winId();
if (X11WindowSystem::instance()->desktopOfWindow(&win, &dsk)
&& X11WindowSystem::instance()->currentDesktop(&curr_dsk)) {
// qDebug() << "bringToFront current desktop=" << curr_dsk << " windowDesktop=" << dsk;
if ((dsk != curr_dsk) && (dsk != -1)) { // second condition for sticky windows
w->hide();
}
}
}

// FIXME: multi-desktop hacks for Win and Mac required
}

//>>>-- Nathaniel Gray -- Caltech Computer Science ------>
//>>>-- Mojave Project -- http://mojave.cs.caltech.edu -->
// Copied from http://www.nedit.org/archives/discuss/2002-Aug/0386.html
Expand Down
3 changes: 2 additions & 1 deletion src/x11windowsystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#include <QRect>
#include <QSet>
#include <QWidget>
//#include <QX11Info>
#include <QtCore>

// TODO: Find a way to include Xlib here and not redefine Atom and Window types
Expand Down Expand Up @@ -36,13 +35,15 @@ class X11WindowSystem {

public:
static X11WindowSystem *instance();
bool isValid() const;
QRect windowRect(Window win);
bool isWindowObscured(QWidget *widget, bool alwaysOnTop);
bool windowHasOnlyTypes(Window win, const QSet<Atom> &allowedTypes);
bool windowHasAnyOfStates(Window win, const QSet<Atom> &filteredStates);
bool currentDesktop(long *desktop);
bool desktopOfWindow(Window *window, long *desktop);
void x11wmClass(WId wid, QString resName);
void bringToFront(QWidget *w);
};

#endif // X11WINDOWSYSTEM_H

0 comments on commit 694f428

Please sign in to comment.