all repos — tint2 @ c763cf71721e11d5c55e747c96dfbc45b9d4737f

fork of the tint2 desktop panel for my custom setup - only minimized windows across all desktops for the taskbar

fixed config reload SIGUSR1. added systray = 1 parameter to enable systray

git-svn-id: http://tint2.googlecode.com/svn/trunk@242 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
lorthiois@bbsoft.fr lorthiois@bbsoft.fr@121b4492-b84c-0410-8b4c-0d4edfb3f3cc
commit

c763cf71721e11d5c55e747c96dfbc45b9d4737f

parent

51b9ce356a7c534b635fe70c7c64fb700be38760

M src/battery/battery.csrc/battery/battery.c

@@ -32,8 +32,8 @@ #include "taskbar.h"

#include "battery.h" #include "clock.h" -PangoFontDescription *bat1_font_desc; -PangoFontDescription *bat2_font_desc; +PangoFontDescription *bat1_font_desc=0; +PangoFontDescription *bat2_font_desc=0; struct batstate battery_state; int battery_enabled;

@@ -41,8 +41,11 @@ static char buf_bat_percentage[10];

static char buf_bat_time[20]; int8_t battery_low_status; -char *battery_low_cmd; -char *path_energy_now, *path_energy_full, *path_current_now, *path_status; +char *battery_low_cmd=0; +char *path_energy_now=0; +char *path_energy_full=0; +char *path_current_now=0; +char *path_status=0; void init_battery()

@@ -55,7 +58,6 @@ char *battery_dir = 0;

if (!battery_enabled) return; - path_energy_now = path_energy_full = path_current_now = path_status = 0; directory = g_dir_open("/sys/class/power_supply", 0, &error); if (error) g_error_free(error);

@@ -75,7 +77,7 @@ }

if (directory) g_dir_close(directory); if (!battery_dir) { - battery_enabled = 0; + cleanup_battery(); fprintf(stderr, "ERROR: battery applet can't found power_supply\n"); return; }

@@ -107,13 +109,8 @@ fp2 = fopen(path_energy_full, "r");

fp3 = fopen(path_current_now, "r"); fp4 = fopen(path_status, "r"); if (fp1 == NULL || fp2 == NULL || fp3 == NULL || fp4 == NULL) { - battery_enabled = 0; + cleanup_battery(); fprintf(stderr, "ERROR: battery applet can't open energy_now\n"); - g_free(path_energy_now); - g_free(path_energy_full); - g_free(path_current_now); - g_free(path_status); - path_energy_now = path_energy_full = path_current_now = path_status = 0; } fclose(fp1); fclose(fp2);

@@ -123,6 +120,29 @@ }

g_free(path1); g_free(battery_dir); +} + + +void cleanup_battery() +{ + battery_enabled = 0; + if (bat1_font_desc) + pango_font_description_free(bat1_font_desc); + if (bat2_font_desc) + pango_font_description_free(bat2_font_desc); + if (path_energy_now) + g_free(path_energy_now); + if (path_energy_full) + g_free(path_energy_full); + if (path_current_now) + g_free(path_current_now); + if (path_status) + g_free(path_status); + if (battery_low_cmd) + g_free(battery_low_cmd); + + battery_low_cmd = path_energy_now = path_energy_full = path_current_now = path_status = 0; + bat1_font_desc = bat2_font_desc = 0; }
M src/battery/battery.hsrc/battery/battery.h

@@ -62,6 +62,7 @@ void update_battery();

void init_battery(); void init_battery_panel(void *panel); +void cleanup_battery(); void draw_battery(void *obj, cairo_t *c, int active);
M src/clock/clock.csrc/clock/clock.c

@@ -32,16 +32,17 @@ #include "taskbar.h"

#include "clock.h" -char *time1_format; -char *time2_format; -char *clock_lclick_command; -char *clock_rclick_command; +char *time1_format=0; +char *time2_format=0; +char *clock_lclick_command=0; +char *clock_rclick_command=0; struct timeval time_clock; int time_precision; -PangoFontDescription *time1_font_desc; -PangoFontDescription *time2_font_desc; +PangoFontDescription *time1_font_desc=0; +PangoFontDescription *time2_font_desc=0; static char buf_time[40]; static char buf_date[40]; +int clock_enabled; void init_precision()

@@ -78,6 +79,7 @@ clock->area._draw_foreground = draw_clock;

