Prevent to exec second copy of application
- From: jakonda jakarta <janjakon mail ru>
- To: gtk-app-devel-list gnome org
- Subject: Prevent to exec second copy of application
- Date: Sat, 13 Nov 2004 14:41:53 +0300
Helo, I try to force my application to be only one on display,
I mean if somebody do
$./my-program
OK!
$./my-program
There is another copy. Use it
My algorithm is follow: create atom, check if it selected by somebody, if it so another copy of application
is
running, if it not so we are alone, select atom and work.
Code is follows:
--------------------------------------------------------------------------------------------------------------
$ cat main.cpp
#include <gdk/gdk.h>
#include <gtk/gtk.h>
#include <cstdlib>
#include <cstring>
gint OnDelete(GtkWidget *widget, GdkEvent *event, gpointer data);
gint OnDestroy(GtkWidget *widget, GdkEvent *event, gpointer data);
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *topLevelWindow=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_signal_connect(GTK_OBJECT(topLevelWindow), "delete_event",
GTK_SIGNAL_FUNC(OnDelete), NULL);
gtk_signal_connect(GTK_OBJECT(topLevelWindow), "destroy",
GTK_SIGNAL_FUNC(OnDestroy), NULL);
gtk_widget_show(topLevelWindow);
GdkAtom atom=gdk_atom_intern("MY_PRIVATE_ATOM_GTK_EXAMPLE", FALSE);
if(gdk_selection_owner_get_for_display(gdk_display_get_default(), atom)!=NULL)
g_print("There is another copy\n");
gtk_selection_owner_set_for_display(gdk_display_get_default(),
topLevelWindow, atom, 0);
gtk_main();
g_print("Done!\n");
return EXIT_SUCCESS;
}
gint OnDelete(GtkWidget *widget, GdkEvent *event, gpointer data)
{
return FALSE;
}
gint OnDestroy(GtkWidget *widget, GdkEvent *event, gpointer data)
{
g_print("Shutting down\n");
gtk_main_quit();
return 0;
}
--------------------------------------------------------------------------------------------------------------
but it didn't work, what wrong?
May be there is another algorithm to prevent starting second copy of application in the same dipslay?
With regards, Jan.
PS
I don't want to use bonobo.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]