コード例 #1
0
ファイル: opensnap.c プロジェクト: babymastodon/opensnap
int main(int argc, char **argv)
{
    gtk_init(&argc, &argv);                     
    Display *dsp = XOpenDisplay( NULL );
    if( !dsp ){ return 1; }


    screens scrinfo;
    getScreens(&scrinfo);

    Window parentWin;

    int action=0;
    int verbose=0;
    int isdrag=0;
    int isinitialclick=1;
    int offset=10;
    mousestate mousepos;
    mousestate relativeMousepos;
    XEvent event;
    Window activeWindow;
    char launch[MY_MAXPATH];
    char configbase[MY_MAXPATH];
    strcpy(configbase,"~/.config/opensnap/");

    struct option longopts[] = {
        {"config",  1, NULL, 'c'},
        {"offset",  1, NULL, 'o'},
        {"daemon",  0, NULL, 'd'},
        {"info",    0, NULL, 'i'},
        {"verbose", 0, NULL, 'v'},
        {"help",    0, NULL, 'h'},
        {"version", 0, NULL, 'V'},
        {0, 0, 0, 0}};

    int opt=0;
    while((opt = getopt_long(argc,argv,"c:o:divVh",longopts,NULL)) != -1){
        switch(opt){
            case 'c':
                strncpy(configbase,optarg,MY_MAXPATH);
                configbase[MY_MAXPATH-1]='\0';
                break;
            case 'd':
                if(daemon(0,0) == -1){
                    perror("daemon");
                    exit(EXIT_FAILURE);
                }
                break;
            case 'i':
                dumpInfo(&scrinfo);
                exit(EXIT_SUCCESS);
                break;
            case 'v':
                verbose=1;
                break;
            case 'V':
                printf("opensnap version %s\n", versionstring);
                exit(EXIT_SUCCESS);
            case 'o':
                offset=atoi(optarg);
                break;
            case 'h':
            case '?':
                printHelp();
                exit(EXIT_FAILURE);
                break;
        }
    }

    while(1){
        getMousePosition(dsp, &event, &mousepos);
        int scrnn;
        scrnn = gdk_screen_get_monitor_at_point(gdk_screen_get_default(), mousepos.x, mousepos.y);
        //make mouse coordinates relative to screen
        relativeMousepos.x=mousepos.x-scrinfo.screens[scrnn].x;
        relativeMousepos.y=mousepos.y-scrinfo.screens[scrnn].y;
        if(verbose)
            printf("Mouse Coordinates: %d %d %d\n", mousepos.x, mousepos.y, mousepos.state );
        if((LEFTCLICK & mousepos.state)==LEFTCLICK){
            if(!isdrag && isinitialclick) {
                if(isTitlebarHit(dsp, &mousepos)){
                    isdrag=1;
                }
            }
            if(relativeMousepos.y<=offset)
                action=HIT_TOP;
            else if(relativeMousepos.x<=offset)
                action=HIT_LEFT;
            else if(relativeMousepos.x>=scrinfo.screens[scrnn].width-offset-1)
                action=HIT_RIGHT;
            else if(relativeMousepos.y>=scrinfo.screens[scrnn].height-offset-1)
                action=HIT_BOTTOM;
            else
                action=0;
            isinitialclick=false;
        }
        if(verbose)printf("action is: %d, isdrag is: %d\n",action,isdrag);
        if((16 & mousepos.state) == mousepos.state && isdrag){
            if(action){
                getFocusedWindow(dsp,&activeWindow);
                findParentWindow(dsp,&activeWindow,&parentWin);
                if(verbose)printf("Running script: %s",SCRIPT_NAMES[action]);
                sprintf(launch,"/bin/sh %s/%s %lu %i %i %i %i",configbase,SCRIPT_NAMES[action],parentWin,
                        scrinfo.screens[scrnn].width,scrinfo.screens[scrnn].height,scrinfo.screens[scrnn].x, scrinfo.screens[scrnn].y);
                system(launch);
            }
            action=0;
        }
        if((LEFTCLICK & mousepos.state) != LEFTCLICK){
            isdrag=0;
            isinitialclick=1;
        }
        usleep(10000);
    }
    XCloseDisplay(dsp);
    free(scrinfo.screens);
    return 0;
}
コード例 #2
0
void SDReflectionMapping::update(){

    //TODO support for multi screen

    SDScreens * screens = (SDScreens*)getScreens();
    osg::Camera * viewCam = screens->getActiveView()->getOsgCam();

    tCarElt * car = this->car->getCar();

    pre_cam->setCar(car);
    post_cam->setCar(car);

    sgVec3 p;
    osg::Vec3 eye,center,up;

    p[0] = car->_drvPos_x;
    p[1] = car->_bonnetPos_y;
    p[2] = car->_drvPos_z;
    sgXformPnt3(p, car->_posMat);

    eye[0] = p[0];
    eye[1] = p[1];
    eye[2] = p[2];


  /*  P[0] = car->_drvPos_x + 30.0 * cos(2*PI/3 * car->_glance + offset);
    P[1] = car->_bonnetPos_y - 30.0 * sin(2*PI/3 * car->_glance + offset);
    P[2] = car->_drvPos_z;
    sgXformPnt3(P, car->_posMat);

    center[0] =  P[0];
    center[1] = P[1];
    center[2] = P[2];

    up[0] = car->_posMat[2][0];
    up[1] = car->_posMat[2][1];
    up[2] = car->_posMat[2][2];*/


    osg::Matrix n = osg::Matrix(-1.0,0.0,0.0,0.0,
                               0.0,1.0,0.0,0.0,
                               0.0,0.0,1.0,0.0,
                               0.0,0.0,0.0,1.0);

    cameras[osg::TextureCubeMap::POSITIVE_Z]->setViewMatrix(osg::Matrix::translate(-eye)*osg::Matrix::rotate(viewCam->getViewMatrix().getRotate())*n);
    osg::Matrix mat = cameras[osg::TextureCubeMap::POSITIVE_Z]->getViewMatrix();

    osg::Matrix negX = osg::Matrix::rotate(osg::inDegrees(-90.0),osg::Y_AXIS);
    osg::Matrix negZ = osg::Matrix::rotate(osg::inDegrees(-180.0),osg::Y_AXIS);
    osg::Matrix posX = osg::Matrix::rotate(osg::inDegrees(90.0),osg::Y_AXIS);

    osg::Matrix negY= osg::Matrix::rotate(osg::inDegrees(-90.0),osg::X_AXIS);
    osg::Matrix posY= osg::Matrix::rotate(osg::inDegrees(90.0),osg::X_AXIS);

    cameras[osg::TextureCubeMap::NEGATIVE_X]->setViewMatrix(mat*negX);
    cameras[osg::TextureCubeMap::NEGATIVE_Z]->setViewMatrix(mat*negZ);
    cameras[osg::TextureCubeMap::POSITIVE_X]->setViewMatrix(mat*posX);

    cameras[osg::TextureCubeMap::NEGATIVE_Y]->setViewMatrix(mat*negY);
    cameras[osg::TextureCubeMap::POSITIVE_Y]->setViewMatrix(mat*posY);

    /*for(unsigned int i=0;i<cameras.size();i++){
        cameras[i]->setViewMatrixAsLookAt(eye,center,up);
    }*/
}
コード例 #3
0
int main(int argc, char **argv)
{
	gtk_init(&argc, &argv);
	Display *dsp = XOpenDisplay( NULL );
	if( !dsp ) { return 1; }

	screens scrinfo;
	getScreens(&scrinfo);
	int isdrag=0;
	int isinitialclick=1;
	int offset=10;
	mousestate mousepos;
	mousestate relativeMousepos;
	XEvent event;
	int mode = 0;
	int Continue = 0;

	struct option longopts[] = {
		{"offset",    1, NULL, 'o'},
		{"daemon",    0, NULL, 'd'},
		{"help",      0, NULL, 'h'},
		{"version",   0, NULL, 'V'},
		{"titledrag", 0, NULL, 't'},
		{"altdrag",   0, NULL, 'a'},
		{0, 0, 0, 0}};

	int opt=0;

	// Handle command line options
	while((opt = getopt_long(argc,argv,"o:dvhta",longopts,NULL)) != -1)
	{
		switch(opt)
		{
		case 'd':
			if(daemon(0,0) == -1)
			{
				perror("daemon");
				exit(EXIT_FAILURE);
			}
			break;

		case 'v':
			printf("opensnap-quicktile " VERSION);
			exit(EXIT_SUCCESS);
			break;

		case 'o':
			offset=atoi(optarg);
			break;

		case 't':
			mode = 1;
			break;

		case 'a':
			mode = 2;
			break;

		case 'h':
		case '?':
			printf("Usage: opensnap-quicktile <OPTION>\n\n");
			printf("Options:\n");
			printf("  -d, --daemon            Run opensnap-quicktile as daemon.\n");
			printf("  -o, --offset <PIXEL>    Offset in pixel.\n");
			printf("  -v, --version           Print opensnap-quicktile version number.\n");
			printf("  -h, --help              Print this help.\n");
			printf("  -t, --titledrag         Only drags by titlebar.\n");
			printf("  -a, --altdrag           Only drags by Alt+Dragging.\n\n");

			exit(EXIT_FAILURE);
			break;
		}
	}

	// Main loop
	while(1)
	{
		getMousePosition(dsp, &event, &mousepos);

		int scrnn;
		scrnn = gdk_screen_get_monitor_at_point(gdk_screen_get_default(), mousepos.x, mousepos.y);

		relativeMousepos.x=mousepos.x-scrinfo.screens[scrnn].x;
		relativeMousepos.y=mousepos.y-scrinfo.screens[scrnn].y;

		/* Check if the window has been dragged to a screen edge. */
		if((LEFTCLICK & mousepos.state)==LEFTCLICK)
		{
			if(relativeMousepos.x<=offset || relativeMousepos.x>=scrinfo.screens[scrnn].width-offset-1 || relativeMousepos.y>=scrinfo.screens[scrnn].height-offset-1 || relativeMousepos.y<=offset) { Continue = 1; }

			else
			{
				if(!isdrag && isinitialclick)
				{
					if(mode == 0 || mode == 2)
					{
						if(mousepos.state & 8)
						{
							isdrag=1;
						}
					}

					if(mode == 0 || mode == 1)
					{
						if(isTitlebarHit(dsp, &mousepos))
						{

							isdrag=1;
						}
					}
				}
				Continue = 0;
			}
			isinitialclick=false;
		}

		if(Continue == 1)
		{
			if(((16 & mousepos.state) == mousepos.state || (24 & mousepos.state) == mousepos.state) && isdrag)
			{
				/* Check to see if window is still over there. This is to prevent the window from snapping after the mouse has been moved away. */
				if(relativeMousepos.x<=offset)
				{
					if(relativeMousepos.y<=offset) { string2exec("top-left"); }

					else if(relativeMousepos.y>=scrinfo.screens[scrnn].height-offset-1) { string2exec("bottom-left"); }

					else { string2exec("left"); }
				}

				else if(relativeMousepos.x>=scrinfo.screens[scrnn].width-offset-1)
				{
					if(relativeMousepos.y<=offset) { string2exec("top-right"); }

					else if(relativeMousepos.y>=scrinfo.screens[scrnn].height-offset-1) { string2exec("bottom-right"); }

					else { string2exec("right"); }
				}

				else if(relativeMousepos.y>=scrinfo.screens[scrnn].height-offset-1) { string2exec("bottom"); }

				else if(relativeMousepos.y<=offset) { string2exec("maximize"); }

				Continue = 0;
			}
		}

		if((LEFTCLICK & mousepos.state) != LEFTCLICK)
		{
			isdrag=0;
			isinitialclick=1;
		}
		usleep(10000);
	}

	XCloseDisplay(dsp);
	free(scrinfo.screens);
	return 0;
}