2010-05-25 22:38:44 +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
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2010-05-25 22:38:44 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <gdk/gdktypes.h>
|
|
|
|
#include <gdk/gdkdevicemanager.h>
|
2010-12-23 11:59:26 +00:00
|
|
|
#include <gdk/gdkdeviceprivate.h>
|
2015-12-14 14:44:15 +00:00
|
|
|
#include <gdk/gdkseatdefaultprivate.h>
|
2010-12-23 11:59:26 +00:00
|
|
|
#include <gdk/gdkdevicemanagerprivate.h>
|
2018-12-03 12:24:03 +00:00
|
|
|
#include <gdk/gdkdisplayprivate.h>
|
2010-12-22 16:30:29 +00:00
|
|
|
#include "gdkdevicemanager-core-quartz.h"
|
2010-12-23 11:59:26 +00:00
|
|
|
#include "gdkquartzdevice-core.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
#include "gdkkeysyms.h"
|
2015-12-14 14:44:15 +00:00
|
|
|
#include "gdkprivate-quartz.h"
|
2019-01-27 19:16:33 +00:00
|
|
|
#include "gdkinternal-quartz.h"
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2019-01-27 19:16:33 +00:00
|
|
|
typedef enum
|
|
|
|
{
|
|
|
|
#if MAC_OS_X_VERSION_MIN_REQUIRED < 101200
|
|
|
|
GDK_QUARTZ_POINTER_DEVICE_TYPE_CURSOR = NSCursorPointingDevice,
|
|
|
|
GDK_QUARTZ_POINTER_DEVICE_TYPE_ERASER = NSEraserPointingDevice,
|
|
|
|
GDK_QUARTZ_POINTER_DEVICE_TYPE_PEN = NSPenPointingDevice,
|
|
|
|
#else
|
|
|
|
GDK_QUARTZ_POINTER_DEVICE_TYPE_CURSOR = NSPointingDeviceTypeCursor,
|
|
|
|
GDK_QUARTZ_POINTER_DEVICE_TYPE_ERASER = NSPointingDeviceTypeEraser,
|
|
|
|
GDK_QUARTZ_POINTER_DEVICE_TYPE_PEN = NSPointingDeviceTypePen,
|
|
|
|
#endif
|
|
|
|
} GdkQuartzPointerDeviceType;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
#define HAS_FOCUS(toplevel) \
|
|
|
|
((toplevel)->has_focus || (toplevel)->has_pointer_focus)
|
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
static void gdk_quartz_device_manager_core_finalize (GObject *object);
|
|
|
|
static void gdk_quartz_device_manager_core_constructed (GObject *object);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
static GList * gdk_quartz_device_manager_core_list_devices (GdkDeviceManager *device_manager,
|
|
|
|
GdkDeviceType type);
|
|
|
|
static GdkDevice * gdk_quartz_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
G_DEFINE_TYPE (GdkQuartzDeviceManagerCore, gdk_quartz_device_manager_core, GDK_TYPE_DEVICE_MANAGER)
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
static void
|
2010-12-22 16:30:29 +00:00
|
|
|
gdk_quartz_device_manager_core_class_init (GdkQuartzDeviceManagerCoreClass *klass)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
|
|
|
GdkDeviceManagerClass *device_manager_class = GDK_DEVICE_MANAGER_CLASS (klass);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
object_class->finalize = gdk_quartz_device_manager_core_finalize;
|
|
|
|
object_class->constructed = gdk_quartz_device_manager_core_constructed;
|
|
|
|
device_manager_class->list_devices = gdk_quartz_device_manager_core_list_devices;
|
|
|
|
device_manager_class->get_client_pointer = gdk_quartz_device_manager_core_get_client_pointer;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GdkDevice *
|
|
|
|
create_core_pointer (GdkDeviceManager *device_manager,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
2010-12-22 16:25:46 +00:00
|
|
|
return g_object_new (GDK_TYPE_QUARTZ_DEVICE_CORE,
|
2010-05-25 22:38:44 +00:00
|
|
|
"name", "Core Pointer",
|
|
|
|
"type", GDK_DEVICE_TYPE_MASTER,
|
|
|
|
"input-source", GDK_SOURCE_MOUSE,
|
|
|
|
"input-mode", GDK_MODE_SCREEN,
|
|
|
|
"has-cursor", TRUE,
|
|
|
|
"display", display,
|
|
|
|
"device-manager", device_manager,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static GdkDevice *
|
|
|
|
create_core_keyboard (GdkDeviceManager *device_manager,
|
|
|
|
GdkDisplay *display)
|
|
|
|
{
|
2010-12-22 16:25:46 +00:00
|
|
|
return g_object_new (GDK_TYPE_QUARTZ_DEVICE_CORE,
|
2010-05-25 22:38:44 +00:00
|
|
|
"name", "Core Keyboard",
|
|
|
|
"type", GDK_DEVICE_TYPE_MASTER,
|
|
|
|
"input-source", GDK_SOURCE_KEYBOARD,
|
|
|
|
"input-mode", GDK_MODE_SCREEN,
|
|
|
|
"has-cursor", FALSE,
|
|
|
|
"display", display,
|
|
|
|
"device-manager", device_manager,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-22 16:30:29 +00:00
|
|
|
gdk_quartz_device_manager_core_init (GdkQuartzDeviceManagerCore *device_manager)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2019-01-27 19:16:33 +00:00
|
|
|
device_manager->known_tablet_devices = NULL;
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-22 16:30:29 +00:00
|
|
|
gdk_quartz_device_manager_core_finalize (GObject *object)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-22 16:30:29 +00:00
|
|
|
GdkQuartzDeviceManagerCore *quartz_device_manager_core;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
quartz_device_manager_core = GDK_QUARTZ_DEVICE_MANAGER_CORE (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
g_object_unref (quartz_device_manager_core->core_pointer);
|
|
|
|
g_object_unref (quartz_device_manager_core->core_keyboard);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2019-01-27 19:16:33 +00:00
|
|
|
g_list_free_full (quartz_device_manager_core->known_tablet_devices, g_object_unref);
|
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
G_OBJECT_CLASS (gdk_quartz_device_manager_core_parent_class)->finalize (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2010-12-22 16:30:29 +00:00
|
|
|
gdk_quartz_device_manager_core_constructed (GObject *object)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2010-12-22 16:30:29 +00:00
|
|
|
GdkQuartzDeviceManagerCore *device_manager;
|
2010-05-25 22:38:44 +00:00
|
|
|
GdkDisplay *display;
|
2015-12-14 14:44:15 +00:00
|
|
|
GdkSeat *seat;
|
2010-05-25 22:38:44 +00:00
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
device_manager = GDK_QUARTZ_DEVICE_MANAGER_CORE (object);
|
2010-05-25 22:38:44 +00:00
|
|
|
display = gdk_device_manager_get_display (GDK_DEVICE_MANAGER (object));
|
|
|
|
device_manager->core_pointer = create_core_pointer (GDK_DEVICE_MANAGER (device_manager), display);
|
|
|
|
device_manager->core_keyboard = create_core_keyboard (GDK_DEVICE_MANAGER (device_manager), display);
|
|
|
|
|
|
|
|
_gdk_device_set_associated_device (device_manager->core_pointer, device_manager->core_keyboard);
|
|
|
|
_gdk_device_set_associated_device (device_manager->core_keyboard, device_manager->core_pointer);
|
2015-12-14 14:44:15 +00:00
|
|
|
|
|
|
|
seat = gdk_seat_default_new_for_master_pair (device_manager->core_pointer,
|
|
|
|
device_manager->core_keyboard);
|
|
|
|
gdk_display_add_seat (display, seat);
|
|
|
|
g_object_unref (seat);
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static GList *
|
2010-12-22 16:30:29 +00:00
|
|
|
gdk_quartz_device_manager_core_list_devices (GdkDeviceManager *device_manager,
|
|
|
|
GdkDeviceType type)
|
2010-05-25 22:38:44 +00:00
|
|
|
{
|
2019-01-27 19:16:33 +00:00
|
|
|
GdkQuartzDeviceManagerCore *self;
|
2010-05-25 22:38:44 +00:00
|
|
|
GList *devices = NULL;
|
2019-01-27 19:16:33 +00:00
|
|
|
GList *l;
|
|
|
|
|
|
|
|
self = GDK_QUARTZ_DEVICE_MANAGER_CORE (device_manager);
|
2010-05-25 22:38:44 +00:00
|
|
|
|
|
|
|
if (type == GDK_DEVICE_TYPE_MASTER)
|
|
|
|
{
|
2019-01-27 19:16:33 +00:00
|
|
|
devices = g_list_prepend (devices, self->core_keyboard);
|
|
|
|
devices = g_list_prepend (devices, self->core_pointer);
|
|
|
|
}
|
|
|
|
|
|
|
|
for (l = self->known_tablet_devices; l; l = g_list_next (l))
|
|
|
|
{
|
|
|
|
devices = g_list_prepend (devices, GDK_DEVICE (l->data));
|
2010-05-25 22:38:44 +00:00
|
|
|
}
|
|
|
|
|
2019-01-27 19:16:33 +00:00
|
|
|
devices = g_list_reverse (devices);
|
|
|
|
|
2010-05-25 22:38:44 +00:00
|
|
|
return devices;
|
|
|
|
}
|
2010-06-08 13:16:59 +00:00
|
|
|
|
|
|
|
static GdkDevice *
|
2010-12-22 16:30:29 +00:00
|
|
|
gdk_quartz_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager)
|
2010-06-08 13:16:59 +00:00
|
|
|
{
|
2010-12-22 16:30:29 +00:00
|
|
|
GdkQuartzDeviceManagerCore *quartz_device_manager_core;
|
2010-06-08 13:16:59 +00:00
|
|
|
|
2010-12-22 16:30:29 +00:00
|
|
|
quartz_device_manager_core = (GdkQuartzDeviceManagerCore *) device_manager;
|
|
|
|
return quartz_device_manager_core->core_pointer;
|
2010-06-08 13:16:59 +00:00
|
|
|
}
|
2019-01-27 19:16:33 +00:00
|
|
|
|
|
|
|
static GdkDevice *
|
|
|
|
create_core_device (GdkDeviceManager *device_manager,
|
|
|
|
const gchar *device_name,
|
|
|
|
GdkInputSource source)
|
|
|
|
{
|
|
|
|
GdkDisplay *display = gdk_device_manager_get_display (device_manager);
|
|
|
|
GdkDevice *device = g_object_new (GDK_TYPE_QUARTZ_DEVICE_CORE,
|
|
|
|
"name", device_name,
|
|
|
|
"type", GDK_DEVICE_TYPE_SLAVE,
|
|
|
|
"input-source", source,
|
|
|
|
"input-mode", GDK_MODE_DISABLED,
|
|
|
|
"has-cursor", FALSE,
|
|
|
|
"display", display,
|
|
|
|
"device-manager", device_manager,
|
|
|
|
NULL);
|
|
|
|
|
|
|
|
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_PRESSURE, 0.0, 1.0, 0.001);
|
|
|
|
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_XTILT, -1.0, 1.0, 0.001);
|
|
|
|
_gdk_device_add_axis (device, GDK_NONE, GDK_AXIS_YTILT, -1.0, 1.0, 0.001);
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_gdk_quartz_device_manager_register_device_for_ns_event (GdkDeviceManager *device_manager,
|
|
|
|
NSEvent *nsevent)
|
|
|
|
{
|
|
|
|
GdkQuartzDeviceManagerCore *self = GDK_QUARTZ_DEVICE_MANAGER_CORE (device_manager);
|
|
|
|
GList *l = NULL;
|
|
|
|
GdkInputSource input_source = GDK_SOURCE_MOUSE;
|
|
|
|
GdkDevice *device = NULL;
|
|
|
|
|
|
|
|
/* Only handle device updates for proximity events */
|
|
|
|
if ([nsevent type] != GDK_QUARTZ_EVENT_TABLET_PROXIMITY &&
|
|
|
|
[nsevent subtype] != GDK_QUARTZ_EVENT_SUBTYPE_TABLET_PROXIMITY)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if ([nsevent pointingDeviceType] == GDK_QUARTZ_POINTER_DEVICE_TYPE_PEN)
|
|
|
|
input_source = GDK_SOURCE_PEN;
|
|
|
|
else if ([nsevent pointingDeviceType] == GDK_QUARTZ_POINTER_DEVICE_TYPE_CURSOR)
|
|
|
|
input_source = GDK_SOURCE_CURSOR;
|
|
|
|
else if ([nsevent pointingDeviceType] == GDK_QUARTZ_POINTER_DEVICE_TYPE_ERASER)
|
|
|
|
input_source = GDK_SOURCE_ERASER;
|
|
|
|
|
|
|
|
for (l = self->known_tablet_devices; l; l = g_list_next (l))
|
|
|
|
{
|
|
|
|
GdkDevice *device_to_check = GDK_DEVICE (l->data);
|
|
|
|
|
|
|
|
if (input_source == gdk_device_get_source (device_to_check) &&
|
|
|
|
[nsevent uniqueID] == _gdk_quartz_device_core_get_unique (device_to_check))
|
|
|
|
{
|
|
|
|
device = device_to_check;
|
|
|
|
if ([nsevent isEnteringProximity])
|
|
|
|
{
|
|
|
|
if (!_gdk_quartz_device_core_is_active (device, [nsevent deviceID]))
|
|
|
|
self->num_active_devices++;
|
|
|
|
|
|
|
|
_gdk_quartz_device_core_set_active (device, TRUE, [nsevent deviceID]);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (_gdk_quartz_device_core_is_active (device, [nsevent deviceID]))
|
|
|
|
self->num_active_devices--;
|
|
|
|
|
|
|
|
_gdk_quartz_device_core_set_active (device, FALSE, [nsevent deviceID]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we haven't seen this device before, add it */
|
|
|
|
if (!device)
|
|
|
|
{
|
|
|
|
GdkSeat *seat;
|
|
|
|
|
|
|
|
switch (input_source)
|
|
|
|
{
|
|
|
|
case GDK_SOURCE_PEN:
|
|
|
|
device = create_core_device (device_manager,
|
|
|
|
"Quartz Pen",
|
|
|
|
GDK_SOURCE_PEN);
|
|
|
|
break;
|
|
|
|
case GDK_SOURCE_CURSOR:
|
|
|
|
device = create_core_device (device_manager,
|
|
|
|
"Quartz Cursor",
|
|
|
|
GDK_SOURCE_CURSOR);
|
|
|
|
break;
|
|
|
|
case GDK_SOURCE_ERASER:
|
|
|
|
device = create_core_device (device_manager,
|
|
|
|
"Quartz Eraser",
|
|
|
|
GDK_SOURCE_ERASER);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_warning ("GDK Quarz unknown input source: %i", input_source);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
_gdk_device_set_associated_device (GDK_DEVICE (device), self->core_pointer);
|
|
|
|
_gdk_device_add_slave (self->core_pointer, GDK_DEVICE (device));
|
|
|
|
|
|
|
|
seat = gdk_device_get_seat (self->core_pointer);
|
|
|
|
gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), device);
|
|
|
|
|
|
|
|
_gdk_quartz_device_core_set_unique (device, [nsevent uniqueID]);
|
|
|
|
_gdk_quartz_device_core_set_active (device, TRUE, [nsevent deviceID]);
|
|
|
|
|
|
|
|
self->known_tablet_devices = g_list_append (self->known_tablet_devices,
|
|
|
|
device);
|
|
|
|
|
|
|
|
if ([nsevent isEnteringProximity])
|
|
|
|
{
|
|
|
|
if (!_gdk_quartz_device_core_is_active (device, [nsevent deviceID]))
|
|
|
|
self->num_active_devices++;
|
|
|
|
_gdk_quartz_device_core_set_active (device, TRUE, [nsevent deviceID]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self->num_active_devices)
|
|
|
|
[NSEvent setMouseCoalescingEnabled: FALSE];
|
|
|
|
else
|
|
|
|
[NSEvent setMouseCoalescingEnabled: TRUE];
|
|
|
|
}
|
|
|
|
|
|
|
|
GdkDevice *
|
|
|
|
_gdk_quartz_device_manager_core_device_for_ns_event (GdkDeviceManager *device_manager,
|
|
|
|
NSEvent *nsevent)
|
|
|
|
{
|
|
|
|
GdkQuartzDeviceManagerCore *self = GDK_QUARTZ_DEVICE_MANAGER_CORE (device_manager);
|
|
|
|
GdkDevice *device = NULL;
|
|
|
|
|
|
|
|
if ([nsevent type] == GDK_QUARTZ_EVENT_TABLET_PROXIMITY ||
|
|
|
|
[nsevent subtype] == GDK_QUARTZ_EVENT_SUBTYPE_TABLET_PROXIMITY ||
|
|
|
|
[nsevent subtype] == GDK_QUARTZ_EVENT_SUBTYPE_TABLET_POINT)
|
|
|
|
{
|
|
|
|
/* Find the device based on deviceID */
|
|
|
|
GList *l = NULL;
|
|
|
|
|
|
|
|
for (l = self->known_tablet_devices; l && !device; l = g_list_next (l))
|
|
|
|
{
|
|
|
|
GdkDevice *device_to_check = GDK_DEVICE (l->data);
|
|
|
|
|
|
|
|
if (_gdk_quartz_device_core_is_active (device_to_check, [nsevent deviceID]))
|
|
|
|
device = device_to_check;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!device)
|
|
|
|
device = self->core_pointer;
|
|
|
|
|
|
|
|
return device;
|
|
|
|
}
|