Refactor temp-space opening for optional fullscreen mode
authorJulian Eisel <eiseljulian@gmail.com>
Wed, 18 Sep 2019 12:21:32 +0000 (14:21 +0200)
committerJulian Eisel <eiseljulian@gmail.com>
Wed, 18 Sep 2019 12:22:50 +0000 (14:22 +0200)
Will be put to use in followup commits.

source/blender/editors/include/ED_screen.h
source/blender/editors/render/render_view.c
source/blender/editors/screen/screen_edit.c
source/blender/editors/screen/screen_ops.c
source/blender/makesdna/DNA_userdef_types.h
source/blender/makesrna/intern/rna_userdef.c
source/blender/windowmanager/WM_api.h
source/blender/windowmanager/intern/wm_event_system.c
source/blender/windowmanager/intern/wm_window.c

index d0fab134dcc0aad4dd68901d31316dae4dfc8461..dbd5e74da5cf6b7e1501483341b55b147b40acfd 100644 (file)
@@ -238,6 +238,14 @@ struct ScrArea *ED_screen_state_toggle(struct bContext *C,
                                        struct wmWindow *win,
                                        struct ScrArea *sa,
                                        const short state);
+ScrArea *ED_screen_temp_space_open(struct bContext *C,
+                                   const char *title,
+                                   int x,
+                                   int y,
+                                   int sizex,
+                                   int sizey,
+                                   eSpace_Type space_type,
+                                   int display_type);
 void ED_screens_header_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
 void ED_screens_footer_tools_menu_create(struct bContext *C, struct uiLayout *layout, void *arg);
 void ED_screens_navigation_bar_tools_menu_create(struct bContext *C,
index 3154d5d0985e8a78ab23d0c9abe912d8108da428..d92cd13628b5871ac80954f4f079716ae533eabf 100644 (file)
@@ -36,6 +36,8 @@
 #include "BKE_screen.h"
 #include "BKE_report.h"
 
+#include "BLT_translation.h"
+
 #include "WM_api.h"
 #include "WM_types.h"
 
@@ -154,7 +156,8 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports)
     }
 
     /* changes context! */
-    if (WM_window_open_temp(C, mx, my, sizex, sizey, WM_WINDOW_RENDER) == NULL) {
+    if (WM_window_open_temp(C, IFACE_("Blender Render"), mx, my, sizex, sizey, SPACE_IMAGE) ==
+        NULL) {
       BKE_report(reports, RPT_ERROR, "Failed to open window!");
       return NULL;
     }
index b37aa47aba67e5e189d72f74890e62df1b2d817c..20920dc6f84bc29747625c2e68247075c9de14b1 100644 (file)
@@ -1346,6 +1346,39 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *sa, const s
   return sc->areabase.first;
 }
 
