[Bf-blender-cvs] [333719193a2] workspaces: Move window level workspace data into struct managed by workspace code

Julian Eisel noreply at git.blender.org
Mon Mar 13 23:23:26 CET 2017


Commit: 333719193a2436a91413664cd091261b23553dae
Author: Julian Eisel
Date:   Mon Mar 13 22:12:33 2017 +0100
Branches: workspaces
https://developer.blender.org/rB333719193a2436a91413664cd091261b23553dae

Move window level workspace data into struct managed by workspace code

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

M	source/blender/blenkernel/BKE_workspace.h
M	source/blender/blenkernel/intern/context.c
M	source/blender/blenkernel/intern/image.c
M	source/blender/blenkernel/intern/layer.c
M	source/blender/blenkernel/intern/library_query.c
M	source/blender/blenkernel/intern/scene.c
M	source/blender/blenkernel/intern/workspace.c
M	source/blender/blenloader/intern/readfile.c
M	source/blender/blenloader/intern/versioning_280.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/depsgraph_tag.cc
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesdna/dna_workspace_types.h
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/blenkernel/BKE_workspace.h b/source/blender/blenkernel/BKE_workspace.h
index 17e703718c9..7a09118b814 100644
--- a/source/blender/blenkernel/BKE_workspace.h
+++ b/source/blender/blenkernel/BKE_workspace.h
@@ -35,6 +35,7 @@ struct TransformOrientation;
 struct WorkSpace;
 
 typedef struct WorkSpace WorkSpace;
+typedef struct WorkSpaceInstanceHook WorkSpaceInstanceHook;
 typedef struct WorkSpaceLayout WorkSpaceLayout;
 
 /**
@@ -55,6 +56,9 @@ WorkSpace *BKE_workspace_add(struct Main *bmain, const char *name);
 void BKE_workspace_free(WorkSpace *ws);
 void BKE_workspace_remove(WorkSpace *workspace, struct Main *bmain);
 
+WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(void);
+void BKE_workspace_instance_hook_free(WorkSpaceInstanceHook *hook);
+
 struct WorkSpaceLayout *BKE_workspace_layout_add(WorkSpace *workspace, struct bScreen *screen) ATTR_NONNULL();
 void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout, struct Main *bmain) ATTR_NONNULL();
 
@@ -89,6 +93,10 @@ WorkSpaceLayout *BKE_workspace_layout_iter_circular(const WorkSpace *workspace,
 /* -------------------------------------------------------------------- */
 /* Getters/Setters */
 
+WorkSpace *BKE_workspace_temp_store_get(WorkSpaceInstanceHook *hook) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void       BKE_workspace_temp_store_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) ATTR_NONNULL(1);
+WorkSpace *BKE_workspace_active_get(WorkSpaceInstanceHook *hook) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void       BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace) ATTR_NONNULL(1);
 struct ID *BKE_workspace_id_get(WorkSpace *workspace);
 const char *BKE_workspace_name_get(const WorkSpace *workspace);
 WorkSpaceLayout *BKE_workspace_active_layout_get(const struct WorkSpace *ws) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index d4dd4887e3e..d1ac491e4e7 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -837,7 +837,7 @@ void CTX_wm_window_set(bContext *C, wmWindow *win)
 	if (C->wm.window) {
 		C->data.scene = C->wm.window->scene;
 	}
-	C->wm.workspace = (win) ? win->workspace : NULL;
+	C->wm.workspace = (win) ? BKE_workspace_active_get(win->workspace_hook) : NULL;
 	C->wm.screen = (win) ? BKE_workspace_active_screen_get(C->wm.workspace) : NULL;
 	C->wm.area = NULL;
 	C->wm.region = NULL;
