1
0
Fork 0
mirror of https://github.com/lcpz/awesome-copycats.git synced 2024-12-22 19:22:32 +00:00

freedesktop: some patches

This commit is contained in:
luke bonham 2013-09-22 17:16:20 +02:00
parent 5b527a28f9
commit 7c9196b23e
3 changed files with 48 additions and 22 deletions

View file

@ -113,9 +113,9 @@ Every theme has a colorscheme_.
Blackburn and Dremora use Icons_, be sure to have bitmaps enabled if running under Debian_ or Ubuntu_. Blackburn and Dremora use Icons_, be sure to have bitmaps enabled if running under Debian_ or Ubuntu_.
Freedesktop requires ``/etc/mime.types``, so be sure to have mime-types support installed. Freedesktop uses ``/etc/mime.types``, so be sure to have mime-types support installed.
Freedesktop, eminent and scratchdrop are third-party softwares: **rely on their creators if they cause you issues**. Eminent, freedesktop and scratchdrop are third-party softwares: **rely on their creators if they cause you issues**.
.. _BY-NC-SA: http://creativecommons.org/licenses/by-nc-sa/3.0/ .. _BY-NC-SA: http://creativecommons.org/licenses/by-nc-sa/3.0/
.. _Awesome: http://awesome.naquadah.org/ .. _Awesome: http://awesome.naquadah.org/

View file

@ -7,6 +7,7 @@ local ipairs = ipairs
local awful = require("awful") local awful = require("awful")
local utils = require("freedesktop.utils") local utils = require("freedesktop.utils")
local wibox = require("wibox") local wibox = require("wibox")
local capi = { screen = screen }
module("freedesktop.desktop") module("freedesktop.desktop")
@ -20,20 +21,20 @@ function add_icon(settings)
local s = settings.screen local s = settings.screen
if not current_pos[s] then if not current_pos[s] then
current_pos[s] = { x = (screen[s].geometry.width - iconsize.width - margin.x), y = 40 } current_pos[s] = { x = (capi.screen[s].geometry.width - iconsize.width - margin.x), y = 40 }
end end
local totheight = (settings.icon and iconsize.height or 0) + (settings.label and labelsize.height or 0) local totheight = (settings.icon and iconsize.height or 0) + (settings.label and labelsize.height or 0)
if totheight == 0 then return end if totheight == 0 then return end
if current_pos[s].y + totheight > screen[s].geometry.height - 40 then if current_pos[s].y + totheight > capi.screen[s].geometry.height - 40 then
current_pos[s].x = current_pos[s].x - labelsize.width - iconsize.width - margin.x current_pos[s].x = current_pos[s].x - labelsize.width - iconsize.width - margin.x
current_pos[s].y = 40 current_pos[s].y = 40
end end
if (settings.icon) then if (settings.icon) then
icon = awful.widget.button({ image = settings.icon }) icon = awful.widget.button({ image = settings.icon })
local newbuttons = icon:buttons() local newbuttons = icon:buttons({}, 1, nil, settings.click)
table.insert(newbuttons, button({}, 1, nil, settings.click)); table.insert(newbuttons, button({}, 1, nil, settings.click));
icon:buttons(newbuttons) icon:buttons(newbuttons)

View file

