From a78b5da75c693b48ff33c17a930029ca14fd1fea Mon Sep 17 00:00:00 2001 From: numzero Date: Tue, 20 Oct 2026 03:09:48 +0300 Subject: [PATCH] port to Qt5 --- CMakeLists.txt | 6 ++++-- ui/CMakeLists.txt | 4 ++-- ui/src/main_window.cxx | 5 ++++- ui/src/viewport.cxx | 17 ++++++++++------- 4 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 0042389..09a2b13 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -5,12 +5,14 @@ project(gear-cutter VERSION 1.0.0 LANGUAGES CXX) set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD_REQUIRED ON) -find_package(Qt6 REQUIRED COMPONENTS Gui Widgets) +find_package(Qt5 REQUIRED COMPONENTS Core Gui Widgets X11Extras) find_program(CARGO cargo REQUIRED) set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo") include(cbindgen.cmake) -qt_standard_project_setup() +set(CMAKE_AUTOMOC ON) +set(CMAKE_AUTOUIC ON) +include(GNUInstallDirs) add_subdirectory(ui) diff --git a/ui/CMakeLists.txt b/ui/CMakeLists.txt index 54a464d..b4c5980 100644 --- a/ui/CMakeLists.txt +++ b/ui/CMakeLists.txt @@ -1,6 +1,6 @@ include(impl.cmake) -qt_add_executable(gear-cutter +add_executable(gear-cutter src/api.cxx src/main.cxx src/main_window.cxx @@ -8,6 +8,6 @@ qt_add_executable(gear-cutter src/viewport.cxx ) -target_link_libraries(gear-cutter PRIVATE Qt6::Gui Qt6::Widgets) +target_link_libraries(gear-cutter PRIVATE Qt5::Core Qt5::Gui Qt5::Widgets Qt5::X11Extras X11-xcb) target_link_libraries(gear-cutter PRIVATE gear_cutter_impl) target_include_directories(gear-cutter PRIVATE src) diff --git a/ui/src/main_window.cxx b/ui/src/main_window.cxx index 0e65394..4969779 100644 --- a/ui/src/main_window.cxx +++ b/ui/src/main_window.cxx @@ -1,7 +1,10 @@ #include "main_window.hxx" - #include "ui_main_window.h" +#include + +#include + GearCutter::GearCutter(QWidget* parent) : QMainWindow(parent), m_ui(new Ui::MainWindow) { diff --git a/ui/src/viewport.cxx b/ui/src/viewport.cxx index 14ca272..bdc0d2b 100644 --- a/ui/src/viewport.cxx +++ b/ui/src/viewport.cxx @@ -3,6 +3,10 @@ #include #include #include +#include + +// must be the last as it is macro-heavy +#include Viewport::Viewport(QWidget* parent, Qt::WindowFlags f) : QWidget(parent, f) { @@ -55,15 +59,14 @@ void Viewport::resizeEvent(QResizeEvent* event) { } void Viewport::recreate() try { - auto* app = qobject_cast(QApplication::instance()); - if (!app) - throw std::runtime_error("not a GUI application (WTF?)"); + auto* xlib_display = QX11Info::display(); + if (!xlib_display) + throw std::runtime_error("got no X11 display"); - auto* native = app->nativeInterface(); - if (!native) - throw std::runtime_error("X11 interface is not available"); + auto* xcb_connection = XGetXCBConnection(xlib_display); + if (!xcb_connection) + throw std::runtime_error("failed to get the XCB connection from the X11 display"); - auto* xcb_connection = native->connection(); std::uint32_t x11_window = winId(); fprintf(stderr, "connection %p, window %#08x\n", xcb_connection, x11_window);