示例#1
0
static void WINDOWTRACKERSPU_APIENTRY
windowtrackerspuGetChromiumParametervCR(GLenum target, GLuint index,
																				GLenum type, GLsizei count,
																				GLvoid *values)
{
	switch (target) {
	case GL_WINDOW_SIZE_CR:
		{
			GLint x, y, *size = (GLint *) values;
			if (!getWindowGeometry(&x, &y, size+0, size+1))
				size[0] = size[1] = -1;
		}
		break;
	case GL_WINDOW_POSITION_CR:
		/* return window position, as a screen coordinate */
		{
			GLint w, h, *pos = (GLint *) values;
			if (!getWindowGeometry(pos+0, pos+1, &w, &h))
				pos[0] = pos[1] = -1;
			/*crDebug("%s returning pos %d %d", __FUNCTION__, pos[0], pos[1]);*/
		}
		break;
	default:
		/* pass-through */
		windowtracker_spu.child.GetChromiumParametervCR(target, index, type,
																										count, values);
	}
}
示例#2
0
/**
 *
 * @param argc
 * @param argv
 * @return
 */
int
main(int argc, char *argv[]) {
    // result
    int ret = -1;

    // supress invalid option -- 'xyz' output
    int opterr = 0;

    Rect rect;
    rect.x = -1;
    rect.y = -1;
    rect.w = -1;
    rect.h = -1;

    // parse options
    int c = getopt(argc, argv, "dwm");
    switch (c) {
        case 'd': //
        case 'w': //
        case 'm': // desktop
        {
            // common stuff >>
            // get display + root window
            Display *disp = XOpenDisplay(NULL);
            if (disp != NULL) {
                Window root = XDefaultRootWindow(disp);
                switch (c) {
                    case 'd': // desktop
                        ret = getWindowGeometry(disp, &root, &rect);
                        break;
                    case 'w': // window
                        ret = selectWindow(disp, &root, &rect);
                        break;
                    case 'm': // mouse
                        ret = selectArea(disp, &root, &rect);
                        break;
                }

                // common stuff >>
                // close display
                XCloseDisplay(disp);
                // common stuff <<
            }
        }
            break;
    }

    if(rect.w % 2 != 0)
        rect.w++;
    if(rect.h % 2 != 0)
        rect.h++;
    //
    printf("%d %d %d %d %d\n", ret, rect.w, rect.h, rect.x, rect.y);
    return ret;
}
示例#3
0
文件: mouse.cpp 项目: naelstrof/slop
Window slop::Mouse::findWindow( Window foo ) {
    glm::vec2 pos = getMousePos();
    Window root, parent;
    Window* children;
    unsigned int nchildren;
    Window selectedWindow;
    XQueryTree( x11->display, foo, &root, &parent, &children, &nchildren );
    if ( !children || nchildren <= 0 ) {
        return foo;
    }
    // The children are ordered, so we traverse backwards.
    for( int i=nchildren-1;i>=0;i-- ) {
        if ( children[i] == ignoreWindow ) {
            continue;
        }
        // We need to make sure the window is mapped.
        XWindowAttributes attr;         
        XGetWindowAttributes( x11->display, children[i], &attr );
        if ( attr.map_state != IsViewable ) {
            continue;
        }
        // We need to make sure we can get pixel data from it as well
        if ( attr.c_class == InputOnly ) {
          continue;
        }

        glm::vec4 rect = getWindowGeometry(children[i], false);
        float a = pos.x - rect.x;
        float b = pos.y - rect.y;
        if ( a <= rect.z && a >= 0 ) {
            if ( b <= rect.w && b >= 0 ) {
                selectedWindow = children[i];
                switch( nodecorations ) {
                    case 0:
                        XFree(children);
                        return selectedWindow;
                    case 1:
                        XFree(children);
                        //return findWindow( selectedWindow );
                        XQueryTree( x11->display, selectedWindow, &root, &parent, &children, &nchildren );
                        if ( !children || nchildren <= 0 ) {
                            return selectedWindow;
                        }
                        return children[nchildren-1];
                    case 2:
                        return findWindow( selectedWindow );
                }
            }
        }
    }
    return foo;
}
示例#4
0
/**
 *
 * @param disp
 * @param root
 * @param rect
 * @return
 */
int
selectWindow(
        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);

    if ((XGrabPointer
                 (disp, *root, False,
                  ButtonPressMask, GrabModeAsync,
                  GrabModeAsync, *root, cursor, CurrentTime) != GrabSuccess)) {
        printf("couldn't grab pointer:\n");
        return -1;
    }

    while (1) {
        while (XPending(disp)) {
            XNextEvent(disp, &ev);
            switch (ev.type) {
                case ButtonPress:
                    return getWindowGeometry(disp, &ev.xbutton.subwindow, rect);
                default:
                    break;
            }
        }
    }
}