-
Notifications
You must be signed in to change notification settings - Fork 1
/
helpers.lua
129 lines (109 loc) · 2.69 KB
/
helpers.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
127
128
129
-- Contains a bunch of useful helper functions
local awful = require("awful")
local gears = require("gears")
local wibox = require("wibox")
local beautiful = require("beautiful")
local lgi = require("lgi")
local Gio = lgi.Gio
local Gtk = lgi.require("Gtk", "3.0")
local M = {}
function M.rrect()
return function(cr, width, height)
gears.shape.rounded_rect(cr, width, height, beautiful.radius)
end
end
function M.circle()
return function(cr, width, height)
gears.shape.circle(cr, width, height)
end
end
-- Makes widget change color on hover
function M.add_click(widget, color)
color = color or beautiful.blue
local background = wibox.widget({
widget,
shape = M.rrect(),
layout = wibox.container.background,
})
background:connect_signal("mouse::enter", function()
background.fg = beautiful.bg0
background.bg = color
end)
background:connect_signal("mouse::leave", function()
background.fg = beautiful.fg0
background.bg = "#00000000"
end)
return background
end
-- Adds background to widget
function M.add_bg0(widget)
local background = wibox.widget({
widget,
layout = wibox.container.background,
bg = beautiful.bg0,
fg = beautiful.fg0,
shape = M.rrect()
})
return background
end
function M.add_bg1(widget)
local background = wibox.widget({
widget,
layout = wibox.container.background,
bg = beautiful.bg1,
fg = beautiful.fg0,
shape = M.rrect()
})
return background
end
function M.add_bg(widget)
return wibox.widget({
widget,
shape = M.rrect(),
layout = wibox.container.background
})
end
-- Creates tooltip
function M.add_tooltip(widget, markup)
return awful.tooltip({
objects = { widget },
markup = markup,
shape = M.rrect(),
margins_leftright = beautiful.margin[1],
margins_topbottom = beautiful.margin[1],
border_width = beautiful.border_width,
border_color = beautiful.border_color_active,
})
end
-- Adds margin to widget
function M.add_margin(widget, h, v)
h = h or beautiful.margin[0]
v = v or beautiful.margin[0]
return wibox.container.margin(widget, h, h, v, v)
end
-- Icons
M.gtk_theme = Gtk.IconTheme.get_default()
M.apps = Gio.AppInfo.get_all()
function M.get_icon(client_name)
if not client_name then
return nil
end
local icon_info = M.gtk_theme:lookup_icon(client_name, beautiful.icon_size[3], 0)
if icon_info then
local icon_path = icon_info:get_filename()
if icon_path then
return icon_path
end
end
return nil
end
function M.get_gicon_path(gicon)
if not gicon then
return nil
end
local info = M.gtk_theme:lookup_by_gicon(gicon, beautiful.icon_size[3], 0)
if info then
return info:get_filename()
end
end
return M