UI: Window Title With Version

Include blender version information in title (including cycle), and
also indicate unsaved and dirty status better.

Pull Request: https://projects.blender.org/blender/blender/pulls/111998
This commit is contained in:
Harley Acheson
2023-09-16 02:37:06 +02:00
committed by Harley Acheson
parent b3baeeaa32
commit 636f3697ee
3 changed files with 34 additions and 13 deletions

View File

@@ -42,6 +42,9 @@ extern "C" {
/** User readable version string. */ /** User readable version string. */
const char *BKE_blender_version_string(void); const char *BKE_blender_version_string(void);
/** As above but does not show patch version. */
const char *BKE_blender_version_string_compact(void);
/** Returns true when version cycle is alpha, otherwise (beta, rc) returns false. */ /** Returns true when version cycle is alpha, otherwise (beta, rc) returns false. */
bool BKE_blender_version_is_alpha(void); bool BKE_blender_version_is_alpha(void);

View File

@@ -93,6 +93,9 @@ void BKE_blender_free()
static char blender_version_string[48] = ""; static char blender_version_string[48] = "";
/* Only includes patch if non-zero. */
static char blender_version_string_compact[48] = "";
static void blender_version_init() static void blender_version_init()
{ {
const char *version_cycle = ""; const char *version_cycle = "";
@@ -118,6 +121,12 @@ static void blender_version_init()
BLENDER_VERSION % 100, BLENDER_VERSION % 100,
BLENDER_VERSION_PATCH, BLENDER_VERSION_PATCH,
version_cycle); version_cycle);
SNPRINTF(blender_version_string_compact,
"%d.%01d%s",
BLENDER_VERSION / 100,
BLENDER_VERSION % 100,
version_cycle);
} }
const char *BKE_blender_version_string() const char *BKE_blender_version_string()
@@ -125,6 +134,11 @@ const char *BKE_blender_version_string()
return blender_version_string; return blender_version_string;
} }
const char *BKE_blender_version_string_compact()
{
return blender_version_string_compact;
}
void BKE_blender_version_blendfile_string_from_values(char *str_buff, void BKE_blender_version_blendfile_string_from_values(char *str_buff,
const size_t str_buff_maxncpy, const size_t str_buff_maxncpy,
const short file_version, const short file_version,

View File

@@ -30,6 +30,7 @@
#include "BLT_translation.h" #include "BLT_translation.h"
#include "BKE_blender_version.h"
#include "BKE_context.h" #include "BKE_context.h"
#include "BKE_global.h" #include "BKE_global.h"
#include "BKE_icons.h" #include "BKE_icons.h"
@@ -481,20 +482,23 @@ void wm_window_title(wmWindowManager *wm, wmWindow *win)
* because #WM_window_open always sets window title. */ * because #WM_window_open always sets window title. */
} }
else if (win->ghostwin) { else if (win->ghostwin) {
/* this is set to 1 if you don't have startup.blend open */ char str[sizeof(Main::filepath) + 24];
const char *blendfile_path = BKE_main_blendfile_path_from_global(); const char *filepath = BKE_main_blendfile_path_from_global();
if (blendfile_path[0] != '\0') { char basepath[FILE_MAXDIR] = {0};
char str[sizeof(Main::filepath) + 24]; char filename[FILE_MAXFILE] = {0};
SNPRINTF(str, std::string location;
"Blender%s [%s%s]", if (filepath[0]) {
wm->file_saved ? "" : "*", BLI_path_split_dir_file(filepath, basepath, sizeof(basepath), filename, sizeof(filename));
blendfile_path, location = " [" + std::string(basepath) + "]";
G_MAIN->recovered ? " (Recovered)" : "");
GHOST_SetTitle(static_cast<GHOST_WindowHandle>(win->ghostwin), str);
}
else {
GHOST_SetTitle(static_cast<GHOST_WindowHandle>(win->ghostwin), "Blender");
} }
SNPRINTF(str,
"%s %s%s%s - Blender %s",
wm->file_saved ? "" : "*",
filename[0] ? filename : IFACE_("(Unsaved)"),
G_MAIN->recovered ? " (Recovered)" : "",
basepath[0] ? location.c_str() : "",
BKE_blender_version_string_compact());
GHOST_SetTitle(static_cast<GHOST_WindowHandle>(win->ghostwin), str);
/* Informs GHOST of unsaved changes, to set window modified visual indicator (macOS) /* Informs GHOST of unsaved changes, to set window modified visual indicator (macOS)
* and to give hint of unsaved changes for a user warning mechanism in case of OS application * and to give hint of unsaved changes for a user warning mechanism in case of OS application