1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-11-03 19:37:16 -05:00

Simple output of idle/away

This commit is contained in:
James Booth 2012-11-30 21:26:28 +00:00
parent 846d3f848a
commit 020e516acf
4 changed files with 59 additions and 1 deletions

View File

@ -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])

View File

@ -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)
{

View File

@ -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);

View File

@ -25,6 +25,10 @@
#include <stdlib.h>
#include <string.h>
#ifdef HAVE_LIBXSS
#include <X11/extensions/scrnsaver.h>
#endif
#include <glib.h>
#ifdef HAVE_LIBNOTIFY
#include <libnotify/notify.h>
@ -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)
{