5 #include "render2/render.h"
6 #include "render2/theme.h"
16 struct RrSurface *s_bg;
17 struct RrSurface *s_icon;
18 struct RrSurface *s_text;
26 Popup *popup_new(gboolean hasicon)
28 XSetWindowAttributes attrib;
31 self = g_new(Popup, 1);
32 self->obwin.type = Window_Internal;
33 self->hasicon = hasicon;
34 self->gravity = NorthWestGravity;
35 self->x = self->y = self->w = self->h = 0;
36 stacking_add(INTERNAL_AS_WINDOW(self));
37 stacking_raise(INTERNAL_AS_WINDOW(self));
39 attrib.override_redirect = True;
40 attrib.event_mask = ExposureMask;
41 self->bg = XCreateWindow(ob_display, ob_root,
42 0, 0, 1, 1, 0, RrInstanceDepth(ob_render_inst),
43 InputOutput, RrInstanceVisual(ob_render_inst),
44 CWEventMask|CWOverrideRedirect, &attrib);
45 self->s_bg = RrSurfaceNew(ob_render_inst, 0, self->bg, 0);
46 RrSurfaceCopy(self->s_bg, ob_theme->app_bg_h);
48 self->s_text = RrSurfaceNewChild(0, self->s_bg, 1);
49 RrSurfaceCopy(self->s_text, ob_theme->app_label_h);
51 self->text = RrSurfaceWindow(self->s_text);
54 self->s_icon = RrSurfaceNewChild(RR_SURFACE_PLANAR, self->s_bg, 1);
55 RrSurfaceCopy(self->s_icon, ob_theme->app_icon);
57 self->icon = RrSurfaceWindow(self->s_icon);
66 void popup_free(Popup *self)
68 RrSurfaceFree(self->s_icon);
69 RrSurfaceFree(self->s_text);
70 RrSurfaceFree(self->s_bg);
71 XDestroyWindow(ob_display, self->bg);
72 stacking_remove(self);
76 void popup_position(Popup *self, int gravity, int x, int y)
78 self->gravity = gravity;
83 void popup_size(Popup *self, int w, int h)
89 void popup_size_to_string(Popup *self, char *text)
95 RrColorSet(&c, 0, 0, 0, 1.0);
96 RrTextureSetText(self->s_text, 0, NULL, RR_LEFT, &c, text);
97 RrSurfaceMinSize(self->s_text, &textw, &texth);
98 textw += ob_theme->bevel * 2;
99 texth += ob_theme->bevel * 2;
101 self->h = texth + ob_theme->bevel * 2 + ob_theme->bwidth * 2;
102 iconw = (self->hasicon ? texth + ob_theme->bevel : 0);
103 self->w = textw + iconw + ob_theme->bevel * 2 + ob_theme->bwidth * 2;
106 void popup_show(Popup *self, char *text, Icon *icon)
114 /* set up the textures */
115 RrColorSet(&c, 0, 0, 0, 1.0);
116 font = RrFontOpen(ob_render_inst, "arial-10:bold"); /* XXX mem leak! */
117 RrTextureSetText(self->s_text, 0, font, RR_LEFT, &c, text);
119 /* measure the shit out */
120 RrSurfaceMinSize(self->s_text, &textw, &texth);
121 textw += ob_theme->bevel * 2;
122 texth += ob_theme->bevel * 2;
124 /* set the sizes up and reget the text sizes from the calculated
128 texth = h - (ob_theme->bevel * 2) - ob_theme->bwidth * 2;
130 h = texth + ob_theme->bevel * 2 + ob_theme->bwidth * 2;
131 iconw = (self->hasicon ? texth : 0);
134 textw = w - (iconw + ob_theme->bevel * (self->hasicon ? 3 : 2)) -
135 ob_theme->bwidth * 2;
137 w = textw + iconw + ob_theme->bevel * (self->hasicon ? 3 : 2) +
138 ob_theme->bwidth * 2;
139 /* sanity checks to avoid crashes! */
142 if (textw < 1) textw = 1;
143 if (texth < 1) texth = 1;
145 /* set up the x coord */
147 switch (self->gravity) {
153 case NorthEastGravity:
155 case SouthEastGravity:
160 /* set up the y coord */
162 switch (self->gravity) {
168 case SouthWestGravity:
170 case SouthEastGravity:
175 /* set the surfaces up */
176 RrSurfaceSetArea(self->s_bg, x, y, w, h);
178 RrSurfaceSetArea(self->s_text,
179 iconw + ob_theme->bevel * (self->hasicon ? 2 : 1) +
181 ob_theme->bevel + ob_theme->bwidth,
186 RrTextureSetRGBA(self->s_icon, 0, icon->data, 0, 0, icon->width,
189 RrTextureSetNone(self->s_icon, 0);
190 if (iconw < 1) iconw = 1; /* sanity check for crashes */
191 RrSurfaceSetArea(self->s_icon,
192 ob_theme->bwidth + ob_theme->bevel,
193 ob_theme->bwidth + ob_theme->bevel,
197 if (!RrSurfaceVisible(self->s_bg)) {
198 RrSurfaceShow(self->s_bg);
199 stacking_raise(INTERNAL_AS_WINDOW(self));
204 void popup_hide(Popup *self)
206 RrSurfaceHide(self->s_bg);