Skip to content

Commit

Permalink
hiro:qt: separate linux from X11 assumption in qt hiro; address a few…
Browse files Browse the repository at this point in the history
… Qt5 deprecation warnings
  • Loading branch information
JamesDunne committed Mar 9, 2025
1 parent 25a3471 commit 73cb7e0
Show file tree
Hide file tree
Showing 11 changed files with 28 additions and 27 deletions.
4 changes: 2 additions & 2 deletions hiro/GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,9 @@ ifneq ($(filter $(platform),linux bsd),)
endif

ifeq ($(hiro),qt5)
moc = /usr/local/lib/qt5/bin/moc
moc = /usr/lib/qt5/bin/moc
hiro.flags = $(flags.cpp) -DHIRO_QT=5 -fPIC $(shell pkg-config --cflags Qt5Core Qt5Gui Qt5Widgets)
hiro.options = -L/usr/local/lib -lX11 $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets)
hiro.options = -lX11 $(shell pkg-config --libs Qt5Core Qt5Gui Qt5Widgets)
endif
endif

Expand Down
13 changes: 7 additions & 6 deletions hiro/qt/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ auto pApplication::run() -> void {
}

auto pApplication::pendingEvents() -> bool {
return QApplication::hasPendingEvents();
return QAbstractEventDispatcher::instance()->hasPendingEvents();
}

auto pApplication::processEvents() -> void {
while(pendingEvents()) QApplication::processEvents();
auto dispatcher = QAbstractEventDispatcher::instance();
dispatcher->processEvents(QEventLoop::AllEvents);
}

