--- gtk+-3.8.2/gdk/broadway/broadwayd.c	2013-05-04 16:28:25 +0000
+++ gtk+-3.8.2/gdk/broadway/broadwayd.c	2013-06-12 07:45:31 +0000
@@ -1,6 +1,8 @@
 #include "config.h"
 #include <string.h>
+#ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <stdlib.h>
@@ -8,7 +10,9 @@
 
 #include <glib.h>
 #include <gio/gio.h>
+#ifdef G_OS_UNIX
 #include <gio/gunixsocketaddress.h>
+#endif
 
 #include "broadway-server.h"
 
@@ -433,12 +437,15 @@
   GError *error = NULL;
   GOptionContext *context;
   GMainLoop *loop;
+  GInetAddress *inet;
   GSocketAddress *address;
   GSocketService *listener;
   char *path, *base;
   char *http_address = NULL;
   int http_port = 0;
   int display = 1;
+  char *local_socket_type = NULL;
+  int local_port = 0;
   const GOptionEntry entries[] = {
     { "port", 'p', 0, G_OPTION_ARG_INT, &http_port, "Httpd port", "PORT" },
     { "address", 'a', 0, G_OPTION_ARG_STRING, &http_address, "Ip address to bind to ", "ADDRESS" },
@@ -478,13 +485,60 @@
       return 1;
     }
 
-  base = g_strdup_printf ("broadway%d.socket", display);
-  path = g_build_filename (g_get_user_runtime_dir (), base, NULL);
-  g_free (base);
-  g_print ("Listening on %s\n", path);
-  address = g_unix_socket_address_new_with_type (path, -1,
-						 G_UNIX_SOCKET_ADDRESS_ABSTRACT);
-  g_free (path);
+  char *local_socket_env = g_strdup (g_getenv ("BROADWAY_LOCALPORT"));
+  if (local_socket_env != NULL)
+    {
+      char *type_env = strtok (local_socket_env, ":");
+      char *port_env = strtok (NULL, ":");
+
+      if ( (strcmp (type_env, "tcp") == 0)||(strcmp (type_env, "unix") == 0) )
+        local_socket_type = type_env;
+
+      if (port_env != NULL)
+        {
+          int port_envl = strtol (port_env, NULL, 10);
+          if ( (port_envl >= 1)&&(port_envl <= (65535 - (display - 1))) )
+            local_port = port_envl + (display - 1);
+        }  
+    }
+  g_free (local_socket_env);
+
+#ifdef G_OS_WIN32
+  local_socket_type = g_strdup ("tcp");
+#endif
+
+  if (local_socket_type == NULL)
+#ifdef G_OS_UNIX
+    local_socket_type = g_strdup ("unix");
+#else
+    local_socket_type = g_strdup ("tcp");
+#endif
+
+  if (local_port == 0)
+    local_port = 9090 + (display - 1);
+
+#ifdef G_OS_UNIX
+  if (strcmp (local_socket_type, "unix") == 0)
+    {
+      base = g_strdup_printf ("broadway%d.socket", display);
+      path = g_build_filename (g_get_user_runtime_dir (), base, NULL);
+      g_free (base);
+      g_print ("Listening on %s\n", path);
+      address = g_unix_socket_address_new_with_type (path, -1,
+						     G_UNIX_SOCKET_ADDRESS_ABSTRACT);
+      g_free (path);
+    }
+  else if (strcmp (local_socket_type, "tcp") == 0)
+    {
+#endif
+      g_print ("Listening on localhost:%d\n", local_port);
+      inet = g_inet_address_new_from_string ("127.0.0.1");
+      address = g_inet_socket_address_new (inet, local_port);
+#ifdef G_OS_UNIX
+    }
+#endif
+
+  g_free (local_socket_type);
 
   listener = g_socket_service_new ();
   if (!g_socket_listener_add_address (G_SOCKET_LISTENER (listener),
@@ -499,7 +553,7 @@
       return 1;
     }
   g_object_unref (address);
-
+  g_object_unref (inet);
   g_signal_connect (listener, "incoming", G_CALLBACK (incoming_client), NULL);
 
   g_socket_service_start (G_SOCKET_SERVICE (listener));
--- gtk+-3.8.2/gdk/broadway/broadway-server.c	2013-05-04 16:28:25 +0000
+++ gtk+-3.8.2/gdk/broadway/broadway-server.c	2013-06-12 08:04:40 +0000
@@ -12,13 +12,21 @@
 #include <errno.h>
 #include <unistd.h>
 #include <crypt.h>
+#ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
+#ifdef G_OS_UNIX
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#include <string.h>
+#endif
 
 typedef struct BroadwayInput BroadwayInput;
 typedef struct BroadwayWindow BroadwayWindow;
@@ -858,6 +866,62 @@
 }
 
 static char *
