Reset old config
This commit is contained in:
36
wrapper/backlight.lua
Executable file
36
wrapper/backlight.lua
Executable file
@ -0,0 +1,36 @@
|
||||
local backlight = {}
|
||||
|
||||
|
||||
backlight.hooks = {}
|
||||
backlight.add_hook = function(callback)
|
||||
backlight.hooks[#backlight.hooks + 1] = callback
|
||||
end
|
||||
|
||||
backlight.exec_hooks = function()
|
||||
backlight.read(function(status)
|
||||
for i=1, #backlight.hooks do
|
||||
backlight.hooks[i](status)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
backlight.read = function(callback)
|
||||
bin.backlight.get(
|
||||
function(stdout, stderr, exitreason, exitcode)
|
||||
callback(tonumber(stdout))
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
backlight.up = function()
|
||||
bin.backlight.up()
|
||||
backlight.exec_hooks()
|
||||
end
|
||||
|
||||
backlight.down = function()
|
||||
bin.backlight.down()
|
||||
backlight.exec_hooks()
|
||||
end
|
||||
|
||||
return backlight
|
102
wrapper/ibus.lua
Normal file
102
wrapper/ibus.lua
Normal file
@ -0,0 +1,102 @@
|
||||
local ibus = {}
|
||||
|
||||
|
||||
ibus.current_engine = ""
|
||||
ibus.current_engine_index = nil
|
||||
|
||||
ibus.ibus_indicator_text = wibox.widget.textbox("??")
|
||||
ibus.ibus_indicator_text.valign = "center"
|
||||
ibus.ibus_indicator_text.align = "center"
|
||||
ibus.ibus_indicator_text.font = "Hack NF 14"
|
||||
|
||||
ibus.xkb_indicator_text = wibox.widget.textbox("??")
|
||||
ibus.xkb_indicator_text.valign = "center"
|
||||
ibus.xkb_indicator_text.align = "center"
|
||||
ibus.xkb_indicator_text.font = "Hack NF 10"
|
||||
|
||||
|
||||
ibus.get = function(callback)
|
||||
awful.spawn.easy_async("ibus engine", function(stdout, stderr, exitreason, exitcode)
|
||||
-- Get current ibus engine, remove newlines from output.
|
||||
ibus.current_engine = string.gsub(stdout, "\n", "")
|
||||
ibus.current_engine_index = nil
|
||||
|
||||
-- Find the current engine's index in conf.ibus_language_list.
|
||||
-- If it is not there, ibus.current_engine_index will be nil.
|
||||
for k, v in pairs(conf.ibus_language_list) do
|
||||
if (v["ibus_engine"] == ibus.current_engine) then
|
||||
ibus.current_engine_index = k
|
||||
end
|
||||
end
|
||||
|
||||
if callback then
|
||||
callback()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
ibus.update_indicator = function()
|
||||
-- Update indicators
|
||||
awful.spawn.easy_async("setxkbmap -query" , function(stdout, stderr, exitreason, exitcode)
|
||||
ibus.ibus_indicator_text.markup = conf.ibus_language_list[ibus.current_engine_index]["indicator_code"]
|
||||
ibus.xkb_indicator_text.markup = string.match(stdout, "layout:%s+(%w+)")
|
||||
end)
|
||||
end
|
||||
|
||||
ibus.set = function(language_index, callback)
|
||||
-- engine is an index of the language list above
|
||||
|
||||
engine = conf.ibus_language_list[language_index]["ibus_engine"]
|
||||
|
||||
-- Get required engine, if one is given
|
||||
local requires_engine
|
||||
for k, v in pairs(conf.ibus_language_list) do
|
||||
if (v["ibus_engine"] == engine) then
|
||||
requires_engine = v["requires_engine"]
|
||||
end
|
||||
end
|
||||
|
||||
-- If a required xkb engine is given, but it is not active, switch to it before switching to the target
|
||||
if (requires_engine ~= ibus.current_engine) and (requires_engine ~= nil) then
|
||||
awful.spawn.easy_async("ibus engine " .. requires_engine, function(stdout, stderr, exitreason, exitcode)
|
||||
awful.spawn.easy_async("ibus engine " .. engine, function(stdout, stderr, exitreason, exitcode)
|
||||
ibus.update_indicator()
|
||||
ibus.get(callback)
|
||||
end)
|
||||
end)
|
||||
else
|
||||
awful.spawn.easy_async("ibus engine " .. engine, function(stdout, stderr, exitreason, exitcode)
|
||||
ibus.update_indicator()
|
||||
ibus.get(callback)
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
ibus.next = function(callback)
|
||||
if (ibus.current_engine_index == nil) or (ibus.current_engine_index == #conf.ibus_language_list) then
|
||||
ibus.current_engine_index = 1
|
||||
else
|
||||
ibus.current_engine_index = ibus.current_engine_index + 1
|
||||
end
|
||||
ibus.set(ibus.current_engine_index, callback)
|
||||
end
|
||||
|
||||
-- Update the language indicator
|
||||
ibus.update_timer = gears.timer {
|
||||
timeout = 2,
|
||||
call_now = false,
|
||||
autostart = true,
|
||||
single_shot = false,
|
||||
|
||||
callback = function()
|
||||
ibus.get(
|
||||
function()
|
||||
ibus.update_indicator()
|
||||
end
|
||||
)
|
||||
end
|
||||
}
|
||||
|
||||
return ibus
|
7
wrapper/init.lua
Executable file
7
wrapper/init.lua
Executable file
@ -0,0 +1,7 @@
|
||||
return {
|
||||
backlight = require("wrapper.backlight"),
|
||||
volume = require("wrapper.volume"),
|
||||
sound = require("wrapper.sound"),
|
||||
ibus = require("wrapper.ibus"),
|
||||
mdadm = require("wrapper.mdadm")
|
||||
}
|
38
wrapper/mdadm.lua
Normal file
38
wrapper/mdadm.lua
Normal file
@ -0,0 +1,38 @@
|
||||
local mdadm = {}
|
||||
|
||||
mdadm.get = function(callback)
|
||||
awful.spawn.easy_async("awk '/^md/ {printf \"%s: \", $1}; /blocks/ {print $NF}' /proc/mdstat",
|
||||
function(stdout, stderr, exitreason, exitcode)
|
||||
status = string.match(stdout, "%[(.*)%]")
|
||||
callback(status)
|
||||
|
||||
end)
|
||||
end
|
||||
|
||||
|
||||
|
||||
mdadm.indicator_text = wibox.widget.textbox("??")
|
||||
mdadm.indicator_text.valign = "center"
|
||||
mdadm.indicator_text.align = "center"
|
||||
mdadm.indicator_text.font = "Hack NF 10"
|
||||
|
||||
|
||||
mdadm.update_indicator = function(status)
|
||||
mdadm.indicator_text.markup = status
|
||||
end
|
||||
|
||||
-- Update the indicator
|
||||
mdadm.update_timer = gears.timer {
|
||||
timeout = 2,
|
||||
call_now = false,
|
||||
autostart = true,
|
||||
single_shot = false,
|
||||
|
||||
callback = function()
|
||||
mdadm.get(
|
||||
mdadm.update_indicator
|
||||
)
|
||||
end
|
||||
}
|
||||
|
||||
return mdadm
|
22
wrapper/sound.lua
Normal file
22
wrapper/sound.lua
Normal file
@ -0,0 +1,22 @@
|
||||
local sound = {}
|
||||
|
||||
sound.counter = 0
|
||||
|
||||
sound.play = function(sound_key)
|
||||
if (beautiful.sounds[sound_key] == nil) then
|
||||
naughty.notify({
|
||||
title = "Sound play error:",
|
||||
text = "There is no sound with key " .. sound_key
|
||||
})
|
||||
else
|
||||
if (sound.counter > 5) then
|
||||
return
|
||||
end
|
||||
sound.counter = sound.counter + 1
|
||||
awful.spawn.easy_async("play -q \"" .. beautiful.sounds[sound_key] .. "\"", function()
|
||||
sound.counter = sound.counter - 1
|
||||
end)
|
||||
end
|
||||
end
|
||||
|
||||
return sound
|
146
wrapper/volume.lua
Executable file
146
wrapper/volume.lua
Executable file
@ -0,0 +1,146 @@
|
||||
local volume = {}
|
||||
volume.commands = {}
|
||||
|
||||
|
||||
-- Create pamixer option string
|
||||
volume.pamixer_options = ""
|
||||
if (conf.pamixer_sink ~= "") then
|
||||
volume.pamixer_options = volume.pamixer_options .. " --sink " .. conf.pamixer_sink
|
||||
end
|
||||
|
||||
function volume.commands:up()
|
||||
awful.spawn("pamixer --increase 5" .. volume.pamixer_options, false)
|
||||
end
|
||||
|
||||
function volume.commands:down()
|
||||
awful.spawn("pamixer --decrease 5" .. volume.pamixer_options, false)
|
||||
end
|
||||
|
||||
function volume.commands:set(value)
|
||||
awful.spawn("pamixer --set_volume" .. tostring(value) .. " " .. volume.pamixer_options, false)
|
||||
end
|
||||
|
||||
function volume.commands:mute()
|
||||
awful.spawn("pamixer --mute" .. volume.pamixer_options, false)
|
||||
end
|
||||
|
||||
function volume.commands:unmute()
|
||||
awful.spawn("pamixer --unmute" .. volume.pamixer_options, false)
|
||||
end
|
||||
|
||||
function volume.commands:get(callback)
|
||||
local muted
|
||||
local value
|
||||
|
||||
awful.spawn.easy_async("pamixer --get-mute --get-volume" .. volume.pamixer_options,
|
||||
function(stdout, stderr, exitreason, exitcode)
|
||||
muted = string.match(stdout, "(%w%w%w%w%w?) ") -- "true" or "false"
|
||||
muted = (muted == "true")
|
||||
|
||||
value = string.match(stdout, "(%d?%d?%d)") -- (\d?\d?\d)\%)
|
||||
|
||||
if (value == nil) then
|
||||
value = false
|
||||
else
|
||||
value = tonumber(string.format("% 3d", value))
|
||||
end
|
||||
|
||||
callback({
|
||||
mute = muted,
|
||||
value = value
|
||||
})
|
||||
end)
|
||||
end
|
||||
|
||||
function volume.commands:watch(timeout, callback, widget)
|
||||
awful.widget.watch(
|
||||
"pamixer --get-mute --get-volume " .. volume.pamixer_options,
|
||||
timeout, scallback, widget
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
|
||||
volume.hooks = {}
|
||||
volume.add_hook = function(callback)
|
||||
volume.hooks[#volume.hooks + 1] = callback
|
||||
end
|
||||
|
||||
volume.exec_hooks = function()
|
||||
volume.commands:get(function(status)
|
||||
for i=1, #volume.hooks do
|
||||
volume.hooks[i](status)
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
volume.up = function()
|
||||
if volume.muted then
|
||||
volume.unmute()
|
||||
end
|
||||
|
||||
volume.commands:up()
|
||||
wrapper.sound.play("volume_up")
|
||||
|
||||
volume.exec_hooks()
|
||||
end
|
||||
|
||||
volume.down = function()
|
||||
if volume.muted then
|
||||
volume.unmute()
|
||||
end
|
||||
|
||||
volume.commands:down()
|
||||
wrapper.sound.play("volume_down")
|
||||
|
||||
volume.exec_hooks()
|
||||
end
|
||||
|
||||
volume.mute = function()
|
||||
volume.commands:mute()
|
||||
volume.muted = true
|
||||
|
||||
-- Spawn notification
|
||||
local n = naughty.notify({
|
||||
title = "Volume muted",
|
||||
text = "Silence!",
|
||||
timeout = 1,
|
||||
replaces_id = volume.notificationid
|
||||
})
|
||||
|
||||
volume.notificationid = n.id
|
||||
|
||||
volume.exec_hooks()
|
||||
end
|
||||
|
||||
volume.unmute = function()
|
||||
volume.commands:unmute()
|
||||
volume.muted = false
|
||||
|
||||
-- Spawn notification
|
||||
local n = naughty.notify({
|
||||
title = "Volume unmuted",
|
||||
text = "Loud.",
|
||||
timeout = 1,
|
||||
replaces_id = volume.notificationid
|
||||
})
|
||||
|
||||
volume.notificationid = n.id
|
||||
|
||||
volume.exec_hooks()
|
||||
end
|
||||
|
||||
volume.togglemute = function()
|
||||
volume.commands:get(function(status)
|
||||
if status.mute then
|
||||
volume.unmute()
|
||||
else
|
||||
volume.mute()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
-- Make sure volume is unmuted at startup
|
||||
volume.commands:unmute()
|
||||
|
||||
return volume
|
Reference in New Issue
Block a user