*add* changed everything to kernel timer for easier integration with new timer

*todo* adapt tooltip also to the timer syntax
*fix* memory leak



git-svn-id: http://tint2.googlecode.com/svn/trunk@266 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
Andreas.Fink85 2009-11-15 16:55:50 +00:00
parent 429660abb6
commit 806451955b
9 changed files with 113 additions and 87 deletions

View file

@ -14,6 +14,8 @@ tint2_SOURCES = config.c \
util/area.c \ util/area.c \
util/window.h \ util/window.h \
util/window.c \ util/window.c \
util/timer.h \
util/timer.c \
panel.h \ panel.h \
clock/clock.c \ clock/clock.c \
clock/clock.h \ clock/clock.h \

View file

@ -31,6 +31,7 @@
#include "taskbar.h" #include "taskbar.h"
#include "battery.h" #include "battery.h"
#include "clock.h" #include "clock.h"
#include "timer.h"
PangoFontDescription *bat1_font_desc=0; PangoFontDescription *bat1_font_desc=0;
PangoFontDescription *bat2_font_desc=0; PangoFontDescription *bat2_font_desc=0;
@ -47,6 +48,14 @@ char *path_energy_full=0;
char *path_current_now=0; char *path_current_now=0;
char *path_status=0; char *path_status=0;
void update_batterys()
{
int i;
update_battery();
for (i=0 ; i < nb_panel ; i++)
panel1[i].battery.area.resize = 1;
}
void init_battery() void init_battery()
{ {
@ -120,6 +129,9 @@ void init_battery()
g_free(path1); g_free(path1);
g_free(battery_dir); g_free(battery_dir);
if (battery_enabled)
install_timer(0, 1000000, 3, 0, update_batterys);
} }

View file

@ -30,6 +30,7 @@
#include "panel.h" #include "panel.h"
#include "taskbar.h" #include "taskbar.h"
#include "clock.h" #include "clock.h"
#include "timer.h"
char *time1_format=0; char *time1_format=0;
@ -37,7 +38,6 @@ char *time2_format=0;
char *clock_lclick_command=0; char *clock_lclick_command=0;
char *clock_rclick_command=0; char *clock_rclick_command=0;
struct timeval time_clock; struct timeval time_clock;
int time_precision;
PangoFontDescription *time1_font_desc=0; PangoFontDescription *time1_font_desc=0;
PangoFontDescription *time2_font_desc=0; PangoFontDescription *time2_font_desc=0;
static char buf_time[40]; static char buf_time[40];
@ -45,25 +45,25 @@ static char buf_date[40];
int clock_enabled; int clock_enabled;
void init_precision() void update_clocks()
{ {
if (!time1_format) time_precision = 60; gettimeofday(&time_clock, 0);
else if (strchr(time1_format, 'S')) time_precision = 1; int i;
else if (strchr(time1_format, 'T')) time_precision = 1; if (time1_format) {
else if (strchr(time1_format, 'r')) time_precision = 1; for (i=0 ; i < nb_panel ; i++)
else time_precision = 60; panel1[i].clock.area.resize = 1;
}
panel_refresh = 1;
} }
void init_clock() void init_clock()
{ {
init_precision(); if(time1_format) {
if (strchr(time1_format, 'S') || strchr(time1_format, 'T') || strchr(time1_format, 'r'))
// update clock to force update (-time_precision) install_timer(0, 1000000, 1, 0, update_clocks);
struct timeval stv; else install_timer(0, 1000000, 60, 0, update_clocks);
gettimeofday(&stv, 0); }
time_clock.tv_sec = stv.tv_sec - time_precision;
time_clock.tv_sec -= time_clock.tv_sec % time_precision;
} }

View file

@ -26,8 +26,6 @@ typedef struct Clock {
extern char *time1_format; extern char *time1_format;
extern char *time2_format; extern char *time2_format;
extern struct timeval time_clock;
extern int time_precision;
extern PangoFontDescription *time1_font_desc; extern PangoFontDescription *time1_font_desc;
extern PangoFontDescription *time2_font_desc; extern PangoFontDescription *time2_font_desc;
extern char *clock_lclick_command; extern char *clock_lclick_command;
@ -38,7 +36,6 @@ extern int clock_enabled;
// initialize clock : y position, precision, ... // initialize clock : y position, precision, ...
void init_clock(); void init_clock();
void init_clock_panel(void *panel); void init_clock_panel(void *panel);
void init_precision();
void cleanup_clock(); void cleanup_clock();
void draw_clock (void *obj, cairo_t *c, int active); void draw_clock (void *obj, cairo_t *c, int active);

View file

@ -265,6 +265,11 @@ void cleanup_panel()
if (panel1) free(panel1); if (panel1) free(panel1);
panel1 = 0; panel1 = 0;
if (panel_config.g_task.font_desc) {
pango_font_description_free(panel_config.g_task.font_desc);
panel_config.g_task.font_desc = 0;
}
} }

