Re: How can I find out if a program is already running
- From: Zoltan Boszormenyi <zboszor freemail hu>
- To: Mark Leisher <mleisher crl nmsu edu>
- Cc: gtk-list <gtk-list gnome org>
- Subject: Re: How can I find out if a program is already running
- Date: Sun, 11 Dec 2005 18:37:51 +0100
Thanks for the answer, although I still have problems with this.
Mark Leisher írta:
Zoltan Boszormenyi wrote:
Hi,
I need to find out whether an instance of a program is already running
and possibly unminimize it or bring it above any other windows, so
I can prevent an application started again.
Is is possible using GTK-1.2, or GTK-2.x, and how?
The following procedure is an old X11 trick. It will not work on Windows.
0. Add code to your program to handle GDK_SELECTION_CLEAR events. See
5 below for what this code should do.
1. At startup of the program, create an atom with gdk_intern_atom().
2. Use gdk_selection_owner_get() on the atom.
3. If the selection owner is NULL, then call gdk_selection_owner_set()
with the time_ parameter set to GDK_CURRENT_TIME and the send_event
parameter set to FALSE.
My problem is, the owner this call returns is always NULL.
This has something to do with the fact that the actual owner is a window
in another process.
There is this call: GdkWindow *gdk_window_foreign_new(GdkNativeWindow anid)
This GdkNativeWindow is a native X Window ID or HWND on Windows.
I seem to have to call this, wrap a foreign window into a GdkWindow before
gdk_selection_owner_set() can give me sensible return value.
But how can I tell the XID of a window created from another process?
Sorry, I don't know too much about low level Xlib programming...
4. Else, there is a valid owner of the atom, so the program is already
running. Assert ownership of the selection with
gdk_selection_owner_set() again. This causes the running application
to lose ownership and call the code to handle GDK_SELECTION_CLEAR
events. Then exit.
5. The code to handle GDK_SELECTION_CLEAR events should do 2 things:
A. If minimized, unminimize.
B. Assert ownership of the selection again.
This doesn't work on Windows because the GDK selection API apparently
only works within applications and not globally like they do in X11.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]