Esempio n. 1
0
static void
configure_term_widget (VteTerminal  *vtterm,
                       GVariantDict *options)
{
    /* Pick default settings from the settings... */
    dg_lmem gchar *opt_font = NULL;
    dg_lmem gchar *opt_theme = NULL;
    dg_lmem gchar *opt_fgcolor = NULL;
    dg_lmem gchar *opt_bgcolor = NULL;
    gboolean opt_bold;
    guint opt_scroll;
    DwtSettings *settings = dwt_settings_get_instance ();

    g_object_get (settings,
                  "font", &opt_font,
                  "theme", &opt_theme,
                  "allow-bold", &opt_bold,
                  "scrollback", &opt_scroll,
                  "foreground-color", &opt_fgcolor,
                  "background-color", &opt_bgcolor,
                  NULL);

    /*
     * This ensures that properties are updated for the terminal whenever they
     * change in the configuration files.
     *
     * TODO: For now this is done only for those properties which cannot be
     *       overriden using command line flags.
     */
    static const struct {
        const gchar  *setting_name;
        const gchar  *property_name;
        GBindingFlags bind_flags;
    } property_bind_map[] = {
        { "mouse-autohide", "pointer-autohide", G_BINDING_SYNC_CREATE },
        { "audible-bell",   "audible-bell",     G_BINDING_SYNC_CREATE },
    };
    for (guint i = 0; i < G_N_ELEMENTS (property_bind_map); i++) {
        g_object_bind_property (settings,
                                property_bind_map[i].setting_name,
                                G_OBJECT (vtterm),
                                property_bind_map[i].property_name,
                                property_bind_map[i].bind_flags);
    }

    /* ...and allow command line options to override them. */
    if (options) {
        dg_lmem gchar *cmd_font = NULL;
        g_variant_dict_lookup (options, "font", "s", &cmd_font);
        if (cmd_font) SWAP (gchar*, cmd_font, opt_font);

        dg_lmem gchar *cmd_theme = NULL;
        g_variant_dict_lookup (options, "theme", "s", &cmd_theme);
        if (cmd_theme) SWAP (gchar*, cmd_theme, opt_theme);

        g_variant_dict_lookup (options, "allow-bold", "b", &opt_bold);
        g_variant_dict_lookup (options, "scrollback", "u", &opt_scroll);
    }

    PangoFontDescription *fontd = pango_font_description_from_string (opt_font);
    if (fontd) {
      if (!pango_font_description_get_family (fontd))
        pango_font_description_set_family_static (fontd, "monospace");
      if (!pango_font_description_get_size (fontd))
        pango_font_description_set_size (fontd, 12 * PANGO_SCALE);
      vte_terminal_set_font (vtterm, fontd);
      pango_font_description_free (fontd);
      fontd = NULL;
    }

    const Theme *theme = &themes[1];
    if (opt_theme) {
        theme = find_theme (opt_theme);
        if (!theme) {
            g_printerr ("No such theme '%s', using default (linux)\n", opt_theme);
            theme = &themes[1];
        }
    }

    GdkRGBA fgcolor, bgcolor;
    if (!(opt_fgcolor && gdk_rgba_parse (&fgcolor, opt_fgcolor)))
        fgcolor = theme->fg;
    if (!(opt_bgcolor && gdk_rgba_parse (&bgcolor, opt_bgcolor)))
        bgcolor = theme->bg;

    vte_terminal_set_rewrap_on_resize    (vtterm, TRUE);
    vte_terminal_set_scroll_on_keystroke (vtterm, TRUE);
    vte_terminal_set_audible_bell        (vtterm, FALSE);
    vte_terminal_set_scroll_on_output    (vtterm, FALSE);
    vte_terminal_set_allow_bold          (vtterm, opt_bold);
    vte_terminal_set_scrollback_lines    (vtterm, opt_scroll);
    vte_terminal_set_cursor_blink_mode   (vtterm, VTE_CURSOR_BLINK_OFF);
    vte_terminal_set_cursor_shape        (vtterm, VTE_CURSOR_SHAPE_BLOCK);
    vte_terminal_set_colors              (vtterm,
                                          &fgcolor,
                                          &bgcolor,
                                          theme->colors,
                                          G_N_ELEMENTS (theme->colors));

    const GRegexCompileFlags regex_compile_flags =
        G_REGEX_CASELESS | G_REGEX_OPTIMIZE | G_REGEX_MULTILINE;
    gint match_tag =
        vte_terminal_match_add_gregex (vtterm,
                                       g_regex_new (uri_regexp,
                                                    regex_compile_flags,
                                                    G_REGEX_MATCH_NOTEMPTY,
                                                    NULL),
                                       G_REGEX_MATCH_NOTEMPTY);
    vte_terminal_match_set_cursor_type (vtterm, match_tag, GDK_HAND2);
}
Esempio n. 2
0
  void terminal::setup_terminal() {
    if ( m_terminal && m_configuration ) {
      GError *error = NULL;

      vte_terminal_set_scrollback_lines(m_terminal, m_configuration->get_scrollback_lines());
      vte_terminal_set_allow_bold(m_terminal, m_configuration->get_allow_bold());
      vte_terminal_set_audible_bell(m_terminal, m_configuration->get_audible_bell());
      vte_terminal_set_scroll_on_keystroke(m_terminal, m_configuration->get_scroll_on_keystroke());
      vte_terminal_set_scroll_on_output(m_terminal, m_configuration->get_scroll_on_output());
      vte_terminal_set_rewrap_on_resize(m_terminal, m_configuration->get_rewrap_on_resize());
      vte_terminal_set_mouse_autohide(m_terminal, m_configuration->get_autohide_mouse());
      if ( ! vte_terminal_set_encoding(m_terminal, m_configuration->get_encoding().c_str(), &error) ) {
        sterm::common::warning("sterm::terminal", "failed to set terminal encoding to '%s'", m_configuration->get_encoding().c_str());
        sterm::common::debug("sterm::terminal", "VteTerminal error message: %s", error->message);
      }

      std::string word_chars = m_configuration->get_word_chars();
      if ( ! word_chars.empty() )
        vte_terminal_set_word_char_exceptions(m_terminal, word_chars.c_str());
      else
        vte_terminal_set_word_char_exceptions(m_terminal, NULL);

      vte_terminal_set_cursor_blink_mode(m_terminal, m_configuration->get_cursor_blink_mode());
      vte_terminal_set_cursor_shape(m_terminal, m_configuration->get_cursor_shape());

      PangoFontDescription *font = NULL;
      if ( m_configuration->copy_font_description(&font) ) {
        vte_terminal_set_font(m_terminal, font);
        pango_font_description_free(font);
      } else {
        vte_terminal_set_font(m_terminal, NULL);
      }

      std::vector<GdkRGBA> color_palette = m_configuration->get_color_palette();
      color foreground = m_configuration->get_foreground_color();
      color background = m_configuration->get_background_color();
      color bold_color = m_configuration->get_bold_color();
      color cursor_color = m_configuration->get_cursor_color();
      color highlight_bg = m_configuration->get_highlight_bg_color();
      color highlight_fg = m_configuration->get_highlight_fg_color();

      if ( color_palette.size() == PALETTE_SIZE )
        vte_terminal_set_colors(m_terminal, NULL, NULL, color_palette.data(), PALETTE_SIZE);
      else
        vte_terminal_set_default_colors(m_terminal);

      if ( foreground.set )
        vte_terminal_set_color_foreground(m_terminal, &(foreground.value));

      if ( background.set )
        vte_terminal_set_color_background(m_terminal, &(background.value));

      if ( bold_color.set )
        vte_terminal_set_color_bold(m_terminal, &(bold_color.value));
      else
        vte_terminal_set_color_bold(m_terminal, NULL);

      if ( cursor_color.set )
        vte_terminal_set_color_cursor(m_terminal, &(cursor_color.value));
      else
        vte_terminal_set_color_cursor(m_terminal, NULL);

      if ( highlight_bg.set )
        vte_terminal_set_color_highlight(m_terminal, &(highlight_bg.value));
      else
        vte_terminal_set_color_highlight(m_terminal, NULL);

      if ( highlight_fg.set )
        vte_terminal_set_color_highlight_foreground(m_terminal, &(highlight_fg.value));
      else
        vte_terminal_set_color_highlight_foreground(m_terminal, NULL);
    }
  }