[PATCH] Visual feedback for keyboard commands
Ivan Stankovic
ivan.stankovic at fer.hr
Thu May 31 15:37:45 EDT 2007
---
gschem/include/globals.h | 3 +++
gschem/src/g_keys.c | 41 ++++++++++++++++++++++++++++++++++++++---
gschem/src/i_basic.c | 8 ++++++++
3 files changed, 49 insertions(+), 3 deletions(-)
diff --git a/gschem/include/globals.h b/gschem/include/globals.h
index bff096b..0e1c1c9 100644
--- a/gschem/include/globals.h
+++ b/gschem/include/globals.h
@@ -29,6 +29,9 @@ extern GdkVisual *visual;
extern GdkColor white;
extern GdkColor black;
+/* used for visual feedback when pressing keyboard accelerators */
+extern gchar *current_keyaccel_string;
+
#if 0
extern GdkColor red;
extern GdkColor green;
diff --git a/gschem/src/g_keys.c b/gschem/src/g_keys.c
index 03602a4..e4af0ed 100644
--- a/gschem/src/g_keys.c
+++ b/gschem/src/g_keys.c
@@ -40,6 +40,8 @@
#include <dmalloc.h>
#endif
+gchar *current_keyaccel_string = NULL;
+
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
@@ -69,6 +71,21 @@ int g_keys_execute(int state, int keyval)
return 0;
}
+ if(strcmp(key_name, "Escape") == 0) {
+ g_free(current_keyaccel_string);
+ current_keyaccel_string = NULL;
+ } else {
+ if(current_keyaccel_string) {
+ gchar *tmp = current_keyaccel_string;
+ current_keyaccel_string = g_strdup_printf("%s%s", tmp, key_name);
+ g_free(tmp);
+ }
+ else
+ current_keyaccel_string = g_strdup(key_name);
+ }
+
+ i_show_state(global_window_current, NULL);
+
if (state & GDK_SHIFT_MASK) {
modifier = g_strdup_printf("\"Shift ");
} else if (state & GDK_CONTROL_MASK) {
@@ -142,14 +159,32 @@ g_keys_dump_keymap (void)
return ret;
}
-/*! \brief
+/*! \brief Clear the current key accelerator string
*
+ * \par Function Description
+ * This function clears the current keyboard accelerator
+ * string in the status bar of the global_window_current
+ * toplevel. Called after the action specifed by the keyboard
+ * accelerator is executed and the associated timeout interval
+ * has passed.
+ *
+ * \param [in] data unused
*/
+static gboolean clear_keyaccel_string(gpointer data)
+{
+ g_free(current_keyaccel_string);
+ current_keyaccel_string = NULL;
+
+ i_show_state(global_window_current, NULL);
+ return FALSE;
+}
+
#define DEFINE_G_KEYS(name) \
SCM g_keys_ ## name(void) \
{ \
- i_callback_ ## name(global_window_current, 0, NULL); \
- return SCM_BOOL_T; \
+ i_callback_ ## name(global_window_current, 0, NULL); \
+ g_timeout_add(400, clear_keyaccel_string, 0); \
+ return SCM_BOOL_T; \
}
/*! \brief test-comment
diff --git a/gschem/src/i_basic.c b/gschem/src/i_basic.c
index a86a68a..d89dbee 100644
--- a/gschem/src/i_basic.c
+++ b/gschem/src/i_basic.c
@@ -183,6 +183,14 @@ void i_show_state(TOPLEVEL *w_current, const char *message)
what_to_say = g_strjoinv(" - ", (gchar **) array + i);
+ if(current_keyaccel_string) {
+ gchar *p = what_to_say;
+
+ what_to_say = g_strdup_printf("%s \t\t %s", current_keyaccel_string,
+ what_to_say);
+ g_free(p);
+ }
+
i_update_status(w_current, what_to_say);
g_free(what_to_say);
}
--
1.5.2
--VS++wcV0S1rZb1Fb--
More information about the geda-dev
mailing list