1
0
mirror of https://github.com/GOSTSec/sgminer synced 2025-01-10 23:08:07 +00:00

Recreate curses windows on windows when a device is hotplugged to allow window resizing without crashing.

This commit is contained in:
Con Kolivas 2013-08-09 16:57:16 +10:00
parent 9a21a47334
commit 106e461f21

View File

@ -2273,9 +2273,16 @@ static void check_winsizes(void)
} }
} }
static void switch_logsize(void) static void disable_curses_windows(void);
static void enable_curses_windows(void);
static void switch_logsize(bool newdevs)
{ {
if (curses_active_locked()) { if (curses_active_locked()) {
#ifdef WIN32
if (newdevs)
disable_curses_windows();
#endif
if (opt_compact) { if (opt_compact) {
logstart = devcursor + 1; logstart = devcursor + 1;
logcursor = logstart + 1; logcursor = logstart + 1;
@ -2283,9 +2290,13 @@ static void switch_logsize(void)
logstart = devcursor + most_devices + 1; logstart = devcursor + most_devices + 1;
logcursor = logstart + 1; logcursor = logstart + 1;
} }
#ifdef WIN32
if (newdevs)
enable_curses_windows();
#endif
unlock_curses(); unlock_curses();
check_winsizes();
} }
check_winsizes();
} }
/* For mandatory printing when mutex is already locked */ /* For mandatory printing when mutex is already locked */
@ -2303,7 +2314,7 @@ void _wlogprint(const char *str)
} }
} }
#else #else
static void switch_logsize(void) static void switch_logsize(bool __maybe_unused newdevs)
{ {
} }
#endif #endif
@ -2885,18 +2896,23 @@ static bool get_upstream_work(struct work *work, CURL *curl)
} }
#ifdef HAVE_CURSES #ifdef HAVE_CURSES
static void disable_curses_windows(void)
{
leaveok(logwin, false);
leaveok(statuswin, false);
leaveok(mainwin, false);
nocbreak();
echo();
delwin(logwin);
delwin(statuswin);
}
static void disable_curses(void) static void disable_curses(void)
{ {
if (curses_active_locked()) { if (curses_active_locked()) {
use_curses = false; use_curses = false;
curses_active = false; curses_active = false;
leaveok(logwin, false); disable_curses_windows();
leaveok(statuswin, false);
leaveok(mainwin, false);
nocbreak();
echo();
delwin(logwin);
delwin(statuswin);
delwin(mainwin); delwin(mainwin);
endwin(); endwin();
#ifdef WIN32 #ifdef WIN32
@ -4442,7 +4458,7 @@ retry:
opt_compact = false; opt_compact = false;
want_per_device_stats = false; want_per_device_stats = false;
wlogprint("Output mode reset to normal\n"); wlogprint("Output mode reset to normal\n");
switch_logsize(); switch_logsize(false);
goto retry; goto retry;
} else if (!strncasecmp(&input, "d", 1)) { } else if (!strncasecmp(&input, "d", 1)) {
opt_debug ^= true; opt_debug ^= true;
@ -4454,7 +4470,7 @@ retry:
} else if (!strncasecmp(&input, "m", 1)) { } else if (!strncasecmp(&input, "m", 1)) {
opt_compact ^= true; opt_compact ^= true;
wlogprint("Compact mode %s\n", opt_compact ? "enabled" : "disabled"); wlogprint("Compact mode %s\n", opt_compact ? "enabled" : "disabled");
switch_logsize(); switch_logsize(false);
goto retry; goto retry;
} else if (!strncasecmp(&input, "p", 1)) { } else if (!strncasecmp(&input, "p", 1)) {
want_per_device_stats ^= true; want_per_device_stats ^= true;
@ -7009,16 +7025,10 @@ static void fork_monitor()
#endif // defined(unix) #endif // defined(unix)
#ifdef HAVE_CURSES #ifdef HAVE_CURSES
void enable_curses(void) { static void enable_curses_windows(void)
{
int x,y; int x,y;
lock_curses();
if (curses_active) {
unlock_curses();
return;
}
mainwin = initscr();
getmaxyx(mainwin, y, x); getmaxyx(mainwin, y, x);
statuswin = newwin(logstart, x, 0, 0); statuswin = newwin(logstart, x, 0, 0);
leaveok(statuswin, true); leaveok(statuswin, true);
@ -7028,6 +7038,16 @@ void enable_curses(void) {
leaveok(logwin, true); leaveok(logwin, true);
cbreak(); cbreak();
noecho(); noecho();
}
void enable_curses(void) {
lock_curses();
if (curses_active) {
unlock_curses();
return;
}
mainwin = initscr();
enable_curses_windows();
curses_active = true; curses_active = true;
statusy = logstart; statusy = logstart;
unlock_curses(); unlock_curses();
@ -7190,11 +7210,8 @@ struct _cgpu_devid_counter {
static void adjust_mostdevs(void) static void adjust_mostdevs(void)
{ {
// device window resize crashes on windows - disable resize now
#ifndef WIN32
if (total_devices - zombie_devs > most_devices) if (total_devices - zombie_devs > most_devices)
most_devices = total_devices - zombie_devs; most_devices = total_devices - zombie_devs;
#endif
} }
bool add_cgpu(struct cgpu_info *cgpu) bool add_cgpu(struct cgpu_info *cgpu)
@ -7309,7 +7326,7 @@ static void hotplug_process()
} }
adjust_mostdevs(); adjust_mostdevs();
switch_logsize(); switch_logsize(true);
} }
static void *hotplug_thread(void __maybe_unused *userdata) static void *hotplug_thread(void __maybe_unused *userdata)
@ -7634,12 +7651,7 @@ int main(int argc, char *argv[])
quit(1, "All devices disabled, cannot mine!"); quit(1, "All devices disabled, cannot mine!");
#endif #endif
// device window resize crashes on windows - disable resize now
#ifdef WIN32
most_devices = total_devices + 1; // Allow space for 1 hotplug
#else
most_devices = total_devices; most_devices = total_devices;
#endif
load_temp_cutoffs(); load_temp_cutoffs();