summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2019-05-29 19:28:02 +0000
committerThomas Holder <thomas@thomas-holder.de>2019-05-29 19:28:02 +0000
commitd66a11f144601d1bb2fb0007e3e4463a393b6bd3 (patch)
treeffe9f81118c094033ab4530991fc6d388bb81967
parentRename effect attribute to "implements-custom-gui" (diff)
downloadinkscape-d66a11f144601d1bb2fb0007e3e4463a393b6bd3.tar.gz
inkscape-d66a11f144601d1bb2fb0007e3e4463a393b6bd3.zip
macOS: gtk-mac-integration
-rw-r--r--CMakeScripts/DefineDependsandFlags.cmake6
-rw-r--r--src/inkscape-application.cpp28
-rw-r--r--src/widgets/desktop-widget.cpp19
-rw-r--r--src/widgets/desktop-widget.h2
4 files changed, 55 insertions, 0 deletions
diff --git a/CMakeScripts/DefineDependsandFlags.cmake b/CMakeScripts/DefineDependsandFlags.cmake
index e1f6ca2b9..1ab70106b 100644
--- a/CMakeScripts/DefineDependsandFlags.cmake
+++ b/CMakeScripts/DefineDependsandFlags.cmake
@@ -211,6 +211,12 @@ else()
set(LPE_ENABLE_TEST_EFFECTS OFF)
endif()
+if(APPLE)
+ pkg_check_modules(MacIntegration REQUIRED gtk-mac-integration-gtk3)
+ list(APPEND INKSCAPE_INCS_SYS ${MacIntegration_INCLUDE_DIRS})
+ list(APPEND INKSCAPE_LIBS ${MacIntegration_LIBRARIES})
+endif()
+
# ----------------------------------------------------------------------------
# CMake's builtin
# ----------------------------------------------------------------------------
diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp
index 70a27e1fd..a019d8515 100644
--- a/src/inkscape-application.cpp
+++ b/src/inkscape-application.cpp
@@ -42,6 +42,10 @@
#include "actions/actions-selection.h" // Actions
#include "actions/actions-transform.h" // Actions
+#ifdef GDK_WINDOWING_QUARTZ
+#include <gtkosxapplication.h>
+#endif
+
#ifdef WITH_DBUS
# include "extension/dbus/dbus-init.h"
#endif
@@ -572,6 +576,11 @@ ConcreteInkscapeApplication<Gio::Application>::on_startup2()
Inkscape::Application::create(nullptr, false);
}
+#ifdef GDK_WINDOWING_QUARTZ
+static gboolean osx_openfile_callback(GtkosxApplication *, gchar const *,
+ ConcreteInkscapeApplication<Gtk::Application> *);
+#endif
+
template<>
void
ConcreteInkscapeApplication<Gtk::Application>::on_startup2()
@@ -614,6 +623,11 @@ ConcreteInkscapeApplication<Gtk::Application>::on_startup2()
} else {
// set_app_menu(menu);
}
+
+#ifdef GDK_WINDOWING_QUARTZ
+ GtkosxApplication *osxapp = gtkosx_application_get();
+ g_signal_connect(G_OBJECT(osxapp), "NSApplicationOpenFile", G_CALLBACK(osx_openfile_callback), this);
+#endif
}
/** We should not create a window if T is Gio::Applicaton.
@@ -709,6 +723,20 @@ ConcreteInkscapeApplication<Gtk::Application>::create_window(const Glib::RefPtr<
return (desktop); // Temp: Need to track desktop for shell mode.
}
+#ifdef GDK_WINDOWING_QUARTZ
+/**
+ * On macOS, handle dropping files on Inkscape.app icon and "Open With" file association.
+ */
+static gboolean osx_openfile_callback(GtkosxApplication *osxapp, gchar const *path,
+ ConcreteInkscapeApplication<Gtk::Application> *app)
+{
+ auto ptr = Gio::File::create_for_path(path);
+ g_return_val_if_fail(ptr, false);
+ app->create_window(ptr);
+ return true;
+}
+#endif
+
/** No need to destroy window if T is Gio::Application.
*/
template<class T>
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index 32ca1bac2..f4e278a5a 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -79,6 +79,9 @@
#include "toolbox.h"
#include "widget-sizes.h"
+#ifdef GDK_WINDOWING_QUARTZ
+#include <gtkosxapplication.h>
+#endif
using Inkscape::DocumentUndo;
using Inkscape::UI::Widget::UnitTracker;
@@ -928,6 +931,17 @@ sp_desktop_widget_realize (GtkWidget *widget)
window->get_style_context()->remove_class("symbolic");
}
}
+
+#ifdef GDK_WINDOWING_QUARTZ
+ // native macOS menu
+ auto osxapp = gtkosx_application_get();
+ auto menushell = static_cast<Gtk::MenuShell *>(dtw->menubar());
+ if (osxapp && menushell && window) {
+ menushell->set_parent(*window);
+ gtkosx_application_set_menu_bar(osxapp, menushell->gobj());
+ gtkosx_application_set_use_quartz_accelerators(osxapp, false);
+ }
+#endif
}
/* This is just to provide access to common functionality from sp_desktop_widget_realize() above
@@ -1691,7 +1705,12 @@ SPDesktopWidget* SPDesktopWidget::createInstance(SPDocument *document)
dtw->_menubar = build_menubar(dtw->desktop);
dtw->_menubar->set_name("MenuBar");
dtw->_menubar->show_all();
+
+#ifdef GDK_WINDOWING_QUARTZ
+ // native macOS menu: do this later because we don't have the window handle yet
+#else
dtw->_vbox->pack_start(*dtw->_menubar, false, false);
+#endif
dtw->layoutWidgets();
diff --git a/src/widgets/desktop-widget.h b/src/widgets/desktop-widget.h
index f0b42222d..d21ba7bb8 100644
--- a/src/widgets/desktop-widget.h
+++ b/src/widgets/desktop-widget.h
@@ -269,6 +269,8 @@ public:
void updateTitle(gchar const *uri);
bool onFocusInEvent(GdkEventFocus*);
+ Gtk::MenuBar *menubar() { return _menubar; }
+
Inkscape::UI::Widget::Dock* getDock();
static GType getType();