annotate xia-inhibitor.c @ 2:432155b982cf

Added tag version-1 for changeset bdab58c3db61
author Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
date Sat, 27 Apr 2013 21:30:44 +0200
parents 9a16bf50daba
children 957d697d27d3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
1 /*
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
2 * Copyright (C) 2013 Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
3 *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
4 * Permission is hereby granted, free of charge, to any person obtaining
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
5 * a copy of this software and associated documentation files (the
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
6 * "Software"), to deal in the Software without restriction, including
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
7 * without limitation the rights to use, copy, modify, merge, publish,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
8 * distribute, sublicense, and/or sell copies of the Software, and to
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
9 * permit persons to whom the Software is furnished to do so, subject to
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
10 * the following conditions:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
11 *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
12 * The above copyright notice and this permission notice shall be included
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
13 * in all copies or substantial portions of the Software.
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
14 *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
22 */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
23
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
24 #include <X11/Xlib.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
25 #include <X11/keysym.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
26 #include <X11/extensions/Xext.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
27 #ifdef HAVE_LIBXTST
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
28 #include <X11/extensions/XTest.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
29 #endif /* HAVE_LIBXTST */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
30 #include <glib.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
31 #include <glib/gi18n.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
32 #include <gdk/gdkx.h>
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
33 #include "xia-inhibitor.h"
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
34
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
35 #define FAKE_EVENT_TIMEOUT 20
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
36
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
37 G_DEFINE_TYPE(XiaInhibitor, xia_inhibitor, G_TYPE_OBJECT)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
38
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
39 #define XIA_INHIBITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj), \
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
40 XIA_TYPE_INHIBITOR, XiaInhibitorPrivate))
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
41
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
42 struct _XiaInhibitorPrivate
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
43 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
44 XiaInhibitor *inhibitor;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
45 gboolean inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
46 gboolean have_xtest;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
47 guint generate_fake_event_id;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
48 };
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
49
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
50 enum { PROP_0, PROP_INHIBITED };
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
51
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
52 static gboolean
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
53 generate_fake_event(gpointer data)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
54 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
55 #ifdef HAVE_LIBXTST
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
56 XiaInhibitor *self = XIA_INHIBITOR(data);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
57 static KeyCode keycode = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
58
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
59 if (!self->priv->have_xtest) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
60 return (TRUE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
61 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
62
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
63 if (keycode == 0) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
64 keycode = XKeysymToKeycode(gdk_x11_get_default_xdisplay(),
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
65 XK_Alt_L);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
66 if (keycode == 0) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
67 return (TRUE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
68 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
69 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
70
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
71 XTestFakeKeyEvent(gdk_x11_get_default_xdisplay(), keycode, True, 0);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
72 XTestFakeKeyEvent(gdk_x11_get_default_xdisplay(), keycode, False, 0);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
73
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
74 g_debug("Generated fake key event using XTEST");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
75 #endif /* HAVE_LIBXTST */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
76
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
77 return (TRUE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
78 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
79
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
80 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
81 xia_inhibitor_set_property(GObject *object, guint property_id,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
82 const GValue *value, GParamSpec *pspec)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
83 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
84 XiaInhibitor *self = XIA_INHIBITOR(object);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
85
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
86 switch (property_id) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
87 case PROP_INHIBITED: {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
88 gboolean inhibited = g_value_get_boolean(value);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
89 if (self->priv->inhibited == inhibited) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
90 return;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
91 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
92
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
93 if (inhibited) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
94 self->priv->generate_fake_event_id = \
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
95 g_timeout_add_seconds(FAKE_EVENT_TIMEOUT,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
96 (GSourceFunc)generate_fake_event, self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
97 } else {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
98 g_source_remove(self->priv->generate_fake_event_id);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
99 self->priv->generate_fake_event_id = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
100 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
101
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
102 self->priv->inhibited = inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
103
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
104 g_debug("Automatic power management is %s", (inhibited) ?
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
105 "inhibited" : "enabled");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
106 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
107 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
108 default:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
109 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
110 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
111 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
112 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
113
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
114 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
115 xia_inhibitor_get_property(GObject *object, guint property_id, GValue *value,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
116 GParamSpec *pspec)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
117 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
118 XiaInhibitor *self = XIA_INHIBITOR(object);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
119
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
120 switch (property_id) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
121 case PROP_INHIBITED:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
122 g_value_set_boolean(value, self->priv->inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
123 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
124 default:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
125 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
126 pspec);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
127 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
128 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
129 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
130
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
131 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
132 xia_inhibitor_finalize(GObject *gobject)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
133 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
134 XiaInhibitor *self = XIA_INHIBITOR(gobject);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
135
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
136 if (self->priv->generate_fake_event_id != 0) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
137 g_source_remove(self->priv->generate_fake_event_id);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
138 self->priv->generate_fake_event_id = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
139 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
140
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
141 G_OBJECT_CLASS(xia_inhibitor_parent_class)->finalize(gobject);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
142 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
143
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
144 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
145 xia_inhibitor_class_init(XiaInhibitorClass *klass)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
146 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
147 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
148 GParamSpec *pspec;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
149
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
150 gobject_class->set_property = xia_inhibitor_set_property;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
151 gobject_class->get_property = xia_inhibitor_get_property;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
152 gobject_class->finalize = xia_inhibitor_finalize;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
153
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
154 pspec = g_param_spec_boolean("inhibited", "Inhibited",
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
155 "Whether automatic power management is inhibited", FALSE,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
156 G_PARAM_READWRITE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
157 g_object_class_install_property(gobject_class, PROP_INHIBITED, pspec);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
158
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
159 g_type_class_add_private(klass, sizeof (XiaInhibitorPrivate));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
160 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
161
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
162 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
163 xia_inhibitor_init(XiaInhibitor *self)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
164 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
165 #ifdef HAVE_LIBXTST
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
166 int event_base;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
167 int error_base;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
168 int xtest_major;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
169 int xtest_minor;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
170 #endif /* HAVE_LIBXTST */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
171
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
172 self->priv = XIA_INHIBITOR_GET_PRIVATE(self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
173
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
174 self->priv->inhibited = FALSE;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
175 self->priv->generate_fake_event_id = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
176
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
177 #ifdef HAVE_LIBXTST
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
178 self->priv->have_xtest = ((gboolean)XTestQueryExtension(
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
179 gdk_x11_get_default_xdisplay(), &event_base, &error_base,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
180 &xtest_major, &xtest_minor));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
181 #endif /* HAVE_LIBXTST */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
182 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
183
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
184 void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
185 xia_inhibitor_set_inhibited(XiaInhibitor *self, gboolean inhibited)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
186 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
187 g_return_if_fail(XIA_IS_INHIBITOR(self));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
188
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
189 g_object_set(G_OBJECT(self), "inhibited", inhibited, NULL);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
190 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
191
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
192 gboolean
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
193 xia_inhibitor_get_inhibited(XiaInhibitor *self)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
194 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
195 gboolean inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
196
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
197 g_return_val_if_fail(XIA_IS_INHIBITOR(self), FALSE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
198
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
199 g_object_get(G_OBJECT(self), "inhibited", &inhibited, NULL);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
200
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
201 return (inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
202 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
203
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
204 XiaInhibitor *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
205 xia_inhibitor_new(void)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
206 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
207 return (g_object_new(XIA_TYPE_INHIBITOR, NULL));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
208 }