~ubuntu-branches/ubuntu/natty/geany/natty

« back to all changes in this revision

Viewing changes to src/vte.c

  • Committer: Bazaar Package Importer
  • Author(s): Chow Loong Jin
  • Date: 2010-08-07 03:23:12 UTC
  • mfrom: (1.4.3 upstream)
  • mto: This revision was merged to the branch mainline in revision 22.
  • Revision ID: james.westby@ubuntu.com-20100807032312-ot70ac9d50cn79we
Tags: upstream-0.19
ImportĀ upstreamĀ versionĀ 0.19

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *      along with this program; if not, write to the Free Software
19
19
 *      Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20
20
 *
21
 
 * $Id: vte.c 4630 2010-01-31 21:54:47Z eht16 $
 
21
 * $Id: vte.c 4789 2010-03-30 14:43:40Z ntrel $
22
22
 */
23
23
 
24
24
/*
56
56
VteInfo vte_info;
57
57
VteConfig *vc;
58
58
 
59
 
extern gchar **environ;
60
59
static pid_t pid = 0;
61
60
static gboolean clean = TRUE;
62
61
static GModule *module = NULL;
108
107
        void (*vte_terminal_paste_clipboard) (VteTerminal *terminal);
109
108
        void (*vte_terminal_set_emulation) (VteTerminal *terminal, const gchar *emulation);
110
109
        void (*vte_terminal_set_color_foreground) (VteTerminal *terminal, const GdkColor *foreground);
 
110
        void (*vte_terminal_set_color_bold) (VteTerminal *terminal, const GdkColor *foreground);
111
111
        void (*vte_terminal_set_color_background) (VteTerminal *terminal, const GdkColor *background);
112
112
        void (*vte_terminal_feed_child) (VteTerminal *terminal, const char *data, glong length);
113
113
        void (*vte_terminal_im_append_menuitems) (VteTerminal *terminal, GtkMenuShell *menushell);
155
155
};
156
156
 
157
157
 
158
 
/* taken from anjuta, thanks */
159
158
static gchar **vte_get_child_environment(void)
160
159
{
161
 
        /* code from gnome-terminal, sort of. */
162
 
        gchar **p;
163
 
        gint i;
164
 
        gchar **retval;
165
 
#define EXTRA_ENV_VARS 5
166
 
 
167
 
        /* count env vars that are set */
168
 
        for (p = environ; *p; p++);
169
 
 
170
 
        i = p - environ;
171
 
        retval = g_new0(gchar *, i + 1 + EXTRA_ENV_VARS);
172
 
 
173
 
        for (i = 0, p = environ; *p; p++)
174
 
        {
175
 
                /* Strip all these out, we'll replace some of them */
176
 
                if ((strncmp(*p, "COLUMNS=", 8) == 0) ||
177
 
                    (strncmp(*p, "LINES=", 6) == 0)   ||
178
 
                    (strncmp(*p, "TERM=", 5) == 0))
179
 
                {
180
 
                        /* nothing: do not copy */
181
 
                }
182
 
                else
183
 
                {
184
 
                        retval[i] = g_strdup(*p);
185
 
                        ++i;
186
 
                }
187
 
        }
188
 
 
189
 
        retval[i] = g_strdup("TERM=xterm");
190
 
        ++i;
191
 
 
192
 
        retval[i] = NULL;
193
 
 
194
 
        return retval;
 
160
        const gchar *exclude_vars[] = {"COLUMNS", "LINES", "TERM", NULL};
 
161
 
 
162
        return utils_copy_environment(exclude_vars, "TERM", "xterm", NULL);
195
163
}
196
164
 
197
165
 
235
203
                const gchar *sonames[] = {  "libvte.so", "libvte.so.4",
236
204
                                                                        "libvte.so.8", "libvte.so.9", NULL };
237
205
 
238
 
                for (i = 0; sonames[i] != NULL && module == NULL; i++ )
 
206
                for (i = 0; sonames[i] != NULL && module == NULL; i++)
239
207
                {
240
208
                        module = g_module_open(sonames[i], G_MODULE_BIND_LAZY);
241
209
                }
329
297
 
