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 RrAppearanceFree(self->a_bg);
50 RrAppearanceFree(self->a_icon);
53 RrAppearanceFree(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 = RrAppearanceCopy(ob_rr_theme->app_hilite_label);
79 self->a_text->texture[0].data.text.string = text;
80 RrMinsize(self->a_text, &textw, &texth);
81 textw += ob_rr_theme->bevel * 2;
82 texth += ob_rr_theme->bevel * 2;
84 self->h = texth + ob_rr_theme->bevel * 2;
85 iconw = (self->hasicon ? texth : 0);
86 self->w = textw + iconw + ob_rr_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, RrDepth(ob_rr_inst),
101 InputOutput, RrVisual(ob_rr_inst),
102 CWOverrideRedirect, &attrib);
104 XSetWindowBorderWidth(ob_display, self->bg, ob_rr_theme->bwidth);
105 XSetWindowBorder(ob_display, self->bg, ob_rr_theme->b_color->pixel);
107 self->text = XCreateWindow(ob_display, self->bg,
108 0, 0, 1, 1, 0, RrDepth(ob_rr_inst),
109 InputOutput, RrVisual(ob_rr_inst), 0, NULL);
111 self->icon = XCreateWindow(ob_display, self->bg,
113 RrDepth(ob_rr_inst), InputOutput,
114 RrVisual(ob_rr_inst), 0, NULL);
116 XMapWindow(ob_display, self->text);
117 XMapWindow(ob_display, self->icon);
119 self->a_bg = RrAppearanceCopy(ob_rr_theme->app_hilite_bg);
121 self->a_icon = RrAppearanceCopy(ob_rr_theme->app_icon);
124 self->a_text = RrAppearanceCopy(ob_rr_theme->app_hilite_label);
126 /* set up the textures */
127 self->a_text->texture[0].data.text.string = text;
130 self->a_icon->texture[0].type = RR_TEXTURE_RGBA;
131 self->a_icon->texture[0].data.rgba.width = icon->width;
132 self->a_icon->texture[0].data.rgba.height = icon->height;
133 self->a_icon->texture[0].data.rgba.data = icon->data;
135 self->a_icon->texture[0].type = RR_TEXTURE_NONE;
138 /* measure the shit out */
139 RrMinsize(self->a_text, &textw, &texth);
140 textw += ob_rr_theme->bevel * 2;
141 texth += ob_rr_theme->bevel * 2;
143 /* set the sizes up and reget the text sizes from the calculated
147 texth = h - (ob_rr_theme->bevel * 2);
149 h = texth + ob_rr_theme->bevel * 2;
150 iconw = (self->hasicon ? texth : 0);
153 textw = w - (iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2));
155 w = textw + iconw + ob_rr_theme->bevel * (self->hasicon ? 3 : 2);
156 /* sanity checks to avoid crashes! */
159 if (textw < 1) textw = 1;
160 if (texth < 1) texth = 1;
162 /* set up the x coord */
164 switch (self->gravity) {
170 case NorthEastGravity:
172 case SouthEastGravity:
177 /* set up the y coord */
179 switch (self->gravity) {
185 case SouthWestGravity:
187 case SouthEastGravity:
192 /* set the windows/appearances up */
193 XMoveResizeWindow(ob_display, self->bg, x, y, w, h);
195 self->a_text->surface.parent = self->a_bg;
196 self->a_text->surface.parentx = iconw +
197 ob_rr_theme->bevel * (self->hasicon ? 2 : 1);
198 self->a_text->surface.parenty = ob_rr_theme->bevel;
199 XMoveResizeWindow(ob_display, self->text,
200 iconw + ob_rr_theme->bevel * (self->hasicon ? 2 : 1),
201 ob_rr_theme->bevel, textw, texth);
204 if (iconw < 1) iconw = 1; /* sanity check for crashes */
205 self->a_icon->surface.parent = self->a_bg;
206 self->a_icon->surface.parentx = ob_rr_theme->bevel;
207 self->a_icon->surface.parenty = ob_rr_theme->bevel;
208 XMoveResizeWindow(ob_display, self->icon,
209 ob_rr_theme->bevel, ob_rr_theme->bevel,
213 RrPaint(self->a_bg, self->bg, w, h);
214 RrPaint(self->a_text, self->text, textw, texth);
216 RrPaint(self->a_icon, self->icon, iconw, texth);
219 XMapWindow(ob_display, self->bg);
220 stacking_raise(INTERNAL_AS_WINDOW(self));
225 void popup_hide(Popup *self)
228 XUnmapWindow(ob_display, self->bg);
229 self->mapped = FALSE;