← Back to team overview

widelands-dev team mailing list archive

[Merge] lp:~widelands-dev/widelands/fsmenu_fullscreen_0_flicker into lp:widelands

 

GunChleoc has proposed merging lp:~widelands-dev/widelands/fsmenu_fullscreen_0_flicker into lp:widelands.

Commit message:
Stop fullscreen toggle from flickering.

Requested reviews:
  Widelands Developers (widelands-dev)
Related bugs:
  Bug #1459529 in widelands: "Fullscreen toggle with the f button doesn't work properly"
  https://bugs.launchpad.net/widelands/+bug/1459529

For more details, see:
https://code.launchpad.net/~widelands-dev/widelands/fsmenu_fullscreen_0_flicker/+merge/309277

The problem is that the SDL keypress event gets triggered multiple times for some reason, switching fullscreen mode on and off.
-- 
Your team Widelands Developers is requested to review the proposed merge of lp:~widelands-dev/widelands/fsmenu_fullscreen_0_flicker into lp:widelands.
=== modified file 'src/wlapplication.cc'
--- src/wlapplication.cc	2016-10-16 09:31:42 +0000
+++ src/wlapplication.cc	2016-10-25 15:46:19 +0000
@@ -289,7 +289,8 @@
 #else
      homedir_(FileSystem::get_homedir() + "/.widelands"),
 #endif
-     redirected_stdio_(false) {
+     redirected_stdio_(false),
+     last_resolution_change_(0) {
 	g_fs = new LayeredFileSystem();
 
 	parse_commandline(argc, argv);  // throws ParameterError, handled by main.cc
@@ -519,10 +520,14 @@
 			return true;
 
 		case SDLK_f: {
-			// toggle fullscreen
-			bool value = !g_gr->fullscreen();
-			g_gr->set_fullscreen(value);
-			g_options.pull_section("global").set_bool("fullscreen", value);
+			// Toggle fullscreen
+			const uint32_t time = SDL_GetTicks();
+			if (time - last_resolution_change_ > 250) {
+				last_resolution_change_ = time;
+				bool value = !g_gr->fullscreen();
+				g_gr->set_fullscreen(value);
+				g_options.pull_section("global").set_bool("fullscreen", value);
+			}
 			return true;
 		}
 

=== modified file 'src/wlapplication.h'
--- src/wlapplication.h	2016-10-16 09:31:42 +0000
+++ src/wlapplication.h	2016-10-25 15:46:19 +0000
@@ -261,6 +261,9 @@
 	std::string datadir_;
 	std::string datadir_for_testing_;
 
+	/// Prevent toggling fullscreen on and off from flickering
+	uint32_t last_resolution_change_;
+
 	/// Holds this process' one and only instance of WLApplication, if it was
 	/// created already. nullptr otherwise.
 	/// \note This is private on purpose. Read the class documentation.


Follow ups