File: ops.c

package info (click to toggle)
notion 4.0.2%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 4,676 kB
  • sloc: ansic: 47,508; sh: 2,096; makefile: 603; perl: 270
file content (163 lines) | stat: -rw-r--r-- 3,660 bytes parent folder | download | duplicates (2)
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
/*
 * ion/mod_tiling/ops.c
 *
 * Copyright (c) Tuomo Valkonen 1999-2007.
 *
 * See the included file LICENSE for details.
 */

#include <libtu/objp.h>
#include <ioncore/common.h>
#include <ioncore/mplex.h>
#include <ioncore/focus.h>
#include <ioncore/return.h>
#include <ioncore/group.h>
#include "tiling.h"


/*{{{ mkbottom */


static WRegion *mkbottom_fn(WWindow *parent, const WFitParams *fp,
                            void *param)
{
    WRegion *reg=(WRegion*)param, *res;
    WRegionAttachData data;
    WTiling *tiling;
    WFitParams fp2;

    fp2.mode=REGION_FIT_EXACT;
    fp2.g=fp->g;

    tiling=create_tiling(parent, &fp2, NULL, FALSE);

    if(tiling==NULL)
        return NULL;

    data.type=REGION_ATTACH_REPARENT;
    data.u.reg=reg;

    /* Warning! Potentially dangerous call to remove a `reg` from the same
     * group we're being attached to, and from the attach routine of which
     * this function is called from!
     */
    res=region_attach_helper((WRegion*)tiling, parent, &fp2,
                             (WRegionDoAttachFn*)tiling_do_attach_initial,
                             NULL, &data);

    if(res==NULL){
        destroy_obj((Obj*)tiling);
        return NULL;
    }

    return (WRegion*)tiling;
}


/*EXTL_DOC
 * Create a new \type{WTiling} 'bottom' for the group of \var{reg},
 * consisting of \var{reg}.
 */
EXTL_EXPORT
bool mod_tiling_mkbottom(WRegion *reg)
{
    WGroup *grp=REGION_MANAGER_CHK(reg, WGroup);
    WGroupAttachParams ap=GROUPATTACHPARAMS_INIT;
    WRegionAttachData data;

    if(grp==NULL){
        warn(TR("Not member of a group"));
        return FALSE;
    }

    if(group_bottom(grp)!=NULL){
        warn(TR("Manager group already has bottom"));
        return FALSE;
    }

    ap.level_set=TRUE;
    ap.level=STACKING_LEVEL_BOTTOM;

    ap.szplcy_set=TRUE;
    ap.szplcy=SIZEPOLICY_FULL_EXACT;

    ap.switchto_set=TRUE;
    ap.switchto=region_may_control_focus(reg);

    ap.bottom=TRUE;

    data.type=REGION_ATTACH_NEW;
    data.u.n.fn=mkbottom_fn;
    data.u.n.param=reg;

    /* See the "Warning!" above. */
    return (group_do_attach(grp, &ap, &data)!=NULL);
}


/*}}}*/


/*{{{ untile */


/*EXTL_DOC
 * If \var{tiling} is managed by some group, float the frames in
 * the tiling in that group, and dispose of \var{tiling}.
 */
EXTL_EXPORT
bool mod_tiling_untile(WTiling *tiling)
{
    WGroup *grp=REGION_MANAGER_CHK(tiling, WGroup);
    WGroupAttachParams param=GROUPATTACHPARAMS_INIT;
    WTilingIterTmp tmp;
    WRegion *reg, *reg2;

    if(grp==NULL){
        warn(TR("Not member of a group"));
        return FALSE;
    }

    if(group_bottom(grp)==(WRegion*)tiling)
        group_set_bottom(grp, NULL);

    /* Setting `batchop` will stop `tiling_managed_remove` from
     * resizing remaining frames into freed space. It will also
     * stop the tiling from being destroyed by actions of
     * `tiling_managed_disposeroot`.
     */
    tiling->batchop=TRUE;

    FOR_ALL_MANAGED_BY_TILING(reg, tiling, tmp){
        WRegionAttachData data;

        /* Don't bother with the status display */
        if(reg==TILING_STDISP_OF(tiling))
            continue;

        /* Don't bother with regions containing no client windows. */
        if(!region_rescue_needed(reg))
            continue;

        data.type=REGION_ATTACH_REPARENT;
        data.u.reg=reg;

        param.geom_set=TRUE;
        param.geom=REGION_GEOM(reg);

        reg2=group_do_attach(grp, &param, &data);

        if(reg2==NULL)
            warn(TR("Unable to move a region from tiling to group."));
    }

    tiling->batchop=FALSE;

    region_dispose((WRegion*)tiling);

    return TRUE;
}


/*}}}*/