平铺式窗口管理器Awesome配置文件

~/.config/awesome/rc.lua 文件
-- 说明:Screen 指屏幕,awesome支持多屏幕。 Tag 指标签,一个标签对应一个虚拟桌面。 Client 指程序窗口。
-- {{{ 运行所需的库
-- 标准awesome库
local gears = require("gears")
local awful = require("awful")
awful.rules = require("awful.rules")
require("awful.autofocus")
-- 窗口和布局库
local wibox = require("wibox")
-- 主题控制库
local beautiful = require("beautiful")
-- 通知库
local naughty = require("naughty")
local menubar = require("menubar")
-- 导入右键程序菜单模块
require("debian.menu")
-- }}}

-- {{{ 错误处理
-- 检查awesome启动过程中是否发生错误
-- 如果发生错误则启用最近的正确配置,并通知用户
if awesome.startup_errors then
    naughty.notify({ preset = naughty.config.presets.critical,
                     title = "Oops, there were errors during startup!",
                     text = awesome.startup_errors })
end

-- 处理awesome启动后的运行时错误
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
-- }}}

-- {{{ 变量定义
-- 主题定义:颜色、图标、字体、壁纸
beautiful.init("/usr/share/awesome/themes/default/theme.lua")           -- 默认主题配置文件所在路径

-- 设置默认的终端和文本编辑器
terminal = "mate-terminal"
editor = "pluma"
editor_cmd = terminal .. " -e " .. editor

-- 默认的modkey设置,用于快捷键。默认是Mod4,也就是Win键
-- 通常,Mod4键位于键盘左侧的Ctrl和Alt键之间
-- 如果你不喜欢这样的设置或者没有这个按键,
-- 建议你使用xmodmap或者别的工具把Mod4键映射到别的按键
modkey = "Mod4"

-- 默认的布局方式和顺序
-- 可以手动调整顺序,可以删除不需要的布局方式(建议注释掉即可,以免以后再想使用)
local layouts =
{
    awful.layout.suit.tile,             -- 平铺                        
    awful.layout.suit.floating,         -- 浮动   
    awful.layout.suit.tile.left,        
    awful.layout.suit.tile.bottom,
    awful.layout.suit.tile.top,
    awful.layout.suit.fair,             -- 平铺,每个窗口大小一致
    awful.layout.suit.max,              -- 最大化          
--  awful.layout.suit.fair.horizontal,
--  awful.layout.suit.max.fullscreen,   -- 全屏
--  awful.layout.suit.spiral,           -- 螺旋式
    awful.layout.suit.magnifier         -- 放大
}
-- }}}

-- {{{ 壁纸设置
if beautiful.wallpaper then
    for s = 1, screen.count() do
        gears.wallpaper.maximized("/home/td/Pictures/background.jpg", s, true)          -- 替代引号中图片路径即可                      
    end
end
-- }}}

-- {{{ 桌面标签
-- 定义一个包含所有虚拟桌面的标签列表
tags = {
  names = {"Internet","Term","Code","Music",5,6},                                       -- 桌面标签的名称
  layout = {layouts[1],layouts[1],layouts[1],layouts[1],layouts[2],layouts[1]}          -- 标签默认布局,用索引表示,按照上面设置的layouts顺序
}
for s = 1, screen.count() do
    tags[s] = awful.tag(tags.names, s, tags.layout)
end
-- }}}

-- {{{ 菜单
-- myawesomemenu是mymainmenu主菜单的一项,这里包含3个子菜单,可以手动修改子菜单
-- 还可以仿照myawesomemenu向主菜单添加新项,添加后务必加入下面的mymainmenu中
myawesomemenu = {
   { "edit config", "pluma /home/td/.config/awesome/rc.lua" },      -- 这个子菜单用于修改awesome配置文件,pluma是一个简单的文本编辑器
   { "restart", awesome.restart },
   { "quit", awesome.quit }
}
-- mymainmenu主菜单
mymainmenu = awful.menu({ items = { { "awesome", myawesomemenu, beautiful.awesome_icon },   -- 这里的awesome项添加上面的myawesomemenu
                                    { "应用程序", debian.menu.Debian_menu.Debian },         -- 这是debian.menu模块自动生成的应用程序子菜单
                                    { "文件管理器", "caja /home/td/" },                      -- 手动添加的项
                                    { "网络浏览器", "chromium-browser %u" },             -- 手动添加的项
                                    { "open terminal", terminal },
                                    { "重启电脑", "gksu reboot now" },                      -- 手动添加的项
                                    { "关闭系统", "gksu 'shutdown -h now'" },               -- 手动添加的项
                                  }
                        })

mylauncher = awful.widget.launcher({ image = beautiful.awesome_icon,
                                     menu = mymainmenu })

menubar.utils.terminal = terminal -- 应用终端,见上文默认终端设置
-- }}}

