Exemple #1
0
static void
show_cursor (Doppelganger *dg)
{
  int current_pointer;
  XIEventMask mask = { dg->mpx, 0, "" };

#if 0
  /* probably unnecessary */
  XIGetClientPointer (gdk_x11_get_default_xdisplay (),
		      None,
		      &current_pointer);
  
  /* probably unnecessary */
  XISetClientPointer (gdk_x11_get_default_xdisplay (),
		      None,
		      dg->mpx);

  if (XIGrabDevice (gdk_x11_get_default_xdisplay (),
                    dg->mpx,
                    GDK_ROOT_WINDOW(), CurrentTime,
                    gdk_x11_cursor_get_xcursor (dg->cursor),
                    GrabModeAsync, GrabModeAsync,
                    True, &mask) != GrabSuccess)
    {
      g_warning ("Grab failed.");
    }

  /* probably unnecessary */
  XISetClientPointer (gdk_x11_get_default_xdisplay (),
		      None,
		      current_pointer);

#endif
}
Exemple #2
0
int
GrabPointerSet(Win win, unsigned int csr, int confine __UNUSED__)
{
   int                 rc;

#if USE_XI2
   EXIEventMask        em;

   EXIMaskSetup(&em, DEV_PTR,
		ButtonPressMask | ButtonReleaseMask | PointerMotionMask);
   rc = XIGrabDevice(disp, DEV_PTR, WinGetXwin(win), CurrentTime, ECsrGet(csr),
		     GrabModeAsync, GrabModeAsync, False, &em.em);
#else
   EX_Window           confine_to = (confine) ? WinGetXwin(VROOT) : NoXID;

   rc = XGrabPointer(disp, WinGetXwin(win), False,
		     ButtonPressMask | ButtonReleaseMask | PointerMotionMask |
		     ButtonMotionMask | EnterWindowMask | LeaveWindowMask,
		     GrabModeAsync, GrabModeAsync, confine_to, ECsrGet(csr),
		     CurrentTime);
#endif

   Mode.grabs.pointer_grab_window = WinGetXwin(win);
   Mode.grabs.pointer_grab_active = 1;

   if (EDebug(EDBUG_TYPE_GRABS))
      Eprintf("%s: %#x, rc=%d\n", __func__, Mode.grabs.pointer_grab_window, rc);

   return rc;
}
Exemple #3
0
static gboolean
meta_backend_x11_grab_device (MetaBackend *backend,
                              int          device_id,
                              uint32_t     timestamp)
{
  MetaBackendX11 *x11 = META_BACKEND_X11 (backend);
  MetaBackendX11Private *priv = meta_backend_x11_get_instance_private (x11);
  unsigned char mask_bits[XIMaskLen (XI_LASTEVENT)] = { 0 };
  XIEventMask mask = { XIAllMasterDevices, sizeof (mask_bits), mask_bits };
  int ret;

  if (timestamp != CurrentTime)
    timestamp = MAX (timestamp, priv->latest_evtime);

  XISetMask (mask.mask, XI_ButtonPress);
  XISetMask (mask.mask, XI_ButtonRelease);
  XISetMask (mask.mask, XI_Enter);
  XISetMask (mask.mask, XI_Leave);
  XISetMask (mask.mask, XI_Motion);
  XISetMask (mask.mask, XI_KeyPress);
  XISetMask (mask.mask, XI_KeyRelease);

  ret = XIGrabDevice (priv->xdisplay, device_id,
                      meta_backend_x11_get_xwindow (x11),
                      timestamp,
                      None,
                      XIGrabModeAsync, XIGrabModeAsync,
                      False, /* owner_events */
                      &mask);

  return (ret == Success);
}
Exemple #4
0
static void install_grabs_mouse( void )
{
	int i;
	int num_devices;
	XIDeviceInfo *info;
	XIEventMask mask;

	assert( x11display.dpy && x11display.win );

	if( mouse_active )
		return;

	XDefineCursor(x11display.dpy, x11display.win, CreateNullCursor(x11display.dpy, x11display.win));

	mask.deviceid = XIAllDevices;
	mask.mask_len = XIMaskLen(XI_LASTEVENT);
	mask.mask = calloc(mask.mask_len, sizeof(char));
	XISetMask(mask.mask, XI_Enter);
	XISetMask(mask.mask, XI_Leave);
	XISetMask(mask.mask, XI_ButtonPress);
	XISetMask(mask.mask, XI_ButtonRelease);

	info = XIQueryDevice(x11display.dpy, XIAllDevices, &num_devices);
	for(i = 0; i < num_devices; i++) {
		int id = info[i].deviceid;
		if(info[i].use == XISlavePointer) {
			mask.deviceid = id;
			XIGrabDevice(x11display.dpy, id, x11display.win, CurrentTime, None, GrabModeSync,
				GrabModeSync, True, &mask);
		}
		else if(info[i].use == XIMasterPointer) {
			if (x11display.features.wmStateFullscreen)
				XIWarpPointer(x11display.dpy, id, None, x11display.win, 0, 0, 0, 0, 0, 0);
			else
				XIWarpPointer(x11display.dpy, id, None, x11display.win, 0, 0, 0, 0, x11display.win_width/2, x11display.win_height/2);
		}
	}
	XIFreeDeviceInfo(info);

	mask.deviceid = XIAllDevices;
	memset(mask.mask, 0, mask.mask_len);
	XISetMask(mask.mask, XI_RawMotion);

	XISelectEvents(x11display.dpy, DefaultRootWindow(x11display.dpy), &mask, 1);

	free(mask.mask);

	XSync(x11display.dpy, True);

	mx = my = 0;
	mouse_active = qtrue;
}
Exemple #5
0
void
test_sync_grab(Display *display, Window win)
{
    int loop = 3;
    int rc;
    XIEventMask mask;

    /* Select for motion events */
    mask.deviceid = XIAllDevices;
    mask.mask_len = 2;
    mask.mask = calloc(2, sizeof(char));
    XISetMask(mask.mask, XI_ButtonPress);

    if ((rc = XIGrabDevice(display, 2,  win, CurrentTime, None, GrabModeSync,
                           GrabModeAsync, False, &mask)) != GrabSuccess)
    {
        fprintf(stderr, "Grab failed with %d\n", rc);
        return;
    }
    free(mask.mask);

    XSync(display, True);
    XIAllowEvents(display, 2, SyncPointer, CurrentTime);
    XFlush(display);

    printf("Holding sync grab for %d button presses.\n", loop);

    while(loop--)
    {
        XIEvent ev;

        XNextEvent(display, (XEvent*)&ev);
        if (ev.type == GenericEvent && ev.extension == xi_opcode )
        {
            XIDeviceEvent *event = (XIDeviceEvent*)&ev;
            print_deviceevent(event);
            XIAllowEvents(display, 2, SyncPointer, CurrentTime);
        }
    }

    XIUngrabDevice(display, 2, CurrentTime);
    printf("Done\n");
}
Exemple #6
0
static void install_grabs_keyboard( void )
{
	int i;
	int num_devices;
	XIDeviceInfo *info;
	XIEventMask mask;

	assert( x11display.dpy && x11display.win );

	if( input_active )
		return;

	XDefineCursor(x11display.dpy, x11display.win, CreateNullCursor(x11display.dpy, x11display.win));

	mask.deviceid = XIAllMasterDevices;
	mask.mask_len = XIMaskLen(XI_LASTEVENT);
	mask.mask = calloc(mask.mask_len, sizeof(char));
	XISetMask(mask.mask, XI_KeyPress);
	XISetMask(mask.mask, XI_KeyRelease);
	XISetMask(mask.mask, XI_ButtonPress);
	XISetMask(mask.mask, XI_ButtonRelease);
	XISelectEvents(x11display.dpy, x11display.win, &mask, 1);

	info = XIQueryDevice(x11display.dpy, XIAllDevices, &num_devices);
	for(i = 0; i < num_devices; i++) {
		int id = info[i].deviceid;
		if(info[i].use == XIMasterKeyboard)
		{
			XIGrabDevice(x11display.dpy, id, x11display.win, CurrentTime, None, GrabModeAsync, GrabModeAsync, False, &mask);
		}
	}
	XIFreeDeviceInfo(info);

	free(mask.mask);

	XSync(x11display.dpy, True);

	input_active = qtrue;
}
/* Grab the device so input is captured */
void grab(Display* display, int grabDeviceID) {
	XIEventMask device_mask;
	unsigned char mask_data[8] = { 0,0,0,0,0,0,0,0 };
	device_mask.mask_len = sizeof(mask_data);
	device_mask.mask = mask_data;
	XISetMask(device_mask.mask, XI_Motion);
	XISetMask(device_mask.mask, XI_ButtonPress);

/* Experiments with X MT support, not working yet */
//	XISetMask(device_mask.mask, XI_TouchBegin);
//	XISetMask(device_mask.mask, XI_TouchUpdate);
//	XISetMask(device_mask.mask, XI_TouchEnd);
//	XIGrabModifiers modifiers;
//	modifiers.modifiers = XIAnyModifier;
//	int r = XIGrabButton(display, grabDeviceID, XIAnyButton, root, None, GrabModeSync,
//			GrabModeAsync, True, &device_mask, 1, &modifiers);
//	int r = XIGrabTouchBegin(display, grabDeviceID, root, None, &device_mask, 0, modifiers);

	int r = XIGrabDevice(display, grabDeviceID, root, CurrentTime, None, GrabModeAsync, GrabModeAsync, False, &device_mask);

	if(debugMode) printf("Grab Result: %i\n", r);

}
Exemple #8
0
static int
_GrabKeyboard(Win win, int sync_kbd)
{
   int                 rc;

#if USE_XI2
   EXIEventMask        em;

   EXIMaskSetup(&em, DEV_KBD, KeyPressMask | KeyReleaseMask);
   rc = XIGrabDevice(disp, DEV_KBD, WinGetXwin(win), CurrentTime, NoXID,
		     GrabModeAsync, sync_kbd ? GrabModeSync : GrabModeAsync,
		     False, &em.em);
#else
   rc = XGrabKeyboard(disp, WinGetXwin(win), False,
		      GrabModeAsync, sync_kbd ? GrabModeSync : GrabModeAsync,
		      CurrentTime);
#endif

#if 0
   Eprintf("%s: %#lx sync=%d rc=%d\n", __func__, WinGetXwin(win), sync_kbd, rc);
#endif

   return rc;
}
Exemple #9
0
gboolean
xfwm_device_grab (XfwmDevices *devices, XfwmDevice *device, Display *display,
                  Window grab_window, gboolean owner_events, guint event_mask,
                  gint grab_mode, Window confine_to, Cursor cursor, Time time)
{
    gboolean result;
    Status status;
#ifdef HAVE_XI2
    XIEventMask xievent_mask;
#endif

#ifdef HAVE_XI2
    if (device->xi2_device != None)
    {
        xfwm_device_fill_xi2_event_mask (&xievent_mask, event_mask);
        status = XIGrabDevice (display, device->xi2_device, grab_window, time, cursor,
                               grab_mode, grab_mode, owner_events, &xievent_mask);
        g_free (xievent_mask.mask);
        result = (status == XIGrabSuccess);
    }
    else
#endif
    if (device->keyboard)
    {
        status = XGrabKeyboard (display, grab_window, owner_events,
                                grab_mode, grab_mode, time);
        result = (status == GrabSuccess);
    }
    else
    {
        status = XGrabPointer (display, grab_window, owner_events, event_mask,
                               grab_mode, grab_mode, confine_to, cursor, time);
        result = (status == GrabSuccess);
    }
    return result;
}
Exemple #10
0
void
doppelganger_set_image (Doppelganger *dg,
                        GdkPixbuf *pixbuf)
{
  GdkPixbuf *scaled = NULL;
  GdkPixdata black_arrow_data;
  GdkPixbuf *black_arrow;
  GdkPixbuf *cursor_image;
  gboolean preexisting = dg->cursor!=NULL;

  if (!gdk_pixdata_deserialize (&black_arrow_data,
				-1,
				black_cursor,
				NULL) ||
      black_cursor == NULL)
    {
      /* This won't happen in practice, so it can be fatal */
      g_error ("Failed to deseralise pointer.");
    }

  black_arrow =
    gdk_pixbuf_from_pixdata (&black_arrow_data,
			     TRUE,
			     NULL);

  if (pixbuf)
    {
      scaled = gdk_pixbuf_scale_simple (pixbuf,
					64, 64,
					GDK_INTERP_BILINEAR);

      /*
       * Composite a black arrow onto the top left-hand
       * corner.
       */

      gdk_pixbuf_composite (black_arrow,
                            scaled,
                            0, 0, 13, 21,
                            0.0, 0.0, 1.0, 1.0,
                            GDK_INTERP_NEAREST,
                            255);
      gdk_pixbuf_unref (black_arrow);

      cursor_image = scaled;
    }
  else
    {
      cursor_image = black_arrow;
    }

  if (preexisting)
    {
      gdk_cursor_unref (dg->cursor);
    }

  dg->cursor = gdk_cursor_new_from_pixbuf
    (gdk_display_get_default (),
     cursor_image,
     1, 1);
  gdk_pixbuf_unref (cursor_image);

#if 0
  if (preexisting)
    {
      XIEventMask mask = { dg->mpx, 0, "" };

      if (XIUngrabDevice (gdk_x11_get_default_xdisplay (),
                          dg->mpx,
                          CurrentTime) != GrabSuccess)
        {
          g_warning ("Ungrab failed.");
        }

      if (XIGrabDevice (gdk_x11_get_default_xdisplay (),
                        dg->mpx,
                        GDK_ROOT_WINDOW(), CurrentTime,
                        gdk_x11_cursor_get_xcursor (dg->cursor),
                        GrabModeAsync, GrabModeAsync,
                        True, &mask) != GrabSuccess)
        {
          g_warning ("Grab failed.");
        }
    }
#endif
}