diff options
author | Marc-André Lureau <marcandre.lureau@redhat.com> | 2016-10-21 23:44:44 +0300 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2017-01-27 18:07:59 +0100 |
commit | 41ac54b253f41df924c350ef63564df8e1d8ad88 (patch) | |
tree | a6d8fdcb913b558c4f5ecc698bd82ae1a195705c /ui/gtk.c | |
parent | 5ebd67030c4e4bc702d07a3e10c909be4520f170 (diff) |
char: allocate CharDriverState as a single object
Use a single allocation for CharDriverState, this avoids extra
allocations & pointers, and is a step towards more object-oriented
CharDriver.
Gtk console is a bit peculiar, gd_vc_chr_set_echo() used to have a
temporary VirtualConsole to save the echo bit. Instead now, we consider
whether vcd->console is set or not, and restore the echo bit saved in
VCDriverState when calling gd_vc_vte_init().
The casts added are temporary, they are replaced with QOM type-safe
macros in a later patch in this series.
Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
Diffstat (limited to 'ui/gtk.c')
-rw-r--r-- | ui/gtk.c | 30 |
1 files changed, 19 insertions, 11 deletions
@@ -181,6 +181,12 @@ struct GtkDisplayState { bool ignore_keys; }; +typedef struct VCDriverState { + CharDriverState parent; + VirtualConsole *console; + bool echo; +} VCDriverState; + static void gd_grab_pointer(VirtualConsole *vc, const char *reason); static void gd_ungrab_pointer(GtkDisplayState *s); static void gd_grab_keyboard(VirtualConsole *vc, const char *reason); @@ -1685,7 +1691,8 @@ static void gd_vc_adjustment_changed(GtkAdjustment *adjustment, void *opaque) static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len) { - VirtualConsole *vc = chr->opaque; + VCDriverState *vcd = (VCDriverState *)chr; + VirtualConsole *vc = vcd->console; vte_terminal_feed(VTE_TERMINAL(vc->vte.terminal), (const char *)buf, len); return len; @@ -1693,9 +1700,14 @@ static int gd_vc_chr_write(CharDriverState *chr, const uint8_t *buf, int len) static void gd_vc_chr_set_echo(CharDriverState *chr, bool echo) { - VirtualConsole *vc = chr->opaque; + VCDriverState *vcd = (VCDriverState *)chr; + VirtualConsole *vc = vcd->console; - vc->vte.echo = echo; + if (vc) { + vc->vte.echo = echo; + } else { + vcd->echo = echo; + } } static int nb_vcs; @@ -1704,6 +1716,7 @@ static CharDriverState *vcs[MAX_VCS]; static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp) { static const CharDriver gd_vc_driver = { + .instance_size = sizeof(VCDriverState), .kind = CHARDEV_BACKEND_KIND_VC, .chr_write = gd_vc_chr_write, .chr_set_echo = gd_vc_chr_set_echo, @@ -1722,9 +1735,6 @@ static CharDriverState *gd_vc_handler(ChardevVC *vc, Error **errp) return NULL; } - /* Temporary, until gd_vc_vte_init runs. */ - chr->opaque = g_new0(VirtualConsole, 1); - vcs[nb_vcs++] = chr; return chr; @@ -1765,14 +1775,12 @@ static GSList *gd_vc_vte_init(GtkDisplayState *s, VirtualConsole *vc, GtkWidget *box; GtkWidget *scrollbar; GtkAdjustment *vadjustment; - VirtualConsole *tmp_vc = chr->opaque; + VCDriverState *vcd = (VCDriverState *)chr; vc->s = s; - vc->vte.echo = tmp_vc->vte.echo; - + vc->vte.echo = vcd->echo; vc->vte.chr = chr; - chr->opaque = vc; - g_free(tmp_vc); + vcd->console = vc; snprintf(buffer, sizeof(buffer), "vc%d", idx); vc->label = g_strdup_printf("%s", vc->vte.chr->label |