0

I'm trying to implement an icon for the following program written in C I found online. I looked everywhere but couldn't find a proper answer.

#include <vte/vte.h>

static void
child_ready(VteTerminal *terminal, GPid pid, GError *error, gpointer user_data)
{
    if (!terminal) return;
    if (pid == -1) gtk_main_quit();
}

int
main(int argc, char *argv[])
{
    GtkWidget *window, *terminal;

    /* Initialise GTK, the window and the terminal */
    gtk_init(&argc, &argv);
    terminal = vte_terminal_new();
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "myterm");

    /* Start a new shell */
    gchar **envp = g_get_environ();
    gchar **command = (gchar *[]){g_strdup(g_environ_getenv(envp, "SHELL")), NULL };
    g_strfreev(envp);
    vte_terminal_spawn_async(VTE_TERMINAL(terminal),
        VTE_PTY_DEFAULT,
        NULL,         /* working directory  */
        command,      /* command */
        NULL,         /* environment */
        0,            /* spawn flags */
        NULL, NULL,   /* child setup */
        NULL,         /* child pid */
        -1,           /* timeout */
        NULL,         /* cancellable */
        child_ready,  /* callback */
        NULL);        /* user_data */

    /* Connect some signals */
    g_signal_connect(window, "delete-event", gtk_main_quit, NULL);
    g_signal_connect(terminal, "child-exited", gtk_main_quit, NULL);

    vte_terminal_set_scrollback_lines(VTE_TERMINAL(terminal), 0);
    vte_terminal_set_scroll_on_output(VTE_TERMINAL(terminal), FALSE);
    vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(terminal), TRUE);
    vte_terminal_set_mouse_autohide(VTE_TERMINAL(terminal), TRUE);
    /* Put widgets together and run the main loop */
    gtk_container_add(GTK_CONTAINER(window), terminal);
    gtk_widget_show_all(window);
    gtk_main();
}

I'm trying to implement an icon for the following program written in C I found online. I looked everywhere but couldn't find a proper answer.

1 Answers1

1

You need to set the icon on the window like this:

void gtk_window_set_icon (
  GtkWindow* window,
  GdkPixbuf* icon
)
samann
  • 73
  • 5
  • I did this `gtk_window_set_icon(GTK_WINDOW(window), "/home/Desktop/terminal-59.png");` but I'm getting the following error `expected ‘GdkPixbuf *’` . What do I put there? –  Mar 22 '23 at 11:09
  • @NicholasWinberg you need to read the image file into a PixBuf first. See the [documentation](https://docs.gtk.org/gdk-pixbuf/class.Pixbuf.html) for ways to get thePixBuf. Probably [gdk_pixbuf_new_from_file](https://docs.gtk.org/gdk-pixbuf/ctor.Pixbuf.new_from_file.html) would be a good starting point. – Gerhardh Mar 22 '23 at 11:14
  • @Gerhardh It works only when I'm inside the same directory with the icon. Not when I'm outside the dir. –  Mar 22 '23 at 15:35
  • @NicholasWinberg do you specify an absolute or a relative path to your icon? – Gerhardh Mar 22 '23 at 16:23
  • @Gerhardh I tried both and they work on my machine. But let's say I want to use it on Ubuntu for example. Then the path would be different. –  Mar 22 '23 at 16:34