5 #include "render/render.h"
6 #include "render/theme.h"
27 Popup
*popup_new(gboolean hasicon
)
29 XSetWindowAttributes attrib
;
30 Popup
*self
= g_new(Popup
, 1);
32 self
->obwin
.type
= Window_Internal
;
33 self
->hasicon
= hasicon
;
35 self
->gravity
= NorthWestGravity
;
36 self
->x
= self
->y
= self
->w
= self
->h
= 0;
38 self
->a_bg
= self
->a_icon
= self
->a_text
= NULL
;
40 attrib
.override_redirect
= True
;
41 self
->bg
= XCreateWindow(ob_display
, ob_root
,
42 0, 0, 1, 1, 0, RrDepth(ob_rr_inst
),
43 InputOutput
, RrVisual(ob_rr_inst
),
44 CWOverrideRedirect
, &attrib
);
46 self
->text
= XCreateWindow(ob_display
, self
->bg
,
47 0, 0, 1, 1, 0, RrDepth(ob_rr_inst
),
48 InputOutput
, RrVisual(ob_rr_inst
), 0, NULL
);
51 self
->icon
= XCreateWindow(ob_display
, self
->bg
,
53 RrDepth(ob_rr_inst
), InputOutput
,
54 RrVisual(ob_rr_inst
), 0, NULL
);
56 XMapWindow(ob_display
, self
->text
);
57 XMapWindow(ob_display
, self
->icon
);
59 stacking_add(INTERNAL_AS_WINDOW(self
));
63 void popup_free(Popup
*self
)
66 XDestroyWindow(ob_display
, self
->bg
);
67 XDestroyWindow(ob_display
, self
->text
);
68 XDestroyWindow(ob_display
, self
->icon
);
69 RrAppearanceFree(self
->a_bg
);
70 RrAppearanceFree(self
->a_icon
);
71 RrAppearanceFree(self
->a_text
);
72 stacking_remove(self
);
77 void popup_position(Popup
*self
, int gravity
, int x
, int y
)
79 self
->gravity
= gravity
;
84 void popup_size(Popup
*self
, int w
, int h
)
90 void popup_size_to_string(Popup
*self
, char *text
)
96 self
->a_text
= RrAppearanceCopy(ob_rr_theme
->app_hilite_label
);
98 self
->a_text
->texture
[0].data
.text
.string
= text
;
99 RrMinsize(self
->a_text
, &textw
, &texth
);
100 textw
+= ob_rr_theme
->bevel
* 2;
101 texth
+= ob_rr_theme
->bevel
* 2;
103 self
->h
= texth
+ ob_rr_theme
->bevel
* 2;
104 iconw
= (self
->hasicon
? texth
: 0);
105 self
->w
= textw
+ iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 3 : 2);
108 void popup_show(Popup
*self
, char *text
, ObClientIcon
*icon
)
114 /* create the shit if needed */
116 self
->a_bg
= RrAppearanceCopy(ob_rr_theme
->app_hilite_bg
);
117 if (self
->hasicon
&& !self
->a_icon
)
118 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->app_icon
);
120 self
->a_text
= RrAppearanceCopy(ob_rr_theme
->app_hilite_label
);
122 XSetWindowBorderWidth(ob_display
, self
->bg
, ob_rr_theme
->bwidth
);
123 XSetWindowBorder(ob_display
, self
->bg
, ob_rr_theme
->b_color
->pixel
);
125 /* set up the textures */
126 self
->a_text
->texture
[0].data
.text
.string
= text
;
129 self
->a_icon
->texture
[0].type
= RR_TEXTURE_RGBA
;
130 self
->a_icon
->texture
[0].data
.rgba
.width
= icon
->width
;
131 self
->a_icon
->texture
[0].data
.rgba
.height
= icon
->height
;
132 self
->a_icon
->texture
[0].data
.rgba
.data
= icon
->data
;
134 self
->a_icon
->texture
[0].type
= RR_TEXTURE_NONE
;
137 /* measure the shit out */
138 RrMinsize(self
->a_text
, &textw
, &texth
);
139 textw
+= ob_rr_theme
->bevel
* 2;
140 texth
+= ob_rr_theme
->bevel
* 2;
142 /* set the sizes up and reget the text sizes from the calculated
146 texth
= h
- (ob_rr_theme
->bevel
* 2);
148 h
= texth
+ ob_rr_theme
->bevel
* 2;
149 iconw
= (self
->hasicon
? texth
: 0);
152 textw
= w
- (iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 3 : 2));
154 w
= textw
+ iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 3 : 2);
155 /* sanity checks to avoid crashes! */
158 if (textw
< 1) textw
= 1;
159 if (texth
< 1) texth
= 1;
161 /* set up the x coord */
163 switch (self
->gravity
) {
169 case NorthEastGravity
:
171 case SouthEastGravity
:
176 /* set up the y coord */
178 switch (self
->gravity
) {
184 case SouthWestGravity
:
186 case SouthEastGravity
:
191 /* set the windows/appearances up */
192 XMoveResizeWindow(ob_display
, self
->bg
, x
, y
, w
, h
);
194 self
->a_text
->surface
.parent
= self
->a_bg
;
195 self
->a_text
->surface
.parentx
= iconw
+
196 ob_rr_theme
->bevel
* (self
->hasicon
? 2 : 1);
197 self
->a_text
->surface
.parenty
= ob_rr_theme
->bevel
;
198 XMoveResizeWindow(ob_display
, self
->text
,
199 iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 2 : 1),
200 ob_rr_theme
->bevel
, textw
, texth
);
203 if (iconw
< 1) iconw
= 1; /* sanity check for crashes */
204 self
->a_icon
->surface
.parent
= self
->a_bg
;
205 self
->a_icon
->surface
.parentx
= ob_rr_theme
->bevel
;
206 self
->a_icon
->surface
.parenty
= ob_rr_theme
->bevel
;
207 XMoveResizeWindow(ob_display
, self
->icon
,
208 ob_rr_theme
->bevel
, ob_rr_theme
->bevel
,
212 RrPaint(self
->a_bg
, self
->bg
, w
, h
);
213 RrPaint(self
->a_text
, self
->text
, textw
, texth
);
215 RrPaint(self
->a_icon
, self
->icon
, iconw
, texth
);
218 XMapWindow(ob_display
, self
->bg
);
219 stacking_raise(INTERNAL_AS_WINDOW(self
));
224 void popup_hide(Popup
*self
)
227 XUnmapWindow(ob_display
, self
->bg
);
228 self
->mapped
= FALSE
;