Change the API of the keygrabber so only one gdk_sync is neccessary. (ticket #7999)
This commit is contained in:
parent
a73cbc351d
commit
3d3e453157
@ -102,12 +102,12 @@
|
||||
(return-type "GType")
|
||||
)
|
||||
|
||||
(define-method grab
|
||||
(define-method grab_keys
|
||||
(of-object "SugarKeyGrabber")
|
||||
(c-name "sugar_key_grabber_grab")
|
||||
(c-name "sugar_key_grabber_grab_keys")
|
||||
(return-type "none")
|
||||
(parameters
|
||||
'("const-char*" "key")
|
||||
'("const-char*[]" "keys")
|
||||
)
|
||||
)
|
||||
|
||||
|
@ -33,3 +33,48 @@ ignore-glob
|
||||
*_get_type
|
||||
_*
|
||||
%%
|
||||
override sugar_key_grabber_grab_keys kwargs
|
||||
static PyObject *
|
||||
_wrap_sugar_key_grabber_grab_keys(PyGObject *self, PyObject *args, PyObject *kwargs)
|
||||
{
|
||||
static char *kwlist[] = { "key", NULL };
|
||||
PyObject *py_keys;
|
||||
char **keys;
|
||||
int i, len;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args,kwargs,
|
||||
"O:SugarKeyGrabber.grab_keys",
|
||||
kwlist, &py_keys))
|
||||
return NULL;
|
||||
|
||||
if (!PySequence_Check(py_keys) || (len = PySequence_Size(py_keys)) < 0) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"keys should be a sequence of strings");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
keys = g_new(char*, len + 1);
|
||||
for (i = 0; i < len; i++) {
|
||||
PyObject *item = PySequence_GetItem(py_keys, i);
|
||||
if (!item) {
|
||||
g_free(keys);
|
||||
return NULL;
|
||||
}
|
||||
if (!PyString_Check(item)) {
|
||||
PyErr_SetString(PyExc_TypeError, "key must be a string");
|
||||
g_free(keys);
|
||||
Py_DECREF(item);
|
||||
return NULL;
|
||||
}
|
||||
keys[i] = PyString_AsString(item);
|
||||
Py_DECREF(item);
|
||||
}
|
||||
keys[len] = NULL;
|
||||
|
||||
sugar_key_grabber_grab_keys (SUGAR_KEY_GRABBER(self->obj), (const char**) keys);
|
||||
|
||||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
|
||||
%%
|
||||
|
@ -155,21 +155,15 @@ sugar_key_grabber_init(SugarKeyGrabber *grabber)
|
||||
* gnome-control-center/gnome-settings-daemon/gnome-settings-multimedia-keys.c
|
||||
*/
|
||||
|
||||
static gboolean
|
||||
static void
|
||||
grab_key_real (Key *key, GdkWindow *root, gboolean grab, int result)
|
||||
{
|
||||
gdk_error_trap_push ();
|
||||
if (grab)
|
||||
XGrabKey (GDK_DISPLAY(), key->keycode, (result | key->state),
|
||||
GDK_WINDOW_XID (root), True, GrabModeAsync, GrabModeAsync);
|
||||
else
|
||||
XUngrabKey(GDK_DISPLAY(), key->keycode, (result | key->state),
|
||||
GDK_WINDOW_XID (root));
|
||||
gdk_flush ();
|
||||
|
||||
gdk_error_trap_pop ();
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
#define N_BITS 32
|
||||
@ -198,18 +192,27 @@ grab_key (SugarKeyGrabber *grabber, Key *key, gboolean grab)
|
||||
result |= (1<<indexes[j]);
|
||||
}
|
||||
|
||||
if (grab_key_real (key, grabber->root, grab, result) == FALSE)
|
||||
return;
|
||||
grab_key_real (key, grabber->root, grab, result);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
sugar_key_grabber_grab(SugarKeyGrabber *grabber, const char *key)
|
||||
sugar_key_grabber_grab_keys(SugarKeyGrabber *grabber, const char **keys)
|
||||
{
|
||||
char **cur = keys;
|
||||
char *key;
|
||||
Key *keyinfo;
|
||||
|
||||
gdk_error_trap_push();
|
||||
|
||||
while (*cur != NULL) {
|
||||
key = *cur;
|
||||
cur += 1;
|
||||
|
||||
keyinfo = g_new0 (Key, 1);
|
||||
keyinfo->key = g_strdup(key);
|
||||
|
||||
egg_accelerator_parse_virtual (key, &keyinfo->keysym,
|
||||
&keyinfo->keycode, &keyinfo->state);
|
||||
|
||||
@ -218,6 +221,10 @@ sugar_key_grabber_grab(SugarKeyGrabber *grabber, const char *key)
|
||||
grabber->keys = g_list_append(grabber->keys, keyinfo);
|
||||
}
|
||||
|
||||
gdk_flush();
|
||||
gdk_error_trap_push();
|
||||
}
|
||||
|
||||
gboolean
|
||||
sugar_key_grabber_is_modifier(SugarKeyGrabber *grabber, guint keycode, guint mask)
|
||||
{
|
||||
|
@ -55,8 +55,8 @@ struct _SugarKeyGrabberClass {
|
||||
};
|
||||
|
||||
GType sugar_key_grabber_get_type (void);
|
||||
void sugar_key_grabber_grab (SugarKeyGrabber *grabber,
|
||||
const char *key);
|
||||
void sugar_key_grabber_grab_keys (SugarKeyGrabber *grabber,
|
||||
const char **keys);
|
||||
char *sugar_key_grabber_get_key (SugarKeyGrabber *grabber,
|
||||
guint keycode,
|
||||
guint state);
|
||||
|
Loading…
Reference in New Issue
Block a user