6 #include "render/render.h"
7 #include "render/theme.h"
28 Popup
*popup_new(gboolean hasicon
)
30 XSetWindowAttributes attrib
;
31 Popup
*self
= g_new(Popup
, 1);
33 self
->obwin
.type
= Window_Internal
;
34 self
->hasicon
= hasicon
;
36 self
->gravity
= NorthWestGravity
;
37 self
->x
= self
->y
= self
->w
= self
->h
= 0;
39 self
->a_bg
= self
->a_icon
= self
->a_text
= NULL
;
41 attrib
.override_redirect
= True
;
42 self
->bg
= XCreateWindow(ob_display
, ob_root
,
43 0, 0, 1, 1, 0, RrDepth(ob_rr_inst
),
44 InputOutput
, RrVisual(ob_rr_inst
),
45 CWOverrideRedirect
, &attrib
);
47 self
->text
= XCreateWindow(ob_display
, self
->bg
,
48 0, 0, 1, 1, 0, RrDepth(ob_rr_inst
),
49 InputOutput
, RrVisual(ob_rr_inst
), 0, NULL
);
52 self
->icon
= XCreateWindow(ob_display
, self
->bg
,
54 RrDepth(ob_rr_inst
), InputOutput
,
55 RrVisual(ob_rr_inst
), 0, NULL
);
57 XMapWindow(ob_display
, self
->text
);
58 XMapWindow(ob_display
, self
->icon
);
60 stacking_add(INTERNAL_AS_WINDOW(self
));
64 void popup_free(Popup
*self
)
67 XDestroyWindow(ob_display
, self
->bg
);
68 XDestroyWindow(ob_display
, self
->text
);
69 XDestroyWindow(ob_display
, self
->icon
);
70 RrAppearanceFree(self
->a_bg
);
71 RrAppearanceFree(self
->a_icon
);
72 RrAppearanceFree(self
->a_text
);
73 stacking_remove(self
);
78 void popup_position(Popup
*self
, int gravity
, int x
, int y
)
80 self
->gravity
= gravity
;
85 void popup_size(Popup
*self
, int w
, int h
)
91 void popup_size_to_string(Popup
*self
, char *text
)
97 self
->a_text
= RrAppearanceCopy(ob_rr_theme
->app_hilite_label
);
99 self
->a_text
->texture
[0].data
.text
.string
= text
;
100 RrMinsize(self
->a_text
, &textw
, &texth
);
101 textw
+= ob_rr_theme
->bevel
* 2;
102 texth
+= ob_rr_theme
->bevel
* 2;
104 self
->h
= texth
+ ob_rr_theme
->bevel
* 2;
105 iconw
= (self
->hasicon
? texth
: 0);
106 self
->w
= textw
+ iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 3 : 2);
109 void popup_show(Popup
*self
, char *text
, ObClientIcon
*icon
)
115 /* create the shit if needed */
117 self
->a_bg
= RrAppearanceCopy(ob_rr_theme
->app_hilite_bg
);
118 if (self
->hasicon
&& !self
->a_icon
)
119 self
->a_icon
= RrAppearanceCopy(ob_rr_theme
->app_icon
);
121 self
->a_text
= RrAppearanceCopy(ob_rr_theme
->app_hilite_label
);
123 XSetWindowBorderWidth(ob_display
, self
->bg
, ob_rr_theme
->bwidth
);
124 XSetWindowBorder(ob_display
, self
->bg
, ob_rr_theme
->b_color
->pixel
);
126 /* set up the textures */
127 self
->a_text
->texture
[0].data
.text
.string
= text
;
130 self
->a_icon
->texture
[0].type
= RR_TEXTURE_RGBA
;
131 self
->a_icon
->texture
[0].data
.rgba
.width
= icon
->width
;
132 self
->a_icon
->texture
[0].data
.rgba
.height
= icon
->height
;
133 self
->a_icon
->texture
[0].data
.rgba
.data
= icon
->data
;
135 self
->a_icon
->texture
[0].type
= RR_TEXTURE_NONE
;
138 /* measure the shit out */
139 RrMinsize(self
->a_text
, &textw
, &texth
);
140 textw
+= ob_rr_theme
->bevel
* 2;
141 texth
+= ob_rr_theme
->bevel
* 2;
143 /* set the sizes up and reget the text sizes from the calculated
147 texth
= h
- (ob_rr_theme
->bevel
* 2);
149 h
= texth
+ ob_rr_theme
->bevel
* 2;
150 iconw
= (self
->hasicon
? texth
: 0);
153 textw
= w
- (iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 3 : 2));
155 w
= textw
+ iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 3 : 2);
156 /* sanity checks to avoid crashes! */
159 if (textw
< 1) textw
= 1;
160 if (texth
< 1) texth
= 1;
162 /* set up the x coord */
164 switch (self
->gravity
) {
170 case NorthEastGravity
:
172 case SouthEastGravity
:
177 /* set up the y coord */
179 switch (self
->gravity
) {
185 case SouthWestGravity
:
187 case SouthEastGravity
:
192 /* set the windows/appearances up */
193 XMoveResizeWindow(ob_display
, self
->bg
, x
, y
, w
, h
);
195 self
->a_text
->surface
.parent
= self
->a_bg
;
196 self
->a_text
->surface
.parentx
= iconw
+
197 ob_rr_theme
->bevel
* (self
->hasicon
? 2 : 1);
198 self
->a_text
->surface
.parenty
= ob_rr_theme
->bevel
;
199 XMoveResizeWindow(ob_display
, self
->text
,
200 iconw
+ ob_rr_theme
->bevel
* (self
->hasicon
? 2 : 1),
201 ob_rr_theme
->bevel
, textw
, texth
);
204 if (iconw
< 1) iconw
= 1; /* sanity check for crashes */
205 self
->a_icon
->surface
.parent
= self
->a_bg
;
206 self
->a_icon
->surface
.parentx
= ob_rr_theme
->bevel
;
207 self
->a_icon
->surface
.parenty
= ob_rr_theme
->bevel
;
208 XMoveResizeWindow(ob_display
, self
->icon
,
209 ob_rr_theme
->bevel
, ob_rr_theme
->bevel
,
213 RrPaint(self
->a_bg
, self
->bg
, w
, h
);
214 RrPaint(self
->a_text
, self
->text
, textw
, texth
);
216 RrPaint(self
->a_icon
, self
->icon
, iconw
, texth
);
219 XMapWindow(ob_display
, self
->bg
);
220 stacking_raise(INTERNAL_AS_WINDOW(self
));
225 void popup_hide(Popup
*self
)
228 XUnmapWindow(ob_display
, self
->bg
);
229 self
->mapped
= FALSE
;