- char *lc;
- int x;
- gboolean n, d, i, l, m, c, s;
-
- n = d = i = l = m = c = s = FALSE;
-
- /* figure out whats being shown, and the width of the label */
- self->label_width = self->width - (ob_rr_theme->padding + 1) * 2;
- for (lc = config_title_layout; *lc != '\0'; ++lc) {
- switch (*lc) {
- case 'N':
- if (n) { *lc = ' '; break; } /* rm duplicates */
- n = TRUE;
- self->label_width -= (ob_rr_theme->button_size + 2 +
- ob_rr_theme->padding + 1);
- break;
- case 'D':
- if (d) { *lc = ' '; break; } /* rm duplicates */
- d = TRUE;
- self->label_width -= (ob_rr_theme->button_size +
- ob_rr_theme->padding + 1);
- break;
- case 'S':
- if (s) { *lc = ' '; break; } /* rm duplicates */
- s = TRUE;
- self->label_width -= (ob_rr_theme->button_size +
- ob_rr_theme->padding + 1);
- break;
- case 'I':
- if (i) { *lc = ' '; break; } /* rm duplicates */
- i = TRUE;
- self->label_width -= (ob_rr_theme->button_size +
- ob_rr_theme->padding + 1);
- break;
- case 'L':
- if (l) { *lc = ' '; break; } /* rm duplicates */
- l = TRUE;
- break;
- case 'M':
- if (m) { *lc = ' '; break; } /* rm duplicates */
- m = TRUE;
- self->label_width -= (ob_rr_theme->button_size +
- ob_rr_theme->padding + 1);
- break;
- case 'C':
- if (c) { *lc = ' '; break; } /* rm duplicates */
- c = TRUE;
- self->label_width -= (ob_rr_theme->button_size +
- ob_rr_theme->padding + 1);
- break;
- }
- }
- if (self->label_width < 1) self->label_width = 1;
-
- XResizeWindow(ob_display, self->label, self->label_width,
- ob_rr_theme->label_height);
-
- if (!n) XUnmapWindow(ob_display, self->icon);
- if (!d) XUnmapWindow(ob_display, self->desk);
- if (!s) XUnmapWindow(ob_display, self->shade);
- if (!i) XUnmapWindow(ob_display, self->iconify);
- if (!l) XUnmapWindow(ob_display, self->label);
- if (!m) XUnmapWindow(ob_display, self->max);
- if (!c) XUnmapWindow(ob_display, self->close);
-
- x = ob_rr_theme->padding + 1;
- for (lc = config_title_layout; *lc != '\0'; ++lc) {
- switch (*lc) {
- case 'N':
- if (!n) break;
- self->icon_x = x;
- XMapWindow(ob_display, self->icon);
- XMoveWindow(ob_display, self->icon, x, ob_rr_theme->padding);
- x += ob_rr_theme->button_size + 2 + ob_rr_theme->padding + 1;
- break;
- case 'D':
- if (!d) break;
- self->desk_x = x;
- XMapWindow(ob_display, self->desk);
- XMoveWindow(ob_display, self->desk, x, ob_rr_theme->padding + 1);
- x += ob_rr_theme->button_size + ob_rr_theme->padding + 1;
- break;
- case 'S':
- if (!s) break;
- self->shade_x = x;
- XMapWindow(ob_display, self->shade);
- XMoveWindow(ob_display, self->shade, x, ob_rr_theme->padding + 1);
- x += ob_rr_theme->button_size + ob_rr_theme->padding + 1;
- break;
- case 'I':
- if (!i) break;
- self->iconify_x = x;
- XMapWindow(ob_display, self->iconify);
- XMoveWindow(ob_display,self->iconify, x, ob_rr_theme->padding + 1);
- x += ob_rr_theme->button_size + ob_rr_theme->padding + 1;
- break;
- case 'L':
- if (!l) break;
- self->label_x = x;
- XMapWindow(ob_display, self->label);
- XMoveWindow(ob_display, self->label, x, ob_rr_theme->padding);
- x += self->label_width + ob_rr_theme->padding + 1;
- break;
- case 'M':
- if (!m) break;
- self->max_x = x;
- XMapWindow(ob_display, self->max);
- XMoveWindow(ob_display, self->max, x, ob_rr_theme->padding + 1);
- x += ob_rr_theme->button_size + ob_rr_theme->padding + 1;
- break;
- case 'C':
- if (!c) break;
- self->close_x = x;
- XMapWindow(ob_display, self->close);
- XMoveWindow(ob_display, self->close, x, ob_rr_theme->padding + 1);
- x += ob_rr_theme->button_size + ob_rr_theme->padding + 1;
- break;
- }
+ gchar *lc;
+ gint i;
+
+ const gint bwidth = ob_rr_theme->button_size + ob_rr_theme->paddingx + 1;
+ /* position of the leftmost button */
+ const gint left = ob_rr_theme->paddingx + 1;
+ /* position of the rightmost 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 shown, 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;
+ /* icon is bigger than buttons */
+ place_button(self, lc, bwidth + 2, left, i, &x, &self->icon_on, &self->icon_x);
+ } else if (*lc == 'D') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_ALLDESKTOPS;
+ place_button(self, lc, bwidth, left, i, &x, &self->desk_on, &self->desk_x);
+ } else if (*lc == 'S') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_SHADE;
+ place_button(self, lc, bwidth, left, i, &x, &self->shade_on, &self->shade_x);
+ } else if (*lc == 'I') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_ICONIFY;
+ place_button(self, lc, bwidth, left, i, &x, &self->iconify_on, &self->iconify_x);
+ } else if (*lc == 'M') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_MAXIMIZE;
+ place_button(self, lc, bwidth, left, i, &x, &self->max_on, &self->max_x);
+ } else if (*lc == 'C') {
+ if (firstcon) *firstcon = OB_FRAME_CONTEXT_CLOSE;
+ place_button(self, lc, bwidth, left, i, &x, &self->close_on, &self->close_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 > 0) {
+ XMapWindow(obt_display, self->label);
+ XMoveWindow(obt_display, self->label, self->label_x,
+ ob_rr_theme->paddingy);
+ } else
+ XUnmapWindow(obt_display, self->label);
+}
+
+gboolean frame_next_context_from_string(gchar *names, ObFrameContext *cx)
+{
+ gchar *p, *n;
+
+ if (!*names) /* empty string */
+ return FALSE;
+
+ /* find the first space */
+ for (p = names; *p; p = g_utf8_next_char(p)) {
+ const gunichar c = g_utf8_get_char(p);
+ if (g_unichar_isspace(c)) break;
+ }
+
+ if (p == names) {
+ /* leading spaces in the string */
+ n = g_utf8_next_char(names);
+ if (!frame_next_context_from_string(n, cx))
+ return FALSE;
+ } else {
+ n = p;
+ if (*p) {
+ /* delete the space with null zero(s) */
+ while (n < g_utf8_next_char(p))
+ *(n++) = '\0';
+ }
+
+ *cx = frame_context_from_string(names);
+
+ /* find the next non-space */
+ for (; *n; n = g_utf8_next_char(n)) {
+ const gunichar c = g_utf8_get_char(n);
+ if (!g_unichar_isspace(c)) break;
+ }