From 0da9aa2660b51ce6208b041cc6e14f15e522c289 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 2 May 2007 00:59:07 +0000 Subject: [PATCH] add a slight delay to the focus/desktop switch dialogs. so if you hit the key really fast there is no flicker. of course if you hit it fast but not fast enough there is still flicker. is this cool or does this make it feel bad? i dunno. we'll see.. make the keychain popup use the new delay popup facilities --- openbox/focus.c | 8 ++++---- openbox/keyboard.c | 23 +++-------------------- openbox/popup.c | 44 +++++++++++++++++++++++++++++++++++--------- openbox/popup.h | 13 +++++++++---- openbox/screen.c | 3 ++- 5 files changed, 53 insertions(+), 38 deletions(-) diff --git a/openbox/focus.c b/openbox/focus.c index c1d51477..aac6675e 100644 --- a/openbox/focus.c +++ b/openbox/focus.c @@ -318,10 +318,10 @@ static void popup_cycle(ObClient *c, gboolean show) (p->iconic ? p->icon_title : p->title), NULL); */ - icon_popup_show(focus_cycle_popup, - (title ? title : - (c->iconic ? c->icon_title : c->title)), - client_icon(p, 48, 48)); + icon_popup_delay_show(focus_cycle_popup, G_USEC_PER_SEC/12, + (title ? title : + (c->iconic ? c->icon_title : c->title)), + client_icon(p, 48, 48)); g_free(title); } } diff --git a/openbox/keyboard.c b/openbox/keyboard.c index c1151eb3..1509f69f 100644 --- a/openbox/keyboard.c +++ b/openbox/keyboard.c @@ -75,14 +75,6 @@ static gboolean chain_timeout(gpointer data) return FALSE; /* don't repeat */ } -static gboolean popup_show_timeout(gpointer data) -{ - gchar *text = data; - popup_show(popup, text); - - return FALSE; /* don't repeat */ -} - static void set_curpos(KeyBindingTree *newpos) { grab_keys(FALSE); @@ -103,19 +95,11 @@ static void set_curpos(KeyBindingTree *newpos) } popup_position(popup, NorthWestGravity, 10, 10); - if (popup->mapped) { - popup_show_timeout(text); - g_free(text); - } else { - ob_main_loop_timeout_remove(ob_main_loop, popup_show_timeout); - /* 1 second delay for the popup to show */ - ob_main_loop_timeout_add(ob_main_loop, G_USEC_PER_SEC, - popup_show_timeout, text, - g_direct_equal, g_free); - } + /* 1 second delay for the popup to show */ + popup_delay_show(popup, G_USEC_PER_SEC, text); + g_free(text); } else { popup_hide(popup); - ob_main_loop_timeout_remove(ob_main_loop, popup_show_timeout); } } @@ -362,7 +346,6 @@ void keyboard_shutdown(gboolean reconfig) interactive_states = NULL; ob_main_loop_timeout_remove(ob_main_loop, chain_timeout); - ob_main_loop_timeout_remove(ob_main_loop, popup_show_timeout); keyboard_unbind_all(); set_curpos(NULL); diff --git a/openbox/popup.c b/openbox/popup.c index 392aa9d1..a3c94653 100644 --- a/openbox/popup.c +++ b/openbox/popup.c @@ -25,9 +25,22 @@ #include "stacking.h" #include "event.h" #include "screen.h" +#include "mainloop.h" #include "render/render.h" #include "render/theme.h" +static gboolean popup_show_timeout(gpointer data) +{ + ObPopup *self = data; + + XMapWindow(ob_display, self->bg); + stacking_raise(INTERNAL_AS_WINDOW(self)); + self->mapped = TRUE; + self->delay_mapped = FALSE; + + return FALSE; /* don't repeat */ +} + ObPopup *popup_new(gboolean hasicon) { XSetWindowAttributes attrib; @@ -128,7 +141,7 @@ void popup_set_text_align(ObPopup *self, RrJustify align) self->a_text->texture[0].data.text.justify = align; } -void popup_show(ObPopup *self, gchar *text) +void popup_delay_show(ObPopup *self, gulong usec, gchar *text) { gint l, t, r, b; gint x, y, w, h; @@ -230,10 +243,19 @@ void popup_show(ObPopup *self, gchar *text) iconw, texth, self->draw_icon_data); } + /* do the actual showing */ if (!self->mapped) { - XMapWindow(ob_display, self->bg); - stacking_raise(INTERNAL_AS_WINDOW(self)); - self->mapped = TRUE; + if (usec) { + /* don't kill previous show timers */ + if (!self->delay_mapped) { + ob_main_loop_timeout_add(ob_main_loop, usec, + popup_show_timeout, self, + g_direct_equal, NULL); + self->delay_mapped = TRUE; + } + } else { + popup_show_timeout(self); + } } } @@ -245,6 +267,9 @@ void popup_hide(ObPopup *self) /* kill enter events cause by this unmapping */ event_ignore_queued_enters(); + } else if (self->delay_mapped) { + ob_main_loop_timeout_remove(ob_main_loop, popup_show_timeout); + self->delay_mapped = FALSE; } } @@ -288,8 +313,8 @@ void icon_popup_free(ObIconPopup *self) } } -void icon_popup_show(ObIconPopup *self, - gchar *text, const ObClientIcon *icon) +void icon_popup_delay_show(ObIconPopup *self, gulong usec, + gchar *text, const ObClientIcon *icon) { if (icon) { self->a_icon->texture[0].type = RR_TEXTURE_RGBA; @@ -299,7 +324,7 @@ void icon_popup_show(ObIconPopup *self, } else self->a_icon->texture[0].type = RR_TEXTURE_NONE; - popup_show(self->popup, text); + popup_delay_show(self->popup, usec, text); } static void pager_popup_draw_icon(gint px, gint py, gint w, gint h, @@ -448,7 +473,8 @@ void pager_popup_free(ObPagerPopup *self) } } -void pager_popup_show(ObPagerPopup *self, gchar *text, guint desk) +void pager_popup_delay_show(ObPagerPopup *self, gulong usec, + gchar *text, guint desk) { guint i; @@ -475,5 +501,5 @@ void pager_popup_show(ObPagerPopup *self, gchar *text, guint desk) self->desks = screen_num_desktops; self->curdesk = desk; - popup_show(self->popup, text); + popup_delay_show(self->popup, usec, text); } diff --git a/openbox/popup.h b/openbox/popup.h index 3ce0b5cc..66e0fcab 100644 --- a/openbox/popup.h +++ b/openbox/popup.h @@ -48,6 +48,7 @@ struct _ObPopup gint w; gint h; gboolean mapped; + gboolean delay_mapped; void (*draw_icon)(gint x, gint y, gint w, gint h, gpointer data); gpointer draw_icon_data; @@ -91,7 +92,8 @@ void popup_width_to_strings(ObPopup *self, gchar **strings, gint max); void popup_set_text_align(ObPopup *self, RrJustify align); -void popup_show(ObPopup *self, gchar *text); +#define popup_show(s, t) popup_delay_show((s),0,(t)) +void popup_delay_show(ObPopup *self, gulong usec, gchar *text); void popup_hide(ObPopup *self); RrAppearance *popup_icon_appearance(ObPopup *self); @@ -100,8 +102,9 @@ RrAppearance *popup_icon_appearance(ObPopup *self); ObIconPopup *icon_popup_new(); void icon_popup_free(ObIconPopup *self); -void icon_popup_show(ObIconPopup *self, - gchar *text, const struct _ObClientIcon *icon); +#define icon_popup_show(s, t, i) icon_popup_delay_show((s),0,(t),(i)) +void icon_popup_delay_show(ObIconPopup *self, gulong usec, + gchar *text, const struct _ObClientIcon *icon); #define icon_popup_hide(p) popup_hide((p)->popup) #define icon_popup_position(p, g, x, y) popup_position((p)->popup,(g),(x),(y)) #define icon_popup_width(p, w) popup_width((p)->popup,(w)) @@ -115,7 +118,9 @@ void icon_popup_show(ObIconPopup *self, ObPagerPopup *pager_popup_new(); void pager_popup_free(ObPagerPopup *self); -void pager_popup_show(ObPagerPopup *self, gchar *text, guint desk); +#define pager_popup_show(s, t, d) paper_popup_delay_show((s),0,(t),(d;2D)) +void pager_popup_delay_show(ObPagerPopup *self, gulong usec, + gchar *text, guint desk); #define pager_popup_hide(p) popup_hide((p)->popup) #define pager_popup_position(p, g, x, y) popup_position((p)->popup,(g),(x),(y)) #define pager_popup_width(p, w) popup_width((p)->popup,(w)) diff --git a/openbox/screen.c b/openbox/screen.c index a302828b..25b7a46d 100644 --- a/openbox/screen.c +++ b/openbox/screen.c @@ -601,7 +601,8 @@ void screen_desktop_popup(guint d, gboolean show) pager_popup_width(desktop_cycle_popup, MAX(a->width/3, POPUP_WIDTH)); pager_popup_height(desktop_cycle_popup, POPUP_HEIGHT); - pager_popup_show(desktop_cycle_popup, screen_desktop_names[d], d); + pager_popup_delay_show(desktop_cycle_popup, G_USEC_PER_SEC/12, + screen_desktop_names[d], d); } } -- 2.45.2