--- gtk+-3.8.2/gdk/broadway/broadwayd.c	2013-04-13 20:26:13 +0000
+++ gtk+-3.8.2/gdk/broadway/broadwayd.c	2013-06-05 09:17:49 +0000
@@ -1,6 +1,8 @@
 #include "config.h"
 #include <string.h>
+#ifndef _WIN32
 #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>
+#ifndef _WIN32
 #include <gio/gunixsocketaddress.h>
+#endif
 
 #include "broadway-server.h"
 
@@ -433,11 +437,18 @@
   GError *error = NULL;
   GOptionContext *context;
   GMainLoop *loop;
+#ifdef _WIN32
+  GInetAddress *inet;
+#endif
   GSocketAddress *address;
   GSocketService *listener;
   char *path, *base;
   char *http_address = NULL;
   int http_port = 0;
+#ifdef _WIN32
+  int local_port = 0;
+  char *local_port_name = NULL;
+#endif
   int display = 1;
   const GOptionEntry entries[] = {
     { "port", 'p', 0, G_OPTION_ARG_INT, &http_port, "Httpd port", "PORT" },
@@ -471,6 +482,21 @@
   if (http_port == 0)
     http_port = 8080 + (display - 1);
 
+#ifdef _WIN32
+  if (local_port == 0)
+    {
+      if (local_port_name == NULL)
+        local_port_name = g_getenv ("BROADWAY_LOCALPORT");
+      if (local_port_name != NULL)
+          local_port = strtol(local_port_name, NULL, 10);
+      else
+          local_port = 9090;
+    }
+  local_port += (display - 1);
+  if (local_port <= 0)
+    local_port = 1;
+#endif
+
   server = broadway_server_new (http_address, http_port, &error);
   if (server == NULL)
     {
@@ -478,6 +504,8 @@
       return 1;
     }
 
+
+#ifndef _WIN32
   base = g_strdup_printf ("broadway%d.socket", display);
   path = g_build_filename (g_get_user_runtime_dir (), base, NULL);
   g_free (base);
@@ -485,7 +513,11 @@
   address = g_unix_socket_address_new_with_type (path, -1,
 						 G_UNIX_SOCKET_ADDRESS_ABSTRACT);
   g_free (path);
-
+#else
+  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);
+#endif
   listener = g_socket_service_new ();
   if (!g_socket_listener_add_address (G_SOCKET_LISTENER (listener),
 				      address,
@@ -499,7 +531,9 @@
       return 1;
     }
   g_object_unref (address);
-
+#ifdef _WIN32
+  g_object_unref (inet);
+#endif
   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-04-13 20:26:13 +0000
+++ gtk+-3.8.2/gdk/broadway/broadway-server.c	2013-06-06 05:27:27 +0000
@@ -12,13 +12,21 @@
 #include <errno.h>
 #include <unistd.h>
 #include <crypt.h>
+#ifndef _WIN32
 #include <sys/mman.h>
+#else
+#include <windows.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#else
+#include <string.h>
+#endif
 
 typedef struct BroadwayInput BroadwayInput;
 typedef struct BroadwayWindow BroadwayWindow;
@@ -1831,7 +1839,11 @@
 shm_data_unmap (void *_data)
 {
   ShmSurfaceData *data = _data;
+#ifndef _WIN32
   munmap (data->data, data->data_size);
+#else
+  UnmapViewOfFile (data->data);
+#endif
   g_free (data);
 }
 
@@ -1860,17 +1872,67 @@
 
   size = width * height * sizeof (guint32);
 
+#ifndef _WIN32
   fd = shm_open(name, O_RDONLY, 0600);
+#else
+  char *bwdpath = NULL;
+  bwdpath = g_getenv ("HOMEDRIVE");
+  if (bwdpath == NULL)
+    bwdpath = g_strdup ("c:");
+  strncat (bwdpath, G_DIR_SEPARATOR_S, PATH_MAX);
+  strncat (bwdpath, ".bwd", PATH_MAX);
+
+  if (!g_file_test (bwdpath, G_FILE_TEST_EXISTS))
+    {
+      g_mkdir (bwdpath);
+    }
+  else
+    {
+      if (g_file_test (bwdpath, G_FILE_TEST_IS_REGULAR))
+        {
+          g_remove (bwdpath);
+          g_mkdir (bwdpath);
+        }
+    }
+  SetFileAttributes (bwdpath, FILE_ATTRIBUTE_HIDDEN);
+
+  if (*name == '/') ++name;
+  strncat (bwdpath, G_DIR_SEPARATOR_S, PATH_MAX);
+  strncat (bwdpath, name, PATH_MAX);
+  fd = open(bwdpath, O_RDONLY, 0600);
+#endif
   if (fd == -1)
     {
       perror ("Failed to shm_open");
       return NULL;
     }
 
+#ifndef _WIN32
   ptr = mmap(0, size, PROT_READ, MAP_SHARED, fd, 0);
+#else
+  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
   (void) close(fd);
 
+#ifndef _WIN32
   shm_unlink (name);
+#else
+  remove (bwdpath);
+#endif
 
   if (ptr == NULL)
     return NULL;
--- gtk+-3.8.2/gdk/broadway/gdkbroadway-server.c	2013-04-13 20:26:13 +0000
+++ gtk+-3.8.2/gdk/broadway/gdkbroadway-server.c	2013-06-06 05:26:48 +0000
@@ -1,4 +1,8 @@
+#ifndef _WIN32
 #include <sys/mman.h>
+#else
+#include <windows.h>
+#endif
 #include <sys/stat.h>
 #include <fcntl.h>
 
@@ -8,15 +12,19 @@
 
 #include <glib.h>
 #include <glib/gprintf.h>
+#ifndef _WIN32
 #include <gio/gunixsocketaddress.h>
+#endif
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
 #include <unistd.h>
 #include <sys/types.h>
+#ifndef _WIN32
 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <netinet/tcp.h>
+#endif
 
 typedef struct BroadwayInput BroadwayInput;
 
@@ -39,6 +47,37 @@
   GObjectClass parent_class;
 };
 
