#159: Host rename | Packages upgrade | Code clean up

This commit is contained in:
Daniil Vinogradov
2025-03-16 23:30:16 +01:00
parent 2d562c914c
commit 6b83c9aedf
28 changed files with 192 additions and 170 deletions
+3
View File
@@ -1,4 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CMakePythonSetting">
<option name="pythonIntegrationState" value="YES" />
</component>
<component name="CMakeWorkspace" PROJECT_DIR="$PROJECT_DIR$" />
</project>
Generated
+5 -3
View File
@@ -2,15 +2,17 @@
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
<mapping directory="$PROJECT_DIR$/android-project/app/jni/SDL" vcs="Git" />
<mapping directory="$PROJECT_DIR$/android-project/app/jni/borealis" vcs="Git" />
<mapping directory="$PROJECT_DIR$/android-project/app/jni/vcpkg" vcs="Git" />
<mapping directory="$PROJECT_DIR$/app/platforms/android-project/app/jni/SDL" vcs="Git" />
<mapping directory="$PROJECT_DIR$/app/platforms/android-project/app/jni/moonlight" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/CImg" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/borealis" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/borealis/android-project/app/jni/SDL" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/borealis/android-project/app/jni/borealis" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/borealis/library/lib/extern/SDL" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/borealis/library/lib/extern/glfw" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/hacBrewPack" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/hacPack" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/mdns" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/moonlight-common-c" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/moonlight-common-c/enet" vcs="Git" />
<mapping directory="$PROJECT_DIR$/extern/vcpkg" vcs="Git" />
+2 -1
View File
@@ -27,7 +27,8 @@
"defines": [
"__SWITCH__",
"PLATFORM_SWITCH",
"BOREALIS_USE_DEKO3D"
"USE_GL_RENDERER",
"USE_MBEDTLS_CRYPTO"
],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
+1 -1
View File
@@ -14,7 +14,7 @@ using namespace brls;
class AppCell : public Box {
public:
AppCell(Host host, AppInfo app, int currentApp);
AppCell(const Host& host, const AppInfo& app, int currentApp);
BRLS_BIND(Image, image, "image");
BRLS_BIND(Label, title, "title");
+3 -3
View File
@@ -20,7 +20,7 @@ using namespace brls;
class AppListView : public Box {
public:
AppListView(Host host);
AppListView(const Host& host);
void onLayout() override;
void willAppear(bool resetState) override;
@@ -37,8 +37,8 @@ class AppListView : public Box {
GridView* gridView;
BRLS_BIND(Box, container, "container");
void setCurrentApp(AppInfo app);
void setCurrentApp(const AppInfo& app);
void terninateApp();
void updateAppList();
void updateFavoriteAction(AppCell* cell, Host host, AppInfo app);
void updateFavoriteAction(AppCell* cell, Host host, const AppInfo& app);
};
+3 -3
View File
@@ -10,7 +10,7 @@
#include <borealis.hpp>
void showAlert(
std::string message, std::function<void(void)> cb = [] {});
std::string message, const std::function<void(void)>& cb = [] {});
void showError(
std::string message, std::function<void(void)> cb = [] {});
brls::Dialog* createLoadingDialog(std::string text);
const std::string& message, const std::function<void(void)>& cb = [] {});
brls::Dialog* createLoadingDialog(const std::string& text);
+1 -1
View File
@@ -14,7 +14,7 @@ enum HostState { FETCHING, AVAILABLE, UNAVAILABLE };
class HostTab : public brls::Box {
public:
HostTab(Host host);
HostTab(const Host& host);
void reloadHost();
BRLS_BIND(brls::DetailCell, connect, "connect");
+4 -4
View File
@@ -14,7 +14,7 @@
class IngameOverlay : public brls::Box {
public:
explicit IngameOverlay(StreamingView* streamView);
~IngameOverlay() override;
~IngameOverlay() override = default;
brls::AppletFrame* getAppletFrame() override;
bool isTranslucent() override { return true; }
@@ -47,9 +47,9 @@ class OptionsTab : public brls::Box {
private:
StreamingView* streamView;
std::string getTextFromButtons(std::vector<brls::ControllerButton> buttons);
NVGcolor getColorFromButtons(std::vector<brls::ControllerButton> buttons);
void setupButtonsSelectorCell(brls::DetailCell* cell, std::vector<brls::ControllerButton> buttons);
static std::string getTextFromButtons(std::vector<brls::ControllerButton> buttons);
static NVGcolor getColorFromButtons(const std::vector<brls::ControllerButton>& buttons);
void setupButtonsSelectorCell(brls::DetailCell* cell, const std::vector<brls::ControllerButton>& buttons);
BRLS_BIND(brls::DetailCell, inputOverlayButton, "input_overlay");
BRLS_BIND(brls::SelectorCell, keyboardType, "keyboard_type");
+8 -6
View File
@@ -31,20 +31,22 @@ struct KeyboardLocale {
struct KeyboardState {
bool keys[_VK_KEY_MAX];
KeyboardState() = default;
explicit KeyboardState(const bool keys[_VK_KEY_MAX]): keys(keys) {}
};
class KeyboardView;
class ButtonView : public brls::Box {
public:
ButtonView(KeyboardView* keyboardView);
~ButtonView();
explicit ButtonView(KeyboardView* keyboardView);
~ButtonView() override;
brls::Label* charLabel;
void setKey(KeyboardKeys key);
void registerCallback();
bool triggerType = false;
KeyboardKeys key;
std::function<void(void)> event = NULL;
std::function<void(void)> event = nullptr;
void draw(NVGcontext* vg, float x, float y, float width, float height,
brls::Style style, brls::FrameContext* ctx) override;
@@ -67,8 +69,8 @@ class KeyboardView : public brls::Box {
inline static brls::VoidEvent shiftUpdated;
inline static std::vector<KeyboardLocale> getLocales() { return locales; }
KeyboardView(bool focusable);
~KeyboardView();
explicit KeyboardView(bool focusable);
~KeyboardView() override;
KeyboardState getKeyboardState();
short getKeyCode(KeyboardKeys key);
@@ -83,7 +85,7 @@ class KeyboardView : public brls::Box {
void createEnglishLayout();
void createNumpadLayout();
void createFullLayout();
void changeLang(int lang);
static void changeLang(int lang);
void createLocales();
inline static std::vector<KeyboardLocale> locales;
+1 -1
View File
@@ -16,7 +16,7 @@ using namespace brls;
class MainTabs : public brls::TabFrame {
public:
MainTabs();
void refillTabs();
void refillTabs(bool keepFocus = true);
static View* create();
void willAppear(bool resetState) override;
+4 -5
View File
@@ -8,10 +8,9 @@
#include "app_cell.hpp"
#include "BoxArtManager.hpp"
#include "Settings.hpp"
#include "main_tabs_view.hpp"
#include "streaming_view.hpp"
AppCell::AppCell(Host host, AppInfo app, int currentApp) {
AppCell::AppCell(const Host& host, const AppInfo& app, int currentApp) {
this->inflateFromXMLRes("xml/cells/app_cell.xml");
this->setFavorite(false);
@@ -26,7 +25,7 @@ AppCell::AppCell(Host host, AppInfo app, int currentApp) {
this->addGestureRecognizer(new TapGestureRecognizer(this));
this->registerClickAction([host, app](View* view) {
AppletFrame* frame = new AppletFrame(new StreamingView(host, app));
auto* frame = new AppletFrame(new StreamingView(host, app));
frame->setBackground(ViewBackground::NONE);
frame->setHeaderVisibility(brls::Visibility::GONE);
frame->setFooterVisibility(brls::Visibility::GONE);
@@ -37,7 +36,7 @@ AppCell::AppCell(Host host, AppInfo app, int currentApp) {
if (BoxArtManager::instance().has_boxart(app.app_id))
image->setImageFromFile(
BoxArtManager::instance().get_texture_path(app.app_id));
BoxArtManager::get_texture_path(app.app_id));
else {
ASYNC_RETAIN
GameStreamClient::instance().app_boxart(
@@ -48,7 +47,7 @@ AppCell::AppCell(Host host, AppInfo app, int currentApp) {
BoxArtManager::instance().set_data(result.value(),
app.app_id);
image->setImageFromFile(
BoxArtManager::instance().get_texture_path(app.app_id));
BoxArtManager::get_texture_path(app.app_id));
}
});
}
+12 -13
View File
@@ -8,12 +8,11 @@
#include "app_list_view.hpp"
#include "helper.hpp"
#include "main_tabs_view.hpp"
#include "streaming_view.hpp"
AppListView::AppListView(Host host) : host(host) {
AppListView::AppListView(const Host& host) : host(host) {
this->inflateFromXMLRes("xml/views/app_list_view.xml");
Label* label = new brls::Label();
auto* label = new brls::Label();
label->setText(brls::Hint::getKeyIcon(ControllerButton::BUTTON_BACK) +
" " + "app_list/terminate_current_app"_i18n);
label->setFontSize(24);
@@ -77,13 +76,13 @@ void AppListView::terninateApp() {
if (loading)
return;
Dialog* dialog =
auto* dialog =
new Dialog("app_list/terminate_prefix"_i18n + currentApp->name +
"app_list/terminate_postfix"_i18n);
dialog->addButton("common/cancel"_i18n, [] {});
dialog->addButton("app_list/terminate"_i18n, [dialog, this] {
dialog->addButton("app_list/terminate"_i18n, [this] {
if (loading)
return;
@@ -95,7 +94,7 @@ void AppListView::terninateApp() {
ASYNC_RETAIN
GameStreamClient::instance().quit(
host.address, [ASYNC_TOKEN](GSResult<bool> result) {
host.address, [ASYNC_TOKEN](const GSResult<bool>& result) {
ASYNC_RELEASE
loading = false;
@@ -129,7 +128,7 @@ void AppListView::updateAppList() {
ASYNC_RETAIN
GameStreamClient::instance().connect(
host.address, [ASYNC_TOKEN](GSResult<SERVER_DATA> result) {
host.address, [ASYNC_TOKEN](const GSResult<SERVER_DATA>& result) {
ASYNC_RELEASE
if (result.isSuccess()) {
@@ -138,7 +137,7 @@ void AppListView::updateAppList() {
ASYNC_RETAIN
GameStreamClient::instance().applist(
host.address,
[ASYNC_TOKEN, currentGame](GSResult<AppInfoList> result) {
[ASYNC_TOKEN, currentGame](const GSResult<AppInfoList>& result) {
ASYNC_RELEASE
loading = false;
@@ -149,7 +148,7 @@ void AppListView::updateAppList() {
AppInfoList sortedApps = result.value();
std::sort(
sortedApps.begin(), sortedApps.end(),
[this, currentGame](AppInfo l, AppInfo r) {
[this, currentGame](const AppInfo& l, const AppInfo& r) {
bool currentCondition =
l.app_id == currentGame &&
r.app_id != currentGame;
@@ -162,11 +161,11 @@ void AppListView::updateAppList() {
favoriteCondition;
});
for (AppInfo app : sortedApps) {
for (const AppInfo& app : sortedApps) {
if (app.app_id == currentGame)
setCurrentApp(app);
AppCell* cell =
auto* cell =
new AppCell(host, app, currentGame);
cell->setFavorite(
Settings::instance().is_favorite(
@@ -187,7 +186,7 @@ void AppListView::updateAppList() {
});
}
void AppListView::setCurrentApp(AppInfo app) {
void AppListView::setCurrentApp(const AppInfo& app) {
this->currentApp = app;
hintView->setVisibility(Visibility::VISIBLE);
getAppletFrameItem()->title =
@@ -207,7 +206,7 @@ void AppListView::onLayout() {
loader->layout();
}
void AppListView::updateFavoriteAction(AppCell* cell, Host host, AppInfo app) {
void AppListView::updateFavoriteAction(AppCell* cell, Host host, const AppInfo& app) {
bool isFavorite = Settings::instance().is_favorite(host, app.app_id);
cell->registerAction(
isFavorite ? "app_list/unstar"_i18n : "app_list/star"_i18n, BUTTON_Y,
-1
View File
@@ -6,7 +6,6 @@
//
#include "button_selecting_dialog.hpp"
#include "Settings.hpp"
ButtonSelectingDialog::ButtonSelectingDialog(
Box* box, std::function<void(std::vector<ControllerButton>)> callback,
+6 -6
View File
@@ -30,24 +30,24 @@ void FavoriteTab::refreshIfNeeded() {
void FavoriteTab::updateAppList() {
container->clearViews();
std::vector<Host> hosts = Settings::instance().hosts();
for (Host host : hosts) {
for (const Host& host : hosts) {
if (host.favorites.empty())
continue;
Header* header = new Header();
auto* header = new Header();
header->setTitle(host.hostname);
header->setLineBottom(0);
if (container->getChildren().size() > 0)
if (!container->getChildren().empty())
header->setMarginTop(40);
container->addView(header);
GridView* gridView = new GridView(5);
auto* gridView = new GridView(5);
for (App app : host.favorites) {
for (const App& app : host.favorites) {
AppInfo info{app.name, app.app_id};
AppCell* cell = new AppCell(host, info, 0);
auto* cell = new AppCell(host, info, 0);
gridView->addView(cell);
cell->registerAction(
+10 -8
View File
@@ -7,30 +7,32 @@
#include "helper.hpp"
#include <utility>
using namespace brls;
void showAlert(std::string message, std::function<void(void)> cb) {
auto alert = new brls::Dialog(message);
alert->addButton("common/close"_i18n, [alert, cb] { cb(); });
void showAlert(std::string message, const std::function<void(void)>& cb) {
auto alert = new brls::Dialog(std::move(message));
alert->addButton("common/close"_i18n, [cb] { cb(); });
alert->setCancelable(false);
alert->open();
}
void showError(std::string message, std::function<void(void)> cb) {
void showError(const std::string& message, const std::function<void(void)>& cb) {
showAlert("error/dialog_header"_i18n + "\n\n" + message, cb);
}
brls::Dialog* createLoadingDialog(std::string text) {
brls::Dialog* createLoadingDialog(const std::string& text) {
Style style = Application::getStyle();
Box* holder = new Box(Axis::COLUMN);
Label* label = new Label();
auto* label = new Label();
label->setText(text);
label->setFontSize(style["brls/dialog/fontSize"]);
label->setHorizontalAlign(HorizontalAlign::CENTER);
label->setMarginBottom(21);
ProgressSpinner* spinner = new ProgressSpinner(ProgressSpinnerSize::LARGE);
auto* spinner = new ProgressSpinner(ProgressSpinnerSize::LARGE);
spinner->View::setSize(Size(92, 92));
holder->addView(label);
@@ -42,7 +44,7 @@ brls::Dialog* createLoadingDialog(std::string text) {
style["brls/dialog/paddingLeftRight"], 28,
style["brls/dialog/paddingLeftRight"]);
Dialog* dialog = new Dialog(holder);
auto* dialog = new Dialog(holder);
dialog->setCancelable(false);
dialog->setFocusable(true);
dialog->setHideHighlight(true);
+22 -7
View File
@@ -13,7 +13,7 @@
using namespace brls::literals;
HostTab::HostTab(Host host) : host(host) {
HostTab::HostTab(const Host& host) : host(host) {
// Inflate the tab from the XML file
this->inflateFromXMLRes("xml/tabs/host.xml");
@@ -22,19 +22,33 @@ HostTab::HostTab(Host host) : host(host) {
reloadHost();
registerAction("Rename"_i18n, ControllerButton::BUTTON_START,
[this](View* view) {
std::string title = this->host.hostname;
Application::getPlatform()->getImeManager()->openForText(
[this](const std::string& text) {
this->host.hostname = text;
Settings::instance().add_host(this->host);
MainTabs::getInstanse()->refillTabs();
},
"Rename Host"_i18n, "", 60, title, 0);
return true;
});
connect->registerClickAction([this](View* view) {
switch (state) {
case AVAILABLE:
this->present(new AppListView(this->host));
break;
case UNAVAILABLE:
if (GameStreamClient::instance().can_wake_up_host(this->host)) {
if (GameStreamClient::can_wake_up_host(this->host)) {
Dialog* loader =
createLoadingDialog("host/wake_up_message"_i18n);
loader->open();
GameStreamClient::instance().wake_up_host(
this->host, [this, loader](GSResult<bool> result) {
GameStreamClient::wake_up_host(
this->host, [this, loader](const GSResult<bool>& result) {
loader->close([this, result] {
if (result.isSuccess()) {
reloadHost();
@@ -51,8 +65,8 @@ HostTab::HostTab(Host host) : host(host) {
return true;
});
remove->registerClickAction([this, host](View* view) {
Dialog* dialog = new Dialog("host/remove_message"_i18n);
remove->registerClickAction([host](View* view) {
auto* dialog = new Dialog("host/remove_message"_i18n);
dialog->addButton("common/cancel"_i18n, [] {});
dialog->addButton("common/remove"_i18n, [host] {
Settings::instance().remove_host(host);
@@ -67,11 +81,12 @@ HostTab::HostTab(Host host) : host(host) {
void HostTab::reloadHost() {
state = FETCHING;
header->setTitle("host/status"_i18n + ": " + "host/fetching"_i18n);
header->setSubtitle(host.address);
connect->setText("host/wait"_i18n);
ASYNC_RETAIN
GameStreamClient::instance().connect(
host.address, [ASYNC_TOKEN](GSResult<SERVER_DATA> result) {
host.address, [ASYNC_TOKEN](const GSResult<SERVER_DATA>& result) {
ASYNC_RELEASE
if (result.isSuccess()) {
+28 -31
View File
@@ -13,7 +13,6 @@
#include "ingame_overlay_view.hpp"
#include "streaming_input_overlay.hpp"
#include "button_selecting_dialog.hpp"
#include <libretro-common/retro_timers.h>
#include <iomanip>
#include <sstream>
@@ -53,7 +52,7 @@ IngameOverlay::IngameOverlay(StreamingView* streamView)
}));
applet->addGestureRecognizer(new TapGestureRecognizer(
[this](TapGestureStatus status, Sound* sound) {}));
[](TapGestureStatus status, Sound* sound) {}));
getAppletFrameItem()->title =
streamView->getHost().hostname + ": " + streamView->getApp().name;
@@ -62,8 +61,6 @@ IngameOverlay::IngameOverlay(StreamingView* streamView)
brls::AppletFrame* IngameOverlay::getAppletFrame() { return applet; }
IngameOverlay::~IngameOverlay() {}
// MARK: - Logout Tab
LogoutTab::LogoutTab(StreamingView* streamView) : streamView(streamView) {
this->inflateFromXMLRes("xml/views/ingame_overlay/logout_tab.xml");
@@ -131,10 +128,10 @@ OptionsTab::OptionsTab(StreamingView* streamView) : streamView(streamView) {
std::to_string(Settings::instance().get_volume()) + "%");
float amplification =
Settings::instance().get_volume_amplification() ? 500.0f : 100.0f;
float progress = Settings::instance().get_volume() / amplification;
float progress = (float) Settings::instance().get_volume() / amplification;
volumeSlider->getProgressEvent()->subscribe(
[this, amplification](float progress) {
int volume = progress * amplification;
int volume = int(progress * amplification);
Settings::instance().set_volume(volume);
volumeHeader->setSubtitle(std::to_string(volume) + "%");
});
@@ -150,20 +147,20 @@ OptionsTab::OptionsTab(StreamingView* streamView) : streamView(streamView) {
rumbleForceSlider->setProgress(rumbleForceProgress);
float mouseProgress =
(Settings::instance().get_mouse_speed_multiplier() / 100.0f);
((float) Settings::instance().get_mouse_speed_multiplier() / 100.0f);
mouseSlider->getProgressEvent()->subscribe([this](float value) {
float multiplier = value * 1.5f + 0.5f;
std::stringstream stream;
stream << std::fixed << std::setprecision(1) << multiplier;
mouseHeader->setSubtitle("x" + stream.str());
Settings::instance().set_mouse_speed_multiplier(value * 100);
Settings::instance().set_mouse_speed_multiplier(int(value * 100));
});
mouseSlider->setProgress(mouseProgress);
inputOverlayButton->setText("streaming/mouse_input"_i18n);
inputOverlayButton->registerClickAction([this, streamView](View* view) {
inputOverlayButton->registerClickAction([this](View* view) {
this->dismiss([this]() {
StreamingInputOverlay* overlay =
auto* overlay =
new StreamingInputOverlay(this->streamView);
Application::pushActivity(new Activity(overlay));
});
@@ -175,15 +172,15 @@ OptionsTab::OptionsTab(StreamingView* streamView) : streamView(streamView) {
keyboardType->setText("settings/keyboard_type"_i18n);
keyboardType->setData(keyboardTypes);
switch (Settings::instance().get_keyboard_type()) {
GET_SETTINGS(keyboardType, COMPACT, 0);
GET_SETTINGS(keyboardType, FULLSIZED, 1);
DEFAULT;
GET_SETTINGS(keyboardType, COMPACT, 0)
GET_SETTINGS(keyboardType, FULLSIZED, 1)
DEFAULT
}
keyboardType->getEvent()->subscribe([](int selected) {
switch (selected) {
SET_SETTING(0, set_keyboard_type(COMPACT));
SET_SETTING(1, set_keyboard_type(FULLSIZED));
DEFAULT;
SET_SETTING(0, set_keyboard_type(COMPACT))
SET_SETTING(1, set_keyboard_type(FULLSIZED))
DEFAULT
}
});
@@ -192,25 +189,25 @@ OptionsTab::OptionsTab(StreamingView* streamView) : streamView(streamView) {
keyboardFingers->setText("settings/keyboard_fingers"_i18n);
keyboardFingers->setData(keyboardFingersOptions);
switch (Settings::instance().get_keyboard_fingers()) {
GET_SETTINGS(keyboardFingers, 3, 0);
GET_SETTINGS(keyboardFingers, 4, 1);
GET_SETTINGS(keyboardFingers, 5, 2);
GET_SETTINGS(keyboardFingers, -1, 3);
DEFAULT;
GET_SETTINGS(keyboardFingers, 3, 0)
GET_SETTINGS(keyboardFingers, 4, 1)
GET_SETTINGS(keyboardFingers, 5, 2)
GET_SETTINGS(keyboardFingers, -1, 3)
DEFAULT
}
keyboardFingers->getEvent()->subscribe([](int selected) {
switch (selected) {
SET_SETTING(0, set_keyboard_fingers(3));
SET_SETTING(1, set_keyboard_fingers(4));
SET_SETTING(2, set_keyboard_fingers(5));
SET_SETTING(3, set_keyboard_fingers(-1));
DEFAULT;
SET_SETTING(0, set_keyboard_fingers(3))
SET_SETTING(1, set_keyboard_fingers(4))
SET_SETTING(2, set_keyboard_fingers(5))
SET_SETTING(3, set_keyboard_fingers(-1))
DEFAULT
}
});
touchscreenMouseMode->init("settings/touchscreen_mouse_mode"_i18n,
Settings::instance().touchscreen_mouse_mode(),
[this](bool value) {
[](bool value) {
Settings::instance().set_touchscreen_mouse_mode(value);
});
@@ -232,8 +229,8 @@ OptionsTab::~OptionsTab() { Settings::instance().save(); }
std::string
OptionsTab::getTextFromButtons(std::vector<ControllerButton> buttons) {
std::string buttonsText = "";
if (buttons.size() > 0) {
std::string buttonsText;
if (!buttons.empty()) {
for (int i = 0; i < buttons.size(); i++) {
buttonsText += brls::Hint::getKeyIcon(buttons[i], true);
if (i < buttons.size() - 1)
@@ -246,13 +243,13 @@ OptionsTab::getTextFromButtons(std::vector<ControllerButton> buttons) {
}
NVGcolor
OptionsTab::getColorFromButtons(std::vector<brls::ControllerButton> buttons) {
OptionsTab::getColorFromButtons(const std::vector<brls::ControllerButton>& buttons) {
Theme theme = Application::getTheme();
return buttons.empty() ? theme["brls/text_disabled"]
: theme["brls/list/listItem_value_color"];
}
void OptionsTab::setupButtonsSelectorCell(brls::DetailCell* cell, std::vector<ControllerButton> buttons) {
void OptionsTab::setupButtonsSelectorCell(brls::DetailCell* cell, const std::vector<ControllerButton>& buttons) {
cell->setDetailText(getTextFromButtons(buttons));
cell->setDetailTextColor(getColorFromButtons(buttons));
}
+7 -10
View File
@@ -173,7 +173,7 @@ void ButtonView::setKey(KeyboardKeys key) {
}
void ButtonView::registerCallback() {
TapGestureRecognizer* tapRecognizer =
auto* tapRecognizer =
new TapGestureRecognizer([this](TapGestureStatus status, Sound* sound) {
if (!triggerType) {
this->playClickAnimation(
@@ -191,7 +191,7 @@ void ButtonView::registerCallback() {
if (!dummy)
keysState[key] = false;
if (event != NULL)
if (event != nullptr)
event();
break;
default:
@@ -212,7 +212,7 @@ void ButtonView::registerCallback() {
break;
case brls::GestureState::END:
keysState[key] = !keysState[key];
if (event != NULL)
if (event != nullptr)
event();
if (!keysState[key])
@@ -280,15 +280,12 @@ void KeyboardView::draw(NVGcontext* vg, float x, float y, float width,
}
KeyboardState KeyboardView::getKeyboardState() {
KeyboardState state;
for (int i = 0; i < _VK_KEY_MAX; i++)
state.keys[i] = keysState[i];
return state;
return KeyboardState(keysState);
}
short KeyboardView::getKeyCode(KeyboardKeys key) { return KeyboardCodes[key]; }
short KeyboardView::getKeyCode(KeyboardKeys key) {
return KeyboardCodes[key];
}
View* KeyboardView::getParentNavigationDecision(View* from, View* newFocus,
FocusDirection direction) {
+1 -1
View File
@@ -58,7 +58,7 @@ bool startFromArgs(int argc, char** argv) {
if (auto it = std::find_if(hosts.begin(), hosts.end(), [args](const Host& host) {
return host.mac == args[0];
}); it != std::end(hosts)) {
Host host = *it;
const Host& host = *it;
AppInfo info { args[2], stoi(args[1]) };
auto* frame = new AppletFrame(new StreamingView(host, info));
+15 -5
View File
@@ -29,11 +29,21 @@ void MainTabs::willAppear(bool resetState) {
void MainTabs::updateFavoritesIfNeeded() {
if (lastHasAnyFavorites != Settings::instance().has_any_favorite()) {
refillTabs();
refillTabs(false);
}
}
void MainTabs::refillTabs() {
void MainTabs::refillTabs(bool keepFocus) {
int newFocus = 0;
if (keepFocus) {
for (int i = 0; i < this->sidebar->getItemsSize(); i++) {
auto item = dynamic_cast<SidebarItem*>(this->sidebar->getItem(i));
if (item && item->isActive())
newFocus = i;
}
}
clearTabs();
bool hasAnyFavorite = Settings::instance().has_any_favorite();
@@ -44,18 +54,18 @@ void MainTabs::refillTabs() {
lastHasAnyFavorites = hasAnyFavorite;
auto hosts = Settings::instance().hosts();
for (Host host : hosts) {
for (const Host& host : hosts) {
addTab(host.hostname, [host] { return new HostTab(host); });
}
if (hosts.size() > 0)
if (!hosts.empty())
addSeparator();
addTab("tabs/add_host"_i18n, AddHostTab::create);
addTab("tabs/settings"_i18n, SettingsTab::create);
addSeparator();
addTab("tabs/about"_i18n, AboutTab::create);
focusTab(0);
sidebar->setContentOffsetY(-40, false);
focusTab(newFocus);
}
View* MainTabs::create() { return new MainTabs(); }
+7 -8
View File
@@ -21,13 +21,12 @@ MoonlightInputManager::MoonlightInputManager() {
if (offset.x != 0 || offset.y != 0) {
float multiplier =
Settings::instance().get_mouse_speed_multiplier() / 100.f *
1.5f +
0.5f;
(float) Settings::instance().get_mouse_speed_multiplier() / 100.f *
1.5f + 0.5f;
if (!this->inputDropped) {
LiSendMouseMoveEvent(offset.x * multiplier,
offset.y * multiplier);
LiSendMouseMoveEvent(short(offset.x * multiplier),
short(offset.y * multiplier));
}
}
});
@@ -160,7 +159,7 @@ void MoonlightInputManager::dropInput() {
// Drop keyboard state
for (int i = BRLS_KBD_KEY_SPACE; i < BrlsKeyboardScancode::BRLS_KBD_KEY_LAST; i++) {
int vkKey = MoonlightInputManager::glfwKeyToVKKey((BrlsKeyboardScancode)i);
short vkKey = MoonlightInputManager::glfwKeyToVKKey((BrlsKeyboardScancode)i);
LiSendKeyboardEvent(vkKey, KEY_ACTION_UP, 0);
}
@@ -234,7 +233,7 @@ GamepadState MoonlightInputManager::getControllerState(int controllerNum,
SET_GAME_PAD_STATE(RS_CLK_FLAG, brls::BUTTON_RSB);
auto guideKeys = Settings::instance().guide_key_options().buttons;
bool guideCombo = guideKeys.size() > 0;
bool guideCombo = !guideKeys.empty();
for (auto key : guideKeys)
guideCombo &= controller.buttons[key];
@@ -300,7 +299,7 @@ void MoonlightInputManager::handleInput() {
brls::Application::getPlatform()->getInputManager()->updateTouchStates(&states);
//Do not use gamepad for mouse controll assist if touchscreen mode enabled
bool specialKey = Settings::instance().touchscreen_mouse_mode() ? false : states.size() == 1;
bool specialKey = !Settings::instance().touchscreen_mouse_mode() && states.size() == 1;
handleControllers(specialKey);
+24 -24
View File
@@ -19,7 +19,7 @@ extern "C" {
//#else
//#define DECODER_BUFFER_SIZE 92 * 1024 * 2
//#endif
#define DECODER_BUFFER_SIZE 1024 * 1024
#define DECODER_BUFFER_SIZE (1024 * 1024)
#if defined(PLATFORM_ANDROID)
#include <jni.h>
@@ -42,13 +42,13 @@ FFmpegVideoDecoder::FFmpegVideoDecoder() {
// av_hwdevice_ctx_init(deviceRef);
}
FFmpegVideoDecoder::~FFmpegVideoDecoder() {}
FFmpegVideoDecoder::~FFmpegVideoDecoder() = default;
void ffmpegLog(void* ptr, int level, const char* fmt, va_list vargs) {
std::string message;
va_list ap_copy;
va_copy(ap_copy, vargs);
size_t len = vsnprintf(0, 0, fmt, ap_copy);
size_t len = vsnprintf(nullptr, 0, fmt, ap_copy);
message.resize(len + 1); // need space for NUL
vsnprintf(&message[0], len + 1,fmt, vargs);
message.resize(len); // remove the NUL
@@ -93,13 +93,13 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
}
#endif
if (m_decoder == NULL) {
if (m_decoder == nullptr) {
brls::Logger::error("FFmpeg: Couldn't find decoder");
return -1;
}
m_decoder_context = avcodec_alloc_context3(m_decoder);
if (m_decoder_context == NULL) {
if (m_decoder_context == nullptr) {
brls::Logger::error("FFmpeg: Couldn't allocate context");
return -1;
}
@@ -138,7 +138,7 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
// m_decoder_context->pix_fmt = AV_PIX_FMT_NV12;
#endif
int err = avcodec_open2(m_decoder_context, m_decoder, NULL);
int err = avcodec_open2(m_decoder_context, m_decoder, nullptr);
if (err < 0) {
char error[512];
av_strerror(err, error, sizeof(error));
@@ -147,9 +147,9 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
}
tmp_frame = av_frame_alloc();
for (int i = 0; i < m_frames_count; i++) {
m_frames[i] = av_frame_alloc();
if (m_frames[i] == NULL) {
for (auto & m_frame : m_frames) {
m_frame = av_frame_alloc();
if (m_frame == nullptr) {
brls::Logger::error("FFmpeg: Couldn't allocate frame");
return -1;
}
@@ -160,16 +160,16 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
m_frames[i]->format = AV_PIX_FMT_MEDIACODEC;
#else
if (video_format & VIDEO_FORMAT_MASK_10BIT)
m_frames[i]->format = AV_PIX_FMT_P010;
m_frame->format = AV_PIX_FMT_P010;
else
m_frames[i]->format = AV_PIX_FMT_NV12;
m_frame->format = AV_PIX_FMT_NV12;
#endif
m_frames[i]->width = width;
m_frames[i]->height = height;
m_frame->width = width;
m_frame->height = height;
// Need to align Switch frame to 256, need to de reviewed
#if defined(PLATFORM_SWITCH) && !defined(BOREALIS_USE_DEKO3D)
int err = av_frame_get_buffer(m_frames[i], 256);
int err = av_frame_get_buffer(m_frame, 256);
if (err < 0) {
char errs[64];
brls::Logger::error("FFmpeg: Couldn't allocate frame buffer: {}", av_make_error_string(errs, 64, err));
@@ -177,17 +177,17 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
}
for (int j = 0; j < 2; j++) {
uintptr_t ptr = (uintptr_t)m_frames[i]->data[j];
uintptr_t ptr = (uintptr_t)m_frame->data[j];
uintptr_t dst = (((ptr)+(256)-1)&~((256)-1));
uintptr_t gap = dst - ptr;
m_frames[i]->data[j] += gap;
m_frame->data[j] += gap;
}
#endif
}
m_ffmpeg_buffer =
(char*)malloc(DECODER_BUFFER_SIZE + AV_INPUT_BUFFER_PADDING_SIZE);
if (m_ffmpeg_buffer == NULL) {
if (m_ffmpeg_buffer == nullptr) {
brls::Logger::error("FFmpeg: Not enough memory");
cleanup();
return -1;
@@ -204,7 +204,7 @@ int FFmpegVideoDecoder::setup(int video_format, int width, int height,
#endif
if (Settings::instance().use_hw_decoding() && hwType != AV_HWDEVICE_TYPE_NONE) {
if ((err = av_hwdevice_ctx_create(&hw_device_ctx, hwType, NULL, NULL, 0)) < 0) {
if ((err = av_hwdevice_ctx_create(&hw_device_ctx, hwType, nullptr, nullptr, 0)) < 0) {
char error[512];
av_strerror(err, error, sizeof(error));
brls::Logger::error("FFmpeg: Error initializing hardware decoder - {}", error);
@@ -231,7 +231,7 @@ void FFmpegVideoDecoder::cleanup() {
if (m_decoder_context) {
avcodec_close(m_decoder_context);
av_free(m_decoder_context);
m_decoder_context = NULL;
m_decoder_context = nullptr;
}
// if (m_frames) {
@@ -282,7 +282,7 @@ int FFmpegVideoDecoder::submit_decode_unit(PDECODE_UNIT decode_unit) {
m_video_decode_stats_progress.total_frames++;
int length = 0;
while (entry != NULL) {
while (entry != nullptr) {
if (length > DECODER_BUFFER_SIZE) {
brls::Logger::error("FFmpeg: Big buffer to decode... !");
}
@@ -343,7 +343,7 @@ int FFmpegVideoDecoder::submit_decode_unit(PDECODE_UNIT decode_unit) {
}
m_frame = get_frame(true);
if (m_frame != NULL)
if (m_frame != nullptr)
AVFrameHolder::instance().push(m_frame);
}
} else {
@@ -397,7 +397,7 @@ AVFrame* FFmpegVideoDecoder::get_frame(bool native_frame) {
char a[AV_ERROR_MAX_STRING_SIZE] = { 0 };
brls::Logger::error("FFmpeg: Error receiving frame with error {}", av_make_error_string(a, AV_ERROR_MAX_STRING_SIZE, err));
return NULL;
return nullptr;
}
if (hw_device_ctx) {
@@ -418,7 +418,7 @@ AVFrame* FFmpegVideoDecoder::get_frame(bool native_frame) {
if ((err = av_hwframe_transfer_data(resultFrame, decodeFrame, 0)) < 0) {
char a[AV_ERROR_MAX_STRING_SIZE] = { 0 };
brls::Logger::error("FFmpeg: Error transferring the data to system memory with error {}", av_make_error_string(a, AV_ERROR_MAX_STRING_SIZE, err));
return NULL;
return nullptr;
}
av_frame_copy_props(resultFrame, decodeFrame);
@@ -437,7 +437,7 @@ AVFrame* FFmpegVideoDecoder::get_frame(bool native_frame) {
av_strerror(err, error, sizeof(error));
brls::Logger::error("FFmpeg: Receive failed - %d/%s", err, error);
}
return NULL;
return nullptr;
}
VideoDecodeStats* FFmpegVideoDecoder::video_decode_stats() {
+13 -13
View File
@@ -117,7 +117,7 @@ StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host),
if (status.state == brls::GestureState::END) {
Logger::debug("Left mouse click");
MoonlightInputManager::instance().leftMouseClick();
MoonlightInputManager::leftMouseClick();
lMouseKeyGate = true;
delay(200, [] { lMouseKeyGate = false; });
}
@@ -129,7 +129,7 @@ StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host),
if (status.state == brls::GestureState::END) {
Logger::debug("Right mouse click");
MoonlightInputManager::instance().rightMouseClick();
MoonlightInputManager::rightMouseClick();
}
}));
@@ -187,14 +187,14 @@ StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host),
if (state.state == brls::GestureState::START)
this->touchScrollCounter = 0;
int threashhold = state.delta.y / 25;
if (threashhold != this->touchScrollCounter) {
int threshold = int(state.delta.y / 25);
if (threshold != this->touchScrollCounter) {
Logger::debug("Scroll on: {}",
threashhold - this->touchScrollCounter);
threshold - this->touchScrollCounter);
int invert = Settings::instance().swap_mouse_scroll() ? -1 : 1;
char scrollCount = threashhold - this->touchScrollCounter;
char scrollCount = threshold - this->touchScrollCounter;
LiSendScrollEvent(scrollCount * invert);
this->touchScrollCounter = threashhold;
this->touchScrollCounter = threshold;
}
}));
@@ -232,7 +232,7 @@ StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host),
}
void StreamingView::onFocusGained() {
View::onFocusGained();
Box::onFocusGained();
MoonlightInputManager::instance().setInputEnabled(true);
@@ -255,7 +255,7 @@ void StreamingView::onFocusGained() {
}
void StreamingView::onFocusLost() {
View::onFocusLost();
Box::onFocusLost();
MoonlightInputManager::instance().setInputEnabled(false);
MoonlightInputManager::instance().dropInput();
@@ -282,7 +282,7 @@ void StreamingView::draw(NVGcontext* vg, float x, float y, float width,
return;
}
session->draw(vg, width, height);
session->draw(vg, (int) width, (int) height);
if (!tempInputLock && session->is_active())
handleInput();
@@ -349,11 +349,11 @@ void StreamingView::draw(NVGcontext* vg, float x, float y, float width,
nvgFontBlur(vg, 1);
nvgFillColor(vg, nvgRGBA(0, 0, 0, 255));
nvgTextBox(vg, 20, 30, width, output, NULL);
nvgTextBox(vg, 20, 30, width, output, nullptr);
nvgFontBlur(vg, 0);
nvgFillColor(vg, nvgRGBA(0, 255, 0, 255));
nvgTextBox(vg, 20, 30, width, output, NULL);
nvgTextBox(vg, 20, 30, width, output, nullptr);
}
Box::draw(vg, x, y, width, height, style, ctx);
@@ -420,7 +420,7 @@ void StreamingView::handleInput() {
MoonlightInputManager::instance().handleInput();
}
if (Application::currentTouchState.size() > 0) {
if (!Application::currentTouchState.empty()) {
setBottomBarStatus("2");
if (bottombarDelayTask != -1)
-1
View File
@@ -2,7 +2,6 @@
#include "Data.hpp"
#include "Settings.hpp"
#include "nanovg.h"
#include <algorithm>
#include <mutex>
#include <CImg.h>
+9 -11
View File
@@ -1,9 +1,9 @@
#include "Settings.hpp"
#include <jansson.h>
#include <algorithm>
#include <string.h>
#include <cstring>
#include <iomanip>
#include <limits.h>
#include <climits>
#include <sys/stat.h>
using namespace brls;
@@ -58,7 +58,7 @@ static int mkdirtree(const char* directory) {
return 0;
}
void Settings::set_working_dir(std::string working_dir) {
void Settings::set_working_dir(const std::string& working_dir) {
m_working_dir = working_dir;
m_key_dir = working_dir + "/key";
m_boxart_dir = working_dir + "/boxart";
@@ -153,17 +153,15 @@ bool Settings::is_favorite(const Host& host, int app_id) {
}
bool Settings::has_any_favorite() {
for (auto host : m_hosts) {
if (!host.favorites.empty())
return true;
}
return false;
return std::any_of(m_hosts.begin(), m_hosts.end(), [&](const auto &item) {
return !item.favorites.empty();
});
}
void Settings::load() {
loadBaseLayouts();
json_t* root = json_load_file((m_working_dir + "/settings.json").c_str(), 0, NULL);
json_t* root = json_load_file((m_working_dir + "/settings.json").c_str(), 0, nullptr);
if (root && json_typeof(root) == JSON_OBJECT) {
if (json_t* hosts = json_object_get(root, "hosts")) {
@@ -449,7 +447,7 @@ void Settings::save() {
if (root) {
if (json_t* hosts = json_array()) {
for (auto host: m_hosts) {
for (const auto& host: m_hosts) {
if (json_t* json = json_object()) {
json_object_set_new(json, "address", json_string(host.address.c_str()));
json_object_set_new(json, "hostname", json_string(host.hostname.c_str()));
@@ -525,7 +523,7 @@ void Settings::save() {
}
if (json_t* hosts = json_array()) {
for (auto mappint_layout: m_mapping_laouts) {
for (const auto& mappint_layout: m_mapping_laouts) {
if (!mappint_layout.editable) continue;
if (json_t* json = json_object()) {
+1 -1
View File
@@ -47,7 +47,7 @@ struct Host {
class Settings : public Singleton<Settings> {
public:
void set_working_dir(std::string working_dir);
void set_working_dir(const std::string& working_dir);
[[nodiscard]] std::string key_dir() const { return m_key_dir; }