+ if(OBJ_IS(reg, WRootWin))
+ break;
+
+ *subreg=reg;
+ reg=REGION_PARENT_REG(reg);
+ }while(reg!=NULL);
+
+ return binding;
+}
+
+static WBinding *lookup_binding(WRegion *oreg,
+ int act, uint state, uint kcb,
+ WRegion **binding_owner, WRegion **subreg)
+{
+ WRegion *reg=oreg;
+
+ /* Find the deepest nested active window grabbing this key. */
+ while(reg->active_sub!=NULL)
+ reg=reg->active_sub;
+
+ return lookup_binding_(reg, act, state, kcb, oreg->submapstat,
+ binding_owner, subreg);
+}
+
+
+static void do_call_binding(WBinding *binding, WRegion *reg, WRegion *subreg)
+{
+ WRegion *mgd=region_managed_within(reg, subreg);
+
+ /* TODO: having to pass both mgd and subreg for some handlers
+ * to work is ugly and complex.
+ */
+ extl_call(binding->func, "ooo", NULL, reg, mgd, subreg);
+}
+
+
+static int do_key(WRegion *oreg, XKeyEvent *ev)
+{
+ WBinding *binding=NULL;
+ WRegion *binding_owner=NULL, *subreg=NULL;
+ bool grabbed=(oreg->flags®ION_BINDINGS_ARE_GRABBED);
+ int ret=GRAB_NONE;
+
+ if(grabbed){
+ binding=lookup_binding(oreg, BINDING_KEYPRESS, ev->state, ev->keycode,
+ &binding_owner, &subreg);