summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-11-16 13:00:21 +0000
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2019-11-16 13:02:10 +0000
commit42e691d9b4de72755747a376655663b1079bb592 (patch)
tree0fe394ca0e8e3251afdf401e5ada70b5f34c53ba
parent7096634a3969fdef8e8b3d13a70d034cc0ea41e8 (diff)
ecore-x - add some xi2 api's for fiddling with device properties
add some infra to be able to get and set device properties (as well as know if devices changed to we can refersh a gui or re-apply saved settings etc.). it doesn't do everything but... it adds enough to build on in e.
-rw-r--r--src/lib/ecore_x/Ecore_X.h11
-rw-r--r--src/lib/ecore_x/Ecore_X_Atoms.h2
-rw-r--r--src/lib/ecore_x/ecore_x.c4
-rw-r--r--src/lib/ecore_x/ecore_x_atoms_decl.h4
-rw-r--r--src/lib/ecore_x/ecore_x_xi2.c179
5 files changed, 200 insertions, 0 deletions
diff --git a/src/lib/ecore_x/Ecore_X.h b/src/lib/ecore_x/Ecore_X.h
index 223bc912ae..7d4423048b 100644
--- a/src/lib/ecore_x/Ecore_X.h
+++ b/src/lib/ecore_x/Ecore_X.h
@@ -1197,6 +1197,8 @@ EAPI extern int ECORE_X_RAW_BUTTON_PRESS; /**< @since 1.8 */
1197EAPI extern int ECORE_X_RAW_BUTTON_RELEASE; /**< @since 1.8 */ 1197EAPI extern int ECORE_X_RAW_BUTTON_RELEASE; /**< @since 1.8 */
1198EAPI extern int ECORE_X_RAW_MOTION; /**< @since 1.8 */ 1198EAPI extern int ECORE_X_RAW_MOTION; /**< @since 1.8 */
1199 1199
1200EAPI extern int ECORE_X_DEVICES_CHANGE; /**< @since 1.24 */
1201
1200typedef enum _Ecore_X_WM_Protocol 1202typedef enum _Ecore_X_WM_Protocol
1201{ 1203{
1202 /** If enabled the window manager will be asked to send a 1204 /** If enabled the window manager will be asked to send a
@@ -2568,6 +2570,15 @@ EAPI Eina_Bool ecore_x_input_raw_select(Ecore_X_Window win); /**< @since 1.8
2568EAPI Eina_Bool ecore_x_input_touch_devices_grab(Ecore_X_Window win); /**< @since 1.15 */ 2570EAPI Eina_Bool ecore_x_input_touch_devices_grab(Ecore_X_Window win); /**< @since 1.15 */
2569EAPI Eina_Bool ecore_x_input_touch_devices_ungrab(void); /**< @since 1.15 */ 2571EAPI Eina_Bool ecore_x_input_touch_devices_ungrab(void); /**< @since 1.15 */
2570 2572
2573EAPI void ecore_x_input_devices_update(void); /**< @since 1.24 */
2574EAPI int ecore_x_input_device_num_get(void); /**< @since 1.24 */
2575EAPI int ecore_x_input_device_id_get(int slot); /**< @since 1.24 */
2576EAPI const char *ecore_x_input_device_name_get(int slot); /**< @since 1.24 */
2577EAPI char **ecore_x_input_device_properties_list(int slot, int *num_ret); /**< @since 1.24 */
2578EAPI void ecore_x_input_device_properties_free(char **list, int num); /**< @since 1.24 */
2579EAPI void *ecore_x_input_device_property_get(int slot, const char *prop, int *num_ret, Ecore_X_Atom *format_ret, int *unit_size_ret); /**< @since 1.24 */
2580EAPI void ecore_x_input_device_property_set(int slot, const char *prop, void *data, int num, Ecore_X_Atom format, int unit_size); /**< @since 1.24 */
2581
2571EAPI Eina_Bool ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win); 2582EAPI Eina_Bool ecore_x_vsync_animator_tick_source_set(Ecore_X_Window win);
2572 2583
2573typedef enum _Ecore_X_Gesture_Event_Mask 2584typedef enum _Ecore_X_Gesture_Event_Mask
diff --git a/src/lib/ecore_x/Ecore_X_Atoms.h b/src/lib/ecore_x/Ecore_X_Atoms.h
index 15c8037c97..35f3a885c2 100644
--- a/src/lib/ecore_x/Ecore_X_Atoms.h
+++ b/src/lib/ecore_x/Ecore_X_Atoms.h
@@ -9,6 +9,8 @@
9/* generic atoms */ 9/* generic atoms */
10EAPI extern Ecore_X_Atom ECORE_X_ATOM_ATOM; 10EAPI extern Ecore_X_Atom ECORE_X_ATOM_ATOM;
11EAPI extern Ecore_X_Atom ECORE_X_ATOM_CARDINAL; 11EAPI extern Ecore_X_Atom ECORE_X_ATOM_CARDINAL;
12EAPI extern Ecore_X_Atom ECORE_X_ATOM_INTEGER; /**< @since 1.24 */
13EAPI extern Ecore_X_Atom ECORE_X_ATOM_FLOAT; /**< @since 1.24 */
12EAPI extern Ecore_X_Atom ECORE_X_ATOM_COMPOUND_TEXT; 14EAPI extern Ecore_X_Atom ECORE_X_ATOM_COMPOUND_TEXT;
13EAPI extern Ecore_X_Atom ECORE_X_ATOM_FILE_NAME; 15EAPI extern Ecore_X_Atom ECORE_X_ATOM_FILE_NAME;
14EAPI extern Ecore_X_Atom ECORE_X_ATOM_STRING; 16EAPI extern Ecore_X_Atom ECORE_X_ATOM_STRING;
diff --git a/src/lib/ecore_x/ecore_x.c b/src/lib/ecore_x/ecore_x.c
index a32f42f641..cbe2d137cd 100644
--- a/src/lib/ecore_x/ecore_x.c
+++ b/src/lib/ecore_x/ecore_x.c
@@ -167,6 +167,8 @@ EAPI int ECORE_X_RAW_BUTTON_PRESS = 0;
167EAPI int ECORE_X_RAW_BUTTON_RELEASE = 0; 167EAPI int ECORE_X_RAW_BUTTON_RELEASE = 0;
168EAPI int ECORE_X_RAW_MOTION = 0; 168EAPI int ECORE_X_RAW_MOTION = 0;
169 169
170EAPI int ECORE_X_DEVICES_CHANGE = 0;
171
170#ifdef LOGRT 172#ifdef LOGRT
171static double t0 = 0.0; 173static double t0 = 0.0;
172static Status (*_logrt_real_reply)(Display *disp, 174static Status (*_logrt_real_reply)(Display *disp,
@@ -655,6 +657,8 @@ _ecore_x_init2(void)
655 ECORE_X_RAW_BUTTON_RELEASE = ecore_event_type_new(); 657 ECORE_X_RAW_BUTTON_RELEASE = ecore_event_type_new();
656 ECORE_X_RAW_MOTION = ecore_event_type_new(); 658 ECORE_X_RAW_MOTION = ecore_event_type_new();
657 659
660 ECORE_X_DEVICES_CHANGE = ecore_event_type_new();
661
658 _ecore_x_modifiers_get(); 662 _ecore_x_modifiers_get();
659 663
660 _ecore_x_atoms_init(); 664 _ecore_x_atoms_init();
diff --git a/src/lib/ecore_x/ecore_x_atoms_decl.h b/src/lib/ecore_x/ecore_x_atoms_decl.h
index 78545c7d5e..c4d8ead63f 100644
--- a/src/lib/ecore_x/ecore_x_atoms_decl.h
+++ b/src/lib/ecore_x/ecore_x_atoms_decl.h
@@ -1,6 +1,8 @@
1/* generic atoms */ 1/* generic atoms */
2EAPI Ecore_X_Atom ECORE_X_ATOM_ATOM = 0; 2EAPI Ecore_X_Atom ECORE_X_ATOM_ATOM = 0;
3EAPI Ecore_X_Atom ECORE_X_ATOM_CARDINAL = 0; 3EAPI Ecore_X_Atom ECORE_X_ATOM_CARDINAL = 0;
4EAPI Ecore_X_Atom ECORE_X_ATOM_INTEGER = 0;
5EAPI Ecore_X_Atom ECORE_X_ATOM_FLOAT = 0;
4EAPI Ecore_X_Atom ECORE_X_ATOM_COMPOUND_TEXT = 0; 6EAPI Ecore_X_Atom ECORE_X_ATOM_COMPOUND_TEXT = 0;
5EAPI Ecore_X_Atom ECORE_X_ATOM_FILE_NAME = 0; 7EAPI Ecore_X_Atom ECORE_X_ATOM_FILE_NAME = 0;
6EAPI Ecore_X_Atom ECORE_X_ATOM_STRING = 0; 8EAPI Ecore_X_Atom ECORE_X_ATOM_STRING = 0;
@@ -398,6 +400,8 @@ const Atom_Item atom_items[] =
398{ 400{
399 { "ATOM", &ECORE_X_ATOM_ATOM }, 401 { "ATOM", &ECORE_X_ATOM_ATOM },
400 { "CARDINAL", &ECORE_X_ATOM_CARDINAL }, 402 { "CARDINAL", &ECORE_X_ATOM_CARDINAL },
403 { "INTEGER", &ECORE_X_ATOM_INTEGER },
404 { "FLOAT", &ECORE_X_ATOM_FLOAT },
401 { "COMPOUND_TEXT", &ECORE_X_ATOM_COMPOUND_TEXT }, 405 { "COMPOUND_TEXT", &ECORE_X_ATOM_COMPOUND_TEXT },
402 { "FILE_NAME", &ECORE_X_ATOM_FILE_NAME }, 406 { "FILE_NAME", &ECORE_X_ATOM_FILE_NAME },
403 { "STRING", &ECORE_X_ATOM_STRING }, 407 { "STRING", &ECORE_X_ATOM_STRING },
diff --git a/src/lib/ecore_x/ecore_x_xi2.c b/src/lib/ecore_x/ecore_x_xi2.c
index 089c2a7029..6bbbd855b6 100644
--- a/src/lib/ecore_x/ecore_x_xi2.c
+++ b/src/lib/ecore_x/ecore_x_xi2.c
@@ -36,6 +36,7 @@ typedef struct _Ecore_X_Touch_Device_Info
36} Ecore_X_Touch_Device_Info; 36} Ecore_X_Touch_Device_Info;
37#endif /* ifdef ECORE_XI2_2 */ 37#endif /* ifdef ECORE_XI2_2 */
38 38
39static Ecore_Job *update_devices_job = NULL;
39static XIDeviceInfo *_ecore_x_xi2_devs = NULL; 40static XIDeviceInfo *_ecore_x_xi2_devs = NULL;
40static int _ecore_x_xi2_num = 0; 41static int _ecore_x_xi2_num = 0;
41#ifdef ECORE_XI2_2 42#ifdef ECORE_XI2_2
@@ -64,6 +65,18 @@ _ecore_x_input_init(void)
64 return; 65 return;
65 } 66 }
66 67
68 // listen for device changes
69 XIEventMask m;
70 m.deviceid = XIAllDevices;
71 m.mask_len = XIMaskLen(XI_LASTEVENT);
72 m.mask = calloc( m.mask_len, 1);
73 if (!m.mask) return;
74 XISetMask(m.mask, XI_DeviceChanged);
75 XISetMask(m.mask, XI_HierarchyChanged);
76 XISetMask(m.mask, XI_PropertyEvent);
77 XISelectEvents(_ecore_x_disp, DefaultRootWindow(_ecore_x_disp), &m, 1);
78 free(m.mask);
79
67 _ecore_x_xi2_devs = XIQueryDevice(_ecore_x_disp, XIAllDevices, 80 _ecore_x_xi2_devs = XIQueryDevice(_ecore_x_disp, XIAllDevices,
68 &_ecore_x_xi2_num); 81 &_ecore_x_xi2_num);
69#endif /* ifdef ECORE_XI2 */ 82#endif /* ifdef ECORE_XI2 */
@@ -130,6 +143,15 @@ _ecore_x_input_get_axis_label(char *axis_name)
130void 143void
131_ecore_x_input_shutdown(void) 144_ecore_x_input_shutdown(void)
132{ 145{
146 XIEventMask m;
147 m.deviceid = XIAllDevices;
148 m.mask_len = XIMaskLen(XI_LASTEVENT);
149 m.mask = calloc( m.mask_len, 1);
150 if (m.mask)
151 {
152 XISelectEvents(_ecore_x_disp, DefaultRootWindow(_ecore_x_disp), &m, 1);
153 free(m.mask);
154 }
133#ifdef ECORE_XI2 155#ifdef ECORE_XI2
134 if (_ecore_x_xi2_devs) 156 if (_ecore_x_xi2_devs)
135 { 157 {
@@ -147,6 +169,8 @@ _ecore_x_input_shutdown(void)
147 eina_list_free(_ecore_x_xi2_grabbed_devices_list); 169 eina_list_free(_ecore_x_xi2_grabbed_devices_list);
148 _ecore_x_xi2_grabbed_devices_list = NULL; 170 _ecore_x_xi2_grabbed_devices_list = NULL;
149#endif /* ifdef ECORE_XI2 */ 171#endif /* ifdef ECORE_XI2 */
172 if (update_devices_job) ecore_job_del(update_devices_job);
173 update_devices_job = NULL;
150} 174}
151 175
152#ifdef ECORE_XI2 176#ifdef ECORE_XI2
@@ -655,6 +679,14 @@ _ecore_x_input_device_lookup(int deviceid)
655} 679}
656#endif 680#endif
657 681
682static void
683_cb_update_devices(void *data EINA_UNUSED)
684{
685 update_devices_job = NULL;
686 ecore_x_input_devices_update();
687 ecore_event_add(ECORE_X_DEVICES_CHANGE, NULL, NULL, NULL);
688}
689
658void 690void
659_ecore_x_input_handler(XEvent *xevent) 691_ecore_x_input_handler(XEvent *xevent)
660{ 692{
@@ -663,6 +695,14 @@ _ecore_x_input_handler(XEvent *xevent)
663 695
664 switch (xevent->xcookie.evtype) 696 switch (xevent->xcookie.evtype)
665 { 697 {
698 case XI_DeviceChanged:
699 case XI_HierarchyChanged:
700 case XI_PropertyEvent:
701 if (update_devices_job) ecore_job_del(update_devices_job);
702 update_devices_job = ecore_job_add(_cb_update_devices, NULL);
703 // XXX: post change event
704 break;
705
666 case XI_RawMotion: 706 case XI_RawMotion:
667 case XI_RawButtonPress: 707 case XI_RawButtonPress:
668 case XI_RawButtonRelease: 708 case XI_RawButtonRelease:
@@ -904,3 +944,142 @@ ecore_x_input_touch_devices_ungrab(void)
904{ 944{
905 return _ecore_x_input_touch_devices_grab(0, EINA_FALSE); 945 return _ecore_x_input_touch_devices_grab(0, EINA_FALSE);
906} 946}
947
948// XXX
949EAPI void
950ecore_x_input_devices_update(void)
951{
952 if (_ecore_x_xi2_devs) XIFreeDeviceInfo(_ecore_x_xi2_devs);
953 _ecore_x_xi2_num = 0;
954 _ecore_x_xi2_devs = XIQueryDevice(_ecore_x_disp, XIAllDevices,
955 &_ecore_x_xi2_num);
956}
957
958EAPI int
959ecore_x_input_device_num_get(void)
960{
961 return _ecore_x_xi2_num;
962}
963
964EAPI int
965ecore_x_input_device_id_get(int slot)
966{
967 if ((slot < 0) || (slot >= _ecore_x_xi2_num)) return 0;
968 return _ecore_x_xi2_devs[slot].deviceid;
969}
970
971EAPI const char *
972ecore_x_input_device_name_get(int slot)
973{
974 if ((slot < 0) || (slot >= _ecore_x_xi2_num)) return NULL;
975 return _ecore_x_xi2_devs[slot].name;
976}
977
978EAPI char **
979ecore_x_input_device_properties_list(int slot, int *num_ret)
980{
981 char **atoms = NULL;
982 int num = 0, i;
983 Atom *a;
984
985 if ((slot < 0) || (slot >= _ecore_x_xi2_num)) goto err;
986 a = XIListProperties(_ecore_x_disp, _ecore_x_xi2_devs[slot].deviceid, &num);
987 if (!a) goto err;
988 atoms = calloc(num, sizeof(char *));
989 if (!atoms) goto err;
990 for (i = 0; i < num; i++)
991 {
992 Ecore_X_Atom at = a[i];
993 atoms[i] = ecore_x_atom_name_get(at);
994 if (!atoms[i]) goto err;
995 }
996 XFree(a);
997 *num_ret = num;
998 return atoms;
999err:
1000 if (atoms)
1001 {
1002 for (i = 0; i < num; i++) free(atoms[i]);
1003 free(atoms);
1004 }
1005 *num_ret = 0;
1006 return NULL;
1007}
1008
1009EAPI void
1010ecore_x_input_device_properties_free(char **list, int num)
1011{
1012 int i;
1013
1014 for (i = 0; i < num; i++) free(list[i]);
1015 free(list);
1016}
1017
1018// unit_size_ret will be 8, 16, 32
1019// fromat_ret will almost be one of:
1020// ECORE_X_ATOM_CARDINAL
1021// ECORE_X_ATOM_INTEGER
1022// ECORE_X_ATOM_FLOAT (unit_size 32 only)
1023// ECORE_X_ATOM_ATOM // very rare
1024// ECORE_X_ATOM_STRING (unit_size 8 only - guaratee nul termination)
1025
1026EAPI void *
1027ecore_x_input_device_property_get(int slot, const char *prop, int *num_ret,
1028 Ecore_X_Atom *format_ret, int *unit_size_ret)
1029{
1030 Atom a, a_type = 0;
1031 int fmt = 0;
1032 unsigned long num = 0, dummy;
1033 unsigned char *data = NULL;
1034 unsigned char *d = NULL;
1035
1036 if ((slot < 0) || (slot >= _ecore_x_xi2_num)) goto err;
1037 a = XInternAtom(_ecore_x_disp, prop, False);
1038 if (!XIGetProperty(_ecore_x_disp, _ecore_x_xi2_devs[slot].deviceid,
1039 a, 0, 65536, False, AnyPropertyType, &a_type, &fmt,
1040 &num, &dummy, &data)) goto err;
1041 *format_ret = a_type;
1042 *num_ret = num;
1043 *unit_size_ret = fmt;
1044 if ((a_type == ECORE_X_ATOM_STRING) && (fmt == 8))
1045 {
1046 d = malloc(num + 1);
1047 if (!d) goto err2;
1048 memcpy(d, data, num);
1049 d[num] = 0;
1050 }
1051 else
1052 {
1053 if (fmt == 8 ) d = malloc(num);
1054 else if (fmt == 16) d = malloc(num * 2);
1055 else if (fmt == 32) d = malloc(num * 4);
1056 if (!d) goto err2;
1057 memcpy(d, data, num * (fmt / 8));
1058 }
1059 XFree(data);
1060 return d;
1061err2:
1062 XFree(data);
1063err:
1064 *num_ret = 0;
1065 *format_ret = 0;
1066 *unit_size_ret = 0;
1067 return NULL;
1068}
1069
1070EAPI void
1071ecore_x_input_device_property_set(int slot, const char *prop, void *data,
1072 int num, Ecore_X_Atom format, int unit_size)
1073{
1074 Atom a, a_type = 0;
1075 if ((slot < 0) || (slot >= _ecore_x_xi2_num)) return;
1076 a = XInternAtom(_ecore_x_disp, prop, False);
1077 a_type = format;
1078 XIChangeProperty(_ecore_x_disp, _ecore_x_xi2_devs[slot].deviceid,
1079 a, a_type, unit_size, XIPropModeReplace, data, num);
1080}
1081
1082// XXX: add api's to get XIDeviceInfo->... stuff like
1083// use, attachement, enabled, num_classes, classes (which list number of
1084// buttons and their names, keycodes, valuators (mouse etc.), touch devices
1085// etc.