From 3f3552f4e224c75cc7c8513bf310c3f272354f31 Mon Sep 17 00:00:00 2001 From: crater2150 Date: Thu, 15 Mar 2012 09:02:06 +0100 Subject: [PATCH] mpd_prompt with modular bindings added --- bindings.lua | 10 +++---- mpd_prompt.lua | 78 ++++++++++++++++++++++++++++++++++++++++++++++++++ rc.lua | 1 + 3 files changed, 83 insertions(+), 6 deletions(-) create mode 100644 mpd_prompt.lua diff --git a/bindings.lua b/bindings.lua index b677136..1d93296 100644 --- a/bindings.lua +++ b/bindings.lua @@ -6,6 +6,7 @@ awful.button({ }, 5, awful.tag.viewprev) )) -- }}} + -- {{{ Key bindings globalkeys = awful.util.table.join( --{{{ Focus and Tags @@ -88,16 +89,13 @@ globalkeys = awful.util.table.join( awful.key({ }, "XF86AudioLowerVolume", function () awful.util.spawn("amixer set Master 2%-")end ), awful.key({ }, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer set Master 2%+")end ), awful.key({ }, "XF86AudioMute", function () awful.util.spawn("amixer set Master toggle") end), - awful.key({ modkey , "Shift" }, "m", function () awful.util.spawn("mpdmenu -a") end), - awful.key({ modkey , "Control" }, "m", function () awful.util.spawn("mpdmenu -t") end), awful.key({ modkey }, "m", function () awful.util.spawn("mpc toggle") end), - awful.key({ modkey }, "n", function () awful.util.spawn("mpc next") end), - awful.key({ modkey , "Shift"}, "n", function () awful.util.spawn("mpc prev") end), + awful.key({ modkey }, ">", function () awful.util.spawn("mpc next") end), + awful.key({ modkey }, "<", function () awful.util.spawn("mpc prev") end), + awful.key({ modkey , "Shift" }, "m", mpd_prompt.grabber), awful.key({ }, "XF86AudioPlay", function () awful.util.spawn("mpc toggle") end), awful.key({ }, "XF86AudioNext", function () awful.util.spawn("mpc next") end), awful.key({ }, "XF86AudioPrev", function () awful.util.spawn("mpc prev") end), - awful.key({ }, "XF86AudioStop", function () awful.util.spawn("mpdmenu -a") end), - awful.key({ modkey , "Control" }, "n", function () awful.util.spawn("mpdmenu -j") end), awful.key({ modkey }, "`", function () teardrop("urxvtc -e ncmpcpp","bottom","center", 0.99, 0.4)end ), --}}} diff --git a/mpd_prompt.lua b/mpd_prompt.lua new file mode 100644 index 0000000..6b241d0 --- /dev/null +++ b/mpd_prompt.lua @@ -0,0 +1,78 @@ +local awful = awful +local obvious = obvious +local naughty = naughty +local keygrabber = keygrabber +local io = io +local pairs = pairs + +local M = {} + +local type = "" +local clear_before = true + +local keymap = {} + +local show, + mpc_play_search + +M.grabber = function() + keygrabber.run(function(mod, key, event) + if event == "release" then return true end + keygrabber.stop() + if keymap[key] then keymap[key]() end + return true + end) +end + +M.artist = function() + type = "artist" + show() +end + +M.album = function() + type = "album" + show() +end + + +M.title = function() + type = "title" + show() +end +M.title = title + +M.replace_on_search = function(bool) + clear_before = bool +end + +M.toggle_replace_on_search = function() + clear_before = not clear_before + if not (naughty == nil) then + naughty.notify({ + text="MPD prompts now " ..( + clear_before and "replace" or "add to" + ).. " the playlist" + }) + end +end + +function show() + obvious.popup_run_prompt.set_prompt_string("Play ".. type .. ":") + obvious.popup_run_prompt.set_run_function(mpc_play_search) + obvious.popup_run_prompt.run_prompt() +end + +function mpc_play_search(s) + if clear_before then awful.util.spawn("mpc clear") end + awful.util.spawn_with_shell("mpc search ".. type .." '" .. s .. "' | mpc add") + awful.util.spawn("mpc play"); +end + +keymap = { + a = M.artist, + A = M.album, + t = M.title, + r = M.toggle_replace_on_search +} + +return M diff --git a/rc.lua b/rc.lua index a24fafb..5fa9e66 100644 --- a/rc.lua +++ b/rc.lua @@ -10,6 +10,7 @@ require("obvious.popup_run_prompt") require("vicious") require("rodentbane.rodentbane") require("aweswt") +mpd_prompt = require("mpd_prompt") MY_PATH = os.getenv("HOME") .. "/.config/awesome/" WALLPATH = MY_PATH .. "walls/"