Sort Xinerama monitors by x before using them
This commit is contained in:
parent
6fb75424e8
commit
81ef4a8eb7
38
bar.c
38
bar.c
|
@ -393,6 +393,12 @@ monitor_add (monitor_t *mon)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
rect_sort_cb (const void *p1, const void *p2)
|
||||||
|
{
|
||||||
|
return ((xcb_rectangle_t *)p1)->x - ((xcb_rectangle_t *)p2)->x;
|
||||||
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
get_randr_outputs(void)
|
get_randr_outputs(void)
|
||||||
{
|
{
|
||||||
|
@ -505,30 +511,44 @@ get_xinerama_screens (void)
|
||||||
xcb_xinerama_query_screens_reply_t *xqs_reply;
|
xcb_xinerama_query_screens_reply_t *xqs_reply;
|
||||||
xcb_xinerama_screen_info_iterator_t iter;
|
xcb_xinerama_screen_info_iterator_t iter;
|
||||||
int width = cfg.width;
|
int width = cfg.width;
|
||||||
|
int i, screens;
|
||||||
|
|
||||||
xqs_reply = xcb_xinerama_query_screens_reply (c,
|
xqs_reply = xcb_xinerama_query_screens_reply (c,
|
||||||
xcb_xinerama_query_screens_unchecked (c), NULL);
|
xcb_xinerama_query_screens_unchecked (c), NULL);
|
||||||
|
|
||||||
iter = xcb_xinerama_query_screens_screen_info_iterator (xqs_reply);
|
iter = xcb_xinerama_query_screens_screen_info_iterator (xqs_reply);
|
||||||
|
|
||||||
/* The width is consumed across all the screens */
|
xcb_rectangle_t rects[iter.rem];
|
||||||
|
|
||||||
while (iter.rem) {
|
/* Fetch all the screens first */
|
||||||
|
for (i = 0; iter.rem; i++) {
|
||||||
|
rects[i].x = iter.data->x_org;
|
||||||
|
rects[i].y = iter.data->y_org;
|
||||||
|
rects[i].width = iter.data->width;
|
||||||
|
rects[i].height = iter.data->height;
|
||||||
|
xcb_xinerama_screen_info_next (&iter);
|
||||||
|
}
|
||||||
|
|
||||||
|
screens = i;
|
||||||
|
|
||||||
|
/* Sort by X */
|
||||||
|
qsort(rects, i, sizeof(xcb_rectangle_t), rect_sort_cb);
|
||||||
|
|
||||||
|
/* The width is consumed across all the screens */
|
||||||
|
for (i = 0; i < screens; i++) {
|
||||||
monitor_t *mon = monitor_new (
|
monitor_t *mon = monitor_new (
|
||||||
iter.data->x_org,
|
rects[i].x,
|
||||||
iter.data->y_org,
|
rects[i].y,
|
||||||
MIN(width, iter.data->width),
|
MIN(width, rects[i].width),
|
||||||
iter.data->height);
|
rects[i].height);
|
||||||
|
|
||||||
monitor_add (mon);
|
monitor_add (mon);
|
||||||
|
|
||||||
width -= iter.data->width;
|
width -= rects[i].width;
|
||||||
|
|
||||||
/* No need to check for other monitors */
|
/* No need to check for other monitors */
|
||||||
if (width <= 0)
|
if (width <= 0)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
xcb_xinerama_screen_info_next (&iter);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free (xqs_reply);
|
free (xqs_reply);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user