Skip to content

Commit

Permalink
Exclude QX11Info usage on Linux using Qt 6
Browse files Browse the repository at this point in the history
QX11Info has been removed in Qt 6. Seems we should use X11/Xlib.h for
X11 types.
  • Loading branch information
bear101 committed Oct 29, 2024
1 parent 22c83d6 commit 619761d
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 79 deletions.
3 changes: 3 additions & 0 deletions Client/qtTeamTalk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ if (Qt5_FOUND OR Qt6_FOUND)

if (Qt6_FOUND)
set (TEAMTALK_LINK_FLAGS Qt6::Widgets Qt6::Xml Qt6::Network Qt6::Multimedia Qt6::TextToSpeech)
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
list (APPEND TEAMTALK_LINK_FLAGS Qt6::DBus -lX11 -lXss)
endif()
else()
if (${CMAKE_SYSTEM_NAME} MATCHES "Linux")
set (TEAMTALK_LINK_FLAGS Qt5::Widgets Qt5::Xml Qt5::Network Qt5::Multimedia Qt5::TextToSpeech Qt5::DBus Qt5::X11Extras -lX11 -lXss)
Expand Down
6 changes: 3 additions & 3 deletions Client/qtTeamTalk/desktopsharedlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ DesktopShareDlg::DesktopShareDlg(QWidget* parent)
while(TT_MacOS_GetWindow(i++, &wnd))
{
if(_Q(wnd.szWindowTitle).size())
ui.windowComboBox->addItem(_Q(wnd.szWindowTitle) +
ui.windowComboBox->addItem(_Q(wnd.szWindowTitle) +
QString(" - (%1x%2)").arg(wnd.nWidth)
.arg(wnd.nHeight), (qint64)wnd.nWindowID);
}
Expand All @@ -99,7 +99,7 @@ DesktopShareDlg::DesktopShareDlg(QWidget* parent)
// ZERO_STRUCT(attr);
// Status s_attr = XGetWindowAttributes(m_display, children[i], &attr);
// ui.windowComboBox->addItem(QString("%1 - (%2x%3)")
// .arg(str).arg(attr.width).arg(attr.height),
// .arg(str).arg(attr.width).arg(attr.height),
// (qint64)children[i]);
// XFree(str);
// }
Expand Down Expand Up @@ -212,7 +212,7 @@ void DesktopShareDlg::accept()
else
ttSettings->setValue(SETTINGS_DESKTOPSHARE_INTERVAL, 0);

ttSettings->setValue(SETTINGS_DESKTOPSHARE_BMPMODE,
ttSettings->setValue(SETTINGS_DESKTOPSHARE_BMPMODE,
ui.rgbComboBox->itemData(ui.rgbComboBox->currentIndex()));

ttSettings->setValue(SETTINGS_DESKTOPSHARE_CURSOR, ui.cursorChkBox->isChecked());
Expand Down
8 changes: 2 additions & 6 deletions Client/qtTeamTalk/desktopsharedlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,7 @@
#include "ui_desktopshare.h"

#include "common.h"

#ifdef Q_OS_LINUX
#include <QX11Info>
#endif
#include "utilos.h"

class DesktopShareDlg : public QDialog
{
Expand All @@ -51,7 +48,6 @@ class DesktopShareDlg : public QDialog
#if defined(Q_OS_LINUX)
Display* m_display;
#endif
};
};

#endif

52 changes: 4 additions & 48 deletions Client/qtTeamTalk/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ class MyQApplication

#elif defined(Q_OS_LINUX)

//For hotkeys on X11
#include <QX11Info>
#include <X11/Xlib.h>
#include <xcb/xcb.h> // used by Qt5

Expand Down Expand Up @@ -129,7 +127,11 @@ class MyQApplication : public QApplication
, public QAbstractNativeEventFilter
{
public:
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
bool nativeEventFilter(const QByteArray &eventType, void *message, long *result)
#else
bool nativeEventFilter(const QByteArray &eventType, void *message, qintptr *result)
#endif
{
Q_UNUSED(result);

Expand Down Expand Up @@ -169,52 +171,6 @@ class MyQApplication : public QApplication
installNativeEventFilter(this);
}

bool x11EventFilter ( XEvent * event )
{
if(event->type == KeyPress || event->type == KeyRelease)
{
XKeyEvent* key = reinterpret_cast<XKeyEvent*> (event);

bool autor = false;
static uint curr_autorep = 0;
if (event->type == KeyPress)
{
if (curr_autorep == event->xkey.keycode)
{
autor = true;
curr_autorep = 0;
}
}
else
{
// look ahead for auto-repeat
XEvent nextpress;

Display* dpy = QX11Info::display();

// was this the last auto-repeater?
x_auto_repeat_data auto_repeat_data;
auto_repeat_data.keycode = event->xkey.keycode;
auto_repeat_data.timestamp = event->xkey.time;

auto_repeat_data.release = true;
auto_repeat_data.error = false;
if (XCheckIfEvent(dpy, &nextpress, &qt_keypress_scanner,
(XPointer) &auto_repeat_data))
{
autor = true;
XPutBackEvent(dpy,&nextpress);
}

curr_autorep = autor ? event->xkey.keycode : 0;
}

if(!autor)
m_mainwindow->keysActive(key->keycode, key->state, event->type == KeyPress);
}

return true; //x11EventFilter is not supported in Qt5, so just return true
}
MainWindow* m_mainwindow;
};

Expand Down
18 changes: 9 additions & 9 deletions Client/qtTeamTalk/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
#include <QTextToSpeech>
#endif

#ifdef Q_OS_LINUX //For hotkeys and DBus on X11
#if defined(Q_OS_LINUX) //For hotkeys and DBus on X11
#include <QtDBus/QtDBus>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
Expand Down Expand Up @@ -627,7 +627,7 @@ MainWindow::MainWindow(const QString& cfgfile)

MainWindow::~MainWindow()
{
#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX)
if(m_display)
XCloseDisplay(m_display);
#endif
Expand Down Expand Up @@ -2327,7 +2327,7 @@ void MainWindow::showTTErrorMessage(const ClientErrorMsg& msg, CommandComplete c
}
}

#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX)
void MainWindow::keysActive(quint32 keycode, quint32 mods, bool active)
{
keycomp_t comp;
Expand Down Expand Up @@ -3353,7 +3353,7 @@ bool MainWindow::sendDesktopWindow()
#elif defined(Q_OS_LINUX)
{
if(!m_display)
m_display = XOpenDisplay(0);
m_display = XOpenDisplay(nullptr);

if(!m_display)
return false;
Expand Down Expand Up @@ -3691,10 +3691,10 @@ void MainWindow::enableHotKey(HotKeyID id, const hotkey_t& hk)
//disable first so we don't double register
disableHotKey(id);

#ifdef Q_OS_WIN32
#if defined(Q_OS_WIN32)
TT_HotKey_Register(ttInst, id, &hk[0], INT32(hk.size()));

#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)

Display* display = QX11Info::display();
Window x11window = QX11Info::appRootWindow();
Expand Down Expand Up @@ -3774,11 +3774,11 @@ void MainWindow::enableHotKey(HotKeyID id, const hotkey_t& hk)

void MainWindow::disableHotKey(HotKeyID id)
{
#ifdef Q_OS_WIN32
#if defined(Q_OS_WIN32)

TT_HotKey_Unregister(ttInst, id);

#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)

Display* display = QX11Info::display();
Window window = QX11Info::appRootWindow();
Expand Down Expand Up @@ -4640,7 +4640,7 @@ void MainWindow::slotMeEnableDesktopSharing(bool checked/*=false*/)
{
#if defined(Q_OS_LINUX)
if(!m_display)
m_display = XOpenDisplay(0);
m_display = XOpenDisplay(nullptr);

if(!m_display)
QMessageBox::critical(this, MENUTEXT(ui.actionEnableDesktopSharing->text()),
Expand Down
24 changes: 11 additions & 13 deletions Client/qtTeamTalk/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@

#include "ui_mainwindow.h"

#include "common.h"
#include "textmessagecontainer.h"
#include "utilhotkey.h"
#include "utilos.h"
#include "utilsound.h"
#include "utilui.h"

#include <QMap>
#include <QSet>
#include <QQueue>
Expand All @@ -28,16 +35,6 @@
#include <QSortFilterProxyModel>
#include <optional>

#include "common.h"
#include "textmessagecontainer.h"
#include "utilsound.h"
#include "utilui.h"
#include "utilhotkey.h"

#ifdef Q_OS_LINUX
#include <QX11Info>
#endif

#if defined(Q_OS_DARWIN)
#include <Carbon/Carbon.h>
#endif
Expand Down Expand Up @@ -86,15 +83,15 @@ enum
class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(const QString& cfgfile);
~MainWindow();

void loadSettings();

bool parseArgs(const QStringList& args);
#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX)
//X11 hotkeys
void keysActive(quint32 keycode, quint32 mods, bool active);
#endif
Expand Down Expand Up @@ -278,6 +275,7 @@ class MainWindow : public QMainWindow
#if defined(Q_OS_WIN32)
HWND m_hShareWnd;
#endif

#if defined(Q_OS_LINUX)
//set of native key codes
typedef QSet<quint32> keycomp_t;
Expand Down Expand Up @@ -369,7 +367,7 @@ class MainWindow : public QMainWindow
void slotChannelsDownloadFile(bool checked=false);
void slotChannelsDeleteFile(bool checked=false);
void slotChannelsGenerateTTUrl(bool checked=false);

void slotServerUserAccounts(bool checked=false);
void slotServerBannedUsers(bool checked=false);
void slotServerOnlineUsers(bool checked=false);
Expand Down
6 changes: 6 additions & 0 deletions Client/qtTeamTalk/utilos.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
#ifndef UTILOS_H
#define UTILOS_H

#if defined(Q_OS_LINUX)
// Forward declaration of Display because it is not possible to
// include X11/Xlib.h due to namespace collisions.
typedef struct _XDisplay Display;
#endif

bool isComputerIdle(int idle_secs);

#endif // UTILOS_H

0 comments on commit 619761d

Please sign in to comment.