Skip to content

Instantly share code, notes, and snippets.

@SkyyySi
Last active February 8, 2023 22:06
Show Gist options
  • Save SkyyySi/3c5388db8717a3bb670754bc3f24c2f0 to your computer and use it in GitHub Desktop.
Save SkyyySi/3c5388db8717a3bb670754bc3f24c2f0 to your computer and use it in GitHub Desktop.
Port of awesome wm's rc.lua to moonscript
-- If LuaRocks is installed, make sure that packages installed through it are
-- found (e.g. lgi). If LuaRocks is not installed, do nothing.
pcall require, "luarocks.loader"
awesome = awesome ---@type awesome
screen = screen ---@type screen
client = client ---@type client
awful = require "awful" ---@type awful
gears = require "gears" ---@type gears
wibox = require "wibox" ---@type wibox Widget and layout library
naughty = require "naughty" ---@type naughty
beautiful = require "beautiful" ---@type beautiful
ruled = require "ruled" ---@type ruled
menubar = require "menubar" ---@type menubar
hotkeys_popup = require "awful.hotkeys_popup"
-- Enable hotkeys help widget for VIM and other apps
-- when client with a matching name is opened:
require "awful.hotkeys_popup.keys"
-- {{{ Error handling
-- Check if awesome encountered an error during startup and fell back to
-- another config (This code will only ever execute for the fallback config)
naughty.connect_signal "request::display_error", (message, startup) -> naughty.notification {
urgency: "critical"
title: "Oops, an error happened" .. if startup then " during startup!" else "!"
message: message
}
-- }}}
-- {{{ Variable definitions
-- Themes define colours, icons, font and wallpapers.
beautiful.init "#{gears.filesystem.get_themes_dir!}/default/theme.lua"
-- This is used later as the default terminal and editor to run.
terminal = os.getenv("TERMINAL") or "xterm"
editor = os.getenv("EDITOR") or "#{terminal} -e nano"
-- 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"
-- {{{ Menu
-- Create a launcher widget and a main menu
main_menu_items = {}
main_menu_items.awesome = {
{ "hotkeys", -> hotkeys_popup.show_help nil, awful.screen.focused! }
{ "manual", "#{terminal} -e man awesome" }
{ "edit config", "#{editor} #{awesome.conffile}" }
{ "restart", awesome.restart }
{ "quit", awesome.quit }
}
main_menu = awful.menu
items: {
{ "awesome", main_menu_items.awesome, beautiful.awesome_icon }
{ "open terminal", terminal }
}
launcher = awful.widget.launcher
image: beautiful.awesome_icon
menu: main_menu
-- Menubar configuration
menubar.utils.terminal = terminal -- Set the terminal for applications that require it
-- }}}
-- {{{ Tag layout
-- Table of layouts to cover with awful.layout.inc, order matters.
tag.connect_signal "request::default_layouts", () -> awful.layout.append_default_layouts {
awful.layout.suit.floating
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.spiral
awful.layout.suit.spiral.dwindle
awful.layout.suit.max
awful.layout.suit.max.fullscreen
awful.layout.suit.magnifier
awful.layout.suit.corner.nw
}
-- }}}
-- {{{ Wallpaper
screen.connect_signal "request::wallpaper", (s) -> awful.wallpaper {
screen: s,
widget: {
{
image: beautiful.wallpaper
upscale: true
downscale: true
widget: wibox.widget.imagebox
}
valign: "center"
halign: "center"
tiled: false
widget: wibox.container.tile
}
}
-- }}}
-- {{{ Wibar
-- Keyboard map indicator and switcher
keyboard_layout = awful.widget.keyboardlayout!
-- Create a textclock widget
mytextclock = wibox.widget.textclock!
screen.connect_signal "request::desktop_decoration", (s) ->
-- Each screen has its own tag table.
awful.tag { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, s, awful.layout.layouts[1]
-- Create a promptbox for each screen
s.promptbox = awful.widget.prompt!
-- Create an imagebox widget which will contain an icon indicating which layout we're using.
-- We need one layoutbox per screen.
s.layoutbox = awful.widget.layoutbox
screen: s
buttons: {
awful.button {}, 1, () -> awful.layout.inc( 1)
awful.button {}, 3, () -> awful.layout.inc(-1)
awful.button {}, 4, () -> awful.layout.inc(-1)
awful.button {}, 5, () -> awful.layout.inc( 1)
}
-- Create a taglist widget
s.taglist = awful.widget.taglist {
screen: s
filter: awful.widget.taglist.filter.all
buttons: {
awful.button {}, 1, (t) -> t\view_only!
awful.button { modkey }, 1, (t) ->
if client.focus then
client.focus\move_to_tag client.focus, t
awful.button {}, 3, awful.tag.viewtoggle,
awful.button { modkey }, 3, (t) ->
if client.focus then
client.focus\toggle_tag(t)
awful.button {}, 4, (t) -> awful.tag.viewprev t.screen
awful.button {}, 5, (t) -> awful.tag.viewnext t.screen
}
}
-- Create a tasklist widget
s.tasklist = awful.widget.tasklist {
screen: s,
filter: awful.widget.tasklist.filter.currenttags,
buttons: {
awful.button {}, 1, (c) -> c\activate
context: "tasklist"
action: "toggle_minimization"
awful.button {}, 3, () -> awful.menu.client_list
theme:
width: 250
awful.button {}, 4, () -> awful.client.focus.byidx -1
awful.button {}, 5, () -> awful.client.focus.byidx 1
}
}
-- Create the wibox
s.main_wibar = awful.wibar {
position: "top"
screen: s
widget: {
{ -- Left widgets
launcher
s.taglist
s.promptbox
layout: wibox.layout.fixed.horizontal
}
{ -- Middle / center widgets
s.tasklist
layout: wibox.layout.fixed.horizontal
}
{ -- Right widgets
layout: wibox.layout.fixed.horizontal
keyboard_layout
wibox.widget.systray!
mytextclock
s.layoutbox
}
layout: wibox.layout.align.horizontal
}
}
-- }}}
-- {{{ Mouse bindings
awful.mouse.append_global_mousebindings {
awful.button {}, 3, () -> main_menu\toggle()
awful.button {}, 4, awful.tag.viewprev
awful.button {}, 5, awful.tag.viewnext
}
-- }}}
-- {{{ Key bindings
-- @DOC_GLOBAL_KEYBINDINGS@
-- General Awesome keys
awful.keyboard.append_global_keybindings {
awful.key { modkey }, "s", hotkeys_popup.show_help,
description: "show help"
group: "awesome"
awful.key { modkey }, "w", () -> main_menu\show(),
description: "show main menu"
group: "awesome"
awful.key { modkey, "Control" }, "r", awesome.restart,
description: "reload awesome"
group: "awesome"
awful.key { modkey, "Shift" }, "q", awesome.quit,
description: "quit awesome"
group: "awesome"
awful.key { modkey }, "x",
->
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"
description: "lua execute prompt"
group: "awesome"
awful.key { modkey }, "Return", -> awful.spawn(terminal),
description: "open a terminal"
group: "launcher"
awful.key { modkey }, "r", -> awful.screen.focused!.mypromptbox\run!,
description: "run prompt"
group: "launcher"
awful.key { modkey }, "p", -> menubar.show!,
description: "show the menubar"
group: "launcher"
}
-- Tags related keybindings
awful.keyboard.append_global_keybindings {
awful.key { modkey }, "Left", awful.tag.viewprev,
description: "view previous"
group: "tag"
awful.key { modkey }, "Right", awful.tag.viewnext,
description: "view next"
group: "tag"
awful.key { modkey }, "Escape", awful.tag.history.restore,
description: "go back"
group: "tag"
}
-- Focus related keybindings
awful.keyboard.append_global_keybindings {
awful.key { modkey }, "j", -> awful.client.focus.byidx 1,
description: "focus next by index"
group: "client"
awful.key { modkey }, "k", -> awful.client.focus.byidx -1,
description: "focus previous by index"
group: "client"
awful.key { modkey }, "Tab",
->
awful.client.focus.history.previous!
if client.focus then
client.focus\raise!,
description: "go back"
group: "client"
awful.key { modkey, "Control" }, "j",
->
awful.screen.focus_relative 1
description: "focus the next screen"
group: "screen"
awful.key { modkey, "Control" }, "k",
->
awful.screen.focus_relative -1
description: "focus the previous screen"
group: "screen"
awful.key { modkey, "Control" }, "n",
->
-- Focus restored client
if c = awful.client.restore() then
c\activate
raise: true
context: "key.unminimize"
description: "restore minimized"
group: "client"
}
-- Layout related keybindings
awful.keyboard.append_global_keybindings {
awful.key { modkey, "Shift" }, "j",
->
awful.client.swap.byidx 1
description: "swap with next client by index"
group: "client"
awful.key { modkey, "Shift" }, "k",
->
awful.client.swap.byidx -1
description: "swap with previous client by index"
group: "client"
awful.key { modkey }, "u", awful.client.urgent.jumpto,
description: "jump to urgent client"
group: "client"
awful.key { modkey }, "l",
->
awful.tag.incmwfact 0.05
description: "increase master width factor"
group: "layout"
awful.key { modkey }, "h",
->
awful.tag.incmwfact -0.05
description: "decrease master width factor"
group: "layout"
awful.key { modkey, "Shift" }, "h",
->
awful.tag.incnmaster1, nil, true
description: "increase the number of master clients"
group: "layout"
awful.key { modkey, "Shift" }, "l",
->
awful.tag.incnmaster -1, nil, true
description: "decrease the number of master clients"
group: "layout"
awful.key { modkey, "Control" }, "h",
->
awful.tag.incncol1, nil, true
description: "increase the number of columns"
group: "layout"
awful.key { modkey, "Control" }, "l",
->
awful.tag.incncol -1, nil, true
description: "decrease the number of columns"
group: "layout"
awful.key { modkey }, "space",
->
awful.layout.inc 1
description: "select next"
group: "layout"
awful.key { modkey, "Shift" }, "space",
->
awful.layout.inc -1
description: "select previous"
group: "layout"
}
awful.keyboard.append_global_keybindings {
awful.key
modifiers: { modkey }
keygroup: "numrow"
description: "only view tag"
group: "tag"
on_press: (index) ->
screen = awful.screen.focused!
tag = screen.tags[index]
if tag then
tag\view_only!
awful.key
modifiers: { modkey, "Control" },
keygroup: "numrow",
description: "toggle tag",
group: "tag",
on_press: (index) ->
screen = awful.screen.focused!
tag = screen.tags[index]
if tag then
awful.tag.viewtoggle(tag)
awful.key
modifiers: { modkey, "Shift" },
keygroup: "numrow",
description: "move focused client to tag",
group: "tag",
on_press: (index) ->
if client.focus then
if tag = client.focus.screen.tags[index] then
client.focus\move_to_tag tag
awful.key
modifiers: { modkey, "Control", "Shift" },
keygroup: "numrow",
description: "toggle focused client on tag",
group: "tag",
on_press: (index) ->
if client.focus then
if tag = client.focus.screen.tags[index] then
client.focus\toggle_tag tag
awful.key
modifiers: { modkey },
keygroup: "numpad",
description: "select layout directly",
group: "layout",
on_press: (index) ->
if t = awful.screen.focused!.selected_tag then
t.layout = t.layouts[index] or t.layout
}
client.connect_signal "request::default_mousebindings", ->
awful.mouse.append_client_mousebindings {
awful.button {}, 1, (c) ->
c\activate
context: "mouse_click"
awful.button { modkey }, 1, (c) ->
c\activate
context: "mouse_click"
action: "mouse_move"
awful.button { modkey }, 3, (c) ->
c\activate
context: "mouse_click"
action: "mouse_resize"
}
client.connect_signal "request::default_keybindings", ->
awful.keyboard.append_client_keybindings {
awful.key { modkey }, "f",
(c) ->
c.fullscreen = not c.fullscreen
c\raise!
description: "toggle fullscreen"
group: "client"
awful.key { modkey, "Shift" }, "c", (c) -> c\kill!,
description: "close"
group: "client"
awful.key { modkey, "Control" }, "space", awful.client.floating.toggle,
description: "toggle floating"
group: "client"
awful.key { modkey, "Control" }, "Return", (c) -> c\swap awful.client.getmaster!,
description: "move to master"
group: "client"
awful.key { modkey }, "o", (c) -> c\move_to_screen!,
description: "move to screen"
group: "client"
awful.key { modkey }, "t", (c) -> c.ontop = not c.ontop,
description: "toggle keep on top"
group: "client"
awful.key { modkey }, "n",
(c) ->
-- The client currently has the input focus, so it cannot be
-- minimized, since minimized clients can't have the focus.
c.minimized = true
description: "minimize"
group: "client"
awful.key { modkey }, "m",
(c) ->
c.maximized = not c.maximized
c\raise!
description: "(un)maximize"
group: "client"
awful.key { modkey, "Control" }, "m",
(c) ->
c.maximized_vertical = not c.maximized_vertical
c\raise!
description: "(un)maximize vertically"
group: "client"
awful.key { modkey, "Shift" }, "m",
(c) ->
c.maximized_horizontal = not c.maximized_horizontal
c\raise!
description: "(un)maximize horizontally"
group: "client"
}
-- }}}
-- {{{ Rules
-- Rules to apply to new clients.
ruled.client.connect_signal "request::rules", ->
-- All clients will match this rule.
ruled.client.append_rule
id: "global"
rule: {}
properties:
focus: awful.client.focus.filter
raise: true
screen: awful.screen.preferred
placement: awful.placement.no_overlap + awful.placement.no_offscreen
-- Floating clients.
ruled.client.append_rule
id: "floating"
rule_any: {
instance: {
"copyq"
"pinentry"
}
class: {
"Arandr"
"Blueman-manager"
"Gpick"
"Kruler"
"Sxiv"
"Tor Browser"
"Wpa_gui"
"veromix"
"xtightvncviewer"
}
-- Note that the name property shown in xprop might be set slightly after creation of the client
-- and the name shown there might not match defined rules here.
name: {
"Event Tester" -- xev.
}
role: {
"AlarmWindow" -- Thunderbird's calendar.
"ConfigManager" -- Thunderbird's about:config.
"pop-up" -- e.g. Google Chrome's (detached) Developer Tools.
}
},
properties:
floating: true
-- Add titlebars to normal clients and dialogs
ruled.client.append_rule
id: "titlebars",
rule_any:
type: {
"normal"
"dialog"
}
properties:
titlebars_enabled: true
-- Set Firefox to always map on the tag named "2" on screen 1.
-- ruled.client.append_rule {
-- rule = { class = "Firefox" },
-- properties = { screen = 1, tag = "2" }
-- }
-- }}}
-- {{{ Titlebars
-- Add a titlebar if titlebars_enabled is set to true in the rules.
client.connect_signal "request::titlebars", (c) ->
-- buttons for the titlebar
buttons = {
awful.button {}, 1, ->
c\activate
context: "titlebar"
action: "mouse_move"
awful.button {}, 3, ->
c\activate
context: "titlebar"
action: "mouse_resize"
}
awful.titlebar(c).widget = {
{ -- Left
awful.titlebar.widget.iconwidget(c)
buttons: buttons
layout: wibox.layout.fixed.horizontal
}
{ -- Middle
{ -- Title
halign: "center"
widget: awful.titlebar.widget.titlewidget c
},
buttons: buttons,
layout: wibox.layout.flex.horizontal
}
{ -- Right
awful.titlebar.widget.floatingbutton c
awful.titlebar.widget.maximizedbutton c
awful.titlebar.widget.stickybutton c
awful.titlebar.widget.ontopbutton c
awful.titlebar.widget.closebutton c
layout: wibox.layout.fixed.horizontal()
}
layout: wibox.layout.align.horizontal
}
-- }}}
-- {{{ Notifications
ruled.notification.connect_signal "request::rules", ->
-- All notifications will match this rule.
ruled.notification.append_rule
rule: {},
properties:
screen: awful.screen.preferred,
implicit_timeout: 5,
naughty.connect_signal "request::display", (n) ->
naughty.layout.box
notification: n
-- }}}
-- Enable sloppy focus, so that focus follows mouse.
client.connect_signal "mouse::enter", (c) ->
c\activate
context: "mouse_enter"
raise: false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment