2 #include "tilda-terminal.h"
3 #include "tilda-terminal-dbus-glue.h"
5 // FIXME: temporary helpers for gettext
10 #define DINGUS1 "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?"
11 #define DINGUS2 "(((news|telnet|nttp|file|http|ftp|https)://)|(www|ftp)[-A-Za-z0-9]*\\.)[-A-Za-z0-9\\.]+(:[0-9]*)?/[-A-Za-z0-9_\\$\\.\\+\\!\\*\\(\\),;:@&=\\?/~\\#\\%]*[^]'\\.}>\\) ,\\\"]"
15 tilda_terminal_dbus_register_object (TildaTerminal *tt)
19 // Register this object with DBus
20 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d/Terminal%d",
21 tt->window_number, tt->number);
22 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tt));
27 * Start the current tt->shell in the given TildaTerminal
28 * NOTE: this will kill whatever is running in the terminal,
29 * NOTE: and run the current tt->shell instead :)
30 * Return: TRUE if ok, FALSE otherwise
33 tilda_terminal_start_shell (TildaTerminal *tt)
40 /* Launch a custom command if tt->shell is set (not NULL) */
43 /* Try to parse the user's custom command */
44 ret = g_shell_parse_argv (tt->shell, &argc, &argv, &error);
48 g_printerr (_("Problem parsing custom command: %s\n"), error->message);
49 g_printerr (_("Launching default shell instead\n"));
52 goto launch_default_shell;
55 /* Try to start the user's custom command */
56 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
57 argv[0], /* Command */
58 argv, /* Arg Vector */
59 NULL, /* Env Vector */
60 tt->working_directory, /* Start directory */
61 TRUE, /* Add to lastlog */
62 TRUE, /* Add to utmp */
63 TRUE); /* Add to wtmp */
70 g_printerr (_("Unable to launch custom command: %s\n"), tt->shell);
71 g_printerr (_("Launching default shell instead\n"));
73 goto launch_default_shell;
76 return TRUE; /* SUCCESS: the early way out */
81 ret = vte_terminal_fork_command (VTE_TERMINAL(tt->vte_term),
82 NULL, /* Command -- VTE will figure it out */
83 NULL, /* Arg Vector */
84 NULL, /* Env Vector */
85 tt->working_directory, /* Start Directory */
86 TRUE, /* Add to lastlog */
87 TRUE, /* Add to utmp */
88 TRUE);/* Add to wtmp */
92 g_printerr (_("Unable to launch default shell\n"));
100 * Called when the child process running in the VteTerminal exits.
103 tilda_terminal_child_exited_cb (GtkWidget *widget, gpointer data)
105 TildaTerminal *self = TILDA_TERMINAL(data);
107 /* These can stay here. They don't need to go into a header because
108 * they are only used at this point in the code. */
109 enum exit_actions { HOLD_TERMINAL_OPEN, RESTART_COMMAND, EXIT_TERMINAL };
111 /* Check the user's preference for what to do when the child terminal
112 * is closed. Take the appropriate action */
113 switch (self->exit_action)
116 tilda_window_remove_term (TILDA_WINDOW(self->parent_window), self->number);
118 case RESTART_COMMAND:
119 vte_terminal_feed (VTE_TERMINAL(self->vte_term), "\r\n\r\n", 4);
120 tilda_terminal_start_shell (self);
122 case HOLD_TERMINAL_OPEN:
130 * Called when the child window title changes. Determines if a new
131 * title needs to be put into the notebook's tab label.
134 tilda_terminal_window_title_changed_cb (GtkWidget *widget, gpointer data)
136 TildaTerminal *self = TILDA_TERMINAL(data);
137 TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
139 const gchar *vte_title;
142 enum dynamic_titles { NOT_DISPLAYED, AFTER_INITIAL, BEFORE_INITIAL, REPLACE_INITIAL };
143 label = gtk_notebook_get_tab_label (GTK_NOTEBOOK(parent_window->notebook), self->hbox);
145 /* If we aren't using a dynamic title -- NOT_DISPLAYED -- then just
146 * set it to the static title and exit */
147 if (!self->dynamic_title)
149 gtk_label_set_text (GTK_LABEL(label), self->title);
153 /* Get the title from VTE */
154 vte_title = vte_terminal_get_window_title (VTE_TERMINAL (widget));
156 /* Take the appropriate action */
157 switch (self->dynamic_title)
159 case REPLACE_INITIAL:
160 new_title = g_strdup (vte_title);
164 new_title = g_strdup_printf ("%s - %s", vte_title, self->title);
168 new_title = g_strdup_printf ("%s - %s", self->title, vte_title);
173 g_printerr (_("FIXME: Bad value of self->dynamic_title\n"));
174 new_title = g_strdup(self->title);
178 gtk_label_set_text (GTK_LABEL(label), new_title);
183 * Gets called whenever there is a button-press event in the VteTerminal. It
184 * is used to open the user's web browser, for example.
187 tilda_terminal_button_press_cb (GtkWidget *widget,
188 GdkEventButton *event,
191 GError *error = NULL;
192 TildaTerminal *self = TILDA_TERMINAL(data);
193 VteTerminal *terminal = VTE_TERMINAL(self->vte_term);
194 gint tag, xpad, ypad;
195 gchar *match, *cmd, *web_browser_cmd;
196 gboolean ret = FALSE;
198 switch (event->button)
200 case 3: /* Right Click */
201 // FIXME: need to add this
202 //popup_menu (tt->tw, tt);
203 g_print ("FIXME: popup_menu() here\n");
206 case 2: /* Middle Click */
209 case 1: /* Left Click */
210 vte_terminal_get_padding (terminal, &xpad, &ypad);
211 match = vte_terminal_match_check (terminal,
212 (event->x - ypad) / terminal->char_width,
213 (event->y - ypad) / terminal->char_height,
216 /* Check if we can launch a web browser, and do so if possible */
217 if ((event->state & GDK_CONTROL_MASK) && match != NULL)
220 g_print ("Got a Ctrl+Left Click -- Matched: `%s' (%d)\n", match, tag);
222 web_browser_cmd = g_strescape (self->web_browser, NULL);
223 cmd = g_strdup_printf ("%s %s", web_browser_cmd, match);
225 g_print ("Launching command: `%s'\n", cmd);
227 ret = g_spawn_command_line_async(cmd, &error);
229 /* Check that the command launched */
232 g_printerr (_("Failed to launch web browser command: `%s'\n"), cmd);
233 g_printerr (_("Error message: %s\n"), error->message);
236 /* Free allocated memory */
237 g_free (web_browser_cmd);
241 /* Always free match if it is non NULL */
253 * Set the given TildaTerminal to the appropriate transparency level
254 * based on the self->transparency_percent member. */
256 tilda_terminal_set_transparent (TildaTerminal *self)
258 TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
261 /* Convert the transparency to VTE's format */
262 temp = ((gdouble) self->transparency_percent) / 100.0;
264 if (self->transparency_percent > 0)
266 vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), temp);
267 vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), (1.0 - temp) * 0xffff);
269 /* Use fake transparency if necessary */
270 vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term),
271 !parent_window->have_real_transparency);
275 /* Turn off transparency */
276 vte_terminal_set_background_saturation (VTE_TERMINAL(self->vte_term), 0);
277 vte_terminal_set_opacity (VTE_TERMINAL(self->vte_term), 0xffff);
278 vte_terminal_set_background_transparent (VTE_TERMINAL(self->vte_term), FALSE);
282 * Set the scrollbar position of the given TildaTerminal to
283 * the value in self->scrollbar_position.
286 tilda_terminal_set_scrollbar_position (TildaTerminal *self)
288 enum scrollbar_positions { DISABLED, LEFT, RIGHT };
289 switch (self->scrollbar_position)
292 gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 0);
293 gtk_widget_show (self->scrollbar);
297 gtk_box_reorder_child (GTK_BOX(self->hbox), self->scrollbar, 1);
298 gtk_widget_show (self->scrollbar);
303 gtk_widget_hide (self->scrollbar);
308 /*******************************************************************************
309 * All GObject stuff is below. You probably don't need to change this...
310 ******************************************************************************/
312 static GObjectClass *parent_class = NULL;
314 enum tilda_terminal_properties {
315 TILDA_TERMINAL_NUMBER = 1,
316 TILDA_TERMINAL_WINDOW_NUMBER,
319 /* All non-constructor-only properties */
320 TILDA_TERMINAL_BACKGROUND_IMAGE,
321 TILDA_TERMINAL_SHELL,
323 TILDA_TERMINAL_TITLE,
324 TILDA_TERMINAL_WORKING_DIRECTORY,
325 TILDA_TERMINAL_WEB_BROWSER,
327 TILDA_TERMINAL_SCROLLBACK_LINES,
328 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
330 TILDA_TERMINAL_BACKSPACE_BINDING,
331 TILDA_TERMINAL_DELETE_BINDING,
332 TILDA_TERMINAL_DYNAMIC_TITLE,
333 TILDA_TERMINAL_EXIT_ACTION,
334 TILDA_TERMINAL_SCROLLBAR_POSITION,
336 TILDA_TERMINAL_SCROLL_BACKGROUND,
337 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
338 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
339 TILDA_TERMINAL_ANTIALIASED,
340 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
341 TILDA_TERMINAL_CURSOR_BLINKS,
342 TILDA_TERMINAL_AUDIBLE_BELL,
343 TILDA_TERMINAL_VISIBLE_BELL,
344 TILDA_TERMINAL_DOUBLE_BUFFERED,
345 TILDA_TERMINAL_MOUSE_AUTOHIDE,
349 tilda_terminal_instance_init (GTypeInstance *instance,
352 TildaTerminal *self = (TildaTerminal *) instance;
354 /* Initialize instance members and allocate any necessary memory here.
355 * NOTE: any constructor-time values will be set later. */
356 self->dispose_has_run = FALSE;
359 self->vte_term = vte_terminal_new ();
360 self->scrollbar = gtk_vscrollbar_new (VTE_TERMINAL(self->vte_term)->adjustment);
361 self->hbox = gtk_hbox_new (FALSE, 0);
365 tilda_terminal_set_property (GObject *object,
370 TildaTerminal *self = (TildaTerminal *) object;
372 switch (property_id) {
374 case TILDA_TERMINAL_NUMBER:
375 self->number = g_value_get_int (value);
376 g_print ("terminal number: %d\n", self->number);
379 case TILDA_TERMINAL_WINDOW_NUMBER:
380 self->window_number = g_value_get_int (value);
381 g_print ("terminal parent window number: %d\n", self->window_number);
384 case TILDA_TERMINAL_TW:
385 self->parent_window = g_value_get_pointer (value);
386 g_print ("terminal parent window: 0x%x\n", self->parent_window);
387 g_print ("terminal parent window number (direct): %d\n", TILDA_WINDOW(self->parent_window)->number);
390 case TILDA_TERMINAL_BACKGROUND_IMAGE:
391 g_free (self->background_image);
392 self->background_image = g_value_dup_string (value);
393 vte_terminal_set_background_image_file (VTE_TERMINAL(self->vte_term), self->background_image);
394 g_print ("terminal back img: %s\n", self->background_image);
397 case TILDA_TERMINAL_SHELL:
398 g_free (self->shell);
399 self->shell = g_value_dup_string (value);
400 tilda_terminal_start_shell (self);
401 g_print ("terminal shell: %s\n", self->shell);
404 case TILDA_TERMINAL_FONT:
406 self->font = g_value_dup_string (value);
407 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
410 g_print ("terminal font: %s\n", self->font);
413 case TILDA_TERMINAL_TITLE:
414 g_free (self->title);
415 self->title = g_value_dup_string (value);
416 g_print ("terminal title: %s\n", self->title);
419 case TILDA_TERMINAL_WORKING_DIRECTORY:
420 g_free (self->working_directory);
421 self->working_directory = g_value_dup_string (value);
422 g_print ("terminal wrk dir: %s\n", self->working_directory);
425 case TILDA_TERMINAL_WEB_BROWSER:
426 g_free (self->web_browser);
427 self->web_browser = g_value_dup_string (value);
428 g_print ("terminal web browser: %s\n", self->web_browser);
431 case TILDA_TERMINAL_SCROLLBACK_LINES:
432 self->scrollback_lines = g_value_get_int (value);
433 vte_terminal_set_scrollback_lines (VTE_TERMINAL(self->vte_term), self->scrollback_lines);
434 g_print ("terminal scrollback lines: %d\n", self->scrollback_lines);
437 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
438 self->transparency_percent = g_value_get_int (value);
439 tilda_terminal_set_transparent (self);
440 g_print ("terminal transp percent: %d\n", self->transparency_percent);
443 case TILDA_TERMINAL_BACKSPACE_BINDING:
444 self->backspace_binding = g_value_get_int (value);
445 vte_terminal_set_backspace_binding (VTE_TERMINAL(self->vte_term), self->backspace_binding);
446 g_print ("terminal backspace key: %d\n", self->backspace_binding);
449 case TILDA_TERMINAL_DELETE_BINDING:
450 self->delete_binding = g_value_get_int (value);
451 vte_terminal_set_delete_binding (VTE_TERMINAL(self->vte_term), self->delete_binding);
452 g_print ("terminal delete key: %d\n", self->delete_binding);
455 case TILDA_TERMINAL_DYNAMIC_TITLE:
456 self->dynamic_title = g_value_get_int (value);
457 g_print ("terminal dynamic title: %d\n", self->dynamic_title);
460 case TILDA_TERMINAL_EXIT_ACTION:
461 self->exit_action = g_value_get_int (value);
462 g_print ("terminal exit action: %d\n", self->exit_action);
465 case TILDA_TERMINAL_SCROLLBAR_POSITION:
466 self->scrollbar_position = g_value_get_int (value);
467 tilda_terminal_set_scrollbar_position (self);
468 g_print ("terminal scrollbar position: %d\n", self->scrollbar_position);
471 case TILDA_TERMINAL_SCROLL_BACKGROUND:
472 self->scroll_background = g_value_get_boolean (value);
473 vte_terminal_set_scroll_background (VTE_TERMINAL(self->vte_term), self->scroll_background);
474 g_print ("terminal scroll background: %d\n", self->scroll_background);
477 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
478 self->scroll_on_output = g_value_get_boolean (value);
479 vte_terminal_set_scroll_on_output (VTE_TERMINAL(self->vte_term), self->scroll_on_output);
480 g_print ("terminal scroll on output: %d\n", self->scroll_on_output);
483 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
484 self->scroll_on_keystroke = g_value_get_boolean (value);
485 vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(self->vte_term), self->scroll_on_keystroke);
486 g_print ("terminal scroll on keystroke: %d\n", self->scroll_on_keystroke);
489 case TILDA_TERMINAL_ANTIALIASED:
490 self->antialiased = g_value_get_boolean (value);
491 vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
494 g_print ("terminal antialiased: %d\n", self->antialiased);
497 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
498 self->allow_bold_text = g_value_get_boolean (value);
499 vte_terminal_set_allow_bold (VTE_TERMINAL(self->vte_term), self->allow_bold_text);
500 g_print ("terminal allow bold text: %d\n", self->allow_bold_text);
503 case TILDA_TERMINAL_CURSOR_BLINKS:
504 self->cursor_blinks = g_value_get_boolean (value);
505 vte_terminal_set_cursor_blinks (VTE_TERMINAL(self->vte_term), self->cursor_blinks);
506 g_print ("terminal cursor blinks: %d\n", self->cursor_blinks);
509 case TILDA_TERMINAL_AUDIBLE_BELL:
510 self->audible_bell = g_value_get_boolean (value);
511 vte_terminal_set_audible_bell (VTE_TERMINAL(self->vte_term), self->audible_bell);
512 g_print ("terminal audible bell: %d\n", self->audible_bell);
515 case TILDA_TERMINAL_VISIBLE_BELL:
516 self->visible_bell = g_value_get_boolean (value);
517 vte_terminal_set_visible_bell (VTE_TERMINAL(self->vte_term), self->visible_bell);
518 g_print ("terminal visible bell: %d\n", self->visible_bell);
521 case TILDA_TERMINAL_DOUBLE_BUFFERED:
522 self->double_buffered = g_value_get_boolean (value);
523 gtk_widget_set_double_buffered (GTK_WIDGET(self->vte_term), self->double_buffered);
524 g_print ("terminal double buffered: %d\n", self->double_buffered);
527 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
528 self->mouse_autohide = g_value_get_boolean (value);
529 vte_terminal_set_mouse_autohide (VTE_TERMINAL(self->vte_term), self->mouse_autohide);
530 g_print ("terminal mouse autohide: %d\n", self->mouse_autohide);
534 /* We don't have this property... */
535 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
541 tilda_terminal_get_property (GObject *object,
546 TildaTerminal *self = (TildaTerminal *) object;
548 switch (property_id) {
550 case TILDA_TERMINAL_NUMBER:
551 g_value_set_int (value, self->number);
554 case TILDA_TERMINAL_WINDOW_NUMBER:
555 g_value_set_int (value, self->window_number);
558 case TILDA_TERMINAL_TW:
559 g_value_set_pointer (value, self->parent_window);
562 case TILDA_TERMINAL_BACKGROUND_IMAGE:
563 g_value_set_string (value, self->background_image);
566 case TILDA_TERMINAL_SHELL:
567 g_value_set_string (value, self->shell);
570 case TILDA_TERMINAL_FONT:
571 g_value_set_string (value, self->font);
574 case TILDA_TERMINAL_TITLE:
575 g_value_set_string (value, self->title);
578 case TILDA_TERMINAL_WORKING_DIRECTORY:
579 g_value_set_string (value, self->working_directory);
582 case TILDA_TERMINAL_WEB_BROWSER:
583 g_value_set_string (value, self->web_browser);
586 case TILDA_TERMINAL_SCROLLBACK_LINES:
587 g_value_set_int (value, self->scrollback_lines);
590 case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
591 g_value_set_int (value, self->transparency_percent);
594 case TILDA_TERMINAL_BACKSPACE_BINDING:
595 g_value_set_int (value, self->backspace_binding);
598 case TILDA_TERMINAL_DELETE_BINDING:
599 g_value_set_int (value, self->delete_binding);
602 case TILDA_TERMINAL_DYNAMIC_TITLE:
603 g_value_set_int (value, self->dynamic_title);
606 case TILDA_TERMINAL_EXIT_ACTION:
607 g_value_set_int (value, self->exit_action);
610 case TILDA_TERMINAL_SCROLLBAR_POSITION:
611 g_value_set_int (value, self->scrollbar_position);
614 case TILDA_TERMINAL_SCROLL_BACKGROUND:
615 g_value_set_boolean (value, self->scroll_background);
618 case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
619 g_value_set_boolean (value, self->scroll_on_output);
622 case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
623 g_value_set_boolean (value, self->scroll_on_keystroke);
626 case TILDA_TERMINAL_ANTIALIASED:
627 g_value_set_boolean (value, self->antialiased);
630 case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
631 g_value_set_boolean (value, self->allow_bold_text);
634 case TILDA_TERMINAL_CURSOR_BLINKS:
635 g_value_set_boolean (value, self->cursor_blinks);
638 case TILDA_TERMINAL_AUDIBLE_BELL:
639 g_value_set_boolean (value, self->audible_bell);
642 case TILDA_TERMINAL_VISIBLE_BELL:
643 g_value_set_boolean (value, self->visible_bell);
646 case TILDA_TERMINAL_DOUBLE_BUFFERED:
647 g_value_set_boolean (value, self->double_buffered);
650 case TILDA_TERMINAL_MOUSE_AUTOHIDE:
651 g_value_set_boolean (value, self->mouse_autohide);
654 /* We don't have this property... */
655 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
661 tilda_terminal_constructor (GType type,
662 guint n_construct_properties,
663 GObjectConstructParam *construct_properties)
669 /* Invoke parent constructor */
670 TildaTerminalClass *klass;
671 klass = TILDA_TERMINAL_CLASS (g_type_class_peek (TILDA_TYPE_TERMINAL));
672 obj = parent_class->constructor (type,
673 n_construct_properties,
674 construct_properties);
676 /* Do other stuff here. The object is ready to go now, and all
677 * ctor properties have been set.
679 * TODO: This is the place to do DBus-init */
680 self = TILDA_TERMINAL(obj);
682 /* Pack into the hbox */
683 gtk_box_pack_end (GTK_BOX(self->hbox), self->scrollbar, FALSE, FALSE, 0);
684 gtk_box_pack_end (GTK_BOX(self->hbox), self->vte_term, TRUE, TRUE, 0);
685 gtk_widget_show (self->scrollbar);
687 /* Match URL's, etc */
688 ret = vte_terminal_match_add (VTE_TERMINAL(self->vte_term), DINGUS1);
689 vte_terminal_match_set_cursor_type (VTE_TERMINAL(self->vte_term), ret, GDK_HAND2);
690 ret = vte_terminal_match_add(VTE_TERMINAL(self->vte_term), DINGUS2);
691 vte_terminal_match_set_cursor_type (VTE_TERMINAL(self->vte_term), ret, GDK_HAND2);
693 /* Connect Signals */
694 g_signal_connect (G_OBJECT(self->vte_term), "child-exited",
695 G_CALLBACK(tilda_terminal_child_exited_cb), self);
696 g_signal_connect (G_OBJECT(self->vte_term), "eof",
697 G_CALLBACK(tilda_terminal_child_exited_cb), self);
698 g_signal_connect (G_OBJECT(self->vte_term), "window-title-changed",
699 G_CALLBACK(tilda_terminal_window_title_changed_cb), self);
700 g_signal_connect (G_OBJECT(self->vte_term), "button-press-event",
701 G_CALLBACK(tilda_terminal_button_press_cb), self);
703 tilda_terminal_start_shell (self);
704 tilda_terminal_dbus_register_object (self);
710 tilda_terminal_dispose (GObject *obj)
712 TildaTerminal *self = (TildaTerminal *) obj;
714 /* We don't want to run dispose twice, so just return immediately */
715 if (self->dispose_has_run)
718 self->dispose_has_run = TRUE;
721 * In dispose, you are supposed to free all types referenced from this
722 * object which might themselves hold a reference to self. Generally,
723 * the most simple solution is to unref all members on which you own a
727 /* Chain up to the parent class */
728 G_OBJECT_CLASS (parent_class)->dispose (obj);
732 tilda_terminal_finalize (GObject *obj)
734 TildaTerminal *self = (TildaTerminal *) obj;
737 * Here, complete object destruction.
738 * You might not need to do much...
741 // TODO: g_free() any primitives here
742 g_free (self->background_image);
743 g_free (self->shell);
745 g_free (self->title);
746 g_free (self->working_directory);
749 /* Chain up to the parent class */
750 G_OBJECT_CLASS (parent_class)->finalize (obj);
754 tilda_terminal_class_init (gpointer g_class,
755 gpointer g_class_data)
757 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
758 TildaTerminalClass *klass = TILDA_TERMINAL_CLASS (g_class);
761 /* Hook our functions to this type */
762 gobject_class->set_property = tilda_terminal_set_property;
763 gobject_class->get_property = tilda_terminal_get_property;
764 gobject_class->dispose = tilda_terminal_dispose;
765 gobject_class->finalize = tilda_terminal_finalize;
766 gobject_class->constructor = tilda_terminal_constructor;
768 parent_class = g_type_class_peek_parent (klass);
770 /* Hook the TildaTerminal type into DBus */
771 dbus_g_object_type_install_info (tilda_terminal_get_type(), &dbus_glib_tilda_terminal_object_info);
773 /* Install all of the properties */
774 pspec = g_param_spec_int ("number",
776 "Set terminal's number",
778 INT_MAX, // max value
780 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
782 g_object_class_install_property (gobject_class,
783 TILDA_TERMINAL_NUMBER,
786 pspec = g_param_spec_int ("window-number",
787 "Number of the window to which this terminal belongs",
788 "Set the number of the parent window",
792 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
794 g_object_class_install_property (gobject_class,
795 TILDA_TERMINAL_WINDOW_NUMBER,
798 pspec = g_param_spec_pointer ("parent-window",
799 "Pointer to terminal's parent TildaWindow",
800 "Set the pointer to the terminal's parent TildaWindow",
801 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
803 g_object_class_install_property (gobject_class,
807 pspec = g_param_spec_string ("background-image",
808 "Terminal's background image",
809 "Get/Set terminal's background image",
813 g_object_class_install_property (gobject_class,
814 TILDA_TERMINAL_BACKGROUND_IMAGE,
817 pspec = g_param_spec_string ("shell",
819 "Get/Set terminal's shell",
823 g_object_class_install_property (gobject_class,
824 TILDA_TERMINAL_SHELL,
827 pspec = g_param_spec_string ("font",
829 "Get/Set terminal's font",
833 g_object_class_install_property (gobject_class,
837 pspec = g_param_spec_string ("title",
839 "Get/Set terminal's title",
843 g_object_class_install_property (gobject_class,
844 TILDA_TERMINAL_TITLE,
847 pspec = g_param_spec_string ("working-directory",
848 "Terminal's initial working directory",
849 "Get/Set terminal's initial working directory",
853 g_object_class_install_property (gobject_class,
854 TILDA_TERMINAL_WORKING_DIRECTORY,
857 pspec = g_param_spec_string ("web-browser",
858 "Terminal's web browser command",
863 g_object_class_install_property (gobject_class,
864 TILDA_TERMINAL_WEB_BROWSER,
867 pspec = g_param_spec_int ("scrollback-lines",
868 "Terminal's scrollback amount (lines)",
869 "Get/Set terminal's scrollback amount",
871 INT_MAX, // TODO: artificially limit this?
875 g_object_class_install_property (gobject_class,
876 TILDA_TERMINAL_SCROLLBACK_LINES,
879 pspec = g_param_spec_int ("transparency-percent",
880 "Terminal's transparency (percent)",
881 "Get/Set terminal's transparency",
887 g_object_class_install_property (gobject_class,
888 TILDA_TERMINAL_TRANSPARENCY_PERCENT,
891 pspec = g_param_spec_int ("backspace-binding",
892 "Terminal's backspace binding",
893 "Get/Set terminal's backspace key binding",
895 VTE_ERASE_DELETE_SEQUENCE,
899 g_object_class_install_property (gobject_class,
900 TILDA_TERMINAL_BACKSPACE_BINDING,
903 pspec = g_param_spec_int ("delete-binding",
904 "Terminal's delete binding",
905 "Get/Set terminal's delete key binding",
907 VTE_ERASE_DELETE_SEQUENCE,
911 g_object_class_install_property (gobject_class,
912 TILDA_TERMINAL_DELETE_BINDING,
915 pspec = g_param_spec_int ("dynamic-title",
916 "Terminal's dynamic title generation method",
917 "Get/Set terminal's dynamic title generation method",
923 g_object_class_install_property (gobject_class,
924 TILDA_TERMINAL_DYNAMIC_TITLE,
927 pspec = g_param_spec_int ("exit-action",
928 "Terminal's action upon child exit",
929 "Get/Set terminal's action upon child exit",
935 g_object_class_install_property (gobject_class,
936 TILDA_TERMINAL_EXIT_ACTION,
939 pspec = g_param_spec_int ("scrollbar-position",
940 "Terminal's scrollbar position",
947 g_object_class_install_property (gobject_class,
948 TILDA_TERMINAL_SCROLLBAR_POSITION,
951 pspec = g_param_spec_boolean ("scroll-background",
952 "Controls terminal's scrolling behavior",
953 "Get/Set terminal's scrolling behavior",
957 g_object_class_install_property (gobject_class,
958 TILDA_TERMINAL_SCROLL_BACKGROUND,
961 pspec = g_param_spec_boolean ("scroll-on-output",
962 "Controls terminal's scrolling behavior on output",
963 "Get/Set terminal's scrolling behavior on output",
967 g_object_class_install_property (gobject_class,
968 TILDA_TERMINAL_SCROLL_ON_OUTPUT,
971 pspec = g_param_spec_boolean ("scroll-on-keystroke",
972 "Controls the terminal's scrolling behavior on keystroke",
973 NULL, FALSE, G_PARAM_READWRITE);
975 g_object_class_install_property (gobject_class,
976 TILDA_TERMINAL_SCROLL_ON_KEYSTROKE,
979 pspec = g_param_spec_boolean ("antialiased",
980 "Attempt to antialias fonts",
981 NULL, FALSE, G_PARAM_READWRITE);
983 g_object_class_install_property (gobject_class,
984 TILDA_TERMINAL_ANTIALIASED,
987 pspec = g_param_spec_boolean ("allow-bold-text",
989 NULL, FALSE, G_PARAM_READWRITE);
991 g_object_class_install_property (gobject_class,
992 TILDA_TERMINAL_ALLOW_BOLD_TEXT,
995 pspec = g_param_spec_boolean ("cursor-blinks",
996 NULL, NULL, FALSE, G_PARAM_READWRITE);
998 g_object_class_install_property (gobject_class,
999 TILDA_TERMINAL_CURSOR_BLINKS,
1002 pspec = g_param_spec_boolean ("audible-bell",
1003 NULL, NULL, FALSE, G_PARAM_READWRITE);
1005 g_object_class_install_property (gobject_class,
1006 TILDA_TERMINAL_AUDIBLE_BELL,
1009 pspec = g_param_spec_boolean ("visible-bell",
1010 NULL, NULL, FALSE, G_PARAM_READWRITE);
1012 g_object_class_install_property (gobject_class,
1013 TILDA_TERMINAL_VISIBLE_BELL,
1016 pspec = g_param_spec_boolean ("double-buffered",
1017 NULL, NULL, FALSE, G_PARAM_READWRITE);
1019 g_object_class_install_property (gobject_class,
1020 TILDA_TERMINAL_DOUBLE_BUFFERED,
1023 pspec = g_param_spec_boolean ("mouse-autohide",
1024 NULL, NULL, FALSE, G_PARAM_READWRITE);
1026 g_object_class_install_property (gobject_class,
1027 TILDA_TERMINAL_MOUSE_AUTOHIDE,
1032 tilda_terminal_get_type (void)
1034 static GType type = 0;
1038 static const GTypeInfo info = {
1039 sizeof (TildaTerminalClass),
1040 NULL, /* base_init */
1041 NULL, /* base_finalize */
1042 tilda_terminal_class_init, /* class_init */
1043 NULL, /* class_finalize */
1044 NULL, /* class_data */
1045 sizeof (TildaTerminal),
1046 0, /* n_preallocs */
1047 tilda_terminal_instance_init, /* instance_init */
1050 type = g_type_register_static (G_TYPE_OBJECT,
1051 "TildaTerminalType",
1061 int main (int argc, char *argv[])
1064 gint test_number = INT_MIN;
1065 gchar *test_string = NULL;
1067 /* Initialize the GObject type system */
1069 gtk_init (&argc, &argv);
1071 tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 10, NULL);
1072 g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
1073 g_assert (test_number == 10);
1075 g_object_unref (G_OBJECT (tt));
1077 tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 22, NULL);
1078 g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
1079 g_assert (test_number == 22);
1081 g_object_set (G_OBJECT (tt), "font", "hello I'm a font");
1082 g_object_set (G_OBJECT (tt), "font", "Bitstream Vera Sans Mono 13");
1084 g_object_get (G_OBJECT (tt), "font", &test_string, NULL);
1085 g_print ("Read Font: %s\n", test_string);
1086 // NOTE: you MUST free the string!!!!
1087 g_free (test_string);
1089 g_object_set (G_OBJECT (tt), "transparency-percent", 50);
1091 g_object_unref (G_OBJECT (tt));
1098 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */