mirror of
https://github.com/vale981/bspwm
synced 2025-03-06 10:11:43 -05:00
Merge overlapping monitors
This commit is contained in:
parent
1aad51ef0b
commit
ca2d03072a
1 changed files with 25 additions and 7 deletions
32
monitor.c
32
monitor.c
|
@ -88,6 +88,8 @@ monitor_t *add_monitor(xcb_rectangle_t rect)
|
||||||
|
|
||||||
void remove_monitor(monitor_t *m)
|
void remove_monitor(monitor_t *m)
|
||||||
{
|
{
|
||||||
|
PRINTF("remove monitor %s (0x%X)\n", m->name, m->id);
|
||||||
|
|
||||||
while (m->desk_head != NULL)
|
while (m->desk_head != NULL)
|
||||||
remove_desktop(m, m->desk_head);
|
remove_desktop(m, m->desk_head);
|
||||||
monitor_t *prev = m->prev;
|
monitor_t *prev = m->prev;
|
||||||
|
@ -219,6 +221,9 @@ bool import_monitors(void)
|
||||||
if (sres == NULL)
|
if (sres == NULL)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
monitor_t *m, *mm = NULL;
|
||||||
|
unsigned int num = 0;
|
||||||
|
|
||||||
int len = xcb_randr_get_screen_resources_current_outputs_length(sres);
|
int len = xcb_randr_get_screen_resources_current_outputs_length(sres);
|
||||||
xcb_randr_output_t *outputs = xcb_randr_get_screen_resources_current_outputs(sres);
|
xcb_randr_output_t *outputs = xcb_randr_get_screen_resources_current_outputs(sres);
|
||||||
|
|
||||||
|
@ -226,12 +231,9 @@ bool import_monitors(void)
|
||||||
for (int i = 0; i < len; i++)
|
for (int i = 0; i < len; i++)
|
||||||
cookies[i] = xcb_randr_get_output_info(dpy, outputs[i], XCB_CURRENT_TIME);
|
cookies[i] = xcb_randr_get_output_info(dpy, outputs[i], XCB_CURRENT_TIME);
|
||||||
|
|
||||||
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
for (m = mon_head; m != NULL; m = m->next)
|
||||||
m->wired = false;
|
m->wired = false;
|
||||||
|
|
||||||
monitor_t *mm = NULL;
|
|
||||||
unsigned int num = 0;
|
|
||||||
|
|
||||||
for (int i = 0; i < len; i++) {
|
for (int i = 0; i < len; i++) {
|
||||||
xcb_randr_get_output_info_reply_t *info = xcb_randr_get_output_info_reply(dpy, cookies[i], NULL);
|
xcb_randr_get_output_info_reply_t *info = xcb_randr_get_output_info_reply(dpy, cookies[i], NULL);
|
||||||
if (info != NULL && info->crtc != XCB_NONE) {
|
if (info != NULL && info->crtc != XCB_NONE) {
|
||||||
|
@ -276,17 +278,33 @@ bool import_monitors(void)
|
||||||
}
|
}
|
||||||
free(gpo);
|
free(gpo);
|
||||||
|
|
||||||
|
/* handle overlapping monitors */
|
||||||
|
m = mon_head;
|
||||||
|
while (m != NULL) {
|
||||||
|
monitor_t *next = m->next;
|
||||||
|
if (m->wired) {
|
||||||
|
for (monitor_t *mb = mon_head; mb != NULL; mb = mb->next)
|
||||||
|
if (mb != m && mb->wired && contains(mb->rectangle, m->rectangle)) {
|
||||||
|
if (mm == m)
|
||||||
|
mm = mb;
|
||||||
|
merge_monitors(m, mb);
|
||||||
|
remove_monitor(m);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
m = next;
|
||||||
|
}
|
||||||
|
|
||||||
/* add one desktop to each new monitor */
|
/* add one desktop to each new monitor */
|
||||||
for (monitor_t *m = mon_head; m != NULL; m = m->next)
|
for (m = mon_head; m != NULL; m = m->next)
|
||||||
if (m->desk == NULL && (running || pri_mon == NULL || m != pri_mon))
|
if (m->desk == NULL && (running || pri_mon == NULL || m != pri_mon))
|
||||||
add_desktop(m, make_desktop(NULL));
|
add_desktop(m, make_desktop(NULL));
|
||||||
|
|
||||||
/* merge and remove disconnected monitors */
|
/* merge and remove disconnected monitors */
|
||||||
monitor_t *m = mon_head;
|
m = mon_head;
|
||||||
while (m != NULL) {
|
while (m != NULL) {
|
||||||
monitor_t *next = m->next;
|
monitor_t *next = m->next;
|
||||||
if (!m->wired) {
|
if (!m->wired) {
|
||||||
PRINTF("remove monitor %s (0x%X)\n", m->name, m->id);
|
|
||||||
merge_monitors(m, mm);
|
merge_monitors(m, mm);
|
||||||
remove_monitor(m);
|
remove_monitor(m);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue