added gtkutil_compress_motion() utility function to seek and destroy

Mon Feb 28 19:11:39 GMT 2000  Adam D. Moss <adam@gimp.org>

	* app/cursorutil.c app/cursorutil.h:
	added gtkutil_compress_motion() utility function to seek and
	destroy outstanding pointer motion events from the gdk event queue
	for a given widget.

	* app/edit_selection.c:305: Use gtkutil_compress_motion() to
	do a more thorough job of tracking motion (something recently
	started interleaving our motion events with others, largely
	nullifying the effectiveness of GDK_POINTER_MOTION_HINT_MASK).

	* app/edit_selection.c:704: Yikes, the key-press snooping code
	was turning part of the event queue back-to-front with each
	compressed key-press.  (Still looks a bit bogus overall; looks
	as though it could transplant a whole chunk of the start of
	the event queue right onto the end.  I'll probably disable it
	unless someone points out that I'm a doofus.)
This commit is contained in:
GMT 2000 Adam D. Moss 2000-02-28 19:25:42 +00:00 committed by Adam D. Moss
parent de605b01ee
commit f5b589820b
11 changed files with 224 additions and 31 deletions

View File

@ -1,3 +1,22 @@
Mon Feb 28 19:11:39 GMT 2000 Adam D. Moss <adam@gimp.org>
* app/cursorutil.c app/cursorutil.h:
added gtkutil_compress_motion() utility function to seek and
destroy outstanding pointer motion events from the gdk event queue
for a given widget.
* app/edit_selection.c:305: Use gtkutil_compress_motion() to
do a more thorough job of tracking motion (something recently
started interleaving our motion events with others, largely
nullifying the effectiveness of GDK_POINTER_MOTION_HINT_MASK).
* app/edit_selection.c:704: Yikes, the key-press snooping code
was turning part of the event queue back-to-front with each
compressed key-press. (Still looks a bit bogus overall; looks
as though it could transplant a whole chunk of the start of
the event queue right onto the end. I'll probably disable it
unless someone points out that I'm a doofus.)
Mon Feb 28 19:37:25 CET 2000 Sven Neumann <sven@gimp.org>
* plug-ins/gap/gap_arr_dialog.[ch]

View File

@ -189,7 +189,7 @@ gimp_add_busy_cursors (void)
gdk_flush();
}
int
gint
gimp_remove_busy_cursors (gpointer data)
{
GDisplay *gdisp;
@ -213,5 +213,58 @@ gimp_remove_busy_cursors (gpointer data)
}
/***************************************************************/
/* gtkutil_compress_motion:
This function walks the whole GDK event queue seeking motion events
corresponding to the widget 'widget'. If it finds any it will
remove them from the queue, write the most recent motion offset
to 'lastmotion_x' and 'lastmotion_y', then return TRUE. Otherwise
it will return FALSE and 'lastmotion_x' / 'lastmotion_y' will be
untouched.
*/
/* The gtkutil_compress_motion function source may be re-used under
the XFree86-style license. <adam@gimp.org> */
gboolean
gtkutil_compress_motion (GtkWidget *widget,
gdouble *lastmotion_x,
gdouble *lastmotion_y)
{
GdkEvent *event;
GList *requeued_events = NULL;
gboolean success = FALSE;
/* Move the entire GDK event queue to a private list, filtering
out any motion events for the desired widget. */
while (gdk_events_pending ())
{
event = gdk_event_get ();
if ((gtk_get_event_widget (event) == widget) &&
(event->any.type == GDK_MOTION_NOTIFY))
{
*lastmotion_x = event->motion.x;
*lastmotion_y = event->motion.y;
gdk_event_free(event);
success = TRUE;
}
else
{
requeued_events = g_list_append (requeued_events, event);
}
}
/* Replay the remains of our private event list back into the
event queue in order. */
while (requeued_events)
{
gdk_event_put ((GdkEvent*)requeued_events->data);
gdk_event_free ((GdkEvent*)requeued_events->data);
requeued_events =
g_list_remove_link (requeued_events, requeued_events);
}
return success;
}

View File

@ -18,12 +18,16 @@
#ifndef __CURSORUTIL_H__
#define __CURSORUTIL_H__
#include <glib.h>
#include <gdk/gdktypes.h>
#if defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_X11)
/* Stopgap measure to detect build with current CVS GTk+ */
#include <gdk/gdkcursor.h>
#endif
#include <gtk/gtk.h>
typedef enum
{
GIMP_MOUSE1_CURSOR = (GDK_LAST_CURSOR + 2),
@ -47,6 +51,9 @@ void unset_win_cursor (GdkWindow *);
void gimp_add_busy_cursors_until_idle (void);
void gimp_add_busy_cursors (void);
int gimp_remove_busy_cursors (gpointer);
gint gimp_remove_busy_cursors (gpointer);
gboolean gtkutil_compress_motion (GtkWidget *widget,
gdouble *lastmotion_x, gdouble *lastmotion_y);
#endif /* __CURSORUTIL_H__ */

View File

@ -19,8 +19,11 @@
#include <stdlib.h>
#include <stdarg.h>
#include "gdk/gdkkeysyms.h"
#include <gdk/gdkkeysyms.h>
#include "appenv.h"
#include "cursorutil.h"
#include "draw_core.h"
#include "drawable.h"
#include "tools.h"
@ -282,10 +285,11 @@ edit_selection_motion (Tool *tool,
{
GDisplay * gdisp;
gchar offset[STATUSBAR_SIZE];
gdouble lastmotion_x, lastmotion_y;
if (tool->state != ACTIVE)
{
g_warning ("Tracking motion while !ACTIVE");
g_warning ("BUG: Tracking motion while !ACTIVE");
return;
}
@ -295,9 +299,21 @@ edit_selection_motion (Tool *tool,
draw_core_pause (edit_select.core, tool);
edit_selection_snap (gdisp, mevent->x, mevent->y);
/**********************************************adam hack*************/
/* Perform motion compression so that we don't lag and/or waste time. */
if (!gtkutil_compress_motion(gtk_get_event_widget((GdkEvent*)mevent),
&lastmotion_x, &lastmotion_y))
{
lastmotion_x = mevent->x;
lastmotion_y = mevent->y;
}
/* now do the actual move. */
edit_selection_snap (gdisp, RINT(lastmotion_x), RINT(lastmotion_y));
/******************************************* adam's live move *******/
/********************************************************************/
{
gint x, y;
@ -685,7 +701,7 @@ process_event_queue_keys (GdkEventKey *kevent, ...)
}
if (!discard_event)
list = g_list_prepend(list, event);
list = g_list_append(list, event);
else
gdk_event_free(event);
}

View File

@ -127,10 +127,12 @@ move_tool_button_press (Tool *tool,
/* if we've got an active tool grab the pointer */
if (tool->state == ACTIVE)
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
{
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
}
}

View File

@ -19,8 +19,11 @@
#include <stdlib.h>
#include <stdarg.h>
#include "gdk/gdkkeysyms.h"
#include <gdk/gdkkeysyms.h>
#include "appenv.h"
#include "cursorutil.h"
#include "draw_core.h"
#include "drawable.h"
#include "tools.h"
@ -282,10 +285,11 @@ edit_selection_motion (Tool *tool,
{
GDisplay * gdisp;
gchar offset[STATUSBAR_SIZE];
gdouble lastmotion_x, lastmotion_y;
if (tool->state != ACTIVE)
{
g_warning ("Tracking motion while !ACTIVE");
g_warning ("BUG: Tracking motion while !ACTIVE");
return;
}
@ -295,9 +299,21 @@ edit_selection_motion (Tool *tool,
draw_core_pause (edit_select.core, tool);
edit_selection_snap (gdisp, mevent->x, mevent->y);
/**********************************************adam hack*************/
/* Perform motion compression so that we don't lag and/or waste time. */
if (!gtkutil_compress_motion(gtk_get_event_widget((GdkEvent*)mevent),
&lastmotion_x, &lastmotion_y))
{
lastmotion_x = mevent->x;
lastmotion_y = mevent->y;
}
/* now do the actual move. */
edit_selection_snap (gdisp, RINT(lastmotion_x), RINT(lastmotion_y));
/******************************************* adam's live move *******/
/********************************************************************/
{
gint x, y;
@ -685,7 +701,7 @@ process_event_queue_keys (GdkEventKey *kevent, ...)
}
if (!discard_event)
list = g_list_prepend(list, event);
list = g_list_append(list, event);
else
gdk_event_free(event);
}

View File

@ -19,8 +19,11 @@
#include <stdlib.h>
#include <stdarg.h>
#include "gdk/gdkkeysyms.h"
#include <gdk/gdkkeysyms.h>
#include "appenv.h"
#include "cursorutil.h"
#include "draw_core.h"
#include "drawable.h"
#include "tools.h"
@ -282,10 +285,11 @@ edit_selection_motion (Tool *tool,
{
GDisplay * gdisp;
gchar offset[STATUSBAR_SIZE];
gdouble lastmotion_x, lastmotion_y;
if (tool->state != ACTIVE)
{
g_warning ("Tracking motion while !ACTIVE");
g_warning ("BUG: Tracking motion while !ACTIVE");
return;
}
@ -295,9 +299,21 @@ edit_selection_motion (Tool *tool,
draw_core_pause (edit_select.core, tool);
edit_selection_snap (gdisp, mevent->x, mevent->y);
/**********************************************adam hack*************/
/* Perform motion compression so that we don't lag and/or waste time. */
if (!gtkutil_compress_motion(gtk_get_event_widget((GdkEvent*)mevent),
&lastmotion_x, &lastmotion_y))
{
lastmotion_x = mevent->x;
lastmotion_y = mevent->y;
}
/* now do the actual move. */
edit_selection_snap (gdisp, RINT(lastmotion_x), RINT(lastmotion_y));
/******************************************* adam's live move *******/
/********************************************************************/
{
gint x, y;
@ -685,7 +701,7 @@ process_event_queue_keys (GdkEventKey *kevent, ...)
}
if (!discard_event)
list = g_list_prepend(list, event);
list = g_list_append(list, event);
else
gdk_event_free(event);
}

View File

@ -127,10 +127,12 @@ move_tool_button_press (Tool *tool,
/* if we've got an active tool grab the pointer */
if (tool->state == ACTIVE)
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
{
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
}
}

View File

@ -127,10 +127,12 @@ move_tool_button_press (Tool *tool,
/* if we've got an active tool grab the pointer */
if (tool->state == ACTIVE)
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
{
gdk_pointer_grab (gdisp->canvas->window, FALSE,
GDK_POINTER_MOTION_HINT_MASK | GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK,
NULL, NULL, bevent->time);
}
}

View File

@ -189,7 +189,7 @@ gimp_add_busy_cursors (void)
gdk_flush();
}
int
gint
gimp_remove_busy_cursors (gpointer data)
{
GDisplay *gdisp;
@ -213,5 +213,58 @@ gimp_remove_busy_cursors (gpointer data)
}
/***************************************************************/
/* gtkutil_compress_motion:
This function walks the whole GDK event queue seeking motion events
corresponding to the widget 'widget'. If it finds any it will
remove them from the queue, write the most recent motion offset
to 'lastmotion_x' and 'lastmotion_y', then return TRUE. Otherwise
it will return FALSE and 'lastmotion_x' / 'lastmotion_y' will be
untouched.
*/
/* The gtkutil_compress_motion function source may be re-used under
the XFree86-style license. <adam@gimp.org> */
gboolean
gtkutil_compress_motion (GtkWidget *widget,
gdouble *lastmotion_x,
gdouble *lastmotion_y)
{
GdkEvent *event;
GList *requeued_events = NULL;
gboolean success = FALSE;
/* Move the entire GDK event queue to a private list, filtering
out any motion events for the desired widget. */
while (gdk_events_pending ())
{
event = gdk_event_get ();
if ((gtk_get_event_widget (event) == widget) &&
(event->any.type == GDK_MOTION_NOTIFY))
{
*lastmotion_x = event->motion.x;
*lastmotion_y = event->motion.y;
gdk_event_free(event);
success = TRUE;
}
else
{
requeued_events = g_list_append (requeued_events, event);
}
}
/* Replay the remains of our private event list back into the
event queue in order. */
while (requeued_events)
{
gdk_event_put ((GdkEvent*)requeued_events->data);
gdk_event_free ((GdkEvent*)requeued_events->data);
requeued_events =
g_list_remove_link (requeued_events, requeued_events);
}
return success;
}

View File

@ -18,12 +18,16 @@
#ifndef __CURSORUTIL_H__
#define __CURSORUTIL_H__
#include <glib.h>
#include <gdk/gdktypes.h>
#if defined (GDK_WINDOWING_WIN32) || defined (GDK_WINDOWING_X11)
/* Stopgap measure to detect build with current CVS GTk+ */
#include <gdk/gdkcursor.h>
#endif
#include <gtk/gtk.h>
typedef enum
{
GIMP_MOUSE1_CURSOR = (GDK_LAST_CURSOR + 2),
@ -47,6 +51,9 @@ void unset_win_cursor (GdkWindow *);
void gimp_add_busy_cursors_until_idle (void);
void gimp_add_busy_cursors (void);
int gimp_remove_busy_cursors (gpointer);
gint gimp_remove_busy_cursors (gpointer);
gboolean gtkutil_compress_motion (GtkWidget *widget,
gdouble *lastmotion_x, gdouble *lastmotion_y);
#endif /* __CURSORUTIL_H__ */