Example #1
0
void
mousefunc_client_resize(void *ctx, union arg *arg, enum xev xev)
{
	struct client_ctx	*cc = ctx;
	XEvent			 ev;
	Time			 ltime = 0;
	struct screen_ctx	*sc = cc->sc;

	if (cc->flags & CLIENT_FREEZE)
		return;

	client_raise(cc);
	client_ptrsave(cc);

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

	if (XGrabPointer(X_Dpy, cc->win, False, MOUSEMASK,
	    GrabModeAsync, GrabModeAsync, None, Conf.cursor[CF_RESIZE],
	    CurrentTime) != GrabSuccess)
		return;

	menu_windraw(sc, cc->win, "%4d x %-4d", cc->dim.w, cc->dim.h);

	for (;;) {
		XWindowEvent(X_Dpy, cc->win, MOUSEMASK, &ev);

		switch (ev.type) {
		case MotionNotify:
			/* not more than 60 times / second */
			if ((ev.xmotion.time - ltime) <= (1000 / 60))
				continue;
			ltime = ev.xmotion.time;

			cc->geom.w = ev.xmotion.x;
			cc->geom.h = ev.xmotion.y;
			client_applysizehints(cc);
			client_resize(cc, 1);
			menu_windraw(sc, cc->win,
			    "%4d x %-4d", cc->dim.w, cc->dim.h);
			break;
		case ButtonRelease:
			client_resize(cc, 1);
			XUnmapWindow(X_Dpy, sc->menu.win);
			XReparentWindow(X_Dpy, sc->menu.win, sc->rootwin, 0, 0);
			XUngrabPointer(X_Dpy, CurrentTime);

			/* 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 */
}
Example #2
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 */
}
Example #3
0
void
mousefunc_menu_unhide(struct client_ctx *cc, union arg *arg)
{
    struct screen_ctx	*sc = cc->sc;
    struct client_ctx	*old_cc;
    struct menu		*mi;
    struct menu_q		 menuq;
    char			*wname;

    old_cc = client_current();

    TAILQ_INIT(&menuq);
    TAILQ_FOREACH(cc, &Clientq, entry)
    if (cc->flags & CLIENT_HIDDEN) {
        wname = (cc->label) ? cc->label : cc->name;
        if (wname == NULL)
            continue;

        menuq_add(&menuq, cc, "(%d) %s",
                  cc->group->shortcut, wname);
    }

    if (TAILQ_EMPTY(&menuq))
        return;

    if ((mi = menu_filter(sc, &menuq, NULL, NULL, 0,
                          NULL, NULL)) != NULL) {
        cc = (struct client_ctx *)mi->ctx;
        client_unhide(cc);

        if (old_cc != NULL)
            client_ptrsave(old_cc);
        client_ptrwarp(cc);
    }

    menuq_clear(&menuq);
}