]> Dogcows Code - chaz/tint2/commitdiff
order of panel items : position of each object is update by layering engine (area)
authorThierry Lorthiois <lorthiois@bbsoft.fr>
Sat, 18 Sep 2010 10:41:34 +0000 (10:41 +0000)
committerThierry Lorthiois <lorthiois@bbsoft.fr>
Sat, 18 Sep 2010 10:41:34 +0000 (10:41 +0000)
src/battery/battery.c
src/clock/clock.c
src/launcher/launcher.c
src/panel.c
src/systray/systraybar.c
src/taskbar/taskbar.c
src/tint.c
src/util/area.c
src/util/area.h

index 3ad28996af88b0321656b5a4241e5f4f93dfca94..8fd6aa03deb0fb654b0cd5687d197972218b4fba 100644 (file)
 
 #include "window.h"
 #include "server.h"
-#include "area.h"
 #include "panel.h"
-#include "taskbar.h"
 #include "battery.h"
-#include "clock.h"
 #include "timer.h"
 #include "common.h"
 
@@ -76,8 +73,6 @@ void update_batterys(void* arg)
                if (battery_state.percentage >= percentage_hide) {
                        if (panel1[i].battery.area.on_screen == 1) {
                                panel1[i].battery.area.on_screen = 0;
-                               // force resize on panel
-                               panel1[i].area.resize = 1;
                                panel_refresh = 1;
                        }
                        continue;
@@ -85,8 +80,6 @@ void update_batterys(void* arg)
                else {
                        if (panel1[i].battery.area.on_screen == 0) {
                                panel1[i].battery.area.on_screen = 1;
-                               // force resize on panel
-                               panel1[i].area.resize = 1;
                                panel_refresh = 1;
                        }
                }
@@ -250,8 +243,6 @@ void init_battery_panel(void *p)
        }
        else {
                // panel vertical => fixed width, height, posy and posx
-               battery->area.posy = panel->clock.area.posy + panel->clock.area.height + panel->area.paddingx;
-               battery->area.height = (2 * battery->area.paddingxlr) + (bat_time_height + bat_percentage_height);
                battery->area.posx = panel->area.bg->border.width + panel->area.paddingy;
                battery->area.width = panel->area.width - (2 * panel->area.bg->border.width) - (2 * panel->area.paddingy);
        }
@@ -465,7 +456,11 @@ int resize_battery(void *obj)
                snprintf(buf_bat_time, sizeof(buf_bat_time), "%02d:%02d", battery_state.time.hours, battery_state.time.minutes);
        }
        // vertical panel doen't adjust width
-       if (!panel_horizontal) return ret;
+       if (!panel_horizontal) {
+//             battery->area.posy = panel->clock.area.posy + panel->clock.area.height + panel->area.paddingx;
+//             battery->area.height = (2 * battery->area.paddingxlr) + (bat_time_height + bat_percentage_height);
+               return ret;
+       }
 
        cairo_surface_t *cs;
        cairo_t *c;
@@ -490,16 +485,11 @@ int resize_battery(void *obj)
        if(percentage_width > time_width) new_width = percentage_width;
        else new_width = time_width;
 
-       new_width += (2*battery->area.paddingxlr) + (2*battery->area.bg->border.width);
-
        int old_width = battery->area.width;
-
-       Panel *panel = ((Area*)obj)->panel;
+       
+       new_width += (2*battery->area.paddingxlr) + (2*battery->area.bg->border.width);
        battery->area.width = new_width + 1;
