Bugfix: Correctly use base_width/base_height and size increment hints, correctly send fake configure notify events

This commit is contained in:
Michael Stapelberg 2009-08-23 21:49:38 +02:00
parent 8c4e2e48f4
commit 55b1bf4582
4 changed files with 27 additions and 17 deletions

View File

@ -346,6 +346,9 @@ struct Client {
int proportional_height; int proportional_height;
int proportional_width; int proportional_width;
int base_height;
int base_width;
/** contains the minimum increment size as specified for the window /** contains the minimum increment size as specified for the window
* (in pixels). */ * (in pixels). */
int width_increment; int width_increment;

View File

@ -1030,13 +1030,9 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
client->width_increment = size_hints.width_inc; client->width_increment = size_hints.width_inc;
if (size_hints.height_inc > 0) if (size_hints.height_inc > 0)
client->height_increment = size_hints.height_inc; client->height_increment = size_hints.height_inc;
}
/* If no aspect ratio was set or if it was invalid, we ignore the hints */ resize_client(conn, client);
if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) || xcb_flush(conn);
(size_hints.min_aspect_num <= 0) ||
(size_hints.min_aspect_den <= 0)) {
return 1;
} }
int base_width = 0, base_height = 0; int base_width = 0, base_height = 0;
@ -1052,6 +1048,16 @@ int handle_normal_hints(void *data, xcb_connection_t *conn, uint8_t state, xcb_w
base_height = size_hints.min_height; base_height = size_hints.min_height;
} }
client->base_width = base_width;
client->base_height = base_height;
/* If no aspect ratio was set or if it was invalid, we ignore the hints */
if (!(size_hints.flags & XCB_SIZE_HINT_P_ASPECT) ||
(size_hints.min_aspect_num <= 0) ||
(size_hints.min_aspect_den <= 0)) {
return 1;
}
double width = client->rect.width - base_width; double width = client->rect.width - base_width;
double height = client->rect.height - base_height; double height = client->rect.height - base_height;
/* Convert numerator/denominator to a double */ /* Convert numerator/denominator to a double */

View File

@ -26,6 +26,7 @@
#include "layout.h" #include "layout.h"
#include "client.h" #include "client.h"
#include "floating.h" #include "floating.h"
#include "handlers.h"
/* /*
* Updates *destination with new_value and returns true if it was changed or false * Updates *destination with new_value and returns true if it was changed or false
@ -298,21 +299,14 @@ void resize_client(xcb_connection_t *conn, Client *client) {
if (client->height_increment > 1) { if (client->height_increment > 1) {
int old_height = rect->height; int old_height = rect->height;
rect->height = ((int)(rect->height / client->height_increment) * client->height_increment); rect->height -= (rect->height - client->base_height) % client->height_increment;
/* We round up if the height was changed */
if (rect->height != old_height)
rect->height++;
LOG("Lost %d pixel due to client's height_increment (%d px)\n", LOG("Lost %d pixel due to client's height_increment (%d px)\n",
old_height - rect->height, client->height_increment); old_height - rect->height, client->height_increment);
} }
if (client->width_increment > 1) { if (client->width_increment > 1) {
int old_width = rect->width; int old_width = rect->width;
rect->width = ((int)(rect->width / client->width_increment) * client->width_increment); rect->width -= (rect->width - client->base_width) % client->width_increment;
/* We round up if the height was changed */
if (rect->width != old_width)
rect->width++;
LOG("Lost %d pixel due to client's width_increment (%d px)\n", LOG("Lost %d pixel due to client's width_increment (%d px)\n",
old_width - rect->width, client->width_increment); old_width - rect->width, client->width_increment);
} }
@ -325,6 +319,13 @@ void resize_client(xcb_connection_t *conn, Client *client) {
* This is necessary to inform the client of its position relative to the root window, * This is necessary to inform the client of its position relative to the root window,
* not relative to its frame (as done in the configure_notify_event by the x server). */ * not relative to its frame (as done in the configure_notify_event by the x server). */
fake_absolute_configure_notify(conn, client); fake_absolute_configure_notify(conn, client);
/* Force redrawing after resizing the window because any now lost
* pixels could contain old garbage. */
xcb_expose_event_t generated;
generated.window = client->frame;
generated.count = 0;
handle_expose_event(NULL, conn, &generated);
} }
/* /*

View File

@ -193,8 +193,8 @@ void fake_absolute_configure_notify(xcb_connection_t *conn, Client *client) {
absolute.x = client->rect.x + client->child_rect.x; absolute.x = client->rect.x + client->child_rect.x;
absolute.y = client->rect.y + client->child_rect.y; absolute.y = client->rect.y + client->child_rect.y;
absolute.width = client->rect.width - (2 * client->child_rect.x); absolute.width = client->child_rect.width;
absolute.height = client->rect.height - client->child_rect.y - 1; absolute.height = client->child_rect.height;
fake_configure_notify(conn, absolute, client->child); fake_configure_notify(conn, absolute, client->child);
} }