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 a94b853
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 31 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
16 changes: 8 additions & 8 deletions Client/qtTeamTalk/desktopsharedlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

extern QSettings* ttSettings;

#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
DesktopShareDlg::DesktopShareDlg(Display* display, QWidget* parent)
#else
DesktopShareDlg::DesktopShareDlg(QWidget* parent)
Expand All @@ -38,7 +38,7 @@ DesktopShareDlg::DesktopShareDlg(QWidget* parent)
, m_hShareWnd(nullptr)
#elif defined(Q_OS_DARWIN)
, m_nCGShareWnd(0)
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
, m_nWindowShareWnd(0)
, m_display(display)
#endif
Expand Down Expand Up @@ -73,11 +73,11 @@ 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);
}
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
//TODO: X11, share specific window
// if(m_display)
// {
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 @@ -182,7 +182,7 @@ void DesktopShareDlg::accept()
mode = DESKTOPSHARE_DESKTOP;
#if defined(Q_OS_WIN32)
m_hShareWnd = TT_Windows_GetDesktopHWND();
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
if(m_display)
m_nWindowShareWnd = XRootWindow(m_display, 0);
#endif
Expand All @@ -198,7 +198,7 @@ void DesktopShareDlg::accept()
// tr("The requested window cannot be found"));
#elif defined(Q_OS_DARWIN)
m_nCGShareWnd = (INT64)ui.windowComboBox->itemData(ui.windowComboBox->currentIndex()).toLongLong();
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
m_nWindowShareWnd = (INT64)ui.windowComboBox->itemData(ui.windowComboBox->currentIndex()).toLongLong();
#endif
ttSettings->setValue(SETTINGS_DESKTOPSHARE_WINDOWTITLE,
Expand All @@ -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
11 changes: 5 additions & 6 deletions Client/qtTeamTalk/desktopsharedlg.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include "common.h"

#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <QX11Info>
#endif

Expand All @@ -31,7 +31,7 @@ class DesktopShareDlg : public QDialog
Q_OBJECT

public:
#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
DesktopShareDlg(Display* display, QWidget* parent);
#else
DesktopShareDlg(QWidget* parent);
Expand All @@ -40,18 +40,17 @@ class DesktopShareDlg : public QDialog
HWND m_hShareWnd;
#elif defined(Q_OS_DARWIN)
INT64 m_nCGShareWnd;
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
INT64 m_nWindowShareWnd;
#endif
public:
void accept();

private:
Ui::DesktopShareDlg ui;
#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
Display* m_display;
#endif
};
};

#endif

9 changes: 9 additions & 0 deletions Client/qtTeamTalk/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ class MyQApplication
#elif defined(Q_OS_LINUX)

//For hotkeys on X11
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <QX11Info>
#endif

#include <X11/Xlib.h>
#include <xcb/xcb.h> // used by Qt5

Expand Down Expand Up @@ -129,7 +132,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,6 +176,7 @@ class MyQApplication : public QApplication
installNativeEventFilter(this);
}

