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));
41 void popup_free(Popup *self)
44 XDestroyWindow(ob_display, self->bg);
45 XDestroyWindow(ob_display, self->text);
46 XDestroyWindow(ob_display, self->icon);
47 RrAppearanceFree(self->a_bg);
49 RrAppearanceFree(self->a_icon);
52 RrAppearanceFree(self->a_text);
53 stacking_remove(self);
57 void popup_position(Popup *self, int gravity, int x, int y)
59 self->gravity = gravity;
64 void popup_size(Popup *self, int w, int h)
70 void popup_size_to_string(Popup *self, char *text)
76 self->a_text = RrAppearanceCopy(ob_rr_theme->app_hilite_label);
78 self->a_text->texture[0].data.text.string = text;
79 RrMinsize(self->a_text, &textw, &texth);
80 textw += ob_rr_theme->bevel * 2;
81 texth += ob_rr_theme->bevel * 2;
83 self->h = texth + ob_rr_theme->bevel * 2;
84 iconw = (self->hasicon ? texth : 0);
85 self->w = textw + iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2);
88 void popup_show(Popup *self, char *text, Icon *icon)
90 XSetWindowAttributes attrib;
95 /* create the shit if needed */
97 attrib.override_redirect = True;
98 self->bg = XCreateWindow(ob_display, ob_root,
99 0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
100 InputOutput, RrVisual(ob_rr_inst),
101 CWOverrideRedirect, &attrib);
103 XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->bwidth);
104 XSetWindowBorder(ob_display, self->bg, ob_rr_theme->b_color->pixel);
106 self->text = XCreateWindow(ob_display, self->bg,
107 0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
108 InputOutput, RrVisual(ob_rr_inst), 0, NULL);
110 self->icon = XCreateWindow(ob_display, self->bg,
112 RrDepth(ob_rr_inst), InputOutput,
113 RrVisual(ob_rr_inst), 0, NULL);
115 XMapWindow(ob_display, self->text);
116 XMapWindow(ob_display, self->icon);
118 self->a_bg = RrAppearanceCopy(ob_rr_theme->app_hilite_bg);
120 self->a_icon = RrAppearanceCopy(ob_rr_theme->app_icon);
123 self->a_text = RrAppearanceCopy(ob_rr_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 = RR_TEXTURE_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 = RR_TEXTURE_NONE;
137 /* measure the shit out */
138 RrMinsize(self->a_text, &textw, &texth);
139 textw += ob_rr_theme->bevel * 2;
140 texth += ob_rr_theme->bevel * 2;
142 /* set the sizes up and reget the text sizes from the calculated
146 texth = h - (ob_rr_theme->bevel * 2);
148 h = texth + ob_rr_theme->bevel * 2;
149 iconw = (self->hasicon ? texth : 0);
152 textw = w - (iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2));
154 w = textw + iconw + ob_rr_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 XMoveResizeWindow(ob_display, self->bg, x, y, w, h);
194 self->a_text->surface.parent = self->a_bg;
195 self->a_text->surface.parentx = iconw +
196 ob_rr_theme->bevel * (self->hasicon ? 2 : 1);
197 self->a_text->surface.parenty = ob_rr_theme->bevel;
198 XMoveResizeWindow(ob_display, self->text,
199 iconw + ob_rr_theme->bevel * (self->hasicon ? 2 : 1),
200 ob_rr_theme->bevel, textw, texth);
203 if (iconw < 1) iconw = 1; /* sanity check for crashes */
204 self->a_icon->surface.parent = self->a_bg;
205 self->a_icon->surface.parentx = ob_rr_theme->bevel;
206 self->a_icon->surface.parenty = ob_rr_theme->bevel;
207 XMoveResizeWindow(ob_display, self->icon,
208 ob_rr_theme->bevel, ob_rr_theme->bevel,
212 RrPaint(self->a_bg, self->bg, w, h);
213 RrPaint(self->a_text, self->text, textw, texth);
215 RrPaint(self->a_icon, self->icon, iconw, texth);
218 XMapWindow(ob_display, self->bg);
219 stacking_raise(INTERNAL_AS_WINDOW(self));
224 void popup_hide(Popup *self)
227 XUnmapWindow(ob_display, self->bg);
228 self->mapped = FALSE;