[Bf-blender-cvs] [5c0c1ef] workspaces: Fix layout changing when changing workspace

Julian Eisel noreply at git.blender.org
Sun Dec 4 21:51:33 CET 2016


Commit: 5c0c1ef8fa9aac50510256485b69f039cf29e790
Author: Julian Eisel
Date:   Sun Dec 4 00:51:21 2016 +0100
Branches: workspaces
https://developer.blender.org/rB5c0c1ef8fa9aac50510256485b69f039cf29e790

Fix layout changing when changing workspace

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

M	source/blender/blenkernel/intern/context.c
M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/interface/interface.c
M	source/blender/editors/screen/workspace_edit.c
M	source/blender/editors/space_view3d/space_view3d.c
M	source/blender/makesdna/DNA_windowmanager_types.h
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/WM_types.h
M	source/blender/windowmanager/intern/wm.c
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blenderplayer/bad_level_call_stubs/stubs.c

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

diff --git a/source/blender/blenkernel/intern/context.c b/source/blender/blenkernel/intern/context.c
index c55a2a9..f4ced80 100644
--- a/source/blender/blenkernel/intern/context.c
+++ b/source/blender/blenkernel/intern/context.c
@@ -833,7 +833,8 @@ void CTX_wm_manager_set(bContext *C, wmWindowManager *wm)
 void CTX_wm_window_set(bContext *C, wmWindow *win)
 {
 	C->wm.window = win;
-	C->wm.screen = (win) ? BKE_workspace_active_screen_get(win->workspace) : NULL;
+	C->wm.workspace = (win) ? win->workspace : NULL;
+	C->wm.screen = (win) ? BKE_workspace_active_screen_get(C->wm.workspace) : NULL;
 	if (C->wm.screen)
 		C->data.scene = C->wm.screen->scene;
 	C->wm.area = NULL;
@@ -843,10 +844,9 @@ void CTX_wm_window_set(bContext *C, wmWindow *win)
 void CTX_wm_workspace_set(bContext *C, WorkSpace *ws)
 {
 	C->wm.workspace = ws;
-	if (C->wm.workspace) {
-		C->wm.screen = BKE_workspace_active_screen_get(C->wm.workspace);
+	C->wm.screen = (C->wm.workspace) ? BKE_workspace_active_screen_get(C->wm.workspace) : NULL;
+	if (C->wm.screen)
 		C->data.scene = C->wm.screen->scene;
-	}
 	C->wm.area = NULL;
 	C->wm.region = NULL;
 }
diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 784b6ce..97a63c5 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -124,8 +124,8 @@ bool    ED_screen_stereo3d_required(const struct bScreen *screen);
 void    ED_screen_preview_render(const struct bScreen *screen, int size_x, int size_y, unsigned int *r_rect) ATTR_NONNULL();
 
 /* workspaces */
-void ED_workspace_change(struct wmWindow *win, WorkSpace *ws_new);
-bool ED_workspace_delete(struct Main *bmain, struct wmWindow *win, WorkSpace *ws);
+void ED_workspace_change(struct bContext *C, struct wmWindow *win, WorkSpace *ws_new);
+bool ED_workspace_delete(struct Main *bmain, const struct bContext *C, struct wmWindow *win, WorkSpace *ws);
 
 /* anim */
 void    ED_update_for_newframe(struct Main *bmain, struct Scene *scene, int mute);
diff --git a/source/blender/editors/interface/interface.c b/source/blender/editors/interface/interface.c
index 187f5c6..a447630 100644
--- a/source/blender/editors/interface/interface.c
+++ b/source/blender/editors/interface/interface.c
@@ -2781,7 +2781,8 @@ uiBlock *UI_block_begin(const bContext *C, ARegion *region, const char *name, sh
 		block->aspect = 2.0f / fabsf(getsizex * block->winmat[0][0]);
 	}
 	else {
-		bScreen *screen = WM_window_get_active_screen(window);
+		const bScreen *screen = WM_window_get_active_screen(window);
+
 		/* no subwindow created yet, for menus for example, so we
 		 * use the main window instead, since buttons are created
 		 * there anyway */
diff --git a/source/blender/editors/screen/workspace_edit.c b/source/blender/editors/screen/workspace_edit.c
index 104b02c..efc969b 100644
--- a/source/blender/editors/screen/workspace_edit.c
+++ b/source/blender/editors/screen/workspace_edit.c
@@ -43,31 +43,17 @@
  * \brief API for managing workspaces and their data.
  * \{ */
 
-static void workspace_unassign_window_workspace(wmWindow *win)
-{
-	win->workspace = NULL; /* just for safty, should always be set */
-}
-
-/**
- * \note Should either be called to initially assign workspace or after calling #workspace_unassign_window_workspace.
- */
-static void workspace_assign_to_window(wmWindow *win, WorkSpace *ws)
-{
-	BLI_assert(win->workspace == NULL);
-	win->workspace = ws;
-}
 
-void ED_workspace_change(wmWindow *win, WorkSpace *ws_new)
+void ED_workspace_change(bContext *C, wmWindow *win, WorkSpace *ws_new)
 {
-	workspace_unassign_window_workspace(win);
-	workspace_assign_to_window(win, ws_new);
-	/* TODO: send notifier */
+	win->workspace = ws_new;
+	ED_screen_set(C, win->workspace->act_layout->screen);
 }
 
 /**
  * \return if succeeded.
  */
-bool ED_workspace_delete(Main *bmain, wmWindow *win, WorkSpace *ws)
+bool ED_workspace_delete(Main *bmain, const bContext *C, wmWindow *win, WorkSpace *ws)
 {
 	if (BLI_listbase_is_single(&bmain->workspaces)) {
 		return false;
@@ -75,7 +61,7 @@ bool ED_workspace_delete(Main *bmain, wmWindow *win, WorkSpace *ws)
 
 	if (win->workspace == ws) {
 		WorkSpace *fallback_ws = ws->id.prev ? ws->id.prev : ws->id.next;
-		ED_workspace_change(win, fallback_ws);
+		ED_workspace_change(C, win, fallback_ws);
 	}
 	BKE_libblock_free(bmain, &ws->id);
 
@@ -96,7 +82,7 @@ static int workspace_new_exec(bContext *C, wmOperator *UNUSED(op))
 	WorkSpace *old_ws = win->workspace;
 	WorkSpace *new_ws = BKE_workspace_duplicate(bmain, old_ws);
 
-	ED_workspace_change(win, new_ws);
+	ED_workspace_change(C, win, new_ws);
 
 	return OPERATOR_FINISHED;
 }
@@ -118,7 +104,7 @@ static int workspace_delete_exec(bContext *C, wmOperator *UNUSED(op))
 	Main *bmain = CTX_data_main(C);
 	wmWindow *win = CTX_wm_window(C);
 
-	ED_workspace_delete(bmain, win, win->workspace);
+	ED_workspace_delete(bmain, C, win, win->workspace);
 
 	return OPERATOR_FINISHED;
 }
diff --git a/source/blender/editors/space_view3d/space_view3d.c b/source/blender/editors/space_view3d/space_view3d.c
index 07daeef..0fb899d 100644
--- a/source/blender/editors/space_view3d/space_view3d.c
+++ b/source/blender/editors/space_view3d/space_view3d.c
@@ -1012,13 +1012,13 @@ static void view3d_main_region_listener(bScreen *sc, ScrArea *sa, ARegion *ar, w
 				case ND_SKETCH:
 					ED_region_tag_redraw(ar);
 					break;
-				case ND_SCREENBROWSE:
+//				case ND_SCREENBROWSE:
 				case ND_SCREENDELETE:
 				case ND_SCREENSET:
 					/* screen was changed, need to update used layers due to NC_SCENE|ND_LAYER_CONTENT */
 					/* updates used layers only for View3D in active screen */
 					if (wmn->reference) {
-						const bScreen *sc_ref = BKE_workspace_layout_screen_get(wmn->reference);
+						const bScreen *sc_ref = wmn->reference;
 						view3d_recalc_used_layers(ar, wmn, sc_ref->scene);
 					}
 					ED_region_tag_redraw(ar);
diff --git a/source/blender/makesdna/DNA_windowmanager_types.h b/source/blender/makesdna/DNA_windowmanager_types.h
index b4ac014..397e237 100644
--- a/source/blender/makesdna/DNA_windowmanager_types.h
+++ b/source/blender/makesdna/DNA_windowmanager_types.h
@@ -179,6 +179,7 @@ typedef struct wmWindow {
 
 	struct bScreen *screen DNA_DEPRECATED;
 	struct WorkSpace *workspace; /* active workspace */
+	struct WorkSpace *new_workspace; /* temporary when switching */
 	char screenname[64];         /* MAX_ID_NAME for matching window with active screen after file read */
 
 	short posx, posy, sizex, sizey;  /* window coords */
diff --git a/source/blender/makesrna/intern/rna_wm.c b/source/blender/makesrna/intern/rna_wm.c
index 04e8d83..f2d64a7 100644
--- a/source/blender/makesrna/intern/rna_wm.c
+++ b/source/blender/makesrna/intern/rna_wm.c
@@ -626,8 +626,27 @@ static PointerRNA rna_PieMenu_layout_get(PointerRNA *ptr)
 static void rna_Window_workspace_set(PointerRNA *ptr, PointerRNA value)
 {
 	wmWindow *win = (wmWindow *)ptr->data;
-	WorkSpace *ws_new = value.data;
-	ED_workspace_change(win, ws_new);
+
+	if (WM_window_is_temp_screen(win)) {
+		return;
+	}
+	if (value.data == NULL) {
+		return;
+	}
+
+	win->new_workspace = value.data;
+}
+
+static void rna_Window_workspace_update(bContext *C, PointerRNA *ptr)
+{
+	wmWindow *win = ptr->data;
+
+	/* exception: can't set screens inside of area/region handlers,
+	 * and must use context so notifier gets to the right window */
+	if (win->new_workspace) {
+		WM_event_add_notifier(C, NC_SCREEN | ND_WORKSPACE_SET, win->new_workspace);
+		win->new_workspace = NULL;
+	}
 }
 
 static PointerRNA rna_KeyMapItem_properties_get(PointerRNA *ptr)
@@ -1886,9 +1905,9 @@ static void rna_def_window(BlenderRNA *brna)
 	RNA_def_property_flag(prop, PROP_NEVER_NULL);
 	RNA_def_property_struct_type(prop, "WorkSpace");
 	RNA_def_property_ui_text(prop, "Workspace", "Active workspace showing in the window");
-	RNA_def_property_flag(prop, PROP_EDITABLE);
 	RNA_def_property_pointer_funcs(prop, NULL, "rna_Window_workspace_set", NULL, NULL);
-//	RNA_def_property_update(prop, 0, NULL); /* TODO own notifier? */
+	RNA_def_property_flag(prop, PROP_EDITABLE | PROP_CONTEXT_UPDATE);
+	RNA_def_property_update(prop, 0, "rna_Window_workspace_update");
 
 	prop = RNA_def_property(srna, "x", PROP_INT, PROP_NONE);
 	RNA_def_property_int_sdna(prop, NULL, "posx");
diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h
index 99b7775..92f782a 100644
--- a/source/blender/windowmanager/WM_api.h
+++ b/source/blender/windowmanager/WM_api.h
@@ -101,7 +101,7 @@ int			WM_window_pixels_x		(struct wmWindow *win);
 int			WM_window_pixels_y		(struct wmWindow *win);
 bool		WM_window_is_fullscreen	(struct wmWindow *win);
 
-struct Scene *WM_window_get_active_scene(const struct wmWindow *win) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
+struct Scene   *WM_window_get_active_scene(const struct wmWindow *win) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 struct bScreen *WM_window_get_active_screen(const struct wmWindow *win) ATTR_NONNULL() ATTR_WARN_UNUSED_RESULT;
 void            WM_window_set_active_screen(struct wmWindow *win, struct bScreen *screen) ATTR_NONNULL(1);
 bool WM_window_is_temp_screen(const struct wmWindow *win) ATTR_WARN_UNUSED_RESULT;
diff --git a/source/blender/windowmanager/WM_types.h b/source/blender/windowmanager/WM_types.h
index f51b6b2..046f115 100644
--- a/source/blender/windowmanager/WM_types.h
+++ b/source/blender/windowmanager/WM_types.h
@@ -267,6 +267,7 @@ typedef struct wmNotifier {
 #define ND_EDITOR_CHANGED	(6<<16) /*sent to new editors after switching to them*/
 #define ND_SCREENSET		(7<<16)
 #define ND_SKETCH			(8<<16)
+#define ND_WORKSPACE_SET	(9<<16)
 
 	/* NC_SCENE Scene */
 #define ND_SCENEBROWSE		(1<<16)
diff --git a/source/blender/windowmanager/intern/wm.c b/source/blender/windowmanager/intern/wm.c
index 1a21223..de02b3f 100644
--- a/source/blender/windowmanager/intern/wm.c
+++ b/source/blender/windowmanager/intern/wm.c
@@ -442,7 +442,7 @@ void wm_close_and_free(bContext *C, wmWindowManager *wm)
 		wm_autosave_timer_ended(wm);
 
 	while ((win = BLI_pophead(&wm->windows))) {
-		ED_workspace_change(win, NULL);
+		ED_workspace_change(C, win, NULL);
 		wm_draw_window_clear(win);
 		wm_window

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list