diff --git a/source/blender/blenkernel/intern/image.c b/source/blender/blenkernel/intern/image.c
index c14d03b24c5..59810405849 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -2542,7 +2542,7 @@ void BKE_image_walk_all_users(const Main *mainp, void *customdata,
 	/* image window, compo node users */
 	for (wm = mainp->wm.first; wm; wm = wm->id.next) { /* only 1 wm */
 		for (win = wm->windows.first; win; win = win->next) {
-			const bScreen *screen = BKE_workspace_active_screen_get(win->workspace);
+			const bScreen *screen = BKE_workspace_active_screen_get(BKE_workspace_active_get(win->workspace_hook));
 
 			for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 				if (sa->spacetype == SPACE_VIEW3D) {
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
index 192cd19fec2..3ac81a5eccb 100644
--- a/source/blender/blenkernel/intern/layer.c
+++ b/source/blender/blenkernel/intern/layer.c
@@ -85,7 +85,7 @@ SceneLayer *BKE_scene_layer_context_active(const Scene *scene)
 	for (wmWindowManager *wm = G.main->wm.first; wm; wm = wm->id.next) {
 		for (wmWindow *win = wm->windows.first; win; win = win->next) {
 			if (win->scene == scene) {
-				return BKE_workspace_render_layer_get(win->workspace);
+				return BKE_workspace_render_layer_get(BKE_workspace_active_get(win->workspace_hook));
 			}
 		}
 	}
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index ec7b8557f44..184191f9e40 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -913,13 +913,13 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
 				wmWindowManager *wm = (wmWindowManager *)id;
 
 				for (wmWindow *win = wm->windows.first; win; win = win->next) {
-					ID *workspace = BKE_workspace_id_get(win->workspace);
+					ID *workspace = BKE_workspace_id_get(BKE_workspace_active_get(win->workspace_hook));
 
 					CALLBACK_INVOKE(win->scene, IDWALK_CB_USER_ONE);
 
 					CALLBACK_INVOKE_ID(workspace, IDWALK_CB_NOP);
 					/* allow callback to set a different workspace */
-					win->workspace = (WorkSpace *)workspace;
+					BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace);
 				}
 				break;
 			}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index b19936dea2c..7b95eea395f 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1404,7 +1404,7 @@ static bool check_rendered_viewport_visible(Main *bmain)
 	wmWindowManager *wm = bmain->wm.first;
 	wmWindow *window;
 	for (window = wm->windows.first; window != NULL; window = window->next) {
-		const bScreen *screen = BKE_workspace_active_screen_get(window->workspace);
+		const bScreen *screen = BKE_workspace_active_screen_get(BKE_workspace_active_get(window->workspace_hook));
 
 		for (ScrArea *area = screen->areabase.first; area != NULL; area = area->next) {
 			View3D *v3d = area->spacedata.first;
diff --git a/source/blender/blenkernel/intern/workspace.c b/source/blender/blenkernel/intern/workspace.c
index de3d929fbbe..293ceaddb4b 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -79,6 +79,14 @@ void BKE_workspace_remove(WorkSpace *workspace, Main *bmain)
 	BKE_libblock_free(bmain, workspace);
 }
 
+WorkSpaceInstanceHook *BKE_workspace_instance_hook_create(void)
+{
+	return MEM_callocN(sizeof(WorkSpaceInstanceHook), __func__);
+}
+void BKE_workspace_instance_hook_free(WorkSpaceInstanceHook *hook)
+{
+	MEM_freeN(hook);
+}
 
 /**
  * Add a new layout to \a workspace for \a screen.
@@ -192,6 +200,27 @@ WorkSpaceLayout *BKE_workspace_layout_iter_circular(const WorkSpace *workspace,
 /* -------------------------------------------------------------------- */
 /* Getters/Setters */
 
+/**
+ * Needed because we can't switch workspaces during handlers, it would break context.
+ */
+WorkSpace *BKE_workspace_temp_store_get(WorkSpaceInstanceHook *hook)
+{
+	return hook->temp_store;
+}
+void BKE_workspace_temp_store_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace)
+{
+	hook->temp_store = workspace;
+}
+
+WorkSpace *BKE_workspace_active_get(WorkSpaceInstanceHook *hook)
+{
+	return hook->active;
+}
+void BKE_workspace_active_set(WorkSpaceInstanceHook *hook, WorkSpace *workspace)
+{
+	hook->active = workspace;
+}
+
 ID *BKE_workspace_id_get(WorkSpace *workspace)
 {
 	return &workspace->id;
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index f71b5511c9f..c12e87613eb 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2773,6 +2773,12 @@ static void lib_link_workspaces(FileData *fd, Main *bmain)
 	BKE_workspace_iter_end;
 }
 
+static void lib_link_workspace_instance_hook(FileData *fd, WorkSpaceInstanceHook *hook, ID *id)
+{
+	WorkSpace *workspace = BKE_workspace_active_get(hook);
+	BKE_workspace_active_set(hook, newlibadr(fd, id->lib, workspace));
+}
+
 static void direct_link_workspace(FileData *fd, WorkSpace *ws)
 {
 	WorkSpaceLayout *act_layout = BKE_workspace_active_layout_get(ws);
@@ -2783,6 +2789,11 @@ static void direct_link_workspace(FileData *fd, WorkSpace *ws)
 	BKE_workspace_active_layout_set(ws, act_layout);
 }
 
+static void direct_link_workspace_instance_hook(FileData *fd, WorkSpaceInstanceHook *hook)
+{
+	UNUSED_VARS(fd, hook);
+}
+
 /* ************ READ MOTION PATHS *************** */
 
 /* direct data for cache */
@@ -6356,6 +6367,9 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
 	link_list(fd, &wm->windows);
 	
 	for (win = wm->windows.first; win; win = win->next) {
+		win->workspace_hook = newdataadr(fd, win->workspace_hook);
+		direct_link_workspace_instance_hook(fd, win->workspace_hook);
+
 		win->ghostwin = NULL;
 		win->eventstate = NULL;
 		win->curswin = NULL;
@@ -6420,7 +6434,7 @@ static void lib_link_windowmanager(FileData *fd, Main *main)
 		if (wm->id.tag & LIB_TAG_NEED_LINK) {
 			for (win = wm->windows.first; win; win = win->next) {
 				win->scene = newlibadr(fd, wm->id.lib, win->scene);
-				win->workspace = newlibadr(fd, wm->id.lib, win->workspace);
+				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);
 			}
@@ -7077,14 +7091,17 @@ void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene
 	BKE_workspace_iter_end;
 
 	for (wmWindow *win = curwm->windows.first; win; win = win->next) {
+		WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+		ID *workspace_id = BKE_workspace_id_get(workspace);
 		Scene *oldscene = win->scene;
-		WorkSpace *workspace = restore_pointer_by_name(id_map, (ID *)win->workspace, USER_REAL);
 
+		workspace = restore_pointer_by_name(id_map, workspace_id, USER_REAL);
+		BKE_workspace_active_set(win->workspace_hook, workspace);
 		win->scene = restore_pointer_by_name(id_map, (ID *)win->scene, USER_REAL);
 		if (win->scene == NULL) {
 			win->scene = curscene;
 		}
-		win->workspace = workspace;
+		BKE_workspace_active_set(win->workspace_hook, workspace);
 
 		/* keep cursor location through undo */
 		copy_v3_v3(win->scene->cursor, oldscene->cursor);
diff --git a/source/blender/blenloader/intern/versioning_280.c b/source/blender/blenloader/intern/versioning_280.c
index 432f10275af..736fadb5ed6 100644
--- a/source/blender/blenloader/intern/versioning_280.c
+++ b/s

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list