X-Git-Url: http://git.maemo.org/git/?p=espeaktime;a=blobdiff_plain;f=src%2Fdaemon.c;h=3c6da747d67ec647d5d1832d2c03e36901be3103;hp=3330da098f9b5bdbbc2597b3fe5d74f070e00be1;hb=HEAD;hpb=bb6debe65662306cc7ffa3b86c83b2404299b03f diff --git a/src/daemon.c b/src/daemon.c index 3330da0..3c6da74 100644 --- a/src/daemon.c +++ b/src/daemon.c @@ -1,9 +1,12 @@ #include #include +#include +#include #include #include #include #include +#include "config.h" #include #include @@ -15,11 +18,22 @@ struct app_data { DBusGConnection *bus; LibHalContext *hal; + GConfClient *gconf; gboolean mode_locked; gboolean display_on; + time_t last_press; + unsigned press_count; }; +static void speak_time(struct app_data *app) +{ + struct espeaktime_settings cfg; + cfg_read(app->gconf, &cfg); + cfg_speak(&cfg, FALSE); + cfg_free(&cfg); +} + static void sig_tklock_mode(DBusGProxy *proxy, const char *mode, gpointer user_data) { struct app_data *app = user_data; @@ -32,6 +46,14 @@ static void sig_display_status(DBusGProxy *proxy, const char *status, gpointer u struct app_data *app = user_data; g_debug("sig_display_status [%s]", status); app->display_on = !strcmp(status, MCE_DISPLAY_ON_STRING); + + /* Double-pressing the button at a normal rate will usually result + * in the two ButtonPress events being received before the display_status==on + * event. Check here if that's the case. + */ + if (app->mode_locked && app->display_on && app->press_count > 1 && + time(NULL) - app->last_press <= 1) + speak_time(app); } static void debug_log(const gchar *log_domain, @@ -42,11 +64,17 @@ static void debug_log(const gchar *log_domain, static void power_button(struct app_data *app) { - g_debug("power button"); - if (app->mode_locked && app->display_on) { - int res = system("espeaktime-now.sh"); - g_debug("speak script: %d", res); - } + time_t now; + + time(&now); + if (now - app->last_press > 1) + app->press_count = 0; + app->press_count++; + app->last_press = now; + + g_debug("power button: count=%d", app->press_count); + if (app->mode_locked && app->display_on) + speak_time(app); } /** @@ -157,6 +185,7 @@ int main(int argc, char *argv[]) g_debug("init"); memset(&app, 0, sizeof(app)); + signal(SIGCHLD, SIG_IGN); g_type_init(); loop = g_main_loop_new(NULL, FALSE); @@ -168,6 +197,9 @@ int main(int argc, char *argv[]) return 1; } + app.gconf = gconf_client_get_default(); + g_assert(app.gconf); + if (!init_hal(&app)) return 1;