Example #1
0
 def dump_cfg(self) -> None:
     i3_cfg, test_cfg = 'config', '.config'
     generated_cfg = '\n'.join(self.generate())
     with open(Misc.i3path() + test_cfg, 'w', encoding='utf8') as fp:
         fp.write(generated_cfg)
     if checker.check_i3_config(verbose=False, cfg=test_cfg):
         with open(Misc.i3path() + i3_cfg, 'w', encoding='utf8') as fp:
             fp.write(generated_cfg)
         os.remove(Misc.i3path() + test_cfg)
Example #2
0
    def __init__(self, i3ipc) -> None:
        # Initialize cfg.
        cfg.__init__(self, i3ipc)

        # i3ipc connection, bypassed by negi3wm runner
        self.i3ipc = i3ipc

        # i3 path used to get "send" binary path
        self.i3_path = Misc.i3path()

        # i3-msg application name
        self.i3cmd = self.conf("i3cmd")

        # Window properties shown by xprop menu.
        self.xprops_list = self.conf("xprops_list")

        # cache screen width
        if not self.conf("use_default_width"):
            from display import Display
            self.screen_width = Display.get_screen_resolution()["width"]
        else:
            self.screen_width = int(self.conf('use_default_width'))

        for mod in self.cfg['modules']:
            module = importlib.import_module('menu_mods.' + mod)
            setattr(self, mod, getattr(module, mod)(self))

        self.bindings = {
            "cmd_menu": self.i3menu.cmd_menu,
            "xprop": self.xprop.xprop,
            "autoprop": self.props.autoprop,
            "show_props": self.props.show_props,
            "pulse_output": self.pulse_menu.pulseaudio_output,
            "pulse_input": self.pulse_menu.pulseaudio_input,
            "pulse_mute": self.pulse_menu.pulseaudio_mute,
            "ws": self.winact.goto_ws,
            "goto_win": self.winact.goto_win,
            "attach": self.winact.attach_win,
            "movews": self.winact.move_to_ws,
            "gtk_theme": self.gnome.change_gtk_theme,
            "icon_theme": self.gnome.change_icon_theme,
            "xrandr_resolution": self.xrandr.change_resolution_xrandr,
            "reload": self.reload_config,
        }
Example #3
0
File: cfg.py Project: snide/negi3wm
    def __init__(self, i3) -> None:
        # detect current extension
        self.mod = self.__class__.__name__

        # extension config path
        self.i3_cfg_mod_path = Misc.i3path() + '/cfg/' + self.mod + '.cfg'

        # load current config
        self.load_config()

        # used for props add / del hacks
        self.win_attrs = {}

        # bind numbers to cfg names
        self.conv_props = {
            'class': 'class',
            'instance': 'instance',
            'window_role': 'window_role',
            'title': 'name',
        }

        self.i3ipc = i3
Example #4
0
 def __init__(self, menu):
     self.menu = menu
     self.gtk_config = configparser.ConfigParser()
     self.gsettings_script = os.path.expanduser(
         Misc.i3path() + 'bin/gnome_settings'
     )
Example #5
0
    def __init__(self, name: str, config) -> None:
        self.name = name
        cache_dir = Misc.i3path() + '/cache'
        Misc.create_dir(cache_dir)

        tmux_socket_dir = expanduser(f'{cache_dir}/tmux_sockets')
        dtach_session_dir = expanduser(f'{cache_dir}/dtach_sessions')
        self.alacritty_cfg_dir = expanduser(f'{cache_dir}/alacritty_cfg')
        self.alacritty_cfg = expanduser(os.environ.get("XDG_CONFIG_HOME") + \
            "/alacritty/alacritty.yml")

        Misc.create_dir(tmux_socket_dir)
        Misc.create_dir(self.alacritty_cfg_dir)
        Misc.create_dir(dtach_session_dir)

        self.sockpath = expanduser(f'{tmux_socket_dir}/{name}.socket')

        for sh in ['dash', 'zsh', 'bash', 'sh']:
            if shutil.which(sh):
                self.default_shell = sh
                break

        cfg_block = config.get(name, {})
        if not cfg_block:
            return

        # get terminal from config, use Alacritty by default
        self.term = cfg_block.get("term", "alacritty").lower()

        if os.path.exists(self.alacritty_cfg):
            if os.stat(self.alacritty_cfg).st_size == 0:
                print('Alacritty cfg {self.alacritty_cfg} is empty')
                self.term = env.terminal_fallback_detect()
        else:
            print('Alacritty cfg {self.alacritty_cfg} not exists, put it here')
            self.term = env.terminal_fallback_detect()

        self.wclass = cfg_block.get("class", self.term)
        self.title = cfg_block.get("title", self.wclass)
        self.font = config.get("default_font", "")
        if not self.font:
            self.font = cfg_block.get("font", "Iosevka Term")
        self.font_size = config.get("default_font_size", "")
        if not self.font_size:
            self.font_size = cfg_block.get("font_size", "14")
        use_one_fontstyle = config.get("use_one_fontstyle", False)
        self.font_style = config.get("default_font_style", "")
        if not self.font_style:
            self.font_style = cfg_block.get("font_style", "Regular")
        if use_one_fontstyle:
            self.font_normal = cfg_block.get("font_normal", self.font_style)
            self.font_bold = cfg_block.get("font_bold", self.font_style)
            self.font_italic = cfg_block.get("font_italic", self.font_style)
        else:
            self.font_normal = cfg_block.get("font_normal", 'Regular')
            self.font_bold = cfg_block.get("font_bold", 'Bold')
            self.font_italic = cfg_block.get("font_italic", 'Italic')

        self.tmux_session_attach = f"tmux -S {self.sockpath} a -t {name}"
        self.tmux_new_session = f"tmux -S {self.sockpath} new-session -s {name}"
        self.exec = cfg_block.get("exec", '')
        env_list = cfg_block.get("env", '')
        self.env_dict = {**os.environ}
        for env_str in env_list:
            env_data = env_str.split('=')
            if len(env_data) > 1:
                self.env_dict.update({env_data[0]: ' '.join(env_data[1:])})
        self.exec_tmux = cfg_block.get("exec_tmux", [])
        self.with_tmux = bool(self.exec_tmux)
        if not self.with_tmux:
            exec_dtach = cfg_block.get('exec_dtach', '')
            if not exec_dtach:
                self.prog = cfg_block.get('exec', 'true')
            else:
                self.prog = f'dtach -A {dtach_session_dir}' \
                            f'/{name}.session {exec_dtach}'

        self.padding = cfg_block.get('padding', [2, 2])
        self.opacity = cfg_block.get('opacity', 0.88)
        self.statusline = cfg_block.get('statusline', 1)

        self.create_term_params(config, name)

        def join_processes():
            for prc in multiprocessing.active_children():
                prc.join()

        threading.Thread(target=join_processes, args=(), daemon=True).start()