2 * ion/mod_tiling/tiling.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
14 #include <libtu/objp.h>
15 #include <libtu/minmax.h>
16 #include <libtu/ptrlist.h>
17 #include <libmainloop/defer.h>
18 #include <libmainloop/signal.h>
20 #include <ioncore/common.h>
21 #include <ioncore/rootwin.h>
22 #include <ioncore/focus.h>
23 #include <ioncore/global.h>
24 #include <ioncore/region.h>
25 #include <ioncore/manage.h>
26 #include <ioncore/screen.h>
27 #include <ioncore/names.h>
28 #include <ioncore/saveload.h>
29 #include <ioncore/attach.h>
30 #include <ioncore/resize.h>
31 #include <libextl/extl.h>
32 #include <ioncore/regbind.h>
33 #include <ioncore/extlconv.h>
34 #include <ioncore/xwindow.h>
35 #include <ioncore/navi.h>
36 #include "placement.h"
39 #include "splitfloat.h"
40 #include "split-stdisp.h"
45 static WTilingIterTmp tiling_iter_default_tmp;
48 /*{{{ Some helper routines */
51 static WSplitRegion *get_node_check(WTiling *ws, WRegion *reg)
58 node=splittree_node_of(reg);
60 if(node==NULL || REGION_MANAGER(reg)!=(WRegion*)ws)
67 static bool check_node(WTiling *ws, WSplit *split)
70 return check_node(ws, (WSplit*)split->parent);
72 if((split->ws_if_root!=(void*)ws)){
73 warn(TR("Split not on workspace."));
83 /*{{{ Dynfun implementations */
86 static void reparent_mgd(WRegion *sub, WWindow *par)
89 subfp.g=REGION_GEOM(sub);
90 subfp.mode=REGION_FIT_EXACT;
91 if(!region_fitrep(sub, par, &subfp)){
92 warn(TR("Error reparenting %s."), region_name(sub));
93 region_detach_manager(sub);
98 bool tiling_fitrep(WTiling *ws, WWindow *par, const WFitParams *fp)
104 if(!region_same_rootwin((WRegion*)ws, (WRegion*)par))
107 region_unset_parent((WRegion*)ws);
109 XReparentWindow(ioncore_g.dpy, ws->dummywin,
110 par->win, fp->g.x, fp->g.y);
112 region_set_parent((WRegion*)ws, par);
114 if(ws->split_tree!=NULL)
115 split_reparent(ws->split_tree, par);
118 REGION_GEOM(ws)=fp->g;
120 if(ws->split_tree!=NULL){
122 if(fp->mode®ION_FIT_ROTATE)
123 ok=split_rotate_to(ws->split_tree, &(fp->g), fp->rotation);
125 split_resize(ws->split_tree, &(fp->g), PRIMN_ANY, PRIMN_ANY);
132 void tiling_managed_rqgeom(WTiling *ws, WRegion *mgd,
133 const WRQGeomParams *rq,
136 WSplitRegion *node=get_node_check(ws, mgd);
137 if(node!=NULL && ws->split_tree!=NULL)
138 splittree_rqgeom((WSplit*)node, rq->flags, &rq->geom, geomret);
142 void tiling_map(WTiling *ws)
144 REGION_MARK_MAPPED(ws);
145 XMapWindow(ioncore_g.dpy, ws->dummywin);
147 if(ws->split_tree!=NULL)
148 split_map(ws->split_tree);
152 void tiling_unmap(WTiling *ws)
154 REGION_MARK_UNMAPPED(ws);
155 XUnmapWindow(ioncore_g.dpy, ws->dummywin);
157 if(ws->split_tree!=NULL)
158 split_unmap(ws->split_tree);
162 void tiling_fallback_focus(WTiling *ws, bool warp)
164 region_finalise_focusing((WRegion*)ws, ws->dummywin, warp);
168 void tiling_do_set_focus(WTiling *ws, bool warp)
170 WRegion *sub=tiling_current(ws);
173 tiling_fallback_focus(ws, warp);
177 region_do_set_focus(sub, warp);
181 static WTimer *restack_timer=NULL;
184 static void restack_handler(WTimer *tmr, Obj *obj)
187 WTiling *ws=(WTiling*)obj;
188 split_restack(ws->split_tree, ws->dummywin, Above);
193 bool tiling_managed_prepare_focus(WTiling *ws, WRegion *reg,
194 int flags, WPrepareFocusResult *res)
198 if(!region_prepare_focus((WRegion*)ws, flags, res))
201 node=get_node_check(ws, reg);
203 if(node!=NULL && node->split.parent!=NULL)
204 splitinner_mark_current(node->split.parent, &(node->split));
206 /* WSplitSplit uses activity based stacking as required on WAutoWS,
207 * so we must restack here.
209 if(ws->split_tree!=NULL){
210 int rd=mod_tiling_raise_delay;
211 bool use_timer=rd>0 && flags®ION_GOTO_ENTERWINDOW;
214 if(restack_timer!=NULL){
215 Obj *obj=restack_timer->objwatch.obj;
217 timer_reset(restack_timer);
218 restack_handler(restack_timer, obj);
221 restack_timer=create_timer();
225 if(use_timer && restack_timer!=NULL){
226 timer_set(restack_timer, rd, restack_handler, (Obj*)ws);
228 split_restack(ws->split_tree, ws->dummywin, Above);
239 void tiling_restack(WTiling *ws, Window other, int mode)
241 xwindow_restack(ws->dummywin, other, mode);
242 if(ws->split_tree!=NULL)
243 split_restack(ws->split_tree, ws->dummywin, Above);
247 void tiling_stacking(WTiling *ws, Window *bottomret, Window *topret)
249 Window sbottom=None, stop=None;
251 if(ws->split_tree!=None)
252 split_stacking(ws->split_tree, &sbottom, &stop);
254 *bottomret=ws->dummywin;
255 *topret=(stop!=None ? stop : ws->dummywin);
259 Window tiling_xwindow(const WTiling *ws)
265 WPHolder *tiling_prepare_manage_transient(WTiling *ws,
266 const WClientWin *transient,
267 const WManageParams *param,
270 /* Transient manager searches should not cross tilings unless
271 * explicitly floated.
273 if(extl_table_is_bool_set(transient->proptab, "float")){
274 return region_prepare_manage_transient_default((WRegion*)ws,
287 /*{{{ Status display support code */
290 static bool regnodefilter(WSplit *split)
292 return OBJ_IS(split, WSplitRegion);
296 void tiling_unmanage_stdisp(WTiling *ws, bool permanent, bool nofocus)
298 WSplitRegion *tofocus=NULL;
302 if(ws->stdispnode==NULL)
305 od=ws->stdispnode->regnode.reg;
308 if(!nofocus && REGION_IS_ACTIVE(od) &&
309 region_may_control_focus((WRegion*)ws)){
311 tofocus=(WSplitRegion*)split_nextto((WSplit*)(ws->stdispnode),
312 PRIMN_ANY, PRIMN_ANY,
315 /* Reset node_of info here so tiling_managed_remove will not
318 splittree_set_node_of(od, NULL);
319 tiling_do_managed_remove(ws, od);
323 WSplit *node=(WSplit*)ws->stdispnode;
325 splittree_remove(node, TRUE);
330 region_set_focus(tofocus->reg);
332 tiling_fallback_focus(ws, FALSE);
337 static void tiling_create_stdispnode(WTiling *ws, WRegion *stdisp,
338 int corner, int orientation,
341 int flags=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
342 WRectangle *wg=®ION_GEOM(ws), dg;
343 WSplitST *stdispnode;
346 assert(ws->split_tree!=NULL);
348 if(orientation==REGION_ORIENTATION_HORIZONTAL){
352 dg.y=((corner==MPLEX_STDISP_BL || corner==MPLEX_STDISP_BR)
359 dg.x=((corner==MPLEX_STDISP_TR || corner==MPLEX_STDISP_BR)
364 stdispnode=create_splitst(&dg, stdisp);
366 if(stdispnode==NULL){
367 warn(TR("Unable to create a node for status display."));
371 stdispnode->corner=corner;
372 stdispnode->orientation=orientation;
373 stdispnode->fullsize=fullsize;
375 split=create_splitsplit(wg, (orientation==REGION_ORIENTATION_HORIZONTAL
377 : SPLIT_HORIZONTAL));
380 warn(TR("Unable to create new split for status display."));
381 stdispnode->regnode.reg=NULL;
382 destroy_obj((Obj*)stdispnode);
386 /* Set up new split tree */
387 ((WSplit*)stdispnode)->parent=(WSplitInner*)split;
388 ws->split_tree->parent=(WSplitInner*)split;
389 ws->split_tree->ws_if_root=NULL;
391 if((orientation==REGION_ORIENTATION_HORIZONTAL &&
392 (corner==MPLEX_STDISP_BL || corner==MPLEX_STDISP_BR)) ||
393 (orientation==REGION_ORIENTATION_VERTICAL &&
394 (corner==MPLEX_STDISP_TR || corner==MPLEX_STDISP_BR))){
395 split->tl=ws->split_tree;
396 split->br=(WSplit*)stdispnode;
397 split->current=SPLIT_CURRENT_TL;
399 split->tl=(WSplit*)stdispnode;
400 split->br=ws->split_tree;
401 split->current=SPLIT_CURRENT_BR;
404 ws->split_tree=(WSplit*)split;
405 ((WSplit*)split)->ws_if_root=ws;
406 ws->stdispnode=stdispnode;
410 void tiling_manage_stdisp(WTiling *ws, WRegion *stdisp,
411 const WMPlexSTDispInfo *di)
413 bool mcf=region_may_control_focus((WRegion*)ws);
414 int flags=REGION_RQGEOM_WEAK_X|REGION_RQGEOM_WEAK_Y;
415 int orientation=region_orientation(stdisp);
417 WRectangle dg, *stdg;
419 if(orientation!=REGION_ORIENTATION_VERTICAL /*&&
420 orientation!=REGION_ORIENTATION_HORIZONTAL*/){
421 orientation=REGION_ORIENTATION_HORIZONTAL;
424 if(ws->stdispnode==NULL || ws->stdispnode->regnode.reg!=stdisp)
425 region_detach_manager(stdisp);
427 /* Remove old stdisp if corner and orientation don't match.
429 if(ws->stdispnode!=NULL && (di->pos!=ws->stdispnode->corner ||
430 orientation!=ws->stdispnode->orientation)){
431 tiling_unmanage_stdisp(ws, TRUE, TRUE);
434 if(ws->stdispnode==NULL){
435 tiling_create_stdispnode(ws, stdisp, di->pos, orientation,
437 if(ws->stdispnode==NULL)
440 WRegion *od=ws->stdispnode->regnode.reg;
442 act=REGION_IS_ACTIVE(od);
443 splittree_set_node_of(od, NULL);
444 tiling_managed_remove(ws, od);
445 assert(ws->stdispnode->regnode.reg==NULL);
448 ws->stdispnode->fullsize=di->fullsize;
449 ws->stdispnode->regnode.reg=stdisp;
450 splittree_set_node_of(stdisp, &(ws->stdispnode->regnode));
453 if(!tiling_managed_add(ws, stdisp)){
454 tiling_unmanage_stdisp(ws, TRUE, TRUE);
458 dg=((WSplit*)(ws->stdispnode))->geom;
460 dg.h=stdisp_recommended_h(ws->stdispnode);
461 dg.w=stdisp_recommended_w(ws->stdispnode);
463 splittree_rqgeom((WSplit*)(ws->stdispnode), flags, &dg, FALSE);
465 stdg=&(((WSplit*)ws->stdispnode)->geom);
467 if(stdisp->geom.x!=stdg->x || stdisp->geom.y!=stdg->y ||
468 stdisp->geom.w!=stdg->w || stdisp->geom.h!=stdg->h){
469 region_fit(stdisp, stdg, REGION_FIT_EXACT);
472 /* Restack to ensure the split tree is stacked in the expected order. */
473 if(ws->split_tree!=NULL)
474 split_restack(ws->split_tree, ws->dummywin, Above);
477 region_set_focus(stdisp);
484 /*{{{ Create/destroy */
487 bool tiling_managed_add_default(WTiling *ws, WRegion *reg)
489 Window bottom=None, top=None;
492 if(TILING_STDISP_OF(ws)!=reg){
493 if(!ptrlist_insert_last(&(ws->managed_list), reg))
497 region_set_manager(reg, (WRegion*)ws);
499 frame=OBJ_CAST(reg, WFrame);
501 WFrameMode mode=frame_mode(frame);
502 if(mode!=FRAME_MODE_TILED && mode!=FRAME_MODE_TILED_ALT)
503 frame_set_mode(frame, FRAME_MODE_TILED);
506 if(REGION_IS_MAPPED(ws))
509 if(region_may_control_focus((WRegion*)ws)){
510 WRegion *curr=tiling_current(ws);
511 if(curr==NULL || !REGION_IS_ACTIVE(curr))
519 bool tiling_managed_add(WTiling *ws, WRegion *reg)
522 CALL_DYN_RET(ret, bool, tiling_managed_add, ws, (ws, reg));
527 bool tiling_do_attach_initial(WTiling *ws, WRegion *reg)
529 assert(ws->split_tree==NULL);
531 ws->split_tree=(WSplit*)create_splitregion(®ION_GEOM(reg), reg);
532 if(ws->split_tree==NULL)
535 ws->split_tree->ws_if_root=ws;
537 if(!tiling_managed_add(ws, reg)){
538 destroy_obj((Obj*)ws->split_tree);
547 static WRegion *create_frame_tiling(WWindow *parent, const WFitParams *fp)
549 return (WRegion*)create_frame(parent, fp, FRAME_MODE_TILED);
553 bool tiling_init(WTiling *ws, WWindow *parent, const WFitParams *fp,
554 WRegionSimpleCreateFn *create_frame_fn, bool ci)
557 ws->create_frame_fn=(create_frame_fn
559 : create_frame_tiling);
561 ws->managed_list=NULL;
564 ws->dummywin=XCreateWindow(ioncore_g.dpy, parent->win,
565 fp->g.x, fp->g.y, 1, 1, 0,
566 CopyFromParent, InputOnly,
567 CopyFromParent, 0, NULL);
568 if(ws->dummywin==None)
571 region_init(&(ws->reg), parent, fp);
573 ws->reg.flags|=(REGION_GRAB_ON_PARENT|
577 WRegionAttachData data;
580 data.type=REGION_ATTACH_NEW;
581 data.u.n.fn=(WRegionCreateFn*)ws->create_frame_fn;
584 res=region_attach_helper((WRegion*)ws, parent, fp,
585 (WRegionDoAttachFn*)tiling_do_attach_initial,
589 XDestroyWindow(ioncore_g.dpy, ws->dummywin);
594 XSelectInput(ioncore_g.dpy, ws->dummywin,
595 FocusChangeMask|KeyPressMask|KeyReleaseMask|
596 ButtonPressMask|ButtonReleaseMask);
597 XSaveContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context,
600 region_register(&(ws->reg));
601 region_add_bindmap((WRegion*)ws, mod_tiling_tiling_bindmap);
607 WTiling *create_tiling(WWindow *parent, const WFitParams *fp,
608 WRegionSimpleCreateFn *create_frame_fn, bool ci)
610 CREATEOBJ_IMPL(WTiling, tiling, (p, parent, fp, create_frame_fn, ci));
614 WTiling *create_tiling_simple(WWindow *parent, const WFitParams *fp)
616 return create_tiling(parent, fp, NULL, TRUE);
620 void tiling_deinit(WTiling *ws)
624 WMPlex *remanage_mplex=NULL;
626 tiling_unmanage_stdisp(ws, FALSE, TRUE);
628 FOR_ALL_MANAGED_BY_TILING(reg, ws, tmp){
629 destroy_obj((Obj*)reg);
632 FOR_ALL_MANAGED_BY_TILING(reg, ws, tmp){
636 if(ws->split_tree!=NULL)
637 destroy_obj((Obj*)(ws->split_tree));
639 XDeleteContext(ioncore_g.dpy, ws->dummywin, ioncore_g.win_context);
640 XDestroyWindow(ioncore_g.dpy, ws->dummywin);
643 region_deinit(&(ws->reg));
647 WRegion *tiling_managed_disposeroot(WTiling *ws, WRegion *reg)
655 FOR_ALL_MANAGED_BY_TILING(mgd, ws, tmp){
656 if(mgd!=TILING_STDISP_OF(ws) && mgd!=reg)
660 return region_disposeroot((WRegion*)ws);
664 bool tiling_rescue_clientwins(WTiling *ws, WRescueInfo *info)
668 ptrlist_iter_init(&tmp, ws->managed_list);
670 return region_rescue_some_clientwins((WRegion*)ws, info,
671 (WRegionIterator*)ptrlist_iter,
676 void tiling_do_managed_remove(WTiling *ws, WRegion *reg)
678 if(TILING_STDISP_OF(ws)==reg){
679 ws->stdispnode->regnode.reg=NULL;
681 ptrlist_remove(&(ws->managed_list), reg);
684 region_unset_manager(reg, (WRegion*)ws);
688 static bool nostdispfilter(WSplit *node)
690 return (OBJ_IS(node, WSplitRegion) && !OBJ_IS(node, WSplitST));
694 void tiling_managed_remove(WTiling *ws, WRegion *reg)
696 bool act=REGION_IS_ACTIVE(reg);
697 bool mcf=region_may_control_focus((WRegion*)ws);
698 WSplitRegion *node=get_node_check(ws, reg);
699 bool norestore=(OBJ_IS_BEING_DESTROYED(ws) || ws->batchop);
703 other=tiling_do_navi_next(ws, reg, REGION_NAVI_ANY, TRUE, FALSE);
705 tiling_do_managed_remove(ws, reg);
707 if(node==(WSplitRegion*)(ws->stdispnode))
713 if(other==NULL && !norestore){
714 WWindow *par=REGION_PARENT(ws);
719 fp.g=node->split.geom;
720 fp.mode=REGION_FIT_EXACT;
722 other=(ws->create_frame_fn)(par, &fp);
726 tiling_managed_add(ws, other);
729 warn(TR("Tiling in useless state."));
734 splittree_remove((WSplit*)node, (!norestore && other!=NULL));
737 if(!norestore && other!=NULL && act && mcf)
742 static bool mplexfilter(WSplit *node)
744 WSplitRegion *regnode=OBJ_CAST(node, WSplitRegion);
746 return (regnode!=NULL && regnode->reg!=NULL &&
747 OBJ_IS(regnode->reg, WMPlex));
751 static WPHolder *find_ph_result=NULL;
752 static WRegion *find_ph_param=NULL;
755 static bool find_ph(WSplit *split)
757 WSplitRegion *sr=OBJ_CAST(split, WSplitRegion);
759 assert(find_ph_result==NULL);
761 if(sr==NULL || sr->reg==NULL)
764 find_ph_result=region_get_rescue_pholder_for(sr->reg, find_ph_param);
766 return (find_ph_result!=NULL);
770 WPHolder *tiling_get_rescue_pholder_for(WTiling *ws, WRegion *mgd)
772 WSplit *node=(WSplit*)get_node_check(ws, mgd);
779 if(ws->split_tree!=NULL){
780 split_current_todir(ws->split_tree, PRIMN_ANY, PRIMN_ANY,
785 split_nextto(node, PRIMN_ANY, PRIMN_ANY, find_ph);
786 if(find_ph_result!=NULL)
788 node=(WSplit*)node->parent;
806 static void navi_to_primn(WRegionNavi nh, WPrimn *hprimn, WPrimn *vprimn,
809 /* choice should be PRIMN_ANY or PRIMN_NONE */
812 case REGION_NAVI_BEG:
817 case REGION_NAVI_END:
822 case REGION_NAVI_LEFT:
827 case REGION_NAVI_RIGHT:
832 case REGION_NAVI_TOP:
837 case REGION_NAVI_BOTTOM:
843 case REGION_NAVI_ANY:
851 static WRegion *node_reg(WSplit *node)
853 WSplitRegion *rnode=OBJ_CAST(node, WSplitRegion);
854 return (rnode!=NULL ? rnode->reg : NULL);
858 WRegion *tiling_do_navi_next(WTiling *ws, WRegion *reg,
859 WRegionNavi nh, bool nowrap,
862 WSplitFilter *filter=(any ? NULL : nostdispfilter);
863 WPrimn hprimn, vprimn;
866 navi_to_primn(nh, &hprimn, &vprimn, PRIMN_NONE);
869 reg=tiling_current(ws);
872 WSplitRegion *node=get_node_check(ws, reg);
874 nxt=node_reg(split_nextto((WSplit*)node, hprimn, vprimn,
879 if(nxt==NULL && !nowrap){
880 nxt=node_reg(split_current_todir(ws->split_tree,
881 primn_none2any(primn_invert(hprimn)),
882 primn_none2any(primn_invert(vprimn)),
890 WRegion *tiling_do_navi_first(WTiling *ws, WRegionNavi nh, bool any)
892 WSplitFilter *filter=(any ? NULL : nostdispfilter);
893 WPrimn hprimn, vprimn;
895 navi_to_primn(nh, &hprimn, &vprimn, PRIMN_ANY);
897 return node_reg(split_current_todir(ws->split_tree,
898 hprimn, vprimn, filter));
902 WRegion *tiling_navi_next(WTiling *ws, WRegion *reg,
903 WRegionNavi nh, WRegionNaviData *data)
905 WRegion *nxt=tiling_do_navi_next(ws, reg, nh, TRUE, FALSE);
907 return region_navi_cont(&ws->reg, nxt, data);
911 WRegion *tiling_navi_first(WTiling *ws, WRegionNavi nh,
912 WRegionNaviData *data)
914 WRegion *reg=tiling_do_navi_first(ws, nh, FALSE);
916 return region_navi_cont(&ws->reg, reg, data);
923 /*{{{ Split/unsplit */
926 static bool get_split_dir_primn(const char *str, int *dir, int *primn)
928 WPrimn hprimn, vprimn;
931 if(!ioncore_string_to_navi(str, &nh))
934 navi_to_primn(nh, &hprimn, &vprimn, PRIMN_NONE);
936 if(hprimn==PRIMN_NONE){
939 }else if(vprimn==PRIMN_NONE){
940 *dir=SPLIT_HORIZONTAL;
943 warn(TR("Invalid direction"));
951 static bool get_split_dir_primn_float(const char *str, int *dir, int *primn,
954 if(strncmp(str, "floating:", 9)==0){
956 return get_split_dir_primn(str+9, dir, primn);
959 return get_split_dir_primn(str, dir, primn);
964 #define SPLIT_MINS 16 /* totally arbitrary */
967 static WFrame *tiling_do_split(WTiling *ws, WSplit *node,
968 const char *dirstr, int minw, int minh)
970 int dir, primn, mins;
975 if(node==NULL || ws->split_tree==NULL){
976 warn(TR("Invalid node."));
980 if(!get_split_dir_primn_float(dirstr, &dir, &primn, &floating))
983 mins=(dir==SPLIT_VERTICAL ? minh : minw);
986 nnode=splittree_split(node, dir, primn, mins,
990 nnode=splittree_split_floating(node, dir, primn, mins,
991 ws->create_frame_fn, ws);
995 warn(TR("Unable to split."));
999 /* We must restack here to ensure the split tree is stacked in the
1002 if(ws->split_tree!=NULL)
1003 split_restack(ws->split_tree, ws->dummywin, Above);
1005 newframe=OBJ_CAST(nnode->reg, WFrame);
1006 assert(newframe!=NULL);
1008 if(!tiling_managed_add(ws, nnode->reg)){
1010 destroy_obj((Obj*)nnode);
1011 destroy_obj((Obj*)newframe);
1016 if(ws->split_tree!=NULL)
1017 split_restack(ws->split_tree, ws->dummywin, Above);
1024 * Create a new frame on \var{ws} above/below/left of/right of
1025 * \var{node} as indicated by \var{dirstr}. If \var{dirstr} is
1026 * prefixed with ''floating:'' a floating split is created.
1029 WFrame *tiling_split(WTiling *ws, WSplit *node, const char *dirstr)
1031 if(!check_node(ws, node))
1034 return tiling_do_split(ws, node, dirstr,
1035 SPLIT_MINS, SPLIT_MINS);
1040 * Same as \fnref{WTiling.split} at the root of the split tree.
1043 WFrame *tiling_split_top(WTiling *ws, const char *dirstr)
1045 return tiling_do_split(ws, ws->split_tree, dirstr,
1046 SPLIT_MINS, SPLIT_MINS);
1051 * Split \var{frame} creating a new frame to direction \var{dirstr}
1052 * (one of ''left'', ''right'', ''top'' or ''bottom'') of \var{frame}.
1053 * If \var{attach_current} is set, the region currently displayed in
1054 * \var{frame}, if any, is moved to thenew frame.
1055 * If \var{dirstr} is prefixed with ''floating:'' a floating split is
1059 WFrame *tiling_split_at(WTiling *ws, WFrame *frame, const char *dirstr,
1060 bool attach_current)
1069 node=get_node_check(ws, (WRegion*)frame);
1071 newframe=tiling_do_split(ws, (WSplit*)node, dirstr,
1072 region_min_w((WRegion*)frame),
1073 region_min_h((WRegion*)frame));
1078 curr=mplex_mx_current(&(frame->mplex));
1080 if(attach_current && curr!=NULL)
1081 mplex_attach_simple(&(newframe->mplex), curr, MPLEX_ATTACH_SWITCHTO);
1083 if(region_may_control_focus((WRegion*)frame))
1084 region_goto((WRegion*)newframe);
1090 void do_unsplit(WRegion *reg)
1092 WTiling *ws=REGION_MANAGER_CHK(reg, WTiling);
1099 ph=region_get_rescue_pholder_for((WRegion*)ws, reg);
1102 res=!region_rescue_needed(reg);
1104 res=region_rescue(reg, ph);
1105 destroy_obj((Obj*)ph);
1109 warn(TR("Unable to unsplit: Could not move client windows "
1110 "elsewhere within the tiling."));
1114 destroy_obj((Obj*)reg);
1119 * Try to relocate regions managed by \var{reg} to another frame
1120 * and, if possible, destroy it.
1123 void tiling_unsplit_at(WTiling *ws, WRegion *reg)
1125 if(reg==NULL || REGION_MANAGER(reg)!=(WRegion*)ws)
1128 mainloop_defer_action((Obj*)reg, (WDeferredAction*)do_unsplit);
1135 /*{{{ Navigation etc. exports */
1138 WRegion *tiling_current(WTiling *ws)
1140 WSplitRegion *node=NULL;
1141 if(ws->split_tree!=NULL){
1142 node=(WSplitRegion*)split_current_todir(ws->split_tree,
1143 PRIMN_ANY, PRIMN_ANY, NULL);
1145 return (node ? node->reg : NULL);
1150 * Iterate over managed regions of \var{ws} until \var{iterfn} returns
1152 * The function itself returns \code{true} if it reaches the end of list
1153 * without this happening.
1157 bool tiling_managed_i(WTiling *ws, ExtlFn iterfn)
1161 ptrlist_iter_init(&tmp, ws->managed_list);
1163 return extl_iter_objlist_(iterfn, (ObjIterator*)ptrlist_iter, &tmp);
1168 * Returns the root of the split tree.
1172 WSplit *tiling_split_tree(WTiling *ws)
1174 return ws->split_tree;
1179 * Return the most previously active region next to \var{reg} in
1180 * direction \var{dirstr} (left/right/up/down). The region \var{reg}
1181 * must be managed by \var{ws}. If \var{any} is not set, the status display
1182 * is not considered.
1186 WRegion *tiling_nextto(WTiling *ws, WRegion *reg, const char *dirstr,
1191 if(!ioncore_string_to_navi(dirstr, &nh))
1194 return tiling_do_navi_next(ws, reg, nh, FALSE, any);
1199 * Return the most previously active region on \var{ws} with no
1200 * other regions next to it in direction \var{dirstr}
1201 * (left/right/up/down). If \var{any} is not set, the status
1202 * display is not considered.
1206 WRegion *tiling_farthest(WTiling *ws, const char *dirstr, bool any)
1210 if(!ioncore_string_to_navi(dirstr, &nh))
1213 return tiling_do_navi_first(ws, nh, any);
1218 * For region \var{reg} managed by \var{ws} return the \type{WSplit}
1219 * a leaf of which \var{reg} is.
1223 WSplitRegion *tiling_node_of(WTiling *ws, WRegion *reg)
1226 warn(TR("Nil parameter."));
1230 if(REGION_MANAGER(reg)!=(WRegion*)ws){
1231 warn(TR("Manager doesn't match."));
1235 return splittree_node_of(reg);
1242 /*{{{ Flip and transpose */
1245 static WSplitSplit *get_at_split(WTiling *ws, WRegion *reg)
1251 split=OBJ_CAST(ws->split_tree, WSplitSplit);
1254 else if(split->br==(WSplit*)ws->stdispnode)
1255 return OBJ_CAST(split->tl, WSplitSplit);
1256 else if(split->tl==(WSplit*)ws->stdispnode)
1257 return OBJ_CAST(split->br, WSplitSplit);
1262 node=(WSplit*)get_node_check(ws, reg);
1267 if(node==(WSplit*)ws->stdispnode){
1268 warn(TR("The status display is not a valid parameter for "
1273 split=OBJ_CAST(node->parent, WSplitSplit);
1275 if(split!=NULL && (split->tl==(WSplit*)ws->stdispnode ||
1276 split->br==(WSplit*)ws->stdispnode)){
1277 split=OBJ_CAST(((WSplit*)split)->parent, WSplitSplit);
1285 * Flip \var{ws} at \var{reg} or root if nil.
1288 bool iowns_flip_at(WTiling *ws, WRegion *reg)
1290 WSplitSplit *split=get_at_split(ws, reg);
1295 splitsplit_flip(split);
1302 * Transpose \var{ws} at \var{reg} or root if nil.
1305 bool iowns_transpose_at(WTiling *ws, WRegion *reg)
1307 WSplitSplit *split=get_at_split(ws, reg);
1312 split_transpose((WSplit*)split);
1321 /*{{{ Floating toggle */
1324 static void replace(WSplitSplit *split, WSplitSplit *nsplit)
1326 WSplitInner *psplit=split->isplit.split.parent;
1328 nsplit->tl=split->tl;
1330 nsplit->tl->parent=(WSplitInner*)nsplit;
1332 nsplit->br=split->br;
1334 nsplit->br->parent=(WSplitInner*)nsplit;
1337 splitinner_replace((WSplitInner*)psplit, (WSplit*)split,
1340 splittree_changeroot((WSplit*)split, (WSplit*)nsplit);
1345 WSplitSplit *tiling_set_floating(WTiling *ws, WSplitSplit *split, int sp)
1347 bool set=OBJ_IS(split, WSplitFloat);
1348 bool nset=libtu_do_setparam(sp, set);
1349 const WRectangle *g=&((WSplit*)split)->geom;
1356 ns=(WSplitSplit*)create_splitfloat(g, ws, split->dir);
1358 if(OBJ_IS(split->tl, WSplitST) || OBJ_IS(split->br, WSplitST)){
1359 warn(TR("Refusing to float split directly containing the "
1360 "status display."));
1363 ns=create_splitsplit(g, split->dir);
1368 split_resize((WSplit*)ns, g, PRIMN_ANY, PRIMN_ANY);
1369 mainloop_defer_destroy((Obj*)split);
1377 * Toggle floating of a split's sides at \var{split} as indicated by the
1378 * parameter \var{how} (set/unset/toggle). A split of the appropriate is
1379 * returned, if there was a change.
1381 EXTL_EXPORT_AS(WTiling, set_floating)
1382 WSplitSplit *tiling_set_floating_extl(WTiling *ws, WSplitSplit *split,
1385 if(!check_node(ws, (WSplit*)split))
1387 return tiling_set_floating(ws, split, libtu_string_to_setparam(how));
1392 * Toggle floating of the sides of a split containin \var{reg} as indicated
1393 * by the parameters \var{how} (set/unset/toggle) and \var{dirstr}
1394 * (left/right/up/down/any). The new status is returned (and \code{false}
1397 EXTL_EXPORT_AS(WTiling, set_floating_at)
1398 bool tiling_set_floating_at_extl(WTiling *ws, WRegion *reg, const char *how,
1401 WPrimn hprimn=PRIMN_ANY, vprimn=PRIMN_ANY;
1402 WSplitSplit *split, *nsplit;
1405 node=(WSplit*)get_node_check(ws, reg);
1413 if(!ioncore_string_to_navi(dirstr, &nh))
1416 navi_to_primn(nh, &hprimn, &vprimn, PRIMN_NONE);
1420 split=OBJ_CAST(node->parent, WSplitSplit);
1422 warn(TR("No suitable split here."));
1426 if(!OBJ_IS(split->tl, WSplitST) && !OBJ_IS(split->br, WSplitST)){
1427 WPrimn tmp=(split->dir==SPLIT_VERTICAL ? vprimn : hprimn);
1429 || (node==split->tl && tmp==PRIMN_BR)
1430 || (node==split->br && tmp==PRIMN_TL)){
1435 node=(WSplit*)split;
1438 nsplit=tiling_set_floating(ws, split, libtu_string_to_setparam(how));
1440 return OBJ_IS((Obj*)(nsplit==NULL ? split : nsplit), WSplitFloat);
1450 ExtlTab tiling_get_configuration(WTiling *ws)
1452 ExtlTab tab, split_tree=extl_table_none();
1454 tab=region_get_base_configuration((WRegion*)ws);
1456 if(ws->split_tree!=NULL){
1457 if(!split_get_config(ws->split_tree, &split_tree))
1458 warn(TR("Could not get split tree."));
1461 extl_table_sets_t(tab, "split_tree", split_tree);
1462 extl_unref_table(split_tree);
1474 WSplit *load_splitst(WTiling *ws, const WRectangle *geom, ExtlTab tab)
1478 if(ws->stdispnode!=NULL){
1479 warn(TR("Workspace already has a status display node."));
1483 st=create_splitst(geom, NULL);
1489 static bool do_attach(WTiling *ws, WRegion *reg, void *p)
1491 WSplitRegion *node=create_splitregion(®ION_GEOM(reg), reg);
1496 if(!tiling_managed_add(ws, reg)){
1498 destroy_obj((Obj*)node);
1502 *(WSplitRegion**)p=node;
1508 WSplit *load_splitregion(WTiling *ws, const WRectangle *geom, ExtlTab tab)
1510 WWindow *par=REGION_PARENT(ws);
1511 WRegionAttachData data;
1516 if(!extl_table_gets_t(tab, "regparams", &rt)){
1517 warn(TR("Missing region parameters."));
1521 data.type=REGION_ATTACH_LOAD;
1526 fp.mode=REGION_FIT_EXACT;
1528 region_attach_helper((WRegion*)ws, par, &fp,
1529 (WRegionDoAttachFn*)do_attach, &node, &data);
1531 extl_unref_table(rt);
1539 WSplit *load_splitsplit(WTiling *ws, const WRectangle *geom, ExtlTab tab)
1541 WSplit *tl=NULL, *br=NULL;
1549 set+=(extl_table_gets_i(tab, "tls", &tls)==TRUE);
1550 set+=(extl_table_gets_i(tab, "brs", &brs)==TRUE);
1551 set+=(extl_table_gets_s(tab, "dir", &dir_str)==TRUE);
1556 if(strcmp(dir_str, "vertical")==0){
1558 }else if(strcmp(dir_str, "horizontal")==0){
1559 dir=SPLIT_HORIZONTAL;
1561 warn(TR("Invalid direction."));
1567 split=create_splitsplit(geom, dir);
1571 tls=maxof(tls, MINS);
1572 brs=maxof(brs, MINS);
1575 if(dir==SPLIT_HORIZONTAL){
1576 tls=maxof(0, geom->w)*tls/(tls+brs);
1579 tls=maxof(0, geom->h)*tls/(tls+brs);
1583 if(extl_table_gets_t(tab, "tl", &subtab)){
1584 tl=tiling_load_node(ws, &geom2, subtab);
1585 extl_unref_table(subtab);
1589 if(dir==SPLIT_HORIZONTAL){
1597 if(extl_table_gets_t(tab, "br", &subtab)){
1598 br=tiling_load_node(ws, &geom2, subtab);
1599 extl_unref_table(subtab);
1602 if(tl==NULL || br==NULL){
1603 /* PRIMN_TL/BR instead of ANY because of stdisp. */
1604 destroy_obj((Obj*)split);
1606 split_do_resize(tl, geom, PRIMN_BR, PRIMN_BR, FALSE);
1610 split_do_resize(br, geom, PRIMN_TL, PRIMN_TL, FALSE);
1616 tl->parent=(WSplitInner*)split;
1617 br->parent=(WSplitInner*)split;
1619 /*split->tmpsize=tls;*/
1623 return (WSplit*)split;
1627 WSplit *tiling_load_node_default(WTiling *ws, const WRectangle *geom,
1633 extl_table_gets_s(tab, "type", &typestr);
1636 warn(TR("No split type given."));
1640 if(strcmp(typestr, "WSplitRegion")==0)
1641 node=load_splitregion(ws, geom, tab);
1642 else if(strcmp(typestr, "WSplitSplit")==0)
1643 node=load_splitsplit(ws, geom, tab);
1644 else if(strcmp(typestr, "WSplitFloat")==0)
1645 node=load_splitfloat(ws, geom, tab);
1646 else if(strcmp(typestr, "WSplitST")==0)
1647 node=NULL;/*load_splitst(ws, geom, tab);*/
1649 warn(TR("Unknown split type."));
1657 WSplit *tiling_load_node(WTiling *ws, const WRectangle *geom, ExtlTab tab)
1660 CALL_DYN_RET(ret, WSplit*, tiling_load_node, ws, (ws, geom, tab));
1666 WRegion *tiling_load(WWindow *par, const WFitParams *fp, ExtlTab tab)
1672 if(extl_table_gets_t(tab, "split_tree", &treetab))
1675 ws=create_tiling(par, fp, NULL, ci);
1679 extl_unref_table(treetab);
1684 ws->split_tree=tiling_load_node(ws, ®ION_GEOM(ws), treetab);
1685 extl_unref_table(treetab);
1688 if(ws->split_tree==NULL){
1689 warn(TR("The workspace is empty."));
1690 destroy_obj((Obj*)ws);
1694 ws->split_tree->ws_if_root=ws;
1695 split_restack(ws->split_tree, ws->dummywin, Above);
1697 return (WRegion*)ws;
1704 /*{{{ Dynamic function table and class implementation */
1707 static DynFunTab tiling_dynfuntab[]={
1714 {region_do_set_focus,
1715 tiling_do_set_focus},
1717 {(DynFun*)region_fitrep,
1718 (DynFun*)tiling_fitrep},
1720 {region_managed_rqgeom,
1721 tiling_managed_rqgeom},
1723 {region_managed_remove,
1724 tiling_managed_remove},
1726 {(DynFun*)region_managed_prepare_focus,
1727 (DynFun*)tiling_managed_prepare_focus},
1729 {(DynFun*)region_prepare_manage,
1730 (DynFun*)tiling_prepare_manage},
1732 {(DynFun*)region_rescue_clientwins,
1733 (DynFun*)tiling_rescue_clientwins},
1735 {(DynFun*)region_get_rescue_pholder_for,
1736 (DynFun*)tiling_get_rescue_pholder_for},
1738 {(DynFun*)region_get_configuration,
1739 (DynFun*)tiling_get_configuration},
1741 {(DynFun*)region_managed_disposeroot,
1742 (DynFun*)tiling_managed_disposeroot},
1744 {(DynFun*)region_current,
1745 (DynFun*)tiling_current},
1747 {(DynFun*)tiling_managed_add,
1748 (DynFun*)tiling_managed_add_default},
1750 {region_manage_stdisp,
1751 tiling_manage_stdisp},
1753 {region_unmanage_stdisp,
1754 tiling_unmanage_stdisp},
1756 {(DynFun*)tiling_load_node,
1757 (DynFun*)tiling_load_node_default},
1765 {(DynFun*)region_navi_first,
1766 (DynFun*)tiling_navi_first},
1768 {(DynFun*)region_navi_next,
1769 (DynFun*)tiling_navi_next},
1771 {(DynFun*)region_xwindow,
1772 (DynFun*)tiling_xwindow},
1774 {(DynFun*)region_prepare_manage_transient,
1775 (DynFun*)tiling_prepare_manage_transient},
1782 IMPLCLASS(WTiling, WRegion, tiling_deinit, tiling_dynfuntab);