aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-03-11 02:47:16 +0100
committerdec05eba <dec05eba@protonmail.com>2022-03-11 02:47:16 +0100
commit8c142359fd27d73fc6c77dc5d1bd4df831f7c0c1 (patch)
tree915d6d69f7609d571906043e137e6d60af151ea4 /src
parent2b29acfb9f70cb7aff7d5da1f5fc59ee319e3606 (diff)
Fix video player focus (in dwm, it would cause focus spam)
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp46
1 files changed, 27 insertions, 19 deletions
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) {