+shm_get_path (char *name)
+{
+  if (*name == '/') ++name;
+  char *path = g_strconcat (g_get_tmp_dir (), G_DIR_SEPARATOR_S, name, NULL);
+  return path;
+}
+
+static int
+shm_open_read_cross (char *name)
+{
+  int fd;
+#ifdef G_OS_UNIX
+  fd = shm_open(name, O_RDONLY, 0600);
+#elif defined(G_OS_WIN32)
+  char *shmpath = shm_get_path (name);
+  fd = open(shmpath, O_RDONLY, 0600);
+  g_free (shmpath);
+#endif
+  return fd;
+}
+
+static void *
+shm_unlink_cross (char *name)
+{
+#ifdef G_OS_UNLINK
+  shm_unlink (name);
+#elif defined(G_OS_WIN32)
+  char *shmpath = shm_get_path (name);
+  remove (shmpath);
+  g_free (shmpath);
+#endif
+}
+
+static void *
+mmap_read_cross (int fd, gsize size)
+{
+  void *ptr;
+#if G_OS_UNIX
+  ptr = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
+#elif defined(G_OS_WIN32)
+  void *map = ((void *)-1);
+  if (size == 0)
+    ptr = map;
+  else
+    {
+      HANDLE h, fm;
+      h = (HANDLE)_get_osfhandle (fd);
+      fm = CreateFileMapping (h, NULL, PAGE_READONLY, 0, (DWORD)size, NULL);
+      ptr = MapViewOfFile (fm, FILE_MAP_READ, 0, 0, (size_t)size);
+      CloseHandle (fm);
+    }
+#endif
+  return ptr;
+}
+
+static char *
 parse_line (char *line, char *key)
 {
   char *p;
@@ -873,6 +937,7 @@
     p++;
   return p;
 }
