11 void (*mouse_in
)( int );
12 void (*mouse_out
)( int );
13 void (*mouse_click
)( int, unsigned int );
18 struct regioned_window
21 struct region
*first_reg
;
22 struct regioned_window
*next
;
26 static struct regioned_window
*regioned_windows
=NULL
;
27 static Display
*dpy
=NULL
;
30 static struct region
*region_locate( Window win
, int x
, int y
);
31 static struct region
*region_find( Window win
, int id
);
32 static struct regioned_window
*region_get_win( Window win
);
34 void region_init( Display
*_dpy
)
39 void region_add( Window win
, int id
, int x
, int y
, int w
, int h
,
40 void (*mouse_in
)(int), void (*mouse_out
)(int), void (*mouse_click
)(int, unsigned int) )
42 /* cerate the region and set its fields */
43 struct region
*reg
= new region
;
50 reg
->mouse_in
= mouse_in
;
51 reg
->mouse_out
= mouse_out
;
52 reg
->mouse_click
= mouse_click
;
54 /* find the regioned_win and insert the new region into its list of regions */
55 struct regioned_window
*reg_win
= region_get_win(win
);
56 reg
->next
= reg_win
->first_reg
;
57 reg_win
->first_reg
= reg
;
60 void region_enable( Window win
, int id
)
62 struct region
*reg
= region_find( win
, id
);
67 void region_disable( Window win
, int id
)
69 struct region
*reg
= region_find( win
, id
);
75 bool region_in( Window win
, int x
, int y
)
77 return (region_locate(win
,x
,y
) != NULL
);
80 void region_mouse_motion( Window win
, int x
, int y
)
83 static struct region
*last_active_reg
=NULL
;
84 reg
= region_locate( win
, x
, y
);
85 if( reg
== last_active_reg
)
87 if( last_active_reg
!= NULL
)
89 last_active_reg
->mouse_out( last_active_reg
->id
);
90 XUngrabPointer( dpy
, CurrentTime
);
94 reg
->mouse_in( reg
->id
) ;
95 XGrabPointer( dpy
, win
, true, PointerMotionMask
|ButtonPress
, GrabModeAsync
, GrabModeAsync
, None
, None
, CurrentTime
);
97 last_active_reg
= reg
;
100 void region_mouse_click( Window win
, int x
, int y
, unsigned int button
)
103 region_mouse_motion( win
, x
, y
);
104 if( (reg
=region_locate(win
,x
,y
)) != NULL
)
105 reg
->mouse_click(reg
->id
, button
);
108 static struct region
*region_locate( Window win
, int x
, int y
)
110 struct region
*reg
= region_get_win(win
)->first_reg
;
114 if( (x
>= reg
->x
) && (x
<= reg
->x
+reg
->w
) &&
115 (y
>= reg
->y
) && (y
<= reg
->y
+reg
->h
) &&
123 static struct region
*region_find( Window win
, int id
)
125 struct region
*reg
= region_get_win(win
)->first_reg
;
136 static struct regioned_window
*region_get_win( Window win
)
138 struct regioned_window
*reg_win
= regioned_windows
;
140 while( reg_win
!= NULL
)
142 if( reg_win
->win
== win
)
144 reg_win
= reg_win
->next
;
147 reg_win
= new regioned_window
;
149 reg_win
->first_reg
= NULL
;
150 reg_win
->next
= regioned_windows
;
151 regioned_windows
= reg_win
;