#include "color.h"
#include "cursor.h"
#include "compass.h"
+#include "event.h"
/* #include "track.h" */
int current_gc;
int last_dir;
int last_draw_dir;
- guint animate_timer;
+ struct callback *animate_callback;
+ struct event_timeout *animate_timer;
struct point cursor_pnt;
};
}
}
-static gboolean cursor_animate(struct cursor * this)
+static void
+cursor_animate(struct cursor * this)
{
struct point p;
this->current_gc++;
p.x = this->cursor_pnt.x;
p.y = this->cursor_pnt.y;
cursor_draw(this, &p, this->last_dir, this->last_draw_dir, 1);
- return TRUE;
}
struct cursor *
break; // no need to create other GCs if we are not animating
}
}
- if (animate)
- this->animate_timer=g_timeout_add(250, (GSourceFunc)cursor_animate, (gpointer *)this);
+ if (animate) {
+ this->animate_callback=callback_new_1(callback_cast(cursor_animate), this);
+ this->animate_timer=event_add_timeout(250, 1, this->animate_callback);
+ }
this->cursor_pnt.x = 0;
this->cursor_pnt.y = 0;
dbg(2,"ret=%p\n", this);
cursor_destroy(struct cursor *this_)
{
int i;
- if (this_->animate_timer)
- g_source_remove(this_->animate_timer);
- for (i=0;i<NUM_GC;i++)
+
+ callback_destroy(this_->animate_callback);
+ event_remove_timeout(this_->animate_timer);
+ for (i=0;i<NUM_GC;i++) {
if(this_->cursor_gc[i])
graphics_gc_destroy(this_->cursor_gc[i]);
if(this_->cursor_gc2[i])
graphics_gc_destroy(this_->cursor_gc2[i]);
+ }
g_free(this_);
}
event_glib_remove_watch(struct event_watch *ev)
{
GError *error = NULL;
+ if (! ev)
+ return;
g_source_remove(ev->source);
g_io_channel_shutdown(ev->iochan, 0, &error);
g_free(ev);
struct event_timeout {
guint source;
+ struct callback *cb;
};
static gboolean
-event_glib_call_timeout_single(gpointer t)
+event_glib_call_timeout_single(struct event_timeout *ev)
{
- struct callback *cb=t;
- callback_call_0(cb);
+ callback_call_0(ev->cb);
+ g_free(ev);
return FALSE;
}
static gboolean
-event_glib_call_timeout_multi(gpointer t)
+event_glib_call_timeout_multi(struct event_timeout *ev)
{
- struct callback *cb=t;
- callback_call_0(cb);
+ callback_call_0(ev->cb);
return TRUE;
}
event_glib_add_timeout(int timeout, int multi, struct callback *cb)
{
struct event_timeout *ret=g_new0(struct event_timeout, 1);
- ret->source = g_timeout_add(timeout, multi ? (GSourceFunc)event_glib_call_timeout_multi : (GSourceFunc)event_glib_call_timeout_single, (gpointer)cb);
+ ret->cb=cb;
+ ret->source = g_timeout_add(timeout, multi ? (GSourceFunc)event_glib_call_timeout_multi : (GSourceFunc)event_glib_call_timeout_single, (gpointer)ret);
return ret;
}
static void
event_glib_remove_timeout(struct event_timeout *ev)
{
+ if (! ev)
+ return;
g_source_remove(ev->source);
g_free(ev);
}
#include <glib.h>
#include "file.h"
#include "item.h"
+#include "event.h"
+#include "callback.h"
#include "debug.h"
#include "log.h"
int mkdir;
int flush_size;
int flush_time;
- guint timer;
+ struct event_timeout *timer;
+ struct callback *timer_callback;
struct timeval last_flush;
char *filename;
char *filename_ex1;
return (strcmp(this_->filename_ex1, buffer) != 0);
}
-static gboolean
-log_timer(gpointer data)
+static void
+log_timer(struct log *this_)
{
- struct log *this_=data;
struct timeval tv;
int delta;
gettimeofday(&tv, NULL);
dbg(1,"delta=%d flush_time=%d\n", delta, this_->flush_time);
if (this_->flush_time && delta >= this_->flush_time*1000)
log_flush(this_);
- return TRUE;
}
int
ret->flush_time=flush_time->u.num;
if (ret->flush_time) {
dbg(1,"interval %d\n", ret->flush_time*1000);
- ret->timer=g_timeout_add(ret->flush_time*1000, log_timer, ret);
+ ret->timer_callback=callback_new_1(callback_cast(log_timer), ret);
+ ret->timer=event_add_timeout(ret->flush_time*1000, 1, ret->timer_callback);
}
expand_filenames(ret);
if (ret->lazy)
void
log_destroy(struct log *this_)
{
- if (this_->timer)
- g_source_remove(this_->timer);
+ callback_destroy(this_->timer_callback);
+ event_remove_timeout(this_->timer);
log_flush(this_);
log_close(this_);
g_free(this_);
struct menu *destinations;
struct point pressed, last, current;
int button_pressed,moved,popped;
- guint button_timeout, motion_timeout;
+ struct event_timer *button_timeout, *motion_timeout;
+ struct callback *motion_timeout_callback;
int ignore_button;
struct log *textfile_debug_log;
struct pcoord destination;
{
struct navit *this_=data;
popup(this_, 1, &this_->pressed);
- this_->button_timeout=0;
+ this_->button_timeout=NULL;
this_->popped=1;
}
-static gboolean
-navit_handle_button_timeout(void *data)
-{
- callback_call_0((struct callback *)data);
- return FALSE;
-}
-
int
navit_ignore_button(struct navit *this_)
{
this_->moved=0;
this_->popped=0;
if (popup_callback)
- this_->button_timeout=g_timeout_add(500, navit_handle_button_timeout, popup_callback);
+ this_->button_timeout=event_add_timeout(500, 0, popup_callback);
}
if (button == 2)
navit_set_center_screen(this_, p);
} else {
this_->button_pressed=0;
if (this_->button_timeout) {
- g_source_remove(this_->button_timeout);
- this_->button_timeout=0;
+ event_remove_timeout(this_->button_timeout);
+ this_->button_timeout=NULL;
if (! this_->moved && ! transform_within_border(this_->trans, p, border))
navit_set_center_screen(this_, p);
}
if (this_->motion_timeout) {
- g_source_remove(this_->motion_timeout);
- this_->motion_timeout=0;
+ event_remove_timeout(this_->motion_timeout);
+ this_->motion_timeout=NULL;
}
if (this_->moved) {
struct point pt;
}
-static gboolean
-navit_motion_timeout(void *data)
+static void
+navit_motion_timeout(struct navit *this_)
{
- struct navit *this_=data;
int dx, dy;
dx=(this_->current.x-this_->last.x);
graphics_displaylist_draw(this_->gra, this_->displaylist, this_->trans, this_->layout_current, 0);
this_->moved=1;
}
- this_->motion_timeout=0;
+ this_->motion_timeout=NULL;
return FALSE;
}
dy=(p->y-this_->pressed.y);
if (dx < -8 || dx > 8 || dy < -8 || dy > 8) {
if (this_->button_timeout) {
- g_source_remove(this_->button_timeout);
- this_->button_timeout=0;
+ event_remove_timeout(this_->button_timeout);
+ this_->button_timeout=NULL;
}
this_->current=*p;
+ if (! this_->motion_timeout_callback)
+ this_->motion_timeout_callback=callback_new_1(callback_cast(navit_motion_timeout), this_);
if (! this_->motion_timeout)
- this_->motion_timeout=g_timeout_add(100, navit_motion_timeout, this_);
+ this_->motion_timeout=event_add_timeout(100, 0, this_->motion_timeout_callback);
}
}
}
} while (!file_exists(config_file));
g_list_free(list);
+ event_request_system("glib","start");
if (!config_load(config_file, &error)) {
printf(_("Error parsing '%s': %s\n"), config_file, error->message);
exit(1);
printf(_("No instance has been created, exiting\n"));
exit(1);
}
- event_request_system("glib","start");
event_main_loop_run();
return 0;