Skip to content

Commit

Permalink
Small fixup/cleanup to the handling of window flags
Browse files Browse the repository at this point in the history
* Merged the resolution keys into one pair
* Don't flag maximized off when switching to fullscreen. This fixes a case where
  toggling back from fullscreen on a maximized window wouldn't return to maximized
* Fixed a typo in the maximized getter
  • Loading branch information
Vultraz committed Mar 4, 2016
1 parent dc8e937 commit becdecd
Showing 1 changed file with 8 additions and 10 deletions.
18 changes: 8 additions & 10 deletions src/preferences.cpp
Expand Up @@ -106,9 +106,9 @@ base_manager::~base_manager()
}

#if SDL_VERSION_ATLEAST(2, 0, 0)
/*
/*
* Hook for setting window state variables on window resize and maximize
* events. Since there is no fullscreen window event, that setter is called
* events. Since there is no fullscreen window event, that setter is called
* from the CVideo function instead.
*/
void prefs_event_handler::handle_window_event(const SDL_Event& event)
Expand All @@ -129,7 +129,7 @@ void prefs_event_handler::handle_window_event(const SDL_Event& event)
break;

case SDL_WINDOWEVENT_RESTORED:
_set_maximized(false);
_set_maximized(fullscreen() || false);

break;
}
Expand Down Expand Up @@ -362,8 +362,7 @@ int min_allowed_height()

std::pair<int,int> resolution()
{
const std::string postfix = fullscreen() ? "resolution" : "windowsize";
std::string x = prefs['x' + postfix], y = prefs['y' + postfix];
const std::string& x = prefs["xresolution"], y = prefs["yresolution"];

if (!x.empty() && !y.empty()) {
return std::make_pair(
Expand All @@ -376,7 +375,7 @@ std::pair<int,int> resolution()

bool maximized()
{
return get("maximized", (fullscreen() & true));
return get("maximized", !fullscreen());
}

bool fullscreen()
Expand All @@ -386,9 +385,8 @@ bool fullscreen()

void _set_resolution(const std::pair<int, int>& res)
{
const std::string postfix = fullscreen() ? "resolution" : "windowsize";
preferences::set('x' + postfix, lexical_cast<std::string>(res.first));
preferences::set('y' + postfix, lexical_cast<std::string>(res.second));
preferences::set("xresolution", lexical_cast<std::string>(res.first));
preferences::set("yresolution", lexical_cast<std::string>(res.second));
}

void _set_maximized(bool ison)
Expand Down Expand Up @@ -424,7 +422,7 @@ void save_turbo_speed(const double speed)
{
prefs["turbo_speed"] = speed;
}

int font_scaling()
{
// Clip at 50 because if it's too low it'll cause crashes
Expand Down

0 comments on commit becdecd

Please sign in to comment.