From: Andreas Fink Date: Sat, 20 Mar 2010 08:30:41 +0000 (+0000) Subject: *add* allow xrandr names (hopefully works) X-Git-Url: https://git.brokenzipper.com/gitweb?a=commitdiff_plain;h=9f561215b52f7e275bbe50faa68cfc9fbc935994;p=chaz%2Ftint2 *add* allow xrandr names (hopefully works) --- diff --git a/configure.ac b/configure.ac index 5365a80..4efd9fc 100644 --- a/configure.ac +++ b/configure.ac @@ -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) diff --git a/src/config.c b/src/config.c index f825d5b..150face 100644 --- a/src/config.c +++ b/src/config.c @@ -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 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); diff --git a/src/server.c b/src/server.c index 5557a01..99c4e51 100644 --- a/src/server.c +++ b/src/server.c @@ -19,6 +19,8 @@ **************************************************************************/ #include +#include + #include #include @@ -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 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; incrtc; ++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; jnoutput; ++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