Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » GTK+
  • » Embedding applications via XEmbed [RSS Feed]

#1 Jan. 20, 2011 20:53:32

Michael T.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Embedding applications via XEmbed


Hi all,

I am hoping someone can point me to some documentation about this, or
perhaps supplement what's already in the main Gtk docs. I am trying
to write an application which can swallow any window which understands
XEmbed.

I've read about GtkSocket and GtkPlug, but the examples for the
official documentation don't make it clear to me how to go about this.

Can someone outline more fully how this would work?

I currently have nothing more than a toplevel GtkWindow rendered which
I would like to use to accept an application which understands XEmbed.
As I understand it, my application would have to set this up, and
assign a window ID, which other clients can then use via XEmbed to
embed themselves into my application.

but I am unsure if this is a GtkSocket or GtkPlug which I need to define.

If someone could provide an example of how this is handled, i'd much
appreciate it.

TIA,

Michael
_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Offline

#2 Jan. 21, 2011 04:24:50

Andy S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Embedding applications via XEmbed


On 2011-01-20 20:52, Michael Treibton wrote:
> I've read about GtkSocket and GtkPlug, but the examples for the
> official documentation don't make it clear to me how to go about this.
>
> Can someone outline more fully how this would work?

Most likely you want to do something like this:

1. Create a GtkSocket as part of your application
2. Get the GtkSocket's window ID
3. Pass the window ID to the application you want to embed

Gtk and the other application should take care of the rest. A common way
to pass the window id is with a flag when you spawn the other program.
For example `xterm -into <id>' or `mplayer -wid <id>'.


> If someone could provide an example of how this is handled, i'd much
> appreciate it.

I've attached a small example I wrote a while back that embeds a gVim
window inside an GTK+ application. You should be able to substitute any
other XEmbed application for gVim. You can just print out the window id
and the spawn the other application manually if you want.pgpyIwwiGu01c.pgpDescription:PGP signature_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Attachments:
attachment pgpyIwwiGu01c.pgp (198 bytes)

Offline

#3 Jan. 21, 2011 04:26:06

Andy S.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Embedding applications via XEmbed


Oops, forgot to attach the example..#include <gtk/gtk.h>

#define EXPR "'GoHello, World!<Esc><C-O>'"

void send_hello(GtkButton *btn, gint id)
{
gchar *command = g_strdup_printf(
"gvim --servername %d --remote-send " EXPR, id);
g_spawn_command_line_async(command, NULL);
}

gint main(gint argc, gchar **argv)
{
gtk_init(&argc, &argv);

/* Create window */
GtkWidget *win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
GtkWidget *vbox = gtk_vbox_new(FALSE, 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), sock, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(vbox), btn, FALSE, TRUE, 0);
gtk_container_add(GTK_CONTAINER(win), vbox);
gtk_widget_show_all(win);

/* Embed vim */
GdkNativeWindow id = gtk_socket_get_id(GTK_SOCKET(sock));
gchar *command = g_strdup_printf(
"gvim --servername %d --socketid %d", id, id);
g_spawn_command_line_async(command, NULL);
g_signal_connect(btn, "clicked", G_CALLBACK(send_hello), (gpointer)id);

/* Run */
gtk_main();
return 0;
}pgpp4i69UDaBF.pgpDescription:PGP signature_______________________________________________
gtk-list mailing list
gtk-list@gnome.orghttp://mail.gnome.org/mailman/listinfo/gtk-list

Attachments:
attachment pgpp4i69UDaBF.pgp (198 bytes)

Offline

  • Root
  • » GTK+
  • » Embedding applications via XEmbed [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support