2013-06-13 15:58:53 +00:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
#include "broadway-server.h"
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2012-12-23 21:05:02 +00:00
|
|
|
#include "broadway-output.h"
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
#include <glib.h>
|
|
|
|
#include <glib/gprintf.h>
|
2012-12-23 22:35:03 +00:00
|
|
|
#include "gdktypes.h"
|
2020-04-03 13:19:37 +00:00
|
|
|
#include "gdkinternals.h"
|
2012-12-19 11:37:02 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
2013-09-26 16:21:08 +00:00
|
|
|
|
2013-07-01 12:51:03 +00:00
|
|
|
#ifdef HAVE_UNISTD_H
|
2012-12-19 11:37:02 +00:00
|
|
|
#include <unistd.h>
|
2013-07-01 12:51:03 +00:00
|
|
|
#elif defined (G_OS_WIN32)
|
|
|
|
#include <io.h>
|
|
|
|
#endif
|
2013-06-13 15:58:53 +00:00
|
|
|
#ifdef HAVE_SYS_MMAN_H
|
2013-03-29 08:38:34 +00:00
|
|
|
#include <sys/mman.h>
|
2013-06-13 15:58:53 +00:00
|
|
|
#endif
|
2013-03-29 08:38:34 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
2012-12-19 11:37:02 +00:00
|
|
|
#include <sys/types.h>
|
2013-06-13 17:35:43 +00:00
|
|
|
#ifdef G_OS_UNIX
|
2012-12-19 11:37:02 +00:00
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
#include <netinet/tcp.h>
|
2013-06-13 17:35:43 +00:00
|
|
|
#endif
|
2014-08-15 00:29:54 +00:00
|
|
|
#ifdef HAVE_GIO_UNIX
|
|
|
|
#include <gio/gunixsocketaddress.h>
|
|
|
|
#endif
|
2013-06-13 17:35:43 +00:00
|
|
|
#ifdef G_OS_WIN32
|
|
|
|
#include <windows.h>
|
|
|
|
#include <string.h>
|
|
|
|
#endif
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2021-02-04 19:09:56 +00:00
|
|
|
#if !GLIB_CHECK_VERSION (2, 67, 3)
|
|
|
|
# define g_memdup2(mem,size) g_memdup((mem), (size))
|
|
|
|
#endif
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
typedef struct {
|
|
|
|
int id;
|
|
|
|
guint32 tag;
|
|
|
|
} BroadwayOutstandingRoundtrip;
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
typedef struct BroadwayInput BroadwayInput;
|
2017-12-05 13:38:57 +00:00
|
|
|
typedef struct BroadwaySurface BroadwaySurface;
|
2012-12-23 22:35:03 +00:00
|
|
|
struct _BroadwayServer {
|
2012-12-19 11:37:02 +00:00
|
|
|
GObject parent_instance;
|
|
|
|
|
2013-01-10 20:38:15 +00:00
|
|
|
char *address;
|
2012-12-19 11:37:02 +00:00
|
|
|
int port;
|
2014-12-15 11:25:43 +00:00
|
|
|
char *ssl_cert;
|
|
|
|
char *ssl_key;
|
2012-12-19 11:37:02 +00:00
|
|
|
GSocketService *service;
|
|
|
|
BroadwayOutput *output;
|
|
|
|
guint32 id_counter;
|
|
|
|
guint32 saved_serial;
|
|
|
|
guint64 last_seen_time;
|
|
|
|
BroadwayInput *input;
|
|
|
|
GList *input_messages;
|
|
|
|
guint process_input_idle;
|
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
GHashTable *surface_id_hash;
|
2017-12-05 13:38:57 +00:00
|
|
|
GList *surfaces;
|
|
|
|
BroadwaySurface *root;
|
|
|
|
gint32 focused_surface_id; /* -1 => none */
|
2020-07-24 13:54:49 +00:00
|
|
|
int show_keyboard;
|
2013-01-08 16:56:39 +00:00
|
|
|
|
2017-11-18 15:47:43 +00:00
|
|
|
guint32 next_texture_id;
|
|
|
|
GHashTable *textures;
|
|
|
|
|
2020-03-12 10:12:01 +00:00
|
|
|
guint32 screen_scale;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
gint32 mouse_in_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
int last_x, last_y; /* in root coords */
|
|
|
|
guint32 last_state;
|
2017-12-05 13:38:57 +00:00
|
|
|
gint32 real_mouse_in_surface_id; /* Not affected by grabs */
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
/* Explicit pointer grabs: */
|
2017-12-05 13:38:57 +00:00
|
|
|
gint32 pointer_grab_surface_id; /* -1 => none */
|
2012-12-26 21:31:52 +00:00
|
|
|
gint32 pointer_grab_client_id; /* -1 => none */
|
2012-12-19 11:37:02 +00:00
|
|
|
guint32 pointer_grab_time;
|
|
|
|
gboolean pointer_grab_owner_events;
|
|
|
|
|
|
|
|
/* Future data, from the currently queued events */
|
|
|
|
int future_root_x;
|
|
|
|
int future_root_y;
|
|
|
|
guint32 future_state;
|
2017-12-05 13:38:57 +00:00
|
|
|
int future_mouse_in_surface;
|
2017-11-23 09:22:23 +00:00
|
|
|
|
|
|
|
GList *outstanding_roundtrips;
|
2012-12-19 11:37:02 +00:00
|
|
|
};
|
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
struct _BroadwayServerClass
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
GObjectClass parent_class;
|
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct HttpRequest {
|
2012-12-23 22:35:03 +00:00
|
|
|
BroadwayServer *server;
|
2014-12-15 11:25:43 +00:00
|
|
|
GSocketConnection *socket_connection;
|
|
|
|
GIOStream *connection;
|
2012-12-19 11:37:02 +00:00
|
|
|
GDataInputStream *data;
|
|
|
|
GString *request;
|
|
|
|
} HttpRequest;
|
|
|
|
|
|
|
|
struct BroadwayInput {
|
2012-12-23 22:35:03 +00:00
|
|
|
BroadwayServer *server;
|
2013-03-28 21:57:33 +00:00
|
|
|
BroadwayOutput *output;
|
2014-12-15 11:25:43 +00:00
|
|
|
GIOStream *connection;
|
2012-12-19 11:37:02 +00:00
|
|
|
GByteArray *buffer;
|
|
|
|
GSource *source;
|
|
|
|
gboolean seen_time;
|
|
|
|
gint64 time_base;
|
2013-03-28 21:57:33 +00:00
|
|
|
gboolean active;
|
2012-12-19 11:37:02 +00:00
|
|
|
};
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
struct BroadwaySurface {
|
2019-03-29 10:07:04 +00:00
|
|
|
guint32 owner;
|
2012-12-19 11:37:02 +00:00
|
|
|
gint32 id;
|
|
|
|
gint32 x;
|
|
|
|
gint32 y;
|
|
|
|
gint32 width;
|
|
|
|
gint32 height;
|
|
|
|
gboolean visible;
|
|
|
|
gint32 transient_for;
|
2017-11-18 19:36:57 +00:00
|
|
|
guint32 texture;
|
2017-11-29 18:08:37 +00:00
|
|
|
BroadwayNode *nodes;
|
2019-03-25 13:15:49 +00:00
|
|
|
GHashTable *node_lookup;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct _BroadwayTexture {
|
|
|
|
grefcount refcount;
|
|
|
|
guint32 id;
|
|
|
|
GBytes *bytes;
|
2013-01-08 16:56:39 +00:00
|
|
|
};
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
static void broadway_server_resync_surfaces (BroadwayServer *server);
|
2017-11-23 09:22:23 +00:00
|
|
|
static void send_outstanding_roundtrips (BroadwayServer *server);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2019-03-25 13:15:49 +00:00
|
|
|
static void broadway_server_ref_texture (BroadwayServer *server,
|
|
|
|
guint32 id);
|
|
|
|
|
2014-09-05 23:39:05 +00:00
|
|
|
static GType broadway_server_get_type (void);
|
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
G_DEFINE_TYPE (BroadwayServer, broadway_server, G_TYPE_OBJECT)
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-11-29 18:08:37 +00:00
|
|
|
static void
|
2019-03-25 13:15:49 +00:00
|
|
|
broadway_texture_free (BroadwayTexture *texture)
|
|
|
|
{
|
|
|
|
g_bytes_unref (texture->bytes);
|
|
|
|
g_free (texture);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadway_node_unref (BroadwayServer *server,
|
|
|
|
BroadwayNode *node)
|
2017-11-29 18:08:37 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
2019-03-25 13:15:49 +00:00
|
|
|
if (g_ref_count_dec (&node->refcount))
|
|
|
|
{
|
|
|
|
for (i = 0; i < node->n_children; i++)
|
|
|
|
broadway_node_unref (server, node->children[i]);
|
|
|
|
|
|
|
|
if (node->texture_id)
|
|
|
|
broadway_server_release_texture (server, node->texture_id);
|
|
|
|
|
|
|
|
g_free (node);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BroadwayNode *
|
|
|
|
broadway_node_ref (BroadwayNode *node)
|
|
|
|
{
|
|
|
|
g_ref_count_inc (&node->refcount);
|
|
|
|
|
|
|
|
return node;
|
2017-11-29 18:08:37 +00:00
|
|
|
}
|
|
|
|
|
2017-11-29 19:05:36 +00:00
|
|
|
gboolean
|
|
|
|
broadway_node_equal (BroadwayNode *a,
|
2017-11-30 09:36:30 +00:00
|
|
|
BroadwayNode *b)
|
2017-11-29 19:05:36 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (a->type != b->type)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (a->n_data != b->n_data)
|
|
|
|
return FALSE;
|
|
|
|
|
2017-11-30 09:36:30 +00:00
|
|
|
/* Don't check data for containers, that is just n_children, which
|
|
|
|
we don't want to compare for a shallow equal */
|
|
|
|
if (a->type != BROADWAY_NODE_CONTAINER)
|
|
|
|
{
|
|
|
|
for (i = 0; i < a->n_data; i++)
|
|
|
|
if (a->data[i] != b->data[i])
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
|
|
|
broadway_node_deep_equal (BroadwayNode *a,
|
|
|
|
BroadwayNode *b)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (a->hash != b->hash)
|
2017-11-29 19:05:36 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2017-11-30 09:36:30 +00:00
|
|
|
if (!broadway_node_equal (a,b))
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
if (a->n_children != b->n_children)
|
|
|
|
return FALSE;
|
2017-11-29 19:05:36 +00:00
|
|
|
|
|
|
|
for (i = 0; i < a->n_children; i++)
|
2017-11-30 09:36:30 +00:00
|
|
|
if (!broadway_node_deep_equal (a->children[i], b->children[i]))
|
2017-11-29 19:05:36 +00:00
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2017-11-29 18:08:37 +00:00
|
|
|
|
2017-11-30 09:36:30 +00:00
|
|
|
|
2019-03-28 15:03:42 +00:00
|
|
|
void
|
2019-03-28 18:17:01 +00:00
|
|
|
broadway_node_mark_deep_reused (BroadwayNode *node,
|
|
|
|
gboolean reused)
|
|
|
|
{
|
|
|
|
node->reused = reused;
|
|
|
|
for (int i = 0; i < node->n_children; i++)
|
|
|
|
broadway_node_mark_deep_reused (node->children[i], reused);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
broadway_node_mark_deep_consumed (BroadwayNode *node,
|
|
|
|
gboolean consumed)
|
2019-03-28 15:03:42 +00:00
|
|
|
{
|
2019-03-28 18:17:01 +00:00
|
|
|
node->consumed = consumed;
|
2019-03-28 15:03:42 +00:00
|
|
|
for (int i = 0; i < node->n_children; i++)
|
2019-03-28 18:17:01 +00:00
|
|
|
broadway_node_mark_deep_consumed (node->children[i], consumed);
|
2019-03-28 15:03:42 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
broadway_node_add_to_lookup (BroadwayNode *node,
|
|
|
|
GHashTable *node_lookup)
|
|
|
|
{
|
|
|
|
g_hash_table_insert (node_lookup, GINT_TO_POINTER(node->id), node);
|
|
|
|
for (int i = 0; i < node->n_children; i++)
|
|
|
|
broadway_node_add_to_lookup (node->children[i], node_lookup);
|
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_init (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *root;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
server->service = g_socket_service_new ();
|
2017-12-05 13:38:57 +00:00
|
|
|
server->pointer_grab_surface_id = -1;
|
2012-12-19 11:37:02 +00:00
|
|
|
server->saved_serial = 1;
|
|
|
|
server->last_seen_time = 1;
|
2017-12-05 15:10:06 +00:00
|
|
|
server->surface_id_hash = g_hash_table_new (NULL, NULL);
|
2012-12-19 11:37:02 +00:00
|
|
|
server->id_counter = 0;
|
2017-11-18 15:47:43 +00:00
|
|
|
server->textures = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
|
2019-03-25 13:15:49 +00:00
|
|
|
(GDestroyNotify)broadway_texture_free);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
root = g_new0 (BroadwaySurface, 1);
|
2012-12-19 11:37:02 +00:00
|
|
|
root->id = server->id_counter++;
|
|
|
|
root->width = 1024;
|
|
|
|
root->height = 768;
|
|
|
|
root->visible = TRUE;
|
|
|
|
|
2013-01-08 16:56:39 +00:00
|
|
|
server->root = root;
|
2020-03-12 10:12:01 +00:00
|
|
|
server->screen_scale = 1;
|
2013-01-08 16:56:39 +00:00
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
g_hash_table_insert (server->surface_id_hash,
|
2017-12-05 13:38:57 +00:00
|
|
|
GINT_TO_POINTER (root->id),
|
|
|
|
root);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_finalize (GObject *object)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2013-01-10 20:38:15 +00:00
|
|
|
BroadwayServer *server = BROADWAY_SERVER (object);
|
|
|
|
|
|
|
|
g_free (server->address);
|
2014-12-15 11:25:43 +00:00
|
|
|
g_free (server->ssl_cert);
|
|
|
|
g_free (server->ssl_key);
|
2017-11-18 15:47:43 +00:00
|
|
|
g_hash_table_destroy (server->textures);
|
2013-01-10 20:38:15 +00:00
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
G_OBJECT_CLASS (broadway_server_parent_class)->finalize (object);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_class_init (BroadwayServerClass * class)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
object_class->finalize = broadway_server_finalize;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-21 18:33:12 +00:00
|
|
|
static void
|
2019-03-25 13:15:49 +00:00
|
|
|
broadway_surface_free (BroadwayServer *server,
|
|
|
|
BroadwaySurface *surface)
|
2017-11-21 18:33:12 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface->nodes)
|
2019-03-25 13:15:49 +00:00
|
|
|
broadway_node_unref (server, surface->nodes);
|
|
|
|
g_hash_table_unref (surface->node_lookup);
|
2017-12-05 13:38:57 +00:00
|
|
|
g_free (surface);
|
2017-11-21 18:33:12 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
static BroadwaySurface *
|
|
|
|
broadway_server_lookup_surface (BroadwayServer *server,
|
|
|
|
guint32 id)
|
|
|
|
{
|
|
|
|
return g_hash_table_lookup (server->surface_id_hash,
|
|
|
|
GINT_TO_POINTER (id));
|
|
|
|
}
|
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
static void start (BroadwayInput *input);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
static void
|
|
|
|
http_request_free (HttpRequest *request)
|
|
|
|
{
|
2014-12-15 11:25:43 +00:00
|
|
|
g_object_unref (request->socket_connection);
|
2012-12-19 11:37:02 +00:00
|
|
|
g_object_unref (request->connection);
|
|
|
|
g_object_unref (request->data);
|
|
|
|
g_string_free (request->request, TRUE);
|
|
|
|
g_free (request);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadway_input_free (BroadwayInput *input)
|
|
|
|
{
|
|
|
|
g_object_unref (input->connection);
|
|
|
|
g_byte_array_free (input->buffer, FALSE);
|
|
|
|
g_source_destroy (input->source);
|
|
|
|
g_free (input);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
update_event_state (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwayInputMsg *message)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2013-01-08 16:33:29 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
switch (message->base.type) {
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_ENTER:
|
2012-12-19 11:37:02 +00:00
|
|
|
server->last_x = message->pointer.root_x;
|
|
|
|
server->last_y = message->pointer.root_y;
|
|
|
|
server->last_state = message->pointer.state;
|
2017-12-05 13:38:57 +00:00
|
|
|
server->real_mouse_in_surface_id = message->pointer.mouse_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
/* TODO: Unset when it dies */
|
2017-12-05 13:38:57 +00:00
|
|
|
server->mouse_in_surface_id = message->pointer.event_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_LEAVE:
|
2012-12-19 11:37:02 +00:00
|
|
|
server->last_x = message->pointer.root_x;
|
|
|
|
server->last_y = message->pointer.root_y;
|
|
|
|
server->last_state = message->pointer.state;
|
2017-12-05 13:38:57 +00:00
|
|
|
server->real_mouse_in_surface_id = message->pointer.mouse_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
server->mouse_in_surface_id = 0;
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_POINTER_MOVE:
|
2012-12-19 11:37:02 +00:00
|
|
|
server->last_x = message->pointer.root_x;
|
|
|
|
server->last_y = message->pointer.root_y;
|
|
|
|
server->last_state = message->pointer.state;
|
2017-12-05 13:38:57 +00:00
|
|
|
server->real_mouse_in_surface_id = message->pointer.mouse_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_BUTTON_PRESS:
|
|
|
|
case BROADWAY_EVENT_BUTTON_RELEASE:
|
2013-11-12 11:03:50 +00:00
|
|
|
if (message->base.type == BROADWAY_EVENT_BUTTON_PRESS &&
|
2017-12-05 13:38:57 +00:00
|
|
|
server->focused_surface_id != message->pointer.mouse_surface_id &&
|
|
|
|
server->pointer_grab_surface_id == -1)
|
2013-11-12 11:36:05 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_raise (server, message->pointer.mouse_surface_id);
|
|
|
|
broadway_server_focus_surface (server, message->pointer.mouse_surface_id);
|
2013-11-12 11:36:05 +00:00
|
|
|
broadway_server_flush (server);
|
|
|
|
}
|
2013-11-12 11:03:50 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
server->last_x = message->pointer.root_x;
|
|
|
|
server->last_y = message->pointer.root_y;
|
|
|
|
server->last_state = message->pointer.state;
|
2017-12-05 13:38:57 +00:00
|
|
|
server->real_mouse_in_surface_id = message->pointer.mouse_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_SCROLL:
|
2012-12-19 11:37:02 +00:00
|
|
|
server->last_x = message->pointer.root_x;
|
|
|
|
server->last_y = message->pointer.root_y;
|
|
|
|
server->last_state = message->pointer.state;
|
2017-12-05 13:38:57 +00:00
|
|
|
server->real_mouse_in_surface_id = message->pointer.mouse_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
2013-11-12 15:11:15 +00:00
|
|
|
case BROADWAY_EVENT_TOUCH:
|
2013-11-14 10:03:10 +00:00
|
|
|
if (message->touch.touch_type == 0 && message->touch.is_emulated &&
|
2017-12-05 13:38:57 +00:00
|
|
|
server->focused_surface_id != message->touch.event_surface_id)
|
2013-11-12 21:06:33 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_raise (server, message->touch.event_surface_id);
|
|
|
|
broadway_server_focus_surface (server, message->touch.event_surface_id);
|
2013-11-12 21:06:33 +00:00
|
|
|
broadway_server_flush (server);
|
|
|
|
}
|
|
|
|
|
2013-11-14 10:03:10 +00:00
|
|
|
if (message->touch.is_emulated)
|
|
|
|
{
|
|
|
|
server->last_x = message->pointer.root_x;
|
|
|
|
server->last_y = message->pointer.root_y;
|
|
|
|
}
|
|
|
|
|
2013-11-12 15:11:15 +00:00
|
|
|
server->last_state = message->touch.state;
|
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_KEY_PRESS:
|
|
|
|
case BROADWAY_EVENT_KEY_RELEASE:
|
2012-12-19 11:37:02 +00:00
|
|
|
server->last_state = message->key.state;
|
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_GRAB_NOTIFY:
|
|
|
|
case BROADWAY_EVENT_UNGRAB_NOTIFY:
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_CONFIGURE_NOTIFY:
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, message->configure_notify.id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface != NULL)
|
2013-01-08 16:33:29 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->x = message->configure_notify.x;
|
|
|
|
surface->y = message->configure_notify.y;
|
2013-01-08 16:33:29 +00:00
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
2017-11-23 09:22:23 +00:00
|
|
|
case BROADWAY_EVENT_ROUNDTRIP_NOTIFY:
|
|
|
|
break;
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_SCREEN_SIZE_CHANGED:
|
2013-01-08 16:56:39 +00:00
|
|
|
server->root->width = message->screen_resize_notify.width;
|
|
|
|
server->root->height = message->screen_resize_notify.height;
|
2020-03-12 10:12:01 +00:00
|
|
|
server->screen_scale = message->screen_resize_notify.scale;
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_printerr ("update_event_state - Unknown input command %c\n", message->base.type);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_lookahead_event (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
const char *types)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
BroadwayInputMsg *message;
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = server->input_messages; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
message = l->data;
|
|
|
|
if (strchr (types, message->base.type) != NULL)
|
2017-12-05 13:38:57 +00:00
|
|
|
return TRUE;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2012-12-26 21:31:52 +00:00
|
|
|
static gboolean
|
|
|
|
is_pointer_event (BroadwayInputMsg *message)
|
|
|
|
{
|
|
|
|
return
|
|
|
|
message->base.type == BROADWAY_EVENT_ENTER ||
|
|
|
|
message->base.type == BROADWAY_EVENT_LEAVE ||
|
|
|
|
message->base.type == BROADWAY_EVENT_POINTER_MOVE ||
|
|
|
|
message->base.type == BROADWAY_EVENT_BUTTON_PRESS ||
|
|
|
|
message->base.type == BROADWAY_EVENT_BUTTON_RELEASE ||
|
|
|
|
message->base.type == BROADWAY_EVENT_SCROLL ||
|
|
|
|
message->base.type == BROADWAY_EVENT_GRAB_NOTIFY ||
|
|
|
|
message->base.type == BROADWAY_EVENT_UNGRAB_NOTIFY;
|
|
|
|
}
|
|
|
|
|
2013-01-08 16:33:29 +00:00
|
|
|
static void
|
|
|
|
process_input_message (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwayInputMsg *message)
|
2013-01-08 16:33:29 +00:00
|
|
|
{
|
|
|
|
gint32 client;
|
2019-03-29 10:07:04 +00:00
|
|
|
BroadwaySurface *surface;
|
2013-01-08 16:33:29 +00:00
|
|
|
|
|
|
|
update_event_state (server, message);
|
2019-03-29 10:07:04 +00:00
|
|
|
|
|
|
|
|
|
|
|
switch (message->base.type) {
|
|
|
|
case BROADWAY_EVENT_ENTER:
|
|
|
|
case BROADWAY_EVENT_LEAVE:
|
|
|
|
case BROADWAY_EVENT_POINTER_MOVE:
|
|
|
|
case BROADWAY_EVENT_BUTTON_PRESS:
|
|
|
|
case BROADWAY_EVENT_BUTTON_RELEASE:
|
|
|
|
case BROADWAY_EVENT_SCROLL:
|
|
|
|
case BROADWAY_EVENT_GRAB_NOTIFY:
|
|
|
|
case BROADWAY_EVENT_UNGRAB_NOTIFY:
|
|
|
|
surface = broadway_server_lookup_surface (server, message->pointer.event_surface_id);
|
|
|
|
break;
|
|
|
|
case BROADWAY_EVENT_TOUCH:
|
|
|
|
surface = broadway_server_lookup_surface (server, message->touch.event_surface_id);
|
|
|
|
break;
|
|
|
|
case BROADWAY_EVENT_CONFIGURE_NOTIFY:
|
|
|
|
surface = broadway_server_lookup_surface (server, message->configure_notify.id);
|
|
|
|
break;
|
|
|
|
case BROADWAY_EVENT_ROUNDTRIP_NOTIFY:
|
|
|
|
surface = broadway_server_lookup_surface (server, message->roundtrip_notify.id);
|
|
|
|
break;
|
|
|
|
case BROADWAY_EVENT_KEY_PRESS:
|
|
|
|
case BROADWAY_EVENT_KEY_RELEASE:
|
|
|
|
/* TODO: Send to keys focused clients only... */
|
|
|
|
case BROADWAY_EVENT_FOCUS:
|
|
|
|
case BROADWAY_EVENT_SCREEN_SIZE_CHANGED:
|
|
|
|
default:
|
|
|
|
surface = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (surface)
|
|
|
|
client = surface->owner;
|
|
|
|
else
|
|
|
|
client = -1;
|
|
|
|
|
2013-01-08 16:33:29 +00:00
|
|
|
if (is_pointer_event (message) &&
|
2017-12-05 13:38:57 +00:00
|
|
|
server->pointer_grab_surface_id != -1)
|
2013-01-08 16:33:29 +00:00
|
|
|
client = server->pointer_grab_client_id;
|
|
|
|
|
|
|
|
broadway_events_got_input (message, client);
|
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
process_input_messages (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
BroadwayInputMsg *message;
|
|
|
|
|
|
|
|
while (server->input_messages)
|
|
|
|
{
|
|
|
|
message = server->input_messages->data;
|
|
|
|
server->input_messages =
|
2017-12-05 13:38:57 +00:00
|
|
|
g_list_delete_link (server->input_messages,
|
|
|
|
server->input_messages);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-01-08 09:14:41 +00:00
|
|
|
if (message->base.serial == 0)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
/* This was sent before we got any requests, but we don't want the
|
|
|
|
daemon serials to go backwards, so we fix it up to be the last used
|
|
|
|
serial */
|
|
|
|
message->base.serial = server->saved_serial - 1;
|
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-01-08 16:33:29 +00:00
|
|
|
process_input_message (server, message);
|
2012-12-19 11:37:02 +00:00
|
|
|
g_free (message);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-01-08 16:33:29 +00:00
|
|
|
static void
|
|
|
|
fake_configure_notify (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface)
|
2013-01-08 16:33:29 +00:00
|
|
|
{
|
|
|
|
BroadwayInputMsg ev = { {0} };
|
|
|
|
|
|
|
|
ev.base.type = BROADWAY_EVENT_CONFIGURE_NOTIFY;
|
|
|
|
ev.base.serial = server->saved_serial - 1;
|
|
|
|
ev.base.time = server->last_seen_time;
|
2017-12-05 13:38:57 +00:00
|
|
|
ev.configure_notify.id = surface->id;
|
|
|
|
ev.configure_notify.x = surface->x;
|
|
|
|
ev.configure_notify.y = surface->y;
|
|
|
|
ev.configure_notify.width = surface->width;
|
|
|
|
ev.configure_notify.height = surface->height;
|
2013-01-08 16:33:29 +00:00
|
|
|
|
|
|
|
process_input_message (server, &ev);
|
|
|
|
}
|
|
|
|
|
2013-09-26 16:21:08 +00:00
|
|
|
static guint32 *
|
|
|
|
parse_pointer_data (guint32 *p, BroadwayInputPointerMsg *data)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
data->mouse_surface_id = ntohl (*p++);
|
|
|
|
data->event_surface_id = ntohl (*p++);
|
2013-10-30 23:43:58 +00:00
|
|
|
data->root_x = ntohl (*p++);
|
|
|
|
data->root_y = ntohl (*p++);
|
|
|
|
data->win_x = ntohl (*p++);
|
|
|
|
data->win_y = ntohl (*p++);
|
|
|
|
data->state = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2013-11-12 15:11:15 +00:00
|
|
|
static guint32 *
|
|
|
|
parse_touch_data (guint32 *p, BroadwayInputTouchMsg *data)
|
|
|
|
{
|
|
|
|
data->touch_type = ntohl (*p++);
|
2017-12-05 13:38:57 +00:00
|
|
|
data->event_surface_id = ntohl (*p++);
|
2013-11-12 15:11:15 +00:00
|
|
|
data->sequence_id = ntohl (*p++);
|
2013-11-14 10:03:10 +00:00
|
|
|
data->is_emulated = ntohl (*p++);
|
2013-11-12 15:11:15 +00:00
|
|
|
data->root_x = ntohl (*p++);
|
|
|
|
data->root_y = ntohl (*p++);
|
|
|
|
data->win_x = ntohl (*p++);
|
|
|
|
data->win_y = ntohl (*p++);
|
|
|
|
data->state = ntohl (*p++);
|
|
|
|
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
update_future_pointer_info (BroadwayServer *server, BroadwayInputPointerMsg *data)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
server->future_root_x = data->root_x;
|
|
|
|
server->future_root_y = data->root_y;
|
|
|
|
server->future_state = data->state;
|
2017-12-05 13:38:57 +00:00
|
|
|
server->future_mouse_in_surface = data->mouse_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
static void
|
|
|
|
queue_input_message (BroadwayServer *server, BroadwayInputMsg *msg)
|
|
|
|
{
|
2021-02-04 19:09:56 +00:00
|
|
|
server->input_messages = g_list_append (server->input_messages, g_memdup2 (msg, sizeof (BroadwayInputMsg)));
|
2017-11-23 09:22:23 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
static void
|
2013-10-31 16:19:59 +00:00
|
|
|
parse_input_message (BroadwayInput *input, const unsigned char *message)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2012-12-23 22:35:03 +00:00
|
|
|
BroadwayServer *server = input->server;
|
2012-12-19 11:37:02 +00:00
|
|
|
BroadwayInputMsg msg;
|
2013-09-26 16:21:08 +00:00
|
|
|
guint32 *p;
|
2012-12-19 11:37:02 +00:00
|
|
|
gint64 time_;
|
2017-11-23 09:22:23 +00:00
|
|
|
GList *l;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-01-08 16:33:29 +00:00
|
|
|
memset (&msg, 0, sizeof (msg));
|
|
|
|
|
2013-09-26 16:21:08 +00:00
|
|
|
p = (guint32 *) message;
|
|
|
|
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.base.type = ntohl (*p++);
|
|
|
|
msg.base.serial = ntohl (*p++);
|
2019-03-29 10:44:46 +00:00
|
|
|
|
2013-10-30 23:43:58 +00:00
|
|
|
time_ = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (time_ == 0) {
|
|
|
|
time_ = server->last_seen_time;
|
|
|
|
} else {
|
|
|
|
if (!input->seen_time) {
|
|
|
|
input->seen_time = TRUE;
|
|
|
|
/* Calculate time base so that any following times are normalized to start
|
2017-12-05 13:38:57 +00:00
|
|
|
5 seconds after last_seen_time, to avoid issues that could appear when
|
|
|
|
a long hiatus due to a reconnect seems to be instant */
|
2012-12-19 11:37:02 +00:00
|
|
|
input->time_base = time_ - (server->last_seen_time + 5000);
|
|
|
|
}
|
|
|
|
time_ = time_ - input->time_base;
|
|
|
|
}
|
|
|
|
|
|
|
|
server->last_seen_time = time_;
|
|
|
|
|
|
|
|
msg.base.time = time_;
|
|
|
|
|
|
|
|
switch (msg.base.type) {
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_ENTER:
|
|
|
|
case BROADWAY_EVENT_LEAVE:
|
2012-12-19 11:37:02 +00:00
|
|
|
p = parse_pointer_data (p, &msg.pointer);
|
|
|
|
update_future_pointer_info (server, &msg.pointer);
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.crossing.mode = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_POINTER_MOVE: /* Mouse move */
|
2012-12-19 11:37:02 +00:00
|
|
|
p = parse_pointer_data (p, &msg.pointer);
|
|
|
|
update_future_pointer_info (server, &msg.pointer);
|
|
|
|
break;
|
|
|
|
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_BUTTON_PRESS:
|
|
|
|
case BROADWAY_EVENT_BUTTON_RELEASE:
|
2012-12-19 11:37:02 +00:00
|
|
|
p = parse_pointer_data (p, &msg.pointer);
|
|
|
|
update_future_pointer_info (server, &msg.pointer);
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.button.button = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_SCROLL:
|
2012-12-19 11:37:02 +00:00
|
|
|
p = parse_pointer_data (p, &msg.pointer);
|
|
|
|
update_future_pointer_info (server, &msg.pointer);
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.scroll.dir = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
2013-11-12 15:11:15 +00:00
|
|
|
case BROADWAY_EVENT_TOUCH:
|
|
|
|
p = parse_touch_data (p, &msg.touch);
|
|
|
|
break;
|
|
|
|
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_KEY_PRESS:
|
|
|
|
case BROADWAY_EVENT_KEY_RELEASE:
|
2017-12-05 13:38:57 +00:00
|
|
|
msg.key.surface_id = server->focused_surface_id;
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.key.key = ntohl (*p++);
|
|
|
|
msg.key.state = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_GRAB_NOTIFY:
|
|
|
|
case BROADWAY_EVENT_UNGRAB_NOTIFY:
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.grab_reply.res = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_CONFIGURE_NOTIFY:
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.configure_notify.id = ntohl (*p++);
|
|
|
|
msg.configure_notify.x = ntohl (*p++);
|
|
|
|
msg.configure_notify.y = ntohl (*p++);
|
|
|
|
msg.configure_notify.width = ntohl (*p++);
|
|
|
|
msg.configure_notify.height = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
case BROADWAY_EVENT_ROUNDTRIP_NOTIFY:
|
|
|
|
msg.roundtrip_notify.id = ntohl (*p++);
|
|
|
|
msg.roundtrip_notify.tag = ntohl (*p++);
|
|
|
|
msg.roundtrip_notify.local = FALSE;
|
|
|
|
|
|
|
|
/* Remove matched outstanding roundtrips */
|
|
|
|
for (l = server->outstanding_roundtrips; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
BroadwayOutstandingRoundtrip *rt = l->data;
|
|
|
|
|
|
|
|
if (rt->id == msg.roundtrip_notify.id &&
|
|
|
|
rt->tag == msg.roundtrip_notify.tag)
|
2019-03-29 10:07:21 +00:00
|
|
|
break;
|
2017-11-23 09:22:23 +00:00
|
|
|
}
|
2019-03-29 10:07:21 +00:00
|
|
|
|
|
|
|
if (l == NULL)
|
2020-08-21 12:41:13 +00:00
|
|
|
g_warning ("Got unexpected roundtrip reply for id %d, tag %d\n", msg.roundtrip_notify.id, msg.roundtrip_notify.tag);
|
2019-03-29 10:07:21 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
BroadwayOutstandingRoundtrip *rt = l->data;
|
|
|
|
|
|
|
|
server->outstanding_roundtrips = g_list_delete_link (server->outstanding_roundtrips, l);
|
|
|
|
g_free (rt);
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
break;
|
|
|
|
|
2012-12-20 12:40:31 +00:00
|
|
|
case BROADWAY_EVENT_SCREEN_SIZE_CHANGED:
|
2013-10-30 23:43:58 +00:00
|
|
|
msg.screen_resize_notify.width = ntohl (*p++);
|
|
|
|
msg.screen_resize_notify.height = ntohl (*p++);
|
2020-03-12 10:12:01 +00:00
|
|
|
msg.screen_resize_notify.scale = ntohl (*p++);
|
2012-12-19 11:37:02 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_printerr ("parse_input_message - Unknown input command %c (%s)\n", msg.base.type, message);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
queue_input_message (server, &msg);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline void
|
|
|
|
hex_dump (guchar *data, gsize len)
|
|
|
|
{
|
|
|
|
#ifdef DEBUG_WEBSOCKETS
|
|
|
|
gsize i, j;
|
|
|
|
for (j = 0; j < len + 15; j += 16)
|
|
|
|
{
|
|
|
|
fprintf (stderr, "0x%.4x ", j);
|
|
|
|
for (i = 0; i < 16; i++)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
if ((j + i) < len)
|
|
|
|
fprintf (stderr, "%.2x ", data[j+i]);
|
|
|
|
else
|
|
|
|
fprintf (stderr, " ");
|
|
|
|
if (i == 8)
|
|
|
|
fprintf (stderr, " ");
|
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
fprintf (stderr, " | ");
|
|
|
|
|
|
|
|
for (i = 0; i < 16; i++)
|
2017-12-05 13:38:57 +00:00
|
|
|
if ((j + i) < len && g_ascii_isalnum(data[j+i]))
|
|
|
|
fprintf (stderr, "%c", data[j+i]);
|
|
|
|
else
|
|
|
|
fprintf (stderr, ".");
|
2012-12-19 11:37:02 +00:00
|
|
|
fprintf (stderr, "\n");
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
parse_input (BroadwayInput *input)
|
|
|
|
{
|
|
|
|
if (!input->buffer->len)
|
|
|
|
return;
|
|
|
|
|
2013-09-25 15:59:40 +00:00
|
|
|
hex_dump (input->buffer->data, input->buffer->len);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-09-25 15:59:40 +00:00
|
|
|
while (input->buffer->len > 2)
|
|
|
|
{
|
|
|
|
gsize len, payload_len;
|
|
|
|
BroadwayWSOpCode code;
|
|
|
|
gboolean is_mask, fin;
|
|
|
|
guchar *buf, *data, *mask;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-09-25 15:59:40 +00:00
|
|
|
buf = input->buffer->data;
|
|
|
|
len = input->buffer->len;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_WEBSOCKETS
|
2013-09-25 15:59:40 +00:00
|
|
|
g_print ("Parse input first byte 0x%2x 0x%2x\n", buf[0], buf[1]);
|
2012-12-19 11:37:02 +00:00
|
|
|
#endif
|
|
|
|
|
2013-09-25 15:59:40 +00:00
|
|
|
fin = buf[0] & 0x80;
|
|
|
|
code = buf[0] & 0x0f;
|
|
|
|
payload_len = buf[1] & 0x7f;
|
|
|
|
is_mask = buf[1] & 0x80;
|
|
|
|
data = buf + 2;
|
|
|
|
|
2016-03-20 04:50:53 +00:00
|
|
|
if (payload_len == 126)
|
2013-09-25 15:59:40 +00:00
|
|
|
{
|
|
|
|
if (len < 4)
|
|
|
|
return;
|
|
|
|
payload_len = GUINT16_FROM_BE( *(guint16 *) data );
|
|
|
|
data += 2;
|
|
|
|
}
|
2016-03-20 04:50:53 +00:00
|
|
|
else if (payload_len == 127)
|
2013-09-25 15:59:40 +00:00
|
|
|
{
|
|
|
|
if (len < 10)
|
|
|
|
return;
|
|
|
|
payload_len = GUINT64_FROM_BE( *(guint64 *) data );
|
|
|
|
data += 8;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask = NULL;
|
|
|
|
if (is_mask)
|
|
|
|
{
|
|
|
|
if (data - buf + 4 > len)
|
|
|
|
return;
|
|
|
|
mask = data;
|
|
|
|
data += 4;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data - buf + payload_len > len)
|
|
|
|
return; /* wait to accumulate more */
|
|
|
|
|
|
|
|
if (is_mask)
|
|
|
|
{
|
|
|
|
gsize i;
|
|
|
|
for (i = 0; i < payload_len; i++)
|
|
|
|
data[i] ^= mask[i%4];
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (code) {
|
|
|
|
case BROADWAY_WS_CNX_CLOSE:
|
|
|
|
break; /* hang around anyway */
|
2013-09-26 16:21:08 +00:00
|
|
|
case BROADWAY_WS_BINARY:
|
2013-09-25 15:59:40 +00:00
|
|
|
if (!fin)
|
|
|
|
{
|
2012-12-19 11:37:02 +00:00
|
|
|
#ifdef DEBUG_WEBSOCKETS
|
2013-09-25 15:59:40 +00:00
|
|
|
g_warning ("can't yet accept fragmented input");
|
2012-12-19 11:37:02 +00:00
|
|
|
#endif
|
2013-09-25 15:59:40 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-11-05 16:13:57 +00:00
|
|
|
parse_input_message (input, data);
|
2013-09-25 15:59:40 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BROADWAY_WS_CNX_PING:
|
|
|
|
broadway_output_pong (input->output);
|
|
|
|
break;
|
|
|
|
case BROADWAY_WS_CNX_PONG:
|
|
|
|
break; /* we never send pings, but tolerate pongs */
|
2013-09-26 16:21:08 +00:00
|
|
|
case BROADWAY_WS_TEXT:
|
2013-09-25 15:59:40 +00:00
|
|
|
case BROADWAY_WS_CONTINUATION:
|
|
|
|
default:
|
|
|
|
{
|
|
|
|
g_warning ("fragmented or unknown input code 0x%2x with fin set", code);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-09-25 15:59:40 +00:00
|
|
|
g_byte_array_remove_range (input->buffer, 0, data - buf + payload_len);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
2012-12-23 22:35:03 +00:00
|
|
|
process_input_idle_cb (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
server->process_input_idle = 0;
|
|
|
|
process_input_messages (server);
|
|
|
|
return G_SOURCE_REMOVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
queue_process_input_at_idle (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
if (server->process_input_idle == 0)
|
|
|
|
server->process_input_idle =
|
|
|
|
g_idle_add_full (G_PRIORITY_DEFAULT, (GSourceFunc)process_input_idle_cb, server, NULL);
|
|
|
|
}
|
|
|
|
|
2015-07-23 15:13:54 +00:00
|
|
|
static gboolean
|
2013-03-28 21:57:33 +00:00
|
|
|
broadway_server_read_all_input_nonblocking (BroadwayInput *input)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
GInputStream *in;
|
|
|
|
gssize res;
|
|
|
|
guint8 buffer[1024];
|
2014-12-15 11:25:43 +00:00
|
|
|
GError *error = NULL;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
if (input == NULL)
|
2015-07-23 15:13:54 +00:00
|
|
|
return FALSE;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2014-12-15 11:25:43 +00:00
|
|
|
in = g_io_stream_get_input_stream (input->connection);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
res = g_pollable_input_stream_read_nonblocking (G_POLLABLE_INPUT_STREAM (in),
|
2017-12-05 13:38:57 +00:00
|
|
|
buffer, sizeof (buffer), NULL, &error);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (res <= 0)
|
|
|
|
{
|
|
|
|
if (res < 0 &&
|
2017-12-05 13:38:57 +00:00
|
|
|
g_error_matches (error, G_IO_ERROR, G_IO_ERROR_WOULD_BLOCK))
|
|
|
|
{
|
|
|
|
g_error_free (error);
|
|
|
|
return TRUE;
|
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
if (input->server->input == input)
|
2017-11-23 09:22:23 +00:00
|
|
|
{
|
|
|
|
send_outstanding_roundtrips (input->server);
|
|
|
|
|
|
|
|
input->server->input = NULL;
|
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
broadway_input_free (input);
|
|
|
|
if (res < 0)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
g_printerr ("input error %s\n", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
}
|
2015-07-23 15:13:54 +00:00
|
|
|
return FALSE;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_byte_array_append (input->buffer, buffer, res);
|
|
|
|
|
|
|
|
parse_input (input);
|
2015-07-23 15:13:54 +00:00
|
|
|
return TRUE;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_consume_all_input (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2013-03-28 21:57:33 +00:00
|
|
|
broadway_server_read_all_input_nonblocking (server->input);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
/* Since we're parsing input but not processing the resulting messages
|
|
|
|
we might not get a readable callback on the stream, so queue an idle to
|
|
|
|
process the messages */
|
|
|
|
queue_process_input_at_idle (server);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
input_data_cb (GObject *stream,
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwayInput *input)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2012-12-23 22:35:03 +00:00
|
|
|
BroadwayServer *server = input->server;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2015-07-23 15:13:54 +00:00
|
|
|
if (!broadway_server_read_all_input_nonblocking (input))
|
|
|
|
return FALSE;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
if (input->active)
|
|
|
|
process_input_messages (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2013-01-08 09:14:41 +00:00
|
|
|
guint32
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_get_next_serial (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
if (server->output)
|
|
|
|
return broadway_output_get_next_serial (server->output);
|
|
|
|
|
|
|
|
return server->saved_serial;
|
|
|
|
}
|
|
|
|
|
2013-01-08 16:56:39 +00:00
|
|
|
void
|
|
|
|
broadway_server_get_screen_size (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
guint32 *width,
|
2020-03-12 10:12:01 +00:00
|
|
|
guint32 *height,
|
|
|
|
guint32 *scale)
|
2013-01-08 16:56:39 +00:00
|
|
|
{
|
|
|
|
*width = server->root->width;
|
|
|
|
*height = server->root->height;
|
2020-03-12 10:12:01 +00:00
|
|
|
*scale = server->screen_scale;
|
2013-01-08 16:56:39 +00:00
|
|
|
}
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
static void
|
|
|
|
broadway_server_fake_roundtrip_reply (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id,
|
2017-11-23 09:22:23 +00:00
|
|
|
guint32 tag)
|
|
|
|
{
|
|
|
|
BroadwayInputMsg msg;
|
|
|
|
|
|
|
|
msg.base.type = BROADWAY_EVENT_ROUNDTRIP_NOTIFY;
|
|
|
|
msg.base.serial = 0;
|
|
|
|
msg.base.time = server->last_seen_time;
|
|
|
|
msg.roundtrip_notify.id = id;
|
|
|
|
msg.roundtrip_notify.tag = tag;
|
|
|
|
msg.roundtrip_notify.local = 1;
|
|
|
|
|
|
|
|
queue_input_message (server, &msg);
|
|
|
|
queue_process_input_at_idle (server);
|
|
|
|
}
|
2013-01-08 16:56:39 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
void
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_flush (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
if (server->output &&
|
|
|
|
!broadway_output_flush (server->output))
|
|
|
|
{
|
|
|
|
server->saved_serial = broadway_output_get_next_serial (server->output);
|
|
|
|
broadway_output_free (server->output);
|
|
|
|
server->output = NULL;
|
2017-11-23 09:22:23 +00:00
|
|
|
send_outstanding_roundtrips (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
void
|
|
|
|
broadway_server_roundtrip (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id,
|
2017-11-23 09:22:23 +00:00
|
|
|
guint32 tag)
|
|
|
|
{
|
|
|
|
if (server->output)
|
|
|
|
{
|
|
|
|
BroadwayOutstandingRoundtrip *rt = g_new0 (BroadwayOutstandingRoundtrip, 1);
|
|
|
|
rt->id = id;
|
|
|
|
rt->tag = tag;
|
|
|
|
server->outstanding_roundtrips = g_list_prepend (server->outstanding_roundtrips, rt);
|
|
|
|
|
|
|
|
broadway_output_roundtrip (server->output, id, tag);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
broadway_server_fake_roundtrip_reply (server, id, tag);
|
|
|
|
}
|
|
|
|
|
2017-10-06 14:01:19 +00:00
|
|
|
static const char *
|
|
|
|
parse_line (const char *line, const char *key)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-10-06 14:01:19 +00:00
|
|
|
const char *p;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2020-11-27 10:34:09 +00:00
|
|
|
if (g_ascii_strncasecmp (line, key, strlen (key)) != 0)
|
2012-12-19 11:37:02 +00:00
|
|
|
return NULL;
|
|
|
|
p = line + strlen (key);
|
|
|
|
if (*p != ':')
|
|
|
|
return NULL;
|
|
|
|
p++;
|
|
|
|
/* Skip optional initial space */
|
|
|
|
if (*p == ' ')
|
|
|
|
p++;
|
|
|
|
return p;
|
|
|
|
}
|
2013-06-13 17:35:43 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
static void
|
|
|
|
send_error (HttpRequest *request,
|
2017-12-05 13:38:57 +00:00
|
|
|
int error_code,
|
|
|
|
const char *reason)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
res = g_strdup_printf ("HTTP/1.0 %d %s\r\n\r\n"
|
2017-12-05 13:38:57 +00:00
|
|
|
"<html><head><title>%d %s</title></head>"
|
|
|
|
"<body>%s</body></html>",
|
|
|
|
error_code, reason,
|
|
|
|
error_code, reason,
|
|
|
|
reason);
|
2014-12-15 11:25:43 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
/* TODO: This should really be async */
|
2014-12-15 11:25:43 +00:00
|
|
|
g_output_stream_write_all (g_io_stream_get_output_stream (request->connection),
|
|
|
|
res, strlen (res), NULL, NULL, NULL);
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
g_free (res);
|
|
|
|
http_request_free (request);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* magic from: http://tools.ietf.org/html/draft-ietf-hybi-thewebsocketprotocol-17 */
|
|
|
|
#define SEC_WEB_SOCKET_KEY_MAGIC "258EAFA5-E914-47DA-95CA-C5AB0DC85B11"
|
|
|
|
|
|
|
|
/* 'x3JJHMbDL1EzLkh9GBhXDw==' generates 'HSmrc0sMlYUkAGmm5OPpG2HaGWk=' */
|
2020-07-24 18:40:36 +00:00
|
|
|
static char *
|
|
|
|
generate_handshake_response_wsietf_v7 (const char *key)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
gsize digest_len = 20;
|
2013-07-01 12:51:03 +00:00
|
|
|
guchar digest[20];
|
2012-12-19 11:37:02 +00:00
|
|
|
GChecksum *checksum;
|
|
|
|
|
|
|
|
checksum = g_checksum_new (G_CHECKSUM_SHA1);
|
|
|
|
if (!checksum)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
g_checksum_update (checksum, (guchar *)key, -1);
|
|
|
|
g_checksum_update (checksum, (guchar *)SEC_WEB_SOCKET_KEY_MAGIC, -1);
|
|
|
|
|
|
|
|
g_checksum_get_digest (checksum, digest, &digest_len);
|
|
|
|
g_checksum_free (checksum);
|
|
|
|
|
|
|
|
g_assert (digest_len == 20);
|
|
|
|
|
|
|
|
return g_base64_encode (digest, digest_len);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2013-09-25 15:59:40 +00:00
|
|
|
start_input (HttpRequest *request)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
char **lines;
|
2017-10-06 14:01:19 +00:00
|
|
|
const char *p;
|
2012-12-19 11:37:02 +00:00
|
|
|
int i;
|
|
|
|
char *res;
|
2017-10-06 14:01:19 +00:00
|
|
|
const char *origin, *host;
|
2012-12-19 11:37:02 +00:00
|
|
|
BroadwayInput *input;
|
|
|
|
const void *data_buffer;
|
|
|
|
gsize data_buffer_size;
|
|
|
|
GInputStream *in;
|
2017-10-06 14:01:19 +00:00
|
|
|
const char *key;
|
2013-03-28 21:57:33 +00:00
|
|
|
GSocket *socket;
|
|
|
|
int flag = 1;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
#ifdef DEBUG_WEBSOCKETS
|
|
|
|
g_print ("incoming request:\n%s\n", request->request->str);
|
|
|
|
#endif
|
|
|
|
lines = g_strsplit (request->request->str, "\n", 0);
|
|
|
|
|
2013-09-25 15:59:40 +00:00
|
|
|
key = NULL;
|
2012-12-19 11:37:02 +00:00
|
|
|
origin = NULL;
|
|
|
|
host = NULL;
|
|
|
|
for (i = 0; lines[i] != NULL; i++)
|
|
|
|
{
|
2013-09-25 15:59:40 +00:00
|
|
|
if ((p = parse_line (lines[i], "Sec-WebSocket-Key")))
|
|
|
|
key = p;
|
2012-12-19 11:37:02 +00:00
|
|
|
else if ((p = parse_line (lines[i], "Origin")))
|
2013-09-25 15:59:40 +00:00
|
|
|
origin = p;
|
2012-12-19 11:37:02 +00:00
|
|
|
else if ((p = parse_line (lines[i], "Host")))
|
2013-09-25 15:59:40 +00:00
|
|
|
host = p;
|
2012-12-19 11:37:02 +00:00
|
|
|
else if ((p = parse_line (lines[i], "Sec-WebSocket-Origin")))
|
2013-09-25 15:59:40 +00:00
|
|
|
origin = p;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2013-01-10 21:50:03 +00:00
|
|
|
if (host == NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
g_strfreev (lines);
|
|
|
|
send_error (request, 400, "Bad websocket request");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-25 15:59:40 +00:00
|
|
|
if (key != NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2013-09-25 15:59:40 +00:00
|
|
|
char* accept = generate_handshake_response_wsietf_v7 (key);
|
2012-12-19 11:37:02 +00:00
|
|
|
res = g_strdup_printf ("HTTP/1.1 101 Switching Protocols\r\n"
|
2017-12-05 13:38:57 +00:00
|
|
|
"Upgrade: websocket\r\n"
|
|
|
|
"Connection: Upgrade\r\n"
|
|
|
|
"Sec-WebSocket-Accept: %s\r\n"
|
|
|
|
"%s%s%s"
|
|
|
|
"Sec-WebSocket-Location: ws://%s/socket\r\n"
|
|
|
|
"Sec-WebSocket-Protocol: broadway\r\n"
|
|
|
|
"\r\n", accept,
|
|
|
|
origin?"Sec-WebSocket-Origin: ":"", origin?origin:"", origin?"\r\n":"",
|
|
|
|
host);
|
2012-12-19 11:37:02 +00:00
|
|
|
g_free (accept);
|
|
|
|
|
|
|
|
#ifdef DEBUG_WEBSOCKETS
|
|
|
|
g_print ("v7 proto response:\n%s", res);
|
|
|
|
#endif
|
|
|
|
|
2014-12-15 11:25:43 +00:00
|
|
|
g_output_stream_write_all (g_io_stream_get_output_stream (request->connection),
|
|
|
|
res, strlen (res), NULL, NULL, NULL);
|
2012-12-19 11:37:02 +00:00
|
|
|
g_free (res);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-09-25 15:59:40 +00:00
|
|
|
g_strfreev (lines);
|
|
|
|
send_error (request, 400, "Bad websocket request");
|
|
|
|
return;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2014-12-15 11:25:43 +00:00
|
|
|
socket = g_socket_connection_get_socket (request->socket_connection);
|
2013-03-28 21:57:33 +00:00
|
|
|
setsockopt (g_socket_get_fd (socket), IPPROTO_TCP,
|
2017-12-05 13:38:57 +00:00
|
|
|
TCP_NODELAY, (char *) &flag, sizeof(int));
|
2012-12-19 20:58:25 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
input = g_new0 (BroadwayInput, 1);
|
|
|
|
input->server = request->server;
|
|
|
|
input->connection = g_object_ref (request->connection);
|
|
|
|
|
|
|
|
data_buffer = g_buffered_input_stream_peek_buffer (G_BUFFERED_INPUT_STREAM (request->data), &data_buffer_size);
|
|
|
|
input->buffer = g_byte_array_sized_new (data_buffer_size);
|
|
|
|
g_byte_array_append (input->buffer, data_buffer, data_buffer_size);
|
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
input->output =
|
2014-12-15 11:25:43 +00:00
|
|
|
broadway_output_new (g_io_stream_get_output_stream (request->connection), 0);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
/* This will free and close the data input stream, but we got all the buffered content already */
|
|
|
|
http_request_free (request);
|
|
|
|
|
2014-12-15 11:25:43 +00:00
|
|
|
in = g_io_stream_get_input_stream (input->connection);
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
input->source = g_pollable_input_stream_create_source (G_POLLABLE_INPUT_STREAM (in), NULL);
|
|
|
|
g_source_set_callback (input->source, (GSourceFunc)input_data_cb, input, NULL);
|
|
|
|
g_source_attach (input->source, NULL);
|
|
|
|
|
2013-09-26 18:04:34 +00:00
|
|
|
start (input);
|
2013-03-28 21:57:33 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
/* Process any data in the pipe already */
|
|
|
|
parse_input (input);
|
|
|
|
|
|
|
|
g_strfreev (lines);
|
|
|
|
}
|
|
|
|
|
2017-11-23 09:22:23 +00:00
|
|
|
static void
|
|
|
|
send_outstanding_roundtrips (BroadwayServer *server)
|
|
|
|
{
|
|
|
|
GList *l;
|
|
|
|
|
|
|
|
for (l = server->outstanding_roundtrips; l != NULL; l = l->next)
|
|
|
|
{
|
|
|
|
BroadwayOutstandingRoundtrip *rt = l->data;
|
|
|
|
broadway_server_fake_roundtrip_reply (server, rt->id, rt->tag);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_list_free_full (server->outstanding_roundtrips, g_free);
|
|
|
|
server->outstanding_roundtrips = NULL;
|
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
static void
|
2013-03-28 21:57:33 +00:00
|
|
|
start (BroadwayInput *input)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2012-12-23 22:35:03 +00:00
|
|
|
BroadwayServer *server;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
input->active = TRUE;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
server = BROADWAY_SERVER (input->server);
|
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
{
|
2017-11-23 09:22:23 +00:00
|
|
|
send_outstanding_roundtrips (server);
|
2013-03-28 21:57:33 +00:00
|
|
|
broadway_output_disconnected (server->output);
|
|
|
|
broadway_output_flush (server->output);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (server->input != NULL)
|
|
|
|
{
|
2017-11-23 09:22:23 +00:00
|
|
|
send_outstanding_roundtrips (server);
|
2013-03-28 21:57:33 +00:00
|
|
|
broadway_input_free (server->input);
|
|
|
|
server->input = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
server->input = input;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
{
|
|
|
|
server->saved_serial = broadway_output_get_next_serial (server->output);
|
|
|
|
broadway_output_free (server->output);
|
|
|
|
}
|
2013-03-28 21:57:33 +00:00
|
|
|
server->output = input->output;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-03-28 21:57:33 +00:00
|
|
|
broadway_output_set_next_serial (server->output, server->saved_serial);
|
|
|
|
broadway_output_flush (server->output);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_resync_surfaces (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->pointer_grab_surface_id != -1)
|
2012-12-19 11:37:02 +00:00
|
|
|
broadway_output_grab_pointer (server->output,
|
2017-12-05 13:38:57 +00:00
|
|
|
server->pointer_grab_surface_id,
|
|
|
|
server->pointer_grab_owner_events);
|
2013-03-28 21:57:33 +00:00
|
|
|
|
|
|
|
process_input_messages (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
send_data (HttpRequest *request,
|
2017-12-05 13:38:57 +00:00
|
|
|
const char *mimetype,
|
|
|
|
const char *data, gsize len)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
res = g_strdup_printf ("HTTP/1.0 200 OK\r\n"
|
2017-12-05 13:38:57 +00:00
|
|
|
"Content-Type: %s\r\n"
|
|
|
|
"Content-Length: %"G_GSIZE_FORMAT"\r\n"
|
|
|
|
"\r\n",
|
|
|
|
mimetype, len);
|
2014-12-15 11:25:43 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
/* TODO: This should really be async */
|
2014-12-15 11:25:43 +00:00
|
|
|
g_output_stream_write_all (g_io_stream_get_output_stream (request->connection),
|
2017-12-05 13:38:57 +00:00
|
|
|
res, strlen (res), NULL, NULL, NULL);
|
2012-12-19 11:37:02 +00:00
|
|
|
g_free (res);
|
2014-12-15 11:25:43 +00:00
|
|
|
g_output_stream_write_all (g_io_stream_get_output_stream (request->connection),
|
2017-12-05 13:38:57 +00:00
|
|
|
data, len, NULL, NULL, NULL);
|
2012-12-19 11:37:02 +00:00
|
|
|
http_request_free (request);
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "clienthtml.h"
|
|
|
|
#include "broadwayjs.h"
|
|
|
|
|
|
|
|
static void
|
|
|
|
got_request (HttpRequest *request)
|
|
|
|
{
|
|
|
|
char *start, *escaped, *tmp, *version, *query;
|
|
|
|
|
|
|
|
if (!g_str_has_prefix (request->request->str, "GET "))
|
|
|
|
{
|
|
|
|
send_error (request, 501, "Only GET implemented");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
start = request->request->str + 4; /* Skip "GET " */
|
|
|
|
|
|
|
|
while (*start == ' ')
|
|
|
|
start++;
|
|
|
|
|
|
|
|
for (tmp = start; *tmp != 0 && *tmp != ' ' && *tmp != '\n'; tmp++)
|
|
|
|
;
|
|
|
|
escaped = g_strndup (start, tmp - start);
|
|
|
|
version = NULL;
|
|
|
|
if (*tmp == ' ')
|
|
|
|
{
|
|
|
|
start = tmp;
|
|
|
|
while (*start == ' ')
|
2017-12-05 13:38:57 +00:00
|
|
|
start++;
|
2012-12-19 11:37:02 +00:00
|
|
|
for (tmp = start; *tmp != 0 && *tmp != ' ' && *tmp != '\n'; tmp++)
|
2017-12-05 13:38:57 +00:00
|
|
|
;
|
2012-12-19 11:37:02 +00:00
|
|
|
version = g_strndup (start, tmp - start);
|
|
|
|
}
|
|
|
|
|
|
|
|
query = strchr (escaped, '?');
|
|
|
|
if (query)
|
|
|
|
*query = 0;
|
|
|
|
|
|
|
|
if (strcmp (escaped, "/client.html") == 0 || strcmp (escaped, "/") == 0)
|
|
|
|
send_data (request, "text/html", client_html, G_N_ELEMENTS(client_html) - 1);
|
|
|
|
else if (strcmp (escaped, "/broadway.js") == 0)
|
|
|
|
send_data (request, "text/javascript", broadway_js, G_N_ELEMENTS(broadway_js) - 1);
|
|
|
|
else if (strcmp (escaped, "/socket") == 0)
|
2013-09-25 15:59:40 +00:00
|
|
|
start_input (request);
|
2012-12-19 11:37:02 +00:00
|
|
|
else
|
|
|
|
send_error (request, 404, "File not found");
|
|
|
|
|
|
|
|
g_free (escaped);
|
|
|
|
g_free (version);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
got_http_request_line (GInputStream *stream,
|
2017-12-05 13:38:57 +00:00
|
|
|
GAsyncResult *result,
|
|
|
|
HttpRequest *request)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
char *line;
|
|
|
|
|
|
|
|
line = g_data_input_stream_read_line_finish (G_DATA_INPUT_STREAM (stream), result, NULL, NULL);
|
|
|
|
if (line == NULL)
|
|
|
|
{
|
|
|
|
http_request_free (request);
|
|
|
|
g_printerr ("Error reading request lines\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (strlen (line) == 0)
|
|
|
|
got_request (request);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Protect against overflow in request length */
|
|
|
|
if (request->request->len > 1024 * 5)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
send_error (request, 400, "Request too long");
|
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
else
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
g_string_append_printf (request->request, "%s\n", line);
|
|
|
|
g_data_input_stream_read_line_async (request->data, 0, NULL,
|
|
|
|
(GAsyncReadyCallback)got_http_request_line, request);
|
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
g_free (line);
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
handle_incoming_connection (GSocketService *service,
|
2017-12-05 13:38:57 +00:00
|
|
|
GSocketConnection *connection,
|
|
|
|
GObject *source_object)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
HttpRequest *request;
|
|
|
|
GInputStream *in;
|
|
|
|
|
|
|
|
request = g_new0 (HttpRequest, 1);
|
2014-12-15 11:25:43 +00:00
|
|
|
request->socket_connection = g_object_ref (connection);
|
2012-12-23 22:35:03 +00:00
|
|
|
request->server = BROADWAY_SERVER (source_object);
|
2012-12-19 11:37:02 +00:00
|
|
|
request->request = g_string_new ("");
|
|
|
|
|
2014-12-15 11:25:43 +00:00
|
|
|
if (request->server->ssl_cert && request->server->ssl_key)
|
|
|
|
{
|
|
|
|
GError *error = NULL;
|
|
|
|
GTlsCertificate *certificate;
|
|
|
|
|
|
|
|
certificate = g_tls_certificate_new_from_files (request->server->ssl_cert,
|
|
|
|
request->server->ssl_key,
|
|
|
|
&error);
|
|
|
|
if (!certificate)
|
|
|
|
{
|
|
|
|
g_warning ("Cannot create TLS certificate: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
request->connection = g_tls_server_connection_new (G_IO_STREAM (connection),
|
|
|
|
certificate,
|
|
|
|
&error);
|
|
|
|
if (!request->connection)
|
|
|
|
{
|
|
|
|
g_warning ("Cannot create TLS connection: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!g_tls_connection_handshake (G_TLS_CONNECTION (request->connection),
|
|
|
|
NULL, &error))
|
|
|
|
{
|
|
|
|
g_warning ("Cannot create TLS connection: %s", error->message);
|
|
|
|
g_error_free (error);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-12-21 18:42:26 +00:00
|
|
|
request->connection = G_IO_STREAM (g_object_ref (connection));
|
2014-12-15 11:25:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
in = g_io_stream_get_input_stream (request->connection);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
request->data = g_data_input_stream_new (in);
|
|
|
|
g_filter_input_stream_set_close_base_stream (G_FILTER_INPUT_STREAM (request->data), FALSE);
|
|
|
|
/* Be tolerant of input */
|
|
|
|
g_data_input_stream_set_newline_type (request->data, G_DATA_STREAM_NEWLINE_TYPE_ANY);
|
|
|
|
|
|
|
|
g_data_input_stream_read_line_async (request->data, 0, NULL,
|
2017-12-05 13:38:57 +00:00
|
|
|
(GAsyncReadyCallback)got_http_request_line, request);
|
2012-12-19 11:37:02 +00:00
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
BroadwayServer *
|
2014-12-15 11:25:43 +00:00
|
|
|
broadway_server_new (char *address,
|
|
|
|
int port,
|
|
|
|
const char *ssl_cert,
|
|
|
|
const char *ssl_key,
|
|
|
|
GError **error)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2012-12-23 22:35:03 +00:00
|
|
|
BroadwayServer *server;
|
2013-01-10 20:38:15 +00:00
|
|
|
GInetAddress *inet_address;
|
|
|
|
GSocketAddress *socket_address;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
server = g_object_new (BROADWAY_TYPE_SERVER, NULL);
|
2012-12-19 11:37:02 +00:00
|
|
|
server->port = port;
|
2013-01-10 20:38:15 +00:00
|
|
|
server->address = g_strdup (address);
|
2014-12-15 11:25:43 +00:00
|
|
|
server->ssl_cert = g_strdup (ssl_cert);
|
|
|
|
server->ssl_key = g_strdup (ssl_key);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2013-01-10 20:38:15 +00:00
|
|
|
if (address == NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2013-01-10 20:38:15 +00:00
|
|
|
if (!g_socket_listener_add_inet_port (G_SOCKET_LISTENER (server->service),
|
2017-12-05 13:38:57 +00:00
|
|
|
server->port,
|
|
|
|
G_OBJECT (server),
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_prefix_error (error, "Unable to listen to port %d: ", server->port);
|
|
|
|
g_object_unref (server);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-01-10 20:38:15 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
inet_address = g_inet_address_new_from_string (address);
|
|
|
|
if (inet_address == NULL)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Invalid ip address %s: ", address);
|
|
|
|
g_object_unref (server);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-01-10 20:38:15 +00:00
|
|
|
socket_address = g_inet_socket_address_new (inet_address, port);
|
|
|
|
g_object_unref (inet_address);
|
|
|
|
if (!g_socket_listener_add_address (G_SOCKET_LISTENER (server->service),
|
2017-12-05 13:38:57 +00:00
|
|
|
socket_address,
|
|
|
|
G_SOCKET_TYPE_STREAM,
|
|
|
|
G_SOCKET_PROTOCOL_TCP,
|
|
|
|
G_OBJECT (server),
|
|
|
|
NULL,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_prefix_error (error, "Unable to listen to %s:%d: ", server->address, server->port);
|
|
|
|
g_object_unref (socket_address);
|
|
|
|
g_object_unref (server);
|
|
|
|
return NULL;
|
|
|
|
}
|
2013-01-10 20:38:15 +00:00
|
|
|
g_object_unref (socket_address);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (server->service, "incoming",
|
2017-12-05 13:38:57 +00:00
|
|
|
G_CALLBACK (handle_incoming_connection), NULL);
|
2012-12-19 11:37:02 +00:00
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
2014-08-14 11:30:00 +00:00
|
|
|
BroadwayServer *
|
|
|
|
broadway_server_on_unix_socket_new (char *address, GError **error)
|
|
|
|
{
|
|
|
|
BroadwayServer *server;
|
2014-08-15 00:29:54 +00:00
|
|
|
GSocketAddress *socket_address = NULL;
|
2014-08-14 11:30:00 +00:00
|
|
|
|
|
|
|
server = g_object_new (BROADWAY_TYPE_SERVER, NULL);
|
|
|
|
server->port = -1;
|
|
|
|
server->address = g_strdup (address);
|
|
|
|
|
|
|
|
if (address == NULL)
|
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Unspecified unix domain socket address");
|
|
|
|
g_object_unref (server);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-08-15 00:29:54 +00:00
|
|
|
#ifdef HAVE_GIO_UNIX
|
2014-08-14 11:30:00 +00:00
|
|
|
socket_address = g_unix_socket_address_new (address);
|
2014-08-15 00:29:54 +00:00
|
|
|
#endif
|
2014-08-14 11:30:00 +00:00
|
|
|
if (socket_address == NULL)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
g_set_error (error, G_IO_ERROR, G_IO_ERROR_INVALID_DATA, "Invalid unix domain socket address %s: ", address);
|
|
|
|
g_object_unref (server);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-14 11:30:00 +00:00
|
|
|
if (!g_socket_listener_add_address (G_SOCKET_LISTENER (server->service),
|
2017-12-05 13:38:57 +00:00
|
|
|
socket_address,
|
|
|
|
G_SOCKET_TYPE_STREAM,
|
|
|
|
G_SOCKET_PROTOCOL_DEFAULT,
|
|
|
|
G_OBJECT (server),
|
|
|
|
NULL,
|
|
|
|
error))
|
|
|
|
{
|
|
|
|
g_prefix_error (error, "Unable to listen to %s: ", server->address);
|
|
|
|
g_object_unref (socket_address);
|
|
|
|
g_object_unref (server);
|
|
|
|
return NULL;
|
|
|
|
}
|
2014-08-14 11:30:00 +00:00
|
|
|
g_object_unref (socket_address);
|
|
|
|
}
|
|
|
|
|
|
|
|
g_signal_connect (server->service, "incoming",
|
2017-12-05 13:38:57 +00:00
|
|
|
G_CALLBACK (handle_incoming_connection), NULL);
|
2014-08-14 11:30:00 +00:00
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
guint32
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_get_last_seen_time (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_consume_all_input (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
return (guint32) server->last_seen_time;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_query_mouse (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
guint32 *surface,
|
|
|
|
gint32 *root_x,
|
|
|
|
gint32 *root_y,
|
|
|
|
guint32 *mask)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
if (server->output)
|
|
|
|
{
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_consume_all_input (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
if (root_x)
|
2017-12-05 13:38:57 +00:00
|
|
|
*root_x = server->future_root_x;
|
2012-12-19 11:37:02 +00:00
|
|
|
if (root_y)
|
2017-12-05 13:38:57 +00:00
|
|
|
*root_y = server->future_root_y;
|
2012-12-19 11:37:02 +00:00
|
|
|
if (mask)
|
2017-12-05 13:38:57 +00:00
|
|
|
*mask = server->future_state;
|
|
|
|
if (surface)
|
|
|
|
*surface = server->future_mouse_in_surface;
|
2012-12-19 11:37:02 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fallback when unconnected */
|
|
|
|
if (root_x)
|
|
|
|
*root_x = server->last_x;
|
|
|
|
if (root_y)
|
|
|
|
*root_y = server->last_y;
|
|
|
|
if (mask)
|
|
|
|
*mask = server->last_state;
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface)
|
|
|
|
*surface = server->mouse_in_surface_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_destroy_surface (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->mouse_in_surface_id == id)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
/* TODO: Send leave + enter event, update cursors, etc */
|
2017-12-05 13:38:57 +00:00
|
|
|
server->mouse_in_surface_id = 0;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->pointer_grab_surface_id == id)
|
|
|
|
server->pointer_grab_surface_id = -1;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
broadway_output_destroy_surface (server->output,
|
2017-12-05 13:38:57 +00:00
|
|
|
id);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface != NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
server->surfaces = g_list_remove (server->surfaces, surface);
|
2017-12-05 15:10:06 +00:00
|
|
|
g_hash_table_remove (server->surface_id_hash,
|
2017-11-21 18:33:12 +00:00
|
|
|
GINT_TO_POINTER (id));
|
2019-03-25 13:15:49 +00:00
|
|
|
broadway_surface_free (server, surface);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_show (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2012-12-19 11:37:02 +00:00
|
|
|
gboolean sent = FALSE;
|
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface == NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->visible = TRUE;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_output_show_surface (server->output, surface->id);
|
2012-12-19 11:37:02 +00:00
|
|
|
sent = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_hide (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2012-12-19 11:37:02 +00:00
|
|
|
gboolean sent = FALSE;
|
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface == NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->visible = FALSE;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->mouse_in_surface_id == id)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
/* TODO: Send leave + enter event, update cursors, etc */
|
2017-12-05 13:38:57 +00:00
|
|
|
server->mouse_in_surface_id = 0;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->pointer_grab_surface_id == id)
|
|
|
|
server->pointer_grab_surface_id = -1;
|
2012-12-26 21:31:52 +00:00
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
if (server->output)
|
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_output_hide_surface (server->output, surface->id);
|
2012-12-19 11:37:02 +00:00
|
|
|
sent = TRUE;
|
|
|
|
}
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
|
2013-11-12 11:23:58 +00:00
|
|
|
void
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_raise (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id)
|
2013-11-12 11:23:58 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2013-11-12 11:23:58 +00:00
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface == NULL)
|
2013-11-12 11:23:58 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
server->surfaces = g_list_remove (server->surfaces, surface);
|
|
|
|
server->surfaces = g_list_append (server->surfaces, surface);
|
2013-11-12 11:23:58 +00:00
|
|
|
|
|
|
|
if (server->output)
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_output_raise_surface (server->output, surface->id);
|
2013-11-12 11:23:58 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 11:20:07 +00:00
|
|
|
void
|
|
|
|
broadway_server_set_show_keyboard (BroadwayServer *server,
|
|
|
|
gboolean show)
|
|
|
|
{
|
|
|
|
server->show_keyboard = show;
|
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
{
|
|
|
|
broadway_output_set_show_keyboard (server->output, server->show_keyboard);
|
|
|
|
broadway_server_flush (server);
|
2017-12-05 13:38:57 +00:00
|
|
|
}
|
2013-11-13 11:20:07 +00:00
|
|
|
}
|
|
|
|
|
2013-11-12 11:23:58 +00:00
|
|
|
void
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_lower (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id)
|
2013-11-12 11:23:58 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2013-11-12 11:23:58 +00:00
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface == NULL)
|
2013-11-12 11:23:58 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
server->surfaces = g_list_remove (server->surfaces, surface);
|
|
|
|
server->surfaces = g_list_prepend (server->surfaces, surface);
|
2013-11-12 11:23:58 +00:00
|
|
|
|
|
|
|
if (server->output)
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_output_lower_surface (server->output, surface->id);
|
2013-11-12 11:23:58 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
void
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_set_transient_for (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id, int parent)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface == NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
return;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->transient_for = parent;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_output_set_transient_for (server->output, surface->id, surface->transient_for);
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_flush (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
gboolean
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_has_client (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
return server->output != NULL;
|
|
|
|
}
|
|
|
|
|
2019-03-25 13:15:49 +00:00
|
|
|
#define NODE_SIZE_COLOR 1
|
|
|
|
#define NODE_SIZE_FLOAT 1
|
|
|
|
#define NODE_SIZE_POINT 2
|
2019-03-27 18:27:16 +00:00
|
|
|
#define NODE_SIZE_MATRIX 16
|
2019-03-25 13:15:49 +00:00
|
|
|
#define NODE_SIZE_SIZE 2
|
|
|
|
#define NODE_SIZE_RECT (NODE_SIZE_POINT + NODE_SIZE_SIZE)
|
|
|
|
#define NODE_SIZE_RRECT (NODE_SIZE_RECT + 4 * NODE_SIZE_SIZE)
|
|
|
|
#define NODE_SIZE_COLOR_STOP (NODE_SIZE_FLOAT + NODE_SIZE_COLOR)
|
|
|
|
#define NODE_SIZE_SHADOW (NODE_SIZE_COLOR + 3 * NODE_SIZE_FLOAT)
|
|
|
|
|
|
|
|
static guint32
|
|
|
|
rotl (guint32 value, int shift)
|
|
|
|
{
|
|
|
|
if ((shift &= 32 - 1) == 0)
|
|
|
|
return value;
|
|
|
|
return (value << shift) | (value >> (32 - shift));
|
|
|
|
}
|
|
|
|
|
|
|
|
static BroadwayNode *
|
|
|
|
decode_nodes (BroadwayServer *server,
|
|
|
|
BroadwaySurface *surface,
|
|
|
|
int len,
|
|
|
|
guint32 data[],
|
|
|
|
GHashTable *client_texture_map,
|
|
|
|
int *pos)
|
|
|
|
{
|
|
|
|
BroadwayNode *node;
|
|
|
|
guint32 type, id;
|
|
|
|
guint32 i, n_stops, n_shadows, n_chars;
|
|
|
|
guint32 size, n_children;
|
|
|
|
gint32 texture_offset;
|
|
|
|
guint32 hash;
|
2019-03-27 18:27:16 +00:00
|
|
|
guint32 transform_type;
|
2019-03-25 13:15:49 +00:00
|
|
|
|
|
|
|
g_assert (*pos < len);
|
|
|
|
|
|
|
|
size = 0;
|
|
|
|
n_children = 0;
|
|
|
|
texture_offset = -1;
|
|
|
|
|
|
|
|
type = data[(*pos)++];
|
|
|
|
id = data[(*pos)++];
|
|
|
|
switch (type) {
|
|
|
|
case BROADWAY_NODE_REUSE:
|
|
|
|
node = g_hash_table_lookup (surface->node_lookup, GINT_TO_POINTER(id));
|
|
|
|
g_assert (node != NULL);
|
|
|
|
return broadway_node_ref (node);
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_COLOR:
|
|
|
|
size = NODE_SIZE_RECT + NODE_SIZE_COLOR;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_BORDER:
|
|
|
|
size = NODE_SIZE_RRECT + 4 * NODE_SIZE_FLOAT + 4 * NODE_SIZE_COLOR;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_INSET_SHADOW:
|
|
|
|
case BROADWAY_NODE_OUTSET_SHADOW:
|
|
|
|
size = NODE_SIZE_RRECT + NODE_SIZE_COLOR + 4 * NODE_SIZE_FLOAT;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_TEXTURE:
|
|
|
|
texture_offset = 4;
|
|
|
|
size = 5;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_CONTAINER:
|
|
|
|
size = 1;
|
|
|
|
n_children = data[*pos];
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_ROUNDED_CLIP:
|
|
|
|
size = NODE_SIZE_RRECT;
|
|
|
|
n_children = 1;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_CLIP:
|
|
|
|
size = NODE_SIZE_RECT;
|
|
|
|
n_children = 1;
|
|
|
|
break;
|
2019-03-27 18:27:16 +00:00
|
|
|
case BROADWAY_NODE_TRANSFORM:
|
|
|
|
transform_type = data[(*pos)];
|
|
|
|
size = 1;
|
|
|
|
if (transform_type == 0) {
|
|
|
|
size += NODE_SIZE_POINT;
|
|
|
|
} else if (transform_type == 1) {
|
|
|
|
size += NODE_SIZE_MATRIX;
|
|
|
|
} else {
|
|
|
|
g_assert_not_reached();
|
|
|
|
}
|
2019-03-25 13:15:49 +00:00
|
|
|
n_children = 1;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_LINEAR_GRADIENT:
|
|
|
|
size = NODE_SIZE_RECT + 2 * NODE_SIZE_POINT;
|
|
|
|
n_stops = data[*pos + size++];
|
|
|
|
size += n_stops * NODE_SIZE_COLOR_STOP;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_SHADOW:
|
|
|
|
size = 1;
|
|
|
|
n_shadows = data[*pos];
|
|
|
|
size += n_shadows * NODE_SIZE_SHADOW;
|
|
|
|
n_children = 1;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_OPACITY:
|
|
|
|
size = NODE_SIZE_FLOAT;
|
|
|
|
n_children = 1;
|
|
|
|
break;
|
|
|
|
case BROADWAY_NODE_DEBUG:
|
|
|
|
n_chars = data[*pos];
|
|
|
|
size = 1 + (n_chars + 3) / 4;
|
|
|
|
n_children = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
|
|
|
|
node = g_malloc (sizeof(BroadwayNode) + (size - 1) * sizeof(guint32) + n_children * sizeof (BroadwayNode *));
|
|
|
|
g_ref_count_init (&node->refcount);
|
|
|
|
node->type = type;
|
|
|
|
node->id = id;
|
2019-03-28 18:17:01 +00:00
|
|
|
node->output_id = id;
|
2019-03-25 13:15:49 +00:00
|
|
|
node->texture_id = 0;
|
|
|
|
node->n_children = n_children;
|
|
|
|
node->children = (BroadwayNode **)((char *)node + sizeof(BroadwayNode) + (size - 1) * sizeof(guint32));
|
|
|
|
node->n_data = size;
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
{
|
|
|
|
node->data[i] = data[(*pos)++];
|
|
|
|
if (i == texture_offset)
|
|
|
|
{
|
|
|
|
node->texture_id = GPOINTER_TO_INT (g_hash_table_lookup (client_texture_map, GINT_TO_POINTER (node->data[i])));
|
|
|
|
broadway_server_ref_texture (server, node->texture_id);
|
|
|
|
node->data[i] = node->texture_id;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < n_children; i++)
|
|
|
|
node->children[i] = decode_nodes (server, surface, len, data, client_texture_map, pos);
|
|
|
|
|
|
|
|
hash = node->type << 16;
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
hash ^= rotl (node->data[i], i);
|
|
|
|
|
|
|
|
for (i = 0; i < n_children; i++)
|
|
|
|
hash ^= rotl (node->children[i]->hash, i);
|
|
|
|
|
|
|
|
node->hash = hash;
|
|
|
|
|
|
|
|
return node;
|
|
|
|
}
|
|
|
|
|
2017-11-29 18:08:37 +00:00
|
|
|
/* passes ownership of nodes */
|
2017-11-21 18:33:12 +00:00
|
|
|
void
|
2019-03-25 13:15:49 +00:00
|
|
|
broadway_server_surface_update_nodes (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id,
|
2019-03-25 13:15:49 +00:00
|
|
|
guint32 data[],
|
|
|
|
int len,
|
|
|
|
GHashTable *client_texture_map)
|
2017-11-21 18:33:12 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface;
|
2019-03-25 13:15:49 +00:00
|
|
|
int pos = 0;
|
|
|
|
BroadwayNode *root;
|
2017-11-21 18:33:12 +00:00
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface == NULL)
|
2017-11-21 18:33:12 +00:00
|
|
|
return;
|
|
|
|
|
2019-03-25 13:15:49 +00:00
|
|
|
root = decode_nodes (server, surface, len, data, client_texture_map, &pos);
|
|
|
|
|
2017-11-29 19:05:02 +00:00
|
|
|
if (server->output != NULL)
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_output_surface_set_nodes (server->output, surface->id,
|
|
|
|
root,
|
2019-03-28 15:03:42 +00:00
|
|
|
surface->nodes,
|
|
|
|
surface->node_lookup);
|
2017-11-29 19:05:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface->nodes)
|
2019-03-25 13:15:49 +00:00
|
|
|
broadway_node_unref (server, surface->nodes);
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->nodes = root;
|
2019-03-25 13:15:49 +00:00
|
|
|
|
|
|
|
g_hash_table_remove_all (surface->node_lookup);
|
2019-03-28 15:03:42 +00:00
|
|
|
broadway_node_add_to_lookup (root, surface->node_lookup);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2017-11-18 15:47:43 +00:00
|
|
|
guint32
|
|
|
|
broadway_server_upload_texture (BroadwayServer *server,
|
2019-03-25 13:15:49 +00:00
|
|
|
GBytes *bytes)
|
2017-11-18 15:47:43 +00:00
|
|
|
{
|
2019-03-25 13:15:49 +00:00
|
|
|
BroadwayTexture *texture;
|
|
|
|
|
|
|
|
texture = g_new0 (BroadwayTexture, 1);
|
|
|
|
g_ref_count_init (&texture->refcount);
|
|
|
|
texture->id = ++server->next_texture_id;
|
|
|
|
texture->bytes = g_bytes_ref (bytes);
|
2017-11-18 15:47:43 +00:00
|
|
|
|
|
|
|
g_hash_table_replace (server->textures,
|
2019-03-25 13:15:49 +00:00
|
|
|
GINT_TO_POINTER (texture->id),
|
|
|
|
texture);
|
2017-11-18 15:47:43 +00:00
|
|
|
|
2017-11-18 16:36:38 +00:00
|
|
|
if (server->output)
|
2019-03-25 13:15:49 +00:00
|
|
|
broadway_output_upload_texture (server->output, texture->id, texture->bytes);
|
|
|
|
|
|
|
|
return texture->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
broadway_server_ref_texture (BroadwayServer *server,
|
|
|
|
guint32 id)
|
|
|
|
{
|
|
|
|
BroadwayTexture *texture;
|
2017-11-18 16:36:38 +00:00
|
|
|
|
2019-03-25 13:15:49 +00:00
|
|
|
texture = g_hash_table_lookup (server->textures, GINT_TO_POINTER (id));
|
|
|
|
if (texture)
|
|
|
|
g_ref_count_inc (&texture->refcount);
|
2017-11-18 15:47:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
broadway_server_release_texture (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
guint32 id)
|
2017-11-18 15:47:43 +00:00
|
|
|
{
|
2019-03-25 13:15:49 +00:00
|
|
|
BroadwayTexture *texture;
|
2017-11-18 16:36:38 +00:00
|
|
|
|
2019-03-25 13:15:49 +00:00
|
|
|
texture = g_hash_table_lookup (server->textures, GINT_TO_POINTER (id));
|
|
|
|
|
|
|
|
if (texture && g_ref_count_dec (&texture->refcount))
|
|
|
|
{
|
|
|
|
g_hash_table_remove (server->textures, GINT_TO_POINTER (id));
|
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
broadway_output_release_texture (server->output, id);
|
|
|
|
}
|
2017-11-18 15:47:43 +00:00
|
|
|
}
|
|
|
|
|
2012-12-19 11:37:02 +00:00
|
|
|
gboolean
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_surface_move_resize (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int id,
|
2017-12-05 13:38:57 +00:00
|
|
|
gboolean with_move,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
|
|
|
int height)
|
|
|
|
{
|
|
|
|
BroadwaySurface *surface;
|
2013-01-08 16:33:29 +00:00
|
|
|
gboolean with_resize;
|
2012-12-19 11:37:02 +00:00
|
|
|
gboolean sent = FALSE;
|
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
surface = broadway_server_lookup_surface (server, id);
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface == NULL)
|
2012-12-19 11:37:02 +00:00
|
|
|
return FALSE;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
with_resize = width != surface->width || height != surface->height;
|
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (server->output != NULL)
|
|
|
|
{
|
|
|
|
broadway_output_move_resize_surface (server->output,
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->id,
|
|
|
|
with_move, x, y,
|
|
|
|
with_resize, surface->width, surface->height);
|
2012-12-19 11:37:02 +00:00
|
|
|
sent = TRUE;
|
|
|
|
}
|
2013-01-08 16:33:29 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
if (with_move)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
surface->x = x;
|
|
|
|
surface->y = y;
|
|
|
|
}
|
2013-01-08 16:33:29 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
fake_configure_notify (server, surface);
|
2013-01-08 16:33:29 +00:00
|
|
|
}
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
return sent;
|
|
|
|
}
|
|
|
|
|
2013-11-12 11:03:50 +00:00
|
|
|
void
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_focus_surface (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int new_focused_surface)
|
2013-11-12 11:03:50 +00:00
|
|
|
{
|
|
|
|
BroadwayInputMsg focus_msg;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->focused_surface_id == new_focused_surface)
|
2013-11-12 11:03:50 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
memset (&focus_msg, 0, sizeof (focus_msg));
|
|
|
|
focus_msg.base.type = BROADWAY_EVENT_FOCUS;
|
|
|
|
focus_msg.base.time = broadway_server_get_last_seen_time (server);
|
2017-12-05 13:38:57 +00:00
|
|
|
focus_msg.focus.old_id = server->focused_surface_id;
|
|
|
|
focus_msg.focus.new_id = new_focused_surface;
|
2013-11-12 11:03:50 +00:00
|
|
|
|
|
|
|
broadway_events_got_input (&focus_msg, -1);
|
2013-11-13 11:10:29 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
/* Keep track of the new focused surface */
|
|
|
|
server->focused_surface_id = new_focused_surface;
|
2013-11-12 11:03:50 +00:00
|
|
|
}
|
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
guint32
|
|
|
|
broadway_server_grab_pointer (BroadwayServer *server,
|
2020-07-24 13:54:49 +00:00
|
|
|
int client_id,
|
|
|
|
int id,
|
2017-12-05 13:38:57 +00:00
|
|
|
gboolean owner_events,
|
|
|
|
guint32 event_mask,
|
|
|
|
guint32 time_)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->pointer_grab_surface_id != -1 &&
|
2012-12-19 11:37:02 +00:00
|
|
|
time_ != 0 && server->pointer_grab_time > time_)
|
|
|
|
return GDK_GRAB_ALREADY_GRABBED;
|
|
|
|
|
|
|
|
if (time_ == 0)
|
|
|
|
time_ = server->last_seen_time;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
server->pointer_grab_surface_id = id;
|
2012-12-26 21:31:52 +00:00
|
|
|
server->pointer_grab_client_id = client_id;
|
2012-12-19 11:37:02 +00:00
|
|
|
server->pointer_grab_owner_events = owner_events;
|
|
|
|
server->pointer_grab_time = time_;
|
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
{
|
|
|
|
broadway_output_grab_pointer (server->output,
|
2017-12-05 13:38:57 +00:00
|
|
|
id,
|
|
|
|
owner_events);
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_flush (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
/* TODO: What about surface grab events if we're not connected? */
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
return GDK_GRAB_SUCCESS;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_ungrab_pointer (BroadwayServer *server,
|
2017-12-05 13:38:57 +00:00
|
|
|
guint32 time_)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
|
|
|
guint32 serial;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (server->pointer_grab_surface_id != -1 &&
|
2012-12-19 11:37:02 +00:00
|
|
|
time_ != 0 && server->pointer_grab_time > time_)
|
|
|
|
return 0;
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
/* TODO: What about surface grab events if we're not connected? */
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
{
|
|
|
|
serial = broadway_output_ungrab_pointer (server->output);
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_flush (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
serial = server->saved_serial;
|
|
|
|
}
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
server->pointer_grab_surface_id = -1;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
return serial;
|
|
|
|
}
|
|
|
|
|
|
|
|
guint32
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_new_surface (BroadwayServer *server,
|
2019-03-29 10:07:04 +00:00
|
|
|
guint32 client,
|
2017-12-05 13:38:57 +00:00
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int width,
|
2020-03-13 13:33:07 +00:00
|
|
|
int height)
|
2017-12-05 13:38:57 +00:00
|
|
|
{
|
|
|
|
BroadwaySurface *surface;
|
|
|
|
|
|
|
|
surface = g_new0 (BroadwaySurface, 1);
|
2019-03-29 10:07:04 +00:00
|
|
|
surface->owner = client;
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->id = server->id_counter++;
|
|
|
|
surface->x = x;
|
|
|
|
surface->y = y;
|
|
|
|
surface->width = width;
|
|
|
|
surface->height = height;
|
2019-03-25 13:15:49 +00:00
|
|
|
surface->node_lookup = g_hash_table_new (g_direct_hash, g_direct_equal);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 15:10:06 +00:00
|
|
|
g_hash_table_insert (server->surface_id_hash,
|
2017-12-05 13:38:57 +00:00
|
|
|
GINT_TO_POINTER (surface->id),
|
|
|
|
surface);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
server->surfaces = g_list_append (server->surfaces, surface);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
if (server->output)
|
|
|
|
broadway_output_new_surface (server->output,
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->id,
|
|
|
|
surface->x,
|
|
|
|
surface->y,
|
|
|
|
surface->width,
|
2020-03-13 13:33:07 +00:00
|
|
|
surface->height);
|
2013-01-08 16:33:29 +00:00
|
|
|
else
|
2017-12-05 13:38:57 +00:00
|
|
|
fake_configure_notify (server, surface);
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
return surface->id;
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-12-05 13:38:57 +00:00
|
|
|
broadway_server_resync_surfaces (BroadwayServer *server)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-11-18 16:36:38 +00:00
|
|
|
GHashTableIter iter;
|
|
|
|
gpointer key, value;
|
2012-12-19 11:37:02 +00:00
|
|
|
GList *l;
|
|
|
|
|
|
|
|
if (server->output == NULL)
|
|
|
|
return;
|
|
|
|
|
2017-11-18 16:36:38 +00:00
|
|
|
/* First upload all textures */
|
|
|
|
g_hash_table_iter_init (&iter, server->textures);
|
|
|
|
while (g_hash_table_iter_next (&iter, &key, &value))
|
2019-03-25 13:15:49 +00:00
|
|
|
{
|
|
|
|
BroadwayTexture *texture = value;
|
|
|
|
broadway_output_upload_texture (server->output,
|
|
|
|
GPOINTER_TO_INT (key),
|
|
|
|
texture->bytes);
|
|
|
|
}
|
2017-11-18 16:36:38 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
/* Then create all surfaces */
|
|
|
|
for (l = server->surfaces; l != NULL; l = l->next)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface = l->data;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface->id == 0)
|
|
|
|
continue; /* Skip root */
|
2012-12-19 11:37:02 +00:00
|
|
|
|
|
|
|
broadway_output_new_surface (server->output,
|
2017-12-05 13:38:57 +00:00
|
|
|
surface->id,
|
|
|
|
surface->x,
|
|
|
|
surface->y,
|
|
|
|
surface->width,
|
2020-03-13 13:33:07 +00:00
|
|
|
surface->height);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
/* Then do everything that may reference other surfaces */
|
|
|
|
for (l = server->surfaces; l != NULL; l = l->next)
|
2012-12-19 11:37:02 +00:00
|
|
|
{
|
2017-12-05 13:38:57 +00:00
|
|
|
BroadwaySurface *surface = l->data;
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface->id == 0)
|
|
|
|
continue; /* Skip root */
|
2012-12-19 11:37:02 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface->transient_for != -1)
|
|
|
|
broadway_output_set_transient_for (server->output, surface->id,
|
|
|
|
surface->transient_for);
|
2017-11-18 19:36:57 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface->nodes)
|
|
|
|
broadway_output_surface_set_nodes (server->output, surface->id,
|
2019-03-28 15:03:42 +00:00
|
|
|
surface->nodes,
|
|
|
|
NULL, NULL);
|
2017-11-21 18:33:12 +00:00
|
|
|
|
2017-12-05 13:38:57 +00:00
|
|
|
if (surface->visible)
|
|
|
|
broadway_output_show_surface (server->output, surface->id);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|
|
|
|
|
2013-11-13 11:20:07 +00:00
|
|
|
if (server->show_keyboard)
|
|
|
|
broadway_output_set_show_keyboard (server->output, TRUE);
|
|
|
|
|
2012-12-23 22:35:03 +00:00
|
|
|
broadway_server_flush (server);
|
2012-12-19 11:37:02 +00:00
|
|
|
}
|