2012-06-02 14:46:46 +02:00
|
|
|
#define _POSIX_C_SOURCE 200809L
|
|
|
|
|
2012-05-30 10:22:09 +02:00
|
|
|
#include <stdbool.h>
|
2012-06-02 14:46:46 +02:00
|
|
|
#include <string.h>
|
2012-05-30 10:22:09 +02:00
|
|
|
|
2012-05-22 06:34:35 +02:00
|
|
|
#include <gtk/gtk.h>
|
|
|
|
#include <vte/vte.h>
|
|
|
|
|
2012-05-22 21:21:54 +02:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-05-31 15:38:13 +02:00
|
|
|
#define CONCAT(X, Y) X ## Y
|
|
|
|
#define KEY(X) CONCAT(GDK_KEY_, X)
|
|
|
|
|
2012-05-30 10:22:09 +02:00
|
|
|
#ifndef __GNUC__
|
|
|
|
# define __attribute__(x)
|
|
|
|
#endif
|
|
|
|
|
2012-06-04 05:17:18 +02:00
|
|
|
enum overlay_mode {
|
2012-06-04 05:39:19 +02:00
|
|
|
OVERLAY_HIDDEN = 0,
|
2012-06-04 05:17:18 +02:00
|
|
|
OVERLAY_SEARCH,
|
2012-06-04 05:37:15 +02:00
|
|
|
OVERLAY_RSEARCH,
|
2012-06-04 05:17:18 +02:00
|
|
|
OVERLAY_COMPLETION
|
|
|
|
};
|
|
|
|
|
2012-06-01 03:31:09 +02:00
|
|
|
typedef struct search_panel_info {
|
2012-05-30 10:22:09 +02:00
|
|
|
GtkWidget *vte;
|
2012-06-01 03:49:06 +02:00
|
|
|
GtkWidget *entry;
|
2012-06-01 03:31:09 +02:00
|
|
|
GtkBin *panel;
|
2012-06-04 05:17:18 +02:00
|
|
|
enum overlay_mode mode;
|
2012-06-01 03:31:09 +02:00
|
|
|
} search_panel_info;
|
2012-05-30 10:22:09 +02:00
|
|
|
|
2012-05-31 23:16:01 +02:00
|
|
|
static const gchar *browser_cmd[3] = { NULL };
|
|
|
|
|
2012-06-03 03:31:28 +02:00
|
|
|
static gboolean add_to_list_store(char *key,
|
|
|
|
__attribute__((unused)) void *value,
|
|
|
|
GtkListStore *store) {
|
|
|
|
GtkTreeIter iter;
|
|
|
|
gtk_list_store_append(store, &iter);
|
|
|
|
gtk_list_store_set(store, &iter, 0, key, -1);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-03 02:28:06 +02:00
|
|
|
static GtkTreeModel *create_completion_model(VteTerminal *vte) {
|
2012-06-06 01:39:44 +02:00
|
|
|
GtkListStore *store = gtk_list_store_new(1, G_TYPE_STRING);
|
2012-06-03 02:28:06 +02:00
|
|
|
|
2012-06-07 03:22:26 +02:00
|
|
|
glong end_row, end_col;
|
|
|
|
vte_terminal_get_cursor_position(vte, &end_col, &end_row);
|
2012-06-07 03:26:22 +02:00
|
|
|
gchar *content = vte_terminal_get_text_range(vte, 0, 0, end_row, end_col,
|
2012-06-07 03:22:26 +02:00
|
|
|
NULL, NULL, NULL);
|
2012-06-02 14:46:46 +02:00
|
|
|
|
|
|
|
if (!content) {
|
2012-06-07 17:42:17 +02:00
|
|
|
g_printerr("no content returned for completion\n");
|
2012-06-07 03:26:22 +02:00
|
|
|
return GTK_TREE_MODEL(store);
|
2012-06-02 14:46:46 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
char *s_ptr = content, *saveptr;
|
|
|
|
|
2012-06-03 03:31:28 +02:00
|
|
|
GTree *tree = g_tree_new((GCompareFunc)strcmp);
|
|
|
|
|
2012-06-07 04:06:46 +02:00
|
|
|
for (; ; s_ptr = NULL) {
|
2012-06-05 21:24:05 +02:00
|
|
|
char *token = strtok_r(s_ptr, " \n\t", &saveptr);
|
2012-06-02 14:46:46 +02:00
|
|
|
if (!token) {
|
|
|
|
break;
|
|
|
|
}
|
2012-06-03 03:31:28 +02:00
|
|
|
g_tree_insert(tree, token, NULL);
|
2012-06-02 14:46:46 +02:00
|
|
|
}
|
|
|
|
|
2012-06-03 03:31:28 +02:00
|
|
|
g_tree_foreach(tree, (GTraverseFunc)add_to_list_store, store);
|
2012-06-07 02:54:33 +02:00
|
|
|
g_tree_destroy(tree);
|
2012-06-07 01:17:39 +02:00
|
|
|
g_free(content);
|
2012-06-03 02:28:06 +02:00
|
|
|
return GTK_TREE_MODEL(store);
|
|
|
|
}
|
|
|
|
|
2012-05-30 10:29:25 +02:00
|
|
|
static void search(VteTerminal *vte, const char *pattern, bool reverse) {
|
2012-05-30 10:22:09 +02:00
|
|
|
GRegex *regex = vte_terminal_search_get_gregex(vte);
|
|
|
|
if (regex) g_regex_unref(regex);
|
2012-06-02 12:13:59 +02:00
|
|
|
regex = g_regex_new(pattern, (GRegexCompileFlags)0, (GRegexMatchFlags)0, NULL);
|
2012-05-30 10:22:09 +02:00
|
|
|
vte_terminal_search_set_gregex(vte, regex);
|
|
|
|
|
2012-05-30 10:29:25 +02:00
|
|
|
if (!reverse) {
|
2012-05-30 10:22:09 +02:00
|
|
|
vte_terminal_search_find_next(vte);
|
|
|
|
} else {
|
|
|
|
vte_terminal_search_find_previous(vte);
|
|
|
|
}
|
2012-05-30 11:27:27 +02:00
|
|
|
vte_terminal_copy_primary(vte);
|
2012-05-30 10:22:09 +02:00
|
|
|
}
|
|
|
|
|
2012-06-04 05:17:18 +02:00
|
|
|
static gboolean entry_key_press_cb(GtkEntry *entry, GdkEventKey *event, search_panel_info *info) {
|
2012-06-01 04:27:10 +02:00
|
|
|
gboolean ret = FALSE;
|
|
|
|
|
|
|
|
if (event->keyval == GDK_KEY_Escape) {
|
|
|
|
ret = TRUE;
|
|
|
|
} else if (event->keyval == GDK_KEY_Return) {
|
2012-06-04 05:17:18 +02:00
|
|
|
const gchar *text = gtk_entry_get_text(entry);
|
|
|
|
|
|
|
|
switch (info->mode) {
|
|
|
|
case OVERLAY_SEARCH:
|
2012-06-04 05:37:15 +02:00
|
|
|
search(VTE_TERMINAL(info->vte), text, false);
|
|
|
|
break;
|
|
|
|
case OVERLAY_RSEARCH:
|
|
|
|
search(VTE_TERMINAL(info->vte), text, true);
|
2012-06-04 05:17:18 +02:00
|
|
|
break;
|
|
|
|
case OVERLAY_COMPLETION:
|
2012-06-04 06:24:39 +02:00
|
|
|
vte_terminal_feed_child(VTE_TERMINAL(info->vte), text, -1);
|
2012-06-04 05:17:18 +02:00
|
|
|
break;
|
2012-06-04 05:49:39 +02:00
|
|
|
case OVERLAY_HIDDEN:
|
2012-06-04 05:17:18 +02:00
|
|
|
break;
|
|
|
|
}
|
2012-06-04 05:49:39 +02:00
|
|
|
ret = TRUE;
|
2012-06-01 04:27:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (ret) {
|
2012-06-04 05:17:18 +02:00
|
|
|
info->mode = OVERLAY_HIDDEN;
|
2012-06-01 03:31:09 +02:00
|
|
|
gtk_widget_hide(GTK_WIDGET(info->panel));
|
2012-06-01 03:49:06 +02:00
|
|
|
gtk_widget_grab_focus(info->vte);
|
2012-05-31 13:06:31 +02:00
|
|
|
}
|
2012-06-01 04:27:10 +02:00
|
|
|
return ret;
|
2012-05-31 13:06:31 +02:00
|
|
|
}
|
|
|
|
|
2012-06-04 05:37:15 +02:00
|
|
|
static void overlay_show(search_panel_info *info, enum overlay_mode mode, bool complete) {
|
|
|
|
if (complete) {
|
|
|
|
GtkEntryCompletion *completion = gtk_entry_completion_new();
|
|
|
|
gtk_entry_set_completion(GTK_ENTRY(info->entry), completion);
|
|
|
|
g_object_unref(completion);
|
|
|
|
|
|
|
|
GtkTreeModel *completion_model = create_completion_model(VTE_TERMINAL(info->vte));
|
|
|
|
gtk_entry_completion_set_model(completion, completion_model);
|
|
|
|
g_object_unref(completion_model);
|
|
|
|
|
2012-06-06 01:28:55 +02:00
|
|
|
gtk_entry_completion_set_inline_selection(completion, TRUE);
|
2012-06-04 05:37:15 +02:00
|
|
|
gtk_entry_completion_set_text_column(completion, 0);
|
|
|
|
}
|
|
|
|
|
2012-06-04 06:24:39 +02:00
|
|
|
gtk_entry_set_text(GTK_ENTRY(info->entry), "");
|
|
|
|
|
2012-06-04 05:37:15 +02:00
|
|
|
info->mode = mode;
|
|
|
|
gtk_widget_show(GTK_WIDGET(info->panel));
|
|
|
|
gtk_widget_grab_focus(info->entry);
|
|
|
|
}
|
|
|
|
|
2012-06-02 12:53:31 +02:00
|
|
|
static gboolean key_press_cb(VteTerminal *vte, GdkEventKey *event, search_panel_info *info) {
|
2012-06-02 12:13:59 +02:00
|
|
|
const guint modifiers = event->state & gtk_accelerator_get_default_mod_mask();
|
2012-05-22 10:20:55 +02:00
|
|
|
if (modifiers == (GDK_CONTROL_MASK|GDK_SHIFT_MASK)) {
|
2012-05-22 08:58:38 +02:00
|
|
|
switch (gdk_keyval_to_lower(event->keyval)) {
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_COPY):
|
2012-06-02 12:53:31 +02:00
|
|
|
vte_terminal_copy_clipboard(vte);
|
2012-05-23 11:40:04 +02:00
|
|
|
return TRUE;
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_PASTE):
|
2012-06-02 12:53:31 +02:00
|
|
|
vte_terminal_paste_clipboard(vte);
|
2012-05-23 11:40:04 +02:00
|
|
|
return TRUE;
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_PREV):
|
2012-06-02 12:53:31 +02:00
|
|
|
vte_terminal_search_find_previous(vte);
|
|
|
|
vte_terminal_copy_primary(vte);
|
2012-05-30 10:22:09 +02:00
|
|
|
return TRUE;
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_NEXT):
|
2012-06-02 12:53:31 +02:00
|
|
|
vte_terminal_search_find_next(vte);
|
|
|
|
vte_terminal_copy_primary(vte);
|
2012-05-30 10:22:09 +02:00
|
|
|
return TRUE;
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_SEARCH):
|
2012-06-04 05:37:15 +02:00
|
|
|
overlay_show(info, OVERLAY_SEARCH, true);
|
2012-05-30 10:22:09 +02:00
|
|
|
return TRUE;
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_RSEARCH):
|
2012-06-04 05:37:15 +02:00
|
|
|
overlay_show(info, OVERLAY_RSEARCH, true);
|
2012-05-30 10:22:09 +02:00
|
|
|
return TRUE;
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_URL):
|
2012-06-02 12:53:31 +02:00
|
|
|
search(vte, url_regex, false);
|
2012-05-30 11:35:41 +02:00
|
|
|
return TRUE;
|
2012-05-31 15:38:13 +02:00
|
|
|
case KEY(KEY_RURL):
|
2012-06-02 12:53:31 +02:00
|
|
|
search(vte, url_regex, true);
|
2012-05-30 11:35:41 +02:00
|
|
|
return TRUE;
|
2012-05-22 08:58:38 +02:00
|
|
|
}
|
2012-06-04 05:17:18 +02:00
|
|
|
} else if (modifiers == GDK_CONTROL_MASK && event->keyval == GDK_KEY_Tab) {
|
2012-06-04 05:37:15 +02:00
|
|
|
overlay_show(info, OVERLAY_COMPLETION, true);
|
2012-06-04 05:17:18 +02:00
|
|
|
return TRUE;
|
2012-05-22 08:58:38 +02:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-05-22 13:15:28 +02:00
|
|
|
static void get_vte_padding(VteTerminal *vte, int *w, int *h) {
|
|
|
|
GtkBorder *border = NULL;
|
|
|
|
gtk_widget_style_get(GTK_WIDGET(vte), "inner-border", &border, NULL);
|
2012-05-31 11:32:51 +02:00
|
|
|
if (!border) {
|
2012-05-22 13:15:28 +02:00
|
|
|
g_warning("VTE's inner-border property unavailable");
|
|
|
|
*w = *h = 0;
|
|
|
|
} else {
|
|
|
|
*w = border->left + border->right;
|
|
|
|
*h = border->top + border->bottom;
|
|
|
|
gtk_border_free(border);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static char *check_match(VteTerminal *vte, int event_x, int event_y) {
|
|
|
|
int xpad, ypad, tag;
|
|
|
|
get_vte_padding(vte, &xpad, &ypad);
|
2012-05-22 13:17:27 +02:00
|
|
|
return vte_terminal_match_check(vte,
|
2012-05-22 13:15:28 +02:00
|
|
|
(event_x - ypad) / vte_terminal_get_char_width(vte),
|
|
|
|
(event_y - ypad) / vte_terminal_get_char_height(vte),
|
|
|
|
&tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean button_press_cb(VteTerminal *vte, GdkEventButton *event) {
|
2012-06-01 11:42:05 +02:00
|
|
|
char *match = check_match(vte, (int)event->x, (int)event->y);
|
2012-05-22 13:15:28 +02:00
|
|
|
if (event->button == 1 && event->type == GDK_BUTTON_PRESS && match != NULL) {
|
2012-05-31 23:16:01 +02:00
|
|
|
browser_cmd[1] = match;
|
|
|
|
g_spawn_async(NULL, (gchar **)browser_cmd, NULL, G_SPAWN_SEARCH_PATH, NULL, NULL, NULL, NULL);
|
2012-05-22 13:15:28 +02:00
|
|
|
g_free(match);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-06-04 17:19:53 +02:00
|
|
|
static void beep_handler(GtkWindow *window) {
|
2012-05-30 19:30:00 +02:00
|
|
|
gtk_window_set_urgency_hint(window, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean focus_in_handler(GtkWindow *window) {
|
|
|
|
gtk_window_set_urgency_hint(window, FALSE);
|
|
|
|
return FALSE;
|
2012-05-22 13:47:51 +02:00
|
|
|
}
|
|
|
|
|
2012-05-22 14:22:31 +02:00
|
|
|
static void window_title_cb(VteTerminal *vte, GtkWindow *window) {
|
|
|
|
const char *t = vte_terminal_get_window_title(vte);
|
2012-05-22 15:50:21 +02:00
|
|
|
gtk_window_set_title(window, t ? t : "termite");
|
2012-05-22 14:22:31 +02:00
|
|
|
}
|
|
|
|
|
2012-06-02 11:28:56 +02:00
|
|
|
static gboolean position_overlay_cb(GtkBin *overlay, GtkWidget *widget, GdkRectangle *alloc) {
|
|
|
|
GtkWidget *vte = gtk_bin_get_child(overlay);
|
2012-05-31 18:39:59 +02:00
|
|
|
|
2012-06-01 04:31:15 +02:00
|
|
|
int width = gtk_widget_get_allocated_width(vte);
|
|
|
|
int height = gtk_widget_get_allocated_height(vte);
|
2012-05-31 18:39:59 +02:00
|
|
|
|
|
|
|
GtkRequisition req;
|
|
|
|
gtk_widget_get_preferred_size(widget, NULL, &req);
|
|
|
|
|
2012-06-01 04:31:15 +02:00
|
|
|
alloc->x = width - req.width - 40;
|
2012-05-31 18:39:59 +02:00
|
|
|
alloc->y = 0;
|
2012-06-01 04:31:15 +02:00
|
|
|
alloc->width = MIN(width, req.width);
|
|
|
|
alloc->height = MIN(height, req.height);
|
2012-05-31 18:39:59 +02:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
#define MAKE_GET_CONFIG_FUNCTION(NAME, TYPE) \
|
|
|
|
static bool get_config_ ## NAME (GKeyFile *config, const char *group, const char *key, TYPE *value) { \
|
|
|
|
GError *error = NULL; \
|
|
|
|
*value = g_key_file_get_ ## NAME (config, group, key, &error); \
|
|
|
|
if (error) { \
|
|
|
|
g_error_free(error); \
|
|
|
|
return false; \
|
|
|
|
} \
|
|
|
|
return true; \
|
|
|
|
}
|
|
|
|
|
|
|
|
MAKE_GET_CONFIG_FUNCTION(boolean, gboolean)
|
|
|
|
MAKE_GET_CONFIG_FUNCTION(integer, gint)
|
|
|
|
MAKE_GET_CONFIG_FUNCTION(string, gchar *)
|
2012-06-08 03:05:31 +02:00
|
|
|
MAKE_GET_CONFIG_FUNCTION(double, gdouble)
|
2012-06-07 18:41:48 +02:00
|
|
|
|
2012-06-08 19:19:10 +02:00
|
|
|
static void load_config(GtkWindow *window, VteTerminal *vte, bool first_run,
|
2012-06-07 20:15:31 +02:00
|
|
|
gboolean *dynamic_title, gboolean *urgent_on_bell,
|
2012-06-08 20:33:22 +02:00
|
|
|
gboolean *clickable_url, double *transparency, const gchar **term) {
|
2012-06-08 01:25:04 +02:00
|
|
|
|
2012-06-08 02:08:34 +02:00
|
|
|
static const char *filename = "termite.cfg";
|
2012-06-08 01:25:04 +02:00
|
|
|
const gchar *dir = g_get_user_config_dir();
|
2012-06-08 02:08:34 +02:00
|
|
|
gchar *path = g_build_filename(dir, filename, NULL);
|
2012-06-08 01:25:04 +02:00
|
|
|
|
2012-06-07 18:22:24 +02:00
|
|
|
GKeyFile *config = g_key_file_new();
|
2012-06-08 02:08:34 +02:00
|
|
|
|
|
|
|
if ((g_key_file_load_from_file(config, path, G_KEY_FILE_NONE, NULL) ||
|
|
|
|
g_key_file_load_from_dirs(config, filename, (const char **)g_get_system_config_dirs(),
|
|
|
|
NULL, G_KEY_FILE_NONE, NULL))) {
|
2012-06-07 23:56:17 +02:00
|
|
|
gboolean cfgbool;
|
2012-06-08 19:19:10 +02:00
|
|
|
gdouble cfgdouble;
|
|
|
|
gint cfgint;
|
2012-06-07 23:56:17 +02:00
|
|
|
gchar *cfgstr;
|
|
|
|
|
2012-06-08 19:19:10 +02:00
|
|
|
if (first_run && get_config_string(config, "terminal", "term", &cfgstr)) {
|
|
|
|
*term = cfgstr;
|
|
|
|
}
|
|
|
|
|
2012-06-08 18:44:08 +02:00
|
|
|
if (get_config_boolean(config, "options", "resize_grip", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
gtk_window_set_has_resize_grip(window, cfgbool);
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "scroll_on_output", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
vte_terminal_set_scroll_on_output(vte, cfgbool);
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "scroll_on_keystroke", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
vte_terminal_set_scroll_on_keystroke(vte, cfgbool);
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "audible_bell", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
vte_terminal_set_audible_bell(vte, cfgbool);
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "visible_bell", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
vte_terminal_set_visible_bell(vte, cfgbool);
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "mouse_autohide", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
vte_terminal_set_mouse_autohide(vte, cfgbool);
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "allow_bold", &cfgbool)) {
|
2012-06-08 17:56:50 +02:00
|
|
|
vte_terminal_set_allow_bold(vte, cfgbool);
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "dynamic_title", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
*dynamic_title = cfgbool;
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "urgent_on_bell", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
*urgent_on_bell = cfgbool;
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
|
|
|
if (get_config_boolean(config, "options", "clickable_url", &cfgbool)) {
|
2012-06-07 23:56:17 +02:00
|
|
|
*clickable_url = cfgbool;
|
2012-06-08 18:44:08 +02:00
|
|
|
}
|
2012-06-08 01:31:07 +02:00
|
|
|
if (get_config_string(config, "options", "browser", &cfgstr)) {
|
|
|
|
browser_cmd[0] = cfgstr;
|
|
|
|
} else {
|
|
|
|
browser_cmd[0] = g_getenv("BROWSER");
|
|
|
|
if (!browser_cmd[0]) *clickable_url = false;
|
|
|
|
}
|
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_string(config, "options", "font", &cfgstr)) {
|
|
|
|
vte_terminal_set_font_from_string(vte, cfgstr);
|
|
|
|
g_free(cfgstr);
|
2012-06-07 18:55:08 +02:00
|
|
|
}
|
2012-06-07 18:58:07 +02:00
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_integer(config, "options", "scrollback_lines", &cfgint)) {
|
|
|
|
vte_terminal_set_scrollback_lines(vte, cfgint);
|
2012-06-07 18:58:07 +02:00
|
|
|
}
|
2012-06-07 19:36:03 +02:00
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_string(config, "options", "cursor_blink", &cfgstr)) {
|
|
|
|
if (!strcmp(cfgstr, "SYSTEM")) {
|
2012-06-07 19:36:03 +02:00
|
|
|
vte_terminal_set_cursor_blink_mode(vte, VTE_CURSOR_BLINK_SYSTEM);
|
2012-06-07 23:56:17 +02:00
|
|
|
} else if (!strcmp(cfgstr, "ON")) {
|
2012-06-07 19:36:03 +02:00
|
|
|
vte_terminal_set_cursor_blink_mode(vte, VTE_CURSOR_BLINK_ON);
|
2012-06-07 23:56:17 +02:00
|
|
|
} else if (!strcmp(cfgstr, "OFF")) {
|
2012-06-07 19:36:03 +02:00
|
|
|
vte_terminal_set_cursor_blink_mode(vte, VTE_CURSOR_BLINK_OFF);
|
|
|
|
}
|
2012-06-07 23:56:17 +02:00
|
|
|
g_free(cfgstr);
|
2012-06-07 19:36:03 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_string(config, "options", "cursor_shape", &cfgstr)) {
|
|
|
|
if (!strcmp(cfgstr, "BLOCK")) {
|
2012-06-07 19:36:03 +02:00
|
|
|
vte_terminal_set_cursor_shape(vte, VTE_CURSOR_SHAPE_BLOCK);
|
2012-06-07 23:56:17 +02:00
|
|
|
} else if (!strcmp(cfgstr, "IBEAM")) {
|
2012-06-07 19:36:03 +02:00
|
|
|
vte_terminal_set_cursor_shape(vte, VTE_CURSOR_SHAPE_IBEAM);
|
2012-06-07 23:56:17 +02:00
|
|
|
} else if (!strcmp(cfgstr, "UNDERLINE")) {
|
2012-06-07 19:36:03 +02:00
|
|
|
vte_terminal_set_cursor_shape(vte, VTE_CURSOR_SHAPE_UNDERLINE);
|
|
|
|
}
|
2012-06-07 23:56:17 +02:00
|
|
|
g_free(cfgstr);
|
2012-06-07 19:36:03 +02:00
|
|
|
}
|
2012-06-07 20:10:16 +02:00
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_string(config, "options", "icon_name", &cfgstr)) {
|
|
|
|
gtk_window_set_icon_name(window, cfgstr);
|
|
|
|
g_free(cfgstr);
|
2012-06-07 20:10:16 +02:00
|
|
|
}
|
2012-06-07 20:36:28 +02:00
|
|
|
|
2012-06-08 03:05:31 +02:00
|
|
|
if (get_config_double(config, "options", "transparency", &cfgdouble)) {
|
|
|
|
*transparency = cfgdouble;
|
|
|
|
}
|
|
|
|
|
2012-06-07 21:07:42 +02:00
|
|
|
GdkColor foreground, background, cursor, palette[16];
|
|
|
|
|
2012-06-08 19:26:36 +02:00
|
|
|
static const char *colors[8] = {"black", "red", "green", "yellow",
|
|
|
|
"blue", "magenta", "cyan", "white"};
|
2012-06-07 21:22:28 +02:00
|
|
|
|
2012-06-07 22:50:52 +02:00
|
|
|
bool success = true;
|
2012-06-07 21:22:28 +02:00
|
|
|
for (unsigned i = 0; i < 8; i++) {
|
2012-06-08 18:39:25 +02:00
|
|
|
GError *error = NULL;
|
2012-06-07 21:22:28 +02:00
|
|
|
gsize length;
|
2012-06-08 19:26:36 +02:00
|
|
|
gchar **pair = g_key_file_get_string_list(config, "colors", colors[i], &length, &error);
|
2012-06-07 21:22:28 +02:00
|
|
|
if (error) {
|
2012-06-07 22:50:52 +02:00
|
|
|
success = false;
|
2012-06-07 23:56:17 +02:00
|
|
|
g_error_free(error);
|
2012-06-07 21:22:28 +02:00
|
|
|
break;
|
2012-06-07 21:01:40 +02:00
|
|
|
}
|
2012-06-07 22:50:52 +02:00
|
|
|
if ((length != 2 || !gdk_color_parse(pair[0], &palette[i]) ||
|
|
|
|
!gdk_color_parse(pair[1], &palette[i+8]))) {
|
|
|
|
success = false;
|
|
|
|
g_strfreev(pair);
|
|
|
|
break;
|
2012-06-07 21:22:28 +02:00
|
|
|
}
|
|
|
|
g_strfreev(pair);
|
|
|
|
}
|
|
|
|
|
2012-06-07 22:50:52 +02:00
|
|
|
if (success) {
|
2012-06-07 21:22:28 +02:00
|
|
|
vte_terminal_set_colors(vte, NULL, NULL, palette, 16);
|
2012-06-07 20:36:28 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_string(config, "colors", "foreground", &cfgstr)) {
|
|
|
|
if (gdk_color_parse(cfgstr, &foreground)) {
|
2012-06-07 21:07:42 +02:00
|
|
|
vte_terminal_set_color_foreground(vte, &foreground);
|
2012-06-07 20:43:41 +02:00
|
|
|
}
|
2012-06-07 23:56:17 +02:00
|
|
|
g_free(cfgstr);
|
2012-06-07 20:43:41 +02:00
|
|
|
}
|
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_string(config, "colors", "background", &cfgstr)) {
|
|
|
|
if (gdk_color_parse(cfgstr, &background)) {
|
2012-06-07 21:07:42 +02:00
|
|
|
vte_terminal_set_color_background(vte, &background);
|
2012-06-07 20:43:41 +02:00
|
|
|
}
|
2012-06-07 23:56:17 +02:00
|
|
|
g_free(cfgstr);
|
2012-06-07 20:43:41 +02:00
|
|
|
}
|
2012-06-07 20:39:02 +02:00
|
|
|
|
2012-06-07 23:56:17 +02:00
|
|
|
if (get_config_string(config, "colors", "cursor", &cfgstr)) {
|
|
|
|
if (gdk_color_parse(cfgstr, &cursor)) {
|
2012-06-07 21:07:42 +02:00
|
|
|
vte_terminal_set_color_cursor(vte, &cursor);
|
2012-06-07 20:39:02 +02:00
|
|
|
}
|
2012-06-07 23:56:17 +02:00
|
|
|
g_free(cfgstr);
|
2012-06-07 20:39:02 +02:00
|
|
|
}
|
2012-06-07 18:22:24 +02:00
|
|
|
}
|
2012-06-08 01:25:04 +02:00
|
|
|
g_free(path);
|
2012-06-07 18:22:24 +02:00
|
|
|
g_key_file_free(config);
|
|
|
|
}
|
|
|
|
|
2012-05-22 06:34:35 +02:00
|
|
|
int main(int argc, char **argv) {
|
|
|
|
GError *error = NULL;
|
2012-06-08 20:33:22 +02:00
|
|
|
const char *term = "vte-256color";
|
2012-05-22 06:34:35 +02:00
|
|
|
|
2012-05-31 15:25:22 +02:00
|
|
|
GOptionContext *context = g_option_context_new("[COMMAND]");
|
2012-05-31 15:22:13 +02:00
|
|
|
const gchar *role = NULL;
|
|
|
|
const GOptionEntry entries[] = {
|
|
|
|
{ "role", 'r', 0, G_OPTION_ARG_STRING, &role, "The role to use", "ROLE" },
|
|
|
|
{ NULL }
|
|
|
|
};
|
2012-05-31 11:43:18 +02:00
|
|
|
g_option_context_add_main_entries(context, entries, NULL);
|
2012-05-31 15:17:08 +02:00
|
|
|
g_option_context_add_group(context, gtk_get_option_group(TRUE));
|
2012-05-22 06:34:35 +02:00
|
|
|
|
2012-05-31 11:43:18 +02:00
|
|
|
if (!g_option_context_parse(context, &argc, &argv, &error)) {
|
2012-06-01 21:53:23 +02:00
|
|
|
g_printerr("option parsing failed: %s\n", error->message);
|
2012-05-31 11:43:18 +02:00
|
|
|
return 1;
|
|
|
|
}
|
2012-05-22 06:34:35 +02:00
|
|
|
|
2012-05-22 17:50:01 +02:00
|
|
|
GtkWidget *window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
2012-05-22 06:34:35 +02:00
|
|
|
/*gtk_window_set_default_size(GTK_WINDOW(window), 400, 400);*/
|
2012-05-30 12:54:10 +02:00
|
|
|
|
2012-05-31 11:43:18 +02:00
|
|
|
if (role) {
|
|
|
|
gtk_window_set_role(GTK_WINDOW(window), role);
|
|
|
|
}
|
|
|
|
|
2012-05-31 18:39:59 +02:00
|
|
|
GtkWidget *overlay = gtk_overlay_new();
|
2012-05-22 06:34:35 +02:00
|
|
|
GtkWidget *vte = vte_terminal_new();
|
|
|
|
|
2012-05-24 04:50:01 +02:00
|
|
|
char **command_argv;
|
|
|
|
char *default_argv[2] = {NULL, NULL};
|
|
|
|
|
|
|
|
if (argc > 1) {
|
|
|
|
command_argv = &argv[1];
|
|
|
|
} else {
|
|
|
|
default_argv[0] = vte_get_user_shell();
|
|
|
|
if (!default_argv[0]) default_argv[0] = "/bin/sh";
|
|
|
|
command_argv = default_argv;
|
|
|
|
}
|
2012-05-22 06:34:35 +02:00
|
|
|
|
2012-06-02 17:42:20 +02:00
|
|
|
VtePty *pty = vte_terminal_pty_new(VTE_TERMINAL(vte), VTE_PTY_DEFAULT, &error);
|
2012-05-22 06:34:35 +02:00
|
|
|
|
|
|
|
if (!pty) {
|
2012-06-01 21:53:23 +02:00
|
|
|
g_printerr("Failed to create pty: %s\n", error->message);
|
2012-05-22 06:34:35 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-06-08 19:19:10 +02:00
|
|
|
gboolean dynamic_title = FALSE, urgent_on_bell = FALSE, clickable_url = FALSE;
|
|
|
|
double transparency = 0.0;
|
|
|
|
load_config(GTK_WINDOW(window), VTE_TERMINAL(vte), true, &dynamic_title,
|
|
|
|
&urgent_on_bell, &clickable_url, &transparency, &term);
|
|
|
|
|
2012-05-22 06:34:35 +02:00
|
|
|
vte_terminal_set_pty_object(VTE_TERMINAL(vte), pty);
|
|
|
|
vte_pty_set_term(pty, term);
|
|
|
|
|
|
|
|
GPid ppid;
|
|
|
|
|
|
|
|
if (g_spawn_async(NULL, command_argv, NULL,
|
2012-06-02 12:13:59 +02:00
|
|
|
(GSpawnFlags)(G_SPAWN_DO_NOT_REAP_CHILD | G_SPAWN_SEARCH_PATH),
|
2012-05-22 06:34:35 +02:00
|
|
|
(GSpawnChildSetupFunc)vte_pty_child_setup, pty,
|
|
|
|
&ppid, &error)) {
|
|
|
|
vte_terminal_watch_child(VTE_TERMINAL(vte), ppid);
|
|
|
|
} else {
|
2012-06-01 21:53:23 +02:00
|
|
|
g_printerr("The new terminal's command failed to run: %s\n", error->message);
|
2012-05-22 06:34:35 +02:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2012-06-01 03:31:09 +02:00
|
|
|
GtkWidget *alignment = gtk_alignment_new(0, 0, 1, 1);
|
|
|
|
gtk_alignment_set_padding(GTK_ALIGNMENT(alignment), 5, 5, 5, 5);
|
|
|
|
gtk_overlay_add_overlay(GTK_OVERLAY(overlay), alignment);
|
2012-05-31 18:39:59 +02:00
|
|
|
|
|
|
|
GtkWidget *entry = gtk_entry_new();
|
|
|
|
gtk_widget_set_halign(entry, GTK_ALIGN_START);
|
|
|
|
gtk_widget_set_valign(entry, GTK_ALIGN_END);
|
2012-05-22 06:34:35 +02:00
|
|
|
|
2012-06-01 03:31:09 +02:00
|
|
|
gtk_container_add(GTK_CONTAINER(alignment), entry);
|
|
|
|
gtk_container_add(GTK_CONTAINER(overlay), vte);
|
|
|
|
gtk_container_add(GTK_CONTAINER(window), overlay);
|
|
|
|
|
2012-06-04 05:39:19 +02:00
|
|
|
search_panel_info info = {vte, entry, GTK_BIN(alignment), OVERLAY_HIDDEN};
|
2012-06-01 03:31:09 +02:00
|
|
|
|
|
|
|
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
g_signal_connect(vte, "child-exited", G_CALLBACK(gtk_main_quit), NULL);
|
|
|
|
g_signal_connect(vte, "key-press-event", G_CALLBACK(key_press_cb), &info);
|
2012-06-04 05:17:18 +02:00
|
|
|
g_signal_connect(entry, "key-press-event", G_CALLBACK(entry_key_press_cb), &info);
|
2012-06-01 03:31:09 +02:00
|
|
|
g_signal_connect(overlay, "get-child-position", G_CALLBACK(position_overlay_cb), NULL);
|
2012-05-22 06:34:35 +02:00
|
|
|
|
2012-06-08 03:05:31 +02:00
|
|
|
if (transparency > 0.0) {
|
|
|
|
GdkScreen *screen = gtk_widget_get_screen(window);
|
|
|
|
GdkVisual *visual = gdk_screen_get_rgba_visual(screen);
|
|
|
|
if (!visual) {
|
|
|
|
visual = gdk_screen_get_system_visual(screen);
|
|
|
|
}
|
|
|
|
gtk_widget_set_visual(window, visual);
|
|
|
|
vte_terminal_set_background_saturation(VTE_TERMINAL(vte), transparency);
|
|
|
|
vte_terminal_set_opacity(VTE_TERMINAL(vte), (guint16)(0xffff * (1 - transparency)));
|
2012-05-31 11:32:51 +02:00
|
|
|
}
|
2012-05-24 08:51:40 +02:00
|
|
|
|
2012-06-07 20:15:31 +02:00
|
|
|
if (clickable_url) {
|
|
|
|
int tmp = vte_terminal_match_add_gregex(VTE_TERMINAL(vte),
|
|
|
|
g_regex_new(url_regex,
|
|
|
|
G_REGEX_CASELESS,
|
|
|
|
G_REGEX_MATCH_NOTEMPTY,
|
|
|
|
NULL),
|
|
|
|
(GRegexMatchFlags)0);
|
|
|
|
vte_terminal_match_set_cursor_type(VTE_TERMINAL(vte), tmp, GDK_HAND2);
|
|
|
|
g_signal_connect(vte, "button-press-event", G_CALLBACK(button_press_cb), NULL);
|
|
|
|
}
|
2012-05-24 05:41:55 +02:00
|
|
|
|
2012-06-07 19:54:15 +02:00
|
|
|
if (urgent_on_bell) {
|
|
|
|
g_signal_connect_swapped(vte, "beep", G_CALLBACK(beep_handler), window);
|
|
|
|
g_signal_connect(window, "focus-in-event", G_CALLBACK(focus_in_handler), NULL);
|
|
|
|
}
|
2012-05-22 13:47:51 +02:00
|
|
|
|
2012-06-07 19:54:15 +02:00
|
|
|
if (dynamic_title) {
|
|
|
|
window_title_cb(VTE_TERMINAL(vte), GTK_WINDOW(window));
|
|
|
|
g_signal_connect(vte, "window-title-changed", G_CALLBACK(window_title_cb), window);
|
|
|
|
}
|
2012-05-22 14:22:31 +02:00
|
|
|
|
2012-05-22 17:50:01 +02:00
|
|
|
gtk_widget_grab_focus(vte);
|
2012-05-22 06:34:35 +02:00
|
|
|
gtk_widget_show_all(window);
|
2012-06-01 03:31:09 +02:00
|
|
|
gtk_widget_hide(alignment);
|
2012-05-22 06:34:35 +02:00
|
|
|
gtk_main();
|
|
|
|
return 0;
|
|
|
|
}
|
2012-06-08 18:56:46 +02:00
|
|
|
|
|
|
|
// vim: et:sts=4:sw=4:cino=(0
|