[Goodies-commits] r3177 - in xfce4-places-plugin/trunk: . panel-plugin
Diego Ongaro
ongardie at xfce.org
Sat Sep 8 06:17:29 CEST 2007
Author: ongardie
Date: 2007-09-08 04:17:29 +0000 (Sat, 08 Sep 2007)
New Revision: 3177
Modified:
xfce4-places-plugin/trunk/ChangeLog
xfce4-places-plugin/trunk/panel-plugin/places.h
xfce4-places-plugin/trunk/panel-plugin/view.c
Log:
2007-09-07 Diego Ongaro <ongardie at gmail.com>
* view.c: added menu timeout to poll for model changes
Modified: xfce4-places-plugin/trunk/ChangeLog
===================================================================
--- xfce4-places-plugin/trunk/ChangeLog 2007-09-08 04:14:05 UTC (rev 3176)
+++ xfce4-places-plugin/trunk/ChangeLog 2007-09-08 04:17:29 UTC (rev 3177)
@@ -5,6 +5,7 @@
* view.c: improve how icon theme changes and screen changes are
handled
* *.{c,h}: removed all C++-style comments
+ * view.c: added menu timeout to poll for model changes
2007-08-23 Diego Ongaro <ongardie at gmail.com>
Modified: xfce4-places-plugin/trunk/panel-plugin/places.h
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/places.h 2007-09-08 04:14:05 UTC (rev 3176)
+++ xfce4-places-plugin/trunk/panel-plugin/places.h 2007-09-08 04:17:29 UTC (rev 3177)
@@ -44,6 +44,7 @@
GtkWidget *view_menu;
GtkTooltips *view_tooltips;
gboolean view_needs_separator;
+ guint view_menu_timeout_id;
/* model */
GList *bookmark_groups;
Modified: xfce4-places-plugin/trunk/panel-plugin/view.c
===================================================================
--- xfce4-places-plugin/trunk/panel-plugin/view.c 2007-09-08 04:14:05 UTC (rev 3176)
+++ xfce4-places-plugin/trunk/panel-plugin/view.c 2007-09-08 04:17:29 UTC (rev 3177)
@@ -48,6 +48,33 @@
#include "model_user.h"
#include "cfg.h"
+/* Debugging */
+#if defined(DEBUG) && (DEBUG > 0)
+
+static guint places_debug_menu_timeout_count = 0;
+#define PLACES_DEBUG_MENU_TIMEOUT_COUNT(delta) \
+ G_STMT_START{ \
+ places_debug_menu_timeout_count += delta; \
+ DBG("Menu timeout count: %d", places_debug_menu_timeout_count); \
+ g_assert(places_debug_menu_timeout_count == 0 || \
+ places_debug_menu_timeout_count == 1); \
+ if(pd != NULL){ \
+ if(places_debug_menu_timeout_count == 0) \
+ g_assert(pd->view_menu_timeout_id == 0); \
+ else \
+ g_assert(pd->view_menu_timeout_id > 0); \
+ } \
+ }G_STMT_END
+
+#else
+
+#define PLACES_DEBUG_MENU_TIMEOUT_COUNT(delta) \
+ G_STMT_START{ \
+ (void) 0; \
+ }G_STMT_END
+
+#endif
+
/* UI Helpers */
static void places_view_update_menu(PlacesData*);
@@ -61,6 +88,8 @@
static void places_view_cb_theme_changed(PlacesData *pd);
/* - Menu */
+static gboolean places_view_cb_menu_timeout(PlacesData *pd);
+
static void places_view_cb_menu_position(GtkMenu*,
gint *x, gint *y,
gboolean *push_in,
@@ -87,6 +116,7 @@
pd->view_needs_separator = FALSE;
pd->view_menu = NULL;
+ pd->view_menu_timeout_id = 0;
pd->cfg = places_cfg_new(pd);
places_view_reconfigure_model(pd);
@@ -361,6 +391,22 @@
(GtkMenuPositionFunc) places_view_cb_menu_position,
pd, 0,
gtk_get_current_event_time ());
+
+ /* menu timeout to poll for model changes */
+ if(pd->view_menu_timeout_id == 0){
+#if GLIB_CHECK_VERSION(2,14,0)
+ pd->view_menu_timeout_id = g_timeout_add_seconds_full(G_PRIORITY_LOW, 2,
+ (GSourceFunc) places_view_cb_menu_timeout, pd,
+ NULL);
+#else
+ pd->view_menu_timeout_id = g_timeout_add_full(G_PRIORITY_LOW, 2000,
+ (GSourceFunc) places_view_cb_menu_timeout, pd,
+ NULL);
+#endif
+ PLACES_DEBUG_MENU_TIMEOUT_COUNT(1);
+ }else{
+ PLACES_DEBUG_MENU_TIMEOUT_COUNT(0);
+ }
}
void
@@ -485,7 +531,32 @@
}
/* Menu callbacks */
+static gboolean /* return false to stop calling it */
+places_view_cb_menu_timeout(PlacesData *pd){
+ if(!pd->view_menu_timeout_id)
+ goto killtimeout;
+
+ if(pd->view_menu == NULL || !GTK_WIDGET_VISIBLE(pd->view_menu))
+ goto killtimeout;
+
+ if(places_view_bookmarks_changed(pd->bookmark_groups))
+ places_view_open_menu(pd);
+
+ PLACES_DEBUG_MENU_TIMEOUT_COUNT(0);
+ return TRUE;
+
+ killtimeout:
+ if(pd->view_menu_timeout_id){
+ pd->view_menu_timeout_id = 0;
+ PLACES_DEBUG_MENU_TIMEOUT_COUNT(-1);
+ }else{
+ PLACES_DEBUG_MENU_TIMEOUT_COUNT(0);
+ }
+ return FALSE;
+
+}
+
/* Copied almost verbatim from xfdesktop plugin */
static void
places_view_cb_menu_position(GtkMenu *menu,
@@ -560,6 +631,15 @@
{
/* deactivate button */
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(pd->view_button), FALSE);
+
+ /* remove the timeout to save a tick */
+ if(pd->view_menu_timeout_id){
+ g_source_remove(pd->view_menu_timeout_id);
+ pd->view_menu_timeout_id = 0;
+ PLACES_DEBUG_MENU_TIMEOUT_COUNT(-1);
+ }else{
+ PLACES_DEBUG_MENU_TIMEOUT_COUNT(0);
+ }
}
/* Button */
More information about the Goodies-commits
mailing list