mirror of
https://github.com/vale981/bspwm
synced 2025-03-06 10:11:43 -05:00
Initially center floating windows on their monitor
And simplify fit_monitor along the way.
This commit is contained in:
parent
dc575c74b8
commit
114881d958
2 changed files with 5 additions and 21 deletions
12
monitor.c
12
monitor.c
|
@ -73,17 +73,7 @@ monitor_t *get_monitor_by_id(xcb_randr_output_t id)
|
|||
|
||||
void fit_monitor(monitor_t *m, client_t *c)
|
||||
{
|
||||
xcb_rectangle_t crect = c->floating_rectangle;
|
||||
xcb_rectangle_t mrect = m->rectangle;
|
||||
while (crect.x < mrect.x)
|
||||
crect.x += mrect.width;
|
||||
while (crect.x > (mrect.x + mrect.width - 1))
|
||||
crect.x -= mrect.width;
|
||||
while (crect.y < mrect.y)
|
||||
crect.y += mrect.height;
|
||||
while (crect.y > (mrect.y + mrect.height - 1))
|
||||
crect.y -= mrect.height;
|
||||
c->floating_rectangle = crect;
|
||||
center(m->rectangle, &c->floating_rectangle);
|
||||
}
|
||||
|
||||
void update_root(monitor_t *m)
|
||||
|
|
14
window.c
14
window.c
|
@ -61,6 +61,7 @@ void manage_window(monitor_t *m, desktop_t *d, xcb_window_t win)
|
|||
|
||||
client_t *c = make_client(win);
|
||||
update_floating_rectangle(c);
|
||||
fit_monitor(m, c);
|
||||
c->frame = frame;
|
||||
|
||||
xcb_icccm_get_wm_class_reply_t reply;
|
||||
|
@ -89,11 +90,6 @@ void manage_window(monitor_t *m, desktop_t *d, xcb_window_t win)
|
|||
set_fullscreen(n, fullscreen);
|
||||
c->transient = transient;
|
||||
|
||||
xcb_rectangle_t *frect = &n->client->floating_rectangle;
|
||||
if (frect->x == 0 && frect->y == 0)
|
||||
center(m->rectangle, frect);
|
||||
fit_monitor(m, n->client);
|
||||
|
||||
arrange(m, d);
|
||||
|
||||
bool give_focus = (takes_focus && (d == mon->desk || follow));
|
||||
|
@ -270,10 +266,8 @@ pointer_state_t *make_pointer_state(void)
|
|||
|
||||
void center(xcb_rectangle_t a, xcb_rectangle_t *b)
|
||||
{
|
||||
if (b->width < a.width)
|
||||
b->x = a.x + (a.width - b->width) / 2;
|
||||
if (b->height < a.height)
|
||||
b->y = a.y + (a.height - b->height) / 2;
|
||||
b->x = a.x + (a.width - b->width) / 2;
|
||||
b->y = a.y + (a.height - b->height) / 2;
|
||||
}
|
||||
|
||||
bool contains(xcb_rectangle_t a, xcb_rectangle_t b)
|
||||
|
@ -547,7 +541,7 @@ void update_floating_rectangle(client_t *c)
|
|||
if (geo != NULL)
|
||||
c->floating_rectangle = (xcb_rectangle_t) {geo->x, geo->y, geo->width, geo->height};
|
||||
else
|
||||
c->floating_rectangle = (xcb_rectangle_t) {0, 0, 32, 24};
|
||||
c->floating_rectangle = (xcb_rectangle_t) {0, 0, 320, 240};
|
||||
|
||||
free(geo);
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue