Пример #1
0
/* callback to react to key press events */
static gboolean
key_press_cb(VteTerminal* vte, GdkEventKey* event)
{
    if ((event->state & (TINYTERM_MODIFIER)) == (TINYTERM_MODIFIER)) {
        switch (gdk_keyval_to_upper(event->keyval)) {
            case TINYTERM_KEY_FONTSIZE_INCREASE:
            {
                const PangoFontDescription *font = vte_terminal_get_font(vte);
                pango_font_description_set_size(font, (pango_font_description_get_size(font) / PANGO_SCALE + 1) * PANGO_SCALE);
                vte_terminal_set_font(vte, font);
                return TRUE;
            }
            case TINYTERM_KEY_FONTSIZE_DECREASE:
            {
                const PangoFontDescription *font = vte_terminal_get_font(vte);
                const gint size = pango_font_description_get_size(font) / PANGO_SCALE - 1;
                if (size > 0) {
                    pango_font_description_set_size(font, size * PANGO_SCALE);
                    vte_terminal_set_font(vte, font);
                }
                return TRUE;
            }
        }
    }
    return FALSE;
}
Пример #2
0
static void termit_set_fonts()
{
    gint page_num = gtk_notebook_get_n_pages(GTK_NOTEBOOK(termit.notebook));
    gint minWidth = 0, minHeight = 0;
    gint i=0;
    for (; i<page_num; ++i) {
        TERMIT_GET_TAB_BY_INDEX(pTab, i);
        vte_terminal_set_font(VTE_TERMINAL(pTab->vte), pTab->style.font);
        GtkBorder* border;
        gtk_widget_style_get(GTK_WIDGET(pTab->vte), "inner-border", &border, NULL);
        gint w = vte_terminal_get_char_width(VTE_TERMINAL(pTab->vte)) * configs.cols + border->left + border->right;
        if (w > minWidth)
            minWidth = w;
        gint h = vte_terminal_get_char_height(VTE_TERMINAL(pTab->vte)) * configs.rows + border->top + border->bottom;
        if (h > minHeight)
            minHeight = h;
    }
    gint oldWidth, oldHeight;
    gtk_window_get_size(GTK_WINDOW(termit.main_window), &oldWidth, &oldHeight);
    
    gint width = (minWidth > oldWidth) ? minWidth : oldWidth;
    gint height = (minHeight > oldHeight) ? minHeight : oldHeight;
    gtk_window_resize(GTK_WINDOW(termit.main_window), width, height);

    GdkGeometry geom;
    geom.min_width = minWidth;
    geom.min_height = minHeight;
    TRACE("width=%d height=%d", width, height);
    TRACE("minWidth=%d minHeight=%d", minWidth, minHeight);
    gtk_window_set_geometry_hints(GTK_WINDOW(termit.main_window), termit.main_window, &geom, GDK_HINT_MIN_SIZE);
}
Пример #3
0
static void
adjust_font_size(GtkWidget *widget, gpointer data, gint howmuch)
{
	VteTerminal *terminal;
	PangoFontDescription *desired;
	gint newsize;
	gint columns, rows, owidth, oheight;

	/* Read the screen dimensions in cells. */
	terminal = VTE_TERMINAL(widget);
	columns = terminal->column_count;
	rows = terminal->row_count;

	/* Take into account padding and border overhead. */
	gtk_window_get_size(GTK_WINDOW(data), &owidth, &oheight);
	owidth -= terminal->char_width * terminal->column_count;
	oheight -= terminal->char_height * terminal->row_count;

	/* Calculate the new font size. */
	desired = pango_font_description_copy(vte_terminal_get_font(terminal));
	newsize = pango_font_description_get_size(desired) / PANGO_SCALE;
	newsize += howmuch;
	pango_font_description_set_size(desired,
					CLAMP(newsize, 4, 144) * PANGO_SCALE);

	/* Change the font, then resize the window so that we have the same
	 * number of rows and columns. */
	vte_terminal_set_font(terminal, desired);
	gtk_window_resize(GTK_WINDOW(data),
			  columns * terminal->char_width + owidth,
			  rows * terminal->char_height + oheight);

	pango_font_description_free(desired);
}
Пример #4
0
void
term_set_font(GtkWidget *win, VteTerminal *term, size_t index)
{
    PangoFontDescription *font_desc = NULL;
    glong width, height;

    if (index >= sizeof fonts / sizeof fonts[0])
    {
        fprintf(stderr, __NAME__": Warning: Invalid font index\n");
        return;
    }

    width = vte_terminal_get_column_count(term);
    height = vte_terminal_get_row_count(term);

    font_desc = pango_font_description_from_string(fonts[index]);
    vte_terminal_set_font(term, font_desc);
    pango_font_description_free(font_desc);
    vte_terminal_set_font_scale(term, 1);

    term_set_size(win, term, width, height);

    if (win != NULL)
        vte_terminal_set_geometry_hints_for_window(VTE_TERMINAL(term),
                                                   GTK_WINDOW(win));
}
Пример #5
0
static void
font_size_action_ativated (GSimpleAction *action,
                           GVariant      *parameter,
                           gpointer       userdata)
{
    VteTerminal *vtterm = window_get_term_widget (GTK_WINDOW (userdata));
    const gint modifier = g_variant_get_int32 (parameter);

    const PangoFontDescription *fontd = vte_terminal_get_font (vtterm);
    gint old_size = pango_font_description_get_size (fontd);
    if (default_font_size == 0)
      default_font_size = old_size;
    PangoFontDescription *new_fontd;
    gint new_size;

    switch (modifier) {
      case 0:
        old_size = default_font_size;
        /* fall-through */
      case 1:
      case -1:
        new_size = old_size + modifier * PANGO_SCALE;
        new_fontd = pango_font_description_copy_static (fontd);
        pango_font_description_set_size (new_fontd, new_size);
        vte_terminal_set_font (vtterm, new_fontd);
        break;

      default:
        g_printerr ("%s: invalid modifier '%i'", __func__, modifier);
        return;
    }

    pango_font_description_free (new_fontd);
}
Пример #6
0
static VALUE
term_set_font(int argc, VALUE *argv, VALUE self)
{
    VALUE font_desc_or_name, rb_antialias;
    VteTerminalAntiAlias antialias = VTE_ANTI_ALIAS_USE_DEFAULT;
    VteTerminal *term;

    rb_scan_args(argc, argv, "11", &font_desc_or_name, &rb_antialias);

    term = RVAL2TERM(self);
    if (!NIL_P(rb_antialias))
        antialias = RVAL2AA(rb_antialias);

    if (rb_obj_is_kind_of(font_desc_or_name, rb_cString)) {
        char *name;
        name = RVAL2CSTR(font_desc_or_name);
        if (NIL_P(rb_antialias))
            vte_terminal_set_font_from_string(term, name);
        else
            vte_terminal_set_font_from_string_full(term, name, antialias);
    } else {
        PangoFontDescription *font_desc;
        font_desc = RVAL2PFD(font_desc_or_name);
        if (NIL_P(rb_antialias))
            vte_terminal_set_font(term, font_desc);
        else
            vte_terminal_set_font_full(term, font_desc, antialias);
    }

    return Qnil;
}
Пример #7
0
static void zoom(gboolean b, struct term *t) {

  int size = -2000;
  if(b)
    size = 2000;
  PangoFontDescription *font = vte_terminal_get_font(VTE_TERMINAL(t->vte));
  pango_font_description_set_size(font, pango_font_description_get_size(font) + size);
  vte_terminal_set_font(VTE_TERMINAL(t->vte), font);

}
Пример #8
0
static VALUE
rg_set_font(VALUE self, VALUE desc_or_name)
{
    if (rb_obj_is_kind_of(desc_or_name, rb_cString)) {
        vte_terminal_set_font_from_string(_SELF(self), RVAL2CSTR(desc_or_name));
    } else {
        vte_terminal_set_font(_SELF(self), RVAL2PANGOFONTDESCRIPTION(desc_or_name));
    }

    return self;
}
Пример #9
0
static void
gb_terminal_view_set_font_name (GbTerminalView *self,
                                const gchar    *font_name)
{
  PangoFontDescription *font_desc = NULL;

  g_assert (GB_IS_TERMINAL_VIEW (self));

  if (font_name != NULL)
    font_desc = pango_font_description_from_string (font_name);

  if (font_desc != NULL)
    {
      vte_terminal_set_font (self->terminal_top, font_desc);

      if (self->terminal_bottom)
        vte_terminal_set_font (self->terminal_bottom, font_desc);

      pango_font_description_free (font_desc);
    }
}
Пример #10
0
void termit_tab_set_font(struct TermitTab* pTab, const gchar* font_name)
{
    if (pTab->style.font_name) {
        g_free(pTab->style.font_name);
    }
    pTab->style.font_name = g_strdup(font_name);

    if (pTab->style.font) {
        pango_font_description_free(pTab->style.font);
    }
    pTab->style.font = pango_font_description_from_string(font_name);
    vte_terminal_set_font(VTE_TERMINAL(pTab->vte), pTab->style.font);
}
Пример #11
0
void tilda_term_adjust_font_scale(tilda_term *term, gdouble scale) {
    DEBUG_FUNCTION ("tilda_term_adjust_font_scale");

    VteTerminal *terminal = VTE_TERMINAL(term->vte_term);
    /* We need the tilda_term object to access the unscaled
     * font size and current scale factor */
    PangoFontDescription *desired;

    desired = pango_font_description_copy (vte_terminal_get_font(terminal));
    pango_font_description_set_size (desired, (gint) (term->tw->unscaled_font_size * scale));
    vte_terminal_set_font (terminal, desired);
    pango_font_description_free (desired);
}
Пример #12
0
void fake_vte_terminal_set_font_from_string(GtkWidget *vte, const char *font_name, gboolean anti_alias)
{
#ifdef DETAIL
	g_debug("! Launch fake_vte_terminal_set_font_from_string() with vte = %p, font_name = %s, anti_alias = %d", vte, font_name, anti_alias);
#endif
#ifdef SAFEMODE
	if ((vte==NULL) || (font_name==NULL)) return;
#endif

#ifdef USE_VTE_TERMINAL_SET_FONT
	PangoFontDescription *font_desc = pango_font_description_from_string(font_name);
	vte_terminal_set_font(VTE_TERMINAL(vte), font_desc);
#else
	vte_terminal_set_font_from_string_full( VTE_TERMINAL(vte), font_name, anti_alias);
#endif
}
Пример #13
0
static void
ide_terminal_font_changed (IdeTerminal *self,
                           const gchar *key,
                           GSettings   *settings)
{
  PangoFontDescription *font_desc = NULL;
  g_autofree gchar *font_name = NULL;

  g_assert (IDE_IS_TERMINAL (self));
  g_assert (G_IS_SETTINGS (settings));

  font_name = g_settings_get_string (settings, "font-name");

  if (font_name != NULL)
    font_desc = pango_font_description_from_string (font_name);

  vte_terminal_set_font (VTE_TERMINAL (self), font_desc);
  g_clear_pointer (&font_desc, pango_font_description_free);
}
Пример #14
0
static void
vte_config(VteTerminal* vte)
{
    GRegex* regex = g_regex_new(url_regex, G_REGEX_CASELESS, G_REGEX_MATCH_NOTEMPTY, NULL);

    vte_terminal_search_set_gregex(vte, regex, G_REGEX_MATCH_NOTEMPTY);
    vte_terminal_search_set_wrap_around     (vte, TINYTERM_SEARCH_WRAP_AROUND);
    vte_terminal_set_audible_bell           (vte, TINYTERM_AUDIBLE_BELL);
    vte_terminal_set_cursor_shape           (vte, TINYTERM_CURSOR_SHAPE);
    vte_terminal_set_cursor_blink_mode      (vte, TINYTERM_CURSOR_BLINK);
    vte_terminal_set_word_char_exceptions   (vte, TINYTERM_WORD_CHARS);
    vte_terminal_set_scrollback_lines       (vte, TINYTERM_SCROLLBACK_LINES);
    PangoFontDescription *font = pango_font_description_from_string(TINYTERM_FONT);
    vte_terminal_set_font(vte, font);

    GdkRGBA color_fg, color_bg;
    GdkRGBA color_palette[16];
    gdk_rgba_parse(&color_fg, TINYTERM_COLOR_FOREGROUND);
    gdk_rgba_parse(&color_bg, TINYTERM_COLOR_BACKGROUND);
    gdk_rgba_parse(&color_palette[0], TINYTERM_COLOR00);
    gdk_rgba_parse(&color_palette[1], TINYTERM_COLOR01);
    gdk_rgba_parse(&color_palette[2], TINYTERM_COLOR02);
    gdk_rgba_parse(&color_palette[3], TINYTERM_COLOR03);
    gdk_rgba_parse(&color_palette[4], TINYTERM_COLOR04);
    gdk_rgba_parse(&color_palette[5], TINYTERM_COLOR05);
    gdk_rgba_parse(&color_palette[6], TINYTERM_COLOR06);
    gdk_rgba_parse(&color_palette[7], TINYTERM_COLOR07);
    gdk_rgba_parse(&color_palette[8], TINYTERM_COLOR08);
    gdk_rgba_parse(&color_palette[9], TINYTERM_COLOR09);
    gdk_rgba_parse(&color_palette[10], TINYTERM_COLOR0A);
    gdk_rgba_parse(&color_palette[11], TINYTERM_COLOR0B);
    gdk_rgba_parse(&color_palette[12], TINYTERM_COLOR0C);
    gdk_rgba_parse(&color_palette[13], TINYTERM_COLOR0D);
    gdk_rgba_parse(&color_palette[14], TINYTERM_COLOR0E);
    gdk_rgba_parse(&color_palette[15], TINYTERM_COLOR0F);

    vte_terminal_set_colors(vte, &color_fg, &color_bg, &color_palette, 16);
}
Пример #15
0
static void
mud_subwindow_set_terminal_font(MudSubwindow *self)
{
    PangoFontDescription *desc = NULL;
    char *name;

    g_return_if_fail(MUD_IS_SUBWINDOW(self));

    name = self->priv->parent_view->profile->preferences->FontName;

    if(name)
        desc = pango_font_description_from_string(name);

    if(!desc)
        desc = pango_font_description_from_string("Monospace 10");

    vte_terminal_set_font(VTE_TERMINAL(self->priv->terminal), desc);

    mud_subwindow_set_size_force_grid(self,
            VTE_TERMINAL(self->priv->terminal),
            TRUE,
            self->priv->width,
            self->priv->height);
}
Пример #16
0
void termit_append_tab_with_details(const struct TabInfo* ti)
{
    struct TermitTab* pTab = g_malloc0(sizeof(struct TermitTab));
    termit_style_copy(&pTab->style, &configs.style);
    if (ti->name) {
        pTab->tab_name = gtk_label_new(ti->name);
        pTab->custom_tab_name = TRUE;
    } else {
        gchar* label_text = g_strdup_printf("%s %d", configs.default_tab_name, termit.tab_max_number++);
        pTab->tab_name = gtk_label_new(label_text);
        g_free(label_text);
        pTab->custom_tab_name = FALSE;
    }
    pTab->encoding = (ti->encoding) ? g_strdup(ti->encoding) : g_strdup(configs.default_encoding);
    pTab->bksp_binding = ti->bksp_binding;
    pTab->delete_binding = ti->delete_binding;
    pTab->hbox = gtk_hbox_new(FALSE, 0);
    pTab->vte = vte_terminal_new();

    vte_terminal_set_scrollback_lines(VTE_TERMINAL(pTab->vte), configs.scrollback_lines);
    if (configs.default_word_chars)
        vte_terminal_set_word_chars(VTE_TERMINAL(pTab->vte), configs.default_word_chars);
    vte_terminal_set_mouse_autohide(VTE_TERMINAL(pTab->vte), TRUE);
    vte_terminal_set_backspace_binding(VTE_TERMINAL(pTab->vte), pTab->bksp_binding);
    vte_terminal_set_delete_binding(VTE_TERMINAL(pTab->vte), pTab->delete_binding);
#ifdef TERMIT_ENABLE_SEARCH
    vte_terminal_search_set_wrap_around(VTE_TERMINAL(pTab->vte), TRUE);
#endif // TERMIT_ENABLE_SEARCH

    /* parse command */
    gchar **cmd_argv;
    GError *cmd_err = NULL;
    gchar *cmd_path = NULL;
    gchar *cmd_file = NULL;

    pTab->command = (ti->command) ? g_strdup(ti->command) : g_strdup(configs.default_command);
    if (!g_shell_parse_argv(pTab->command, NULL, &cmd_argv, &cmd_err)) {
        ERROR("%s", _("Cannot parse command. Creating tab with shell"));
        g_error_free(cmd_err);
    } else {
        cmd_path = g_find_program_in_path(cmd_argv[0]);
        cmd_file = g_path_get_basename(cmd_argv[0]);
    }

    TRACE("command=%s cmd_path=%s cmd_file=%s", pTab->command, cmd_path, cmd_file);
    if (cmd_path && cmd_file) {
        g_free(cmd_argv[0]);
        cmd_argv[0] = g_strdup(cmd_path);
#if VTE_CHECK_VERSION(0, 26, 0) > 0
        if (vte_terminal_fork_command_full(VTE_TERMINAL(pTab->vte),
                VTE_PTY_DEFAULT,
                ti->working_dir, 
                cmd_argv, NULL,
                0,
                NULL, NULL,
                &pTab->pid,
                &cmd_err) != TRUE) {
            ERROR("failed to open tab: %s", cmd_err->message);
            g_error_free(cmd_err);
        }
#else
        pTab->pid = vte_terminal_fork_command(VTE_TERMINAL(pTab->vte),
                cmd_path, cmd_argv, NULL, ti->working_dir, TRUE, TRUE, TRUE);
#endif // version >= 0.26
    } else {
        g_free(pTab->command);
        pTab->command = g_strdup(configs.default_command);
        gchar* argv[] = {pTab->command, NULL};
        TRACE("defaults: cmd=%s working_dir=%s", pTab->command, ti->working_dir);
        /* default tab */
#if VTE_CHECK_VERSION(0, 26, 0) > 0
        if (vte_terminal_fork_command_full(VTE_TERMINAL(pTab->vte),
                    VTE_PTY_DEFAULT,
                    ti->working_dir,
                    argv, NULL,
                    G_SPAWN_SEARCH_PATH,
                    NULL, NULL,
                    &pTab->pid,
                    &cmd_err) != TRUE) {
            ERROR("failed to open tab: %s", cmd_err->message);
            g_error_free(cmd_err);
        }
#else
        pTab->pid = vte_terminal_fork_command(VTE_TERMINAL(pTab->vte),
                pTab->command, NULL, NULL, ti->working_dir, TRUE, TRUE, TRUE);
#endif // version >= 0.26
    }

    g_strfreev(cmd_argv);
    g_free(cmd_path);
    g_free(cmd_file);

    g_signal_connect(G_OBJECT(pTab->vte), "beep", G_CALLBACK(termit_on_beep), pTab);
    g_signal_connect(G_OBJECT(pTab->vte), "focus-in-event", G_CALLBACK(termit_on_focus), pTab);
    g_signal_connect(G_OBJECT(pTab->vte), "window-title-changed", G_CALLBACK(termit_on_tab_title_changed), NULL);

    g_signal_connect(G_OBJECT(pTab->vte), "child-exited", G_CALLBACK(termit_on_child_exited), NULL);
//    g_signal_connect(G_OBJECT(pTab->vte), "eof", G_CALLBACK(termit_eof), NULL);
    g_signal_connect_swapped(G_OBJECT(pTab->vte), "button-press-event", G_CALLBACK(termit_on_popup), NULL);
    
    vte_terminal_set_encoding(VTE_TERMINAL(pTab->vte), pTab->encoding);

    pTab->matches = g_array_new(FALSE, TRUE, sizeof(struct Match));
    termit_tab_add_matches(pTab, configs.matches);
    termit_tab_set_transparency(pTab, pTab->style.transparency);
    vte_terminal_set_font(VTE_TERMINAL(pTab->vte), pTab->style.font);

    gint index = gtk_notebook_append_page(GTK_NOTEBOOK(termit.notebook), pTab->hbox, pTab->tab_name);
    if (index == -1) {
        ERROR("%s", _("Cannot create a new tab"));
        return;
    }
    if (configs.fill_tabbar) {
        GValue val = {};
        g_value_init(&val, G_TYPE_BOOLEAN);
        g_value_set_boolean(&val, TRUE);
        gtk_container_child_set_property(GTK_CONTAINER(termit.notebook), pTab->hbox, "tab-expand", &val);
        gtk_container_child_set_property(GTK_CONTAINER(termit.notebook), pTab->hbox, "tab-fill", &val);
    }

    termit_tab_set_audible_bell(pTab, configs.audible_bell);
    termit_tab_set_visible_bell(pTab, configs.visible_bell);

    pTab->scrollbar = gtk_vscrollbar_new(vte_terminal_get_adjustment(VTE_TERMINAL(pTab->vte)));

    gtk_box_pack_start(GTK_BOX(pTab->hbox), pTab->vte, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(pTab->hbox), pTab->scrollbar, FALSE, FALSE, 0);
    GtkWidget* tabWidget = gtk_notebook_get_nth_page(GTK_NOTEBOOK(termit.notebook), index);
    if (!tabWidget) {
        ERROR("tabWidget is NULL");
        return;
    }
    g_object_set_data(G_OBJECT(tabWidget), TERMIT_TAB_DATA, pTab);

    if (index == 0) { // there is no "switch-page" signal on the first page
        termit_set_statusbar_message(index);
    }
    pTab->scrollbar_is_shown = configs.show_scrollbar;
    gtk_widget_show_all(termit.notebook);
    
    if (pTab->style.image_file == NULL) {
        vte_terminal_set_background_image(VTE_TERMINAL(pTab->vte), NULL);
    } else {
        vte_terminal_set_background_image_file(VTE_TERMINAL(pTab->vte), pTab->style.image_file);
    }
    termit_tab_apply_colors(pTab);

    gtk_notebook_set_current_page(GTK_NOTEBOOK(termit.notebook), index);
    gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(termit.notebook), pTab->hbox, TRUE);
    gtk_window_set_focus(GTK_WINDOW(termit.main_window), pTab->vte);

    termit_check_single_tab();
    termit_hide_scrollbars();
}
Пример #17
0
/**
 * tilda_term_config_defaults ()
 *
 * Read and set all of the defaults for this terminal from the current configuration.
 *
 * Success: return 0
 * Failure: return non-zero
 */
