X-Git-Url: https://git.madduck.net/etc/awesome.git/blobdiff_plain/00e8ae90e85e6cfa55b0cab8e3fdf37bd49fd12b..bfd2f3d9e50c286c22a745816828a33c157a7487:/.config/awesome/rc.lua?ds=sidebyside;pf=etc diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index ae354e7..5a4db69 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -1,3 +1,4 @@ +-- {{{ Imports -- Standard awesome library local gears = require("gears") local awful = require("awful") @@ -6,10 +7,24 @@ require("awful.autofocus") local wibox = require("wibox") -- Theme handling library local beautiful = require("beautiful") +local xrdb = beautiful.xresources -- Notification library local naughty = require("naughty") local menubar = require("menubar") local hotkeys_popup = require("awful.hotkeys_popup").widget +-- Enable hotkeys help widget for VIM and other apps +-- when client with a matching name is opened: +require("awful.hotkeys_popup.keys") + +-- Load Debian menu entries +local debian = require("debian.menu") +local has_fdo, freedesktop = pcall(require, "freedesktop") +-- Other libraries +local tblutils = require("tblutils") +local lain = require("lain") +local ccwidgets = require("cryptocoin_widgets") +local clocksarray = require("clocksarray") +-- }}} -- {{{ Error handling -- Check if awesome encountered an error during startup and fell back to @@ -37,12 +52,16 @@ end -- }}} -- {{{ Variable definitions --- Themes define colours, icons, and wallpapers -beautiful.init(awful.util.get_themes_dir() .. "default/theme.lua") +--xrdb.set_dpi(95, screen[1]) +--xrdb.set_dpi(120, screen[2]) + +-- Themes define colours, icons, font and wallpapers. +beautiful.init(gears.filesystem.get_themes_dir() .. "default/theme.lua") +beautiful.font = 'Sans 10' -- This is used later as the default terminal and editor to run. -terminal = "xterm" -editor = os.getenv("EDITOR") or "nano" +terminal = "x-terminal-emulator" +editor = os.getenv("EDITOR") or "editor" editor_cmd = terminal .. " -e " .. editor -- Default modkey. @@ -51,6 +70,7 @@ editor_cmd = terminal .. " -e " .. editor -- 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. modkey = "Mod4" +cmdkey = "Mod3" -- Table of layouts to cover with awful.layout.inc, order matters. awful.layout.layouts = { @@ -71,6 +91,11 @@ awful.layout.layouts = { -- awful.layout.suit.corner.sw, -- awful.layout.suit.corner.se, } + +layout_default = awful.layout.layouts[6] +layout_tiled = awful.layout.layouts[2] +layout_maximised = awful.layout.layouts[10] +layout_floating = awful.layout.layouts[1] -- }}} -- {{{ Helper functions @@ -86,6 +111,18 @@ local function client_menu_toggle_fn() end 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 -- }}} -- {{{ Menu @@ -95,13 +132,27 @@ myawesomemenu = { { "manual", terminal .. " -e man awesome" }, { "edit config", editor_cmd .. " " .. awesome.conffile }, { "restart", awesome.restart }, - { "quit", awesome.quit } + { "quit", function() awesome.quit() end} } -mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, - { "open terminal", terminal } - } - }) +local menu_awesome = { "awesome", myawesomemenu, beautiful.awesome_icon } +local menu_terminal = { "open terminal", terminal } + +if has_fdo then + mymainmenu = freedesktop.menu.build({ + before = { menu_awesome }, + after = { menu_terminal } + }) +else + mymainmenu = awful.menu({ + items = { + menu_awesome, + { "Debian", debian.menu.Debian_menu.Debian }, + menu_terminal, + } + }) +end + mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, menu = mymainmenu }) @@ -110,19 +161,31 @@ mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon, menubar.utils.terminal = terminal -- Set the terminal for applications that require it -- }}} +-- {{{ Wibar +local spacer = wibox.widget.textbox() +spacer:set_text(' │ ') + -- Keyboard map indicator and switcher mykeyboardlayout = awful.widget.keyboardlayout() --- {{{ Wibox +local lain_bat = lain.widget.bat({ + batteries = {"BAT0", "BAT1"}, + settings = function() + local delim = "↓" + if bat_now.status == "Charging" then delim = "↑" + elseif bat_now.status == "Unknown" then delim = "٭" end + widget:set_text(bat_now.perc .. "% " .. delim .. " " .. bat_now.time) + end, +}) + -- Create a textclock widget -mytextclock = wibox.widget.textclock() +clocksarray = clocksarray.get_clocksarray("%a %d %b %H:%M:%S %Z", { + ["NZ"] = "Pacific/Auckland", + ["DE"] = "Europe/Berlin" + }, spacer) -- Create a wibox for each screen and add it -mywibox = {} -mypromptbox = {} -mylayoutbox = {} -mytaglist = {} -mytaglist.buttons = awful.util.table.join( +local taglist_buttons = gears.table.join( awful.button({ }, 1, function(t) t:view_only() end), awful.button({ modkey }, 1, function(t) if client.focus then @@ -139,11 +202,11 @@ mytaglist.buttons = awful.util.table.join( awful.button({ }, 5, function(t) awful.tag.viewprev(t.screen) end) ) -mytasklist = {} -mytasklist.buttons = awful.util.table.join( +local tasklist_buttons = gears.table.join( awful.button({ }, 1, function (c) if c == client.focus then - c.minimized = true + -- I don't like click-minimising + -- c.minimized = true else -- Without this, the following -- :isvisible() makes no sense @@ -164,20 +227,58 @@ mytasklist.buttons = awful.util.table.join( awful.button({ }, 5, function () awful.client.focus.byidx(-1) end)) +-- }}} + +-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution) +screen.connect_signal("property::geometry", set_wallpaper) + +-- {{{ Tags +tags = {} +tags.config = {} +tags.config["main"] = { + t1 = { layout = layout_default, selected = true }, + t2 = { layout = layout_default }, + t3 = { layout = layout_tiled }, + t4 = { layout = layout_tiled }, + t5 = { layout = layout_tiled }, + t6 = { layout = layout_floating }, + t7 = { layout = layout_maximised }, + t8 = { layout = layout_maximised }, + t9 = { layout = layout_maximised }, +} +tags.config["aux"] = { + t1 = { layout = layout_default, selected = true }, + t2 = { layout = layout_default }, + t3 = { layout = layout_tiled }, + t4 = { layout = layout_floating }, + t5 = { layout = layout_floating }, + t6 = { layout = layout_floating }, + t7 = { layout = layout_floating }, + t8 = { layout = layout_floating }, + t9 = { layout = layout_maximised }, +} + +screentags = {} +screentags[1] = tags.config["main"] +if screen.count() == 2 then -- aux screen is on the right + screentags[2] = tags.config["aux"] +elseif screen.count() == 3 then -- main screen is still #1 in the middle + screentags[2] = tags.config["aux"] + screentags[3] = tags.config["aux"] +end awful.screen.connect_for_each_screen(function(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 + -- local fontsize = math.floor(250 * xrdb.get_dpi(s)/s.geometry.width) + -- beautiful.font = "Sans " .. tostring(fontsize) - -- Each screen has its own tag table. - awful.tag({ "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1]) + if not tags[s.index] then + tags[s.index] = {} + end + for n,p in tblutils.sorted_pairs(screentags[s.index]) do + p["screen"] = s + n = string.sub(n, 2) -- remove leading 't' needed for syntax in table + table.insert(tags[s.index], awful.tag.add(n, p)) + end -- Create a promptbox for each screen mypromptbox[s] = awful.widget.prompt() @@ -203,24 +304,34 @@ awful.screen.connect_for_each_screen(function(s) layout = wibox.layout.align.horizontal, { -- Left widgets layout = wibox.layout.fixed.horizontal, - mylauncher, + -- mylauncher, mytaglist[s], mypromptbox[s], }, mytasklist[s], -- Middle widget - { -- Right widgets - layout = wibox.layout.fixed.horizontal, - mykeyboardlayout, - wibox.widget.systray(), - mytextclock, - mylayoutbox[s], - }, + awful.util.table.join( -- Right widgets + { + layout = wibox.layout.fixed.horizontal, + mykeyboardlayout, + wibox.widget.systray(), + ccwidgets.btc_widget, + spacer, + ccwidgets.eth_widget, + spacer, + lain_bat.widget, + spacer, + }, + clocksarray, + { + mylayoutbox[s], + } + ), } end) -- }}} -- {{{ Mouse bindings -root.buttons(awful.util.table.join( +root.buttons(gears.table.join( awful.button({ }, 3, function () mymainmenu:toggle() end), awful.button({ }, 4, awful.tag.viewnext), awful.button({ }, 5, awful.tag.viewprev) @@ -228,7 +339,7 @@ root.buttons(awful.util.table.join( -- }}} -- {{{ Key bindings -globalkeys = awful.util.table.join( +globalkeys = gears.table.join( awful.key({ modkey, }, "s", hotkeys_popup.show_help, {description="show help", group="awesome"}), awful.key({ modkey, }, "Left", awful.tag.viewprev, @@ -238,13 +349,13 @@ globalkeys = awful.util.table.join( awful.key({ modkey, }, "Escape", awful.tag.history.restore, {description = "go back", group = "tag"}), - awful.key({ modkey, }, "j", + awful.key({ modkey, }, "k", function () awful.client.focus.byidx( 1) end, {description = "focus next by index", group = "client"} ), - awful.key({ modkey, }, "k", + awful.key({ modkey, }, "j", function () awful.client.focus.byidx(-1) end, @@ -254,13 +365,13 @@ globalkeys = awful.util.table.join( {description = "show main menu", group = "awesome"}), -- 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, {description = "swap with next client by index", group = "client"}), - awful.key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end, + awful.key({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( -1) end, {description = "swap with previous client by index", group = "client"}), - awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative( 1) end, + awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative( 1) end, {description = "focus the next screen", group = "screen"}), - awful.key({ modkey, "Control" }, "k", function () awful.screen.focus_relative(-1) end, + awful.key({ modkey, "Control" }, "j", function () awful.screen.focus_relative(-1) end, {description = "focus the previous screen", group = "screen"}), awful.key({ modkey, }, "u", awful.client.urgent.jumpto, {description = "jump to urgent client", group = "client"}), @@ -310,15 +421,17 @@ globalkeys = awful.util.table.join( {description = "restore minimized", group = "client"}), -- Prompt - awful.key({ modkey }, "r", function () mypromptbox[awful.screen.focused()]:run() end, + awful.key({ modkey }, "r", function () awful.screen.focused().mypromptbox:run() end, {description = "run prompt", group = "launcher"}), awful.key({ modkey }, "x", function () - awful.prompt.run({ prompt = "Run Lua code: " }, - mypromptbox[awful.screen.focused()].widget, - awful.util.eval, nil, - awful.util.get_cache_dir() .. "/history_eval") + awful.prompt.run { + prompt = "Run Lua code: ", + textbox = awful.screen.focused().mypromptbox.widget, + exe_callback = awful.util.eval, + history_path = awful.util.get_cache_dir() .. "/history_eval" + } end, {description = "lua execute prompt", group = "awesome"}), -- Menubar @@ -326,7 +439,7 @@ globalkeys = awful.util.table.join( {description = "show the menubar", group = "launcher"}) ) -clientkeys = awful.util.table.join( +clientkeys = gears.table.join( awful.key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen @@ -353,16 +466,30 @@ clientkeys = awful.util.table.join( awful.key({ modkey, }, "m", function (c) c.maximized = not c.maximized + c.maximized_horizontal = false + c.maximized_vertical = false + c:raise() + end , + {description = "(un)maximize", group = "client"}), + awful.key({ modkey, "Control" }, "m", + function (c) + c.maximized_vertical = not c.maximized_vertical c:raise() end , - {description = "maximize", group = "client"}) + {description = "(un)maximize vertically", group = "client"}), + awful.key({ modkey, "Shift" }, "m", + function (c) + c.maximized_horizontal = not c.maximized_horizontal + c:raise() + end , + {description = "(un)maximize horizontally", group = "client"}) ) -- Bind all key numbers to tags. --- Be careful: we use keycodes to make it works on any keyboard layout. +-- Be careful: we use keycodes to make it work 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, + globalkeys = gears.table.join(globalkeys, -- View tag only. awful.key({ modkey }, "#" .. i + 9, function () @@ -373,7 +500,7 @@ for i = 1, 9 do end end, {description = "view tag #"..i, group = "tag"}), - -- Toggle tag. + -- Toggle tag display. awful.key({ modkey, "Control" }, "#" .. i + 9, function () local screen = awful.screen.focused() @@ -408,17 +535,59 @@ for i = 1, 9 do ) end -clientbuttons = awful.util.table.join( +clientbuttons = gears.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)) +-- misc apps +globalkeys = awful.util.table.join(globalkeys, +awful.key({ cmdkey }, "n", function () awful.spawn("firefox") end), +awful.key({ cmdkey }, "m", function () awful.spawn("chromium --enable-remote-extensions") end), +awful.key({ cmdkey }, "y", function () awful.spawn(terminal .. " -e python") end), +awful.key({ cmdkey }, "c", function () awful.spawn("thunderbird") end), +awful.key({ cmdkey }, "r", function () mypromptbox[mouse.screen]:run() end), +awful.key({ cmdkey }, "g", function () awful.spawn("gscan2pdf") end), +awful.key({ cmdkey }, "v", function () awful.spawn("virt-manager") end), +awful.key({ cmdkey }, "l", function () awful.spawn("libreoffice") end), +awful.key({ cmdkey }, "f", function () awful.spawn("thunar") end), +awful.key({ cmdkey }, "i", function () awful.spawn(terminal .. " -name irc -e env MOSH_TITLE_NOPREFIX=true mosh -4 -- irc-host tmux new -As irc irssi") end), +awful.key({ cmdkey }, "x", function () awful.spawn.with_shell("/sbin/start-stop-daemon --start --background --exec /usr/bin/xscreensaver -- -no-capture-stderr; sleep 2; xscreensaver-command -lock") end), +awful.key({ cmdkey, "Shift" }, "x", function () awful.spawn("xscreensaver-command -exit") end), + +-- function keys +awful.key(nil, "XF86ScreenSaver", function () awful.spawn("xset dpms force off") end), +awful.key(nil, "XF86AudioMute", function () awful.spawn("pactl set-sink-mute 0 toggle") end), +awful.key({ cmdkey }, "End", function () awful.spawn("pactl set-sink-mute 0 toggle") end), +awful.key(nil, "XF86AudioLowerVolume", function () awful.spawn("pactl set-sink-volume 0 -2%") end), +awful.key({ cmdkey }, "Next", function () awful.spawn("pactl set-sink-volume 0 -2%") end), +awful.key(nil, "XF86AudioRaiseVolume", function () awful.spawn("pactl set-sink-volume 0 +2%") end), +awful.key({ cmdkey }, "Prior", function () awful.spawn("pactl set-sink-volume 0 +2%") end), +awful.key(nil, "XF86AudioMicMute", function () awful.spawn("pactl set-source-mute 1 toggle") end), +awful.key({ cmdkey }, "Home", function () awful.spawn("pactl set-source-mute 1 toggle") end), +awful.key(nil, "XF86MonBrightnessDown", function () awful.spawn("xbacklight -dec 5%") end), +awful.key(nil, "XF86MonBrightnessUp", function () awful.spawn("xbacklight -inc 5%") end), +awful.key(nil, "XF86Display", function () awful.spawn("") end), +awful.key(nil, "XF86WLAN", function () awful.spawn("") end), +awful.key(nil, "XF86Tools", function () awful.spawn("") end), +awful.key(nil, "XF86Search", function () awful.spawn("") end), +awful.key(nil, "XF86LaunchA", function () awful.spawn("") end), +awful.key(nil, "XF86Explorer", function () awful.spawn("") end) +) + -- Set keys root.keys(globalkeys) -- }}} -- {{{ Rules -- Rules to apply to new clients (through the "manage" signal). + +local function move_to_tag(s, t) + return function(c) + c:move_to_tag(tags[s][t]) + end +end + awful.rules.rules = { -- All clients will match this rule. { rule = { }, @@ -428,44 +597,89 @@ awful.rules.rules = { raise = true, keys = clientkeys, buttons = clientbuttons, - placement = awful.placement.no_overlap+awful.placement.no_offscreen - } + screen = awful.screen.preferred, + placement = awful.placement.no_overlap+awful.placement.no_offscreen, + floating = false + }, }, - -- Floating clients. - { rule_any = { - instance = { - "DTA", -- Firefox addon DownThemAll. - "copyq", -- Includes session name in class. - }, - class = { - "Arandr", - "Gpick", - "Kruler", - "MessageWin", -- kalarm. - "Sxiv", - "Wpa_gui", - "pinentry", - "veromix", - "xtightvncviewer"}, - - name = { - "Event Tester", -- xev. - }, - role = { - "AlarmWindow", -- Thunderbird's calendar. - "pop-up", -- e.g. Google Chrome's (detached) Developer Tools. - } - }, properties = { floating = true }}, - -- Add titlebars to normal clients and dialogs - { rule_any = {type = { "normal", "dialog" } - }, properties = { titlebars_enabled = true } + --DISABLED-- { rule_any = {type = { "normal", "dialog" } + --DISABLED-- }, properties = { titlebars_enabled = true } + --DISABLED-- }, + + { rule = { type = "dialog" }, + properties = { floating = true, + placement = awful.placement.centered + } }, - -- Set Firefox to always map on the tag named "2" on screen 1. - -- { rule = { class = "Firefox" }, - -- properties = { screen = 1, tag = "2" } }, + { rule = { class = "URxvt" }, + properties = { + -- floating = false, + size_hints_honor = false + } }, + { rule = { class = "URxvt", instance = "irc" }, + properties = { + switchtotag = true + }, + callback = move_to_tag(screen.count(), screen.count() == 1 and 2 or 1) + }, + { rule = { class = "Firefox", instance = "Navigator" }, + properties = { + floating = false, + }, + callback = move_to_tag(screen.count() == 1 and 1 or 2, 9) + }, + { rule = { class = "Firefox-esr", instance = "Navigator" }, + properties = { + floating = false, + }, + callback = move_to_tag(screen.count() == 1 and 1 or 2, 9) + }, + { rule = { class = "Thunderbird", instance = "Mail" }, + properties = { + floating = false, + }, + callback = move_to_tag(screen.count() == 1 and 1 or 2, 8) + }, + { rule = { class = "Chromium", instance = "chromium" }, + properties = { + floating = false, + }, + callback = move_to_tag(screen.count() == 1 and 1 or 2, 9) + }, + { rule = { class = "Gscan2pdf" }, + properties = { + switchtotag = true + }, + callback = move_to_tag(1, 5) + }, + { rule = { name = "gscan2pdf .*" }, + properties = { + floating = false, + }, + }, + { rule = { class = "Thunar", type = "normal" }, + properties = { + floating = false, + }, + }, + { rule = { class = "MuPDF", instance = "mupdf" }, + properties = { + floating = true, + }, + }, + { rule = { class = "Pinentry", instance = "pinentry" }, + properties = { + floating = true, + }, + }, + { rule = { class = "Gxmessage" }, + properties = { + floating = true, + }, + }, } -- }}} @@ -474,7 +688,7 @@ awful.rules.rules = { client.connect_signal("manage", function (c) -- Set the windows at the slave, -- i.e. put it at the end of others instead of setting it master. - -- if not awesome.startup then awful.client.setslave(c) end + if not awesome.startup then awful.client.setslave(c) end if awesome.startup and not c.size_hints.user_position @@ -482,12 +696,15 @@ client.connect_signal("manage", function (c) -- Prevent clients from being unreachable after screen count changes. awful.placement.no_offscreen(c) end + + c.maximized_horizontal = false + c.maximized_vertical = false end) -- Add a titlebar if titlebars_enabled is set to true in the rules. client.connect_signal("request::titlebars", function(c) -- buttons for the titlebar - local buttons = awful.util.table.join( + local buttons = gears.table.join( awful.button({ }, 1, function() client.focus = c c:raise() @@ -526,7 +743,7 @@ client.connect_signal("request::titlebars", function(c) } end) --- Enable sloppy focus +-- Enable sloppy focus, so that focus follows mouse. client.connect_signal("mouse::enter", function(c) if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier and awful.client.focus.filter(c) then @@ -536,4 +753,9 @@ end) client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end) client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end) --- }}} + +awful.ewmh.add_activate_filter(function(c, context, hints) + if context == "ewmh" and (c.class == "Firefox-esr" or c.class == "Firefox") then return false end +end) + +-- vim:ft=lua:sw=4:sts=4:ts=4:et