1
0
Fork 0
mirror of https://github.com/lcpz/awesome-copycats.git synced 2024-10-22 20:41:22 +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_.
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/
.. _Awesome: http://awesome.naquadah.org/

View file

@ -7,6 +7,7 @@ local ipairs = ipairs
local awful = require("awful")
local utils = require("freedesktop.utils")
local wibox = require("wibox")
local capi = { screen = screen }
module("freedesktop.desktop")
@ -20,20 +21,20 @@ function add_icon(settings)
local s = settings.screen
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
local totheight = (settings.icon and iconsize.height or 0) + (settings.label and labelsize.height or 0)
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].y = 40
end
if (settings.icon) then
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));
icon:buttons(newbuttons)

View file

@ -6,15 +6,15 @@ local table = table
local type = type
local ipairs = ipairs
local pairs = pairs
local lgi = require('lgi')
local Gtk = lgi.Gtk
local Gtk = require("lgi").Gtk
module("freedesktop.utils")
terminal = 'xterm'
icon_theme = nil
local gtk_icon_theme = Gtk.IconTheme.get_default()
gtk_icon_theme = Gtk.IconTheme.get_default()
all_icon_sizes = {
'128x128',
@ -26,9 +26,7 @@ all_icon_sizes = {
'32x32',
'24x24',
'22x22',
'16x16',
'8x8',
'scalable'
'16x16'
}
all_icon_types = {
'apps',
@ -64,14 +62,16 @@ function file_exists(filename)
end
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
return arg.icon
else
local gtk_icon_info = Gtk.IconTheme.lookup_icon(gtk_icon_theme, arg.icon, 48, 0)
if gtk_icon_info then
filename = Gtk.IconInfo.get_filename(gtk_icon_info)
if filename then return filename end
if filename then
return filename
end
end
local icon_path = {}
@ -108,14 +108,12 @@ function lookup_icon(arg)
table.insert(icon_path, '/usr/share/app-install/icons/')
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
elseif file_exists(directory .. arg.icon .. '.png') then
return directory .. arg.icon .. '.png'
elseif file_exists(directory .. arg.icon .. '.xpm') then
return directory .. arg.icon .. '.xpm'
elseif file_exists(directory .. arg.icon .. '.svg') then
return directory .. arg.icon .. '.svg'
end
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.
-- @return A table with file entries.
function parse_desktop_file(arg)
local program = { show = true, file = arg.file }
for line in io.lines(arg.file) do
for key, value in line:gmatch("(%w+)=(.+)") do
program[key] = value
end
local function check_nil(f, v)
-- Almost the same as
-- return f and f or v
-- but it will return false if f = false
if f == nil then return v else return f 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
-- Only show the program if there is not OnlyShowIn attribute
-- or if it's equal to 'awesome'