From e801a3f55671aca3b884fe5e7da1d83446261907 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Sat, 6 Jul 2019 11:35:12 -0400 Subject: [PATCH] switcher --- switcher.lua | 84 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 switcher.lua diff --git a/switcher.lua b/switcher.lua new file mode 100644 index 0000000..1f593ee --- /dev/null +++ b/switcher.lua @@ -0,0 +1,84 @@ +local api = { + beautiful = require("beautiful"), + wibox = require("wibox"), + awful = require("awful"), + screen = require("awful.screen"), + layout = require("awful.layout"), + keygrabber = require("awful.keygrabber"), + naughty = require("naughty"), + gears = require("gears"), + dpi = require("beautiful.xresources").apply_dpi, +} + +local label_font_family = api.beautiful.get_font( + api.beautiful.mono_font or api.beautiful.font):get_family() +local label_size = api.dpi(30) +local border_color = "#ffffffc0" +local fill_color = "#00000080" + +local function start(c) + local screen = c.screen + local layout = api.layout.get(screen) + if c.floating or layout.get_regions == nil then return end + + local infobox = api.wibox({ + x = screen.workarea.x, + y = screen.workarea.y, + width = screen.workarea.width, + height = screen.workarea.height, + bg = "#ffffff00", + opacity = 1, + ontop = true + }) + infobox.visible = true + + local function draw_info(context, cr, width, height) + cr:set_source_rgba(0, 0, 0, 0) + cr:rectangle(0, 0, width, height) + cr:fill() + + local msg, ext + local regions = layout.get_regions() + for i, a in ipairs(regions) do + cr:rectangle(a.x, a.y, a.width, a.height) + cr:clip() + cr:set_source(api.gears.color(fill_color)) + cr:rectangle(a.x, a.y, a.width, a.height) + cr:fill() + cr:set_source(api.gears.color(border_color)) + cr:rectangle(a.x, a.y, a.width, a.height) + cr:set_line_width(10.0) + cr:stroke() + cr:reset_clip() + + cr:select_font_face(label_font_family, "normal", "normal") + cr:set_font_size(label_size) + cr:set_font_face(cr:get_font_face()) + msg = tostring(i) + ext = cr:text_extents(msg) + cr:move_to(a.x + a.width / 2 - ext.width / 2 - ext.x_bearing, a.y + a.height / 2 - ext.height / 2 - ext.y_bearing) + cr:text_path(msg) + cr:set_source_rgba(1, 1, 1, 1) + cr:fill() + + end + end + + infobox.bgimage = draw_info + + local kg + kg = keygrabber.run( + function (mod, key, event) + if event == "release" then return end + + if key == "Escape" then + infobox.visible = false + kg.stop() + end + end + ) +end + +return { + start = start, +}