aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2021-07-06 19:01:35 +0200
committerdec05eba <dec05eba@protonmail.com>2021-07-06 19:01:35 +0200
commit3b1458784942574222f8fea5b2ab2f8accaac6b8 (patch)
treedda654e96263e590cdd519f1b96652ad079c2897
parent2a7c6525c2ab62cb6a09f049c8bf53bc7e6e0039 (diff)
Respond to x11 ping (should fix gnome unresponsive application detection)
-rw-r--r--README.md32
-rw-r--r--include/QuickMedia.hpp5
-rw-r--r--src/QuickMedia.cpp44
3 files changed, 46 insertions, 35 deletions
diff --git a/README.md b/README.md
index 0c8e0b0..397a0a7 100644
--- a/README.md
+++ b/README.md
@@ -23,6 +23,22 @@ EXAMPLES:
```
## Installation
If you are running arch linux then you can install QuickMedia from aur (https://aur.archlinux.org/packages/quickmedia-git/), otherwise you will need to first install [sibs](https://git.dec05eba.com/sibs/) and then run `./install.sh` as root.
+## Dependencies
+### Libraries
+`sfml`, `libx11`, `libxrandr`, `jsoncpp`, `libglvnd` (opengl)
+### Executables
+`curl`, `imagemagick`
+### Fonts
+`noto-fonts`
+### Optional
+`noto-fonts-cjk` needs to be installed to view chinese, japanese and korean characters.\
+`mpv` needs to be installed to play videos.\
+`youtube-dl` needs to be installed to download youtube music/videos. (Note: `youtube-dl` is not required to watch (stream) youtube music/videos).\
+`libnotify` which provides `notify-send` needs to be installed to show notifications (on Linux and other systems that uses d-bus notification system).\
+[automedia](https://git.dec05eba.com/AutoMedia/) needs to be installed when tracking manga with `Ctrl + T`.\
+`waifu2x-ncnn-vulkan` needs to be installed when using the `--upscale-images` or `--upscale-images-always` option.\
+`xdg-utils` which provides `xdg-open` needs to be installed when downloading torrents with `nyaa.si` plugin.\
+`ffmpeg (and ffprobe which is included in ffmpeg)` needs to be installed to upload videos with thumbnails on matrix.
## Controls
### General control
Type text and then wait and QuickMedia will automatically search.\
@@ -129,22 +145,6 @@ For example a value of 96 for the `Xft.dpi` means 1.0 scaling and 144 (96*1.5) m
Note that at the moment, cached images will not be scaled with the dpi. Images do also not scale above their original size.
## Tabs
[tabbed](https://tools.suckless.org/tabbed/) can be used to put quickmedia windows into tabs. After installing `tabbed`, run `tabbed -c -k quickmedia launcher -e`.
-## Dependencies
-### Libraries
-`sfml`, `libx11`, `libxrandr`, `jsoncpp`, `libglvnd` (opengl)
-### Executables
-`curl`, `imagemagick`
-### Fonts
-`noto-fonts`
-### Optional
-`noto-fonts-cjk` needs to be installed to view chinese, japanese and korean characters.\
-`mpv` needs to be installed to play videos.\
-`youtube-dl` needs to be installed to download youtube music/videos. (Note: `youtube-dl` is not required to watch (stream) youtube music/videos).\
-`libnotify` which provides `notify-send` needs to be installed to show notifications (on Linux and other systems that uses d-bus notification system).\
-[automedia](https://git.dec05eba.com/AutoMedia/) needs to be installed when tracking manga with `Ctrl + T`.\
-`waifu2x-ncnn-vulkan` needs to be installed when using the `--upscale-images` or `--upscale-images-always` option.\
-`xdg-utils` which provides `xdg-open` needs to be installed when downloading torrents with `nyaa.si` plugin.\
-`ffmpeg (and ffprobe which is included in ffmpeg)` needs to be installed to upload videos with thumbnails on matrix.
## License
QuickMedia is free software licensed under GPL 3.0, see LICENSE for more details. `images/emoji.png` uses Noto Color Emoji, which is licensed under the Apache license, see: https://github.com/googlefonts/noto-emoji.
# Screenshots
diff --git a/include/QuickMedia.hpp b/include/QuickMedia.hpp
index 7078791..cc4a10f 100644
--- a/include/QuickMedia.hpp
+++ b/include/QuickMedia.hpp
@@ -103,8 +103,7 @@ namespace QuickMedia {
private:
void init(Window 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);
- // Returns true if the window was closed
- bool handle_window_close();
+ void handle_x11_events();
void base_event_handler(sf::Event &event, PageType previous_page, Body *body, SearchBar *search_bar, bool handle_key_press = true, bool handle_searchbar = true);
void event_idle_handler(const sf::Event &event);
void idle_active_handler();
@@ -202,9 +201,11 @@ namespace QuickMedia {
sf::Clock idle_timer;
bool idle = true;
bool low_cpu_mode = false;
+ bool window_closed = false;
std::string pipe_selected_text;
Window x11_window = None;
Atom wm_delete_window_atom;
+ Atom net_wm_ping_atom;
XEvent xev;
std::filesystem::path file_manager_start_dir;
std::string youtube_url;
diff --git a/src/QuickMedia.cpp b/src/QuickMedia.cpp
index ba97794..0914df2 100644
--- a/src/QuickMedia.cpp
+++ b/src/QuickMedia.cpp
@@ -606,6 +606,7 @@ namespace QuickMedia {
XSetIOErrorHandler(x_io_error_handler);
wm_delete_window_atom = XInternAtom(disp, "WM_DELETE_WINDOW", False);
+ net_wm_ping_atom = XInternAtom(disp, "_NET_WM_PING", True);
int screen = DefaultScreen(disp);
sf::Vector2i monitor_size;
@@ -1246,13 +1247,20 @@ namespace QuickMedia {
}
}
- bool Program::handle_window_close() {
- if(wm_delete_window_atom && XCheckTypedWindowEvent(disp, x11_window, ClientMessage, &xev) && (Atom)xev.xclient.data.l[0] == wm_delete_window_atom) {
- current_page = PageType::EXIT;
- window.close();
- return true;
+ void Program::handle_x11_events() {
+ window_closed = false;
+
+ while(XCheckTypedWindowEvent(disp, x11_window, ClientMessage, &xev)) {
+ if(net_wm_ping_atom && xev.xclient.format == 32 && (Atom)xev.xclient.data.l[0] == net_wm_ping_atom) {
+ fprintf(stderr, "Responding to X11 ping\n");
+ xev.xclient.window = DefaultRootWindow(disp);
+ XSendEvent(disp, DefaultRootWindow(disp), False, SubstructureNotifyMask | SubstructureRedirectMask, &xev);
+ } else if(wm_delete_window_atom && xev.xclient.format == 32 && (Atom)xev.xclient.data.l[0] == wm_delete_window_atom) {
+ current_page = PageType::EXIT;
+ window.close();
+ window_closed = true;
+ }
}
- return false;
}
void Program::base_event_handler(sf::Event &event, PageType previous_page, Body *body, SearchBar *search_bar, bool handle_keypress, bool handle_searchbar) {
@@ -1998,7 +2006,7 @@ namespace QuickMedia {
}
}
update_idle_state();
- handle_window_close();
+ handle_x11_events();
if(!loop_running || !window.isOpen())
break;
@@ -2348,7 +2356,8 @@ namespace QuickMedia {
}
}
- if(handle_window_close()) {
+ handle_x11_events();
+ if(window_closed) {
task.cancel();
task_result = TaskResult::CANCEL;
goto task_end;
@@ -2833,7 +2842,7 @@ namespace QuickMedia {
load_video_error_check();
}
}
- handle_window_close();
+ handle_x11_events();
if(video_player && video_player_window && XCheckTypedWindowEvent(disp, video_player_window, KeyPress, &xev)/* && xev.xkey.subwindow == video_player_window*/) {
#pragma GCC diagnostic push
@@ -3313,7 +3322,7 @@ namespace QuickMedia {
current_page = pop_page_stack();
}
}
- handle_window_close();
+ handle_x11_events();
if(num_manga_pages_future.valid() && num_manga_pages_future.wait_for(std::chrono::seconds(0)) == std::future_status::ready) {
num_manga_pages = num_manga_pages_future.get();
@@ -3460,7 +3469,7 @@ namespace QuickMedia {
}
}
}
- handle_window_close();
+ handle_x11_events();
if(download_in_progress && check_downloaded_timer.getElapsedTime().asMilliseconds() >= check_downloaded_timeout_ms) {
sf::String error_msg;
@@ -3588,7 +3597,7 @@ namespace QuickMedia {
idle_active_handler();
while(current_page == PageType::IMAGES_CONTINUOUS && window.isOpen()) {
- handle_window_close();
+ handle_x11_events();
window.clear(get_current_theme().background_color);
ImageViewerAction action = image_viewer.draw();
switch(action) {
@@ -4053,7 +4062,7 @@ namespace QuickMedia {
}
frame_skip_text_entry = false;
update_idle_state();
- handle_window_close();
+ handle_x11_events();
if(selected_file_for_upload.empty()) {
if(file_to_upload_thumbnail_data) {
@@ -4292,7 +4301,7 @@ namespace QuickMedia {
inputs[focused_input]->on_event(event);
}
update_idle_state();
- handle_window_close();
+ handle_x11_events();
if(current_page != PageType::CHAT_LOGIN)
break;
@@ -5841,7 +5850,7 @@ namespace QuickMedia {
}
frame_skip_text_entry = false;
update_idle_state();
- handle_window_close();
+ handle_x11_events();
matrix->update();
mention.update();
@@ -6860,7 +6869,8 @@ namespace QuickMedia {
}
}
- if(handle_window_close()) {
+ handle_x11_events();
+ if(window_closed) {
show_notification("QuickMedia", "Download cancelled!");
downloader->stop(false);
exit_code = 1;
@@ -7092,7 +7102,7 @@ namespace QuickMedia {
}
update_idle_state();
- handle_window_close();
+ handle_x11_events();
search_bar->update();
if(std::abs(file_name_entry.get_height() - prev_entry_height) >= 1.0f) {