Fix T59137: Prefs moves header to bottom
authorCampbell Barton <ideasman42@gmail.com>
Thu, 13 Dec 2018 22:07:22 +0000 (09:07 +1100)
committerCampbell Barton <ideasman42@gmail.com>
Thu, 13 Dec 2018 22:09:41 +0000 (09:09 +1100)
Only use a new spaces header alignment when no previous header exists.

source/blender/editors/include/ED_screen.h
source/blender/editors/screen/area.c

index a5660c434164b304366c2c89309a961c2c5efdc2..ce0c9468d1e59f8ac9b83c61d5fd95c3064f4c03 100644 (file)
@@ -149,6 +149,7 @@ void    ED_area_newspace(struct bContext *C, ScrArea *sa, int type, const bool s
 void    ED_area_prevspace(struct bContext *C, ScrArea *sa);
 void    ED_area_swapspace(struct bContext *C, ScrArea *sa1, ScrArea *sa2);
 int     ED_area_headersize(void);
+int     ED_area_header_alignment_or_fallback(const ScrArea *area, int fallback);
 int     ED_area_header_alignment(const ScrArea *area);
 int     ED_area_global_size_y(const ScrArea *area);
 int     ED_area_global_min_size_y(const ScrArea *area);
index 3eecab46aa541eede983d898583b83723fe24c56..dd7b6fe5ce11ec42d1b07fd5f0f1c2fbe3662648 100644 (file)
@@ -1816,11 +1816,17 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
                /* When the user switches between space-types from the type-selector,
                 * changing the header-type is jarring (especially when using Ctrl-MouseWheel).
                 *
-                * However, add-on install for example -forces the header to the top which shouldn't
+                * However, add-on install for exampleforces the header to the top which shouldn't
                 * be applied back to the previous space type when closing - see: T57724
+                *
+                * Newly created windows wont have any space data, use the alignment
+                * the space type defaults to in this case instead
+                * (needed for preferences to have space-type on bottom).
                 */
-               const bool sync_header_alignment = (sa->flag & AREA_FLAG_TEMP_TYPE) == 0;
-               int header_alignment = ED_area_header_alignment(sa);
+               int header_alignment = ED_area_header_alignment_or_fallback(sa, -1);
+               const bool sync_header_alignment = (
+                       (header_alignment != -1) &&
+                       (sa->flag & AREA_FLAG_TEMP_TYPE) == 0);
 
                /* in some cases (opening temp space) we don't want to
                 * call area exit callback, so we temporarily unset it */
@@ -1869,17 +1875,6 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
                        /* put in front of list */
                        BLI_remlink(&sa->spacedata, sl);
                        BLI_addhead(&sa->spacedata, sl);
-
-
-                       /* Sync header alignment. */
-                       if (sync_header_alignment) {
-                               for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
-                                       if (ar->regiontype == RGN_TYPE_HEADER) {
-                                               ar->alignment = header_alignment;
-                                               break;
-                                       }
-                               }
-                       }
                }
                else {
                        /* new space */
@@ -1897,6 +1892,16 @@ void ED_area_newspace(bContext *C, ScrArea *sa, int type, const bool skip_ar_exi
                        }
                }
 
+               /* Sync header alignment. */
+               if (sync_header_alignment) {
+                       for (ARegion *ar = sa->regionbase.first; ar; ar = ar->next) {
+                               if (ar->regiontype == RGN_TYPE_HEADER) {
+                                       ar->alignment = header_alignment;
+                                       break;
+                               }
+                       }
+               }
+
                ED_area_initialize(CTX_wm_manager(C), win, sa);
 
                /* tell WM to refresh, cursor types etc */
@@ -2498,16 +2503,19 @@ int ED_area_headersize(void)
        return (int)(HEADERY * UI_DPI_FAC);
 }
 
-
-int ED_area_header_alignment(const ScrArea *area)
+int ED_area_header_alignment_or_fallback(const ScrArea *area, int fallback)
 {
        for (ARegion *ar = area->regionbase.first; ar; ar = ar->next) {
                if (ar->regiontype == RGN_TYPE_HEADER) {
                        return ar->alignment;
                }
        }
+       return fallback;
+}
 
-       return RGN_ALIGN_TOP;
+int ED_area_header_alignment(const ScrArea *area)
+{
+       return ED_area_header_alignment_or_fallback(area, RGN_ALIGN_TOP);
 }
 
 /**