auto pApplication::quit() -> void {
QApplication::quit();
qtApplication = nullptr; //note: deleting QApplication will crash libQtGui

#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
if(state().display) {
if(state().screenSaverXDG && state().screenSaverWindow) {
//this needs to run synchronously, so that XUnmapWindow() won't happen before xdg-screensaver is finished
Expand All @@ -49,7 +50,7 @@ auto pApplication::quit() -> void {
}

auto pApplication::setScreenSaver(bool screenSaver) -> void {
#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
if(state().screenSaverXDG && state().screenSaverWindow) {
invoke("xdg-screensaver", screenSaver ? "resume" : "suspend", string{"0x", hex(state().screenSaverWindow)});
}
Expand All @@ -65,7 +66,7 @@ auto pApplication::state() -> State& {
//obviously, it is used as sparingly as possible
auto pApplication::synchronize() -> void {
for(auto n : range(8)) {
#if HIRO_QT==4 && defined(DISPLAY_XORG)
#if HIRO_QT==4 && defined(QT_DISPLAY_XORG)
QApplication::syncX();
#elif HIRO_QT==5
QApplication::sync();
Expand All @@ -80,7 +81,7 @@ auto pApplication::initialize() -> void {
setenv("QTCOMPOSE", "/usr/local/lib/X11/locale/", 0);
#endif

#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
state().display = XOpenDisplay(nullptr);
state().screenSaverXDG = (bool)execute("xdg-screensaver", "--version").output.find("xdg-screensaver");

Expand Down
2 changes: 1 addition & 1 deletion hiro/qt/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct pApplication {
static auto synchronize() -> void;

struct State {
#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
XlibDisplay* display = nullptr;
XlibWindow screenSaverWindow = 0;
bool screenSaverXDG = false;
Expand Down
4 changes: 2 additions & 2 deletions hiro/qt/desktop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace hiro {
auto pDesktop::size() -> Size {
#if defined(DISPLAY_WINDOWS)
return {GetSystemMetrics(SM_CXVIRTUALSCREEN), GetSystemMetrics(SM_CYVIRTUALSCREEN)};
#elif defined(DISPLAY_XORG)
#elif defined(QT_DISPLAY_XORG)
auto display = XOpenDisplay(nullptr);
int screen = DefaultScreen(display);
XWindowAttributes attributes;
Expand All @@ -24,7 +24,7 @@ auto pDesktop::workspace() -> Geometry {
RECT rc;
SystemParametersInfo(SPI_GETWORKAREA, 0, &rc, 0);
return {rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top};
#elif defined(DISPLAY_XORG)
#elif defined(QT_DISPLAY_XORG)
auto display = XOpenDisplay(nullptr);
int screen = DefaultScreen(display);

Expand Down
10 changes: 5 additions & 5 deletions hiro/qt/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ auto pKeyboard::poll() -> vector<bool> {
vector<bool> result;
char state[256];

#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
XQueryKeymap(pApplication::state().display, state);
#endif

Expand All @@ -22,7 +22,7 @@ auto pKeyboard::poll() -> vector<bool> {
auto pKeyboard::pressed(unsigned code) -> bool {
char state[256];

#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
XQueryKeymap(pApplication::state().display, state);
#endif

Expand All @@ -33,7 +33,7 @@ auto pKeyboard::_pressed(const char* state, uint16_t code) -> bool {
uint8_t lo = code >> 0;
uint8_t hi = code >> 8;

#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
if(lo && state[lo >> 3] & (1 << (lo & 7))) return true;
if(hi && state[hi >> 3] & (1 << (hi & 7))) return true;
#endif
Expand All @@ -43,7 +43,7 @@ auto pKeyboard::_pressed(const char* state, uint16_t code) -> bool {

auto pKeyboard::initialize() -> void {
auto append = [](unsigned lo, unsigned hi = 0) {
#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
lo = lo ? (uint8_t)XKeysymToKeycode(pApplication::state().display, lo) : 0;
hi = hi ? (uint8_t)XKeysymToKeycode(pApplication::state().display, hi) : 0;
#endif
Expand All @@ -52,7 +52,7 @@ auto pKeyboard::initialize() -> void {

#define map(name, ...) if(key == name) { append(__VA_ARGS__); continue; }
for(auto& key : Keyboard::keys) {
#if defined(DISPLAY_XORG)
#if defined(QT_DISPLAY_XORG)
#include <hiro/platform/xorg/keyboard.hpp>
#endif

Expand Down
2 changes: 1 addition & 1 deletion hiro/qt/mouse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ auto pMouse::pressed(Mouse::Button button) -> bool {
Qt::MouseButtons buttons = QApplication::mouseButtons();
switch(button) {
case Mouse::Button::Left: return buttons & Qt::LeftButton;
case Mouse::Button::Middle: return buttons & Qt::MidButton;
case Mouse::Button::Middle: return buttons & Qt::MiddleButton;
case Mouse::Button::Right: return buttons & Qt::RightButton;
}
return false;
Expand Down
4 changes: 2 additions & 2 deletions hiro/qt/qt.moc
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/****************************************************************************
** Meta object code from reading C++ file 'qt.hpp'
**
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.15.16)
** Created by: The Qt Meta Object Compiler version 67 (Qt 5.15.3)
**
** WARNING! All changes made in this file will be lost!
*****************************************************************************/
Expand All @@ -12,7 +12,7 @@
#if !defined(Q_MOC_OUTPUT_REVISION)
#error "The header file 'qt.hpp' doesn't include <QObject>."
#elif Q_MOC_OUTPUT_REVISION != 67
#error "This file was generated using the moc from 5.15.16. It"
#error "This file was generated using the moc from 5.15.3. It"
#error "cannot be used with the include files from this version of Qt."
#error "(The moc has changed too much.)"
#endif
Expand Down
4 changes: 2 additions & 2 deletions hiro/qt/widget/canvas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ auto QtCanvas::mouseMoveEvent(QMouseEvent* event) -> void {
auto QtCanvas::mousePressEvent(QMouseEvent* event) -> void {
switch(event->button()) {
case Qt::LeftButton: p.self().doMousePress(Mouse::Button::Left); break;
case Qt::MidButton: p.self().doMousePress(Mouse::Button::Middle); break;
case Qt::MiddleButton: p.self().doMousePress(Mouse::Button::Middle); break;
case Qt::RightButton: p.self().doMousePress(Mouse::Button::Right); break;
}
}

auto QtCanvas::mouseReleaseEvent(QMouseEvent* event) -> void {
switch(event->button()) {
case Qt::LeftButton: p.self().doMouseRelease(Mouse::Button::Left); break;
case Qt::MidButton: p.self().doMouseRelease(Mouse::Button::Middle); break;
case Qt::MiddleButton: p.self().doMouseRelease(Mouse::Button::Middle); break;
case Qt::RightButton: p.self().doMouseRelease(Mouse::Button::Right); break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions hiro/qt/widget/label.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,15 @@ auto pLabel::setText(const string& text) -> void {
auto QtLabel::mousePressEvent(QMouseEvent* event) -> void {
switch(event->button()) {
case Qt::LeftButton: p.self().doMousePress(Mouse::Button::Left); break;
case Qt::MidButton: p.self().doMousePress(Mouse::Button::Middle); break;
case Qt::MiddleButton: p.self().doMousePress(Mouse::Button::Middle); break;
case Qt::RightButton: p.self().doMousePress(Mouse::Button::Right); break;
}
}

auto QtLabel::mouseReleaseEvent(QMouseEvent* event) -> void {
switch(event->button()) {
case Qt::LeftButton: p.self().doMouseRelease(Mouse::Button::Left); break;
case Qt::MidButton: p.self().doMouseRelease(Mouse::Button::Middle); break;
case Qt::MiddleButton: p.self().doMouseRelease(Mouse::Button::Middle); break;
case Qt::RightButton: p.self().doMouseRelease(Mouse::Button::Right); break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions hiro/qt/widget/viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ auto QtViewport::mouseMoveEvent(QMouseEvent* event) -> void {
auto QtViewport::mousePressEvent(QMouseEvent* event) -> void {
switch(event->button()) {
case Qt::LeftButton: p.self().doMousePress(Mouse::Button::Left); break;
case Qt::MidButton: p.self().doMousePress(Mouse::Button::Middle); break;
case Qt::MiddleButton: p.self().doMousePress(Mouse::Button::Middle); break;
case Qt::RightButton: p.self().doMousePress(Mouse::Button::Right); break;
}
}

auto QtViewport::mouseReleaseEvent(QMouseEvent* event) -> void {
switch(event->button()) {
case Qt::LeftButton: p.self().doMouseRelease(Mouse::Button::Left); break;
case Qt::MidButton: p.self().doMouseRelease(Mouse::Button::Middle); break;
case Qt::MiddleButton: p.self().doMouseRelease(Mouse::Button::Middle); break;
case Qt::RightButton: p.self().doMouseRelease(Mouse::Button::Right); break;
}
}
Expand Down
4 changes: 2 additions & 2 deletions hiro/qt/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ auto pWindow::remove(sStatusBar statusBar) -> void {
}

auto pWindow::setBackgroundColor(Color color) -> void {
static auto defaultColor = qtContainer->palette().color(QPalette::Background);
static auto defaultColor = qtContainer->palette().color(QPalette::Window);

auto palette = qtContainer->palette();
palette.setColor(QPalette::Background, CreateColor(color, defaultColor));
palette.setColor(QPalette::Window, CreateColor(color, defaultColor));
qtContainer->setPalette(palette);
qtContainer->setAutoFillBackground((bool)color);
//translucency results are very unpleasant without a compositor; so disable for now
Expand Down

0 comments on commit 73cb7e0

Please sign in to comment.