Fix: Filebrowser saving dialog size when maximized
authorDalai Felinto <dfelinto>
Fri, 15 Nov 2019 13:05:02 +0000 (10:05 -0300)
committerDalai Felinto <dfelinto@gmail.com>
Fri, 15 Nov 2019 15:10:16 +0000 (12:10 -0300)
Reviewed By: Severin

Differential Revision: https://developer.blender.org/D6260

source/blender/editors/include/ED_fileselect.h
source/blender/editors/space_file/filesel.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_window.c

index 83890c1621c0d1ae654e3f6e16a25e8cd37f5d86..85b9cf4657459a84f8e316b688fd31e427f8c605 100644 (file)
@@ -99,7 +99,9 @@ struct FileSelectParams *ED_fileselect_get_params(struct SpaceFile *sfile);
 
 short ED_fileselect_set_params(struct SpaceFile *sfile);
 void ED_fileselect_set_params_from_userdef(struct SpaceFile *sfile);
-void ED_fileselect_params_to_userdef(struct SpaceFile *sfile, int temp_win_size[]);
+void ED_fileselect_params_to_userdef(struct SpaceFile *sfile,
+                                     int temp_win_size[],
+                                     const bool is_maximized);
 
 void ED_fileselect_reset_params(struct SpaceFile *sfile);
 
