broadway: Add serial tracking and roundtripping

This commit is contained in:
Alexander Larsson 2011-03-10 14:58:47 +01:00
parent 3914d0af38
commit d4e2414d4a
8 changed files with 53 additions and 18 deletions

View File

@ -223,7 +223,7 @@ main (int argc, char *argv[])
{
BroadwayOutput *output;
output = broadway_output_new (STDOUT_FILENO);
output = broadway_output_new (STDOUT_FILENO, 1);
demo2(output);
return 0;

View File

@ -1,4 +1,3 @@
#include <glib.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
@ -450,6 +449,7 @@ struct BroadwayOutput {
int fd;
gzFile *zfd;
int error;
guint32 serial;
};
static void
@ -537,13 +537,14 @@ send_boundary (BroadwayOutput *output)
}
BroadwayOutput *
broadway_output_new(int fd)
broadway_output_new(int fd, guint32 serial)
{
BroadwayOutput *output;
output = g_new0 (BroadwayOutput, 1);
output->fd = fd;
output->serial = serial;
broadway_output_write_header (output);
@ -565,6 +566,12 @@ broadway_output_free (BroadwayOutput *output)
free (output);
}
guint32
broadway_output_get_next_serial (BroadwayOutput *output)
{
return output->serial;
}
int
broadway_output_flush (BroadwayOutput *output)
{
@ -578,7 +585,7 @@ broadway_output_flush (BroadwayOutput *output)
* Core rendering operations *
************************************************************************/
#define HEADER_LEN 1
#define HEADER_LEN (1+6)
static void
append_uint16 (guint32 v, char *buf, int *p)
@ -601,6 +608,7 @@ write_header(BroadwayOutput *output, char *buf, char op)
p = 0;
buf[p++] = op;
append_uint32 (output->serial++, buf, &p);
return p;
}
@ -1008,7 +1016,9 @@ broadway_output_put_rgba (BroadwayOutput *output, int id, int x, int y,
len = strlen (url);
append_uint32 (len, buf, &p);
broadway_output_write (output, buf, 16);
assert (p == sizeof (buf));
broadway_output_write (output, buf, sizeof (buf));
broadway_output_write (output, url, len);

View File

@ -1,3 +1,5 @@
#include <glib.h>
typedef struct BroadwayOutput BroadwayOutput;
typedef struct {
@ -5,10 +7,12 @@ typedef struct {
int width, height;
} BroadwayRect;
BroadwayOutput *broadway_output_new (int fd);
BroadwayOutput *broadway_output_new (int fd,
guint32 serial);
void broadway_output_free (BroadwayOutput *output);
int broadway_output_flush (BroadwayOutput *output);
int broadway_output_has_error (BroadwayOutput *output);
guint32 broadway_output_get_next_serial (BroadwayOutput *output);
void broadway_output_new_surface (BroadwayOutput *output,
int id,
int x,

View File

@ -63,6 +63,7 @@ function createXHR()
return null;
}
var last_serial = 0;
var surfaces = {};
var outstanding_commands = new Array();
var input_socket = null;
@ -89,6 +90,8 @@ function handleCommands(cmd_obj)
while (i < cmd.length) {
var command = cmd[i++];
last_serial = base64_32(cmd, i);
i = i + 6;
switch (command) {
/* create new surface */
case 's':
@ -277,7 +280,7 @@ function get_surface_id(ev) {
function send_input(cmd, args)
{
if (input_socket != null) {
input_socket.send(cmd + args.join(","));
input_socket.send(cmd + ([last_serial].concat(args)).join(","));
}
}

View File

@ -61,6 +61,7 @@ gdk_event_init (GdkDisplay *display)
broadway_display = GDK_BROADWAY_DISPLAY (display);
broadway_display->event_source = _gdk_broadway_event_source_new (display);
broadway_display->saved_serial = 1;
}
static void
@ -350,7 +351,14 @@ start_output (HttpRequest *request)
fd = g_socket_get_fd (socket);
set_fd_blocking (fd);
/* We dup this because otherwise it'll be closed with the request SocketConnection */
broadway_display->output = broadway_output_new (dup(fd));
if (broadway_display->output)
{
broadway_display->saved_serial = broadway_output_get_next_serial (broadway_display->output);
broadway_output_free (broadway_display->output);
}
broadway_display->output = broadway_output_new (dup(fd), broadway_display->saved_serial);
_gdk_broadway_resync_windows ();
http_request_free (request);
}
@ -715,7 +723,11 @@ gdk_broadway_display_list_devices (GdkDisplay *display)
static gulong
gdk_broadway_display_get_next_serial (GdkDisplay *display)
{
return 0;
GdkBroadwayDisplay *broadway_display;
broadway_display = GDK_BROADWAY_DISPLAY (display);
if (broadway_display->output)
return broadway_output_get_next_serial (broadway_display->output);
return broadway_display->saved_serial;
}

View File

@ -81,6 +81,7 @@ struct _GdkBroadwayDisplay
GSocketService *service;
BroadwayOutput *output;
guint32 saved_serial;
HttpRequest *input;
};

View File

@ -97,6 +97,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
GdkWindow *root, *window;
char *p;
int x, y, button, id, dir,key;
guint32 serial;
guint64 time;
GdkEvent *event = NULL;
char cmd;
@ -107,6 +108,8 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
p = (char *)message;
cmd = *p++;
serial = (guint32)strtol(p, &p, 10);
p++; /* Skip , */
switch (cmd) {
case 'm':
id = strtol(p, &p, 10);
@ -137,7 +140,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
event = gdk_event_new (GDK_FOCUS_CHANGE);
event->focus_change.window = g_object_ref (display_broadway->mouse_in_toplevel);
@ -145,7 +148,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
}
/* TODO: Unset when it dies */
@ -165,7 +168,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
event = gdk_event_new (GDK_FOCUS_CHANGE);
event->focus_change.window = g_object_ref (window);
@ -173,7 +176,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
}
}
@ -190,7 +193,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
}
break;
@ -223,7 +226,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
}
break;
@ -255,7 +258,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
}
break;
@ -277,7 +280,7 @@ _gdk_broadway_events_got_input (GdkDisplay *display,
gdk_event_set_device (event, display->core_pointer);
node = _gdk_event_queue_append (display, event);
_gdk_windowing_got_event (display, node, event, 0);
_gdk_windowing_got_event (display, node, event, serial);
}
break;

View File

@ -186,6 +186,7 @@ dirty_flush_idle (gpointer data)
if (!broadway_output_flush (display->output))
{
display->saved_serial = broadway_output_get_next_serial (display->output);
broadway_output_free (display->output);
display->output = NULL;
}
@ -662,7 +663,8 @@ gdk_window_broadway_move_resize (GdkWindow *window,
gdk_event_set_device (event, GDK_DISPLAY_OBJECT (broadway_display)->core_pointer);
node = _gdk_event_queue_append (GDK_DISPLAY_OBJECT (broadway_display), event);
_gdk_windowing_got_event (GDK_DISPLAY_OBJECT (broadway_display), node, event, 0);
_gdk_windowing_got_event (GDK_DISPLAY_OBJECT (broadway_display), node, event,
_gdk_display_get_next_serial (GDK_DISPLAY (broadway_display)) - 1);
}
}