Skip to content

Commit

Permalink
Implemented custom actions for Home and Screenshot buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
XITRIX committed Nov 3, 2024
1 parent 3f80695 commit 5ade637
Show file tree
Hide file tree
Showing 16 changed files with 292 additions and 163 deletions.
3 changes: 2 additions & 1 deletion .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
],
"defines": [
"__SWITCH__",
"PLATFORM_SWITCH"
"PLATFORM_SWITCH",
"BOREALIS_USE_DEKO3D"
],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
Expand Down
2 changes: 1 addition & 1 deletion app/include/ingame_overlay_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class OptionsTab : public brls::Box {
BRLS_BIND(brls::SelectorCell, keyboardFingers, "keyboard_fingers");
BRLS_BIND(brls::BooleanCell, touchscreenMouseMode, "touchscreen_mouse_mode");
BRLS_BIND(brls::DetailCell, guideKeyButtons, "guide_key_buttons");
BRLS_BIND(brls::BooleanCell, guideByScreenshot, "guide_by_screenshot");
BRLS_BIND(brls::SelectorCell, guideBySystemButton, "guide_by_system_button");
BRLS_BIND(brls::Header, volumeHeader, "volume_header");
BRLS_BIND(brls::Slider, volumeSlider, "volume_slider");
BRLS_BIND(brls::Header, rumbleForceHeader, "rumble_slider_header");
Expand Down
3 changes: 2 additions & 1 deletion app/include/settings_tab.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ class SettingsTab : public brls::Box {
BRLS_BIND(brls::Slider, rumbleForceSlider, "rumble_slider");
BRLS_BIND(brls::BooleanCell, swapStickToDpad, "swap_stick_to_dpad");
BRLS_BIND(brls::DetailCell, guideKeyButtons, "guide_key_buttons");
BRLS_BIND(brls::BooleanCell, guideByScreenshot, "guide_by_screenshot");
BRLS_BIND(brls::SelectorCell, guideBySystemButton, "guide_by_system_button");
BRLS_BIND(brls::SelectorCell, overlayTime, "overlay_time");
BRLS_BIND(brls::DetailCell, overlayButtons, "overlay_buttons");
BRLS_BIND(brls::SelectorCell, overlayBySystemButton, "overlay_by_system_button");
BRLS_BIND(brls::SelectorCell, mouseInputTime, "mouse_input_time");
BRLS_BIND(brls::DetailCell, mouseInputButtons, "mouse_input_buttons");
BRLS_BIND(brls::SelectorCell, keyboardType, "keyboard_type");
Expand Down
29 changes: 23 additions & 6 deletions app/src/ingame_overlay_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <borealis/platforms/switch/switch_input.hpp>
#endif

#include "helper.hpp"
#include "ingame_overlay_view.hpp"
#include "streaming_input_overlay.hpp"
#include "button_selecting_dialog.hpp"
Expand Down Expand Up @@ -101,13 +102,29 @@ OptionsTab::OptionsTab(StreamingView* streamView) : streamView(streamView) {
});

#ifndef PLATFORM_SWITCH
guideByScreenshot->removeFromSuperView();
guideBySystemButton->removeFromSuperView();
#else
guideByScreenshot->init("settings/guide_by_screenshot"_i18n, Settings::instance().replace_screenshot_with_guide_button(),
[](bool value) {
Settings::instance().set_replace_screenshot_with_guide_button(value);
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setReplaceScreenshotWithGuideButton(Settings::instance().replace_screenshot_with_guide_button());
});
guideBySystemButton->init(
"settings/use_system_button"_i18n,
{"hints/off"_i18n, "settings/buttons/screenshot"_i18n, "settings/buttons/home"_i18n},
(int) Settings::instance().get_guide_system_button(), [this](int value) {
if (value != 0 && Settings::instance().get_overlay_system_button() == (ButtonOverrideType) value) {
brls::sync([this, value](){
showError("settings/system_button_duplication_error"_i18n, [](){});
});
guideBySystemButton->setSelection((int) Settings::instance().get_guide_system_button(), true);
return;
}

Settings::instance().set_guide_system_button((ButtonOverrideType) value);

auto color = Settings::instance().get_guide_system_button() == ButtonOverrideType::NONE ?
Application::getTheme()["brls/text_disabled"] : Application::getTheme()["brls/accent"];
guideBySystemButton->setDetailTextColor(color);
});
auto color = Settings::instance().get_guide_system_button() == ButtonOverrideType::NONE ?
Application::getTheme()["brls/text_disabled"] : Application::getTheme()["brls/accent"];
guideBySystemButton->setDetailTextColor(color);
#endif

volumeHeader->setSubtitle(
Expand Down
5 changes: 0 additions & 5 deletions app/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// Switch include only necessary for demo videos recording
#ifdef __SWITCH__
#include <switch.h>
#include <borealis/platforms/switch/switch_input.hpp>
#endif

#include <cstdlib>
Expand Down Expand Up @@ -77,10 +76,6 @@ int main(int argc, char* argv[]) {
Settings::instance().set_working_dir(home);
brls::Logger::info("Working dir, {}", home);

#ifdef PLATFORM_SWITCH
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setReplaceScreenshotWithGuideButton(Settings::instance().replace_screenshot_with_guide_button());
#endif

// Have the application register an action on every activity that will quit
// when you press BUTTON_START
brls::Application::setGlobalQuit(false);
Expand Down
52 changes: 46 additions & 6 deletions app/src/settings_tab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

#include "settings_tab.hpp"
#include "Settings.hpp"
#include "helper.hpp"
#include "button_selecting_dialog.hpp"
#include "mapping_layout_editor.hpp"
#include <iomanip>
Expand Down Expand Up @@ -312,13 +313,52 @@ SettingsTab::SettingsTab() {
});

#ifndef PLATFORM_SWITCH
guideByScreenshot->removeFromSuperView();
guideBySystemButton->removeFromSuperView();
overlayBySystemButton->removeFromSuperView();
#else
guideByScreenshot->init("settings/guide_by_screenshot"_i18n, Settings::instance().replace_screenshot_with_guide_button(),
[](bool value) {
Settings::instance().set_replace_screenshot_with_guide_button(value);
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setReplaceScreenshotWithGuideButton(Settings::instance().replace_screenshot_with_guide_button());
});
guideBySystemButton->init(
"settings/use_system_button"_i18n,
{"hints/off"_i18n, "settings/buttons/screenshot"_i18n, "settings/buttons/home"_i18n},
(int) Settings::instance().get_guide_system_button(), [this](int value) {
if (value != 0 && Settings::instance().get_overlay_system_button() == (ButtonOverrideType) value) {
brls::sync([this, value](){
showError("settings/system_button_duplication_error"_i18n, [](){});
});
guideBySystemButton->setSelection((int) Settings::instance().get_guide_system_button(), true);
return;
}

Settings::instance().set_guide_system_button((ButtonOverrideType) value);

auto color = Settings::instance().get_guide_system_button() == ButtonOverrideType::NONE ?
Application::getTheme()["brls/text_disabled"] : Application::getTheme()["brls/accent"];
guideBySystemButton->setDetailTextColor(color);
});
auto color = Settings::instance().get_guide_system_button() == ButtonOverrideType::NONE ?
Application::getTheme()["brls/text_disabled"] : Application::getTheme()["brls/accent"];
guideBySystemButton->setDetailTextColor(color);

overlayBySystemButton->init(
"settings/use_system_button"_i18n,
{"hints/off"_i18n, "settings/buttons/screenshot"_i18n, "settings/buttons/home"_i18n},
(int) Settings::instance().get_overlay_system_button(), [this](int value) {
if (value != 0 && Settings::instance().get_guide_system_button() == (ButtonOverrideType) value) {
brls::sync([this, value](){
showError("settings/system_button_duplication_error"_i18n, [](){});
});
overlayBySystemButton->setSelection((int) Settings::instance().get_overlay_system_button(), true);
return;
}

Settings::instance().set_overlay_system_button((ButtonOverrideType) value);

auto color = Settings::instance().get_overlay_system_button() == ButtonOverrideType::NONE ?
Application::getTheme()["brls/text_disabled"] : Application::getTheme()["brls/accent"];
overlayBySystemButton->setDetailTextColor(color);
});
color = Settings::instance().get_overlay_system_button() == ButtonOverrideType::NONE ?
Application::getTheme()["brls/text_disabled"] : Application::getTheme()["brls/accent"];
overlayBySystemButton->setDetailTextColor(color);
#endif

overlayTime->init(
Expand Down
2 changes: 1 addition & 1 deletion app/src/streaming/video/deko3d/DKVideoRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ namespace
};
}

DKVideoRenderer::DKVideoRenderer() {}
DKVideoRenderer::DKVideoRenderer() {}

DKVideoRenderer::~DKVideoRenderer() {
// Destroy the vertex buffer (not strictly needed in this case)
Expand Down
2 changes: 1 addition & 1 deletion app/src/streaming/video/deko3d/texture_fsh.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@ layout (std140, binding = 2) uniform Transformation
void main()
{
vec2 uv = (vTextureCoord - u.uv_data.xy) * u.uv_data.zw;
vec3 YCbCr = vec3(texture(plane0, uv).r, texture(plane1, uv).r, texture(plane2, uv).r) - u.offset;
vec3 YCbCr = vec3(texture(plane0, uv).r, texture(plane1, uv).r, texture(plane1, uv).g) - u.offset;
outColor = vec4(clamp(u.yuvmat * YCbCr, 0.0, 1.0), 1.0);
}
52 changes: 52 additions & 0 deletions app/src/streaming_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
// Created by Даниил Виноградов on 27.05.2021.
//

#ifdef __SWITCH__
#include <borealis/platforms/switch/switch_input.hpp>
#endif

#include "streaming_view.hpp"
#include "InputManager.hpp"
#include "click_gesture_recognizer.hpp"
Expand Down Expand Up @@ -32,6 +36,34 @@ void setBottomBarStatus(const char *value) {
#endif
}

void overrideButtonsIfNeeded(bool value) {
#ifdef PLATFORM_SWITCH
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setScreenshotButtonOverrideMode(ButtonOverrideMode::NONE);
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setHomeButtonOverrideMode(ButtonOverrideMode::NONE);
if (!value) return;

switch (Settings::instance().get_overlay_system_button()) {
case ButtonOverrideType::NONE: break;
case ButtonOverrideType::HOME:
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setHomeButtonOverrideMode(ButtonOverrideMode::CUSTOM_EVENT);
break;
case ButtonOverrideType::SCREENSHOT:
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setScreenshotButtonOverrideMode(ButtonOverrideMode::CUSTOM_EVENT);
break;
}

switch (Settings::instance().get_guide_system_button()) {
case ButtonOverrideType::NONE: break;
case ButtonOverrideType::HOME:
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setHomeButtonOverrideMode(ButtonOverrideMode::GUIDE_BUTTON);
break;
case ButtonOverrideType::SCREENSHOT:
((SwitchInputManager*) brls::Application::getPlatform()->getInputManager())->setScreenshotButtonOverrideMode(ButtonOverrideMode::GUIDE_BUTTON);
break;
}
#endif
}

StreamingView::StreamingView(const Host& host, const AppInfo& app) : host(host), app(app) {
Application::getPlatform()->disableScreenDimming(true);

Expand Down Expand Up @@ -214,6 +246,7 @@ void StreamingView::onFocusGained() {

Application::getPlatform()->getInputManager()->setPointerLock(true);

overrideButtonsIfNeeded(true);
setBottomBarStatus("1");
}

Expand All @@ -231,6 +264,7 @@ void StreamingView::onFocusLost() {
removeKeyboard();
Application::getPlatform()->getInputManager()->setPointerLock(false);

overrideButtonsIfNeeded(false);
setBottomBarStatus("2");

if (bottombarDelayTask != -1)
Expand Down Expand Up @@ -431,6 +465,24 @@ void StreamingView::handleOverlayCombo() {
auto overlay = new IngameOverlay(this);
Application::pushActivity(new Activity(overlay));
}

#ifdef PLATFORM_SWITCH
static bool oldSystemButtonOverlayPressed = false;
bool systemButtonOverlayPressed = false;
if (Settings::instance().get_overlay_system_button() == ButtonOverrideType::HOME)
systemButtonOverlayPressed |= ((SwitchInputManager*) Application::getPlatform()->getInputManager())->isHomeButtonPressed();

if (Settings::instance().get_overlay_system_button() == ButtonOverrideType::SCREENSHOT)
systemButtonOverlayPressed |= ((SwitchInputManager*) Application::getPlatform()->getInputManager())->isScreenshotButtonPressed();

if (oldSystemButtonOverlayPressed != systemButtonOverlayPressed) {
oldSystemButtonOverlayPressed = systemButtonOverlayPressed;
if (systemButtonOverlayPressed) {
auto overlay = new IngameOverlay(this);
Application::pushActivity(new Activity(overlay));
}
}
#endif
}

void StreamingView::handleMouseInputCombo() {
Expand Down
8 changes: 4 additions & 4 deletions app/src/utils/Settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,9 +383,9 @@ void Settings::load() {
}
}

if (json_t* replace_screenshot_with_guide_button = json_object_get(settings, "replace_screenshot_with_guide_button")) {
m_replace_screenshot_with_guide_button = json_typeof(replace_screenshot_with_guide_button) == JSON_TRUE;
}
// if (json_t* replace_screenshot_with_guide_button = json_object_get(settings, "replace_screenshot_with_guide_button")) {
// m_replace_screenshot_with_guide_button = json_typeof(replace_screenshot_with_guide_button) == JSON_TRUE;
// }

if (json_t* buttons = json_object_get(settings, "guide_key_buttons")) {
m_guide_key_options.buttons.clear();
Expand Down Expand Up @@ -489,7 +489,7 @@ void Settings::save() {
json_object_set_new(settings, "current_mapping_layout", json_integer(m_current_mapping_layout));
json_object_set_new(settings, "keyboard_type", json_integer(m_keyboard_type));
json_object_set_new(settings, "keyboard_fingers", json_integer(m_keyboard_fingers));
json_object_set_new(settings, "replace_screenshot_with_guide_button", m_replace_screenshot_with_guide_button ? json_true() : json_false());
// json_object_set_new(settings, "replace_screenshot_with_guide_button", m_replace_screenshot_with_guide_button ? json_true() : json_false());

if (json_t* overlayButtons = json_array()) {
for (auto button: m_overlay_options.buttons) {
Expand Down
16 changes: 13 additions & 3 deletions app/src/utils/Settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ enum AudioBackend : int {

enum KeyboardType : int { COMPACT, FULLSIZED };

enum class ButtonOverrideType : int { NONE, SCREENSHOT, HOME };

struct KeyMappingLayout {
std::string title;
bool editable;
Expand Down Expand Up @@ -119,8 +121,8 @@ class Settings : public Singleton<Settings> {
void set_swap_mouse_scroll(bool swap_mouse_scroll) { m_swap_mouse_scroll = swap_mouse_scroll; }
[[nodiscard]] bool swap_mouse_scroll() const { return m_swap_mouse_scroll; }

void set_replace_screenshot_with_guide_button(bool value) { m_replace_screenshot_with_guide_button = value; }
[[nodiscard]] bool replace_screenshot_with_guide_button() const { return m_replace_screenshot_with_guide_button; }
// void set_replace_screenshot_with_guide_button(bool value) { m_replace_screenshot_with_guide_button = value; }
// [[nodiscard]] bool replace_screenshot_with_guide_button() const { return m_replace_screenshot_with_guide_button; }

void set_guide_key_options(KeyComboOptions options) { m_guide_key_options = std::move(options); }
[[nodiscard]] KeyComboOptions guide_key_options() const { return m_guide_key_options; }
Expand All @@ -143,6 +145,12 @@ class Settings : public Singleton<Settings> {
void set_keyboard_type(KeyboardType type) { m_keyboard_type = type; }
[[nodiscard]] KeyboardType get_keyboard_type() const { return m_keyboard_type; }

void set_overlay_system_button(ButtonOverrideType type) { m_overlay_system_button = type; }
[[nodiscard]] ButtonOverrideType get_overlay_system_button() const { return m_overlay_system_button; }

void set_guide_system_button(ButtonOverrideType type) { m_guide_system_button = type; }
[[nodiscard]] ButtonOverrideType get_guide_system_button() const { return m_guide_system_button; }

void set_keyboard_fingers(int fingers) { m_keyboard_fingers = fingers; }
[[nodiscard]] int get_keyboard_fingers() const { return m_keyboard_fingers; }

Expand Down Expand Up @@ -191,13 +199,15 @@ class Settings : public Singleton<Settings> {
int m_volume = 100;
bool m_use_hw_decoding = true;
KeyboardType m_keyboard_type = COMPACT;
ButtonOverrideType m_overlay_system_button = ButtonOverrideType::NONE;
ButtonOverrideType m_guide_system_button = ButtonOverrideType::NONE;
int m_keyboard_fingers = 3;
int m_keyboard_locale = 0;
bool m_volume_amplification = false;
int m_mouse_speed_multiplier = 34;
int m_current_mapping_layout = 0;
std::vector<KeyMappingLayout> m_mapping_laouts;
bool m_replace_screenshot_with_guide_button = false;
// bool m_replace_screenshot_with_guide_button = false;
KeyComboOptions m_guide_key_options{
.holdTime = 0,
.buttons = {},
Expand Down
2 changes: 1 addition & 1 deletion extern/borealis
Submodule borealis updated 224 files
7 changes: 6 additions & 1 deletion resources/i18n/en-US/main.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@
"settings": {
"audio_backend": "Audio driver",
"av1": "AV1 (Experimental)",
"buttons": {
"home": "Home",
"screenshot": "Screenshot"
},
"debug": "Debug",
"debugging_view": "Show debugging view",
"decoder_threads": "Decoder Threads",
"fps": "FPS",
"guide_by_screenshot": "Use Screenshot button",
"guide_key": "Guide key (clicks immediately)",
"guide_key_buttons": "Buttons combination",
"guide_key_setup_message": "Press keys you'd like to use to press Guide button:\n\n",
Expand Down Expand Up @@ -138,8 +141,10 @@
"swap_mouse_scroll": "Swap mouse vertical scrolling direction",
"swap_stick_to_dpad": "Use Stick as D-Pad",
"swap_ui": "Swap / and / for UI",
"system_button_duplication_error": "Another action already use this system button.",
"touchscreen_mouse_mode": "Touchscreen mode",
"use_hw_decoding": "Enable hardware acceleration",
"use_system_button": "Use system button",
"usops": "Use Streaming Optimal Playable Settings",
"video_bitrate": "Video bitrate",
"video_codec": "Video codec",
Expand Down
Loading

0 comments on commit 5ade637

Please sign in to comment.