Re: Bringing a GtkWindow to the current desktop with libwnck



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

2009/7/3 Jim George <jimgeorge gmail com>

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




[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]