From 81fae350c95f730eebefa2e92295b972072b1e18 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Thu, 13 Sep 2018 18:00:36 +0300 Subject: [PATCH 1/3] Fix draw being called twice when mapping the window --- src/dunst.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/dunst.c b/src/dunst.c index 5abd86e..0e98055 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -51,8 +51,12 @@ static gboolean run(void *data) static gint64 next_timeout = 0; - if (!x_win_visible(win) && queues_length_displayed() > 0) { + // Call draw before showing the window to avoid flickering + if (queues_length_displayed() > 0) { draw(); + } + + if (!x_win_visible(win) && queues_length_displayed() > 0) { x_win_show(win); } @@ -60,10 +64,6 @@ static gboolean run(void *data) x_win_hide(win); } - if (x_win_visible(win)) { - draw(); - } - if (x_win_visible(win)) { gint64 now = time_monotonic_now(); gint64 sleep = queues_get_next_datachange(now); From 69100790a1c720ef6af70d0879145969172ba4c5 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Thu, 13 Sep 2018 18:04:26 +0300 Subject: [PATCH 2/3] Do not wake up on focus events Focus events do not mark any change in state of the notifications so calling wake_up as a response is a wake of CPU cycles. Instead treat them like PropertyNotify and only redraw if we need to change monitors. --- src/x11/x.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/x11/x.c b/src/x11/x.c index 21eed84..b80f4fb 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -326,22 +326,16 @@ gboolean x_mainloop_fd_dispatch(GSource *source, GSourceFunc callback, gpointer wake_up(); } break; - case FocusIn: - LOG_D("XEvent: processing 'FocusIn'"); - wake_up(); - break; - case FocusOut: - LOG_D("XEvent: processing 'FocusOut'"); - wake_up(); - break; case CreateNotify: LOG_D("XEvent: processing 'CreateNotify'"); if (win->visible && ev.xcreatewindow.override_redirect == 0) XRaiseWindow(xctx.dpy, win->xwin); break; + case FocusIn: + case FocusOut: case PropertyNotify: - LOG_D("XEvent: processing 'PropertyNotify'"); + LOG_D("XEvent: Checking for active sceen changes"); fullscreen_now = have_fullscreen_window(); scr = get_active_screen(); From 7ac054b3cca2f6649b28f315d421e8cfbfc2df01 Mon Sep 17 00:00:00 2001 From: Nikos Tsipinakis Date: Thu, 20 Sep 2018 10:40:29 +0300 Subject: [PATCH 3/3] Simplify window showing and hiding As suggested by @bebehei make x_win_{show,hide} callable at any time and avoid double checking the queue length. --- src/dunst.c | 15 ++++++--------- src/x11/x.c | 6 ++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/dunst.c b/src/dunst.c index 0e98055..05cd63a 100644 --- a/src/dunst.c +++ b/src/dunst.c @@ -51,20 +51,17 @@ static gboolean run(void *data) static gint64 next_timeout = 0; - // Call draw before showing the window to avoid flickering - if (queues_length_displayed() > 0) { + bool active = queues_length_displayed() > 0; + + if (active) { + // Call draw before showing the window to avoid flickering draw(); - } - - if (!x_win_visible(win) && queues_length_displayed() > 0) { x_win_show(win); - } - - if (x_win_visible(win) && queues_length_displayed() == 0) { + } else { x_win_hide(win); } - if (x_win_visible(win)) { + if (active) { gint64 now = time_monotonic_now(); gint64 sleep = queues_get_next_datachange(now); gint64 timeout_at = now + sleep; diff --git a/src/x11/x.c b/src/x11/x.c index b80f4fb..857ff8b 100644 --- a/src/x11/x.c +++ b/src/x11/x.c @@ -674,9 +674,8 @@ void x_win_destroy(window_x11 *win) void x_win_show(window_x11 *win) { /* window is already mapped or there's nothing to show */ - if (win->visible || queues_length_displayed() == 0) { + if (win->visible) return; - } x_shortcut_grab(&settings.close_ks); x_shortcut_grab(&settings.close_all_ks); @@ -706,6 +705,9 @@ void x_win_show(window_x11 *win) */ void x_win_hide(window_x11 *win) { + if (!win->visible) + return; + x_shortcut_ungrab(&settings.close_ks); x_shortcut_ungrab(&settings.close_all_ks); x_shortcut_ungrab(&settings.context_ks);