X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=engines%2Fopenbox%2Fopenbox.c;h=69888b42c6e12cd3b68885758943792344d6f16d;hb=1b20f591af578f0b9dea7c13b4de8f15ab1074af;hp=fdab22a31a5ecf0d2cc8a8df8a6db787f7f834d6;hpb=f8a47de5ec444c452093371e3db16857eb39a490;p=chaz%2Fopenbox diff --git a/engines/openbox/openbox.c b/engines/openbox/openbox.c index fdab22a3..69888b42 100644 --- a/engines/openbox/openbox.c +++ b/engines/openbox/openbox.c @@ -2,16 +2,19 @@ #include "../../kernel/openbox.h" #include "../../kernel/screen.h" #include "../../kernel/extensions.h" -#include "../../kernel/themerc.h" +#include "../../kernel/dispatch.h" +#include "../../kernel/config.h" #include "../../kernel/frame.h" #include "../../render/render.h" #include "../../render/color.h" +#include "../../render/font.h" +#include "../../render/mask.h" #include #include -#define TITLE_HEIGHT (s_font_height + s_bevel * 2) -#define LABEL_HEIGHT (s_font_height) +#define LABEL_HEIGHT (s_winfont_height + 2) +#define TITLE_HEIGHT (LABEL_HEIGHT + s_bevel * 2) #define HANDLE_Y(f) (f->innersize.top + f->frame.client->area.height + \ f->cbwidth) #define BUTTON_SIZE (LABEL_HEIGHT - 2) @@ -20,9 +23,10 @@ #define PLATE_EVENTMASK (SubstructureRedirectMask | ButtonPressMask) #define FRAME_EVENTMASK (EnterWindowMask | LeaveWindowMask) +#define ELEMENT_EVENTMASK (ButtonPressMask | ButtonReleaseMask | \ + ButtonMotionMask | ExposureMask) /* style settings - geometry */ -int s_font_height; int s_bevel; int s_handle_height; int s_bwidth; @@ -31,6 +35,20 @@ int s_cbwidth; color_rgb *s_b_color; color_rgb *s_cb_focused_color; color_rgb *s_cb_unfocused_color; +color_rgb *s_title_focused_color; +color_rgb *s_title_unfocused_color; +color_rgb *s_titlebut_focused_color; +color_rgb *s_titlebut_unfocused_color; +/* style settings - fonts */ +int s_winfont_height; +int s_winfont_shadow; +int s_winfont_shadow_offset; +ObFont *s_winfont; +/* style settings - masks */ +pixmap_mask *s_max_mask; +pixmap_mask *s_icon_mask; +pixmap_mask *s_desk_mask; +pixmap_mask *s_close_mask; /* global appearances */ Appearance *a_focused_unpressed_max; @@ -111,6 +129,9 @@ static void render_iconify(ObFrame *self); static void render_desk(ObFrame *self); static void render_close(ObFrame *self); +static void frame_mouse_press(const ObEvent *e, ObFrame *self); +static void frame_mouse_release(const ObEvent *e, ObFrame *self); + gboolean startup() { g_quark_from_string("none"); @@ -127,12 +148,16 @@ gboolean startup() g_quark_from_string("icon"); g_quark_from_string("close"); - s_b_color = s_cb_unfocused_color = s_cb_focused_color = NULL; + s_b_color = s_cb_unfocused_color = s_cb_focused_color = + s_title_unfocused_color = s_title_focused_color = + s_titlebut_unfocused_color = s_titlebut_focused_color = NULL; + s_winfont = NULL; + s_max_mask = s_icon_mask = s_desk_mask = s_close_mask = NULL; - a_focused_unpressed_max = appearance_new(Surface_Planar, 0);//1); - a_focused_pressed_max = appearance_new(Surface_Planar, 0);//1); - a_unfocused_unpressed_max = appearance_new(Surface_Planar, 0);//1); - a_unfocused_pressed_max = appearance_new(Surface_Planar, 0);//1); + a_focused_unpressed_max = appearance_new(Surface_Planar, 1); + a_focused_pressed_max = appearance_new(Surface_Planar, 1); + a_unfocused_unpressed_max = appearance_new(Surface_Planar, 1); + a_unfocused_pressed_max = appearance_new(Surface_Planar, 1); a_focused_unpressed_close = NULL; a_focused_pressed_close = NULL; a_unfocused_unpressed_close = NULL; @@ -149,9 +174,9 @@ gboolean startup() a_unfocused_grip = appearance_new(Surface_Planar, 0); a_focused_title = appearance_new(Surface_Planar, 0); a_unfocused_title = appearance_new(Surface_Planar, 0); - a_focused_label = appearance_new(Surface_Planar, 0);//1); - a_unfocused_label = appearance_new(Surface_Planar, 0);//1); - a_icon = appearance_new(Surface_Planar, 0);//1); + a_focused_label = appearance_new(Surface_Planar, 1); + a_unfocused_label = appearance_new(Surface_Planar, 1); + a_icon = appearance_new(Surface_Planar, 1); a_focused_handle = appearance_new(Surface_Planar, 0); a_unfocused_handle = appearance_new(Surface_Planar, 0); @@ -163,6 +188,19 @@ void shutdown() if (s_b_color != NULL) color_free(s_b_color); if (s_cb_unfocused_color != NULL) color_free(s_cb_unfocused_color); if (s_cb_focused_color != NULL) color_free(s_cb_focused_color); + if (s_title_unfocused_color != NULL) color_free(s_title_unfocused_color); + if (s_title_focused_color != NULL) color_free(s_title_focused_color); + if (s_titlebut_unfocused_color != NULL) + color_free(s_titlebut_unfocused_color); + if (s_titlebut_focused_color != NULL) + color_free(s_titlebut_focused_color); + + if (s_max_mask != NULL) pixmap_mask_free(s_max_mask); + if (s_desk_mask != NULL) pixmap_mask_free(s_desk_mask); + if (s_icon_mask != NULL) pixmap_mask_free(s_icon_mask); + if (s_close_mask != NULL) pixmap_mask_free(s_close_mask); + + if (s_winfont != NULL) font_close(s_winfont); appearance_free(a_focused_unpressed_max); appearance_free(a_focused_pressed_max); @@ -206,10 +244,8 @@ void shutdown() static Window createWindow(Window parent, unsigned long mask, XSetWindowAttributes *attrib) { - /* XXX DONT USE THE DEFAULT SHIT */ return XCreateWindow(ob_display, parent, 0, 0, 1, 1, 0, - DefaultDepth(ob_display, ob_screen), InputOutput, - DefaultVisual(ob_display, ob_screen), + render_depth, InputOutput, render_visual, mask, attrib); } @@ -234,8 +270,7 @@ Frame *frame_new() self->frame.plate = createWindow(self->frame.window, mask, &attrib); mask = CWEventMask; - attrib.event_mask = (ButtonPressMask | ButtonReleaseMask | - ButtonMotionMask | ExposureMask); + attrib.event_mask = ELEMENT_EVENTMASK; self->title = createWindow(self->frame.window, mask, &attrib); self->label = createWindow(self->title, mask, &attrib); self->max = createWindow(self->title, mask, &attrib); @@ -282,6 +317,11 @@ Frame *frame_new() self->max_press = self->close_press = self->desk_press = self->iconify_press = FALSE; + dispatch_register(Event_X_ButtonPress, (EventHandler)frame_mouse_press, + self); + dispatch_register(Event_X_ButtonRelease, (EventHandler)frame_mouse_release, + self); + return (Frame*)self; } @@ -297,6 +337,9 @@ static void frame_free(ObFrame *self) XDestroyWindow(ob_display, self->frame.window); + dispatch_register(0, (EventHandler)frame_mouse_press, self); + dispatch_register(0, (EventHandler)frame_mouse_release, self); + g_free(self); } @@ -363,100 +406,118 @@ void frame_adjust_shape(ObFrame *self) #endif } -void frame_adjust_size(ObFrame *self) +void frame_adjust_area(ObFrame *self, gboolean moved, gboolean resized) { - if (self->frame.client->decorations & Decor_Border) { - self->bwidth = s_bwidth; - self->cbwidth = s_cbwidth; - } else { - self->bwidth = self->cbwidth = 0; - } - STRUT_SET(self->innersize, self->cbwidth, self->cbwidth, - self->cbwidth, self->cbwidth); - self->width = self->frame.client->area.width + self->cbwidth * 2; - g_assert(self->width > 0); - - /* set border widths */ - XSetWindowBorderWidth(ob_display, self->frame.plate, self->cbwidth); - XSetWindowBorderWidth(ob_display, self->frame.window, self->bwidth); - XSetWindowBorderWidth(ob_display, self->title, self->bwidth); - XSetWindowBorderWidth(ob_display, self->handle, self->bwidth); - XSetWindowBorderWidth(ob_display, self->lgrip, self->bwidth); - XSetWindowBorderWidth(ob_display, self->rgrip, self->bwidth); + if (resized) { + if (self->frame.client->decorations & Decor_Border) { + self->bwidth = s_bwidth; + self->cbwidth = s_cbwidth; + } else { + self->bwidth = self->cbwidth = 0; + } + STRUT_SET(self->innersize, self->cbwidth, self->cbwidth, + self->cbwidth, self->cbwidth); + self->width = self->frame.client->area.width + self->cbwidth * 2; + g_assert(self->width > 0); + + /* set border widths */ + XSetWindowBorderWidth(ob_display, self->frame.plate, self->cbwidth); + XSetWindowBorderWidth(ob_display, self->frame.window, self->bwidth); + XSetWindowBorderWidth(ob_display, self->title, self->bwidth); + XSetWindowBorderWidth(ob_display, self->handle, self->bwidth); + XSetWindowBorderWidth(ob_display, self->lgrip, self->bwidth); + XSetWindowBorderWidth(ob_display, self->rgrip, self->bwidth); - /* position/size and map/unmap all the windows */ + /* position/size and map/unmap all the windows */ + + /* they all default off, they're turned on in layout_title */ + self->icon_x = -1; + self->desk_x = -1; + self->icon_x = -1; + self->label_x = -1; + self->max_x = -1; + self->close_x = -1; + + if (self->frame.client->decorations & Decor_Titlebar) { + XMoveResizeWindow(ob_display, self->title, + -self->bwidth, -self->bwidth, + self->width, TITLE_HEIGHT); + self->innersize.top += TITLE_HEIGHT + self->bwidth; + XMapWindow(ob_display, self->title); + + /* layout the title bar elements */ + layout_title(self); + } else { + XUnmapWindow(ob_display, self->title); + /* make all the titlebar stuff not render */ + self->frame.client->decorations &= ~(Decor_Icon | Decor_Iconify | + Decor_Maximize | Decor_Close | + Decor_AllDesktops); + } + + if (self->frame.client->decorations & Decor_Handle) { + XMoveResizeWindow(ob_display, self->handle, + -self->bwidth, HANDLE_Y(self), + self->width, s_handle_height); + XMoveWindow(ob_display, self->lgrip, + -self->bwidth, -self->bwidth); + XMoveWindow(ob_display, self->rgrip, + -self->bwidth + self->width - + GRIP_WIDTH, -self->bwidth); + self->innersize.bottom += s_handle_height + + self->bwidth; + XMapWindow(ob_display, self->handle); + } else + XUnmapWindow(ob_display, self->handle); + } - if (self->frame.client->decorations & Decor_Titlebar) { - XMoveResizeWindow(ob_display, self->title, - -self->bwidth, -self->bwidth, - self->width, TITLE_HEIGHT); - self->innersize.top += TITLE_HEIGHT + self->bwidth; - XMapWindow(ob_display, self->title); - - /* layout the title bar elements */ - layout_title(self); - } else { - XUnmapWindow(ob_display, self->title); - /* make all the titlebar stuff not render */ - self->frame.client->decorations &= ~(Decor_Icon | Decor_Iconify | - Decor_Maximize | Decor_Close | - Decor_AllDesktops); + if (resized) { + /* move and resize the plate */ + XMoveResizeWindow(ob_display, self->frame.plate, + self->innersize.left - self->cbwidth, + self->innersize.top - self->cbwidth, + self->frame.client->area.width, + self->frame.client->area.height); + /* when the client has StaticGravity, it likes to move around. */ + XMoveWindow(ob_display, self->frame.client->window, 0, 0); } - if (self->frame.client->decorations & Decor_Handle) { - XMoveResizeWindow(ob_display, self->handle, - -self->bwidth, HANDLE_Y(self), - self->width, s_handle_height); - XMoveWindow(ob_display, self->lgrip, - -self->bwidth, -self->bwidth); - XMoveWindow(ob_display, self->rgrip, - -self->bwidth + self->width - - GRIP_WIDTH, -self->bwidth); - self->innersize.bottom += s_handle_height + - self->bwidth; - XMapWindow(ob_display, self->handle); - } else - XUnmapWindow(ob_display, self->handle); - - XResizeWindow(ob_display, self->frame.window, self->width, - (self->frame.client->shaded ? TITLE_HEIGHT : - self->innersize.top + self->innersize.bottom + - self->frame.client->area.height)); - - /* do this in two steps because clients whose gravity is set to - 'Static' don't end up getting moved at all with an XMoveResizeWindow */ - XMoveWindow(ob_display, self->frame.plate, - self->innersize.left - self->cbwidth, - self->innersize.top - self->cbwidth); - XResizeWindow(ob_display, self->frame.plate, - self->frame.client->area.width, - self->frame.client->area.height); - - STRUT_SET(self->frame.size, - self->innersize.left + self->bwidth, - self->innersize.top + self->bwidth, - self->innersize.right + self->bwidth, - self->innersize.bottom + self->bwidth); + if (resized) { + STRUT_SET(self->frame.size, + self->innersize.left + self->bwidth, + self->innersize.top + self->bwidth, + self->innersize.right + self->bwidth, + self->innersize.bottom + self->bwidth); + } + /* shading can change without being moved or resized */ RECT_SET_SIZE(self->frame.area, self->frame.client->area.width + self->frame.size.left + self->frame.size.right, - self->frame.client->area.height + - self->frame.size.top + self->frame.size.bottom); + (self->frame.client->shaded ? TITLE_HEIGHT + self->bwidth*2: + self->frame.client->area.height + + self->frame.size.top + self->frame.size.bottom)); + + if (moved) { + /* find the new coordinates, done after setting the frame.size, for + frame_client_gravity. */ + self->frame.area.x = self->frame.client->area.x; + self->frame.area.y = self->frame.client->area.y; + frame_client_gravity((Frame*)self, + &self->frame.area.x, &self->frame.area.y); + } - render(self); - - frame_adjust_shape(self); -} + /* move and resize the top level frame. + shading can change without being moved or resized */ + XMoveResizeWindow(ob_display, self->frame.window, + self->frame.area.x, self->frame.area.y, + self->width, self->frame.area.height - self->bwidth * 2); -void frame_adjust_position(ObFrame *self) -{ - self->frame.area.x = self->frame.client->area.x; - self->frame.area.y = self->frame.client->area.y; - frame_client_gravity((Frame*)self, - &self->frame.area.x, &self->frame.area.y); - XMoveWindow(ob_display, self->frame.window, - self->frame.area.x, self->frame.area.y); + if (resized) { + render(self); + + frame_adjust_shape(self); + } } void frame_adjust_state(ObFrame *self) @@ -504,22 +565,21 @@ void frame_grab_client(ObFrame *self, Client *client) /* map the client so it maps when the frame does */ XMapWindow(ob_display, client->window); - frame_adjust_size(self); - frame_adjust_position(self); + frame_adjust_area(self, TRUE, TRUE); /* set all the windows for the frame in the client_map */ - g_hash_table_insert(client_map, (gpointer)self->frame.window, client); - g_hash_table_insert(client_map, (gpointer)self->frame.plate, client); - g_hash_table_insert(client_map, (gpointer)self->title, client); - g_hash_table_insert(client_map, (gpointer)self->label, client); - g_hash_table_insert(client_map, (gpointer)self->max, client); - g_hash_table_insert(client_map, (gpointer)self->close, client); - g_hash_table_insert(client_map, (gpointer)self->desk, client); - g_hash_table_insert(client_map, (gpointer)self->icon, client); - g_hash_table_insert(client_map, (gpointer)self->iconify, client); - g_hash_table_insert(client_map, (gpointer)self->handle, client); - g_hash_table_insert(client_map, (gpointer)self->lgrip, client); - g_hash_table_insert(client_map, (gpointer)self->rgrip, client); + g_hash_table_insert(client_map, &self->frame.window, client); + g_hash_table_insert(client_map, &self->frame.plate, client); + g_hash_table_insert(client_map, &self->title, client); + g_hash_table_insert(client_map, &self->label, client); + g_hash_table_insert(client_map, &self->max, client); + g_hash_table_insert(client_map, &self->close, client); + g_hash_table_insert(client_map, &self->desk, client); + g_hash_table_insert(client_map, &self->icon, client); + g_hash_table_insert(client_map, &self->iconify, client); + g_hash_table_insert(client_map, &self->handle, client); + g_hash_table_insert(client_map, &self->lgrip, client); + g_hash_table_insert(client_map, &self->rgrip, client); } void frame_release_client(ObFrame *self, Client *client) @@ -543,18 +603,18 @@ void frame_release_client(ObFrame *self, Client *client) } /* remove all the windows for the frame from the client_map */ - g_hash_table_remove(client_map, (gpointer)self->frame.window); - g_hash_table_remove(client_map, (gpointer)self->frame.plate); - g_hash_table_remove(client_map, (gpointer)self->title); - g_hash_table_remove(client_map, (gpointer)self->label); - g_hash_table_remove(client_map, (gpointer)self->max); - g_hash_table_remove(client_map, (gpointer)self->close); - g_hash_table_remove(client_map, (gpointer)self->desk); - g_hash_table_remove(client_map, (gpointer)self->icon); - g_hash_table_remove(client_map, (gpointer)self->iconify); - g_hash_table_remove(client_map, (gpointer)self->handle); - g_hash_table_remove(client_map, (gpointer)self->lgrip); - g_hash_table_remove(client_map, (gpointer)self->rgrip); + g_hash_table_remove(client_map, &self->frame.window); + g_hash_table_remove(client_map, &self->frame.plate); + g_hash_table_remove(client_map, &self->title); + g_hash_table_remove(client_map, &self->label); + g_hash_table_remove(client_map, &self->max); + g_hash_table_remove(client_map, &self->close); + g_hash_table_remove(client_map, &self->desk); + g_hash_table_remove(client_map, &self->icon); + g_hash_table_remove(client_map, &self->iconify); + g_hash_table_remove(client_map, &self->handle); + g_hash_table_remove(client_map, &self->lgrip); + g_hash_table_remove(client_map, &self->rgrip); frame_free(self); } @@ -564,26 +624,33 @@ static void layout_title(ObFrame *self) const char *lc; int x; gboolean n, d, i, l, m ,c; + ConfigValue layout; + n = d = i = l = m = c = FALSE; + if (!config_get("titlebar.layout", Config_String, &layout)) { + layout.string = "NDLIMC"; + config_set("titlebar.layout", Config_String, layout); + } + /* figure out whats being shown, and the width of the label */ - self->label_width = self->width - s_bevel * 2; - for (lc = themerc_titlebar_layout; *lc != '\0'; ++lc) { + self->label_width = self->width - (s_bevel + 1) * 2; + for (lc = layout.string; *lc != '\0'; ++lc) { switch (*lc) { case 'N': if (!(self->frame.client->decorations & Decor_Icon)) break; n = TRUE; - self->label_width -= BUTTON_SIZE + s_bevel; + self->label_width -= BUTTON_SIZE + s_bevel + 1; break; case 'D': if (!(self->frame.client->decorations & Decor_AllDesktops)) break; d = TRUE; - self->label_width -= BUTTON_SIZE + s_bevel; + self->label_width -= BUTTON_SIZE + s_bevel + 1; break; case 'I': if (!(self->frame.client->decorations & Decor_Iconify)) break; i = TRUE; - self->label_width -= BUTTON_SIZE + s_bevel; + self->label_width -= BUTTON_SIZE + s_bevel + 1; break; case 'L': l = TRUE; @@ -591,93 +658,71 @@ static void layout_title(ObFrame *self) case 'M': if (!(self->frame.client->decorations & Decor_Maximize)) break; m = TRUE; - self->label_width -= BUTTON_SIZE + s_bevel; + self->label_width -= BUTTON_SIZE + s_bevel + 1; break; case 'C': if (!(self->frame.client->decorations & Decor_Close)) break; c = TRUE; - self->label_width -= BUTTON_SIZE + s_bevel; + self->label_width -= BUTTON_SIZE + s_bevel + 1; break; } } if (self->label_width < 1) self->label_width = 1; - XResizeWindow(ob_display, self->label, self->label_width, s_font_height); + XResizeWindow(ob_display, self->label, self->label_width, + LABEL_HEIGHT); - if (!n) { - self->frame.client->decorations &= ~Decor_Icon; - XUnmapWindow(ob_display, self->icon); - self->icon_x = -1; - } - if (!d) { - self->frame.client->decorations &= ~Decor_AllDesktops; - XUnmapWindow(ob_display, self->desk); - self->desk_x = -1; - } - if (!i) { - self->frame.client->decorations &= ~Decor_Iconify; - XUnmapWindow(ob_display, self->iconify); - self->icon_x = -1; - } - if (!l) { - XUnmapWindow(ob_display, self->label); - self->label_x = -1; - } - if (!m) { - self->frame.client->decorations &= ~Decor_Maximize; - XUnmapWindow(ob_display, self->max); - self->max_x = -1; - } - if (!c) { - self->frame.client->decorations &= ~Decor_Close; - XUnmapWindow(ob_display, self->close); - self->close_x = -1; - } - - x = s_bevel; - for (lc = themerc_titlebar_layout; *lc != '\0'; ++lc) { + if (!n) XUnmapWindow(ob_display, self->icon); + if (!d) XUnmapWindow(ob_display, self->desk); + 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 = s_bevel + 1; + for (lc = layout.string; *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, s_bevel + 1); - x += BUTTON_SIZE + s_bevel; + x += BUTTON_SIZE + s_bevel + 1; break; case 'D': if (!d) break; self->desk_x = x; XMapWindow(ob_display, self->desk); XMoveWindow(ob_display, self->desk, x, s_bevel + 1); - x += BUTTON_SIZE + s_bevel; + x += BUTTON_SIZE + s_bevel + 1; break; case 'I': if (!i) break; self->iconify_x = x; XMapWindow(ob_display, self->iconify); XMoveWindow(ob_display, self->iconify, x, s_bevel + 1); - x += BUTTON_SIZE + s_bevel; + x += BUTTON_SIZE + s_bevel + 1; break; case 'L': if (!l) break; self->label_x = x; XMapWindow(ob_display, self->label); XMoveWindow(ob_display, self->label, x, s_bevel); - x += self->label_width + s_bevel; + x += self->label_width + s_bevel + 1; break; case 'M': if (!m) break; self->max_x = x; XMapWindow(ob_display, self->max); XMoveWindow(ob_display, self->max, x, s_bevel + 1); - x += BUTTON_SIZE + s_bevel; + x += BUTTON_SIZE + s_bevel + 1; break; case 'C': if (!c) break; self->close_x = x; XMapWindow(ob_display, self->close); XMoveWindow(ob_display, self->close, x, s_bevel + 1); - x += BUTTON_SIZE + s_bevel; + x += BUTTON_SIZE + s_bevel + 1; break; } } @@ -685,122 +730,138 @@ static void layout_title(ObFrame *self) static void render(ObFrame *self) { - if (self->frame.client->focused) { - XSetWindowBorder(ob_display, self->frame.plate, - s_cb_focused_color->pixel); + if (client_focused(self->frame.client)) { + XSetWindowBorder(ob_display, self->frame.plate, + s_cb_focused_color->pixel); } else { - XSetWindowBorder(ob_display, self->frame.plate, - s_cb_unfocused_color->pixel); + XSetWindowBorder(ob_display, self->frame.plate, + s_cb_unfocused_color->pixel); } if (self->frame.client->decorations & Decor_Titlebar) { - paint(self->title, (self->frame.client->focused ? - self->a_focused_title : - self->a_unfocused_title), - self->width, TITLE_HEIGHT); - render_label(self); - render_max(self); - render_icon(self); - render_iconify(self); - render_desk(self); - render_close(self); + paint(self->title, (client_focused(self->frame.client) ? + self->a_focused_title : + self->a_unfocused_title), + 0, 0, self->width, TITLE_HEIGHT); + render_label(self); + render_max(self); + render_icon(self); + render_iconify(self); + render_desk(self); + render_close(self); } if (self->frame.client->decorations & Decor_Handle) { - paint(self->handle, (self->frame.client->focused ? - self->a_focused_handle : - self->a_unfocused_handle), - HANDLE_WIDTH(self), s_handle_height); - paint(self->lgrip, (self->frame.client->focused ? - a_focused_grip : - a_unfocused_grip), - GRIP_WIDTH, s_handle_height); - paint(self->rgrip, (self->frame.client->focused ? - a_focused_grip : - a_unfocused_grip), - GRIP_WIDTH, s_handle_height); + paint(self->handle, (client_focused(self->frame.client) ? + self->a_focused_handle : + self->a_unfocused_handle), + GRIP_WIDTH + self->bwidth, 0, + HANDLE_WIDTH(self), s_handle_height); + paint(self->lgrip, (client_focused(self->frame.client) ? + a_focused_grip : + a_unfocused_grip), + 0, 0, GRIP_WIDTH, s_handle_height); + paint(self->rgrip, (client_focused(self->frame.client) ? + a_focused_grip : + a_unfocused_grip), + 0, 0, GRIP_WIDTH, s_handle_height); } } static void render_label(ObFrame *self) { + Appearance *a; + if (self->label_x < 0) return; - /* XXX set the texture's text! */ - paint(self->label, (self->frame.client->focused ? - self->a_focused_label : - self->a_unfocused_label), - self->label_width, LABEL_HEIGHT); + a = (client_focused(self->frame.client) ? + self->a_focused_label : self->a_unfocused_label); + + /* set the texture's text! */ + a->texture[0].data.text.string = self->frame.client->title; + RECT_SET(a->texture[0].position, 0, 0, self->label_width, LABEL_HEIGHT); + + paint(self->label, a, 0, 0, self->label_width, LABEL_HEIGHT); } static void render_icon(ObFrame *self) { if (self->icon_x < 0) return; - /* XXX set the texture's icon picture! */ - paint(self->icon, self->a_icon, BUTTON_SIZE, BUTTON_SIZE); + if (self->frame.client->nicons) { + Icon *icon = client_icon(self->frame.client, BUTTON_SIZE, BUTTON_SIZE); + self->a_icon->texture[0].type = RGBA; + self->a_icon->texture[0].data.rgba.width = icon->width; + self->a_icon->texture[0].data.rgba.height = icon->height; + self->a_icon->texture[0].data.rgba.data = icon->data; + RECT_SET(self->a_icon->texture[0].position, 0, 0, + BUTTON_SIZE,BUTTON_SIZE); + } else + self->a_icon->texture[0].type = NoTexture; + + paint(self->icon, self->a_icon, 0, 0, BUTTON_SIZE, BUTTON_SIZE); } static void render_max(ObFrame *self) { + Appearance *a; + gboolean press = self->max_press || self->frame.client->max_vert || self->frame.client->max_horz; if (self->max_x < 0) return; - paint(self->max, (self->frame.client->focused ? - (press ? - a_focused_pressed_max : - a_focused_unpressed_max) : - (press ? - a_unfocused_pressed_max : - a_unfocused_unpressed_max)), - BUTTON_SIZE, BUTTON_SIZE); + a = (client_focused(self->frame.client) ? + (press ? a_focused_pressed_max : a_focused_unpressed_max) : + (press ? a_unfocused_pressed_max : a_unfocused_unpressed_max)); + RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE); + paint(self->max, a, 0, 0, BUTTON_SIZE, BUTTON_SIZE); } static void render_iconify(ObFrame *self) { + Appearance *a; + if (self->iconify_x < 0) return; - paint(self->iconify, (self->frame.client->focused ? - (self->iconify_press ? - a_focused_pressed_iconify : - a_focused_unpressed_iconify) : - (self->iconify_press ? - a_unfocused_pressed_iconify : - a_unfocused_unpressed_iconify)), - BUTTON_SIZE, BUTTON_SIZE); + a = (client_focused(self->frame.client) ? + (self->iconify_press ? + a_focused_pressed_iconify : a_focused_unpressed_iconify) : + (self->iconify_press ? + a_unfocused_pressed_iconify : a_unfocused_unpressed_iconify)); + RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE); + paint(self->iconify, a, 0, 0, BUTTON_SIZE, BUTTON_SIZE); } static void render_desk(ObFrame *self) { + Appearance *a; + gboolean press = self->desk_press || self->frame.client->desktop == DESKTOP_ALL; if (self->desk_x < 0) return; - paint(self->desk, (self->frame.client->focused ? - (press ? - a_focused_pressed_desk : - a_focused_unpressed_desk) : - (press ? - a_unfocused_pressed_desk : - a_unfocused_unpressed_desk)), - BUTTON_SIZE, BUTTON_SIZE); + a = (client_focused(self->frame.client) ? + (press ? a_focused_pressed_desk : a_focused_unpressed_desk) : + (press ? a_unfocused_pressed_desk : a_unfocused_unpressed_desk)); + RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE); + paint(self->desk, a, 0, 0, BUTTON_SIZE, BUTTON_SIZE); } static void render_close(ObFrame *self) { + Appearance *a; + if (self->close_x < 0) return; - paint(self->close, (self->frame.client->focused ? - (self->close_press ? - a_focused_pressed_close : - a_focused_unpressed_close) : - (self->close_press ? - a_unfocused_pressed_close : - a_unfocused_unpressed_close)), - BUTTON_SIZE, BUTTON_SIZE); + a = (client_focused(self->frame.client) ? + (self->close_press ? + a_focused_pressed_close : a_focused_unpressed_close) : + (self->close_press ? + a_unfocused_pressed_close : a_unfocused_unpressed_close)); + RECT_SET(a->texture[0].position, 0, 0, BUTTON_SIZE,BUTTON_SIZE); + paint(self->close, a, 0, 0, BUTTON_SIZE, BUTTON_SIZE); } GQuark get_context(Client *client, Window win) @@ -827,3 +888,39 @@ GQuark get_context(Client *client, Window win) return g_quark_try_string("none"); } + +static void frame_mouse_press(const ObEvent *e, ObFrame *self) +{ + Window win = e->data.x.e->xbutton.window; + if (win == self->max) { + self->max_press = TRUE; + render_max(self); + } else if (win == self->close) { + self->close_press = TRUE; + render_close(self); + } else if (win == self->iconify) { + self->iconify_press = TRUE; + render_iconify(self); + } else if (win == self->desk) { + self->desk_press = TRUE; + render_desk(self); + } +} + +static void frame_mouse_release(const ObEvent *e, ObFrame *self) +{ + Window win = e->data.x.e->xbutton.window; + if (win == self->max) { + self->max_press = FALSE; + render_max(self); + } else if (win == self->close) { + self->close_press = FALSE; + render_close(self); + } else if (win == self->iconify) { + self->iconify_press = FALSE; + render_iconify(self); + } else if (win == self->desk) { + self->desk_press = FALSE; + render_desk(self); + } +}