Merge branch 'fix-coords'

This commit is contained in:
Michael Stapelberg 2012-08-04 16:09:46 +02:00
commit c5cfe22511
3 changed files with 32 additions and 9 deletions

View File

@ -1001,9 +1001,14 @@ void cmd_move_workspace_to_output(I3_CMD, char *name) {
TAILQ_FOREACH(current, &owindows, owindows) { TAILQ_FOREACH(current, &owindows, owindows) {
Output *current_output = get_output_containing(current->con->rect.x, Output *current_output = get_output_containing(current->con->rect.x,
current->con->rect.y); current->con->rect.y);
if (!current_output) {
ELOG("Cannot get current output. This is a bug in i3.\n");
ysuccess(false);
return;
}
Output *output = get_output_from_string(current_output, name); Output *output = get_output_from_string(current_output, name);
if (!output) { if (!output) {
LOG("No such output\n"); ELOG("Could not get output from string \"%s\"\n", name);
ysuccess(false); ysuccess(false);
return; return;
} }

View File

@ -607,19 +607,24 @@ void floating_reposition(Con *con, Rect newrect) {
* *
*/ */
void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect) { void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect) {
DLOG("Fixing coordinates of floating window %p\n", con); DLOG("Fixing coordinates of floating window %p (rect (%d, %d), %d x %d)\n",
con, con->rect.x, con->rect.y, con->rect.width, con->rect.height);
DLOG("old_rect = (%d, %d), %d x %d\n",
old_rect->x, old_rect->y, old_rect->width, old_rect->height);
DLOG("new_rect = (%d, %d), %d x %d\n",
new_rect->x, new_rect->y, new_rect->width, new_rect->height);
/* First we get the x/y coordinates relative to the x/y coordinates /* First we get the x/y coordinates relative to the x/y coordinates
* of the output on which the window is on */ * of the output on which the window is on */
uint32_t rel_x = (con->rect.x - old_rect->x); int32_t rel_x = (con->rect.x - old_rect->x);
uint32_t rel_y = (con->rect.y - old_rect->y); int32_t rel_y = (con->rect.y - old_rect->y);
/* Then we calculate a fraction, for example 0.63 for a window /* Then we calculate a fraction, for example 0.63 for a window
* which is at y = 1212 of a 1920 px high output */ * which is at y = 1212 of a 1920 px high output */
double fraction_x = ((double)rel_x / old_rect->width); double fraction_x = ((double)rel_x / (int32_t)old_rect->width);
double fraction_y = ((double)rel_y / old_rect->height); double fraction_y = ((double)rel_y / (int32_t)old_rect->height);
DLOG("rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n", DLOG("rel_x = %d, rel_y = %d, fraction_x = %f, fraction_y = %f, output->w = %d, output->h = %d\n",
rel_x, rel_y, fraction_x, fraction_y, old_rect->width, old_rect->height); rel_x, rel_y, fraction_x, fraction_y, old_rect->width, old_rect->height);
con->rect.x = new_rect->x + (fraction_x * new_rect->width); con->rect.x = (int32_t)new_rect->x + (fraction_x * (int32_t)new_rect->width);
con->rect.y = new_rect->y + (fraction_y * new_rect->height); con->rect.y = (int32_t)new_rect->y + (fraction_y * (int32_t)new_rect->height);
DLOG("Resulting coordinates: x = %d, y = %d\n", con->rect.x, con->rect.y); DLOG("Resulting coordinates: x = %d, y = %d\n", con->rect.x, con->rect.y);
} }

View File

@ -359,6 +359,19 @@ void init_ws_for_output(Output *output, Con *content) {
workspace_show(previous); workspace_show(previous);
} }
/* Render the output on which the workspace was to get correct Rects.
* Then, we need to work with the "content" container, since we cannot
* be sure that the workspace itself was rendered at all (in case its
* invisible, it wont be rendered). */
render_con(workspace_out, false);
Con *ws_out_content = output_get_content(workspace_out);
Con *floating_con;
TAILQ_FOREACH(floating_con, &(workspace->floating_head), floating_windows)
/* NB: We use output->con here because content is not yet rendered,
* so it has a rect of {0, 0, 0, 0}. */
floating_fix_coordinates(floating_con, &(ws_out_content->rect), &(output->con->rect));
con_detach(workspace); con_detach(workspace);
con_attach(workspace, content, false); con_attach(workspace, content, false);
@ -682,7 +695,7 @@ void randr_query_outputs(void) {
DLOG("Fixing the coordinates of floating containers\n"); DLOG("Fixing the coordinates of floating containers\n");
Con *floating_con; Con *floating_con;
TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows) TAILQ_FOREACH(floating_con, &(current->floating_head), floating_windows)
floating_fix_coordinates(floating_con, &(old_content->rect), &(first_content->rect)); floating_fix_coordinates(floating_con, &(output->con->rect), &(first->con->rect));
DLOG("Done, next\n"); DLOG("Done, next\n");
} }
DLOG("re-attached all workspaces\n"); DLOG("re-attached all workspaces\n");