Use less threads, they're expensive [#9 state:closed]
[amazing.git] / lib / amazing / awesome.rb
blob6f13f78fee2315ff95d932b2de054f032d18a906
1 # Copyright 2008 Dag Odenhall <dag.odenhall@gmail.com>
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
7 #    http://www.apache.org/licenses/LICENSE-2.0
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
15 require 'socket'
17 module Amazing
19   # Communicate with awesome
20   #
21   #   awesome = Awesome.new
22   #   awesome.widget_tell(0, widget_id, "Hello, world")
23   #   awesome = Awesome.new(1)
24   #   awesome.tag_view(0, 3)
25   #   Awesome.new.client_zoom
26   class Awesome
27     attr_accessor :screen, :display
29     def initialize(display=0)
30       @display = display
31     end
33     def method_missing(uicb, screen=0, *args)
34       data = "#{screen} #{uicb} #{args.join(' ')}\n"
35       __setup_socket__
36       @socket.write(data)
37     end
39     private
41     def __setup_socket__
42       @socket = Socket.new(Socket::AF_UNIX, Socket::SOCK_DGRAM, 0)
43       @socket.connect(Socket.sockaddr_un("#{ENV["HOME"]}/.awesome_ctl.#@display"))
44     end
45   end
46 end