+
+#ifdef _WIN32
+static char *
+get_bwdpath ()
+{
+  char *bwdpath = NULL;
+  bwdpath = g_getenv ("HOMEDRIVE");
+  if (bwdpath == NULL)
+    bwdpath = g_strdup ("c:");
+  strncat (bwdpath, G_DIR_SEPARATOR_S, PATH_MAX);
+  strncat (bwdpath, ".bwd", PATH_MAX);
+
+  if (!g_file_test (bwdpath, G_FILE_TEST_EXISTS))
+    {
+      g_mkdir (bwdpath);
+    }
+  else
+    {
+      if (g_file_test (bwdpath, G_FILE_TEST_IS_REGULAR))
+        {
+          g_remove (bwdpath);
+          g_mkdir (bwdpath);
+        }
+    }
+  SetFileAttributes (bwdpath, FILE_ATTRIBUTE_HIDDEN);
+
+  return bwdpath;
+}
+#endif
+
+
 static gboolean input_available_cb (gpointer stream, gpointer user_data);
 
 G_DEFINE_TYPE (GdkBroadwayServer, gdk_broadway_server, G_TYPE_OBJECT)
@@ -84,26 +123,55 @@
   char *basename;
   GSocketClient *client;
   GSocketConnection *connection;
+#ifdef _WIN32
+  GInetAddress *inet;
+#endif
   GSocketAddress *address;
   GPollableInputStream *pollable;
   GInputStream *in;
   GSource *source;
   char *path;
 
+#ifndef _WIN32
   basename = g_strdup_printf ("broadway%d.socket", port);
   path = g_build_filename (g_get_user_runtime_dir (), basename, NULL);
   g_free (basename);
+  g_free (path);
 
   address = g_unix_socket_address_new_with_type (path, -1,
 						 G_UNIX_SOCKET_ADDRESS_ABSTRACT);
-  g_free (path);
+#else
+  int local_port = 0;
+  char *local_port_name = NULL;
+
+  if (local_port == 0)
+    {
+      if (local_port_name == NULL)
+        local_port_name = g_getenv ("BROADWAY_LOCALPORT");
+      if (local_port_name != NULL)
+          local_port = strtol(local_port_name, NULL, 10);
+      else
+          local_port = 9090;
+    }
+
+   local_port += (port - 1);
+   if (local_port <= 0)
+     local_port = 1;
+
+  inet = g_inet_address_new_from_string ("127.0.0.1");
+  address = g_inet_socket_address_new (inet, local_port);
+#endif
 
   client = g_socket_client_new ();
 
   error = NULL;
