mirror of
https://github.com/saymrwulf/xous-core.git
synced 2026-11-18 08:52:45 +00:00
fix for issue #145
This commit is contained in:
parent
ae60065040
commit
ce5a81878c
1 changed files with 28 additions and 16 deletions
|
|
@ -491,25 +491,37 @@ fn xmain() -> ! {
|
||||||
log::debug!("trying to switch to {:?} with token {:?}", switchapp.app_name.as_str().unwrap(), switchapp.token);
|
log::debug!("trying to switch to {:?} with token {:?}", switchapp.app_name.as_str().unwrap(), switchapp.token);
|
||||||
|
|
||||||
if let Some(new_app_token) = context_mgr.find_app_token_by_name(switchapp.app_name.as_str().unwrap()) {
|
if let Some(new_app_token) = context_mgr.find_app_token_by_name(switchapp.app_name.as_str().unwrap()) {
|
||||||
let authorized_switchers = vec![MAIN_MENU_NAME, ROOTKEY_MODAL_NAME, gam::STATUS_BAR_NAME];
|
if new_app_token != context_mgr.focused_app().unwrap_or([0, 0, 0, 0]) {
|
||||||
for switchers in authorized_switchers {
|
// two things:
|
||||||
if let Some(auth_token) = context_mgr.find_app_token_by_name(switchers) {
|
// 1. [0, 0, 0, 0] is simply a very unlikely GID because it's a 128 bit TRNG, and this allows us to handle
|
||||||
if auth_token == switchapp.token {
|
// the power-on case where we have no focused app cleanly.
|
||||||
context_mgr.notify_app_switch(new_app_token)
|
// 2. the `activate()` method on `context_mgr` does not handle app-to-app switches when you're the same app.
|
||||||
.unwrap_or_else(|_| {log::warn!("Application does not recognize focus changes")});
|
// this is because there is a rule which says if you're going to put an app on top of an app, take the old
|
||||||
match context_mgr.activate(&gfx, &mut canvases, new_app_token, false) {
|
// app and hide it, while also taking the new app and showing it. This is a race condition, and it results
|
||||||
Ok(_) => (),
|
// in the "same-app" switch ending up in a hidden state, because within the routine the entering state is
|
||||||
Err(_) => log::warn!("failed to switch to {}, silent error!", switchapp.app_name.as_str().unwrap()),
|
// set before the leaving state due to interior-mutability issues (see the block under the debug statement
|
||||||
|
// titled "resolving visibility rules"). The fix is to simply not issue a context switch if it's the same app.
|
||||||
|
// It saves CPU thrashing and also works around this problem. (see issue #145)
|
||||||
|
let authorized_switchers = vec![MAIN_MENU_NAME, ROOTKEY_MODAL_NAME, gam::STATUS_BAR_NAME];
|
||||||
|
for switchers in authorized_switchers {
|
||||||
|
if let Some(auth_token) = context_mgr.find_app_token_by_name(switchers) {
|
||||||
|
if auth_token == switchapp.token {
|
||||||
|
context_mgr.notify_app_switch(new_app_token)
|
||||||
|
.unwrap_or_else(|_| {log::warn!("Application does not recognize focus changes")});
|
||||||
|
match context_mgr.activate(&gfx, &mut canvases, new_app_token, false) {
|
||||||
|
Ok(_) => (),
|
||||||
|
Err(_) => log::warn!("failed to switch to {}, silent error!", switchapp.app_name.as_str().unwrap()),
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
// this message came from ourselves
|
||||||
// this message came from ourselves
|
if gam_token == switchapp.token {
|
||||||
if gam_token == switchapp.token {
|
match context_mgr.activate(&gfx, &mut canvases, new_app_token, true) {
|
||||||
match context_mgr.activate(&gfx, &mut canvases, new_app_token, true) {
|
Ok(_) => (),
|
||||||
Ok(_) => (),
|
Err(_) => log::warn!("failed to switch to {}, silent error!", switchapp.app_name.as_str().unwrap()),
|
||||||
Err(_) => log::warn!("failed to switch to {}, silent error!", switchapp.app_name.as_str().unwrap()),
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue