gdkdevicemanager-core-quartz.c 5.61 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14
/* 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
Javier Jardón's avatar
Javier Jardón committed
15
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
16 17 18 19 20 21
 */

#include "config.h"

#include <gdk/gdktypes.h>
#include <gdk/gdkdevicemanager.h>
22
#include <gdk/gdkdeviceprivate.h>
23
#include <gdk/gdkseatdefaultprivate.h>
24
#include <gdk/gdkdevicemanagerprivate.h>
25
#include "gdkdevicemanager-core-quartz.h"
26
#include "gdkquartzdevice-core.h"
27
#include "gdkkeysyms.h"
28
#include "gdkprivate-quartz.h"
29 30 31 32 33


#define HAS_FOCUS(toplevel)                           \
  ((toplevel)->has_focus || (toplevel)->has_pointer_focus)

34 35
static void    gdk_quartz_device_manager_core_finalize    (GObject *object);
static void    gdk_quartz_device_manager_core_constructed (GObject *object);
36

37 38 39
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);
40 41


42
G_DEFINE_TYPE (GdkQuartzDeviceManagerCore, gdk_quartz_device_manager_core, GDK_TYPE_DEVICE_MANAGER)
43 44

static void
45
gdk_quartz_device_manager_core_class_init (GdkQuartzDeviceManagerCoreClass *klass)
46 47 48 49
{
  GdkDeviceManagerClass *device_manager_class = GDK_DEVICE_MANAGER_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

50 51 52 53
  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;
54 55 56 57 58 59
}

static GdkDevice *
create_core_pointer (GdkDeviceManager *device_manager,
                     GdkDisplay       *display)
{
60
  return g_object_new (GDK_TYPE_QUARTZ_DEVICE_CORE,
61 62 63 64 65 66 67 68 69 70 71 72 73 74
                       "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)
{
75
  return g_object_new (GDK_TYPE_QUARTZ_DEVICE_CORE,
76 77 78 79 80 81 82 83 84 85 86
                       "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
87
gdk_quartz_device_manager_core_init (GdkQuartzDeviceManagerCore *device_manager)
88 89 90 91
{
}

static void
92
gdk_quartz_device_manager_core_finalize (GObject *object)
93
{
94
  GdkQuartzDeviceManagerCore *quartz_device_manager_core;
95

96
  quartz_device_manager_core = GDK_QUARTZ_DEVICE_MANAGER_CORE (object);
97

98 99
  g_object_unref (quartz_device_manager_core->core_pointer);
  g_object_unref (quartz_device_manager_core->core_keyboard);
100

101
  G_OBJECT_CLASS (gdk_quartz_device_manager_core_parent_class)->finalize (object);
102 103 104
}

static void
105
gdk_quartz_device_manager_core_constructed (GObject *object)
106
{
107
  GdkQuartzDeviceManagerCore *device_manager;
108
  GdkDisplay *display;
109
  GdkSeat *seat;
110

111
  device_manager = GDK_QUARTZ_DEVICE_MANAGER_CORE (object);
112 113 114 115 116 117
  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);
118 119 120 121 122

  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);
123 124 125
}

static GList *
126 127
gdk_quartz_device_manager_core_list_devices (GdkDeviceManager *device_manager,
                                             GdkDeviceType     type)
128
{
129
  GdkQuartzDeviceManagerCore *quartz_device_manager_core;
130 131 132 133
  GList *devices = NULL;

  if (type == GDK_DEVICE_TYPE_MASTER)
    {
134 135 136
      quartz_device_manager_core = (GdkQuartzDeviceManagerCore *) device_manager;
      devices = g_list_prepend (devices, quartz_device_manager_core->core_keyboard);
      devices = g_list_prepend (devices, quartz_device_manager_core->core_pointer);
137 138 139 140
    }

  return devices;
}
141 142

static GdkDevice *
143
gdk_quartz_device_manager_core_get_client_pointer (GdkDeviceManager *device_manager)
144
{
145
  GdkQuartzDeviceManagerCore *quartz_device_manager_core;
146

147 148
  quartz_device_manager_core = (GdkQuartzDeviceManagerCore *) device_manager;
  return quartz_device_manager_core->core_pointer;
149
}