diff options
author | dec05eba <dec05eba@protonmail.com> | 2022-03-11 02:47:16 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2022-03-11 02:47:16 +0100 |
commit | 8c142359fd27d73fc6c77dc5d1bd4df831f7c0c1 (patch) | |
tree | 915d6d69f7609d571906043e137e6d60af151ea4 | |
parent | 2b29acfb9f70cb7aff7d5da1f5fc59ee319e3606 (diff) |
Fix video player focus (in dwm, it would cause focus spam)
-rw-r--r-- | TODO | 3 | ||||
m--------- | depends/mglpp | 0 | ||||
-rw-r--r-- | include/QuickMedia.hpp | 4 | ||||
-rw-r--r-- | src/QuickMedia.cpp | 46 |
4 files changed, 32 insertions, 21 deletions
@@ -223,4 +223,5 @@ Zero clear password memory after use. Periodically cleanup old cache files (especially manga images, thumbnails and media). Maybe have a file that says when we last checked for old files, and if its X days old then check and remove old files again and update the file. Render watch progress in youtube. -Readd youtube watch progress which seems to be broken because of frozen download?
\ No newline at end of file +Readd youtube watch progress which seems to be broken because of frozen download? +Set _NET_WM_USER_TIME (see sfml).
\ No newline at end of file diff --git a/depends/mglpp b/depends/mglpp -Subproject e8113a53d8b9d91db3728ac875b49b17a1ed665 +Subproject 5b97ed133553f92875872a32728221bcda53be3 diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp index d7680ff..1fda7a3 100644 --- a/include/QuickMedia.hpp +++ b/include/QuickMedia.hpp @@ -112,7 +112,7 @@ namespace QuickMedia { void set_clipboard(const std::string &str); private: - void init(unsigned long parent_window, std::string &program_path); + void init(mgl::WindowHandle parent_window, std::string &program_path); void load_plugin_by_name(std::vector<Tab> &tabs, int &start_tab_index, FileManagerMimeType fm_mime_type, FileSelectionHandler file_selection_handler, std::string instance); void common_event_handler(mgl::Event &event); void handle_x11_events(); @@ -126,6 +126,8 @@ namespace QuickMedia { using PageLoopSubmitHandler = std::function<void(const std::vector<Tab> &new_tabs)>; // Returns false if the page loop was escaped by user navigation (pressing escape) or if there was an error at startup bool page_loop(std::vector<Tab> &tabs, int start_tab_index = 0, PageLoopSubmitHandler after_submit_handler = nullptr, bool go_to_previous_on_escape = true); + void redirect_focus_to_video_player_window(mgl::WindowHandle video_player_window); + void show_video_player_window(mgl::WindowHandle video_player_window); void video_page_download_video(const std::string &url, mgl::WindowHandle video_player_window = 0); bool video_download_if_non_streamable(std::string &video_url, std::string &audio_url, bool &is_audio_only, bool &has_embedded_audio, PageType previous_page); int video_get_max_height(); diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 6dda729..49bfd36 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -651,7 +651,7 @@ namespace QuickMedia { return focused_monitor_center; } - void Program::init(unsigned long parent_window, std::string &program_path) { + void Program::init(mgl::WindowHandle parent_window, std::string &program_path) { disp = XOpenDisplay(NULL); if (!disp) { show_notification("QuickMedia", "Failed to open display to X11 server", Urgency::CRITICAL); @@ -2906,15 +2906,21 @@ namespace QuickMedia { || is_soundcloud(url); } - static void show_video_player_window(Display *disp, Window video_player_window, Window window) { - XMapWindow(disp, video_player_window); - XSync(disp, False); - + void Program::redirect_focus_to_video_player_window(mgl::WindowHandle video_player_window) { Window focused_window = None; int dummy; XGetInputFocus(disp, &focused_window, &dummy); - if(focused_window == window) - XSetInputFocus(disp, video_player_window, RevertToParent, CurrentTime); + if(focused_window != window.get_system_handle()) + return; + + XRaiseWindow(disp, video_player_window); + XSetInputFocus(disp, video_player_window, RevertToPointerRoot, CurrentTime); + } + + void Program::show_video_player_window(mgl::WindowHandle video_player_window) { + XMapWindow(disp, video_player_window); + XSync(disp, False); + redirect_focus_to_video_player_window(video_player_window); } void Program::video_page_download_video(const std::string &url, mgl::WindowHandle video_player_window) { @@ -2951,7 +2957,7 @@ namespace QuickMedia { bool selected = page_loop(tabs); if(video_player_window) - show_video_player_window(disp, video_player_window, window.get_system_handle()); + show_video_player_window(video_player_window); if(!selected) return; @@ -3047,6 +3053,7 @@ namespace QuickMedia { double video_duration = 0.0; // Time in seconds. 0 if unknown bool update_time_pos = false; bool update_duration = false; + bool update_window_focus = false; mgl::Clock video_time_pos_clock; std::string youtube_video_id_dummy; @@ -3071,6 +3078,7 @@ namespace QuickMedia { auto on_window_create = [&](mgl::WindowHandle _video_player_window) mutable { video_player_window = _video_player_window; XSelectInput(disp, video_player_window, KeyPressMask | PointerMotionMask); + redirect_focus_to_video_player_window(video_player_window); XSync(disp, False); SubtitleData subtitle_data; @@ -3078,13 +3086,8 @@ namespace QuickMedia { if(!subtitle_data.url.empty()) video_player->add_subtitle(subtitle_data.url, subtitle_data.title, "eng"); - Window focused_window = None; - int dummy; - XGetInputFocus(disp, &focused_window, &dummy); - if(focused_window == window.get_system_handle()) - XSetInputFocus(disp, video_player_window, RevertToParent, CurrentTime); - update_time_pos = true; + update_window_focus = true; }; std::unique_ptr<YoutubeMediaProxy> youtube_video_media_proxy; @@ -3393,7 +3396,7 @@ namespace QuickMedia { while (window.poll_event(event)) { common_event_handler(event); if(event.type == mgl::Event::GainedFocus && video_player_window) { - XSetInputFocus(disp, video_player_window, RevertToParent, CurrentTime); + redirect_focus_to_video_player_window(video_player_window); } else if(event.type == mgl::Event::Resized) { window_size.x = event.size.width; window_size.y = event.size.height; @@ -3414,6 +3417,11 @@ namespace QuickMedia { } handle_x11_events(); + if(video_player_window && update_window_focus) { + update_window_focus = false; + redirect_focus_to_video_player_window(video_player_window); + } + if(video_player && video_player_window && XCheckTypedWindowEvent(disp, video_player_window, KeyPress, &xev)/* && xev.xkey.subwindow == video_player_window*/) { #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wdeprecated-declarations" @@ -3463,7 +3471,7 @@ namespace QuickMedia { }); if(task_result == TaskResult::CANCEL) { - show_video_player_window(disp, video_player_window, window.get_system_handle()); + show_video_player_window(video_player_window); cancelled = true; } } @@ -3479,7 +3487,7 @@ namespace QuickMedia { }); if(related_pages_result == TaskResult::FALSE) { - show_video_player_window(disp, video_player_window, window.get_system_handle()); + show_video_player_window(video_player_window); show_notification("QuickMedia", "Failed to get related pages", Urgency::CRITICAL); } else if(related_pages_result == TaskResult::TRUE && !related_pages.empty()) { video_page->set_watch_progress(video_time_pos, video_duration); @@ -3513,10 +3521,10 @@ namespace QuickMedia { current_page = PageType::VIDEO_CONTENT; load_video_error_check(resume_start_time > 0.1 ? std::to_string((int)resume_start_time) : ""); } else { - show_video_player_window(disp, video_player_window, window.get_system_handle()); + show_video_player_window(video_player_window); } } else { - show_video_player_window(disp, video_player_window, window.get_system_handle()); + show_video_player_window(video_player_window); } } } else if(pressed_keysym == XK_c && pressing_ctrl) { |