Skip to content

Commit

Permalink
Statically allocate VteConfig
Browse files Browse the repository at this point in the history
In preparation of always setting up the VTE stash group, the global
VteConfig pointer is replaced by a plain global variable that does
not need to be allocated.

VteConfig is small and not loading libvte is probably a niche use case
so this change is generally beneficial by simplifying things.
  • Loading branch information
kugel- committed Apr 10, 2022
1 parent 5856e4b commit 3f45510
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 56 deletions.
13 changes: 6 additions & 7 deletions src/build.c
Expand Up @@ -861,9 +861,9 @@ static gchar *prepare_run_cmd(GeanyDocument *doc, gchar **working_dir, guint cmd
cmd_string = utils_get_locale_from_utf8(cmd_string_utf8);

#ifdef HAVE_VTE
if (vte_info.have_vte && vc->run_in_vte)
if (vte_info.have_vte && vte_config.run_in_vte)
{
if (vc->skip_run_script)
if (vte_config.skip_run_script)
{
utils_free_pointers(2, cmd_string_utf8, working_dir_utf8, NULL);
return cmd_string;
Expand Down Expand Up @@ -914,15 +914,15 @@ static void build_run_cmd(GeanyDocument *doc, guint cmdindex)
run_info[cmdindex].file_type_id = doc->file_type->id;

#ifdef HAVE_VTE
if (vte_info.have_vte && vc->run_in_vte)
if (vte_info.have_vte && vte_config.run_in_vte)
{
gchar *vte_cmd;

/* VTE expects commands in UTF-8 */
SETPTR(run_cmd, utils_get_utf8_from_locale(run_cmd));
SETPTR(working_dir, utils_get_utf8_from_locale(working_dir));

if (vc->skip_run_script)
if (vte_config.skip_run_script)
vte_cmd = g_strconcat(run_cmd, "\n", NULL);
else
vte_cmd = g_strconcat("\n/bin/sh ", run_cmd, "\n", NULL);
Expand All @@ -933,13 +933,13 @@ static void build_run_cmd(GeanyDocument *doc, guint cmdindex)
const gchar *msg = _("File not executed because the terminal may contain some input (press Ctrl+C or Enter to clear it).");
ui_set_statusbar(FALSE, "%s", msg);
geany_debug("%s", msg);
if (!vc->skip_run_script)
if (!vte_config.skip_run_script)
g_unlink(run_cmd);
}

/* show the VTE */
gtk_notebook_set_current_page(GTK_NOTEBOOK(msgwindow.notebook), MSG_VTE);
gtk_widget_grab_focus(vc->vte);
gtk_widget_grab_focus(vte_config.vte);
msgwin_show_hide(TRUE);

run_info[cmdindex].pid = 1;
Expand Down Expand Up @@ -2823,4 +2823,3 @@ gboolean build_keybinding(guint key_id)
gtk_menu_item_activate(GTK_MENU_ITEM(item));
return TRUE;
}

2 changes: 1 addition & 1 deletion src/callbacks.c
Expand Up @@ -1259,7 +1259,7 @@ void on_menu_select_all1_activate(GtkMenuItem *menuitem, gpointer user_data)
}
/* special case for Select All in the VTE widget */
#ifdef HAVE_VTE
else if (vte_info.have_vte && focusw == vc->vte)
else if (vte_info.have_vte && focusw == vte_config.vte)
{
vte_select_all();
}
Expand Down
6 changes: 3 additions & 3 deletions src/keybindings.c
Expand Up @@ -1204,7 +1204,7 @@ static gboolean check_menu_key(GeanyDocument *doc, guint keyval, guint state, gu
|| focusw == msgwindow.tree_msg
|| focusw == msgwindow.scribble
#ifdef HAVE_VTE
|| (vte_info.have_vte && focusw == vc->vte)
|| (vte_info.have_vte && focusw == vte_config.vte)
#endif
)
{
Expand All @@ -1231,12 +1231,12 @@ static gboolean check_vte(GdkModifierType state, guint keyval)
GeanyKeyGroup *group;
GtkWidget *widget;

if (gtk_window_get_focus(GTK_WINDOW(main_widgets.window)) != vc->vte)
if (gtk_window_get_focus(GTK_WINDOW(main_widgets.window)) != vte_config.vte)
return FALSE;
/* let VTE copy/paste override any user keybinding */
if (state == (GEANY_PRIMARY_MOD_MASK | GDK_SHIFT_MASK) && (keyval == GDK_KEY_c || keyval == GDK_KEY_v))
return TRUE;
if (! vc->enable_bash_keys)
if (! vte_config.enable_bash_keys)
return FALSE;
/* prevent menubar flickering: */
if (state == GDK_SHIFT_MASK && (keyval >= GDK_KEY_a && keyval <= GDK_KEY_z))
Expand Down
3 changes: 2 additions & 1 deletion src/keyfile.c
Expand Up @@ -563,6 +563,7 @@ static void save_dialog_prefs(GKeyFile *config)
g_key_file_set_boolean(config, "VTE", "load_vte", vte_info.load_vte);
if (vte_info.have_vte)
{
VteConfig *vc = &vte_config;
gchar *tmp_string;

g_key_file_set_string(config, "VTE", "font", vc->font);
Expand Down Expand Up @@ -909,6 +910,7 @@ static void load_dialog_prefs(GKeyFile *config)
vte_info.load_vte = utils_get_setting_boolean(config, "VTE", "load_vte", TRUE);
if (vte_info.load_vte && vte_info.load_vte_cmdline /* not disabled on the cmdline */)
{
VteConfig *vc = &vte_config;
StashGroup *group;
struct passwd *pw = getpwuid(getuid());
const gchar *shell = (pw != NULL) ? pw->pw_shell : "/bin/sh";
Expand All @@ -920,7 +922,6 @@ static void load_dialog_prefs(GKeyFile *config)
shell = "/bin/bash -l";
#endif

vc = g_new0(VteConfig, 1);
vte_info.dir = utils_get_setting_string(config, "VTE", "last_dir", NULL);
if ((vte_info.dir == NULL || utils_str_equal(vte_info.dir, "")) && pw != NULL)
/* last dir is not set, fallback to user's home directory */
Expand Down
2 changes: 1 addition & 1 deletion src/msgwindow.c
Expand Up @@ -1281,7 +1281,7 @@ void msgwin_switch_tab(gint tabnum, gboolean show)
case MSG_STATUS: widget = msgwindow.tree_status; break;
case MSG_MESSAGE: widget = msgwindow.tree_msg; break;
#ifdef HAVE_VTE
case MSG_VTE: widget = (vte_info.have_vte) ? vc->vte : NULL; break;
case MSG_VTE: widget = (vte_info.have_vte) ? vte_config.vte : NULL; break;
#endif
default: break;
}
Expand Down
4 changes: 4 additions & 0 deletions src/prefs.c
Expand Up @@ -759,6 +759,8 @@ static void prefs_init_dialog(void)
/* VTE settings */
if (vte_info.have_vte)
{
VteConfig *vc = &vte_config;

widget = ui_lookup_widget(ui_widgets.prefs_dialog, "font_term");
gtk_font_button_set_font_name(GTK_FONT_BUTTON(widget), vc->font);

Expand Down Expand Up @@ -1232,6 +1234,8 @@ on_prefs_dialog_response(GtkDialog *dialog, gint response, gpointer user_data)
/* VTE settings */
if (vte_info.have_vte)
{
VteConfig *vc = &vte_config;

widget = ui_lookup_widget(ui_widgets.prefs_dialog, "spin_scrollback");
gtk_spin_button_update(GTK_SPIN_BUTTON(widget));
vc->scrollback_lines = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
Expand Down

0 comments on commit 3f45510

Please sign in to comment.