From 73a4dd9435a6022ab1ef7d83de665a0313865003 Mon Sep 17 00:00:00 2001
From: John Robertson <jro@advops.com>
Date: Sat, 20 Dec 2025 14:55:40 -0700
Subject: [PATCH] The unit info widget can be mouse drag and dropped outside of
 the map view area, making it unreachable.

---
 client/gui-qt/hudwidget.cpp | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/client/gui-qt/hudwidget.cpp b/client/gui-qt/hudwidget.cpp
index 08522fc671..8a88066e17 100644
--- a/client/gui-qt/hudwidget.cpp
+++ b/client/gui-qt/hudwidget.cpp
@@ -596,6 +596,11 @@ void hud_units::update_actions(unit_list *punits)
   struct player *owner;
   struct tileset *tmp;
   struct unit *punit;
+  QPoint move_pnt(qRound(gui()->mapview_wdg->width()
+                    * gui()->qt_settings.unit_info_pos_fx),
+                  qRound((gui()->mapview_wdg->height()
+                    * gui()->qt_settings.unit_info_pos_fy)));
+  QRect parent_frame = this->parentWidget()->geometry();
 
   punit = head_of_units_in_focus();
   if (punit == nullptr) {
@@ -608,10 +613,11 @@ void hud_units::update_actions(unit_list *punits)
   setFixedHeight(parentWidget()->height() / 12);
   text_label.setFixedHeight((height() * 2) / 10);
 
-  move(qRound(gui()->mapview_wdg->width()
-        * gui()->qt_settings.unit_info_pos_fx),
-       qRound((gui()->mapview_wdg->height()
-        * gui()->qt_settings.unit_info_pos_fy)));
+  move_pnt.rx() = qMax(0, qMin(move_pnt.x(),
+                      parent_frame.width() - mw->frameRect().width()));
+  move_pnt.ry() = qMax(0, qMin(move_pnt.y(),
+                      parent_frame.height() - mw->frameRect().height()));
+  move(move_pnt);
   unit_icons->setFixedHeight((height() * 8) / 10);
 
   setUpdatesEnabled(false);
-- 
2.43.0

