awesomewm lua code to cycle windows and activate the selection with hotkey alt+tab (like…
- User
awesomewm lua code to cycle windows and activate the selection with hotkey alt+tab (like mac), hotkey to go to workspace 1-4, and hotkeys to move focused window to workspace 1-4. include making the windows themselves draggable
- Assistant
To configure AwesomeWM with the desired functionalities—cycling through windows using
Alt+Tab(similar to macOS), switching to workspaces 1-4, moving the focused window to workspaces 1-4, and making windows draggable—you can modify yourrc.luaconfiguration file as follows:1. Cycle Windows with
Alt+Tab:To implement an
Alt+Tabbehavior that cycles through all open windows, you can use theawful.keygrabbermodule. This approach allows for a more comprehensive window cycling experience. Here's how you can set it up:local awful = require("awful") local gears = require("gears") -- Define the keygrabber for Alt+Tab functionality local alt_tab_keygrabber = nil -- Function to start the keygrabber local function start_alt_tab() if alt_tab_keygrabber then return end alt_tab_keygrabber = awful.keygrabber { keybindings = { {{'Mod1'}, 'Tab', function() awful.client.focus.byidx(1) if client.focus then client.focus:raise() end end}, {{'Mod1', 'Shift'}, 'Tab', function() awful.client.focus.byidx(-1) if client.focus then client.focus:raise() end end}, }, stop_key = 'Mod1', stop_event = 'release', start_callback = function() -- Disable client history tracking to prevent interference awful.client.focus.history.disable_tracking() end, stop_callback = function() -- Re-enable client history tracking awful.client.focus.history.enable_tracking() alt_tab_keygrabber = nil end, export_keybindings = true, } alt_tab_keygrabber:start() end -- Bind Alt+Tab to start the keygrabber awful.keyboard.append_global_keybindings({ awful.key({ 'Mod1' }, 'Tab', start_alt_tab, {description = 'cycle through windows', group = 'client'}), })In this setup:
- Pressing
Alt+Tabcycles forward through the windows. - Pressing
Alt+Shift+Tabcycles backward. - Releasing the
Altkey stops the cycling and focuses the selected window.
2. Switch to Workspaces 1-4:
To switch to specific workspaces (tags) using keybindings, you can define the following:
-- Bind keys to switch to workspace 1-4 for i = 1, 4 do awful.keyboard.append_global_keybindings({ awful.key({ modkey }, "#" .. i + 9, function () local screen = awful.screen.focused() local tag = screen.tags[i] if tag then tag:view_only() end end, {description = "view tag #"..i, group = "tag"}), }) endIn this configuration:
modkeyis typically set toMod4(the Super/Windows key).- Pressing
Mod4+1switches to workspace 1,Mod4+2to workspace 2, and so on up to workspace 4.
3. Move Focused Window to Workspaces 1-4:
To move the currently focused window to a specific workspace, use the following keybindings:
-- Bind keys to move focused window to workspace 1-4 for i = 1, 4 do awful.keyboard.append_global_keybindings({ awful.key({ modkey, "Shift" }, "#" .. i + 9, function () if client.focus then local tag = client.focus.screen.tags[i] if tag then client.focus:move_to_tag(tag) end end end, {description = "move focused client to tag #"..i, group = "tag"}), }) endHere:
- Pressing
Mod4+Shift+1moves the focused window to workspace 1,Mod4+Shift+2to workspace 2, and so on up to workspace 4.
4. Make Windows Draggable:
To enable dragging of windows with the mouse, you can set up mouse bindings as follows:
-- Enable dragging of windows client.connect_signal("request::default_mousebindings", function() awful.mouse.append_client_mousebindings({ awful.button({ modkey }, 1, function(c) c:activate { context = "mouse_click", action = "mouse_move" } end), awful.button({ modkey }, 3, function(c) c:activate { context = "mouse_click", action = "mouse_resize" } end), }) end)In this setup:
- Holding
Mod4and left-clicking on a window allows you to drag it. - Holding
Mod4and right-clicking on a window allows you to resize it.
Note: Ensure that you have the
gearsandawfulmodules required at the beginning of yourrc.luafile:local gears = require("gears") local awful = require("awful")By incorporating these configurations into your
rc.luafile, you can achieve the desired window management behaviors in AwesomeWM. - Pressing
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.