Class | SSHMenu::GeoGrabber |
In: |
lib/sshmenu.rb
(Git)
|
Parent: | Object |
The SSHMenu::GeoGrabber class wraps the external ‘xwininfo’ command to ‘grab’ the geometry of a running window. The user would typically press ‘Test’ on the Edit Host dialog (SSHMenu::HostDialog) to pop up a window; size and position the window; and then ‘Grab’ to populate the ‘Geometry’ text entry.
Called from SSHMenu::HostDialog#add_geometry_input to determine whether the ‘Grab’ button should be enabled. Returns true if xwininfo is available and false otherwise.
# File lib/sshmenu.rb, line 2695 def GeoGrabber.can_grab? @@xwininfo ||= nil if @@xwininfo.nil? @@xwininfo = ENV['PATH'].split(':').collect { |d| d + '/xwininfo' }.find { |p| File.executable?(p) } end return !@@xwininfo.nil? end
This method is the main entry point for the class. It takes no arguments and yields a geometry string on success. The external ‘xwininfo’ program is used to retrieve the geometry details of a selected window.
# File lib/sshmenu.rb, line 2712 def GeoGrabber.grab # :yields: geometry return unless can_grab? `#{@@xwininfo}`.each_line do |l| if l.match(/-geometry\s+([\d+x-]+)/) yield $1 end end end