GitLab repository storage has been migrated to hashed layout. Please contact Infrastructure team if you notice any issues with repositories or hooks.

gdkinput.c 7.24 KB
Newer Older
Anders Carlsson's avatar
Anders Carlsson committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
/* GDK - The GIMP Drawing Kit
 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
 *
 * 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.
 */

/*
 * 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/. 
 */

27
#include "config.h"
Anders Carlsson's avatar
Anders Carlsson committed
28 29 30 31 32 33
#include <stdlib.h>

#include "gdkprivate-quartz.h"
#include "gdkinput.h"
#include "gdkprivate.h"
#include "gdkinputprivate.h"
34 35
#include <gdkdevice.h>
#include <gdkdeviceprivate.h>
Anders Carlsson's avatar
Anders Carlsson committed
36

37 38
/* Addition used for extension_events mask */
#define GDK_ALL_DEVICES_MASK (1<<30)
Anders Carlsson's avatar
Anders Carlsson committed
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62

GdkDevice *_gdk_core_pointer = NULL;

/* Global variables  */

gchar            *_gdk_input_gxid_host;
gint              _gdk_input_gxid_port;
gint              _gdk_input_ignore_core;
GList            *_gdk_input_windows;
GList            *_gdk_input_devices;


GList *
gdk_devices_list (void)
{
  return _gdk_input_devices;
}

GList *
gdk_display_list_devices (GdkDisplay *dpy)
{
  return _gdk_input_devices;
}

63 64 65
static void
_gdk_input_select_device_events (GdkWindow *impl_window,
                                 GdkDevice *device)
Matthias Clasen's avatar
Matthias Clasen committed
66
{
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
  guint event_mask;
  GdkWindowObject *w;
  GdkInputWindow *iw;
  GdkInputMode mode;
  gboolean has_cursor;
  GdkDeviceType type;
  GList *l;

  event_mask = 0;
  iw = ((GdkWindowObject *)impl_window)->input_window;

  g_object_get (device,
                "type", &type,
                "input-mode", &mode,
                "has-cursor", &has_cursor,
                NULL);

  if (iw == NULL ||
      mode == GDK_MODE_DISABLED ||
      type == GDK_DEVICE_TYPE_MASTER)
Matthias Clasen's avatar
Matthias Clasen committed
87 88
    return;

89
  for (l = _gdk_input_windows; l != NULL; l = l->next)
Anders Carlsson's avatar
Anders Carlsson committed
90
    {
91
      w = l->data;
Anders Carlsson's avatar
Anders Carlsson committed
92

93 94 95
      if (has_cursor || (w->extension_events & GDK_ALL_DEVICES_MASK))
        {
          event_mask = w->extension_events;
Anders Carlsson's avatar
Anders Carlsson committed
96

97 98 99 100
          if (event_mask)
            event_mask |= GDK_PROXIMITY_OUT_MASK
                | GDK_BUTTON_PRESS_MASK
                | GDK_BUTTON_RELEASE_MASK;
Anders Carlsson's avatar
Anders Carlsson committed
101

102 103
          gdk_window_set_device_events ((GdkWindow *) w, device, event_mask);
        }
Anders Carlsson's avatar
Anders Carlsson committed
104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
    }
}

gint
_gdk_input_enable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
{
  return TRUE;
}

gint
_gdk_input_disable_window (GdkWindow *window, GdkDevicePrivate *gdkdev)
{
  return TRUE;
}


GdkInputWindow *
_gdk_input_window_find(GdkWindow *window)
{
  GList *tmp_list;

  for (tmp_list=_gdk_input_windows; tmp_list; tmp_list=tmp_list->next)
    if (((GdkInputWindow *)(tmp_list->data))->window == window)
      return (GdkInputWindow *)(tmp_list->data);

  return NULL;      /* Not found */
}

/* FIXME: this routine currently needs to be called between creation
   and the corresponding configure event (because it doesn't get the
   root_relative_geometry).  This should work with
   gtk_window_set_extension_events, but will likely fail in other
   cases */

void
139 140 141
gdk_input_set_extension_events (GdkWindow        *window,
                                gint              mask,
                                GdkExtensionMode  mode)
