Skip to content

Instantly share code, notes, and snippets.

@weberc2
Last active August 29, 2015 14:20
Show Gist options
  • Save weberc2/9881de8dc05218237e4c to your computer and use it in GitHub Desktop.
Save weberc2/9881de8dc05218237e4c to your computer and use it in GitHub Desktop.
#include <gtk/gtk.h>
#include <vte/vte.h>
GtkWidget* create_window() {
GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_default_size(GTK_WINDOW(window), 600, 400);
g_signal_connect(window, "destroy", gtk_main_quit, NULL);
return window;
}
GtkWidget* create_scrolled_window(GtkContainer* parent) {
GtkWidget* scrolledWindow = gtk_scrolled_window_new(NULL, NULL);
gtk_scrolled_window_set_policy(
GTK_SCROLLED_WINDOW(scrolledWindow),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_add(parent, scrolledWindow);
return scrolledWindow;
}
GtkWidget* create_terminal(GtkContainer* parent) {
GtkWidget* terminal = vte_terminal_new();
// Setup bash terminal
vte_terminal_fork_command(
VTE_TERMINAL(terminal),
"bash",
NULL,
NULL,
g_get_current_dir(),
FALSE,
FALSE,
FALSE);
// Setup colors
GdkColor background;
gdk_color_parse("#333333", &background);
GdkColor foreground;
gdk_color_parse("#FFFFFF", &foreground);
vte_terminal_set_colors(VTE_TERMINAL(terminal), &foreground, &background, NULL, 0);
// Close the program when bash exits
g_signal_connect(terminal, "child-exited", gtk_main_quit, NULL);
gtk_container_add(parent, terminal);
return terminal;
}
void on_window_title_changed(VteTerminal* terminal, gpointer data) {
GtkWidget* window = (GtkWidget*)data;
gtk_window_set_title(GTK_WINDOW(window), vte_terminal_get_window_title(terminal));
}
int main(int argc, char** argv) {
gtk_init(&argc, &argv);
GtkWidget* window = create_window();
GtkWidget* scrolledWindow = create_scrolled_window(GTK_CONTAINER(window));
GtkWidget* terminal = create_terminal(GTK_CONTAINER(scrolledWindow));
g_signal_connect(terminal, "window-title-changed", G_CALLBACK(on_window_title_changed), window);
gtk_widget_show_all(window);
gtk_main();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment