Commit 788cfce1 authored by Andreas.Fink85's avatar Andreas.Fink85

*add* allow xrandr names (hopefully works)


git-svn-id: http://tint2.googlecode.com/svn/trunk@403 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
parent fda9e0e7
......@@ -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)
......
......@@ -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);
......
......@@ -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) {
......
......@@ -78,6 +78,7 @@ typedef struct Monitor
int y;
int width;
int height;
char** names;
} Monitor;
......
......@@ -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) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment