8 #include "render/render.h"
9 #include "render/theme.h"
31 Popup *popup_new(gboolean hasicon)
33 XSetWindowAttributes attrib;
34 Popup *self = g_new(Popup, 1);
36 self->obwin.type = Window_Internal;
37 self->hasicon = hasicon;
39 self->gravity = NorthWestGravity;
40 self->x = self->y = self->w = self->h = 0;
42 self->a_bg = self->a_icon = self->a_text = NULL;
44 attrib.override_redirect = True;
45 self->bg = XCreateWindow(ob_display, ob_root,
46 0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
47 InputOutput, RrVisual(ob_rr_inst),
48 CWOverrideRedirect, &attrib);
50 self->text = XCreateWindow(ob_display, self->bg,
51 0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
52 InputOutput, RrVisual(ob_rr_inst), 0, NULL);
55 self->icon = XCreateWindow(ob_display, self->bg,
57 RrDepth(ob_rr_inst), InputOutput,
58 RrVisual(ob_rr_inst), 0, NULL);
60 XMapWindow(ob_display, self->text);
61 XMapWindow(ob_display, self->icon);
63 stacking_add(INTERNAL_AS_WINDOW(self));
67 void popup_free(Popup *self)
70 XDestroyWindow(ob_display, self->bg);
71 XDestroyWindow(ob_display, self->text);
72 XDestroyWindow(ob_display, self->icon);
73 RrAppearanceFree(self->a_bg);
74 RrAppearanceFree(self->a_icon);
75 RrAppearanceFree(self->a_text);
76 stacking_remove(self);
81 void popup_position(Popup *self, gint gravity, gint x, gint y)
83 self->gravity = gravity;
88 void popup_size(Popup *self, gint w, gint h)
94 void popup_size_to_string(Popup *self, gchar *text)
100 self->a_text = RrAppearanceCopy(ob_rr_theme->app_hilite_label);
102 self->a_text->texture[0].data.text.string = text;
103 RrMinsize(self->a_text, &textw, &texth);
104 textw += ob_rr_theme->bevel * 2;
105 texth += ob_rr_theme->bevel * 2;
107 self->h = texth + ob_rr_theme->bevel * 2;
108 iconw = (self->hasicon ? texth : 0);
109 self->w = textw + iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2);
112 void popup_show(Popup *self, gchar *text, ObClientIcon *icon)
118 /* create the shit if needed */
120 self->a_bg = RrAppearanceCopy(ob_rr_theme->app_hilite_bg);
121 if (self->hasicon && !self->a_icon)
122 self->a_icon = RrAppearanceCopy(ob_rr_theme->app_icon);
124 self->a_text = RrAppearanceCopy(ob_rr_theme->app_hilite_label);
126 XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->bwidth);
127 XSetWindowBorder(ob_display, self->bg, ob_rr_theme->b_color->pixel);
129 /* set up the textures */
130 self->a_text->texture[0].data.text.string = text;
133 self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
134 self->a_icon->texture[0].data.rgba.width = icon->width;
135 self->a_icon->texture[0].data.rgba.height = icon->height;
136 self->a_icon->texture[0].data.rgba.data = icon->data;
138 self->a_icon->texture[0].type = RR_TEXTURE_NONE;
141 /* measure the shit out */
142 RrMinsize(self->a_text, &textw, &texth);
143 textw += ob_rr_theme->bevel * 2;
144 texth += ob_rr_theme->bevel * 2;
146 /* set the sizes up and reget the text sizes from the calculated
150 texth = h - (ob_rr_theme->bevel * 2);
152 h = texth + ob_rr_theme->bevel * 2;
153 iconw = (self->hasicon ? texth : 0);
156 textw = w - (iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2));
158 w = textw + iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2);
159 /* sanity checks to avoid crashes! */
162 if (textw < 1) textw = 1;
163 if (texth < 1) texth = 1;
165 /* set up the x coord */
167 switch (self->gravity) {
173 case NorthEastGravity:
175 case SouthEastGravity:
180 /* set up the y coord */
182 switch (self->gravity) {
188 case SouthWestGravity:
190 case SouthEastGravity:
195 /* set the windows/appearances up */
196 XMoveResizeWindow(ob_display, self->bg, x, y, w, h);
198 self->a_text->surface.parent = self->a_bg;
199 self->a_text->surface.parentx = iconw +
200 ob_rr_theme->bevel * (self->hasicon ? 2 : 1);
201 self->a_text->surface.parenty = ob_rr_theme->bevel;
202 XMoveResizeWindow(ob_display, self->text,
203 iconw + ob_rr_theme->bevel * (self->hasicon ? 2 : 1),
204 ob_rr_theme->bevel, textw, texth);
207 if (iconw < 1) iconw = 1; /* sanity check for crashes */
208 self->a_icon->surface.parent = self->a_bg;
209 self->a_icon->surface.parentx = ob_rr_theme->bevel;
210 self->a_icon->surface.parenty = ob_rr_theme->bevel;
211 XMoveResizeWindow(ob_display, self->icon,
212 ob_rr_theme->bevel, ob_rr_theme->bevel,
216 RrPaint(self->a_bg, self->bg, w, h);
217 RrPaint(self->a_text, self->text, textw, texth);
219 RrPaint(self->a_icon, self->icon, iconw, texth);
222 XMapWindow(ob_display, self->bg);
223 stacking_raise(INTERNAL_AS_WINDOW(self));
228 void popup_hide(Popup *self)
231 XUnmapWindow(ob_display, self->bg);
232 self->mapped = FALSE;