View file

@ -51,7 +51,6 @@ extern int panel_refresh;
extern Task *task_active; extern Task *task_active;
extern Task *task_drag; extern Task *task_drag;
extern GSList *urgent_list; extern GSList *urgent_list;
extern int tick_urgent;
extern int max_tick_urgent; extern int max_tick_urgent;
extern Imlib_Image default_icon; extern Imlib_Image default_icon;

View file

@ -32,8 +32,9 @@
#include "server.h" #include "server.h"
#include "panel.h" #include "panel.h"
#include "tooltip.h" #include "tooltip.h"
#include "timer.h"
static int urgent_timer = 0;
Task *add_task (Window win) Task *add_task (Window win)
{ {
@ -411,6 +412,21 @@ void active_task()
} }
void blink_urgent()
{
GSList* urgent_task = urgent_list;
while (urgent_task) {
Task_urgent* t = urgent_task->data;
if ( t->tick < max_tick_urgent) {
t->tsk->area.is_active = !t->tsk->area.is_active;
t->tsk->area.redraw = 1;
t->tick++;
}
urgent_task = urgent_task->next;
}
}
void add_urgent(Task *tsk) void add_urgent(Task *tsk)
{ {
// first check if task is already in the list and reset the counter // first check if task is already in the list and reset the counter
@ -431,7 +447,11 @@ void add_urgent(Task *tsk)
t->tsk = tsk; t->tsk = tsk;
t->tick = 0; t->tick = 0;
urgent_list = g_slist_prepend(urgent_list, t); urgent_list = g_slist_prepend(urgent_list, t);
time_precision = 1;
if (urgent_timer == 0)
urgent_timer = install_timer(0, 1000000, 1, 0, blink_urgent);
else
reset_timer(urgent_timer, 0, 1000000, 1, 0);
} }
@ -444,7 +464,7 @@ void del_urgent(Task *tsk)
urgent_list = g_slist_remove(urgent_list, t); urgent_list = g_slist_remove(urgent_list, t);
free(t); free(t);
if (!urgent_list) if (!urgent_list)
init_precision(); reset_timer(urgent_timer, 0, 0, 0, 0);
return; return;
} }
urgent_task = urgent_task->next; urgent_task = urgent_task->next;

View file