clock->area._resize = resize_clock; clock->area.resize = 1; clock->area.redraw = 1; + clock->area.on_screen = 1; strftime(buf_time, sizeof(buf_time), time1_format, localtime(&time_clock.tv_sec)); get_text_size(time1_font_desc, &time_height_ink, &time_height, panel->area.height, buf_time, strlen(buf_time));

@@ -107,6 +109,27 @@

clock->time1_posy -= ((date_height_ink + 2) / 2); clock->time2_posy = clock->time1_posy + time_height + 2 - (time_height - time_height_ink)/2 - (date_height - date_height_ink)/2; } +} + + +void cleanup_clock() +{ + clock_enabled = 0; + if (time1_font_desc) + pango_font_description_free(time1_font_desc); + if (time2_font_desc) + pango_font_description_free(time2_font_desc); + if (time1_format) + g_free(time1_format); + if (time2_format) + g_free(time2_format); + if (clock_lclick_command) + g_free(clock_lclick_command); + if (clock_rclick_command) + g_free(clock_rclick_command); + time1_font_desc = time2_font_desc = 0; + time1_format = time2_format = 0; + clock_lclick_command = clock_rclick_command = 0; }
M src/clock/clock.hsrc/clock/clock.h

@@ -32,12 +32,14 @@ extern PangoFontDescription *time1_font_desc;

extern PangoFontDescription *time2_font_desc; extern char *clock_lclick_command; extern char *clock_rclick_command; +extern int clock_enabled; // initialize clock : y position, precision, ... void init_clock(); void init_clock_panel(void *panel); void init_precision(); +void cleanup_clock(); void draw_clock (void *obj, cairo_t *c, int active);
M src/config.csrc/config.c

