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 /*XXX textw += ob_rr_theme->bevel * 2;*/
105 texth
+= ob_rr_theme
->padding
* 2;
107 self
->h
= texth
+ ob_rr_theme
->padding
* 2;
108 iconw
= (self
->hasicon
? texth
: 0);
109 self
->w
= textw
+ iconw
+ ob_rr_theme
->padding
* (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
)
127 /* create the shit if needed */
129 self
->a_bg
= RrAppearanceCopy(ob_rr_theme
->app_hilite_bg
);
130 if (self
->hasicon
&& !self
->a_icon
)
131 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->a_clear_tex
);
133 self
->a_text
= RrAppearanceCopy(ob_rr_theme
->app_hilite_label
);
135 RrMargins(self
->a_bg
, &l
, &t
, &r
, &b
);
137 XSetWindowBorderWidth(ob_display
, self
->bg
, ob_rr_theme
->bwidth
);
138 XSetWindowBorder(ob_display
, self
->bg
, ob_rr_theme
->b_color
->pixel
);
140 /* set up the textures */
141 self
->a_text
->texture
[0].data
.text
.string
= text
;
144 self
->a_icon
->texture
[0].type
= RR_TEXTURE_RGBA
;
145 self
->a_icon
->texture
[0].data
.rgba
.width
= icon
->width
;
146 self
->a_icon
->texture
[0].data
.rgba
.height
= icon
->height
;
147 self
->a_icon
->texture
[0].data
.rgba
.data
= icon
->data
;
149 self
->a_icon
->texture
[0].type
= RR_TEXTURE_NONE
;
152 /* measure the shit out */
153 RrMinsize(self
->a_text
, &textw
, &texth
);
154 /*XXX textw += ob_rr_theme->padding * 2;*/
155 texth
+= ob_rr_theme
->padding
* 2;
157 /* set the sizes up and reget the text sizes from the calculated
161 texth
= h
- (t
+b
+ ob_rr_theme
->padding
* 2);
163 h
= t
+b
+ texth
+ ob_rr_theme
->padding
* 2;
164 iconw
= (self
->hasicon
? texth
: 0);
167 textw
= w
- (l
+r
+ iconw
+ ob_rr_theme
->padding
*
168 (self
->hasicon
? 3 : 2));
170 w
= l
+r
+ textw
+ iconw
+ ob_rr_theme
->padding
*
171 (self
->hasicon
? 3 : 2);
172 /* sanity checks to avoid crashes! */
175 if (textw
< 1) textw
= 1;
176 if (texth
< 1) texth
= 1;
178 /* set up the x coord */
180 switch (self
->gravity
) {
186 case NorthEastGravity
:
188 case SouthEastGravity
:
193 /* set up the y coord */
195 switch (self
->gravity
) {
201 case SouthWestGravity
:
203 case SouthEastGravity
:
208 /* set the windows/appearances up */
209 XMoveResizeWindow(ob_display
, self
->bg
, x
, y
, w
, h
);
211 self
->a_text
->surface
.parent
= self
->a_bg
;
212 self
->a_text
->surface
.parentx
= l
+ iconw
+
213 ob_rr_theme
->padding
* (self
->hasicon
? 2 : 1);
214 self
->a_text
->surface
.parenty
= t
+ ob_rr_theme
->padding
;
215 XMoveResizeWindow(ob_display
, self
->text
,
216 l
+ iconw
+ ob_rr_theme
->padding
* (self
->hasicon
? 2 : 1),
217 t
+ ob_rr_theme
->padding
, textw
, texth
);
220 if (iconw
< 1) iconw
= 1; /* sanity check for crashes */
221 self
->a_icon
->surface
.parent
= self
->a_bg
;
222 self
->a_icon
->surface
.parentx
= l
+ ob_rr_theme
->padding
;
223 self
->a_icon
->surface
.parenty
= t
+ ob_rr_theme
->padding
;
224 XMoveResizeWindow(ob_display
, self
->icon
,
225 l
+ ob_rr_theme
->padding
, t
+ ob_rr_theme
->padding
,
229 RrPaint(self
->a_bg
, self
->bg
, w
, h
);
230 RrPaint(self
->a_text
, self
->text
, textw
, texth
);
232 RrPaint(self
->a_icon
, self
->icon
, iconw
, texth
);
235 XMapWindow(ob_display
, self
->bg
);
236 stacking_raise(INTERNAL_AS_WINDOW(self
));
241 void popup_hide(Popup
*self
)
244 XUnmapWindow(ob_display
, self
->bg
);
245 self
->mapped
= FALSE
;