mirror of
https://github.com/brl/mutter.git
synced 2024-11-22 08:00:42 -05:00
test button aspect ratio instead of hardcoded button size, James feel free
2002-06-03 Havoc Pennington <hp@pobox.com> * src/themes/Esco/metacity-theme-1.xml: test button aspect ratio instead of hardcoded button size, James feel free to revert if you don't like it this way. * src/theme-parser.c: parse the aspect_ratio element for button aspect ratios. * src/theme.h (struct _MetaFrameLayout): allow button sizes to be given as an aspect ratio derived from the titlebar height, instead of as a fixed size. * src/theme.c (meta_frame_layout_validate): validate new button sizing parameters * src/theme.c (meta_frame_layout_calc_geometry): use new button layout params
This commit is contained in:
parent
22bbeb0ae0
commit
85815f8188
19
ChangeLog
19
ChangeLog
@ -1,3 +1,22 @@
|
|||||||
|
2002-06-03 Havoc Pennington <hp@pobox.com>
|
||||||
|
|
||||||
|
* src/themes/Esco/metacity-theme-1.xml: test button aspect ratio
|
||||||
|
instead of hardcoded button size, James feel free to revert if you
|
||||||
|
don't like it this way.
|
||||||
|
|
||||||
|
* src/theme-parser.c: parse the aspect_ratio element for button
|
||||||
|
aspect ratios.
|
||||||
|
|
||||||
|
* src/theme.h (struct _MetaFrameLayout): allow button sizes to be
|
||||||
|
given as an aspect ratio derived from the titlebar height,
|
||||||
|
instead of as a fixed size.
|
||||||
|
|
||||||
|
* src/theme.c (meta_frame_layout_validate): validate new button
|
||||||
|
sizing parameters
|
||||||
|
|
||||||
|
* src/theme.c (meta_frame_layout_calc_geometry): use new button
|
||||||
|
layout params
|
||||||
|
|
||||||
Mon Jun 3 15:12:11 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
|
Mon Jun 3 15:12:11 2002 HideToshi Tajima <hidetoshi.tajima@sun.com>
|
||||||
|
|
||||||
* configure.in (METACITY_LIBS): put -lXext into SHAPE_LIBS
|
* configure.in (METACITY_LIBS): put -lXext into SHAPE_LIBS
|
||||||
|
@ -42,6 +42,7 @@ typedef enum
|
|||||||
STATE_FRAME_GEOMETRY,
|
STATE_FRAME_GEOMETRY,
|
||||||
STATE_DISTANCE,
|
STATE_DISTANCE,
|
||||||
STATE_BORDER,
|
STATE_BORDER,
|
||||||
|
STATE_ASPECT_RATIO,
|
||||||
/* draw ops */
|
/* draw ops */
|
||||||
STATE_DRAW_OPS,
|
STATE_DRAW_OPS,
|
||||||
STATE_LINE,
|
STATE_LINE,
|
||||||
@ -1309,9 +1310,92 @@ parse_distance (GMarkupParseContext *context,
|
|||||||
else if (strcmp (name, "left_titlebar_edge") == 0)
|
else if (strcmp (name, "left_titlebar_edge") == 0)
|
||||||
info->layout->left_titlebar_edge = val;
|
info->layout->left_titlebar_edge = val;
|
||||||
else if (strcmp (name, "button_width") == 0)
|
else if (strcmp (name, "button_width") == 0)
|
||||||
|
{
|
||||||
info->layout->button_width = val;
|
info->layout->button_width = val;
|
||||||
|
|
||||||
|
if (!(info->layout->button_sizing == META_BUTTON_SIZING_LAST ||
|
||||||
|
info->layout->button_sizing == META_BUTTON_SIZING_FIXED))
|
||||||
|
{
|
||||||
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
|
_("Cannot specify both button_width/button_height and aspect ratio for buttons"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info->layout->button_sizing = META_BUTTON_SIZING_FIXED;
|
||||||
|
}
|
||||||
else if (strcmp (name, "button_height") == 0)
|
else if (strcmp (name, "button_height") == 0)
|
||||||
|
{
|
||||||
info->layout->button_height = val;
|
info->layout->button_height = val;
|
||||||
|
|
||||||
|
if (!(info->layout->button_sizing == META_BUTTON_SIZING_LAST ||
|
||||||
|
info->layout->button_sizing == META_BUTTON_SIZING_FIXED))
|
||||||
|
{
|
||||||
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
|
_("Cannot specify both button_width/button_height and aspect ratio for buttons"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info->layout->button_sizing = META_BUTTON_SIZING_FIXED;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
|
_("Distance \"%s\" is unknown"), name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
parse_aspect_ratio (GMarkupParseContext *context,
|
||||||
|
const gchar *element_name,
|
||||||
|
const gchar **attribute_names,
|
||||||
|
const gchar **attribute_values,
|
||||||
|
ParseInfo *info,
|
||||||
|
GError **error)
|
||||||
|
{
|
||||||
|
const char *name;
|
||||||
|
const char *value;
|
||||||
|
double val;
|
||||||
|
|
||||||
|
if (!locate_attributes (context, element_name, attribute_names, attribute_values,
|
||||||
|
error,
|
||||||
|
"name", &name, "value", &value,
|
||||||
|
NULL))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (name == NULL)
|
||||||
|
{
|
||||||
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
|
_("No \"name\" attribute on element <%s>"), element_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value == NULL)
|
||||||
|
{
|
||||||
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
|
_("No \"value\" attribute on element <%s>"), element_name);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = 0;
|
||||||
|
if (!parse_double (value, &val, context, error))
|
||||||
|
return;
|
||||||
|
|
||||||
|
g_assert (info->layout);
|
||||||
|
|
||||||
|
if (strcmp (name, "button") == 0)
|
||||||
|
{
|
||||||
|
info->layout->button_aspect = val;
|
||||||
|
|
||||||
|
if (info->layout->button_sizing != META_BUTTON_SIZING_LAST)
|
||||||
|
{
|
||||||
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
|
_("Cannot specify both button_width/button_height and aspect ratio for buttons"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
info->layout->button_sizing = META_BUTTON_SIZING_ASPECT;
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
@ -1446,6 +1530,14 @@ parse_geometry_element (GMarkupParseContext *context,
|
|||||||
info, error);
|
info, error);
|
||||||
push_state (info, STATE_BORDER);
|
push_state (info, STATE_BORDER);
|
||||||
}
|
}
|
||||||
|
else if (ELEMENT_IS ("aspect_ratio"))
|
||||||
|
{
|
||||||
|
parse_aspect_ratio (context, element_name,
|
||||||
|
attribute_names, attribute_values,
|
||||||
|
info, error);
|
||||||
|
|
||||||
|
push_state (info, STATE_ASPECT_RATIO);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
set_error (error, context,
|
set_error (error, context,
|
||||||
@ -3535,8 +3627,9 @@ start_element_handler (GMarkupParseContext *context,
|
|||||||
break;
|
break;
|
||||||
case STATE_DISTANCE:
|
case STATE_DISTANCE:
|
||||||
case STATE_BORDER:
|
case STATE_BORDER:
|
||||||
|
case STATE_ASPECT_RATIO:
|
||||||
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
set_error (error, context, G_MARKUP_ERROR, G_MARKUP_ERROR_PARSE,
|
||||||
_("Element <%s> is not allowed inside a distance/border element"),
|
_("Element <%s> is not allowed inside a distance/border/aspect_ratio element"),
|
||||||
element_name);
|
element_name);
|
||||||
break;
|
break;
|
||||||
case STATE_DRAW_OPS:
|
case STATE_DRAW_OPS:
|
||||||
@ -3687,6 +3780,10 @@ end_element_handler (GMarkupParseContext *context,
|
|||||||
pop_state (info);
|
pop_state (info);
|
||||||
g_assert (peek_state (info) == STATE_FRAME_GEOMETRY);
|
g_assert (peek_state (info) == STATE_FRAME_GEOMETRY);
|
||||||
break;
|
break;
|
||||||
|
case STATE_ASPECT_RATIO:
|
||||||
|
pop_state (info);
|
||||||
|
g_assert (peek_state (info) == STATE_FRAME_GEOMETRY);
|
||||||
|
break;
|
||||||
case STATE_DRAW_OPS:
|
case STATE_DRAW_OPS:
|
||||||
{
|
{
|
||||||
g_assert (info->op_list);
|
g_assert (info->op_list);
|
||||||
@ -4007,6 +4104,9 @@ text_handler (GMarkupParseContext *context,
|
|||||||
case STATE_BORDER:
|
case STATE_BORDER:
|
||||||
NO_TEXT ("border");
|
NO_TEXT ("border");
|
||||||
break;
|
break;
|
||||||
|
case STATE_ASPECT_RATIO:
|
||||||
|
NO_TEXT ("aspect_ratio");
|
||||||
|
break;
|
||||||
case STATE_DRAW_OPS:
|
case STATE_DRAW_OPS:
|
||||||
NO_TEXT ("draw_ops");
|
NO_TEXT ("draw_ops");
|
||||||
break;
|
break;
|
||||||
|
69
src/theme.c
69
src/theme.c
@ -330,6 +330,8 @@ meta_frame_layout_new (void)
|
|||||||
layout->right_titlebar_edge = -1;
|
layout->right_titlebar_edge = -1;
|
||||||
layout->left_titlebar_edge = -1;
|
layout->left_titlebar_edge = -1;
|
||||||
|
|
||||||
|
layout->button_sizing = META_BUTTON_SIZING_LAST;
|
||||||
|
layout->button_aspect = 1.0;
|
||||||
layout->button_width = -1;
|
layout->button_width = -1;
|
||||||
layout->button_height = -1;
|
layout->button_height = -1;
|
||||||
|
|
||||||
@ -416,8 +418,30 @@ meta_frame_layout_validate (const MetaFrameLayout *layout,
|
|||||||
CHECK_GEOMETRY_VALUE (right_titlebar_edge);
|
CHECK_GEOMETRY_VALUE (right_titlebar_edge);
|
||||||
CHECK_GEOMETRY_VALUE (left_titlebar_edge);
|
CHECK_GEOMETRY_VALUE (left_titlebar_edge);
|
||||||
|
|
||||||
|
switch (layout->button_sizing)
|
||||||
|
{
|
||||||
|
case META_BUTTON_SIZING_ASPECT:
|
||||||
|
if (layout->button_aspect < (0.1) ||
|
||||||
|
layout->button_aspect > (15.0))
|
||||||
|
{
|
||||||
|
g_set_error (error, META_THEME_ERROR,
|
||||||
|
META_THEME_ERROR_FRAME_GEOMETRY,
|
||||||
|
_("Button aspect ratio %g is not reasonable"),
|
||||||
|
layout->button_aspect);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case META_BUTTON_SIZING_FIXED:
|
||||||
CHECK_GEOMETRY_VALUE (button_width);
|
CHECK_GEOMETRY_VALUE (button_width);
|
||||||
CHECK_GEOMETRY_VALUE (button_height);
|
CHECK_GEOMETRY_VALUE (button_height);
|
||||||
|
break;
|
||||||
|
case META_BUTTON_SIZING_LAST:
|
||||||
|
g_set_error (error, META_THEME_ERROR,
|
||||||
|
META_THEME_ERROR_FRAME_GEOMETRY,
|
||||||
|
_("Frame geometry does not specify size of buttons"));
|
||||||
|
return FALSE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
CHECK_GEOMETRY_BORDER (button_border);
|
CHECK_GEOMETRY_BORDER (button_border);
|
||||||
|
|
||||||
@ -517,6 +541,7 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
|
|||||||
int button_y;
|
int button_y;
|
||||||
int title_right_edge;
|
int title_right_edge;
|
||||||
int width, height;
|
int width, height;
|
||||||
|
int button_width, button_height;
|
||||||
|
|
||||||
meta_frame_layout_get_borders (layout, text_height,
|
meta_frame_layout_get_borders (layout, text_height,
|
||||||
flags,
|
flags,
|
||||||
@ -538,17 +563,35 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
|
|||||||
|
|
||||||
x = width - layout->right_titlebar_edge;
|
x = width - layout->right_titlebar_edge;
|
||||||
|
|
||||||
/* center buttons */
|
switch (layout->button_sizing)
|
||||||
|
{
|
||||||
|
case META_BUTTON_SIZING_ASPECT:
|
||||||
|
button_height = fgeom->top_height - layout->button_border.top - layout->button_border.bottom;
|
||||||
|
button_width = button_height / layout->button_aspect;
|
||||||
|
break;
|
||||||
|
case META_BUTTON_SIZING_FIXED:
|
||||||
|
button_width = layout->button_width;
|
||||||
|
button_height = layout->button_height;
|
||||||
|
break;
|
||||||
|
case META_BUTTON_SIZING_LAST:
|
||||||
|
g_assert_not_reached ();
|
||||||
|
/* gcc warnings */
|
||||||
|
button_width = -1;
|
||||||
|
button_height = -1;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* center buttons vertically */
|
||||||
button_y = (fgeom->top_height -
|
button_y = (fgeom->top_height -
|
||||||
(layout->button_height + layout->button_border.top + layout->button_border.bottom)) / 2 + layout->button_border.top;
|
(button_height + layout->button_border.top + layout->button_border.bottom)) / 2 + layout->button_border.top;
|
||||||
|
|
||||||
if ((flags & META_FRAME_ALLOWS_DELETE) &&
|
if ((flags & META_FRAME_ALLOWS_DELETE) &&
|
||||||
x >= 0)
|
x >= 0)
|
||||||
{
|
{
|
||||||
fgeom->close_rect.x = x - layout->button_border.right - layout->button_width;
|
fgeom->close_rect.x = x - layout->button_border.right - button_width;
|
||||||
fgeom->close_rect.y = button_y;
|
fgeom->close_rect.y = button_y;
|
||||||
fgeom->close_rect.width = layout->button_width;
|
fgeom->close_rect.width = button_width;
|
||||||
fgeom->close_rect.height = layout->button_height;
|
fgeom->close_rect.height = button_height;
|
||||||
|
|
||||||
x = fgeom->close_rect.x - layout->button_border.left;
|
x = fgeom->close_rect.x - layout->button_border.left;
|
||||||
}
|
}
|
||||||
@ -563,10 +606,10 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
|
|||||||
if ((flags & META_FRAME_ALLOWS_MAXIMIZE) &&
|
if ((flags & META_FRAME_ALLOWS_MAXIMIZE) &&
|
||||||
x >= 0)
|
x >= 0)
|
||||||
{
|
{
|
||||||
fgeom->max_rect.x = x - layout->button_border.right - layout->button_width;
|
fgeom->max_rect.x = x - layout->button_border.right - button_width;
|
||||||
fgeom->max_rect.y = button_y;
|
fgeom->max_rect.y = button_y;
|
||||||
fgeom->max_rect.width = layout->button_width;
|
fgeom->max_rect.width = button_width;
|
||||||
fgeom->max_rect.height = layout->button_height;
|
fgeom->max_rect.height = button_height;
|
||||||
|
|
||||||
x = fgeom->max_rect.x - layout->button_border.left;
|
x = fgeom->max_rect.x - layout->button_border.left;
|
||||||
}
|
}
|
||||||
@ -581,10 +624,10 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
|
|||||||
if ((flags & META_FRAME_ALLOWS_MINIMIZE) &&
|
if ((flags & META_FRAME_ALLOWS_MINIMIZE) &&
|
||||||
x >= 0)
|
x >= 0)
|
||||||
{
|
{
|
||||||
fgeom->min_rect.x = x - layout->button_border.right - layout->button_width;
|
fgeom->min_rect.x = x - layout->button_border.right - button_width;
|
||||||
fgeom->min_rect.y = button_y;
|
fgeom->min_rect.y = button_y;
|
||||||
fgeom->min_rect.width = layout->button_width;
|
fgeom->min_rect.width = button_width;
|
||||||
fgeom->min_rect.height = layout->button_height;
|
fgeom->min_rect.height = button_height;
|
||||||
|
|
||||||
x = fgeom->min_rect.x - layout->button_border.left;
|
x = fgeom->min_rect.x - layout->button_border.left;
|
||||||
}
|
}
|
||||||
@ -605,8 +648,8 @@ meta_frame_layout_calc_geometry (const MetaFrameLayout *layout,
|
|||||||
{
|
{
|
||||||
fgeom->menu_rect.x = x + layout->button_border.left;
|
fgeom->menu_rect.x = x + layout->button_border.left;
|
||||||
fgeom->menu_rect.y = button_y;
|
fgeom->menu_rect.y = button_y;
|
||||||
fgeom->menu_rect.width = layout->button_width;
|
fgeom->menu_rect.width = button_width;
|
||||||
fgeom->menu_rect.height = layout->button_height;
|
fgeom->menu_rect.height = button_height;
|
||||||
|
|
||||||
x = fgeom->menu_rect.x + fgeom->menu_rect.width + layout->button_border.right;
|
x = fgeom->menu_rect.x + fgeom->menu_rect.width + layout->button_border.right;
|
||||||
}
|
}
|
||||||
|
10
src/theme.h
10
src/theme.h
@ -52,6 +52,12 @@ typedef enum
|
|||||||
META_THEME_ERROR_FAILED
|
META_THEME_ERROR_FAILED
|
||||||
} MetaThemeError;
|
} MetaThemeError;
|
||||||
|
|
||||||
|
typedef enum
|
||||||
|
{
|
||||||
|
META_BUTTON_SIZING_ASPECT,
|
||||||
|
META_BUTTON_SIZING_FIXED,
|
||||||
|
META_BUTTON_SIZING_LAST
|
||||||
|
} MetaButtonSizing;
|
||||||
|
|
||||||
/* Parameters used to calculate the geometry of the frame */
|
/* Parameters used to calculate the geometry of the frame */
|
||||||
struct _MetaFrameLayout
|
struct _MetaFrameLayout
|
||||||
@ -74,6 +80,10 @@ struct _MetaFrameLayout
|
|||||||
int left_titlebar_edge;
|
int left_titlebar_edge;
|
||||||
|
|
||||||
/* Size of buttons */
|
/* Size of buttons */
|
||||||
|
MetaButtonSizing button_sizing;
|
||||||
|
|
||||||
|
double button_aspect; /* height / width */
|
||||||
|
|
||||||
int button_width;
|
int button_width;
|
||||||
int button_height;
|
int button_height;
|
||||||
|
|
||||||
|
@ -15,11 +15,10 @@
|
|||||||
<distance name="bottom_height" value="5"/>
|
<distance name="bottom_height" value="5"/>
|
||||||
<distance name="left_titlebar_edge" value="5"/>
|
<distance name="left_titlebar_edge" value="5"/>
|
||||||
<distance name="right_titlebar_edge" value="5"/>
|
<distance name="right_titlebar_edge" value="5"/>
|
||||||
<distance name="button_width" value="16"/>
|
<aspect_ratio name="button" value="1.0"/>
|
||||||
<distance name="button_height" value="16"/>
|
|
||||||
<distance name="title_vertical_pad" value="3"/>
|
<distance name="title_vertical_pad" value="3"/>
|
||||||
<border name="title_border" left="3" right="3" top="4" bottom="3"/>
|
<border name="title_border" left="3" right="3" top="4" bottom="3"/>
|
||||||
<border name="button_border" left="0" right="1" top="0" bottom="0"/>
|
<border name="button_border" left="0" right="1" top="4" bottom="3"/>
|
||||||
</frame_geometry>
|
</frame_geometry>
|
||||||
|
|
||||||
<!-- strip borders off the normal geometry -->
|
<!-- strip borders off the normal geometry -->
|
||||||
|
@ -27,6 +27,8 @@ Themes are in a simple XML-subset format.
|
|||||||
<distance name="right_titlebar_edge" value="6"/>
|
<distance name="right_titlebar_edge" value="6"/>
|
||||||
<distance name="button_width" value="17"/>
|
<distance name="button_width" value="17"/>
|
||||||
<distance name="button_height" value="17"/>
|
<distance name="button_height" value="17"/>
|
||||||
|
<!-- alternative to button_width button_height distances -->
|
||||||
|
<aspect_ratio name="button" value="1.0"/>
|
||||||
<distance name="title_vertical_pad" value="4"/>
|
<distance name="title_vertical_pad" value="4"/>
|
||||||
<border name="title_border" left="3" right="12" top="4" bottom="3"/>
|
<border name="title_border" left="3" right="12" top="4" bottom="3"/>
|
||||||
<border name="button_border" left="0" right="0" top="1" bottom="1"/>
|
<border name="button_border" left="0" right="0" top="1" bottom="1"/>
|
||||||
|
Loading…
Reference in New Issue
Block a user