@@ -130,6 +132,10 @@ void ED_fileselect_clear(struct wmWindowManager *wm, struct ScrArea *sa, struct
 
 void ED_fileselect_exit(struct wmWindowManager *wm, struct ScrArea *sa, struct SpaceFile *sfile);
 
+void ED_fileselect_window_params_get(const struct wmWindow *win,
+                                     int win_size[2],
+                                     bool *is_maximized);
+
 int ED_path_extension_type(const char *path);
 int ED_file_extension_icon(const char *path);
 
index 3776b660859ada446cedda097b7b3972303e3f84..1a8a8246eb96cb18bf3277d813fef6fec771669d 100644 (file)
@@ -327,6 +327,17 @@ short ED_fileselect_set_params(SpaceFile *sfile)
 /* The subset of FileSelectParams.flag items we store into preferences. */
 #define PARAMS_FLAGS_REMEMBERED (FILE_HIDE_DOT | FILE_SORT_INVERT)
 
+void ED_fileselect_window_params_get(const wmWindow *win, int win_size[2], bool *is_maximized)
+{
+  /* Get DPI/pixelsize independent size to be stored in preferences. */
+  WM_window_set_dpi(win); /* Ensure the DPI is taken from the right window. */
+
+  win_size[0] = WM_window_pixels_x(win) / UI_DPI_FAC;
+  win_size[1] = WM_window_pixels_y(win) / UI_DPI_FAC;
+
+  *is_maximized = WM_window_is_maximized(win);
+}
+
 void ED_fileselect_set_params_from_userdef(SpaceFile *sfile)
 {
   wmOperator *op = sfile->op;
@@ -359,7 +370,9 @@ void ED_fileselect_set_params_from_userdef(SpaceFile *sfile)
  * \param temp_win_size: If the browser was opened in a temporary window,
  * pass its size here so we can store that in the preferences. Otherwise NULL.
  */
-void ED_fileselect_params_to_userdef(SpaceFile *sfile, int temp_win_size[2])
+void ED_fileselect_params_to_userdef(SpaceFile *sfile,
+                                     int temp_win_size[2],
+                                     const bool is_maximized)
 {
   UserDef_FileSpaceData *sfile_udata_new = &U.file_space_data;
   UserDef_FileSpaceData sfile_udata_old = U.file_space_data;
@@ -370,7 +383,7 @@ void ED_fileselect_params_to_userdef(SpaceFile *sfile, int temp_win_size[2])
   sfile_udata_new->details_flags = sfile->params->details_flags;
   sfile_udata_new->flag = sfile->params->flag & PARAMS_FLAGS_REMEMBERED;
 
-  if (temp_win_size) {
+  if (temp_win_size && !is_maximized) {
     sfile_udata_new->temp_win_sizex = temp_win_size[0];
     sfile_udata_new->temp_win_sizey = temp_win_size[1];
   }
@@ -958,15 +971,16 @@ void ED_fileselect_exit(wmWindowManager *wm, ScrArea *sa, SpaceFile *sfile)
   }
   if (sfile->op) {
     wmWindow *temp_win = WM_window_is_temp_screen(wm->winactive) ? wm->winactive : NULL;
-    int win_size[2];
-
     if (temp_win) {
-      /* Get DPI/pixelsize independent size to be stored in preferences. */
-      WM_window_set_dpi(temp_win); /* Ensure the DPI is taken from the right window. */
-      win_size[0] = WM_window_pixels_x(temp_win) / UI_DPI_FAC;
-      win_size[1] = WM_window_pixels_y(temp_win) / UI_DPI_FAC;
+      int win_size[2];
+      bool is_maximized;
+
+      ED_fileselect_window_params_get(temp_win, win_size, &is_maximized);
+      ED_fileselect_params_to_userdef(sfile, win_size, is_maximized);
+    }
+    else {
+      ED_fileselect_params_to_userdef(sfile, NULL, false);
     }
-    ED_fileselect_params_to_userdef(sfile, temp_win ? win_size : NULL);
 
     WM_event_fileselect_event(wm, sfile->op, EVT_FILESELECT_EXTERNAL_CANCEL);
     sfile->op = NULL;
index f8b6b5171daeeab6b2f1ef2feec911c855fe80ee..b2fb77328c7375d9fa7e6aee4a103740b76c87ea 100644 (file)
@@ -111,6 +111,7 @@ int WM_window_pixels_y(const struct wmWindow *win);
 void WM_window_rect_calc(const struct wmWindow *win, struct rcti *r_rect);
 void WM_window_screen_rect_calc(const struct wmWindow *win, struct rcti *r_rect);
 bool WM_window_is_fullscreen(struct wmWindow *win);
+bool WM_window_is_maximized(struct wmWindow *win);
 
 void WM_windows_scene_data_sync(const ListBase *win_lb, struct Scene *scene) ATTR_NONNULL();
 struct Scene *WM_windows_scene_get_from_screen(const struct wmWindowManager *wm,
index 97fad9fcf59339375987bca094110ded4bfed5d2..7d150ad48fd9a8b874e253265ea9a1981d37e72e 100644 (file)
@@ -2401,13 +2401,9 @@ static int wm_handler_fileselect_do(bContext *C,
 
           if (screen->temp && (file_sa->spacetype == SPACE_FILE)) {
             int win_size[2];
-
-            /* Get DPI/pixelsize independent size to be stored in preferences. */
-            WM_window_set_dpi(temp_win); /* Ensure the DPI is taken from the right window. */
-            win_size[0] = WM_window_pixels_x(temp_win) / UI_DPI_FAC;
-            win_size[1] = WM_window_pixels_y(temp_win) / UI_DPI_FAC;
-
-            ED_fileselect_params_to_userdef(file_sa->spacedata.first, win_size);
+            bool is_maximized;
+            ED_fileselect_window_params_get(temp_win, win_size, &is_maximized);
+            ED_fileselect_params_to_userdef(file_sa->spacedata.first, win_size, is_maximized);
 
             if (BLI_listbase_is_single(&file_sa->spacedata)) {
               BLI_assert(ctx_win != temp_win);
@@ -2437,7 +2433,7 @@ static int wm_handler_fileselect_do(bContext *C,
         }
 
         if (!temp_win && ctx_sa->full) {
-          ED_fileselect_params_to_userdef(ctx_sa->spacedata.first, NULL);
+          ED_fileselect_params_to_userdef(ctx_sa->spacedata.first, NULL, false);
           ED_screen_full_prevspace(C, ctx_sa);
         }
       }
index fa2320585d78770e240b9d03d986f00b8b086633..020589dcf3da037d44d8f91001698c9cfc35063d 100644 (file)
@@ -2191,6 +2191,11 @@ bool WM_window_is_fullscreen(wmWindow *win)
   return win->windowstate == GHOST_kWindowStateFullScreen;
 }
 
+bool WM_window_is_maximized(wmWindow *win)
+{
+  return win->windowstate == GHOST_kWindowStateMaximized;
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */