1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333
| #include "GtkItTerm.h"
/* Private structure definition. */
struct _GtkItTermPrivate
{
GtkWidget *vteterm ;
GtkWidget *terminal_scrollbar ;
};
G_DEFINE_TYPE_WITH_PRIVATE (GtkItTerm, gtk_itterm, GTK_TYPE_BOX)
static void gtk_itterm_class_init (GtkItTermClass *class);
static void gtk_itterm_init (GtkItTerm *itterm); // Constructeur
static void gtk_itterm_finalize (GObject * object); // Destructeur
static void
gtk_itterm_class_init (GtkItTermClass *class)
{
g_return_if_fail (class != NULL);
G_OBJECT_CLASS(class)->finalize = gtk_itterm_finalize; // destructeur
}
static void
gtk_itterm_init (GtkItTerm *itterm)
{
g_return_if_fail (itterm != NULL);
// Permet d'accéder aux données privées de l'objet
GtkItTermPrivate *priv = gtk_itterm_get_instance_private (itterm);
// Initialisation des différentes données privées
priv->vteterm = NULL;
priv->terminal_scrollbar = NULL;
}
static void
gtk_itterm_finalize (GObject *object)
{
GtkItTermPrivate *priv = gtk_itterm_get_instance_private (GTK_ITTERM(object));
// Destruction des données privées si nécessaire
G_OBJECT_CLASS (gtk_itterm_parent_class)->finalize (object);
}
/******************************************************************************/
void
setup_terminal(GtkWidget *vteterminal, gboolean is_sidebar)
{
#ifdef DEBUG
DEBUG_FUNC_MARK
#endif
// extern GUI *gui ;
/** Configure terminal partially according to the configuration stored settings. **/
// configure_terminal(vteterminal, true) ;
char *argv_cmd[2] = {vte_get_user_shell(), NULL} ;
/** Fork a new process: your default shell. The configurations files like .bashrc will be reading. **/
// The process is killed per example if you closing a terminals tab or by resetting the terminal else it is automatic by exiting the application.
// So we let no zoombies after us.
GPid child_pid ;
gchar **envp = g_get_environ() ;
vte_terminal_spawn_sync(VTE_TERMINAL(vteterminal), VTE_PTY_DEFAULT, g_get_home_dir(), argv_cmd, envp, G_SPAWN_DEFAULT, NULL, NULL, &child_pid, NULL, NULL);
g_strfreev(envp) ;
vte_terminal_watch_child(VTE_TERMINAL(vteterminal), child_pid) ;
/** Generate clipboard menu connect to the terminal. **/
GtkWidget *clipboard_menu = gtk_menu_new() ;
GtkWidget *copy_label = gtk_menu_item_new_with_label("Copy from terminal") ;
GtkWidget *paste_label = gtk_menu_item_new_with_label("Paste to terminal") ;
//GtkWidget *select_all_label = gtk_menu_item_new_with_label("Select all") ;
// TODO: reset, curdir sync
GtkWidget *separator_1 = gtk_separator_menu_item_new() ;
GtkWidget *new_tab_label = gtk_menu_item_new_with_label("Open new tab");
GtkWidget *close_tab_label = gtk_menu_item_new_with_label("Close tab");
GtkWidget *separator_2 = gtk_separator_menu_item_new() ;
GtkWidget *decr_font_label = gtk_menu_item_new_with_label("Decrease font-scale");
GtkWidget *incr_font_label = gtk_menu_item_new_with_label("Increase font-scale");
GtkWidget *separator_3 = gtk_separator_menu_item_new() ;
GtkWidget *reset_label = gtk_menu_item_new_with_label("Reset terminal");
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), copy_label) ;
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), paste_label) ;
if (is_sidebar) {
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), separator_1) ;
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), new_tab_label) ;
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), close_tab_label) ;
}
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), separator_2) ;
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), decr_font_label) ;
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), incr_font_label) ;
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), separator_3) ;
gtk_menu_shell_append(GTK_MENU_SHELL(clipboard_menu), reset_label) ;
/* GtkAccelGroup *accel_group ;
accel_group = gtk_accel_group_new() ;
gtk_window_add_accel_group(GTK_WINDOW(gui->main_window), accel_group);
gtk_widget_add_accelerator(GTK_WIDGET(copy_label), "activate", accel_group, GDK_KEY_Copy, GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE) ;
gtk_widget_add_accelerator(GTK_WIDGET(paste_label), "activate", accel_group, GDK_KEY_Insert, GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE) ;
gtk_widget_add_accelerator(GTK_WIDGET(incr_font_label), "activate", accel_group, GDK_KEY_plus, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE) ;
gtk_widget_add_accelerator(GTK_WIDGET(decr_font_label), "activate", accel_group, GDK_KEY_minus, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE) ;
if (is_sidebar) {
gtk_widget_add_accelerator(GTK_WIDGET(new_tab_label), "activate", accel_group, GDK_KEY_t, GDK_CONTROL_MASK | GDK_SHIFT_MASK, GTK_ACCEL_VISIBLE) ;
}
gtk_widget_show_all(clipboard_menu) ;
// g_signal_connect(G_OBJECT(vteterminal), "button-press-event", G_CALLBACK(display_clipboard_menu), clipboard_menu) ;
// g_signal_connect(G_OBJECT(copy_label), "activate", G_CALLBACK(clipboard_copy), vteterminal) ;
// g_signal_connect(G_OBJECT(paste_label), "activate", G_CALLBACK(clipboard_paste), vteterminal) ;
g_object_set_data(G_OBJECT(vteterminal), "Pid", &child_pid) ;
// g_signal_connect(G_OBJECT(reset_label), "activate", G_CALLBACK(reset_terminal), vteterminal) ;
// g_signal_connect(G_OBJECT(incr_font_label), "activate", G_CALLBACK(increase_font_size), vteterminal) ;
// g_signal_connect(G_OBJECT(decr_font_label), "activate", G_CALLBACK(decrease_font_size), vteterminal) ;
// g_signal_connect(G_OBJECT(vteterminal), "increase-font-size", G_CALLBACK(increase_font_size), vteterminal) ;
// g_signal_connect(G_OBJECT(vteterminal), "decrease-font-size", G_CALLBACK(decrease_font_size), vteterminal) ;
/* if (is_sidebar) {
g_signal_connect(G_OBJECT(new_tab_label), "activate", G_CALLBACK(add_new_terminals), NULL) ;
gint *ret = g_malloc(sizeof(gint)) ;
*ret = gtk_notebook_get_current_page(GTK_NOTEBOOK(gui->terminal_notebook)) ;
++(*ret) ;
g_signal_connect(G_OBJECT(close_tab_label), "activate", G_CALLBACK(remove_terminal_tabs_from_clipboard), ret ) ;
}
if (! is_sidebar) {
gtk_widget_destroy(separator_1) ;
gtk_widget_destroy(new_tab_label) ;
gtk_widget_destroy(close_tab_label) ;
}
*/
return ;
}
GtkWidget *
gtk_itterm_new ()
{
/** Pack a terminal with a GtkScrollbar in a container. **/
#ifdef DEBUG
DEBUG_FUNC_MARK
#endif
GtkItTerm *itterm = NULL;
// Création d'un nouvel objet
itterm = g_object_new (GTK_TYPE_ITTERM, NULL);
// Il faut indiquer quel est l'orientation du GtkBox
gtk_orientable_set_orientation (GTK_ORIENTABLE (itterm), GTK_ORIENTATION_HORIZONTAL);
// Récupération du pointeur sur les données privées
GtkItTermPrivate *priv = gtk_itterm_get_instance_private (itterm);
priv->vteterm = vte_terminal_new() ;
priv->terminal_scrollbar = gtk_scrollbar_new( GTK_ORIENTATION_VERTICAL, gtk_scrollable_get_vadjustment(GTK_SCROLLABLE(priv->vteterm))) ;
/* Cette déclaration devient inutile. Notre objet hérite d'un GtkBox.
* Nous utilisation directement notre objet pour insérer les éléments à
* l'intérieur.
*/
//terminal->terminal_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL,0) ;
gtk_widget_set_redraw_on_allocate(priv->vteterm , TRUE) ;
gtk_box_pack_start(GTK_BOX(itterm), priv->vteterm, TRUE, TRUE, 0) ;
gtk_box_pack_start(GTK_BOX(itterm), priv->terminal_scrollbar, FALSE, FALSE, 0) ;
gtk_box_set_homogeneous(GTK_BOX(itterm),FALSE);
// Configuration du vte terminal
gtk_itterm_configure_terminal(GTK_WIDGET (itterm), TRUE);
setup_terminal(priv->vteterm, FALSE);
return GTK_WIDGET(itterm);
}
GtkWidget*
gtk_itterm_get_vte_terminal (GtkWidget *itterm)
{
if (!itterm || !IS_GTK_ITTERM (itterm))
{
g_printerr ("gtk_itterm_get_vte_terminal(); attend un pointeur valide !\n");
return NULL;
}
// Récupération du pointeur sur les données privées
GtkItTermPrivate *priv = gtk_itterm_get_instance_private (GTK_ITTERM(itterm));
return priv->vteterm;
}
void
gtk_itterm_configure_terminal(GtkWidget *itterm, gboolean initialize)
{
/** Configure the VteTerminal according to the configuration. **/
#ifdef DEBUG
DEBUG_FUNC_MARK
#endif
if (!itterm || !IS_GTK_ITTERM (itterm))
{
g_printerr ("gtk_itterm_configure_terminal (); attend un pointeur valide !\n");
return;
}
GtkWidget *vteterminal = gtk_itterm_get_vte_terminal (itterm);
vte_terminal_set_default_colors(VTE_TERMINAL(vteterminal)) ;
/** Font settings: **/
PangoFontDescription *font_desc = pango_font_description_from_string("Monospace 10") ;
g_object_set(G_OBJECT(vteterminal), "font-desc", font_desc, NULL) ;
vte_terminal_set_font_scale(VTE_TERMINAL(vteterminal), 1.0) ;
/** Cursor settings: **/
vte_terminal_set_cursor_shape(VTE_TERMINAL(vteterminal), (0 == 0) ? VTE_CURSOR_SHAPE_BLOCK : (0 == 1) ? VTE_CURSOR_SHAPE_IBEAM : VTE_CURSOR_SHAPE_UNDERLINE) ;
vte_terminal_set_cursor_blink_mode(VTE_TERMINAL(vteterminal), (1 == 0) ? VTE_CURSOR_BLINK_SYSTEM : (1 == 1) ? VTE_CURSOR_BLINK_ON : VTE_CURSOR_BLINK_OFF) ;
vte_terminal_set_audible_bell(VTE_TERMINAL(vteterminal), TRUE) ;
vte_terminal_set_mouse_autohide(VTE_TERMINAL(vteterminal), FALSE) ;
/** Bold setting: **/
vte_terminal_set_allow_bold(VTE_TERMINAL(vteterminal), TRUE) ;
GdkRGBA bold_color ;
gdk_rgba_parse(&bold_color, "#FFFFFF") ;
vte_terminal_set_color_bold(VTE_TERMINAL(vteterminal), &bold_color) ;
/** Erasing keys binding. **/
g_object_set(G_OBJECT(vteterminal), "backspace-binding", (0 == 0) ? VTE_ERASE_AUTO :
(0 == 1) ? VTE_ERASE_ASCII_BACKSPACE :
(0 == 2) ? VTE_ERASE_ASCII_DELETE :
(0 == 3) ? VTE_ERASE_DELETE_SEQUENCE :
VTE_ERASE_TTY,
NULL) ;
g_object_set(G_OBJECT(vteterminal), "delete-binding", (0 == 0) ? VTE_ERASE_AUTO :
(0 == 1) ? VTE_ERASE_ASCII_BACKSPACE :
(0 == 2) ? VTE_ERASE_ASCII_DELETE :
(0 == 3) ? VTE_ERASE_DELETE_SEQUENCE :
VTE_ERASE_TTY,
NULL) ;
/** Colors settings: **/
GdkRGBA bg_terminal ;
gdk_rgba_parse(&bg_terminal, "#000000") ;
GdkRGBA fg_terminal ;
gdk_rgba_parse(&fg_terminal, "#FFFFFF") ;
vte_terminal_set_color_foreground(VTE_TERMINAL(vteterminal), &fg_terminal) ;
vte_terminal_set_color_background(VTE_TERMINAL(vteterminal), &bg_terminal) ;
/** Usual default settings: **/
vte_terminal_set_scrollback_lines(VTE_TERMINAL(vteterminal), -1) ;
vte_terminal_set_scroll_on_output(VTE_TERMINAL(vteterminal), TRUE) ;
vte_terminal_set_scroll_on_keystroke(VTE_TERMINAL(vteterminal), FALSE) ;
if (initialize) {
vte_terminal_set_encoding(VTE_TERMINAL(vteterminal), vte_terminal_get_encoding(VTE_TERMINAL(vteterminal)), NULL) ; // default
/** Mouse left button double click word separators: The following characters are not register as word separators. **/
// vte_terminal_set_word_char_exceptions(VTE_TERMINAL(vteterminal), vte_terminal_get_word_char_exceptions(VTE_TERMINAL(vteterminal)) ) ;
vte_terminal_set_rewrap_on_resize(VTE_TERMINAL(vteterminal), TRUE) ;
vte_terminal_set_size(VTE_TERMINAL(vteterminal), 80, 24) ;
}
} |
Partager