Emit "window_title_changed" and "icon_title_changed" when the titles change,
[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 <string.h>
22 #include <gtk/gtk.h>
23 #include <glib-object.h>
24 #include "vte.h"
25
26 static void
27 window_title_changed(GtkWidget *widget, gpointer win)
28 {
29         GtkWindow *window;
30
31         g_return_if_fail(VTE_TERMINAL(widget));
32         g_return_if_fail(GTK_IS_WINDOW(win));
33         g_return_if_fail(VTE_TERMINAL (widget)->window_title != NULL);
34         window = GTK_WINDOW(win);
35
36         gtk_window_set_title(window, VTE_TERMINAL (widget)->window_title);
37 }
38
39 static void
40 char_size_changed(GtkWidget *widget, guint width, guint height, gpointer win)
41 {
42         VteTerminal *terminal;
43         GtkWindow *window;
44         GdkGeometry geometry;
45         g_return_if_fail(GTK_IS_WINDOW(win));
46         g_return_if_fail(VTE_IS_TERMINAL(widget));
47         terminal = VTE_TERMINAL(widget);
48         window = GTK_WINDOW(win);
49         geometry.base_width = 0;
50         geometry.base_height = 0;
51         geometry.min_width = terminal->char_width;
52         geometry.min_height = terminal->char_height;
53         geometry.width_inc = terminal->char_width;
54         geometry.height_inc = terminal->char_height;
55         gtk_window_set_geometry_hints(window, widget, &geometry,
56                                       GDK_HINT_RESIZE_INC |
57                                       GDK_HINT_BASE_SIZE |
58                                       GDK_HINT_MIN_SIZE);
59 }
60
61 int
62 main(int argc, char **argv)
63 {
64         GtkWidget *window, *hbox, *scrollbar, *widget;
65         const char *message = "Launching interactive shell...\r\n";
66
67         gtk_init(&argc, &argv);
68
69         /* Create a window to hold the scrolling shell, and hook its
70          * delete event to the quit function.. */
71         window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
72         g_signal_connect(G_OBJECT(window), "delete_event",
73                          GTK_SIGNAL_FUNC(gtk_main_quit), NULL);
74
75         /* Create a box to hold everything. */
76         hbox = gtk_hbox_new(0, FALSE);
77         gtk_container_add(GTK_CONTAINER(window), hbox);
78
79         /* Create the terminal widget and add it to the scrolling shell. */
80         widget = vte_terminal_new();
81         char_size_changed(widget,
82                           (VTE_TERMINAL(widget)->char_width),
83                           (VTE_TERMINAL(widget)->char_height),
84                           window);
85         gtk_box_pack_start(GTK_BOX(hbox), widget, TRUE, TRUE, 0);
86
87         /* Connect to the "char_size_changed" signal to set geometry hints
88          * whenever the font used by the terminal is changed. */
89         g_signal_connect_object(G_OBJECT(widget), "char_size_changed",
90                                 G_CALLBACK(char_size_changed), window, 0);
91
92         /* Connect to the "window_title_changed" signal to set the main
93          * window's title. */
94         g_signal_connect(G_OBJECT(widget), "window_title_changed",
95                          G_CALLBACK(window_title_changed), window);
96
97         /* Connect to the "eof" signal to quit when the session ends. */
98         g_signal_connect(G_OBJECT(widget), "eof",
99                          G_CALLBACK(gtk_main_quit), NULL);
100
101         /* Create the scrollbar for the widget. */
102         scrollbar = gtk_vscrollbar_new((VTE_TERMINAL(widget))->adjustment);
103         gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0);
104
105         /* Launch a shell. */
106 #ifdef VTE_DEBUG
107         vte_terminal_feed(VTE_TERMINAL(widget), message, strlen(message));
108 #endif
109         vte_terminal_fork_command(VTE_TERMINAL(widget), NULL, NULL);
110
111         /* Go for it! */
112         gtk_widget_show_all(window);
113         gtk_main();
114
115         return 0;
116 }