+
 static void
 send_error (HttpRequest *request,
 	    int error_code,
@@ -1831,7 +1896,11 @@
 shm_data_unmap (void *_data)
 {
   ShmSurfaceData *data = _data;
+#ifdef G_OS_UNIX
   munmap (data->data, data->data_size);
+#elif defined(G_OS_WIN32)
+  UnmapViewOfFile (data->data);
+#endif
   g_free (data);
 }
 
@@ -1860,17 +1929,17 @@
 
   size = width * height * sizeof (guint32);
 
-  fd = shm_open(name, O_RDONLY, 0600);
+  fd = shm_open_read_cross (name);
   if (fd == -1)
     {
       perror ("Failed to shm_open");
       return NULL;
     }
 
-  ptr = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
+  ptr = mmap_read_cross (fd, size);
   (void) close(fd);
 
-  shm_unlink (name);
+  shm_unlink_cross (name);
 
   if (ptr == NULL)
     return NULL;
--- gtk+-3.8.2/gdk/broadway/gdkbroadway-server.c	2013-05-04 16:28:25 +0000
+++ gtk+-3.8.2/gdk/broadway/gdkbroadway-server.c	2013-06-12 08:05:18 +0000
@@ -1,4 +1,6 @@
+#ifdef HAVE_SYS_MMAN_H
 #include <sys/mman.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 
@@ -8,15 +10,22 @@
 
 #include <glib.h>
 #include <glib/gprintf.h>
+#ifdef G_OS_UNIX
 #include <gio/gunixsocketaddress.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
+#ifdef G_OS_UNIX
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#endif
+#ifdef G_OS_WIN32
+#include <windows.h>
+#endif
 
 typedef struct BroadwayInput BroadwayInput;
 
@@ -84,26 +93,76 @@
   char *basename;
   GSocketClient *client;
   GSocketConnection *connection;
+  GInetAddress *inet;
   GSocketAddress *address;
   GPollableInputStream *pollable;
   GInputStream *in;
   GSource *source;
   char *path;
+  char *local_socket_type = NULL;
+  int local_port = 0;
 
-  basename = g_strdup_printf ("broadway%d.socket", port);
-  path = g_build_filename (g_get_user_runtime_dir (), basename, NULL);
-  g_free (basename);
-
-  address = g_unix_socket_address_new_with_type (path, -1,
-						 G_UNIX_SOCKET_ADDRESS_ABSTRACT);
-  g_free (path);
+  char *local_socket_env = g_strdup (g_getenv ("BROADWAY_LOCALPORT"));
+  if (local_socket_env != NULL)
+    {
+      char *type_env = strtok (local_socket_env, ":");
+      char *port_env = strtok (NULL, ":");
+
+      if ( (strcmp (type_env, "tcp") == 0)||(strcmp (type_env, "unix") == 0) )
+        local_socket_type = type_env;
+
+      if (port_env != NULL)
+        {
+          int port_envl = strtol (port_env, NULL, 10);
+          if ( (port_envl >= 1)&&(port_envl <= (65535 - (port - 1))) )
+            local_port = port_envl + (port - 1);
+        }  
+    }
+  g_free (local_socket_env);
+
+#ifdef G_OS_WIN32
+  local_socket_type = g_strdup ("tcp");
+#endif
+
+  if (local_socket_type == NULL)
+#ifdef G_OS_UNIX
+    local_socket_type = g_strdup ("unix");
+#else
+    local_socket_type = g_strdup ("tcp");
+#endif
+
+  if (local_port == 0)
+    local_port = 9090 + (port - 1);
+
+#ifdef G_OS_UNIX
+  if (strcmp (local_socket_type, "unix") == 0)
+    {
+      basename = g_strdup_printf ("broadway%d.socket", port);
+      path = g_build_filename (g_get_user_runtime_dir (), basename, NULL);
+      g_free (basename);
+
+      address = g_unix_socket_address_new_with_type (path, -1,
+						     G_UNIX_SOCKET_ADDRESS_ABSTRACT);
+      g_free (path);
+    }
+  else if (strcmp (local_socket_type, "unix") == 0)
+    {
+#endif
+      inet = g_inet_address_new_from_string ("127.0.0.1");
+      address = g_inet_socket_address_new (inet, local_port);
+#ifdef G_OS_UNIX
+    }
+#endif
+
+  g_free (local_socket_type);
 
   client = g_socket_client_new ();
 
   error = NULL;
   connection = g_socket_client_connect (client, G_SOCKET_CONNECTABLE (address), NULL, error);
-  
+
   g_object_unref (address);
+  g_object_unref (inet);
   g_object_unref (client);
 
   if (connection == NULL)
@@ -501,6 +560,50 @@
   return TRUE;
 }
 
+static void *
+mmap_write_cross (int fd, gsize size)
+{
+  void *ptr;
+#if G_OS_UNIX
+  ptr = mmap(0, size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0);
+#elif defined(G_OS_WIN32)
+  void *map = ((void *)-1);
+  if (size == 0)
+    ptr = map;
+  else
+    {
+      HANDLE h, fm;
+      h = (HANDLE)_get_osfhandle (fd);
+      fm = CreateFileMapping (h, NULL, PAGE_READWRITE, 0, (DWORD)size, NULL);
+      ptr = MapViewOfFile (fm, FILE_MAP_WRITE, 0, 0, (size_t)size);
+      CloseHandle (fm);
+    }
+#endif
+  return ptr;
+}
+
+static char *
+shm_get_path (char *name)
+{
+  if (*name == '/') ++name;
+  char *path = g_strconcat (g_get_tmp_dir (), G_DIR_SEPARATOR_S, name, NULL);
+  return path;
+}
+
+static int
+shm_open_write_cross (char *name)
+{
+  int fd;
+#ifdef G_OS_UNIX
+  fd = shm_open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
+#elif defined(G_OS_WIN32)
+  char *shmpath = shm_get_path (name);
+  fd = open(shmpath, O_RDWR|O_CREAT|O_EXCL, 0600);
+  g_free (shmpath);
+#endif
+  return fd;
+}
+
 static char
 make_valid_fs_char (char c)
 {
@@ -533,8 +636,8 @@
 	  name[o++] = make_valid_fs_char ((r >> 24) & 0xff);
 	}
       name[o++] = 0;
-  
-      fd = shm_open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
+
+      fd = shm_open_write_cross (name);
       if (fd >= 0)
 	return fd;
 
