aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorMateja <mail@matejamaric.com>2020-12-09 16:17:59 +0100
committerMateja <mail@matejamaric.com>2020-12-09 16:17:59 +0100
commitf5644c06b741ee51089a10286fd89a739d3d572f (patch)
tree74ffb4a3fbce2ca90ef3c1c5b80b9e77301d9f26 /main.c
downloadmterm-f5644c06b741ee51089a10286fd89a739d3d572f.tar.gz
mterm-f5644c06b741ee51089a10286fd89a739d3d572f.zip
First commit.
Diffstat (limited to 'main.c')
-rw-r--r--main.c85
1 files changed, 85 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..06591b2
--- /dev/null
+++ b/main.c
@@ -0,0 +1,85 @@
+#include <vte/vte.h>
+#include "config.h"
+
+#define CLR_R(x) (((x) & 0xff0000) >> 16)
+#define CLR_G(x) (((x) & 0x00ff00) >> 8)
+#define CLR_B(x) (((x) & 0x0000ff) >> 0)
+#define CLR_16(x) ((double)(x) / 0xff)
+#define CLR_GDK(x, y) (const GdkRGBA){ .red = CLR_16(CLR_R(x)), \
+ .green = CLR_16(CLR_G(x)), \
+ .blue = CLR_16(CLR_B(x)), \
+ .alpha = (y) }
+
+static void child_ready(VteTerminal*, GPid, GError*, gpointer);
+
+
+int main(int argc, char *argv[]) {
+ GtkWidget *window, *terminal;
+
+ /* Initialise GTK, the window and the terminal */
+ gtk_init(&argc, &argv);
+ terminal = vte_terminal_new();
+ window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+ gtk_window_set_title(GTK_WINDOW(window), "mterm");
+
+ /* Set colors */
+ vte_terminal_set_colors(VTE_TERMINAL(terminal),
+ &CLR_GDK(foreground, 0),
+ &CLR_GDK(background, transparency),
+ (const GdkRGBA[]){
+ CLR_GDK(colors[0], 0),
+ CLR_GDK(colors[1], 0),
+ CLR_GDK(colors[2], 0),
+ CLR_GDK(colors[3], 0),
+ CLR_GDK(colors[4], 0),
+ CLR_GDK(colors[5], 0),
+ CLR_GDK(colors[6], 0),
+ CLR_GDK(colors[7], 0),
+ CLR_GDK(colors[8], 0),
+ CLR_GDK(colors[9], 0),
+ CLR_GDK(colors[10], 0),
+ CLR_GDK(colors[11], 0),
+ CLR_GDK(colors[12], 0),
+ CLR_GDK(colors[13], 0),
+ CLR_GDK(colors[14], 0),
+ CLR_GDK(colors[15], 0)
+ }, 16);
+
+ /* More settings */
+ vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), max_lines);
+ vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), scroll_on_output);
+ vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), scroll_on_keystroke);
+ vte_terminal_set_mouse_autohide(VTE_TERMINAL(terminal), mouse_autohide);
+ vte_terminal_set_allow_hyperlink(VTE_TERMINAL(terminal), TRUE);
+
+ /* Start a new shell */
+ gchar **envp = g_get_environ();
+ gchar **command = (gchar *[]){g_strdup(g_environ_getenv(envp, "SHELL")), NULL };
+ g_strfreev(envp);
+ vte_terminal_spawn_async(VTE_TERMINAL(terminal),
+ VTE_PTY_DEFAULT,
+ NULL, /* working directory */
+ command, /* command */
+ NULL, /* environment */
+ 0, /* spawn flags */
+ NULL, NULL, /* child setup */
+ NULL, /* child pid */
+ -1, /* timeout */
+ NULL, /* cancellable */
+ child_ready, /* callback */
+ NULL); /* user_data */
+
+ /* Connect some signals */
+ g_signal_connect(window, "delete-event", gtk_main_quit, NULL);
+ g_signal_connect(terminal, "child-exited", gtk_main_quit, NULL);
+
+ /* Put widgets together and run the main loop */
+ gtk_container_add(GTK_CONTAINER(window), terminal);
+ gtk_widget_show_all(window);
+ gtk_main();
+}
+
+static void child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data) {
+ if (!terminal) return;
+ if (pid == -1) gtk_main_quit();
+}