def run_qtile(): try: init_log(logging.INFO, log_path=None) q = QtileManager(config_class(), self.display, self.sockfile) q.loop() except Exception: wpipe.send(traceback.format_exc())
def patched_lifecycle(monkeypatch): init_log(logging.WARNING, log_path=None, log_color=False) monkeypatch.setattr("libqtile.core.lifecycle.sys.executable", "python") monkeypatch.setattr("libqtile.core.lifecycle.sys.argv", ["arg1", "arg2"]) monkeypatch.setattr("libqtile.core.lifecycle.atexit.register", no_op) monkeypatch.setattr("libqtile.core.lifecycle.os.execv", fake_os_execv) yield LifeCycle()
def make_qtile(options): log_level = getattr(logging, options.log_level) init_log(log_level=log_level, log_color=stdout.isatty()) kore = libqtile.backend.get_core(options.backend) if not path.isfile(options.configfile): try: makedirs(path.dirname(options.configfile), exist_ok=True) from shutil import copyfile default_config_path = path.join(path.dirname(__file__), "..", "resources", "default_config.py") copyfile(default_config_path, options.configfile) logger.info('Copied default_config.py to %s', options.configfile) except Exception as e: logger.exception('Failed to copy default_config.py to %s: (%s)', options.configfile, e) config = confreader.Config(options.configfile, kore=kore) # XXX: the import is here because we need to call init_log # before start importing stuff from libqtile.core import session_manager return session_manager.SessionManager( kore, config, fname=options.socket, no_spawn=options.no_spawn, state=options.state, )
def run_qtile(): try: kore = xcore.XCore(display_name=self.display) init_log(self.log_level, log_path=None, log_color=False) q = SessionManager(kore, config_class(), fname=self.sockfile) q.loop() except Exception: wpipe.send(traceback.format_exc())
def create_manager(self, config_class): """Create a Qtile manager instance in this thread This should only be used when it is known that the manager will throw an error and the returned manager should not be started, otherwise this will likely block the thread. """ init_log(logging.INFO, log_path=None) return QtileManager(config_class(), self.display, self.sockfile)
def run_qtile(): llvl = logging.DEBUG if pytest.config.getoption("--debuglog") else logging.INFO kore = xcore.XCore() try: init_log(llvl, log_path=None, log_color=False) q = QtileManager(kore, config_class(), self.display, self.sockfile) q.loop() except Exception: wpipe.send(traceback.format_exc())
def runQtile(): try: init_log(logging.INFO, log_path=self.logfile, log_color=False) q = Qtile(config, self.display, self.sockfile) q.loop() except Exception: wpipe.send(traceback.format_exc()) with open(self.logfile, 'a') as f: f.write("--------------------- >> begin qtile traceback << --------------------") f.write(traceback.format_exc()) f.write("-------------------- >> begin qtile traceback << ---------------------")
def run_qtile(): try: kore = Core(display_name=self.display) init_log(self.log_level, log_path=None, log_color=False) Qtile( kore, config_class(), socket_path=self.sockfile, no_spawn=no_spawn, ).loop() except Exception: wpipe.send(traceback.format_exc())
def create_manager(self, config_class): """Create a Qtile manager instance in this thread This should only be used when it is known that the manager will throw an error and the returned manager should not be started, otherwise this will likely block the thread. """ llvl = logging.DEBUG if pytest.config.getoption( "--debuglog") else logging.INFO init_log(llvl, log_path=None, log_color=False) kore = xcore.XCore() return QtileManager(kore, config_class(), self.display, self.sockfile)
def main(): parent_parser = argparse.ArgumentParser(add_help=False) parent_parser.add_argument( "-l", "--log-level", default="WARNING", dest="log_level", type=str.upper, choices=("DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL"), help="Set qtile log level", ) main_parser = argparse.ArgumentParser( prog="qtile", description="A full-featured, pure-Python tiling window manager.", ) main_parser.add_argument( "-v", "--version", action="version", version=VERSION, ) subparsers = main_parser.add_subparsers() start.add_subcommand(subparsers, [parent_parser]) shell.add_subcommand(subparsers, [parent_parser]) top.add_subcommand(subparsers, [parent_parser]) run_cmd.add_subcommand(subparsers, [parent_parser]) cmd_obj.add_subcommand(subparsers, [parent_parser]) check.add_subcommand(subparsers, [parent_parser]) migrate.add_subcommand(subparsers, [parent_parser]) # `qtile help` should print help def print_help(options): main_parser.print_help() help_ = subparsers.add_parser("help", help="Print help information and exit") help_.set_defaults(func=print_help) options = main_parser.parse_args() try: log_level = getattr(logging, options.log_level) init_log(log_level=log_level, log_color=sys.stdout.isatty()) options.func(options) except AttributeError: main_parser.print_usage() print("") print("Did you mean:") print(" ".join(sys.argv + ["start"])) sys.exit(1)
def runQtile(): try: init_log(logging.INFO, log_path=self.logfile, log_color=False) q = Qtile(config, self.display, self.sockfile) q.loop() except Exception: wpipe.send(traceback.format_exc()) with open(self.logfile, 'a') as f: f.write( "--------------------- >> begin qtile traceback << --------------------" ) f.write(traceback.format_exc()) f.write( "-------------------- >> begin qtile traceback << ---------------------" )
def create_manager(self, config_class): """Create a Qtile manager instance in this thread This should only be used when it is known that the manager will throw an error and the returned manager should not be started, otherwise this will likely block the thread. """ init_log(self.log_level, log_path=None, log_color=False) kore = self.backend.create() config = config_class() for attr in dir(default_config): if not hasattr(config, attr): setattr(config, attr, getattr(default_config, attr)) return Qtile(kore, config, socket_path=self.sockfile)
def run_qtile(): try: os.environ.pop("DISPLAY", None) os.environ.pop("WAYLAND_DISPLAY", None) kore = self.backend.create() os.environ.update(self.backend.env) init_log(self.log_level, log_path=None, log_color=False) Qtile( kore, config_class(), socket_path=self.sockfile, no_spawn=no_spawn, ).loop() except Exception: wpipe.send(traceback.format_exc())
def create_manager(self, config_class): """Create a Qtile manager instance in this thread This should only be used when it is known that the manager will throw an error and the returned manager should not be started, otherwise this will likely block the thread. """ llvl = logging.DEBUG if pytest.config.getoption("--debuglog") else logging.INFO init_log(llvl, log_path=None, log_color=False) kore = xcore.XCore() config = config_class() for attr in dir(default_config): if not hasattr(config, attr): setattr(config, attr, getattr(default_config, attr)) return QtileManager(kore, config, self.display, self.sockfile)
def log_extension_output(monkeypatch): init_log(logging.WARNING, log_path=None, log_color=False) def fake_popen(cmd, *args, **kwargs): class PopenObj: def communicate(self, value_in, *args): if value_in.startswith(b"missing"): return [b"something_else", None] else: return [value_in, None] return PopenObj() monkeypatch.setattr("libqtile.extension.base.Popen", fake_popen) yield
def main(): # backward compat hack: `qtile` with no args (or non-subcommand args) # should default to `qtile start`. it seems impolite for commands to do # nothing when run with no args, so let's warn about this being deprecated. if len(sys.argv) == 1: print("please move to `qtile start` as your qtile invocation, " "instead of just `qtile`; this default will be removed Soon(TM)") sys.argv.insert(1, "start") parser = argparse.ArgumentParser( prog='qtile', description='A full-featured, pure-Python tiling window manager.', ) parser.add_argument( '--version', action='version', version=VERSION, ) parser.add_argument('-l', '--log-level', default='WARNING', dest='log_level', type=str.upper, choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), help='Set qtile log level') subparsers = parser.add_subparsers() start.add_subcommand(subparsers) shell.add_subcommand(subparsers) top.add_subcommand(subparsers) run_cmd.add_subcommand(subparsers) cmd_obj.add_subcommand(subparsers) check.add_subcommand(subparsers) # `qtile help` should print help def print_help(options): parser.print_help() help_ = subparsers.add_parser("help", help="Print help information and exit") help_.set_defaults(func=print_help) options = parser.parse_args() log_level = getattr(logging, options.log_level) init_log(log_level=log_level, log_color=sys.stdout.isatty()) options.func(options)
def run_qtile(): try: os.environ.pop("DISPLAY", None) os.environ.pop("WAYLAND_DISPLAY", None) kore = self.backend.create() os.environ.update(self.backend.env) logger = init_log(self.log_level, log_path=None, log_color=False) if hasattr(self, "log_queue"): logger.addHandler(logging.handlers.QueueHandler(self.log_queue)) Qtile( kore, config_class(), socket_path=self.sockfile, no_spawn=no_spawn, state=state, ).loop() except Exception: wpipe.send(traceback.format_exc())
def make_qtile(): from argparse import ArgumentParser parser = ArgumentParser( description='A full-featured, pure-Python tiling window manager.', prog='qtile', ) parser.add_argument( '--version', action='version', version=VERSION, ) parser.add_argument( "-c", "--config", action="store", default=None, dest="configfile", help='Use specified configuration file,' ' "default" will load the system default config.' ) parser.add_argument( "-s", "--socket", action="store", default=None, dest="socket", help='Path to Qtile comms socket.' ) parser.add_argument( "-n", "--no-spawn", action="store_true", default=False, dest="no_spawn", help='Avoid spawning apps. (Used for restart)' ) parser.add_argument( '-l', '--log-level', default='WARNING', dest='log_level', choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), help='Set qtile log level' ) parser.add_argument( '--with-state', default=None, dest='state', help='Pickled QtileState object (typically used only internally)', ) options = parser.parse_args() log_level = getattr(logging, options.log_level) init_log(log_level=log_level) try: config = confreader.File(options.configfile, is_restart=options.no_spawn) except Exception as e: logger.exception('Error while reading config file (%s)', e) raise # XXX: the import is here becouse we need to call init_log # before start importing stuff from libqtile import manager try: return manager.Qtile( config, fname=options.socket, no_spawn=options.no_spawn, state=options.state, ) except: logger.exception('Qtile crashed during startup') raise
def make_qtile(): from argparse import ArgumentParser parser = ArgumentParser( description='A full-featured, pure-Python tiling window manager.', prog='qtile', ) parser.add_argument( '--version', action='version', version=VERSION, ) parser.add_argument("-c", "--config", action="store", default=None, dest="configfile", help='Use specified configuration file,' ' "default" will load the system default config.') parser.add_argument("-s", "--socket", action="store", default=None, dest="socket", help='Path to Qtile comms socket.') parser.add_argument("-n", "--no-spawn", action="store_true", default=False, dest="no_spawn", help='Avoid spawning apps. (Used for restart)') parser.add_argument('-l', '--log-level', default='WARNING', dest='log_level', choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), help='Set qtile log level') parser.add_argument( '--with-state', default=None, dest='state', help='Pickled QtileState object (typically used only internally)', ) options = parser.parse_args() log_level = getattr(logging, options.log_level) init_log(log_level=log_level) try: config = confreader.File(options.configfile, is_restart=options.no_spawn) except Exception as e: logger.exception('Error while reading config file (%s)', e) raise # XXX: the import is here becouse we need to call init_log # before start importing stuff from libqtile import manager try: return manager.Qtile( config, fname=options.socket, no_spawn=options.no_spawn, state=options.state, ) except: logger.exception('Qtile crashed during startup') raise
def make_qtile(): from argparse import ArgumentParser parser = ArgumentParser( description='A full-featured, pure-Python tiling window manager.', prog='qtile', ) parser.add_argument( '--version', action='version', version=VERSION, ) parser.add_argument( "-c", "--config", action="store", default=path.expanduser( path.join(getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile', 'config.py')), dest="configfile", help='Use the specified configuration file', ) parser.add_argument("-s", "--socket", action="store", default=None, dest="socket", help='Path of the Qtile IPC socket.') parser.add_argument("-n", "--no-spawn", action="store_true", default=False, dest="no_spawn", help='Avoid spawning apps. (Used for restart)') parser.add_argument('-l', '--log-level', default='WARNING', dest='log_level', choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), help='Set qtile log level') parser.add_argument( '--with-state', default=None, dest='state', help='Pickled QtileState object (typically used only internally)', ) options = parser.parse_args() log_level = getattr(logging, options.log_level) init_log(log_level=log_level) kore = xcore.XCore() try: if not path.isfile(options.configfile): try: makedirs(path.dirname(options.configfile), exist_ok=True) from shutil import copyfile default_config_path = path.join(path.dirname(__file__), "..", "resources", "default_config.py") copyfile(default_config_path, options.configfile) logger.info('Copied default_config.py to %s', options.configfile) except Exception as e: logger.exception( 'Failed to copy default_config.py to %s: (%s)', options.configfile, e) config = confreader.Config.from_file(options.configfile, kore=kore) except Exception as e: logger.exception('Error while reading config file (%s)', e) config = confreader.Config() from libqtile.widget import TextBox widgets = config.screens[0].bottom.widgets widgets.insert(0, TextBox('Config Err!')) # XXX: the import is here because we need to call init_log # before start importing stuff from libqtile.core import session_manager return session_manager.SessionManager( kore, config, fname=options.socket, no_spawn=options.no_spawn, state=options.state, )
def __init__(self, config, displayName=None, fname=None, no_spawn=False, log=None, state=None): gobject.threads_init() self.log = log or init_log() if hasattr(config, "log_level"): self.log.setLevel(config.log_level) self.no_spawn = no_spawn if not displayName: displayName = os.environ.get("DISPLAY") if not displayName: raise QtileError("No DISPLAY set.") if not fname: # Dots might appear in the host part of the display name # during remote X sessions. Let's strip the host part first. displayNum = displayName.partition(":")[2] if not "." in displayNum: displayName = displayName + ".0" fname = command.find_sockfile(displayName) self.conn = xcbq.Connection(displayName) self.config = config self.fname = fname hook.init(self) self.keyMap = {} self.windowMap = {} self.widgetMap = {} self.groupMap = {} self.groups = [] self.keyMap = {} # Find the modifier mask for the numlock key, if there is one: nc = self.conn.keysym_to_keycode(xcbq.keysyms["Num_Lock"]) self.numlockMask = xcbq.ModMasks[self.conn.get_modifier(nc)] self.validMask = ~(self.numlockMask | xcbq.ModMasks["lock"]) # Because we only do Xinerama multi-screening, # we can assume that the first # screen's root is _the_ root. self.root = self.conn.default_screen.root self.root.set_attribute( eventmask=( EventMask.StructureNotify | EventMask.SubstructureNotify | EventMask.SubstructureRedirect | EventMask.EnterWindow | EventMask.LeaveWindow ) ) self.root.set_property( '_NET_SUPPORTED', [self.conn.atoms[x] for x in xcbq.SUPPORTED_ATOMS] ) self.supporting_wm_check_window = self.conn.create_window(-1, -1, 1, 1) self.root.set_property( '_NET_SUPPORTING_WM_CHECK', self.supporting_wm_check_window.wid ) # TODO: maybe allow changing the name without external tools? self.supporting_wm_check_window.set_property('_NET_WM_NAME', "qtile") self.supporting_wm_check_window.set_property( '_NET_SUPPORTING_WM_CHECK', self.supporting_wm_check_window.wid ) if config.main: config.main(self) if self.config.groups: key_binder = None if hasattr(self.config, 'dgroups_key_binder'): key_binder = self.config.dgroups_key_binder DGroups(self, self.config.groups, key_binder) if hasattr(config, "widget_defaults") and config.widget_defaults: _Widget.global_defaults = config.widget_defaults else: _Widget.global_defaults = {} for i in self.groups: self.groupMap[i.name] = i self.currentScreen = None self.screens = [] self._process_screens() self.currentScreen = self.screens[0] self._drag = None self.ignoreEvents = set([ xcb.xproto.KeyReleaseEvent, xcb.xproto.ReparentNotifyEvent, xcb.xproto.CreateNotifyEvent, # DWM handles this to help "broken focusing windows". xcb.xproto.MapNotifyEvent, xcb.xproto.LeaveNotifyEvent, xcb.xproto.FocusOutEvent, xcb.xproto.FocusInEvent, xcb.xproto.NoExposureEvent ]) self.conn.flush() self.conn.xsync() self._xpoll() self.server = command._Server(self.fname, self, config) # Map and Grab keys for key in self.config.keys: self.mapKey(key) # It fixes problems with focus when clicking windows of some specific clients like xterm def noop(qtile): pass self.config.mouse += (Click([], "Button1", command.lazy.function(noop), focus="after"),) self.mouseMap = {} for i in self.config.mouse: if self.mouseMap.get(i.button_code) is None: self.mouseMap[i.button_code] = [] self.mouseMap[i.button_code].append(i) self.grabMouse() hook.fire("startup") self.scan() self.update_net_desktops() hook.subscribe.setgroup(self.update_net_desktops) if state: st = pickle.load(StringIO(state)) st.apply(self)
def __init__(self, config, displayName=None, fname=None, no_spawn=False, log=None, state=None): gobject.threads_init() self.log = log or init_log() if hasattr(config, "log_level"): self.log.setLevel(config.log_level) self.no_spawn = no_spawn if not displayName: displayName = os.environ.get("DISPLAY") if not displayName: raise QtileError("No DISPLAY set.") if not fname: # Dots might appear in the host part of the display name # during remote X sessions. Let's strip the host part first. displayNum = displayName.partition(":")[2] if not "." in displayNum: displayName = displayName + ".0" fname = command.find_sockfile(displayName) self.conn = xcbq.Connection(displayName) self.config = config self.fname = fname hook.init(self) self.keyMap = {} self.windowMap = {} self.widgetMap = {} self.groupMap = {} self.groups = [] self.keyMap = {} # Find the modifier mask for the numlock key, if there is one: nc = self.conn.keysym_to_keycode(xcbq.keysyms["Num_Lock"]) self.numlockMask = xcbq.ModMasks[self.conn.get_modifier(nc)] self.validMask = ~(self.numlockMask | xcbq.ModMasks["lock"]) # Because we only do Xinerama multi-screening, # we can assume that the first # screen's root is _the_ root. self.root = self.conn.default_screen.root self.root.set_attribute( eventmask=(EventMask.StructureNotify | EventMask.SubstructureNotify | EventMask.SubstructureRedirect | EventMask.EnterWindow | EventMask.LeaveWindow)) self.root.set_property( '_NET_SUPPORTED', [self.conn.atoms[x] for x in xcbq.SUPPORTED_ATOMS]) self.supporting_wm_check_window = self.conn.create_window(-1, -1, 1, 1) self.root.set_property('_NET_SUPPORTING_WM_CHECK', self.supporting_wm_check_window.wid) # TODO: maybe allow changing the name without external tools? self.supporting_wm_check_window.set_property('_NET_WM_NAME', "qtile") self.supporting_wm_check_window.set_property( '_NET_SUPPORTING_WM_CHECK', self.supporting_wm_check_window.wid) if config.main: config.main(self) if self.config.groups: key_binder = None if hasattr(self.config, 'dgroups_key_binder'): key_binder = self.config.dgroups_key_binder DGroups(self, self.config.groups, key_binder) if hasattr(config, "widget_defaults") and config.widget_defaults: _Widget.global_defaults = config.widget_defaults else: _Widget.global_defaults = {} for i in self.groups: self.groupMap[i.name] = i self.currentScreen = None self.screens = [] self._process_screens() self.currentScreen = self.screens[0] self._drag = None self.ignoreEvents = set([ xcb.xproto.KeyReleaseEvent, xcb.xproto.ReparentNotifyEvent, xcb.xproto.CreateNotifyEvent, # DWM handles this to help "broken focusing windows". xcb.xproto.MapNotifyEvent, xcb.xproto.LeaveNotifyEvent, xcb.xproto.FocusOutEvent, xcb.xproto.FocusInEvent, xcb.xproto.NoExposureEvent ]) self.conn.flush() self.conn.xsync() self._xpoll() self.server = command._Server(self.fname, self, config) # Map and Grab keys for key in self.config.keys: self.mapKey(key) # It fixes problems with focus when clicking windows of some specific clients like xterm def noop(qtile): pass self.config.mouse += (Click([], "Button1", command.lazy.function(noop), focus="after"), ) self.mouseMap = {} for i in self.config.mouse: if self.mouseMap.get(i.button_code) is None: self.mouseMap[i.button_code] = [] self.mouseMap[i.button_code].append(i) self.grabMouse() hook.fire("startup") self.scan() self.update_net_desktops() hook.subscribe.setgroup(self.update_net_desktops) if state: st = pickle.load(StringIO(state)) st.apply(self)
def make_qtile(): from argparse import ArgumentParser parser = ArgumentParser( description='A full-featured, pure-Python tiling window manager.', prog='qtile', ) parser.add_argument( '--version', action='version', version=VERSION, ) parser.add_argument( "-c", "--config", action="store", default=path.expanduser( path.join(getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile', 'config.py')), dest="configfile", help='Use the specified configuration file', ) parser.add_argument("-s", "--socket", action="store", default=None, dest="socket", help='Path to Qtile comms socket.') parser.add_argument("-n", "--no-spawn", action="store_true", default=False, dest="no_spawn", help='Avoid spawning apps. (Used for restart)') parser.add_argument('-l', '--log-level', default='WARNING', dest='log_level', choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), help='Set qtile log level') parser.add_argument( '--with-state', default=None, dest='state', help='Pickled QtileState object (typically used only internally)', ) options = parser.parse_args() log_level = getattr(logging, options.log_level) init_log(log_level=log_level) try: config = confreader.Config.from_file(options.configfile) except Exception as e: logger.exception('Error while reading config file (%s)', e) config = confreader.Config() from libqtile.widget import TextBox widgets = config.screens[0].bottom.widgets widgets.insert(0, TextBox('Config Err!')) # XXX: the import is here becouse we need to call init_log # before start importing stuff from libqtile import manager return manager.Qtile( config, fname=options.socket, no_spawn=options.no_spawn, state=options.state, )
def make_qtile(): from argparse import ArgumentParser parser = ArgumentParser( description='A full-featured, pure-Python tiling window manager.', prog='qtile', ) parser.add_argument( '--version', action='version', version=VERSION, ) parser.add_argument( "-c", "--config", action="store", default=path.expanduser(path.join( getenv('XDG_CONFIG_HOME', '~/.config'), 'qtile', 'config.py')), dest="configfile", help='Use the specified configuration file', ) parser.add_argument( "-s", "--socket", action="store", default=None, dest="socket", help='Path to Qtile comms socket.' ) parser.add_argument( "-n", "--no-spawn", action="store_true", default=False, dest="no_spawn", help='Avoid spawning apps. (Used for restart)' ) parser.add_argument( '-l', '--log-level', default='WARNING', dest='log_level', choices=('DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'), help='Set qtile log level' ) parser.add_argument( '--with-state', default=None, dest='state', help='Pickled QtileState object (typically used only internally)', ) options = parser.parse_args() log_level = getattr(logging, options.log_level) init_log(log_level=log_level) try: config = confreader.Config.from_file(options.configfile) except Exception as e: logger.exception('Error while reading config file (%s)', e) config = confreader.Config() from libqtile.widget import TextBox widgets = config.screens[0].bottom.widgets widgets.insert(0, TextBox('Config Err!')) # XXX: the import is here because we need to call init_log # before start importing stuff from libqtile import manager return manager.Qtile( config, fname=options.socket, no_spawn=options.no_spawn, state=options.state, )