]> Dogcows Code - chaz/openbox/blobdiff - openbox/actions/cyclewindows.c
symmetry..tho it's not used right now
[chaz/openbox] / openbox / actions / cyclewindows.c
index ed2a4d0b679370e1f5907ef2cba127d821b250e8..7b4bd11e29e58e3875206afcf2bde4ec2b323612 100644 (file)
@@ -14,7 +14,13 @@ typedef struct {
     GSList *actions;
 } Options;
 
+static gboolean cycling = FALSE;
+
 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node);
+static gpointer setup_forward_func(ObParseInst *i, xmlDocPtr doc,
+                                   xmlNodePtr node);
+static gpointer setup_backward_func(ObParseInst *i, xmlDocPtr doc,
+                                    xmlNodePtr node);
 static void     free_func(gpointer options);
 static gboolean run_func(ObActionsData *data, gpointer options);
 static gboolean i_input_func(guint initial_state,
@@ -27,12 +33,10 @@ static void     end_cycle(gboolean cancel, guint state, Options *o);
 
 void action_cyclewindows_startup()
 {
-    actions_register("CycleWindows",
-                     setup_func,
-                     free_func,
-                     run_func,
-                     i_input_func,
-                     i_cancel_func);
+    actions_register("NextWindow", setup_forward_func, free_func,
+                     run_func, i_input_func, i_cancel_func);
+    actions_register("PreviousWindow", setup_backward_func, free_func,
+                     run_func, i_input_func, i_cancel_func);
 }
 
 static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
@@ -43,8 +47,6 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
     o = g_new0(Options, 1);
     o->dialog = TRUE;
 
-    if ((n = parse_find_node("forward", node)))
-        o->forward = parse_bool(doc, n);
     if ((n = parse_find_node("linear", node)))
         o->linear = parse_bool(doc, n);
     if ((n = parse_find_node("dialog", node)))
@@ -66,6 +68,31 @@ static gpointer setup_func(ObParseInst *i, xmlDocPtr doc, xmlNodePtr node)
             m = parse_find_node("action", m->next);
         }
     }
+    else {
+        o->actions = g_slist_prepend(o->actions,
+                                     actions_parse_string("Focus"));
+        o->actions = g_slist_prepend(o->actions,
+                                     actions_parse_string("Raise"));
+        o->actions = g_slist_prepend(o->actions,
+                                     actions_parse_string("Unshade"));
+    }
+
+    return o;
+}
+
+static gpointer setup_forward_func(ObParseInst *i, xmlDocPtr doc,
+                                   xmlNodePtr node)
+{
+    Options *o = setup_func(i, doc, node);
+    o->forward = TRUE;
+    return o;
+}
+
+static gpointer setup_backward_func(ObParseInst *i, xmlDocPtr doc,
+                                    xmlNodePtr node)
+{
+    Options *o = setup_func(i, doc, node);
+    o->forward = FALSE;
     return o;
 }
 
@@ -73,6 +100,11 @@ static void free_func(gpointer options)
 {
     Options *o = options;
 
+    while (o->actions) {
+        actions_act_unref(o->actions->data);
+        o->actions = g_slist_delete_link(o->actions, o->actions);
+    }
+
     g_free(o);
 }
 
@@ -80,10 +112,6 @@ static gboolean run_func(ObActionsData *data, gpointer options)
 {
     Options *o = options;
 
-    /* if using focus_delay, stop the timer now so that focus doesn't go moving
-       on us */
-    event_halt_focus_delay();
-    
     focus_cycle(o->forward,
                 o->all_desktops,
                 o->dock_windows,
@@ -92,6 +120,7 @@ static gboolean run_func(ObActionsData *data, gpointer options)
                 TRUE,
                 o->dialog,
                 FALSE, FALSE);
+    cycling = TRUE;
 
     return TRUE;
 }
@@ -129,7 +158,10 @@ static gboolean i_input_func(guint initial_state,
 
 static void i_cancel_func(gpointer options)
 {
-    end_cycle(TRUE, 0, options);
+    /* we get cancelled when we move focus, but we're not cycling anymore, so
+       just ignore that */
+    if (cycling)
+        end_cycle(TRUE, 0, options);
 }
 
 static void end_cycle(gboolean cancel, guint state, Options *o)
@@ -144,6 +176,7 @@ static void end_cycle(gboolean cancel, guint state, Options *o)
                      TRUE,
                      o->dialog,
                      TRUE, cancel);
+    cycling = FALSE;
 
     if (ft) {
         actions_run_acts(o->actions, OB_USER_ACTION_KEYBOARD_KEY,
This page took 0.023622 seconds and 4 git commands to generate.