Пример #1
0
void rclick_root(void)
{
	XEvent ev;
	if (!grab(root, MouseMask, None))
	{
		return;
	}
	draw_menubar();
	do
	{
		XMaskEvent(dsply, MouseMask|KeyMask, &ev);
		switch (ev.type)
		{
			case MotionNotify:
				if (ev.xmotion.y < BARHEIGHT())
				{
					ungrab();
					rclick_taskbar(ev.xmotion.x);
					return;
				}
				break;
			case KeyPress:
				XPutBackEvent(dsply, &ev);
				break;
		}
	}
	while (ev.type != ButtonRelease && ev.type != KeyPress);

	redraw_taskbar();
	ungrab();
}
Пример #2
0
static void UnmapClients (ClientData *pCD, unsigned int event_mask)
{
    ClientData *pNext;
    Boolean doGrab = False;

    pNext = pCD->transientChildren;
    while (pNext)
    {
	/* unmap all children first */
	if (pNext->transientChildren)
	    UnmapClients (pNext, (unsigned int) 0);

	/* then unmap all siblings at this level */
	XUnmapWindow (DISPLAY, pNext->clientFrameWin);
	XUnmapWindow (DISPLAY, pNext->client);
	pNext->wmUnmapCount++;
	pNext = pNext->transientSiblings;
    }

    if (event_mask)
	doGrab = (Success == XGrabPointer (DISPLAY, DefaultRootWindow(DISPLAY),
		False, event_mask, GrabModeAsync, GrabModeAsync,
		None, None, CurrentTime));
    /* unmap this primary window */
    XUnmapWindow (DISPLAY, pCD->clientFrameWin); 
    XUnmapWindow (DISPLAY, pCD->client);
    if (event_mask && doGrab)
	{
	XEvent event;
	XMaskEvent(DISPLAY, event_mask, &event);
	XUngrabPointer(DISPLAY,CurrentTime);
	}
    pCD->wmUnmapCount++;

} /* END OF FUNCTION UnmapClients */
Пример #3
0
void _pan_zoom(int mode) {
	int x, y, xx, yy, dx, dy, ig;
	unsigned int w, h, uig;
	Window wig;
	XEvent ev;
	XQueryPointer(dpy, root, &wig, &wig, &xx, &yy, &ig, &ig , &uig);
	XGetGeometry(dpy, presWin, &wig, &x, &y, &w, &h, &uig, &uig);
	XGrabPointer(dpy, root, true, PointerMotionMask | ButtonReleaseMask,
			GrabModeAsync, GrabModeAsync, None, None, CurrentTime);
	while (true) {
		XMaskEvent(dpy, PointerMotionMask | ButtonReleaseMask, &ev);
		if (ev.type == ButtonRelease) break;
		dx = ev.xbutton.x_root - xx; xx = ev.xbutton.x_root;
		dy = ev.xbutton.y_root - yy; yy = ev.xbutton.y_root;
		XClearWindow(dpy, topWin);
		if (mode == 1) {
			XMoveWindow(dpy, presWin, x+=dx, y+=dy);
		}
		else if (mode == 3) {
			if ((w+=dx) > winMax) w = winMax;
			if (w < winMin) w = winMin;
			if ((h+=dy) > winMax) h = winMax;
			if (h < winMin) h = winMin;
			XResizeWindow(dpy, presWin, w, h);
			render_page(cur, presWin, true);
		}
		while (XCheckMaskEvent(dpy, PointerMotionMask, &ev));
	}
	XUngrabPointer(dpy, CurrentTime);
}
Пример #4
0
/**********************************************************************
 * If no application window was indicated on the command line, prompt
 * the user to select one
 *********************************************************************/
