src/video/cocoa/SDL_cocoawindow.h
author Sam Lantinga <slouken@libsdl.org>
Thu, 11 Jul 2013 21:51:09 -0700
changeset 7408 c50e165abfdf
parent 7090 c4ac8be0065b
child 7507 885b4aab4190
permissions -rw-r--r--
Fixed bug 1958 - Cocoa SwapWindow doesn't swap the specified window

Ryan C. Gordon

We have this in Cocoa_GL_SwapWindow()...

/* FIXME: Do we need to get the context for the window? */
[[NSOpenGLContext currentContext] flushBuffer];

...which means if the current GL context is not the one in (window), we swap a different one than requested.

Right now, we don't store information about which context is assigned to which window, and the OS doesn't give you a way to retrieve it from an NSView. We would have to track this per-window during SDL_GL_MakeCurrent() (and SDL_GL_CreateContext) calls.
slouken@1933
     1
/*
slouken@5535
     2
  Simple DirectMedia Layer
slouken@6885
     3
  Copyright (C) 1997-2013 Sam Lantinga <slouken@libsdl.org>
slouken@1933
     4
slouken@5535
     5
  This software is provided 'as-is', without any express or implied
slouken@5535
     6
  warranty.  In no event will the authors be held liable for any damages
slouken@5535
     7
  arising from the use of this software.
slouken@1933
     8
slouken@5535
     9
  Permission is granted to anyone to use this software for any purpose,
slouken@5535
    10
  including commercial applications, and to alter it and redistribute it
slouken@5535
    11
  freely, subject to the following restrictions:
slouken@1933
    12
slouken@5535
    13
  1. The origin of this software must not be misrepresented; you must not
slouken@5535
    14
     claim that you wrote the original software. If you use this software
slouken@5535
    15
     in a product, an acknowledgment in the product documentation would be
slouken@5535
    16
     appreciated but is not required.
slouken@5535
    17
  2. Altered source versions must be plainly marked as such, and must not be
slouken@5535
    18
     misrepresented as being the original software.
slouken@5535
    19
  3. This notice may not be removed or altered from any source distribution.
slouken@1933
    20
*/
slouken@1933
    21
#include "SDL_config.h"
slouken@1933
    22
slouken@1933
    23
#ifndef _SDL_cocoawindow_h
slouken@1933
    24
#define _SDL_cocoawindow_h
slouken@1933
    25
slouken@3400
    26
#import <Cocoa/Cocoa.h>
slouken@3400
    27
slouken@1933
    28
typedef struct SDL_WindowData SDL_WindowData;
slouken@1933
    29
slouken@1936
    30
/* *INDENT-OFF* */
icculus@5646
    31
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1060
slouken@5374
    32
