430 lines
11 KiB
Lua
Executable file
430 lines
11 KiB
Lua
Executable file
#!/usr/bin/lua5.4
|
|
|
|
-- Convenient functions ────────────────────────────────────────────────────────
|
|
|
|
-- Wrapper around table.concat() to also handle other types
|
|
local function concat(...)
|
|
local list, sep, i, j = ...
|
|
|
|
if type(list) == 'table' then
|
|
return table.concat(list, sep, i, j)
|
|
else
|
|
return tostring(list)
|
|
end
|
|
end
|
|
|
|
-- All the setting tables ──────────────────────────────────────────────────────
|
|
|
|
local wallpapers = {
|
|
primary = '~/Pictures/wallpaper/wof.jpg',
|
|
secondary = '~/Pictures/wallpaper/wof.jpg'
|
|
}
|
|
|
|
local monitors = {
|
|
main = 'eDP-2',
|
|
external = 'HDMI-A-1'
|
|
}
|
|
|
|
local pointers = {
|
|
touchpad = 'pointer-10248-514-ASUF1204:00_2808:0202_Touchpad',
|
|
mouse = 'pointer-9639-64124-Compx_2.4G_Wireless_Receiver'
|
|
}
|
|
|
|
local startup_commands = {
|
|
-- Inform dbus about the environment variables
|
|
{
|
|
'dbus-update-activation-environment',
|
|
'DISPLAY',
|
|
'WAYLAND_DISPLAY',
|
|
'XDG_SESSION_TYPE',
|
|
'XDG_CURRENT_DESKTOP',
|
|
},
|
|
{
|
|
'waybar'
|
|
},
|
|
{
|
|
'kanshi'
|
|
},
|
|
-- Wallpaper
|
|
{
|
|
string.format("swaybg -o %s -i %s -o %s -i %s",
|
|
monitors.main, wallpapers.primary,
|
|
monitors.external, wallpapers.secondary)
|
|
},
|
|
-- Fetch mail
|
|
{
|
|
'fetchmail',
|
|
'-d', '600'
|
|
},
|
|
-- Update notmuch database
|
|
{
|
|
'notmuch',
|
|
'new'
|
|
}
|
|
}
|
|
|
|
local inputs = {
|
|
[pointers.touchpad] = {
|
|
['drag'] = 'enabled',
|
|
['tap'] = 'enabled',
|
|
['tap-button-map'] = 'left-right-middle',
|
|
['disable-while-typing'] = 'enabled',
|
|
['scroll-method'] = 'two-finger',
|
|
['accel-profile'] = 'none',
|
|
},
|
|
[pointers.mouse] = {
|
|
['accel-profile'] = 'none',
|
|
}
|
|
}
|
|
|
|
local river_options = {
|
|
-- Theme options
|
|
['border-width'] = 2,
|
|
['border-color-focused'] = '0xeceff4',
|
|
['border-color-unfocused'] = '0x81a1c1',
|
|
['border-color-urgent'] = '0xbf616a',
|
|
['xcursor-theme'] = { 'Vimix-cursors', 24 },
|
|
['background-color'] = '0x2e3440',
|
|
|
|
-- Other options
|
|
['set-repeat'] = { 25, 300 },
|
|
['focus-follows-cursor'] = 'normal',
|
|
['set-cursor-warp'] = 'on-output-change',
|
|
['attach-mode'] = 'bottom',
|
|
['default-layout'] = 'rivertile',
|
|
['keyboard-layout'] = { '-options', 'grp:alt_shift_toggle', 'us,ru' }
|
|
}
|
|
|
|
local gsettings = {
|
|
['org.gnome.desktop.interface'] = {
|
|
['gtk-theme'] = 'Nordic',
|
|
['icon-theme'] = 'Papirus-Dark',
|
|
['cursor-theme'] = river_options['xcursor-theme'][1],
|
|
['cursor-size'] = river_options['xcursor-theme'][2],
|
|
},
|
|
}
|
|
|
|
local modes = {
|
|
{
|
|
name = 'passthrough',
|
|
mod = 'Super',
|
|
key = 'F11',
|
|
},
|
|
}
|
|
|
|
local mappings = {
|
|
map = {
|
|
normal = {
|
|
-- Terminal emulator
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'T',
|
|
command = { 'spawn', 'alacritty' },
|
|
},
|
|
-- Application launcher
|
|
{
|
|
mod = { 'Shift', 'Control' },
|
|
key = 'Escape',
|
|
command = { 'spawn', [['wofi --show drun']] }
|
|
},
|
|
-- Region screenshot
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'S',
|
|
command = { 'spawn', [['slurp | grim -g - - | wl-copy']] }
|
|
},
|
|
-- Output screenshot
|
|
{
|
|
mod = 'None',
|
|
key = 'Print',
|
|
command = { 'spawn', [['slurp -o | grim -g - - | wl-copy']] }
|
|
},
|
|
-- Screen locker
|
|
{
|
|
mod = 'Super',
|
|
key = 'O',
|
|
command = { 'spawn', [['swaylock -i ']] .. wallpapers.primary }
|
|
},
|
|
-- Prompt wifi ssid and attempt to connect
|
|
{
|
|
mod = { 'Super', 'Alt' },
|
|
key = 'C',
|
|
command = { 'spawn', [['gui-prompt | fish -c wlan-connect']]}
|
|
},
|
|
-- Close view
|
|
{
|
|
mod = 'Alt',
|
|
key = 'F4',
|
|
command = 'close',
|
|
},
|
|
-- Exit river
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'Q',
|
|
command = 'exit',
|
|
},
|
|
-- Focus next/previous view
|
|
{
|
|
mod = 'Super',
|
|
key = 'J',
|
|
command = { 'focus-view', 'previous' },
|
|
},
|
|
{
|
|
mod = 'Super',
|
|
key = 'K',
|
|
command = { 'focus-view', 'next' },
|
|
},
|
|
-- Swap focused view with the next/previous view
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'J',
|
|
command = { 'swap', 'previous' },
|
|
},
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'K',
|
|
command = { 'swap', 'next' },
|
|
},
|
|
-- Focus next/previous output
|
|
{
|
|
mod = 'Super',
|
|
key = 'P',
|
|
command = { 'focus-output', 'previous' },
|
|
},
|
|
{
|
|
mod = 'Super',
|
|
key = 'N',
|
|
command = { 'focus-output', 'next' },
|
|
},
|
|
-- Send the focused view to next/previous output
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'P',
|
|
command = { 'send-to-output', 'previous' },
|
|
},
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'N',
|
|
command = { 'send-to-output', 'next' },
|
|
},
|
|
-- Make view primary
|
|
{
|
|
mod = 'Super',
|
|
key = 'E',
|
|
command = 'zoom',
|
|
},
|
|
-- Decrease/increase the main view ratio
|
|
{
|
|
mod = 'Super',
|
|
key = 'H',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-ratio -0.02']] },
|
|
},
|
|
{
|
|
mod = 'Super',
|
|
key = 'L',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-ratio +0.02']] },
|
|
},
|
|
-- Increment/decrement the main_count value of rivertile
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'H',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-count +1']] },
|
|
},
|
|
{
|
|
mod = { 'Super', 'Shift' },
|
|
key = 'L',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-count -1']] },
|
|
},
|
|
-- Change layout orientation
|
|
{
|
|
mod = { 'Control', 'Alt' },
|
|
key = 'H',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-location left']] },
|
|
},
|
|
{
|
|
mod = { 'Control', 'Alt' },
|
|
key = 'J',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-location bottom']] },
|
|
},
|
|
{
|
|
mod = { 'Control', 'Alt' },
|
|
key = 'K',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-location top']] },
|
|
},
|
|
{
|
|
mod = { 'Control', 'Alt' },
|
|
key = 'L',
|
|
command = { 'send-layout-cmd', 'rivertile', [['main-location right']] },
|
|
},
|
|
-- Toggle float
|
|
{
|
|
mod = 'Super',
|
|
key = 'Space',
|
|
command = 'toggle-float',
|
|
},
|
|
-- Toggle fullscreen
|
|
{
|
|
mod = 'Super',
|
|
key = 'F',
|
|
command = 'toggle-fullscreen',
|
|
},
|
|
-- Media buttons
|
|
{
|
|
mod = 'None',
|
|
key = 'XF86AudioNext',
|
|
command = { 'spawn', [['mpc next']] }
|
|
},
|
|
{
|
|
mod = 'None',
|
|
key = 'XF86AudioPlay',
|
|
command = { 'spawn', [['mpc toggle']] }
|
|
}
|
|
},
|
|
},
|
|
-- Mappings for pointer (mouse)
|
|
['map-pointer'] = {
|
|
normal = {
|
|
-- Move floating views
|
|
{
|
|
mod = 'Super',
|
|
key = 'BTN_LEFT',
|
|
command = 'move-view',
|
|
},
|
|
-- Resize floating views
|
|
{
|
|
mod = 'Super',
|
|
key = 'BTN_RIGHT',
|
|
command = 'resize-view',
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
-- These mappings are repeated, so they are separated from the mappings table
|
|
local function tag_mappings()
|
|
for i = 1, 9 do
|
|
local tag_num = 1 << (i - 1)
|
|
|
|
-- Super+[1-9] to focus tag [0-8]
|
|
os.execute(string.format('riverctl map normal Super %s set-focused-tags %s', i, tag_num))
|
|
|
|
-- Super+Shift+[1-9] to tag focused view with tag [0-8]
|
|
os.execute(string.format('riverctl map normal Super+Shift %s set-view-tags %s', i, tag_num))
|
|
|
|
-- Super+Control+[1-9] to toggle focus of tag [0-8]
|
|
os.execute(string.format('riverctl map normal Super+Control %s toggle-focused-tags %s', i, tag_num))
|
|
|
|
-- Super+Alt+[1-9] to toggle tag [0-8] of focused view
|
|
os.execute(string.format('riverctl map normal Super+Alt %s toggle-view-tags %s', i, tag_num))
|
|
end
|
|
|
|
-- river has a total of 32 tags
|
|
local all_tags = (1 << 32) - 1
|
|
os.execute(string.format('riverctl map normal Super 0 set-focused-tags %s', all_tags))
|
|
os.execute(string.format('riverctl map normal Super+Shift 0 set-view-tags %s', all_tags))
|
|
end
|
|
|
|
-- Window rules
|
|
local window_rules = {
|
|
{
|
|
app_id = "gui-prompt",
|
|
rule = "float"
|
|
},
|
|
{
|
|
app_id = "gui-prompt",
|
|
rule = "ssd"
|
|
}
|
|
}
|
|
|
|
-- Apply settings ──────────────────────────────────────────────────────────────
|
|
|
|
for _, cmd in ipairs(startup_commands) do
|
|
os.execute(string.format([[riverctl spawn '%s']], concat(cmd, ' ')))
|
|
end
|
|
|
|
-- Configure input devices
|
|
for device, options in pairs(inputs) do
|
|
for key, val in pairs(options) do
|
|
os.execute(string.format('riverctl input %s %s %s', device, key, val))
|
|
end
|
|
end
|
|
|
|
-- GNOME-related settings
|
|
for group, tbl in pairs(gsettings) do
|
|
for key, value in pairs(tbl) do
|
|
os.execute(string.format('gsettings set %s %s %s', group, key, value))
|
|
end
|
|
end
|
|
|
|
-- Set river's options
|
|
for key, value in pairs(river_options) do
|
|
os.execute(string.format('riverctl %s %s', key, concat(value, ' ')))
|
|
end
|
|
|
|
-- Additional modes (beside 'normal' and 'locked')
|
|
for _, mode in ipairs(modes) do
|
|
local mode_name = mode.name
|
|
local modifiers = concat(mode.mod, '+')
|
|
|
|
-- Declare the mode
|
|
os.execute('riverctl declare-mode ' .. mode_name)
|
|
|
|
-- Setup key bindings to enter/exit the mode
|
|
os.execute(string.format('riverctl map normal %s %s enter-mode %s', modifiers, mode.key, mode_name))
|
|
os.execute(string.format('riverctl map %s %s %s enter-mode normal', mode_name, modifiers, mode.key))
|
|
end
|
|
|
|
-- Keyboard and mouse bindings
|
|
for map_type, tbl in pairs(mappings) do
|
|
for mode, value in pairs(tbl) do
|
|
for _, binding in ipairs(value) do
|
|
local modifiers = concat(binding.mod, '+')
|
|
local cmd = concat(binding.command, ' ')
|
|
|
|
-- Options -release and -repeat for 'map' and 'unmap' commands
|
|
local opt = binding.opt
|
|
if opt ~= 'release' and opt ~= 'repeat' then
|
|
opt = ''
|
|
else
|
|
opt = '-' .. opt
|
|
end
|
|
local layout = ''
|
|
-- -layout 0 is hardcoded on 'riverctl map *' to make mappings work on any layout
|
|
if map_type == 'map' then
|
|
layout = '-layout 0'
|
|
end
|
|
os.execute(string.format('riverctl %s %s %s %s %s %s %s', map_type, layout, opt, mode, modifiers, binding.key, cmd))
|
|
|
|
-- Duplicate mappings of mode 'locked' for mode 'normal'
|
|
if mode == 'locked' then
|
|
os.execute(string.format('riverctl %s -layout 0 %s normal %s %s %s', map_type, opt, modifiers, binding.key, cmd))
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
-- Mappings for tag management
|
|
tag_mappings()
|
|
|
|
for _, rule in ipairs(window_rules) do
|
|
local cmd = "riverctl rule-add "
|
|
if rule.app_id ~= nil then
|
|
cmd = cmd .. "-app-id " .. rule.app_id
|
|
end
|
|
if rule.title ~= nil then
|
|
cmd = cmd .. "-title " .. rule.title
|
|
end
|
|
cmd = cmd .. " " .. rule.rule
|
|
|
|
os.execute(cmd)
|
|
end
|
|
|
|
-- Launch the layout generator as the final initial process.
|
|
local unistd = require('posix.unistd')
|
|
unistd.execp('rivertile', {
|
|
'-view-padding', 5,
|
|
'-outer-padding', 5,
|
|
'-main-location', 'left',
|
|
'-main-count', 1,
|
|
'-main-ratio', 0.7,
|
|
})
|