user16819948
user16819948

Reputation:

Can we use libvte terminal widget on gtk4 window?

I want to use libvte on this gtk4 window. But facing issue during compile, demo script given below. Can anyone tell me whether libvte-2.91 is supported with gtk4? I'm on Ubuntu 22.04LTS

$ gcc -Wall $(pkg-config --cflags gtk4 vte-2.91) gtk4App.c -o term $(pkg-config --libs gtk4 vte-2.91)

ERROR SHOW--------------
In file included from /usr/include/vte-2.91/vte/vte.h:33,
             from gtk4App.c:2: 
/usr/include/vte-2.91/vte/vtetypebuiltins.h:27:10: fatal error: vtetypebuiltins-gtk4.h: No such file or directory
   27 | #include "vtetypebuiltins-gtk4.h"
      |          ^~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.

This is the gtk4 script-----

#include <gtk/gtk.h>
#include <vte/vte.h>
//sudo apt install libgtk-4-dev libvte-2.91-dev  
//gcc -Wall $(pkg-config --cflags gtk4 vte-2.91) gtk4App.c -o term $(pkg-config --libs gtk4 vte-2.91)

static void
activate (GtkApplication *app,
          gpointer        user_data)
{
  GtkWidget *window;
  GtkWidget *terminal;

  window = gtk_application_window_new (app);
  gtk_window_set_title (GTK_WINDOW (window), "Window");
  gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);

  GtkWidget *grid = gtk_grid_new ();
  gtk_window_set_child ((GtkWindow    *)window, grid);
  gtk_widget_set_vexpand(grid, TRUE);
  gtk_widget_set_hexpand(grid, TRUE);

    GtkWidget *scrollview1;
    scrollview1 = gtk_scrolled_window_new();

    gtk_grid_attach(GTK_GRID(grid), scrollview1, 0, 0, 1, 1);

    terminal = vte_terminal_new();
    gtk_window_set_child ((GtkWindow    *)scrollview1, terminal);

  gtk_widget_show (window);
}

int
main (int    argc,
      char **argv)
{
  GtkApplication *app;
  int status;

  app = gtk_application_new ("org.gtk.example", G_APPLICATION_FLAGS_NONE);
  g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
  status = g_application_run (G_APPLICATION (app), argc, argv);
  g_object_unref (app);

  return status;
}

I know libvte working fine with gtk+3.0,,but i want to use it on gtk4.

Upvotes: 1

Views: 1104

Answers (1)

NoDakker
NoDakker

Reputation: 4816

I did get your sample code to compile and executed on my Ubuntu 22.04 virtual machine. Following were the steps I performed to make that work.

First, rather than installing the "libvte-2.91-dev" library from the package manager, I went out to the Github repository for the "vte" library (https://github.com/GNOME/vte) and cloned the code. Prior to running the meson and ninja build commands as noted in the installation steps, I revised the "meson_options.txt" file to enable the building of "GTK4" support for the "vte" libraries, changing the "value" attribute from "false" to "true".

option(
    'gtk4',
    type: 'boolean',
    value: true,
    description: 'Enable GTK+ 4.0 widget',
)

I then stepped through the build directions noted from the Github repository.

cd vte
meson _build
ninja -C _build
sudo ninja -C _build install

I added the "sudo" command in front of the "ninja -C _build install". Otherwise, I believe the system will still prompt for a password.

Having performed these steps, not only was the "vte" library in place for GTK3 support, but the "vte" library for GTK4 support was built as well. So that the libraries were visible for program execution, I ran the "ldconfig" command which updated the library search path.

sudo ldconfig

I then copied your sample code to a text file, naming it "gtk4App.c" and then ran the "gcc" compiler with the following revision to your parameter values.

gcc -Wall $(pkg-config --cflags gtk4 vte-2.91-gtk4) gtk4App.c -o term $(pkg-config --libs gtk4 vte-2.91-gtk4)

Library "libvte-2.91-gtk4" sets adjacent to library "libvte-2.91".

After compiling the sample program, I launched the program and got a sample terminal.

Sample GTK4 vte terminal

The last item to note that when I ran the meson build command, there was a warning noting that the GTK4 support was experimental. So please bear that in mind.

I hope that clarifies everything for you.

Regards.

Upvotes: 1

Related Questions