Separate theme options for osd prompt buttons.

I managed to keep backwards compatibility without really cluttering
the code so here is the patch
http://bugzilla.icculus.org/show_bug.cgi?id=4874 too.

Please keep in mind that this is my first piece of code for openbox
and that I'm not a die hard openbox user (yet), not to tell the patch
was not exhaustively tested. Anyway I think it's pretty much in a good
shape but any criticism will be welcome.

Basically the patch add the following theme options for controlling
buttons in osd prompts:

%%%% colors
%
% for the text inside the button
osd.button.unpressed.text.color
osd.button.pressed.text.color
osd.button.focused.text.color
%
% for the line art around the button
%  (if you don't wan't the box just make box.color = bg.color)
osd.button.pressed.box.color
osd.button.focused.box.color

%%%% textures
%
osd.button.unpressed.bg
osd.button.pressed.bg
osd.button.focused.bg

The buttons can be in three states:

 unpressed: neither clicked nor selected
 focused: selected but not clicked
 pressed: clicked (and of course selected)

I discarded the previous distinction between press and pfocus as in
fact it was only a formal distinction, in that both appearances
mimicked each other in every sense. It think that it was just
inherited from the way titlebar buttons are managed so I decided to
simplify it a bit.

All the options default in a way that preserves backwards compatibility:

osd.button.unpressed.text.color  -> osd.active.label.text.color
osd.button.pressed.text.color -> osd.active.label.text.color
osd.button.focused.text.color -> osd.active.label.text.color

osd.button.pressed.box.color ->  window.active.button.pressed.image.color
osd.button.focused.box.color -> window.active.button.hover.image.color

osd.button.unpressed.bg -> window.active.button.unpressed.bg
osd.button.pressed.bg -> window.active.button.pressed.bg
osd.button.focused.bg -> window.active.button.hover.bg

Notice that a good deal of locs where added to theme.c but in
compensation prompt.c is pretty much simpler now because the
appearances and textures are created while loading the theme.
This commit is contained in:
Carlos Pita 2011-01-12 20:49:45 -03:00 committed by Mikael Magnusson
parent d09fd3183e
commit 177a0340a7
3 changed files with 77 additions and 59 deletions

View file

@ -93,6 +93,13 @@ static RrFont *get_font(RrFont *target, RrFont **default_font,
RrAppearanceFree(x_var); \
x_var = RrAppearanceCopy(x_defval); }
#define READ_APPEARANCE_COPY_TEXTURES(x_resstr, x_var, x_parrel, x_defval, n_tex) \
if (!read_appearance(db, inst, x_resstr, x_var, x_parrel)) {\
RrAppearanceFree(x_var); \
x_var = RrAppearanceCopy(x_defval); \
RrAppearanceRemoveTextures(x_var); \
RrAppearanceAddTextures(x_var, 5); }
#define READ_APPEARANCE_(x_res1, x_res2, x_var, x_parrel, x_defval) \
if (!read_appearance(db, inst, x_res1, x_var, x_parrel) && \
!read_appearance(db, inst, x_res2, x_var, x_parrel)) {\
@ -209,6 +216,9 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->osd_hilite_bg = RrAppearanceNew(inst, 0);
theme->osd_unhilite_label = RrAppearanceNew(inst, 1);
theme->osd_unhilite_bg = RrAppearanceNew(inst, 0);
theme->osd_unpressed_button = RrAppearanceNew(inst, 1);
theme->osd_pressed_button = RrAppearanceNew(inst, 5);
theme->osd_focused_button = RrAppearanceNew(inst, 5);
/* load the font stuff */
theme->win_font_focused = get_font(active_window_font,
@ -390,6 +400,17 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
READ_COLOR("menu.bullet.selected.image.color",
theme->menu_bullet_selected_color,
RrColorCopy(theme->menu_selected_color));
READ_COLOR("osd.button.unpressed.text.color", theme->osd_unpressed_color,
RrColorCopy(theme->osd_text_active_color));
READ_COLOR("osd.button.pressed.text.color", theme->osd_pressed_color,
RrColorCopy(theme->osd_text_active_color));
READ_COLOR("osd.button.focused.text.color", theme->osd_focused_color,
RrColorCopy(theme->osd_text_active_color));
READ_COLOR("osd.button.pressed.box.color", theme->osd_pressed_lineart,
RrColorCopy(theme->titlebut_focused_pressed_color));
READ_COLOR("osd.button.focused.box.color", theme->osd_focused_lineart,
RrColorCopy(theme->titlebut_hover_focused_color));
/* load the image masks */
@ -868,6 +889,11 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->btn_iconify->a_hover_unfocused, TRUE,
theme->btn_iconify->a_unfocused_unpressed);
/* osd buttons */
READ_APPEARANCE_COPY("osd.button.unpressed.bg", theme->osd_unpressed_button, TRUE, a_focused_unpressed_tmp);
READ_APPEARANCE_COPY_TEXTURES("osd.button.pressed.bg", theme->osd_pressed_button, TRUE, a_focused_pressed_tmp, 5);
READ_APPEARANCE_COPY_TEXTURES("osd.button.focused.bg", theme->osd_focused_button, TRUE, a_focused_unpressed_tmp, 5);
theme->a_icon->surface.grad =
theme->a_clear->surface.grad =
theme->a_clear_tex->surface.grad =
@ -975,6 +1001,35 @@ RrTheme* RrThemeNew(const RrInstance *inst, const gchar *name,
theme->osd_hilite_label->texture[0].data.text.shadow_alpha =
theme->osd_text_active_shadow_alpha;
theme->osd_unpressed_button->texture[0] =
theme->osd_pressed_button->texture[0] =
theme->osd_focused_button->texture[0] =
theme->osd_hilite_label->texture[0];
theme->osd_unpressed_button->texture[0].data.text.justify =
theme->osd_pressed_button->texture[0].data.text.justify =
theme->osd_focused_button->texture[0].data.text.justify =
RR_JUSTIFY_CENTER;
theme->osd_unpressed_button->texture[0].data.text.color =
theme->osd_unpressed_color;
theme->osd_pressed_button->texture[0].data.text.color =
theme->osd_pressed_color;
theme->osd_focused_button->texture[0].data.text.color =
theme->osd_focused_color;
theme->osd_pressed_button->texture[1].data.lineart.color =
theme->osd_pressed_button->texture[2].data.lineart.color =
theme->osd_pressed_button->texture[3].data.lineart.color =
theme->osd_pressed_button->texture[4].data.lineart.color =
theme->osd_pressed_lineart;
theme->osd_focused_button->texture[1].data.lineart.color =
theme->osd_focused_button->texture[2].data.lineart.color =
theme->osd_focused_button->texture[3].data.lineart.color =
theme->osd_focused_button->texture[4].data.lineart.color =
theme->osd_focused_lineart;
theme->a_unfocused_label->texture[0].type = RR_TEXTURE_TEXT;
theme->a_unfocused_label->texture[0].data.text.justify = winjust;
theme->a_unfocused_label->texture[0].data.text.font =
@ -1583,6 +1638,11 @@ void RrThemeFree(RrTheme *theme)
RrColorFree(theme->osd_text_inactive_color);
RrColorFree(theme->osd_text_active_shadow_color);
RrColorFree(theme->osd_text_inactive_shadow_color);
RrColorFree(theme->osd_pressed_color);
RrColorFree(theme->osd_unpressed_color);
RrColorFree(theme->osd_focused_color);
RrColorFree(theme->osd_pressed_lineart);
RrColorFree(theme->osd_focused_lineart);
RrColorFree(theme->menu_title_shadow_color);
RrColorFree(theme->menu_text_normal_shadow_color);
RrColorFree(theme->menu_text_selected_shadow_color);
@ -1631,6 +1691,9 @@ void RrThemeFree(RrTheme *theme)
RrAppearanceFree(theme->osd_hilite_label);
RrAppearanceFree(theme->osd_unhilite_bg);
RrAppearanceFree(theme->osd_unhilite_label);
RrAppearanceFree(theme->osd_pressed_button);
RrAppearanceFree(theme->osd_unpressed_button);
RrAppearanceFree(theme->osd_focused_button);
g_slice_free(RrTheme, theme);
}

View file

@ -105,6 +105,11 @@ struct _RrTheme {
RrColor *osd_text_inactive_shadow_color;
gchar osd_text_active_shadow_alpha;
gchar osd_text_inactive_shadow_alpha;
RrColor *osd_pressed_color;
RrColor *osd_unpressed_color;
RrColor *osd_focused_color;
RrColor *osd_pressed_lineart;
RrColor *osd_focused_lineart;
RrColor *menu_title_shadow_color;
gchar menu_title_shadow_alpha;
RrColor *menu_text_normal_shadow_color;
@ -169,6 +174,9 @@ struct _RrTheme {
RrAppearance *osd_hilite_label; /* can be parent relative */
RrAppearance *osd_unhilite_bg; /* can never be parent relative */
RrAppearance *osd_unhilite_label; /* can be parent relative */
RrAppearance *osd_pressed_button;
RrAppearance *osd_unpressed_button;
RrAppearance *osd_focused_button;
gchar *name;
};

View file

@ -34,7 +34,6 @@ static RrAppearance *prompt_a_bg;
static RrAppearance *prompt_a_button;
static RrAppearance *prompt_a_focus;
static RrAppearance *prompt_a_press;
static RrAppearance *prompt_a_pfocus;
/* we change the max width which would screw with others */
static RrAppearance *prompt_a_msg;
@ -54,58 +53,12 @@ static void prompt_run_callback(ObPrompt *self, gint result);
void prompt_startup(gboolean reconfig)
{
RrColor *c_button, *c_focus, *c_press, *c_pfocus;
/* note: this is not a copy, don't free it */
prompt_a_bg = ob_rr_theme->osd_bg;
prompt_a_button = RrAppearanceCopy(ob_rr_theme->btn_close->a_focused_unpressed);
prompt_a_focus = RrAppearanceCopy(ob_rr_theme->btn_close->a_hover_focused);
prompt_a_press = RrAppearanceCopy(ob_rr_theme->btn_close->a_focused_pressed);
prompt_a_pfocus = RrAppearanceCopy(ob_rr_theme->btn_close->a_focused_pressed);
c_button = prompt_a_button->texture[0].data.mask.color;
c_focus = prompt_a_focus->texture[0].data.mask.color;
c_press = prompt_a_press->texture[0].data.mask.color;
c_pfocus = prompt_a_press->texture[0].data.mask.color;
RrAppearanceRemoveTextures(prompt_a_button);
RrAppearanceRemoveTextures(prompt_a_focus);
RrAppearanceRemoveTextures(prompt_a_press);
RrAppearanceRemoveTextures(prompt_a_pfocus);
/* texture[0] is the text and texture[1-4] (for prompt_a_focus and
prompt_a_pfocus) is lineart to show where keyboard focus is */
RrAppearanceAddTextures(prompt_a_button, 1);
RrAppearanceAddTextures(prompt_a_focus, 5);
RrAppearanceAddTextures(prompt_a_press, 1);
RrAppearanceAddTextures(prompt_a_pfocus, 5);
/* totally cheating here.. */
prompt_a_button->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
prompt_a_focus->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
prompt_a_press->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
prompt_a_pfocus->texture[0] = ob_rr_theme->osd_hilite_label->texture[0];
prompt_a_button->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
prompt_a_focus->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
prompt_a_press->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
prompt_a_pfocus->texture[0].data.text.justify = RR_JUSTIFY_CENTER;
prompt_a_button->texture[0].data.text.color = c_button;
prompt_a_focus->texture[0].data.text.color = c_focus;
prompt_a_press->texture[0].data.text.color = c_press;
prompt_a_pfocus->texture[0].data.text.color = c_pfocus;
prompt_a_focus->texture[1].data.lineart.color = c_focus;
prompt_a_focus->texture[2].data.lineart.color = c_focus;
prompt_a_focus->texture[3].data.lineart.color = c_focus;
prompt_a_focus->texture[4].data.lineart.color = c_focus;
prompt_a_pfocus->texture[1].data.lineart.color = c_press;
prompt_a_pfocus->texture[2].data.lineart.color = c_press;
prompt_a_pfocus->texture[3].data.lineart.color = c_press;
prompt_a_pfocus->texture[4].data.lineart.color = c_press;
prompt_a_button = RrAppearanceCopy(ob_rr_theme->osd_unpressed_button);
prompt_a_focus = RrAppearanceCopy(ob_rr_theme->osd_focused_button);
prompt_a_press = RrAppearanceCopy(ob_rr_theme->osd_pressed_button);
prompt_a_msg = RrAppearanceCopy(ob_rr_theme->osd_hilite_label);
prompt_a_msg->texture[0].data.text.flow = TRUE;
@ -136,7 +89,6 @@ void prompt_shutdown(gboolean reconfig)
RrAppearanceFree(prompt_a_button);
RrAppearanceFree(prompt_a_focus);
RrAppearanceFree(prompt_a_press);
RrAppearanceFree(prompt_a_pfocus);
RrAppearanceFree(prompt_a_msg);
}
@ -281,7 +233,6 @@ static void prompt_layout(ObPrompt *self)
prompt_a_button->texture[0].data.text.string = self->button[i].text;
prompt_a_focus->texture[0].data.text.string = self->button[i].text;
prompt_a_press->texture[0].data.text.string = self->button[i].text;
prompt_a_pfocus->texture[0].data.text.string = self->button[i].text;
RrMinSize(prompt_a_button, &bw, &bh);
self->button[i].width = bw;
self->button[i].height = bh;
@ -291,9 +242,6 @@ static void prompt_layout(ObPrompt *self)
RrMinSize(prompt_a_press, &bw, &bh);
self->button[i].width = MAX(self->button[i].width, bw);
self->button[i].height = MAX(self->button[i].height, bh);
RrMinSize(prompt_a_pfocus, &bw, &bh);
self->button[i].width = MAX(self->button[i].width, bw);
self->button[i].height = MAX(self->button[i].height, bh);
self->button[i].width += BUTTON_HMARGIN * 2;
self->button[i].height += BUTTON_VMARGIN * 2;
@ -414,9 +362,8 @@ static void render_button(ObPrompt *self, ObPromptElement *e)
{
RrAppearance *a;
if (e->hover && self->focus == e) a = prompt_a_pfocus;
if (e->hover && e->pressed) a = prompt_a_press;
else if (self->focus == e) a = prompt_a_focus;
else if (e->pressed) a = prompt_a_press;
else a = prompt_a_button;
a->surface.parent = prompt_a_bg;
@ -424,7 +371,7 @@ static void render_button(ObPrompt *self, ObPromptElement *e)
a->surface.parenty = e->y;
/* draw the keyfocus line */
if (a == prompt_a_pfocus || a == prompt_a_focus)
if (self->focus == e)
setup_button_focus_tex(e, a, TRUE);
a->texture[0].data.text.string = e->text;
@ -432,7 +379,7 @@ static void render_button(ObPrompt *self, ObPromptElement *e)
/* turn off the keyfocus line so that it doesn't affect size calculations
*/
if (a == prompt_a_pfocus || a == prompt_a_focus)
if (self->focus == e)
setup_button_focus_tex(e, a, FALSE);
}