add a popup dialog that shows where you are in a keychain

This commit is contained in:
Dana Jansens 2007-04-25 20:04:25 +00:00
parent b5dbe857db
commit df9b2294db
2 changed files with 41 additions and 32 deletions

View file

@ -32,12 +32,11 @@
#include "keyboard.h" #include "keyboard.h"
#include "translate.h" #include "translate.h"
#include "moveresize.h" #include "moveresize.h"
#include "popup.h"
#include "gettext.h" #include "gettext.h"
#include <glib.h> #include <glib.h>
KeyBindingTree *keyboard_firstnode;
typedef struct { typedef struct {
guint state; guint state;
ObClient *client; ObClient *client;
@ -45,37 +44,31 @@ typedef struct {
ObFrameContext context; ObFrameContext context;
} ObInteractiveState; } ObInteractiveState;
KeyBindingTree *keyboard_firstnode = NULL;
static ObPopup *popup = NULL;
static GSList *interactive_states; static GSList *interactive_states;
static KeyBindingTree *curpos; static KeyBindingTree *curpos;
static void grab_for_window(Window win, gboolean grab) static void grab_keys(gboolean grab)
{ {
KeyBindingTree *p; KeyBindingTree *p;
ungrab_all_keys(win); ungrab_all_keys(RootWindow(ob_display, ob_screen));
if (grab) { if (grab) {
p = curpos ? curpos->first_child : keyboard_firstnode; p = curpos ? curpos->first_child : keyboard_firstnode;
while (p) { while (p) {
grab_key(p->key, p->state, win, GrabModeAsync); grab_key(p->key, p->state, RootWindow(ob_display, ob_screen),
GrabModeAsync);
p = p->next_sibling; p = p->next_sibling;
} }
if (curpos) if (curpos)
grab_key(config_keyboard_reset_keycode, grab_key(config_keyboard_reset_keycode,
config_keyboard_reset_state, config_keyboard_reset_state,
win, GrabModeAsync); RootWindow(ob_display, ob_screen), GrabModeAsync);
} }
} }
static void grab_keys(gboolean grab)
{
GList *it;
grab_for_window(screen_support_win, grab);
grab_for_window(RootWindow(ob_display, ob_screen), grab);
}
static gboolean chain_timeout(gpointer data) static gboolean chain_timeout(gpointer data)
{ {
keyboard_reset_chains(); keyboard_reset_chains();
@ -83,23 +76,38 @@ static gboolean chain_timeout(gpointer data)
return FALSE; /* don't repeat */ return FALSE; /* don't repeat */
} }
static void set_curpos(KeyBindingTree *newpos)
{
grab_keys(FALSE);
curpos = newpos;
grab_keys(TRUE);
if (curpos != NULL) {
gchar *text = NULL;
GList *it;
for (it = curpos->keylist; it; it = g_list_next(it))
text = g_strconcat((text ? text : ""), it->data, "-", NULL);
popup_position(popup, NorthWestGravity, 10, 10);
popup_show(popup, text);
g_free(text);
} else
popup_hide(popup);
}
void keyboard_reset_chains() void keyboard_reset_chains()
{ {
ob_main_loop_timeout_remove(ob_main_loop, chain_timeout); ob_main_loop_timeout_remove(ob_main_loop, chain_timeout);
if (curpos) { if (curpos)
grab_keys(FALSE); set_curpos(NULL);
curpos = NULL;
grab_keys(TRUE);
}
} }
void keyboard_unbind_all() void keyboard_unbind_all()
{ {
tree_destroy(keyboard_firstnode); tree_destroy(keyboard_firstnode);
keyboard_firstnode = NULL; keyboard_firstnode = NULL;
grab_keys(FALSE);
curpos = NULL;
} }
gboolean keyboard_bind(GList *keylist, ObAction *action) gboolean keyboard_bind(GList *keylist, ObAction *action)
@ -269,9 +277,7 @@ void keyboard_event(ObClient *client, const XEvent *e)
ob_main_loop_timeout_add(ob_main_loop, 5 * G_USEC_PER_SEC, ob_main_loop_timeout_add(ob_main_loop, 5 * G_USEC_PER_SEC,
chain_timeout, NULL, chain_timeout, NULL,
g_direct_equal, NULL); g_direct_equal, NULL);
grab_keys(FALSE); set_curpos(p);
curpos = p;
grab_keys(TRUE);
} else { } else {
keyboard_reset_chains(); keyboard_reset_chains();
@ -294,6 +300,7 @@ gboolean keyboard_interactively_grabbed()
void keyboard_startup(gboolean reconfig) void keyboard_startup(gboolean reconfig)
{ {
grab_keys(TRUE); grab_keys(TRUE);
popup = popup_new(FALSE);
if (!reconfig) if (!reconfig)
client_add_destructor(keyboard_interactive_end_client, NULL); client_add_destructor(keyboard_interactive_end_client, NULL);
@ -314,5 +321,9 @@ void keyboard_shutdown(gboolean reconfig)
ob_main_loop_timeout_remove(ob_main_loop, chain_timeout); ob_main_loop_timeout_remove(ob_main_loop, chain_timeout);
keyboard_unbind_all(); keyboard_unbind_all();
set_curpos(NULL);
popup_free(popup);
popup = NULL;
} }

View file

@ -52,16 +52,14 @@ KeyBindingTree *tree_build(GList *keylist)
return NULL; /* nothing in the list.. */ return NULL; /* nothing in the list.. */
for (it = g_list_last(keylist); it; it = g_list_previous(it)) { for (it = g_list_last(keylist); it; it = g_list_previous(it)) {
GList *kit;
p = ret; p = ret;
ret = g_new0(KeyBindingTree, 1); ret = g_new0(KeyBindingTree, 1);
if (p == NULL) {
GList *it;
/* this is the first built node, the bottom node of the tree */ for (kit = it; kit != NULL; kit = g_list_previous(kit))
ret->keylist = g_list_copy(keylist); /* shallow copy */ ret->keylist = g_list_prepend(ret->keylist,
for (it = ret->keylist; it; it = g_list_next(it)) /* deep copy */ g_strdup(kit->data)); /* deep copy */
it->data = g_strdup(it->data);
}
ret->first_child = p; ret->first_child = p;
if (!translate_key(it->data, &ret->state, &ret->key)) { if (!translate_key(it->data, &ret->state, &ret->key)) {
tree_destroy(ret); tree_destroy(ret);