Esempio n. 1
0
	vec2 updatemouse()
	{
		glm::vec2 mouse(0, 0);

		ManyMouseEvent ev;
		while (ManyMouse_PollEvent(&ev))
		{
			if (ev.type == MANYMOUSE_EVENT_RELMOTION)
			{
				//printf("Mouse #%u relative motion %s %d\n", ev.device,
				//    ev.item == 0 ? "X" : "Y", ev.value);
				if (ev.item == 0)
				{
					//camera.ProcessMouseMovement(ev.value*.5f, 0);
					//camera.Yawcur += ev.value*0.01f;
					mouse.x += ev.value;
				}
				else
				{
					//camera.ProcessMouseMovement(0, -ev.value*.5f);
					//camera.Pitchcur -= ev.value*0.01f;
					mouse.y -= ev.value;

				}
			}

			else if (ev.type == MANYMOUSE_EVENT_ABSMOTION)
			{
				//MANYMOUSE_EVENT_
				printf("Mouse #%u absolute motion %s %d\n", ev.device,
					ev.item == 0 ? "X" : "Y", ev.value);
			}
		}
		return mouse;
	}
Esempio n. 2
0
void Xmouse::run() {
  ManyMouseEvent mmevent;

  Window root_window;
  Window child_window;
  int root_x, root_y, win_x, win_y;
  unsigned int mask;

  while (no_subscribers) {
    while(ManyMouse_PollEvent(&mmevent)) {
      if (mmevent.type == MANYMOUSE_EVENT_BUTTON) {
        XQueryPointer(display, window, &root_window,
                      &child_window, &root_x, &root_y,
                      &win_x, &win_y, &mask);
        if (mmevent.value == 0) 
          emit press(root_x, root_y, mmevent.item);
        else
          emit release(root_x, root_y, mmevent.item);
      }
    }
    usleep(100000);
  }
}
Esempio n. 3
0
JNIEXPORT jboolean JNICALL Java_ManyMouse_PollEvent
  (JNIEnv *env, jclass obj, jobject jevent)
{
    ManyMouseEvent event;
    jclass cls = (*env)->GetObjectClass(env, jevent);
    if (cls == 0)
        return JNI_FALSE;  /* !!! FIXME: throw an exception? */

    if (ManyMouse_PollEvent(&event) == 0)
        return JNI_FALSE;  /* no new events. */

    #define SETINT(field) \
        if (!setInt(env, jevent, cls, #field, event.field)) return JNI_FALSE;
    SETINT(type);
    SETINT(device);
    SETINT(item);
    SETINT(value);
    SETINT(minval);
    SETINT(maxval);
    #undef SETINT

    return JNI_TRUE;
} /* JNI org.icculus.ManyMouse.PollEvent */
Esempio n. 4
0
static void *manymouse_thread(void* data)
{
    fs_log("[MANYMOUSE] Thread running\n");

    int k = g_fs_ml_input_device_count;
    g_first_manymouse_index = k;
    int mouse_count = ManyMouse_Init();
    if (mouse_count < 0) {
        fs_log("[MANYMOUSE] Initialization failed (%d)\n", mouse_count);
    }
    else if (mouse_count == 0) {
        fs_log("MANYMOUSE: no mice found\n");
        // no mice found, so we just quit using the library
    }

    for (int i = 0; i < mouse_count; i++) {
        const char *device = ManyMouse_DeviceName(i);
        const char *driver = ManyMouse_DriverName();

        char *name;
        if (device[0] == 0 || g_ascii_strcasecmp(device, "mouse") == 0) {
            name = g_strdup("Mouse: Unnamed Mouse");
        } else {
            name = g_strdup_printf("Mouse: %s", device);
        }
        // fs_ml_input_unique_device_name either returns name, or frees it
        // and return another name, so name must be malloced and owned by
        // caller
        name = fs_ml_input_unique_device_name(name);
        fs_log("MANYMOUSE: Adding %s (%s)\n", name, driver);

        g_fs_ml_input_devices[k].type = FS_ML_MOUSE;
        g_fs_ml_input_devices[k].index = k;
        g_fs_ml_input_devices[k].name = name;
        g_fs_ml_input_devices[k].alias = g_strdup_printf("MOUSE #%d", i + 2);
        k += 1;
    }

    // when done like this, I believe no memory barrier is needed when the
    // other thread polls g_manymouse_last_index
    g_manymouse_last_index = k;

    if (mouse_count < 0) {
        // ManyMouse library was not initialized
        return NULL;
    }

    ManyMouseEvent event;
    fs_ml_event *new_event;
    while (!fs_ml_is_quitting()) {
        // printf("..\n");
        while (ManyMouse_PollEvent(&event)) {
            // printf(" -- event type %d -- \n", event.type);
            if (event.type == MANYMOUSE_EVENT_RELMOTION) {
                // printf("MANYMOUSE_EVENT_RELMOTION\n");
                new_event = fs_ml_alloc_event();
                new_event->type = FS_ML_MOUSEMOTION;
                new_event->motion.device = g_first_manymouse_index + \
                        event.device;
                if (event.item == 0) {
                    new_event->motion.xrel = event.value;
                    new_event->motion.yrel = 0;
                }
                else if (event.item == 1) {
                    new_event->motion.xrel = 0;
                    new_event->motion.yrel = event.value;
                }
                new_event->motion.x = FS_ML_NO_ABSOLUTE_MOUSE_POS;
                new_event->motion.y = FS_ML_NO_ABSOLUTE_MOUSE_POS;

                fs_ml_post_event(new_event);
                // ManyMouseEventType type;
                // unsigned int device;
                // unsigned int item;
                // int value;
                // int minval;
                // int maxval;
            }
            else if (event.type == MANYMOUSE_EVENT_BUTTON) {
                db_log(input, "MANYMOUSE: EVENT_BUTTON "
                       "device %d item %d value %d\n",
                       event.device, event.item, event.value);
                new_event = fs_ml_alloc_event();
                new_event->type = event.value ? FS_ML_MOUSEBUTTONDOWN :
                        FS_ML_MOUSEBUTTONUP;
                new_event->button.state = event.value != 0;
                new_event->button.device = g_first_manymouse_index + \
                        event.device;
                if (event.item == 0) {
                    new_event->button.button = FS_ML_BUTTON_LEFT;
                }
                else if (event.item == 1) {
                    new_event->button.button = FS_ML_BUTTON_RIGHT;
                }
                else if (event.item == 2) {
                    new_event->button.button = FS_ML_BUTTON_MIDDLE;
                }
                else {
                    new_event->button.button = 0;
                }
                fs_ml_post_event(new_event);
            }
            else if (event.type == MANYMOUSE_EVENT_ABSMOTION) {
                // printf("MANYMOUSE_EVENT_ABSMOTION\n");
            }
            else if (event.type == MANYMOUSE_EVENT_SCROLL) {
                db_log(input, "MANYMOUSE: EVENT_SCROLL "
                       "device %d item %d value %d\n",
                       event.device, event.item, event.value);
                new_event = fs_ml_alloc_event();
                new_event->type = FS_ML_MOUSEBUTTONDOWN;
                new_event->button.state = 1;
                new_event->button.device = g_first_manymouse_index + \
                        event.device;
                new_event->button.button = 0;
                if (event.item == 0) {
                    if (event.value == 1) {
                        new_event->button.button = FS_ML_BUTTON_WHEELUP;
                    }
                    else {
                        new_event->button.button = FS_ML_BUTTON_WHEELDOWN;
                    }
                }
                fs_ml_post_event(new_event);
            }
        }
        fs_ml_usleep(1000);
    }

    ManyMouse_Quit();
    return NULL;
}