Anders Carlsson's avatar
Anders Carlsson committed
142 143
{
  GdkWindowObject *window_private;
144
  GdkWindowObject *impl_window;
Anders Carlsson's avatar
Anders Carlsson committed
145 146 147 148
  GList *tmp_list;
  GdkInputWindow *iw;

  g_return_if_fail (window != NULL);
149
  g_return_if_fail (GDK_WINDOW_IS_QUARTZ (window));
Anders Carlsson's avatar
Anders Carlsson committed
150 151

  window_private = (GdkWindowObject*) window;
152
  impl_window = (GdkWindowObject *)_gdk_window_get_impl_window (window);
Anders Carlsson's avatar
Anders Carlsson committed
153 154 155 156 157 158

  if (mode == GDK_EXTENSION_EVENTS_NONE)
    mask = 0;

  if (mask != 0)
    {
159
      iw = g_new (GdkInputWindow, 1);
Anders Carlsson's avatar
Anders Carlsson committed
160 161 162 163 164 165 166 167

      iw->window = window;
      iw->mode = mode;

      iw->obscuring = NULL;
      iw->num_obscuring = 0;
      iw->grabbed = FALSE;

168
      _gdk_input_windows = g_list_append (_gdk_input_windows, iw);
Anders Carlsson's avatar
Anders Carlsson committed
169 170 171 172 173
      window_private->extension_events = mask;

      /* Add enter window events to the event mask */
      /* FIXME, this is not needed for XINPUT_NONE */
      gdk_window_set_events (window,
174 175
                             gdk_window_get_events (window) | 
                             GDK_ENTER_NOTIFY_MASK);
Anders Carlsson's avatar
Anders Carlsson committed
176 177 178 179 180
    }
  else
    {
      iw = _gdk_input_window_find (window);
      if (iw)
181 182 183 184
        {
          _gdk_input_windows = g_list_remove (_gdk_input_windows,iw);
          g_free (iw);
        }
Anders Carlsson's avatar
Anders Carlsson committed
185 186 187 188 189 190

      window_private->extension_events = 0;
    }

  for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
    {
191
      GdkDevice *dev = tmp_list->data;
Anders Carlsson's avatar
Anders Carlsson committed
192

193
      _gdk_input_select_device_events (GDK_WINDOW (impl_window), dev);
Anders Carlsson's avatar
Anders Carlsson committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
    }
}

void
_gdk_input_window_destroy (GdkWindow *window)
{
  GdkInputWindow *input_window;

  input_window = _gdk_input_window_find (window);
  g_return_if_fail (input_window != NULL);

  _gdk_input_windows = g_list_remove (_gdk_input_windows,input_window);
  g_free (input_window);
}

209 210 211 212 213
void
_gdk_input_check_extension_events (GdkDevice *device)
{
}

Anders Carlsson's avatar
Anders Carlsson committed
214 215 216
void
_gdk_input_init (void)
{
217 218 219 220 221 222 223 224 225 226 227 228 229 230
  GdkDeviceManager *device_manager;
  GList *list, *l;

  device_manager = gdk_display_get_device_manager (_gdk_display);

  /* For backward compatibility, just add floating devices that are
   * not keyboards.
   */
  list = gdk_device_manager_list_devices (device_manager,
                                          GDK_DEVICE_TYPE_FLOATING);
  for (l = list; l; l = l->next)
    {
      GdkDevice *device = l->data;

231
      if (gdk_device_get_source(device) == GDK_SOURCE_KEYBOARD)
232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
        continue;

      _gdk_input_devices = g_list_prepend (_gdk_input_devices, l->data);
    }

  g_list_free (list);

  /* Now set "core" pointer to the first master device that is a pointer.
   */
  list = gdk_device_manager_list_devices (device_manager,
                                          GDK_DEVICE_TYPE_MASTER);

  for (l = list; l; l = l->next)
    {
      GdkDevice *device = list->data;

248
      if (gdk_device_get_source(device) != GDK_SOURCE_MOUSE)
249 250 251 252 253 254 255 256 257 258 259 260
        continue;

      _gdk_display->core_pointer = device;
      break;
    }

  g_list_free (list);

  /* Add the core pointer to the devices list */
  _gdk_input_devices = g_list_prepend (_gdk_input_devices,
                                       _gdk_display->core_pointer);

Anders Carlsson's avatar
Anders Carlsson committed
261 262 263 264 265 266 267 268 269 270 271 272 273 274 275
  _gdk_input_ignore_core = FALSE;
}

void
_gdk_input_exit (void)
{
  GList *tmp_list;
  GdkDevicePrivate *gdkdev;

  for (tmp_list = _gdk_input_devices; tmp_list; tmp_list = tmp_list->next)
    {
      gdkdev = (GdkDevicePrivate *)(tmp_list->data);
      if (gdkdev != (GdkDevicePrivate *)_gdk_core_pointer)
	{
	  gdk_device_set_mode ((GdkDevice *)gdkdev, GDK_MODE_DISABLED);
276
	  g_object_unref(gdkdev);
Anders Carlsson's avatar
Anders Carlsson committed
277 278 279 280 281 282 283 284 285 286 287
	}
    }

  g_list_free (_gdk_input_devices);

  for (tmp_list = _gdk_input_windows; tmp_list; tmp_list = tmp_list->next)
    {
      g_free (tmp_list->data);
    }
  g_list_free (_gdk_input_windows);
}