qt5base-lts/tests/manual/xembed/gtk-container/gtk-container.cpp
Liang Qi aef55501bc tests: replace gtk-embedder.py with a gtk3 app
All linux CI machines have gtk3 installed. And Python GTK things
are too complicate to setup.

Pick-to: 6.4 6.3 6.2 5.15
Change-Id: I3c0d967f61aebea508784df79569b9d0064f66e2
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
2022-08-06 01:24:41 +02:00

44 lines
1.3 KiB
C++

// Copyright (C) 2022 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include <gtk/gtk.h>
#include <gtk/gtkx.h>
gchar *cmd;
void launch_app(GtkButton */* btn */, guint32 *id)
{
gchar *command = g_strdup_printf("%s %u", cmd, *id);
g_spawn_command_line_async(command, NULL);
}
gint main(gint argc, gchar **argv)
{
if (argc <=1 || argc > 2) {
g_print("No client application defined.\n");
return 0;
}
cmd = g_strdup_printf("%s", argv[1]);
gtk_init(&argc, &argv);
GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
GtkWidget *sock = gtk_socket_new();
GtkWidget *btn = gtk_button_new_with_label("Hello, World!");
g_signal_connect(sock, "plug-removed", gtk_main_quit, NULL);
g_signal_connect(win, "delete-event", gtk_main_quit, NULL);
gtk_widget_set_size_request(sock, 200, 200);
gtk_box_pack_start(GTK_BOX(vbox), btn, FALSE, FALSE, 0);
gtk_box_pack_start(GTK_BOX(vbox), sock, TRUE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(win), vbox);
gtk_widget_show_all(win);
guint32 id = gtk_socket_get_id(GTK_SOCKET(sock));
g_signal_connect(btn, "clicked", G_CALLBACK(launch_app), &id);
gtk_main();
return 0;
}