1
////////////////////////////////////////////////////////////////////////////
2
// NoteCase notes manager project <http://notecase.sf.net>
4
// This code is licensed under BSD license.See "license.txt" for more details.
6
// File: object of this class should be alive as long as program lives
7
// so that instance can be detected (borowed from gnome-volume-manager)
8
////////////////////////////////////////////////////////////////////////////
10
* src/clipboard.c - X clipboard hack to detect if daemon is running
12
* Elliot Lee <sopwith@redhat.com>
14
* (C) Copyright 1999 Red Hat, Inc.
16
* Licensed under the GNU GPL v2. See COPYING.
19
#include "SingleInstance.h"
24
//pair of dummy functions
25
static void clipboard_get_func (GtkClipboard *clipboard, GtkSelectionData *selection_data, guint info, gpointer user_data_or_owner){}
26
static void clipboard_clear_func (GtkClipboard *clipboard, gpointer user_data_or_owner){}
28
#define CLIPBOARD_NAME "_NOTECASE"
31
* notecase_get_clipboard - try and get the CLIPBOARD_NAME clipboard
33
* Returns TRUE if successfully retrieved and FALSE otherwise.
35
gboolean notecase_get_clipboard ()
38
static const GtkTargetEntry targets[] = { {CLIPBOARD_NAME, 0, 0} };
39
Atom atom = gdk_x11_get_xatom_by_name (CLIPBOARD_NAME);
40
gboolean retval = FALSE;
41
GtkClipboard *clipboard;
43
XGrabServer (GDK_DISPLAY ());
45
if (XGetSelectionOwner (GDK_DISPLAY (), atom) != None)
48
clipboard = gtk_clipboard_get (gdk_atom_intern (CLIPBOARD_NAME, FALSE));
50
if (gtk_clipboard_set_with_data (clipboard, targets,
51
G_N_ELEMENTS (targets),
53
clipboard_clear_func, NULL))
57
XUngrabServer (GDK_DISPLAY ());
63
CSingleInstance::CSingleInstance(const char *szName)
65
m_bAlreadyExists = !notecase_get_clipboard();
68
CSingleInstance::~CSingleInstance()
72
bool CSingleInstance::ProgramAlreadyStarted()
74
return m_bAlreadyExists;