static void channel_new(SpiceSession *s, SpiceChannel *c, gpointer *data);
/* 创建一个 Spice session */
spice_session = spice_session_new();
/* 设置 Spice 的地址和端口 */
g_object_set(spice_session, "host", host, NULL);
g_object_set(spice_session, "port", port, NULL);
/* 设置当 Spice Channel 建立之后的 callback, 也就是说这个时候可以
* 获取 Spice Gtk 建立的 Spice Widget, 包括 Spice Window 等 */
g_signal_connect(spice_session, "channel-new",
G_CALLBACK(channel_new), NULL);
/* 最后调用这个 API, 连接 Server 就可以了 */
spice_session_connect(spice_session);
static void channel_new(SpiceSession *s, SpiceChannel *c, gpointer *data)
{
int id = 0;
/* 获取通道 ID */
g_object_get(c, "channel-id", &id, NULL);
if (SPICE_IS_DISPLAY_CHANNEL(c)) {
/* 对 Display 通道, 获取 spice window, 然后把它加入我们的容器(主窗口,
* VBox 等), 这里的 main_window 是我用 gtk_window_new() 创建的主窗口 */
spice_display = spice_display_new(s, id);
gtk_container_add(GTK_CONTAINER(main_window), GTK_WIDGET(spice_display));
gtk_widget_show_all(main_window);
}
} |