2 #include "tilda-terminal.h"
3 #include "tilda-terminal-dbus-glue.h"
5 // FIXME: temporary helpers for gettext
11 tilda_terminal_dbus_register_object (TildaTerminal *tt)
15 // Register this object with DBus
16 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d/Terminal%d",
17 tt->window_number, tt->number);
18 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tt));
23 * Start the current tt->shell in the given TildaTerminal
24 * NOTE: this will kill whatever is running in the terminal,
25 * NOTE: and run the current tt->shell instead :)
26 * Return: TRUE if ok, FALSE otherwise
29 tilda_terminal_start_shell (TildaTerminal *tt)
36 /* Launch a custom command if tt->shell is set (not NULL) */
39 /* Try to parse the user's custom command */
40 ret = g_shell_parse_argv (tt->shell, &argc, &argv, &error);
44 g_printerr (_("Problem parsing custom command: %s\n"), error->message);
45 g_printerr (_("Launching default shell instead\n"));
48 goto launch_default_shell;
51 /* Try to start the user's custom command */
52 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
53 argv[0], /* Command */
54 argv, /* Arg Vector */
55 NULL, /* Env Vector */
56 tt->working_directory, /* Start directory */
57 TRUE, /* Add to lastlog */
58 TRUE, /* Add to utmp */
59 TRUE); /* Add to wtmp */
66 g_printerr (_("Unable to launch custom command: %s\n"), tt->shell);
67 g_printerr (_("Launching default shell instead\n"));
69 goto launch_default_shell;
72 return TRUE; /* SUCCESS: the early way out */
77 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
78 NULL, /* Command -- VTE will figure it out */
79 NULL, /* Arg Vector */
80 NULL, /* Env Vector */
81 tt->working_directory, /* Start Directory */
82 TRUE, /* Add to lastlog */
83 TRUE, /* Add to utmp */
84 TRUE);/* Add to wtmp */
88 g_printerr (_("Unable to launch default shell\n"));
95 /*******************************************************************************
96 * All GObject stuff is below. You probably don't need to change this...
97 ******************************************************************************/
99 static GObjectClass *parent_class = NULL;
101 enum tilda_terminal_properties {
102 TILDA_TERMINAL_NUMBER = 1,
103 TILDA_TERMINAL_WINDOW_NUMBER,
106 /* All non-constructor-only properties */
107 TILDA_TERMINAL_BACKGROUND_IMAGE,
108 TILDA_TERMINAL_SHELL,
110 TILDA_TERMINAL_TITLE,
111 TILDA_TERMINAL_WORKING_DIRECTORY,
113 TILDA_TERMINAL_SCROLLBACK_LINES,
114 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
116 TILDA_TERMINAL_BACKSPACE_BINDING,
117 TILDA_TERMINAL_DELETE_BINDING,
118 TILDA_TERMINAL_DYNAMIC_TITLE,
119 TILDA_TERMINAL_EXIT_ACTION,
121 TILDA_TERMINAL_SCROLL_BACKGROUND,
122 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
123 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
124 TILDA_TERMINAL_ANTIALIASED,
125 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
126 TILDA_TERMINAL_CURSOR_BLINKS,
127 TILDA_TERMINAL_AUDIBLE_BELL,
128 TILDA_TERMINAL_VISIBLE_BELL,
129 TILDA_TERMINAL_DOUBLE_BUFFERED,
133 tilda_terminal_instance_init (GTypeInstance *instance,
136 TildaTerminal *self = (TildaTerminal *) instance;
138 /* Initialize instance members and allocate any necessary memory here.
139 * NOTE: any constructor-time values will be set later. */
140 self->dispose_has_run = FALSE;
143 self->vte_term = vte_terminal_new ();
144 self->scrollbar = gtk_vscrollbar_new (VTE_TERMINAL(self->vte_term)->adjustment);
145 self->hbox = gtk_hbox_new (FALSE, 0);
149 tilda_terminal_set_property (GObject *object,
154 TildaTerminal *self = (TildaTerminal *) object;
156 switch (property_id) {
158 case TILDA_TERMINAL_NUMBER:
159 self->number = g_value_get_int (value);
160 g_print ("terminal number: %d\n", self->number);
163 case TILDA_TERMINAL_WINDOW_NUMBER:
164 self->window_number = g_value_get_int (value);
165 g_print ("terminal parent window number: %d\n", self->window_number);
168 case TILDA_TERMINAL_TW:
169 self->parent_window = g_value_get_pointer (value);
170 g_print ("terminal parent window: 0x%x\n", self->parent_window);
171 g_print ("terminal parent window number (direct): %d\n", TILDA_WINDOW(self->parent_window)->number);
174 case TILDA_TERMINAL_BACKGROUND_IMAGE:
175 g_free (self->background_image);
176 self->background_image = g_value_dup_string (value);
177 vte_terminal_set_background_image_file (VTE_TERMINAL(self->vte_term), self->background_image);
178 g_print ("terminal back img: %s\n", self->background_image);
181 case TILDA_TERMINAL_SHELL:
182 g_free (self->shell);
183 self->shell = g_value_dup_string (value);
184 tilda_terminal_start_shell (self);
185 g_print ("terminal shell: %s\n", self->shell);
188 case TILDA_TERMINAL_FONT:
190 self->font = g_value_dup_string (value);
191 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
194 g_print ("terminal font: %s\n", self->font);
197 case TILDA_TERMINAL_TITLE:
198 g_free (self->title);
199 self->title = g_value_dup_string (value);
200 g_print ("terminal title: %s\n", self->title);
203 case TILDA_TERMINAL_WORKING_DIRECTORY:
204 g_free (self->working_directory);
205 self->working_directory = g_value_dup_string (value);
206 g_print ("terminal wrk dir: %s\n", self->working_directory);
209 case TILDA_TERMINAL_SCROLLBACK_LINES:
210 self->scrollback_lines = g_value_get_int (value);
211 vte_terminal_set_scrollback_lines (VTE_TERMINAL(self->vte_term), self->scrollback_lines);
212 g_print ("terminal scrollback lines: %d\n", self->scrollback_lines);
215 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
216 self->transparency_percent = g_value_get_int (value);
217 g_print ("terminal transp percent: %d\n", self->transparency_percent);
220 case TILDA_TERMINAL_BACKSPACE_BINDING:
221 self->backspace_binding = g_value_get_int (value);
222 vte_terminal_set_backspace_binding (VTE_TERMINAL(self->vte_term), self->backspace_binding);
223 g_print ("terminal backspace key: %d\n", self->backspace_binding);
226 case TILDA_TERMINAL_DELETE_BINDING:
227 self->delete_binding = g_value_get_int (value);
228 vte_terminal_set_delete_binding (VTE_TERMINAL(self->vte_term), self->delete_binding);
229 g_print ("terminal delete key: %d\n", self->delete_binding);
232 case TILDA_TERMINAL_DYNAMIC_TITLE:
233 self->dynamic_title = g_value_get_int (value);
234 g_print ("terminal dynamic title: %d\n", self->dynamic_title);
237 case TILDA_TERMINAL_EXIT_ACTION:
238 self->exit_action = g_value_get_int (value);
239 g_print ("terminal exit action: %d\n", self->exit_action);
242 case TILDA_TERMINAL_SCROLL_BACKGROUND:
243 self->scroll_background = g_value_get_boolean (value);
244 vte_terminal_set_scroll_background (VTE_TERMINAL(self->vte_term), self->scroll_background);
245 g_print ("terminal scroll background: %d\n", self->scroll_background);
248 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
249 self->scroll_on_output = g_value_get_boolean (value);
250 vte_terminal_set_scroll_on_output (VTE_TERMINAL(self->vte_term), self->scroll_on_output);
251 g_print ("terminal scroll on output: %d\n", self->scroll_on_output);
254 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
255 self->scroll_on_keystroke = g_value_get_boolean (value);
256 vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(self->vte_term), self->scroll_on_keystroke);
257 g_print ("terminal scroll on keystroke: %d\n", self->scroll_on_keystroke);
260 case TILDA_TERMINAL_ANTIALIASED:
261 self->antialiased = g_value_get_boolean (value);
262 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
265 g_print ("terminal antialiased: %d\n", self->antialiased);
268 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
269 self->allow_bold_text = g_value_get_boolean (value);
270 vte_terminal_set_allow_bold (VTE_TERMINAL(self->vte_term), self->allow_bold_text);
271 g_print ("terminal allow bold text: %d\n", self->allow_bold_text);
274 case TILDA_TERMINAL_CURSOR_BLINKS:
275 self->cursor_blinks = g_value_get_boolean (value);
276 vte_terminal_set_cursor_blinks (VTE_TERMINAL(self->vte_term), self->cursor_blinks);
277 g_print ("terminal cursor blinks: %d\n", self->cursor_blinks);
280 case TILDA_TERMINAL_AUDIBLE_BELL:
281 self->audible_bell = g_value_get_boolean (value);
282 vte_terminal_set_audible_bell (VTE_TERMINAL(self->vte_term), self->audible_bell);
283 g_print ("terminal audible bell: %d\n", self->audible_bell);
286 case TILDA_TERMINAL_VISIBLE_BELL:
287 self->visible_bell = g_value_get_boolean (value);
288 vte_terminal_set_visible_bell (VTE_TERMINAL(self->vte_term), self->visible_bell);
289 g_print ("terminal visible bell: %d\n", self->visible_bell);
292 case TILDA_TERMINAL_DOUBLE_BUFFERED:
293 self->double_buffered = g_value_get_boolean (value);
294 gtk_widget_set_double_buffered (GTK_WIDGET(self->vte_term), self->double_buffered);
295 g_print ("terminal double buffered: %d\n", self->double_buffered);
299 /* We don't have this property... */
300 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
306 tilda_terminal_get_property (GObject *object,
311 TildaTerminal *self = (TildaTerminal *) object;
313 switch (property_id) {
315 case TILDA_TERMINAL_NUMBER:
316 g_value_set_int (value, self->number);
319 case TILDA_TERMINAL_WINDOW_NUMBER:
320 g_value_set_int (value, self->window_number);
323 case TILDA_TERMINAL_TW:
324 g_value_set_pointer (value, self->parent_window);
327 case TILDA_TERMINAL_BACKGROUND_IMAGE:
328 g_value_set_string (value, self->background_image);
331 case TILDA_TERMINAL_SHELL:
332 g_value_set_string (value, self->shell);
335 case TILDA_TERMINAL_FONT:
336 g_value_set_string (value, self->font);
339 case TILDA_TERMINAL_TITLE:
340 g_value_set_string (value, self->title);
343 case TILDA_TERMINAL_WORKING_DIRECTORY:
344 g_value_set_string (value, self->working_directory);
347 case TILDA_TERMINAL_SCROLLBACK_LINES:
348 g_value_set_int (value, self->scrollback_lines);
351 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
352 g_value_set_int (value, self->transparency_percent);
355 case TILDA_TERMINAL_BACKSPACE_BINDING:
356 g_value_set_int (value, self->backspace_binding);
359 case TILDA_TERMINAL_DELETE_BINDING:
360 g_value_set_int (value, self->delete_binding);
363 case TILDA_TERMINAL_DYNAMIC_TITLE:
364 g_value_set_int (value, self->dynamic_title);
367 case TILDA_TERMINAL_EXIT_ACTION:
368 g_value_set_int (value, self->exit_action);
371 case TILDA_TERMINAL_SCROLL_BACKGROUND:
372 g_value_set_boolean (value, self->scroll_background);
375 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
376 g_value_set_boolean (value, self->scroll_on_output);
379 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
380 g_value_set_boolean (value, self->scroll_on_keystroke);
383 case TILDA_TERMINAL_ANTIALIASED:
384 g_value_set_boolean (value, self->antialiased);
387 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
388 g_value_set_boolean (value, self->allow_bold_text);
391 case TILDA_TERMINAL_CURSOR_BLINKS:
392 g_value_set_boolean (value, self->cursor_blinks);
395 case TILDA_TERMINAL_AUDIBLE_BELL:
396 g_value_set_boolean (value, self->audible_bell);
399 case TILDA_TERMINAL_VISIBLE_BELL:
400 g_value_set_boolean (value, self->visible_bell);
403 case TILDA_TERMINAL_DOUBLE_BUFFERED:
404 g_value_set_boolean (value, self->double_buffered);
408 /* We don't have this property... */
409 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
415 tilda_terminal_constructor (GType type,
416 guint n_construct_properties,
417 GObjectConstructParam *construct_properties)
422 /* Invoke parent constructor */
423 TildaTerminalClass *klass;
424 klass = TILDA_TERMINAL_CLASS (g_type_class_peek (TILDA_TYPE_TERMINAL));
425 obj = parent_class->constructor (type,
426 n_construct_properties,
427 construct_properties);
429 /* Do other stuff here. The object is ready to go now, and all
430 * ctor properties have been set.
432 * TODO: This is the place to do DBus-init */
433 self = TILDA_TERMINAL(obj);
435 /* Pack into the hbox */
436 gtk_box_pack_end (GTK_BOX(self->hbox), self->scrollbar, FALSE, FALSE, 0);
437 gtk_box_pack_end (GTK_BOX(self->hbox), self->vte_term, TRUE, TRUE, 0);
438 gtk_widget_show (self->scrollbar);
441 g_signal_connect (G_OBJECT(self->vte_term), "child-exited",
442 G_CALLBACK(gtk_main_quit), self);
444 tilda_terminal_start_shell (self);
445 tilda_terminal_dbus_register_object (self);
451 tilda_terminal_dispose (GObject *obj)
453 TildaTerminal *self = (TildaTerminal *) obj;
455 /* We don't want to run dispose twice, so just return immediately */
456 if (self->dispose_has_run)
459 self->dispose_has_run = TRUE;
462 * In dispose, you are supposed to free all types referenced from this
463 * object which might themselves hold a reference to self. Generally,
464 * the most simple solution is to unref all members on which you own a
468 /* Chain up to the parent class */
469 G_OBJECT_CLASS (parent_class)->dispose (obj);
473 tilda_terminal_finalize (GObject *obj)
475 TildaTerminal *self = (TildaTerminal *) obj;
478 * Here, complete object destruction.
479 * You might not need to do much...
482 // TODO: g_free() any primitives here
483 g_free (self->background_image);
484 g_free (self->shell);
486 g_free (self->title);
487 g_free (self->working_directory);
490 /* Chain up to the parent class */
491 G_OBJECT_CLASS (parent_class)->finalize (obj);
495 tilda_terminal_class_init (gpointer g_class,
496 gpointer g_class_data)
498 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
499 TildaTerminalClass *klass = TILDA_TERMINAL_CLASS (g_class);
502 /* Hook our functions to this type */
503 gobject_class->set_property = tilda_terminal_set_property;
504 gobject_class->get_property = tilda_terminal_get_property;
505 gobject_class->dispose = tilda_terminal_dispose;
506 gobject_class->finalize = tilda_terminal_finalize;
507 gobject_class->constructor = tilda_terminal_constructor;
509 parent_class = g_type_class_peek_parent (klass);
511 /* Hook the TildaTerminal type into DBus */
512 dbus_g_object_type_install_info (tilda_terminal_get_type(), &dbus_glib_tilda_terminal_object_info);
514 /* Install all of the properties */
515 pspec = g_param_spec_int ("number",
517 "Set terminal's number",
519 INT_MAX, // max value
521 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
523 g_object_class_install_property (gobject_class,
524 TILDA_TERMINAL_NUMBER,
527 pspec = g_param_spec_int ("window-number",
528 "Number of the window to which this terminal belongs",
529 "Set the number of the parent window",
533 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
535 g_object_class_install_property (gobject_class,
536 TILDA_TERMINAL_WINDOW_NUMBER,
539 pspec = g_param_spec_pointer ("parent-window",
540 "Pointer to terminal's parent TildaWindow",
541 "Set the pointer to the terminal's parent TildaWindow",
542 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
544 g_object_class_install_property (gobject_class,
548 pspec = g_param_spec_string ("background-image",
549 "Terminal's background image",
550 "Get/Set terminal's background image",
554 g_object_class_install_property (gobject_class,
555 TILDA_TERMINAL_BACKGROUND_IMAGE,
558 pspec = g_param_spec_string ("shell",
560 "Get/Set terminal's shell",
564 g_object_class_install_property (gobject_class,
565 TILDA_TERMINAL_SHELL,
568 pspec = g_param_spec_string ("font",
570 "Get/Set terminal's font",
574 g_object_class_install_property (gobject_class,
578 pspec = g_param_spec_string ("title",
580 "Get/Set terminal's title",
584 g_object_class_install_property (gobject_class,
585 TILDA_TERMINAL_TITLE,
588 pspec = g_param_spec_string ("working-directory",
589 "Terminal's initial working directory",
590 "Get/Set terminal's initial working directory",
594 g_object_class_install_property (gobject_class,
595 TILDA_TERMINAL_WORKING_DIRECTORY,
598 pspec = g_param_spec_int ("scrollback-lines",
599 "Terminal's scrollback amount (lines)",
600 "Get/Set terminal's scrollback amount",
602 INT_MAX, // TODO: artificially limit this?
606 g_object_class_install_property (gobject_class,
607 TILDA_TERMINAL_SCROLLBACK_LINES,
610 pspec = g_param_spec_int ("transparency-percent",
611 "Terminal's transparency (percent)",
612 "Get/Set terminal's transparency",
618 g_object_class_install_property (gobject_class,
619 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
622 pspec = g_param_spec_int ("backspace-binding",
623 "Terminal's backspace binding",
624 "Get/Set terminal's backspace key binding",
626 VTE_ERASE_DELETE_SEQUENCE,
630 g_object_class_install_property (gobject_class,
631 TILDA_TERMINAL_BACKSPACE_BINDING,
634 pspec = g_param_spec_int ("delete-binding",
635 "Terminal's delete binding",
636 "Get/Set terminal's delete key binding",
638 VTE_ERASE_DELETE_SEQUENCE,
642 g_object_class_install_property (gobject_class,
643 TILDA_TERMINAL_DELETE_BINDING,
646 pspec = g_param_spec_int ("dynamic-title",
647 "Terminal's dynamic title generation method",
648 "Get/Set terminal's dynamic title generation method",
654 g_object_class_install_property (gobject_class,
655 TILDA_TERMINAL_DYNAMIC_TITLE,
658 pspec = g_param_spec_int ("exit-action",
659 "Terminal's action upon child exit",
660 "Get/Set terminal's action upon child exit",
666 g_object_class_install_property (gobject_class,
667 TILDA_TERMINAL_EXIT_ACTION,
670 pspec = g_param_spec_boolean ("scroll-background",
671 "Controls terminal's scrolling behavior",
672 "Get/Set terminal's scrolling behavior",
676 g_object_class_install_property (gobject_class,
677 TILDA_TERMINAL_SCROLL_BACKGROUND,
680 pspec = g_param_spec_boolean ("scroll-on-output",
681 "Controls terminal's scrolling behavior on output",
682 "Get/Set terminal's scrolling behavior on output",
686 g_object_class_install_property (gobject_class,
687 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
690 pspec = g_param_spec_boolean ("scroll-on-keystroke",
691 "Controls the terminal's scrolling behavior on keystroke",
692 NULL, FALSE, G_PARAM_READWRITE);
694 g_object_class_install_property (gobject_class,
695 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
698 pspec = g_param_spec_boolean ("antialiased",
699 "Attempt to antialias fonts",
700 NULL, FALSE, G_PARAM_READWRITE);
702 g_object_class_install_property (gobject_class,
703 TILDA_TERMINAL_ANTIALIASED,
706 pspec = g_param_spec_boolean ("allow-bold-text",
708 NULL, FALSE, G_PARAM_READWRITE);
710 g_object_class_install_property (gobject_class,
711 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
714 pspec = g_param_spec_boolean ("cursor-blinks",
715 NULL, NULL, FALSE, G_PARAM_READWRITE);
717 g_object_class_install_property (gobject_class,
718 TILDA_TERMINAL_CURSOR_BLINKS,
721 pspec = g_param_spec_boolean ("audible-bell",
722 NULL, NULL, FALSE, G_PARAM_READWRITE);
724 g_object_class_install_property (gobject_class,
725 TILDA_TERMINAL_AUDIBLE_BELL,
728 pspec = g_param_spec_boolean ("visible-bell",
729 NULL, NULL, FALSE, G_PARAM_READWRITE);
731 g_object_class_install_property (gobject_class,
732 TILDA_TERMINAL_VISIBLE_BELL,
735 pspec = g_param_spec_boolean ("double-buffered",
736 NULL, NULL, FALSE, G_PARAM_READWRITE);
738 g_object_class_install_property (gobject_class,
739 TILDA_TERMINAL_DOUBLE_BUFFERED,
744 tilda_terminal_get_type (void)
746 static GType type = 0;
750 static const GTypeInfo info = {
751 sizeof (TildaTerminalClass),
752 NULL, /* base_init */
753 NULL, /* base_finalize */
754 tilda_terminal_class_init, /* class_init */
755 NULL, /* class_finalize */
756 NULL, /* class_data */
757 sizeof (TildaTerminal),
759 tilda_terminal_instance_init, /* instance_init */
762 type = g_type_register_static (G_TYPE_OBJECT,
773 int main (int argc, char *argv[])
776 gint test_number = INT_MIN;
777 gchar *test_string = NULL;
779 /* Initialize the GObject type system */
781 gtk_init (&argc, &argv);
783 tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 10, NULL);
784 g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
785 g_assert (test_number == 10);
787 g_object_unref (G_OBJECT (tt));
789 tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 22, NULL);
790 g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
791 g_assert (test_number == 22);
793 g_object_set (G_OBJECT (tt), "font", "hello I'm a font");
794 g_object_set (G_OBJECT (tt), "font", "Bitstream Vera Sans Mono 13");
796 g_object_get (G_OBJECT (tt), "font", &test_string, NULL);
797 g_print ("Read Font: %s\n", test_string);
798 // NOTE: you MUST free the string!!!!
799 g_free (test_string);
801 g_object_set (G_OBJECT (tt), "transparency-percent", 50);
803 g_object_unref (G_OBJECT (tt));
810 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */