5 #include "render2/render.h"
8 static int theme_bevel = 1;
9 static int theme_bwidth = 3;
11 typedef struct Popup {
19 struct RrSurface *s_bg;
20 struct RrSurface *s_icon;
21 struct RrSurface *s_text;
29 Popup *popup_new(gboolean hasicon)
31 XSetWindowAttributes attrib;
34 self = g_new(Popup, 1);
35 self->obwin.type = Window_Internal;
36 self->hasicon = hasicon;
37 self->gravity = NorthWestGravity;
38 self->x = self->y = self->w = self->h = 0;
39 stacking_add(INTERNAL_AS_WINDOW(self));
40 stacking_raise(INTERNAL_AS_WINDOW(self));
42 attrib.override_redirect = True;
43 self->bg = XCreateWindow(ob_display, ob_root,
44 0, 0, 1, 1, 0, RrInstanceDepth(ob_render_inst),
45 InputOutput, RrInstanceVisual(ob_render_inst),
46 CWOverrideRedirect, &attrib);
47 self->s_bg = RrSurfaceNew(ob_render_inst, RR_SURFACE_PLANAR, self->bg, 0);
48 self->s_text = RrSurfaceNewChild(RR_SURFACE_PLANAR, self->s_bg, 1);
49 self->text = RrSurfaceWindow(self->s_text);
51 self->s_icon = RrSurfaceNewChild(RR_SURFACE_PLANAR, self->s_bg, 1);
52 self->icon = RrSurfaceWindow(self->s_icon);
58 /* XXX COPY THE APPEARANCES FROM THE THEME...... LIKE THIS SORTA!
59 self->a_text = appearance_copy(theme_app_hilite_label);
65 void popup_free(Popup *self)
67 RrSurfaceFree(self->s_bg);
68 RrSurfaceFree(self->s_icon);
69 RrSurfaceFree(self->s_text);
70 XDestroyWindow(ob_display, self->bg);
71 stacking_remove(self);
75 void popup_position(Popup *self, int gravity, int x, int y)
77 self->gravity = gravity;
82 void popup_size(Popup *self, int w, int h)
88 void popup_size_to_string(Popup *self, char *text)
93 RrTextureSetText(self->s_text, 0, NULL, RR_LEFT, text);
94 RrSurfaceMinSize(self->s_text, &textw, &texth);
95 textw += theme_bevel * 2;
96 texth += theme_bevel * 2;
98 self->h = texth + theme_bevel * 2 + theme_bwidth * 2;
99 iconw = (self->hasicon ? texth + theme_bevel : 0);
100 self->w = textw + iconw + theme_bevel * 2 + theme_bwidth * 2;
103 void popup_show(Popup *self, char *text, Icon *icon)
109 /* set up the textures */
110 RrTextureSetText(self->s_text, 0, NULL, RR_LEFT, text);
112 /* measure the shit out */
113 RrSurfaceMinSize(self->s_text, &textw, &texth);
114 textw += theme_bevel * 2;
115 texth += theme_bevel * 2;
117 /* set the sizes up and reget the text sizes from the calculated
121 texth = h - (theme_bevel * 2);
123 h = texth + theme_bevel * 2;
124 iconw = (self->hasicon ? texth : 0);
127 textw = w - (iconw + theme_bevel * (self->hasicon ? 3 : 2));
129 w = textw + iconw + theme_bevel * (self->hasicon ? 3 : 2);
130 /* sanity checks to avoid crashes! */
133 if (textw < 1) textw = 1;
134 if (texth < 1) texth = 1;
136 /* set up the x coord */
138 switch (self->gravity) {
144 case NorthEastGravity:
146 case SouthEastGravity:
151 /* set up the y coord */
153 switch (self->gravity) {
159 case SouthWestGravity:
161 case SouthEastGravity:
166 /* set the surfaces up */
167 RrSurfaceSetArea(self->s_bg, x, y, w, h);
169 RrSurfaceSetArea(self->s_text,
170 iconw + theme_bevel * (self->hasicon ? 3 : 2) +
172 theme_bevel + theme_bwidth,
176 RrTextureSetRGBA(self->s_icon, 0, icon->data, 0, 0, icon->width,
178 if (iconw < 1) iconw = 1; /* sanity check for crashes */
179 RrSurfaceSetArea(self->s_icon,
180 theme_bwidth + theme_bevel,
181 theme_bwidth + theme_bevel,
185 if (!RrSurfaceVisible(self->s_bg)) {
186 RrSurfaceShow(self->s_bg);
187 stacking_raise(INTERNAL_AS_WINDOW(self));
191 void popup_hide(Popup *self)
193 if (RrSurfaceVisible(self->s_bg)) {
194 RrSurfaceHide(self->s_bg);