* the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation.
- *
+ *
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
- *
+ *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
- *
+ *
* Except as contained in this notice, the name of the author shall
* not be used in advertising or otherwise to promote the sale, use or
* other dealings in this Software without prior written authorization
* from the author.
- *
+ *
*/
#include "xinput.h"
* Create a new master device. Name must be supplied, other values are
* optional.
*/
-int
+int
create_master(Display* dpy, int argc, char** argv, char* name, char *desc)
{
XCreateMasterInfo c;
- XCreateMasterInfo* pc = &c;
if (argc == 0)
{
c.sendCore = (argc >= 2) ? atoi(argv[1]) : 1;
c.enable = (argc >= 3) ? atoi(argv[2]) : 1;
- return XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pc);
+ return XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
}
/**
int
remove_master(Display* dpy, int argc, char** argv, char *name, char *desc)
{
+ XDeviceInfo *info;
XRemoveMasterInfo r;
- XRemoveMasterInfo* pr = &r;
XDevice* master = NULL, *ptr = NULL, *keybd = NULL;
int ret;
return EXIT_FAILURE;
}
- master = XOpenDevice(dpy, atoi(argv[0]));
+ info = find_device_info(dpy, argv[0], False);
+
+ if (!info) {
+ fprintf(stderr, "unable to find device %s\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ master = XOpenDevice(dpy, info->id);
if (!master)
- Error(BadValue, "Invalid master device.\n");
+ Error(BadValue, "Unable to open device %s.\n", argv[0]);
r.type = CH_RemoveMasterDevice;
r.device = master;
r.returnMode = Floating;
else if (!strcmp(argv[1], "AttachToMaster"))
r.returnMode = AttachToMaster;
- else
+ else
Error(BadValue, "Invalid returnMode.\n");
} else
r.returnMode = Floating;
r.returnKeyboard = keybd;
}
- ret = XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pr);
+ ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&r, 1);
if (ptr)
XCloseDevice(dpy, ptr);
if (keybd)
int
change_attachment(Display* dpy, int argc, char** argv, char *name, char* desc)
{
+ XDeviceInfo *info_sd, *info_md;
XChangeAttachmentInfo c;
- XChangeAttachmentInfo* pc = &c;
XDevice *slave, *master;
int ret;
return EXIT_FAILURE;
}
- slave = XOpenDevice(dpy, atoi(argv[0]));
- master = XOpenDevice(dpy, atoi(argv[1]));
+ info_sd = find_device_info(dpy, argv[0], True);
+ info_md = find_device_info(dpy, argv[1], False);
+
+ if (!info_sd) {
+ fprintf(stderr, "unable to find device %s\n", argv[0]);
+ return EXIT_FAILURE;
+ }
+
+ if (!info_md) {
+ fprintf(stderr, "unable to find device %s\n", argv[1]);
+ return EXIT_FAILURE;
+ }
+
+ slave = XOpenDevice(dpy, info_sd->id);
+ master = XOpenDevice(dpy, info_md->id);
if (!slave)
Error(BadValue, "Invalid slave device given %d\n", atoi(argv[0]));
c.device = slave;
c.newMaster = master;
- ret = XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pc);
+ ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
XCloseDevice(dpy, slave);
XCloseDevice(dpy, master);
return ret;
int
float_device(Display* dpy, int argc, char** argv, char* name, char* desc)
{
+ XDeviceInfo *info;
XChangeAttachmentInfo c;
- XChangeAttachmentInfo* pc = &c;
XDevice *slave;
int ret;
return EXIT_FAILURE;
}
+ info = find_device_info(dpy, argv[0], True);
+
+ if (!info) {
+ fprintf(stderr, "unable to find device %s\n", argv[0]);
+ return EXIT_FAILURE;
+ }
- slave = XOpenDevice(dpy, atoi(argv[0]));
+ slave = XOpenDevice(dpy, info->id);
if (!slave)
return BadValue;
c.changeMode = Floating;
c.device = slave;
- ret = XChangeDeviceHierarchy(dpy, 1, (XAnyHierarchyChangeInfo**)&pc);
+ ret = XChangeDeviceHierarchy(dpy, (XAnyHierarchyChangeInfo*)&c, 1);
XCloseDevice(dpy, slave);
return ret;
}