Skip to content

Commit

Permalink
Mac OS X|Fixed: Prevented Cmd+Q in fullscreen mode
Browse files Browse the repository at this point in the history
  • Loading branch information
skyjake committed Mar 18, 2012
1 parent c81ea69 commit 0b7181e
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 11 deletions.
12 changes: 3 additions & 9 deletions doomsday/engine/mac/src/displaymode_macx.mm
Expand Up @@ -128,21 +128,17 @@ static int findIndex(const DisplayMode* mode)
return -1; // Invalid mode.
}

#define DISABLE_FADE

int DisplayMode_Native_Change(const DisplayMode* mode)
{
const CGDisplayFadeInterval fadeTime = .5f;

assert(mode);
assert(findIndex(mode) >= 0); // mode must be an enumerated one

#ifndef DISABLE_FADE
// Fade all displays to black.
CGDisplayFadeReservationToken token;
CGAcquireDisplayFadeReservation(kCGMaxDisplayReservationInterval, &token);
CGDisplayFade(token, fadeTime, kCGDisplayBlendNormal, kCGDisplayBlendSolidColor, 0, 0, 0, true /* wait */);
#endif

// Capture the displays now if haven't yet done so.
bool wasPreviouslyCaptured = true;
Expand All @@ -156,6 +152,8 @@ int DisplayMode_Native_Change(const DisplayMode* mode)
{
CFDictionaryRef current = currentModeDict();

qDebug() << "Changing to native mode" << findIndex(mode);

// Try to change.
result = CGDisplaySwitchToMode(kCGDirectMainDisplay, displayDicts[findIndex(mode)]);
if(result != kCGErrorSuccess)
Expand All @@ -166,13 +164,9 @@ int DisplayMode_Native_Change(const DisplayMode* mode)
}
}

/// @todo fade should wait when shutting down

#ifndef DISABLE_FADE
// Fade back to normal.
CGDisplayFade(token, fadeTime, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false /* don't wait */);
CGDisplayFade(token, 2*fadeTime, kCGDisplayBlendSolidColor, kCGDisplayBlendNormal, 0, 0, 0, false);
CGReleaseDisplayFadeReservation(token);
#endif

return result == kCGErrorSuccess;
}
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/canvaswindow.h
Expand Up @@ -46,6 +46,7 @@ class CanvasWindow : public QMainWindow
void setMoveFunc(void (*func)(CanvasWindow&));

// Events.
void closeEvent(QCloseEvent* ev);
void moveEvent(QMoveEvent* ev);
void hideEvent(QHideEvent* ev);

Expand Down
6 changes: 6 additions & 0 deletions doomsday/engine/portable/src/canvaswindow.cpp
Expand Up @@ -63,6 +63,12 @@ void CanvasWindow::setMoveFunc(void (*func)(CanvasWindow&))
d->moveFunc = func;
}

void CanvasWindow::closeEvent(QCloseEvent* ev)
{
/// @todo autosave and quit?
ev->ignore();
}

void CanvasWindow::moveEvent(QMoveEvent *ev)
{
QMainWindow::moveEvent(ev);
Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/portable/src/displaymode.cpp
Expand Up @@ -156,6 +156,8 @@ void DisplayMode_Shutdown(void)
{
if(!inited) return;

qDebug() << "Restoring original display mode due to shutdown.";

// Back to the original mode.
DisplayMode_Change(&originalMode);

Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/portable/src/window.cpp
Expand Up @@ -201,6 +201,7 @@ struct ddwindow_s
else
{
DisplayMode_Change(DisplayMode_OriginalMode());
widget->canvas().trapMouse(false);
}
}

Expand All @@ -213,6 +214,8 @@ struct ddwindow_s
{
assertWindow();

applyDisplayMode();

if(flags & DDWF_FULLSCREEN)
{
if(widget->isVisible()) widget->showFullScreen();
Expand Down Expand Up @@ -860,8 +863,6 @@ static Window* createWindow(ddwindowtype_t type, const char* title)
// Let's see if there are command line options overriding the previous state.
mainWindow.modifyAccordingToOptions();

mainWindow.applyDisplayMode();

// Make it so. (Not shown yet.)
mainWindow.applyWindowGeometry();

Expand Down

0 comments on commit 0b7181e

Please sign in to comment.