~ubuntu-core-dev/update-notifier/ubuntu

« back to all changes in this revision

Viewing changes to src/clipboard.c

  • Committer: Michael Terry
  • Date: 2011-07-01 12:46:30 UTC
  • Revision ID: michael.terry@canonical.com-20110701124630-oesjak2rueshotbm
Tags: 0.112ubuntu2
* data/update-notifier.desktop.in:
  - Don't show in "Startup Applications" (LP: #803917)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * src/clipboard.c - X clipboard hack to detect if daemon is running
 
3
 *
 
4
 * Elliot Lee <sopwith@redhat.com>
 
5
 *
 
6
 * (C) Copyright 1999 Red Hat, Inc.
 
7
 *
 
8
 * Licensed under the GNU GPL v2.  See COPYING.
 
9
 */
 
10
 
 
11
#include "config.h"
 
12
 
 
13
#include <gconf/gconf-client.h>
 
14
#include <gdk/gdkx.h>
 
15
 
 
16
#include "update-notifier.h"
 
17
 
 
18
/*
 
19
 * clipboard_get_func - dummy get_func for gtk_clipboard_set_with_data ()
 
20
 */
 
21
static void
 
22
clipboard_get_func (GtkClipboard *clipboard __attribute__((__unused__)),
 
23
                   GtkSelectionData *selection_data __attribute__((__unused__)),
 
24
                    guint info __attribute__((__unused__)),
 
25
                    gpointer user_data_or_owner __attribute__((__unused__)))
 
26
{
 
27
}
 
28
 
 
29
/*
 
30
 * clipboard_clear_func - dummy clear_func for gtk_clipboard_set_with_data ()
 
31
 */
 
32
static void
 
33
clipboard_clear_func (GtkClipboard *clipboard __attribute__((__unused__)),
 
34
                      gpointer user_data_or_owner __attribute__((__unused__)))
 
35
{
 
36
}
 
37
 
 
38
/*
 
39
 * up_get_clipboard - try and get the CLIPBOARD_NAME clipboard
 
40
 *
 
41
 * Returns TRUE if successfully retrieved and FALSE otherwise.
 
42
 */
 
43
gboolean
 
44
up_get_clipboard (void)
 
45
{
 
46
        static const GtkTargetEntry targets[] = { {CLIPBOARD_NAME, 0, 0} };
 
47
        gboolean retval = FALSE;
 
48
        GtkClipboard *clipboard;
 
49
        Atom atom;
 
50
        Display *display;
 
51
 
 
52
        atom = gdk_x11_get_xatom_by_name (CLIPBOARD_NAME);
 
53
        display = gdk_x11_display_get_xdisplay (gdk_display_get_default ());
 
54
 
 
55
        XGrabServer (display);
 
56
 
 
57
        if (XGetSelectionOwner (display, atom) != None)
 
58
                goto out;
 
59
 
 
60
        clipboard = gtk_clipboard_get (gdk_atom_intern (CLIPBOARD_NAME, FALSE));
 
61
 
 
62
        if (gtk_clipboard_set_with_data (clipboard, targets,
 
63
                                         G_N_ELEMENTS (targets),
 
64
                                         clipboard_get_func,
 
65
                                         clipboard_clear_func, NULL))
 
66
                retval = TRUE;
 
67
 
 
68
out:
 
69
        XUngrabServer (display);
 
70
        gdk_flush ();
 
71
 
 
72
        return retval;
 
73
}