X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fserver.c;h=511eca5d49bbb51f2614a06ac225a2a0b8db7939;hb=f4fb078b79ed585b0ea3f26092321fbc1844db09;hp=61fa257b99ddd4a73f99044412e504d44403416e;hpb=9cb781048d0a1cf55f0044e2f9f65ac9a5a241e9;p=chaz%2Ftint2 diff --git a/src/server.c b/src/server.c index 61fa257..511eca5 100644 --- a/src/server.c +++ b/src/server.c @@ -68,11 +68,11 @@ void server_init_atoms () server.atom.UTF8_STRING = XInternAtom (server.dsp, "UTF8_STRING", False); server.atom._NET_SUPPORTING_WM_CHECK = XInternAtom (server.dsp, "_NET_SUPPORTING_WM_CHECK", False); server.atom._NET_SUPPORTING_WM_CHECK = XInternAtom (server.dsp, "_NET_WM_NAME", False); - server.atom._WIN_LAYER = XInternAtom (server.dsp, "_WIN_LAYER", False); server.atom._NET_WM_STRUT_PARTIAL = XInternAtom (server.dsp, "_NET_WM_STRUT_PARTIAL", False); server.atom.WM_NAME = XInternAtom(server.dsp, "WM_NAME", False); server.atom.__SWM_VROOT = XInternAtom(server.dsp, "__SWM_VROOT", False); server.atom._MOTIF_WM_HINTS = XInternAtom(server.dsp, "_MOTIF_WM_HINTS", False); + server.atom.WM_HINTS = XInternAtom(server.dsp, "WM_HINTS", False); // systray protocol name_trayer = g_strdup_printf("_NET_SYSTEM_TRAY_S%d", DefaultScreen(server.dsp)); @@ -83,6 +83,11 @@ void server_init_atoms () server.atom._NET_SYSTEM_TRAY_ORIENTATION = XInternAtom(server.dsp, "_NET_SYSTEM_TRAY_ORIENTATION", False); server.atom._XEMBED = XInternAtom(server.dsp, "_XEMBED", False); server.atom._XEMBED_INFO = XInternAtom(server.dsp, "_XEMBED_INFO", False); + + // drag 'n' drop + server.atom.XdndAware = XInternAtom(server.dsp, "XdndAware", False); + server.atom.XdndPosition = XInternAtom(server.dsp, "XdndPosition", False); + server.atom.XdndStatus = XInternAtom(server.dsp, "XdndStatus", False); } @@ -188,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; @@ -196,79 +201,89 @@ 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; + } } -void get_monitors_and_desktops() +int compareMonitorIncluded(const void *monitor1, const void *monitor2) { - int i; + 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; + } +} + +void get_monitors() +{ if (server.monitor) free(server.monitor); server.nb_monitor = 0; server.monitor = 0; - int 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)); + 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); } +} + + +void get_desktops() +{ + int i; // detect number of desktops // wait 15s to leave some time for window manager startup @@ -281,7 +296,6 @@ next: server.nb_desktop = 1; fprintf(stderr, "warning : WM doesn't respect NETWM specs. tint2 default to 1 desktop.\n"); } - fprintf(stderr, "tint2 : nb monitor %d, nb desktop %d\n", server.nb_monitor, server.nb_desktop); }