about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorhut <hut@lavabit.com>2009-07-19 16:35:19 +0200
committerhut <hut@lavabit.com>2009-07-19 16:35:19 +0200
commitad6460c301cb27c6b57d3d0f30b2674fdc5779a7 (patch)
tree19512781714cd0422db650ac3f896690070c3207
parent252d8f1959095793c783622b0f062439ca08391d (diff)
downloadranger-ad6460c301cb27c6b57d3d0f30b2674fdc5779a7.tar.gz
added doubleclick, with configurable mouseinterval
-rw-r--r--code/cli.rb4
-rw-r--r--code/keys.rb17
-rw-r--r--ranger.conf7
-rwxr-xr-xranger.rb3
4 files changed, 23 insertions, 8 deletions
diff --git a/code/cli.rb b/code/cli.rb
index 60f74e75..3c0f506e 100644
--- a/code/cli.rb
+++ b/code/cli.rb
@@ -73,8 +73,8 @@ module CLI
 	MOUSE_MASK_ON = Ncurses::ALL_MOUSE_EVENTS | Ncurses::REPORT_MOUSE_POSITION
 	MOUSE_MASK_OFF = 0
 
-	def init_mouse
-		Ncurses.mouseinterval( 0 )
+	def init_mouse( interval )
+		Ncurses.mouseinterval( interval )
 		Ncurses.mousemask( MOUSE_MASK_ON, [] )
 	end
 
diff --git a/code/keys.rb b/code/keys.rb
index f553cf24..5916c69c 100644
--- a/code/keys.rb
+++ b/code/keys.rb
@@ -483,7 +483,14 @@ module Fm
 
 		when Option.mouse && '<mouse>'
 			log mouse.bstate
-			if mouse.press3? or mouse.press1?
+			if mouse.press1? or
+				mouse.press3? or
+				mouse.click1? or
+				mouse.click3? or
+				mouse.doubleclick1?
+
+				left = ! (right = mouse.press3? or mouse.click3?)
+
 				if mouse.y == 0
 				elsif mouse.y >= CLI.lines - @bars.size - 1
 				else
@@ -494,26 +501,26 @@ module Fm
 					case mouse.x
 					when ranges[0]
 						descend
-						if mouse.press1?
+						if left
 							@pwd.pos = get_offset( @path[-1], lines ) + mouse.y - 1
 							descend
 						end
 					when ranges[1]
 						descend
-						if mouse.press1?
+						if left
 							@pwd.pos = get_offset( @path[-1], lines ) + mouse.y - 1
 						end
 					when ranges[2]
 						@pwd.pos = get_offset( @path[-1], lines ) + mouse.y - 1
 
-						if mouse.press3?
+						if right or mouse.doubleclick1?
 							@buffer.clear
 							if mouse.ctrl? then press('L') else press('l') end
 						end
 					when ranges[3]
 						@buffer.clear
 						if mouse.ctrl? then press('L') else press('l') end
-						if mouse.press1? and currentfile.dir?
+						if left and currentfile.dir?
 							@pwd.pos = get_offset( @path[-1], lines ) + mouse.y - 1
 						end
 					end
diff --git a/ranger.conf b/ranger.conf
index b6aeaffd..5fcef6bf 100644
--- a/ranger.conf
+++ b/ranger.conf
@@ -26,6 +26,13 @@ Option.wide_bar       = true
 # by default, there are 'default' and 'mono'
 Option.colorscheme    = 'default'
 
+# the time between a mouse button press and release in which
+# a "click" is recognized. A value of 0 turns clicks off.
+# I've noticed a problem with each variant:
+# If value is 0, doubleclicks are not possible
+# If value is >0, there's a short, annoying delay after clicks
+Option.mouse_interval = 200
+
 # ask for a confirmation before deleting things?
 Option.confirm_string = "yes I am!"
 Option.confirm        = true
diff --git a/ranger.rb b/ranger.rb
index bc74982c..5bd71303 100755
--- a/ranger.rb
+++ b/ranger.rb
@@ -45,6 +45,7 @@ opt = {
 	:file_preview           => true,
 	:preview                => true,
 	:mouse                  => true,
+	:mouse_interval         => 200,
 	:colorscheme            => 'default',
 	:cd                     => ARGV.include?('--cd'),
 }
@@ -79,7 +80,7 @@ Signal.trap(Scheduler::UPDATE_SIGNAL) do
 	Fm.refresh
 end
 
-CLI.init_mouse
+CLI.init_mouse( Option.mouse_interval )
 
 begin
 	Fm.initialize( pwd )