[Bf-blender-cvs] [9b1a5b942cd] workspaces: Better fix for reading fullscreens from old files

Julian Eisel noreply at git.blender.org
Sun May 7 23:28:55 CEST 2017


Commit: 9b1a5b942cdcccbfe6209fa65be3df58c8de4bce
Author: Julian Eisel
Date:   Sun May 7 23:26:42 2017 +0200
Branches: workspaces
https://developer.blender.org/rB9b1a5b942cdcccbfe6209fa65be3df58c8de4bce

Better fix for reading fullscreens from old files

Old fix was rBe38481e53b84db. We now solve this in a nicer way by doing
all workspace versioning after lib-linking.

===================================================================

M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index de251d2b2d2..78e45cf9950 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -65,9 +65,6 @@ void BKE_workspace_layout_remove(
         struct Main *bmain,
         WorkSpace *workspace, WorkSpaceLayout *layout) ATTR_NONNULL();
 
-void BKE_workspace_layouts_transfer(
-        WorkSpace *workspace_dst, WorkSpace *workspace_src) ATTR_NONNULL();
-
 /* -------------------------------------------------------------------- */
 /* General Utils */
 
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index 4462833fe66..89535c02ba6 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -228,12 +228,6 @@ void BKE_workspace_layout_remove(
 	BLI_freelinkN(&workspace->layouts, layout);
 }
 
-void BKE_workspace_layouts_transfer(
-        WorkSpace *workspace_dst, WorkSpace *workspace_src)
-{
-	BLI_movelisttolist(&workspace_dst->layouts, &workspace_src->layouts);
-}
-
 /* -------------------------------------------------------------------- */
 /* General Utils */
 
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index a91dd3e7c18..b6c6381e251 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2786,9 +2786,6 @@ static void direct_link_cachefile(FileData *fd, CacheFile *cache_file)
 
 static void lib_link_workspaces(FileData *fd, Main *bmain)
 {
-	/* Note the NULL pointer checks for result of newlibadr. This is needed for reading old files from before the
-	 * introduction of workspaces (in do_versioning code we already created workspaces for screens of old file). */
-
 	BKE_WORKSPACE_ITER_BEGIN (workspace, bmain->workspaces.first) {
 		ID *id = BKE_workspace_id_get(workspace);
 		ListBase *layouts = BKE_workspace_layouts_get(workspace);
@@ -2798,15 +2795,13 @@ static void lib_link_workspaces(FileData *fd, Main *bmain)
 		BKE_WORKSPACE_LAYOUT_ITER_BEGIN (layout, layouts->first) {
 			bScreen *screen = newlibadr(fd, id->lib, BKE_workspace_layout_screen_get(layout));
 
-			if (screen) {
-				BKE_workspace_layout_screen_set(layout, screen);
+			BKE_workspace_layout_screen_set(layout, screen);
 
-				if (ID_IS_LINKED_DATABLOCK(id)) {
-					screen->winid = 0;
-					if (screen->temp) {
-						/* delete temp layouts when appending */
-						BKE_workspace_layout_remove(bmain, workspace, layout);
-					}
+			if (ID_IS_LINKED_DATABLOCK(id)) {
+				screen->winid = 0;
+				if (screen->temp) {
+					/* delete temp layouts when appending */
+					BKE_workspace_layout_remove(bmain, workspace, layout);
 				}
 			}
 		} BKE_WORKSPACE_LAYOUT_ITER_END;
@@ -6533,9 +6528,10 @@ static void lib_link_windowmanager(FileData *fd, Main *main)
 		if (wm->id.tag & LIB_TAG_NEED_LINK) {
 			/* Note: WM IDProperties are never written to file, hence no need to read/link them here. */
 			for (win = wm->windows.first; win; win = win->next) {
-				/* Note: WM IDProperties are never written to file, hence no need to read/link them here. */
+				if (win->workspace_hook) { /* NULL for old files */
+					lib_link_workspace_instance_hook(fd, win->workspace_hook, &wm->id);
+				}
 				win->scene = newlibadr(fd, wm->id.lib, win->scene);
-				lib_link_workspace_instance_hook(fd, win->workspace_hook, &wm->id);
 				/* deprecated, but needed for versioning (will be NULL'ed then) */
 				win->screen = newlibadr(fd, NULL, win->screen);
 			}
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 66b66a95cba..f8e8a3233c1 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/source/blender/blenloader/intern/versioning_280.c
@@ -53,103 +53,76 @@
 #include "MEM_guardedalloc.h"
 
 
-static bScreen *screen_parent_get(bScreen *screen)
+static bScreen *screen_parent_find(const bScreen *screen)
 {
-	for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
-		if (sa->full && sa->full != screen) {
-			return sa->full;
+	/* can avoid lookup if screen state isn't maximized/full (parent and child store the same state) */
+	if (ELEM(screen->state, SCREENMAXIMIZED, SCREENFULL)) {
+		for (const ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
+			if (sa->full && sa->full != screen) {
+				BLI_assert(sa->full->state == screen->state);
+				return sa->full;
+			}
 		}
 	}
+
 	return NULL;
 }
 
-/**
- * \brief Before lib-link versioning for new workspace design.
- *
- * Adds a workspace for each screen of the old file and adds the needed workspace-layout to wrap the screen.
- * Rest of the conversion is done in #do_version_workspaces_after_lib_link.
- *
- * Note that some of the created workspaces might be deleted again in case of reading the default startup.blend.
- */
-static void do_version_workspaces_before_lib_link(Main *main)
+static void do_version_workspaces_create_from_screens(Main *bmain)
 {
-	BLI_assert(BLI_listbase_is_empty(&main->workspaces));
-
-	for (bScreen *screen = main->screen.first; screen; screen = screen->id.next) {
-
-		// XXX, ideally we would use screen_get_unique_full here to avoid loading some screens.
-		// but we didn't link yet so we can't tell .
-
-		WorkSpace *ws = BKE_workspace_add(main, screen->id.name + 2);
-		BKE_workspace_layout_add(ws, screen, screen->id.name + 2);
-
-		/* For compatibility, the workspace should be activated that represents the active
-		 * screen of the old file. This is done in blo_do_versions_after_linking_270. */
-	}
-
-	for (wmWindowManager *wm = main->wm.first; wm; wm = wm->id.next) {
-		for (wmWindow *win = wm->windows.first; win; win = win->next) {
-			win->workspace_hook = BKE_workspace_instance_hook_create(main);
+	for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
+		const bScreen *screen_parent = screen_parent_find(screen);
+		WorkSpace *workspace;
+
+		if (screen_parent) {
+			/* fullscreen with "Back to Previous" option, don't create
+			 * a new workspace, add layout workspace containing parent */
+			workspace = BLI_findstring(
+			        &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
+		}
+		else {
+			workspace = BKE_workspace_add(bmain, screen->id.name + 2);
 		}
+		BKE_workspace_layout_add(workspace, screen, screen->id.name + 2);
+		BKE_workspace_render_layer_set(workspace, screen->scene->render_layers.first);
 	}
 }
 
 /**
  * \brief After lib-link versioning for new workspace design.
  *
+ *  *  Adds a workspace for (almost) each screen of the old file
+ *     and adds the needed workspace-layout to wrap the screen.
  *  *  Active screen isn't stored directly in window anymore, but in the active workspace.
- *     We already created a new workspace for each screen in #do_version_workspaces_before_lib_link,
- *     here we need to find and activate the workspace that contains the active screen of the old file.
  *  *  Active scene isn't stored in screen anymore, but in window.
+ *  *  Create workspace instance hook for each window.
+ *
+ * \note Some of the created workspaces might be deleted again in case of reading the default startup.blend.
  */
 static void do_version_workspaces_after_lib_link(Main *bmain)
 {
-	for (bScreen *screen = bmain->screen.first; screen; screen = screen->id.next) {
-		WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
-		BKE_workspace_render_layer_set(workspace, screen->scene->render_layers.first);
-	}
+	BLI_assert(BLI_listbase_is_empty(&bmain->workspaces));
 
-	bool has_temp_workspaces = false;
+	do_version_workspaces_create_from_screens(bmain);
 
 	for (wmWindowManager *wm = bmain->wm.first; wm; wm = wm->id.next) {
 		for (wmWindow *win = wm->windows.first; win; win = win->next) {
-			bScreen *screen = win->screen;
-			bScreen *screen_parent = screen_parent_get(screen);
+			bScreen *screen_parent = screen_parent_find(win->screen);
+			bScreen *screen = screen_parent ? screen_parent : win->screen;
 			WorkSpace *workspace = BLI_findstring(&bmain->workspaces, screen->id.name + 2, offsetof(ID, name) + 2);
-
-			if (screen_parent) {
-				WorkSpace *workspace_parent = BLI_findstring(
-				        &bmain->workspaces, screen_parent->id.name + 2, offsetof(ID, name) + 2);
-				BKE_workspace_layouts_transfer(workspace_parent, workspace);
-
-				workspace = workspace_parent;
-
-				has_temp_workspaces = true;
-			}
-
 			ListBase *layouts = BKE_workspace_layouts_get(workspace);
 
-			BKE_workspace_active_set(win->workspace_hook, workspace);
-			win->scene = screen->scene;
+			win->workspace_hook = BKE_workspace_instance_hook_create(bmain);
 
-			/* use last so the workspace_parent layout is used if it was added. */
-			BKE_workspace_active_layout_set(win->workspace_hook, layouts->last);
+			BKE_workspace_active_set(win->workspace_hook, workspace);
+			BKE_workspace_active_layout_set(win->workspace_hook, layouts->first);
 
+			win->scene = screen->scene;
 			/* Deprecated from now on! */
+			win->screen->scene = screen->scene = NULL;
 			win->screen = NULL;
-			screen->scene = NULL;
 		}
 	}
-
-	/* Cleanup workspaces from temp screens */
-	if (has_temp_workspaces) {
-		BKE_WORKSPACE_ITER_BEGIN (workspace, bmain->workspaces.first) {
-			ListBase *layouts = BKE_workspace_layouts_get((WorkSpace *)workspace);
-			if (BLI_listbase_is_empty(layouts)) {
-				BKE_workspace_remove(bmain, (WorkSpace *)workspace);
-			}
-		} BKE_WORKSPACE_ITER_END;
-	}
 }
 
 void do_versions_after_linking_280(Main *main)
@@ -377,11 +350,4 @@ void blo_do_versions_280(FileData *fd, Library *UNUSED(lib), Main *main)
 			}
 		}
 	}
-
-	{
-		/* New workspace design */
-		if (!DNA_struct_find(fd->filesdna, "WorkSpace")) {
-			do_version_workspaces_before_lib_link(main);
-		}
-	}
 }




More information about the Bf-blender-cvs mailing list