2010-11-12 12:18:58 +00:00
|
|
|
/* GDK - The GIMP Drawing Kit
|
|
|
|
* Copyright (C) 2009 Carlos Garnacho <carlosg@gnome.org>
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the
|
|
|
|
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
* Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gdkeventsource.h"
|
|
|
|
|
|
|
|
#include "gdkinternals.h"
|
|
|
|
|
2010-11-25 11:33:07 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
|
2010-11-12 12:18:58 +00:00
|
|
|
static gboolean gdk_event_source_prepare (GSource *source,
|
|
|
|
gint *timeout);
|
|
|
|
static gboolean gdk_event_source_check (GSource *source);
|
|
|
|
static gboolean gdk_event_source_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data);
|
|
|
|
static void gdk_event_source_finalize (GSource *source);
|
|
|
|
|
|
|
|
#define HAS_FOCUS(toplevel) \
|
|
|
|
((toplevel)->has_focus || (toplevel)->has_pointer_focus)
|
|
|
|
|
|
|
|
struct _GdkEventSource
|
|
|
|
{
|
|
|
|
GSource source;
|
|
|
|
|
|
|
|
GdkDisplay *display;
|
|
|
|
GPollFD event_poll_fd;
|
|
|
|
};
|
|
|
|
|
|
|
|
static GSourceFuncs event_funcs = {
|
|
|
|
gdk_event_source_prepare,
|
|
|
|
gdk_event_source_check,
|
|
|
|
gdk_event_source_dispatch,
|
|
|
|
gdk_event_source_finalize
|
|
|
|
};
|
|
|
|
|
|
|
|
static GList *event_sources = NULL;
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_event_source_prepare (GSource *source,
|
|
|
|
gint *timeout)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = ((GdkEventSource*) source)->display;
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
GDK_THREADS_ENTER ();
|
|
|
|
|
|
|
|
*timeout = -1;
|
2010-11-15 19:08:18 +00:00
|
|
|
retval = (_gdk_event_queue_find_first (display) != NULL);
|
2010-11-12 12:18:58 +00:00
|
|
|
|
|
|
|
GDK_THREADS_LEAVE ();
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_event_source_check (GSource *source)
|
|
|
|
{
|
|
|
|
GdkEventSource *event_source = (GdkEventSource*) source;
|
|
|
|
gboolean retval;
|
|
|
|
|
|
|
|
GDK_THREADS_ENTER ();
|
|
|
|
|
|
|
|
if (event_source->event_poll_fd.revents & G_IO_IN)
|
2010-11-15 19:08:18 +00:00
|
|
|
retval = (_gdk_event_queue_find_first (event_source->display) != NULL);
|
2010-11-12 12:18:58 +00:00
|
|
|
else
|
|
|
|
retval = FALSE;
|
|
|
|
|
|
|
|
GDK_THREADS_LEAVE ();
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2011-03-11 20:10:23 +00:00
|
|
|
typedef struct {
|
|
|
|
int id;
|
|
|
|
int root_x;
|
|
|
|
int root_y;
|
|
|
|
int win_x;
|
|
|
|
int win_y;
|
2011-03-14 11:09:19 +00:00
|
|
|
guint32 state;
|
2011-03-11 20:10:23 +00:00
|
|
|
guint64 time;
|
|
|
|
} PointerData;
|
|
|
|
|
|
|
|
static char *
|
|
|
|
parse_pointer_data (char *p, PointerData *data)
|
|
|
|
{
|
|
|
|
data->id = strtol (p, &p, 10);
|
|
|
|
p++; /* Skip , */
|
|
|
|
data->root_x = strtol (p, &p, 10);
|
|
|
|
p++; /* Skip , */
|
|
|
|
data->root_y = strtol (p, &p, 10);
|
|
|
|
p++; /* Skip , */
|
|
|
|
data->win_x = strtol (p, &p, 10);
|
|
|
|
p++; /* Skip , */
|
|
|
|
data->win_y = strtol (p, &p, 10);
|
|
|
|
p++; /* Skip , */
|
2011-03-14 11:09:19 +00:00
|
|
|
data->state = strtol (p, &p, 10);
|
|
|
|
p++; /* Skip , */
|
2011-03-11 20:10:23 +00:00
|
|
|
data->time = strtol(p, &p, 10);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-11-25 11:33:07 +00:00
|
|
|
void
|
2011-01-06 22:36:44 +00:00
|
|
|
_gdk_broadway_events_got_input (GdkDisplay *display,
|
|
|
|
const char *message)
|
2010-11-25 11:33:07 +00:00
|
|
|
{
|
2011-01-06 22:36:44 +00:00
|
|
|
GdkBroadwayDisplay *display_broadway = GDK_BROADWAY_DISPLAY (display);
|
2010-11-25 11:33:07 +00:00
|
|
|
GdkScreen *screen;
|
|
|
|
GdkWindow *root, *window;
|
|
|
|
char *p;
|
2011-03-14 11:13:21 +00:00
|
|
|
int button, dir, key, mode;
|
2011-03-10 13:58:47 +00:00
|
|
|
guint32 serial;
|
2010-11-25 11:33:07 +00:00
|
|
|
guint64 time;
|
|
|
|
GdkEvent *event = NULL;
|
|
|
|
char cmd;
|
|
|
|
GList *node;
|
2011-03-11 20:10:23 +00:00
|
|
|
PointerData data;
|
2010-11-25 11:33:07 +00:00
|
|
|
|
|
|
|
screen = gdk_display_get_default_screen (display);
|
|
|
|
root = gdk_screen_get_root_window (screen);
|
|
|
|
|
|
|
|
p = (char *)message;
|
|
|
|
cmd = *p++;
|
2011-03-11 20:10:23 +00:00
|
|
|
serial = (guint32)strtol (p, &p, 10);
|
2011-03-10 13:58:47 +00:00
|
|
|
p++; /* Skip , */
|
2010-11-25 11:33:07 +00:00
|
|
|
switch (cmd) {
|
2011-03-11 20:10:23 +00:00
|
|
|
case 'e': /* Enter */
|
|
|
|
p = parse_pointer_data (p, &data);
|
2011-03-14 10:46:43 +00:00
|
|
|
p++; /* Skip , */
|
2011-03-14 11:13:21 +00:00
|
|
|
mode = strtol(p, &p, 10);
|
2011-03-11 20:10:23 +00:00
|
|
|
|
|
|
|
display_broadway->last_x = data.root_x;
|
|
|
|
display_broadway->last_y = data.root_y;
|
2010-11-25 11:33:07 +00:00
|
|
|
|
2011-03-11 20:10:23 +00:00
|
|
|
window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
|
2010-11-25 11:33:07 +00:00
|
|
|
|
2011-03-11 20:10:23 +00:00
|
|
|
/* TODO: Unset when it dies */
|
|
|
|
display_broadway->mouse_in_toplevel = window;
|
|
|
|
|
|
|
|
if (window)
|
2010-11-25 11:33:07 +00:00
|
|
|
{
|
2011-03-11 20:10:23 +00:00
|
|
|
event = gdk_event_new (GDK_ENTER_NOTIFY);
|
|
|
|
event->crossing.window = g_object_ref (window);
|
|
|
|
event->crossing.time = data.time;
|
|
|
|
event->crossing.x = data.win_x;
|
|
|
|
event->crossing.y = data.win_y;
|
|
|
|
event->crossing.x_root = data.root_x;
|
|
|
|
event->crossing.y_root = data.root_y;
|
2011-03-14 11:09:19 +00:00
|
|
|
event->crossing.state = data.state;
|
2011-03-14 11:13:21 +00:00
|
|
|
event->crossing.mode = mode;
|
2011-03-11 20:10:23 +00:00
|
|
|
event->crossing.detail = GDK_NOTIFY_ANCESTOR;
|
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
|
|
|
|
|
|
|
event = gdk_event_new (GDK_FOCUS_CHANGE);
|
|
|
|
event->focus_change.window = g_object_ref (window);
|
|
|
|
event->focus_change.in = TRUE;
|
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
2010-11-25 11:33:07 +00:00
|
|
|
}
|
2011-03-11 20:10:23 +00:00
|
|
|
break;
|
|
|
|
case 'l': /* Leave */
|
|
|
|
p = parse_pointer_data (p, &data);
|
2011-03-14 10:46:43 +00:00
|
|
|
p++; /* Skip , */
|
2011-03-14 11:13:21 +00:00
|
|
|
mode = strtol(p, &p, 10);
|
2011-03-11 20:10:23 +00:00
|
|
|
|
|
|
|
display_broadway->last_x = data.root_x;
|
|
|
|
display_broadway->last_y = data.root_y;
|
|
|
|
|
|
|
|
window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
|
|
|
|
|
|
|
|
display_broadway->mouse_in_toplevel = NULL;
|
|
|
|
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
event = gdk_event_new (GDK_LEAVE_NOTIFY);
|
|
|
|
event->crossing.window = g_object_ref (window);
|
|
|
|
event->crossing.time = data.time;
|
|
|
|
event->crossing.x = data.win_x;
|
|
|
|
event->crossing.y = data.win_y;
|
|
|
|
event->crossing.x_root = data.root_x;
|
|
|
|
event->crossing.y_root = data.root_y;
|
2011-03-14 11:09:19 +00:00
|
|
|
event->crossing.state = data.state;
|
2011-03-14 11:13:21 +00:00
|
|
|
event->crossing.mode = mode;
|
|
|
|
event->crossing.detail = GDK_NOTIFY_ANCESTOR;
|
2011-03-11 20:10:23 +00:00
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
|
|
|
|
|
|
|
event = gdk_event_new (GDK_FOCUS_CHANGE);
|
|
|
|
event->focus_change.window = g_object_ref (window);
|
|
|
|
event->focus_change.in = FALSE;
|
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case 'm': /* Mouse move */
|
|
|
|
p = parse_pointer_data (p, &data);
|
|
|
|
|
|
|
|
display_broadway->last_x = data.root_x;
|
|
|
|
display_broadway->last_y = data.root_y;
|
|
|
|
|
|
|
|
window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
|
2010-11-25 11:33:07 +00:00
|
|
|
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
event = gdk_event_new (GDK_MOTION_NOTIFY);
|
|
|
|
event->motion.window = g_object_ref (window);
|
2011-03-11 20:10:23 +00:00
|
|
|
event->motion.time = data.time;
|
|
|
|
event->motion.x = data.win_x;
|
|
|
|
event->motion.y = data.win_y;
|
|
|
|
event->motion.x_root = data.root_x;
|
|
|
|
event->motion.y_root = data.root_y;
|
2011-03-14 11:09:19 +00:00
|
|
|
event->motion.state = data.state;
|
2010-11-25 11:33:07 +00:00
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
2011-03-10 13:58:47 +00:00
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
2010-11-25 11:33:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'b':
|
|
|
|
case 'B':
|
2011-03-11 20:10:23 +00:00
|
|
|
p = parse_pointer_data (p, &data);
|
2010-11-25 11:33:07 +00:00
|
|
|
p++; /* Skip , */
|
|
|
|
button = strtol(p, &p, 10);
|
2011-03-11 20:10:23 +00:00
|
|
|
display_broadway->last_x = data.root_x;
|
|
|
|
display_broadway->last_y = data.root_y;
|
2010-11-25 11:33:07 +00:00
|
|
|
|
2011-03-11 20:10:23 +00:00
|
|
|
window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
|
2010-11-25 11:33:07 +00:00
|
|
|
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
event = gdk_event_new (cmd == 'b' ? GDK_BUTTON_PRESS : GDK_BUTTON_RELEASE);
|
|
|
|
event->button.window = g_object_ref (window);
|
2011-03-11 20:10:23 +00:00
|
|
|
event->button.time = data.time;
|
|
|
|
event->button.x = data.win_x;
|
|
|
|
event->button.y = data.win_y;
|
|
|
|
event->button.x_root = data.root_x;
|
|
|
|
event->button.y_root = data.root_y;
|
2011-03-14 14:24:25 +00:00
|
|
|
event->button.button = button;
|
2011-03-14 11:09:19 +00:00
|
|
|
event->button.state = data.state;
|
2010-11-25 11:33:07 +00:00
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
2011-03-10 13:58:47 +00:00
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
2010-11-25 11:33:07 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 20:57:31 +00:00
|
|
|
break;
|
|
|
|
case 's':
|
2011-03-11 20:10:23 +00:00
|
|
|
p = parse_pointer_data (p, &data);
|
2010-11-25 20:57:31 +00:00
|
|
|
p++; /* Skip , */
|
|
|
|
dir = strtol(p, &p, 10);
|
2011-03-11 20:10:23 +00:00
|
|
|
display_broadway->last_x = data.root_x;
|
|
|
|
display_broadway->last_y = data.root_y;
|
2010-11-25 20:57:31 +00:00
|
|
|
|
2011-03-11 20:10:23 +00:00
|
|
|
window = g_hash_table_lookup (display_broadway->id_ht, GINT_TO_POINTER (data.id));
|
2010-11-25 20:57:31 +00:00
|
|
|
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
event = gdk_event_new (GDK_SCROLL);
|
|
|
|
event->scroll.window = g_object_ref (window);
|
2011-03-11 20:10:23 +00:00
|
|
|
event->scroll.time = data.time;
|
|
|
|
event->scroll.x = data.win_x;
|
|
|
|
event->scroll.y = data.win_y;
|
|
|
|
event->scroll.x_root = data.root_x;
|
|
|
|
event->scroll.y_root = data.root_y;
|
2010-11-25 20:57:31 +00:00
|
|
|
event->scroll.direction = dir == 0 ? GDK_SCROLL_UP : GDK_SCROLL_DOWN;
|
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
2011-03-10 13:58:47 +00:00
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
2010-11-25 20:57:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
case 'k':
|
|
|
|
case 'K':
|
|
|
|
key = strtol(p, &p, 10);
|
|
|
|
p++; /* Skip , */
|
|
|
|
time = strtol(p, &p, 10);
|
|
|
|
|
|
|
|
window = display_broadway->mouse_in_toplevel;
|
|
|
|
|
|
|
|
if (window)
|
|
|
|
{
|
|
|
|
event = gdk_event_new (cmd == 'k' ? GDK_KEY_PRESS : GDK_KEY_RELEASE);
|
|
|
|
event->key.window = g_object_ref (window);
|
|
|
|
event->key.time = time;
|
|
|
|
event->key.keyval = key;
|
|
|
|
event->key.length = 0;
|
|
|
|
gdk_event_set_device (event, display->core_pointer);
|
|
|
|
|
|
|
|
node = _gdk_event_queue_append (display, event);
|
2011-03-10 13:58:47 +00:00
|
|
|
_gdk_windowing_got_event (display, node, event, serial);
|
2010-11-25 20:57:31 +00:00
|
|
|
}
|
|
|
|
|
2011-03-11 13:56:31 +00:00
|
|
|
break;
|
2011-03-14 10:46:43 +00:00
|
|
|
case 'g':
|
|
|
|
case 'u':
|
|
|
|
_gdk_display_device_grab_update (display, display->core_pointer, NULL, serial);
|
|
|
|
break;
|
2011-03-11 13:56:31 +00:00
|
|
|
case 'q':
|
|
|
|
g_printerr ("Got unexpected query pointer reply w serial %d\n", serial);
|
2010-11-25 11:33:07 +00:00
|
|
|
break;
|
|
|
|
default:
|
2011-03-11 13:56:31 +00:00
|
|
|
g_printerr ("Unknown input command %s\n", message);
|
2010-11-25 11:33:07 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-11-12 12:18:58 +00:00
|
|
|
void
|
2011-01-06 22:36:44 +00:00
|
|
|
_gdk_broadway_display_queue_events (GdkDisplay *display)
|
2010-11-12 12:18:58 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gdk_event_source_dispatch (GSource *source,
|
|
|
|
GSourceFunc callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = ((GdkEventSource*) source)->display;
|
|
|
|
GdkEvent *event;
|
|
|
|
|
|
|
|
GDK_THREADS_ENTER ();
|
|
|
|
|
|
|
|
event = gdk_display_get_event (display);
|
|
|
|
|
|
|
|
if (event)
|
|
|
|
{
|
2010-12-04 21:28:31 +00:00
|
|
|
_gdk_event_emit (event);
|
2010-11-12 12:18:58 +00:00
|
|
|
|
|
|
|
gdk_event_free (event);
|
|
|
|
}
|
|
|
|
|
|
|
|
GDK_THREADS_LEAVE ();
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gdk_event_source_finalize (GSource *source)
|
|
|
|
{
|
|
|
|
GdkEventSource *event_source = (GdkEventSource *)source;
|
|
|
|
|
2010-11-15 19:08:18 +00:00
|
|
|
event_sources = g_list_remove (event_sources, event_source);
|
2010-11-12 12:18:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GSource *
|
2011-01-06 22:36:44 +00:00
|
|
|
_gdk_broadway_event_source_new (GdkDisplay *display)
|
2010-11-12 12:18:58 +00:00
|
|
|
{
|
|
|
|
GSource *source;
|
|
|
|
GdkEventSource *event_source;
|
|
|
|
char *name;
|
|
|
|
|
|
|
|
source = g_source_new (&event_funcs, sizeof (GdkEventSource));
|
2010-11-16 11:33:02 +00:00
|
|
|
name = g_strdup_printf ("GDK Broadway Event source (%s)",
|
2010-11-12 12:18:58 +00:00
|
|
|
gdk_display_get_name (display));
|
|
|
|
g_source_set_name (source, name);
|
|
|
|
g_free (name);
|
|
|
|
event_source = (GdkEventSource *) source;
|
|
|
|
event_source->display = display;
|
|
|
|
|
|
|
|
g_source_set_priority (source, GDK_PRIORITY_EVENTS);
|
|
|
|
g_source_set_can_recurse (source, TRUE);
|
|
|
|
g_source_attach (source, NULL);
|
|
|
|
|
|
|
|
event_sources = g_list_prepend (event_sources, source);
|
|
|
|
|
|
|
|
return source;
|
|
|
|
}
|