-- {{{ 窗口和布局
-- 创建一个时钟部件
mytextclock = awful.widget.textclock("%X",1)

-- 为每个屏幕创建一个wibox
mywibox = {}
mypromptbox = {}
mylayoutbox = {}
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)
                    )
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
    -- 为每个屏幕创建一个信息框
    mypromptbox[s] = awful.widget.prompt()
    -- 在屏幕右上角显示目前正在使用的布局样式
    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)))
    -- 创建屏幕左上方的tag列表
    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 })

    -- 左对齐的部件
    local left_layout = wibox.layout.fixed.horizontal()
    left_layout:add(mylauncher)
    left_layout:add(mytaglist[s])
    left_layout:add(mypromptbox[s])

    -- 右对齐的部件
    local right_layout = wibox.layout.fixed.horizontal()
    if s == 1 then right_layout:add(wibox.widget.systray()) end
    right_layout:add(mytextclock)
    right_layout:add(mylayoutbox[s])

    --
    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
-- }}}

-- {{{ 鼠标绑定
root.buttons(awful.util.table.join(
    awful.button({ }, 3, function () mymainmenu:toggle() end),
    awful.button({ }, 4, awful.tag.viewnext),
    awful.button({ }, 5, awful.tag.viewprev)
))
-- }}}

-- {{{ 快捷键
globalkeys = awful.util.table.join(
    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,           }, "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,           }, "w", function () mymainmenu:show() 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,           }, "u", awful.client.urgent.jumpto),
    awful.key({ modkey,           }, "Tab",                 -- 切换到之前使用的窗口
        function ()
            awful.client.focus.history.previous()
            if client.focus then
                client.focus:raise()
            end
        end),

    -- 标准程序
    awful.key({ modkey,           }, "Return", function () awful.util.spawn(terminal) end),
    awful.key({ modkey, "Control" }, "r", awesome.restart),                                     -- 重启awesome
    awful.key({ modkey, "Shift"   }, "q", awesome.quit),                                        -- 退出awesome

    awful.key({ modkey,           }, "l",     function () awful.tag.incmwfact( 0.05)    end),   -- 增加主区域宽度
    awful.key({ modkey,           }, "h",     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, "Control" }, "h",     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, "Shift"   }, "space", function () awful.layout.inc(layouts, -1) end),   -- 反向切换布局样式

    awful.key({ modkey, "Control" }, "n", awful.client.restore),

    -- 启动器
    awful.key({ modkey },            "r",     function () mypromptbox[mouse.screen]:run() end),     -- 默认,程序启动器
--  awful.key({ modkey },            "r",     function () awful.util.spawn( "dmenu_run" ) end),     -- dmenu,程序启动器,需额外安装
    -- 包含显式选项的启动器
    awful.key({ modkey }, "p", function() menubar.show() end)
)

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)
)

-- 把数字键1到9绑定到对应的标签
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,            -- 快捷键,注意需要先用 Mod4 + t 标记当前窗口
                  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

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))

-- 应用快捷键
root.keys(globalkeys)
-- }}}

-- {{{ 规则
-- 设置部分程序启动时默认所在的屏幕和虚拟桌面,以及是否浮动(支持多屏幕,默认为屏幕1)
awful.rules.rules = {
    { 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 } },       -- 设置mplayer启动时默认为浮动状态
    { rule = { class = "pinentry" },
      properties = { floating = true } },
    { rule = { class = "gimp" },
      properties = { floating = true } },
-- 设置chromium浏览器启动时默认位于第一个屏幕的第一个标签
    { rule = { class = "Chromium-browser" },
      properties = { tag = tags[1][1] } },
--  { rule = { class = "Firefox" },
--    properties = { tag = tags[1][1] } },
}
-- }}}

-- {{{ Signals
-- 以下功能仅在新窗口出现时生效
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 does 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
    elseif not c.size_hints.user_position and not c.size_hints.program_position then
        -- Prevent clients from being unreachable after screen count change
        awful.placement.no_offscreen(c)
    end

    local titlebars_enabled = false
    if titlebars_enabled and (c.type == "normal" or c.type == "dialog") then
        -- 标题栏的按钮
        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)
                )

        -- 左对齐的部件
        local left_layout = wibox.layout.fixed.horizontal()
        left_layout:add(awful.titlebar.widget.iconwidget(c))
        left_layout:buttons(buttons)

        -- 右对齐的部件
        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))

        -- 中间的标题
        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) c.border_color = beautiful.border_focus end)
client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end)
-- }}}

你可能感兴趣的:(平铺式窗口管理器Awesome配置文件)