Commit 43c31e34 authored by Jeremy White's avatar Jeremy White

Flesh out the gui a bit.

The disconnect button does not function yet.
parent 342f929e
......@@ -29,6 +29,21 @@ void gui_sigterm(void)
cached_gui = NULL;
}
void gui_remote_connected(gui_t *gui, const char *details)
{
gtk_label_set_text(GTK_LABEL(gui->status_label), "Connection established");
gtk_widget_set_tooltip_text(gui->status_label, details);
gtk_widget_set_sensitive(gui->disconnect_button, TRUE);
// FIXME - disconnect should do something, but that looks hard
}
void gui_remote_disconnected(gui_t *gui)
{
gtk_label_set_text(GTK_LABEL(gui->status_label), "Waiting for connection");
gtk_widget_set_sensitive(gui->disconnect_button, FALSE);
}
int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden)
{
if (! gtk_init_check(&argc, &argv))
......@@ -36,6 +51,26 @@ int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden)
gui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(gui->window, "destroy", G_CALLBACK(gui_sigterm), NULL);
gui->button_box = gtk_vbutton_box_new();
gtk_container_add(GTK_CONTAINER(gui->window), gui->button_box);
gui->status_label = gtk_label_new(NULL);
gtk_container_add(GTK_CONTAINER(gui->button_box), gui->status_label);
gui->disconnect_button = gtk_button_new_from_stock(GTK_STOCK_DISCONNECT);
gtk_container_add(GTK_CONTAINER(gui->button_box), gui->disconnect_button);
gui_remote_disconnected(gui);
gui->quit_button = gtk_button_new_from_stock(GTK_STOCK_QUIT);
gtk_container_add(GTK_CONTAINER(gui->button_box), gui->quit_button);
g_signal_connect_swapped(gui->quit_button, "clicked", G_CALLBACK (gtk_widget_destroy), gui->window);
gtk_widget_show(gui->status_label);
gtk_widget_show(gui->disconnect_button);
gtk_widget_show(gui->quit_button);
gtk_widget_show(gui->button_box);
if (! hidden)
gtk_widget_show(gui->window);
if (minimize)
......
......@@ -29,6 +29,10 @@
typedef struct
{
GtkWidget *window;
GtkWidget *button_box;
GtkWidget *quit_button;
GtkWidget *disconnect_button;
GtkWidget *status_label;
} gui_t;
/*----------------------------------------------------------------------------
......@@ -39,4 +43,7 @@ void gui_sigterm(void);
void gui_run(gui_t *gui);
void gui_destroy(gui_t *gui);
void gui_remote_connected(gui_t *gui, const char *details);
void gui_remote_disconnected(gui_t *gui);
#endif
......@@ -33,6 +33,15 @@
#include "scan.h"
/*----------------------------------------------------------------------------
** I fought very hard to avoid global variables, but the spice channel_event
** callback simply had no way of passing back a data pointer.
** So we use this global variable to enable the use of the session connect
** and disconnect notices from spice
----------------------------------------------------------------------------*/
session_t *global_session;
void free_cursor_queue_item(gpointer data)
{
QXLCursorCmd *ccmd = (QXLCursorCmd *) data;
......@@ -161,6 +170,7 @@ int session_start(session_t *s)
s->running = 1;
end:
global_session = s;
if (rc)
session_end(s);
return rc;
......@@ -169,6 +179,7 @@ end:
void session_end(session_t *s)
{
s->running = 0;
global_session = NULL;
scanner_destroy(&s->scanner);
......@@ -184,14 +195,8 @@ int session_create(session_t *s)
return 0;
}
/* Important note - this is meant to be called from
a thread context *other* than the spice worker thread */
int session_recreate_primary(session_t *s)
static void flush_and_lock(session_t *s)
{
int rc;
while (1)
{
g_mutex_lock(&s->lock);
......@@ -202,7 +207,15 @@ int session_recreate_primary(session_t *s)
// FIXME - g_threads?
sched_yield();
}
}
/* Important note - this is meant to be called from
a thread context *other* than the spice worker thread */
int session_recreate_primary(session_t *s)
{
int rc;
flush_and_lock(s);
spice_destroy_primary(&s->spice);
display_destroy_fullscreen(&s->display);
......@@ -324,3 +337,17 @@ int session_get_one_led(session_t *session, const char *name)
return ret;
}
void session_remote_connected(const char *from)
{
if (!global_session)
return;
gui_remote_connected(&global_session->gui, from);
}
void session_remote_disconnected(void)
{
if (!global_session)
return;
gui_remote_disconnected(&global_session->gui);
}
......@@ -74,4 +74,7 @@ int session_push_cursor_image(session_t *s,
int x, int y, int w, int h, int xhot, int yhot,
int imglen, uint8_t *imgdata);
void session_remote_connected(const char *from);
void session_remote_disconnected(void);
#endif
......@@ -22,6 +22,8 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/socket.h>
#include <netdb.h>
#include "local_spice.h"
#include "x11spice.h"
......@@ -164,12 +166,26 @@ static void watch_remove(SpiceWatch *watch)
static void channel_event(int event, SpiceChannelEventInfo *info)
{
/* This event, as far as I can tell, is fairly useless.
You don't get any real information in the pointer, so
it's not a good opportunity to act on connect/disconnect,
for example */
g_debug("channel event [connection_id %d|type %d|id %d]",
info->connection_id, info->type, info->id);
g_debug("channel event %d [connection_id %d|type %d|id %d|flags %d]",
event, info->connection_id, info->type, info->id, info->flags);
if (event == SPICE_CHANNEL_EVENT_INITIALIZED && info->type == SPICE_CHANNEL_MAIN)
{
char from[NI_MAXHOST + NI_MAXSERV + 128];
strcpy(from, "Remote computer");
if (info->flags & SPICE_CHANNEL_EVENT_FLAG_ADDR_EXT)
{
int rc;
char host[NI_MAXHOST];
char server[NI_MAXSERV];
rc = getnameinfo((struct sockaddr *) &info->paddr_ext, info->plen_ext, host, sizeof(host), server, sizeof(server), 0);
if (rc == 0)
snprintf(from, sizeof(from), "Connection from %s:%s", host, server);
}
session_remote_connected(from);
}
if (event == SPICE_CHANNEL_EVENT_DISCONNECTED && info->type == SPICE_CHANNEL_MAIN)
session_remote_disconnected();
}
static void attach_worker(QXLInstance *qin, QXLWorker *qxl_worker)
......@@ -584,6 +600,7 @@ static int try_auto(spice_t *s, options_t *options)
if (fd < 0)
return X11SPICE_ERR_AUTO_FAILED;
// FIXME - do we need to also set the port so subsequent sessions use the same port?
return spice_server_set_listen_socket_fd(s->server, fd);
}
......
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