Commit 95db2b9e authored by Jeremy White's avatar Jeremy White

Implement a first session where we process XDamage.

parent 2e8b92eb
......@@ -2,6 +2,7 @@ AC_INIT([x11spice], 1.0)
AM_INIT_AUTOMAKE
PKG_CHECK_MODULES(X11, x11)
PKG_CHECK_MODULES(XDAMAGE, xdamage)
PKG_CHECK_MODULES(GTK2, gtk+-2.0)
PKG_CHECK_MODULES(SPICE, spice-server)
PKG_CHECK_MODULES(GLIB2, glib-2.0)
......
bin_PROGRAMS = x11spice
AM_CFLAGS = $(XLL_CFLAGS) $(GTK2_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS)
x11spice_LDADD = $(X11_LIBS) $(GTK2_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS)
AM_CFLAGS = -Wall $(XLL_CFLAGS) $(GTK2_CFLAGS) $(SPICE_CFLAGS) $(GLIB2_CFLAGS) $(XDAMAGE_CFLAGS)
x11spice_LDADD = $(X11_LIBS) $(GTK2_LIBS) $(SPICE_LIBS) $(GLIB2_LIBS) $(XDAMAGE_LIBS)
x11spice_SOURCES = \
display.c \
gui.c \
options.c \
session.c \
spice.c \
main.c
......@@ -22,34 +22,39 @@
#include <stdio.h>
#include <X11/Xlib.h>
#include <glib.h>
#include "x11spice.h"
#include "options.h"
#include "display.h"
display_t *display_open(options_t *options)
int display_open(display_t *d, options_t *options)
{
display_t *d = malloc(sizeof(*d));
if (! d)
return NULL;
d->xdisplay = XOpenDisplay(options->display);
// FIXME g_x_error_handler = XSetErrorHandler(handle_xerrors);
// FIXME - do we care? - g_x_error_handler = XSetErrorHandler(handle_xerrors);
if (! d->xdisplay)
{
fprintf(stderr, "Error: could not open display %s\n", options->display ? options->display : "");
return NULL;
return X11SPICE_ERR_NODISPLAY;
}
if (! XDamageQueryExtension(d->xdisplay, &d->xd_event_base, &d->xd_error_base))
{
fprintf(stderr, "Error: XDAMAGE not found on display %s\n", options->display ? options->display : "");
return X11SPICE_ERR_NODAMAGE;
}
return d;
d->xdamage = XDamageCreate(d->xdisplay, DefaultRootWindow(d->xdisplay), XDamageReportRawRectangles);
g_info("Display %s opened", options->display ? options->display : "");
return 0;
}
void display_close(display_t *display)
void display_close(display_t *d)
{
if (display->xdisplay)
{
XCloseDisplay(display->xdisplay);
display->xdisplay = NULL;
}
XDamageDestroy(d->xdisplay, d->xdamage);
XCloseDisplay(d->xdisplay);
}
......@@ -22,6 +22,7 @@
#define DISPLAY_H_
#include <X11/Xlib.h>
#include <X11/extensions/Xdamage.h>
/*----------------------------------------------------------------------------
** Structure definitions
......@@ -29,13 +30,16 @@
typedef struct
{
Display *xdisplay;
Damage xdamage;
int xd_event_base;
int xd_error_base;
} display_t;
/*----------------------------------------------------------------------------
** Prototypes
**--------------------------------------------------------------------------*/
display_t *display_open(options_t *options);
int display_open(display_t *display, options_t *options);
void display_close(display_t *display);
#endif
......@@ -23,8 +23,6 @@
int gui_init(gui_t *gui, int argc, char *argv[])
{
GtkWidget *window;
if (! gtk_init_check(&argc, &argv))
return X11SPICE_ERR_GTK_FAILED;
......
......@@ -26,61 +26,70 @@
#include "local_spice.h"
#include "display.h"
#include "gui.h"
#include "session.h"
int main(int argc, char *argv[])
{
int rc;
options_t options;
display_t * display = NULL;
gui_t gui;
spice_t s;
session_t session;
int display_opened = 0;
int spice_started = 0;
/*------------------------------------------------------------------------
** Parse arguments
**----------------------------------------------------------------------*/
options_init(&options);
rc = options_parse_arguments(argc, argv, &options);
options_init(&session.options);
rc = options_parse_arguments(argc, argv, &session.options);
if (rc)
goto exit;
options_from_config(&options);
options_from_config(&session.options);
/*------------------------------------------------------------------------
** Open the display
**----------------------------------------------------------------------*/
display = display_open(&options);
if (! display)
{
rc = X11SPICE_ERR_NODISPLAY;
rc = display_open(&session.display, &session.options);
if (rc)
goto exit;
}
display_opened = 1;
/*------------------------------------------------------------------------
** Initialize the GUI
**----------------------------------------------------------------------*/
rc = gui_init(&gui, argc, argv);
rc = gui_init(&session.gui, argc, argv);
if (rc)
goto exit;
/*------------------------------------------------------------------------
** Start up a spice server
**----------------------------------------------------------------------*/
rc = spice_start(&s, &options);
rc = spice_start(&session.spice, &session.options);
if (rc)
goto exit;
spice_started = 1;
gui_run(&gui);
/*------------------------------------------------------------------------
** Leave the GUI running until we have a reason to quit
**----------------------------------------------------------------------*/
rc = session_start(&session);
if (rc)
goto exit;
spice_end(&s);
gui_run(&session.gui);
session_end(&session);
/*------------------------------------------------------------------------
** Close the display, go home
** Clean up, go home
**----------------------------------------------------------------------*/
exit:
options_free(&options);
if (spice_started)
spice_end(&session.spice);
if (display_opened)
display_close(&session.display);
if (display)
display_close(display);
options_free(&session.options);
return rc;
}
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
x11spice is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
#include "x11spice.h"
#include "session.h"
static void session_handle_xevent(int fd, int event, void *opaque)
{
session_t *s = (session_t *) opaque;
XEvent xev;
int rc;
XDamageNotifyEvent *dev = (XDamageNotifyEvent *) &xev;;
rc = XNextEvent(s->display.xdisplay, &xev);
if (rc == 0)
{
if (xev.type != s->display.xd_event_base + XDamageNotify)
{
g_debug("Unexpected X event %d", xev.type);
return;
}
g_debug("XDamageNotify [ser %ld|send_event %d|level %d|more %d|area (%dx%d)@%dx%d|geo (%dx%d)@%dx%d",
dev->serial, dev->send_event, dev->level, dev->more,
dev->area.width, dev->area.height, dev->area.x, dev->area.y,
dev->geometry.width, dev->geometry.height, dev->geometry.x, dev->geometry.y);
}
}
int session_start(session_t *s)
{
s->xwatch = s->spice.core->watch_add(ConnectionNumber(s->display.xdisplay),
SPICE_WATCH_EVENT_READ, session_handle_xevent, s);
if (! s->xwatch)
return X11SPICE_ERR_NOWATCH;
/* In order for the watch to function,
we seem to have to request at least one event */
// FIXME - not sure I know why...
XPending(s->display.xdisplay);
return 0;
}
void session_end(session_t *s)
{
s->spice.core->watch_remove(s->xwatch);
}
/*
Copyright (C) 2016 Jeremy White <jwhite@codeweavers.com>
All rights reserved.
This file is part of x11spice
x11spice is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
x11spice is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with x11spice. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SESSION_H_
#define SESSION_H_
#include "options.h"
#include "display.h"
#include "local_spice.h"
#include "gui.h"
/*----------------------------------------------------------------------------
** Structure definitions
**--------------------------------------------------------------------------*/
typedef struct
{
options_t options;
display_t display;
spice_t spice;
gui_t gui;
SpiceWatch *xwatch;
} session_t;
/*----------------------------------------------------------------------------
** Prototypes
**--------------------------------------------------------------------------*/
int session_start(session_t *s);
void session_end(session_t *s);
#endif
......@@ -28,5 +28,7 @@
#define X11SPICE_ERR_NODISPLAY 2
#define X11SPICE_ERR_GTK_FAILED 3
#define X11SPICE_ERR_SPICE_INIT_FAILED 4
#define X11SPICE_ERR_NODAMAGE 5
#define X11SPICE_ERR_NOWATCH 6
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment