static void
device_removed_cb (GdkDeviceManager *manager,
		   GdkDevice        *device,
		   gpointer          user_data)
{
	g_hash_table_remove (monitors,
			     GINT_TO_POINTER (gdk_x11_device_get_id (device)));
	g_message ("Removed watch for device %s (%d)",
		   gdk_device_get_name (device),
		   gdk_x11_device_get_id (device));
}
static void
device_added_cb (GdkDeviceManager *manager,
		 GdkDevice        *device,
		 gpointer          user_data)
{
	GnomeIdleMonitor *monitor;
	guint watch_id;
	int device_id;
	GError *error = NULL;

	device_id = gdk_x11_device_get_id (device);
	monitor = gnome_idle_monitor_new_for_device (device, &error);
	if (!monitor) {
		g_warning ("Per-device idletime monitor not available: %s", error->message);
		g_error_free (error);
		return;
	}

	watch_id = gnome_idle_monitor_add_idle_watch (monitor,
						      IDLE_TIME,
						      idle_watch_func,
						      NULL,
						      NULL);
	g_message ("Added idle watch ID %d for device %s (%d)",
		   watch_id,
		   gdk_device_get_name (device),
		   device_id);

	ensure_active_watch (monitor);

	g_hash_table_insert (monitors,
			     GINT_TO_POINTER (device_id),
			     monitor);
}
示例#3
0
文件: device.c 项目: iglosiggio/xfwm4
XfwmDevices *
xfwm_devices_new (GdkDisplay *display)
{
    XfwmDevices *devices;
#ifdef HAVE_XI2
    GdkSeat *seat;
    GdkDevice *pointer_device;
    GdkDevice *keyboard_device;
    gint firstevent, firsterror;
#endif

    devices = g_new0 (XfwmDevices, 1);
    devices->xi2_available = FALSE;
    devices->xi2_opcode = 0;

    devices->pointer.keyboard = FALSE;
    devices->pointer.xi2_device = None;

    devices->keyboard.keyboard = TRUE;
    devices->keyboard.xi2_device = None;

#ifdef HAVE_XI2
    seat = gdk_display_get_default_seat (display);
    pointer_device = gdk_seat_get_pointer (seat);
    keyboard_device = gdk_seat_get_keyboard (seat);

    if (GDK_IS_X11_DEVICE_XI2 (pointer_device) || GDK_IS_X11_DEVICE_XI2 (keyboard_device))
    {
        /* GDK uses XI2, let's use it too */

        /* Obtain XI2 opcode */
        if (XQueryExtension (gdk_x11_display_get_xdisplay (display), "XInputExtension",
                             &devices->xi2_opcode, &firstevent, &firsterror))
        {
            devices->xi2_available = TRUE;
            devices->pointer.xi2_device = gdk_x11_device_get_id (pointer_device);
            devices->keyboard.xi2_device = gdk_x11_device_get_id (keyboard_device);
        }
    }
#endif

    return devices;
}
static void
active_watch_func (GnomeIdleMonitor *monitor,
		   guint             id,
		   gpointer          user_data)
{
	GdkDevice *device;
	int device_id;

	g_object_get (monitor, "device", &device, NULL);
	device_id = gdk_x11_device_get_id (device);
	g_message ("Active watch func called for device %s (id: %d, watch id %d)",
		   gdk_device_get_name (device),
		   device_id,
		   id);
	g_object_unref (device);
}
static void
ensure_active_watch (GnomeIdleMonitor *monitor)
{
	GdkDevice *device;
	guint watch_id;
	int device_id;

	g_object_get (monitor, "device", &device, NULL);
	device_id = gdk_x11_device_get_id (device);
	watch_id = gnome_idle_monitor_add_user_active_watch (monitor,
							     active_watch_func,
							     NULL,
							     NULL);
	g_message ("Added active watch ID %d for device %s (%d)",
		   watch_id,
		   gdk_device_get_name (device),
		   device_id);
}
static gboolean
on_button_press_event(GtkWidget      *widget,
                      GdkEventButton *event,
                      CalibArea      *area)
{
    gboolean success;

    if (area->success)
        return FALSE;

    /* Check matching device ID if a device ID was provided */
    if (area->device_id > -1) {
        GdkDevice *device;

        device = gdk_event_get_source_device ((GdkEvent *) event);
        if (device != NULL && gdk_x11_device_get_id (device) != area->device_id)
	    return FALSE;
    }

    /* Handle click */
    area->time_elapsed = 0;
    success = add_click(&area->calibrator, (int)event->x_root, (int)event->y_root);

    if (!success && area->calibrator.num_clicks == 0)
        draw_message(area, N_("Mis-click detected, restarting..."));
    else
        draw_message(area, NULL);

    /* Are we done yet? */
    if (area->calibrator.num_clicks >= 4)
    {
        set_calibration_status (area);
        return FALSE;
    }

    /* Force a redraw */
    redraw(area);

    return FALSE;
}