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) ...@@ -29,6 +29,21 @@ void gui_sigterm(void)
cached_gui = NULL; 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) int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden)
{ {
if (! gtk_init_check(&argc, &argv)) if (! gtk_init_check(&argc, &argv))
...@@ -36,6 +51,26 @@ int gui_create(gui_t *gui, int argc, char *argv[], int minimize, int hidden) ...@@ -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); gui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
g_signal_connect(gui->window, "destroy", G_CALLBACK(gui_sigterm), NULL); 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) if (! hidden)
gtk_widget_show(gui->window); gtk_widget_show(gui->window);
if (minimize) if (minimize)
......
...@@ -29,6 +29,10 @@ ...@@ -29,6 +29,10 @@
typedef struct typedef struct
{ {
GtkWidget *window; GtkWidget *window;
GtkWidget *button_box;
GtkWidget *quit_button;
GtkWidget *disconnect_button;
GtkWidget *status_label;
} gui_t; } gui_t;
/*---------------------------------------------------------------------------- /*----------------------------------------------------------------------------
...@@ -39,4 +43,7 @@ void gui_sigterm(void); ...@@ -39,4 +43,7 @@ void gui_sigterm(void);
void gui_run(gui_t *gui); void gui_run(gui_t *gui);
void gui_destroy(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 #endif
...@@ -33,6 +33,15 @@ ...@@ -33,6 +33,15 @@
#include "scan.h" #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) void free_cursor_queue_item(gpointer data)
{ {
QXLCursorCmd *ccmd = (QXLCursorCmd *) data; QXLCursorCmd *ccmd = (QXLCursorCmd *) data;
...@@ -161,6 +170,7 @@ int session_start(session_t *s) ...@@ -161,6 +170,7 @@ int session_start(session_t *s)
s->running = 1; s->running = 1;
end: end:
global_session = s;
if (rc) if (rc)
session_end(s); session_end(s);
return rc; return rc;
...@@ -169,6 +179,7 @@ end: ...@@ -169,6 +179,7 @@ end:
void session_end(session_t *s) void session_end(session_t *s)
{ {
s->running = 0; s->running = 0;
global_session = NULL;
scanner_destroy(&s->scanner); scanner_destroy(&s->scanner);
...@@ -184,14 +195,8 @@ int session_create(session_t *s) ...@@ -184,14 +195,8 @@ int session_create(session_t *s)
return 0; return 0;
} }
static void flush_and_lock(session_t *s)
/* 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;
while (1) while (1)
{ {
g_mutex_lock(&s->lock); g_mutex_lock(&s->lock);
...@@ -202,7 +207,15 @@ int session_recreate_primary(session_t *s) ...@@ -202,7 +207,15 @@ int session_recreate_primary(session_t *s)
// FIXME - g_threads? // FIXME - g_threads?
sched_yield(); 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); spice_destroy_primary(&s->spice);
display_destroy_fullscreen(&s->display); display_destroy_fullscreen(&s->display);
...@@ -324,3 +337,17 @@ int session_get_one_led(session_t *session, const char *name) ...@@ -324,3 +337,17 @@ int session_get_one_led(session_t *session, const char *name)
return ret; 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, ...@@ -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 x, int y, int w, int h, int xhot, int yhot,
int imglen, uint8_t *imgdata); int imglen, uint8_t *imgdata);
void session_remote_connected(const char *from);
void session_remote_disconnected(void);
#endif #endif
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/socket.h>
#include <netdb.h>
#include "local_spice.h" #include "local_spice.h"
#include "x11spice.h" #include "x11spice.h"
...@@ -164,12 +166,26 @@ static void watch_remove(SpiceWatch *watch) ...@@ -164,12 +166,26 @@ static void watch_remove(SpiceWatch *watch)
static void channel_event(int event, SpiceChannelEventInfo *info) static void channel_event(int event, SpiceChannelEventInfo *info)
{ {
/* This event, as far as I can tell, is fairly useless. g_debug("channel event %d [connection_id %d|type %d|id %d|flags %d]",
You don't get any real information in the pointer, so event, info->connection_id, info->type, info->id, info->flags);
it's not a good opportunity to act on connect/disconnect, if (event == SPICE_CHANNEL_EVENT_INITIALIZED && info->type == SPICE_CHANNEL_MAIN)
for example */ {
g_debug("channel event [connection_id %d|type %d|id %d]", char from[NI_MAXHOST + NI_MAXSERV + 128];
info->connection_id, info->type, info->id); 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) static void attach_worker(QXLInstance *qin, QXLWorker *qxl_worker)
...@@ -584,6 +600,7 @@ static int try_auto(spice_t *s, options_t *options) ...@@ -584,6 +600,7 @@ static int try_auto(spice_t *s, options_t *options)
if (fd < 0) if (fd < 0)
return X11SPICE_ERR_AUTO_FAILED; 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); 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