2 * This file is part of GtkHotkey.
3 * Copyright Mikkel Kamstrup Erlandsen, March, 2008
5 * GtkHotkey is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
10 * GtkHotkey is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with GtkHotkey. If not, see <http://www.gnu.org/licenses/>.
21 #include "gtk-hotkey-listener.h"
22 #include "gtk-hotkey-x11-listener.h"
23 #include "gtk-hotkey-marshal.h"
25 /* FIXME: The default listener is hardcoded to x11, should be compilation target dependent */
34 GTK_HOTKEY_LISTENER_DUMMY_PROPERTY
37 guint listener_signals
[LAST_SIGNAL
] = { 0 };
39 static gpointer gtk_hotkey_listener_parent_class
= NULL
;
41 static GtkHotkeyListener
*default_listener
= NULL
;
42 static GType default_listener_type
= G_TYPE_INVALID
;
45 * SECTION:gtk-hotkey-listener
46 * @short_description: Abstract base class providing platform independent hotkey listening capabilities
47 * @see_also: #GtkHotkeyRegistry, #GtkHotkeyInfo
49 * #GtkHotkeyListener is an abstract base class for implementing platform
50 * specific hotkey listeners - ie objects able to register when the user enters
51 * a certain keyboard combination, regardless of which window has focus.
53 * Unless you have very special needs you should use the factory method
54 * gtk_hotkey_listener_get_default() to get a reference to a #GtkHotkeyListener
55 * matching your platform. Although most applications will not need.
57 * This class is part of the advanced API of GtkHotkey. Applications will not
58 * normally use a #GtkHotkeyListener directly, since gtk_hotkey_info_bind()
59 * will call into gtk_hotkey_listener_bind() on the default listener for you.
63 * gtk_hotkey_listener_get_default
64 * @returns: A new reference to the default hotkey listener for the platform
66 * Static factory method to get a reference to the default #GtkHotkeyListener
67 * for the current platform.
69 * FIXME: Currently hardcoded to X11
72 gtk_hotkey_listener_get_default ()
74 /* FIXME: This method should be changedd to use the same approach as
75 * gtk_hotkey_registry_get_default() */
77 if (default_listener
) {
78 g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(default_listener
), NULL
);
79 return g_object_ref (default_listener
);
81 gtk_hotkey_listener_get_type (); /* This call makes sure the default type ise set */
82 g_debug ("Listener Type: %s", g_type_name (default_listener_type
));
84 default_listener
= g_object_new (default_listener_type
, NULL
);
85 g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(default_listener
), NULL
);
87 return g_object_ref (default_listener
);
91 * gtk_hotkey_listener_bind_hotkey
92 * @self: The hotkey listener on which to bind a hotkey
93 * @hotkey: The #GtkHotkeyInfo to bind. See #GtkHotkeyInfo:signature
94 * @error: #GError in which to store errors, or %NULL to ignore
95 * @returns: %TRUE if the binding succeeded, or %FALSE otherwise. In case of
96 * runtime errors @error will be set
98 * This method must be implemented by any child class of #GtkHotkeyListener.
100 * Start listening for keypresses matching the signature of @hotkey.
101 * This method is notmally accessed indirectly by calling gtk_hotkey_info_bind().
104 gtk_hotkey_listener_bind_hotkey (GtkHotkeyListener
*self
,
105 GtkHotkeyInfo
*hotkey
,
108 g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(self
), FALSE
);
110 return GTK_HOTKEY_LISTENER_GET_CLASS (self
)->bind_hotkey (self
, hotkey
, error
);
114 * gtk_hotkey_listener_unbind_hotkey
115 * @self: The hotkey listener on which to bind a hotkey
116 * @hotkey: The #GtkHotkeyInfo to bind. See #GtkHotkeyInfo:signature
117 * @error: #GError in which to store errors, or %NULL to ignore
118 * @returns: %TRUE if the binding has been removed, or %FALSE otherwise.
119 * In case of runtime errors @error will be set
121 * This method must be implemented by any child class of #GtkHotkeyListener.
123 * Stop listening for keypresses matching the signature of @hotkey. This method
124 * is notmally accessed indirectly by calling gtk_hotkey_info_unbind().
127 gtk_hotkey_listener_unbind_hotkey (GtkHotkeyListener
*self
,
128 GtkHotkeyInfo
*hotkey
,
131 g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(self
), FALSE
);
133 return GTK_HOTKEY_LISTENER_GET_CLASS (self
)->unbind_hotkey (self
, hotkey
, error
);
137 * gtk_hotkey_listener_activated
138 * @self: #GtkHotkeyListener to emit the #GtkHotkeyListener::activated signal
139 * @hotkey: The #GtkHotkeyInfo the event happened for
140 * @event_time: The system time the event happened on. This is useful for
141 * applications to pass through focus stealing prevention when
144 * Emit the #GtkHotkeyInfo::activated signal on a hotkey listener.
147 gtk_hotkey_listener_activated (GtkHotkeyListener
*self
,
148 GtkHotkeyInfo
*hotkey
,
151 g_return_if_fail (GTK_HOTKEY_IS_LISTENER(self
));
152 g_return_if_fail (GTK_HOTKEY_IS_INFO(hotkey
));
154 g_signal_emit (self
, listener_signals
[ACTIVATED
], 0, hotkey
, event_time
);
158 gtk_hotkey_listener_class_init (GtkHotkeyListenerClass
* klass
)
160 gtk_hotkey_listener_parent_class
= g_type_class_peek_parent (klass
);
163 * GtkHotkeyListener::activated
164 * @listener: The object that emitted the signal
165 * @hotkey: a #GtkHotkeyInfo for the hotkey that was activated
166 * @event_time: Time for event triggering the keypress. This is mainly
167 * used to pass to window management functions to pass through
168 * focus stealing prevention
170 * Emitted when a registered hotkey has been activated.
172 listener_signals
[ACTIVATED
] = \
173 g_signal_new ("activated",
174 GTK_HOTKEY_TYPE_LISTENER
,
177 gtk_hotkey_marshal_VOID__OBJECT_UINT
,
179 GTK_HOTKEY_TYPE_INFO
,
185 gtk_hotkey_listener_init (GtkHotkeyListener
* self
)
191 gtk_hotkey_listener_get_type (void)
193 static GType gtk_hotkey_listener_type_id
= 0;
195 if (G_UNLIKELY (gtk_hotkey_listener_type_id
== 0)) {
196 static const GTypeInfo g_define_type_info
= {
197 sizeof (GtkHotkeyListenerClass
),
198 (GBaseInitFunc
) NULL
,
199 (GBaseFinalizeFunc
) NULL
,
200 (GClassInitFunc
) gtk_hotkey_listener_class_init
,
201 (GClassFinalizeFunc
) NULL
,
203 sizeof (GtkHotkeyListener
),
205 (GInstanceInitFunc
) gtk_hotkey_listener_init
,
206 (const GTypeValueTable
*) NULL
/* value table */
209 gtk_hotkey_listener_type_id
= g_type_register_static (G_TYPE_OBJECT
,
212 G_TYPE_FLAG_ABSTRACT
);
214 default_listener_type
= gtk_hotkey_x11_listener_get_type ();
216 return gtk_hotkey_listener_type_id
;