Esempio n. 1
0
void termit_set_encoding(const gchar* encoding)
{
    gint page = gtk_notebook_get_current_page(GTK_NOTEBOOK(termit.notebook));
    TERMIT_GET_TAB_BY_INDEX(pTab, page);
    TRACE("%s tab=%p page=%d encoding=%s", __FUNCTION__, pTab, page, encoding);
    vte_terminal_set_encoding(VTE_TERMINAL(pTab->vte), encoding);
    g_free(pTab->encoding);
    pTab->encoding = g_strdup(encoding);
    termit_set_statusbar_message(page);
}
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);
    }
  }
Esempio n. 3
0
static VALUE
term_set_encoding(VALUE self, VALUE encoding)
{
    vte_terminal_set_encoding(RVAL2TERM(self), RVAL2CSTR(encoding));
    return Qnil;
}
Esempio n. 4
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();
}
Esempio n. 5
0
static GObject *
mud_subwindow_constructor (GType gtype,
                           guint n_properties,
                           GObjectConstructParam *properties)
{
    GtkWidget *term_box;
    MudWindow *app;
    GtkWidget *main_window;

    MudSubwindow *self;
    GObject *obj;
    MudSubwindowClass *klass;
    GObjectClass *parent_class;
    GtkBuilder *builder;

    /* Chain up to parent constructor */
    klass = MUD_SUBWINDOW_CLASS( g_type_class_peek(MUD_TYPE_SUBWINDOW) );
    parent_class = G_OBJECT_CLASS( g_type_class_peek_parent(klass) );
    obj = parent_class->constructor(gtype, n_properties, properties);

    self = MUD_SUBWINDOW(obj);

    if(!self->priv->parent_view)
    {
        g_printf("ERROR: Tried to instantiate MudSubwindow without passing parent view\n");
        g_error("Tried to instantiate MudSubwindow without passing parent view");
    }

    if(!self->priv->title)
    {
        g_printf("ERROR: Tried to instantiate MudSubwindow without passing title\n");
        g_error("Tried to instantiate MudSubwindow without passing title.");
    }

    if(!self->priv->identifier)
    {
        g_printf("ERROR: Tried to instantiate MudSubwindow without passing identifier\n");
        g_error("Tried to instantiate MudSubwindow without passing identifier.");
    }

    if(self->priv->width == 0 || self->priv->height == 0)
    {
        g_printf("ERROR: Tried to instantiate MudSubwindow without passing valid width/height\n");
        g_error("Tried to instantiate MudSubwindow without passing valid width/height.");
    }

    self->priv->old_width = self->priv->width;
    self->priv->old_height = self->priv->height;
    self->priv->initial_width = self->priv->width;
    self->priv->initial_height = self->priv->height;

    /* start glading */
    builder = gtk_builder_new_from_resource ("/org/gnome/MUD/main.ui");

    self->priv->window = GTK_WIDGET(gtk_builder_get_object(builder, "subwindow"));

    g_object_unref(builder);

    gtk_window_set_type_hint(GTK_WINDOW(self->priv->window),
                             GDK_WINDOW_TYPE_HINT_UTILITY);
    gtk_window_set_skip_taskbar_hint(GTK_WINDOW(self->priv->window), TRUE);
    gtk_window_set_skip_pager_hint(GTK_WINDOW(self->priv->window), TRUE);

    g_object_get(self->priv->parent_view, "window", &app, NULL);
    g_object_get(app, "window", &main_window, NULL);

    gtk_window_set_transient_for(GTK_WINDOW(self->priv->window),
                                 GTK_WINDOW(main_window));

    self->priv->vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
    self->priv->entry = gtk_entry_new();

    gtk_widget_hide(self->priv->entry);

    self->priv->terminal = vte_terminal_new();
    self->priv->scrollbar = gtk_scrollbar_new (GTK_ORIENTATION_VERTICAL, gtk_scrollable_get_vadjustment (GTK_SCROLLABLE (self->priv->terminal)));
    term_box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);

    vte_terminal_set_encoding(VTE_TERMINAL(self->priv->terminal),
                              "ISO-8859-1", NULL); /* TODO: This is deprecated; if keeping, at least add error handling? */

    /* TODO: set_emulation doesn't exist anymore. We don't really care, but does it affect TTYPE queries? */
    /* vte_terminal_set_emulation(VTE_TERMINAL(self->priv->terminal), "xterm"); */

    vte_terminal_set_cursor_shape(VTE_TERMINAL(self->priv->terminal),
                                  VTE_CURSOR_SHAPE_UNDERLINE);

    vte_terminal_set_cursor_blink_mode(VTE_TERMINAL(self->priv->terminal),
                                       VTE_CURSOR_BLINK_OFF);

    vte_terminal_set_size(VTE_TERMINAL(self->priv->terminal),
                                       self->priv->initial_width,
                                       self->priv->initial_height);

    gtk_box_pack_start(GTK_BOX(term_box),
                       self->priv->terminal,
                       TRUE,
                       TRUE,
                       0);

    gtk_box_pack_end(GTK_BOX(term_box),
                     self->priv->scrollbar,
                     FALSE,
                     FALSE,
                     0);

    gtk_box_pack_start(GTK_BOX(self->priv->vbox), term_box, TRUE, TRUE, 0);
    gtk_box_pack_end(GTK_BOX(self->priv->vbox), self->priv->entry, FALSE, FALSE, 0);
    gtk_container_add(GTK_CONTAINER(self->priv->window), self->priv->vbox);

    gtk_window_set_title(GTK_WINDOW(self->priv->window), self->priv->title);

    gtk_widget_show(term_box);
    gtk_widget_show(self->priv->vbox);

    if(self->priv->scroll)
        gtk_widget_show(self->priv->scrollbar);

    gtk_widget_show(self->priv->terminal);
    gtk_widget_show(self->priv->window);

    gtk_window_get_size(GTK_WINDOW(self->priv->window),
                        &self->priv->pixel_width,
                        &self->priv->pixel_height);


    return obj;
}