diff options
Diffstat (limited to 'src/QuickMedia.cpp')
-rw-r--r-- | src/QuickMedia.cpp | 42 |
1 files changed, 17 insertions, 25 deletions
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 5a13179..8fdedb3 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -4,6 +4,7 @@ #include "../plugins/Youtube.hpp" #include "../plugins/Pornhub.hpp" #include "../plugins/Fourchan.hpp" +#include "../plugins/Dmenu.hpp" #include "../include/Scale.hpp" #include "../include/Program.h" #include "../include/VideoPlayer.hpp" @@ -21,8 +22,6 @@ #include <assert.h> #include <cmath> #include <string.h> -#include <X11/Xlib.h> -#include <X11/Xatom.h> #include <signal.h> static const sf::Color back_color(30, 32, 34); @@ -44,6 +43,7 @@ static int x_io_error_handler(Display *display) { namespace QuickMedia { Program::Program() : + disp(nullptr), window(sf::VideoMode(800, 600), "QuickMedia"), window_size(800, 600), body(nullptr), @@ -51,6 +51,10 @@ namespace QuickMedia { current_page(Page::SEARCH_SUGGESTION), image_index(0) { + disp = XOpenDisplay(NULL); + if (!disp) + throw std::runtime_error("Failed to open display to X11 server"); + window.setVerticalSyncEnabled(true); if(!font.loadFromFile("../../../fonts/Lato-Regular.ttf")) { fprintf(stderr, "Failed to load font: Lato-Regular.ttf\n"); @@ -75,6 +79,8 @@ namespace QuickMedia { Program::~Program() { delete body; delete current_plugin; + if(disp) + XCloseDisplay(disp); } static SearchResult search_selected_suggestion(Body *input_body, Body *output_body, Plugin *plugin, std::string &selected_title, std::string &selected_url) { @@ -93,11 +99,12 @@ namespace QuickMedia { static void usage() { fprintf(stderr, "usage: QuickMedia <plugin> [--tor]\n"); fprintf(stderr, "OPTIONS:\n"); - fprintf(stderr, "plugin The plugin to use. Should be either 4chan, manganelo, mangadex, pornhub or youtube\n"); + fprintf(stderr, "plugin The plugin to use. Should be either 4chan, manganelo, mangadex, pornhub, youtube or dmenu\n"); fprintf(stderr, "--tor Use tor. Disabled by default\n"); fprintf(stderr, "EXAMPLES:\n"); fprintf(stderr, "QuickMedia manganelo\n"); fprintf(stderr, "QuickMedia youtube --tor\n"); + fprintf(stderr, "echo \"hello\nworld\" | QuickMedia dmenu\n"); } static bool is_program_executable_by_name(const char *name) { @@ -146,6 +153,8 @@ namespace QuickMedia { } else if(strcmp(argv[i], "4chan") == 0) { current_plugin = new Fourchan(); plugin_logo_path = "../../../images/4chan_logo.png"; + } else if(strcmp(argv[i], "dmenu") == 0) { + current_plugin = new Dmenu(); } } @@ -237,7 +246,7 @@ namespace QuickMedia { } } - return 0; + return exit_code; } void Program::base_event_handler(sf::Event &event, Page previous_page, bool handle_keypress, bool clear_on_escape, bool handle_searchbar) { @@ -357,7 +366,7 @@ namespace QuickMedia { } search_bar->onTextUpdateCallback = [&update_search_text, this, &tabs, &selected_tab](const std::string &text) { - if(tabs[selected_tab].body == body) + if(tabs[selected_tab].body == body && !current_plugin->search_is_filter()) update_search_text = text; else { tabs[selected_tab].body->filter_search_fuzzy(text); @@ -438,6 +447,7 @@ namespace QuickMedia { tabs[selected_tab].body->select_next_item(); } else if(event.key.code == sf::Keyboard::Escape) { current_page = Page::EXIT; + exit_code = 1; } else if(event.key.code == sf::Keyboard::Left) { selected_tab = std::max(0, selected_tab - 1); search_bar->clear(); @@ -578,19 +588,6 @@ namespace QuickMedia { #endif } - struct XDisplayScope { - XDisplayScope(Display *_display) : display(_display) { - - } - - ~XDisplayScope() { - if(display) - XCloseDisplay(display); - } - - Display *display; - }; - enum class WindowFullscreenState { UNSET, SET, @@ -631,13 +628,8 @@ namespace QuickMedia { Page previous_page = pop_page_stack(); - Display* disp = XOpenDisplay(NULL); - if (!disp) - throw std::runtime_error("Failed to open display to X11 server"); - XDisplayScope display_scope(disp); - std::unique_ptr<sf::RenderWindow> video_player_ui_window; - auto on_window_create = [disp, &video_player_ui_window](sf::WindowHandle video_player_window) { + auto on_window_create = [this, &video_player_ui_window](sf::WindowHandle video_player_window) { int screen = DefaultScreen(disp); Window ui_window = XCreateWindow(disp, RootWindow(disp, screen), 0, 0, 1, 1, 0, @@ -705,7 +697,7 @@ namespace QuickMedia { }, on_window_create); load_video_error_check(); - auto on_doubleclick = [this, disp]() { + auto on_doubleclick = [this]() { window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::TOGGLE); }; |