Skip to content

Instantly share code, notes, and snippets.

@Hammer2900
Created December 26, 2025 14:53
Show Gist options
  • Select an option

  • Save Hammer2900/0a55555ceff9d60e9368bf2482347e87 to your computer and use it in GitHub Desktop.

Select an option

Save Hammer2900/0a55555ceff9d60e9368bf2482347e87 to your computer and use it in GitHub Desktop.
Smart Hot Corners (Global Back / Alt-Tab Teleport)
-- ===================================================================
-- LEFT HOT CORNER (Smart Client Menu)
-- ===================================================================
-- 1. Variable to track the menu instance (to check visibility later)
local client_menu_instance = nil
-- 2. Timer to prevent "debouncing" (accidental multiple triggers)
local hot_corner_timer = gears.timer {
timeout = 0.5,
autostart = false,
single_shot = true
}
-- 3. Function to show the sorted menu
local function show_sorted_client_menu()
-- If menu exists and is visible, do nothing
if client_menu_instance and client_menu_instance.wibox.visible then
return
end
local clients = client.get()
-- Sorting Priority: Lower number = Higher in the list
local priority = {
["google-chrome"] = 1,
["org.mozilla.firefox"] = 2,
["jetbrains-pycharm-ce"] = 3,
["sublime_text"] = 4,
["kitty"] = 5
}
table.sort(clients, function(a, b)
local pa = priority[(a.class or ""):lower()] or 999
local pb = priority[(b.class or ""):lower()] or 999
if pa == pb then
return (a.name or "") < (b.name or "")
end
return pa < pb
end)
local items = {}
for _, c in ipairs(clients) do
table.insert(items, {
string.format("%s — %s", c.class or "?", c.name or "—"),
function()
c:jump_to()
end,
c.icon
})
end
-- Create and show the menu
-- Note: 'theme_menu_w1' should be defined elsewhere in your config or replaced with {}
client_menu_instance = awful.menu({items = items, theme = theme_menu_w1 or { width = 400 }})
client_menu_instance:show()
-- === THE MAGIC PART ===
-- Automatically close the menu when the mouse leaves the menu area
client_menu_instance.wibox:connect_signal("mouse::leave", function()
if client_menu_instance then
client_menu_instance:hide()
end
end)
end
-- 4. Function to create the Left Hot Corner
local function create_smart_hot_corner(s)
-- Avoid duplicate creation on config reload
if s.my_hot_corner then return end
local hot_corner = wibox({
screen = s,
x = s.geometry.x, -- Left edge (0)
y = s.geometry.y, -- Top edge (0)
width = 5, -- Active zone width (pixels)
height = 5, -- Active zone height
bg = "#00000000", -- Transparent
ontop = true,
visible = true,
type = "dock"
})
hot_corner:connect_signal("mouse::enter", function()
-- Trigger only if timer is not running AND menu is not already open
if not hot_corner_timer.started and
(not client_menu_instance or not client_menu_instance.wibox.visible) then
show_sorted_client_menu()
hot_corner_timer:start() -- Start cooldown timer
end
end)
-- Save reference to the screen object
s.my_hot_corner = hot_corner
end
-- 5. Activate on all screens
awful.screen.connect_for_each_screen(function(s)
create_smart_hot_corner(s)
end)
local function show_sorted_client_menu()
local clients = client.get()
-- Sort priority (lower number = higher in the list)
local priority = {
["google-chrome"] = 1,
["org.mozilla.firefox"] = 2,
["jetbrains-pycharm-ce"] = 3,
["sublime_text"] = 4,
["kitty"] = 5
}
table.sort(clients, function(a, b)
-- Use :lower() to match "Google-chrome" and "google-chrome"
local pa = priority[(a.class or ""):lower()] or 999
local pb = priority[(b.class or ""):lower()] or 999
-- If priorities are equal, sort by name
if pa == pb then
return (a.name or "") < (b.name or "")
end
return pa < pb
end)
local items = {}
for _, c in ipairs(clients) do
table.insert(items, {
string.format("%s — %s", c.class or "?", c.name or "—"),
function() c:jump_to() end,
c.icon
})
end
-- Show the menu
awful.menu({items = items, theme = { width = 400 }}):show()
end
-- Subscribe to the global keyboard layout change signal
awesome.connect_signal("xkb::group_changed", function()
-- Get current layout index (0 = US, 1 = Secondary)
local layout_index = awesome.xkb_get_layout_group()
-- 1. Icon logic (optional)
local icon = "🇺🇸"
if layout_index == 1 then
icon = "🇺🇦"
end
-- (Update icon widget code here if needed)
-- 2. Bar Color Logic
local target_bg = beautiful.bg_normal or "#222222" -- Default color
if layout_index == 1 then
target_bg = "#550000" -- Dark red warning color
end
-- Apply the background color to all wiboxes on all screens
for s in screen do
if s.mywibox then
s.mywibox.bg = target_bg
end
end
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment