- /* remove all the windows for the frame from the window_map */
- g_hash_table_remove(window_map, &self->window);
- g_hash_table_remove(window_map, &self->plate);
- g_hash_table_remove(window_map, &self->title);
- g_hash_table_remove(window_map, &self->label);
- g_hash_table_remove(window_map, &self->max);
- g_hash_table_remove(window_map, &self->close);
- g_hash_table_remove(window_map, &self->desk);
- g_hash_table_remove(window_map, &self->shade);
- g_hash_table_remove(window_map, &self->icon);
- g_hash_table_remove(window_map, &self->iconify);
- g_hash_table_remove(window_map, &self->handle);
- g_hash_table_remove(window_map, &self->lgrip);
- g_hash_table_remove(window_map, &self->rgrip);
-
- frame_free(self);
-}
-
-static void layout_title(Frame *self)
-{
- 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 - (theme_bevel + 1) * 2;
- for (lc = theme_title_layout; *lc != '\0'; ++lc) {
- switch (*lc) {
- case 'N':
- if (!(self->client->decorations & Decor_Icon)) break;
- if (n) { *lc = ' '; break; } /* rm duplicates */
- n = TRUE;
- self->label_width -= theme_button_size + 2 + theme_bevel + 1;
- break;
- case 'D':
- if (!(self->client->decorations & Decor_AllDesktops)) break;
- if (d) { *lc = ' '; break; } /* rm duplicates */
- d = TRUE;
- self->label_width -= theme_button_size + theme_bevel + 1;
- break;
- case 'S':
- if (!(self->client->decorations & Decor_Shade)) break;
- if (s) { *lc = ' '; break; } /* rm duplicates */
- s = TRUE;
- self->label_width -= theme_button_size + theme_bevel + 1;
- break;
- case 'I':
- if (!(self->client->decorations & Decor_Iconify)) break;
- if (i) { *lc = ' '; break; } /* rm duplicates */
- i = TRUE;
- self->label_width -= theme_button_size + theme_bevel + 1;
- break;
- case 'L':
- if (l) { *lc = ' '; break; } /* rm duplicates */
- l = TRUE;
- break;
- case 'M':
- if (!(self->client->decorations & Decor_Maximize)) break;
- if (m) { *lc = ' '; break; } /* rm duplicates */
- m = TRUE;
- self->label_width -= theme_button_size + theme_bevel + 1;
- break;
- case 'C':
- if (!(self->client->decorations & Decor_Close)) break;
- if (c) { *lc = ' '; break; } /* rm duplicates */
- c = TRUE;
- self->label_width -= theme_button_size + theme_bevel + 1;
- break;
- }
- }
- if (self->label_width < 1) self->label_width = 1;
-
- XResizeWindow(ob_display, self->label, self->label_width,
- 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 = theme_bevel + 1;
- for (lc = theme_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, theme_bevel);
- x += theme_button_size + 2 + theme_bevel + 1;
- break;
- case 'D':
- if (!d) break;
- self->desk_x = x;
- XMapWindow(ob_display, self->desk);
- XMoveWindow(ob_display, self->desk, x, theme_bevel + 1);
- x += theme_button_size + theme_bevel + 1;
- break;
- case 'S':
- if (!s) break;
- self->shade_x = x;
- XMapWindow(ob_display, self->shade);
- XMoveWindow(ob_display, self->shade, x, theme_bevel + 1);
- x += theme_button_size + theme_bevel + 1;
- break;
- case 'I':
- if (!i) break;
- self->iconify_x = x;
- XMapWindow(ob_display, self->iconify);
- XMoveWindow(ob_display, self->iconify, x, theme_bevel + 1);
- x += theme_button_size + theme_bevel + 1;
- break;
- case 'L':
- if (!l) break;
- self->label_x = x;
- XMapWindow(ob_display, self->label);
- XMoveWindow(ob_display, self->label, x, theme_bevel);
- x += self->label_width + theme_bevel + 1;
- break;
- case 'M':
- if (!m) break;
- self->max_x = x;
- XMapWindow(ob_display, self->max);
- XMoveWindow(ob_display, self->max, x, theme_bevel + 1);
- x += theme_button_size + theme_bevel + 1;
- break;
- case 'C':
- if (!c) break;
- self->close_x = x;
- XMapWindow(ob_display, self->close);
- XMoveWindow(ob_display, self->close, x, theme_bevel + 1);
- x += theme_button_size + theme_bevel + 1;
- break;
- }
- }
-}
-
-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 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;
+ }
+ }
+
+ /* delete everything we just read (copy everything at n to the start of
+ the string */
+ for (p = names; *n; ++p, ++n)
+ *p = *n;
+ *p = *n;
+
+ return TRUE;
+}
+
+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;
+ else if (!g_ascii_strcasecmp("Dock", name))
+ return OB_FRAME_CONTEXT_DOCK;
+
+ return OB_FRAME_CONTEXT_NONE;
+}
+
+ObFrameContext frame_context(ObClient *client, Window win, gint x, gint y)
+{
+ ObFrame *self;
+ ObWindow *obwin;
+
+ if (moveresize_in_progress)
+ return OB_FRAME_CONTEXT_MOVE_RESIZE;
+
+ if (win == obt_root(ob_screen))
+ return OB_FRAME_CONTEXT_ROOT;
+ if ((obwin = window_find(win))) {
+ if (WINDOW_IS_DOCK(obwin)) {
+ return OB_FRAME_CONTEXT_DOCK;
+ }
+ }
+ 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;
+ }