Allow specifying only one of width and height in per-app settings size

Fixes bug 5819.
This commit is contained in:
Mikael Magnusson 2013-08-11 14:33:46 +02:00 committed by Dana Jansens
parent 937ba3c7e7
commit b2b5df767c
3 changed files with 35 additions and 34 deletions

View file

@ -154,13 +154,10 @@ void config_app_settings_copy_non_defaults(const ObAppSettings *src,
/* monitor is copied above */ /* monitor is copied above */
} }
if (src->size_given) { dst->width_num = src->width_num;
dst->size_given = TRUE; dst->width_denom = src->width_denom;
dst->width_num = src->width_num; dst->height_num = src->height_num;
dst->width_denom = src->width_denom; dst->height_denom = src->height_denom;
dst->height_num = src->height_num;
dst->height_denom = src->height_denom;
}
} }
void config_parse_relative_number(gchar *s, gint *num, gint *denom) void config_parse_relative_number(gchar *s, gint *num, gint *denom)
@ -212,7 +209,6 @@ static void parse_single_per_app_settings(xmlNodePtr app,
{ {
xmlNodePtr n, c; xmlNodePtr n, c;
gboolean x_pos_given = FALSE; gboolean x_pos_given = FALSE;
gboolean width_given = FALSE;
if ((n = obt_xml_find_node(app->children, "decor"))) if ((n = obt_xml_find_node(app->children, "decor")))
if (!obt_xml_node_contains(n, "default")) if (!obt_xml_node_contains(n, "default"))
@ -263,20 +259,22 @@ static void parse_single_per_app_settings(xmlNodePtr app,
config_parse_relative_number(s, config_parse_relative_number(s,
&settings->width_num, &settings->width_num,
&settings->width_denom); &settings->width_denom);
if (settings->width_num > 0 && settings->width_denom >= 0) if (settings->width_num <= 0 || settings->width_denom < 0)
width_given = TRUE; settings->width_num = settings->width_denom = 0;
g_free(s); g_free(s);
} }
} }
if (width_given && (c = obt_xml_find_node(n->children, "height"))) { if ((c = obt_xml_find_node(n->children, "height"))) {
gchar *s = obt_xml_node_string(c); if (!obt_xml_node_contains(c, "default")) {
config_parse_relative_number(s, gchar *s = obt_xml_node_string(c);
&settings->height_num, config_parse_relative_number(s,
&settings->height_denom); &settings->height_num,
if (settings->height_num > 0 && settings->height_denom >= 0) &settings->height_denom);
settings->size_given = TRUE; if (settings->height_num <= 0 || settings->height_denom < 0)
g_free(s); settings->height_num = settings->height_denom = 0;
g_free(s);
}
} }
} }

View file

@ -51,7 +51,6 @@ struct _ObAppSettings
gint width_denom; gint width_denom;
gint height_num; gint height_num;
gint height_denom; gint height_denom;
gboolean size_given;
guint desktop; guint desktop;
gint shade; gint shade;

View file

@ -322,28 +322,32 @@ static void place_per_app_setting_size(ObClient *client, Rect *screen,
gint *w, gint *h, gint *w, gint *h,
ObAppSettings *settings) ObAppSettings *settings)
{ {
if (!settings || !settings->size_given) if (!settings)
return; return;
ob_debug("sizing by per-app settings"); g_assert(settings->width_num >= 0);
g_assert(settings->width_num > 0);
g_assert(settings->width_denom >= 0); g_assert(settings->width_denom >= 0);
g_assert(settings->height_num > 0); g_assert(settings->height_num >= 0);
g_assert(settings->height_denom >= 0); g_assert(settings->height_denom >= 0);
if (!settings->width_denom) if (settings->width_num) {
*w = settings->width_num; ob_debug("setting width by per-app settings");
else { if (!settings->width_denom)
*w = screen->width * settings->width_num / settings->width_denom; *w = settings->width_num;
*w = MIN(*w, screen->width); else {
*w = screen->width * settings->width_num / settings->width_denom;
*w = MIN(*w, screen->width);
}
} }
if (!settings->height_denom) if (settings->height_num) {
*h = settings->height_num; ob_debug("setting height by per-app settings");
else { if (!settings->height_denom)
*h = screen->height * settings->height_num / settings->height_denom; *h = settings->height_num;
*h = MIN(*h, screen->height); else {
*h = screen->height * settings->height_num / settings->height_denom;
*h = MIN(*h, screen->height);
}
} }
} }