Skip to content

Commit

Permalink
Commit some work in progress code for XCB. See #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
ZaneA committed Jan 13, 2013
1 parent 062b2ee commit 8418e16
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
41 changes: 28 additions & 13 deletions src/XInput.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,32 @@ xinput_state_t g_xinput_state = {
// Functions.
//

static XDeviceInfo* xinput_findDeviceById(Display *display, int id)
static xcb_input_device_info_t* xinput_findDeviceById(xcb_connection_t *display, int id)
{
XDeviceInfo *tablet = NULL;
XDeviceInfo *devices = NULL;
int num;
xcb_input_list_input_devices_cookie_t devices_cookie = xcb_input_list_input_devices(display);

devices = XListInputDevices(display, &num);
xcb_input_list_input_devices_reply_t *devices_reply = xcb_input_list_input_devices_reply(display, devices_cookie, NULL);

if (devices_reply) {
xcb_input_device_info_t *devices = xcb_input_list_input_devices_devices(devices_reply);
int num_devices = xcb_input_list_input_devices_devices_length(devices_reply);

for (int i = 0; i < num_devices; i++) {
xcb_input_device_info_t device = devices[i];
}

free(devices_reply);
}

/*for (int i = 0; i < num; i++) {
debug("Got device \"%s\", type %i.\n", devices[i].name, devices[i].type);
for (int i = 0; i < num; i++) {
if (strstr(devices[i].name, "stylus") != NULL) {
// Fill tablet model here.
snprintf(g_xinput_values.tabletModel, sizeof(g_xinput_values.tabletModel), devices[i].name);
snprintf(g_xinput_values.tabletModelID, sizeof(g_xinput_values.tabletModelID), devices[i].name);
debug("Got %s, %i\n", devices[i].name, devices[i].type);
debug("Found stylus.\n");
tablet = &devices[i];
Expand All @@ -85,10 +96,13 @@ static XDeviceInfo* xinput_findDeviceById(Display *display, int id)
any = (XAnyClassPtr)((char *)any + any->length);
}
} else if (strstr(devices[i].name, "eraser") != NULL) {
debug("Found eraser.\n");
}
}
}*/

return tablet;
//return tablet;
return NULL;
}

static int xinput_registerDeviceEvents(Display *display, XDeviceInfo *deviceInfo)
Expand Down Expand Up @@ -198,17 +212,18 @@ static void xinput_printDeviceEvents(Display *display)
}
}

// Run in a thread.
static void *xinput_run(void *args)
{
Display *display = XOpenDisplay(NULL);
xcb_connection_t *display = xcb_connect(NULL, NULL);

assert(display != NULL);

XDeviceInfo *info = xinput_findDeviceById(display, 8);
xcb_input_device_info_t *info = xinput_findDeviceById(display, 8);

if (info == NULL) {
fprintf(stderr, "Couldn't find device.\n");
XCloseDisplay(display);
xcb_disconnect(display);
return NULL;
}

Expand All @@ -218,7 +233,7 @@ static void *xinput_run(void *args)
}
}

XCloseDisplay(display);
xcb_disconnect(display);

return NULL;
}
Expand Down
5 changes: 2 additions & 3 deletions src/XInput.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@
#include <unistd.h>
#include <pthread.h>

#include <X11/Xlib.h>
#include <X11/extensions/XInput.h>
#include <X11/Xutil.h>
#include <xcb/xcb.h>
#include <xcb/xinput.h>

// Helper macros, for returning results.
#define XINPUT(name, type) if (IS_IDENTIFIER(""#name)) { type##_TO_NPVARIANT(values->name, *result); return true; }
Expand Down

0 comments on commit 8418e16

Please sign in to comment.