gdkdisplay-broadway.c 12.6 KB
Newer Older
1
/* GDK - The GIMP Drawing Kit
2
 * gdkdisplay-broadway.c
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
 * 
 * Copyright 2001 Sun Microsystems Inc.
 * Copyright (C) 2004 Nokia Corporation
 *
 * Erwann Chenede <erwann.chenede@sun.com>
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library 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
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
Javier Jardón's avatar
Javier Jardón committed
20
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 22 23 24 25 26
 */

#include "config.h"

#include "gdkdisplay-broadway.h"

27
#include "gdkcairocontext-broadway.h"
28 29
#include "gdkdisplay.h"
#include "gdkeventsource.h"
30
#include "gdkmonitor-broadway.h"
31 32
#include "gdkseatdefaultprivate.h"
#include "gdkdevice-broadway.h"
33 34
#include "gdkinternals.h"
#include "gdkdeviceprivate.h"
35
#include <gdk/gdktextureprivate.h>
36 37 38 39 40 41

#include <glib.h>
#include <glib/gprintf.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
42
#ifdef HAVE_UNISTD_H
43
#include <unistd.h>
44
#endif
45
#include <sys/types.h>
46

47 48
static void   gdk_broadway_display_dispose            (GObject            *object);
static void   gdk_broadway_display_finalize           (GObject            *object);
49

50 51 52 53
#if 0
#define DEBUG_WEBSOCKETS 1
#endif

54
G_DEFINE_TYPE (GdkBroadwayDisplay, gdk_broadway_display, GDK_TYPE_DISPLAY)
55 56

static void
57
gdk_broadway_display_init (GdkBroadwayDisplay *display)
58
{
59
  display->id_ht = g_hash_table_new (NULL, NULL);
60 61 62 63 64 65

  display->monitor = g_object_new (GDK_TYPE_BROADWAY_MONITOR,
                                   "display", display,
                                   NULL);
  gdk_monitor_set_manufacturer (display->monitor, "browser");
  gdk_monitor_set_model (display->monitor, "0");
66 67 68
}

static void
69
gdk_event_init (GdkDisplay *display)
70
{
71
  GdkBroadwayDisplay *broadway_display;
72

73 74
  broadway_display = GDK_BROADWAY_DISPLAY (display);
  broadway_display->event_source = _gdk_broadway_event_source_new (display);
75 76
}

77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
void
_gdk_broadway_display_size_changed (GdkDisplay                      *display,
                                    BroadwayInputScreenResizeNotify *msg)
{
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (display);
  GdkMonitor *monitor;
  GdkRectangle size;
  GList *toplevels, *l;

  monitor = broadway_display->monitor;
  gdk_monitor_get_geometry (monitor, &size);

  if (msg->width == size.width && msg->height == size.height)
    return;

  gdk_monitor_set_size (monitor, msg->width, msg->height);
  gdk_monitor_set_physical_size (monitor, msg->width * 25.4 / 96, msg->height * 25.4 / 96);

95
  toplevels =  broadway_display->toplevels;
96 97
  for (l = toplevels; l != NULL; l = l->next)
    {
98
      GdkSurfaceImplBroadway *toplevel_impl = l->data;
99 100

      if (toplevel_impl->maximized)
101
        gdk_surface_move_resize (toplevel_impl->wrapper, 0, 0, msg->width, msg->height);
102 103 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 139 140 141 142
static GdkDevice *
create_core_pointer (GdkDisplay       *display)
{
  return g_object_new (GDK_TYPE_BROADWAY_DEVICE,
                       "name", "Core Pointer",
                       "type", GDK_DEVICE_TYPE_MASTER,
                       "input-source", GDK_SOURCE_MOUSE,
                       "input-mode", GDK_MODE_SCREEN,
                       "has-cursor", TRUE,
                       "display", display,
                       NULL);
}

static GdkDevice *
create_core_keyboard (GdkDisplay       *display)
{
  return g_object_new (GDK_TYPE_BROADWAY_DEVICE,
                       "name", "Core Keyboard",
                       "type", GDK_DEVICE_TYPE_MASTER,
                       "input-source", GDK_SOURCE_KEYBOARD,
                       "input-mode", GDK_MODE_SCREEN,
                       "has-cursor", FALSE,
                       "display", display,
                       NULL);
}

static GdkDevice *
create_touchscreen (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,
                       NULL);
}
143

144
GdkDisplay *
145
_gdk_broadway_display_open (const gchar *display_name)
146 147
{
  GdkDisplay *display;
148
  GdkBroadwayDisplay *broadway_display;
149
  GError *error = NULL;
150
  GdkSeat *seat;
151

152 153
  display = g_object_new (GDK_TYPE_BROADWAY_DISPLAY, NULL);
  broadway_display = GDK_BROADWAY_DISPLAY (display);
154

155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
  broadway_display->core_pointer = create_core_pointer (display);
  broadway_display->core_keyboard = create_core_keyboard (display);
  broadway_display->touchscreen = create_touchscreen (display);

  _gdk_device_set_associated_device (broadway_display->core_pointer, broadway_display->core_keyboard);
  _gdk_device_set_associated_device (broadway_display->core_keyboard, broadway_display->core_pointer);
  _gdk_device_set_associated_device (broadway_display->touchscreen, broadway_display->core_pointer);
  _gdk_device_add_slave (broadway_display->core_pointer, broadway_display->touchscreen);

  seat = gdk_seat_default_new_for_master_pair (broadway_display->core_pointer,
                                               broadway_display->core_keyboard);
  gdk_display_add_seat (display, seat);
  gdk_seat_default_add_slave (GDK_SEAT_DEFAULT (seat), broadway_display->touchscreen);
  g_object_unref (seat);

170
  gdk_event_init (display);
171

172
  _gdk_broadway_display_init_dnd (display);
173

174 175 176
  if (display_name == NULL)
    display_name = g_getenv ("BROADWAY_DISPLAY");

177
  broadway_display->server = _gdk_broadway_server_new (display_name, &error);
178
  if (broadway_display->server == NULL)
179
    {
180
      g_printerr ("Unable to init Broadway server: %s\n", error->message);
181
      g_error_free (error);
182 183 184
      return NULL;
    }

185 186 187 188 189
  g_signal_emit_by_name (display, "opened");

  return display;
}

190
static const gchar *
191
gdk_broadway_display_get_name (GdkDisplay *display)
192 193
{
  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);
194 195

  return (gchar *) "Broadway";
196 197
}

