summaryrefslogtreecommitdiff
path: root/src/eventsource.cpp
blob: e621cd8e2d26dfac2f0e16c0fa5b9c9ffdce5677 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * Copyright © 2010 Canonical Ltd
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Authored by: Jason Smith <jason.smith@canonical.com>
 * 	      : Sam Spilsbury <sam.spilsbury@canonical.com>
 */

#include "privatescreen.h"

Glib::RefPtr <CompEventSource>
CompEventSource::create ()
{
    return Glib::RefPtr <CompEventSource> (new CompEventSource ());
}

sigc::connection
CompEventSource::connect (const sigc::slot <bool> &slot)
{
    return connect_generic (slot);
}

CompEventSource::CompEventSource () :
    Glib::Source (),
    mDpy (screen->dpy ()),
    mConnectionFD (ConnectionNumber (screen->dpy ()))
{
    mPollFD.set_fd (mConnectionFD);
    mPollFD.set_events (Glib::IO_IN);

    set_priority (G_PRIORITY_DEFAULT);
    add_poll (mPollFD);
    set_can_recurse (true);

    connect (sigc::mem_fun <bool, CompEventSource> (this, &CompEventSource::callback));
}

CompEventSource::~CompEventSource ()
{
}

bool
CompEventSource::callback ()
{
    if (restartSignal || shutDown)
    {
	screen->priv->mainloop->quit ();
	return false;
    }
    else
	screen->priv->processEvents ();
    return true;
}

bool
CompEventSource::prepare (int &timeout)
{
    timeout = -1;
    return XPending (mDpy);
}

bool
CompEventSource::check ()
{
    if (mPollFD.get_revents () & Glib::IO_IN)
	return XPending (mDpy);

    return false;
}

bool
CompEventSource::dispatch (sigc::slot_base *slot)
{
    return (*static_cast <sigc::slot <bool> *> (slot)) ();
}