Let the minimap be hidden by other applications in focus

This commit is contained in:
2025-04-09 18:00:51 -05:00
parent 3ba9259482
commit 4041d0c1b2
3 changed files with 73 additions and 4 deletions

View File

@@ -544,9 +544,11 @@ void cDialog::run(std::function<void(cDialog&)> onopen){
if(onopen) onopen(*this);
animTimer.restart();
has_focus = true;
handle_events();
win.setVisible(false);
// Flush events on parent window from while this one was running
while(pollEvent(parentWin, currentEvent));
set_cursor(former_curs);
topWindow = formerTop;
@@ -625,6 +627,9 @@ void cDialog::handleTab(bool reverse) {
}
}
extern sf::RenderWindow& mini_map();
extern bool map_visible;
// This method handles one event received by the dialog.
void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter& fps_limiter) {
using Key = sf::Keyboard::Key;
@@ -737,10 +742,31 @@ void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter&
where = {(int)(currentEvent.mouseButton.x / get_ui_scale()), (int)(currentEvent.mouseButton.y / get_ui_scale())};
process_click(where, key.mod, fps_limiter);
break;
default: // To silence warning of unhandled enum values
case sf::Event::LostFocus:
has_focus = false;
setWindowFloating(mini_map(), false);
break;
case sf::Event::GainedFocus:
case sf::Event::MouseMoved:
if(!has_focus){
has_focus = true;
setWindowFloating(mini_map(), true);
makeFrontWindow(mainPtr());
if(map_visible)
makeFrontWindow(mini_map());
std::vector<sf::RenderWindow*> dialog_stack;
cDialog* next = this;
while(next != nullptr){
dialog_stack.push_back(&(next->win));
next = next->parent;
}
for(int i = dialog_stack.size() - 1; i >= 0; --i){
makeFrontWindow(*(dialog_stack[i]));
}
// that generates a LostFocus and a GainedFocus event
sf::Event evt;
while(pollEvent(win, evt));
}
case sf::Event::MouseMoved:{
// Did the window move, potentially dirtying the canvas below it?
if(check_window_moved(win, winLastX, winLastY))
if (redraw_everything != NULL)
@@ -755,6 +781,8 @@ void cDialog::handle_one_event(const sf::Event& currentEvent, cFramerateLimiter&
}
}
if(!inField) set_cursor(sword_curs);
}break;
default: // To silence warning of unhandled enum values
break;
}
}

View File

@@ -77,6 +77,7 @@ class cDialog : public iComponent, public iNameGiver {
static bool initCalled;
int anim_pict_fps = 2;
bool doAnimations;
bool has_focus = false;
public:
static void (*redraw_everything)();
/// Performs essential startup initialization. Generally should not be called directly.