198 199
static void
gdk_broadway_display_beep (GdkDisplay *display)
200
{
201
  g_return_if_fail (GDK_IS_DISPLAY (display));
202 203
}

204 205
static void
gdk_broadway_display_sync (GdkDisplay *display)
206
{
207
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (display);
208

209 210 211
  g_return_if_fail (GDK_IS_BROADWAY_DISPLAY (display));

  _gdk_broadway_server_sync (broadway_display->server);
212 213
}

214 215
static void
gdk_broadway_display_flush (GdkDisplay *display)
216
{
217 218
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (display);

219
  g_return_if_fail (GDK_IS_BROADWAY_DISPLAY (display));
220

221
  _gdk_broadway_server_flush (broadway_display->server);
222 223
}

224 225
static gboolean
gdk_broadway_display_has_pending (GdkDisplay *display)
226
{
227
  return FALSE;
228 229
}

230
static GdkSurface *
231
gdk_broadway_display_get_default_group (GdkDisplay *display)
232 233 234
{
  g_return_val_if_fail (GDK_IS_DISPLAY (display), NULL);

235
  return NULL;
236 237 238
}

static void
239
gdk_broadway_display_dispose (GObject *object)
240
{
241
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (object);
242

243
  if (broadway_display->event_source)
244
    {
245 246 247
      g_source_destroy (broadway_display->event_source);
      g_source_unref (broadway_display->event_source);
      broadway_display->event_source = NULL;
248 249
    }

250
  G_OBJECT_CLASS (gdk_broadway_display_parent_class)->dispose (object);
251 252 253
}

static void
254
gdk_broadway_display_finalize (GObject *object)
255
{
256
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (object);
257 258

  /* Keymap */
259 260
  if (broadway_display->keymap)
    g_object_unref (broadway_display->keymap);
261

262
  _gdk_broadway_cursor_display_finalize (GDK_DISPLAY(broadway_display));
263

264 265
  g_object_unref (broadway_display->monitor);

266
  G_OBJECT_CLASS (gdk_broadway_display_parent_class)->finalize (object);
267 268
}

269 270 271
static void
gdk_broadway_display_notify_startup_complete (GdkDisplay  *display,
					      const gchar *startup_id)
272 273 274
{
}

275 276
static gboolean
gdk_broadway_display_supports_shapes (GdkDisplay *display)
277
{
278
  return FALSE;
279 280
}

281 282
static gboolean
gdk_broadway_display_supports_input_shapes (GdkDisplay *display)
283
{
284
  return FALSE;
285 286
}

287 288
static gulong
gdk_broadway_display_get_next_serial (GdkDisplay *display)
289
{
290 291
  GdkBroadwayDisplay *broadway_display;
  broadway_display = GDK_BROADWAY_DISPLAY (display);
292

293 294
  return _gdk_broadway_server_get_next_serial (broadway_display->server);
}
295

296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311
void
gdk_broadway_display_show_keyboard (GdkBroadwayDisplay *display)
{
  g_return_if_fail (GDK_IS_BROADWAY_DISPLAY (display));

  _gdk_broadway_server_set_show_keyboard (display->server, TRUE);
}

