gdkdevicemanager-broadway.c 6.15 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 22 23 24 25 26 27 28 29 30
 */

#include "config.h"

#include "gdkdevicemanager-broadway.h"

#include "gdktypes.h"
#include "gdkdevicemanager.h"
#include "gdkdevice-broadway.h"
#include "gdkkeysyms.h"
#include "gdkprivate-broadway.h"

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

31 32
static void    gdk_broadway_device_manager_finalize    (GObject *object);
static void    gdk_broadway_device_manager_constructed (GObject *object);
33

34 35 36
static GList * gdk_broadway_device_manager_list_devices (GdkDeviceManager *device_manager,
							 GdkDeviceType     type);
static GdkDevice * gdk_broadway_device_manager_get_client_pointer (GdkDeviceManager *device_manager);
37

38
G_DEFINE_TYPE (GdkBroadwayDeviceManager, gdk_broadway_device_manager, GDK_TYPE_DEVICE_MANAGER)
39 40

static void
41
gdk_broadway_device_manager_class_init (GdkBroadwayDeviceManagerClass *klass)
42 43 44 45
{
  GdkDeviceManagerClass *device_manager_class = GDK_DEVICE_MANAGER_CLASS (klass);
  GObjectClass *object_class = G_OBJECT_CLASS (klass);

46 47 48 49
  object_class->finalize = gdk_broadway_device_manager_finalize;
  object_class->constructed = gdk_broadway_device_manager_constructed;
  device_manager_class->list_devices = gdk_broadway_device_manager_list_devices;
  device_manager_class->get_client_pointer = gdk_broadway_device_manager_get_client_pointer;
50 51 52 53 54 55
}

static GdkDevice *
create_core_pointer (GdkDeviceManager *device_manager,
                     GdkDisplay       *display)
{
56
  return g_object_new (GDK_TYPE_BROADWAY_DEVICE,
57 58 59 60 61 62 63 64 65 66 67 68 69 70
                       "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)
{
71
  return g_object_new (GDK_TYPE_BROADWAY_DEVICE,
72 73 74 75 76 77 78 79 80 81
                       "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);
}

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96
static GdkDevice *
create_touchscreen (GdkDeviceManager *device_manager,
                    GdkDisplay       *display)
{
  return g_object_new (GDK_TYPE_BROADWAY_DEVICE,
                       "name", "Touchscreen",
                       "type", GDK_DEVICE_TYPE_SLAVE,
                       "input-source", GDK_SOURCE_TOUCHSCREEN,
                       "input-mode", GDK_MODE_SCREEN,
                       "has-cursor", FALSE,
                       "display", display,
                       "device-manager", device_manager,
                       NULL);
}

97
static void
98
gdk_broadway_device_manager_init (GdkBroadwayDeviceManager *device_manager)
99 100 101 102
{
}

static void
103
gdk_broadway_device_manager_finalize (GObject *object)
104
{
105
  GdkBroadwayDeviceManager *device_manager;
106

107
  device_manager = GDK_BROADWAY_DEVICE_MANAGER (object);
108

109 110
  g_object_unref (device_manager->core_pointer);
  g_object_unref (device_manager->core_keyboard);
111
  g_object_unref (device_manager->touchscreen);
112

113
  G_OBJECT_CLASS (gdk_broadway_device_manager_parent_class)->finalize (object);
114 115 116
}

static void
117
gdk_broadway_device_manager_constructed (GObject *object)
118
{
119
  GdkBroadwayDeviceManager *device_manager;
120 121
  GdkDisplay *display;

122
  device_manager = GDK_BROADWAY_DEVICE_MANAGER (object);
123 124 125
  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);
126
  device_manager->touchscreen = create_touchscreen (GDK_DEVICE_MANAGER (device_manager), display);
127 128 129

  _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);
130 131
  _gdk_device_set_associated_device (device_manager->touchscreen, device_manager->core_pointer);
  _gdk_device_add_slave (device_manager->core_pointer, device_manager->touchscreen);
132 133 134 135
}


static GList *
136 137
gdk_broadway_device_manager_list_devices (GdkDeviceManager *device_manager,
					  GdkDeviceType     type)
138
{
139
  GdkBroadwayDeviceManager *broadway_device_manager = (GdkBroadwayDeviceManager *) device_manager;
140 141 142 143
  GList *devices = NULL;

  if (type == GDK_DEVICE_TYPE_MASTER)
    {
144 145
      devices = g_list_prepend (devices, broadway_device_manager->core_keyboard);
      devices = g_list_prepend (devices, broadway_device_manager->core_pointer);
146 147
    }

148 149 150 151 152
  if (type == GDK_DEVICE_TYPE_SLAVE)
    {
      devices = g_list_prepend (devices, broadway_device_manager->touchscreen);
    }

153 154 155 156
  return devices;
}

static GdkDevice *
157
gdk_broadway_device_manager_get_client_pointer (GdkDeviceManager *device_manager)
158
{
159
  GdkBroadwayDeviceManager *broadway_device_manager = (GdkBroadwayDeviceManager *) device_manager;
160

161
  return broadway_device_manager->core_pointer;
162 163 164
}

GdkDeviceManager *
165
_gdk_broadway_device_manager_new (GdkDisplay *display)
166
{
167
  return g_object_new (GDK_TYPE_BROADWAY_DEVICE_MANAGER,
168 169 170
		       "display", display,
		       NULL);
}