]> Dogcows Code - chaz/tint2/commitdiff
improved multi-monitor detection. need more work.
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Wed, 21 Oct 2009 21:13:13 +0000 (21:13 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Wed, 21 Oct 2009 21:13:13 +0000 (21:13 +0000)
src/panel.c
src/server.c
src/tint.c

index c28db61c73e08727b1d4285752188a92037eb9fa..0bd2c4cc8e30efd8f9bd86bbab3668ad011c7a16 100644 (file)
@@ -138,7 +138,7 @@ void init_panel()
 
                if (i >= old_nb_panel) {
                        // new panel
-                       //printf("new window\n");
+                       printf("new panel %d, %d, %d, %d\n", p->posx, p->posy, p->area.width, p->area.height);
 
                        // Catch some events
                        long event_mask = ExposureMask|ButtonPressMask|ButtonReleaseMask;
@@ -154,7 +154,7 @@ void init_panel()
                }
                else {
                        // old panel
-                       //printf("move old window\n");
+                       printf("old panel %d, %d, %d, %d\n", p->posx, p->posy, p->area.width, p->area.height);
                        XMoveResizeWindow(server.dsp, p->main_win, p->posx, p->posy, p->area.width, p->area.height);
                        set_panel_background(p);
                }
index c501ec1e6eecec09328b6ae669c005535953a815..56a12446114c7fca1cdbb16670788c844e3b2a19 100644 (file)
@@ -193,7 +193,7 @@ void get_root_pixmap()
 }
 
 
-int compareMonitor(const void *monitor1, const void *monitor2)
+int compareMonitorPos(const void *monitor1, const void *monitor2)
 {
        Monitor *m1 = (Monitor*)monitor1;
        Monitor *m2 = (Monitor*)monitor2;
@@ -201,21 +201,33 @@ int compareMonitor(const void *monitor1, const void *monitor2)
        if (m1->x < m2->x) {
                return -1;
        }
-       else
-               if (m1->x > m2->x) {
-                       return 1;
-               }
-               else
-                       if (m1->width < m2->width) {
-                               return 1;
-                       }
-                       else
-                               if (m1->width > m2->width) {
-                                       return -1;
-                               }
-                               else {
-                                       return 0;
-                               }
+       else if (m1->x > m2->x) {
+               return 1;
+       }
+       else if (m1->y < m2->y) {
+               return -1;
+       }
+       else if (m1->y > m2->y) {
+               return 1;
+       }
+       else {
+               return 0;
+       }
+}
+
+
+int compareMonitorIncluded(const void *monitor1, const void *monitor2)
+{
+       Monitor *m1 = (Monitor*)monitor1;
+       Monitor *m2 = (Monitor*)monitor2;
+
+       if (m1->x >= m2->x && m1->y >= m2->y && (m1->x+m1->width) <= (m2->x+m2->width) && (m1->y+m1->height) <= (m2->y+m2->height)) {
+               // m1 included inside m2
+               return 1;
+       }
+       else {
+               return -1;
+       }
 }
 
 
@@ -225,49 +237,44 @@ void get_monitors()
        server.nb_monitor = 0;
        server.monitor = 0;
 
-       int i, nb_monitor;
+       int i, j, nbmonitor;
        if (XineramaIsActive(server.dsp)) {
-               XineramaScreenInfo *info = XineramaQueryScreens(server.dsp, &nb_monitor);
+               XineramaScreenInfo *info = XineramaQueryScreens(server.dsp, &nbmonitor);
+
+               if (info && nbmonitor > 0) {
+                       server.monitor = malloc(nbmonitor * sizeof(Monitor));
+                       for (i=0 ; i < nbmonitor ; i++) {
+                               server.monitor[i].x = info[i].x_org;
+                               server.monitor[i].y = info[i].y_org;
+                               server.monitor[i].width = info[i].width;
+                               server.monitor[i].height = info[i].height;
+                       }
+                       XFree(info);
 
-               if (info) {
-                       int nb=0, j;
+                       // ordered monitor
+                       qsort(server.monitor, nbmonitor, sizeof(Monitor), compareMonitorIncluded);
 
+                       // remove monitor included into another one
                        i = 0;
-                       server.monitor = calloc(nb_monitor, sizeof(Monitor));
-                       while (i < nb_monitor) {
-                               for (j = 0; j < i; j++) {
-                                       if (info[i].x_org >= info[j].x_org && info[i].y_org >= info[j].y_org && (info[i].x_org+info[i].width) <= (info[j].x_org+info[j].width) && (info[i].y_org+info[i].height) <= (info[j].y_org+info[j].height)) {
-                                               if (info[i].x_org == info[j].x_org && info[i].y_org == info[j].y_org && info[i].width == info[j].width && info[i].height == info[j].height && nb == 0) {
-                                                       // add the first monitor
-                                                       break;
-                                               }
-                                               else {
-                                                       // doesn't count monitor 'i' because it's included into another one
-                                                       //fprintf(stderr, "monitor %d included into another one\n", i);
-                                                       goto next;
-                                               }
+                       while (i < nbmonitor) {
+                               for (j=0; j < i ; j++) {
+                                       if (compareMonitorIncluded(&server.monitor[i], &server.monitor[j]) > 0) {
+                                               goto next;
                                        }
                                }
-
-                               server.monitor[nb].x = info[i].x_org;
-                               server.monitor[nb].y = info[i].y_org;
-                               server.monitor[nb].width = info[i].width;
-                               server.monitor[nb].height = info[i].height;
-                               nb++;
-next:
                                i++;
                        }
-                       XFree(info);
-                       server.nb_monitor = nb;
-
-                       // ordered monitor according to coordinate
-                       qsort(server.monitor, server.nb_monitor, sizeof(Monitor), compareMonitor);
+next:
+                       server.nb_monitor = i;
+                       server.monitor = realloc(server.monitor, server.nb_monitor * sizeof(Monitor));                  
+                       //printf("  nbmonitor %d\n", server.nb_monitor);
+                       qsort(server.monitor, server.nb_monitor, sizeof(Monitor), compareMonitorPos);
                }
        }
 
        if (!server.nb_monitor) {
                server.nb_monitor = 1;
-               server.monitor = calloc(server.nb_monitor, sizeof(Monitor));
+               server.monitor = malloc(sizeof(Monitor));
                server.monitor[0].x = server.monitor[0].y = 0;
                server.monitor[0].width = DisplayWidth (server.dsp, server.screen);
                server.monitor[0].height = DisplayHeight (server.dsp, server.screen);
index 70b07c8521e383fc60030128bc444667d1963522..88f33434888152b699a26b8b008047d33477c84a 100644 (file)
@@ -861,7 +861,10 @@ int main (int argc, char *argv[])
                switch (signal_pending) {
                        case SIGUSR1:
                                signal_pending = 0;
-                               return 0;
+                               printf("SIGUSR1\n");
+                               config_read_file (config_path);
+                               init_panel();
+                               break;
                        case SIGINT:
                        case SIGTERM:
                        case SIGHUP:
This page took 0.031164 seconds and 4 git commands to generate.