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")
|
(return-type "GType")
|
||||||
)
|
)
|
||||||
|
|
||||||
(define-method grab
|
(define-method grab_keys
|
||||||
(of-object "SugarKeyGrabber")
|
(of-object "SugarKeyGrabber")
|
||||||
(c-name "sugar_key_grabber_grab")
|
(c-name "sugar_key_grabber_grab_keys")
|
||||||
(return-type "none")
|
(return-type "none")
|
||||||
(parameters
|
(parameters
|
||||||
'("const-char*" "key")
|
'("const-char*[]" "keys")
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -33,3 +33,48 @@ ignore-glob
|
|||||||
*_get_type
|
*_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
|
* 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)
|
grab_key_real (Key *key, GdkWindow *root, gboolean grab, int result)
|
||||||
{
|
{
|
||||||
gdk_error_trap_push ();
|
|
||||||
if (grab)
|
if (grab)
|
||||||
XGrabKey (GDK_DISPLAY(), key->keycode, (result | key->state),
|
XGrabKey (GDK_DISPLAY(), key->keycode, (result | key->state),
|
||||||
GDK_WINDOW_XID (root), True, GrabModeAsync, GrabModeAsync);
|
GDK_WINDOW_XID (root), True, GrabModeAsync, GrabModeAsync);
|
||||||
else
|
else
|
||||||
XUngrabKey(GDK_DISPLAY(), key->keycode, (result | key->state),
|
XUngrabKey(GDK_DISPLAY(), key->keycode, (result | key->state),
|
||||||
GDK_WINDOW_XID (root));
|
GDK_WINDOW_XID (root));
|
||||||
gdk_flush ();
|
|
||||||
|
|
||||||
gdk_error_trap_pop ();
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#define N_BITS 32
|
#define N_BITS 32
|
||||||
@ -198,24 +192,37 @@ grab_key (SugarKeyGrabber *grabber, Key *key, gboolean grab)
|
|||||||
result |= (1<<indexes[j]);
|
result |= (1<<indexes[j]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (grab_key_real (key, grabber->root, grab, result) == FALSE)
|
grab_key_real (key, grabber->root, grab, result);
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
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;
|
Key *keyinfo;
|
||||||
|
|
||||||
keyinfo = g_new0 (Key, 1);
|
gdk_error_trap_push();
|
||||||
keyinfo->key = g_strdup(key);
|
|
||||||
egg_accelerator_parse_virtual (key, &keyinfo->keysym,
|
|
||||||
&keyinfo->keycode, &keyinfo->state);
|
|
||||||
|
|
||||||
grab_key(grabber, keyinfo, TRUE);
|
while (*cur != NULL) {
|
||||||
|
key = *cur;
|
||||||
|
cur += 1;
|
||||||
|
|
||||||
|
keyinfo = g_new0 (Key, 1);
|
||||||
|
keyinfo->key = g_strdup(key);
|
||||||
|
|
||||||
grabber->keys = g_list_append(grabber->keys, keyinfo);
|
egg_accelerator_parse_virtual (key, &keyinfo->keysym,
|
||||||
|
&keyinfo->keycode, &keyinfo->state);
|
||||||
|
|
||||||
|
grab_key(grabber, keyinfo, TRUE);
|
||||||
|
|
||||||
|
grabber->keys = g_list_append(grabber->keys, keyinfo);
|
||||||
|
}
|
||||||
|
|
||||||
|
gdk_flush();
|
||||||
|
gdk_error_trap_push();
|
||||||
}
|
}
|
||||||
|
|
||||||
gboolean
|
gboolean
|
||||||
|
@ -55,8 +55,8 @@ struct _SugarKeyGrabberClass {
|
|||||||
};
|
};
|
||||||
|
|
||||||
GType sugar_key_grabber_get_type (void);
|
GType sugar_key_grabber_get_type (void);
|
||||||
void sugar_key_grabber_grab (SugarKeyGrabber *grabber,
|
void sugar_key_grabber_grab_keys (SugarKeyGrabber *grabber,
|
||||||
const char *key);
|
const char **keys);
|
||||||
char *sugar_key_grabber_get_key (SugarKeyGrabber *grabber,
|
char *sugar_key_grabber_get_key (SugarKeyGrabber *grabber,
|
||||||
guint keycode,
|
guint keycode,
|
||||||
guint state);
|
guint state);
|
||||||
|
Loading…
Reference in New Issue
Block a user