Gtk4 by sbarber-dsi · Pull Request #1696 · solvespace/solvespace · GitHub
Skip to content
Open

Gtk4 #1696

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .github/scripts/build-ubuntu-gtk4.sh
10 changes: 10 additions & 0 deletions .github/scripts/install-ubuntu-gtk4.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/sh -xe

sudo apt-get update -qq

sudo apt-get install -q -y \
zlib1g-dev libpng-dev libcairo2-dev libfreetype6-dev libjson-c-dev \
libfontconfig1-dev libgtkmm-4.0-dev libgl-dev \
libglu-dev libspnav-dev

git submodule update --init extlib/libdxfrw extlib/mimalloc extlib/eigen
23 changes: 17 additions & 6 deletions .github/workflows/cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ jobs:
- name: Build & Test
run: .github/scripts/build-ubuntu.sh

test_ubuntu_gtk4:
needs: [cancel_previous_runs]
runs-on: ubuntu-latest
name: Test Ubuntu (GTK4)
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: .github/scripts/install-ubuntu-gtk4.sh
- name: Build & Test
run: .github/scripts/build-ubuntu-gtk4.sh

test_windows:
needs: [cancel_previous_runs]
runs-on: windows-2022
Expand All @@ -55,7 +66,7 @@ jobs:
run: .github/scripts/build-macos.sh debug arm64 && .github/scripts/build-macos.sh debug x86_64

build_release_windows_x86:
needs: [test_ubuntu, test_windows, test_macos]
needs: [test_ubuntu, test_ubuntu_gtk4, test_windows, test_macos]
name: Build Release Windows x86
runs-on: windows-2022
steps:
Expand All @@ -73,7 +84,7 @@ jobs:
path: build/bin/RelWithDebInfo/solvespace_single_core_x86.exe

build_release_windows_openmp_x86:
needs: [test_ubuntu, test_windows, test_macos]
needs: [test_ubuntu, test_ubuntu_gtk4, test_windows, test_macos]
name: Build Release Windows (OpenMP) x86
runs-on: windows-2022
steps:
Expand All @@ -91,7 +102,7 @@ jobs:
path: build/bin/RelWithDebInfo/solvespace_x86.exe

build_release_windows_x64:
needs: [test_ubuntu, test_windows, test_macos]
needs: [test_ubuntu, test_ubuntu_gtk4, test_windows, test_macos]
name: Build Release Windows x64
runs-on: windows-2022
steps:
Expand All @@ -109,7 +120,7 @@ jobs:
path: build/bin/RelWithDebInfo/solvespace_single_core_x64.exe

build_release_windows_openmp_x64:
needs: [test_ubuntu, test_windows, test_macos]
needs: [test_ubuntu, test_ubuntu_gtk4, test_windows, test_macos]
name: Build Release Windows (OpenMP) x64
runs-on: windows-2022
steps:
Expand All @@ -127,7 +138,7 @@ jobs:
path: build/bin/RelWithDebInfo/solvespace_x64.exe

build_release_macos:
needs: [test_ubuntu, test_windows, test_macos]
needs: [test_ubuntu, test_ubuntu_gtk4, test_windows, test_macos]
name: Build Release macOS
runs-on: macos-latest
steps:
Expand All @@ -151,7 +162,7 @@ jobs:
path: build/bin/SolveSpace.dmg

build_release_web:
needs: [test_ubuntu, test_windows, test_macos]
needs: [test_ubuntu, test_ubuntu_gtk4, test_windows, test_macos]
name: Build Release Web
runs-on: ubuntu-latest
steps:
Expand Down
10 changes: 10 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ jobs:
- name: Build & Test
run: .github/scripts/build-ubuntu.sh

test_ubuntu_gtk4:
runs-on: ubuntu-latest
name: Test Ubuntu (GTK4)
steps:
- uses: actions/checkout@v4
- name: Install Dependencies
run: .github/scripts/install-ubuntu-gtk4.sh
- name: Build & Test
run: .github/scripts/build-ubuntu-gtk4.sh

test_windows:
runs-on: windows-2022
name: Test Windows
Expand Down
89 changes: 89 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# SolveSpace — Agent Guidelines

## Project Overview

SolveSpace is a parametric 2D/3D CAD application written in C++11. It consists of a
**portable core** (everything outside `src/platform/`) and **platform-specific UI** code
(`src/platform/`). Licensed under GPLv3+.

## Building

```sh
mkdir build && cd build
cmake .. -DCMAKE_BUILD_TYPE=Debug
make -j$(nproc)
```

Run tests:
```sh
make test_solvespace
# or directly:
./build/test/solvespace-testsuite
```

The test suite links against `solvespace-headless` (no GUI). Tests live in `test/`
organized by category (constraint, request, group, core, analysis).

## Architecture

| Directory | Purpose |
|-----------|---------|
| `src/` | Portable core: geometric kernel, constraint solver, file I/O, UI logic |
| `src/platform/` | Platform abstraction layer (`gui.h`, `platform.h`) and backends |
| `src/platform/gui*.cpp` | GUI backends: `guigtk.cpp` (GTK 3), `guiqt.cpp` (Qt), `guiwin.cpp` (Win32), `guimac.mm` (Cocoa), `guihtml.cpp` (Emscripten), `guinone.cpp` (headless) |
| `src/render/` | Rendering backends (OpenGL 1/3, Cairo, 2D export) |
| `src/slvs/` | C API for the constraint solver library |
| `src/srf/` | Surface/NURBS code |
| `include/` | Public header for the solver library (`slvs.h`) |
| `extlib/` | Vendored third-party libraries (built as CMake subprojects) |
| `res/` | Resources: icons, locales, shaders, fonts |
| `test/` | Test suite (branch-coverage focused) |
| `exposed/` | Additional language bindings |

