Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix drastic savestates, deepsleep, and screenshots #1387

Merged
merged 9 commits into from
Jan 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions src/common/system/screenshot.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,40 +145,51 @@ bool __screenshot_save(const uint32_t *buffer, const char *screenshot_path)
return true;
}

bool __screenshot_perform(bool(get_path)(char *))
bool __screenshot_perform(bool(get_path)(char *), pid_t p_id)
{
bool retval = false;
char path[512];
uint32_t *buffer;
pid_t ra_pid;

if ((ra_pid = process_searchpid("retroarch")) != 0) {
kill(ra_pid, SIGSTOP);
if (p_id != 0) {
kill(p_id, SIGSTOP);
}

buffer = __screenshot_buffer();

if (ra_pid != 0) {
kill(ra_pid, SIGCONT);
if (p_id != 0) {
kill(p_id, SIGCONT);
}

if (get_path(path)) {
retval = __screenshot_save(buffer, path);
}

free(buffer);

return retval;
}

pid_t get_game_pid(void)
{
pid_t p_id = process_searchpid("retroarch");
if (p_id == 0) {
p_id = process_searchpid("drastic");
}
return p_id;
}

bool screenshot_recent(void)
{
return __screenshot_perform(__get_path_recent);
return __screenshot_perform(__get_path_recent, get_game_pid());
}

bool screenshot_system(void)
{
return __screenshot_perform(__get_path_romscreen);
pid_t p_id = get_game_pid();
if (p_id != 0) {
return __screenshot_perform(__get_path_romscreen, p_id);
}
return false;
}

#endif // SCREENSHOT_H__
93 changes: 48 additions & 45 deletions src/keymon/keymon.c
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ int suspend(uint32_t mode)
(strcmp(comm, "(MainUI)")) &&
(strcmp(comm, "(tee)")) &&
(strncmp(comm, "(audioserver", 12)) &&
(strcmp(comm, "(batmon)"))){
(strcmp(comm, "(batmon)"))) {
kill(pid, (mode == 1) ? SIGTERM : SIGKILL);
ret++;
}
Expand Down Expand Up @@ -187,6 +187,52 @@ void shutdown(void)
exit(0);
}

//
// [onion] deepsleep if MainUI/gameSwitcher/retroarch is running
//
void deepsleep(void)
{
system_state_update();
if (system_state == MODE_MAIN_UI) {
short_pulse();
set_system_shutdown();
kill_mainUI();
}
else if (system_state == MODE_SWITCHER) {
short_pulse();
set_system_shutdown();
kill(system_state_pid, SIGTERM);
}
else if (system_state == MODE_GAME) {
if (check_autosave()) {
short_pulse();
set_system_shutdown();
screenshot_system();
terminate_retroarch();
}
}
else if (system_state == MODE_ADVMENU) {
short_pulse();
set_system_shutdown();
kill(system_state_pid, SIGQUIT);
}
else if (system_state == MODE_APPS) {
short_pulse();
remove(CMD_TO_RUN_PATH);
set_system_shutdown();
suspend(1);
}
else if (system_state == MODE_DRASTIC) {
short_pulse();
set_system_shutdown();
screenshot_system();
terminate_drastic();
}

sleep(30);
shutdown();
}

//
// Suspend interface
//
Expand Down Expand Up @@ -243,7 +289,7 @@ void suspend_exec(int timeout)
system_powersave_off();
resume();
usleep(150000);
shutdown();
deepsleep();
}
}

Expand All @@ -268,49 +314,6 @@ void suspend_exec(int timeout)
keyinput_enable();
}

//
// [onion] deepsleep if MainUI/gameSwitcher/retroarch is running
//
void deepsleep(void)
{
system_state_update();
if (system_state == MODE_MAIN_UI) {
short_pulse();
set_system_shutdown();
kill_mainUI();
}
else if (system_state == MODE_SWITCHER) {
short_pulse();
set_system_shutdown();
kill(system_state_pid, SIGTERM);
}
else if (system_state == MODE_GAME) {
if (check_autosave()) {
short_pulse();
set_system_shutdown();
screenshot_system();
terminate_retroarch();
}
}
else if (system_state == MODE_ADVMENU) {
short_pulse();
set_system_shutdown();
kill(system_state_pid, SIGQUIT);
}
else if (system_state == MODE_APPS) {
short_pulse();
remove(CMD_TO_RUN_PATH);
set_system_shutdown();
suspend(1);
}
else if (system_state == MODE_DRASTIC) {
short_pulse();
set_system_shutdown();
screenshot_system();
terminate_drastic();
}
}

void turnOffScreen(void)
{
int timeout = (settings.sleep_timer + SHUTDOWN_MIN) * 60000;
Expand Down
10 changes: 3 additions & 7 deletions src/keymon/menuButtonAction.h
Original file line number Diff line number Diff line change
Expand Up @@ -107,15 +107,11 @@ bool terminate_drastic(void)
usleep(200000); // 0.2s
system("sendkeys 1 0, 18 0");

uint32_t count = 12;

sprintf(fname, "/proc/%d", pid);
while (--count && exists(fname)) {
system("sendkeys 1 1, 18 1");
uint32_t count = 150; // 30s

while (--count && exists(fname))
usleep(200000); // 0.2s
system("sendkeys 1 0, 18 0");
sleep(1);
}
return true;
}
return false;
Expand Down
Loading
Loading