[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
gEDA-dev: [PATCH] gschem: Visual feedback for keyboard commands
Hi,
Here is a patch to add visual feedback when pressing keyboard
accelerators. The current keyboard accelerator is displayed in
the status bar.
Let me give an example; if you press 'f', the string displayed
will be just 'f' and it will stay displayed until you press
another key. Assume then you press 'w'. Then the 'w' will be
appended to the string and 'fw' will be displayed in the
status bar for 400ms. After that the string is cleared.
(The string is also cleared any time you press Escape.)
Personally I like this behaviour very much, but I'm sure
there are people with a different taste. What do you think?
The patch applies on top of my latest i_basic.c-cleanup
patch. Comments and suggestions welcome.
--
Ivan Stankovic, ivan.stankovic@fer.hr
"Protect your digital freedom and privacy, eliminate DRM,
learn more at http://www.defectivebydesign.org/what_is_drm"
---
gschem/include/globals.h | 3 ++
gschem/src/g_keys.c | 61 +++++++++++++++++++++++++++++++++++++++++++--
gschem/src/i_basic.c | 8 ++++++
3 files changed, 69 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..509c070 100644
--- a/gschem/src/g_keys.c
+++ b/gschem/src/g_keys.c
@@ -40,6 +40,9 @@
#include <dmalloc.h>
#endif
+gchar *current_keyaccel_string = NULL;
+static TOPLEVEL *saved_toplevel = NULL;
+
/*! \todo Finish function documentation!!!
* \brief
* \par Function Description
@@ -69,6 +72,26 @@ 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);
+ }
+
+ /* We need to save the toplevel because it may not be
+ * there anymore when we need to clear the status bar string
+ * (this occurs with the 'fc' command, for example) */
+ saved_toplevel = global_window_current;
+
+ 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 +165,46 @@ 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 saved 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)
+{
+ TOPLEVEL *w = global_window_current;
+
+ g_free(current_keyaccel_string);
+ current_keyaccel_string = NULL;
+
+ /* Find out if the toplevel is present... */
+ while(w->prev)
+ w = w->prev;
+
+ while(w) {
+ if(w == saved_toplevel) {
+ /* ... it is, update its status bar */
+ i_show_state(w, NULL);
+ break;
+ }
+ w = w->next;
+ }
+
+ 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
_______________________________________________
geda-dev mailing list
geda-dev@moria.seul.org
http://www.seul.org/cgi-bin/mailman/listinfo/geda-dev