]> Dogcows Code - chaz/tint2/commitdiff
*add* allow xrandr names (hopefully works)
authorAndreas Fink <andreas.fink85@googlemail.com>
Sat, 20 Mar 2010 08:30:41 +0000 (08:30 +0000)
committerAndreas Fink <andreas.fink85@googlemail.com>
Sat, 20 Mar 2010 08:30:41 +0000 (08:30 +0000)
configure.ac
src/config.c
src/server.c
src/server.h
src/tint.c

index 5365a80a2328879b361d4792bd93671a28068704..4efd9fc5dc98d10c9c00f67b59de08cf72dad1ac 100644 (file)
@@ -66,7 +66,7 @@ PKG_CHECK_MODULES([GOBJECT2], [gobject-2.0])
 AC_SUBST(GOBJECT2_CFLAGS)
 AC_SUBST(GOBJECT2_LIBS)
 
-PKG_CHECK_MODULES([X11], [x11 xcomposite xdamage xinerama xrender])
+PKG_CHECK_MODULES([X11], [x11 xcomposite xdamage xinerama xrender xrandr])
 AC_SUBST(X11_CFLAGS)
 AC_SUBST(X11_LIBS)
 
index f825d5b9ce44d045690964234fbf2d9aa3c0f9a9..150face8b7f172eac0b7536f94dc4c951419a445 100644 (file)
@@ -185,6 +185,30 @@ int get_task_status(char* status)
 }
 
 
