aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/T.c75
-rw-r--r--src/config.h38
2 files changed, 65 insertions, 48 deletions
diff --git a/src/T.c b/src/T.c
index fd1859e..dc8f52f 100644
--- a/src/T.c
+++ b/src/T.c
@@ -31,12 +31,16 @@ static int window_count;
/* Event callbacks */
static gboolean window_delete_event_callback(GtkWidget *widget, GdkEvent *event, gpointer data);
static void window_destroy_callback(GtkWidget *widget, gpointer data);
+
+static gboolean key_press_callback(GtkWidget *widget, GdkEvent *event, gpointer data);
+
static void terminal_child_exited_callback(VteTerminal *terminal, gpointer data);
static void terminal_window_title_changed_callback(VteTerminal *terminal, gpointer data);
-/* Helper setup functions */
+/* Helper functions */
+static void set_font_size(VteTerminal *terminal, int diff);
static void setup_pty(VteTerminal *terminal, GPid *child_pid);
-static void set_app_preferences(VteTerminal *terminal);
+static void set_preferences(VteTerminal *terminal);
static void setup_terminal(GtkWindow *window, VteTerminal *terminal);
static void setup_window(GtkWindow *window);
static void spawn_window(void);
@@ -58,45 +62,50 @@ window_destroy_callback(GtkWidget *widget, gpointer data)
}
static gboolean
-terminal_key_press_callback(GtkWidget *widget, GdkEvent *event, gpointer data)
+key_press_callback(GtkWidget *widget, GdkEvent *event, gpointer data)
{
GdkEventKey *key_event = (GdkEventKey *) event;
- /* VteTerminal *terminal = (VteTerminal *) widget; */
+ VteTerminal *terminal = VTE_TERMINAL(widget);
+
+ gboolean has_shift = (key_event->state & GDK_SHIFT_MASK) != 0;
+ gboolean has_control = (key_event->state & GDK_CONTROL_MASK) != 0;
+
+ if (!has_control)
+ return FALSE;
- if ((key_event->state & GDK_SHIFT_MASK) == 0
- || (key_event->state & GDK_CONTROL_MASK) == 0)
+ switch (key_event->keyval) {
+ case GDK_KEY_minus:
+ set_font_size(terminal, -1);
+ return TRUE;
+ case GDK_KEY_plus:
+ set_font_size(terminal, 1);
+ return TRUE;
+ }
+
+ if (!has_shift)
return FALSE;
+ /* Handles ctrl + shift + {c,v,n} */
switch (key_event->keyval) {
case GDK_KEY_C:
case GDK_KEY_c:
- /*
- * This was:
- * vte_terminal_copy_clipboard(terminal);
- * break;
- * But now we just turn this event into a Control+Insert and delegate it
- */
+ /* turn this event into a Control+Insert and delegate it */
key_event->keyval = GDK_KEY_Insert;
key_event->state &= ~GDK_SHIFT_MASK;
- return FALSE;
+ break;
case GDK_KEY_V:
case GDK_KEY_v:
- /*
- * This was:
- * vte_terminal_paste_clipboard(terminal);
- * break;
- * But now we just turn this event into a Shift+Insert and delegate it
- */
+ /* turn this event into a Shift+Insert and delegate it */
key_event->keyval = GDK_KEY_Insert;
key_event->state &= ~GDK_CONTROL_MASK;
- return FALSE;
+ break;
case GDK_KEY_N:
case GDK_KEY_n:
spawn_window();
- break;
+ return TRUE;
}
- return TRUE;
+ return FALSE;
}
static void
@@ -104,7 +113,7 @@ terminal_child_exited_callback(VteTerminal *terminal, gpointer data)
{
GtkWindow *window;
- window = (GtkWindow *) data;
+ window = GTK_WINDOW(data);
gtk_widget_destroy(GTK_WIDGET(window));
}
@@ -118,6 +127,15 @@ terminal_window_title_changed_callback(VteTerminal *terminal, gpointer data)
}
static void
+set_font_size(VteTerminal *terminal, int diff)
+{
+ PangoFontDescription *desc = (PangoFontDescription *) vte_terminal_get_font(terminal);
+ gint font_size = pango_font_description_get_size(desc) + diff * PANGO_SCALE;
+ pango_font_description_set_size(desc, font_size);
+ vte_terminal_set_font(terminal, desc);
+}
+
+static void
setup_pty(VteTerminal *terminal, GPid *child_pid)
{
VtePty* pty;
@@ -131,7 +149,7 @@ setup_pty(VteTerminal *terminal, GPid *child_pid)
}
static void
-set_app_preferences(VteTerminal *terminal)
+set_preferences(VteTerminal *terminal)
{
/*
* Options set here can (and should) be configured through config.h
@@ -173,10 +191,10 @@ setup_terminal(GtkWindow *window, VteTerminal *terminal)
vte_terminal_watch_child(terminal, child_pid);
g_signal_connect(terminal, "child-exited", G_CALLBACK(terminal_child_exited_callback), window);
+ g_signal_connect(terminal, "key-press-event", G_CALLBACK(key_press_callback), window);
g_signal_connect(terminal, "window-title-changed", G_CALLBACK(terminal_window_title_changed_callback), window);
- g_signal_connect(terminal, "key-press-event", G_CALLBACK(terminal_key_press_callback), window);
- set_app_preferences(terminal);
+ set_preferences(terminal);
}
static void
@@ -227,10 +245,9 @@ main(int argc, char *argv[])
spawn_window();
/*
- * TODO
+ * TODO:
* Find out a nice and clean way of opening more windows when the user
- * does not have focus on a T window. Maybe fire spawn_window() when we
- * detect a running T process?
+ * does not have focus on a T window.
*/
gtk_main();
diff --git a/src/config.h b/src/config.h
index 0a348c4..f1f5b59 100644
--- a/src/config.h
+++ b/src/config.h
@@ -22,7 +22,7 @@
#define CONFIG_MIN_WIDTH 20
#define CONFIG_MIN_HEIGHT 5
-/* Font name */
+/* Font */
#define CONFIG_FONT_NAME "Monospace 9"
/* Color palette definition */
@@ -30,27 +30,27 @@
#define CONFIG_PALETTE_SIZE 16
static const char *CONFIG_COLOR_PALETTE[CONFIG_PALETTE_SIZE] = {
- "#000000000000", /* 0 Black */
- "#959551513a3a", /* 1 Red */
- "#3a3a95955151", /* 2 Green */
- "#7e7e95953a3a", /* 3 Yellow */
- "#3d3d55558d8d", /* 4 Blue */
- "#95953a3a7e7e", /* 5 Magenta */
- "#3a3a7e7e9595", /* 6 Cyan */
- "#d9d9d9d9d9d9", /* 7 White */
- "#444444444444", /* 8 Black */
- "#c1c178786060", /* 9 Red */
- "#6060c1c17878", /* 10 Green */
- "#a9a9c1c16060", /* 11 Yellow */
- "#5f5f7a7ababa", /* 12 Blue */
- "#c1c16060a9a9", /* 13 Magenta */
- "#6060a9a9c1c1", /* 14 Cyan */
- "#ffffffffffff", /* 15 White */
+ "#000000", /* 0 Black */
+ "#95513a", /* 1 Red */
+ "#3a9551", /* 2 Green */
+ "#7e953a", /* 3 Yellow */
+ "#3d558d", /* 4 Blue */
+ "#953a7e", /* 5 Magenta */
+ "#3a7e95", /* 6 Cyan */
+ "#d9d9d9", /* 7 White */
+ "#262626", /* 8 Black */
+ "#c17860", /* 9 Red */
+ "#60c178", /* 10 Green */
+ "#a9c160", /* 11 Yellow */
+ "#5f7aba", /* 12 Blue */
+ "#c160a9", /* 13 Magenta */
+ "#60a9c1", /* 14 Cyan */
+ "#ffffff", /* 15 White */
};
/* Foreground and background. */
-#define CONFIG_FOREGROUND_COLOR "#d9d9e6e6f2f2" /* COLOR_PALETTE[7] */
-#define CONFIG_BACKGROUND_COLOR "#0d0d19192626" /* COLOR_PALETTE[0] */
+#define CONFIG_FOREGROUND_COLOR "#d9e6f2" /* COLOR_PALETTE[7] */
+#define CONFIG_BACKGROUND_COLOR "#0d1926" /* COLOR_PALETTE[0] */
/* Scrollback lines (0 means disabled; negative means "infinite") */
#define CONFIG_SCROLLBACK_LINES 2000