From 93b879710bcd65fb31c6d4b26d07570139406aa1 Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Sun, 30 Jul 2017 12:34:20 +0000 Subject: [PATCH] Notify when clicking on launchbar icon --- awesome/command_launcher.lua | 43 ++++++++++++++++++++++++++++++++++++ awesome/launchbar.lua | 11 +++++++-- 2 files changed, 52 insertions(+), 2 deletions(-) create mode 100644 awesome/command_launcher.lua diff --git a/awesome/command_launcher.lua b/awesome/command_launcher.lua new file mode 100644 index 0000000..7618d7e --- /dev/null +++ b/awesome/command_launcher.lua @@ -0,0 +1,43 @@ +-- INSPIRED FROM +--------------------------------------------------------------------------- +-- @author Julien Danjou <julien@danjou.info> +-- @copyright 2008-2009 Julien Danjou +-- @classmod awful.widget.launcher +--------------------------------------------------------------------------- +-- MODIFIED BY +-- thomas forgione + +local setmetatable = setmetatable +local naughty = require('naughty') +local gtable = require("gears.table") +local spawn = require("awful.spawn") +local wbutton = require("awful.widget.button") +local button = require("awful.button") + +local launcher = { mt = {} } + +--- Create a button widget which will launch a command. +-- @param args Standard widget table arguments, plus image for the image path +-- and command for the command to run on click, or either menu to create menu. +-- @return A launcher widget. +function launcher.new(args) + if not args.callback and not args.menu then return end + local w = wbutton(args) + if not w then return end + + local b + if args.callback then + b = gtable.join(w:buttons(), button({}, 1, nil, function () args.callback() end)) + elseif args.menu then + b = gtable.join(w:buttons(), button({}, 1, nil, function () args.menu:toggle() end)) + end + + w:buttons(b) + return w +end + +function launcher.mt:__call(...) + return launcher.new(...) +end + +return setmetatable(launcher, launcher.mt) diff --git a/awesome/launchbar.lua b/awesome/launchbar.lua index 99b5178..89e9b29 100644 --- a/awesome/launchbar.lua +++ b/awesome/launchbar.lua @@ -8,7 +8,8 @@ local naughty = require('naughty') local layout = require("wibox.layout") local util = require("awful.util") -local launcher = require("awful.widget.launcher") +local spawn = require('awful.spawn') +local launcher = require("command_launcher") local launchbar = {} @@ -46,7 +47,13 @@ function launchbar.new(filedir) for f in files:lines() do local t = io.open(f):read("*all") table.insert(items, { image = find_icon(getValue(t,"Icon")), - command = getValue(t,"Exec"), + callback = function () + naughty.notify({ + title = "Starting " .. getValue(t, "Name"), + text = "" + }) + spawn(getValue(t,"Exec")) + end, position = tonumber(getValue(t,"Position")) or 255 }) end table.sort(items, function(a,b) return a.position < b.position end)