+/**
+ * Wrapper to open a temporary space either as fullscreen space, or as separate window, as defined
+ * by \a display_type.
+ *
+ * \param title: Title to set for the window, if a window is spawned.
+ * \param x, y: Position of the window, if a window is spawned.
+ * \param sizex, sizey: Dimensions of the window, if a window is spawned.
+ */
+ScrArea *ED_screen_temp_space_open(bContext *C,
+                                   const char *title,
+                                   int x,
+                                   int y,
+                                   int sizex,
+                                   int sizey,
+                                   eSpace_Type space_type,
+                                   int display_type)
+{
+  ScrArea *sa = NULL;
+
+  switch (display_type) {
+    case USER_TEMP_SPACE_DISPLAY_WINDOW:
+      if (WM_window_open_temp(C, title, x, y, sizex, sizey, (int)space_type)) {
+        sa = CTX_wm_area(C);
+      }
+      break;
+    case USER_TEMP_SPACE_DISPLAY_FULLSCREEN:
+      sa = ED_screen_full_newspace(C, CTX_wm_area(C), (int)space_type);
+      break;
+  }
+
+  return sa;
+}
+
 /* update frame rate info for viewport drawing */
 void ED_refresh_viewport_fps(bContext *C)
 {
index f29535a7f0badaf0003a3e3713b5547121ae439e..53b30373ec3aa10157b120f47e2f83f8ab25e0c7 100644 (file)
@@ -4833,7 +4833,9 @@ static int userpref_show_invoke(bContext *C, wmOperator *op, const wmEvent *even
   int sizey = 520 * UI_DPI_FAC;
 
   /* changes context! */
-  if (WM_window_open_temp(C, event->x, event->y, sizex, sizey, WM_WINDOW_USERPREFS) != NULL) {
+  if (WM_window_open_temp(
+          C, IFACE_("Blender Preferences"), event->x, event->y, sizex, sizey, SPACE_USERPREF) !=
+      NULL) {
     /* The header only contains the editor switcher and looks empty.
      * So hiding in the temp window makes sense. */
     ScrArea *area = CTX_wm_area(C);
@@ -4882,7 +4884,11 @@ static int drivers_editor_show_invoke(bContext *C, wmOperator *op, const wmEvent
   but = UI_context_active_but_prop_get(C, &ptr, &prop, &index);
 
   /* changes context! */
-  if (WM_window_open_temp(C, event->x, event->y, sizex, sizey, WM_WINDOW_DRIVERS) != NULL) {
+  if (WM_window_open_temp(
+          C, IFACE_("Blender Drivers Editor"), event->x, event->y, sizex, sizey, SPACE_GRAPH) !=
+      NULL) {
+    ED_drivers_editor_init(C, CTX_wm_area(C));
+
     /* activate driver F-Curve for the property under the cursor */
     if (but) {
       FCurve *fcu;
@@ -4938,7 +4944,9 @@ static int info_log_show_invoke(bContext *C, wmOperator *op, const wmEvent *even
   int shift_y = 480;
 
   /* changes context! */
-  if (WM_window_open_temp(C, event->x, event->y + shift_y, sizex, sizey, WM_WINDOW_INFO) != NULL) {
+  if (WM_window_open_temp(
+          C, IFACE_("Blender Info Log"), event->x, event->y + shift_y, sizex, sizey, SPACE_INFO) !=
+      NULL) {
     return OPERATOR_FINISHED;
   }
   else {
index 6e44c51970dbd48cdbc31e5cd28c76a3d2264ef3..86c2b2f09a8ef29f8a5d60549c5f531864c576be 100644 (file)
@@ -1202,6 +1202,11 @@ typedef enum eUserpref_FactorDisplay {
   USER_FACTOR_AS_PERCENTAGE = 1,
 } eUserpref_FactorDisplay;
 
+typedef enum eUserpref_TempSpaceDisplayType {
+  USER_TEMP_SPACE_DISPLAY_FULLSCREEN,
+  USER_TEMP_SPACE_DISPLAY_WINDOW,
+} eUserpref_TempSpaceDisplayType;
+
 #ifdef __cplusplus
 }
 #endif
index 548111500addeb31fcc47a4efd3b772eca9487fb..94f800c82a97e6702c4a53be3aa19cde4e1fce96 100644 (file)
@@ -4044,6 +4044,20 @@ static void rna_def_userdef_view(BlenderRNA *brna)
       {0, NULL, 0, NULL, NULL},
   };
 
+  static const EnumPropertyItem temp_space_display_types[] = {
+      {USER_TEMP_SPACE_DISPLAY_FULLSCREEN,
+       "SCREEN", /* Could be FULLSCREEN, but keeping it consistent with render_display_types */
+       0,
+       "Full Screen",
+       "Open the temporary editor in a maximized screen"},
+      {USER_TEMP_SPACE_DISPLAY_WINDOW,
+       "WINDOW",
+       0,
+       "New Window",
+       "Open the temporary editor in a new window"},
+      {0, NULL, 0, NULL, NULL},
+  };
+
   PropertyRNA *prop;
   StructRNA *srna;
 
index 455a30b6ff530272cadef788dda65d0a90dabbe5..568b904dcb7e4e256911cfe40db9d738e69d8383 100644 (file)
@@ -153,18 +153,9 @@ void WM_opengl_context_dispose(void *context);
 void WM_opengl_context_activate(void *context);
 void WM_opengl_context_release(void *context);
 
-/* defines for 'type' WM_window_open_temp */
-enum {
-  WM_WINDOW_RENDER = 1,
-  WM_WINDOW_USERPREFS,
-  WM_WINDOW_DRIVERS,
-  WM_WINDOW_INFO,
-  WM_WINDOW_FILESEL,
-};
-
 struct wmWindow *WM_window_open(struct bContext *C, const struct rcti *rect);
 struct wmWindow *WM_window_open_temp(
-    struct bContext *C, int x, int y, int sizex, int sizey, int type);
+    struct bContext *C, const char *title, int x, int y, int sizex, int sizey, int space_type);
 void WM_window_set_dpi(wmWindow *win);
 
 bool WM_stereo3d_enabled(struct wmWindow *win, bool only_fullscreen_test);
index 77672e0403018170f87c1065cc30a854dc978471..347e26e0ba51da56b4e34e65e8482dfef3f060bd 100644 (file)
@@ -58,6 +58,8 @@
 
 #include "BKE_sound.h"
 
+#include "BLT_translation.h"
+
 #include "ED_fileselect.h"
 #include "ED_info.h"
 #include "ED_screen.h"
@@ -2346,11 +2348,12 @@ static int wm_handler_fileselect_do(bContext *C,
       const int sizey = 600 * UI_DPI_FAC;
 
       if (WM_window_open_temp(C,
+                              IFACE_("Blender File View"),
                               WM_window_pixels_x(win) / 2,
                               WM_window_pixels_y(win) / 2,
                               sizex,
                               sizey,
-                              WM_WINDOW_FILESEL) != NULL) {
+                              SPACE_FILE) != NULL) {
         ScrArea *area = CTX_wm_area(C);
         ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER);
 
index 7437001cdfc494636cbc4dd1e3f253a95474ec92..081797542f2332bbc8a099f4b07432e406ca348d 100644 (file)
@@ -792,10 +792,11 @@ wmWindow *WM_window_open(bContext *C, const rcti *rect)
  * Uses `screen->temp` tag to define what to do, currently it limits
  * to only one "temp" window for render out, preferences, filewindow, etc...
  *
- * \param type: WM_WINDOW_RENDER, WM_WINDOW_USERPREFS...
- * \return the window or NULL.
+ * \param space_type: SPACE_VIEW3D, SPACE_INFO, ... (eSpace_Type)
+ * \return the window or NULL in case of failure.
  */
-wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, int type)
+wmWindow *WM_window_open_temp(
+    bContext *C, const char *title, int x, int y, int sizex, int sizey, int space_type)
 {
   Main *bmain = CTX_data_main(C);
   wmWindow *win_prev = CTX_wm_window(C);
@@ -804,8 +805,6 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
   ScrArea *sa;
   Scene *scene = CTX_data_scene(C);
   ViewLayer *view_layer = CTX_data_view_layer(C);
-  eSpace_Type space_type = SPACE_EMPTY;
-  const char *title;
 
   /* convert to native OS window coordinates */
   const float native_pixel_size = GHOST_GetNativePixelSize(win_prev->ghostwin);
@@ -885,53 +884,11 @@ wmWindow *WM_window_open_temp(bContext *C, int x, int y, int sizex, int sizey, i
   sa = screen->areabase.first;
   CTX_wm_area_set(C, sa);
 
-  if (type == WM_WINDOW_RENDER) {
-    space_type = SPACE_IMAGE;
-  }
-  else if (type == WM_WINDOW_DRIVERS) {
-    space_type = SPACE_GRAPH;
-  }
-  else if (type == WM_WINDOW_USERPREFS) {
-    space_type = SPACE_USERPREF;
-  }
-  else if (type == WM_WINDOW_FILESEL) {
-    space_type = SPACE_FILE;
-  }
-  else if (type == WM_WINDOW_INFO) {
-    space_type = SPACE_INFO;
-  }
-  else {
-    BLI_assert(false);
-  }
   ED_area_newspace(C, sa, space_type, false);
 
   ED_screen_change(C, screen);
   ED_screen_refresh(CTX_wm_manager(C), win); /* test scale */
 
-  /* do additional setup for specific editor type */
-  if (type == WM_WINDOW_DRIVERS) {
-    ED_drivers_editor_init(C, sa);
-  }
-
-  if (sa->spacetype == SPACE_IMAGE) {
-    title = IFACE_("Blender Render");
-  }
-  else if (ELEM(sa->spacetype, SPACE_OUTLINER, SPACE_USERPREF)) {
-    title = IFACE_("Blender Preferences");
-  }
-  else if (sa->spacetype == SPACE_FILE) {
-    title = IFACE_("Blender File View");
-  }
-  else if (sa->spacetype == SPACE_GRAPH) {
-    title = IFACE_("Blender Drivers Editor");
-  }
-  else if (sa->spacetype == SPACE_INFO) {
-    title = IFACE_("Blender Info Log");
-  }
-  else {
-    title = "Blender";
-  }
-
   if (win->ghostwin) {
     GHOST_SetTitle(win->ghostwin, title);
     return win;