Replace the XTerm widget with VTE

It does not seem to be functional yet: no shell seems to be started.

This defaults to Gtk+ 3.
This commit is contained in:
Pierre Pronchery 2018-09-27 02:36:14 +02:00
parent a63c05a846
commit cde6cbd602
2 changed files with 36 additions and 4 deletions

View File

@ -1,9 +1,17 @@
targets=terminal targets=terminal
#cppflags=-D EMBEDDED #cppflags=-D EMBEDDED
cflags_force=`pkg-config --cflags libDesktop`
cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector cflags=-W -Wall -g -O2 -pedantic -fPIE -D_FORTIFY_SOURCE=2 -fstack-protector
ldflags_force=`pkg-config --libs libDesktop` -lintl
ldflags=-pie -Wl,-z,relro -Wl,-z,now ldflags=-pie -Wl,-z,relro -Wl,-z,now
#for XTerm
#cppflags_force=-DWITH_XTERM
#cflags_force=`pkg-config --cflags libDesktop`
#ldflags_force=`pkg-config --libs libDesktop` -lintl
#for Gtk+ 2 (VTE)
#cflags_force=`pkg-config --cflags libDesktop vte`
#ldflags_force=`pkg-config --libs libDesktop vte` -lintl
#for Gtk+ 3 (VTE)
cflags_force=`pkg-config --cflags libDesktop vte-2.91`
ldflags_force=`pkg-config --libs libDesktop vte-2.91` -lintl
dist=Makefile,terminal.h dist=Makefile,terminal.h
[terminal] [terminal]

View File

