#include "clock.h"
#include "timer.h"
-PangoFontDescription *bat1_font_desc=0;
-PangoFontDescription *bat2_font_desc=0;
+PangoFontDescription *bat1_font_desc;
+PangoFontDescription *bat2_font_desc;
struct batstate battery_state;
int battery_enabled;
int percentage_hide;
-static timeout* battery_timeout=0;
+static timeout* battery_timeout;
static char buf_bat_percentage[10];
static char buf_bat_time[20];
int8_t battery_low_status;
unsigned char battery_low_cmd_send;
-char *battery_low_cmd=0;
-char *path_energy_now=0;
-char *path_energy_full=0;
-char *path_current_now=0;
-char *path_status=0;
+char *battery_low_cmd;
+char *path_energy_now;
+char *path_energy_full;
+char *path_current_now;
+char *path_status;
void update_batterys(void* arg)
{
}
}
+void default_battery()
+{
+ battery_enabled = 0;
+ percentage_hide = 101;
+ battery_low_cmd_send = 0;
+ battery_timeout = 0;
+ bat1_font_desc = 0;
+ bat2_font_desc = 0;
+ battery_low_cmd = 0;
+ path_energy_now = 0;
+ path_energy_full = 0;
+ path_current_now = 0;
+ path_status = 0;
+}
+
+void cleanup_battery()
+{
+ 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);
+}
+
void init_battery()
{
}
-void cleanup_battery()
-{
- battery_enabled = 0;
- percentage_hide = 101;
- battery_low_cmd_send = 0;
-
- if (bat1_font_desc) {
- pango_font_description_free(bat1_font_desc);
- bat1_font_desc = 0;
- }
- if (bat2_font_desc) {
- pango_font_description_free(bat2_font_desc);
- bat2_font_desc = 0;
- }
- if (path_energy_now) {
- g_free(path_energy_now);
- path_energy_now = 0;
- }
- if (path_energy_full) {
- g_free(path_energy_full);
- path_energy_full = 0;
- }
- if (path_current_now) {
- g_free(path_current_now);
- path_current_now = 0;
- }
- if (path_status) {
- g_free(path_status);
- path_status = 0;
- }
- if (battery_low_cmd) {
- g_free(battery_low_cmd);
- battery_low_cmd = 0;
- }
-}
-
-
void init_battery_panel(void *p)
{
Panel *panel = (Panel*)p;
extern char *battery_low_cmd;
extern char *path_energy_now, *path_energy_full, *path_current_now, *path_status;
+// default values
+void default_battery();
+// freed memory
+void cleanup_battery();
// initialize clock : y position, ...
void update_battery();
void init_battery();
void init_battery_panel(void *panel);
-// freed memory and set default values
-void cleanup_battery();
-
void draw_battery(void *obj, cairo_t *c);
void resize_battery(void *obj);
#include "timer.h"
-char *time1_format=0;
-char *time1_timezone=0;
-char *time2_format=0;
-char *time2_timezone=0;
-char *time_tooltip_format=0;
-char *time_tooltip_timezone=0;
-char *clock_lclick_command=0;
-char *clock_rclick_command=0;
+char *time1_format;
+char *time1_timezone;
+char *time2_format;
+char *time2_timezone;
+char *time_tooltip_format;
+char *time_tooltip_timezone;
+char *clock_lclick_command;
+char *clock_rclick_command;
struct timeval time_clock;
-PangoFontDescription *time1_font_desc=0;
-PangoFontDescription *time2_font_desc=0;
+PangoFontDescription *time1_font_desc;
+PangoFontDescription *time2_font_desc;
static char buf_time[40];
static char buf_date[40];
static char buf_tooltip[40];
int clock_enabled;
-static timeout* clock_timeout=0;
+static timeout* clock_timeout;
+
+
+void default_clock()
+{
+ clock_enabled = 0;
+ clock_timeout = 0;
+ time1_format = 0;
+ time1_timezone = 0;
+ time2_format = 0;
+ time2_timezone = 0;
+ time_tooltip_format = 0;
+ time_tooltip_timezone = 0;
+ clock_lclick_command = 0;
+ clock_rclick_command = 0;
+ time1_font_desc = 0;
+ time2_font_desc = 0;
+}
+
+void cleanup_clock()
+{
+ 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 (time_tooltip_format) g_free(time_tooltip_format);
+ if (time1_timezone) g_free(time1_timezone);
+ if (time2_timezone) g_free(time2_timezone);
+ if (time_tooltip_timezone) g_free(time_tooltip_timezone);
+ if (clock_lclick_command) g_free(clock_lclick_command);
+ if (clock_rclick_command) g_free(clock_rclick_command);
+}
void update_clocks_sec(void* arg)
}
-void cleanup_clock()
-{
- clock_enabled = 0;
- if (time1_font_desc) {
- pango_font_description_free(time1_font_desc);
- time1_font_desc = 0;
- }
- if (time2_font_desc) {
- pango_font_description_free(time2_font_desc);
- time2_font_desc = 0;
- }
- if (time1_format) {
- g_free(time1_format);
- time1_format = 0;
- }
- if (time2_format) {
- g_free(time2_format);
- time2_format = 0;
- }
- if (time_tooltip_format) {
- g_free(time_tooltip_format);
- time_tooltip_format = 0;
- }
- if (time1_timezone) {
- g_free(time1_timezone);
- time1_timezone = 0;
- }
- if (time2_timezone) {
- g_free(time2_timezone);
- time2_timezone = 0;
- }
- if (time_tooltip_timezone) {
- g_free(time_tooltip_timezone);
- time_tooltip_timezone = 0;
- }
- if (clock_lclick_command) {
- g_free(clock_lclick_command);
- clock_lclick_command = 0;
- }
- if (clock_rclick_command) {
- g_free(clock_rclick_command);
- clock_rclick_command = 0;
- }
-}
-
-
void draw_clock (void *obj, cairo_t *c)
{
Clock *clock = obj;
extern int clock_enabled;
+// default values
+void default_clock();
+// freed memory
+void cleanup_clock();
+
// initialize clock : y position, precision, ...
void init_clock();
void init_clock_panel(void *panel);
-// freed memory and set default values
-void cleanup_clock();
-
void draw_clock (void *obj, cairo_t *c);
void resize_clock (void *obj);
#endif
// global path
-char *config_path = 0;
-char *snapshot_path = 0;
+char *config_path;
+char *snapshot_path;
// --------------------------------------------------
// backward compatibility
static int old_config_file;
+void default_config()
+{
+ config_path = 0;
+ snapshot_path = 0;
+ old_config_file = 1;
+}
+
+void cleanup_config()
+{
+ if (config_path) g_free(config_path);
+ if (snapshot_path) g_free(snapshot_path);
+}
+
+
void init_config()
{
if (backgrounds)
pango_font_description_free(panel_config.g_task.font_desc);
}
memset(&panel_config, 0, sizeof(Panel));
- systray.alpha = 100;
- systray.sort = 3;
- old_config_file = 1;
// window manager's menu default value == false
wm_menu = 0;
}
-void cleanup_config()
-{
-}
-
-
void extract_values (const char *value, char **value1, char **value2, char **value3)
{
char *b=0, *c=0;
extern char *config_path;
extern char *snapshot_path;
-void init_config();
+// default values
+void default_config();
+// freed memory
void cleanup_config();
+
+void init_config();
int config_read_file (const char *path);
int config_read ();
{
if (!panel1) return;
+printf("*** cleanup_panel()\n");
task_active = 0;
task_drag = 0;
else if (!panel_horizontal && panel_position & RIGHT)
xoff = p->area.width-p->hidden_width;
- if (real_transparency) {
+ if (server.real_transparency) {
clear_pixmap(p->area.pix, 0, 0, p->area.width, p->area.height);
}
else {
void server_catch_error (Display *d, XErrorEvent *ev){}
-int real_transparency = 0;
-
void server_init_atoms ()
{
server.atom._XROOTPMAP_ID = XInternAtom (server.dsp, "_XROOTPMAP_ID", False);
server.atom.XdndAware = XInternAtom(server.dsp, "XdndAware", False);
server.atom.XdndPosition = XInternAtom(server.dsp, "XdndPosition", False);
server.atom.XdndStatus = XInternAtom(server.dsp, "XdndStatus", False);
-
- server.colormap = 0;
- server.monitor = 0;
- server.gc = 0;
}
attrs.event_mask = StructureNotifyMask;
XChangeWindowAttributes (server.dsp, server.composite_manager, CWEventMask, &attrs);
- real_transparency = 1;
+ server.real_transparency = 1;
server.depth = 32;
printf("real transparency on... depth: %d\n", server.depth);
server.colormap = XCreateColormap(server.dsp, server.root_win, visual, AllocNone);
}
else {
// no composite manager or snapshot mode => fake transparency
- real_transparency = 0;
+ server.real_transparency = 0;
server.depth = DefaultDepth(server.dsp, server.screen);
printf("real transparency off.... depth: %d\n", server.depth);
server.colormap = DefaultColormap(server.dsp, server.screen);
#include <X11/Xatom.h>
#include <X11/extensions/Xinerama.h>
-extern int real_transparency;
+
typedef struct Global_atom
{
Atom _XROOTPMAP_ID;
Display *dsp;
Window root_win;
Window composite_manager;
+ int real_transparency;
// current desktop
int desktop;
int screen;
Server_global server;
+// freed memory
+void cleanup_server();
+
void send_event32 (Window win, Atom at, long data1, long data2, long data3);
int get_property32 (Window win, Atom at, Atom type);
void *server_get_property (Window win, Atom at, Atom type, int *num_results);
void server_catch_error (Display *d, XErrorEvent *ev);
void server_init_atoms ();
void server_init_visual();
-void cleanup_server();
// detect root background
void get_root_pixmap();
int systray_max_icon_size;
// background pixmap if we render ourselves the icons
-static Pixmap render_background = 0;
+static Pixmap render_background;
+void default_systray()
+{
+printf("*** default_systray()\n");
+ memset(&systray, 0, sizeof(Systraybar));
+ render_background = 0;
+ systray.alpha = 100;
+ systray.sort = 3;
+ systray.area._draw_foreground = draw_systray;
+ systray.area._resize = resize_systray;
+}
+
+void cleanup_systray()
+{
+ systray_enabled = 0;
+ systray_max_icon_size = 0;
+ systray.area.on_screen = 0;
+ free_area(&systray.area);
+ if (render_background) {
+ XFreePixmap(server.dsp, render_background);
+ render_background = 0;
+ }
+}
+
void init_systray()
{
start_net();
systray.alpha = 100;
systray.brightness = systray.saturation = 0;
}
- systray.area._draw_foreground = draw_systray;
- systray.area._resize = resize_systray;
systray.area.resize = 1;
systray.area.redraw = 1;
systray.area.on_screen = 1;
}
-void cleanup_systray()
-{
- systray_enabled = 0;
- systray_max_icon_size = 0;
- systray.area.on_screen = 0;
- free_area(&systray.area);
- if (render_background) {
- XFreePixmap(server.dsp, render_background);
- render_background = 0;
- }
-}
-
-
void draw_systray(void *obj, cairo_t *c)
{
- if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
+ 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);
XCopyArea(server.dsp, systray.area.pix, render_background, server.gc, 0, 0, systray.area.width, systray.area.height, 0, 0);
// watch for the icon trying to resize itself!
XSelectInput(server.dsp, traywin->tray_id, StructureNotifyMask);
- if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
+ if (server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
traywin->damage = XDamageCreate(server.dsp, traywin->id, XDamageReportRawRectangles);
XCompositeRedirectWindow(server.dsp, traywin->id, CompositeRedirectManual);
}
return;
}
Picture pict_image;
- if (real_transparency)
+ if (server.real_transparency)
pict_image = XRenderCreatePicture(server.dsp, traywin->id, f, 0, 0);
else
pict_image = XRenderCreatePicture(server.dsp, traywin->tray_id, f, 0, 0);
void systray_render_icon(TrayWindow* traywin)
{
- if (real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
+ if (server.real_transparency || systray.alpha != 100 || systray.brightness != 0 || systray.saturation != 0) {
// wine tray icons update whenever mouse is over them, so we limit the updates to 50 ms
if (traywin->render_timeout == 0)
traywin->render_timeout = add_timeout(50, 0, systray_render_icon_now, traywin);
extern int systray_enabled;
extern int systray_max_icon_size;
-void init_systray();
+// default values
+void default_systray();
+// freed memory
+void cleanup_systray();
+// initialize protocol and panel position
+void init_systray();
void init_systray_panel(void *p);
-// freed memory and set default values
-void cleanup_systray();
-
void draw_systray(void *obj, cairo_t *c);
void resize_systray(void *obj);
#include "tooltip.h"
#include "timer.h"
-static timeout* urgent_timeout = 0;
-static GSList* urgent_list = 0;
+timeout* urgent_timeout;
+GSList* urgent_list;
const char* task_get_tooltip(void* obj)
{
// Render
imlib_context_set_image (tsk->icon[tsk->current_state]);
- if (real_transparency) {
+ if (server.real_transparency) {
render_image(tsk->area.pix, pos_x, panel->g_task.icon_posy, imlib_image_get_width(), imlib_image_get_height() );
}
else {
#include <pango/pangocairo.h>
#include <Imlib2.h>
#include "common.h"
+#include "timer.h"
enum { TASK_NORMAL, TASK_ACTIVE, TASK_ICONIFIED, TASK_URGENT, TASK_STATE_COUNT };
+extern timeout* urgent_timeout;
+extern GSList* urgent_list;
// --------------------------------------------------
// global task parameter
element. However for omnipresent windows (windows which are visible in every taskbar) the array
contains to every Task* on each panel a pointer (i.e. GPtrArray.len == server.nb_desktop)
*/
-GHashTable* win_to_task_table = 0;
+GHashTable* win_to_task_table;
guint win_hash(gconstpointer key) { return (guint)*((Window*)key); }
gboolean win_compare(gconstpointer a, gconstpointer b) { return (*((Window*)a) == *((Window*)b)); }
remove_task(task_get_task(*(Window*)key));
}
+void default_taskbar()
+{
+ win_to_task_table = 0;
+ urgent_timeout = 0;
+ urgent_list = 0;
+}
+
void cleanup_taskbar()
{
Panel *panel;
int use_active;
} Global_taskbar;
-void init_taskbar();
-// freed memory and set default values
+// default values
+void default_taskbar();
+// freed memory
void cleanup_taskbar();
+void init_taskbar();
+
Task *task_get_task (Window win);
GPtrArray* task_get_tasks(Window win);
void task_refresh_tasklist ();
#include "tooltip.h"
#include "timer.h"
+
void signal_handler(int sig)
{
// signal handler is light as it should be
{
int i;
+ // set global data
+ default_timeout();
+ default_systray();
+ memset(&server, 0, sizeof(Server_global));
+ default_battery();
+ default_clock();
+ default_taskbar();
+ default_tooltip();
+ default_config();
+
// read options
for (i = 1; i < argc; ++i) {
if (!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
// sigaddset(&block_mask, SIGHUP);
// sigaddset(&block_mask, SIGUSR1);
// sigprocmask(SIG_BLOCK, &block_mask, 0);
-
- // set global data
- memset(&server, 0, sizeof(Server_global));
- memset(&systray, 0, sizeof(Systraybar));
}
void init_X11()
void cleanup()
{
- stop_all_timeouts();
+printf("*** cleanup()\n");
+ cleanup_timeout();
cleanup_systray();
stop_net();
cleanup_panel();
#ifdef ENABLE_BATTERY
cleanup_battery();
#endif
+ cleanup_config();
if (default_icon) {
imlib_context_set_image(default_icon);
imlib_free_image();
}
- if (config_path) g_free(config_path);
- if (snapshot_path) g_free(snapshot_path);
cleanup_server();
if (server.dsp) XCloseDisplay(server.dsp);
void start_hide_timeout();
void stop_tooltip_timeout();
-// give the tooltip some reasonable default values
-Tooltip g_tooltip = {
- .tooltip_text = 0,
- .area = 0,
- .panel = 0,
- .window = 0,
- .show_timeout_msec = 0,
- .hide_timeout_msec = 0,
- .enabled = False,
- .mapped = False,
- .paddingx = 0,
- .paddingy = 0,
- .font_color = { .color={1, 1, 1}, .alpha=1 },
- .bg = 0,
- .font_desc = 0,
- .timeout = 0
-};
+Tooltip g_tooltip;
+
+
+void default_tooltip()
+{
+ // give the tooltip some reasonable default values
+ memset(&g_tooltip, 0, sizeof(Tooltip));
+
+ g_tooltip.font_color.color[0] = 1;
+ g_tooltip.font_color.color[1] = 1;
+ g_tooltip.font_color.color[2] = 1;
+ g_tooltip.font_color.alpha = 1;
+}
+
+void cleanup_tooltip()
+{
+ stop_tooltip_timeout();
+ tooltip_hide(0);
+ tooltip_copy_text(0);
+ if (g_tooltip.window) XDestroyWindow(server.dsp, g_tooltip.window);
+ if (g_tooltip.font_desc) pango_font_description_free(g_tooltip.font_desc);
+}
+
void init_tooltip()
{
}
-void cleanup_tooltip()
-{
- stop_tooltip_timeout();
- tooltip_hide(0);
- g_tooltip.enabled = False;
- tooltip_copy_text(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_trigger_show(Area* area, Panel* p, int x_root, int y_root)
{
x = x_root;
c = cairo_create(cs);
Color bc = g_tooltip.bg->back;
Border b = g_tooltip.bg->border;
- if (real_transparency) {
+ if (server.real_transparency) {
clear_pixmap(g_tooltip.window, 0, 0, width, height);
draw_rect(c, b.width, b.width, width-2*b.width, height-2*b.width, b.rounded-b.width/1.571);
cairo_set_source_rgba(c, bc.color[0], bc.color[1], bc.color[2], bc.alpha);
}
cairo_fill(c);
cairo_set_line_width(c, b.width);
- if (real_transparency) draw_rect(c, b.width/2.0, b.width/2.0, width - b.width, height - b.width, b.rounded);
- else cairo_rectangle(c, b.width/2.0, b.width/2.0, width-b.width, height-b.width);
+ if (server.real_transparency)
+ draw_rect(c, b.width/2.0, b.width/2.0, width - b.width, height - b.width, b.rounded);
+ else
+ cairo_rectangle(c, b.width/2.0, b.width/2.0, width-b.width, height-b.width);
cairo_set_source_rgba(c, b.color[0], b.color[1], b.color[2], b.alpha);
cairo_stroke(c);
extern Tooltip g_tooltip;
-void init_tooltip();
+
+// default values
+void default_tooltip();
+// freed memory
void cleanup_tooltip();
+
+void init_tooltip();
void tooltip_trigger_show(Area* area, Panel* p, int x, int y);
void tooltip_show(void* /*arg*/);
void tooltip_update();
a->pix = XCreatePixmap (server.dsp, server.root_win, a->width, a->height, server.depth);
// add layer of root pixmap (or clear pixmap if real_transparency==true)
- if (real_transparency)
+ if (server.real_transparency)
clear_pixmap(a->pix, 0 ,0, a->width, a->height);
XCopyArea (server.dsp, ((Panel *)a->panel)->temp_pmap, a->pix, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
#include "timer.h"
-GSList* timeout_list = 0;
+GSList* timeout_list;
struct timeval next_timeout;
+GHashTable* multi_timeouts;
// functions and structs for multi timeouts
multi_timeout* multi_timeout;
};
+
+void default_timeout()
+{
+ timeout_list = 0;
+ multi_timeouts = 0;
+}
+
+void cleanup_timeout()
+{
+ while (timeout_list) {
+ timeout* t = timeout_list->data;
+ if (t->multi_timeout)
+ stop_multi_timeout(t);
+ free(t);
+ timeout_list = g_slist_remove(timeout_list, t);
+ }
+}
+
void add_timeout_intern(int value_msec, int interval_msec, void(*_callback)(void*), void* arg, timeout* t);
gint compare_timeouts(gconstpointer t1, gconstpointer t2);
gint compare_timespecs(const struct timespec* t1, const struct timespec* t2);
void remove_from_multi_timeout(timeout* t);
void stop_multi_timeout(timeout* t);
-GHashTable* multi_timeouts = 0;
-
/** Implementation notes for timeouts: The timeouts are kept in a GSList sorted by their
* expiration time.
* That means that update_next_timeout() only have to consider the first timeout in the list,
}
-void stop_all_timeouts()
-{
- while (timeout_list) {
- timeout* t = timeout_list->data;
- if (t->multi_timeout)
- stop_multi_timeout(t);
- free(t);
- timeout_list = g_slist_remove(timeout_list, t);
- }
-}
-
-
void add_timeout_intern(int value_msec, int interval_msec, void(*_callback)(), void* arg, timeout *t)
{
t->interval_msec = interval_msec;
* integral multiple of the other.
**/
+/** default values **/
+void default_timeout();
+/** freed memory : stops all timeouts **/
+void cleanup_timeout();
+
/** installs a timeout with the first timeout of 'value_msec' and then a periodic timeout with
* 'interval_msec'. '_callback' is the callback function when the timer reaches the timeout.
* returns a pointer to the timeout, which is needed for stopping it again
/** stops the timeout 't' **/
void stop_timeout(timeout* t);
-/** stops all timeouts **/
-void stop_all_timeouts();
-
/** update_next_timeout updates next_timeout to the value, when the next installed timeout will expire **/
void update_next_timeout();