- 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_find_to_focus(mplex, node, NULL, hidelist);
+
+ /* If 'node' points to a group, it isn't actually on the stacking list.
+ * Give it the focus, if there's nothing "proper" that could be focussed.
+ */
+ if(st==NULL && grp!=NULL && REGION_IS_MAPPED(grp))
+ st=node;
+
+ 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);
+}
+
+
+/* 1. Try keep focus in REGION_ACTIVE_SUB.
+ * 2. Choose something else, attempting previous in focus history.
+ */
+static WStacking *mplex_to_focus(WMPlex *mplex)
+{
+ WStacking *foc=NULL, *fallback=NULL;
+ WRegion *reg=NULL;
+
+ foc=maybe_focusable(REGION_ACTIVE_SUB(mplex));
+
+ if(foc==NULL){
+ /* Search focus history if no specific attempt set.*/
+ for(reg=ioncore_g.focus_current; reg!=NULL; reg=reg->active_next){
+ foc=has_stacking_within(mplex, reg);
+ if(foc!=NULL)
+ break;
+ }