Initial version of input support
This commit is contained in:
@ -26,18 +26,18 @@
|
||||
* Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
|
||||
* file for a list of people on the GTK+ Team. See the ChangeLog
|
||||
* files for a list of changes. These files are distributed with
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
* GTK+ at ftp://ftp.gtk.org/pub/gtk/.
|
||||
*/
|
||||
|
||||
/* forward declarations */
|
||||
|
||||
static void gdk_input_check_proximity (GdkDisplay *display);
|
||||
|
||||
void
|
||||
void
|
||||
_gdk_input_init(GdkDisplay *display)
|
||||
{
|
||||
_gdk_init_input_core (display);
|
||||
GDK_DISPLAY_X11 (display)->input_ignore_core = FALSE;
|
||||
display->ignore_core_events = FALSE;
|
||||
_gdk_input_common_init (display, FALSE);
|
||||
}
|
||||
|
||||
@ -47,7 +47,6 @@ gdk_device_set_mode (GdkDevice *device,
|
||||
{
|
||||
GList *tmp_list;
|
||||
GdkDevicePrivate *gdkdev;
|
||||
GdkInputMode old_mode;
|
||||
GdkInputWindow *input_window;
|
||||
GdkDisplayX11 *display_impl;
|
||||
|
||||
@ -59,58 +58,35 @@ gdk_device_set_mode (GdkDevice *device,
|
||||
if (device->mode == mode)
|
||||
return TRUE;
|
||||
|
||||
old_mode = device->mode;
|
||||
device->mode = mode;
|
||||
|
||||
display_impl = GDK_DISPLAY_X11 (gdkdev->display);
|
||||
|
||||
if (mode == GDK_MODE_WINDOW)
|
||||
{
|
||||
device->has_cursor = FALSE;
|
||||
for (tmp_list = display_impl->input_windows; tmp_list; tmp_list = tmp_list->next)
|
||||
{
|
||||
input_window = (GdkInputWindow *)tmp_list->data;
|
||||
if (input_window->mode != GDK_EXTENSION_EVENTS_CURSOR)
|
||||
_gdk_input_enable_window (input_window->window, gdkdev);
|
||||
else
|
||||
if (old_mode != GDK_MODE_DISABLED)
|
||||
_gdk_input_disable_window (input_window->window, gdkdev);
|
||||
}
|
||||
}
|
||||
device->has_cursor = FALSE;
|
||||
else if (mode == GDK_MODE_SCREEN)
|
||||
device->has_cursor = TRUE;
|
||||
|
||||
display_impl = GDK_DISPLAY_X11 (gdkdev->display);
|
||||
for (tmp_list = display_impl->input_windows; tmp_list; tmp_list = tmp_list->next)
|
||||
{
|
||||
device->has_cursor = TRUE;
|
||||
for (tmp_list = display_impl->input_windows; tmp_list; tmp_list = tmp_list->next)
|
||||
_gdk_input_enable_window (((GdkInputWindow *)tmp_list->data)->window,
|
||||
gdkdev);
|
||||
}
|
||||
else /* mode == GDK_MODE_DISABLED */
|
||||
{
|
||||
for (tmp_list = display_impl->input_windows; tmp_list; tmp_list = tmp_list->next)
|
||||
{
|
||||
input_window = (GdkInputWindow *)tmp_list->data;
|
||||
if (old_mode != GDK_MODE_WINDOW ||
|
||||
input_window->mode != GDK_EXTENSION_EVENTS_CURSOR)
|
||||
_gdk_input_disable_window (input_window->window, gdkdev);
|
||||
}
|
||||
input_window = (GdkInputWindow *)tmp_list->data;
|
||||
_gdk_input_select_events (input_window->impl_window, gdkdev);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
gdk_input_check_proximity (GdkDisplay *display)
|
||||
{
|
||||
gint new_proximity = 0;
|
||||
GdkDisplayX11 *display_impl = GDK_DISPLAY_X11 (display);
|
||||
GList *tmp_list = display_impl->input_devices;
|
||||
gint new_proximity = 0;
|
||||
|
||||
while (tmp_list && !new_proximity)
|
||||
while (tmp_list && !new_proximity)
|
||||
{
|
||||
GdkDevicePrivate *gdkdev = (GdkDevicePrivate *)(tmp_list->data);
|
||||
|
||||
if (gdkdev->info.mode != GDK_MODE_DISABLED
|
||||
if (gdkdev->info.mode != GDK_MODE_DISABLED
|
||||
&& !GDK_IS_CORE (gdkdev)
|
||||
&& gdkdev->xdevice)
|
||||
{
|
||||
@ -118,7 +94,7 @@ gdk_input_check_proximity (GdkDisplay *display)
|
||||
gdkdev->xdevice);
|
||||
XInputClass *xic;
|
||||
int i;
|
||||
|
||||
|
||||
xic = state->data;
|
||||
for (i=0; i<state->num_classes; i++)
|
||||
{
|
||||
@ -135,117 +111,197 @@ gdk_input_check_proximity (GdkDisplay *display)
|
||||
}
|
||||
|
||||
XFreeDeviceState (state);
|
||||
}
|
||||
}
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
display_impl->input_ignore_core = new_proximity;
|
||||
display->ignore_core_events = new_proximity;
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_input_configure_event (XConfigureEvent *xevent,
|
||||
GdkWindow *window)
|
||||
{
|
||||
GdkWindowObject *priv = (GdkWindowObject *)window;
|
||||
GdkInputWindow *input_window;
|
||||
gint root_x, root_y;
|
||||
|
||||
input_window = _gdk_input_window_find(window);
|
||||
g_return_if_fail (input_window != NULL);
|
||||
|
||||
_gdk_input_get_root_relative_geometry(GDK_WINDOW_XDISPLAY (window),
|
||||
GDK_WINDOW_XWINDOW (window),
|
||||
&root_x, &root_y, NULL, NULL);
|
||||
|
||||
input_window->root_x = root_x;
|
||||
input_window->root_y = root_y;
|
||||
input_window = priv->input_window;
|
||||
if (input_window != NULL)
|
||||
{
|
||||
_gdk_input_get_root_relative_geometry (window, &root_x, &root_y);
|
||||
input_window->root_x = root_x;
|
||||
input_window->root_y = root_y;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_input_enter_event (XCrossingEvent *xevent,
|
||||
GdkWindow *window)
|
||||
void
|
||||
_gdk_input_crossing_event (GdkWindow *window,
|
||||
gboolean enter)
|
||||
{
|
||||
GdkDisplay *display = GDK_WINDOW_DISPLAY (window);
|
||||
GdkDisplayX11 *display_impl = GDK_DISPLAY_X11 (display);
|
||||
GdkWindowObject *priv = (GdkWindowObject *)window;
|
||||
GdkInputWindow *input_window;
|
||||
gint root_x, root_y;
|
||||
|
||||
input_window = _gdk_input_window_find (window);
|
||||
g_return_if_fail (input_window != NULL);
|
||||
if (enter)
|
||||
{
|
||||
gdk_input_check_proximity(display);
|
||||
|
||||
gdk_input_check_proximity(GDK_WINDOW_DISPLAY (window));
|
||||
|
||||
_gdk_input_get_root_relative_geometry(GDK_WINDOW_XDISPLAY (window),
|
||||
GDK_WINDOW_XWINDOW(window),
|
||||
&root_x, &root_y, NULL, NULL);
|
||||
|
||||
input_window->root_x = root_x;
|
||||
input_window->root_y = root_y;
|
||||
input_window = priv->input_window;
|
||||
if (input_window != NULL)
|
||||
{
|
||||
_gdk_input_get_root_relative_geometry (window, &root_x, &root_y);
|
||||
input_window->root_x = root_x;
|
||||
input_window->root_y = root_y;
|
||||
}
|
||||
}
|
||||
else
|
||||
display->ignore_core_events = FALSE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gdk_input_other_event (GdkEvent *event,
|
||||
XEvent *xevent,
|
||||
GdkWindow *window)
|
||||
static GdkEventType
|
||||
get_input_event_type (GdkDevicePrivate *gdkdev,
|
||||
XEvent *xevent,
|
||||
int *core_x, int *core_y)
|
||||
{
|
||||
GdkInputWindow *input_window;
|
||||
|
||||
if (xevent->type == gdkdev->buttonpress_type)
|
||||
{
|
||||
XDeviceButtonEvent *xie = (XDeviceButtonEvent *)(xevent);
|
||||
*core_x = xie->x;
|
||||
*core_y = xie->y;
|
||||
return GDK_BUTTON_PRESS;
|
||||
}
|
||||
|
||||
if (xevent->type == gdkdev->buttonrelease_type)
|
||||
{
|
||||
XDeviceButtonEvent *xie = (XDeviceButtonEvent *)(xevent);
|
||||
*core_x = xie->x;
|
||||
*core_y = xie->y;
|
||||
return GDK_BUTTON_RELEASE;
|
||||
}
|
||||
|
||||
if (xevent->type == gdkdev->keypress_type)
|
||||
{
|
||||
XDeviceKeyEvent *xie = (XDeviceKeyEvent *)(xevent);
|
||||
*core_x = xie->x;
|
||||
*core_y = xie->y;
|
||||
return GDK_KEY_PRESS;
|
||||
}
|
||||
|
||||
if (xevent->type == gdkdev->keyrelease_type)
|
||||
{
|
||||
XDeviceKeyEvent *xie = (XDeviceKeyEvent *)(xevent);
|
||||
*core_x = xie->x;
|
||||
*core_y = xie->y;
|
||||
return GDK_KEY_RELEASE;
|
||||
}
|
||||
|
||||
if (xevent->type == gdkdev->motionnotify_type)
|
||||
{
|
||||
XDeviceMotionEvent *xie = (XDeviceMotionEvent *)(xevent);
|
||||
*core_x = xie->x;
|
||||
*core_y = xie->y;
|
||||
return GDK_MOTION_NOTIFY;
|
||||
}
|
||||
|
||||
if (xevent->type == gdkdev->proximityin_type)
|
||||
{
|
||||
XProximityNotifyEvent *xie = (XProximityNotifyEvent *)(xevent);
|
||||
*core_x = xie->x;
|
||||
*core_y = xie->y;
|
||||
return GDK_PROXIMITY_IN;
|
||||
}
|
||||
|
||||
if (xevent->type == gdkdev->proximityout_type)
|
||||
{
|
||||
XProximityNotifyEvent *xie = (XProximityNotifyEvent *)(xevent);
|
||||
*core_x = xie->x;
|
||||
*core_y = xie->y;
|
||||
return GDK_PROXIMITY_OUT;
|
||||
}
|
||||
|
||||
*core_x = 0;
|
||||
*core_y = 0;
|
||||
return GDK_NOTHING;
|
||||
}
|
||||
|
||||
|
||||
gboolean
|
||||
_gdk_input_other_event (GdkEvent *event,
|
||||
XEvent *xevent,
|
||||
GdkWindow *event_window)
|
||||
{
|
||||
GdkWindow *window;
|
||||
GdkWindowObject *priv;
|
||||
GdkInputWindow *iw;
|
||||
GdkDevicePrivate *gdkdev;
|
||||
gint return_val;
|
||||
GdkDisplayX11 *display_impl = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window));
|
||||
|
||||
input_window = _gdk_input_window_find(window);
|
||||
g_return_val_if_fail (input_window != NULL, FALSE);
|
||||
GdkEventType event_type;
|
||||
int x, y;
|
||||
GdkDisplay *display = GDK_WINDOW_DISPLAY (event_window);
|
||||
GdkDisplayX11 *display_impl = GDK_DISPLAY_X11 (display);
|
||||
|
||||
/* This is a sort of a hack, as there isn't any XDeviceAnyEvent -
|
||||
but it's potentially faster than scanning through the types of
|
||||
every device. If we were deceived, then it won't match any of
|
||||
the types for the device anyways */
|
||||
gdkdev = _gdk_input_find_device (GDK_WINDOW_DISPLAY (window),
|
||||
gdkdev = _gdk_input_find_device (display,
|
||||
((XDeviceButtonEvent *)xevent)->deviceid);
|
||||
if (!gdkdev)
|
||||
return FALSE; /* we don't handle it - not an XInput event */
|
||||
|
||||
/* FIXME: It would be nice if we could just get rid of the events
|
||||
entirely, instead of having to ignore them */
|
||||
if (gdkdev->info.mode == GDK_MODE_DISABLED ||
|
||||
(gdkdev->info.mode == GDK_MODE_WINDOW
|
||||
&& input_window->mode == GDK_EXTENSION_EVENTS_CURSOR))
|
||||
event_type = get_input_event_type (gdkdev, xevent, &x, &y);
|
||||
if (event_type == GDK_NOTHING)
|
||||
return FALSE;
|
||||
|
||||
if (!display_impl->input_ignore_core)
|
||||
gdk_input_check_proximity(GDK_WINDOW_DISPLAY (window));
|
||||
|
||||
return_val = _gdk_input_common_other_event (event, xevent,
|
||||
input_window, gdkdev);
|
||||
window = _gdk_window_get_input_window_for_event (event_window,
|
||||
event_type,
|
||||
x, y,
|
||||
xevent->xany.serial);
|
||||
/* If we're not getting any event window its likely because we're outside the
|
||||
window and there is no grab. We should still report according to the
|
||||
implicit grab though. */
|
||||
iw = ((GdkWindowObject *)event_window)->input_window;
|
||||
if (window == NULL)
|
||||
window = iw->button_down_window;
|
||||
|
||||
priv = (GdkWindowObject *)window;
|
||||
if (window == NULL)
|
||||
return FALSE;
|
||||
|
||||
if (gdkdev->info.mode == GDK_MODE_DISABLED ||
|
||||
!(gdkdev->info.has_cursor || (priv->extension_events & GDK_ALL_DEVICES_MASK)))
|
||||
return FALSE;
|
||||
|
||||
if (!display->ignore_core_events && priv->extension_events != 0)
|
||||
gdk_input_check_proximity (GDK_WINDOW_DISPLAY (window));
|
||||
|
||||
return_val = _gdk_input_common_other_event (event, xevent, window, gdkdev);
|
||||
|
||||
if (return_val && event->type == GDK_BUTTON_PRESS)
|
||||
iw->button_down_window = window;
|
||||
if (return_val && event->type == GDK_BUTTON_RELEASE)
|
||||
iw->button_down_window = NULL;
|
||||
|
||||
if (return_val && event->type == GDK_PROXIMITY_OUT &&
|
||||
display_impl->input_ignore_core)
|
||||
gdk_input_check_proximity(GDK_WINDOW_DISPLAY (window));
|
||||
display->ignore_core_events)
|
||||
gdk_input_check_proximity (GDK_WINDOW_DISPLAY (window));
|
||||
|
||||
return return_val;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gdk_input_enable_window(GdkWindow *window, GdkDevicePrivate *gdkdev)
|
||||
{
|
||||
/* FIXME: watchout, gdkdev might be core pointer, never opened */
|
||||
_gdk_input_common_select_events (window, gdkdev);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gboolean
|
||||
_gdk_input_disable_window(GdkWindow *window, GdkDevicePrivate *gdkdev)
|
||||
{
|
||||
_gdk_input_common_select_events (window, gdkdev);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
gint
|
||||
_gdk_input_grab_pointer (GdkWindow * window,
|
||||
gint
|
||||
_gdk_input_grab_pointer (GdkWindow *window,
|
||||
GdkWindow *native_window, /* This is the toplevel */
|
||||
gint owner_events,
|
||||
GdkEventMask event_mask,
|
||||
GdkWindow * confine_to,
|
||||
guint32 time)
|
||||
{
|
||||
GdkInputWindow *input_window, *new_window;
|
||||
GdkInputWindow *input_window;
|
||||
GdkWindowObject *priv, *impl_window;
|
||||
gboolean need_ungrab;
|
||||
GdkDevicePrivate *gdkdev;
|
||||
GList *tmp_list;
|
||||
@ -255,36 +311,36 @@ _gdk_input_grab_pointer (GdkWindow * window,
|
||||
GdkDisplayX11 *display_impl = GDK_DISPLAY_X11 (GDK_WINDOW_DISPLAY (window));
|
||||
|
||||
tmp_list = display_impl->input_windows;
|
||||
new_window = NULL;
|
||||
need_ungrab = FALSE;
|
||||
|
||||
while (tmp_list)
|
||||
{
|
||||
input_window = (GdkInputWindow *)tmp_list->data;
|
||||
|
||||
if (input_window->window == window)
|
||||
new_window = input_window;
|
||||
else if (input_window->grabbed)
|
||||
if (input_window->grabbed)
|
||||
{
|
||||
input_window->grabbed = FALSE;
|
||||
need_ungrab = TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if (new_window)
|
||||
priv = (GdkWindowObject *)window;
|
||||
impl_window = (GdkWindowObject *)_gdk_window_get_impl_window (window);
|
||||
input_window = impl_window->input_window;
|
||||
if (priv->extension_events)
|
||||
{
|
||||
new_window->grabbed = TRUE;
|
||||
|
||||
g_assert (input_window != NULL);
|
||||
input_window->grabbed = TRUE;
|
||||
|
||||
tmp_list = display_impl->input_devices;
|
||||
while (tmp_list)
|
||||
{
|
||||
gdkdev = (GdkDevicePrivate *)tmp_list->data;
|
||||
if (!GDK_IS_CORE (gdkdev) && gdkdev->xdevice)
|
||||
{
|
||||
_gdk_input_common_find_events (window, gdkdev,
|
||||
event_mask,
|
||||
_gdk_input_common_find_events (gdkdev, event_mask,
|
||||
event_classes, &num_classes);
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (_gdk_debug_flags & GDK_DEBUG_NOGRABS)
|
||||
@ -292,10 +348,10 @@ _gdk_input_grab_pointer (GdkWindow * window,
|
||||
else
|
||||
#endif
|
||||
result = XGrabDevice (display_impl->xdisplay, gdkdev->xdevice,
|
||||
GDK_WINDOW_XWINDOW (window),
|
||||
GDK_WINDOW_XWINDOW (native_window),
|
||||
owner_events, num_classes, event_classes,
|
||||
GrabModeAsync, GrabModeAsync, time);
|
||||
|
||||
|
||||
/* FIXME: if failure occurs on something other than the first
|
||||
device, things will be badly inconsistent */
|
||||
if (result != Success)
|
||||
@ -305,7 +361,7 @@ _gdk_input_grab_pointer (GdkWindow * window,
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
{
|
||||
tmp_list = display_impl->input_devices;
|
||||
while (tmp_list)
|
||||
{
|
||||
@ -316,17 +372,16 @@ _gdk_input_grab_pointer (GdkWindow * window,
|
||||
XUngrabDevice (display_impl->xdisplay, gdkdev->xdevice, time);
|
||||
gdkdev->button_state = 0;
|
||||
}
|
||||
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
}
|
||||
|
||||
return Success;
|
||||
|
||||
}
|
||||
|
||||
void
|
||||
_gdk_input_ungrab_pointer (GdkDisplay *display,
|
||||
void
|
||||
_gdk_input_ungrab_pointer (GdkDisplay *display,
|
||||
guint32 time)
|
||||
{
|
||||
GdkInputWindow *input_window = NULL; /* Quiet GCC */
|
||||
|
||||
Reference in New Issue
Block a user