Fix a minor ICCCM incompatibility

ICCCM says that the min size should be used for the base size if no base size is
specified. The only exception is when calculating the aspect ratio of the
window, in that case only the "real" base size may be used.

Awesome didn't do this last part before.

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2010-07-22 09:42:04 +02:00
parent a53aac0dde
commit 8e5409a2cd
1 changed files with 17 additions and 8 deletions

View File

@ -553,12 +553,15 @@ area_t
client_geometry_hints(client_t *c, area_t geometry)
{
int32_t basew, baseh, minw, minh;
int32_t real_basew = 0, real_baseh = 0;
/* base size is substituted with min size if not specified */
if(c->size_hints.flags & XCB_SIZE_HINT_P_SIZE)
{
basew = c->size_hints.base_width;
baseh = c->size_hints.base_height;
real_basew = basew;
real_baseh = baseh;
}
else if(c->size_hints.flags & XCB_SIZE_HINT_P_MIN_SIZE)
{
@ -585,11 +588,17 @@ client_geometry_hints(client_t *c, area_t geometry)
if(c->size_hints.flags & XCB_SIZE_HINT_P_ASPECT
&& c->size_hints.min_aspect_num > 0
&& c->size_hints.min_aspect_den > 0
&& geometry.height - baseh > 0
&& geometry.width - basew > 0)
&& geometry.height - real_baseh > 0
&& geometry.width - real_basew > 0)
{
double dx = (double) (geometry.width - basew);
double dy = (double) (geometry.height - baseh);
/* ICCCM mandates:
* If a base size is provided along with the aspect ratio fields, the
* base size should be subtracted from the window size prior to checking
* that the aspect ratio falls in range. If a base size is not provided,
* nothing should be subtracted from the window size. (The minimum size
* is not to be used in place of the base size for this purpose.) */
double dx = (double) (geometry.width - real_basew);
double dy = (double) (geometry.height - real_baseh);
double min = (double) c->size_hints.min_aspect_num / (double) c->size_hints.min_aspect_den;
double max = (double) c->size_hints.max_aspect_num / (double) c->size_hints.min_aspect_den;
double ratio = dx / dy;
@ -599,15 +608,15 @@ client_geometry_hints(client_t *c, area_t geometry)
{
dy = (dx * min + dy) / (min * min + 1);
dx = dy * min;
geometry.width = (int) dx + basew;
geometry.height = (int) dy + baseh;
geometry.width = (int) dx + real_basew;
geometry.height = (int) dy + real_baseh;
}
else if(ratio > max)
{
dy = (dx * min + dy) / (max * max + 1);
dx = dy * min;
geometry.width = (int) dx + basew;
geometry.height = (int) dy + baseh;
geometry.width = (int) dx + real_basew;
geometry.height = (int) dy + real_baseh;
}
}
}