Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Window: Allow disabling minimize on focus loss
  • Loading branch information
dscharrer committed May 13, 2016
1 parent 4c0a034 commit 36f10c2
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/window/SDL1Window.cpp
Expand Up @@ -442,6 +442,15 @@ void SDL1Window::hide() {
onShow(false);
}

void SDL1Window::setMinimizeOnFocusLost(bool enabled) {
ARX_UNUSED(enabled);
// Not supported
}

Window::MinimizeSetting SDL1Window::willMinimizeOnFocusLost() {
return AlwaysEnabled;
}

InputBackend * SDL1Window::getInputBackend() {
if(!m_input) {
m_input = new SDL1InputBackend();
Expand Down
3 changes: 3 additions & 0 deletions src/window/SDL1Window.h
Expand Up @@ -45,6 +45,9 @@ class SDL1Window : public RenderWindow {

void hide();

void setMinimizeOnFocusLost(bool enabled);
MinimizeSetting willMinimizeOnFocusLost();

InputBackend * getInputBackend();

private:
Expand Down
23 changes: 23 additions & 0 deletions src/window/SDL2Window.cpp
Expand Up @@ -80,6 +80,7 @@ SDL2Window::SDL2Window()
: m_window(NULL)
, m_glcontext(NULL)
, m_input(NULL)
, m_minimizeOnFocusLost(AlwaysEnabled)
{
m_renderer = new OpenGLRenderer;
}
Expand Down Expand Up @@ -115,6 +116,17 @@ bool SDL2Window::initializeFramework() {
SDL_SetHint(SDL_HINT_NO_SIGNAL_HANDLERS, "1");
#endif

const char * minimize = SDL_GetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS);
if(minimize) {
if(*minimize == '0') {
m_minimizeOnFocusLost = AlwaysDisabled;
} else {
m_minimizeOnFocusLost = AlwaysEnabled;
}
} else {
m_minimizeOnFocusLost = Enabled;
}

arx_assert(s_mainWindow == NULL, "SDL only supports one window"); // TODO it supports multiple windows now!
arx_assert(m_displayModes.empty());

Expand Down Expand Up @@ -570,6 +582,17 @@ void SDL2Window::hide() {
onShow(false);
}

void SDL2Window::setMinimizeOnFocusLost(bool enabled) {
if(m_minimizeOnFocusLost != AlwaysDisabled && m_minimizeOnFocusLost != AlwaysEnabled) {
SDL_SetHint(SDL_HINT_VIDEO_MINIMIZE_ON_FOCUS_LOSS, enabled ? "1" : "0");
m_minimizeOnFocusLost = enabled ? Enabled : Disabled;
}
}

Window::MinimizeSetting SDL2Window::willMinimizeOnFocusLost() {
return m_minimizeOnFocusLost;
}

InputBackend * SDL2Window::getInputBackend() {
if(!m_input) {
m_input = new SDL2InputBackend(this);
Expand Down
5 changes: 5 additions & 0 deletions src/window/SDL2Window.h
Expand Up @@ -45,6 +45,9 @@ class SDL2Window : public RenderWindow {

void hide();

void setMinimizeOnFocusLost(bool enabled);
MinimizeSetting willMinimizeOnFocusLost();

InputBackend * getInputBackend();

private:
Expand All @@ -59,6 +62,8 @@ class SDL2Window : public RenderWindow {

SDL2InputBackend * m_input;

MinimizeSetting m_minimizeOnFocusLost;

static SDL2Window * s_mainWindow;

friend class SDL2InputBackend;
Expand Down
19 changes: 19 additions & 0 deletions src/window/Window.h
Expand Up @@ -75,6 +75,25 @@ class Window {
virtual void tick() = 0;

virtual void hide() = 0;

/*!
* Minimize the fullscreen windows if they lose focus.
* This setting may be overrriden by the environment,
* see \ref willMinimizeOnFocusLost().
*/
virtual void setMinimizeOnFocusLost(bool enabled) = 0;

enum MinimizeSetting {
Disabled,
Enabled,
AlwaysDisabled,
AlwaysEnabled
};

/*!
* Return if fullscreen windows if they lose focus.
*/
virtual MinimizeSetting willMinimizeOnFocusLost() = 0;

class Listener {

Expand Down

0 comments on commit 36f10c2

Please sign in to comment.