static void setup_button_focus_tex(ObPromptElement *e, RrAppearance *a, gboolean on) { gint i, l, r, t, b; for (i = 1; i < 5; ++i) a->texture[i].type = on ? RR_TEXTURE_LINE_ART : RR_TEXTURE_NONE; if (!on) return; RrMargins(a, &l, &t, &r, &b); l += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2; r += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2; t += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2; b += MIN(BUTTON_HMARGIN, BUTTON_VMARGIN) / 2; /* top line */ a->texture[1].data.lineart.x1 = l; a->texture[1].data.lineart.x2 = e->width - r - 1; a->texture[1].data.lineart.y1 = t; a->texture[1].data.lineart.y2 = t; /* bottom line */ a->texture[2].data.lineart.x1 = l; a->texture[2].data.lineart.x2 = e->width - r - 1; a->texture[2].data.lineart.y1 = e->height - b - 1; a->texture[2].data.lineart.y2 = e->height - b - 1; /* left line */ a->texture[3].data.lineart.x1 = l; a->texture[3].data.lineart.x2 = l; a->texture[3].data.lineart.y1 = t; a->texture[3].data.lineart.y2 = e->height - b - 1; /* right line */ a->texture[4].data.lineart.x1 = e->width - r - 1; a->texture[4].data.lineart.x2 = e->width - r - 1; a->texture[4].data.lineart.y1 = t; a->texture[4].data.lineart.y2 = e->height - b - 1; }
void menu_frame_render(ObMenuFrame *self) { gint w = 0, h = 0; gint tw, th; /* temps */ GList *it; gboolean has_icon = FALSE; ObMenu *sub; ObMenuEntryFrame *e; /* find text dimensions */ STRUT_SET(self->item_margin, 0, 0, 0, 0); if (self->entries) { gint l, t, r, b; e = self->entries->data; ob_rr_theme->a_menu_text_normal->texture[0].data.text.string = ""; tw = RrMinWidth(ob_rr_theme->a_menu_text_normal); tw += 2*PADDING; th = ITEM_HEIGHT; RrMargins(ob_rr_theme->a_menu_normal, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); RrMargins(ob_rr_theme->a_menu_selected, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); RrMargins(ob_rr_theme->a_menu_disabled, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); RrMargins(ob_rr_theme->a_menu_disabled_selected, &l, &t, &r, &b); STRUT_SET(self->item_margin, MAX(self->item_margin.left, l), MAX(self->item_margin.top, t), MAX(self->item_margin.right, r), MAX(self->item_margin.bottom, b)); } /* render the entries */ for (it = self->entries; it; it = g_list_next(it)) { RrAppearance *text_a; e = it->data; /* if the first entry is a labeled separator, then make its border overlap with the menu's outside border */ if (it == self->entries && e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR && e->entry->data.separator.label) { h -= ob_rr_theme->mbwidth; } if (e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR && e->entry->data.separator.label) { e->border = ob_rr_theme->mbwidth; } RECT_SET_POINT(e->area, 0, h+e->border); XMoveWindow(obt_display, e->window, e->area.x-e->border, e->area.y-e->border); XSetWindowBorderWidth(obt_display, e->window, e->border); XSetWindowBorder(obt_display, e->window, RrColorPixel(ob_rr_theme->menu_border_color)); text_a = (e->entry->type == OB_MENU_ENTRY_TYPE_NORMAL && !e->entry->data.normal.enabled ? /* disabled */ (e == self->selected ? ob_rr_theme->a_menu_text_disabled_selected : ob_rr_theme->a_menu_text_disabled) : /* enabled */ (e == self->selected ? ob_rr_theme->a_menu_text_selected : ob_rr_theme->a_menu_text_normal)); switch (e->entry->type) { case OB_MENU_ENTRY_TYPE_NORMAL: text_a->texture[0].data.text.string = e->entry->data.normal.label; tw = RrMinWidth(text_a); tw = MIN(tw, MAX_MENU_WIDTH); th = ob_rr_theme->menu_font_height; if (e->entry->data.normal.icon || e->entry->data.normal.mask) has_icon = TRUE; break; case OB_MENU_ENTRY_TYPE_SUBMENU: sub = e->entry->data.submenu.submenu; text_a->texture[0].data.text.string = sub ? sub->title : ""; tw = RrMinWidth(text_a); tw = MIN(tw, MAX_MENU_WIDTH); th = ob_rr_theme->menu_font_height; if (e->entry->data.normal.icon || e->entry->data.normal.mask) has_icon = TRUE; tw += ITEM_HEIGHT - PADDING; break; case OB_MENU_ENTRY_TYPE_SEPARATOR: if (e->entry->data.separator.label != NULL) { ob_rr_theme->a_menu_text_title->texture[0].data.text.string = e->entry->data.separator.label; tw = RrMinWidth(ob_rr_theme->a_menu_text_title) + 2*ob_rr_theme->paddingx; tw = MIN(tw, MAX_MENU_WIDTH); th = ob_rr_theme->menu_title_height + (ob_rr_theme->mbwidth - PADDING) *2; } else { tw = 0; th = ob_rr_theme->menu_sep_width + 2*ob_rr_theme->menu_sep_paddingy - 2*PADDING; } break; default: g_assert_not_reached(); } tw += 2*PADDING; th += 2*PADDING; w = MAX(w, tw); h += th; } /* if the last entry is a labeled separator, then make its border overlap with the menu's outside border */ it = g_list_last(self->entries); e = it ? it->data : NULL; if (e && e->entry->type == OB_MENU_ENTRY_TYPE_SEPARATOR && e->entry->data.separator.label) { h -= ob_rr_theme->mbwidth; } self->text_x = PADDING; self->text_w = w; if (self->entries) { if (has_icon) { w += ITEM_HEIGHT + PADDING; self->text_x += ITEM_HEIGHT + PADDING; } } if (!w) w = 10; if (!h) h = 3; XResizeWindow(obt_display, self->window, w, h); self->inner_w = w; RrPaint(self->a_items, self->window, w, h); for (it = self->entries; it; it = g_list_next(it)) menu_entry_frame_render(it->data); w += ob_rr_theme->mbwidth * 2; h += ob_rr_theme->mbwidth * 2; RECT_SET_SIZE(self->area, w, h); XFlush(obt_display); }
void popup_delay_show(ObPopup *self, gulong msec, gchar *text) { gint l, t, r, b; gint x, y, w, h; guint m; gint emptyx, emptyy; /* empty space between elements */ gint textx, texty, textw, texth; gint iconx, icony, iconw, iconh; const Rect *area; Rect mon; gboolean hasicon = self->hasicon; /* when there is no icon and the text is not parent relative, then fill the whole dialog with the text appearance, don't use the bg at all */ if (hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL) RrMargins(self->a_bg, &l, &t, &r, &b); else l = t = r = b = 0; /* set up the textures */ self->a_text->texture[0].data.text.string = text; /* measure the text out */ if (text[0] != '\0') { RrMinSize(self->a_text, &textw, &texth); } else { textw = 0; texth = RrMinHeight(self->a_text); } /* get the height, which is also used for the icon width */ emptyy = t + b + ob_rr_theme->paddingy * 2; if (self->h) texth = self->h - emptyy; h = texth * self->iconhm + emptyy; if (self->textw) textw = self->textw; iconx = textx = l + ob_rr_theme->paddingx; emptyx = l + r + ob_rr_theme->paddingx * 2; if (hasicon) { iconw = texth * self->iconwm; iconh = texth * self->iconhm; textx += iconw + ob_rr_theme->paddingx; if (textw) emptyx += ob_rr_theme->paddingx; /* between the icon and text */ icony = (h - iconh - emptyy) / 2 + t + ob_rr_theme->paddingy; } else iconw = 0; texty = (h - texth - emptyy) / 2 + t + ob_rr_theme->paddingy; /* when there is no icon, then fill the whole dialog with the text appearance */ if (!hasicon) { textx = texty = 0; texth += emptyy; textw += emptyx; emptyx = emptyy = 0; } w = textw + emptyx + iconw; /* cap it at maxw/minw */ if (self->maxw) w = MIN(w, self->maxw); if (self->minw) w = MAX(w, self->minw); textw = w - emptyx - iconw; /* sanity checks to avoid crashes! */ if (w < 1) w = 1; if (h < 1) h = 1; if (texth < 1) texth = 1; /* set up the x coord */ x = self->x; switch (self->gravity) { case NorthGravity: case CenterGravity: case SouthGravity: x -= w / 2; break; case NorthEastGravity: case EastGravity: case SouthEastGravity: x -= w; break; } /* set up the y coord */ y = self->y; switch (self->gravity) { case WestGravity: case CenterGravity: case EastGravity: y -= h / 2; break; case SouthWestGravity: case SouthGravity: case SouthEastGravity: y -= h; break; } /* Find the monitor which contains the biggest part of the popup. * If the popup is completely off screen, limit it to the intersection * of all monitors and then try again. If it's still off screen, put it * on monitor 0. */ RECT_SET(mon, x, y, w, h); m = screen_find_monitor(&mon); area = screen_physical_area_monitor(m); x=MAX(MIN(x, area->x+area->width-w),area->x); y=MAX(MIN(y, area->y+area->height-h),area->y); if (m == screen_num_monitors) { RECT_SET(mon, x, y, w, h); m = screen_find_monitor(&mon); if (m == screen_num_monitors) m = 0; area = screen_physical_area_monitor(m); x=MAX(MIN(x, area->x+area->width-w),area->x); y=MAX(MIN(y, area->y+area->height-h),area->y); } /* set the windows/appearances up */ XMoveResizeWindow(obt_display, self->bg, x, y, w, h); /* when there is no icon and the text is not parent relative, then fill the whole dialog with the text appearance, don't use the bg at all */ if (hasicon || self->a_text->surface.grad == RR_SURFACE_PARENTREL) RrPaint(self->a_bg, self->bg, w, h); if (textw) { self->a_text->surface.parent = self->a_bg; self->a_text->surface.parentx = textx; self->a_text->surface.parenty = texty; XMoveResizeWindow(obt_display, self->text, textx, texty, textw, texth); RrPaint(self->a_text, self->text, textw, texth); } if (hasicon) self->draw_icon(iconx, icony, iconw, iconh, self->draw_icon_data); /* do the actual showing */ if (!self->mapped) { if (msec) { /* don't kill previous show timers */ if (!self->delay_mapped) { self->delay_timer = g_timeout_add(msec, popup_show_timeout, self); self->delay_mapped = TRUE; } } else { popup_show_timeout(self); } } }
static void prompt_layout(ObPrompt *self) { gint l, r, t, b; gint i; gint allbuttonsw, allbuttonsh, buttonx; gint w, h; gint maxw; RrMargins(prompt_a_bg, &l, &t, &r, &b); l += OUTSIDE_MARGIN; t += OUTSIDE_MARGIN; r += OUTSIDE_MARGIN; b += OUTSIDE_MARGIN; { const Rect *area = screen_physical_area_all_monitors(); maxw = MIN(MAX_WIDTH, area->width*4/5); } /* find the button sizes and how much space we need for them */ allbuttonsw = allbuttonsh = 0; for (i = 0; i < self->n_buttons; ++i) { gint bw, bh; prompt_a_button->texture[0].data.text.string = self->button[i].text; prompt_a_focus->texture[0].data.text.string = self->button[i].text; prompt_a_press->texture[0].data.text.string = self->button[i].text; prompt_a_pfocus->texture[0].data.text.string = self->button[i].text; RrMinSize(prompt_a_button, &bw, &bh); self->button[i].width = bw; self->button[i].height = bh; RrMinSize(prompt_a_focus, &bw, &bh); self->button[i].width = MAX(self->button[i].width, bw); self->button[i].height = MAX(self->button[i].height, bh); RrMinSize(prompt_a_press, &bw, &bh); self->button[i].width = MAX(self->button[i].width, bw); self->button[i].height = MAX(self->button[i].height, bh); RrMinSize(prompt_a_pfocus, &bw, &bh); self->button[i].width = MAX(self->button[i].width, bw); self->button[i].height = MAX(self->button[i].height, bh); self->button[i].width += BUTTON_HMARGIN * 2; self->button[i].height += BUTTON_VMARGIN * 2; allbuttonsw += self->button[i].width + (i > 0 ? BUTTON_SEPARATION : 0); allbuttonsh = MAX(allbuttonsh, self->button[i].height); } self->msg_wbound = MAX(allbuttonsw, maxw); /* measure the text message area */ prompt_a_msg->texture[0].data.text.string = self->msg.text; prompt_a_msg->texture[0].data.text.maxwidth = self->msg_wbound; RrMinSize(prompt_a_msg, &self->msg.width, &self->msg.height); /* width and height inside the outer margins */ w = MAX(self->msg.width, allbuttonsw); h = self->msg.height + MSG_BUTTON_SEPARATION + allbuttonsh; /* position the text message */ self->msg.x = l + (w - self->msg.width) / 2; self->msg.y = t; /* position the button buttons on the right of the dialog */ buttonx = l + w; for (i = self->n_buttons - 1; i >= 0; --i) { self->button[i].x = buttonx - self->button[i].width; buttonx -= self->button[i].width + BUTTON_SEPARATION; self->button[i].y = t + h - allbuttonsh; self->button[i].y += (allbuttonsh - self->button[i].height) / 2; } /* size and position the toplevel window */ prompt_resize(self, w + l + r, h + t + b); /* move and resize the internal windows */ XMoveResizeWindow(obt_display, self->msg.window, self->msg.x, self->msg.y, self->msg.width, self->msg.height); for (i = 0; i < self->n_buttons; ++i) XMoveResizeWindow(obt_display, self->button[i].window, self->button[i].x, self->button[i].y, self->button[i].width, self->button[i].height); }