@@ -77,6 +77,13 @@ {

// append full transparency background list_back = g_slist_append(0, calloc(1, sizeof(Area))); + // tint2 could reload config, so we cleanup objects + cleanup_systray(); + cleanup_battery(); + cleanup_clock(); + cleanup_tooltip(); + + // panel's default value memset(&panel_config, 0, sizeof(Panel)); panel_config.g_task.alpha = 100; panel_config.g_task.alpha_active = 100;

@@ -199,6 +206,11 @@ else {

panel_config.monitor = atoi (value); if (panel_config.monitor > 0) panel_config.monitor -= 1; } + if (panel_config.monitor > (server.nb_monitor-1)) { + // server.nb_monitor minimum value is 1 (see get_monitors()) + fprintf(stderr, "warning : monitor not found. tint2 default to all monitors.\n"); + panel_config.monitor = 0; + } } else if (strcmp (key, "panel_size") == 0) { extract_values(value, &value1, &value2, &value3);

@@ -289,9 +301,8 @@ #endif

} else if (strcmp (key, "battery_low_cmd") == 0) { #ifdef ENABLE_BATTERY - if (battery_low_cmd) g_free(battery_low_cmd); - if (strlen(value) > 0) battery_low_cmd = strdup (value); - else battery_low_cmd = 0; + if (strlen(value) > 0) + battery_low_cmd = strdup (value); #endif } else if (strcmp (key, "bat1_font") == 0) {

@@ -335,20 +346,14 @@ }

/* Clock */ else if (strcmp (key, "time1_format") == 0) { - if (time1_format) g_free(time1_format); if (strlen(value) > 0) { time1_format = strdup (value); - panel_config.clock.area.on_screen = 1; - } - else { - time1_format = 0; - panel_config.clock.area.on_screen = 0; + clock_enabled = 1; } } else if (strcmp (key, "time2_format") == 0) { - if (time2_format) g_free(time2_format); - if (strlen(value) > 0) time2_format = strdup (value); - else time2_format = 0; + if (strlen(value) > 0) + time2_format = strdup (value); } else if (strcmp (key, "time1_font") == 0) { if (save_file_config) old_time1_font = strdup (value);

@@ -379,14 +384,12 @@ memcpy(&panel_config.clock.area.pix.back, &a->pix.back, sizeof(Color));

memcpy(&panel_config.clock.area.pix.border, &a->pix.border, sizeof(Border)); } else if (strcmp(key, "clock_lclick_command") == 0) { - if (clock_lclick_command) g_free(clock_lclick_command); - if (strlen(value) > 0) clock_lclick_command = strdup(value); - else clock_lclick_command = 0; + if (strlen(value) > 0) + clock_lclick_command = strdup(value); } else if (strcmp(key, "clock_rclick_command") == 0) { - if (clock_rclick_command) g_free(clock_rclick_command); - if (strlen(value) > 0) clock_rclick_command = strdup(value); - else clock_rclick_command = 0; + if (strlen(value) > 0) + clock_rclick_command = strdup(value); } /* Taskbar */

@@ -482,12 +485,15 @@ memcpy(&panel_config.g_task.area.pix_active.border, &a->pix.border, sizeof(Border));

} /* Systray */ + else if (strcmp (key, "systray") == 0) { + if(atoi(value) == 1) + systray_enabled = 1; + } else if (strcmp (key, "systray_padding") == 0) { extract_values(value, &value1, &value2, &value3); systray.area.paddingxlr = systray.area.paddingx = atoi (value1); if (value2) systray.area.paddingy = atoi (value2); if (value3) systray.area.paddingx = atoi (value3); - systray.area.on_screen = 1; } else if (strcmp (key, "systray_background_id") == 0) { int id = atoi (value);

@@ -635,29 +641,6 @@

if (value1) free (value1); if (value2) free (value2); if (value3) free (value3); -} - - -void config_finish () -{ - if (panel_config.monitor > (server.nb_monitor-1)) { - // server.nb_monitor minimum value is 1 (see get_monitors()) - // and panel_config->monitor is higher - fprintf(stderr, "warning : monitor not found. tint2 default to all monitors.\n"); - panel_config.monitor = 0; - } - - // TODO: user can configure layout => ordered objects in panel.area.list - // clock and systray before taskbar because resize(clock) can resize others object ?? - init_tooltip(); - init_clock(); -#ifdef ENABLE_BATTERY - init_battery(); -#endif - init_systray(); - init_panel(); - - cleanup_config(); }
M src/config.hsrc/config.h

@@ -16,7 +16,6 @@ void init_config();

void cleanup_config(); int config_read_file (const char *path); int config_read (); -void config_finish (); void save_config (); #endif
M src/panel.csrc/panel.c

@@ -71,6 +71,13 @@ {

int i, old_nb_panel; Panel *new_panel, *p; + init_tooltip(); + init_systray(); + init_clock(); +#ifdef ENABLE_BATTERY + init_battery(); +#endif + cleanup_taskbar(); for (i=0 ; i < nb_panel ; i++) { free_area(&panel1[i].area);

@@ -123,7 +130,7 @@ p->g_task.area.panel = p;

init_panel_size_and_position(p); // add childs - if (p->clock.area.on_screen) { + if (clock_enabled) { init_clock_panel(p); p->area.list = g_slist_append(p->area.list, &p->clock); }
M src/systray/systraybar.csrc/systray/systraybar.c

@@ -43,20 +43,21 @@

// freedesktop specification doesn't allow multi systray Systraybar systray; int refresh_systray; +int systray_enabled; void init_systray() { - if (systray.area.on_screen) - systray.area.on_screen = init_net(); + start_net(); - if (!systray.area.on_screen) + if (!systray_enabled) return; systray.area._draw_foreground = draw_systray; systray.area._resize = resize_systray; systray.area.resize = 1; systray.area.redraw = 1; + systray.area.on_screen = 1; refresh_systray = 0; }

@@ -80,17 +81,9 @@

void cleanup_systray() { - if (systray.list_icons) { - // remove_icon change systray.list_icons - while(systray.list_icons) - remove_icon((TrayWindow*)systray.list_icons->data); - - g_slist_free(systray.list_icons); - systray.list_icons = 0; - } - + systray_enabled = 0; + systray.area.on_screen = 0; free_area(&systray.area); - cleanup_net(); }

@@ -177,8 +170,18 @@

// *********************************************** // systray protocol -int init_net() +void start_net() { + if (net_sel_win) { + // protocol already started + if (!systray_enabled) + stop_net(); + return; + } + else + if (!systray_enabled) + return; + Window win = XGetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN); // freedesktop systray specification

@@ -201,7 +204,7 @@ pid += prop[0];

fprintf(stderr, " pid=%d", pid); } fprintf(stderr, "\n"); - return 0; + return; } // init systray protocol

@@ -214,10 +217,12 @@ XChangeProperty(server.dsp, net_sel_win, server.atom._NET_SYSTEM_TRAY_ORIENTATION, XA_CARDINAL, 32, PropModeReplace, (unsigned char *) &orient, 1);

XSetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN, net_sel_win, CurrentTime); if (XGetSelectionOwner(server.dsp, server.atom._NET_SYSTEM_TRAY_SCREEN) != net_sel_win) { + stop_net(); fprintf(stderr, "tint2 : can't get systray manager\n"); - return 0; + return; } + //fprintf(stderr, "tint2 : systray started\n"); XClientMessageEvent ev; ev.type = ClientMessage; ev.window = server.root_win;

@@ -229,12 +234,21 @@ 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, (XEvent*)&ev); - return 1; } -void cleanup_net() +void stop_net() { + //fprintf(stderr, "tint2 : systray stopped\n"); + if (systray.list_icons) { + // remove_icon change systray.list_icons + while(systray.list_icons) + remove_icon((TrayWindow*)systray.list_icons->data); + + g_slist_free(systray.list_icons); + systray.list_icons = 0; + } + if (net_sel_win != None) { XDestroyWindow(server.dsp, net_sel_win); net_sel_win = None;
M src/systray/systraybar.hsrc/systray/systraybar.h

@@ -38,10 +38,11 @@ int hide;

} TrayWindow; +// net_sel_win != None when protocol started extern Window net_sel_win; extern Systraybar systray; extern int refresh_systray; - +extern int systray_enabled; void init_systray(); void init_systray_panel(void *p);