## Coding Conventions

### Style
- **4-space indent**, no tabs, no trailing whitespace, 100-column wrap.
- Braces on same line as declaration/control flow (`Attach` style).
- Braces required on all control flow bodies, even single-statement.
- No space after `if`, `while`, `for` — write `if(cond)` not `if (cond)`.
- camelCase variables (`exampleVar`), PascalCase functions (`ExampleFunction`).
- Apply `.clang-format` via `git clang-format` before committing.

### C++ Usage
- **C++11 only** — do not use C++14/17/20 features.
- **No exceptions** — they interfere with branch-coverage measurement.
- **No operator overloading** — use named methods (e.g. `Plus`, `Minus`).
- **All members are public** — no access specifiers for implementation hiding.
- **No constructors for initialization** — use aggregate init `Foo foo = {};`.
- Output parameters are passed by pointer (`Vector *out`), never by reference.
- Use `ssassert(cond, "message")` instead of `assert()` — it is always enabled.
- Use `ssprintf()` for string formatting (remember `.c_str()` for std::string args).
- Use `ssfopen()` / `ssremove()` for filesystem access (UTF-8 safe).
- Strings are always UTF-8 internally.

### Platform Code
- Everything outside `src/platform/` must be portable standard C++11.
- Platform interaction goes through `src/platform/platform.h` and `src/platform/gui.h`.
- When adding a new platform backend, implement the abstract interfaces in `gui.h`
(`Window`, `Menu`, `MenuBar`, `MenuItem`, `Timer`, `Settings`, `MessageDialog`,
`FileDialog`) plus the free functions (`InitGui`, `RunGui`, `ExitGui`, etc.).

### Libraries
- External libraries must be portable, includable as CMake subprojects, and use a
license less restrictive than GPL (BSD/MIT, Apache2, MPL).
- STL I/O streams are **not used** — SolveSpace has its own file I/O.
- Check `extlib/` and `CMakeLists.txt` for available dependencies before adding new ones.

## Testing

- Tests use the headless build (`solvespace-headless`).
- Test harness is in `test/harness.h` / `test/harness.cpp`.
- Tests compare against reference `.slvs` files and expected output.
- Branch coverage is tracked — avoid patterns that add untestable branches.
- `ssassert` and `switch` are excluded from coverage metrics.

## Plans

Migration/implementation plans are stored in `plans/`. Read them before starting
related work.
18 changes: 16 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ set(ENABLE_GUI ON CACHE BOOL
"Whether the graphical interface is enabled")
set(USE_QT_GUI OFF CACHE BOOL
"Whether the Qt library used to build graphical interface")
set(USE_GTK4_GUI OFF CACHE BOOL
"Whether GTK 4 is used instead of GTK 3 for the graphical interface")
set(ENABLE_CLI ${INCLUDE_NATIVE_COMPONENTS} CACHE BOOL
"Whether the command line interface is enabled")
set(ENABLE_TESTS ${INCLUDE_NATIVE_COMPONENTS} CACHE BOOL
Expand All @@ -76,6 +78,15 @@ option(FORCE_VENDORED_Eigen3
"Whether we should use our bundled Eigen even in the presence of a system copy"
OFF)

if(USE_QT_GUI AND USE_GTK4_GUI)
message(FATAL_ERROR "USE_QT_GUI and USE_GTK4_GUI are mutually exclusive")
endif()

# gtkmm-4.0 requires C++17; override the default C++11 standard.
if(USE_GTK4_GUI)
set(CMAKE_CXX_STANDARD 17)
endif()

set(OPENGL 3 CACHE STRING "OpenGL version to use (one of: 1 3)")

set(EXECUTABLE_OUTPUT_PATH ${CMAKE_BINARY_DIR}/bin)
Expand Down Expand Up @@ -340,7 +351,7 @@ if(ENABLE_GUI OR ENABLE_CLI)
find_package(ZLIB REQUIRED)
find_package(PNG REQUIRED)
find_package(Freetype REQUIRED)
if (NOT USE_QT_GUI OR ENABLE_CLI OR ENABLE_TESTS)
if (NOT USE_QT_GUI OR USE_GTK4_GUI OR ENABLE_CLI OR ENABLE_TESTS)
find_package(Cairo REQUIRED)
endif()
endif()
Expand Down Expand Up @@ -383,7 +394,10 @@ if(ENABLE_GUI)
find_package(OpenGL REQUIRED)
find_package(SpaceWare)
pkg_check_modules(FONTCONFIG REQUIRED fontconfig)
if (NOT USE_QT_GUI)
if(USE_GTK4_GUI)
pkg_check_modules(JSONC REQUIRED json-c)
pkg_check_modules(GTKMM REQUIRED gtkmm-4.0>=4.10)
elseif(NOT USE_QT_GUI)
pkg_check_modules(JSONC REQUIRED json-c)
pkg_check_modules(GTKMM REQUIRED gtkmm-3.0>=3.18 pangomm-1.4 x11)
endif()
Expand Down
4 changes: 0 additions & 4 deletions extlib/si/spwmacro.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
/*----------------------------------------------------------------------
* spwmacro.h -- cpp macros we ALWAYS use.
*
<<<<<<< spwmacro.h
* $Id: spwmacro.h,v 1.3 2001/01/16 01:18:40 HJin Exp $
=======
* $Id: spwmacro.h,v 1.3 2001/01/16 01:18:40 HJin Exp $
>>>>>>> 1.1.1.1.4.1
*
* We always seem to use the same macros.
* This is the place we define them.
Expand Down
54 changes: 54 additions & 0 deletions makefile
Loading