diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 5e4ca8fc8914267d1078ab873c29cc6cce406d89..137fd0908f5a0f30362f0dd9da53799b84eefbac 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -294,6 +294,21 @@ set(main_SRC actions/actions-transform.h actions/actions-transform.cpp ) +set(headless_SRC + inkscape-main.cpp + inkscape-application-headless.h + inkscape-application-headless.cpp + actions/actions-base.h + actions/actions-base.cpp + actions/actions-helper.h + actions/actions-helper.cpp + actions/actions-output.h + actions/actions-output.cpp + actions/actions-selection.h + actions/actions-selection.cpp + actions/actions-transform.h + actions/actions-transform.cpp +) set(view_SRC inkview-main.cpp inkview-application.h @@ -337,9 +352,10 @@ endif() # make executables for inkscape and inkview add_executable(inkscape ${main_SRC}) +add_executable(inkscape-headless ${headless_SRC}) add_executable(inkview ${view_SRC}) - +set_source_files_properties( inkscape-application-headless.cpp PROPERTIES COMPILE_FLAGS "-DHEADLESS") set(INKSCAPE_TARGET_LIBS # order from automake @@ -373,6 +389,7 @@ target_link_libraries(inkscape_base PRIVATE ${INKSCAPE_TARGET_LIBS} PUBLIC ${INK # Link inkscape and inkview against inkscape_base target_link_libraries(inkscape inkscape_base) +target_link_libraries(inkscape-headless inkscape_base) target_link_libraries(inkview inkscape_base) @@ -381,7 +398,8 @@ target_link_libraries(inkview inkscape_base) if(NOT WIN32) install(TARGETS inkscape - inkview + inkscape-headless + inkview RUNTIME DESTINATION bin) if(BUILD_SHARED_LIBS) install(TARGETS inkscape_base LIBRARY DESTINATION lib/inkscape) diff --git a/src/inkscape-application-headless.cpp b/src/inkscape-application-headless.cpp new file mode 120000 index 0000000000000000000000000000000000000000..5d9a6bb65f77f7a940cb11a6edb352e982e0e716 --- /dev/null +++ b/src/inkscape-application-headless.cpp @@ -0,0 +1 @@ +inkscape-application.cpp \ No newline at end of file diff --git a/src/inkscape-application-headless.h b/src/inkscape-application-headless.h new file mode 120000 index 0000000000000000000000000000000000000000..77ad4077caef4330aa20ac4940e39d7c8aab4420 --- /dev/null +++ b/src/inkscape-application-headless.h @@ -0,0 +1 @@ +inkscape-application.h \ No newline at end of file diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp index cf442ecbc090fd2ade32aa9e3d35e5cf165c4714..a6b47791e27e3a0cac8177ac29fa7a14c7459f87 100644 --- a/src/inkscape-application.cpp +++ b/src/inkscape-application.cpp @@ -44,7 +44,11 @@ using Inkscape::IO::Resource::UIS; // after calling on_handle_local_options() are assumed to be filenames. InkscapeApplication::InkscapeApplication() +#ifdef HEADLESS + : Gio::Application("org.inkscape.application.with_gui", +#else : Gtk::Application("org.inkscape.application.with_gui", +#endif Gio::APPLICATION_HANDLES_OPEN | // Use default file opening. Gio::APPLICATION_NON_UNIQUE ) // Allows different instances of Inkscape to run at same time. , _with_gui(true) @@ -177,7 +181,11 @@ InkscapeApplication::get_active_selection() void InkscapeApplication::on_startup() { +#ifdef HEADLESS + Gio::Application::on_startup(); +#else Gtk::Application::on_startup(); +#endif } // Here are things that should be in on_startup() but cannot be as we don't set _with_gui until @@ -188,6 +196,10 @@ InkscapeApplication::on_startup2() // This should be completely rewritten. Inkscape::Application::create(nullptr, _with_gui); // argv appears to not be used. +#ifdef HEADLESS + _with_gui = false; +#endif + if (!_with_gui) { return; } @@ -219,7 +231,9 @@ InkscapeApplication::on_startup2() if (!menu) { std::cerr << "InkscapeApplication: failed to load application menu!" << std::endl; } else { +#ifndef HEADLESS set_app_menu(menu); +#endif } } @@ -315,8 +329,9 @@ InkscapeApplication::create_window(const Glib::RefPtr& file) _documents.push_back(desktop->getDocument()); // Add to Gtk::Window to app window list. +#ifndef HEADLESS add_window(*desktop->getToplevel()); - +#endif return (desktop); // Temp: Need to track desktop for shell mode. } @@ -697,12 +712,13 @@ InkscapeApplication::on_new() void InkscapeApplication::on_quit() { +#ifndef HEADLESS // Delete all windows (quit() doesn't do this). std::vector windows = get_windows(); for (auto window: windows) { // Do something } - +#endif quit(); } diff --git a/src/inkscape-application.h b/src/inkscape-application.h index 90553cd0da6145c260e429bafac71fa056e8a027..5c29ef34bfeddc56cda07dff1aae75cfbd90735e 100644 --- a/src/inkscape-application.h +++ b/src/inkscape-application.h @@ -30,7 +30,11 @@ typedef std::vector > action_vector_t; +#ifdef HEADLESS +class InkscapeApplication : public Gio::Application +#else class InkscapeApplication : public Gtk::Application +#endif { protected: InkscapeApplication(); diff --git a/testfiles/rendering_tests/CMakeLists.txt b/testfiles/rendering_tests/CMakeLists.txt index 15a5eb15e07b31d90c81caed46e60a7b89992f65..15496a54bcff3d028fd7ccd450b1ddc14ad6c8c1 100644 --- a/testfiles/rendering_tests/CMakeLists.txt +++ b/testfiles/rendering_tests/CMakeLists.txt @@ -17,7 +17,7 @@ set(RENDERING_TESTS foreach(rendering_test ${RENDERING_TESTS}) - add_test(NAME ${rendering_test} COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/inkscape ${CMAKE_CURRENT_SOURCE_DIR}/${rendering_test} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testfiles/rendering_tests ) + add_test(NAME ${rendering_test} COMMAND bash ${CMAKE_CURRENT_SOURCE_DIR}/test.sh ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/inkscape-headless ${CMAKE_CURRENT_SOURCE_DIR}/${rendering_test} WORKING_DIRECTORY ${CMAKE_BINARY_DIR}/testfiles/rendering_tests ) set_tests_properties(${rendering_test} PROPERTIES ENVIRONMENT "${CMAKE_CTEST_ENV}") endforeach()