#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
bool x11EventFilter ( XEvent * event )
{
if(event->type == KeyPress || event->type == KeyRelease)
Expand Down Expand Up @@ -215,6 +223,7 @@ class MyQApplication : public QApplication

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

Expand Down
31 changes: 17 additions & 14 deletions Client/qtTeamTalk/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ MainWindow::MainWindow(const QString& cfgfile)
, m_hShareWnd(nullptr)
#elif defined(Q_OS_DARWIN)
, m_nCGShareWnd(kCGNullWindowID)
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
, m_display(nullptr)
, m_nWindowShareWnd(0)
#endif
Expand Down Expand Up @@ -627,7 +627,7 @@ MainWindow::MainWindow(const QString& cfgfile)

MainWindow::~MainWindow()
{
#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
if(m_display)
XCloseDisplay(m_display);
#endif
Expand Down Expand Up @@ -3350,7 +3350,7 @@ bool MainWindow::sendDesktopWindow()
case DESKTOPSHARE_ACTIVE_WINDOW :
#if defined(Q_OS_WIN32)
m_hShareWnd = TT_Windows_GetDesktopActiveHWND();
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
{
if(!m_display)
m_display = XOpenDisplay(0);
Expand Down Expand Up @@ -3405,7 +3405,7 @@ bool MainWindow::sendDesktopWindow()
if(m_nCGShareWnd)
ret = TT_SendDesktopFromWindowID(ttInst, m_nCGShareWnd, bmp_mode, DESKTOPPROTOCOL_ZLIB_1);

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

if(!m_display)
return false;
Expand Down Expand Up @@ -3463,7 +3463,7 @@ void MainWindow::restartSendDesktopWindowTimer()

QRect MainWindow::getSharedWindowRect()
{
#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
//TODO: X11, get active window (this only handles entire desktop)

if(!m_display)
Expand Down Expand Up @@ -3492,7 +3492,7 @@ void MainWindow::sendDesktopCursor()
{
QPoint curPos = QCursor::pos();

#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
if(!m_display)
return;

Expand Down Expand Up @@ -3568,7 +3568,7 @@ void MainWindow::processDesktopInput(int userid, const DesktopInput& input)
qDebug() << "Ignoring desktop input. Incorrect window has focus.";
return;
}
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
{
if(!m_display)
return;
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 @@ -3833,6 +3833,8 @@ void MainWindow::disableHotKey(HotKeyID id)
#if defined(Q_OS_LINUX)
void MainWindow::executeDesktopInput(const DesktopInput& input)
{
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)

//TODO: X11, mouse held down for selection (e.g. text in edit field)
//TODO: X11, key strokes

Expand Down Expand Up @@ -3900,6 +3902,7 @@ void MainWindow::executeDesktopInput(const DesktopInput& input)
XSendEvent(m_display, PointerWindow, True, 0, &event);
XFlush(m_display);
}
#endif
}
#endif

Expand Down Expand Up @@ -4638,7 +4641,7 @@ void MainWindow::slotMeEnableDesktopSharing(bool checked/*=false*/)
{
if(checked)
{
#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
if(!m_display)
m_display = XOpenDisplay(0);

Expand All @@ -4656,7 +4659,7 @@ void MainWindow::slotMeEnableDesktopSharing(bool checked/*=false*/)
m_hShareWnd = dlg.m_hShareWnd;
#elif defined(Q_OS_DARWIN)
m_nCGShareWnd = dlg.m_nCGShareWnd;
#elif defined(Q_OS_LINUX)
#elif defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
m_nWindowShareWnd = dlg.m_nWindowShareWnd;
#endif
if(!sendDesktopWindow())
Expand Down Expand Up @@ -4685,7 +4688,7 @@ void MainWindow::slotMeEnableDesktopSharing(bool checked/*=false*/)
killLocalTimer(TIMER_SEND_DESKTOPCURSOR);
TT_CloseDesktopWindow(ttInst);

#if defined(Q_OS_LINUX)
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
if(m_display)
XCloseDisplay(m_display);
m_display = nullptr;
Expand Down
11 changes: 8 additions & 3 deletions Client/qtTeamTalk/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

#include "ui_mainwindow.h"


#include <QMap>
#include <QSet>
#include <QQueue>
Expand All @@ -34,7 +35,7 @@
#include "utilui.h"
#include "utilhotkey.h"

#ifdef Q_OS_LINUX
#if defined(Q_OS_LINUX) && QT_VERSION < QT_VERSION_CHECK(6,0,0)
#include <QX11Info>
#endif

Expand Down Expand Up @@ -86,7 +87,7 @@ enum
class MainWindow : public QMainWindow
{
Q_OBJECT

public:
MainWindow(const QString& cfgfile);
~MainWindow();
Expand Down Expand Up @@ -278,14 +279,18 @@ 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;
typedef QMap<HotKeyID, keycomp_t> reghotkeys_t;
//the registered hotkeys
reghotkeys_t m_hotkeys;
#if QT_VERSION < QT_VERSION_CHECK(6,0,0)
Display* m_display;
INT64 m_nWindowShareWnd;
#endif

#elif defined(Q_OS_DARWIN)
typedef QMap<int,EventHotKeyRef> reghotkeys_t;
reghotkeys_t m_hotkeys;
Expand Down Expand Up @@ -369,7 +374,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

0 comments on commit a94b853

Please sign in to comment.