Skip to content
TheChatArchiveThe Chat Archive
gpt-4o-search-preview-high· OpenAIHugging Face LMArena Search Arena 24K

awesomewm lua code to cycle windows and activate the selection with hotkey alt+tab (like…

From a Chatbot Arena battleThe same person sent this prompt to two anonymous models at once. Compare it with gpt-4o-search-preview-high-loc’s answer.
  1. 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

  2. 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 your rc.lua configuration file as follows:

    1. Cycle Windows with Alt+Tab:

    To implement an Alt+Tab behavior that cycles through all open windows, you can use the awful.keygrabber module. 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+Tab cycles forward through the windows.
    • Pressing Alt+Shift+Tab cycles backward.
    • Releasing the Alt key 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"}),
        })
    end
    

    In this configuration:

    • modkey is typically set to Mod4 (the Super/Windows key).
    • Pressing Mod4+1 switches to workspace 1, Mod4+2 to 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"}),
        })
    end
    

    Here:

    • Pressing Mod4+Shift+1 moves the focused window to workspace 1, Mod4+Shift+2 to 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 Mod4 and left-clicking on a window allows you to drag it.
    • Holding Mod4 and right-clicking on a window allows you to resize it.

    Note: Ensure that you have the gears and awful modules required at the beginning of your rc.lua file:

    local gears = require("gears")
    local awful = require("awful")
    

    By incorporating these configurations into your rc.lua file, you can achieve the desired window management behaviors in AwesomeWM.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.