aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-05 07:16:25 +0100
committerdec05eba <dec05eba@protonmail.com>2022-03-05 07:23:15 +0100
commit63d18f733602f9b7381a03b72a17662a99c44fc2 (patch)
tree01992222bf601f8398b330a4bb08f9f0a98f4383 /src
parent8923e0d8f268462b2a7dfabe2545e1d6bda5615a (diff)
Fix video fullscreen button, double-click fullscreen
Fix video seekbar mouse collision not working for the top of the seekbar
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp16
-rw-r--r--src/VideoPlayer.cpp49
2 files changed, 46 insertions, 19 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 8d6e4a2..ddb81a9 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -3076,7 +3076,7 @@ namespace QuickMedia {
std::string channel_url;
AsyncTask<void> related_videos_task;
- std::function<void(const char*)> video_event_callback;
+ EventCallbackFunc video_event_callback;
bool go_to_previous_page = false;
std::string video_url;
@@ -3317,7 +3317,7 @@ namespace QuickMedia {
}
};
- video_event_callback = [&](const char *event_name) mutable {
+ video_event_callback = [&](const char *event_name, const std::vector<std::string> &args) mutable {
if(strcmp(event_name, "pause") == 0) {
//double time_remaining = 9999.0;
//if(video_player->get_time_remaining(&time_remaining) == VideoPlayer::Error::OK && time_remaining <= 1.0)
@@ -3337,6 +3337,8 @@ namespace QuickMedia {
} else if(strcmp(event_name, "seek") == 0) {
if(video_page->is_local())
update_time_pos = true;
+ } else if(strcmp(event_name, "fullscreen") == 0 && args.size() == 1) {
+ window_set_fullscreen(disp, window.get_system_handle(), args[0] == "yes" ? WindowFullscreenState::SET : WindowFullscreenState::UNSET);
}
//fprintf(stderr, "event name: %s\n", event_name);
@@ -3376,13 +3378,12 @@ namespace QuickMedia {
} else if(event.type == mgl::Event::KeyPressed && (event.key.code == mgl::Keyboard::Escape || event.key.code == mgl::Keyboard::Q || event.key.code == mgl::Keyboard::Backspace)) {
// To be able to close the video player while the video is loading
if(window_is_fullscreen(disp, window.get_system_handle())) {
- window_set_fullscreen(disp, window.get_system_handle(), WindowFullscreenState::UNSET);
+ if(video_player && video_player_window && event.key.code != mgl::Keyboard::Escape)
+ video_player->cycle_fullscreen();
} else {
current_page = previous_page;
go_to_previous_page = true;
}
- } else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::F && event.key.control) {
- window_set_fullscreen(disp, window.get_system_handle(), WindowFullscreenState::TOGGLE);
} else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::C && event.key.control && !video_page->is_local()) {
save_video_url_to_clipboard();
} else if(event.type == mgl::Event::KeyPressed && event.key.code == mgl::Keyboard::F5 && !video_page->is_local()) {
@@ -3401,14 +3402,15 @@ namespace QuickMedia {
window.close();
} else if(pressed_keysym == XK_Escape || pressed_keysym == XK_q || pressed_keysym == XK_BackSpace) {
if(window_is_fullscreen(disp, window.get_system_handle())) {
- window_set_fullscreen(disp, window.get_system_handle(), WindowFullscreenState::UNSET);
+ if(pressed_keysym != XK_Escape)
+ video_player->cycle_fullscreen();
} else {
current_page = previous_page;
go_to_previous_page = true;
break;
}
} else if(pressed_keysym == XK_f && pressing_ctrl) {
- window_set_fullscreen(disp, window.get_system_handle(), WindowFullscreenState::TOGGLE);
+ video_player->cycle_fullscreen();
} else if(pressed_keysym == XK_s && pressing_ctrl && !video_page->is_local()) {
video_page_download_video(video_page->get_download_url(video_get_max_height()), video_player_window);
} else if(pressed_keysym == XK_F5 && !video_page->is_local()) {
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index 2c0fe44..26e2013 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -96,8 +96,8 @@ namespace QuickMedia {
video_process_id(-1),
connect_tries(0),
find_window_tries(0),
- event_callback(_event_callback),
- window_create_callback(_window_create_callback),
+ event_callback(std::move(_event_callback)),
+ window_create_callback(std::move(_window_create_callback)),
window_handle(0),
display(nullptr),
request_id_counter(1),
@@ -364,6 +364,21 @@ namespace QuickMedia {
return Error::OK;
}
+ static std::vector<std::string> json_array_to_string_list(const Json::Value &json) {
+ std::vector<std::string> result;
+ if(!json.isArray())
+ return result;
+
+ for(const Json::Value &item : json) {
+ if(!item.isString())
+ continue;
+
+ result.push_back(item.asString());
+ }
+
+ return result;
+ }
+
VideoPlayer::Error VideoPlayer::read_ipc_func() {
Json::Value json_root;
Json::CharReaderBuilder json_builder;
@@ -386,18 +401,26 @@ namespace QuickMedia {
if(json_reader->parse(buffer + start, buffer + i, &json_root, &json_errors) && json_root.isObject()) {
const Json::Value &event = json_root["event"];
- const Json::Value &request_id_json = json_root["request_id"];
+ const Json::Value &args = json_root["args"];
if(event.isString()) {
if(event_callback)
- event_callback(event.asCString());
+ event_callback(event.asCString(), json_array_to_string_list(args));
}
+ const Json::Value &request_id_json = json_root["request_id"];
if(expected_request_id != 0 && request_id_json.isNumeric() && request_id_json.asUInt() == expected_request_id) {
const Json::Value &status_json = json_root["status"];
- if(!status_json.isString() || strcmp(status_json.asCString(), "error") == 0)
+ if(!status_json.isString() || strcmp(status_json.asCString(), "error") == 0) {
response_data_status = ResponseDataStatus::ERROR;
- else
+ const char *err_msg = "Unknown";
+ const Json::Value &message_json = json_root["message"];
+ if(message_json.isString())
+ err_msg = message_json.asCString();
+
+ fprintf(stderr, "VideoPlayer::send_command failed, error from video player: %s\n", err_msg);
+ } else {
response_data_status = ResponseDataStatus::OK;
+ }
request_response_data = json_root["data"];
}
} else {
@@ -440,6 +463,14 @@ namespace QuickMedia {
return send_command(json_root, &result, Json::ValueType::nullValue);
}
+ VideoPlayer::Error VideoPlayer::cycle_fullscreen() {
+ Json::Value json_root(Json::objectValue);
+ json_root["command"] = "cycle-fullscreen";
+
+ Json::Value result;
+ return send_command(json_root, &result, Json::ValueType::nullValue);
+ }
+
uint32_t VideoPlayer::get_next_request_id() {
unsigned int cmd_request_id = request_id_counter;
++request_id_counter;
@@ -483,12 +514,6 @@ namespace QuickMedia {
else
err = Error::READ_INCORRECT_TYPE;
} else if(response_data_status == ResponseDataStatus::ERROR) {
- const char *err_msg = "Unknown";
- const Json::Value &message_json = request_response_data["message"];
- if(message_json.isString())
- err_msg = message_json.asCString();
-
- fprintf(stderr, "VideoPlayer::send_command failed, error from video player: %s\n", err_msg);
err = Error::READ_RESPONSE_ERROR;
goto cleanup;
} else {