void
gdk_broadway_display_hide_keyboard (GdkBroadwayDisplay *display)
{
  g_return_if_fail (GDK_IS_BROADWAY_DISPLAY (display));

  _gdk_broadway_server_set_show_keyboard (display->server, FALSE);
}

312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337
static int
gdk_broadway_display_get_n_monitors (GdkDisplay *display)
{
  return 1;
}

static GdkMonitor *
gdk_broadway_display_get_monitor (GdkDisplay *display,
                                  int         monitor_num)
{
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (display);

  if (monitor_num == 0)
    return broadway_display->monitor;

  return NULL;
}

static GdkMonitor *
gdk_broadway_display_get_primary_monitor (GdkDisplay *display)
{
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (display);

  return broadway_display->monitor;
}

338 339 340 341 342 343 344 345
static gboolean
gdk_broadway_display_get_setting (GdkDisplay *display,
                                  const char *name,
                                  GValue     *value)
{
  return FALSE;
}

346 347 348 349 350 351
static guint32
gdk_broadway_display_get_last_seen_time (GdkDisplay *display)
{
  return _gdk_broadway_server_get_last_seen_time (GDK_BROADWAY_DISPLAY (display)->server);
}

352 353 354
typedef struct {
  int id;
  GdkDisplay *display;
355
  GList *textures;
356 357 358
} BroadwayTextureData;

static void
359
broadway_texture_data_free (BroadwayTextureData *data)
360 361 362
{
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (data->display);

363 364 365
  gdk_broadway_server_release_texture (broadway_display->server, data->id);
  g_object_unref (data->display);
  g_free (data);
366 367 368 369 370 371 372 373 374
}

guint32
gdk_broadway_display_ensure_texture (GdkDisplay *display,
                                     GdkTexture *texture)
{
  GdkBroadwayDisplay *broadway_display = GDK_BROADWAY_DISPLAY (display);
  BroadwayTextureData *data;

375 376 377
  data = g_object_get_data (G_OBJECT (texture), "broadway-data");
  if (data == NULL)
    {
378
      guint32 id = gdk_broadway_server_upload_texture (broadway_display->server, texture);
379 380 381 382

      data = g_new0 (BroadwayTextureData, 1);
      data->id = id;
      data->display = g_object_ref (display);
383
      g_object_set_data_full (G_OBJECT (texture), "broadway-data", data, (GDestroyNotify)broadway_texture_data_free);
384
    }
385

386
  return data->id;
387 388
}

389 390
static void
gdk_broadway_display_class_init (GdkBroadwayDisplayClass * class)
391
{
392 393 394 395 396 397
  GObjectClass *object_class = G_OBJECT_CLASS (class);
  GdkDisplayClass *display_class = GDK_DISPLAY_CLASS (class);

  object_class->dispose = gdk_broadway_display_dispose;
  object_class->finalize = gdk_broadway_display_finalize;

398
  display_class->surface_type = GDK_TYPE_BROADWAY_SURFACE;
399
  display_class->cairo_context_type = GDK_TYPE_BROADWAY_CAIRO_CONTEXT;
400 401 402 403 404 405 406 407 408 409 410 411 412

  display_class->get_name = gdk_broadway_display_get_name;
  display_class->beep = gdk_broadway_display_beep;
  display_class->sync = gdk_broadway_display_sync;
  display_class->flush = gdk_broadway_display_flush;
  display_class->has_pending = gdk_broadway_display_has_pending;
  display_class->queue_events = _gdk_broadway_display_queue_events;
  display_class->get_default_group = gdk_broadway_display_get_default_group;
  display_class->supports_shapes = gdk_broadway_display_supports_shapes;
  display_class->supports_input_shapes = gdk_broadway_display_supports_input_shapes;

  display_class->get_next_serial = gdk_broadway_display_get_next_serial;
  display_class->notify_startup_complete = gdk_broadway_display_notify_startup_complete;
413
  display_class->create_surface_impl = _gdk_broadway_display_create_surface_impl;
414 415 416
  display_class->get_keymap = _gdk_broadway_display_get_keymap;
  display_class->text_property_to_utf8_list = _gdk_broadway_display_text_property_to_utf8_list;
  display_class->utf8_to_string_target = _gdk_broadway_display_utf8_to_string_target;
417 418 419 420

  display_class->get_n_monitors = gdk_broadway_display_get_n_monitors;
  display_class->get_monitor = gdk_broadway_display_get_monitor;
  display_class->get_primary_monitor = gdk_broadway_display_get_primary_monitor;
421
  display_class->get_setting = gdk_broadway_display_get_setting;
422
  display_class->get_last_seen_time = gdk_broadway_display_get_last_seen_time;
423
}