diff --git a/ChangeLog b/ChangeLog index a97389cd8b..e75aff3c0c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2005-01-18 Matthias Clasen + + * gdk/gdkdisplay.h: + * gdk/x11/gdkwindow-x11.c (gdk_display_warp_pointer): + * gdk/win32/gdkwindow-win32.c (gdk_display_warp_pointer): Add + pointer warping to GDK. (#160437) + + * gtk/gtkcolorsel.c (key_press): Use gdk_display_warp_pointer. + 2005-01-18 Matthias Clasen * gtk/gtkstyle.c (gtk_default_draw_check) diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index a97389cd8b..e75aff3c0c 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,12 @@ +2005-01-18 Matthias Clasen + + * gdk/gdkdisplay.h: + * gdk/x11/gdkwindow-x11.c (gdk_display_warp_pointer): + * gdk/win32/gdkwindow-win32.c (gdk_display_warp_pointer): Add + pointer warping to GDK. (#160437) + + * gtk/gtkcolorsel.c (key_press): Use gdk_display_warp_pointer. + 2005-01-18 Matthias Clasen * gtk/gtkstyle.c (gtk_default_draw_check) diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index a97389cd8b..e75aff3c0c 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,12 @@ +2005-01-18 Matthias Clasen + + * gdk/gdkdisplay.h: + * gdk/x11/gdkwindow-x11.c (gdk_display_warp_pointer): + * gdk/win32/gdkwindow-win32.c (gdk_display_warp_pointer): Add + pointer warping to GDK. (#160437) + + * gtk/gtkcolorsel.c (key_press): Use gdk_display_warp_pointer. + 2005-01-18 Matthias Clasen * gtk/gtkstyle.c (gtk_default_draw_check) diff --git a/gdk/gdk.symbols b/gdk/gdk.symbols index cb579f3efe..c3e7a04079 100644 --- a/gdk/gdk.symbols +++ b/gdk/gdk.symbols @@ -98,6 +98,7 @@ gdk_display_supports_cursor_alpha gdk_display_supports_cursor_color gdk_display_supports_selection_notification gdk_display_sync +gdk_display_warp_pointer gdk_drag_abort gdk_drag_action_get_type G_GNUC_CONST gdk_drag_begin diff --git a/gdk/gdkdisplay.h b/gdk/gdkdisplay.h index bfdd1674ce..5aa2ec44e0 100644 --- a/gdk/gdkdisplay.h +++ b/gdk/gdkdisplay.h @@ -154,6 +154,10 @@ void gdk_display_get_pointer (GdkDisplay *disp GdkWindow * gdk_display_get_window_at_pointer (GdkDisplay *display, gint *win_x, gint *win_y); +void gdk_display_warp_pointer (GdkDisplay *display, + GdkScreen *screen, + gint x, + gint y); GdkDisplayPointerHooks *gdk_display_set_pointer_hooks (GdkDisplay *display, const GdkDisplayPointerHooks *new_hooks); diff --git a/gdk/win32/gdkwindow-win32.c b/gdk/win32/gdkwindow-win32.c index bb7502ac72..bc3f69d506 100644 --- a/gdk/win32/gdkwindow-win32.c +++ b/gdk/win32/gdkwindow-win32.c @@ -2140,6 +2140,15 @@ _gdk_windowing_get_pointer (GdkDisplay *display, _gdk_windowing_window_get_pointer (display, root_window, x, y, mask); } +void +gdk_display_warp_pointer (GdkDisplay *display, + GdkScreen *screen, + gint x, + gint y) +{ + SetCursorPos (x, y); +} + GdkWindow* _gdk_windowing_window_at_pointer (GdkDisplay *display, gint *win_x, diff --git a/gdk/x11/gdkwindow-x11.c b/gdk/x11/gdkwindow-x11.c index b14ff9f95c..bcde9073c4 100644 --- a/gdk/x11/gdkwindow-x11.c +++ b/gdk/x11/gdkwindow-x11.c @@ -3265,6 +3265,42 @@ _gdk_windowing_window_get_pointer (GdkDisplay *display, return return_val; } +/** + * gdk_display_warp_pointer: + * @display: a #GdkDisplay + * @screen: the screen of @display to warp the pointer to + * @x: the x coordinate of the destination + * @y: the y coordinate of the destination + * + * Warps the pointer of @display to the point @x,@y on + * the screen @screen, unless the pointer is confined + * to a window by a grab, in which case it will be moved + * as far as allowed by the grab. Warping the pointer + * creates events as if the user had moved the mouse + * instantaneously to the destination. + * + * Note that the pointer should normally be under the + * control of the user. This function was added to cover + * some rare use cases like keyboard navigation support + * for the color picker in the #GtkColorSelectionDialog. + * + * Since: 2.8 + */ +void +gdk_display_warp_pointer (GdkDisplay *display, + GdkScreen *screen, + gint x, + gint y) +{ + Display *xdisplay; + Window dest; + + xdisplay = GDK_DISPLAY_XDISPLAY (display); + dest = GDK_WINDOW_XWINDOW (gdk_screen_get_root_window (screen)); + + XWarpPointer (xdisplay, None, dest, 0, 0, 0, 0, x, y); +} + GdkWindow* _gdk_windowing_window_at_pointer (GdkDisplay *display, gint *win_x, diff --git a/gtk/gtkcolorsel.c b/gtk/gtkcolorsel.c index cb9006bb55..9916d4c876 100644 --- a/gtk/gtkcolorsel.c +++ b/gtk/gtkcolorsel.c @@ -63,14 +63,6 @@ #include -#ifdef GDK_WINDOWING_X11 -#include -#include "x11/gdkx.h" -#elif defined GDK_WINDOWING_WIN32 -#define WIN32_LEAN_AND_MEAN -#include -#endif - /* Number of elements in the custom palatte */ #define GTK_CUSTOM_PALETTE_WIDTH 10 #define GTK_CUSTOM_PALETTE_HEIGHT 2 @@ -1283,10 +1275,13 @@ key_press (GtkWidget *invisible, gpointer data) { GdkDisplay *display = gtk_widget_get_display (invisible); + GdkScreen *screen = gdk_event_get_screen ((GdkEvent *)event); guint state = event->state & gtk_accelerator_get_default_mod_mask (); gint x, y; gint dx, dy; + gdk_display_get_pointer (display, NULL, &x, &y, NULL); + dx = 0; dy = 0; @@ -1296,10 +1291,7 @@ key_press (GtkWidget *invisible, case GDK_Return: case GDK_KP_Enter: case GDK_KP_Space: - gdk_display_get_pointer (display, - NULL, &x, &y, NULL); - grab_color_at_mouse (gdk_event_get_screen ((GdkEvent *)event), - x, y, data); + grab_color_at_mouse (screen, x, y, data); /* fall through */ case GDK_Escape: @@ -1340,16 +1332,7 @@ key_press (GtkWidget *invisible, return FALSE; } -#ifdef GDK_WINDOWING_X11 - XWarpPointer (gdk_x11_display_get_xdisplay (display), - None, None, 0, 0, 0, 0, dx, dy); -#elif defined GDK_WINDOWING_WIN32 - { - POINT point; - if (GetCursorPos (&point)) - SetCursorPos (point.x + dx, point.y + dy); - } -#endif + gdk_display_warp_pointer (display, screen, x + dx, y + dy); return TRUE;