+ }
+ }
+
+ st=mplex_find_to_focus(mplex, node, NULL, 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);
+}
+
+
+/* 1. Try keep focus in REGION_ACTIVE_SUB.
+ * 2. Try given `node`.
+ * 3. Choose something else, attempting previous in focus history
+ * (unless `node` was set).
+ */
+static WStacking *mplex_to_focus(WMPlex *mplex, WStacking *node)
+{
+ WStacking *foc=NULL, *fallback=NULL;
+ WRegion *reg=NULL;
+ bool within=FALSE;
+ WStacking *st;
+
+ foc=maybe_focusable(REGION_ACTIVE_SUB(mplex));
+
+ if(foc==NULL && node==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;
+ }
+ }
+
+ if(foc!=NULL){
+ /*fallback=mplex_find_to_focus(mplex, foc, NULL, NULL);*/
+ /* In the history search case, 'foc' might point to a group,
+ * since we don't properly try to find a stacking within it...