Archive of RubyForge sup-devel mailing list
 help / color / mirror / Atom feed
From: Eric Sherman <hyperbolist@gmail.com>
To: sup-devel <sup-devel@rubyforge.org>
Subject: [sup-devel] [PATCH] idle and unidle updates
Date: Wed, 13 Jan 2010 08:56:44 -0500	[thread overview]
Message-ID: <1263390213-sup-2608@changeling.local> (raw)

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


             reply	other threads:[~2010-01-13 13:57 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-01-13 13:56 Eric Sherman [this message]
2010-01-14 14:22 ` William Morgan
2010-01-14 14:31   ` Eric Sherman

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1263390213-sup-2608@changeling.local \
    --to=hyperbolist@gmail.com \
    --cc=sup-devel@rubyforge.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox