From 7ec17eeb4a8d754aec18d72839430e9b492c8273 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 11 Jul 2020 14:21:37 +0200 Subject: Add ctrl+f keybind for fullscreening video --- README.md | 1 + src/QuickMedia.cpp | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 667edde..db74a50 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,7 @@ echo -e "hello\nworld" | QuickMedia dmenu Press `arrow up` and `arrow down` to navigate the menu and also to scroll to the previous/next image when viewing manga in scorll mode. Alternatively you can use the mouse scroll to scroll to the previous/next manga in scroll mode.\ Press `Enter` (aka `Return`) to select the item.\ Press `ESC` to go back to the previous menu.\ +Press `Ctrl + F` to toggle fullscreen when watching a video.\ Press `Ctrl + T` when hovering over a manga chapter to start tracking manga after that chapter. This only works if AutoMedia is installed and accessible in PATH environment variable.\ Press `Backspace` to return to the preview item when reading replies in image board threads.\ diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp index e2b4a2b..6cf6875 100644 --- a/src/QuickMedia.cpp +++ b/src/QuickMedia.cpp @@ -798,6 +798,42 @@ namespace QuickMedia { return -1; } + enum class WindowFullscreenState { + UNSET, + SET, + TOGGLE + }; + + static bool window_set_fullscreen(Display *display, Window window, WindowFullscreenState state) { + Atom wm_state_atom = XInternAtom(display, "_NET_WM_STATE", False); + Atom wm_state_fullscreen_atom = XInternAtom(display, "_NET_WM_STATE_FULLSCREEN", False); + if(wm_state_atom == False || wm_state_fullscreen_atom == False) { + fprintf(stderr, "Failed to fullscreen window. The window manager doesn't support fullscreening windows.\n"); + return false; + } + + XEvent xev; + xev.type = ClientMessage; + xev.xclient.window = window; + xev.xclient.message_type = wm_state_atom; + xev.xclient.format = 32; + xev.xclient.data.l[0] = (int)state; + xev.xclient.data.l[1] = wm_state_fullscreen_atom; + xev.xclient.data.l[2] = 0; + xev.xclient.data.l[3] = 1; + xev.xclient.data.l[4] = 0; + + if(!XSendEvent(display, XDefaultRootWindow(display), 0, SubstructureRedirectMask | SubstructureNotifyMask, &xev)) { + fprintf(stderr, "Failed to fullscreen window\n"); + return false; + } + + XFlush(display); + return true; + } + +#define CLEANMASK(mask) ((mask) & (ShiftMask|ControlMask|Mod1Mask|Mod4Mask|Mod5Mask)) + void Program::video_content_page() { search_bar->onTextUpdateCallback = nullptr; search_bar->onTextSubmitCallback = nullptr; @@ -918,6 +954,8 @@ namespace QuickMedia { KeySym pressed_keysym = XKeycodeToKeysym(disp, xev.xkey.keycode, 0); if(pressed_keysym == XK_Escape) { current_page = previous_page; + } else if(pressed_keysym == XK_f && CLEANMASK(xev.xkey.state) == ControlMask) { + window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::TOGGLE); } } @@ -965,6 +1003,7 @@ namespace QuickMedia { } //window.setMouseCursorVisible(true); + window_set_fullscreen(disp, window.getSystemHandle(), WindowFullscreenState::UNSET); } enum class TrackMediaType { @@ -1055,7 +1094,7 @@ namespace QuickMedia { BodyItem *selected_item = body->get_selected(); if(selected_item) { if(track_media(TrackMediaType::HTML, content_title, selected_item->title, content_url) == 0) { - show_notification("Media tracker", "You are now tracking \"" + content_title + "\" after \"" + selected_item->title + "\""); + show_notification("Media tracker", "You are now tracking \"" + content_title + "\" after \"" + selected_item->title + "\"", Urgency::LOW); } else { show_notification("Media tracker", "Failed to track media \"" + content_title + "\", chapter: \"" + selected_item->title + "\"", Urgency::CRITICAL); } -- cgit v1.2.3