static gint tilda_term_config_defaults (tilda_term *tt)
{
    DEBUG_FUNCTION ("tilda_term_config_defaults");
    DEBUG_ASSERT (tt != NULL);

    gdouble transparency_level = 0.0;
    GdkRGBA fg, bg, cc;
    gchar* word_chars;
    gint i;
    gint cursor_shape;

    /** Colors & Palette **/
    bg.red   =    GUINT16_TO_FLOAT(config_getint ("back_red"));
    bg.green =    GUINT16_TO_FLOAT(config_getint ("back_green"));
    bg.blue  =    GUINT16_TO_FLOAT(config_getint ("back_blue"));
    bg.alpha =    1.0;

    fg.red   =    GUINT16_TO_FLOAT(config_getint ("text_red"));
    fg.green =    GUINT16_TO_FLOAT(config_getint ("text_green"));
    fg.blue  =    GUINT16_TO_FLOAT(config_getint ("text_blue"));
    fg.alpha =    1.0;

    cc.red   =    GUINT16_TO_FLOAT(config_getint ("cursor_red"));
    cc.green =    GUINT16_TO_FLOAT(config_getint ("cursor_green"));
    cc.blue  =    GUINT16_TO_FLOAT(config_getint ("cursor_blue"));
    cc.alpha = 1.0;

    for(i = 0;i < TERMINAL_PALETTE_SIZE; i++) {
        current_palette[i].red   = GUINT16_TO_FLOAT(config_getnint ("palette", i*3));
        current_palette[i].green = GUINT16_TO_FLOAT(config_getnint ("palette", i*3+1));
        current_palette[i].blue  = GUINT16_TO_FLOAT(config_getnint ("palette", i*3+2));
        current_palette[i].alpha = 1.0;
    }

    vte_terminal_set_colors_rgba (VTE_TERMINAL(tt->vte_term), &fg, &bg, current_palette, TERMINAL_PALETTE_SIZE);

    /** Bells **/
    vte_terminal_set_audible_bell (VTE_TERMINAL(tt->vte_term), config_getbool ("bell"));
    vte_terminal_set_visible_bell (VTE_TERMINAL(tt->vte_term), config_getbool ("bell"));

    /** Cursor **/
    vte_terminal_set_cursor_blink_mode (VTE_TERMINAL(tt->vte_term),
            (config_getbool ("blinks"))?VTE_CURSOR_BLINK_ON:VTE_CURSOR_BLINK_OFF);
    vte_terminal_set_color_cursor_rgba (VTE_TERMINAL(tt->vte_term), &cc);

    cursor_shape = config_getint("cursor_shape");
    if (cursor_shape < 0 || cursor_shape > 2) {
        config_setint("cursor_shape", 0);
        cursor_shape = 0;
    }
    vte_terminal_set_cursor_shape(VTE_TERMINAL(tt->vte_term), (VteTerminalCursorShape)cursor_shape);

    /** Scrolling **/
    vte_terminal_set_scroll_background (VTE_TERMINAL(tt->vte_term), config_getbool ("scroll_background"));
    vte_terminal_set_scroll_on_output (VTE_TERMINAL(tt->vte_term), config_getbool ("scroll_on_output"));
    vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(tt->vte_term), config_getbool ("scroll_on_key"));

    /** Mouse **/
    vte_terminal_set_mouse_autohide (VTE_TERMINAL(tt->vte_term), FALSE); /* TODO: make this configurable */

    /** Text Properties **/
    vte_terminal_set_allow_bold (VTE_TERMINAL(tt->vte_term), config_getbool ("bold"));
    gtk_widget_set_double_buffered (tt->vte_term, config_getbool("double_buffer"));
    PangoFontDescription *description =
        pango_font_description_from_string (config_getstr ("font"));
    vte_terminal_set_font (VTE_TERMINAL (tt->vte_term), description);

    /** Scrollback **/
    vte_terminal_set_scrollback_lines (VTE_TERMINAL(tt->vte_term), config_getbool("scroll_history_infinite") ? -1 : config_getint ("lines"));

    /** Keys **/
    switch (config_getint ("backspace_key"))
    {
        case ASCII_DELETE:
            vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_DELETE);
            break;
        case DELETE_SEQUENCE:
            vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_DELETE_SEQUENCE);
            break;
        case ASCII_BACKSPACE:
            vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_BACKSPACE);
            break;
        case AUTO:
        default:
            vte_terminal_set_backspace_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_AUTO);
            break;
    }

    switch (config_getint ("delete_key"))
    {
        case ASCII_DELETE:
            vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_DELETE);
            break;
        case DELETE_SEQUENCE:
            vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_DELETE_SEQUENCE);
            break;
        case ASCII_BACKSPACE:
            vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_ASCII_BACKSPACE);
            break;
        case AUTO:
        default:
            vte_terminal_set_delete_binding (VTE_TERMINAL(tt->vte_term), VTE_ERASE_AUTO);
            break;
    }

    /** Word chars **/
    word_chars =  config_getstr ("word_chars");
    if (NULL == word_chars || '\0' == *word_chars) {
        word_chars = DEFAULT_WORD_CHARS;
    }
    vte_terminal_set_word_chars (VTE_TERMINAL(tt->vte_term), word_chars);

    /** Background **/
    if (config_getbool ("use_image"))
        vte_terminal_set_background_image_file (VTE_TERMINAL(tt->vte_term), config_getstr ("image"));
    else
        vte_terminal_set_background_image_file (VTE_TERMINAL(tt->vte_term), NULL);

    transparency_level = ((gdouble) config_getint ("transparency"))/100;

    if (config_getbool ("enable_transparency") && transparency_level > 0)
    {
        vte_terminal_set_background_saturation (VTE_TERMINAL (tt->vte_term), transparency_level);
        vte_terminal_set_opacity (VTE_TERMINAL (tt->vte_term), (1.0 - transparency_level) * 0xffff);
        vte_terminal_set_background_transparent (VTE_TERMINAL(tt->vte_term), !tt->tw->have_argb_visual);
    }

    return 0;
}
Пример #18
0
 void terminal::set_font_description(PangoFontDescription **i_font) {
   if ( m_terminal != NULL && *i_font != NULL ) {
     vte_terminal_set_font(m_terminal, *i_font);
   }
 }
Пример #19
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);
}
Пример #20
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);
    }
  }