Skip to content

Commit

Permalink
Add an experimental scroll-WM-like Awesome layout
Browse files Browse the repository at this point in the history
  • Loading branch information
demostanis committed Dec 9, 2024
1 parent 55d671e commit dc2fcbd
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 16 deletions.
24 changes: 13 additions & 11 deletions airootfs/etc/skel/.config/awesome/globalkeys.lua
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ local function app_shortcut(app, key)
end

local globalkeys = gears.table.join(
awful.key({ modkey }, "l", awful.tag.viewnext),
awful.key({ modkey }, "h", awful.tag.viewprev),

awful.key({ modkey, "Shift" }, "l", function() moveclient("down") end),
awful.key({ modkey, "Shift" }, "h", function() moveclient("up") end),

Expand All @@ -47,17 +44,11 @@ local globalkeys = gears.table.join(

awful.key({ modkey }, "r", awesome.restart),

awful.key({ modkey }, "Tab", function()
switcher.switch(1, modkey, "Super_L", "Shift", "Tab")
end),
awful.key({ modkey, "Shift" }, "Tab", function()
switcher.switch(-1, modkey, "Super_L", "Shift", "Tab")
end),

awful.key({ modkey }, "p", function() show_panel() end, nil),
awful.key({ modkey }, "k", require"screenlock", nil),
awful.key({ modkey }, "o", require"overview", nil),
awful.key({ modkey }, "space", require"applauncher", nil),
awful.key({ modkey }, "u", function() awful.spawn("nemo /home/demostanis/programming/subjects") end, nil),
-- God, why is it trying to call some on_release when I don't specify nil??
awful.key({ modkey }, "e", require"emojipicker", nil),

Expand All @@ -77,9 +68,20 @@ local globalkeys = gears.table.join(
end),
awful.key({ }, "XF86AudioLowerVolume", function()
awful.spawn("amixer -q sset Master 3%-", false)
end)
end),

awful.key({ modkey }, "h", layout.move_left_window),
awful.key({ modkey }, "l", layout.move_right_window),

awful.key({ modkey }, "Tab", layout.cycle_window_focus)
)

root.keys(globalkeys)

root.buttons(gears.table.join(
-- scroll
awful.button({ modkey }, 5, layout.move_left),
awful.button({ modkey }, 4, layout.move_right)
))

-- vim:set et sw=4 ts=4:
187 changes: 187 additions & 0 deletions airootfs/etc/skel/.config/awesome/layout.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,187 @@
local step = 500
local margin_before_window_on_focus = 50

local global_x = 0
local scroll = {name = "scroll"}
function scroll.arrange(p)
local t = p.tag
local wa = p.workarea
local cls = p.clients

local x = global_x + 0
for i=#cls,1,-1 do
local g = {}
local c = cls[i]

-- TODO: do not hardcode
g.x = x + 5
g.y = beautiful.wibar_height+10
g.width = c.width
g.height = mouse.screen.geometry.height-beautiful.dock_height-10
p.geometries[c] = g

x = x + c.width
end
end

local function leftmost_window()
local leftmost = nil
for _, c in ipairs(mouse.screen.clients) do
if not leftmost or leftmost.x < 0 or (c.x > 0 and c.x < leftmost.x) then
leftmost = c
end
end
return leftmost
end

local function lefthand_window()
local lefthand = nil
local leftmost = leftmost_window()
for _, c in ipairs(mouse.screen.clients) do
if not lefthand or (
math.abs(c.x+c.width-leftmost.x) <
math.abs(lefthand.x+lefthand.width-leftmost.x)) then
lefthand = c
end
end
return lefthand
end

local function righthand_window()
local righthand = nil
local leftmost = leftmost_window()
for _, c in ipairs(mouse.screen.clients) do
if not righthand or (
math.abs(c.x-(leftmost.x+leftmost.width)) <
math.abs(righthand.x-(leftmost.x+leftmost.width))) then
righthand = c
end
end
return righthand
end

local function farthest_window()
local farthest = nil
for _, c in ipairs(mouse.screen.clients) do
if not farthest or c.x > farthest.x then
farthest = c
end
end
return farthest
end

local function first_window()
local nearest = nil
for _, c in ipairs(mouse.screen.clients) do
if not nearest or c.x < nearest.x then
nearest = c
end
end
return nearest
end

local function set_global_x(new)
rubato.timed{
pos = global_x,
duration = 0.3,
subscribed = function(w)
global_x = w
awful.layout.arrange(mouse.screen)
end
}.target = new
end

local function move_right()
if client.focus then
local farthest = farthest_window()
if farthest.x < 0 then
return
end
local new_global_x = global_x - step
set_global_x(new_global_x)
end
end

local function move_left()
if client.focus then
local new_global_x = global_x + step
if new_global_x > 0 then
new_global_x = 0
end
set_global_x(new_global_x)
end
end

