Class: Robobot::Window

Inherits:
Object
  • Object
show all
Defined in:
lib/robobot/window.rb

Instance Method Summary collapse

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

#focusObject

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

#geometryObject

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

#hideObject

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

#idObject

Return window id



35
36
37
# File 'lib/robobot/window.rb', line 35

def id
	@window
end

#killObject

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

#nameObject

Return a windows name



40
41
42
# File 'lib/robobot/window.rb', line 40

def name
	return `xdotool getwindowname #{@window}`.chomp
end

#raiseObject

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

#set_size(width, height) ⇒ Object

Set window size



61
62
63
64
# 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

#showObject

Show window



79
80
81
82
# File 'lib/robobot/window.rb', line 79

def show
	`xdotool windowmap #{@window}`
	puts "xdotool windowmap #{@window}" if Robobot.debug
end