Include mod_xrandr instead of using submodules
[notion/jeffpc.git] / ioncore / return.c
blobffc108375900b6880061f2523eef8b2402627814
1 /*
2 * ion/ioncore/return.h
4 * Copyright (c) Tuomo Valkonen 1999-2009.
6 * See the included file LICENSE for details.
7 */
9 #include <libtu/rb.h>
10 #include <libmainloop/defer.h>
12 #include "common.h"
13 #include "global.h"
14 #include "region.h"
15 #include "pholder.h"
16 #include "return.h"
19 /*{{{ Storage tree */
22 static Rb_node retrb=NULL;
25 /*}}}*/
29 /*{{{ Set */
32 bool region_do_set_return(WRegion *reg, WPHolder *ph)
34 Rb_node node;
35 int found=0;
37 assert(!OBJ_IS_BEING_DESTROYED(reg));
39 region_unset_return(reg);
41 if(retrb==NULL){
42 retrb=make_rb();
43 if(retrb==NULL)
44 return FALSE;
47 node=rb_insertp(retrb, reg, ph);
49 region_notify_change(reg, ioncore_g.notifies.set_return);
51 return (node!=NULL);
55 WPHolder *region_make_return_pholder(WRegion *reg)
57 WRegion *mgr=region_manager(reg);
59 if(mgr==NULL)
60 return NULL;
62 return region_managed_get_pholder(mgr, reg);
67 extern WPHolder *region_set_return(WRegion *reg)
69 WPHolder *ph=region_make_return_pholder(reg);
71 if(ph!=NULL){
72 if(region_do_set_return(reg, ph))
73 return ph;
74 destroy_obj((Obj*)ph);
77 return NULL;
82 /*}}}*/
85 /*{{{ Get */
87 Rb_node do_find(WRegion *reg)
89 int found=0;
90 Rb_node node;
92 if(retrb==NULL)
93 return NULL;
95 node=rb_find_pkey_n(retrb, reg, &found);
97 return (found ? node : NULL);
101 WPHolder *region_do_get_return(WRegion *reg)
103 Rb_node node=do_find(reg);
105 return (node!=NULL ? (WPHolder*)node->v.val : NULL);
109 WPHolder *region_get_return(WRegion *reg)
111 /* Should managers be scanned? */
112 return region_do_get_return(reg);
116 /*}}}*/
119 /*{{{ Unset */
122 static WPHolder *do_remove_node(Rb_node node)
124 WPHolder *ph=(WPHolder*)node->v.val;
126 rb_delete_node(node);
128 return ph;
132 WPHolder *region_unset_get_return(WRegion *reg)
134 Rb_node node;
136 node=do_find(reg);
138 if(node!=NULL){
139 region_notify_change(reg, ioncore_g.notifies.unset_return);
140 return do_remove_node(node);
141 }else{
142 return NULL;
147 void region_unset_return(WRegion *reg)
149 WPHolder *ph=region_unset_get_return(reg);
151 if(ph!=NULL)
152 mainloop_defer_destroy((Obj*)ph);
156 /*}}}*/
159 /*{{{ Internal Lua exports */
162 EXTL_SAFE
163 EXTL_EXPORT_MEMBER
164 WRegion *region___return_target(WRegion *reg)
166 WPHolder *ph=region_get_return(reg);
167 return (ph!=NULL ? pholder_target(ph) : NULL);
171 /*}}}*/