From e7afb4c7605c9b6ec02a59a059136844627ea164 Mon Sep 17 00:00:00 2001
From: Martin Vignali <martin.vignali@gmail.com>
Date: Sun, 8 Apr 2018 17:07:19 +0200
Subject: [PATCH 2/3] avdevice/sdl2 : add option for setting window position

---
 libavdevice/sdl2.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/libavdevice/sdl2.c b/libavdevice/sdl2.c
index e363df398d..c0996311a3 100644
--- a/libavdevice/sdl2.c
+++ b/libavdevice/sdl2.c
@@ -42,6 +42,8 @@ typedef struct {
     int window_width, window_height;  /**< size of the window */
     int window_fullscreen;
     int window_borderless;
+    int window_pos_x;
+    int window_pos_y;
 
     SDL_Texture *texture;
     int texture_fmt;
@@ -216,6 +218,10 @@ static int sdl2_write_header(AVFormatContext *s)
 
     SDL_SetWindowTitle(sdl->window, sdl->window_title);
 
+    if ((sdl->window_pos_x != INT_MAX)&&(sdl->window_pos_y != INT_MAX)) { /* custom position */
+        SDL_SetWindowPosition(sdl->window, sdl->window_pos_x, sdl->window_pos_y);
+    }
+
     sdl->texture = SDL_CreateTexture(sdl->renderer, sdl->texture_fmt, SDL_TEXTUREACCESS_STREAMING,
                                      codecpar->width, codecpar->height);
 
@@ -338,6 +344,8 @@ static const AVOption options[] = {
     { "window_size",       "set SDL window forced size", OFFSET(window_width), AV_OPT_TYPE_IMAGE_SIZE, { .str = NULL }, 0, 0, AV_OPT_FLAG_ENCODING_PARAM },
     { "window_fullscreen", "set SDL window fullscreen",  OFFSET(window_fullscreen), AV_OPT_TYPE_BOOL,  { .i64 = 0 },    0, 1, AV_OPT_FLAG_ENCODING_PARAM },
     { "window_borderless", "set SDL window border off",  OFFSET(window_borderless), AV_OPT_TYPE_BOOL,  { .i64 = 0 },    0, 1, AV_OPT_FLAG_ENCODING_PARAM },
+    { "window_pos_x", "set top left window position",  OFFSET(window_pos_x), AV_OPT_TYPE_INT, {.i64=INT_MAX}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
+    { "window_pos_y", "set top left window position", OFFSET(window_pos_y), AV_OPT_TYPE_INT, {.i64=INT_MAX}, INT_MIN, INT_MAX, AV_OPT_FLAG_ENCODING_PARAM },
     { NULL },
 };
 
-- 
2.14.3 (Apple Git-98)

