Class: Robobot::Window
- Inherits:
-
Object
- Object
- Robobot::Window
- Defined in:
- lib/robobot/window.rb
Instance Method Summary collapse
-
#focus ⇒ Object
Focus the window.
-
#geometry ⇒ Object
Return window geometry.
-
#hide ⇒ Object
Hide window.
-
#id ⇒ Object
Return window id.
-
#initialize(name_or_pid) ⇒ Window
constructor
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.
-
#kill ⇒ Object
Kill window.
-
#name ⇒ Object
Return a windows name.
-
#raise ⇒ Object
Raise window to the front.
-
#set_position(x, y) ⇒ Object
Set window position.
-
#set_size(width, height) ⇒ Object
Set window size.
-
#show ⇒ Object
Show window.
Constructor Details
#initialize(name_or_pid) ⇒ Window
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
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# 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 |
Instance Method Details
#focus ⇒ Object
Focus the window
91 92 93 94 95 |
# 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 ⇒ Object
Return window geometry
45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# 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 ⇒ Object
Hide window
73 74 75 76 |
# File 'lib/robobot/window.rb', line 73 def hide `xdotool windowunmap #{@window}` puts "xdotool windowunmap #{@window}" if Robobot.debug end |
#id ⇒ Object
Return window id
35 36 37 |
# File 'lib/robobot/window.rb', line 35 def id @window end |
#kill ⇒ Object
Kill window
98 99 100 101 |
# File 'lib/robobot/window.rb', line 98 def kill `xdotool windowkill #{@window}` puts "xdotool windowkill #{@window}" if Robobot.debug end |
#name ⇒ Object
Return a windows name
40 41 42 |
# File 'lib/robobot/window.rb', line 40 def name return `xdotool getwindowname #{@window}`.chomp end |
#raise ⇒ Object
Raise window to the front
85 86 87 88 |
# File 'lib/robobot/window.rb', line 85 def raise `xdotool windowraise #{@window}` puts "xdotool windowraise #{@window}" if Robobot.debug end |
#set_position(x, y) ⇒ Object
Set window position
67 68 69 70 |
# 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 |