X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Ffloating.c;h=f5641fffa3b81941e2da4ce5e043f8529ba535e8;hb=884214f14fdbd0a4a368d2a36d5e50324fa1d52a;hp=e6ca2d7188d6392c172aa09bf17d6eb0588f6544;hpb=8629c2e208930414f542435509594df051be2009;p=i3%2Fi3 diff --git a/src/floating.c b/src/floating.c index e6ca2d71..f5641fff 100644 --- a/src/floating.c +++ b/src/floating.c @@ -4,7 +4,7 @@ * vim:ts=4:sw=4:expandtab * * i3 - an improved dynamic tiling window manager - * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE) + * © 2009 Michael Stapelberg and contributors (see also: LICENSE) * * floating.c: Floating windows. * @@ -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;