Kaydet (Commit) f509afca authored tarafından Enrico Tröger's avatar Enrico Tröger

Save all VTE settings in an own VTE section in the configuration file instead of…

Save all VTE settings in an own VTE section in the configuration file instead of using an unhandy string list.
Added new settings: ignore menu bar accelerator and define the shell which is started within the VTE.
(Code not yet complete, might be buggy, GUI stuff is missing)


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@755 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst e3d8949e
2006-08-22 Enrico Tröger <enrico.troeger@uvena.de>
* src/vte.c, src/prefs.c, src/keyfile.c, src/utils.c:
Save all VTE settings in an own VTE section in the configuration
file instead of using an unhandy string list.
Added new settings: ignore menu bar accelerator and define the shell
which is started within the VTE.
(Code not yet complete, might be buggy, GUI stuff is missing)
2006-08-21 Enrico Tröger <enrico.troeger@uvena.de> 2006-08-21 Enrico Tröger <enrico.troeger@uvena.de>
* src/images.c, src/notebook.c: * src/images.c, src/notebook.c:
......
...@@ -25,6 +25,12 @@ ...@@ -25,6 +25,12 @@
#include "geany.h" #include "geany.h"
#ifdef HAVE_VTE
#include <pwd.h>
#include <sys/types.h>
#include <unistd.h>
#endif
#include "support.h" #include "support.h"
#include "keyfile.h" #include "keyfile.h"
#include "utils.h" #include "utils.h"
...@@ -109,12 +115,29 @@ void configuration_save() ...@@ -109,12 +115,29 @@ void configuration_save()
g_key_file_set_boolean(config, PACKAGE, "auto_close_xml_tags", app->pref_editor_auto_close_xml_tags); g_key_file_set_boolean(config, PACKAGE, "auto_close_xml_tags", app->pref_editor_auto_close_xml_tags);
g_key_file_set_boolean(config, PACKAGE, "auto_complete_constructs", app->pref_editor_auto_complete_constructs); g_key_file_set_boolean(config, PACKAGE, "auto_complete_constructs", app->pref_editor_auto_complete_constructs);
#ifdef HAVE_VTE #ifdef HAVE_VTE
g_key_file_set_boolean(config, PACKAGE, "load_vte", vte_info.load_vte); g_key_file_set_boolean(config, "VTE", "load_vte", vte_info.load_vte);
g_key_file_set_comment(config, PACKAGE, "terminal_settings", if (vte_info.load_vte)
_(" VTE settings: FONT;FOREGROUND;BACKGROUND;scrollback;type;scroll on keystroke;scroll on output;follow path of file"), NULL); {
g_key_file_set_string(config, PACKAGE, "terminal_settings", vte_info.terminal_settings); gchar *tmp_string;
vte_get_working_directory(); // refresh vte_info.dir
g_key_file_set_string(config, PACKAGE, "terminal_dir", vte_info.dir); g_key_file_set_string(config, "VTE", "emulation", vc->emulation);
g_key_file_set_string(config, "VTE", "font", vc->font);
g_key_file_set_boolean(config, "VTE", "scroll_on_key", vc->scroll_on_key);
g_key_file_set_boolean(config, "VTE", "scroll_on_out", vc->scroll_on_out);
g_key_file_set_boolean(config, "VTE", "ignore_menu_bar_accel", vc->ignore_menu_bar_accel);
g_key_file_set_boolean(config, "VTE", "follow_path", vc->follow_path);
g_key_file_set_integer(config, "VTE", "scrollback_lines", vc->scrollback_lines);
g_key_file_set_string(config, "VTE", "font", vc->font);
g_key_file_set_string(config, "VTE", "shell", vc->shell);
tmp_string = utils_get_hex_from_color(vc->colour_fore);
g_key_file_set_string(config, "VTE", "colour_fore", tmp_string);
g_free(tmp_string);
tmp_string = utils_get_hex_from_color(vc->colour_back);
g_key_file_set_string(config, "VTE", "colour_back", tmp_string);
g_free(tmp_string);
vte_get_working_directory(); // refresh vte_info.dir
g_key_file_set_string(config, "VTE", "last_dir", vte_info.dir);
}
#endif #endif
g_key_file_set_string(config, PACKAGE, "custom_date_format", app->custom_date_format); g_key_file_set_string(config, PACKAGE, "custom_date_format", app->custom_date_format);
g_key_file_set_string(config, PACKAGE, "editor_font", app->editor_font); g_key_file_set_string(config, PACKAGE, "editor_font", app->editor_font);
...@@ -324,9 +347,38 @@ gboolean configuration_load() ...@@ -324,9 +347,38 @@ gboolean configuration_load()
app->pref_toolbar_show_colour = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_colour", TRUE); app->pref_toolbar_show_colour = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_colour", TRUE);
app->pref_toolbar_show_fileops = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_fileops", TRUE); app->pref_toolbar_show_fileops = utils_get_setting_boolean(config, PACKAGE, "pref_toolbar_show_fileops", TRUE);
#ifdef HAVE_VTE #ifdef HAVE_VTE
vte_info.load_vte = utils_get_setting_boolean(config, PACKAGE, "load_vte", TRUE); vte_info.load_vte = utils_get_setting_boolean(config, "VTE", "load_vte", TRUE);
vte_info.terminal_settings = utils_get_setting_string(config, PACKAGE, "terminal_settings", ""); if (vte_info.load_vte)
vte_info.dir = utils_get_setting_string(config, PACKAGE, "terminal_dir", NULL); {
struct passwd *pw = getpwuid(getuid());
gchar *shell = (pw != NULL) ? pw->pw_shell : "/bin/sh";
vc = g_new0(VteConfig, 1);
vte_info.dir = utils_get_setting_string(config, "VTE", "last_dir", NULL);
if ((vte_info.dir == NULL || utils_strcmp(vte_info.dir, "")) && pw != NULL)
// last dir is not set, fallback to user's home directory
vte_info.dir = g_strdup(pw->pw_dir);
else if (vte_info.dir == NULL && pw == NULL)
// fallback to root
vte_info.dir = g_strdup("/");
vc->emulation = utils_get_setting_string(config, "VTE", "emulation", "xterm");
vc->shell = utils_get_setting_string(config, "VTE", "shell", shell);
vc->font = utils_get_setting_string(config, "VTE", "font", "Monospace 10");
vc->scroll_on_key = utils_get_setting_boolean(config, "VTE", "scroll_on_key", TRUE);
vc->scroll_on_out = utils_get_setting_boolean(config, "VTE", "scroll_on_out", TRUE);
vc->ignore_menu_bar_accel = utils_get_setting_boolean(config, "VTE", "ignore_menu_bar_accel", FALSE);
vc->follow_path = utils_get_setting_boolean(config, "VTE", "follow_path", FALSE);
vc->scrollback_lines = utils_get_setting_integer(config, "VTE", "scrollback_lines", 500);
vc->colour_fore = g_new0(GdkColor, 1);
vc->colour_back = g_new0(GdkColor, 1);
tmp_string = utils_get_setting_string(config, "VTE", "colour_fore", "#ffffff");
gdk_color_parse(tmp_string, vc->colour_fore);
g_free(tmp_string);
tmp_string = utils_get_setting_string(config, "VTE", "colour_back", "#000000");
gdk_color_parse(tmp_string, vc->colour_back);
g_free(tmp_string);
}
#endif #endif
app->pref_template_developer = utils_get_setting_string(config, PACKAGE, "pref_template_developer", g_get_real_name()); app->pref_template_developer = utils_get_setting_string(config, PACKAGE, "pref_template_developer", g_get_real_name());
app->pref_template_company = utils_get_setting_string(config, PACKAGE, "pref_template_company", ""); app->pref_template_company = utils_get_setting_string(config, PACKAGE, "pref_template_company", "");
......
...@@ -331,10 +331,10 @@ void prefs_init_dialog(void) ...@@ -331,10 +331,10 @@ void prefs_init_dialog(void)
gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font); gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);
widget = lookup_widget(app->prefs_dialog, "color_fore"); widget = lookup_widget(app->prefs_dialog, "color_fore");
gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), vc->color_fore); gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), vc->colour_fore);
widget = lookup_widget(app->prefs_dialog, "color_back"); widget = lookup_widget(app->prefs_dialog, "color_back");
gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), vc->color_back); gtk_color_button_set_color(GTK_COLOR_BUTTON(widget), vc->colour_back);
widget = lookup_widget(app->prefs_dialog, "spin_scrollback"); widget = lookup_widget(app->prefs_dialog, "spin_scrollback");
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), vc->scrollback_lines); gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), vc->scrollback_lines);
...@@ -573,8 +573,6 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat ...@@ -573,8 +573,6 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat
// VTE settings // VTE settings
if (vte_info.have_vte) if (vte_info.have_vte)
{ {
gchar *hex_color_back, *hex_color_fore;
widget = lookup_widget(app->prefs_dialog, "spin_scrollback"); widget = lookup_widget(app->prefs_dialog, "spin_scrollback");
vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
...@@ -591,18 +589,7 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat ...@@ -591,18 +589,7 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat
widget = lookup_widget(app->prefs_dialog, "check_follow_path"); widget = lookup_widget(app->prefs_dialog, "check_follow_path");
vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); vc->follow_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
g_free(vte_info.terminal_settings);
hex_color_fore = utils_get_hex_from_color(vc->color_fore);
hex_color_back = utils_get_hex_from_color(vc->color_back);
vte_info.terminal_settings = g_strdup_printf("%s;%s;%s;%d;%s;%s;%s;%s", vc->font,
hex_color_fore, hex_color_back,
vc->scrollback_lines, vc->emulation,
utils_btoa(vc->scroll_on_key), utils_btoa(vc->scroll_on_out),
utils_btoa(vc->follow_path));
vte_apply_user_settings(); vte_apply_user_settings();
g_free(hex_color_fore);
g_free(hex_color_back);
} }
#endif #endif
...@@ -657,16 +644,16 @@ void on_prefs_color_choosed(GtkColorButton *widget, gpointer user_data) ...@@ -657,16 +644,16 @@ void on_prefs_color_choosed(GtkColorButton *widget, gpointer user_data)
#ifdef HAVE_VTE #ifdef HAVE_VTE
case 2: case 2:
{ {
g_free(vc->color_fore); g_free(vc->colour_fore);
vc->color_fore = g_new0(GdkColor, 1); vc->colour_fore = g_new0(GdkColor, 1);
gtk_color_button_get_color(widget, vc->color_fore); gtk_color_button_get_color(widget, vc->colour_fore);
break; break;
} }
case 3: case 3:
{ {
g_free(vc->color_back); g_free(vc->colour_back);
vc->color_back = g_new0(GdkColor, 1); vc->colour_back = g_new0(GdkColor, 1);
gtk_color_button_get_color(widget, vc->color_back); gtk_color_button_get_color(widget, vc->colour_back);
break; break;
} }
#endif #endif
......
...@@ -1944,6 +1944,8 @@ gchar *utils_get_hex_from_color(GdkColor *color) ...@@ -1944,6 +1944,8 @@ gchar *utils_get_hex_from_color(GdkColor *color)
{ {
gchar *buffer = g_malloc0(9); gchar *buffer = g_malloc0(9);
if (color == NULL) return NULL;
g_snprintf(buffer, 8, "#%02X%02X%02X", g_snprintf(buffer, 8, "#%02X%02X%02X",
(guint) (utils_scale_round(color->red / 256, 255)), (guint) (utils_scale_round(color->red / 256, 255)),
(guint) (utils_scale_round(color->green / 256, 255)), (guint) (utils_scale_round(color->green / 256, 255)),
......
...@@ -25,8 +25,6 @@ ...@@ -25,8 +25,6 @@
#ifdef HAVE_VTE #ifdef HAVE_VTE
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#include <pwd.h>
#include <unistd.h>
#include <signal.h> #include <signal.h>
#include <string.h> #include <string.h>
...@@ -43,7 +41,7 @@ VteInfo vte_info; ...@@ -43,7 +41,7 @@ VteInfo vte_info;
extern gchar **environ; extern gchar **environ;
static pid_t pid; static pid_t pid;
static GModule *module = NULL; static GModule *module = NULL;
static struct vte_funcs *vf; static struct VteFunctions *vf;
static gboolean popup_menu_created = FALSE; static gboolean popup_menu_created = FALSE;
...@@ -54,7 +52,6 @@ static void vte_start(GtkWidget *widget); ...@@ -54,7 +52,6 @@ static void vte_start(GtkWidget *widget);
static gboolean vte_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer user_data); static gboolean vte_button_pressed(GtkWidget *widget, GdkEventButton *event, gpointer user_data);
static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data); static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer data);
static void vte_register_symbols(GModule *module); static void vte_register_symbols(GModule *module);
static void vte_get_settings(void);
static void vte_popup_menu_clicked(GtkMenuItem *menuitem, gpointer user_data); static void vte_popup_menu_clicked(GtkMenuItem *menuitem, gpointer user_data);
static GtkWidget *vte_create_popup_menu(void); static GtkWidget *vte_create_popup_menu(void);
static void vte_char_size_changed(VteTerminal *vteterminal, guint arg1, guint arg2, static void vte_char_size_changed(VteTerminal *vteterminal, guint arg1, guint arg2,
...@@ -132,8 +129,7 @@ void vte_init(void) ...@@ -132,8 +129,7 @@ void vte_init(void)
else else
{ {
vte_info.have_vte = TRUE; vte_info.have_vte = TRUE;
vf = g_new0(struct vte_funcs, 1); vf = g_new0(struct VteFunctions, 1);
vc = g_new0(struct vte_conf, 1);
vte_register_symbols(module); vte_register_symbols(module);
} }
...@@ -149,8 +145,6 @@ void vte_init(void) ...@@ -149,8 +145,6 @@ void vte_init(void)
gtk_box_pack_start(GTK_BOX(hbox), vte, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(hbox), vte, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(hbox), scrollbar, FALSE, FALSE, 0);
vte_get_settings();
vf->vte_terminal_set_size(VTE_TERMINAL(vte), 30, 1); vf->vte_terminal_set_size(VTE_TERMINAL(vte), 30, 1);
//vf->vte_terminal_set_encoding(VTE_TERMINAL(vte), "UTF-8"); //vf->vte_terminal_set_encoding(VTE_TERMINAL(vte), "UTF-8");
vf->vte_terminal_set_mouse_autohide(VTE_TERMINAL(vte), TRUE); vf->vte_terminal_set_mouse_autohide(VTE_TERMINAL(vte), TRUE);
...@@ -187,8 +181,8 @@ void vte_close(void) ...@@ -187,8 +181,8 @@ void vte_close(void)
if (popup_menu_created) gtk_widget_destroy(vc->menu); if (popup_menu_created) gtk_widget_destroy(vc->menu);
g_free(vc->font); g_free(vc->font);
g_free(vc->emulation); g_free(vc->emulation);
g_free(vc->color_back); g_free(vc->colour_back);
g_free(vc->color_fore); g_free(vc->colour_fore);
g_free(vc); g_free(vc);
g_module_close(module); g_module_close(module);
} }
...@@ -219,26 +213,11 @@ static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer dat ...@@ -219,26 +213,11 @@ static gboolean vte_keypress(GtkWidget *widget, GdkEventKey *event, gpointer dat
static void vte_start(GtkWidget *widget) static void vte_start(GtkWidget *widget)
{ {
VteTerminal *vte = VTE_TERMINAL(widget); VteTerminal *vte = VTE_TERMINAL(widget);
struct passwd *pw;
const gchar *shell;
const gchar *dir = NULL;
gchar **env; gchar **env;
pw = getpwuid(getuid());
if (pw)
{
shell = pw->pw_shell;
dir = pw->pw_dir;
}
else
{
shell = "/bin/sh";
dir = "/";
}
env = vte_get_child_environment(); env = vte_get_child_environment();
pid = vf->vte_terminal_fork_command(VTE_TERMINAL(vte), shell, NULL, env, pid = vf->vte_terminal_fork_command(VTE_TERMINAL(vte), vc->shell, NULL, env,
(vte_info.dir == NULL) ? dir : vte_info.dir, TRUE, TRUE, TRUE); vte_info.dir, TRUE, TRUE, TRUE);
g_strfreev(env); g_strfreev(env);
} }
...@@ -307,37 +286,12 @@ void vte_apply_user_settings(void) ...@@ -307,37 +286,12 @@ void vte_apply_user_settings(void)
vf->vte_terminal_set_scroll_on_output(VTE_TERMINAL(vc->vte), vc->scroll_on_out); vf->vte_terminal_set_scroll_on_output(VTE_TERMINAL(vc->vte), vc->scroll_on_out);
vf->vte_terminal_set_emulation(VTE_TERMINAL(vc->vte), vc->emulation); vf->vte_terminal_set_emulation(VTE_TERMINAL(vc->vte), vc->emulation);
vf->vte_terminal_set_font_from_string(VTE_TERMINAL(vc->vte), vc->font); vf->vte_terminal_set_font_from_string(VTE_TERMINAL(vc->vte), vc->font);
vf->vte_terminal_set_color_foreground(VTE_TERMINAL(vc->vte), vc->color_fore); vf->vte_terminal_set_color_foreground(VTE_TERMINAL(vc->vte), vc->colour_fore);
vf->vte_terminal_set_color_background(VTE_TERMINAL(vc->vte), vc->color_back); vf->vte_terminal_set_color_background(VTE_TERMINAL(vc->vte), vc->colour_back);
}
static void vte_get_settings(void) if (vc->ignore_menu_bar_accel)
{ gtk_settings_set_string_property(gtk_settings_get_default(), "gtk-menu-bar-accel",
gchar **values = g_strsplit(vte_info.terminal_settings, ";", 8); "<Shift><Control><Mod1><Mod2><Mod3><Mod4><Mod5>F10", "Geany");
if (g_strv_length(values) != 8)
{
vte_info.terminal_settings =
g_strdup_printf("Monospace 10;#FFFFFF;#000000;500;xterm;true;true;false");
values = g_strsplit(vte_info.terminal_settings, ";", 8);
}
vc->font = g_strdup(values[0]);
vc->color_fore = g_new0(GdkColor, 1);
vc->color_back = g_new0(GdkColor, 1);
gdk_color_parse(values[1], vc->color_fore);
gdk_color_parse(values[2], vc->color_back);
vc->scrollback_lines = strtod(values[3], NULL);
if ((vc->scrollback_lines < 0) || (vc->scrollback_lines > 5000)) vc->scrollback_lines = 500;
vc->emulation = g_strdup(values[4]);
vc->scroll_on_key = utils_atob(values[5]);
vc->scroll_on_out = utils_atob(values[6]);
vc->follow_path = utils_atob(values[7]);
g_strfreev(values);
} }
...@@ -488,4 +442,5 @@ gboolean vte_drag_drop(GtkWidget *widget, GdkDragContext *drag_context, gint x, ...@@ -488,4 +442,5 @@ gboolean vte_drag_drop(GtkWidget *widget, GdkDragContext *drag_context, gint x,
} }
*/ */
#endif #endif
...@@ -31,16 +31,34 @@ ...@@ -31,16 +31,34 @@
#ifdef HAVE_VTE #ifdef HAVE_VTE
typedef struct typedef struct
{ {
gboolean load_vte; gboolean load_vte;
gboolean have_vte; gboolean have_vte;
gchar *lib_vte; gchar *lib_vte;
gchar *terminal_settings;
gchar *dir; gchar *dir;
} VteInfo; } VteInfo;
extern VteInfo vte_info; extern VteInfo vte_info;
typedef struct
{
GtkWidget *vte;
GtkWidget *menu;
GtkWidget *im_submenu;
gboolean scroll_on_key;
gboolean scroll_on_out;
gboolean ignore_menu_bar_accel;
gboolean follow_path;
gint scrollback_lines;
gchar *emulation;
gchar *shell;
gchar *font;
GdkColor *colour_fore;
GdkColor *colour_back;
} VteConfig;
VteConfig *vc;
#endif #endif
...@@ -80,26 +98,9 @@ struct _VteTerminal ...@@ -80,26 +98,9 @@ struct _VteTerminal
}; };
struct vte_conf
{
GtkWidget *vte;
GtkWidget *menu;
GtkWidget *im_submenu;
gboolean scroll_on_key;
gboolean scroll_on_out;
gboolean follow_path;
gint scrollback_lines;
gchar *emulation;
gchar *font;
GdkColor *color_fore;
GdkColor *color_back;
};
struct vte_conf *vc;
/* store function pointers in a struct to avoid a strange segfault if they are stored directly /* store function pointers in a struct to avoid a strange segfault if they are stored directly
* if accessed directly, gdb says the segfault arrives at old_tab_width(prefs.c), don't ask me */ * if accessed directly, gdb says the segfault arrives at old_tab_width(prefs.c), don't ask me */
struct vte_funcs struct VteFunctions
{ {
GtkWidget* (*vte_terminal_new) (void); GtkWidget* (*vte_terminal_new) (void);
pid_t (*vte_terminal_fork_command) (VteTerminal *terminal, const char *command, char **argv, pid_t (*vte_terminal_fork_command) (VteTerminal *terminal, const char *command, char **argv,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment