diff --git a/source/blender/editors/include/ED_screen.h b/source/blender/editors/include/ED_screen.h index 2f6589f35a9..eddc94fdc5b 100644 --- a/source/blender/editors/include/ED_screen.h +++ b/source/blender/editors/include/ED_screen.h @@ -361,18 +361,14 @@ struct ScrArea *ED_screen_state_toggle(struct bContext *C, * 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. + * \param rect_unscaled: Position & size of the window, if a window is spawned. */ ScrArea *ED_screen_temp_space_open(struct bContext *C, const char *title, - int x, - int y, - int sizex, - int sizey, + const struct rcti *rect_unscaled, eSpace_Type space_type, int display_type, - bool dialog); + bool dialog) ATTR_NONNULL(1, 2, 3); 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_region_flip_menu_create(struct bContext *C, struct uiLayout *layout, void *arg); diff --git a/source/blender/editors/render/render_view.cc b/source/blender/editors/render/render_view.cc index c291a9e3d36..6f036df1596 100644 --- a/source/blender/editors/render/render_view.cc +++ b/source/blender/editors/render/render_view.cc @@ -146,13 +146,17 @@ ScrArea *render_view_open(bContext *C, int mx, int my, ReportList *reports) sizey = 256; } + const rcti window_rect = { + /*xmin*/ mx, + /*xmax*/ mx + sizex, + /*ymin*/ my, + /*ymax*/ my + sizey, + }; + /* changes context! */ if (WM_window_open(C, IFACE_("Blender Render"), - mx, - my, - sizex, - sizey, + &window_rect, SPACE_IMAGE, true, false, diff --git a/source/blender/editors/screen/screen_edit.cc b/source/blender/editors/screen/screen_edit.cc index f1cd180b4c1..24a825c3690 100644 --- a/source/blender/editors/screen/screen_edit.cc +++ b/source/blender/editors/screen/screen_edit.cc @@ -1631,10 +1631,7 @@ ScrArea *ED_screen_state_toggle(bContext *C, wmWindow *win, ScrArea *area, const ScrArea *ED_screen_temp_space_open(bContext *C, const char *title, - int x, - int y, - int sizex, - int sizey, + const rcti *rect_unscaled, eSpace_Type space_type, int display_type, bool dialog) @@ -1645,10 +1642,7 @@ ScrArea *ED_screen_temp_space_open(bContext *C, case USER_TEMP_SPACE_DISPLAY_WINDOW: if (WM_window_open(C, title, - x, - y, - sizex, - sizey, + rect_unscaled, int(space_type), false, dialog, diff --git a/source/blender/editors/screen/screen_ops.cc b/source/blender/editors/screen/screen_ops.cc index a5c8e7be5d4..cd407ef65df 100644 --- a/source/blender/editors/screen/screen_ops.cc +++ b/source/blender/editors/screen/screen_ops.cc @@ -1441,18 +1441,16 @@ static int area_dupli_invoke(bContext *C, wmOperator *op, const wmEvent *event) area = sad->sa1; } + const rcti window_rect = { + /*xmin*/ area->totrct.xmin, + /*xmax*/ area->totrct.xmin + area->winx, + /*ymin*/ area->totrct.ymin, + /*ymax*/ area->totrct.ymin + area->winy, + }; + /* Create new window. No need to set space_type since it will be copied over. */ - wmWindow *newwin = WM_window_open(C, - "Blender", - area->totrct.xmin, - area->totrct.ymin, - area->winx, - area->winy, - SPACE_EMPTY, - false, - false, - false, - WIN_ALIGN_ABSOLUTE); + wmWindow *newwin = WM_window_open( + C, "Blender", &window_rect, SPACE_EMPTY, false, false, false, WIN_ALIGN_ABSOLUTE); if (newwin) { /* copy area to new screen */ @@ -5148,13 +5146,17 @@ static int userpref_show_exec(bContext *C, wmOperator *op) RNA_property_update(C, &pref_ptr, active_section_prop); } + const rcti window_rect = { + /*xmin*/ event->xy[0], + /*xmax*/ event->xy[0] + sizex, + /*ymin*/ event->xy[1], + /*ymax*/ event->xy[1] + sizey, + }; + /* changes context! */ if (WM_window_open(C, IFACE_("Blender Preferences"), - event->xy[0], - event->xy[1], - sizex, - sizey, + &window_rect, SPACE_USERPREF, false, false, @@ -5221,13 +5223,17 @@ static int drivers_editor_show_exec(bContext *C, wmOperator *op) PropertyRNA *prop; uiBut *but = UI_context_active_but_prop_get(C, &ptr, &prop, &index); + const rcti window_rect = { + /*xmin*/ event->xy[0], + /*xmax*/ event->xy[0] + sizex, + /*ymin*/ event->xy[1], + /*ymax*/ event->xy[1] + sizey, + }; + /* changes context! */ if (WM_window_open(C, IFACE_("Blender Drivers Editor"), - event->xy[0], - event->xy[1], - sizex, - sizey, + &window_rect, SPACE_GRAPH, false, false, @@ -5292,17 +5298,23 @@ static int info_log_show_exec(bContext *C, wmOperator *op) wmWindow *win_cur = CTX_wm_window(C); /* Use eventstate, not event from _invoke, so this can be called through exec(). */ const wmEvent *event = win_cur->eventstate; + const int shift_y = 480; + const int mx = event->xy[0]; + const int my = event->xy[1] + shift_y; int sizex = 900 * UI_SCALE_FAC; int sizey = 580 * UI_SCALE_FAC; - int shift_y = 480; + + const rcti window_rect = { + /*xmin*/ mx, + /*xmax*/ mx + sizex, + /*ymin*/ my, + /*ymax*/ my + sizey, + }; /* changes context! */ if (WM_window_open(C, IFACE_("Blender Info Log"), - event->xy[0], - event->xy[1] + shift_y, - sizex, - sizey, + &window_rect, SPACE_INFO, false, false, diff --git a/source/blender/windowmanager/WM_api.h b/source/blender/windowmanager/WM_api.h index 5d740a8e195..a358693442d 100644 --- a/source/blender/windowmanager/WM_api.h +++ b/source/blender/windowmanager/WM_api.h @@ -330,7 +330,8 @@ typedef enum eWindowAlignment { } eWindowAlignment; /** - * \param space_type: SPACE_VIEW3D, SPACE_INFO, ... (eSpace_Type) + * \param rect: Position & size of the window. + * \param space_type: #SPACE_VIEW3D, #SPACE_INFO, ... (#eSpace_Type). * \param toplevel: Not a child owned by other windows. A peer of main window. * \param dialog: whether this should be made as a dialog-style window * \param temp: whether this is considered a short-lived window @@ -339,15 +340,12 @@ typedef enum eWindowAlignment { */ struct wmWindow *WM_window_open(struct bContext *C, const char *title, - int x, - int y, - int sizex, - int sizey, + const struct rcti *rect_unscaled, int space_type, bool toplevel, bool dialog, bool temp, - eWindowAlignment alignment); + eWindowAlignment alignment) ATTR_NONNULL(1, 2, 3); void WM_window_set_dpi(const wmWindow *win); diff --git a/source/blender/windowmanager/intern/wm_event_system.cc b/source/blender/windowmanager/intern/wm_event_system.cc index 7fffd175669..80dbf422520 100644 --- a/source/blender/windowmanager/intern/wm_event_system.cc +++ b/source/blender/windowmanager/intern/wm_event_system.cc @@ -2647,17 +2647,24 @@ static eHandlerActionFlag wm_handler_fileselect_do(bContext *C, switch (val) { case EVT_FILESELECT_FULL_OPEN: { wmWindow *win = CTX_wm_window(C); - ScrArea *area; + const int window_center[2] = { + WM_window_pixels_x(win) / 2, + WM_window_pixels_y(win) / 2, + }; - if ((area = ED_screen_temp_space_open(C, - IFACE_("Blender File View"), - WM_window_pixels_x(win) / 2, - WM_window_pixels_y(win) / 2, - U.file_space_data.temp_win_sizex * UI_SCALE_FAC, - U.file_space_data.temp_win_sizey * UI_SCALE_FAC, - SPACE_FILE, - U.filebrowser_display_type, - true))) + const rcti window_rect = { + /*xmin*/ window_center[0], + /*xmax*/ window_center[0] + int(U.file_space_data.temp_win_sizex * UI_SCALE_FAC), + /*ymin*/ window_center[1], + /*ymax*/ window_center[1] + int(U.file_space_data.temp_win_sizey * UI_SCALE_FAC), + }; + + if (ScrArea *area = ED_screen_temp_space_open(C, + IFACE_("Blender File View"), + &window_rect, + SPACE_FILE, + U.filebrowser_display_type, + true)) { ARegion *region_header = BKE_area_find_region_type(area, RGN_TYPE_HEADER); diff --git a/source/blender/windowmanager/intern/wm_window.c b/source/blender/windowmanager/intern/wm_window.c index b47b0c906b2..90857e85049 100644 --- a/source/blender/windowmanager/intern/wm_window.c +++ b/source/blender/windowmanager/intern/wm_window.c @@ -875,10 +875,7 @@ static bool wm_window_update_size_position(wmWindow *win) wmWindow *WM_window_open(bContext *C, const char *title, - int x, - int y, - int sizex, - int sizey, + const rcti *rect_unscaled, int space_type, bool toplevel, bool dialog, @@ -890,6 +887,10 @@ wmWindow *WM_window_open(bContext *C, wmWindow *win_prev = CTX_wm_window(C); Scene *scene = CTX_data_scene(C); ViewLayer *view_layer = CTX_data_view_layer(C); + int x = rect_unscaled->xmin; + int y = rect_unscaled->ymin; + int sizex = BLI_rcti_size_x(rect_unscaled); + int sizey = BLI_rcti_size_y(rect_unscaled); rcti rect; const float native_pixel_size = GHOST_GetNativePixelSize(win_prev->ghostwin); @@ -1033,13 +1034,16 @@ int wm_window_new_exec(bContext *C, wmOperator *op) { wmWindow *win_src = CTX_wm_window(C); ScrArea *area = BKE_screen_find_big_area(CTX_wm_screen(C), SPACE_TYPE_ANY, 0); + const rcti window_rect = { + /*xmin*/ 0, + /*xmax*/ win_src->sizex * 0.95f, + /*ymin*/ 0, + /*ymax*/ win_src->sizey * 0.9f, + }; bool ok = (WM_window_open(C, IFACE_("Blender"), - 0, - 0, - win_src->sizex * 0.95f, - win_src->sizey * 0.9f, + &window_rect, area->spacetype, false, false,