theme: Add background functions for single buttons

With the existing background functions, single buttons can not be
styled separately - on the left side, the style of the left button
is picked, and the right button's style on the right side.

As theme authors may want to add rounded corners to button groups
as a whole, it makes sense to treat the case of a single button in
a group differently.

https://bugzilla.gnome.org/show_bug.cgi?id=635683
This commit is contained in:
Florian Müllner 2010-12-03 01:14:13 +01:00
parent 4bc8c70c75
commit 0a2bb1b71c
4 changed files with 51 additions and 7 deletions

View File

@ -22,6 +22,12 @@ This document has separate sections for each format version. You may
want to read the document in reverse order, since the base features want to read the document in reverse order, since the base features
are discussed under version 1. are discussed under version 1.
New Features in Theme Format Version 3.3
========================================
Add two additional button background functions - left_single_background and
right_single_background - for button groups with just a single button.
New Features in Theme Format Version 3.2 New Features in Theme Format Version 3.2
======================================== ========================================

View File

@ -38,7 +38,7 @@
* look out for. * look out for.
*/ */
#define THEME_MAJOR_VERSION 3 #define THEME_MAJOR_VERSION 3
#define THEME_MINOR_VERSION 2 #define THEME_MINOR_VERSION 3
#define THEME_VERSION (1000 * THEME_MAJOR_VERSION + THEME_MINOR_VERSION) #define THEME_VERSION (1000 * THEME_MAJOR_VERSION + THEME_MINOR_VERSION)
#define METACITY_THEME_FILENAME_FORMAT "metacity-theme-%d.xml" #define METACITY_THEME_FILENAME_FORMAT "metacity-theme-%d.xml"

View File

@ -234,7 +234,7 @@ struct _MetaFrameGeometry
/* used for a memset hack */ /* used for a memset hack */
#define ADDRESS_OF_BUTTON_RECTS(fgeom) (((char*)(fgeom)) + G_STRUCT_OFFSET (MetaFrameGeometry, close_rect)) #define ADDRESS_OF_BUTTON_RECTS(fgeom) (((char*)(fgeom)) + G_STRUCT_OFFSET (MetaFrameGeometry, close_rect))
#define LENGTH_OF_BUTTON_RECTS (G_STRUCT_OFFSET (MetaFrameGeometry, right_right_background) + sizeof (GdkRectangle) - G_STRUCT_OFFSET (MetaFrameGeometry, close_rect)) #define LENGTH_OF_BUTTON_RECTS (G_STRUCT_OFFSET (MetaFrameGeometry, right_single_background) + sizeof (GdkRectangle) - G_STRUCT_OFFSET (MetaFrameGeometry, close_rect))
/* The button rects (if changed adjust memset hack) */ /* The button rects (if changed adjust memset hack) */
MetaButtonSpace close_rect; MetaButtonSpace close_rect;
@ -252,9 +252,11 @@ struct _MetaFrameGeometry
GdkRectangle left_left_background; GdkRectangle left_left_background;
GdkRectangle left_middle_backgrounds[MAX_MIDDLE_BACKGROUNDS]; GdkRectangle left_middle_backgrounds[MAX_MIDDLE_BACKGROUNDS];
GdkRectangle left_right_background; GdkRectangle left_right_background;
GdkRectangle left_single_background;
GdkRectangle right_left_background; GdkRectangle right_left_background;
GdkRectangle right_middle_backgrounds[MAX_MIDDLE_BACKGROUNDS]; GdkRectangle right_middle_backgrounds[MAX_MIDDLE_BACKGROUNDS];
GdkRectangle right_right_background; GdkRectangle right_right_background;
GdkRectangle right_single_background;
/* End of button rects (if changed adjust memset hack) */ /* End of button rects (if changed adjust memset hack) */
/* Saved button layout */ /* Saved button layout */
@ -647,9 +649,11 @@ typedef enum
META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND, META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND,
META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND, META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND,
META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND, META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND,
META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND,
META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND, META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND,
META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND, META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND,
META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND, META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND,
META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND,
META_BUTTON_TYPE_CLOSE, META_BUTTON_TYPE_CLOSE,
META_BUTTON_TYPE_MAXIMIZE, META_BUTTON_TYPE_MAXIMIZE,
META_BUTTON_TYPE_MINIMIZE, META_BUTTON_TYPE_MINIMIZE,

View File

@ -734,7 +734,9 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
for (i = 0; i < n_left; i++) for (i = 0; i < n_left; i++)
{ {
if (i == 0) /* prefer left background if only one button */ if (n_left == 1)
left_bg_rects[i] = &fgeom->left_single_background;
else if (i == 0)
left_bg_rects[i] = &fgeom->left_left_background; left_bg_rects[i] = &fgeom->left_left_background;
else if (i == (n_left - 1)) else if (i == (n_left - 1))
left_bg_rects[i] = &fgeom->left_right_background; left_bg_rects[i] = &fgeom->left_right_background;
@ -744,8 +746,9 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
for (i = 0; i < n_right; i++) for (i = 0; i < n_right; i++)
{ {
/* prefer right background if only one button */ if (n_right == 1)
if (i == (n_right - 1)) right_bg_rects[i] = &fgeom->right_single_background;
else if (i == (n_right - 1))
right_bg_rects[i] = &fgeom->right_right_background; right_bg_rects[i] = &fgeom->right_right_background;
else if (i == 0) else if (i == 0)
right_bg_rects[i] = &fgeom->right_left_background; right_bg_rects[i] = &fgeom->right_left_background;
@ -4260,6 +4263,7 @@ map_button_state (MetaButtonType button_type,
/* Map position buttons to the corresponding function */ /* Map position buttons to the corresponding function */
case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND: case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND:
case META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND:
if (fgeom->n_right_buttons > 0) if (fgeom->n_right_buttons > 0)
function = fgeom->button_layout.right_buttons[0]; function = fgeom->button_layout.right_buttons[0];
break; break;
@ -4272,6 +4276,7 @@ map_button_state (MetaButtonType button_type,
function = fgeom->button_layout.right_buttons[middle_bg_offset + 1]; function = fgeom->button_layout.right_buttons[middle_bg_offset + 1];
break; break;
case META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND: case META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND:
case META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND:
if (fgeom->n_left_buttons > 0) if (fgeom->n_left_buttons > 0)
function = fgeom->button_layout.left_buttons[0]; function = fgeom->button_layout.left_buttons[0];
break; break;
@ -4309,10 +4314,19 @@ get_button (MetaFrameStyle *style,
parent = parent->parent; parent = parent->parent;
} }
/* We fall back to middle button backgrounds if we don't /* We fall back to the side buttons if we don't have
* have the ones on the sides * single button backgrounds, and to middle button
* backgrounds if we don't have the ones on the sides
*/ */
if (op_list == NULL &&
type == META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND)
return get_button (style, META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND, state);
if (op_list == NULL &&
type == META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND)
return get_button (style, META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND, state);
if (op_list == NULL && if (op_list == NULL &&
(type == META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND || (type == META_BUTTON_TYPE_LEFT_LEFT_BACKGROUND ||
type == META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND)) type == META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND))
@ -4387,6 +4401,10 @@ button_rect (MetaButtonType type,
case META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND: case META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND:
*rect = fgeom->left_right_background; *rect = fgeom->left_right_background;
break; break;
case META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND:
*rect = fgeom->left_single_background;
break;
case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND: case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND:
*rect = fgeom->right_left_background; *rect = fgeom->right_left_background;
@ -4399,6 +4417,10 @@ button_rect (MetaButtonType type,
case META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND: case META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND:
*rect = fgeom->right_right_background; *rect = fgeom->right_right_background;
break; break;
case META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND:
*rect = fgeom->right_single_background;
break;
case META_BUTTON_TYPE_CLOSE: case META_BUTTON_TYPE_CLOSE:
*rect = fgeom->close_rect.visible; *rect = fgeom->close_rect.visible;
@ -5873,12 +5895,16 @@ meta_button_type_from_string (const char *str, MetaTheme *theme)
return META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND; return META_BUTTON_TYPE_LEFT_MIDDLE_BACKGROUND;
else if (strcmp ("left_right_background", str) == 0) else if (strcmp ("left_right_background", str) == 0)
return META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND; return META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND;
else if (strcmp ("left_single_background", str) == 0)
return META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND;
else if (strcmp ("right_left_background", str) == 0) else if (strcmp ("right_left_background", str) == 0)
return META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND; return META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND;
else if (strcmp ("right_middle_background", str) == 0) else if (strcmp ("right_middle_background", str) == 0)
return META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND; return META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND;
else if (strcmp ("right_right_background", str) == 0) else if (strcmp ("right_right_background", str) == 0)
return META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND; return META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND;
else if (strcmp ("right_single_background", str) == 0)
return META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND;
else else
return META_BUTTON_TYPE_LAST; return META_BUTTON_TYPE_LAST;
} }
@ -5914,12 +5940,16 @@ meta_button_type_to_string (MetaButtonType type)
return "left_middle_background"; return "left_middle_background";
case META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND: case META_BUTTON_TYPE_LEFT_RIGHT_BACKGROUND:
return "left_right_background"; return "left_right_background";
case META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND:
return "left_single_background";
case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND: case META_BUTTON_TYPE_RIGHT_LEFT_BACKGROUND:
return "right_left_background"; return "right_left_background";
case META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND: case META_BUTTON_TYPE_RIGHT_MIDDLE_BACKGROUND:
return "right_middle_background"; return "right_middle_background";
case META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND: case META_BUTTON_TYPE_RIGHT_RIGHT_BACKGROUND:
return "right_right_background"; return "right_right_background";
case META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND:
return "right_single_background";
case META_BUTTON_TYPE_LAST: case META_BUTTON_TYPE_LAST:
break; break;
} }
@ -6793,6 +6823,10 @@ meta_theme_earliest_version_with_button (MetaButtonType type)
case META_BUTTON_TYPE_UNSTICK: case META_BUTTON_TYPE_UNSTICK:
return 2000; return 2000;
case META_BUTTON_TYPE_LEFT_SINGLE_BACKGROUND:
case META_BUTTON_TYPE_RIGHT_SINGLE_BACKGROUND:
return 3003;
default: default:
meta_warning("Unknown button %d\n", type); meta_warning("Unknown button %d\n", type);
return 1000; return 1000;