Index: Source/x11/XGServerWindow.m =================================================================== --- Source/x11/XGServerWindow.m (Revision 28048) +++ Source/x11/XGServerWindow.m (Arbeitskopie) @@ -3626,6 +3626,22 @@ grab_window = NULL; } +- (void) setmouseposition: (int)x :(int)y :(int)win +{ + gswindow_device_t *window; + window = WINDOW_WITH_TAG(win); + + unsigned int style = window->win_attrs.window_style; + float t, b, l, r; + + [self styleoffsets: &l : &r : &t : &b : style : window->ident]; + + float xx = x - l; + float xy = NSHeight(window->xframe) - y + b; + + XWarpPointer(dpy,None,window->ident,0,0,0,0,xx,xy); +} + - (void) setinputfocus: (int)win { gswindow_device_t *window = WINDOW_WITH_TAG(win); Index: Source/x11/XGGLContext.m =================================================================== --- Source/x11/XGGLContext.m (Revision 28048) +++ Source/x11/XGGLContext.m (Arbeitskopie) @@ -29,6 +29,7 @@ #ifdef HAVE_GLX #include #include +#include #include #include #include @@ -232,7 +233,7 @@ { MAKE_DISPLAY(dpy); - if (GSglxMinorVersion(dpy) >= 3) + if ([XGGLPixelFormat glxMinorVersion] >= 3) { if ( !glXMakeContextCurrent(dpy, None, None, NULL) ) NSDebugMLLog( @"GLX", @"Can not clear current GL context - Errror %u", @@ -434,26 +435,22 @@ if (xSubWindow == nil) [NSException raise: NSGenericException - format: @"GL Context is not bind, cannot be made current"]; + format: @"GL Context has no view attached, cannot be made current"]; NSAssert(glx_context != None && glx_drawable != None, NSInternalInconsistencyException); - if (GSglxMinorVersion(dpy) >= 3) + if ([XGGLPixelFormat glxMinorVersion] >= 3) { - //NSDebugMLLog(@"GLX", @"before glXMakeContextCurrent"); if ( !glXMakeContextCurrent(dpy, glx_drawable, glx_drawable, glx_context) ) NSDebugMLLog( @"GLX", @"Can not make GL context %@ current - Errror %u", self, glGetError() ); - //NSDebugMLLog(@"GLX", @"after glXMakeContextCurrent"); } else { - //NSDebugMLLog(@"GLX", @"before glXMakeCurrent"); if ( !glXMakeCurrent(dpy, glx_drawable, glx_context) ) NSDebugMLLog( @"GLX", @"Can not make GL context %@ current - Errror %u", self, glGetError() ); - //NSDebugMLLog(@"GLX", @"after glXMakeCurrent"); } currentGLContext = self; @@ -497,7 +494,7 @@ [current_view _setIgnoresBacking: saved_ignores_backing]; } ASSIGN(xSubWindow, [XGXSubWindow subwindowOnView: view - visualinfo: [pixelFormat xvinfo]]); + visualinfo: [pixelFormat visualinfo]]); glx_drawable = [pixelFormat drawableForWindow: xSubWindow->xwindowid]; saved_ignores_backing = [view _ignoresBacking]; [view _setIgnoresBacking: YES]; Index: Source/x11/XGServerEvent.m =================================================================== --- Source/x11/XGServerEvent.m (Revision 28048) +++ Source/x11/XGServerEvent.m (Arbeitskopie) @@ -90,6 +90,8 @@ static BOOL _is_keyboard_initialized = NO; static BOOL _mod_ignore_shift = NO; +static BOOL next_event_is_a_keyrepeat; + void __objc_xgcontextevent_linking (void) { } @@ -342,6 +344,7 @@ NSGraphicsContext *gcontext; float deltaX; float deltaY; + int buttonNumber; gcontext = GSCurrentContext(); xEvent = *event; @@ -404,24 +407,35 @@ deltaY = 0.0; if (xEvent.xbutton.button == generic.lMouse) + { eventType = NSLeftMouseDown; + buttonNumber = generic.lMouse; + } else if (xEvent.xbutton.button == generic.rMouse && generic.rMouse != 0) + { eventType = NSRightMouseDown; + buttonNumber = generic.rMouse; + } else if (xEvent.xbutton.button == generic.mMouse && generic.mMouse != 0) + { eventType = NSOtherMouseDown; + buttonNumber = generic.mMouse; + } else if (xEvent.xbutton.button == generic.upMouse && generic.upMouse != 0) { deltaY = 1.; eventType = NSScrollWheel; + buttonNumber = generic.upMouse; } else if (xEvent.xbutton.button == generic.downMouse && generic.downMouse != 0) { deltaY = -1.; eventType = NSScrollWheel; + buttonNumber = generic.downMouse; } else { @@ -471,7 +485,7 @@ eventNumber: xEvent.xbutton.serial clickCount: clickCount pressure: 1.0 - buttonNumber: 0 /* FIXME */ + buttonNumber: buttonNumber /* FIXME */ deltaX: 0. deltaY: deltaY deltaZ: 0.]; @@ -482,13 +496,22 @@ xEvent.xbutton.window); [self setLastTime: xEvent.xbutton.time]; if (xEvent.xbutton.button == generic.lMouse) + { eventType = NSLeftMouseUp; + buttonNumber = generic.lMouse; + } else if (xEvent.xbutton.button == generic.rMouse && generic.rMouse != 0) + { eventType = NSRightMouseUp; + buttonNumber = generic.rMouse; + } else if (xEvent.xbutton.button == generic.mMouse && generic.mMouse != 0) + { eventType = NSOtherMouseUp; + buttonNumber = generic.mMouse; + } else { // we ignore release of scrollUp or scrollDown @@ -516,7 +539,7 @@ eventNumber: xEvent.xbutton.serial clickCount: clickCount pressure: 1.0 - buttonNumber: 0 /* FIXMME */ + buttonNumber: buttonNumber /* FIXMME */ deltaX: 0.0 deltaY: 0.0 deltaZ: 0.0]; @@ -1925,6 +1948,7 @@ int alt_key = 0; int help_key = 0; KeySym modKeysym; // process modifier independently of shift, etc. + XEvent next_event; if (_is_keyboard_initialized == NO) initialize_keyboard (); @@ -2057,6 +2081,27 @@ eventType = NSFlagsChanged; } + BOOL keyRepeat = NO; + + if ( next_event_is_a_keyrepeat == YES ) + { + keyRepeat = YES; + next_event_is_a_keyrepeat = NO; + } + else if( XEventsQueued( [context xDisplay], QueuedAfterReading ) ) + { + XPeekEvent( [context xDisplay], &next_event ); + if( next_event.xkey.window == xEvent->xkey.window && + next_event.xkey.keycode == xEvent->xkey.keycode && + next_event.xkey.time == xEvent->xkey.time ) + { + // Do not report anything for this event + keyRepeat = YES; + next_event_is_a_keyrepeat = YES; + } + } + + if (help_key) { unicode = NSHelpFunctionKey; @@ -2071,7 +2116,7 @@ context: GSCurrentContext() characters: keys charactersIgnoringModifiers: keys - isARepeat: NO + isARepeat: keyRepeat keyCode: keyCode]; [event_queue addObject: event]; event = [NSEvent keyEventWithType: NSFlagsChanged @@ -2107,7 +2152,7 @@ context: GSCurrentContext() characters: keys charactersIgnoringModifiers: keys - isARepeat: NO + isARepeat: keyRepeat keyCode: keyCode]; return event; } @@ -2145,7 +2190,7 @@ context: GSCurrentContext() characters: keys charactersIgnoringModifiers: ukeys - isARepeat: NO /* isARepeat can't be supported with X */ + isARepeat: keyRepeat keyCode: keyCode]; return event; Index: Source/x11/XGGLFormat.m =================================================================== --- Source/x11/XGGLFormat.m (Revision 28048) +++ Source/x11/XGGLFormat.m (Arbeitskopie) @@ -26,71 +26,103 @@ */ #include "config.h" + #ifdef HAVE_GLX + #include #include #include +#include #include #include "x11/XGServer.h" #include "x11/XGOpenGL.h" #include +#include -#define MAKE_DISPLAY(dpy) Display *dpy;\ - dpy = [(XGServer *)GSCurrentServer() xDisplay];\ - NSAssert(dpy != NULL, NSInternalInconsistencyException) - @implementation XGGLPixelFormat -/* FIXME: - we assume that the ABI of NSOpenGLPixelFormatAttribute matches the ABI - of glX. Apparently, this is true for the most useful attributes. -*/ ++ (int) glxMinorVersion +{ + Display * display = [ (XGServer *)GSCurrentServer() xDisplay ]; + NSDictionary * attributes = [ GSCurrentServer() attributes ]; + NSString * sn = [ attributes objectForKey: GSScreenNumber ]; + NSString * glxServerVersion = [ NSString stringWithFormat:@"%s", glXQueryServerString(display, [sn intValue], GLX_VERSION) ]; + NSString * glxClientVersion = [ NSString stringWithFormat:@"%s", glXGetClientString(display, GLX_VERSION) ]; + + float serverversion = [ glxServerVersion floatValue ]; + float clientversion = [ glxClientVersion floatValue ]; + + float serverIntegerPart; + float clientIntegerPart; + float fracServer = modff(serverversion, &serverIntegerPart); + float fracClient = modff(clientversion, &clientIntegerPart); + + if ( serverIntegerPart == 1.0f && clientIntegerPart == 1.0f ) + { + fracServer = rintf(fracServer * 10.0f); + fracClient = rintf(fracClient * 10.0f); + + NSDebugMLLog(@"GLX", @"server %f client %f", fracServer, fracClient ); + + return (int)MIN(fracServer, fracClient); + } + + return -1; +} + +// Works for some attributes only - (void) getValues: (GLint *)vals forAttribute: (NSOpenGLPixelFormatAttribute)attrib forVirtualScreen: (GLint)screen { - MAKE_DISPLAY(dpy); - GLint error; - - NSAssert(((GSglxMinorVersion (dpy) >= 3) ? (void *)configurations.fbconfig : (void *)configurations.visualinfo) != NULL - && configurationCount > 0, + NSAssert((fbconfig != NULL || visualinfo != NULL) && configurationCount > 0, NSInternalInconsistencyException); - if (GSglxMinorVersion(dpy) >= 3) + int error; + + if (glxminorversion >= 3) { - error = glXGetFBConfigAttrib(dpy, configurations.fbconfig[0], attrib, vals); + error = glXGetFBConfigAttrib(display, fbconfig[0], attrib, vals); if ( error != 0 ) NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Errror %u", self, error ); } else { - error = glXGetConfig(dpy, configurations.visualinfo, attrib, vals); + error = glXGetConfig(display, visualinfo, attrib, vals); if ( error != 0 ) NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Errror %u", self, error ); - if ( error != 0 ) - NSDebugMLLog( @"GLX", @"Can not get FB attribute for pixel format %@ - Errror %u", - self, error ); } } -- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs +- (NSMutableData *) assembleGLXAttributes:(NSOpenGLPixelFormatAttribute *)pixelFormatAttributes { int AccumSize; - NSOpenGLPixelFormatAttribute *ptr = attribs; + NSOpenGLPixelFormatAttribute *ptr = pixelFormatAttributes; NSMutableData *data = [NSMutableData data]; - MAKE_DISPLAY(dpy); - GLint drawable_type = 0; -#define append(a, b) do {int v1 = a; int v2 = b; [data appendBytes: &v1 length: sizeof(v1)];\ - [data appendBytes: &v2 length: sizeof(v2)];} while (0) +#define append(a, b) \ +do \ +{ \ + int v1 = a; \ + int v2 = b; \ + [data appendBytes: &v1 length: sizeof(v1)]; \ + [data appendBytes: &v2 length: sizeof(v2)]; \ +} while (0) -#define append1(a) do {int v1 = a; [data appendBytes: &v1 length: sizeof(v1)];} while (0) +#define append1(a) \ +do \ +{ \ + int v1 = a; \ + [data appendBytes: &v1 length: sizeof(v1)]; \ +} while (0) - if (GSglxMinorVersion (dpy) < 3) + GLint drawable_type = 0; + + if (glxminorversion < 3) { append1 (GLX_RGBA); } @@ -110,95 +142,138 @@ case NSOpenGLPFASingleRenderer: case NSOpenGLPFAAllRenderers: case NSOpenGLPFAAccelerated: - if (GSglxMinorVersion(dpy) < 3) - append(GLX_USE_GL,YES); - break; + if (glxminorversion < 3) + { + append(GLX_USE_GL,YES); + break; + } case NSOpenGLPFADoubleBuffer: - append(GLX_DOUBLEBUFFER, YES); - break; + { + append(GLX_DOUBLEBUFFER, YES); + break; + } case NSOpenGLPFAStereo: - append(GLX_STEREO, YES); - break; + { + append(GLX_STEREO, YES); + break; + } case NSOpenGLPFAAuxBuffers: - ptr++; - append(GLX_AUX_BUFFERS, *ptr); - break; + { + ptr++; + append(GLX_AUX_BUFFERS, *ptr); + break; + } case NSOpenGLPFAColorSize: - ptr++; - append(GLX_RED_SIZE, *ptr); - append(GLX_GREEN_SIZE, *ptr); - append(GLX_BLUE_SIZE, *ptr); - break; + { + ptr++; + append(GLX_RED_SIZE, *ptr); + append(GLX_GREEN_SIZE, *ptr); + append(GLX_BLUE_SIZE, *ptr); + break; + } case NSOpenGLPFAAlphaSize: - ptr++; - append(GLX_ALPHA_SIZE, *ptr); - break; + { + ptr++; + append(GLX_ALPHA_SIZE, *ptr); + break; + } case NSOpenGLPFADepthSize: - ptr++; - append(GLX_DEPTH_SIZE, *ptr); - break; + { + ptr++; + append(GLX_DEPTH_SIZE, *ptr); + break; + } case NSOpenGLPFAStencilSize: - ptr++; - append(GLX_STENCIL_SIZE, *ptr); - break; + { + ptr++; + append(GLX_STENCIL_SIZE, *ptr); + break; + } case NSOpenGLPFAAccumSize: - ptr++; - //has to been tested - I did it in that way.... - //FIXME? I don't understand... - //append(GLX_ACCUM_RED_SIZE, *ptr/3); - //append(GLX_ACCUM_GREEN_SIZE, *ptr/3); - //append(GLX_ACCUM_BLUE_SIZE, *ptr/3); - AccumSize=*ptr; - switch (AccumSize) - { - case 8: - append(GLX_ACCUM_RED_SIZE, 3); - append(GLX_ACCUM_GREEN_SIZE, 3); - append(GLX_ACCUM_BLUE_SIZE, 2); - append(GLX_ACCUM_ALPHA_SIZE, 0); - break; - case 15: - case 16: - append(GLX_ACCUM_RED_SIZE, 5); - append(GLX_ACCUM_GREEN_SIZE, 5); - append(GLX_ACCUM_BLUE_SIZE, 5); - append(GLX_ACCUM_ALPHA_SIZE, 0); - break; - case 24: - append(GLX_ACCUM_RED_SIZE, 8); - append(GLX_ACCUM_GREEN_SIZE, 8); - append(GLX_ACCUM_BLUE_SIZE, 8); - append(GLX_ACCUM_ALPHA_SIZE, 0); - break; - case 32: - append(GLX_ACCUM_RED_SIZE, 8); - append(GLX_ACCUM_GREEN_SIZE, 8); - append(GLX_ACCUM_BLUE_SIZE, 8); - append(GLX_ACCUM_ALPHA_SIZE, 8); - break; - } - break; - case NSOpenGLPFAWindow: - drawable_type |= GLX_WINDOW_BIT; - break; - case NSOpenGLPFAPixelBuffer: - drawable_type |= GLX_PBUFFER_BIT; - break; + { + ptr++; + AccumSize=*ptr; + switch (AccumSize) + { + case 8: + append(GLX_ACCUM_RED_SIZE, 3); + append(GLX_ACCUM_GREEN_SIZE, 3); + append(GLX_ACCUM_BLUE_SIZE, 2); + append(GLX_ACCUM_ALPHA_SIZE, 0); + break; + case 15: + case 16: + append(GLX_ACCUM_RED_SIZE, 5); + append(GLX_ACCUM_GREEN_SIZE, 5); + append(GLX_ACCUM_BLUE_SIZE, 5); + append(GLX_ACCUM_ALPHA_SIZE, 0); + break; + case 24: + append(GLX_ACCUM_RED_SIZE, 8); + append(GLX_ACCUM_GREEN_SIZE, 8); + append(GLX_ACCUM_BLUE_SIZE, 8); + append(GLX_ACCUM_ALPHA_SIZE, 0); + break; + case 32: + append(GLX_ACCUM_RED_SIZE, 8); + append(GLX_ACCUM_GREEN_SIZE, 8); + append(GLX_ACCUM_BLUE_SIZE, 8); + append(GLX_ACCUM_ALPHA_SIZE, 8); + break; + } + break; + } + + case NSOpenGLPFAWindow: + { + drawable_type |= GLX_WINDOW_BIT; + break; + } + case NSOpenGLPFAPixelBuffer: + { + drawable_type |= GLX_PBUFFER_BIT; + break; + } case NSOpenGLPFAOffScreen: - drawable_type |= GLX_PIXMAP_BIT; - break; + { + drawable_type |= GLX_PIXMAP_BIT; + break; + } //can not be handle by X11 case NSOpenGLPFAMinimumPolicy: - break; + { + break; + } // can not be handle by X11 case NSOpenGLPFAMaximumPolicy: - break; + { + break; + } - //FIXME all of this stuff... case NSOpenGLPFAFullScreen: + { + break; + } case NSOpenGLPFASampleBuffers: + { + if ( glxminorversion >= 4 ) + { + ptr++; + append(GLX_SAMPLE_BUFFERS, *ptr); + break; + } + } case NSOpenGLPFASamples: + { + if ( glxminorversion >= 4 ) + { + ptr++; + append(GLX_SAMPLES, *ptr); + break; + } + } + case NSOpenGLPFAAuxDepthStencil: case NSOpenGLPFARendererID: case NSOpenGLPFANoRecovery: @@ -228,29 +303,40 @@ append1(None); - //FIXME, what screen number ? - if (GSglxMinorVersion (dpy) >= 3) + return data; + +#undef append +#undef append1 + +} + +- (id)initWithAttributes:(NSOpenGLPixelFormatAttribute *)attribs +{ + self = [ super init ]; + + fbconfig = NULL; + visualinfo = NULL; + + display = [(XGServer *)GSCurrentServer() xDisplay]; + NSAssert(display != NULL, NSInternalInconsistencyException); + + glxminorversion = [ XGGLPixelFormat glxMinorVersion ]; + NSDebugMLLog(@"GLX", @"minor version %d", glxminorversion ); + + NSMutableData * glxAttributes = [ self assembleGLXAttributes:attribs ]; + NSDictionary * dsattributes = [ GSCurrentServer() attributes ]; + + if (glxminorversion >= 3) { - configurations.fbconfig = glXChooseFBConfig(dpy, DefaultScreen(dpy), - [data mutableBytes], - &configurationCount); - if ( configurations.fbconfig == NULL ) - NSDebugMLLog( @"GLX", @"Can not choose FB config for pixel format %@", - self ); + fbconfig = glXChooseFBConfig(display, [[dsattributes objectForKey: GSScreenNumber] intValue], [glxAttributes mutableBytes], &configurationCount); + visualinfo = glXGetVisualFromFBConfig(display,fbconfig[0]); } else { - configurations.visualinfo = glXChooseVisual(dpy, DefaultScreen(dpy), - [data mutableBytes]); - if((void *)configurations.visualinfo != NULL) - configurationCount = 1; - else - NSDebugMLLog( @"GLX", @"Can not choose FB config for pixel format %@", - self ); + visualinfo = glXChooseVisual(display, [[dsattributes objectForKey: GSScreenNumber] intValue], [glxAttributes mutableBytes]); } - if (((GSglxMinorVersion (dpy) >= 3) ? (void *)configurations.fbconfig : - (void *)configurations.visualinfo) == NULL) + if (fbconfig == NULL && visualinfo == NULL) { NSDebugMLLog(@"GLX", @"no pixel format found matching what is required"); RELEASE(self); @@ -265,33 +351,28 @@ } } -- (XVisualInfo *)xvinfo +- (Display *) display { - MAKE_DISPLAY(dpy); + return display; +} - if (GSglxMinorVersion(dpy) >= 3) - { - return glXGetVisualFromFBConfig(dpy, configurations.fbconfig[0]); - } - else - { - return configurations.visualinfo; - } +- (XVisualInfo *) visualinfo +{ + return visualinfo; } - (GLXContext)createGLXContext: (XGGLContext *)share { GLXContext context; - MAKE_DISPLAY(dpy); - if (GSglxMinorVersion(dpy) >= 3) + if (glxminorversion >= 3) { - context = glXCreateNewContext(dpy, configurations.fbconfig[0], + context = glXCreateNewContext(display, fbconfig[0], GLX_RGBA_TYPE, [share glxcontext], YES); } else { - context = glXCreateContext(dpy, configurations.visualinfo, + context = glXCreateContext(display, visualinfo, [share glxcontext], GL_TRUE); } if ( context == NULL ) @@ -304,12 +385,10 @@ - (GLXWindow) drawableForWindow: (Window)xwindowid { GLXWindow win; - MAKE_DISPLAY(dpy); - if (GSglxMinorVersion(dpy) >= 3) + if (glxminorversion >= 3) { - win = glXCreateWindow(dpy, configurations.fbconfig[0], - xwindowid, NULL); + win = glXCreateWindow(display, fbconfig[0], xwindowid, NULL); } else { @@ -327,17 +406,14 @@ { //FIXME //are we sure that X Connection is still up here ? - MAKE_DISPLAY(dpy); - if (GSglxMinorVersion(dpy) >= 3) + if (glxminorversion >= 3) { - XFree(configurations.fbconfig); + XFree(fbconfig); } - else - { - XFree(configurations.visualinfo); - } + XFree(visualinfo); + NSDebugMLLog(@"GLX", @"deallocation"); [super dealloc]; } @@ -350,4 +426,5 @@ } @end + #endif Index: Headers/x11/XGOpenGL.h =================================================================== --- Headers/x11/XGOpenGL.h (Revision 28048) +++ Headers/x11/XGOpenGL.h (Arbeitskopie) @@ -25,23 +25,19 @@ Boston, MA 02110-1301, USA. */ -#ifndef _GNUstep_H_XGOpenGL -#define _GNUstep_H_XGOpenGL +#ifndef _GNUstep_H_XGOpenGL_ +#define _GNUstep_H_XGOpenGL_ +#include #include -#define id _gs_avoid_id_collision -#define BOOL XWINDOWSBOOL -#include -#undef id -#undef BOOL - @class NSView; @class XGXSubWindow; @class XGGLPixelFormat; @interface XGGLContext : NSOpenGLContext { + int glxminorversion; GLXContext glx_context; GLXWindow glx_drawable; XGXSubWindow *xSubWindow; @@ -55,33 +51,19 @@ @interface XGGLPixelFormat : NSOpenGLPixelFormat { - @public - union - { - GLXFBConfig *fbconfig; - XVisualInfo *visualinfo; - } configurations; - + Display * display; + long int glxminorversion; + GLXFBConfig *fbconfig; + XVisualInfo *visualinfo; int configurationCount; } -- (XVisualInfo *)xvinfo; -- (GLXContext)createGLXContext: (XGGLContext *)share; ++ (int) glxMinorVersion; +- (Display *) display; +- (XVisualInfo *) visualinfo; +- (GLXContext) createGLXContext: (XGGLContext *)share; - (GLXWindow) drawableForWindow: (Window)xwindowid; @end -static inline int -GSglxMinorVersion(Display *dpy) -{ - int major, minor; - - if (False == glXQueryVersion(dpy, &major, &minor)) - { - return -1; - } - - return minor; -} - #endif