Class: WMCtrl
- Inherits:
-
Object
- Object
- WMCtrl
- Includes:
- Windows::Structures
- Defined in:
- lib/windows/engines/wmctrl.rb
Instance Method Summary collapse
- #action(*args) ⇒ Object
- #active_window ⇒ Object
- #desktops ⇒ Object
- #find_desktop(id) ⇒ Object
- #find_window(id) ⇒ Object
- #register_window(&block) ⇒ Object
- #spawn_window(command) ⇒ Object
- #windows ⇒ Object
Instance Method Details
#action(*args) ⇒ Object
7 8 9 10 |
# File 'lib/windows/engines/wmctrl.rb', line 7 def action(*args) action_window(*args) pause end |
#active_window ⇒ Object
45 46 47 |
# File 'lib/windows/engines/wmctrl.rb', line 45 def active_window windows.find(&:active) end |
#desktops ⇒ Object
26 27 28 29 |
# File 'lib/windows/engines/wmctrl.rb', line 26 def desktops list = list_desktops.map {|d| Desktop.new(d[:id], d[:workarea]) } Collection.new(list) end |
#find_desktop(id) ⇒ Object
49 50 51 |
# File 'lib/windows/engines/wmctrl.rb', line 49 def find_desktop(id) desktops.find {|d| d.id == id} end |
#find_window(id) ⇒ Object
41 42 43 |
# File 'lib/windows/engines/wmctrl.rb', line 41 def find_window(id) windows.find{ |w| w.id == id } end |
#register_window(&block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/windows/engines/wmctrl.rb', line 12 def register_window(&block) before = windows block.call # wait until windows list refresh after = loop do pause after = windows if after.ids != before.ids break after - before end end end |
#spawn_window(command) ⇒ Object
53 54 55 56 57 58 59 60 |
# File 'lib/windows/engines/wmctrl.rb', line 53 def spawn_window(command) register_window do pid = Process.spawn(command, :out => :close, :err => :close) Process.detach(pid) end rescue Errno::ENOENT raise "Failed to create window with command: #{command}. Maybe a typo?" end |
#windows ⇒ Object
31 32 33 34 35 36 37 38 39 |
# File 'lib/windows/engines/wmctrl.rb', line 31 def windows list = list_windows(true).map do |w| # wmctrl mark default desktop as -1 desktop_id = w[:desktop].abs desktop = find_desktop(desktop_id) Window.new(w[:id], w[:title], desktop, *w[:geometry], w[:active]) end.sort_by(&:id) Collection.new(list) end |