Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Modules
- -- Standard modules
- gears = require("gears")
- awful = require("awful")
- awful.rules = require("awful.rules")
- awful.autofocus = require("awful.autofocus")
- -- Widget box
- wibox = require("wibox")
- -- Theming
- beautiful = require("beautiful")
- -- Notification
- naughty = require("naughty")
- -- Menubar: dmenu-like launcher
- --menubar = require("menubar")
- -- 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 = "An error happened!",
- text = tostring(err) })
- in_error = false
- end)
- end
- -- Third-party modules
- -- Additional widgets and layouts
- lain = require("lain")
- -- Widget displaying volume information
- volume = require("volume")
- -- Variables
- -- $HOME/
- home_path = os.getenv('HOME') .. '/'
- -- Terminal emulator
- terminal = "xfce4-terminal"
- -- Set terminal for applications which require it (menubar)
- --menubar.utils.terminal = terminal
- -- Editor, graphical
- --editor = "geany"
- -- Editor, terminal (man sensible-editor)
- editor = terminal .. ' -e "sensible-editor \\"%s\\""'
- -- Meta/Win/Super
- modkey = "Mod4"
- -- Alt
- modkey_alt = "Mod1"
- -- Appearance
- -- Set default theme
- beautiful.init(awful.util.getdir("config") .. "/themes/default_white/theme.lua")
- -- If beautiful.wallpaper variable is set (in theme.lua) then
- if beautiful.wallpaper then
- -- for each screen
- for s = 1, screen.count() do
- -- set this wallpaper
- gears.wallpaper.maximized(beautiful.wallpaper, s, true)
- end
- end
- -- Functions
- -- "Match" function
- -- Returns true if all pairs in table1 are present in table2 (for use by "Run or raise")
- function match (table1, table2)
- for k, v in pairs(table1) do
- if table2[k] ~= v and not table2[k]:find(v) then
- return false
- end
- end
- return true
- end
- -- "Run or raise" function
- -- Jump to client, which matches PROPERTIES, otherwise run CMD
- function run_or_raise(cmd, properties)
- local clients = client.get()
- local focused = awful.client.next(0)
- local findex = 0
- local matched_clients = {}
- local n = 0
- -- Check all clients
- for i, c in pairs(clients) do
- -- Make an array of matched clients
- -- If client matches properties
- if match(properties, c) then
- n = n + 1
- -- Add it to an array of matching clients
- matched_clients[n] = c
- if c == focused then
- findex = n
- end
- end
- end
- -- If there is a client, which matches properties
- if n > 0 then
- -- Choose first client, which matched properties
- local c = matched_clients[1]
- -- If the focused client matches, switch to next matching client in list
- if 0 < findex and findex < n then
- c = matched_clients[findex+1]
- end
- -- List of tags, on which this client is visible
- local ctags = c:tags()
- -- If client is visible on 0 tags, move it to current tag
- if #ctags == 0 then
- local curtag = awful.tag.selected()
- awful.client.movetotag(curtag, c)
- -- Otherwise, jump to first tag client is visible on
- else
- awful.tag.viewonly(ctags[1])
- end
- -- Focus and raise the client
- client.focus = c
- c:raise()
- return
- end
- -- If no client matches, just run this program
- awful.util.spawn(cmd)
- end
- -- "Run once" function
- -- Run PRG once with command-line ARGuments, expecting PNAME as process name on SCREEN
- function run_once(prg,arg_string,pname,screen)
- -- Check if program name is passed to function
- if not prg then
- do return nil end
- end
- -- If process name is not set, expect that process name = program name
- if not pname then
- pname = prg
- end
- -- If no arguments are specified
- if not arg_string then
- -- Look for process with such name, if nothing found - run program on screen
- awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. "' || (" .. prg .. ")",screen)
- -- If arguments are specified
- else
- awful.util.spawn_with_shell("pgrep -f -u $USER -x '" .. pname .. " ".. arg_string .."' || (" .. prg .. " " .. arg_string .. ")",screen)
- end
- end
- -- Autostart (start only once, to prevent having multiple instances of one program running, if we restart Awesome, but not the session)
- -- Set X server keymap and its settings (doesn't remain as a process, so it can be run multiple times)
- awful.util.spawn("setxkbmap")
- -- Switch/restore keyboard layout on per-client basis
- run_once("kbdd")
- -- Compton (composite manager) for less tearing
- run_once("compton","--vsync opengl-swc --backend glx --glx-no-stencil")
- -- Automatically lock session after 5 minutes of idleness
- run_once("xautolock",'-locker "i3lock -i .wallpaper -e" -time 5')
- -- XSettings daemon from Xfce4
- run_once("xfsettingsd")
- -- Clipboard manager
- run_once("clipit")
- -- Pcmanfm (daemon) for faster Pcmanfm startup
- run_once("pcmanfm","--daemon-mode")
- -- Gnome policykit agent (prompts for password when policykit authentication is required)
- run_once("/usr/lib/policykit-1-gnome/polkit-gnome-authentication-agent-1")
- -- Key bindings
- -- Global
- globalkeys = awful.util.table.join(
- -- Switch tags (relatively)
- awful.key({ modkey, }, "Left", awful.tag.viewprev),
- awful.key({ modkey, }, "Right", awful.tag.viewnext),
- awful.key({ modkey, }, "`", function () awful.client.urgent.jumpto() end),
- awful.key({ modkey, }, "Escape", awful.tag.history.restore),
- -- Clients: focus
- 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),
- awful.key({ modkey_alt, }, "Tab",
- function ()
- awful.client.focus.byidx(1)
- if client.focus then client.focus:raise() end
- end),
- awful.key({ modkey, }, "Tab",
- function ()
- awful.client.focus.history.previous()
- if client.focus then client.focus:raise() end
- end),
- -- Clients: placement
- 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_alt, "Shift" }, "Tab", function () awful.client.swap.byidx(1) end),
- awful.key({ modkey, }, "h", function () awful.tag.incmwfact(-0.05) end),
- awful.key({ modkey, }, "l", function () awful.tag.incmwfact(0.05) end),
- awful.key({ modkey, "Shift" }, "h", function () awful.tag.incnmaster(-1) end),
- awful.key({ modkey, "Shift" }, "l", function () awful.tag.incnmaster(1) end),
- awful.key({ modkey, }, "space", function () awful.layout.inc(1) end),
- awful.key({ modkey, "Shift" }, "space", function () awful.layout.inc(-1) end),
- -- Restart Awesome
- awful.key({ modkey, "Shift" }, "r", awesome.restart),
- -- Awesome launchers
- awful.key({ modkey, }, "p", function () awful.util.spawn(terminal .. " -T mylauncher --geometry 100x5 --hide-menubar --hide-toolbar --hide-borders -e 'env ZDOTDIR=.zsh zsh'") 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),
- awful.key({ modkey, }, "F3", function () mymainmenu:toggle() end),
- -- Program launchers
- awful.key({ modkey, }, "w", function () run_or_raise("iceweasel", { class = "Iceweasel" }) end),
- awful.key({ modkey, }, "e", function () run_or_raise("icedove", { class = "Icedove" }) end),
- awful.key({ modkey, }, "o", function () awful.util.spawn("xautolock -locknow") end),
- awful.key({ modkey, }, "Return", function () awful.util.spawn(terminal) end),
- awful.key({ modkey, }, "F1", function () awful.util.spawn(terminal) end),
- awful.key({ modkey, }, "f", function () awful.util.spawn("pcmanfm") end),
- awful.key({ modkey, }, "q", function () awful.util.spawn("tkscreen") end),
- awful.key({ modkey, }, "t", function () run_or_raise("transmission-remote-gtk", { class = "transmission-remote-gtk" }) end),
- awful.key({ modkey, }, "a", function () run_or_raise(terminal .. " -T Ncmpcpp -e ncmpcpp ", { name = "Ncmpcpp" }) end),
- awful.key({ modkey, }, "F2", function () run_or_raise(terminal .. " -T Htop -e 'sudo htop' ", { name = "Htop" }) end),
- -- Multimedia
- awful.key({}, "XF86Calculator", function () awful.util.spawn("qalculate") end),
- awful.key({}, "XF86AudioPlay", function () awful.util.spawn("mpc toggle") end),
- awful.key({}, "XF86AudioNext", function () awful.util.spawn("mpc next") end),
- awful.key({}, "XF86AudioPrev", function () awful.util.spawn("mpc prev") end),
- awful.key({}, "XF86AudioStop", function () awful.util.spawn("mpc stop") end),
- -- We should update volume_widget every time volume changes
- -- Unlike os.execute() or io.popen(), awful.util.spawn() and awful.util.spawn_with_shell() don't lock an application (os.execute() and io.popen() normally should not be used)
- -- Thus awful.util.spawn_with_shell is used here, and "update_volume" command is passed to Awesome via awesome-client
- -- Such approach guarantees, that "update_volume" is executed after volume change
- -- If we change volume, also turn "Master" channel ON prior to volume change. More convenient
- awful.key({}, "XF86AudioRaiseVolume", function () awful.util.spawn_with_shell('amixer set Master on 4%+ && echo "update_volume(volume_widget)" | awesome-client') end),
- awful.key({}, "XF86AudioLowerVolume", function () awful.util.spawn_with_shell('amixer set Master on 4%- && echo "update_volume(volume_widget)" | awesome-client') end),
- awful.key({}, "XF86AudioMute", function () awful.util.spawn_with_shell('amixer set Master toggle && echo "update_volume(volume_widget)" | awesome-client') end)
- )
- -- Switch tags
- for i = 1, 9 do
- globalkeys = awful.util.table.join(globalkeys,
- 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),
- 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),
- 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),
- 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 (per-client)
- clientkeys = awful.util.table.join(
- awful.key({ modkey_alt, }, "F1", function (c) c.fullscreen = not c.fullscreen end),
- awful.key({ modkey_alt, }, "F2",
- function (c)
- c:raise()
- c.maximized_horizontal = not c.maximized_horizontal
- c.maximized_vertical = not c.maximized_vertical
- end),
- awful.key({ modkey_alt, }, "F3", awful.client.floating.toggle),
- awful.key({ modkey_alt, }, "F4", function (c) c:kill() end),
- awful.key({ modkey_alt, }, "F5", function (c) c:swap(awful.client.getmaster()) end),
- awful.key({ modkey_alt, }, "F6", function (c) c.ontop = not c.ontop end)
- )
- -- Mouse bindings
- -- On desktop
- root.buttons(awful.util.table.join(
- -- Open/close main menu on right-click
- awful.button({ }, 3, function () mymainmenu:toggle() end),
- -- Scroll through tags
- awful.button({ }, 4, awful.tag.viewnext),
- awful.button({ }, 5, awful.tag.viewprev)
- ))
- -- On window
- clientbuttons = awful.util.table.join(
- -- Left-click to give client focus and raise it
- awful.button({ }, 1, function (c) client.focus = c; c:raise() end),
- -- Meta+left-click and drag to move window
- awful.button({ modkey }, 1, awful.mouse.client.move),
- -- Meta+right-click and drag to resize window
- awful.button({ modkey }, 3, awful.mouse.client.resize))
- -- Table of layouts
- awful.layout.layouts = {
- -- All clients are tiled (masters and slaves)
- awful.layout.suit.tile,
- -- If only one client, it is centered (see themes/default/theme.lua, theme.single_gap and theme.useless_gap variables). If more, tiled (masters and slaves)
- lain.layout.uselesstile,
- -- All clients are tiled fairly (no masters or slaves)
- awful.layout.suit.fair,
- -- All clients float (like in traditional desktop)
- awful.layout.suit.floating
- }
- -- Tags
- tags = {
- -- Set names for tags
- names = { "www", "music", "mail", 4, 5, 6, 7, 8, 9 },
- -- Set layouts for tags (layout number in square brackets)
- layout = { awful.layout.layouts[1], awful.layout.layouts[1], awful.layout.layouts[1], awful.layout.layouts[2], awful.layout.layouts[2],
- awful.layout.layouts[2], awful.layout.layouts[3], awful.layout.layouts[3], awful.layout.layouts[3]
- }}
- -- For each screen create tags with corresponding names and layouts
- for s = 1, screen.count() do
- tags[s] = awful.tag(tags.names, s, tags.layout)
- end
- -- Rules
- awful.rules.rules = {
- { rule = { },
- -- Rules for all the clients: define border appearance, focus settings, remove gaps between windows (see FAQ), and set local key/mouse bindings
- properties = { border_width = beautiful.border_width,
- border_color = beautiful.border_normal,
- focus = awful.client.focus.filter,
- size_hints_honor = false,
- keys = clientkeys,
- buttons = clientbuttons } },
- -- Per-client rules
- { rule = { instance = "pidgin" },
- properties = { floating = true }
- },
- { rule = { instance = "Pidgin" },
- properties = { floating = true }
- },
- { rule = { class = "qemu-system-x86_64" },
- properties = { floating = true }
- },
- { rule = { instance = "qalculate" },
- properties = { floating = true }
- },
- { rule = { name = "mylauncher" },
- properties = { floating = true }
- },
- { rule = { name = "Действия над файлами" },
- properties = { floating = true }
- },
- { rule = { name = "Catfish" },
- properties = { floating = true }
- }
- }
- -- Widgets
- -- Launcher widget and main menu
- myawesomemenu = {
- { "edit config", editor:format(awesome.conffile) },
- { "restart", awesome.restart },
- }
- mysessionmenu = {
- { "lock session", "xautolock -locknow" },
- { "quit session", awesome.quit },
- { "suspend", "systemctl suspend" },
- { "shutdown", "systemctl poweroff" },
- { "reboot", "systemctl reboot" }
- }
- mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon }, { "session", mysessionmenu } }
- })
- mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
- menu = mymainmenu })
- -- Keyboard layout widget
- kbdwidget = wibox.widget.textbox(" Eng ")
- kbdwidget:set_font("Liberation Mono 9")
- kbdstrings = {[0] = " Eng ",
- [1] = " Рус ",
- -- Workaround for unknown kbdd bug. See dbus-monitor for details
- [2] = " Eng ",
- [3] = " Рус "}
- dbus.request_name("session", "ru.gentoo.kbdd")
- dbus.add_match("session", "interface='ru.gentoo.kbdd',member='layoutChanged'")
- dbus.connect_signal("ru.gentoo.kbdd",
- function(...)
- local data = {...}
- local layout = data[2]
- kbdwidget:set_text(kbdstrings[layout])
- end
- )
- -- Textclock widget
- -- See Lua Date and Time format for format details
- mytextclock = awful.widget.textclock.new(" %A %d.%m.%y, %H:%M")
- -- Attach Lain calendar to clock widget
- lain.widgets.calendar:attach(mytextclock, {font_size = 9, font = "DejaVu Sans Mono"})
- -- Wibox (panel)
- mywibox = {}
- mypromptbox = {}
- mylayoutbox = {}
- mytaglist = {}
- -- Mouse bindings for taglist widget
- mytaglist.buttons = awful.util.table.join(
- -- Left-click on tag to switch to this tag
- awful.button({ }, 1, awful.tag.viewonly),
- -- Meta+left-click on tag to move focused client to this tag
- awful.button({ modkey }, 1, awful.client.movetotag),
- -- Right-click on tag to toggle it's view (make clients on this tag visible)
- awful.button({ }, 3, awful.tag.viewtoggle),
- -- Meta+right-click on tag to make focused client visible on this tag
- awful.button({ modkey }, 3, awful.client.toggletag),
- -- Scroll through tags
- 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)
- )
- mytasklist = {}
- -- Mouse bindings for tasklist widget
- mytasklist.buttons = awful.util.table.join(
- -- If client is focused, minimize it on left-click
- -- If client is not focused, go to the first tag, where client is visible, unminimize it and give focus
- awful.button({ }, 1,
- function (c)
- if c == client.focus then
- c.minimized = true
- else
- c.minimized = false
- if not c:isvisible() then
- awful.tag.viewonly(c:tags()[1])
- end
- client.focus = c
- c:raise()
- end
- end),
- -- Right-click for client list
- awful.button({ }, 3,
- function ()
- if instance then
- instance:hide()
- instance = nil
- else
- instance = awful.menu.clients({
- theme = { width = 250 }
- })
- end
- end),
- -- Scroll through clients
- 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 each screen:
- for s = 1, screen.count() do
- -- Create a promptbox
- mypromptbox[s] = awful.widget.prompt()
- -- Create an layoutbox widget which will contain an icon indicating which layout we're using
- mylayoutbox[s] = awful.widget.layoutbox(s)
- -- Mouse bindings for layoutbox widget
- mylayoutbox[s]:buttons(awful.util.table.join(
- -- Scroll through layouts
- 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
- 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 on top of the screen
- 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(mytaglist[s])
- left_layout:add(mypromptbox[s])
- -- Widgets that are aligned to the right
- local right_layout = wibox.layout.fixed.horizontal()
- -- Tray should only be on one screen
- if s == 1 then right_layout:add(wibox.widget.systray()) end
- right_layout:add(volume_widget)
- right_layout:add(mytextclock)
- right_layout:add(kbdwidget)
- 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
- -- Enable global keybindings (after adding all the widgets, because widgets may contain their own global keybindings)
- root.keys(globalkeys)
- -- Signals
- -- When client appears
- client.connect_signal("manage",
- function (c)
- -- When Awesome is already started
- if not awesome.startup then
- -- Set new clients as slaves (put them in the end of the list)
- awful.client.setslave(c)
- -- When floating, prevent windows from overlapping or appearing outside the screen and make them appear in the center of the screen by default, if their position is not predefined
- 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)
- awful.placement.centered(c,nil)
- end
- -- On Awesome startup
- -- Prevent windows from appearing outside the screen, if their position is not predefined
- elseif not c.size_hints.user_position and not c.size_hints.program_position then
- awful.placement.no_offscreen(c)
- end
- -- Disable titlebars
- local titlebars_enabled = false
- end)
- -- Enable sloppy focus (focus follows the 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
- client.focus = c
- end
- end)
- -- If client gets focus
- client.connect_signal("focus",
- function(c)
- -- Change it's border color
- c.border_color = beautiful.border_focus
- -- And if it is not visible - jump to it
- if not c:isvisible() then
- awful.client.jumpto(c)
- end
- end)
- -- If client loses focus, change it's border color back to normal
- client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement