1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005
|
/*
* ion/mod_tiling/splitext.c
*
* Copyright (c) Tuomo Valkonen 1999-2007.
*
* See the included file LICENSE for details.
*/
#include <string.h>
#include <limits.h>
#include <libtu/objp.h>
#include <libtu/minmax.h>
#include <ioncore/common.h>
#include <ioncore/global.h>
#include <ioncore/rootwin.h>
#include <ioncore/xwindow.h>
#include <ioncore/window.h>
#include "tiling.h"
#include "split.h"
#include "splitfloat.h"
#include "panehandle.h"
#define GEOM(X) (((WSplit*)(X))->geom)
/*{{{ Init/deinit */
static void splitfloat_set_borderlines(WSplitFloat *split)
{
int dir=split->ssplit.dir;
split->tlpwin->bline=(dir==SPLIT_HORIZONTAL
? GR_BORDERLINE_RIGHT
: GR_BORDERLINE_BOTTOM);
split->brpwin->bline=(dir==SPLIT_HORIZONTAL
? GR_BORDERLINE_LEFT
: GR_BORDERLINE_TOP);
}
bool splitfloat_init(WSplitFloat *split, const WRectangle *geom,
WTiling *ws, int dir)
{
WFitParams fp;
WWindow *par=REGION_PARENT(ws);
assert(par!=NULL);
fp.g=*geom;
fp.mode=REGION_FIT_EXACT;
split->tlpwin=create_panehandle(par, &fp);
if(split->tlpwin==NULL)
return FALSE;
fp.g=*geom;
fp.mode=REGION_FIT_EXACT;
split->brpwin=create_panehandle(par, &fp);
if(split->brpwin==NULL){
destroy_obj((Obj*)split->tlpwin);
return FALSE;
}
if(!splitsplit_init(&(split->ssplit), geom, dir)){
destroy_obj((Obj*)split->brpwin);
destroy_obj((Obj*)split->tlpwin);
return FALSE;
}
split->tlpwin->splitfloat=split;
split->brpwin->splitfloat=split;
splitfloat_set_borderlines(split);
if(REGION_IS_MAPPED(ws)){
region_map((WRegion*)(split->tlpwin));
region_map((WRegion*)(split->brpwin));
}
return TRUE;
}
WSplitFloat *create_splitfloat(const WRectangle *geom, WTiling *ws, int dir)
{
CREATEOBJ_IMPL(WSplitFloat, splitfloat, (p, geom, ws, dir));
}
void splitfloat_deinit(WSplitFloat *split)
{
if(split->tlpwin!=NULL){
WPaneHandle *tmp=split->tlpwin;
split->tlpwin=NULL;
tmp->splitfloat=NULL;
destroy_obj((Obj*)tmp);
}
if(split->brpwin!=NULL){
WPaneHandle *tmp=split->brpwin;
split->brpwin=NULL;
tmp->splitfloat=NULL;
destroy_obj((Obj*)tmp);
}
splitsplit_deinit(&(split->ssplit));
}
/*}}}*/
/*{{{ X window handling */
static void stack_stacking_reg(WRegion *reg,
Window *bottomret, Window *topret)
{
Window b=None, t=None;
if(reg!=NULL){
region_stacking(reg, &b, &t);
if(*bottomret==None)
*bottomret=b;
if(t!=None)
*topret=t;
}
}
static void stack_stacking_split(WSplit *split,
Window *bottomret, Window *topret)
{
Window b=None, t=None;
if(split!=NULL){
split_stacking(split, &b, &t);
if(*bottomret==None)
*bottomret=b;
if(t!=None)
*topret=t;
}
}
static void splitfloat_stacking(WSplitFloat *split,
Window *bottomret, Window *topret)
{
*bottomret=None;
*topret=None;
if(split->ssplit.current!=SPLIT_CURRENT_TL){
stack_stacking_reg((WRegion*)split->tlpwin, bottomret, topret);
stack_stacking_split(split->ssplit.tl, bottomret, topret);
stack_stacking_reg((WRegion*)split->brpwin, bottomret, topret);
stack_stacking_split(split->ssplit.br, bottomret, topret);
}else{
stack_stacking_reg((WRegion*)split->brpwin, bottomret, topret);
stack_stacking_split(split->ssplit.br, bottomret, topret);
stack_stacking_reg((WRegion*)split->tlpwin, bottomret, topret);
stack_stacking_split(split->ssplit.tl, bottomret, topret);
}
}
static void stack_restack_reg(WRegion *reg, Window *other, int *mode)
{
Window b=None, t=None;
if(reg!=NULL){
region_restack(reg, *other, *mode);
region_stacking(reg, &b, &t);
if(t!=None){
*other=t;
*mode=Above;
}
}
}
static void stack_restack_split(WSplit *split, Window *other, int *mode)
{
Window b=None, t=None;
if(split!=NULL){
split_restack(split, *other, *mode);
split_stacking(split, &b, &t);
if(t!=None){
*other=t;
*mode=Above;
}
}
}
static void splitfloat_restack(WSplitFloat *split, Window other, int mode)
{
if(split->ssplit.current!=SPLIT_CURRENT_TL){
stack_restack_reg((WRegion*)split->tlpwin, &other, &mode);
stack_restack_split(split->ssplit.tl, &other, &mode);
stack_restack_reg((WRegion*)split->brpwin, &other, &mode);
stack_restack_split(split->ssplit.br, &other, &mode);
}else{
stack_restack_reg((WRegion*)split->brpwin, &other, &mode);
stack_restack_split(split->ssplit.br, &other, &mode);
stack_restack_reg((WRegion*)split->tlpwin, &other, &mode);
stack_restack_split(split->ssplit.tl, &other, &mode);
}
}
static void splitfloat_map(WSplitFloat *split)
{
region_map((WRegion*)(split->tlpwin));
region_map((WRegion*)(split->brpwin));
splitinner_forall((WSplitInner*)split, split_map);
}
static void splitfloat_unmap(WSplitFloat *split)
{
region_unmap((WRegion*)(split->tlpwin));
region_unmap((WRegion*)(split->brpwin));
splitinner_forall((WSplitInner*)split, split_unmap);
}
static void reparentreg(WRegion *reg, WWindow *target)
{
WRectangle g=REGION_GEOM(reg);
region_reparent(reg, target, &g, REGION_FIT_EXACT);
}
static void splitfloat_reparent(WSplitFloat *split, WWindow *target)
{
if(split->ssplit.current!=SPLIT_CURRENT_TL){
reparentreg((WRegion*)split->tlpwin, target);
split_reparent(split->ssplit.tl, target);
reparentreg((WRegion*)split->brpwin, target);
split_reparent(split->ssplit.br, target);
}else{
reparentreg((WRegion*)split->brpwin, target);
split_reparent(split->ssplit.br, target);
reparentreg((WRegion*)split->tlpwin, target);
split_reparent(split->ssplit.tl, target);
}
}
/*}}}*/
/*{{{ Geometry */
#define TL_BORDER(SF) ((SF)->ssplit.dir==SPLIT_VERTICAL \
? (SF)->tlpwin->bdw.bottom \
: (SF)->tlpwin->bdw.right)
#define BR_BORDER(SF) ((SF)->ssplit.dir==SPLIT_VERTICAL \
? (SF)->brpwin->bdw.top \
: (SF)->brpwin->bdw.left)
void splitfloat_tl_pwin_to_cnt(WSplitFloat *split, WRectangle *g)
{
if(split->ssplit.dir==SPLIT_HORIZONTAL)
g->w=MAXOF((unsigned int)1, g->w-split->tlpwin->bdw.right);
else
g->h=MAXOF((unsigned int)1, g->h-split->tlpwin->bdw.bottom);
}
void splitfloat_br_pwin_to_cnt(WSplitFloat *split, WRectangle *g)
{
if(split->ssplit.dir==SPLIT_HORIZONTAL){
int delta=split->tlpwin->bdw.left;
g->w=MAXOF(1, g->w-delta);
g->x+=delta;
}else{
int delta=split->tlpwin->bdw.top;
g->h=MAXOF(1, g->h-delta);
g->y+=delta;
}
}
void splitfloat_tl_cnt_to_pwin(WSplitFloat *split, WRectangle *g)
{
if(split->ssplit.dir==SPLIT_HORIZONTAL)
g->w=MAXOF((unsigned int)1, g->w+split->tlpwin->bdw.right);
else
g->h=MAXOF((unsigned int)1, g->h+split->tlpwin->bdw.bottom);
}
void splitfloat_br_cnt_to_pwin(WSplitFloat *split, WRectangle *g)
{
if(split->ssplit.dir==SPLIT_HORIZONTAL){
int delta=split->tlpwin->bdw.left;
g->w=MAXOF(1, g->w+delta);
g->x-=delta;
}else{
int delta=split->tlpwin->bdw.top;
g->h=MAXOF(1, g->h+delta);
g->y-=delta;
}
}
static int infadd(int x, int y)
{
return ((x==INT_MAX || y==INT_MAX) ? INT_MAX : (x+y));
}
static int splitfloat_get_handle(WSplitFloat *split, int dir,
WSplit *other)
{
assert(other==split->ssplit.tl || other==split->ssplit.br);
if(dir!=split->ssplit.dir)
return 0;
if(dir==SPLIT_VERTICAL){
if(other==split->ssplit.tl)
return split->tlpwin->bdw.right;
else if(other==split->ssplit.br)
return split->tlpwin->bdw.left;
}else{
if(other==split->ssplit.tl)
return split->tlpwin->bdw.bottom;
else if(other==split->ssplit.br)
return split->tlpwin->bdw.top;
}
return 0;
}
static int splitfloat_get_max(WSplitFloat *split, int dir, WSplit *other)
{
return infadd((dir==SPLIT_VERTICAL ? other->max_h : other->max_w),
splitfloat_get_handle(split, dir, other));
}
static int splitfloat_get_min(WSplitFloat *split, int dir, WSplit *other)
{
return ((dir==SPLIT_VERTICAL ? other->min_h : other->min_w)
+splitfloat_get_handle(split, dir, other));
}
static void splitfloat_update_bounds(WSplitFloat *split, bool recursive)
{
WSplit *tl=split->ssplit.tl, *br=split->ssplit.br;
WSplit *node=(WSplit*)split;
int tl_max_w, br_max_w, tl_max_h, br_max_h;
int tl_min_w, br_min_w, tl_min_h, br_min_h;
if(recursive){
split_update_bounds(tl, recursive);
split_update_bounds(br, recursive);
}
tl_max_w=splitfloat_get_max(split, SPLIT_HORIZONTAL, tl);
br_max_w=splitfloat_get_max(split, SPLIT_HORIZONTAL, br);
tl_max_h=splitfloat_get_max(split, SPLIT_VERTICAL, tl);
br_max_h=splitfloat_get_max(split, SPLIT_VERTICAL, br);
tl_min_w=splitfloat_get_min(split, SPLIT_HORIZONTAL, tl);
br_min_w=splitfloat_get_min(split, SPLIT_HORIZONTAL, br);
tl_min_h=splitfloat_get_min(split, SPLIT_VERTICAL, tl);
br_min_h=splitfloat_get_min(split, SPLIT_VERTICAL, br);
if(split->ssplit.dir==SPLIT_HORIZONTAL){
node->max_w=infadd(tl_max_w, br_max_w);
node->min_w=MINOF(tl_min_w, br_min_w);
node->unused_w=0;
node->min_h=MAXOF(tl_min_h, br_min_h);
node->max_h=MAXOF(MINOF(tl_max_h, br_max_h), node->min_h);
node->unused_h=MINOF(tl->unused_h, br->unused_h);
}else{
node->max_h=infadd(tl_max_h, br_max_h);
node->min_h=MINOF(tl_min_h, br_min_h);
node->unused_h=0;
node->min_w=MAXOF(tl_min_w, br_min_w);
node->max_w=MAXOF(MINOF(tl_max_w, br_max_w), node->min_w);
node->unused_w=MINOF(tl->unused_w, br->unused_w);
}
}
void splitfloat_update_handles(WSplitFloat *split, const WRectangle *tlg_,
const WRectangle *brg_)
{
WRectangle tlg=*tlg_, brg=*brg_;
if(split->ssplit.dir==SPLIT_HORIZONTAL){
tlg.w=split->tlpwin->bdw.right;
tlg.x=tlg_->x+tlg_->w-tlg.w;
brg.w=split->brpwin->bdw.left;
}else{
tlg.h=split->tlpwin->bdw.bottom;
tlg.y=tlg_->y+tlg_->h-tlg.h;
brg.h=split->brpwin->bdw.top;
}
region_fit((WRegion*)split->tlpwin, &tlg, REGION_FIT_EXACT);
region_fit((WRegion*)split->brpwin, &brg, REGION_FIT_EXACT);
}
static void bound(int *what, int min, int max)
{
if(*what<min)
*what=min;
else if(*what>max)
*what=max;
}
static void adjust_sizes(int *tls_, int *brs_, int nsize,
int tlmin, int brmin, int tlmax, int brmax,
int primn)
{
int tls=MAXOF(0, *tls_);
int brs=MAXOF(0, *brs_);
nsize=MAXOF(1, nsize);
if(primn==PRIMN_TL){
tls=MAXOF(1, nsize-brs);
bound(&tls, tlmin, tlmax);
brs=nsize-tls;
bound(&brs, brmin, brmax);
tls=nsize-brs;
bound(&tls, tlmin, tlmax);
}else if(primn==PRIMN_BR){
brs=MAXOF(1, nsize-tls);
bound(&brs, brmin, brmax);
tls=nsize-brs;
bound(&tls, tlmin, tlmax);
brs=nsize-tls;
bound(&brs, brmin, brmax);
}else{ /* && PRIMN_ANY */
tls=tls*nsize/MAXOF(2, tls+brs);
bound(&tls, tlmin, tlmax);
brs=nsize-tls;
bound(&brs, brmin, brmax);
tls=nsize-brs;
bound(&tls, tlmin, tlmax);
}
*tls_=tls;
*brs_=brs;
}
static void adjust_size(int *sz, int dir, WSplitFloat *f, WSplit *s)
{
int mi=splitfloat_get_min(f, dir, s);
int ma=splitfloat_get_max(f, dir, s);
*sz=MAXOF(mi, MINOF(*sz, ma));
}
static void splitfloat_do_resize(WSplitFloat *split, const WRectangle *ng,
int hprimn, int vprimn, bool transpose)
{
WRectangle tlg=GEOM(split->ssplit.tl);
WRectangle brg=GEOM(split->ssplit.br);
WRectangle ntlg=*ng, nbrg=*ng;
int dir=split->ssplit.dir;
bool adjust=TRUE;
splitfloat_tl_cnt_to_pwin(split, &tlg);
splitfloat_br_cnt_to_pwin(split, &brg);
if(transpose){
if(dir==SPLIT_VERTICAL){
dir=SPLIT_HORIZONTAL;
split->tlpwin->bline=GR_BORDERLINE_RIGHT;
split->brpwin->bline=GR_BORDERLINE_LEFT;
}else{
dir=SPLIT_VERTICAL;
split->tlpwin->bline=GR_BORDERLINE_BOTTOM;
split->brpwin->bline=GR_BORDERLINE_TOP;
}
split->ssplit.dir=dir;
}
if(dir==SPLIT_VERTICAL){
if(ng->h<=tlg.h+brg.h){
if(transpose){
ntlg.h=MINOF(tlg.w, ng->h*2/3);
nbrg.h=MINOF(brg.w, ng->h*2/3);
adjust_size(&ntlg.h, dir, split, split->ssplit.tl);
adjust_size(&nbrg.h, dir, split, split->ssplit.br);
adjust=(ng->h>ntlg.h+nbrg.h);
}else{
ntlg.h=MINOF(ng->h, tlg.h);
nbrg.h=MINOF(ng->h, brg.h);
adjust=FALSE;
}
}else{
ntlg.h=tlg.h;
nbrg.h=brg.h;
}
if(adjust){
adjust_sizes(&ntlg.h, &nbrg.h, ng->h,
splitfloat_get_min(split, dir, split->ssplit.tl),
splitfloat_get_min(split, dir, split->ssplit.br),
splitfloat_get_max(split, dir, split->ssplit.tl),
splitfloat_get_max(split, dir, split->ssplit.br),
vprimn);
}
nbrg.y=ng->y+ng->h-nbrg.h;
}else{
if(ng->w<=tlg.w+brg.w){
if(transpose){
ntlg.w=MINOF(tlg.h, ng->w*2/3);
nbrg.w=MINOF(brg.h, ng->w*2/3);
adjust_size(&ntlg.w, dir, split, split->ssplit.tl);
adjust_size(&nbrg.w, dir, split, split->ssplit.br);
adjust=(ng->w>ntlg.w+nbrg.w);
}else{
ntlg.w=MINOF(ng->w, tlg.w);
nbrg.w=MINOF(ng->w, brg.w);
adjust=FALSE;
}
}else{
ntlg.w=tlg.w;
nbrg.w=brg.w;
}
if(adjust){
adjust_sizes(&ntlg.w, &nbrg.w, ng->w,
splitfloat_get_min(split, dir, split->ssplit.tl),
splitfloat_get_min(split, dir, split->ssplit.br),
splitfloat_get_max(split, dir, split->ssplit.tl),
splitfloat_get_max(split, dir, split->ssplit.br),
hprimn);
}
nbrg.x=ng->x+ng->w-nbrg.w;
}
GEOM(split)=*ng;
splitfloat_update_handles(split, &ntlg, &nbrg);
splitfloat_tl_pwin_to_cnt(split, &ntlg);
split_do_resize(split->ssplit.tl, &ntlg, hprimn, vprimn, transpose);
splitfloat_br_pwin_to_cnt(split, &nbrg);
split_do_resize(split->ssplit.br, &nbrg, hprimn, vprimn, transpose);
}
static void calc_amount(int *amount, int *oamount,
int rs, WSplitSplit *p, int omax,
const WRectangle *ng, const WRectangle *og)
{
*oamount=0;
if(rs>=0){
if(p->dir==SPLIT_VERTICAL)
*amount=MAXOF(0, MINOF(rs, GEOM(p).h-ng->h));
else
*amount=MAXOF(0, MINOF(rs, GEOM(p).w-ng->w));
}else{
if(p->dir==SPLIT_VERTICAL){
int overlap=MAXOF(0, og->h-(GEOM(p).h-ng->h));
*amount=-MINOF(-rs, overlap);
*oamount=MAXOF(0, MINOF(*amount-rs, omax-og->h));
*amount-=*oamount;
}else{
int overlap=MAXOF(0, og->w-(GEOM(p).w-ng->w));
*amount=-MINOF(-rs, overlap);
*oamount=MAXOF(0, MINOF(*amount-rs, omax-og->w));
*amount-=*oamount;
}
}
}
static void splitfloat_do_rqsize(WSplitFloat *split, WSplit *node,
RootwardAmount *ha, RootwardAmount *va,
WRectangle *rg, bool tryonly)
{
int hprimn=PRIMN_ANY, vprimn=PRIMN_ANY;
WRectangle pg, og, ng, nog, nng;
RootwardAmount *ca;
WSplit *other;
int amount=0, oamount=0, omax;
int thisnode;
WSplitSplit *p=&(split->ssplit);
assert(!ha->any || ha->tl==0);
assert(!va->any || va->tl==0);
assert(p->tl==node || p->br==node);
if(p->tl==node){
other=p->br;
thisnode=PRIMN_TL;
}else{
other=p->tl;
thisnode=PRIMN_BR;
}
ng=GEOM(node);
og=GEOM(other);
if(thisnode==PRIMN_TL){
splitfloat_tl_cnt_to_pwin(split, &ng);
splitfloat_br_cnt_to_pwin(split, &og);
}else{
splitfloat_br_cnt_to_pwin(split, &ng);
splitfloat_tl_cnt_to_pwin(split, &og);
}
ca=(p->dir==SPLIT_VERTICAL ? va : ha);
omax=splitfloat_get_max(split, p->dir, other);
if(thisnode==PRIMN_TL || ca->any){
calc_amount(&amount, &oamount, ca->br, p, omax, &ng, &og);
ca->br-=amount;
}else/*if(thisnode==PRIMN_BR)*/{
calc_amount(&amount, &oamount, ca->tl, p, omax, &ng, &og);
ca->tl-=amount;
}
if(((WSplit*)p)->parent==NULL /*||
(ha->tl==0 && ha->br==0 && va->tl==0 && va->br==0)*/){
pg=((WSplit*)p)->geom;
}else{
splitinner_do_rqsize(((WSplit*)p)->parent, (WSplit*)p, ha, va,
&pg, tryonly);
}
assert(pg.w>=0 && pg.h>=0);
nog=pg;
nng=pg;
if(p->dir==SPLIT_VERTICAL){
nog.h=MINOF(pg.h, MAXOF(0, og.h+oamount));
nng.h=MINOF(pg.h, MAXOF(0, ng.h+amount+pg.h-GEOM(p).h));
if(thisnode==PRIMN_TL)
nog.y=pg.y+pg.h-nog.h;
else
nng.y=pg.y+pg.h-nng.h;
vprimn=thisnode;
}else{
nog.w=MINOF(pg.w, MAXOF(0, og.w+oamount));
nng.w=MINOF(pg.w, MAXOF(0, ng.w+amount+pg.w-GEOM(p).w));
if(thisnode==PRIMN_TL)
nog.x=pg.x+pg.w-nog.w;
else
nng.x=pg.x+pg.w-nng.w;
hprimn=thisnode;
}
if(!tryonly){
GEOM(p)=pg;
if(thisnode==PRIMN_TL){
splitfloat_update_handles(split, &nng, &nog);
splitfloat_br_pwin_to_cnt(split, &nog);
}else{
splitfloat_update_handles(split, &nog, &nng);
splitfloat_tl_pwin_to_cnt(split, &nog);
}
/* Ent jos 'other' on stdisp? */
split_do_resize(other, &nog, hprimn, vprimn, FALSE);
}
*rg=nng;
if(thisnode==PRIMN_TL)
splitfloat_tl_pwin_to_cnt(split, rg);
else
splitfloat_br_pwin_to_cnt(split, rg);
}
void splitfloat_flip(WSplitFloat *split)
{
WRectangle tlg, brg;
splitsplit_flip_default(&split->ssplit);
tlg=split->ssplit.tl->geom;
brg=split->ssplit.br->geom;
splitfloat_tl_cnt_to_pwin(split, &tlg);
splitfloat_br_cnt_to_pwin(split, &brg);
splitfloat_update_handles(split, &tlg, &brg);
}
/*}}}*/
/*{{{ Loading code */
#define MINS 8
static void adjust_tls_brs(int *tls, int *brs, int total)
{
if(*tls<=0)
*tls=MINS;
if(*brs<=0)
*brs=MINS;
if(*tls+*brs<total){
*tls=total*(*tls)/(*tls+*brs);
*brs=total-(*tls);
}
*tls=MINOF(MAXOF(MINS, *tls), total);
*brs=MINOF(MAXOF(MINS, *brs), total);
}
static void calc_tlg_brg(const WRectangle *geom, int tls, int brs, int dir,
WRectangle *tlg, WRectangle *brg)
{
*tlg=*geom;
*brg=*geom;
if(dir==SPLIT_HORIZONTAL){
adjust_tls_brs(&tls, &brs, geom->w);
tlg->w=tls;
brg->w=brs;
brg->x=geom->x+geom->w-brs;
}else{
adjust_tls_brs(&tls, &brs, geom->h);
tlg->h=tls;
brg->h=brs;
brg->y=geom->y+geom->h-brs;
}
}
WSplit *load_splitfloat(WTiling *ws, const WRectangle *geom, ExtlTab tab)
{
WSplit *tl=NULL, *br=NULL;
WSplitFloat *split;
char *dir_str;
int dir, brs, tls;
ExtlTab subtab;
WRectangle tlg, brg;
int set=0;
set+=(extl_table_gets_i(tab, "tls", &tls)==TRUE);
set+=(extl_table_gets_i(tab, "brs", &brs)==TRUE);
set+=(extl_table_gets_s(tab, "dir", &dir_str)==TRUE);
if(set!=3)
return NULL;
if(strcmp(dir_str, "vertical")==0){
dir=SPLIT_VERTICAL;
}else if(strcmp(dir_str, "horizontal")==0){
dir=SPLIT_HORIZONTAL;
}else{
warn(TR("Invalid direction."));
free(dir_str);
return NULL;
}
free(dir_str);
split=create_splitfloat(geom, ws, dir);
if(split==NULL)
return NULL;
if(!extl_table_is_bool_set(tab, "tls_brs_incl_handles")){
if(split->ssplit.dir==SPLIT_HORIZONTAL){
tls+=split->tlpwin->bdw.right;
brs+=split->brpwin->bdw.left;
}else{
tls+=split->tlpwin->bdw.bottom;
brs+=split->brpwin->bdw.top;
}
}
calc_tlg_brg(geom, tls, brs, dir, &tlg, &brg);
splitfloat_update_handles(split, &tlg, &brg);
if(extl_table_gets_t(tab, "tl", &subtab)){
WRectangle g=tlg;
splitfloat_tl_pwin_to_cnt(split, &g);
tl=tiling_load_node(ws, &g, subtab);
extl_unref_table(subtab);
}
if(extl_table_gets_t(tab, "br", &subtab)){
WRectangle g;
if(tl==NULL){
g=*geom;
}else{
g=brg;
splitfloat_br_pwin_to_cnt(split, &g);
}
br=tiling_load_node(ws, &g, subtab);
extl_unref_table(subtab);
}
if(tl==NULL || br==NULL){
destroy_obj((Obj*)split);
if(tl!=NULL){
split_do_resize(tl, geom, PRIMN_ANY, PRIMN_ANY, FALSE);
return tl;
}
if(br!=NULL){
split_do_resize(br, geom, PRIMN_ANY, PRIMN_ANY, FALSE);
return br;
}
return NULL;
}
tl->parent=(WSplitInner*)split;
br->parent=(WSplitInner*)split;
split->ssplit.tl=tl;
split->ssplit.br=br;
return (WSplit*)split;
}
/*}}}*/
/*{{{ Split */
WSplitRegion *splittree_split_floating(WSplit *node, int dir, int primn,
int nmins, WRegionSimpleCreateFn *fn,
WTiling *ws)
{
WSplitFloat *sf;
int omins, mins;
int sn, so, s, rs;
int bn, bo;
WRectangle gn, go, gnc, goc;
WFitParams fp;
WRegion *nreg;
WSplitRegion *nnode;
WSplitInner *psplit;
if(primn!=PRIMN_TL && primn!=PRIMN_BR)
primn=PRIMN_BR;
split_update_bounds(split_find_root(node), TRUE);
sf=create_splitfloat(&node->geom, ws, dir);
if(sf==NULL)
return NULL;
omins=(dir==SPLIT_VERTICAL ? node->min_h : node->min_w);
s=split_size(node, dir);
if(primn==PRIMN_BR){
bn=BR_BORDER(sf);
bo=TL_BORDER(sf);
}else{
bn=TL_BORDER(sf);
bo=BR_BORDER(sf);
}
mins=MAXOF(omins+bo, nmins+bn);
/* Potentially resize old node. */
splittree_begin_resize();
if(mins>s){
WRectangle ng=node->geom, rg;
if(dir==SPLIT_VERTICAL)
ng.h=mins;
else
ng.w=mins;
split_do_rqgeom_(node, &ng, TRUE, TRUE, &rg, TRUE);
rs=(dir==SPLIT_VERTICAL ? rg.h : rg.w);
if(rs<mins){
warn(TR("Unable to split: not enough free space."));
destroy_obj((Obj*)sf);
return NULL;
}
split_do_rqgeom_(node, &ng, TRUE, TRUE, &rg, FALSE);
s=split_size(node, dir);
}else{
splittree_scan_stdisp_rootward(node);
}
/* Calculate geometries. */
sn=MAXOF(nmins+bn, s/2);
so=MAXOF(omins+bo, s-s/2);
((WSplit*)sf)->geom=node->geom;
if(primn==PRIMN_TL){
calc_tlg_brg(&(node->geom), sn, so, dir, &gn, &go);
splitfloat_update_handles(sf, &gn, &go);
gnc=gn; splitfloat_tl_pwin_to_cnt(sf, &gnc);
goc=go; splitfloat_br_pwin_to_cnt(sf, &goc);
}else{
calc_tlg_brg(&(node->geom), so, sn, dir, &go, &gn);
splitfloat_update_handles(sf, &go, &gn);
goc=go; splitfloat_tl_pwin_to_cnt(sf, &goc);
gnc=gn; splitfloat_br_pwin_to_cnt(sf, &gnc);
}
/* Create the region. */
fp.mode=REGION_FIT_EXACT;
fp.g=gnc;
nreg=fn(REGION_PARENT(ws), &fp);
if(nreg==NULL){
destroy_obj((Obj*)sf);
return NULL;
}
nnode=create_splitregion(&(fp.g), nreg);
if(nnode==NULL){
destroy_obj((Obj*)nreg);
destroy_obj((Obj*)sf);
return NULL;
}
/* Now that everything's ok, resize and move original node. */
split_do_resize(node, &goc,
(dir==SPLIT_HORIZONTAL ? primn : PRIMN_ANY),
(dir==SPLIT_VERTICAL ? primn : PRIMN_ANY),
FALSE);
/* Set up split structure. */
psplit=node->parent;
if(psplit!=NULL)
splitinner_replace(psplit, node, (WSplit*)sf);
else
splittree_changeroot(node, (WSplit*)sf);
node->parent=(WSplitInner*)sf;
((WSplit*)nnode)->parent=(WSplitInner*)sf;
if(primn==PRIMN_BR){
sf->ssplit.tl=node;
sf->ssplit.br=(WSplit*)nnode;
}else{
sf->ssplit.tl=(WSplit*)nnode;
sf->ssplit.br=node;
}
/*splittree_end_resize();*/
return nnode;
}
/*}}}*/
/*{{{ The class */
static DynFunTab splitfloat_dynfuntab[]={
{split_update_bounds, splitfloat_update_bounds},
{split_do_resize, splitfloat_do_resize},
{splitinner_do_rqsize, splitfloat_do_rqsize},
{split_stacking, splitfloat_stacking},
{split_restack, splitfloat_restack},
{split_reparent, splitfloat_reparent},
{split_map, splitfloat_map},
{split_unmap, splitfloat_unmap},
{splitsplit_flip, splitfloat_flip},
END_DYNFUNTAB,
};
EXTL_EXPORT
IMPLCLASS(WSplitFloat, WSplitSplit, splitfloat_deinit, splitfloat_dynfuntab);
/*}}}*/
|