Merge pull request #2355 from psychon/gravity_changes

Some gravity changes
This commit is contained in:
mergify[bot] 2018-08-18 22:07:26 +00:00 committed by GitHub
commit 8151a13e44
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 29 additions and 30 deletions

View File

@ -345,17 +345,13 @@ event_handle_configurerequest(xcb_configure_request_event_t *ev)
if(ev->value_mask & XCB_CONFIG_WINDOW_X)
{
int16_t diff = 0;
geometry.x = ev->x;
xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &diff, NULL);
geometry.x += diff;
xwindow_translate_for_gravity(c->size_hints.win_gravity, deco_left, 0, deco_right, 0, &geometry.x, NULL);
}
if(ev->value_mask & XCB_CONFIG_WINDOW_Y)
{
int16_t diff = 0;
geometry.y = ev->y;
xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &diff);
geometry.y += diff;
xwindow_translate_for_gravity(c->size_hints.win_gravity, 0, deco_top, 0, deco_bottom, NULL, &geometry.y);
}
if(ev->value_mask & XCB_CONFIG_WINDOW_WIDTH)
{

View File

@ -1389,12 +1389,9 @@ border_width_callback(client_t *c, uint16_t old_width, uint16_t new_width)
{
area_t geometry = c->geometry;
int16_t diff = new_width - old_width;
int16_t diff_x = 0, diff_y = 0;
xwindow_translate_for_gravity(c->size_hints.win_gravity,
diff, diff, diff, diff,
&diff_x, &diff_y);
geometry.x += diff_x;
geometry.y += diff_y;
&geometry.x, &geometry.y);
/* inform client about changes */
client_resize_do(c, geometry);
}
@ -2872,13 +2869,10 @@ titlebar_resize(lua_State *L, int cidx, client_t *c, client_titlebar_t bar, int
if(c->size_hints.flags & XCB_ICCCM_SIZE_HINT_P_WIN_GRAVITY)
{
int16_t diff_x = 0, diff_y = 0;
xwindow_translate_for_gravity(c->size_hints.win_gravity,
diff_left, diff_top,
diff_right, diff_bottom,
&diff_x, &diff_y);
geometry.x += diff_x;
geometry.y += diff_y;
&geometry.x, &geometry.y);
}
c->titlebar[bar].size = size;

View File

@ -244,6 +244,14 @@ static const char *state_to_string(enum test_state state)
}
}
static int32_t div2(int32_t value, int32_t *rounding)
{
/* If value is odd, we could round up or down */
if (value & 1)
*rounding = 1;
return value / 2;
}
static void check_geometry(int32_t expected_x, int32_t expected_y, uint32_t expected_width, uint32_t expected_height)
{
int32_t actual_x, actual_y;
@ -252,6 +260,7 @@ static void check_geometry(int32_t expected_x, int32_t expected_y, uint32_t expe
&left, &right, &top, &bottom);
int32_t offset_x, offset_y;
int32_t extra_x = 0, extra_y = 0;
int32_t diff_x = state_difference[window_state.state][0], diff_y = state_difference[window_state.state][1];
switch (window_state.gravity)
{
@ -260,7 +269,7 @@ static void check_geometry(int32_t expected_x, int32_t expected_y, uint32_t expe
offset_y = top;
break;
case XCB_GRAVITY_NORTH:
offset_x = (left - right + diff_x + 1) / 2;
offset_x = div2(left - right + diff_x, &extra_x);;
offset_y = top;
break;
case XCB_GRAVITY_NORTH_EAST:
@ -269,22 +278,22 @@ static void check_geometry(int32_t expected_x, int32_t expected_y, uint32_t expe
break;
case XCB_GRAVITY_WEST:
offset_x = left;
offset_y = (top - bottom + diff_y + 1) / 2;
offset_y = div2(top - bottom + diff_y, &extra_y);
break;
case XCB_GRAVITY_CENTER:
offset_x = (left - right + diff_x + 1) / 2;
offset_y = (top - bottom + diff_y + 1) / 2;
offset_x = div2(left - right + diff_x, &extra_x);
offset_y = div2(top - bottom + diff_y, &extra_y);
break;
case XCB_GRAVITY_EAST:
offset_x = -right + diff_x;
offset_y = (top - bottom + diff_y + 1) / 2;
offset_y = div2(top - bottom + diff_y, &extra_y);
break;
case XCB_GRAVITY_SOUTH_WEST:
offset_x = left;
offset_y = -bottom + diff_y;
break;
case XCB_GRAVITY_SOUTH:
offset_x = (left - right + diff_x + 1) / 2;
offset_x = div2(left - right + diff_x, &extra_x);
offset_y = -bottom + diff_y;
break;
case XCB_GRAVITY_SOUTH_EAST:
@ -312,12 +321,12 @@ static void check_geometry(int32_t expected_x, int32_t expected_y, uint32_t expe
check(expected_height == actual_height,
"For window with gravity %s in state %s, expected height = %d, but got %d",
gravity_to_string(window_state.gravity), state_to_string(window_state.state), (int) expected_height, (int) actual_height);
check(expected_x + offset_x == actual_x,
"For window with gravity %s in state %s, expected x = %d+%d, but got %d",
gravity_to_string(window_state.gravity), state_to_string(window_state.state), (int) expected_x, (int) offset_x, (int) actual_x);
check(expected_y + offset_y == actual_y,
"For window with gravity %s in state %s, expected y = %d+%d, but got %d",
gravity_to_string(window_state.gravity), state_to_string(window_state.state), (int) expected_y, (int) offset_y, (int) actual_y);
check(expected_x + offset_x == actual_x || expected_x + offset_x + extra_x == actual_x,
"For window with gravity %s in state %s, expected x = %d+%d (+%d), but got %d",
gravity_to_string(window_state.gravity), state_to_string(window_state.state), (int) expected_x, (int) offset_x, (int) extra_x, (int) actual_x);
check(expected_y + offset_y == actual_y || expected_y + offset_y + extra_y == actual_y,
"For window with gravity %s in state %s, expected y = %d+%d (+%d), but got %d",
gravity_to_string(window_state.gravity), state_to_string(window_state.state), (int) expected_y, (int) offset_y, (int) extra_y, (int) actual_y);
}
static void init(xcb_gravity_t gravity)

View File

@ -400,8 +400,8 @@ xwindow_set_shape(xcb_window_t win, int width, int height, enum xcb_shape_sk_t k
* \param change_height_before The window height difference that will be applied.
* \param change_width_after The window width difference that will be applied.
* \param change_height_after The window height difference that will be applied.
* \param dx On return, this will be set to the amount the pixel has to be moved.
* \param dy On return, this will be set to the amount the pixel has to be moved.
* \param dx On return, this will be changed by the amount the pixel has to be moved.
* \param dy On return, this will be changed by the amount the pixel has to be moved.
*/
void xwindow_translate_for_gravity(xcb_gravity_t gravity, int16_t change_width_before, int16_t change_height_before,
int16_t change_width_after, int16_t change_height_after, int16_t *dx, int16_t *dy)
@ -449,9 +449,9 @@ void xwindow_translate_for_gravity(xcb_gravity_t gravity, int16_t change_width_b
}
if (dx)
*dx = x;
*dx += x;
if (dy)
*dy = y;
*dy += y;
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80