-       battery->area.posx = panel->area.width - battery->area.width - panel->area.paddingxlr - panel->area.bg->border.width;
-       if (panel->clock.area.on_screen)
-               battery->area.posx -= (panel->clock.area.width + panel->area.paddingx);
-
+       
        if (new_width > old_width || new_width < (old_width-6)) {
                // refresh and resize other objects on panel
                // we try to limit the number of refresh
index bd741c2bcd270c19904276d2237384a30b6cc638..783f7e9ff4031f5d269623804d4218b05bdd73dd 100644 (file)
@@ -26,9 +26,7 @@
 
 #include "window.h"
 #include "server.h"
-#include "area.h"
 #include "panel.h"
-#include "taskbar.h"
 #include "clock.h"
 #include "timer.h"
 #include "common.h"
@@ -169,8 +167,8 @@ void init_clock_panel(void *p)
        }
        else {
                // panel vertical => fixed width, height, posy and posx
-               clock->area.posy = panel->area.bg->border.width + panel->area.paddingxlr;
-               clock->area.height = (2 * clock->area.paddingxlr) + (time_height + date_height);
+//             clock->area.posy = panel->area.bg->border.width + panel->area.paddingxlr;
+//             clock->area.height = (2 * clock->area.paddingxlr) + (time_height + date_height);
                clock->area.posx = panel->area.bg->border.width + panel->area.paddingy;
                clock->area.width = panel->area.width - (2 * panel->area.bg->border.width) - (2 * panel->area.paddingy);
        }
@@ -266,7 +264,6 @@ int resize_clock (void *obj)
        else new_width = date_width;
        new_width += (2*clock->area.paddingxlr) + (2*clock->area.bg->border.width);
 
-       Panel *panel = ((Area*)obj)->panel;
        if (new_width > clock->area.width || new_width < (clock->area.width-6)) {
                // resize clock
                // we try to limit the number of resize
@@ -277,8 +274,6 @@ int resize_clock (void *obj)
                ret = 1;
                panel_refresh = 1;
        }
-       clock->area.posx = panel->area.width - clock->area.width - panel->area.paddingxlr - panel->area.bg->border.width;
-
 
        g_object_unref (layout);
        cairo_destroy (c);
index 3a7c4ca11734cd38890b36c62b4aa0bcf42ce28d..50d3829100636e665a6bcf1e833ab4dd4f9e8841 100644 (file)
@@ -223,7 +223,7 @@ int resize_launcher(void *obj)
                        launcher->area.width = (2 * launcher->area.bg->border.width) + (2 * launcher->area.paddingxlr) + (icon_size * icons_per_row) + ((icons_per_row-1) * launcher->area.paddingx);
                }
 
-               launcher->area.posx = panel->area.bg->border.width + panel->area.paddingxlr;
+//             launcher->area.posx = panel->area.bg->border.width + panel->area.paddingxlr;
                launcher->area.posy = panel->area.bg->border.width;
        }
        else {
@@ -238,7 +238,7 @@ int resize_launcher(void *obj)
                }
 
                launcher->area.posx = panel->area.bg->border.width;
-               launcher->area.posy = panel->area.height - panel->area.bg->border.width - panel->area.paddingxlr - launcher->area.height;
+//             launcher->area.posy = panel->area.height - panel->area.bg->border.width - panel->area.paddingxlr - launcher->area.height;
        }
 
        int i, posx, posy;
index 21604e4a94c2365c32cce976680565423ec72349..b3b854789132083985ae27869a60197fb23a3f27 100644 (file)
@@ -393,7 +393,7 @@ int resize_panel(void *obj)
                                posy += panel->taskbar[i].area.height + panel->area.paddingx;
                }
        }
-       return 1;
+       return 0;
 }
 
 
