Bringing a GtkWindow to the current desktop with libwnck

View: New views
4 Messages — Rating Filter:   Alert me  

Bringing a GtkWindow to the current desktop with libwnck

by Jim George :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi all,
I'm writing a program that needs to be "single-instance". The program
will only run on gnome desktop machines. I'm using dbus to ensure
this, by having the program try a dbus rpc each time it starts. If
there's a running instance, it responds to the rpc by calling
gtk_window_present on the main window. However, if the user switches
desktops and tries to run another instance, gtk_window_present will
only cause the window to appear on the previous desktop, not the
current one.

I tried to get around this using libwnck. I call
wnck_window_get(GDK_WINDOW_XID(main_window->window)), but the
WnckWindow returned is always NULL. The X window ID "seems" to make
sense (it's a large integer), so what am I doing wrong?

Any alternate solutions to this problem are also welcome.
Thanks,
Jim
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@...
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Bringing a GtkWindow to the current desktop with libwnck

by Brian J. Tarricone :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On 2009/07/02 23:27, Jim George wrote:

> I tried to get around this using libwnck. I call
> wnck_window_get(GDK_WINDOW_XID(main_window->window)), but the
> WnckWindow returned is always NULL. The X window ID "seems" to make
> sense (it's a large integer), so what am I doing wrong?

Try this:

WnckScreen *wnck_screen = wnck_screen_get_default();
wnck_screen_force_update(wnck_screen);

... before your wnck_window_get() call.

        -brian
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@...
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Bringing a GtkWindow to the current desktop with libwnck

by Vivien Malerba :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/7/3 Jim George <jimgeorge@...>

> Hi all,
> I'm writing a program that needs to be "single-instance". The program
> will only run on gnome desktop machines. I'm using dbus to ensure
> this, by having the program try a dbus rpc each time it starts. If
> there's a running instance, it responds to the rpc by calling
> gtk_window_present on the main window. However, if the user switches
> desktops and tries to run another instance, gtk_window_present will
> only cause the window to appear on the previous desktop, not the
> current one.
>
> I tried to get around this using libwnck. I call
> wnck_window_get(GDK_WINDOW_XID(main_window->window)), but the
> WnckWindow returned is always NULL. The X window ID "seems" to make
> sense (it's a large integer), so what am I doing wrong?
>

You could use Libunique http://live.gnome.org/LibUnique for that purpose.

Vivien
_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@...
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Re: Bringing a GtkWindow to the current desktop with libwnck

by Chris Vine :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Sun, 5 Jul 2009 11:51:19 +0200
Vivien Malerba <vmalerba@...> wrote:

>
> 2009/7/3 Jim George <jimgeorge@...>
>
> > Hi all,
> > I'm writing a program that needs to be "single-instance". The
> > program will only run on gnome desktop machines. I'm using dbus to
> > ensure this, by having the program try a dbus rpc each time it
> > starts. If there's a running instance, it responds to the rpc by
> > calling gtk_window_present on the main window. However, if the user
> > switches desktops and tries to run another instance,
> > gtk_window_present will only cause the window to appear on the
> > previous desktop, not the current one.
> >
> > I tried to get around this using libwnck. I call
> > wnck_window_get(GDK_WINDOW_XID(main_window->window)), but the
> > WnckWindow returned is always NULL. The X window ID "seems" to make
> > sense (it's a large integer), so what am I doing wrong?
> >
>
> You could use Libunique http://live.gnome.org/LibUnique for that
> purpose.

libunique does not address the OP's problem, which is that
gtk_window_present() does not do what it should do.  (libunique would
make it unncessary for him to write his own dbus RPC for the purpose,
but since he has already written that I would stick with what he has, as
it is one dependency less.)

Metacity is responsible for the program not presenting itself on the
current workspace, but something also appears to go wrong in GTK+'s
tracking of window status, which can be demonstrated by repeatedly
hiding and presenting a window on different workspaces and when
obscured by different windows.  I did set up a test program to try and
get to the bottom of it, but didn't have the time to follow through
(but I did manage to show it was generating bogus status information).

What I do when re-presenting an instance of a single instance program is
to transfer the window to the current workspace using libwnck, and then
after doing so present it with gtk_window_present().  Sometimes however
the window reaches a state where it will not go to the top of the
Z-order.  I have found that the following sequence in the routine
which presents the program to the user on a restart deals with this:

* transfer to the current workspace with libwnck
* call gtk_widget_hide() on the window
* call gtk_window_present() on the window
* call gtk_window_deiconify() on the window

The last call should be completely otiose, but sometimes metacity
reaches the conclusion that the window is or should be iconified when it
should not be or isn't, and that prevents that particular problem.

On the OP's other issue, as suggested by another poster, if he first
calls wnck_screen_force_update(wnck_screen_get_default()) before
getting his WnckWindow object, that will result in him getting a valid
pointer back when he subsequently calls wnck_window_get().

Chris

_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@...
http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list