5 #include "render/render.h"
6 #include "render/theme.h"
27 Popup
*popup_new(gboolean hasicon
)
29 Popup
*self
= g_new(Popup
, 1);
30 self
->obwin
.type
= Window_Internal
;
31 self
->hasicon
= hasicon
;
34 self
->gravity
= NorthWestGravity
;
35 self
->x
= self
->y
= self
->w
= self
->h
= 0;
37 stacking_add(INTERNAL_AS_WINDOW(self
));
38 stacking_raise(INTERNAL_AS_WINDOW(self
));
42 void popup_free(Popup
*self
)
45 XDestroyWindow(ob_display
, self
->bg
);
46 XDestroyWindow(ob_display
, self
->text
);
47 XDestroyWindow(ob_display
, self
->icon
);
48 appearance_free(self
->a_bg
);
50 appearance_free(self
->a_icon
);
53 appearance_free(self
->a_text
);
54 stacking_remove(self
);
58 void popup_position(Popup
*self
, int gravity
, int x
, int y
)
60 self
->gravity
= gravity
;
65 void popup_size(Popup
*self
, int w
, int h
)
71 void popup_size_to_string(Popup
*self
, char *text
)
77 self
->a_text
= appearance_copy(theme_app_hilite_label
);
79 self
->a_text
->texture
[0].data
.text
.string
= text
;
80 appearance_minsize(self
->a_text
, &textw
, &texth
);
81 textw
+= theme_bevel
* 2;
82 texth
+= theme_bevel
* 2;
84 self
->h
= texth
+ theme_bevel
* 2;
85 iconw
= (self
->hasicon
? texth
: 0);
86 self
->w
= textw
+ iconw
+ theme_bevel
* (self
->hasicon
? 3 : 2);
89 void popup_show(Popup
*self
, char *text
, Icon
*icon
)
91 XSetWindowAttributes attrib
;
96 /* create the shit if needed */
98 attrib
.override_redirect
= True
;
99 self
->bg
= XCreateWindow(ob_display
, ob_root
,
100 0, 0, 1, 1, 0, render_depth
, InputOutput
,
101 render_visual
, CWOverrideRedirect
, &attrib
);
103 XSetWindowBorderWidth(ob_display
, self
->bg
, theme_bwidth
);
104 XSetWindowBorder(ob_display
, self
->bg
, theme_b_color
->pixel
);
106 self
->text
= XCreateWindow(ob_display
, self
->bg
,
107 0, 0, 1, 1, 0, render_depth
, InputOutput
,
108 render_visual
, 0, NULL
);
110 self
->icon
= XCreateWindow(ob_display
, self
->bg
,
112 render_depth
, InputOutput
,
113 render_visual
, 0, NULL
);
115 XMapWindow(ob_display
, self
->text
);
116 XMapWindow(ob_display
, self
->icon
);
118 self
->a_bg
= appearance_copy(theme_app_hilite_bg
);
120 self
->a_icon
= appearance_copy(theme_app_icon
);
123 self
->a_text
= appearance_copy(theme_app_hilite_label
);
125 /* set up the textures */
126 self
->a_text
->texture
[0].data
.text
.string
= text
;
129 self
->a_icon
->texture
[0].type
= RGBA
;
130 self
->a_icon
->texture
[0].data
.rgba
.width
= icon
->width
;
131 self
->a_icon
->texture
[0].data
.rgba
.height
= icon
->height
;
132 self
->a_icon
->texture
[0].data
.rgba
.data
= icon
->data
;
134 self
->a_icon
->texture
[0].type
= NoTexture
;
137 /* measure the shit out */
138 appearance_minsize(self
->a_text
, &textw
, &texth
);
139 textw
+= theme_bevel
* 2;
140 texth
+= theme_bevel
* 2;
142 /* set the sizes up and reget the text sizes from the calculated
146 texth
= h
- (theme_bevel
* 2);
148 h
= texth
+ theme_bevel
* 2;
149 iconw
= (self
->hasicon
? texth
: 0);
152 textw
= w
- (iconw
+ theme_bevel
* (self
->hasicon
? 3 : 2));
154 w
= textw
+ iconw
+ theme_bevel
* (self
->hasicon
? 3 : 2);
155 /* sanity checks to avoid crashes! */
158 if (textw
< 1) textw
= 1;
159 if (texth
< 1) texth
= 1;
161 /* set up the x coord */
163 switch (self
->gravity
) {
169 case NorthEastGravity
:
171 case SouthEastGravity
:
176 /* set up the y coord */
178 switch (self
->gravity
) {
184 case SouthWestGravity
:
186 case SouthEastGravity
:
191 /* set the windows/appearances up */
192 RECT_SET(self
->a_bg
->area
, 0, 0, w
, h
);
193 XMoveResizeWindow(ob_display
, self
->bg
, x
, y
, w
, h
);
195 RECT_SET(self
->a_text
->area
, 0, 0, textw
, texth
);
196 RECT_SET(self
->a_text
->texture
[0].position
, theme_bevel
, theme_bevel
,
197 textw
- theme_bevel
* 2, texth
- theme_bevel
* 2);
198 self
->a_text
->surface
.data
.planar
.parent
= self
->a_bg
;
199 self
->a_text
->surface
.data
.planar
.parentx
= iconw
+
200 theme_bevel
* (self
->hasicon
? 2 : 1);
201 self
->a_text
->surface
.data
.planar
.parenty
= theme_bevel
;
202 XMoveResizeWindow(ob_display
, self
->text
,
203 iconw
+ theme_bevel
* (self
->hasicon
? 2 : 1),
204 theme_bevel
, textw
, texth
);
207 if (iconw
< 1) iconw
= 1; /* sanity check for crashes */
208 RECT_SET(self
->a_icon
->area
, 0, 0, iconw
, texth
);
209 RECT_SET(self
->a_icon
->texture
[0].position
, 0, 0, iconw
, texth
);
210 self
->a_icon
->surface
.data
.planar
.parent
= self
->a_bg
;
211 self
->a_icon
->surface
.data
.planar
.parentx
= theme_bevel
;
212 self
->a_icon
->surface
.data
.planar
.parenty
= theme_bevel
;
213 XMoveResizeWindow(ob_display
, self
->icon
,
214 theme_bevel
, theme_bevel
, iconw
, texth
);
217 paint(self
->bg
, self
->a_bg
);
218 paint(self
->text
, self
->a_text
);
220 paint(self
->icon
, self
->a_icon
);
223 XMapWindow(ob_display
, self
->bg
);
224 stacking_raise(INTERNAL_AS_WINDOW(self
));
229 void popup_hide(Popup
*self
)
232 XUnmapWindow(ob_display
, self
->bg
);
233 self
->mapped
= FALSE
;