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, RootWindow(ob_display, ob_screen),
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_set_text_align(Popup *self, RrJustify align)
115 self->a_text = RrAppearanceCopy(ob_rr_theme->app_hilite_label);
117 self->a_text->texture[0].data.text.justify = align;
120 void popup_show(Popup *self, gchar *text, ObClientIcon *icon)
126 /* create the shit if needed */
128 self->a_bg = RrAppearanceCopy(ob_rr_theme->app_hilite_bg);
129 if (self->hasicon && !self->a_icon)
130 self->a_icon = RrAppearanceCopy(ob_rr_theme->app_icon);
132 self->a_text = RrAppearanceCopy(ob_rr_theme->app_hilite_label);
134 XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->bwidth);
135 XSetWindowBorder(ob_display, self->bg, ob_rr_theme->b_color->pixel);
137 /* set up the textures */
138 self->a_text->texture[0].data.text.string = text;
141 self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
142 self->a_icon->texture[0].data.rgba.width = icon->width;
143 self->a_icon->texture[0].data.rgba.height = icon->height;
144 self->a_icon->texture[0].data.rgba.data = icon->data;
146 self->a_icon->texture[0].type = RR_TEXTURE_NONE;
149 /* measure the shit out */
150 RrMinsize(self->a_text, &textw, &texth);
151 textw += ob_rr_theme->bevel * 2;
152 texth += ob_rr_theme->bevel * 2;
154 /* set the sizes up and reget the text sizes from the calculated
158 texth = h - (ob_rr_theme->bevel * 2);
160 h = texth + ob_rr_theme->bevel * 2;
161 iconw = (self->hasicon ? texth : 0);
164 textw = w - (iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2));
166 w = textw + iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2);
167 /* sanity checks to avoid crashes! */
170 if (textw < 1) textw = 1;
171 if (texth < 1) texth = 1;
173 /* set up the x coord */
175 switch (self->gravity) {
181 case NorthEastGravity:
183 case SouthEastGravity:
188 /* set up the y coord */
190 switch (self->gravity) {
196 case SouthWestGravity:
198 case SouthEastGravity:
203 /* set the windows/appearances up */
204 XMoveResizeWindow(ob_display, self->bg, x, y, w, h);
206 self->a_text->surface.parent = self->a_bg;
207 self->a_text->surface.parentx = iconw +
208 ob_rr_theme->bevel * (self->hasicon ? 2 : 1);
209 self->a_text->surface.parenty = ob_rr_theme->bevel;
210 XMoveResizeWindow(ob_display, self->text,
211 iconw + ob_rr_theme->bevel * (self->hasicon ? 2 : 1),
212 ob_rr_theme->bevel, textw, texth);
215 if (iconw < 1) iconw = 1; /* sanity check for crashes */
216 self->a_icon->surface.parent = self->a_bg;
217 self->a_icon->surface.parentx = ob_rr_theme->bevel;
218 self->a_icon->surface.parenty = ob_rr_theme->bevel;
219 XMoveResizeWindow(ob_display, self->icon,
220 ob_rr_theme->bevel, ob_rr_theme->bevel,
224 RrPaint(self->a_bg, self->bg, w, h);
225 RrPaint(self->a_text, self->text, textw, texth);
227 RrPaint(self->a_icon, self->icon, iconw, texth);
230 XMapWindow(ob_display, self->bg);
231 stacking_raise(INTERNAL_AS_WINDOW(self));
236 void popup_hide(Popup *self)
239 XUnmapWindow(ob_display, self->bg);
240 self->mapped = FALSE;