]> Dogcows Code - chaz/tint2/commitdiff
fixed issue 49 and some systray code (not yet)
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Fri, 27 Feb 2009 22:18:30 +0000 (22:18 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Fri, 27 Feb 2009 22:18:30 +0000 (22:18 +0000)
ChangeLog
src/Makefile
src/config.c
src/panel.c
src/panel.h
src/systray/systraybar.c
src/systray/systraybar.h
src/tint.c
src/tint2
src/util/area.c
src/util/area.h

index 55a5ac9f3d812aa083dd3c5861707007f99a7c5a..54ddae1809c02a4d6886d62fc3a5faa1da9b4516 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2009-02-27
+- fixed issue 49 : better Makefile
+- some systray code (doesn't work)
+- cleanup code
+
+2009-02-25
+- fixed issue 48 : tint2 does't create config file on first start
+
+2009-02-14
+- fxed issue 45 : segfault without clock
+
 2009-02-13
 - improved object oriented layout
 - tint2 looks good for me. if you see bugs, report it.
index 73695a919743848e625e304186b6831f2f944c45..a08c75aab6d0b6e638b0cc160eb9867856d9a8c7 100644 (file)
@@ -23,9 +23,20 @@ endif
 
 $(PROGNAME): $(FILES) $(SYSTRAYOBJ)
        $(CC) $(CFLAGS) -I. -Iutil -Iclock -Itaskbar -Isystray -o $(PROGNAME) $(FILES) $(FLAGS)
+       
+install: install-strip
+
+install-strip:
+       mkdir -p $(BINDIR)
+       mkdir -p $(XDG_CONFIG_DIR)/tint2
+       mkdir -p $(MANDIR)
+       mkdir -p $(MANDIR)/man1
        strip $(PROGNAME)
+       install $(PROGNAME) $(BINDIR)
+       cp -f ../tintrc01 $(XDG_CONFIG_DIR)/tint2/tint2rc
+       cp -f ../doc/man/tint2.1 $(MANDIR)/man1
 
-install:
+install-nostrip:
        mkdir -p $(BINDIR)
        mkdir -p $(XDG_CONFIG_DIR)/tint2
        mkdir -p $(MANDIR)
@@ -41,4 +52,4 @@ uninstall:
 clean:
        rm -f $(PROGNAME)
 
-.PHONY: clean uninstall install
+.PHONY: clean uninstall install install-strip install-nostrip
index 98938e4dae425ffd72382e2e5cc7633203c2a285..8f88fdfd206dc9e4db338a6ef3fc33c1c71d61e2 100644 (file)
@@ -414,16 +414,16 @@ void add_entry (char *key, char *value)
    /* Systray */
    else if (strcmp (key, "systray_padding") == 0) {
       extract_values(value, &value1, &value2, &value3);
-      panel_config->systray.area.paddingxlr = panel_config->systray.area.paddingx = atoi (value1);
-      if (value2) panel_config->systray.area.paddingy = atoi (value2);
-      if (value3) panel_config->systray.area.paddingx = atoi (value3);
-      panel_config->systray.area.visible = 1;
+      systray.area.paddingxlr = systray.area.paddingx = atoi (value1);
+      if (value2) systray.area.paddingy = atoi (value2);
+      if (value3) systray.area.paddingx = atoi (value3);
+      systray.area.visible = 1;
    }
    else if (strcmp (key, "systray_background_id") == 0) {
       int id = atoi (value);
       Area *a = g_slist_nth_data(list_back, id);
-      memcpy(&panel_config->systray.area.pix.back, &a->pix.back, sizeof(Color));
-      memcpy(&panel_config->systray.area.pix.border, &a->pix.border, sizeof(Border));
+      memcpy(&systray.area.pix.back, &a->pix.back, sizeof(Color));
+      memcpy(&systray.area.pix.border, &a->pix.border, sizeof(Border));
    }
 
    /* Mouse actions */
@@ -560,7 +560,7 @@ void config_finish ()
        // alloc panels
    int i;
    if (panel_config->monitor >= 0) {
-       // just one monitor
+       // one monitor
           nb_panel = 1;
           panel1 = calloc(nb_panel, sizeof(Panel));
           memcpy(panel1, panel_config, sizeof(Panel));
@@ -578,16 +578,9 @@ void config_finish ()
        }
 
        // TODO: user can configure layout => ordered objects in panel.area.list
-       // clock and systray before taskbar because resize(clock) can resize others object
+       // clock and systray before taskbar because resize(clock) can resize others object ??
    init_panel();
        init_clock();
-   // force the resize
-       for (i=0 ; i < nb_panel ; i++) {
-          panel1[i].area.resize = 1;
-          if (panel1[i].clock.area.visible)
-                  resize_clock(&panel1[i].clock);
-       }
-
        init_systray();
    init_taskbar();
    visible_object();
index d257cf9a4deb77b7b37e8c6bfd4fdd7aa6a5d2f5..c3c58032a894f3fe1fc1fd6861123665224ea5c1 100644 (file)
@@ -55,12 +55,14 @@ void init_panel()
 {
        int i;
        Panel *p;
+
        for (i=0 ; i < nb_panel ; i++) {
                p = &panel1[i];
 
                p->area.parent = p;
                p->area.panel = p;
                p->area.visible = 1;
+          p->area.resize = 1;
                p->area._resize = resize_panel;
                p->g_taskbar.parent = p;
                p->g_taskbar.panel = p;
@@ -69,8 +71,10 @@ void init_panel()
                // add childs
           if (p->clock.area.visible)
                        p->area.list = g_slist_append(p->area.list, &p->clock);
-          if (p->systray.area.visible)
-                       p->area.list = g_slist_append(p->area.list, &p->systray);
+          if (systray.area.visible && i == 0) {
+               // systray only on first panel
+                       p->area.list = g_slist_append(p->area.list, &systray);
+               }
 
                // detect panel size
                if (p->pourcentx)
@@ -173,10 +177,10 @@ void resize_panel(void *obj)
    else taskbar_on_screen = 1;
 
    taskbar_width = panel->area.width - (2 * panel->area.paddingxlr) - (2 * panel->area.pix.border.width);
-   if (panel->clock.area.visible)
+   if (panel->clock.area.visible && panel->clock.area.width)
       taskbar_width -= (panel->clock.area.width + panel->area.paddingx);
-   if (panel->systray.area.visible)
-       taskbar_width -= (panel->systray.area.width + panel->area.paddingx);
+   if (systray.area.visible && systray.area.width)
+       taskbar_width -= (systray.area.width + panel->area.paddingx);
 
    taskbar_width = (taskbar_width - ((taskbar_on_screen-1) * panel->area.paddingx)) / taskbar_on_screen;
 
index c76d98a322bf055af6d12ba234c2a5173f017e88..67c995cef2ac71f87fa52943f48aa9d8d30fd03d 100644 (file)
@@ -77,12 +77,6 @@ typedef struct {
    // clock
    Clock clock;
 
-   // --------------------------------------------------
-   // systray
-   Systraybar systray;
-
-       // global taskbar parameter
-       //Area g_systraybar;
 } Panel;
 
 
index 0fa8daeb56e42656b33f36d1a59c9de15f33f156..6d72240271a57274965085576217d614856bd16a 100644 (file)
@@ -39,76 +39,58 @@ GSList *icons;
 // selection window
 Window net_sel_win = None;
 
+// freedesktop specification doesn't allow multi systray
+Systraybar systray;
+
 
 void init_systray()
 {
-   Panel *panel;
-   Systraybar *sysbar;
-   int i, run_systray;
-
        cleanup_systray();
 
-       run_systray = 0;
-       for (i=0 ; i < nb_panel ; i++) {
-          if (panel1[i].systray.area.visible) {
-               run_systray = 1;
-               break;
-               }
-       }
-       if (run_systray) {
+       Panel *panel = &panel1[0];
+       systray.area.parent = panel;
+       systray.area.panel = panel;
+       systray.area._resize = resize_systray;
+
+       if (systray.area.visible) {
                if (XGetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN) != None) {
                        fprintf(stderr, "tint2 : another systray is running\n");
-                       run_systray = 0;
+                       systray.area.visible = 0;
                }
        }
 
-       if (run_systray)
-               run_systray = net_init();
-
-       // configure sysbar on all panels
-       for (i=0 ; i < nb_panel ; i++) {
-          panel = &panel1[i];
-          sysbar = &panel->systray;
-
-          if (!run_systray) {
-               sysbar->area.visible = 0;
-               continue;
-               }
-          if (!sysbar->area.visible)
-               continue;
+       if (systray.area.visible)
+               systray.area.visible = net_init();
 
-               sysbar->area.parent = panel;
-               sysbar->area.panel = panel;
+       if (!systray.area.visible)
+               return;
 
-               sysbar->area.posy = panel->area.pix.border.width + panel->area.paddingy;
-               sysbar->area.height = panel->area.height - (2 * sysbar->area.posy);
-               sysbar->area.width = 100;
+       // configure systray
+       // draw only one systray (even with multi panel)
+       systray.area.posy = panel->area.pix.border.width + panel->area.paddingy;
+       systray.area.height = panel->area.height - (2 * systray.area.posy);
+       systray.area.width = 0;
 
-               sysbar->area.posx = panel->area.width - panel->area.paddingxlr - panel->area.pix.border.width - sysbar->area.width;
-          if (panel->clock.area.visible)
-               sysbar->area.posx -= (panel->clock.area.width + panel->area.paddingx);
+       systray.area.posx = panel->area.width - panel->area.paddingxlr - panel->area.pix.border.width - systray.area.width;
+       if (panel->clock.area.visible)
+               systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
 
-               sysbar->area.redraw = 1;
-       }
+       systray.area.redraw = 1;
 }
 
 
 void cleanup_systray()
 {
-   Panel *panel;
-   int i;
-
-       for (i=0 ; i < nb_panel ; i++) {
-               panel = &panel1[i];
-          if (!panel->systray.area.visible) continue;
-
-               free_area(&panel->systray.area);
-       }
+       free_area(&systray.area);
 
        if (net_sel_win != None) {
                XDestroyWindow(server.dsp, net_sel_win);
                net_sel_win = None;
        }
+   if (systray.list_icons) {
+      g_slist_free(systray.list_icons);
+      systray.list_icons = 0;
+   }
 }
 
 
@@ -137,15 +119,29 @@ int net_init()
        ev.data.l[2] = net_sel_win;
        ev.data.l[3] = 0;
        ev.data.l[4] = 0;
-       XSendEvent(server.dsp, server.root_win, False, StructureNotifyMask, &ev);
+       XSendEvent(server.dsp, server.root_win, False, StructureNotifyMask, (XEvent*)&ev);
 
        return 1;
 }
 
 
-int resize_systray (Systraybar *sysbar)
+void resize_systray (void *obj)
 {
-   return 0;
+       Systraybar *sysbar = obj;
+       Panel *panel = sysbar->area.panel;
+       int count = g_slist_length(systray.list_icons);
+
+       if (!count) systray.area.width = 0;
+       else systray.area.width = 30 * count;
+
+       systray.area.posx = panel->area.width - panel->area.paddingxlr - panel->area.pix.border.width - systray.area.width;
+       if (panel->clock.area.visible)
+               systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
+
+       systray.area.redraw = 1;
+
+       // resize other objects on panel
+       printf("resize_systray %d %d\n", systray.area.posx, systray.area.width);
 }
 
 
@@ -207,6 +203,16 @@ gboolean icon_add(Window id)
        traywin = g_new0(TrayWindow, 1);
        traywin->id = id;
 
+       systray.list_icons = g_slist_append(systray.list_icons, traywin);
+       printf("ajout d'un icone %d (%lx)\n", g_slist_length(systray.list_icons), id);
+       systray.area.resize = 1;
+
+       // changed in systray force resize on panel
+       Panel *panel = systray.area.panel;
+       panel->area.resize = 1;
+       panel_refresh = 1;
+       return TRUE;
+
        if (!icon_swallow(traywin)) {
                printf("not icon_swallow\n");
                g_free(traywin);
@@ -224,7 +230,7 @@ gboolean icon_add(Window id)
        icons = g_slist_append(icons, traywin);
 
        // watch for the icon trying to resize itself!
-       XSelectInput(server.dsp, traywin->id, StructureNotifyMask);
+       //XSelectInput(server.dsp, traywin->id, StructureNotifyMask);
 
        // position and size the icon window
        XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size);
@@ -245,6 +251,39 @@ gboolean icon_add(Window id)
 }
 
 
+void icon_remove(TrayWindow *traywin)
+{
+       XErrorHandler old;
+       Window win_id = traywin->id;
+
+       XSelectInput(server.dsp, traywin->id, NoEventMask);
+
+       // remove it from our list
+       systray.list_icons = g_slist_remove(systray.list_icons, traywin);
+       g_free(traywin);
+       printf("suppression d'un icone %d\n", g_slist_length(systray.list_icons));
+       systray.area.resize = 1;
+
+       // changed in systray force resize on panel
+       Panel *panel = systray.area.panel;
+       panel->area.resize = 1;
+       panel_refresh = 1;
+       return;
+
+/*
+       // reparent it to root
+       error = FALSE;
+       old = XSetErrorHandler(window_error_handler);
+       XReparentWindow(server.dsp, win_id, root, 0, 0);
+       XSync(server.dsp, False);
+       XSetErrorHandler(old);
+
+       reposition_icons();
+       fix_geometry();
+       */
+}
+
+
 void net_message(XClientMessageEvent *e)
 {
        unsigned long opcode;
@@ -256,7 +295,6 @@ void net_message(XClientMessageEvent *e)
        case SYSTEM_TRAY_REQUEST_DOCK:
                panel_refresh = 1;
                id = e->data.l[2];
-               printf("add dockapp\n");
                if (id && icon_add(id)) {
                        XSelectInput(server.dsp, id, StructureNotifyMask);
                }
index 5222dd6b3d36b8bb22c5404c089470d8796b4a89..fab1891e801540d54fa278d28bdd9d72426a06f9 100644 (file)
@@ -34,16 +34,16 @@ typedef struct
 
 
 extern Window net_sel_win;
+extern Systraybar systray;
 
 
 void init_systray();
 void cleanup_systray();
 int net_init();
 void net_message(XClientMessageEvent *e);
+void icon_remove(TrayWindow *traywin);
 
-// return 1 if task_width changed
-int resize_systray (Systraybar *sysbar);
-
+void resize_systray (void *obj);
 
 
 #endif
index 13e380fdd1c78c67e629bae633a3c4b196dfad9f..9d830bf7b413d26e00f9fd89441ba205947361d4 100644 (file)
@@ -55,6 +55,7 @@ void init ()
 
    // set global data
    memset(&server, 0, sizeof(Server_global));
+   memset(&systray, 0, sizeof(Systraybar));
 
    server.dsp = XOpenDisplay (NULL);
    if (!server.dsp) {
@@ -86,6 +87,7 @@ void init ()
 void cleanup()
 {
        cleanup_panel();
+       cleanup_systray();
 
    if (time1_font_desc) pango_font_description_free(time1_font_desc);
    if (time2_font_desc) pango_font_description_free(time2_font_desc);
@@ -453,6 +455,7 @@ int main (int argc, char *argv[])
    int x11_fd, i, c;
    struct timeval tv;
    Panel *panel;
+       GSList *it;
 
    c = getopt (argc, argv, "c:");
    init ();
@@ -517,15 +520,12 @@ load_config:
 
                                        case UnmapNotify:
                                        case DestroyNotify:
-//     printf("destroy client\n");
-                                       /*
-                                               GSList *it;
-                                               for (it = icons; it; it = g_slist_next(it)) {
+                                               for (it = systray.list_icons; it; it = g_slist_next(it)) {
                                                        if (((TrayWindow*)it->data)->id == e.xany.window) {
-                                                               icon_remove(it);
+                                                               icon_remove((TrayWindow*)it->data);
                                                                break;
                                                        }
-                                               }*/
+                                               }
                                        break;
 
                                        case ClientMessage:
@@ -557,7 +557,7 @@ load_config:
                                if (panel->temp_pmap) XFreePixmap(server.dsp, panel->temp_pmap);
                                panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
 
-                               refresh(panel);
+                               refresh(&panel->area);
                           XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
                        }
                        XFlush (server.dsp);
index 7a98f5f57a118cf794e527ce0cdd523aa357a0cc..786d990d3c350a2be45d1ffc1edd404ed03f950d 100755 (executable)
Binary files a/src/tint2 and b/src/tint2 differ
index 4cb3b4160c0478b8ed5fdbb61bc2641ae3461128..4b45fbd97fc8e4e4acb09b2009bc8a4534a8cd68 100644 (file)
 #include "server.h"
 #include "panel.h"
 
-
+// 1) resize child
+// 2) resize parent
+// 3) redraw parent
+// 4) redraw child
 void refresh (Area *a)
 {
        if (!a->visible) return;
-   if (a->resize) {
-       // resize can generate a redraw
-          if (a->_resize) {
-                  //printf("resize area posx %d, width %d\n", a->posx, a->width);
-       a->_resize(a);
-               }
-      a->resize = 0;
-       }
+
+       size(a);
 
    if (a->redraw) {
+          a->redraw = 0;
           //printf("draw area posx %d, width %d\n", a->posx, a->width);
       draw(a, 0);
       if (a->use_active)
              draw(a, 1);
-          a->redraw = 0;
        }
 
        // draw current Area
@@ -55,12 +52,29 @@ void refresh (Area *a)
    XCopyArea (server.dsp, *pmap, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
 
    // and then refresh child object
-   GSList *l = a->list;
-   for (; l ; l = l->next)
+       GSList *l;
+   for (l = a->list; l ; l = l->next)
       refresh(l->data);
 }
 
 
+void size (Area *a)
+{
+       GSList *l;
+
+       if (a->resize) {
+      a->resize = 0;
+               for (l = a->list; l ; l = l->next)
+                       size(l->data);
+
+       // resize can generate a redraw
+          if (a->_resize) {
+       a->_resize(a);
+               }
+       }
+}
+
+
 void set_redraw (Area *a)
 {
    a->redraw = 1;
index da32592c39b31cd005f5bf75973983124775a094..cbcf58feba7c31cebdacac25266b681038474eec 100644 (file)
@@ -52,6 +52,7 @@ typedef struct
 typedef struct {
    // absolute coordinate in panel
    int posx, posy;
+   // width and height including border
    int width, height;
    Pmap pix;
    Pmap pix_active;
@@ -85,6 +86,8 @@ typedef struct {
 // draw background and foreground
 void refresh (Area *a);
 
+void size (Area *a);
+
 // set 'redraw' on an area and childs
 void set_redraw (Area *a);
 
This page took 0.039122 seconds and 4 git commands to generate.