aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/QuickMedia.cpp44
1 files changed, 27 insertions, 17 deletions
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) {