Handle floating centering in one function and test for consistency

This commit is contained in:
Deiz
2015-03-30 03:10:40 -04:00
parent 2759a308a2
commit c6581a5fd6
5 changed files with 128 additions and 20 deletions

View File

@ -1761,25 +1761,18 @@ void cmd_move_window_to_center(I3_CMD, char *method) {
}
if (strcmp(method, "absolute") == 0) {
Rect *rect = &focused->parent->rect;
DLOG("moving to absolute center\n");
rect->x = croot->rect.width / 2 - rect->width / 2;
rect->y = croot->rect.height / 2 - rect->height / 2;
floating_center(focused->parent, croot->rect);
floating_maybe_reassign_ws(focused->parent);
cmd_output->needs_tree_render = true;
}
if (strcmp(method, "position") == 0) {
Rect *wsrect = &con_get_workspace(focused)->rect;
Rect newrect = focused->parent->rect;
DLOG("moving to center\n");
newrect.x = wsrect->x + wsrect->width / 2 - newrect.width / 2;
newrect.y = wsrect->y + wsrect->height / 2 - newrect.height / 2;
floating_center(focused->parent, con_get_workspace(focused)->rect);
floating_reposition(focused->parent, newrect);
cmd_output->needs_tree_render = true;
}
// XXX: default reply for now, make this a better reply

View File

@ -246,12 +246,10 @@ void floating_enable(Con *con, bool automatic) {
if (con->window && con->window->leader != XCB_NONE &&
(leader = con_by_window_id(con->window->leader)) != NULL) {
DLOG("Centering above leader\n");
nc->rect.x = leader->rect.x + (leader->rect.width / 2) - (nc->rect.width / 2);
nc->rect.y = leader->rect.y + (leader->rect.height / 2) - (nc->rect.height / 2);
floating_center(nc, leader->rect);
} else {
/* center the window on workspace as fallback */
nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
floating_center(nc, ws->rect);
}
}
@ -310,8 +308,7 @@ void floating_enable(Con *con, bool automatic) {
}
ELOG("No output found at destination coordinates, centering floating window on current ws\n");
nc->rect.x = ws->rect.x + (ws->rect.width / 2) - (nc->rect.width / 2);
nc->rect.y = ws->rect.y + (ws->rect.height / 2) - (nc->rect.height / 2);
floating_center(nc, ws->rect);
ipc_send_window_event("floating", con);
}
@ -420,6 +417,15 @@ bool floating_maybe_reassign_ws(Con *con) {
return true;
}
/*
* Centers a floating con above the specified rect.
*
*/
void floating_center(Con *con, Rect rect) {
con->rect.x = rect.x + (rect.width / 2) - (con->rect.width / 2);
con->rect.y = rect.y + (rect.height / 2) - (con->rect.height / 2);
}
DRAGGING_CB(drag_window_callback) {
const struct xcb_button_press_event_t *event = extra;

View File

@ -198,10 +198,7 @@ void scratchpad_show(Con *con) {
con->rect.width = output->rect.width * 0.5;
con->rect.height = output->rect.height * 0.75;
floating_check_size(con);
con->rect.x = output->rect.x +
((output->rect.width / 2.0) - (con->rect.width / 2.0));
con->rect.y = output->rect.y +
((output->rect.height / 2.0) - (con->rect.height / 2.0));
floating_center(con, con_get_workspace(con)->rect);
}
/* Activate active workspace if window is from another workspace to ensure