-
-
Notifications
You must be signed in to change notification settings - Fork 66
/
Copy pathmplex.c
2102 lines (1550 loc) · 49.3 KB
/
mplex.c
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
/*
* ion/ioncore/mplex.c
*
* Copyright (c) Tuomo Valkonen 1999-2007.
*
* See the included file LICENSE for details.
*/
#include <limits.h>
#include <string.h>
#include <libtu/objp.h>
#include <libtu/minmax.h>
#include <libtu/rb.h>
#include <libextl/extl.h>
#include <libmainloop/defer.h>
#include "names.h"
#include "common.h"
#include "window.h"
#include "global.h"
#include "rootwin.h"
#include "focus.h"
#include "event.h"
#include "attach.h"
#include "manage.h"
#include "resize.h"
#include "tags.h"
#include "sizehint.h"
#include "extlconv.h"
#include "frame-pointer.h"
#include "bindmaps.h"
#include "regbind.h"
#include "saveload.h"
#include "xwindow.h"
#include "mplexpholder.h"
#include "llist.h"
#include "names.h"
#include "sizepolicy.h"
#include "stacking.h"
#include "group.h"
#include "navi.h"
#include "groupedpholder.h"
#define SUBS_MAY_BE_MAPPED(MPLEX) \
(REGION_IS_MAPPED(MPLEX) && !MPLEX_MGD_UNVIEWABLE(MPLEX))
#define PASSIVE(ST) ((ST)->level<=STACKING_LEVEL_MODAL1 \
&& ((ST)->reg==NULL \
|| (ST)->reg->flags®ION_SKIP_FOCUS))
#define CAN_MANAGE_STDISP(REG) HAS_DYN(REG, region_manage_stdisp)
/*{{{ Stacking list stuff */
WStacking *mplex_get_stacking(WMPlex *mplex)
{
return window_get_stacking(&mplex->win);
}
WStacking **mplex_get_stackingp(WMPlex *mplex)
{
return window_get_stackingp(&mplex->win);
}
void mplex_iter_init(WMPlexIterTmp *tmp, WMPlex *mplex)
{
stacking_iter_mgr_init(tmp, mplex->mgd, NULL, mplex);
}
WRegion *mplex_iter(WMPlexIterTmp *tmp)
{
return stacking_iter_mgr(tmp);
}
WStacking *mplex_iter_nodes(WMPlexIterTmp *tmp)
{
return stacking_iter_mgr_nodes(tmp);
}
/*}}}*/
/*{{{ Destroy/create mplex */
bool mplex_do_init(WMPlex *mplex, WWindow *parent,
const WFitParams *fp, Window win, const char *name)
{
mplex->flags=0;
mplex->mx_list=NULL;
mplex->mx_current=NULL;
mplex->mx_phs=NULL;
mplex->mx_count=0;
mplex->mgd=NULL;
watch_init(&(mplex->stdispwatch));
mplex->stdispinfo.pos=MPLEX_STDISP_BL;
mplex->stdispinfo.fullsize=FALSE;
if(!window_do_init((WWindow*)mplex, parent, fp, win, name))
return FALSE;
mplex->win.region.flags|=REGION_BINDINGS_ARE_GRABBED;
window_select_input(&(mplex->win), IONCORE_EVENTMASK_CWINMGR);
region_register((WRegion*)mplex);
region_set_name((WRegion*)mplex, name);
/* Call this to set MPLEX_MANAGED_UNVIEWABLE if necessary. */
mplex_fit_managed(mplex);
return TRUE;
}
bool mplex_init(WMPlex *mplex, WWindow *parent, const WFitParams *fp, const char *name)
{
return mplex_do_init(mplex, parent, fp, None, name);
}
WMPlex *create_mplex(WWindow *parent, const WFitParams *fp, const char *name)
{
CREATEOBJ_IMPL(WMPlex, mplex, (p, parent, fp, name));
}
void mplex_deinit(WMPlex *mplex)
{
WMPlexIterTmp tmp;
WRegion *reg;
FOR_ALL_MANAGED_BY_MPLEX(mplex, reg, tmp){
destroy_obj((Obj*)reg);
}
assert(mplex->mgd==NULL);
assert(mplex->mx_list==NULL);
while(mplex->mx_phs!=NULL){
assert(mplexpholder_move(mplex->mx_phs, NULL, NULL, NULL));
}
window_deinit((WWindow*)mplex);
}
/*}}}*/
/*{{{ Node lookup etc. */
WStacking *mplex_find_stacking(WMPlex *mplex, WRegion *reg)
{
WStacking *st;
/* Some routines that call us expect us to this check. */
if(reg==NULL || REGION_MANAGER(reg)!=(WRegion*)mplex)
return NULL;
st=ioncore_find_stacking(reg);
assert(st==NULL || st->mgr_prev!=NULL);
return st;
}
WStacking *mplex_current_node(WMPlex *mplex)
{
WStacking *st=NULL;
WRegion *reg;
reg=REGION_ACTIVE_SUB(mplex);
reg=region_managed_within((WRegion*)mplex, reg);
if(reg!=NULL)
st=mplex_find_stacking(mplex, reg);
if(st!=NULL)
return st;
else
return (mplex->mx_current!=NULL ? mplex->mx_current->st : NULL);
}
WRegion *mplex_current(WMPlex *mplex)
{
WStacking *node=mplex_current_node(mplex);
return (node==NULL ? NULL : node->reg);
}
/*}}}*/
/*{{{ Exclusive list management and exports */
/*EXTL_DOC
* Returns the number of objects on the mutually exclusive list of \var{mplex}.
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
int mplex_mx_count(WMPlex *mplex)
{
return mplex->mx_count;
}
/*EXTL_DOC
* Returns the managed object currently active within the mutually exclusive
* list of \var{mplex}.
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
WRegion *mplex_mx_current(WMPlex *mplex)
{
WLListNode *lnode=mplex->mx_current;
return (lnode==NULL ? NULL : lnode->st->reg);
}
/*EXTL_DOC
* Returns the \var{n}:th object managed by \var{mplex} on the
* \var{l}:th layer.
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
WRegion *mplex_mx_nth(WMPlex *mplex, uint n)
{
WLListNode *lnode=llist_nth_node(mplex->mx_list, n);
return (lnode==NULL ? NULL : lnode->st->reg);
}
/*EXTL_DOC
* Iterate over numbered/mutually exclusive region list of \var{mplex}
* until \var{iterfn} returns \code{false}.
* The function itself returns \code{true} if it reaches the end of list
* without this happening.
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
bool mplex_mx_i(WMPlex *mplex, ExtlFn iterfn)
{
WLListIterTmp tmp;
llist_iter_init(&tmp, mplex->mx_list);
return extl_iter_objlist_(iterfn, (ObjIterator*)llist_iter_regions, &tmp);
}
/*EXTL_DOC
* Iterate over managed regions of \var{mplex} until \var{iterfn} returns
* \code{false}.
* The function itself returns \code{true} if it reaches the end of list
* without this happening.
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
bool mplex_managed_i(WMPlex *mplex, ExtlFn iterfn)
{
WMPlexIterTmp tmp;
mplex_iter_init(&tmp, mplex);
return extl_iter_objlist_(iterfn, (ObjIterator*)mplex_iter, &tmp);
}
/*EXTL_DOC
* Set index of \var{reg} to \var{index} within the mutually exclusive
* list of \var{mplex}. Special values for \var{index} are:
* \begin{tabularx}{\linewidth}{lX}
* $-1$ & Last. \\
* $-2$ & After \fnref{WMPlex.mx_current}. \\
* \end{tabularx}
*/
EXTL_EXPORT_MEMBER
void mplex_set_index(WMPlex *mplex, WRegion *reg, int index)
{
WLListNode *lnode, *after;
WStacking *node;
node=mplex_find_stacking(mplex, reg);
if(node==NULL)
return;
lnode=node->lnode;
if(lnode==NULL){
lnode=ALLOC(WLListNode);
if(lnode==NULL)
return;
lnode->next=NULL;
lnode->prev=NULL;
lnode->phs=NULL;
lnode->st=node;
node->lnode=lnode;
mplex->mx_count++;
}else{
mplex_move_phs_before(mplex, lnode);
llist_unlink(&(mplex->mx_list), lnode);
}
after=llist_index_to_after(mplex->mx_list, mplex->mx_current, index);
llist_link_after(&(mplex->mx_list), after, lnode);
mplex_managed_changed(mplex, MPLEX_CHANGE_REORDER, FALSE, reg);
}
/*EXTL_DOC
* Get index of \var{reg} on the mutually exclusive list of \var{mplex}.
* The indices begin from zero.. If \var{reg} is not on the list,
* -1 is returned.
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
int mplex_get_index(WMPlex *mplex, WRegion *reg)
{
WLListIterTmp tmp;
WLListNode *lnode;
int index=0;
FOR_ALL_NODES_ON_LLIST(lnode, mplex->mx_list, tmp){
if(reg==lnode->st->reg)
return index;
index++;
}
return -1;
}
/*EXTL_DOC
* Move \var{r} ''right'' within objects managed by \var{mplex} on list 1.
*/
EXTL_EXPORT_MEMBER
void mplex_inc_index(WMPlex *mplex, WRegion *r)
{
if(r==NULL)
r=mplex_mx_current(mplex);
if(r!=NULL)
mplex_set_index(mplex, r, mplex_get_index(mplex, r)+1);
}
/*EXTL_DOC
* Move \var{r} ''right'' within objects managed by \var{mplex} on list 1.
*/
EXTL_EXPORT_MEMBER
void mplex_dec_index(WMPlex *mplex, WRegion *r)
{
if(r==NULL)
r=mplex_mx_current(mplex);
if(r!=NULL)
mplex_set_index(mplex, r, mplex_get_index(mplex, r)-1);
}
/*}}}*/
/*{{{ Mapping */
static void mplex_map_mgd(WMPlex *mplex)
{
WMPlexIterTmp tmp;
WStacking *node;
FOR_ALL_NODES_IN_MPLEX(mplex, node, tmp){
if(!STACKING_IS_HIDDEN(node))
region_map(node->reg);
}
}
static void mplex_unmap_mgd(WMPlex *mplex)
{
WMPlexIterTmp tmp;
WStacking *node;
FOR_ALL_NODES_IN_MPLEX(mplex, node, tmp){
if(!STACKING_IS_HIDDEN(node))
region_unmap(node->reg);
}
}
void mplex_map(WMPlex *mplex)
{
window_map((WWindow*)mplex);
/* A lame requirement of the ICCCM is that client windows should be
* unmapped if the parent is unmapped.
*/
if(!MPLEX_MGD_UNVIEWABLE(mplex))
mplex_map_mgd(mplex);
}
void mplex_unmap(WMPlex *mplex)
{
window_unmap((WWindow*)mplex);
/* A lame requirement of the ICCCM is that client windows should be
* unmapped if the parent is unmapped.
*/
if(!MPLEX_MGD_UNVIEWABLE(mplex))
mplex_unmap_mgd(mplex);
}
/*}}}*/
/*{{{ Resize and reparent */
bool mplex_fitrep(WMPlex *mplex, WWindow *par, const WFitParams *fp)
{
bool wchg=(REGION_GEOM(mplex).w!=fp->g.w);
bool hchg=(REGION_GEOM(mplex).h!=fp->g.h);
window_do_fitrep(&(mplex->win), par, &(fp->g));
if(wchg || hchg){
mplex_fit_managed(mplex);
mplex_size_changed(mplex, wchg, hchg);
}
return TRUE;
}
void mplex_do_fit_managed(WMPlex *mplex, WFitParams *fp)
{
WMPlexIterTmp tmp;
WStacking *node;
WFitParams fp2;
if(!MPLEX_MGD_UNVIEWABLE(mplex) && (fp->g.w<=1 || fp->g.h<=1)){
mplex->flags|=MPLEX_MANAGED_UNVIEWABLE;
if(REGION_IS_MAPPED(mplex))
mplex_unmap_mgd(mplex);
}else if(MPLEX_MGD_UNVIEWABLE(mplex) && !(fp->g.w<=1 || fp->g.h<=1)){
mplex->flags&=~MPLEX_MANAGED_UNVIEWABLE;
if(REGION_IS_MAPPED(mplex))
mplex_map_mgd(mplex);
}
if(!MPLEX_MGD_UNVIEWABLE(mplex)){
FOR_ALL_NODES_IN_MPLEX(mplex, node, tmp){
fp2=*fp;
sizepolicy(&node->szplcy, node->reg, NULL, 0, &fp2);
region_fitrep(node->reg, NULL, &fp2);
}
}
}
void mplex_fit_managed(WMPlex *mplex)
{
WFitParams fp;
fp.mode=REGION_FIT_EXACT;
mplex_managed_geom(mplex, &(fp.g));
mplex_do_fit_managed(mplex, &fp);
}
static void mplex_managed_rqgeom(WMPlex *mplex, WRegion *sub,
const WRQGeomParams *rq,
WRectangle *geomret)
{
WFitParams fp;
WStacking *node;
node=mplex_find_stacking(mplex, sub);
assert(node!=NULL);
mplex_managed_geom(mplex, &fp.g);
sizepolicy(&node->szplcy, sub, &rq->geom, rq->flags, &fp);
if(geomret!=NULL)
*geomret=fp.g;
if(!(rq->flags®ION_RQGEOM_TRYONLY))
region_fitrep(sub, NULL, &fp);
}
/*}}}*/
/*{{{ Focus */
static WStacking *mplex_do_to_focus(WMPlex *mplex, WStacking *to_try)
{
WStacking *stacking=mplex_get_stacking(mplex);
WStacking *st=NULL;
if(stacking==NULL)
return NULL;
if(to_try!=NULL && (to_try->reg==NULL || !REGION_IS_MAPPED(to_try->reg)))
to_try=NULL;
st=stacking_find_to_focus_mapped(stacking, to_try, NULL);
if(st!=NULL)
return st;
else if(mplex->mx_current!=NULL)
return mplex->mx_current->st;
else
return NULL;
}
static WStacking *maybe_focusable(WRegion *reg)
{
if(reg==NULL || !REGION_IS_MAPPED(reg))
return NULL;
return ioncore_find_stacking(reg);
}
static WStacking *stacking_within(WMPlex *mplex, WRegion *reg)
{
while(reg!=NULL && REGION_MANAGER(reg)!=(WRegion*)mplex)
reg=REGION_MANAGER(reg);
return maybe_focusable(reg);
}
static WStacking *mplex_to_focus(WMPlex *mplex)
{
WStacking *to_try=NULL;
WRegion *reg=NULL;
to_try=maybe_focusable(REGION_ACTIVE_SUB(mplex));
if(to_try==NULL){
/* Search focus history */
for(reg=ioncore_g.focus_current; reg!=NULL; reg=reg->active_next){
to_try=stacking_within(mplex, reg);
if(to_try!=NULL)
break;
}
}
return mplex_do_to_focus(mplex, to_try);
}
static WStacking *mplex_do_to_focus_on(WMPlex *mplex, WStacking *node,
WStacking *to_try)
{
WStacking *stacking=mplex_get_stacking(mplex);
if(stacking==NULL)
return NULL;
if(to_try!=NULL && (to_try->reg==NULL || !REGION_IS_MAPPED(to_try->reg)))
to_try=NULL;
return stacking_find_to_focus_mapped(stacking, to_try, node->reg);
}
static WStacking *mplex_to_focus_on(WMPlex *mplex, WStacking *node,
WStacking *to_try)
{
WGroup *grp=OBJ_CAST(node->reg, WGroup);
WStacking *st;
if(grp!=NULL){
if(to_try==NULL)
to_try=grp->current_managed;
st=mplex_do_to_focus_on(mplex, node, to_try);
if(st!=NULL || to_try!=NULL)
return st;
/* We don't know whether something is blocking focus here,
* or if there was nothing to focus (as node->reg itself
* isn't on the stacking list).
*/
}
st=mplex_do_to_focus(mplex, node);
return (st==node ? st : NULL);
}
void mplex_do_set_focus(WMPlex *mplex, bool warp)
{
if(!MPLEX_MGD_UNVIEWABLE(mplex)){
WStacking *st=mplex_to_focus(mplex);
if(st!=NULL){
region_do_set_focus(st->reg, warp);
return;
}
}
window_do_set_focus((WWindow*)mplex, warp);
}
/*}}}*/
/*{{{ Switch */
static void mplex_do_remanage_stdisp(WMPlex *mplex, WRegion *sub)
{
WRegion *stdisp=(WRegion*)(mplex->stdispwatch.obj);
/* Move stdisp */
if(sub!=NULL && CAN_MANAGE_STDISP(sub)){
if(stdisp!=NULL){
WRegion *omgr=REGION_MANAGER(stdisp);
if(omgr!=sub && omgr!=NULL){
if(CAN_MANAGE_STDISP(omgr))
region_unmanage_stdisp(omgr, FALSE, FALSE);
region_detach_manager(stdisp);
}
region_manage_stdisp(sub, stdisp,
&(mplex->stdispinfo));
}else{
region_unmanage_stdisp(sub, TRUE, FALSE);
}
}
}
void mplex_remanage_stdisp(WMPlex *mplex)
{
mplex_do_remanage_stdisp(mplex, (mplex->mx_current!=NULL
? mplex->mx_current->st->reg
: NULL));
}
static void mplex_do_node_display(WMPlex *mplex, WStacking *node,
bool call_changed)
{
WRegion *sub=node->reg;
WLListNode *mxc=mplex->mx_current;
WFitParams fp;
if(!STACKING_IS_HIDDEN(node))
return;
if(node->lnode!=NULL && node->lnode!=mxc)
mplex_do_remanage_stdisp(mplex, sub);
node->hidden=FALSE;
if(SUBS_MAY_BE_MAPPED(mplex))
region_map(sub);
else
region_unmap(sub);
/* the mplex might have been resized while this window was invisible,
* and the client window might have had lazy resizing enabled.
*/
fp.mode=REGION_FIT_EXACT;
mplex_managed_geom(mplex, &(fp.g));
sizepolicy(&node->szplcy, node->reg, NULL, 0, &fp);
region_fitrep(node->reg, NULL, &fp);
if(node->lnode!=NULL){
if(mxc!=NULL){
/* Hide current mx region. We do it after mapping the
* new one to avoid flicker.
*/
if(REGION_IS_MAPPED(mplex))
region_unmap(mxc->st->reg);
mxc->st->hidden=TRUE;
}
mplex->mx_current=node->lnode;
/* Ugly hack:
* Many programs will get upset if the visible, although only
* such, client window is not the lowest window in the mplex.
* xprop/xwininfo will return the information for the lowest
* window. 'netscape -remote' will not work at all if there are
* no visible netscape windows.
*/
{
WGroup *grp=(WGroup*)OBJ_CAST(sub, WGroupCW);
if(grp!=NULL){
WRegion *bottom=group_bottom(grp);
if(bottom!=NULL){
region_managed_rqorder((WRegion*)grp, bottom,
REGION_ORDER_BACK);
}
}
}
if(call_changed)
mplex_managed_changed(mplex, MPLEX_CHANGE_SWITCHONLY, TRUE, sub);
}
}
static bool mplex_refocus(WMPlex *mplex, WStacking *node, bool warp)
{
WStacking *foc=NULL;
bool ret=TRUE;
if(node!=NULL){
foc=mplex_to_focus_on(mplex, node, NULL);
ret=(foc!=NULL);
}
if(foc==NULL){
ret=FALSE;
foc=mplex_to_focus(mplex);
}
if(foc!=NULL)
region_maybewarp(foc->reg, warp);
return ret;
}
bool mplex_do_prepare_focus(WMPlex *mplex, WStacking *node,
WStacking *sub, int flags,
WPrepareFocusResult *res)
{
WStacking *foc;
if(sub==NULL && node==NULL)
return FALSE;
/* Display the node in any case */
if(node!=NULL && !(flags®ION_GOTO_ENTERWINDOW))
mplex_do_node_display(mplex, node, TRUE);
if(!region_prepare_focus((WRegion*)mplex, flags, res))
return FALSE;
if(node!=NULL)
foc=mplex_to_focus_on(mplex, node, sub);
else
foc=mplex_do_to_focus(mplex, sub);
if(foc!=NULL){
if(ioncore_g.autoraise &&
!(flags®ION_GOTO_ENTERWINDOW) &&
foc->level>STACKING_LEVEL_BOTTOM){
WStacking **stackingp=mplex_get_stackingp(mplex);
stacking_restack(stackingp, foc, None, NULL, NULL, FALSE);
}
res->reg=foc->reg;
res->flags=flags;
if(sub==NULL)
return (foc==node);
else
return (foc==sub);
}else{
return FALSE;
}
}
bool mplex_managed_prepare_focus(WMPlex *mplex, WRegion *disp,
int flags, WPrepareFocusResult *res)
{
WStacking *node=mplex_find_stacking(mplex, disp);
if(node==NULL)
return FALSE;
else
return mplex_do_prepare_focus(mplex, node, NULL, flags, res);
}
/*}}}*/
/*{{{ Switch exports */
static void do_switch(WMPlex *mplex, WLListNode *lnode)
{
WStacking *node=(lnode!=NULL ? lnode->st : NULL);
if(node!=NULL){
bool mcf=region_may_control_focus((WRegion*)mplex);
mplex_do_node_display(mplex, node, TRUE);
if(mcf)
mplex_refocus(mplex, node, TRUE);
}
}
/*EXTL_DOC
* Have \var{mplex} display the \var{n}:th object managed by it.
*/
EXTL_EXPORT_MEMBER
void mplex_switch_nth(WMPlex *mplex, uint n)
{
do_switch(mplex, llist_nth_node(mplex->mx_list, n));
}
/*EXTL_DOC
* Have \var{mplex} display next (wrt. currently selected) object managed
* by it.
*/
EXTL_EXPORT_MEMBER
void mplex_switch_next(WMPlex *mplex)
{
do_switch(mplex, LIST_NEXT_WRAP(mplex->mx_list, mplex->mx_current,
next, prev));
}
/*EXTL_DOC
* Have \var{mplex} display previous (wrt. currently selected) object
* managed by it.
*/
EXTL_EXPORT_MEMBER
void mplex_switch_prev(WMPlex *mplex)
{
do_switch(mplex, LIST_PREV_WRAP(mplex->mx_list, mplex->mx_current,
next, prev));
}
/*EXTL_DOC
* Have \var{mplex} display the given child window already added to the mplex
*/
EXTL_EXPORT_MEMBER
void mplex_switch_to(WMPlex *mplex, WRegion *reg)
{
WPrepareFocusResult result;
mplex_managed_prepare_focus(mplex, reg->manager, 0, &result);
}
bool mplex_set_hidden(WMPlex *mplex, WRegion *reg, int sp)
{
bool mcf=region_may_control_focus((WRegion*)mplex);
WStacking *node=mplex_find_stacking(mplex, reg);
bool hidden, nhidden;
if(node==NULL)
return FALSE;
hidden=STACKING_IS_HIDDEN(node);
nhidden=libtu_do_setparam(sp, hidden);
if(!hidden && nhidden){
node->hidden=TRUE;
if(REGION_IS_MAPPED(mplex) && !MPLEX_MGD_UNVIEWABLE(mplex))
region_unmap(reg);
/* lnode -> switch next? */
}else if(hidden && !nhidden){
mplex_do_node_display(mplex, node, TRUE);
}
if(mcf && !PASSIVE(node))
mplex_refocus(mplex, (nhidden ? NULL : node), TRUE);
return STACKING_IS_HIDDEN(node);
}
/*EXTL_DOC
* Set the visibility of the region \var{reg} on \var{mplex}
* as specified with the parameter \var{how} (set/unset/toggle).
* The resulting state is returned.
*/
EXTL_EXPORT_AS(WMPlex, set_hidden)
bool mplex_set_hidden_extl(WMPlex *mplex, WRegion *reg, const char *how)
{
return mplex_set_hidden(mplex, reg, libtu_string_to_setparam(how));
}
/*EXTL_DOC
* Is \var{reg} on within \var{mplex} and hidden?
*/
EXTL_SAFE
EXTL_EXPORT_MEMBER
bool mplex_is_hidden(WMPlex *mplex, WRegion *reg)
{
WStacking *node=mplex_find_stacking(mplex, reg);
return (node!=NULL && STACKING_IS_HIDDEN(node));
}
/*}}}*/
/*{{{ Navigation */
static WStacking *mplex_nxt(WMPlex *mplex, WStacking *st, bool wrap)
{
return (st->mgr_next!=NULL
? st->mgr_next
: (wrap ? mplex->mgd : NULL));
}
static WStacking *mplex_prv(WMPlex *mplex, WStacking *st, bool wrap)
{
return (st!=mplex->mgd
? st->mgr_prev
: (wrap ? st->mgr_prev : NULL));
}
typedef WStacking *NxtFn(WMPlex *mplex, WStacking *st, bool wrap);
static WRegion *do_navi(WMPlex *mplex, WStacking *sti,
NxtFn *fn, WRegionNaviData *data,
bool sti_ok, bool wrap)
{
WStacking *st, *stacking;
uint min_level=0;
stacking=mplex_get_stacking(mplex);
if(stacking!=NULL)
min_level=stacking_min_level_mapped(stacking);
st=sti;
while(1){
st=fn(mplex, st, wrap);
if(st==NULL || (st==sti && !sti_ok))
break;
if(!st->hidden){
if(OBJ_IS(st->reg, WGroup)){
/* WGroup navigation code should respect modal stuff. */
WRegion *res=region_navi_cont((WRegion*)mplex, st->reg, data);
if(res!=NULL && res!=st->reg)
return res;
}else{
if(st->level>=min_level && !PASSIVE(st))
return region_navi_cont((WRegion*)mplex, st->reg, data);
}
}
if(st==sti)
break;
}
return NULL;
}
WRegion *mplex_navi_first(WMPlex *mplex, WRegionNavi nh,
WRegionNaviData *data)
{
WStacking *lst=mplex->mgd;
WRegion *res=NULL;
if(lst!=NULL){
if(nh==REGION_NAVI_ANY){
/* ? */
}
if(nh==REGION_NAVI_ANY || nh==REGION_NAVI_END ||
nh==REGION_NAVI_BOTTOM || nh==REGION_NAVI_RIGHT){