File: activity.c

package info (click to toggle)
notion 4.0.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 4,656 kB
  • sloc: ansic: 47,365; sh: 2,093; makefile: 594; perl: 270
file content (168 lines) | stat: -rw-r--r-- 3,183 bytes parent folder | download | duplicates (3)
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
/*
 * ion/ioncore/activity.c
 *
 * Copyright (c) Tuomo Valkonen 1999-2007.
 *
 * See the included file LICENSE for details.
 */

#include <libtu/setparam.h>
#include <libtu/minmax.h>
#include <libtu/objlist.h>
#include "common.h"
#include "global.h"
#include "region.h"
#include "activity.h"


static ObjList *actlist=NULL;


void region_mark_mgd_activity(WRegion *mgr)
{
    bool mgr_marked;

    if(mgr==NULL)
        return;

    mgr_marked=region_is_activity_r(mgr);
    mgr->mgd_activity++;

    if(!mgr_marked){
        region_notify_change(mgr, ioncore_g.notifies.sub_activity);
        region_mark_mgd_activity(REGION_MANAGER(mgr));
    }
}


void region_clear_mgd_activity(WRegion *mgr)
{
    if(mgr==NULL)
        return;

    mgr->mgd_activity=MAXOF(0, mgr->mgd_activity-1);

    if(!region_is_activity_r(mgr)){
        region_notify_change(mgr, ioncore_g.notifies.sub_activity);
        region_clear_mgd_activity(REGION_MANAGER(mgr));
    }
}


static void propagate_activity(WRegion *reg)
{
    region_mark_mgd_activity(REGION_MANAGER(reg));
}


static void propagate_clear(WRegion *reg)
{
    region_clear_mgd_activity(REGION_MANAGER(reg));
}


bool region_set_activity(WRegion *reg, int sp)
{
    bool set=(reg->flags&REGION_ACTIVITY);
    bool nset=libtu_do_setparam(sp, set);

    if(!XOR(set, nset))
        return nset;

    if(nset){
        if(REGION_IS_ACTIVE(reg))
            return FALSE;

        reg->flags|=REGION_ACTIVITY;
        objlist_insert_last(&actlist, (Obj*)reg);

        if(reg->mgd_activity==0)
            propagate_activity(reg);
    }else{
        reg->flags&=~REGION_ACTIVITY;
        objlist_remove(&actlist, (Obj*)reg);

        if(reg->mgd_activity==0)
            propagate_clear(reg);
    }

    region_notify_change(reg, ioncore_g.notifies.activity);

    return nset;
}


/*EXTL_DOC
 * Set activity flag of \var{reg}. The \var{how} parameter most be
 * one of (set/unset/toggle).
 */
EXTL_EXPORT_AS(WRegion, set_activity)
bool region_set_activity_extl(WRegion *reg, const char *how)
{
    return region_set_activity(reg, libtu_string_to_setparam(how));
}


/*EXTL_DOC
 * Is activity notification set on \var{reg}.
 */
EXTL_SAFE
EXTL_EXPORT_MEMBER
bool region_is_activity(WRegion *reg)
{
    return (reg->flags&REGION_ACTIVITY);
}


bool region_is_activity_r(WRegion *reg)
{
    return (reg->flags&REGION_ACTIVITY || reg->mgd_activity!=0);
}


/*EXTL_DOC
 * Iterate over activity list 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
bool ioncore_activity_i(ExtlFn iterfn)
{
    return extl_iter_objlist(iterfn, actlist);
}


/*EXTL_DOC
 * Return first regio non activity list.
 */
EXTL_SAFE
EXTL_EXPORT
WRegion *ioncore_activity_first()
{
    if(actlist==NULL)
        return NULL;
    return (WRegion*)actlist->watch.obj;
}


ObjList *ioncore_activity_list()
{
    return actlist;
}


/*EXTL_DOC
 * Go to first region on activity list.
 */
EXTL_EXPORT
bool ioncore_goto_activity()
{
    WRegion *reg=ioncore_activity_first();

    if(reg!=NULL)
        return region_goto(reg);
    else
        return FALSE;
}