summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThomas Holder <thomas@thomas-holder.de>2019-08-15 22:20:16 +0000
committerThomas Holder <thomas@thomas-holder.de>2019-08-16 21:27:35 +0000
commite9ded04d15ee12fec8c023f2dba95135fceac154 (patch)
tree778601d0c462b94c73d275eaa419ac5fbb599d1c /src
parentFix a bug in fillet/chamfer LPE pointed in mailing list by Miguel Lopez. Fill... (diff)
downloadinkscape-e9ded04d15ee12fec8c023f2dba95135fceac154.tar.gz
inkscape-e9ded04d15ee12fec8c023f2dba95135fceac154.zip
fix #385 inbox#765 macOS accelerators
- re-fix Cmd-Q confirmation dialog (#383) without the numbers typing regression (#385) - re-fix Alt modifiers (inbox#765) - fix Cmd-A select all text (inbox#765)
Diffstat (limited to 'src')
-rw-r--r--src/include/macros.h19
-rw-r--r--src/inkscape-window.cpp15
-rw-r--r--src/ui/tools/tool-base.cpp19
-rw-r--r--src/widgets/desktop-widget.cpp4
4 files changed, 51 insertions, 6 deletions
diff --git a/src/include/macros.h b/src/include/macros.h
index 21ddaff9e..ff049ddf1 100644
--- a/src/include/macros.h
+++ b/src/include/macros.h
@@ -20,14 +20,25 @@
#define sp_round(v,m) (((v) < 0.0) ? ((ceil((v) / (m) - 0.5)) * (m)) : ((floor((v) / (m) + 0.5)) * (m)))
+// "primary" modifier: Ctrl on Linux/Windows and Cmd on macOS.
+// note: Could query this at runtime with
+// `gdk_keymap_get_modifier_mask(..., GDK_MODIFIER_INTENT_PRIMARY_ACCELERATOR)`
+#ifdef GDK_WINDOWING_QUARTZ
+#define INK_GDK_PRIMARY_MASK GDK_MOD2_MASK
+#else
+#define INK_GDK_PRIMARY_MASK GDK_CONTROL_MASK
+#endif
+
+// all modifiers used by Inkscape
+#define INK_GDK_MODIFIER_MASK (GDK_SHIFT_MASK | INK_GDK_PRIMARY_MASK | GDK_MOD1_MASK)
// keyboard modifiers in an event
#define MOD__SHIFT(event) ((event)->key.state & GDK_SHIFT_MASK)
-#define MOD__CTRL(event) ((event)->key.state & GDK_CONTROL_MASK)
+#define MOD__CTRL(event) ((event)->key.state & INK_GDK_PRIMARY_MASK)
#define MOD__ALT(event) ((event)->key.state & GDK_MOD1_MASK)
-#define MOD__SHIFT_ONLY(event) (((event)->key.state & GDK_SHIFT_MASK) && !((event)->key.state & GDK_CONTROL_MASK) && !((event)->key.state & GDK_MOD1_MASK))
-#define MOD__CTRL_ONLY(event) (!((event)->key.state & GDK_SHIFT_MASK) && ((event)->key.state & GDK_CONTROL_MASK) && !((event)->key.state & GDK_MOD1_MASK))
-#define MOD__ALT_ONLY(event) (!((event)->key.state & GDK_SHIFT_MASK) && !((event)->key.state & GDK_CONTROL_MASK) && ((event)->key.state & GDK_MOD1_MASK))
+#define MOD__SHIFT_ONLY(event) (((event)->key.state & INK_GDK_MODIFIER_MASK) == GDK_SHIFT_MASK)
+#define MOD__CTRL_ONLY(event) (((event)->key.state & INK_GDK_MODIFIER_MASK) == INK_GDK_PRIMARY_MASK)
+#define MOD__ALT_ONLY(event) (((event)->key.state & INK_GDK_MODIFIER_MASK) == GDK_MOD1_MASK)
#endif // SEEN_MACROS_H
diff --git a/src/inkscape-window.cpp b/src/inkscape-window.cpp
index 3629b45f3..27ca5309b 100644
--- a/src/inkscape-window.cpp
+++ b/src/inkscape-window.cpp
@@ -120,11 +120,24 @@ InkscapeWindow::change_document(SPDocument* document)
}
}
+/**
+ * Return true if this is the Cmd-Q shortcut on macOS
+ */
+inline bool is_Cmd_Q(GdkEventKey *event)
+{
+#ifdef GDK_WINDOWING_QUARTZ
+ return (event->keyval == 'q' && event->state == (GDK_MOD2_MASK | GDK_META_MASK));
+#else
+ return false;
+#endif
+}
+
bool
InkscapeWindow::on_key_press_event(GdkEventKey* event)
{
// Need to call base class method first or text tool won't work!
- bool done = Gtk::Window::on_key_press_event(event);
+ // Intercept Cmd-Q on macOS to not bypass confirmation dialog
+ bool done = !is_Cmd_Q(event) && Gtk::Window::on_key_press_event(event);
if (done) {
return true;
}
diff --git a/src/ui/tools/tool-base.cpp b/src/ui/tools/tool-base.cpp
index 4d30740c9..eb2f2119a 100644
--- a/src/ui/tools/tool-base.cpp
+++ b/src/ui/tools/tool-base.cpp
@@ -1320,7 +1320,26 @@ guint get_latin_keyval(GdkEventKey const *event, guint *consumed_modifiers /*= N
&keyval, nullptr, nullptr, &modifiers);
if (consumed_modifiers) {
+#ifndef GDK_WINDOWING_QUARTZ
*consumed_modifiers = modifiers;
+#else
+ // gdk_quartz_keymap_translate_keyboard_state fills the `consumed_modifiers`
+ // incorrectly, e.g. assigns 0xB instead of 0x0 when no modifiers pressed.
+
+ *consumed_modifiers = 0;
+
+ for (unsigned mod = 1, statemask = (event->state & GDK_MODIFIER_MASK); mod <= statemask; mod <<= 1) {
+ if ((mod & statemask)) {
+ guint keyval_no_mod = 0;
+ gdk_keymap_translate_keyboard_state(Gdk::Display::get_default()->get_keymap(), event->hardware_keycode,
+ (GdkModifierType)(event->state & ~mod), group, &keyval_no_mod,
+ nullptr, nullptr, nullptr);
+ if (keyval_no_mod != keyval) {
+ *consumed_modifiers |= mod;
+ }
+ }
+ }
+#endif
}
return keyval;
}
diff --git a/src/widgets/desktop-widget.cpp b/src/widgets/desktop-widget.cpp
index 09797dd32..8ccba0319 100644
--- a/src/widgets/desktop-widget.cpp
+++ b/src/widgets/desktop-widget.cpp
@@ -952,7 +952,9 @@ sp_desktop_widget_realize (GtkWidget *widget)
if (osxapp && menushell && window) {
menushell->set_parent(*window);
gtkosx_application_set_menu_bar(osxapp, menushell->gobj());
- gtkosx_application_set_use_quartz_accelerators(osxapp, true);
+ // using quartz accelerators gives menu shortcuts priority over everything else,
+ // messes up text input because Inkscape has single key shortcuts (e.g. 1-6).
+ gtkosx_application_set_use_quartz_accelerators(osxapp, false);
gtkosx_application_set_help_menu(osxapp, _get_help_menu(menushell->gobj()));
gtkosx_application_set_window_menu(osxapp, nullptr);
}