summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Hutterer <peter.hutterer@who-t.net>2009-05-07 14:13:45 +1000
committerPeter Hutterer <peter.hutterer@who-t.net>2009-05-07 14:49:25 +1000
commitff1b12265de1010aa22011c5db829274a8a3dab1 (patch)
tree92d32218841b3b3b3476f4f4d95040283e383d57
parentba2396b40a427c30c58f8c17b64f4cf7bfaa2909 (diff)
Get the XIDeviceInfo instead of just the id.
This way we leak the XIDeviceInfo array, but then again it doesn't matter since we exit after the command anyway. And with the XIDeviceInfo around, we can actually print the name and whatnot. Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
-rw-r--r--src/hierarchy.c31
-rw-r--r--src/setcp.c8
-rw-r--r--src/xinput.c26
-rw-r--r--src/xinput.h4
4 files changed, 35 insertions, 34 deletions
diff --git a/src/hierarchy.c b/src/hierarchy.c
index 7739074..ed5e930 100644
--- a/src/hierarchy.c
+++ b/src/hierarchy.c
@@ -65,7 +65,8 @@ int
remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
{
XIRemoveMasterInfo r;
- int ret, id;
+ XIDeviceInfo *info;
+ int ret;
if (argc == 0)
{
@@ -73,15 +74,15 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
return EXIT_FAILURE;
}
- id = xi2_find_device_id(dpy, argv[0]);
+ info = xi2_find_device_info(dpy, argv[0]);
- if (id == -1) {
+ if (!info) {
fprintf(stderr, "unable to find device %s\n", argv[0]);
return EXIT_FAILURE;
}
r.type = CH_RemoveMasterDevice;
- r.device = id;
+ r.device = info->deviceid;
if (argc >= 2)
{
if (!strcmp(argv[1], "Floating"))
@@ -109,7 +110,7 @@ remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
int
change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
{
- int sd_id, md_id;
+ XIDeviceInfo *sd_info, *md_info;
XIAttachSlaveInfo c;
int ret;
@@ -119,22 +120,22 @@ change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
return EXIT_FAILURE;
}
- sd_id = xi2_find_device_id(dpy, argv[0]);
- md_id = xi2_find_device_id(dpy, argv[1]);
+ sd_info = xi2_find_device_info(dpy, argv[0]);
+ md_info= xi2_find_device_info(dpy, argv[1]);
- if (sd_id == -1) {
+ if (!sd_info) {
fprintf(stderr, "unable to find device %s\n", argv[0]);
return EXIT_FAILURE;
}
- if (md_id == -1) {
+ if (!md_info) {
fprintf(stderr, "unable to find device %s\n", argv[1]);
return EXIT_FAILURE;
}
c.type = CH_AttachSlave;
- c.device = sd_id;
- c.newMaster = md_id;
+ c.device = sd_info->deviceid;
+ c.newMaster = md_info->deviceid;
ret = XIChangeDeviceHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&c, 1);
return ret;
@@ -146,7 +147,7 @@ change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
int
float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
{
- int id;
+ XIDeviceInfo *info;
XIDetachSlaveInfo c;
int ret;
@@ -156,15 +157,15 @@ float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
return EXIT_FAILURE;
}
- id = xi2_find_device_id(dpy, argv[0]);
+ info = xi2_find_device_info(dpy, argv[0]);
- if (id == -1) {
+ if (!info) {
fprintf(stderr, "unable to find device %s\n", argv[0]);
return EXIT_FAILURE;
}
c.type = CH_DetachSlave;
- c.device = id;
+ c.device = info->deviceid;
ret = XIChangeDeviceHierarchy(dpy, (XIAnyHierarchyChangeInfo*)&c, 1);
return ret;
diff --git a/src/setcp.c b/src/setcp.c
index f2b2a6c..7a28644 100644
--- a/src/setcp.c
+++ b/src/setcp.c
@@ -32,7 +32,7 @@
int
set_clientpointer(Display* dpy, int argc, char** argv, char* name, char *desc)
{
- int deviceid;
+ XIDeviceInfo *info;
XID window;
char* id;
char* dummy;
@@ -49,13 +49,13 @@ set_clientpointer(Display* dpy, int argc, char** argv, char* name, char *desc)
window = strtol(argv[0], &dummy, (*id == 'x') ? 16 : 10);
- deviceid = xi2_find_device_id(dpy, argv[1]);
+ info = xi2_find_device_info(dpy, argv[1]);
- if (deviceid == -1) {
+ if (!info) {
fprintf(stderr, "unable to find device %s\n", argv[1]);
return EXIT_FAILURE;
}
- XISetClientPointer(dpy, window, deviceid);
+ XISetClientPointer(dpy, window, info->deviceid);
return 0;
}
diff --git a/src/xinput.c b/src/xinput.c
index 4acb7bf..cff33d5 100644
--- a/src/xinput.c
+++ b/src/xinput.c
@@ -203,8 +203,8 @@ find_device_info(Display *display,
}
#ifdef HAVE_XI2
-int
-xi2_find_device_id(Display *display, char *name)
+XIDeviceInfo*
+xi2_find_device_info(Display *display, char *name)
{
XIDeviceInfo *info;
int ndevices;
@@ -220,22 +220,20 @@ xi2_find_device_id(Display *display, char *name)
if (is_id) {
id = atoi(name);
- } else
+ }
+
+ info = XIQueryDevice(display, AllDevices, &ndevices);
+ for(i = 0; i < ndevices; i++)
{
- info = XIQueryDevice(display, AllDevices, &ndevices);
- for(i = 0; i < ndevices; i++)
+ if ((is_id && info[i].deviceid == id) ||
+ (!is_id && strcmp(info[i].name, name) == 0))
{
- if ((is_id && info[i].deviceid == id) ||
- (!is_id && strcmp(info[i].name, name) == 0))
- {
- id = info[i].deviceid;
- break;
- }
+ return &info[i];
}
-
- XIFreeDeviceInfo(info);
}
- return id;;
+
+ XIFreeDeviceInfo(info);
+ return NULL;
}
#endif
diff --git a/src/xinput.h b/src/xinput.h
index c7269b9..f3fc266 100644
--- a/src/xinput.h
+++ b/src/xinput.h
@@ -43,8 +43,10 @@
XDeviceInfo* find_device_info( Display *display, char *name, Bool only_extended);
-int xi2_find_device_id(Display *display, char *name);
+#if HAVE_XI2
+XIDeviceInfo* xi2_find_device_info(Display *display, char *name);
int xinput_version(Display* display);
+#endif
int get_feedbacks( Display* display, int argc, char *argv[], char *prog_name, char *prog_desc);
int set_ptr_feedback( Display* display, int argc, char *argv[], char *prog_name, char *prog_desc);