Error trying to set up dual monitors in Qtile

I recently switched from KDE to Qtile, and I’m having some issues trying to set up multiple displays. I want to have groups 1-5 on one monitor, and 6-9 on the other.

Following this example from the FAQ:

def go_to_group(name: str) -> Callable:
    def _inner(qtile: Qtile) -> None:
        if len(qtile.screens) == 1:
            qtile.groups_map[name].cmd_toscreen()
            return

        if name in '123':
            qtile.focus_screen(0)
            qtile.groups_map[name].cmd_toscreen()
        else:
            qtile.focus_screen(1)
            qtile.groups_map[name].cmd_toscreen()

    return _inner

for i in groups:
    keys.append(Key([mod], i.name, lazy.function(go_to_group(i.name))))

I get an error when I check my config.

error: config failed to import, NameError: name 'Qtile' is not defined
Stub: in file /tmp/tmp42a57p7n/config.pyi:1
MypyFile:1(
  /tmp/tmp42a57p7n/config.pyi)
Runtime:
MISSING

Found 1 error (checked 1 module)

Obviously I’m missing an import for ‘Qtile’ here, but I don’t know where to import it from.

Hi @beavis ,
Have a look at the config of Derek Taylor alias DT

1 Like

Well, I couldn’t get the example from the FAQ to work, but I was able to create my own solution. I’m leaving it here in case someone finds it useful in the future.

It’s just a small modification of the default config.

groups = [
    Group("1", spawn="alacritty"),
    Group("2"),
    Group("3"),
    Group("4"),
    Group("5"),
    Group("6", matches=[Match(wm_class=["firefox"])], layout="max"),
    Group("7"),
    Group("8"),
    Group("9"),
]

# Indicates which group should appear on which screen.
# Groups 1-5 on screen 0, and 6-9 on screen 1.
s = [0, 0, 0, 0, 0, 1, 1, 1, 1]

# Iterates over the groups and sets up keys to move focus to groups/screens.
for index, i in enumerate(groups):
    keys.extend(
        [
            # mod1 + letter of group = switch to group/screen
            Key(
                [mod],
                i.name,
                lazy.group[i.name].toscreen(s[index]),
                lazy.to_screen(s[index]),
                desc="Switch to group {}".format(i.name),
            ),
            # mod1 + shift + letter of group = switch to & move focused window to group
            Key(
                [mod, "shift"],
                i.name,
                lazy.window.togroup(i.name, switch_group=True),
                desc="Switch to & move focused window to group {}".format(i.name),
            ),
            # Or, use below if you prefer not to switch to that group.
            # # mod1 + shift + letter of group = move focused window to group
            # Key([mod, "shift"], i.name, lazy.window.togroup(i.name),
            #     desc="move focused window to group {}".format(i.name)),
        ]
    )
1 Like

Thanks for the suggestion.

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.