3 #include "render/render.h"
4 #include "render/theme.h"
21 Popup *popup_new(gboolean hasicon)
23 Popup *self = g_new(Popup, 1);
24 self->hasicon = hasicon;
27 self->gravity = NorthWestGravity;
28 self->x = self->y = self->w = self->h = 0;
32 void popup_free(Popup *self)
35 XDestroyWindow(ob_display, self->bg);
36 XDestroyWindow(ob_display, self->text);
37 XDestroyWindow(ob_display, self->icon);
38 appearance_free(self->a_bg);
40 appearance_free(self->a_icon);
43 appearance_free(self->a_text);
47 void popup_position(Popup *self, int gravity, int x, int y)
49 self->gravity = gravity;
54 void popup_size(Popup *self, int w, int h)
60 void popup_size_to_string(Popup *self, char *text)
66 self->a_text = appearance_copy(theme_app_hilite_label);
68 self->a_text->texture[0].data.text.string = text;
69 appearance_minsize(self->a_text, &textw, &texth);
70 textw += theme_bevel * 2;
71 texth += theme_bevel * 2;
73 self->h = texth + theme_bevel * 2;
74 iconw = (self->hasicon ? texth : 0);
75 self->w = textw + iconw + theme_bevel * 3;
78 void popup_show(Popup *self, char *text, Icon *icon)
80 XSetWindowAttributes attrib;
85 /* create the shit if needed */
87 attrib.override_redirect = True;
88 self->bg = XCreateWindow(ob_display, ob_root,
89 0, 0, 1, 1, 0, render_depth, InputOutput,
90 render_visual, CWOverrideRedirect, &attrib);
92 XSetWindowBorderWidth(ob_display, self->bg, theme_bwidth);
93 XSetWindowBorder(ob_display, self->bg, theme_b_color->pixel);
95 self->text = XCreateWindow(ob_display, self->bg,
96 0, 0, 1, 1, 0, render_depth, InputOutput,
97 render_visual, 0, NULL);
99 self->icon = XCreateWindow(ob_display, self->bg,
101 render_depth, InputOutput,
102 render_visual, 0, NULL);
104 XMapWindow(ob_display, self->text);
105 XMapWindow(ob_display, self->icon);
107 self->a_bg = appearance_copy(theme_app_hilite_bg);
109 self->a_icon = appearance_copy(theme_app_icon);
112 self->a_text = appearance_copy(theme_app_hilite_label);
114 /* set up the textures */
115 self->a_text->texture[0].data.text.string = text;
118 self->a_icon->texture[0].type = RGBA;
119 self->a_icon->texture[0].data.rgba.width = icon->width;
120 self->a_icon->texture[0].data.rgba.height = icon->height;
121 self->a_icon->texture[0].data.rgba.data = icon->data;
123 self->a_icon->texture[0].type = NoTexture;
126 /* measure the shit out */
127 appearance_minsize(self->a_text, &textw, &texth);
128 textw += theme_bevel * 2;
129 texth += theme_bevel * 2;
131 /* set the sizes up and reget the text sizes from the calculated
135 texth = h - (theme_bevel * 2);
137 h = texth + theme_bevel * 2;
138 iconw = (self->hasicon ? texth : 0);
141 textw = w - (iconw + theme_bevel * 3);
143 w = textw + iconw + theme_bevel * 3;
144 /* sanity checks to avoid crashes! */
147 if (textw < 1) textw = 1;
148 if (texth < 1) texth = 1;
150 /* set up the x coord */
152 switch (self->gravity) {
158 case NorthEastGravity:
160 case SouthEastGravity:
165 /* set up the y coord */
167 switch (self->gravity) {
173 case SouthWestGravity:
175 case SouthEastGravity:
180 /* set the windows/appearances up */
181 RECT_SET(self->a_bg->area, 0, 0, w, h);
182 XMoveResizeWindow(ob_display, self->bg, x, y, w, h);
184 RECT_SET(self->a_text->area, 0, 0, textw, texth);
185 RECT_SET(self->a_text->texture[0].position, theme_bevel, theme_bevel,
186 textw - theme_bevel * 2, texth - theme_bevel * 2);
187 self->a_text->surface.data.planar.parent = self->a_bg;
188 self->a_text->surface.data.planar.parentx = iconw + theme_bevel * 2;
189 self->a_text->surface.data.planar.parenty = theme_bevel;
190 XMoveResizeWindow(ob_display, self->text,
191 iconw + theme_bevel * 2, theme_bevel, textw, texth);
194 if (iconw < 1) iconw = 1; /* sanity check for crashes */
195 RECT_SET(self->a_icon->area, 0, 0, iconw, texth);
196 RECT_SET(self->a_icon->texture[0].position, 0, 0, iconw, texth);
197 self->a_icon->surface.data.planar.parent = self->a_bg;
198 self->a_icon->surface.data.planar.parentx = theme_bevel;
199 self->a_icon->surface.data.planar.parenty = theme_bevel;
200 XMoveResizeWindow(ob_display, self->icon,
201 theme_bevel, theme_bevel, iconw, texth);
204 paint(self->bg, self->a_bg);
205 paint(self->text, self->a_text);
207 paint(self->icon, self->a_icon);
209 XMapWindow(ob_display, self->bg);
212 void popup_hide(Popup *self)
214 XUnmapWindow(ob_display, self->bg);