index 9592fdc9e58c2b416a37e2163e39e323f3d10b78..4161a6a0ea79f19020e6afd55214366540aca47e 100644 (file)
@@ -116,6 +116,53 @@ void init_systray_panel(void *p)
 
 void draw_systray(void *obj, cairo_t *c)
 {
+       // TODO : position and size the icon window when position of systray is known
+       Systraybar *sysbar = obj;
+       Panel *panel = sysbar->area.panel;
+       int i, posx, posy, marging=3, icons_per_column=1, icons_per_row=1;
+       int icon_size = 24;
+       int start = panel->area.bg->border.width + panel->area.paddingy + systray.area.bg->border.width + systray.area.paddingy +marging/2;
+       if (panel_horizontal) {
+               posy = start;
+               posx = systray.area.posx + systray.area.bg->border.width + systray.area.paddingxlr;
+       }
+       else {
+               posx = start;
+               posy = systray.area.posy + systray.area.bg->border.width + systray.area.paddingxlr;
+       }
+
+       TrayWindow *traywin;
+       GSList *l;
+       for (i=1, l = systray.list_icons; l ; i++, l = l->next) {
+               traywin = (TrayWindow*)l->data;
+               if (traywin->hide) continue;
+
+               traywin->y = posy;
+               traywin->x = posx;
+               traywin->width = icon_size;
+               traywin->height = icon_size;
+               if (panel_horizontal) {
+                       if (i % icons_per_column)
+                               posy += icon_size + sysbar->area.paddingx;
+                       else {
+                               posy = start;
+                               posx += (icon_size + systray.area.paddingx);
+                       }
+               }
+               else {
+                       if (i % icons_per_row)
+                               posx += icon_size + systray.area.paddingx;
+                       else {
+                               posx = start;
+                               posy += (icon_size + systray.area.paddingx);
+                       }
+               }
+
+               // position and size the icon window
+               XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size);
+               XResizeWindow(server.dsp, traywin->tray_id, icon_size, icon_size);
+       }
+
        if (server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
                if (render_background) XFreePixmap(server.dsp, render_background);
                render_background = XCreatePixmap(server.dsp, server.root_win, systray.area.width, systray.area.height, server.depth);
@@ -129,8 +176,6 @@ void draw_systray(void *obj, cairo_t *c)
 int resize_systray(void *obj)
 {
        Systraybar *sysbar = obj;
-       Panel *panel = sysbar->area.panel;
-       TrayWindow *traywin;
        GSList *l;
        int count, icon_size;
        int icons_per_column=1, icons_per_row=1, marging=0;
@@ -159,14 +204,6 @@ int resize_systray(void *obj)
                        icons_per_row = count / icons_per_column + (count%icons_per_column != 0);
                        systray.area.width = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_row) + ((icons_per_row-1) * systray.area.paddingx);
                }
-
-               systray.area.posx = panel->area.width - panel->area.bg->border.width - panel->area.paddingxlr - systray.area.width;
-               if (panel->clock.area.on_screen)
-                       systray.area.posx -= (panel->clock.area.width + panel->area.paddingx);
-#ifdef ENABLE_BATTERY
-               if (panel->battery.area.on_screen)
-                       systray.area.posx -= (panel->battery.area.width + panel->area.paddingx);
-#endif
        }
        else {
                if (!count) systray.area.height = 0;
@@ -178,55 +215,6 @@ int resize_systray(void *obj)
                        icons_per_column = count / icons_per_row+ (count%icons_per_row != 0);
                        systray.area.height = (2 * systray.area.bg->border.width) + (2 * systray.area.paddingxlr) + (icon_size * icons_per_column) + ((icons_per_column-1) * systray.area.paddingx);
                }
