Windowless application in gtk4

how can i create an application without windows in gtk 4? my program only works with the clipboard. in gtk 3 i used gtk_init and gtk_main_loop. but in gtk 4 the windowless application is closed immediately. or how can I use gdk without gtk since I only need the clipboard.

I think calling g_application_hold() should keep yourGtkApplication alive. You can call g_application_release() when you want your application to exit.

Aside from using g_application_hold() and g_application_release(), you can also still use gtk_init() to initialise GTK, and then use a GMainLoop to spin the loop, like this:

main (int argc, char *argv[])
  gtk_init ();

  GMainLoop *loop = g_main_loop_new (NULL, FALSE);

  // ... set up your program here...
  // pass the "loop" variable to callbacks that can terminate the program
  // and use g_main_loop_quit() when you need to stop the main loop

  g_main_loop_run (loop);

  return EXIT_SUCCESS;

I don’t think using the clipboard without having the window focused will ever work on Wayland. It’s something you can only do with Xorg.

I think the described use case, even if not a majority
use case, is a good one. For instance on linux I use
xclip, but gtk also provides copy/paste functionality
on windows as-is, which I think can be super-useful.
So who knows - wayland may find some use case there
for windowless applications too, even if it is not the
main use case, via extensions or something. The more
closely mapped users can switch from xorg to wayland
the better for transitioning too!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.