Skip to content

Commit

Permalink
Initially center floating windows on their monitor
Browse files Browse the repository at this point in the history
And simplify fit_monitor along the way.
  • Loading branch information
baskerville committed Oct 19, 2013
1 parent dc575c7 commit 114881d
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 21 deletions.
12 changes: 1 addition & 11 deletions monitor.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
14 changes: 4 additions & 10 deletions window.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 114881d

Please sign in to comment.