+/*
+ * Repositions the CT_FLOATING_CON to have the coordinates specified by
+ * newrect, but only if the coordinates are not out-of-bounds. Also reassigns
+ * the floating con to a different workspace if this move was across different
+ * outputs.
+ *
+ */
+void floating_reposition(Con *con, Rect newrect) {
+ /* Sanity check: Are the new coordinates on any output? If not, we
+ * ignore that request. */
+ Output *output = get_output_containing(
+ newrect.x + (newrect.width / 2),
+ newrect.y + (newrect.height / 2));
+
+ if (!output) {
+ ELOG("No output found at destination coordinates. Not repositioning.\n");
+ return;
+ }
+
+ con->rect = newrect;
+
+ floating_maybe_reassign_ws(con);
+ tree_render();
+}
+
+/*
+ * Fixes the coordinates of the floating window whenever the window gets
+ * reassigned to a different output (or when the output’s rect changes).
+ *
+ */
+void floating_fix_coordinates(Con *con, Rect *old_rect, Rect *new_rect) {
+ DLOG("Fixing coordinates of floating window %p\n", con);
+ /* First we get the x/y coordinates relative to the x/y coordinates
+ * of the output on which the window is on */
+ uint32_t rel_x = (con->rect.x - old_rect->x);
+ uint32_t rel_y = (con->rect.y - old_rect->y);
+ /* Then we calculate a fraction, for example 0.63 for a window
+ * which is at y = 1212 of a 1920 px high output */
+ double fraction_x = ((double)rel_x / old_rect->width);
+ double fraction_y = ((double)rel_y / old_rect->height);
+ 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);
+ con->rect.x = new_rect->x + (fraction_x * new_rect->width);
+ con->rect.y = new_rect->y + (fraction_y * new_rect->height);
+ DLOG("Resulting coordinates: x = %d, y = %d\n", con->rect.x, con->rect.y);
+}
+