+
   connection = g_socket_client_connect (client, G_SOCKET_CONNECTABLE (address), NULL, error);
-  
+
   g_object_unref (address);
+#ifdef _WIN32
+  g_object_unref (inet);
+#endif
   g_object_unref (client);
 
   if (connection == NULL)
@@ -533,8 +601,16 @@
 	  name[o++] = make_valid_fs_char ((r >> 24) & 0xff);
 	}
       name[o++] = 0;
-  
+
+#ifndef _WIN32
       fd = shm_open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
+#else
+      if (*name == '/') ++name;
+      char *bwdpath = get_bwdpath ();
+      strncat (bwdpath, G_DIR_SEPARATOR_S, PATH_MAX);
+      strncat (bwdpath, name, PATH_MAX);
+      fd = open(bwdpath, O_RDWR|O_CREAT|O_EXCL, 0600);
+#endif
       if (fd >= 0)
 	return fd;
 
@@ -560,8 +636,16 @@
 {
   BroadwayShmSurfaceData *data = _data;
 
+#ifndef _WIN32
   munmap (data->data, data->data_size);
   shm_unlink (data->name);
+#else
+  UnmapViewOfFile (data->data);
+  char *bwdpath = get_bwdpath ();
+  strncat (bwdpath, G_DIR_SEPARATOR_S, PATH_MAX);
+  strncat (bwdpath, data->name, PATH_MAX);
+  remove (bwdpath);
+#endif
   g_free (data);
 }
 
@@ -582,14 +666,59 @@
   res = ftruncate (fd, data->data_size);
   g_assert (res != -1);
 
+#ifndef _WIN32
   res = posix_fallocate (fd, 0, data->data_size);
+
   if (res != 0)
     {
       shm_unlink (data->name);
+
       g_error ("Not enough shared memory for window surface");
     }
+#else
+  int zero_size = (int) data->data_size;
+  char zeros[zero_size];
+  memset (zeros, 0, sizeof(zeros));
+
+  ssize_t w;
+  size_t pos_t = 0;
+  size_t len_t = (size_t) data->data_size;
+
+  while (pos_t < len_t)
+    {
+      w = write (fd, zeros, len_t - pos_t < zero_size ? len_t - pos_t : zero_size);
+      if (w == -1)
+      {
+        char *bwdpath = get_bwdpath ();
+        strncat (bwdpath, G_DIR_SEPARATOR_S, PATH_MAX);
+        strncat (bwdpath, data->name, PATH_MAX);
+        remove (bwdpath);
+
+        g_error ("Not enough shared memory for window surface");
+      }
+      pos_t += w;
+    }
+#endif
 
+#ifndef _WIN32
   data->data = mmap(0, data->data_size, PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0); 
+#else
+  void *map = ((void *)-1);
+
+  if (data->data_size == 0)
+    {
+      data->data = map;
+    }
+  else
+    {
+      HANDLE h, fm;
+ 
+      h = (HANDLE)_get_osfhandle (fd);
+      fm = CreateFileMapping (h, NULL, PAGE_READWRITE, 0, (DWORD)data->data_size, NULL);
+      data->data = MapViewOfFile (fm, FILE_MAP_WRITE, 0, 0, (size_t)data->data_size);
+      CloseHandle (fm);
+    }
+#endif
   (void) close(fd);
 
   surface = cairo_image_surface_create_for_data ((guchar *)data->data,
--- gtk+-3.8.2/gdk/broadway/Makefile.am	2013-04-13 20:26:13 +0000
+++ gtk+-3.8.2/gdk/broadway/Makefile.am	2013-06-06 10:24:10 +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-04-15 17:43:14 +0000
+++ gtk+-3.8.2/configure.ac	2013-06-06 10:31:39 +0000
@@ -381,7 +381,7 @@
 if test "x$enable_broadway_backend" = xyes; then
   GDK_BACKENDS="$GDK_BACKENDS broadway"
   cairo_backends="$cairo_backends cairo"
-  have_gio_unix=yes
+  have_gio_unix=no
   GDK_WINDOWING="$GDK_WINDOWING
 #define GDK_WINDOWING_BROADWAY"
   GDK_EXTRA_LIBS="$GDK_EXTRA_LIBS -lz"