Window
get_target_window ()
{
	XEvent eventp;
	int val = -10, trials;
	Window target = None;

	trials = 0;
	while ((trials < 100) && (val != GrabSuccess))
    {
		val = XGrabPointer (dpy, Scr.Root, True,
				  		   	ButtonReleaseMask,
			  				GrabModeAsync, GrabModeAsync, Scr.Root,
			  				XCreateFontCursor (dpy, XC_crosshair),
			  				CurrentTime);
      	if( val != GrabSuccess )
			sleep_a_little (100);
		trials++;
    }
  	if (val != GrabSuccess)
    {
    	show_error( "Couldn't grab the cursor!\n", MyName);
      	DeadPipe(0);
    }
  	XMaskEvent (dpy, ButtonReleaseMask, &eventp);
  	XUngrabPointer (dpy, CurrentTime);
  	ASSync(0);
  	target = eventp.xbutton.window;
	LOCAL_DEBUG_OUT( "window = %lX, root = %lX, subwindow = %lX", 
					 eventp.xbutton.window, eventp.xbutton.root, eventp.xbutton.subwindow );
  	if( eventp.xbutton.subwindow != None )
    	target = eventp.xbutton.subwindow;
	return target;
}
Пример #5
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);
}
Пример #6
0
int
readmouse(Point *p, uint *button) {
	XEvent ev;

	for(;;) {
		XMaskEvent(display, MouseMask|ExposureMask|PropertyChangeMask, &ev);
		debug_event(&ev);
		switch(ev.type) {
		case Expose:
		case NoExpose:
		case PropertyNotify:
			event_dispatch(&ev);
		default:
			Dprint(DEvent, "readmouse(): ignored: %E\n", &ev);
			continue;
		case ButtonPress:
		case ButtonRelease:
			*button = ev.xbutton.button;
		case MotionNotify:
			p->x = ev.xmotion.x_root;
			p->y = ev.xmotion.y_root;
			if(p->x == scr.rect.max.x - 1)
				p->x = scr.rect.max.x;
			if(p->y == scr.rect.max.y - 1)
				p->y = scr.rect.max.y;
			break;
		}
		return ev.type;
	}
}
Пример #7
0
int
readmouse(Point *p, uint *button) {
	XEvent ev;

	for(;;) {
		XMaskEvent(display, MouseMask|ExposureMask|StructureNotifyMask|PropertyChangeMask, &ev);
		switch(ev.type) {
		case ConfigureNotify:
		case Expose:
		case NoExpose:
		case PropertyNotify:
			dispatch_event(&ev);
		default:
			continue;
		case ButtonPress:
		case ButtonRelease:
			*button = ev.xbutton.button;
		case MotionNotify:
			p->x = ev.xmotion.x_root;
			p->y = ev.xmotion.y_root;
			break;
		}
		return ev.type;
	}
}
Пример #8
0
static __inline__ int X11_WarpedMotion(_THIS, XEvent *xevent)
{
	int w, h, i;
	int deltax, deltay;
	int posted;

	w = SDL_VideoSurface->w;
	h = SDL_VideoSurface->h;
	deltax = xevent->xmotion.x - mouse_last.x;
	deltay = xevent->xmotion.y - mouse_last.y;
#ifdef DEBUG_MOTION
  printf("Warped mouse motion: %d,%d\n", deltax, deltay);
#endif
	mouse_last.x = xevent->xmotion.x;
	mouse_last.y = xevent->xmotion.y;
	posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);

	if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
	     (xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
	     (xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
	     (xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
		/* Get the events that have accumulated */
		while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
			deltax = xevent->xmotion.x - mouse_last.x;
			deltay = xevent->xmotion.y - mouse_last.y;
#ifdef DEBUG_MOTION
  printf("Extra mouse motion: %d,%d\n", deltax, deltay);
#endif
			mouse_last.x = xevent->xmotion.x;
			mouse_last.y = xevent->xmotion.y;
			posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
		}
		mouse_last.x = w/2;
		mouse_last.y = h/2;
		XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
					mouse_last.x, mouse_last.y);
		for ( i=0; i<10; ++i ) {
        		XMaskEvent(SDL_Display, PointerMotionMask, xevent);
			if ( (xevent->xmotion.x >
			          (mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
			     (xevent->xmotion.x <
			          (mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
			     (xevent->xmotion.y >
			          (mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
			     (xevent->xmotion.y <
			          (mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
				break;
			}
#ifdef DEBUG_XEVENTS
  printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
#endif
		}
#ifdef DEBUG_XEVENTS
		if ( i == 10 ) {
			printf("Warning: didn't detect mouse warp motion\n");
		}
#endif
	}
	return(posted);
}
Пример #9
0
static gboolean
meta_backend_x11_nested_handle_host_xevent (MetaBackendX11 *x11,
                                            XEvent         *event)
{
#ifdef HAVE_WAYLAND
  if (event->type == FocusIn)
    {
      Window xwin = meta_backend_x11_get_xwindow (x11);
      XEvent xev;

      if (event->xfocus.window == xwin)
        {
          MetaWaylandCompositor *compositor =
            meta_wayland_compositor_get_default ();
          Display *xdisplay = meta_backend_x11_get_xdisplay (x11);

          /*
           * Since we've selected for KeymapStateMask, every FocusIn is
           * followed immediately by a KeymapNotify event.
           */
          XMaskEvent (xdisplay, KeymapStateMask, &xev);
          meta_wayland_compositor_update_key_state (compositor,
                                                    xev.xkeymap.key_vector,
                                                    32, 8);
        }
    }
#endif

  return FALSE;
}
Пример #10
0
static void sorter(const char *cmd) {
	int i, j, n, nn = show->cur, grid, pn = -1;
	grid = (int) ceil(sqrt(show->nslides));
	cairo_surface_t *t = cairo_image_surface_create(0, show->w, show->h);
	cairo_t *ctx = cairo_create(t);
	cairo_scale(ctx, MARGIN/(float)grid, MARGIN/(float)grid);
	cairo_translate(ctx,
			(show->w * (1-MARGIN))/2.0,
			(show->w * (1-MARGIN))/2.0);
	grab_mouse();
	XEvent ev;
	XDefineCursor(dpy, wshow, None);
	while (True) {
		if (nn != pn) {
			pn = nn;
			cairo_set_source_rgba(ctx, 0, 0, 0, 1);
			cairo_paint(ctx);
			for (j = 0; j < grid; j++) for (i = 0; i < grid; i++) {
				if ( (n=j * grid + i) >= show->nslides ) break;
				cairo_set_source_surface(ctx, show->slide[n],
					(show->w * i)/MARGIN, (show->h * j)/MARGIN);
				cairo_paint_with_alpha(ctx,(n == nn ? 1.0 : 0.5));
			}
			cairo_set_source_surface(show->target[0].ctx, t, 0, 0);
			cairo_paint(show->target[0].ctx);
			XFlush(dpy);
		}
		XMaskEvent(dpy,PointerMotionMask|ButtonPressMask|KeyPressMask,&ev);
		if (ev.type == KeyPress) {
			switch (XkbKeycodeToKeysym(dpy, ev.xkey.keycode, 0, 0)) {
				case 'h': case XK_Right: nn++; break;
				case 'j': case XK_Down: nn += grid; break;
				case 'k': case XK_Up: nn -= grid; break;
				case 'l': case XK_Left: nn--; break;
				case XK_space: case XK_Return: goto full_break_change; break;
				default: goto full_break_no_change;
			}
			if (nn < 0) nn = 0;
			else if (nn >= show->nslides) nn = show->nslides - 1;
		}
		else if (ev.type == ButtonPress) {
			if (ev.xbutton.button == 1) break;
			else if (ev.xbutton.button == 2) goto full_break_no_change;
			else if (ev.xbutton.button == 3) goto full_break_no_change;
		}
		else if (ev.type == MotionNotify) {
			nn = (ev.xbutton.y * grid / show->h) * grid +
					(ev.xbutton.x * grid / show->w);
		}
	}
	full_break_change:
	show->cur = nn;
	full_break_no_change:
	XUngrabKeyboard(dpy, CurrentTime);
	XUngrabPointer(dpy, CurrentTime);
	cairo_destroy(ctx);
	cairo_surface_destroy(t);
	XDefineCursor(dpy, wshow, invisible_cursor);
	draw(None);
}
Пример #11
0
void
init_xterm(int move)
{
	XEvent ev;

	system(command);
	while (1) {
		XMaskEvent(dpy, SubstructureNotifyMask, &ev);
		if (ev.type == CreateNotify || ev.type == MapNotify) {
			termwin = ev.xcreatewindow.window;
			break;
		}
	}

	XSetWindowBorderWidth(dpy, termwin, 0);
	if (move) {
		resize_inc = get_height_inc();
		height = get_optimal_height(resize_inc * opt_height);
		resize_term(opt_width, height);
		XMoveWindow(dpy, win, opt_x, -(height + opt_bw));
		XSync(dpy, False);
	}
	XSetInputFocus(dpy, termwin, RevertToPointerRoot, CurrentTime);
	XSync(dpy, False);
}
Пример #12
0
/*
 * If the application doesn't receive events with timestamp for a long time
 * XtLastTimestampProcessed() will return out-of-date value. This may cause
 * selection handling routines to fail (see BugTraq ID 4085183).
 * This routine is to resolve this problem. It queries the current X server
 * time by appending a zero-length data to a property as prescribed by
 * X11 Reference Manual.
 * Note that this is a round-trip request, so it can be slow. If you know
 * that the Xt timestamp is up-to-date use XtLastTimestampProcessed().
 */
Time
awt_util_getCurrentServerTime() {

    JNIEnv *env = (JNIEnv *)JNU_GetEnv(jvm, JNI_VERSION_1_2);
    static Atom _XA_JAVA_TIME_PROPERTY_ATOM = 0;
    Time server_time = 0;

    AWT_LOCK();

    if (_XA_JAVA_TIME_PROPERTY_ATOM == 0) {
        XtAddEventHandler(awt_root_shell, PropertyChangeMask, False,
                          propertyChangeEventHandler, NULL);
        _XA_JAVA_TIME_PROPERTY_ATOM = XInternAtom(awt_display, "_SUNW_JAVA_AWT_TIME", False);
    }

    timeStampUpdated = False;
    XChangeProperty(awt_display, XtWindow(awt_root_shell),
                    _XA_JAVA_TIME_PROPERTY_ATOM, XA_ATOM, 32, PropModeAppend,
                    (unsigned char *)"", 0);
    XFlush(awt_display);

    if (awt_currentThreadIsPrivileged(env)) {
        XEvent event;
        XMaskEvent(awt_display, PropertyChangeMask, &event);
        XtDispatchEvent(&event);
    } else {
        awt_MToolkit_modalWait(isTimeStampUpdated, NULL);
    }
    server_time = XtLastTimestampProcessed(awt_display);

    AWT_UNLOCK();

    return server_time;
}
Пример #13
0
void
resize()
{
	XEvent ev;
	if (!XGrabPointer
		(dpy, root, False,
		 ButtonPressMask | ButtonReleaseMask | PointerMotionMask,
		 GrabModeAsync, GrabModeAsync, None, cursor, CurrentTime) == GrabSuccess)
		return;
	resize_inc = get_height_inc();
	while (1) {
		XMaskEvent(dpy, ButtonPressMask | ButtonReleaseMask | PointerMotionHintMask, &ev);
		switch (ev.type) {
		case MotionNotify:
			if (ev.xmotion.y >= resize_inc) {
				height = ev.xmotion.y - ev.xmotion.y % resize_inc;
				height = get_optimal_height(height);
				resize_term(opt_width, height);
				break;
		case ButtonRelease:
				XUngrabPointer(dpy, CurrentTime);
				return;
			}
		}
	}
}
Пример #14
0
void handle_keypress_event(XEvent * e)
{
	XEvent event;
	XGrabKey(display, AnyKey, AnyModifier, root, True, GrabModeAsync, GrabModeAsync);
        XMaskEvent (display, KeyPressMask, &event);
	XDefineCursor(display, selected, (XCreateFontCursor(display, CURSOR)));
	unsigned int key = XLookupKeysym((XKeyEvent *) &event, 0);
	if (key >= '0' && key <= '9')
	{
		XUngrabKey(display, AnyKey, AnyModifier, root);
		grab_keyboard();
		select_window(key - '0');
		return;
	}
	switch (key)
        {       
		case KEY_TERMINAL:
			spawn(TERMINAL);
			break;
		case KEY_MENU:
			spawn(MENU);
			break;
		case KEY_STATUS:
			echo_output(STATUS);
			break;
		case KEY_WINLIST:
			if(TIMEOUT > 0)
			{
				list_windows();
			}			
			break;
		case KEY_KILL:
			XDestroyWindow(display, selected);
			selected = root;
			break;
		case KEY_PREV:
			if(get_prev_window() != -1){
				select_window(get_prev_window());
			} else {
				message("Can't access previous window!");
			}
			break;
		case KEY_NEXT:
			if(get_next_window() != -1)
			{
				select_window(get_next_window());
			} else {
				message("Can't access next window!");
			}
			break;
                default:
                        message("Key \"%c\" is unbound!", (char)key);
	}

	XUngrabKey(display, AnyKey, AnyModifier, root);
	grab_keyboard();
	XSetInputFocus (display, selected, RevertToParent, CurrentTime);
}
Пример #15
0
int mask_event (long event_mask, register XEvent * event_return)
{
	register int res;

	res = XMaskEvent (dpy, event_mask, event_return);
	if (res)
		stash_event_time (event_return);
	return res;
}
Пример #16
0
Файл: mlx.c Проект: TijmenW/tom7
int ml_maskevent(Display * d, long m, XEvent * * xe) {

  XEvent * x = (XEvent*) malloc(sizeof (XEvent));
  
  XMaskEvent(d, m, x);

  *xe = x;

  return x->type;
}
Пример #17
0
void xf_create_window(xfInfo* xfi)
{
	XEvent xevent;
	char* win_title;
	int width, height;

	width = xfi->width;
	height = xfi->height;

	xfi->attribs.background_pixel = BlackPixelOfScreen(xfi->screen);
	xfi->attribs.border_pixel = WhitePixelOfScreen(xfi->screen);
	xfi->attribs.backing_store = xfi->primary ? NotUseful : Always;
	xfi->attribs.override_redirect = xfi->fullscreen;
	xfi->attribs.colormap = xfi->colormap;
	xfi->attribs.bit_gravity = ForgetGravity;
	xfi->attribs.win_gravity = StaticGravity;

	if (xfi->instance->settings->window_title != NULL)
	{
		win_title = xstrdup(xfi->instance->settings->window_title);
	}
	else if (xfi->instance->settings->port == 3389)
	{
		win_title = xmalloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->hostname));
		sprintf(win_title, "FreeRDP: %s", xfi->instance->settings->hostname);
	}
	else
	{
		win_title = xmalloc(1 + sizeof("FreeRDP: ") + strlen(xfi->instance->settings->hostname) + sizeof(":00000"));
		sprintf(win_title, "FreeRDP: %s:%i", xfi->instance->settings->hostname, xfi->instance->settings->port);
	}

	xfi->window = xf_CreateDesktopWindow(xfi, win_title, width, height, xfi->decorations);
	xfree(win_title);

	if (xfi->parent_window)
		XReparentWindow(xfi->display, xfi->window->handle, xfi->parent_window, 0, 0);

	if (xfi->fullscreen)
		xf_SetWindowFullscreen(xfi, xfi->window, xfi->fullscreen);

	/* wait for VisibilityNotify */
	do
	{
		XMaskEvent(xfi->display, VisibilityChangeMask, &xevent);
	}
	while (xevent.type != VisibilityNotify);

	xfi->unobscured = (xevent.xvisibility.state == VisibilityUnobscured);

	XSetWMProtocols(xfi->display, xfi->window->handle, &(xfi->WM_DELETE_WINDOW), 1);
	xfi->drawable = xfi->window->handle;
}
Пример #18
0
void
mousefunc_client_resize(struct client_ctx *cc, union arg *arg)
{
    XEvent			 ev;
    Time			 ltime = 0;
    struct screen_ctx	*sc = cc->sc;
    int			 x = cc->geom.x, y = cc->geom.y;

    if (cc->flags & CLIENT_FREEZE)
        return;

    client_raise(cc);
    client_ptrsave(cc);

    if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_RESIZE]) < 0)
        return;

    xu_ptr_setpos(cc->win, cc->geom.w, cc->geom.h);
    mousefunc_sweep_draw(cc);

    for (;;) {
        XMaskEvent(X_Dpy, MOUSEMASK, &ev);

        switch (ev.type) {
        case MotionNotify:
            mousefunc_sweep_calc(cc, x, y,
                                 ev.xmotion.x_root, ev.xmotion.y_root);

            /* don't resize more than 60 times / second */
            if ((ev.xmotion.time - ltime) > (1000 / 60)) {
                ltime = ev.xmotion.time;
                client_resize(cc, 1);
                mousefunc_sweep_draw(cc);
            }
            break;
        case ButtonRelease:
            if (ltime)
                client_resize(cc, 1);
            XUnmapWindow(X_Dpy, sc->menuwin);
            XReparentWindow(X_Dpy, sc->menuwin, sc->rootwin, 0, 0);
            xu_ptr_ungrab();

            /* Make sure the pointer stays within the window. */
            if (cc->ptr.x > cc->geom.w)
                cc->ptr.x = cc->geom.w - cc->bwidth;
            if (cc->ptr.y > cc->geom.h)
                cc->ptr.y = cc->geom.h - cc->bwidth;
            client_ptrwarp(cc);
            return;
        }
    }
    /* NOTREACHED */
}
Пример #19
0
void rclick_taskbar(int x)
{
	XEvent ev;
	int mousex, mousey;
	Rect bounddims;
	unsigned int current_item = UINT_MAX;
	Window constraint_win;
	XSetWindowAttributes pattr;

	get_mouse_position(&mousex, &mousey);

	bounddims.x = 0;
	bounddims.y = 0;
	bounddims.width = DisplayWidth(dsply, screen);
	bounddims.height = BARHEIGHT();

	constraint_win = XCreateWindow(dsply, root, bounddims.x, bounddims.y, bounddims.width, bounddims.height, 0, CopyFromParent, InputOnly, CopyFromParent, 0, &pattr);
	XMapWindow(dsply, constraint_win);

	if (!(XGrabPointer(dsply, root, False, MouseMask, GrabModeAsync, GrabModeAsync, constraint_win, None, CurrentTime) == GrabSuccess))
	{
		XDestroyWindow(dsply, constraint_win);
		return;
	}
	draw_menubar();
	update_menuitem(INT_MAX); // force initial highlight
	current_item = update_menuitem(x);
	do
	{
		XMaskEvent(dsply, MouseMask|KeyMask, &ev);
		switch (ev.type)
		{
			case MotionNotify:
				current_item = update_menuitem(ev.xmotion.x);
				break;
			case ButtonRelease:
				if (current_item != UINT_MAX)
				{
					fork_exec(menuitems[current_item].command);
				}
				break;
			case KeyPress:
				XPutBackEvent(dsply, &ev);
				break;
		}
	}
	while (ev.type != ButtonPress && ev.type != ButtonRelease && ev.type != KeyPress);

	redraw_taskbar();
	XUnmapWindow(dsply, constraint_win);
	XDestroyWindow(dsply, constraint_win);
	ungrab();
}
Пример #20
0
static PetscErrorCode PetscDrawGetMouseButton_X(PetscDraw draw,PetscDrawButton *button,PetscReal* x_user,PetscReal *y_user,PetscReal *x_phys,PetscReal *y_phys)
{
  XEvent       report;
  PetscDraw_X* win = (PetscDraw_X*)draw->data;
  Window       root,child;
  int          root_x,root_y,px,py;
  unsigned int keys_button;
  Cursor       cursor = 0;

  PetscFunctionBegin;
  /* change cursor to indicate input */
  if (!cursor) {
    cursor = XCreateFontCursor(win->disp,XC_hand2);
    if (!cursor) SETERRQ(PETSC_COMM_SELF,PETSC_ERR_LIB,"Unable to create X cursor");
  }
  XDefineCursor(win->disp,win->win,cursor);
  XSelectInput(win->disp,win->win,ButtonPressMask | ButtonReleaseMask);

  while (XCheckTypedEvent(win->disp,ButtonPress,&report));
  XMaskEvent(win->disp,ButtonReleaseMask,&report);
  switch (report.xbutton.button) {
    case Button1:
      if (report.xbutton.state & ShiftMask)
        *button = PETSC_BUTTON_LEFT_SHIFT;
      else
        *button = PETSC_BUTTON_LEFT;
      break;
    case Button2:
      if (report.xbutton.state & ShiftMask)
        *button = PETSC_BUTTON_CENTER_SHIFT;
      else
        *button = PETSC_BUTTON_CENTER;
      break;
    case Button3:
      if (report.xbutton.state & ShiftMask)
        *button = PETSC_BUTTON_RIGHT_SHIFT;
      else
        *button = PETSC_BUTTON_RIGHT;
      break;
  }
  XQueryPointer(win->disp,report.xmotion.window,&root,&child,&root_x,&root_y,&px,&py,&keys_button);

  if (x_phys) *x_phys = ((double)px)/((double)win->w);
  if (y_phys) *y_phys = 1.0 - ((double)py)/((double)win->h);

  if (x_user) *x_user = draw->coor_xl + ((((double)px)/((double)win->w)-draw->port_xl))*(draw->coor_xr - draw->coor_xl)/(draw->port_xr - draw->port_xl);
  if (y_user) *y_user = draw->coor_yl + ((1.0 - ((double)py)/((double)win->h)-draw->port_yl))*(draw->coor_yr - draw->coor_yl)/(draw->port_yr - draw->port_yl);

  XUndefineCursor(win->disp,win->win);
  XFlush(win->disp);
  XSync(win->disp,False);
  PetscFunctionReturn(0);
}
Пример #21
0
void
drag_client(Client * c, int mouse_x, int mouse_y)
{
  XEvent ev;
  Client *exposed;
  int startx, starty;

  startx = c->x;
  starty = c->y;

  /* XGrabServer(disp); */
#ifdef DEBUG
  fprintf(stdout, "in drag_client: %d,%d\n", mouse_x, mouse_y);
#endif

  for (;;) {
    XMaskEvent(disp, ButtonReleaseMask | PointerMotionMask | ExposureMask, &ev);
    switch (ev.type) {
      case MotionNotify:
#ifdef DEBUG
        fprintf(stdout, "got MotionNotify: %d,%d\n", ev.xmotion.x_root,
                ev.xmotion.y_root);
#endif
        c->x = startx + (ev.xmotion.x_root - mouse_x);
        c->y = starty + (ev.xmotion.y_root - mouse_y);
#ifdef DEBUG
        fprintf(stdout, "c->x, c->y: %d,%d\n", c->x, c->y);
#endif

        if (!MOVE_AFTER_DRAG) {
          XMoveWindow(disp, c->frame, c->x, c->y);
          XFlush(disp);
          if (!SEND_CONFIGURE_AFTER_DRAG)
            icccm_send_configure_event(c);
        }
        break;
      case ButtonRelease:
        /* XUngrabServer(disp); */
        return;
      case Expose:
        exposed = find_client_by_frame(ev.xexpose.window);
        if (exposed) {
          exposed->updates =
              imlib_update_append_rect(exposed->updates, ev.xexpose.x,
                                       ev.xexpose.y, ev.xexpose.width,
                                       ev.xexpose.height);
          redraw_client(exposed);
        }
        break;
    }
  }
}
Пример #22
0
void
mousefunc_client_move(struct client_ctx *cc, union arg *arg)
{
    XEvent			 ev;
    Time			 ltime = 0;
    struct screen_ctx	*sc = cc->sc;
    struct geom		 xine;
    int			 px, py;

    client_raise(cc);

    if (cc->flags & CLIENT_FREEZE)
        return;

    if (xu_ptr_grab(cc->win, MOUSEMASK, Conf.cursor[CF_MOVE]) < 0)
        return;

    xu_ptr_getpos(cc->win, &px, &py);

    for (;;) {
        XMaskEvent(X_Dpy, MOUSEMASK, &ev);

        switch (ev.type) {
        case MotionNotify:
            cc->geom.x = ev.xmotion.x_root - px - cc->bwidth;
            cc->geom.y = ev.xmotion.y_root - py - cc->bwidth;

            xine = screen_find_xinerama(sc,
                                        cc->geom.x + cc->geom.w / 2,
                                        cc->geom.y + cc->geom.h / 2, CWM_GAP);
            cc->geom.x += client_snapcalc(cc->geom.x,
                                          cc->geom.x + cc->geom.w + (cc->bwidth * 2),
                                          xine.x, xine.x + xine.w, sc->snapdist);
            cc->geom.y += client_snapcalc(cc->geom.y,
                                          cc->geom.y + cc->geom.h + (cc->bwidth * 2),
                                          xine.y, xine.y + xine.h, sc->snapdist);

            /* don't move more than 60 times / second */
            if ((ev.xmotion.time - ltime) > (1000 / 60)) {
                ltime = ev.xmotion.time;
                client_move(cc);
            }
            break;
        case ButtonRelease:
            if (ltime)
                client_move(cc);
            xu_ptr_ungrab();
            return;
        }
    }
    /* NOTREACHED */
}
Пример #23
0
static void
next_keystroke(ulong *mod, KeyCode *code) {
	XEvent e;
	KeySym sym;
	*mod = 0;

	do {
		XMaskEvent(display, KeyPressMask, &e);
		*mod |= e.xkey.state & valid_mask;
		*code = (KeyCode)e.xkey.keycode;
		sym = XKeycodeToKeysym(display, e.xkey.keycode, 0);
	} while(IsModifierKey(sym));
}
Пример #24
0
void
tilemovemouse(const Arg *arg) {
	/* Could EnterNotify events be used instead? */
	Client *c, *d;
	Monitor *m;
	XEvent ev;
	int x, y;
	Bool after;

	if(!(c = selmon->sel))
		return;

	if((m = recttomon(c->x, c->y, c->w, c->h)) != selmon) {
		sendmon(c, m);
		selmon = m;
		focus(NULL);
	}

	if(c->isfloating || !selmon->lt[selmon->sellt]->arrange){
		movemouse(NULL);
		return;
	}
	if(XGrabPointer(dpy, root, False, MOUSEMASK, GrabModeAsync, GrabModeAsync,
		None, cursor[CurMove], CurrentTime) != GrabSuccess)
		return;
	do {
		XMaskEvent(dpy, MOUSEMASK|ExposureMask|SubstructureRedirectMask, &ev);
		switch (ev.type) {
		case ConfigureRequest:
		case Expose:
		case MapRequest:
			handler[ev.type](&ev);
			break;
		case MotionNotify:
			x = ev.xmotion.x;
			y = ev.xmotion.y;
			after = False;
			for(d = nexttiled(m->clients); d; d = nexttiled(d->next)){
				if(d == c)
					after = True;
				else if(INRECT(x, y, d->x, d->y, d->w+2*borderpx, d->h+2*borderpx)){
					detach(c);
					after ? insertafter(c, d) : insertbefore(c,d);
					arrange(c->mon);
					break;
				}
			}
		}
	} while(ev.type != ButtonRelease);
	XUngrabPointer(dpy, CurrentTime);
}
Пример #25
0
void xf_create_window(xfInfo* xfi)
{
	XEvent xevent;
	char* title;
	char* hostname;
	int width, height;

	width = xfi->width;
	height = xfi->height;

	xfi->attribs.background_pixel = BlackPixelOfScreen(xfi->screen);
	xfi->attribs.border_pixel = WhitePixelOfScreen(xfi->screen);
	xfi->attribs.backing_store = xfi->primary ? NotUseful : Always;
	xfi->attribs.override_redirect = xfi->fullscreen;
	xfi->attribs.colormap = xfi->colormap;

	if (xfi->remote_app != True)
	{
		if (xfi->fullscreen)
		{
			width = xfi->fullscreen ? WidthOfScreen(xfi->screen) : xfi->width;
			height = xfi->fullscreen ? HeightOfScreen(xfi->screen) : xfi->height;
		}

		hostname = xfi->instance->settings->hostname;
		title = xmalloc(sizeof("FreeRDP: ") + strlen(hostname));
		sprintf(title, "FreeRDP: %s", hostname);

		xfi->window = xf_CreateDesktopWindow(xfi, title, width, height, xfi->decorations);
		xfree(title);

		if (xfi->fullscreen)
			xf_SetWindowFullscreen(xfi, xfi->window, xfi->fullscreen);

		/* wait for VisibilityNotify */
		do
		{
			XMaskEvent(xfi->display, VisibilityChangeMask, &xevent);
		}
		while (xevent.type != VisibilityNotify);

		xfi->unobscured = (xevent.xvisibility.state == VisibilityUnobscured);

		XSetWMProtocols(xfi->display, xfi->window->handle, &(xfi->WM_DELETE_WINDOW), 1);
		xfi->drawable = xfi->window->handle;
	}
	else
	{
		xfi->drawable = DefaultRootWindow(xfi->display);
	}
}
Пример #26
0
char xhextrisButtonPress(XButtonEvent *ev){
    int w = ev->x;
    XEvent xe;

    while (1) {
        w=xhextrisSetspeed(w);
        XMaskEvent(dpy, ButtonPressMask|ButtonReleaseMask|ButtonMotionMask,&xe);
        if (xe.type == MotionNotify){
            w= xe.xmotion.x;
        }else if (xe.type == ButtonRelease) break;
    }
    button_speed=w+(CURSOR_H>>1);
    return 0;
}
Пример #27
0
int
send_command (unsigned char interactive, unsigned char *cmd, int screen_num)
{
  Window w, root;
  int done = 0;
  struct sbuf *s;

  s = sbuf_new(0);
  sbuf_printf(s, "%c%s", interactive, cmd);


  /* If the user specified a specific screen, then send the event to
     that screen. */
  if (screen_num >= 0)
    root = RootWindow (dpy, screen_num);
  else
    root = DefaultRootWindow (dpy);

  w = XCreateSimpleWindow (dpy, root, 0, 0, 1, 1, 0, 0, 0);

  /* Select first to avoid race condition */
  XSelectInput (dpy, w, PropertyChangeMask);

  XChangeProperty (dpy, w, rp_command, XA_STRING,
                   8, PropModeReplace, sbuf_get(s), strlen ((char *)cmd) + 2);

  XChangeProperty (dpy, root,
                   rp_command_request, XA_WINDOW,
                   8, PropModeAppend, (unsigned char *)&w, sizeof (Window));

  sbuf_free (s);

  while (!done)
    {
      XEvent ev;

      XMaskEvent (dpy, PropertyChangeMask, &ev);
      if (ev.xproperty.atom == rp_command_result
          && ev.xproperty.state == PropertyNewValue)
        {
          receive_command_result(ev.xproperty.window);
          done = 1;
        }
    }

  XDestroyWindow (dpy, w);

  return 1;
}
Пример #28
0
bool i_drag(arg_t a) {
	int dx = 0, dy = 0, i, ox, oy, x, y;
	unsigned int ui;
	bool dragging = true, next = false;
	XEvent e;
	Window w;

	if (mode != MODE_IMAGE)
		return false;
	if (!XQueryPointer(win.env.dpy, win.xwin, &w, &w, &i, &i, &ox, &oy, &ui))
		return false;
	
	win_set_cursor(&win, CURSOR_HAND);

	while (dragging) {
		if (!next)
			XMaskEvent(win.env.dpy,
			           ButtonPressMask | ButtonReleaseMask | PointerMotionMask, &e);
		switch (e.type) {
			case ButtonPress:
			case ButtonRelease:
				dragging = false;
				break;
			case MotionNotify:
				x = e.xmotion.x;
				y = e.xmotion.y;
				if (x >= 0 && x <= win.w && y >= 0 && y <= win.h) {
					dx += x - ox;
					dy += y - oy;
				}
				ox = x;
				oy = y;
				break;
		}
		if (dragging)
			next = XCheckIfEvent(win.env.dpy, &e, is_motionnotify, None);
		if ((!dragging || !next) && (dx != 0 || dy != 0)) {
			if (img_move(&img, dx, dy))
				img_render(&img);
			dx = dy = 0;
		}
	}
	
	win_set_cursor(&win, CURSOR_ARROW);
	set_timeout(reset_cursor, TO_CURSOR_HIDE, true);
	reset_timeout(redraw);

	return false;
}
Пример #29
0
int
read_key (KeySym *keysym, unsigned int *modifiers, char *keysym_name, int len)
{
  XEvent ev;
  int nbytes;

  /* Read a key from the keyboard. */
  do
    {
      XMaskEvent (dpy, KeyPressMask|KeyRelease, &ev);
      *modifiers = ev.xkey.state;
      nbytes = cook_keycode (&ev.xkey, keysym, modifiers, keysym_name, len, 0);
    } while (IsModifierKey (*keysym) || ev.xkey.type == KeyRelease);

  return nbytes;
}
Пример #30
0
void sweep(Client *c) {
    XEvent ev;
    int old_cx = c->x;
    int old_cy = c->y;

    if (!grab_pointer(c->screen->root, MouseMask, resize_curs)) return;

    client_raise(c);
#ifdef INFOBANNER_MOVERESIZE
    create_info_window(c);
#endif
    XGrabServer(dpy);
    draw_outline(c);

    setmouse(c->window, c->width, c->height);
    for (;;) {
        XMaskEvent(dpy, MouseMask, &ev);
        switch (ev.type) {
        case MotionNotify:
            if (ev.xmotion.root != c->screen->root)
                break;
            draw_outline(c); /* clear */
            XUngrabServer(dpy);
            recalculate_sweep(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y, ev.xmotion.state & altmask);
#ifdef INFOBANNER_MOVERESIZE
            update_info_window(c);
#endif
            XSync(dpy, False);
            XGrabServer(dpy);
            draw_outline(c);
            break;
        case ButtonRelease:
            draw_outline(c); /* clear */
            XUngrabServer(dpy);
#ifdef INFOBANNER_MOVERESIZE
            remove_info_window();
#endif
            XUngrabPointer(dpy, CurrentTime);
            moveresize(c);
            /* In case maximise state has changed: */
            ewmh_set_net_wm_state(c);
            return;
        default:
            break;
        }
    }
}