Compile warning
[notion/jeffpc.git] / ioncore / activity.c
blob1beddba7804e129b81805a4c5d157d2d986157b7
1 /*
2 * ion/ioncore/activity.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <libtu/setparam.h>
10 #include <libtu/minmax.h>
11 #include <libtu/objlist.h>
12 #include "common.h"
13 #include "global.h"
14 #include "region.h"
15 #include "activity.h"
18 static ObjList *actlist=NULL;
21 void region_mark_mgd_activity(WRegion *mgr)
23 bool mgr_marked;
25 if(mgr==NULL)
26 return;
28 mgr_marked=region_is_activity_r(mgr);
29 mgr->mgd_activity++;
31 if(!mgr_marked){
32 region_notify_change(mgr, ioncore_g.notifies.sub_activity);
33 region_mark_mgd_activity(REGION_MANAGER(mgr));
38 void region_clear_mgd_activity(WRegion *mgr)
40 if(mgr==NULL)
41 return;
43 mgr->mgd_activity=maxof(0, mgr->mgd_activity-1);
45 if(!region_is_activity_r(mgr)){
46 region_notify_change(mgr, ioncore_g.notifies.sub_activity);
47 region_clear_mgd_activity(REGION_MANAGER(mgr));
52 static void propagate_activity(WRegion *reg)
54 region_mark_mgd_activity(REGION_MANAGER(reg));
58 static void propagate_clear(WRegion *reg)
60 region_clear_mgd_activity(REGION_MANAGER(reg));
64 bool region_set_activity(WRegion *reg, int sp)
66 bool set=(reg->flags&REGION_ACTIVITY);
67 bool nset=libtu_do_setparam(sp, set);
69 if(!XOR(set, nset))
70 return nset;
72 if(nset){
73 if(REGION_IS_ACTIVE(reg))
74 return FALSE;
76 reg->flags|=REGION_ACTIVITY;
77 objlist_insert_last(&actlist, (Obj*)reg);
79 if(reg->mgd_activity==0)
80 propagate_activity(reg);
81 }else{
82 reg->flags&=~REGION_ACTIVITY;
83 objlist_remove(&actlist, (Obj*)reg);
85 if(reg->mgd_activity==0)
86 propagate_clear(reg);
89 region_notify_change(reg, ioncore_g.notifies.activity);
91 return nset;
95 /*EXTL_DOC
96 * Set activity flag of \var{reg}. The \var{how} parameter must be
97 * one of \codestr{set}, \codestr{unset} or \codestr{toggle}.
99 EXTL_EXPORT_AS(WRegion, set_activity)
100 bool region_set_activity_extl(WRegion *reg, const char *how)
102 return region_set_activity(reg, libtu_string_to_setparam(how));
106 /*EXTL_DOC
107 * Is activity notification set on \var{reg}.
109 EXTL_SAFE
110 EXTL_EXPORT_MEMBER
111 bool region_is_activity(WRegion *reg)
113 return (reg->flags&REGION_ACTIVITY);
117 bool region_is_activity_r(WRegion *reg)
119 return (reg->flags&REGION_ACTIVITY || reg->mgd_activity!=0);
123 /*EXTL_DOC
124 * Iterate over activity list until \var{iterfn} returns \code{false}.
125 * The function is called in protected mode.
126 * This routine returns \code{true} if it reaches the end of list
127 * without this happening.
129 EXTL_SAFE
130 EXTL_EXPORT
131 bool ioncore_activity_i(ExtlFn iterfn)
133 return extl_iter_objlist(iterfn, actlist);
137 /*EXTL_DOC
138 * Returns first region on activity list.
140 EXTL_SAFE
141 EXTL_EXPORT
142 WRegion *ioncore_activity_first()
144 if(actlist==NULL)
145 return NULL;
146 return (WRegion*)actlist->watch.obj;
150 ObjList *ioncore_activity_list()
152 return actlist;
156 /*EXTL_DOC
157 * Go to first region on activity list.
159 EXTL_EXPORT
160 bool ioncore_goto_activity()
162 WRegion *reg=ioncore_activity_first();
164 if(reg!=NULL)
165 return region_goto(reg);
166 else
167 return FALSE;