Cloning main window to multiple windows

What is the simplest way to clone a main (GTK) window onto multiple other windows?
In my application I need to show the same UI on all connected monitors. There is no need to interact with the other windows. They can simply show an image identical to the main window.
Due to application limitations I cannot use the OS clone to replicate one of the monitors to all the others, so I am trying to create the UI on one window and then open additional windows (1 for each monitor) and “copy” the image created on the main monitor to all the other monitors

1 Like

A rather crude way of doing that would be to use gtk_offscreen_window ( Gtk.OffscreenWindow – gtk+-3.0 ), and manually paint the pixels in the other windows.

This is a terrible idea, please don’t ever suggest it again. :sweat_smile:

You should write your application in such a way that the UI is just a reflection of some state object; then you could create multiple windows showing the same UI starting from the same state object. See the MVC pattern.

There is nothing inside GTK that will let you “clone” a window without modifying the application itself.

In GTK4, you can use WidgetPaintable to draw the main widget from one window to another:

  GtkWidget *window1 = gtk_application_window_new (app);
  GtkWidget *button = gtk_button_new_with_label ("Hello World!");
  gtk_window_set_title (GTK_WINDOW (window1), "main");
  gtk_window_set_child (GTK_WINDOW (window1), button);
  gtk_window_present (GTK_WINDOW (window1));
  GdkPaintable *paintable = gtk_widget_paintable_new (button);
  GtkWidget *window2 = gtk_application_window_new (app);
  GtkWidget *picture = gtk_picture_new_for_paintable (paintable);
  gtk_window_set_title (GTK_WINDOW (window2), "cloned");
  gtk_window_set_child (GTK_WINDOW (window2), picture);
  gtk_window_present (GTK_WINDOW (window2));

You can observe how pressing the button in the main window will change its appearance in the cloned window.

1 Like

This works perfectly. Thanks

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