From: Michael Stapelberg Date: Sat, 12 Dec 2009 21:27:57 +0000 (+0100) Subject: Take into account the window’s base_{width,height} when resizing (Thanks Mirko) X-Git-Tag: 3.e~6^2~204 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f87b98e0a7bf385fd60c06281c96cc2d9c768c44;p=i3%2Fi3 Take into account the window’s base_{width,height} when resizing (Thanks Mirko) --- diff --git a/include/client.h b/include/client.h index 9da3a5ec..dced48ec 100644 --- a/include/client.h +++ b/include/client.h @@ -112,6 +112,20 @@ void client_map(xcb_connection_t *conn, Client *client); */ void client_mark(xcb_connection_t *conn, Client *client, const char *mark); +/** + * Returns the minimum height of a specific window. The height is calculated + * by using 2 pixels (for the client window itself), possibly padding this to + * comply with the client’s base_height and then adding the decoration height. + * + */ +uint32_t client_min_height(Client *client); + +/** + * See client_min_height. + * + */ +uint32_t client_min_width(Client *client); + /** * Pretty-prints the client’s information into the logfile. * diff --git a/src/client.c b/src/client.c index b686a1ae..2de501ea 100644 --- a/src/client.c +++ b/src/client.c @@ -26,6 +26,7 @@ #include "client.h" #include "table.h" #include "workspace.h" +#include "config.h" /* * Removes the given client from the container, either because it will be inserted into another @@ -372,3 +373,38 @@ void client_mark(xcb_connection_t *conn, Client *client, const char *mark) { break; } } + +/* + * Returns the minimum height of a specific window. The height is calculated + * by using 2 pixels (for the client window itself), possibly padding this to + * comply with the client’s base_height and then adding the decoration height. + * + */ +uint32_t client_min_height(Client *client) { + uint32_t height = max(2, client->base_height); + i3Font *font = load_font(global_conn, config.font); + + if (client->titlebar_position == TITLEBAR_OFF && client->borderless) + return height; + + if (client->titlebar_position == TITLEBAR_OFF && !client->borderless) + return height + 2; + + return height + font->height + 2 + 2; +} + +/* + * See client_min_height. + * + */ +uint32_t client_min_width(Client *client) { + uint32_t width = max(2, client->base_width); + + if (client->titlebar_position == TITLEBAR_OFF && client->borderless) + return width; + + if (client->titlebar_position == TITLEBAR_OFF && !client->borderless) + return width + 2; + + return width + 2 + 2; +} diff --git a/src/floating.c b/src/floating.c index 4177b6e5..a8557416 100644 --- a/src/floating.c +++ b/src/floating.c @@ -173,7 +173,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre case BORDER_RIGHT: { int new_width = old_rect->width + (new_x - event->root_x); if ((new_width < 0) || - (new_width < 50 && client->rect.width >= new_width)) + (new_width < client_min_width(client) && client->rect.width >= new_width)) return; client->rect.width = new_width; break; @@ -182,7 +182,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre case BORDER_BOTTOM: { int new_height = old_rect->height + (new_y - event->root_y); if ((new_height < 0) || - (new_height < 20 && client->rect.height >= new_height)) + (new_height < client_min_height(client) && client->rect.height >= new_height)) return; client->rect.height = old_rect->height + (new_y - event->root_y); break; @@ -191,7 +191,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre case BORDER_TOP: { int new_height = old_rect->height + (event->root_y - new_y); if ((new_height < 0) || - (new_height < 20 && client->rect.height >= new_height)) + (new_height < client_min_height(client) && client->rect.height >= new_height)) return; client->rect.y = old_rect->y + (new_y - event->root_y); @@ -202,7 +202,7 @@ int floating_border_click(xcb_connection_t *conn, Client *client, xcb_button_pre case BORDER_LEFT: { int new_width = old_rect->width + (event->root_x - new_x); if ((new_width < 0) || - (new_width < 50 && client->rect.width >= new_width)) + (new_width < client_min_width(client) && client->rect.width >= new_width)) return; client->rect.x = old_rect->x + (new_x - event->root_x); client->rect.width = new_width; @@ -273,10 +273,10 @@ void floating_resize_window(xcb_connection_t *conn, Client *client, xcb_button_p int32_t new_height = old_rect->height + (new_y - event->root_y); /* Obey minimum window size and reposition the client */ - if (new_width >= 50) + if (new_width > 0 && new_width >= client_min_width(client)) client->rect.width = new_width; - if (new_height >= 20) + if (new_height > 0 && new_height >= client_min_height(client)) client->rect.height = new_height; /* resize_client flushes */