@interface Cocoa_WindowListener : NSResponder <NSWindowDelegate> {
slouken@5374
    33
#else
slouken@3400
    34
@interface Cocoa_WindowListener : NSResponder {
slouken@5374
    35
#endif
slouken@1933
    36
    SDL_WindowData *_data;
jorgen@7090
    37
    BOOL observingVisible;
jorgen@7090
    38
    BOOL wasVisible;
slouken@1933
    39
}
slouken@1933
    40
slouken@1933
    41
-(void) listen:(SDL_WindowData *) data;
jorgen@7090
    42
-(void) pauseVisibleObservation;
jorgen@7090
    43
-(void) resumeVisibleObservation;
slouken@1933
    44
-(void) close;
slouken@1933
    45
slouken@1933
    46
/* Window delegate functionality */
slouken@1933
    47
-(BOOL) windowShouldClose:(id) sender;
slouken@1933
    48
-(void) windowDidExpose:(NSNotification *) aNotification;
slouken@1933
    49
-(void) windowDidMove:(NSNotification *) aNotification;
slouken@1933
    50
-(void) windowDidResize:(NSNotification *) aNotification;
slouken@1933
    51
-(void) windowDidMiniaturize:(NSNotification *) aNotification;
slouken@1933
    52
-(void) windowDidDeminiaturize:(NSNotification *) aNotification;
slouken@1933
    53
-(void) windowDidBecomeKey:(NSNotification *) aNotification;
slouken@1933
    54
-(void) windowDidResignKey:(NSNotification *) aNotification;
slouken@1933
    55
slouken@1933
    56
/* Window event handling */
slouken@1933
    57
-(void) mouseDown:(NSEvent *) theEvent;
slouken@1933
    58
-(void) rightMouseDown:(NSEvent *) theEvent;
slouken@1933
    59
-(void) otherMouseDown:(NSEvent *) theEvent;
slouken@1933
    60
-(void) mouseUp:(NSEvent *) theEvent;
slouken@1933
    61
-(void) rightMouseUp:(NSEvent *) theEvent;
slouken@1933
    62
-(void) otherMouseUp:(NSEvent *) theEvent;
slouken@1933
    63
-(void) mouseMoved:(NSEvent *) theEvent;
slouken@1957
    64
-(void) mouseDragged:(NSEvent *) theEvent;
slouken@1958
    65
-(void) rightMouseDragged:(NSEvent *) theEvent;
slouken@1958
    66
-(void) otherMouseDragged:(NSEvent *) theEvent;
slouken@1933
    67
-(void) scrollWheel:(NSEvent *) theEvent;
slouken@4673
    68
-(void) touchesBeganWithEvent:(NSEvent *) theEvent;
slouken@4673
    69
-(void) touchesMovedWithEvent:(NSEvent *) theEvent;
slouken@4673
    70
-(void) touchesEndedWithEvent:(NSEvent *) theEvent;
slouken@4673
    71
-(void) touchesCancelledWithEvent:(NSEvent *) theEvent;
slouken@4673
    72
slouken@4673
    73
/* Touch event handling */
slouken@4673
    74
typedef enum {
slouken@4673
    75
    COCOA_TOUCH_DOWN,
slouken@4673
    76
    COCOA_TOUCH_UP,
slouken@4673
    77
    COCOA_TOUCH_MOVE,
slouken@4673
    78
    COCOA_TOUCH_CANCELLED
slouken@4673
    79
} cocoaTouchType;
slouken@4673
    80
-(void) handleTouches:(cocoaTouchType)type withEvent:(NSEvent*) event;
slouken@4673
    81
slouken@1936
    82
@end
slouken@1936
    83
/* *INDENT-ON* */
slouken@1936
    84
slouken@1936
    85
struct SDL_WindowData
slouken@1933
    86
{
slouken@3685
    87
    SDL_Window *window;
slouken@3685
    88
    NSWindow *nswindow;
slouken@7408
    89
    NSOpenGLContext *nscontext;
slouken@1951
    90
    SDL_bool created;
slouken@1933
    91
    Cocoa_WindowListener *listener;
slouken@1933
    92
    struct SDL_VideoData *videodata;
slouken@1933
    93
};
slouken@1933
    94
slouken@1933
    95
extern int Cocoa_CreateWindow(_THIS, SDL_Window * window);
slouken@1933
    96
extern int Cocoa_CreateWindowFrom(_THIS, SDL_Window * window,
slouken@1933
    97
                                  const void *data);
slouken@1933
    98
extern void Cocoa_SetWindowTitle(_THIS, SDL_Window * window);
slouken@5375
    99
extern void Cocoa_SetWindowIcon(_THIS, SDL_Window * window, SDL_Surface * icon);
slouken@1933
   100
extern void Cocoa_SetWindowPosition(_THIS, SDL_Window * window);
slouken@1933
   101
extern void Cocoa_SetWindowSize(_THIS, SDL_Window * window);
stopiccot@6681
   102
extern void Cocoa_SetWindowMinimumSize(_THIS, SDL_Window * window);
slouken@6788
   103
extern void Cocoa_SetWindowMaximumSize(_THIS, SDL_Window * window);
slouken@1933
   104
extern void Cocoa_ShowWindow(_THIS, SDL_Window * window);
slouken@1933
   105
extern void Cocoa_HideWindow(_THIS, SDL_Window * window);
slouken@1933
   106
extern void Cocoa_RaiseWindow(_THIS, SDL_Window * window);
slouken@1933
   107
extern void Cocoa_MaximizeWindow(_THIS, SDL_Window * window);
slouken@1933
   108
extern void Cocoa_MinimizeWindow(_THIS, SDL_Window * window);
slouken@1933
   109
extern void Cocoa_RestoreWindow(_THIS, SDL_Window * window);
icculus@6422
   110
extern void Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered);
slouken@5305
   111
extern void Cocoa_SetWindowFullscreen(_THIS, SDL_Window * window, SDL_VideoDisplay * display, SDL_bool fullscreen);
slouken@5466
   112
extern int Cocoa_SetWindowGammaRamp(_THIS, SDL_Window * window, const Uint16 * ramp);
slouken@5466
   113
extern int Cocoa_GetWindowGammaRamp(_THIS, SDL_Window * window, Uint16 * ramp);
slouken@6662
   114
extern void Cocoa_SetWindowGrab(_THIS, SDL_Window * window, SDL_bool grabbed);
slouken@1933
   115
extern void Cocoa_DestroyWindow(_THIS, SDL_Window * window);
slouken@1933
   116
extern SDL_bool Cocoa_GetWindowWMInfo(_THIS, SDL_Window * window,
slouken@1933
   117
                                      struct SDL_SysWMinfo *info);
slouken@1933
   118
slouken@1933
   119
#endif /* _SDL_cocoawindow_h */
slouken@1933
   120
slouken@1933
   121
/* vi: set ts=4 sw=4 expandtab: */