~kroq-gar78/ubuntu/precise/gnome-control-center/fix-885947

« back to all changes in this revision

Viewing changes to panels/keyboard/wm-common.c

  • Committer: Bazaar Package Importer
  • Author(s): Rodrigo Moya
  • Date: 2011-05-17 10:47:27 UTC
  • mfrom: (0.1.11 experimental) (1.1.45 upstream)
  • Revision ID: james.westby@ubuntu.com-20110517104727-lqel6m8vhfw5jby1
Tags: 1:3.0.1.1-1ubuntu1
* Rebase on Debian, remaining Ubuntu changes:
* debian/control:
  - Build-Depend on hardening-wrapper, dpkg-dev and dh-autoreconf
  - Add dependency on ubuntu-system-service
  - Remove dependency on gnome-icon-theme-symbolic
  - Move dependency on apg, gnome-icon-theme-symbolic and accountsservice to
    be a Recommends: until we get them in main
* debian/rules:
  - Use autoreconf
  - Add binary-post-install rule for gnome-control-center-data
  - Run dh-autoreconf
* debian/gnome-control-center.dirs:
* debian/gnome-control-center.links:
  - Add a link to the control center shell for indicators
* debian/patches/00_disable-nm.patch:
  - Temporary patch to disable building with NetworkManager until we get
    the new one in the archive
* debian/patches/01_git_remove_gettext_calls.patch:
  - Remove calls to AM_GNU_GETTEXT, IT_PROG_INTLTOOL should be enough
* debian/patches/01_git_kill_warning.patch:
  - Kill warning
* debian/patches/50_ubuntu_systemwide_prefs.patch:
  - Ubuntu specific proxy preferences
* debian/patches/51_ubuntu_system_keyboard.patch:
  - Implement the global keyboard spec at https://wiki.ubuntu.com/DefaultKeyboardSettings

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <X11/Xatom.h>
 
2
#include <gdk/gdkx.h>
 
3
#include <gdk/gdk.h>
 
4
#include <string.h>
 
5
#include <glib.h>
 
6
#include <glib-object.h>
 
7
#include "wm-common.h"
 
8
 
 
9
typedef struct _WMCallbackData
 
10
{
 
11
  GFunc func;
 
12
  gpointer data;
 
13
} WMCallbackData;
 
14
 
 
15
/* Our WM Window */
 
16
static Window wm_window = None;
 
17
 
 
18
static char *
 
19
wm_common_get_window_manager_property (Atom atom)
 
20
{
 
21
  Atom utf8_string, type;
 
22
  int result;
 
23
  char *retval;
 
24
  int format;
 
25
  gulong nitems;
 
26
  gulong bytes_after;
 
27
  gchar *val;
 
28
 
 
29
  if (wm_window == None)
 
30
    return NULL;
 
31
 
 
32
  utf8_string = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "UTF8_STRING", False);
 
33
 
 
34
  gdk_error_trap_push ();
 
35
 
 
36
  val = NULL;
 
37
  result = XGetWindowProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),
 
38
                               wm_window,
 
39
                               atom,
 
40
                               0, G_MAXLONG,
 
41
                               False, utf8_string,
 
42
                               &type, &format, &nitems,
 
43
                               &bytes_after, (guchar **) &val);
 
44
 
 
45
  if (gdk_error_trap_pop () || result != Success ||
 
46
      type != utf8_string || format != 8 || nitems == 0 ||
 
47
      !g_utf8_validate (val, nitems, NULL))
 
48
    {
 
49
      retval = NULL;
 
50
    }
 
51
  else
 
52
    {
 
53
      retval = g_strndup (val, nitems);
 
54
    }
 
55
 
 
56
  if (val)
 
57
    XFree (val);
 
58
 
 
59
  return retval;
 
60
}
 
61
 
 
62
char*
 
63
wm_common_get_current_window_manager (void)
 
64
{
 
65
  Atom atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_NET_WM_NAME", False);
 
66
  char *result;
 
67
 
 
68
  result = wm_common_get_window_manager_property (atom);
 
69
  if (result)
 
70
    return result;
 
71
  else
 
72
    return g_strdup (WM_COMMON_UNKNOWN);
 
73
}
 
74
 
 
75
char**
 
76
wm_common_get_current_keybindings (void)
 
