平铺式窗口管理器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)
-- }}}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 204,530评论 6 478
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 86,403评论 2 381
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 151,120评论 0 337
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 54,770评论 1 277
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 63,758评论 5 367
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,649评论 1 281
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 38,021评论 3 398
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,675评论 0 258
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,931评论 1 299
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,659评论 2 321
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,751评论 1 330
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,410评论 4 321
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 39,004评论 3 307
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,969评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 31,203评论 1 260
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 45,042评论 2 350
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 42,493评论 2 343

推荐阅读更多精彩内容