Center transient windows over their parent

f9d5f530ab51cf694a5f9eb7247c6f2f75be1e24
Alexis Sellier committed ago 1 parent dc74e0b4
swm.c +8 -0
1259 1259
1260 1260
    if (box->y + box->height <= bounds->y)
1261 1261
        box->y = bounds->y;
1262 1262
}
1263 1263
1264 +
/* Center a box over another box without changing its size. */
1265 +
static void swm_box_center(struct swm_box *box, const struct swm_box *parent) {
1266 +
    box->x = parent->x + (parent->width - box->width) / 2;
1267 +
    box->y = parent->y + (parent->height - box->height) / 2;
1268 +
}
1269 +
1264 1270
/* Resize a box from the selected edges. */
1265 1271
struct swm_box swm_box_resize(
1266 1272
    const struct swm_box *box, int dx, int dy, unsigned int edges, unsigned int border
1267 1273
) {
1268 1274
    int            minimum = 1 + 2 * (int)border;
4108 4114
    }
4109 4115
    /* Child windows float on their parent's workspace and display. Apply the
4110 4116
     * configured matching rules to other windows. */
4111 4117
    if ((p = client_get_parent(c))) {
4112 4118
        c->is_floating = true;
4119 +
        /* Surface geometry is local; place the child in layout coordinates. */
4120 +
        swm_box_center((struct swm_box *)&c->geom, (const struct swm_box *)&p->geom);
4113 4121
        set_monitor(c, p->mon, p->ws);
4114 4122
    } else {
4115 4123
        apply_rules(c, spawnws);
4116 4124
        c->persist_float  = c->is_floating;
4117 4125
        oldbw             = c->bw;
test/unit.c +2 -0
75 75
    struct swm_box cursor = { 20, 30, 4, 10 };
76 76
    struct swm_box output = { 0, 0, 500, 400 };
77 77
78 78
    swm_box_apply_bounds(&box, &bounds, 2);
79 79
    assert_box(box, 105, 95, 5, 5);
80 +
    swm_box_center(&box, &(struct swm_box){ -1920, 40, 1600, 900 });
81 +
    assert_box(box, -1123, 487, 5, 5);
80 82
    box = (struct swm_box){ 10, 20, 100, 80 };
81 83
    assert_box(swm_box_resize(&box, 20, 10, 10, 1), 10, 20, 120, 90);
82 84
    assert_box(swm_box_resize(&box, 500, 500, 5, 2), 105, 95, 5, 5);
83 85
    swm_box_reconcile_commit(&box, 90, 70, 2, 5);
84 86
    assert_box(box, 16, 26, 94, 74);