@@ -560,8 +663,16 @@
 {
   BroadwayShmSurfaceData *data = _data;
 
+#ifdef G_OS_UNIX
   munmap (data->data, data->data_size);
   shm_unlink (data->name);
+#elif defined(G_OS_WIN32)
+  UnmapViewOfFile (data->data);
+  char *name = data->name;
+  char *shmpath = shm_get_path (name);
+  remove (shmpath);
+  g_free (shmpath);
+#endif
   g_free (data);
 }
 
@@ -582,14 +693,23 @@
   res = ftruncate (fd, data->data_size);
   g_assert (res != -1);
 
+#if G_OS_UNIX
   res = posix_fallocate (fd, 0, data->data_size);
+
   if (res != 0)
     {
       shm_unlink (data->name);
+
       g_error ("Not enough shared memory for window surface");
     }
-
-  data->data = mmap(0, data->data_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 
+#elif defined(G_OS_WIN32)
+  char *name = data->name;
+  char *shmpath = shm_get_path (name);
+  remove (shmpath);
+  g_free (shmpath);
+#endif
+  
+  data->data = mmap_write_cross (fd, data->data_size);
   (void) close(fd);
 
   surface = cairo_image_surface_create_for_data ((guchar *)data->data,
--- gtk+-3.8.2/gdk/broadway/gdkdisplay-broadway.c	2013-05-13 10:15:07 +0000
+++ gtk+-3.8.2/gdk/broadway/gdkdisplay-broadway.c	2013-06-11 18:23:43 +0000
@@ -39,9 +39,11 @@
 #include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
+#ifdef G_OS_UNIX
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#endif
 
 static void   gdk_broadway_display_dispose            (GObject            *object);
 static void   gdk_broadway_display_finalize           (GObject            *object);
--- gtk+-3.8.2/gdk/broadway/gdkwindow-broadway.c	2013-05-13 10:15:07 +0000
+++ gtk+-3.8.2/gdk/broadway/gdkwindow-broadway.c	2013-06-11 18:25:31 +0000
@@ -39,8 +39,10 @@
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
+#ifdef G_OS_UNIX
 #include <netinet/in.h>
 #include <unistd.h>
+#endif
 
 /* Forward declarations */
 static void     gdk_window_broadway_set_background     (GdkWindow      *window,
--- gtk+-3.8.2/gdk/broadway/Makefile.am	2013-05-13 10:15:07 +0000
+++ gtk+-3.8.2/gdk/broadway/Makefile.am	2013-06-12 08:59:41 +0000
@@ -83,7 +83,11 @@
 	broadway-output.h		\
 	broadway-output.c
 
+if OS_WIN32
+broadwayd_LDADD = $(GDK_DEP_LIBS) -lcrypt -lws2_32
+else
 broadwayd_LDADD = $(GDK_DEP_LIBS) -lrt -lcrypt
+endif
 
 MAINTAINERCLEANFILES = $(broadway_built_sources)
 EXTRA_DIST += $(broadway_built_sources)
--- gtk+-3.8.2/configure.ac	2013-05-13 10:23:51 +0000
+++ gtk+-3.8.2/configure.ac	2013-06-12 11:53:18 +0000
@@ -381,7 +381,9 @@
 if test "x$enable_broadway_backend" = xyes; then
   GDK_BACKENDS="$GDK_BACKENDS broadway"
   cairo_backends="$cairo_backends cairo"
-  have_gio_unix=yes
+  if test "$os_unix" = "yes"; then
+    have_gio_unix=yes
+  fi
   GDK_WINDOWING="$GDK_WINDOWING
 #define GDK_WINDOWING_BROADWAY"
   GDK_EXTRA_LIBS="$GDK_EXTRA_LIBS -lz"
@@ -714,6 +716,9 @@
 AC_CHECK_HEADERS(pwd.h,
                  AC_DEFINE(HAVE_PWD_H, 1,
                            [Define to 1 if pwd.h is available]))
+AC_CHECK_HEADERS(sys/mman.h,
+                 AC_DEFINE(HAVE_SYS_MMAN_H, 1,
+                           [Define to 1 if time.h is available]))
 AC_CHECK_HEADERS(sys/time.h,
                  AC_DEFINE(HAVE_SYS_TIME_H, 1,
                            [Define to 1 if time.h is available]))
