modif awesome

This commit is contained in:
vincent 2018-11-07 23:15:54 +01:00
parent 5663007822
commit a86f5af2fb
2 changed files with 214 additions and 2 deletions

View File

@ -6,6 +6,7 @@ require("awful.autofocus")
local wibox = require("wibox") local wibox = require("wibox")
-- Theme handling library -- Theme handling library
local lain = require("lain") local lain = require("lain")
local markup = lain.util.markup
local beautiful = require("beautiful") local beautiful = require("beautiful")
--import xrandr library --import xrandr library
local xrandr = require("xrandr") local xrandr = require("xrandr")
@ -47,7 +48,11 @@ end
beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua") beautiful.init(awful.util.getdir("config") .. "/themes/default/theme.lua")
beautiful.useless_gap = 5 beautiful.useless_gap = 5
-- This is used later as the default terminal and editor to run. -- This is used later as the default terminal and editor to run.
terminal = "termite"
local terminal = "termite"
awful.util.terminal = terminal
editor = os.getenv("EDITOR") or "vim" editor = os.getenv("EDITOR") or "vim"
editor_cmd = terminal .. " -e " .. editor editor_cmd = terminal .. " -e " .. editor
@ -122,6 +127,65 @@ mykeyboardlayout = awful.widget.keyboardlayout()
-- Create a textclock widget -- Create a textclock widget
mytextclock = wibox.widget.textclock() mytextclock = wibox.widget.textclock()
local cpu = lain.widget.cpu({
settings = function()
widget:set_markup(markup.fontfg(beautiful.font, "#e33a6e", cpu_now.usage .. "% "))
end
})
-- Net
local netdownicon = wibox.widget.imagebox(beautiful.widget_netdown)
local netdowninfo = wibox.widget.textbox()
local netupicon = wibox.widget.imagebox(beautiful.widget_netup)
local netupinfo = lain.widget.net({
settings = function()
widget:set_markup(markup.fontfg(beautiful.font, "#e54c62", net_now.sent .. " "))
netdowninfo:set_markup(markup.fontfg(beautiful.font, "#87af5f", net_now.received .. " "))
end
})
local mpdicon = wibox.widget.imagebox()
local mpd = lain.widget.mpd({
settings = function()
mpd_notification_preset = {
text = string.format("%s [%s] - %s\n%s", mpd_now.artist,
mpd_now.album, mpd_now.date, mpd_now.title)
}
if mpd_now.state == "play" then
artist = mpd_now.artist .. " > "
title = mpd_now.title .. " "
mpdicon:set_image(beautiful.widget_note_on)
elseif mpd_now.state == "pause" then
artist = "mpd "
title = "paused "
else
artist = ""
title = ""
--mpdicon:set_image() -- not working in 4.0
mpdicon._private.image = nil
mpdicon:emit_signal("widget::redraw_needed")
mpdicon:emit_signal("widget::layout_changed")
end
widget:set_markup(markup.fontfg(beautiful.font, "#e54c62", artist) .. markup.fontfg(beautiful.font, "#b2b2b2", title))
end
})
local baticon = wibox.widget.imagebox(beautiful
.widget_batt)
local bat = lain.widget.bat({
settings = function()
local perc = bat_now.perc ~= "N/A" and bat_now.perc .. "%" or bat_now.perc
if bat_now.ac_status == 1 then
perc = perc .. " plug"
end
widget:set_markup(markup.fontfg(beautiful.font, beautiful.fg_normal, perc .. " "))
end
})
-- Create a wibox for each screen and add it -- Create a wibox for each screen and add it
local taglist_buttons = gears.table.join( local taglist_buttons = gears.table.join(
awful.button({ }, 1, function(t) t:view_only() end), awful.button({ }, 1, function(t) t:view_only() end),
@ -157,10 +221,12 @@ end
screen.connect_signal("property::geometry", set_wallpaper) screen.connect_signal("property::geometry", set_wallpaper)
awful.screen.connect_for_each_screen(function(s) awful.screen.connect_for_each_screen(function(s)
s.quake = lain.util.quake({ app = awful.util.terminal ,
argname = "-name %s"})
-- Wallpaper -- Wallpaper
set_wallpaper(s) set_wallpaper(s)
-- Each screen has its own tag table. -- Each screen has its own tag taawful.util.terminable.
awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[2]) awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[2])
@ -188,10 +254,18 @@ awful.screen.connect_for_each_screen(function(s)
mylauncher, mylauncher,
s.mytaglist, s.mytaglist,
s.mypromptbox, s.mypromptbox,
mpdicon,
mpd.widget
}, },
nil -- Middle widget nil -- Middle widget
,{ -- Right widgets ,{ -- Right widgets
layout = wibox.layout.fixed.horizontal, layout = wibox.layout.fixed.horizontal,
netdownicon,
netdowninfo,
netupicon,
netupinfo.widget,
cpuicon,
cpu ,
mykeyboardlayout, mykeyboardlayout,
wibox.widget.systray(), wibox.widget.systray(),
mytextclock, mytextclock,
@ -258,6 +332,9 @@ globalkeys = gears.table.join(
{description = "go back", group = "client"}), {description = "go back", group = "client"}),
-- Standard program -- Standard program
-- Dropdown application
awful.key({ modkey, }, "z", function () awful.screen.focused().quake:toggle() end,
{description = "dropdown application", group = "launcher"}),
awful.key({ modkey, }, "Return", function () awful.spawn(terminal) end, awful.key({ modkey, }, "Return", function () awful.spawn(terminal) end,
{description = "open a terminal", group = "launcher"}), {description = "open a terminal", group = "launcher"}),
awful.key({ modkey, "Control" }, "r", awesome.restart, awful.key({ modkey, "Control" }, "r", awesome.restart,

View File

@ -0,0 +1,135 @@
--- Separating Multiple Monitor functions as a separeted module (taken from awesome wiki)
local awful = require("awful")
local naughty = require("naughty")
-- A path to a fancy icon
local icon_path = ""
-- Get active outputs
local function outputs()
local outputs = {}
local xrandr = io.popen("xrandr -q --current")
if xrandr then
for line in xrandr:lines() do
local output = line:match("^([%w-]+) connected ")
if output then
outputs[#outputs + 1] = output
end
end
xrandr:close()
end
return outputs
end
local function arrange(out)
-- We need to enumerate all permutations of horizontal outputs.
local choices = {}
local previous = { {} }
for i = 1, #out do
-- Find all permutation of length `i`: we take the permutation
-- of length `i-1` and for each of them, we create new
-- permutations by adding each output at the end of it if it is
-- not already present.
local new = {}
for _, p in pairs(previous) do
for _, o in pairs(out) do
if not awful.util.table.hasitem(p, o) then
new[#new + 1] = awful.util.table.join(p, {o})
end
end
end
choices = awful.util.table.join(choices, new)
previous = new
end
return choices
end
-- Build available choices
local function menu()
local menu = {}
local out = outputs()
local choices = arrange(out)
for _, choice in pairs(choices) do
local cmd = "xrandr"
-- Enabled outputs
for i, o in pairs(choice) do
cmd = cmd .. " --output " .. o .. " --auto"
if i > 1 then
cmd = cmd .. " --right-of " .. choice[i-1]
end
end
-- Disabled outputs
for _, o in pairs(out) do
if not awful.util.table.hasitem(choice, o) then
cmd = cmd .. " --output " .. o .. " --off"
end
end
local label = ""
if #choice == 1 then
label = 'Only <span weight="bold">' .. choice[1] .. '</span>'
else
for i, o in pairs(choice) do
if i > 1 then label = label .. " + " end
label = label .. '<span weight="bold">' .. o .. '</span>'
end
end
menu[#menu + 1] = { label, cmd }
end
return menu
end
-- Display xrandr notifications from choices
local state = { cid = nil }
local function naughty_destroy_callback(reason)
if reason == naughty.notificationClosedReason.expired or
reason == naughty.notificationClosedReason.dismissedByUser then
local action = state.index and state.menu[state.index - 1][2]
if action then
awful.util.spawn(action, false)
state.index = nil
end
end
end
local function xrandr()
-- Build the list of choices
if not state.index then
state.menu = menu()
state.index = 1
end
-- Select one and display the appropriate notification
local label, action
local next = state.menu[state.index]
state.index = state.index + 1
if not next then
label = "Keep the current configuration"
state.index = nil
else
label, action = unpack(next)
end
state.cid = naughty.notify({ text = label,
icon = icon_path,
timeout = 4,
screen = mouse.screen,
replaces_id = state.cid,
destroy = naughty_destroy_callback}).id
end
return {
outputs = outputs,
arrange = arrange,
menu = menu,
xrandr = xrandr
}