/* Written by Behdad Esfahbod. * No rights claimed. Use as you wish. */ #define G_LOG_DOMAIN "IdleModule" #include #include #include #include #include void gtk_module_init (gint *argc, gchar ***argv); static const char *idle_action_str; static GTimeVal timeval; static gboolean idle_callback (gpointer data G_GNUC_UNUSED) { if (strstr (idle_action_str, "time")) { GTimeVal timeval2; g_get_current_time (&timeval2); g_debug ("time before idling: %gs", (timeval2.tv_sec - timeval.tv_sec) + ((timeval2.tv_usec - timeval.tv_usec)/(double)1e6)); } if (strstr (idle_action_str, "quit")) gtk_main_quit (); if (strstr (idle_action_str, "kill")) kill (getpid (), SIGINT); return FALSE; } /* Note: argc and arvs are always 0 and NULL */ void gtk_module_init (gint *argc G_GNUC_UNUSED, gchar ***argv G_GNUC_UNUSED) { idle_action_str = getenv ("IDLE_ACTION"); if (idle_action_str == NULL || *idle_action_str == '\0') return; if (strstr (idle_action_str, "recursive") == NULL) unsetenv ("IDLE_ACTION"); g_idle_add_full (G_PRIORITY_LOW, idle_callback, NULL, NULL); g_get_current_time (&timeval); }