This is my rc.lua (with Shifty support):
Do not forget to check and correct the marked words if you deem it necessary.
require("awful")require("beautiful")require("naughty")require("shifty")require("wicked")--Invaders must die! :)require("invaders")-- Create a battery widgetbatterywidget = widget({type = "textbox", name = "batterywidget", align = "right" })batteryicon = widget({ type = "imagebox", align = "right" })-- useful for debugging, marks the beginning of rc.lua execprint("Entered rc.lua: " .. os.time())-- {{{ Variable definitions--here is my theme:--http://thenixer.blogspot.com/2009/08/my-awesome-wm-theme.htmltheme_path = ".config/awesome/themes/mytheme"-- Actually load themebeautiful.init(theme_path)-- This is used later as the default terminal and editor to run.browser = "chromium-browser"--mail = "thunderbird"terminal = "urxvt"editor = os.getenv("EDITOR") or "vim"editor_cmd = terminal .. " -e " .. editorFM = "pcmanfm"-- 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.modkey = "Mod4"-- Autorun programsautorun = trueautorunApps ={"xcompmgr","eval `cat .fehbg`","pcmanfm -d","glipper-old","ck-launch-session blueman-applet","gsynaptics-init",}if autorun thenfor app = 1, #autorunApps doawful.util.spawn(autorunApps[app])endendfunction mcabber_mess()--mcabber_message_num.sh is here:--http://thebosha.blogspot.com/2009/08/number-of-unread-mcabber-messages-in.htmllocal filedescriptor = io.popen('~/.scripts/mcabber_message_num.sh')local value = nilif filedescriptor ~= nil thenvalue = filedescriptor:read()endfiledescriptor:close()if value == nil thenreturn '0 msg.'elsereturn valueend--local value = filedescriptor:read()--filedescriptor:close()--return valueendgetmcabbermessnum = widget({type = 'textbox',name = 'getmcabbermessnum',align = 'right'})wicked.register(getmcabbermessnum,mcabber_mess," $1 ")space = widget({type = 'textbox',name = 'space',align = 'right'})space.text = ' '--sound widget code--you must setup your card ID and ALSA channelscardid = 0channel = "LineOut"mutechannel = "iSpeaker"function volume (mode, widget)if mode == "update" thenlocal fd = io.popen("amixer -c " .. cardid .. " -- sget " .. channel)local status = fd:read("*all")fd:close()local volume = string.match(status, "(%d?%d?%d)%%")volume = string.format("% 3d", volume)status = string.match(status, "%[(o[^%]]*)%]")if string.find(status, "on", 1, true) thenvolume = volume .. "%"elsevolume = volume .. "M"endwidget.text = volumeelseif mode == "up" thenio.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%+"):read("*all")volume("update", widget)elseif mode == "down" thenio.popen("amixer -q -c " .. cardid .. " sset " .. channel .. " 5%-"):read("*all")volume("update", widget)elseif mode == "mpd_toggle" thenio.popen("mpc toggle"):read("*all")volume("update", widget)elseif mode == "moc_toggle" thenio.popen("mocp -G"):read("*all")volume("update", widget)elseio.popen("amixer -c " .. cardid .. " sset " .. channel .. " toggle"):read("*all")io.popen("amixer -c " .. cardid .. " sset " .. mutechannel .. " toggle"):read("*all")volume("update", widget)endendtb_volume = widget({ type = "textbox", name = "tb_volume", align = "right" })--right mouse button — play/pause MOC--middle mouse button — play/pause ncmpcpp (MPD client)tb_volume:buttons({button({ }, 4, function () volume("up", tb_volume) end),button({ }, 5, function () volume("down", tb_volume) end),button({ }, 1, function () volume("mute", tb_volume) end),button({ }, 2, function () volume("mpd_toggle", tb_volume) end),button({ }, 3, function () volume("moc_toggle", tb_volume) end)})volume("update", tb_volume)--battery monitor code (added_by_me)function batteryInfo(adapter)spacer = " "local fcur = io.open("/sys/class/power_supply/"..adapter.."/charge_now")local fcap = io.open("/sys/class/power_supply/"..adapter.."/charge_full")local fsta = io.open("/sys/class/power_supply/"..adapter.."/status")local cur = fcur:read()local cap = fcap:read()local sta = fsta:read()local battery = math.floor(cur * 100 / cap)if sta:match("Charging") thendir = "↑"--battery = "A/C ("..battery..")"battery = ""..battery..""elseif sta:match("Discharging") thendir = "↓"if tonumber(battery) > 25 and tonumber(battery) <>battery = batteryelseif tonumber(battery) <>if tonumber(battery) <>naughty.notify({ title = "Battery Warning", text = "Battery low!"..spacer..battery.."%"..spacer.."left!", timeout = 5, position = "top_right", fg = beautiful.fg_focus, bg = beautiful.bg_focus})endbattery = batteryelsebattery = batteryendelsedir = "↕"battery = "A/C"endbatterywidget.text = dir..batteryfcur:close()fcap:close()fsta:close()end-- Create a textbox widgetclock = widget({ type = "textbox", align = "right" })-- Set the default text in textboxclock.text = " "-- Table of layouts to cover with awful.layout.inc, order matters.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.max,awful.layout.suit.max.fullscreen,--awful.layout.suit.magnifier,awful.layout.suit.floating}-- Define if we want to use titlebar on all applications.use_titlebar = false-- }}}--{{{ SHIFTY: configured tagsshifty.config.tags = {["Main"] = { layout = awful.layout.suit.tile.left, mwfact=0.60, exclusive = false, position = 1, init = true, screen = 1, slave = false, nopopup = true, } ,["Web"] = { layout = awful.layout.suit.max, mwfact=0.50, exclusive = false, position = 2, init = false, screen = 1, slave = false, nopopup = true },["Chat"] = { layout = awful.layout.suit.tile, mwfact=0.10, exclusive = false, position = 3, init = false, screen = 1, slave = false, nopopup = true },["Med"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.60, exclusive = false, position = 4, init = false, screen = 1, slave = false, nopopup = true },["Code"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.60, exclusive = false, position = 5, init = false, screen = 1, slave = false, nopopup = true },["Term"] = { layout = awful.layout.suit.tile.top, mwfact=0.60, exclusive = false, position = 6, init = true, screen = 1, slave = false, nopopup = true },["Vim"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.60, exclusive = false, position = 7, init = false, screen = 1, slave = false, nopopup = true },["Files"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.50, exclusive = false, position = 8, init = false, screen = 1, slave = false, nopopup = true },["Notes"] = { layout = awful.layout.suit.tile.bottom, mwfact=0.50, exclusive = false, position = 9, init = false, screen = 1, slave = false, nopopup = true },}--}}}--{{{ SHIFTY: application matching rules-- order here matters, early rules will be applied firstshifty.config.apps = {{ match = { "psi", } , tag = "Chat" },{ match = { "chrome", "firefox", } , tag = "Web", } ,{ match = { "pcmanfm", } , tag = "Files", } ,{ match = { "geany", } , tag = "Code", } ,{ match = { "wpa_gui", "OpenOffice.*", "epdfview", } , tag = "Main", } ,{ match = { "gpodder", "smplayer", "sonata", "ncmpcpp", "gnome-alsamixer"} , tag = "Med", } ,{ match = { "leafpad" } , tag = "Notes", },{ match = { terminal } , tag = "Term" },{ match = { "gvim", } , tag = "Vim" },{ match = { "gqview", } , tag = "Main" },--{ match = { terminal } , honorsizehints = false, slave = false, tag = "term" }}--}}}--{{{ SHIFTY: default tag creation rules-- parameter description-- * floatBars : if floating clients should always have a titlebar-- * guess_name : wether shifty should try and guess tag names when creating new (unconfigured) tags-- * guess_position: as above, but for position parameter-- * run : function to exec when shifty creates a new tag-- * remember_index: ?-- * all other parameters (e.g. layout, mwfact) follow awesome's tag APIshifty.config.defaults={layout = awful.layout.suit.tile.bottom,ncol = 1,mwfact = 0.60,floatBars=false,guess_name=true,guess_position=true,run = function(tag)local stitle = "Shifty Created: "stitle = stitle .. (awful.tag.getproperty(tag,"position") or shifty.tag2index(mouse.screen,tag))stitle = stitle .. " : "..tag.namenaughty.notify({ text = stitle })end,}--}}}-- {{{ Wibox-- Create a textbox widgetclock = widget({ type = "textbox", align = "right" })-- Create a laucher widget and a main menumyinternetmenu = {{ "Firefox", "firefox" },{ "Chrome", "chromium-browser" },{ "Psi", "psi" },{ "Gpodder", "gpodder"},{ "NMap", "gksudo nmapfe" },{ "Skype", "skype" }}myofficemenu = {{ "EPDFView", "epdfview" },{ "Office Base", "soffice -base" },{ "Office Calc", "soffice -calc" },{ "Office Draw", "soffice -draw" },{ "Office Temlate", "soffice slog:5500" },{ "Office Impress", "soffice -impress" },{ "Office Math", "soffice -math" },{ "Office Writer", "soffice- writer" },}mymediamenu = {{ "Mixer", "gnome-alsamixer"},{ "Sonata", "sonata" },{ "SMPlayer", "smplayer" },{ "VLC", "vlc" },{ "wxCam", "wxcam" },{ "Sound Converter", "soundconverter" },}mygraphicsmenu = {{ "GQView", "gqview" },{ "GIMP", "gimp" },{ "XSane", "xsane" },}mygamesmenu = {{ "XMoto", ".scripts/game_xmoto.sh" },{ "Duke 3D", ".scripts/game_eduke32.sh" },{ "Frozen Bubble", "frozen-bubble" },{ "Invaders", invaders.run },{ "XBL", "xbl" },}mycodemenu = {{ "Geany", "geany" },{ "gVim", "gvim" },}myothermenu = {{ "Leafpad", "leafpad" },{ "XArchiver", "xarchiver" },{ "LXAppearance", "lxappearance" },{ "Dia", "dia" },{ "Disk Usage", "xdiskusage" },{ "HP Toolbox", "hp-toolbox" },}mymainmenu = awful.menu.new({ items = { { " Internet", myinternetmenu },{ " Media", mymediamenu },{ " Graphics", mygraphicsmenu },{ "Office", myofficemenu },{ "Code", mycodemenu },{ "Other", myothermenu },{ "Games", mygamesmenu },{ " ", separator },{ "Terminal", terminal },{ "KeePassX", "keepassx" },{ "File manager", FM }}})mylauncher = awful.widget.launcher({ image = image(beautiful.awesome_icon),menu = mymainmenu })-- Create a systraymysystray = widget({ type = "systray", align = "right" })-- Create a wibox for each screen and add ittopwibox = {}botttopwibox = {}mypromptbox = {}mylayoutbox = {}mytaglist = {}mytaglist.buttons = { button({ }, 1, awful.tag.viewonly),button({ modkey }, 1, awful.client.movetotag),button({ }, 3, function (tag) tag.selected = not tag.selected end),button({ modkey }, 3, awful.client.toggletag),button({ }, 5, awful.tag.viewnext),button({ }, 4, awful.tag.viewprev) }mytasklist = {}mytasklist.buttons = { button({ }, 1, function (c)if not c:isvisible() thenawful.tag.viewonly(c:tags()[1])endclient.focus = cc:raise()end),button({ }, 3, function () if instance then instance:hide() instance = nil else instance = awful.menu.clients({ width=250 }) end end),button({ }, 4, function ()awful.client.focus.byidx(1)if client.focus then client.focus:raise() endend),button({ }, 5, function ()awful.client.focus.byidx(-1)if client.focus then client.focus:raise() endend) }for s = 1, screen.count() do-- Create a promptbox for each screenmypromptbox[s] = widget({ type = "textbox", align = "left" })-- Create an imagebox widget which will contains an icon indicating which layout we're using.-- We need one layoutbox per screen.mylayoutbox[s] = widget({ type = "imagebox", align = "right" })mylayoutbox[s]:buttons({ button({ }, 1, function () awful.layout.inc(layouts, 1) end),button({ }, 3, function () awful.layout.inc(layouts, -1) end),button({ }, 4, function () awful.layout.inc(layouts, 1) end),button({ }, 5, function () awful.layout.inc(layouts, -1) end) })-- Create a taglist widgetmytaglist[s] = awful.widget.taglist.new(s, awful.widget.taglist.label.all, mytaglist.buttons)-- Create a tasklist widgetmytasklist[s] = awful.widget.tasklist.new(function(c)return awful.widget.tasklist.label.currenttags(c, s)end, mytasklist.buttons)-- Create the wiboxtopwibox[s] = wibox({ position = "top", fg = beautiful.fg_normal, bg = beautiful.bg_normal })topwibox[s].widgets = {mylauncher,mytaglist[s],mypromptbox[s],space,tb_volume,space,getmcabbermessnum,space,batterywidget,space,clock,--space,s == 1 and mysystray or nil,mylayoutbox[s]}topwibox[s].screen = s--you may enable bottom panel--bottwibox[s] = wibox({ position = "bottom", fg = beautiful.fg_normal, bg = beautiful.bg_normal })--bottwibox[s].widgets = {--mytasklist[s],--space,--s == 1 and mysystray or nil,-- }--bottwibox[s].screen = send-- }}}--{{{ SHIFTY: initialize shifty-- the assignment of shifty.taglist must always be after its actually initialized-- with awful.widget.taglist.new()shifty.taglist = mytaglistshifty.init()--}}}-- {{{ Key bindingsglobalkeys ={-- TAGSkey({ modkey, }, "x", awful.tag.viewprev ),key({ modkey, }, "Left", awful.tag.viewprev ),key({ modkey, }, "c", awful.tag.viewnext ),key({ modkey, }, "Right", awful.tag.viewnext ),key({ modkey, }, "Escape", awful.tag.history.restore),-- SHIFTY: keybindings specific to shiftykey({ modkey, "Shift" }, "d", shifty.del), -- delete a tagkey({ modkey, "Shift" }, "n", shifty.send_prev),-- move client to prev tagkey({ modkey }, "n", shifty.send_next),-- move client to next tagkey({ modkey,"Control"}, "n", function()shifty.tagtoscr(awful.util.cycle(screen.count(), mouse.screen +1))end),-- move client to next tagkey({ modkey }, "a", shifty.add), -- creat a new tagkey({ modkey, }, "r", shifty.rename), -- rename a tagkey({ modkey, "Shift" }, "a", -- nopopup new tagfunction()shifty.add({ nopopup = true })end),key({ modkey, }, "j",function ()awful.client.focus.byidx( 1)if client.focus then client.focus:raise() endend),key({ modkey, }, "k",function ()awful.client.focus.byidx(-1)if client.focus then client.focus:raise() endend),key({ modkey, }, "z", function () mymainmenu:show(true) end),-- Layout manipulationkey({ modkey, "Shift" }, "j", function () awful.client.swap.byidx( 1) end),key({ modkey, "Shift" }, "k", function () awful.client.swap.byidx( -1) end),key({ modkey, "Control" }, "j", function () awful.screen.focus( 1) end),key({ modkey, "Control" }, "k", function () awful.screen.focus(-1) end),key({ modkey, }, "u", awful.client.urgent.jumpto),key({ modkey, }, "Tab",function ()awful.client.focus.history.previous()if client.focus thenclient.focus:raise()endend),-- Standard programkey({ modkey, }, "Return", function () awful.util.spawn(terminal) end),key({ modkey, "Control" }, "r", awesome.restart),key({ modkey, "Shift" }, "q", awesome.quit),key({ modkey }, "F6", function () awful.util.spawn('xkill') end),key({ modkey }, "F3", function () awful.util.spawn('transset-df -p --inc .05 &') end),key({ modkey }, "F4", function () awful.util.spawn('transset-df -p --dec .05 &') end),key({ modkey }, "F10", function () awful.util.spawn('ncmpcpp toggle &') end),key({ modkey }, "F8", function () awful.util.spawn('ncmpcpp volume -1 &') end),key({ modkey }, "F9", function () awful.util.spawn('ncmpcpp volume +1 &') end),key({ modkey }, "]", function () awful.util.spawn('ncmpcpp next &') end),key({ modkey }, "[", function () awful.util.spawn('ncmpcpp prev &') end),key({ modkey, }, "l", function () awful.tag.incmwfact( 0.05) end),key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster( 1) end),key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(-1) end),key({ modkey, "Control" }, "h", function () awful.tag.incncol( 1) end),key({ modkey, "Control" }, "l", function () awful.tag.incncol(-1) end),key({ modkey, }, "space", function () awful.layout.inc(layouts, 1) end),key({ modkey, "Shift" }, "space", function () awful.layout.inc(layouts, -1) end),-- Promptkey({ modkey }, "F2",function ()awful.prompt.run({ prompt = "Run: " },mypromptbox[mouse.screen],awful.util.spawn, awful.completion.shell,awful.util.getdir("cache") .. "/history")end),key({ modkey }, "p",function ()awful.prompt.run({ prompt = "Run Lua code: " },mypromptbox[mouse.screen],awful.util.eval, nil,awful.util.getdir("cache") .. "/history_eval")end),}--{{{ Client awful tagging: this is useful to tag some clients and then do stuff like move to tag on themclientkeys ={key({ modkey, }, "f", function (c) c.fullscreen = not c.fullscreen end),key({ modkey, }, "q", function (c) c:kill() end),key({ modkey, "Control" }, "space", awful.client.floating.toggle ),key({ modkey, "Control" }, "Return", function (c) c:swap(awful.client.getmaster()) end),key({ modkey, }, "o", awful.client.movetoscreen ),key({ modkey, "Shift" }, "r", function (c) c:redraw() end),key({ modkey }, "t", awful.client.togglemarked),key({ modkey,}, "m",function (c)c.maximized_horizontal = not c.maximized_horizontalc.maximized_vertical = not c.maximized_verticalend),}-- SHIFTY: assign client keys to shifty for use in-- match() function (manage hook)shifty.config.clientkeys = clientkeysshifty.config.modkey = modkey--}}}-- Compute the maximum number of digit we need, limited to 9for i=1, ( shifty.config.maxtags or 9 ) dotable.insert(globalkeys, key({ modkey }, i,function ()local t = awful.tag.viewonly(shifty.getpos(i))end))table.insert(globalkeys, key({ modkey, "Control" }, i,function ()local t = shifty.getpos(i)t.selected = not t.selectedend))table.insert(globalkeys, key({ modkey, "Control", "Shift" }, i,function ()if client.focus thenawful.client.toggletag(shifty.getpos(i))endend))-- move clients to other tagstable.insert(globalkeys, key({ modkey, "Shift" }, i,function ()if client.focus thent = shifty.getpos(i)awful.client.movetotag(t)awful.tag.viewonly(t)endend))end-- Set keysroot.keys(globalkeys)-- }}}-- {{{ Hooks-- Hook function to execute when focusing a client.awful.hooks.focus.register(function (c)if not awful.client.ismarked(c) thenc.border_color = beautiful.border_focus--c.opacity = 1endend)-- Hook function to execute when unfocusing a client.awful.hooks.unfocus.register(function (c)if not awful.client.ismarked(c) thenc.border_color = beautiful.border_normal--c.opacity = 0.9endend)-- Hook function to execute when marking a clientawful.hooks.marked.register(function (c)c.border_color = beautiful.border_markedend)-- Hook function to execute when unmarking a client.awful.hooks.unmarked.register(function (c)c.border_color = beautiful.border_focusend)-- Hook function to execute when the mouse enters a client.awful.hooks.mouse_enter.register(function (c)-- Sloppy focus, but disabled for magnifier layoutif awful.layout.get(c.screen) ~= awful.layout.suit.magnifierand awful.client.focus.filter(c) thenclient.focus = cendend)--[[ Placeholder: for end users who want to customize the behavior-- of new client appearances.---- Otherwise shifty.lua provides a manage hook already.--awful.hooks.manage.register(function (c, startup)end) --]]--awful.hooks.manage.register(function (c, startup)-- If we are not managing this application at startup,-- move it to the screen where the mouse is.-- We only do it for filtered windows (i.e. no dock, etc).if not startup and awful.client.focus.filter(c) thenc.screen = mouse.screenendif use_titlebar then-- Add a titlebarawful.titlebar.add(c, { modkey = modkey })end-- Add mouse bindingsc:buttons(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),awful.button({ modkey }, 2, function (c) c:kill() end)))-- New client may not receive focus-- if they're not focusable, so set border anyway.c.border_width = beautiful.border_widthc.border_color = beautiful.border_normal-- Check if the application should be floating.local cls = c.classlocal inst = c.instanceif floatapps[cls] ~= nil thenawful.client.floating.set(c, floatapps[cls])elseif floatapps[inst] ~= nil thenawful.client.floating.set(c, floatapps[inst])end-- Check application->screen/tag mappings.local targetif apptags[cls] thentarget = apptags[cls]elseif apptags[inst] thentarget = apptags[inst]endif target thenc.screen = target.screenawful.client.movetotag(tags[target.screen][target.tag], c)end-- Do this after tag mapping, so you don't see it on the wrong tag for a split second.client.focus = c-- Set key bindingsc:keys(clientkeys)-- Set the windows at the slave,-- i.e. put it at the end of others instead of setting it master.-- awful.client.setslave(c)-- Honor size hints: if you want to drop the gaps between windows, set this to false.-- c.size_hints_honor = falseend)-- Hook function to execute when arranging the screen.-- (tag switch, new client, etc)awful.hooks.arrange.register(function (screen)local layout = awful.layout.getname(awful.layout.get(screen))if layout and beautiful["layout_" ..layout] thenmylayoutbox[screen].image = image(beautiful["layout_" .. layout])elsemylayoutbox[screen].image = nilend-- Give focus to the latest client in history if no window has focus-- or if the current window is a desktop or a dock one.if not client.focus thenlocal c = awful.client.focus.history.get(screen, 0)if c then client.focus = c endendend)-- Hooks (added by me)awful.hooks.timer.register(10, function() batteryInfo("BAT0") end)awful.hooks.timer.register(10, function() getmcabbermessnum.text = mcabber_mess() end)--you may edit clock.text for your needsawful.hooks.timer.register(20, function () clock.text = os.date("%u:%d-%H:%M") end)awful.hooks.timer.register(10, function () volume("update", tb_volume) end)-- }}}
No comments:
Post a Comment