Hey,
Just for information, i have added, with the help of Philippe Caseiro
(Puppet_Master), some XKB support in ecore_x (xlib only for now).
ecore_xkb.diff : diff of ecore_x
ecore_x_kb.c : file to add in ecore_x/xlib
ecore_kbd.c : small test for the capslock, numlock and scrolllock
status. It displays the initial state, then when the state of the key is
modified, an event is sent and the new status is displayed
feel free to make comments, add ideas, etc...
If that initial support is sufficient for now, i can push it in svn (with
a modification of the name of the event, though)
Vincent
/* gcc -g -Wall -o ecore_kbd ecore_kbd.c `pkg-config --cflags --libs ecore
ecore-x` */
#include <stdio.h>
#include <X11/XKBlib.h>
#include <Ecore.h>
#include <Ecore_X.h>
#define NUM_LOCK_MASK 0x00000002
#define CAPS_LOCK_MASK 0x00000001
#define SCROLL_LOCK_MASK 0x00000004
int _cb(void *data, int type, void *event)
{
Ecore_X_Event_Kbd *ev;
ev = (Ecore_X_Event_Kbd *)event;
printf ("Caps Num Scroll\n");
printf ("%d %d %d\n",
(ev->state & CAPS_LOCK_MASK) == CAPS_LOCK_MASK,
(ev->state & NUM_LOCK_MASK) == NUM_LOCK_MASK,
(ev->state & SCROLL_LOCK_MASK) == SCROLL_LOCK_MASK);
return 1;
}
int main()
{
Eina_Bool capslock, numlock, scrolllock;
ecore_init();
ecore_x_init(NULL);
ecore_x_kb_events_select(1);
ecore_event_handler_add(ECORE_X_EVENT_KB_NOTIFY, _cb, NULL);
printf ("initial state :\n");
ecore_x_kb_led_state_get(&capslock, &numlock, &scrolllock);
printf ("Caps Num Scroll\n");
printf ("%d %d %d\n", capslock, numlock, scrolllock);
ecore_main_loop_begin();
return 0;
}
diff --git a/src/lib/ecore_x/Ecore_X.h b/src/lib/ecore_x/Ecore_X.h
index d48a68c..8fb5b3a 100644
--- a/src/lib/ecore_x/Ecore_X.h
+++ b/src/lib/ecore_x/Ecore_X.h
@@ -1800,6 +1800,21 @@ EAPI void ecore_x_composite_unredirect_subwindows(Ecore_X_Window wi
EAPI Ecore_X_Pixmap ecore_x_composite_name_window_pixmap_get(Ecore_X_Window win);
EAPI Ecore_X_Window ecore_x_composite_render_window_enable(Ecore_X_Window root);
EAPI void ecore_x_composite_render_window_disable(Ecore_X_Window root);
+
+/* XKb Extension Support */
+
+struct _Ecore_X_Event_Kbd {
+ int type;
+ unsigned long serial;
+ Bool send_event;
+ Ecore_X_Display *display;
+ Ecore_X_Time time;
+ int xkb_type;
+ unsigned int device;
+};
+
+typedef struct _Ecore_X_Event_Kbd Ecore_X_Event_Kbd;
+
/* XDamage Extension Support */
typedef Ecore_X_ID Ecore_X_Damage;
diff --git a/src/lib/ecore_x/xlib/ecore_x.c b/src/lib/ecore_x/xlib/ecore_x.c
index 547b7ba..57c6d69 100644
--- a/src/lib/ecore_x/xlib/ecore_x.c
+++ b/src/lib/ecore_x/xlib/ecore_x.c
@@ -49,6 +49,9 @@ static int _ecore_x_event_fixes_selection_id = 0;
#ifdef ECORE_XDAMAGE
static int _ecore_x_event_damage_id = 0;
#endif
+#ifdef ECORE_XKB
+static int _ecore_x_event_kb_id = 0;
+#endif
static int _ecore_x_event_handlers_num = 0;
static void (**_ecore_x_event_handlers) (XEvent * event) = NULL;
@@ -233,6 +236,11 @@ ecore_x_init(const char *name)
int damage_base = 0;
int damage_err_base = 0;
#endif
+#ifdef ECORE_XKB
+ int kbop_rtrn;
+ int kb_base = 0;
+ int *kb_err_base = 0;
+#endif
if (++_ecore_x_init_count != 1)
return _ecore_x_init_count;
@@ -305,6 +313,12 @@ ecore_x_init(const char *name)
ECORE_X_EVENT_HANDLERS_GROW(damage_base, XDamageNumberEvents);
#endif
+#ifdef ECORE_XKB
+ if (XkbQueryExtension(_ecore_x_disp, &kb_code, &kb_base, &kb_err_base, &kb_major, &kb_minor))
+ _ecore_x_event_kb_id = kb_base;
+ ECORE_X_EVENT_HANDLERS_GROW(kb_base, XkbNumberEvents);
+#endif
+
_ecore_x_event_handlers = calloc(_ecore_x_event_handlers_num, sizeof(void *));
if (!_ecore_x_event_handlers)
goto close_display;
@@ -376,6 +390,9 @@ ecore_x_init(const char *name)
_ecore_x_event_handlers[_ecore_x_event_damage_id] = _ecore_x_event_handle_damage_notify;
#endif
#ifdef ECORE_XKB
+ if (_ecore_x_event_kb_id)
+ _ecore_x_event_handlers[_ecore_x_event_kb_id] = _ecore_x_event_kb_notify;
+
// set x autorepeat detection to on. that means instead of
// press-release-press-release-press-release
// you get
diff --git a/src/lib/ecore_x/xlib/ecore_x_events.c b/src/lib/ecore_x/xlib/ecore_x_events.c
index a30f610..121c8a3 100644
--- a/src/lib/ecore_x/xlib/ecore_x_events.c
+++ b/src/lib/ecore_x/xlib/ecore_x_events.c
@@ -2086,6 +2086,13 @@ _ecore_x_event_handle_damage_notify(XEvent *event)
ecore_event_add(ECORE_X_EVENT_DAMAGE_NOTIFY, e, NULL, NULL);
}
#endif
+#ifdef ECORE_XKB
+void
+_ecore_x_event_handle_kb_notify(XEvent *event);
+{
+ TODO
+}
+#endif
static void
_ecore_x_event_free_generic_event(void *data, void *ev)
diff --git a/src/lib/ecore_x/xlib/ecore_x_kb.c b/src/lib/ecore_x/xlib/ecore_x_kb.c
new file mode 100644
index 0000000..769d613
--- /dev/null
+++ b/src/lib/ecore_x/xlib/ecore_x_kb.c
@@ -0,0 +1,49 @@
+/*
+ * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+
+#include "ecore_x_private.h"
+#include "Ecore_X.h"
+
+static int _xkb_available;
+#ifdef ECORE_XKB
+static int _xkb_major, _xkb_minor;
+#endif
+
+void
+_ecore_x_kb_init(void)
+{
+#ifdef ECORE_XKB
+ _xkb_major = 1;
+ _xkb_minor = 0;
+
+ LOGFN(__FILE__, __LINE__, __FUNCTION__);
+ if (XkbLibraryVersion(&_xkb_major, &_xkb_minor))
+ _xkb_available = 1;
+ else
+ _xkb_available = 0;
+#else
+ _xkb_available = 0;
+#endif
+}
+
+EAPI int
+ecore_x_kb_query(void)
+{
+ return _xkb_available;
+}
+
+EAPI bool
+ecore_x_kb_select_events(unsigned int dev, unsigned long int bits_to_change, unsigned long int values_for_bits)
+{
+
+ if (XkbSelectEvents(_ecore_x_disp, dev, bits_to_change, values_for_bits))
+ return 1;
+
+ return 0;
+}
/*
* vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include "ecore_x_private.h"
#include "Ecore_X.h"
static int _xkb_available = 0;
#ifdef ECORE_XKB
static int _xkb_major = 1;
static int _xkb_minor = 0;
#endif
void
_ecore_x_kb_init(void)
{
#ifdef ECORE_XKB
LOGFN(__FILE__, __LINE__, __FUNCTION__);
if (XkbLibraryVersion(&_xkb_major, &_xkb_minor))
_xkb_available = 1;
#endif
}
EAPI int
ecore_x_kb_query(void)
{
return _xkb_available;
}
EAPI int
ecore_x_kb_events_select(int on)
{
#ifdef ECORE_XKB
Eina_Bool ret;
if (on)
{
ret = 1;
ret &= XkbSelectEvents(_ecore_x_disp,
XkbUseCoreKbd,
XkbIndicatorStateNotifyMask,
XkbIndicatorStateNotifyMask);
/* add more events here */
}
else
{
ret = XkbSelectEvents(_ecore_x_disp, XkbUseCoreKbd, XkbAllEventsMask,
0);
}
return ret;
#else
return 0;
#endif
}
EAPI void
ecore_x_kb_led_state_get(Eina_Bool *capslock, Eina_Bool *numlock, Eina_Bool
*scrolllock)
{
#ifdef ECORE_XKB
unsigned int state;
if (XkbGetIndicatorState(_ecore_x_disp, XkbUseCoreKbd, &state) == Success)
{
if (capslock)
*capslock = ((state & 1) == 1);
if (numlock)
*numlock = ((state & 2) == 2);
if (scrolllock)
*scrolllock = ((state & 4) == 4);
}
else
{
if (capslock)
*capslock = 0;
if (numlock)
*numlock = 0;
if (scrolllock)
*scrolllock =0;
}
#else
if (capslock)
*capslock = 0;
if (numlock)
*numlock = 0;
if (scrolllock)
*scrolllock =0;
#endif
}
------------------------------------------------------------------------------
Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev
_______________________________________________
enlightenment-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/enlightenment-devel