2019-08-01 03:00:38 +02:00
|
|
|
local machi = {
|
|
|
|
layout = require((...):match("(.-)[^%.]+$") .. "layout"),
|
|
|
|
}
|
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
local api = {
|
2019-07-07 19:05:42 +02:00
|
|
|
client = client,
|
2019-07-06 17:35:12 +02:00
|
|
|
beautiful = require("beautiful"),
|
|
|
|
wibox = require("wibox"),
|
|
|
|
awful = require("awful"),
|
|
|
|
screen = require("awful.screen"),
|
|
|
|
layout = require("awful.layout"),
|
|
|
|
naughty = require("naughty"),
|
|
|
|
gears = require("gears"),
|
2019-07-06 23:06:14 +02:00
|
|
|
lgi = require("lgi"),
|
2019-07-06 17:35:12 +02:00
|
|
|
dpi = require("beautiful.xresources").apply_dpi,
|
|
|
|
}
|
|
|
|
|
2019-07-07 23:36:48 +02:00
|
|
|
local function min(a, b)
|
|
|
|
if a < b then return a else return b end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function max(a, b)
|
|
|
|
if a < b then return b else return a end
|
|
|
|
end
|
|
|
|
|
2019-07-06 23:06:14 +02:00
|
|
|
local function with_alpha(col, alpha)
|
2019-07-12 16:05:58 +02:00
|
|
|
local r, g, b
|
|
|
|
_, r, g, b, _ = col:get_rgba()
|
2019-07-06 23:06:14 +02:00
|
|
|
return api.lgi.cairo.SolidPattern.create_rgba(r, g, b, alpha)
|
|
|
|
end
|
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
local function start(c)
|
2019-07-14 00:39:38 +02:00
|
|
|
local tablist_font_desc = api.beautiful.get_merged_font(
|
|
|
|
api.beautiful.mono_font or api.beautiful.font, api.dpi(10))
|
|
|
|
local font_color = with_alpha(api.gears.color(api.beautiful.fg_normal), 1)
|
2019-07-16 15:28:10 +02:00
|
|
|
local font_color_hl = with_alpha(api.gears.color(api.beautiful.fg_focus), 1)
|
2019-07-14 00:39:38 +02:00
|
|
|
local label_size = api.dpi(30)
|
|
|
|
local border_color = with_alpha(api.gears.color(api.beautiful.border_focus), 0.75)
|
|
|
|
local fill_color = with_alpha(api.gears.color(api.beautiful.bg_normal), 0.5)
|
|
|
|
local fill_color_hl = with_alpha(api.gears.color(api.beautiful.bg_focus), 1)
|
|
|
|
-- for comparing floats
|
|
|
|
local threshold = 0.1
|
|
|
|
local traverse_radius = api.dpi(5)
|
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
local screen = c.screen
|
2019-07-18 05:26:09 +02:00
|
|
|
local start_x = screen.workarea.x
|
|
|
|
local start_y = screen.workarea.y
|
2019-07-08 19:15:05 +02:00
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
local layout = api.layout.get(screen)
|
2019-07-12 16:05:58 +02:00
|
|
|
if c.floating or layout.machi_get_regions == nil then return end
|
2019-07-06 17:35:12 +02:00
|
|
|
|
2019-08-01 03:00:38 +02:00
|
|
|
local regions, draft_mode = layout.machi_get_regions(c.screen.workarea, c.screen.selected_tag)
|
2019-07-06 18:22:19 +02:00
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
local infobox = api.wibox({
|
2019-07-06 18:22:19 +02:00
|
|
|
screen = screen,
|
2019-07-06 17:35:12 +02:00
|
|
|
x = screen.workarea.x,
|
|
|
|
y = screen.workarea.y,
|
|
|
|
width = screen.workarea.width,
|
|
|
|
height = screen.workarea.height,
|
|
|
|
bg = "#ffffff00",
|
|
|
|
opacity = 1,
|
2019-08-05 00:52:50 +02:00
|
|
|
ontop = true,
|
|
|
|
type = "dock",
|
2019-07-06 17:35:12 +02:00
|
|
|
})
|
|
|
|
infobox.visible = true
|
|
|
|
|
2019-08-01 03:00:38 +02:00
|
|
|
local tablist_region = nil
|
2019-07-07 19:30:05 +02:00
|
|
|
local tablist = nil
|
|
|
|
local tablist_index = nil
|
|
|
|
|
2019-07-07 23:36:48 +02:00
|
|
|
local traverse_x = c.x + traverse_radius
|
|
|
|
local traverse_y = c.y + traverse_radius
|
2019-07-06 18:22:19 +02:00
|
|
|
|
2019-07-09 23:34:06 +02:00
|
|
|
local function ensure_tablist()
|
|
|
|
if tablist == nil then
|
|
|
|
tablist = {}
|
|
|
|
for _, tc in ipairs(screen.tiled_clients) do
|
2019-08-01 03:00:38 +02:00
|
|
|
if not (tc.floating or tc.maximized or tc.maximized_horizontal or tc.maximized_vertical)
|
2019-07-09 23:34:06 +02:00
|
|
|
then
|
2019-08-01 03:00:38 +02:00
|
|
|
if tc.x <= traverse_x and traverse_x < tc.x + tc.width and
|
|
|
|
tc.y <= traverse_y and traverse_y < tc.y + tc.height
|
|
|
|
then
|
|
|
|
tablist[#tablist + 1] = tc
|
|
|
|
end
|
2019-07-09 23:34:06 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
tablist_index = 1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
local function draw_info(context, cr, width, height)
|
2019-07-09 23:34:06 +02:00
|
|
|
ensure_tablist()
|
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
cr:set_source_rgba(0, 0, 0, 0)
|
|
|
|
cr:rectangle(0, 0, width, height)
|
|
|
|
cr:fill()
|
|
|
|
|
|
|
|
local msg, ext
|
|
|
|
for i, a in ipairs(regions) do
|
2019-08-01 03:00:38 +02:00
|
|
|
if a.x <= traverse_x and traverse_x < a.x + a.width and
|
|
|
|
a.y <= traverse_y and traverse_y < a.y + a.height then
|
2019-07-07 23:18:10 +02:00
|
|
|
|
2019-07-08 13:36:06 +02:00
|
|
|
local pl = api.lgi.Pango.Layout.create(cr)
|
|
|
|
pl:set_font_description(tablist_font_desc)
|
2019-07-08 16:03:49 +02:00
|
|
|
|
|
|
|
local vpadding = api.dpi(10)
|
2019-07-24 01:08:26 +02:00
|
|
|
local list_height = vpadding
|
2019-07-08 16:03:49 +02:00
|
|
|
local exts = {}
|
2019-07-07 23:18:10 +02:00
|
|
|
|
|
|
|
for index, tc in ipairs(tablist) do
|
|
|
|
local label = tc.name
|
2019-07-08 13:36:06 +02:00
|
|
|
pl:set_text(label)
|
|
|
|
local w, h
|
|
|
|
w, h = pl:get_size()
|
|
|
|
w = w / api.lgi.Pango.SCALE
|
|
|
|
h = h / api.lgi.Pango.SCALE
|
|
|
|
local ext = { width = w, height = h, x_bearing = 0, y_bearing = 0 }
|
2019-07-08 16:03:49 +02:00
|
|
|
exts[#exts + 1] = ext
|
2019-07-24 01:08:26 +02:00
|
|
|
list_height = list_height + ext.height + vpadding
|
2019-07-08 16:03:49 +02:00
|
|
|
end
|
|
|
|
|
2019-07-18 05:26:09 +02:00
|
|
|
local x_offset = a.x + a.width / 2 - start_x
|
2019-07-24 01:08:26 +02:00
|
|
|
local y_offset = a.y + a.height / 2 - list_height / 2 + vpadding - start_y
|
2019-07-08 16:03:49 +02:00
|
|
|
|
2019-08-01 03:00:38 +02:00
|
|
|
-- cr:rectangle(a.x - start_x, y_offset - vpadding - start_y, a.width, list_height)
|
|
|
|
-- cover the entire region
|
|
|
|
cr:rectangle(a.x - start_x, a.y - start_y, a.width, a.height)
|
2019-07-08 16:03:49 +02:00
|
|
|
cr:set_source(fill_color)
|
|
|
|
cr:fill()
|
|
|
|
|
|
|
|
for index, tc in ipairs(tablist) do
|
|
|
|
local label = tc.name
|
|
|
|
local ext = exts[index]
|
2019-07-07 23:18:10 +02:00
|
|
|
if index == tablist_index then
|
2019-07-08 16:03:49 +02:00
|
|
|
cr:rectangle(x_offset - ext.width / 2 - vpadding / 2, y_offset - vpadding / 2, ext.width + vpadding, ext.height + vpadding)
|
2019-07-07 23:18:10 +02:00
|
|
|
cr:set_source(fill_color_hl)
|
2019-07-08 16:03:49 +02:00
|
|
|
cr:fill()
|
2019-07-16 15:28:10 +02:00
|
|
|
pl:set_text(label)
|
|
|
|
cr:move_to(x_offset - ext.width / 2 - ext.x_bearing, y_offset - ext.y_bearing)
|
|
|
|
cr:set_source(font_color_hl)
|
|
|
|
cr:show_layout(pl)
|
|
|
|
else
|
|
|
|
pl:set_text(label)
|
|
|
|
cr:move_to(x_offset - ext.width / 2 - ext.x_bearing, y_offset - ext.y_bearing)
|
|
|
|
cr:set_source(font_color)
|
|
|
|
cr:show_layout(pl)
|
2019-07-07 23:18:10 +02:00
|
|
|
end
|
|
|
|
|
2019-07-08 16:03:49 +02:00
|
|
|
y_offset = y_offset + ext.height + vpadding
|
2019-07-07 23:18:10 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-01 20:53:13 +02:00
|
|
|
cr:rectangle(a.x - start_x, a.y - start_y, a.width, a.height)
|
|
|
|
cr:clip()
|
2019-07-06 23:06:14 +02:00
|
|
|
-- cr:set_source(fill_color)
|
|
|
|
-- cr:rectangle(a.x, a.y, a.width, a.height)
|
|
|
|
-- cr:fill()
|
|
|
|
cr:set_source(border_color)
|
2019-07-18 05:26:09 +02:00
|
|
|
cr:rectangle(a.x - start_x, a.y - start_y, a.width, a.height)
|
2019-07-06 23:06:14 +02:00
|
|
|
cr:set_line_width(10.0)
|
|
|
|
cr:stroke()
|
|
|
|
cr:reset_clip()
|
2019-07-06 17:35:12 +02:00
|
|
|
end
|
2019-07-06 18:22:19 +02:00
|
|
|
|
2019-07-06 23:06:14 +02:00
|
|
|
-- show the traverse point
|
2019-07-18 05:26:09 +02:00
|
|
|
cr:rectangle(traverse_x - start_x - traverse_radius, traverse_y - start_y - traverse_radius, traverse_radius * 2, traverse_radius * 2)
|
2019-07-06 23:06:14 +02:00
|
|
|
cr:set_source_rgba(1, 1, 1, 1)
|
|
|
|
cr:fill()
|
2019-07-06 17:35:12 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
infobox.bgimage = draw_info
|
|
|
|
|
2019-08-06 04:29:03 +02:00
|
|
|
local key_translate_tab = {
|
|
|
|
["w"] = "Up",
|
|
|
|
["a"] = "Left",
|
|
|
|
["s"] = "Down",
|
|
|
|
["d"] = "Right",
|
|
|
|
}
|
|
|
|
|
2019-07-06 17:35:12 +02:00
|
|
|
local kg
|
2019-07-25 00:11:44 +02:00
|
|
|
kg = api.awful.keygrabber.run(
|
2019-07-06 17:35:12 +02:00
|
|
|
function (mod, key, event)
|
|
|
|
if event == "release" then return end
|
2019-08-06 04:29:03 +02:00
|
|
|
if key_translate_tab[key] ~= nil then
|
|
|
|
key = key_translate_tab[key]
|
|
|
|
end
|
2019-07-07 19:30:05 +02:00
|
|
|
if key == "Tab" then
|
2019-07-09 23:34:06 +02:00
|
|
|
ensure_tablist()
|
2019-07-07 19:30:05 +02:00
|
|
|
|
|
|
|
if #tablist > 0 then
|
|
|
|
tablist_index = tablist_index % #tablist + 1
|
|
|
|
c = tablist[tablist_index]
|
|
|
|
c:emit_signal("request::activate", "mouse.move", {raise=false})
|
|
|
|
c:raise()
|
2019-07-07 23:18:10 +02:00
|
|
|
|
|
|
|
infobox.bgimage = draw_info
|
2019-07-07 19:30:05 +02:00
|
|
|
end
|
|
|
|
elseif key == "Up" or key == "Down" or key == "Left" or key == "Right" then
|
2019-08-01 03:00:38 +02:00
|
|
|
local shift = false
|
|
|
|
local ctrl = false
|
|
|
|
for i, m in ipairs(mod) do
|
|
|
|
if m == "Shift" then shift = true
|
|
|
|
elseif m == "Control" then ctrl = true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-09 21:54:41 +02:00
|
|
|
local current_region = nil
|
|
|
|
|
|
|
|
if shift or ctrl then
|
|
|
|
for i, a in ipairs(regions) do
|
|
|
|
if a.x <= traverse_x and traverse_x < a.x + a.width and
|
|
|
|
a.y <= traverse_y and traverse_y < a.y + a.height
|
|
|
|
then
|
|
|
|
current_region = i
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-09 23:34:55 +02:00
|
|
|
if shift then
|
|
|
|
if current_region == nil or
|
|
|
|
regions[current_region].x ~= c.x or
|
|
|
|
regions[current_region].y ~= c.y
|
|
|
|
then
|
|
|
|
traverse_x = c.x + traverse_radius
|
|
|
|
traverse_y = c.y + traverse_radius
|
|
|
|
current_region = nil
|
|
|
|
end
|
|
|
|
elseif ctrl then
|
|
|
|
local ex = c.x + c.width + c.border_width * 2
|
|
|
|
local ey = c.y + c.height + c.border_width * 2
|
|
|
|
if current_region == nil or
|
|
|
|
regions[current_region].x + regions[current_region].width ~= ex or
|
|
|
|
regions[current_region].y + regions[current_region].height ~= ey
|
|
|
|
then
|
|
|
|
traverse_x = ex - traverse_radius
|
|
|
|
traverse_y = ey - traverse_radius
|
|
|
|
current_region = nil
|
2019-08-09 21:54:41 +02:00
|
|
|
end
|
|
|
|
end
|
2019-08-01 03:00:38 +02:00
|
|
|
end
|
|
|
|
|
2019-07-06 18:22:19 +02:00
|
|
|
local choice = nil
|
|
|
|
local choice_value
|
|
|
|
|
|
|
|
for i, a in ipairs(regions) do
|
2019-08-01 03:00:38 +02:00
|
|
|
if a.x <= traverse_x and traverse_x < a.x + a.width and
|
|
|
|
a.y <= traverse_y and traverse_y < a.y + a.height
|
|
|
|
then
|
|
|
|
current_region = i
|
|
|
|
end
|
|
|
|
|
2019-07-06 18:22:19 +02:00
|
|
|
local v
|
|
|
|
if key == "Up" then
|
|
|
|
if a.x < traverse_x + threshold
|
|
|
|
and traverse_x < a.x + a.width + threshold then
|
|
|
|
v = traverse_y - a.y - a.height
|
|
|
|
else
|
|
|
|
v = -1
|
|
|
|
end
|
|
|
|
elseif key == "Down" then
|
|
|
|
if a.x < traverse_x + threshold
|
|
|
|
and traverse_x < a.x + a.width + threshold then
|
|
|
|
v = a.y - traverse_y
|
|
|
|
else
|
|
|
|
v = -1
|
|
|
|
end
|
|
|
|
elseif key == "Left" then
|
|
|
|
if a.y < traverse_y + threshold
|
|
|
|
and traverse_y < a.y + a.height + threshold then
|
|
|
|
v = traverse_x - a.x - a.width
|
|
|
|
else
|
|
|
|
v = -1
|
|
|
|
end
|
|
|
|
elseif key == "Right" then
|
|
|
|
if a.y < traverse_y + threshold
|
|
|
|
and traverse_y < a.y + a.height + threshold then
|
|
|
|
v = a.x - traverse_x
|
|
|
|
else
|
|
|
|
v = -1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if (v > threshold) and (choice_value == nil or choice_value > v) then
|
|
|
|
choice = i
|
|
|
|
choice_value = v
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-01 03:00:38 +02:00
|
|
|
if choice == nil then
|
|
|
|
choice = current_region
|
|
|
|
if key == "Up" then
|
|
|
|
traverse_y = screen.workarea.y
|
|
|
|
elseif key == "Down" then
|
|
|
|
traverse_y = screen.workarea.y + screen.workarea.height
|
|
|
|
elseif key == "Left" then
|
|
|
|
traverse_x = screen.workarea.x
|
|
|
|
else
|
|
|
|
traverse_x = screen.workarea.x + screen.workarea.width
|
2019-07-07 19:05:42 +02:00
|
|
|
end
|
2019-08-01 03:00:38 +02:00
|
|
|
end
|
2019-07-07 19:05:42 +02:00
|
|
|
|
2019-08-01 03:00:38 +02:00
|
|
|
if choice ~= nil then
|
2019-08-01 04:46:19 +02:00
|
|
|
traverse_x = max(regions[choice].x + traverse_radius, min(regions[choice].x + regions[choice].width - traverse_radius, traverse_x))
|
|
|
|
traverse_y = max(regions[choice].y + traverse_radius, min(regions[choice].y + regions[choice].height - traverse_radius, traverse_y))
|
|
|
|
tablist = nil
|
|
|
|
|
2019-08-06 04:29:03 +02:00
|
|
|
if ctrl and draft_mode then
|
|
|
|
local lu = c.machi_lu
|
|
|
|
local rd = c.machi_rd
|
|
|
|
|
|
|
|
if shift then
|
|
|
|
lu = choice
|
|
|
|
if regions[rd].x + regions[rd].width <= regions[lu].x or
|
|
|
|
regions[rd].y + regions[rd].height <= regions[lu].y
|
|
|
|
then
|
2019-08-20 05:26:27 +02:00
|
|
|
rd = nil
|
2019-08-06 04:29:03 +02:00
|
|
|
end
|
|
|
|
else
|
|
|
|
rd = choice
|
|
|
|
if regions[rd].x + regions[rd].width <= regions[lu].x or
|
|
|
|
regions[rd].y + regions[rd].height <= regions[lu].y
|
|
|
|
then
|
2019-08-20 05:26:27 +02:00
|
|
|
lu = nil
|
2019-08-06 04:29:03 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-08-20 05:26:27 +02:00
|
|
|
if lu ~= nil and rd ~= nil then
|
|
|
|
machi.layout.set_geometry(c, regions[lu], regions[rd], 0, c.border_width)
|
|
|
|
elseif lu ~= nil then
|
|
|
|
machi.layout.set_geometry(c, regions[lu], nil, 0, c.border_width)
|
|
|
|
elseif rd ~= nil then
|
|
|
|
c.x = min(c.x, regions[rd].x)
|
|
|
|
c.y = min(c.y, regions[rd].y)
|
|
|
|
machi.layout.set_geometry(c, nil, regions[rd], 0, c.border_width)
|
|
|
|
end
|
2019-08-06 04:29:03 +02:00
|
|
|
c.machi_lu = lu
|
|
|
|
c.machi_rd = rd
|
|
|
|
|
|
|
|
c:emit_signal("request::activate", "mouse.move", {raise=false})
|
|
|
|
c:raise()
|
|
|
|
api.layout.arrange(screen)
|
|
|
|
elseif shift then
|
2019-08-01 15:54:18 +02:00
|
|
|
-- move the window
|
2019-08-01 03:00:38 +02:00
|
|
|
if draft_mode then
|
2019-08-01 15:54:18 +02:00
|
|
|
c.x = regions[choice].x
|
|
|
|
c.y = regions[choice].y
|
2019-08-01 03:00:38 +02:00
|
|
|
else
|
|
|
|
machi.layout.set_geometry(c, regions[choice], regions[choice], 0, c.border_width)
|
|
|
|
c.machi_region = choice
|
|
|
|
end
|
2019-07-16 04:00:33 +02:00
|
|
|
c:emit_signal("request::activate", "mouse.move", {raise=false})
|
|
|
|
c:raise()
|
2019-07-07 19:05:42 +02:00
|
|
|
api.layout.arrange(screen)
|
2019-08-01 03:00:38 +02:00
|
|
|
|
|
|
|
tablist = nil
|
|
|
|
else
|
|
|
|
-- move the focus
|
|
|
|
ensure_tablist()
|
|
|
|
if #tablist > 0 and tablist[1] ~= c then
|
|
|
|
c = tablist[1]
|
|
|
|
api.client.focus = c
|
|
|
|
end
|
2019-07-07 19:05:42 +02:00
|
|
|
end
|
2019-07-06 18:22:19 +02:00
|
|
|
|
|
|
|
infobox.bgimage = draw_info
|
|
|
|
end
|
2019-07-06 18:23:58 +02:00
|
|
|
elseif key == "Escape" or key == "Return" then
|
2019-07-06 17:35:12 +02:00
|
|
|
infobox.visible = false
|
2019-07-25 00:11:44 +02:00
|
|
|
api.awful.keygrabber.stop(kg)
|
2019-07-07 19:30:05 +02:00
|
|
|
else
|
|
|
|
print("Unhandled key " .. key)
|
2019-07-06 17:35:12 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
return {
|
|
|
|
start = start,
|
|
|
|
}
|