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 to cycle through windows using
Alt+Tab, switch to workspaces 1-4, move the focused window to workspaces 1-4, and make windows draggable, you can add the following Lua code to your AwesomeWM configuration file (rc.lua):-- Import necessary modules local awful = require("awful") local gears = require("gears") -- Define modkey local modkey = "Mod1" -- Alt key -- Cycle through windows with Alt+Tab awful.keygrabber { start_callback = function() -- Start cycling through clients local clients = awful.client.visible() if #clients > 1 then local current_index = gears.table.hasitem(clients, client.focus) local next_index = (current_index % #clients) + 1 clients[next_index]:emit_signal("request::activate", "key.ungrab", {raise = true}) end end, stop_callback = function() -- Stop cycling end, export_keybindings = true, stop_event = "release", stop_key = "Tab", keybindings = { {{modkey}, "Tab", function() end}, } } -- Hotkeys to switch to workspaces 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"} ), }) end -- Hotkeys to move focused window to workspaces 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"} ), }) end -- Make windows draggable client.connect_signal("manage", function (c) c:connect_signal("request::activate", function() c:emit_signal("request::activate", "mouse_click", {raise = true}) end) c:connect_signal("mouse::press", function(c, _, _, button) if button == 1 then c:emit_signal("request::activate", "mouse_click", {raise = true}) awful.mouse.client.move(c) end end) end)Explanation:
-
Cycle Through Windows with
Alt+Tab: Theawful.keygrabberis used to capture theAlt+Tabkey combination. WhenAlt+Tabis pressed, it cycles through the visible clients (windows) on the current screen. Releasing theTabkey stops the cycling. -
Switch to Workspaces 1-4: The
forloop binds theAltkey combined with the number keys 1 to 4 to switch to the corresponding workspaces (tags). The"#" .. i + 9expression maps the number keys to their keycodes. -
Move Focused Window to Workspaces 1-4: Another
forloop binds theAlt+Shiftkey combination with the number keys 1 to 4 to move the currently focused window to the corresponding workspace. -
Make Windows Draggable: The
client.connect_signalfunction connects to themanagesignal, which is emitted when a new client appears. It then connects to themouse::presssignal to allow dragging windows by holding the left mouse button.
Note: Ensure that the
awfulandgearsmodules are required at the beginning of yourrc.luafile. Also, make sure that themodkeyis set to"Mod1"to correspond to theAltkey. Adjust the keybindings as needed to fit your preferences.After adding this code to your
rc.luafile, reload AwesomeWM to apply the changes. -
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.