Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
|
90e59727e8 | ||
|
3b9dc589ca | ||
|
f3ae47547c | ||
|
4f3c4fa7ae | ||
|
0a58ec27aa |
@ -12,6 +12,7 @@ CACHE_DIR="/tmp/surferlul_awesome"
|
|||||||
mkdir $CACHE_DIR
|
mkdir $CACHE_DIR
|
||||||
echo "Downloading AwesomeWM Configs"
|
echo "Downloading AwesomeWM Configs"
|
||||||
git clone https://github.com/Surferlul/awesome.git $CACHE_DIR
|
git clone https://github.com/Surferlul/awesome.git $CACHE_DIR
|
||||||
|
git --git-dir $CACHE_DIR checkout 4.3
|
||||||
[ -d "$HOME/.config/awesome" ] && echo "Backing up previous configs" && tar cf $CACHE_DIR/previous.tar $HOME/.config/awesome/ && echo "Removing previous configs" && rm -rf $HOME/.config/awesome/
|
[ -d "$HOME/.config/awesome" ] && echo "Backing up previous configs" && tar cf $CACHE_DIR/previous.tar $HOME/.config/awesome/ && echo "Removing previous configs" && rm -rf $HOME/.config/awesome/
|
||||||
echo "Downloading Vicious widgets for AwesomeWM"
|
echo "Downloading Vicious widgets for AwesomeWM"
|
||||||
git -C $CACHE_DIR submodule init vicious
|
git -C $CACHE_DIR submodule init vicious
|
||||||
|
201
menubar/init.lua
201
menubar/init.lua
@ -1,28 +1,22 @@
|
|||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
--- Menubar module, which aims to provide a freedesktop menu alternative.
|
--- Menubar module, which aims to provide a freedesktop menu alternative
|
||||||
--
|
--
|
||||||
-- List of menubar keybindings:
|
-- List of menubar keybindings:
|
||||||
-- ---
|
-- ---
|
||||||
--
|
--
|
||||||
-- <table class='widget_list' border=1>
|
-- * "Left" | "C-j" select an item on the left
|
||||||
-- <tr style='font-weight: bold;'>
|
-- * "Right" | "C-k" select an item on the right
|
||||||
-- <th align='center'>Keybinding</th>
|
-- * "Backspace" exit the current category if we are in any
|
||||||
-- <th align='center'>Description</th>
|
-- * "Escape" exit the current directory or exit menubar
|
||||||
-- </tr> </td></tr>
|
-- * "Home" select the first item
|
||||||
-- <tr><td><kbd>Left</kbd><kbd>C-j</kbd></td><td> select an item on the left </td></tr>
|
-- * "End" select the last
|
||||||
-- <tr><td><kbd>Right</kbd><kbd>C-k</kbd></td><td> select an item on the right </td></tr>
|
-- * "Return" execute the entry
|
||||||
-- <tr><td><kbd>Backspace </kbd></td><td> exit the current category if we are in any </td></tr>
|
-- * "C-Return" execute the command with awful.spawn
|
||||||
-- <tr><td><kbd>Escape </kbd></td><td> exit the current directory or exit menubar </td></tr>
|
-- * "C-M-Return" execute the command in a terminal
|
||||||
-- <tr><td><kbd>Home </kbd></td><td> select the first item </td></tr>
|
|
||||||
-- <tr><td><kbd>End </kbd></td><td> select the last </td></tr>
|
|
||||||
-- <tr><td><kbd>Return </kbd></td><td> execute the entry </td></tr>
|
|
||||||
-- <tr><td><kbd>C-Return </kbd></td><td> execute the command with awful.spawn </td></tr>
|
|
||||||
-- <tr><td><kbd>C-M-Return </kbd></td><td> execute the command in a terminal </td></tr>
|
|
||||||
-- </table>
|
|
||||||
--
|
--
|
||||||
-- @author Alexander Yakushev <yakushev.alex@gmail.com>
|
-- @author Alexander Yakushev <yakushev.alex@gmail.com>
|
||||||
-- @copyright 2011-2012 Alexander Yakushev
|
-- @copyright 2011-2012 Alexander Yakushev
|
||||||
-- @popupmod menubar
|
-- @module menubar
|
||||||
---------------------------------------------------------------------------
|
---------------------------------------------------------------------------
|
||||||
|
|
||||||
-- Grab environment we need
|
-- Grab environment we need
|
||||||
@ -48,11 +42,9 @@ end
|
|||||||
|
|
||||||
--- Menubar normal text color.
|
--- Menubar normal text color.
|
||||||
-- @beautiful beautiful.menubar_fg_normal
|
-- @beautiful beautiful.menubar_fg_normal
|
||||||
-- @param color
|
|
||||||
|
|
||||||
--- Menubar normal background color.
|
--- Menubar normal background color.
|
||||||
-- @beautiful beautiful.menubar_bg_normal
|
-- @beautiful beautiful.menubar_bg_normal
|
||||||
-- @param color
|
|
||||||
|
|
||||||
--- Menubar border width.
|
--- Menubar border width.
|
||||||
-- @beautiful beautiful.menubar_border_width
|
-- @beautiful beautiful.menubar_border_width
|
||||||
@ -60,26 +52,19 @@ end
|
|||||||
|
|
||||||
--- Menubar border color.
|
--- Menubar border color.
|
||||||
-- @beautiful beautiful.menubar_border_color
|
-- @beautiful beautiful.menubar_border_color
|
||||||
-- @param color
|
|
||||||
|
|
||||||
--- Menubar selected item text color.
|
--- Menubar selected item text color.
|
||||||
-- @beautiful beautiful.menubar_fg_focus
|
-- @beautiful beautiful.menubar_fg_normal
|
||||||
-- @param color
|
|
||||||
|
|
||||||
--- Menubar selected item background color.
|
--- Menubar selected item background color.
|
||||||
-- @beautiful beautiful.menubar_bg_focus
|
-- @beautiful beautiful.menubar_bg_normal
|
||||||
-- @param color
|
|
||||||
|
|
||||||
--- Menubar font.
|
|
||||||
-- @beautiful beautiful.menubar_font
|
|
||||||
-- @param[opt=beautiful.font] font
|
|
||||||
|
|
||||||
|
|
||||||
-- menubar
|
-- menubar
|
||||||
local menubar = { menu_entries = {} }
|
local menubar = { menu_entries = {} }
|
||||||
menubar.menu_gen = require("menubar.menu_gen")
|
menubar.menu_gen = require("menubar.menu_gen")
|
||||||
menubar.utils = require("menubar.utils")
|
menubar.utils = require("menubar.utils")
|
||||||
|
local compute_text_width = menubar.utils.compute_text_width
|
||||||
|
|
||||||
|
|
||||||
local current_page = {}
|
local current_page = {}
|
||||||
@ -96,10 +81,6 @@ menubar.cache_entries = true
|
|||||||
-- @tfield[opt=true] boolean show_categories
|
-- @tfield[opt=true] boolean show_categories
|
||||||
menubar.show_categories = true
|
menubar.show_categories = true
|
||||||
|
|
||||||
--- When false will hide results if the current query is empty
|
|
||||||
-- @tfield[opt=true] boolean match_empty
|
|
||||||
menubar.match_empty = true
|
|
||||||
|
|
||||||
--- Specifies the geometry of the menubar. This is a table with the keys
|
--- Specifies the geometry of the menubar. This is a table with the keys
|
||||||
-- x, y, width and height. Missing values are replaced via the screen's
|
-- x, y, width and height. Missing values are replaced via the screen's
|
||||||
-- geometry. However, missing height is replaced by the font size.
|
-- geometry. However, missing height is replaced by the font size.
|
||||||
@ -129,12 +110,13 @@ menubar.right_label = "▶▶ "
|
|||||||
-- @tfield[opt="◀◀"] string left_label
|
-- @tfield[opt="◀◀"] string left_label
|
||||||
menubar.left_label = "◀◀ "
|
menubar.left_label = "◀◀ "
|
||||||
|
|
||||||
-- awful.widget.common.list_update adds spacing of dpi(4) between items.
|
-- awful.widget.common.list_update adds three times a margin of dpi(4)
|
||||||
-- @tfield number list_spacing
|
-- for each item:
|
||||||
local list_spacing = theme.xresources.apply_dpi(4)
|
-- @tfield number list_interspace
|
||||||
|
local list_interspace = theme.xresources.apply_dpi(4) * 3
|
||||||
|
|
||||||
--- Allows user to specify custom parameters for prompt.run function
|
--- Allows user to specify custom parameters for prompt.run function
|
||||||
-- (like colors). This will merge with the default parameters, overriding affected values.
|
-- (like colors).
|
||||||
-- @see awful.prompt
|
-- @see awful.prompt
|
||||||
menubar.prompt_args = {}
|
menubar.prompt_args = {}
|
||||||
|
|
||||||
@ -158,10 +140,10 @@ end
|
|||||||
|
|
||||||
--- Get how the menu item should be displayed.
|
--- Get how the menu item should be displayed.
|
||||||
-- @param o The menu item.
|
-- @param o The menu item.
|
||||||
-- @return item name, item background color, background image, item icon, item args.
|
-- @return item name, item background color, background image, item icon.
|
||||||
local function label(o)
|
local function label(o)
|
||||||
local fg_color = theme.menubar_fg_normal or theme.menu_fg_normal or theme.fg_normal
|
local fg_color = theme.menubar_fg_normal or theme.menu_fg_normal or theme.fg_normal
|
||||||
local bg_color = theme.menubar_tag_bg_normal or theme.menu_tag_bg_normal or theme.tag_bg_normal or "#00000000" -- option to set tag background color different than background color. Needed because the normal way would make tags darker than the background anyways -> was annoying
|
local bg_color = theme.menubar_tag_bg_normal or theme.menu_tag_bg_normal or theme.tag_bg_normal or "#00000000" -- option to ste ttag background color different than background color. Needed because the normal way would make tags darker than the background anyways -> was annoying
|
||||||
if o.focused then
|
if o.focused then
|
||||||
fg_color = theme.menubar_fg_focus or theme.menu_fg_focus or theme.fg_focus
|
fg_color = theme.menubar_fg_focus or theme.menu_fg_focus or theme.fg_focus
|
||||||
bg_color = theme.menubar_bg_focus or theme.menu_bg_focus or theme.bg_focus
|
bg_color = theme.menubar_bg_focus or theme.menu_bg_focus or theme.bg_focus
|
||||||
@ -169,8 +151,7 @@ local function label(o)
|
|||||||
return colortext(gstring.xml_escape(o.name), fg_color),
|
return colortext(gstring.xml_escape(o.name), fg_color),
|
||||||
bg_color,
|
bg_color,
|
||||||
nil,
|
nil,
|
||||||
o.icon,
|
nil-- o.icon
|
||||||
o.icon and {icon_size=20} -- TODO: dirty fix
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function load_count_table()
|
local function load_count_table()
|
||||||
@ -235,11 +216,6 @@ end
|
|||||||
-- @tparam number|screen scr Screen
|
-- @tparam number|screen scr Screen
|
||||||
-- @return table List of items for current page.
|
-- @return table List of items for current page.
|
||||||
local function get_current_page(all_items, query, scr)
|
local function get_current_page(all_items, query, scr)
|
||||||
|
|
||||||
local compute_text_width = function(text, s)
|
|
||||||
return wibox.widget.textbox.get_markup_geometry(text, s, instance.font)['width']
|
|
||||||
end
|
|
||||||
|
|
||||||
scr = get_screen(scr)
|
scr = get_screen(scr)
|
||||||
if not instance.prompt.width then
|
if not instance.prompt.width then
|
||||||
instance.prompt.width = compute_text_width(instance.prompt.prompt, scr)
|
instance.prompt.width = compute_text_width(instance.prompt.prompt, scr)
|
||||||
@ -250,10 +226,9 @@ local function get_current_page(all_items, query, scr)
|
|||||||
if not menubar.right_label_width then
|
if not menubar.right_label_width then
|
||||||
menubar.right_label_width = compute_text_width(menubar.right_label, scr)
|
menubar.right_label_width = compute_text_width(menubar.right_label, scr)
|
||||||
end
|
end
|
||||||
local border_width = theme.menubar_border_width or theme.menu_border_width or 0
|
|
||||||
--local available_space = instance.geometry.width - menubar.right_margin -
|
--local available_space = instance.geometry.width - menubar.right_margin -
|
||||||
-- menubar.right_label_width - menubar.left_label_width -
|
-- menubar.right_label_width - menubar.left_label_width -
|
||||||
-- compute_text_width(query..' ', scr) - instance.prompt.width - border_width * 2
|
-- compute_text_width(query, scr) - instance.prompt.width
|
||||||
-- space character is added as input cursor placeholder
|
-- space character is added as input cursor placeholder
|
||||||
local extra_width = menubar.left_label_width
|
local extra_width = menubar.left_label_width
|
||||||
local subtracted = false
|
local subtracted = false
|
||||||
@ -263,13 +238,13 @@ local function get_current_page(all_items, query, scr)
|
|||||||
current_page = {}
|
current_page = {}
|
||||||
for i, item in ipairs(all_items) do
|
for i, item in ipairs(all_items) do
|
||||||
item.width = item.width or (
|
item.width = item.width or (
|
||||||
compute_text_width(label(item), scr) +
|
compute_text_width(item.name, scr) +
|
||||||
(item.icon and (item_height + list_spacing) or 0)
|
(item.icon and (item_height + list_interspace) or 0)
|
||||||
) -- TODO: 20 = dirty fix
|
) -- TODO: 20 = dirty fix
|
||||||
local total_height = item_height * math.floor(item.width / menubar.geometry.width + 1)
|
local total_height = item_height * math.floor(item.width / menubar.geometry.width + 1)
|
||||||
if width_sum + total_height > available_space then -- TODO: 20 = dirty fix
|
if width_sum + total_height > available_space then
|
||||||
if current_item < i then
|
if current_item < i then
|
||||||
table.insert(current_page, { name = menubar.right_label, ncon = nil })
|
table.insert(current_page, { name = menubar.right_label, icon = nil })
|
||||||
break
|
break
|
||||||
end
|
end
|
||||||
current_page = { { name = menubar.left_label, icon = nil }, item, }
|
current_page = { { name = menubar.left_label, icon = nil }, item, }
|
||||||
@ -336,46 +311,38 @@ local function menulist_update(scr)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- Add the applications according to their name and cmdline
|
-- Add the applications according to their name and cmdline
|
||||||
local add_entry = function(entry)
|
for _, v in ipairs(menubar.menu_entries) do
|
||||||
entry.focused = false
|
v.focused = false
|
||||||
if not current_category or entry.category == current_category then
|
if not current_category or v.category == current_category then
|
||||||
|
|
||||||
-- check if the query matches either the name or the commandline
|
-- check if the query matches either the name or the commandline
|
||||||
-- of some entry
|
-- of some entry
|
||||||
if string.match(entry.name, pattern)
|
if string.match(v.name, pattern)
|
||||||
or string.match(entry.cmdline, pattern) then
|
or string.match(v.cmdline, pattern) then
|
||||||
|
|
||||||
entry.weight = 0
|
v.weight = 0
|
||||||
entry.prio = PRIO_NONE
|
v.prio = PRIO_NONE
|
||||||
|
|
||||||
-- get use count from count_table if present
|
-- get use count from count_table if present
|
||||||
-- and use it as weight
|
-- and use it as weight
|
||||||
if string.len(pattern) > 0 and count_table[entry.name] ~= nil then
|
if string.len(pattern) > 0 and count_table[v.name] ~= nil then
|
||||||
entry.weight = tonumber(count_table[entry.name])
|
v.weight = tonumber(count_table[v.name])
|
||||||
end
|
end
|
||||||
|
|
||||||
-- check for prefix match
|
-- check for prefix match
|
||||||
if string.match(entry.name, "^" .. pattern)
|
if string.match(v.name, "^" .. pattern)
|
||||||
or string.match(entry.cmdline, "^" .. pattern) then
|
or string.match(v.cmdline, "^" .. pattern) then
|
||||||
-- increase default priority
|
-- increase default priority
|
||||||
entry.prio = PRIO_NONE + 1
|
v.prio = PRIO_NONE + 1
|
||||||
else
|
else
|
||||||
entry.prio = PRIO_NONE
|
v.prio = PRIO_NONE
|
||||||
end
|
end
|
||||||
|
|
||||||
table.insert (command_list, entry)
|
table.insert (command_list, v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- Add entries if required
|
|
||||||
if query ~= "" or menubar.match_empty then
|
|
||||||
for _, v in ipairs(menubar.menu_entries) do
|
|
||||||
add_entry(v)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function compare_counts(a, b)
|
local function compare_counts(a, b)
|
||||||
if a.prio == b.prio then
|
if a.prio == b.prio then
|
||||||
return a.weight > b.weight
|
return a.weight > b.weight
|
||||||
@ -407,7 +374,6 @@ end
|
|||||||
|
|
||||||
--- Refresh menubar's cache by reloading .desktop files.
|
--- Refresh menubar's cache by reloading .desktop files.
|
||||||
-- @tparam[opt] screen scr Screen.
|
-- @tparam[opt] screen scr Screen.
|
||||||
-- @staticfct menubar.refresh
|
|
||||||
function menubar.refresh(scr)
|
function menubar.refresh(scr)
|
||||||
scr = get_screen(scr or awful.screen.focused() or 1)
|
scr = get_screen(scr or awful.screen.focused() or 1)
|
||||||
menubar.menu_gen.generate(function(entries)
|
menubar.menu_gen.generate(function(entries)
|
||||||
@ -431,35 +397,36 @@ local function prompt_keypressed_callback(mod, key, comm)
|
|||||||
current_item = current_item + 1
|
current_item = current_item + 1
|
||||||
return true
|
return true
|
||||||
elseif key == "Left" or key == "Right" then
|
elseif key == "Left" or key == "Right" then
|
||||||
local tmp_sum = 0
|
local tmp_sum = 0
|
||||||
local index = nil
|
local index = nil
|
||||||
local index_gen = function(tbl)
|
local index_gen = function(tbl)
|
||||||
local idx = {}
|
local idx = {}
|
||||||
for k,v in pairs(tbl) do
|
for k,v in pairs(tbl) do
|
||||||
idx[v] = k
|
idx[v] = k
|
||||||
|
end
|
||||||
|
return idx
|
||||||
end
|
end
|
||||||
return idx
|
if current_pagqe[1]["name"] == menubar.left_label then
|
||||||
end
|
tmp_sum = 1
|
||||||
if current_page[1]["name"] == menubar.left_label then
|
if key == "Left" then
|
||||||
tmp_sum = 1
|
if not index then
|
||||||
if key == "Left" then
|
index = index_gen(current_page)
|
||||||
if not index then
|
end
|
||||||
index = index_gen(current_page)
|
tmp_sum = #current_page - index[shownitems[current_item]]
|
||||||
end
|
end
|
||||||
tmp_sum = #current_page - index[shownitems[current_item]]
|
elseif key == "Left" then
|
||||||
end
|
tmp_sum = tmp_sum + 1
|
||||||
elseif key == "Left" then
|
end
|
||||||
tmp_sum = #current_page - current_item
|
tmp_sum = tmp_sum + 1
|
||||||
end
|
if current_page[#current_page]["name"] == menubar.right_label and key == "Right" then
|
||||||
tmp_sum = tmp_sum + 1
|
if not index then
|
||||||
if current_page[#current_page]["name"] == menubar.right_label and key == "Right" then
|
index = index_gen(current_page)
|
||||||
if not index then
|
end
|
||||||
index = index_gen(current_page)
|
tmp_sum = index[shownitems[current_item]]
|
||||||
end
|
end
|
||||||
tmp_sum = index[shownitems[current_item]]
|
current_item = current_item + (#current_page - tmp_sum) * (key == "Right" and 1 or -1)
|
||||||
end
|
return true
|
||||||
current_item = current_item + (#current_page - tmp_sum) * (key == "Right" and 1 or -1)
|
|
||||||
return true
|
|
||||||
elseif key == "BackSpace" then
|
elseif key == "BackSpace" then
|
||||||
if comm == "" and current_category then
|
if comm == "" and current_category then
|
||||||
current_category = nil
|
current_category = nil
|
||||||
@ -494,14 +461,12 @@ end
|
|||||||
|
|
||||||
--- Show the menubar on the given screen.
|
--- Show the menubar on the given screen.
|
||||||
-- @param[opt] scr Screen.
|
-- @param[opt] scr Screen.
|
||||||
-- @staticfct menubar.show
|
|
||||||
function menubar.show(scr)
|
function menubar.show(scr)
|
||||||
scr = get_screen(scr or awful.screen.focused() or 1)
|
scr = get_screen(scr or awful.screen.focused() or 1)
|
||||||
local fg_color = theme.menubar_fg_normal or theme.menu_fg_normal or theme.fg_normal
|
local fg_color = theme.menubar_fg_normal or theme.menu_fg_normal or theme.fg_normal
|
||||||
local bg_color = theme.menubar_bg_normal or theme.menu_bg_normal or theme.bg_normal
|
local bg_color = theme.menubar_bg_normal or theme.menu_bg_normal or theme.bg_normal
|
||||||
local border_width = theme.menubar_border_width or theme.menu_border_width or 0
|
local border_width = theme.menubar_border_width or theme.menu_border_width or 0
|
||||||
local border_color = theme.menubar_border_color or theme.menu_border_color
|
local border_color = theme.menubar_border_color or theme.menu_border_color
|
||||||
local font = theme.menubar_font or theme.font or "Monospace 10"
|
|
||||||
|
|
||||||
if not instance then
|
if not instance then
|
||||||
-- Add to each category the name of its key in all_categories
|
-- Add to each category the name of its key in all_categories
|
||||||
@ -520,16 +485,14 @@ function menubar.show(scr)
|
|||||||
fg = fg_color,
|
fg = fg_color,
|
||||||
border_width = border_width,
|
border_width = border_width,
|
||||||
border_color = border_color,
|
border_color = border_color,
|
||||||
font = font,
|
|
||||||
},
|
},
|
||||||
widget = common_args.w,
|
widget = common_args.w,
|
||||||
prompt = awful.widget.prompt(),
|
prompt = awful.widget.prompt(),
|
||||||
query = nil,
|
query = nil,
|
||||||
count_table = nil,
|
count_table = nil,
|
||||||
font = font,
|
|
||||||
}
|
}
|
||||||
local layout = wibox.layout.fixed.vertical()
|
local layout = wibox.layout.fixed.vertical()
|
||||||
layout:add(instance.prompt)
|
layout:add(instance.prompt)
|
||||||
layout:add(instance.widget)
|
layout:add(instance.widget)
|
||||||
instance.wibox:set_widget(layout)
|
instance.wibox:set_widget(layout)
|
||||||
end
|
end
|
||||||
@ -546,7 +509,7 @@ function menubar.show(scr)
|
|||||||
local geometry = menubar.geometry
|
local geometry = menubar.geometry
|
||||||
instance.geometry = {x = geometry.x or scrgeom.x,
|
instance.geometry = {x = geometry.x or scrgeom.x,
|
||||||
y = geometry.y or scrgeom.y,
|
y = geometry.y or scrgeom.y,
|
||||||
height = geometry.height or gmath.round(theme.get_font_height(font) * 1.5),
|
height = geometry.height or gmath.round(theme.get_font_height() * 1.5),
|
||||||
width = (geometry.width or scrgeom.width) - border_width * 2}
|
width = (geometry.width or scrgeom.width) - border_width * 2}
|
||||||
instance.wibox:geometry(instance.geometry)
|
instance.wibox:geometry(instance.geometry)
|
||||||
|
|
||||||
@ -554,9 +517,14 @@ function menubar.show(scr)
|
|||||||
current_category = nil
|
current_category = nil
|
||||||
menulist_update(scr)
|
menulist_update(scr)
|
||||||
|
|
||||||
local default_prompt_args = {
|
local prompt_args = menubar.prompt_args or {}
|
||||||
|
|
||||||
|
local tmp = instance.prompt.widget
|
||||||
|
tmp.forced_height = 18
|
||||||
|
|
||||||
|
awful.prompt.run(setmetatable({
|
||||||
prompt = "Run: ",
|
prompt = "Run: ",
|
||||||
textbox = instance.prompt.widget,
|
textbox = tmp,
|
||||||
completion_callback = awful.completion.shell,
|
completion_callback = awful.completion.shell,
|
||||||
history_path = gfs.get_cache_dir() .. "/history_menu",
|
history_path = gfs.get_cache_dir() .. "/history_menu",
|
||||||
done_callback = menubar.hide,
|
done_callback = menubar.hide,
|
||||||
@ -565,17 +533,12 @@ function menubar.show(scr)
|
|||||||
menulist_update(scr)
|
menulist_update(scr)
|
||||||
end,
|
end,
|
||||||
keypressed_callback = prompt_keypressed_callback
|
keypressed_callback = prompt_keypressed_callback
|
||||||
}
|
}, {__index=prompt_args}))
|
||||||
default_prompt_args.textbox.forced_height = 18
|
|
||||||
|
|
||||||
awful.prompt.run(setmetatable(menubar.prompt_args, {__index=default_prompt_args}))
|
|
||||||
|
|
||||||
|
|
||||||
instance.wibox.visible = true
|
instance.wibox.visible = true
|
||||||
end
|
end
|
||||||
|
|
||||||
--- Hide the menubar.
|
--- Hide the menubar.
|
||||||
-- @staticfct menubar.hide
|
|
||||||
function menubar.hide()
|
function menubar.hide()
|
||||||
if instance then
|
if instance then
|
||||||
instance.wibox.visible = false
|
instance.wibox.visible = false
|
||||||
|
@ -58,7 +58,6 @@ menu_gen.all_categories = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
--- Find icons for category entries.
|
--- Find icons for category entries.
|
||||||
-- @staticfct menubar.menu_gen.lookup_category_icons
|
|
||||||
function menu_gen.lookup_category_icons()
|
function menu_gen.lookup_category_icons()
|
||||||
for _, v in pairs(menu_gen.all_categories) do
|
for _, v in pairs(menu_gen.all_categories) do
|
||||||
v.icon = utils.lookup_icon(v.icon_name)
|
v.icon = utils.lookup_icon(v.icon_name)
|
||||||
@ -80,7 +79,6 @@ end
|
|||||||
-- @tparam function callback Will be fired when all menu entries were parsed
|
-- @tparam function callback Will be fired when all menu entries were parsed
|
||||||
-- with the resulting list of menu entries as argument.
|
-- with the resulting list of menu entries as argument.
|
||||||
-- @tparam table callback.entries All menu entries.
|
-- @tparam table callback.entries All menu entries.
|
||||||
-- @staticfct menubar.menu_gen.generate
|
|
||||||
function menu_gen.generate(callback)
|
function menu_gen.generate(callback)
|
||||||
-- Update icons for category entries
|
-- Update icons for category entries
|
||||||
menu_gen.lookup_category_icons()
|
menu_gen.lookup_category_icons()
|
||||||
|
@ -19,6 +19,7 @@ local glib = lgi.GLib
|
|||||||
local w_textbox = require("wibox.widget.textbox")
|
local w_textbox = require("wibox.widget.textbox")
|
||||||
local gdebug = require("gears.debug")
|
local gdebug = require("gears.debug")
|
||||||
local protected_call = require("gears.protected_call")
|
local protected_call = require("gears.protected_call")
|
||||||
|
local gstring = require("gears.string")
|
||||||
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
local unpack = unpack or table.unpack -- luacheck: globals unpack (compatibility with Lua 5.1)
|
||||||
|
|
||||||
local utils = {}
|
local utils = {}
|
||||||
@ -31,7 +32,6 @@ local utils = {}
|
|||||||
-- Options section
|
-- Options section
|
||||||
|
|
||||||
--- Terminal which applications that need terminal would open in.
|
--- Terminal which applications that need terminal would open in.
|
||||||
-- @param[opt="xterm"] string
|
|
||||||
utils.terminal = 'xterm'
|
utils.terminal = 'xterm'
|
||||||
|
|
||||||
--- The default icon for applications that don't provide any icon in
|
--- The default icon for applications that don't provide any icon in
|
||||||
@ -39,7 +39,6 @@ utils.terminal = 'xterm'
|
|||||||
local default_icon = nil
|
local default_icon = nil
|
||||||
|
|
||||||
--- Name of the WM for the OnlyShowIn entry in the .desktop file.
|
--- Name of the WM for the OnlyShowIn entry in the .desktop file.
|
||||||
-- @param[opt="awesome"] string
|
|
||||||
utils.wm_name = "awesome"
|
utils.wm_name = "awesome"
|
||||||
|
|
||||||
-- Maps keys in desktop entries to suitable getter function.
|
-- Maps keys in desktop entries to suitable getter function.
|
||||||
@ -128,11 +127,10 @@ local all_icon_sizes = {
|
|||||||
'16x16'
|
'16x16'
|
||||||
}
|
}
|
||||||
|
|
||||||
--- List of supported icon exts.
|
--- List of supported icon formats.
|
||||||
local supported_icon_file_exts = { png = 1, xpm = 2, svg = 3 }
|
local supported_icon_formats = { png = 1, xpm = 2, svg = 3 }
|
||||||
|
|
||||||
local icon_lookup_path = nil
|
local icon_lookup_path = nil
|
||||||
|
|
||||||
--- Get a list of icon lookup paths.
|
--- Get a list of icon lookup paths.
|
||||||
-- @treturn table A list of directories, without trailing slash.
|
-- @treturn table A list of directories, without trailing slash.
|
||||||
local function get_icon_lookup_path()
|
local function get_icon_lookup_path()
|
||||||
@ -200,7 +198,6 @@ end
|
|||||||
|
|
||||||
--- Remove CR newline from the end of the string.
|
--- Remove CR newline from the end of the string.
|
||||||
-- @param s string to trim
|
-- @param s string to trim
|
||||||
-- @staticfct menubar.utils.rtrim
|
|
||||||
function utils.rtrim(s)
|
function utils.rtrim(s)
|
||||||
if not s then return end
|
if not s then return end
|
||||||
if string.byte(s, #s) == 13 then
|
if string.byte(s, #s) == 13 then
|
||||||
@ -212,34 +209,34 @@ end
|
|||||||
--- Lookup an icon in different folders of the filesystem.
|
--- Lookup an icon in different folders of the filesystem.
|
||||||
-- @tparam string icon_file Short or full name of the icon.
|
-- @tparam string icon_file Short or full name of the icon.
|
||||||
-- @treturn string|boolean Full name of the icon, or false on failure.
|
-- @treturn string|boolean Full name of the icon, or false on failure.
|
||||||
-- @staticfct menubar.utils.lookup_icon_uncached
|
|
||||||
function utils.lookup_icon_uncached(icon_file)
|
function utils.lookup_icon_uncached(icon_file)
|
||||||
if not icon_file or icon_file == "" then
|
if not icon_file or icon_file == "" then
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local icon_file_ext = icon_file:match(".+%.(.*)$")
|
local icon_file_ext = icon_file:match(".*%.(.-)$")
|
||||||
if icon_file:sub(1, 1) == '/' and supported_icon_file_exts[icon_file_ext] then
|
if icon_file:sub(1, 1) == '/' and supported_icon_formats[icon_file_ext] then
|
||||||
-- If the path to the icon is absolute do not perform a lookup [nil if unsupported ext or missing]
|
-- If the path to the icon is absolute and its format is
|
||||||
|
-- supported, do not perform a lookup.
|
||||||
return gfs.file_readable(icon_file) and icon_file or nil
|
return gfs.file_readable(icon_file) and icon_file or nil
|
||||||
else
|
else
|
||||||
-- Look for the requested file in the lookup path
|
|
||||||
for _, directory in ipairs(get_icon_lookup_path()) do
|
for _, directory in ipairs(get_icon_lookup_path()) do
|
||||||
local possible_file = directory .. "/" .. icon_file
|
local directory_file = directory .. "/" .. icon_file
|
||||||
-- Check to see if file exists if requested with a valid extension
|
if supported_icon_formats[icon_file_ext] and
|
||||||
if supported_icon_file_exts[icon_file_ext] and gfs.file_readable(possible_file) then
|
gfs.file_readable(directory_file) then
|
||||||
return possible_file
|
return directory_file
|
||||||
else
|
else
|
||||||
-- Find files with any supported extension if icon specified without, eg: 'firefox'
|
-- Icon is probably specified without path and format,
|
||||||
for ext, _ in pairs(supported_icon_file_exts) do
|
-- like 'firefox'. Try to add supported extensions to
|
||||||
local possible_file_new_ext = possible_file .. "." .. ext
|
-- it and see if such file exists.
|
||||||
if gfs.file_readable(possible_file_new_ext) then
|
for format, _ in pairs(supported_icon_formats) do
|
||||||
return possible_file_new_ext
|
local possible_file = directory_file .. "." .. format
|
||||||
|
if gfs.file_readable(possible_file) then
|
||||||
|
return possible_file
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- No icon found
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -248,7 +245,6 @@ local lookup_icon_cache = {}
|
|||||||
--- Lookup an icon in different folders of the filesystem (cached).
|
--- Lookup an icon in different folders of the filesystem (cached).
|
||||||
-- @param icon Short or full name of the icon.
|
-- @param icon Short or full name of the icon.
|
||||||
-- @return full name of the icon.
|
-- @return full name of the icon.
|
||||||
-- @staticfct menubar.utils.lookup_icon
|
|
||||||
function utils.lookup_icon(icon)
|
function utils.lookup_icon(icon)
|
||||||
if not lookup_icon_cache[icon] and lookup_icon_cache[icon] ~= false then
|
if not lookup_icon_cache[icon] and lookup_icon_cache[icon] ~= false then
|
||||||
lookup_icon_cache[icon] = utils.lookup_icon_uncached(icon)
|
lookup_icon_cache[icon] = utils.lookup_icon_uncached(icon)
|
||||||
@ -259,7 +255,6 @@ end
|
|||||||
--- Parse a .desktop file.
|
--- Parse a .desktop file.
|
||||||
-- @param file The .desktop file.
|
-- @param file The .desktop file.
|
||||||
-- @return A table with file entries.
|
-- @return A table with file entries.
|
||||||
-- @staticfct menubar.utils.parse_desktop_file
|
|
||||||
function utils.parse_desktop_file(file)
|
function utils.parse_desktop_file(file)
|
||||||
local program = { show = true, file = file }
|
local program = { show = true, file = file }
|
||||||
|
|
||||||
@ -356,7 +351,6 @@ end
|
|||||||
-- @tparam function callback Will be fired when all the files were parsed
|
-- @tparam function callback Will be fired when all the files were parsed
|
||||||
-- with the resulting list of menu entries as argument.
|
-- with the resulting list of menu entries as argument.
|
||||||
-- @tparam table callback.programs Paths of found .desktop files.
|
-- @tparam table callback.programs Paths of found .desktop files.
|
||||||
-- @staticfct menubar.utils.parse_dir
|
|
||||||
function utils.parse_dir(dir_path, callback)
|
function utils.parse_dir(dir_path, callback)
|
||||||
|
|
||||||
local function get_readable_path(file)
|
local function get_readable_path(file)
|
||||||
@ -409,8 +403,6 @@ function utils.parse_dir(dir_path, callback)
|
|||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- luacov: disable
|
|
||||||
|
|
||||||
function utils.compute_textbox_width(textbox, s)
|
function utils.compute_textbox_width(textbox, s)
|
||||||
gdebug.deprecate("Use 'width, _ = textbox:get_preferred_size(s)' directly.", {deprecated_in=4})
|
gdebug.deprecate("Use 'width, _ = textbox:get_preferred_size(s)' directly.", {deprecated_in=4})
|
||||||
s = screen[s or mouse.screen]
|
s = screen[s or mouse.screen]
|
||||||
@ -418,13 +410,15 @@ function utils.compute_textbox_width(textbox, s)
|
|||||||
return w
|
return w
|
||||||
end
|
end
|
||||||
|
|
||||||
function utils.compute_text_width(text, s, font)
|
--- Compute text width.
|
||||||
gdebug.deprecate("Use 'width = textbox.get_markup_geometry(text, s, font)['width']'.", {deprecated_in=4})
|
-- @tparam str text Text.
|
||||||
return w_textbox.get_markup_geometry(text, s, font)['width']
|
-- @tparam number|screen s Screen
|
||||||
|
-- @treturn int Text width.
|
||||||
|
function utils.compute_text_width(text, s)
|
||||||
|
local w, _ = w_textbox(gstring.xml_escape(text)):get_preferred_size(s)
|
||||||
|
return w
|
||||||
end
|
end
|
||||||
|
|
||||||
-- luacov: enable
|
|
||||||
|
|
||||||
return utils
|
return utils
|
||||||
|
|
||||||
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|
||||||
|
Loading…
Reference in New Issue
Block a user