]> Dogcows Code - chaz/tint2/blobdiff - src/server.c
fixed issue 13, removed Window magager s menu for stability reason
[chaz/tint2] / src / server.c
index 2c34415d5660cc6223889f3f888cd45b9ddca56b..8e90d24b8da179751adc2ec29aa701a1e4fcb242 100644 (file)
@@ -1,10 +1,10 @@
 /**************************************************************************
 *
 * Tint2 panel
-* 
+*
 * Copyright (C) 2007 Pål Staurland (staura@gmail.com)
 * Modified (C) 2008 thierry lorthiois (lorthiois@bbsoft.fr)
-* 
+*
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License version 2
 * as published by the Free Software Foundation.
@@ -67,6 +67,7 @@ void server_init_atoms ()
    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);
 }
 
 
@@ -134,84 +135,75 @@ void *server_get_property (Window win, Atom at, Atom type, int *num_results)
 }
 
 
-Pixmap server_create_pixmap (int width, int height)
+int compareMonitor(const void *monitor1, const void *monitor2)
 {
-   return XCreatePixmap (server.dsp, server.root_win, width, height, server.depth);
-}
-
+   Monitor *m1 = (Monitor*)monitor1;
+   Monitor *m2 = (Monitor*)monitor2;
 
-Pixmap get_root_pixmap ()
-{
-   Pixmap ret;
-       Window root = RootWindow(server.dsp, server.screen);
-
-   ret = None;    
-   int  act_format, c = 2 ;
-   u_long  nitems ;
-   u_long  bytes_after ;
-   u_char *prop ;
-   Atom dummy_id;
-
-   do {
-      if (XGetWindowProperty(server.dsp, root, server.atom._XROOTPMAP_ID, 0, 1,
-                False, XA_PIXMAP, &dummy_id, &act_format,
-                &nitems, &bytes_after, &prop) == Success) {
-          if (prop) {
-              ret = *((Pixmap *)prop);
-              XFree(prop);
-              break;
-          }
+   if (m1->x < m2->x) {
+      return -1;
+   }
+   else
+      if (m1->x > m2->x) {
+         return 1;
       }
-   } while (--c > 0);
-
-   return ret;
+      else
+         if (m1->width < m2->width) {
+            return 1;
+         }
+         else
+            if (m1->width > m2->width) {
+               return -1;
+            }
+            else {
+               return 0;
+            }
 }
 
 
-/*
-Pixmap get_root_pixmap ()
-{
-   // conky capture correctement le fond d'écran en xlib !!
-   Pixmap root_pixmap;
-   unsigned long *res;
-
-       server.root_win = window_get_root();   
-
-   res = server_get_property (server.root_win, server.atom._XROOTPMAP_ID, XA_PIXMAP, 0);
-   if (res) {
-      root_pixmap = *((Drawable*) res);
-      XFree(res);
-      return root_pixmap;
-   }
-   else {
-      printf("get_root_pixmap incorrect\n");
-      // try _XSETROOT_ID
-   }
-   return 0;
-}  
-*/
-
-
 void get_monitors()
 {
    if (server.monitor) free(server.monitor);
    server.nb_monitor = 0;
    server.monitor = 0;
-   
+
+   int nb_monitor;
    if (XineramaIsActive(server.dsp)) {
-      XineramaScreenInfo *info = XineramaQueryScreens(server.dsp, &server.nb_monitor);
+      XineramaScreenInfo *info = XineramaQueryScreens(server.dsp, &nb_monitor);
 
       if (info) {
-         int i;
-         
-         server.monitor = calloc(server.nb_monitor, sizeof(Monitor));
-         for (i = 0; i < server.nb_monitor; 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;
-         }  
+         int i = 0, nb=0, j;
+
+         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;
+                                               }
+                                       }
+                               }
+
+               //fprintf(stderr, "monitor %d added\n", i);
+            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);
       }
    }
 
This page took 0.022935 seconds and 4 git commands to generate.