77
{
 
78
  Atom keybindings_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_GNOME_WM_KEYBINDINGS", False);
 
79
  char *keybindings = wm_common_get_window_manager_property (keybindings_atom);
 
80
  char **results;
 
81
 
 
82
  if (keybindings)
 
83
    {
 
84
      char **p;
 
85
      results = g_strsplit(keybindings, ",", -1);
 
86
      for (p = results; *p; p++)
 
87
        g_strstrip (*p);
 
88
      g_free (keybindings);
 
89
    }
 
90
  else
 
91
    {
 
92
      Atom wm_atom = XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_NET_WM_NAME", False);
 
93
      char *wm_name = wm_common_get_window_manager_property (wm_atom);
 
94
      char *to_copy[] = { NULL, NULL };
 
95
 
 
96
      to_copy[0] = wm_name ? wm_name : WM_COMMON_UNKNOWN;
 
97
 
 
98
      results = g_strdupv (to_copy);
 
99
      g_free (wm_name);
 
100
    }
 
101
 
 
102
  return results;
 
103
}
 
104
 
 
105
static void
 
106
update_wm_window (void)
 
107
{
 
108
  Window *xwindow;
 
109
  Atom type;
 
110
  gint format;
 
111
  gulong nitems;
 
112
  gulong bytes_after;
 
113
 
 
114
  XGetWindowProperty (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_ROOT_WINDOW (),
 
115
                      XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_NET_SUPPORTING_WM_CHECK", False),
 
116
                      0, G_MAXLONG, False, XA_WINDOW, &type, &format,
 
117
                      &nitems, &bytes_after, (guchar **) &xwindow);
 
118
 
 
119
  if (type != XA_WINDOW)
 
120
    {
 
121
      wm_window = None;
 
122
     return;
 
123
    }
 
124
 
 
125
  gdk_error_trap_push ();
 
126
  XSelectInput (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), *xwindow, StructureNotifyMask | PropertyChangeMask);
 
127
  XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
 
128
 
 
129
  if (gdk_error_trap_pop ())
 
130
    {
 
131
       XFree (xwindow);
 
132
       wm_window = None;
 
133
       return;
 
134
    }
 
135
 
 
136
    wm_window = *xwindow;
 
137
    XFree (xwindow);
 
138
}
 
139
 
 
140
static GdkFilterReturn
 
141
wm_window_event_filter (GdkXEvent *xev,
 
142
                        GdkEvent  *event,
 
143
                        gpointer   data)
 
144
{
 
145
  WMCallbackData *ncb_data = (WMCallbackData*) data;
 
146
  XEvent *xevent = (XEvent *)xev;
 
147
 
 
148
  if ((xevent->type == DestroyNotify &&
 
149
       wm_window != None && xevent->xany.window == wm_window) ||
 
150
      (xevent->type == PropertyNotify &&
 
151
       xevent->xany.window == GDK_ROOT_WINDOW () &&
 
152
       xevent->xproperty.atom == (XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()),  "_NET_SUPPORTING_WM_CHECK", False))) ||
 
153
      (xevent->type == PropertyNotify &&
 
154
       wm_window != None && xevent->xany.window == wm_window &&
 
155
       xevent->xproperty.atom == (XInternAtom (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), "_NET_WM_NAME", False))))
 
156
    {
 
157
      update_wm_window ();
 
158
      (* ncb_data->func) ((gpointer)wm_common_get_current_window_manager(),
 
159
                          ncb_data->data);
 
160
    }
 
161
 
 
162
  return GDK_FILTER_CONTINUE;
 
163
}
 
164
 
 
165
void
 
166
wm_common_register_window_manager_change (GFunc    func,
 
167
                                          gpointer data)
 
168
{
 
169
  WMCallbackData *ncb_data;
 
170
 
 
171
  ncb_data = g_new0 (WMCallbackData, 1);
 
172
 
 
173
  ncb_data->func = func;
 
174
  ncb_data->data = data;
 
175
 
 
176
  gdk_window_add_filter (NULL, wm_window_event_filter, ncb_data);
 
177
 
 
178
  update_wm_window ();
 
179
 
 
180
  XSelectInput (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), GDK_ROOT_WINDOW (), PropertyChangeMask);
 
181
  XSync (GDK_DISPLAY_XDISPLAY (gdk_display_get_default ()), False);
 
182
}
 
183
 
 
184