Skip to content

Instantly share code, notes, and snippets.

@silverweed
Last active July 6, 2023 07:55
Show Gist options
  • Save silverweed/078ab193a90d2e341774 to your computer and use it in GitHub Desktop.
Save silverweed/078ab193a90d2e341774 to your computer and use it in GitHub Desktop.
Awesome 4 rc.lua
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2016, silverweed
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local string = { gmatch = string.gmatch }
-- }}}
-- brightness: provides the current brightness
local brightness = {}
-- {{{ Brightness widget type
local function worker(format, warg)
local fname = {
base = warg,
cur = warg .. "/brightness",
max = warg .. "/max_brightness"
}
local brightness = {
["{perc}"] = "N/A",
["{cur}"] = "N/A",
["{max}"] = "N/A"
}
io.input(fname.max)
brightness["{max}"] = tonumber(io.read("*all"))
io.input(fname.cur)
brightness["{cur}"] = tonumber(io.read("*all"))
io.close()
brightness["{perc}"] = math.floor(brightness["{cur}"] * 100 / brightness["{max}"])
return brightness
end
-- }}}
return setmetatable(brightness, { __call = function(_, ...) return worker(...) end })
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2016, silverweed
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { gmatch = string.gmatch }
-- }}}
-- gpu: provides GPU temperatures using the hddtemp daemon
-- vicious.widgets.hddtemp
local gpu = {}
-- {{{ GPU Temperature widget type
local function worker(format)
local f = io.popen("nvidia-smi --query-gpu=temperature.gpu --format=csv,noheader,nounits")
local gputemp = {tonumber(f:read())}
f:close()
return gputemp
end
-- }}}
return setmetatable(gpu, { __call = function(_, ...) return worker(...) end })
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- * (c) 2010, Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local setmetatable = setmetatable
local string = { format = string.format }
local helpers = require("vicious.helpers")
local math = {
min = math.min,
floor = math.floor
}
-- }}}
-- Bat: provides state, charge, and remaining time for a requested battery
-- vicious.widgets.mybat
local mybat = {}
-- {{{ Battery widget type
local function worker(format, warg)
if not warg then return end
local battery = helpers.pathtotable("/sys/class/power_supply/"..warg)
local battery_state = {
["Full\n"] = "",
["Unknown\n"] = "",
["Charged\n"] = "",
["Charging\n"] = "+",
["Discharging\n"] = "-"
}
-- Check if the battery is present
if battery.present ~= "1\n" then
return {battery_state["Unknown\n"], 0, "N/A"}
end
-- Get state information
local state = battery_state[battery.status] or battery_state["Unknown\n"]
-- Get capacity information
if battery.charge_now then
remaining, capacity = battery.charge_now, battery.charge_full
elseif battery.energy_now then
remaining, capacity = battery.energy_now, battery.energy_full
else
return {battery_state["Unknown\n"], 0, "N/A"}
end
-- Calculate percentage (but work around broken BAT/ACPI implementations)
local percent = math.min(math.floor(remaining / capacity * 100), 100)
-- Get charge information
if battery.current_now then
rate = tonumber(battery.current_now)
elseif battery.power_now then
rate = tonumber(battery.power_now)
else
return {state, percent, "N/A"}
end
-- Calculate remaining (charging or discharging) time
local time = "N/A"
if rate ~= nil and rate ~= 0 then
if state == "+" then
timeleft = (tonumber(capacity) - tonumber(remaining)) / tonumber(rate)
elseif state == "-" then
timeleft = tonumber(remaining) / tonumber(rate)
else
return {state, percent, time}
end
-- Calculate time
local hoursleft = math.floor(timeleft)
local minutesleft = math.floor((timeleft - hoursleft) * 60 )
-- ADDED BY JP: if minutes left < 5, issue warning; this widget
-- will be launched every minute by awesome.
if state == "-" and hoursleft == 0 and minutesleft < 5 then
local naughty = require("naughty")
naughty.notify({ preset = naughty.config.presets.critical,
title = "Battery state low",
text = "Minutes left: "..minutesleft })
end
time = string.format("%02d:%02d", hoursleft, minutesleft)
end
return {state, percent, time}
end
-- }}}
return setmetatable(mybat, { __call = function(_, ...) return worker(...) end })
--- Awesome 4 rc.lua
--- by silverweed
--- latest update 19/08/2017
-- {{{ User prefs
local terminal = "xfce4-terminal"
local editor = os.getenv("EDITOR") or "vim"
local editor_cmd = terminal .. " -e " .. editor
local filemanager = "pcmanfm"
local browser = "firefox"
-- }}}
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
local naughty = require("naughty")
local menubar = require("menubar")
-- Widget library
local vicious = require("vicious")
local hotkeys_popup = require("awful.hotkeys_popup").widget
-- Custom widgets
local mywidgets = {}
mywidgets.mybat = require("mywidgets.mybat")
mywidgets.brightness = require("mywidgets.brightness")
-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
naughty.notify({
preset = naughty.config.presets.critical,
title = "Oops, there were errors during startup!",
text = awesome.startup_errors
})
end
-- Handle runtime errors after startup
do
local in_error = false
awesome.connect_signal("debug::error", function (err)
-- Make sure we don't go into an endless error loop
if in_error then return end
in_error = true
naughty.notify({
preset = naughty.config.presets.critical,
title = "Oops, an error happened!",
text = err
})
in_error = false
end)
end
-- }}}
-- {{{ Variable definitions
-- Themes define colours, icons, font and wallpapers.
beautiful.init("~/.config/awesome/themes/default-theme.lua")
--beautiful.init("~/.config/awesome/themes/fullhd.lua")
-- Default modkey.
-- Usually, Mod4 is the key with a logo between Control and Alt.
-- If you do not like this or do not have such a key,
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
-- However, you can use another modifier like Mod1, but it may interact with others.
local modkey = "Mod4"
-- Table of layouts to cover with awful.layout.inc, order matters.
awful.layout.layouts = {
awful.layout.suit.tile,
-- awful.layout.suit.tile.left,
-- awful.layout.suit.tile.bottom,
awful.layout.suit.tile.top,
awful.layout.suit.fair,
-- awful.layout.suit.fair.horizontal,
-- awful.layout.suit.spiral,
-- awful.layout.suit.spiral.dwindle,
awful.layout.suit.max,
-- awful.layout.suit.max.fullscreen,
-- awful.layout.suit.floating,
-- awful.layout.suit.magnifier
}
-- }}}
-- {{{ Menu
-- Create a laucher widget and a main menu
local myawesomemenu = {
{ "hotkeys", function() return false, hotkeys_popup.show_help end},
{ "manual", terminal .. " -e man awesome" },
{ "edit config", editor_cmd .. " " .. awesome.conffile },
{ "restart", awesome.restart },
{ "quit", awesome.quit }
}
local mymainmenu = awful.menu({
items = {
{ "awesome", myawesomemenu, beautiful.awesome_icon },
{ "open terminal", terminal, beautiful.terminal_icon },
{ "reboot", terminal .. " -e reboot", beautiful.reboot_icon },
{ "poweroff", terminal .. " -e poweroff", beautiful.poweroff_icon }
}
})
local mylauncher = awful.widget.launcher({
image = beautiful.lotusface,
menu = mymainmenu
})
-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}
-- {{{ Wibox
-- Create a textclock widget
local mytextclock = awful.widget.textclock()
--local mykeyboardlayout = awful.widget.keyboardlayout()
-- {{ Vicious widgets:
----Networking
local netwidget = wibox.widget.textbox()
vicious.register(netwidget, vicious.widgets.net, '<span color="#CC9393">d:${wlp2s0 down_kb} | ${enp3s0f1 down_kb}</span> <span color="#7F9F7F">u:${wlp2s0 up_kb} | ${enp3s0f1 up_kb}</span> ', 3)
----CPU
local cpuwidget = wibox.widget.textbox()
vicious.register(cpuwidget, vicious.widgets.cpu,'<span color="#33CCFF">cpu:</span>(<span color="#00AAAA">$2</span>|<span color="#00AAAA">$3</span>|<span color="#00AAAA">$4</span>|<span color="#00AAAA">$5</span>|<span color="#00AAAA">$6</span>|<span color="#00AAAA">$7</span>|<span color="#00AAAA">$8</span>|<span color="#00AAAA">$9</span>) ')
----RAM/SWAP
local memwidget = wibox.widget.textbox()
vicious.register(memwidget, vicious.widgets.mem, '<span color="#FF2052">ram:$1%</span>[<span color="#648C11">$5%</span>] ', 7)
----HDDTEMP
--local hddwidget = wibox.widget.textbox()
---vicious.register(hddwidget, vicious.widgets.hddtemp, "<span color='#FF9900'>sda:${/dev/sda}°C</span> ", 19)
----HDD I/O
--local iowidget = wibox.widget.textbox()
--vicious.register(iowidget, vicious.widgets.dio, "<span color='#FF9900'>(${sda total_s}%')</span>", 4)
----OS
--oswidget = wibox.widget.textbox()
--oswidget:set_align('right')
--vicious.register(oswidget, vicious.widgets.os,'$2 | ', 86401)
--vicious.cache(oswidget)
----CPU temperature
local thermalwidget = wibox.widget.textbox()
vicious.register(thermalwidget, vicious.widgets.thermal, "$1°C ", 5, { "thermal_zone7", "sys" } )
----GPU temperature
--local gpuwidget = wibox.widget.textbox()
--vicious.register(gpuwidget, vicious.widgets.gpu, "<span color='#ff33cc'>gpu:$1°C</span> ", 19)
----VOLUME
local volwidget = wibox.widget.textbox()
vicious.register(volwidget,vicious.widgets.volume,'(($1)) $2', 121, "Master")
----WIFI
--local wifiwidget = wibox.widget.textbox()
--vicious.register(wifiwidget, vicious.widgets.wifi,'<span color="#CC44CC">wifi:${ssid} (${linp}%)</span> ',3,"wlp2s0")
----Battery
local batwidget = wibox.widget.textbox()
vicious.register(batwidget, mywidgets.mybat,' <span color="#00AACC">bat:$2% ($1 $3h)</span> | ', 61, "BAT0")
----Brightness
local brightwidget = wibox.widget.textbox()
vicious.register(brightwidget, mywidgets.brightness, '<span color="#00FF00">☀${perc}%</span> ', 171,
"/sys/class/backlight/intel_backlight")
----Keyboard layout
--local langwidget = wibox.widget.textbox()
--vicious.register(langwidget, vicious.widgets.lang, '[$1] ', 6)
-- }}
-- Create a wibox for each screen and add it
local taglist_buttons = awful.util.table.join(
awful.button({ }, 1, awful.tag.viewonly),
awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({ }, 3, awful.tag.viewtoggle),
awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
)
local tasklist_buttons = awful.util.table.join(
awful.button({ }, 1, function (c)
if c == client.focus then
c.minimized = true
else
-- Without this, the following
-- :isvisible() makes no sense
c.minimized = false
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
-- This will also un-minimize
-- the client, if needed
client.focus = c
c:raise()
end
end),
awful.button({ }, 3, function ()
if instance then
instance:hide()
instance = nil
else
instance = awful.menu.clients({
theme = { width = 250 }
})
end
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
awful.button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end)
)
local function set_wallpaper(s)
-- Wallpaper
if beautiful.wallpaper then
local wallpaper = beautiful.wallpaper
-- If wallpaper is a function, call it with the screen
if type(wallpaper) == "function" then
wallpaper = wallpaper(s)
end
gears.wallpaper.maximized(wallpaper, s, true)
end
end
-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal("property::geometry", set_wallpaper)
awful.screen.connect_for_each_screen(function (s)
set_wallpaper(s)
-- Each screen has its own tag table.
--awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1])
awful.tag({ "1", "2", "3", "4", "5" }, s, awful.layout.layouts[1])
-- Create a promptbox for each screen
s.mypromptbox = awful.widget.prompt()
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen.
s.mylayoutbox = awful.widget.layoutbox(s)
s.mylayoutbox:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.layout.inc(1) end),
awful.button({ }, 3, function () awful.layout.inc(-1) end),
awful.button({ }, 4, function () awful.layout.inc(1) end),
awful.button({ }, 5, function () awful.layout.inc(-1) end)
))
-- Create a taglist widget
s.mytaglist = awful.widget.taglist(s, awful.widget.taglist.filter.all, taglist_buttons)
-- Create a tasklist widget
s.mytasklist = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, tasklist_buttons)
-- Create the wibox
s.mywibox = awful.wibar({ position = "top", screen = s })
s.mywibox:setup {
layout = wibox.layout.align.horizontal,
{ -- Left widgets
layout = wibox.layout.fixed.horizontal,
mylauncher,
netwidget,
cpuwidget,
thermalwidget,
--gpuwidget,
--hddwidget,
memwidget,
--iowidget,
s.mytaglist,
s.mypromptbox
},
s.mytasklist,
{ -- Right widgets
layout = wibox.layout.fixed.horizontal,
wibox.widget.systray(),
batwidget,
oswidget,
--wifiwidget,
brightwidget,
volwidget,
mytextclock,
--langwidget,
s.mylayoutbox,
}
}
end)
-- }}}
-- {{{ Mouse bindings
root.buttons(awful.util.table.join(
awful.button({ }, 3, function () mymainmenu:toggle() end)
-- mouse wheel changes tag
--awful.button({ }, 4, awful.tag.viewnext),
--awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}
-- Move the focused window to the next tag
local function movetonexttag(delta)
-- Get a relative tag number
if client.focus then
local tags = client.focus.screen.tags
local tag = tags[(client.focus.first_tag.index + delta - 1) % #tags + 1]
if tag then
client.focus:move_to_tag(tag)
tag:view_only()
end
end
end
-- }}}
local touchpad_enabled = true
-- {{{ Key bindings
local globalkeys = awful.util.table.join(
-- Help popup
awful.key({ modkey }, "h", hotkeys_popup.show_help, {
description = "show help",
group="awesome"
}),
awful.key({ modkey }, "q", awesome.restart, {
description = "restart awesome",
group = "awesome"
}),
awful.key({ modkey, "Shift" }, "q", awesome.quit, {
description = "quit awesome",
group = "awesome"
}),
-- Tag jousting
awful.key({ modkey }, "Left", awful.tag.viewprev, {
description = "view previous",
group = "tag"
}),
awful.key({ modkey }, "Right", awful.tag.viewnext, {
description = "view next",
group = "tag"
}),
awful.key({ modkey }, "Escape", awful.tag.history.restore, {
description = "go back",
group = "tag"
}),
awful.key({ "Mod1", "Shift", "Control" }, "Left", function ()
movetonexttag(-1)
end, {
description = "move to previous tag",
group = "tag"
}),
awful.key({ "Mod1", "Shift", "Control" }, "Right", function ()
movetonexttag(1)
end, {
description = "move to next tag",
group = "tag"
}),
-- Client / focus
awful.key({ modkey, }, "j", function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end, {
description = "focus next",
group = "client"
}),
awful.key({ modkey, }, "l", function ()
awful.tag.incmwfact(0.05)
end, {
description = "expand right",
group = "client"
}),
awful.key({ modkey, }, "k", function ()
awful.tag.incmwfact(-0.05)
end, {
description = "expand left",
group = "client"
}),
awful.key({ "Mod1", }, "Tab", function ()
-- awful.client.focus.history.previous()
awful.client.focus.byidx(1)
if client.focus then
client.focus:raise()
end
end, {
description = "focus next window",
group = "client"
}),
awful.key({ "Mod1", "Shift" }, "Tab", function ()
-- awful.client.focus.history.previous()
awful.client.focus.byidx(-1)
if client.focus then
client.focus:raise()
end
end, {
description = "focus previous window",
group = "client"
}),
awful.key({ modkey, "Control" }, "n", awful.client.restore, {
description = "restore minimized",
group = "client"
}),
-- Screen
awful.key({ modkey, "Shift" }, "w", awful.client.movetoscreen, {
description = "move window to other screen",
group = "screen"
}),
awful.key({ modkey, }, "w", function ()
awful.screen.focus_relative(1)
end, {
description = "focus next screen",
group = "screen"
}),
awful.key({ modkey, "Control" }, "k", function ()
awful.screen.focus_relative(-1)
end, {
description = "focus previous screen",
group = "screen"
}),
-- Layout manipulation
--awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx(1) end),
--awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx(-1) end),
awful.key({ modkey, "Shift" }, "k", function ()
awful.tag.incnmaster( 1)
end, {
description = "increase the number of master clients",
group = "layout"
}),
awful.key({ modkey, "Shift" }, "l", function ()
awful.tag.incnmaster(-1)
end, {
description = "decrease the number of master clients",
group = "layout"
}),
awful.key({ modkey }, "Home", function ()
awful.client.swap.byidx(1)
end, {
description = "swap with next window",
group = "layout"
}),
awful.key({ modkey, }, "space", function ()
awful.layout.inc(1)
end, {
description = "change to next layout",
group = "layout"
}),
awful.key({ modkey, "Mod1" }, "space", function ()
awful.layout.inc(-1)
end, {
description = "change to previous layout",
group = "layout"
}),
-- Standard program
awful.key({ }, "Print", function ()
awful.util.spawn_with_shell("scrot /tmp/scr_$(date +%d-%m-%Y_%H:%M:%S).png && xclip -selection c -target image/png $_ && rm -f $_")
end, {
description = "copies a screenshot to clipboard",
group = "programs"
}),
awful.key({ modkey }, "Print", function ()
awful.util.spawn_with_shell("scrot $HOME/pictures/screenshots/$(date +%d-%m-%Y_%H:%M:%S).png")
end, {
description = "saves a screenshot in pictures/screenshots",
group = "programs"
}),
-- Why the nil is there? -> https://wiki.archlinux.org/index.php/Awesome#scrot:_Cannot_take_a_mouse_selected_screenshot_with_keyboard_shortcuts
awful.key({ modkey, "Shift" }, "s", nil, function ()
awful.util.spawn_with_shell("scrot -s /tmp/scr_$(date +%d-%m-%Y_%H:%M:%S).png && xclip -selection c -target image/png $_ && rm -f $_")
end, {
description = "saves a portion of the screen to the clipboard",
group = "programs"
}),
awful.key({ modkey, }, "Return", function ()
awful.util.spawn(terminal, {
tag = mouse.screen.selected_tag
})
end, {
description = "open terminal",
group = "programs"
}),
awful.key({ modkey, }, "t", function ()
awful.util.spawn(terminal, {
tag = mouse.screen.selected_tag
})
end, {
description = "open terminal",
group = "programs"
}),
awful.key({ modkey, }, "i", function ()
awful.util.spawn(browser, {
tag = mouse.screen.selected_tag
})
end, {
description = "open browser",
group = "programs"
}),
awful.key({ modkey, "Shift" }, "f", function ()
awful.util.spawn(filemanager, {
tag = mouse.screen.selected_tag
})
end, {
description = "open file manager",
group = "programs"
}),
awful.key({ modkey, "Control" }, "l", function ()
awful.util.spawn("xscreensaver-command --lock")
end, {
description = "lock screen",
group = "programs"
}),
--awful.key({ modkey, "Control" }, "k", function () awful.tag.incncol( 1) end),
--awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
-- System utils
awful.key({ modkey, }, "s", function ()
awful.util.spawn("/usr/local/bin/switchkbmap.sh")
end, {
description = "switch keyboard layout",
group = "system"
}),
-- Backlight (in case keys don't work out of the box)
--awful.key({ modkey, }, "F5", function () awful.util.spawn("xbacklight -dec 10") end),
--awful.key({ modkey, }, "F6", function () awful.util.spawn("xbacklight -inc 10") end),
--awful.key({ }, "XF86KbdBrightnessDown", function () awful.util.spawn("/usr/local/bin/kbacklight.sh dec") end),
--awful.key({ }, "XF86KbdBrightnessUp", function () awful.util.spawn("/usr/local/bin/kbacklight.sh inc") end),
awful.key({ modkey, }, "F5", function ()
awful.util.spawn("/usr/local/bin/backlight.sh -dec 10")
vicious.force({ brightwidget })
end, {
description = "decrease brightness",
group = "system"
}),
awful.key({ modkey, }, "F6", function ()
awful.util.spawn("/usr/local/bin/backlight.sh -inc 10")
vicious.force({ brightwidget })
end, {
description = "increase brightness",
group = "system"
}),
-- Volume control bindings (since kernel doesn't handle this by itself)
awful.key({ }, "XF86AudioRaiseVolume", function ()
awful.util.spawn("amixer set Master 5%+")
vicious.force({ volwidget })
end, {
description = "increase volume",
group = "system"
}),
awful.key({ }, "XF86AudioLowerVolume", function ()
awful.util.spawn("amixer set Master 5%-")
vicious.force({ volwidget })
end, {
description = "decrease volume",
group = "system"
}),
awful.key({ }, "XF86AudioMute", function ()
local f = io.popen("amixer get Speaker|grep Left|tail -1|awk '{print $4}'")
if tonumber(f:read()) > 0 then
awful.util.spawn("amixer set Speaker unmute")
else
awful.util.spawn("amixer set Headphone unmute")
end
awful.util.spawn("amixer set Master toggle")
f:close()
vicious.force({ volwidget })
end, {
description = "toggle mute",
group = "system"
}),
-- Touchpad controls
awful.key({ }, "XF86TouchpadToggle", function ()
local f = io.popen("xinput|grep Touchpad|cut -f2 -d=|cut -f1")
if touchpad_enabled then
awful.util.spawn("xinput disable " .. f:read())
else
awful.util.spawn("xinput enable " .. f:read())
end
f:close()
touchpad_enabled = not touchpad_enabled
end, {
description = "toggle touchpad",
group = "system"
}),
-- Prompt
--awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end)
awful.key({ modkey }, "r", function () menubar.show() end, {
description = "show menubar",
group = "awesome"
})
--awful.key({ modkey }, "x",
-- function ()
-- awful.prompt.run({ prompt = "Run Lua code: " },
-- mypromptbox[mouse.screen].widget,
-- awful.util.eval, nil,
-- awful.util.getdir("cache") .. "/history_eval")
-- end)
)
local clientkeys = awful.util.table.join(
awful.key({ modkey }, "f", function (c)
c.fullscreen = not c.fullscreen
end, {
description = "toggle fullscreen",
group = "client"
}),
awful.key({ modkey, "Shift" }, "c", function (c)
c:kill()
end, {
description = "kill client",
group = "client"
}),
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle, {
description = "toggle floating",
group = "client"
}),
awful.key({ modkey, "Control" }, "Return", function (c)
c:swap(awful.client.getmaster())
end, {
description = "swap window with master",
group = "client"
}),
awful.key({ modkey }, "o", awful.client.movetoscreen, {
description = "move to screen",
group = "client"
}),
awful.key({ modkey, "Control" }, "t", function (c)
c.ontop = not c.ontop
end, {
description = "toggle keep on top",
group = "client"
}),
awful.key({ modkey }, "n", function (c)
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.minimized = true
end, {
description = "minimize",
group = "client"
}),
awful.key({ modkey }, "m", function (c)
c.maximized = not c.maximized
c:raise()
end, {
description = "maximize",
group = "client"
}),
awful.key({ modkey, "Shift" }, "h", function (c)
c.maximized_horizontal = not c.maximized_horizontal
c:raise()
end, {
description = "maximize horizontally",
group = "client"
}),
awful.key({ modkey, "Shift" }, "v", function (c)
c.maximized_vertical = not c.maximized_vertical
c:raise()
end, {
description = "maximize vertically",
group = "client"
})
)
-- Bind all key numbers to tags.
-- Be careful: we use keycodes to make it works on any keyboard layout.
-- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, 9 do
globalkeys = awful.util.table.join(globalkeys,
-- View tag only
awful.key({ modkey }, "#" .. i + 9, function ()
local screen = awful.screen.focused()
local tag = screen.tags[i]
if tag then
tag:view_only()
end
end, {description = "view tag #"..i, group = "tag"}),
-- Toggle tag
awful.key({ modkey, "Control" }, "#" .. i + 9, function ()
local screen = awful.screen.focused()
local tag = screen.tags[i]
if tag then
awful.tag.viewtoggle(tag)
end
end, {description = "toggle tag #" .. i, group = "tag"}),
-- Move client to tag
awful.key({ modkey, "Shift" }, "#" .. i + 9, function ()
if client.focus then
local tag = client.focus.screen.tags[i]
if tag then
client.focus:move_to_tag(tag)
tag:view_only()
end
end
end, {description = "move focused client to tag #"..i, group = "tag"}),
-- Toggle tag
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, function ()
if client.focus then
local tag = client.focus.screen.tags[i]
if tag then
client.focus:toggle_tag(tag)
end
end
end, {description = "toggle focused client on tag #" .. i, group = "tag"})
)
end
local clientbuttons = awful.util.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize)
)
-- Set keys
root.keys(globalkeys)
-- }}}
-- {{{ Rules
-- Rules to apply to new clients (through the "manage" signal).
awful.rules.rules = {
-- All clients will match this rule.
{ rule = { },
properties = {
border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = awful.client.focus.filter,
raise = true,
keys = clientkeys,
buttons = clientbuttons }
},
{ rule = { class = "MPlayer" },
properties = { floating = true }
},
{ rule = { class = "pinentry" },
properties = { floating = true }
},
{ rule = { class = "gimp" },
properties = { floating = true }
},
-- Set Firefox to always map on tags number 2 of screen 1.
--{ rule = { class = "Firefox" },
--properties = { tag = awful.screen.focused().tags[5] } },
}
-- }}}
-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c, startup)
-- Enable sloppy focus
c:connect_signal("mouse::enter", function(c)
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
and awful.client.focus.filter(c)
then
client.focus = c
end
end)
if not startup then
-- Set the windows at the slave,
-- i.e. put it at the end of others instead of setting it master.
awful.client.setslave(c)
-- Put windows in a smart way, only if they do not set an initial position.
if not c.size_hints.user_position and not c.size_hints.program_position then
awful.placement.no_overlap(c)
awful.placement.no_offscreen(c)
end
end
local titlebars_enabled = false
if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
-- buttons for the titlebar
local buttons = awful.util.table.join(
awful.button({ }, 1, function()
client.focus = c
c:raise()
awful.mouse.client.move(c)
end),
awful.button({ }, 3, function()
client.focus = c
c:raise()
awful.mouse.client.resize(c)
end)
)
-- Widgets that are aligned to the left
local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(awful.titlebar.widget.iconwidget(c))
left_layout:buttons(buttons)
-- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal()
right_layout:add(awful.titlebar.widget.floatingbutton(c))
right_layout:add(awful.titlebar.widget.maximizedbutton(c))
right_layout:add(awful.titlebar.widget.stickybutton(c))
right_layout:add(awful.titlebar.widget.ontopbutton(c))
right_layout:add(awful.titlebar.widget.closebutton(c))
-- The title goes in the middle
local middle_layout = wibox.layout.flex.horizontal()
local title = awful.titlebar.widget.titlewidget(c)
title:set_align("center")
middle_layout:add(title)
middle_layout:buttons(buttons)
-- Now bring it all together
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_right(right_layout)
layout:set_middle(middle_layout)
awful.titlebar(c):set_widget(layout)
end
end)
client.connect_signal("focus", function(c)
-- don't draw borders on maximized windows
if c.maximized_horizontal and c.maximized_vertical then
c.border_width = "0"
else
c.border_width = beautiful.border_width
end
c.border_color = beautiful.border_focus
end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
-- }}}
-- {{{
-- https://gist.github.com/Flowkap/8858434
--
local function spawn_once(command, class, tag)
if tag ~= nil then
-- create move callback
local callback
callback = function(c)
if c.class == class then
c:move_to_tag(tag)
client.disconnect_signal("manage", callback)
end
end
client.connect_signal("manage", callback)
end
-- now check if not already running!
local findme = command
local firstspace = findme:find(" ")
if firstspace then
findme = findme:sub(0, firstspace-1)
end
-- finally run it
awful.util.spawn_with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || exec " .. command)
end
--local function spawn_once_new(command, _tag)
--awful.spawn(command, { tag = _tag })
--end
-- }}}
-- {{{ AUTOSTART
-- Remap Menu key to Mod key
awful.util.spawn_with_shell("sleep 2 && xmodmap -e \"keysym Menu = Super_L\"")
spawn_once("firefox https://www.duckduckgo.com", "Firefox", awful.screen.focused().tags[5])
-- Load YCM to memory to speedup next vim startup
--spawn_once("vim <<<:q!")
spawn_once("redshift-gtk")
spawn_once(terminal)
vicious.force({ volwidget })
vicious.force({ brightwidget })
-- }}}
--- Awesome 3.5 rc.lua
--- by silverweed
--- latest update 25/01/2017
-- {{{ User prefs
local terminal = "xfce4-terminal"
local editor = os.getenv("EDITOR") or "vim"
local editor_cmd = terminal .. " -e " .. editor
local filemanager = "pcmanfm"
local browser = "firefox"
-- }}}
-- Standard awesome library
local gears = require("gears")
local awful = require("awful")
awful.rules = require("awful.rules")
require("awful.autofocus")
-- Widget and layout library
local wibox = require("wibox")
-- Theme handling library
local beautiful = require("beautiful")
-- Notification library
local naughty = require("naughty")
local menubar = require("menubar")
-- Widget library
local vicious = require("vicious")
-- New "widget API"
local wibox = require("wibox")
-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
if awesome.startup_errors then
naughty.notify({
preset = naughty.config.presets.critical,
title = "Oops, there were errors during startup!",
text = awesome.startup_errors
})
end
-- Handle runtime errors after startup
do
local in_error = false
awesome.connect_signal("debug::error", function (err)
-- Make sure we don't go into an endless error loop
if in_error then return end
in_error = true
naughty.notify({
preset = naughty.config.presets.critical,
title = "Oops, an error happened!",
text = err
})
in_error = false
end)
end
-- }}}
-- {{{ Variable definitions
-- Themes define colours, icons, font and wallpapers.
beautiful.init("~/.config/awesome/themes/default-theme.lua")
-- Default modkey.
-- Usually, Mod4 is the key with a logo between Control and Alt.
-- If you do not like this or do not have such a key,
-- I suggest you to remap Mod4 to another key using xmodmap or other tools.
-- However, you can use another modifier like Mod1, but it may interact with others.
local modkey = "Mod4"
-- Table of layouts to cover with awful.layout.inc, order matters.
local layouts =
{
awful.layout.suit.tile,
-- awful.layout.suit.tile.left,
-- awful.layout.suit.tile.bottom,
awful.layout.suit.tile.top,
awful.layout.suit.fair,
-- awful.layout.suit.fair.horizontal,
-- awful.layout.suit.spiral,
-- awful.layout.suit.spiral.dwindle,
awful.layout.suit.max,
-- awful.layout.suit.max.fullscreen,
-- awful.layout.suit.floating,
-- awful.layout.suit.magnifier
}
-- }}}
-- {{{ Wallpaper
if beautiful.wallpaper then
for s = 1, screen.count() do
gears.wallpaper.maximized(beautiful.wallpaper, s, true)
end
end
-- }}}
-- {{{ Tags
-- Define a tag table which hold all screen tags.
local tags = {}
for s = 1, screen.count() do
-- Each screen has its own tag table.
tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
end
-- }}}
-- {{{ Menu
-- Create a laucher widget and a main menu
local myawesomemenu = {
{ "manual", terminal .. " -e man awesome" },
{ "edit config", editor_cmd .. " " .. awesome.conffile },
{ "restart", awesome.restart },
{ "quit", awesome.quit }
}
local mymainmenu = awful.menu({
items = {
{ "awesome", myawesomemenu, beautiful.awesome_icon },
{ "open terminal", terminal },
{ "reboot", terminal .. " -e reboot", beautiful.reboot_icon },
{ "poweroff", terminal .. " -e poweroff", beautiful.poweroff_icon }
}
})
local mylauncher = awful.widget.launcher({
image = beautiful.awesome_icon,
menu = mymainmenu
})
-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}
-- {{{ Wibox
-- Create a textclock widget
local mytextclock = awful.widget.textclock()
-- {{ Vicious widgets:
----Networking
local netwidget = wibox.widget.textbox()
vicious.register(netwidget, vicious.widgets.net, '<span color="#CC9393">d:${wlp2s0 down_kb} | ${enp3s0f1 down_kb}</span> <span color="#7F9F7F">u:${wlp2s0 up_kb} | ${enp3s0f1 up_kb}</span> ', 3)
----CPU
local cpuwidget = wibox.widget.textbox()
vicious.register(cpuwidget, vicious.widgets.cpu,'<span color="#33CCFF">cpu:</span>(<span color="#00AAAA">$2</span>|<span color="#00AAAA">$3</span>|<span color="#00AAAA">$4</span>|<span color="#00AAAA">$5</span>|<span color="#00AAAA">$6</span>|<span color="#00AAAA">$7</span>|<span color="#00AAAA">$8</span>|<span color="#00AAAA">$9</span>) ')
----RAM/SWAP
local memwidget = wibox.widget.textbox()
vicious.register(memwidget, vicious.widgets.mem, '<span color="#FF2052">ram:$1%</span>[<span color="#648C11">$5%</span>] ', 7)
----HDDTEMP
--local hddwidget = wibox.widget.textbox()
---vicious.register(hddwidget, vicious.widgets.hddtemp, "<span color='#FF9900'>sda:${/dev/sda}°C</span> ", 19)
----HDD I/O
--local iowidget = wibox.widget.textbox()
--vicious.register(iowidget, vicious.widgets.dio, "<span color='#FF9900'>(${sda total_s}%')</span>", 4)
----OS
oswidget = wibox.widget.textbox()
oswidget:set_align('right')
vicious.register(oswidget, vicious.widgets.os,'$4 $2 | ', 86401)
vicious.cache(oswidget)
----CPU temperature
local thermalwidget = wibox.widget.textbox()
vicious.register(thermalwidget, vicious.widgets.thermal, "$1°C ", 5, { "thermal_zone7", "sys" } )
----GPU temperature
--local gpuwidget = wibox.widget.textbox()
--vicious.register(gpuwidget, vicious.widgets.gpu, "<span color='#ff33cc'>gpu:$1°C</span> ", 19)
----VOLUME
local volwidget = wibox.widget.textbox()
vicious.register(volwidget,vicious.widgets.volume,'(($1)) $2', 86400, "Master")
vicious.cache(volwidget)
----WIFI
--local wifiwidget = wibox.widget.textbox()
--vicious.register(wifiwidget, vicious.widgets.wifi,'<span color="#CC44CC">wifi:${ssid} (${linp}%)</span> ',3,"wlp2s0")
----Battery
local batwidget = wibox.widget.textbox()
vicious.register(batwidget, vicious.widgets.mybat,' <span color="#00AACC">bat:$2% ($1 $3h)</span> | ', 61, "BAT0")
----Brightness
local brightwidget = wibox.widget.textbox()
vicious.register(brightwidget, vicious.widgets.brightness, '<span color="#00FF00">☀${perc}%</span> ', 86400,
"/sys/class/backlight/intel_backlight")
vicious.cache(brightwidget)
----Keyboard layout
--local langwidget = wibox.widget.textbox()
--vicious.register(langwidget, vicious.widgets.lang, '[$1] ', 6)
-- }}
-- Create a wibox for each screen and add it
local mywibox = {}
local mypromptbox = {}
local mylayoutbox = {}
local mytaglist = {}
mytaglist.buttons = awful.util.table.join(
awful.button({ }, 1, awful.tag.viewonly),
awful.button({ modkey }, 1, awful.client.movetotag),
awful.button({ }, 3, awful.tag.viewtoggle),
awful.button({ modkey }, 3, awful.client.toggletag),
awful.button({ }, 4, function(t) awful.tag.viewnext(awful.tag.getscreen(t)) end),
awful.button({ }, 5, function(t) awful.tag.viewprev(awful.tag.getscreen(t)) end)
)
local mytasklist = {}
mytasklist.buttons = awful.util.table.join(
awful.button({ }, 1, function (c)
if c == client.focus then
c.minimized = true
else
-- Without this, the following
-- :isvisible() makes no sense
c.minimized = false
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
-- This will also un-minimize
-- the client, if needed
client.focus = c
c:raise()
end
end),
awful.button({ }, 3, function ()
if instance then
instance:hide()
instance = nil
else
instance = awful.menu.clients({
theme = { width = 250 }
})
end
end),
awful.button({ }, 4, function ()
awful.client.focus.byidx(1)
if client.focus then client.focus:raise() end
end),
awful.button({ }, 5, function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end)
)
for s = 1, screen.count() do
-- Create a promptbox for each screen
mypromptbox[s] = awful.widget.prompt()
-- Create an imagebox widget which will contains an icon indicating which layout we're using.
-- We need one layoutbox per screen.
mylayoutbox[s] = awful.widget.layoutbox(s)
mylayoutbox[s]:buttons(awful.util.table.join(
awful.button({ }, 1, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 3, function () awful.layout.inc(layouts, -1) end),
awful.button({ }, 4, function () awful.layout.inc(layouts, 1) end),
awful.button({ }, 5, function () awful.layout.inc(layouts, -1) end)))
-- Create a taglist widget
mytaglist[s] = awful.widget.taglist(s, awful.widget.taglist.filter.all, mytaglist.buttons)
-- Create a tasklist widget
mytasklist[s] = awful.widget.tasklist(s, awful.widget.tasklist.filter.currenttags, mytasklist.buttons)
-- Create the wibox
mywibox[s] = awful.wibox({ position = "top", screen = s })
-- Widgets that are aligned to the left
local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(mylauncher)
left_layout:add(netwidget)
left_layout:add(cpuwidget)
left_layout:add(thermalwidget)
--left_layout:add(gpuwidget)
--left_layout:add(hddwidget)
left_layout:add(memwidget)
--left_layout:add(iowidget)
left_layout:add(mytaglist[s])
left_layout:add(mypromptbox[s])
-- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal()
if s == 1 then right_layout:add(wibox.widget.systray()) end
right_layout:add(batwidget)
right_layout:add(oswidget)
--right_layout:add(wifiwidget)
right_layout:add(brightwidget)
right_layout:add(volwidget)
right_layout:add(mytextclock)
--right_layout:add(langwidget)
right_layout:add(mylayoutbox[s])
-- Now bring it all together (with the tasklist in the middle)
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_middle(mytasklist[s])
layout:set_right(right_layout)
mywibox[s]:set_widget(layout)
end
-- }}}
-- {{{ Mouse bindings
root.buttons(awful.util.table.join(
awful.button({ }, 3, function () mymainmenu:toggle() end)
-- mouse wheel changes tag
--awful.button({ }, 4, awful.tag.viewnext),
--awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}
-- {{{ These lines are used for the function "movetonexttag" {{{
-- Get a relative tag number
function getrelativetag(delta, screen)
return (awful.tag.getidx(selected) + delta - 1) % #tags[screen] + 1
end
-- Move the focused window to the next tag
function movetonexttag(delta)
local stags = {}
if client.focus then
stags = tags[client.focus.screen]
awful.client.movetotag(stags[getrelativetag(delta, 1)])
else
stags = tags[1]
end
awful.tag.viewonly(stags[getrelativetag(delta, 1)])
end
-- }}}
local touchpad_enabled = true
-- {{{ Key bindings
local globalkeys = awful.util.table.join(
-- Tag jousting
awful.key({ modkey, }, "Left", awful.tag.viewprev),
awful.key({ modkey, }, "Right", awful.tag.viewnext),
awful.key({ modkey, }, "Escape", awful.tag.history.restore),
awful.key({ modkey, }, "s", function () awful.util.spawn("/usr/local/bin/switchkbmap.sh") end),
awful.key({ "Mod1", "Shift", "Control" }, "Left", function () movetonexttag(-1) end),
awful.key({ "Mod1", "Shift", "Control" }, "Right", function () movetonexttag(1) end),
awful.key({ modkey, "Shift" }, "w", awful.client.movetoscreen),
awful.key({ modkey, }, "w", function () awful.screen.focus_relative(1) end),
awful.key({ modkey, }, "j", function ()
awful.client.focus.byidx( 1)
if client.focus then client.focus:raise() end
end),
awful.key({ modkey, }, "k", function ()
awful.client.focus.byidx(-1)
if client.focus then client.focus:raise() end
end),
-- Layout manipulation
awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx(1) end),
awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx(-1) end),
awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative(1) end),
awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end),
awful.key({ modkey }, "Home", function () awful.client.swap.byidx(1) end),
awful.key({ modkey, }, "u", awful.client.urgent.jumpto),
awful.key({ "Mod1", }, "Tab", function ()
-- awful.client.focus.history.previous()
awful.client.focus.byidx(1)
if client.focus then
client.focus:raise()
end
end),
awful.key({ "Mod1", "Shift" }, "Tab", function ()
-- awful.client.focus.history.previous()
awful.client.focus.byidx(-1)
if client.focus then
client.focus:raise()
end
end),
-- Standard program
awful.key({ }, "Print", function ()
awful.util.spawn_with_shell("scrot $HOME/pictures/screenshots/$(date +%d-%m-%Y_%H:%M:%S).png")
end),
awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
awful.key({ modkey, }, "t", function () awful.util.spawn(terminal) end),
awful.key({ modkey, }, "i", function () awful.util.spawn(browser) end),
awful.key({ modkey, "Shift" }, "f", function () awful.util.spawn(filemanager) end),
awful.key({ modkey, }, "q", awesome.restart),
awful.key({ modkey, "Shift" }, "q", awesome.quit),
awful.key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),
awful.key({ modkey, }, "k", function () awful.tag.incmwfact(-0.05) end),
awful.key({ modkey, "Shift" }, "k", function () awful.tag.incnmaster( 1) end),
awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),
awful.key({ modkey, "Control" }, "l", function () awful.util.spawn("xscreensaver-command --lock") end),
awful.key({ modkey, "Control" }, "k", function () awful.tag.incncol( 1) end),
awful.key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),
awful.key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),
awful.key({ modkey, "Mod1" }, "space", function () awful.layout.inc(layouts, -1) end),
awful.key({ modkey, "Control" }, "n", awful.client.restore),
-- Backlight (in case keys don't work out of the box)
--awful.key({ modkey, }, "F5", function () awful.util.spawn("xbacklight -dec 10") end),
--awful.key({ modkey, }, "F6", function () awful.util.spawn("xbacklight -inc 10") end),
--awful.key({ }, "XF86KbdBrightnessDown", function () awful.util.spawn("/usr/local/bin/kbacklight.sh dec") end),
--awful.key({ }, "XF86KbdBrightnessUp", function () awful.util.spawn("/usr/local/bin/kbacklight.sh inc") end),
awful.key({ modkey, }, "F5", function ()
awful.util.spawn("/usr/local/bin/backlight.sh -dec 10")
vicious.force({ brightwidget })
end),
awful.key({ modkey, }, "F6", function ()
awful.util.spawn("/usr/local/bin/backlight.sh -inc 10")
vicious.force({ brightwidget })
end),
-- Volume control bindings (since kernel doesn't handle this by itself)
awful.key({ }, "XF86AudioRaiseVolume", function ()
awful.util.spawn("amixer set Master 5%+")
vicious.force({ volwidget })
end),
awful.key({ }, "XF86AudioLowerVolume", function ()
awful.util.spawn("amixer set Master 5%-")
vicious.force({ volwidget })
end),
awful.key({ }, "XF86AudioMute", function ()
local f = io.popen("amixer get Speaker|grep Left|tail -1|awk '{print $4}'")
if tonumber(f:read()) > 0 then
awful.util.spawn("amixer set Speaker unmute")
else
awful.util.spawn("amixer set Headphone unmute")
end
awful.util.spawn("amixer set Master toggle")
f:close()
vicious.force({ volwidget })
end),
-- Touchpad controls
awful.key({ }, "XF86TouchpadToggle", function ()
local f = io.popen("xinput|grep Touchpad|cut -f2 -d=|cut -f1")
if touchpad_enabled then
awful.util.spawn("xinput disable " .. f:read())
else
awful.util.spawn("xinput enable " .. f:read())
end
f:close()
touchpad_enabled = not touchpad_enabled
end),
-- Prompt
--awful.key({ modkey }, "r", function () mypromptbox[mouse.screen]:run() end)
awful.key({ modkey }, "r", function () menubar.show() end)
--awful.key({ modkey }, "x",
-- function ()
-- awful.prompt.run({ prompt = "Run Lua code: " },
-- mypromptbox[mouse.screen].widget,
-- awful.util.eval, nil,
-- awful.util.getdir("cache") .. "/history_eval")
-- end)
)
local clientkeys = awful.util.table.join(
awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),
awful.key({ modkey, "Shift" }, "c", function (c) c:kill() end),
awful.key({ modkey, "Control" }, "space", awful.client.floating.toggle ),
awful.key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),
awful.key({ modkey, }, "o", awful.client.movetoscreen ),
awful.key({ modkey, }, "t", function (c) c.ontop = not c.ontop end),
awful.key({ modkey, }, "n", function (c)
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.minimized = true
end),
awful.key({ modkey, }, "m", function (c)
c.maximized_horizontal = not c.maximized_horizontal
c.maximized_vertical = not c.maximized_vertical
end)
)
-- Bind all key numbers to tags.
-- Be careful: we use keycodes to make it works on any keyboard layout.
-- This should map on the top row of your keyboard, usually 1 to 9.
for i = 1, 9 do
globalkeys = awful.util.table.join(globalkeys,
-- View tag only
awful.key({ modkey }, "#" .. i + 9, function ()
local screen = mouse.screen
local tag = awful.tag.gettags(screen)[i]
if tag then
awful.tag.viewonly(tag)
end
end),
-- Toggle tag
awful.key({ modkey, "Control" }, "#" .. i + 9, function ()
local screen = mouse.screen
local tag = awful.tag.gettags(screen)[i]
if tag then
awful.tag.viewtoggle(tag)
end
end),
-- Move client to tag
awful.key({ modkey, "Shift" }, "#" .. i + 9, function ()
if client.focus then
local tag = awful.tag.gettags(client.focus.screen)[i]
if tag then
awful.client.movetotag(tag)
end
end
end),
-- Toggle tag
awful.key({ modkey, "Control", "Shift" }, "#" .. i + 9, function ()
if client.focus then
local tag = awful.tag.gettags(client.focus.screen)[i]
if tag then
awful.client.toggletag(tag)
end
end
end))
end
local clientbuttons = awful.util.table.join(
awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
awful.button({ modkey }, 1, awful.mouse.client.move),
awful.button({ modkey }, 3, awful.mouse.client.resize)
)
-- Set keys
root.keys(globalkeys)
-- }}}
-- {{{ Rules
-- Rules to apply to new clients (through the "manage" signal).
awful.rules.rules = {
-- All clients will match this rule.
{ rule = { },
properties = {
border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = awful.client.focus.filter,
raise = true,
keys = clientkeys,
buttons = clientbuttons }
},
{ rule = { class = "MPlayer" },
properties = { floating = true }
},
{ rule = { class = "pinentry" },
properties = { floating = true }
},
{ rule = { class = "gimp" },
properties = { floating = true }
},
-- Set Firefox to always map on tags number 2 of screen 1.
-- { rule = { class = "Firefox" },
-- properties = { tag = tags[1][2] } },
}
-- }}}
-- {{{ Signals
-- Signal function to execute when a new client appears.
client.connect_signal("manage", function (c, startup)
-- Enable sloppy focus
c:connect_signal("mouse::enter", function(c)
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier
and awful.client.focus.filter(c)
then
client.focus = c
end
end)
if not startup then
-- Set the windows at the slave,
-- i.e. put it at the end of others instead of setting it master.
awful.client.setslave(c)
-- Put windows in a smart way, only if they do not set an initial position.
if not c.size_hints.user_position and not c.size_hints.program_position then
awful.placement.no_overlap(c)
awful.placement.no_offscreen(c)
end
end
local titlebars_enabled = false
if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
-- buttons for the titlebar
local buttons = awful.util.table.join(
awful.button({ }, 1, function()
client.focus = c
c:raise()
awful.mouse.client.move(c)
end),
awful.button({ }, 3, function()
client.focus = c
c:raise()
awful.mouse.client.resize(c)
end)
)
-- Widgets that are aligned to the left
local left_layout = wibox.layout.fixed.horizontal()
left_layout:add(awful.titlebar.widget.iconwidget(c))
left_layout:buttons(buttons)
-- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal()
right_layout:add(awful.titlebar.widget.floatingbutton(c))
right_layout:add(awful.titlebar.widget.maximizedbutton(c))
right_layout:add(awful.titlebar.widget.stickybutton(c))
right_layout:add(awful.titlebar.widget.ontopbutton(c))
right_layout:add(awful.titlebar.widget.closebutton(c))
-- The title goes in the middle
local middle_layout = wibox.layout.flex.horizontal()
local title = awful.titlebar.widget.titlewidget(c)
title:set_align("center")
middle_layout:add(title)
middle_layout:buttons(buttons)
-- Now bring it all together
local layout = wibox.layout.align.horizontal()
layout:set_left(left_layout)
layout:set_right(right_layout)
layout:set_middle(middle_layout)
awful.titlebar(c):set_widget(layout)
end
end)
client.connect_signal("focus", function(c)
-- don't draw borders on maximized windows
if c.maximized_horizontal and c.maximized_vertical then
c.border_width = "0"
else
c.border_width = beautiful.border_width
end
c.border_color = beautiful.border_focus
end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
-- }}}
-- {{{
-- https://gist.github.com/Flowkap/8858434
--
local function spawn_once(command, class, tag)
if tag ~= nil then
-- create move callback
local callback
callback = function(c)
if c.class == class then
awful.client.movetotag(tag, c)
client.disconnect_signal("manage", callback)
end
end
client.connect_signal("manage", callback)
end
-- now check if not already running!
local findme = command
local firstspace = findme:find(" ")
if firstspace then
findme = findme:sub(0, firstspace-1)
end
-- finally run it
awful.util.spawn_with_shell("pgrep -u $USER -x " .. findme .. " > /dev/null || exec " .. command)
end
-- }}}
-- remap Menu key to Super_L
awful.util.spawn_with_shell("sleep 2 && xmodmap -e \"keysym Menu = Super_L\"")
-- {{{ AUTOSTART
spawn_once("firefox www.google.com", "Firefox", tags[1][9])
-- Load YCM to memory to speedup next vim startup
--spawn_once("vim <<<:q!")
spawn_once(terminal)
-- }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment