commit 24b8bb04d4677f5a6ee02cbb97644576a1100ab7
parent 6dbea04dbdf03ad0d49fe50c38104d7ec7f503be
Author: wabu <waeber@inf.fu-berlin.de>
Date: Wed, 13 May 2009 17:24:38 +0200
add 'click' parameter to handle status bar button clicks
add status_button() method to access the underlying Button object
add status_click() method to invoke a button's mouse click handler
remove default RightBarMouseDown event handler in config.yaml
Diffstat:
config.rb | | | 63 | ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++----- |
config.yaml | | | 16 | ++++++---------- |
2 files changed, 64 insertions(+), 15 deletions(-)
diff --git a/config.rb b/config.rb
@@ -205,6 +205,7 @@ class Button < Thread
#
def initialize fs_bar_node, refresh_rate, &button_label
raise ArgumentError, 'block must be given' unless block_given?
+
super(fs_bar_node) do |button|
while true
label =
@@ -294,12 +295,14 @@ def load_config config_file
fs.rbar.clear
unless defined? @status_button_by_name
- @status_button_by_name = {}
+ @status_button_by_name = {}
+ @status_button_by_file = {}
+ @on_click_by_status_button = {}
CONFIG['display']['status'].each_with_index do |hash, position|
name, defn = hash.to_a.first
- # buttons are displayed in the ASCII order of their IXP file names
+ # buttons appear in ASCII order of their IXP file name
file = "#{position}-#{name}"
button = eval(
@@ -308,6 +311,13 @@ def load_config config_file
)
@status_button_by_name[name] = button
+ @status_button_by_file[file] = button
+
+ # mouse click handler
+ @on_click_by_status_button[button] = eval(
+ "lambda {|mouse_button| #{defn['click']} }",
+ TOPLEVEL_BINDING, "#{config_file}:display:status:#{name}:click"
+ )
end
end
@@ -316,16 +326,59 @@ def load_config config_file
end.call
##
+ # Returns the status button associated with the given name.
+ #
+ # ==== Parameters
+ #
+ # [name]
+ # Either the the user-defined name of
+ # the status button or the basename
+ # of the status button's IXP file.
+ #
+ def status_button name
+ @status_button_by_name[name] || @status_button_by_file[name]
+ end
+
+ ##
# Refreshes the content of the status button with the given name.
#
+ # ==== Parameters
+ #
+ # [name]
+ # Either the the user-defined name of
+ # the status button or the basename
+ # of the status button's IXP file.
+ #
def status name
- name = name.sub(/^\d+-/,'')
-
- if button = @status_button_by_name[name]
+ if button = status_button(name)
button.refresh
end
end
+ ##
+ # Invokes the mouse click handler for the given mouse
+ # button on the status button that has the given name.
+ #
+ # ==== Parameters
+ #
+ # [name]
+ # Either the the user-defined name of
+ # the status button or the basename
+ # of the status button's IXP file.
+ #
+ # [mouse_button]
+ # The identification number of
+ # the mouse button (as defined
+ # by X server) that was clicked.
+ #
+ def status_click name, mouse_button
+ if button = status_button(name) and
+ handle = @on_click_by_status_button[button]
+ then
+ handle.call mouse_button.to_i
+ end
+ end
+
# control
%w[key action event].each do |param|
CONFIG['control'][param].each do |name, code|
diff --git a/config.yaml b/config.yaml
@@ -91,10 +91,13 @@ display:
# - <button name>:
# refresh: <number of seconds to wait before refreshing the content>
# content: <Ruby code whose result is displayed as the content>
+ # click: <Ruby code to handle mouse clicks on the status button.
+ # This code has access to a "mouse_button" variable which is
+ # an integer representing the mouse button that was clicked.>
#
# You can refresh a particular status button in Ruby using:
#
- # status("your button name")
+ # status "your button name"
#
# The horizontal order in which these buttons appear on the status
# bar reflects the vertical order in which they are defined below.
@@ -666,15 +669,8 @@ control:
#
LeftBarDND: *LeftBarClick
- RightBarMouseDown: |
- mouse_button, status_id = argv
-
- if mouse_button == '3' # secondary button
- case click_menu %w[refresh], status_id
- when 'refresh' then status(status_id)
- else # TODO: mouse events on status buttons
- end
- end
+ RightBarClick: |
+ status_click *argv.reverse
Unresponsive: |
client_id = argv[0]