annotate xia-inhibitor.c @ 13:14f31e92372f

Fix style
author Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
date Thu, 17 Apr 2014 11:01:25 +0200
parents 957d697d27d3
children
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
13
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 3
diff changeset
39 #define XIA_INHIBITOR_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),\
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 3
diff changeset
40 XIA_TYPE_INHIBITOR, XiaInhibitorPrivate))
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
41
13
14f31e92372f Fix style
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 3
diff changeset
42 struct _XiaInhibitorPrivate {
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
43 XiaInhibitor *inhibitor;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
44 gboolean inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
45 gboolean have_xtest;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
46 guint generate_fake_event_id;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
47 };
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 enum { PROP_0, PROP_INHIBITED };
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
50
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
51 static gboolean
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
52 generate_fake_event(gpointer data)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
53 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
54 #ifdef HAVE_LIBXTST
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
55 XiaInhibitor *self = XIA_INHIBITOR(data);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
56 static KeyCode keycode = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
57
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
58 if (!self->priv->have_xtest) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
59 return (TRUE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
60 }
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 if (keycode == 0) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
63 keycode = XKeysymToKeycode(gdk_x11_get_default_xdisplay(),
3
957d697d27d3 Minimize interference with menus
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents: 0
diff changeset
64 XK_Shift_L);
0
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
65 if (keycode == 0) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
66 return (TRUE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
67 }
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 XTestFakeKeyEvent(gdk_x11_get_default_xdisplay(), keycode, True, 0);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
71 XTestFakeKeyEvent(gdk_x11_get_default_xdisplay(), keycode, False, 0);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
72
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
73 g_debug("Generated fake key event using XTEST");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
74 #endif /* HAVE_LIBXTST */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
75
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
76 return (TRUE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
77 }
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 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
80 xia_inhibitor_set_property(GObject *object, guint property_id,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
81 const GValue *value, GParamSpec *pspec)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
82 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
83 XiaInhibitor *self = XIA_INHIBITOR(object);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
84
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
85 switch (property_id) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
86 case PROP_INHIBITED: {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
87 gboolean inhibited = g_value_get_boolean(value);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
88 if (self->priv->inhibited == inhibited) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
89 return;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
90 }
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 if (inhibited) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
93 self->priv->generate_fake_event_id = \
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
94 g_timeout_add_seconds(FAKE_EVENT_TIMEOUT,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
95 (GSourceFunc)generate_fake_event, self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
96 } else {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
97 g_source_remove(self->priv->generate_fake_event_id);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
98 self->priv->generate_fake_event_id = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
99 }
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 self->priv->inhibited = inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
102
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
103 g_debug("Automatic power management is %s", (inhibited) ?
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
104 "inhibited" : "enabled");
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
105 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
106 }
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
107 default:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
108 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
109 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
110 }
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 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
114 xia_inhibitor_get_property(GObject *object, guint property_id, GValue *value,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
115 GParamSpec *pspec)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
116 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
117 XiaInhibitor *self = XIA_INHIBITOR(object);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
118
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
119 switch (property_id) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
120 case PROP_INHIBITED:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
121 g_value_set_boolean(value, self->priv->inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
122 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
123 default:
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
124 G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
125 pspec);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
126 break;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
127 }
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 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
131 xia_inhibitor_finalize(GObject *gobject)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
132 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
133 XiaInhibitor *self = XIA_INHIBITOR(gobject);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
134
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
135 if (self->priv->generate_fake_event_id != 0) {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
136 g_source_remove(self->priv->generate_fake_event_id);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
137 self->priv->generate_fake_event_id = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
138 }
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 G_OBJECT_CLASS(xia_inhibitor_parent_class)->finalize(gobject);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
141 }
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 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
144 xia_inhibitor_class_init(XiaInhibitorClass *klass)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
145 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
146 GObjectClass *gobject_class = G_OBJECT_CLASS(klass);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
147 GParamSpec *pspec;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
148
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
149 gobject_class->set_property = xia_inhibitor_set_property;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
150 gobject_class->get_property = xia_inhibitor_get_property;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
151 gobject_class->finalize = xia_inhibitor_finalize;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
152
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
153 pspec = g_param_spec_boolean("inhibited", "Inhibited",
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
154 "Whether automatic power management is inhibited", FALSE,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
155 G_PARAM_READWRITE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
156 g_object_class_install_property(gobject_class, PROP_INHIBITED, pspec);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
157
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
158 g_type_class_add_private(klass, sizeof (XiaInhibitorPrivate));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
159 }
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 static void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
162 xia_inhibitor_init(XiaInhibitor *self)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
163 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
164 #ifdef HAVE_LIBXTST
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
165 int event_base;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
166 int error_base;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
167 int xtest_major;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
168 int xtest_minor;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
169 #endif /* HAVE_LIBXTST */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
170
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
171 self->priv = XIA_INHIBITOR_GET_PRIVATE(self);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
172
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
173 self->priv->inhibited = FALSE;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
174 self->priv->generate_fake_event_id = 0;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
175
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
176 #ifdef HAVE_LIBXTST
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
177 self->priv->have_xtest = ((gboolean)XTestQueryExtension(
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
178 gdk_x11_get_default_xdisplay(), &event_base, &error_base,
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
179 &xtest_major, &xtest_minor));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
180 #endif /* HAVE_LIBXTST */
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
181 }
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 void
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
184 xia_inhibitor_set_inhibited(XiaInhibitor *self, gboolean inhibited)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
185 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
186 g_return_if_fail(XIA_IS_INHIBITOR(self));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
187
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
188 g_object_set(G_OBJECT(self), "inhibited", inhibited, NULL);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
189 }
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 gboolean
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
192 xia_inhibitor_get_inhibited(XiaInhibitor *self)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
193 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
194 gboolean inhibited;
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
195
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
196 g_return_val_if_fail(XIA_IS_INHIBITOR(self), FALSE);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
197
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
198 g_object_get(G_OBJECT(self), "inhibited", &inhibited, NULL);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
199
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
200 return (inhibited);
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
201 }
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 XiaInhibitor *
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
204 xia_inhibitor_new(void)
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
205 {
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
206 return (g_object_new(XIA_TYPE_INHIBITOR, NULL));
9a16bf50daba Initial revision
Guido Berhoerster <guido+xinhibit-applet@berhoerster.name>
parents:
diff changeset
207 }