Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
* [sup-devel] [PATCH] idle and unidle updates
@ 2010-01-13 13:56 Eric Sherman
  2010-01-14 14:22 ` William Morgan
  0 siblings, 1 reply; 3+ messages in thread
From: Eric Sherman @ 2010-01-13 13:56 UTC (permalink / raw)
  To: sup-devel

After talking it over with Rich Lane who suggested I check for idleness 
near the unblocking_getch loop, it made sense to separate it out into its 
own patch.

The :idle and :unidle updates are relayed only once, when transitioning 
from one state to the other.

* Is setting 'main' as the relay sender a problem?
* Is there anything more meaningful to send as the payload than the time of 
the last keystroke?

---
 bin/sup    |   16 ++++++++++++++++
 lib/sup.rb |    3 ++-
 2 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/bin/sup b/bin/sup
index 19b2a87..f4261f4 100755
--- a/bin/sup
+++ b/bin/sup
@@ -260,6 +260,9 @@ begin
     SearchResultsMode.spawn_from_query $opts[:search]
   end
 
+  no_keystrokes_since = Time.now
+  idle = false
+
   until Redwood::exceptions.nonempty? || $die
     c = begin
       Ncurses.nonblocking_getch
@@ -274,9 +277,22 @@ begin
         debug "redrawing screen on sigwinch"
         BufferManager.completely_redraw_screen
       end
+
+      if !idle and Time.now.to_i - no_keystrokes_since.to_i >= ($config[:idle_threshold] || 60)
+        UpdateManager.relay self, :idle, Time.at(no_keystrokes_since)
+        idle = true
+      end
+
       next
     end
 
+    if idle
+      UpdateManager.relay self, :unidle, Time.at(no_keystrokes_since)
+      idle = false
+    end
+
+    no_keystrokes_since = Time.now
+
     if c == 410
       ## this is ncurses's way of telling us it's detected a refresh.
       ## since we have our own sigwinch handler, we don't do anything.
diff --git a/lib/sup.rb b/lib/sup.rb
index b83bbe7..e228772 100644
--- a/lib/sup.rb
+++ b/lib/sup.rb
@@ -230,7 +230,8 @@ else
     :discard_snippets_from_encrypted_messages => false,
     :default_attachment_save_dir => "",
     :sent_source => "sup://sent",
-    :poll_interval => 300
+    :poll_interval => 300,
+    :idle_threshold => 60
   }
   begin
     FileUtils.mkdir_p Redwood::BASE_DIR
-- 
1.6.6
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [sup-devel] [PATCH] idle and unidle updates
  2010-01-13 13:56 [sup-devel] [PATCH] idle and unidle updates Eric Sherman
@ 2010-01-14 14:22 ` William Morgan
  2010-01-14 14:31   ` Eric Sherman
  0 siblings, 1 reply; 3+ messages in thread
From: William Morgan @ 2010-01-14 14:22 UTC (permalink / raw)
  To: sup-devel

Reformatted excerpts from Eric Sherman's message of 2010-01-13:
> After talking it over with Rich Lane who suggested I check for idleness 
> near the unblocking_getch loop, it made sense to separate it out into its 
> own patch.

Yes, I like this even better, with the same caveat as before about the
config option.

> * Is setting 'main' as the relay sender a problem?

I don't think so.

> * Is there anything more meaningful to send as the payload than the time of 
> the last keystroke?

Probably not. Not a big deal either way.

Are you going to send a second patch that makes use of these events to
do the accumulation?
-- 
William <wmorgan-sup@masanjin.net>
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [sup-devel] [PATCH] idle and unidle updates
  2010-01-14 14:22 ` William Morgan
@ 2010-01-14 14:31   ` Eric Sherman
  0 siblings, 0 replies; 3+ messages in thread
From: Eric Sherman @ 2010-01-14 14:31 UTC (permalink / raw)
  To: sup-devel

Excerpts from William Morgan's message of Thu Jan 14 09:22:45 -0500 2010:
> Are you going to send a second patch that makes use of these events to
> do the accumulation?

Yes.  I wanted to wait till this was accepted though since I wasn't sure 
about submitting a patch that depends on another patch.
_______________________________________________
Sup-devel mailing list
Sup-devel@rubyforge.org
http://rubyforge.org/mailman/listinfo/sup-devel


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2010-01-14 14:31 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-01-13 13:56 [sup-devel] [PATCH] idle and unidle updates Eric Sherman
2010-01-14 14:22 ` William Morgan
2010-01-14 14:31   ` Eric Sherman

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox