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.
26 @log.level = Logger.const_get(@options[:loglevel].upcase)
29 @log.error("Unsupported log level #{@options[:loglevel].inspect}")
30 @log.level = Logger::INFO
34 def stop_process(log=true)
35 Process.kill("SIGINT", File.read("#{ENV["HOME"]}/.amazing/pids/#{@display.display}.pid").to_i)
36 @log.warn("Killed older process") if log
41 scripts = @options[:include]
43 if @options[:autoinclude]
44 scripts << Dir["#{ENV["HOME"]}/.amazing/widgets/*"]
47 scripts.flatten.each do |script|
48 if File.exist?(script)
49 @log.debug("Loading script #{script.inspect}")
52 Widgets.module_eval(File.read(script), script)
54 rescue SyntaxError => e
55 @log.error("Bad syntax in #{script} at line #{e.to_s.scan(/:(\d+)/)}")
59 @log.error("No such widget script #{script.inspect}")
65 @log.debug("Parsing configuration file")
68 @config = Config.new(@options[:config])
71 @log.fatal("Unable to parse configuration file, exiting")
78 @log.debug("Waiting for awesome control socket for display #{@display.display}")
81 Timeout.timeout(30) do
82 sleep 1 until File.exist?("#{ENV["HOME"]}/.awesome_ctl.#{@display.display}")
83 @log.debug("Got socket for display #{@display.display}")
87 @log.fatal("Socket for display #{@display.display} not created within 30 seconds, exiting")
94 path = "#{ENV["HOME"]}/.amazing/pids"
95 FileUtils.makedirs(path)
97 File.open("#{path}/#{@display.display}.pid", "w+") do |f|
103 File.delete("#{ENV["HOME"]}/.amazing/pids/#{@display.display}.pid") rescue Errno::ENOENT
108 @log.fatal("Received SIGINT, exiting")
114 def update_non_interval
115 @config[:awesome].each do |awesome|
116 awesome[:widgets].each do |widget|
117 next if widget[:interval]
119 @threads << Thread.new(awesome, widget) do |awesome, widget|
120 update_widget(awesome[:screen], awesome[:statusbar], widget)
126 def update_widget(screen, statusbar, widget, iteration=0)
127 @log.debug("Updating widget #{widget[:identifier]} of type #{widget[:module]} on screen #{screen}")
130 mod = Widgets.const_get(widget[:module]).new(widget.merge(:iteration => iteration))
132 if widget[:properties].empty?
133 @awesome.widget_tell(screen, statusbar, widget[:identifier], widget[:property], mod.formatize)
136 widget[:properties].each do |property, format|
137 @awesome.widget_tell(screen, statusbar, widget[:identifier], property, mod.formatize(format))
140 rescue WidgetError => e
141 @log.error(widget[:module]) { e.message }
146 @threads.each {|t| t.join }