forked from doronbehar/awesome-freedesktop
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdesktop.lua
126 lines (110 loc) · 4.13 KB
/
desktop.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
local wibox = wibox
local widget = widget
local screen = screen
local image = image
local button = button
local table = table
local ipairs = ipairs
local awful = require("awful")
local utils = require("freedesktop.utils")
module("freedesktop.desktop")
local current_pos = {}
local iconsize = { width = 48, height = 48 }
local labelsize = { width = 130, height = 20 }
local margin = { x = 20, y = 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 }
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
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()
table.insert(newbuttons, button({}, 1, nil, settings.click));
icon:buttons(newbuttons)
icon_container = wibox({ position = "floating", screen = s, bg = "#00000000" })
icon_container.widgets = { icon }
icon_container:geometry({
width = iconsize.width,
height = iconsize.height,
y = current_pos[s].y,
x = current_pos[s].x
})
icon_container.screen = s
current_pos[s].y = current_pos[s].y + iconsize.height + 5
end
if (settings.label) then
caption = widget({ type="textbox", align="right", width=labelsize.width })
caption.ellipsize = "middle"
caption.text = settings.label
caption:buttons({
button({ }, 1, settings.click)
})
caption_container = wibox({ position = "floating", screen = s, bg = "#00000000" })
caption_container.widgets = { caption }
caption_container:geometry({
width = labelsize.width,
height = labelsize.height,
y = current_pos[s].y,
x = current_pos[s].x - labelsize.width + iconsize.width
})
caption_container.screen = s
end
current_pos[s].y = current_pos[s].y + labelsize.height + margin.y
end
--- Adds subdirs and files icons to the desktop
-- @param dir The directory to parse, (default is ~/Desktop)
-- @param showlabels Shows icon captions (default is false)
function add_applications_icons(arg)
for i, program in ipairs(utils.parse_desktop_files({
dir = arg.dir or '~/Desktop/',
icon_sizes = {
iconsize.width .. "x" .. iconsize.height,
"128x128", "96x96", "72x72", "64x64", "48x48",
"36x36", "32x32", "24x24", "22x22", "16x6"
}
})) do
if program.show then
add_icon({
label = arg.showlabels and program.Name or nil,
icon = program.icon_path,
screen = arg.screen,
click = function () awful.util.spawn(program.cmdline) end
})
end
end
end
--- Adds subdirs and files icons to the desktop
-- @param dir The directory to parse
-- @param showlabels Shows icon captions
-- @param open_with The program to use to open clicked files and dirs (i.e. xdg_open, thunar, etc.)
function add_dirs_and_files_icons(arg)
arg.open_with = arg.open_with or 'thunar'
for i, file in ipairs(utils.parse_dirs_and_files({
dir = arg.dir or '~/Desktop/',
icon_sizes = {
iconsize.width .. "x" .. iconsize.height,
"128x128", "96x96", "72x72", "64x64", "48x48",
"36x36", "32x32", "24x24", "22x22", "16x6"
}
})) do
if file.show then
add_icon({
label = arg.showlabels and file.filename or nil,
icon = file.icon,
screen = arg.screen,
click = function () awful.util.spawn(arg.open_with .. ' ' .. file.path) end
})
end
end
end
function add_desktop_icons(args)
add_applications_icons(args)
add_dirs_and_files_icons(args)
end