Skip to content

Commit

Permalink
Add F11 as a full screen shortcut key
Browse files Browse the repository at this point in the history
  • Loading branch information
xfangfang committed Oct 19, 2024
1 parent ba17583 commit 7a5804c
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 50 deletions.
2 changes: 1 addition & 1 deletion resources/xml/activity/player_activity.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
axis="column">

<VideoView
id="video/detail/video"
id="video"
focusable="true"
focusDown="video_detail_info_box"
grow="1"
Expand Down
2 changes: 1 addition & 1 deletion wiliwili/include/activity/player_activity.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ class BasePlayerActivity : public brls::Activity, public VideoDetail {
inline static bool PLAYER_SKIP_OPENING_CREDITS = true;

protected:
BRLS_BIND(VideoView, video, "video/detail/video");
BRLS_BIND(VideoView, video, "video");
BRLS_BIND(brls::AppletFrame, appletFrame, "video/detail/frame");
BRLS_BIND(UserInfoView, videoUserInfo, "video_author");
BRLS_BIND(brls::Box, videoTitleBox, "video/title/box");
Expand Down
9 changes: 0 additions & 9 deletions wiliwili/source/activity/dlna_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,15 +191,6 @@ void DLNAActivity::onContentAvailable() {
},
true);

// 暂停
this->registerAction(
"toggle", brls::ControllerButton::BUTTON_SPACE,
[this](...) -> bool {
this->video->togglePlay();
return true;
},
true);

// 手动将焦点 赋给video组件,这将允许焦点进入video组件内部
brls::sync([this]() { brls::Application::giveFocus(video); });
}
Expand Down
9 changes: 0 additions & 9 deletions wiliwili/source/activity/live_player_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,6 @@ void LiveActivity::onContentAvailable() {
}
});

// 暂停
this->registerAction(
"toggle", brls::ControllerButton::BUTTON_SPACE,
[this](...) -> bool {
this->video->togglePlay();
return true;
},
true);

