- reg=mplex_do_to_focus_on(mplex, node, to_try);
- if(reg!=NULL || to_try!=NULL)
- return reg;
- /* We don't know whether something is blocking focus here,
- * or if there was nothing to focus (as node->reg itself
- * isn't on the stacking list).
- */
+ /* Only will return stuff within 'node' */
+ st=mplex_find_to_focus(mplex, to_try, node, hidelist);
+ if(st!=NULL){
+ if(within!=NULL)
+ *within=TRUE;
+ return st;
+ }
+ }
+
+ st=mplex_do_to_focus(mplex, node, hidelist);
+
+ if(st==node && within!=NULL)
+ *within=TRUE;
+
+ return st;
+}
+
+
+static WStacking *maybe_focusable(WRegion *reg)
+{
+ if(reg==NULL || !REGION_IS_MAPPED(reg))
+ return NULL;
+
+ return ioncore_find_stacking(reg);
+}
+
+
+static WStacking *has_stacking_within(WMPlex *mplex, WRegion *reg)
+{
+ while(reg!=NULL && REGION_MANAGER(reg)!=(WRegion*)mplex)
+ reg=REGION_MANAGER(reg);
+
+ return maybe_focusable(reg);
+}
+
+
+static WStacking *mplex_to_focus(WMPlex *mplex)
+{
+ WStacking *to_try=NULL;
+ WRegion *reg=NULL;
+ WStacking *st;
+
+ to_try=maybe_focusable(REGION_ACTIVE_SUB(mplex));
+
+ if(to_try==NULL){
+ /* Search focus history */
+ for(reg=ioncore_g.focus_current; reg!=NULL; reg=reg->active_next){
+ to_try=has_stacking_within(mplex, reg);
+ if(to_try!=NULL)
+ break;
+ }