new window behaviour for macos X computers :

if video card is open GL accelerated and has 16 Mo or more
start window in maximized mode wich is a full screen mode
but keeping access to other windows and sytem menu items

older comps start as usual
This commit is contained in:
Jean-Luc Peurière 2004-07-27 20:40:42 +00:00
parent 0b9cf9006a
commit f3beeec296
5 changed files with 187 additions and 19 deletions

@ -75,13 +75,21 @@ const EventTypeSpec kEvents[] =
{ kEventClassMouse, kEventMouseDragged },
{ kEventClassMouse, kEventMouseWheelMoved },
{ kEventClassWindow, kEventWindowClickZoomRgn } , /* for new zoom behaviour */
{ kEventClassWindow, kEventWindowZoom }, /* for new zoom behaviour */
{ kEventClassWindow, kEventWindowExpand } , /* for new zoom behaviour */
{ kEventClassWindow, kEventWindowExpandAll }, /* for new zoom behaviour */
{ kEventClassWindow, kEventWindowClose },
{ kEventClassWindow, kEventWindowActivated },
{ kEventClassWindow, kEventWindowDeactivated },
{ kEventClassWindow, kEventWindowUpdate },
{ kEventClassWindow, kEventWindowBoundsChanged }
};
static GHOST_TButtonMask convertButton(EventMouseButton button)
{
switch (button) {
@ -385,7 +393,9 @@ GHOST_IWindow* GHOST_SystemCarbon::createWindow(
)
{
GHOST_IWindow* window = 0;
window = new GHOST_WindowCarbon (title, left, top, width, height, state, type);
window = new GHOST_WindowCarbon (title, left, top, width, height, state, type);
if (window) {
if (window->getValid()) {
// Store the pointer to the window
@ -633,7 +643,7 @@ OSStatus GHOST_SystemCarbon::handleWindowEvent(EventRef event)
return err;
}
if (!getFullScreen()) {
//if (!getFullScreen()) {
err = noErr;
switch(::GetEventKind(event))
{
@ -664,7 +674,7 @@ OSStatus GHOST_SystemCarbon::handleWindowEvent(EventRef event)
err = eventNotHandledErr;
break;
}
}
// }
//else {
//window = (GHOST_WindowCarbon*) m_windowManager->getFullScreenWindow();
//GHOST_PRINT("GHOST_SystemCarbon::handleWindowEvent(): full-screen window event, " << window << "\n");
@ -770,7 +780,7 @@ OSStatus GHOST_SystemCarbon::handleKeyEvent(EventRef event)
key = convertKey(rawCode);
ascii= convertRomanToLatin(ascii);
if (key!=GHOST_kKeyUnknown) {
// if (key!=GHOST_kKeyUnknown) {
GHOST_TEventType type;
if (kind == kEventRawKeyDown) {
type = GHOST_kEventKeyDown;
@ -780,7 +790,7 @@ OSStatus GHOST_SystemCarbon::handleKeyEvent(EventRef event)
type = GHOST_kEventKeyUp;
}
pushEvent( new GHOST_EventKey( getMilliSeconds(), type, window, key, ascii) );
}
// }
break;
case kEventRawKeyModifiersChanged:
@ -817,13 +827,13 @@ bool GHOST_SystemCarbon::handleMouseDown(EventRef event)
short part;
BitMap screenBits;
bool handled = true;
GHOST_IWindow* ghostWindow;
GHOST_WindowCarbon* ghostWindow;
Point mousePos = {0 , 0};
::GetEventParameter(event, kEventParamMouseLocation, typeQDPoint, NULL, sizeof(Point), NULL, &mousePos);
part = ::FindWindow(mousePos, &window);
ghostWindow = (GHOST_IWindow*) ::GetWRefCon(window);
ghostWindow = (GHOST_WindowCarbon*) ::GetWRefCon(window);
switch (part) {
case inMenuBar:
@ -880,7 +890,25 @@ bool GHOST_SystemCarbon::handleMouseDown(EventRef event)
case inZoomOut:
GHOST_ASSERT(ghostWindow, "GHOST_SystemCarbon::handleMouseEvent: ghostWindow==0");
if (::TrackBox(window, mousePos, part)) {
::ZoomWindow(window, part, true);
int macState;
macState = ghostWindow->getMac_windowState();
if ( macState== 0)
::ZoomWindow(window, part, true);
else
if (macState == 2) { // always ok
::ZoomWindow(window, part, true);
ghostWindow->setMac_windowState(1);
} else { // need to force size again
GHOST_TUns32 scr_x,scr_y;
ghostWindow->setMac_windowState(2);
this->getMainDisplayDimensions(scr_x,scr_y);
::SizeWindow (window, scr_x,scr_y-22,false);
::MoveWindow (window, 1,22,true);
}
}
break;

@ -66,8 +66,33 @@ AGL_DEPTH_SIZE, 16,
AGL_NONE,
};
WindowRef ugly_hack=NULL;
const EventTypeSpec kWEvents[] = {
{ kEventClassWindow, kEventWindowZoom }, /* for new zoom behaviour */
};
static OSStatus myWEventHandlerProc(EventHandlerCallRef handler, EventRef event, void* userData) {
WindowRef mywindow;
GHOST_WindowCarbon *ghost_window;
OSStatus err;
int theState;
if (::GetEventKind(event) == kEventWindowZoom) {
err = ::GetEventParameter (event,kEventParamDirectObject,typeWindowRef,NULL,sizeof(mywindow),NULL, &mywindow);
ghost_window = (GHOST_WindowCarbon *) GetWRefCon(mywindow);
theState = ghost_window->getMac_windowState();
if (theState == 1)
ghost_window->setMac_windowState(2);
else if (theState == 2)
ghost_window->setMac_windowState(1);
}
return eventNotHandledErr;
}
GHOST_WindowCarbon::GHOST_WindowCarbon(
const STR_String& title,
GHOST_TInt32 left,
@ -86,21 +111,36 @@ GHOST_WindowCarbon::GHOST_WindowCarbon(
m_fullScreenDirty(false)
{
Str255 title255;
OSStatus err;
if (state >= 8 ) {
state = state - 8;
setMac_windowState(2);
} else
setMac_windowState(0);
if (state != GHOST_kWindowStateFullScreen) {
Rect bnds = { top, left, top+height, left+width };
Boolean visible = (state == GHOST_kWindowStateNormal) || (state == GHOST_kWindowStateMaximized);
gen2mac(title, title255);
m_windowRef = ::NewCWindow(
nil, // Storage
&bnds, // Bounding rectangle of the window
title255, // Title of the window
visible, // Window initially visible
kWindowFullZoomGrowDocumentProc, //kWindowGrowDocumentProc, // procID
(WindowRef)-1L, // Put window before all other windows
true, // Window has minimize box
(SInt32)this); // Store a pointer to the class in the refCon
err = ::CreateNewWindow( kDocumentWindowClass,
kWindowStandardDocumentAttributes+kWindowLiveResizeAttribute,
&bnds,
&m_windowRef);
if ( err != noErr) {
fprintf(stderr," error creating window %i \n",err);
} else {
//void *handler = &GHOST_WindowCarbon::myWEventHandlerProc;
::SetWRefCon(m_windowRef,(SInt32)this);
err = InstallWindowEventHandler (m_windowRef, myWEventHandlerProc, GetEventTypeCount(kWEvents), kWEvents,NULL,NULL);
if ( err != noErr) {
fprintf(stderr," error creating handler %i \n",err);
} else {
::TransitionWindow (m_windowRef,kWindowZoomTransitionEffect,kWindowShowTransitionAction,NULL);
}
}
if (m_windowRef) {
m_grafPtr = ::GetWindowPort(m_windowRef);
setDrawingContextType(type);
@ -654,3 +694,14 @@ GHOST_TSuccess GHOST_WindowCarbon::setWindowCustomCursorShape(GHOST_TUns8 bitmap
{
setWindowCustomCursorShape((GHOST_TUns8*)bitmap, (GHOST_TUns8*) mask, 16, 16, hotX, hotY, 0, 1);
}
void GHOST_WindowCarbon::setMac_windowState(short value)
{
mac_windowState = value;
}
short GHOST_WindowCarbon::getMac_windowState()
{
return mac_windowState;
}

@ -207,6 +207,11 @@ public:
*/
virtual bool getFullScreenDirty();
/* accessor for fullscreen window */
virtual void setMac_windowState(short value);
virtual short getMac_windowState();
protected:
/**
* Tries to install a rendering context in this window.
@ -261,7 +266,7 @@ protected:
* @param out The converted string object.
*/
virtual void mac2gen(const Str255 in, STR_String& out) const;
WindowRef m_windowRef;
CGrafPtr m_grafPtr;
AGLContext m_aglCtx;
@ -273,6 +278,20 @@ protected:
/** When running in full-screen this tells whether to refresh the window. */
bool m_fullScreenDirty;
/** specific MacOs X full screen window setting as we use partially system mechanism
values : 0 not maximizable default
1 normal state
2 maximized state
this will be reworked when rebuilding GHOST carbon to use new OS X apis
in order to be unified with GHOST fullscreen/maximised settings
(lukep)
**/
short mac_windowState;
/**
* The width/height of the size rectangle in the lower right corner of a

@ -64,6 +64,9 @@
#include "winlay.h"
#ifdef __APPLE__
#include <OpenGL/OpenGL.h>
#endif
///
struct _Window {
@ -94,6 +97,55 @@ struct _Window {
///
#ifdef __APPLE__
/* to avoid killing small end comps, we want to allow
blender to start maximised if all the followings are true :
- Renderer is OpenGL capable
- Hardware acceleration
- VRAM > 8 Mo
*/
static int macPrefState = 0;
int checkAppleVideoCard() {
long theErr;
unsigned long display_mask;
CGLRendererInfoObj rend;
long nrend;
int j;
long value;
display_mask = CGDisplayIDToOpenGLDisplayMask (CGMainDisplayID() );
theErr = CGLQueryRendererInfo( display_mask, &rend, &nrend);
if (theErr == 0) {
theErr = CGLDescribeRenderer (rend, 0, kCGLRPRendererCount, &nrend);
if (theErr == 0) {
for (j = 0; j < nrend; j++) {
theErr = CGLDescribeRenderer (rend, j, kCGLRPAccelerated, &value);
if ((theErr == 0) && (value != 0)) {
theErr = CGLDescribeRenderer (rend, j, kCGLRPCompliant, &value);
if ((theErr == 0) && (value != 0)) {
theErr = CGLDescribeRenderer (rend, j, kCGLRPVideoMemory, &value);
if ((theErr == 0) && (value >= 10000000)) {
/*fprintf(stderr,"make it big\n");*/
CGLDestroyRendererInfo (rend);
macPrefState = 8;
return 1;
}
}
}
}
}
}
CGLDestroyRendererInfo (rend);
return 0;
}
#endif
static GHOST_SystemHandle g_system= 0;
/* Some simple ghost <-> blender conversions */
@ -251,6 +303,7 @@ Window *window_open(char *title, int posx, int posy, int sizex, int sizey, int s
inital_state= start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
#else // APPLE
inital_state= start_maximized?GHOST_kWindowStateMaximized:GHOST_kWindowStateNormal;
inital_state += macPrefState;
#endif
#endif

@ -109,12 +109,20 @@ extern char * build_type;
static void print_help();
static void print_version();
/* defined is ghostwinlay , we can't include carbon here, conflict with DNA */
#ifdef __APPLE
extern int checkAppleVideoCard();
#endif
/* for the callbacks: */
extern int pluginapi_force_ref(void); /* from blenpluginapi:pluginapi.c */
char bprogname[FILE_MAXDIR+FILE_MAXFILE]; /* from blenpluginapi:pluginapi.c */
/* Initialise callbacks for the modules that need them */
void setCallbacks(void);
@ -214,9 +222,18 @@ int main(int argc, char **argv)
argc= 1;
/* first let us check if we are hardware accelerated and with VRAM >= 16 Mo */
if (checkAppleVideoCard()) {
winlay_get_screensize(&scr_x, &scr_y);
/* let sneak under topbar */
setprefsize(1, 1, scr_x-2, scr_y-24);
} else {
/* 40 + 684 + (headers) 22 + 22 = 768, the powerbook screen height */
setprefsize(120, 40, 850, 684);
}
winlay_get_screensize(&scr_x, &scr_y);
winlay_process_events(0);
if (GHOST_HACK_getFirstFile(firstfilebuf)) {