Share window geometry translation across output changes

2f656d6cfb54b5f2c46d621e44be36e4a4bc16bc
Alexis Sellier committed ago 1 parent 94b33783
swm.c +16 -18
5447 5447
5448 5448
    if (mv && sel)
5449 5449
        focus_client(sel, 1);
5450 5450
}
5451 5451
5452 -
/* Preserve a window's position relative to its display during directed moves. */
5453 -
static void client_translate_monitor(client_t *c, monitor_t *oldmon, monitor_t *newmon) {
5454 -
    struct wlr_box *geom;
5452 +
/* Shift a window's normal geometry and its saved floating geometry. */
5453 +
static void client_translate_geometry(client_t *c, int dx, int dy) {
5454 +
    struct wlr_box *geom = c->is_fullscreen ? &c->prev : &c->geom;
5455 5455
5456 -
    if (!c || !oldmon || !newmon || oldmon == newmon)
5457 -
        return;
5458 -
    geom     = c->is_fullscreen ? &c->prev : &c->geom;
5459 -
    geom->x += newmon->m.x - oldmon->m.x;
5460 -
    geom->y += newmon->m.y - oldmon->m.y;
5456 +
    geom->x += dx;
5457 +
    geom->y += dy;
5461 5458
    if (c->is_max_stacked) {
5462 -
        c->maxstack_prev.x += newmon->m.x - oldmon->m.x;
5463 -
        c->maxstack_prev.y += newmon->m.y - oldmon->m.y;
5459 +
        c->maxstack_prev.x += dx;
5460 +
        c->maxstack_prev.y += dy;
5464 5461
    }
5465 5462
}
5466 5463
5464 +
/* Preserve a window's position relative to its display during directed moves. */
5465 +
static void client_translate_monitor(client_t *c, monitor_t *oldmon, monitor_t *newmon) {
5466 +
    if (c && oldmon && newmon && oldmon != newmon)
5467 +
        client_translate_geometry(c, newmon->m.x - oldmon->m.x, newmon->m.y - oldmon->m.y);
5468 +
}
5469 +
5467 5470
/* Fit a window to the display it was just moved to. */
5468 5471
void client_place(client_t *c) {
5469 5472
    /* An initial commit may assign a monitor before map_notify() creates the
5470 5473
     * client's scene tree. Defer all scene operations until the surface maps. */
5471 5474
    if (!c->mon || !client_surface(c)->mapped)
6805 6808
        m->w        = m->m;
6806 6809
        /* Keep current and saved window positions relative to the output. */
6807 6810
        wl_list_for_each(c, &clients, link) {
6808 6811
            if (c->mon != m)
6809 6812
                continue;
6810 -
            c->geom.x += m->m.x - old.x;
6811 -
            c->geom.y += m->m.y - old.y;
6813 +
            client_translate_geometry(c, m->m.x - old.x, m->m.y - old.y);
6812 6814
            if (c->is_fullscreen) {
6813 -
                c->prev.x += m->m.x - old.x;
6814 -
                c->prev.y += m->m.y - old.y;
6815 -
            }
6816 -
            if (c->is_max_stacked) {
6817 -
                c->maxstack_prev.x += m->m.x - old.x;
6818 -
                c->maxstack_prev.y += m->m.y - old.y;
6815 +
                c->geom.x += m->m.x - old.x;
6816 +
                c->geom.y += m->m.y - old.y;
6819 6817
            }
6820 6818
        }
6821 6819
        wlr_scene_output_set_position(m->scene_output, m->m.x, m->m.y);
6822 6820
6823 6821
        wlr_scene_node_set_position(&m->fullscreen_bg->node, m->m.x, m->m.y);