From 24d8e4e55d59c8e5ad81431dab0a68e9ce5ed1d6 Mon Sep 17 00:00:00 2001 From: mental Date: Wed, 29 Aug 2007 03:24:44 +0000 Subject: [PATCH] add experimental modifier remapping --- src/inkscape-private.h | 3 +++ src/inkscape.cpp | 26 +++++++++++++++++++++++++- src/main.cpp | 30 ++++++++++++++++++++++++++++++ src/preferences-skeleton.h | 1 + 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/inkscape-private.h b/src/inkscape-private.h index e6e6a44ea..93fd9c8af 100644 --- a/src/inkscape-private.h +++ b/src/inkscape-private.h @@ -29,6 +29,9 @@ GType inkscape_get_type (void); void inkscape_ref (void); void inkscape_unref (void); +guint inkscape_mapalt(); +void inkscape_mapalt(guint); + /* * These are meant solely for desktop, document etc. implementations */ diff --git a/src/inkscape.cpp b/src/inkscape.cpp index c167be493..7e46efce6 100644 --- a/src/inkscape.cpp +++ b/src/inkscape.cpp @@ -117,6 +117,7 @@ struct Inkscape::Application { gboolean dialogs_toggle; gboolean use_gui; // may want to consider a virtual function // for overriding things like the warning dlg's + guint mapalt; }; struct Inkscape::ApplicationClass { @@ -302,8 +303,9 @@ inkscape_init (SPObject * object) inkscape->desktops = NULL; inkscape->dialogs_toggle = TRUE; -} + inkscape->mapalt=GDK_MOD1_MASK; +} static void inkscape_dispose (GObject *object) @@ -348,6 +350,22 @@ inkscape_unref (void) g_object_unref (G_OBJECT (inkscape)); } +/* returns the mask of the keyboard modifier to map to Alt, zero if no mapping */ +/* Needs to be a guint because gdktypes.h does not define a 'no-modifier' value */ +guint +inkscape_mapalt() { + return inkscape->mapalt; +} + +/* Sets the keyboard modifer to map to Alt. Zero switches off mapping, as does '1', which is the default */ +void inkscape_mapalt(guint maskvalue) +{ + if(maskvalue<2 || maskvalue> 5 ){ /* MOD5 is the highest defined in gdktypes.h */ + inkscape->mapalt=0; + }else{ + inkscape->mapalt=(GDK_MOD1_MASK << (maskvalue-1)); + } +} static void inkscape_activate_desktop_private (Inkscape::Application *inkscape, SPDesktop *desktop) @@ -594,6 +612,12 @@ inkscape_application_init (const gchar *argv0, gboolean use_gui) Inkscape::UI::Dialogs::DebugDialog::getInstance()->captureLogMessages(); } + /* Check for global remapping of Alt key */ + if(use_gui) + { + inkscape_mapalt(guint(prefs_get_int_attribute("options.mapalt","value",0))); + } + /* Initialize the extensions */ Inkscape::Extension::init(); diff --git a/src/main.cpp b/src/main.cpp index 87913a801..cc359793a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -620,6 +620,34 @@ int sp_common_main( int argc, char const **argv, GSList **flDest ) return 0; } +static void +snooper(GdkEvent *event, gpointer data) { + if(inkscape_mapalt()) /* returns the map of the keyboard modifier to map to Alt, zero if no mapping */ + { + GdkModifierType mapping=(GdkModifierType)inkscape_mapalt(); + switch (event->type) { + case GDK_MOTION_NOTIFY: + if(event->motion.state & mapping) { + event->motion.state|=GDK_MOD1_MASK; + } + break; + case GDK_BUTTON_PRESS: + if(event->button.state & mapping) { + event->button.state|=GDK_MOD1_MASK; + } + break; + case GDK_KEY_PRESS: + if(event->key.state & mapping) { + event->key.state|=GDK_MOD1_MASK; + } + break; + default: + break; + } + } + gtk_main_do_event (event); +} + int sp_main_gui(int argc, char const **argv) { @@ -631,6 +659,8 @@ sp_main_gui(int argc, char const **argv) inkscape_gtk_stock_init(); + gdk_event_handler_set((GdkEventFunc)snooper, NULL, NULL); + Inkscape::Debug::log_display_config(); /* Set default icon */ diff --git a/src/preferences-skeleton.h b/src/preferences-skeleton.h index eb83a2b95..457fa6926 100644 --- a/src/preferences-skeleton.h +++ b/src/preferences-skeleton.h @@ -175,6 +175,7 @@ static char const preferences_skeleton[] = " \n" "\n" " \n" +" " " " " \n" " \n" -- 2.30.2