Merge pull request #328 from ixjlyons/icon-switch

Add command line switch to set icon.
This commit is contained in:
jelle van der Waa 2016-05-06 21:20:55 +02:00
commit e7a8cdba54
2 changed files with 21 additions and 11 deletions

View File

@ -25,6 +25,8 @@ titles.
Tell termite to change to \fIDIRECTORY\fP when launching.
.IP "\fB\-\-geometry\fR\fB=\fR\fIGEOMETRY\fR"
Override the window geometry in pixels.
.IP "\fB\-\-icon\fR\f8=\fR\fIICON\fR"
Override the window icon name.
.IP "\fB\-\-hold\fR"
Keep termite open after the child process exits.
.IP "\fB\-\-display\fR\fB=\fR\fIDISPLAY\fR"

View File

@ -158,9 +158,9 @@ static void overlay_show(search_panel_info *info, overlay_mode mode, VteTerminal
static void get_vte_padding(VteTerminal *vte, int *left, int *top, int *right, int *bottom);
static char *check_match(VteTerminal *vte, GdkEventButton *event);
static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
char **geometry);
char **geometry, char **icon);
static void set_config(GtkWindow *window, VteTerminal *vte, config_info *info,
char **geometry, GKeyFile *config);
char **geometry, char **icon, GKeyFile *config);
static long first_row(VteTerminal *vte);
static std::function<void ()> reload_config;
@ -1324,7 +1324,7 @@ static void load_theme(GtkWindow *window, VteTerminal *vte, GKeyFile *config, hi
}
static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
char **geometry) {
char **geometry, char **icon) {
const std::string default_path = "/termite/config";
GKeyFile *config = g_key_file_new();
@ -1349,13 +1349,13 @@ static void load_config(GtkWindow *window, VteTerminal *vte, config_info *info,
}
if (loaded) {
set_config(window, vte, info, geometry, config);
set_config(window, vte, info, geometry, icon, config);
}
g_key_file_free(config);
}
static void set_config(GtkWindow *window, VteTerminal *vte, config_info *info,
char **geometry, GKeyFile *config) {
char **geometry, char **icon, GKeyFile *config) {
if (geometry) {
if (auto s = get_config_string(config, "options", "geometry")) {
*geometry = *s;
@ -1442,9 +1442,10 @@ static void set_config(GtkWindow *window, VteTerminal *vte, config_info *info,
g_free(*s);
}
if (auto s = get_config_string(config, "options", "icon_name")) {
gtk_window_set_icon_name(window, *s);
g_free(*s);
if (icon) {
if (auto s = get_config_string(config, "options", "icon_name")) {
*icon = *s;
}
}
if (info->size_hints) {
@ -1492,7 +1493,7 @@ int main(int argc, char **argv) {
GOptionContext *context = g_option_context_new(nullptr);
char *role = nullptr, *geometry = nullptr, *execute = nullptr, *config_file = nullptr;
char *title = nullptr;
char *title = nullptr, *icon = nullptr;
const GOptionEntry entries[] = {
{"version", 'v', 0, G_OPTION_ARG_NONE, &version, "Version info", nullptr},
{"exec", 'e', 0, G_OPTION_ARG_STRING, &execute, "Command to execute", "COMMAND"},
@ -1502,6 +1503,7 @@ int main(int argc, char **argv) {
{"geometry", 0, 0, G_OPTION_ARG_STRING, &geometry, "Window geometry", "GEOMETRY"},
{"hold", 0, 0, G_OPTION_ARG_NONE, &hold, "Remain open after child process exits", nullptr},
{"config", 'c', 0, G_OPTION_ARG_STRING, &config_file, "Path of config file", "CONFIG"},
{"icon", 'i', 0, G_OPTION_ARG_STRING, &icon, "Icon", "ICON"},
{nullptr, 0, 0, G_OPTION_ARG_NONE, nullptr, nullptr, nullptr}
};
g_option_context_add_main_entries(context, entries, nullptr);
@ -1571,10 +1573,11 @@ int main(int argc, char **argv) {
gtk_window_fullscreen
};
load_config(GTK_WINDOW(window), vte, &info.config, geometry ? nullptr : &geometry);
load_config(GTK_WINDOW(window), vte, &info.config, geometry ? nullptr : &geometry,
icon ? nullptr : &icon);
reload_config = [&]{
load_config(GTK_WINDOW(window), vte, &info.config, nullptr);
load_config(GTK_WINDOW(window), vte, &info.config, nullptr, nullptr);
};
signal(SIGUSR1, [](int){ reload_config(); });
@ -1641,6 +1644,11 @@ int main(int argc, char **argv) {
g_free(geometry);
}
if (icon) {
gtk_window_set_icon_name(GTK_WINDOW(window), icon);
g_free(icon);
}
gtk_widget_grab_focus(vte_widget);
gtk_widget_show_all(window);
gtk_widget_hide(info.panel.entry);