Reserve more video memory for Xdummy
[notion/jeffpc.git] / ioncore / group.c
blobc0f8063002b6e514bc960f558f370c204d888f4b
1 /*
2 * ion/ioncore/group.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <string.h>
11 #include <X11/Xatom.h>
13 #include <libtu/minmax.h>
14 #include <libtu/objp.h>
15 #include <libmainloop/defer.h>
17 #include <ioncore/property.h>
19 #include "common.h"
20 #include "rootwin.h"
21 #include "focus.h"
22 #include "global.h"
23 #include "region.h"
24 #include "manage.h"
25 #include "screen.h"
26 #include "names.h"
27 #include "saveload.h"
28 #include "attach.h"
29 #include "regbind.h"
30 #include "extlconv.h"
31 #include "xwindow.h"
32 #include "resize.h"
33 #include "stacking.h"
34 #include "sizepolicy.h"
35 #include "bindmaps.h"
36 #include "navi.h"
37 #include "sizehint.h"
38 #include "llist.h"
39 #include "mplex.h"
40 #include "group.h"
41 #include "grouppholder.h"
42 #include "frame.h"
43 #include "float-placement.h"
44 #include "return.h"
47 static void group_place_stdisp(WGroup *ws, WWindow *parent,
48 int pos, WRegion *stdisp);
50 static void group_remanage_stdisp(WGroup *ws);
52 static void group_do_set_bottom(WGroup *grp, WStacking *st);
55 /*{{{ Stacking list stuff */
58 WStacking *group_get_stacking(WGroup *ws)
60 WWindow *par=REGION_PARENT(ws);
62 return (par==NULL
63 ? NULL
64 : window_get_stacking(par));
68 WStacking **group_get_stackingp(WGroup *ws)
70 WWindow *par=REGION_PARENT(ws);
72 return (par==NULL
73 ? NULL
74 : window_get_stackingp(par));
78 static bool wsfilt(WStacking *st, void *ws)
80 return (st->reg!=NULL && REGION_MANAGER(st->reg)==(WRegion*)ws);
84 static bool wsfilt_nostdisp(WStacking *st, void *ws)
86 return (wsfilt(st, ws) && ((WGroup*)ws)->managed_stdisp!=st);
90 void group_iter_init(WGroupIterTmp *tmp, WGroup *ws)
92 stacking_iter_mgr_init(tmp, ws->managed_list, NULL, ws);
96 void group_iter_init_nostdisp(WGroupIterTmp *tmp, WGroup *ws)
98 stacking_iter_mgr_init(tmp, ws->managed_list, wsfilt_nostdisp, ws);
102 WRegion *group_iter(WGroupIterTmp *tmp)
104 return stacking_iter_mgr(tmp);
108 WStacking *group_iter_nodes(WGroupIterTmp *tmp)
110 return stacking_iter_mgr_nodes(tmp);
114 WGroupIterTmp group_iter_default_tmp;
117 /*}}}*/
120 /*{{{ region dynfun implementations */
123 static void group_fit(WGroup *ws, const WRectangle *geom)
125 REGION_GEOM(ws)=*geom;
129 bool group_fitrep(WGroup *ws, WWindow *par, const WFitParams *fp)
131 WGroupIterTmp tmp;
132 WStacking *unweaved=NULL;
133 int xdiff=0, ydiff=0;
134 WStacking *st;
135 WWindow *oldpar;
136 WRectangle g;
138 oldpar=REGION_PARENT(ws);
140 if(par==NULL){
141 if(fp->mode&REGION_FIT_WHATEVER)
142 return TRUE;
143 REGION_GEOM(ws)=fp->g;
144 }else{
145 if(!region_same_rootwin((WRegion*)ws, (WRegion*)par))
146 return FALSE;
148 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg!=NULL)
149 region_detach_manager(ws->managed_stdisp->reg);
151 assert(ws->managed_stdisp==NULL);
153 xdiff=fp->g.x-REGION_GEOM(ws).x;
154 ydiff=fp->g.y-REGION_GEOM(ws).y;
156 region_unset_parent((WRegion*)ws);
157 XReparentWindow(ioncore_g.dpy, ws->dummywin, par->win, -1, -1);
158 region_set_parent((WRegion*)ws, par);
160 REGION_GEOM(ws).x=fp->g.x;
161 REGION_GEOM(ws).y=fp->g.y;
162 if(!(fp->mode&REGION_FIT_WHATEVER)){
163 REGION_GEOM(ws).w=fp->g.w;
164 REGION_GEOM(ws).h=fp->g.h;
167 if(oldpar!=NULL)
168 unweaved=stacking_unweave(&oldpar->stacking, wsfilt, (void*)ws);
171 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
172 WFitParams fp2=*fp;
174 if(st->reg==NULL)
175 continue;
177 g=REGION_GEOM(st->reg);
178 g.x+=xdiff;
179 g.y+=ydiff;
181 if(fp->mode&REGION_FIT_WHATEVER){
182 fp2.g=g;
183 }else{
184 fp2.g=REGION_GEOM(ws);
185 sizepolicy(&st->szplcy, st->reg, &g, REGION_RQGEOM_WEAK_ALL, &fp2);
188 if(!region_fitrep(st->reg, par, &fp2)){
189 warn(TR("Error reparenting %s."), region_name(st->reg));
190 region_detach_manager(st->reg);
194 if(unweaved!=NULL)
195 stacking_weave(&par->stacking, &unweaved, FALSE);
197 return TRUE;
201 static void group_map(WGroup *ws)
203 WRegion *reg;
204 WGroupIterTmp tmp;
206 REGION_MARK_MAPPED(ws);
207 XMapWindow(ioncore_g.dpy, ws->dummywin);
209 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
210 region_map(reg);
215 static void group_unmap(WGroup *ws)
217 WRegion *reg;
218 WGroupIterTmp tmp;
220 REGION_MARK_UNMAPPED(ws);
221 XUnmapWindow(ioncore_g.dpy, ws->dummywin);
223 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
224 region_unmap(reg);
229 static WStacking *find_to_focus(WGroup *ws, WStacking *st, bool group_only)
231 WStacking *stacking=group_get_stacking(ws);
233 if(stacking==NULL)
234 return st;
236 return stacking_find_to_focus_mapped(stacking, st,
237 (group_only ? (WRegion*)ws : NULL));
241 static void group_do_set_focus(WGroup *ws, bool warp)
243 WStacking *st=find_to_focus(ws, ws->current_managed, FALSE);
245 if(st!=NULL && st->reg!=NULL)
246 region_do_set_focus(st->reg, warp);
247 else
248 region_finalise_focusing((WRegion*)ws, ws->dummywin, warp, CurrentTime);
252 static bool group_managed_prepare_focus(WGroup *ws, WRegion *reg,
253 int flags, WPrepareFocusResult *res)
255 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
256 WStacking *st=group_find_stacking(ws, reg);
258 if(st==NULL)
259 return FALSE;
261 if(mplex!=NULL){
262 WStacking *node=mplex_find_stacking(mplex, (WRegion*)ws);
264 if(node==NULL)
265 return FALSE;
267 return mplex_do_prepare_focus(mplex, node, st,
268 flags, res);
269 }else{
270 if(!region_prepare_focus((WRegion*)ws, flags, res))
271 return FALSE;
273 st=find_to_focus(ws, st, FALSE);
275 if(st==NULL)
276 return FALSE;
278 if(ioncore_g.autoraise &&
279 !(flags&REGION_GOTO_ENTERWINDOW) &&
280 st->level>STACKING_LEVEL_BOTTOM){
281 WStacking **stackingp=group_get_stackingp(ws);
282 stacking_restack(stackingp, st, None, NULL, NULL, FALSE);
285 res->reg=st->reg;
286 res->flags=flags;
288 return (res->reg==reg);
293 void group_managed_remove(WGroup *ws, WRegion *reg)
295 bool mcf=region_may_control_focus((WRegion*)ws);
296 WStacking *st, *next_st=NULL;
297 bool was_stdisp=FALSE, was_bottom=FALSE;
298 bool was_current=FALSE;
300 st=group_find_stacking(ws, reg);
302 if(st!=NULL){
303 if(st==ws->bottom){
304 was_bottom=TRUE;
305 group_do_set_bottom(ws, NULL);
308 if(st==ws->managed_stdisp){
309 ws->managed_stdisp=NULL;
310 was_stdisp=TRUE;
313 if(st==ws->current_managed){
314 ws->current_managed=NULL;
315 was_current=TRUE;
318 next_st=stacking_unstack(REGION_PARENT(ws), st);
319 UNLINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
320 stacking_unassoc(st);
321 stacking_free(st);
324 region_unset_manager(reg, (WRegion*)ws);
326 if(!OBJ_IS_BEING_DESTROYED(ws) && was_current){
327 /* This may still potentially cause problems when focus
328 * change is pending. Perhaps we should use region_await_focus,
329 * if it is pointing to our child (and region_may_control_focus
330 * fail if it is pointing somewhere else).
332 WStacking *stf=find_to_focus(ws, next_st, TRUE);
333 if(stf!=NULL && mcf){
334 region_maybewarp_now(stf->reg, FALSE);
335 }else{
336 ws->current_managed=stf;
342 void group_managed_notify(WGroup *ws, WRegion *reg, WRegionNotify how)
344 if(how==ioncore_g.notifies.activated ||
345 how==ioncore_g.notifies.pseudoactivated){
346 ws->current_managed=group_find_stacking(ws, reg);
351 /*}}}*/
354 /*{{{ Create/destroy */
357 bool group_init(WGroup *ws, WWindow *par, const WFitParams *fp)
359 const char *p[1];
361 ws->current_managed=NULL;
362 ws->managed_stdisp=NULL;
363 ws->bottom=NULL;
364 ws->managed_list=NULL;
365 ws->phs=NULL;
367 ws->dummywin=XCreateWindow(ioncore_g.dpy, par->win,
368 fp->g.x, fp->g.y, 1, 1, 0,
369 CopyFromParent, InputOnly,
370 CopyFromParent, 0, NULL);
371 if(ws->dummywin==None)
372 return FALSE;
374 p[0] = "WGroup";
375 xwindow_set_text_property(ws->dummywin, XA_WM_NAME, p, 1);
377 region_init(&ws->reg, par, fp);
378 region_register(&ws->reg);
380 XSelectInput(ioncore_g.dpy, ws->dummywin,
381 FocusChangeMask|KeyPressMask|KeyReleaseMask|
382 ButtonPressMask|ButtonReleaseMask);
383 XSaveContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context,
384 (XPointer)ws);
386 ((WRegion*)ws)->flags|=REGION_GRAB_ON_PARENT;
388 region_add_bindmap((WRegion*)ws, ioncore_group_bindmap);
390 return TRUE;
394 WGroup *create_group(WWindow *par, const WFitParams *fp)
396 CREATEOBJ_IMPL(WGroup, group, (p, par, fp));
400 void group_deinit(WGroup *ws)
402 WGroupIterTmp tmp;
403 WRegion *reg;
405 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg!=NULL){
406 group_managed_remove(ws, ws->managed_stdisp->reg);
407 assert(ws->managed_stdisp==NULL);
410 FOR_ALL_MANAGED_BY_GROUP(ws, reg, tmp){
411 destroy_obj((Obj*)reg);
414 assert(ws->managed_list==NULL);
416 XDeleteContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context);
417 XDestroyWindow(ioncore_g.dpy, ws->dummywin);
418 ws->dummywin=None;
420 while(ws->phs!=NULL)
421 grouppholder_do_unlink(ws->phs);
423 region_deinit(&ws->reg);
427 bool group_rescue_clientwins(WGroup *ws, WRescueInfo *info)
429 WGroupIterTmp tmp;
431 group_iter_init_nostdisp(&tmp, ws);
433 return region_rescue_some_clientwins((WRegion*)ws, info,
434 (WRegionIterator*)group_iter,
435 &tmp);
439 WPHolder *group_get_rescue_pholder_for(WGroup *ws,
440 WRegion *forwhat)
442 WGroupAttachParams ap=GROUPATTACHPARAMS_INIT;
443 WFramedParam fp=FRAMEDPARAM_INIT;
444 WPHolder *ph;
446 ap.geom_set=TRUE;
447 ap.geom=REGION_GEOM(forwhat);
449 ap.geom_weak_set=1;
451 if(REGION_PARENT(forwhat)==REGION_PARENT(ws)){
452 ap.geom.x-=REGION_GEOM(ws).x;
453 ap.geom.y-=REGION_GEOM(ws).y;
454 }else{
455 ap.geom_weak=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
458 /* frame mode */
460 WFrame *frame=OBJ_CAST(forwhat, WFrame);
461 if(frame!=NULL)
462 fp.mode=frame->mode;
465 ph=(WPHolder*)create_grouppholder(ws, NULL, &ap);
467 return pholder_either((WPHolder*)create_framedpholder(ph, &fp), ph);
472 /*}}}*/
475 /*{{{ Bottom */
478 void group_bottom_set(WGroup *grp)
480 CALL_DYN(group_bottom_set, grp, (grp));
484 static void group_do_set_bottom(WGroup *grp, WStacking *st)
486 WStacking *was=grp->bottom;
487 WStacking *std=grp->managed_stdisp;
489 grp->bottom=st;
491 if(!OBJ_IS_BEING_DESTROYED(grp)){
492 bool noremanage=((was==st) ||
493 (was==NULL && std==NULL) ||
494 (st!=NULL && st==std) ||
495 (st==NULL && was==std));
497 if(!noremanage &&
498 (st==NULL || HAS_DYN(st->reg, region_manage_stdisp))){
499 group_remanage_stdisp(grp);
502 group_bottom_set(grp);
507 /*EXTL_DOC
508 * Sets the `bottom' of \var{ws}. The region \var{reg} must already
509 * be managed by \var{ws}, unless \code{nil}.
511 EXTL_EXPORT_MEMBER
512 bool group_set_bottom(WGroup *ws, WRegion *reg)
514 WStacking *st=NULL;
516 if(reg!=NULL){
517 st=group_find_stacking(ws, reg);
519 if(st==NULL)
520 return FALSE;
523 group_do_set_bottom(ws, st);
525 return TRUE;
529 /*EXTL_DOC
530 * Returns the `bottom' of \var{ws}.
532 EXTL_SAFE
533 EXTL_EXPORT_MEMBER
534 WRegion *group_bottom(WGroup *ws)
536 return (ws->bottom!=NULL ? ws->bottom->reg : NULL);
540 /*}}}*/
543 /*{{{ Attach */
546 WStacking *group_do_add_managed(WGroup *ws, WRegion *reg, int level,
547 WSizePolicy szplcy)
549 WStacking *st=NULL;
550 CALL_DYN_RET(st, WStacking*, group_do_add_managed, ws,
551 (ws, reg, level, szplcy));
552 return st;
556 WStacking *group_do_add_managed_default(WGroup *ws, WRegion *reg, int level,
557 WSizePolicy szplcy)
559 WStacking *st=NULL, *tmp=NULL;
560 Window bottom=None, top=None;
561 WStacking **stackingp=group_get_stackingp(ws);
562 WFrame *frame;
564 if(stackingp==NULL)
565 return NULL;
567 st=create_stacking();
569 if(st==NULL)
570 return NULL;
572 if(!stacking_assoc(st, reg)){
573 stacking_free(st);
574 return NULL;
577 frame=OBJ_CAST(reg, WFrame);
578 if(frame!=NULL){
579 if(framemode_unalt(frame_mode(frame))==FRAME_MODE_TILED)
580 frame_set_mode(frame, FRAME_MODE_FLOATING);
583 st->level=level;
584 st->szplcy=szplcy;
586 LINK_ITEM_FIRST(tmp, st, next, prev);
587 stacking_weave(stackingp, &tmp, FALSE);
588 assert(tmp==NULL);
590 LINK_ITEM(ws->managed_list, st, mgr_next, mgr_prev);
591 region_set_manager(reg, (WRegion*)ws);
593 if(region_is_fully_mapped((WRegion*)ws))
594 region_map(reg);
596 return st;
600 static void geom_group_to_parent(WGroup *ws, const WRectangle *g,
601 WRectangle *wg)
603 wg->x=g->x+REGION_GEOM(ws).x;
604 wg->y=g->y+REGION_GEOM(ws).y;
605 wg->w=maxof(1, g->w);
606 wg->h=maxof(1, g->h);
610 static int group_must_focus(WGroup *ws, WStacking *st)
612 WStacking *stacking=group_get_stacking(ws);
614 return (stacking!=NULL && stacking_must_focus(stacking, st));
618 bool group_do_attach_final(WGroup *ws,
619 WRegion *reg,
620 const WGroupAttachParams *param)
622 WStacking *st, *stabove=NULL;
623 WSizePolicy szplcy;
624 WFitParams fp;
625 WRectangle g;
626 uint level;
627 int weak;
628 bool sw;
630 /* Stacking */
631 if(param->stack_above!=NULL)
632 stabove=group_find_stacking(ws, param->stack_above);
634 level=(stabove!=NULL
635 ? stabove->level
636 : (param->level_set
637 ? param->level
638 : STACKING_LEVEL_NORMAL));
640 /* Fit */
641 szplcy=(param->szplcy_set
642 ? param->szplcy
643 : (param->bottom
644 ? SIZEPOLICY_FULL_EXACT
645 : SIZEPOLICY_VISIBILITY_CONSTRAINED));
647 if(!param->whatever){
648 weak=(param->geom_weak_set
649 ? param->geom_weak
650 : (param->geom_set
652 : REGION_RQGEOM_WEAK_ALL));
654 if(param->geom_set)
655 geom_group_to_parent(ws, &param->geom, &g);
656 else
657 g=REGION_GEOM(reg);
659 /* If the requested geometry does not overlap the workspaces's geometry,
660 * position request is never honoured.
662 if((g.x+g.w<=REGION_GEOM(ws).x) ||
663 (g.x>=REGION_GEOM(ws).x+REGION_GEOM(ws).w)){
664 weak|=REGION_RQGEOM_WEAK_X;
667 if((g.y+g.h<=REGION_GEOM(ws).y) ||
668 (g.y>=REGION_GEOM(ws).y+REGION_GEOM(ws).h)){
669 weak|=REGION_RQGEOM_WEAK_Y;
672 if(weak&(REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y) &&
673 (szplcy==SIZEPOLICY_UNCONSTRAINED ||
674 szplcy==SIZEPOLICY_VISIBILITY_CONSTRAINED ||
675 szplcy==SIZEPOLICY_FREE ||
676 szplcy==SIZEPOLICY_FREE_GLUE /* without flags */)){
677 /* TODO: use 'weak'? */
678 group_calc_placement(ws, level, &g);
681 fp.g=REGION_GEOM(ws);
682 fp.mode=REGION_FIT_EXACT;
684 sizepolicy(&szplcy, reg, &g, weak, &fp);
686 if(rectangle_compare(&fp.g, &REGION_GEOM(reg))!=RECTANGLE_SAME)
687 region_fitrep(reg, NULL, &fp);
690 /* Add */
691 st=group_do_add_managed(ws, reg, level, szplcy);
693 if(st==NULL)
694 return FALSE;
696 if(stabove!=NULL)
697 st->above=stabove;
699 if(param->bottom)
700 group_do_set_bottom(ws, st);
702 /* Focus */
703 sw=((param->switchto_set ? param->switchto : ioncore_g.switchto_new)
704 ? st==find_to_focus(ws, st, FALSE)
705 : group_must_focus(ws, st));
707 if(sw){
708 if(region_may_control_focus((WRegion*)ws))
709 region_set_focus(st->reg);
710 else
711 ws->current_managed=st;
712 }else if(region_is_fully_mapped(reg)){
713 region_pointer_focus_hack(reg);
716 return TRUE;
720 static void group_attach_fp(WGroup *ws, const WGroupAttachParams *param,
721 WFitParams *fp)
723 if(param->geom_set){
724 geom_group_to_parent(ws, &param->geom, &fp->g);
725 fp->mode=REGION_FIT_EXACT;
726 }else{
727 fp->g=REGION_GEOM(ws);
728 fp->mode=REGION_FIT_BOUNDS|REGION_FIT_WHATEVER;
733 WRegion *group_do_attach(WGroup *ws,
734 /*const*/ WGroupAttachParams *param,
735 WRegionAttachData *data)
737 WFitParams fp;
738 WRegion *reg;
740 if(ws->bottom!=NULL && param->bottom){
741 warn(TR("'bottom' already set."));
742 return NULL;
745 group_attach_fp(ws, param, &fp);
747 return region_attach_helper((WRegion*) ws, REGION_PARENT(ws), &fp,
748 (WRegionDoAttachFn*)group_do_attach_final,
749 /*(const WRegionAttachParams*)*/param, data);
750 /* ^^^^ doesn't seem to work. */
754 void groupattachparams_get(WGroupAttachParams *par, ExtlTab tab, const char *sub)
756 int tmp;
757 bool tmpb;
758 char *tmps;
759 ExtlTab g;
761 par->switchto_set=0;
762 par->level_set=0;
763 par->szplcy_set=0;
764 par->geom_set=0;
765 par->bottom=0;
767 if(sub){
768 ExtlTab s;
769 if(extl_table_gets_t(tab, sub, &s)){
770 groupattachparams_get(par, s, NULL);
771 extl_unref_table(s);
773 return;
776 if(extl_table_is_bool_set(tab, "bottom")){
777 par->level=STACKING_LEVEL_BOTTOM;
778 par->level_set=1;
779 par->bottom=1;
782 if(extl_table_gets_i(tab, "level", &tmp)){
783 if(tmp>=0){
784 par->level_set=1;
785 par->level=tmp;
789 if(!par->level_set && extl_table_is_bool_set(tab, "modal")){
790 par->level=STACKING_LEVEL_MODAL1;
791 par->level_set=1;
794 if(extl_table_gets_b(tab, "switchto", &tmpb)){
795 par->switchto=(tmpb!=0);
796 par->switchto_set=1;
799 if(extl_table_gets_i(tab, "sizepolicy", &tmp)){
800 par->szplcy_set=1;
801 par->szplcy=tmp;
802 }else if(extl_table_gets_s(tab, "sizepolicy", &tmps)){
803 if(string2sizepolicy(tmps, &par->szplcy))
804 par->szplcy_set=1;
805 free(tmps);
808 if(extl_table_gets_t(tab, "geom", &g)){
809 int n=0;
811 if(extl_table_gets_i(g, "x", &(par->geom.x)))
812 n++;
813 if(extl_table_gets_i(g, "y", &(par->geom.y)))
814 n++;
815 if(extl_table_gets_i(g, "w", &(par->geom.w)))
816 n++;
817 if(extl_table_gets_i(g, "h", &(par->geom.h)))
818 n++;
820 if(n==4)
821 par->geom_set=1;
823 extl_unref_table(g);
826 if(extl_table_gets_b(tab, "auto_placement", &tmpb)){
827 par->geom_weak_set=1;
828 par->geom_weak=(tmpb ? REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y : 0);
834 /*EXTL_DOC
835 * Attach and reparent existing region \var{reg} to \var{ws}.
836 * The table \var{param} may contain the fields \var{index} and
837 * \var{switchto} that are interpreted as for \fnref{WMPlex.attach_new}.
839 EXTL_EXPORT_MEMBER
840 WRegion *group_attach(WGroup *ws, WRegion *reg, ExtlTab param)
842 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
843 WRegionAttachData data;
845 if(reg==NULL)
846 return NULL;
848 groupattachparams_get(&par, param, NULL);
850 data.type=REGION_ATTACH_REPARENT;
851 data.u.reg=reg;
853 return group_do_attach(ws, &par, &data);
857 /*EXTL_DOC
858 * Create a new region to be managed by \var{ws}. At least the following
859 * fields in \var{param} are understood:
861 * \begin{tabularx}{\linewidth}{lX}
862 * \tabhead{Field & Description}
863 * \var{type} & (string) Class of the object to be created. Mandatory. \\
864 * \var{name} & (string) Name of the object to be created. \\
865 * \var{switchto} & (boolean) Should the region be switched to? \\
866 * \var{level} & (integer) Stacking level; default is 1. \\
867 * \var{modal} & (boolean) Make object modal; ignored if level is set. \\
868 * \var{sizepolicy} & (string) Size policy; see Section \ref{sec:sizepolicies}. \\
869 * \var{bottom} & (boolean) Mark the attached region as the
870 * ``bottom'' of \var{ws}. \\
871 * \end{tabularx}
873 * In addition parameters to the region to be created are passed in this
874 * same table.
876 EXTL_EXPORT_MEMBER
877 WRegion *group_attach_new(WGroup *ws, ExtlTab param)
879 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
880 WRegionAttachData data;
882 groupattachparams_get(&par, param, NULL);
884 data.type=REGION_ATTACH_LOAD;
885 data.u.tab=param;
887 return group_do_attach(ws, &par, &data);
891 /*}}}*/
894 /*{{{ Status display support */
897 static int stdisp_szplcy(const WMPlexSTDispInfo *di, WRegion *stdisp)
899 int pos=di->pos;
900 int policy=0, gravity=0;
902 if(di->fullsize){
903 if(region_orientation(stdisp)==REGION_ORIENTATION_VERTICAL){
904 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_BL)
905 policy=SIZEPOLICY_STRETCH_LEFT;
906 else
907 policy=SIZEPOLICY_STRETCH_RIGHT;
908 }else{
909 if(pos==MPLEX_STDISP_TL || pos==MPLEX_STDISP_TR)
910 policy=SIZEPOLICY_STRETCH_TOP;
911 else
912 policy=SIZEPOLICY_STRETCH_BOTTOM;
914 }else{
915 policy=SIZEPOLICY_GRAVITY;
918 if(pos==MPLEX_STDISP_TL)
919 gravity=SIZEPOLICY_VERT_TOP|SIZEPOLICY_HORIZ_LEFT;
920 else if(pos==MPLEX_STDISP_BL)
921 gravity=SIZEPOLICY_VERT_BOTTOM|SIZEPOLICY_HORIZ_LEFT;
922 else if(pos==MPLEX_STDISP_TR)
923 gravity=SIZEPOLICY_VERT_TOP|SIZEPOLICY_HORIZ_RIGHT;
924 else /*if(pos=MPLEX_STDISP_BR)*/
925 gravity=SIZEPOLICY_VERT_BOTTOM|SIZEPOLICY_HORIZ_RIGHT;
927 return (policy|gravity);
931 void group_manage_stdisp(WGroup *ws, WRegion *stdisp,
932 const WMPlexSTDispInfo *di)
934 WFitParams fp;
935 uint szplcy;
936 WRegion *b=(ws->bottom==NULL ? NULL : ws->bottom->reg);
938 /* Check if 'bottom' wants to manage the stdisp. */
939 if(b!=NULL
940 && !OBJ_IS_BEING_DESTROYED(b)
941 && HAS_DYN(b, region_manage_stdisp)){
942 region_manage_stdisp(b, stdisp, di);
943 if(REGION_MANAGER(stdisp)==b)
944 return;
947 /* No. */
949 szplcy=stdisp_szplcy(di, stdisp)|SIZEPOLICY_SHRUNK;
951 if(ws->managed_stdisp!=NULL && ws->managed_stdisp->reg==stdisp){
952 if(ws->managed_stdisp->szplcy==szplcy)
953 return;
954 ws->managed_stdisp->szplcy=szplcy;
955 }else{
956 region_detach_manager(stdisp);
957 ws->managed_stdisp=group_do_add_managed(ws, stdisp,
958 STACKING_LEVEL_ON_TOP,
959 szplcy);
962 stdisp->flags|=REGION_SKIP_FOCUS;
964 fp.g=REGION_GEOM(ws);
965 fp.mode=0;
967 sizepolicy(&ws->managed_stdisp->szplcy, stdisp, NULL, 0, &fp);
969 region_fitrep(stdisp, NULL, &fp);
973 static void group_remanage_stdisp(WGroup *ws)
975 WMPlex *mplex=OBJ_CAST(REGION_MANAGER(ws), WMPlex);
977 if(mplex!=NULL &&
978 mplex->mx_current!=NULL &&
979 mplex->mx_current->st->reg==(WRegion*)ws){
980 mplex_remanage_stdisp(mplex);
985 /*}}}*/
988 /*{{{ Geometry requests */
991 void group_managed_rqgeom(WGroup *ws, WRegion *reg,
992 const WRQGeomParams *rq,
993 WRectangle *geomret)
995 WFitParams fp;
996 WStacking *st;
998 st=group_find_stacking(ws, reg);
1000 if(st==NULL){
1001 fp.g=rq->geom;
1002 fp.mode=REGION_FIT_EXACT;
1003 }else{
1004 fp.g=REGION_GEOM(ws);
1005 fp.mode=0;
1006 sizepolicy(&st->szplcy, reg, &rq->geom, rq->flags, &fp);
1009 if(geomret!=NULL)
1010 *geomret=fp.g;
1012 if(!(rq->flags&REGION_RQGEOM_TRYONLY))
1013 region_fitrep(reg, NULL, &fp);
1017 void group_managed_rqgeom_absolute(WGroup *grp, WRegion *sub,
1018 const WRQGeomParams *rq,
1019 WRectangle *geomret)
1021 if(grp->bottom!=NULL && grp->bottom->reg==sub){
1022 region_rqgeom((WRegion*)grp, rq, geomret);
1023 if(!(rq->flags&REGION_RQGEOM_TRYONLY) && geomret!=NULL)
1024 *geomret=REGION_GEOM(sub);
1025 }else{
1026 WRQGeomParams rq2=*rq;
1027 rq2.flags&=~REGION_RQGEOM_ABSOLUTE;
1029 region_managed_rqgeom((WRegion*)grp, sub, &rq2, geomret);
1034 /*}}}*/
1037 /*{{{ Navigation */
1040 static WStacking *nxt(WGroup *ws, WStacking *st, bool wrap)
1042 return (st->mgr_next!=NULL
1043 ? st->mgr_next
1044 : (wrap ? ws->managed_list : NULL));
1048 static WStacking *prv(WGroup *ws, WStacking *st, bool wrap)
1050 return (st!=ws->managed_list
1051 ? st->mgr_prev
1052 : (wrap ? st->mgr_prev : NULL));
1056 typedef WStacking *NxtFn(WGroup *ws, WStacking *st, bool wrap);
1059 static bool focusable(WGroup *ws, WStacking *st, uint min_level)
1061 return (st->reg!=NULL
1062 && REGION_IS_MAPPED(st->reg)
1063 && !(st->reg->flags&REGION_SKIP_FOCUS)
1064 && st->level>=min_level);
1068 static WStacking *do_get_next(WGroup *ws, WStacking *sti,
1069 NxtFn *fn, bool wrap, bool sti_ok)
1071 WStacking *st, *stacking;
1072 uint min_level=0;
1074 stacking=group_get_stacking(ws);
1076 if(stacking!=NULL)
1077 min_level=stacking_min_level_mapped(stacking);
1079 st=sti;
1080 while(1){
1081 st=fn(ws, st, wrap);
1083 if(st==NULL || st==sti)
1084 break;
1086 if(focusable(ws, st, min_level))
1087 return st;
1090 if(sti_ok && focusable(ws, sti, min_level))
1091 return sti;
1093 return NULL;
1097 static WStacking *group_do_navi_first(WGroup *ws, WRegionNavi nh)
1099 WStacking *lst=ws->managed_list;
1101 if(lst==NULL)
1102 return NULL;
1104 if(nh==REGION_NAVI_ANY &&
1105 ws->current_managed!=NULL &&
1106 ws->current_managed->reg!=NULL){
1107 return ws->current_managed;
1110 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1111 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1112 return do_get_next(ws, lst, prv, TRUE, TRUE);
1113 }else{
1114 return do_get_next(ws, lst->mgr_prev, nxt, TRUE, TRUE);
1119 static WRegion *group_navi_first(WGroup *ws, WRegionNavi nh,
1120 WRegionNaviData *data)
1122 WStacking *st=group_do_navi_first(ws, nh);
1124 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1128 static WStacking *group_do_navi_next(WGroup *ws, WStacking *st,
1129 WRegionNavi nh, bool wrap)
1131 if(st==NULL)
1132 return group_do_navi_first(ws, nh);
1134 if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
1135 nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){
1136 return do_get_next(ws, st, nxt, wrap, FALSE);
1137 }else{
1138 return do_get_next(ws, st, prv, wrap, FALSE);
1142 static WRegion *group_navi_next(WGroup *ws, WRegion *reg,
1143 WRegionNavi nh, WRegionNaviData *data)
1145 WStacking *st=group_find_stacking(ws, reg);
1147 st=group_do_navi_next(ws, st, nh, FALSE);
1149 return region_navi_cont(&ws->reg, (st!=NULL ? st->reg : NULL), data);
1153 /*}}}*/
1156 /*{{{ Stacking */
1160 * Note: Managed objects are considered to be stacked separately from the
1161 * group, slightly violating expectations.
1164 void group_stacking(WGroup *ws, Window *bottomret, Window *topret)
1166 Window win=region_xwindow((WRegion*)ws);
1168 *bottomret=win;
1169 *topret=win;
1173 void group_restack(WGroup *ws, Window other, int mode)
1175 Window win;
1177 win=region_xwindow((WRegion*)ws);
1178 if(win!=None){
1179 xwindow_restack(win, other, mode);
1180 other=win;
1181 mode=Above;
1186 WStacking *group_find_stacking(WGroup *ws, WRegion *r)
1188 if(r==NULL || REGION_MANAGER(r)!=(WRegion*)ws)
1189 return NULL;
1191 return ioncore_find_stacking(r);
1195 static WStacking *find_stacking_if_not_on_ws(WGroup *ws, Window w)
1197 WRegion *r=xwindow_region_of(w);
1198 WStacking *st=NULL;
1200 while(r!=NULL){
1201 if(REGION_MANAGER(r)==(WRegion*)ws)
1202 break;
1203 st=group_find_stacking(ws, r);
1204 if(st!=NULL)
1205 break;
1206 r=REGION_MANAGER(r);
1209 return st;
1213 bool group_managed_rqorder(WGroup *grp, WRegion *reg, WRegionOrder order)
1215 WStacking **stackingp=group_get_stackingp(grp);
1216 WStacking *st;
1218 if(stackingp==NULL || *stackingp==NULL)
1219 return FALSE;
1221 st=group_find_stacking(grp, reg);
1223 if(st==NULL)
1224 return FALSE;
1226 stacking_restack(stackingp, st, None, NULL, NULL,
1227 (order!=REGION_ORDER_FRONT));
1229 return TRUE;
1233 /*}}}*/
1236 /*{{{ Misc. */
1239 /*EXTL_DOC
1240 * Iterate over managed regions of \var{ws} until \var{iterfn} returns
1241 * \code{false}.
1242 * The function is called in protected mode.
1243 * This routine returns \code{true} if it reaches the end of list
1244 * without this happening.
1246 EXTL_SAFE
1247 EXTL_EXPORT_MEMBER
1248 bool group_managed_i(WGroup *ws, ExtlFn iterfn)
1250 WGroupIterTmp tmp;
1251 group_iter_init(&tmp, ws);
1253 return extl_iter_objlist_(iterfn, (ObjIterator*)group_iter, &tmp);
1257 WRegion* group_current(WGroup *ws)
1259 return (ws->current_managed!=NULL ? ws->current_managed->reg : NULL);
1263 void group_size_hints(WGroup *ws, WSizeHints *hints_ret)
1265 if(ws->bottom==NULL || ws->bottom->reg==NULL){
1266 sizehints_clear(hints_ret);
1267 }else{
1268 region_size_hints(ws->bottom->reg, hints_ret);
1269 hints_ret->no_constrain=TRUE;
1274 Window group_xwindow(const WGroup *ws)
1276 return ws->dummywin;
1280 /*EXTL_DOC
1281 * Returns the group of \var{reg}, if it is managed by one,
1282 * and \var{reg} itself otherwise.
1284 /*EXTL_EXPORT_MEMBER
1285 WRegion *region_group_of(WRegion *reg)
1287 WRegion *mgr=REGION_MANAGER(reg);
1289 return (OBJ_IS(mgr, WGroup) ? mgr : reg);
1293 /*EXTL_DOC
1294 * Returns the group of \var{reg}, if \var{reg} is its bottom,
1295 * and \var{reg} itself otherwise.
1297 EXTL_EXPORT_MEMBER
1298 WRegion *region_groupleader_of(WRegion *reg)
1300 WGroup *grp=REGION_MANAGER_CHK(reg, WGroup);
1302 return ((grp!=NULL && group_bottom(grp)==reg)
1303 ? (WRegion*)grp
1304 : reg);
1308 /*}}}*/
1311 /*{{{ Save/load */
1314 static ExtlTab group_get_configuration(WGroup *ws)
1316 ExtlTab tab, mgds, subtab, g;
1317 WStacking *st;
1318 WGroupIterTmp tmp;
1319 WMPlex *par;
1320 int n=0;
1321 WRectangle tmpg;
1323 tab=region_get_base_configuration((WRegion*)ws);
1325 mgds=extl_create_table();
1327 extl_table_sets_t(tab, "managed", mgds);
1329 /* TODO: stacking order messed up */
1331 FOR_ALL_NODES_IN_GROUP(ws, st, tmp){
1332 if(st->reg==NULL)
1333 continue;
1335 subtab=region_get_configuration(st->reg);
1337 if(subtab!=extl_table_none()){
1338 extl_table_sets_s(subtab, "sizepolicy",
1339 sizepolicy2string(st->szplcy));
1340 extl_table_sets_i(subtab, "level", st->level);
1342 tmpg=REGION_GEOM(st->reg);
1343 tmpg.x-=REGION_GEOM(ws).x;
1344 tmpg.y-=REGION_GEOM(ws).y;
1346 g=extl_table_from_rectangle(&tmpg);
1347 extl_table_sets_t(subtab, "geom", g);
1348 extl_unref_table(g);
1350 if(ws->bottom==st)
1351 extl_table_sets_b(subtab, "bottom", TRUE);
1353 extl_table_seti_t(mgds, ++n, subtab);
1354 extl_unref_table(subtab);
1358 extl_unref_table(mgds);
1360 return tab;
1364 void group_do_load(WGroup *ws, ExtlTab tab)
1366 ExtlTab substab, subtab;
1367 int i, n;
1369 if(extl_table_gets_t(tab, "managed", &substab)){
1370 n=extl_table_get_n(substab);
1371 for(i=1; i<=n; i++){
1372 if(extl_table_geti_t(substab, i, &subtab)){
1373 WGroupAttachParams par=GROUPATTACHPARAMS_INIT;
1374 WRegionAttachData data;
1375 WFitParams fp;
1376 WPHolder *ph;
1378 groupattachparams_get(&par, subtab, NULL);
1379 group_attach_fp(ws, &par, &fp);
1381 ph=(WPHolder*)create_grouppholder(ws, NULL, &par);
1383 region_attach_load_helper((WRegion*)ws, REGION_PARENT(ws), &fp,
1384 (WRegionDoAttachFn*)group_do_attach_final,
1385 (void*)&par, subtab, &ph);
1387 if(ph!=NULL)
1388 destroy_obj((Obj*)ph);
1390 extl_unref_table(subtab);
1394 extl_unref_table(substab);
1399 WRegion *group_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
1401 WGroup *ws;
1403 ws=create_group(par, fp);
1405 if(ws==NULL)
1406 return NULL;
1408 group_do_load(ws, tab);
1410 return (WRegion*)ws;
1414 /*}}}*/
1417 /*{{{ Dynamic function table and class implementation */
1420 static DynFunTab group_dynfuntab[]={
1421 {(DynFun*)region_fitrep,
1422 (DynFun*)group_fitrep},
1424 {region_map,
1425 group_map},
1427 {region_unmap,
1428 group_unmap},
1430 {(DynFun*)region_managed_prepare_focus,
1431 (DynFun*)group_managed_prepare_focus},
1433 {region_do_set_focus,
1434 group_do_set_focus},
1436 {region_managed_notify,
1437 group_managed_notify},
1439 {region_managed_remove,
1440 group_managed_remove},
1442 {(DynFun*)region_get_configuration,
1443 (DynFun*)group_get_configuration},
1445 {(DynFun*)region_current,
1446 (DynFun*)group_current},
1448 {(DynFun*)region_rescue_clientwins,
1449 (DynFun*)group_rescue_clientwins},
1451 {region_restack,
1452 group_restack},
1454 {region_stacking,
1455 group_stacking},
1457 {(DynFun*)region_managed_get_pholder,
1458 (DynFun*)group_managed_get_pholder},
1460 {region_managed_rqgeom,
1461 group_managed_rqgeom},
1463 {region_managed_rqgeom_absolute,
1464 group_managed_rqgeom_absolute},
1466 {(DynFun*)group_do_add_managed,
1467 (DynFun*)group_do_add_managed_default},
1469 {region_size_hints,
1470 group_size_hints},
1472 {(DynFun*)region_xwindow,
1473 (DynFun*)group_xwindow},
1475 {(DynFun*)region_navi_first,
1476 (DynFun*)group_navi_first},
1478 {(DynFun*)region_navi_next,
1479 (DynFun*)group_navi_next},
1481 {(DynFun*)region_managed_rqorder,
1482 (DynFun*)group_managed_rqorder},
1484 {(DynFun*)region_get_rescue_pholder_for,
1485 (DynFun*)group_get_rescue_pholder_for},
1487 END_DYNFUNTAB
1491 EXTL_EXPORT
1492 IMPLCLASS(WGroup, WRegion, group_deinit, group_dynfuntab);
1495 /*}}}*/