foxygit / doom Log in
commit fa5c42dc122c8171743b4ac0471571f3e4a49003
Author:     Simon Howard <fraggle@soulsphere.org>
AuthorDate: Sun Jan 8 21:05:15 2017 +0100
Commit:     Simon Howard <fraggle@soulsphere.org>
CommitDate: Sun Jan 8 21:05:15 2017 +0100

    video: Grab window move events and save display.

    When we move the game window to a different monitor we want to save
    that so that next time we start the game on the same monitor. So detect
    when the window is moved and update the new video_display config
    variable appropriately.

    Second part of #734.
---
 src/i_video.c | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/src/i_video.c b/src/i_video.c
index c787db31..106fab54 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -304,7 +304,7 @@ static void AdjustWindowSize(void)

 static void HandleWindowEvent(SDL_WindowEvent *event)
 {
-    int flags;
+    int i, flags;

     switch (event->event)
     {
@@ -361,6 +361,19 @@ static void HandleWindowEvent(SDL_WindowEvent *event)
             window_focused = false;
             break;

+        // We want to save the user's preferred monitor to use for running the
+        // game, so that next time we're run we start on the same display. So
+        // every time the window is moved, find which display we're now on and
+        // update the video_display config variable.
+
+        case SDL_WINDOWEVENT_MOVED:
+            i = SDL_GetWindowDisplayIndex(screen);
+            if (i >= 0)
+            {
+                video_display = i;
+            }
+            break;
+
         default:
             break;
     }