aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rw-r--r--Makefile25
-rw-r--r--README.md10
-rw-r--r--config.h35
-rw-r--r--main.c85
-rw-r--r--mterm.19
-rw-r--r--mterm.desktop8
7 files changed, 173 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..237bdb6
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1 @@
+mterm
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..25fff3d
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,25 @@
+CC := gcc
+CFLAGS := -O2 -Wall $(shell pkg-config --cflags vte-2.91)
+LIBS := $(shell pkg-config --libs vte-2.91)
+
+PREFIX ?= /usr/local
+BINDIR ?= ${PREFIX}/bin
+DATADIR ?= ${PREFIX}/share
+MANDIR ?= ${DATADIR}/man
+
+mterm: main.c config.h; $(CC) $(CFLAGS) $? $(LIBS) -o $@
+
+run: mterm; ./mterm
+
+install: mterm mterm.desktop mterm.1
+ install -Dm755 mterm ${DESTDIR}${BINDIR}/mterm
+ install -Dm644 mterm.desktop ${DESTDIR}${DATADIR}/applications/mterm.desktop
+ install -Dm644 mterm.1 ${DESTDIR}${MANDIR}/man1/mterm.1
+
+uninstall:
+ rm -f ${DESTDIR}${BINDIR}/mterm
+ rm -f ${DESTDIR}${DATADIR}/applications/mterm.desktop
+ rm -f ${DESTDIR}${MANDIR}/man1/mterm.1
+
+clean:
+ rm mterm
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..5af179e
--- /dev/null
+++ b/README.md
@@ -0,0 +1,10 @@
+My VTE based minimal terminal emulator.
+
+
+Copyright (C) 2020 Mateja Maric
+
+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 3 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, see https://www.gnu.org/licenses/.
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..4967a55
--- /dev/null
+++ b/config.h
@@ -0,0 +1,35 @@
+static const int max_lines = 10000;
+static const int scroll_on_output = 0;
+static const int scroll_on_keystroke = 1;
+static const int mouse_autohide = 0;
+
+
+static const float transparency = 0.8;
+
+static const int colors[] = {
+ 0x3b4252,
+ 0xbf616a,
+ 0xa3be8c,
+ 0xebcb8b,
+ 0x81a1c1,
+ 0xb48ead,
+ 0x88c0d0,
+ 0xe5e9f0,
+ 0x4c566a,
+ 0xbf616a,
+ 0xa3be8c,
+ 0xebcb8b,
+ 0x81a1c1,
+ 0xb48ead,
+ 0x8fbcbb,
+ 0xeceff4
+};
+
+static const int cursor = 0xd8dee9;
+static const int cursor_foreground = 0x2e3440;
+
+static const int foreground = 0xd8dee9;
+static const int foreground_bold = 0xd8dee9;
+static const int background = 0x2e3440;
+
+static const int highlight = 0x4c566a;
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();
+}
diff --git a/mterm.1 b/mterm.1
new file mode 100644
index 0000000..9d071e8
--- /dev/null
+++ b/mterm.1
@@ -0,0 +1,9 @@
+.TH MTERM 1
+.SH NAME
+mterm \- Mateja's VTE based minimal terminal emulator.
+.SH SYNOPSIS
+.B mterm
+[options]
+.SH DESCRIPTION
+.B mterm
+is minimal VTE based terminal emulator that is configured by compiling it's source code.
diff --git a/mterm.desktop b/mterm.desktop
new file mode 100644
index 0000000..93b61eb
--- /dev/null
+++ b/mterm.desktop
@@ -0,0 +1,8 @@
+[Desktop Entry]
+Name=mterm
+Comment=Mateja's VTE based minimal terminal emulator
+Exec=mterm
+Icon=utilities-terminal
+Type=Application
+Categories=GTK;System;TerminalEmulator;
+StartupNotify=true