@ -6,15 +6,15 @@ local table = table
local type = type local type = type
local ipairs = ipairs local ipairs = ipairs
local pairs = pairs local pairs = pairs
local lgi = require('lgi')
local Gtk = lgi.Gtk local Gtk = require("lgi").Gtk
module("freedesktop.utils") module("freedesktop.utils")
terminal = 'xterm' terminal = 'xterm'
icon_theme = nil icon_theme = nil
local gtk_icon_theme = Gtk.IconTheme.get_default() gtk_icon_theme = Gtk.IconTheme.get_default()
all_icon_sizes = { all_icon_sizes = {
'128x128', '128x128',
@ -26,9 +26,7 @@ all_icon_sizes = {
'32x32', '32x32',
'24x24', '24x24',
'22x22', '22x22',
'16x16', '16x16'
'8x8',
'scalable'
} }
all_icon_types = { all_icon_types = {
'apps', 'apps',
@ -64,14 +62,16 @@ function file_exists(filename)
end end
function lookup_icon(arg) function lookup_icon(arg)
if arg.icon:sub(1, 1) == '/' and (arg.icon:find('.+%.png') or arg.icon:find('.+%.xpm') or arg.icon:find('.+%.svg')) then if arg.icon:sub(1, 1) == '/' and (arg.icon:find('.+%.png') or arg.icon:find('.+%.xpm')) then
-- icons with absolute path and supported (AFAICT) formats -- icons with absolute path and supported (AFAICT) formats
return arg.icon return arg.icon
else else
local gtk_icon_info = Gtk.IconTheme.lookup_icon(gtk_icon_theme, arg.icon, 48, 0) local gtk_icon_info = Gtk.IconTheme.lookup_icon(gtk_icon_theme, arg.icon, 48, 0)
if gtk_icon_info then if gtk_icon_info then
filename = Gtk.IconInfo.get_filename(gtk_icon_info) filename = Gtk.IconInfo.get_filename(gtk_icon_info)
if filename then return filename end if filename then
return filename
end
end end
local icon_path = {} local icon_path = {}
@ -108,14 +108,12 @@ function lookup_icon(arg)
table.insert(icon_path, '/usr/share/app-install/icons/') table.insert(icon_path, '/usr/share/app-install/icons/')
for i, directory in ipairs(icon_path) do for i, directory in ipairs(icon_path) do
if (arg.icon:find('.+%.png') or arg.icon:find('.+%.xpm') or arg.icon:find('.+%.svg')) and file_exists(directory .. arg.icon) then if (arg.icon:find('.+%.png') or arg.icon:find('.+%.xpm')) and file_exists(directory .. arg.icon) then
return directory .. arg.icon return directory .. arg.icon
elseif file_exists(directory .. arg.icon .. '.png') then elseif file_exists(directory .. arg.icon .. '.png') then
return directory .. arg.icon .. '.png' return directory .. arg.icon .. '.png'
elseif file_exists(directory .. arg.icon .. '.xpm') then elseif file_exists(directory .. arg.icon .. '.xpm') then
return directory .. arg.icon .. '.xpm' return directory .. arg.icon .. '.xpm'
elseif file_exists(directory .. arg.icon .. '.svg') then
return directory .. arg.icon .. '.svg'
end end
end end
end end
@ -158,7 +156,7 @@ function load_mime_types()
for w in line:gmatch('[^%s]+') do for w in line:gmatch('[^%s]+') do
table.insert(parsed, w) table.insert(parsed, w)
end end
if #parsed > 1 then if #parsed > 1 then
for i = 2, #parsed do for i = 2, #parsed do
mime_types[parsed[i]] = parsed[1]:gsub('/', '-') mime_types[parsed[i]] = parsed[1]:gsub('/', '-')
end end
@ -173,13 +171,40 @@ end
-- @param requested_icon_sizes A list of icon sizes (optional). If this list is given, it will be used as a priority list for icon sizes when looking up for icons. If you want large icons, for example, you can put '128x128' as the first item in the list. -- @param requested_icon_sizes A list of icon sizes (optional). If this list is given, it will be used as a priority list for icon sizes when looking up for icons. If you want large icons, for example, you can put '128x128' as the first item in the list.
-- @return A table with file entries. -- @return A table with file entries.
function parse_desktop_file(arg) function parse_desktop_file(arg)
local program = { show = true, file = arg.file }
for line in io.lines(arg.file) do local function check_nil(f, v)
for key, value in line:gmatch("(%w+)=(.+)") do -- Almost the same as
program[key] = value -- return f and f or v
end -- but it will return false if f = false
if f == nil then return v else return f end
end end
--- Parses .desktop file considering groups.
-- @param file Path to file
-- @return A table with group enries. Each group entry is table with file entries.
local function parse_file(file)
local result = {}
local group = nil
for line in io.lines(file) do
group = line:match("^%[([^%[%]%c]+)%]") or group
if group then
result[group] = check_nil(result[group], {})
for key, value in line:gmatch("(%w+)=(.+)") do
result[group][key] = value
end
end
end
return result
end
-- Using only 'Desktop Entry' group.
local program = parse_file(arg.file)['Desktop Entry']
program.show = check_nil(program.show, true)
program.file = arg.file
-- Don't show the program if NoDisplay is true -- Don't show the program if NoDisplay is true
-- Only show the program if there is not OnlyShowIn attribute -- Only show the program if there is not OnlyShowIn attribute
-- or if it's equal to 'awesome' -- or if it's equal to 'awesome'