+
+static void icon_popup_draw_icon(gint x, gint y, gint w, gint h, gpointer data)
+{
+ ObIconPopup *self = data;
+
+ self->a_icon->surface.parent = self->popup->a_bg;
+ self->a_icon->surface.parentx = x;
+ self->a_icon->surface.parenty = y;
+ XMoveResizeWindow(obt_display, self->icon, x, y, w, h);
+ RrPaint(self->a_icon, self->icon, w, h);
+}
+
+ObIconPopup *icon_popup_new(void)
+{
+ ObIconPopup *self;
+
+ self = g_new0(ObIconPopup, 1);
+ self->popup = popup_new();
+ self->a_icon = RrAppearanceCopy(ob_rr_theme->a_clear_tex);
+ self->icon = XCreateWindow(obt_display, self->popup->bg,
+ 0, 0, 1, 1, 0,
+ RrDepth(ob_rr_inst), InputOutput,
+ RrVisual(ob_rr_inst), 0, NULL);
+ XMapWindow(obt_display, self->icon);
+
+ self->popup->hasicon = TRUE;
+ self->popup->draw_icon = icon_popup_draw_icon;
+ self->popup->draw_icon_data = self;
+
+ return self;
+}
+
+void icon_popup_free(ObIconPopup *self)
+{
+ if (self) {
+ XDestroyWindow(obt_display, self->icon);
+ RrAppearanceFree(self->a_icon);
+ popup_free(self->popup);
+ g_free(self);
+ }
+}
+
+void icon_popup_delay_show(ObIconPopup *self, gulong usec,
+ gchar *text, RrImage *icon)
+{
+ if (icon) {
+ RrAppearanceClearTextures(self->a_icon);
+ self->a_icon->texture[0].type = RR_TEXTURE_IMAGE;
+ self->a_icon->texture[0].data.image.alpha = 0xff;
+ self->a_icon->texture[0].data.image.image = icon;
+ } else {
+ RrAppearanceClearTextures(self->a_icon);
+ self->a_icon->texture[0].type = RR_TEXTURE_NONE;
+ }
+
+ popup_delay_show(self->popup, usec, text);
+}
+
+void icon_popup_icon_size_multiplier(ObIconPopup *self, guint wm, guint hm)
+{
+ /* cap them at 1 */
+ self->popup->iconwm = MAX(1, wm);
+ self->popup->iconhm = MAX(1, hm);
+}
+
+static void pager_popup_draw_icon(gint px, gint py, gint w, gint h,
+ gpointer data)
+{
+ ObPagerPopup *self = data;
+ gint x, y;
+ guint rown, n;
+ guint horz_inc;
+ guint vert_inc;
+ guint r, c;
+ gint eachw, eachh;
+ const guint cols = screen_desktop_layout.columns;
+ const guint rows = screen_desktop_layout.rows;
+ const gint linewidth = ob_rr_theme->obwidth;
+
+ eachw = (w - ((cols + 1) * linewidth)) / cols;
+ eachh = (h - ((rows + 1) * linewidth)) / rows;
+ /* make them squares */
+ eachw = eachh = MIN(eachw, eachh);
+
+ /* center */
+ px += (w - (cols * (eachw + linewidth) + linewidth)) / 2;
+ py += (h - (rows * (eachh + linewidth) + linewidth)) / 2;
+
+ if (eachw <= 0 || eachh <= 0)
+ return;
+
+ switch (screen_desktop_layout.orientation) {
+ case OB_ORIENTATION_HORZ:
+ switch (screen_desktop_layout.start_corner) {
+ case OB_CORNER_TOPLEFT:
+ n = 0;
+ horz_inc = 1;
+ vert_inc = cols;
+ break;
+ case OB_CORNER_TOPRIGHT:
+ n = cols - 1;
+ horz_inc = -1;
+ vert_inc = cols;
+ break;
+ case OB_CORNER_BOTTOMRIGHT:
+ n = rows * cols - 1;
+ horz_inc = -1;
+ vert_inc = -screen_desktop_layout.columns;
+ break;
+ case OB_CORNER_BOTTOMLEFT:
+ n = (rows - 1) * cols;
+ horz_inc = 1;
+ vert_inc = -cols;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ break;
+ case OB_ORIENTATION_VERT:
+ switch (screen_desktop_layout.start_corner) {
+ case OB_CORNER_TOPLEFT:
+ n = 0;
+ horz_inc = rows;
+ vert_inc = 1;
+ break;
+ case OB_CORNER_TOPRIGHT:
+ n = rows * (cols - 1);
+ horz_inc = -rows;
+ vert_inc = 1;
+ break;
+ case OB_CORNER_BOTTOMRIGHT:
+ n = rows * cols - 1;
+ horz_inc = -rows;
+ vert_inc = -1;
+ break;
+ case OB_CORNER_BOTTOMLEFT:
+ n = rows - 1;
+ horz_inc = rows;
+ vert_inc = -1;
+ break;
+ default:
+ g_assert_not_reached();
+ }
+ break;
+ default:
+ g_assert_not_reached();
+ }
+
+ rown = n;
+ for (r = 0, y = 0; r < rows; ++r, y += eachh + linewidth)
+ {
+ for (c = 0, x = 0; c < cols; ++c, x += eachw + linewidth)
+ {
+ RrAppearance *a;
+
+ if (n < self->desks) {
+ a = (n == self->curdesk ? self->hilight : self->unhilight);
+
+ a->surface.parent = self->popup->a_bg;
+ a->surface.parentx = x + px;
+ a->surface.parenty = y + py;
+ XMoveResizeWindow(obt_display, self->wins[n],
+ x + px, y + py, eachw, eachh);
+ RrPaint(a, self->wins[n], eachw, eachh);
+ }
+ n += horz_inc;
+ }
+ n = rown += vert_inc;
+ }
+}
+
+ObPagerPopup *pager_popup_new(void)
+{
+ ObPagerPopup *self;
+
+ self = g_new(ObPagerPopup, 1);
+ self->popup = popup_new();
+
+ self->desks = 0;
+ self->wins = g_new(Window, self->desks);
+ self->hilight = RrAppearanceCopy(ob_rr_theme->osd_hilite_fg);
+ self->unhilight = RrAppearanceCopy(ob_rr_theme->osd_unhilite_fg);
+
+ self->popup->hasicon = TRUE;
+ self->popup->draw_icon = pager_popup_draw_icon;
+ self->popup->draw_icon_data = self;
+
+ return self;
+}
+
+void pager_popup_free(ObPagerPopup *self)
+{
+ if (self) {
+ guint i;
+
+ for (i = 0; i < self->desks; ++i)
+ XDestroyWindow(obt_display, self->wins[i]);
+ g_free(self->wins);
+ RrAppearanceFree(self->hilight);
+ RrAppearanceFree(self->unhilight);
+ popup_free(self->popup);
+ g_free(self);
+ }
+}
+
+void pager_popup_delay_show(ObPagerPopup *self, gulong usec,
+ gchar *text, guint desk)
+{
+ guint i;
+
+ if (screen_num_desktops < self->desks)
+ for (i = screen_num_desktops; i < self->desks; ++i)
+ XDestroyWindow(obt_display, self->wins[i]);
+
+ if (screen_num_desktops != self->desks)
+ self->wins = g_renew(Window, self->wins, screen_num_desktops);
+
+ if (screen_num_desktops > self->desks)
+ for (i = self->desks; i < screen_num_desktops; ++i) {
+ XSetWindowAttributes attr;
+
+ attr.border_pixel =
+ RrColorPixel(ob_rr_theme->osd_border_color);
+ self->wins[i] = XCreateWindow(obt_display, self->popup->bg,
+ 0, 0, 1, 1, ob_rr_theme->obwidth,
+ RrDepth(ob_rr_inst), InputOutput,
+ RrVisual(ob_rr_inst), CWBorderPixel,
+ &attr);
+ XMapWindow(obt_display, self->wins[i]);
+ }
+
+ self->desks = screen_num_desktops;
+ self->curdesk = desk;
+
+ popup_delay_show(self->popup, usec, text);
+}
+
+void pager_popup_icon_size_multiplier(ObPagerPopup *self, guint wm, guint hm)
+{
+ /* cap them at 1 */
+ self->popup->iconwm = MAX(1, wm);
+ self->popup->iconhm = MAX(1, hm);
+}