-
-               systray.area.posy = panel->area.bg->border.width + panel->area.paddingxlr;
-               if (panel->clock.area.on_screen)
-                       systray.area.posy += (panel->clock.area.height + panel->area.paddingx);
-#ifdef ENABLE_BATTERY
-               if (panel->battery.area.on_screen)
-                       systray.area.posy += (panel->battery.area.height + panel->area.paddingx);
-#endif
-       }
-
-       int i, posx, posy;
-       int start = panel->area.bg->border.width + panel->area.paddingy + systray.area.bg->border.width + systray.area.paddingy +marging/2;
-       if (panel_horizontal) {
-               posy = start;
-               posx = systray.area.posx + systray.area.bg->border.width + systray.area.paddingxlr;
-       }
-       else {
-               posx = start;
-               posy = systray.area.posy + systray.area.bg->border.width + systray.area.paddingxlr;
-       }
-
-       for (i=1, l = systray.list_icons; l ; i++, l = l->next) {
-               traywin = (TrayWindow*)l->data;
-               if (traywin->hide) continue;
-
-               traywin->y = posy;
-               traywin->x = posx;
-               traywin->width = icon_size;
-               traywin->height = icon_size;
-               if (panel_horizontal) {
-                       if (i % icons_per_column)
-                               posy += icon_size + sysbar->area.paddingx;
-                       else {
-                               posy = start;
-                               posx += (icon_size + systray.area.paddingx);
-                       }
-               }
-               else {
-                       if (i % icons_per_row)
-                               posx += icon_size + systray.area.paddingx;
-                       else {
-                               posx = start;
-                               posy += (icon_size + systray.area.paddingx);
-                       }
-               }
-
-               // position and size the icon window
-               XMoveResizeWindow(server.dsp, traywin->id, traywin->x, traywin->y, icon_size, icon_size);
-               XResizeWindow(server.dsp, traywin->tray_id, icon_size, icon_size);
        }
        return 1;
 }
index bb351fe1792096f87c5b92d74018e8aed52706f9..02cfbb0d076279c136ac83bfde13ca86eae4bb78 100644 (file)
@@ -266,7 +266,7 @@ int resize_taskbar(void *obj)
 
        if (panel_horizontal) {
                int  pixel_width, modulo_width=0;
-               int  x, taskbar_width;
+               int  taskbar_width;
 
                // new task width for 'desktop'
                task_count = g_slist_length(taskbar->area.list);
@@ -287,27 +287,24 @@ int resize_taskbar(void *obj)
                taskbar->text_width = pixel_width - panel->g_task.text_posx - panel->g_task.area.bg->border.width - panel->g_task.area.paddingx;
 
                // change pos_x and width for all tasks
-               x = taskbar->area.posx + border_width + taskbar->area.paddingxlr;
                for (l = taskbar->area.list; l ; l = l->next) {
                        tsk = l->data;
                        if (!tsk->area.on_screen) continue;
-                       tsk->area.posx = x;
                        set_task_redraw(tsk);  // always redraw task, because the background could have changed (taskbar_active_id)
                        tsk->area.width = pixel_width;
-                       long value[] = { panel->posx+x, panel->posy, pixel_width, panel->area.height };
-                       XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4);
+// TODO : move later (when posx is known)
+//                     long value[] = { panel->posx+x, panel->posy, pixel_width, panel->area.height };
+//                     XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4);
 
                        if (modulo_width) {
                                tsk->area.width++;
                                modulo_width--;
                        }
-
-                       x += tsk->area.width + panel->g_taskbar.area.paddingx;
                }
        }
        else {
                int  pixel_height, modulo_height=0;
-               int  y, taskbar_height;
+               int  taskbar_height;
 
                // new task width for 'desktop'
                task_count = g_slist_length(taskbar->area.list);
@@ -328,23 +325,21 @@ int resize_taskbar(void *obj)
                taskbar->text_width = taskbar->area.width - (2 * panel->g_taskbar.area.paddingy) - panel->g_task.text_posx - panel->g_task.area.bg->border.width - panel->g_task.area.paddingx;
 
                // change pos_y and height for all tasks
-               y = taskbar->area.posy + border_width + taskbar->area.paddingxlr;
                for (l = taskbar->area.list; l ; l = l->next) {
                        tsk = l->data;
                        if (!tsk->area.on_screen) continue;
-                       tsk->area.posy = y;
                        set_task_redraw(tsk);  // always redraw task, because the background could have changed (taskbar_active_id)
                        tsk->area.height = pixel_height;
-                       long value[] = { panel->posx, panel->posy+y, panel->area.width, pixel_height };
-                       XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4);
+// TODO : move later (when posy is known)
+//                     long value[] = { panel->posx, panel->posy+y, panel->area.width, pixel_height };
+//                     XChangeProperty (server.dsp, tsk->win, server.atom._NET_WM_ICON_GEOMETRY, XA_CARDINAL, 32, PropModeReplace, (unsigned char*)value, 4);
 
                        if (modulo_height) {
                                tsk->area.height++;
                                modulo_height--;
                        }
-
-                       y += tsk->area.height + panel->g_taskbar.area.paddingx;
                }
        }
        return 0;
 }