330
298
static gboolean vte_keyrelease_cb(GtkWidget *widget, GdkEventKey *event, gpointer data)
331
299
{
332
 
        if (event->keyval == GDK_Return ||
333
 
                         event->keyval == GDK_ISO_Enter ||
334
 
                         event->keyval == GDK_KP_Enter ||
335
 
                         ((event->keyval == GDK_c) && (event->state & GDK_CONTROL_MASK)))
 
300
        if (ui_is_keyval_enter_or_return(event->keyval) ||
 
301
                ((event->keyval == GDK_c) && (event->state & GDK_CONTROL_MASK)))
336
302
        {
337
303
                /* assume any text on the prompt has been executed when pressing Enter/Return */
338
304
                clean = TRUE;
454
420
        g_module_symbol(mod, "vte_terminal_paste_clipboard", (void*)&vf->vte_terminal_paste_clipboard);
455
421
        g_module_symbol(mod, "vte_terminal_set_emulation", (void*)&vf->vte_terminal_set_emulation);
456
422
        g_module_symbol(mod, "vte_terminal_set_color_foreground", (void*)&vf->vte_terminal_set_color_foreground);
 
423
        g_module_symbol(mod, "vte_terminal_set_color_bold", (void*)&vf->vte_terminal_set_color_bold);
457
424
        g_module_symbol(mod, "vte_terminal_set_color_background", (void*)&vf->vte_terminal_set_color_background);
458
425
        g_module_symbol(mod, "vte_terminal_feed_child", (void*)&vf->vte_terminal_feed_child);
459
426
        g_module_symbol(mod, "vte_terminal_im_append_menuitems", (void*)&vf->vte_terminal_im_append_menuitems);
476
443
        vf->vte_terminal_set_emulation(VTE_TERMINAL(vc->vte), vc->emulation);
477
444
        vf->vte_terminal_set_font_from_string(VTE_TERMINAL(vc->vte), vc->font);
478
445
        vf->vte_terminal_set_color_foreground(VTE_TERMINAL(vc->vte), vc->colour_fore);
 
446
        vf->vte_terminal_set_color_bold(VTE_TERMINAL(vc->vte), vc->colour_fore);
479
447
        vf->vte_terminal_set_color_background(VTE_TERMINAL(vc->vte), vc->colour_back);
480
448
        vte_set_cursor_blink_mode();
481
449
 
705
673
}
706
674
 
707
675
 
 
676
static void font_button_clicked_cb(GtkFontButton *widget, gpointer user_data)
 
677
{
 
678
        const gchar *fontbtn = gtk_font_button_get_font_name(widget);
 
679
 
 
680
        if (! utils_str_equal(fontbtn, vc->font))
 
681
        {
 
682
                setptr(vc->font, g_strdup(gtk_font_button_get_font_name(widget)));
 
683
                vte_apply_user_settings();
 
684
        }
 
685
}
 
686
 
 
687
 
 
688
static void on_color_button_choose_cb(GtkColorButton *widget, gpointer user_data)
 
689
{
 
690
        switch (GPOINTER_TO_INT(user_data))
 
691
        {
 
692
                case 1:
 
693
                {
 
694
                        g_free(vc->colour_fore);
 
695
                        vc->colour_fore = g_new0(GdkColor, 1);
 
696
                        gtk_color_button_get_color(widget, vc->colour_fore);
 
697
                        break;
 
698
                }
 
699
                case 2:
 
700
                {
 
701
                        g_free(vc->colour_back);
 
702
                        vc->colour_back = g_new0(GdkColor, 1);
 
703
                        gtk_color_button_get_color(widget, vc->colour_back);
 
704
                        break;
 
705
                }
 
706
        }
 
707
}
 
708
 
 
709
 
708
710
void vte_append_preferences_tab(void)
709
711
{
710
712
        if (vte_info.have_vte)
718
720
 
719
721
                notebook = ui_lookup_widget(ui_widgets.prefs_dialog, "notebook2");
720
722
 
721
 
                frame = ui_frame_new_with_alignment(_("Terminal plugin"), &alignment);
 
723
                frame = ui_frame_new_with_alignment(_("Terminal"), &alignment);
722
724
                gtk_container_set_border_width(GTK_CONTAINER(frame), 5);
723
725
                vbox = gtk_vbox_new(FALSE, 12);
724
726
                gtk_container_add(GTK_CONTAINER(alignment), vbox);
731
733
                gtk_table_set_row_spacings(GTK_TABLE(table), 3);
732
734
                gtk_table_set_col_spacings(GTK_TABLE(table), 10);
733
735
 
734
 
                label = gtk_label_new(_("Terminal font:"));
 
736
                label = gtk_label_new(_("Font:"));
735
737
                gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
736
738
                                        (GtkAttachOptions) (GTK_FILL),
737
739
                                        (GtkAttachOptions) (0), 0, 0);
777
779
 
778
780
                spin_scrollback_adj = gtk_adjustment_new(500, 0, 5000, 1, 10, 0);
779
781
                spin_scrollback = gtk_spin_button_new(GTK_ADJUSTMENT(spin_scrollback_adj), 1, 0);
780
 
                ui_entry_add_clear_icon(spin_scrollback);
 
782
                ui_entry_add_clear_icon(GTK_ENTRY(spin_scrollback));
781
783
                gtk_table_attach(GTK_TABLE(table), spin_scrollback, 1, 2, 3, 4,
782
784
                                        (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
783
785
                                        (GtkAttachOptions) (0), 0, 0);
792
794
                gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5);
793
795
 
794
796
                entry_shell = gtk_entry_new();
795
 
                ui_entry_add_clear_icon(entry_shell);
 
797
                ui_entry_add_clear_icon(GTK_ENTRY(entry_shell));
796
798
                ui_widget_set_tooltip_text(entry_shell, _("Sets the path to the shell which should be started inside the terminal emulation"));
797
799
 
798
800
                button_shell = gtk_button_new();
881
883
 
882
884
                gtk_widget_show_all(frame);
883
885
 
884
 
                g_signal_connect(font_term, "font-set", G_CALLBACK(on_prefs_font_choosed),
885
 
                                                                                                                        GINT_TO_POINTER(4));
886
 
                g_signal_connect(color_fore, "color-set", G_CALLBACK(on_prefs_color_choosed),
 
886
                g_signal_connect(font_term, "font-set", G_CALLBACK(font_button_clicked_cb), NULL);
 
887
                g_signal_connect(color_fore, "color-set", G_CALLBACK(on_color_button_choose_cb),
 
888
                                                                                                                        GINT_TO_POINTER(1));
 
889
                g_signal_connect(color_back, "color-set", G_CALLBACK(on_color_button_choose_cb),
887
890
                                                                                                                        GINT_TO_POINTER(2));
888
 
                g_signal_connect(color_back, "color-set", G_CALLBACK(on_prefs_color_choosed),
889
 
                                                                                                                        GINT_TO_POINTER(3));
890
 
                g_signal_connect(button_shell, "clicked",
891
 
                                G_CALLBACK(on_prefs_tools_button_clicked), entry_shell);
 
891
                ui_setup_open_button_callback(button_shell, NULL,
 
892
                        GTK_FILE_CHOOSER_ACTION_OPEN, GTK_ENTRY(entry_shell));
892
893
        }
893
894
}
894
895
 
915
916
 
916
917
        len = strlen(text);
917
918
 
918
 
        /* Make sure there is no newline character at the end to prevent unwanted execution */
919
 
        if (text[len-1] == '\n' || text[len-1] == '\r')
920
 
                text[len-1] = '\0';
 
919
        if (vc->send_selection_unsafe)
 
920
        {       /* Explicitly append a trailing newline character to get the command executed,
 
921
                   this is disabled by default as it could cause all sorts of damage. */
 
922
                if (text[len-1] != '\n' && text[len-1] != '\r')
 
923
                {
 
924
                        setptr(text, g_strconcat(text, "\n", NULL));
 
925
                        len++;
 
926
                }
 
927
        }
 
928
        else
 
929
        {       /* Make sure there is no newline character at the end to prevent unwanted execution */
 
930
                while (text[len-1] == '\n' || text[len-1] == '\r')
 
931
                {
 
932
                        text[len-1] = '\0';
 
933
                        len--;
 
934
                }
 
935
        }
921
936
 
922
937
        vf->vte_terminal_feed_child(VTE_TERMINAL(vc->vte), text, len);
923
938
 
929
944
        g_free(text);
930
945
}
931
946
 
 
947
 
932
948
#endif