[Bf-blender-cvs] [8bfc10c] HMD_viewport: Make HMD window a proper 'restricted' window

Julian Eisel noreply at git.blender.org
Sat Nov 19 13:38:52 CET 2016


Commit: 8bfc10ce66d799771e4e5301053e4a84fc14e920
Author: Julian Eisel
Date:   Sat Nov 19 13:33:12 2016 +0100
Branches: HMD_viewport
https://developer.blender.org/rB8bfc10ce66d799771e4e5301053e4a84fc14e920

Make HMD window a proper 'restricted' window

A restricted window is a new concept that doesn't allow changing the screen of a window in any way. This way we can ensure the HMD window is only used for displaying the 3D View, so users can't accidentally change it without knowing how to get back. This also fixes some issues we had when using temp screens like they're used for UserPrefs.
Fixes:
* Could open toolbar/properties in HMD view
* HMD window used when opening UserPrefs through menu/shortcut
* Could easily change editor to non-3D-View

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

M	source/blender/editors/include/ED_screen.h
M	source/blender/editors/render/render_view.c
M	source/blender/editors/screen/area.c
M	source/blender/editors/screen/screen_edit.c
M	source/blender/editors/screen/screen_ops.c
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_screen.c
M	source/blender/makesrna/intern/rna_wm.c
M	source/blender/windowmanager/WM_api.h
M	source/blender/windowmanager/intern/wm_event_system.c
M	source/blender/windowmanager/intern/wm_files.c
M	source/blender/windowmanager/intern/wm_operators.c
M	source/blender/windowmanager/intern/wm_window.c

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

diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h
index 6a558d1..70adcfd 100644
--- a/source/blender/editors/include/ED_screen.h
+++ b/source/blender/editors/include/ED_screen.h
@@ -118,6 +118,7 @@ void    ED_screen_full_restore(struct bContext *C, ScrArea *sa);
 struct ScrArea *ED_screen_state_toggle(struct bContext *C, struct wmWindow *win, struct ScrArea *sa, const short state);
 void    ED_screens_header_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
 bool    ED_screen_stereo3d_required(struct bScreen *screen);
+bool    ED_screen_is_editable(const struct bScreen *screen);
 
 /* anim */
 void    ED_update_for_newframe(struct Main *bmain, struct Scene *scene, int mute);
diff --git a/source/blender/editors/render/render_view.c b/source/blender/editors/render/render_view.c
index 65f0fec..235d805 100644
--- a/source/blender/editors/render/render_view.c
+++ b/source/blender/editors/render/render_view.c
@@ -54,9 +54,8 @@
 /* returns biggest area that is not uv/image editor. Note that it uses buttons */
 /* window as the last possible alternative.									   */
 /* would use BKE_screen_find_big_area(...) but this is too specific            */
-static ScrArea *biggest_non_image_area(bContext *C)
+static ScrArea *biggest_non_image_area(const bScreen *sc)
 {
-	bScreen *sc = CTX_wm_screen(C);
 	ScrArea *sa, *big = NULL;
 	int size, maxsize = 0, bwmaxsize = 0;
 	short foundwin = 0;
@@ -181,7 +180,9 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
 	}
 
 	if (!sa) {
+		bScreen *screen = CTX_wm_screen(C);
 		sa = find_area_showing_r_result(C, scene, &win);
+
 		if (sa == NULL)
 			sa = find_area_image_empty(C);
 		
@@ -189,9 +190,9 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
 		if (win && win != CTX_wm_window(C))
 			wm_window_raise(win);
 
-		if (sa == NULL) {
+		if (sa == NULL && ED_screen_is_editable(screen)) {
 			/* find largest open non-image area */
-			sa = biggest_non_image_area(C);
+			sa = biggest_non_image_area(screen);
 			if (sa) {
 				ED_area_newspace(C, sa, SPACE_IMAGE, true);
 				sima = sa->spacedata.first;
@@ -206,7 +207,7 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
 			}
 			else {
 				/* use any area of decent size */
-				sa = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TYPE_ANY, 0);
+				sa = BKE_screen_find_big_area(screen, SPACE_TYPE_ANY, 0);
 				if (sa->spacetype != SPACE_IMAGE) {
 					// XXX newspace(sa, SPACE_IMAGE);
 					sima = sa->spacedata.first;
@@ -216,6 +217,11 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
 				}
 			}
 		}
+		else if (!sa) {
+			/* Could also search in other screens. */
+			BKE_report(reports, RPT_ERROR, "Can't show render result in current screen.");
+			return NULL;
+		}
 	}
 	sima = sa->spacedata.first;
 