+int config_get_monitor(char* monitor)
+{
+       if (strcmp(monitor, "all") == 0)
+               return -1;
+       else {
+               char* endptr;
+               int ret_int = strtol(monitor, &endptr, 10);
+               if (*endptr == 0)
+                       return ret_int-1;
+               else {
+                       // monitor specified by name, not by index
+                       int i, j;
+                       for (i=0; i<server.nb_monitor; ++i) {
+                               j = 0;
+                               while (server.monitor[i].names[j] != 0) {
+                                       if (strcmp(monitor, server.monitor[i].names[j++]) == 0)
+                                               return i;
+                               }
+                       }
+               }
+       }
+       return -1;
+}
+
 void add_entry (char *key, char *value)
 {
        char *value1=0, *value2=0, *value3=0;
@@ -216,11 +240,7 @@ void add_entry (char *key, char *value)
 
        /* Panel */
        else if (strcmp (key, "panel_monitor") == 0) {
-               if (strcmp (value, "all") == 0) panel_config.monitor = -1;
-               else {
-                       panel_config.monitor = atoi (value);
-                       if (panel_config.monitor > 0) panel_config.monitor -= 1;
-               }
+               panel_config.monitor = config_get_monitor(value);
        }
        else if (strcmp (key, "panel_size") == 0) {
                extract_values(value, &value1, &value2, &value3);
index 5557a0152aeb201185adb0845911c1f44a612c11..99c4e5118b65e3c4f9002d97d9af460823f54d9b 100644 (file)
@@ -19,6 +19,8 @@
 **************************************************************************/
 
 #include <X11/extensions/Xrender.h>
+#include <X11/extensions/Xrandr.h>
+
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -104,7 +106,12 @@ void cleanup_server()
 {
        if (server.colormap) XFreeColormap(server.dsp, server.colormap);
        if (server.colormap32) XFreeColormap(server.dsp, server.colormap32);
-       if (server.monitor) free(server.monitor);
+       if (server.monitor) {
+               int i;
+               for (i=0; i<server.nb_monitor; ++i)
+                       g_strfreev(server.monitor[i].names);
+               free(server.monitor);
+       }
        if (server.gc) XFreeGC(server.dsp, server.gc);
 }
 
@@ -245,42 +252,75 @@ int compareMonitorIncluded(const void *monitor1, const void *monitor2)
 
 void get_monitors()
 {
-       if (server.monitor) free(server.monitor);
+       if (server.monitor) {
+               int i;
+               for (i=0; i<server.nb_monitor; ++i)
+                       g_strfreev(server.monitor[i].names);
+               free(server.monitor);
+       }
        server.nb_monitor = 0;
        server.monitor = 0;
 
        int i, j, nbmonitor;
        if (XineramaIsActive(server.dsp)) {
                XineramaScreenInfo *info = XineramaQueryScreens(server.dsp, &nbmonitor);
-
-               if (info && nbmonitor > 0) {
+               XRRScreenResources *res = XRRGetScreenResourcesCurrent(server.dsp, server.root_win);
+
+               if (res->ncrtc >= nbmonitor) {
+                       // use xrandr to identify monitors (does not work with proprietery nvidia drivers)
+                       printf("xRandr: Found crtc's: %d\n", res->ncrtc );
+                       server.monitor = malloc(res->ncrtc * sizeof(Monitor));
+                       for (i=0; i<res->ncrtc; ++i) {
+                               XRRCrtcInfo* crtc_info = XRRGetCrtcInfo(server.dsp, res, res->crtcs[i]);
+                               server.monitor[i].x = crtc_info->x;
+                               server.monitor[i].y = crtc_info->y;
+                               server.monitor[i].width = crtc_info->width;
+                               server.monitor[i].height = crtc_info->height;
+                               server.monitor[i].names = malloc((crtc_info->noutput+1) * sizeof(char*));
+                               for (j=0; j<crtc_info->noutput; ++j) {
+                                       XRROutputInfo* output_info = XRRGetOutputInfo(server.dsp, res, crtc_info->outputs[j]);
+                                       printf("xRandr: Linking output %s with crtc %d\n", output_info->name, i);
+                                       server.monitor[i].names[j] = g_strdup(output_info->name);
+                                       XRRFreeOutputInfo(output_info);
+                               }
+                               server.monitor[i].names[j] = 0;
+                               XRRFreeCrtcInfo(crtc_info);
+                       }
+                       nbmonitor = res->ncrtc;
+               }
+               else 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;
+                               server.monitor[i].names = 0;
                        }
-                       XFree(info);
-
-                       // ordered monitor
-                       qsort(server.monitor, nbmonitor, sizeof(Monitor), compareMonitorIncluded);
-
-                       // remove monitor included into another one
-                       i = 0;
-                       while (i < nbmonitor) {
-                               for (j=0; j < i ; j++) {
-                                       if (compareMonitorIncluded(&server.monitor[i], &server.monitor[j]) > 0) {
-                                               goto next;
-                                       }
+               }
+
+               // ordered monitor
+               qsort(server.monitor, nbmonitor, sizeof(Monitor), compareMonitorIncluded);
+
+               // remove monitor included into another one
+               i = 0;
+               while (i < nbmonitor) {
+                       for (j=0; j < i ; j++) {
+                               if (compareMonitorIncluded(&server.monitor[i], &server.monitor[j]) > 0) {
+                                       goto next;
                                }
-                               i++;
                        }
-next:
-                       server.nb_monitor = i;
-                       server.monitor = realloc(server.monitor, server.nb_monitor * sizeof(Monitor));
-                       qsort(server.monitor, server.nb_monitor, sizeof(Monitor), compareMonitorPos);
+                       i++;
                }
+next:
+               for (j=i; j<server.nb_monitor; ++j)
+                       g_strfreev(server.monitor[j].names);
+               server.nb_monitor = i;
+               server.monitor = realloc(server.monitor, server.nb_monitor * sizeof(Monitor));
+               qsort(server.monitor, server.nb_monitor, sizeof(Monitor), compareMonitorPos);
+
+               XRRFreeScreenResources(res);
+               XFree(info);
        }
 
        if (!server.nb_monitor) {
index 9c2b2cfb6ae32db8a4740ff92e07f15fd39cd2df..cc6ffeea9aaf74b8d6ed4f752eb1225ac45a4eb4 100644 (file)
@@ -78,6 +78,7 @@ typedef struct Monitor
        int y;
        int width;
        int height;
+       char** names;
 } Monitor;
 
 
index 23970f087b32a91208cd67881bdc0cf48922f07b..2c30f3731f1405277199c14d558df643c4078e8e 100644 (file)
@@ -692,6 +692,8 @@ int main (int argc, char *argv[])
 
        init (argc, argv);
        init_config();
+       init_X11();
+
        i = 0;
        if (config_path)
                i = config_read_file (config_path);
@@ -703,7 +705,6 @@ int main (int argc, char *argv[])
                exit(1);
        }
 
-       init_X11();
        init_panel();
        cleanup_config();
        if (snapshot_path) {
This page took 0.032859 seconds and 4 git commands to generate.