⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win.cpp

📁 一个3D桌面的实现源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
        int rc2 = XGrabPointer(display, win, True, ButtonPressMask | ButtonMotionMask | PointerMotionMask,                               GrabModeAsync, GrabModeAsync, win, empty_cursor, CurrentTime);        msgout(DEBUG, "xgrabkeyboard rc = %d\n", rc1);        msgout(DEBUG, "xgrabpointer rc = %d\n", rc2);        XSync(display, 0);    }    else    {        /* create a window in window mode*/        attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask |            StructureNotifyMask;        win = XCreateWindow(display, RootWindow(display, vi->screen),                                   0, 0, width, height, 0, vi->depth, InputOutput, vi->visual,                                   CWBorderPixel | CWColormap | CWEventMask, &attr);        /* only set window title and handle wm_delete_events if in windowed mode */        wmDelete = XInternAtom(display, "WM_DELETE_WINDOW", True);        XSetWMProtocols(display, win, &wmDelete, 1);        XSetStandardProperties(display, win, title,                               title, None, NULL, 0, NULL);        XMapRaised(display, win);    }           Atom kwm_atom = 0;    long int data=1;    kwm_atom = XInternAtom(display, "KWM_MODULE", False);        XChangeProperty(display, win, kwm_atom, kwm_atom, 32,                    PropModeReplace, (unsigned char *)&data, 1);        sendClientMessage(display, screen, win, kwm_atom, (long) win);    /* connect the glx-context to the window */    glXMakeCurrent(display, win, ctx);    XGetGeometry(display, win, &winDummy, &x, &y,                 (unsigned int *)&width, (unsigned int *)&height,                  &borderDummy, &depth);    msgout(DEBUG, "Depth %d\n", depth);    if (glXIsDirect(display, ctx))         msgout(DEBUG, "Congrats, you have Direct Rendering!\n");    else {        msgout (ERROR,                 "glXIsDirect failed, no Direct Rendering possible!\n"                "Please configure hardware acceleration.  Exiting.\n");        fprintf (stderr,                  "3ddeskd: glXIsDirect failed, no Direct Rendering possible!\n"                 "3ddeskd: Please configure hardware acceleration.  Exiting.\n");        end_program(-1);    }        return 1;}int GLWindow::get_best_texture_size (int s){    int width;    for ( ; s >= 64; s >>= 1) {        glTexImage2D(GL_PROXY_TEXTURE_2D, 0, GL_RGB,                     s, s, 0, GL_RGBA,                     GL_UNSIGNED_BYTE, NULL);        glGetTexLevelParameteriv(GL_PROXY_TEXTURE_2D, 0, GL_TEXTURE_WIDTH, &width);        if (s == width) {            msgout (DEBUG, "Found best texture size as %d\n", s);            return s;        }    }    return 64; // all cards should support 64}int GLWindow::kill_GL_window (){    msgout (DEBUG, "kill window\n");    XDestroyWindow(display, win);    XSync(display, 0);    /* switch back to original desktop resolution if we were in fs */    if (fullscreen)    {        XF86VidModeSwitchToMode(display, screen, &deskMode);        XF86VidModeSetViewPort(display, screen, 0, 0);    }    return 0;}int GLWindow::unhide_GL_window(){    if (fullscreen) {        XF86VidModeSwitchToMode(display, screen, &fullscreenMode);        XF86VidModeSetViewPort(display, screen, 0, 0);    }    XMapRaised (display, win);        if (fullscreen) {        int rc1, rc2, retries = 0;        // it seems this call can fail with return code 1        // (AlreadyGrabbed) so we add a retry loop here.         rc1 = XGrabKeyboard(display, win, True, GrabModeSync,                            GrabModeAsync, CurrentTime);        while (rc1 != 0 &&                retries++ != 5000)  // no infinite loops!        {            //msgout (DEBUG, "xgrabkeyboard failed (%d)\n", rc1);            rc1 = XGrabKeyboard(display, win, True, GrabModeSync,                                GrabModeAsync, CurrentTime);        }        if (rc1 != 0)            msgout(WARN, "xgrabkeyboard rc = %d\n", rc1);        rc2 = XGrabPointer(display, win, True, ButtonPressMask | ButtonMotionMask | PointerMotionMask,                           GrabModeAsync, GrabModeAsync, win, empty_cursor, CurrentTime);        if (rc1 != 0 || rc2 != 0)            msgout(WARN, "xgrabpointer rc = %d\n", rc2);    }    XSync(display, 0);    return 0;}int GLWindow::hide_GL_window(){    XUnmapWindow (display, win);        XSync(display, 0);    if (fullscreen)    {        XF86VidModeSwitchToMode(display, screen, &deskMode);        XF86VidModeSetViewPort(display, screen, 0, 0);    }    return 0;}voidGLWindow::resize_scene(){    resize_scene(width, height);}voidGLWindow::resize_scene(int w, int h){    // Let's not core dump, no matter what.    if (h == 0)        h = 1;    width = w;    height = h;    glViewport(0, 0, width, height);    glMatrixMode(GL_PROJECTION);    glLoadIdentity();    gluPerspective(FOV, (GLfloat)width/(GLfloat)height,0.1f,100.0f);    glMatrixMode(GL_MODELVIEW);} // END resize_sceneint GLWindow::grab_screenshot_data_portion(int x1, int y1, int x2, int y2){    int texture_x1 = (int)ceil((cfg->texture_size * x1) / (float)screen_width);     int texture_x2 = (int)ceil((cfg->texture_size * x2) / (float)screen_width);     int texture_y1 = (int)ceil((cfg->texture_size * y1) / (float)screen_height);     int texture_y2 = (int)ceil((cfg->texture_size * y2) / (float)screen_height);     // deleted in destructor (life of object)    if (!screenshot_data) {        screenshot_data = new unsigned char [cfg->texture_size * cfg->texture_size * 4];        if (screenshot_data == NULL) {            msgout (ERROR, "out of memory\n");            end_program(-1);        }        imgfinal = imlib_create_image(cfg->texture_size, cfg->texture_size);    }    /* set the display , visual, colormap and drawable we are using */    imlib_context_set_image(img);    imlib_copy_drawable_to_image((Pixmap)0, //Pixmap mask,                                  x1, y1,                                 x2 - x1, y2 - y1,                                 0, 0, //int destination_x, int destination_y,                                 1 ); //char need_to_grab_x);    imlib_context_set_image(imgfinal);    //imlib_image_clear();    //msgout (DEBUG, "---portion of textures is %dx%d to %dx%d\n",    //        texture_x1, texture_y1, texture_x2, texture_y2);    //msgout (DEBUG, "===real portion is %dx%d to %dx%d\n",    //        x1, y1, x2, y2);    imlib_blend_image_onto_image(img, 0,                                  0, 0, x2 - x1, y2 - y1,                                  texture_x1, texture_y1,                                  texture_x2 - texture_x1, texture_y2 - texture_y1);    unsigned int *tmp = imlib_image_get_data();    int w = imlib_image_get_width();    int h = imlib_image_get_height();    int x, y;    int offset;    int img_offset;    w = h = cfg->texture_size;        for (y = 0; y < h; y++) {        for (x = 0; x < w; x++) {            offset = (y * w + x) * 4;            img_offset = (y * w + x);            screenshot_data[offset]     = (tmp[img_offset] >> 16) & 0xff;            screenshot_data[offset + 1] = (tmp[img_offset] >> 8) & 0xff;            screenshot_data[offset + 2] =  tmp[img_offset] & 0xff;            screenshot_data[offset + 3] = (tmp[img_offset] >> 24) & 0xff;        }    }    return 0;}int GLWindow::grab_screenshot_data(){    // deleted in destructor (life of object)    if (!screenshot_data) {        screenshot_data = new unsigned char [cfg->texture_size * cfg->texture_size * 4];        if (screenshot_data == NULL) {            msgout (ERROR, "out of memory\n");            end_program(-1);        }        imgfinal = imlib_create_image(cfg->texture_size, cfg->texture_size);    }    /* set the display , visual, colormap and drawable we are using */    imlib_context_set_image(img);    imlib_copy_drawable_to_image((Pixmap)0, //Pixmap mask,                                  0, 0, //int x, int y,                                  screen_width, //int width, int height,                                 screen_height,                                 0, 0, //int destination_x, int destination_y,                                 1 ); //char need_to_grab_x);    imlib_context_set_image(imgfinal);    imlib_image_clear();    imlib_blend_image_onto_image(img, 0,                                  0, 0, screen_width, screen_height,                                  0, 0, cfg->texture_size, cfg->texture_size);    unsigned int *tmp = imlib_image_get_data();    int w = imlib_image_get_width();    int h = imlib_image_get_height();    int x, y;    int offset;    int img_offset;    w = h = cfg->texture_size;        for (y = 0; y < h; y++) {        for (x = 0; x < w; x++) {            offset = (y * w + x) * 4;            img_offset = (y * w + x);            screenshot_data[offset]     = (tmp[img_offset] >> 16) & 0xff;            screenshot_data[offset + 1] = (tmp[img_offset] >> 8) & 0xff;            screenshot_data[offset + 2] =  tmp[img_offset] & 0xff;            screenshot_data[offset + 3] = (tmp[img_offset] >> 24) & 0xff;        }    }    return 0;}unsigned char *GLWindow::get_screenshot_data_ptr(void){    return screenshot_data;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -