]> git.proxmox.com Git - spiceterm.git/blobdiff - screen.c
implement resize
[spiceterm.git] / screen.c
index 231fbbe5ec9f6d2db821755d0c28b352943231ae..ff36f18d98ef35ffd4449c48b7c8060ad5184312 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -39,6 +39,7 @@
 #include <spice/enums.h>
 #include <spice/macros.h>
 #include <spice/qxl_dev.h>
+#include <spice/vd_agent.h>
 
 #include "glyphs.h"
 
@@ -89,9 +90,6 @@ spice_screen_destroy_update(SimpleSpiceUpdate *update)
     g_free(update);
 }
 
-#define DEFAULT_WIDTH 640
-#define DEFAULT_HEIGHT 320
-
 static int unique = 0x0ffff + 1;
 
 static void 
@@ -349,6 +347,22 @@ create_primary_surface(SpiceScreen *spice_screen, uint32_t width,
     qxl_worker->create_primary_surface(qxl_worker, 0, &surface);
 }
 
+void 
+spice_screen_resize(SpiceScreen *spice_screen, uint32_t width,
+                    uint32_t height)
+{
+    QXLWorker *qxl_worker = spice_screen->qxl_worker;
+
+    if (spice_screen->width == width && spice_screen->height == height) {
+        return;
+    }
+
+    qxl_worker->destroy_primary_surface(qxl_worker, 0);
+
+    create_primary_surface(spice_screen, width, height);
+}
+                       
+
 QXLDevMemSlot slot = {
     .slot_group_id = MEM_SLOT_GROUP_ID,
     .slot_id = 0,
@@ -370,7 +384,7 @@ attache_worker(QXLInstance *qin, QXLWorker *_qxl_worker)
  
     spice_screen->qxl_worker = _qxl_worker;
     spice_screen->qxl_worker->add_memslot(spice_screen->qxl_worker, &slot);
-    create_primary_surface(spice_screen, DEFAULT_WIDTH, DEFAULT_HEIGHT);
+    create_primary_surface(spice_screen, spice_screen->width, spice_screen->height);
     spice_screen->qxl_worker->start(spice_screen->qxl_worker);
 }
 
@@ -631,48 +645,21 @@ QXLInterface display_sif = {
     .set_client_capabilities = set_client_capabilities,
 };
 
-/* vdagent interface - not sure why we need that? */
-static int 
-vmc_write(SpiceCharDeviceInstance *sin, const uint8_t *buf, int len)
-{
-    return len;
-}
-
-static int 
-vmc_read(SpiceCharDeviceInstance *sin, uint8_t *buf, int len)
-{
-    return 0;
-}
-
-static void 
-vmc_state(SpiceCharDeviceInstance *sin, int connected)
-{
-
-}
-
-static SpiceCharDeviceInterface vdagent_sif = {
-    .base.type          = SPICE_INTERFACE_CHAR_DEVICE,
-    .base.description   = "spice virtual channel char device",
-    .base.major_version = SPICE_INTERFACE_CHAR_DEVICE_MAJOR,
-    .base.minor_version = SPICE_INTERFACE_CHAR_DEVICE_MINOR,
-    .state              = vmc_state,
-    .write              = vmc_write,
-    .read               = vmc_read,
-};
-
-SpiceCharDeviceInstance vdagent_sin = {
-    .base = {
-        .sif = &vdagent_sif.base,
-    },
-    .subtype = "vdagent",
-};
 
 void 
-spice_screen_draw_char(SpiceScreen *spice_screen, int x, int y, gunichar2 ch, TextAttributes attrib)
+spice_screen_draw_char(SpiceScreen *spice_screen, int x, int y, gunichar2 ch, 
+                       TextAttributes attrib)
 {
     int fg, bg;
 
+    int invers;
     if (attrib.invers) {
+        invers = attrib.selected ? 0 : 1;
+    } else {
+        invers = attrib.selected ? 1 : 0;
+    }        
+
+    if (invers) {
         bg = attrib.fgcol;
         fg = attrib.bgcol;
     } else {
@@ -694,12 +681,15 @@ spice_screen_draw_char(SpiceScreen *spice_screen, int x, int y, gunichar2 ch, Te
 }
 
 SpiceScreen *
-spice_screen_new(SpiceCoreInterface *core, guint timeout)
+spice_screen_new(SpiceCoreInterface *core, uint32_t width, uint32_t height, guint timeout)
 {
     int port = 5912;
     SpiceScreen *spice_screen = g_new0(SpiceScreen, 1);
     SpiceServer* server = spice_server_new();
 
+    spice_screen->width = width;
+    spice_screen->height = height;
+
     spice_screen->command_cond = g_cond_new();
     spice_screen->command_mutex = g_mutex_new();
 
@@ -731,7 +721,5 @@ spice_screen_new(SpiceCoreInterface *core, guint timeout)
 
     spice_server_add_interface(spice_screen->server, &spice_screen->qxl_instance.base);
 
-    spice_server_add_interface(server, &vdagent_sin.base);
-
     return spice_screen;
 }