Quick launch bar

From awesome
(Redirected from Quick launch bar widget)
Jump to: navigation, search
Time machine.pngThis page contains version-specific content
Code or instructions listed here may not work for all versions of Awesome.
You can help the community by creating pages for other versions.
Proven working in: 3.4.x
Pages for other versions: 3.5

Description[edit]

Here is a widget that allows you to put application shortcuts on your taskbar.

An example of how the widget might be looking. Launchbar is next to taglist.

Though it is not as dynamic as in Gnome or KDE (you cannot just drag-and-drop a shortcut on the panel), you still don't have to modify your config every time you want to add new shortcut. The widget uses the folder which you specify to find all *.desktop files in it and show them on the taskbar. .desktop format was picked so former Gnome\KDE users could just specify their /home/username/Desktop folder and all the shortcuts from there would appear on the panel.

.desktop file consists of key=value pairs separated by new lines. Here is the example of calculator.desktop file

 [Desktop Entry]
 Name=Calculator
 Exec=gcalctool
 Icon=/usr/share/icons/gnome/24x24/apps/calc.png
 Position=1
 #and so on

It is very simple, it contains the name of application (Name), command to run it (Exec), icon to show on the taskbar (Icon) and it's position relatively to other shortcuts. Widget only uses three fields: Exec, Icon and Position (optional), so you can just write a text file with these fields and save it as something.desktop.

Note: original .desktop files (that Gnome\KDE use) do not contain the field "Position", you should append it by yourself. Although this field is optional, if you don't specify it the shortcuts will simply be appended to the end of the list.

Hint: you don't have to rewrite all positions if you want to insert a shortcuts between two others. You can use non-integer number as Position value for this. For example, if you have two shortcuts with Position 2 and 3 respectively, put in the third shortcut Position=2.5 and it will go between these two.

Howto[edit]

  • First, as I said earlier, you have to create a folder where you will keep your .desktop files. There could be other files, widget would not crash because of them.
  • Open your rc.lua config and put somewhere the following code:
 local util = require('awful.util')
 
 -- Quick launch bar widget BEGINS
 function find_icon(icon_name, icon_dirs)
    if string.sub(icon_name, 1, 1) == '/' then
       if util.file_readable(icon_name) then
          return icon_name
       else
          return nil
       end
    end
    if icon_dirs then
       for _, v in ipairs(icon_dirs) do
          if util.file_readable(v .. "/" .. icon_name) then
             return v .. '/' .. icon_name
          end
       end
    end
    return nil
 end
 
 function getValue(t, key)
    _, _, res = string.find(t, key .. " *= *([^%c]+)%c")
    return res
 end
 
 launchbar = { layout = awful.widget.layout.horizontal.leftright }
 filedir = "/home/unlogic/.config/awesome/launchbar/" -- Specify your folder with shortcuts here
 local items = {}
 local files = io.popen("ls " .. filedir .. "*.desktop")
 for f in files:lines() do
     local t = io.open(f):read("*all")
     table.insert(items, { image = find_icon(getValue(t,"Icon"), 
                                             { "/usr/share/icons/hicolor/22x22/apps" }),
                           command = getValue(t,"Exec"),
                           tooltip = getValue(t,"Name"),
                           position = tonumber(getValue(t,"Position")) or 255 })
 end
 table.sort(items, function(a,b) return a.position < b.position end)
 for i = 1, table.getn(items) do
 --     local txt = launchbar[i].tooltip
    launchbar[i] = awful.widget.launcher(items[i])
 --     local tt = awful.tooltip ({ objects = { launchbar[i] } })
 --     tt:set_text (txt)
 --     tt:set_timeout (0)
 end
 
 -- Quick launch bar widget ENDS
  • Put launchbar on the wibox. For example:
 mywibox[s].widgets = {
   {
      mylauncher,
      mytaglist[s],         
      launchbar,
      s == 1 and mysystray or nil,
      mypromptbox[s],
      layout = awful.widget.layout.horizontal.leftright
   },
   ...
  • That's all. Just reload your awesome and launch bar will appear.

For any questions mail me at yakushev.alex{ear}gmail.com