-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
81 lines (66 loc) · 2.27 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/*
* Copyright (C) 2007 OpenedHand Ltd
*
* This program is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option) any later
* version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
* details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
* Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <gtk/gtk.h>
#include <vte/vte.h>
static void
on_window_title_changed (VteTerminal *terminal, GtkWindow *window)
{
char *title;
title = g_strdup_printf ("%s - Terminal", terminal->window_title);
gtk_window_set_title (window, title);
g_free (title);
}
static void
on_eof (VteTerminal *terminal, gpointer user_data)
{
gtk_main_quit ();
}
int
main (int argc, char **argv)
{
GtkWidget *window, *box, *terminal, *scrollbar;
int fakeargc = 1;
char *command = NULL;
char **args = NULL;
if (argc > 1)
command = argv[1];
if (argc > 2)
args = &(argv[1]);
gtk_init (&fakeargc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (window, "destroy", gtk_main_quit, NULL);
gtk_window_set_title (GTK_WINDOW (window), "Terminal");
box = gtk_hbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (window), box);
terminal = g_object_connect
(vte_terminal_new (),
/* Child dying */
"signal::child-exited", on_eof, NULL,
"signal::eof", on_eof, NULL,
/* Child is trying to control the terminal */
"signal::window-title-changed", on_window_title_changed, window,
NULL);
gtk_box_pack_start (GTK_BOX (box), terminal, TRUE, TRUE, 0);
scrollbar = gtk_vscrollbar_new (VTE_TERMINAL (terminal)->adjustment);
gtk_box_pack_start (GTK_BOX (box), scrollbar, FALSE, FALSE, 0);
vte_terminal_fork_command (VTE_TERMINAL (terminal),
command, args, NULL, NULL, TRUE, TRUE, TRUE);
gtk_widget_show_all (window);
gtk_main ();
return 0;
}