1
0
mirror of https://github.com/profanity-im/profanity.git synced 2024-12-04 14:46:46 -05:00

Added comments to ui_get_idle_time

This commit is contained in:
James Booth 2013-01-05 00:38:50 +00:00
parent 83aa2212f5
commit b84051701d

View File

@ -187,8 +187,8 @@ _ui_draw_win_title(void)
g_string_free(version_str, TRUE); g_string_free(version_str, TRUE);
// draw if change
if (g_strcmp0(win_title, new_win_title) != 0) { if (g_strcmp0(win_title, new_win_title) != 0) {
// print to x-window title bar
printf(new_win_title); printf(new_win_title);
if (win_title != NULL) { if (win_title != NULL) {
free(win_title); free(win_title);
@ -200,6 +200,7 @@ _ui_draw_win_title(void)
unsigned long unsigned long
ui_get_idle_time(void) ui_get_idle_time(void)
{ {
// if compiled with libxss, get the x sessions idle time
#ifdef HAVE_LIBXSS #ifdef HAVE_LIBXSS
XScreenSaverInfo *info = XScreenSaverAllocInfo(); XScreenSaverInfo *info = XScreenSaverAllocInfo();
if (info != NULL && display != NULL) { if (info != NULL && display != NULL) {
@ -207,11 +208,16 @@ ui_get_idle_time(void)
unsigned long result = info->idle; unsigned long result = info->idle;
XFree(info); XFree(info);
return result; return result;
// if we couldn't get a screensaverinfo, use profanity interaction idle time
// this may occur if compiled with libxss, but then run in a bare terminal
} else { } else {
gdouble seconds_elapsed = g_timer_elapsed(ui_idle_time, NULL); gdouble seconds_elapsed = g_timer_elapsed(ui_idle_time, NULL);
unsigned long ms_elapsed = seconds_elapsed * 1000.0; unsigned long ms_elapsed = seconds_elapsed * 1000.0;
return ms_elapsed; return ms_elapsed;
} }
// if not compiled with libxss, just use profanity interaction idle time
#else #else
gdouble seconds_elapsed = g_timer_elapsed(ui_idle_time, NULL); gdouble seconds_elapsed = g_timer_elapsed(ui_idle_time, NULL);
unsigned long ms_elapsed = seconds_elapsed * 1000.0; unsigned long ms_elapsed = seconds_elapsed * 1000.0;