local function global_x_to_client(c)
local new_global_x = c.x-first_window().x
if new_global_x <= 0 then
new_global_x = 0
else
new_global_x = new_global_x - margin_before_window_on_focus
end
return -new_global_x
end

local function move_left_window()
local lefthand = lefthand_window()
set_global_x(global_x_to_client(lefthand))
client.focus = lefthand
end

local function move_right_window()
local righthand = righthand_window()
set_global_x(global_x_to_client(righthand))
client.focus = righthand
end

local function cycle_window_focus()
local windows_in_viewport = {}
for _, c in ipairs(mouse.screen.clients) do
-- don't judge those magic numbers please
if c.x+c.width > 56 and c.x < c.screen.geometry.width-56 then
table.insert(windows_in_viewport, c)
end
end
table.sort(windows_in_viewport, function(a, b)
return a.x < b.x
end)
if #windows_in_viewport < 2 then
return
end
for i, c in ipairs(windows_in_viewport) do
if c == client.focus then
if i == #windows_in_viewport then
i = 1
else
i = i+1
end
local target = windows_in_viewport[i]
target:activate { context = "mouse_enter", raise = false }
return
end
end
end

client.connect_signal("raised", function(c)
set_global_x(global_x_to_client(c))
end)

client.connect_signal("unmanage", function()
gears.timer{
timeout = 0.1,
single_shot = true,
call_once = true,
callback = function()
set_global_x(global_x_to_client(client.focus))
end
}:start()
end)

return {
move_left = move_left,
move_right = move_right,
move_left_window = move_left_window,
move_right_window = move_right_window,
cycle_window_focus = cycle_window_focus,
scroll = scroll,
}
23 changes: 21 additions & 2 deletions airootfs/etc/skel/.config/awesome/rc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ bling = require"bling"
utils = require"utils"
cairo = require"lgi".cairo
glib = require"lgi".GLib
layout = require"layout"

terminal = "urxvt"
modkey = "Mod4"
Expand All @@ -33,7 +34,7 @@ awful.screen.connect_for_each_screen(function(s)
-- Why is it not the same color??? Why do I have to hardcode this one??
gears.wallpaper.centered(beautiful.wallpaper, s, "#1E0427", 0.1)

awful.tag({ "1", "2", "3", "4", "5" }, s, awful.layout.suit.floating)
awful.tag({ "1", "2", "3", "4", "5" }, s, layout.scroll)

s.mywibar = require"wibar"(s)
s.mydock = require"dock"(s)
Expand Down Expand Up @@ -70,13 +71,27 @@ client.connect_signal("manage", function(c)
end)
end)

function grabmouse(fn)
return function(c)
c:emit_signal("request::activate", "mouse_click", {raise = true})
mousegrabber.run(function()
fn()
return false
end, "mouse")
end
end

awful.rules.rules = {{
rule = { },
properties = {
focus = awful.client.focus.filter,
raise = true,
keys = require"clientkeys",
buttons = require"windowcontrols",
buttons = gears.table.join(
require"windowcontrols",
awful.button({ modkey }, 5, grabmouse(layout.move_left)),
awful.button({ modkey }, 4, grabmouse(layout.move_right))
),
screen = awful.screen.preferred,
placement = awful.placement.no_overlap+awful.placement.no_offscreen,
size_hints_honor = false
Expand Down Expand Up @@ -119,4 +134,8 @@ client.connect_signal("request::titlebars", function(c)
require"tabs"(c)
end)

client.connect_signal("mouse::enter", function(c)
c:activate { context = "mouse_enter", raise = false }
end)

-- vim:set et sw=4 ts=4:
1 change: 1 addition & 0 deletions airootfs/etc/skel/.config/awesome/theme/theme.lua
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ theme.wibar_widget_hover_color = theme.color13
theme.panel_width = 415
theme.panel_height = 415
theme.dock_width = 50
theme.dock_height = 100
theme.dock_indicator_color = theme.color7
theme.border_radius = 5

Expand Down
2 changes: 1 addition & 1 deletion airootfs/etc/skel/.config/awesome/wibar.lua
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ return function(s)
mywibar:setup {
{
require"panel"(s),
require"taglist"(s),
nil,
{
{
{
Expand Down
11 changes: 9 additions & 2 deletions airootfs/etc/skel/.config/awesome/windowcontrols.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local cursors = {
["left"] = "sb_h_double_arrow",
["right"] = "sb_h_double_arrow",
Expand Down Expand Up @@ -108,12 +107,20 @@ return gears.table.join(
return true
end

-- with scroll layout
c.width = geo.width
-- with floating layout
c:emit_signal(
"request::geometry", "mouse.resize",
geo)
return true
end, cursors[corner])
end)
end),

awful.key({ modkey }, "h", layout.move_left_window),
awful.key({ modkey }, "l", layout.move_right_window),

awful.key({ modkey }, "Tab", layout.cycle_window_focus)
)

-- vim:set et sw=4 ts=4:

0 comments on commit dc2fcbd

Please sign in to comment.