port to Qt5
This commit is contained in:
parent
f56fd9f7db
commit
a78b5da75c
|
|
@ -5,12 +5,14 @@ project(gear-cutter VERSION 1.0.0 LANGUAGES CXX)
|
||||||
set(CMAKE_CXX_STANDARD 17)
|
set(CMAKE_CXX_STANDARD 17)
|
||||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
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)
|
find_program(CARGO cargo REQUIRED)
|
||||||
set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo")
|
set(CARGO_TARGET_DIR "${CMAKE_BINARY_DIR}/cargo")
|
||||||
|
|
||||||
include(cbindgen.cmake)
|
include(cbindgen.cmake)
|
||||||
|
|
||||||
qt_standard_project_setup()
|
set(CMAKE_AUTOMOC ON)
|
||||||
|
set(CMAKE_AUTOUIC ON)
|
||||||
|
include(GNUInstallDirs)
|
||||||
|
|
||||||
add_subdirectory(ui)
|
add_subdirectory(ui)
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
include(impl.cmake)
|
include(impl.cmake)
|
||||||
|
|
||||||
qt_add_executable(gear-cutter
|
add_executable(gear-cutter
|
||||||
src/api.cxx
|
src/api.cxx
|
||||||
src/main.cxx
|
src/main.cxx
|
||||||
src/main_window.cxx
|
src/main_window.cxx
|
||||||
|
|
@ -8,6 +8,6 @@ qt_add_executable(gear-cutter
|
||||||
src/viewport.cxx
|
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_link_libraries(gear-cutter PRIVATE gear_cutter_impl)
|
||||||
target_include_directories(gear-cutter PRIVATE src)
|
target_include_directories(gear-cutter PRIVATE src)
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,10 @@
|
||||||
#include "main_window.hxx"
|
#include "main_window.hxx"
|
||||||
|
|
||||||
#include "ui_main_window.h"
|
#include "ui_main_window.h"
|
||||||
|
|
||||||
|
#include <cmath>
|
||||||
|
|
||||||
|
#include <QtMath>
|
||||||
|
|
||||||
GearCutter::GearCutter(QWidget* parent)
|
GearCutter::GearCutter(QWidget* parent)
|
||||||
: QMainWindow(parent),
|
: QMainWindow(parent),
|
||||||
m_ui(new Ui::MainWindow) {
|
m_ui(new Ui::MainWindow) {
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,10 @@
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QEvent>
|
#include <QEvent>
|
||||||
#include <QGuiApplication>
|
#include <QGuiApplication>
|
||||||
|
#include <QX11Info>
|
||||||
|
|
||||||
|
// must be the last as it is macro-heavy
|
||||||
|
#include <X11/Xlib-xcb.h>
|
||||||
|
|
||||||
Viewport::Viewport(QWidget* parent, Qt::WindowFlags f)
|
Viewport::Viewport(QWidget* parent, Qt::WindowFlags f)
|
||||||
: QWidget(parent, f) {
|
: QWidget(parent, f) {
|
||||||
|
|
@ -55,15 +59,14 @@ void Viewport::resizeEvent(QResizeEvent* event) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Viewport::recreate() try {
|
void Viewport::recreate() try {
|
||||||
auto* app = qobject_cast<QGuiApplication*>(QApplication::instance());
|
auto* xlib_display = QX11Info::display();
|
||||||
if (!app)
|
if (!xlib_display)
|
||||||
throw std::runtime_error("not a GUI application (WTF?)");
|
throw std::runtime_error("got no X11 display");
|
||||||
|
|
||||||
auto* native = app->nativeInterface<QNativeInterface::QX11Application>();
|
auto* xcb_connection = XGetXCBConnection(xlib_display);
|
||||||
if (!native)
|
if (!xcb_connection)
|
||||||
throw std::runtime_error("X11 interface is not available");
|
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();
|
std::uint32_t x11_window = winId();
|
||||||
|
|
||||||
fprintf(stderr, "connection %p, window %#08x\n", xcb_connection, x11_window);
|
fprintf(stderr, "connection %p, window %#08x\n", xcb_connection, x11_window);
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user