@@ -255,7 +261,7 @@ static int render_view_cancel_exec(bContext *C, wmOperator *UNUSED(op))
 	}
 
 	/* test if we have a temp screen in front */
-	if (win->screen->temp) {
+	if (win->screen->type == SCREEN_TYPE_TEMP) {
 		wm_window_lower(win);
 		return OPERATOR_FINISHED;
 	}
@@ -301,7 +307,7 @@ static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *e
 	wmWindow *wincur = CTX_wm_window(C);
 	
 	/* test if we have currently a temp screen active */
-	if (wincur->screen->temp) {
+	if (wincur->screen->type == SCREEN_TYPE_TEMP) {
 		wm_window_lower(wincur);
 	}
 	else {
@@ -311,7 +317,7 @@ static int render_view_show_invoke(bContext *C, wmOperator *op, const wmEvent *e
 		/* is there another window on current scene showing result? */
 		for (win = CTX_wm_manager(C)->windows.first; win; win = win->next) {
 			bScreen *sc = win->screen;
-			if ((sc->temp && ((ScrArea *)sc->areabase.first)->spacetype == SPACE_IMAGE) ||
+			if (((sc->type == SCREEN_TYPE_TEMP) && ((ScrArea *)sc->areabase.first)->spacetype == SPACE_IMAGE) ||
 			    (win == winshow && winshow != wincur))
 			{
 				wm_window_raise(win);
diff --git a/source/blender/editors/screen/area.c b/source/blender/editors/screen/area.c
index e6bb604..a1a96fb 100644
--- a/source/blender/editors/screen/area.c
+++ b/source/blender/editors/screen/area.c
@@ -1529,7 +1529,11 @@ void ED_region_cursor_set(wmWindow *win, ScrArea *sa, ARegion *ar)
 void region_toggle_hidden(bContext *C, ARegion *ar, const bool do_fade)
 {
 	ScrArea *sa = CTX_wm_area(C);
-	
+
+	if (!ED_screen_is_editable(CTX_wm_screen(C))) {
+		return;
+	}
+
 	ar->flag ^= RGN_FLAG_HIDDEN;
 	
 	if (do_fade && ar->overlap) {
diff --git a/source/blender/editors/screen/screen_edit.c b/source/blender/editors/screen/screen_edit.c
index 5cd0d33..fe61523 100644
--- a/source/blender/editors/screen/screen_edit.c
+++ b/source/blender/editors/screen/screen_edit.c
@@ -1344,7 +1344,7 @@ void ED_screen_exit(bContext *C, wmWindow *window, bScreen *screen)
 	/* mark it available for use for other windows */
 	screen->winid = 0;
 	
-	if (prevwin->screen->temp == 0) {
+	if (prevwin->screen->type == SCREEN_TYPE_NORMAL) {
 		/* use previous window if possible */
 		CTX_wm_window_set(C, prevwin);
 	}
@@ -1495,7 +1495,8 @@ bool ED_screen_set(bContext *C, bScreen *sc)
 	wmWindowManager *wm = CTX_wm_manager(C);
 	wmWindow *win = CTX_wm_window(C);
 	bScreen *oldscreen = CTX_wm_screen(C);
-	
+
+	BLI_assert(ED_screen_is_editable(sc)); /* Caller should check */
 	/* validate screen, it's called with notifier reference */
 	if (BLI_findindex(&bmain->screen, sc) == -1) {
 		return true;
@@ -1623,12 +1624,12 @@ bool ED_screen_delete(bContext *C, bScreen *sc)
 	 * can safely assume ours is not in use anywhere an delete it */
 
 	for (newsc = sc->id.prev; newsc; newsc = newsc->id.prev)
-		if (!ed_screen_used(wm, newsc) && !newsc->temp)
+		if (!ed_screen_used(wm, newsc) && newsc->type != SCREEN_TYPE_TEMP)
 			break;
 	
 	if (!newsc) {
 		for (newsc = sc->id.next; newsc; newsc = newsc->id.next)
-			if (!ed_screen_used(wm, newsc) && !newsc->temp)
+			if (!ed_screen_used(wm, newsc) && newsc->type != SCREEN_TYPE_TEMP)
 				break;
 	}
 
@@ -1943,7 +1944,7 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
 		sc = ED_screen_add(win, oldscreen->scene, newname);
 		sc->state = state;
 		sc->redraws_flag = oldscreen->redraws_flag;
-		sc->temp = oldscreen->temp;
+		sc->type = oldscreen->type;
 
 		/* timer */
 		sc->animtimer = oldscreen->animtimer;
@@ -2256,3 +2257,8 @@ bool ED_screen_stereo3d_required(bScreen *screen)
 
 	return false;
 }
+
+bool ED_screen_is_editable(const bScreen *screen)
+{
+	return (screen && screen->type != SCREEN_TYPE_RESTRICTED);
+}
diff --git a/source/blender/editors/screen/screen_ops.c b/source/blender/editors/screen/screen_ops.c
index 2ed28ea..badd5b7 100644
--- a/source/blender/editors/screen/screen_ops.c
+++ b/source/blender/editors/screen/screen_ops.c
@@ -2374,7 +2374,7 @@ static bool screen_set_is_ok(bScreen *screen, bScreen *screen_prev)
 	return ((screen->winid == 0) &&
 	        /* in typical usage these should have a nonzero winid
 	         * (all temp screens should be used, or closed & freed). */
-	        (screen->temp == false) &&
+	        (screen->type == SCREEN_TYPE_NORMAL) &&
 	        (screen->state == SCREENNORMAL) &&
 	        (screen != screen_prev) &&
 	        (screen->id.name[2] != '.' || !(U.uiflag & USER_HIDE_DOT)));
@@ -2392,7 +2392,7 @@ static int screen_set_exec(bContext *C, wmOperator *op)
 	int delta = RNA_int_get(op->ptr, "delta");
 	
 	/* temp screens are for userpref or render display */
-	if (screen->temp || (sa && sa->full && sa->full->temp)) {
+	if (screen->type != SCREEN_TYPE_NORMAL || (sa && sa->full && sa->full->type != SCREEN_TYPE_NORMAL)) {
 		return OPERATOR_CANCELLED;
 	}
 	
@@ -2447,12 +2447,7 @@ static void SCREEN_OT_screen_set(wmOperatorType *ot)
 
 static int screen_maximize_area_poll(bContext *C)
 {
-	return ED_operator_areaactive(C) &&
-#ifdef WITH_INPUT_HMD
-	        !(CTX_wm_manager(C)->hmd_view.hmd_win == CTX_wm_window(C));
-#else
-	        true;
-#endif
+	return ED_operator_areaactive(C) && ED_screen_is_editable(CTX_wm_screen(C));
 }
 
 /* function to be called outside UI context, or for redo */
@@ -3200,9 +3195,10 @@ static void SCREEN_OT_region_flip(wmOperatorType *ot)
 /* ************** header operator ***************************** */
 static int header_exec(bContext *C, wmOperator *UNUSED(op))
 {
+	const bScreen *screen = CTX_wm_screen(C);
 	ARegion *ar = screen_find_region_type(C, RGN_TYPE_HEADER);
 
-	if (ar == NULL) {
+	if (ar == NULL || !ED_screen_is_editable(screen)) {
 		return OPERATOR_CANCELLED;
 	}
 
diff --git a/source/blender/makesdna/DNA_screen_types.h b/source/blender/makesdna/DNA_screen_types.h
index 2a5845c..1e6bc1c 100644
--- a/source/blender/makesdna/DNA_screen_types.h
+++ b/source/blender/makesdna/DNA_screen_types.h
@@ -45,6 +45,16 @@ struct Scene;
 struct uiLayout;
 struct wmTimer;
 
+/* bScreen.type */
+enum {
+	SCREEN_TYPE_NORMAL     = 0,
+	/* temp screen in a temp window, don't save (like user prefs) */
+	SCREEN_TYPE_TEMP       = 1,
+	/* A restricted window only allows to display one particulare editor. It will only
+	 * display the main region and won't allow going out of fullscreen or switch the editor. */
+	SCREEN_TYPE_RESTRICTED = 2,
+};
+
 typedef struct bScreen {
 	ID id;
 	
@@ -59,7 +69,7 @@ typedef struct bScreen {
 	short winid;						/* winid from WM, starts with 1 */
 	short redraws_flag;					/* user-setting for which editors get redrawn during anim playback (used to be time->redraws) */
 
-	char temp;							/* temp screen in a temp window, don't save (like user prefs) */
+	char type;
 	char state;							/* temp screen for image render display or fileselect */
 	char do_draw;						/* notifier for drawing edges */
 	char do_refresh;					/* notifier for scale screen, changed screen, etc */
@@ -71,7 +81,7 @@ typedef struct bScreen {
 	char scrubbing;						/* set when scrubbing to avoid some costly updates */
 	char is_hmd_running;				/* is this screen running an HMD session? */
 	char pad[5];
-	
+
 	short mainwin;						/* screensize subwindow, for screenedges and global menus */
 	short subwinactive;					/* active subwindow */
 
diff --git a/source/blender/

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list