]> gitweb.fluxo.info Git - awesompd.git/commitdiff
Add support for global keybindings
authorAlexander Yakushev <yakushev.alex@gmail.com>
Wed, 7 Dec 2011 18:35:23 +0000 (20:35 +0200)
committerAlexander Yakushev <yakushev.alex@gmail.com>
Wed, 7 Dec 2011 18:35:23 +0000 (20:35 +0200)
See rcsample.lua and wikipage for instructions

awesompd.lua
jamendo.lua
rcsample.lua

index 97c3722dd349e64bc0210e60f65c8370bbe8b4d9..d88f8d16667efb9db99af486b6a4ea97c13495c6 100644 (file)
@@ -1,7 +1,7 @@
 ---------------------------------------------------------------------------
 -- @author Alexander Yakushev <yakushev.alex@gmail.com>
 -- @copyright 2010-2011 Alexander Yakushev
--- @release v1.1.1
+-- @release v1.1.2
 ---------------------------------------------------------------------------
 
 awesompd = {}
@@ -34,7 +34,7 @@ local keygrabber = keygrabber
 
 -- Debug stuff
 
-local enable_dbg = false
+local enable_dbg = true
 local function dbg (...)
    if enable_dbg then
       print(...)
@@ -248,18 +248,43 @@ end
 -- Function that registers buttons on the widget.
 function awesompd:register_buttons(buttons)
    widget_buttons = {}
+   self.global_bindings = {}
    for b=1,table.getn(buttons) do
       if type(buttons[b][1]) == "string" then
          mods = { buttons[b][1] }
       else
          mods = buttons[b][1]
       end
-      table.insert(widget_buttons, 
-                   awful.button(mods, buttons[b][2], buttons[b][3]))
+      if type(buttons[b][2]) == "number" then 
+         -- This is a mousebinding, bind it to the widget
+         table.insert(widget_buttons, 
+                      awful.button(mods, buttons[b][2], buttons[b][3]))
+      else 
+         -- This is a global keybinding, remember it for later usage in append_global_keys
+         table.insert(self.global_bindings, awful.key(mods, buttons[b][2], buttons[b][3]))
+      end
    end
    self.widget:buttons(self.ajoin(widget_buttons))
 end
 
+-- Takes the current table with keybindings and adds widget's own
+-- global keybindings that were specified in register_buttons.
+-- If keytable is not specified, then adds bindings to default
+-- globalkeys table. If specified, then adds bindings to keytable and
+-- returns it.
+function awesompd:append_global_keys(keytable)
+   if keytable then
+      for i = 1, table.getn(self.global_bindings) do
+         keytable = awful.util.table.join(keytable, self.global_bindings[i])
+      end
+      return keytable
+   else
+      for i = 1, table.getn(self.global_bindings) do
+         globalkeys = awful.util.table.join(globalkeys, self.global_bindings[i])
+      end
+   end
+end
+
 -- /// Group of mpc command functions ///
 
 -- Takes a command to mpc and a hook that is provided with awesompd
index 5a019751e9e0678264ab1108964c16610bc7ad8a..9308dc2de0162bce144741ccf43bc4ca9e7f9155 100644 (file)
@@ -1,7 +1,7 @@
 ---------------------------------------------------------------------------
 -- @author Alexander Yakushev <yakushev.alex@gmail.com>
 -- @copyright 2011 Alexander Yakushev
--- @release v1.1.1
+-- @release v1.1.2
 ---------------------------------------------------------------------------
 
 -- Grab environment
index 30acbb9263f0412f9128c2983bc84b41c67328fb..c5e0364ad027fe7c5a27219663c4174fdd5b346b 100644 (file)
@@ -127,17 +127,22 @@ mysystray = widget({ type = "systray" })
           port = 6600 }
   }
 
-  -- Set the buttons of the widget
+  -- Set the buttons of the widget. Keyboard keys are working in the
+  -- entire Awesome environment. Also look at the line 352.
   musicwidget:register_buttons({ { "", awesompd.MOUSE_LEFT, musicwidget:command_playpause() },
                               { "Control", awesompd.MOUSE_SCROLL_UP, musicwidget:command_prev_track() },
                               { "Control", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_next_track() },
                               { "", awesompd.MOUSE_SCROLL_UP, musicwidget:command_volume_up() },
                               { "", awesompd.MOUSE_SCROLL_DOWN, musicwidget:command_volume_down() },
-                              { "", awesompd.MOUSE_RIGHT, musicwidget:command_show_menu() } })
+                              { "", awesompd.MOUSE_RIGHT, musicwidget:command_show_menu() },
+                               { "", "XF86AudioLowerVolume", musicwidget:command_volume_down() },
+                               { "", "XF86AudioRaiseVolume", musicwidget:command_volume_up() },
+                               { modkey, "Pause", musicwidget:command_playpause() } })
+
   musicwidget:run() -- After all configuration is done, run the widget
 
 -- END OF AWESOMPD WIDGET DECLARATION
--- Don't forget to add the widget to the wibox. It is done on the line 207.
+-- Don't forget to add the widget to the wibox. It is done on the line 216.
 
 mywibox = {}
 mypromptbox = {}
@@ -343,6 +348,9 @@ clientbuttons = awful.util.table.join(
     awful.button({ modkey }, 3, awful.mouse.client.resize))
 
 -- Set keys
+-- Add this line before root.keys(globalkeys).
+musicwidget:append_global_keys()
+
 root.keys(globalkeys)
 -- }}}