?? win.cpp
字號:
//// Copyright (C) 2002 Brad Wasson <bard@systemtoolbox.com>//// This file is part of 3ddesktop.//// 3ddesktop is free software; you can redistribute it and/or modify it// under the terms of the GNU General Public License as published by// the Free Software Foundation; either version 2, or (at your option)// any later version.//// 3ddesktop is distributed in the hope that it will be useful, but// WITHOUT ANY WARRANTY; without even the implied warranty of// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the// GNU General Public License for more details.//// You should have received a copy of the GNU General Public License// along with 3ddesktop; see the file COPYING. If not, write to// the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.//#include <stdio.h>#include <stdlib.h>#include <string.h>#include <math.h>#include <GL/gl.h> // OpenGL itself.#include <GL/glu.h> // GLU support library.#include <GL/glx.h>#include <X11/extensions/xf86vmode.h>#include <Imlib2.h>#include "win.hpp"#include "3ddesk.h" // for FOV#include "config.hpp"/* attributes for a single buffered visual in RGBA format with at least * 4 bits per color and a 16 bit depth buffer */static int attrListSgl[] = {GLX_RGBA, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None};/* attributes for a double buffered visual in RGBA format with at least * 4 bits per color and a 16 bit depth buffer */static int attrListDbl[] = { GLX_RGBA, GLX_DOUBLEBUFFER, GLX_RED_SIZE, 4, GLX_GREEN_SIZE, 4, GLX_BLUE_SIZE, 4, GLX_DEPTH_SIZE, 16, None };unsigned int GLWindow::get_width(){ return width; }unsigned int GLWindow::get_height(){ return height; }unsigned int GLWindow::get_screen_width(){ return screen_width; }unsigned int GLWindow::get_screen_height(){ return screen_height; }Display *GLWindow::get_display(){ return display; }Window GLWindow::get_window(){ return win; }static intX_errors_handler (Display *display, XErrorEvent *error){ msgout (ERROR, "-------- X error\n"); return 0;}extern Config *cfg; // FIXME!GLWindow::GLWindow() { screenshot_data = NULL;}GLWindow::~GLWindow() { if (screenshot_data) delete screenshot_data;}int GLWindow::open_display() { display = XOpenDisplay(0); if (display == NULL) { msgout (ERROR, "Can't open display\n"); return -1; } #if 0 // this must be done later after create_GL_window and after // get_best_texture_size when we know what texturesize we will be // using (also init imgfinal then) 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); }#endif screen = DefaultScreen(display); screen_width = DisplayWidth(display, screen); screen_height = DisplayHeight(display, screen); Visual *vis = DefaultVisual(display, screen); Colormap cm = DefaultColormap(display, screen); imlib_context = imlib_context_new(); imlib_context_set_display(display); imlib_context_set_visual(vis); imlib_context_set_colormap(cm); imlib_context_set_drawable(RootWindow(display, screen)); imlib_context_set_anti_alias(1); imlib_context_set_blend(0); img = imlib_create_image(screen_width, screen_height); XSetErrorHandler(X_errors_handler); return 0;}// ripped from bbws.cc -- redundant to VDesktops::send_client_message// but it was easier to just put another version herestatic void sendClientMessage(Display *display, int screen, int win, Atom atom, XID data){ XEvent e; unsigned long mask; e.xclient.type = ClientMessage; e.xclient.window = win; e.xclient.message_type = atom; e.xclient.format = 32; e.xclient.data.l[0] = (unsigned long) data; e.xclient.data.l[1] = CurrentTime; mask = SubstructureRedirectMask; XSendEvent(display, RootWindow(display,screen), False, mask, &e);}int GLWindow::create_GL_window(char *title, Bool fs){ Colormap cmap; int dpyWidth, dpyHeight; int i; int glxMajorVersion, glxMinorVersion; int vidModeMajorVersion, vidModeMinorVersion; XF86VidModeModeInfo **modes; int modeNum; int bestMode; Atom wmDelete; Window winDummy; unsigned int borderDummy; static int first_time = 1; /* set best mode to current */ bestMode = 0; fullscreen = fs; if (fullscreen) { width = screen_width; height = screen_height; msgout (DEBUG, "width %d x %d\n", width, height); } else { width = 600; height = 480; } XF86VidModeQueryVersion(display, &vidModeMajorVersion, &vidModeMinorVersion); msgout(DEBUG, "XF86VidModeExtension-Version %d.%d\n", vidModeMajorVersion, vidModeMinorVersion); XF86VidModeGetAllModeLines(display, screen, &modeNum, &modes); // first entry cooresponds to the current mode - we want to use // that so the mode switch happens seamlessly (no monitor reset) deskMode = *modes[0]; bestMode = 0; // verify the first mode is the current resolution if ((modes[0]->hdisplay != width) || (modes[0]->vdisplay != height)) { msgout (ERROR, "First mode in XF86VidMode list is not the same resolution as current desktop.\n" "This will not do. Exiting.\n"); fprintf (stderr, "3ddeskd: First mode in XF86VidMode list is not the same resolution as current desktop.\n" "3ddeskd: This will not do. Exiting.\n"); end_program(-1); } // print out all the resolutions we found for (i = 0; i < modeNum; i++) { msgout (DEBUG, "Found mode: %dx%d (%d) %d %d %d %d - %d %d %d\n", modes[i]->hdisplay, modes[i]->vdisplay, modes[i]->dotclock, modes[i]->hsyncstart, modes[i]->hsyncend, modes[i]->htotal, modes[i]->hskew, modes[i]->vsyncstart, modes[i]->vsyncend, modes[i]->vtotal); } /* get an appropriate visual */ vi = glXChooseVisual(display, screen, attrListDbl); if (vi == NULL) { vi = glXChooseVisual(display, screen, attrListSgl); msgout(DEBUG, "Only Singlebuffered Visual!\n"); } else { msgout(DEBUG, "Got Doublebuffered Visual!\n"); } glXQueryVersion(display, &glxMajorVersion, &glxMinorVersion); msgout(DEBUG, "glX-Version %d.%d\n", glxMajorVersion, glxMinorVersion); if (first_time) { /* create a GLX context */ msgout (DEBUG, "create context\n"); ctx = glXCreateContext(display, vi, 0, GL_TRUE); first_time = 0; } /* create a color map */ cmap = XCreateColormap(display, RootWindow(display, vi->screen), vi->visual, AllocNone); attr.colormap = cmap; attr.border_pixel = 0; if (fullscreen) { fullscreenMode = *modes[bestMode]; XF86VidModeSwitchToMode(display, screen, modes[bestMode]); XF86VidModeSetViewPort(display, screen, 0, 0); dpyWidth = modes[bestMode]->hdisplay; dpyHeight = modes[bestMode]->vdisplay; msgout(DEBUG, "Resolution %dx%d\n", dpyWidth, dpyHeight); XFree(modes); /* create a fullscreen window */ attr.override_redirect = True; attr.event_mask = ExposureMask | KeyPressMask | ButtonPressMask | StructureNotifyMask | SubstructureRedirectMask; win = XCreateWindow(display, RootWindow(display, vi->screen), 0, 0, dpyWidth, dpyHeight, 0, vi->depth, InputOutput, vi->visual, CWBorderPixel | CWColormap | CWEventMask | CWOverrideRedirect, &attr); Atom wmproto[2]; wmproto[0] = XInternAtom (display, "WM_DELETE_WINDOW", False); wmproto[1] = XInternAtom(display, "_BLACKBOX_STRUCTURE_MESSAGES", False); XSetWMProtocols(display, win, wmproto, 2); // this code fragment from xscreensaver - for making a blank mouse pointer XColor black; black.red = black.green = black.blue = 0; Pixmap bit; bit = XCreatePixmapFromBitmapData (display, win, "\000", 1, 1, 0, //BlackPixelOfScreen (screen), 0, //BlackPixelOfScreen (screen), 1); empty_cursor = XCreatePixmapCursor (display, bit, bit, &black, &black, 0, 0); XFreePixmap (display, bit); // ----- //XUndefineCursor (display, win); //XDefineCursor (display, win, empty_cursor); //XWarpPointer(display, None, win, 0, 0, 0, 0, 0, 0); XMapRaised(display, win); int rc1 = XGrabKeyboard(display, win, True, GrabModeSync, GrabModeAsync, CurrentTime);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -