2 * ion/ioncore/activity.c
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
9 #include <libtu/setparam.h>
10 #include <libtu/minmax.h>
11 #include <libtu/objlist.h>
18 static ObjList
*actlist
=NULL
;
21 void region_mark_mgd_activity(WRegion
*mgr
)
28 mgr_marked
=region_is_activity_r(mgr
);
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
)
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
®ION_ACTIVITY
);
67 bool nset
=libtu_do_setparam(sp
, set
);
73 if(REGION_IS_ACTIVE(reg
))
76 reg
->flags
|=REGION_ACTIVITY
;
77 objlist_insert_last(&actlist
, (Obj
*)reg
);
79 if(reg
->mgd_activity
==0)
80 propagate_activity(reg
);
82 reg
->flags
&=~REGION_ACTIVITY
;
83 objlist_remove(&actlist
, (Obj
*)reg
);
85 if(reg
->mgd_activity
==0)
89 region_notify_change(reg
, ioncore_g
.notifies
.activity
);
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
));
107 * Is activity notification set on \var{reg}.
111 bool region_is_activity(WRegion
*reg
)
113 return (reg
->flags
®ION_ACTIVITY
);
117 bool region_is_activity_r(WRegion
*reg
)
119 return (reg
->flags
®ION_ACTIVITY
|| reg
->mgd_activity
!=0);
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.
131 bool ioncore_activity_i(ExtlFn iterfn
)
133 return extl_iter_objlist(iterfn
, actlist
);
138 * Returns first region on activity list.
142 WRegion
*ioncore_activity_first()
146 return (WRegion
*)actlist
->watch
.obj
;
150 ObjList
*ioncore_activity_list()
157 * Go to first region on activity list.
160 bool ioncore_goto_activity()
162 WRegion
*reg
=ioncore_activity_first();
165 return region_goto(reg
);