// 调整清晰度
this->registerAction("wiliwili/player/quality"_i18n, brls::ControllerButton::BUTTON_START,
[this](brls::View* view) -> bool {
Expand Down
9 changes: 0 additions & 9 deletions wiliwili/source/activity/player_base_activity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,6 @@ void BasePlayerActivity::setCommonData() {
return true;
});

// 暂停
this->registerAction(
"toggle", brls::ControllerButton::BUTTON_SPACE,
[this](...) -> bool {
this->video->togglePlay();
return true;
},
true);

this->btnQR->getParent()->addGestureRecognizer(new brls::TapGestureRecognizer(this->btnQR->getParent()));

this->btnAgree->getParent()->addGestureRecognizer(new brls::TapGestureRecognizer(this->btnAgree->getParent()));
Expand Down
5 changes: 1 addition & 4 deletions wiliwili/source/utils/activity_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,5 @@ void Intent::openActivity(const std::string& id) {
}

void Intent::_registerFullscreen(brls::Activity* activity) {
activity->registerAction("", brls::BUTTON_F, [](...) {
ProgramConfig::instance().toggleFullscreen();
return true;
}, true);
(void)activity;
}
41 changes: 36 additions & 5 deletions wiliwili/source/utils/config_helper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <borealis/core/application.hpp>
#include <borealis/core/cache_helper.hpp>
#include <borealis/core/touch/pan_gesture.hpp>
#include <borealis/views/edit_text_dialog.hpp>
#include <cpr/filesystem.h>

#include "bilibili.h"
Expand Down Expand Up @@ -227,7 +228,7 @@ std::unordered_map<SettingItem, ProgramOption> ProgramConfig::SETTING_MAP = {
{SettingItem::ON_TOP_MODE, {"on_top_mode", {"off", "always", "auto"}, {0, 1, 2}, 0}},
{SettingItem::SCROLL_SPEED, {"scroll_speed", {}, {}, 0}},

/// Custom
/// Custom
{SettingItem::UP_FILTER, {"up_filter", {}, {}, 0}},
};

Expand Down Expand Up @@ -578,7 +579,6 @@ void ProgramConfig::load() {
#endif
brls::PanGestureRecognizer::panFactor = scrollSpeed * 0.01f;


// 初始化i18n
std::set<std::string> i18nData{
brls::LOCALE_AUTO, brls::LOCALE_EN_US, brls::LOCALE_JA, brls::LOCALE_RYU,
Expand Down Expand Up @@ -663,6 +663,38 @@ void ProgramConfig::load() {
brls::Application::getPlatform()->setWindowSizeLimits(minWidth, minHeight, 0, 0);
checkOnTop();
#endif

// Init keyboard shortcut
brls::Application::getPlatform()->getInputManager()->getKeyboardKeyStateChanged()->subscribe(
[](brls::KeyState state) {
if (!state.pressed) return;
switch (state.key) {
#ifndef __APPLE__
case brls::BRLS_KBD_KEY_F11:
ProgramConfig::instance().toggleFullscreen();
break;
#endif
case brls::BRLS_KBD_KEY_F: {
// 在编辑框弹出时不触发
auto activityStack = brls::Application::getActivitiesStack();
brls::Activity* top = activityStack[activityStack.size() - 1];
if(!dynamic_cast<brls::EditTextDialog*>(top->getContentView())){
ProgramConfig::instance().toggleFullscreen();
}
break;
}
case brls::BRLS_KBD_KEY_SPACE: {
// 只在顶部的 Activity 中存在播放器组件时触发
auto activityStack = brls::Application::getActivitiesStack();
brls::Activity* top = activityStack[activityStack.size() - 1];
VideoView* video = dynamic_cast<VideoView*>(top->getContentView()->getView("video"));
if (!video) break;
video->togglePlay();
}
default:
break;
}
});
});

#ifdef IOS
Expand Down Expand Up @@ -766,9 +798,8 @@ void ProgramConfig::checkOnTop() {
return;
case 2: {
// 自动模式,根据窗口大小判断是否需要切换到置顶模式
double factor = brls::Application::getPlatform()->getVideoContext()->getScaleFactor();
uint32_t minWidth =
ProgramConfig::instance().getIntOption(SettingItem::ON_TOP_WINDOW_WIDTH) * factor + 0.1;
double factor = brls::Application::getPlatform()->getVideoContext()->getScaleFactor();
uint32_t minWidth = ProgramConfig::instance().getIntOption(SettingItem::ON_TOP_WINDOW_WIDTH) * factor + 0.1;
uint32_t minHeight =
ProgramConfig::instance().getIntOption(SettingItem::ON_TOP_WINDOW_HEIGHT) * factor + 0.1;
bool onTop = brls::Application::windowWidth <= minWidth || brls::Application::windowHeight <= minHeight;
Expand Down
12 changes: 1 addition & 11 deletions wiliwili/source/view/video_view.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,16 +138,6 @@ VideoView::VideoView() {
},
true, true);

// 暂停
this->registerAction(
"toggle", brls::ControllerButton::BUTTON_SPACE,
[this](...) -> bool {
CHECK_OSD(true);
this->togglePlay();
return true;
},
true);

this->registerAction(
"volumeDown", brls::ControllerButton::BUTTON_NAV_DOWN,
[this](brls::View* view) -> bool {
Expand Down Expand Up @@ -1242,7 +1232,7 @@ void VideoView::setFullScreen(bool fs) {
for (size_t i = activityStack.size() - 2; i != 0; i--) {
auto* last = dynamic_cast<BasePlayerActivity*>(activityStack[i]);
if (!last) continue;
auto* video = dynamic_cast<VideoView*>(last->getView("video/detail/video"));
auto* video = dynamic_cast<VideoView*>(last->getView("video"));
if (video) {
video->setProgress(this->getProgress());
video->showOSD(this->osd_state != OSDState::ALWAYS_ON);
Expand Down

0 comments on commit 7a5804c

Please sign in to comment.