From 996fae60ee768335032a8e1ab8e077b40c3adcac Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 11 Jul 2020 17:05:34 +0200 Subject: Automatically hide cursor after a while when video is focused --- src/QuickMedia.cpp | 30 ++++++++++++++++++++++++++---- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index 8a01dc6..a8a3ddc 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -845,7 +845,7 @@ namespace QuickMedia { sf::WindowHandle video_player_window = None; auto on_window_create = [this, &video_player_window](sf::WindowHandle _video_player_window) mutable { video_player_window = _video_player_window; - XSelectInput(disp, video_player_window, KeyPressMask); + XSelectInput(disp, video_player_window, KeyPressMask | PointerMotionMask); XSync(disp, False); }; @@ -944,6 +944,8 @@ namespace QuickMedia { window.display(); XEvent xev; + bool cursor_visible = true; + sf::Clock cursor_hide_timer; while (current_page == Page::VIDEO_CONTENT) { while (window.pollEvent(event)) { @@ -959,11 +961,19 @@ namespace QuickMedia { } } + if(video_player_window && XCheckTypedWindowEvent(disp, video_player_window, MotionNotify, &xev)) { + while(XCheckTypedEvent(disp, MotionNotify, &xev)); + cursor_hide_timer.restart(); + if(!cursor_visible) + window.setMouseCursorVisible(true); + cursor_visible = true; + } + VideoPlayer::Error update_err = video_player->update(); if(update_err == VideoPlayer::Error::FAIL_TO_CONNECT_TIMEOUT) { show_notification("Video player", "Failed to connect to mpv ipc after 5 seconds", Urgency::CRITICAL); current_page = previous_page; - return; + break; } else if(update_err == VideoPlayer::Error::EXITED) { std::string youtube_video_id; if(youtube_url_extract_id(content_url, youtube_video_id)) { @@ -995,14 +1005,26 @@ namespace QuickMedia { return; } - // TODO: Show loading video animation + // TODO: Show loading video animation. load_video needs to be made asynchronous first //window.clear(); //window.display(); + if(video_player_window) { + if(!cursor_visible) { + std::this_thread::sleep_for(std::chrono::milliseconds(50)); + continue; + } + + const int UI_HIDE_TIMEOUT = 4500; + if(cursor_hide_timer.getElapsedTime().asMilliseconds() > UI_HIDE_TIMEOUT) { + cursor_visible = false; + window.setMouseCursorVisible(false); + } + } std::this_thread::sleep_for(std::chrono::milliseconds(50)); } - //window.setMouseCursorVisible(true); + window.setMouseCursorVisible(true); window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::UNSET); } -- cgit v1.2.3