diff options
| author | Victor Kareh <[email protected]> | 2026-04-10 14:27:15 -0400 |
|---|---|---|
| committer | Victor Kareh <[email protected]> | 2026-04-10 14:31:22 -0400 |
| commit | f739b69918dd70279f1ba8a834ea8402a3e77c8a (patch) | |
| tree | fe2f19ccfc040d30fb1771b4e9134420a6843306 | |
| parent | 82c29555af291daf6504bdd57be8502be38282d3 (diff) | |
| download | mate-terminal-profile-icons.tar.bz2 mate-terminal-profile-icons.tar.xz | |
terminal-profile: reintroduce per-profile window iconsprofile-icons
Wire up the existing but unused "icon" GSettings key in the profile
schema so that each profile can specify a window icon. Also adds
a profile option with a file chooser.
When switching tabs, the window icon updates to match the active tab's
profile icon. Icons set via the --icon CLI option take precedence over
profile icons for the lifetime of the window.
Fixes #62
| -rw-r--r-- | src/profile-editor.c | 77 | ||||
| -rw-r--r-- | src/profile-preferences.ui | 56 | ||||
| -rw-r--r-- | src/terminal-app.c | 2 | ||||
| -rw-r--r-- | src/terminal-profile.c | 4 | ||||
| -rw-r--r-- | src/terminal-profile.h | 1 | ||||
| -rw-r--r-- | src/terminal-screen.c | 3 | ||||
| -rw-r--r-- | src/terminal-window.c | 41 | ||||
| -rw-r--r-- | src/terminal-window.h | 7 |
8 files changed, 182 insertions, 9 deletions
diff --git a/src/profile-editor.c b/src/profile-editor.c index f4959db..188ccdb 100644 --- a/src/profile-editor.c +++ b/src/profile-editor.c @@ -585,6 +585,77 @@ editor_response_cb (GtkWidget *editor, } static void +icon_browse_button_clicked_cb (GtkWidget *button, + GtkWidget *entry) +{ + GtkWidget *dialog; + GtkFileFilter *filter; + + dialog = gtk_file_chooser_dialog_new (_("Choose A Profile Icon"), + GTK_WINDOW (gtk_widget_get_toplevel (button)), + GTK_FILE_CHOOSER_ACTION_OPEN, + _("_Cancel"), GTK_RESPONSE_CANCEL, + _("_Open"), GTK_RESPONSE_ACCEPT, + NULL); + + filter = gtk_file_filter_new (); + gtk_file_filter_add_pixbuf_formats (filter); + gtk_file_filter_set_name (filter, _("Images")); + gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter); + + gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (dialog), TRUE); + + /* Add standard icon folders as shortcots. + * This resolves to something like /usr/share/icons in the file chooser sidebar. */ + gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), + TERM_DATADIR "/icons", NULL); + gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (dialog), + TERM_DATADIR "/pixmaps", NULL); + + /* Pre-select the current icon file, resolving theme names via the icon theme */ + const char *current = gtk_entry_get_text (GTK_ENTRY (entry)); + if (current && current[0] != '\0') + { + if (g_path_is_absolute (current)) + { + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), current); + } + else + { + GtkIconTheme *icon_theme; + GtkIconInfo *info; + + icon_theme = gtk_icon_theme_get_for_screen (gtk_widget_get_screen (button)); + info = gtk_icon_theme_lookup_icon (icon_theme, current, 48, 0); + if (info) + { + gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), + gtk_icon_info_get_filename (info)); + g_object_unref (info); + } + } + } + else + { + /* Use /usr/share/icons as the initial folder */ + gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), + TERM_DATADIR "/icons"); + } + + if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT) + { + char *filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog)); + if (filename) + { + gtk_entry_set_text (GTK_ENTRY (entry), filename); + g_free (filename); + } + } + + gtk_widget_destroy (dialog); +} + +static void setup_background_filechooser (GtkWidget *filechooser, TerminalProfile *profile) { @@ -842,6 +913,11 @@ terminal_profile_edit (TerminalProfile *profile, g_signal_connect (w, "changed", G_CALLBACK (visible_name_entry_changed_cb), editor); + w = GTK_WIDGET (gtk_builder_get_object (builder, "profile-icon-browse-button")); + g_signal_connect (w, "clicked", + G_CALLBACK (icon_browse_button_clicked_cb), + gtk_builder_get_object (builder, "profile-icon-entry")); + g_signal_connect (gtk_builder_get_object (builder, "reset-compat-defaults-button"), "clicked", G_CALLBACK (reset_compat_defaults_cb), @@ -868,6 +944,7 @@ terminal_profile_edit (TerminalProfile *profile, CONNECT ("foreground-colorpicker", TERMINAL_PROFILE_FOREGROUND_COLOR); CONNECT ("image-radiobutton", TERMINAL_PROFILE_BACKGROUND_TYPE); CONNECT ("login-shell-checkbutton", TERMINAL_PROFILE_LOGIN_SHELL); + CONNECT ("profile-icon-entry", TERMINAL_PROFILE_ICON); CONNECT ("profile-name-entry", TERMINAL_PROFILE_VISIBLE_NAME); CONNECT ("scrollback-lines-spinbutton", TERMINAL_PROFILE_SCROLLBACK_LINES); CONNECT ("scrollback-unlimited-checkbutton", TERMINAL_PROFILE_SCROLLBACK_UNLIMITED); diff --git a/src/profile-preferences.ui b/src/profile-preferences.ui index e64b9f9..281a78a 100644 --- a/src/profile-preferences.ui +++ b/src/profile-preferences.ui @@ -352,6 +352,60 @@ Author: Wolfgang Ulbrich </packing> </child> <child> + <object class="GtkBox" id="hbox-profile-icon"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="spacing">12</property> + <child> + <object class="GtkLabel" id="profile-icon-label"> + <property name="visible">True</property> + <property name="can-focus">False</property> + <property name="halign">start</property> + <property name="valign">center</property> + <property name="label" translatable="yes">Profile _icon:</property> + <property name="use-underline">True</property> + <property name="justify">center</property> + <property name="mnemonic-widget">profile-icon-entry</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">0</property> + </packing> + </child> + <child> + <object class="GtkEntry" id="profile-icon-entry"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="placeholder-text" translatable="yes">Icon name or file path</property> + </object> + <packing> + <property name="expand">True</property> + <property name="fill">True</property> + <property name="position">1</property> + </packing> + </child> + <child> + <object class="GtkButton" id="profile-icon-browse-button"> + <property name="visible">True</property> + <property name="can-focus">True</property> + <property name="label" translatable="yes">_Browse…</property> + <property name="use-underline">True</property> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">2</property> + </packing> + </child> + </object> + <packing> + <property name="expand">False</property> + <property name="fill">False</property> + <property name="position">1</property> + </packing> + </child> + <child> <object class="GtkCheckButton" id="system-font-checkbutton"> <property name="label" translatable="yes">_Use the system fixed width font</property> <property name="visible">True</property> @@ -364,7 +418,7 @@ Author: Wolfgang Ulbrich <packing> <property name="expand">False</property> <property name="fill">False</property> - <property name="position">1</property> + <property name="position">2</property> </packing> </child> <child> diff --git a/src/terminal-app.c b/src/terminal-app.c index 831f42f..ca99eb2 100644 --- a/src/terminal-app.c +++ b/src/terminal-app.c @@ -1798,7 +1798,7 @@ terminal_app_handle_options (TerminalApp *app, gtk_window_set_role (GTK_WINDOW (window), iw->role); if (iw->icon) - terminal_window_set_icon (window, iw->icon); + terminal_window_set_icon_from_cli (window, iw->icon); if (iw->force_menubar_state) terminal_window_set_menubar_visible (window, iw->menubar_state); diff --git a/src/terminal-profile.c b/src/terminal-profile.c index f789f66..ed6d1b8 100644 --- a/src/terminal-profile.c +++ b/src/terminal-profile.c @@ -65,6 +65,7 @@ enum PROP_EXIT_ACTION, PROP_FONT, PROP_FOREGROUND_COLOR, + PROP_ICON, PROP_LOGIN_SHELL, PROP_NAME, PROP_PALETTE, @@ -107,6 +108,7 @@ enum #define KEY_EXIT_ACTION "exit-action" #define KEY_FONT "font" #define KEY_FOREGROUND_COLOR "foreground-color" +#define KEY_ICON "icon" #define KEY_LOGIN_SHELL "login-shell" #define KEY_PALETTE "palette" #define KEY_SCROLL_BACKGROUND "scroll-background" @@ -146,6 +148,7 @@ enum #define DEFAULT_EXIT_ACTION (TERMINAL_EXIT_CLOSE) #define DEFAULT_FONT ("Monospace 12") #define DEFAULT_FOREGROUND_COLOR ("#000000") +#define DEFAULT_ICON ("") #define DEFAULT_LOGIN_SHELL (FALSE) #define DEFAULT_NAME (NULL) #define DEFAULT_PALETTE (terminal_palettes[TERMINAL_PALETTE_TANGO]) @@ -1342,6 +1345,7 @@ terminal_profile_class_init (TerminalProfileClass *klass) TERMINAL_PROFILE_PROPERTY_STRING (BACKGROUND_IMAGE_FILE, DEFAULT_BACKGROUND_IMAGE_FILE, KEY_BACKGROUND_IMAGE_FILE); TERMINAL_PROFILE_PROPERTY_STRING (CUSTOM_COMMAND, DEFAULT_CUSTOM_COMMAND, KEY_CUSTOM_COMMAND); + TERMINAL_PROFILE_PROPERTY_STRING (ICON, DEFAULT_ICON, KEY_ICON); TERMINAL_PROFILE_PROPERTY_STRING (TITLE, _(DEFAULT_TITLE), KEY_TITLE); TERMINAL_PROFILE_PROPERTY_STRING (VISIBLE_NAME, _(DEFAULT_VISIBLE_NAME), KEY_VISIBLE_NAME); TERMINAL_PROFILE_PROPERTY_STRING (WORD_CHARS, DEFAULT_WORD_CHARS, KEY_WORD_CHARS); diff --git a/src/terminal-profile.h b/src/terminal-profile.h index 5ce6ece..de00cb3 100644 --- a/src/terminal-profile.h +++ b/src/terminal-profile.h @@ -86,6 +86,7 @@ typedef enum #define TERMINAL_PROFILE_EXIT_ACTION "exit-action" #define TERMINAL_PROFILE_FONT "font" #define TERMINAL_PROFILE_FOREGROUND_COLOR "foreground-color" +#define TERMINAL_PROFILE_ICON "icon" #define TERMINAL_PROFILE_LOGIN_SHELL "login-shell" #define TERMINAL_PROFILE_NAME "name" #define TERMINAL_PROFILE_PALETTE "palette" diff --git a/src/terminal-screen.c b/src/terminal-screen.c index dd713d9..d9a008c 100644 --- a/src/terminal-screen.c +++ b/src/terminal-screen.c @@ -959,6 +959,9 @@ terminal_screen_profile_notify_cb (TerminalProfile *profile, * update terminal window config * with the flag of copy selection to clipboard or not. */ terminal_window_update_copy_selection(screen, window); + + if (!prop_name || prop_name == I_(TERMINAL_PROFILE_ICON)) + terminal_window_update_icon (window); } if (!prop_name || prop_name == I_(TERMINAL_PROFILE_SCROLLBAR_POSITION)) diff --git a/src/terminal-window.c b/src/terminal-window.c index 75e5fd8..757a543 100644 --- a/src/terminal-window.c +++ b/src/terminal-window.c @@ -2584,6 +2584,7 @@ profile_set_callback (TerminalScreen *screen, return; terminal_window_update_set_profile_menu_active_profile (window); + terminal_window_update_icon (window); } static void @@ -2844,11 +2845,6 @@ void terminal_window_set_icon (TerminalWindow *window, const char *icon) { - TerminalWindowPrivate *priv = window->priv; - - g_free (priv->icon); - priv->icon = g_strdup (icon); - if (icon == NULL || icon[0] == '\0') return; @@ -2868,6 +2864,40 @@ terminal_window_set_icon (TerminalWindow *window, } } +void +terminal_window_set_icon_from_cli (TerminalWindow *window, + const char *icon) +{ + TerminalWindowPrivate *priv = window->priv; + + g_free (priv->icon); + priv->icon = g_strdup (icon); + + terminal_window_set_icon (window, icon); +} + +void +terminal_window_update_icon (TerminalWindow *window) +{ + TerminalWindowPrivate *priv = window->priv; + TerminalProfile *profile; + const char *icon; + + /* The --icon flag takes precedence over the profile icon */ + if (priv->icon != NULL && priv->icon[0] != '\0') + return; + + if (priv->active_screen == NULL || + !(profile = terminal_screen_get_profile (priv->active_screen))) + return; + + icon = terminal_profile_get_property_string (profile, TERMINAL_PROFILE_ICON); + if (icon != NULL && icon[0] != '\0') + terminal_window_set_icon (window, icon); + else + gtk_window_set_icon_name (GTK_WINDOW (window), MATE_TERMINAL_ICON_NAME); +} + GtkWidget * terminal_window_get_notebook (TerminalWindow *window) { @@ -3254,6 +3284,7 @@ notebook_page_selected_callback (GtkWidget *notebook, sync_screen_icon_title_set (screen, NULL, window); sync_screen_icon_title (screen, NULL, window); sync_screen_title (screen, NULL, window); + terminal_window_update_icon (window); /* set size of window to current grid size */ _terminal_debug_print (TERMINAL_DEBUG_GEOMETRY, diff --git a/src/terminal-window.h b/src/terminal-window.h index 86b8e28..4ffe2b9 100644 --- a/src/terminal-window.h +++ b/src/terminal-window.h @@ -78,8 +78,11 @@ void terminal_window_set_menubar_visible (TerminalWindow *window, gboolean setting); gboolean terminal_window_get_menubar_visible (TerminalWindow *window); -void terminal_window_set_icon (TerminalWindow *window, - const char *icon); +void terminal_window_set_icon (TerminalWindow *window, + const char *icon); +void terminal_window_set_icon_from_cli (TerminalWindow *window, + const char *icon); +void terminal_window_update_icon (TerminalWindow *window); void terminal_window_switch_screen (TerminalWindow *window, TerminalScreen *screen); |
