*add* more task states (normal, active, iconified, urgent), with each an own background, font and asb
*fix* two memleaks *fix* some code beautification git-svn-id: http://tint2.googlecode.com/svn/trunk@327 121b4492-b84c-0410-8b4c-0d4edfb3f3cc
This commit is contained in:
@@ -30,9 +30,6 @@
|
||||
#include "server.h"
|
||||
#include "panel.h"
|
||||
|
||||
// QUESTION: Why do we need Pixmaps for drawing? Can't we draw directly in the Window???
|
||||
// Parent could pass a cairo_surface_t to the children, and children use it, for drawing...
|
||||
|
||||
|
||||
// 1) resize child
|
||||
// 2) resize parent
|
||||
@@ -54,15 +51,12 @@ void refresh (Area *a)
|
||||
set_redraw(l->data);
|
||||
|
||||
//printf("draw area posx %d, width %d\n", a->posx, a->width);
|
||||
draw(a, 0);
|
||||
if (a->use_active)
|
||||
draw(a, 1);
|
||||
draw(a);
|
||||
}
|
||||
|
||||
// draw current Area
|
||||
Pixmap pmap = (a->is_active == 0) ? (a->pix.pmap) : (a->pix_active.pmap);
|
||||
if (pmap == 0) printf("empty area posx %d, width %d\n", a->posx, a->width);
|
||||
XCopyArea (server.dsp, pmap, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
|
||||
if (a->pix == 0) printf("empty area posx %d, width %d\n", a->posx, a->width);
|
||||
XCopyArea (server.dsp, a->pix, ((Panel *)a->panel)->temp_pmap, server.gc, 0, 0, a->width, a->height, a->posx, a->posy);
|
||||
|
||||
// and then refresh child object
|
||||
GSList *l;
|
||||
@@ -101,51 +95,46 @@ void set_redraw (Area *a)
|
||||
}
|
||||
|
||||
|
||||
void draw (Area *a, int active)
|
||||
void draw (Area *a)
|
||||
{
|
||||
Pixmap *pmap = (active == 0) ? (&a->pix.pmap) : (&a->pix_active.pmap);
|
||||
|
||||
if (*pmap) XFreePixmap (server.dsp, *pmap);
|
||||
*pmap = XCreatePixmap (server.dsp, server.root_win, a->width, a->height, server.depth);
|
||||
if (a->pix) XFreePixmap (server.dsp, a->pix);
|
||||
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)
|
||||
clear_pixmap(*pmap, 0 ,0, a->width, a->height);
|
||||
XCopyArea (server.dsp, ((Panel *)a->panel)->temp_pmap, *pmap, server.gc, a->posx, a->posy, a->width, a->height, 0, 0);
|
||||
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);
|
||||
|
||||
cairo_surface_t *cs;
|
||||
cairo_t *c;
|
||||
|
||||
cs = cairo_xlib_surface_create (server.dsp, *pmap, server.visual, a->width, a->height);
|
||||
cs = cairo_xlib_surface_create (server.dsp, a->pix, server.visual, a->width, a->height);
|
||||
c = cairo_create (cs);
|
||||
|
||||
draw_background (a, c, active);
|
||||
draw_background (a, c);
|
||||
|
||||
if (a->_draw_foreground)
|
||||
a->_draw_foreground(a, c, active);
|
||||
a->_draw_foreground(a, c);
|
||||
|
||||
cairo_destroy (c);
|
||||
cairo_surface_destroy (cs);
|
||||
}
|
||||
|
||||
|
||||
void draw_background (Area *a, cairo_t *c, int active)
|
||||
void draw_background (Area *a, cairo_t *c)
|
||||
{
|
||||
Pmap *pix = (active == 0) ? (&a->pix) : (&a->pix_active);
|
||||
|
||||
if (pix->back.alpha > 0.0) {
|
||||
if (a->bg->back.alpha > 0.0) {
|
||||
//printf(" draw_background (%d %d) RGBA (%lf, %lf, %lf, %lf)\n", a->posx, a->posy, pix->back.color[0], pix->back.color[1], pix->back.color[2], pix->back.alpha);
|
||||
draw_rect(c, pix->border.width, pix->border.width, a->width-(2.0 * pix->border.width), a->height-(2.0*pix->border.width), pix->border.rounded - pix->border.width/1.571);
|
||||
cairo_set_source_rgba(c, pix->back.color[0], pix->back.color[1], pix->back.color[2], pix->back.alpha);
|
||||
|
||||
draw_rect(c, a->bg->border.width, a->bg->border.width, a->width-(2.0 * a->bg->border.width), a->height-(2.0*a->bg->border.width), a->bg->border.rounded - a->bg->border.width/1.571);
|
||||
cairo_set_source_rgba(c, a->bg->back.color[0], a->bg->back.color[1], a->bg->back.color[2], a->bg->back.alpha);
|
||||
cairo_fill(c);
|
||||
}
|
||||
|
||||
if (pix->border.width > 0 && pix->border.alpha > 0.0) {
|
||||
cairo_set_line_width (c, pix->border.width);
|
||||
if (a->bg->border.width > 0 && a->bg->border.alpha > 0.0) {
|
||||
cairo_set_line_width (c, a->bg->border.width);
|
||||
|
||||
// draw border inside (x, y, width, height)
|
||||
draw_rect(c, pix->border.width/2.0, pix->border.width/2.0, a->width - pix->border.width, a->height - pix->border.width, pix->border.rounded);
|
||||
draw_rect(c, a->bg->border.width/2.0, a->bg->border.width/2.0, a->width - a->bg->border.width, a->height - a->bg->border.width, a->bg->border.rounded);
|
||||
/*
|
||||
// convert : radian = degre * M_PI/180
|
||||
// définir le dégradé dans un carré de (0,0) (100,100)
|
||||
@@ -182,7 +171,7 @@ void draw_background (Area *a, cairo_t *c, int active)
|
||||
cairo_pattern_add_color_stop_rgba (linpat, 1, a->border.color[0], a->border.color[1], a->border.color[2], 0);
|
||||
cairo_set_source (c, linpat);
|
||||
*/
|
||||
cairo_set_source_rgba (c, pix->border.color[0], pix->border.color[1], pix->border.color[2], pix->border.alpha);
|
||||
cairo_set_source_rgba (c, a->bg->border.color[0], a->bg->border.color[1], a->bg->border.color[2], a->bg->border.alpha);
|
||||
|
||||
cairo_stroke (c);
|
||||
//cairo_pattern_destroy (linpat);
|
||||
@@ -220,13 +209,9 @@ void free_area (Area *a)
|
||||
g_slist_free(a->list);
|
||||
a->list = 0;
|
||||
}
|
||||
if (a->pix.pmap) {
|
||||
XFreePixmap (server.dsp, a->pix.pmap);
|
||||
a->pix.pmap = 0;
|
||||
}
|
||||
if (a->pix_active.pmap) {
|
||||
XFreePixmap (server.dsp, a->pix_active.pmap);
|
||||
a->pix_active.pmap = 0;
|
||||
if (a->pix) {
|
||||
XFreePixmap (server.dsp, a->pix);
|
||||
a->pix = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,7 @@
|
||||
* Area is at the begining of each object (&object == &area).
|
||||
*
|
||||
* Area manage the background and border drawing, size and padding.
|
||||
* Each Area have 2 Pixmap (pix and pix_active).
|
||||
* Each Area has one Pixmap (pix).
|
||||
*
|
||||
* Area manage the tree of all objects. Parent object drawn before child object.
|
||||
* panel -> taskbars -> tasks
|
||||
@@ -40,13 +40,12 @@ typedef struct
|
||||
double alpha;
|
||||
} Color;
|
||||
|
||||
|
||||
typedef struct
|
||||
{
|
||||
Pixmap pmap;
|
||||
Color back;
|
||||
Border border;
|
||||
} Pmap;
|
||||
} Background;
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
@@ -54,8 +53,8 @@ typedef struct {
|
||||
int posx, posy;
|
||||
// width and height including border
|
||||
int width, height;
|
||||
Pmap pix;
|
||||
Pmap pix_active;
|
||||
Pixmap pix;
|
||||
Background *bg;
|
||||
|
||||
// list of child : Area object
|
||||
GSList *list;
|
||||
@@ -65,7 +64,6 @@ typedef struct {
|
||||
int resize;
|
||||
// need redraw Pixmap
|
||||
int redraw;
|
||||
int use_active, is_active;
|
||||
// paddingxlr = horizontal padding left/right
|
||||
// paddingx = horizontal padding between childs
|
||||
int paddingxlr, paddingx, paddingy;
|
||||
@@ -75,7 +73,7 @@ typedef struct {
|
||||
void *panel;
|
||||
|
||||
// each object can overwrite following function
|
||||
void (*_draw_foreground)(void *obj, cairo_t *c, int active);
|
||||
void (*_draw_foreground)(void *obj, cairo_t *c);
|
||||
void (*_resize)(void *obj);
|
||||
void (*_add_child)(void *obj);
|
||||
int (*_remove_child)(void *obj);
|
||||
@@ -92,9 +90,9 @@ void size (Area *a);
|
||||
// set 'redraw' on an area and childs
|
||||
void set_redraw (Area *a);
|
||||
|
||||
// draw pixmap and pixmap_active
|
||||
void draw (Area *a, int active);
|
||||
void draw_background (Area *a, cairo_t *c, int active);
|
||||
// draw pixmap
|
||||
void draw (Area *a);
|
||||
void draw_background (Area *a, cairo_t *c);
|
||||
|
||||
void remove_area (Area *a);
|
||||
void add_area (Area *a);
|
||||
|
||||
@@ -34,22 +34,6 @@ enum { NONE=0, CLOSE, TOGGLE, ICONIFY, SHADE, TOGGLE_ICONIFY, MAXIMIZE_RESTORE,
|
||||
#define ALLDESKTOP 0xFFFFFFFF
|
||||
|
||||
|
||||
typedef struct config_border
|
||||
{
|
||||
double color[3];
|
||||
double alpha;
|
||||
int width;
|
||||
int rounded;
|
||||
} config_border;
|
||||
|
||||
|
||||
typedef struct config_color
|
||||
{
|
||||
double color[3];
|
||||
double alpha;
|
||||
} config_color;
|
||||
|
||||
|
||||
// copy file source to file dest
|
||||
void copy_file(const char *pathSrc, const char *pathDest);
|
||||
|
||||
|
||||
128
src/util/timer.c
128
src/util/timer.c
@@ -24,31 +24,41 @@
|
||||
GSList* timeout_list = 0;
|
||||
struct timeval next_timeout;
|
||||
|
||||
void add_timeout_intern(int value_msec, int interval_msec, void(*_callback)(void*), void* arg, struct timeout* t);
|
||||
|
||||
// functions and structs for multi timeouts
|
||||
typedef struct {
|
||||
int current_count;
|
||||
int count_to_expiration;
|
||||
} multi_timeout;
|
||||
|
||||
typedef struct {
|
||||
GSList* timeout_list;
|
||||
timeout* parent_timeout;
|
||||
} multi_timeout_handler;
|
||||
|
||||
struct _timeout {
|
||||
int interval_msec;
|
||||
struct timespec timeout_expires;
|
||||
void (*_callback)(void*);
|
||||
void* arg;
|
||||
multi_timeout* multi_timeout;
|
||||
};
|
||||
|
||||
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);
|
||||
int timespec_subtract(struct timespec* result, struct timespec* x, struct timespec* y);
|
||||
struct timespec add_msec_to_timespec(struct timespec ts, int msec);
|
||||
|
||||
// functions and structs for multi timeouts
|
||||
struct multi_timeout {
|
||||
int current_count;
|
||||
int count_to_expiration;
|
||||
};
|
||||
|
||||
struct multi_timeout_handler {
|
||||
GSList* timeout_list;
|
||||
struct timeout* parent_timeout;
|
||||
};
|
||||
|
||||
int align_with_existing_timeouts(struct timeout* t);
|
||||
void create_multi_timeout(struct timeout* t1, struct timeout* t2);
|
||||
void append_multi_timeout(struct timeout* t1, struct timeout* t2);
|
||||
int calc_multi_timeout_interval(struct multi_timeout_handler* mth);
|
||||
void update_multi_timeout_values(struct multi_timeout_handler* mth);
|
||||
int align_with_existing_timeouts(timeout* t);
|
||||
void create_multi_timeout(timeout* t1, timeout* t2);
|
||||
void append_multi_timeout(timeout* t1, timeout* t2);
|
||||
int calc_multi_timeout_interval(multi_timeout_handler* mth);
|
||||
void update_multi_timeout_values(multi_timeout_handler* mth);
|
||||
void callback_multi_timeout(void* mth);
|
||||
void remove_from_multi_timeout(struct timeout* t);
|
||||
void stop_multi_timeout(struct timeout* t);
|
||||
void remove_from_multi_timeout(timeout* t);
|
||||
void stop_multi_timeout(timeout* t);
|
||||
|
||||
GHashTable* multi_timeouts = 0;
|
||||
|
||||
@@ -64,25 +74,25 @@ GHashTable* multi_timeouts = 0;
|
||||
* however it's save to call it.
|
||||
**/
|
||||
|
||||
const struct timeout* add_timeout(int value_msec, int interval_msec, void (*_callback)(void*), void* arg)
|
||||
timeout* add_timeout(int value_msec, int interval_msec, void (*_callback)(void*), void* arg)
|
||||
{
|
||||
struct timeout* t = malloc(sizeof(struct timeout));
|
||||
timeout* t = malloc(sizeof(timeout));
|
||||
t->multi_timeout = 0;
|
||||
add_timeout_intern(value_msec, interval_msec, _callback, arg, t);
|
||||
return t;
|
||||
}
|
||||
|
||||
|
||||
void change_timeout(const struct timeout *t, int value_msec, int interval_msec, void(*_callback)(), void* arg)
|
||||
void change_timeout(timeout *t, int value_msec, int interval_msec, void(*_callback)(), void* arg)
|
||||
{
|
||||
if ( g_slist_find(timeout_list, t) == 0 && g_hash_table_lookup(multi_timeouts, t) == 0)
|
||||
printf("programming error: timeout already deleted...");
|
||||
else {
|
||||
if (t->multi_timeout)
|
||||
remove_from_multi_timeout((struct timeout*)t);
|
||||
remove_from_multi_timeout((timeout*)t);
|
||||
else
|
||||
timeout_list = g_slist_remove(timeout_list, t);
|
||||
add_timeout_intern(value_msec, interval_msec, _callback, arg, (struct timeout*)t);
|
||||
add_timeout_intern(value_msec, interval_msec, _callback, arg, (timeout*)t);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,7 +100,7 @@ void change_timeout(const struct timeout *t, int value_msec, int interval_msec,
|
||||
void update_next_timeout()
|
||||
{
|
||||
if (timeout_list) {
|
||||
struct timeout* t = timeout_list->data;
|
||||
timeout* t = timeout_list->data;
|
||||
struct timespec cur_time;
|
||||
struct timespec next_timeout2 = { .tv_sec=next_timeout.tv_sec, .tv_nsec=next_timeout.tv_usec*1000 };
|
||||
clock_gettime(CLOCK_MONOTONIC, &cur_time);
|
||||
@@ -111,7 +121,7 @@ void update_next_timeout()
|
||||
void callback_timeout_expired()
|
||||
{
|
||||
struct timespec cur_time;
|
||||
struct timeout* t;
|
||||
timeout* t;
|
||||
while (timeout_list) {
|
||||
clock_gettime(CLOCK_MONOTONIC, &cur_time);
|
||||
t = timeout_list->data;
|
||||
@@ -133,12 +143,12 @@ void callback_timeout_expired()
|
||||
}
|
||||
|
||||
|
||||
void stop_timeout(const struct timeout* t)
|
||||
void stop_timeout(timeout* t)
|
||||
{
|
||||
// if not in the list, it was deleted in callback_timeout_expired
|
||||
if (g_slist_find(timeout_list, t) || g_hash_table_lookup(multi_timeouts, t)) {
|
||||
if (t->multi_timeout)
|
||||
remove_from_multi_timeout((struct timeout*)t);
|
||||
remove_from_multi_timeout((timeout*)t);
|
||||
timeout_list = g_slist_remove(timeout_list, t);
|
||||
free((void*)t);
|
||||
}
|
||||
@@ -148,7 +158,7 @@ void stop_timeout(const struct timeout* t)
|
||||
void stop_all_timeouts()
|
||||
{
|
||||
while (timeout_list) {
|
||||
struct timeout* t = timeout_list->data;
|
||||
timeout* t = timeout_list->data;
|
||||
if (t->multi_timeout)
|
||||
stop_multi_timeout(t);
|
||||
free(t);
|
||||
@@ -157,7 +167,7 @@ void stop_all_timeouts()
|
||||
}
|
||||
|
||||
|
||||
void add_timeout_intern(int value_msec, int interval_msec, void(*_callback)(), void* arg, struct timeout *t)
|
||||
void add_timeout_intern(int value_msec, int interval_msec, void(*_callback)(), void* arg, timeout *t)
|
||||
{
|
||||
t->interval_msec = interval_msec;
|
||||
t->_callback = _callback;
|
||||
@@ -176,8 +186,8 @@ void add_timeout_intern(int value_msec, int interval_msec, void(*_callback)(), v
|
||||
|
||||
gint compare_timeouts(gconstpointer t1, gconstpointer t2)
|
||||
{
|
||||
return compare_timespecs(&((const struct timeout*)t1)->timeout_expires,
|
||||
&((const struct timeout*)t2)->timeout_expires);
|
||||
return compare_timespecs(&((timeout*)t1)->timeout_expires,
|
||||
&((timeout*)t2)->timeout_expires);
|
||||
}
|
||||
|
||||
|
||||
@@ -232,11 +242,11 @@ struct timespec add_msec_to_timespec(struct timespec ts, int msec)
|
||||
}
|
||||
|
||||
|
||||
int align_with_existing_timeouts(struct timeout *t)
|
||||
int align_with_existing_timeouts(timeout *t)
|
||||
{
|
||||
GSList* it = timeout_list;
|
||||
while (it) {
|
||||
struct timeout* t2 = it->data;
|
||||
timeout* t2 = it->data;
|
||||
if (t2->interval_msec > 0) {
|
||||
if (t->interval_msec % t2->interval_msec == 0 || t2->interval_msec % t->interval_msec == 0) {
|
||||
if (multi_timeouts == 0)
|
||||
@@ -256,10 +266,10 @@ int align_with_existing_timeouts(struct timeout *t)
|
||||
}
|
||||
|
||||
|
||||
int calc_multi_timeout_interval(struct multi_timeout_handler* mth)
|
||||
int calc_multi_timeout_interval(multi_timeout_handler* mth)
|
||||
{
|
||||
GSList* it = mth->timeout_list;
|
||||
struct timeout* t = it->data;
|
||||
timeout* t = it->data;
|
||||
int min_interval = t->interval_msec;
|
||||
it = it->next;
|
||||
while (it) {
|
||||
@@ -272,12 +282,12 @@ int calc_multi_timeout_interval(struct multi_timeout_handler* mth)
|
||||
}
|
||||
|
||||
|
||||
void create_multi_timeout(struct timeout* t1, struct timeout* t2)
|
||||
void create_multi_timeout(timeout* t1, timeout* t2)
|
||||
{
|
||||
struct multi_timeout* mt1 = malloc(sizeof(struct multi_timeout));
|
||||
struct multi_timeout* mt2 = malloc(sizeof(struct multi_timeout));
|
||||
struct multi_timeout_handler* mth = malloc(sizeof(struct multi_timeout_handler));
|
||||
struct timeout* real_timeout = malloc(sizeof(struct timeout));
|
||||
multi_timeout* mt1 = malloc(sizeof(multi_timeout));
|
||||
multi_timeout* mt2 = malloc(sizeof(multi_timeout));
|
||||
multi_timeout_handler* mth = malloc(sizeof(multi_timeout_handler));
|
||||
timeout* real_timeout = malloc(sizeof(timeout));
|
||||
|
||||
mth->timeout_list = 0;
|
||||
mth->timeout_list = g_slist_prepend(mth->timeout_list, t1);
|
||||
@@ -299,17 +309,17 @@ void create_multi_timeout(struct timeout* t1, struct timeout* t2)
|
||||
}
|
||||
|
||||
|
||||
void append_multi_timeout(struct timeout* t1, struct timeout* t2)
|
||||
void append_multi_timeout(timeout* t1, timeout* t2)
|
||||
{
|
||||
if (t2->multi_timeout) {
|
||||
// swap t1 and t2 such that t1 is the multi timeout
|
||||
struct timeout* tmp = t2;
|
||||
timeout* tmp = t2;
|
||||
t2 = t1;
|
||||
t1 = tmp;
|
||||
}
|
||||
|
||||
struct multi_timeout* mt = malloc(sizeof(struct multi_timeout));
|
||||
struct multi_timeout_handler* mth = g_hash_table_lookup(multi_timeouts, t1);
|
||||
multi_timeout* mt = malloc(sizeof(multi_timeout));
|
||||
multi_timeout_handler* mth = g_hash_table_lookup(multi_timeouts, t1);
|
||||
|
||||
mth->timeout_list = g_slist_prepend(mth->timeout_list, t2);
|
||||
g_hash_table_insert(multi_timeouts, t2, mth);
|
||||
@@ -320,7 +330,7 @@ void append_multi_timeout(struct timeout* t1, struct timeout* t2)
|
||||
}
|
||||
|
||||
|
||||
void update_multi_timeout_values(struct multi_timeout_handler* mth)
|
||||
void update_multi_timeout_values(multi_timeout_handler* mth)
|
||||
{
|
||||
int interval = calc_multi_timeout_interval(mth);
|
||||
int next_timeout_msec = interval;
|
||||
@@ -331,13 +341,12 @@ void update_multi_timeout_values(struct multi_timeout_handler* mth)
|
||||
GSList* it = mth->timeout_list;
|
||||
struct timespec diff_time;
|
||||
while (it) {
|
||||
struct timeout* t = it->data;
|
||||
struct multi_timeout* mt = t->multi_timeout;
|
||||
mt->count_to_expiration = t->interval_msec / interval;
|
||||
timeout* t = it->data;
|
||||
t->multi_timeout->count_to_expiration = t->interval_msec / interval;
|
||||
timespec_subtract(&diff_time, &t->timeout_expires, &cur_time);
|
||||
int msec_to_expiration = diff_time.tv_sec*1000 + diff_time.tv_nsec/1000000;
|
||||
int count_left = msec_to_expiration / interval + (msec_to_expiration%interval != 0);
|
||||
mt->current_count = mt->count_to_expiration - count_left;
|
||||
t->multi_timeout->current_count = t->multi_timeout->count_to_expiration - count_left;
|
||||
if (msec_to_expiration < next_timeout_msec)
|
||||
next_timeout_msec = msec_to_expiration;
|
||||
it = it->next;
|
||||
@@ -351,16 +360,15 @@ void update_multi_timeout_values(struct multi_timeout_handler* mth)
|
||||
|
||||
void callback_multi_timeout(void* arg)
|
||||
{
|
||||
struct multi_timeout_handler* mth = arg;
|
||||
multi_timeout_handler* mth = arg;
|
||||
struct timespec cur_time;
|
||||
clock_gettime(CLOCK_MONOTONIC, &cur_time);
|
||||
GSList* it = mth->timeout_list;
|
||||
while (it) {
|
||||
struct timeout* t = it->data;
|
||||
struct multi_timeout* mt = t->multi_timeout;
|
||||
if (++mt->current_count >= mt->count_to_expiration) {
|
||||
timeout* t = it->data;
|
||||
if (++t->multi_timeout->current_count >= t->multi_timeout->count_to_expiration) {
|
||||
t->_callback(t->arg);
|
||||
mt->current_count = 0;
|
||||
t->multi_timeout->current_count = 0;
|
||||
t->timeout_expires = add_msec_to_timespec(cur_time, t->interval_msec);
|
||||
}
|
||||
it = it->next;
|
||||
@@ -368,9 +376,9 @@ void callback_multi_timeout(void* arg)
|
||||
}
|
||||
|
||||
|
||||
void remove_from_multi_timeout(struct timeout* t)
|
||||
void remove_from_multi_timeout(timeout* t)
|
||||
{
|
||||
struct multi_timeout_handler* mth = g_hash_table_lookup(multi_timeouts, t);
|
||||
multi_timeout_handler* mth = g_hash_table_lookup(multi_timeouts, t);
|
||||
g_hash_table_remove(multi_timeouts, t);
|
||||
|
||||
mth->timeout_list = g_slist_remove(mth->timeout_list, t);
|
||||
@@ -378,7 +386,7 @@ void remove_from_multi_timeout(struct timeout* t)
|
||||
t->multi_timeout = 0;
|
||||
|
||||
if (g_slist_length(mth->timeout_list) == 1) {
|
||||
struct timeout* last_timeout = mth->timeout_list->data;
|
||||
timeout* last_timeout = mth->timeout_list->data;
|
||||
free(last_timeout->multi_timeout);
|
||||
last_timeout->multi_timeout = 0;
|
||||
g_hash_table_remove(multi_timeouts, last_timeout);
|
||||
@@ -398,12 +406,12 @@ void remove_from_multi_timeout(struct timeout* t)
|
||||
}
|
||||
|
||||
|
||||
void stop_multi_timeout(struct timeout* t)
|
||||
void stop_multi_timeout(timeout* t)
|
||||
{
|
||||
struct multi_timeout_handler* mth = g_hash_table_lookup(multi_timeouts, t);
|
||||
multi_timeout_handler* mth = g_hash_table_lookup(multi_timeouts, t);
|
||||
g_hash_table_remove(multi_timeouts, mth->parent_timeout);
|
||||
while (mth->timeout_list) {
|
||||
struct timeout* t = mth->timeout_list->data;
|
||||
timeout* t = mth->timeout_list->data;
|
||||
mth->timeout_list = g_slist_remove(mth->timeout_list, t);
|
||||
g_hash_table_remove(multi_timeouts, t);
|
||||
free(t);
|
||||
|
||||
@@ -25,30 +25,36 @@ extern GSList* timeout_list;
|
||||
extern struct timeval next_timeout;
|
||||
|
||||
|
||||
struct timeout {
|
||||
int interval_msec;
|
||||
struct timespec timeout_expires;
|
||||
void (*_callback)(void*);
|
||||
void* arg;
|
||||
void* multi_timeout;
|
||||
};
|
||||
typedef struct _timeout timeout;
|
||||
|
||||
|
||||
// timer functions
|
||||
/** 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 **/
|
||||
const struct timeout* add_timeout(int value_msec, int interval_msec, void (*_callback)(void*), void* arg);
|
||||
/**
|
||||
* Single shot timer (i.e. timer with interval_msec == 0) are deleted automatically as soon as they expire
|
||||
* i.e. you do not need to stop them, however it is safe to call stop_timeout for these timers.
|
||||
* Periodic timeouts are aligned to each other whenever possible, i.e. one interval_msec is an
|
||||
* integral multiple of the other.
|
||||
**/
|
||||
|
||||
void change_timeout(const struct timeout* t, int value_msec, int interval_msec, void (*_callback)(void*), void* arg);
|
||||
/** 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
|
||||
**/
|
||||
timeout* add_timeout(int value_msec, int interval_msec, void (*_callback)(void*), void* arg);
|
||||
|
||||
/** changes timeout 't'. If timeout 't' does not exist, nothing happens **/
|
||||
void change_timeout(timeout* t, int value_msec, int interval_msec, void (*_callback)(void*), void* arg);
|
||||
|
||||
/** stops the timeout 't' **/
|
||||
void stop_timeout(const struct 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();
|
||||
|
||||
/** Callback of all expired timeouts **/
|
||||
void callback_timeout_expired();
|
||||
|
||||
#endif // TIMER_H
|
||||
|
||||
@@ -146,7 +146,21 @@ int window_get_monitor (Window win)
|
||||
|
||||
int window_is_iconified (Window win)
|
||||
{
|
||||
return (IconicState == get_property32(win, server.atom.WM_STATE, server.atom.WM_STATE));
|
||||
if (IconicState == get_property32(win, server.atom.WM_STATE, server.atom.WM_STATE)) {
|
||||
// openbox sets on shaded windows the IconicState, however we do not consider these windows iconified
|
||||
Atom *at;
|
||||
int count, i;
|
||||
at = server_get_property (win, server.atom._NET_WM_STATE, XA_ATOM, &count);
|
||||
for (i = 0; i < count; i++) {
|
||||
if (at[i] == server.atom._NET_WM_STATE_SHADED) {
|
||||
XFree(at);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
XFree(at);
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user