From 020e516acfaaee61ccb52e41d5f9d323e324d625 Mon Sep 17 00:00:00 2001 From: James Booth Date: Fri, 30 Nov 2012 21:26:28 +0000 Subject: [PATCH] Simple output of idle/away --- configure.ac | 4 ++++ src/profanity.c | 28 ++++++++++++++++++++++++++++ src/ui.h | 3 +++ src/windows.c | 25 ++++++++++++++++++++++++- 4 files changed, 59 insertions(+), 1 deletion(-) diff --git a/configure.ac b/configure.ac index ca9d8479..e34ade42 100644 --- a/configure.ac +++ b/configure.ac @@ -47,6 +47,10 @@ AC_CHECK_LIB([notify], [main], [], [AC_MSG_NOTICE([libnotify not found, desktop notifications not supported])]) AC_CHECK_LIB([headunit], [main], [], [AC_MSG_NOTICE([headunit not found, will not be able to run tests])]) +AC_CHECK_LIB([Xss], [main], [], + [AC_MSG_NOTICE([libxss not found, falling back to profanity auto-away])]) +AC_CHECK_LIB([X11], [main], [], + [AC_MSG_NOTICE([libX11 not found, falling back to profanity auto-away])]) # Checks for header files. AC_CHECK_HEADERS([stdlib.h string.h]) diff --git a/src/profanity.c b/src/profanity.c index e36fdd96..bf61ff4b 100644 --- a/src/profanity.c +++ b/src/profanity.c @@ -46,9 +46,13 @@ static log_level_t _get_log_level(char *log_level); static gboolean _process_input(char *inp); +static void _handle_idle_time(void); static void _init(const int disable_tls, char *log_level); static void _shutdown(void); +static gboolean idle = FALSE; +static gboolean away = FALSE; + void prof_run(const int disable_tls, char *log_level) { @@ -67,6 +71,8 @@ prof_run(const int disable_tls, char *log_level) while(ch != '\n') { + _handle_idle_time(); + gdouble elapsed = g_timer_elapsed(timer, NULL); gint remind_period = prefs_get_notify_remind(); @@ -434,6 +440,28 @@ _process_input(char *inp) return result; } +static void +_handle_idle_time() +{ + unsigned long idle_ms = ui_get_desktop_idle(); + if (!idle) { + if (idle_ms >= 5000) { + idle = TRUE; + cons_show("IDLE"); + } + + } else { + if (idle_ms < 5000) { + idle = FALSE; + away = FALSE; + cons_show("BACK"); + } else if ((idle_ms >= 10000) && (!away)) { + away = TRUE; + cons_show("AWAY"); + } + } +} + static void _init(const int disable_tls, char *log_level) { diff --git a/src/ui.h b/src/ui.h index 0edcb2ab..e8d3e44d 100644 --- a/src/ui.h +++ b/src/ui.h @@ -76,6 +76,9 @@ void ui_disconnected(void); void ui_handle_special_keys(const int * const ch); void ui_switch_win(const int i); gboolean ui_windows_full(void); +#ifdef HAVE_LIBXSS +unsigned long ui_get_desktop_idle(void); +#endif // create windows void create_title_bar(void); diff --git a/src/windows.c b/src/windows.c index 9ef29d88..03e6b699 100644 --- a/src/windows.c +++ b/src/windows.c @@ -25,6 +25,10 @@ #include #include +#ifdef HAVE_LIBXSS +#include +#endif + #include #ifdef HAVE_LIBNOTIFY #include @@ -66,6 +70,10 @@ static int dirty; // max columns for main windows, never resize below static int max_cols = 0; +#ifdef HAVE_LIBXSS +static Display *display; +#endif + static void _set_current(int index); static void _create_windows(void); static void _cons_splash_logo(void); @@ -116,7 +124,9 @@ ui_init(void) status_bar_active(0); create_input_window(); _create_windows(); - +#ifdef HAVE_LIBXSS + display = XOpenDisplay(0); +#endif dirty = TRUE; } @@ -161,6 +171,19 @@ ui_refresh(void) inp_put_back(); } +#ifdef HAVE_LIBXSS +unsigned long +ui_get_desktop_idle(void) +{ + XScreenSaverInfo *info = XScreenSaverAllocInfo(); + XScreenSaverQueryInfo(display, DefaultRootWindow(display), info); + unsigned long result = info->idle; + XFree(info); + + return result; +} +#endif + void ui_close(void) {