+ return region_managed_within((WRegion*)mplex, st->reg);
+}
+
+
+static WStacking *stacking_within(WMPlex *mplex, WStacking *st)
+{
+ WRegion *reg=manager_within(mplex, st);
+
+ return (reg==NULL
+ ? NULL
+ : (reg==st->reg
+ ? st
+ : ioncore_find_stacking(reg)));
+}
+
+
+/* Mutually exclusive regions can't be pseudomodal */
+#define IS_PSEUDOMODAL(ST) ((ST)->lnode==NULL && (ST)->pseudomodal)
+
+
+static bool mapped_pseudomodal_include_filt(WStacking *st, void *data_)
+{
+ FiltData *data=(FiltData*)data_;
+ WStacking *stw;
+
+ if(st->reg==NULL || !REGION_IS_MAPPED(st->reg))
+ return FALSE;
+
+ if(!data->hidelist
+ || (data->to_try==NULL && data->group_st==NULL)
+ || st->level<STACKING_LEVEL_MODAL1){
+ return TRUE;
+ }
+
+ /* Ok, modal node in the way. Let's see if it is pseudomodal
+ * and can be hidden.
+ */
+
+ stw=stacking_within(data->mplex, st);
+
+ /* This should not happen */
+ if(stw==NULL || stw->reg==NULL)
+ return FALSE;
+
+ /* The node is within the same group, so it can not be hidden.
+ * Latter case should not happen.
+ */
+ if(stw==data->group_st || stw==data->to_try)
+ return TRUE;
+
+ if(IS_PSEUDOMODAL(stw)){
+ /* Don't insert multiple times. */
+ return !ptrlist_reinsert_first(data->hidelist, stw);
+ }
+
+ return TRUE;
+}
+
+
+static bool mgr_pseudomodal_approve_filt(WStacking *st, void *data_)
+{
+ FiltData *data=(FiltData*)data_;
+
+ return (data->group_st==NULL || st==data->group_st ||
+ manager_within(data->mplex, st)==data->group_st->reg);
+}
+
+
+WStacking *mplex_find_to_focus(WMPlex *mplex,
+ WStacking *to_try,
+ WStacking *group_st,
+ PtrList **hidelist)
+{
+ WStackingFilter *fi=mapped_pseudomodal_include_filt;
+ WStackingFilter *fa=mgr_pseudomodal_approve_filt;