~malept/gtkhotkey/win32-support

« back to all changes in this revision

Viewing changes to src/gtk-hotkey-listener.c

  • Committer: Mark Lee
  • Date: 2009-01-01 22:36:40 UTC
  • Revision ID: bzr@lazymalevolence.com-20090101223640-65unk1g97mfubkdi
Listener: Replace get_default () with the registry implementation; add Win32 support.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 */
18
18
 
19
19
#include "gtk-hotkey-listener.h"
 
20
#ifdef _WIN32
 
21
#include "gtk-hotkey-win32-listener.h"
 
22
#else
20
23
#include "gtk-hotkey-x11-listener.h"
 
24
#endif
21
25
#include "gtk-hotkey-marshal.h"
22
26
 
23
 
/* FIXME: The default listener is hardcoded to x11, should be compilation target dependent */
24
 
 
25
27
enum  {
26
28
        ACTIVATED,
27
29
        
39
41
static  GtkHotkeyListener       *default_listener = NULL;
40
42
static  GType                           default_listener_type = G_TYPE_INVALID;
41
43
 
 
44
#ifdef _WIN32
 
45
#define DEFAULT_LISTENER_TYPE GTK_HOTKEY_TYPE_WIN32_LISTENER
 
46
#else
 
47
#define DEFAULT_LISTENER_TYPE GTK_HOTKEY_TYPE_X11_LISTENER
 
48
#endif
 
49
 
42
50
/**
43
51
 * SECTION:gtk-hotkey-listener
44
52
 * @short_description: Abstract base class providing platform independent hotkey listening capabilities
63
71
 *
64
72
 * Static factory method to get a reference to the default #GtkHotkeyListener
65
73
 * for the current platform.
66
 
 *
67
 
 * FIXME: Currently hardcoded to X11
68
74
 */
69
75
GtkHotkeyListener*
70
76
gtk_hotkey_listener_get_default ()
71
77
{
72
 
        /* FIXME: This method should be changedd to use the same approach as
73
 
         * gtk_hotkey_registry_get_default() */
74
 
        
75
 
        if (default_listener) {
 
78
        if (G_UNLIKELY(default_listener == NULL)) {
 
79
                
 
80
                /* Set the default type of registry to create */
 
81
                if (default_listener_type == G_TYPE_INVALID)
 
82
                        default_listener_type = DEFAULT_LISTENER_TYPE;
 
83
                
 
84
                default_listener = GTK_HOTKEY_LISTENER (g_object_new (DEFAULT_LISTENER_TYPE,
 
85
                                                                                                                        NULL));
76
86
                g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(default_listener), NULL);
77
 
                return g_object_ref (default_listener);
 
87
                /* We always keep a ref to the listener here */
78
88
        }
79
 
        gtk_hotkey_listener_get_type (); /* This call makes sure the default type ise set */
80
 
        g_debug ("Listener Type: %s", g_type_name (default_listener_type));
81
 
        
82
 
        default_listener = g_object_new (default_listener_type, NULL);
83
 
        g_return_val_if_fail (GTK_HOTKEY_IS_LISTENER(default_listener), NULL);
84
 
        
85
89
        return g_object_ref (default_listener);
86
90
}
87
91
 
207
211
                                                                                                                          "GtkHotkeyListener",
208
212
                                                                                                                          &g_define_type_info,
209
213
                                                                                                                          G_TYPE_FLAG_ABSTRACT);
210
 
                
211
 
                default_listener_type = gtk_hotkey_x11_listener_get_type ();
212
214
        }
213
215
        return gtk_hotkey_listener_type_id;
214
216
}