+
index 0352aa891d9064545a087347c94635943eab7aee..fd89b8c468a528467ec22347a4913fee61c19894 100644 (file)
@@ -186,9 +186,7 @@ void get_snapshot(const char *path)
                panel->area.width = server.monitor[0].width;
 
        panel->temp_pmap = XCreatePixmap(server.dsp, server.root_win, panel->area.width, panel->area.height, server.depth);
-       size_by_content(&panel->area);
-       size_by_layout(&panel->area);
-       refresh(&panel->area);
+       rendering(panel);
 
        Imlib_Image img = NULL;
        imlib_context_set_drawable(panel->temp_pmap);
@@ -777,9 +775,7 @@ start:
                                else {
                                        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);
-                                       size_by_content(&panel->area);
-                                       size_by_layout(&panel->area);
-                                       refresh(&panel->area);
+                                       rendering(panel);
                                        XCopyArea(server.dsp, panel->temp_pmap, panel->main_win, server.gc, 0, 0, panel->area.width, panel->area.height, 0, 0);
                                }
                        }
index 7455561b34e90e5f0862ac476ce794953531ab97..ce122a2178d5f31de655c074da6aa6f380d1d0ea 100644 (file)
  *
  ************************************************************/
 
+void rendering(void *obj)
+{
+       Panel *panel = (Panel*)obj;
+       
+       size_by_content(&panel->area);
+       size_by_layout(&panel->area, 0, 0);
+       
+       refresh(&panel->area);
+}
+
 
 void size_by_content (Area *a)
 {
@@ -94,16 +104,16 @@ void size_by_content (Area *a)
 
                if (a->_resize) {
                        if (a->_resize(a)) {
-                               // 'size' changed then 'resize = 1' on the parent
+                               // 'size' changed => 'resize = 1' on the parent and redraw object
                                ((Area*)a->parent)->resize = 1;
+                               a->redraw = 1;
                        }
-                       a->redraw = 1;
                }
        }
 }
 
 
-void size_by_layout (Area *a)
+void size_by_layout (Area *a, int pos, int level)
 {
        // don't resize hiden objects
        if (!a->on_screen) return;
@@ -125,8 +135,24 @@ void size_by_layout (Area *a)
                }
        }
 
-       for (l = a->list; l ; l = l->next)
-               size_by_layout(l->data);        
+       // update position of childs
+       pos += a->paddingxlr + a->bg->border.width;
+       int i=0;
+       for (l = a->list; l ; l = l->next) {
+               Area *child = ((Area*)l->data);
+               i++;
+               
+               if (pos != child->posx) {
+                       // pos changed => redraw
+                       child->posx = pos;
+                       child->redraw = 1;
+               }
+               //printf("level %d, object %d, pos %d\n", level, i, pos);
+               
+               size_by_layout(child, pos, level+1);
+               
+               pos += child->width + a->paddingx;
+       }
 }
 
 
index 77f957e2988ac914abe4aac35710a85d92eef761..b016674ed4f3c97f602addd00252e5a42e42b506 100644 (file)
@@ -89,9 +89,9 @@ typedef struct {
 } Area;
 
 
-
+void rendering(void *panel);
 void size_by_content (Area *a);
-void size_by_layout (Area *a);
+void size_by_layout (Area *a, int pos, int level);
 // draw background and foreground
 void refresh (Area *a);
  
This page took 0.03853 seconds and 4 git commands to generate.