aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Body.cpp2
-rw-r--r--src/DownloadUtils.cpp11
-rw-r--r--src/QuickMedia.cpp95
-rw-r--r--src/VideoPlayer.cpp7
4 files changed, 28 insertions, 87 deletions
diff --git a/src/Body.cpp b/src/Body.cpp
index 3bd2421..54134b6 100644
--- a/src/Body.cpp
+++ b/src/Body.cpp
@@ -112,7 +112,7 @@ namespace QuickMedia {
loading_thumbnail = true;
thumbnail_load_thread = std::thread([this, result, url]() {
std::string texture_data;
- if(download_to_string_cache(url, texture_data, {}, program->get_current_plugin()->use_tor) == DownloadResult::OK) {
+ if(download_to_string_cache(url, texture_data, {}, program->get_current_plugin()->use_tor, true) == DownloadResult::OK) {
if(result->loadFromMemory(texture_data.data(), texture_data.size())) {
//result->generateMipmap();
}
diff --git a/src/DownloadUtils.cpp b/src/DownloadUtils.cpp
index 129234f..8193c90 100644
--- a/src/DownloadUtils.cpp
+++ b/src/DownloadUtils.cpp
@@ -4,6 +4,8 @@
#include <SFML/System/Clock.hpp>
#include <cppcodec/base64_rfc4648.hpp>
+static const bool debug_download = false;
+
static int accumulate_string(char *data, int size, void *userdata) {
std::string *str = (std::string*)userdata;
str->append(data, size);
@@ -31,6 +33,13 @@ namespace QuickMedia {
args.push_back("--");
args.push_back(url.c_str());
args.push_back(nullptr);
+ if(debug_download) {
+ for(const char *arg : args) {
+ if(arg)
+ fprintf(stderr, "%s ", arg);
+ }
+ fprintf(stderr, "\n");
+ }
if(exec_program(args.data(), accumulate_string, &result) != 0)
return DownloadResult::NET_ERR;
fprintf(stderr, "Download duration for %s: %d ms\n", url.c_str(), timer.getElapsedTime().asMilliseconds());
@@ -49,7 +58,7 @@ namespace QuickMedia {
return DownloadResult::ERR;
}
} else {
- DownloadResult download_result = download_to_string(url, result, additional_args, use_tor);
+ DownloadResult download_result = download_to_string(url, result, additional_args, use_tor, use_browser_useragent);
if(download_result == DownloadResult::OK) {
if(create_directory_recursive(media_dir) == 0 && file_overwrite(media_file_path, result) == 0) {
create_lock_file(media_finished_path);
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index 750ea3c..aa14d11 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -24,6 +24,7 @@
#include <cmath>
#include <string.h>
#include <signal.h>
+#include <X11/keysym.h>
static const sf::Color back_color(30, 32, 34);
static const int DOUBLE_CLICK_TIME = 500;
@@ -637,20 +638,15 @@ namespace QuickMedia {
Page previous_page = pop_page_stack();
- bool ui_resize = true;
bool seekable = false;
std::unique_ptr<VideoPlayer> video_player;
- std::unique_ptr<sf::RenderWindow> video_player_ui_window;
- auto on_window_create = [this, &video_player_ui_window, &video_player, &seekable](sf::WindowHandle video_player_window) mutable {
- int screen = DefaultScreen(disp);
- Window ui_window = XCreateSimpleWindow(disp, video_player_window, 0, 0, 1, 1, 0, 0, BlackPixel(disp, screen));
- XMapWindow(disp, ui_window);
- XFlush(disp);
-
- video_player_ui_window = std::make_unique<sf::RenderWindow>(ui_window);
- video_player_ui_window->setVerticalSyncEnabled(true);
+ sf::WindowHandle video_player_window = None;
+ auto on_window_create = [this, &video_player, &seekable, &video_player_window](sf::WindowHandle _video_player_window) mutable {
+ video_player_window = _video_player_window;
+ XSelectInput(disp, video_player_window, KeyPressMask);
+ XSync(disp, False);
video_player->is_seekable(&seekable);
};
@@ -708,30 +704,23 @@ namespace QuickMedia {
window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::TOGGLE);
};
- sf::Clock ui_hide_timer;
- bool ui_visible = true;
- const int UI_HIDE_TIMEOUT = 4500;
-
sf::Clock time_since_last_left_click;
int left_click_counter;
sf::Event event;
sf::RectangleShape rect;
rect.setFillColor(sf::Color::Red);
- sf::Clock get_progress_timer;
- double progress = 0.0;
-
// Clear screen before playing video, to show a black screen instead of being frozen
// at the previous UI for a moment
window.clear();
window.display();
+ XEvent xev;
+
while (current_page == Page::VIDEO_CONTENT) {
while (window.pollEvent(event)) {
base_event_handler(event, previous_page, true, false, false);
if(event.type == sf::Event::Resized) {
- if(video_player_ui_window)
- ui_resize = true;
} else if(event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Space) {
if(video_player->toggle_pause() != VideoPlayer::Error::OK) {
fprintf(stderr, "Failed to toggle pause!\n");
@@ -745,29 +734,13 @@ namespace QuickMedia {
} else {
left_click_counter = 1;
}
- } else if(event.type == sf::Event::MouseMoved) {
- ui_hide_timer.restart();
- if(!ui_visible) {
- ui_visible = true;
- video_player_ui_window->setVisible(true);
- //window.setMouseCursorVisible(true);
- }
}
}
- if(video_player_ui_window) {
- while(video_player_ui_window->pollEvent(event)) {
- if(event.type == sf::Event::Resized) {
- sf::FloatRect visible_area(0, 0, event.size.width, event.size.height);
- video_player_ui_window->setView(sf::View(visible_area));
- } else if(event.type == sf::Event::MouseMoved) {
- ui_hide_timer.restart();
- if(!ui_visible) {
- ui_visible = true;
- video_player_ui_window->setVisible(true);
- //window.setMouseCursorVisible(true);
- }
- }
+ if(video_player_window && XCheckTypedWindowEvent(disp, video_player_window, KeyPress, &xev)/* && xev.xkey.subwindow == video_player_window*/) {
+ KeySym pressed_keysym = XKeycodeToKeysym(disp, xev.xkey.keycode, 0);
+ if(pressed_keysym == XK_Escape) {
+ current_page = previous_page;
}
}
@@ -786,51 +759,9 @@ namespace QuickMedia {
//window.clear();
//window.display();
- if(video_player->is_connected() && get_progress_timer.getElapsedTime().asMilliseconds() >= 500) {
- get_progress_timer.restart();
- video_player->get_progress(&progress);
- }
-
- if(video_player_ui_window) {
- if(!ui_visible) {
- std::this_thread::sleep_for(std::chrono::milliseconds(50));
- continue;
- }
-
- if(ui_hide_timer.getElapsedTime().asMilliseconds() > UI_HIDE_TIMEOUT) {
- ui_visible = false;
- video_player_ui_window->setVisible(false);
- //window.setMouseCursorVisible(false);
- }
-
- const float ui_height = window_size.y * 0.025f;
- if(ui_resize) {
- ui_resize = false;
- video_player_ui_window->setSize(sf::Vector2u(window_size.x, ui_height));
- video_player_ui_window->setPosition(sf::Vector2i(0, window_size.y - ui_height));
- }
-
- // TODO: Make window transparent, so the ui overlay for the video has transparency
- video_player_ui_window->clear(sf::Color(33, 33, 33));
- rect.setSize(sf::Vector2f(window_size.x * progress, ui_height));
- video_player_ui_window->draw(rect);
- video_player_ui_window->display();
-
- if(sf::Mouse::isButtonPressed(sf::Mouse::Left)) {
- auto mouse_pos = sf::Mouse::getPosition(window);
- if(mouse_pos.y >= window_size.y - ui_height && mouse_pos.y <= window_size.y) {
- if(seekable)
- video_player->set_progress((double)mouse_pos.x / (double)window_size.x);
- else
- fprintf(stderr, "Video is not seekable!\n"); // TODO: Show this to the user
- }
- }
- } else {
- std::this_thread::sleep_for(std::chrono::milliseconds(50));
- }
+ std::this_thread::sleep_for(std::chrono::milliseconds(50));
}
- video_player_ui_window.reset();
window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::UNSET);
//window.setMouseCursorVisible(true);
}
diff --git a/src/VideoPlayer.cpp b/src/VideoPlayer.cpp
index 8bb6825..85c0d4d 100644
--- a/src/VideoPlayer.cpp
+++ b/src/VideoPlayer.cpp
@@ -75,10 +75,11 @@ namespace QuickMedia {
// TODO: Resume playback if the last video played matches the first video played next time QuickMedia is launched
args.insert(args.end(), { "mpv", "--keep-open=yes", /*"--keep-open-pause=no",*/ input_ipc_server_arg.c_str(),
- "--no-config", "--no-input-default-bindings", "--input-vo-keyboard=no",
+ "--no-config",
+ //"--no-input-default-bindings", "--input-vo-keyboard=no",
"--demuxer-max-bytes=40M", "--demuxer-max-back-bytes=20M",
- "--no-input-terminal",
- "--no-osc",
+ //"--no-input-terminal",
+ //"--no-osc",
"--profile=gpu-hq",
"--vo=gpu",
"--hwdec=auto",