[gtk/wip.win32.fixes: 16/16] partial WIP port of GDK4-Broadway to Windows...




commit f268567f2ac1d1021c97dd487e8ef91aaa44958c
Author: Chun-wei Fan <fanchunwei src gnome org>
Date:   Mon Jun 21 11:26:45 2021 +0800

    partial WIP port of GDK4-Broadway to Windows...

 gdk/broadway/broadwayd.c          | 41 +++++++++++++++++++++++++++++++++++++--
 gdk/broadway/gdkbroadway-server.c | 29 ++++++++++++++++++++++++---
 2 files changed, 65 insertions(+), 5 deletions(-)
---
diff --git a/gdk/broadway/broadwayd.c b/gdk/broadway/broadwayd.c
index 9cfa48f138..20a0763823 100644
--- a/gdk/broadway/broadwayd.c
+++ b/gdk/broadway/broadwayd.c
@@ -17,6 +17,11 @@
 #include <gio/gunixfdmessage.h>
 #endif
 
+#ifdef G_OS_WIN32
+#include <io.h>
+#include <winsock2.h>
+#endif
+
 #include "broadway-server.h"
 
 BroadwayServer *server;
@@ -60,11 +65,13 @@ typedef struct  {
   GHashTable *textures;
 } BroadwayClient;
 
+#ifdef G_OS_UNIX
 static void
 close_fd (void *data)
 {
   close (GPOINTER_TO_INT (data));
 }
+#endif
 
 static void
 client_free (BroadwayClient *client)
@@ -76,7 +83,9 @@ client_free (BroadwayClient *client)
   g_object_unref (client->in);
   g_string_free (client->buffer, TRUE);
   g_slist_free_full (client->serial_mappings, g_free);
+#ifdef G_OS_UNIX
   g_list_free_full (client->fds, close_fd);
+#endif
   g_hash_table_destroy (client->textures);
   g_free (client);
 }
@@ -296,6 +305,7 @@ client_handle_request (BroadwayClient *client,
       }
       break;
     case BROADWAY_REQUEST_UPLOAD_TEXTURE:
+#ifdef G_OS_UNIX
       if (client->fds == NULL)
         g_warning ("FD passing mismatch for texture upload %d", request->release_texture.id);
       else
@@ -341,6 +351,7 @@ client_handle_request (BroadwayClient *client,
                                 GINT_TO_POINTER (request->release_texture.id),
                                 GINT_TO_POINTER (global_id));
         }
+#endif
       break;
     case BROADWAY_REQUEST_RELEASE_TEXTURE:
       global_id = GPOINTER_TO_INT (g_hash_table_lookup (client->textures,
@@ -439,6 +450,8 @@ client_input_cb (GPollableInputStream *stream,
       return G_SOURCE_REMOVE;
     }
 
+/* realistically, the "messages" only apply on UNIX platforms */
+#ifdef G_OS_UNIX
   for (i = 0; i < num_messages; i++)
     {
       if (G_IS_UNIX_FD_MESSAGE (messages[i]))
@@ -454,6 +467,8 @@ client_input_cb (GPollableInputStream *stream,
         }
       g_object_unref (messages[i]);
     }
+#endif
+
   g_free (messages);
 
   g_string_set_size (client->buffer, old_len + res);
@@ -570,13 +585,32 @@ main (int argc, char *argv[])
     }
 
   if (display == NULL)
-    display = ":0";
+    {
+#ifdef G_OS_UNIX
+      display = ":0";
+#elif defined (G_OS_WIN32)
+      display = ":tcp";
+#endif
+    }
+
+  if (g_str_has_prefix (display, ":tcp"))
+    {
+      GInetAddress *inet;
+
+      port = 9090 + strtol (display + strlen (":tcp"), NULL, 10);
+
+      inet = g_inet_address_new_from_string ("127.0.0.1");
+      address = g_inet_socket_address_new (inet, port);
+      g_object_unref (inet);
+    }
 
-  if (display[0] == ':' && g_ascii_isdigit(display[1]))
+#ifdef G_OS_UNIX
+  else if (display[0] == ':' && g_ascii_isdigit(display[1]))
     {
       char *path, *basename;
 
       port = strtol (display + strlen (":"), NULL, 10);
+
       basename = g_strdup_printf ("broadway%d.socket", port + 1);
       path = g_build_filename (g_get_user_runtime_dir (), basename, NULL);
       g_free (basename);
@@ -588,6 +622,7 @@ main (int argc, char *argv[])
                                                      G_UNIX_SOCKET_ADDRESS_PATH);
       g_free (path);
     }
+#endif
   else
     {
       g_printerr ("Failed to parse display %s\n", display);
@@ -597,9 +632,11 @@ main (int argc, char *argv[])
   if (http_port == 0)
     http_port = 8080 + port;
 
+#ifdef G_OS_UNIX
   if (unixsocket_address != NULL)
     server = broadway_server_on_unix_socket_new (unixsocket_address, &error);
   else
+#endif
     server = broadway_server_new (http_address,
                                   http_port,
                                   ssl_cert,
diff --git a/gdk/broadway/gdkbroadway-server.c b/gdk/broadway/gdkbroadway-server.c
index bd221f5442..9a15532f4e 100644
--- a/gdk/broadway/gdkbroadway-server.c
+++ b/gdk/broadway/gdkbroadway-server.c
@@ -19,8 +19,12 @@
 
 #include <glib.h>
 #include <glib/gprintf.h>
+
+#ifdef G_OS_UNIX
 #include <gio/gunixsocketaddress.h>
 #include <gio/gunixfdmessage.h>
+#endif
+
 #include <stdlib.h>
 #include <string.h>
 #include <errno.h>
@@ -113,10 +117,28 @@ _gdk_broadway_server_new (GdkDisplay *display,
   char *local_socket_type = NULL;
   int port;
 
-  if (display_name == NULL)
-    display_name = ":0";
+  if (display == NULL)
+    {
+#ifdef G_OS_UNIX
+      display_name = ":0";
+#elif defined (G_OS_WIN32)
+      display_name = ":tcp";
+#endif
+    }
 
-  if (display_name[0] == ':' && g_ascii_isdigit(display_name[1]))
+  if (g_str_has_prefix (display_name, ":tcp"))
+    {
+      GInetAddress *inet;
+
+      port = 9090 + strtol (display_name + strlen (":tcp"), NULL, 10);
+
+      inet = g_inet_address_new_from_string ("127.0.0.1");
+      address = g_inet_socket_address_new (inet, port);
+      g_object_unref (inet);
+    }
+
+#ifdef G_OS_UNIX
+  else if (display_name[0] == ':' && g_ascii_isdigit(display_name[1]))
     {
       char *path, *basename;
 
@@ -129,6 +151,7 @@ _gdk_broadway_server_new (GdkDisplay *display,
                                                      G_UNIX_SOCKET_ADDRESS_PATH);
       g_free (path);
     }
+#endif
   else
     {
       g_set_error (error, G_IO_ERROR, G_IO_ERROR_NOT_SUPPORTED,


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]