-osd/windows: Minimise full-screen windows on losing focus (#2997).

-osd/modules/osdwindow.cpp: Clean up window title formatting.
 * Show data type model in window title.
 * Moved window title formatting to a single place.

-tools/chdman.cpp: Removed some unnecessary .c_str() calls.
This commit is contained in:
Vas Crabb 2021-01-21 23:33:53 +11:00
parent ef82fd102d
commit 7cfe419ca8
13 changed files with 61 additions and 58 deletions

View File

@ -270,13 +270,13 @@ void image_manager::postdevice_init()
bool image_manager::try_change_working_directory(std::string &working_directory, const std::string &subdir)
{
const osd::directory::entry *entry;
bool success = false;
bool done = false;
auto directory = osd::directory::open(working_directory);
if (directory)
{
const osd::directory::entry *entry;
bool done = false;
while (!done && (entry = directory->read()) != nullptr)
{
if (!core_stricmp(subdir.c_str(), entry->name))

View File

@ -313,12 +313,6 @@ int mac_window_info::window_init()
set_renderer(osd_renderer::make_for_type(video_config.mode, static_cast<osd_window*>(this)->shared_from_this()));
// make the window title
if (video_config.numscreens == 1)
sprintf(m_title, "%s: %s [%s]", emulator_info::get_appname(), machine().system().type.fullname(), machine().system().name);
else
sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine().system().type.fullname(), machine().system().name, index());
result = complete_create();
// handle error conditions
@ -515,7 +509,7 @@ void mac_window_info::update()
// complete_create
//============================================================
extern void *CreateMAMEWindow(char *title, int x, int y, int w, int h, bool isFullscreen);
extern void *CreateMAMEWindow(const char *title, int x, int y, int w, int h, bool isFullscreen);
extern void *GetOSWindow(void *wincontroller);
int mac_window_info::complete_create()
@ -552,7 +546,7 @@ int mac_window_info::complete_create()
// get monitor work area for centering
osd_rect work = monitor()->usuable_position_size();
auto window = CreateMAMEWindow(m_title,
auto window = CreateMAMEWindow(title().c_str(),
work.left() + (work.width() - temp.width()) / 2,
work.top() + (work.height() - temp.height()) / 2,
temp.width(), temp.height(), fullscreen());

View File

@ -59,7 +59,6 @@ public:
private:
// window handle and info
char m_title[256];
int m_startmaximized;
// dimensions

View File

@ -109,7 +109,7 @@ void *GetOSWindow(void *wincontroller)
return [wc getWindow];
}
void *CreateMAMEWindow(char *title, int x, int y, int w, int h, bool isFullscreen)
void *CreateMAMEWindow(const char *title, int x, int y, int w, int h, bool isFullscreen)
{
NSRect bounds = NSMakeRect(x, y, w, h);
NSUInteger style = NSTitledWindowMask | NSClosableWindowMask | NSResizableWindowMask;

View File

@ -22,6 +22,35 @@
#include "render/drawsdl.h"
#endif
osd_window::osd_window(running_machine &machine, int index, std::shared_ptr<osd_monitor_info> monitor, const osd_window_config &config) :
#ifdef OSD_WINDOWS
m_dc(nullptr), m_resize_state(0),
#endif
m_target(nullptr),
m_primlist(nullptr),
m_win_config(config),
m_index(index),
m_fullscreen(false),
m_prescale(1),
m_machine(machine),
m_monitor(std::move(monitor)),
m_renderer(nullptr),
m_main(nullptr),
m_title(
util::string_format(
(video_config.numscreens > 1)
? "%1$s: %2$s [%3$s] - Screen %4$d (%5$s%6$sP%7$d)"
: "%1$s: %2$s [%3$s] (%5$s%6$sP%7$d)",
emulator_info::get_appname(),
machine.system().type.fullname(),
machine.system().name,
index,
(sizeof(int) == sizeof(void *)) ? "I" : "",
(sizeof(long) == sizeof(void *)) ? "L" : (sizeof(long long) == sizeof(void *)) ? "LL" : "",
sizeof(void *) * 8))
{
}
float osd_window::pixel_aspect() const
{
return monitor()->pixel_aspect();

View File

@ -65,28 +65,14 @@ class osd_monitor_info;
class osd_window : public std::enable_shared_from_this<osd_window>
{
public:
osd_window(running_machine &machine, int index, std::shared_ptr<osd_monitor_info> monitor, const osd_window_config &config)
:
#ifdef OSD_WINDOWS
m_dc(nullptr), m_resize_state(0),
#endif
m_target(nullptr),
m_primlist(nullptr),
m_win_config(config),
m_index(index),
m_fullscreen(false),
m_prescale(1),
m_machine(machine),
m_monitor(std::move(monitor)),
m_renderer(nullptr),
m_main(nullptr)
{}
osd_window(running_machine &machine, int index, std::shared_ptr<osd_monitor_info> monitor, const osd_window_config &config);
virtual ~osd_window() { }
render_target *target() const { return m_target; }
int fullscreen() const { return m_fullscreen; }
running_machine &machine() const { return m_machine; }
const std::string &title() const { return m_title; }
bool has_renderer() const { return m_renderer != nullptr; }
osd_renderer &renderer() const { return *m_renderer; }
@ -168,6 +154,7 @@ private:
std::shared_ptr<osd_monitor_info> m_monitor;
std::unique_ptr<osd_renderer> m_renderer;
std::shared_ptr<osd_window> m_main;
const std::string m_title;
};
template <class TWindowHandle>

View File

@ -411,12 +411,6 @@ int sdl_window_info::window_init()
set_renderer(osd_renderer::make_for_type(video_config.mode, static_cast<osd_window*>(this)->shared_from_this()));
// make the window title
if (video_config.numscreens == 1)
sprintf(m_title, "%s: %s [%s]", emulator_info::get_appname(), machine().system().type.fullname(), machine().system().name);
else
sprintf(m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine().system().type.fullname(), machine().system().name, index());
int result = complete_create();
// handle error conditions
@ -691,7 +685,7 @@ int sdl_window_info::complete_create()
osd_rect work = monitor()->usuable_position_size();
// create the SDL window
auto sdlwindow = SDL_CreateWindow(m_title,
auto sdlwindow = SDL_CreateWindow(title().c_str(),
work.left() + (work.width() - temp.width()) / 2,
work.top() + (work.height() - temp.height()) / 2,
temp.width(), temp.height(), m_extra_flags);

View File

@ -64,7 +64,6 @@ public:
private:
// window handle and info
char m_title[256];
int m_startmaximized;
// dimensions

View File

@ -258,7 +258,6 @@ uwp_window_info::uwp_window_info(
m_lastclickx(0),
m_lastclicky(0)
{
memset(m_title,0,sizeof(m_title));
m_non_fullscreen_bounds.left = 0;
m_non_fullscreen_bounds.top = 0;
m_non_fullscreen_bounds.right = 0;
@ -393,12 +392,6 @@ void uwp_window_info::create(running_machine &machine, int index, std::shared_pt
window->m_targetlayerconfig = window->target()->layer_config();
window->m_targetvismask = window->target()->visibility_mask();
// make the window title
if (video_config.numscreens == 1)
sprintf(window->m_title, "%s: %s [%s]", emulator_info::get_appname(), machine.system().type.fullname(), machine.system().name);
else
sprintf(window->m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine.system().type.fullname(), machine.system().name, index);
// set the initial maximized state
window->m_startmaximized = downcast<windows_options &>(machine.options()).maximize();

View File

@ -78,7 +78,6 @@ public:
volatile int m_init_state;
// window handle and info
char m_title[256];
RECT m_non_fullscreen_bounds;
int m_startmaximized;
int m_isminimized;

View File

@ -314,7 +314,6 @@ win_window_info::win_window_info(
, m_lastclicky(0)
, m_attached_mode(false)
{
memset(m_title,0,sizeof(m_title));
m_non_fullscreen_bounds.left = 0;
m_non_fullscreen_bounds.top = 0;
m_non_fullscreen_bounds.right = 0;
@ -779,12 +778,6 @@ void win_window_info::create(running_machine &machine, int index, std::shared_pt
window->m_targetlayerconfig = window->target()->layer_config();
window->m_targetvismask = window->target()->visibility_mask();
// make the window title
if (video_config.numscreens == 1)
sprintf(window->m_title, "%s: %s [%s]", emulator_info::get_appname(), machine.system().type.fullname(), machine.system().name);
else
sprintf(window->m_title, "%s: %s [%s] - Screen %d", emulator_info::get_appname(), machine.system().type.fullname(), machine.system().name, index);
// set the initial maximized state
window->m_startmaximized = downcast<windows_options &>(machine.options()).maximize();
@ -1046,7 +1039,7 @@ int win_window_info::complete_create()
hwnd = win_create_window_ex_utf8(
fullscreen() ? FULLSCREEN_STYLE_EX : WINDOW_STYLE_EX,
"MAME",
m_title,
title().c_str(),
fullscreen() ? FULLSCREEN_STYLE : WINDOW_STYLE,
monitorbounds.left() + 20, monitorbounds.top() + 20,
monitorbounds.left() + 100, monitorbounds.top() + 100,
@ -1279,6 +1272,22 @@ LRESULT CALLBACK win_window_info::video_window_proc(HWND wnd, UINT message, WPAR
}
return DefWindowProc(wnd, message, wparam, lparam);
case WM_ACTIVATE:
if (window->has_renderer() && window->fullscreen())
{
if ((wparam == WA_ACTIVE) || (wparam == WA_CLICKACTIVE))
{
for (const auto &w : osd_common_t::s_window_list)
ShowWindow(std::static_pointer_cast<win_window_info>(w)->platform_window(), SW_RESTORE);
}
else if ((wparam == WA_INACTIVE) && !is_mame_window(HWND(lparam)))
{
for (const auto &w : osd_common_t::s_window_list)
ShowWindow(std::static_pointer_cast<win_window_info>(w)->platform_window(), SW_MINIMIZE);
}
}
return DefWindowProc(wnd, message, wparam, lparam);
// close: cause MAME to exit
case WM_CLOSE:
window->machine().schedule_exit();

View File

@ -100,7 +100,6 @@ public:
volatile int m_init_state;
// window handle and info
char m_title[256];
RECT m_non_fullscreen_bounds;
int m_startmaximized;
int m_isminimized;

View File

@ -1318,14 +1318,15 @@ void output_track_metadata(int mode, util::core_file &file, int tracknum, const
size = 2352;
break;
}
bool needquote = filename.find(' ') != std::string::npos;
file.printf("%d %d %d %d %s%s%s %d\n", tracknum+1, frameoffs, mode, size, needquote?"\"":"", filename.c_str(), needquote?"\"":"", discoffs);
const bool needquote = filename.find(' ') != std::string::npos;
const char *const quotestr = needquote ? "\"" : "";
file.printf("%d %d %d %d %s%s%s %d\n", tracknum+1, frameoffs, mode, size, quotestr, filename, quotestr, discoffs);
}
else if (mode == MODE_CUEBIN)
{
// first track specifies the file
if (tracknum == 0)
file.printf("FILE \"%s\" BINARY\n", filename.c_str());
file.printf("FILE \"%s\" BINARY\n", filename);
// determine submode
std::string tempstr;
@ -1404,9 +1405,9 @@ void output_track_metadata(int mode, util::core_file &file, int tracknum, const
// all tracks but the first one have a file offset
if (tracknum > 0)
file.printf("DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename.c_str(), uint32_t(discoffs), msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize));
file.printf("DATAFILE \"%s\" #%d %s // length in bytes: %d\n", filename, uint32_t(discoffs), msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize));
else
file.printf("DATAFILE \"%s\" %s // length in bytes: %d\n", filename.c_str(), msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize));
file.printf("DATAFILE \"%s\" %s // length in bytes: %d\n", filename, msf_string_from_frames(info.frames), info.frames * (info.datasize + info.subsize));
// tracks with pregaps get a START marker too
if (info.pregap > 0)