From 965340a39c12cd62b3485b4a97c30984c62f6aaf Mon Sep 17 00:00:00 2001 From: Maarten ter Huurne Date: Fri, 16 Aug 2013 10:41:16 +0200 Subject: [PATCH] Fixed bug with launch screen and double buffering LinkApp::drawRun() assumes the layers below are already painted when it is called, but this was not the case. With single buffering, the previous frame was still there so it still looked good, but with double buffering the buffer typically contains an outdated screen. Long term I think the launch should happen at the outermost scope, so all destructors get a chance to run. This commit is a small step in that direction, by exiting the main loop before launching. --- src/gmenu2x.cpp | 19 +++++++++++++++++-- src/gmenu2x.h | 10 ++++++++++ src/linkapp.cpp | 6 ++---- src/linkapp.h | 5 +++-- 4 files changed, 32 insertions(+), 8 deletions(-) diff --git a/src/gmenu2x.cpp b/src/gmenu2x.cpp index 0446cdd..4e4ffdd 100644 --- a/src/gmenu2x.cpp +++ b/src/gmenu2x.cpp @@ -194,6 +194,7 @@ void GMenu2X::initCPULimits() { #endif GMenu2X::GMenu2X() + : appToLaunch(nullptr) { usbnet = samba = inet = web = false; useSelectionPng = false; @@ -589,8 +590,9 @@ void GMenu2X::main() { if (!fileExists(CARD_ROOT)) CARD_ROOT = ""; - bool quit = false; - while (!quit) { + appToLaunch = nullptr; + + while (true) { // Remove dismissed layers from the stack. for (auto it = layers.begin(); it != layers.end(); ) { if ((*it)->getStatus() == Layer::Status::DISMISSED) { @@ -610,6 +612,9 @@ void GMenu2X::main() { for (auto layer : layers) { layer->paint(*s); } + if (appToLaunch) { + break; + } s->flip(); // Handle touchscreen events. @@ -639,6 +644,11 @@ void GMenu2X::main() { } } } + + if (appToLaunch) { + appToLaunch->drawRun(); + appToLaunch->launch(fileToLaunch); + } } void GMenu2X::explorer() { @@ -662,6 +672,11 @@ void GMenu2X::explorer() { } } +void GMenu2X::queueLaunch(LinkApp *app, const std::string &file) { + appToLaunch = app; + fileToLaunch = file; +} + void GMenu2X::showHelpPopup() { layers.push_back(make_shared(*this)); } diff --git a/src/gmenu2x.h b/src/gmenu2x.h index 03e769c..dcb7157 100644 --- a/src/gmenu2x.h +++ b/src/gmenu2x.h @@ -39,6 +39,7 @@ class Font; class HelpPopup; class IconButton; class Layer; +class LinkApp; class MediaMonitor; class Menu; class Surface; @@ -72,6 +73,9 @@ private: std::shared_ptr menu; MediaMonitor *monitor; + LinkApp *appToLaunch; + std::string fileToLaunch; + std::vector> layers; /*! @@ -184,6 +188,12 @@ public: void setInputSpeed(); + /** + * Requests that the given application be launched. + * The launch won't happen immediately; it will happen after control + * returns to the main loop. + */ + void queueLaunch(LinkApp *app, const std::string &file); void saveSelection(); void writeConfig(); void writeSkinConfig(); diff --git a/src/linkapp.cpp b/src/linkapp.cpp index 1cea1ba..f6c6481 100644 --- a/src/linkapp.cpp +++ b/src/linkapp.cpp @@ -372,7 +372,7 @@ void LinkApp::start() { if (!selectordir.empty()) selector(); else - launch(); + gmenu2x->queueLaunch(this, ""); } void LinkApp::showManual() { @@ -547,13 +547,11 @@ void LinkApp::selector(int startSelection, const string &selectorDir) { selectordir = selectedDir; } gmenu2x->writeTmp(selection, selectedDir); - launch(selectedDir + sel.getFile()); + gmenu2x->queueLaunch(this, selectedDir + sel.getFile()); } } void LinkApp::launch(const string &selectedFile) { - drawRun(); - save(); if (isOpk()) { diff --git a/src/linkapp.h b/src/linkapp.h index f90850f..b0849b4 100644 --- a/src/linkapp.h +++ b/src/linkapp.h @@ -41,7 +41,6 @@ private: int iclock; std::string exec, params, workdir, manual, selectordir, selectorfilter, selectorscreens; bool selectorbrowser, editable; - void drawRun(); std::string aliasfile; std::string file; @@ -53,7 +52,6 @@ private: #endif void start(); - void launch(const std::string &selectedFile = ""); protected: virtual const std::string &searchIcon(); @@ -107,6 +105,9 @@ public: const std::string &getFile() { return file; } void renameFile(const std::string &name); + + void drawRun(); + void launch(const std::string &selectedFile); }; #endif