2 * ion/ioncore/activity.c
4 * Copyright (c) Tuomo Valkonen 1999-2007.
6 * Ion is free software; you can redistribute it and/or modify it under
7 * the terms of the GNU Lesser General Public License as published by
8 * the Free Software Foundation; either version 2.1 of the License, or
9 * (at your option) any later version.
12 #include <libtu/setparam.h>
13 #include <libtu/minmax.h>
14 #include <libtu/objlist.h>
21 static ObjList *actlist=NULL;
24 void region_mark_mgd_activity(WRegion *mgr)
31 mgr_marked=region_is_activity_r(mgr);
35 region_notify_change(mgr, ioncore_g.notifies.sub_activity);
36 region_mark_mgd_activity(REGION_MANAGER(mgr));
41 void region_clear_mgd_activity(WRegion *mgr)
46 mgr->mgd_activity=maxof(0, mgr->mgd_activity-1);
48 if(!region_is_activity_r(mgr)){
49 region_notify_change(mgr, ioncore_g.notifies.sub_activity);
50 region_clear_mgd_activity(REGION_MANAGER(mgr));
55 static void propagate_activity(WRegion *reg)
57 region_mark_mgd_activity(REGION_MANAGER(reg));
61 static void propagate_clear(WRegion *reg)
63 region_clear_mgd_activity(REGION_MANAGER(reg));
67 bool region_set_activity(WRegion *reg, int sp)
69 bool set=(reg->flags®ION_ACTIVITY);
70 bool nset=libtu_do_setparam(sp, set);
76 if(REGION_IS_ACTIVE(reg))
79 reg->flags|=REGION_ACTIVITY;
80 objlist_insert_last(&actlist, (Obj*)reg);
82 if(reg->mgd_activity==0)
83 propagate_activity(reg);
85 reg->flags&=~REGION_ACTIVITY;
86 objlist_remove(&actlist, (Obj*)reg);
88 if(reg->mgd_activity==0)
92 region_notify_change(reg, ioncore_g.notifies.activity);
99 * Set activity flag of \var{reg}. The \var{how} parameter most be
100 * one of (set/unset/toggle).
102 EXTL_EXPORT_AS(WRegion, set_activity)
103 bool region_set_activity_extl(WRegion *reg, const char *how)
105 return region_set_activity(reg, libtu_string_to_setparam(how));
110 * Is activity notification set on \var{reg}.
114 bool region_is_activity(WRegion *reg)
116 return (reg->flags®ION_ACTIVITY);
120 bool region_is_activity_r(WRegion *reg)
122 return (reg->flags®ION_ACTIVITY || reg->mgd_activity!=0);
127 * Iterate over activity list until \var{iterfn} returns \code{false}.
128 * The function itself returns \code{true} if it reaches the end of list
129 * without this happening.
133 bool ioncore_activity_i(ExtlFn iterfn)
135 return extl_iter_objlist(iterfn, actlist);
140 * Return first regio non activity list.
144 WRegion *ioncore_activity_first()
148 return (WRegion*)actlist->watch.obj;
152 ObjList *ioncore_activity_list()
159 * Go to first region on activity list.
162 bool ioncore_goto_activity()
164 WRegion *reg=ioncore_activity_first();
167 return region_goto(reg);