I recognize that the RPI Zero is a very weak computer by modern standards, but is there anything that I can do to make the GTK4 apps I write startup faster on it? The GTK4 example on the website takes about 14 seconds to open a window on it
#include <gtk/gtk.h>
static void
activate (GtkApplication* app,
gpointer user_data)
{
GtkWidget *window;
window = gtk_application_window_new (app);
gtk_window_set_title (GTK_WINDOW (window), "Window");
gtk_window_set_default_size (GTK_WINDOW (window), 200, 200);
gtk_window_present (GTK_WINDOW (window));
}
int
main (int argc,
char **argv)
{
GtkApplication *app;
int status;
app = gtk_application_new ("org.gtk.example", G_APPLICATION_DEFAULT_FLAGS);
g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
status = g_application_run (G_APPLICATION (app), argc, argv);
g_object_unref (app);
return status;
}
For comparison (and in no way apples to apples), an SDL2 program takes ~6 seconds, to open up a blank window, a comparable python tkinter app takes 3, and just working directly with X11 is instant.
#include <X11/Xlib.h>
#include <stdio.h>
#include <stdlib.h> // For exit function
int main() {
Display *display;
Window window;
XEvent event;
int screen;
// Open connection to the X server
display = XOpenDisplay(NULL);
if (display == NULL) {
fprintf(stderr, "Cannot open display\n");
exit(1);
}
screen = DefaultScreen(display);
window = XCreateSimpleWindow(display, RootWindow(display, screen), 10, 10, 800, 600, 1,
BlackPixel(display, screen), WhitePixel(display, screen));
XSelectInput(display, window, ExposureMask | KeyPressMask);
XMapWindow(display, window);
while (1) {
XNextEvent(display, &event);
// Break out of the loop if the user presses any key
if (event.type == KeyPress)
break;
}
XCloseDisplay(display);
return 0;
}
I know GTK is doing a lot for me, so I don’t expect things to be instant, and it’s amazing that it even works on an RPI Zero to begin with. But I just want to make sure I didn’t miss anything when looking to see if things could be made faster.