Handle kb by treating it as a backspace. Make pangox rendering the
[vte.git] / src / vteapp.c
1 /*
2  * Copyright (C) 2001,2002 Red Hat, Inc.
3  *
4  * This is free software; you can redistribute it and/or modify it under
5  * the terms of the GNU Library General Public License as published by
6  * the Free Software Foundation; either version 2 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful, but
10  * WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * General Public License for more details.
13  *
14  * You should have received a copy of the GNU Library General Public
15  * License along with this program; if not, write to the Free Software
16  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17  */
18
19 #ident "$Id$"
20 #include "../config.h"
21 #include <sys/stat.h>
22 #include <string.h>
23 #include <gtk/gtk.h>
24 #include <glib-object.h>
25 #include "vte.h"
26
27 static void
28 window_title_changed(GtkWidget *widget, gpointer win)
29 {
30         GtkWindow *window;
31
32         g_return_if_fail(VTE_TERMINAL(widget));
33         g_return_if_fail(GTK_IS_WINDOW(win));
34         g_return_if_fail(VTE_TERMINAL (widget)->window_title != NULL);
35         window = GTK_WINDOW(win);
36
37         gtk_window_set_title(window, VTE_TERMINAL (widget)->window_title);
38 }
39
40 static void
41 char_size_changed(GtkWidget *widget, guint width, guint height, gpointer win)
42 {
43         VteTerminal *terminal;
44         GtkWindow *window;
45         GdkGeometry geometry;
46         g_return_if_fail(GTK_IS_WINDOW(win));
47         g_return_if_fail(VTE_IS_TERMINAL(widget));
48         terminal = VTE_TERMINAL(widget);
49         window = GTK_WINDOW(win);
50         geometry.base_width = 0;
51         geometry.base_height = 0;
52         geometry.min_width = terminal->char_width;
53         geometry.min_height = terminal->char_height;
54         geometry.width_inc = terminal->char_width;
55         geometry.height_inc = terminal->char_height;
56         gtk_window_set_geometry_hints(window, widget, &geometry,
57                                       GDK_HINT_RESIZE_INC |
58                                       GDK_HINT_BASE_SIZE |
59                                       GDK_HINT_MIN_SIZE);
60 }
61
62 static void
63 destroy_and_quit(GtkWidget *widget, gpointer data)
64 {
65         if (GTK_IS_CONTAINER(data)) {
66                 gtk_container_remove(GTK_CONTAINER(data), widget);
67         } else {
68                 gtk_widget_destroy(widget);
69         }
70         gtk_main_quit();
71 }
72
73 int
74 main(int argc, char **argv)
75 {
76         GtkWidget *window, *hbox, *scrollbar, *widget;
77         const char *message = "Launching interactive shell...\r\n";
78         struct stat st;
79
80         gtk_init(&argc, &argv);
81
82         /* Create a window to hold the scrolling shell, and hook its
83          * delete event to the quit function.. */
84         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
85         g_signal_connect(G_OBJECT(window), "delete_event",
86                          GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
87
88         /* Create a box to hold everything. */
89         hbox = gtk_hbox_new(0, FALSE);
90         gtk_container_add(GTK_CONTAINER(window), hbox);
91
92         /* Create the terminal widget and add it to the scrolling shell. */
93         widget = vte_terminal_new();
94         char_size_changed(widget,
95                           (VTE_TERMINAL(widget)->char_width),
96                           (VTE_TERMINAL(widget)->char_height),
97                           window);
98         gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
99
100         /* Connect to the "char_size_changed" signal to set geometry hints
101          * whenever the font used by the terminal is changed. */
102         g_signal_connect_object(G_OBJECT(widget), "char_size_changed",
103                                 G_CALLBACK(char_size_changed), window, 0);
104
105         /* Connect to the "window_title_changed" signal to set the main
106          * window's title. */
107         g_signal_connect(G_OBJECT(widget), "window_title_changed",
108                          G_CALLBACK(window_title_changed), window);
109
110         /* Connect to the "eof" signal to quit when the session ends. */
111         g_signal_connect(G_OBJECT(widget), "eof",
112                          G_CALLBACK(destroy_and_quit), widget);
113
114         /* Create the scrollbar for the widget. */
115         scrollbar = gtk_vscrollbar_new((VTE_TERMINAL(widget))->adjustment);
116         gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0);
117
118         /* Set some defaults. */
119         vte_terminal_set_audible_bell(VTE_TERMINAL(widget), TRUE);
120         vte_terminal_set_cursor_blinks(VTE_TERMINAL(widget), TRUE);
121         vte_terminal_set_scroll_on_output(VTE_TERMINAL(widget), FALSE);
122         vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(widget), TRUE);
123         vte_terminal_set_scrollback_lines(VTE_TERMINAL(widget), 100);
124         if (stat("./background", &st) == 0) {
125                 vte_terminal_set_background_image_file(VTE_TERMINAL(widget),
126                                                        "./background");
127         } else {
128                 vte_terminal_set_background_transparent(VTE_TERMINAL(widget),
129                                                         TRUE);
130         }
131
132         /* Set the default font. */
133         vte_terminal_set_font_from_string(VTE_TERMINAL(widget),
134                                           "fixed semi-condensed 12");
135
136         /* Launch a shell. */
137 #ifdef VTE_DEBUG
138         vte_terminal_feed(VTE_TERMINAL(widget), message, strlen(message));
139 #endif
140         vte_terminal_fork_command(VTE_TERMINAL(widget), NULL, NULL);
141         vte_terminal_feed_child(VTE_TERMINAL(widget), "pwd\n", -1);
142
143         /* Go for it! */
144         gtk_widget_show_all(window);
145         gtk_main();
146
147         return 0;
148 }