@ -19,10 +19,10 @@
**************************************************************************/ **************************************************************************/
#include <sys/stat.h> #include <sys/stat.h>
#include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdint.h>
#include <string.h> #include <string.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/Xatom.h> #include <X11/Xatom.h>
@ -38,7 +38,7 @@
#include "systraybar.h" #include "systraybar.h"
#include "panel.h" #include "panel.h"
#include "tooltip.h" #include "tooltip.h"
#include "timer.h"
void signal_handler(int sig) void signal_handler(int sig)
{ {
@ -74,12 +74,21 @@ void init (int argc, char *argv[])
} }
// Set signal handler // Set signal handler
signal(SIGUSR1, signal_handler); struct sigaction sa = { .sa_handler = signal_handler };
signal(SIGINT, signal_handler); sigaction(SIGUSR1, &sa, 0);
signal(SIGTERM, signal_handler); sigaction(SIGINT, &sa, 0);
signal(SIGHUP, signal_handler); sigaction(SIGTERM, &sa, 0);
sigaction(SIGHUP, &sa, 0);
signal(SIGCHLD, SIG_IGN); // don't have to wait() after fork() signal(SIGCHLD, SIG_IGN); // don't have to wait() after fork()
signal(SIGALRM, tooltip_sighandler); signal(SIGALRM, tooltip_sighandler);
// block all signals, such that no race conditions occur before pselect in our main loop
sigset_t block_mask;
sigaddset(&block_mask, SIGINT);
sigaddset(&block_mask, SIGTERM);
sigaddset(&block_mask, SIGHUP);
sigaddset(&block_mask, SIGUSR1);
sigprocmask(SIG_BLOCK, &block_mask, 0);
// set global data // set global data
memset(&server, 0, sizeof(Server_global)); memset(&server, 0, sizeof(Server_global));
@ -111,7 +120,7 @@ void init (int argc, char *argv[])
setlocale (LC_ALL, ""); setlocale (LC_ALL, "");
// load default icon // load default icon
char *path; gchar *path;
const gchar * const *data_dirs; const gchar * const *data_dirs;
data_dirs = g_get_system_data_dirs (); data_dirs = g_get_system_data_dirs ();
for (i = 0; data_dirs[i] != NULL; i++) { for (i = 0; data_dirs[i] != NULL; i++) {
@ -660,42 +669,6 @@ void event_configure_notify (Window win)
void event_timer() void event_timer()
{ {
struct timeval stv;
int i;
if (gettimeofday(&stv, 0)) return;
if (abs(stv.tv_sec - time_clock.tv_sec) < time_precision) return;
time_clock.tv_sec = stv.tv_sec;
time_clock.tv_sec -= time_clock.tv_sec % time_precision;
// urgent task
GSList* urgent_task = urgent_list;
while (urgent_task) {
Task_urgent* t = urgent_task->data;
if ( t->tick < max_tick_urgent) {
t->tsk->area.is_active = !t->tsk->area.is_active;
t->tsk->area.redraw = 1;
t->tick++;
}
urgent_task = urgent_task->next;
}
// update battery
#ifdef ENABLE_BATTERY
if (battery_enabled) {
update_battery();
for (i=0 ; i < nb_panel ; i++)
panel1[i].battery.area.resize = 1;
}
#endif
// update clock
if (time1_format) {
for (i=0 ; i < nb_panel ; i++)
panel1[i].clock.area.resize = 1;
}
panel_refresh = 1;
} }
@ -732,11 +705,12 @@ void dnd_message(XClientMessageEvent *e)
int main (int argc, char *argv[]) int main (int argc, char *argv[])
{ {
XEvent e; XEvent e;
fd_set fd; fd_set fd_set;
int x11_fd, i; int x11_fd, i;
struct timeval tv;
Panel *panel; Panel *panel;
GSList *it; GSList *it;
GSList* timer_iter;
struct timer* timer;
init (argc, argv); init (argc, argv);
@ -762,17 +736,25 @@ int main (int argc, char *argv[])
x11_fd = ConnectionNumber(server.dsp); x11_fd = ConnectionNumber(server.dsp);
XSync(server.dsp, False); XSync(server.dsp, False);
sigset_t empty_mask;
sigemptyset(&empty_mask);
while (1) { while (1) {
// thanks to AngryLlama for the timer // thanks to AngryLlama for the timer
// Create a File Description Set containing x11_fd // Create a File Description Set containing x11_fd, and every timer_fd
FD_ZERO (&fd); FD_ZERO (&fd_set);
FD_SET (x11_fd, &fd); FD_SET (x11_fd, &fd_set);
int max_fd = x11_fd;
tv.tv_usec = 500000; timer_iter = timer_list;
tv.tv_sec = 0; while (timer_iter) {
timer = timer_iter->data;
max_fd = timer->id > max_fd ? timer->id : max_fd;
FD_SET(timer->id, &fd_set);
timer_iter = timer_iter->next;
}
// Wait for X Event or a Timer // Wait for X Event or a Timer
if (select(x11_fd+1, &fd, 0, 0, &tv)) { if (pselect(max_fd+1, &fd_set, 0, 0, 0, &empty_mask) > 0) {
while (XPending (server.dsp)) { while (XPending (server.dsp)) {
XNextEvent(server.dsp, &e); XNextEvent(server.dsp, &e);
@ -844,22 +826,32 @@ int main (int argc, char *argv[])
break; break;
} }
} }
timer_iter = timer_list;
while (timer_iter) {
timer = timer_iter->data;
if (FD_ISSET(timer->id, &fd_set)) {
uint64_t dummy;
read(timer->id, &dummy, sizeof(uint64_t));
timer->_callback();
}
timer_iter = timer_iter->next;
}
} }
event_timer();
switch (signal_pending) { switch (signal_pending) {
case SIGUSR1: // reload config file case SIGUSR1: // reload config file
signal_pending = 0; signal_pending = 0;
init_config(); init_config();
config_read_file (config_path); config_read_file (config_path);
init_panel(); init_panel();
cleanup_config(); cleanup_config();
break; break;
case SIGINT: case SIGINT:
case SIGTERM: case SIGTERM:
case SIGHUP: case SIGHUP:
cleanup (); cleanup ();
return 0; return 0;
} }
if (panel_refresh) { if (panel_refresh) {

View file

@ -64,6 +64,5 @@ void get_color (char *hex, double *rgb);
// adjust Alpha/Saturation/Brightness on an ARGB icon // adjust Alpha/Saturation/Brightness on an ARGB icon
// alpha from 0 to 100, satur from 0 to 1, bright from 0 to 1. // alpha from 0 to 100, satur from 0 to 1, bright from 0 to 1.
void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright); void adjust_asb(DATA32 *data, int w, int h, int alpha, float satur, float bright);
#endif #endif