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.0.2'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(screen = 0) ⇒ Awesomer

Returns a new instance of Awesomer.



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

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.



47
48
49
# File 'lib/awesomer.rb', line 47

def method_missing(method, *args)
  send(method, args.join(' '))
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.



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

def socket
  @socket
end

Class Method Details

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

Contact the awesome window manager using a block.

Yields:

  • (awesome)


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

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.



64
65
66
# File 'lib/awesomer.rb', line 64

def close
  @socket.close
end

#connectObject

Connect to the awesome window manager socket.



52
53
54
55
56
57
58
59
60
61
# File 'lib/awesomer.rb', line 52

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