]> Dogcows Code - chaz/openbox/commitdiff
don't run 100 actions when doing interactive actions. keep only one interactive actio...
authorDana Jansens <danakj@orodu.net>
Thu, 3 May 2007 04:21:16 +0000 (04:21 +0000)
committerDana Jansens <danakj@orodu.net>
Thu, 3 May 2007 04:21:16 +0000 (04:21 +0000)
openbox/keyboard.c

index ccfe04977c755ec23ef29815a6dde78be06bb9be..bee264f6f56f05efb71d7fc25f4bbed7cc9d09aa 100644 (file)
 #include <glib.h>
 
 typedef struct {
+    gboolean active;
     guint state;
     ObClient *client;
-    GSList *actions;
-    ObFrameContext context;
+    ObAction *action;
 } ObInteractiveState;
 
 KeyBindingTree *keyboard_firstnode = NULL;
 static ObPopup *popup = NULL;
-static GSList *interactive_states;
+static ObInteractiveState istate;
 static KeyBindingTree *curpos;
 
 static void grab_keys(gboolean grab)
@@ -186,92 +186,76 @@ gboolean keyboard_bind(GList *keylist, ObAction *action)
     return TRUE;
 }
 
-gboolean keyboard_interactive_grab(guint state, ObClient *client,
-                                   ObAction *action)
+static void keyboard_interactive_end(guint state, gboolean cancel, Time time,
+                                     gboolean ungrab)
 {
-    ObInteractiveState *s;
-
-    g_assert(action->data.any.interactive);
-
-    if (!interactive_states) {
-        grab_pointer(TRUE, FALSE, OB_CURSOR_POINTER);
-        if (!grab_keyboard(TRUE)) {
-            grab_pointer(FALSE, FALSE, OB_CURSOR_NONE);
-            return FALSE;
-        }
-    }
-
-    s = g_new(ObInteractiveState, 1);
-
-    s->state = state;
-    s->client = client;
-    s->actions = g_slist_append(NULL, action);
-
-    interactive_states = g_slist_append(interactive_states, s);
+    GSList *alist;
 
-    return TRUE;
-}
-
-void keyboard_interactive_end(ObInteractiveState *s,
-                              guint state, gboolean cancel, Time time)
-{
-    action_run_interactive(s->actions, s->client, state, time, cancel, TRUE);
+    g_assert(istate.active);
 
-    g_slist_free(s->actions);
-    g_free(s);
+    alist = g_slist_append(NULL, istate.action);
+    action_run_interactive(alist, istate.client, state, time, cancel, TRUE);
+    g_slist_free(alist);
 
-    interactive_states = g_slist_remove(interactive_states, s);
+    istate.active = FALSE;
 
-    if (!interactive_states) {
+    if (ungrab) {
         grab_keyboard(FALSE);
         grab_pointer(FALSE, FALSE, OB_CURSOR_NONE);
     }
 }
 
-void keyboard_interactive_end_client(ObClient *client, gpointer data)
+static void keyboard_interactive_end_client(ObClient *client, gpointer data)
 {
-    GSList *it, *next;
-
-    for (it = interactive_states; it; it = next) {
-        ObInteractiveState *s = it->data;
+    if (istate.active && istate.client == client)
+        istate.client = NULL;
+}
 
-        next = g_slist_next(it);
+gboolean keyboard_interactive_grab(guint state, ObClient *client,
+                                   ObAction *action)
+{
+    g_assert(action->data.any.interactive);
 
-        if (s->client == client)
-            s->client = NULL;
+    if (!istate.active) {
+        grab_pointer(TRUE, FALSE, OB_CURSOR_POINTER);
+        if (!grab_keyboard(TRUE)) {
+            grab_pointer(FALSE, FALSE, OB_CURSOR_NONE);
+            return FALSE;
+        }
+    } else if (action->func != istate.action->func) {
+        keyboard_interactive_end(state, FALSE, action->data.any.time, FALSE);
     }
+
+    istate.active = TRUE;
+    istate.state = state;
+    istate.client = client;
+    istate.action = action;
+
+    return TRUE;
 }
 
 gboolean keyboard_process_interactive_grab(const XEvent *e, ObClient **client)
 {
-    GSList *it, *next;
     gboolean handled = FALSE;
     gboolean done = FALSE;
     gboolean cancel = FALSE;
 
-    for (it = interactive_states; it; it = next) {
-        ObInteractiveState *s = it->data;
-
-        next = g_slist_next(it);
-        
-        if ((e->type == KeyRelease && 
-             !(s->state & e->xkey.state)))
-            done = TRUE;
-        else if (e->type == KeyPress) {
-            /*if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN))
-                done = TRUE;
-            else */if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE))
-                cancel = done = TRUE;
-        } else if (e->type == ButtonPress)
-            cancel = done = TRUE;
-
-        if (done) {
-            keyboard_interactive_end(s, e->xkey.state, cancel, e->xkey.time);
-
-            handled = TRUE;
-        } else
-            *client = s->client;
-    }
+    if ((e->type == KeyRelease && !(istate.state & e->xkey.state)))
+        done = TRUE;
+    else if (e->type == KeyPress) {
+        /*if (e->xkey.keycode == ob_keycode(OB_KEY_RETURN))
+          done = TRUE;
+          else */if (e->xkey.keycode == ob_keycode(OB_KEY_ESCAPE))
+              cancel = done = TRUE;
+    } else if (e->type == ButtonPress)
+        cancel = done = TRUE;
+
+    if (done) {
+        keyboard_interactive_end(e->xkey.state, cancel, e->xkey.time, TRUE);
+
+        handled = TRUE;
+    } else
+        *client = istate.client;
 
     return handled;
 }
@@ -326,7 +310,7 @@ void keyboard_event(ObClient *client, const XEvent *e)
 
 gboolean keyboard_interactively_grabbed()
 {
-    return !!interactive_states;
+    return istate.active;
 }
 
 void keyboard_startup(gboolean reconfig)
@@ -345,10 +329,7 @@ void keyboard_shutdown(gboolean reconfig)
     if (!reconfig)
         client_remove_destructor(keyboard_interactive_end_client);
 
-    for (it = interactive_states; it; it = g_slist_next(it))
-        g_free(it->data);
-    g_slist_free(interactive_states);
-    interactive_states = NULL;
+    istate.active = FALSE;
 
     ob_main_loop_timeout_remove(ob_main_loop, chain_timeout);
 
This page took 0.025387 seconds and 4 git commands to generate.