class Robobot::Window
Public Class Methods
new(name_or_pid)
click to toggle source
Gets a window by process name (string) or process id (integer) you may also use :current to use the current active one or use :click to request clicking the window
# File lib/robobot/window.rb, line 17 def initialize name_or_pid if name_or_pid == :current @window = `xdotool getwindowfocus`.chomp elsif name_or_pid == :click @window = `xdotool selectwindow`.chomp elsif name_or_pid.is_a? String @window = `xdotool search #{name_or_pid} | head -1`.chomp elsif name_or_pid.is_a? Integer @window = `xdotool search --pid #{name_or_pid}`.chomp else raise 'Not a valid window value' end if Robobot.debug puts "Window selected: #{@window}" end end
Public Instance Methods
focus()
click to toggle source
Focus the window
# File lib/robobot/window.rb, line 91 def focus # may work better than windowfocus, also switches workspaces `xdotool windowactivate --sync #{@window}` puts "xdotool windowactivate --sync #{@window}" if Robobot.debug end
geometry()
click to toggle source
Return window geometry
# File lib/robobot/window.rb, line 45 def geometry geo = `xdotool getwindowgeometry #{@window}`.chomp.split("\n") xy = geo[1].split(": ")[1].split(" ")[0].split(",") screen = geo[1].split("(")[1].split(": ")[1].split(")")[0] wh = geo[2].split(": ")[1].chomp.split("x") out = { :x => xy[0].to_i, :y => xy[1].to_i, :screen => screen.to_i, :width => wh[0].to_i, :height => wh[1].to_i } return out end
hide()
click to toggle source
Hide window
# File lib/robobot/window.rb, line 73 def hide `xdotool windowunmap #{@window}` puts "xdotool windowunmap #{@window}" if Robobot.debug end
id()
click to toggle source
Return window id
# File lib/robobot/window.rb, line 35 def id @window end
kill()
click to toggle source
Kill window
# File lib/robobot/window.rb, line 98 def kill `xdotool windowkill #{@window}` puts "xdotool windowkill #{@window}" if Robobot.debug end
name()
click to toggle source
Return a windows name
# File lib/robobot/window.rb, line 40 def name return `xdotool getwindowname #{@window}`.chomp end
raise()
click to toggle source
Raise window to the front
# File lib/robobot/window.rb, line 85 def raise `xdotool windowraise #{@window}` puts "xdotool windowraise #{@window}" if Robobot.debug end
set_position(x, y)
click to toggle source
Set window position
# File lib/robobot/window.rb, line 67 def set_position x, y `xdotool windowmove #{@window} #{x} #{y}` puts "xdotool windowmove #{@window} #{x} #{y}" if Robobot.debug end
set_size(width, height)
click to toggle source
Set window size
# File lib/robobot/window.rb, line 61 def set_size width, height `xdotool windowsize #{@window} #{width} #{height}` puts "xdotool windowsize #{@window} #{width} #{height}" if Robobot.debug end
show()
click to toggle source
Show window
# File lib/robobot/window.rb, line 79 def show `xdotool windowmap #{@window}` puts "xdotool windowmap #{@window}" if Robobot.debug end