- RECT_SET(self->a_focused_label->area, 0, 0,
- self->label_width, theme_label_height);
- RECT_SET(self->a_unfocused_label->area, 0, 0,
- self->label_width, theme_label_height);
-}
-
-Context frame_context_from_string(char *name)
-{
- if (!g_ascii_strcasecmp("root", name))
- return Context_Root;
- else if (!g_ascii_strcasecmp("client", name))
- return Context_Client;
- else if (!g_ascii_strcasecmp("titlebar", name))
- return Context_Titlebar;
- else if (!g_ascii_strcasecmp("handle", name))
- return Context_Handle;
- else if (!g_ascii_strcasecmp("frame", name))
- return Context_Frame;
- else if (!g_ascii_strcasecmp("blcorner", name))
- return Context_BLCorner;
- else if (!g_ascii_strcasecmp("tlcorner", name))
- return Context_TLCorner;
- else if (!g_ascii_strcasecmp("brcorner", name))
- return Context_BRCorner;
- else if (!g_ascii_strcasecmp("trcorner", name))
- return Context_TRCorner;
- else if (!g_ascii_strcasecmp("maximize", name))
- return Context_Maximize;
- else if (!g_ascii_strcasecmp("alldesktops", name))
- return Context_AllDesktops;
- else if (!g_ascii_strcasecmp("shade", name))
- return Context_Shade;
- else if (!g_ascii_strcasecmp("iconify", name))
- return Context_Iconify;
- else if (!g_ascii_strcasecmp("icon", name))
- return Context_Icon;
- else if (!g_ascii_strcasecmp("close", name))
- return Context_Close;
- return Context_None;
-}
-
-Context frame_context(Client *client, Window win)
-{
- Frame *self;
-
- if (win == ob_root) return Context_Root;
- if (client == NULL) return Context_None;
- if (win == client->window) return Context_Client;
+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(ob_display, self->icon);
+ XMoveWindow(ob_display, self->icon, self->icon_x,
+ ob_rr_theme->paddingy);
+ } else
+ XUnmapWindow(ob_display, self->icon);
+
+ if (self->desk_on) {
+ XMapWindow(ob_display, self->desk);
+ XMoveWindow(ob_display, self->desk, self->desk_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(ob_display, self->desk);
+
+ if (self->shade_on) {
+ XMapWindow(ob_display, self->shade);
+ XMoveWindow(ob_display, self->shade, self->shade_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(ob_display, self->shade);
+
+ if (self->iconify_on) {
+ XMapWindow(ob_display, self->iconify);
+ XMoveWindow(ob_display, self->iconify, self->iconify_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(ob_display, self->iconify);
+
+ if (self->max_on) {
+ XMapWindow(ob_display, self->max);
+ XMoveWindow(ob_display, self->max, self->max_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(ob_display, self->max);
+
+ if (self->close_on) {
+ XMapWindow(ob_display, self->close);
+ XMoveWindow(ob_display, self->close, self->close_x,
+ ob_rr_theme->paddingy + 1);
+ } else
+ XUnmapWindow(ob_display, self->close);
+
+ if (self->label_on) {
+ self->label_width = MAX(1, self->label_width); /* no lower than 1 */
+ XMapWindow(ob_display, self->label);
+ XMoveWindow(ob_display, self->label, self->label_x,
+ ob_rr_theme->paddingy);
+ } else
+ XUnmapWindow(ob_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 == RootWindow(ob_display, 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;
+ }