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;
33 struct RrColor pri, sec;
35 self = g_new(Popup, 1);
36 self->obwin.type = Window_Internal;
37 self->hasicon = hasicon;
38 self->gravity = NorthWestGravity;
39 self->x = self->y = self->w = self->h = 0;
40 stacking_add(INTERNAL_AS_WINDOW(self));
41 stacking_raise(INTERNAL_AS_WINDOW(self));
43 attrib.override_redirect = True;
44 attrib.event_mask = ExposureMask;
45 self->bg = XCreateWindow(ob_display, ob_root,
46 0, 0, 1, 1, 0, RrInstanceDepth(ob_render_inst),
47 InputOutput, RrInstanceVisual(ob_render_inst),
48 CWEventMask|CWOverrideRedirect, &attrib);
49 self->s_bg = RrSurfaceNew(ob_render_inst, RR_SURFACE_PLANAR, self->bg, 0);
50 self->s_text = RrSurfaceNewChild(RR_SURFACE_PLANAR, self->s_bg, 1);
51 self->text = RrSurfaceWindow(self->s_text);
53 self->s_icon = RrSurfaceNewChild(RR_SURFACE_PLANAR, self->s_bg, 1);
54 self->icon = RrSurfaceWindow(self->s_icon);
60 /* XXX COPY THE APPEARANCES FROM THE THEME...... LIKE THIS SORTA!
61 self->a_text = appearance_copy(theme_app_hilite_label);
63 RrColorSet(&pri, 1, 0, 0, 0);
64 RrColorSet(&sec, 0, 1, 0, 0);
65 RrPlanarSet(self->s_bg, RR_PLANAR_VERTICAL, RR_SUNKEN_INNER, &pri, &sec,
67 RrColorSet(&pri, 0, 0.5, 0, 0.7);
68 RrColorSet(&sec, 0.5, 0, 0.5, 0.7);
69 RrPlanarSet(self->s_text, RR_PLANAR_HORIZONTAL, RR_BEVEL_NONE, &pri, &sec,
72 RrColorSet(&pri, 0, 0, 1, 0.7);
73 RrColorSet(&sec, 0.5, 0.5, 0, 0.7);
74 RrPlanarSet(self->s_icon, RR_PLANAR_HORIZONTAL, RR_BEVEL_NONE, &pri,
81 void popup_free(Popup *self)
83 RrSurfaceFree(self->s_icon);
84 RrSurfaceFree(self->s_text);
85 RrSurfaceFree(self->s_bg);
86 XDestroyWindow(ob_display, self->bg);
87 stacking_remove(self);
91 void popup_position(Popup *self, int gravity, int x, int y)
93 self->gravity = gravity;
98 void popup_size(Popup *self, int w, int h)
104 void popup_size_to_string(Popup *self, char *text)
109 RrTextureSetText(self->s_text, 0, NULL, RR_LEFT, text);
110 RrSurfaceMinSize(self->s_text, &textw, &texth);
111 textw += theme_bevel * 2;
112 texth += theme_bevel * 2;
114 self->h = texth + theme_bevel * 2 + theme_bwidth * 2;
115 iconw = (self->hasicon ? texth + theme_bevel : 0);
116 self->w = textw + iconw + theme_bevel * 2 + theme_bwidth * 2;
119 void popup_show(Popup *self, char *text, Icon *icon)
125 /* set up the textures */
126 RrTextureSetText(self->s_text, 0, NULL, RR_LEFT, text);
128 /* measure the shit out */
129 RrSurfaceMinSize(self->s_text, &textw, &texth);
130 textw += theme_bevel * 2;
131 texth += theme_bevel * 2;
133 /* set the sizes up and reget the text sizes from the calculated
137 texth = h - (theme_bevel * 2) - theme_bwidth * 2;
139 h = texth + theme_bevel * 2 + theme_bwidth * 2;
140 iconw = (self->hasicon ? texth : 0);
143 textw = w - (iconw + theme_bevel * (self->hasicon ? 3 : 2)) -
146 w = textw + iconw + theme_bevel * (self->hasicon ? 3 : 2) +
148 /* sanity checks to avoid crashes! */
151 if (textw < 1) textw = 1;
152 if (texth < 1) texth = 1;
154 /* set up the x coord */
156 switch (self->gravity) {
162 case NorthEastGravity:
164 case SouthEastGravity:
169 /* set up the y coord */
171 switch (self->gravity) {
177 case SouthWestGravity:
179 case SouthEastGravity:
184 /* set the surfaces up */
185 RrSurfaceSetArea(self->s_bg, x, y, w, h);
187 RrSurfaceSetArea(self->s_text,
188 iconw + theme_bevel * (self->hasicon ? 2 : 1) +
190 theme_bevel + theme_bwidth,
195 RrTextureSetRGBA(self->s_icon, 0, icon->data, 0, 0, icon->width,
198 RrTextureSetNone(self->s_icon, 0);
199 if (iconw < 1) iconw = 1; /* sanity check for crashes */
200 RrSurfaceSetArea(self->s_icon,
201 theme_bwidth + theme_bevel,
202 theme_bwidth + theme_bevel,
206 if (!RrSurfaceVisible(self->s_bg)) {
207 RrSurfaceShow(self->s_bg);
208 stacking_raise(INTERNAL_AS_WINDOW(self));
213 void popup_hide(Popup *self)
215 RrSurfaceHide(self->s_bg);