[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: gEDA-dev: [PATCH] gschem: Visual feedback for keyboard commands
On Thu, May 31, 2007 at 09:15:10PM +0100, Peter TB Brett wrote:
> Okay, having tested, I've found a bug; it doesn't display modifier keys.
> Ideally, it should show the same text as is shown in the menus. In any case,
> it should distinguish between "c" and "Ctrl-c".
The patch below should implement this. Note that I'm not very happy
with the behaviour, and this patch certainly isn't for CVS.
For example, see what happens when you press the return key several
times. It floods the entire status bar with a 'ReturnReturn..." string.
Would a static global counter be acceptable to solve this problem? :)
Because, I really don't know how to solve this (yes, I tried, very
hard, but the resulting code was _very_ complicated which is what
I'm trying to avoid here). Maybe I'm just dumb.
--
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 | 77 ++++++++++++++++++++++++++++++++++++++--------
gschem/src/i_basic.c | 8 +++++
3 files changed, 75 insertions(+), 13 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..cc69f35 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
@@ -58,9 +60,8 @@ int g_keys_execute(int state, int keyval)
}
key_name = gdk_keyval_name(keyval);
- if ( key_name == NULL ) {
+ if ( key_name == NULL )
return 0;
- }
/* don't pass the raw modifier key presses to the guile code */
if (strstr(key_name, "Alt") ||
@@ -69,17 +70,35 @@ int g_keys_execute(int state, int keyval)
return 0;
}
- if (state & GDK_SHIFT_MASK) {
- modifier = g_strdup_printf("\"Shift ");
- } else if (state & GDK_CONTROL_MASK) {
- modifier = g_strdup_printf("\"Control ");
- } else if (state & GDK_MOD1_MASK) {
- modifier = g_strdup_printf("\"Alt ");
+ if (state & GDK_SHIFT_MASK)
+ modifier = g_strdup_printf("Shift ");
+ else if (state & GDK_CONTROL_MASK)
+ modifier = g_strdup_printf("Control ");
+ else if (state & GDK_MOD1_MASK)
+ modifier = g_strdup_printf("Alt ");
+ else
+ modifier = g_strdup("");
+
+ if(strcmp(key_name, "Escape") == 0) {
+ /*|| (current_keyaccel_string && strcmp(current_keyaccel_string, key_name) != 0)) { */
+ g_free(current_keyaccel_string);
+ current_keyaccel_string = NULL;
} else {
- modifier = g_strdup_printf("\"");
+ gchar *p, *r;
+
+ p = current_keyaccel_string;
+ current_keyaccel_string = g_strconcat(modifier, key_name, NULL);
+ if(p) {
+ r = g_strconcat(p, current_keyaccel_string, NULL);
+ g_free(p);
+ g_free(current_keyaccel_string);
+ current_keyaccel_string = r;
+ }
}
- guile_string = g_strdup_printf("(press-key %s%s\")",
+ i_show_state(global_window_current, NULL);
+
+ guile_string = g_strdup_printf("(press-key \"%s%s\")",
modifier, key_name);
#if DEBUG
@@ -142,14 +161,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 relevant toplevel.
+ * Called after the action specifed by the keyboard
+ * accelerator is executed and the associated timeout interval
+ * has passed.
+ *
+ * \param [in] data a pointer to the toplevel
*/
+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 == (TOPLEVEL *) data) {
+ /* ... 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; \
+ g_timeout_add(400, clear_keyaccel_string, global_window_current); \
+ i_callback_ ## name(global_window_current, 0, NULL); \
+ return SCM_BOOL_T; \
}
/*! \brief test-comment
diff --git a/gschem/src/i_basic.c b/gschem/src/i_basic.c
index 3b41f49..7e7f96a 100644
--- a/gschem/src/i_basic.c
+++ b/gschem/src/i_basic.c
@@ -184,6 +184,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