?? skl_drv_x11.cpp
字號:
} XSetWindowColormap( Dsp, _Win, _XCMap ); XInstallColormap( Dsp, _XCMap ); } else { _XCMap = (Colormap)None; _Pixels=0; } return 1;}void SKL_X11_RAW_WIN::Store_CMap(){ if (!Has_CMap()) return; XColor XColors[ 256 ]; const SKL_COLOR *Cols = Get_CMap().Get_Colors(); int N = Get_CMap().Get_Nb_Colors(); for( int i=0; i<N; ++i ) { XColors[i].red = Cols[i].R() << 8; XColors[i].green = Cols[i].G() << 8; XColors[i].blue = Cols[i].B() << 8; XColors[i].pixel = _Pixels[ i ]; XColors[i].flags = DoRed | DoGreen | DoBlue; } Display *Dsp = Get_XDisplay(); XStoreColors( Dsp, _XCMap, XColors, N );}//////////////////////////////////////////////////////////void SKL_X11_RAW_WIN::Set_Position(int Xo, int Yo){ SKL_WINDOW::Set_Position(Xo,Yo); // updates _Xo and _Yo Display *Dsp = Get_XDisplay(); int Screen = Get_Screen(); XMoveWindow( Dsp, _Win, Xo, Yo ); XWarpPointer( Dsp, RootWindow( Dsp, Screen ), RootWindow( Dsp, Screen ), 0, 0, DisplayWidth( Dsp, Screen ), DisplayHeight( Dsp, Screen ), Xo, Yo );}void SKL_X11_RAW_WIN::Set_Resize_Mode(int Resize){ Display *Dsp = Get_XDisplay(); int Screen = Get_Screen(); XSizeHints Size_Hints; Size_Hints.width = Width(); Size_Hints.height = Height(); if (!Resize) { Size_Hints.min_width = Size_Hints.width; Size_Hints.max_width = Size_Hints.width; Size_Hints.min_height = Size_Hints.height; Size_Hints.max_height = Size_Hints.height; } else { Size_Hints.min_width = 16; Size_Hints.max_width = DisplayWidth( Dsp, Screen ); Size_Hints.min_height = 16; Size_Hints.max_height = DisplayHeight( Dsp, Screen ); } Size_Hints.flags = PSize | PMinSize | PMaxSize; XSetWMNormalHints( Dsp, _Win, &Size_Hints );}//////////////////////////////////////////////////////////int SKL_X11_RAW_WIN::Hide_Cursor(){ XColor Dummy; Dummy.flags = 0; Dummy.pixel = 0; Dummy.red = Dummy.green = Dummy.blue = 0; Display *Dsp = Get_XDisplay(); Pixmap Mouse_Void_Pixmap = XCreatePixmap( Dsp, _Win, 1, 1, 1 ); Pixmap Data = XCreateBitmapFromData( Dsp, Mouse_Void_Pixmap, (char *)"\1", 1, 1 ); if ( Data == None ) return 0; // X server could not even allocate a 1x1 Pixmap <gee> !! _Void_Cursor = XCreatePixmapCursor(Dsp, Mouse_Void_Pixmap, Mouse_Void_Pixmap, &Dummy, &Dummy, 0, 0 ); XDefineCursor( Dsp, _Win, _Void_Cursor ); XFreePixmap( Dsp, Mouse_Void_Pixmap ); return 1;}void SKL_X11_RAW_WIN::Hide() { Display *Dsp = Get_XDisplay(); if ( _Win!=0 ) XUnmapWindow(Dsp, _Win); SKL_WINDOW::Hide();}void SKL_X11_RAW_WIN::Show() { Display *Dsp = Get_XDisplay(); if ( _Win!=0 ) XMapWindow(Dsp, _Win); SKL_WINDOW::Show();}//////////////////////////////////////////////////////////int SKL_X11_RAW_WIN::Create_XWindow(){ Display *Dsp = Get_XDisplay(); if (_Win!=0) { XResizeWindow( Dsp, _Win, Width(), Height() ); } else { // Border_pixel and dflt Colormap are MANDATORY (on SGI+Sun) :( SKL_ASSERT(_Root_CMap==None); _Root_CMap = XCreateColormap(Dsp, RootWindow(Dsp, Get_Screen()), _Visual, AllocNone); XSetWindowAttributes W_Attribs; W_Attribs.backing_store = NotUseful; // Always; W_Attribs.event_mask = X11_MASKS; W_Attribs.border_pixel = 0; W_Attribs.colormap = _Root_CMap; _Win = XCreateWindow(Dsp, RootWindow( Dsp, Get_Screen() ), 0, 0, Width(), Height(), 0, _Depth, InputOutput, _Visual, CWBackingStore | CWEventMask | CWBorderPixel | CWColormap, &W_Attribs ); if ( _Win==0 ) return 0; XGCValues gcVals; _GC = XCreateGC( Dsp, _Win, 0, &gcVals );// _GC = DefaultGC( Dsp, Screen ); XStoreName(Dsp, _Win, Get_Name());// XSelectInput( Dsp, _Win, X11_MASKS ); } return 1;}int SKL_X11_RAW_WIN::Create_XImage(){ Display *Dsp = Get_XDisplay(); _XImg = XCreateImage( Dsp, _Visual, _Depth, ZPixmap, 0, 0, Width(), Height(), BitmapPad( Dsp ), 0 ); if ( _XImg==0 ) return 0; int bps = _XImg->bytes_per_line; _XImg->data = (char*)Get_Mem()->New( _XImg->height*bps * sizeof(char) ); Set_Virtual(Width(), Height(), Format(), (SKL_BYTE*)_XImg->data, bps); return 1;}int SKL_X11_RAW_WIN::Create_Window(int show){ if (!Create_XWindow()) return 0; if (!Create_XImage()) return 0; if (!Create_XCMap()) return 0; if (!Hide_Cursor()) return 0; Set_Resize_Mode(0); if (show) Show(); return 1;}void SKL_X11_RAW_WIN::Real_Unlock(int Xo, int Yo, int W, int H){ Display *Dsp = Get_XDisplay(); SKL_ASSERT(Xo>=0 && Yo>=0 && (W-Xo)<=Width() && (H-Yo)<=Height()); XPutImage( Dsp, _Win, _GC, _XImg, Xo, Yo, Xo, Yo, W, H); XFlush(Dsp);}//////////////////////////////////////////////////////////void SKL_X11_RAW_WIN::Translate_X11_Event(XEvent *Event, SKL_EVENT &New){ KeySym Touche; char Buffer; int Type = Event->type; if ( Type == KeyPress ) { if ( XLookupString( (XKeyPressedEvent*)Event, &Buffer, 1, &Touche, 0 ) != 1 )// Touche = XLookupKeysym( (XKeyEvent*)&Event->xkey, 0 );// if ( Touche!=NoSymbol ) { if ( Touche == XK_Shift_L || Touche == XK_Shift_R ) New.Add_Modifier(SKL_EVENT::SHIFT_MODIFIER); if ( Touche == XK_Control_L || Touche == XK_Control_R ) New.Add_Modifier(SKL_EVENT::CTRL_MODIFIER); if ( Touche == XK_Alt_L || Touche == XK_Alt_R ) New.Add_Modifier(SKL_EVENT::ALT_MODIFIER); if ( Touche == XK_Left ) New.Add_Modifier(SKL_EVENT::LEFT_MODIFIER); if ( Touche == XK_Right ) New.Add_Modifier(SKL_EVENT::RIGHT_MODIFIER); if ( Touche == XK_Up ) New.Add_Modifier(SKL_EVENT::UP_MODIFIER); if ( Touche == XK_Down ) New.Add_Modifier(SKL_EVENT::DOWN_MODIFIER); } } else if ( Type == KeyRelease ) { SKL_UINT32 Mod = Event->xkey.state; if ( Mod & ShiftMask ) New.Add_Modifier(SKL_EVENT::SHIFT_MODIFIER); if ( Mod & ControlMask ) New.Add_Modifier(SKL_EVENT::CTRL_MODIFIER); if ( Mod & Mod1Mask ) New.Add_Modifier(SKL_EVENT::ALT_MODIFIER);// if ( XLookupString( ( XKeyReleasedEvent *)( Event ),// &Buffer, 1, &Touche, NULL ) != 1 ) Touche = XLookupKeysym( (XKeyEvent*)&Event->xkey, 0 ); if ( Touche==NoSymbol ) return; if ((Touche>>8)==0xff) // Special Key { if ( (Touche&0xff) == 0x1b ) New.Set_Key(SKL_EVENT::ESCAPE); else if ( (Touche&0xff) == 0xbe ) New.Set_Key(SKL_EVENT::F1); else if ( (Touche&0xff) == 0xbf ) New.Set_Key(SKL_EVENT::F2); else if ( (Touche&0xff) == 0xc0 ) New.Set_Key(SKL_EVENT::F3); else if ( (Touche&0xff) == 0xc1 ) New.Set_Key(SKL_EVENT::F4); else if ( (Touche&0xff) == 0xc2 ) New.Set_Key(SKL_EVENT::F5); else if ( (Touche&0xff) == 0xc3 ) New.Set_Key(SKL_EVENT::F6); else if ( (Touche&0xff) == 0xc4 ) New.Set_Key(SKL_EVENT::F7); else if ( (Touche&0xff) == 0xc5 ) New.Set_Key(SKL_EVENT::F8); else if ( (Touche&0xff) == 0xc6 ) New.Set_Key(SKL_EVENT::F9); else if ( (Touche&0xff) == 0xc7 ) New.Set_Key(SKL_EVENT::F10); else if ( (Touche&0xff) == 0xc8 ) New.Set_Key(SKL_EVENT::F11); else if ( (Touche&0xff) == 0xc9 ) New.Set_Key(SKL_EVENT::F12);// else fprintf( stderr, "KeySym=0x%x\n", Touche ); } else New.Set_Key( (int)Touche ); New.Add_Type(SKL_EVENT::KEY_PRESS); } else if ( Type==MotionNotify ) { XMotionEvent *MEvent = ( XMotionEvent *)&Event->xmotion; SKL_UINT32 But = Event->xbutton.state; New.Set_Position( MEvent->x, MEvent->y ); New.Add_Type(SKL_EVENT::MOVE); if ( But & Button1Mask ) New.Add_Type(SKL_EVENT::CLICK1); else New.Remove_Type(SKL_EVENT::CLICK1); if ( But & Button2Mask ) New.Add_Type(SKL_EVENT::CLICK2); else New.Remove_Type(SKL_EVENT::CLICK2); if ( But & Button3Mask ) New.Add_Type(SKL_EVENT::CLICK3); else New.Remove_Type(SKL_EVENT::CLICK3); } else if ( Type == ButtonRelease ) { XButtonEvent *BEvent = (XButtonEvent *)&Event->xbutton; New.Set_Position( BEvent->x, BEvent->y ); SKL_UINT32 But = BEvent->state; if ( But & Button1Mask ) New.Add_Type(SKL_EVENT::RELEASE1); if ( But & Button2Mask ) New.Add_Type(SKL_EVENT::RELEASE2); if ( But & Button3Mask ) New.Add_Type(SKL_EVENT::RELEASE3); } else if ( Type == ButtonPress ) { XButtonEvent *BEvent = (XButtonEvent *)&Event->xbutton; New.Set_Position( BEvent->x, BEvent->y ); SKL_UINT32 But = BEvent->button; if ( But & Button1 ) New.Add_Type(SKL_EVENT::CLICK1); if ( But & Button2 ) New.Add_Type(SKL_EVENT::CLICK2); if ( But & Button3 ) New.Add_Type(SKL_EVENT::CLICK3); }}void SKL_X11_RAW_WIN::Get_Event(SKL_EVENT &New){ Display *Dsp = Get_XDisplay(); XEvent Event; while( XCheckWindowEvent( Dsp, _Win, X11_MASKS, &Event ) ) Translate_X11_Event( &Event, New );}//////////////////////////////////////////////////////////// SKL_X11_SHM_WIN//////////////////////////////////////////////////////////#if defined(SKL_USE_SHM)SKL_X11_SHM_WIN::SKL_X11_SHM_WIN(const SKL_X11_WIN *w, int W, int H) : SKL_X11_RAW_WIN(w, W, H){ _Shm_Info.shmid = -1; _Shm_Info.shmaddr = 0;}SKL_X11_SHM_WIN::~SKL_X11_SHM_WIN(){ Clear_Shm();}//////////////////////////////////////////////////////////int SKL_X11_SHM_WIN::Create_XImage(){ Display *Dsp = Get_XDisplay(); int bps; _XImg = XShmCreateImage( Dsp, _Visual, _Depth, ZPixmap, NULL /* no alloc */, &_Shm_Info, Width(), Height() ); if ( _XImg==0 ) goto Failed; if ( _XImg->xoffset!=0 ) goto Failed; bps = _XImg->bytes_per_line; _Shm_Info.shmid = shmget( IPC_PRIVATE, _XImg->height*bps, IPC_CREAT | 0777); if ( _Shm_Info.shmid<0 ) goto Failed; _Shm_Info.shmaddr = (char*)shmat( _Shm_Info.shmid, 0, 0 ); if ( _Shm_Info.shmaddr==(char*)-1 ) goto Failed; XSync(Dsp, False); _Shm_Info.readOnly = False; if ( !XShmAttach( Dsp, &_Shm_Info ) ) goto Failed;#ifndef COMPLETION_BUG _Completion_Type = XShmGetEventBase( Dsp ) + ShmCompletion;#endif#ifndef DONT_DETACH_FIRST shmctl( _Shm_Info.shmid, IPC_RMID, 0 );#endif _XImg->data = (char*)_Shm_Info.shmaddr; Set_Virtual(Width(), Height(), Format(), (SKL_BYTE*)_XImg->data, bps); return 1; Failed: Clear_Shm(); Cleanup(); return 0;}void SKL_X11_SHM_WIN::Clear_Shm(){ if (_Shm_Info.shmid>=0) { SKL_ASSERT(_Shm_Info.shmaddr!=0); shmdt( _Shm_Info.shmaddr ); _Shm_Info.shmaddr = 0;#ifdef DONT_DETACH_FIRST shmctl( _Shm_Info.shmid, IPC_RMID, 0 );#endif XShmDetach( Get_XDisplay(), &_Shm_Info ); } _Shm_Info.shmid = -1;}//////////////////////////////////////////////////////////void SKL_X11_SHM_WIN::Real_Unlock(int Xo, int Yo, int W, int H){ SKL_ASSERT(Xo>=0 && Yo>=0 && (W-Xo)<=Width() && (H-Yo)<=Height()); Display *Dsp = Get_XDisplay(); XShmPutImage( Dsp, _Win, _GC, _XImg, Xo, Yo, Xo, Yo, W, H, True ); if (_Drv->VSync_Is_On()) {#ifndef COMPLETION_BUG XEvent Event; while ( !XCheckTypedWindowEvent(Dsp, _Win, _Completion_Type, &Event) );// while( XNextEvent(Dsp, &Event) );// SKL_ANY Addr = (SKL_ANY)( _Shm_Info..shmaddr + ((XShmCompletionEvent*)&Event)->offset ); #else XFlush(Dsp); // TODO: Gahhh!#endif }}#endif /* SKL_USE_SHM *///////////////////////////////////////////////////////////#endif /* SKL_USE_X11 */#endif /* SKL_NO_VIDEO */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -