[Bf-blender-cvs] [9818bf0d56] temp-workspace-multi-window: Add WorkSpaceHook struct as bridge between workspace and window-manager

Julian Eisel noreply at git.blender.org
Sat Feb 25 00:11:50 CET 2017


Commit: 9818bf0d56ebd6ae694312abd50cd293b990679e
Author: Julian Eisel
Date:   Sat Feb 25 00:07:41 2017 +0100
Branches: temp-workspace-multi-window
https://developer.blender.org/rB9818bf0d56ebd6ae694312abd50cd293b990679e

Add WorkSpaceHook struct as bridge between workspace and window-manager

This way we can keep workspace and window-manager data separate and
further steps are made a bit easier.

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

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/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_270.c
M	source/blender/blenloader/intern/writefile.c
M	source/blender/depsgraph/intern/depsgraph_tag.cc
M	source/blender/editors/workspace/workspace_layout_edit.c
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 69d4066b3a..be05da62f4 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 WorkSpaceHook WorkSpaceHook;
 typedef struct WorkSpaceLayout WorkSpaceLayout;
 typedef struct WorkSpaceLayoutType WorkSpaceLayoutType;
 
@@ -60,6 +61,8 @@ WorkSpaceLayout *BKE_workspace_layout_add_from_type(WorkSpace *workspace, WorkSp
 WorkSpaceLayoutType *BKE_workspace_layout_type_add(WorkSpace *workspace, const char *name) ATTR_NONNULL();
 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();
+WorkSpaceHook *BKE_workspace_hook_new(void) ATTR_WARN_UNUSED_RESULT;
+void BKE_workspace_hook_delete(WorkSpaceHook *hook) ATTR_NONNULL();
 
 
 /* -------------------------------------------------------------------- */
@@ -127,6 +130,12 @@ void            BKE_workspace_layout_screen_set(WorkSpaceLayout *layout, struct
 WorkSpaceLayout *BKE_workspace_layout_next_get(const WorkSpaceLayout *layout) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 WorkSpaceLayout *BKE_workspace_layout_prev_get(const WorkSpaceLayout *layout) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 
+WorkSpace *BKE_workspace_active_get(const WorkSpaceHook *hook) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void BKE_workspace_active_set(WorkSpaceHook *hook, WorkSpace *workspace) ATTR_NONNULL(1);
+WorkSpace *BKE_workspace_active_delayed_get(const WorkSpaceHook *hook) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+void BKE_workspace_active_delayed_set(WorkSpaceHook *hook, WorkSpace *workspace) ATTR_NONNULL(1);
+struct ListBase *BKE_workspace_hook_layouts_get(WorkSpaceHook *workspace_hook) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+
 /* -------------------------------------------------------------------- */
 /* Don't use outside of BKE! */
 
diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index d4dd4887e3..d1ac491e4e 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 c14d03b24c..4ba48260d3 100644
--- a/source/blender/blenkernel/intern/image.c
+++ b/source/blender/blenkernel/intern/image.c
@@ -2542,7 +2542,8 @@ 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);
+			WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+			const bScreen *screen = BKE_workspace_active_screen_get(workspace);
 
 			for (ScrArea *sa = screen->areabase.first; sa; sa = sa->next) {
 				if (sa->spacetype == SPACE_VIEW3D) {
diff --git a/source/blender/blenkernel/intern/library_query.c b/source/blender/blenkernel/intern/library_query.c
index 04c3ae034b..5371ef7b9a 100644
--- a/source/blender/blenkernel/intern/library_query.c
+++ b/source/blender/blenkernel/intern/library_query.c
@@ -913,11 +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);
+					WorkSpace *workspace = BKE_workspace_active_get(win->workspace_hook);
+					ListBase *layouts = BKE_workspace_hook_layouts_get(win->workspace_hook);
+					ID *workspace_id = BKE_workspace_id_get(workspace);
 
 					CALLBACK_INVOKE(win->scene, IDWALK_CB_USER_ONE);
 
-					BKE_workspace_layout_iter_begin(layout, win->workspace_layouts.first)
+					BKE_workspace_layout_iter_begin(layout, layouts->first)
 					{
 						bScreen *screen = BKE_workspace_layout_screen_get(layout);
 
@@ -927,9 +929,9 @@ void BKE_library_foreach_ID_link(Main *bmain, ID *id, LibraryIDLinkCallback call
 					}
 					BKE_workspace_layout_iter_end;
 
-					CALLBACK_INVOKE_ID(workspace, IDWALK_CB_NOP);
+					CALLBACK_INVOKE_ID(workspace_id, IDWALK_CB_NOP);
 					/* allow callback to set a different workspace */
-					win->workspace = (WorkSpace *)workspace;
+					BKE_workspace_active_set(win->workspace_hook, (WorkSpace *)workspace_id);
 				}
 				break;
 			}
diff --git a/source/blender/blenkernel/intern/scene.c b/source/blender/blenkernel/intern/scene.c
index ec4f249914..06ef7a2688 100644
--- a/source/blender/blenkernel/intern/scene.c
+++ b/source/blender/blenkernel/intern/scene.c
@@ -1391,7 +1391,8 @@ 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 WorkSpace *workspace = BKE_workspace_active_get(window->workspace_hook);
+		const bScreen *screen = BKE_workspace_active_screen_get(workspace);
 
 		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 d3206b9ad3..d2efa9d0b1 100644
--- a/source/blender/blenkernel/intern/workspace.c
+++ b/source/blender/blenkernel/intern/workspace.c
@@ -141,6 +141,16 @@ void BKE_workspace_layout_remove(WorkSpace *workspace, WorkSpaceLayout *layout,
 	workspace_layout_type_remove(workspace, layout_type);
 }
 
+WorkSpaceHook *BKE_workspace_hook_new(void)
+{
+	return MEM_callocN(sizeof(WorkSpaceHook), __func__);
+}
+
+void BKE_workspace_hook_delete(WorkSpaceHook *hook)
+{
+	MEM_freeN(hook);
+}
+
 
 /* -------------------------------------------------------------------- */
 /* General Utils */
@@ -337,3 +347,26 @@ WorkSpaceLayout *BKE_workspace_layout_prev_get(const WorkSpaceLayout *layout)
 {
 	return layout->prev;
 }
+
+WorkSpace *BKE_workspace_active_get(const WorkSpaceHook *hook)
+{
+	return hook->act_workspace;
+}
+void BKE_workspace_active_set(WorkSpaceHook *hook, WorkSpace *workspace)
+{
+	hook->act_workspace = workspace;
+}
+
+WorkSpace *BKE_workspace_active_delayed_get(const WorkSpaceHook *hook)
+{
+	return hook->new_workspace;
+}
+void BKE_workspace_active_delayed_set(WorkSpaceHook *hook, WorkSpace *workspace)
+{
+	hook->new_workspace = workspace;
+}
+
+ListBase *BKE_workspace_hook_layouts_get(WorkSpaceHook *workspace_hook)
+{
+	return &workspace_hook->layouts;
+}
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 57fd99e3b5..3f643ba98b 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -2790,11 +2790,21 @@ static void direct_link_workspace(FileData *fd, WorkSpace *ws)
 	WorkSpaceLayout *act_layout = BKE_workspace_active_layout_get(ws);
 
 	link_list(fd, BKE_workspace_layouts_get(ws));
+	link_list(fd, BKE_workspace_layout_types_get(ws));
 
 	act_layout = newdataadr(fd, act_layout);
 	BKE_workspace_active_layout_set(ws, act_layout);
 }
 
+static void direct_link_workspace_hook(FileData *fd, WorkSpaceHook *hook)
+{
+	hook = newdataadr(fd, hook);
+	if (hook) {
+		ListBase *layouts = BKE_workspace_hook_layouts_get(hook);
+		link_list(fd, layouts);
+	}
+}
+
 /* ************ READ MOTION PATHS *************** */
 
 /* direct data for cache */
@@ -6368,9 +6378,10 @@ static void direct_link_windowmanager(FileData *fd, wmWindowManager *wm)
 		if (win->stereo3d_format) {
 			win->stereo3d_format->display_mode = S3D_DISPLAY_ANAGLYPH;
 		}
-		link_list(fd, &win->workspace_layouts);
+		win->workspace_hook = newdataadr(fd, win->workspace_hook);
+		direct_link_workspace_hook(fd, win->workspace_hook);
 	}
-	
+
 	BLI_listbase_clear(&wm->timers);
 	BLI_listbase_clear(&wm->operators);
 	BLI_listbase_clear(&wm->paintcursors);
@@ -6400,9 +6411,11 @@ static void lib_link_windowmanager(FileData *fd, Main *main)
 	for (wm = main->wm.first; wm; wm = wm->id.next) {
 		if (wm->id.tag & LIB_TAG_NEED_LINK) {
 			for (win = wm->windows.first; win; win = win->next) {
+				WorkSpace *workspace_new = newlibadr(fd, wm->id.lib, BKE_workspace_active_get(win->workspace_hook));
+
 				win->scene = newlibadr(fd, wm->id.lib, win->scene);
-				win->workspace = newlibadr(fd, wm->id.lib, win->workspace);
-				lib_link_workspace_layouts(fd, wm->id.lib, &win->workspace_layouts);
+				BKE_workspace_active_set(win->workspace_hook, workspace_new);
+				lib_link_workspace_layouts(fd, wm->id.lib, BKE_workspace_hook_layouts_get(win->workspace_hook));
 				/* deprecated, but needed for versioning (will be NULL'ed then) */
 				win->screen = newlibadr(fd, NULL, win->screen);
 			}
@@ -7048,9 +7061,11 @@ void blo_lib_link_restore(Main *newmain, wmWindowManager *curwm, Scene *curscene
 
 	for (wmWindow *win = curwm->windows.first; win; win = win->next) {
 		Scene *oldscene = win->scene;
-		WorkSpace *workspace = restore_pointer_by_name(id_map, (ID *)win->workspace, USER_REAL);
+		const ListBase *layouts = BKE_workspace_hook_layouts_get(win->workspace_hook);
+		WorkSpace *workspace_old = BKE_workspace_active_get(win->workspace_hook);
+		WorkSpace *workspace = restore_pointer_by_name(id_map, (ID *)workspace_old, USER_REAL);
 
-		BKE_workspace_layout_iter_begin(layout, win->workspace_layouts.first)
+		BKE_workspace_layout_iter_begin(layout, layouts->first)
 		{
 			lib_link_workspace_layout_restore(id_map, newmain, layout);
 		}
@@ -7060,7 +7075,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list