Merge "Making window borders visible in WIN32" into emu-1.4-release
diff --git a/android/skin/qt/winsys-qt.cpp b/android/skin/qt/winsys-qt.cpp
index 9abdc70..2054ce9 100644
--- a/android/skin/qt/winsys-qt.cpp
+++ b/android/skin/qt/winsys-qt.cpp
@@ -217,6 +217,16 @@
     window->setWindowPos(x, y);
 }
 
+void skin_winsys_get_window_borders(int *left, int *right, int *top, int *bottom) {
+    // this function is for backward compatibility with SDL windows,
+    // where window border is not accounted for in window dimensions
+    // and is required when re-positioning windows in _WIN32
+    *left = *right = *top = *bottom = 0;
+
+    return;
+}
+
+
 extern void skin_winsys_set_window_title(const char *title)
 {
     D("skin_winsys_set_window_title [%s]", title);
diff --git a/android/skin/window.c b/android/skin/window.c
index d1e1276..eaf86fe 100644
--- a/android/skin/window.c
+++ b/android/skin/window.c
@@ -1293,13 +1293,15 @@
     if (!window->no_display && !skin_winsys_is_window_fully_visible()) {
         SkinRect monitor;
         int win_x, win_y, win_w, win_h;
+        int border_left, border_right, border_top, border_bottom;
         int new_x, new_y;
 
         skin_winsys_get_monitor_rect(&monitor);
 
         skin_winsys_get_window_pos(&win_x, &win_y);
-        win_w = skin_surface_width(window->surface);
-        win_h = skin_surface_height(window->surface);
+        skin_winsys_get_window_borders(&border_left, &border_right, &border_top, &border_bottom);
+        win_w = skin_surface_width(window->surface)  + border_left + border_right;
+        win_h = skin_surface_height(window->surface) + border_top + border_bottom;
 
         VERBOSE_PRINT(init, "Window was not fully visible: "
                 "monitor=[%d,%d,%d,%d] window=[%d,%d,%d,%d]",
@@ -1317,14 +1319,8 @@
         new_y = (monitor.size.h - win_h)/2;
 
         /* If it is still too large, we ensure the top-border is visible */
-        if (new_y < 0)
-            new_y = 0;
-#ifdef _WIN32
-        /* for windows, the title bar is about 30 pixels */
-        /* TODO: find a reliable way to get it */
-        if (new_y < 30)
-            new_y = 30;
-#endif
+        if (new_y < border_top)
+            new_y = border_top;
 
         VERBOSE_PRINT(init, "Window repositioned to [%d,%d]", new_x, new_y);
 
diff --git a/android/skin/winsys-sdl2.c b/android/skin/winsys-sdl2.c
index 55dc766..02e4f00 100644
--- a/android/skin/winsys-sdl2.c
+++ b/android/skin/winsys-sdl2.c
@@ -168,6 +168,21 @@
     }
 }
 
+void skin_winsys_get_window_borders(int *left, int *right, int *top, int *bottom) {
+#ifdef _WIN32
+    if (s_window) {
+        *left  = s_window_borders.left;
+        *right  = s_window_borders.right;
+        *top  = s_window_borders.top;
+        *bottom  = s_window_borders.bottom;
+    }
+#else
+    *left = *right = *top = *bottom = 0;
+#endif // _WIN32
+
+    return;
+}
+
 // Set window title.
 void skin_winsys_set_window_title(const char* title) {
     if (s_window) {
diff --git a/android/skin/winsys.h b/android/skin/winsys.h
index 378e4c2..895ffce 100644
--- a/android/skin/winsys.h
+++ b/android/skin/winsys.h
@@ -42,6 +42,9 @@
 // Get main window position.
 void skin_winsys_get_window_pos(int* window_x, int* window_y);
 
+// Get main window borders.
+void skin_winsys_get_window_borders(int *left, int *right, int *top, int *bottom);
+
 // Set window title.
 void skin_winsys_set_window_title(const char* title);