Class: Awesomer

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

Overview

Awesomer is a ruby library for interacting with the awesome window manager. It replaces the awesome-client distributed with the window manager.

It’s used by either creating a new Awesomer object, connecting, performing actions, and lastly close the connection:

a = Awesomer.new
a.connect
a.tag_view 2
sleep 1
a.tag_view 3
a.close

A better way to handle this is to contact the window manager using a block. Connecting and closing are then handled automatically:

Awesomer.contact do |a|
  a.tag_view 4
  a.spawn :urxvt
  sleep 3
  a.tag_view 5
  a.spawn :urxvt
end

Constant Summary collapse

VERSION =
'1.1.1'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(screen = 0) ⇒ Awesomer

Returns a new instance of Awesomer.



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

def initialize(screen = 0)
  @screen = screen
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args) ⇒ Object

We take all method calls as possible UICB functions.



48
49
50
51
52
53
54
# File 'lib/awesomer.rb', line 48

def method_missing(method, *args)
  if method == :widget_tell && statusbar
    send(method, args.unshift(@statusbar).join(' '))
  else
    send(method, args.join(' '))
  end
end

Instance Attribute Details

#screenObject

Returns the value of attribute screen.



31
32
33
# File 'lib/awesomer.rb', line 31

def screen
  @screen
end

#socketObject

Returns the value of attribute socket.



33
34
35
# File 'lib/awesomer.rb', line 33

def socket
  @socket
end

#statusbarObject

Returns the value of attribute statusbar.



32
33
34
# File 'lib/awesomer.rb', line 32

def statusbar
  @statusbar
end

Class Method Details

.contact(screen = 0) {|awesome| ... } ⇒ Object

Contact the awesome window manager using a block.

Yields:

  • (awesome)


40
41
42
43
44
45
# File 'lib/awesomer.rb', line 40

def self.contact(screen = 0)
  awesome = Awesomer.new(screen)
  awesome.connect
  yield awesome
  awesome.close
end

Instance Method Details

#closeObject

Close connection to the awesome window manager socket.



69
70
71
# File 'lib/awesomer.rb', line 69

def close
  @socket.close
end

#connectObject

Connect to the awesome window manager socket.



57
58
59
60
61
62
63
64
65
66
# File 'lib/awesomer.rb', line 57

def connect
  @socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0)
  path = File.join(ENV['HOME'], ".awesome_ctl.#@screen")
  if File.socket? path
    @socket.connect(Socket.pack_sockaddr_un(path))
  else
    sleep 1
    connect
  end
end