@ -43,9 +43,13 @@ static char const _license[] =
#include <libintl.h> #include <libintl.h>
#include <gtk/gtk.h> #include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h> #include <gdk/gdkkeysyms.h>
#if WITH_XTERM
# if GTK_CHECK_VERSION(3, 0, 0) # if GTK_CHECK_VERSION(3, 0, 0)
# include <gtk/gtkx.h> # include <gtk/gtkx.h>
# endif # endif
#else
# include <vte/vte.h>
#endif
#include <System.h> #include <System.h>
#include <Desktop.h> #include <Desktop.h>
#include "terminal.h" #include "terminal.h"
@ -95,9 +99,13 @@ struct _TerminalTab
Terminal * terminal; Terminal * terminal;
GtkWidget * widget; GtkWidget * widget;
GtkWidget * label; GtkWidget * label;
#if WITH_XTERM
GtkWidget * socket; GtkWidget * socket;
GPid pid; GPid pid;
guint source; guint source;
#else
GtkWidget * socket;
#endif
}; };
@ -119,7 +127,9 @@ static void _terminal_close_tab(Terminal * terminal, unsigned int i);
static void _terminal_close_all(Terminal * terminal); static void _terminal_close_all(Terminal * terminal);
/* callbacks */ /* callbacks */
#if WITH_XTERM
static void _terminal_on_child_watch(GPid pid, gint status, gpointer data); static void _terminal_on_child_watch(GPid pid, gint status, gpointer data);
#endif
static void _terminal_on_close(gpointer data); static void _terminal_on_close(gpointer data);
static gboolean _terminal_on_closex(gpointer data); static gboolean _terminal_on_closex(gpointer data);
static void _terminal_on_fullscreen(gpointer data); static void _terminal_on_fullscreen(gpointer data);
@ -285,10 +295,12 @@ void terminal_delete(Terminal * terminal)
for(i = 0; i < terminal->tabs_cnt; i++) for(i = 0; i < terminal->tabs_cnt; i++)
{ {
#if WITH_XTERM
if(terminal->tabs[i]->source > 0) if(terminal->tabs[i]->source > 0)
g_source_remove(terminal->tabs[i]->source); g_source_remove(terminal->tabs[i]->source);
if(terminal->tabs[i]->pid > 0) if(terminal->tabs[i]->pid > 0)
g_spawn_close_pid(terminal->tabs[i]->pid); g_spawn_close_pid(terminal->tabs[i]->pid);
#endif
free(terminal->tabs[i]); free(terminal->tabs[i]);
} }
/* FIXME also take care of the sub-processes */ /* FIXME also take care of the sub-processes */
@ -352,7 +364,11 @@ static int _terminal_open_tab(Terminal * terminal)
terminal->tabs[terminal->tabs_cnt++] = tab; terminal->tabs[terminal->tabs_cnt++] = tab;
/* create the tab */ /* create the tab */
tab->terminal = terminal; tab->terminal = terminal;
#if WITH_XTERM
tab->socket = gtk_socket_new(); tab->socket = gtk_socket_new();
#else
tab->socket = vte_terminal_new();
#endif
tab->widget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0); tab->widget = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
tab->label = gtk_label_new(_("xterm")); tab->label = gtk_label_new(_("xterm"));
gtk_box_pack_start(GTK_BOX(tab->widget), tab->label, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(tab->widget), tab->label, TRUE, TRUE, 0);
@ -377,6 +393,7 @@ static int _terminal_open_tab(Terminal * terminal)
gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(terminal->notebook), gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(terminal->notebook),
tab->socket, TRUE); tab->socket, TRUE);
#endif #endif
#if WITH_XTERM
/* launch xterm */ /* launch xterm */
snprintf(buf, sizeof(buf), "%lu", gtk_socket_get_id( snprintf(buf, sizeof(buf), "%lu", gtk_socket_get_id(
GTK_SOCKET(tab->socket))); GTK_SOCKET(tab->socket)));
@ -398,6 +415,7 @@ static int _terminal_open_tab(Terminal * terminal)
} }
tab->source = g_child_watch_add(tab->pid, _terminal_on_child_watch, tab->source = g_child_watch_add(tab->pid, _terminal_on_child_watch,
terminal); terminal);
#endif
gtk_widget_show(tab->socket); gtk_widget_show(tab->socket);
return 0; return 0;
} }
@ -425,6 +443,7 @@ static int _terminal_open_window(Terminal * terminal)
/* terminal_close_all */ /* terminal_close_all */
static void _terminal_close_all(Terminal * terminal) static void _terminal_close_all(Terminal * terminal)
{ {
#if WITH_XTERM
GPid * pid; GPid * pid;
size_t i; size_t i;
size_t cnt; size_t cnt;
@ -452,6 +471,7 @@ static void _terminal_close_all(Terminal * terminal)
fprintf(stderr, "%s: %s: %s\n", PROGNAME, "kill", fprintf(stderr, "%s: %s: %s\n", PROGNAME, "kill",
strerror(errno)); strerror(errno));
free(pid); free(pid);
#endif
gtk_main_quit(); gtk_main_quit();
} }
@ -462,6 +482,7 @@ static void _terminal_close_tab(Terminal * terminal, unsigned int i)
#ifdef DEBUG #ifdef DEBUG
fprintf(stderr, "DEBUG: %s(%u)\n", __func__, i); fprintf(stderr, "DEBUG: %s(%u)\n", __func__, i);
#endif #endif
#if WITH_XTERM
if(terminal->tabs[i]->source > 0) if(terminal->tabs[i]->source > 0)
g_source_remove(terminal->tabs[i]->source); g_source_remove(terminal->tabs[i]->source);
if(terminal->tabs[i]->pid >= 0) if(terminal->tabs[i]->pid >= 0)
@ -471,6 +492,7 @@ static void _terminal_close_tab(Terminal * terminal, unsigned int i)
fprintf(stderr, "%s: %s: %s\n", PROGNAME, "kill", fprintf(stderr, "%s: %s: %s\n", PROGNAME, "kill",
strerror(errno)); strerror(errno));
} }
#endif
free(terminal->tabs[i]); free(terminal->tabs[i]);
gtk_notebook_remove_page(GTK_NOTEBOOK(terminal->notebook), i); gtk_notebook_remove_page(GTK_NOTEBOOK(terminal->notebook), i);
memmove(&terminal->tabs[i], &terminal->tabs[i + 1], memmove(&terminal->tabs[i], &terminal->tabs[i + 1],
@ -482,6 +504,7 @@ static void _terminal_close_tab(Terminal * terminal, unsigned int i)
/* callbacks */ /* callbacks */
#if WITH_XTERM
/* terminal_on_child_watch */ /* terminal_on_child_watch */
static void _terminal_on_child_watch(GPid pid, gint status, gpointer data) static void _terminal_on_child_watch(GPid pid, gint status, gpointer data)
{ {
@ -516,6 +539,7 @@ static void _terminal_on_child_watch(GPid pid, gint status, gpointer data)
_terminal_close_tab(terminal, i); _terminal_close_tab(terminal, i);
} }
} }
#endif
/* terminal_on_close */ /* terminal_on_close */