+
+ /* remove all the windows for the frame from the window_map */
+ window_remove(self->window);
+ window_remove(self->backback);
+ window_remove(self->backfront);
+ window_remove(self->innerleft);
+ window_remove(self->innertop);
+ window_remove(self->innerright);
+ window_remove(self->innerbottom);
+ window_remove(self->innerblb);
+ window_remove(self->innerbll);
+ window_remove(self->innerbrb);
+ window_remove(self->innerbrr);
+ window_remove(self->title);
+ window_remove(self->label);
+ window_remove(self->max);
+ window_remove(self->close);
+ window_remove(self->desk);
+ window_remove(self->shade);
+ window_remove(self->icon);
+ window_remove(self->iconify);
+ window_remove(self->handle);
+ window_remove(self->lgrip);
+ window_remove(self->rgrip);
+ window_remove(self->topresize);
+ window_remove(self->tltresize);
+ window_remove(self->tllresize);
+ window_remove(self->trtresize);
+ window_remove(self->trrresize);
+ window_remove(self->left);
+ window_remove(self->right);
+ window_remove(self->titleleft);
+ window_remove(self->titletop);
+ window_remove(self->titletopleft);
+ window_remove(self->titletopright);
+ window_remove(self->titleright);
+ window_remove(self->titlebottom);
+ window_remove(self->handleleft);
+ window_remove(self->handletop);
+ window_remove(self->handleright);
+ window_remove(self->handlebottom);
+ window_remove(self->lgripleft);
+ window_remove(self->lgriptop);
+ window_remove(self->lgripbottom);
+ window_remove(self->rgripright);
+ window_remove(self->rgriptop);
+ window_remove(self->rgripbottom);
+
+ obt_main_loop_timeout_remove_data(ob_main_loop, flash_timeout, self, TRUE);
+}
+
+/* is there anything present between us and the label? */
+static gboolean is_button_present(ObFrame *self, const gchar *lc, gint dir) {
+ for (; *lc != '\0' && lc >= config_title_layout; lc += dir) {
+ if (*lc == ' ') continue; /* it was invalid */
+ if (*lc == 'N' && self->decorations & OB_FRAME_DECOR_ICON)
+ return TRUE;
+ if (*lc == 'D' && self->decorations & OB_FRAME_DECOR_ALLDESKTOPS)
+ return TRUE;
+ if (*lc == 'S' && self->decorations & OB_FRAME_DECOR_SHADE)
+ return TRUE;
+ if (*lc == 'I' && self->decorations & OB_FRAME_DECOR_ICONIFY)
+ return TRUE;
+ if (*lc == 'M' && self->decorations & OB_FRAME_DECOR_MAXIMIZE)
+ return TRUE;
+ if (*lc == 'C' && self->decorations & OB_FRAME_DECOR_CLOSE)
+ return TRUE;
+ if (*lc == 'L') return FALSE;
+ }
+ return FALSE;
+}
+
+static void layout_title(ObFrame *self)
+{
+ gchar *lc;
+ gint i;
+
+ const gint bwidth = ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
+ /* position of the left most button */
+ const gint left = ob_rr_theme->paddingx + 1;
+ /* position of the right most button */
+ const gint right = self->width;
+
+ /* turn them all off */
+ self->icon_on = self->desk_on = self->shade_on = self->iconify_on =
+ self->max_on = self->close_on = self->label_on = FALSE;
+ self->label_width = self->width - (ob_rr_theme->paddingx + 1) * 2;
+ self->leftmost = self->rightmost = OB_FRAME_CONTEXT_NONE;
+
+ /* figure out what's being show, find each element's position, and the
+ width of the label
+
+ do the ones before the label, then after the label,
+ i will be +1 the first time through when working to the left,
+ and -1 the second time through when working to the right */
+ for (i = 1; i >= -1; i-=2) {
+ gint x;
+ ObFrameContext *firstcon;
+
+ if (i > 0) {
+ x = left;
+ lc = config_title_layout;
+ firstcon = &self->leftmost;
+ } else {
+ x = right;
+ lc = config_title_layout + strlen(config_title_layout)-1;
+ firstcon = &self->rightmost;
+ }
+
+ /* stop at the end of the string (or the label, which calls break) */
+ for (; *lc != '\0' && lc >= config_title_layout; lc+=i) {
+ if (*lc == 'L') {
+ if (i > 0) {
+ self->label_on = TRUE;
+ self->label_x = x;
+ }
+ break; /* break the for loop, do other side of label */
+ } else if (*lc == 'N') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICON;
+ if ((self->icon_on = is_button_present(self, lc, i))) {
+ /* icon is bigger than buttons */
+ self->label_width -= bwidth + 2;
+ if (i > 0) self->icon_x = x;
+ x += i * (bwidth + 2);
+ if (i < 0) self->icon_x = x;
+ }
+ } else if (*lc == 'D') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_ALLDESKTOPS;
+ if ((self->desk_on = is_button_present(self, lc, i))) {
+ self->label_width -= bwidth;
+ if (i > 0) self->desk_x = x;
+ x += i * bwidth;
+ if (i < 0) self->desk_x = x;
+ }
+ } else if (*lc == 'S') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_SHADE;
+ if ((self->shade_on = is_button_present(self, lc, i))) {
+ self->label_width -= bwidth;
+ if (i > 0) self->shade_x = x;
+ x += i * bwidth;
+ if (i < 0) self->shade_x = x;
+ }
+ } else if (*lc == 'I') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICONIFY;
+ if ((self->iconify_on = is_button_present(self, lc, i))) {
+ self->label_width -= bwidth;
+ if (i > 0) self->iconify_x = x;
+ x += i * bwidth;
+ if (i < 0) self->iconify_x = x;
+ }
+ } else if (*lc == 'M') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_MAXIMIZE;
+ if ((self->max_on = is_button_present(self, lc, i))) {
+ self->label_width -= bwidth;
+ if (i > 0) self->max_x = x;
+ x += i * bwidth;
+ if (i < 0) self->max_x = x;
+ }
+ } else if (*lc == 'C') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_CLOSE;
+ if ((self->close_on = is_button_present(self, lc, i))) {
+ self->label_width -= bwidth;
+ if (i > 0) self->close_x = x;
+ x += i * bwidth;
+ if (i < 0) self->close_x = x;
+ }
+ } else
+ continue; /* don't set firstcon */
+ firstcon = NULL;
+ }
+ }
+
+ /* position and map the elements */
+ if (self->icon_on) {
+ XMapWindow(obt_display, self->icon);
+ XMoveWindow(obt_display, self->icon, self->icon_x,
+ ob_rr_theme->paddingy);
+ } else
+ XUnmapWindow(obt_display, self->icon);
+
+ if (self->desk_on) {
+ XMapWindow(obt_display, self->desk);
+ XMoveWindow(obt_display, self->desk, self->desk_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(obt_display, self->desk);
+
+ if (self->shade_on) {
+ XMapWindow(obt_display, self->shade);
+ XMoveWindow(obt_display, self->shade, self->shade_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(obt_display, self->shade);
+
+ if (self->iconify_on) {
+ XMapWindow(obt_display, self->iconify);
+ XMoveWindow(obt_display, self->iconify, self->iconify_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(obt_display, self->iconify);
+
+ if (self->max_on) {
+ XMapWindow(obt_display, self->max);
+ XMoveWindow(obt_display, self->max, self->max_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(obt_display, self->max);
+
+ if (self->close_on) {
+ XMapWindow(obt_display, self->close);
+ XMoveWindow(obt_display, self->close, self->close_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(obt_display, self->close);
+
+ if (self->label_on) {
+ self->label_width = MAX(1, self->label_width); /* no lower than 1 */
+ XMapWindow(obt_display, self->label);
+ XMoveWindow(obt_display, self->label, self->label_x,
+ ob_rr_theme->paddingy);
+ } else
+ XUnmapWindow(obt_display, self->label);
+}
+
+ObFrameContext frame_context_from_string(const gchar *name)
+{
+ if (!g_ascii_strcasecmp("Desktop", name))
+ return OB_FRAME_CONTEXT_DESKTOP;
+ else if (!g_ascii_strcasecmp("Root", name))
+ return OB_FRAME_CONTEXT_ROOT;
+ else if (!g_ascii_strcasecmp("Client", name))
+ return OB_FRAME_CONTEXT_CLIENT;
+ else if (!g_ascii_strcasecmp("Titlebar", name))
+ return OB_FRAME_CONTEXT_TITLEBAR;
+ else if (!g_ascii_strcasecmp("Frame", name))
+ return OB_FRAME_CONTEXT_FRAME;
+ else if (!g_ascii_strcasecmp("TLCorner", name))
+ return OB_FRAME_CONTEXT_TLCORNER;
+ else if (!g_ascii_strcasecmp("TRCorner", name))
+ return OB_FRAME_CONTEXT_TRCORNER;
+ else if (!g_ascii_strcasecmp("BLCorner", name))
+ return OB_FRAME_CONTEXT_BLCORNER;
+ else if (!g_ascii_strcasecmp("BRCorner", name))
+ return OB_FRAME_CONTEXT_BRCORNER;
+ else if (!g_ascii_strcasecmp("Top", name))
+ return OB_FRAME_CONTEXT_TOP;
+ else if (!g_ascii_strcasecmp("Bottom", name))
+ return OB_FRAME_CONTEXT_BOTTOM;
+ else if (!g_ascii_strcasecmp("Left", name))
+ return OB_FRAME_CONTEXT_LEFT;
+ else if (!g_ascii_strcasecmp("Right", name))
+ return OB_FRAME_CONTEXT_RIGHT;
+ else if (!g_ascii_strcasecmp("Maximize", name))
+ return OB_FRAME_CONTEXT_MAXIMIZE;
+ else if (!g_ascii_strcasecmp("AllDesktops", name))
+ return OB_FRAME_CONTEXT_ALLDESKTOPS;
+ else if (!g_ascii_strcasecmp("Shade", name))
+ return OB_FRAME_CONTEXT_SHADE;
+ else if (!g_ascii_strcasecmp("Iconify", name))
+ return OB_FRAME_CONTEXT_ICONIFY;
+ else if (!g_ascii_strcasecmp("Icon", name))
+ return OB_FRAME_CONTEXT_ICON;
+ else if (!g_ascii_strcasecmp("Close", name))
+ return OB_FRAME_CONTEXT_CLOSE;
+ else if (!g_ascii_strcasecmp("MoveResize", name))
+ return OB_FRAME_CONTEXT_MOVE_RESIZE;
+ return OB_FRAME_CONTEXT_NONE;
+}
+
+ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
+{
+ ObFrame *self;
+
+ if (moveresize_in_progress)
+ return OB_FRAME_CONTEXT_MOVE_RESIZE;
+
+ if (win == obt_root(ob_screen))
+ return OB_FRAME_CONTEXT_ROOT ;
+ if (client == NULL) return OB_FRAME_CONTEXT_NONE;
+ if (win == client->window) {
+ /* conceptually, this is the desktop, as far as users are
+ concerned */
+ if (client->type == OB_CLIENT_TYPE_DESKTOP)
+ return OB_FRAME_CONTEXT_DESKTOP;
+ return OB_FRAME_CONTEXT_CLIENT;
+ }
+
+ self = client->frame;
+
+ /* when the user clicks in the corners of the titlebar and the client
+ is fully maximized, then treat it like they clicked in the
+ button that is there */
+ if (self->max_horz && self->max_vert &&
+ (win == self->title || win == self->titletop ||
+ win == self->titleleft || win == self->titletopleft ||
+ win == self->titleright || win == self->titletopright))
+ {
+ /* get the mouse coords in reference to the whole frame */
+ gint fx = x;
+ gint fy = y;
+
+ /* these windows are down a border width from the top of the frame */
+ if (win == self->title ||
+ win == self->titleleft || win == self->titleright)
+ fy += self->bwidth;
+
+ /* title is a border width in from the edge */
+ if (win == self->title)
+ fx += self->bwidth;
+ /* titletop is a bit to the right */
+ else if (win == self->titletop)
+ fx += ob_rr_theme->grip_width + self->bwidth;
+ /* titletopright is way to the right edge */
+ else if (win == self->titletopright)
+ fx += self->area.width - (ob_rr_theme->grip_width + self->bwidth);
+ /* titleright is even more way to the right edge */
+ else if (win == self->titleright)
+ fx += self->area.width - self->bwidth;
+
+ /* figure out if we're over the area that should be considered a
+ button */
+ if (fy < self->bwidth + ob_rr_theme->paddingy + 1 +
+ ob_rr_theme->button_size)
+ {
+ if (fx < (self->bwidth + ob_rr_theme->paddingx + 1 +
+ ob_rr_theme->button_size))
+ {
+ if (self->leftmost != OB_FRAME_CONTEXT_NONE)
+ return self->leftmost;
+ }
+ else if (fx >= (self->area.width -
+ (self->bwidth + ob_rr_theme->paddingx + 1 +
+ ob_rr_theme->button_size)))
+ {
+ if (self->rightmost != OB_FRAME_CONTEXT_NONE)
+ return self->rightmost;
+ }
+ }
+
+ /* there is no resizing maximized windows so make them the titlebar
+ context */
+ return OB_FRAME_CONTEXT_TITLEBAR;