@@ -52,8 +53,8 @@

// systray protocol // many tray icon doesn't manage stop/restart of the systray manager -int init_net(); -void cleanup_net(); +void start_net(); +void stop_net(); void net_message(XClientMessageEvent *e); gboolean add_icon(Window id);
M src/tint.csrc/tint.c

@@ -125,35 +125,18 @@

void cleanup() { cleanup_systray(); + stop_net(); cleanup_panel(); + cleanup_tooltip(); + cleanup_clock(); +#ifdef ENABLE_BATTERY + cleanup_battery(); +#endif if (default_icon) { imlib_context_set_image(default_icon); imlib_free_image(); } - if (g_tooltip.window) { - XDestroyWindow(server.dsp, g_tooltip.window); - g_tooltip.window = 0; - } - if (g_tooltip.font_desc) { - pango_font_description_free(g_tooltip.font_desc); - g_tooltip.font_desc = 0; - } - if (time1_font_desc) pango_font_description_free(time1_font_desc); - if (time2_font_desc) pango_font_description_free(time2_font_desc); - if (time1_format) g_free(time1_format); - if (time2_format) g_free(time2_format); -#ifdef ENABLE_BATTERY - if (bat1_font_desc) pango_font_description_free(bat1_font_desc); - if (bat2_font_desc) pango_font_description_free(bat2_font_desc); - if (battery_low_cmd) g_free(battery_low_cmd); - if (path_energy_now) g_free(path_energy_now); - if (path_energy_full) g_free(path_energy_full); - if (path_current_now) g_free(path_current_now); - if (path_status) g_free(path_status); -#endif - if (clock_lclick_command) g_free(clock_lclick_command); - if (clock_rclick_command) g_free(clock_rclick_command); if (config_path) g_free(config_path); if (thumbnail_path) g_free(thumbnail_path);

@@ -730,7 +713,8 @@ fprintf(stderr, "usage: tint2 [-c] <config_file>\n");

cleanup(); exit(1); } - config_finish(); + init_panel(); + cleanup_config(); if (thumbnail_path) { // usage: tint2 -j <file> for internal use printf("file %s\n", thumbnail_path);
M src/tooltip/tooltip.csrc/tooltip/tooltip.c

@@ -59,6 +59,25 @@ g_tooltip.window = XCreateWindow(server.dsp, server.root_win, 0, 0, 100, 20, 0, server.depth, InputOutput, CopyFromParent, CWOverrideRedirect|CWEventMask, &attr);

} +void cleanup_tooltip() +{ + tooltip_hide(); + g_tooltip.enabled = False; + if (g_tooltip.task) { + alarm(0); + g_tooltip.task = 0; + } + if (g_tooltip.window) { + XDestroyWindow(server.dsp, g_tooltip.window); + g_tooltip.window = 0; + } + if (g_tooltip.font_desc) { + pango_font_description_free(g_tooltip.font_desc); + g_tooltip.font_desc = 0; + } +} + + void tooltip_sighandler(int sig) { if (g_tooltip.current_state == TOOLTIP_ABOUT_TO_SHOW)
M src/tooltip/tooltip.hsrc/tooltip/tooltip.h

@@ -47,6 +47,7 @@ extern Tooltip g_tooltip;

void init_tooltip(); +void cleanup_tooltip(); void tooltip_sighandler(int sig); void tooltip_trigger_show(Task* task, int x, int y); void tooltip_show();