Esempio n. 1
0
int
sweep(Client *c, int but, XButtonEvent *ignored)
{
	XEvent ev;
	int status;
	XButtonEvent *e;
	ScreenInfo *s;

	s = c->screen;
	c->dx = 0;
	c->dy = 0;
	status = grab(s->root, s->root, ButtonMask, s->sweep0, 0);
	if(status != GrabSuccess){
		graberror("sweep", status); /* */
		return 0;
	}

	XMaskEvent(dpy, ButtonMask, &ev);
	e = &ev.xbutton;
	if(e->button != but){
		ungrab(e);
		return 0;
	}
	XChangeActivePointerGrab(dpy, ButtonMask, s->boxcurs, e->time);
	return sweepdrag(c, but, e, BorderUnknown, sweepcalc);
}
Esempio n. 2
0
void MenuLeaveNotify(XEvent *event)
{
  StampTime(event->xcrossing.time);
  if(VisibleMenuWin(event->xcrossing.window)) {
    XChangeActivePointerGrab(disp,ButtonPressMask|ButtonReleaseMask|\
         EnterWindowMask|LeaveWindowMask,TheScreen.Mice[C_DEFAULT],TimeStamp);
    if(quittable) SelectItem(NULL, event->xcrossing.state);
  }
}
Esempio n. 3
0
void
doppelganger_show (Doppelganger *dg)
{
#if 0
  XChangeActivePointerGrab (gdk_x11_get_default_xdisplay (),
			    0,
			    gdk_x11_cursor_get_xcursor (dg->cursor),
			    CurrentTime);
#endif
}
Esempio n. 4
0
void slop::Mouse::setCursor( int cursor ) {
    if ( currentCursor == cursor ) {
        return;
    }
    XFreeCursor( x11->display, xcursor );
    xcursor = XCreateFontCursor( x11->display, cursor );
    XChangeActivePointerGrab( x11->display,
                              PointerMotionMask | ButtonPressMask | ButtonReleaseMask | EnterWindowMask,
                              xcursor, CurrentTime );
}
int
pushScreenGrab (CompScreen *s,
		Cursor     cursor)
{
    if (s->maxGrab == 0)
    {
	int status;

	status = XGrabPointer (s->display->display, s->grabWindow, TRUE,
			       POINTER_GRAB_MASK,
			       GrabModeAsync, GrabModeAsync,
			       s->root, cursor,
			       CurrentTime);

	if (status == GrabSuccess)
	{
	    status = XGrabKeyboard (s->display->display,
				    s->grabWindow, TRUE,
				    GrabModeAsync, GrabModeAsync,
				    CurrentTime);
	    if (status != GrabSuccess)
	    {
		XUngrabPointer (s->display->display, CurrentTime);
		return 0;
	    }
	}
	else
	    return 0;
    }
    else
    {
	XChangeActivePointerGrab (s->display->display, POINTER_GRAB_MASK,
				  cursor, CurrentTime);
    }

    if (s->grabSize <= s->maxGrab)
    {
	s->grabs = realloc (s->grabs, sizeof (CompGrab) * (s->maxGrab + 1));
	if (!s->grabs)
	    return 0;

	s->grabSize = s->maxGrab + 1;
    }

    s->grabs[s->maxGrab].cursor = cursor;
    s->grabs[s->maxGrab].active = TRUE;

    s->maxGrab++;

    return s->maxGrab;
}
Esempio n. 6
0
gboolean
myScreenChangeGrabPointer (ScreenInfo *screen_info, unsigned int event_mask, Cursor cursor, guint32 timestamp)
{
    gboolean grab;

    g_return_val_if_fail (screen_info, FALSE);
    TRACE ("entering myScreenChangeGrabPointer");

    grab = FALSE;
    if (screen_info->pointer_grabs > 0)
    {
        grab = (XChangeActivePointerGrab (myScreenGetXDisplay (screen_info),
                                          event_mask, cursor, (Time) timestamp) == GrabSuccess);
    }

    return grab;
}
void
removeScreenGrab (CompScreen *s,
		  int	     index,
		  XPoint     *restorePointer)
{
    int maxGrab;

    index--;
    if (index < 0 || index >= s->maxGrab)
	abort ();

    s->grabs[index].cursor = None;
    s->grabs[index].active = FALSE;

    for (maxGrab = s->maxGrab; maxGrab; maxGrab--)
	if (s->grabs[maxGrab - 1].active)
	    break;

    if (maxGrab != s->maxGrab)
    {
	if (maxGrab)
	{
	    XChangeActivePointerGrab (s->display->display,
				      POINTER_GRAB_MASK,
				      s->grabs[s->maxGrab - 1].cursor,
				      CurrentTime);
	}
	else
	{
	    if (restorePointer)
		XWarpPointer (s->display->display, None, s->root, 0, 0, 0, 0,
			      restorePointer->x, restorePointer->y);

	    XUngrabPointer (s->display->display, CurrentTime);
	    XUngrabKeyboard (s->display->display, CurrentTime);
	}
	s->maxGrab = maxGrab;
    }
}
Esempio n. 8
0
struct Area *display_X11_select_area(void)
{
	Cursor cursor = XCreateFontCursor(disp, XC_left_ptr);
	Cursor cursor2 = XCreateFontCursor(disp, XC_lr_angle);

	GC gc = display_X11_create_gc();

	if (XGrabPointer(disp, scr->root, False, ButtonPressMask, GrabModeAsync, GrabModeAsync,
				scr->root, cursor, CurrentTime) != GrabSuccess)
		return NULL;

	XEvent ev = {0};
	while (ev.type != ButtonPress)
		XNextEvent(disp, &ev);

	int start_x = ev.xbutton.x;
	int start_y = ev.xbutton.y;
	XChangeActivePointerGrab(disp, PointerMotionMask | ButtonReleaseMask, cursor2, CurrentTime);

	struct Area *area = calloc(1, sizeof(*area));

	while (display_X11_process_events(gc, start_x, start_y, area)) {
		fd_set fdset;
		FD_ZERO(&fdset);
		FD_SET(ConnectionNumber(disp), &fdset);
		select(ConnectionNumber(disp)+1, &fdset, NULL, NULL, NULL);
	}

	XUngrabPointer(disp, CurrentTime);
	XFreeCursor(disp, cursor);
	XFreeCursor(disp, cursor2);
	XFreeGC(disp, gc);
	XSync(disp, True);

	display_X11_area_sanitize(area);

