]> Dogcows Code - chaz/tint2/blobdiff - src/panel.c
panel_items : fixed segfault (panel without clock, change number desktop)
[chaz/tint2] / src / panel.c
index 21604e4a94c2365c32cce976680565423ec72349..9754de79ee22b9585ed9eff799c2f8e21dec2b29 100644 (file)
@@ -58,6 +58,7 @@ int panel_autohide_show_timeout;
 int panel_autohide_hide_timeout;
 int panel_autohide_height;
 int panel_strut_policy;
+char *panel_items_order;
 
 int  max_tick_urgent;
 
@@ -79,6 +80,7 @@ void default_panel()
        task_dragged = 0;
        panel_horizontal = 1;
        panel_position = CENTER;
+       panel_items_order = strdup("LTBSC");  // Default order : Launcher, Taskbar, Battery, Systray, Clock
        panel_autohide = 0;
        panel_autohide_show_timeout = 0;
        panel_autohide_hide_timeout = 0;
@@ -115,6 +117,7 @@ void cleanup_panel()
                if (p->main_win) XDestroyWindow(server.dsp, p->main_win);
        }
 
+       if (panel_items_order) g_free(panel_items_order);
        if (panel1) free(panel1);
        if (backgrounds)
                g_array_free(backgrounds, 1);
@@ -123,7 +126,7 @@ void cleanup_panel()
 
 void init_panel()
 {
-       int i, j;
+       int i;
        Panel *p;
 
        if (panel_config.monitor > (server.nb_monitor-1)) {
@@ -139,6 +142,7 @@ void init_panel()
 #ifdef ENABLE_BATTERY
        init_battery();
 #endif
+       init_taskbar();
 
        // number of panels (one monitor or 'all' monitors)
        if (panel_config.monitor >= 0)
@@ -169,33 +173,8 @@ void init_panel()
                p->g_taskbar.area.panel = p;
                p->g_task.area.panel = p;
                init_panel_size_and_position(p);
-               // add childs
-               // TODO : should respect the order of 'panel_items' config parameter
-               if (launcher_enabled) {
-                       init_launcher_panel(p);
-                       p->area.list = g_slist_append(p->area.list, &p->launcher);
-               }
-               p->nb_desktop = server.nb_desktop;
-               p->taskbar = calloc(p->nb_desktop, sizeof(Taskbar));
-               for (j=0 ; j < p->nb_desktop ; j++) {
-                       p->area.list = g_slist_append(p->area.list, &p->taskbar[j]);
-               }
-#ifdef ENABLE_BATTERY
-               if (battery_enabled) {
-                       init_battery_panel(p);
-                       p->area.list = g_slist_append(p->area.list, &p->battery);
-               }
-#endif
-               // systray only on first panel
-               if (systray.area.on_screen && i == 0) {
-                       init_systray_panel(p);
-                       p->area.list = g_slist_append(p->area.list, &systray);
-                       refresh_systray = 1;
-               }
-               if (clock_enabled) {
-                       init_clock_panel(p);
-                       p->area.list = g_slist_append(p->area.list, &p->clock);
-               }
+               // add childs according to panel_items
+               set_panel_items(p);
 
                // catch some events
                XSetWindowAttributes att = { .colormap=server.colormap, .background_pixel=0, .border_pixel=0 };
@@ -226,7 +205,6 @@ void init_panel()
        }
 
        panel_refresh = 1;
-       init_taskbar();
        visible_object();
        task_refresh_tasklist();
        active_task();
@@ -393,7 +371,7 @@ int resize_panel(void *obj)
                                posy += panel->taskbar[i].area.height + panel->area.paddingx;
                }
        }
-       return 1;
+       return 0;
 }
 
 
@@ -475,6 +453,45 @@ void update_strut(Panel* p)
 }
 
 
+void set_panel_items(Panel *p)
+{
+       int k, j;
+       
+       if (p->area.list) {
+               g_slist_free(p->area.list);
+               p->area.list = 0;
+       }
+
+       for (k=0 ; k < strlen(panel_items_order) ; k++) {
+               if (panel_items_order[k] == 'L') {
+                       init_launcher_panel(p);
+                       p->area.list = g_slist_append(p->area.list, &p->launcher);
+               }
+               if (panel_items_order[k] == 'T') {
+                       init_taskbar_panel(p);
+                       for (j=0 ; j < p->nb_desktop ; j++)
+                               p->area.list = g_slist_append(p->area.list, &p->taskbar[j]);
+               }
+#ifdef ENABLE_BATTERY
+               if (panel_items_order[k] == 'B') {
+                       init_battery_panel(p);
+                       p->area.list = g_slist_append(p->area.list, &p->battery);
+               }
+#endif
+               if (panel_items_order[k] == 'S') {
+                       // TODO : check systray is only on 1 panel
+                       init_systray_panel(p);
+                       refresh_systray = 1;
+                       p->area.list = g_slist_append(p->area.list, &systray);
+               }
+               if (panel_items_order[k] == 'C') {
+                       init_clock_panel(p);
+                       p->area.list = g_slist_append(p->area.list, &p->clock);
+               }
+       }
+}
+
+
 void set_panel_properties(Panel *p)
 {
        XStoreName (server.dsp, p->main_win, "tint2");
This page took 0.023501 seconds and 4 git commands to generate.