static GQuark _deactivate_quark = 0;
static GQuark _activate_quark = 0;
static GQuark _state_quark = 0;
+static GQuark _state_changed_focused_quark = 0;
int _dbg = 0;
spi_registry_object_finalize (GObject *object)
{
DBG (1, g_warning ("spi_registry_object_finalize called\n"));
+ g_object_unref (SPI_REGISTRY (object)->de_controller);
- /* TODO: unref deviceeventcontroller, which disconnects key listener */
G_OBJECT_CLASS (spi_registry_parent_class)->finalize (object);
}
while (!g_queue_is_empty (registry->deferred_event_queue)) {
q_ctx = g_queue_pop_tail (registry->deferred_event_queue);
#ifdef SPI_QUEUE_DEBUG
- fprintf (stderr, "%s! %s [n=%d] %p\n", (discard ? "discard" : "start pop"),
+ fprintf (stderr, "%s! %s [n=%d] %p\n", (discard ? "discard" : "pop"),
q_ctx->etype.event_name,
(int) registry->deferred_event_queue->length, q_ctx);
#endif
if (!discard) {
q_ctx->ev = ev;
registry_emit_event (registry, q_ctx);
- fprintf (stderr, "%s! %s [n=%d], %p\n", (discard ? "discard" : "end pop"),
- q_ctx->etype.event_name,
- (int) registry->deferred_event_queue->length, q_ctx);
}
- bonobo_object_release_unref (q_ctx->source, NULL);
+ if (discard &&
+ (q_ctx->etype.type_cat == ETYPE_OBJECT) &&
+ (q_ctx->etype.major == _state_quark) &&
+ (q_ctx->etype.minor == _state_changed_focused_quark)) {
+ registry->focus_object = q_ctx->source;
+#ifdef SPI_QUEUE_DEBUG
+ fprintf (stderr, "discard!: set focus_object %p\n", registry->focus_object);
+#endif
+ }
+ else {
+ bonobo_object_release_unref (q_ctx->source, NULL);
+ }
CORBA_free ((void *)q_ctx->etype.event_name);
CORBA_free ((void *)q_ctx->e_out.type);
-#if 0
- bonobo_object_release_unref (q_ctx->e_out.source, NULL);
-#endif
g_free (q_ctx);
}
registry->is_queueing = FALSE;
fprintf (stderr, "timeout! flushing queue...\n");
#endif
CORBA_exception_init (&ev);
+ registry->queue_handler_id = 0;
registry_flush_event_queue (registry, FALSE, &ev);
return FALSE;
}
return (ctx->etype.type_cat == ETYPE_WINDOW) ? TRUE : FALSE;
}
+#ifdef SPI_QUEUE_DEBUG
+#include <sys/time.h>
+#endif
+
static void
registry_start_queue (SpiRegistry *registry)
{
- g_timeout_add_full (G_PRIORITY_HIGH_IDLE,
- registry->exit_notify_timeout,
- registry_timeout_flush_queue, registry,
- NULL);
- registry->is_queueing = 1;
+#ifdef SPI_QUEUE_DEBUG
+ struct timeval tp;
+ gettimeofday (&tp, NULL);
+ fprintf (stderr, "start queueing at %i.%.6i\n", tp.tv_sec, tp.tv_usec);
+#endif
+ if (registry->queue_handler_id != 0)
+ g_source_remove (registry->queue_handler_id);
+
+ if (registry->focus_object)
+ {
+#ifdef SPI_QUEUE_DEBUG
+ fprintf (stderr, "registry_start_queue: release focus_object %p\n", registry->focus_object);
+#endif
+ bonobo_object_release_unref (registry->focus_object, NULL);
+ registry->focus_object = NULL;
+ }
+ registry->queue_handler_id = g_timeout_add_full (G_PRIORITY_HIGH_IDLE,
+ registry->exit_notify_timeout,
+ registry_timeout_flush_queue, registry,
+ NULL);
+ registry->is_queueing = TRUE;
+}
+
+static gboolean
+registry_discard_event (SpiRegistry *registry, NotifyContext *ctx)
+{
+ gboolean ret = FALSE;
+
+ if (ctx->etype.type_cat == ETYPE_FOCUS)
+ {
+ if (registry->focus_object)
+ {
+ if (CORBA_Object_is_equivalent (registry->focus_object, ctx->source, NULL))
+ {
+ ret = TRUE;
+ }
+#ifdef SPI_QUEUE_DEBUG
+ fprintf (stderr, "registry_discard_event: release focus_object %p\n", registry->focus_object);
+#endif
+ bonobo_object_release_unref (registry->focus_object, NULL);
+ registry->focus_object = NULL;
+ }
+ }
+ return ret;
}
static gboolean
registry_start_queue (registry);
}
/* defer all object:state-change events after a window:deactivate */
- else if ((ctx->etype.type_cat == ETYPE_OBJECT) &&
- (ctx->etype.major == _state_quark)) {
+ else if ((ctx->etype.type_cat == ETYPE_FOCUS) ||
+ ((ctx->etype.type_cat == ETYPE_OBJECT) &&
+ (ctx->etype.major == _state_quark))) {
defer = TRUE;
}
return defer;
}
-static void
+static gboolean
registry_queue_event (SpiRegistry *registry, NotifyContext *ctx)
{
NotifyContext *q_ctx = registry_clone_notify_context (ctx);
#ifdef SPI_QUEUE_DEBUG
if (q_ctx->etype.type_cat != ETYPE_MOUSE)
- fprintf (stderr, "start push! %s %p\n", q_ctx->etype.event_name, q_ctx);
-#endif
- g_queue_push_head (registry->deferred_event_queue, q_ctx);
-#ifdef SPI_QUEUE_DEBUG
- if (q_ctx->etype.type_cat != ETYPE_MOUSE)
- fprintf (stderr, "end push! %s %p\n", q_ctx->etype.event_name, q_ctx);
+ fprintf (stderr, "push! %s %p\n", q_ctx->etype.event_name, q_ctx);
#endif
+ if (registry->is_queueing)
+ {
+ g_queue_push_head (registry->deferred_event_queue, q_ctx);
+
+ return FALSE;
+ }
+ else
+ {
+ bonobo_object_release_unref (q_ctx->source, NULL);
+ CORBA_free ((void *)q_ctx->etype.event_name);
+ CORBA_free ((void *)q_ctx->e_out.type);
+ g_free (q_ctx);
+ return TRUE;
+ }
}
/**
registry_filter_event (SpiRegistry *registry, NotifyContext *ctx,
CORBA_Environment *ev)
{
- gboolean queue_is_empty = FALSE;
g_assert (ctx != NULL);
- /* case #1 is not yet used */
+ if (registry_discard_event (registry, ctx))
+ return FALSE;
+
if (registry_defer_on_event (registry, ctx)) { /* #2, #3 */
if (registry->is_queueing) {
- registry_queue_event (registry, ctx);
- return FALSE;
+ return registry_queue_event (registry, ctx);
}
else { /* #4a */
return TRUE;
#ifdef SPI_QUEUE_DEBUG
fprintf (stderr, "event %s caused reset, discard=%d\n",
ctx->etype.event_name, (int) discard);
+ {
+ struct timeval tp;
+ gettimeofday (&tp, NULL);
+ fprintf (stderr, "event at %i.%.6i\n", tp.tv_sec, tp.tv_usec);
+ }
#endif
registry_flush_event_queue (registry, discard, ev);
return (discard ? FALSE : TRUE);
ctx.e_out = *e;
ctx.source = e->source;
+#ifdef SPI_QUEUE_DEBUG
+ if (ctx.etype.type_cat != ETYPE_MOUSE)
+ fprintf (stderr, "filter! %s level: %d\n", ctx.etype.event_name, level);
+#endif
if (registry_filter_event (registry, &ctx, ev)) {
#ifdef SPI_QUEUE_DEBUG
if (ctx.etype.type_cat != ETYPE_MOUSE)
-{
fprintf (stderr, "emit! %s level: %d\n", ctx.etype.event_name, level);
- fprintf (stderr, "emit! %p %p\n", ctx.e_out, ctx.e_out.type);
-}
#endif
registry_emit_event (registry, &ctx);
}
_deactivate_quark = g_quark_from_static_string ("deactivate");
_activate_quark = g_quark_from_static_string ("activate");
_state_quark = g_quark_from_static_string ("state-changed");
+ _state_changed_focused_quark = g_quark_from_static_string ("state-changedfocused");
}
static void
{
spi_registry_set_debug (g_getenv ("AT_SPI_DEBUG"));
/*
- * TODO: fixme, this module makes the foolish assumptions that
+ * TODO: FIXME, this module makes the foolish assumptions that
* registryd uses the same display as the apps, and that the
* DISPLAY environment variable is set.
*/
registry->window_listeners = NULL;
registry->toolkit_listeners = NULL;
registry->deferred_event_queue = g_queue_new ();
- registry->exit_notify_timeout = 100;
+ registry->exit_notify_timeout = 200;
+ registry->queue_handler_id = 0;
+ /*
+ * The focus_object is set when a state-change:focused event is discarded
+ * after a window:deactivate event is received because a window:activate
+ * event has been received for the same window within the timeout period.
+ * The focus object is used to suppress a focus event for that object.
+ * It is released when a window:deactivate event is received.
+ */
+ registry->focus_object = NULL;
registry->desktop = spi_desktop_new ();
/* Register callback notification for application addition and removal */
g_signal_connect (G_OBJECT (registry->desktop),