def apply(self, qtile: Qtile) -> None:
        """
        Rearrange the windows in the specified Qtile object according to this
        QtileState.
        """
        for group, layout, label in self.groups:
            try:
                qtile.groups_map[group].layout = layout
                qtile.groups_map[group].label = label
            except KeyError:
                qtile.add_group(group, layout, label=label)

        for screen, group in self.screens.items():
            try:
                group = qtile.groups_map[group]
                qtile.screens[screen].set_group(group)
            except (KeyError, IndexError):
                pass  # group or screen missing

        for group in qtile.groups:
            if isinstance(group, ScratchPad) and group.name in self.scratchpads:
                orphans = group.restore_state(self.scratchpads.pop(group.name), self.restart)
                self.orphans.extend(orphans)
        for sp_state in self.scratchpads.values():
            for _, wid, _ in sp_state:
                self.orphans.append(wid)
        if self.orphans:
            if self.restart:
                hook.subscribe.client_new(self.handle_orphan_dropdowns)
            else:
                for wid in self.orphans:
                    win = qtile.windows_map[wid]
                    if isinstance(win, Window):
                        win.group = qtile.current_group

        qtile.focus_screen(self.current_screen)

        Rearrange the windows in the specified Qtile object according to this
        QtileState.
        
libqtile/core/state.py