switcher fix

This commit is contained in:
Xinhao Yuan 2019-07-06 12:22:19 -04:00
parent e801a3f556
commit 7588d3e816
2 changed files with 100 additions and 25 deletions

View File

@ -383,6 +383,7 @@ local function create(data)
local screen = api.screen.focused() local screen = api.screen.focused()
local kg local kg
local infobox = api.wibox({ local infobox = api.wibox({
screen = screen,
x = screen.workarea.x, x = screen.workarea.x,
y = screen.workarea.y, y = screen.workarea.y,
width = screen.workarea.width, width = screen.workarea.width,

View File

@ -13,15 +13,20 @@ local api = {
local label_font_family = api.beautiful.get_font( local label_font_family = api.beautiful.get_font(
api.beautiful.mono_font or api.beautiful.font):get_family() api.beautiful.mono_font or api.beautiful.font):get_family()
local label_size = api.dpi(30) local label_size = api.dpi(30)
local border_color = "#ffffffc0" local border_color = "#ffffff80"
local fill_color = "#00000080" local fill_color = "#00000040"
-- for comparing floats
local threshold = 0.1
local function start(c) local function start(c)
local screen = c.screen local screen = c.screen
local layout = api.layout.get(screen) local layout = api.layout.get(screen)
if c.floating or layout.get_regions == nil then return end if c.floating or layout.get_regions == nil then return end
local regions = layout.get_regions()
local infobox = api.wibox({ local infobox = api.wibox({
screen = screen,
x = screen.workarea.x, x = screen.workarea.x,
y = screen.workarea.y, y = screen.workarea.y,
width = screen.workarea.width, width = screen.workarea.width,
@ -32,14 +37,17 @@ local function start(c)
}) })
infobox.visible = true infobox.visible = true
local traverse_x = c.x + c.width / 2
local traverse_y = c.y + c.height / 2
local function draw_info(context, cr, width, height) local function draw_info(context, cr, width, height)
cr:set_source_rgba(0, 0, 0, 0) cr:set_source_rgba(0, 0, 0, 0)
cr:rectangle(0, 0, width, height) cr:rectangle(0, 0, width, height)
cr:fill() cr:fill()
local msg, ext local msg, ext
local regions = layout.get_regions()
for i, a in ipairs(regions) do for i, a in ipairs(regions) do
if i ~= c.machi_region then
cr:rectangle(a.x, a.y, a.width, a.height) cr:rectangle(a.x, a.y, a.width, a.height)
cr:clip() cr:clip()
cr:set_source(api.gears.color(fill_color)) cr:set_source(api.gears.color(fill_color))
@ -60,10 +68,15 @@ local function start(c)
cr:text_path(msg) cr:text_path(msg)
cr:set_source_rgba(1, 1, 1, 1) cr:set_source_rgba(1, 1, 1, 1)
cr:fill() cr:fill()
end end
end end
-- -- show the traverse point
-- cr:rectangle(traverse_x - api.dpi(5), traverse_y - api.dpi(5), api.dpi(10), api.dpi(10))
-- cr:set_source_rgba(1, 1, 1, 1)
-- cr:fill()
end
infobox.bgimage = draw_info infobox.bgimage = draw_info
local kg local kg
@ -71,9 +84,70 @@ local function start(c)
function (mod, key, event) function (mod, key, event)
if event == "release" then return end if event == "release" then return end
if key == "Escape" then if key == "Up" or key == "Down" or key == "Left" or key == "Right" then
local choice = nil
local choice_value
local choice_x
local choice_y
for i, a in ipairs(regions) do
local v
local x = traverse_x
local y = traverse_y
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
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
y = a.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
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
x = a.x
else
v = -1
end
end
if (v > threshold) and (choice_value == nil or choice_value > v) then
choice = i
choice_value = v
choice_x = x
choice_y = y
end
end
if choice ~= nil and choice_value > threshold then
c.machi_region = choice
api.layout.arrange(screen)
traverse_x = choice_x
traverse_y = choice_y
infobox.bgimage = draw_info
end
elseif key == "Escape" then
infobox.visible = false infobox.visible = false
kg.stop() keygrabber.stop(kg)
end end
end end
) )