	return area;
}
Esempio n. 9
0
File: main.c Progetto: braneed/scrot
Imlib_Image
scrot_sel_and_grab_image(void)
{
  Imlib_Image im = NULL;
  static int xfd = 0;
  static int fdsize = 0;
  XEvent ev;
  fd_set fdset;
  int count = 0, done = 0;
  int rx = 0, ry = 0, rw = 0, rh = 0, btn_pressed = 0;
  int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0;
  Cursor cursor, cursor_nw, cursor_ne, cursor_se, cursor_sw;
  Window target = None;
  GC gc;
  XGCValues gcval;

  xfd = ConnectionNumber(disp);
  fdsize = xfd + 1;

  cursor    = XCreateFontCursor(disp, XC_crosshair);
  cursor_nw = XCreateFontCursor(disp, XC_ul_angle);
  cursor_ne = XCreateFontCursor(disp, XC_ur_angle);
  cursor_se = XCreateFontCursor(disp, XC_lr_angle);
  cursor_sw = XCreateFontCursor(disp, XC_ll_angle);

  gcval.foreground = XWhitePixel(disp, 0);
  gcval.function = GXxor;
  gcval.background = XBlackPixel(disp, 0);
  gcval.plane_mask = gcval.background ^ gcval.foreground;
  gcval.subwindow_mode = IncludeInferiors;

  gc =
    XCreateGC(disp, root,
              GCFunction | GCForeground | GCBackground | GCSubwindowMode,
              &gcval);

  if ((XGrabPointer
       (disp, root, False,
        ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync,
        GrabModeAsync, root, cursor, CurrentTime) != GrabSuccess))
    gib_eprintf("couldn't grab pointer:");

  if ((XGrabKeyboard
       (disp, root, False, GrabModeAsync, GrabModeAsync,
        CurrentTime) != GrabSuccess))
    gib_eprintf("couldn't grab keyboard:");

  while (1) {
    /* handle events here */
    while (!done && XPending(disp)) {
      XNextEvent(disp, &ev);
      switch (ev.type) {
        case MotionNotify:
          if (btn_pressed) {
            if (rect_w) {
              /* re-draw the last rect to clear it */
              XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
            }

            rect_x = rx;
            rect_y = ry;
            rect_w = ev.xmotion.x - rect_x;
            rect_h = ev.xmotion.y - rect_y;

            /* Change the cursor to show we're selecting a region */
            if (rect_w < 0 && rect_h < 0)
              XChangeActivePointerGrab(disp,
                                       ButtonMotionMask | ButtonReleaseMask,
                                       cursor_nw, CurrentTime);
            else if (rect_w < 0 && rect_h > 0)
              XChangeActivePointerGrab(disp,
                                       ButtonMotionMask | ButtonReleaseMask,
                                       cursor_sw, CurrentTime);
            else if (rect_w > 0 && rect_h < 0)
              XChangeActivePointerGrab(disp,
                                       ButtonMotionMask | ButtonReleaseMask,
                                       cursor_ne, CurrentTime);
            else if (rect_w > 0 && rect_h > 0)
              XChangeActivePointerGrab(disp,
                                       ButtonMotionMask | ButtonReleaseMask,
                                       cursor_se, CurrentTime);

            if (rect_w < 0) {
              rect_x += rect_w;
              rect_w = 0 - rect_w;
            }
            if (rect_h < 0) {
              rect_y += rect_h;
              rect_h = 0 - rect_h;
            }
            /* draw rectangle */
            XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
            XFlush(disp);
          }
          break;
        case ButtonPress:
          btn_pressed = 1;
          rx = ev.xbutton.x;
          ry = ev.xbutton.y;
          target =
            scrot_get_window(disp, ev.xbutton.subwindow, ev.xbutton.x,
                             ev.xbutton.y);
          if (target == None)
            target = root;
          break;
        case ButtonRelease:
          done = 1;
          break;
        case KeyPress:
          fprintf(stderr, "Key was pressed, aborting shot\n");
          done = 2;
          break;
        case KeyRelease:
          /* ignore */
          break;
        default:
          break;
      }
    }
    if (done)
      break;

    /* now block some */
    FD_ZERO(&fdset);
    FD_SET(xfd, &fdset);
    errno = 0;
    count = select(fdsize, &fdset, NULL, NULL, NULL);
    if ((count < 0)
        && ((errno == ENOMEM) || (errno == EINVAL) || (errno == EBADF)))
      gib_eprintf("Connection to X display lost");
  }
  if (rect_w) {
    XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
    XFlush(disp);
  }
  XUngrabPointer(disp, CurrentTime);
  XUngrabKeyboard(disp, CurrentTime);
  XFreeCursor(disp, cursor);
  XFreeGC(disp, gc);
  XSync(disp, True);


  if (done < 2) {
    scrot_do_delay();

    Window client_window = None;

    if (rect_w > 5) {
      /* if a rect has been drawn, it's an area selection */
      rw = ev.xbutton.x - rx;
      rh = ev.xbutton.y - ry;

      if (rw < 0) {
        rx += rw;
        rw = 0 - rw;
      }
      if (rh < 0) {
        ry += rh;
        rh = 0 - rh;
      }
    } else {
      /* else it's a window click */
      if (!scrot_get_geometry(target, &client_window, &rx, &ry, &rw, &rh))
        return NULL;
    }
    scrot_nice_clip(&rx, &ry, &rw, &rh);

    XBell(disp, 0);
    if(opt.alpha)
      im = scrot_grab_transparent_shot(disp, client_window, rx, ry, rw, rh);
    else
      im = gib_imlib_create_image_from_drawable(root, 0, rx, ry, rw, rh, 1);
  }
  return im;
}
Esempio n. 10
0
int main(int argc, const char * argv[]) {
  if (argc != 2) {
      printf("Usage: %s output_filename\n", argv[0]);
      return EXIT_FAILURE;
  }

  const char * const filename = argv[1];

  int rx = 0, ry = 0, rw = 0, rh = 0;
  int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0;
  int btn_pressed = 0, done = 0;

  XEvent ev;
  Display *disp = XOpenDisplay(NULL);

  if(!disp) {
    return EXIT_FAILURE;
  }

  Screen *scr = NULL;
  scr = ScreenOfDisplay(disp, DefaultScreen(disp));

  Window root = 0;
  root = RootWindow(disp, XScreenNumberOfScreen(scr));

  Cursor cursor, cursor2;
  cursor = XCreateFontCursor(disp, XC_left_ptr);
  cursor2 = XCreateFontCursor(disp, XC_lr_angle);

  XGCValues gcval;
  gcval.foreground = XWhitePixel(disp, 0);
  gcval.function = GXxor;
  gcval.background = XBlackPixel(disp, 0);
  gcval.plane_mask = gcval.background ^ gcval.foreground;
  gcval.subwindow_mode = IncludeInferiors;

  GC gc;
  gc = XCreateGC(disp, root,
                 GCFunction | GCForeground | GCBackground | GCSubwindowMode,
                 &gcval);

  /* this XGrab* stuff makes XPending true ? */
  if ((XGrabPointer
       (disp, root, False,
        ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync,
        GrabModeAsync, root, cursor, CurrentTime) != GrabSuccess))
    printf("couldn't grab pointer:");

  if ((XGrabKeyboard
       (disp, root, False, GrabModeAsync, GrabModeAsync,
        CurrentTime) != GrabSuccess))
    printf("couldn't grab keyboard:");

  while (!done) {
    while (!done && XPending(disp)) {
      XNextEvent(disp, &ev);
      switch (ev.type) {
        case MotionNotify:
        /* this case is purely for drawing rect on screen */
          if (btn_pressed) {
            if (rect_w) {
              /* re-draw the last rect to clear it */
              XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
            } else {
              /* Change the cursor to show we're selecting a region */
              XChangeActivePointerGrab(disp,
                                       ButtonMotionMask | ButtonReleaseMask,
                                       cursor2, CurrentTime);
            }
            rect_x = rx;
            rect_y = ry;
            rect_w = ev.xmotion.x - rect_x;
            rect_h = ev.xmotion.y - rect_y;

            if (rect_w < 0) {
              rect_x += rect_w;
              rect_w = 0 - rect_w;
            }
            if (rect_h < 0) {
              rect_y += rect_h;
              rect_h = 0 - rect_h;
            }
            /* draw rectangle */
            XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
            XFlush(disp);
          }
          break;
        case ButtonPress:
          btn_pressed = 1;
          rx = ev.xbutton.x;
          ry = ev.xbutton.y;
          break;
        case ButtonRelease:
          done = 1;
          break;
      }
    }
  }
  /* clear the drawn rectangle */
  if (rect_w) {
    XDrawRectangle(disp, root, gc, rect_x, rect_y, rect_w, rect_h);
    XFlush(disp);
  }
  rw = ev.xbutton.x - rx;
  rh = ev.xbutton.y - ry;
  /* cursor moves backwards */
  if (rw < 0) {
    rx += rw;
    rw = 0 - rw;
  }
  if (rh < 0) {
    ry += rh;
    rh = 0 - rh;
  }

  XCloseDisplay(disp);

  char buf[128];

  sprintf(buf, "byzanz-record %s -c -x %d -y %d -w %d -h %d\n", filename, rx, ry, rw, rh);
  printf(buf);
  system(buf);

  return EXIT_SUCCESS;
}
Esempio n. 11
0
main()
{
      Window w2;

      Display *dpy = XOpenDisplay(NIL);
      assert(dpy);
      Screen *scr = DefaultScreenOfDisplay(dpy);

      // CreateWindow

      Window w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			       CopyFromParent, CopyFromParent,
			       0, NIL);

      XDestroyWindow(dpy, w);

      // CreateWindow with arguments

      XSetWindowAttributes swa;
      swa.background_pixel = WhitePixelOfScreen(scr);
      swa.bit_gravity = NorthWestGravity;
      swa.border_pixel = BlackPixelOfScreen(scr);
      swa.colormap = DefaultColormapOfScreen(scr);
      swa.cursor = None;
      swa.win_gravity = NorthGravity;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixel | CWBitGravity | CWBorderPixel | CWColormap | CWCursor | CWWinGravity, 
			&swa);
      
      // CreateWindow with other arguments

      XDestroyWindow(dpy, w);

      Pixmap pixmap = XCreatePixmap(dpy, RootWindowOfScreen(scr), 45, 25, DefaultDepthOfScreen(scr));
      assert(pixmap);

      swa.background_pixmap = pixmap;
      swa.border_pixmap = pixmap;

      w = XCreateWindow(dpy, RootWindowOfScreen(scr), 10, 100, 200, 300, 0, CopyFromParent,
			CopyFromParent, CopyFromParent,
			CWBackPixmap | CWBorderPixmap,
			&swa);
      
      // ChangeWindowAttributes

      swa.backing_planes = 0x1;
      swa.backing_pixel = WhitePixelOfScreen(scr);
      swa.save_under = True;
      swa.event_mask = KeyPressMask | KeyReleaseMask;
      swa.do_not_propagate_mask = ButtonPressMask | Button4MotionMask;
      swa.override_redirect = False;
      XChangeWindowAttributes(dpy, w, CWBackingPlanes | CWBackingPixel | CWSaveUnder | CWEventMask
			      | CWDontPropagate | CWOverrideRedirect, &swa);

      // GetWindowAttributes

      XWindowAttributes wa;
      Status success = XGetWindowAttributes(dpy, w, &wa);

      // DestroyWindow (done)

      // DestroySubwindows

      w2 = XCreateWindow(dpy, w, 20, 30, 40, 50, 3, CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XDestroySubwindows(dpy, w);

      // ChangeSaveSet

//        Display *dpy2 = XOpenDisplay(NIL);
//        assert(dpy2);
//        XAddToSaveSet(dpy2, w);
//        XCloseDisplay(dpy2);

      // ReparentWindow

      w2 = XCreateWindow(dpy, RootWindowOfScreen(scr), 20, 30, 40, 50, 3, 
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);
      XReparentWindow(dpy, w2, w, 10, 5);

      // MapWindow

      XMapWindow(dpy, w);

      // MapSubwindows
      
      XMapSubwindows(dpy, w);

      // UnmapWindow
      
      XUnmapWindow(dpy, w);

      // UnmapSubwindows

      XMapWindow(dpy, w);
      XUnmapSubwindows(dpy, w2);
      XMapSubwindows(dpy, w);

      // ConfigureWindow

      Window w3 = XCreateWindow(dpy, w, 10, 50, 100, 10, 2,
			 CopyFromParent, CopyFromParent, CopyFromParent, 0, NIL);

      XMapWindow(dpy, w3);

      XWindowChanges wc;
      wc.x = -5;
      wc.y = -10;
      wc.width = 50;
      wc.height = 40;
      wc.border_width = 7;
      wc.sibling = w2;
      wc.stack_mode = Opposite;
      XConfigureWindow(dpy, w3, 
		       CWX | CWY | CWWidth | CWHeight | CWBorderWidth | CWSibling | CWStackMode, 
		       &wc);

      // CirculateWindow

      XCirculateSubwindows(dpy, w, RaiseLowest);

      // GetGeometry

      Window root;
      int x, y;
      unsigned width, height, border_width, depth;
      XGetGeometry(dpy, w, &root, &x, &y, &width, &height, &border_width, &depth);

      // QueryTree

      Window parent;
      Window *children;
      unsigned nchildren;
      success = XQueryTree(dpy, w, &root, &parent, &children, &nchildren);
      XFree(children);

      // InternAtom

      Atom a = XInternAtom(dpy, "WM_PROTOCOLS", True);

      // GetAtomName

      char *string = XGetAtomName(dpy, XA_PRIMARY);
      XFree(string);

      // ChangeProperty

      XStoreName(dpy, w, "test window");

      // DeleteProperty

      XDeleteProperty(dpy, w, XA_WM_NAME);

      // GetProperty
      // TODO

      // ListProperties

      int num_prop;
      Atom *list = XListProperties(dpy, w, &num_prop);
      XFree(list);

      // SetSelectionOwner

      XSetSelectionOwner(dpy, XA_PRIMARY, w, 12000);
      XSetSelectionOwner(dpy, XA_SECONDARY, w, CurrentTime);

      // GetSelectionOwner

      Window wx = XGetSelectionOwner(dpy, XA_PRIMARY);

      // ConvertSelection

      XConvertSelection(dpy, XA_SECONDARY, XA_CURSOR, XA_POINT, w, CurrentTime);

      // SendEvent

      // GrabPointer

      std::cerr << "Grabbing" << std::endl;
      int res = XGrabPointer(dpy, w, False, Button5MotionMask | PointerMotionHintMask,
			     GrabModeSync, GrabModeAsync, w, None, CurrentTime);
      XSync(dpy, False);
//      sleep(5);

      // UngrabPointer

      std::cerr << "Ungrabbing" << std::endl;
      XUngrabPointer(dpy, CurrentTime);

      // GrabButton

      XGrabButton(dpy, 3, ShiftMask | ControlMask, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      XGrabButton(dpy, 2, AnyModifier, w, False, PointerMotionHintMask | Button2MotionMask, 
		  GrabModeAsync, GrabModeSync, None, None);
		  
      // UngrabButton

      XUngrabButton(dpy, 2, LockMask, w);

      // ChangeActivePointerGrab

      XChangeActivePointerGrab(dpy, ButtonPressMask, None, CurrentTime);

      // GrabKeyboard

      XGrabKeyboard(dpy, w, True, GrabModeSync, GrabModeSync, 12000);

      // UngrabKeyboard

      XUngrabKeyboard(dpy, 13000);

      // GrabKey

      XGrabKey(dpy, XKeysymToKeycode(dpy, XK_Tab), ShiftMask | Mod3Mask, w, True, GrabModeSync,
	       GrabModeSync);

      // UngrabKey

      XUngrabKey(dpy, AnyKey, AnyModifier, w);

      // AllowEvents

      XAllowEvents(dpy, AsyncPointer, 14000);

      // GrabServer

      XGrabServer(dpy);

      // UngrabServer

      XUngrabServer(dpy);

      // QueryPointer

      Window child;
      int root_x, root_y, win_x, win_y;
      unsigned mask;
      Bool bres = XQueryPointer(dpy, w, &root, &child, &root_x, &root_y, &win_x, &win_y, &mask);

      // GetMotionEvents

      int nevents;
      XGetMotionEvents(dpy, w, 15000, 16000, &nevents);

      // TranslateCoordinates

      int dest_x, dest_y;

      XTranslateCoordinates(dpy, w, w2, 10, 20, &dest_x, &dest_y, &child);

      // WarpPointer

      XWarpPointer(dpy, w, w2, 0, 0, 100, 100, 20, 30);

      // SetInputFocus

      XSetInputFocus(dpy,w, RevertToPointerRoot, 17000);
      XSetInputFocus(dpy, PointerRoot, RevertToPointerRoot, 17000);

      // GetInputFocus

      Window focus;
      int revert_to;
      XGetInputFocus(dpy, &focus, &revert_to);

      // QueryKeymap

      char keys_return[32];
      XQueryKeymap(dpy, keys_return);

      // OpenFont

      Font fid = XLoadFont(dpy, "cursor");

      // CloseFont

      XUnloadFont(dpy, fid);

      // QueryFont

      XFontStruct *fs = XLoadQueryFont(dpy, "cursor");
      assert(fs);

      // QueryTextExtents

      int direction, font_ascent, font_descent;
      XCharStruct overall;
      XQueryTextExtents(dpy, fs -> fid, "toto", 4, &direction, &font_ascent, &font_descent, &overall);
      XQueryTextExtents(dpy, fs -> fid, "odd__length", 11, &direction, &font_ascent, &font_descent, &overall);

      XChar2b c2bs;
      c2bs.byte1 = '$';
      c2bs.byte2 = 'B';
      XQueryTextExtents16(dpy, fs -> fid, &c2bs, 1, &direction, &font_ascent, &font_descent, &overall);

      XQueryTextExtents(dpy, fs -> fid, longString, strlen(longString), &direction, &font_ascent, 
			&font_descent, &overall);

      // ListFonts

      int actual_count;
      char **fontList = XListFonts(dpy, "*", 100, &actual_count);
      XFree((char *)fontList);

      // ListFontsWithInfo

      int count;
      XFontStruct *info;
      char **names = XListFontsWithInfo(dpy, "*", 100, &count, &info);
      XFreeFontInfo(names, info, count);

      // SetFontPath
      // GetFontPath

      int npaths;
      char **charList = XGetFontPath(dpy, &npaths);

      char **charList2 = new char *[npaths + 1];
      memcpy(charList2, charList, npaths * sizeof(char *));
      charList2[npaths] = charList2[0];

      XSetFontPath(dpy, charList2, npaths + 1);
      XSetFontPath(dpy, charList, npaths); // Reset to some reasonnable value

      XFreeFontPath(charList);
      delete [] charList2;

      // CreatePixmap

      Pixmap pix2 = XCreatePixmap(dpy, w, 100, 200, DefaultDepthOfScreen(scr));

      // FreePixmap

      XFreePixmap(dpy, pix2);

      // CreateGC

      Pixmap bitmap = XCreateBitmapFromData(dpy, RootWindowOfScreen(scr), 
					    "\000\000\001\000\000\001\000\000\001\377\377\377", 3, 4);

      XGCValues gcv;
      gcv.function = GXand;
      gcv.plane_mask = 0x1;
      gcv.foreground = WhitePixelOfScreen(scr);
      gcv.background = BlackPixelOfScreen(scr);
      gcv.line_width = 2;
      gcv.line_style = LineDoubleDash;
      gcv.cap_style = CapProjecting;
      gcv.join_style = JoinRound;
      gcv.fill_style = FillStippled;
      gcv.fill_rule = EvenOddRule;
      gcv.arc_mode = ArcPieSlice;
      gcv.tile = pixmap;
      gcv.stipple = bitmap;
      gcv.ts_x_origin = 3;
      gcv.ts_y_origin = 4;
      gcv.font = fs -> fid;
      gcv.subwindow_mode = ClipByChildren;
      gcv.graphics_exposures = True;
      gcv.clip_x_origin = 5;
      gcv.clip_y_origin = 6;
      gcv.clip_mask = bitmap;
      gcv.dash_offset = 1;
      gcv.dashes = 0xc2;
      
      GC gc = XCreateGC(dpy, w, 
			  GCFunction | GCPlaneMask | GCForeground | GCBackground | GCLineWidth
			| GCLineStyle | GCCapStyle | GCJoinStyle | GCFillStyle | GCFillRule | GCTile
			| GCStipple | GCTileStipXOrigin | GCTileStipYOrigin | GCFont | GCSubwindowMode
			| GCGraphicsExposures | GCClipXOrigin | GCClipYOrigin | GCClipMask | GCDashOffset
			| GCDashList | GCArcMode,
			&gcv);

      // ChangeGC

      gcv.function = GXandReverse;

      // Only a few of these should appear, since the values are cached on the client side by the Xlib.

      XChangeGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, &gcv);

      // CopyGC
      
      GC gc2 = XCreateGC(dpy, w, 0, NIL);
      XCopyGC(dpy, gc, GCFunction | GCLineStyle | GCStipple | GCGraphicsExposures | GCDashList, gc2);

      // SetDashes

      XSetDashes(dpy, gc, 3, "\001\377\001", 3);

      // SetClipRectangles

      XRectangle rectangles[] = { { 10, 20, 30, 40 }, { 100, 200, 5, 3 }, { -5, 1, 12, 24 } };
      XSetClipRectangles(dpy, gc, 12, 9, rectangles, SIZEOF(rectangles), Unsorted);

      // FreeGC

	    // done already

      // ClearArea

      XClearArea(dpy, w, 30, 10, 10, 100, False);

      // CopyArea

      XCopyArea(dpy, w, pixmap, gc, 0, 0, 100, 100, 10, 10);

      // CopyPlane

      // This won't work if the Screen doesn't have at least 3 planes
      XCopyPlane(dpy, pixmap, w, gc, 20, 10, 40, 30, 0, 0, 0x4);

      // PolyPoint

      XDrawPoint(dpy, w, gc, 1, 2);

      XPoint points[] = { { 3, 4 }, { 5, 6 } };
      XDrawPoints(dpy, w, gc, points, SIZEOF(points), CoordModeOrigin);

      // PolyLine

      XDrawLines(dpy, w, gc, points, SIZEOF(points), CoordModePrevious);

      // PolySegment

      XSegment segments[] = { { 7, 8, 9, 10 }, { 11, 12, 13, 14 }, { 15, 16, 17, 18 } };
      XDrawSegments(dpy, w, gc, segments, SIZEOF(segments));

      // PolyRectangle

      XDrawRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyArc

      XArc arcs[] = { { 10, 20, 30, 40, 50, 60 }, { -70, 80, 90, 100, 110, 120 }, 
		      { 10, 20, 30, 40, 50, -30 } };

      XDrawArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // FillPoly

      XFillPolygon(dpy, w, gc, points, SIZEOF(points), Convex, CoordModePrevious);

      // PolyFillRectangle
      
      XFillRectangles(dpy, w, gc, rectangles, SIZEOF(rectangles));

      // PolyFillArc
      
      XFillArcs(dpy, w, gc, arcs, SIZEOF(arcs));

      // PutImage
      // GetImage

      XImage *image = XGetImage(dpy, w, 10, 20, 40, 30, AllPlanes, ZPixmap);
      XPutImage(dpy, w, gc, image, 0, 0, 50, 60, 40, 30);
      XSync(dpy, False); // Make the next request starts at the beginning of a packet

      // PolyText8
      XTextItem textItems[3];
      textItems[0].chars = "toto";
      textItems[0].nchars = strlen(textItems[0].chars);
      textItems[0].delta = -3;
      textItems[0].font = fs->fid;
      textItems[1].chars = "titi";
      textItems[1].nchars = strlen(textItems[1].chars);
      textItems[1].delta = 3;
      textItems[1].font = None;
      textItems[2].chars = "tutu";
      textItems[2].nchars = strlen(textItems[2].chars);
      textItems[2].delta = 0;
      textItems[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems, 3);


      XTextItem textItems2[3];
      textItems2[0].chars = "totox";
      textItems2[0].nchars = strlen(textItems2[0].chars);
      textItems2[0].delta = -3;
      textItems2[0].font = fs->fid;
      textItems2[1].chars = "titi";
      textItems2[1].nchars = strlen(textItems2[1].chars);
      textItems2[1].delta = 3;
      textItems2[1].font = None;
      textItems2[2].chars = "tutu";
      textItems2[2].nchars = strlen(textItems2[2].chars);
      textItems2[2].delta = 0;
      textItems2[2].font = fs->fid;

      XDrawText(dpy, w, gc, 10, 10, textItems2, 3);

      // PolyText16

      XChar2b c2b2[] = { 0, 't', 0, 'x' };

      XTextItem16 items16[] = { { &c2bs, 1, -5, None }, { NULL, 0, 0, None }, { c2b2, 2, 0, fs -> fid } };
      XDrawText16(dpy, w, gc, 10, 0, items16, SIZEOF(items16));

      // ImageText8

      XDrawImageString(dpy, w, gc, 10, 10, "toto", 4);

      // ImageText16

      XDrawImageString16(dpy, w, gc, 10, 10, &c2bs, 1);
      XDrawImageString16(dpy, w, gc, 10, 20, c2b2, 2);

      // CreateColormap
      // Don't forget to tell the kids how it was when we had only 8 bits per pixel.

      Colormap colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // FreeColormap

      XFreeColormap(dpy, colormap);
      colormap = XCreateColormap(dpy, w, DefaultVisualOfScreen(scr), None);

      // CopyColormapAndFree

      Colormap colormap2 = XCopyColormapAndFree(dpy, colormap);

      // InstallColormap

      XInstallColormap(dpy, colormap2);

      // UninstallColormap

      XUninstallColormap(dpy, colormap2);

      // ListInstalledColormaps

      int num;
      Colormap *colormapList = XListInstalledColormaps(dpy, w, &num);

      // AllocColor

      XColor screen;
      screen.red = 0;
      screen.green = 32767;
      screen.blue = 65535;
      screen.flags = DoRed | DoGreen | DoBlue;
      success = XAllocColor(dpy, colormap, &screen);

      // AllocNamedColor

      XColor screen2, exact;
      success = XAllocNamedColor(dpy, colormap, "Wheat", &screen2, &exact);

      // AllocColorCells

      unsigned long plane_masks, pixels;
      success = XAllocColorCells(dpy, colormap, False, &plane_masks, 1, &pixels, 1);

      // AllocColorPlanes

      unsigned long rmask, gmask, bmask;
      success = XAllocColorPlanes(dpy, colormap, False, &pixels, 1, 0, 0, 0, &rmask, &gmask, &bmask);

      // FreeColors

      unsigned long pixels2[2] = { screen.pixel, screen2.pixel };
      XFreeColors(dpy, colormap, pixels2, 2, 0);

      // StoreColors

      success = XAllocColorCells(dpy, colormap, False, NIL, 0, pixels2, 2);

      // On many contemporary (that is, year 2000) video cards, you can't allocate read / write cells
      // I want my requests to be sent, however.
      if (!success) {
	    XSetErrorHandler(errorHandler);
      }

      XColor colors[2];
      colors[0] = screen;  colors[0].pixel = pixels2[0];
      colors[1] = screen2; colors[1].pixel = pixels2[1];
      XStoreColors(dpy, colormap, colors, 2);

      // StoreNamedColor

      XStoreNamedColor(dpy, colormap, "Wheat", colors[0].pixel, DoBlue);

      XSync(dpy, False);
      XSetErrorHandler(NIL); // Restore the default handler

      // QueryColors

      screen2.pixel = WhitePixelOfScreen(scr);
      XQueryColor(dpy, colormap, &screen2);

      // LookupColor

      success = XLookupColor(dpy, colormap, "DarkCyan", &exact, &screen);

      // CreateCursor

      Cursor cursor = XCreatePixmapCursor(dpy, pixmap, None, &exact, colors, 10, 10);

      // CreateGlyphCursor
      
      Cursor cursor2 = XCreateGlyphCursor(dpy, fs -> fid, fs -> fid, 'X', 0, &exact, colors);

      // FreeCursor
      
      XFreeCursor(dpy, cursor2);

      // RecolorCursor

      XRecolorCursor(dpy, cursor, colors, &exact);

      // QueryBestSize

      success = XQueryBestSize(dpy, CursorShape, RootWindowOfScreen(scr), 100, 20, &width, &height);

      // QueryExtension

      int major_opcode, first_event, first_error;
      XQueryExtension(dpy, "toto", &major_opcode, &first_event, &first_error);

      // ListExtensions

      int nextensions;
      char **extensionList = XListExtensions(dpy, &nextensions);
      for(char **p = extensionList; nextensions; nextensions--, p++) std::cout << *p << std::endl;
      XFree(extensionList);

      // ChangeKeyboardMapping
      // GetKeyboardMapping

      int min_keycodes, max_keycodes;
      XDisplayKeycodes(dpy, &min_keycodes, &max_keycodes);

      int keysyms_per_keycode;
      KeySym *keysyms = XGetKeyboardMapping(dpy, min_keycodes, max_keycodes - min_keycodes + 1,
					    &keysyms_per_keycode);
      XChangeKeyboardMapping(dpy, min_keycodes, keysyms_per_keycode, keysyms, 
			     max_keycodes - min_keycodes + 1);

      // ChangeKeyboardControl
      // GetKeyboardControl

      XKeyboardState keyboardState;
      XGetKeyboardControl(dpy, &keyboardState);

      XKeyboardControl keyboardValues;
      keyboardValues.key_click_percent = keyboardState.key_click_percent;
      keyboardValues.bell_percent = keyboardState.bell_percent;
      keyboardValues.bell_pitch = keyboardState.bell_pitch;
      keyboardValues.bell_duration = keyboardState.bell_duration;
      keyboardValues.led = 1;
      keyboardValues.led_mode = LedModeOn;
      keyboardValues.key = min_keycodes;
      keyboardValues.auto_repeat_mode = AutoRepeatModeDefault;
      XChangeKeyboardControl(dpy, 
			       KBKeyClickPercent | KBBellPercent | KBBellPitch | KBBellDuration
			     | KBLed | KBLedMode | KBKey | KBAutoRepeatMode,
			     &keyboardValues);

      // Bell

      XBell(dpy, 90);

      // ChangePointerControl
      // GetPointerControl

      int accel_numerator, accel_denominator, threshold;
      XGetPointerControl(dpy, &accel_numerator, &accel_denominator, &threshold);

      XChangePointerControl(dpy, True, True, accel_numerator, accel_denominator, threshold);

      // SetScreenSaver
      // GetScreenSaver

      int timeout, interval, prefer_blanking, allow_exposures;
      XGetScreenSaver(dpy, &timeout, &interval, &prefer_blanking, &allow_exposures);
      XSetScreenSaver(dpy, timeout, interval, prefer_blanking, allow_exposures);

      // ChangeHosts
      // ListHosts

      int nhosts;
      Bool state;
      XHostAddress *hostList = XListHosts(dpy, &nhosts, &state);

      XHostAddress host;
      host.family = FamilyInternet;
      host.length = 4;
      host.address = "\001\002\003\004";
      XAddHost(dpy, &host);

      // SetAccessControl

      XSetAccessControl(dpy, EnableAccess);

      // SetCloseDownMode

      XSetCloseDownMode(dpy, RetainTemporary);

      // KillClient

      XKillClient(dpy, AllTemporary);

      // RotateProperties

      Atom properties[] = { XInternAtom(dpy, "CUT_BUFFER0", False), 
			    XInternAtom(dpy, "CUT_BUFFER1", False),
			    XInternAtom(dpy, "CUT_BUFFER2", False) };
      XRotateWindowProperties(dpy, RootWindowOfScreen(scr), properties, SIZEOF(properties), -1);

      // ForceScreenSaver

      XForceScreenSaver(dpy, ScreenSaverReset);

      // SetPointerMapping
      // GetPointerMapping

      unsigned char map[64];
      int map_length = XGetPointerMapping(dpy, map, 64);
      XSetPointerMapping(dpy, map, map_length);

      // SetModifierMapping
      // GetModifierMapping

      XModifierKeymap *modmap = XGetModifierMapping(dpy);
      XSetModifierMapping(dpy, modmap);

      // NoOperation

      XNoOp(dpy);

      for(;;) {
	    XEvent e;
	    XNextEvent(dpy, &e);
	    std::cout << "Got an event of type " << e.type << std::endl;
      }
}
Esempio n. 12
0
int grab_rectangle (Display * display, Window root, XRectangle * xrect)
{
    Cursor cursor_start, cursor_finis;
    unsigned int x, y, rootx, rooty;
    int rx, ry, rw = 0, rh = 0;
    int drawn = False;
    XEvent event;
    GC gc;

    /* get some cursors for rectangle formation */
    // cursor_start = XCreateFontCursor (display, XC_ul_angle);
    // cursor_finis = XCreateFontCursor (display, XC_lr_angle);
    cursor_start = XCreateFontCursor (display, XC_pencil);
    cursor_finis = XCreateFontCursor (display, XC_pencil);
    
    /* grab the pointer */
    if (GrabSuccess != XGrabPointer (display, root, False, ButtonPressMask,
            GrabModeAsync, GrabModeAsync, root, cursor_start, CurrentTime))
    return 1;

    /* create a graphics context to draw with */
    gc = XCreateGC (display, root, 0, NULL);
    if (!gc)
        return 2;
    XSetSubwindowMode (display, gc, IncludeInferiors);
    XSetForeground (display, gc, 255);
    XSetFunction (display, gc, GXxor);

    /* get a button-press and pull out the root location */
    XMaskEvent (display, ButtonPressMask, &event);
    rootx = rx = event.xbutton.x_root;
    rooty = ry = event.xbutton.y_root;

    /* get pointer motion events */
    XChangeActivePointerGrab (display, ButtonMotionMask | ButtonReleaseMask,
                                cursor_finis, CurrentTime);

    /* MAKE_RECT converts the original root coordinates and the event root
     * coordinates into a rectangle in xrect */
#define MAKE_RECT(etype)            \
x = event.etype.x_root;           \
y = event.etype.y_root;           \
rw = x - rootx;               \
vecx = rw;                    \
if (rw  < 0) rw  = -rw;           \
rh = y - rooty;               \
vecy = -rh;                    \
if (rh  < 0) rh  = -rh;           \
rx = x < rootx ? x : rootx;           \
ry = y < rooty ? y : rooty

    /* loop to let the user drag a rectangle */
    while (1)
    {
        XNextEvent (display, &event);
        
        switch (event.type)
        {
            case ButtonRelease:
                if (drawn)
                {
                  XDrawRectangle (display, root, gc, rx, ry, rw, rh);
                  drawn = 0;
                }
                XFlush (display);
                /* record the final location */
                MAKE_RECT (xbutton);
                /* release resources */
                XFreeGC (display, gc);
                XFreeCursor (display, cursor_start);
                XFreeCursor (display, cursor_finis);
                xrect->x = rx;
                xrect->y = ry;
                xrect->width = rw;
                xrect->height = rh;
                XUngrabPointer (display, CurrentTime);
                XSync (display, 0);
                return 1;
            case MotionNotify:
                if (drawn)
                {
                  XDrawRectangle (display, root, gc, rx, ry, rw, rh);
                  drawn = 0;
                }
                while (XCheckTypedEvent (display, MotionNotify, &event))
                {}
                MAKE_RECT (xmotion);
                XDrawRectangle (display, root, gc, rx, ry, rw, rh);
                drawn = 1;
                break;
        }
    }

    return 0;
}
Esempio n. 13
0
void
gui_move_window(winlist_t *win)
{
    xccore_t *xccore = (xccore_t *)win->data;
    int event_x, event_y;
    int offset_x, offset_y;
    int move_x, move_y;
    GC  moveGC;
    int draw_flag = False;
    int workarea_x, workarea_y;
    int workarea_x2, workarea_y2;
    unsigned int workarea_width, workarea_height;

    gui_get_workarea(&workarea_x, &workarea_y,
			&workarea_width, &workarea_height);

    workarea_x2 = workarea_x + workarea_width;
    workarea_y2 = workarea_y + workarea_height;

    gui_get_mouse_xy(&event_x, &event_y);
    offset_x = event_x - win->pos_x;
    offset_y = event_y - win->pos_y;

    moveGC = XCreateGC(gui->display, gui->root, 0, NULL);
    XSetSubwindowMode(gui->display, moveGC, IncludeInferiors);
    XSetForeground(gui->display, moveGC, BlackPixel(gui->display, gui->screen));
    XSetFunction(gui->display, moveGC, GXxor);

    XChangeActivePointerGrab(gui->display,
                PointerMotionMask | ButtonMotionMask | ButtonReleaseMask |
                OwnerGrabButtonMask, None, CurrentTime);

    XGrabServer(gui->display);

    XEvent myevent;
    while(1)
    {
	XNextEvent(gui->display, &myevent);
	switch(myevent.type)
	{
	    case ButtonRelease:
		if(myevent.xbutton.button == Button1)
		{
		    if (draw_flag)
		    {
			gui_draw_xor_box(moveGC, move_x - offset_x, move_y - offset_y, win->width, win->height);
		    }
		    XFreeGC(gui->display, moveGC);
		    gui_get_mouse_xy(&move_x, &move_y);
		    win->pos_x = move_x - offset_x;
		    win->pos_y = move_y - offset_y;

		    /* */
		    if (win->pos_x < workarea_x)
			win->pos_x = workarea_x;
		    if (win->pos_y < workarea_y)
			win->pos_y = workarea_y;
		    if (win->pos_x + win->width > workarea_x2)
			win->pos_x = workarea_x2 - win->width - 2;
		    if (win->pos_y + win->height > workarea_y2)
			win->pos_y = workarea_y2 - win->height - 2;

		    XMoveWindow(gui->display, win->window,
				 win->pos_x, win->pos_y);
		    XUngrabServer(gui->display);
		    gui_save_window_pos(); /* 儲存視窗位置 */
		    return;
		}
		break;

	    case MotionNotify:
		if (draw_flag)
		{
		    gui_draw_xor_box(moveGC, move_x - offset_x, move_y - offset_y, win->width, win->height);
		}
		gui_get_mouse_xy(&move_x, &move_y);
		gui_draw_xor_box(moveGC, move_x - offset_x, move_y - offset_y, win->width, win->height);
		draw_flag = True;
		break;
	    default:
		break;
	}
    }
}
Esempio n. 14
0
void
move_opaque (Client * c)
{
  XEvent report;
  Client *p;
  int old_x, old_y;
  int move_x, move_y;
  char geo[16];
  int len;

  if (!c)
    return;

  getmouse (&old_x, &old_y, c->screen);

  XMapRaised (dpy, c->parent);
  setmouse (c->x, c->y, c->screen);

  XChangeActivePointerGrab (dpy,
			    PointerMotionHintMask | ButtonMotionMask |
			    ButtonReleaseMask | OwnerGrabButtonMask,
			    c->screen->place, CurrentTime);

  while (1)
    {
      XNextEvent (dpy, &report);

      switch (report.type)
	{
#ifdef THREE_D
	case Expose:
	  p = getclient (report.xexpose.window, 0);

	  if (p)
	    {
	      draw_border (p, p == current ? 1 : 0);
	    }
	  break;
#endif

	case ButtonRelease:
	  if (report.xbutton.button == Button1)
	    {
	      getmouse (&move_x, &move_y, c->screen);

	      c->x = move_x;
	      c->y = move_y;

	      XMoveWindow (dpy, c->parent, c->x, c->y);
	      sendconfig (c);

	      setmouse (old_x, old_y, c->screen);
	      update_tbar ();
	      return;
	    }
	  break;

	case MotionNotify:
	  while (XCheckTypedEvent (dpy, MotionNotify, &report));

	  getmouse (&move_x, &move_y, c->screen);

	  XMoveWindow (dpy, c->parent, move_x, move_y);
	  sendconfig (c);

	  len = sprintf (geo, "+%d+%d", move_x, move_y);

	  XClearWindow (dpy, c->screen->barwin);
#ifdef THREE_D
	  XDrawLine (dpy, c->screen->barwin, c->screen->botwhitegc, 0,
		     prefs.bar_height - 1, BAR_WIDTH (c->screen) - 1,
		     prefs.bar_height - 1);
	  XDrawLine (dpy, c->screen->barwin, c->screen->botwhitegc,
		     BAR_WIDTH (c->screen) - 1, prefs.bar_height - 1,
		     BAR_WIDTH (c->screen) - 1, 0);
	  XDrawLine (dpy, c->screen->barwin, c->screen->topwhitegc, 0, 0,
		     BAR_WIDTH (c->screen) - 1, 0);
	  XDrawLine (dpy, c->screen->barwin, c->screen->topwhitegc, 0, 0, 0,
		     prefs.bar_height - 1);
#endif
	  XDrawString (dpy, c->screen->barwin, c->screen->gc, prefs.bar_height,
		       BAR_TEXT_Y, geo, len);
	  break;
	}
    }
}
Esempio n. 15
0
int
xu_ptr_regrab(unsigned int mask, Cursor curs)
{
	return (XChangeActivePointerGrab(X_Dpy, mask,
	    curs, CurrentTime) == GrabSuccess ? 0 : -1);
}
Esempio n. 16
0
File: cursor.c Progetto: Cougar/pwm
void change_grab_cursor(int cursor)
{
	XChangeActivePointerGrab(wglobal.dpy, GRAB_POINTER_MASK,
							 cursors[cursor], CurrentTime);
}
Esempio n. 17
0
static void appicon_move_motion(virtual_screen *vscr, WScreen *scr, XEvent ev,
                                WDock **lastDock, WDock **originalDock,
                                WAppIcon *aicon, WDock **allDocks,
                                Bool *collapsed, Bool *dockable, Bool *ondock,
                                int *x, int *y, int *ix, int *iy,
                                int *shad_x, int *shad_y, int *ofs_x, int *ofs_y,
				Bool *grabbed, int omnipresent, Bool *showed_all_clips)
{
	WDock *theNewDock = NULL;
	int i, j;

	if (!(*grabbed)) {
		if (abs(*ofs_x - ev.xmotion.x) < MOVE_THRESHOLD &&
		    abs(*ofs_y - ev.xmotion.y) < MOVE_THRESHOLD)
			return;

		XChangeActivePointerGrab(dpy,
					 ButtonMotionMask | ButtonReleaseMask | ButtonPressMask,
					 wPreferences.cursor[WCUR_MOVE], CurrentTime);
		*grabbed = True;
	}

	if (omnipresent && !(*showed_all_clips)) {
		for (j = 0; j < vscr->workspace.count; j++) {
			if (j == vscr->workspace.current)
				continue;

			wDockShowIcons(vscr->workspace.array[j]->clip);
			/*
			 * Note: if dock is collapsed (for instance, because it
			 * auto-collapses), its icons still won't show up
			 */
		}

		*showed_all_clips = True; /* To prevent flickering */
	}

	*x = ev.xmotion.x_root - *ofs_x;
	*y = ev.xmotion.y_root - *ofs_y;
	wAppIconMove(aicon, *x, *y);
	if (!(ev.xmotion.state & MOD_MASK) || aicon->launching || aicon->lock || *originalDock == NULL) {
		for (i = 0; *dockable && i < vscr->drawer.drawer_count + 2; i++) {
			WDock *theDock = allDocks[i];
			if (theDock == NULL)
				break;

			if (wDockSnapIcon(theDock, aicon, *x, *y, ix, iy, (theDock == *originalDock))) {
				theNewDock = theDock;
				break;
			}
		}

		/* Stay in lastDock if no dock really wants us */
		if (*originalDock != NULL && theNewDock == NULL &&
		    (aicon->launching || aicon->lock || aicon->running))
			theNewDock = *lastDock;
	}

	if (*lastDock != NULL && *lastDock != theNewDock) {
		/* Leave lastDock in the state we found it */
		if ((*lastDock)->type == WM_DRAWER)
			wDrawerFillTheGap(*lastDock, aicon, (*lastDock == *originalDock));

		if (*collapsed) {
			(*lastDock)->collapsed = 1;
			wDockHideIcons(*lastDock);
			*collapsed = False;
		}

		if ((*lastDock)->auto_raise_lower)
			wDockLower(*lastDock);
	}

	if (theNewDock != NULL) {
		if (*lastDock != theNewDock) {
			*collapsed = theNewDock->collapsed;
			if (*collapsed) {
				theNewDock->collapsed = 0;
				wDockShowIcons(theNewDock);
			}

			if (theNewDock->auto_raise_lower) {
				wDockRaise(theNewDock);
				/* And raise the moving tile above it */
				wRaiseFrame(aicon->icon->vscr, aicon->icon->core);
			}

			*lastDock = theNewDock;
		}

		*shad_x = (*lastDock)->x_pos + *ix * wPreferences.icon_size;
		*shad_y = (*lastDock)->y_pos + *iy * wPreferences.icon_size;

		XMoveWindow(dpy, scr->dock_shadow, *shad_x, *shad_y);

		if (!(*ondock))
			XMapWindow(dpy, scr->dock_shadow);

		*ondock = 1;
	} else {
		*lastDock = NULL;
		if (*ondock)
			XUnmapWindow(dpy, scr->dock_shadow);

		*ondock = 0;
	}
}
Esempio n. 18
0
void
appIconMouseDown(WObjDescriptor *desc, XEvent *event)
{
    WAppIcon *aicon = desc->parent;
    WIcon *icon = aicon->icon;
    XEvent ev;
    int x=aicon->x_pos, y=aicon->y_pos;
    int dx=event->xbutton.x, dy=event->xbutton.y;
    int grabbed=0;
    int done=0;
    int superfluous = wPreferences.superfluous; /* we catch it to avoid problems */
    WScreen *scr = icon->core->screen_ptr;
    WWorkspace *workspace = scr->workspaces[scr->current_workspace];
    int shad_x = 0, shad_y = 0, docking=0, dockable, collapsed = 0;
    int ix, iy;
    int clickButton = event->xbutton.button;
    Pixmap ghost = None;
    Window wins[2];
    Bool movingSingle = False;
    int oldX = x;
    int oldY = y;
    Bool hasMoved = False;

    if (aicon->editing || WCHECK_STATE(WSTATE_MODAL))
        return;

    if (IsDoubleClick(scr, event)) {
        iconDblClick(desc, event);
        return;
    }

    if (event->xbutton.button == Button3) {
        WObjDescriptor *desc;
        WApplication *wapp = wApplicationOf(aicon->icon->owner->main_window);

        if (!wapp)
            return;

        if (event->xbutton.send_event &&
            XGrabPointer(dpy, aicon->icon->core->window, True, ButtonMotionMask
                         |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
                         GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
            wwarning("pointer grab failed for appicon menu");
            return;
        }

        openApplicationMenu(wapp, event->xbutton.x_root,
                            event->xbutton.y_root);

        /* allow drag select of menu */
        desc = &scr->icon_menu->menu->descriptor;
        event->xbutton.send_event = True;
        (*desc->handle_mousedown)(desc, event);
        return;
    }

#ifdef DEBUG
    puts("Moving icon");
#endif
    if (event->xbutton.state & MOD_MASK)
        wLowerFrame(icon->core);
    else
        wRaiseFrame(icon->core);

    if (XGrabPointer(dpy, icon->core->window, True, ButtonMotionMask
                     |ButtonReleaseMask|ButtonPressMask, GrabModeAsync,
                     GrabModeAsync, None, None, CurrentTime) !=GrabSuccess) {
        wwarning("pointer grab failed for appicon move");
    }

    if (wPreferences.flags.nodock && wPreferences.flags.noclip)
        dockable = 0;
    else
        dockable = canBeDocked(icon->owner);

    wins[0] = icon->core->window;
    wins[1] = scr->dock_shadow;
    XRestackWindows(dpy, wins, 2);
    if (superfluous) {
        if (icon->pixmap!=None)
            ghost = MakeGhostIcon(scr, icon->pixmap);
        else
            ghost = MakeGhostIcon(scr, icon->core->window);
        XSetWindowBackgroundPixmap(dpy, scr->dock_shadow,
                                   ghost);
        XClearWindow(dpy, scr->dock_shadow);
    }

    while (!done) {
        WMMaskEvent(dpy, PointerMotionMask|ButtonReleaseMask|ButtonPressMask
                    |ButtonMotionMask|ExposureMask, &ev);
        switch (ev.type) {
        case Expose:
            WMHandleEvent(&ev);
            break;

        case MotionNotify:
            hasMoved = True;
            if (!grabbed) {
                if (abs(dx-ev.xmotion.x)>=MOVE_THRESHOLD
                    || abs(dy-ev.xmotion.y)>=MOVE_THRESHOLD) {
                    XChangeActivePointerGrab(dpy, ButtonMotionMask
                                             |ButtonReleaseMask|ButtonPressMask,
                                             wCursor[WCUR_MOVE], CurrentTime);
                    grabbed=1;
                } else {
                    break;
                }
            }
            x = ev.xmotion.x_root - dx;
            y = ev.xmotion.y_root - dy;

            if (movingSingle) {
                XMoveWindow(dpy, icon->core->window, x, y);
            } else {
                wAppIconMove(aicon, x, y);
            }

            if (dockable) {
                if (scr->dock && wDockSnapIcon(scr->dock, aicon, x, y,
                                               &ix, &iy, False)) {
                    shad_x = scr->dock->x_pos + ix*wPreferences.icon_size;
                    shad_y = scr->dock->y_pos + iy*wPreferences.icon_size;

                    if (scr->last_dock != scr->dock && collapsed) {
                        scr->last_dock->collapsed = 1;
                        wDockHideIcons(scr->last_dock);
                        collapsed = 0;
                    }
                    if (!collapsed && (collapsed = scr->dock->collapsed)) {
                        scr->dock->collapsed = 0;
                        wDockShowIcons(scr->dock);
                    }

                    if (scr->dock->auto_raise_lower)
                        wDockRaise(scr->dock);

                    scr->last_dock = scr->dock;

                    XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
                    if (!docking) {
                        XMapWindow(dpy, scr->dock_shadow);
                    }
                    docking = 1;
                } else if (workspace->clip &&
                           wDockSnapIcon(workspace->clip, aicon, x, y,
                                         &ix, &iy, False)) {
                    shad_x = workspace->clip->x_pos + ix*wPreferences.icon_size;
                    shad_y = workspace->clip->y_pos + iy*wPreferences.icon_size;

                    if (scr->last_dock != workspace->clip && collapsed) {
                        scr->last_dock->collapsed = 1;
                        wDockHideIcons(scr->last_dock);
                        collapsed = 0;
                    }
                    if (!collapsed && (collapsed = workspace->clip->collapsed)) {
                        workspace->clip->collapsed = 0;
                        wDockShowIcons(workspace->clip);
                    }

                    if (workspace->clip->auto_raise_lower)
                        wDockRaise(workspace->clip);

                    scr->last_dock = workspace->clip;

                    XMoveWindow(dpy, scr->dock_shadow, shad_x, shad_y);
                    if (!docking) {
                        XMapWindow(dpy, scr->dock_shadow);
                    }
                    docking = 1;
                } else if (docking) {
                    XUnmapWindow(dpy, scr->dock_shadow);
                    docking = 0;
                }
            }

            break;

        case ButtonPress:
            break;

        case ButtonRelease:
            if (ev.xbutton.button != clickButton)
                break;
            XUngrabPointer(dpy, CurrentTime);

            if (docking) {
                Bool docked;

                /* icon is trying to be docked */
                SlideWindow(icon->core->window, x, y, shad_x, shad_y);
                XUnmapWindow(dpy, scr->dock_shadow);
                docked = wDockAttachIcon(scr->last_dock, aicon, ix, iy);
                if (scr->last_dock->auto_collapse) {
                    collapsed = 0;
                }
                if (workspace->clip &&
                    workspace->clip != scr->last_dock &&
                    workspace->clip->auto_raise_lower)
                    wDockLower(workspace->clip);

                if (!docked) {
                    /* If icon could not be docked, slide it back to the old
                     * position */
                    SlideWindow(icon->core->window, x, y, oldX, oldY);
                }

                wSoundPlay(WSOUND_DOCK);
            } else {
                if (movingSingle) {
                    /* move back to its place */
                    SlideWindow(icon->core->window, x, y, oldX, oldY);
                    wAppIconMove(aicon, oldX, oldY);
                } else {
                    XMoveWindow(dpy, icon->core->window, x, y);
                    aicon->x_pos = x;
                    aicon->y_pos = y;
                }
                if (workspace->clip && workspace->clip->auto_raise_lower)
                    wDockLower(workspace->clip);
            }
            if (collapsed) {
                scr->last_dock->collapsed = 1;
                wDockHideIcons(scr->last_dock);
                collapsed = 0;
            }
            if (superfluous) {
                if (ghost!=None)
                    XFreePixmap(dpy, ghost);
                XSetWindowBackground(dpy, scr->dock_shadow, scr->white_pixel);
            }

            if (wPreferences.auto_arrange_icons)
                wArrangeIcons(scr, True);

            if (wPreferences.single_click && !hasMoved)
                iconDblClick(desc, event);

            done = 1;
            break;
        }
    }
#ifdef DEBUG
    puts("End icon move");
#endif

}
Esempio n. 19
0
void
resize_opaque (Client * c)
{
  XEvent report;
  Client *p;
  int old_x, old_y;
  int move_x, move_y;
  char geo[32];
  int len, sx, sy, rx = 0, ry = 0, mx = 0, my = 0;

  if (!c)
    return;

  getmouse (&old_x, &old_y, c->screen);

  if (c->size.flags & PMinSize)
    {
      mx = c->size.min_width;
      my = c->size.min_height;
    }

  if (c->size.flags & PResizeInc)
    {
      rx = c->size.width_inc;
      ry = c->size.height_inc;
    }

  XMapRaised (dpy, c->parent);
  setmouse (c->x + c->dx + 1 + BORDER, c->y + c->dy + 1 + BORDER, c->screen);

  XChangeActivePointerGrab (dpy,
			    PointerMotionHintMask | ButtonMotionMask |
			    ButtonReleaseMask | OwnerGrabButtonMask,
			    c->screen->sweep, CurrentTime);

  while (1)
    {
      XNextEvent (dpy, &report);

      switch (report.type)
	{
#ifdef THREE_D
	case Expose:
	  p = getclient (report.xexpose.window, 0);

	  if (p)
	    {
	      draw_border (p, p == current ? 1 : 0);
	    }
	  break;
#endif

	case ButtonRelease:
	  if (report.xbutton.button == Button1)
	    {
	      getmouse (&move_x, &move_y, c->screen);

	      c->dx = move_x - BORDER - c->x - 1;
	      c->dy = move_y - BORDER - c->y - 1;

	      adjust_hints (c);

	      XResizeWindow (dpy, c->window, c->dx, c->dy);
	      XResizeWindow (dpy, c->parent, c->dx + (2 * BORDER),
			     c->dy + (2 * BORDER));
	      sendconfig (c);

	      if (shape)
		setshape (c);

	      setmouse (old_x, old_y, c->screen);
	      update_tbar ();
	      return;
	    }
	  break;

	case MotionNotify:
	  while (XCheckTypedEvent (dpy, MotionNotify, &report));

	  getmouse (&move_x, &move_y, c->screen);

	  c->dx = move_x - BORDER - c->x - 1;
	  c->dy = move_y - BORDER - c->y - 1;

	  adjust_hints (c);

	  sx = c->dx;
	  sy = c->dy;

	  XResizeWindow (dpy, c->window, c->dx, c->dy);
	  XResizeWindow (dpy, c->parent, c->dx + (2 * BORDER),
			 c->dy + (2 * BORDER));
	  sendconfig (c);

	  if (shape)
	    setshape (c);

	  if (rx)
	    {
	      if (mx)
		sx -= mx;

	      sx /= rx;
	      sx++;
	    }

	  if (ry)
	    {
	      if (my)
		sy -= my;

	      sy /= ry;
	      sy++;
	    }

	  if (rx || ry)
	    len = sprintf (geo, "%dx%d (%dx%d)", sx, sy, c->dx, c->dy);
	  else
	    len = sprintf (geo, "%dx%d", c->dx, c->dy);


	  XClearWindow (dpy, c->screen->barwin);
#ifdef THREE_D
	  XDrawLine (dpy, c->screen->barwin, c->screen->botwhitegc, 0,
		     prefs.bar_height - 1, BAR_WIDTH (c->screen) - 1,
		     prefs.bar_height - 1);
	  XDrawLine (dpy, c->screen->barwin, c->screen->botwhitegc,
		     BAR_WIDTH (c->screen) - 1, prefs.bar_height - 1,
		     BAR_WIDTH (c->screen) - 1, 0);
	  XDrawLine (dpy, c->screen->barwin, c->screen->topwhitegc, 0, 0,
		     BAR_WIDTH (c->screen) - 1, 0);
	  XDrawLine (dpy, c->screen->barwin, c->screen->topwhitegc, 0, 0, 0,
		     prefs.bar_height - 1);
#endif
	  XDrawString (dpy, c->screen->barwin, c->screen->gc, prefs.bar_height,
		       BAR_TEXT_Y, geo, len);
	  break;
	}
    }
}
Esempio n. 20
0
int
selectArea(
        Display *disp,
        Window *root,
        Rect *rect
) {
    int rx = 0, ry = 0, rw = 0, rh = 0;
    int rect_x = 0, rect_y = 0, rect_w = 0, rect_h = 0;
    int btn_pressed = 0, done = 0;

    XEvent ev;

    Cursor cursor, cursor2;
    cursor = XCreateFontCursor(disp, XC_left_ptr);
    cursor2 = XCreateFontCursor(disp, XC_lr_angle);

    XGCValues gcval;
    gcval.foreground = XWhitePixel(disp, 0);
    gcval.function = GXxor;
    gcval.background = XBlackPixel(disp, 0);
    gcval.plane_mask = gcval.background ^ gcval.foreground;
    gcval.subwindow_mode = IncludeInferiors;

    GC gc;
    gc = XCreateGC(disp, *root,
                   GCFunction | GCForeground | GCBackground | GCSubwindowMode,
                   &gcval);

    /* this XGrab* stuff makes XPending true ? */
    if ((XGrabPointer
                 (disp, *root, False,
                  ButtonMotionMask | ButtonPressMask | ButtonReleaseMask, GrabModeAsync,
                  GrabModeAsync, *root, cursor, CurrentTime) != GrabSuccess)) {
        printf("couldn't grab pointer:");
        return -1;
    }

    while (!done) {
        while (!done && XPending(disp)) {
            XNextEvent(disp, &ev);
            switch (ev.type) {
                case MotionNotify:
                    /* this case is purely for drawing rect on screen */
                    if (btn_pressed) {
                        if (rect_w) {
                            /* re-draw the last rect to clear it */
                            XDrawRectangle(disp, *root, gc, rect_x, rect_y, rect_w, rect_h);
                        } else {
                            /* Change the cursor to show we're selecting a region */
                            XChangeActivePointerGrab(disp,
                                                     ButtonMotionMask | ButtonReleaseMask,
                                                     cursor2, CurrentTime);
                        }
                        rect_x = rx;
                        rect_y = ry;
                        rect_w = ev.xmotion.x - rect_x;
                        rect_h = ev.xmotion.y - rect_y;

                        if (rect_w < 0) {
                            rect_x += rect_w;
                            rect_w = 0 - rect_w;
                        }
                        if (rect_h < 0) {
                            rect_y += rect_h;
                            rect_h = 0 - rect_h;
                        }
                        /* draw rectangle */
                        XDrawRectangle(disp, *root, gc, rect_x, rect_y, rect_w, rect_h);
                        XFlush(disp);
                    }
                    break;
                case ButtonPress:
                    btn_pressed = 1;
                    rx = ev.xbutton.x;
                    ry = ev.xbutton.y;
                    break;
                case ButtonRelease:
                    done = 1;
                    break;
            }
        }
    }
    /* clear the drawn rectangle */
    if (rect_w) {
        XDrawRectangle(disp, *root, gc, rect_x, rect_y, rect_w, rect_h);
        XFlush(disp);
    }
    rw = ev.xbutton.x - rx;
    rh = ev.xbutton.y - ry;
    /* cursor moves backwards */
    if (rw < 0) {
        rx += rw;
        rw = 0 - rw;
    }
    if (rh < 0) {
        ry += rh;
        rh = 0 - rh;
    }

    rect->w = rw;
    rect->h = rh;
    rect->x = rx;
    rect->y = ry;

    XFreeGC(disp, gc);

    return 0;
}